passkey-kit 0.0.26 → 0.0.28
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 -1
- package/src/index.ts +40 -32
- package/types/index.d.ts +2 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -121,20 +121,47 @@ export class PasskeyAccount {
|
|
|
121
121
|
this.sudoKeyId = startRegistrationResponse.id
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
const { publicKeyObject } = this.getPublicKeyObject(startRegistrationResponse.response.attestationObject);
|
|
125
|
+
|
|
126
|
+
const publicKey = Buffer.from([
|
|
127
|
+
4, // (0x04 prefix) https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
|
|
128
|
+
...publicKeyObject.get('-2')!,
|
|
129
|
+
...publicKeyObject.get('-3')!
|
|
130
|
+
])
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
keyId: base64url.toBuffer(startRegistrationResponse.id),
|
|
134
|
+
publicKey
|
|
135
|
+
}
|
|
125
136
|
}
|
|
126
137
|
|
|
127
|
-
public async connectWallet() {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
public async connectWallet(id?: string) {
|
|
139
|
+
/* TODO
|
|
140
|
+
- Support passing in a contractId as well as a keyId
|
|
141
|
+
Maybe not as we wouldn't have a keyId which could have interesting consequences
|
|
142
|
+
Also not sure what the use case would be for this where keyId wouldn't also be possible and better
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
// @ts-ignore
|
|
146
|
+
// https://github.com/stellar/js-stellar-base/issues/750
|
|
147
|
+
// if (id && StrKey.isValidContract(id)) {
|
|
148
|
+
|
|
149
|
+
// } else {
|
|
150
|
+
|
|
151
|
+
// }
|
|
152
|
+
|
|
153
|
+
const startAuthenticationResponse = id
|
|
154
|
+
? { id }
|
|
155
|
+
: await startAuthentication({
|
|
156
|
+
challenge: base64url("sorobanisbest"),
|
|
157
|
+
// rpId: undefined,
|
|
158
|
+
userVerification: "discouraged",
|
|
159
|
+
});
|
|
133
160
|
|
|
134
161
|
if (!this.keyId)
|
|
135
162
|
this.keyId = startAuthenticationResponse.id
|
|
136
163
|
|
|
137
|
-
const
|
|
164
|
+
const keyIdBuffer = base64url.toBuffer(startAuthenticationResponse.id)
|
|
138
165
|
|
|
139
166
|
// NOTE might not need this for derivation as all signers are stored in the factory and we can use that lookup as both primary and secondary
|
|
140
167
|
let contractId = StrKey.encodeContract(hash(xdr.HashIdPreimage.envelopeTypeContractId(
|
|
@@ -143,7 +170,7 @@ export class PasskeyAccount {
|
|
|
143
170
|
contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
|
|
144
171
|
new xdr.ContractIdPreimageFromAddress({
|
|
145
172
|
address: Address.fromString(this.factoryContractId).toScAddress(),
|
|
146
|
-
salt: hash(
|
|
173
|
+
salt: hash(keyIdBuffer),
|
|
147
174
|
})
|
|
148
175
|
)
|
|
149
176
|
})
|
|
@@ -155,7 +182,7 @@ export class PasskeyAccount {
|
|
|
155
182
|
}
|
|
156
183
|
// if that fails look up from the factory mapper
|
|
157
184
|
catch {
|
|
158
|
-
const { val } = await this.rpc.getContractData(this.factoryContractId, xdr.ScVal.scvBytes(
|
|
185
|
+
const { val } = await this.rpc.getContractData(this.factoryContractId, xdr.ScVal.scvBytes(keyIdBuffer))
|
|
159
186
|
contractId = scValToNative(val.contractData().val())
|
|
160
187
|
}
|
|
161
188
|
|
|
@@ -170,7 +197,7 @@ export class PasskeyAccount {
|
|
|
170
197
|
await this.getData()
|
|
171
198
|
|
|
172
199
|
return {
|
|
173
|
-
keyId,
|
|
200
|
+
keyId: keyIdBuffer,
|
|
174
201
|
contractId
|
|
175
202
|
}
|
|
176
203
|
}
|
|
@@ -209,7 +236,7 @@ export class PasskeyAccount {
|
|
|
209
236
|
)
|
|
210
237
|
|
|
211
238
|
const authenticationResponse = await startAuthentication(
|
|
212
|
-
keyId === 'any' || (keyId === 'sudo' && !this.sudoKeyId)
|
|
239
|
+
keyId === 'any' || (keyId === 'sudo' && !this.sudoKeyId) || (!keyId && !this.keyId)
|
|
213
240
|
? {
|
|
214
241
|
challenge: base64url(authHash),
|
|
215
242
|
// rpId: undefined,
|
|
@@ -236,7 +263,7 @@ export class PasskeyAccount {
|
|
|
236
263
|
if (keyId === 'sudo')
|
|
237
264
|
this.sudoKeyId = authenticationResponse.id
|
|
238
265
|
|
|
239
|
-
// reset this.
|
|
266
|
+
// reset this.keyId to be the most recently used passkey
|
|
240
267
|
this.keyId = authenticationResponse.id
|
|
241
268
|
|
|
242
269
|
const signatureRaw = base64url.toBuffer(authenticationResponse.response.signature);
|
|
@@ -324,25 +351,6 @@ export class PasskeyAccount {
|
|
|
324
351
|
@Later
|
|
325
352
|
*/
|
|
326
353
|
|
|
327
|
-
private async getKey(value: RegistrationResponseJSON | AuthenticationResponseJSON) {
|
|
328
|
-
let publicKey: Buffer | undefined
|
|
329
|
-
|
|
330
|
-
if (isAuthentication(value)) {
|
|
331
|
-
const { publicKeyObject } = this.getPublicKeyObject(value.response.attestationObject);
|
|
332
|
-
|
|
333
|
-
publicKey = Buffer.from([
|
|
334
|
-
4, // (0x04 prefix) https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
|
|
335
|
-
...publicKeyObject.get('-2')!,
|
|
336
|
-
...publicKeyObject.get('-3')!
|
|
337
|
-
])
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
return {
|
|
341
|
-
keyId: base64url.toBuffer(value.id),
|
|
342
|
-
publicKey
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
354
|
private getPublicKeyObject(attestationObject: string) {
|
|
347
355
|
const { authData } = decode(base64url.toBuffer(attestationObject));
|
|
348
356
|
const authDataUint8Array = new Uint8Array(authData);
|
package/types/index.d.ts
CHANGED
|
@@ -32,9 +32,9 @@ export declare class PasskeyAccount {
|
|
|
32
32
|
}>;
|
|
33
33
|
createKey(name: string, user: string): Promise<{
|
|
34
34
|
keyId: Buffer;
|
|
35
|
-
publicKey: Buffer
|
|
35
|
+
publicKey: Buffer;
|
|
36
36
|
}>;
|
|
37
|
-
connectWallet(): Promise<{
|
|
37
|
+
connectWallet(id?: string): Promise<{
|
|
38
38
|
keyId: Buffer;
|
|
39
39
|
contractId: string;
|
|
40
40
|
}>;
|
|
@@ -44,7 +44,6 @@ export declare class PasskeyAccount {
|
|
|
44
44
|
}): Promise<string>;
|
|
45
45
|
send(txn: Transaction, fee?: number): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
|
|
46
46
|
getData(): Promise<Map<string, any>>;
|
|
47
|
-
private getKey;
|
|
48
47
|
private getPublicKeyObject;
|
|
49
48
|
private convertEcdsaSignatureAsnToCompact;
|
|
50
49
|
}
|