passkey-kit 0.5.3 → 0.5.5

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/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.3",
3
+ "version": "0.5.5",
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,6 +8,7 @@
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",
package/src/kit.ts CHANGED
@@ -15,13 +15,21 @@ export class PasskeyKit extends PasskeyBase {
15
15
  public networkPassphrase: string
16
16
  public factory: FactoryClient
17
17
  public wallet: PasskeyClient | undefined
18
+ public WebAuthn: {
19
+ startRegistration: typeof startRegistration,
20
+ startAuthentication: typeof startAuthentication
21
+ }
18
22
 
19
23
  constructor(options: {
20
24
  rpcUrl: string,
21
25
  networkPassphrase: string,
22
26
  factoryContractId: string,
27
+ WebAuthn?: {
28
+ startRegistration: typeof startRegistration,
29
+ startAuthentication: typeof startAuthentication
30
+ }
23
31
  }) {
24
- const { rpcUrl, networkPassphrase, factoryContractId } = options
32
+ const { rpcUrl, networkPassphrase, factoryContractId, WebAuthn } = options
25
33
 
26
34
  super(rpcUrl)
27
35
 
@@ -31,6 +39,7 @@ export class PasskeyKit extends PasskeyBase {
31
39
  networkPassphrase,
32
40
  rpcUrl
33
41
  })
42
+ this.WebAuthn = WebAuthn || { startRegistration, startAuthentication }
34
43
  }
35
44
 
36
45
  public async createWallet(app: string, user: string) {
@@ -57,13 +66,13 @@ export class PasskeyKit extends PasskeyBase {
57
66
  }
58
67
  }
59
68
 
60
- public async createKey(app: string, user: string) {
69
+ public async createKey(app: string, user: string, rpId?: string) {
61
70
  const now = new Date()
62
71
  const displayName = `${user} — ${now.toLocaleString()}`
63
- const { id, response } = await startRegistration({
72
+ const { id, response } = await this.WebAuthn.startRegistration({
64
73
  challenge: base64url("stellaristhebetterblockchain"),
65
74
  rp: {
66
- // id: undefined,
75
+ id: rpId,
67
76
  name: app,
68
77
  },
69
78
  user: {
@@ -72,9 +81,9 @@ export class PasskeyKit extends PasskeyBase {
72
81
  displayName
73
82
  },
74
83
  // authenticatorSelection: {
75
- // requireResidentKey: false,
76
- // residentKey: "preferred",
77
- // userVerification: "discouraged",
84
+ // requireResidentKey: false,
85
+ // residentKey: "preferred",
86
+ // userVerification: "discouraged",
78
87
  // },
79
88
  pubKeyCredParams: [{ alg: -7, type: "public-key" }],
80
89
  // attestation: "none",
@@ -92,15 +101,16 @@ export class PasskeyKit extends PasskeyBase {
92
101
 
93
102
  public async connectWallet(opts?: {
94
103
  keyId?: string | Uint8Array,
104
+ rpId?: string,
95
105
  getContractId?: (keyId: string) => Promise<string | undefined>
96
106
  }) {
97
- let { keyId, getContractId } = opts || {}
107
+ let { keyId, rpId, getContractId } = opts || {}
98
108
  let keyIdBuffer: Buffer
99
109
 
100
110
  if (!keyId) {
101
- const response = await startAuthentication({
111
+ const response = await this.WebAuthn.startAuthentication({
102
112
  challenge: base64url("stellaristhebetterblockchain"),
103
- // rpId: undefined,
113
+ rpId,
104
114
  // userVerification: "discouraged",
105
115
  // timeout: 120_000
106
116
  });
@@ -160,10 +170,11 @@ export class PasskeyKit extends PasskeyBase {
160
170
  entry: xdr.SorobanAuthorizationEntry,
161
171
  options?: {
162
172
  keyId?: 'any' | string | Uint8Array
173
+ rpId?: string,
163
174
  ledgersToLive?: number
164
175
  }
165
176
  ) {
166
- let { keyId, ledgersToLive = DEFAULT_TIMEOUT } = options || {}
177
+ let { keyId, rpId, ledgersToLive = DEFAULT_TIMEOUT } = options || {}
167
178
 
168
179
  const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
169
180
  const credentials = entry.credentials().address();
@@ -177,18 +188,18 @@ export class PasskeyKit extends PasskeyBase {
177
188
  )
178
189
  const payload = hash(preimage.toXDR())
179
190
 
180
- const authenticationResponse = await startAuthentication(
191
+ const authenticationResponse = await this.WebAuthn.startAuthentication(
181
192
  keyId === 'any'
182
193
  || (!keyId && !this.keyId)
183
194
  ? {
184
195
  challenge: base64url(payload),
185
- // rpId: undefined,
196
+ rpId,
186
197
  // userVerification: "discouraged",
187
198
  // timeout: 120_000
188
199
  }
189
200
  : {
190
201
  challenge: base64url(payload),
191
- // rpId: undefined,
202
+ rpId,
192
203
  allowCredentials: [
193
204
  {
194
205
  id: keyId instanceof Uint8Array
@@ -331,7 +342,7 @@ export class PasskeyKit extends PasskeyBase {
331
342
 
332
343
  let publicKeykPrefixSlice = Buffer.from([0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20])
333
344
  let startIndex = attestationObject.indexOf(publicKeykPrefixSlice)
334
- startIndex = startIndex + publicKeykPrefixSlice.length
345
+ startIndex = startIndex + publicKeykPrefixSlice.length
335
346
 
336
347
  x = attestationObject.slice(startIndex, 32 + startIndex)
337
348
  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/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,22 +11,31 @@ 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
30
  xdr: string | undefined;
22
31
  }>;
23
- createKey(app: string, user: string): Promise<{
32
+ createKey(app: string, user: string, rpId?: string): Promise<{
24
33
  keyId: Buffer;
25
34
  publicKey: Buffer;
26
35
  }>;
27
36
  connectWallet(opts?: {
28
37
  keyId?: string | Uint8Array;
38
+ rpId?: string;
29
39
  getContractId?: (keyId: string) => Promise<string | undefined>;
30
40
  }): Promise<{
31
41
  keyId: Buffer;
@@ -33,6 +43,7 @@ export declare class PasskeyKit extends PasskeyBase {
33
43
  }>;
34
44
  signAuthEntry(entry: xdr.SorobanAuthorizationEntry, options?: {
35
45
  keyId?: 'any' | string | Uint8Array;
46
+ rpId?: string;
36
47
  ledgersToLive?: number;
37
48
  }): Promise<xdr.SorobanAuthorizationEntry>;
38
49
  signAuthEntries(entries: xdr.SorobanAuthorizationEntry[], options?: {