summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2020-05-23 15:14:05 -0700
committerMatthew Miller <matthew@millerti.me>2020-05-23 15:14:05 -0700
commita767c65763f347d180941f20926728cf722ca66d (patch)
treef85d6e4494616e6531da709a1b04a7dca654c709 /packages/browser/src/methods
parent1a38e1e786d91436d2d1fe456063545944835357 (diff)
Fix padding count calculation
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r--packages/browser/src/methods/startAssertion.test.ts6
-rw-r--r--packages/browser/src/methods/startAssertion.ts3
2 files changed, 5 insertions, 4 deletions
diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAssertion.test.ts
index 4e3bb07..259400c 100644
--- a/packages/browser/src/methods/startAssertion.test.ts
+++ b/packages/browser/src/methods/startAssertion.test.ts
@@ -22,7 +22,7 @@ const goodOpts1: PublicKeyCredentialRequestOptionsJSON = {
publicKey: {
challenge: 'fizz',
allowCredentials: [{
- id: 'credId',
+ id: 'abcdefgfdnsdfunguisdfgs',
type: 'public-key',
transports: ['nfc'],
}],
@@ -48,11 +48,11 @@ test('should convert options before passing to navigator.credentials.get(...)',
await startAssertion(goodOpts1);
const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey;
+ const credId = base64js.fromByteArray(argsPublicKey.allowCredentials[0].id);
expect(argsPublicKey.challenge).toEqual(toUint8Array(goodOpts1.publicKey.challenge));
// Make sure the credential ID is a proper base64 with a length that's a multiple of 4
- expect(argsPublicKey.allowCredentials[0].id.length % 4).toEqual(0);
- expect(argsPublicKey.allowCredentials[0].id).toEqual(base64js.toByteArray('credId=='));
+ expect(credId.length % 4).toEqual(0);
done();
});
diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts
index 8e411ec..0733194 100644
--- a/packages/browser/src/methods/startAssertion.ts
+++ b/packages/browser/src/methods/startAssertion.ts
@@ -27,7 +27,8 @@ export default async function startAssertion(
challenge: toUint8Array(requestOptionsJSON.publicKey.challenge),
allowCredentials: requestOptionsJSON.publicKey.allowCredentials.map((cred) => {
// Make sure the credential ID length is a multiple of 4
- let id = cred.id.padEnd(cred.id.length + (cred.id.length % 4), '=');
+ const padLength = 4 - cred.id.length % 4;
+ let id = cred.id.padEnd(cred.id.length + padLength, '=');
return {
...cred,