passkey-kit 0.7.2 → 0.7.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/cheatsheet CHANGED
@@ -13,7 +13,7 @@ stellar contract deploy --wasm target/wasm32-unknown-unknown/release/sample_poli
13
13
 
14
14
  export JWT=???
15
15
  mercury-cli --jwt $JWT --local false --mainnet false deploy
16
- mercury-cli --jwt $JWT --local false --mainnet false catchup --project-name "smart-wallets-data-multi-signer-multi-sig" --contracts "CDONKSPO6DUH46JRRIAK4O5ZINA5C2RXHP57BMFHKVBGOQXAT3IW6QCO"
16
+ mercury-cli --jwt $JWT --local false --mainnet false catchup --project-name "smart-wallets-data-multi-signer-multi-sig" --contracts "CBMMJ55OQSFSYASVENVHW55QNA4Q52GE42P23E4V7O37GKMETKOFFENA"
17
17
  curl -X GET https://api.mercurydata.app/catchups/4
18
18
  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\": \"CA4G3X75IGGNXNLXFIVFNYIGC6YAVLA7KSIFFDBSR7RQ7KEZMZWLXQBH\"}"}}}'
19
19
  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.7.2",
3
+ "version": "0.7.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",
@@ -14,8 +14,8 @@
14
14
  "base64url": "^3.0.1",
15
15
  "buffer": "^6.0.3",
16
16
  "passkey-factory-sdk": "0.3.1",
17
- "passkey-kit-sdk": "0.3.1",
18
- "sac-sdk": "0.1.0"
17
+ "sac-sdk": "0.1.0",
18
+ "passkey-kit-sdk": "0.3.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@simplewebauthn/types": "^10.0.0",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PasskeyServer } from "./server"
2
- import { PasskeyKit, DEFAULT_LTL } from "./kit"
2
+ import { PasskeyKit } from "./kit"
3
3
  import { SACClient } from "./sac"
4
4
 
5
- export { PasskeyServer, PasskeyKit, SACClient, DEFAULT_LTL }
5
+ export { PasskeyServer, PasskeyKit, SACClient }
package/src/kit.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Client as PasskeyClient, type Signature, type SignerKey } from 'passkey-kit-sdk'
2
2
  import { Client as FactoryClient } from 'passkey-factory-sdk'
3
- import { Address, StrKey, hash, xdr, Transaction, SorobanRpc, Operation, TransactionBuilder, Keypair } from '@stellar/stellar-sdk'
3
+ import { Address, StrKey, hash, xdr, Transaction, SorobanRpc, TransactionBuilder, Keypair } from '@stellar/stellar-sdk'
4
4
  import base64url from 'base64url'
5
5
  import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
6
6
  import type { AuthenticatorAttestationResponseJSON, AuthenticatorSelectionCriteria } from "@simplewebauthn/types"
@@ -8,8 +8,6 @@ import { Buffer } from 'buffer'
8
8
  import { PasskeyBase } from './base'
9
9
  import { DEFAULT_TIMEOUT } from '@stellar/stellar-sdk/contract'
10
10
 
11
- export const DEFAULT_LTL = 12
12
-
13
11
  export class PasskeyKit extends PasskeyBase {
14
12
  declare public rpc: SorobanRpc.Server
15
13
  declare public rpcUrl: string
@@ -195,17 +193,24 @@ export class PasskeyKit extends PasskeyBase {
195
193
  if (keyId && keypair)
196
194
  throw new Error('Provide either `options.keyId` or `options.keypair` but not both')
197
195
 
196
+ const credentials = entry.credentials().address();
197
+
198
198
  if (!validUntilLedgerSeq) {
199
- const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
200
- validUntilLedgerSeq = lastLedger + DEFAULT_TIMEOUT / 5;
199
+ validUntilLedgerSeq = credentials.signatureExpirationLedger()
200
+
201
+ if (!validUntilLedgerSeq) {
202
+ const lastLedger = await this.rpc.getLatestLedger().then(({ sequence }) => sequence)
203
+ validUntilLedgerSeq = lastLedger + DEFAULT_TIMEOUT / 5;
204
+ }
201
205
  }
202
206
 
203
- const credentials = entry.credentials().address();
207
+ credentials.signatureExpirationLedger(validUntilLedgerSeq)
208
+
204
209
  const preimage = xdr.HashIdPreimage.envelopeTypeSorobanAuthorization(
205
210
  new xdr.HashIdPreimageSorobanAuthorization({
206
211
  networkId: hash(Buffer.from(this.networkPassphrase)),
207
212
  nonce: credentials.nonce(),
208
- signatureExpirationLedger: validUntilLedgerSeq,
213
+ signatureExpirationLedger: credentials.signatureExpirationLedger(),
209
214
  invocation: entry.rootInvocation()
210
215
  })
211
216
  )
@@ -295,14 +300,17 @@ export class PasskeyKit extends PasskeyBase {
295
300
  credentials.signature(xdr.ScVal.scvMap([scEntry]))
296
301
  break;
297
302
  case 'scvMap':
303
+ // Add the new signature to the existing map
298
304
  credentials.signature().map()?.push(scEntry)
305
+ // Order the map by key
306
+ credentials.signature().map()?.sort((a, b) =>
307
+ a.key().toXDR().compare(b.key().toXDR())
308
+ )
299
309
  break;
300
310
  default:
301
311
  throw new Error('Unsupported signature')
302
312
  }
303
313
 
304
- credentials.signatureExpirationLedger(validUntilLedgerSeq)
305
-
306
314
  return entry
307
315
  }
308
316
 
@@ -315,6 +323,8 @@ export class PasskeyKit extends PasskeyBase {
315
323
  validUntilLedgerSeq?: number
316
324
  }
317
325
  ) {
326
+ // TODO should there be more control over which auth entries are signed? Especially given we support multiple signers now?
327
+ // As-is .sign() will always sign every smart wallet auth entry. This may be okay but likely we should have more control over which auth entry the signer is signing
318
328
  for (const auth of entries) {
319
329
  if (
320
330
  auth.credentials().switch().name === 'sorobanCredentialsAddress'
package/types/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { PasskeyServer } from "./server";
2
- import { PasskeyKit, DEFAULT_LTL } from "./kit";
2
+ import { PasskeyKit } from "./kit";
3
3
  import { SACClient } from "./sac";
4
- export { PasskeyServer, PasskeyKit, SACClient, DEFAULT_LTL };
4
+ export { PasskeyServer, PasskeyKit, SACClient };
package/types/kit.d.ts CHANGED
@@ -5,7 +5,6 @@ import { startRegistration, startAuthentication } from "@simplewebauthn/browser"
5
5
  import type { AuthenticatorSelectionCriteria } from "@simplewebauthn/types";
6
6
  import { Buffer } from 'buffer';
7
7
  import { PasskeyBase } from './base';
8
- export declare const DEFAULT_LTL = 12;
9
8
  export declare class PasskeyKit extends PasskeyBase {
10
9
  rpc: SorobanRpc.Server;
11
10
  rpcUrl: string;