@amadeus-protocol/wallet-sdk 0.1.5 → 0.1.7

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.
Files changed (68) hide show
  1. package/README.md +17 -0
  2. package/dist/binary.d.ts +0 -2
  3. package/dist/binary.d.ts.map +1 -1
  4. package/dist/binary.js +1 -2
  5. package/dist/bytes.d.ts +0 -2
  6. package/dist/bytes.d.ts.map +1 -1
  7. package/dist/bytes.js +1 -2
  8. package/dist/client/injected.d.ts +2 -2
  9. package/dist/client/injected.d.ts.map +1 -1
  10. package/dist/client/injected.js +6 -2
  11. package/dist/client/injected.js.map +1 -1
  12. package/dist/constants.d.ts +0 -2
  13. package/dist/constants.d.ts.map +1 -1
  14. package/dist/constants.js +1 -2
  15. package/dist/crypto/apikey.d.ts +0 -2
  16. package/dist/crypto/apikey.d.ts.map +1 -1
  17. package/dist/crypto/apikey.js +1 -2
  18. package/dist/crypto/bls.d.ts +0 -2
  19. package/dist/crypto/bls.d.ts.map +1 -1
  20. package/dist/crypto/bls.js +1 -2
  21. package/dist/crypto/box.d.ts +0 -2
  22. package/dist/crypto/box.d.ts.map +1 -1
  23. package/dist/crypto/box.js +1 -2
  24. package/dist/crypto/connect.d.ts +0 -2
  25. package/dist/crypto/connect.d.ts.map +1 -1
  26. package/dist/crypto/connect.js +1 -2
  27. package/dist/crypto/message.d.ts +0 -2
  28. package/dist/crypto/message.d.ts.map +1 -1
  29. package/dist/crypto/message.js +1 -2
  30. package/dist/errors.d.ts +1 -3
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/errors.js +1 -2
  33. package/dist/errors.js.map +1 -1
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.js +2 -2
  36. package/dist/react/index.d.ts +2 -2
  37. package/dist/react/index.d.ts.map +1 -1
  38. package/dist/react/index.js +2 -2
  39. package/dist/react/index.js.map +1 -1
  40. package/dist/schema.d.ts +10 -3
  41. package/dist/schema.d.ts.map +1 -1
  42. package/dist/schema.js +4 -3
  43. package/dist/schema.js.map +1 -1
  44. package/dist/transport/bridge.d.ts +0 -2
  45. package/dist/transport/bridge.d.ts.map +1 -1
  46. package/dist/transport/bridge.js +1 -2
  47. package/dist/transport/envelope.d.ts +1 -3
  48. package/dist/transport/envelope.d.ts.map +1 -1
  49. package/dist/transport/envelope.js +3 -3
  50. package/dist/transport/envelope.js.map +1 -1
  51. package/dist/transport/session.d.ts +0 -2
  52. package/dist/transport/session.d.ts.map +1 -1
  53. package/dist/transport/session.js +1 -2
  54. package/dist/transport/uri.d.ts +0 -2
  55. package/dist/transport/uri.d.ts.map +1 -1
  56. package/dist/transport/uri.js +1 -2
  57. package/dist/tx.d.ts +0 -2
  58. package/dist/tx.d.ts.map +1 -1
  59. package/dist/tx.js +1 -2
  60. package/dist/types.d.ts +8 -2
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/types.js +1 -2
  63. package/dist/types.js.map +1 -1
  64. package/dist/wallet/handler.d.ts +3 -4
  65. package/dist/wallet/handler.d.ts.map +1 -1
  66. package/dist/wallet/handler.js +5 -4
  67. package/dist/wallet/handler.js.map +1 -1
  68. package/package.json +3 -3
package/README.md CHANGED
@@ -41,6 +41,23 @@ const result = verifyApiKey(apiKey, { aud: 'amadeus' })
41
41
  if (result.valid) console.log(result.address)
42
42
  ```
43
43
 
44
+ > **The token's address is the public key of the `seed` you pass in.** A recovery
45
+ > phrase can open two different addresses (the standard `eip2333` derivation, and
46
+ > the `legacy` raw-BIP39 seed used by wallets created with older extension and app
47
+ > builds), so don't assume one. Resolve the seed with `resolveCandidateForAddress`
48
+ > (sdk ≥ 1.6.0), which returns the candidate whose `publicKey` equals the user's
49
+ > wallet address, or `null` if neither derivation opens it (it throws on an
50
+ > invalid phrase). Otherwise the token silently belongs to a different account.
51
+ >
52
+ > ```ts
53
+ > import { resolveCandidateForAddress } from '@amadeus-protocol/sdk'
54
+ > import { generateApiKey } from '@amadeus-protocol/wallet-sdk'
55
+ >
56
+ > const candidate = resolveCandidateForAddress(phrase, walletAddress)
57
+ > if (!candidate) throw new Error('This phrase does not open that address')
58
+ > const { apiKey } = generateApiKey({ seed: candidate.seed, aud: 'amadeus', expIn: 3600 })
59
+ > ```
60
+
44
61
  ## Security notes
45
62
 
46
63
  - **Distinct DSTs** (`_TX_`, `_APIKEY_`, `_CONNECT_`) make a signature from one
package/dist/binary.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/binary.d.ts
2
1
  /**
3
2
  * JSON-safe encoding for binary values (typed arrays) that cross a text
4
3
  * transport. Transaction args can contain raw bytes (e.g. a recipient pubkey);
@@ -25,6 +24,5 @@ declare function encodeBinaryValues(value: unknown): unknown;
25
24
  declare function decodeBinaryValues(value: unknown): unknown;
26
25
  /** Human-readable stand-in for tagged bytes when displaying args in an approval UI. */
27
26
  declare function describeBinaryValues(value: unknown): unknown;
28
- //#endregion
29
27
  export { BYTES_TAG, TaggedBytes, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes };
30
28
  //# sourceMappingURL=binary.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"binary.d.ts","names":[],"sources":["../src/binary.ts"],"mappings":";;;;;;;;;;;;;cAea;KAED;GAAiB;;iBAab,cAAc,iBAAiB,SAAS;;;;;iBAcxC,mBAAmB;;iBAkBnB,mBAAmB;;iBAgBnB,qBAAqB"}
1
+ {"version":3,"file":"binary.d.ts","names":[],"sources":["../src/binary.ts"],"mappings":";;;;;;;;;;;;cAea;KAED;GAAiB;;iBAab,cAAc,iBAAiB,SAAS;;;;;iBAcxC,mBAAmB;;iBAkBnB,mBAAmB;;iBAgBnB,qBAAqB"}
package/dist/binary.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { base64ToUint8Array, uint8ArrayToBase64 } from "@amadeus-protocol/sdk";
2
- //#region src/binary.ts
2
+ // src/binary.ts
3
3
  /**
4
4
  * JSON-safe encoding for binary values (typed arrays) that cross a text
5
5
  * transport. Transaction args can contain raw bytes (e.g. a recipient pubkey);
@@ -50,7 +50,6 @@ function describeBinaryValues(value) {
50
50
  if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, describeBinaryValues(entry)]));
51
51
  return value;
52
52
  }
53
- //#endregion
54
53
  export { BYTES_TAG, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes };
55
54
 
56
55
  //# sourceMappingURL=binary.js.map
package/dist/bytes.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { concatBytes, randomBytes } from "@noble/hashes/utils";
2
- //#region src/bytes.d.ts
3
2
  declare const concatBytes$1: typeof concatBytes;
4
3
  declare const randomBytes$1: typeof randomBytes;
5
4
  /** A random hex id (default 16 bytes → 32 hex chars). Used for request ids. */
@@ -15,6 +14,5 @@ declare function u32be(n: number): Uint8Array;
15
14
  * (`box.open`) and BLS verification both rely on noble's constant-time primitives.
16
15
  */
17
16
  declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
18
- //#endregion
19
17
  export { bytesToUtf8, concatBytes$1 as concatBytes, equalBytes, randomBytes$1 as randomBytes, randomId, u32be, utf8ToBytes };
20
18
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","names":["concatBytes","nobleConcat","randomBytes","nobleRandom"],"sources":["../src/bytes.ts"],"mappings":";;cAeaA,sBAAWC;cACXC,sBAAWC;;iBAGR,SAAS;iBAIT,YAAY,gBAAgB;iBAI5B,YAAY,OAAO;;iBAKnB,MAAM,YAAY;;;;;;;iBAkBlB,WAAW,GAAG,YAAY,GAAG"}
1
+ {"version":3,"file":"bytes.d.ts","names":["concatBytes","nobleConcat","randomBytes","nobleRandom"],"sources":["../src/bytes.ts"],"mappings":";cAeaA,sBAAWC;cACXC,sBAAWC;;iBAGR,SAAS;iBAIT,YAAY,gBAAgB;iBAI5B,YAAY,OAAO;;iBAKnB,MAAM,YAAY;;;;;;;iBAkBlB,WAAW,GAAG,YAAY,GAAG"}
package/dist/bytes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { bytesToHex, concatBytes, randomBytes } from "@noble/hashes/utils";
2
- //#region src/bytes.ts
2
+ // src/bytes.ts
3
3
  /**
4
4
  * Small byte helpers, kept isomorphic (Node, browser, React Native/Hermes).
5
5
  *
@@ -42,7 +42,6 @@ function equalBytes(a, b) {
42
42
  for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
43
43
  return diff === 0;
44
44
  }
45
- //#endregion
46
45
  export { bytesToUtf8, concatBytes$1 as concatBytes, equalBytes, randomBytes$1 as randomBytes, randomId, u32be, utf8ToBytes };
47
46
 
48
47
  //# sourceMappingURL=bytes.js.map
@@ -1,5 +1,4 @@
1
1
  import { AmadeusEventPayloadMap, AmadeusProvider, AmadeusProviderEvent, SignTransactionRequest, SignTransactionResponse } from "../types.js";
2
- //#region src/client/injected.d.ts
3
2
  /** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */
4
3
  interface ApiKeyStore {
5
4
  get(): string | null;
@@ -12,6 +11,8 @@ interface WalletClient {
12
11
  connect(): Promise<string>;
13
12
  getAccount(): Promise<string | null>;
14
13
  getNetwork(): Promise<string>;
14
+ /** Ask the wallet to switch the active account (user-confirmed); resolves to the new address. */
15
+ switchAccount(target?: string): Promise<string>;
15
16
  signTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>;
16
17
  /** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */
17
18
  signAndSubmit(request: SignTransactionRequest, options: {
@@ -36,6 +37,5 @@ interface WalletClient {
36
37
  * inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.
37
38
  */
38
39
  declare function createInjectedWalletClient(providerOverride?: AmadeusProvider): WalletClient;
39
- //#endregion
40
40
  export { ApiKeyStore, WalletClient, createInjectedWalletClient };
41
41
  //# sourceMappingURL=injected.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"injected.d.ts","names":[],"sources":["../../src/client/injected.ts"],"mappings":";;;UAyBiB;EAChB;EACA,IAAI;;UAiBY;EAChB;EACA,eAAe;;EAEf,WAAW;EACX,cAAc;EACd,cAAc;EACd,gBAAgB,SAAS,yBAAyB,QAAQ;;EAE1D,cACC,SAAS,wBACT;IAAW;IAAiB;MAC1B;IAAU;IAAgB;;;EAE7B,aAAa;IACZ;IACA;IACA,QAAQ;IACR;MACG;EACJ,GAAG,UAAU,sBACZ,OAAO,GACP,KAAK,MAAM,uBAAuB;EAEnC,IAAI,UAAU,sBACb,OAAO,GACP,KAAK,MAAM,uBAAuB;;;;;;iBAQpB,2BAA2B,mBAAmB,kBAAkB"}
1
+ {"version":3,"file":"injected.d.ts","names":[],"sources":["../../src/client/injected.ts"],"mappings":";;UAyBiB;EAChB;EACA,IAAI;;UAiBY;EAChB;EACA,eAAe;;EAEf,WAAW;EACX,cAAc;EACd,cAAc;;EAEd,cAAc,kBAAkB;EAChC,gBAAgB,SAAS,yBAAyB,QAAQ;;EAE1D,cACC,SAAS,wBACT;IAAW;IAAiB;MAC1B;IAAU;IAAgB;;;EAE7B,aAAa;IACZ;IACA;IACA,QAAQ;IACR;MACG;EACJ,GAAG,UAAU,sBACZ,OAAO,GACP,KAAK,MAAM,uBAAuB;EAEnC,IAAI,UAAU,sBACb,OAAO,GACP,KAAK,MAAM,uBAAuB;;;;;;iBAQpB,2BAA2B,mBAAmB,kBAAkB"}
@@ -2,7 +2,7 @@ import { WalletSdkError } from "../errors.js";
2
2
  import { submitTransaction } from "../tx.js";
3
3
  import { getAmadeusProvider } from "../types.js";
4
4
  import { decodeApiKey } from "../crypto/apikey.js";
5
- //#region src/client/injected.ts
5
+ // src/client/injected.ts
6
6
  /**
7
7
  * A framework-agnostic dApp client over the injected `window.amadeus` provider
8
8
  * (the browser extension). It wraps the raw provider with the ergonomics every
@@ -52,6 +52,11 @@ function createInjectedWalletClient(providerOverride) {
52
52
  },
53
53
  getAccount: () => requireProvider().getAccount(),
54
54
  getNetwork: () => requireProvider().getNetwork(),
55
+ switchAccount: async (target) => {
56
+ const provider = requireProvider();
57
+ if (typeof provider.requestSwitchAccount !== "function") throw new WalletSdkError("UNSUPPORTED", "wallet does not support switchAccount");
58
+ return provider.requestSwitchAccount(target);
59
+ },
55
60
  signTransaction: (request) => requireProvider().signTransaction(request),
56
61
  signAndSubmit: async (request, options) => {
57
62
  const { txHash, txPacked } = await requireProvider().signTransaction(request);
@@ -81,7 +86,6 @@ function createInjectedWalletClient(providerOverride) {
81
86
  off: (event, cb) => requireProvider().off(event, cb)
82
87
  };
83
88
  }
84
- //#endregion
85
89
  export { createInjectedWalletClient };
86
90
 
87
91
  //# sourceMappingURL=injected.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"injected.js","names":[],"sources":["../../src/client/injected.ts"],"sourcesContent":["/**\n * A framework-agnostic dApp client over the injected `window.amadeus` provider\n * (the browser extension). It wraps the raw provider with the ergonomics every\n * dApp currently hand-rolls: a single-account `connect`, sign-and-submit, and a\n * cached `ensureApiKey` that decodes expiry via the audited api-key module\n * (replacing the copies in hub / prime-hub).\n *\n * The mobile deep-link/QR path uses the transport module (connect handshake +\n * sealed envelopes) instead of an injected provider; this client is the\n * same-device, extension-present case.\n */\n\nimport { decodeApiKey } from '../crypto/apikey'\nimport { WalletSdkError } from '../errors'\nimport { submitTransaction } from '../tx'\nimport type {\n\tAmadeusEventPayloadMap,\n\tAmadeusProvider,\n\tAmadeusProviderEvent,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\nimport { getAmadeusProvider } from '../types'\n\n/** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */\nexport interface ApiKeyStore {\n\tget(): string | null\n\tset(apiKey: string): void\n}\n\nfunction memoryApiKeyStore(): ApiKeyStore {\n\tlet value: string | null = null\n\treturn { get: () => value, set: (apiKey) => (value = apiKey) }\n}\n\nfunction isApiKeyValid(apiKey: string, leewaySeconds: number): boolean {\n\ttry {\n\t\tconst { payload } = decodeApiKey(apiKey)\n\t\treturn payload.exp > Math.floor(Date.now() / 1000) + leewaySeconds\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport interface WalletClient {\n\tisAvailable(): boolean\n\tgetProvider(): AmadeusProvider | null\n\t/** Prompt connection; resolves to the connected account (Base58 address). */\n\tconnect(): Promise<string>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\tsignTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>\n\t/** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */\n\tsignAndSubmit(\n\t\trequest: SignTransactionRequest,\n\t\toptions: { nodeUrl: string; wait?: boolean }\n\t): Promise<{ txHash: string; submitted: unknown }>\n\t/** Return a valid cached api-key, minting (and caching) a fresh one if needed. Coalesces concurrent calls. */\n\tensureApiKey(options: {\n\t\taud: string\n\t\texpIn: number\n\t\tstore?: ApiKeyStore\n\t\tleewaySeconds?: number\n\t}): Promise<string>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\n/**\n * Create a client bound to the injected provider. Pass `providerOverride` to\n * inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.\n */\nexport function createInjectedWalletClient(providerOverride?: AmadeusProvider): WalletClient {\n\tconst getProvider = () => providerOverride ?? getAmadeusProvider()\n\tconst requireProvider = (): AmadeusProvider => {\n\t\tconst provider = getProvider()\n\t\tif (!provider)\n\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'Amadeus wallet is not available')\n\t\treturn provider\n\t}\n\n\tconst defaultStore = memoryApiKeyStore()\n\tlet pendingApiKey: Promise<string> | null = null\n\n\treturn {\n\t\tisAvailable: () => getProvider() !== null,\n\t\tgetProvider,\n\t\tconnect: async () => {\n\t\t\tconst accounts = await requireProvider().requestAccounts()\n\t\t\tif (!accounts.length)\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'no account returned')\n\t\t\treturn accounts[0]\n\t\t},\n\t\tgetAccount: () => requireProvider().getAccount(),\n\t\tgetNetwork: () => requireProvider().getNetwork(),\n\t\tsignTransaction: (request) => requireProvider().signTransaction(request),\n\t\tsignAndSubmit: async (request, options) => {\n\t\t\tconst { txHash, txPacked } = await requireProvider().signTransaction(request)\n\t\t\tconst submitted = await submitTransaction(txPacked, {\n\t\t\t\tnodeUrl: options.nodeUrl,\n\t\t\t\twait: options.wait\n\t\t\t})\n\t\t\treturn { txHash, submitted }\n\t\t},\n\t\tensureApiKey: ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {\n\t\t\tconst cached = store.get()\n\t\t\tif (cached && isApiKeyValid(cached, leewaySeconds)) return Promise.resolve(cached)\n\t\t\tif (!pendingApiKey) {\n\t\t\t\tpendingApiKey = requireProvider()\n\t\t\t\t\t.generateApiKey({ aud, exp_in: expIn })\n\t\t\t\t\t.then(({ apiKey }) => {\n\t\t\t\t\t\tstore.set(apiKey)\n\t\t\t\t\t\treturn apiKey\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tpendingApiKey = null\n\t\t\t\t\t})\n\t\t\t}\n\t\t\treturn pendingApiKey\n\t\t},\n\t\ton: (event, cb) => requireProvider().on(event, cb),\n\t\toff: (event, cb) => requireProvider().off(event, cb)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8BA,SAAS,oBAAiC;CACzC,IAAI,QAAuB;CAC3B,OAAO;EAAE,WAAW;EAAO,MAAM,WAAY,QAAQ;CAAQ;AAC9D;AAEA,SAAS,cAAc,QAAgB,eAAgC;CACtE,IAAI;EACH,MAAM,EAAE,YAAY,aAAa,MAAM;EACvC,OAAO,QAAQ,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI;CACtD,QAAQ;EACP,OAAO;CACR;AACD;;;;;AAoCA,SAAgB,2BAA2B,kBAAkD;CAC5F,MAAM,oBAAoB,oBAAoB,mBAAmB;CACjE,MAAM,wBAAyC;EAC9C,MAAM,WAAW,YAAY;EAC7B,IAAI,CAAC,UACJ,MAAM,IAAI,eAAe,oBAAoB,iCAAiC;EAC/E,OAAO;CACR;CAEA,MAAM,eAAe,kBAAkB;CACvC,IAAI,gBAAwC;CAE5C,OAAO;EACN,mBAAmB,YAAY,MAAM;EACrC;EACA,SAAS,YAAY;GACpB,MAAM,WAAW,MAAM,gBAAgB,CAAC,CAAC,gBAAgB;GACzD,IAAI,CAAC,SAAS,QACb,MAAM,IAAI,eAAe,oBAAoB,qBAAqB;GACnE,OAAO,SAAS;EACjB;EACA,kBAAkB,gBAAgB,CAAC,CAAC,WAAW;EAC/C,kBAAkB,gBAAgB,CAAC,CAAC,WAAW;EAC/C,kBAAkB,YAAY,gBAAgB,CAAC,CAAC,gBAAgB,OAAO;EACvE,eAAe,OAAO,SAAS,YAAY;GAC1C,MAAM,EAAE,QAAQ,aAAa,MAAM,gBAAgB,CAAC,CAAC,gBAAgB,OAAO;GAK5E,OAAO;IAAE;IAAQ,WAAA,MAJO,kBAAkB,UAAU;KACnD,SAAS,QAAQ;KACjB,MAAM,QAAQ;IACf,CAAC;GAC0B;EAC5B;EACA,eAAe,EAAE,KAAK,OAAO,QAAQ,cAAc,gBAAgB,SAAS;GAC3E,MAAM,SAAS,MAAM,IAAI;GACzB,IAAI,UAAU,cAAc,QAAQ,aAAa,GAAG,OAAO,QAAQ,QAAQ,MAAM;GACjF,IAAI,CAAC,eACJ,gBAAgB,gBAAgB,CAAC,CAC/B,eAAe;IAAE;IAAK,QAAQ;GAAM,CAAC,CAAC,CACtC,MAAM,EAAE,aAAa;IACrB,MAAM,IAAI,MAAM;IAChB,OAAO;GACR,CAAC,CAAC,CACD,cAAc;IACd,gBAAgB;GACjB,CAAC;GAEH,OAAO;EACR;EACA,KAAK,OAAO,OAAO,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE;EACjD,MAAM,OAAO,OAAO,gBAAgB,CAAC,CAAC,IAAI,OAAO,EAAE;CACpD;AACD"}
1
+ {"version":3,"file":"injected.js","names":[],"sources":["../../src/client/injected.ts"],"sourcesContent":["/**\n * A framework-agnostic dApp client over the injected `window.amadeus` provider\n * (the browser extension). It wraps the raw provider with the ergonomics every\n * dApp currently hand-rolls: a single-account `connect`, sign-and-submit, and a\n * cached `ensureApiKey` that decodes expiry via the audited api-key module\n * (replacing the copies in hub / prime-hub).\n *\n * The mobile deep-link/QR path uses the transport module (connect handshake +\n * sealed envelopes) instead of an injected provider; this client is the\n * same-device, extension-present case.\n */\n\nimport { decodeApiKey } from '../crypto/apikey'\nimport { WalletSdkError } from '../errors'\nimport { submitTransaction } from '../tx'\nimport type {\n\tAmadeusEventPayloadMap,\n\tAmadeusProvider,\n\tAmadeusProviderEvent,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\nimport { getAmadeusProvider } from '../types'\n\n/** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */\nexport interface ApiKeyStore {\n\tget(): string | null\n\tset(apiKey: string): void\n}\n\nfunction memoryApiKeyStore(): ApiKeyStore {\n\tlet value: string | null = null\n\treturn { get: () => value, set: (apiKey) => (value = apiKey) }\n}\n\nfunction isApiKeyValid(apiKey: string, leewaySeconds: number): boolean {\n\ttry {\n\t\tconst { payload } = decodeApiKey(apiKey)\n\t\treturn payload.exp > Math.floor(Date.now() / 1000) + leewaySeconds\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport interface WalletClient {\n\tisAvailable(): boolean\n\tgetProvider(): AmadeusProvider | null\n\t/** Prompt connection; resolves to the connected account (Base58 address). */\n\tconnect(): Promise<string>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\t/** Ask the wallet to switch the active account (user-confirmed); resolves to the new address. */\n\tswitchAccount(target?: string): Promise<string>\n\tsignTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>\n\t/** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */\n\tsignAndSubmit(\n\t\trequest: SignTransactionRequest,\n\t\toptions: { nodeUrl: string; wait?: boolean }\n\t): Promise<{ txHash: string; submitted: unknown }>\n\t/** Return a valid cached api-key, minting (and caching) a fresh one if needed. Coalesces concurrent calls. */\n\tensureApiKey(options: {\n\t\taud: string\n\t\texpIn: number\n\t\tstore?: ApiKeyStore\n\t\tleewaySeconds?: number\n\t}): Promise<string>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcb: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\n/**\n * Create a client bound to the injected provider. Pass `providerOverride` to\n * inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.\n */\nexport function createInjectedWalletClient(providerOverride?: AmadeusProvider): WalletClient {\n\tconst getProvider = () => providerOverride ?? getAmadeusProvider()\n\tconst requireProvider = (): AmadeusProvider => {\n\t\tconst provider = getProvider()\n\t\tif (!provider)\n\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'Amadeus wallet is not available')\n\t\treturn provider\n\t}\n\n\tconst defaultStore = memoryApiKeyStore()\n\tlet pendingApiKey: Promise<string> | null = null\n\n\treturn {\n\t\tisAvailable: () => getProvider() !== null,\n\t\tgetProvider,\n\t\tconnect: async () => {\n\t\t\tconst accounts = await requireProvider().requestAccounts()\n\t\t\tif (!accounts.length)\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'no account returned')\n\t\t\treturn accounts[0]\n\t\t},\n\t\tgetAccount: () => requireProvider().getAccount(),\n\t\tgetNetwork: () => requireProvider().getNetwork(),\n\t\tswitchAccount: async (target) => {\n\t\t\tconst provider = requireProvider()\n\t\t\tif (typeof provider.requestSwitchAccount !== 'function')\n\t\t\t\tthrow new WalletSdkError('UNSUPPORTED', 'wallet does not support switchAccount')\n\t\t\treturn provider.requestSwitchAccount(target)\n\t\t},\n\t\tsignTransaction: (request) => requireProvider().signTransaction(request),\n\t\tsignAndSubmit: async (request, options) => {\n\t\t\tconst { txHash, txPacked } = await requireProvider().signTransaction(request)\n\t\t\tconst submitted = await submitTransaction(txPacked, {\n\t\t\t\tnodeUrl: options.nodeUrl,\n\t\t\t\twait: options.wait\n\t\t\t})\n\t\t\treturn { txHash, submitted }\n\t\t},\n\t\tensureApiKey: ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {\n\t\t\tconst cached = store.get()\n\t\t\tif (cached && isApiKeyValid(cached, leewaySeconds)) return Promise.resolve(cached)\n\t\t\tif (!pendingApiKey) {\n\t\t\t\tpendingApiKey = requireProvider()\n\t\t\t\t\t.generateApiKey({ aud, exp_in: expIn })\n\t\t\t\t\t.then(({ apiKey }) => {\n\t\t\t\t\t\tstore.set(apiKey)\n\t\t\t\t\t\treturn apiKey\n\t\t\t\t\t})\n\t\t\t\t\t.finally(() => {\n\t\t\t\t\t\tpendingApiKey = null\n\t\t\t\t\t})\n\t\t\t}\n\t\t\treturn pendingApiKey\n\t\t},\n\t\ton: (event, cb) => requireProvider().on(event, cb),\n\t\toff: (event, cb) => requireProvider().off(event, cb)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA8BA,SAAS,oBAAiC;CACzC,IAAI,QAAuB;CAC3B,OAAO;EAAE,WAAW;EAAO,MAAM,WAAY,QAAQ;CAAQ;AAC9D;AAEA,SAAS,cAAc,QAAgB,eAAgC;CACtE,IAAI;EACH,MAAM,EAAE,YAAY,aAAa,MAAM;EACvC,OAAO,QAAQ,MAAM,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI;CACtD,QAAQ;EACP,OAAO;CACR;AACD;;;;;AAsCA,SAAgB,2BAA2B,kBAAkD;CAC5F,MAAM,oBAAoB,oBAAoB,mBAAmB;CACjE,MAAM,wBAAyC;EAC9C,MAAM,WAAW,YAAY;EAC7B,IAAI,CAAC,UACJ,MAAM,IAAI,eAAe,oBAAoB,iCAAiC;EAC/E,OAAO;CACR;CAEA,MAAM,eAAe,kBAAkB;CACvC,IAAI,gBAAwC;CAE5C,OAAO;EACN,mBAAmB,YAAY,MAAM;EACrC;EACA,SAAS,YAAY;GACpB,MAAM,WAAW,MAAM,gBAAgB,CAAC,CAAC,gBAAgB;GACzD,IAAI,CAAC,SAAS,QACb,MAAM,IAAI,eAAe,oBAAoB,qBAAqB;GACnE,OAAO,SAAS;EACjB;EACA,kBAAkB,gBAAgB,CAAC,CAAC,WAAW;EAC/C,kBAAkB,gBAAgB,CAAC,CAAC,WAAW;EAC/C,eAAe,OAAO,WAAW;GAChC,MAAM,WAAW,gBAAgB;GACjC,IAAI,OAAO,SAAS,yBAAyB,YAC5C,MAAM,IAAI,eAAe,eAAe,uCAAuC;GAChF,OAAO,SAAS,qBAAqB,MAAM;EAC5C;EACA,kBAAkB,YAAY,gBAAgB,CAAC,CAAC,gBAAgB,OAAO;EACvE,eAAe,OAAO,SAAS,YAAY;GAC1C,MAAM,EAAE,QAAQ,aAAa,MAAM,gBAAgB,CAAC,CAAC,gBAAgB,OAAO;GAK5E,OAAO;IAAE;IAAQ,WAAA,MAJO,kBAAkB,UAAU;KACnD,SAAS,QAAQ;KACjB,MAAM,QAAQ;IACf,CAAC;GAC0B;EAC5B;EACA,eAAe,EAAE,KAAK,OAAO,QAAQ,cAAc,gBAAgB,SAAS;GAC3E,MAAM,SAAS,MAAM,IAAI;GACzB,IAAI,UAAU,cAAc,QAAQ,aAAa,GAAG,OAAO,QAAQ,QAAQ,MAAM;GACjF,IAAI,CAAC,eACJ,gBAAgB,gBAAgB,CAAC,CAC/B,eAAe;IAAE;IAAK,QAAQ;GAAM,CAAC,CAAC,CACtC,MAAM,EAAE,aAAa;IACrB,MAAM,IAAI,MAAM;IAChB,OAAO;GACR,CAAC,CAAC,CACD,cAAc;IACd,gBAAgB;GACjB,CAAC;GAEH,OAAO;EACR;EACA,KAAK,OAAO,OAAO,gBAAgB,CAAC,CAAC,GAAG,OAAO,EAAE;EACjD,MAAM,OAAO,OAAO,gBAAgB,CAAC,CAAC,IAAI,OAAO,EAAE;CACpD;AACD"}
@@ -1,4 +1,3 @@
1
- //#region src/constants.d.ts
2
1
  /**
3
2
  * Protocol constants for the Amadeus dApp <-> wallet connection layer.
4
3
  *
@@ -85,6 +84,5 @@ declare const NETWORKS: readonly ["mainnet", "testnet", "custom"];
85
84
  * wallet rejects non-https bridge URLs via `assertAllowedBridgeUrl`).
86
85
  */
87
86
  declare const DEFAULT_BRIDGE_URL = "https://bridge.ama.one";
88
- //#endregion
89
87
  export { API_KEY_DST, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, DEFAULT_BRIDGE_URL, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, TX_DST, WALLET_INITIALIZED_EVENT, WALLET_WINDOW_EVENTS };
90
88
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;;cAaa;;;;;;;cAQA;;;;;;cAOA;;;;;;;;cASA;;cAGA;cACA;cACA;;;;;;;cAQA;;;;;;cAOA;;cAGA;cACA;cACA;;cAGA;;cAGA;;cAGA;;;;;;cAOA;;cAGA;;;;;;;;;cAUA;;cAUA;;;;;;cAOA"}
1
+ {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;cAaa;;;;;;;cAQA;;;;;;cAOA;;;;;;;;cASA;;cAGA;cACA;cACA;;;;;;;cAQA;;;;;;cAOA;;cAGA;cACA;cACA;;cAGA;;cAGA;;cAGA;;;;;;cAOA;;cAGA;;;;;;;;;cAUA;;cAUA;;;;;;cAOA"}
package/dist/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/constants.ts
1
+ // src/constants.ts
2
2
  /**
3
3
  * Protocol constants for the Amadeus dApp <-> wallet connection layer.
4
4
  *
@@ -96,7 +96,6 @@ const NETWORKS = [
96
96
  * wallet rejects non-https bridge URLs via `assertAllowedBridgeUrl`).
97
97
  */
98
98
  const DEFAULT_BRIDGE_URL = "https://bridge.ama.one";
99
- //#endregion
100
99
  export { API_KEY_DST, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, DEFAULT_BRIDGE_URL, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, TX_DST, WALLET_INITIALIZED_EVENT, WALLET_WINDOW_EVENTS };
101
100
 
102
101
  //# sourceMappingURL=constants.js.map
@@ -1,4 +1,3 @@
1
- //#region src/crypto/apikey.d.ts
2
1
  /**
3
2
  * BLS12-381 API-key bearer tokens — the ONE audited implementation, replacing
4
3
  * the byte-identical copies currently hand-rolled in the wallet extension
@@ -67,6 +66,5 @@ type VerifyApiKeyResult = {
67
66
  * result rather than throwing on the common "invalid" paths.
68
67
  */
69
68
  declare function verifyApiKey(apiKey: string, options?: VerifyApiKeyOptions): VerifyApiKeyResult;
70
- //#endregion
71
69
  export { ApiKeyPayload, DecodedApiKey, GenerateApiKeyParams, GenerateApiKeyResult, VerifyApiKeyOptions, VerifyApiKeyResult, decodeApiKey, generateApiKey, verifyApiKey };
72
70
  //# sourceMappingURL=apikey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apikey.d.ts","names":[],"sources":["../../src/crypto/apikey.ts"],"mappings":";;;;;;;;;;;;;;;;;UA6BiB;EAChB;EACA;;UAGgB;;EAEhB;;EAEA;;EAEA;;EAEA;;UAGgB;EAChB;EACA,SAAS;;iBAGM,eAAe,QAAQ,uBAAuB;UAqB7C;EAChB,SAAS;EACT,WAAW;EACX,WAAW;;EAEX,WAAW;;EAEX;;;iBAIe,aAAa,iBAAiB;UAmD7B;;EAEhB;;EAEA;;EAEA;;KAGW;EACP;EAAa,SAAS;EAAe;;EACrC;EAAc;;;;;;;iBAOH,aACf,gBACA,UAAS,sBACP"}
1
+ {"version":3,"file":"apikey.d.ts","names":[],"sources":["../../src/crypto/apikey.ts"],"mappings":";;;;;;;;;;;;;;;;UA6BiB;EAChB;EACA;;UAGgB;;EAEhB;;EAEA;;EAEA;;EAEA;;UAGgB;EAChB;EACA,SAAS;;iBAGM,eAAe,QAAQ,uBAAuB;UAqB7C;EAChB,SAAS;EACT,WAAW;EACX,WAAW;;EAEX,WAAW;;EAEX;;;iBAIe,aAAa,iBAAiB;UAmD7B;;EAEhB;;EAEA;;EAEA;;KAGW;EACP;EAAa,SAAS;EAAe;;EACrC;EAAc;;;;;;;iBAOH,aACf,gBACA,UAAS,sBACP"}
@@ -3,7 +3,7 @@ import { WalletSdkError } from "../errors.js";
3
3
  import { bytesToUtf8, concatBytes, utf8ToBytes } from "../bytes.js";
4
4
  import { deriveSigner, signHashed, verifyHashed } from "./bls.js";
5
5
  import { fromBase58, toBase58 } from "@amadeus-protocol/sdk";
6
- //#region src/crypto/apikey.ts
6
+ // src/crypto/apikey.ts
7
7
  /**
8
8
  * BLS12-381 API-key bearer tokens — the ONE audited implementation, replacing
9
9
  * the byte-identical copies currently hand-rolled in the wallet extension
@@ -106,7 +106,6 @@ function verifyApiKey(apiKey, options = {}) {
106
106
  address: decoded.address
107
107
  };
108
108
  }
109
- //#endregion
110
109
  export { decodeApiKey, generateApiKey, verifyApiKey };
111
110
 
112
111
  //# sourceMappingURL=apikey.js.map
@@ -1,4 +1,3 @@
1
- //#region src/crypto/bls.d.ts
2
1
  /**
3
2
  * Low-level BLS12-381 signing primitives, mirroring the exact recipe used by
4
3
  * `@amadeus-protocol/sdk` (`signing.ts`) and the wallet extension: hash the
@@ -26,6 +25,5 @@ declare function verifyHashed(signature: Uint8Array, payload: Uint8Array, public
26
25
  declare function publicKeyFromAddress(address: string): Uint8Array;
27
26
  /** Decode a Base58 signature into its 96 raw bytes, validating length. */
28
27
  declare function signatureFromBase58(signature: string): Uint8Array;
29
- //#endregion
30
28
  export { SignerKeys, deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed };
31
29
  //# sourceMappingURL=bls.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bls.d.ts","names":[],"sources":["../../src/crypto/bls.ts"],"mappings":";;;;;;;;;UAgBiB;;EAEhB,IAAI;;EAEJ,IAAI;;;iBAIW,aAAa,qBAAqB;;;;;iBAUlC,WAAW,SAAS,YAAY,IAAI,YAAY,cAAc;;iBAM9D,aACf,WAAW,YACX,SAAS,YACT,WAAW,YACX;;iBAWe,qBAAqB,kBAAkB;;iBAiBvC,oBAAoB,oBAAoB"}
1
+ {"version":3,"file":"bls.d.ts","names":[],"sources":["../../src/crypto/bls.ts"],"mappings":";;;;;;;;UAgBiB;;EAEhB,IAAI;;EAEJ,IAAI;;;iBAIW,aAAa,qBAAqB;;;;;iBAUlC,WAAW,SAAS,YAAY,IAAI,YAAY,cAAc;;iBAM9D,aACf,WAAW,YACX,SAAS,YACT,WAAW,YACX;;iBAWe,qBAAqB,kBAAkB;;iBAiBvC,oBAAoB,oBAAoB"}
@@ -3,7 +3,7 @@ import { WalletSdkError } from "../errors.js";
3
3
  import { deriveSkAndSeed64FromBase58Seed, fromBase58, getPublicKey } from "@amadeus-protocol/sdk";
4
4
  import { bls12_381 } from "@noble/curves/bls12-381";
5
5
  import { sha256 } from "@noble/hashes/sha2";
6
- //#region src/crypto/bls.ts
6
+ // src/crypto/bls.ts
7
7
  /**
8
8
  * Low-level BLS12-381 signing primitives, mirroring the exact recipe used by
9
9
  * `@amadeus-protocol/sdk` (`signing.ts`) and the wallet extension: hash the
@@ -59,7 +59,6 @@ function signatureFromBase58(signature) {
59
59
  if (sig.length !== 96) throw new WalletSdkError("INVALID_SIGNATURE", `signature must be 96 bytes, got ${sig.length}`);
60
60
  return sig;
61
61
  }
62
- //#endregion
63
62
  export { deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed };
64
63
 
65
64
  //# sourceMappingURL=bls.js.map
@@ -1,4 +1,3 @@
1
- //#region src/crypto/box.d.ts
2
1
  /**
3
2
  * End-to-end encrypted session channel for cross-device transports (QR / bridge).
4
3
  *
@@ -38,6 +37,5 @@ declare function seal(sharedKey: Uint8Array, plaintext: Uint8Array, aad?: Uint8A
38
37
  * i.e. it fails closed.
39
38
  */
40
39
  declare function open(sharedKey: Uint8Array, envelope: SealedEnvelope, aad?: Uint8Array): Uint8Array;
41
- //#endregion
42
40
  export { SealedEnvelope, SessionKeypair, deriveSharedKey, generateSessionKeypair, open, seal };
43
41
  //# sourceMappingURL=box.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"box.d.ts","names":[],"sources":["../../src/crypto/box.ts"],"mappings":";;;;;;;;;;;;;UA0BiB;;EAEhB;;EAEA,WAAW;;;iBAII,0BAA0B;;;;;iBAU1B,gBAAgB,8BAA8B,aAAa,aAAa;UAyBvE;;EAEhB;;EAEA;;;iBAIe,KACf,WAAW,YACX,WAAW,YACX,MAAM,aACJ;;;;;;iBAWa,KACf,WAAW,YACX,UAAU,gBACV,MAAM,aACJ"}
1
+ {"version":3,"file":"box.d.ts","names":[],"sources":["../../src/crypto/box.ts"],"mappings":";;;;;;;;;;;;UA0BiB;;EAEhB;;EAEA,WAAW;;;iBAII,0BAA0B;;;;;iBAU1B,gBAAgB,8BAA8B,aAAa,aAAa;UAyBvE;;EAEhB;;EAEA;;;iBAIe,KACf,WAAW,YACX,WAAW,YACX,MAAM,aACJ;;;;;;iBAWa,KACf,WAAW,YACX,UAAU,gBACV,MAAM,aACJ"}
@@ -5,7 +5,7 @@ import { fromBase58, toBase58 } from "@amadeus-protocol/sdk";
5
5
  import { sha256 } from "@noble/hashes/sha2";
6
6
  import { xchacha20poly1305 } from "@noble/ciphers/chacha.js";
7
7
  import { x25519 } from "@noble/curves/ed25519";
8
- //#region src/crypto/box.ts
8
+ // src/crypto/box.ts
9
9
  /**
10
10
  * End-to-end encrypted session channel for cross-device transports (QR / bridge).
11
11
  *
@@ -77,7 +77,6 @@ function open(sharedKey, envelope, aad) {
77
77
  throw new WalletSdkError("DECRYPT_FAILED", "authentication failed (wrong key or tampered)");
78
78
  }
79
79
  }
80
- //#endregion
81
80
  export { deriveSharedKey, generateSessionKeypair, open, seal };
82
81
 
83
82
  //# sourceMappingURL=box.js.map
@@ -1,4 +1,3 @@
1
- //#region src/crypto/connect.d.ts
2
1
  /**
3
2
  * Connection-auth signatures. When a dApp asks the wallet to connect, it must
4
3
  * prove control of its address. The wallet signs a TRANSCRIPT that binds the
@@ -54,6 +53,5 @@ interface VerifyConnectParams {
54
53
  * Never throws — returns false on any malformed input or verification failure.
55
54
  */
56
55
  declare function verifyConnect(params: VerifyConnectParams): boolean;
57
- //#endregion
58
56
  export { ConnectTranscript, SignConnectParams, VerifyConnectParams, buildConnectTranscript, signConnect, verifyConnect };
59
57
  //# sourceMappingURL=connect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connect.d.ts","names":[],"sources":["../../src/crypto/connect.ts"],"mappings":";;;;;;;;;;;;;;;;UA4BiB;;EAEhB;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;iBAWe,uBAAuB,YAAY,oBAAoB;UAiBtD;;EAEhB;EACA,YAAY;;;iBAIG,YAAY,QAAQ;UAMnB;;EAEhB;EACA,YAAY;;EAEZ;;;;;;iBAOe,cAAc,QAAQ"}
1
+ {"version":3,"file":"connect.d.ts","names":[],"sources":["../../src/crypto/connect.ts"],"mappings":";;;;;;;;;;;;;;;UA4BiB;;EAEhB;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;;;iBAWe,uBAAuB,YAAY,oBAAoB;UAiBtD;;EAEhB;EACA,YAAY;;;iBAIG,YAAY,QAAQ;UAMnB;;EAEhB;EACA,YAAY;;EAEZ;;;;;;iBAOe,cAAc,QAAQ"}
@@ -2,7 +2,7 @@ import { CONNECT_DST, CONNECT_TRANSCRIPT_LABEL } from "../constants.js";
2
2
  import { concatBytes, u32be, utf8ToBytes } from "../bytes.js";
3
3
  import { deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed } from "./bls.js";
4
4
  import { toBase58 } from "@amadeus-protocol/sdk";
5
- //#region src/crypto/connect.ts
5
+ // src/crypto/connect.ts
6
6
  /**
7
7
  * Connection-auth signatures. When a dApp asks the wallet to connect, it must
8
8
  * prove control of its address. The wallet signs a TRANSCRIPT that binds the
@@ -67,7 +67,6 @@ function verifyConnect(params) {
67
67
  }
68
68
  return verifyHashed(signature, buildConnectTranscript(params.transcript), publicKey, CONNECT_DST);
69
69
  }
70
- //#endregion
71
70
  export { buildConnectTranscript, signConnect, verifyConnect };
72
71
 
73
72
  //# sourceMappingURL=connect.js.map
@@ -1,4 +1,3 @@
1
- //#region src/crypto/message.d.ts
2
1
  /**
3
2
  * Arbitrary-message signing ("personal sign") — the wallet proves control of an
4
3
  * account over a human-readable string (a login challenge, a terms acceptance, a
@@ -42,6 +41,5 @@ interface VerifyMessageParams {
42
41
  * input (bad Base58, wrong length, over-long message) returns `false`.
43
42
  */
44
43
  declare function verifyMessage(params: VerifyMessageParams): boolean;
45
- //#endregion
46
44
  export { SignMessageParams, SignMessageResult, VerifyMessageParams, signMessage, verifyMessage };
47
45
  //# sourceMappingURL=message.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.ts","names":[],"sources":["../../src/crypto/message.ts"],"mappings":";;;;;;;;;;;;;;;UAsBiB;;EAEhB;;EAEA;;UAGgB;;EAEhB;;EAEA;;EAEA;;;iBAiBe,YAAY,QAAQ,oBAAoB;UAOvC;;EAEhB;;EAEA;;EAEA;;;;;;iBAOe,cAAc,QAAQ"}
1
+ {"version":3,"file":"message.d.ts","names":[],"sources":["../../src/crypto/message.ts"],"mappings":";;;;;;;;;;;;;;UAsBiB;;EAEhB;;EAEA;;UAGgB;;EAEhB;;EAEA;;EAEA;;;iBAiBe,YAAY,QAAQ,oBAAoB;UAOvC;;EAEhB;;EAEA;;EAEA;;;;;;iBAOe,cAAc,QAAQ"}
@@ -3,7 +3,7 @@ import { WalletSdkError } from "../errors.js";
3
3
  import { utf8ToBytes } from "../bytes.js";
4
4
  import { deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed } from "./bls.js";
5
5
  import { toBase58 } from "@amadeus-protocol/sdk";
6
- //#region src/crypto/message.ts
6
+ // src/crypto/message.ts
7
7
  /**
8
8
  * Arbitrary-message signing ("personal sign") — the wallet proves control of an
9
9
  * account over a human-readable string (a login challenge, a terms acceptance, a
@@ -48,7 +48,6 @@ function verifyMessage(params) {
48
48
  return false;
49
49
  }
50
50
  }
51
- //#endregion
52
51
  export { signMessage, verifyMessage };
53
52
 
54
53
  //# sourceMappingURL=message.js.map
package/dist/errors.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- //#region src/errors.d.ts
2
1
  /** Stable error codes so callers can branch without string-matching messages. */
3
- type WalletSdkErrorCode = 'INVALID_API_KEY' | 'BAD_SIGNATURE' | 'EXPIRED' | 'AUD_MISMATCH' | 'INVALID_ADDRESS' | 'INVALID_SIGNATURE' | 'INVALID_ARGUMENT' | 'SUBMIT_FAILED' | 'DECRYPT_FAILED';
2
+ type WalletSdkErrorCode = 'INVALID_API_KEY' | 'BAD_SIGNATURE' | 'EXPIRED' | 'AUD_MISMATCH' | 'INVALID_ADDRESS' | 'INVALID_SIGNATURE' | 'INVALID_ARGUMENT' | 'SUBMIT_FAILED' | 'DECRYPT_FAILED' | 'UNSUPPORTED';
4
3
  declare class WalletSdkError extends Error {
5
4
  readonly code: WalletSdkErrorCode;
6
5
  constructor(code: WalletSdkErrorCode, message: string);
7
6
  }
8
- //#endregion
9
7
  export { WalletSdkError, WalletSdkErrorCode };
10
8
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;KACY;cAWC,uBAAuB;WAC1B,MAAM;EAEH,YAAA,MAAM,oBAAoB"}
1
+ {"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";KACY;cAYC,uBAAuB;WAC1B,MAAM;EAEH,YAAA,MAAM,oBAAoB"}
package/dist/errors.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/errors.ts
1
+ // src/errors.ts
2
2
  var WalletSdkError = class WalletSdkError extends Error {
3
3
  code;
4
4
  constructor(code, message) {
@@ -8,7 +8,6 @@ var WalletSdkError = class WalletSdkError extends Error {
8
8
  Object.setPrototypeOf(this, WalletSdkError.prototype);
9
9
  }
10
10
  };
11
- //#endregion
12
11
  export { WalletSdkError };
13
12
 
14
13
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Stable error codes so callers can branch without string-matching messages. */\nexport type WalletSdkErrorCode =\n\t| 'INVALID_API_KEY'\n\t| 'BAD_SIGNATURE'\n\t| 'EXPIRED'\n\t| 'AUD_MISMATCH'\n\t| 'INVALID_ADDRESS'\n\t| 'INVALID_SIGNATURE'\n\t| 'INVALID_ARGUMENT'\n\t| 'SUBMIT_FAILED'\n\t| 'DECRYPT_FAILED'\n\nexport class WalletSdkError extends Error {\n\treadonly code: WalletSdkErrorCode\n\n\tconstructor(code: WalletSdkErrorCode, message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'WalletSdkError'\n\t\tthis.code = code\n\t\t// Restore prototype chain for instanceof across transpile targets.\n\t\tObject.setPrototypeOf(this, WalletSdkError.prototype)\n\t}\n}\n"],"mappings":";AAYA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CACzC;CAEA,YAAY,MAA0B,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EAEZ,OAAO,eAAe,MAAM,eAAe,SAAS;CACrD;AACD"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["/** Stable error codes so callers can branch without string-matching messages. */\nexport type WalletSdkErrorCode =\n\t| 'INVALID_API_KEY'\n\t| 'BAD_SIGNATURE'\n\t| 'EXPIRED'\n\t| 'AUD_MISMATCH'\n\t| 'INVALID_ADDRESS'\n\t| 'INVALID_SIGNATURE'\n\t| 'INVALID_ARGUMENT'\n\t| 'SUBMIT_FAILED'\n\t| 'DECRYPT_FAILED'\n\t| 'UNSUPPORTED'\n\nexport class WalletSdkError extends Error {\n\treadonly code: WalletSdkErrorCode\n\n\tconstructor(code: WalletSdkErrorCode, message: string) {\n\t\tsuper(message)\n\t\tthis.name = 'WalletSdkError'\n\t\tthis.code = code\n\t\t// Restore prototype chain for instanceof across transpile targets.\n\t\tObject.setPrototypeOf(this, WalletSdkError.prototype)\n\t}\n}\n"],"mappings":";AAaA,IAAa,iBAAb,MAAa,uBAAuB,MAAM;CACzC;CAEA,YAAY,MAA0B,SAAiB;EACtD,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EAEZ,OAAO,eAAe,MAAM,eAAe,SAAS;CACrD;AACD"}
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { bytesToUtf8, concatBytes, equalBytes, randomBytes, randomId, u32be, utf
4
4
  import { BYTES_TAG, TaggedBytes, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes } from "./binary.js";
5
5
  import { SignTransactionParams, SignedTransaction, SubmitTransactionOptions, signTransaction, submitTransaction } from "./tx.js";
6
6
  import { AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, GenerateApiKeyRequest, GenerateApiKeyResponse, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable } from "./types.js";
7
- import { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema } from "./schema.js";
7
+ import { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, SwitchAccountRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema } from "./schema.js";
8
8
  import { SignerKeys, deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed } from "./crypto/bls.js";
9
9
  import { ApiKeyPayload, DecodedApiKey, GenerateApiKeyParams, GenerateApiKeyResult, VerifyApiKeyOptions, VerifyApiKeyResult, decodeApiKey, generateApiKey, verifyApiKey } from "./crypto/apikey.js";
10
10
  import { SignMessageParams, SignMessageResult, VerifyMessageParams, signMessage, verifyMessage } from "./crypto/message.js";
@@ -16,4 +16,4 @@ import { EstablishedSession, PendingConnect, WalletSession, approveConnect, comp
16
16
  import { BridgeClient, BridgeClientOptions, BridgeFrame, assertAllowedBridgeUrl, deriveBridgeChannels, deriveConnectChannel } from "./transport/bridge.js";
17
17
  import { WalletHandlerContext, handleRequest } from "./wallet/handler.js";
18
18
  import { ApiKeyStore, WalletClient, createInjectedWalletClient } from "./client/injected.js";
19
- export { API_KEY_DST, AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, ApiKeyPayload, ApiKeyStore, BYTES_TAG, BridgeClient, BridgeClientOptions, BridgeFrame, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, ConnectRequestParams, ConnectResponseParams, ConnectTranscript, ConnectTranscriptInput, DEFAULT_BRIDGE_URL, DecodedApiKey, EstablishedSession, GenerateApiKeyParams, GenerateApiKeyRequest, GenerateApiKeyRequestInput, GenerateApiKeyResponse, GenerateApiKeyResult, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, PendingConnect, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, SealedEnvelope, SeenStore, SessionKeypair, SignConnectParams, SignMessageParams, SignMessageRequestInput, SignMessageResult, SignTransactionParams, SignTransactionRequest, SignTransactionRequestInput, SignTransactionResponse, SignedTransaction, SignerKeys, SubmitTransactionOptions, TX_DST, TaggedBytes, URI_SCHEME, VerifyApiKeyOptions, VerifyApiKeyResult, VerifyConnectParams, VerifyMessageParams, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletClient, WalletHandlerContext, WalletMethod, WalletRequest, WalletResponse, WalletSdkError, WalletSdkErrorCode, WalletSession, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
19
+ export { API_KEY_DST, AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, ApiKeyPayload, ApiKeyStore, BYTES_TAG, BridgeClient, BridgeClientOptions, BridgeFrame, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, ConnectRequestParams, ConnectResponseParams, ConnectTranscript, ConnectTranscriptInput, DEFAULT_BRIDGE_URL, DecodedApiKey, EstablishedSession, GenerateApiKeyParams, GenerateApiKeyRequest, GenerateApiKeyRequestInput, GenerateApiKeyResponse, GenerateApiKeyResult, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, PendingConnect, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, SealedEnvelope, SeenStore, SessionKeypair, SignConnectParams, SignMessageParams, SignMessageRequestInput, SignMessageResult, SignTransactionParams, SignTransactionRequest, SignTransactionRequestInput, SignTransactionResponse, SignedTransaction, SignerKeys, SubmitTransactionOptions, SwitchAccountRequestInput, TX_DST, TaggedBytes, URI_SCHEME, VerifyApiKeyOptions, VerifyApiKeyResult, VerifyConnectParams, VerifyMessageParams, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletClient, WalletHandlerContext, WalletMethod, WalletRequest, WalletResponse, WalletSdkError, WalletSdkErrorCode, WalletSession, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, switchAccountRequestSchema, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { bytesToUtf8, concatBytes, equalBytes, randomBytes, randomId, u32be, utf
4
4
  import { BYTES_TAG, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes } from "./binary.js";
5
5
  import { signTransaction, submitTransaction } from "./tx.js";
6
6
  import { getAmadeusProvider, isProviderAvailable } from "./types.js";
7
- import { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema } from "./schema.js";
7
+ import { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema } from "./schema.js";
8
8
  import { deriveSigner, publicKeyFromAddress, signHashed, signatureFromBase58, verifyHashed } from "./crypto/bls.js";
9
9
  import { decodeApiKey, generateApiKey, verifyApiKey } from "./crypto/apikey.js";
10
10
  import { signMessage, verifyMessage } from "./crypto/message.js";
@@ -16,4 +16,4 @@ import { approveConnect, completeConnect, createConnectRequest, isConnectRequest
16
16
  import { BridgeClient, assertAllowedBridgeUrl, deriveBridgeChannels, deriveConnectChannel } from "./transport/bridge.js";
17
17
  import { handleRequest } from "./wallet/handler.js";
18
18
  import { createInjectedWalletClient } from "./client/injected.js";
19
- export { API_KEY_DST, BYTES_TAG, BridgeClient, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, DEFAULT_BRIDGE_URL, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, TX_DST, URI_SCHEME, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletSdkError, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
19
+ export { API_KEY_DST, BYTES_TAG, BridgeClient, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, DEFAULT_BRIDGE_URL, MAX_API_KEY_STRING_LENGTH, MAX_MESSAGE_LENGTH, MESSAGE_DST, NETWORKS, PROTOCOL_VERSION, PROVIDER_EVENTS, PROVIDER_GLOBAL, PUBLIC_KEY_BYTE_LENGTH, SEED_BYTE_LENGTH, SESSION_NONCE_BYTE_LENGTH, SESSION_PUBLIC_KEY_BYTE_LENGTH, SESSION_SECRET_KEY_BYTE_LENGTH, SIGNATURE_BYTE_LENGTH, TX_DST, URI_SCHEME, WALLET_INITIALIZED_EVENT, WALLET_METHODS, WALLET_WINDOW_EVENTS, WalletSdkError, addressSchema, approveConnect, assertAllowedBridgeUrl, buildConnectResponseUri, buildConnectTranscript, buildConnectUri, bytesToUtf8, completeConnect, concatBytes, connectTranscriptSchema, createConnectRequest, createInjectedWalletClient, createMemorySeenStore, decodeApiKey, decodeBinaryValues, deriveBridgeChannels, deriveConnectChannel, deriveSharedKey, deriveSigner, describeBinaryValues, encodeBinaryValues, equalBytes, generateApiKey, generateApiKeyRequestSchema, generateSessionKeypair, getAmadeusProvider, guardRequest, handleRequest, isConnectRequestExpired, isProviderAvailable, isTaggedBytes, makeRequest, networkSchema, open, openRequest, openResponse, originSchema, parseConnectResponseUri, parseConnectUri, publicKeyFromAddress, randomBytes, randomId, seal, sealRequest, sealResponse, sessionPublicKeySchema, signConnect, signHashed, signMessage, signMessageRequestSchema, signTransaction, signTransactionRequestSchema, signatureFromBase58, submitTransaction, switchAccountRequestSchema, u32be, utf8ToBytes, verifyApiKey, verifyConnect, verifyHashed, verifyMessage };
@@ -1,6 +1,5 @@
1
1
  import { SignTransactionRequest, SignTransactionResponse } from "../types.js";
2
2
  import { WalletClient } from "../client/injected.js";
3
- //#region src/react/index.d.ts
4
3
  type WalletStatus = 'unavailable' | 'disconnected' | 'connecting' | 'connected';
5
4
  interface UseWalletResult {
6
5
  client: WalletClient;
@@ -10,11 +9,12 @@ interface UseWalletResult {
10
9
  isAvailable: boolean;
11
10
  connect: () => Promise<void>;
12
11
  disconnect: () => void;
12
+ /** Switch the active account (user-confirmed in the wallet); `account` reflects the change via the provider's accountsChanged event. */
13
+ switchAccount: (target?: string) => Promise<string>;
13
14
  signTransaction: (request: SignTransactionRequest) => Promise<SignTransactionResponse>;
14
15
  signAndSubmit: WalletClient['signAndSubmit'];
15
16
  ensureApiKey: WalletClient['ensureApiKey'];
16
17
  }
17
18
  declare function useWallet(): UseWalletResult;
18
- //#endregion
19
19
  export { UseWalletResult, WalletStatus, useWallet };
20
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/index.ts"],"mappings":";;;KAoBY;UAEK;EAChB,QAAQ;EACR,QAAQ;EACR;EACA;EACA;EACA,eAAe;EACf;EACA,kBAAkB,SAAS,2BAA2B,QAAQ;EAC9D,eAAe;EACf,cAAc;;iBAGC,aAAa"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/react/index.ts"],"mappings":";;KAoBY;UAEK;EAChB,QAAQ;EACR,QAAQ;EACR;EACA;EACA;EACA,eAAe;EACf;;EAEA,gBAAgB,oBAAoB;EACpC,kBAAkB,SAAS,2BAA2B,QAAQ;EAC9D,eAAe;EACf,cAAc;;iBAGC,aAAa"}
@@ -1,7 +1,7 @@
1
1
  import { WALLET_INITIALIZED_EVENT } from "../constants.js";
2
2
  import { createInjectedWalletClient } from "../client/injected.js";
3
3
  import { useCallback, useEffect, useMemo, useState } from "react";
4
- //#region src/react/index.ts
4
+ // src/react/index.ts
5
5
  /**
6
6
  * React ergonomics for dApps: a single `useWallet()` hook over the injected
7
7
  * provider client. It fixes the `amadeus#initialized` vs `amadeus-wallet#initialized`
@@ -84,12 +84,12 @@ function useWallet() {
84
84
  isAvailable: client.isAvailable(),
85
85
  connect,
86
86
  disconnect,
87
+ switchAccount: client.switchAccount,
87
88
  signTransaction: client.signTransaction,
88
89
  signAndSubmit: client.signAndSubmit,
89
90
  ensureApiKey: client.ensureApiKey
90
91
  };
91
92
  }
92
- //#endregion
93
93
  export { useWallet };
94
94
 
95
95
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/react/index.ts"],"sourcesContent":["/**\n * React ergonomics for dApps: a single `useWallet()` hook over the injected\n * provider client. It fixes the `amadeus#initialized` vs `amadeus-wallet#initialized`\n * detection bug once (dApps historically listened for the wrong name) and wires\n * the provider's account/network/disconnect events into state.\n *\n * Imported from the `@amadeus-protocol/wallet-sdk/react` subpath so non-React\n * consumers (the mobile wallet, node verifiers) never pull in React.\n */\n\nimport { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { createInjectedWalletClient, type WalletClient } from '../client/injected'\nimport { WALLET_INITIALIZED_EVENT } from '../constants'\nimport type {\n\tAmadeusEventPayloadMap,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\n\nexport type WalletStatus = 'unavailable' | 'disconnected' | 'connecting' | 'connected'\n\nexport interface UseWalletResult {\n\tclient: WalletClient\n\tstatus: WalletStatus\n\taccount: string | null\n\tnetwork: string | null\n\tisAvailable: boolean\n\tconnect: () => Promise<void>\n\tdisconnect: () => void\n\tsignTransaction: (request: SignTransactionRequest) => Promise<SignTransactionResponse>\n\tsignAndSubmit: WalletClient['signAndSubmit']\n\tensureApiKey: WalletClient['ensureApiKey']\n}\n\nexport function useWallet(): UseWalletResult {\n\tconst client = useMemo(() => createInjectedWalletClient(), [])\n\tconst [status, setStatus] = useState<WalletStatus>(() =>\n\t\tclient.isAvailable() ? 'disconnected' : 'unavailable'\n\t)\n\tconst [account, setAccount] = useState<string | null>(null)\n\tconst [network, setNetwork] = useState<string | null>(null)\n\n\t// Detect a (possibly late-injected) provider, then read initial account/network.\n\tuseEffect(() => {\n\t\tif (typeof window === 'undefined') return\n\t\tconst onInit = () => {\n\t\t\tif (client.isAvailable()) setStatus((s) => (s === 'unavailable' ? 'disconnected' : s))\n\t\t}\n\t\twindow.addEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t\tif (client.isAvailable()) {\n\t\t\tclient\n\t\t\t\t.getAccount()\n\t\t\t\t.then((a) => {\n\t\t\t\t\tif (a) {\n\t\t\t\t\t\tsetAccount(a)\n\t\t\t\t\t\tsetStatus('connected')\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t\tclient\n\t\t\t\t.getNetwork()\n\t\t\t\t.then(setNetwork)\n\t\t\t\t.catch(() => {})\n\t\t}\n\t\treturn () => window.removeEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t}, [client])\n\n\t// Mirror provider events into state.\n\tuseEffect(() => {\n\t\tif (!client.isAvailable()) return\n\t\tconst applyAccounts = (accounts: string[]) => {\n\t\t\tconst next = accounts[0] ?? null\n\t\t\tsetAccount(next)\n\t\t\tsetStatus(next ? 'connected' : 'disconnected')\n\t\t}\n\t\tconst onAccountsChanged = (d: AmadeusEventPayloadMap['accountsChanged']) =>\n\t\t\tapplyAccounts(d.accounts)\n\t\tconst onConnect = (d: AmadeusEventPayloadMap['connect']) => {\n\t\t\tapplyAccounts(d.accounts)\n\t\t\tsetNetwork(d.network)\n\t\t}\n\t\tconst onDisconnect = () => {\n\t\t\tsetAccount(null)\n\t\t\tsetStatus('disconnected')\n\t\t}\n\t\tconst onNetworkChanged = (d: AmadeusEventPayloadMap['networkChanged']) =>\n\t\t\tsetNetwork(d.network)\n\n\t\tclient.on('accountsChanged', onAccountsChanged)\n\t\tclient.on('connect', onConnect)\n\t\tclient.on('disconnect', onDisconnect)\n\t\tclient.on('networkChanged', onNetworkChanged)\n\t\treturn () => {\n\t\t\tclient.off('accountsChanged', onAccountsChanged)\n\t\t\tclient.off('connect', onConnect)\n\t\t\tclient.off('disconnect', onDisconnect)\n\t\t\tclient.off('networkChanged', onNetworkChanged)\n\t\t}\n\t}, [client])\n\n\tconst connect = useCallback(async () => {\n\t\tsetStatus('connecting')\n\t\ttry {\n\t\t\tconst a = await client.connect()\n\t\t\tsetAccount(a)\n\t\t\tsetStatus('connected')\n\t\t} catch (error) {\n\t\t\tsetStatus(client.isAvailable() ? 'disconnected' : 'unavailable')\n\t\t\tthrow error\n\t\t}\n\t}, [client])\n\n\tconst disconnect = useCallback(() => {\n\t\tsetAccount(null)\n\t\tsetStatus('disconnected')\n\t}, [])\n\n\treturn {\n\t\tclient,\n\t\tstatus,\n\t\taccount,\n\t\tnetwork,\n\t\tisAvailable: client.isAvailable(),\n\t\tconnect,\n\t\tdisconnect,\n\t\tsignTransaction: client.signTransaction,\n\t\tsignAndSubmit: client.signAndSubmit,\n\t\tensureApiKey: client.ensureApiKey\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAgB,YAA6B;CAC5C,MAAM,SAAS,cAAc,2BAA2B,GAAG,CAAC,CAAC;CAC7D,MAAM,CAAC,QAAQ,aAAa,eAC3B,OAAO,YAAY,IAAI,iBAAiB,aACzC;CACA,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAC1D,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAG1D,gBAAgB;EACf,IAAI,OAAO,WAAW,aAAa;EACnC,MAAM,eAAe;GACpB,IAAI,OAAO,YAAY,GAAG,WAAW,MAAO,MAAM,gBAAgB,iBAAiB,CAAE;EACtF;EACA,OAAO,iBAAiB,0BAA0B,MAAM;EACxD,IAAI,OAAO,YAAY,GAAG;GACzB,OACE,WAAW,CAAC,CACZ,MAAM,MAAM;IACZ,IAAI,GAAG;KACN,WAAW,CAAC;KACZ,UAAU,WAAW;IACtB;GACD,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;GAChB,OACE,WAAW,CAAC,CACZ,KAAK,UAAU,CAAC,CAChB,YAAY,CAAC,CAAC;EACjB;EACA,aAAa,OAAO,oBAAoB,0BAA0B,MAAM;CACzE,GAAG,CAAC,MAAM,CAAC;CAGX,gBAAgB;EACf,IAAI,CAAC,OAAO,YAAY,GAAG;EAC3B,MAAM,iBAAiB,aAAuB;GAC7C,MAAM,OAAO,SAAS,MAAM;GAC5B,WAAW,IAAI;GACf,UAAU,OAAO,cAAc,cAAc;EAC9C;EACA,MAAM,qBAAqB,MAC1B,cAAc,EAAE,QAAQ;EACzB,MAAM,aAAa,MAAyC;GAC3D,cAAc,EAAE,QAAQ;GACxB,WAAW,EAAE,OAAO;EACrB;EACA,MAAM,qBAAqB;GAC1B,WAAW,IAAI;GACf,UAAU,cAAc;EACzB;EACA,MAAM,oBAAoB,MACzB,WAAW,EAAE,OAAO;EAErB,OAAO,GAAG,mBAAmB,iBAAiB;EAC9C,OAAO,GAAG,WAAW,SAAS;EAC9B,OAAO,GAAG,cAAc,YAAY;EACpC,OAAO,GAAG,kBAAkB,gBAAgB;EAC5C,aAAa;GACZ,OAAO,IAAI,mBAAmB,iBAAiB;GAC/C,OAAO,IAAI,WAAW,SAAS;GAC/B,OAAO,IAAI,cAAc,YAAY;GACrC,OAAO,IAAI,kBAAkB,gBAAgB;EAC9C;CACD,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,UAAU,YAAY,YAAY;EACvC,UAAU,YAAY;EACtB,IAAI;GACH,MAAM,IAAI,MAAM,OAAO,QAAQ;GAC/B,WAAW,CAAC;GACZ,UAAU,WAAW;EACtB,SAAS,OAAO;GACf,UAAU,OAAO,YAAY,IAAI,iBAAiB,aAAa;GAC/D,MAAM;EACP;CACD,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,aAAa,kBAAkB;EACpC,WAAW,IAAI;EACf,UAAU,cAAc;CACzB,GAAG,CAAC,CAAC;CAEL,OAAO;EACN;EACA;EACA;EACA;EACA,aAAa,OAAO,YAAY;EAChC;EACA;EACA,iBAAiB,OAAO;EACxB,eAAe,OAAO;EACtB,cAAc,OAAO;CACtB;AACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/react/index.ts"],"sourcesContent":["/**\n * React ergonomics for dApps: a single `useWallet()` hook over the injected\n * provider client. It fixes the `amadeus#initialized` vs `amadeus-wallet#initialized`\n * detection bug once (dApps historically listened for the wrong name) and wires\n * the provider's account/network/disconnect events into state.\n *\n * Imported from the `@amadeus-protocol/wallet-sdk/react` subpath so non-React\n * consumers (the mobile wallet, node verifiers) never pull in React.\n */\n\nimport { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { createInjectedWalletClient, type WalletClient } from '../client/injected'\nimport { WALLET_INITIALIZED_EVENT } from '../constants'\nimport type {\n\tAmadeusEventPayloadMap,\n\tSignTransactionRequest,\n\tSignTransactionResponse\n} from '../types'\n\nexport type WalletStatus = 'unavailable' | 'disconnected' | 'connecting' | 'connected'\n\nexport interface UseWalletResult {\n\tclient: WalletClient\n\tstatus: WalletStatus\n\taccount: string | null\n\tnetwork: string | null\n\tisAvailable: boolean\n\tconnect: () => Promise<void>\n\tdisconnect: () => void\n\t/** Switch the active account (user-confirmed in the wallet); `account` reflects the change via the provider's accountsChanged event. */\n\tswitchAccount: (target?: string) => Promise<string>\n\tsignTransaction: (request: SignTransactionRequest) => Promise<SignTransactionResponse>\n\tsignAndSubmit: WalletClient['signAndSubmit']\n\tensureApiKey: WalletClient['ensureApiKey']\n}\n\nexport function useWallet(): UseWalletResult {\n\tconst client = useMemo(() => createInjectedWalletClient(), [])\n\tconst [status, setStatus] = useState<WalletStatus>(() =>\n\t\tclient.isAvailable() ? 'disconnected' : 'unavailable'\n\t)\n\tconst [account, setAccount] = useState<string | null>(null)\n\tconst [network, setNetwork] = useState<string | null>(null)\n\n\t// Detect a (possibly late-injected) provider, then read initial account/network.\n\tuseEffect(() => {\n\t\tif (typeof window === 'undefined') return\n\t\tconst onInit = () => {\n\t\t\tif (client.isAvailable()) setStatus((s) => (s === 'unavailable' ? 'disconnected' : s))\n\t\t}\n\t\twindow.addEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t\tif (client.isAvailable()) {\n\t\t\tclient\n\t\t\t\t.getAccount()\n\t\t\t\t.then((a) => {\n\t\t\t\t\tif (a) {\n\t\t\t\t\t\tsetAccount(a)\n\t\t\t\t\t\tsetStatus('connected')\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\t.catch(() => {})\n\t\t\tclient\n\t\t\t\t.getNetwork()\n\t\t\t\t.then(setNetwork)\n\t\t\t\t.catch(() => {})\n\t\t}\n\t\treturn () => window.removeEventListener(WALLET_INITIALIZED_EVENT, onInit)\n\t}, [client])\n\n\t// Mirror provider events into state.\n\tuseEffect(() => {\n\t\tif (!client.isAvailable()) return\n\t\tconst applyAccounts = (accounts: string[]) => {\n\t\t\tconst next = accounts[0] ?? null\n\t\t\tsetAccount(next)\n\t\t\tsetStatus(next ? 'connected' : 'disconnected')\n\t\t}\n\t\tconst onAccountsChanged = (d: AmadeusEventPayloadMap['accountsChanged']) =>\n\t\t\tapplyAccounts(d.accounts)\n\t\tconst onConnect = (d: AmadeusEventPayloadMap['connect']) => {\n\t\t\tapplyAccounts(d.accounts)\n\t\t\tsetNetwork(d.network)\n\t\t}\n\t\tconst onDisconnect = () => {\n\t\t\tsetAccount(null)\n\t\t\tsetStatus('disconnected')\n\t\t}\n\t\tconst onNetworkChanged = (d: AmadeusEventPayloadMap['networkChanged']) =>\n\t\t\tsetNetwork(d.network)\n\n\t\tclient.on('accountsChanged', onAccountsChanged)\n\t\tclient.on('connect', onConnect)\n\t\tclient.on('disconnect', onDisconnect)\n\t\tclient.on('networkChanged', onNetworkChanged)\n\t\treturn () => {\n\t\t\tclient.off('accountsChanged', onAccountsChanged)\n\t\t\tclient.off('connect', onConnect)\n\t\t\tclient.off('disconnect', onDisconnect)\n\t\t\tclient.off('networkChanged', onNetworkChanged)\n\t\t}\n\t}, [client])\n\n\tconst connect = useCallback(async () => {\n\t\tsetStatus('connecting')\n\t\ttry {\n\t\t\tconst a = await client.connect()\n\t\t\tsetAccount(a)\n\t\t\tsetStatus('connected')\n\t\t} catch (error) {\n\t\t\tsetStatus(client.isAvailable() ? 'disconnected' : 'unavailable')\n\t\t\tthrow error\n\t\t}\n\t}, [client])\n\n\tconst disconnect = useCallback(() => {\n\t\tsetAccount(null)\n\t\tsetStatus('disconnected')\n\t}, [])\n\n\treturn {\n\t\tclient,\n\t\tstatus,\n\t\taccount,\n\t\tnetwork,\n\t\tisAvailable: client.isAvailable(),\n\t\tconnect,\n\t\tdisconnect,\n\t\tswitchAccount: client.switchAccount,\n\t\tsignTransaction: client.signTransaction,\n\t\tsignAndSubmit: client.signAndSubmit,\n\t\tensureApiKey: client.ensureApiKey\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAqCA,SAAgB,YAA6B;CAC5C,MAAM,SAAS,cAAc,2BAA2B,GAAG,CAAC,CAAC;CAC7D,MAAM,CAAC,QAAQ,aAAa,eAC3B,OAAO,YAAY,IAAI,iBAAiB,aACzC;CACA,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAC1D,MAAM,CAAC,SAAS,cAAc,SAAwB,IAAI;CAG1D,gBAAgB;EACf,IAAI,OAAO,WAAW,aAAa;EACnC,MAAM,eAAe;GACpB,IAAI,OAAO,YAAY,GAAG,WAAW,MAAO,MAAM,gBAAgB,iBAAiB,CAAE;EACtF;EACA,OAAO,iBAAiB,0BAA0B,MAAM;EACxD,IAAI,OAAO,YAAY,GAAG;GACzB,OACE,WAAW,CAAC,CACZ,MAAM,MAAM;IACZ,IAAI,GAAG;KACN,WAAW,CAAC;KACZ,UAAU,WAAW;IACtB;GACD,CAAC,CAAC,CACD,YAAY,CAAC,CAAC;GAChB,OACE,WAAW,CAAC,CACZ,KAAK,UAAU,CAAC,CAChB,YAAY,CAAC,CAAC;EACjB;EACA,aAAa,OAAO,oBAAoB,0BAA0B,MAAM;CACzE,GAAG,CAAC,MAAM,CAAC;CAGX,gBAAgB;EACf,IAAI,CAAC,OAAO,YAAY,GAAG;EAC3B,MAAM,iBAAiB,aAAuB;GAC7C,MAAM,OAAO,SAAS,MAAM;GAC5B,WAAW,IAAI;GACf,UAAU,OAAO,cAAc,cAAc;EAC9C;EACA,MAAM,qBAAqB,MAC1B,cAAc,EAAE,QAAQ;EACzB,MAAM,aAAa,MAAyC;GAC3D,cAAc,EAAE,QAAQ;GACxB,WAAW,EAAE,OAAO;EACrB;EACA,MAAM,qBAAqB;GAC1B,WAAW,IAAI;GACf,UAAU,cAAc;EACzB;EACA,MAAM,oBAAoB,MACzB,WAAW,EAAE,OAAO;EAErB,OAAO,GAAG,mBAAmB,iBAAiB;EAC9C,OAAO,GAAG,WAAW,SAAS;EAC9B,OAAO,GAAG,cAAc,YAAY;EACpC,OAAO,GAAG,kBAAkB,gBAAgB;EAC5C,aAAa;GACZ,OAAO,IAAI,mBAAmB,iBAAiB;GAC/C,OAAO,IAAI,WAAW,SAAS;GAC/B,OAAO,IAAI,cAAc,YAAY;GACrC,OAAO,IAAI,kBAAkB,gBAAgB;EAC9C;CACD,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,UAAU,YAAY,YAAY;EACvC,UAAU,YAAY;EACtB,IAAI;GACH,MAAM,IAAI,MAAM,OAAO,QAAQ;GAC/B,WAAW,CAAC;GACZ,UAAU,WAAW;EACtB,SAAS,OAAO;GACf,UAAU,OAAO,YAAY,IAAI,iBAAiB,aAAa;GAC/D,MAAM;EACP;CACD,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,aAAa,kBAAkB;EACpC,WAAW,IAAI;EACf,UAAU,cAAc;CACzB,GAAG,CAAC,CAAC;CAEL,OAAO;EACN;EACA;EACA;EACA;EACA,aAAa,OAAO,YAAY;EAChC;EACA;EACA,eAAe,OAAO;EACtB,iBAAiB,OAAO;EACxB,eAAe,OAAO;EACtB,cAAc,OAAO;CACtB;AACD"}
package/dist/schema.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
- //#region src/schema.d.ts
3
2
  /** http(s) origin, matching the extension's `originSchema`. */
4
3
  declare const originSchema: z.ZodEffects<z.ZodString, string, string>;
5
4
  /** A Base58 string that decodes to a 48-byte Amadeus public key / address. */
@@ -43,6 +42,14 @@ declare const signMessageRequestSchema: z.ZodObject<{
43
42
  }, {
44
43
  message: string;
45
44
  }>;
45
+ /** `switchAccount` params — optional Base58 address hint; when absent the wallet shows its own account chooser. */
46
+ declare const switchAccountRequestSchema: z.ZodObject<{
47
+ account: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
48
+ }, "strip", z.ZodTypeAny, {
49
+ account?: string | undefined;
50
+ }, {
51
+ account?: string | undefined;
52
+ }>;
46
53
  /** The connect transcript fields carried by a deep link / QR payload. */
47
54
  declare const connectTranscriptSchema: z.ZodObject<{
48
55
  origin: z.ZodEffects<z.ZodString, string, string>;
@@ -66,7 +73,7 @@ declare const connectTranscriptSchema: z.ZodObject<{
66
73
  type SignTransactionRequestInput = z.infer<typeof signTransactionRequestSchema>;
67
74
  type GenerateApiKeyRequestInput = z.infer<typeof generateApiKeyRequestSchema>;
68
75
  type SignMessageRequestInput = z.infer<typeof signMessageRequestSchema>;
76
+ type SwitchAccountRequestInput = z.infer<typeof switchAccountRequestSchema>;
69
77
  type ConnectTranscriptInput = z.infer<typeof connectTranscriptSchema>;
70
- //#endregion
71
- export { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema };
78
+ export { ConnectTranscriptInput, GenerateApiKeyRequestInput, SignMessageRequestInput, SignTransactionRequestInput, SwitchAccountRequestInput, addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema };
72
79
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;cAiCa,cAAY,EAAA,WAAA,EAAA;;cAKZ,eAAa,EAAA,WAAA,EAAA;;cAGb,wBAAsB,EAAA,WAAA,EAAA;cAKtB,eAAa,EAAA;;cAGb,8BAA4B,EAAA;;;;;;;;;;;;;;;;;cAQ5B,6BAA2B,EAAA;;;;;;;;;;;cAM3B,0BAAwB,EAAA;;;;;;;;cAKxB,yBAAuB,EAAA;;;;;;;;;;;;;;;;;;;KAQxB,8BAA8B,EAAE,aAAa;KAC7C,6BAA6B,EAAE,aAAa;KAC5C,0BAA0B,EAAE,aAAa;KACzC,yBAAyB,EAAE,aAAa"}
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;cAiCa,cAAY,EAAA,WAAA,EAAA;;cAKZ,eAAa,EAAA,WAAA,EAAA;;cAGb,wBAAsB,EAAA,WAAA,EAAA;cAKtB,eAAa,EAAA;;cAGb,8BAA4B,EAAA;;;;;;;;;;;;;;;;;cAQ5B,6BAA2B,EAAA;;;;;;;;;;;cAM3B,0BAAwB,EAAA;;;;;;;;cAKxB,4BAA0B,EAAA;;;;;;;;cAK1B,yBAAuB,EAAA;;;;;;;;;;;;;;;;;;;KAQxB,8BAA8B,EAAE,aAAa;KAC7C,6BAA6B,EAAE,aAAa;KAC5C,0BAA0B,EAAE,aAAa;KACzC,4BAA4B,EAAE,aAAa;KAC3C,yBAAyB,EAAE,aAAa"}
package/dist/schema.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { MAX_MESSAGE_LENGTH, NETWORKS } from "./constants.js";
2
2
  import { fromBase58 } from "@amadeus-protocol/sdk";
3
3
  import { z } from "zod";
4
- //#region src/schema.ts
4
+ // src/schema.ts
5
5
  /**
6
6
  * Runtime validation for untrusted wire input (deep links, QR payloads, bridge
7
7
  * frames, cross-origin messages). Validate BEFORE any request is shown for
@@ -40,6 +40,8 @@ const generateApiKeyRequestSchema = z.object({
40
40
  });
41
41
  /** `signMessage` params — an arbitrary UTF-8 message, bounded for safety. */
42
42
  const signMessageRequestSchema = z.object({ message: z.string().min(1).max(MAX_MESSAGE_LENGTH) });
43
+ /** `switchAccount` params — optional Base58 address hint; when absent the wallet shows its own account chooser. */
44
+ const switchAccountRequestSchema = z.object({ account: addressSchema.optional() });
43
45
  /** The connect transcript fields carried by a deep link / QR payload. */
44
46
  const connectTranscriptSchema = z.object({
45
47
  origin: originSchema,
@@ -48,7 +50,6 @@ const connectTranscriptSchema = z.object({
48
50
  challenge: z.string().min(1),
49
51
  requestId: z.string().min(1)
50
52
  });
51
- //#endregion
52
- export { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema };
53
+ export { addressSchema, connectTranscriptSchema, generateApiKeyRequestSchema, networkSchema, originSchema, sessionPublicKeySchema, signMessageRequestSchema, signTransactionRequestSchema, switchAccountRequestSchema };
53
54
 
54
55
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/**\n * Runtime validation for untrusted wire input (deep links, QR payloads, bridge\n * frames, cross-origin messages). Validate BEFORE any request is shown for\n * approval or signed. Zod is used here because it is already the schema library\n * on the wallet + dApp side; the lower-level SDK uses `effect` internally, which\n * is intentionally not a dependency of this package.\n */\n\nimport { fromBase58 } from '@amadeus-protocol/sdk'\nimport { z } from 'zod'\n\nimport {\n\tMAX_MESSAGE_LENGTH,\n\tNETWORKS,\n\tPUBLIC_KEY_BYTE_LENGTH,\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH\n} from './constants'\n\n/** A Base58 string that decodes to exactly `length` bytes. */\nfunction base58OfLength(length: number, label: string) {\n\treturn z.string().refine(\n\t\t(v) => {\n\t\t\ttry {\n\t\t\t\treturn fromBase58(v).length === length\n\t\t\t} catch {\n\t\t\t\treturn false\n\t\t\t}\n\t\t},\n\t\t{ message: `${label} must decode to ${length} bytes` }\n\t)\n}\n\n/** http(s) origin, matching the extension's `originSchema`. */\nexport const originSchema = z\n\t.string()\n\t.refine((v) => /^https?:\\/\\//.test(v), { message: 'origin must be an http(s) URL' })\n\n/** A Base58 string that decodes to a 48-byte Amadeus public key / address. */\nexport const addressSchema = base58OfLength(PUBLIC_KEY_BYTE_LENGTH, 'address')\n\n/** A Base58 string that decodes to a 32-byte x25519 session public key. */\nexport const sessionPublicKeySchema = base58OfLength(\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH,\n\t'session public key'\n)\n\nexport const networkSchema = z.enum(NETWORKS)\n\n/** `signTransaction` params — mirrors `ExternalSignRequestMessageSchema`. */\nexport const signTransactionRequestSchema = z.object({\n\tcontract: z.string().min(1),\n\tmethod: z.string().min(1),\n\targs: z.array(z.unknown()),\n\tdescription: z.string().optional()\n})\n\n/** `generateApiKey` params — mirrors `ExternalApiKeyRequestMessageSchema`. */\nexport const generateApiKeyRequestSchema = z.object({\n\taud: z.string().min(1),\n\texp_in: z.number().int().positive()\n})\n\n/** `signMessage` params — an arbitrary UTF-8 message, bounded for safety. */\nexport const signMessageRequestSchema = z.object({\n\tmessage: z.string().min(1).max(MAX_MESSAGE_LENGTH)\n})\n\n/** The connect transcript fields carried by a deep link / QR payload. */\nexport const connectTranscriptSchema = z.object({\n\torigin: originSchema,\n\tdappPublicKey: sessionPublicKeySchema,\n\twalletPublicKey: sessionPublicKeySchema,\n\tchallenge: z.string().min(1),\n\trequestId: z.string().min(1)\n})\n\nexport type SignTransactionRequestInput = z.infer<typeof signTransactionRequestSchema>\nexport type GenerateApiKeyRequestInput = z.infer<typeof generateApiKeyRequestSchema>\nexport type SignMessageRequestInput = z.infer<typeof signMessageRequestSchema>\nexport type ConnectTranscriptInput = z.infer<typeof connectTranscriptSchema>\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,eAAe,QAAgB,OAAe;CACtD,OAAO,EAAE,OAAO,CAAC,CAAC,QAChB,MAAM;EACN,IAAI;GACH,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW;EACjC,QAAQ;GACP,OAAO;EACR;CACD,GACA,EAAE,SAAS,GAAG,MAAM,kBAAkB,OAAO,QAAQ,CACtD;AACD;;AAGA,MAAa,eAAe,EAC1B,OAAO,CAAC,CACR,QAAQ,MAAM,eAAe,KAAK,CAAC,GAAG,EAAE,SAAS,gCAAgC,CAAC;;AAGpF,MAAa,gBAAgB,eAAA,IAAuC,SAAS;;AAG7E,MAAa,yBAAyB,eAAA,IAErC,oBACD;AAEA,MAAa,gBAAgB,EAAE,KAAK,QAAQ;;AAG5C,MAAa,+BAA+B,EAAE,OAAO;CACpD,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC1B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;CACzB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AAClC,CAAC;;AAGD,MAAa,8BAA8B,EAAE,OAAO;CACnD,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACrB,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;AACnC,CAAC;;AAGD,MAAa,2BAA2B,EAAE,OAAO,EAChD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAClD,CAAC;;AAGD,MAAa,0BAA0B,EAAE,OAAO;CAC/C,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC5B,CAAC"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["/**\n * Runtime validation for untrusted wire input (deep links, QR payloads, bridge\n * frames, cross-origin messages). Validate BEFORE any request is shown for\n * approval or signed. Zod is used here because it is already the schema library\n * on the wallet + dApp side; the lower-level SDK uses `effect` internally, which\n * is intentionally not a dependency of this package.\n */\n\nimport { fromBase58 } from '@amadeus-protocol/sdk'\nimport { z } from 'zod'\n\nimport {\n\tMAX_MESSAGE_LENGTH,\n\tNETWORKS,\n\tPUBLIC_KEY_BYTE_LENGTH,\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH\n} from './constants'\n\n/** A Base58 string that decodes to exactly `length` bytes. */\nfunction base58OfLength(length: number, label: string) {\n\treturn z.string().refine(\n\t\t(v) => {\n\t\t\ttry {\n\t\t\t\treturn fromBase58(v).length === length\n\t\t\t} catch {\n\t\t\t\treturn false\n\t\t\t}\n\t\t},\n\t\t{ message: `${label} must decode to ${length} bytes` }\n\t)\n}\n\n/** http(s) origin, matching the extension's `originSchema`. */\nexport const originSchema = z\n\t.string()\n\t.refine((v) => /^https?:\\/\\//.test(v), { message: 'origin must be an http(s) URL' })\n\n/** A Base58 string that decodes to a 48-byte Amadeus public key / address. */\nexport const addressSchema = base58OfLength(PUBLIC_KEY_BYTE_LENGTH, 'address')\n\n/** A Base58 string that decodes to a 32-byte x25519 session public key. */\nexport const sessionPublicKeySchema = base58OfLength(\n\tSESSION_PUBLIC_KEY_BYTE_LENGTH,\n\t'session public key'\n)\n\nexport const networkSchema = z.enum(NETWORKS)\n\n/** `signTransaction` params — mirrors `ExternalSignRequestMessageSchema`. */\nexport const signTransactionRequestSchema = z.object({\n\tcontract: z.string().min(1),\n\tmethod: z.string().min(1),\n\targs: z.array(z.unknown()),\n\tdescription: z.string().optional()\n})\n\n/** `generateApiKey` params — mirrors `ExternalApiKeyRequestMessageSchema`. */\nexport const generateApiKeyRequestSchema = z.object({\n\taud: z.string().min(1),\n\texp_in: z.number().int().positive()\n})\n\n/** `signMessage` params — an arbitrary UTF-8 message, bounded for safety. */\nexport const signMessageRequestSchema = z.object({\n\tmessage: z.string().min(1).max(MAX_MESSAGE_LENGTH)\n})\n\n/** `switchAccount` params — optional Base58 address hint; when absent the wallet shows its own account chooser. */\nexport const switchAccountRequestSchema = z.object({\n\taccount: addressSchema.optional()\n})\n\n/** The connect transcript fields carried by a deep link / QR payload. */\nexport const connectTranscriptSchema = z.object({\n\torigin: originSchema,\n\tdappPublicKey: sessionPublicKeySchema,\n\twalletPublicKey: sessionPublicKeySchema,\n\tchallenge: z.string().min(1),\n\trequestId: z.string().min(1)\n})\n\nexport type SignTransactionRequestInput = z.infer<typeof signTransactionRequestSchema>\nexport type GenerateApiKeyRequestInput = z.infer<typeof generateApiKeyRequestSchema>\nexport type SignMessageRequestInput = z.infer<typeof signMessageRequestSchema>\nexport type SwitchAccountRequestInput = z.infer<typeof switchAccountRequestSchema>\nexport type ConnectTranscriptInput = z.infer<typeof connectTranscriptSchema>\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAS,eAAe,QAAgB,OAAe;CACtD,OAAO,EAAE,OAAO,CAAC,CAAC,QAChB,MAAM;EACN,IAAI;GACH,OAAO,WAAW,CAAC,CAAC,CAAC,WAAW;EACjC,QAAQ;GACP,OAAO;EACR;CACD,GACA,EAAE,SAAS,GAAG,MAAM,kBAAkB,OAAO,QAAQ,CACtD;AACD;;AAGA,MAAa,eAAe,EAC1B,OAAO,CAAC,CACR,QAAQ,MAAM,eAAe,KAAK,CAAC,GAAG,EAAE,SAAS,gCAAgC,CAAC;;AAGpF,MAAa,gBAAgB,eAAA,IAAuC,SAAS;;AAG7E,MAAa,yBAAyB,eAAA,IAErC,oBACD;AAEA,MAAa,gBAAgB,EAAE,KAAK,QAAQ;;AAG5C,MAAa,+BAA+B,EAAE,OAAO;CACpD,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC1B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;CACzB,aAAa,EAAE,OAAO,CAAC,CAAC,SAAS;AAClC,CAAC;;AAGD,MAAa,8BAA8B,EAAE,OAAO;CACnD,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACrB,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;AACnC,CAAC;;AAGD,MAAa,2BAA2B,EAAE,OAAO,EAChD,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,kBAAkB,EAClD,CAAC;;AAGD,MAAa,6BAA6B,EAAE,OAAO,EAClD,SAAS,cAAc,SAAS,EACjC,CAAC;;AAGD,MAAa,0BAA0B,EAAE,OAAO;CAC/C,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;AAC5B,CAAC"}
@@ -1,4 +1,3 @@
1
- //#region src/transport/bridge.d.ts
2
1
  /**
3
2
  * Client for the cross-device relay ("bridge"). After the connect handshake both
4
3
  * sides hold a shared key; from it they derive TWO SECRET channel ids (one per
@@ -77,6 +76,5 @@ declare class BridgeClient {
77
76
  */
78
77
  start(onFrame: (frame: BridgeFrame) => void | Promise<void>, onError?: (error: unknown) => void): () => void;
79
78
  }
80
- //#endregion
81
79
  export { BridgeClient, BridgeClientOptions, BridgeFrame, assertAllowedBridgeUrl, deriveBridgeChannels, deriveConnectChannel };
82
80
  //# sourceMappingURL=bridge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.ts","names":[],"sources":["../../src/transport/bridge.ts"],"mappings":";;;;;;;;;;;;;UAsBiB;;EAEhB;;EAEA;;EAEA;;;;;;;EAOA;;;;;;iBAOe,qBAAqB,WAAW;;EAE/C;;EAEA;;;;;;;;;iBAgBe,qBAAqB;;;;;;iBAarB,uBAAuB;UAetB;;EAEhB;;EAEA;;EAEA,mBAAmB;;EAEnB;;cAGY;mBACK;mBACA;mBACA;mBACA;EAEL,YAAA,SAAS;;EAaf,KAAK,YAAY,YAAY,mBAAmB;;;;;;;;EAmBtD,MACC,UAAU,OAAO,uBAAuB,eACxC,WAAW"}
1
+ {"version":3,"file":"bridge.d.ts","names":[],"sources":["../../src/transport/bridge.ts"],"mappings":";;;;;;;;;;;;UAsBiB;;EAEhB;;EAEA;;EAEA;;;;;;;EAOA;;;;;;iBAOe,qBAAqB,WAAW;;EAE/C;;EAEA;;;;;;;;;iBAgBe,qBAAqB;;;;;;iBAarB,uBAAuB;UAetB;;EAEhB;;EAEA;;EAEA,mBAAmB;;EAEnB;;cAGY;mBACK;mBACA;mBACA;mBACA;EAEL,YAAA,SAAS;;EAaf,KAAK,YAAY,YAAY,mBAAmB;;;;;;;;EAmBtD,MACC,UAAU,OAAO,uBAAuB,eACxC,WAAW"}
@@ -2,7 +2,7 @@ import { WalletSdkError } from "../errors.js";
2
2
  import { concatBytes, utf8ToBytes } from "../bytes.js";
3
3
  import { fromBase58, toBase58 } from "@amadeus-protocol/sdk";
4
4
  import { sha256 } from "@noble/hashes/sha2";
5
- //#region src/transport/bridge.ts
5
+ // src/transport/bridge.ts
6
6
  /**
7
7
  * Client for the cross-device relay ("bridge"). After the connect handshake both
8
8
  * sides hold a shared key; from it they derive TWO SECRET channel ids (one per
@@ -119,7 +119,6 @@ var BridgeClient = class {
119
119
  return () => controller.abort();
120
120
  }
121
121
  };
122
- //#endregion
123
122
  export { BridgeClient, assertAllowedBridgeUrl, deriveBridgeChannels, deriveConnectChannel };
124
123
 
125
124
  //# sourceMappingURL=bridge.js.map
@@ -1,6 +1,5 @@
1
1
  import { SealedEnvelope } from "../crypto/box.js";
2
- //#region src/transport/envelope.d.ts
3
- declare const WALLET_METHODS: readonly ["amadeus_signTransaction", "amadeus_signMessage", "amadeus_getAccounts", "amadeus_generateApiKey", "amadeus_switchNetwork"];
2
+ declare const WALLET_METHODS: readonly ["amadeus_signTransaction", "amadeus_signMessage", "amadeus_getAccounts", "amadeus_generateApiKey", "amadeus_switchNetwork", "amadeus_switchAccount"];
4
3
  type WalletMethod = (typeof WALLET_METHODS)[number];
5
4
  interface WalletRequest {
6
5
  /** Protocol version. */
@@ -75,6 +74,5 @@ declare function createMemorySeenStore(maxEntries?: number): SeenStore;
75
74
  * Throws `EXPIRED` or `INVALID_ARGUMENT` (duplicate).
76
75
  */
77
76
  declare function guardRequest(request: WalletRequest, store: SeenStore, now?: number): void;
78
- //#endregion
79
77
  export { SeenStore, WALLET_METHODS, WalletMethod, WalletRequest, WalletResponse, createMemorySeenStore, guardRequest, makeRequest, openRequest, openResponse, sealRequest, sealResponse };
80
78
  //# sourceMappingURL=envelope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.d.ts","names":[],"sources":["../../src/transport/envelope.ts"],"mappings":";;cAiBa;KAQD,uBAAuB;UAElB;;EAEhB;;EAEA;EACA,QAAQ;;EAER;EACA;;EAEA;;;;;;EAMA;;KAGW;EACP;EAAW;EAAY;EAAU;;EACjC;EAAW;EAAY;EAAW;IAAS;IAAc;;;;iBA4B9C,YAAY;EAC3B;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA;IACG;iBAaY,YAAY,WAAW,YAAY,SAAS,gBAAgB;;;;;;;iBAU5D,YAAY,WAAW,YAAY,UAAU,iBAAiB;iBAe9D,aAAa,WAAW,YAAY,UAAU,iBAAiB;;;;;iBAQ/D,aACf,WAAW,YACX,UAAU,gBACV,sBACE;;;;;;;UAyBc;EAChB,IAAI;EACJ,IAAI;;iBAGW,sBAAsB,sBAAsB;;;;;;iBAgB5C,aAAa,SAAS,eAAe,OAAO,WAAW"}
1
+ {"version":3,"file":"envelope.d.ts","names":[],"sources":["../../src/transport/envelope.ts"],"mappings":";cAiBa;KASD,uBAAuB;UAElB;;EAEhB;;EAEA;EACA,QAAQ;;EAER;EACA;;EAEA;;;;;;EAMA;;KAGW;EACP;EAAW;EAAY;EAAU;;EACjC;EAAW;EAAY;EAAW;IAAS;IAAc;;;;iBA4B9C,YAAY;EAC3B;EACA,QAAQ;EACR;EACA;EACA;EACA;EACA;IACG;iBAaY,YAAY,WAAW,YAAY,SAAS,gBAAgB;;;;;;;iBAU5D,YAAY,WAAW,YAAY,UAAU,iBAAiB;iBAe9D,aAAa,WAAW,YAAY,UAAU,iBAAiB;;;;;iBAQ/D,aACf,WAAW,YACX,UAAU,gBACV,sBACE;;;;;;;UAyBc;EAChB,IAAI;EACJ,IAAI;;iBAGW,sBAAsB,sBAAsB;;;;;;iBAgB5C,aAAa,SAAS,eAAe,OAAO,WAAW"}
@@ -3,7 +3,7 @@ import { WalletSdkError } from "../errors.js";
3
3
  import { bytesToUtf8, utf8ToBytes } from "../bytes.js";
4
4
  import { open, seal } from "../crypto/box.js";
5
5
  import { z } from "zod";
6
- //#region src/transport/envelope.ts
6
+ // src/transport/envelope.ts
7
7
  /**
8
8
  * The encrypted request/response envelope that flows over ANY transport (deep
9
9
  * link, QR, or the cross-device bridge). Post-connect, both sides hold the x25519
@@ -18,7 +18,8 @@ const WALLET_METHODS = [
18
18
  "amadeus_signMessage",
19
19
  "amadeus_getAccounts",
20
20
  "amadeus_generateApiKey",
21
- "amadeus_switchNetwork"
21
+ "amadeus_switchNetwork",
22
+ "amadeus_switchAccount"
22
23
  ];
23
24
  const walletRequestSchema = z.object({
24
25
  v: z.number().int(),
@@ -119,7 +120,6 @@ function guardRequest(request, store, now) {
119
120
  if (store.has(request.id)) throw new WalletSdkError("INVALID_ARGUMENT", "duplicate request id (replay)");
120
121
  store.add(request.id);
121
122
  }
122
- //#endregion
123
123
  export { WALLET_METHODS, createMemorySeenStore, guardRequest, makeRequest, openRequest, openResponse, sealRequest, sealResponse };
124
124
 
125
125
  //# sourceMappingURL=envelope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","names":[],"sources":["../../src/transport/envelope.ts"],"sourcesContent":["/**\n * The encrypted request/response envelope that flows over ANY transport (deep\n * link, QR, or the cross-device bridge). Post-connect, both sides hold the x25519\n * shared key, so every request and response is sealed — even same-device deep\n * links carry ciphertext, so a hijacked scheme yields an unusable blob.\n *\n * Methods mirror the wallet extension's provider vocabulary so a dApp integrates\n * once against the same names on every transport.\n */\n\nimport { z } from 'zod'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { bytesToUtf8, utf8ToBytes } from '../bytes'\nimport { open, seal, type SealedEnvelope } from '../crypto/box'\nimport { WalletSdkError } from '../errors'\n\nexport const WALLET_METHODS = [\n\t'amadeus_signTransaction',\n\t'amadeus_signMessage',\n\t'amadeus_getAccounts',\n\t'amadeus_generateApiKey',\n\t'amadeus_switchNetwork'\n] as const\n\nexport type WalletMethod = (typeof WALLET_METHODS)[number]\n\nexport interface WalletRequest {\n\t/** Protocol version. */\n\tv: number\n\t/** Unique, one-time request id (replay key). */\n\tid: string\n\tmethod: WalletMethod\n\t/** The dApp origin, echoed for display in the approval UI. */\n\torigin: string\n\tparams: unknown\n\t/** Unix-seconds expiry. */\n\texp: number\n\t/**\n\t * Optional Base58 address the dApp wants to act with. The wallet resolves the\n\t * matching account's seed to sign; absent → the session's bound account. Lets\n\t * a multi-account dApp choose which account signs without reconnecting.\n\t */\n\taccount?: string\n}\n\nexport type WalletResponse =\n\t| { v: number; id: string; ok: true; result: unknown }\n\t| { v: number; id: string; ok: false; error: { code: string; message: string } }\n\nconst walletRequestSchema = z.object({\n\tv: z.number().int(),\n\tid: z.string().min(1).max(128),\n\tmethod: z.enum(WALLET_METHODS),\n\torigin: z.string().min(1),\n\tparams: z.unknown(),\n\texp: z.number().int(),\n\taccount: z.string().min(1).max(128).optional()\n})\n\nconst walletResponseSchema = z.union([\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(true),\n\t\tresult: z.unknown()\n\t}),\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(false),\n\t\terror: z.object({ code: z.string(), message: z.string() })\n\t})\n])\n\n/** Build an unsealed request with the current protocol version and a TTL. */\nexport function makeRequest(params: {\n\tid: string\n\tmethod: WalletMethod\n\torigin: string\n\tparams: unknown\n\taccount?: string\n\tttlSeconds?: number\n\tnow?: number\n}): WalletRequest {\n\tconst nowSec = Math.floor((params.now ?? Date.now()) / 1000)\n\treturn {\n\t\tv: PROTOCOL_VERSION,\n\t\tid: params.id,\n\t\tmethod: params.method,\n\t\torigin: params.origin,\n\t\tparams: params.params,\n\t\texp: nowSec + (params.ttlSeconds ?? 120),\n\t\t...(params.account ? { account: params.account } : {})\n\t}\n}\n\nexport function sealRequest(sharedKey: Uint8Array, request: WalletRequest): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(request)))\n}\n\n/**\n * Decrypt + structurally validate an inbound request. Throws `DECRYPT_FAILED` if\n * the envelope is not authentic, `INVALID_ARGUMENT` if the plaintext is not a\n * well-formed request. Does NOT check expiry/replay — call `guardRequest` for\n * that policy step (kept separate so the crypto and the policy are distinct).\n */\nexport function openRequest(sharedKey: Uint8Array, envelope: SealedEnvelope): WalletRequest {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request is not valid JSON')\n\t}\n\tconst result = walletRequestSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request failed schema validation')\n\t}\n\treturn result.data as WalletRequest\n}\n\nexport function sealResponse(sharedKey: Uint8Array, response: WalletResponse): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(response)))\n}\n\n/**\n * Decrypt + validate an inbound response, optionally asserting it answers\n * `expectedId` (defends against a swapped/mismatched reply).\n */\nexport function openResponse(\n\tsharedKey: Uint8Array,\n\tenvelope: SealedEnvelope,\n\texpectedId?: string\n): WalletResponse {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response is not valid JSON')\n\t}\n\tconst result = walletResponseSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response failed schema validation')\n\t}\n\tconst response = result.data as WalletResponse\n\tif (expectedId !== undefined && response.id !== expectedId) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response id does not match the request')\n\t}\n\treturn response\n}\n\n/**\n * A one-time-id store for replay defense. The in-memory default is fine for a\n * single process; the mobile wallet should supply a PERSISTED implementation\n * (e.g. expo-secure-store) so a crash/relaunch inside the TTL window can't let a\n * captured approval replay. `has`+`add` must be atomic in the persisted impl.\n */\nexport interface SeenStore {\n\thas(id: string): boolean\n\tadd(id: string): void\n}\n\nexport function createMemorySeenStore(maxEntries = 10_000): SeenStore {\n\tconst ids = new Set<string>()\n\treturn {\n\t\thas: (id) => ids.has(id),\n\t\tadd: (id) => {\n\t\t\tif (ids.size >= maxEntries) ids.delete(ids.values().next().value as string)\n\t\t\tids.add(id)\n\t\t}\n\t}\n}\n\n/**\n * Policy gate: enforce expiry + one-time id BEFORE acting on a request (i.e.\n * before building/signing anything). Atomic check-and-add against `store`.\n * Throws `EXPIRED` or `INVALID_ARGUMENT` (duplicate).\n */\nexport function guardRequest(request: WalletRequest, store: SeenStore, now?: number): void {\n\tconst nowSec = Math.floor((now ?? Date.now()) / 1000)\n\tif (request.exp <= nowSec) {\n\t\tthrow new WalletSdkError('EXPIRED', 'request has expired')\n\t}\n\tif (store.has(request.id)) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'duplicate request id (replay)')\n\t}\n\tstore.add(request.id)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,iBAAiB;CAC7B;CACA;CACA;CACA;CACA;AACD;AA2BA,MAAM,sBAAsB,EAAE,OAAO;CACpC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,QAAQ,EAAE,KAAK,cAAc;CAC7B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,QAAQ,EAAE,QAAQ;CAClB,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI;CACpB,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;AAC9C,CAAC;AAED,MAAM,uBAAuB,EAAE,MAAM,CACpC,EAAE,OAAO;CACR,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,IAAI,EAAE,QAAQ,IAAI;CAClB,QAAQ,EAAE,QAAQ;AACnB,CAAC,GACD,EAAE,OAAO;CACR,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,IAAI,EAAE,QAAQ,KAAK;CACnB,OAAO,EAAE,OAAO;EAAE,MAAM,EAAE,OAAO;EAAG,SAAS,EAAE,OAAO;CAAE,CAAC;AAC1D,CAAC,CACF,CAAC;;AAGD,SAAgB,YAAY,QAQV;CACjB,MAAM,SAAS,KAAK,OAAO,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;CAC3D,OAAO;EACN,GAAA;EACA,IAAI,OAAO;EACX,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,KAAK,UAAU,OAAO,cAAc;EACpC,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;CACrD;AACD;AAEA,SAAgB,YAAY,WAAuB,SAAwC;CAC1F,OAAO,KAAK,WAAW,YAAY,KAAK,UAAU,OAAO,CAAC,CAAC;AAC5D;;;;;;;AAQA,SAAgB,YAAY,WAAuB,UAAyC;CAC3F,MAAM,QAAQ,KAAK,WAAW,QAAQ;CACtC,IAAI;CACJ,IAAI;EACH,SAAS,KAAK,MAAM,YAAY,KAAK,CAAC;CACvC,QAAQ;EACP,MAAM,IAAI,eAAe,oBAAoB,2BAA2B;CACzE;CACA,MAAM,SAAS,oBAAoB,UAAU,MAAM;CACnD,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,kCAAkC;CAEhF,OAAO,OAAO;AACf;AAEA,SAAgB,aAAa,WAAuB,UAA0C;CAC7F,OAAO,KAAK,WAAW,YAAY,KAAK,UAAU,QAAQ,CAAC,CAAC;AAC7D;;;;;AAMA,SAAgB,aACf,WACA,UACA,YACiB;CACjB,MAAM,QAAQ,KAAK,WAAW,QAAQ;CACtC,IAAI;CACJ,IAAI;EACH,SAAS,KAAK,MAAM,YAAY,KAAK,CAAC;CACvC,QAAQ;EACP,MAAM,IAAI,eAAe,oBAAoB,4BAA4B;CAC1E;CACA,MAAM,SAAS,qBAAqB,UAAU,MAAM;CACpD,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,mCAAmC;CAEjF,MAAM,WAAW,OAAO;CACxB,IAAI,eAAe,KAAA,KAAa,SAAS,OAAO,YAC/C,MAAM,IAAI,eAAe,oBAAoB,wCAAwC;CAEtF,OAAO;AACR;AAaA,SAAgB,sBAAsB,aAAa,KAAmB;CACrE,MAAM,sBAAM,IAAI,IAAY;CAC5B,OAAO;EACN,MAAM,OAAO,IAAI,IAAI,EAAE;EACvB,MAAM,OAAO;GACZ,IAAI,IAAI,QAAQ,YAAY,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAe;GAC1E,IAAI,IAAI,EAAE;EACX;CACD;AACD;;;;;;AAOA,SAAgB,aAAa,SAAwB,OAAkB,KAAoB;CAC1F,MAAM,SAAS,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;CACpD,IAAI,QAAQ,OAAO,QAClB,MAAM,IAAI,eAAe,WAAW,qBAAqB;CAE1D,IAAI,MAAM,IAAI,QAAQ,EAAE,GACvB,MAAM,IAAI,eAAe,oBAAoB,+BAA+B;CAE7E,MAAM,IAAI,QAAQ,EAAE;AACrB"}
1
+ {"version":3,"file":"envelope.js","names":[],"sources":["../../src/transport/envelope.ts"],"sourcesContent":["/**\n * The encrypted request/response envelope that flows over ANY transport (deep\n * link, QR, or the cross-device bridge). Post-connect, both sides hold the x25519\n * shared key, so every request and response is sealed — even same-device deep\n * links carry ciphertext, so a hijacked scheme yields an unusable blob.\n *\n * Methods mirror the wallet extension's provider vocabulary so a dApp integrates\n * once against the same names on every transport.\n */\n\nimport { z } from 'zod'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { bytesToUtf8, utf8ToBytes } from '../bytes'\nimport { open, seal, type SealedEnvelope } from '../crypto/box'\nimport { WalletSdkError } from '../errors'\n\nexport const WALLET_METHODS = [\n\t'amadeus_signTransaction',\n\t'amadeus_signMessage',\n\t'amadeus_getAccounts',\n\t'amadeus_generateApiKey',\n\t'amadeus_switchNetwork',\n\t'amadeus_switchAccount'\n] as const\n\nexport type WalletMethod = (typeof WALLET_METHODS)[number]\n\nexport interface WalletRequest {\n\t/** Protocol version. */\n\tv: number\n\t/** Unique, one-time request id (replay key). */\n\tid: string\n\tmethod: WalletMethod\n\t/** The dApp origin, echoed for display in the approval UI. */\n\torigin: string\n\tparams: unknown\n\t/** Unix-seconds expiry. */\n\texp: number\n\t/**\n\t * Optional Base58 address the dApp wants to act with. The wallet resolves the\n\t * matching account's seed to sign; absent → the session's bound account. Lets\n\t * a multi-account dApp choose which account signs without reconnecting.\n\t */\n\taccount?: string\n}\n\nexport type WalletResponse =\n\t| { v: number; id: string; ok: true; result: unknown }\n\t| { v: number; id: string; ok: false; error: { code: string; message: string } }\n\nconst walletRequestSchema = z.object({\n\tv: z.number().int(),\n\tid: z.string().min(1).max(128),\n\tmethod: z.enum(WALLET_METHODS),\n\torigin: z.string().min(1),\n\tparams: z.unknown(),\n\texp: z.number().int(),\n\taccount: z.string().min(1).max(128).optional()\n})\n\nconst walletResponseSchema = z.union([\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(true),\n\t\tresult: z.unknown()\n\t}),\n\tz.object({\n\t\tv: z.number().int(),\n\t\tid: z.string().min(1).max(128),\n\t\tok: z.literal(false),\n\t\terror: z.object({ code: z.string(), message: z.string() })\n\t})\n])\n\n/** Build an unsealed request with the current protocol version and a TTL. */\nexport function makeRequest(params: {\n\tid: string\n\tmethod: WalletMethod\n\torigin: string\n\tparams: unknown\n\taccount?: string\n\tttlSeconds?: number\n\tnow?: number\n}): WalletRequest {\n\tconst nowSec = Math.floor((params.now ?? Date.now()) / 1000)\n\treturn {\n\t\tv: PROTOCOL_VERSION,\n\t\tid: params.id,\n\t\tmethod: params.method,\n\t\torigin: params.origin,\n\t\tparams: params.params,\n\t\texp: nowSec + (params.ttlSeconds ?? 120),\n\t\t...(params.account ? { account: params.account } : {})\n\t}\n}\n\nexport function sealRequest(sharedKey: Uint8Array, request: WalletRequest): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(request)))\n}\n\n/**\n * Decrypt + structurally validate an inbound request. Throws `DECRYPT_FAILED` if\n * the envelope is not authentic, `INVALID_ARGUMENT` if the plaintext is not a\n * well-formed request. Does NOT check expiry/replay — call `guardRequest` for\n * that policy step (kept separate so the crypto and the policy are distinct).\n */\nexport function openRequest(sharedKey: Uint8Array, envelope: SealedEnvelope): WalletRequest {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request is not valid JSON')\n\t}\n\tconst result = walletRequestSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'request failed schema validation')\n\t}\n\treturn result.data as WalletRequest\n}\n\nexport function sealResponse(sharedKey: Uint8Array, response: WalletResponse): SealedEnvelope {\n\treturn seal(sharedKey, utf8ToBytes(JSON.stringify(response)))\n}\n\n/**\n * Decrypt + validate an inbound response, optionally asserting it answers\n * `expectedId` (defends against a swapped/mismatched reply).\n */\nexport function openResponse(\n\tsharedKey: Uint8Array,\n\tenvelope: SealedEnvelope,\n\texpectedId?: string\n): WalletResponse {\n\tconst bytes = open(sharedKey, envelope)\n\tlet parsed: unknown\n\ttry {\n\t\tparsed = JSON.parse(bytesToUtf8(bytes))\n\t} catch {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response is not valid JSON')\n\t}\n\tconst result = walletResponseSchema.safeParse(parsed)\n\tif (!result.success) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response failed schema validation')\n\t}\n\tconst response = result.data as WalletResponse\n\tif (expectedId !== undefined && response.id !== expectedId) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response id does not match the request')\n\t}\n\treturn response\n}\n\n/**\n * A one-time-id store for replay defense. The in-memory default is fine for a\n * single process; the mobile wallet should supply a PERSISTED implementation\n * (e.g. expo-secure-store) so a crash/relaunch inside the TTL window can't let a\n * captured approval replay. `has`+`add` must be atomic in the persisted impl.\n */\nexport interface SeenStore {\n\thas(id: string): boolean\n\tadd(id: string): void\n}\n\nexport function createMemorySeenStore(maxEntries = 10_000): SeenStore {\n\tconst ids = new Set<string>()\n\treturn {\n\t\thas: (id) => ids.has(id),\n\t\tadd: (id) => {\n\t\t\tif (ids.size >= maxEntries) ids.delete(ids.values().next().value as string)\n\t\t\tids.add(id)\n\t\t}\n\t}\n}\n\n/**\n * Policy gate: enforce expiry + one-time id BEFORE acting on a request (i.e.\n * before building/signing anything). Atomic check-and-add against `store`.\n * Throws `EXPIRED` or `INVALID_ARGUMENT` (duplicate).\n */\nexport function guardRequest(request: WalletRequest, store: SeenStore, now?: number): void {\n\tconst nowSec = Math.floor((now ?? Date.now()) / 1000)\n\tif (request.exp <= nowSec) {\n\t\tthrow new WalletSdkError('EXPIRED', 'request has expired')\n\t}\n\tif (store.has(request.id)) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'duplicate request id (replay)')\n\t}\n\tstore.add(request.id)\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,iBAAiB;CAC7B;CACA;CACA;CACA;CACA;CACA;AACD;AA2BA,MAAM,sBAAsB,EAAE,OAAO;CACpC,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,QAAQ,EAAE,KAAK,cAAc;CAC7B,QAAQ,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CACxB,QAAQ,EAAE,QAAQ;CAClB,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI;CACpB,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;AAC9C,CAAC;AAED,MAAM,uBAAuB,EAAE,MAAM,CACpC,EAAE,OAAO;CACR,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,IAAI,EAAE,QAAQ,IAAI;CAClB,QAAQ,EAAE,QAAQ;AACnB,CAAC,GACD,EAAE,OAAO;CACR,GAAG,EAAE,OAAO,CAAC,CAAC,IAAI;CAClB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC7B,IAAI,EAAE,QAAQ,KAAK;CACnB,OAAO,EAAE,OAAO;EAAE,MAAM,EAAE,OAAO;EAAG,SAAS,EAAE,OAAO;CAAE,CAAC;AAC1D,CAAC,CACF,CAAC;;AAGD,SAAgB,YAAY,QAQV;CACjB,MAAM,SAAS,KAAK,OAAO,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;CAC3D,OAAO;EACN,GAAA;EACA,IAAI,OAAO;EACX,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,QAAQ,OAAO;EACf,KAAK,UAAU,OAAO,cAAc;EACpC,GAAI,OAAO,UAAU,EAAE,SAAS,OAAO,QAAQ,IAAI,CAAC;CACrD;AACD;AAEA,SAAgB,YAAY,WAAuB,SAAwC;CAC1F,OAAO,KAAK,WAAW,YAAY,KAAK,UAAU,OAAO,CAAC,CAAC;AAC5D;;;;;;;AAQA,SAAgB,YAAY,WAAuB,UAAyC;CAC3F,MAAM,QAAQ,KAAK,WAAW,QAAQ;CACtC,IAAI;CACJ,IAAI;EACH,SAAS,KAAK,MAAM,YAAY,KAAK,CAAC;CACvC,QAAQ;EACP,MAAM,IAAI,eAAe,oBAAoB,2BAA2B;CACzE;CACA,MAAM,SAAS,oBAAoB,UAAU,MAAM;CACnD,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,kCAAkC;CAEhF,OAAO,OAAO;AACf;AAEA,SAAgB,aAAa,WAAuB,UAA0C;CAC7F,OAAO,KAAK,WAAW,YAAY,KAAK,UAAU,QAAQ,CAAC,CAAC;AAC7D;;;;;AAMA,SAAgB,aACf,WACA,UACA,YACiB;CACjB,MAAM,QAAQ,KAAK,WAAW,QAAQ;CACtC,IAAI;CACJ,IAAI;EACH,SAAS,KAAK,MAAM,YAAY,KAAK,CAAC;CACvC,QAAQ;EACP,MAAM,IAAI,eAAe,oBAAoB,4BAA4B;CAC1E;CACA,MAAM,SAAS,qBAAqB,UAAU,MAAM;CACpD,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,mCAAmC;CAEjF,MAAM,WAAW,OAAO;CACxB,IAAI,eAAe,KAAA,KAAa,SAAS,OAAO,YAC/C,MAAM,IAAI,eAAe,oBAAoB,wCAAwC;CAEtF,OAAO;AACR;AAaA,SAAgB,sBAAsB,aAAa,KAAmB;CACrE,MAAM,sBAAM,IAAI,IAAY;CAC5B,OAAO;EACN,MAAM,OAAO,IAAI,IAAI,EAAE;EACvB,MAAM,OAAO;GACZ,IAAI,IAAI,QAAQ,YAAY,IAAI,OAAO,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAe;GAC1E,IAAI,IAAI,EAAE;EACX;CACD;AACD;;;;;;AAOA,SAAgB,aAAa,SAAwB,OAAkB,KAAoB;CAC1F,MAAM,SAAS,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;CACpD,IAAI,QAAQ,OAAO,QAClB,MAAM,IAAI,eAAe,WAAW,qBAAqB;CAE1D,IAAI,MAAM,IAAI,QAAQ,EAAE,GACvB,MAAM,IAAI,eAAe,oBAAoB,+BAA+B;CAE7E,MAAM,IAAI,QAAQ,EAAE;AACrB"}
@@ -1,6 +1,5 @@
1
1
  import { SessionKeypair } from "../crypto/box.js";
2
2
  import { ConnectRequestParams, ConnectResponseParams } from "./uri.js";
3
- //#region src/transport/session.d.ts
4
3
  /** State the dApp keeps locally between issuing a connect request and completing it. */
5
4
  interface PendingConnect {
6
5
  requestId: string;
@@ -65,6 +64,5 @@ declare function approveConnect(request: ConnectRequestParams, options: {
65
64
  }): WalletSession;
66
65
  /** Whether a parsed connect request has expired (wallet should reject/re-park). */
67
66
  declare function isConnectRequestExpired(request: ConnectRequestParams, now?: number): boolean;
68
- //#endregion
69
67
  export { EstablishedSession, PendingConnect, WalletSession, approveConnect, completeConnect, createConnectRequest, isConnectRequestExpired };
70
68
  //# sourceMappingURL=session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","names":[],"sources":["../../src/transport/session.ts"],"mappings":";;;;UA6BiB;EAChB;EACA;EACA;;EAEA,aAAa;EACb;EACA;;UAGgB;;EAEhB;;EAEA,WAAW;;EAEX;;EAEA;EACA;;EAEA;;;iBAIe,qBAAqB;EACpC;EACA;EACA;EACA;EACA;;EACK;EAAa,SAAS;;;;;;;iBAoCZ,gBACf,SAAS,gBACT,UAAU,wBACR;UA4Bc;;EAEhB,UAAU;;EAEV,WAAW;;EAEX,eAAe;;EAEf;;EAEA;;;;;;;;iBASe,eACf,SAAS,sBACT;EAAW;EAAc;IACvB;;iBA4Ba,wBAAwB,SAAS,sBAAsB"}
1
+ {"version":3,"file":"session.d.ts","names":[],"sources":["../../src/transport/session.ts"],"mappings":";;;UA6BiB;EAChB;EACA;EACA;;EAEA,aAAa;EACb;EACA;;UAGgB;;EAEhB;;EAEA,WAAW;;EAEX;;EAEA;EACA;;EAEA;;;iBAIe,qBAAqB;EACpC;EACA;EACA;EACA;EACA;;EACK;EAAa,SAAS;;;;;;;iBAoCZ,gBACf,SAAS,gBACT,UAAU,wBACR;UA4Bc;;EAEhB,UAAU;;EAEV,WAAW;;EAEX,eAAe;;EAEf;;EAEA;;;;;;;;iBASe,eACf,SAAS,sBACT;EAAW;EAAc;IACvB;;iBA4Ba,wBAAwB,SAAS,sBAAsB"}
@@ -5,7 +5,7 @@ import { signConnect, verifyConnect } from "../crypto/connect.js";
5
5
  import { deriveSharedKey, generateSessionKeypair } from "../crypto/box.js";
6
6
  import { buildConnectUri } from "./uri.js";
7
7
  import { toBase58 } from "@amadeus-protocol/sdk";
8
- //#region src/transport/session.ts
8
+ // src/transport/session.ts
9
9
  /**
10
10
  * The connect handshake, orchestrated for both sides. This is where the crypto
11
11
  * primitives (connect transcript signing + x25519 box) and the URI transport
@@ -116,7 +116,6 @@ function approveConnect(request, options) {
116
116
  function isConnectRequestExpired(request, now) {
117
117
  return request.exp <= Math.floor((now ?? Date.now()) / 1e3);
118
118
  }
119
- //#endregion
120
119
  export { approveConnect, completeConnect, createConnectRequest, isConnectRequestExpired };
121
120
 
122
121
  //# sourceMappingURL=session.js.map
@@ -1,4 +1,3 @@
1
- //#region src/transport/uri.d.ts
2
1
  /**
3
2
  * Deep-link / QR URI construction and parsing for the connect handshake.
4
3
  *
@@ -44,6 +43,5 @@ declare function parseConnectUri(uri: string): ConnectRequestParams;
44
43
  declare function buildConnectResponseUri(redirectLink: string, response: ConnectResponseParams): string;
45
44
  /** Parse a connect response from a callback URL's query string. */
46
45
  declare function parseConnectResponseUri(uri: string): ConnectResponseParams;
47
- //#endregion
48
46
  export { ConnectRequestParams, ConnectResponseParams, URI_SCHEME, buildConnectResponseUri, buildConnectUri, parseConnectResponseUri, parseConnectUri };
49
47
  //# sourceMappingURL=uri.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"uri.d.ts","names":[],"sources":["../../src/transport/uri.ts"],"mappings":";;;;;;;;;;;;cAea;UAEI;EAChB;;EAEA;EACA;EACA;;EAEA;;EAEA;;EAEA;;UAGgB;EAChB;EACA;;EAEA;;EAEA;;;iBAsCe,gBAAgB,QAAQ;;iBAcxB,gBAAgB,cAAc;;;;;;iBA6B9B,wBACf,sBACA,UAAU;;iBAaK,wBAAwB,cAAc"}
1
+ {"version":3,"file":"uri.d.ts","names":[],"sources":["../../src/transport/uri.ts"],"mappings":";;;;;;;;;;;cAea;UAEI;EAChB;;EAEA;EACA;EACA;;EAEA;;EAEA;;EAEA;;UAGgB;EAChB;EACA;;EAEA;;EAEA;;;iBAsCe,gBAAgB,QAAQ;;iBAcxB,gBAAgB,cAAc;;;;;;iBA6B9B,wBACf,sBACA,UAAU;;iBAaK,wBAAwB,cAAc"}
@@ -1,6 +1,6 @@
1
1
  import "../constants.js";
2
2
  import { WalletSdkError } from "../errors.js";
3
- //#region src/transport/uri.ts
3
+ // src/transport/uri.ts
4
4
  /**
5
5
  * Deep-link / QR URI construction and parsing for the connect handshake.
6
6
  *
@@ -95,7 +95,6 @@ function parseConnectResponseUri(uri) {
95
95
  signature: q.sig
96
96
  };
97
97
  }
98
- //#endregion
99
98
  export { URI_SCHEME, buildConnectResponseUri, buildConnectUri, parseConnectResponseUri, parseConnectUri };
100
99
 
101
100
  //# sourceMappingURL=uri.js.map
package/dist/tx.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { NetworkType } from "@amadeus-protocol/sdk";
2
- //#region src/tx.d.ts
3
2
  interface SignTransactionParams {
4
3
  /** Base58 wallet seed (private key). */
5
4
  seed: string;
@@ -31,6 +30,5 @@ interface SubmitTransactionOptions {
31
30
  * dApps do today. Returns the parsed JSON body when possible, else raw text.
32
31
  */
33
32
  declare function submitTransaction(txPacked: number[] | Uint8Array, options: SubmitTransactionOptions): Promise<unknown>;
34
- //#endregion
35
33
  export { SignTransactionParams, SignedTransaction, SubmitTransactionOptions, signTransaction, submitTransaction };
36
34
  //# sourceMappingURL=tx.d.ts.map
package/dist/tx.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tx.d.ts","names":[],"sources":["../src/tx.ts"],"mappings":";;UAqBiB;;EAEhB;EACA;EACA;;EAEA;EACA;;EAEA,UAAU;;UAGM;;EAEhB;;EAEA;;iBAGe,gBAAgB,QAAQ,wBAAwB;UA0B/C;;EAEhB;;EAEA;;EAEA;;;;;;iBAOqB,kBACrB,qBAAqB,YACrB,SAAS,2BACP"}
1
+ {"version":3,"file":"tx.d.ts","names":[],"sources":["../src/tx.ts"],"mappings":";UAqBiB;;EAEhB;EACA;EACA;;EAEA;EACA;;EAEA,UAAU;;UAGM;;EAEhB;;EAEA;;iBAGe,gBAAgB,QAAQ,wBAAwB;UA0B/C;;EAEhB;;EAEA;;EAEA;;;;;;iBAOqB,kBACrB,qBAAqB,YACrB,SAAS,2BACP"}
package/dist/tx.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WalletSdkError } from "./errors.js";
2
2
  import { decodeBinaryValues } from "./binary.js";
3
3
  import { fromBase58, signContractCall } from "@amadeus-protocol/sdk";
4
- //#region src/tx.ts
4
+ // src/tx.ts
5
5
  /**
6
6
  * Transaction signing + submission.
7
7
  *
@@ -59,7 +59,6 @@ async function submitTransaction(txPacked, options) {
59
59
  clearTimeout(timer);
60
60
  }
61
61
  }
62
- //#endregion
63
62
  export { signTransaction, submitTransaction };
64
63
 
65
64
  //# sourceMappingURL=tx.js.map
package/dist/types.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { NETWORKS, PROVIDER_EVENTS } from "./constants.js";
2
- //#region src/types.d.ts
3
2
  type AmadeusNetwork = (typeof NETWORKS)[number];
4
3
  type AmadeusProviderEvent = (typeof PROVIDER_EVENTS)[number];
5
4
  interface SignTransactionRequest {
@@ -63,6 +62,14 @@ interface AmadeusProvider {
63
62
  getNetwork(): Promise<string>;
64
63
  requestAccounts(): Promise<string[]>;
65
64
  requestSwitchNetwork(network: string): Promise<string>;
65
+ /**
66
+ * Ask the wallet to make another of its accounts active. `target` is an optional
67
+ * Base58 address hint; the wallet always confirms with the user (and presents its
68
+ * own account chooser) before switching, so a dApp can never switch silently.
69
+ * Resolves to the new active account's Base58 address. Optional: wallets that
70
+ * predate it lack the method.
71
+ */
72
+ requestSwitchAccount?(target?: string): Promise<string>;
66
73
  signTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>;
67
74
  generateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>;
68
75
  on<E extends AmadeusProviderEvent>(event: E, callback: (data: AmadeusEventPayloadMap[E]) => void): void;
@@ -75,6 +82,5 @@ declare global {
75
82
  declare function getAmadeusProvider(): AmadeusProvider | null;
76
83
  /** Whether a genuine Amadeus provider is currently injected. */
77
84
  declare function isProviderAvailable(): boolean;
78
- //#endregion
79
85
  export { AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, GenerateApiKeyRequest, GenerateApiKeyResponse, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable };
80
86
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;KASY,yBAAyB;KAEzB,+BAA+B;UAE1B;EAChB;EACA;EAEA;EACA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;;UAIgB;EAChB;IAAmB;IAAoB;IAA4B;;EACnE;IAAW;IAAoB;IAAiB;;EAChD;IAAc;IAAiB;;EAC/B;IAAQ;IAAiB;;EACzB;IAAU;IAAoB;IAAiB;;EAC/C;IAAkB;IAAiB;IAAyB;;;;;;;UAO5C;WACP;EACT,eAAe;EACf,cAAc;EACd,cAAc;EACd,mBAAmB;EACnB,qBAAqB,kBAAkB;EACvC,gBAAgB,QAAQ,yBAAyB,QAAQ;EACzD,eAAe,QAAQ,wBAAwB,QAAQ;EACvD,GAAG,UAAU,sBACZ,OAAO,GACP,WAAW,MAAM,uBAAuB;EAEzC,IAAI,UAAU,sBACb,OAAO,GACP,WAAW,MAAM,uBAAuB;;QAIlC;MACH,SAAS;;;iBAIE,sBAAsB;;iBAMtB"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";KASY,yBAAyB;KAEzB,+BAA+B;UAE1B;EAChB;EACA;EAEA;EACA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;EAEA;;UAGgB;EAChB;;;UAIgB;EAChB;IAAmB;IAAoB;IAA4B;;EACnE;IAAW;IAAoB;IAAiB;;EAChD;IAAc;IAAiB;;EAC/B;IAAQ;IAAiB;;EACzB;IAAU;IAAoB;IAAiB;;EAC/C;IAAkB;IAAiB;IAAyB;;;;;;;UAO5C;WACP;EACT,eAAe;EACf,cAAc;EACd,cAAc;EACd,mBAAmB;EACnB,qBAAqB,kBAAkB;;;;;;;;EAQvC,sBAAsB,kBAAkB;EACxC,gBAAgB,QAAQ,yBAAyB,QAAQ;EACzD,eAAe,QAAQ,wBAAwB,QAAQ;EACvD,GAAG,UAAU,sBACZ,OAAO,GACP,WAAW,MAAM,uBAAuB;EAEzC,IAAI,UAAU,sBACb,OAAO,GACP,WAAW,MAAM,uBAAuB;;QAIlC;MACH,SAAS;;;iBAIE,sBAAsB;;iBAMtB"}
package/dist/types.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region src/types.ts
1
+ // src/types.ts
2
2
  /** Return the injected provider if present and genuine, else null. Browser-only. */
3
3
  function getAmadeusProvider() {
4
4
  const candidate = globalThis.amadeus;
@@ -8,7 +8,6 @@ function getAmadeusProvider() {
8
8
  function isProviderAvailable() {
9
9
  return getAmadeusProvider() !== null;
10
10
  }
11
- //#endregion
12
11
  export { getAmadeusProvider, isProviderAvailable };
13
12
 
14
13
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * The typed public contract every Amadeus dApp already depends on — the injected\n * `window.amadeus` provider — plus the request/response shapes and event names.\n * These mirror the wallet extension exactly; changing a name or shape breaks live\n * dApps, so treat this file as the compatibility surface.\n */\n\nimport { NETWORKS, PROVIDER_EVENTS } from './constants'\n\nexport type AmadeusNetwork = (typeof NETWORKS)[number]\n\nexport type AmadeusProviderEvent = (typeof PROVIDER_EVENTS)[number]\n\nexport interface SignTransactionRequest {\n\tcontract: string\n\tmethod: string\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\targs: any[]\n\tdescription?: string\n}\n\nexport interface SignTransactionResponse {\n\ttxHash: string\n\t/** Packed transaction bytes as a plain number[] (fed into `new Uint8Array(...)`). */\n\ttxPacked: number[]\n}\n\nexport interface GenerateApiKeyRequest {\n\taud: string\n\t/** Lifetime in seconds. */\n\texp_in: number\n}\n\nexport interface GenerateApiKeyResponse {\n\tapiKey: string\n}\n\n/** Event payloads emitted through the provider's `.on(name, cb)` channel. */\nexport interface AmadeusEventPayloadMap {\n\taccountsChanged: { accounts: string[]; previousAccounts: string[]; timestamp: number }\n\tconnect: { accounts: string[]; network: string; timestamp: number }\n\tdisconnect: { reason?: string; timestamp: number }\n\tlock: { reason?: string; timestamp: number }\n\tunlock: { accounts: string[]; network: string; timestamp: number }\n\tnetworkChanged: { network: string; previousNetwork: string; timestamp: number }\n}\n\n/**\n * The injected provider interface. This is the object a dApp reads off\n * `window.amadeus`. Do not rename methods — dApps call them directly.\n */\nexport interface AmadeusProvider {\n\treadonly isAmadeus: boolean\n\tisConnected(): Promise<boolean>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\trequestAccounts(): Promise<string[]>\n\trequestSwitchNetwork(network: string): Promise<string>\n\tsignTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>\n\tgenerateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\ndeclare global {\n\tvar amadeus: AmadeusProvider | undefined\n}\n\n/** Return the injected provider if present and genuine, else null. Browser-only. */\nexport function getAmadeusProvider(): AmadeusProvider | null {\n\tconst candidate = (globalThis as { amadeus?: AmadeusProvider }).amadeus\n\treturn candidate && candidate.isAmadeus === true ? candidate : null\n}\n\n/** Whether a genuine Amadeus provider is currently injected. */\nexport function isProviderAvailable(): boolean {\n\treturn getAmadeusProvider() !== null\n}\n"],"mappings":";;AA2EA,SAAgB,qBAA6C;CAC5D,MAAM,YAAa,WAA6C;CAChE,OAAO,aAAa,UAAU,cAAc,OAAO,YAAY;AAChE;;AAGA,SAAgB,sBAA+B;CAC9C,OAAO,mBAAmB,MAAM;AACjC"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * The typed public contract every Amadeus dApp already depends on — the injected\n * `window.amadeus` provider — plus the request/response shapes and event names.\n * These mirror the wallet extension exactly; changing a name or shape breaks live\n * dApps, so treat this file as the compatibility surface.\n */\n\nimport { NETWORKS, PROVIDER_EVENTS } from './constants'\n\nexport type AmadeusNetwork = (typeof NETWORKS)[number]\n\nexport type AmadeusProviderEvent = (typeof PROVIDER_EVENTS)[number]\n\nexport interface SignTransactionRequest {\n\tcontract: string\n\tmethod: string\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\targs: any[]\n\tdescription?: string\n}\n\nexport interface SignTransactionResponse {\n\ttxHash: string\n\t/** Packed transaction bytes as a plain number[] (fed into `new Uint8Array(...)`). */\n\ttxPacked: number[]\n}\n\nexport interface GenerateApiKeyRequest {\n\taud: string\n\t/** Lifetime in seconds. */\n\texp_in: number\n}\n\nexport interface GenerateApiKeyResponse {\n\tapiKey: string\n}\n\n/** Event payloads emitted through the provider's `.on(name, cb)` channel. */\nexport interface AmadeusEventPayloadMap {\n\taccountsChanged: { accounts: string[]; previousAccounts: string[]; timestamp: number }\n\tconnect: { accounts: string[]; network: string; timestamp: number }\n\tdisconnect: { reason?: string; timestamp: number }\n\tlock: { reason?: string; timestamp: number }\n\tunlock: { accounts: string[]; network: string; timestamp: number }\n\tnetworkChanged: { network: string; previousNetwork: string; timestamp: number }\n}\n\n/**\n * The injected provider interface. This is the object a dApp reads off\n * `window.amadeus`. Do not rename methods — dApps call them directly.\n */\nexport interface AmadeusProvider {\n\treadonly isAmadeus: boolean\n\tisConnected(): Promise<boolean>\n\tgetAccount(): Promise<string | null>\n\tgetNetwork(): Promise<string>\n\trequestAccounts(): Promise<string[]>\n\trequestSwitchNetwork(network: string): Promise<string>\n\t/**\n\t * Ask the wallet to make another of its accounts active. `target` is an optional\n\t * Base58 address hint; the wallet always confirms with the user (and presents its\n\t * own account chooser) before switching, so a dApp can never switch silently.\n\t * Resolves to the new active account's Base58 address. Optional: wallets that\n\t * predate it lack the method.\n\t */\n\trequestSwitchAccount?(target?: string): Promise<string>\n\tsignTransaction(params: SignTransactionRequest): Promise<SignTransactionResponse>\n\tgenerateApiKey(params: GenerateApiKeyRequest): Promise<GenerateApiKeyResponse>\n\ton<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n\toff<E extends AmadeusProviderEvent>(\n\t\tevent: E,\n\t\tcallback: (data: AmadeusEventPayloadMap[E]) => void\n\t): void\n}\n\ndeclare global {\n\tvar amadeus: AmadeusProvider | undefined\n}\n\n/** Return the injected provider if present and genuine, else null. Browser-only. */\nexport function getAmadeusProvider(): AmadeusProvider | null {\n\tconst candidate = (globalThis as { amadeus?: AmadeusProvider }).amadeus\n\treturn candidate && candidate.isAmadeus === true ? candidate : null\n}\n\n/** Whether a genuine Amadeus provider is currently injected. */\nexport function isProviderAvailable(): boolean {\n\treturn getAmadeusProvider() !== null\n}\n"],"mappings":";;AAmFA,SAAgB,qBAA6C;CAC5D,MAAM,YAAa,WAA6C;CAChE,OAAO,aAAa,UAAU,cAAc,OAAO,YAAY;AAChE;;AAGA,SAAgB,sBAA+B;CAC9C,OAAO,mBAAmB,MAAM;AACjC"}
@@ -1,6 +1,5 @@
1
1
  import { WalletRequest, WalletResponse } from "../transport/envelope.js";
2
2
  import { NetworkType } from "@amadeus-protocol/sdk";
3
- //#region src/wallet/handler.d.ts
4
3
  interface WalletHandlerContext {
5
4
  /** Seed (private key) of the account bound to this session. */
6
5
  seed: string;
@@ -15,10 +14,10 @@ interface WalletHandlerContext {
15
14
  /**
16
15
  * Service one approved request and return a response ready to seal. Never throws
17
16
  * — failures come back as `{ ok: false, error }` so the transport can always
18
- * reply. `amadeus_switchNetwork` is deliberately delegated to the app (it mutates
19
- * wallet runtime state), signalled with a distinct error the caller can branch on.
17
+ * reply. `amadeus_switchNetwork` and `amadeus_switchAccount` are deliberately
18
+ * delegated to the app (they mutate wallet runtime state), signalled with a
19
+ * distinct error the caller can branch on.
20
20
  */
21
21
  declare function handleRequest(request: WalletRequest, ctx: WalletHandlerContext): WalletResponse;
22
- //#endregion
23
22
  export { WalletHandlerContext, handleRequest };
24
23
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","names":[],"sources":["../../src/wallet/handler.ts"],"mappings":";;;UAyBiB;;EAEhB;;EAEA;;;;;EAKA,UAAU;;;;;;;;iBAmBK,cAAc,SAAS,eAAe,KAAK,uBAAuB"}
1
+ {"version":3,"file":"handler.d.ts","names":[],"sources":["../../src/wallet/handler.ts"],"mappings":";;UAyBiB;;EAEhB;;EAEA;;;;;EAKA,UAAU;;;;;;;;;iBAoBK,cAAc,SAAS,eAAe,KAAK,uBAAuB"}
@@ -4,7 +4,7 @@ import { signTransaction } from "../tx.js";
4
4
  import { generateApiKeyRequestSchema, signMessageRequestSchema, signTransactionRequestSchema } from "../schema.js";
5
5
  import { generateApiKey } from "../crypto/apikey.js";
6
6
  import { signMessage } from "../crypto/message.js";
7
- //#region src/wallet/handler.ts
7
+ // src/wallet/handler.ts
8
8
  function ok(id, result) {
9
9
  return {
10
10
  v: 1,
@@ -27,8 +27,9 @@ function fail(id, error) {
27
27
  /**
28
28
  * Service one approved request and return a response ready to seal. Never throws
29
29
  * — failures come back as `{ ok: false, error }` so the transport can always
30
- * reply. `amadeus_switchNetwork` is deliberately delegated to the app (it mutates
31
- * wallet runtime state), signalled with a distinct error the caller can branch on.
30
+ * reply. `amadeus_switchNetwork` and `amadeus_switchAccount` are deliberately
31
+ * delegated to the app (they mutate wallet runtime state), signalled with a
32
+ * distinct error the caller can branch on.
32
33
  */
33
34
  function handleRequest(request, ctx) {
34
35
  try {
@@ -67,13 +68,13 @@ function handleRequest(request, ctx) {
67
68
  return ok(request.id, signed);
68
69
  }
69
70
  case "amadeus_switchNetwork": throw new WalletSdkError("INVALID_ARGUMENT", "amadeus_switchNetwork must be handled by the wallet app (it changes runtime state)");
71
+ case "amadeus_switchAccount": throw new WalletSdkError("INVALID_ARGUMENT", "amadeus_switchAccount must be handled by the wallet app (it changes the active account)");
70
72
  default: throw new WalletSdkError("INVALID_ARGUMENT", `unknown method`);
71
73
  }
72
74
  } catch (error) {
73
75
  return fail(request.id, error);
74
76
  }
75
77
  }
76
- //#endregion
77
78
  export { handleRequest };
78
79
 
79
80
  //# sourceMappingURL=handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.js","names":[],"sources":["../../src/wallet/handler.ts"],"sourcesContent":["/**\n * Wallet-side request dispatch. Once the mobile app has opened + guarded an\n * inbound request and the user has approved it, this turns the request into a\n * signed response by routing to the right primitive. Keeping it here means the\n * app's approval screen only has to call one function; the wallet and extension\n * share identical request semantics.\n *\n * IMPORTANT: call this only AFTER `guardRequest` (expiry + replay) has passed and\n * the user has approved. It signs with the bound account's seed.\n */\n\nimport type { NetworkType } from '@amadeus-protocol/sdk'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { generateApiKey } from '../crypto/apikey'\nimport { signMessage } from '../crypto/message'\nimport { WalletSdkError } from '../errors'\nimport {\n\tgenerateApiKeyRequestSchema,\n\tsignMessageRequestSchema,\n\tsignTransactionRequestSchema\n} from '../schema'\nimport { signTransaction } from '../tx'\nimport type { WalletRequest, WalletResponse } from '../transport/envelope'\n\nexport interface WalletHandlerContext {\n\t/** Seed (private key) of the account bound to this session. */\n\tseed: string\n\t/** Address (Base58 public key) of the bound account. */\n\taddress: string\n\t/**\n\t * Active network. Transactions are signed with this network's DST so a tx\n\t * signed on one network can't be replayed on another. Defaults to mainnet.\n\t */\n\tnetwork?: NetworkType\n}\n\nfunction ok(id: string, result: unknown): WalletResponse {\n\treturn { v: PROTOCOL_VERSION, id, ok: true, result }\n}\n\nfunction fail(id: string, error: unknown): WalletResponse {\n\tconst code = error instanceof WalletSdkError ? error.code : 'INTERNAL'\n\tconst message = error instanceof Error ? error.message : 'unexpected error'\n\treturn { v: PROTOCOL_VERSION, id, ok: false, error: { code, message } }\n}\n\n/**\n * Service one approved request and return a response ready to seal. Never throws\n * — failures come back as `{ ok: false, error }` so the transport can always\n * reply. `amadeus_switchNetwork` is deliberately delegated to the app (it mutates\n * wallet runtime state), signalled with a distinct error the caller can branch on.\n */\nexport function handleRequest(request: WalletRequest, ctx: WalletHandlerContext): WalletResponse {\n\ttry {\n\t\tswitch (request.method) {\n\t\t\tcase 'amadeus_signTransaction': {\n\t\t\t\tconst parsed = signTransactionRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid signTransaction params')\n\t\t\t\t}\n\t\t\t\tconst signed = signTransaction({\n\t\t\t\t\tseed: ctx.seed,\n\t\t\t\t\tcontract: parsed.data.contract,\n\t\t\t\t\tmethod: parsed.data.method,\n\t\t\t\t\targs: parsed.data.args,\n\t\t\t\t\tdescription: parsed.data.description,\n\t\t\t\t\tnetwork: ctx.network\n\t\t\t\t})\n\t\t\t\treturn ok(request.id, signed)\n\t\t\t}\n\t\t\tcase 'amadeus_generateApiKey': {\n\t\t\t\tconst parsed = generateApiKeyRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid generateApiKey params')\n\t\t\t\t}\n\t\t\t\tconst { apiKey } = generateApiKey({\n\t\t\t\t\tseed: ctx.seed,\n\t\t\t\t\taud: parsed.data.aud,\n\t\t\t\t\texpIn: parsed.data.exp_in\n\t\t\t\t})\n\t\t\t\treturn ok(request.id, { apiKey })\n\t\t\t}\n\t\t\tcase 'amadeus_getAccounts':\n\t\t\t\treturn ok(request.id, { accounts: [ctx.address] })\n\t\t\tcase 'amadeus_signMessage': {\n\t\t\t\tconst parsed = signMessageRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid signMessage params')\n\t\t\t\t}\n\t\t\t\tconst signed = signMessage({ seed: ctx.seed, message: parsed.data.message })\n\t\t\t\treturn ok(request.id, signed)\n\t\t\t}\n\t\t\tcase 'amadeus_switchNetwork':\n\t\t\t\tthrow new WalletSdkError(\n\t\t\t\t\t'INVALID_ARGUMENT',\n\t\t\t\t\t'amadeus_switchNetwork must be handled by the wallet app (it changes runtime state)'\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', `unknown method`)\n\t\t}\n\t} catch (error) {\n\t\treturn fail(request.id, error)\n\t}\n}\n"],"mappings":";;;;;;;AAqCA,SAAS,GAAG,IAAY,QAAiC;CACxD,OAAO;EAAE,GAAA;EAAqB;EAAI,IAAI;EAAM;CAAO;AACpD;AAEA,SAAS,KAAK,IAAY,OAAgC;CAGzD,OAAO;EAAE,GAAA;EAAqB;EAAI,IAAI;EAAO,OAAO;GAAE,MAFzC,iBAAiB,iBAAiB,MAAM,OAAO;GAEA,SAD5C,iBAAiB,QAAQ,MAAM,UAAU;EACW;CAAE;AACvE;;;;;;;AAQA,SAAgB,cAAc,SAAwB,KAA2C;CAChG,IAAI;EACH,QAAQ,QAAQ,QAAhB;GACC,KAAK,2BAA2B;IAC/B,MAAM,SAAS,6BAA6B,UAAU,QAAQ,MAAM;IACpE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,gCAAgC;IAE9E,MAAM,SAAS,gBAAgB;KAC9B,MAAM,IAAI;KACV,UAAU,OAAO,KAAK;KACtB,QAAQ,OAAO,KAAK;KACpB,MAAM,OAAO,KAAK;KAClB,aAAa,OAAO,KAAK;KACzB,SAAS,IAAI;IACd,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,MAAM;GAC7B;GACA,KAAK,0BAA0B;IAC9B,MAAM,SAAS,4BAA4B,UAAU,QAAQ,MAAM;IACnE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,+BAA+B;IAE7E,MAAM,EAAE,WAAW,eAAe;KACjC,MAAM,IAAI;KACV,KAAK,OAAO,KAAK;KACjB,OAAO,OAAO,KAAK;IACpB,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,EAAE,OAAO,CAAC;GACjC;GACA,KAAK,uBACJ,OAAO,GAAG,QAAQ,IAAI,EAAE,UAAU,CAAC,IAAI,OAAO,EAAE,CAAC;GAClD,KAAK,uBAAuB;IAC3B,MAAM,SAAS,yBAAyB,UAAU,QAAQ,MAAM;IAChE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,4BAA4B;IAE1E,MAAM,SAAS,YAAY;KAAE,MAAM,IAAI;KAAM,SAAS,OAAO,KAAK;IAAQ,CAAC;IAC3E,OAAO,GAAG,QAAQ,IAAI,MAAM;GAC7B;GACA,KAAK,yBACJ,MAAM,IAAI,eACT,oBACA,oFACD;GACD,SACC,MAAM,IAAI,eAAe,oBAAoB,gBAAgB;EAC/D;CACD,SAAS,OAAO;EACf,OAAO,KAAK,QAAQ,IAAI,KAAK;CAC9B;AACD"}
1
+ {"version":3,"file":"handler.js","names":[],"sources":["../../src/wallet/handler.ts"],"sourcesContent":["/**\n * Wallet-side request dispatch. Once the mobile app has opened + guarded an\n * inbound request and the user has approved it, this turns the request into a\n * signed response by routing to the right primitive. Keeping it here means the\n * app's approval screen only has to call one function; the wallet and extension\n * share identical request semantics.\n *\n * IMPORTANT: call this only AFTER `guardRequest` (expiry + replay) has passed and\n * the user has approved. It signs with the bound account's seed.\n */\n\nimport type { NetworkType } from '@amadeus-protocol/sdk'\n\nimport { PROTOCOL_VERSION } from '../constants'\nimport { generateApiKey } from '../crypto/apikey'\nimport { signMessage } from '../crypto/message'\nimport { WalletSdkError } from '../errors'\nimport {\n\tgenerateApiKeyRequestSchema,\n\tsignMessageRequestSchema,\n\tsignTransactionRequestSchema\n} from '../schema'\nimport { signTransaction } from '../tx'\nimport type { WalletRequest, WalletResponse } from '../transport/envelope'\n\nexport interface WalletHandlerContext {\n\t/** Seed (private key) of the account bound to this session. */\n\tseed: string\n\t/** Address (Base58 public key) of the bound account. */\n\taddress: string\n\t/**\n\t * Active network. Transactions are signed with this network's DST so a tx\n\t * signed on one network can't be replayed on another. Defaults to mainnet.\n\t */\n\tnetwork?: NetworkType\n}\n\nfunction ok(id: string, result: unknown): WalletResponse {\n\treturn { v: PROTOCOL_VERSION, id, ok: true, result }\n}\n\nfunction fail(id: string, error: unknown): WalletResponse {\n\tconst code = error instanceof WalletSdkError ? error.code : 'INTERNAL'\n\tconst message = error instanceof Error ? error.message : 'unexpected error'\n\treturn { v: PROTOCOL_VERSION, id, ok: false, error: { code, message } }\n}\n\n/**\n * Service one approved request and return a response ready to seal. Never throws\n * — failures come back as `{ ok: false, error }` so the transport can always\n * reply. `amadeus_switchNetwork` and `amadeus_switchAccount` are deliberately\n * delegated to the app (they mutate wallet runtime state), signalled with a\n * distinct error the caller can branch on.\n */\nexport function handleRequest(request: WalletRequest, ctx: WalletHandlerContext): WalletResponse {\n\ttry {\n\t\tswitch (request.method) {\n\t\t\tcase 'amadeus_signTransaction': {\n\t\t\t\tconst parsed = signTransactionRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid signTransaction params')\n\t\t\t\t}\n\t\t\t\tconst signed = signTransaction({\n\t\t\t\t\tseed: ctx.seed,\n\t\t\t\t\tcontract: parsed.data.contract,\n\t\t\t\t\tmethod: parsed.data.method,\n\t\t\t\t\targs: parsed.data.args,\n\t\t\t\t\tdescription: parsed.data.description,\n\t\t\t\t\tnetwork: ctx.network\n\t\t\t\t})\n\t\t\t\treturn ok(request.id, signed)\n\t\t\t}\n\t\t\tcase 'amadeus_generateApiKey': {\n\t\t\t\tconst parsed = generateApiKeyRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid generateApiKey params')\n\t\t\t\t}\n\t\t\t\tconst { apiKey } = generateApiKey({\n\t\t\t\t\tseed: ctx.seed,\n\t\t\t\t\taud: parsed.data.aud,\n\t\t\t\t\texpIn: parsed.data.exp_in\n\t\t\t\t})\n\t\t\t\treturn ok(request.id, { apiKey })\n\t\t\t}\n\t\t\tcase 'amadeus_getAccounts':\n\t\t\t\treturn ok(request.id, { accounts: [ctx.address] })\n\t\t\tcase 'amadeus_signMessage': {\n\t\t\t\tconst parsed = signMessageRequestSchema.safeParse(request.params)\n\t\t\t\tif (!parsed.success) {\n\t\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'invalid signMessage params')\n\t\t\t\t}\n\t\t\t\tconst signed = signMessage({ seed: ctx.seed, message: parsed.data.message })\n\t\t\t\treturn ok(request.id, signed)\n\t\t\t}\n\t\t\tcase 'amadeus_switchNetwork':\n\t\t\t\tthrow new WalletSdkError(\n\t\t\t\t\t'INVALID_ARGUMENT',\n\t\t\t\t\t'amadeus_switchNetwork must be handled by the wallet app (it changes runtime state)'\n\t\t\t\t)\n\t\t\tcase 'amadeus_switchAccount':\n\t\t\t\tthrow new WalletSdkError(\n\t\t\t\t\t'INVALID_ARGUMENT',\n\t\t\t\t\t'amadeus_switchAccount must be handled by the wallet app (it changes the active account)'\n\t\t\t\t)\n\t\t\tdefault:\n\t\t\t\tthrow new WalletSdkError('INVALID_ARGUMENT', `unknown method`)\n\t\t}\n\t} catch (error) {\n\t\treturn fail(request.id, error)\n\t}\n}\n"],"mappings":";;;;;;;AAqCA,SAAS,GAAG,IAAY,QAAiC;CACxD,OAAO;EAAE,GAAA;EAAqB;EAAI,IAAI;EAAM;CAAO;AACpD;AAEA,SAAS,KAAK,IAAY,OAAgC;CAGzD,OAAO;EAAE,GAAA;EAAqB;EAAI,IAAI;EAAO,OAAO;GAAE,MAFzC,iBAAiB,iBAAiB,MAAM,OAAO;GAEA,SAD5C,iBAAiB,QAAQ,MAAM,UAAU;EACW;CAAE;AACvE;;;;;;;;AASA,SAAgB,cAAc,SAAwB,KAA2C;CAChG,IAAI;EACH,QAAQ,QAAQ,QAAhB;GACC,KAAK,2BAA2B;IAC/B,MAAM,SAAS,6BAA6B,UAAU,QAAQ,MAAM;IACpE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,gCAAgC;IAE9E,MAAM,SAAS,gBAAgB;KAC9B,MAAM,IAAI;KACV,UAAU,OAAO,KAAK;KACtB,QAAQ,OAAO,KAAK;KACpB,MAAM,OAAO,KAAK;KAClB,aAAa,OAAO,KAAK;KACzB,SAAS,IAAI;IACd,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,MAAM;GAC7B;GACA,KAAK,0BAA0B;IAC9B,MAAM,SAAS,4BAA4B,UAAU,QAAQ,MAAM;IACnE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,+BAA+B;IAE7E,MAAM,EAAE,WAAW,eAAe;KACjC,MAAM,IAAI;KACV,KAAK,OAAO,KAAK;KACjB,OAAO,OAAO,KAAK;IACpB,CAAC;IACD,OAAO,GAAG,QAAQ,IAAI,EAAE,OAAO,CAAC;GACjC;GACA,KAAK,uBACJ,OAAO,GAAG,QAAQ,IAAI,EAAE,UAAU,CAAC,IAAI,OAAO,EAAE,CAAC;GAClD,KAAK,uBAAuB;IAC3B,MAAM,SAAS,yBAAyB,UAAU,QAAQ,MAAM;IAChE,IAAI,CAAC,OAAO,SACX,MAAM,IAAI,eAAe,oBAAoB,4BAA4B;IAE1E,MAAM,SAAS,YAAY;KAAE,MAAM,IAAI;KAAM,SAAS,OAAO,KAAK;IAAQ,CAAC;IAC3E,OAAO,GAAG,QAAQ,IAAI,MAAM;GAC7B;GACA,KAAK,yBACJ,MAAM,IAAI,eACT,oBACA,oFACD;GACD,KAAK,yBACJ,MAAM,IAAI,eACT,oBACA,yFACD;GACD,SACC,MAAM,IAAI,eAAe,oBAAoB,gBAAgB;EAC/D;CACD,SAAS,OAAO;EACf,OAAO,KAAK,QAAQ,IAAI,KAAK;CAC9B;AACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amadeus-protocol/wallet-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Shared dApp <-> wallet connection layer for Amadeus Protocol: BLS API-key tokens, transaction signing, message/connect signing, and the typed provider contract. One audited implementation for the wallet, the extension, and every dApp.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -67,7 +67,7 @@
67
67
  "zod": "^3.24.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "@amadeus-protocol/sdk": "^1.1.2",
70
+ "@amadeus-protocol/sdk": "^1.3.0",
71
71
  "react": ">=18.0.0"
72
72
  },
73
73
  "peerDependenciesMeta": {
@@ -76,7 +76,7 @@
76
76
  }
77
77
  },
78
78
  "devDependencies": {
79
- "@amadeus-protocol/sdk": "^1.1.2",
79
+ "@amadeus-protocol/sdk": "^1.6.0",
80
80
  "@eslint/js": "^9.21.0",
81
81
  "@types/node": "^22.14.0",
82
82
  "@types/react": "^19.0.0",