@amadeus-protocol/sdk 1.0.7 → 1.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.
Files changed (199) hide show
  1. package/dist/api/chain.d.ts +144 -117
  2. package/dist/api/chain.d.ts.map +1 -1
  3. package/dist/api/chain.js +175 -146
  4. package/dist/api/chain.js.map +1 -1
  5. package/dist/api/contract.d.ts +78 -60
  6. package/dist/api/contract.d.ts.map +1 -1
  7. package/dist/api/contract.js +102 -75
  8. package/dist/api/contract.js.map +1 -1
  9. package/dist/api/epoch.d.ts +65 -66
  10. package/dist/api/epoch.d.ts.map +1 -1
  11. package/dist/api/epoch.js +90 -98
  12. package/dist/api/epoch.js.map +1 -1
  13. package/dist/api/peer.d.ts +77 -78
  14. package/dist/api/peer.d.ts.map +1 -1
  15. package/dist/api/peer.js +93 -94
  16. package/dist/api/peer.js.map +1 -1
  17. package/dist/api/proof.d.ts +44 -23
  18. package/dist/api/proof.d.ts.map +1 -1
  19. package/dist/api/proof.js +56 -29
  20. package/dist/api/proof.js.map +1 -1
  21. package/dist/api/transaction.d.ts +68 -69
  22. package/dist/api/transaction.d.ts.map +1 -1
  23. package/dist/api/transaction.js +84 -84
  24. package/dist/api/transaction.js.map +1 -1
  25. package/dist/api/wallet.d.ts +36 -37
  26. package/dist/api/wallet.d.ts.map +1 -1
  27. package/dist/api/wallet.js +47 -50
  28. package/dist/api/wallet.js.map +1 -1
  29. package/dist/client.d.ts +66 -68
  30. package/dist/client.d.ts.map +1 -1
  31. package/dist/client.js +231 -276
  32. package/dist/client.js.map +1 -1
  33. package/dist/constants.d.ts +13 -10
  34. package/dist/constants.d.ts.map +1 -1
  35. package/dist/constants.js +49 -45
  36. package/dist/constants.js.map +1 -1
  37. package/dist/contract-state.d.ts +6 -3
  38. package/dist/contract-state.d.ts.map +1 -1
  39. package/dist/contract-state.js +88 -106
  40. package/dist/contract-state.js.map +1 -1
  41. package/dist/contracts/abi-types.d.ts +32 -32
  42. package/dist/contracts/abi-types.d.ts.map +1 -1
  43. package/dist/contracts/coin.d.ts +13 -20
  44. package/dist/contracts/coin.d.ts.map +1 -1
  45. package/dist/contracts/coin.js +42 -38
  46. package/dist/contracts/coin.js.map +1 -1
  47. package/dist/contracts/contract-call.d.ts +14 -16
  48. package/dist/contracts/contract-call.d.ts.map +1 -1
  49. package/dist/contracts/contract-call.js +45 -54
  50. package/dist/contracts/contract-call.js.map +1 -1
  51. package/dist/contracts/contract.d.ts +24 -55
  52. package/dist/contracts/contract.d.ts.map +1 -1
  53. package/dist/contracts/contract.js +63 -101
  54. package/dist/contracts/contract.js.map +1 -1
  55. package/dist/contracts/lockup/abi.d.ts +54 -51
  56. package/dist/contracts/lockup/abi.d.ts.map +1 -1
  57. package/dist/contracts/lockup/abi.js +65 -74
  58. package/dist/contracts/lockup/abi.js.map +1 -1
  59. package/dist/contracts/lockup/helpers.d.ts +22 -18
  60. package/dist/contracts/lockup/helpers.d.ts.map +1 -1
  61. package/dist/contracts/lockup/helpers.js +44 -47
  62. package/dist/contracts/lockup/helpers.js.map +1 -1
  63. package/dist/contracts/lockup/parsers.d.ts +7 -3
  64. package/dist/contracts/lockup/parsers.d.ts.map +1 -1
  65. package/dist/contracts/lockup/parsers.js +51 -55
  66. package/dist/contracts/lockup/parsers.js.map +1 -1
  67. package/dist/contracts/lockup/storage-keys.d.ts +5 -2
  68. package/dist/contracts/lockup/storage-keys.d.ts.map +1 -1
  69. package/dist/contracts/lockup/storage-keys.js +54 -70
  70. package/dist/contracts/lockup/storage-keys.js.map +1 -1
  71. package/dist/contracts/lockup/types.d.ts +73 -70
  72. package/dist/contracts/lockup/types.d.ts.map +1 -1
  73. package/dist/contracts/lockup-prime/abi.d.ts +328 -325
  74. package/dist/contracts/lockup-prime/abi.d.ts.map +1 -1
  75. package/dist/contracts/lockup-prime/abi.js +397 -417
  76. package/dist/contracts/lockup-prime/abi.js.map +1 -1
  77. package/dist/contracts/lockup-prime/helpers.d.ts +35 -31
  78. package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -1
  79. package/dist/contracts/lockup-prime/helpers.js +131 -137
  80. package/dist/contracts/lockup-prime/helpers.js.map +1 -1
  81. package/dist/contracts/lockup-prime/parsers.d.ts +9 -5
  82. package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -1
  83. package/dist/contracts/lockup-prime/parsers.js +61 -61
  84. package/dist/contracts/lockup-prime/parsers.js.map +1 -1
  85. package/dist/contracts/lockup-prime/storage-keys.d.ts +7 -4
  86. package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -1
  87. package/dist/contracts/lockup-prime/storage-keys.js +64 -80
  88. package/dist/contracts/lockup-prime/storage-keys.js.map +1 -1
  89. package/dist/contracts/lockup-prime/types.d.ts +92 -89
  90. package/dist/contracts/lockup-prime/types.d.ts.map +1 -1
  91. package/dist/contracts/lockup-prime/types.js +12 -13
  92. package/dist/contracts/lockup-prime/types.js.map +1 -1
  93. package/dist/contracts/nft/abi.d.ts +104 -0
  94. package/dist/contracts/nft/abi.d.ts.map +1 -0
  95. package/dist/contracts/nft/abi.js +135 -0
  96. package/dist/contracts/nft/abi.js.map +1 -0
  97. package/dist/contracts/nft/helpers.d.ts +21 -0
  98. package/dist/contracts/nft/helpers.d.ts.map +1 -0
  99. package/dist/contracts/nft/helpers.js +61 -0
  100. package/dist/contracts/nft/helpers.js.map +1 -0
  101. package/dist/contracts/nft/types.d.ts +47 -0
  102. package/dist/contracts/nft/types.d.ts.map +1 -0
  103. package/dist/conversion.d.ts +5 -2
  104. package/dist/conversion.d.ts.map +1 -1
  105. package/dist/conversion.js +45 -50
  106. package/dist/conversion.js.map +1 -1
  107. package/dist/crypto.d.ts +14 -16
  108. package/dist/crypto.d.ts.map +1 -1
  109. package/dist/crypto.js +121 -140
  110. package/dist/crypto.js.map +1 -1
  111. package/dist/encoding.d.ts +11 -8
  112. package/dist/encoding.d.ts.map +1 -1
  113. package/dist/encoding.js +123 -144
  114. package/dist/encoding.js.map +1 -1
  115. package/dist/encryption.d.ts +15 -12
  116. package/dist/encryption.d.ts.map +1 -1
  117. package/dist/encryption.js +119 -117
  118. package/dist/encryption.js.map +1 -1
  119. package/dist/explorer.d.ts +10 -7
  120. package/dist/explorer.d.ts.map +1 -1
  121. package/dist/explorer.js +51 -48
  122. package/dist/explorer.js.map +1 -1
  123. package/dist/formatters.d.ts +8 -5
  124. package/dist/formatters.d.ts.map +1 -1
  125. package/dist/formatters.js +67 -68
  126. package/dist/formatters.js.map +1 -1
  127. package/dist/index.d.ts +42 -54
  128. package/dist/index.js +39 -54
  129. package/dist/mnemonic.d.ts +99 -0
  130. package/dist/mnemonic.d.ts.map +1 -0
  131. package/dist/mnemonic.js +119 -0
  132. package/dist/mnemonic.js.map +1 -0
  133. package/dist/networks.d.ts +14 -17
  134. package/dist/networks.d.ts.map +1 -1
  135. package/dist/networks.js +40 -36
  136. package/dist/networks.js.map +1 -1
  137. package/dist/schemas.js +75 -79
  138. package/dist/schemas.js.map +1 -1
  139. package/dist/sdk.d.ts +69 -65
  140. package/dist/sdk.d.ts.map +1 -1
  141. package/dist/sdk.js +126 -117
  142. package/dist/sdk.js.map +1 -1
  143. package/dist/serialization.d.ts +8 -18
  144. package/dist/serialization.d.ts.map +1 -1
  145. package/dist/serialization.js +207 -260
  146. package/dist/serialization.js.map +1 -1
  147. package/dist/signing.js +67 -67
  148. package/dist/signing.js.map +1 -1
  149. package/dist/transaction-builder.d.ts +175 -184
  150. package/dist/transaction-builder.d.ts.map +1 -1
  151. package/dist/transaction-builder.js +295 -344
  152. package/dist/transaction-builder.js.map +1 -1
  153. package/dist/transaction-errors.d.ts +10 -12
  154. package/dist/transaction-errors.d.ts.map +1 -1
  155. package/dist/transaction-errors.js +145 -166
  156. package/dist/transaction-errors.js.map +1 -1
  157. package/dist/types.d.ts +530 -450
  158. package/dist/types.d.ts.map +1 -1
  159. package/dist/types.js +169 -183
  160. package/dist/types.js.map +1 -1
  161. package/dist/validation.d.ts +24 -26
  162. package/dist/validation.d.ts.map +1 -1
  163. package/dist/validation.js +194 -192
  164. package/dist/validation.js.map +1 -1
  165. package/package.json +5 -3
  166. package/dist/api/index.d.ts +0 -8
  167. package/dist/api/index.d.ts.map +0 -1
  168. package/dist/api/index.js +0 -8
  169. package/dist/api/index.js.map +0 -1
  170. package/dist/contracts/abi-types.js +0 -8
  171. package/dist/contracts/abi-types.js.map +0 -1
  172. package/dist/contracts/index.d.ts +0 -7
  173. package/dist/contracts/index.d.ts.map +0 -1
  174. package/dist/contracts/index.js +0 -7
  175. package/dist/contracts/index.js.map +0 -1
  176. package/dist/contracts/lockup/calls.d.ts +0 -23
  177. package/dist/contracts/lockup/calls.d.ts.map +0 -1
  178. package/dist/contracts/lockup/calls.js +0 -25
  179. package/dist/contracts/lockup/calls.js.map +0 -1
  180. package/dist/contracts/lockup/index.d.ts +0 -6
  181. package/dist/contracts/lockup/index.d.ts.map +0 -1
  182. package/dist/contracts/lockup/index.js +0 -6
  183. package/dist/contracts/lockup/index.js.map +0 -1
  184. package/dist/contracts/lockup/types.js +0 -7
  185. package/dist/contracts/lockup/types.js.map +0 -1
  186. package/dist/contracts/lockup-prime/calls.d.ts +0 -53
  187. package/dist/contracts/lockup-prime/calls.d.ts.map +0 -1
  188. package/dist/contracts/lockup-prime/calls.js +0 -60
  189. package/dist/contracts/lockup-prime/calls.js.map +0 -1
  190. package/dist/contracts/lockup-prime/index.d.ts +0 -6
  191. package/dist/contracts/lockup-prime/index.d.ts.map +0 -1
  192. package/dist/contracts/lockup-prime/index.js +0 -6
  193. package/dist/contracts/lockup-prime/index.js.map +0 -1
  194. package/dist/index.d.ts.map +0 -1
  195. package/dist/index.js.map +0 -1
  196. package/dist/schemas.d.ts +0 -67
  197. package/dist/schemas.d.ts.map +0 -1
  198. package/dist/signing.d.ts +0 -39
  199. package/dist/signing.d.ts.map +0 -1
@@ -1,18 +1,6 @@
1
- /**
2
- * VecPack Canonical Serialization Format
3
- *
4
- * This module implements the VecPack canonical serialization format used by Amadeus.
5
- * VecPack provides deterministic, canonical encoding of values for use in cryptographic
6
- * operations (e.g., transaction signing). It ensures that equivalent data structures
7
- * always serialize to the same byte sequence through canonical ordering of map keys.
8
- *
9
- * Format specification:
10
- * - Supports: null, booleans, integers (varint), bytes, lists, and maps
11
- * - Maps/objects are sorted by their encoded key bytes for canonical ordering
12
- * - Varints are limited to 16 bytes maximum
13
- * - Zero values are encoded as a single 0x00 byte
14
- */
15
- import type { DecodedValue, SerializableValue } from './types';
1
+ import { DecodedValue, SerializableValue } from "./types.js";
2
+
3
+ //#region src/serialization.d.ts
16
4
  /**
17
5
  * Encode a value into canonical serialization format
18
6
  *
@@ -25,7 +13,7 @@ import type { DecodedValue, SerializableValue } from './types';
25
13
  * const encoded = encode({ foo: 'bar', count: 42 })
26
14
  * ```
27
15
  */
28
- export declare function encode(term: SerializableValue): Uint8Array;
16
+ declare function encode(term: SerializableValue): Uint8Array;
29
17
  /**
30
18
  * Decode a value from canonical serialization format
31
19
  *
@@ -38,7 +26,7 @@ export declare function encode(term: SerializableValue): Uint8Array;
38
26
  * const decoded = decode(encodedBytes)
39
27
  * ```
40
28
  */
41
- export declare function decode(bytes: Uint8Array | number[]): DecodedValue;
29
+ declare function decode(bytes: Uint8Array | number[]): DecodedValue;
42
30
  /**
43
31
  * Decode VecPack-encoded contract state into key-value pairs
44
32
  *
@@ -60,5 +48,7 @@ export declare function decode(bytes: Uint8Array | number[]): DecodedValue;
60
48
  * }
61
49
  * ```
62
50
  */
63
- export declare function decodeContractState(bytes: Uint8Array | ArrayBuffer): Array<[Uint8Array, Uint8Array]>;
51
+ declare function decodeContractState(bytes: Uint8Array | ArrayBuffer): Array<[Uint8Array, Uint8Array]>;
52
+ //#endregion
53
+ export { decode, decodeContractState, encode };
64
54
  //# sourceMappingURL=serialization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAUH,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAM9D;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,iBAAiB,GAAG,UAAU,CAI1D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,EAAE,GAAG,YAAY,CAQjE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,UAAU,GAAG,WAAW,GAC7B,KAAK,CAAC,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAiBjC"}
1
+ {"version":3,"file":"serialization.d.ts","names":[],"sources":["../src/serialization.ts"],"mappings":";;;;;;;;;AA0FA;;;;;;iBAjDgB,MAAA,CAAO,IAAA,EAAM,iBAAA,GAAoB,UAAA;;;;;;;;;;;;;iBAkBjC,MAAA,CAAO,KAAA,EAAO,UAAA,cAAwB,YAAA;;;;;;;;;;;;;;;;;;;;;;iBA+BtC,mBAAA,CACf,KAAA,EAAO,UAAA,GAAa,WAAA,GAClB,KAAA,EAAO,UAAA,EAAY,UAAA"}
@@ -1,284 +1,231 @@
1
+ //#region src/serialization.ts
1
2
  /**
2
- * VecPack Canonical Serialization Format
3
- *
4
- * This module implements the VecPack canonical serialization format used by Amadeus.
5
- * VecPack provides deterministic, canonical encoding of values for use in cryptographic
6
- * operations (e.g., transaction signing). It ensures that equivalent data structures
7
- * always serialize to the same byte sequence through canonical ordering of map keys.
8
- *
9
- * Format specification:
10
- * - Supports: null, booleans, integers (varint), bytes, lists, and maps
11
- * - Maps/objects are sorted by their encoded key bytes for canonical ordering
12
- * - Varints are limited to 16 bytes maximum
13
- * - Zero values are encoded as a single 0x00 byte
14
- */
15
- const TYPE_NULL = 0x00;
16
- const TYPE_TRUE = 0x01;
17
- const TYPE_FALSE = 0x02;
18
- const TYPE_INT = 0x03;
19
- const TYPE_BYTES = 0x05;
20
- const TYPE_LIST = 0x06;
21
- const TYPE_MAP = 0x07;
3
+ * VecPack Canonical Serialization Format
4
+ *
5
+ * This module implements the VecPack canonical serialization format used by Amadeus.
6
+ * VecPack provides deterministic, canonical encoding of values for use in cryptographic
7
+ * operations (e.g., transaction signing). It ensures that equivalent data structures
8
+ * always serialize to the same byte sequence through canonical ordering of map keys.
9
+ *
10
+ * Format specification:
11
+ * - Supports: null, booleans, integers (varint), bytes, lists, and maps
12
+ * - Maps/objects are sorted by their encoded key bytes for canonical ordering
13
+ * - Varints are limited to 16 bytes maximum
14
+ * - Zero values are encoded as a single 0x00 byte
15
+ */
16
+ const TYPE_NULL = 0;
17
+ const TYPE_TRUE = 1;
18
+ const TYPE_FALSE = 2;
19
+ const TYPE_INT = 3;
20
+ const TYPE_BYTES = 5;
21
+ const TYPE_LIST = 6;
22
+ const TYPE_MAP = 7;
22
23
  /**
23
- * Encode a value into canonical serialization format
24
- *
25
- * @param term - The value to encode
26
- * @returns Encoded bytes as Uint8Array
27
- * @throws Error if the value contains unsupported types
28
- *
29
- * @example
30
- * ```ts
31
- * const encoded = encode({ foo: 'bar', count: 42 })
32
- * ```
33
- */
34
- export function encode(term) {
35
- const bytesOut = [];
36
- encodeTerm(term, bytesOut);
37
- return new Uint8Array(bytesOut);
24
+ * Encode a value into canonical serialization format
25
+ *
26
+ * @param term - The value to encode
27
+ * @returns Encoded bytes as Uint8Array
28
+ * @throws Error if the value contains unsupported types
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const encoded = encode({ foo: 'bar', count: 42 })
33
+ * ```
34
+ */
35
+ function encode(term) {
36
+ const bytesOut = [];
37
+ encodeTerm(term, bytesOut);
38
+ return new Uint8Array(bytesOut);
38
39
  }
39
40
  /**
40
- * Decode a value from canonical serialization format
41
- *
42
- * @param bytes - The encoded bytes to decode
43
- * @returns Decoded value
44
- * @throws Error if the bytes are invalid or contain trailing bytes
45
- *
46
- * @example
47
- * ```ts
48
- * const decoded = decode(encodedBytes)
49
- * ```
50
- */
51
- export function decode(bytes) {
52
- const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
53
- const ref = { offset: 0 };
54
- const value = decodeTerm(data, ref);
55
- if (ref.offset !== data.length) {
56
- throw new Error('trailing_bytes');
57
- }
58
- return value;
41
+ * Decode a value from canonical serialization format
42
+ *
43
+ * @param bytes - The encoded bytes to decode
44
+ * @returns Decoded value
45
+ * @throws Error if the bytes are invalid or contain trailing bytes
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const decoded = decode(encodedBytes)
50
+ * ```
51
+ */
52
+ function decode(bytes) {
53
+ const data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
54
+ const ref = { offset: 0 };
55
+ const value = decodeTerm(data, ref);
56
+ if (ref.offset !== data.length) throw new Error("trailing_bytes");
57
+ return value;
59
58
  }
60
59
  /**
61
- * Decode VecPack-encoded contract state into key-value pairs
62
- *
63
- * Contract state prefix queries return a VecPack-encoded map where both
64
- * keys and values are binary (Uint8Array). This convenience function decodes
65
- * the binary data and returns the entries as an array of tuples.
66
- *
67
- * @param bytes - VecPack-encoded bytes (Uint8Array or ArrayBuffer)
68
- * @returns Array of [key, value] tuples
69
- * @throws Error if the data is not a valid VecPack map or entries are not binary
70
- *
71
- * @example
72
- * ```ts
73
- * const response = await fetch('/contract/state/prefix?prefix=...')
74
- * const buffer = await response.arrayBuffer()
75
- * const entries = decodeContractState(buffer)
76
- * for (const [key, value] of entries) {
77
- * console.log(key, value)
78
- * }
79
- * ```
80
- */
81
- export function decodeContractState(bytes) {
82
- const data = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes;
83
- const decoded = decode(data);
84
- if (!(decoded instanceof Map)) {
85
- throw new Error(`Expected MAP type, got ${typeof decoded}`);
86
- }
87
- const result = [];
88
- for (const [key, value] of decoded.entries()) {
89
- if (!(key instanceof Uint8Array) || !(value instanceof Uint8Array)) {
90
- throw new Error('Expected Uint8Array for key and value');
91
- }
92
- result.push([key, value]);
93
- }
94
- return result;
60
+ * Decode VecPack-encoded contract state into key-value pairs
61
+ *
62
+ * Contract state prefix queries return a VecPack-encoded map where both
63
+ * keys and values are binary (Uint8Array). This convenience function decodes
64
+ * the binary data and returns the entries as an array of tuples.
65
+ *
66
+ * @param bytes - VecPack-encoded bytes (Uint8Array or ArrayBuffer)
67
+ * @returns Array of [key, value] tuples
68
+ * @throws Error if the data is not a valid VecPack map or entries are not binary
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const response = await fetch('/contract/state/prefix?prefix=...')
73
+ * const buffer = await response.arrayBuffer()
74
+ * const entries = decodeContractState(buffer)
75
+ * for (const [key, value] of entries) {
76
+ * console.log(key, value)
77
+ * }
78
+ * ```
79
+ */
80
+ function decodeContractState(bytes) {
81
+ const decoded = decode(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes);
82
+ if (!(decoded instanceof Map)) throw new Error(`Expected MAP type, got ${typeof decoded}`);
83
+ const result = [];
84
+ for (const [key, value] of decoded.entries()) {
85
+ if (!(key instanceof Uint8Array) || !(value instanceof Uint8Array)) throw new Error("Expected Uint8Array for key and value");
86
+ result.push([key, value]);
87
+ }
88
+ return result;
95
89
  }
96
- /*
97
- * Helper functions for encoding and decoding
98
- */
99
90
  function appendBytes(out, bytes) {
100
- for (const b of bytes) {
101
- out.push(b);
102
- }
91
+ for (const b of bytes) out.push(b);
103
92
  }
104
93
  function compareBytes(a, b) {
105
- const n = Math.min(a.length, b.length);
106
- for (let i = 0; i < n; i++) {
107
- if (a[i] !== b[i])
108
- return a[i] - b[i];
109
- }
110
- return a.length - b.length; // shorter wins if prefix equal
94
+ const n = Math.min(a.length, b.length);
95
+ for (let i = 0; i < n; i++) if (a[i] !== b[i]) return a[i] - b[i];
96
+ return a.length - b.length;
111
97
  }
112
98
  function encodeKeyBytes(k) {
113
- const tmp = [];
114
- encodeTerm(k, tmp);
115
- return tmp;
99
+ const tmp = [];
100
+ encodeTerm(k, tmp);
101
+ return tmp;
116
102
  }
117
103
  function encodeVarint(n, out) {
118
- let value = typeof n === 'bigint' ? n : BigInt(n);
119
- if (value === 0n) {
120
- out.push(0);
121
- return;
122
- }
123
- const isNegative = value < 0n;
124
- if (isNegative)
125
- value = -value;
126
- // build big-endian magnitude
127
- const magBytes = [];
128
- while (value > 0n) {
129
- magBytes.push(Number(value & 0xffn));
130
- value >>= 8n;
131
- }
132
- magBytes.reverse(); // now big-endian
133
- const len = magBytes.length;
134
- if (len === 0 || len > 16) {
135
- throw new Error('bad_varint_length');
136
- }
137
- // Rust also rejects leading zero in decode; we don't generate those here
138
- if (magBytes[0] === 0) {
139
- throw new Error('varint_leading_zero');
140
- }
141
- const header = ((isNegative ? 1 : 0) << 7) | len;
142
- out.push(header);
143
- appendBytes(out, magBytes);
104
+ let value = typeof n === "bigint" ? n : BigInt(n);
105
+ if (value === 0n) {
106
+ out.push(0);
107
+ return;
108
+ }
109
+ const isNegative = value < 0n;
110
+ if (isNegative) value = -value;
111
+ const magBytes = [];
112
+ while (value > 0n) {
113
+ magBytes.push(Number(value & 255n));
114
+ value >>= 8n;
115
+ }
116
+ magBytes.reverse();
117
+ const len = magBytes.length;
118
+ if (len === 0 || len > 16) throw new Error("bad_varint_length");
119
+ if (magBytes[0] === 0) throw new Error("varint_leading_zero");
120
+ const header = (isNegative ? 1 : 0) << 7 | len;
121
+ out.push(header);
122
+ appendBytes(out, magBytes);
144
123
  }
145
124
  function decodeVarint(data, ref) {
146
- const header = data[ref.offset++];
147
- if (header === 0)
148
- return 0n;
149
- if (header === 0x80)
150
- throw new Error('noncanonical_zero');
151
- const signBit = header >> 7;
152
- const length = header & 0x7f;
153
- let mag = 0n;
154
- for (let i = 0; i < length; i++) {
155
- mag = (mag << 8n) | BigInt(data[ref.offset++]);
156
- }
157
- if (signBit === 1) {
158
- return -mag;
159
- }
160
- else {
161
- return mag;
162
- }
125
+ const header = data[ref.offset++];
126
+ if (header === 0) return 0n;
127
+ if (header === 128) throw new Error("noncanonical_zero");
128
+ const signBit = header >> 7;
129
+ const length = header & 127;
130
+ let mag = 0n;
131
+ for (let i = 0; i < length; i++) mag = mag << 8n | BigInt(data[ref.offset++]);
132
+ if (signBit === 1) return -mag;
133
+ else return mag;
163
134
  }
164
135
  function decodeVarintGteZero(data, ref) {
165
- const n = decodeVarint(data, ref);
166
- if (n < 0n) {
167
- throw new Error('length_is_negative');
168
- }
169
- if (n > BigInt(Number.MAX_SAFE_INTEGER)) {
170
- throw new Error('length_overflow');
171
- }
172
- return Number(n);
136
+ const n = decodeVarint(data, ref);
137
+ if (n < 0n) throw new Error("length_is_negative");
138
+ if (n > BigInt(Number.MAX_SAFE_INTEGER)) throw new Error("length_overflow");
139
+ return Number(n);
173
140
  }
174
141
  function encodeTerm(value, out) {
175
- if (value === null) {
176
- out.push(TYPE_NULL);
177
- }
178
- else if (typeof value === 'boolean') {
179
- out.push(value ? TYPE_TRUE : TYPE_FALSE);
180
- }
181
- else if (typeof value === 'number' || typeof value === 'bigint') {
182
- out.push(TYPE_INT);
183
- encodeVarint(value, out);
184
- }
185
- else if (typeof value === 'string') {
186
- out.push(TYPE_BYTES);
187
- const utf8 = new TextEncoder().encode(value);
188
- encodeVarint(utf8.length, out);
189
- appendBytes(out, utf8);
190
- }
191
- else if (value instanceof Uint8Array) {
192
- out.push(TYPE_BYTES);
193
- encodeVarint(value.length, out);
194
- appendBytes(out, value);
195
- }
196
- else if (Array.isArray(value)) {
197
- out.push(TYPE_LIST);
198
- encodeVarint(value.length, out);
199
- for (const element of value) {
200
- encodeTerm(element, out);
201
- }
202
- }
203
- else if (value instanceof Map ||
204
- (typeof value === 'object' && !Array.isArray(value) && !(value instanceof Uint8Array))) {
205
- const entries = [];
206
- if (value instanceof Map) {
207
- for (const [k, v] of value.entries()) {
208
- const bytes = encodeKeyBytes(k); // encodes key as Term
209
- entries.push({ k, v, bytes });
210
- }
211
- }
212
- else {
213
- for (const k of Object.keys(value)) {
214
- const v = value[k];
215
- const bytes = encodeKeyBytes(k); // k is string; still encoded via encodeValue
216
- entries.push({ k, v, bytes });
217
- }
218
- }
219
- entries.sort((a, b) => compareBytes(a.bytes, b.bytes));
220
- out.push(TYPE_MAP);
221
- encodeVarint(entries.length, out);
222
- for (const entry of entries) {
223
- encodeTerm(entry.k, out);
224
- encodeTerm(entry.v, out);
225
- }
226
- }
227
- else {
228
- throw new Error(`Unsupported type: ${typeof value}`);
229
- }
142
+ if (value === null) out.push(TYPE_NULL);
143
+ else if (typeof value === "boolean") out.push(value ? TYPE_TRUE : TYPE_FALSE);
144
+ else if (typeof value === "number" || typeof value === "bigint") {
145
+ out.push(TYPE_INT);
146
+ encodeVarint(value, out);
147
+ } else if (typeof value === "string") {
148
+ out.push(TYPE_BYTES);
149
+ const utf8 = new TextEncoder().encode(value);
150
+ encodeVarint(utf8.length, out);
151
+ appendBytes(out, utf8);
152
+ } else if (value instanceof Uint8Array) {
153
+ out.push(TYPE_BYTES);
154
+ encodeVarint(value.length, out);
155
+ appendBytes(out, value);
156
+ } else if (Array.isArray(value)) {
157
+ out.push(TYPE_LIST);
158
+ encodeVarint(value.length, out);
159
+ for (const element of value) encodeTerm(element, out);
160
+ } else if (value instanceof Map || typeof value === "object" && !Array.isArray(value) && !(value instanceof Uint8Array)) {
161
+ const entries = [];
162
+ if (value instanceof Map) for (const [k, v] of value.entries()) {
163
+ const bytes = encodeKeyBytes(k);
164
+ entries.push({
165
+ k,
166
+ v,
167
+ bytes
168
+ });
169
+ }
170
+ else for (const k of Object.keys(value)) {
171
+ const v = value[k];
172
+ const bytes = encodeKeyBytes(k);
173
+ entries.push({
174
+ k,
175
+ v,
176
+ bytes
177
+ });
178
+ }
179
+ entries.sort((a, b) => compareBytes(a.bytes, b.bytes));
180
+ out.push(TYPE_MAP);
181
+ encodeVarint(entries.length, out);
182
+ for (const entry of entries) {
183
+ encodeTerm(entry.k, out);
184
+ encodeTerm(entry.v, out);
185
+ }
186
+ } else throw new Error(`Unsupported type: ${typeof value}`);
230
187
  }
231
188
  function decodeTerm(data, ref) {
232
- if (ref.offset >= data.length) {
233
- throw new Error('decodeBytes: Out of bounds read');
234
- }
235
- const type = data[ref.offset++];
236
- switch (type) {
237
- case TYPE_NULL:
238
- return null;
239
- case TYPE_TRUE:
240
- return true;
241
- case TYPE_FALSE:
242
- return false;
243
- case TYPE_INT:
244
- return decodeVarint(data, ref);
245
- case TYPE_BYTES: {
246
- const length = decodeVarintGteZero(data, ref);
247
- const bytes = data.slice(ref.offset, ref.offset + length);
248
- ref.offset += length;
249
- return bytes;
250
- }
251
- case TYPE_LIST: {
252
- const count = decodeVarintGteZero(data, ref);
253
- const items = new Array(count);
254
- for (let i = 0; i < count; i++) {
255
- items[i] = decodeTerm(data, ref);
256
- }
257
- return items;
258
- }
259
- case TYPE_MAP: {
260
- const count = decodeVarintGteZero(data, ref);
261
- let prevKeyBytes = null;
262
- const map = new Map();
263
- for (let idx = 0; idx < count; idx++) {
264
- // canonical check: track raw key bytes
265
- const kStart = ref.offset;
266
- const key = decodeTerm(data, ref);
267
- const kEnd = ref.offset;
268
- const keyBytes = data.slice(kStart, kEnd);
269
- if (prevKeyBytes !== null) {
270
- if (compareBytes(keyBytes, prevKeyBytes) <= 0) {
271
- throw new Error('map_not_canonical');
272
- }
273
- }
274
- prevKeyBytes = keyBytes;
275
- const value = decodeTerm(data, ref);
276
- map.set(key, value);
277
- }
278
- return map;
279
- }
280
- default:
281
- throw new Error('decodeBytes: Unknown type');
282
- }
189
+ if (ref.offset >= data.length) throw new Error("decodeBytes: Out of bounds read");
190
+ switch (data[ref.offset++]) {
191
+ case TYPE_NULL: return null;
192
+ case TYPE_TRUE: return true;
193
+ case TYPE_FALSE: return false;
194
+ case TYPE_INT: return decodeVarint(data, ref);
195
+ case TYPE_BYTES: {
196
+ const length = decodeVarintGteZero(data, ref);
197
+ const bytes = data.slice(ref.offset, ref.offset + length);
198
+ ref.offset += length;
199
+ return bytes;
200
+ }
201
+ case TYPE_LIST: {
202
+ const count = decodeVarintGteZero(data, ref);
203
+ const items = new Array(count);
204
+ for (let i = 0; i < count; i++) items[i] = decodeTerm(data, ref);
205
+ return items;
206
+ }
207
+ case TYPE_MAP: {
208
+ const count = decodeVarintGteZero(data, ref);
209
+ let prevKeyBytes = null;
210
+ const map = /* @__PURE__ */ new Map();
211
+ for (let idx = 0; idx < count; idx++) {
212
+ const kStart = ref.offset;
213
+ const key = decodeTerm(data, ref);
214
+ const kEnd = ref.offset;
215
+ const keyBytes = data.slice(kStart, kEnd);
216
+ if (prevKeyBytes !== null) {
217
+ if (compareBytes(keyBytes, prevKeyBytes) <= 0) throw new Error("map_not_canonical");
218
+ }
219
+ prevKeyBytes = keyBytes;
220
+ const value = decodeTerm(data, ref);
221
+ map.set(key, value);
222
+ }
223
+ return map;
224
+ }
225
+ default: throw new Error("decodeBytes: Unknown type");
226
+ }
283
227
  }
228
+ //#endregion
229
+ export { decode, decodeContractState, encode };
230
+
284
231
  //# sourceMappingURL=serialization.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../src/serialization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,QAAQ,GAAG,IAAI,CAAA;AACrB,MAAM,UAAU,GAAG,IAAI,CAAA;AACvB,MAAM,SAAS,GAAG,IAAI,CAAA;AACtB,MAAM,QAAQ,GAAG,IAAI,CAAA;AAQrB;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,IAAuB;IAC7C,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,UAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IAC1B,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,MAAM,CAAC,KAA4B;IAClD,MAAM,IAAI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AM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAA;gBACvB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;gBAEzC,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;oBAC3B,IAAI,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC/C,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAA;oBACrC,CAAC;gBACF,CAAC;gBACD,YAAY,GAAG,QAAQ,CAAA;gBAEvB,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;gBACnC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACpB,CAAC;YACD,OAAO,GAAG,CAAA;QACX,CAAC;QACD;YACC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;IAC9C,CAAC;AACF,CAAC"}
1
+ {"version":3,"file":"serialization.js","names":[],"sources":["../src/serialization.ts"],"sourcesContent":["/**\n * VecPack Canonical Serialization Format\n *\n * This module implements the VecPack canonical serialization format used by Amadeus.\n * VecPack provides deterministic, canonical encoding of values for use in cryptographic\n * operations (e.g., transaction signing). It ensures that equivalent data structures\n * always serialize to the same byte sequence through canonical ordering of map keys.\n *\n * Format specification:\n * - Supports: null, booleans, integers (varint), bytes, lists, and maps\n * - Maps/objects are sorted by their encoded key bytes for canonical ordering\n * - Varints are limited to 16 bytes maximum\n * - Zero values are encoded as a single 0x00 byte\n */\n\nconst TYPE_NULL = 0x00\nconst TYPE_TRUE = 0x01\nconst TYPE_FALSE = 0x02\nconst TYPE_INT = 0x03\nconst TYPE_BYTES = 0x05\nconst TYPE_LIST = 0x06\nconst TYPE_MAP = 0x07\n\nimport type { DecodedValue, SerializableValue } from './types'\n\ninterface DecodeRef {\n\toffset: number\n}\n\n/**\n * Encode a value into canonical serialization format\n *\n * @param term - The value to encode\n * @returns Encoded bytes as Uint8Array\n * @throws Error if the value contains unsupported types\n *\n * @example\n * ```ts\n * const encoded = encode({ foo: 'bar', count: 42 })\n * ```\n */\nexport function encode(term: SerializableValue): Uint8Array {\n\tconst bytesOut: number[] = []\n\tencodeTerm(term, bytesOut)\n\treturn new Uint8Array(bytesOut)\n}\n\n/**\n * Decode a value from canonical serialization format\n *\n * @param bytes - The encoded bytes to decode\n * @returns Decoded value\n * @throws Error if the bytes are invalid or contain trailing bytes\n *\n * @example\n * ```ts\n * const decoded = decode(encodedBytes)\n * ```\n */\nexport function decode(bytes: Uint8Array | number[]): DecodedValue {\n\tconst data = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes)\n\tconst ref: DecodeRef = { offset: 0 }\n\tconst value = decodeTerm(data, ref)\n\tif (ref.offset !== data.length) {\n\t\tthrow new Error('trailing_bytes')\n\t}\n\treturn value\n}\n\n/**\n * Decode VecPack-encoded contract state into key-value pairs\n *\n * Contract state prefix queries return a VecPack-encoded map where both\n * keys and values are binary (Uint8Array). This convenience function decodes\n * the binary data and returns the entries as an array of tuples.\n *\n * @param bytes - VecPack-encoded bytes (Uint8Array or ArrayBuffer)\n * @returns Array of [key, value] tuples\n * @throws Error if the data is not a valid VecPack map or entries are not binary\n *\n * @example\n * ```ts\n * const response = await fetch('/contract/state/prefix?prefix=...')\n * const buffer = await response.arrayBuffer()\n * const entries = decodeContractState(buffer)\n * for (const [key, value] of entries) {\n * console.log(key, value)\n * }\n * ```\n */\nexport function decodeContractState(\n\tbytes: Uint8Array | ArrayBuffer\n): Array<[Uint8Array, Uint8Array]> {\n\tconst data = bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes\n\tconst decoded = decode(data)\n\n\tif (!(decoded instanceof Map)) {\n\t\tthrow new Error(`Expected MAP type, got ${typeof decoded}`)\n\t}\n\n\tconst result: Array<[Uint8Array, Uint8Array]> = []\n\tfor (const [key, value] of decoded.entries()) {\n\t\tif (!(key instanceof Uint8Array) || !(value instanceof Uint8Array)) {\n\t\t\tthrow new Error('Expected Uint8Array for key and value')\n\t\t}\n\t\tresult.push([key, value])\n\t}\n\n\treturn result\n}\n\n/*\n * Helper functions for encoding and decoding\n */\nfunction appendBytes(out: number[], bytes: Uint8Array | number[]): void {\n\tfor (const b of bytes) {\n\t\tout.push(b)\n\t}\n}\n\nfunction compareBytes(a: Uint8Array | number[], b: Uint8Array | number[]): number {\n\tconst n = Math.min(a.length, b.length)\n\tfor (let i = 0; i < n; i++) {\n\t\tif (a[i] !== b[i]) return a[i] - b[i]\n\t}\n\treturn a.length - b.length // shorter wins if prefix equal\n}\n\nfunction encodeKeyBytes(k: SerializableValue): number[] {\n\tconst tmp: number[] = []\n\tencodeTerm(k, tmp)\n\treturn tmp\n}\n\nfunction encodeVarint(n: number | bigint, out: number[]): void {\n\tlet value = typeof n === 'bigint' ? n : BigInt(n)\n\n\tif (value === 0n) {\n\t\tout.push(0)\n\t\treturn\n\t}\n\n\tconst isNegative = value < 0n\n\tif (isNegative) value = -value\n\n\t// build big-endian magnitude\n\tconst magBytes: number[] = []\n\twhile (value > 0n) {\n\t\tmagBytes.push(Number(value & 0xffn))\n\t\tvalue >>= 8n\n\t}\n\tmagBytes.reverse() // now big-endian\n\n\tconst len = magBytes.length\n\tif (len === 0 || len > 16) {\n\t\tthrow new Error('bad_varint_length')\n\t}\n\n\t// Rust also rejects leading zero in decode; we don't generate those here\n\tif (magBytes[0] === 0) {\n\t\tthrow new Error('varint_leading_zero')\n\t}\n\n\tconst header = ((isNegative ? 1 : 0) << 7) | len\n\tout.push(header)\n\tappendBytes(out, magBytes)\n}\n\nfunction decodeVarint(data: Uint8Array, ref: DecodeRef): bigint {\n\tconst header = data[ref.offset++]\n\tif (header === 0) return 0n\n\tif (header === 0x80) throw new Error('noncanonical_zero')\n\n\tconst signBit = header >> 7\n\tconst length = header & 0x7f\n\n\tlet mag = 0n\n\tfor (let i = 0; i < length; i++) {\n\t\tmag = (mag << 8n) | BigInt(data[ref.offset++])\n\t}\n\n\tif (signBit === 1) {\n\t\treturn -mag\n\t} else {\n\t\treturn mag\n\t}\n}\n\nfunction decodeVarintGteZero(data: Uint8Array, ref: DecodeRef): number {\n\tconst n = decodeVarint(data, ref)\n\tif (n < 0n) {\n\t\tthrow new Error('length_is_negative')\n\t}\n\tif (n > BigInt(Number.MAX_SAFE_INTEGER)) {\n\t\tthrow new Error('length_overflow')\n\t}\n\treturn Number(n)\n}\n\nfunction encodeTerm(value: SerializableValue, out: number[]): void {\n\tif (value === null) {\n\t\tout.push(TYPE_NULL)\n\t} else if (typeof value === 'boolean') {\n\t\tout.push(value ? TYPE_TRUE : TYPE_FALSE)\n\t} else if (typeof value === 'number' || typeof value === 'bigint') {\n\t\tout.push(TYPE_INT)\n\t\tencodeVarint(value, out)\n\t} else if (typeof value === 'string') {\n\t\tout.push(TYPE_BYTES)\n\t\tconst utf8 = new TextEncoder().encode(value)\n\t\tencodeVarint(utf8.length, out)\n\t\tappendBytes(out, utf8)\n\t} else if (value instanceof Uint8Array) {\n\t\tout.push(TYPE_BYTES)\n\t\tencodeVarint(value.length, out)\n\t\tappendBytes(out, value)\n\t} else if (Array.isArray(value)) {\n\t\tout.push(TYPE_LIST)\n\t\tencodeVarint(value.length, out)\n\t\tfor (const element of value) {\n\t\t\tencodeTerm(element, out)\n\t\t}\n\t} else if (\n\t\tvalue instanceof Map ||\n\t\t(typeof value === 'object' && !Array.isArray(value) && !(value instanceof Uint8Array))\n\t) {\n\t\tconst entries: Array<{ k: SerializableValue; v: SerializableValue; bytes: number[] }> = []\n\t\tif (value instanceof Map) {\n\t\t\tfor (const [k, v] of value.entries()) {\n\t\t\t\tconst bytes = encodeKeyBytes(k) // encodes key as Term\n\t\t\t\tentries.push({ k, v, bytes })\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const k of Object.keys(value)) {\n\t\t\t\tconst v = value[k]\n\t\t\t\tconst bytes = encodeKeyBytes(k) // k is string; still encoded via encodeValue\n\t\t\t\tentries.push({ k, v, bytes })\n\t\t\t}\n\t\t}\n\t\tentries.sort((a, b) => compareBytes(a.bytes, b.bytes))\n\n\t\tout.push(TYPE_MAP)\n\t\tencodeVarint(entries.length, out)\n\t\tfor (const entry of entries) {\n\t\t\tencodeTerm(entry.k, out)\n\t\t\tencodeTerm(entry.v, out)\n\t\t}\n\t} else {\n\t\tthrow new Error(`Unsupported type: ${typeof value}`)\n\t}\n}\n\nfunction decodeTerm(data: Uint8Array, ref: DecodeRef): DecodedValue {\n\tif (ref.offset >= data.length) {\n\t\tthrow new Error('decodeBytes: Out of bounds read')\n\t}\n\n\tconst type = data[ref.offset++]\n\n\tswitch (type) {\n\t\tcase TYPE_NULL:\n\t\t\treturn null\n\t\tcase TYPE_TRUE:\n\t\t\treturn true\n\t\tcase TYPE_FALSE:\n\t\t\treturn false\n\t\tcase TYPE_INT:\n\t\t\treturn decodeVarint(data, ref)\n\t\tcase TYPE_BYTES: {\n\t\t\tconst length = decodeVarintGteZero(data, ref)\n\t\t\tconst bytes = data.slice(ref.offset, ref.offset + length)\n\t\t\tref.offset += length\n\t\t\treturn bytes\n\t\t}\n\t\tcase TYPE_LIST: {\n\t\t\tconst count = decodeVarintGteZero(data, ref)\n\t\t\tconst items: DecodedValue[] = new Array(count)\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\titems[i] = decodeTerm(data, ref)\n\t\t\t}\n\t\t\treturn items\n\t\t}\n\t\tcase TYPE_MAP: {\n\t\t\tconst count = decodeVarintGteZero(data, ref)\n\n\t\t\tlet prevKeyBytes: Uint8Array | null = null\n\t\t\tconst map = new Map<DecodedValue, DecodedValue>()\n\n\t\t\tfor (let idx = 0; idx < count; idx++) {\n\t\t\t\t// canonical check: track raw key bytes\n\t\t\t\tconst kStart = ref.offset\n\t\t\t\tconst key = decodeTerm(data, ref)\n\t\t\t\tconst kEnd = ref.offset\n\t\t\t\tconst keyBytes = data.slice(kStart, kEnd)\n\n\t\t\t\tif (prevKeyBytes !== null) {\n\t\t\t\t\tif (compareBytes(keyBytes, prevKeyBytes) <= 0) {\n\t\t\t\t\t\tthrow new Error('map_not_canonical')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tprevKeyBytes = keyBytes\n\n\t\t\t\tconst value = decodeTerm(data, ref)\n\t\t\t\tmap.set(key, value)\n\t\t\t}\n\t\t\treturn map\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error('decodeBytes: Unknown type')\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAM,YAAY;AAClB,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,WAAW;AACjB,MAAM,aAAa;AACnB,MAAM,YAAY;AAClB,MAAM,WAAW;;;;;;;;;;;;;AAoBjB,SAAgB,OAAO,MAAqC;CAC3D,MAAM,WAAqB,EAAE;CAC7B,WAAW,MAAM,SAAS;CAC1B,OAAO,IAAI,WAAW,SAAS;;;;;;;;;;;;;;AAehC,SAAgB,OAAO,OAA4C;CAClE,MAAM,OAAO,iBAAiB,aAAa,QAAQ,IAAI,WAAW,MAAM;CACxE,MAAM,MAAiB,EAAE,QAAQ,GAAG;CACpC,MAAM,QAAQ,WAAW,MAAM,IAAI;CACnC,IAAI,IAAI,WAAW,KAAK,QACvB,MAAM,IAAI,MAAM,iBAAiB;CAElC,OAAO;;;;;;;;;;;;;;;;;;;;;;;AAwBR,SAAgB,oBACf,OACkC;CAElC,MAAM,UAAU,OADH,iBAAiB,cAAc,IAAI,WAAW,MAAM,GAAG,MACxC;CAE5B,IAAI,EAAE,mBAAmB,MACxB,MAAM,IAAI,MAAM,0BAA0B,OAAO,UAAU;CAG5D,MAAM,SAA0C,EAAE;CAClD,KAAK,MAAM,CAAC,KAAK,UAAU,QAAQ,SAAS,EAAE;EAC7C,IAAI,EAAE,eAAe,eAAe,EAAE,iBAAiB,aACtD,MAAM,IAAI,MAAM,wCAAwC;EAEzD,OAAO,KAAK,CAAC,KAAK,MAAM,CAAC;;CAG1B,OAAO;;AAMR,SAAS,YAAY,KAAe,OAAo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