@aeternity/aepp-sdk 9.0.1 → 11.0.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 (284) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/base.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/index.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/index.mjs +178 -0
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/index.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
@@ -3,12 +3,19 @@
3
3
  *
4
4
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client
5
5
  * @export { RpcClient, RpcClients }
6
- * @example import RpcClient from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client'
6
+ * @example
7
+ * import RpcClient from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client'
7
8
  */
8
9
  import stampit from '@stamp/it'
9
10
 
10
11
  import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES } from '../schema'
11
12
  import { sendMessage, message, isValidAccounts } from '../helpers'
13
+ import {
14
+ InvalidRpcMessageError,
15
+ TypeError,
16
+ DuplicateCallbackError,
17
+ MissingCallbackError
18
+ } from '../../errors'
12
19
 
13
20
  /**
14
21
  * Contain functionality for using RPC conection
@@ -18,7 +25,9 @@ import { sendMessage, message, isValidAccounts } from '../helpers'
18
25
  * @param {Object} param Init params object
19
26
  * @param {String} param.name Client name
20
27
  * @param {Object} param.connection Connection object
21
- * @param {Function[]} param.handlers Arrays with two function for handling messages ([ onMessage: Function, onDisconnect: Function])
28
+ * @param {Function[]} param.handlers Array with two function for message handling
29
+ * @param {Function} param.handlers[0] Message handler
30
+ * @param {Function} param.handlers[1] Disconnect callback
22
31
  * @return {Object}
23
32
  */
24
33
  export default stampit({
@@ -42,7 +51,7 @@ export default stampit({
42
51
 
43
52
  const handleMessage = (msg, origin) => {
44
53
  if (!msg || !msg.jsonrpc || msg.jsonrpc !== '2.0' || !msg.method) {
45
- throw new Error(`Received invalid message: ${msg}`)
54
+ throw new InvalidRpcMessageError(msg)
46
55
  }
47
56
  onMessage(msg, origin)
48
57
  }
@@ -120,7 +129,8 @@ export default stampit({
120
129
  * @return {Boolean} is connected
121
130
  */
122
131
  isConnected () {
123
- return this.connection.isConnected() && this.info.status === RPC_STATUS.CONNECTED
132
+ return this.connection.isConnected() &&
133
+ (this.info.status === RPC_STATUS.CONNECTED || this.info.status === RPC_STATUS.NODE_BINDED)
124
134
  },
125
135
  /**
126
136
  * Get selected account
@@ -148,17 +158,18 @@ export default stampit({
148
158
  },
149
159
  /**
150
160
  * Update accounts and sent `update.address` notification to AEPP
151
- * @param {{ current: Object, connected: Object }} accounts Object with current and connected accounts
152
- * @param {{ forceNotification: Boolean }} [options={ forceNotification: false }] Don not sent update notification to AEPP
161
+ * @param {{ current: Object, connected: Object }} accounts Current and connected accounts
162
+ * @param {Object} [options]
163
+ * @param {Boolean} [options.forceNotification] Don't sent update notification to AEPP
153
164
  */
154
- setAccounts (accounts, { forceNotification = false } = {}) {
165
+ setAccounts (accounts, { forceNotification } = {}) {
155
166
  if (!isValidAccounts(accounts)) {
156
- throw new Error('Invalid accounts object. Should be object like: `{ connected: {}, selected: {} }`')
167
+ throw new TypeError('Invalid accounts object. Should be object like: `{ connected: {}, selected: {} }`')
157
168
  }
158
169
  this.accounts = accounts
159
170
  if (!forceNotification) {
160
171
  // Sent notification about account updates
161
- this.sendMessage(message(METHODS.wallet.updateAddress, this.accounts), true)
172
+ this.sendMessage(message(METHODS.updateAddress, this.accounts), true)
162
173
  }
163
174
  },
164
175
  /**
@@ -190,7 +201,9 @@ export default stampit({
190
201
  */
191
202
  request (name, params) {
192
203
  const msgId = this.sendMessage(message(name, params))
193
- if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId)) throw new Error('Callback Already exist')
204
+ if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId)) {
205
+ throw new DuplicateCallbackError()
206
+ }
194
207
  return new Promise((resolve, reject) => {
195
208
  this.callbacks[msgId] = { resolve, reject }
196
209
  })
@@ -205,7 +218,7 @@ export default stampit({
205
218
  * @return {void}
206
219
  */
207
220
  processResponse ({ id, error, result }, transformResult) {
208
- if (!this.callbacks[id]) throw new Error(`Can't find callback for this messageId ${id}`)
221
+ if (!this.callbacks[id]) throw new MissingCallbackError(id)
209
222
  if (result) {
210
223
  this.callbacks[id].resolve(...typeof transformResult === 'function'
211
224
  ? transformResult({ id, result })
@@ -3,16 +3,27 @@
3
3
  *
4
4
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc
5
5
  * @export WalletRpc
6
- * @example import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
6
+ * @example
7
+ * import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
7
8
  */
8
- import { v4 as uuid } from 'uuid'
9
+ import { v4 as uuid } from '@aeternity/uuid'
9
10
  import Ae from '../../../ae'
10
11
  import verifyTransaction from '../../../tx/validator'
11
12
  import AccountMultiple from '../../../account/multiple'
12
13
  import TxObject from '../../../tx/tx-object'
13
14
  import RpcClient from './rpc-client'
14
- import { getBrowserAPI, getHandler, isValidAccounts, message, resolveOnAccount, sendResponseMessage } from '../helpers'
15
+ import { getBrowserAPI, getHandler, isValidAccounts, message, sendResponseMessage } from '../helpers'
15
16
  import { ERRORS, METHODS, RPC_STATUS, VERSION, WALLET_TYPE } from '../schema'
17
+ import { ArgumentError, TypeError, UnknownRpcClientError } from '../../errors'
18
+ import { isAccountBase } from '../../../account/base'
19
+
20
+ const resolveOnAccount = (addresses, onAccount, opt = {}) => {
21
+ if (!addresses.find(a => a === onAccount)) {
22
+ if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new TypeError('Provided onAccount should be an AccountBase')
23
+ onAccount = opt.onAccount
24
+ }
25
+ return onAccount
26
+ }
16
27
 
17
28
  const NOTIFICATIONS = {
18
29
  [METHODS.closeConnection]: (instance, { client }) =>
@@ -27,26 +38,36 @@ const RESPONSES = {}
27
38
  const REQUESTS = {
28
39
  // Store client info and prepare two fn for each client `connect` and `denyConnection`
29
40
  // which automatically prepare and send response for that client
30
- [METHODS.aepp.connect] (callInstance, instance, client, { name, networkId, version, icons }) {
41
+ [METHODS.connect] (
42
+ callInstance,
43
+ instance,
44
+ client,
45
+ { name, networkId, version, icons, connectNode }) {
31
46
  // Check if protocol and network is compatible with wallet
32
47
  if (version !== VERSION) return { error: ERRORS.unsupportedProtocol() }
33
-
34
48
  // Store new AEPP and wait for connection approve
35
49
  client.updateInfo({
36
50
  status: RPC_STATUS.WAITING_FOR_CONNECTION_APPROVE,
37
51
  name,
38
52
  networkId,
39
53
  icons,
40
- version
54
+ version,
55
+ origin: window.location.origin,
56
+ connectNode
41
57
  })
42
58
 
43
59
  // Call onConnection callBack to notice Wallet about new AEPP
44
60
  return callInstance(
45
61
  'onConnection',
46
62
  { name, networkId, version },
47
- () => {
48
- client.updateInfo({ status: RPC_STATUS.CONNECTED })
49
- return { result: instance.getWalletInfo() }
63
+ ({ shareNode } = {}) => {
64
+ client.updateInfo({ status: shareNode ? RPC_STATUS.NODE_BINDED : RPC_STATUS.CONNECTED })
65
+ return {
66
+ result: {
67
+ ...instance.getWalletInfo(),
68
+ ...(shareNode && { node: instance.selectedNode })
69
+ }
70
+ }
50
71
  },
51
72
  (error) => {
52
73
  client.updateInfo({ status: RPC_STATUS.CONNECTION_REJECTED })
@@ -54,7 +75,7 @@ const REQUESTS = {
54
75
  }
55
76
  )
56
77
  },
57
- [METHODS.aepp.subscribeAddress] (callInstance, instance, client, { type, value }) {
78
+ [METHODS.subscribeAddress] (callInstance, instance, client, { type, value }) {
58
79
  // Authorization check
59
80
  if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
60
81
 
@@ -64,7 +85,9 @@ const REQUESTS = {
64
85
  async ({ accounts } = {}) => {
65
86
  try {
66
87
  const clientAccounts = accounts || instance.getAccounts()
67
- if (!isValidAccounts(clientAccounts)) throw new Error('Invalid provided accounts object')
88
+ if (!isValidAccounts(clientAccounts)) {
89
+ throw new TypeError('Invalid provided accounts object')
90
+ }
68
91
  const subscription = client.updateSubscription(type, value)
69
92
  client.setAccounts(clientAccounts, { forceNotification: true })
70
93
  return {
@@ -74,14 +97,14 @@ const REQUESTS = {
74
97
  }
75
98
  }
76
99
  } catch (e) {
77
- console.error(e)
78
- return { error: ERRORS.internalError({ msg: e.message }) }
100
+ if (instance.debug) console.error(e)
101
+ return { error: ERRORS.internalError(e.message) }
79
102
  }
80
103
  },
81
104
  (error) => ({ error: ERRORS.rejectedByUser(error) })
82
105
  )
83
106
  },
84
- [METHODS.aepp.address] (callInstance, instance, client) {
107
+ [METHODS.address] (callInstance, instance, client) {
85
108
  // Authorization check
86
109
  if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
87
110
  if (!client.isSubscribed()) return { error: ERRORS.notAuthorize() }
@@ -89,20 +112,28 @@ const REQUESTS = {
89
112
  return callInstance(
90
113
  'onAskAccounts',
91
114
  {},
92
- ({ accounts } = {}) => ({ result: accounts || [...Object.keys(client.accounts.current), ...Object.keys(client.accounts.connected)] }),
115
+ ({ accounts } = {}) => ({
116
+ result: accounts ||
117
+ [...Object.keys(client.accounts.current), ...Object.keys(client.accounts.connected)]
118
+ }),
93
119
  (error) => ({ error: ERRORS.rejectedByUser(error) })
94
120
  )
95
121
  },
96
- [METHODS.aepp.sign] (callInstance, instance, client, { tx, onAccount, networkId, returnSigned = false }) {
122
+ [METHODS.sign] (callInstance, instance, client, options) {
123
+ const { tx, onAccount, networkId, returnSigned = false } = options
97
124
  const address = onAccount || client.currentAccount
98
125
  // Update client with new networkId
99
126
  networkId && client.updateInfo({ networkId })
100
127
  // Authorization check
101
128
  if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
102
129
  // Account permission check
103
- if (!client.hasAccessToAccount(address)) return { error: ERRORS.permissionDeny({ account: address }) }
130
+ if (!client.hasAccessToAccount(address)) {
131
+ return { error: ERRORS.permissionDeny(address) }
132
+ }
104
133
  // NetworkId check
105
- if (!networkId || networkId !== instance.getNetworkId()) return { error: ERRORS.unsupportedNetwork() }
134
+ if (!networkId || networkId !== instance.getNetworkId()) {
135
+ return { error: ERRORS.unsupportedNetwork() }
136
+ }
106
137
 
107
138
  return callInstance(
108
139
  'onSign',
@@ -112,15 +143,15 @@ const REQUESTS = {
112
143
  try {
113
144
  onAcc = resolveOnAccount(instance.addresses(), address, opt)
114
145
  } catch (e) {
115
- console.error(e)
116
- return { error: ERRORS.internalError({ msg: e.message }) }
146
+ if (instance.debug) console.error(e)
147
+ return { error: ERRORS.internalError(e.message) }
117
148
  }
118
149
  try {
119
- return {
120
- result: returnSigned
121
- ? { signedTransaction: await instance.signTransaction(rawTx || tx, { onAccount: onAcc }) }
122
- : { transactionHash: await instance.send(rawTx || tx, { onAccount: onAcc, verify: false }) }
123
- }
150
+ const t = rawTx || tx
151
+ const result = returnSigned
152
+ ? { signedTransaction: await instance.signTransaction(t, { onAccount: onAcc }) }
153
+ : { transactionHash: await instance.send(t, { onAccount: onAcc, verify: false }) }
154
+ return { result }
124
155
  } catch (e) {
125
156
  if (!returnSigned) {
126
157
  // Validate transaction
@@ -135,11 +166,13 @@ const REQUESTS = {
135
166
  (error) => ({ error: ERRORS.rejectedByUser(error) })
136
167
  )
137
168
  },
138
- [METHODS.aepp.signMessage] (callInstance, instance, client, { message, onAccount }) {
169
+ [METHODS.signMessage] (callInstance, instance, client, { message, onAccount }) {
139
170
  // Authorization check
140
171
  if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
141
172
  const address = onAccount || client.currentAccount
142
- if (!client.hasAccessToAccount(address)) return { error: ERRORS.permissionDeny({ account: address }) }
173
+ if (!client.hasAccessToAccount(address)) {
174
+ return { error: ERRORS.permissionDeny(address) }
175
+ }
143
176
 
144
177
  return callInstance(
145
178
  'onMessageSign',
@@ -156,8 +189,8 @@ const REQUESTS = {
156
189
  }
157
190
  }
158
191
  } catch (e) {
159
- console.error(e)
160
- return { error: ERRORS.internalError({ msg: e.message }) }
192
+ if (instance.debug) console.error(e)
193
+ return { error: ERRORS.internalError(e.message) }
161
194
  }
162
195
  },
163
196
  (error) => ({ error: ERRORS.rejectedByUser(error) })
@@ -168,7 +201,9 @@ const REQUESTS = {
168
201
  const handleMessage = (instance, id) => async (msg, origin) => {
169
202
  const client = instance.rpcClients[id]
170
203
  if (!msg.id) {
171
- return getHandler(NOTIFICATIONS, msg, { debug: instance.debug })(instance, { client })(msg, origin)
204
+ return getHandler(
205
+ NOTIFICATIONS, msg, { debug: instance.debug }
206
+ )(instance, { client })(msg, origin)
172
207
  }
173
208
  if (Object.prototype.hasOwnProperty.call(client.callbacks, msg.id)) {
174
209
  return getHandler(RESPONSES, msg, { debug: instance.debug })(instance, { client })(msg, origin)
@@ -188,7 +223,9 @@ const handleMessage = (instance, id) => async (msg, origin) => {
188
223
  )
189
224
  })
190
225
  // TODO make one structure for handler functions
191
- const errorObjectOrHandler = getHandler(REQUESTS, msg, { debug: instance.debug })(callInstance, instance, client, msg.params)
226
+ const errorObjectOrHandler = getHandler(REQUESTS, msg, { debug: instance.debug })(
227
+ callInstance, instance, client, msg.params
228
+ )
192
229
  const response = typeof errorObjectOrHandler === 'function' ? await errorObjectOrHandler() : errorObjectOrHandler
193
230
  sendResponseMessage(client)(id, method, response)
194
231
  }
@@ -201,31 +238,31 @@ const handleMessage = (instance, id) => async (msg, origin) => {
201
238
  * @rtype Stamp
202
239
  * @param {Object} param Init params object
203
240
  * @param {String=} [param.name] Wallet name
204
- * @param {Function} onConnection Call-back function for incoming AEPP connection (Second argument contain function for accept/deny request)
205
- * @param {Function} onSubscription Call-back function for incoming AEPP account subscription (Second argument contain function for accept/deny request)
206
- * @param {Function} onSign Call-back function for incoming AEPP sign request (Second argument contain function for accept/deny request)
207
- * @param {Function} onAskAccounts Call-back function for incoming AEPP get address request (Second argument contain function for accept/deny request)
208
- * @param {Function} onMessageSign Call-back function for incoming AEPP sign message request (Second argument contain function for accept/deny request)
241
+ * @param {Function} onConnection Call-back function for incoming AEPP connection
242
+ * @param {Function} onSubscription Call-back function for incoming AEPP account subscription
243
+ * @param {Function} onSign Call-back function for incoming AEPP sign request
244
+ * @param {Function} onAskAccounts Call-back function for incoming AEPP get address request
245
+ * @param {Function} onMessageSign Call-back function for incoming AEPP sign message request
246
+ * Second argument of incoming call-backs contain function for accept/deny request
209
247
  * @param {Function} onDisconnect Call-back function for disconnect event
210
248
  * @return {Object}
211
249
  */
212
250
  export default Ae.compose(AccountMultiple, {
213
- init ({ name, onConnection, onSubscription, onSign, onDisconnect, onAskAccounts, onMessageSign, forceValidation = false, debug = false } = {}) {
251
+ init ({
252
+ name,
253
+ debug = false,
254
+ ...other
255
+ } = {}) {
256
+ [
257
+ 'onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onAskAccounts', 'onMessageSign'
258
+ ].forEach(event => {
259
+ const handler = other[event]
260
+ if (typeof handler !== 'function') throw new ArgumentError(event, 'a function', handler)
261
+ this[event] = handler
262
+ })
263
+
214
264
  this.debug = debug
215
- const eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']
216
- // CallBacks for events
217
- this.onConnection = onConnection
218
- this.onSubscription = onSubscription
219
- this.onSign = onSign
220
- this.onDisconnect = onDisconnect
221
- this.onAskAccounts = onAskAccounts
222
- this.onMessageSign = onMessageSign
223
265
  this.rpcClients = {}
224
-
225
- eventsHandlers.forEach(event => {
226
- if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
227
- })
228
- //
229
266
  this.name = name
230
267
  this.id = uuid()
231
268
 
@@ -268,9 +305,13 @@ export default Ae.compose(AccountMultiple, {
268
305
  // Send notification 'update.network' to all Aepp which connected
269
306
  Object.values(this.rpcClients)
270
307
  .filter(client => client.isConnected())
271
- .forEach(client => client.sendMessage(
272
- message(METHODS.updateNetwork, { networkId: this.getNetworkId() }), true
273
- ))
308
+ .forEach(client => {
309
+ client.sendMessage(
310
+ message(METHODS.updateNetwork, {
311
+ networkId: this.getNetworkId(),
312
+ ...(client.info.status === RPC_STATUS.NODE_BINDED && { node: this.selectedNode })
313
+ }), true)
314
+ })
274
315
  }
275
316
  },
276
317
  methods: {
@@ -285,7 +326,7 @@ export default Ae.compose(AccountMultiple, {
285
326
  */
286
327
  removeRpcClient (id, { forceConnectionClose = false } = {}) {
287
328
  const client = this.rpcClients[id]
288
- if (!client) throw new Error(`RpcClient with id ${id} do not exist`)
329
+ if (!client) throw new UnknownRpcClientError(id)
289
330
  client.disconnect(forceConnectionClose)
290
331
  delete this.rpcClients[id]
291
332
  },
@@ -298,7 +339,8 @@ export default Ae.compose(AccountMultiple, {
298
339
  * @return {String} Client ID
299
340
  */
300
341
  addRpcClient (clientConnection) {
301
- // @TODO detect if aepp has some history based on origin????: if yes use this instance for connection
342
+ // @TODO detect if aepp has some history based on origin????
343
+ // if yes use this instance for connection
302
344
  const id = uuid()
303
345
  this.rpcClients[id] = RpcClient({
304
346
  id,
@@ -320,7 +362,7 @@ export default Ae.compose(AccountMultiple, {
320
362
  shareWalletInfo (postFn) {
321
363
  postFn({
322
364
  jsonrpc: '2.0',
323
- ...message(METHODS.wallet.readyToConnect, this.getWalletInfo())
365
+ ...message(METHODS.readyToConnect, this.getWalletInfo())
324
366
  })
325
367
  },
326
368
  /**
@@ -0,0 +1,80 @@
1
+ export const VERSION = 1
2
+
3
+ export const enum MESSAGE_DIRECTION {
4
+ to_waellet = 'to_waellet',
5
+ to_aepp = 'to_aepp'
6
+ }
7
+
8
+ export const enum WALLET_TYPE {
9
+ window = 'window',
10
+ extension = 'extension'
11
+ }
12
+
13
+ export const enum SUBSCRIPTION_TYPES {
14
+ subscribe = 'subscribe',
15
+ unsubscribe = 'unsubscribe'
16
+ }
17
+
18
+ export const enum METHODS {
19
+ readyToConnect = 'connection.announcePresence',
20
+ updateAddress = 'address.update',
21
+ address = 'address.get',
22
+ connect = 'connection.open',
23
+ sign = 'transaction.sign',
24
+ signMessage = 'message.sign',
25
+ subscribeAddress = 'address.subscribe',
26
+ updateNetwork = 'networkId.update',
27
+ closeConnection = 'connection.close'
28
+ }
29
+
30
+ export const enum RPC_STATUS {
31
+ CONNECTED = 'CONNECTED',
32
+ NODE_BINDED = 'NODE_BINDED',
33
+ DISCONNECTED = 'DISCONNECTED',
34
+ CONNECTION_REJECTED = 'CONNECTION_REJECTED',
35
+ WAITING_FOR_CONNECTION_APPROVE = 'WAITING_FOR_CONNECTION_APPROVE',
36
+ WAITING_FOR_CONNECTION_REQUEST = 'WAITING_FOR_CONNECTION_REQUEST'
37
+ }
38
+
39
+ export const ERRORS = {
40
+ broadcastFailed: (error = {}) => ({
41
+ code: 3,
42
+ data: error,
43
+ message: 'Broadcast failed'
44
+ }),
45
+ invalidTransaction: (error = {}) => ({
46
+ code: 2,
47
+ data: error,
48
+ message: 'Invalid transaction'
49
+ }),
50
+ rejectedByUser: (error = {}) => ({
51
+ code: 4,
52
+ data: error,
53
+ message: 'Operation rejected by user'
54
+ }),
55
+ connectionDeny: (error = {}) => ({
56
+ code: 9,
57
+ data: error,
58
+ message: 'Wallet deny your connection request'
59
+ }),
60
+ permissionDeny: (address: string) => ({
61
+ code: 11,
62
+ message: `You are not subscribed for account ${address}`
63
+ }),
64
+ internalError: (message: string) => ({
65
+ code: 12,
66
+ message
67
+ }),
68
+ notAuthorize: () => ({
69
+ code: 10,
70
+ message: 'You are not connected to the wallet'
71
+ }),
72
+ unsupportedProtocol: () => ({
73
+ code: 5,
74
+ message: 'Unsupported Protocol Version'
75
+ }),
76
+ unsupportedNetwork: () => ({
77
+ code: 8,
78
+ message: 'Unsupported Network'
79
+ })
80
+ }
@@ -25,6 +25,7 @@
25
25
  import stampit from '@stamp/it'
26
26
  import BrowserWindowMessageConnection from './connection/browser-window-message'
27
27
  import { MESSAGE_DIRECTION, METHODS } from './schema'
28
+ import { UnsupportedPlatformError } from '../errors'
28
29
 
29
30
  /**
30
31
  * WalletDetector stamp
@@ -37,7 +38,7 @@ import { MESSAGE_DIRECTION, METHODS } from './schema'
37
38
  */
38
39
  export default stampit({
39
40
  init ({ connection } = {}) {
40
- if (!window) throw new Error('Window object not found, you can run wallet detector only in browser')
41
+ if (!window) throw new UnsupportedPlatformError('Window object not found, you can run wallet detector only in browser')
41
42
  this.connection = connection || BrowserWindowMessageConnection({ connectionInfo: { id: 'spy' } })
42
43
  this.wallets = {}
43
44
  },
@@ -52,7 +53,10 @@ export default stampit({
52
53
  scan (onDetected) {
53
54
  const { wallets } = this
54
55
  this.connection.connect(({ method, params }, origin, source) => {
55
- if (!method || !params || method !== METHODS.wallet.readyToConnect || wallets[params.id]) return
56
+ if (
57
+ !method || !params ||
58
+ method !== METHODS.readyToConnect || wallets[params.id]
59
+ ) return
56
60
 
57
61
  const wallet = {
58
62
  ...params,
@@ -22,6 +22,7 @@
22
22
  */
23
23
  import BigNumber from 'bignumber.js'
24
24
  import { isBigNumber } from './bignumber'
25
+ import { ArgumentError, InvalidDenominationError } from './errors'
25
26
 
26
27
  /**
27
28
  * AE amount formats
@@ -86,9 +87,9 @@ export const formatAmount = (
86
87
  { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS } = {}
87
88
  ): string => {
88
89
  const denominations = Object.values(AE_AMOUNT_FORMATS)
89
- if (!denominations.includes(denomination)) throw new Error(`Invalid denomination: ${denomination}`)
90
- if (!denominations.includes(targetDenomination)) throw new Error(`Invalid target denomination: ${targetDenomination}`)
91
- if (!isBigNumber(value)) throw new Error(`Value ${value?.toString()} is not type of number`)
90
+ if (!denominations.includes(denomination)) throw new InvalidDenominationError(`Invalid denomination: ${denomination}`)
91
+ if (!denominations.includes(targetDenomination)) throw new InvalidDenominationError(`Invalid target denomination: ${targetDenomination}`)
92
+ if (!isBigNumber(value)) throw new ArgumentError('value', `a number`, value)
92
93
 
93
94
  return new BigNumber(value)
94
95
  .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * ISC License (ISC)
3
- * Copyright (c) 2018 aeternity developers
3
+ * Copyright (c) 2022 aeternity developers
4
4
  *
5
5
  * Permission to use, copy, modify, and/or distribute this software for any
6
6
  * purpose with or without fee is hereby granted, provided that the above
@@ -16,7 +16,6 @@
16
16
  */
17
17
 
18
18
  import stampit from '@stamp/it'
19
- import * as R from 'ramda'
20
19
 
21
20
  function asyncInit (options = {}, { stamp, args, instance }) {
22
21
  return stamp.compose.deepConfiguration.AsyncInit.initializers.reduce(async (instance, init) => {
@@ -29,13 +28,18 @@ function asyncInit (options = {}, { stamp, args, instance }) {
29
28
  }, instance)
30
29
  }
31
30
 
32
- const AsyncInit = stampit({
31
+ export default stampit({
33
32
  deepConf: { AsyncInit: { initializers: [] } },
34
33
  composers ({ stamp, composables }) {
35
34
  const conf = stamp.compose.deepConfiguration.AsyncInit
36
- conf.initializers = R.without([asyncInit], R.uniqWith(R.identical, R.flatten(composables.map(c => R.path(['compose', 'deepConfiguration', 'AsyncInit', 'initializers'], c) || (c.compose || c).initializers || []))))
35
+ conf.initializers = composables
36
+ .map(c =>
37
+ c?.compose?.deepConfiguration?.AsyncInit?.initializers ||
38
+ (c.compose || c).initializers ||
39
+ [])
40
+ .flat(Infinity)
41
+ .filter((f, idx, arr) => !arr.slice(0, idx).includes(f))
42
+ .filter(f => f !== asyncInit)
37
43
  stamp.compose.initializers = [asyncInit]
38
44
  }
39
45
  })
40
-
41
- export default AsyncInit
@@ -1,25 +1,18 @@
1
1
  /**
2
2
  * Big Number Helpers
3
3
  * @module @aeternity/aepp-sdk/es/utils/bignumber
4
- * @example import { parseBigNumber, isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
4
+ * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
5
5
  */
6
6
  import BigNumber from 'bignumber.js'
7
7
 
8
- /**
9
- * Convert number to string
10
- * @param {String|Number|BigNumber} number number to convert
11
- * @return {String}
12
- */
13
- export const parseBigNumber = (number: string | number | BigNumber): string =>
14
- new BigNumber(number.toString()).toString(10)
15
-
16
8
  /**
17
9
  * Check if value is BigNumber, Number or number string representation
18
10
  * @param {String|Number|BigNumber} number number to convert
19
11
  * @return {Boolean}
20
12
  */
21
13
  export const isBigNumber = (number: string | number | BigNumber): boolean =>
22
- !isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number)
14
+ ['number', 'object', 'string', 'bigint'].includes(typeof number) &&
15
+ (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))
23
16
 
24
17
  /**
25
18
  * BigNumber ceil operation
@@ -15,6 +15,7 @@
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
17
  import BigNumber from 'bignumber.js'
18
+ import { NoSerializerFoundError, TypeError } from './errors'
18
19
  import { isBase64, isHex } from './string'
19
20
 
20
21
  /**
@@ -29,7 +30,7 @@ import { isBase64, isHex } from './string'
29
30
  * @return Buffer
30
31
  */
31
32
  export function bigNumberToByteArray (x: BigNumber): Buffer {
32
- if (!x.isInteger()) throw new Error(`Unexpected not integer value: ${x.toFixed()}`)
33
+ if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)
33
34
  let hexString = x.toString(16)
34
35
  if (hexString.length % 2 === 1) hexString = '0' + hexString
35
36
  return Buffer.from(hexString, 'hex')
@@ -54,7 +55,7 @@ export function toBytes (val?: null | string | number | BigNumber, big: boolean
54
55
  if (typeof val === 'string') {
55
56
  return Buffer.from(val)
56
57
  }
57
- throw new Error('Byte serialization not supported')
58
+ throw new NoSerializerFoundError()
58
59
  }
59
60
 
60
61
  /**
@@ -15,7 +15,7 @@
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
17
 
18
- import { blake2b } from 'blakejs'
18
+ import { blake2b } from '@aeternity/blakejs'
19
19
  import type { Data } from 'blakejs'
20
20
 
21
21
  /**
@@ -25,5 +25,5 @@ import type { Data } from 'blakejs'
25
25
  * @return {Buffer} Hash
26
26
  */
27
27
  export function hash (input: Data): Buffer {
28
- return Buffer.from(blake2b(input, null, 32)) // 256 bits
28
+ return Buffer.from(blake2b(input, undefined, 32)) // 256 bits
29
29
  }