passkey-kit 0.0.25 → 0.0.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passkey-kit",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "types/index.d.ts",
package/src/index.ts CHANGED
@@ -121,7 +121,18 @@ export class PasskeyAccount {
121
121
  this.sudoKeyId = startRegistrationResponse.id
122
122
  }
123
123
 
124
- return this.getKey(startRegistrationResponse)
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
138
  public async connectWallet() {
@@ -134,7 +145,7 @@ export class PasskeyAccount {
134
145
  if (!this.keyId)
135
146
  this.keyId = startAuthenticationResponse.id
136
147
 
137
- const { keyId } = await this.getKey(startAuthenticationResponse)
148
+ const keyIdBuffer = base64url.toBuffer(startAuthenticationResponse.id)
138
149
 
139
150
  // 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
151
  let contractId = StrKey.encodeContract(hash(xdr.HashIdPreimage.envelopeTypeContractId(
@@ -143,7 +154,7 @@ export class PasskeyAccount {
143
154
  contractIdPreimage: xdr.ContractIdPreimage.contractIdPreimageFromAddress(
144
155
  new xdr.ContractIdPreimageFromAddress({
145
156
  address: Address.fromString(this.factoryContractId).toScAddress(),
146
- salt: hash(keyId),
157
+ salt: hash(keyIdBuffer),
147
158
  })
148
159
  )
149
160
  })
@@ -155,7 +166,7 @@ export class PasskeyAccount {
155
166
  }
156
167
  // if that fails look up from the factory mapper
157
168
  catch {
158
- const { val } = await this.rpc.getContractData(this.factoryContractId, xdr.ScVal.scvBytes(keyId))
169
+ const { val } = await this.rpc.getContractData(this.factoryContractId, xdr.ScVal.scvBytes(keyIdBuffer))
159
170
  contractId = scValToNative(val.contractData().val())
160
171
  }
161
172
 
@@ -169,7 +180,10 @@ export class PasskeyAccount {
169
180
  // get and set the sudo signer
170
181
  await this.getData()
171
182
 
172
- return contractId
183
+ return {
184
+ keyId: keyIdBuffer,
185
+ contractId
186
+ }
173
187
  }
174
188
 
175
189
  public async sign(
@@ -321,25 +335,6 @@ export class PasskeyAccount {
321
335
  @Later
322
336
  */
323
337
 
324
- private async getKey(value: RegistrationResponseJSON | AuthenticationResponseJSON) {
325
- let publicKey: Buffer | undefined
326
-
327
- if (isAuthentication(value)) {
328
- const { publicKeyObject } = this.getPublicKeyObject(value.response.attestationObject);
329
-
330
- publicKey = Buffer.from([
331
- 4, // (0x04 prefix) https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm
332
- ...publicKeyObject.get('-2')!,
333
- ...publicKeyObject.get('-3')!
334
- ])
335
- }
336
-
337
- return {
338
- keyId: base64url.toBuffer(value.id),
339
- publicKey
340
- }
341
- }
342
-
343
338
  private getPublicKeyObject(attestationObject: string) {
344
339
  const { authData } = decode(base64url.toBuffer(attestationObject));
345
340
  const authDataUint8Array = new Uint8Array(authData);
package/types/index.d.ts CHANGED
@@ -32,16 +32,18 @@ export declare class PasskeyAccount {
32
32
  }>;
33
33
  createKey(name: string, user: string): Promise<{
34
34
  keyId: Buffer;
35
- publicKey: Buffer | undefined;
35
+ publicKey: Buffer;
36
+ }>;
37
+ connectWallet(): Promise<{
38
+ keyId: Buffer;
39
+ contractId: string;
36
40
  }>;
37
- connectWallet(): Promise<string>;
38
41
  sign(txn: Transaction | string, options?: {
39
42
  keyId?: 'any' | 'sudo' | string | Uint8Array;
40
43
  ledgersToLive?: number;
41
44
  }): Promise<string>;
42
45
  send(txn: Transaction, fee?: number): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
43
46
  getData(): Promise<Map<string, any>>;
44
- private getKey;
45
47
  private getPublicKeyObject;
46
48
  private convertEcdsaSignatureAsnToCompact;
47
49
  }