@dfns/sdk-react-native 0.6.0-rc1 → 0.6.1-rc.0

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.
Files changed (3) hide show
  1. package/index.d.ts +20 -3
  2. package/index.js +25 -19
  3. package/package.json +3 -3
package/index.d.ts CHANGED
@@ -1,11 +1,28 @@
1
1
  import { CredentialSigner, CredentialStore, Fido2Assertion, Fido2Attestation, UserActionChallenge, UserRegistrationChallenge } from '@dfns/sdk';
2
2
  export declare const DEFAULT_WAIT_TIMEOUT = 60000;
3
- export type PasskeysOptions = {
3
+ interface PasskeysSignerConf {
4
+ /**
5
+ * The relying party identifies your application to users, when users create/use passkeys. (Read more [here](https://www.w3.org/TR/webauthn-2/#relying-party)).
6
+ * - id: The relying party identifier is a valid domain string identifying the WebAuthn Relying Party.
7
+ * In other words, its the domain your application is running on, which will be tied to the passkeys that users create.
8
+ * We advise to use the root domain, not the full domain (eg `acme.com`, not `app.acme.com` nor `foo.app.acme.com`), that way, passkeys created
9
+ * by your users can be re-used on other subdomains (eg. on `foo.acme.com` and `bar.acme.com`) in the future. Read more [here](https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#rp).
10
+ * - name: A string representing the name of the relying party (e.g. "Acme"). This is the name the user will be presented with when creating or validating a WebAuthn operation.
11
+ */
12
+ relyingParty: {
13
+ id: string;
14
+ name: string;
15
+ };
16
+ /**
17
+ * Timeout to use for navigotor.credentials calls. That's the time after which if user did not successfully
18
+ * select and use his passkey, an error will be thrown by webauthn client. Read more [here](https://developer.mozilla.org/en-US/docs/Web/API/PublicKeyCredentialCreationOptions#timeout).
19
+ * */
4
20
  timeout?: number;
5
- };
21
+ }
6
22
  export declare class PasskeysSigner implements CredentialSigner<Fido2Assertion>, CredentialStore<Fido2Attestation> {
7
23
  private platform;
8
- constructor(options?: PasskeysOptions);
24
+ constructor(conf: PasskeysSignerConf);
9
25
  sign(challenge: UserActionChallenge): Promise<Fido2Assertion>;
10
26
  create(challenge: UserRegistrationChallenge): Promise<Fido2Attestation>;
11
27
  }
28
+ export {};
package/index.js CHANGED
@@ -15,18 +15,21 @@ const b64UrlSafeToStandard = (urlSafe) => {
15
15
  // react-native-passkey is incorrect encoding the credId with standard base64 for
16
16
  // some reason. we have to undo that.
17
17
  class AndroidPasskeys {
18
- constructor(options) {
19
- this.options = options;
18
+ constructor(conf) {
19
+ this.conf = conf;
20
+ if (!this.conf?.relyingParty?.id || !this.conf?.relyingParty?.name) {
21
+ throw new sdk_1.DfnsError(-1, `Relying party ID and name must be specified in the WebauthnSigner initializer`);
22
+ }
20
23
  }
21
24
  async sign(challenge) {
22
25
  const request = {
23
26
  challenge: challenge.challenge,
24
27
  allowCredentials: challenge.allowCredentials.webauthn,
25
- rpId: challenge.rp.id,
28
+ rpId: this.conf.relyingParty.id,
26
29
  userVerification: challenge.userVerification,
27
- timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
30
+ timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
28
31
  };
29
- const credential = await react_native_passkey_1.Passkey.get(request);
32
+ const credential = await react_native_passkey_1.Passkey.authenticate(request);
30
33
  return {
31
34
  kind: 'Fido2',
32
35
  credentialAssertion: {
@@ -42,7 +45,7 @@ class AndroidPasskeys {
42
45
  const request = {
43
46
  challenge: challenge.challenge,
44
47
  pubKeyCredParams: challenge.pubKeyCredParams,
45
- rp: challenge.rp,
48
+ rp: this.conf.relyingParty,
46
49
  user: {
47
50
  displayName: challenge.user.displayName,
48
51
  id: (0, utils_1.toBase64Url)(challenge.user.id),
@@ -54,9 +57,9 @@ class AndroidPasskeys {
54
57
  type: v.type,
55
58
  })),
56
59
  authenticatorSelection: challenge.authenticatorSelection,
57
- timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
60
+ timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
58
61
  };
59
- const result = await react_native_passkey_1.Passkey.create(request);
62
+ const result = await react_native_passkey_1.Passkey.register(request);
60
63
  return {
61
64
  credentialKind: 'Fido2',
62
65
  credentialInfo: {
@@ -71,8 +74,11 @@ class AndroidPasskeys {
71
74
  // are standard base64 encoded instead of base64url encoded. we have to convert the
72
75
  // encoding in both directions.
73
76
  class iOSPasskeys {
74
- constructor(options) {
75
- this.options = options;
77
+ constructor(conf) {
78
+ this.conf = conf;
79
+ if (!this.conf?.relyingParty?.id || !this.conf?.relyingParty?.name) {
80
+ throw new sdk_1.DfnsError(-1, `Relying party ID and name must be specified in the WebauthnSigner initializer`);
81
+ }
76
82
  }
77
83
  async sign(challenge) {
78
84
  const request = {
@@ -81,11 +87,11 @@ class iOSPasskeys {
81
87
  id: b64UrlSafeToStandard(id),
82
88
  type,
83
89
  })),
84
- rpId: challenge.rp.id,
90
+ rpId: this.conf.relyingParty.id,
85
91
  userVerification: 'preferred',
86
- timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
92
+ timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
87
93
  };
88
- const credential = await react_native_passkey_1.Passkey.get(request);
94
+ const credential = await react_native_passkey_1.Passkey.authenticate(request);
89
95
  return {
90
96
  kind: 'Fido2',
91
97
  credentialAssertion: {
@@ -101,7 +107,7 @@ class iOSPasskeys {
101
107
  const request = {
102
108
  challenge: b64UrlSafeToStandard(challenge.challenge),
103
109
  pubKeyCredParams: challenge.pubKeyCredParams,
104
- rp: challenge.rp,
110
+ rp: this.conf.relyingParty,
105
111
  user: {
106
112
  displayName: challenge.user.displayName,
107
113
  id: (0, utils_1.toBase64Url)(challenge.user.id),
@@ -113,9 +119,9 @@ class iOSPasskeys {
113
119
  type,
114
120
  })),
115
121
  authenticatorSelection: challenge.authenticatorSelection,
116
- timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
122
+ timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
117
123
  };
118
- const result = await react_native_passkey_1.Passkey.create(request);
124
+ const result = await react_native_passkey_1.Passkey.register(request);
119
125
  return {
120
126
  credentialKind: 'Fido2',
121
127
  credentialInfo: {
@@ -127,13 +133,13 @@ class iOSPasskeys {
127
133
  }
128
134
  }
129
135
  class PasskeysSigner {
130
- constructor(options) {
136
+ constructor(conf) {
131
137
  switch (react_native_1.Platform.OS) {
132
138
  case 'android':
133
- this.platform = new AndroidPasskeys(options);
139
+ this.platform = new AndroidPasskeys(conf);
134
140
  break;
135
141
  case 'ios':
136
- this.platform = new iOSPasskeys(options);
142
+ this.platform = new iOSPasskeys(conf);
137
143
  break;
138
144
  default:
139
145
  throw new sdk_1.DfnsError(-1, `${react_native_1.Platform.OS} is not supported`);
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@dfns/sdk-react-native",
3
- "version": "0.6.0-rc1",
3
+ "version": "0.6.1-rc.0",
4
4
  "dependencies": {
5
5
  "buffer": "6.0.3",
6
6
  "cross-fetch": "3.1.6",
7
7
  "react-native": "0.74.1",
8
- "react-native-passkey": "3.0.0-rc2",
8
+ "react-native-passkey": "^2.1.1",
9
9
  "uuid": "9.0.0"
10
10
  },
11
11
  "peerDependencies": {
12
- "@dfns/sdk": "0.6.0-rc1"
12
+ "@dfns/sdk": "0.6.1-rc.0"
13
13
  },
14
14
  "main": "./index.js",
15
15
  "type": "commonjs"