quantum-coin-js-sdk 1.0.39 → 2.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 (226) hide show
  1. package/.gitignore +2 -1
  2. package/README.md +109 -768
  3. package/index.d.ts +76 -545
  4. package/index.js +319 -1194
  5. package/package.json +20 -5
  6. package/wasmBase64.js +7 -16
  7. package/wasm_exec.js +575 -587
  8. package/.idea/.name +0 -1
  9. package/.idea/modules.xml +0 -8
  10. package/.idea/quantum-coin-js-sdk.iml +0 -12
  11. package/.idea/vcs.xml +0 -6
  12. package/.vs/ProjectSettings.json +0 -3
  13. package/.vs/VSWorkspaceState.json +0 -8
  14. package/.vs/quantum-coin-js-sdk/FileContentIndex/a9d6de82-cfc3-4c22-ac38-06d706ff3673.vsidx +0 -0
  15. package/.vs/quantum-coin-js-sdk/FileContentIndex/fdc816df-1898-4153-99f2-c69ef4c2283b.vsidx +0 -0
  16. package/.vs/quantum-coin-js-sdk/config/applicationhost.config +0 -1011
  17. package/.vs/quantum-coin-js-sdk/v17/.wsuo +0 -0
  18. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.backup.json +0 -39
  19. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.json +0 -57
  20. package/.vs/slnx.sqlite +0 -0
  21. package/example/README.md +0 -14
  22. package/example/conversion-example.js +0 -19
  23. package/example/example-create-contract.js +0 -396
  24. package/example/example-encode-decode-rlp.js +0 -225
  25. package/example/example-event-pack-unpack.js +0 -391
  26. package/example/example-misc.js +0 -100
  27. package/example/example-rpc-send-signRawTransaction.js +0 -318
  28. package/example/example-rpc-send.js +0 -115
  29. package/example/example-send.js +0 -69
  30. package/example/example-token-pack-unpack.js +0 -960
  31. package/example/example-wallet-version4.js +0 -34
  32. package/example/example-wallet.js +0 -43
  33. package/example/example.js +0 -405
  34. package/example/node_modules/.bin/sdkgen +0 -16
  35. package/example/node_modules/.bin/sdkgen.cmd +0 -17
  36. package/example/node_modules/.bin/sdkgen.ps1 +0 -28
  37. package/example/node_modules/.package-lock.json +0 -47
  38. package/example/node_modules/quantumcoin/.github/workflows/publish-npmjs.yaml +0 -22
  39. package/example/node_modules/quantumcoin/LICENSE +0 -21
  40. package/example/node_modules/quantumcoin/README-SDK.md +0 -828
  41. package/example/node_modules/quantumcoin/README.md +0 -197
  42. package/example/node_modules/quantumcoin/config.d.ts +0 -50
  43. package/example/node_modules/quantumcoin/config.js +0 -123
  44. package/example/node_modules/quantumcoin/examples/AllSolidityTypes.sol +0 -184
  45. package/example/node_modules/quantumcoin/examples/SimpleIERC20.sol +0 -74
  46. package/example/node_modules/quantumcoin/examples/events.js +0 -41
  47. package/example/node_modules/quantumcoin/examples/events.ts +0 -35
  48. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.js +0 -100
  49. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.ts +0 -77
  50. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.js +0 -100
  51. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.ts +0 -77
  52. package/example/node_modules/quantumcoin/examples/example.js +0 -67
  53. package/example/node_modules/quantumcoin/examples/example.ts +0 -56
  54. package/example/node_modules/quantumcoin/examples/offline-signing.js +0 -77
  55. package/example/node_modules/quantumcoin/examples/offline-signing.ts +0 -65
  56. package/example/node_modules/quantumcoin/examples/package-lock.json +0 -596
  57. package/example/node_modules/quantumcoin/examples/package.json +0 -32
  58. package/example/node_modules/quantumcoin/examples/read-operations.js +0 -32
  59. package/example/node_modules/quantumcoin/examples/read-operations.ts +0 -31
  60. package/example/node_modules/quantumcoin/examples/sdk-generator-erc20.inline.json +0 -251
  61. package/example/node_modules/quantumcoin/examples/solidity-types.ts +0 -43
  62. package/example/node_modules/quantumcoin/examples/wallet-offline.js +0 -36
  63. package/example/node_modules/quantumcoin/examples/wallet-offline.ts +0 -26
  64. package/example/node_modules/quantumcoin/generate-sdk.js +0 -1846
  65. package/example/node_modules/quantumcoin/index.js +0 -12
  66. package/example/node_modules/quantumcoin/package.json +0 -95
  67. package/example/node_modules/quantumcoin/scripts/copy-declarations.js +0 -31
  68. package/example/node_modules/quantumcoin/scripts/run-all-one-by-one.js +0 -151
  69. package/example/node_modules/quantumcoin/src/abi/fragments.d.ts +0 -42
  70. package/example/node_modules/quantumcoin/src/abi/fragments.js +0 -63
  71. package/example/node_modules/quantumcoin/src/abi/index.d.ts +0 -13
  72. package/example/node_modules/quantumcoin/src/abi/index.js +0 -9
  73. package/example/node_modules/quantumcoin/src/abi/interface.d.ts +0 -128
  74. package/example/node_modules/quantumcoin/src/abi/interface.js +0 -605
  75. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.d.ts +0 -8
  76. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.js +0 -538
  77. package/example/node_modules/quantumcoin/src/constants.d.ts +0 -61
  78. package/example/node_modules/quantumcoin/src/constants.js +0 -94
  79. package/example/node_modules/quantumcoin/src/contract/contract-factory.d.ts +0 -28
  80. package/example/node_modules/quantumcoin/src/contract/contract-factory.js +0 -111
  81. package/example/node_modules/quantumcoin/src/contract/contract.d.ts +0 -113
  82. package/example/node_modules/quantumcoin/src/contract/contract.js +0 -408
  83. package/example/node_modules/quantumcoin/src/contract/index.d.ts +0 -9
  84. package/example/node_modules/quantumcoin/src/contract/index.js +0 -9
  85. package/example/node_modules/quantumcoin/src/errors/index.d.ts +0 -92
  86. package/example/node_modules/quantumcoin/src/errors/index.js +0 -200
  87. package/example/node_modules/quantumcoin/src/generator/index.d.ts +0 -81
  88. package/example/node_modules/quantumcoin/src/generator/index.js +0 -1571
  89. package/example/node_modules/quantumcoin/src/index.d.ts +0 -122
  90. package/example/node_modules/quantumcoin/src/index.js +0 -41
  91. package/example/node_modules/quantumcoin/src/internal/hex.d.ts +0 -68
  92. package/example/node_modules/quantumcoin/src/internal/hex.js +0 -180
  93. package/example/node_modules/quantumcoin/src/providers/extra-providers.d.ts +0 -139
  94. package/example/node_modules/quantumcoin/src/providers/extra-providers.js +0 -614
  95. package/example/node_modules/quantumcoin/src/providers/index.d.ts +0 -17
  96. package/example/node_modules/quantumcoin/src/providers/index.js +0 -10
  97. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.d.ts +0 -12
  98. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.js +0 -89
  99. package/example/node_modules/quantumcoin/src/providers/provider.d.ts +0 -206
  100. package/example/node_modules/quantumcoin/src/providers/provider.js +0 -524
  101. package/example/node_modules/quantumcoin/src/types/index.d.ts +0 -214
  102. package/example/node_modules/quantumcoin/src/types/index.js +0 -9
  103. package/example/node_modules/quantumcoin/src/utils/address.d.ts +0 -58
  104. package/example/node_modules/quantumcoin/src/utils/address.js +0 -144
  105. package/example/node_modules/quantumcoin/src/utils/encoding.d.ts +0 -120
  106. package/example/node_modules/quantumcoin/src/utils/encoding.js +0 -306
  107. package/example/node_modules/quantumcoin/src/utils/fixednumber.d.ts +0 -57
  108. package/example/node_modules/quantumcoin/src/utils/fixednumber.js +0 -366
  109. package/example/node_modules/quantumcoin/src/utils/hashing.d.ts +0 -76
  110. package/example/node_modules/quantumcoin/src/utils/hashing.js +0 -298
  111. package/example/node_modules/quantumcoin/src/utils/index.d.ts +0 -63
  112. package/example/node_modules/quantumcoin/src/utils/index.js +0 -14
  113. package/example/node_modules/quantumcoin/src/utils/result.d.ts +0 -57
  114. package/example/node_modules/quantumcoin/src/utils/result.js +0 -128
  115. package/example/node_modules/quantumcoin/src/utils/rlp.d.ts +0 -12
  116. package/example/node_modules/quantumcoin/src/utils/rlp.js +0 -215
  117. package/example/node_modules/quantumcoin/src/utils/units.d.ts +0 -29
  118. package/example/node_modules/quantumcoin/src/utils/units.js +0 -107
  119. package/example/node_modules/quantumcoin/src/wallet/index.d.ts +0 -10
  120. package/example/node_modules/quantumcoin/src/wallet/index.js +0 -8
  121. package/example/node_modules/quantumcoin/src/wallet/wallet.d.ts +0 -192
  122. package/example/node_modules/quantumcoin/src/wallet/wallet.js +0 -713
  123. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.js +0 -207
  124. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.ts +0 -191
  125. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.fixtures.js +0 -231
  126. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +0 -387
  127. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +0 -350
  128. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.js +0 -165
  129. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.ts +0 -160
  130. package/example/node_modules/quantumcoin/test/e2e/helpers.js +0 -59
  131. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.js +0 -141
  132. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.ts +0 -128
  133. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.js +0 -168
  134. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +0 -141
  135. package/example/node_modules/quantumcoin/test/e2e/transactional.test.js +0 -245
  136. package/example/node_modules/quantumcoin/test/e2e/transactional.test.ts +0 -208
  137. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.js +0 -407
  138. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.ts +0 -337
  139. package/example/node_modules/quantumcoin/test/fixtures/ConstructorParam.sol +0 -23
  140. package/example/node_modules/quantumcoin/test/fixtures/MultiContracts.sol +0 -37
  141. package/example/node_modules/quantumcoin/test/fixtures/SimpleStorage.sol +0 -18
  142. package/example/node_modules/quantumcoin/test/fixtures/StakingContract.abi.json +0 -1
  143. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.js +0 -49
  144. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.ts +0 -44
  145. package/example/node_modules/quantumcoin/test/integration/provider.test.js +0 -88
  146. package/example/node_modules/quantumcoin/test/integration/provider.test.ts +0 -85
  147. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.js +0 -41
  148. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.ts +0 -38
  149. package/example/node_modules/quantumcoin/test/security/abi-decoder-bounds.test.js +0 -122
  150. package/example/node_modules/quantumcoin/test/security/contract-overrides.test.js +0 -112
  151. package/example/node_modules/quantumcoin/test/security/generator-injection.test.js +0 -195
  152. package/example/node_modules/quantumcoin/test/security/malformed-input.test.js +0 -330
  153. package/example/node_modules/quantumcoin/test/security/malformed-input.test.ts +0 -35
  154. package/example/node_modules/quantumcoin/test/security/rpc-numeric-bounds.test.js +0 -81
  155. package/example/node_modules/quantumcoin/test/security/rpc-trust.test.js +0 -202
  156. package/example/node_modules/quantumcoin/test/unit/_encrypted-output.txt +0 -6
  157. package/example/node_modules/quantumcoin/test/unit/_log-encrypted-jsons.js +0 -45
  158. package/example/node_modules/quantumcoin/test/unit/_write-keystore-fixture.js +0 -16
  159. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.js +0 -110
  160. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.ts +0 -109
  161. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.js +0 -923
  162. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.ts +0 -877
  163. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.js +0 -85
  164. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.ts +0 -79
  165. package/example/node_modules/quantumcoin/test/unit/contract.test.js +0 -85
  166. package/example/node_modules/quantumcoin/test/unit/contract.test.ts +0 -83
  167. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.js +0 -127
  168. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.ts +0 -91
  169. package/example/node_modules/quantumcoin/test/unit/errors.test.js +0 -77
  170. package/example/node_modules/quantumcoin/test/unit/errors.test.ts +0 -76
  171. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.js +0 -55
  172. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.ts +0 -54
  173. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.js +0 -656
  174. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.ts +0 -660
  175. package/example/node_modules/quantumcoin/test/unit/fixtures/encrypted-keystores-48-32-36.js +0 -9
  176. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.js +0 -42
  177. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.ts +0 -41
  178. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.js +0 -113
  179. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.ts +0 -110
  180. package/example/node_modules/quantumcoin/test/unit/generator.test.js +0 -149
  181. package/example/node_modules/quantumcoin/test/unit/generator.test.ts +0 -148
  182. package/example/node_modules/quantumcoin/test/unit/hashing.test.js +0 -64
  183. package/example/node_modules/quantumcoin/test/unit/hashing.test.ts +0 -63
  184. package/example/node_modules/quantumcoin/test/unit/init.test.js +0 -39
  185. package/example/node_modules/quantumcoin/test/unit/init.test.ts +0 -38
  186. package/example/node_modules/quantumcoin/test/unit/interface.test.js +0 -56
  187. package/example/node_modules/quantumcoin/test/unit/interface.test.ts +0 -54
  188. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.js +0 -81
  189. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.ts +0 -80
  190. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.js +0 -98
  191. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.ts +0 -64
  192. package/example/node_modules/quantumcoin/test/unit/providers.test.js +0 -252
  193. package/example/node_modules/quantumcoin/test/unit/providers.test.ts +0 -251
  194. package/example/node_modules/quantumcoin/test/unit/result.test.js +0 -80
  195. package/example/node_modules/quantumcoin/test/unit/result.test.ts +0 -79
  196. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.js +0 -49
  197. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.ts +0 -39
  198. package/example/node_modules/quantumcoin/test/unit/utils.test.js +0 -57
  199. package/example/node_modules/quantumcoin/test/unit/utils.test.ts +0 -56
  200. package/example/node_modules/quantumcoin/test/verbose-logger.js +0 -74
  201. package/example/node_modules/quantumcoin/tsconfig.build.json +0 -14
  202. package/example/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
  203. package/example/node_modules/seed-words/BUILD.md +0 -7
  204. package/example/node_modules/seed-words/LICENSE +0 -121
  205. package/example/node_modules/seed-words/README.md +0 -67
  206. package/example/node_modules/seed-words/dist/seedwords.d.ts +0 -39
  207. package/example/node_modules/seed-words/package.json +0 -27
  208. package/example/node_modules/seed-words/seedwords.js +0 -315
  209. package/example/node_modules/seed-words/seedwords.txt +0 -65536
  210. package/example/node_modules/seed-words/tsconfig.json +0 -21
  211. package/example/package-lock.json +0 -56
  212. package/example/package.json +0 -15
  213. package/tests/encrypted-32.json +0 -1
  214. package/tests/encrypted-36.json +0 -1
  215. package/tests/encrypted-48.json +0 -1
  216. package/tests/generate-verify-vectors.js +0 -91
  217. package/tests/get-gas-price.test.js +0 -59
  218. package/tests/non-transactional.preinit.test.js +0 -41
  219. package/tests/non-transactional.test.js +0 -1389
  220. package/tests/scrypt.test.js +0 -128
  221. package/tests/sign-raw-keytype5-context-null.test.js +0 -107
  222. package/tests/sign-raw-transaction.test.js +0 -196
  223. package/tests/sign-verify.test.js +0 -311
  224. package/tests/transactional.relay.test.js +0 -131
  225. package/tests/transactional.rpc.test.js +0 -103
  226. package/tests/verify-vectors.json +0 -95035
@@ -1,306 +0,0 @@
1
- /**
2
- * @fileoverview Encoding/decoding helpers (ethers.js v6 compatible names).
3
- *
4
- * Notes:
5
- * - QuantumCoin addresses are 32 bytes (not 20).
6
- * - This module intentionally uses only built-in Node.js APIs.
7
- */
8
-
9
- const {
10
- isUint8Array,
11
- normalizeHex,
12
- isHexString,
13
- strip0x,
14
- add0x,
15
- hexToBytes,
16
- bytesToHex,
17
- utf8ToBytes,
18
- bytesToUtf8,
19
- arrayify: _arrayify,
20
- } = require("../internal/hex");
21
-
22
- /**
23
- * @typedef {string | Uint8Array} BytesLike
24
- */
25
-
26
- /**
27
- * Converts bytes to UTF-8 string.
28
- * @param {BytesLike} data
29
- * @returns {string}
30
- */
31
- function toUtf8String(data) {
32
- return bytesToUtf8(arrayify(data));
33
- }
34
-
35
- /**
36
- * Converts string to UTF-8 bytes.
37
- * @param {string} str
38
- * @returns {Uint8Array}
39
- */
40
- function toUtf8Bytes(str) {
41
- return utf8ToBytes(str);
42
- }
43
-
44
- /**
45
- * Converts data to hex string.
46
- * @param {BytesLike} data
47
- * @returns {string}
48
- */
49
- function toHex(data) {
50
- if (typeof data === "string") return normalizeHex(data);
51
- return bytesToHex(arrayify(data));
52
- }
53
-
54
- /**
55
- * Alias for toHex.
56
- * @param {BytesLike} data
57
- * @returns {string}
58
- */
59
- function hexlify(data) {
60
- return toHex(data);
61
- }
62
-
63
- /**
64
- * Converts data to byte array.
65
- * @param {BytesLike} data
66
- * @returns {Uint8Array}
67
- */
68
- function arrayify(data) {
69
- return _arrayify(data);
70
- }
71
-
72
- /**
73
- * Returns true if value is BytesLike.
74
- * @param {any} value
75
- * @returns {boolean}
76
- */
77
- function isBytesLike(value) {
78
- return (typeof value === "string" && isHexString(value)) || isUint8Array(value);
79
- }
80
-
81
- /**
82
- * Concatenates byte arrays and returns a hex string.
83
- * @param {BytesLike[]} items
84
- * @returns {string}
85
- */
86
- function concat(items) {
87
- if (!Array.isArray(items)) throw new TypeError("items must be an array");
88
- const parts = items.map((i) => arrayify(i));
89
- const len = parts.reduce((a, b) => a + b.length, 0);
90
- const out = new Uint8Array(len);
91
- let offset = 0;
92
- for (const p of parts) {
93
- out.set(p, offset);
94
- offset += p.length;
95
- }
96
- return bytesToHex(out);
97
- }
98
-
99
- /**
100
- * Strips leading zeros from a hex string.
101
- * @param {BytesLike} data
102
- * @returns {string}
103
- */
104
- function stripZerosLeft(data) {
105
- const hex = toHex(data);
106
- let h = strip0x(hex);
107
- h = h.replace(/^0+/, "");
108
- if (h.length === 0) return "0x";
109
- if (h.length % 2 !== 0) h = "0" + h;
110
- return add0x(h);
111
- }
112
-
113
- /**
114
- * Pads a BytesLike value to the left with zeros (byte length).
115
- * @param {BytesLike} value
116
- * @param {number} length
117
- * @returns {string}
118
- */
119
- function zeroPad(value, length) {
120
- const bytes = arrayify(value);
121
- if (bytes.length > length) throw new RangeError("value exceeds length");
122
- const out = new Uint8Array(length);
123
- out.set(bytes, length - bytes.length);
124
- return bytesToHex(out);
125
- }
126
-
127
- /**
128
- * Pads a hex value (interpreted as bytes) to the left with zeros (byte length).
129
- * @param {BytesLike} value
130
- * @param {number} length
131
- * @returns {string}
132
- */
133
- function zeroPadValue(value, length) {
134
- return zeroPad(value, length);
135
- }
136
-
137
- /**
138
- * Encodes a short UTF-8 string into a bytes32 hex string.
139
- * @param {string} text
140
- * @returns {string}
141
- */
142
- function encodeBytes32String(text) {
143
- const bytes = toUtf8Bytes(text);
144
- if (bytes.length > 32) throw new RangeError("string too long (max 32 bytes)");
145
- const out = new Uint8Array(32);
146
- out.set(bytes, 0);
147
- return bytesToHex(out);
148
- }
149
-
150
- /**
151
- * Decodes a bytes32 hex string into a UTF-8 string (trailing zeros stripped).
152
- * @param {BytesLike} bytes
153
- * @returns {string}
154
- */
155
- function decodeBytes32String(bytes) {
156
- const b = arrayify(bytes);
157
- if (b.length !== 32) throw new RangeError("invalid bytes32 length");
158
- let end = b.length;
159
- while (end > 0 && b[end - 1] === 0) end--;
160
- return bytesToUtf8(b.slice(0, end));
161
- }
162
-
163
- /**
164
- * Base64 decode to bytes.
165
- * @param {string} data
166
- * @returns {Uint8Array}
167
- */
168
- function decodeBase64(data) {
169
- const buf = Buffer.from(data, "base64");
170
- return new Uint8Array(buf);
171
- }
172
-
173
- /**
174
- * Base64 encode BytesLike.
175
- * @param {BytesLike} data
176
- * @returns {string}
177
- */
178
- function encodeBase64(data) {
179
- return Buffer.from(arrayify(data)).toString("base64");
180
- }
181
-
182
- // Minimal base58 implementation (Bitcoin alphabet) for compatibility with ethers helpers.
183
- const _B58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
184
- const _B58_INDEX = new Map(_B58_ALPHABET.split("").map((c, i) => [c, i]));
185
-
186
- /**
187
- * Decode Base58 string to bytes.
188
- * @param {string} data
189
- * @returns {Uint8Array}
190
- */
191
- function decodeBase58(data) {
192
- if (typeof data !== "string" || data.length === 0) throw new TypeError("invalid base58 string");
193
-
194
- let bytes = [0];
195
- for (const ch of data) {
196
- const val = _B58_INDEX.get(ch);
197
- if (val == null) throw new TypeError("invalid base58 character");
198
-
199
- let carry = val;
200
- for (let i = 0; i < bytes.length; i++) {
201
- const x = bytes[i] * 58 + carry;
202
- bytes[i] = x & 0xff;
203
- carry = x >> 8;
204
- }
205
- while (carry > 0) {
206
- bytes.push(carry & 0xff);
207
- carry >>= 8;
208
- }
209
- }
210
-
211
- // Deal with leading zeros
212
- let leading = 0;
213
- for (const ch of data) {
214
- if (ch === "1") leading++;
215
- else break;
216
- }
217
-
218
- const out = new Uint8Array(leading + bytes.length);
219
- for (let i = 0; i < bytes.length; i++) out[out.length - 1 - i] = bytes[i];
220
- return out;
221
- }
222
-
223
- /**
224
- * Encode BytesLike as Base58.
225
- * @param {BytesLike} data
226
- * @returns {string}
227
- */
228
- function encodeBase58(data) {
229
- const bytes = arrayify(data);
230
- let digits = [0];
231
-
232
- for (const b of bytes) {
233
- let carry = b;
234
- for (let i = 0; i < digits.length; i++) {
235
- const x = digits[i] * 256 + carry;
236
- digits[i] = x % 58;
237
- carry = (x / 58) | 0;
238
- }
239
- while (carry > 0) {
240
- digits.push(carry % 58);
241
- carry = (carry / 58) | 0;
242
- }
243
- }
244
-
245
- // Leading zeros
246
- let leading = 0;
247
- for (const b of bytes) {
248
- if (b === 0) leading++;
249
- else break;
250
- }
251
-
252
- let out = "1".repeat(leading);
253
- for (let i = digits.length - 1; i >= 0; i--) out += _B58_ALPHABET[digits[i]];
254
- return out;
255
- }
256
-
257
- /**
258
- * Returns UTF-8 code points for a string.
259
- * @param {string} str
260
- * @returns {number[]}
261
- */
262
- function toUtf8CodePoints(str) {
263
- return Array.from(str).map((c) => c.codePointAt(0) || 0);
264
- }
265
-
266
- /**
267
- * Solidity packed encoding.
268
- * This is a complex helper in ethers.js; in QuantumCoin.js it is currently not implemented.
269
- * @throws
270
- */
271
- function solidityPacked() {
272
- throw new Error("solidityPacked is not implemented in QuantumCoin.js yet");
273
- }
274
- function solidityPackedKeccak256() {
275
- throw new Error("solidityPackedKeccak256 is not implemented in QuantumCoin.js yet");
276
- }
277
- function solidityPackedSha256() {
278
- throw new Error("solidityPackedSha256 is not implemented in QuantumCoin.js yet");
279
- }
280
-
281
- module.exports = {
282
- toUtf8String,
283
- toUtf8Bytes,
284
- toHex,
285
- hexlify,
286
- arrayify,
287
- concat,
288
- stripZerosLeft,
289
- encodeBytes32String,
290
- decodeBytes32String,
291
- decodeBase58,
292
- decodeBase64,
293
- encodeBase58,
294
- encodeBase64,
295
- toUtf8CodePoints,
296
- isHexString,
297
- isBytesLike,
298
- zeroPad,
299
- zeroPadValue,
300
- solidityPacked,
301
- solidityPackedKeccak256,
302
- solidityPackedSha256,
303
- bytesToHex,
304
- hexToBytes,
305
- };
306
-
@@ -1,57 +0,0 @@
1
- import type { BytesLike } from "./encoding";
2
-
3
- export type BigNumberish = string | number | bigint;
4
-
5
- export type FixedFormat = number | string | {
6
- signed?: boolean;
7
- width?: number;
8
- decimals?: number;
9
- };
10
-
11
- export class FixedNumber {
12
- private constructor(guard: any, value: bigint, format: any);
13
-
14
- readonly format: string;
15
- readonly _value: string;
16
-
17
- get signed(): boolean;
18
- get width(): number;
19
- get decimals(): number;
20
- get value(): bigint;
21
-
22
- add(other: FixedNumber): FixedNumber;
23
- addUnsafe(other: FixedNumber): FixedNumber;
24
- sub(other: FixedNumber): FixedNumber;
25
- subUnsafe(other: FixedNumber): FixedNumber;
26
- mul(other: FixedNumber): FixedNumber;
27
- mulUnsafe(other: FixedNumber): FixedNumber;
28
- mulSignal(other: FixedNumber): FixedNumber;
29
- div(other: FixedNumber): FixedNumber;
30
- divUnsafe(other: FixedNumber): FixedNumber;
31
- divSignal(other: FixedNumber): FixedNumber;
32
-
33
- cmp(other: FixedNumber): number;
34
- eq(other: FixedNumber): boolean;
35
- lt(other: FixedNumber): boolean;
36
- lte(other: FixedNumber): boolean;
37
- gt(other: FixedNumber): boolean;
38
- gte(other: FixedNumber): boolean;
39
-
40
- floor(): FixedNumber;
41
- ceiling(): FixedNumber;
42
- round(decimals?: number): FixedNumber;
43
-
44
- isZero(): boolean;
45
- isNegative(): boolean;
46
-
47
- toString(): string;
48
- toUnsafeFloat(): number;
49
- toFormat(format: FixedFormat): FixedNumber;
50
- toHexString(width?: number): string;
51
-
52
- static fromValue(value: BigNumberish, decimals?: number, format?: FixedFormat): FixedNumber;
53
- static fromString(value: string, format?: FixedFormat): FixedNumber;
54
- static fromBytes(value: BytesLike, format?: FixedFormat): FixedNumber;
55
- static from(value: any, format?: FixedFormat): FixedNumber;
56
- static isFixedNumber(value: any): value is FixedNumber;
57
- }