passkey-kit 0.5.2 → 0.5.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.
@@ -2,7 +2,7 @@
2
2
  "rust-analyzer.linkedProjects": [
3
3
  "./zephyr/Cargo.toml",
4
4
  "./contracts/Cargo.toml",
5
- "./contracts/contract-webauthn-factory/Cargo.toml",
6
- "./contracts/contract-webauthn-secp256r1/Cargo.toml",
5
+ "./contracts/webauthn-factory/Cargo.toml",
6
+ "./contracts/webauthn-wallet/Cargo.toml",
7
7
  ]
8
8
  }
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/cheatsheet CHANGED
@@ -9,7 +9,7 @@ pnpm publish --no-git-checks
9
9
 
10
10
  export MERCURY_JWT=???
11
11
  mercury-cli --jwt $MERCURY_JWT --local false --mainnet false deploy
12
- mercury-cli --jwt $MERCURY_JWT --local false --mainnet false catchup --contracts "CCXIUFR243N7QWKXY44LZO3DVUXHAVBEEJWFGNGNVVB44VJXIYWVGNTR" # don't forget to subscribe to the contract first
12
+ mercury-cli --jwt $MERCURY_JWT --local false --mainnet false catchup --contracts "CDOWBLFYFIWXVUW46QILLAIYIWWCZ63CIRQBG3DK5PDBUVVJ4QVJX2IX" # don't forget to subscribe to the contract first
13
13
  curl -X GET https://api.mercurydata.app/catchups/4
14
14
  curl -X POST https://api.mercurydata.app/zephyr/execute -H "Authorization: Bearer $MERCURY_JWT" -H 'Content-Type: application/json' -d '{"mode":{"Function": {"fname": "get_signers_by_address", "arguments": "{\"address\": \"CCXIUFR243N7QWKXY44LZO3DVUXHAVBEEJWFGNGNVVB44VJXIYWVGNTR\"}"}}}'
15
15
  curl -X POST https://api.mercurydata.app/zephyr/execute -H "Authorization: Bearer $MERCURY_JWT" -H 'Content-Type: application/json' -d '{"mode":{"Function": {"fname": "get_address_by_signer", "arguments": "{\"id\": [78,127,30,69,248,174,95,168,47,59,161,168,51,120,117,135,112,133,232,92]}"}}}'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passkey-kit",
3
- "version": "0.5.2",
3
+ "version": "0.5.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",
@@ -8,13 +8,14 @@
8
8
  "main": "src/index.ts",
9
9
  "types": "types/index.d.ts",
10
10
  "dependencies": {
11
+ "@darkedges/capacitor-native-webauthn": "^0.0.4",
11
12
  "@simplewebauthn/browser": "^10.0.0",
12
13
  "@stellar/stellar-sdk": "12.1.0",
13
14
  "base64url": "^3.0.1",
14
15
  "buffer": "^6.0.3",
15
- "sac-sdk": "0.1.0",
16
+ "passkey-factory-sdk": "0.2.1",
16
17
  "passkey-kit-sdk": "0.2.1",
17
- "passkey-factory-sdk": "0.2.1"
18
+ "sac-sdk": "0.1.0"
18
19
  },
19
20
  "devDependencies": {
20
21
  "@simplewebauthn/types": "^10.0.0",
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
@@ -14,11 +15,19 @@ export class PasskeyKit extends PasskeyBase {
14
15
  public networkPassphrase: string
15
16
  public factory: FactoryClient
16
17
  public wallet: PasskeyClient | undefined
18
+ public WebAuthn: {
19
+ startRegistration: typeof startRegistration,
20
+ startAuthentication: typeof startAuthentication
21
+ }
17
22
 
18
23
  constructor(options: {
19
24
  rpcUrl: string,
20
25
  networkPassphrase: string,
21
26
  factoryContractId: string,
27
+ WebAuthn?: {
28
+ startRegistration: typeof startRegistration,
29
+ startAuthentication: typeof startAuthentication
30
+ }
22
31
  }) {
23
32
  const { rpcUrl, networkPassphrase, factoryContractId } = options
24
33
 
@@ -30,6 +39,7 @@ export class PasskeyKit extends PasskeyBase {
30
39
  networkPassphrase,
31
40
  rpcUrl
32
41
  })
42
+ this.WebAuthn = options.WebAuthn || { startRegistration, startAuthentication }
33
43
  }
34
44
 
35
45
  public async createWallet(app: string, user: string) {
@@ -41,7 +51,7 @@ export class PasskeyKit extends PasskeyBase {
41
51
  pk: publicKey
42
52
  })
43
53
 
44
- const contractId = result.unwrap() as string
54
+ const contractId = result.unwrap()
45
55
 
46
56
  this.wallet = new PasskeyClient({
47
57
  contractId,
@@ -52,14 +62,14 @@ export class PasskeyKit extends PasskeyBase {
52
62
  return {
53
63
  keyId,
54
64
  contractId,
55
- xdr: built!.toXDR() as string
65
+ xdr: built?.toXDR()
56
66
  }
57
67
  }
58
68
 
59
69
  public async createKey(app: string, user: string) {
60
70
  const now = new Date()
61
71
  const displayName = `${user} — ${now.toLocaleString()}`
62
- const { id, response } = await startRegistration({
72
+ const { id, response } = await this.WebAuthn.startRegistration({
63
73
  challenge: base64url("stellaristhebetterblockchain"),
64
74
  rp: {
65
75
  // id: undefined,
@@ -71,9 +81,9 @@ export class PasskeyKit extends PasskeyBase {
71
81
  displayName
72
82
  },
73
83
  // authenticatorSelection: {
74
- // requireResidentKey: false,
75
- // residentKey: "preferred",
76
- // userVerification: "discouraged",
84
+ // requireResidentKey: false,
85
+ // residentKey: "preferred",
86
+ // userVerification: "discouraged",
77
87
  // },
78
88
  pubKeyCredParams: [{ alg: -7, type: "public-key" }],
79
89
  // attestation: "none",
@@ -97,7 +107,7 @@ export class PasskeyKit extends PasskeyBase {
97
107
  let keyIdBuffer: Buffer
98
108
 
99
109
  if (!keyId) {
100
- const response = await startAuthentication({
110
+ const response = await this.WebAuthn.startAuthentication({
101
111
  challenge: base64url("stellaristhebetterblockchain"),
102
112
  // rpId: undefined,
103
113
  // userVerification: "discouraged",
@@ -162,8 +172,7 @@ export class PasskeyKit extends PasskeyBase {
162
172
  ledgersToLive?: number
163
173
  }
164
174
  ) {
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 || {}
175
+ let { keyId, ledgersToLive = DEFAULT_TIMEOUT } = options || {}
167
176
 
168
177
  const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
169
178
  const credentials = entry.credentials().address();
@@ -177,7 +186,7 @@ export class PasskeyKit extends PasskeyBase {
177
186
  )
178
187
  const payload = hash(preimage.toXDR())
179
188
 
180
- const authenticationResponse = await startAuthentication(
189
+ const authenticationResponse = await this.WebAuthn.startAuthentication(
181
190
  keyId === 'any'
182
191
  || (!keyId && !this.keyId)
183
192
  ? {
@@ -242,7 +251,7 @@ export class PasskeyKit extends PasskeyBase {
242
251
  && auth.credentials().address().address().switch().name === 'scAddressTypeContract'
243
252
  ) {
244
253
  // 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)
254
+ if (Address.contract(auth.credentials().address().address().contractId()).toString() === this.wallet?.options.contractId)
246
255
  await this.signAuthEntry(auth, options)
247
256
  }
248
257
  }
@@ -309,7 +318,7 @@ export class PasskeyKit extends PasskeyBase {
309
318
 
310
319
  if (response.publicKey) {
311
320
  publicKey = base64url.toBuffer(response.publicKey)
312
- publicKey = publicKey!.slice(publicKey!.length - 65)
321
+ publicKey = publicKey?.slice(publicKey.length - 65)
313
322
  }
314
323
 
315
324
  if (
@@ -331,7 +340,7 @@ export class PasskeyKit extends PasskeyBase {
331
340
 
332
341
  let publicKeykPrefixSlice = Buffer.from([0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20])
333
342
  let startIndex = attestationObject.indexOf(publicKeykPrefixSlice)
334
- startIndex = startIndex + publicKeykPrefixSlice.length
343
+ startIndex = startIndex + publicKeykPrefixSlice.length
335
344
 
336
345
  x = attestationObject.slice(startIndex, 32 + startIndex)
337
346
  y = attestationObject.slice(35 + startIndex, 67 + startIndex)
package/src/server.ts CHANGED
@@ -167,6 +167,7 @@ export class PasskeyServer extends PasskeyBase {
167
167
  @Later
168
168
  */
169
169
 
170
+ // TODO maybe fee should default to something more dynamic since we have endpoints for getting fee information now
170
171
  public async send(xdr: string, fee: number = 10_000) {
171
172
  if (!this.launchtubeUrl || !this.launchtubeJwt)
172
173
  throw new Error('Launchtube service not configured')
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
@@ -1,6 +1,7 @@
1
1
  import { Client as PasskeyClient } from 'passkey-kit-sdk';
2
2
  import { Client as FactoryClient } from 'passkey-factory-sdk';
3
3
  import { xdr, Transaction, SorobanRpc } from '@stellar/stellar-sdk';
4
+ import { startRegistration, startAuthentication } from "@simplewebauthn/browser";
4
5
  import { Buffer } from 'buffer';
5
6
  import { PasskeyBase } from './base';
6
7
  export declare class PasskeyKit extends PasskeyBase {
@@ -10,15 +11,23 @@ export declare class PasskeyKit extends PasskeyBase {
10
11
  networkPassphrase: string;
11
12
  factory: FactoryClient;
12
13
  wallet: PasskeyClient | undefined;
14
+ WebAuthn: {
15
+ startRegistration: typeof startRegistration;
16
+ startAuthentication: typeof startAuthentication;
17
+ };
13
18
  constructor(options: {
14
19
  rpcUrl: string;
15
20
  networkPassphrase: string;
16
21
  factoryContractId: string;
22
+ WebAuthn?: {
23
+ startRegistration: typeof startRegistration;
24
+ startAuthentication: typeof startAuthentication;
25
+ };
17
26
  });
18
27
  createWallet(app: string, user: string): Promise<{
19
28
  keyId: Buffer;
20
29
  contractId: string;
21
- xdr: string;
30
+ xdr: string | undefined;
22
31
  }>;
23
32
  createKey(app: string, user: string): Promise<{
24
33
  keyId: Buffer;