passkey-kit 0.7.14 → 0.7.15

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.7.14",
3
+ "version": "0.7.15",
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",
package/src/kit.ts CHANGED
@@ -6,7 +6,7 @@ import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
6
6
  import type { AuthenticatorAttestationResponseJSON, AuthenticatorSelectionCriteria } from "@simplewebauthn/types"
7
7
  import { Buffer } from 'buffer'
8
8
  import { PasskeyBase } from './base'
9
- import { AssembledTransaction, DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
9
+ import { AssembledTransaction, DEFAULT_TIMEOUT, type Tx } from '@stellar/stellar-sdk/contract'
10
10
 
11
11
  export { Client as PasskeyClient } from 'passkey-kit-sdk'
12
12
  export { Client as FactoryClient } from 'passkey-factory-sdk'
@@ -187,7 +187,7 @@ export class PasskeyKit extends PasskeyBase {
187
187
  }
188
188
  // if that fails look up from the `getContractId` function
189
189
  catch {
190
- contractId = getContractId ? await getContractId(keyId) : undefined
190
+ contractId = getContractId && await getContractId(keyId)
191
191
  }
192
192
 
193
193
  if (!contractId)
@@ -195,8 +195,8 @@ export class PasskeyKit extends PasskeyBase {
195
195
 
196
196
  this.wallet = new PasskeyClient({
197
197
  contractId,
198
+ rpcUrl: this.rpcUrl,
198
199
  networkPassphrase: this.networkPassphrase,
199
- rpcUrl: this.rpcUrl
200
200
  })
201
201
 
202
202
  return {
@@ -393,8 +393,8 @@ export class PasskeyKit extends PasskeyBase {
393
393
  return entry
394
394
  }
395
395
 
396
- public sign<T>(
397
- txn: AssembledTransaction<T>,
396
+ public async sign<T>(
397
+ txn: AssembledTransaction<T> | Tx | string,
398
398
  options?: {
399
399
  rpId?: string,
400
400
  keyId?: 'any' | string | Uint8Array
@@ -403,15 +403,21 @@ export class PasskeyKit extends PasskeyBase {
403
403
  expiration?: number
404
404
  }
405
405
  ) {
406
- // TODO ensure we're outputting a built transaction that's actually useful in the case you don't intend to use launchtube
407
- // Pretty sure we'll always be woefully under budget
408
- return txn.signAuthEntries({
406
+ if (typeof txn === 'string') {
407
+ txn = AssembledTransaction.fromXDR(this.wallet!.options, txn, this.wallet!.spec)
408
+ } else if (!(txn instanceof AssembledTransaction)) {
409
+ txn = AssembledTransaction.fromXDR(this.wallet!.options, txn.toXDR(), this.wallet!.spec)
410
+ }
411
+
412
+ await txn.signAuthEntries({
409
413
  address: this.wallet!.options.contractId,
410
414
  authorizeEntry: (entry) => {
411
415
  const clone = xdr.SorobanAuthorizationEntry.fromXDR(entry.toXDR())
412
416
  return this.signAuthEntry(clone, options)
413
417
  },
414
418
  })
419
+
420
+ return txn
415
421
  }
416
422
 
417
423
  public addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore) {
package/src/server.ts CHANGED
@@ -87,9 +87,29 @@ export class PasskeyServer extends PasskeyBase {
87
87
  }[]
88
88
  }
89
89
 
90
- public async getContractId(keyId: string) {
90
+ public async getContractId(options: {
91
+ keyId?: string,
92
+ publicKey?: string,
93
+ policy?: string,
94
+ }, index = 0) {
91
95
  if (!this.mercuryUrl || !this.mercuryJwt)
92
- return
96
+ throw new Error('Mercury service not configured')
97
+
98
+ let { keyId, publicKey, policy } = options || {}
99
+
100
+ if ([keyId, publicKey, policy].filter((arg) => !!arg).length > 1)
101
+ throw new Error('Exactly one of `options.keyId`, `options.publicKey`, or `options.policy` must be provided.');
102
+
103
+ let args: { key: string, kind: 'Secp256r1' | 'Ed25519' | 'Policy' }
104
+
105
+ if (keyId)
106
+ args = { key: keyId, kind: 'Secp256r1' }
107
+ else if (publicKey)
108
+ args = { key: publicKey, kind: 'Ed25519' }
109
+ else if (policy)
110
+ args = { key: policy, kind: 'Policy' }
111
+ else
112
+ throw new Error('Exactly one of `options.keyId`, `options.publicKey`, or `options.policy` must be provided.');
93
113
 
94
114
  const res = await fetch(`${this.mercuryUrl}/zephyr/execute`, {
95
115
  method: 'POST',
@@ -101,23 +121,20 @@ export class PasskeyServer extends PasskeyBase {
101
121
  project_name: 'smart-wallets-data-multi-signer-multi-sig',
102
122
  mode: {
103
123
  Function: {
104
- fname: "get_address_by_signer",
105
- arguments: JSON.stringify({
106
- key: keyId,
107
- kind: 'Secp256r1'
108
- })
124
+ fname: "get_addresses_by_signer",
125
+ arguments: JSON.stringify(args)
109
126
  }
110
127
  }
111
128
  })
112
129
  })
113
130
  .then(async (res) => {
114
131
  if (res.ok)
115
- return res.json()
132
+ return await res.json() as string[]
116
133
 
117
134
  throw await res.json()
118
135
  })
119
136
 
120
- return res || undefined as string | undefined
137
+ return res[index]
121
138
  }
122
139
 
123
140
  /* LATER
package/types/kit.d.ts CHANGED
@@ -5,7 +5,7 @@ import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
5
5
  import type { AuthenticatorSelectionCriteria } from "@simplewebauthn/types";
6
6
  import { Buffer } from 'buffer';
7
7
  import { PasskeyBase } from './base';
8
- import { AssembledTransaction } from '@stellar/stellar-sdk/contract';
8
+ import { AssembledTransaction, type Tx } from '@stellar/stellar-sdk/contract';
9
9
  export { Client as PasskeyClient } from 'passkey-kit-sdk';
10
10
  export { Client as FactoryClient } from 'passkey-factory-sdk';
11
11
  export declare class SignerKey {
@@ -44,7 +44,7 @@ export declare class PasskeyKit extends PasskeyBase {
44
44
  createWallet(app: string, user: string): Promise<{
45
45
  keyId: Buffer;
46
46
  contractId: string;
47
- built: import("@stellar/stellar-sdk/contract").Tx;
47
+ built: Tx;
48
48
  }>;
49
49
  createKey(app: string, user: string, settings?: {
50
50
  rpId?: string;
@@ -68,13 +68,13 @@ export declare class PasskeyKit extends PasskeyBase {
68
68
  policy?: string;
69
69
  expiration?: number;
70
70
  }): Promise<xdr.SorobanAuthorizationEntry>;
71
- sign<T>(txn: AssembledTransaction<T>, options?: {
71
+ sign<T>(txn: AssembledTransaction<T> | Tx | string, options?: {
72
72
  rpId?: string;
73
73
  keyId?: 'any' | string | Uint8Array;
74
74
  keypair?: Keypair;
75
75
  policy?: string;
76
76
  expiration?: number;
77
- }): Promise<void>;
77
+ }): Promise<AssembledTransaction<T>>;
78
78
  addSecp256r1(keyId: Uint8Array, publicKey: Uint8Array, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
79
79
  addEd25519(publicKey: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
80
80
  addPolicy(policy: string, limits: SignerLimits, store: SignerStore): Promise<AssembledTransaction<import("@stellar/stellar-sdk/contract").Result<void, import("@stellar/stellar-sdk/contract").ErrorMessage>>>;
package/types/server.d.ts CHANGED
@@ -19,6 +19,10 @@ export declare class PasskeyServer extends PasskeyBase {
19
19
  limits: string;
20
20
  expired?: boolean;
21
21
  }[]>;
22
- getContractId(keyId: string): Promise<any>;
22
+ getContractId(options: {
23
+ keyId?: string;
24
+ publicKey?: string;
25
+ policy?: string;
26
+ }, index?: number): Promise<string>;
23
27
  send(txn: Tx, fee?: number): Promise<any>;
24
28
  }