@aeternity/aepp-sdk 12.0.0 → 12.1.2

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 (283) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +2 -1
  5. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +20765 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +7 -7
  10. package/es/AeSdk.mjs.map +1 -1
  11. package/es/AeSdkAepp.d.ts +4 -3
  12. package/es/AeSdkAepp.mjs +2 -1
  13. package/es/AeSdkAepp.mjs.map +1 -1
  14. package/es/AeSdkBase.d.ts +22 -21
  15. package/es/AeSdkBase.mjs +25 -21
  16. package/es/AeSdkBase.mjs.map +1 -1
  17. package/es/AeSdkWallet.d.ts +4 -3
  18. package/es/AeSdkWallet.mjs +5 -1
  19. package/es/AeSdkWallet.mjs.map +1 -1
  20. package/es/Node.d.ts +7 -10
  21. package/es/Node.mjs +63 -57
  22. package/es/Node.mjs.map +1 -1
  23. package/es/account/Base.d.ts +7 -4
  24. package/es/account/Base.mjs +3 -3
  25. package/es/account/Base.mjs.map +1 -1
  26. package/es/account/Memory.d.ts +5 -4
  27. package/es/account/Memory.mjs +24 -2
  28. package/es/account/Memory.mjs.map +1 -1
  29. package/es/account/Rpc.d.ts +6 -6
  30. package/es/account/Rpc.mjs +3 -2
  31. package/es/account/Rpc.mjs.map +1 -1
  32. package/es/aens.d.ts +27 -14
  33. package/es/aens.mjs +27 -21
  34. package/es/aens.mjs.map +1 -1
  35. package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
  36. package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
  37. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  38. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  41. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  44. package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
  51. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/schema.d.ts +17 -2
  53. package/es/aepp-wallet-communication/schema.mjs +54 -17
  54. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  55. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
  56. package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
  57. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  58. package/es/apis/node/models/index.d.ts +6 -2
  59. package/es/apis/node/models/index.mjs.map +1 -1
  60. package/es/apis/node/models/mappers.mjs +4 -2
  61. package/es/apis/node/models/mappers.mjs.map +1 -1
  62. package/es/chain.d.ts +92 -64
  63. package/es/chain.mjs +190 -154
  64. package/es/chain.mjs.map +1 -1
  65. package/es/channel/handlers.d.ts +3 -3
  66. package/es/channel/handlers.mjs +42 -44
  67. package/es/channel/handlers.mjs.map +1 -1
  68. package/es/channel/index.d.ts +43 -52
  69. package/es/channel/index.mjs +46 -49
  70. package/es/channel/index.mjs.map +1 -1
  71. package/es/channel/internal.d.ts +16 -15
  72. package/es/channel/internal.mjs +67 -62
  73. package/es/channel/internal.mjs.map +1 -1
  74. package/es/contract/Compiler.d.ts +1 -0
  75. package/es/contract/Compiler.mjs +5 -4
  76. package/es/contract/Compiler.mjs.map +1 -1
  77. package/es/contract/aci.d.ts +17 -15
  78. package/es/contract/aci.mjs +58 -45
  79. package/es/contract/aci.mjs.map +1 -1
  80. package/es/contract/ga.d.ts +16 -15
  81. package/es/contract/ga.mjs +12 -7
  82. package/es/contract/ga.mjs.map +1 -1
  83. package/es/contract/methods.d.ts +9 -6
  84. package/es/contract/methods.mjs +9 -6
  85. package/es/contract/methods.mjs.map +1 -1
  86. package/es/deprecated/index.d.ts +143 -0
  87. package/es/deprecated/index.mjs +162 -0
  88. package/es/deprecated/index.mjs.map +1 -0
  89. package/es/deprecated/methods.d.ts +18 -0
  90. package/es/deprecated/methods.mjs +26 -0
  91. package/es/deprecated/methods.mjs.map +1 -0
  92. package/es/index.d.ts +4 -1
  93. package/es/index.mjs +4 -1
  94. package/es/index.mjs.map +1 -1
  95. package/es/oracle.d.ts +69 -62
  96. package/es/oracle.mjs +121 -103
  97. package/es/oracle.mjs.map +1 -1
  98. package/es/spend.d.ts +16 -15
  99. package/es/spend.mjs +19 -30
  100. package/es/spend.mjs.map +1 -1
  101. package/es/tx/builder/address.d.ts +25 -0
  102. package/es/tx/builder/address.mjs +45 -0
  103. package/es/tx/builder/address.mjs.map +1 -0
  104. package/es/tx/builder/constants.d.ts +55 -26
  105. package/es/tx/builder/constants.mjs +60 -38
  106. package/es/tx/builder/constants.mjs.map +1 -1
  107. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  108. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  109. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  110. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  111. package/es/tx/builder/field-types/deposit.mjs +19 -0
  112. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  113. package/es/tx/builder/field-types/fee.d.ts +25 -0
  114. package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
  115. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  116. package/es/tx/builder/field-types/field.d.ts +6 -0
  117. package/es/tx/builder/field-types/field.mjs +15 -0
  118. package/es/tx/builder/field-types/field.mjs.map +1 -0
  119. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  120. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  121. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  122. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  123. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  124. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  125. package/es/tx/builder/field-types/index.d.ts +70 -0
  126. package/es/tx/builder/field-types/index.mjs +25 -0
  127. package/es/tx/builder/field-types/index.mjs.map +1 -0
  128. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  129. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  130. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  131. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  132. package/es/tx/builder/field-types/name-id.mjs +19 -0
  133. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  134. package/es/tx/builder/field-types/name.d.ts +13 -0
  135. package/es/tx/builder/field-types/name.mjs +18 -0
  136. package/es/tx/builder/field-types/name.mjs.map +1 -0
  137. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  138. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  139. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  140. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  141. package/es/tx/builder/field-types/u-int.mjs +14 -0
  142. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  143. package/es/tx/builder/helpers.d.ts +27 -33
  144. package/es/tx/builder/helpers.mjs +41 -47
  145. package/es/tx/builder/helpers.mjs.map +1 -1
  146. package/es/tx/builder/index.d.ts +25 -12
  147. package/es/tx/builder/index.mjs +74 -83
  148. package/es/tx/builder/index.mjs.map +1 -1
  149. package/es/tx/builder/schema.d.ts +995 -144
  150. package/es/tx/builder/schema.mjs +121 -170
  151. package/es/tx/builder/schema.mjs.map +1 -1
  152. package/es/tx/index.d.ts +28 -27
  153. package/es/tx/index.mjs +97 -117
  154. package/es/tx/index.mjs.map +1 -1
  155. package/es/tx/validator.d.ts +4 -3
  156. package/es/tx/validator.mjs +79 -92
  157. package/es/tx/validator.mjs.map +1 -1
  158. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
  159. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
  160. package/es/typings/bip32-path/index.d.mjs.map +1 -1
  161. package/es/typings/blakejs/index.d.mjs.map +1 -1
  162. package/es/typings/sha-js/index.d.mjs +2 -0
  163. package/es/typings/sha-js/index.d.mjs.map +1 -0
  164. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
  165. package/es/utils/amount-formatter.d.ts +9 -9
  166. package/es/utils/amount-formatter.mjs +17 -17
  167. package/es/utils/amount-formatter.mjs.map +1 -1
  168. package/es/utils/autorest.mjs +7 -7
  169. package/es/utils/autorest.mjs.map +1 -1
  170. package/es/utils/bignumber.mjs +2 -1
  171. package/es/utils/bignumber.mjs.map +1 -1
  172. package/es/utils/bytes.mjs +1 -1
  173. package/es/utils/bytes.mjs.map +1 -1
  174. package/es/utils/crypto.d.ts +8 -23
  175. package/es/utils/crypto.mjs +15 -41
  176. package/es/utils/crypto.mjs.map +1 -1
  177. package/es/utils/encoder-types.d.ts +61 -0
  178. package/es/utils/encoder-types.mjs +36 -0
  179. package/es/utils/encoder-types.mjs.map +1 -0
  180. package/es/utils/encoder.d.ts +6 -7
  181. package/es/utils/encoder.mjs +42 -26
  182. package/es/utils/encoder.mjs.map +1 -1
  183. package/es/utils/errors.d.ts +1 -11
  184. package/es/utils/errors.mjs +4 -20
  185. package/es/utils/errors.mjs.map +1 -1
  186. package/es/utils/hd-wallet.d.ts +18 -2
  187. package/es/utils/hd-wallet.mjs +64 -34
  188. package/es/utils/hd-wallet.mjs.map +1 -1
  189. package/es/utils/json-big.mjs +2 -2
  190. package/es/utils/json-big.mjs.map +1 -1
  191. package/es/utils/keystore.mjs +4 -2
  192. package/es/utils/keystore.mjs.map +1 -1
  193. package/es/utils/mptree.d.ts +2 -2
  194. package/es/utils/mptree.mjs +11 -6
  195. package/es/utils/mptree.mjs.map +1 -1
  196. package/es/utils/other.d.ts +8 -2
  197. package/es/utils/other.mjs +15 -3
  198. package/es/utils/other.mjs.map +1 -1
  199. package/es/utils/semver-satisfies.d.ts +1 -1
  200. package/es/utils/semver-satisfies.mjs +2 -2
  201. package/es/utils/semver-satisfies.mjs.map +1 -1
  202. package/es/utils/string.mjs.map +1 -1
  203. package/package.json +36 -34
  204. package/src/AeSdk.ts +30 -27
  205. package/src/AeSdkAepp.ts +93 -84
  206. package/src/AeSdkBase.ts +148 -130
  207. package/src/AeSdkWallet.ts +172 -156
  208. package/src/Node.ts +108 -102
  209. package/src/account/Base.ts +42 -32
  210. package/src/account/Memory.ts +45 -30
  211. package/src/account/Rpc.ts +32 -30
  212. package/src/aens.ts +124 -108
  213. package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
  214. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
  215. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
  216. package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
  217. package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
  218. package/src/aepp-wallet-communication/rpc/types.ts +32 -32
  219. package/src/aepp-wallet-communication/schema.ts +117 -74
  220. package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
  221. package/src/apis/node/code-model-v4.yaml +54 -20
  222. package/src/apis/node/models/index.ts +6 -2
  223. package/src/apis/node/models/mappers.ts +4 -2
  224. package/src/chain.ts +286 -228
  225. package/src/channel/handlers.ts +424 -372
  226. package/src/channel/index.ts +285 -251
  227. package/src/channel/internal.ts +248 -232
  228. package/src/contract/Compiler.ts +22 -21
  229. package/src/contract/aci.ts +267 -258
  230. package/src/contract/ga.ts +93 -72
  231. package/src/contract/methods.ts +32 -27
  232. package/src/deprecated/index.ts +172 -0
  233. package/src/deprecated/methods.ts +25 -0
  234. package/src/index.ts +37 -32
  235. package/src/oracle.ts +211 -189
  236. package/src/spend.ts +82 -70
  237. package/src/tx/builder/address.ts +50 -0
  238. package/src/tx/builder/constants.ts +82 -52
  239. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  240. package/src/tx/builder/field-types/deposit.ts +21 -0
  241. package/src/tx/builder/field-types/fee.ts +143 -0
  242. package/src/tx/builder/field-types/field.ts +9 -0
  243. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  244. package/src/tx/builder/field-types/gas-price.ts +16 -0
  245. package/src/tx/builder/field-types/index.ts +45 -0
  246. package/src/tx/builder/field-types/name-fee.ts +32 -0
  247. package/src/tx/builder/field-types/name-id.ts +20 -0
  248. package/src/tx/builder/field-types/name.ts +18 -0
  249. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  250. package/src/tx/builder/field-types/u-int.ts +16 -0
  251. package/src/tx/builder/helpers.ts +112 -117
  252. package/src/tx/builder/index.ts +203 -197
  253. package/src/tx/builder/schema.ts +421 -465
  254. package/src/tx/index.ts +128 -135
  255. package/src/tx/validator.ts +165 -161
  256. package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
  257. package/src/typings/@aeternity__uuid/index.d.ts +3 -1
  258. package/src/typings/bip32-path/index.d.ts +6 -6
  259. package/src/typings/blakejs/index.d.ts +4 -32
  260. package/src/typings/sha-js/index.d.ts +5 -0
  261. package/src/typings/tweetnacl-auth/index.d.ts +2 -2
  262. package/src/utils/amount-formatter.ts +41 -41
  263. package/src/utils/autorest.ts +57 -54
  264. package/src/utils/bignumber.ts +7 -6
  265. package/src/utils/bytes.ts +19 -19
  266. package/src/utils/crypto.ts +82 -94
  267. package/src/utils/encoder-types.ts +63 -0
  268. package/src/utils/encoder.ts +104 -56
  269. package/src/utils/errors.ts +246 -264
  270. package/src/utils/hd-wallet.ts +114 -82
  271. package/src/utils/json-big.ts +16 -15
  272. package/src/utils/keystore.ts +65 -62
  273. package/src/utils/mptree.ts +59 -56
  274. package/src/utils/other.ts +26 -18
  275. package/src/utils/semver-satisfies.ts +15 -11
  276. package/src/utils/string.ts +10 -10
  277. package/es/tx/builder/field-types.d.ts +0 -62
  278. package/es/tx/builder/field-types.mjs +0 -126
  279. package/es/tx/builder/field-types.mjs.map +0 -1
  280. package/es/tx/min-fee.d.ts +0 -20
  281. package/es/tx/min-fee.mjs.map +0 -1
  282. package/src/tx/builder/field-types.ts +0 -111
  283. package/src/tx/min-fee.ts +0 -136
@@ -1,90 +1,93 @@
1
- import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline'
2
- import { AdditionalPolicyConfig } from '@azure/core-client'
3
- import { pause } from './other'
4
- import semverSatisfies from './semver-satisfies'
5
- import { UnsupportedVersionError } from './errors'
1
+ import { RestError, PipelineResponse, PipelinePolicy } from '@azure/core-rest-pipeline';
2
+ import { AdditionalPolicyConfig } from '@azure/core-client';
3
+ import { pause } from './other';
4
+ import semverSatisfies from './semver-satisfies';
5
+ import { UnsupportedVersionError } from './errors';
6
6
 
7
7
  export const genRequestQueuesPolicy = (): AdditionalPolicyConfig => {
8
- const requestQueues = new Map<string, Promise<unknown>>()
8
+ const requestQueues = new Map<string, Promise<unknown>>();
9
9
 
10
10
  return {
11
11
  policy: {
12
12
  name: 'request-queues',
13
- async sendRequest (request, next) {
14
- const key = request.headers.get('__queue')
15
- request.headers.delete('__queue')
16
- const getResponse = async (): Promise<PipelineResponse> => await next(request)
17
- if (key == null) return await getResponse()
18
- const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse)
13
+ async sendRequest(request, next) {
14
+ const key = request.headers.get('__queue');
15
+ request.headers.delete('__queue');
16
+ const getResponse = async (): Promise<PipelineResponse> => next(request);
17
+ if (key == null) return getResponse();
18
+ const req = (requestQueues.get(key) ?? Promise.resolve()).then(getResponse, getResponse);
19
19
  // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
20
20
  // gap to ensure that node won't reject the nonce
21
- requestQueues.set(key, req.then(async () => await pause(750)))
22
- return await req
23
- }
21
+ requestQueues.set(key, req.then(async () => pause(750)));
22
+ return req;
23
+ },
24
24
  },
25
- position: 'perCall'
26
- }
27
- }
25
+ position: 'perCall',
26
+ };
27
+ };
28
28
 
29
29
  export const genCombineGetRequestsPolicy = (): AdditionalPolicyConfig => {
30
- const pendingGetRequests = new Map<string, Promise<PipelineResponse>>()
30
+ const pendingGetRequests = new Map<string, Promise<PipelineResponse>>();
31
31
 
32
32
  return {
33
33
  policy: {
34
34
  name: 'combine-requests',
35
- async sendRequest (request, next) {
36
- if (request.method !== 'GET') return await next(request)
37
- const key = JSON.stringify([request.url, request.body])
38
- const response = pendingGetRequests.get(key) ?? next(request)
39
- pendingGetRequests.set(key, response)
35
+ async sendRequest(request, next) {
36
+ if (request.method !== 'GET') return next(request);
37
+ const key = JSON.stringify([request.url, request.body]);
38
+ const response = pendingGetRequests.get(key) ?? next(request);
39
+ pendingGetRequests.set(key, response);
40
40
  try {
41
- return await response
41
+ return await response;
42
42
  } finally {
43
- pendingGetRequests.delete(key)
43
+ pendingGetRequests.delete(key);
44
44
  }
45
- }
45
+ },
46
46
  },
47
- position: 'perCall'
48
- }
49
- }
47
+ position: 'perCall',
48
+ };
49
+ };
50
50
 
51
51
  export const genErrorFormatterPolicy = (
52
- getMessage: (b: any) => string
52
+ getMessage: (b: any) => string,
53
53
  ): AdditionalPolicyConfig => ({
54
54
  policy: {
55
55
  name: 'error-formatter',
56
- async sendRequest (request, next) {
56
+ async sendRequest(request, next) {
57
57
  try {
58
- return await next(request)
58
+ return await next(request);
59
59
  } catch (error) {
60
- if (!(error instanceof RestError) || error.request == null) throw error
61
- if (error.response?.bodyAsText == null) throw error
60
+ if (!(error instanceof RestError) || error.request == null) throw error;
61
+ if (error.response?.bodyAsText == null) throw error;
62
62
 
63
- let body
63
+ let body;
64
64
  try {
65
- body = JSON.parse(error.response.bodyAsText)
65
+ body = JSON.parse(error.response.bodyAsText);
66
66
  } catch (e) {
67
- throw error
67
+ throw error;
68
68
  }
69
- error.message = `${new URL(error.request.url).pathname.slice(1)} error`
70
- const message = getMessage(body)
71
- if (message !== '') error.message += `:${message}`
72
- throw error
69
+ error.message = `${new URL(error.request.url).pathname.slice(1)} error`;
70
+ const message = getMessage(body);
71
+ if (message !== '') error.message += `:${message}`;
72
+ throw error;
73
73
  }
74
- }
74
+ },
75
75
  },
76
- position: 'perCall'
77
- })
76
+ position: 'perCall',
77
+ });
78
78
 
79
79
  export const genVersionCheckPolicy = (
80
- name: string, ignorePath: string,
81
- versionPromise: Promise<string>, geVersion: string, ltVersion: string
80
+ name: string,
81
+ ignorePath: string,
82
+ versionPromise: Promise<string>,
83
+ geVersion: string,
84
+ ltVersion: string,
82
85
  ): PipelinePolicy => ({
83
86
  name: 'version-check',
84
- async sendRequest (request, next) {
85
- if (new URL(request.url).pathname === ignorePath) return await next(request)
86
- const args = [await versionPromise, geVersion, ltVersion] as const
87
- if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args)
88
- return await next(request)
89
- }
90
- })
87
+ async sendRequest(request, next) {
88
+ if (new URL(request.url).pathname === ignorePath) return next(request);
89
+ const args = [await versionPromise, geVersion, ltVersion] as const;
90
+ if (!semverSatisfies(...args)) throw new UnsupportedVersionError(name, ...args);
91
+ return next(request);
92
+ },
93
+ });
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * Big Number Helpers
3
3
  */
4
- import BigNumber from 'bignumber.js'
4
+ import BigNumber from 'bignumber.js';
5
5
 
6
6
  /**
7
7
  * Check if value is BigNumber, Number, BigInt or number string representation
8
8
  * @param number - number to check
9
9
  */
10
10
  export const isBigNumber = (number: string | number | bigint | BigNumber): boolean => {
11
- if (typeof number === 'bigint') return true
12
- return ['number', 'object', 'string'].includes(typeof number) &&
13
- (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))
14
- }
11
+ if (typeof number === 'bigint') return true;
12
+ return ['number', 'object', 'string'].includes(typeof number)
13
+ // eslint-disable-next-line no-restricted-globals
14
+ && (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number));
15
+ };
15
16
 
16
17
  /**
17
18
  * BigNumber ceil operation
18
19
  */
19
20
  export const ceil = (bigNumber: BigNumber): BigNumber => bigNumber
20
- .integerValue(BigNumber.ROUND_CEIL)
21
+ .integerValue(BigNumber.ROUND_CEIL);
@@ -14,20 +14,20 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
- import BigNumber from 'bignumber.js'
18
- import { NoSerializerFoundError, TypeError } from './errors'
19
- import { isBase64, isHex } from './string'
17
+ import BigNumber from 'bignumber.js';
18
+ import { NoSerializerFoundError, TypeError } from './errors';
19
+ import { isBase64, isHex } from './string';
20
20
 
21
21
  /**
22
22
  * Convert bignumber to byte array
23
23
  * @param x - bignumber instance
24
24
  * @returns Buffer
25
25
  */
26
- export function bigNumberToByteArray (x: BigNumber): Buffer {
27
- if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)
28
- let hexString = x.toString(16)
29
- if (hexString.length % 2 === 1) hexString = '0' + hexString
30
- return Buffer.from(hexString, 'hex')
26
+ export function bigNumberToByteArray(x: BigNumber): Buffer {
27
+ if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`);
28
+ let hexString = x.toString(16);
29
+ if (hexString.length % 2 === 1) hexString = `0${hexString}`;
30
+ return Buffer.from(hexString, 'hex');
31
31
  }
32
32
 
33
33
  /**
@@ -36,20 +36,20 @@ export function bigNumberToByteArray (x: BigNumber): Buffer {
36
36
  * @param big - enables force conversion to BigNumber
37
37
  * @returns Buffer
38
38
  */
39
- export function toBytes (val?: null | string | number | BigNumber, big: boolean = false): Buffer {
39
+ export function toBytes(val?: null | string | number | BigNumber, big = false): Buffer {
40
40
  // Encode a value to bytes.
41
41
  // If the value is an int it will be encoded as bytes big endian
42
42
  // Raises ValueError if the input is not an int or string
43
43
 
44
- if (val === undefined || val === null) return Buffer.from([])
44
+ if (val === undefined || val === null) return Buffer.from([]);
45
45
  if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {
46
- if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)
47
- return bigNumberToByteArray(val)
46
+ if (!BigNumber.isBigNumber(val)) val = new BigNumber(val);
47
+ return bigNumberToByteArray(val);
48
48
  }
49
49
  if (typeof val === 'string') {
50
- return Buffer.from(val)
50
+ return Buffer.from(val);
51
51
  }
52
- throw new NoSerializerFoundError()
52
+ throw new NoSerializerFoundError();
53
53
  }
54
54
 
55
55
  /**
@@ -60,13 +60,13 @@ export function toBytes (val?: null | string | number | BigNumber, big: boolean
60
60
  * @param enc - Encoding of the input string.
61
61
  * @returns Buffer containing the input data.
62
62
  */
63
- export function str2buf (str: string, enc?: BufferEncoding): Buffer {
63
+ export function str2buf(str: string, enc?: BufferEncoding): Buffer {
64
64
  return Buffer.from(
65
65
  str,
66
- enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)
67
- )
66
+ enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined),
67
+ );
68
68
  }
69
69
 
70
- export const bytesToHex = (b: Uint8Array): string => Buffer.from(b).toString('hex')
70
+ export const bytesToHex = (b: Uint8Array): string => Buffer.from(b).toString('hex');
71
71
 
72
- export const hexToBytes = (s: string): Uint8Array => Buffer.from(s, 'hex')
72
+ export const hexToBytes = (s: string): Uint8Array => Buffer.from(s, 'hex');
@@ -14,28 +14,27 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
- import nacl, { SignKeyPair } from 'tweetnacl'
18
- import aesjs from 'aes-js'
19
- import { blake2b, Data } from 'blakejs'
20
- import { encode as varuintEncode } from 'varuint-bitcoin'
21
-
22
- import { str2buf } from './bytes'
23
- import { concatBuffers } from './other'
24
- import { encode, decode, sha256hash, EncodedData, EncodingType } from './encoder'
25
-
26
- export { sha256hash }
27
-
28
- const Ecb = aesjs.ModeOfOperation.ecb
17
+ import nacl, { SignKeyPair } from 'tweetnacl';
18
+ // js extension is required for mjs build, not importing the whole package to reduce bundle size
19
+ // eslint-disable-next-line import/extensions
20
+ import { blake2b } from 'blakejs/blake2b.js';
21
+ import { encode as varuintEncode } from 'varuint-bitcoin';
22
+
23
+ import { str2buf } from './bytes';
24
+ import { concatBuffers } from './other';
25
+ import {
26
+ decode, encode, Encoded, Encoding,
27
+ } from './encoder';
29
28
 
30
29
  /**
31
30
  * Generate address from secret key
32
31
  * @param secret - Private key
33
32
  * @returns Public key encoded as address
34
33
  */
35
- export function getAddressFromPriv (secret: string | Uint8Array): EncodedData<'ak'> {
36
- const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret
37
- const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer)
38
- return encode(keys.publicKey, 'ak')
34
+ export function getAddressFromPriv(secret: string | Uint8Array): Encoded.AccountAddress {
35
+ const secretBuffer = typeof secret === 'string' ? str2buf(secret) : secret;
36
+ const keys = nacl.sign.keyPair.fromSecretKey(secretBuffer);
37
+ return encode(keys.publicKey, Encoding.AccountAddress);
39
38
  }
40
39
 
41
40
  /**
@@ -44,12 +43,15 @@ export function getAddressFromPriv (secret: string | Uint8Array): EncodedData<'a
44
43
  * @param prefix - Transaction prefix. Default: 'ak'
45
44
  * @returns is valid
46
45
  */
47
- export function isAddressValid (address: string, prefix: EncodingType = 'ak'): boolean {
46
+ export function isAddressValid(
47
+ address: string,
48
+ prefix: Encoding = Encoding.AccountAddress,
49
+ ): boolean {
48
50
  try {
49
- decode(address as EncodedData<typeof prefix>)
50
- return true
51
+ decode(address as Encoded.Generic<typeof prefix>);
52
+ return true;
51
53
  } catch (e) {
52
- return false
54
+ return false;
53
55
  }
54
56
  }
55
57
 
@@ -57,8 +59,8 @@ export function isAddressValid (address: string, prefix: EncodingType = 'ak'): b
57
59
  * Generate a random salt (positive integer)
58
60
  * @returns random salt
59
61
  */
60
- export function salt (): number {
61
- return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))
62
+ export function genSalt(): number {
63
+ return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));
62
64
  }
63
65
 
64
66
  /**
@@ -67,10 +69,10 @@ export function salt (): number {
67
69
  * @param value - Value to encode
68
70
  * @returns Encoded number
69
71
  */
70
- export function encodeUnsigned (value: number): Buffer {
71
- const binary = Buffer.allocUnsafe(4)
72
- binary.writeUInt32BE(value)
73
- return binary.slice(binary.findIndex(i => i !== 0))
72
+ export function encodeUnsigned(value: number): Buffer {
73
+ const binary = Buffer.allocUnsafe(4);
74
+ binary.writeUInt32BE(value);
75
+ return binary.slice(binary.findIndex((i) => i !== 0));
74
76
  }
75
77
 
76
78
  /**
@@ -78,21 +80,25 @@ export function encodeUnsigned (value: number): Buffer {
78
80
  * @param input - Data to hash
79
81
  * @returns Hash
80
82
  */
81
- export function hash (input: Data): Buffer {
82
- return Buffer.from(blake2b(input, undefined, 32)) // 256 bits
83
+ export function hash(input: string | Uint8Array): Buffer {
84
+ return Buffer.from(blake2b(input, undefined, 32)); // 256 bits
83
85
  }
84
86
 
85
87
  // Todo Duplicated in tx builder. remove
86
88
  /**
87
89
  * Compute contract address
90
+ * @category contract
88
91
  * @param owner - Address of contract owner
89
92
  * @param nonce - Round when contract was created
90
93
  * @returns Contract address
91
94
  */
92
- export function encodeContractAddress (owner: EncodedData<'ak'>, nonce: number): EncodedData<'ct'> {
93
- const publicKey = decode(owner)
94
- const binary = concatBuffers([publicKey, encodeUnsigned(nonce)])
95
- return encode(hash(binary), 'ct')
95
+ export function encodeContractAddress(
96
+ owner: Encoded.AccountAddress,
97
+ nonce: number,
98
+ ): Encoded.ContractAddress {
99
+ const publicKey = decode(owner);
100
+ const binary = concatBuffers([publicKey, encodeUnsigned(nonce)]);
101
+ return encode(hash(binary), Encoding.ContractAddress);
96
102
  }
97
103
 
98
104
  // KEY-PAIR HELPERS
@@ -102,8 +108,8 @@ export function encodeContractAddress (owner: EncodedData<'ak'>, nonce: number):
102
108
  * @param secret - secret key
103
109
  * @returns Object with Private(privateKey) and Public(publicKey) keys
104
110
  */
105
- export function generateKeyPairFromSecret (secret: Uint8Array): SignKeyPair {
106
- return nacl.sign.keyPair.fromSecretKey(secret)
111
+ export function generateKeyPairFromSecret(secret: Uint8Array): SignKeyPair {
112
+ return nacl.sign.keyPair.fromSecretKey(secret);
107
113
  }
108
114
 
109
115
  /**
@@ -111,52 +117,28 @@ export function generateKeyPairFromSecret (secret: Uint8Array): SignKeyPair {
111
117
  * @param raw - Whether to return raw (binary) keys
112
118
  * @returns Key pair
113
119
  */
114
- export function generateKeyPair (raw: true): { publicKey: Buffer, secretKey: Buffer }
115
- export function generateKeyPair (raw?: false): { publicKey: EncodedData<'ak'>, secretKey: string }
116
- export function generateKeyPair (raw: boolean = false): {
117
- publicKey: EncodedData<'ak'> | Buffer
118
- secretKey: string | Buffer
120
+ export function generateKeyPair(raw: true): { publicKey: Buffer; secretKey: Buffer };
121
+ export function generateKeyPair(raw?: false): {
122
+ publicKey: Encoded.AccountAddress; secretKey: string;
123
+ };
124
+ export function generateKeyPair(raw = false): {
125
+ publicKey: Encoded.AccountAddress | Buffer;
126
+ secretKey: string | Buffer;
119
127
  } {
120
- const keyPair = nacl.sign.keyPair()
121
- const publicBuffer = Buffer.from(keyPair.publicKey)
122
- const secretBuffer = Buffer.from(keyPair.secretKey)
128
+ const keyPair = nacl.sign.keyPair();
129
+ const publicBuffer = Buffer.from(keyPair.publicKey);
130
+ const secretBuffer = Buffer.from(keyPair.secretKey);
123
131
 
124
132
  if (raw) {
125
133
  return {
126
134
  publicKey: publicBuffer,
127
- secretKey: secretBuffer
128
- }
129
- } else {
130
- return {
131
- publicKey: encode(publicBuffer, 'ak'),
132
- secretKey: secretBuffer.toString('hex')
133
- }
135
+ secretKey: secretBuffer,
136
+ };
134
137
  }
135
- }
136
-
137
- /**
138
- * Encrypt given data using `password`
139
- * @param password - Password to encrypt with
140
- * @param binaryData - Data to encrypt
141
- * @returns Encrypted data
142
- */
143
- export function encryptKey (password: string, binaryData: Uint8Array): Uint8Array {
144
- const hashedPasswordBytes = sha256hash(password)
145
- const aesEcb = new Ecb(hashedPasswordBytes)
146
- return aesEcb.encrypt(binaryData)
147
- }
148
-
149
- /**
150
- * Decrypt given data using `password`
151
- * @param password - Password to decrypt with
152
- * @param encrypted - Data to decrypt
153
- * @returns Decrypted data
154
- */
155
- export function decryptKey (password: string, encrypted: Uint8Array): Uint8Array {
156
- const encryptedBytes = Buffer.from(encrypted)
157
- const hashedPasswordBytes = sha256hash(password)
158
- const aesEcb = new Ecb(hashedPasswordBytes)
159
- return aesEcb.decrypt(encryptedBytes)
138
+ return {
139
+ publicKey: encode(publicBuffer, Encoding.AccountAddress),
140
+ secretKey: secretBuffer.toString('hex'),
141
+ };
160
142
  }
161
143
 
162
144
  // SIGNATURES
@@ -167,8 +149,8 @@ export function decryptKey (password: string, encrypted: Uint8Array): Uint8Array
167
149
  * @param privateKey - Key to sign with
168
150
  * @returns Signature
169
151
  */
170
- export function sign (data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {
171
- return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))
152
+ export function sign(data: string | Uint8Array, privateKey: string | Uint8Array): Uint8Array {
153
+ return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));
172
154
  }
173
155
 
174
156
  /**
@@ -178,26 +160,31 @@ export function sign (data: string | Uint8Array, privateKey: string | Uint8Array
178
160
  * @param publicKey - Key to verify against
179
161
  * @returns Valid?
180
162
  */
181
- export function verify (
182
- data: Uint8Array, signature: Uint8Array, publicKey: string | Uint8Array
163
+ export function verify(
164
+ data: Uint8Array,
165
+ signature: Uint8Array,
166
+ publicKey: string | Uint8Array,
183
167
  ): boolean {
184
- const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey
185
- return nacl.sign.detached.verify(data, signature, publicKeyBuffer)
168
+ const publicKeyBuffer = typeof publicKey === 'string' ? str2buf(publicKey) : publicKey;
169
+ return nacl.sign.detached.verify(data, signature, publicKeyBuffer);
186
170
  }
187
171
 
188
- export function messageToHash (message: string): Buffer {
189
- const p = Buffer.from('aeternity Signed Message:\n', 'utf8')
190
- const msg = Buffer.from(message, 'utf8')
191
- return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]))
172
+ export function messageToHash(message: string): Buffer {
173
+ const p = Buffer.from('aeternity Signed Message:\n', 'utf8');
174
+ const msg = Buffer.from(message, 'utf8');
175
+ return hash(concatBuffers([varuintEncode(p.length), p, varuintEncode(msg.length), msg]));
192
176
  }
193
177
 
194
- export function signMessage (message: string, privateKey: string | Buffer): Uint8Array {
195
- return sign(messageToHash(message), privateKey)
178
+ export function signMessage(message: string, privateKey: string | Buffer): Uint8Array {
179
+ return sign(messageToHash(message), privateKey);
196
180
  }
197
181
 
198
- export function verifyMessage (
199
- str: string, signature: Uint8Array, publicKey: string | Uint8Array): boolean {
200
- return verify(messageToHash(str), signature, publicKey)
182
+ export function verifyMessage(
183
+ str: string,
184
+ signature: Uint8Array,
185
+ publicKey: string | Uint8Array,
186
+ ): boolean {
187
+ return verify(messageToHash(str), signature, publicKey);
201
188
  }
202
189
 
203
190
  /**
@@ -208,10 +195,11 @@ export function verifyMessage (
208
195
  * @param publicKey - Public key to verify
209
196
  * @returns Valid?
210
197
  */
211
- export function isValidKeypair (
212
- privateKey: string | Uint8Array, publicKey: string | Uint8Array
198
+ export function isValidKeypair(
199
+ privateKey: string | Uint8Array,
200
+ publicKey: string | Uint8Array,
213
201
  ): boolean {
214
- const message = Buffer.from('TheMessage')
215
- const signature = sign(message, privateKey)
216
- return verify(message, signature, publicKey)
202
+ const message = Buffer.from('TheMessage');
203
+ const signature = sign(message, privateKey);
204
+ return verify(message, signature, publicKey);
217
205
  }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @category transaction builder
3
+ * @see {@link https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md}
4
+ * @see {@link https://github.com/aeternity/aeserialization/blob/eb68fe331bd476910394966b7f5ede7a74d37e35/src/aeser_api_encoder.erl#L205-L230}
5
+ */
6
+ export enum Encoding {
7
+ KeyBlockHash = 'kh',
8
+ MicroBlockHash = 'mh',
9
+ BlockPofHash = 'bf',
10
+ BlockTxHash = 'bx',
11
+ BlockStateHash = 'bs',
12
+ Channel = 'ch',
13
+ ContractAddress = 'ct',
14
+ ContractBytearray = 'cb',
15
+ ContractStoreKey = 'ck',
16
+ ContractStoreValue = 'cv',
17
+ Transaction = 'tx',
18
+ TxHash = 'th',
19
+ OracleAddress = 'ok',
20
+ OracleQuery = 'ov',
21
+ OracleQueryId = 'oq',
22
+ OracleResponse = 'or',
23
+ AccountAddress = 'ak',
24
+ Signature = 'sg',
25
+ Commitment = 'cm',
26
+ PeerPubkey = 'pp',
27
+ Name = 'nm',
28
+ State = 'st',
29
+ Poi = 'pi',
30
+ StateTrees = 'ss',
31
+ CallStateTree = 'cs',
32
+ Bytearray = 'ba',
33
+ }
34
+
35
+ export type KeyBlockHash = `${Encoding.KeyBlockHash}_${string}`;
36
+ export type MicroBlockHash = `${Encoding.MicroBlockHash}_${string}`;
37
+ export type BlockPofHash = `${Encoding.BlockPofHash}_${string}`;
38
+ export type BlockTxHash = `${Encoding.BlockTxHash}_${string}`;
39
+ export type BlockStateHash = `${Encoding.BlockStateHash}_${string}`;
40
+ export type Channel = `${Encoding.Channel}_${string}`;
41
+ export type ContractAddress = `${Encoding.ContractAddress}_${string}`;
42
+ export type ContractBytearray = `${Encoding.ContractBytearray}_${string}`;
43
+ export type ContractStoreKey = `${Encoding.ContractStoreKey}_${string}`;
44
+ export type ContractStoreValue = `${Encoding.ContractStoreValue}_${string}`;
45
+ export type Transaction = `${Encoding.Transaction}_${string}`;
46
+ export type TxHash = `${Encoding.TxHash}_${string}`;
47
+ export type OracleAddress = `${Encoding.OracleAddress}_${string}`;
48
+ export type OracleQuery = `${Encoding.OracleQuery}_${string}`;
49
+ export type OracleQueryId = `${Encoding.OracleQueryId}_${string}`;
50
+ export type OracleResponse = `${Encoding.OracleResponse}_${string}`;
51
+ export type AccountAddress = `${Encoding.AccountAddress}_${string}`;
52
+ export type Signature = `${Encoding.Signature}_${string}`;
53
+ export type Commitment = `${Encoding.Commitment}_${string}`;
54
+ export type PeerPubkey = `${Encoding.PeerPubkey}_${string}`;
55
+ export type Name = `${Encoding.Name}_${string}`;
56
+ export type State = `${Encoding.State}_${string}`;
57
+ export type Poi = `${Encoding.Poi}_${string}`;
58
+ export type StateTrees = `${Encoding.StateTrees}_${string}`;
59
+ export type CallStateTree = `${Encoding.CallStateTree}_${string}`;
60
+ export type Bytearray = `${Encoding.Bytearray}_${string}`;
61
+
62
+ export type Generic<Type extends Encoding> = `${Type}_${string}`;
63
+ export type Any = `${Encoding}_${string}`;