@dfns/sdk-react-native 0.3.4 → 0.4.0-alpha.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/index.d.ts +5 -10
- package/index.js +27 -26
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CredentialSigner, CredentialStore, Fido2Assertion, Fido2Attestation, UserActionChallenge, UserRegistrationChallenge } from '@dfns/sdk';
|
|
2
2
|
export declare const DEFAULT_WAIT_TIMEOUT = 60000;
|
|
3
|
-
type PasskeysOptions = {
|
|
4
|
-
rpId: string;
|
|
3
|
+
export type PasskeysOptions = {
|
|
5
4
|
timeout?: number;
|
|
6
5
|
};
|
|
7
6
|
export declare class PasskeysSigner implements CredentialSigner<Fido2Assertion>, CredentialStore<Fido2Attestation> {
|
|
8
|
-
private
|
|
9
|
-
constructor(options
|
|
10
|
-
sign(challenge:
|
|
11
|
-
key: AllowCredential[];
|
|
12
|
-
webauthn: AllowCredential[];
|
|
13
|
-
}): Promise<Fido2Assertion>;
|
|
7
|
+
private platform;
|
|
8
|
+
constructor(options?: PasskeysOptions);
|
|
9
|
+
sign(challenge: UserActionChallenge): Promise<Fido2Assertion>;
|
|
14
10
|
create(challenge: UserRegistrationChallenge): Promise<Fido2Attestation>;
|
|
15
11
|
}
|
|
16
|
-
export {};
|
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PasskeysSigner = exports.DEFAULT_WAIT_TIMEOUT = void 0;
|
|
4
|
+
const sdk_1 = require("@dfns/sdk");
|
|
4
5
|
const utils_1 = require("@dfns/sdk/utils");
|
|
5
6
|
const react_native_1 = require("react-native");
|
|
6
7
|
const react_native_passkey_1 = require("react-native-passkey");
|
|
@@ -13,21 +14,21 @@ const b64UrlSafeToStandard = (urlSafe) => {
|
|
|
13
14
|
};
|
|
14
15
|
// react-native-passkey is incorrect encoding the credId with standard base64 for
|
|
15
16
|
// some reason. we have to undo that.
|
|
16
|
-
class
|
|
17
|
+
class Android {
|
|
17
18
|
constructor(options) {
|
|
18
19
|
this.options = options;
|
|
19
20
|
}
|
|
20
|
-
async sign(challenge
|
|
21
|
+
async sign(challenge) {
|
|
21
22
|
const request = {
|
|
22
|
-
challenge: challenge,
|
|
23
|
-
allowCredentials: allowCredentials.webauthn.map(({ id, type, transports }) => ({
|
|
23
|
+
challenge: challenge.challenge,
|
|
24
|
+
allowCredentials: challenge.allowCredentials.webauthn.map(({ id, type, transports }) => ({
|
|
24
25
|
id: id,
|
|
25
26
|
type,
|
|
26
27
|
transports: transports ?? [],
|
|
27
28
|
})),
|
|
28
|
-
rpId:
|
|
29
|
-
userVerification: '
|
|
30
|
-
timeout: this.options
|
|
29
|
+
rpId: challenge.rp.id,
|
|
30
|
+
userVerification: 'preferred',
|
|
31
|
+
timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
31
32
|
};
|
|
32
33
|
const credential = await react_native_passkey_1.Passkey.authenticate(request);
|
|
33
34
|
return {
|
|
@@ -42,7 +43,7 @@ class AndroidPasskeys {
|
|
|
42
43
|
};
|
|
43
44
|
}
|
|
44
45
|
async create(challenge) {
|
|
45
|
-
const
|
|
46
|
+
const request = {
|
|
46
47
|
challenge: challenge.challenge,
|
|
47
48
|
pubKeyCredParams: challenge.pubKeyCredParams,
|
|
48
49
|
rp: challenge.rp,
|
|
@@ -57,9 +58,9 @@ class AndroidPasskeys {
|
|
|
57
58
|
type: cred.type,
|
|
58
59
|
})),
|
|
59
60
|
authenticatorSelection: challenge.authenticatorSelection,
|
|
60
|
-
timeout: this.options
|
|
61
|
+
timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
61
62
|
};
|
|
62
|
-
const result = await react_native_passkey_1.Passkey.register(
|
|
63
|
+
const result = await react_native_passkey_1.Passkey.register(request);
|
|
63
64
|
return {
|
|
64
65
|
credentialKind: 'Fido2',
|
|
65
66
|
credentialInfo: {
|
|
@@ -73,21 +74,21 @@ class AndroidPasskeys {
|
|
|
73
74
|
// react-native-passkey's iOS implementation is not WebAuthn spec compliant. all values
|
|
74
75
|
// are standard base64 encoded instead of base64url encoded. we have to convert the
|
|
75
76
|
// encoding in both directions.
|
|
76
|
-
class
|
|
77
|
+
class iOS {
|
|
77
78
|
constructor(options) {
|
|
78
79
|
this.options = options;
|
|
79
80
|
}
|
|
80
|
-
async sign(challenge
|
|
81
|
+
async sign(challenge) {
|
|
81
82
|
const request = {
|
|
82
|
-
challenge: b64UrlSafeToStandard(challenge),
|
|
83
|
-
allowCredentials: allowCredentials.webauthn.map(({ id, type, transports }) => ({
|
|
83
|
+
challenge: b64UrlSafeToStandard(challenge.challenge),
|
|
84
|
+
allowCredentials: challenge.allowCredentials.webauthn.map(({ id, type, transports }) => ({
|
|
84
85
|
id: b64UrlSafeToStandard(id),
|
|
85
86
|
type,
|
|
86
87
|
transports: transports ?? [],
|
|
87
88
|
})),
|
|
88
|
-
rpId:
|
|
89
|
-
userVerification: '
|
|
90
|
-
timeout: this.options
|
|
89
|
+
rpId: challenge.rp.id,
|
|
90
|
+
userVerification: 'preferred',
|
|
91
|
+
timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
91
92
|
};
|
|
92
93
|
const credential = await react_native_passkey_1.Passkey.authenticate(request);
|
|
93
94
|
return {
|
|
@@ -102,7 +103,7 @@ class iOsPasskeys {
|
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
105
|
async create(challenge) {
|
|
105
|
-
const
|
|
106
|
+
const request = {
|
|
106
107
|
challenge: b64UrlSafeToStandard(challenge.challenge),
|
|
107
108
|
pubKeyCredParams: challenge.pubKeyCredParams,
|
|
108
109
|
rp: challenge.rp,
|
|
@@ -117,9 +118,9 @@ class iOsPasskeys {
|
|
|
117
118
|
type: cred.type,
|
|
118
119
|
})),
|
|
119
120
|
authenticatorSelection: challenge.authenticatorSelection,
|
|
120
|
-
timeout: this.options
|
|
121
|
+
timeout: this.options?.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
121
122
|
};
|
|
122
|
-
const result = await react_native_passkey_1.Passkey.register(
|
|
123
|
+
const result = await react_native_passkey_1.Passkey.register(request);
|
|
123
124
|
return {
|
|
124
125
|
credentialKind: 'Fido2',
|
|
125
126
|
credentialInfo: {
|
|
@@ -134,20 +135,20 @@ class PasskeysSigner {
|
|
|
134
135
|
constructor(options) {
|
|
135
136
|
switch (react_native_1.Platform.OS) {
|
|
136
137
|
case 'android':
|
|
137
|
-
this.
|
|
138
|
+
this.platform = new Android(options);
|
|
138
139
|
break;
|
|
139
140
|
case 'ios':
|
|
140
|
-
this.
|
|
141
|
+
this.platform = new iOS(options);
|
|
141
142
|
break;
|
|
142
143
|
default:
|
|
143
|
-
throw
|
|
144
|
+
throw new sdk_1.DfnsError(-1, `${react_native_1.Platform.OS} is not supported`);
|
|
144
145
|
}
|
|
145
146
|
}
|
|
146
|
-
async sign(challenge
|
|
147
|
-
return this.
|
|
147
|
+
async sign(challenge) {
|
|
148
|
+
return this.platform.sign(challenge);
|
|
148
149
|
}
|
|
149
150
|
async create(challenge) {
|
|
150
|
-
return this.
|
|
151
|
+
return this.platform.create(challenge);
|
|
151
152
|
}
|
|
152
153
|
}
|
|
153
154
|
exports.PasskeysSigner = PasskeysSigner;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dfns/sdk-react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-alpha.2",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"buffer": "6.0.3",
|
|
6
6
|
"cross-fetch": "3.1.6",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"uuid": "9.0.0"
|
|
10
10
|
},
|
|
11
11
|
"peerDependencies": {
|
|
12
|
-
"@dfns/sdk": "0.
|
|
12
|
+
"@dfns/sdk": "0.4.0-alpha.2"
|
|
13
13
|
},
|
|
14
14
|
"main": "./index.js",
|
|
15
15
|
"type": "commonjs"
|