passkey-kit 0.4.3 → 0.4.4

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.4.3",
3
+ "version": "0.4.4",
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/base.ts CHANGED
@@ -2,8 +2,8 @@ import { SorobanRpc, xdr } from "@stellar/stellar-sdk"
2
2
  import base64url from "base64url"
3
3
 
4
4
  export class PasskeyBase {
5
- public rpc: SorobanRpc.Server
6
- public rpcUrl: string
5
+ public rpc: SorobanRpc.Server | undefined
6
+ public rpcUrl: string | undefined
7
7
  public launchtubeUrl: string | undefined
8
8
  public launchtubeJwt: string | undefined
9
9
  public mercuryUrl: string | undefined
@@ -12,9 +12,7 @@ export class PasskeyBase {
12
12
  public mercuryPassword: string | undefined
13
13
 
14
14
  constructor(options: {
15
- rpcUrl: string,
16
- networkPassphrase: string,
17
- factoryContractId: string,
15
+ rpcUrl?: string,
18
16
  launchtubeUrl?: string,
19
17
  launchtubeJwt?: string,
20
18
  mercuryUrl?: string,
@@ -53,8 +51,10 @@ export class PasskeyBase {
53
51
  if (!mercuryJwt && mercuryUrl && mercuryEmail && mercuryPassword)
54
52
  this.setMercuryJwt()
55
53
 
56
- this.rpcUrl = rpcUrl
57
- this.rpc = new SorobanRpc.Server(rpcUrl)
54
+ if (rpcUrl) {
55
+ this.rpcUrl = rpcUrl
56
+ this.rpc = new SorobanRpc.Server(rpcUrl)
57
+ }
58
58
  }
59
59
 
60
60
  public async setMercuryJwt() {
@@ -89,7 +89,7 @@ export class PasskeyBase {
89
89
  }
90
90
 
91
91
  public async getSigners(contractId: string) {
92
- if (!this.mercuryUrl || !this.mercuryJwt)
92
+ if (!this.rpc || !this.mercuryUrl || !this.mercuryJwt)
93
93
  throw new Error('Mercury service not configured')
94
94
 
95
95
  const signers = await fetch(`${this.mercuryUrl}/zephyr/execute`, {
package/src/kit.ts CHANGED
@@ -29,6 +29,12 @@ export class PasskeyKit extends PasskeyBase {
29
29
 
30
30
  super(options)
31
31
 
32
+ if (!this.rpcUrl)
33
+ this.rpcUrl = rpcUrl
34
+
35
+ if (!this.rpc)
36
+ this.rpc = new SorobanRpc.Server(rpcUrl)
37
+
32
38
  this.networkPassphrase = networkPassphrase
33
39
  this.factory = new FactoryClient({
34
40
  contractId: factoryContractId,
@@ -140,7 +146,7 @@ export class PasskeyKit extends PasskeyBase {
140
146
  // attempt passkey id derivation
141
147
  try {
142
148
  // TODO what is the error if the entry exists but is archived?
143
- await this.rpc.getContractData(contractId, xdr.ScVal.scvLedgerKeyContractInstance())
149
+ await this.rpc!.getContractData(contractId, xdr.ScVal.scvLedgerKeyContractInstance())
144
150
  }
145
151
  // if that fails look up from the `getContractId` function
146
152
  catch {
@@ -172,7 +178,7 @@ export class PasskeyKit extends PasskeyBase {
172
178
  // Default mirrors DEFAULT_TIMEOUT (currently 5 minutes) https://github.com/stellar/js-stellar-sdk/blob/master/src/contract/utils.ts#L7
173
179
  let { keyId, ledgersToLive = 60 } = options || {}
174
180
 
175
- const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
181
+ const lastLedger = await this.rpc!.getLatestLedger().then(({ sequence }) => sequence)
176
182
  const credentials = entry.credentials().address();
177
183
  const preimage = xdr.HashIdPreimage.envelopeTypeSorobanAuthorization(
178
184
  new xdr.HashIdPreimageSorobanAuthorization({
@@ -295,7 +301,7 @@ export class PasskeyKit extends PasskeyBase {
295
301
  await this.signAuthEntries(entries, options)
296
302
  }
297
303
 
298
- const sim = await this.rpc.simulateTransaction(txn)
304
+ const sim = await this.rpc!.simulateTransaction(txn)
299
305
 
300
306
  if (
301
307
  SorobanRpc.Api.isSimulationError(sim)
package/types/base.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SorobanRpc } from "@stellar/stellar-sdk";
2
2
  export declare class PasskeyBase {
3
- rpc: SorobanRpc.Server;
4
- rpcUrl: string;
3
+ rpc: SorobanRpc.Server | undefined;
4
+ rpcUrl: string | undefined;
5
5
  launchtubeUrl: string | undefined;
6
6
  launchtubeJwt: string | undefined;
7
7
  mercuryUrl: string | undefined;
@@ -9,9 +9,7 @@ export declare class PasskeyBase {
9
9
  mercuryEmail: string | undefined;
10
10
  mercuryPassword: string | undefined;
11
11
  constructor(options: {
12
- rpcUrl: string;
13
- networkPassphrase: string;
14
- factoryContractId: string;
12
+ rpcUrl?: string;
15
13
  launchtubeUrl?: string;
16
14
  launchtubeJwt?: string;
17
15
  mercuryUrl?: string;