summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src')
-rw-r--r--packages/browser/src/index.test.ts8
-rw-r--r--packages/browser/src/index.ts4
-rw-r--r--packages/browser/src/methods/startAuthentication.test.ts (renamed from packages/browser/src/methods/startAssertion.test.ts)117
-rw-r--r--packages/browser/src/methods/startAuthentication.ts (renamed from packages/browser/src/methods/startAssertion.ts)8
4 files changed, 56 insertions, 81 deletions
diff --git a/packages/browser/src/index.test.ts b/packages/browser/src/index.test.ts
index 0d132ba..ffd3b2b 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 `supportsWebauthn`', () => {
diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts
index 4f42044..520af9a 100644
--- a/packages/browser/src/index.ts
+++ b/packages/browser/src/index.ts
@@ -3,7 +3,7 @@
* @module @simplewebauthn/browser
*/
import startRegistration from './methods/startRegistration';
-import startAssertion from './methods/startAssertion';
+import startAuthentication from './methods/startAuthentication';
import supportsWebauthn from './helpers/supportsWebauthn';
-export { startRegistration, startAssertion, supportsWebauthn };
+export { startRegistration, startAuthentication, supportsWebauthn };
diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAuthentication.test.ts
index f005a26..96b140c 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 supportsWebauthn from '../helpers/supportsWebauthn';
import utf8StringToBuffer from '../helpers/utf8StringToBuffer';
import bufferToBase64URLString from '../helpers/bufferToBase64URLString';
-import startAssertion from './startAssertion';
+import startAuthentication from './startAuthentication';
jest.mock('../helpers/supportsWebauthn');
@@ -43,16 +43,14 @@ const goodOpts2UTF8: PublicKeyCredentialRequestOptionsJSON = {
beforeEach(() => {
// Stub out a response so the method won't throw
- mockNavigatorGet.mockImplementation(
- (): Promise<any> => {
- return new Promise(resolve => {
- resolve({
- response: {},
- getClientExtensionResults: () => ({}),
- });
+ mockNavigatorGet.mockImplementation((): Promise<any> => {
+ return new Promise(resolve => {
+ resolve({
+ response: {},
+ getClientExtensionResults: () => ({}),
});
- },
- );
+ });
+ });
mockSupportsWebauthn.mockReturnValue(true);
});
@@ -63,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;
@@ -77,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,
});
@@ -86,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: [],
@@ -95,26 +93,24 @@ test('should convert allow allowCredential to undefined when empty', async () =>
});
test('should return base64url-encoded response values', async done => {
- mockNavigatorGet.mockImplementation(
- (): Promise<AssertionCredential> => {
- return new Promise(resolve => {
- resolve({
- id: 'foobar',
- rawId: Buffer.from('foobar', 'ascii'),
- response: {
- authenticatorData: Buffer.from(mockAuthenticatorData, 'ascii'),
- clientDataJSON: Buffer.from(mockClientDataJSON, 'ascii'),
- signature: Buffer.from(mockSignature, 'ascii'),
- userHandle: Buffer.from(mockUserHandle, 'ascii'),
- },
- getClientExtensionResults: () => ({}),
- type: 'webauthn.get',
- });
+ mockNavigatorGet.mockImplementation((): Promise<AuthenticationCredential> => {
+ return new Promise(resolve => {
+ resolve({
+ id: 'foobar',
+ rawId: Buffer.from('foobar', 'ascii'),
+ response: {
+ authenticatorData: Buffer.from(mockAuthenticatorData, 'ascii'),
+ clientDataJSON: Buffer.from(mockClientDataJSON, 'ascii'),
+ signature: Buffer.from(mockSignature, 'ascii'),
+ userHandle: Buffer.from(mockUserHandle, 'ascii'),
+ },
+ getClientExtensionResults: () => ({}),
+ type: 'webauthn.get',
});
- },
- );
+ });
+ });
- const response = await startAssertion(goodOpts1);
+ const response = await startAuthentication(goodOpts1);
expect(response.rawId).toEqual('Zm9vYmFy');
expect(response.response.authenticatorData).toEqual('bW9ja0F1dGhlbnRpY2F0b3JEYXRh');
@@ -128,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',
);
@@ -136,44 +132,25 @@ test("should throw error if WebAuthn isn't supported", async done => {
});
test('should throw error if assertion is cancelled for some reason', async done => {
- mockNavigatorGet.mockImplementation(
- (): Promise<null> => {
- return new Promise(resolve => {
- resolve(null);
- });
- },
- );
+ mockNavigatorGet.mockImplementation((): Promise<null> => {
+ return new Promise(resolve => {
+ resolve(null);
+ });
+ });
- await expect(startAssertion(goodOpts1)).rejects.toThrow('Assertion was not completed');
+ await expect(startAuthentication(goodOpts1)).rejects.toThrow('Assertion 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;
expect(new Uint8Array(argsPublicKey.challenge)).toEqual(
new Uint8Array([
- 227,
- 130,
- 132,
- 227,
- 130,
- 140,
- 227,
- 130,
- 132,
- 227,
- 130,
- 140,
- 227,
- 129,
- 160,
- 227,
- 129,
- 156,
+ 227, 130, 132, 227, 130, 140, 227, 130, 132, 227, 130, 140, 227, 129, 160, 227, 129, 156,
]),
);
@@ -191,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;
@@ -201,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;
@@ -219,16 +196,14 @@ test('should include extension results', async done => {
};
// Mock extension return values from authenticator
- mockNavigatorGet.mockImplementation(
- (): Promise<any> => {
- return new Promise(resolve => {
- resolve({ response: {}, getClientExtensionResults: () => extResults });
- });
- },
- );
+ mockNavigatorGet.mockImplementation((): Promise<any> => {
+ return new Promise(resolve => {
+ resolve({ response: {}, getClientExtensionResults: () => extResults });
+ });
+ });
// 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);
@@ -236,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 786d55b..1764ff1 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';
@@ -17,7 +17,7 @@ import toPublicKeyCredentialDescriptor from '../helpers/toPublicKeyCredentialDes
*/
export default async function startAssertion(
requestOptionsJSON: PublicKeyCredentialRequestOptionsJSON,
-): Promise<AssertionCredentialJSON> {
+): Promise<AuthenticationCredentialJSON> {
if (!supportsWebauthn()) {
throw new Error('WebAuthn is not supported in this browser');
}
@@ -37,7 +37,7 @@ 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');