@amadeus-protocol/wallet-sdk 0.1.4 → 0.1.6

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 (67) 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 +0 -2
  9. package/dist/client/injected.d.ts.map +1 -1
  10. package/dist/client/injected.js +1 -2
  11. package/dist/constants.d.ts +0 -2
  12. package/dist/constants.d.ts.map +1 -1
  13. package/dist/constants.js +1 -2
  14. package/dist/crypto/apikey.d.ts +0 -2
  15. package/dist/crypto/apikey.d.ts.map +1 -1
  16. package/dist/crypto/apikey.js +5 -3
  17. package/dist/crypto/apikey.js.map +1 -1
  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 +3 -3
  24. package/dist/crypto/box.js.map +1 -1
  25. package/dist/crypto/connect.d.ts +0 -2
  26. package/dist/crypto/connect.d.ts.map +1 -1
  27. package/dist/crypto/connect.js +3 -3
  28. package/dist/crypto/connect.js.map +1 -1
  29. package/dist/crypto/message.d.ts +0 -2
  30. package/dist/crypto/message.d.ts.map +1 -1
  31. package/dist/crypto/message.js +3 -3
  32. package/dist/crypto/message.js.map +1 -1
  33. package/dist/errors.d.ts +0 -2
  34. package/dist/errors.d.ts.map +1 -1
  35. package/dist/errors.js +1 -2
  36. package/dist/react/index.d.ts +0 -2
  37. package/dist/react/index.d.ts.map +1 -1
  38. package/dist/react/index.js +1 -2
  39. package/dist/schema.d.ts +0 -2
  40. package/dist/schema.d.ts.map +1 -1
  41. package/dist/schema.js +1 -2
  42. package/dist/transport/bridge.d.ts +0 -2
  43. package/dist/transport/bridge.d.ts.map +1 -1
  44. package/dist/transport/bridge.js +2 -3
  45. package/dist/transport/bridge.js.map +1 -1
  46. package/dist/transport/envelope.d.ts +0 -2
  47. package/dist/transport/envelope.d.ts.map +1 -1
  48. package/dist/transport/envelope.js +1 -2
  49. package/dist/transport/session.d.ts +0 -2
  50. package/dist/transport/session.d.ts.map +1 -1
  51. package/dist/transport/session.js +11 -11
  52. package/dist/transport/session.js.map +1 -1
  53. package/dist/transport/uri.d.ts +0 -2
  54. package/dist/transport/uri.d.ts.map +1 -1
  55. package/dist/transport/uri.js +1 -2
  56. package/dist/tx.d.ts +3 -11
  57. package/dist/tx.d.ts.map +1 -1
  58. package/dist/tx.js +13 -10
  59. package/dist/tx.js.map +1 -1
  60. package/dist/types.d.ts +0 -2
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/types.js +1 -2
  63. package/dist/wallet/handler.d.ts +6 -2
  64. package/dist/wallet/handler.d.ts.map +1 -1
  65. package/dist/wallet/handler.js +3 -13
  66. package/dist/wallet/handler.js.map +1 -1
  67. package/package.json +6 -6
@@ -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;cAEL,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
@@ -16,7 +16,7 @@ import { sha256 } from "@noble/hashes/sha2";
16
16
  * React Native (no EventSource/streaming dependency).
17
17
  */
18
18
  /** Max bytes we will read from a (possibly hostile) relay response. */
19
- const MAX_POLL_RESPONSE_BYTES = 8 * 1024 * 1024;
19
+ const MAX_POLL_RESPONSE_BYTES = 8388608;
20
20
  /**
21
21
  * Derive the two per-direction secret channel ids from the session shared key.
22
22
  * Both sides compute the same pair; a third party without the shared key cannot.
@@ -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 +1 @@
1
- {"version":3,"file":"bridge.js","names":[],"sources":["../../src/transport/bridge.ts"],"sourcesContent":["/**\n * Client for the cross-device relay (\"bridge\"). After the connect handshake both\n * sides hold a shared key; from it they derive TWO SECRET channel ids (one per\n * direction) via `deriveBridgeChannels`. Each side listens on one channel and\n * sends on the other. Because the channel ids are derived from the shared key —\n * NOT from the public session keys — a third party who only observes the connect\n * handshake cannot address, drain, or flood a session's channels. The relay stays\n * dumb and untrusted: it only moves sealed ciphertext between opaque channel ids.\n *\n * Transport is long-polling over `fetch` — universal across Node, browsers, and\n * React Native (no EventSource/streaming dependency).\n */\n\nimport { fromBase58, toBase58 } from '@amadeus-protocol/sdk'\nimport { sha256 } from '@noble/hashes/sha2'\n\nimport { concatBytes, utf8ToBytes } from '../bytes'\nimport { WalletSdkError } from '../errors'\n\n/** Max bytes we will read from a (possibly hostile) relay response. */\nconst MAX_POLL_RESPONSE_BYTES = 8 * 1024 * 1024\n\nexport interface BridgeFrame {\n\t/** Sender channel (informational). */\n\tfrom: string\n\t/** Recipient channel id this frame is addressed to. */\n\tto: string\n\t/** Unique frame id (also the request/response id) — for dedupe. */\n\tid: string\n\t/**\n\t * The JSON payload. Post-connect this is a sealed (E2E-encrypted) envelope;\n\t * the ONE exception is the connect response (public handshake data, integrity\n\t * protected by the connect signature) sent on the connect channel before a\n\t * shared key exists.\n\t */\n\tpayload: unknown\n}\n\n/**\n * Derive the two per-direction secret channel ids from the session shared key.\n * Both sides compute the same pair; a third party without the shared key cannot.\n */\nexport function deriveBridgeChannels(sharedKey: Uint8Array): {\n\t/** Channel the wallet listens on / the dApp sends to. */\n\ttoWallet: string\n\t/** Channel the dApp listens on / the wallet sends to. */\n\ttoDapp: string\n} {\n\tconst channel = (label: string) => toBase58(sha256(concatBytes(utf8ToBytes(label), sharedKey)))\n\treturn {\n\t\ttoWallet: channel('amadeus-bridge/to-wallet/v1'),\n\t\ttoDapp: channel('amadeus-bridge/to-dapp/v1')\n\t}\n}\n\n/**\n * Channel the dApp listens on for the CONNECT RESPONSE (cross-device / QR), before\n * a shared key exists. Derived from the dApp's PUBLIC session key (which is in the\n * connect QR), so the dApp can listen for it immediately. The response carried\n * here is public handshake data whose integrity is verified by the connect\n * signature (`verifyConnect`), so a forged response is rejected.\n */\nexport function deriveConnectChannel(dappPublicKeyBase58: string): string {\n\treturn toBase58(\n\t\tsha256(\n\t\t\tconcatBytes(utf8ToBytes('amadeus-bridge/connect/v1'), fromBase58(dappPublicKeyBase58))\n\t\t)\n\t)\n}\n\n/**\n * Reject a bridge URL that isn't https (http is allowed only for localhost dev).\n * Blocks the wallet being pointed at file://, internal http hosts, or other\n * SSRF/forced-beacon targets by an attacker-supplied connect link.\n */\nexport function assertAllowedBridgeUrl(url: string): void {\n\tconst match = /^([a-z][a-z0-9+.-]*):\\/\\/([^/:?#]+)/i.exec(url)\n\tif (!match) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'bridge URL is not a valid absolute URL')\n\t}\n\tconst scheme = match[1].toLowerCase()\n\tconst host = match[2].toLowerCase()\n\tconst isLocal = host === 'localhost' || host === '127.0.0.1' || host === '::1'\n\tif (scheme === 'https' || (scheme === 'http' && isLocal)) return\n\tthrow new WalletSdkError(\n\t\t'INVALID_ARGUMENT',\n\t\t'bridge URL must be https (http allowed only for localhost)'\n\t)\n}\n\nexport interface BridgeClientOptions {\n\t/** Relay base URL, e.g. \"https://bridge.ama.one\". */\n\tbridgeUrl: string\n\t/** This side's channel id to listen on (from `deriveBridgeChannels`). */\n\tclientId: string\n\t/** Override fetch (tests / non-standard runtimes). */\n\tfetchImpl?: typeof fetch\n\t/** How long the relay holds a long-poll before returning empty (seconds). */\n\tpollWaitSeconds?: number\n}\n\nexport class BridgeClient {\n\tprivate readonly bridgeUrl: string\n\tprivate readonly clientId: string\n\tprivate readonly fetchImpl: typeof fetch\n\tprivate readonly pollWaitSeconds: number\n\n\tconstructor(options: BridgeClientOptions) {\n\t\tassertAllowedBridgeUrl(options.bridgeUrl)\n\t\tthis.bridgeUrl = options.bridgeUrl.replace(/\\/$/, '')\n\t\tthis.clientId = options.clientId\n\t\t// Bind to the global: a bare `fetch` reference called as `this.fetchImpl(...)`\n\t\t// is detached from its global and throws \"Illegal invocation\" in browsers\n\t\t// (WebIDL requires `this` to be the Window/WorkerGlobalScope). Node/RN tolerate\n\t\t// it, which is why this only surfaces in a real browser dApp.\n\t\tthis.fetchImpl = options.fetchImpl ?? fetch.bind(globalThis)\n\t\tthis.pollWaitSeconds = options.pollWaitSeconds ?? 25\n\t}\n\n\t/** Send a frame (sealed envelope, or plaintext connect response) to a channel id. */\n\tasync send(to: string, id: string, payload: unknown): Promise<void> {\n\t\tconst frame: BridgeFrame = { from: this.clientId, to, id, payload }\n\t\tconst res = await this.fetchImpl(`${this.bridgeUrl}/message?to=${encodeURIComponent(to)}`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify(frame)\n\t\t})\n\t\tif (!res.ok) {\n\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', `bridge send failed: ${res.status}`)\n\t\t}\n\t}\n\n\t/**\n\t * Start long-polling for frames on this client's channel. Returns a `stop()`\n\t * function. `onFrame` is invoked per received frame; transient errors go to\n\t * `onError` (if given) and the loop retries after a short backoff. Each poll\n\t * has a hard timeout and a response-size cap so a hostile/hung relay can't\n\t * stall the loop or exhaust memory.\n\t */\n\tstart(\n\t\tonFrame: (frame: BridgeFrame) => void | Promise<void>,\n\t\tonError?: (error: unknown) => void\n\t): () => void {\n\t\tconst controller = new AbortController()\n\n\t\tconst poll = async (): Promise<BridgeFrame[]> => {\n\t\t\tconst timeout = setTimeout(() => controller.abort(), (this.pollWaitSeconds + 10) * 1000)\n\t\t\ttry {\n\t\t\t\tconst url = `${this.bridgeUrl}/events?client_id=${encodeURIComponent(this.clientId)}&wait=${this.pollWaitSeconds}`\n\t\t\t\tconst res = await this.fetchImpl(url, { signal: controller.signal })\n\t\t\t\tif (!res.ok) {\n\t\t\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', `bridge poll failed: ${res.status}`)\n\t\t\t\t}\n\t\t\t\tconst declared = Number(res.headers.get('content-length') ?? 0)\n\t\t\t\tif (declared > MAX_POLL_RESPONSE_BYTES) {\n\t\t\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', 'bridge response too large')\n\t\t\t\t}\n\t\t\t\tconst text = await res.text()\n\t\t\t\tif (text.length > MAX_POLL_RESPONSE_BYTES) {\n\t\t\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', 'bridge response too large')\n\t\t\t\t}\n\t\t\t\tconst parsed = JSON.parse(text)\n\t\t\t\treturn Array.isArray(parsed) ? (parsed as BridgeFrame[]) : []\n\t\t\t} finally {\n\t\t\t\tclearTimeout(timeout)\n\t\t\t}\n\t\t}\n\n\t\tconst loop = async () => {\n\t\t\twhile (!controller.signal.aborted) {\n\t\t\t\ttry {\n\t\t\t\t\tconst frames = await poll()\n\t\t\t\t\tfor (const frame of frames) {\n\t\t\t\t\t\tif (controller.signal.aborted) break\n\t\t\t\t\t\tawait onFrame(frame)\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (controller.signal.aborted) break\n\t\t\t\t\tonError?.(error)\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid loop()\n\t\treturn () => controller.abort()\n\t}\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"bridge.js","names":[],"sources":["../../src/transport/bridge.ts"],"sourcesContent":["/**\n * Client for the cross-device relay (\"bridge\"). After the connect handshake both\n * sides hold a shared key; from it they derive TWO SECRET channel ids (one per\n * direction) via `deriveBridgeChannels`. Each side listens on one channel and\n * sends on the other. Because the channel ids are derived from the shared key —\n * NOT from the public session keys — a third party who only observes the connect\n * handshake cannot address, drain, or flood a session's channels. The relay stays\n * dumb and untrusted: it only moves sealed ciphertext between opaque channel ids.\n *\n * Transport is long-polling over `fetch` — universal across Node, browsers, and\n * React Native (no EventSource/streaming dependency).\n */\n\nimport { fromBase58, toBase58 } from '@amadeus-protocol/sdk'\nimport { sha256 } from '@noble/hashes/sha2'\n\nimport { concatBytes, utf8ToBytes } from '../bytes'\nimport { WalletSdkError } from '../errors'\n\n/** Max bytes we will read from a (possibly hostile) relay response. */\nconst MAX_POLL_RESPONSE_BYTES = 8 * 1024 * 1024\n\nexport interface BridgeFrame {\n\t/** Sender channel (informational). */\n\tfrom: string\n\t/** Recipient channel id this frame is addressed to. */\n\tto: string\n\t/** Unique frame id (also the request/response id) — for dedupe. */\n\tid: string\n\t/**\n\t * The JSON payload. Post-connect this is a sealed (E2E-encrypted) envelope;\n\t * the ONE exception is the connect response (public handshake data, integrity\n\t * protected by the connect signature) sent on the connect channel before a\n\t * shared key exists.\n\t */\n\tpayload: unknown\n}\n\n/**\n * Derive the two per-direction secret channel ids from the session shared key.\n * Both sides compute the same pair; a third party without the shared key cannot.\n */\nexport function deriveBridgeChannels(sharedKey: Uint8Array): {\n\t/** Channel the wallet listens on / the dApp sends to. */\n\ttoWallet: string\n\t/** Channel the dApp listens on / the wallet sends to. */\n\ttoDapp: string\n} {\n\tconst channel = (label: string) => toBase58(sha256(concatBytes(utf8ToBytes(label), sharedKey)))\n\treturn {\n\t\ttoWallet: channel('amadeus-bridge/to-wallet/v1'),\n\t\ttoDapp: channel('amadeus-bridge/to-dapp/v1')\n\t}\n}\n\n/**\n * Channel the dApp listens on for the CONNECT RESPONSE (cross-device / QR), before\n * a shared key exists. Derived from the dApp's PUBLIC session key (which is in the\n * connect QR), so the dApp can listen for it immediately. The response carried\n * here is public handshake data whose integrity is verified by the connect\n * signature (`verifyConnect`), so a forged response is rejected.\n */\nexport function deriveConnectChannel(dappPublicKeyBase58: string): string {\n\treturn toBase58(\n\t\tsha256(\n\t\t\tconcatBytes(utf8ToBytes('amadeus-bridge/connect/v1'), fromBase58(dappPublicKeyBase58))\n\t\t)\n\t)\n}\n\n/**\n * Reject a bridge URL that isn't https (http is allowed only for localhost dev).\n * Blocks the wallet being pointed at file://, internal http hosts, or other\n * SSRF/forced-beacon targets by an attacker-supplied connect link.\n */\nexport function assertAllowedBridgeUrl(url: string): void {\n\tconst match = /^([a-z][a-z0-9+.-]*):\\/\\/([^/:?#]+)/i.exec(url)\n\tif (!match) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'bridge URL is not a valid absolute URL')\n\t}\n\tconst scheme = match[1].toLowerCase()\n\tconst host = match[2].toLowerCase()\n\tconst isLocal = host === 'localhost' || host === '127.0.0.1' || host === '::1'\n\tif (scheme === 'https' || (scheme === 'http' && isLocal)) return\n\tthrow new WalletSdkError(\n\t\t'INVALID_ARGUMENT',\n\t\t'bridge URL must be https (http allowed only for localhost)'\n\t)\n}\n\nexport interface BridgeClientOptions {\n\t/** Relay base URL, e.g. \"https://bridge.ama.one\". */\n\tbridgeUrl: string\n\t/** This side's channel id to listen on (from `deriveBridgeChannels`). */\n\tclientId: string\n\t/** Override fetch (tests / non-standard runtimes). */\n\tfetchImpl?: typeof fetch\n\t/** How long the relay holds a long-poll before returning empty (seconds). */\n\tpollWaitSeconds?: number\n}\n\nexport class BridgeClient {\n\tprivate readonly bridgeUrl: string\n\tprivate readonly clientId: string\n\tprivate readonly fetchImpl: typeof fetch\n\tprivate readonly pollWaitSeconds: number\n\n\tconstructor(options: BridgeClientOptions) {\n\t\tassertAllowedBridgeUrl(options.bridgeUrl)\n\t\tthis.bridgeUrl = options.bridgeUrl.replace(/\\/$/, '')\n\t\tthis.clientId = options.clientId\n\t\t// Bind to the global: a bare `fetch` reference called as `this.fetchImpl(...)`\n\t\t// is detached from its global and throws \"Illegal invocation\" in browsers\n\t\t// (WebIDL requires `this` to be the Window/WorkerGlobalScope). Node/RN tolerate\n\t\t// it, which is why this only surfaces in a real browser dApp.\n\t\tthis.fetchImpl = options.fetchImpl ?? fetch.bind(globalThis)\n\t\tthis.pollWaitSeconds = options.pollWaitSeconds ?? 25\n\t}\n\n\t/** Send a frame (sealed envelope, or plaintext connect response) to a channel id. */\n\tasync send(to: string, id: string, payload: unknown): Promise<void> {\n\t\tconst frame: BridgeFrame = { from: this.clientId, to, id, payload }\n\t\tconst res = await this.fetchImpl(`${this.bridgeUrl}/message?to=${encodeURIComponent(to)}`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/json' },\n\t\t\tbody: JSON.stringify(frame)\n\t\t})\n\t\tif (!res.ok) {\n\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', `bridge send failed: ${res.status}`)\n\t\t}\n\t}\n\n\t/**\n\t * Start long-polling for frames on this client's channel. Returns a `stop()`\n\t * function. `onFrame` is invoked per received frame; transient errors go to\n\t * `onError` (if given) and the loop retries after a short backoff. Each poll\n\t * has a hard timeout and a response-size cap so a hostile/hung relay can't\n\t * stall the loop or exhaust memory.\n\t */\n\tstart(\n\t\tonFrame: (frame: BridgeFrame) => void | Promise<void>,\n\t\tonError?: (error: unknown) => void\n\t): () => void {\n\t\tconst controller = new AbortController()\n\n\t\tconst poll = async (): Promise<BridgeFrame[]> => {\n\t\t\tconst timeout = setTimeout(() => controller.abort(), (this.pollWaitSeconds + 10) * 1000)\n\t\t\ttry {\n\t\t\t\tconst url = `${this.bridgeUrl}/events?client_id=${encodeURIComponent(this.clientId)}&wait=${this.pollWaitSeconds}`\n\t\t\t\tconst res = await this.fetchImpl(url, { signal: controller.signal })\n\t\t\t\tif (!res.ok) {\n\t\t\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', `bridge poll failed: ${res.status}`)\n\t\t\t\t}\n\t\t\t\tconst declared = Number(res.headers.get('content-length') ?? 0)\n\t\t\t\tif (declared > MAX_POLL_RESPONSE_BYTES) {\n\t\t\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', 'bridge response too large')\n\t\t\t\t}\n\t\t\t\tconst text = await res.text()\n\t\t\t\tif (text.length > MAX_POLL_RESPONSE_BYTES) {\n\t\t\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', 'bridge response too large')\n\t\t\t\t}\n\t\t\t\tconst parsed = JSON.parse(text)\n\t\t\t\treturn Array.isArray(parsed) ? (parsed as BridgeFrame[]) : []\n\t\t\t} finally {\n\t\t\t\tclearTimeout(timeout)\n\t\t\t}\n\t\t}\n\n\t\tconst loop = async () => {\n\t\t\twhile (!controller.signal.aborted) {\n\t\t\t\ttry {\n\t\t\t\t\tconst frames = await poll()\n\t\t\t\t\tfor (const frame of frames) {\n\t\t\t\t\t\tif (controller.signal.aborted) break\n\t\t\t\t\t\tawait onFrame(frame)\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (controller.signal.aborted) break\n\t\t\t\t\tonError?.(error)\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 1000))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvoid loop()\n\t\treturn () => controller.abort()\n\t}\n}\n"],"mappings":"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"}
@@ -1,5 +1,4 @@
1
1
  import { SealedEnvelope } from "../crypto/box.js";
2
- //#region src/transport/envelope.d.ts
3
2
  declare const WALLET_METHODS: readonly ["amadeus_signTransaction", "amadeus_signMessage", "amadeus_getAccounts", "amadeus_generateApiKey", "amadeus_switchNetwork"];
4
3
  type WalletMethod = (typeof WALLET_METHODS)[number];
5
4
  interface WalletRequest {
@@ -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;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"}
@@ -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
@@ -119,7 +119,6 @@ function guardRequest(request, store, now) {
119
119
  if (store.has(request.id)) throw new WalletSdkError("INVALID_ARGUMENT", "duplicate request id (replay)");
120
120
  store.add(request.id);
121
121
  }
122
- //#endregion
123
122
  export { WALLET_METHODS, createMemorySeenStore, guardRequest, makeRequest, openRequest, openResponse, sealRequest, sealResponse };
124
123
 
125
124
  //# sourceMappingURL=envelope.js.map
@@ -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
@@ -29,16 +29,17 @@ function createConnectRequest(options) {
29
29
  const requestId = randomId();
30
30
  const exp = Math.floor((options.now ?? Date.now()) / 1e3) + (options.ttlSeconds ?? 120);
31
31
  const bridgeUrl = options.bridgeUrl ?? "https://bridge.ama.one";
32
+ const params = {
33
+ origin: options.origin,
34
+ dappPublicKey: dappKeypair.publicKey,
35
+ challenge,
36
+ requestId,
37
+ exp,
38
+ redirectLink: options.redirectLink,
39
+ bridgeUrl
40
+ };
32
41
  return {
33
- uri: buildConnectUri({
34
- origin: options.origin,
35
- dappPublicKey: dappKeypair.publicKey,
36
- challenge,
37
- requestId,
38
- exp,
39
- redirectLink: options.redirectLink,
40
- bridgeUrl
41
- }),
42
+ uri: buildConnectUri(params),
42
43
  pending: {
43
44
  requestId,
44
45
  challenge,
@@ -115,7 +116,6 @@ function approveConnect(request, options) {
115
116
  function isConnectRequestExpired(request, now) {
116
117
  return request.exp <= Math.floor((now ?? Date.now()) / 1e3);
117
118
  }
118
- //#endregion
119
119
  export { approveConnect, completeConnect, createConnectRequest, isConnectRequestExpired };
120
120
 
121
121
  //# sourceMappingURL=session.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","names":[],"sources":["../../src/transport/session.ts"],"sourcesContent":["/**\n * The connect handshake, orchestrated for both sides. This is where the crypto\n * primitives (connect transcript signing + x25519 box) and the URI transport\n * come together into an actual dApp <-> wallet session.\n *\n * Flow:\n * dApp: createConnectRequest() -> show `uri` (link/QR), keep `pending`\n * wallet: parseConnectUri(uri) -> [approve in UI] -> approveConnect()\n * -> return `response` to the dApp\n * dApp: completeConnect(pending, response) -> EstablishedSession\n *\n * After that both sides hold the same `sharedKey` and exchange sealed envelopes\n * (see envelope.ts). The wallet signs the transcript binding origin + BOTH\n * session keys + challenge + requestId, so a captured proof can't be replayed\n * under substituted keys.\n */\n\nimport { toBase58 } from '@amadeus-protocol/sdk'\n\nimport { DEFAULT_BRIDGE_URL } from '../constants'\nimport { randomBytes, randomId } from '../bytes'\nimport { signConnect, verifyConnect, type ConnectTranscript } from '../crypto/connect'\nimport { deriveSharedKey, generateSessionKeypair, type SessionKeypair } from '../crypto/box'\nimport { WalletSdkError } from '../errors'\nimport { buildConnectUri, type ConnectRequestParams, type ConnectResponseParams } from './uri'\n\n// ── dApp side ───────────────────────────────────────────────────────────────\n\n/** State the dApp keeps locally between issuing a connect request and completing it. */\nexport interface PendingConnect {\n\trequestId: string\n\tchallenge: string\n\torigin: string\n\t/** The dApp's ephemeral session keypair (secret stays local). */\n\tdappKeypair: SessionKeypair\n\texp: number\n\tbridgeUrl?: string\n}\n\nexport interface EstablishedSession {\n\t/** The connected wallet address (Base58 public key). */\n\taddress: string\n\t/** 32-byte symmetric key for sealing/opening envelopes. Keep in memory only. */\n\tsharedKey: Uint8Array\n\t/** The wallet's session key — the peer's bridge client id to send frames to. */\n\twalletPublicKey: string\n\t/** This dApp's session key — its own bridge client id to listen on. */\n\tselfPublicKey: string\n\torigin: string\n\t/** Relay base URL for post-connect sealed messages, if provided. */\n\tbridgeUrl?: string\n}\n\n/** dApp: create a connect request. Returns the URI to display and the pending state to keep. */\nexport function createConnectRequest(options: {\n\torigin: string\n\tredirectLink?: string\n\tbridgeUrl?: string\n\tttlSeconds?: number\n\tnow?: number\n}): { uri: string; pending: PendingConnect } {\n\tconst dappKeypair = generateSessionKeypair()\n\tconst challenge = toBase58(randomBytes(16))\n\tconst requestId = randomId()\n\tconst nowSec = Math.floor((options.now ?? Date.now()) / 1000)\n\tconst exp = nowSec + (options.ttlSeconds ?? 120)\n\t// Fall back to the production relay when the dApp doesn't pin its own.\n\tconst bridgeUrl = options.bridgeUrl ?? DEFAULT_BRIDGE_URL\n\n\tconst params: ConnectRequestParams = {\n\t\torigin: options.origin,\n\t\tdappPublicKey: dappKeypair.publicKey,\n\t\tchallenge,\n\t\trequestId,\n\t\texp,\n\t\tredirectLink: options.redirectLink,\n\t\tbridgeUrl\n\t}\n\treturn {\n\t\turi: buildConnectUri(params),\n\t\tpending: {\n\t\t\trequestId,\n\t\t\tchallenge,\n\t\t\torigin: options.origin,\n\t\t\tdappKeypair,\n\t\t\texp,\n\t\t\tbridgeUrl\n\t\t}\n\t}\n}\n\n/**\n * dApp: verify the wallet's connect response and establish the session. Throws\n * `INVALID_ARGUMENT` if the response is for a different request, or\n * `BAD_SIGNATURE` if the connect proof does not verify against the transcript.\n */\nexport function completeConnect(\n\tpending: PendingConnect,\n\tresponse: ConnectResponseParams\n): EstablishedSession {\n\tif (response.requestId !== pending.requestId) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response does not match the pending request')\n\t}\n\tconst transcript: ConnectTranscript = {\n\t\torigin: pending.origin,\n\t\tdappPublicKey: pending.dappKeypair.publicKey,\n\t\twalletPublicKey: response.walletPublicKey,\n\t\tchallenge: pending.challenge,\n\t\trequestId: pending.requestId\n\t}\n\tif (!verifyConnect({ address: response.address, transcript, signature: response.signature })) {\n\t\tthrow new WalletSdkError('BAD_SIGNATURE', 'connect proof failed verification')\n\t}\n\t// deriveSharedKey validates the wallet's session key (fails closed on a bad point).\n\tconst sharedKey = deriveSharedKey(response.walletPublicKey, pending.dappKeypair.secretKey)\n\treturn {\n\t\taddress: response.address,\n\t\tsharedKey,\n\t\twalletPublicKey: response.walletPublicKey,\n\t\tselfPublicKey: pending.dappKeypair.publicKey,\n\t\torigin: pending.origin,\n\t\tbridgeUrl: pending.bridgeUrl\n\t}\n}\n\n// ── wallet side ───────────────────────────────────────────────────────────────\n\nexport interface WalletSession {\n\t/** The response to hand back to the dApp (via callback URI or bridge frame). */\n\tresponse: ConnectResponseParams\n\t/** 32-byte symmetric key for sealing/opening envelopes. Keep in memory only. */\n\tsharedKey: Uint8Array\n\t/** The wallet's ephemeral session keypair for this dApp (its own bridge client id). */\n\twalletKeypair: SessionKeypair\n\t/** The dApp's session key — the peer's bridge client id to send frames to. */\n\tpeerPublicKey: string\n\t/** Relay base URL for post-connect sealed messages, if the dApp supplied one. */\n\tbridgeUrl?: string\n}\n\n/**\n * Wallet: approve a connect request and produce the signed response + session.\n * Call this ONLY AFTER the user has approved in the UI and the request's expiry\n * has been checked. `address` is the account that will be bound to this session\n * (bind to a specific account, not the live \"active\" one).\n */\nexport function approveConnect(\n\trequest: ConnectRequestParams,\n\toptions: { seed: string; address: string }\n): WalletSession {\n\tconst walletKeypair = generateSessionKeypair()\n\tconst transcript: ConnectTranscript = {\n\t\torigin: request.origin,\n\t\tdappPublicKey: request.dappPublicKey,\n\t\twalletPublicKey: walletKeypair.publicKey,\n\t\tchallenge: request.challenge,\n\t\trequestId: request.requestId\n\t}\n\tconst signature = signConnect({ seed: options.seed, transcript })\n\t// deriveSharedKey validates the dApp's session key (fails closed on a bad point).\n\tconst sharedKey = deriveSharedKey(request.dappPublicKey, walletKeypair.secretKey)\n\n\treturn {\n\t\tresponse: {\n\t\t\trequestId: request.requestId,\n\t\t\taddress: options.address,\n\t\t\twalletPublicKey: walletKeypair.publicKey,\n\t\t\tsignature\n\t\t},\n\t\tsharedKey,\n\t\twalletKeypair,\n\t\tpeerPublicKey: request.dappPublicKey,\n\t\tbridgeUrl: request.bridgeUrl\n\t}\n}\n\n/** Whether a parsed connect request has expired (wallet should reject/re-park). */\nexport function isConnectRequestExpired(request: ConnectRequestParams, now?: number): boolean {\n\treturn request.exp <= Math.floor((now ?? Date.now()) / 1000)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,qBAAqB,SAMQ;CAC5C,MAAM,cAAc,uBAAuB;CAC3C,MAAM,YAAY,SAAS,YAAY,EAAE,CAAC;CAC1C,MAAM,YAAY,SAAS;CAE3B,MAAM,MADS,KAAK,OAAO,QAAQ,OAAO,KAAK,IAAI,KAAK,GACvC,KAAK,QAAQ,cAAc;CAE5C,MAAM,YAAY,QAAQ,aAAA;CAW1B,OAAO;EACN,KAAK,gBAAgB;GATrB,QAAQ,QAAQ;GAChB,eAAe,YAAY;GAC3B;GACA;GACA;GACA,cAAc,QAAQ;GACtB;EAG0B,CAAC;EAC3B,SAAS;GACR;GACA;GACA,QAAQ,QAAQ;GAChB;GACA;GACA;EACD;CACD;AACD;;;;;;AAOA,SAAgB,gBACf,SACA,UACqB;CACrB,IAAI,SAAS,cAAc,QAAQ,WAClC,MAAM,IAAI,eAAe,oBAAoB,6CAA6C;CAE3F,MAAM,aAAgC;EACrC,QAAQ,QAAQ;EAChB,eAAe,QAAQ,YAAY;EACnC,iBAAiB,SAAS;EAC1B,WAAW,QAAQ;EACnB,WAAW,QAAQ;CACpB;CACA,IAAI,CAAC,cAAc;EAAE,SAAS,SAAS;EAAS;EAAY,WAAW,SAAS;CAAU,CAAC,GAC1F,MAAM,IAAI,eAAe,iBAAiB,mCAAmC;CAG9E,MAAM,YAAY,gBAAgB,SAAS,iBAAiB,QAAQ,YAAY,SAAS;CACzF,OAAO;EACN,SAAS,SAAS;EAClB;EACA,iBAAiB,SAAS;EAC1B,eAAe,QAAQ,YAAY;EACnC,QAAQ,QAAQ;EAChB,WAAW,QAAQ;CACpB;AACD;;;;;;;AAuBA,SAAgB,eACf,SACA,SACgB;CAChB,MAAM,gBAAgB,uBAAuB;CAC7C,MAAM,aAAgC;EACrC,QAAQ,QAAQ;EAChB,eAAe,QAAQ;EACvB,iBAAiB,cAAc;EAC/B,WAAW,QAAQ;EACnB,WAAW,QAAQ;CACpB;CACA,MAAM,YAAY,YAAY;EAAE,MAAM,QAAQ;EAAM;CAAW,CAAC;CAEhE,MAAM,YAAY,gBAAgB,QAAQ,eAAe,cAAc,SAAS;CAEhF,OAAO;EACN,UAAU;GACT,WAAW,QAAQ;GACnB,SAAS,QAAQ;GACjB,iBAAiB,cAAc;GAC/B;EACD;EACA;EACA;EACA,eAAe,QAAQ;EACvB,WAAW,QAAQ;CACpB;AACD;;AAGA,SAAgB,wBAAwB,SAA+B,KAAuB;CAC7F,OAAO,QAAQ,OAAO,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;AAC5D"}
1
+ {"version":3,"file":"session.js","names":[],"sources":["../../src/transport/session.ts"],"sourcesContent":["/**\n * The connect handshake, orchestrated for both sides. This is where the crypto\n * primitives (connect transcript signing + x25519 box) and the URI transport\n * come together into an actual dApp <-> wallet session.\n *\n * Flow:\n * dApp: createConnectRequest() -> show `uri` (link/QR), keep `pending`\n * wallet: parseConnectUri(uri) -> [approve in UI] -> approveConnect()\n * -> return `response` to the dApp\n * dApp: completeConnect(pending, response) -> EstablishedSession\n *\n * After that both sides hold the same `sharedKey` and exchange sealed envelopes\n * (see envelope.ts). The wallet signs the transcript binding origin + BOTH\n * session keys + challenge + requestId, so a captured proof can't be replayed\n * under substituted keys.\n */\n\nimport { toBase58 } from '@amadeus-protocol/sdk'\n\nimport { DEFAULT_BRIDGE_URL } from '../constants'\nimport { randomBytes, randomId } from '../bytes'\nimport { signConnect, verifyConnect, type ConnectTranscript } from '../crypto/connect'\nimport { deriveSharedKey, generateSessionKeypair, type SessionKeypair } from '../crypto/box'\nimport { WalletSdkError } from '../errors'\nimport { buildConnectUri, type ConnectRequestParams, type ConnectResponseParams } from './uri'\n\n// ── dApp side ───────────────────────────────────────────────────────────────\n\n/** State the dApp keeps locally between issuing a connect request and completing it. */\nexport interface PendingConnect {\n\trequestId: string\n\tchallenge: string\n\torigin: string\n\t/** The dApp's ephemeral session keypair (secret stays local). */\n\tdappKeypair: SessionKeypair\n\texp: number\n\tbridgeUrl?: string\n}\n\nexport interface EstablishedSession {\n\t/** The connected wallet address (Base58 public key). */\n\taddress: string\n\t/** 32-byte symmetric key for sealing/opening envelopes. Keep in memory only. */\n\tsharedKey: Uint8Array\n\t/** The wallet's session key — the peer's bridge client id to send frames to. */\n\twalletPublicKey: string\n\t/** This dApp's session key — its own bridge client id to listen on. */\n\tselfPublicKey: string\n\torigin: string\n\t/** Relay base URL for post-connect sealed messages, if provided. */\n\tbridgeUrl?: string\n}\n\n/** dApp: create a connect request. Returns the URI to display and the pending state to keep. */\nexport function createConnectRequest(options: {\n\torigin: string\n\tredirectLink?: string\n\tbridgeUrl?: string\n\tttlSeconds?: number\n\tnow?: number\n}): { uri: string; pending: PendingConnect } {\n\tconst dappKeypair = generateSessionKeypair()\n\tconst challenge = toBase58(randomBytes(16))\n\tconst requestId = randomId()\n\tconst nowSec = Math.floor((options.now ?? Date.now()) / 1000)\n\tconst exp = nowSec + (options.ttlSeconds ?? 120)\n\t// Fall back to the production relay when the dApp doesn't pin its own.\n\tconst bridgeUrl = options.bridgeUrl ?? DEFAULT_BRIDGE_URL\n\n\tconst params: ConnectRequestParams = {\n\t\torigin: options.origin,\n\t\tdappPublicKey: dappKeypair.publicKey,\n\t\tchallenge,\n\t\trequestId,\n\t\texp,\n\t\tredirectLink: options.redirectLink,\n\t\tbridgeUrl\n\t}\n\treturn {\n\t\turi: buildConnectUri(params),\n\t\tpending: {\n\t\t\trequestId,\n\t\t\tchallenge,\n\t\t\torigin: options.origin,\n\t\t\tdappKeypair,\n\t\t\texp,\n\t\t\tbridgeUrl\n\t\t}\n\t}\n}\n\n/**\n * dApp: verify the wallet's connect response and establish the session. Throws\n * `INVALID_ARGUMENT` if the response is for a different request, or\n * `BAD_SIGNATURE` if the connect proof does not verify against the transcript.\n */\nexport function completeConnect(\n\tpending: PendingConnect,\n\tresponse: ConnectResponseParams\n): EstablishedSession {\n\tif (response.requestId !== pending.requestId) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'response does not match the pending request')\n\t}\n\tconst transcript: ConnectTranscript = {\n\t\torigin: pending.origin,\n\t\tdappPublicKey: pending.dappKeypair.publicKey,\n\t\twalletPublicKey: response.walletPublicKey,\n\t\tchallenge: pending.challenge,\n\t\trequestId: pending.requestId\n\t}\n\tif (!verifyConnect({ address: response.address, transcript, signature: response.signature })) {\n\t\tthrow new WalletSdkError('BAD_SIGNATURE', 'connect proof failed verification')\n\t}\n\t// deriveSharedKey validates the wallet's session key (fails closed on a bad point).\n\tconst sharedKey = deriveSharedKey(response.walletPublicKey, pending.dappKeypair.secretKey)\n\treturn {\n\t\taddress: response.address,\n\t\tsharedKey,\n\t\twalletPublicKey: response.walletPublicKey,\n\t\tselfPublicKey: pending.dappKeypair.publicKey,\n\t\torigin: pending.origin,\n\t\tbridgeUrl: pending.bridgeUrl\n\t}\n}\n\n// ── wallet side ───────────────────────────────────────────────────────────────\n\nexport interface WalletSession {\n\t/** The response to hand back to the dApp (via callback URI or bridge frame). */\n\tresponse: ConnectResponseParams\n\t/** 32-byte symmetric key for sealing/opening envelopes. Keep in memory only. */\n\tsharedKey: Uint8Array\n\t/** The wallet's ephemeral session keypair for this dApp (its own bridge client id). */\n\twalletKeypair: SessionKeypair\n\t/** The dApp's session key — the peer's bridge client id to send frames to. */\n\tpeerPublicKey: string\n\t/** Relay base URL for post-connect sealed messages, if the dApp supplied one. */\n\tbridgeUrl?: string\n}\n\n/**\n * Wallet: approve a connect request and produce the signed response + session.\n * Call this ONLY AFTER the user has approved in the UI and the request's expiry\n * has been checked. `address` is the account that will be bound to this session\n * (bind to a specific account, not the live \"active\" one).\n */\nexport function approveConnect(\n\trequest: ConnectRequestParams,\n\toptions: { seed: string; address: string }\n): WalletSession {\n\tconst walletKeypair = generateSessionKeypair()\n\tconst transcript: ConnectTranscript = {\n\t\torigin: request.origin,\n\t\tdappPublicKey: request.dappPublicKey,\n\t\twalletPublicKey: walletKeypair.publicKey,\n\t\tchallenge: request.challenge,\n\t\trequestId: request.requestId\n\t}\n\tconst signature = signConnect({ seed: options.seed, transcript })\n\t// deriveSharedKey validates the dApp's session key (fails closed on a bad point).\n\tconst sharedKey = deriveSharedKey(request.dappPublicKey, walletKeypair.secretKey)\n\n\treturn {\n\t\tresponse: {\n\t\t\trequestId: request.requestId,\n\t\t\taddress: options.address,\n\t\t\twalletPublicKey: walletKeypair.publicKey,\n\t\t\tsignature\n\t\t},\n\t\tsharedKey,\n\t\twalletKeypair,\n\t\tpeerPublicKey: request.dappPublicKey,\n\t\tbridgeUrl: request.bridgeUrl\n\t}\n}\n\n/** Whether a parsed connect request has expired (wallet should reject/re-park). */\nexport function isConnectRequestExpired(request: ConnectRequestParams, now?: number): boolean {\n\treturn request.exp <= Math.floor((now ?? Date.now()) / 1000)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,qBAAqB,SAMQ;CAC5C,MAAM,cAAc,uBAAuB;CAC3C,MAAM,YAAY,SAAS,YAAY,EAAE,CAAC;CAC1C,MAAM,YAAY,SAAS;CAE3B,MAAM,MADS,KAAK,OAAO,QAAQ,OAAO,KAAK,IAAI,KAAK,GACvC,KAAK,QAAQ,cAAc;CAE5C,MAAM,YAAY,QAAQ,aAAA;CAE1B,MAAM,SAA+B;EACpC,QAAQ,QAAQ;EAChB,eAAe,YAAY;EAC3B;EACA;EACA;EACA,cAAc,QAAQ;EACtB;CACD;CACA,OAAO;EACN,KAAK,gBAAgB,MAAM;EAC3B,SAAS;GACR;GACA;GACA,QAAQ,QAAQ;GAChB;GACA;GACA;EACD;CACD;AACD;;;;;;AAOA,SAAgB,gBACf,SACA,UACqB;CACrB,IAAI,SAAS,cAAc,QAAQ,WAClC,MAAM,IAAI,eAAe,oBAAoB,6CAA6C;CAE3F,MAAM,aAAgC;EACrC,QAAQ,QAAQ;EAChB,eAAe,QAAQ,YAAY;EACnC,iBAAiB,SAAS;EAC1B,WAAW,QAAQ;EACnB,WAAW,QAAQ;CACpB;CACA,IAAI,CAAC,cAAc;EAAE,SAAS,SAAS;EAAS;EAAY,WAAW,SAAS;CAAU,CAAC,GAC1F,MAAM,IAAI,eAAe,iBAAiB,mCAAmC;CAG9E,MAAM,YAAY,gBAAgB,SAAS,iBAAiB,QAAQ,YAAY,SAAS;CACzF,OAAO;EACN,SAAS,SAAS;EAClB;EACA,iBAAiB,SAAS;EAC1B,eAAe,QAAQ,YAAY;EACnC,QAAQ,QAAQ;EAChB,WAAW,QAAQ;CACpB;AACD;;;;;;;AAuBA,SAAgB,eACf,SACA,SACgB;CAChB,MAAM,gBAAgB,uBAAuB;CAC7C,MAAM,aAAgC;EACrC,QAAQ,QAAQ;EAChB,eAAe,QAAQ;EACvB,iBAAiB,cAAc;EAC/B,WAAW,QAAQ;EACnB,WAAW,QAAQ;CACpB;CACA,MAAM,YAAY,YAAY;EAAE,MAAM,QAAQ;EAAM;CAAW,CAAC;CAEhE,MAAM,YAAY,gBAAgB,QAAQ,eAAe,cAAc,SAAS;CAEhF,OAAO;EACN,UAAU;GACT,WAAW,QAAQ;GACnB,SAAS,QAAQ;GACjB,iBAAiB,cAAc;GAC/B;EACD;EACA;EACA;EACA,eAAe,QAAQ;EACvB,WAAW,QAAQ;CACpB;AACD;;AAGA,SAAgB,wBAAwB,SAA+B,KAAuB;CAC7F,OAAO,QAAQ,OAAO,KAAK,OAAO,OAAO,KAAK,IAAI,KAAK,GAAI;AAC5D"}
@@ -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,13 +1,4 @@
1
- //#region src/tx.d.ts
2
- /**
3
- * Transaction signing + submission.
4
- *
5
- * Signing reuses `@amadeus-protocol/sdk`'s `TransactionBuilder` verbatim (so the
6
- * packed bytes are identical to what the extension produces today) and layers on
7
- * the two behaviors the wallet's sign handler applies: restore JSON-transported
8
- * binary args, and convert a `Coin.transfer` Base58 recipient to raw bytes.
9
- * The wallet signs only; the caller submits the returned `txPacked` to a node.
10
- */
1
+ import { NetworkType } from "@amadeus-protocol/sdk";
11
2
  interface SignTransactionParams {
12
3
  /** Base58 wallet seed (private key). */
13
4
  seed: string;
@@ -16,6 +7,8 @@ interface SignTransactionParams {
16
7
  /** Args may contain tagged binary values (see `encodeBinaryValues`). */
17
8
  args: unknown[];
18
9
  description?: string;
10
+ /** Network whose signing DST to bind to. Defaults to mainnet. */
11
+ network?: NetworkType;
19
12
  }
20
13
  interface SignedTransaction {
21
14
  /** Base58 transaction hash. */
@@ -37,6 +30,5 @@ interface SubmitTransactionOptions {
37
30
  * dApps do today. Returns the parsed JSON body when possible, else raw text.
38
31
  */
39
32
  declare function submitTransaction(txPacked: number[] | Uint8Array, options: SubmitTransactionOptions): Promise<unknown>;
40
- //#endregion
41
33
  export { SignTransactionParams, SignedTransaction, SubmitTransactionOptions, signTransaction, submitTransaction };
42
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":";;;;;;;;;;UAeiB;;EAEhB;EACA;EACA;;EAEA;EACA;;UAGgB;;EAEhB;;EAEA;;iBAGe,gBAAgB,QAAQ,wBAAwB;UAwB/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,25 +1,29 @@
1
1
  import { WalletSdkError } from "./errors.js";
2
2
  import { decodeBinaryValues } from "./binary.js";
3
- import { TransactionBuilder, fromBase58 } from "@amadeus-protocol/sdk";
4
- //#region src/tx.ts
3
+ import { fromBase58, signContractCall } from "@amadeus-protocol/sdk";
4
+ // src/tx.ts
5
5
  /**
6
6
  * Transaction signing + submission.
7
7
  *
8
- * Signing reuses `@amadeus-protocol/sdk`'s `TransactionBuilder` verbatim (so the
9
- * packed bytes are identical to what the extension produces today) and layers on
10
- * the two behaviors the wallet's sign handler applies: restore JSON-transported
11
- * binary args, and convert a `Coin.transfer` Base58 recipient to raw bytes.
12
- * The wallet signs only; the caller submits the returned `txPacked` to a node.
8
+ * Signing delegates to `@amadeus-protocol/sdk`'s `signContractCall` (so the packed
9
+ * bytes are identical to what the extension produces) and layers on the two
10
+ * behaviors the wallet's sign handler applies: restore JSON-transported binary
11
+ * args, and convert a `Coin.transfer` Base58 recipient to raw bytes. The signature
12
+ * is bound to the given network's DST so a testnet tx can't be replayed on mainnet
13
+ * (defaults to mainnet). The wallet signs only; the caller submits `txPacked`.
13
14
  */
14
15
  function signTransaction(params) {
15
- const builder = new TransactionBuilder(params.seed);
16
16
  let processedArgs = decodeBinaryValues(params.args);
17
17
  if (params.contract === "Coin" && params.method === "transfer" && typeof processedArgs[0] === "string") processedArgs = [
18
18
  fromBase58(processedArgs[0]),
19
19
  processedArgs[1],
20
20
  processedArgs[2]
21
21
  ];
22
- const { txHash, txPacked } = builder.buildAndSign(params.contract, params.method, processedArgs);
22
+ const { txHash, txPacked } = signContractCall(params.seed, {
23
+ contract: params.contract,
24
+ method: params.method,
25
+ args: processedArgs
26
+ }, params.network);
23
27
  return {
24
28
  txHash,
25
29
  txPacked: Array.from(txPacked)
@@ -55,7 +59,6 @@ async function submitTransaction(txPacked, options) {
55
59
  clearTimeout(timer);
56
60
  }
57
61
  }
58
- //#endregion
59
62
  export { signTransaction, submitTransaction };
60
63
 
61
64
  //# sourceMappingURL=tx.js.map
package/dist/tx.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tx.js","names":[],"sources":["../src/tx.ts"],"sourcesContent":["/**\n * Transaction signing + submission.\n *\n * Signing reuses `@amadeus-protocol/sdk`'s `TransactionBuilder` verbatim (so the\n * packed bytes are identical to what the extension produces today) and layers on\n * the two behaviors the wallet's sign handler applies: restore JSON-transported\n * binary args, and convert a `Coin.transfer` Base58 recipient to raw bytes.\n * The wallet signs only; the caller submits the returned `txPacked` to a node.\n */\n\nimport { fromBase58, type SerializableValue, TransactionBuilder } from '@amadeus-protocol/sdk'\n\nimport { decodeBinaryValues } from './binary'\nimport { WalletSdkError } from './errors'\n\nexport interface SignTransactionParams {\n\t/** Base58 wallet seed (private key). */\n\tseed: string\n\tcontract: string\n\tmethod: string\n\t/** Args may contain tagged binary values (see `encodeBinaryValues`). */\n\targs: unknown[]\n\tdescription?: string\n}\n\nexport interface SignedTransaction {\n\t/** Base58 transaction hash. */\n\ttxHash: string\n\t/** Packed transaction bytes as a plain number[] — ready to POST to a node. */\n\ttxPacked: number[]\n}\n\nexport function signTransaction(params: SignTransactionParams): SignedTransaction {\n\tconst builder = new TransactionBuilder(params.seed)\n\n\t// Restore any binary args that were wrapped for a JSON/text transport.\n\tlet processedArgs = decodeBinaryValues(params.args) as unknown[]\n\n\t// Coin.transfer's recipient (arg 0) is a Base58 address on the wire but must\n\t// be raw bytes for the SDK to encode it as BYTES. Matches the extension.\n\tif (\n\t\tparams.contract === 'Coin' &&\n\t\tparams.method === 'transfer' &&\n\t\ttypeof processedArgs[0] === 'string'\n\t) {\n\t\tprocessedArgs = [fromBase58(processedArgs[0]), processedArgs[1], processedArgs[2]]\n\t}\n\n\tconst { txHash, txPacked } = builder.buildAndSign(\n\t\tparams.contract,\n\t\tparams.method,\n\t\tprocessedArgs as SerializableValue[]\n\t)\n\treturn { txHash, txPacked: Array.from(txPacked) }\n}\n\nexport interface SubmitTransactionOptions {\n\t/** Base URL of the node API, e.g. \"https://mainnet-rpc.ama.one/api\". */\n\tnodeUrl: string\n\t/** Wait for inclusion (`/tx/submit_and_wait`) vs fire-and-forget (`/tx/submit`). */\n\twait?: boolean\n\t/** Abort the request after this many ms. */\n\ttimeoutMs?: number\n}\n\n/**\n * Submit packed transaction bytes to a node as an octet-stream, the way the\n * dApps do today. Returns the parsed JSON body when possible, else raw text.\n */\nexport async function submitTransaction(\n\ttxPacked: number[] | Uint8Array,\n\toptions: SubmitTransactionOptions\n): Promise<unknown> {\n\t// nodeUrl is trusted config, but guard the scheme so a stray file:// or other\n\t// non-http target can never be fetched.\n\tif (!/^https?:\\/\\//.test(options.nodeUrl)) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'nodeUrl must be an http(s) URL')\n\t}\n\n\tconst bytes = txPacked instanceof Uint8Array ? txPacked : Uint8Array.from(txPacked)\n\t// Hand fetch a standalone ArrayBuffer — a clean BodyInit across DOM lib\n\t// versions and RN, and it never carries a shared/offset backing buffer.\n\tconst body = bytes.buffer.slice(\n\t\tbytes.byteOffset,\n\t\tbytes.byteOffset + bytes.byteLength\n\t) as ArrayBuffer\n\tconst path = options.wait ? '/tx/submit_and_wait' : '/tx/submit'\n\tconst url = `${options.nodeUrl.replace(/\\/$/, '')}${path}`\n\n\t// Always arm a timeout so a hung node can't block the caller forever.\n\tconst controller = new AbortController()\n\tconst timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 30_000)\n\n\ttry {\n\t\tconst res = await fetch(url, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/octet-stream' },\n\t\t\tbody,\n\t\t\tsignal: controller.signal\n\t\t})\n\t\tconst text = await res.text()\n\t\tif (!res.ok) {\n\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', `node returned ${res.status}: ${text}`)\n\t\t}\n\t\ttry {\n\t\t\treturn JSON.parse(text)\n\t\t} catch {\n\t\t\treturn text\n\t\t}\n\t} finally {\n\t\tclearTimeout(timer)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;AAgCA,SAAgB,gBAAgB,QAAkD;CACjF,MAAM,UAAU,IAAI,mBAAmB,OAAO,IAAI;CAGlD,IAAI,gBAAgB,mBAAmB,OAAO,IAAI;CAIlD,IACC,OAAO,aAAa,UACpB,OAAO,WAAW,cAClB,OAAO,cAAc,OAAO,UAE5B,gBAAgB;EAAC,WAAW,cAAc,EAAE;EAAG,cAAc;EAAI,cAAc;CAAE;CAGlF,MAAM,EAAE,QAAQ,aAAa,QAAQ,aACpC,OAAO,UACP,OAAO,QACP,aACD;CACA,OAAO;EAAE;EAAQ,UAAU,MAAM,KAAK,QAAQ;CAAE;AACjD;;;;;AAeA,eAAsB,kBACrB,UACA,SACmB;CAGnB,IAAI,CAAC,eAAe,KAAK,QAAQ,OAAO,GACvC,MAAM,IAAI,eAAe,oBAAoB,gCAAgC;CAG9E,MAAM,QAAQ,oBAAoB,aAAa,WAAW,WAAW,KAAK,QAAQ;CAGlF,MAAM,OAAO,MAAM,OAAO,MACzB,MAAM,YACN,MAAM,aAAa,MAAM,UAC1B;CACA,MAAM,OAAO,QAAQ,OAAO,wBAAwB;CACpD,MAAM,MAAM,GAAG,QAAQ,QAAQ,QAAQ,OAAO,EAAE,IAAI;CAGpD,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,iBAAiB,WAAW,MAAM,GAAG,QAAQ,aAAa,GAAM;CAE9E,IAAI;EACH,MAAM,MAAM,MAAM,MAAM,KAAK;GAC5B,QAAQ;GACR,SAAS,EAAE,gBAAgB,2BAA2B;GACtD;GACA,QAAQ,WAAW;EACpB,CAAC;EACD,MAAM,OAAO,MAAM,IAAI,KAAK;EAC5B,IAAI,CAAC,IAAI,IACR,MAAM,IAAI,eAAe,iBAAiB,iBAAiB,IAAI,OAAO,IAAI,MAAM;EAEjF,IAAI;GACH,OAAO,KAAK,MAAM,IAAI;EACvB,QAAQ;GACP,OAAO;EACR;CACD,UAAU;EACT,aAAa,KAAK;CACnB;AACD"}
1
+ {"version":3,"file":"tx.js","names":[],"sources":["../src/tx.ts"],"sourcesContent":["/**\n * Transaction signing + submission.\n *\n * Signing delegates to `@amadeus-protocol/sdk`'s `signContractCall` (so the packed\n * bytes are identical to what the extension produces) and layers on the two\n * behaviors the wallet's sign handler applies: restore JSON-transported binary\n * args, and convert a `Coin.transfer` Base58 recipient to raw bytes. The signature\n * is bound to the given network's DST so a testnet tx can't be replayed on mainnet\n * (defaults to mainnet). The wallet signs only; the caller submits `txPacked`.\n */\n\nimport {\n\tfromBase58,\n\ttype NetworkType,\n\ttype SerializableValue,\n\tsignContractCall\n} from '@amadeus-protocol/sdk'\n\nimport { decodeBinaryValues } from './binary'\nimport { WalletSdkError } from './errors'\n\nexport interface SignTransactionParams {\n\t/** Base58 wallet seed (private key). */\n\tseed: string\n\tcontract: string\n\tmethod: string\n\t/** Args may contain tagged binary values (see `encodeBinaryValues`). */\n\targs: unknown[]\n\tdescription?: string\n\t/** Network whose signing DST to bind to. Defaults to mainnet. */\n\tnetwork?: NetworkType\n}\n\nexport interface SignedTransaction {\n\t/** Base58 transaction hash. */\n\ttxHash: string\n\t/** Packed transaction bytes as a plain number[] — ready to POST to a node. */\n\ttxPacked: number[]\n}\n\nexport function signTransaction(params: SignTransactionParams): SignedTransaction {\n\t// Restore any binary args that were wrapped for a JSON/text transport.\n\tlet processedArgs = decodeBinaryValues(params.args) as unknown[]\n\n\t// Coin.transfer's recipient (arg 0) is a Base58 address on the wire but must\n\t// be raw bytes for the SDK to encode it as BYTES. Matches the extension.\n\tif (\n\t\tparams.contract === 'Coin' &&\n\t\tparams.method === 'transfer' &&\n\t\ttypeof processedArgs[0] === 'string'\n\t) {\n\t\tprocessedArgs = [fromBase58(processedArgs[0]), processedArgs[1], processedArgs[2]]\n\t}\n\n\tconst { txHash, txPacked } = signContractCall(\n\t\tparams.seed,\n\t\t{\n\t\t\tcontract: params.contract,\n\t\t\tmethod: params.method,\n\t\t\targs: processedArgs as SerializableValue[]\n\t\t},\n\t\tparams.network\n\t)\n\treturn { txHash, txPacked: Array.from(txPacked) }\n}\n\nexport interface SubmitTransactionOptions {\n\t/** Base URL of the node API, e.g. \"https://mainnet-rpc.ama.one/api\". */\n\tnodeUrl: string\n\t/** Wait for inclusion (`/tx/submit_and_wait`) vs fire-and-forget (`/tx/submit`). */\n\twait?: boolean\n\t/** Abort the request after this many ms. */\n\ttimeoutMs?: number\n}\n\n/**\n * Submit packed transaction bytes to a node as an octet-stream, the way the\n * dApps do today. Returns the parsed JSON body when possible, else raw text.\n */\nexport async function submitTransaction(\n\ttxPacked: number[] | Uint8Array,\n\toptions: SubmitTransactionOptions\n): Promise<unknown> {\n\t// nodeUrl is trusted config, but guard the scheme so a stray file:// or other\n\t// non-http target can never be fetched.\n\tif (!/^https?:\\/\\//.test(options.nodeUrl)) {\n\t\tthrow new WalletSdkError('INVALID_ARGUMENT', 'nodeUrl must be an http(s) URL')\n\t}\n\n\tconst bytes = txPacked instanceof Uint8Array ? txPacked : Uint8Array.from(txPacked)\n\t// Hand fetch a standalone ArrayBuffer — a clean BodyInit across DOM lib\n\t// versions and RN, and it never carries a shared/offset backing buffer.\n\tconst body = bytes.buffer.slice(\n\t\tbytes.byteOffset,\n\t\tbytes.byteOffset + bytes.byteLength\n\t) as ArrayBuffer\n\tconst path = options.wait ? '/tx/submit_and_wait' : '/tx/submit'\n\tconst url = `${options.nodeUrl.replace(/\\/$/, '')}${path}`\n\n\t// Always arm a timeout so a hung node can't block the caller forever.\n\tconst controller = new AbortController()\n\tconst timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 30_000)\n\n\ttry {\n\t\tconst res = await fetch(url, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: { 'Content-Type': 'application/octet-stream' },\n\t\t\tbody,\n\t\t\tsignal: controller.signal\n\t\t})\n\t\tconst text = await res.text()\n\t\tif (!res.ok) {\n\t\t\tthrow new WalletSdkError('SUBMIT_FAILED', `node returned ${res.status}: ${text}`)\n\t\t}\n\t\ttry {\n\t\t\treturn JSON.parse(text)\n\t\t} catch {\n\t\t\treturn text\n\t\t}\n\t} finally {\n\t\tclearTimeout(timer)\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAwCA,SAAgB,gBAAgB,QAAkD;CAEjF,IAAI,gBAAgB,mBAAmB,OAAO,IAAI;CAIlD,IACC,OAAO,aAAa,UACpB,OAAO,WAAW,cAClB,OAAO,cAAc,OAAO,UAE5B,gBAAgB;EAAC,WAAW,cAAc,EAAE;EAAG,cAAc;EAAI,cAAc;CAAE;CAGlF,MAAM,EAAE,QAAQ,aAAa,iBAC5B,OAAO,MACP;EACC,UAAU,OAAO;EACjB,QAAQ,OAAO;EACf,MAAM;CACP,GACA,OAAO,OACR;CACA,OAAO;EAAE;EAAQ,UAAU,MAAM,KAAK,QAAQ;CAAE;AACjD;;;;;AAeA,eAAsB,kBACrB,UACA,SACmB;CAGnB,IAAI,CAAC,eAAe,KAAK,QAAQ,OAAO,GACvC,MAAM,IAAI,eAAe,oBAAoB,gCAAgC;CAG9E,MAAM,QAAQ,oBAAoB,aAAa,WAAW,WAAW,KAAK,QAAQ;CAGlF,MAAM,OAAO,MAAM,OAAO,MACzB,MAAM,YACN,MAAM,aAAa,MAAM,UAC1B;CACA,MAAM,OAAO,QAAQ,OAAO,wBAAwB;CACpD,MAAM,MAAM,GAAG,QAAQ,QAAQ,QAAQ,OAAO,EAAE,IAAI;CAGpD,MAAM,aAAa,IAAI,gBAAgB;CACvC,MAAM,QAAQ,iBAAiB,WAAW,MAAM,GAAG,QAAQ,aAAa,GAAM;CAE9E,IAAI;EACH,MAAM,MAAM,MAAM,MAAM,KAAK;GAC5B,QAAQ;GACR,SAAS,EAAE,gBAAgB,2BAA2B;GACtD;GACA,QAAQ,WAAW;EACpB,CAAC;EACD,MAAM,OAAO,MAAM,IAAI,KAAK;EAC5B,IAAI,CAAC,IAAI,IACR,MAAM,IAAI,eAAe,iBAAiB,iBAAiB,IAAI,OAAO,IAAI,MAAM;EAEjF,IAAI;GACH,OAAO,KAAK,MAAM,IAAI;EACvB,QAAQ;GACP,OAAO;EACR;CACD,UAAU;EACT,aAAa,KAAK;CACnB;AACD"}
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 {
@@ -75,6 +74,5 @@ declare global {
75
74
  declare function getAmadeusProvider(): AmadeusProvider | null;
76
75
  /** Whether a genuine Amadeus provider is currently injected. */
77
76
  declare function isProviderAvailable(): boolean;
78
- //#endregion
79
77
  export { AmadeusEventPayloadMap, AmadeusNetwork, AmadeusProvider, AmadeusProviderEvent, GenerateApiKeyRequest, GenerateApiKeyResponse, SignTransactionRequest, SignTransactionResponse, getAmadeusProvider, isProviderAvailable };
80
78
  //# 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;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"}
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
@@ -1,10 +1,15 @@
1
1
  import { WalletRequest, WalletResponse } from "../transport/envelope.js";
2
- //#region src/wallet/handler.d.ts
2
+ import { NetworkType } from "@amadeus-protocol/sdk";
3
3
  interface WalletHandlerContext {
4
4
  /** Seed (private key) of the account bound to this session. */
5
5
  seed: string;
6
6
  /** Address (Base58 public key) of the bound account. */
7
7
  address: string;
8
+ /**
9
+ * Active network. Transactions are signed with this network's DST so a tx
10
+ * signed on one network can't be replayed on another. Defaults to mainnet.
11
+ */
12
+ network?: NetworkType;
8
13
  }
9
14
  /**
10
15
  * Service one approved request and return a response ready to seal. Never throws
@@ -13,6 +18,5 @@ interface WalletHandlerContext {
13
18
  * wallet runtime state), signalled with a distinct error the caller can branch on.
14
19
  */
15
20
  declare function handleRequest(request: WalletRequest, ctx: WalletHandlerContext): WalletResponse;
16
- //#endregion
17
21
  export { WalletHandlerContext, handleRequest };
18
22
  //# sourceMappingURL=handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handler.d.ts","names":[],"sources":["../../src/wallet/handler.ts"],"mappings":";;UAuBiB;;EAEhB;;EAEA;;;;;;;;iBAmBe,cAAc,SAAS,eAAe,KAAK,uBAAuB"}
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"}
@@ -4,17 +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
8
- /**
9
- * Wallet-side request dispatch. Once the mobile app has opened + guarded an
10
- * inbound request and the user has approved it, this turns the request into a
11
- * signed response by routing to the right primitive. Keeping it here means the
12
- * app's approval screen only has to call one function; the wallet and extension
13
- * share identical request semantics.
14
- *
15
- * IMPORTANT: call this only AFTER `guardRequest` (expiry + replay) has passed and
16
- * the user has approved. It signs with the bound account's seed.
17
- */
7
+ // src/wallet/handler.ts
18
8
  function ok(id, result) {
19
9
  return {
20
10
  v: 1,
@@ -51,7 +41,8 @@ function handleRequest(request, ctx) {
51
41
  contract: parsed.data.contract,
52
42
  method: parsed.data.method,
53
43
  args: parsed.data.args,
54
- description: parsed.data.description
44
+ description: parsed.data.description,
45
+ network: ctx.network
55
46
  });
56
47
  return ok(request.id, signed);
57
48
  }
@@ -82,7 +73,6 @@ function handleRequest(request, ctx) {
82
73
  return fail(request.id, error);
83
74
  }
84
75
  }
85
- //#endregion
86
76
  export { handleRequest };
87
77
 
88
78
  //# 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 { 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}\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})\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":";;;;;;;;;;;;;;;;;AA8BA,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;IAC1B,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` 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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amadeus-protocol/wallet-sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
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,
@@ -51,11 +51,11 @@
51
51
  "license": "MIT",
52
52
  "repository": {
53
53
  "type": "git",
54
- "url": "git+https://github.com/amadeusprotocol/amadeus-wallet-sdk.git"
54
+ "url": "git+https://github.com/TypeError86/amadeus-wallet-sdk.git"
55
55
  },
56
- "homepage": "https://github.com/amadeusprotocol/amadeus-wallet-sdk#readme",
56
+ "homepage": "https://github.com/TypeError86/amadeus-wallet-sdk#readme",
57
57
  "bugs": {
58
- "url": "https://github.com/amadeusprotocol/amadeus-wallet-sdk/issues"
58
+ "url": "https://github.com/TypeError86/amadeus-wallet-sdk/issues"
59
59
  },
60
60
  "publishConfig": {
61
61
  "access": "public"
@@ -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",