passkey-kit 0.0.24 → 0.0.25

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.24",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "types/index.d.ts",
@@ -1,10 +1,12 @@
1
1
  import { Buffer } from "buffer";
2
2
  import {
3
- AssembledTransaction,
4
3
  Client as ContractClient,
4
+ Spec as ContractSpec,
5
+ } from '@stellar/stellar-sdk/contract';
6
+ import type {
7
+ AssembledTransaction,
5
8
  ClientOptions as ContractClientOptions,
6
9
  Result,
7
- Spec as ContractSpec,
8
10
  } from '@stellar/stellar-sdk/contract';
9
11
 
10
12
  if (typeof window !== 'undefined') {
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from "buffer";
2
- import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
2
+ import { Client as ContractClient } from '@stellar/stellar-sdk/contract';
3
+ import type { AssembledTransaction, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
3
4
  export declare const networks: {
4
5
  readonly testnet: {
5
6
  readonly networkPassphrase: "Test SDF Network ; September 2015";
@@ -1,10 +1,12 @@
1
1
  import { Buffer } from "buffer";
2
2
  import {
3
- AssembledTransaction,
4
3
  Client as ContractClient,
4
+ Spec as ContractSpec,
5
+ } from '@stellar/stellar-sdk/contract';
6
+ import type {
7
+ AssembledTransaction,
5
8
  ClientOptions as ContractClientOptions,
6
9
  Result,
7
- Spec as ContractSpec,
8
10
  } from '@stellar/stellar-sdk/contract';
9
11
 
10
12
  if (typeof window !== 'undefined') {
@@ -12,7 +14,6 @@ if (typeof window !== 'undefined') {
12
14
  window.Buffer = window.Buffer || Buffer;
13
15
  }
14
16
 
15
-
16
17
  export const networks = {
17
18
  testnet: {
18
19
  networkPassphrase: "Test SDF Network ; September 2015",
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from "buffer";
2
- import { AssembledTransaction, Client as ContractClient, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
2
+ import { Client as ContractClient } from '@stellar/stellar-sdk/contract';
3
+ import type { AssembledTransaction, ClientOptions as ContractClientOptions, Result } from '@stellar/stellar-sdk/contract';
3
4
  export declare const networks: {
4
5
  readonly testnet: {
5
6
  readonly networkPassphrase: "Test SDF Network ; September 2015";
package/src/index.ts CHANGED
@@ -15,8 +15,8 @@ import { Buffer } from 'buffer'
15
15
  */
16
16
 
17
17
  export class PasskeyAccount {
18
- public id: string | undefined
19
- public sudo: string | undefined
18
+ public keyId: string | undefined
19
+ public sudoKeyId: string | undefined
20
20
  public wallet: PasskeyClient | undefined
21
21
  public factory: FactoryClient
22
22
  public sequencePublicKey: string
@@ -86,6 +86,7 @@ export class PasskeyAccount {
86
86
  })
87
87
 
88
88
  return {
89
+ keyId,
89
90
  contractId,
90
91
  xdr: built!.toXDR() as string
91
92
  }
@@ -112,11 +113,12 @@ export class PasskeyAccount {
112
113
  attestation: "none",
113
114
  });
114
115
 
115
- if (!this.id) {
116
- this.id = startRegistrationResponse.id
116
+ if (!this.keyId) {
117
+ this.keyId = startRegistrationResponse.id
117
118
 
118
- if (!this.sudo)
119
- this.sudo = startRegistrationResponse.id
119
+ // If there was no keyId we're likely about to deploy a new wallet so we should set the sudoKeyId
120
+ if (!this.sudoKeyId)
121
+ this.sudoKeyId = startRegistrationResponse.id
120
122
  }
121
123
 
122
124
  return this.getKey(startRegistrationResponse)
@@ -129,8 +131,8 @@ export class PasskeyAccount {
129
131
  userVerification: "discouraged",
130
132
  });
131
133
 
132
- if (!this.id)
133
- this.id = startAuthenticationResponse.id
134
+ if (!this.keyId)
135
+ this.keyId = startAuthenticationResponse.id
134
136
 
135
137
  const { keyId } = await this.getKey(startAuthenticationResponse)
136
138
 
@@ -173,12 +175,12 @@ export class PasskeyAccount {
173
175
  public async sign(
174
176
  txn: Transaction | string,
175
177
  options?: {
176
- id?: 'any' | 'sudo' | string | Uint8Array
177
- ttl?: number
178
+ keyId?: 'any' | 'sudo' | string | Uint8Array
179
+ ledgersToLive?: number
178
180
  }
179
181
  ) {
180
182
  // Default mirrors DEFAULT_TIMEOUT (currently 5 minutes) https://github.com/stellar/js-stellar-sdk/blob/master/src/contract/utils.ts#L7
181
- let { id, ttl = 60 } = options || {}
183
+ let { keyId, ledgersToLive = 60 } = options || {}
182
184
 
183
185
  // hack to ensure we don't stack fees when simulating and assembling multiple times
184
186
  txn = TransactionBuilder.cloneFrom(new Transaction(
@@ -197,14 +199,14 @@ export class PasskeyAccount {
197
199
  new xdr.HashIdPreimageSorobanAuthorization({
198
200
  networkId: hash(Buffer.from(this.networkPassphrase, 'utf-8')),
199
201
  nonce: auth.credentials().address().nonce(),
200
- signatureExpirationLedger: lastLedger + ttl,
202
+ signatureExpirationLedger: lastLedger + ledgersToLive,
201
203
  invocation: auth.rootInvocation()
202
204
  })
203
205
  ).toXDR()
204
206
  )
205
207
 
206
208
  const authenticationResponse = await startAuthentication(
207
- id === 'any' || (id === 'sudo' && !this.sudo)
209
+ keyId === 'any' || (keyId === 'sudo' && !this.sudoKeyId)
208
210
  ? {
209
211
  challenge: base64url(authHash),
210
212
  // rpId: undefined,
@@ -215,11 +217,11 @@ export class PasskeyAccount {
215
217
  // rpId: undefined,
216
218
  allowCredentials: [
217
219
  {
218
- id: id === 'sudo'
219
- ? this.sudo!
220
- : id instanceof Uint8Array
221
- ? base64url(id)
222
- : id || this.id!,
220
+ id: keyId === 'sudo'
221
+ ? this.sudoKeyId!
222
+ : keyId instanceof Uint8Array
223
+ ? base64url(keyId)
224
+ : keyId || this.keyId!,
223
225
  type: "public-key",
224
226
  },
225
227
  ],
@@ -228,17 +230,17 @@ export class PasskeyAccount {
228
230
  );
229
231
 
230
232
  // set sudo if this is a sudo request
231
- if (id === 'sudo')
232
- this.sudo = authenticationResponse.id
233
+ if (keyId === 'sudo')
234
+ this.sudoKeyId = authenticationResponse.id
233
235
 
234
236
  // reset this.id to be the most recently used passkey
235
- this.id = authenticationResponse.id
237
+ this.keyId = authenticationResponse.id
236
238
 
237
239
  const signatureRaw = base64url.toBuffer(authenticationResponse.response.signature);
238
240
  const signature = this.convertEcdsaSignatureAsnToCompact(signatureRaw);
239
241
  const creds = auth.credentials().address();
240
242
 
241
- creds.signatureExpirationLedger(lastLedger + ttl)
243
+ creds.signatureExpirationLedger(lastLedger + ledgersToLive)
242
244
  creds.signature(xdr.ScVal.scvMap([
243
245
  new xdr.ScMapEntry({
244
246
  key: xdr.ScVal.scvSymbol('authenticator_data'),
@@ -308,7 +310,7 @@ export class PasskeyAccount {
308
310
  );
309
311
  });
310
312
 
311
- this.sudo = base64url(data.get('sudo_sig'))
313
+ this.sudoKeyId = base64url(data.get('sudo_sig'))
312
314
 
313
315
  return data
314
316
  }
package/types/index.d.ts CHANGED
@@ -3,8 +3,8 @@ import { Client as FactoryClient } from 'passkey-factory-sdk';
3
3
  import { Networks, Transaction, Horizon, SorobanRpc } from '@stellar/stellar-sdk';
4
4
  import { Buffer } from 'buffer';
5
5
  export declare class PasskeyAccount {
6
- id: string | undefined;
7
- sudo: string | undefined;
6
+ keyId: string | undefined;
7
+ sudoKeyId: string | undefined;
8
8
  wallet: PasskeyClient | undefined;
9
9
  factory: FactoryClient;
10
10
  sequencePublicKey: string;
@@ -26,6 +26,7 @@ export declare class PasskeyAccount {
26
26
  factoryContractId?: string;
27
27
  });
28
28
  createWallet(name: string, user: string): Promise<{
29
+ keyId: Buffer;
29
30
  contractId: string;
30
31
  xdr: string;
31
32
  }>;
@@ -35,8 +36,8 @@ export declare class PasskeyAccount {
35
36
  }>;
36
37
  connectWallet(): Promise<string>;
37
38
  sign(txn: Transaction | string, options?: {
38
- id?: 'any' | 'sudo' | string | Uint8Array;
39
- ttl?: number;
39
+ keyId?: 'any' | 'sudo' | string | Uint8Array;
40
+ ledgersToLive?: number;
40
41
  }): Promise<string>;
41
42
  send(txn: Transaction, fee?: number): Promise<Horizon.HorizonApi.SubmitTransactionResponse>;
42
43
  getData(): Promise<Map<string, any>>;