passkey-kit 0.4.4 → 0.4.5
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/package.json +1 -2
- package/src/kit.ts +34 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passkey-kit",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "A helper library for creating and using passkey accounts on the Stellar blockchain.",
|
|
5
5
|
"author": "Tyler van der Hoeven",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"@stellar/stellar-sdk": "12.1.0",
|
|
13
13
|
"base64url": "^3.0.1",
|
|
14
14
|
"buffer": "^6.0.3",
|
|
15
|
-
"cbor-x": "^1.5.9",
|
|
16
15
|
"passkey-factory-sdk": "0.2.1",
|
|
17
16
|
"passkey-kit-sdk": "0.2.1"
|
|
18
17
|
},
|
package/src/kit.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { Address, StrKey, hash, xdr, Transaction, SorobanRpc, Operation, Transac
|
|
|
4
4
|
import base64url from 'base64url'
|
|
5
5
|
import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
|
|
6
6
|
import type { AuthenticatorAttestationResponseJSON } from "@simplewebauthn/types"
|
|
7
|
-
import { decode } from 'cbor-x/decode'
|
|
8
7
|
import { Buffer } from 'buffer'
|
|
9
8
|
import { PasskeyBase } from './base'
|
|
10
9
|
|
|
@@ -88,7 +87,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
88
87
|
},
|
|
89
88
|
pubKeyCredParams: [{ alg: -7, type: "public-key" }],
|
|
90
89
|
attestation: "none",
|
|
91
|
-
timeout: 120_000
|
|
90
|
+
timeout: 120_000,
|
|
92
91
|
});
|
|
93
92
|
|
|
94
93
|
if (!this.keyId)
|
|
@@ -96,7 +95,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
96
95
|
|
|
97
96
|
return {
|
|
98
97
|
keyId: base64url.toBuffer(id),
|
|
99
|
-
publicKey: this.getPublicKey(response)
|
|
98
|
+
publicKey: await this.getPublicKey(response)
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
|
|
@@ -115,7 +114,7 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
115
114
|
timeout: 120_000
|
|
116
115
|
});
|
|
117
116
|
|
|
118
|
-
console.log(response);
|
|
117
|
+
// console.log(response);
|
|
119
118
|
|
|
120
119
|
keyId = response.id
|
|
121
120
|
}
|
|
@@ -317,30 +316,51 @@ export class PasskeyKit extends PasskeyBase {
|
|
|
317
316
|
@Later
|
|
318
317
|
*/
|
|
319
318
|
|
|
320
|
-
private getPublicKey(response: AuthenticatorAttestationResponseJSON) {
|
|
319
|
+
private async getPublicKey(response: AuthenticatorAttestationResponseJSON) {
|
|
321
320
|
let publicKey: Buffer | undefined
|
|
322
321
|
|
|
323
|
-
if (response.publicKey)
|
|
324
|
-
publicKey = base64url.toBuffer(response.publicKey)
|
|
322
|
+
if (response.publicKey) {
|
|
323
|
+
publicKey = base64url.toBuffer(response.publicKey)
|
|
324
|
+
publicKey = publicKey!.slice(publicKey!.length - 65)
|
|
325
|
+
}
|
|
325
326
|
|
|
326
327
|
if (
|
|
327
328
|
!publicKey
|
|
328
329
|
|| publicKey[0] !== 0x04
|
|
329
330
|
|| publicKey.length !== 65
|
|
330
331
|
) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
let x: Buffer
|
|
333
|
+
let y: Buffer
|
|
334
|
+
|
|
335
|
+
if (response.authenticatorData) {
|
|
336
|
+
const authenticatorData = base64url.toBuffer(response.authenticatorData)
|
|
337
|
+
const credentialIdLength = (authenticatorData[53] << 8) | authenticatorData[54]
|
|
338
|
+
|
|
339
|
+
x = authenticatorData.slice(65 + credentialIdLength, 97 + credentialIdLength)
|
|
340
|
+
y = authenticatorData.slice(100 + credentialIdLength, 132 + credentialIdLength)
|
|
341
|
+
} else {
|
|
342
|
+
const attestationData = base64url.toBuffer(response.attestationObject)
|
|
343
|
+
|
|
344
|
+
let startIndex = attestationData.indexOf(0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20)
|
|
345
|
+
startIndex = startIndex + startIndex.length
|
|
346
|
+
|
|
347
|
+
x = attestationData.slice(startIndex, 32 + startIndex)
|
|
348
|
+
y = attestationData.slice(35 + startIndex, 67 + startIndex)
|
|
349
|
+
}
|
|
336
350
|
|
|
337
351
|
publicKey = Buffer.from([
|
|
338
352
|
0x04, // (0x04 prefix) https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
|
|
339
|
-
...
|
|
340
|
-
...
|
|
353
|
+
...x,
|
|
354
|
+
...y
|
|
341
355
|
])
|
|
342
356
|
}
|
|
343
357
|
|
|
358
|
+
/* TODO
|
|
359
|
+
- We're doing some pretty "smart" public key decoding stuff so we should verify the signature against this final public key before assuming it's safe to use and save on-chain
|
|
360
|
+
Given that `startRegistration` doesn't produce a signature, verifying we've got the correct public key isn't really possible
|
|
361
|
+
@Later
|
|
362
|
+
*/
|
|
363
|
+
|
|
344
364
|
return publicKey
|
|
345
365
|
}
|
|
346
366
|
|