diff options
author | Matthew Miller <matthew@millerti.me> | 2021-08-25 21:25:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 21:25:57 -0700 |
commit | f38363c22f9168653f47f3d112338b80cab93deb (patch) | |
tree | 6569142b2ad7d1a8a797a7be439e6377d2b750ea /packages/browser/src | |
parent | 30ecc73b9856747337523f1e367b10d9d96a4a95 (diff) | |
parent | b831fc557aac088c2cace7279decb842bb2214a0 (diff) |
Merge pull request #147 from JayHelton/v4/rename-methods-and-types
feat/rename methods and types
Diffstat (limited to 'packages/browser/src')
-rw-r--r-- | packages/browser/src/index.test.ts | 8 | ||||
-rw-r--r-- | packages/browser/src/index.ts | 8 | ||||
-rw-r--r-- | packages/browser/src/methods/startAuthentication.test.ts (renamed from packages/browser/src/methods/startAssertion.test.ts) | 28 | ||||
-rw-r--r-- | packages/browser/src/methods/startAuthentication.ts (renamed from packages/browser/src/methods/startAssertion.ts) | 12 | ||||
-rw-r--r-- | packages/browser/src/methods/startRegistration.test.ts (renamed from packages/browser/src/methods/startAttestation.test.ts) | 22 | ||||
-rw-r--r-- | packages/browser/src/methods/startRegistration.ts (renamed from packages/browser/src/methods/startAttestation.ts) | 16 |
6 files changed, 47 insertions, 47 deletions
diff --git a/packages/browser/src/index.test.ts b/packages/browser/src/index.test.ts index 5e396ca..e82191c 100644 --- a/packages/browser/src/index.test.ts +++ b/packages/browser/src/index.test.ts @@ -1,11 +1,11 @@ import * as index from './index'; -test('should export method `startAttestation`', () => { - expect(index.startAttestation).toBeDefined(); +test('should export method `startRegistration`', () => { + expect(index.startRegistration).toBeDefined(); }); -test('should export method `startAssertion`', () => { - expect(index.startAssertion).toBeDefined(); +test('should export method `startAuthentication`', () => { + expect(index.startAuthentication).toBeDefined(); }); test('should export method `browserSupportsWebauthn`', () => { diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 94c9755..4c83297 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -2,14 +2,14 @@ * @packageDocumentation * @module @simplewebauthn/browser */ -import startAttestation from './methods/startAttestation'; -import startAssertion from './methods/startAssertion'; +import startRegistration from './methods/startRegistration'; +import startAuthentication from './methods/startAuthentication'; import { browserSupportsWebauthn } from './helpers/browserSupportsWebauthn'; import { platformAuthenticatorIsAvailable } from './helpers/platformAuthenticatorIsAvailable'; export { - startAttestation, - startAssertion, + startRegistration, + startAuthentication, browserSupportsWebauthn, platformAuthenticatorIsAvailable, }; diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAuthentication.test.ts index 060d918..5e74789 100644 --- a/packages/browser/src/methods/startAssertion.test.ts +++ b/packages/browser/src/methods/startAuthentication.test.ts @@ -1,5 +1,5 @@ import { - AssertionCredential, + AuthenticationCredential, PublicKeyCredentialRequestOptionsJSON, AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs, @@ -9,7 +9,7 @@ import { browserSupportsWebauthn } from '../helpers/browserSupportsWebauthn'; import utf8StringToBuffer from '../helpers/utf8StringToBuffer'; import bufferToBase64URLString from '../helpers/bufferToBase64URLString'; -import startAssertion from './startAssertion'; +import startAuthentication from './startAuthentication'; jest.mock('../helpers/browserSupportsWebauthn'); @@ -61,7 +61,7 @@ afterEach(() => { }); test('should convert options before passing to navigator.credentials.get(...)', async done => { - await startAssertion(goodOpts1); + await startAuthentication(goodOpts1); const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey; const credId = argsPublicKey.allowCredentials[0].id; @@ -75,7 +75,7 @@ test('should convert options before passing to navigator.credentials.get(...)', }); test('should support optional allowCredential', async () => { - await startAssertion({ + await startAuthentication({ challenge: bufferToBase64URLString(utf8StringToBuffer('fizz')), timeout: 1, }); @@ -84,7 +84,7 @@ test('should support optional allowCredential', async () => { }); test('should convert allow allowCredential to undefined when empty', async () => { - await startAssertion({ + await startAuthentication({ challenge: bufferToBase64URLString(utf8StringToBuffer('fizz')), timeout: 1, allowCredentials: [], @@ -93,7 +93,7 @@ test('should convert allow allowCredential to undefined when empty', async () => }); test('should return base64url-encoded response values', async done => { - mockNavigatorGet.mockImplementation((): Promise<AssertionCredential> => { + mockNavigatorGet.mockImplementation((): Promise<AuthenticationCredential> => { return new Promise(resolve => { resolve({ id: 'foobar', @@ -110,7 +110,7 @@ test('should return base64url-encoded response values', async done => { }); }); - const response = await startAssertion(goodOpts1); + const response = await startAuthentication(goodOpts1); expect(response.rawId).toEqual('Zm9vYmFy'); expect(response.response.authenticatorData).toEqual('bW9ja0F1dGhlbnRpY2F0b3JEYXRh'); @@ -124,7 +124,7 @@ test('should return base64url-encoded response values', async done => { test("should throw error if WebAuthn isn't supported", async done => { mockSupportsWebauthn.mockReturnValue(false); - await expect(startAssertion(goodOpts1)).rejects.toThrow( + await expect(startAuthentication(goodOpts1)).rejects.toThrow( 'WebAuthn is not supported in this browser', ); @@ -138,13 +138,13 @@ test('should throw error if assertion is cancelled for some reason', async done }); }); - await expect(startAssertion(goodOpts1)).rejects.toThrow('Assertion was not completed'); + await expect(startAuthentication(goodOpts1)).rejects.toThrow('Authentication was not completed'); done(); }); test('should handle UTF-8 challenges', async done => { - await startAssertion(goodOpts2UTF8); + await startAuthentication(goodOpts2UTF8); const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey; @@ -168,7 +168,7 @@ test('should send extensions to authenticator if present in options', async done ...goodOpts1, extensions, }; - await startAssertion(optsWithExts); + await startAuthentication(optsWithExts); const argsExtensions = mockNavigatorGet.mock.calls[0][0].publicKey.extensions; @@ -178,7 +178,7 @@ test('should send extensions to authenticator if present in options', async done }); test('should not set any extensions if not present in options', async done => { - await startAssertion(goodOpts1); + await startAuthentication(goodOpts1); const argsExtensions = mockNavigatorGet.mock.calls[0][0].publicKey.extensions; @@ -203,7 +203,7 @@ test('should include extension results', async done => { }); // Extensions aren't present in this object, but it doesn't matter since we're faking the response - const response = await startAssertion(goodOpts1); + const response = await startAuthentication(goodOpts1); expect(response.clientExtensionResults).toEqual(extResults); @@ -211,7 +211,7 @@ test('should include extension results', async done => { }); test('should include extension results when no extensions specified', async done => { - const response = await startAssertion(goodOpts1); + const response = await startAuthentication(goodOpts1); expect(response.clientExtensionResults).toEqual({}); diff --git a/packages/browser/src/methods/startAssertion.ts b/packages/browser/src/methods/startAuthentication.ts index 26fd755..277b8f0 100644 --- a/packages/browser/src/methods/startAssertion.ts +++ b/packages/browser/src/methods/startAuthentication.ts @@ -1,7 +1,7 @@ import { PublicKeyCredentialRequestOptionsJSON, - AssertionCredential, - AssertionCredentialJSON, + AuthenticationCredential, + AuthenticationCredentialJSON, } from '@simplewebauthn/typescript-types'; import bufferToBase64URLString from '../helpers/bufferToBase64URLString'; @@ -15,9 +15,9 @@ import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDes * * @param requestOptionsJSON Output from @simplewebauthn/server's generateAssertionOptions(...) */ -export default async function startAssertion( +export default async function startAuthentication( requestOptionsJSON: PublicKeyCredentialRequestOptionsJSON, -): Promise<AssertionCredentialJSON> { +): Promise<AuthenticationCredentialJSON> { if (!browserSupportsWebauthn()) { throw new Error('WebAuthn is not supported in this browser'); } @@ -37,10 +37,10 @@ export default async function startAssertion( }; // Wait for the user to complete assertion - const credential = (await navigator.credentials.get({ publicKey })) as AssertionCredential; + const credential = (await navigator.credentials.get({ publicKey })) as AuthenticationCredential; if (!credential) { - throw new Error('Assertion was not completed'); + throw new Error('Authentication was not completed'); } const { id, rawId, response, type } = credential; diff --git a/packages/browser/src/methods/startAttestation.test.ts b/packages/browser/src/methods/startRegistration.test.ts index a6a2beb..e11718e 100644 --- a/packages/browser/src/methods/startAttestation.test.ts +++ b/packages/browser/src/methods/startRegistration.test.ts @@ -1,5 +1,5 @@ import { - AttestationCredential, + RegistrationCredential, AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs, PublicKeyCredentialCreationOptionsJSON, @@ -9,7 +9,7 @@ import utf8StringToBuffer from '../helpers/utf8StringToBuffer'; import { browserSupportsWebauthn } from '../helpers/browserSupportsWebauthn'; import bufferToBase64URLString from '../helpers/bufferToBase64URLString'; -import startAttestation from './startAttestation'; +import startRegistration from './startRegistration'; jest.mock('../helpers/browserSupportsWebauthn'); @@ -64,7 +64,7 @@ afterEach(() => { }); test('should convert options before passing to navigator.credentials.create(...)', async done => { - await startAttestation(goodOpts1); + await startRegistration(goodOpts1); const argsPublicKey = mockNavigatorCreate.mock.calls[0][0].publicKey; const credId = argsPublicKey.excludeCredentials[0].id; @@ -83,7 +83,7 @@ test('should convert options before passing to navigator.credentials.create(...) }); test('should return base64url-encoded response values', async done => { - mockNavigatorCreate.mockImplementation((): Promise<AttestationCredential> => { + mockNavigatorCreate.mockImplementation((): Promise<RegistrationCredential> => { return new Promise(resolve => { resolve({ id: 'foobar', @@ -98,7 +98,7 @@ test('should return base64url-encoded response values', async done => { }); }); - const response = await startAttestation(goodOpts1); + const response = await startRegistration(goodOpts1); expect(response.rawId).toEqual('Zm9vYmFy'); expect(response.response.attestationObject).toEqual('bW9ja0F0dGU'); @@ -110,7 +110,7 @@ test('should return base64url-encoded response values', async done => { test("should throw error if WebAuthn isn't supported", async done => { mockSupportsWebauthn.mockReturnValue(false); - await expect(startAttestation(goodOpts1)).rejects.toThrow( + await expect(startRegistration(goodOpts1)).rejects.toThrow( 'WebAuthn is not supported in this browser', ); @@ -124,7 +124,7 @@ test('should throw error if attestation is cancelled for some reason', async don }); }); - await expect(startAttestation(goodOpts1)).rejects.toThrow('Attestation was not completed'); + await expect(startRegistration(goodOpts1)).rejects.toThrow('Registration was not completed'); done(); }); @@ -140,7 +140,7 @@ test('should send extensions to authenticator if present in options', async done ...goodOpts1, extensions, }; - await startAttestation(optsWithExts); + await startRegistration(optsWithExts); const argsExtensions = mockNavigatorCreate.mock.calls[0][0].publicKey.extensions; @@ -150,7 +150,7 @@ test('should send extensions to authenticator if present in options', async done }); test('should not set any extensions if not present in options', async done => { - await startAttestation(goodOpts1); + await startRegistration(goodOpts1); const argsExtensions = mockNavigatorCreate.mock.calls[0][0].publicKey.extensions; @@ -175,7 +175,7 @@ test('should include extension results', async done => { }); // Extensions aren't present in this object, but it doesn't matter since we're faking the response - const response = await startAttestation(goodOpts1); + const response = await startRegistration(goodOpts1); expect(response.clientExtensionResults).toEqual(extResults); @@ -183,7 +183,7 @@ test('should include extension results', async done => { }); test('should include extension results when no extensions specified', async done => { - const response = await startAttestation(goodOpts1); + const response = await startRegistration(goodOpts1); expect(response.clientExtensionResults).toEqual({}); diff --git a/packages/browser/src/methods/startAttestation.ts b/packages/browser/src/methods/startRegistration.ts index c762c6f..eec07c5 100644 --- a/packages/browser/src/methods/startAttestation.ts +++ b/packages/browser/src/methods/startRegistration.ts @@ -1,7 +1,7 @@ import { PublicKeyCredentialCreationOptionsJSON, - AttestationCredential, - AttestationCredentialJSON, + RegistrationCredential, + RegistrationCredentialJSON, } from '@simplewebauthn/typescript-types'; import utf8StringToBuffer from '../helpers/utf8StringToBuffer'; @@ -13,11 +13,11 @@ import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDes /** * Begin authenticator "registration" via WebAuthn attestation * - * @param creationOptionsJSON Output from @simplewebauthn/server's generateAttestationOptions(...) + * @param creationOptionsJSON Output from @simplewebauthn/server's generateRegistrationOptions(...) */ -export default async function startAttestation( +export default async function startRegistration( creationOptionsJSON: PublicKeyCredentialCreationOptionsJSON, -): Promise<AttestationCredentialJSON> { +): Promise<RegistrationCredentialJSON> { if (!browserSupportsWebauthn()) { throw new Error('WebAuthn is not supported in this browser'); } @@ -34,16 +34,16 @@ export default async function startAttestation( }; // Wait for the user to complete attestation - const credential = (await navigator.credentials.create({ publicKey })) as AttestationCredential; + const credential = (await navigator.credentials.create({ publicKey })) as RegistrationCredential; if (!credential) { - throw new Error('Attestation was not completed'); + throw new Error('Registration was not completed'); } const { id, rawId, response, type } = credential; // Convert values to base64 to make it easier to send back to the server - const credentialJSON: AttestationCredentialJSON = { + const credentialJSON: RegistrationCredentialJSON = { id, rawId: bufferToBase64URLString(rawId), response: { |