Skip to content

Commit 2572ee6

Browse files
committed
feat: add numberOfSecretBytes parameter to Payload and adjust related functionality
Added optional numberOfSecretBytes parameter to the Payload interface to specify the number of authenticator secret bytes (default: 20). Added the numberOfSecretBytes parameter in the config to use the value from the Payload or fallback to the default. Adjusted and added corresponding test cases to validate the new parameter and ensure compatibility with existing behavior. This change provides greater flexibility in configuring the number of secret bytes for the authenticator while maintaining backward compatibility.
1 parent 436c8c8 commit 2572ee6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

lib/secret.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ export async function generateSecret(
4848
const config = {
4949
name: encodeURIComponent(payload?.name ?? "App"),
5050
account: payload.account ? encodeURIComponent(`:${payload.account}`) : "",
51-
counter: strategy === "HOTP" ? (payload.counter ?? 0).toString() : undefined,
52-
numberOfBytes: payload.numberOfSecretBytes ?? 20
51+
counter:
52+
strategy === "HOTP" ? (payload.counter ?? 0).toString() : undefined,
53+
numberOfBytes: payload.numberOfSecretBytes ?? 20,
5354
} as const;
5455

5556
const secret = authenticator.generateSecret(config.numberOfBytes);

tests/hotp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const { secret } = await generateSecret({
66
name: "App",
77
account: "exemple@exemple.com",
88
counter: 0,
9-
numberOfSecretBytes: 20
9+
numberOfSecretBytes: 20,
1010
});
1111

1212
const counter = 0;

tests/totp.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { secret } = await generateSecret(
77
name: "App",
88
account: "exemple@exemple.com",
99
counter: 0,
10-
numberOfSecretBytes: 20
10+
numberOfSecretBytes: 20,
1111
},
1212
"HOTP",
1313
);

0 commit comments

Comments
 (0)