@aeternity/aepp-sdk 9.0.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/base.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/index.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/index.mjs +178 -0
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/index.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
@@ -1,742 +0,0 @@
1
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
2
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
3
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
4
- import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
5
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
6
- import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
7
- import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
8
- import _typeof from "@babel/runtime-corejs3/helpers/typeof";
9
- import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
10
- import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
11
- import _toArray from "@babel/runtime-corejs3/helpers/toArray";
12
- import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
13
-
14
- var _context;
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context29; _forEachInstanceProperty(_context29 = ownKeys(Object(source), true)).call(_context29, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context30; _forEachInstanceProperty(_context30 = ownKeys(Object(source))).call(_context30, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
-
20
- import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
21
- import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
22
- import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
23
- import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
24
- import _Object$entries3 from "@babel/runtime-corejs3/core-js-stable/object/entries";
25
- import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
26
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
27
- import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
28
- import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
29
- import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
30
- import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
31
- import _entriesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/entries";
32
- import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
33
- import _JSON$stringify from "@babel/runtime-corejs3/core-js-stable/json/stringify";
34
- import Joi from 'joi-browser';
35
- import { isHex } from '../../utils/string';
36
- import { toBytes } from '../../utils/bytes';
37
- import { decode } from '../../tx/builder/helpers';
38
- import { parseBigNumber } from '../../utils/bignumber';
39
- import { isAddressValid, addressFromDecimal, hash } from '../../utils/crypto';
40
- export var SOPHIA_TYPES = _reduceInstanceProperty(_context = ['int', 'string', 'tuple', 'address', 'bool', 'list', 'map', 'record', 'option', 'oracle', 'oracleQuery', 'hash', 'signature', 'bytes', 'variant']).call(_context, function (acc, type) {
41
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, type, type));
42
- }, {
43
- ChainTtl: 'Chain.ttl'
44
- });
45
- /**
46
- * Transform decoded event to JS type
47
- * @param {Object[]} events Array of events
48
- * @param {Object} [options={}] Options
49
- * @param {Object} [options.schema=[]] SC function ACI schema
50
- * @return {Object}
51
- */
52
-
53
- export function decodeEvents(events) {
54
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
55
- schema: []
56
- };
57
- if (!events.length) return [];
58
- return _mapInstanceProperty(events).call(events, function (l) {
59
- var _context2;
60
-
61
- var _l$topics = _toArray(l.topics),
62
- eName = _l$topics[0],
63
- eParams = _sliceInstanceProperty(_l$topics).call(_l$topics, 1);
64
-
65
- var hexHash = toBytes(eName, true).toString('hex');
66
-
67
- var _options$schema$reduc = _reduceInstanceProperty(_context2 = options.schema).call(_context2, function (acc, el) {
68
- if (hash(el.name).toString('hex') === hexHash) {
69
- l.name = el.name;
70
- return {
71
- schema: el.types,
72
- name: el.name
73
- };
74
- }
75
-
76
- return acc;
77
- }, {
78
- schema: []
79
- }),
80
- schema = _options$schema$reduc.schema;
81
-
82
- var _schema$reduce = _reduceInstanceProperty(schema).call(schema, function (acc, el) {
83
- var _context4;
84
-
85
- if (el === SOPHIA_TYPES.string) {
86
- var _context3;
87
-
88
- return {
89
- decoded: _concatInstanceProperty(_context3 = []).call(_context3, _toConsumableArray(acc.decoded), [transformEvent(l.data, el)]),
90
- params: acc.params
91
- };
92
- }
93
-
94
- var _acc$params = _toArray(acc.params),
95
- event = _acc$params[0],
96
- tail = _sliceInstanceProperty(_acc$params).call(_acc$params, 1);
97
-
98
- return {
99
- decoded: _concatInstanceProperty(_context4 = []).call(_context4, _toConsumableArray(acc.decoded), [transformEvent(event, el)]),
100
- params: tail
101
- };
102
- }, {
103
- decoded: [],
104
- params: eParams
105
- }),
106
- decoded = _schema$reduce.decoded;
107
-
108
- return _objectSpread(_objectSpread({}, l), {}, {
109
- decoded: decoded
110
- });
111
- });
112
- }
113
- /**
114
- * Transform Event based on type
115
- * @param {String|Number} event Event data
116
- * @param {String} type Event type from schema
117
- * @return {*}
118
- */
119
-
120
- export function transformEvent(event, type) {
121
- switch (type) {
122
- case SOPHIA_TYPES["int"]:
123
- return parseBigNumber(event);
124
-
125
- case SOPHIA_TYPES.bool:
126
- return !!event;
127
-
128
- case SOPHIA_TYPES.hash:
129
- return toBytes(event, true).toString('hex');
130
-
131
- case SOPHIA_TYPES.address:
132
- return addressFromDecimal(event).split('_')[1];
133
-
134
- case SOPHIA_TYPES.string:
135
- return decode(event).toString('utf-8');
136
-
137
- default:
138
- return toBytes(event, true);
139
- }
140
- }
141
- export function injectVars(t, aciType) {
142
- var _Object$entries = _Object$entries3(aciType.typedef),
143
- _Object$entries2 = _slicedToArray(_Object$entries, 1),
144
- _Object$entries2$ = _slicedToArray(_Object$entries2[0], 2),
145
- baseType = _Object$entries2$[0],
146
- generic = _Object$entries2$[1];
147
-
148
- var _Object$entries4 = _Object$entries3(t),
149
- _Object$entries5 = _slicedToArray(_Object$entries4, 1),
150
- _Object$entries5$ = _slicedToArray(_Object$entries5[0], 2),
151
- varianValue = _Object$entries5$[1];
152
-
153
- switch (baseType) {
154
- case SOPHIA_TYPES.variant:
155
- return _defineProperty({}, baseType, _mapInstanceProperty(generic).call(generic, function (el) {
156
- var _Object$entries$ = _slicedToArray(_Object$entries3(el)[0], 2),
157
- tag = _Object$entries$[0],
158
- gen = _Object$entries$[1];
159
-
160
- return _defineProperty({}, tag, _mapInstanceProperty(gen).call(gen, function (type) {
161
- var _context5, _context6;
162
-
163
- var index = _indexOfInstanceProperty(_context5 = _mapInstanceProperty(_context6 = aciType.vars).call(_context6, function (e) {
164
- return e.name;
165
- })).call(_context5, type);
166
-
167
- return index === -1 ? type : varianValue[index];
168
- }));
169
- }));
170
- }
171
- }
172
- /**
173
- * Ling Type Defs
174
- * @param t
175
- * @param bindings
176
- * @return {Object}
177
- */
178
-
179
- export function linkTypeDefs(t, bindings) {
180
- var _context7, _context8;
181
-
182
- var _ref3 = _typeof(t) === 'object' ? _Object$keys(t)[0].split('.') : t.split('.'),
183
- _ref4 = _slicedToArray(_ref3, 2),
184
- root = _ref4[0],
185
- typeDef = _ref4[1];
186
-
187
- var contractTypeDefs = _findInstanceProperty(bindings).call(bindings, function (c) {
188
- return c.name === root;
189
- });
190
-
191
- var aciType = _findInstanceProperty(_context7 = _concatInstanceProperty(_context8 = []).call(_context8, _toConsumableArray(contractTypeDefs.type_defs), [{
192
- name: 'state',
193
- typedef: contractTypeDefs.state,
194
- vars: []
195
- }])).call(_context7, function (_ref5) {
196
- var name = _ref5.name;
197
- return name === typeDef;
198
- });
199
-
200
- if (aciType.vars.length) {
201
- aciType.typedef = injectVars(t, aciType);
202
- }
203
-
204
- return isTypedDefOrState(aciType.typedef, bindings) ? linkTypeDefs(aciType.typedef, bindings) : aciType.typedef;
205
- }
206
-
207
- var isTypedDefOrState = function isTypedDefOrState(t, bindings) {
208
- var _context9, _context10;
209
-
210
- if (!_includesInstanceProperty(_context9 = ['string', 'object']).call(_context9, _typeof(t))) return false;
211
- t = _typeof(t) === 'object' ? _Object$keys(t)[0] : t;
212
-
213
- var _t$split = t.split('.'),
214
- _t$split2 = _toArray(_t$split),
215
- root = _t$split2[0],
216
- path = _sliceInstanceProperty(_t$split2).call(_t$split2, 1); // Remote Contract Address
217
-
218
-
219
- if (!path.length) return false;
220
- return _includesInstanceProperty(_context10 = _mapInstanceProperty(bindings).call(bindings, function (c) {
221
- return c.name;
222
- })).call(_context10, root);
223
- };
224
-
225
- var isRemoteAddress = function isRemoteAddress(t) {
226
- var _context11;
227
-
228
- if (typeof t !== 'string') return false;
229
-
230
- var _t$split3 = t.split('.'),
231
- _t$split4 = _toArray(_t$split3),
232
- root = _t$split4[0],
233
- path = _sliceInstanceProperty(_t$split4).call(_t$split4, 1);
234
-
235
- return !path.length && !_includesInstanceProperty(_context11 = _Object$values(SOPHIA_TYPES)).call(_context11, root);
236
- };
237
- /**
238
- * Parse sophia type
239
- * @param type
240
- * @param returnType
241
- * @return {Object}
242
- */
243
-
244
-
245
- export function readType(type) {
246
- var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
247
- bindings = _ref6.bindings;
248
-
249
- var _ref7 = _Array$isArray(type) ? type : [type],
250
- _ref8 = _slicedToArray(_ref7, 1),
251
- t = _ref8[0]; // If remote address
252
-
253
-
254
- if (isRemoteAddress(t)) return {
255
- t: SOPHIA_TYPES.address
256
- }; // Link State and typeDef
257
-
258
- if (isTypedDefOrState(t, bindings)) t = linkTypeDefs(t, bindings); // Map, Tuple, List, Record, Bytes
259
-
260
- if (_typeof(t) === 'object') {
261
- var _Object$entries6 = _Object$entries3(t),
262
- _Object$entries7 = _slicedToArray(_Object$entries6, 1),
263
- _Object$entries7$ = _slicedToArray(_Object$entries7[0], 2),
264
- baseType = _Object$entries7$[0],
265
- generic = _Object$entries7$[1];
266
-
267
- return {
268
- t: baseType,
269
- generic: generic
270
- };
271
- } // Base types
272
-
273
-
274
- if (typeof t === 'string') return {
275
- t: t
276
- };
277
- } // FUNCTION ARGUMENTS TRANSFORMATION ↓↓↓
278
-
279
- /**
280
- * Transform JS type to Sophia-type
281
- * @param type
282
- * @param value
283
- * @param bindings
284
- * @return {string}
285
- */
286
-
287
- export function transform(type, value) {
288
- var _ref9 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
289
- bindings = _ref9.bindings;
290
-
291
- var _readType = readType(type, {
292
- bindings: bindings
293
- }),
294
- t = _readType.t,
295
- generic = _readType.generic;
296
-
297
- switch (t) {
298
- case SOPHIA_TYPES.ChainTtl:
299
- return "".concat(value);
300
-
301
- case SOPHIA_TYPES.string:
302
- return "\"".concat(value, "\"");
303
-
304
- case SOPHIA_TYPES.list:
305
- return "[".concat(_mapInstanceProperty(value).call(value, function (el) {
306
- return transform(generic, el, {
307
- bindings: bindings
308
- });
309
- }), "]");
310
-
311
- case SOPHIA_TYPES.tuple:
312
- return "(".concat(_mapInstanceProperty(value).call(value, function (el, i) {
313
- return transform(generic[i], el, {
314
- bindings: bindings
315
- });
316
- }), ")");
317
-
318
- case SOPHIA_TYPES.option:
319
- {
320
- return value === undefined ? 'None' : "Some(".concat(transform(generic, value, {
321
- bindings: bindings
322
- }), ")");
323
- }
324
-
325
- case SOPHIA_TYPES.hash:
326
- case SOPHIA_TYPES.bytes:
327
- case SOPHIA_TYPES.signature:
328
- if (typeof value === 'string') {
329
- if (isHex(value)) return "#".concat(value);
330
- if (isAddressValid(value)) return "#".concat(decode(value).toString('hex'));
331
- }
332
-
333
- return "#".concat(Buffer.from(value).toString('hex'));
334
-
335
- case SOPHIA_TYPES.record:
336
- return "{".concat(_reduceInstanceProperty(generic).call(generic, function (acc, _ref10, i) {
337
- var _context12, _context13;
338
-
339
- var name = _ref10.name,
340
- type = _ref10.type;
341
- acc += _concatInstanceProperty(_context12 = _concatInstanceProperty(_context13 = "".concat(i !== 0 ? ',' : '')).call(_context13, name, " = ")).call(_context12, transform(type, value[name], {
342
- bindings: bindings
343
- }));
344
- return acc;
345
- }, ''), "}");
346
-
347
- case _mapInstanceProperty(SOPHIA_TYPES):
348
- return transformMap(value, generic, {
349
- bindings: bindings
350
- });
351
-
352
- case SOPHIA_TYPES.variant:
353
- return transformVariant(value, generic, {
354
- bindings: bindings
355
- });
356
- }
357
-
358
- return "".concat(value);
359
- }
360
- export function transformVariant(value, generic, _ref11) {
361
- var _context14, _context15;
362
-
363
- var bindings = _ref11.bindings;
364
-
365
- var _ref12 = typeof value === 'string' ? [[value, []]] : _Object$entries3(value),
366
- _ref13 = _slicedToArray(_ref12, 1),
367
- _ref13$ = _slicedToArray(_ref13[0], 2),
368
- variant = _ref13$[0],
369
- variantArgs = _ref13$[1];
370
-
371
- var _Object$entries8 = _Object$entries3(_findInstanceProperty(generic).call(generic, function (o) {
372
- return _Object$keys(o)[0].toLowerCase() === variant.toLowerCase();
373
- })),
374
- _Object$entries9 = _slicedToArray(_Object$entries8, 1),
375
- _Object$entries9$ = _slicedToArray(_Object$entries9[0], 2),
376
- v = _Object$entries9$[0],
377
- type = _Object$entries9$[1];
378
-
379
- return _concatInstanceProperty(_context14 = "".concat(v)).call(_context14, !type.length ? '' : "(".concat(_mapInstanceProperty(_context15 = _sliceInstanceProperty(variantArgs).call(variantArgs, 0, type.length)).call(_context15, function (el, i) {
380
- return transform(type[i], el, {
381
- bindings: bindings
382
- });
383
- }), ")"));
384
- }
385
- export function transformMap(value, generic, _ref14) {
386
- var bindings = _ref14.bindings;
387
-
388
- if (!_Array$isArray(value)) {
389
- if (_entriesInstanceProperty(value)) value = _Array$from(_entriesInstanceProperty(value).call(value));else if (value instanceof Object) value = _Object$entries3(value);
390
- }
391
-
392
- return ['{', _mapInstanceProperty(value).call(value, function (_ref15) {
393
- var _ref16 = _slicedToArray(_ref15, 2),
394
- key = _ref16[0],
395
- value = _ref16[1];
396
-
397
- return ["[".concat(transform(generic[0], key, {
398
- bindings: bindings
399
- }), "]"), transform(generic[1], value, {
400
- bindings: bindings
401
- })].join(' = ');
402
- }).join(), '}'].join('');
403
- } // FUNCTION RETURN VALUE TRANSFORMATION ↓↓↓
404
-
405
- /**
406
- * Transform decoded data to JS type
407
- * @param aci
408
- * @param result
409
- * @param transformDecodedData
410
- * @return {*}
411
- */
412
-
413
- export function transformDecodedData(aci, result) {
414
- var _ref17 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
415
- _ref17$skipTransformD = _ref17.skipTransformDecoded,
416
- skipTransformDecoded = _ref17$skipTransformD === void 0 ? false : _ref17$skipTransformD,
417
- _ref17$addressPrefix = _ref17.addressPrefix,
418
- addressPrefix = _ref17$addressPrefix === void 0 ? 'ak' : _ref17$addressPrefix,
419
- bindings = _ref17.bindings;
420
-
421
- if (skipTransformDecoded) return result;
422
-
423
- var _readType2 = readType(aci, {
424
- bindings: bindings
425
- }),
426
- t = _readType2.t,
427
- generic = _readType2.generic;
428
-
429
- switch (t) {
430
- case SOPHIA_TYPES.bool:
431
- return !!result;
432
-
433
- case SOPHIA_TYPES.address:
434
- return result === 0 ? 0 : result;
435
-
436
- case SOPHIA_TYPES.hash:
437
- case SOPHIA_TYPES.bytes:
438
- case SOPHIA_TYPES.signature:
439
- return result.split('#')[1];
440
-
441
- case _mapInstanceProperty(SOPHIA_TYPES):
442
- {
443
- var _generic = _slicedToArray(generic, 2),
444
- keyT = _generic[0],
445
- valueT = _generic[1];
446
-
447
- return _reduceInstanceProperty(result).call(result, function (acc, _ref18) {
448
- var _ref19 = _slicedToArray(_ref18, 2),
449
- key = _ref19[0],
450
- val = _ref19[1];
451
-
452
- key = transformDecodedData(keyT, key, {
453
- bindings: bindings
454
- });
455
- val = transformDecodedData(valueT, val, {
456
- bindings: bindings
457
- });
458
- acc.push([key, val]);
459
- return acc;
460
- }, []);
461
- }
462
-
463
- case SOPHIA_TYPES.option:
464
- {
465
- if (result === 'None') return undefined;
466
-
467
- var _Object$entries10 = _Object$entries3(result),
468
- _Object$entries11 = _slicedToArray(_Object$entries10, 1),
469
- _Object$entries11$ = _slicedToArray(_Object$entries11[0], 2),
470
- variantType = _Object$entries11$[0],
471
- _Object$entries11$$ = _slicedToArray(_Object$entries11$[1], 1),
472
- value = _Object$entries11$$[0];
473
-
474
- return variantType === 'Some' ? transformDecodedData(generic, value, {
475
- bindings: bindings
476
- }) : undefined;
477
- }
478
-
479
- case SOPHIA_TYPES.list:
480
- return _mapInstanceProperty(result).call(result, function (value) {
481
- return transformDecodedData(generic, value, {
482
- bindings: bindings
483
- });
484
- });
485
-
486
- case SOPHIA_TYPES.tuple:
487
- return _mapInstanceProperty(result).call(result, function (value, i) {
488
- return transformDecodedData(generic[i], value, {
489
- bindings: bindings
490
- });
491
- });
492
-
493
- case SOPHIA_TYPES.record:
494
- {
495
- var _context16;
496
-
497
- var genericMap = _reduceInstanceProperty(generic).call(generic, function (acc, val) {
498
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, val.name, {
499
- type: val.type
500
- }));
501
- }, {});
502
-
503
- return _reduceInstanceProperty(_context16 = _Object$entries3(result)).call(_context16, function (acc, _ref20) {
504
- var _ref21 = _slicedToArray(_ref20, 2),
505
- name = _ref21[0],
506
- value = _ref21[1];
507
-
508
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, name, transformDecodedData(genericMap[name].type, value, {
509
- bindings: bindings
510
- })));
511
- }, {});
512
- }
513
- }
514
-
515
- return result;
516
- } // FUNCTION ARGUMENTS VALIDATION ↓↓↓
517
-
518
- /**
519
- * Prepare Joi validation schema for sophia types
520
- * @param type
521
- * @param bindings
522
- * @return {Object} JoiSchema
523
- */
524
-
525
- export function prepareSchema(type) {
526
- var _Joi$string, _Joi$object;
527
-
528
- var _ref22 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
529
- bindings = _ref22.bindings;
530
-
531
- var _readType3 = readType(type, {
532
- bindings: bindings
533
- }),
534
- t = _readType3.t,
535
- generic = _readType3.generic;
536
-
537
- switch (t) {
538
- case SOPHIA_TYPES["int"]:
539
- return Joi.number().error(getJoiErrorMsg);
540
-
541
- case SOPHIA_TYPES.variant:
542
- return Joi.alternatives()["try"]([(_Joi$string = Joi.string()).valid.apply(_Joi$string, _toConsumableArray(_reduceInstanceProperty(generic).call(generic, function (acc, el) {
543
- var _Object$entries12 = _Object$entries3(el),
544
- _Object$entries13 = _slicedToArray(_Object$entries12, 1),
545
- _Object$entries13$ = _slicedToArray(_Object$entries13[0], 2),
546
- t = _Object$entries13$[0],
547
- g = _Object$entries13$[1];
548
-
549
- if (!g || !g.length) acc.push(t);
550
- return acc;
551
- }, []))), (_Joi$object = Joi.object(_reduceInstanceProperty(generic).call(generic, function (acc, el) {
552
- var variant = _Object$keys(el)[0];
553
-
554
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, variant, Joi.array()));
555
- }, {}))).or.apply(_Joi$object, _toConsumableArray(_mapInstanceProperty(generic).call(generic, function (e) {
556
- return _Object$keys(e)[0];
557
- })))]);
558
-
559
- case SOPHIA_TYPES.ChainTtl:
560
- return Joi.string().error(getJoiErrorMsg);
561
-
562
- case SOPHIA_TYPES.string:
563
- return Joi.string().error(getJoiErrorMsg);
564
-
565
- case SOPHIA_TYPES.address:
566
- return Joi.string().regex(/^(ak_|ct_|ok_|oq_)/).error(getJoiErrorMsg);
567
-
568
- case SOPHIA_TYPES.bool:
569
- return Joi["boolean"]().error(getJoiErrorMsg);
570
-
571
- case SOPHIA_TYPES.list:
572
- return Joi.array().items(prepareSchema(generic, {
573
- bindings: bindings
574
- })).error(getJoiErrorMsg);
575
-
576
- case SOPHIA_TYPES.tuple:
577
- return Joi.array().ordered(_mapInstanceProperty(generic).call(generic, function (type) {
578
- return prepareSchema(type, {
579
- bindings: bindings
580
- }).required();
581
- })).label('Tuple argument').error(getJoiErrorMsg);
582
-
583
- case SOPHIA_TYPES.record:
584
- return Joi.object(_reduceInstanceProperty(generic).call(generic, function (acc, _ref23) {
585
- var name = _ref23.name,
586
- type = _ref23.type;
587
- return _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, name, prepareSchema(type, {
588
- bindings: bindings
589
- })));
590
- }, {})).error(getJoiErrorMsg);
591
-
592
- case SOPHIA_TYPES.hash:
593
- return JoiBinary.binary().bufferCheck(32).error(getJoiErrorMsg);
594
-
595
- case SOPHIA_TYPES.bytes:
596
- return JoiBinary.binary().bufferCheck(generic).error(getJoiErrorMsg);
597
-
598
- case SOPHIA_TYPES.signature:
599
- return JoiBinary.binary().bufferCheck(64).error(getJoiErrorMsg);
600
-
601
- case SOPHIA_TYPES.option:
602
- return prepareSchema(generic, {
603
- bindings: bindings
604
- }).optional().error(getJoiErrorMsg);
605
- // @Todo Need to transform Map to Array of arrays before validating it
606
- // case SOPHIA_TYPES.map:
607
- // return Joi.array().items(Joi.array().ordered(generic.map(type => prepareSchema(type))))
608
-
609
- default:
610
- return Joi.any();
611
- }
612
- }
613
- /**
614
- * Parse Joi validation error message
615
- * @param errors
616
- * @return {Object} JoiError
617
- */
618
-
619
- export function getJoiErrorMsg(errors) {
620
- return _mapInstanceProperty(errors).call(errors, function (err) {
621
- var _context17, _context18, _context19, _context20, _context21, _context22, _context23, _context24, _context25, _context26, _context27;
622
-
623
- var path = err.path,
624
- type = err.type,
625
- context = err.context;
626
- var value = Object.prototype.hasOwnProperty.call(context, 'value') ? context.value : context.label;
627
- value = _typeof(value) === 'object' ? _sliceInstanceProperty(_context17 = _sliceInstanceProperty(_context18 = _JSON$stringify(value)).call(_context18, 1)).call(_context17, 0, -1) : value;
628
-
629
- switch (type) {
630
- case 'string.base':
631
- return _objectSpread(_objectSpread({}, err), {}, {
632
- message: _concatInstanceProperty(_context19 = "Value \"".concat(value, "\" at path: [")).call(_context19, path, "] not a string")
633
- });
634
-
635
- case 'number.base':
636
- return _objectSpread(_objectSpread({}, err), {}, {
637
- message: _concatInstanceProperty(_context20 = "Value \"".concat(value, "\" at path: [")).call(_context20, path, "] not a number")
638
- });
639
-
640
- case 'boolean.base':
641
- return _objectSpread(_objectSpread({}, err), {}, {
642
- message: _concatInstanceProperty(_context21 = "Value \"".concat(value, "\" at path: [")).call(_context21, path, "] not a boolean")
643
- });
644
-
645
- case 'array.base':
646
- return _objectSpread(_objectSpread({}, err), {}, {
647
- message: _concatInstanceProperty(_context22 = "Value \"".concat(value, "\" at path: [")).call(_context22, path, "] not a array")
648
- });
649
-
650
- case 'object.base':
651
- return _objectSpread(_objectSpread({}, err), {}, {
652
- message: _concatInstanceProperty(_context23 = "Value '".concat(value, "' at path: [")).call(_context23, path, "] not a object")
653
- });
654
-
655
- case 'object.type':
656
- return _objectSpread(_objectSpread({}, err), {}, {
657
- message: _concatInstanceProperty(_context24 = _concatInstanceProperty(_context25 = "Value '".concat(value, "' at path: [")).call(_context25, path, "] not a ")).call(_context24, context.type)
658
- });
659
-
660
- case 'binary.bufferCheck':
661
- return _objectSpread(_objectSpread({}, err), {}, {
662
- message: _concatInstanceProperty(_context26 = _concatInstanceProperty(_context27 = "Value '".concat(Buffer.from(value).toString('hex'), "' at path: [")).call(_context27, path, "] not a ")).call(_context26, context.size, " bytes")
663
- });
664
-
665
- default:
666
- return err;
667
- }
668
- });
669
- }
670
- /**
671
- * Custom Joi Validator for binary type
672
- */
673
-
674
- var JoiBinary = Joi.extend(function (joi) {
675
- return {
676
- name: 'binary',
677
- base: joi.any(),
678
- pre: function pre(value, state, options) {
679
- if (options.convert && typeof value === 'string') {
680
- if (isAddressValid(value)) {
681
- return decode(value);
682
- }
683
-
684
- try {
685
- return Buffer.from(value, 'hex');
686
- } catch (e) {
687
- return undefined;
688
- }
689
- }
690
-
691
- return Buffer.from(value);
692
- },
693
- rules: [{
694
- name: 'bufferCheck',
695
- params: {
696
- size: joi.number().required()
697
- },
698
- validate: function validate(params, value, state, options) {
699
- if (!Buffer.isBuffer(value)) {
700
- return this.createError('binary.base', {
701
- value: value
702
- }, state, options);
703
- }
704
-
705
- if (value.length !== params.size) {
706
- return this.createError('binary.bufferCheck', {
707
- value: value,
708
- size: params.size
709
- }, state, options);
710
- }
711
-
712
- return value;
713
- }
714
- }]
715
- };
716
- });
717
- /**
718
- * Validation contract function arguments
719
- * @param aci
720
- * @param params
721
- */
722
-
723
- export function validateArguments(aci, params) {
724
- var _context28;
725
-
726
- var validationSchema = Joi.array().ordered(_mapInstanceProperty(_context28 = aci.arguments).call(_context28, function (_ref24, i) {
727
- var type = _ref24.type;
728
- return prepareSchema(type, {
729
- bindings: aci.bindings
730
- }).label("[".concat(params[i], "]"));
731
- })).sparse(true).label('Argument');
732
-
733
- var _Joi$validate = Joi.validate(params, validationSchema, {
734
- abortEarly: false
735
- }),
736
- error = _Joi$validate.error;
737
-
738
- if (error) {
739
- throw error;
740
- }
741
- }
742
- //# sourceMappingURL=transformation.js.map