diff options
Diffstat (limited to 'packages/browser/src')
-rw-r--r-- | packages/browser/src/methods/startAssertion.test.ts | 22 | ||||
-rw-r--r-- | packages/browser/src/methods/startAssertion.ts | 6 | ||||
-rw-r--r-- | packages/browser/src/methods/startAttestation.test.ts | 48 | ||||
-rw-r--r-- | packages/browser/src/methods/startAttestation.ts | 10 |
4 files changed, 41 insertions, 45 deletions
diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAssertion.test.ts index 7449dbf..db401dc 100644 --- a/packages/browser/src/methods/startAssertion.test.ts +++ b/packages/browser/src/methods/startAssertion.test.ts @@ -22,17 +22,15 @@ const mockSignature = toBase64String(toUint8Array('mockSignature')); const mockUserHandle = toBase64String(toUint8Array('mockUserHandle')); const goodOpts1: PublicKeyCredentialRequestOptionsJSON = { - publicKey: { - challenge: 'fizz', - allowCredentials: [ - { - id: 'abcdefgfdnsdfunguisdfgs', - type: 'public-key', - transports: ['nfc'], - }, - ], - timeout: 1, - }, + challenge: 'fizz', + allowCredentials: [ + { + id: 'abcdefgfdnsdfunguisdfgs', + type: 'public-key', + transports: ['nfc'], + }, + ], + timeout: 1, }; beforeEach(() => { @@ -57,7 +55,7 @@ test('should convert options before passing to navigator.credentials.get(...)', const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey; const credId = base64js.fromByteArray(argsPublicKey.allowCredentials[0].id); - expect(argsPublicKey.challenge).toEqual(toUint8Array(goodOpts1.publicKey.challenge)); + expect(argsPublicKey.challenge).toEqual(toUint8Array(goodOpts1.challenge)); // Make sure the credential ID is a proper base64 with a length that's a multiple of 4 expect(credId.length % 4).toEqual(0); diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAssertion.ts index 0648e56..093cf30 100644 --- a/packages/browser/src/methods/startAssertion.ts +++ b/packages/browser/src/methods/startAssertion.ts @@ -23,9 +23,9 @@ export default async function startAssertion( // We need to convert some values to Uint8Arrays before passing the credentials to the navigator const publicKey: PublicKeyCredentialRequestOptions = { - ...requestOptionsJSON.publicKey, - challenge: toUint8Array(requestOptionsJSON.publicKey.challenge), - allowCredentials: requestOptionsJSON.publicKey.allowCredentials.map( + ...requestOptionsJSON, + challenge: toUint8Array(requestOptionsJSON.challenge), + allowCredentials: requestOptionsJSON.allowCredentials.map( toPublicKeyCredentialDescriptor, ), }; diff --git a/packages/browser/src/methods/startAttestation.test.ts b/packages/browser/src/methods/startAttestation.test.ts index a972014..ae79235 100644 --- a/packages/browser/src/methods/startAttestation.test.ts +++ b/packages/browser/src/methods/startAttestation.test.ts @@ -19,31 +19,29 @@ const mockAttestationObject = 'mockAtte'; const mockClientDataJSON = 'mockClie'; const goodOpts1: PublicKeyCredentialCreationOptionsJSON = { - publicKey: { - challenge: 'fizz', - attestation: 'direct', - pubKeyCredParams: [ - { - alg: -7, - type: 'public-key', - }, - ], - rp: { - id: '1234', - name: 'simplewebauthn', - }, - user: { - id: '5678', - displayName: 'username', - name: 'username', - }, - timeout: 1, - excludeCredentials: [{ - id: 'authIdentifier', + challenge: 'fizz', + attestation: 'direct', + pubKeyCredParams: [ + { + alg: -7, type: 'public-key', - transports: ['internal'], - }], + }, + ], + rp: { + id: '1234', + name: 'simplewebauthn', }, + user: { + id: '5678', + displayName: 'username', + name: 'username', + }, + timeout: 1, + excludeCredentials: [{ + id: 'authIdentifier', + type: 'public-key', + transports: ['internal'], + }], }; beforeEach(() => { @@ -67,8 +65,8 @@ test('should convert options before passing to navigator.credentials.create(...) const argsPublicKey = mockNavigatorCreate.mock.calls[0][0].publicKey; - expect(argsPublicKey.challenge).toEqual(toUint8Array(goodOpts1.publicKey.challenge)); - expect(argsPublicKey.user.id).toEqual(toUint8Array(goodOpts1.publicKey.user.id)); + expect(argsPublicKey.challenge).toEqual(toUint8Array(goodOpts1.challenge)); + expect(argsPublicKey.user.id).toEqual(toUint8Array(goodOpts1.user.id)); expect(argsPublicKey.excludeCredentials).toEqual([{ id: base64js.toByteArray('authIdentifier=='), type: 'public-key', diff --git a/packages/browser/src/methods/startAttestation.ts b/packages/browser/src/methods/startAttestation.ts index f77c2de..ea05fa8 100644 --- a/packages/browser/src/methods/startAttestation.ts +++ b/packages/browser/src/methods/startAttestation.ts @@ -23,13 +23,13 @@ export default async function startAttestation( // We need to convert some values to Uint8Arrays before passing the credentials to the navigator const publicKey: PublicKeyCredentialCreationOptions = { - ...creationOptionsJSON.publicKey, - challenge: toUint8Array(creationOptionsJSON.publicKey.challenge), + ...creationOptionsJSON, + challenge: toUint8Array(creationOptionsJSON.challenge), user: { - ...creationOptionsJSON.publicKey.user, - id: toUint8Array(creationOptionsJSON.publicKey.user.id), + ...creationOptionsJSON.user, + id: toUint8Array(creationOptionsJSON.user.id), }, - excludeCredentials: creationOptionsJSON.publicKey.excludeCredentials.map( + excludeCredentials: creationOptionsJSON.excludeCredentials.map( toPublicKeyCredentialDescriptor, ), }; |