passkey-kit 0.4.2 → 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.2",
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
@@ -1,12 +1,9 @@
1
- import { Networks, SorobanRpc, xdr } from "@stellar/stellar-sdk"
2
- import { Client as FactoryClient } from 'passkey-factory-sdk'
1
+ import { SorobanRpc, xdr } from "@stellar/stellar-sdk"
3
2
  import base64url from "base64url"
4
3
 
5
4
  export class PasskeyBase {
6
- public rpc: SorobanRpc.Server
7
- public factory: FactoryClient
8
- public rpcUrl: string
9
- public networkPassphrase: Networks
5
+ public rpc: SorobanRpc.Server | undefined
6
+ public rpcUrl: string | undefined
10
7
  public launchtubeUrl: string | undefined
11
8
  public launchtubeJwt: string | undefined
12
9
  public mercuryUrl: string | undefined
@@ -15,9 +12,7 @@ export class PasskeyBase {
15
12
  public mercuryPassword: string | undefined
16
13
 
17
14
  constructor(options: {
18
- rpcUrl: string,
19
- networkPassphrase: string,
20
- factoryContractId: string,
15
+ rpcUrl?: string,
21
16
  launchtubeUrl?: string,
22
17
  launchtubeJwt?: string,
23
18
  mercuryUrl?: string,
@@ -27,8 +22,6 @@ export class PasskeyBase {
27
22
  }) {
28
23
  const {
29
24
  rpcUrl,
30
- networkPassphrase,
31
- factoryContractId,
32
25
  launchtubeUrl,
33
26
  launchtubeJwt,
34
27
  mercuryUrl,
@@ -55,17 +48,16 @@ export class PasskeyBase {
55
48
  if (mercuryPassword)
56
49
  this.mercuryPassword = mercuryPassword
57
50
 
58
- this.rpcUrl = rpcUrl
59
- this.rpc = new SorobanRpc.Server(rpcUrl)
60
- this.networkPassphrase = networkPassphrase as Networks
61
- this.factory = new FactoryClient({
62
- contractId: factoryContractId,
63
- networkPassphrase,
64
- rpcUrl
65
- })
51
+ if (!mercuryJwt && mercuryUrl && mercuryEmail && mercuryPassword)
52
+ this.setMercuryJwt()
53
+
54
+ if (rpcUrl) {
55
+ this.rpcUrl = rpcUrl
56
+ this.rpc = new SorobanRpc.Server(rpcUrl)
57
+ }
66
58
  }
67
59
 
68
- public async getMercuryJwt() {
60
+ public async setMercuryJwt() {
69
61
  if (!this.mercuryEmail || !this.mercuryPassword)
70
62
  throw new Error('Mercury service not configured')
71
63
 
@@ -92,11 +84,12 @@ export class PasskeyBase {
92
84
  throw await res.json()
93
85
  })
94
86
 
87
+ this.mercuryJwt = jwtToken
95
88
  return jwtToken
96
89
  }
97
90
 
98
- public async getSigners(contractId: string = this.factory.options.contractId) {
99
- if (!this.mercuryUrl || !this.mercuryJwt)
91
+ public async getSigners(contractId: string) {
92
+ if (!this.rpc || !this.mercuryUrl || !this.mercuryJwt)
100
93
  throw new Error('Mercury service not configured')
101
94
 
102
95
  const signers = await fetch(`${this.mercuryUrl}/zephyr/execute`, {
package/src/kit.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Client as PasskeyClient } from 'passkey-kit-sdk'
2
-
2
+ import { Client as FactoryClient } from 'passkey-factory-sdk'
3
3
  import { Address, StrKey, hash, xdr, Transaction, SorobanRpc, Operation, TransactionBuilder } from '@stellar/stellar-sdk'
4
4
  import base64url from 'base64url'
5
5
  import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
@@ -10,6 +10,8 @@ import { PasskeyBase } from './base'
10
10
 
11
11
  export class PasskeyKit extends PasskeyBase {
12
12
  public keyId: string | undefined
13
+ public networkPassphrase: string
14
+ public factory: FactoryClient
13
15
  public wallet: PasskeyClient | undefined
14
16
 
15
17
  constructor(options: {
@@ -23,7 +25,22 @@ export class PasskeyKit extends PasskeyBase {
23
25
  mercuryEmail?: string,
24
26
  mercuryPassword?: string
25
27
  }) {
28
+ const { rpcUrl, networkPassphrase, factoryContractId } = options
29
+
26
30
  super(options)
31
+
32
+ if (!this.rpcUrl)
33
+ this.rpcUrl = rpcUrl
34
+
35
+ if (!this.rpc)
36
+ this.rpc = new SorobanRpc.Server(rpcUrl)
37
+
38
+ this.networkPassphrase = networkPassphrase
39
+ this.factory = new FactoryClient({
40
+ contractId: factoryContractId,
41
+ networkPassphrase,
42
+ rpcUrl
43
+ })
27
44
  }
28
45
 
29
46
  public async createWallet(app: string, user: string) {
@@ -129,7 +146,7 @@ export class PasskeyKit extends PasskeyBase {
129
146
  // attempt passkey id derivation
130
147
  try {
131
148
  // TODO what is the error if the entry exists but is archived?
132
- await this.rpc.getContractData(contractId, xdr.ScVal.scvLedgerKeyContractInstance())
149
+ await this.rpc!.getContractData(contractId, xdr.ScVal.scvLedgerKeyContractInstance())
133
150
  }
134
151
  // if that fails look up from the `getContractId` function
135
152
  catch {
@@ -161,7 +178,7 @@ export class PasskeyKit extends PasskeyBase {
161
178
  // Default mirrors DEFAULT_TIMEOUT (currently 5 minutes) https://github.com/stellar/js-stellar-sdk/blob/master/src/contract/utils.ts#L7
162
179
  let { keyId, ledgersToLive = 60 } = options || {}
163
180
 
164
- const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
181
+ const lastLedger = await this.rpc!.getLatestLedger().then(({ sequence }) => sequence)
165
182
  const credentials = entry.credentials().address();
166
183
  const preimage = xdr.HashIdPreimage.envelopeTypeSorobanAuthorization(
167
184
  new xdr.HashIdPreimageSorobanAuthorization({
@@ -284,7 +301,7 @@ export class PasskeyKit extends PasskeyBase {
284
301
  await this.signAuthEntries(entries, options)
285
302
  }
286
303
 
287
- const sim = await this.rpc.simulateTransaction(txn)
304
+ const sim = await this.rpc!.simulateTransaction(txn)
288
305
 
289
306
  if (
290
307
  SorobanRpc.Api.isSimulationError(sim)
package/types/base.d.ts CHANGED
@@ -1,10 +1,7 @@
1
- import { Networks, SorobanRpc } from "@stellar/stellar-sdk";
2
- import { Client as FactoryClient } from 'passkey-factory-sdk';
1
+ import { SorobanRpc } from "@stellar/stellar-sdk";
3
2
  export declare class PasskeyBase {
4
- rpc: SorobanRpc.Server;
5
- factory: FactoryClient;
6
- rpcUrl: string;
7
- networkPassphrase: Networks;
3
+ rpc: SorobanRpc.Server | undefined;
4
+ rpcUrl: string | undefined;
8
5
  launchtubeUrl: string | undefined;
9
6
  launchtubeJwt: string | undefined;
10
7
  mercuryUrl: string | undefined;
@@ -12,9 +9,7 @@ export declare class PasskeyBase {
12
9
  mercuryEmail: string | undefined;
13
10
  mercuryPassword: string | undefined;
14
11
  constructor(options: {
15
- rpcUrl: string;
16
- networkPassphrase: string;
17
- factoryContractId: string;
12
+ rpcUrl?: string;
18
13
  launchtubeUrl?: string;
19
14
  launchtubeJwt?: string;
20
15
  mercuryUrl?: string;
@@ -22,8 +17,8 @@ export declare class PasskeyBase {
22
17
  mercuryEmail?: string;
23
18
  mercuryPassword?: string;
24
19
  });
25
- getMercuryJwt(): Promise<any>;
26
- getSigners(contractId?: string): Promise<{
20
+ setMercuryJwt(): Promise<any>;
21
+ getSigners(contractId: string): Promise<{
27
22
  id: string;
28
23
  pk: string;
29
24
  admin: boolean;
package/types/kit.d.ts CHANGED
@@ -1,9 +1,12 @@
1
1
  import { Client as PasskeyClient } from 'passkey-kit-sdk';
2
+ import { Client as FactoryClient } from 'passkey-factory-sdk';
2
3
  import { xdr, Transaction } from '@stellar/stellar-sdk';
3
4
  import { Buffer } from 'buffer';
4
5
  import { PasskeyBase } from './base';
5
6
  export declare class PasskeyKit extends PasskeyBase {
6
7
  keyId: string | undefined;
8
+ networkPassphrase: string;
9
+ factory: FactoryClient;
7
10
  wallet: PasskeyClient | undefined;
8
11
  constructor(options: {
9
12
  rpcUrl: string;