otplib API Documentation / @otplib/uri / generate
Function: generate()
generate(
uri):string
Defined in: packages/uri/src/generate.ts:88
Generate an otpauth:// URI
Parameters
uri
The URI components
Returns
string
The otpauth:// URI string
Example
ts
import { generate } from '@otplib/uri';
import { encode } from '@otplib/base32';
const secret = encode(new Uint8Array([1, 2, 3, 4, 5]));
const uri = generate({
type: 'totp',
label: 'ACME:john@example.com',
params: {
secret,
issuer: 'ACME',
algorithm: 'sha1',
digits: 6,
},
});
// Returns: 'otpauth://totp/ACME:john%40example.com?secret=...'