@amadeus-protocol/sdk 1.0.8 → 1.1.1

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 (200) hide show
  1. package/README.md +215 -30
  2. package/dist/api/chain.d.ts +144 -117
  3. package/dist/api/chain.d.ts.map +1 -1
  4. package/dist/api/chain.js +175 -146
  5. package/dist/api/chain.js.map +1 -1
  6. package/dist/api/contract.d.ts +78 -60
  7. package/dist/api/contract.d.ts.map +1 -1
  8. package/dist/api/contract.js +102 -75
  9. package/dist/api/contract.js.map +1 -1
  10. package/dist/api/epoch.d.ts +65 -66
  11. package/dist/api/epoch.d.ts.map +1 -1
  12. package/dist/api/epoch.js +90 -98
  13. package/dist/api/epoch.js.map +1 -1
  14. package/dist/api/peer.d.ts +77 -78
  15. package/dist/api/peer.d.ts.map +1 -1
  16. package/dist/api/peer.js +93 -94
  17. package/dist/api/peer.js.map +1 -1
  18. package/dist/api/proof.d.ts +44 -23
  19. package/dist/api/proof.d.ts.map +1 -1
  20. package/dist/api/proof.js +56 -29
  21. package/dist/api/proof.js.map +1 -1
  22. package/dist/api/transaction.d.ts +68 -69
  23. package/dist/api/transaction.d.ts.map +1 -1
  24. package/dist/api/transaction.js +84 -84
  25. package/dist/api/transaction.js.map +1 -1
  26. package/dist/api/wallet.d.ts +36 -37
  27. package/dist/api/wallet.d.ts.map +1 -1
  28. package/dist/api/wallet.js +47 -50
  29. package/dist/api/wallet.js.map +1 -1
  30. package/dist/client.d.ts +66 -68
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +231 -276
  33. package/dist/client.js.map +1 -1
  34. package/dist/constants.d.ts +13 -10
  35. package/dist/constants.d.ts.map +1 -1
  36. package/dist/constants.js +49 -45
  37. package/dist/constants.js.map +1 -1
  38. package/dist/contract-state.d.ts +6 -3
  39. package/dist/contract-state.d.ts.map +1 -1
  40. package/dist/contract-state.js +88 -106
  41. package/dist/contract-state.js.map +1 -1
  42. package/dist/contracts/abi-types.d.ts +32 -32
  43. package/dist/contracts/abi-types.d.ts.map +1 -1
  44. package/dist/contracts/coin.d.ts +13 -20
  45. package/dist/contracts/coin.d.ts.map +1 -1
  46. package/dist/contracts/coin.js +42 -38
  47. package/dist/contracts/coin.js.map +1 -1
  48. package/dist/contracts/contract-call.d.ts +14 -16
  49. package/dist/contracts/contract-call.d.ts.map +1 -1
  50. package/dist/contracts/contract-call.js +45 -54
  51. package/dist/contracts/contract-call.js.map +1 -1
  52. package/dist/contracts/contract.d.ts +24 -55
  53. package/dist/contracts/contract.d.ts.map +1 -1
  54. package/dist/contracts/contract.js +63 -101
  55. package/dist/contracts/contract.js.map +1 -1
  56. package/dist/contracts/lockup/abi.d.ts +54 -51
  57. package/dist/contracts/lockup/abi.d.ts.map +1 -1
  58. package/dist/contracts/lockup/abi.js +65 -74
  59. package/dist/contracts/lockup/abi.js.map +1 -1
  60. package/dist/contracts/lockup/helpers.d.ts +22 -18
  61. package/dist/contracts/lockup/helpers.d.ts.map +1 -1
  62. package/dist/contracts/lockup/helpers.js +44 -47
  63. package/dist/contracts/lockup/helpers.js.map +1 -1
  64. package/dist/contracts/lockup/parsers.d.ts +7 -3
  65. package/dist/contracts/lockup/parsers.d.ts.map +1 -1
  66. package/dist/contracts/lockup/parsers.js +51 -55
  67. package/dist/contracts/lockup/parsers.js.map +1 -1
  68. package/dist/contracts/lockup/storage-keys.d.ts +5 -2
  69. package/dist/contracts/lockup/storage-keys.d.ts.map +1 -1
  70. package/dist/contracts/lockup/storage-keys.js +54 -70
  71. package/dist/contracts/lockup/storage-keys.js.map +1 -1
  72. package/dist/contracts/lockup/types.d.ts +73 -70
  73. package/dist/contracts/lockup/types.d.ts.map +1 -1
  74. package/dist/contracts/lockup-prime/abi.d.ts +328 -325
  75. package/dist/contracts/lockup-prime/abi.d.ts.map +1 -1
  76. package/dist/contracts/lockup-prime/abi.js +397 -417
  77. package/dist/contracts/lockup-prime/abi.js.map +1 -1
  78. package/dist/contracts/lockup-prime/helpers.d.ts +35 -31
  79. package/dist/contracts/lockup-prime/helpers.d.ts.map +1 -1
  80. package/dist/contracts/lockup-prime/helpers.js +131 -137
  81. package/dist/contracts/lockup-prime/helpers.js.map +1 -1
  82. package/dist/contracts/lockup-prime/parsers.d.ts +9 -5
  83. package/dist/contracts/lockup-prime/parsers.d.ts.map +1 -1
  84. package/dist/contracts/lockup-prime/parsers.js +61 -61
  85. package/dist/contracts/lockup-prime/parsers.js.map +1 -1
  86. package/dist/contracts/lockup-prime/storage-keys.d.ts +7 -4
  87. package/dist/contracts/lockup-prime/storage-keys.d.ts.map +1 -1
  88. package/dist/contracts/lockup-prime/storage-keys.js +64 -80
  89. package/dist/contracts/lockup-prime/storage-keys.js.map +1 -1
  90. package/dist/contracts/lockup-prime/types.d.ts +92 -89
  91. package/dist/contracts/lockup-prime/types.d.ts.map +1 -1
  92. package/dist/contracts/lockup-prime/types.js +12 -13
  93. package/dist/contracts/lockup-prime/types.js.map +1 -1
  94. package/dist/contracts/nft/abi.d.ts +104 -0
  95. package/dist/contracts/nft/abi.d.ts.map +1 -0
  96. package/dist/contracts/nft/abi.js +135 -0
  97. package/dist/contracts/nft/abi.js.map +1 -0
  98. package/dist/contracts/nft/helpers.d.ts +21 -0
  99. package/dist/contracts/nft/helpers.d.ts.map +1 -0
  100. package/dist/contracts/nft/helpers.js +61 -0
  101. package/dist/contracts/nft/helpers.js.map +1 -0
  102. package/dist/contracts/nft/types.d.ts +47 -0
  103. package/dist/contracts/nft/types.d.ts.map +1 -0
  104. package/dist/conversion.d.ts +5 -2
  105. package/dist/conversion.d.ts.map +1 -1
  106. package/dist/conversion.js +45 -50
  107. package/dist/conversion.js.map +1 -1
  108. package/dist/crypto.d.ts +14 -16
  109. package/dist/crypto.d.ts.map +1 -1
  110. package/dist/crypto.js +121 -140
  111. package/dist/crypto.js.map +1 -1
  112. package/dist/encoding.d.ts +11 -8
  113. package/dist/encoding.d.ts.map +1 -1
  114. package/dist/encoding.js +123 -144
  115. package/dist/encoding.js.map +1 -1
  116. package/dist/encryption.d.ts +15 -12
  117. package/dist/encryption.d.ts.map +1 -1
  118. package/dist/encryption.js +119 -117
  119. package/dist/encryption.js.map +1 -1
  120. package/dist/explorer.d.ts +10 -7
  121. package/dist/explorer.d.ts.map +1 -1
  122. package/dist/explorer.js +51 -48
  123. package/dist/explorer.js.map +1 -1
  124. package/dist/formatters.d.ts +8 -5
  125. package/dist/formatters.d.ts.map +1 -1
  126. package/dist/formatters.js +67 -68
  127. package/dist/formatters.js.map +1 -1
  128. package/dist/index.d.ts +42 -55
  129. package/dist/index.js +39 -55
  130. package/dist/mnemonic.d.ts +12 -9
  131. package/dist/mnemonic.d.ts.map +1 -1
  132. package/dist/mnemonic.js +105 -114
  133. package/dist/mnemonic.js.map +1 -1
  134. package/dist/networks.d.ts +14 -17
  135. package/dist/networks.d.ts.map +1 -1
  136. package/dist/networks.js +40 -36
  137. package/dist/networks.js.map +1 -1
  138. package/dist/schemas.js +75 -79
  139. package/dist/schemas.js.map +1 -1
  140. package/dist/sdk.d.ts +69 -65
  141. package/dist/sdk.d.ts.map +1 -1
  142. package/dist/sdk.js +126 -117
  143. package/dist/sdk.js.map +1 -1
  144. package/dist/serialization.d.ts +8 -18
  145. package/dist/serialization.d.ts.map +1 -1
  146. package/dist/serialization.js +207 -260
  147. package/dist/serialization.js.map +1 -1
  148. package/dist/signing.js +67 -67
  149. package/dist/signing.js.map +1 -1
  150. package/dist/transaction-builder.d.ts +175 -184
  151. package/dist/transaction-builder.d.ts.map +1 -1
  152. package/dist/transaction-builder.js +295 -344
  153. package/dist/transaction-builder.js.map +1 -1
  154. package/dist/transaction-errors.d.ts +10 -12
  155. package/dist/transaction-errors.d.ts.map +1 -1
  156. package/dist/transaction-errors.js +145 -166
  157. package/dist/transaction-errors.js.map +1 -1
  158. package/dist/types.d.ts +530 -450
  159. package/dist/types.d.ts.map +1 -1
  160. package/dist/types.js +169 -183
  161. package/dist/types.js.map +1 -1
  162. package/dist/validation.d.ts +24 -26
  163. package/dist/validation.d.ts.map +1 -1
  164. package/dist/validation.js +194 -192
  165. package/dist/validation.js.map +1 -1
  166. package/package.json +4 -3
  167. package/dist/api/index.d.ts +0 -8
  168. package/dist/api/index.d.ts.map +0 -1
  169. package/dist/api/index.js +0 -8
  170. package/dist/api/index.js.map +0 -1
  171. package/dist/contracts/abi-types.js +0 -8
  172. package/dist/contracts/abi-types.js.map +0 -1
  173. package/dist/contracts/index.d.ts +0 -7
  174. package/dist/contracts/index.d.ts.map +0 -1
  175. package/dist/contracts/index.js +0 -7
  176. package/dist/contracts/index.js.map +0 -1
  177. package/dist/contracts/lockup/calls.d.ts +0 -23
  178. package/dist/contracts/lockup/calls.d.ts.map +0 -1
  179. package/dist/contracts/lockup/calls.js +0 -25
  180. package/dist/contracts/lockup/calls.js.map +0 -1
  181. package/dist/contracts/lockup/index.d.ts +0 -6
  182. package/dist/contracts/lockup/index.d.ts.map +0 -1
  183. package/dist/contracts/lockup/index.js +0 -6
  184. package/dist/contracts/lockup/index.js.map +0 -1
  185. package/dist/contracts/lockup/types.js +0 -7
  186. package/dist/contracts/lockup/types.js.map +0 -1
  187. package/dist/contracts/lockup-prime/calls.d.ts +0 -53
  188. package/dist/contracts/lockup-prime/calls.d.ts.map +0 -1
  189. package/dist/contracts/lockup-prime/calls.js +0 -60
  190. package/dist/contracts/lockup-prime/calls.js.map +0 -1
  191. package/dist/contracts/lockup-prime/index.d.ts +0 -6
  192. package/dist/contracts/lockup-prime/index.d.ts.map +0 -1
  193. package/dist/contracts/lockup-prime/index.js +0 -6
  194. package/dist/contracts/lockup-prime/index.js.map +0 -1
  195. package/dist/index.d.ts.map +0 -1
  196. package/dist/index.js.map +0 -1
  197. package/dist/schemas.d.ts +0 -67
  198. package/dist/schemas.d.ts.map +0 -1
  199. package/dist/signing.d.ts +0 -39
  200. package/dist/signing.d.ts.map +0 -1
package/dist/encoding.js CHANGED
@@ -1,165 +1,144 @@
1
+ import bs58 from "bs58";
2
+ //#region src/encoding.ts
1
3
  /**
2
- * Encoding/Decoding Utilities
3
- *
4
- * Provides general-purpose encoding and decoding functions for converting
5
- * between different binary formats (Uint8Array, ArrayBuffer, Base64, Base58)
6
- */
7
- import bs58 from 'bs58';
8
- // ============================================================================
9
- // Base64 Encoding/Decoding
10
- // ============================================================================
4
+ * Encoding/Decoding Utilities
5
+ *
6
+ * Provides general-purpose encoding and decoding functions for converting
7
+ * between different binary formats (Uint8Array, ArrayBuffer, Base64, Base58)
8
+ */
11
9
  /**
12
- * Check if Buffer is available (Node.js environment)
13
- */
10
+ * Check if Buffer is available (Node.js environment)
11
+ */
14
12
  function isBufferAvailable() {
15
- return typeof Buffer !== 'undefined' && Buffer.from !== undefined;
13
+ return typeof Buffer !== "undefined" && Buffer.from !== void 0;
16
14
  }
17
15
  /**
18
- * Convert Uint8Array to Base64 string
19
- *
20
- * Uses Node.js Buffer when available (more efficient), falls back to btoa for browsers.
21
- *
22
- * @param bytes - Bytes to encode
23
- * @returns Base64 encoded string
24
- *
25
- * @example
26
- * ```ts
27
- * const base64 = uint8ArrayToBase64(new Uint8Array([1, 2, 3]))
28
- * ```
29
- */
30
- export function uint8ArrayToBase64(bytes) {
31
- if (isBufferAvailable()) {
32
- // Node.js: Use Buffer for better performance
33
- return Buffer.from(bytes).toString('base64');
34
- }
35
- // Browser: Use btoa (available in Node.js 18+ and all modern browsers)
36
- let binary = '';
37
- for (let i = 0; i < bytes.byteLength; i++) {
38
- binary += String.fromCharCode(bytes[i]);
39
- }
40
- return btoa(binary);
16
+ * Convert Uint8Array to Base64 string
17
+ *
18
+ * Uses Node.js Buffer when available (more efficient), falls back to btoa for browsers.
19
+ *
20
+ * @param bytes - Bytes to encode
21
+ * @returns Base64 encoded string
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const base64 = uint8ArrayToBase64(new Uint8Array([1, 2, 3]))
26
+ * ```
27
+ */
28
+ function uint8ArrayToBase64(bytes) {
29
+ if (isBufferAvailable()) return Buffer.from(bytes).toString("base64");
30
+ let binary = "";
31
+ for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
32
+ return btoa(binary);
41
33
  }
42
34
  /**
43
- * Convert Base64 string to Uint8Array
44
- *
45
- * Uses Node.js Buffer when available (more efficient), falls back to atob for browsers.
46
- *
47
- * @param base64 - Base64 encoded string
48
- * @returns Decoded bytes
49
- *
50
- * @example
51
- * ```ts
52
- * const bytes = base64ToUint8Array('AQID')
53
- * ```
54
- */
55
- export function base64ToUint8Array(base64) {
56
- if (isBufferAvailable()) {
57
- // Node.js: Use Buffer for better performance
58
- return new Uint8Array(Buffer.from(base64, 'base64'));
59
- }
60
- // Browser: Use atob (available in Node.js 18+ and all modern browsers)
61
- const binaryString = atob(base64);
62
- const bytes = new Uint8Array(binaryString.length);
63
- for (let i = 0; i < binaryString.length; i++) {
64
- bytes[i] = binaryString.charCodeAt(i);
65
- }
66
- return bytes;
35
+ * Convert Base64 string to Uint8Array
36
+ *
37
+ * Uses Node.js Buffer when available (more efficient), falls back to atob for browsers.
38
+ *
39
+ * @param base64 - Base64 encoded string
40
+ * @returns Decoded bytes
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const bytes = base64ToUint8Array('AQID')
45
+ * ```
46
+ */
47
+ function base64ToUint8Array(base64) {
48
+ if (isBufferAvailable()) return new Uint8Array(Buffer.from(base64, "base64"));
49
+ const binaryString = atob(base64);
50
+ const bytes = new Uint8Array(binaryString.length);
51
+ for (let i = 0; i < binaryString.length; i++) bytes[i] = binaryString.charCodeAt(i);
52
+ return bytes;
67
53
  }
68
54
  /**
69
- * Convert ArrayBuffer to Base64 string
70
- *
71
- * @param buffer - Buffer to encode
72
- * @returns Base64 encoded string
73
- *
74
- * @example
75
- * ```ts
76
- * const base64 = arrayBufferToBase64(new ArrayBuffer(8))
77
- * ```
78
- */
79
- export function arrayBufferToBase64(buffer) {
80
- const bytes = new Uint8Array(buffer);
81
- return uint8ArrayToBase64(bytes);
55
+ * Convert ArrayBuffer to Base64 string
56
+ *
57
+ * @param buffer - Buffer to encode
58
+ * @returns Base64 encoded string
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const base64 = arrayBufferToBase64(new ArrayBuffer(8))
63
+ * ```
64
+ */
65
+ function arrayBufferToBase64(buffer) {
66
+ return uint8ArrayToBase64(new Uint8Array(buffer));
82
67
  }
83
68
  /**
84
- * Convert Base64 string to ArrayBuffer
85
- *
86
- * @param base64 - Base64 encoded string
87
- * @returns Decoded buffer
88
- *
89
- * @example
90
- * ```ts
91
- * const buffer = base64ToArrayBuffer('AQID')
92
- * ```
93
- */
94
- export function base64ToArrayBuffer(base64) {
95
- const bytes = base64ToUint8Array(base64);
96
- const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
97
- return buffer;
69
+ * Convert Base64 string to ArrayBuffer
70
+ *
71
+ * @param base64 - Base64 encoded string
72
+ * @returns Decoded buffer
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * const buffer = base64ToArrayBuffer('AQID')
77
+ * ```
78
+ */
79
+ function base64ToArrayBuffer(base64) {
80
+ const bytes = base64ToUint8Array(base64);
81
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
98
82
  }
99
- // ============================================================================
100
- // ArrayBuffer/Uint8Array Conversions
101
- // ============================================================================
102
83
  /**
103
- * Convert Uint8Array to ArrayBuffer
104
- *
105
- * @param bytes - The Uint8Array to convert
106
- * @returns ArrayBuffer
107
- *
108
- * @example
109
- * ```ts
110
- * const buffer = uint8ArrayToArrayBuffer(new Uint8Array([1, 2, 3]))
111
- * ```
112
- */
113
- export function uint8ArrayToArrayBuffer(bytes) {
114
- if (bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength) {
115
- return bytes.buffer;
116
- }
117
- return bytes.slice().buffer;
84
+ * Convert Uint8Array to ArrayBuffer
85
+ *
86
+ * @param bytes - The Uint8Array to convert
87
+ * @returns ArrayBuffer
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const buffer = uint8ArrayToArrayBuffer(new Uint8Array([1, 2, 3]))
92
+ * ```
93
+ */
94
+ function uint8ArrayToArrayBuffer(bytes) {
95
+ if (bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength) return bytes.buffer;
96
+ return bytes.slice().buffer;
118
97
  }
119
98
  /**
120
- * Convert ArrayBuffer to Uint8Array
121
- *
122
- * @param buffer - The ArrayBuffer to convert
123
- * @returns Uint8Array view of the buffer
124
- *
125
- * @example
126
- * ```ts
127
- * const bytes = arrayBufferToUint8Array(new ArrayBuffer(8))
128
- * ```
129
- */
130
- export function arrayBufferToUint8Array(buffer) {
131
- return new Uint8Array(buffer);
99
+ * Convert ArrayBuffer to Uint8Array
100
+ *
101
+ * @param buffer - The ArrayBuffer to convert
102
+ * @returns Uint8Array view of the buffer
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const bytes = arrayBufferToUint8Array(new ArrayBuffer(8))
107
+ * ```
108
+ */
109
+ function arrayBufferToUint8Array(buffer) {
110
+ return new Uint8Array(buffer);
132
111
  }
133
- // ============================================================================
134
- // Base58 Encoding/Decoding
135
- // ============================================================================
136
112
  /**
137
- * Encode a Uint8Array to Base58 string
138
- *
139
- * @param buf - The bytes to encode
140
- * @returns Base58 encoded string
141
- *
142
- * @example
143
- * ```ts
144
- * const encoded = toBase58(new Uint8Array([1, 2, 3]))
145
- * ```
146
- */
147
- export function toBase58(buf) {
148
- return bs58.encode(buf);
113
+ * Encode a Uint8Array to Base58 string
114
+ *
115
+ * @param buf - The bytes to encode
116
+ * @returns Base58 encoded string
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * const encoded = toBase58(new Uint8Array([1, 2, 3]))
121
+ * ```
122
+ */
123
+ function toBase58(buf) {
124
+ return bs58.encode(buf);
149
125
  }
150
126
  /**
151
- * Decode a Base58 string to Uint8Array
152
- *
153
- * @param str - The Base58 string to decode
154
- * @returns Decoded bytes as Uint8Array
155
- * @throws Error if the string is invalid Base58
156
- *
157
- * @example
158
- * ```ts
159
- * const decoded = fromBase58('5Kd3N...')
160
- * ```
161
- */
162
- export function fromBase58(str) {
163
- return bs58.decode(str);
127
+ * Decode a Base58 string to Uint8Array
128
+ *
129
+ * @param str - The Base58 string to decode
130
+ * @returns Decoded bytes as Uint8Array
131
+ * @throws Error if the string is invalid Base58
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const decoded = fromBase58('5Kd3N...')
136
+ * ```
137
+ */
138
+ function fromBase58(str) {
139
+ return bs58.decode(str);
164
140
  }
141
+ //#endregion
142
+ export { arrayBufferToBase64, arrayBufferToUint8Array, base64ToArrayBuffer, base64ToUint8Array, fromBase58, toBase58, uint8ArrayToArrayBuffer, uint8ArrayToBase64 };
143
+
165
144
  //# sourceMappingURL=encoding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"encoding.js","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"encoding.js","names":[],"sources":["../src/encoding.ts"],"sourcesContent":["/**\n * Encoding/Decoding Utilities\n *\n * Provides general-purpose encoding and decoding functions for converting\n * between different binary formats (Uint8Array, ArrayBuffer, Base64, Base58)\n */\n\nimport bs58 from 'bs58'\n\n// ============================================================================\n// Base64 Encoding/Decoding\n// ============================================================================\n\n/**\n * Check if Buffer is available (Node.js environment)\n */\nfunction isBufferAvailable(): boolean {\n\treturn typeof Buffer !== 'undefined' && Buffer.from !== undefined\n}\n\n/**\n * Convert Uint8Array to Base64 string\n *\n * Uses Node.js Buffer when available (more efficient), falls back to btoa for browsers.\n *\n * @param bytes - Bytes to encode\n * @returns Base64 encoded string\n *\n * @example\n * ```ts\n * const base64 = uint8ArrayToBase64(new Uint8Array([1, 2, 3]))\n * ```\n */\nexport function uint8ArrayToBase64(bytes: Uint8Array): string {\n\tif (isBufferAvailable()) {\n\t\t// Node.js: Use Buffer for better performance\n\t\treturn Buffer.from(bytes).toString('base64')\n\t}\n\t// Browser: Use btoa (available in Node.js 18+ and all modern browsers)\n\tlet binary = ''\n\tfor (let i = 0; i < bytes.byteLength; i++) {\n\t\tbinary += String.fromCharCode(bytes[i])\n\t}\n\treturn btoa(binary)\n}\n\n/**\n * Convert Base64 string to Uint8Array\n *\n * Uses Node.js Buffer when available (more efficient), falls back to atob for browsers.\n *\n * @param base64 - Base64 encoded string\n * @returns Decoded bytes\n *\n * @example\n * ```ts\n * const bytes = base64ToUint8Array('AQID')\n * ```\n */\nexport function base64ToUint8Array(base64: string): Uint8Array {\n\tif (isBufferAvailable()) {\n\t\t// Node.js: Use Buffer for better performance\n\t\treturn new Uint8Array(Buffer.from(base64, 'base64'))\n\t}\n\t// Browser: Use atob (available in Node.js 18+ and all modern browsers)\n\tconst binaryString = atob(base64)\n\tconst bytes = new Uint8Array(binaryString.length)\n\tfor (let i = 0; i < binaryString.length; i++) {\n\t\tbytes[i] = binaryString.charCodeAt(i)\n\t}\n\treturn bytes\n}\n\n/**\n * Convert ArrayBuffer to Base64 string\n *\n * @param buffer - Buffer to encode\n * @returns Base64 encoded string\n *\n * @example\n * ```ts\n * const base64 = arrayBufferToBase64(new ArrayBuffer(8))\n * ```\n */\nexport function arrayBufferToBase64(buffer: ArrayBuffer): string {\n\tconst bytes = new Uint8Array(buffer)\n\treturn uint8ArrayToBase64(bytes)\n}\n\n/**\n * Convert Base64 string to ArrayBuffer\n *\n * @param base64 - Base64 encoded string\n * @returns Decoded buffer\n *\n * @example\n * ```ts\n * const buffer = base64ToArrayBuffer('AQID')\n * ```\n */\nexport function base64ToArrayBuffer(base64: string): ArrayBuffer {\n\tconst bytes = base64ToUint8Array(base64)\n\tconst buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)\n\treturn buffer as ArrayBuffer\n}\n\n// ============================================================================\n// ArrayBuffer/Uint8Array Conversions\n// ============================================================================\n\n/**\n * Convert Uint8Array to ArrayBuffer\n *\n * @param bytes - The Uint8Array to convert\n * @returns ArrayBuffer\n *\n * @example\n * ```ts\n * const buffer = uint8ArrayToArrayBuffer(new Uint8Array([1, 2, 3]))\n * ```\n */\nexport function uint8ArrayToArrayBuffer(bytes: Uint8Array): ArrayBuffer {\n\tif (bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength) {\n\t\treturn bytes.buffer as ArrayBuffer\n\t}\n\treturn bytes.slice().buffer\n}\n\n/**\n * Convert ArrayBuffer to Uint8Array\n *\n * @param buffer - The ArrayBuffer to convert\n * @returns Uint8Array view of the buffer\n *\n * @example\n * ```ts\n * const bytes = arrayBufferToUint8Array(new ArrayBuffer(8))\n * ```\n */\nexport function arrayBufferToUint8Array(buffer: ArrayBuffer): Uint8Array {\n\treturn new Uint8Array(buffer)\n}\n\n// ============================================================================\n// Base58 Encoding/Decoding\n// ============================================================================\n\n/**\n * Encode a Uint8Array to Base58 string\n *\n * @param buf - The bytes to encode\n * @returns Base58 encoded string\n *\n * @example\n * ```ts\n * const encoded = toBase58(new Uint8Array([1, 2, 3]))\n * ```\n */\nexport function toBase58(buf: Uint8Array): string {\n\treturn bs58.encode(buf)\n}\n\n/**\n * Decode a Base58 string to Uint8Array\n *\n * @param str - The Base58 string to decode\n * @returns Decoded bytes as Uint8Array\n * @throws Error if the string is invalid Base58\n *\n * @example\n * ```ts\n * const decoded = fromBase58('5Kd3N...')\n * ```\n */\nexport function fromBase58(str: string): Uint8Array {\n\treturn bs58.decode(str)\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAS,oBAA6B;CACrC,OAAO,OAAO,WAAW,eAAe,OAAO,SAAS,KAAA;;;;;;;;;;;;;;;AAgBzD,SAAgB,mBAAmB,OAA2B;CAC7D,IAAI,mBAAmB,EAEtB,OAAO,OAAO,KAAK,MAAM,CAAC,SAAS,SAAS;CAG7C,IAAI,SAAS;CACb,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,YAAY,KACrC,UAAU,OAAO,aAAa,MAAM,GAAG;CAExC,OAAO,KAAK,OAAO;;;;;;;;;;;;;;;AAgBpB,SAAgB,mBAAmB,QAA4B;CAC9D,IAAI,mBAAmB,EAEtB,OAAO,IAAI,WAAW,OAAO,KAAK,QAAQ,SAAS,CAAC;CAGrD,MAAM,eAAe,KAAK,OAAO;CACjC,MAAM,QAAQ,IAAI,WAAW,aAAa,OAAO;CACjD,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACxC,MAAM,KAAK,aAAa,WAAW,EAAE;CAEtC,OAAO;;;;;;;;;;;;;AAcR,SAAgB,oBAAoB,QAA6B;CAEhE,OAAO,mBAAmB,IADR,WAAW,OACE,CAAC;;;;;;;;;;;;;AAcjC,SAAgB,oBAAoB,QAA6B;CAChE,MAAM,QAAQ,mBAAmB,OAAO;CAExC,OADe,MAAM,OAAO,MAAM,MAAM,YAAY,MAAM,aAAa,MAAM,WAChE;;;;;;;;;;;;;AAkBd,SAAgB,wBAAwB,OAAgC;CACvE,IAAI,MAAM,eAAe,KAAK,MAAM,eAAe,MAAM,OAAO,YAC/D,OAAO,MAAM;CAEd,OAAO,MAAM,OAAO,CAAC;;;;;;;;;;;;;AActB,SAAgB,wBAAwB,QAAiC;CACxE,OAAO,IAAI,WAAW,OAAO;;;;;;;;;;;;;AAkB9B,SAAgB,SAAS,KAAyB;CACjD,OAAO,KAAK,OAAO,IAAI;;;;;;;;;;;;;;AAexB,SAAgB,WAAW,KAAyB;CACnD,OAAO,KAAK,OAAO,IAAI"}
@@ -1,3 +1,4 @@
1
+ //#region src/encryption.d.ts
1
2
  /**
2
3
  * Password-Based Encryption Utilities
3
4
  *
@@ -12,32 +13,32 @@
12
13
  * @param iterations - Number of PBKDF2 iterations (default: 100,000)
13
14
  * @returns Derived AES-GCM key
14
15
  */
15
- export declare function deriveKey(password: string, salt: Uint8Array | ArrayBuffer, iterations?: number): Promise<CryptoKey>;
16
+ declare function deriveKey(password: string, salt: Uint8Array | ArrayBuffer, iterations?: number): Promise<CryptoKey>;
16
17
  /**
17
18
  * Generate a cryptographically secure random salt
18
19
  *
19
20
  * @returns Random salt (16 bytes)
20
21
  */
21
- export declare function generateSalt(): Uint8Array;
22
+ declare function generateSalt(): Uint8Array;
22
23
  /**
23
24
  * Generate a cryptographically secure random initialization vector
24
25
  *
25
26
  * @returns Random IV (12 bytes)
26
27
  */
27
- export declare function generateIV(): Uint8Array;
28
+ declare function generateIV(): Uint8Array;
28
29
  /**
29
30
  * Encrypted data payload (Base64 encoded)
30
31
  *
31
32
  * Uses Base64 encoding for binary payloads like vaults (more efficient than Base58).
32
33
  * Base58 is reserved for addresses, keys, and hashes.
33
34
  */
34
- export interface EncryptedPayload {
35
- /** Encrypted data (Base64 encoded) */
36
- encryptedData: string;
37
- /** Initialization vector (Base64 encoded) */
38
- iv: string;
39
- /** Salt used for key derivation (Base64 encoded) */
40
- salt: string;
35
+ interface EncryptedPayload {
36
+ /** Encrypted data (Base64 encoded) */
37
+ encryptedData: string;
38
+ /** Initialization vector (Base64 encoded) */
39
+ iv: string;
40
+ /** Salt used for key derivation (Base64 encoded) */
41
+ salt: string;
41
42
  }
42
43
  /**
43
44
  * Encrypt plaintext with a password using AES-GCM
@@ -58,7 +59,7 @@ export interface EncryptedPayload {
58
59
  * // Store encrypted.encryptedData, encrypted.iv, encrypted.salt
59
60
  * ```
60
61
  */
61
- export declare function encryptWithPassword(plaintext: string, password: string): Promise<EncryptedPayload>;
62
+ declare function encryptWithPassword(plaintext: string, password: string): Promise<EncryptedPayload>;
62
63
  /**
63
64
  * Decrypt encrypted data with a password
64
65
  *
@@ -72,5 +73,7 @@ export declare function encryptWithPassword(plaintext: string, password: string)
72
73
  * const decrypted = await decryptWithPassword(encrypted, 'my-password')
73
74
  * ```
74
75
  */
75
- export declare function decryptWithPassword(payload: EncryptedPayload, password: string): Promise<string>;
76
+ declare function decryptWithPassword(payload: EncryptedPayload, password: string): Promise<string>;
77
+ //#endregion
78
+ export { EncryptedPayload, decryptWithPassword, deriveKey, encryptWithPassword, generateIV, generateSalt };
76
79
  //# sourceMappingURL=encryption.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../src/encryption.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqCH;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAC9B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,UAAU,GAAE,MAA0B,GACpC,OAAO,CAAC,SAAS,CAAC,CAgBpB;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,UAAU,CAIzC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,IAAI,UAAU,CAIvC;AAMD;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAA;IACrB,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAA;IACV,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAA;CACZ;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,mBAAmB,CACxC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,gBAAgB,CAAC,CAkB3B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
1
+ {"version":3,"file":"encryption.d.ts","names":[],"sources":["../src/encryption.ts"],"mappings":";;AAkDA;;;;;;;;;;;;;iBAAsB,SAAA,CACrB,QAAA,UACA,IAAA,EAAM,UAAA,GAAa,WAAA,EACnB,UAAA,YACE,OAAA,CAAQ,SAAA;;;;;AA2BX;iBAAgB,YAAA,CAAA,GAAgB,UAAA;;;;AAWhC;;iBAAgB,UAAA,CAAA,GAAc,UAAA;;;AAgB9B;;;;UAAiB,gBAAA;EAIhB;EAFA,aAAA;EAII;EAFJ,EAAA;EAwBqB;EAtBrB,IAAA;AAAA;;;;;;;;AA0DD;;;;;;;;;;;;iBApCsB,mBAAA,CACrB,SAAA,UACA,QAAA,WACE,OAAA,CAAQ,gBAAA;;;;;;;;;;;;;;iBAiCW,mBAAA,CACrB,OAAA,EAAS,gBAAA,EACT,QAAA,WACE,OAAA"}
@@ -1,137 +1,139 @@
1
+ import { base64ToUint8Array, uint8ArrayToArrayBuffer, uint8ArrayToBase64 } from "./encoding.js";
2
+ //#region src/encryption.ts
1
3
  /**
2
- * Password-Based Encryption Utilities
3
- *
4
- * Provides secure password-based encryption using PBKDF2 key derivation
5
- * and AES-GCM encryption. Suitable for encrypting sensitive wallet data.
6
- */
7
- import { uint8ArrayToBase64, base64ToUint8Array } from './encoding';
8
- import { uint8ArrayToArrayBuffer } from './encoding';
9
- // ============================================================================
10
- // Constants
11
- // ============================================================================
4
+ * Password-Based Encryption Utilities
5
+ *
6
+ * Provides secure password-based encryption using PBKDF2 key derivation
7
+ * and AES-GCM encryption. Suitable for encrypting sensitive wallet data.
8
+ */
12
9
  /**
13
- * PBKDF2 iterations for key derivation (100,000 iterations for security)
14
- * Matches web wallet implementation for consistency
15
- */
16
- const PBKDF2_ITERATIONS = 100_000;
10
+ * PBKDF2 iterations for key derivation (100,000 iterations for security)
11
+ * Matches web wallet implementation for consistency
12
+ */
13
+ const PBKDF2_ITERATIONS = 1e5;
17
14
  /**
18
- * Salt length in bytes (128 bits)
19
- */
15
+ * Salt length in bytes (128 bits)
16
+ */
20
17
  const SALT_LENGTH = 16;
21
18
  /**
22
- * IV length in bytes for AES-GCM (96 bits)
23
- */
19
+ * IV length in bytes for AES-GCM (96 bits)
20
+ */
24
21
  const IV_LENGTH = 12;
25
- // ============================================================================
26
- // Helper Functions
27
- // ============================================================================
28
22
  /**
29
- * Import password as a PBKDF2 key
30
- */
23
+ * Import password as a PBKDF2 key
24
+ */
31
25
  async function importPbkdf2Key(password) {
32
- const enc = new TextEncoder();
33
- return crypto.subtle.importKey('raw', enc.encode(password), 'PBKDF2', false, ['deriveKey']);
26
+ const enc = new TextEncoder();
27
+ return crypto.subtle.importKey("raw", enc.encode(password), "PBKDF2", false, ["deriveKey"]);
34
28
  }
35
29
  /**
36
- * Derive a cryptographic key from a password using PBKDF2
37
- *
38
- * @param password - Password string
39
- * @param salt - Salt as Uint8Array or ArrayBuffer
40
- * @param iterations - Number of PBKDF2 iterations (default: 100,000)
41
- * @returns Derived AES-GCM key
42
- */
43
- export async function deriveKey(password, salt, iterations = PBKDF2_ITERATIONS) {
44
- const baseKey = await importPbkdf2Key(password);
45
- const saltBuffer = salt instanceof Uint8Array ? uint8ArrayToArrayBuffer(salt) : salt;
46
- return crypto.subtle.deriveKey({
47
- name: 'PBKDF2',
48
- salt: saltBuffer,
49
- iterations,
50
- hash: 'SHA-256'
51
- }, baseKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
30
+ * Derive a cryptographic key from a password using PBKDF2
31
+ *
32
+ * @param password - Password string
33
+ * @param salt - Salt as Uint8Array or ArrayBuffer
34
+ * @param iterations - Number of PBKDF2 iterations (default: 100,000)
35
+ * @returns Derived AES-GCM key
36
+ */
37
+ async function deriveKey(password, salt, iterations = PBKDF2_ITERATIONS) {
38
+ const baseKey = await importPbkdf2Key(password);
39
+ const saltBuffer = salt instanceof Uint8Array ? uint8ArrayToArrayBuffer(salt) : salt;
40
+ return crypto.subtle.deriveKey({
41
+ name: "PBKDF2",
42
+ salt: saltBuffer,
43
+ iterations,
44
+ hash: "SHA-256"
45
+ }, baseKey, {
46
+ name: "AES-GCM",
47
+ length: 256
48
+ }, false, ["encrypt", "decrypt"]);
52
49
  }
53
- // ============================================================================
54
- // Random Generation
55
- // ============================================================================
56
50
  /**
57
- * Generate a cryptographically secure random salt
58
- *
59
- * @returns Random salt (16 bytes)
60
- */
61
- export function generateSalt() {
62
- const salt = new Uint8Array(SALT_LENGTH);
63
- crypto.getRandomValues(salt);
64
- return salt;
51
+ * Generate a cryptographically secure random salt
52
+ *
53
+ * @returns Random salt (16 bytes)
54
+ */
55
+ function generateSalt() {
56
+ const salt = new Uint8Array(SALT_LENGTH);
57
+ crypto.getRandomValues(salt);
58
+ return salt;
65
59
  }
66
60
  /**
67
- * Generate a cryptographically secure random initialization vector
68
- *
69
- * @returns Random IV (12 bytes)
70
- */
71
- export function generateIV() {
72
- const iv = new Uint8Array(IV_LENGTH);
73
- crypto.getRandomValues(iv);
74
- return iv;
61
+ * Generate a cryptographically secure random initialization vector
62
+ *
63
+ * @returns Random IV (12 bytes)
64
+ */
65
+ function generateIV() {
66
+ const iv = new Uint8Array(IV_LENGTH);
67
+ crypto.getRandomValues(iv);
68
+ return iv;
75
69
  }
76
70
  /**
77
- * Encrypt plaintext with a password using AES-GCM
78
- *
79
- * Uses PBKDF2 for key derivation and Base64 encoding for output.
80
- * Suitable for encrypting sensitive wallet data like private keys.
81
- *
82
- * **Encoding Standard**: Uses Base64 encoding for binary payloads (RFC 4648).
83
- * Base58 is used for addresses, keys, and hashes elsewhere in the SDK.
84
- *
85
- * @param plaintext - Plaintext string to encrypt
86
- * @param password - Password for encryption
87
- * @returns Encrypted payload with encryptedData, IV, and salt (all Base64 encoded)
88
- *
89
- * @example
90
- * ```ts
91
- * const encrypted = await encryptWithPassword('sensitive data', 'my-password')
92
- * // Store encrypted.encryptedData, encrypted.iv, encrypted.salt
93
- * ```
94
- */
95
- export async function encryptWithPassword(plaintext, password) {
96
- const enc = new TextEncoder();
97
- const iv = generateIV();
98
- const salt = generateSalt();
99
- const key = await deriveKey(password, salt);
100
- const ivBuffer = uint8ArrayToArrayBuffer(iv);
101
- const encryptedBuf = await crypto.subtle.encrypt({ name: 'AES-GCM', iv: ivBuffer }, key, enc.encode(plaintext));
102
- return {
103
- encryptedData: uint8ArrayToBase64(new Uint8Array(encryptedBuf)),
104
- iv: uint8ArrayToBase64(iv),
105
- salt: uint8ArrayToBase64(salt)
106
- };
71
+ * Encrypt plaintext with a password using AES-GCM
72
+ *
73
+ * Uses PBKDF2 for key derivation and Base64 encoding for output.
74
+ * Suitable for encrypting sensitive wallet data like private keys.
75
+ *
76
+ * **Encoding Standard**: Uses Base64 encoding for binary payloads (RFC 4648).
77
+ * Base58 is used for addresses, keys, and hashes elsewhere in the SDK.
78
+ *
79
+ * @param plaintext - Plaintext string to encrypt
80
+ * @param password - Password for encryption
81
+ * @returns Encrypted payload with encryptedData, IV, and salt (all Base64 encoded)
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * const encrypted = await encryptWithPassword('sensitive data', 'my-password')
86
+ * // Store encrypted.encryptedData, encrypted.iv, encrypted.salt
87
+ * ```
88
+ */
89
+ async function encryptWithPassword(plaintext, password) {
90
+ const enc = new TextEncoder();
91
+ const iv = generateIV();
92
+ const salt = generateSalt();
93
+ const key = await deriveKey(password, salt);
94
+ const ivBuffer = uint8ArrayToArrayBuffer(iv);
95
+ const encryptedBuf = await crypto.subtle.encrypt({
96
+ name: "AES-GCM",
97
+ iv: ivBuffer
98
+ }, key, enc.encode(plaintext));
99
+ return {
100
+ encryptedData: uint8ArrayToBase64(new Uint8Array(encryptedBuf)),
101
+ iv: uint8ArrayToBase64(iv),
102
+ salt: uint8ArrayToBase64(salt)
103
+ };
107
104
  }
108
105
  /**
109
- * Decrypt encrypted data with a password
110
- *
111
- * @param payload - Encrypted payload (Base64 encoded)
112
- * @param password - Password used for encryption
113
- * @returns Decrypted plaintext string
114
- * @throws {Error} If decryption fails (wrong password or corrupted data)
115
- *
116
- * @example
117
- * ```ts
118
- * const decrypted = await decryptWithPassword(encrypted, 'my-password')
119
- * ```
120
- */
121
- export async function decryptWithPassword(payload, password) {
122
- const dec = new TextDecoder();
123
- const ivBytes = base64ToUint8Array(payload.iv);
124
- const saltBytes = base64ToUint8Array(payload.salt);
125
- const encryptedBytes = base64ToUint8Array(payload.encryptedData);
126
- const key = await deriveKey(password, saltBytes);
127
- const iv = uint8ArrayToArrayBuffer(ivBytes);
128
- const encrypted = uint8ArrayToArrayBuffer(encryptedBytes);
129
- try {
130
- const plaintextBuf = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, encrypted);
131
- return dec.decode(plaintextBuf);
132
- }
133
- catch {
134
- throw new Error('Decryption failed. Incorrect password or corrupted data.');
135
- }
106
+ * Decrypt encrypted data with a password
107
+ *
108
+ * @param payload - Encrypted payload (Base64 encoded)
109
+ * @param password - Password used for encryption
110
+ * @returns Decrypted plaintext string
111
+ * @throws {Error} If decryption fails (wrong password or corrupted data)
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * const decrypted = await decryptWithPassword(encrypted, 'my-password')
116
+ * ```
117
+ */
118
+ async function decryptWithPassword(payload, password) {
119
+ const dec = new TextDecoder();
120
+ const ivBytes = base64ToUint8Array(payload.iv);
121
+ const saltBytes = base64ToUint8Array(payload.salt);
122
+ const encryptedBytes = base64ToUint8Array(payload.encryptedData);
123
+ const key = await deriveKey(password, saltBytes);
124
+ const iv = uint8ArrayToArrayBuffer(ivBytes);
125
+ const encrypted = uint8ArrayToArrayBuffer(encryptedBytes);
126
+ try {
127
+ const plaintextBuf = await crypto.subtle.decrypt({
128
+ name: "AES-GCM",
129
+ iv
130
+ }, key, encrypted);
131
+ return dec.decode(plaintextBuf);
132
+ } catch {
133
+ throw new Error("Decryption failed. Incorrect password or corrupted data.");
134
+ }
136
135
  }
136
+ //#endregion
137
+ export { decryptWithPassword, deriveKey, encryptWithPassword, generateIV, generateSalt };
138
+
137
139
  //# sourceMappingURL=encryption.js.map