@amadeus-protocol/wallet-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/binary.d.ts +30 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +56 -0
- package/dist/binary.js.map +1 -0
- package/dist/bytes.d.ts +20 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/bytes.js +48 -0
- package/dist/bytes.js.map +1 -0
- package/dist/client/injected.d.ts +41 -0
- package/dist/client/injected.d.ts.map +1 -0
- package/dist/client/injected.js +87 -0
- package/dist/client/injected.js.map +1 -0
- package/dist/constants.d.ts +70 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +82 -0
- package/dist/constants.js.map +1 -0
- package/dist/crypto/apikey.d.ts +72 -0
- package/dist/crypto/apikey.d.ts.map +1 -0
- package/dist/crypto/apikey.js +109 -0
- package/dist/crypto/apikey.js.map +1 -0
- package/dist/crypto/bls.d.ts +31 -0
- package/dist/crypto/bls.d.ts.map +1 -0
- package/dist/crypto/bls.js +65 -0
- package/dist/crypto/bls.js.map +1 -0
- package/dist/crypto/box.d.ts +43 -0
- package/dist/crypto/box.d.ts.map +1 -0
- package/dist/crypto/box.js +82 -0
- package/dist/crypto/box.js.map +1 -0
- package/dist/crypto/connect.d.ts +59 -0
- package/dist/crypto/connect.d.ts.map +1 -0
- package/dist/crypto/connect.js +72 -0
- package/dist/crypto/connect.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +14 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/react/index.d.ts +20 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +95 -0
- package/dist/react/index.js.map +1 -0
- package/dist/schema.d.ts +63 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +52 -0
- package/dist/schema.js.map +1 -0
- package/dist/transport/bridge.d.ts +82 -0
- package/dist/transport/bridge.d.ts.map +1 -0
- package/dist/transport/bridge.js +125 -0
- package/dist/transport/bridge.js.map +1 -0
- package/dist/transport/envelope.d.ts +73 -0
- package/dist/transport/envelope.d.ts.map +1 -0
- package/dist/transport/envelope.js +123 -0
- package/dist/transport/envelope.js.map +1 -0
- package/dist/transport/session.d.ts +70 -0
- package/dist/transport/session.d.ts.map +1 -0
- package/dist/transport/session.js +119 -0
- package/dist/transport/session.js.map +1 -0
- package/dist/transport/uri.d.ts +49 -0
- package/dist/transport/uri.d.ts.map +1 -0
- package/dist/transport/uri.js +101 -0
- package/dist/transport/uri.js.map +1 -0
- package/dist/tx.d.ts +42 -0
- package/dist/tx.d.ts.map +1 -0
- package/dist/tx.js +61 -0
- package/dist/tx.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/wallet/handler.d.ts +18 -0
- package/dist/wallet/handler.d.ts.map +1 -0
- package/dist/wallet/handler.js +79 -0
- package/dist/wallet/handler.js.map +1 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @amadeus-protocol/wallet-sdk
|
|
2
|
+
|
|
3
|
+
One audited home for the Amadeus dApp ↔ wallet connection layer. The wallet
|
|
4
|
+
(mobile + extension) and every dApp import the **same** crypto and protocol code,
|
|
5
|
+
so the two sides can never drift — which is the entire point.
|
|
6
|
+
|
|
7
|
+
Built on top of [`@amadeus-protocol/sdk`](https://www.npmjs.com/package/@amadeus-protocol/sdk)
|
|
8
|
+
(key derivation, encoding, `TransactionBuilder`). This package adds only the
|
|
9
|
+
connection layer.
|
|
10
|
+
|
|
11
|
+
> **Status: v0.1 — crypto + protocol core.** Transports (deep link / QR / bridge)
|
|
12
|
+
> and React hooks are not in this release. See "Roadmap" below.
|
|
13
|
+
|
|
14
|
+
## What's in this release
|
|
15
|
+
|
|
16
|
+
| Area | Exports |
|
|
17
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
18
|
+
| **API-key tokens** | `generateApiKey`, `verifyApiKey`, `decodeApiKey` |
|
|
19
|
+
| **Transactions** | `signTransaction`, `submitTransaction` |
|
|
20
|
+
| **Connection auth** | `signConnect`, `verifyConnect`, `buildConnectTranscript` |
|
|
21
|
+
| **Session encryption** | `generateSessionKeypair`, `deriveSharedKey`, `seal`, `open` |
|
|
22
|
+
| **Provider contract** | `AmadeusProvider`, `getAmadeusProvider`, `isProviderAvailable`, event/response types |
|
|
23
|
+
| **Wire validation** | zod schemas: `signTransactionRequestSchema`, `generateApiKeyRequestSchema`, `connectTranscriptSchema`, `addressSchema`, `originSchema` |
|
|
24
|
+
| **Binary args** | `encodeBinaryValues`, `decodeBinaryValues`, `describeBinaryValues` |
|
|
25
|
+
| **Constants** | all DSTs, byte lengths, event names, `PROTOCOL_VERSION` |
|
|
26
|
+
|
|
27
|
+
## Why unify the API-key token first
|
|
28
|
+
|
|
29
|
+
It was hand-rolled in **three** places (the extension, `hub`, and `prime-hub`),
|
|
30
|
+
all of which must stay byte-identical to the `kbs.ama.one` backend. `generateApiKey`
|
|
31
|
+
here reproduces that exact token — `base58( json{aud,exp} ‖ pubkey48 ‖ sig96 )`
|
|
32
|
+
signed over `sha256(json ‖ pubkey)` under the `_APIKEY_` DST — and a test asserts
|
|
33
|
+
byte-for-byte equality with the original recipe. Consumers can now delete their copies.
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { generateApiKey, verifyApiKey } from '@amadeus-protocol/wallet-sdk'
|
|
37
|
+
|
|
38
|
+
const { apiKey } = generateApiKey({ seed, aud: 'amadeus', expIn: 7 * 24 * 3600 })
|
|
39
|
+
// ... later, on any verifier:
|
|
40
|
+
const result = verifyApiKey(apiKey, { aud: 'amadeus' })
|
|
41
|
+
if (result.valid) console.log(result.address)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Security notes
|
|
45
|
+
|
|
46
|
+
- **Distinct DSTs** (`_TX_`, `_APIKEY_`, `_CONNECT_`) make a signature from one
|
|
47
|
+
context cryptographically unusable in another.
|
|
48
|
+
- **Connect auth signs the full transcript** — origin + both session keys +
|
|
49
|
+
challenge + request id — not just the nonce, which closes the key-substitution
|
|
50
|
+
MITM.
|
|
51
|
+
- **No arbitrary message-signing oracle**: connection proof only ever signs a
|
|
52
|
+
structured, length-prefixed transcript.
|
|
53
|
+
- **Session box** uses x25519 + XChaCha20-Poly1305 via `@noble` (Hermes-safe; no
|
|
54
|
+
`tweetnacl` "no PRNG" issue) and fails closed on any tamper.
|
|
55
|
+
|
|
56
|
+
## Develop
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
bun install
|
|
60
|
+
bun run test # vitest
|
|
61
|
+
bun run typecheck
|
|
62
|
+
bun run build # tsdown -> dist/
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Roadmap
|
|
66
|
+
|
|
67
|
+
1. **Transports** — deep link / Universal Link ingress, QR pairing, and a
|
|
68
|
+
self-hosted encrypted bridge, all speaking one envelope.
|
|
69
|
+
2. **`/react`** — `WalletProvider` + `useWallet()` so dApps stop copy-pasting
|
|
70
|
+
provider glue (and the `amadeus#initialized` vs `amadeus-wallet#initialized`
|
|
71
|
+
bug gets fixed once).
|
|
72
|
+
3. **Adoption** — migrate the extension, `hub`, and `prime-hub` off their
|
|
73
|
+
hand-rolled crypto onto this package.
|
package/dist/binary.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/binary.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* JSON-safe encoding for binary values (typed arrays) that cross a text
|
|
4
|
+
* transport. Transaction args can contain raw bytes (e.g. a recipient pubkey);
|
|
5
|
+
* JSON.stringify would mangle a Uint8Array into `{"0":7,...}`, which the node
|
|
6
|
+
* then vecpack-encodes as a MAP instead of BYTES and rejects.
|
|
7
|
+
*
|
|
8
|
+
* Values are wrapped as `{ "__amadeusBytes__": "<base64>" }` before transport and
|
|
9
|
+
* restored to Uint8Array right before the SDK consumes them. The tag string and
|
|
10
|
+
* base64 payload are wire-compatible with the wallet extension's `utils/binary.ts`
|
|
11
|
+
* (only the base64 codec differs — we use the SDK's helpers so it works on Hermes,
|
|
12
|
+
* which has no `btoa`/`atob`).
|
|
13
|
+
*/
|
|
14
|
+
declare const BYTES_TAG = "__amadeusBytes__";
|
|
15
|
+
type TaggedBytes = {
|
|
16
|
+
[BYTES_TAG]: string;
|
|
17
|
+
};
|
|
18
|
+
declare function isTaggedBytes(value: unknown): value is TaggedBytes;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively replace binary values with a JSON-safe tagged envelope.
|
|
21
|
+
* Idempotent: already-tagged values pass through unchanged.
|
|
22
|
+
*/
|
|
23
|
+
declare function encodeBinaryValues(value: unknown): unknown;
|
|
24
|
+
/** Recursively restore tagged envelopes back into Uint8Array. */
|
|
25
|
+
declare function decodeBinaryValues(value: unknown): unknown;
|
|
26
|
+
/** Human-readable stand-in for tagged bytes when displaying args in an approval UI. */
|
|
27
|
+
declare function describeBinaryValues(value: unknown): unknown;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { BYTES_TAG, TaggedBytes, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes };
|
|
30
|
+
//# sourceMappingURL=binary.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/binary.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { base64ToUint8Array, uint8ArrayToBase64 } from "@amadeus-protocol/sdk";
|
|
2
|
+
//#region src/binary.ts
|
|
3
|
+
/**
|
|
4
|
+
* JSON-safe encoding for binary values (typed arrays) that cross a text
|
|
5
|
+
* transport. Transaction args can contain raw bytes (e.g. a recipient pubkey);
|
|
6
|
+
* JSON.stringify would mangle a Uint8Array into `{"0":7,...}`, which the node
|
|
7
|
+
* then vecpack-encodes as a MAP instead of BYTES and rejects.
|
|
8
|
+
*
|
|
9
|
+
* Values are wrapped as `{ "__amadeusBytes__": "<base64>" }` before transport and
|
|
10
|
+
* restored to Uint8Array right before the SDK consumes them. The tag string and
|
|
11
|
+
* base64 payload are wire-compatible with the wallet extension's `utils/binary.ts`
|
|
12
|
+
* (only the base64 codec differs — we use the SDK's helpers so it works on Hermes,
|
|
13
|
+
* which has no `btoa`/`atob`).
|
|
14
|
+
*/
|
|
15
|
+
const BYTES_TAG = "__amadeusBytes__";
|
|
16
|
+
/** Realm-safe detection of binary values (typed arrays, DataView, ArrayBuffer). */
|
|
17
|
+
function asBytes(value) {
|
|
18
|
+
if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
19
|
+
if (Object.prototype.toString.call(value) === "[object ArrayBuffer]") return new Uint8Array(value);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
function isTaggedBytes(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length === 1 && typeof value["__amadeusBytes__"] === "string";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Recursively replace binary values with a JSON-safe tagged envelope.
|
|
27
|
+
* Idempotent: already-tagged values pass through unchanged.
|
|
28
|
+
*/
|
|
29
|
+
function encodeBinaryValues(value) {
|
|
30
|
+
const bytes = asBytes(value);
|
|
31
|
+
if (bytes) return { [BYTES_TAG]: uint8ArrayToBase64(bytes) };
|
|
32
|
+
if (Array.isArray(value)) return value.map(encodeBinaryValues);
|
|
33
|
+
if (typeof value === "object" && value !== null) {
|
|
34
|
+
if (isTaggedBytes(value)) return value;
|
|
35
|
+
return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, encodeBinaryValues(entry)]));
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
/** Recursively restore tagged envelopes back into Uint8Array. */
|
|
40
|
+
function decodeBinaryValues(value) {
|
|
41
|
+
if (isTaggedBytes(value)) return base64ToUint8Array(value[BYTES_TAG]);
|
|
42
|
+
if (Array.isArray(value)) return value.map(decodeBinaryValues);
|
|
43
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, decodeBinaryValues(entry)]));
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
/** Human-readable stand-in for tagged bytes when displaying args in an approval UI. */
|
|
47
|
+
function describeBinaryValues(value) {
|
|
48
|
+
if (isTaggedBytes(value)) return `<bytes[${base64ToUint8Array(value[BYTES_TAG]).length}] base64:${value[BYTES_TAG]}>`;
|
|
49
|
+
if (Array.isArray(value)) return value.map(describeBinaryValues);
|
|
50
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, describeBinaryValues(entry)]));
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { BYTES_TAG, decodeBinaryValues, describeBinaryValues, encodeBinaryValues, isTaggedBytes };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=binary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary.js","names":[],"sources":["../src/binary.ts"],"sourcesContent":["/**\n * JSON-safe encoding for binary values (typed arrays) that cross a text\n * transport. Transaction args can contain raw bytes (e.g. a recipient pubkey);\n * JSON.stringify would mangle a Uint8Array into `{\"0\":7,...}`, which the node\n * then vecpack-encodes as a MAP instead of BYTES and rejects.\n *\n * Values are wrapped as `{ \"__amadeusBytes__\": \"<base64>\" }` before transport and\n * restored to Uint8Array right before the SDK consumes them. The tag string and\n * base64 payload are wire-compatible with the wallet extension's `utils/binary.ts`\n * (only the base64 codec differs — we use the SDK's helpers so it works on Hermes,\n * which has no `btoa`/`atob`).\n */\n\nimport { base64ToUint8Array, uint8ArrayToBase64 } from '@amadeus-protocol/sdk'\n\nexport const BYTES_TAG = '__amadeusBytes__'\n\nexport type TaggedBytes = { [BYTES_TAG]: string }\n\n/** Realm-safe detection of binary values (typed arrays, DataView, ArrayBuffer). */\nfunction asBytes(value: unknown): Uint8Array | null {\n\tif (ArrayBuffer.isView(value)) {\n\t\treturn new Uint8Array(value.buffer, value.byteOffset, value.byteLength)\n\t}\n\tif (Object.prototype.toString.call(value) === '[object ArrayBuffer]') {\n\t\treturn new Uint8Array(value as ArrayBuffer)\n\t}\n\treturn null\n}\n\nexport function isTaggedBytes(value: unknown): value is TaggedBytes {\n\treturn (\n\t\ttypeof value === 'object' &&\n\t\tvalue !== null &&\n\t\t!Array.isArray(value) &&\n\t\tObject.keys(value).length === 1 &&\n\t\ttypeof (value as Record<string, unknown>)[BYTES_TAG] === 'string'\n\t)\n}\n\n/**\n * Recursively replace binary values with a JSON-safe tagged envelope.\n * Idempotent: already-tagged values pass through unchanged.\n */\nexport function encodeBinaryValues(value: unknown): unknown {\n\tconst bytes = asBytes(value)\n\tif (bytes) {\n\t\treturn { [BYTES_TAG]: uint8ArrayToBase64(bytes) }\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(encodeBinaryValues)\n\t}\n\tif (typeof value === 'object' && value !== null) {\n\t\tif (isTaggedBytes(value)) return value\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value).map(([key, entry]) => [key, encodeBinaryValues(entry)])\n\t\t)\n\t}\n\treturn value\n}\n\n/** Recursively restore tagged envelopes back into Uint8Array. */\nexport function decodeBinaryValues(value: unknown): unknown {\n\tif (isTaggedBytes(value)) {\n\t\treturn base64ToUint8Array(value[BYTES_TAG])\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(decodeBinaryValues)\n\t}\n\tif (typeof value === 'object' && value !== null) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value).map(([key, entry]) => [key, decodeBinaryValues(entry)])\n\t\t)\n\t}\n\treturn value\n}\n\n/** Human-readable stand-in for tagged bytes when displaying args in an approval UI. */\nexport function describeBinaryValues(value: unknown): unknown {\n\tif (isTaggedBytes(value)) {\n\t\tconst bytes = base64ToUint8Array(value[BYTES_TAG])\n\t\treturn `<bytes[${bytes.length}] base64:${value[BYTES_TAG]}>`\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.map(describeBinaryValues)\n\t}\n\tif (typeof value === 'object' && value !== null) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries(value).map(([key, entry]) => [key, describeBinaryValues(entry)])\n\t\t)\n\t}\n\treturn value\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,MAAa,YAAY;;AAKzB,SAAS,QAAQ,OAAmC;CACnD,IAAI,YAAY,OAAO,KAAK,GAC3B,OAAO,IAAI,WAAW,MAAM,QAAQ,MAAM,YAAY,MAAM,UAAU;CAEvE,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,wBAC7C,OAAO,IAAI,WAAW,KAAoB;CAE3C,OAAO;AACR;AAEA,SAAgB,cAAc,OAAsC;CACnE,OACC,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAC9B,OAAQ,MAAA,wBAAiD;AAE3D;;;;;AAMA,SAAgB,mBAAmB,OAAyB;CAC3D,MAAM,QAAQ,QAAQ,KAAK;CAC3B,IAAI,OACH,OAAO,GAAG,YAAY,mBAAmB,KAAK,EAAE;CAEjD,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,IAAI,kBAAkB;CAEpC,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM;EAChD,IAAI,cAAc,KAAK,GAAG,OAAO;EACjC,OAAO,OAAO,YACb,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,mBAAmB,KAAK,CAAC,CAAC,CAC7E;CACD;CACA,OAAO;AACR;;AAGA,SAAgB,mBAAmB,OAAyB;CAC3D,IAAI,cAAc,KAAK,GACtB,OAAO,mBAAmB,MAAM,UAAU;CAE3C,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,IAAI,kBAAkB;CAEpC,IAAI,OAAO,UAAU,YAAY,UAAU,MAC1C,OAAO,OAAO,YACb,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,mBAAmB,KAAK,CAAC,CAAC,CAC7E;CAED,OAAO;AACR;;AAGA,SAAgB,qBAAqB,OAAyB;CAC7D,IAAI,cAAc,KAAK,GAEtB,OAAO,UADO,mBAAmB,MAAM,UAClB,CAAC,CAAC,OAAO,WAAW,MAAM,WAAW;CAE3D,IAAI,MAAM,QAAQ,KAAK,GACtB,OAAO,MAAM,IAAI,oBAAoB;CAEtC,IAAI,OAAO,UAAU,YAAY,UAAU,MAC1C,OAAO,OAAO,YACb,OAAO,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,qBAAqB,KAAK,CAAC,CAAC,CAC/E;CAED,OAAO;AACR"}
|
package/dist/bytes.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { concatBytes, randomBytes } from "@noble/hashes/utils";
|
|
2
|
+
//#region src/bytes.d.ts
|
|
3
|
+
declare const concatBytes$1: typeof concatBytes;
|
|
4
|
+
declare const randomBytes$1: typeof randomBytes;
|
|
5
|
+
/** A random hex id (default 16 bytes → 32 hex chars). Used for request ids. */
|
|
6
|
+
declare function randomId(byteLength?: number): string;
|
|
7
|
+
declare function utf8ToBytes(value: string): Uint8Array;
|
|
8
|
+
declare function bytesToUtf8(bytes: Uint8Array): string;
|
|
9
|
+
/** 4-byte big-endian length prefix, used to make concatenations unambiguous. */
|
|
10
|
+
declare function u32be(n: number): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Constant-time equality for two byte arrays (length is not secret). Exported
|
|
13
|
+
* for downstream consumers that need to compare secret-derived bytes. Note: the
|
|
14
|
+
* in-package verify paths do NOT hand-roll comparisons — the AEAD tag check
|
|
15
|
+
* (`box.open`) and BLS verification both rely on noble's constant-time primitives.
|
|
16
|
+
*/
|
|
17
|
+
declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { bytesToUtf8, concatBytes$1 as concatBytes, equalBytes, randomBytes$1 as randomBytes, randomId, u32be, utf8ToBytes };
|
|
20
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","names":[],"sources":["../src/bytes.ts"],"mappings":";;cAea,sBAAW;cACX,sBAAW;;iBAGR,SAAS;iBAIT,YAAY,gBAAgB;iBAI5B,YAAY,OAAO;;iBAKnB,MAAM,YAAY;;;;;;;iBAkBlB,WAAW,GAAG,YAAY,GAAG"}
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { bytesToHex, concatBytes, randomBytes } from "@noble/hashes/utils";
|
|
2
|
+
//#region src/bytes.ts
|
|
3
|
+
/**
|
|
4
|
+
* Small byte helpers, kept isomorphic (Node, browser, React Native/Hermes).
|
|
5
|
+
*
|
|
6
|
+
* We route randomness and concat through `@noble/hashes/utils` (which uses the
|
|
7
|
+
* platform CSPRNG via `crypto.getRandomValues`) rather than tweetnacl, which
|
|
8
|
+
* throws "no PRNG" under Hermes. UTF-8 uses the platform TextEncoder/Decoder,
|
|
9
|
+
* matching the byte output of the extension's `new TextEncoder().encode(...)`.
|
|
10
|
+
*/
|
|
11
|
+
const concatBytes$1 = concatBytes;
|
|
12
|
+
const randomBytes$1 = randomBytes;
|
|
13
|
+
/** A random hex id (default 16 bytes → 32 hex chars). Used for request ids. */
|
|
14
|
+
function randomId(byteLength = 16) {
|
|
15
|
+
return bytesToHex(randomBytes(byteLength));
|
|
16
|
+
}
|
|
17
|
+
function utf8ToBytes(value) {
|
|
18
|
+
return new TextEncoder().encode(value);
|
|
19
|
+
}
|
|
20
|
+
function bytesToUtf8(bytes) {
|
|
21
|
+
return new TextDecoder().decode(bytes);
|
|
22
|
+
}
|
|
23
|
+
/** 4-byte big-endian length prefix, used to make concatenations unambiguous. */
|
|
24
|
+
function u32be(n) {
|
|
25
|
+
if (!Number.isInteger(n) || n < 0 || n > 4294967295) throw new RangeError(`u32be out of range: ${n}`);
|
|
26
|
+
const out = /* @__PURE__ */ new Uint8Array(4);
|
|
27
|
+
out[0] = n >>> 24 & 255;
|
|
28
|
+
out[1] = n >>> 16 & 255;
|
|
29
|
+
out[2] = n >>> 8 & 255;
|
|
30
|
+
out[3] = n & 255;
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Constant-time equality for two byte arrays (length is not secret). Exported
|
|
35
|
+
* for downstream consumers that need to compare secret-derived bytes. Note: the
|
|
36
|
+
* in-package verify paths do NOT hand-roll comparisons — the AEAD tag check
|
|
37
|
+
* (`box.open`) and BLS verification both rely on noble's constant-time primitives.
|
|
38
|
+
*/
|
|
39
|
+
function equalBytes(a, b) {
|
|
40
|
+
if (a.length !== b.length) return false;
|
|
41
|
+
let diff = 0;
|
|
42
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
43
|
+
return diff === 0;
|
|
44
|
+
}
|
|
45
|
+
//#endregion
|
|
46
|
+
export { bytesToUtf8, concatBytes$1 as concatBytes, equalBytes, randomBytes$1 as randomBytes, randomId, u32be, utf8ToBytes };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","names":["concatBytes","nobleConcat","randomBytes","nobleRandom"],"sources":["../src/bytes.ts"],"sourcesContent":["/**\n * Small byte helpers, kept isomorphic (Node, browser, React Native/Hermes).\n *\n * We route randomness and concat through `@noble/hashes/utils` (which uses the\n * platform CSPRNG via `crypto.getRandomValues`) rather than tweetnacl, which\n * throws \"no PRNG\" under Hermes. UTF-8 uses the platform TextEncoder/Decoder,\n * matching the byte output of the extension's `new TextEncoder().encode(...)`.\n */\n\nimport {\n\tbytesToHex,\n\tconcatBytes as nobleConcat,\n\trandomBytes as nobleRandom\n} from '@noble/hashes/utils'\n\nexport const concatBytes = nobleConcat\nexport const randomBytes = nobleRandom\n\n/** A random hex id (default 16 bytes → 32 hex chars). Used for request ids. */\nexport function randomId(byteLength = 16): string {\n\treturn bytesToHex(nobleRandom(byteLength))\n}\n\nexport function utf8ToBytes(value: string): Uint8Array {\n\treturn new TextEncoder().encode(value)\n}\n\nexport function bytesToUtf8(bytes: Uint8Array): string {\n\treturn new TextDecoder().decode(bytes)\n}\n\n/** 4-byte big-endian length prefix, used to make concatenations unambiguous. */\nexport function u32be(n: number): Uint8Array {\n\tif (!Number.isInteger(n) || n < 0 || n > 0xffffffff) {\n\t\tthrow new RangeError(`u32be out of range: ${n}`)\n\t}\n\tconst out = new Uint8Array(4)\n\tout[0] = (n >>> 24) & 0xff\n\tout[1] = (n >>> 16) & 0xff\n\tout[2] = (n >>> 8) & 0xff\n\tout[3] = n & 0xff\n\treturn out\n}\n\n/**\n * Constant-time equality for two byte arrays (length is not secret). Exported\n * for downstream consumers that need to compare secret-derived bytes. Note: the\n * in-package verify paths do NOT hand-roll comparisons — the AEAD tag check\n * (`box.open`) and BLS verification both rely on noble's constant-time primitives.\n */\nexport function equalBytes(a: Uint8Array, b: Uint8Array): boolean {\n\tif (a.length !== b.length) return false\n\tlet diff = 0\n\tfor (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i]\n\treturn diff === 0\n}\n"],"mappings":";;;;;;;;;;AAeA,MAAaA,gBAAcC;AAC3B,MAAaC,gBAAcC;;AAG3B,SAAgB,SAAS,aAAa,IAAY;CACjD,OAAO,WAAWA,YAAY,UAAU,CAAC;AAC1C;AAEA,SAAgB,YAAY,OAA2B;CACtD,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK;AACtC;AAEA,SAAgB,YAAY,OAA2B;CACtD,OAAO,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK;AACtC;;AAGA,SAAgB,MAAM,GAAuB;CAC5C,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,KAAK,IAAI,YACxC,MAAM,IAAI,WAAW,uBAAuB,GAAG;CAEhD,MAAM,sBAAM,IAAI,WAAW,CAAC;CAC5B,IAAI,KAAM,MAAM,KAAM;CACtB,IAAI,KAAM,MAAM,KAAM;CACtB,IAAI,KAAM,MAAM,IAAK;CACrB,IAAI,KAAK,IAAI;CACb,OAAO;AACR;;;;;;;AAQA,SAAgB,WAAW,GAAe,GAAwB;CACjE,IAAI,EAAE,WAAW,EAAE,QAAQ,OAAO;CAClC,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK,QAAQ,EAAE,KAAK,EAAE;CACpD,OAAO,SAAS;AACjB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AmadeusEventPayloadMap, AmadeusProvider, AmadeusProviderEvent, SignTransactionRequest, SignTransactionResponse } from "../types.js";
|
|
2
|
+
//#region src/client/injected.d.ts
|
|
3
|
+
/** Where a cached api-key lives. Default is in-memory; dApps can pass localStorage-backed. */
|
|
4
|
+
interface ApiKeyStore {
|
|
5
|
+
get(): string | null;
|
|
6
|
+
set(apiKey: string): void;
|
|
7
|
+
}
|
|
8
|
+
interface WalletClient {
|
|
9
|
+
isAvailable(): boolean;
|
|
10
|
+
getProvider(): AmadeusProvider | null;
|
|
11
|
+
/** Prompt connection; resolves to the connected account (Base58 address). */
|
|
12
|
+
connect(): Promise<string>;
|
|
13
|
+
getAccount(): Promise<string | null>;
|
|
14
|
+
getNetwork(): Promise<string>;
|
|
15
|
+
signTransaction(request: SignTransactionRequest): Promise<SignTransactionResponse>;
|
|
16
|
+
/** Sign then submit the packed bytes to a node; resolves to the tx hash + node reply. */
|
|
17
|
+
signAndSubmit(request: SignTransactionRequest, options: {
|
|
18
|
+
nodeUrl: string;
|
|
19
|
+
wait?: boolean;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
txHash: string;
|
|
22
|
+
submitted: unknown;
|
|
23
|
+
}>;
|
|
24
|
+
/** Return a valid cached api-key, minting (and caching) a fresh one if needed. Coalesces concurrent calls. */
|
|
25
|
+
ensureApiKey(options: {
|
|
26
|
+
aud: string;
|
|
27
|
+
expIn: number;
|
|
28
|
+
store?: ApiKeyStore;
|
|
29
|
+
leewaySeconds?: number;
|
|
30
|
+
}): Promise<string>;
|
|
31
|
+
on<E extends AmadeusProviderEvent>(event: E, cb: (data: AmadeusEventPayloadMap[E]) => void): void;
|
|
32
|
+
off<E extends AmadeusProviderEvent>(event: E, cb: (data: AmadeusEventPayloadMap[E]) => void): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Create a client bound to the injected provider. Pass `providerOverride` to
|
|
36
|
+
* inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.
|
|
37
|
+
*/
|
|
38
|
+
declare function createInjectedWalletClient(providerOverride?: AmadeusProvider): WalletClient;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { ApiKeyStore, WalletClient, createInjectedWalletClient };
|
|
41
|
+
//# sourceMappingURL=injected.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { WalletSdkError } from "../errors.js";
|
|
2
|
+
import { submitTransaction } from "../tx.js";
|
|
3
|
+
import { getAmadeusProvider } from "../types.js";
|
|
4
|
+
import { decodeApiKey } from "../crypto/apikey.js";
|
|
5
|
+
//#region src/client/injected.ts
|
|
6
|
+
/**
|
|
7
|
+
* A framework-agnostic dApp client over the injected `window.amadeus` provider
|
|
8
|
+
* (the browser extension). It wraps the raw provider with the ergonomics every
|
|
9
|
+
* dApp currently hand-rolls: a single-account `connect`, sign-and-submit, and a
|
|
10
|
+
* cached `ensureApiKey` that decodes expiry via the audited api-key module
|
|
11
|
+
* (replacing the copies in hub / prime-hub).
|
|
12
|
+
*
|
|
13
|
+
* The mobile deep-link/QR path uses the transport module (connect handshake +
|
|
14
|
+
* sealed envelopes) instead of an injected provider; this client is the
|
|
15
|
+
* same-device, extension-present case.
|
|
16
|
+
*/
|
|
17
|
+
function memoryApiKeyStore() {
|
|
18
|
+
let value = null;
|
|
19
|
+
return {
|
|
20
|
+
get: () => value,
|
|
21
|
+
set: (apiKey) => value = apiKey
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function isApiKeyValid(apiKey, leewaySeconds) {
|
|
25
|
+
try {
|
|
26
|
+
const { payload } = decodeApiKey(apiKey);
|
|
27
|
+
return payload.exp > Math.floor(Date.now() / 1e3) + leewaySeconds;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a client bound to the injected provider. Pass `providerOverride` to
|
|
34
|
+
* inject a provider (e.g. in tests); otherwise it reads `window.amadeus`.
|
|
35
|
+
*/
|
|
36
|
+
function createInjectedWalletClient(providerOverride) {
|
|
37
|
+
const getProvider = () => providerOverride ?? getAmadeusProvider();
|
|
38
|
+
const requireProvider = () => {
|
|
39
|
+
const provider = getProvider();
|
|
40
|
+
if (!provider) throw new WalletSdkError("INVALID_ARGUMENT", "Amadeus wallet is not available");
|
|
41
|
+
return provider;
|
|
42
|
+
};
|
|
43
|
+
const defaultStore = memoryApiKeyStore();
|
|
44
|
+
let pendingApiKey = null;
|
|
45
|
+
return {
|
|
46
|
+
isAvailable: () => getProvider() !== null,
|
|
47
|
+
getProvider,
|
|
48
|
+
connect: async () => {
|
|
49
|
+
const accounts = await requireProvider().requestAccounts();
|
|
50
|
+
if (!accounts.length) throw new WalletSdkError("INVALID_ARGUMENT", "no account returned");
|
|
51
|
+
return accounts[0];
|
|
52
|
+
},
|
|
53
|
+
getAccount: () => requireProvider().getAccount(),
|
|
54
|
+
getNetwork: () => requireProvider().getNetwork(),
|
|
55
|
+
signTransaction: (request) => requireProvider().signTransaction(request),
|
|
56
|
+
signAndSubmit: async (request, options) => {
|
|
57
|
+
const { txHash, txPacked } = await requireProvider().signTransaction(request);
|
|
58
|
+
return {
|
|
59
|
+
txHash,
|
|
60
|
+
submitted: await submitTransaction(txPacked, {
|
|
61
|
+
nodeUrl: options.nodeUrl,
|
|
62
|
+
wait: options.wait
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
ensureApiKey: ({ aud, expIn, store = defaultStore, leewaySeconds = 60 }) => {
|
|
67
|
+
const cached = store.get();
|
|
68
|
+
if (cached && isApiKeyValid(cached, leewaySeconds)) return Promise.resolve(cached);
|
|
69
|
+
if (!pendingApiKey) pendingApiKey = requireProvider().generateApiKey({
|
|
70
|
+
aud,
|
|
71
|
+
exp_in: expIn
|
|
72
|
+
}).then(({ apiKey }) => {
|
|
73
|
+
store.set(apiKey);
|
|
74
|
+
return apiKey;
|
|
75
|
+
}).finally(() => {
|
|
76
|
+
pendingApiKey = null;
|
|
77
|
+
});
|
|
78
|
+
return pendingApiKey;
|
|
79
|
+
},
|
|
80
|
+
on: (event, cb) => requireProvider().on(event, cb),
|
|
81
|
+
off: (event, cb) => requireProvider().off(event, cb)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createInjectedWalletClient };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=injected.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Protocol constants for the Amadeus dApp <-> wallet connection layer.
|
|
4
|
+
*
|
|
5
|
+
* The Domain Separation Tags (DSTs) below are the single most safety-critical
|
|
6
|
+
* values in this package. A signature made under one DST can NEVER verify under
|
|
7
|
+
* another (BLS hash-to-curve mixes the DST into the point), which is exactly how
|
|
8
|
+
* we guarantee an auth signature can never be replayed as a transaction, and
|
|
9
|
+
* vice-versa. Two of these (`TX`, `APIKEY`) already exist in production — in
|
|
10
|
+
* `@amadeus-protocol/sdk` and in the wallet extension respectively — and MUST
|
|
11
|
+
* stay byte-for-byte identical here or existing tokens/txs stop verifying.
|
|
12
|
+
*/
|
|
13
|
+
/** Transactions. Owned by `@amadeus-protocol/sdk` (`signing.ts`). Do not change. */
|
|
14
|
+
declare const TX_DST = "AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_";
|
|
15
|
+
/**
|
|
16
|
+
* KBS bearer / API-key tokens. Currently hand-rolled identically in the wallet
|
|
17
|
+
* extension (`background/handlers/api-key.ts`) and in hub/prime-hub
|
|
18
|
+
* (`utils/blsWallet.ts`). This package is the one audited home for it. Do not
|
|
19
|
+
* change — `kbs.ama.one` verifies against this exact tag.
|
|
20
|
+
*/
|
|
21
|
+
declare const API_KEY_DST = "AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_APIKEY_";
|
|
22
|
+
/**
|
|
23
|
+
* Connection-auth transcript signatures. NEW in this package — nothing verified
|
|
24
|
+
* it before, so there is no backward-compat constraint. Deliberately distinct
|
|
25
|
+
* from every other DST so a connect proof is unusable anywhere else.
|
|
26
|
+
*/
|
|
27
|
+
declare const CONNECT_DST = "AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_CONNECT_";
|
|
28
|
+
/** Byte lengths of the Amadeus BLS12-381 "long-signature" variant (G1 pk / G2 sig). */
|
|
29
|
+
declare const PUBLIC_KEY_BYTE_LENGTH = 48;
|
|
30
|
+
declare const SIGNATURE_BYTE_LENGTH = 96;
|
|
31
|
+
declare const SEED_BYTE_LENGTH = 64;
|
|
32
|
+
/**
|
|
33
|
+
* Hard cap on the length of an api-key string accepted for decoding. A genuine
|
|
34
|
+
* token is ~260 chars; this bounds untrusted input BEFORE the (quadratic) Base58
|
|
35
|
+
* decode so a huge string can't stall the verifier's event loop. Generous enough
|
|
36
|
+
* for a multi-hundred-char audience claim.
|
|
37
|
+
*/
|
|
38
|
+
declare const MAX_API_KEY_STRING_LENGTH = 1024;
|
|
39
|
+
/** x25519 / xchacha20-poly1305 session-box parameters. */
|
|
40
|
+
declare const SESSION_PUBLIC_KEY_BYTE_LENGTH = 32;
|
|
41
|
+
declare const SESSION_SECRET_KEY_BYTE_LENGTH = 32;
|
|
42
|
+
declare const SESSION_NONCE_BYTE_LENGTH = 24;
|
|
43
|
+
/** Wire protocol version. Absent in the extension today; new requests carry it. */
|
|
44
|
+
declare const PROTOCOL_VERSION = 1;
|
|
45
|
+
/** Label mixed into the connect transcript so its bytes are unambiguous. */
|
|
46
|
+
declare const CONNECT_TRANSCRIPT_LABEL = "amadeus-connect/v1";
|
|
47
|
+
/** The injected-provider global name and feature-detect flag. */
|
|
48
|
+
declare const PROVIDER_GLOBAL = "amadeus";
|
|
49
|
+
/**
|
|
50
|
+
* The canonical wallet-ready window event. NOTE: several dApps historically
|
|
51
|
+
* listened for the WRONG name `amadeus#initialized`; the real one the extension
|
|
52
|
+
* dispatches is `amadeus-wallet#initialized`. Consumers should use this constant.
|
|
53
|
+
*/
|
|
54
|
+
declare const WALLET_INITIALIZED_EVENT = "amadeus-wallet#initialized";
|
|
55
|
+
/** All window CustomEvents the wallet dispatches on the page. */
|
|
56
|
+
declare const WALLET_WINDOW_EVENTS: {
|
|
57
|
+
readonly initialized: "amadeus-wallet#initialized";
|
|
58
|
+
readonly connected: "amadeus-wallet#connected";
|
|
59
|
+
readonly disconnected: "amadeus-wallet#disconnected";
|
|
60
|
+
readonly locked: "amadeus-wallet#locked";
|
|
61
|
+
readonly unlocked: "amadeus-wallet#unlocked";
|
|
62
|
+
readonly networkChanged: "amadeus-wallet#networkChanged";
|
|
63
|
+
};
|
|
64
|
+
/** Provider `.on()` event names (EIP-1193-style). */
|
|
65
|
+
declare const PROVIDER_EVENTS: readonly ["accountsChanged", "connect", "disconnect", "lock", "unlock", "networkChanged"];
|
|
66
|
+
/** The valid networks the wallet exposes. */
|
|
67
|
+
declare const NETWORKS: readonly ["mainnet", "testnet", "custom"];
|
|
68
|
+
//#endregion
|
|
69
|
+
export { API_KEY_DST, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, MAX_API_KEY_STRING_LENGTH, 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 };
|
|
70
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;;;;;;;;;cAaa;;;;;;;cAQA;;;;;;cAOA;;cAGA;cACA;cACA;;;;;;;cAQA;;cAGA;cACA;cACA;;cAGA;;cAGA;;cAGA;;;;;;cAOA;;cAGA;;;;;;;;;cAUA;;cAUA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
/**
|
|
3
|
+
* Protocol constants for the Amadeus dApp <-> wallet connection layer.
|
|
4
|
+
*
|
|
5
|
+
* The Domain Separation Tags (DSTs) below are the single most safety-critical
|
|
6
|
+
* values in this package. A signature made under one DST can NEVER verify under
|
|
7
|
+
* another (BLS hash-to-curve mixes the DST into the point), which is exactly how
|
|
8
|
+
* we guarantee an auth signature can never be replayed as a transaction, and
|
|
9
|
+
* vice-versa. Two of these (`TX`, `APIKEY`) already exist in production — in
|
|
10
|
+
* `@amadeus-protocol/sdk` and in the wallet extension respectively — and MUST
|
|
11
|
+
* stay byte-for-byte identical here or existing tokens/txs stop verifying.
|
|
12
|
+
*/
|
|
13
|
+
/** Transactions. Owned by `@amadeus-protocol/sdk` (`signing.ts`). Do not change. */
|
|
14
|
+
const TX_DST = "AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_";
|
|
15
|
+
/**
|
|
16
|
+
* KBS bearer / API-key tokens. Currently hand-rolled identically in the wallet
|
|
17
|
+
* extension (`background/handlers/api-key.ts`) and in hub/prime-hub
|
|
18
|
+
* (`utils/blsWallet.ts`). This package is the one audited home for it. Do not
|
|
19
|
+
* change — `kbs.ama.one` verifies against this exact tag.
|
|
20
|
+
*/
|
|
21
|
+
const API_KEY_DST = "AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_APIKEY_";
|
|
22
|
+
/**
|
|
23
|
+
* Connection-auth transcript signatures. NEW in this package — nothing verified
|
|
24
|
+
* it before, so there is no backward-compat constraint. Deliberately distinct
|
|
25
|
+
* from every other DST so a connect proof is unusable anywhere else.
|
|
26
|
+
*/
|
|
27
|
+
const CONNECT_DST = "AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_CONNECT_";
|
|
28
|
+
/** Byte lengths of the Amadeus BLS12-381 "long-signature" variant (G1 pk / G2 sig). */
|
|
29
|
+
const PUBLIC_KEY_BYTE_LENGTH = 48;
|
|
30
|
+
const SIGNATURE_BYTE_LENGTH = 96;
|
|
31
|
+
const SEED_BYTE_LENGTH = 64;
|
|
32
|
+
/**
|
|
33
|
+
* Hard cap on the length of an api-key string accepted for decoding. A genuine
|
|
34
|
+
* token is ~260 chars; this bounds untrusted input BEFORE the (quadratic) Base58
|
|
35
|
+
* decode so a huge string can't stall the verifier's event loop. Generous enough
|
|
36
|
+
* for a multi-hundred-char audience claim.
|
|
37
|
+
*/
|
|
38
|
+
const MAX_API_KEY_STRING_LENGTH = 1024;
|
|
39
|
+
/** x25519 / xchacha20-poly1305 session-box parameters. */
|
|
40
|
+
const SESSION_PUBLIC_KEY_BYTE_LENGTH = 32;
|
|
41
|
+
const SESSION_SECRET_KEY_BYTE_LENGTH = 32;
|
|
42
|
+
const SESSION_NONCE_BYTE_LENGTH = 24;
|
|
43
|
+
/** Wire protocol version. Absent in the extension today; new requests carry it. */
|
|
44
|
+
const PROTOCOL_VERSION = 1;
|
|
45
|
+
/** Label mixed into the connect transcript so its bytes are unambiguous. */
|
|
46
|
+
const CONNECT_TRANSCRIPT_LABEL = "amadeus-connect/v1";
|
|
47
|
+
/** The injected-provider global name and feature-detect flag. */
|
|
48
|
+
const PROVIDER_GLOBAL = "amadeus";
|
|
49
|
+
/**
|
|
50
|
+
* The canonical wallet-ready window event. NOTE: several dApps historically
|
|
51
|
+
* listened for the WRONG name `amadeus#initialized`; the real one the extension
|
|
52
|
+
* dispatches is `amadeus-wallet#initialized`. Consumers should use this constant.
|
|
53
|
+
*/
|
|
54
|
+
const WALLET_INITIALIZED_EVENT = "amadeus-wallet#initialized";
|
|
55
|
+
/** All window CustomEvents the wallet dispatches on the page. */
|
|
56
|
+
const WALLET_WINDOW_EVENTS = {
|
|
57
|
+
initialized: "amadeus-wallet#initialized",
|
|
58
|
+
connected: "amadeus-wallet#connected",
|
|
59
|
+
disconnected: "amadeus-wallet#disconnected",
|
|
60
|
+
locked: "amadeus-wallet#locked",
|
|
61
|
+
unlocked: "amadeus-wallet#unlocked",
|
|
62
|
+
networkChanged: "amadeus-wallet#networkChanged"
|
|
63
|
+
};
|
|
64
|
+
/** Provider `.on()` event names (EIP-1193-style). */
|
|
65
|
+
const PROVIDER_EVENTS = [
|
|
66
|
+
"accountsChanged",
|
|
67
|
+
"connect",
|
|
68
|
+
"disconnect",
|
|
69
|
+
"lock",
|
|
70
|
+
"unlock",
|
|
71
|
+
"networkChanged"
|
|
72
|
+
];
|
|
73
|
+
/** The valid networks the wallet exposes. */
|
|
74
|
+
const NETWORKS = [
|
|
75
|
+
"mainnet",
|
|
76
|
+
"testnet",
|
|
77
|
+
"custom"
|
|
78
|
+
];
|
|
79
|
+
//#endregion
|
|
80
|
+
export { API_KEY_DST, CONNECT_DST, CONNECT_TRANSCRIPT_LABEL, MAX_API_KEY_STRING_LENGTH, 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 };
|
|
81
|
+
|
|
82
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Protocol constants for the Amadeus dApp <-> wallet connection layer.\n *\n * The Domain Separation Tags (DSTs) below are the single most safety-critical\n * values in this package. A signature made under one DST can NEVER verify under\n * another (BLS hash-to-curve mixes the DST into the point), which is exactly how\n * we guarantee an auth signature can never be replayed as a transaction, and\n * vice-versa. Two of these (`TX`, `APIKEY`) already exist in production — in\n * `@amadeus-protocol/sdk` and in the wallet extension respectively — and MUST\n * stay byte-for-byte identical here or existing tokens/txs stop verifying.\n */\n\n/** Transactions. Owned by `@amadeus-protocol/sdk` (`signing.ts`). Do not change. */\nexport const TX_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_TX_'\n\n/**\n * KBS bearer / API-key tokens. Currently hand-rolled identically in the wallet\n * extension (`background/handlers/api-key.ts`) and in hub/prime-hub\n * (`utils/blsWallet.ts`). This package is the one audited home for it. Do not\n * change — `kbs.ama.one` verifies against this exact tag.\n */\nexport const API_KEY_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_APIKEY_'\n\n/**\n * Connection-auth transcript signatures. NEW in this package — nothing verified\n * it before, so there is no backward-compat constraint. Deliberately distinct\n * from every other DST so a connect proof is unusable anywhere else.\n */\nexport const CONNECT_DST = 'AMADEUS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_CONNECT_'\n\n/** Byte lengths of the Amadeus BLS12-381 \"long-signature\" variant (G1 pk / G2 sig). */\nexport const PUBLIC_KEY_BYTE_LENGTH = 48\nexport const SIGNATURE_BYTE_LENGTH = 96\nexport const SEED_BYTE_LENGTH = 64\n\n/**\n * Hard cap on the length of an api-key string accepted for decoding. A genuine\n * token is ~260 chars; this bounds untrusted input BEFORE the (quadratic) Base58\n * decode so a huge string can't stall the verifier's event loop. Generous enough\n * for a multi-hundred-char audience claim.\n */\nexport const MAX_API_KEY_STRING_LENGTH = 1024\n\n/** x25519 / xchacha20-poly1305 session-box parameters. */\nexport const SESSION_PUBLIC_KEY_BYTE_LENGTH = 32\nexport const SESSION_SECRET_KEY_BYTE_LENGTH = 32\nexport const SESSION_NONCE_BYTE_LENGTH = 24\n\n/** Wire protocol version. Absent in the extension today; new requests carry it. */\nexport const PROTOCOL_VERSION = 1\n\n/** Label mixed into the connect transcript so its bytes are unambiguous. */\nexport const CONNECT_TRANSCRIPT_LABEL = 'amadeus-connect/v1'\n\n/** The injected-provider global name and feature-detect flag. */\nexport const PROVIDER_GLOBAL = 'amadeus'\n\n/**\n * The canonical wallet-ready window event. NOTE: several dApps historically\n * listened for the WRONG name `amadeus#initialized`; the real one the extension\n * dispatches is `amadeus-wallet#initialized`. Consumers should use this constant.\n */\nexport const WALLET_INITIALIZED_EVENT = 'amadeus-wallet#initialized'\n\n/** All window CustomEvents the wallet dispatches on the page. */\nexport const WALLET_WINDOW_EVENTS = {\n\tinitialized: 'amadeus-wallet#initialized',\n\tconnected: 'amadeus-wallet#connected',\n\tdisconnected: 'amadeus-wallet#disconnected',\n\tlocked: 'amadeus-wallet#locked',\n\tunlocked: 'amadeus-wallet#unlocked',\n\tnetworkChanged: 'amadeus-wallet#networkChanged'\n} as const\n\n/** Provider `.on()` event names (EIP-1193-style). */\nexport const PROVIDER_EVENTS = [\n\t'accountsChanged',\n\t'connect',\n\t'disconnect',\n\t'lock',\n\t'unlock',\n\t'networkChanged'\n] as const\n\n/** The valid networks the wallet exposes. */\nexport const NETWORKS = ['mainnet', 'testnet', 'custom'] as const\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,SAAS;;;;;;;AAQtB,MAAa,cAAc;;;;;;AAO3B,MAAa,cAAc;;AAG3B,MAAa,yBAAyB;AACtC,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;;;;;;;AAQhC,MAAa,4BAA4B;;AAGzC,MAAa,iCAAiC;AAC9C,MAAa,iCAAiC;AAC9C,MAAa,4BAA4B;;AAGzC,MAAa,mBAAmB;;AAGhC,MAAa,2BAA2B;;AAGxC,MAAa,kBAAkB;;;;;;AAO/B,MAAa,2BAA2B;;AAGxC,MAAa,uBAAuB;CACnC,aAAa;CACb,WAAW;CACX,cAAc;CACd,QAAQ;CACR,UAAU;CACV,gBAAgB;AACjB;;AAGA,MAAa,kBAAkB;CAC9B;CACA;CACA;CACA;CACA;CACA;AACD;;AAGA,MAAa,WAAW;CAAC;CAAW;CAAW;AAAQ"}
|