passkey-kit 0.5.1 → 0.5.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Passkey Kit
2
2
 
3
- Passkey kit is a basic TypeScript SDK for creating and managing Stellar smart wallets. It's intended to be used in tandem with [Launchtube](https://github.com/kalepail/launchtube) for submitting passkey signed transactions onchain however this is not a requirement. This is both a client and a server side library. `PasskeyKit` on the client and `PasskeyBase` on the server.
3
+ Passkey kit is a basic TypeScript SDK for creating and managing Stellar smart wallets. It's intended to be used in tandem with [Launchtube](https://github.com/kalepail/launchtube) for submitting passkey signed transactions onchain however this is not a requirement. This is both a client and a server side library. `PasskeyKit` on the client and `PasskeyServer` on the server.
4
4
 
5
5
  Demo site: [passkey-kit-demo.pages.dev](https://passkey-kit-demo.pages.dev/)
6
6
 
@@ -20,7 +20,7 @@ const account = new PasskeyKit({
20
20
 
21
21
  On the server:
22
22
  ```ts
23
- const account = new PasskeyBase({
23
+ const account = new PasskeyServer({
24
24
  rpcUrl: env.PUBLIC_rpcUrl,
25
25
  launchtubeUrl: env.PUBLIC_launchtubeUrl,
26
26
  launchtubeJwt: env.PRIVATE_launchtubeJwt,
@@ -30,9 +30,15 @@ const account = new PasskeyBase({
30
30
  });
31
31
  ```
32
32
 
33
- Note that while I don't recommend it you can use the server-intended `send` method on the client side by passing in the `launchtubeUrl` and `launchtubeJwt` values to the `PasskeyKit` constructor. We do this in the `./demo` site to ease demonstration, development and experimentation, however in a production environment you'll want to keep your secrets safe on the server.
33
+ This is a fully typed library so docs aren't provided, however there's a full example showcasing all the core public methods in the `./demo` directory. I also recommend reviewing the [Super Peach](https://github.com/kalepail/superpeach) repo for an example of how you could implement both the client and server side in a more real-world scenario.
34
+
35
+ Good luck, have fun, and change the world!
36
+
37
+ For any questions or to showcase your progress please join the `#passkeys` channel on our [Discord](https://discord.gg/stellardev).
38
+
39
+ ## Deploy the event indexer
34
40
 
35
- In order to utilize the zephyr indexing service to track available signers and reverse lookup smart wallet contract addresses from passkey ids you'll need to deploy the Zephyr program from inside the `./zephyr` directory.
41
+ In order to utilize the Mercury Zephyr indexing service to track available signers and reverse lookup smart wallet contract addresses from passkey ids you'll need to deploy the Zephyr program from inside the `./zephyr` directory.
36
42
 
37
43
  ```bash
38
44
  cd ./zephyr
@@ -43,13 +49,7 @@ export MERCURY_JWT="<YOUR.MERCURY.JWT>"
43
49
  mercury-cli --jwt $MERCURY_JWT --local false --mainnet false deploy
44
50
  ```
45
51
 
46
- This is a fully typed library so docs aren't provided, however there's a full example showcasing all the core public methods in the `./demo` directory. I also recommend reviewing the [Super Peach](https://github.com/kalepail/superpeach) repo for an example of how you could implement both the client and server side in a more real-world scenario.
47
-
48
- Good luck, have fun, and change the world!
49
-
50
- For any questions or to showcase your progress please join the `#passkeys` channel on our [Discord](https://discord.gg/stellardev).
51
-
52
- ## Some Notes
52
+ ## TypeScript gotchas
53
53
 
54
54
  This is a TypeScript library and the npm package doesn't export a JavaScript version. The `@stellar/stellar-sdk` library is enormous and I really don't wan't folks bundling it up twice. Therefore you'll need to ensure you're transpiling this library into your project and that goes for either a TS project or a JS one. For many of you this will "just work" but for others you'll need to do some fiddling.
55
55
 
@@ -60,7 +60,8 @@ const nextConfig = {
60
60
  transpilePackages: [
61
61
  'passkey-kit',
62
62
  'passkey-factory-sdk',
63
- 'passkey-kit-sdk'
63
+ 'passkey-kit-sdk',
64
+ 'sac-sdk',
64
65
  ]
65
66
  };
66
67
 
@@ -71,10 +72,10 @@ If someone smarter than me knows how to include an optional JS build from a TS l
71
72
  ## Contributing
72
73
 
73
74
  Passkey kit consists of three primary directories:
74
- - `./contracts` - Contains the Rust Soroban smart contracts of the smart wallet implementation.
75
- - `./zephyr` - Contains the [Zephyr](https://www.mercurydata.app/products/zephyr-vm) program for processing smart wallet events.
76
75
  - `./src` - Contains the TypeScript files for the actual TS SDK library.
77
76
  - `./demo` - Contains a basic demo of the SDK in action.
77
+ - `./contracts` - Contains the Rust Soroban smart contracts of the smart wallet implementation.
78
+ - `./zephyr` - Contains the [Zephyr](https://www.mercurydata.app/products/zephyr-vm) program for processing smart wallet events.
78
79
 
79
80
  To install dependencies:
80
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passkey-kit",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
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,6 +6,7 @@ import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
6
6
  import type { AuthenticatorAttestationResponseJSON } from "@simplewebauthn/types"
7
7
  import { Buffer } from 'buffer'
8
8
  import { PasskeyBase } from './base'
9
+ import { DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
9
10
 
10
11
  export class PasskeyKit extends PasskeyBase {
11
12
  declare public rpc: SorobanRpc.Server
@@ -41,7 +42,7 @@ export class PasskeyKit extends PasskeyBase {
41
42
  pk: publicKey
42
43
  })
43
44
 
44
- const contractId = result.unwrap() as string
45
+ const contractId = result.unwrap()
45
46
 
46
47
  this.wallet = new PasskeyClient({
47
48
  contractId,
@@ -52,7 +53,7 @@ export class PasskeyKit extends PasskeyBase {
52
53
  return {
53
54
  keyId,
54
55
  contractId,
55
- xdr: built!.toXDR() as string
56
+ xdr: built?.toXDR()
56
57
  }
57
58
  }
58
59
 
@@ -70,14 +71,14 @@ export class PasskeyKit extends PasskeyBase {
70
71
  name: displayName,
71
72
  displayName
72
73
  },
73
- authenticatorSelection: {
74
- requireResidentKey: false,
75
- residentKey: "preferred",
76
- userVerification: "discouraged",
77
- },
74
+ // authenticatorSelection: {
75
+ // requireResidentKey: false,
76
+ // residentKey: "preferred",
77
+ // userVerification: "discouraged",
78
+ // },
78
79
  pubKeyCredParams: [{ alg: -7, type: "public-key" }],
79
- attestation: "none",
80
- timeout: 120_000,
80
+ // attestation: "none",
81
+ // timeout: 120_000,
81
82
  });
82
83
 
83
84
  if (!this.keyId)
@@ -100,8 +101,8 @@ export class PasskeyKit extends PasskeyBase {
100
101
  const response = await startAuthentication({
101
102
  challenge: base64url("stellaristhebetterblockchain"),
102
103
  // rpId: undefined,
103
- userVerification: "discouraged",
104
- timeout: 120_000
104
+ // userVerification: "discouraged",
105
+ // timeout: 120_000
105
106
  });
106
107
 
107
108
  keyId = response.id
@@ -162,8 +163,7 @@ export class PasskeyKit extends PasskeyBase {
162
163
  ledgersToLive?: number
163
164
  }
164
165
  ) {
165
- // Default mirrors DEFAULT_TIMEOUT (currently 5 minutes) https://github.com/stellar/js-stellar-sdk/blob/master/src/contract/utils.ts#L7
166
- let { keyId, ledgersToLive = 60 } = options || {}
166
+ let { keyId, ledgersToLive = DEFAULT_TIMEOUT } = options || {}
167
167
 
168
168
  const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
169
169
  const credentials = entry.credentials().address();
@@ -183,8 +183,8 @@ export class PasskeyKit extends PasskeyBase {
183
183
  ? {
184
184
  challenge: base64url(payload),
185
185
  // rpId: undefined,
186
- userVerification: "discouraged",
187
- timeout: 120_000
186
+ // userVerification: "discouraged",
187
+ // timeout: 120_000
188
188
  }
189
189
  : {
190
190
  challenge: base64url(payload),
@@ -197,8 +197,8 @@ export class PasskeyKit extends PasskeyBase {
197
197
  type: "public-key",
198
198
  },
199
199
  ],
200
- userVerification: "discouraged",
201
- timeout: 120_000
200
+ // userVerification: "discouraged",
201
+ // timeout: 120_000
202
202
  }
203
203
  );
204
204
 
@@ -242,7 +242,7 @@ export class PasskeyKit extends PasskeyBase {
242
242
  && auth.credentials().address().address().switch().name === 'scAddressTypeContract'
243
243
  ) {
244
244
  // If auth entry matches our Smart Wallet move forward with the signature request
245
- if (Address.contract(auth.credentials().address().address().contractId()).toString() === this.wallet!.options.contractId)
245
+ if (Address.contract(auth.credentials().address().address().contractId()).toString() === this.wallet?.options.contractId)
246
246
  await this.signAuthEntry(auth, options)
247
247
  }
248
248
  }
@@ -309,7 +309,7 @@ export class PasskeyKit extends PasskeyBase {
309
309
 
310
310
  if (response.publicKey) {
311
311
  publicKey = base64url.toBuffer(response.publicKey)
312
- publicKey = publicKey!.slice(publicKey!.length - 65)
312
+ publicKey = publicKey?.slice(publicKey.length - 65)
313
313
  }
314
314
 
315
315
  if (
@@ -327,13 +327,14 @@ export class PasskeyKit extends PasskeyBase {
327
327
  x = authenticatorData.slice(65 + credentialIdLength, 97 + credentialIdLength)
328
328
  y = authenticatorData.slice(100 + credentialIdLength, 132 + credentialIdLength)
329
329
  } else {
330
- const attestationData = base64url.toBuffer(response.attestationObject)
331
-
332
- let startIndex = attestationData.indexOf(0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20)
333
- startIndex = startIndex + startIndex.length
330
+ const attestationObject = base64url.toBuffer(response.attestationObject)
331
+
332
+ let publicKeykPrefixSlice = Buffer.from([0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20])
333
+ let startIndex = attestationObject.indexOf(publicKeykPrefixSlice)
334
+ startIndex = startIndex + publicKeykPrefixSlice.length
334
335
 
335
- x = attestationData.slice(startIndex, 32 + startIndex)
336
- y = attestationData.slice(35 + startIndex, 67 + startIndex)
336
+ x = attestationObject.slice(startIndex, 32 + startIndex)
337
+ y = attestationObject.slice(35 + startIndex, 67 + startIndex)
337
338
  }
338
339
 
339
340
  publicKey = Buffer.from([
package/src/sac.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { SorobanRpc } from "@stellar/stellar-sdk"
2
1
  import { Client as SacClient } from 'sac-sdk'
2
+ import { PasskeyBase } from "./base"
3
+ import type { SorobanRpc } from '@stellar/stellar-sdk'
3
4
 
4
- export class SACClient {
5
+ export class SACClient extends PasskeyBase {
6
+ declare public rpc: SorobanRpc.Server
7
+ declare public rpcUrl: string
5
8
  public networkPassphrase: string
6
- public rpcUrl: string
7
- public rpc: SorobanRpc.Server
8
9
 
9
10
  constructor(options: {
10
11
  networkPassphrase: string,
@@ -12,9 +13,9 @@ export class SACClient {
12
13
  }) {
13
14
  const { networkPassphrase, rpcUrl } = options
14
15
 
16
+ super(rpcUrl)
17
+
15
18
  this.networkPassphrase = networkPassphrase
16
- this.rpcUrl = rpcUrl
17
- this.rpc = new SorobanRpc.Server(rpcUrl)
18
19
  }
19
20
 
20
21
  public getSACClient(SACContractId: string) {
@@ -23,72 +24,5 @@ export class SACClient {
23
24
  networkPassphrase: this.networkPassphrase,
24
25
  rpcUrl: this.rpcUrl
25
26
  })
26
-
27
- // switch (command) {
28
- // case SacCommands.Allowance:
29
- // return sac.allowance(args)
30
- // case SacCommands.Authorized:
31
- // return sac.authorized(args)
32
- // case SacCommands.Approve:
33
- // return sac.approve(args)
34
- // case SacCommands.Balance:
35
- // return sac.balance(args)
36
- // case SacCommands.Burn:
37
- // return sac.burn(args)
38
- // case SacCommands.BurnFrom:
39
- // return sac.burn_from(args)
40
- // case SacCommands.Clawback:
41
- // return sac.clawback(args)
42
- // case SacCommands.Decimals:
43
- // return sac.decimals(args)
44
- // case SacCommands.Mint:
45
- // return sac.mint(args)
46
- // case SacCommands.Name:
47
- // return sac.name(args)
48
- // case SacCommands.SetAdmin:
49
- // return sac.set_admin(args)
50
- // case SacCommands.Admin:
51
- // return sac.admin(args)
52
- // case SacCommands.SetAuthorized:
53
- // return sac.set_authorized(args)
54
- // case SacCommands.Symbol:
55
- // return sac.symbol(args)
56
- // case SacCommands.Transfer:
57
- // return sac.transfer(args)
58
- // case SacCommands.TransferFrom:
59
- // return sac.transfer_from(args)
60
- // default:
61
- // throw new Error('Invalid command')
62
- // }
63
-
64
- // const { SAC, from, to, amount, fee = 0 } = args
65
- // const txn = new TransactionBuilder(mockSource, {
66
- // fee: fee.toString(),
67
- // networkPassphrase: import.meta.env.VITE_networkPassphrase
68
- // })
69
- // .addOperation(Operation.invokeContractFunction({
70
- // contract: SAC,
71
- // function: 'transfer',
72
- // args: [
73
- // nativeToScVal(from, { type: 'address' }),
74
- // nativeToScVal(to, { type: 'address' }),
75
- // nativeToScVal(amount, { type: 'i128' })
76
- // ],
77
- // }))
78
- // .setTimeout(5 * 60)
79
- // .build()
80
-
81
- // const sim = await rpc.simulateTransaction(txn)
82
-
83
- // if (
84
- // SorobanRpc.Api.isSimulationError(sim)
85
- // || SorobanRpc.Api.isSimulationRestore(sim)
86
- // ) throw sim
87
-
88
- // return {
89
- // txn,
90
- // sim,
91
- // built: SorobanRpc.assembleTransaction(txn, sim).build()
92
- // }
93
27
  }
94
28
  }
package/tsconfig.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "module": "ESNext",
7
7
  "moduleDetection": "force",
8
8
  // Bundler mode
9
- "moduleResolution": "node",
9
+ "moduleResolution": "Bundler",
10
10
  "allowImportingTsExtensions": true,
11
11
  "verbatimModuleSyntax": true,
12
12
  "declaration": true,
@@ -21,12 +21,7 @@
21
21
  "noPropertyAccessFromIndexSignature": false,
22
22
  "strictNullChecks": true,
23
23
  },
24
- "exclude": [
25
- "./bun_tests",
26
- "./contracts",
27
- "./demo",
28
- "./packages",
29
- "./types",
30
- "./zephyr",
31
- ]
24
+ "include": [
25
+ "src/*",
26
+ ],
32
27
  }
package/types/kit.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare class PasskeyKit extends PasskeyBase {
18
18
  createWallet(app: string, user: string): Promise<{
19
19
  keyId: Buffer;
20
20
  contractId: string;
21
- xdr: string;
21
+ xdr: string | undefined;
22
22
  }>;
23
23
  createKey(app: string, user: string): Promise<{
24
24
  keyId: Buffer;
package/types/sac.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { SorobanRpc } from "@stellar/stellar-sdk";
2
1
  import { Client as SacClient } from 'sac-sdk';
3
- export declare class SACClient {
4
- networkPassphrase: string;
5
- rpcUrl: string;
2
+ import { PasskeyBase } from "./base";
3
+ import type { SorobanRpc } from '@stellar/stellar-sdk';
4
+ export declare class SACClient extends PasskeyBase {
6
5
  rpc: SorobanRpc.Server;
6
+ rpcUrl: string;
7
+ networkPassphrase: string;
7
8
  constructor(options: {
8
9
  networkPassphrase: string;
9
10
  rpcUrl: string;