@dfns/sdk-react-native 0.3.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.
- package/index.d.ts +14 -0
- package/index.js +68 -0
- package/package.json +15 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AllowCredential, CredentialSigner, CredentialStore, Fido2Assertion, Fido2Attestation, UserRegistrationChallenge } from '@dfns/sdk';
|
|
2
|
+
export declare const DEFAULT_WAIT_TIMEOUT = 60000;
|
|
3
|
+
export declare class PasskeySigner implements CredentialSigner<Fido2Assertion>, CredentialStore<Fido2Attestation> {
|
|
4
|
+
private options;
|
|
5
|
+
constructor(options: {
|
|
6
|
+
rpId: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
});
|
|
9
|
+
sign(challenge: string, allowCredentials: {
|
|
10
|
+
key: AllowCredential[];
|
|
11
|
+
webauthn: AllowCredential[];
|
|
12
|
+
}): Promise<Fido2Assertion>;
|
|
13
|
+
create(challenge: UserRegistrationChallenge): Promise<Fido2Attestation>;
|
|
14
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PasskeySigner = exports.DEFAULT_WAIT_TIMEOUT = void 0;
|
|
4
|
+
const utils_1 = require("@dfns/sdk/utils");
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const react_native_passkey_1 = require("react-native-passkey");
|
|
7
|
+
exports.DEFAULT_WAIT_TIMEOUT = 60000;
|
|
8
|
+
class PasskeySigner {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.options = options;
|
|
11
|
+
}
|
|
12
|
+
async sign(challenge, allowCredentials) {
|
|
13
|
+
const request = {
|
|
14
|
+
challenge: challenge,
|
|
15
|
+
allowCredentials: allowCredentials.webauthn.map(({ id, type, transports }) => ({
|
|
16
|
+
id: id,
|
|
17
|
+
type,
|
|
18
|
+
transports: transports ?? [],
|
|
19
|
+
})),
|
|
20
|
+
rpId: this.options.rpId,
|
|
21
|
+
userVerification: 'required',
|
|
22
|
+
timeout: this.options.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
23
|
+
};
|
|
24
|
+
const credential = await react_native_passkey_1.Passkey.authenticate(request);
|
|
25
|
+
return {
|
|
26
|
+
kind: 'Fido2',
|
|
27
|
+
credentialAssertion: {
|
|
28
|
+
credId: credential.id,
|
|
29
|
+
clientData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(credential.response.clientDataJSON)),
|
|
30
|
+
authenticatorData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(credential.response.authenticatorData)),
|
|
31
|
+
signature: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(credential.response.signature)),
|
|
32
|
+
userHandle: credential.response.userHandle ? (0, utils_1.toBase64Url)(buffer_1.Buffer.from(credential.response.userHandle)) : '',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
async create(challenge) {
|
|
37
|
+
const options = {
|
|
38
|
+
challenge: challenge.challenge,
|
|
39
|
+
pubKeyCredParams: challenge.pubKeyCredParams,
|
|
40
|
+
rp: challenge.rp,
|
|
41
|
+
user: {
|
|
42
|
+
displayName: challenge.user.displayName,
|
|
43
|
+
id: (0, utils_1.toBase64Url)(challenge.user.id),
|
|
44
|
+
name: challenge.user.name,
|
|
45
|
+
},
|
|
46
|
+
attestation: challenge.attestation,
|
|
47
|
+
excludeCredentials: challenge.excludeCredentials.map((cred) => ({
|
|
48
|
+
id: cred.id,
|
|
49
|
+
type: cred.type,
|
|
50
|
+
})),
|
|
51
|
+
authenticatorSelection: challenge.authenticatorSelection,
|
|
52
|
+
timeout: this.options.timeout ?? exports.DEFAULT_WAIT_TIMEOUT,
|
|
53
|
+
};
|
|
54
|
+
const result = await react_native_passkey_1.Passkey.register(options);
|
|
55
|
+
if (result === null) {
|
|
56
|
+
throw Error(`Failed to create and sign with Passkey credential`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
credentialKind: 'Fido2',
|
|
60
|
+
credentialInfo: {
|
|
61
|
+
credId: result.id,
|
|
62
|
+
attestationData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(result.response.attestationObject)),
|
|
63
|
+
clientData: (0, utils_1.toBase64Url)(buffer_1.Buffer.from(result.response.clientDataJSON)),
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.PasskeySigner = PasskeySigner;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dfns/sdk-react-native",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"buffer": "6.0.3",
|
|
6
|
+
"cross-fetch": "3.1.6",
|
|
7
|
+
"react-native-passkey": "^2.1.1",
|
|
8
|
+
"uuid": "9.0.0"
|
|
9
|
+
},
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"@dfns/sdk": "0.3.0"
|
|
12
|
+
},
|
|
13
|
+
"main": "./index.js",
|
|
14
|
+
"type": "commonjs"
|
|
15
|
+
}
|