@aeternity/aepp-sdk 10.0.0 → 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 (238) 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 -27
  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.js → base.mjs} +20 -10
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/{memory.js → memory.mjs} +29 -14
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/{multiple.js → multiple.mjs} +10 -9
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +18 -22
  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.js → index.mjs} +8 -7
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +33 -16
  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} +20 -4
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +121 -73
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/{handlers.js → handlers.mjs} +18 -20
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +7 -7
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +49 -32
  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.js → index.mjs} +36 -28
  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.js → index.mjs} +11 -10
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/{node.js → node.mjs} +9 -8
  55. package/es/node.mjs.map +1 -0
  56. package/es/tx/builder/field-types.mjs +74 -0
  57. package/es/tx/builder/field-types.mjs.map +1 -0
  58. package/es/tx/builder/{helpers.js → helpers.mjs} +114 -56
  59. package/es/tx/builder/helpers.mjs.map +1 -0
  60. package/es/tx/builder/{index.js → index.mjs} +79 -68
  61. package/es/tx/builder/index.mjs.map +1 -0
  62. package/es/tx/builder/{schema.js → schema.mjs} +11 -65
  63. package/es/tx/builder/schema.mjs.map +1 -0
  64. package/es/tx/{index.js → index.mjs} +5 -2
  65. package/es/tx/index.mjs.map +1 -0
  66. package/es/tx/{tx-object.js → tx-object.mjs} +22 -15
  67. package/es/tx/tx-object.mjs.map +1 -0
  68. package/es/tx/{tx.js → tx.mjs} +15 -14
  69. package/es/tx/tx.mjs.map +1 -0
  70. package/es/tx/{validator.js → validator.mjs} +72 -33
  71. package/es/tx/validator.mjs.map +1 -0
  72. package/es/typings/blakejs/index.d.mjs +2 -0
  73. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  74. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +7 -6
  75. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  76. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +10 -11
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  78. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +5 -2
  79. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  80. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +6 -5
  81. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  82. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  83. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  84. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +113 -67
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  86. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +14 -9
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  88. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +71 -63
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  90. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  92. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  94. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  95. package/es/utils/amount-formatter.mjs.map +1 -0
  96. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  97. package/es/utils/async-init.mjs.map +1 -0
  98. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  99. package/es/utils/bignumber.mjs.map +1 -0
  100. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  101. package/es/utils/bytes.mjs.map +1 -0
  102. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  103. package/es/utils/crypto-ts.mjs.map +1 -0
  104. package/es/utils/{crypto.js → crypto.mjs} +40 -105
  105. package/es/utils/crypto.mjs.map +1 -0
  106. package/es/utils/errors.mjs +689 -0
  107. package/es/utils/errors.mjs.map +1 -0
  108. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  109. package/es/utils/hd-wallet.mjs.map +1 -0
  110. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  111. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  112. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  113. package/es/utils/keystore.mjs.map +1 -0
  114. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  115. package/es/utils/mptree.mjs.map +1 -0
  116. package/es/utils/{other.js → other.mjs} +2 -2
  117. package/es/utils/other.mjs.map +1 -0
  118. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  119. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  120. package/es/utils/{string.js → string.mjs} +1 -1
  121. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  122. package/es/utils/{swagger.js → swagger.mjs} +46 -14
  123. package/es/utils/swagger.mjs.map +1 -0
  124. package/package.json +46 -55
  125. package/src/account/memory.js +13 -8
  126. package/src/account/multiple.js +12 -4
  127. package/src/ae/aens.js +12 -17
  128. package/src/ae/aepp.js +2 -2
  129. package/src/ae/contract.js +15 -152
  130. package/src/ae/index.js +2 -1
  131. package/src/ae/oracle.js +25 -10
  132. package/src/ae/universal.js +2 -2
  133. package/src/ae/wallet.js +2 -2
  134. package/src/chain/index.js +21 -2
  135. package/src/chain/node.js +80 -53
  136. package/src/channel/handlers.js +20 -17
  137. package/src/channel/internal.js +30 -24
  138. package/src/contract/{aci/index.js → aci.js} +152 -93
  139. package/src/contract/compiler.js +22 -117
  140. package/src/contract/ga/helpers.js +7 -5
  141. package/src/contract/ga/index.js +27 -24
  142. package/src/index.js +7 -8
  143. package/src/node-pool/index.js +9 -8
  144. package/src/node.js +5 -7
  145. package/src/tx/builder/field-types.js +61 -0
  146. package/src/tx/builder/helpers.js +113 -58
  147. package/src/tx/builder/index.js +39 -34
  148. package/src/tx/builder/schema.js +11 -25
  149. package/src/tx/tx-object.js +10 -9
  150. package/src/tx/tx.js +17 -8
  151. package/src/tx/validator.js +25 -5
  152. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +8 -3
  153. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +10 -6
  154. package/src/utils/aepp-wallet-communication/content-script-bridge.js +5 -4
  155. package/src/utils/aepp-wallet-communication/helpers.js +2 -12
  156. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +81 -55
  157. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +15 -6
  158. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +60 -49
  159. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  160. package/src/utils/aepp-wallet-communication/wallet-detector.js +3 -2
  161. package/src/utils/amount-formatter.ts +4 -3
  162. package/src/utils/async-init.js +10 -6
  163. package/src/utils/bignumber.ts +1 -9
  164. package/src/utils/bytes.ts +3 -2
  165. package/src/utils/crypto-ts.ts +2 -2
  166. package/src/utils/crypto.js +9 -92
  167. package/src/utils/errors.ts +683 -0
  168. package/src/utils/hd-wallet.js +11 -26
  169. package/src/utils/keystore.js +47 -51
  170. package/src/utils/mptree.ts +12 -6
  171. package/src/utils/swagger.js +67 -44
  172. package/CHANGELOG.md +0 -1603
  173. package/es/account/base.js.map +0 -1
  174. package/es/account/memory.js.map +0 -1
  175. package/es/account/multiple.js.map +0 -1
  176. package/es/ae/aens.js.map +0 -1
  177. package/es/ae/aepp.js.map +0 -1
  178. package/es/ae/contract.js +0 -312
  179. package/es/ae/contract.js.map +0 -1
  180. package/es/ae/index.js.map +0 -1
  181. package/es/ae/oracle.js.map +0 -1
  182. package/es/ae/universal.js.map +0 -1
  183. package/es/ae/wallet.js.map +0 -1
  184. package/es/chain/index.js.map +0 -1
  185. package/es/chain/node.js.map +0 -1
  186. package/es/channel/handlers.js.map +0 -1
  187. package/es/channel/index.js.map +0 -1
  188. package/es/channel/internal.js.map +0 -1
  189. package/es/contract/aci/helpers.js +0 -298
  190. package/es/contract/aci/helpers.js.map +0 -1
  191. package/es/contract/aci/index.js +0 -361
  192. package/es/contract/aci/index.js.map +0 -1
  193. package/es/contract/aci/transformation.js +0 -66
  194. package/es/contract/aci/transformation.js.map +0 -1
  195. package/es/contract/compiler.js +0 -244
  196. package/es/contract/compiler.js.map +0 -1
  197. package/es/contract/ga/helpers.js +0 -22
  198. package/es/contract/ga/helpers.js.map +0 -1
  199. package/es/contract/ga/index.js.map +0 -1
  200. package/es/contract/index.js +0 -162
  201. package/es/contract/index.js.map +0 -1
  202. package/es/index.js +0 -57
  203. package/es/index.js.map +0 -1
  204. package/es/node-pool/index.js.map +0 -1
  205. package/es/node.js.map +0 -1
  206. package/es/tx/builder/helpers.js.map +0 -1
  207. package/es/tx/builder/index.js.map +0 -1
  208. package/es/tx/builder/schema.js.map +0 -1
  209. package/es/tx/index.js.map +0 -1
  210. package/es/tx/tx-object.js.map +0 -1
  211. package/es/tx/tx.js.map +0 -1
  212. package/es/tx/validator.js.map +0 -1
  213. package/es/typings/blakejs/index.d.js +0 -2
  214. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  215. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  216. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  217. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  218. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  219. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  220. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  221. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  222. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  223. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  224. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  225. package/es/utils/amount-formatter.js.map +0 -1
  226. package/es/utils/async-init.js.map +0 -1
  227. package/es/utils/bignumber.js.map +0 -1
  228. package/es/utils/bytes.js.map +0 -1
  229. package/es/utils/crypto-ts.js.map +0 -1
  230. package/es/utils/crypto.js.map +0 -1
  231. package/es/utils/hd-wallet.js.map +0 -1
  232. package/es/utils/keystore.js.map +0 -1
  233. package/es/utils/mptree.js.map +0 -1
  234. package/es/utils/other.js.map +0 -1
  235. package/es/utils/swagger.js.map +0 -1
  236. package/src/contract/aci/transformation.js +0 -72
  237. package/src/contract/index.js +0 -163
  238. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/node-pool/index.js"],"names":["stampit","getNetworkId","DisconnectedError","DuplicateNodeError","NodeNotFoundError","TypeError","init","nodes","pool","Map","validateNodes","forEach","node","i","name","instance","addNode","length","selectNode","propertyDescriptors","api","enumerable","configurable","get","selectedNode","methods","select","has","set","url","internalUrl","networkId","nodeNetworkId","version","consensusProtocolVersion","isNodeConnected","getNodeInfo","getNodesInPool","Array","from","entries","map","isArray","notObject","n","find","t","wrongFields","JSON","stringify","wrongInstanceFields","genesisHash","props"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;SACSC,Y;SACAC,iB,EAAmBC,kB,EAAoBC,iB,EAAmBC,S;AAEnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeL,OAAO,CAAC;AACrBM,EAAAA,IAAI,GAAuB;AAAA,QAArB;AAAEC,MAAAA,KAAK,GAAG;AAAV,KAAqB,uEAAJ,EAAI;AACzB,SAA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CAAC,CAACqB,wBAAT,KAAsC,QAHd,CAA5B;;AAIA,UAAIgB,mBAAJ,EAAyB;AACvB,cAAM,IAAI7C,SAAJ,CACJ,qFACC,oCAAmC2C,IAAI,CAACC,SAAL,CAAeC,mBAAf,CAAoC,UAFpE,CAAN;AAID;AACF;;AA3HM,GAvBY;AAoJrBE,EAAAA,KAAK,EAAE;AACL5B,IAAAA,YAAY,EAAE;AADT;AApJc,CAAD,CAAtB","sourcesContent":["/**\n * NodePool module\n * @module @aeternity/aepp-sdk/es/node-pool\n * @export NodePool\n * @example import { NodePool } from '@aeternity/aepp-sdk'\n */\nimport stampit from '@stamp/it'\nimport { getNetworkId } from '../node'\nimport { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from '../utils/errors'\n\n/**\n * Node Pool Stamp\n * This stamp allow you to make basic manipulation(add, remove, select) on list of nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Array} [options.nodes] - Array with Node instances\n * @return {Object} NodePool instance\n */\nexport default stampit({\n init ({ nodes = [] } = {}) {\n this.pool = new Map()\n this.validateNodes(nodes)\n\n nodes.forEach((node, i) => {\n const { name, instance } = node\n this.addNode(name, instance, i === 0)\n })\n if (nodes.length) this.selectNode(nodes[0].name)\n },\n propertyDescriptors: {\n api: {\n enumerable: true,\n configurable: false,\n get () {\n if (!this.selectedNode || !this.selectedNode.instance) {\n throw new NodeNotFoundError('You can\\'t use Node API. Node is not connected or not defined!')\n }\n return this.selectedNode.instance.api\n }\n }\n },\n methods: {\n /**\n * Add Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String, nodeInstance: Object, select: Boolean) => void\n * @param {String} name - Node name\n * @param {Object} node - Node instance\n * @param {Boolean} select - Select this node as current\n * @return {void}\n * @example\n * // add and select new node with name 'testNode'\n * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)\n */\n addNode (name, node, select = false) {\n if (this.pool.has(name)) throw new DuplicateNodeError(name)\n\n this.validateNodes([{ name, instance: node }])\n\n this.pool.set(name, {\n name,\n instance: node,\n url: node.url,\n internalUrl: node.internalUrl,\n networkId: node.nodeNetworkId,\n version: node.version,\n consensusProtocolVersion: node.consensusProtocolVersion\n })\n if (select || !this.selectedNode) {\n this.selectNode(name)\n }\n },\n /**\n * Select Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype (name: String) => void\n * @param {String} name - Node name\n * @return {void}\n * @example\n * nodePool.selectNode('testNode')\n */\n selectNode (name) {\n if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`)\n\n this.selectedNode = this.pool.get(name)\n },\n /**\n * Get NetworkId of current Node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => String\n * @return {String}\n * @example\n * nodePool.getNetworkId()\n */\n getNetworkId,\n /**\n * Check if you have selected node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Boolean\n * @return {Boolean}\n * @example\n * nodePool.isNodeConnected()\n */\n isNodeConnected () {\n return !!this.selectedNode.instance\n },\n /**\n * Get information about node\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object\n * @return {Object}\n * @example\n * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }\n */\n getNodeInfo () {\n if (!this.isNodeConnected()) throw new DisconnectedError()\n return {\n name: this.selectedNode.name,\n ...this.selectedNode.instance.getNodeInfo()\n }\n },\n /**\n * Get array of available nodes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node-pool\n * @rtype () => Object[]\n * @return {Object[]}\n * @example\n * nodePool.getNodesInPool()\n */\n getNodesInPool () {\n return Array.from(this.pool.entries()).map(([name, node]) => ({\n name,\n ...node.instance.getNodeInfo()\n }))\n },\n validateNodes (nodes) {\n // TODO: validate it on TypeScript level instead\n // (to speedup development, save runtime resources)\n if (!Array.isArray(nodes)) throw new TypeError('\"nodes\" should be an array')\n const notObject = nodes.map(n => typeof n).find(t => t !== 'object')\n if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`)\n const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')\n if (notObject) {\n throw new TypeError(\n 'Each node should have name (string), instance (object) ' +\n `fields, got ${JSON.stringify(wrongFields)} instead`\n )\n }\n const wrongInstanceFields = nodes\n .map(n => n.instance)\n .find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||\n typeof i.consensusProtocolVersion !== 'number')\n if (wrongInstanceFields) {\n throw new TypeError(\n 'Each node instance should have api (object), consensusProtocolVersion (number), ' +\n `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`\n )\n }\n }\n },\n props: {\n selectedNode: {}\n }\n})\n"],"file":"index.mjs"}
@@ -21,9 +21,10 @@
21
21
  * @export Node
22
22
  * @example import { Node } from '@aeternity/aepp-sdk'
23
23
  */
24
- import AsyncInit from './utils/async-init';
25
- import genSwaggerClient from './utils/swagger';
26
- import semverSatisfies from './utils/semver-satisfies';
24
+ import AsyncInit from "./utils/async-init.mjs";
25
+ import genSwaggerClient from "./utils/swagger.mjs";
26
+ import semverSatisfies from "./utils/semver-satisfies.mjs";
27
+ import { MissingParamError, UnsupportedVersionError } from "./utils/errors.mjs";
27
28
  /**
28
29
  * Obtain networkId from account or node
29
30
  * @instance
@@ -40,7 +41,7 @@ export function getNetworkId() {
40
41
  force = false
41
42
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
42
43
  const res = networkId || this.networkId || ((_this$selectedNode = this.selectedNode) === null || _this$selectedNode === void 0 ? void 0 : _this$selectedNode.networkId);
43
- if (!force && !res) throw new Error('networkId is not provided');
44
+ if (!force && !res) throw new MissingParamError('networkId is not provided');
44
45
  if (force && !res) return null;
45
46
  return res;
46
47
  }
@@ -66,9 +67,9 @@ const Node = AsyncInit.compose({
66
67
  internalUrl,
67
68
  ignoreVersion
68
69
  } = _ref;
69
- if (!url) throw new Error('"url" required');
70
+ if (!url) throw new MissingParamError('"url" required');
70
71
  this.url = url.replace(/\/$/, '');
71
- this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url;
72
+ this.internalUrl = internalUrl === null || internalUrl === void 0 ? void 0 : internalUrl.replace(/\/$/, '');
72
73
  const client = await genSwaggerClient(`${this.url}/api?oas3`, {
73
74
  internalUrl: this.internalUrl,
74
75
  responseInterceptor: response => {
@@ -81,7 +82,7 @@ const Node = AsyncInit.compose({
81
82
  this.version = client.spec.info.version;
82
83
 
83
84
  if (!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion) {
84
- throw new Error(`Unsupported node version ${this.version}. ` + `Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`);
85
+ throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION);
85
86
  }
86
87
 
87
88
  this.api = client.api;
@@ -129,4 +130,4 @@ const Node = AsyncInit.compose({
129
130
  const NODE_GE_VERSION = '6.2.0';
130
131
  const NODE_LT_VERSION = '7.0.0';
131
132
  export default Node;
132
- //# sourceMappingURL=node.js.map
133
+ //# sourceMappingURL=node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/node.js"],"names":["AsyncInit","genSwaggerClient","semverSatisfies","MissingParamError","UnsupportedVersionError","getNetworkId","networkId","force","res","selectedNode","Node","compose","init","url","internalUrl","ignoreVersion","replace","client","responseInterceptor","response","ok","Object","assign","statusText","URL","pathname","slice","body","reason","version","spec","info","NODE_GE_VERSION","NODE_LT_VERSION","api","nodeRevision","revision","genesisKeyBlockHash","genesisHash","protocols","topBlockHeight","getStatus","consensusProtocolVersion","filter","effectiveAtHeight","reduce","acc","p","nodeNetworkId","methods","getNodeInfo","props"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;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AAF;AAAYE,MAAAA;AAAZ,KAApB,CAAP;AACD,GApC4B;;AAqC7BW,EAAAA,OAAO,EAAE;AACPC,IAAAA,WAAW,GAAI;AACb,aAAO;AACLrC,QAAAA,GAAG,EAAE,KAAKA,GADL;AAELC,QAAAA,WAAW,EAAE,KAAKA,WAFb;AAGLkC,QAAAA,aAAa,EAAE,KAAKA,aAHf;AAILnB,QAAAA,OAAO,EAAE,KAAKA,OAJT;AAKLa,QAAAA,wBAAwB,EAAE,KAAKA;AAL1B,OAAP;AAOD;;AATM,GArCoB;AAgD7BS,EAAAA,KAAK,EAAE;AACLtB,IAAAA,OAAO,EAAE,IADJ;AAELa,IAAAA,wBAAwB,EAAE,IAFrB;AAGLM,IAAAA,aAAa,EAAE;AAHV;AAhDsB,CAAlB,CAAb;AAuDA,MAAMhB,eAAe,GAAG,OAAxB;AACA,MAAMC,eAAe,GAAG,OAAxB;AAEA,eAAevB,IAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Node module\n * @module @aeternity/aepp-sdk/es/node\n * @export Node\n * @example import { Node } from '@aeternity/aepp-sdk'\n */\n\nimport AsyncInit from './utils/async-init'\nimport genSwaggerClient from './utils/swagger'\nimport semverSatisfies from './utils/semver-satisfies'\nimport { MissingParamError, UnsupportedVersionError } from './utils/errors'\n\n/**\n * Obtain networkId from account or node\n * @instance\n * @category async\n * @rtype () => networkId: String\n * @return {String} NetworkId\n */\nexport function getNetworkId ({ networkId, force = false } = {}) {\n const res = networkId || this.networkId || this.selectedNode?.networkId\n if (!force && !res) throw new MissingParamError('networkId is not provided')\n if (force && !res) return null\n return res\n}\n\n/**\n * {@link genSwaggerClient} based Node remote API Stamp\n * @function\n * @alias module:@aeternity/aepp-sdk/es/node\n * @rtype Stamp\n * @param {Object} [options={}] - Options\n * @param {String} options.url - Base URL for Node\n * @param {String} options.internalUrl - Base URL for internal requests\n * @param {Object} options.axiosConfig - Object with axios configuration\n * @param {Object} options.axiosConfig.config\n * @param {Function} options.axiosConfig.errorHandler - (err) => throw err\n * @return {Object} Node client\n * @example Node({url: 'https://testnet.aeternity.io'})\n */\nconst Node = AsyncInit.compose({\n async init ({ url, internalUrl, ignoreVersion }) {\n if (!url) throw new MissingParamError('\"url\" required')\n this.url = url.replace(/\\/$/, '')\n this.internalUrl = internalUrl?.replace(/\\/$/, '')\n const client = await genSwaggerClient(`${this.url}/api?oas3`, {\n internalUrl: this.internalUrl,\n responseInterceptor: response => {\n if (response.ok) return\n return Object.assign(response, {\n statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason\n })\n }\n })\n this.version = client.spec.info.version\n if (\n !semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&\n !ignoreVersion\n ) {\n throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION)\n }\n this.api = client.api\n\n const {\n nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId,\n protocols, topBlockHeight\n } = await this.api.getStatus()\n this.consensusProtocolVersion = protocols\n .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)\n .reduce(\n (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,\n { effectiveAtHeight: -1, version: 0 }\n )\n .version\n this.nodeNetworkId = networkId\n return Object.assign(this, { revision, genesisHash })\n },\n methods: {\n getNodeInfo () {\n return {\n url: this.url,\n internalUrl: this.internalUrl,\n nodeNetworkId: this.nodeNetworkId,\n version: this.version,\n consensusProtocolVersion: this.consensusProtocolVersion\n }\n }\n },\n props: {\n version: null,\n consensusProtocolVersion: null,\n nodeNetworkId: null\n }\n})\n\nconst NODE_GE_VERSION = '6.2.0'\nconst NODE_LT_VERSION = '7.0.0'\n\nexport default Node\n"],"file":"node.mjs"}
@@ -0,0 +1,74 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+ import { writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt } from "./helpers.mjs";
6
+ import { InsufficientNameFeeError, IllegalArgumentError } from "../../utils/errors.mjs";
7
+ export class Field {
8
+ static serialize(value) {
9
+ return value;
10
+ }
11
+
12
+ static deserialize(value) {
13
+ return value;
14
+ }
15
+
16
+ }
17
+ export class Name extends Field {
18
+ static serialize(value) {
19
+ ensureNameValid(value);
20
+ return _Buffer.from(value);
21
+ }
22
+
23
+ static deserialize(value) {
24
+ return value.toString();
25
+ }
26
+
27
+ }
28
+ export class NameId extends Field {
29
+ static serialize(value) {
30
+ return writeId(isNameValid(value) ? produceNameId(value) : value);
31
+ }
32
+
33
+ static deserialize(value) {
34
+ return readId(value);
35
+ }
36
+
37
+ }
38
+ export class NameFee extends Field {
39
+ static serialize(value, _ref) {
40
+ var _value;
41
+
42
+ let {
43
+ name
44
+ } = _ref;
45
+ const minNameFee = getMinimumNameFee(name);
46
+ (_value = value) !== null && _value !== void 0 ? _value : value = minNameFee;
47
+
48
+ if (minNameFee.gt(value)) {
49
+ throw new InsufficientNameFeeError(value, minNameFee);
50
+ }
51
+
52
+ return writeInt(value);
53
+ }
54
+
55
+ static deserialize(value) {
56
+ return readInt(value);
57
+ }
58
+
59
+ }
60
+ export class Deposit extends Field {
61
+ static serialize(value, _ref2) {
62
+ let {
63
+ name
64
+ } = _ref2;
65
+ if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`);
66
+ return writeInt(0);
67
+ }
68
+
69
+ static deserialize(value) {
70
+ return readInt(value);
71
+ }
72
+
73
+ }
74
+ //# sourceMappingURL=field-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/tx/builder/field-types.js"],"names":["writeId","readId","isNameValid","produceNameId","ensureNameValid","getMinimumNameFee","readInt","writeInt","InsufficientNameFeeError","IllegalArgumentError","Field","serialize","value","deserialize","Name","from","toString","NameId","NameFee","name","minNameFee","gt","Deposit"],"mappings":";;;;SACEA,O,EAASC,M,EAAQC,W,EAAaC,a,EAAeC,e,EAAiBC,iB,EAAmBC,O,EAASC,Q;SAEnFC,wB,EAA0BC,oB;AAEnC,OAAO,MAAMC,KAAN,CAAY;AACD,SAATC,SAAS,CAAEC,KAAF,EAAS;AACvB,WAAOA,KAAP;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAOA,KAAP;AACD;;AAPgB;AAUnB,OAAO,MAAME,IAAN,SAAmBJ,KAAnB,CAAyB;AACd,SAATC,SAAS,CAAEC,KAAF,EAAS;AACvBR,IAAAA,eAAe,CAACQ,KAAD,CAAf;AACA,WAAO,QAAOG,IAAP,CAAYH,KAAZ,CAAP;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAOA,KAAK,CAACI,QAAN,EAAP;AACD;;AAR6B;AAWhC,OAAO,MAAMC,MAAN,SAAqBP,KAArB,CAA2B;AAChB,SAATC,SAAS,CAAEC,KAAF,EAAS;AACvB,WAAOZ,OAAO,CAACE,WAAW,CAACU,KAAD,CAAX,GAAqBT,aAAa,CAACS,KAAD,CAAlC,GAA4CA,KAA7C,CAAd;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAOX,MAAM,CAACW,KAAD,CAAb;AACD;;AAP+B;AAUlC,OAAO,MAAMM,OAAN,SAAsBR,KAAtB,CAA4B;AACjB,SAATC,SAAS,CAAEC,KAAF,QAAmB;AAAA;;AAAA,QAAV;AAAEO,MAAAA;AAAF,KAAU;AACjC,UAAMC,UAAU,GAAGf,iBAAiB,CAACc,IAAD,CAApC;AACA,cAAAP,KAAK,UAAL,iCAAAA,KAAK,GAAKQ,UAAV;;AACA,QAAIA,UAAU,CAACC,EAAX,CAAcT,KAAd,CAAJ,EAA0B;AACxB,YAAM,IAAIJ,wBAAJ,CAA6BI,KAA7B,EAAoCQ,UAApC,CAAN;AACD;;AACD,WAAOb,QAAQ,CAACK,KAAD,CAAf;AACD;;AAEiB,SAAXC,WAAW,CAAED,KAAF,EAAS;AACzB,WAAON,OAAO,CAACM,KAAD,CAAd;AACD;;AAZgC;AAenC,OAAO,MAAMU,OAAN,SAAsBZ,KAAtB,CAA4B;AACjB,SAATC,SAAS,CAAEC,KAAF,SAAmB;AAAA,QAAV;AAAEO,MAAAA;AAAF,KAAU;AACjC,QAAI,CAACP,KAAL,EAAY,MAAM,IAAIH,oBAAJ,CAA0B,oEAAmEG,KAAM,UAAnG,CAAN;AACZ,WAAOL,QAAQ,CAAC,CAAD,CAAf;AACD;;AAEiB,SAAXM,WAAW,CAAED,KAAF,EAAS;AACzB,WAAON,OAAO,CAACM,KAAD,CAAd;AACD;;AARgC","sourcesContent":["import {\n writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt\n} from './helpers'\nimport { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'\n\nexport class Field {\n static serialize (value) {\n return value\n }\n\n static deserialize (value) {\n return value\n }\n}\n\nexport class Name extends Field {\n static serialize (value) {\n ensureNameValid(value)\n return Buffer.from(value)\n }\n\n static deserialize (value) {\n return value.toString()\n }\n}\n\nexport class NameId extends Field {\n static serialize (value) {\n return writeId(isNameValid(value) ? produceNameId(value) : value)\n }\n\n static deserialize (value) {\n return readId(value)\n }\n}\n\nexport class NameFee extends Field {\n static serialize (value, { name }) {\n const minNameFee = getMinimumNameFee(name)\n value ??= minNameFee\n if (minNameFee.gt(value)) {\n throw new InsufficientNameFeeError(value, minNameFee)\n }\n return writeInt(value)\n }\n\n static deserialize (value) {\n return readInt(value)\n }\n}\n\nexport class Deposit extends Field {\n static serialize (value, { name }) {\n if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`)\n return writeInt(0)\n }\n\n static deserialize (value) {\n return readInt(value)\n }\n}\n"],"file":"field-types.mjs"}
@@ -1,13 +1,14 @@
1
- import _T from "ramda/src/T";
2
- import _lte from "ramda/src/lte";
3
- import _always from "ramda/src/always";
4
- import _lt from "ramda/src/lt";
5
- import _cond from "ramda/src/cond";
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
6
5
  import BigNumber from 'bignumber.js';
7
- import { decodeBase58Check, decodeBase64Check, encodeBase58Check, encodeBase64Check, hash, salt } from '../../utils/crypto';
8
- import { toBytes } from '../../utils/bytes';
9
- import { ID_TAG_PREFIX, PREFIX_ID_TAG, NAME_BID_RANGES, NAME_BID_MAX_LENGTH, NAME_FEE, NAME_FEE_BID_INCREMENT, NAME_BID_TIMEOUTS, NAME_MAX_LENGTH_FEE, POINTER_KEY_BY_PREFIX } from './schema';
10
- import { ceil } from '../../utils/bignumber';
6
+ import bs58 from 'bs58';
7
+ import { hash, salt, sha256hash } from "../../utils/crypto.mjs";
8
+ import { toBytes } from "../../utils/bytes.mjs";
9
+ import { ID_TAG_PREFIX, PREFIX_ID_TAG, NAME_BID_RANGES, NAME_FEE_BID_INCREMENT, NAME_BID_TIMEOUTS, NAME_MAX_LENGTH_FEE, POINTER_KEY_BY_PREFIX } from "./schema.mjs";
10
+ import { ceil } from "../../utils/bignumber.mjs";
11
+ import { PrefixMismatchError, DecodeError, EncodeError, PayloadLengthError, TagNotFoundError, PrefixNotFoundError, InvalidNameError, IllegalBidFeeError, NoDefaultAensPointerError, ArgumentError, InvalidChecksumError } from "../../utils/errors.mjs";
11
12
  /**
12
13
  * JavaScript-based Transaction builder helper function's
13
14
  * @module @aeternity/aepp-sdk/es/tx/builder/helpers
@@ -16,7 +17,6 @@ import { ceil } from '../../utils/bignumber';
16
17
  */
17
18
 
18
19
  export const createSalt = salt;
19
- const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba'];
20
20
  /**
21
21
  * Build a contract public key
22
22
  * @function
@@ -27,7 +27,8 @@ const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba'];
27
27
  */
28
28
 
29
29
  export function buildContractId(ownerId, nonce) {
30
- const ownerIdAndNonce = Buffer.from([...decode(ownerId, 'ak'), ...toBytes(nonce)]);
30
+ const ownerIdAndNonce = _Buffer.from([...decode(ownerId, 'ak'), ...toBytes(nonce)]);
31
+
31
32
  const b2bHash = hash(ownerIdAndNonce);
32
33
  return encode(b2bHash, 'ct');
33
34
  }
@@ -44,10 +45,10 @@ export function buildContractId(ownerId, nonce) {
44
45
  export function oracleQueryId(senderId, nonce, oracleId) {
45
46
  function _int32(val) {
46
47
  const nonceBE = toBytes(val, true);
47
- return Buffer.concat([Buffer.alloc(32 - nonceBE.length), nonceBE]);
48
+ return _Buffer.concat([_Buffer.alloc(32 - nonceBE.length), nonceBE]);
48
49
  }
49
50
 
50
- const b2bHash = hash(Buffer.from([...decode(senderId, 'ak'), ..._int32(nonce), ...decode(oracleId, 'ok')]));
51
+ const b2bHash = hash(_Buffer.from([...decode(senderId, 'ak'), ..._int32(nonce), ...decode(oracleId, 'ok')]));
51
52
  return encode(b2bHash, 'oq');
52
53
  }
53
54
  /**
@@ -59,14 +60,14 @@ export function oracleQueryId(senderId, nonce, oracleId) {
59
60
  */
60
61
 
61
62
  export function formatSalt(salt) {
62
- return Buffer.from(salt.toString(16).padStart(64, '0'), 'hex');
63
+ return _Buffer.from(salt.toString(16).padStart(64, '0'), 'hex');
63
64
  }
64
65
  /**
65
- * Encode a domain name
66
+ * Encode an AENS name
66
67
  * @function
67
68
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
68
69
  * @param {String} name Name to encode
69
- * @return {String} `nm_` prefixed encoded domain name
70
+ * @return {String} `nm_` prefixed encoded AENS name
70
71
  */
71
72
 
72
73
  export function produceNameId(name) {
@@ -89,8 +90,46 @@ export function produceNameId(name) {
89
90
  export function commitmentHash(name) {
90
91
  let salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createSalt();
91
92
  ensureNameValid(name);
92
- return `cm_${encodeBase58Check(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])))}`;
93
+ return encode(hash(_Buffer.concat([_Buffer.from(name.toLowerCase()), formatSalt(salt)])), 'cm');
94
+ } // based on https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md
95
+
96
+ const base64Types = ['ba', 'cb', 'or', 'ov', 'pi', 'ss', 'cs', 'ck', 'cv', 'st', 'tx'];
97
+ const base58Types = ['ak', 'bf', 'bs', 'bx', 'ch', 'cm', 'ct', 'kh', 'mh', 'nm', 'ok', 'oq', 'pp', 'sg', 'th']; // TODO: add all types with a fixed length
98
+
99
+ const typesLength = {
100
+ ak: 32,
101
+ ct: 32,
102
+ ok: 32
103
+ };
104
+
105
+ function ensureValidLength(data, type) {
106
+ if (!typesLength[type]) return;
107
+ if (data.length === typesLength[type]) return;
108
+ throw new PayloadLengthError(`Payload should be ${typesLength[type]} bytes, got ${data.length} instead`);
93
109
  }
110
+
111
+ const getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4);
112
+
113
+ const addChecksum = input => {
114
+ const payload = _Buffer.from(input);
115
+
116
+ return _Buffer.concat([payload, getChecksum(payload)]);
117
+ };
118
+
119
+ function getPayload(buffer) {
120
+ const payload = buffer.slice(0, -4);
121
+ if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError();
122
+ return payload;
123
+ }
124
+
125
+ const base64 = {
126
+ encode: buffer => addChecksum(buffer).toString('base64'),
127
+ decode: string => getPayload(_Buffer.from(string, 'base64'))
128
+ };
129
+ const base58 = {
130
+ encode: buffer => bs58.encode(addChecksum(buffer)),
131
+ decode: string => getPayload(bs58.decode(string))
132
+ };
94
133
  /**
95
134
  * Decode data using the default encoding/decoding algorithm
96
135
  * @function
@@ -101,15 +140,24 @@ export function commitmentHash(name) {
101
140
  */
102
141
 
103
142
  export function decode(data, requiredPrefix) {
104
- const [prefix, payload, extra] = data.split('_');
105
- if (!payload) throw new Error(`Encoded string missing payload: ${data}`);
106
- if (extra) throw new Error(`Encoded string have extra parts: ${data}`);
143
+ if (typeof data !== 'string') throw new DecodeError(`Encoded should be a string, got ${data} instead`);
144
+ const [prefix, encodedPayload, extra] = data.split('_');
145
+ if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`);
146
+ if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`);
107
147
 
108
148
  if (requiredPrefix && requiredPrefix !== prefix) {
109
- throw new Error(`Encoded string have a wrong type: ${prefix} (expected: ${requiredPrefix})`);
149
+ throw new PrefixMismatchError(prefix, requiredPrefix);
150
+ }
151
+
152
+ const decoder = base64Types.includes(prefix) && base64.decode || base58Types.includes(prefix) && base58.decode;
153
+
154
+ if (!decoder) {
155
+ throw new DecodeError(`Encoded string have unknown type: ${prefix}`);
110
156
  }
111
157
 
112
- return (base64Types.includes(prefix) ? decodeBase64Check : decodeBase58Check)(payload);
158
+ const payload = decoder(encodedPayload);
159
+ ensureValidLength(payload, prefix);
160
+ return payload;
113
161
  }
114
162
  /**
115
163
  * Encode data using the default encoding/decoding algorithm
@@ -121,7 +169,14 @@ export function decode(data, requiredPrefix) {
121
169
  */
122
170
 
123
171
  export function encode(data, type) {
124
- return `${type}_${base64Types.includes(type) ? encodeBase64Check(data) : encodeBase58Check(data)}`;
172
+ const encoder = base64Types.includes(type) && base64.encode || base58Types.includes(type) && base58.encode;
173
+
174
+ if (!encoder) {
175
+ throw new EncodeError(`Unknown type: ${type}`);
176
+ }
177
+
178
+ ensureValidLength(data, type);
179
+ return `${type}_${encoder(data)}`;
125
180
  }
126
181
  /**
127
182
  * Utility function to create and _id type
@@ -132,14 +187,11 @@ export function encode(data, type) {
132
187
  */
133
188
 
134
189
  export function writeId(hashId) {
135
- if (typeof hashId !== 'string') {
136
- throw new Error(`Address should be a string, got ${hashId} instead`);
137
- }
138
-
190
+ if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId);
139
191
  const prefix = hashId.slice(0, 2);
140
192
  const idTag = PREFIX_ID_TAG[prefix];
141
- if (!idTag) throw new Error(`Id tag for prefix ${prefix} not found.`);
142
- return Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)]);
193
+ if (!idTag) throw new TagNotFoundError(prefix);
194
+ return _Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)]);
143
195
  }
144
196
  /**
145
197
  * Utility function to read and _id type
@@ -150,9 +202,10 @@ export function writeId(hashId) {
150
202
  */
151
203
 
152
204
  export function readId(buf) {
153
- const tag = buf.readUIntBE(0, 1);
205
+ const tag = _Buffer.from(buf).readUIntBE(0, 1);
206
+
154
207
  const prefix = ID_TAG_PREFIX[tag];
155
- if (!prefix) throw new Error(`Prefix for id-tag ${tag} not found.`);
208
+ if (!prefix) throw new PrefixNotFoundError(tag);
156
209
  return encode(buf.slice(1, buf.length), prefix);
157
210
  }
158
211
  /**
@@ -175,8 +228,8 @@ export function writeInt(val) {
175
228
  */
176
229
 
177
230
  export function readInt() {
178
- let buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Buffer.from([]);
179
- return BigNumber(buf.toString('hex'), 16).toString(10);
231
+ let buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _Buffer.from([]);
232
+ return new BigNumber(_Buffer.from(buf).toString('hex'), 16).toString(10);
180
233
  }
181
234
  /**
182
235
  * Helper function to build pointers for name update TX
@@ -208,8 +261,9 @@ export function readPointers(pointers) {
208
261
  });
209
262
  });
210
263
  }
264
+ const AENS_SUFFIX = '.chain';
211
265
  /**
212
- * Ensure that name is valid
266
+ * Ensure that AENS name is valid
213
267
  * @function
214
268
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
215
269
  * @param {string} name
@@ -218,11 +272,11 @@ export function readPointers(pointers) {
218
272
  */
219
273
 
220
274
  export function ensureNameValid(name) {
221
- if (!name || typeof name !== 'string') throw new Error('Name must be a string');
222
- if (!name.endsWith('.chain')) throw new Error(`Name should end with .chain: ${name}`);
275
+ if (!name || typeof name !== 'string') throw new InvalidNameError('Name must be a string');
276
+ if (!name.endsWith(AENS_SUFFIX)) throw new InvalidNameError(`Name should end with ${AENS_SUFFIX}: ${name}`);
223
277
  }
224
278
  /**
225
- * Is name valid
279
+ * Is AENS name valid
226
280
  * @function
227
281
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
228
282
  * @param {string} name
@@ -247,59 +301,63 @@ export function getDefaultPointerKey(identifier) {
247
301
  decode(identifier);
248
302
  const prefix = identifier.substr(0, 2);
249
303
  return POINTER_KEY_BY_PREFIX[prefix] || (() => {
250
- throw new Error(`Default AENS pointer key is not defined for ${prefix} prefix`);
304
+ throw new NoDefaultAensPointerError(prefix);
251
305
  })();
252
306
  }
253
307
  /**
254
- * Get the minimum name fee for a domain
308
+ * Get the minimum AENS name fee
255
309
  * @function
256
310
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
257
- * @param {String} domain the domain name to get the fee for
258
- * @return {String} the minimum fee for the domain auction
311
+ * @param {String} name the AENS name to get the fee for
312
+ * @return {String} the minimum fee for the AENS name auction
259
313
  */
260
314
 
261
- export function getMinimumNameFee(domain) {
262
- const nameLength = domain.replace('.chain', '').length;
263
- return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength];
315
+ export function getMinimumNameFee(name) {
316
+ ensureNameValid(name);
317
+ const nameLength = name.length - AENS_SUFFIX.length;
318
+ return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];
264
319
  }
265
320
  /**
266
321
  * Compute bid fee for AENS auction
267
322
  * @function
268
323
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
269
- * @param {String} domain the domain name to get the fee for
324
+ * @param {String} name the AENS name to get the fee for
270
325
  * @param {Number|String} startFee Auction start fee
271
326
  * @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)
272
327
  * @return {String} Bid fee
273
328
  */
274
329
 
275
- export function computeBidFee(domain) {
276
- let startFee = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NAME_FEE;
330
+ export function computeBidFee(name, startFee) {
277
331
  let increment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NAME_FEE_BID_INCREMENT;
278
- if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(`Increment must be float. Current increment ${increment}`);
279
- if (increment < NAME_FEE_BID_INCREMENT) throw new Error(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);
280
- return ceil(BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1)));
332
+ if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);
333
+ if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);
334
+ return ceil(BigNumber(startFee !== null && startFee !== void 0 ? startFee : getMinimumNameFee(name)).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1)));
281
335
  }
282
336
  /**
283
337
  * Compute auction end height
284
338
  * @function
285
339
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
286
- * @param {String} domain the domain name to get the fee for
340
+ * @param {String} name
287
341
  * @param {Number|String} claimHeight Auction starting height
288
342
  * @return {String} Auction end height
289
343
  */
290
344
 
291
- export function computeAuctionEndBlock(domain, claimHeight) {
292
- return _cond([[_lt(5), _always(NAME_BID_TIMEOUTS[4].plus(claimHeight))], [_lt(9), _always(NAME_BID_TIMEOUTS[8].plus(claimHeight))], [_lte(NAME_BID_MAX_LENGTH), _always(NAME_BID_TIMEOUTS[12].plus(claimHeight))], [_T, _always(BigNumber(claimHeight))]])(domain.replace('.chain', '').length).toString(10);
345
+ export function computeAuctionEndBlock(name, claimHeight) {
346
+ ensureNameValid(name);
347
+ const length = name.length - AENS_SUFFIX.length;
348
+ const h = length <= 4 && NAME_BID_TIMEOUTS[4] || length <= 8 && NAME_BID_TIMEOUTS[8] || length <= 12 && NAME_BID_TIMEOUTS[12] || NAME_BID_TIMEOUTS[13];
349
+ return h.plus(claimHeight).toString(10);
293
350
  }
294
351
  /**
295
352
  * Is name accept going to auction
296
353
  * @function
297
354
  * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
298
- * @param {String} name Transaction abiVersion
355
+ * @param {String} name
299
356
  * @return {Boolean}
300
357
  */
301
358
 
302
359
  export function isAuctionName(name) {
303
- return name.replace('.chain', '').length < 13;
360
+ ensureNameValid(name);
361
+ return name.length < 13 + AENS_SUFFIX.length;
304
362
  }
305
- //# sourceMappingURL=helpers.js.map
363
+ //# sourceMappingURL=helpers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/tx/builder/helpers.js"],"names":["BigNumber","bs58","hash","salt","sha256hash","toBytes","ID_TAG_PREFIX","PREFIX_ID_TAG","NAME_BID_RANGES","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUTS","NAME_MAX_LENGTH_FEE","POINTER_KEY_BY_PREFIX","ceil","PrefixMismatchError","DecodeError","EncodeError","PayloadLengthError","TagNotFoundError","PrefixNotFoundError","InvalidNameError","IllegalBidFeeError","NoDefaultAensPointerError","ArgumentError","InvalidChecksumError","createSalt","buildContractId","ownerId","nonce","ownerIdAndNonce","from","decode","b2bHash","encode","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","concat","alloc","length","formatSalt","toString","padStart","produceNameId","name","ensureNameValid","toLowerCase","commitmentHash","base64Types","base58Types","typesLength","ak","ct","ok","ensureValidLength","data","type","getChecksum","payload","slice","addChecksum","input","getPayload","buffer","equals","base64","string","base58","requiredPrefix","prefix","encodedPayload","extra","split","decoder","includes","encoder","writeId","hashId","idTag","readId","buf","tag","readUIntBE","writeInt","readInt","buildPointers","pointers","map","p","key","id","readPointers","Object","assign","AENS_SUFFIX","endsWith","isNameValid","error","getDefaultPointerKey","identifier","substr","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","h","isAuctionName"],"mappings":";;;;AAAA,OAAOA,SAAP,MAAsB,cAAtB;AACA,OAAOC,IAAP,MAAiB,MAAjB;SACSC,I,EAAMC,I,EAAMC,U;SACZC,O;SAEPC,a,EACAC,a,EACAC,e,EACAC,sB,EACAC,iB,EACAC,mB,EACAC,qB;SAEOC,I;SAEPC,mB,EACAC,W,EACAC,W,EACAC,kB,EACAC,gB,EACAC,mB,EACAC,gB,EACAC,kB,EACAC,yB,EACAC,a,EACAC,oB;AAGF;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMC,UAAU,GAAGtB,IAAnB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASuB,eAAT,CAA0BC,OAA1B,EAAmCC,KAAnC,EAA0C;AAC/C,QAAMC,eAAe,GAAG,QAAOC,IAAP,CAAY,CAAC,GAAGC,MAAM,CAACJ,OAAD,EAAU,IAAV,CAAV,EAA2B,GAAGtB,OAAO,CAACuB,KAAD,CAArC,CAAZ,CAAxB;;AACA,QAAMI,OAAO,GAAG9B,IAAI,CAAC2B,eAAD,CAApB;AACA,SAAOI,MAAM,CAACD,OAAD,EAAU,IAAV,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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AaL,iBAAiB,CAACzD,IAAD,CAA9B,CAAT,CAA+CiE,KAA/C,CAAqDhH,SAAS,CAACS,sBAAD,CAAT,CAAkCwG,IAAlC,CAAuC,CAAvC,CAArD,CADS,CAAX;AAGD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,sBAAT,CAAiCnE,IAAjC,EAAuCoE,WAAvC,EAAoD;AACzDnE,EAAAA,eAAe,CAACD,IAAD,CAAf;AACA,QAAML,MAAM,GAAGK,IAAI,CAACL,MAAL,GAAcuD,WAAW,CAACvD,MAAzC;AACA,QAAM0E,CAAC,GAAI1E,MAAM,IAAI,CAAV,IAAehC,iBAAiB,CAAC,CAAD,CAAjC,IACPgC,MAAM,IAAI,CAAV,IAAehC,iBAAiB,CAAC,CAAD,CADzB,IAEPgC,MAAM,IAAI,EAAV,IAAgBhC,iBAAiB,CAAC,EAAD,CAF1B,IAGRA,iBAAiB,CAAC,EAAD,CAHnB;AAIA,SAAO0G,CAAC,CAACH,IAAF,CAAOE,WAAP,EAAoBvE,QAApB,CAA6B,EAA7B,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASyE,aAAT,CAAwBtE,IAAxB,EAA8B;AACnCC,EAAAA,eAAe,CAACD,IAAD,CAAf;AACA,SAAOA,IAAI,CAACL,MAAL,GAAc,KAAKuD,WAAW,CAACvD,MAAtC;AACD","sourcesContent":["import BigNumber from 'bignumber.js'\nimport bs58 from 'bs58'\nimport { hash, salt, sha256hash } from '../../utils/crypto'\nimport { toBytes } from '../../utils/bytes'\nimport {\n ID_TAG_PREFIX,\n PREFIX_ID_TAG,\n NAME_BID_RANGES,\n NAME_FEE_BID_INCREMENT,\n NAME_BID_TIMEOUTS,\n NAME_MAX_LENGTH_FEE,\n POINTER_KEY_BY_PREFIX\n} from './schema'\nimport { ceil } from '../../utils/bignumber'\nimport {\n PrefixMismatchError,\n DecodeError,\n EncodeError,\n PayloadLengthError,\n TagNotFoundError,\n PrefixNotFoundError,\n InvalidNameError,\n IllegalBidFeeError,\n NoDefaultAensPointerError,\n ArgumentError,\n InvalidChecksumError\n} from '../../utils/errors'\n\n/**\n * JavaScript-based Transaction builder helper function's\n * @module @aeternity/aepp-sdk/es/tx/builder/helpers\n * @export TxBuilderHelper\n * @example import { TxBuilderHelper } from '@aeternity/aepp-sdk'\n */\n\nexport const createSalt = salt\n\n/**\n * Build a contract public key\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} ownerId The public key of the owner account\n * @param {number} nonce the nonce of the transaction\n * @return {string} Contract public key\n */\nexport function buildContractId (ownerId, nonce) {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId, 'ak'), ...toBytes(nonce)])\n const b2bHash = hash(ownerIdAndNonce)\n return encode(b2bHash, 'ct')\n}\n\n/**\n * Build a oracle query id\n * @function\n * @function* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} senderId The public key of the sender account\n * @param {Number} nonce the nonce of the transaction\n * @param {Number} oracleId The oracle public key\n * @return {string} Contract public key\n */\nexport function oracleQueryId (senderId, nonce, oracleId) {\n function _int32 (val) {\n const nonceBE = toBytes(val, true)\n return Buffer.concat([Buffer.alloc(32 - nonceBE.length), nonceBE])\n }\n\n const b2bHash = hash(Buffer.from([...decode(senderId, 'ak'), ..._int32(nonce), ...decode(oracleId, 'ok')]))\n return encode(b2bHash, 'oq')\n}\n\n/**\n * Format the salt into a 64-byte hex string\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {number} salt\n * @return {string} Zero-padded hex string of salt\n */\nexport function formatSalt (salt) {\n return Buffer.from(salt.toString(16).padStart(64, '0'), 'hex')\n}\n\n/**\n * Encode an AENS name\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name Name to encode\n * @return {String} `nm_` prefixed encoded AENS name\n */\nexport function produceNameId (name) {\n ensureNameValid(name)\n return encode(hash(name.toLowerCase()), 'nm')\n}\n\n/**\n * Generate the commitment hash by hashing the formatted salt and\n * name, base 58 encoding the result and prepending 'cm_'\n *\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @function commitmentHash\n * @category async\n * @rtype (name: String, salt?: String) => hash: Promise[String]\n * @param {String} name - Name to be registered\n * @param {Number} salt Random salt\n * @return {String} Commitment hash\n */\nexport function commitmentHash (name, salt = createSalt()) {\n ensureNameValid(name)\n return encode(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])), 'cm')\n}\n\n// based on https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md\nconst base64Types = ['ba', 'cb', 'or', 'ov', 'pi', 'ss', 'cs', 'ck', 'cv', 'st', 'tx']\nconst base58Types = ['ak', 'bf', 'bs', 'bx', 'ch', 'cm', 'ct', 'kh', 'mh', 'nm', 'ok', 'oq', 'pp', 'sg', 'th']\n// TODO: add all types with a fixed length\nconst typesLength = {\n ak: 32,\n ct: 32,\n ok: 32\n}\n\nfunction ensureValidLength (data, type) {\n if (!typesLength[type]) return\n if (data.length === typesLength[type]) return\n throw new PayloadLengthError(`Payload should be ${typesLength[type]} bytes, got ${data.length} instead`)\n}\n\nconst getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4)\n\nconst addChecksum = (input) => {\n const payload = Buffer.from(input)\n return Buffer.concat([payload, getChecksum(payload)])\n}\n\nfunction getPayload (buffer) {\n const payload = buffer.slice(0, -4)\n if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError()\n return payload\n}\n\nconst base64 = {\n encode: buffer => addChecksum(buffer).toString('base64'),\n decode: string => getPayload(Buffer.from(string, 'base64'))\n}\n\nconst base58 = {\n encode: buffer => bs58.encode(addChecksum(buffer)),\n decode: string => getPayload(bs58.decode(string))\n}\n\n/**\n * Decode data using the default encoding/decoding algorithm\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)\n * @param {string} [requiredPrefix] Ensure that data have this prefix\n * @return {Buffer} Decoded data\n */\nexport function decode (data, requiredPrefix) {\n if (typeof data !== 'string') throw new DecodeError(`Encoded should be a string, got ${data} instead`)\n const [prefix, encodedPayload, extra] = data.split('_')\n if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`)\n if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`)\n if (requiredPrefix && requiredPrefix !== prefix) {\n throw new PrefixMismatchError(prefix, requiredPrefix)\n }\n const decoder = (base64Types.includes(prefix) && base64.decode) ||\n (base58Types.includes(prefix) && base58.decode)\n if (!decoder) {\n throw new DecodeError(`Encoded string have unknown type: ${prefix}`)\n }\n const payload = decoder(encodedPayload)\n ensureValidLength(payload, prefix)\n return payload\n}\n\n/**\n * Encode data using the default encoding/decoding algorithm\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer|String} data An decoded data\n * @param {string} type Prefix of Transaction\n * @return {String} Encoded string Base58check or Base64check data\n */\nexport function encode (data, type) {\n const encoder = (base64Types.includes(type) && base64.encode) ||\n (base58Types.includes(type) && base58.encode)\n if (!encoder) {\n throw new EncodeError(`Unknown type: ${type}`)\n }\n ensureValidLength(data, type)\n return `${type}_${encoder(data)}`\n}\n\n/**\n * Utility function to create and _id type\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} hashId Encoded hash\n * @return {Buffer} Buffer Buffer with ID tag and decoded HASh\n */\nexport function writeId (hashId) {\n if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId)\n const prefix = hashId.slice(0, 2)\n const idTag = PREFIX_ID_TAG[prefix]\n if (!idTag) throw new TagNotFoundError(prefix)\n return Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)])\n}\n\n/**\n * Utility function to read and _id type\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer} buf Data\n * @return {String} Encoided hash string with prefix\n */\nexport function readId (buf) {\n const tag = Buffer.from(buf).readUIntBE(0, 1)\n const prefix = ID_TAG_PREFIX[tag]\n if (!prefix) throw new PrefixNotFoundError(tag)\n return encode(buf.slice(1, buf.length), prefix)\n}\n\n/**\n * Utility function to convert int to bytes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Number|String|BigNumber} val Value\n * @return {Buffer} Buffer Buffer from number(BigEndian)\n */\nexport function writeInt (val) {\n return toBytes(val, true)\n}\n\n/**\n * Utility function to convert bytes to int\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer} buf Value\n * @return {String} Buffer Buffer from number(BigEndian)\n */\nexport function readInt (buf = Buffer.from([])) {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10)\n}\n\n/**\n * Helper function to build pointers for name update TX\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Array} pointers - Array of pointers\n * ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])\n * @return {Array} Serialized pointers array\n */\nexport function buildPointers (pointers) {\n return pointers.map(\n p => [\n toBytes(p.key),\n writeId(p.id)\n ]\n )\n}\n\n/**\n * Helper function to read pointers from name update TX\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Array} pointers - Array of pointers\n * ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])\n * @return {Array} Deserialize pointer array\n */\nexport function readPointers (pointers) {\n return pointers.map(\n ([key, id]) => Object.assign({\n key: key.toString(),\n id: readId(id)\n })\n )\n}\n\nconst AENS_SUFFIX = '.chain'\n\n/**\n * Ensure that AENS name is valid\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} name\n * @return void\n * @throws Error\n */\nexport function ensureNameValid (name) {\n if (!name || typeof name !== 'string') throw new InvalidNameError('Name must be a string')\n if (!name.endsWith(AENS_SUFFIX)) throw new InvalidNameError(`Name should end with ${AENS_SUFFIX}: ${name}`)\n}\n\n/**\n * Is AENS name valid\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} name\n * @return Boolean\n */\nexport function isNameValid (name) {\n try {\n ensureNameValid(name)\n return true\n } catch (error) {\n return false\n }\n}\n\n/**\n * @param identifier - account/oracle/contract address, or channel\n * @returns {String} default AENS pointer key\n * @throws exception when default key not defined\n */\nexport function getDefaultPointerKey (identifier) {\n decode(identifier)\n const prefix = identifier.substr(0, 2)\n return POINTER_KEY_BY_PREFIX[prefix] ||\n (() => { throw new NoDefaultAensPointerError(prefix) })()\n}\n\n/**\n * Get the minimum AENS name fee\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name the AENS name to get the fee for\n * @return {String} the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee (name) {\n ensureNameValid(name)\n const nameLength = name.length - AENS_SUFFIX.length\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)]\n}\n\n/**\n * Compute bid fee for AENS auction\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name the AENS name to get the fee for\n * @param {Number|String} startFee Auction start fee\n * @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)\n * @return {String} Bid fee\n */\nexport function computeBidFee (name, startFee, increment = NAME_FEE_BID_INCREMENT) {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`)\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)\n return ceil(\n BigNumber(startFee ?? getMinimumNameFee(name)).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))\n )\n}\n\n/**\n * Compute auction end height\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name\n * @param {Number|String} claimHeight Auction starting height\n * @return {String} Auction end height\n */\nexport function computeAuctionEndBlock (name, claimHeight) {\n ensureNameValid(name)\n const length = name.length - AENS_SUFFIX.length\n const h = (length <= 4 && NAME_BID_TIMEOUTS[4]) ||\n (length <= 8 && NAME_BID_TIMEOUTS[8]) ||\n (length <= 12 && NAME_BID_TIMEOUTS[12]) ||\n NAME_BID_TIMEOUTS[13]\n return h.plus(claimHeight).toString(10)\n}\n\n/**\n * Is name accept going to auction\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name\n * @return {Boolean}\n */\nexport function isAuctionName (name) {\n ensureNameValid(name)\n return name.length < 13 + AENS_SUFFIX.length\n}\n"],"file":"helpers.mjs"}