@virtonetwork/authenticators-webauthn 1.2.4 → 1.2.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/README.md +80 -15
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -19,28 +19,93 @@ The implementation is **browser‑only** and keeps all credential mapping in the
|
|
|
19
19
|
npm i @virtonetwork/authenticators-webauthn
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Setup
|
|
23
|
+
|
|
24
|
+
First, initialize the `WebAuthn` authenticator with the user's identifier and a challenger.
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
wa = await new WebAuthn(USERNAME, blockHashChallenger(client)).setup();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Registration
|
|
31
|
+
|
|
32
|
+
To register a new credential, call the `register` method. This will trigger the browser's WebAuthn prompt.
|
|
33
|
+
The returned attestation must be submitted to the chain using the `Pass.register` extrinsic.
|
|
23
34
|
|
|
24
35
|
```ts
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
const finalizedBlock = await client.getFinalizedBlock();
|
|
37
|
+
const attestation = await wa.register(finalizedBlock.number);
|
|
38
|
+
|
|
39
|
+
const tx = api.tx.Pass.register({
|
|
40
|
+
user: Binary.fromBytes(wa.hashedUserId),
|
|
41
|
+
attestation: {
|
|
42
|
+
type: 'WebAuthn',
|
|
43
|
+
value: {
|
|
44
|
+
meta: attestation.meta,
|
|
45
|
+
authenticator_data: attestation.authenticator_data,
|
|
46
|
+
client_data: attestation.client_data,
|
|
47
|
+
public_key: attestation.public_key,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
await new Promise<void>((resolve, error) => {
|
|
53
|
+
tx.signSubmitAndWatch(ALICE).subscribe({
|
|
54
|
+
next: (event) => {
|
|
55
|
+
if (event.type === 'finalized') {
|
|
56
|
+
resolve();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
error,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
```
|
|
27
63
|
|
|
28
|
-
|
|
29
|
-
const savedId = await db.getCredentialId("alice@example.com");
|
|
64
|
+
## Authentication
|
|
30
65
|
|
|
31
|
-
|
|
32
|
-
|
|
66
|
+
Once registered, you can use the `WebAuthn` instance to create a `KreivoPassSigner`.
|
|
67
|
+
This signer can then be used to sign transactions, which will trigger the browser's WebAuthn prompt for authentication.
|
|
33
68
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
69
|
+
```ts
|
|
70
|
+
const kreivoPassSigner = new KreivoPassSigner(wa);
|
|
71
|
+
const accountId = ss58Encode(kreivoPassSigner.publicKey, 2);
|
|
72
|
+
|
|
73
|
+
// Transfer tokens
|
|
74
|
+
{
|
|
75
|
+
const tx = api.tx.Balances.transfer_keep_alive({
|
|
76
|
+
dest: { type: 'Id', value: accountId },
|
|
77
|
+
value: 1_0000000000n,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
await new Promise<void>((resolve, error) =>
|
|
81
|
+
tx.signSubmitAndWatch(ALICE).subscribe({
|
|
82
|
+
next: (event) => {
|
|
83
|
+
if (event.type === 'finalized') {
|
|
84
|
+
resolve();
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
error,
|
|
88
|
+
}),
|
|
89
|
+
);
|
|
38
90
|
}
|
|
39
91
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
92
|
+
// Sign remark
|
|
93
|
+
{
|
|
94
|
+
const remark = Binary.fromText('Hello, Kreivo!');
|
|
95
|
+
const tx = api.tx.System.remark_with_event({ remark });
|
|
96
|
+
|
|
97
|
+
const signedTx = await tx.sign(kreivoPassSigner, {
|
|
98
|
+
mortality: { mortal: false },
|
|
99
|
+
});
|
|
100
|
+
const txBytes = Vector(u8).dec(signedTx);
|
|
101
|
+
|
|
102
|
+
const txResult = await api.apis.BlockBuilder.apply_extrinsic(
|
|
103
|
+
Binary.fromBytes(new Uint8Array(txBytes)),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
assert(txResult.success);
|
|
107
|
+
assert(txResult.value.success);
|
|
108
|
+
}
|
|
44
109
|
```
|
|
45
110
|
|
|
46
111
|
## 🛠️ API
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virtonetwork/authenticators-webauthn",
|
|
3
3
|
"description": "An Authenticator compatible with KreivoPassSigner that uses the WebAuthn standard",
|
|
4
|
-
"homepage": "https://
|
|
5
|
-
"version": "1.2.
|
|
4
|
+
"homepage": "https://virto-network.github.io/papi-signers/guide/webauthn",
|
|
5
|
+
"version": "1.2.6",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@simplewebauthn/server": "^13.1.1",
|
|
40
|
-
"@virtonetwork/signer": "^1.3.
|
|
40
|
+
"@virtonetwork/signer": "^1.3.2",
|
|
41
41
|
"nid-webauthn-emulator": "^0.2.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|