Skip to content

Commit

Permalink
Merge pull request #198 from MasterKale/feat/cable-take-2
Browse files Browse the repository at this point in the history
feat/cable-take-2
  • Loading branch information
MasterKale authored Apr 28, 2022
2 parents db2d9b2 + 02396a1 commit 76383fd
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ export default function toPublicKeyCredentialDescriptor(
return {
...descriptor,
id: base64URLStringToBuffer(id),
/**
* `descriptor.transports` is an array of our `AuthenticatorTransport` that includes newer
* transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
* are fine to pass to WebAuthn since browsers will recognize the new value.
*/
transports: descriptor.transports as AuthenticatorTransport[],
};
}
17 changes: 17 additions & 0 deletions packages/browser/src/methods/startAuthentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,23 @@ test('should include extension results when no extensions specified', async () =
expect(response.clientExtensionResults).toEqual({});
});

test('should support "cable" transport', async () => {
const opts: PublicKeyCredentialRequestOptionsJSON = {
...goodOpts1,
allowCredentials: [
{
...goodOpts1.allowCredentials![0],
transports: ["cable"],
},
]
};

await startAuthentication(opts);

expect(mockNavigatorGet.mock.calls[0][0].publicKey.allowCredentials[0].transports[0])
.toEqual("cable");
});

describe('WebAuthnError', () => {
describe('AbortError', () => {
const AbortError = generateCustomError('AbortError');
Expand Down
35 changes: 35 additions & 0 deletions packages/browser/src/methods/startRegistration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,41 @@ test('should include extension results when no extensions specified', async () =
expect(response.clientExtensionResults).toEqual({});
});

test('should support "cable" transport in excludeCredentials', async () => {
const opts: PublicKeyCredentialCreationOptionsJSON = {
...goodOpts1,
excludeCredentials: [
{
...goodOpts1.excludeCredentials![0],
transports: ["cable"],
},
]
};

await startRegistration(opts);

expect(mockNavigatorCreate.mock.calls[0][0].publicKey.excludeCredentials[0].transports[0])
.toEqual("cable");
});

test('should return "cable" transport from response', async () => {
mockNavigatorCreate.mockResolvedValue({
id: 'foobar',
rawId: utf8StringToBuffer('foobar'),
response: {
attestationObject: Buffer.from(mockAttestationObject, 'ascii'),
clientDataJSON: Buffer.from(mockClientDataJSON, 'ascii'),
getTransports: () => (["cable"]),
},
getClientExtensionResults: () => ({}),
type: 'webauthn.create',
});

const response = await startRegistration(goodOpts1);

expect(response.transports).toEqual(["cable"]);
});

describe('WebAuthnError', () => {
describe('AbortError', () => {
const AbortError = generateCustomError('AbortError');
Expand Down
1 change: 0 additions & 1 deletion packages/typescript-types/extract-dom-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const types = [
'AuthenticatorAssertionResponse',
'AttestationConveyancePreference',
'AuthenticatorAttestationResponse',
'AuthenticatorTransport',
'AuthenticationExtensionsClientInputs',
'AuthenticationExtensionsClientOutputs',
'AuthenticatorSelectionCriteria',
Expand Down
10 changes: 8 additions & 2 deletions packages/typescript-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import type {
AuthenticatorAssertionResponse,
AuthenticatorAttestationResponse,
AuthenticatorTransport,
COSEAlgorithmIdentifier,
PublicKeyCredential,
PublicKeyCredentialCreationOptions,
Expand Down Expand Up @@ -43,8 +42,9 @@ export interface PublicKeyCredentialRequestOptionsJSON
}

export interface PublicKeyCredentialDescriptorJSON
extends Omit<PublicKeyCredentialDescriptor, 'id'> {
extends Omit<PublicKeyCredentialDescriptor, 'id' | 'transports'> {
id: Base64URLString;
transports?: AuthenticatorTransport[];
}

export interface PublicKeyCredentialUserEntityJSON
Expand Down Expand Up @@ -146,3 +146,9 @@ export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAtt
getPublicKey?: () => ArrayBuffer;
getPublicKeyAlgorithm?: () => COSEAlgorithmIdentifier[];
}

/**
* Communication methods by which an authenticator can talk with the browser to perform WebAuthn
* registration and authentication.
*/
export type AuthenticatorTransport = "ble" | "internal" | "nfc" | "usb" | "cable";

0 comments on commit 76383fd

Please sign in to comment.