@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) 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} +23 -11
  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} +14 -11
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +69 -59
  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} +12 -10
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +37 -20
  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} +28 -8
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +133 -90
  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} +43 -22
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +51 -35
  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} +40 -28
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/encoder.d.ts +26 -0
  50. package/es/errors.d.ts +284 -0
  51. package/es/index.mjs +57 -0
  52. package/es/index.mjs.map +1 -0
  53. package/es/node-pool/{index.js → index.mjs} +15 -12
  54. package/es/node-pool/index.mjs.map +1 -0
  55. package/es/{node.js → node.mjs} +17 -11
  56. package/es/node.mjs.map +1 -0
  57. package/es/tx/builder/constants.mjs +108 -0
  58. package/es/tx/builder/constants.mjs.map +1 -0
  59. package/es/tx/builder/field-types.mjs +74 -0
  60. package/es/tx/builder/field-types.mjs.map +1 -0
  61. package/es/tx/builder/helpers.mjs +321 -0
  62. package/es/tx/builder/helpers.mjs.map +1 -0
  63. package/es/tx/builder/{index.js → index.mjs} +92 -74
  64. package/es/tx/builder/index.mjs.map +1 -0
  65. package/es/tx/builder/{schema.js → schema.mjs} +16 -172
  66. package/es/tx/builder/schema.mjs.map +1 -0
  67. package/es/tx/{index.js → index.mjs} +106 -14
  68. package/es/tx/index.mjs.map +1 -0
  69. package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
  70. package/es/tx/tx-object.mjs.map +1 -0
  71. package/es/tx/{tx.js → tx.mjs} +15 -14
  72. package/es/tx/tx.mjs.map +1 -0
  73. package/es/tx/{validator.js → validator.mjs} +72 -33
  74. package/es/tx/validator.mjs.map +1 -0
  75. package/es/typings/blakejs/index.d.mjs +2 -0
  76. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  77. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
  78. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
  80. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  82. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
  84. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  86. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
  88. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
  90. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
  92. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  94. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  95. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  96. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  97. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  98. package/es/utils/amount-formatter.mjs.map +1 -0
  99. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  100. package/es/utils/async-init.mjs.map +1 -0
  101. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  102. package/es/utils/bignumber.mjs.map +1 -0
  103. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  104. package/es/utils/bytes.mjs.map +1 -0
  105. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  106. package/es/utils/crypto-ts.mjs.map +1 -0
  107. package/es/utils/{crypto.js → crypto.mjs} +42 -156
  108. package/es/utils/crypto.mjs.map +1 -0
  109. package/es/utils/encoder.mjs +106 -0
  110. package/es/utils/encoder.mjs.map +1 -0
  111. package/es/utils/errors.mjs +689 -0
  112. package/es/utils/errors.mjs.map +1 -0
  113. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  114. package/es/utils/hd-wallet.mjs.map +1 -0
  115. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  116. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  117. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  118. package/es/utils/keystore.mjs.map +1 -0
  119. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  120. package/es/utils/mptree.mjs.map +1 -0
  121. package/es/utils/{other.js → other.mjs} +2 -2
  122. package/es/utils/other.mjs.map +1 -0
  123. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  124. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  125. package/es/utils/{string.js → string.mjs} +1 -1
  126. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  127. package/es/utils/{swagger.js → swagger.mjs} +49 -15
  128. package/es/utils/swagger.mjs.map +1 -0
  129. package/package.json +49 -58
  130. package/src/account/base.js +3 -1
  131. package/src/account/memory.js +13 -8
  132. package/src/account/multiple.js +16 -6
  133. package/src/ae/aens.js +52 -58
  134. package/src/ae/aepp.js +2 -2
  135. package/src/ae/contract.js +21 -154
  136. package/src/ae/index.js +6 -4
  137. package/src/ae/oracle.js +33 -14
  138. package/src/ae/universal.js +4 -2
  139. package/src/ae/wallet.js +2 -2
  140. package/src/chain/index.js +29 -6
  141. package/src/chain/node.js +95 -65
  142. package/src/channel/handlers.js +30 -20
  143. package/src/channel/index.js +46 -16
  144. package/src/channel/internal.js +35 -30
  145. package/src/contract/aci.js +376 -0
  146. package/src/contract/compiler.js +22 -113
  147. package/src/contract/ga/helpers.js +10 -6
  148. package/src/contract/ga/index.js +31 -24
  149. package/src/index.js +9 -8
  150. package/src/node-pool/index.js +13 -10
  151. package/src/node.js +11 -10
  152. package/src/tx/builder/constants.js +100 -0
  153. package/src/tx/builder/field-types.js +61 -0
  154. package/src/tx/builder/helpers.js +99 -103
  155. package/src/tx/builder/index.js +81 -40
  156. package/src/tx/builder/schema.js +44 -132
  157. package/src/tx/index.js +101 -12
  158. package/src/tx/tx-object.js +35 -15
  159. package/src/tx/tx.js +110 -35
  160. package/src/tx/validator.js +25 -5
  161. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  162. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  163. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  164. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  165. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  166. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
  167. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  168. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
  169. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  170. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  171. package/src/utils/amount-formatter.ts +4 -3
  172. package/src/utils/async-init.js +10 -6
  173. package/src/utils/bignumber.ts +1 -9
  174. package/src/utils/bytes.ts +3 -2
  175. package/src/utils/crypto-ts.ts +2 -2
  176. package/src/utils/crypto.js +11 -155
  177. package/src/utils/encoder.ts +101 -0
  178. package/src/utils/errors.ts +683 -0
  179. package/src/utils/hd-wallet.js +11 -26
  180. package/src/utils/keystore.js +57 -53
  181. package/src/utils/mptree.ts +12 -6
  182. package/src/utils/swagger.js +68 -45
  183. package/es/account/base.js.map +0 -1
  184. package/es/account/memory.js.map +0 -1
  185. package/es/account/multiple.js.map +0 -1
  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 -308
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js.map +0 -1
  191. package/es/ae/oracle.js.map +0 -1
  192. package/es/ae/universal.js.map +0 -1
  193. package/es/ae/wallet.js.map +0 -1
  194. package/es/chain/index.js.map +0 -1
  195. package/es/chain/node.js.map +0 -1
  196. package/es/channel/handlers.js.map +0 -1
  197. package/es/channel/index.js.map +0 -1
  198. package/es/channel/internal.js.map +0 -1
  199. package/es/contract/aci/helpers.js +0 -298
  200. package/es/contract/aci/helpers.js.map +0 -1
  201. package/es/contract/aci/index.js +0 -356
  202. package/es/contract/aci/index.js.map +0 -1
  203. package/es/contract/aci/transformation.js +0 -66
  204. package/es/contract/aci/transformation.js.map +0 -1
  205. package/es/contract/compiler.js +0 -242
  206. package/es/contract/compiler.js.map +0 -1
  207. package/es/contract/ga/helpers.js +0 -22
  208. package/es/contract/ga/helpers.js.map +0 -1
  209. package/es/contract/ga/index.js.map +0 -1
  210. package/es/contract/index.js +0 -158
  211. package/es/contract/index.js.map +0 -1
  212. package/es/index.js +0 -56
  213. package/es/index.js.map +0 -1
  214. package/es/node-pool/index.js.map +0 -1
  215. package/es/node.js.map +0 -1
  216. package/es/tx/builder/helpers.js +0 -318
  217. package/es/tx/builder/helpers.js.map +0 -1
  218. package/es/tx/builder/index.js.map +0 -1
  219. package/es/tx/builder/schema.js.map +0 -1
  220. package/es/tx/index.js.map +0 -1
  221. package/es/tx/tx-object.js.map +0 -1
  222. package/es/tx/tx.js.map +0 -1
  223. package/es/tx/validator.js.map +0 -1
  224. package/es/typings/blakejs/index.d.js +0 -2
  225. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  226. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  227. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  228. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  229. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  230. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  231. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  232. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  233. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  234. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  235. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  236. package/es/utils/amount-formatter.js.map +0 -1
  237. package/es/utils/async-init.js.map +0 -1
  238. package/es/utils/bignumber.js.map +0 -1
  239. package/es/utils/bytes.js.map +0 -1
  240. package/es/utils/crypto-ts.js.map +0 -1
  241. package/es/utils/crypto.js.map +0 -1
  242. package/es/utils/hd-wallet.js.map +0 -1
  243. package/es/utils/keystore.js.map +0 -1
  244. package/es/utils/mptree.js.map +0 -1
  245. package/es/utils/other.js.map +0 -1
  246. package/es/utils/swagger.js.map +0 -1
  247. package/src/contract/aci/index.js +0 -310
  248. package/src/contract/aci/transformation.js +0 -72
  249. package/src/contract/index.js +0 -159
  250. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -5,7 +5,8 @@
5
5
  * @example import { NodePool } from '@aeternity/aepp-sdk'
6
6
  */
7
7
  import stampit from '@stamp/it';
8
- import { getNetworkId } from '../node';
8
+ import { getNetworkId } from "../node.mjs";
9
+ import { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from "../utils/errors.mjs";
9
10
  /**
10
11
  * Node Pool Stamp
11
12
  * This stamp allow you to make basic manipulation(add, remove, select) on list of nodes
@@ -41,7 +42,7 @@ export default stampit({
41
42
 
42
43
  get() {
43
44
  if (!this.selectedNode || !this.selectedNode.instance) {
44
- throw new Error('You can\'t use Node API. Node is not connected or not defined!');
45
+ throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!');
45
46
  }
46
47
 
47
48
  return this.selectedNode.instance.api;
@@ -60,11 +61,12 @@ export default stampit({
60
61
  * @param {Boolean} select - Select this node as current
61
62
  * @return {void}
62
63
  * @example
63
- * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true) // add and select new node with name 'testNode'
64
+ * // add and select new node with name 'testNode'
65
+ * nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
64
66
  */
65
67
  addNode(name, node) {
66
68
  let select = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
67
- if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`);
69
+ if (this.pool.has(name)) throw new DuplicateNodeError(name);
68
70
  this.validateNodes([{
69
71
  name,
70
72
  instance: node
@@ -95,7 +97,7 @@ export default stampit({
95
97
  * nodePool.selectNode('testNode')
96
98
  */
97
99
  selectNode(name) {
98
- if (!this.pool.has(name)) throw new Error(`Node with name ${name} not in pool`);
100
+ if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`);
99
101
  this.selectedNode = this.pool.get(name);
100
102
  },
101
103
 
@@ -133,7 +135,7 @@ export default stampit({
133
135
  * nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
134
136
  */
135
137
  getNodeInfo() {
136
- if (!this.isNodeConnected()) throw new Error('Can not get node info. Node is not connected');
138
+ if (!this.isNodeConnected()) throw new DisconnectedError();
137
139
  return {
138
140
  name: this.selectedNode.name,
139
141
  ...this.selectedNode.instance.getNodeInfo()
@@ -160,20 +162,21 @@ export default stampit({
160
162
  },
161
163
 
162
164
  validateNodes(nodes) {
163
- // TODO: validate it on TypeScript level instead (to speedup development, save runtime resources)
164
- if (!Array.isArray(nodes)) throw new Error('"nodes" should be an array');
165
+ // TODO: validate it on TypeScript level instead
166
+ // (to speedup development, save runtime resources)
167
+ if (!Array.isArray(nodes)) throw new TypeError('"nodes" should be an array');
165
168
  const notObject = nodes.map(n => typeof n).find(t => t !== 'object');
166
- if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`);
169
+ if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`);
167
170
  const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object');
168
171
 
169
172
  if (notObject) {
170
- throw new Error('Each node should have name (string), instance (object) ' + `fields, got ${JSON.stringify(wrongFields)} instead`);
173
+ throw new TypeError('Each node should have name (string), instance (object) ' + `fields, got ${JSON.stringify(wrongFields)} instead`);
171
174
  }
172
175
 
173
176
  const wrongInstanceFields = nodes.map(n => n.instance).find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' || typeof i.consensusProtocolVersion !== 'number');
174
177
 
175
178
  if (wrongInstanceFields) {
176
- throw new Error('Each node instance should have api (object), consensusProtocolVersion (number), ' + `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`);
179
+ throw new TypeError('Each node instance should have api (object), consensusProtocolVersion (number), ' + `genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`);
177
180
  }
178
181
  }
179
182
 
@@ -182,4 +185,4 @@ export default stampit({
182
185
  selectedNode: {}
183
186
  }
184
187
  });
185
- //# sourceMappingURL=index.js.map
188
+ //# sourceMappingURL=index.mjs.map
@@ -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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,CAAeF,WAAf,CAA4B,UAFvC,CAAN;AAID;;AACD,YAAMG,mBAAmB,GAAG3C,KAAK,CAC9BkC,GADyB,CACrBG,CAAC,IAAIA,CAAC,CAAC7B,QADc,EAEzB8B,IAFyB,CAEpBhC,CAAC,IAAI,OAAOA,CAAC,CAACO,GAAT,KAAiB,QAAjB,IAA6B,OAAOP,CAAC,CAACsC,WAAT,KAAyB,QAAtD,IACT,OAAOtC,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
@@ -33,13 +34,16 @@ import semverSatisfies from './utils/semver-satisfies';
33
34
  */
34
35
 
35
36
  export function getNetworkId() {
37
+ var _this$selectedNode;
38
+
36
39
  let {
37
40
  networkId,
38
41
  force = false
39
42
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
40
- if (!force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) throw new Error('networkId is not provided');
41
- if (force && !networkId && !this.networkId && (!this.selectedNode || !this.selectedNode.networkId)) return null;
42
- return networkId || this.networkId || this.selectedNode.networkId;
43
+ const res = networkId || this.networkId || ((_this$selectedNode = this.selectedNode) === null || _this$selectedNode === void 0 ? void 0 : _this$selectedNode.networkId);
44
+ if (!force && !res) throw new MissingParamError('networkId is not provided');
45
+ if (force && !res) return null;
46
+ return res;
43
47
  }
44
48
  /**
45
49
  * {@link genSwaggerClient} based Node remote API Stamp
@@ -49,7 +53,9 @@ export function getNetworkId() {
49
53
  * @param {Object} [options={}] - Options
50
54
  * @param {String} options.url - Base URL for Node
51
55
  * @param {String} options.internalUrl - Base URL for internal requests
52
- * @param {String} options.axiosConfig - Object with axios configuration. Example { config: {}, errorHandler: (err) => throw err }
56
+ * @param {Object} options.axiosConfig - Object with axios configuration
57
+ * @param {Object} options.axiosConfig.config
58
+ * @param {Function} options.axiosConfig.errorHandler - (err) => throw err
53
59
  * @return {Object} Node client
54
60
  * @example Node({url: 'https://testnet.aeternity.io'})
55
61
  */
@@ -61,9 +67,9 @@ const Node = AsyncInit.compose({
61
67
  internalUrl,
62
68
  ignoreVersion
63
69
  } = _ref;
64
- if (!url) throw new Error('"url" required');
70
+ if (!url) throw new MissingParamError('"url" required');
65
71
  this.url = url.replace(/\/$/, '');
66
- this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url;
72
+ this.internalUrl = internalUrl === null || internalUrl === void 0 ? void 0 : internalUrl.replace(/\/$/, '');
67
73
  const client = await genSwaggerClient(`${this.url}/api?oas3`, {
68
74
  internalUrl: this.internalUrl,
69
75
  responseInterceptor: response => {
@@ -76,7 +82,7 @@ const Node = AsyncInit.compose({
76
82
  this.version = client.spec.info.version;
77
83
 
78
84
  if (!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) && !ignoreVersion) {
79
- 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);
80
86
  }
81
87
 
82
88
  this.api = client.api;
@@ -124,4 +130,4 @@ const Node = AsyncInit.compose({
124
130
  const NODE_GE_VERSION = '6.2.0';
125
131
  const NODE_LT_VERSION = '7.0.0';
126
132
  export default Node;
127
- //# 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;OAEOA,S;OACAC,gB;OACAC,e;SACEC,iB,EAAmBC,uB;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,GAA0D;AAAA;;AAAA,MAAnC;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,KAAK,GAAG;AAArB,GAAmC,uEAAJ,EAAI;AAC/D,QAAMC,GAAG,GAAGF,SAAS,IAAI,KAAKA,SAAlB,2BAA+B,KAAKG,YAApC,uDAA+B,mBAAmBH,SAAlD,CAAZ;AACA,MAAI,CAACC,KAAD,IAAU,CAAC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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,108 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { mapObject } from "../../utils/other.mjs"; // # AENS
3
+
4
+ export const NAME_TTL = 180000; // # max number of block into the future that the name is going to be available
5
+ // # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update
6
+ // # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry
7
+
8
+ export const NAME_MAX_TTL = 36000;
9
+ export const NAME_MAX_CLIENT_TTL = 84600;
10
+ export const CLIENT_TTL = NAME_MAX_CLIENT_TTL; // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67
11
+
12
+ export const NAME_FEE_MULTIPLIER = 1e14; // 100000000000000
13
+
14
+ export const NAME_FEE_BID_INCREMENT = 0.05; // # the increment is in percentage
15
+ // # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272
16
+
17
+ export const NAME_BID_TIMEOUT_BLOCKS = 480; // # ~1 day
18
+ // # this is the max length for a domain that requires a base fee to be paid
19
+
20
+ export const NAME_MAX_LENGTH_FEE = 31;
21
+ export const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid
22
+
23
+ export const POINTER_KEY_BY_PREFIX = {
24
+ ak: 'account_pubkey',
25
+ ok: 'oracle_pubkey',
26
+ ct: 'contract_pubkey',
27
+ ch: 'channel'
28
+ }; // # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290
29
+ // # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times
30
+ // # bid ranges:
31
+
32
+ export const NAME_BID_RANGES = mapObject({
33
+ 31: 3,
34
+ 30: 5,
35
+ 29: 8,
36
+ 28: 13,
37
+ 27: 21,
38
+ 26: 34,
39
+ 25: 55,
40
+ 24: 89,
41
+ 23: 144,
42
+ 22: 233,
43
+ 21: 377,
44
+ 20: 610,
45
+ 19: 987,
46
+ 18: 1597,
47
+ 17: 2584,
48
+ 16: 4181,
49
+ 15: 6765,
50
+ 14: 10946,
51
+ 13: 17711,
52
+ 12: 28657,
53
+ 11: 46368,
54
+ 10: 75025,
55
+ 9: 121393,
56
+ 8: 196418,
57
+ 7: 317811,
58
+ 6: 514229,
59
+ 5: 832040,
60
+ 4: 1346269,
61
+ 3: 2178309,
62
+ 2: 3524578,
63
+ 1: 5702887
64
+ }, _ref => {
65
+ let [key, value] = _ref;
66
+ return [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)];
67
+ }); // # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273
68
+ // # name bid timeouts
69
+
70
+ export const NAME_BID_TIMEOUTS = {
71
+ 13: BigNumber(0),
72
+ 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS),
73
+ // # 480 blocks
74
+ 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS),
75
+ // # 14880 blocks
76
+ 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks
77
+
78
+ }; // # Tag constant for ids (type uint8)
79
+ // # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type
80
+ // # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>
81
+
82
+ const ID_TAG_ACCOUNT = 1;
83
+ const ID_TAG_NAME = 2;
84
+ const ID_TAG_COMMITMENT = 3;
85
+ const ID_TAG_ORACLE = 4;
86
+ const ID_TAG_CONTRACT = 5;
87
+ const ID_TAG_CHANNEL = 6;
88
+ export const ID_TAG = {
89
+ account: ID_TAG_ACCOUNT,
90
+ name: ID_TAG_NAME,
91
+ commitment: ID_TAG_COMMITMENT,
92
+ oracle: ID_TAG_ORACLE,
93
+ contract: ID_TAG_CONTRACT,
94
+ channel: ID_TAG_CHANNEL
95
+ };
96
+ export const PREFIX_ID_TAG = {
97
+ ak: ID_TAG.account,
98
+ nm: ID_TAG.name,
99
+ cm: ID_TAG.commitment,
100
+ ok: ID_TAG.oracle,
101
+ ct: ID_TAG.contract,
102
+ ch: ID_TAG.channel
103
+ };
104
+ export const ID_TAG_PREFIX = mapObject(PREFIX_ID_TAG, _ref2 => {
105
+ let [key, value] = _ref2;
106
+ return [value, key];
107
+ });
108
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/tx/builder/constants.js"],"names":["BigNumber","mapObject","NAME_TTL","NAME_MAX_TTL","NAME_MAX_CLIENT_TTL","CLIENT_TTL","NAME_FEE_MULTIPLIER","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUT_BLOCKS","NAME_MAX_LENGTH_FEE","NAME_BID_MAX_LENGTH","POINTER_KEY_BY_PREFIX","ak","ok","ct","ch","NAME_BID_RANGES","key","value","times","NAME_BID_TIMEOUTS","ID_TAG_ACCOUNT","ID_TAG_NAME","ID_TAG_COMMITMENT","ID_TAG_ORACLE","ID_TAG_CONTRACT","ID_TAG_CHANNEL","ID_TAG","account","name","commitment","oracle","contract","channel","PREFIX_ID_TAG","nm","cm","ID_TAG_PREFIX"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,S,iCAET;;AACA,OAAO,MAAMC,QAAQ,GAAG,MAAjB,C,CACP;AACA;AACA;;AACA,OAAO,MAAMC,YAAY,GAAG,KAArB;AACP,OAAO,MAAMC,mBAAmB,GAAG,KAA5B;AACP,OAAO,MAAMC,UAAU,GAAGD,mBAAnB,C,CACP;;AACA,OAAO,MAAME,mBAAmB,GAAG,IAA5B,C,CAAiC;;AACxC,OAAO,MAAMC,sBAAsB,GAAG,IAA/B,C,CAAoC;AAC3C;;AACA,OAAO,MAAMC,uBAAuB,GAAG,GAAhC,C,CAAoC;AAC3C;;AACA,OAAO,MA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js'\nimport { mapObject } from '../../utils/other'\n\n// # AENS\nexport const NAME_TTL = 180000\n// # max number of block into the future that the name is going to be available\n// # https://github.com/aeternity/protocol/blob/epoch-v0.22.0/AENS.md#update\n// # https://github.com/aeternity/protocol/blob/44a93d3aab957ca820183c3520b9daf6b0fedff4/AENS.md#aens-entry\nexport const NAME_MAX_TTL = 36000\nexport const NAME_MAX_CLIENT_TTL = 84600\nexport const CLIENT_TTL = NAME_MAX_CLIENT_TTL\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L67\nexport const NAME_FEE_MULTIPLIER = 1e14 // 100000000000000\nexport const NAME_FEE_BID_INCREMENT = 0.05 // # the increment is in percentage\n// # see https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L272\nexport const NAME_BID_TIMEOUT_BLOCKS = 480 // # ~1 day\n// # this is the max length for a domain that requires a base fee to be paid\nexport const NAME_MAX_LENGTH_FEE = 31\nexport const NAME_BID_MAX_LENGTH = 12 // # this is the max length for a domain to be part of a bid\nexport const POINTER_KEY_BY_PREFIX = {\n ak: 'account_pubkey',\n ok: 'oracle_pubkey',\n ct: 'contract_pubkey',\n ch: 'channel'\n}\n// # https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L290\n// # https://github.com/aeternity/protocol/blob/master/AENS.md#protocol-fees-and-protection-times\n// # bid ranges:\nexport const NAME_BID_RANGES = mapObject({\n 31: 3,\n 30: 5,\n 29: 8,\n 28: 13,\n 27: 21,\n 26: 34,\n 25: 55,\n 24: 89,\n 23: 144,\n 22: 233,\n 21: 377,\n 20: 610,\n 19: 987,\n 18: 1597,\n 17: 2584,\n 16: 4181,\n 15: 6765,\n 14: 10946,\n 13: 17711,\n 12: 28657,\n 11: 46368,\n 10: 75025,\n 9: 121393,\n 8: 196418,\n 7: 317811,\n 6: 514229,\n 5: 832040,\n 4: 1346269,\n 3: 2178309,\n 2: 3524578,\n 1: 5702887\n}, ([key, value]) => [key, new BigNumber(value).times(NAME_FEE_MULTIPLIER)])\n\n// # ref: https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273\n// # name bid timeouts\nexport const NAME_BID_TIMEOUTS = {\n 13: BigNumber(0),\n 12: BigNumber(NAME_BID_TIMEOUT_BLOCKS), // # 480 blocks\n 8: BigNumber(31).times(NAME_BID_TIMEOUT_BLOCKS), // # 14880 blocks\n 4: BigNumber(62).times(NAME_BID_TIMEOUT_BLOCKS) // # 29760 blocks\n}\n\n// # Tag constant for ids (type uint8)\n// # see https://github.com/aeternity/protocol/blob/master/serializations.md#the-id-type\n// # <<Tag:1/unsigned-integer-unit:8, Hash:32/binary-unit:8>>\nconst ID_TAG_ACCOUNT = 1\nconst ID_TAG_NAME = 2\nconst ID_TAG_COMMITMENT = 3\nconst ID_TAG_ORACLE = 4\nconst ID_TAG_CONTRACT = 5\nconst ID_TAG_CHANNEL = 6\n\nexport const ID_TAG = {\n account: ID_TAG_ACCOUNT,\n name: ID_TAG_NAME,\n commitment: ID_TAG_COMMITMENT,\n oracle: ID_TAG_ORACLE,\n contract: ID_TAG_CONTRACT,\n channel: ID_TAG_CHANNEL\n}\n\nexport const PREFIX_ID_TAG = {\n ak: ID_TAG.account,\n nm: ID_TAG.name,\n cm: ID_TAG.commitment,\n ok: ID_TAG.oracle,\n ct: ID_TAG.contract,\n ch: ID_TAG.channel\n}\n\nexport const ID_TAG_PREFIX = mapObject(PREFIX_ID_TAG, ([key, value]) => [value, key])\n"],"file":"constants.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,E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AAd;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"}