@dfns/sdk-react-native 0.6.4 → 0.6.6
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/index.d.ts +2 -3
- package/index.js +20 -37
- package/package.json +3 -3
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CredentialSigner, CredentialStore, Fido2Assertion, Fido2Attestation, UserActionChallenge, UserRegistrationChallenge } from '@dfns/sdk';
|
|
2
2
|
export declare const DEFAULT_WAIT_TIMEOUT = 60000;
|
|
3
|
-
|
|
3
|
+
export type PasskeysSignerConf = {
|
|
4
4
|
/**
|
|
5
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
6
|
* - id: The relying party identifier is a valid domain string identifying the WebAuthn Relying Party.
|
|
@@ -18,11 +18,10 @@ interface PasskeysSignerConf {
|
|
|
18
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
19
|
* */
|
|
20
20
|
timeout?: number;
|
|
21
|
-
}
|
|
21
|
+
};
|
|
22
22
|
export declare class PasskeysSigner implements CredentialSigner<Fido2Assertion>, CredentialStore<Fido2Attestation> {
|
|
23
23
|
private platform;
|
|
24
24
|
constructor(conf: PasskeysSignerConf);
|
|
25
25
|
sign(challenge: UserActionChallenge): Promise<Fido2Assertion>;
|
|
26
26
|
create(challenge: UserRegistrationChallenge): Promise<Fido2Attestation>;
|
|
27
27
|
}
|
|
28
|
-
export {};
|
package/index.js
CHANGED
|
@@ -6,19 +6,11 @@ const utils_1 = require("@dfns/sdk/utils");
|
|
|
6
6
|
const react_native_1 = require("react-native");
|
|
7
7
|
const react_native_passkey_1 = require("react-native-passkey");
|
|
8
8
|
exports.DEFAULT_WAIT_TIMEOUT = 60000;
|
|
9
|
-
const b64StandardToUrlSafe = (standard) => {
|
|
10
|
-
return standard.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
11
|
-
};
|
|
12
|
-
const b64UrlSafeToStandard = (urlSafe) => {
|
|
13
|
-
return (urlSafe + '==='.slice((urlSafe.length + 3) % 4)).replace(/-/g, '+').replace(/_/g, '/');
|
|
14
|
-
};
|
|
15
|
-
// react-native-passkey is incorrect encoding the credId with standard base64 for
|
|
16
|
-
// some reason. we have to undo that.
|
|
17
9
|
class AndroidPasskeys {
|
|
18
10
|
constructor(conf) {
|
|
19
11
|
this.conf = conf;
|
|
20
12
|
if (!this.conf?.relyingParty?.id || !this.conf?.relyingParty?.name) {
|
|
21
|
-
throw new sdk_1.DfnsError(-1,
|
|
13
|
+
throw new sdk_1.DfnsError(-1, 'Relying party ID and name must be specified in the WebauthnSigner initializer');
|
|
22
14
|
}
|
|
23
15
|
}
|
|
24
16
|
async sign(challenge) {
|
|
@@ -29,11 +21,11 @@ class AndroidPasskeys {
|
|
|
29
21
|
userVerification: challenge.userVerification,
|
|
30
22
|
timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
31
23
|
};
|
|
32
|
-
const credential = await react_native_passkey_1.Passkey.
|
|
24
|
+
const credential = await react_native_passkey_1.Passkey.get(request);
|
|
33
25
|
return {
|
|
34
26
|
kind: 'Fido2',
|
|
35
27
|
credentialAssertion: {
|
|
36
|
-
credId:
|
|
28
|
+
credId: credential.id,
|
|
37
29
|
clientData: credential.response.clientDataJSON,
|
|
38
30
|
authenticatorData: credential.response.authenticatorData,
|
|
39
31
|
signature: credential.response.signature,
|
|
@@ -59,53 +51,47 @@ class AndroidPasskeys {
|
|
|
59
51
|
authenticatorSelection: challenge.authenticatorSelection,
|
|
60
52
|
timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
61
53
|
};
|
|
62
|
-
const result = await react_native_passkey_1.Passkey.
|
|
54
|
+
const result = await react_native_passkey_1.Passkey.create(request);
|
|
63
55
|
return {
|
|
64
56
|
credentialKind: 'Fido2',
|
|
65
57
|
credentialInfo: {
|
|
66
|
-
credId:
|
|
58
|
+
credId: result.id,
|
|
67
59
|
attestationData: result.response.attestationObject,
|
|
68
60
|
clientData: result.response.clientDataJSON,
|
|
69
61
|
},
|
|
70
62
|
};
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
|
-
// react-native-passkey's iOS implementation is not WebAuthn spec compliant. all values
|
|
74
|
-
// are standard base64 encoded instead of base64url encoded. we have to convert the
|
|
75
|
-
// encoding in both directions.
|
|
76
65
|
class iOSPasskeys {
|
|
77
66
|
constructor(conf) {
|
|
78
67
|
this.conf = conf;
|
|
79
68
|
if (!this.conf?.relyingParty?.id || !this.conf?.relyingParty?.name) {
|
|
80
|
-
throw new sdk_1.DfnsError(-1,
|
|
69
|
+
throw new sdk_1.DfnsError(-1, 'Relying party ID and name must be specified in the WebauthnSigner initializer');
|
|
81
70
|
}
|
|
82
71
|
}
|
|
83
72
|
async sign(challenge) {
|
|
84
73
|
const request = {
|
|
85
|
-
challenge:
|
|
86
|
-
allowCredentials: challenge.allowCredentials.webauthn
|
|
87
|
-
id: b64UrlSafeToStandard(id),
|
|
88
|
-
type,
|
|
89
|
-
})),
|
|
74
|
+
challenge: challenge.challenge,
|
|
75
|
+
allowCredentials: challenge.allowCredentials.webauthn,
|
|
90
76
|
rpId: this.conf.relyingParty.id,
|
|
91
77
|
userVerification: 'preferred',
|
|
92
78
|
timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
93
79
|
};
|
|
94
|
-
const credential = await react_native_passkey_1.Passkey.
|
|
80
|
+
const credential = await react_native_passkey_1.Passkey.get(request);
|
|
95
81
|
return {
|
|
96
82
|
kind: 'Fido2',
|
|
97
83
|
credentialAssertion: {
|
|
98
|
-
credId:
|
|
99
|
-
clientData:
|
|
100
|
-
authenticatorData:
|
|
101
|
-
signature:
|
|
102
|
-
userHandle:
|
|
84
|
+
credId: credential.id,
|
|
85
|
+
clientData: credential.response.clientDataJSON,
|
|
86
|
+
authenticatorData: credential.response.authenticatorData,
|
|
87
|
+
signature: credential.response.signature,
|
|
88
|
+
userHandle: credential.response.userHandle,
|
|
103
89
|
},
|
|
104
90
|
};
|
|
105
91
|
}
|
|
106
92
|
async create(challenge) {
|
|
107
93
|
const request = {
|
|
108
|
-
challenge:
|
|
94
|
+
challenge: challenge.challenge,
|
|
109
95
|
pubKeyCredParams: challenge.pubKeyCredParams,
|
|
110
96
|
rp: this.conf.relyingParty,
|
|
111
97
|
user: {
|
|
@@ -114,20 +100,17 @@ class iOSPasskeys {
|
|
|
114
100
|
name: challenge.user.name,
|
|
115
101
|
},
|
|
116
102
|
attestation: challenge.attestation,
|
|
117
|
-
excludeCredentials: challenge.excludeCredentials
|
|
118
|
-
id: b64UrlSafeToStandard(id),
|
|
119
|
-
type,
|
|
120
|
-
})),
|
|
103
|
+
excludeCredentials: challenge.excludeCredentials,
|
|
121
104
|
authenticatorSelection: challenge.authenticatorSelection,
|
|
122
105
|
timeout: this.conf.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
123
106
|
};
|
|
124
|
-
const result = await react_native_passkey_1.Passkey.
|
|
107
|
+
const result = await react_native_passkey_1.Passkey.create(request);
|
|
125
108
|
return {
|
|
126
109
|
credentialKind: 'Fido2',
|
|
127
110
|
credentialInfo: {
|
|
128
|
-
credId:
|
|
129
|
-
attestationData:
|
|
130
|
-
clientData:
|
|
111
|
+
credId: result.id,
|
|
112
|
+
attestationData: result.response.attestationObject,
|
|
113
|
+
clientData: result.response.clientDataJSON,
|
|
131
114
|
},
|
|
132
115
|
};
|
|
133
116
|
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dfns/sdk-react-native",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
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": "^
|
|
8
|
+
"react-native-passkey": "^3.1.0",
|
|
9
9
|
"uuid": "9.0.0"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@dfns/sdk": "0.6.
|
|
12
|
+
"@dfns/sdk": "0.6.6"
|
|
13
13
|
},
|
|
14
14
|
"main": "./index.js",
|
|
15
15
|
"type": "commonjs"
|