@dfns/sdk-browser 0.7.8 → 0.7.9-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dfns/sdk-browser",
3
- "version": "0.7.8",
3
+ "version": "0.7.9-rc.2",
4
4
  "dependencies": {
5
5
  "buffer": "6.0.3",
6
6
  "cross-fetch": "3.1.6"
7
7
  },
8
8
  "peerDependencies": {
9
- "@dfns/sdk": "0.7.8"
9
+ "@dfns/sdk": "0.7.9-rc.2"
10
10
  },
11
11
  "main": "./index.js",
12
12
  "type": "commonjs"
@@ -22,7 +22,9 @@ interface WebAuthnSignerConf {
22
22
  }
23
23
  export declare class WebAuthnSigner implements CredentialSigner<Fido2Assertion>, CredentialStore<Fido2Attestation> {
24
24
  private conf;
25
+ private _signal?;
25
26
  constructor(conf: WebAuthnSignerConf);
27
+ set signal(signal: AbortSignal);
26
28
  sign(challenge: UserActionChallenge): Promise<Fido2Assertion>;
27
29
  create(challenge: CreateRegistrationChallengeResponse | (CreateCredentialChallengeResponse & {
28
30
  kind: 'Fido2';
@@ -12,69 +12,84 @@ class WebAuthnSigner {
12
12
  throw new sdk_1.DfnsError(-1, `Relying party ID and name must be specified in the WebauthnSigner initializer`);
13
13
  }
14
14
  }
15
+ set signal(signal) {
16
+ this._signal = signal;
17
+ }
15
18
  async sign(challenge) {
16
- const response = await navigator.credentials.get({
17
- publicKey: {
18
- challenge: buffer_1.Buffer.from(challenge.challenge),
19
- allowCredentials: challenge.allowCredentials.webauthn.map(({ id, type }) => ({
20
- id: (0, utils_1.fromBase64Url)(id),
21
- type,
22
- })),
23
- rpId: this.conf.relyingParty.id,
24
- userVerification: challenge.userVerification,
25
- timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
26
- },
27
- });
28
- if (response === null) {
29
- throw new sdk_1.DfnsError(-1, 'Failed to sign with WebAuthn credential');
19
+ try {
20
+ const response = await navigator.credentials.get({
21
+ publicKey: {
22
+ challenge: buffer_1.Buffer.from(challenge.challenge),
23
+ allowCredentials: challenge.allowCredentials.webauthn.map(({ id, type }) => ({
24
+ id: (0, utils_1.fromBase64Url)(id),
25
+ type,
26
+ })),
27
+ rpId: this.conf.relyingParty.id,
28
+ userVerification: challenge.userVerification,
29
+ timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
30
+ },
31
+ signal: this._signal,
32
+ });
33
+ if (response === null) {
34
+ throw new sdk_1.DfnsError(-1, 'Failed to sign with WebAuthn credential');
35
+ }
36
+ const credential = response;
37
+ const assertion = credential.response;
38
+ return {
39
+ kind: 'Fido2',
40
+ credentialAssertion: {
41
+ credId: credential.id,
42
+ clientData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.clientDataJSON)),
43
+ authenticatorData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.authenticatorData)),
44
+ signature: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.signature)),
45
+ userHandle: assertion.userHandle ? (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.userHandle)) : undefined,
46
+ },
47
+ };
48
+ }
49
+ finally {
50
+ this._signal = undefined;
30
51
  }
31
- const credential = response;
32
- const assertion = credential.response;
33
- return {
34
- kind: 'Fido2',
35
- credentialAssertion: {
36
- credId: credential.id,
37
- clientData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.clientDataJSON)),
38
- authenticatorData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.authenticatorData)),
39
- signature: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.signature)),
40
- userHandle: assertion.userHandle ? (0, utils_1.toBase64Url)(buffer_1.Buffer.from(assertion.userHandle)) : undefined,
41
- },
42
- };
43
52
  }
44
53
  async create(challenge) {
45
- const options = {
46
- publicKey: {
47
- challenge: buffer_1.Buffer.from(challenge.challenge),
48
- pubKeyCredParams: challenge.pubKeyCredParams,
49
- rp: this.conf.relyingParty,
50
- user: {
51
- displayName: challenge.user.displayName,
52
- id: buffer_1.Buffer.from(challenge.user.id),
53
- name: challenge.user.name,
54
+ try {
55
+ const options = {
56
+ publicKey: {
57
+ challenge: buffer_1.Buffer.from(challenge.challenge),
58
+ pubKeyCredParams: challenge.pubKeyCredParams,
59
+ rp: this.conf.relyingParty,
60
+ user: {
61
+ displayName: challenge.user.displayName,
62
+ id: buffer_1.Buffer.from(challenge.user.id),
63
+ name: challenge.user.name,
64
+ },
65
+ attestation: challenge.attestation,
66
+ excludeCredentials: challenge.excludeCredentials.map(({ id, type }) => ({
67
+ id: (0, utils_1.fromBase64Url)(id),
68
+ type,
69
+ })),
70
+ authenticatorSelection: challenge.authenticatorSelection,
71
+ timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
72
+ },
73
+ signal: this._signal,
74
+ };
75
+ const response = await navigator.credentials.create(options);
76
+ if (response === null) {
77
+ throw new sdk_1.DfnsError(-1, `Failed to create and sign with WebAuthn credential`);
78
+ }
79
+ const credential = response;
80
+ const attestation = credential.response;
81
+ return {
82
+ credentialKind: 'Fido2',
83
+ credentialInfo: {
84
+ credId: credential.id,
85
+ attestationData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(attestation.attestationObject)),
86
+ clientData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(attestation.clientDataJSON)),
54
87
  },
55
- attestation: challenge.attestation,
56
- excludeCredentials: challenge.excludeCredentials.map(({ id, type }) => ({
57
- id: (0, utils_1.fromBase64Url)(id),
58
- type,
59
- })),
60
- authenticatorSelection: challenge.authenticatorSelection,
61
- timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
62
- },
63
- };
64
- const response = await navigator.credentials.create(options);
65
- if (response === null) {
66
- throw new sdk_1.DfnsError(-1, `Failed to create and sign with WebAuthn credential`);
88
+ };
89
+ }
90
+ finally {
91
+ this._signal = undefined;
67
92
  }
68
- const credential = response;
69
- const attestation = credential.response;
70
- return {
71
- credentialKind: 'Fido2',
72
- credentialInfo: {
73
- credId: credential.id,
74
- attestationData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(attestation.attestationObject)),
75
- clientData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(attestation.clientDataJSON)),
76
- },
77
- };
78
93
  }
79
94
  }
80
95
  exports.WebAuthnSigner = WebAuthnSigner;