@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
@@ -1,16 +1,9 @@
1
1
  /**
2
2
  * Big Number Helpers
3
3
  * @module @aeternity/aepp-sdk/es/utils/bignumber
4
- * @example import { parseBigNumber, isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
4
+ * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
5
5
  */
6
6
  import BigNumber from 'bignumber.js';
7
- /**
8
- * Convert number to string
9
- * @param {String|Number|BigNumber} number number to convert
10
- * @return {String}
11
- */
12
-
13
- export const parseBigNumber = number => new BigNumber(number.toString()).toString(10);
14
7
  /**
15
8
  * Check if value is BigNumber, Number or number string representation
16
9
  * @param {String|Number|BigNumber} number number to convert
@@ -25,4 +18,4 @@ export const isBigNumber = number => ['number', 'object', 'string', 'bigint'].in
25
18
  */
26
19
 
27
20
  export const ceil = bigNumber => bigNumber.integerValue(BigNumber.ROUND_CEIL);
28
- //# sourceMappingURL=bignumber.js.map
21
+ //# sourceMappingURL=bignumber.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/bignumber.ts"],"names":["BigNumber","isBigNumber","number","includes","isNaN","Number","isInteger","ceil","bigNumber","integerValue","ROUND_CEIL"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAIC,MAAD,IACzB,CAAC,QAAD,EAAW,QAAX,EAAqB,QAArB,EAA+B,QAA/B,EAAyCC,QAAzC,CAAkD,OAAOD,MAAzD,MACC,CAACE,KAAK,CAACF,MAAD,CAAN,IAA4BG,MAAM,CAACC,SAAP,CAAiBJ,MAAjB,CAA5B,IAAwDF,SAAS,CAACC,WAAV,CAAsBC,MAAtB,CADzD,CADK;AAIP;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMK,IAAI,GAAIC,SAAD,IAAqCA,SAAS,CAACC,YAAV,CAAuBT,SAAS,CAACU,UAAjC,CAAlD","sourcesContent":["/**\n * Big Number Helpers\n * @module @aeternity/aepp-sdk/es/utils/bignumber\n * @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'\n */\nimport BigNumber from 'bignumber.js'\n\n/**\n * Check if value is BigNumber, Number or number string representation\n * @param {String|Number|BigNumber} number number to convert\n * @return {Boolean}\n */\nexport const isBigNumber = (number: string | number | BigNumber): boolean =>\n ['number', 'object', 'string', 'bigint'].includes(typeof number) &&\n (!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))\n\n/**\n * BigNumber ceil operation\n * @param {BigNumber} bigNumber\n * @return {BigNumber}\n */\nexport const ceil = (bigNumber: BigNumber): BigNumber => bigNumber.integerValue(BigNumber.ROUND_CEIL)\n"],"file":"bignumber.mjs"}
@@ -1,3 +1,8 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+
1
6
  /*
2
7
  * ISC License (ISC)
3
8
  * Copyright 2018 aeternity developers
@@ -15,7 +20,8 @@
15
20
  * PERFORMANCE OF THIS SOFTWARE.
16
21
  */
17
22
  import BigNumber from 'bignumber.js';
18
- import { isBase64, isHex } from './string';
23
+ import { NoSerializerFoundError, TypeError } from "./errors.mjs";
24
+ import { isBase64, isHex } from "./string.mjs";
19
25
  /**
20
26
  * Bytes module
21
27
  * @module @aeternity/aepp-sdk/es/utils/bytes
@@ -29,10 +35,10 @@ import { isBase64, isHex } from './string';
29
35
  */
30
36
 
31
37
  export function bigNumberToByteArray(x) {
32
- if (!x.isInteger()) throw new Error(`Unexpected not integer value: ${x.toFixed()}`);
38
+ if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`);
33
39
  let hexString = x.toString(16);
34
40
  if (hexString.length % 2 === 1) hexString = '0' + hexString;
35
- return Buffer.from(hexString, 'hex');
41
+ return _Buffer.from(hexString, 'hex');
36
42
  }
37
43
  /**
38
44
  * Convert string, number, or BigNumber to byte array
@@ -46,7 +52,7 @@ export function toBytes(val) {
46
52
  // Encode a value to bytes.
47
53
  // If the value is an int it will be encoded as bytes big endian
48
54
  // Raises ValueError if the input is not an int or string
49
- if (val === undefined || val === null) return Buffer.from([]);
55
+ if (val === undefined || val === null) return _Buffer.from([]);
50
56
 
51
57
  if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {
52
58
  if (!BigNumber.isBigNumber(val)) val = new BigNumber(val);
@@ -54,10 +60,10 @@ export function toBytes(val) {
54
60
  }
55
61
 
56
62
  if (typeof val === 'string') {
57
- return Buffer.from(val);
63
+ return _Buffer.from(val);
58
64
  }
59
65
 
60
- throw new Error('Byte serialization not supported');
66
+ throw new NoSerializerFoundError();
61
67
  }
62
68
  /**
63
69
  * Convert a string to a Buffer. If encoding is not specified, hex-encoding
@@ -69,6 +75,8 @@ export function toBytes(val) {
69
75
  */
70
76
 
71
77
  export function str2buf(str, enc) {
72
- return Buffer.from(str, enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined));
78
+ var _ref;
79
+
80
+ return _Buffer.from(str, (_ref = enc !== null && enc !== void 0 ? enc : isHex(str) ? 'hex' : undefined) !== null && _ref !== void 0 ? _ref : isBase64(str) ? 'base64' : undefined);
73
81
  }
74
- //# sourceMappingURL=bytes.js.map
82
+ //# sourceMappingURL=bytes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/bytes.ts"],"names":["BigNumber","NoSerializerFoundError","TypeError","isBase64","isHex","bigNumberToByteArray","x","isInteger","toFixed","hexString","toString","length","from","toBytes","val","big","undefined","Number","isBigNumber","str2buf","str","enc"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,sB,EAAwBC,S;SACxBC,Q,EAAUC,K;AAEnB;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,oBAAT,CAA+BC,CAA/B,EAAqD;AAC1D,MAAI,CAACA,CAAC,CAACC,SAAF,EAAL,EAAoB,MAAM,IAAIL,SAAJ,CAAe,iCAAgCI,CAAC,CAACE,OAAF,EAAY,EAA3D,CAAN;AACpB,MAAIC,SAAS,GAAGH,CAAC,CAACI,QAAF,CAAW,EAAX,CAAhB;AACA,MAAID,SAAS,CAACE,MAAV,GAAmB,CAAnB,KAAyB,CAA7B,EAAgCF,SAAS,GAAG,MAAMA,SAAlB;AAChC,SAAO,QAAOG,IAAP,CAAYH,SAAZ,EAAuB,KAAvB,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,OAAT,CAAkBC,GAAlB,EAA0F;AAAA,MAA9BC,GAA8B,uEAAf,KAAe;AAC/F;AACA;AACA;AAEA,MAAID,GAAG,KAAKE,SAAR,IAAqBF,GAAG,KAAK,IAAjC,EAAuC,OAAO,QAAOF,IAAP,CAAY,EAAZ,CAAP;;AACvC,MAAIK,MAAM,CAACV,SAAP,CAAiBO,GAAjB,KAAyBd,SAAS,CAACkB,WAAV,CAAsBJ,GAAtB,CAAzB,IAAuDC,GAA3D,EAAgE;AAC9D,QAAI,CAACf,SAAS,CAACkB,WAAV,CAAsBJ,GAAtB,CAAL,EAAiCA,GAAG,GAAG,IAAId,SAAJ,CAAcc,GAAd,CAAN;AACjC,WAAOT,oBAAoB,CAACS,GAAD,CAA3B;AACD;;AACD,MAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAO,QAAOF,IAAP,CAAYE,GAAZ,CAAP;AACD;;AACD,QAAM,IAAIb,sBAAJ,EAAN;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkB,OAAT,CAAkBC,GAAlB,EAA+BC,GAA/B,EAA6D;AAAA;;AAClE,SAAO,QAAOT,IAAP,CACLQ,GADK,UAELC,GAFK,aAELA,GAFK,cAELA,GAFK,GAEGjB,KAAK,CAACgB,GAAD,CAAL,GAAa,KAAb,GAAqBJ,SAFxB,uCAEuCb,QAAQ,CAACiB,GAAD,CAAR,GAAgB,QAAhB,GAA2BJ,SAFlE,CAAP;AAID","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 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 */\nimport BigNumber from 'bignumber.js'\nimport { NoSerializerFoundError, TypeError } from './errors'\nimport { isBase64, isHex } from './string'\n\n/**\n * Bytes module\n * @module @aeternity/aepp-sdk/es/utils/bytes\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\n/**\n * Convert bignumber to byte array\n * @param {BigNumber} x bignumber instance\n * @return Buffer\n */\nexport function bigNumberToByteArray (x: BigNumber): Buffer {\n if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)\n let hexString = x.toString(16)\n if (hexString.length % 2 === 1) hexString = '0' + hexString\n return Buffer.from(hexString, 'hex')\n}\n\n/**\n * Convert string, number, or BigNumber to byte array\n * @param {null|string|number|BigNumber} val\n * @param {boolean} big enables force conversion to BigNumber\n * @return Buffer\n */\nexport function toBytes (val?: null | string | number | BigNumber, big: boolean = false): Buffer {\n // Encode a value to bytes.\n // If the value is an int it will be encoded as bytes big endian\n // Raises ValueError if the input is not an int or string\n\n if (val === undefined || val === null) return Buffer.from([])\n if (Number.isInteger(val) || BigNumber.isBigNumber(val) || big) {\n if (!BigNumber.isBigNumber(val)) val = new BigNumber(val)\n return bigNumberToByteArray(val)\n }\n if (typeof val === 'string') {\n return Buffer.from(val)\n }\n throw new NoSerializerFoundError()\n}\n\n/**\n * Convert a string to a Buffer. If encoding is not specified, hex-encoding\n * will be used if the input is valid hex. If the input is valid base64 but\n * not valid hex, base64 will be used. Otherwise, utf8 will be used.\n * @param {string} str String to be converted.\n * @param {string} [enc] Encoding of the input string.\n * @return {buffer} Buffer containing the input data.\n */\nexport function str2buf (str: string, enc?: BufferEncoding): Buffer {\n return Buffer.from(\n str,\n enc ?? (isHex(str) ? 'hex' : undefined) ?? (isBase64(str) ? 'base64' : undefined)\n )\n}\n"],"file":"bytes.mjs"}
@@ -1,3 +1,8 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+
1
6
  /*
2
7
  * ISC License (ISC)
3
8
  * Copyright 2021 aeternity developers
@@ -14,7 +19,10 @@
14
19
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
20
  * PERFORMANCE OF THIS SOFTWARE.
16
21
  */
17
- import { blake2b } from 'blakejs';
22
+ import _aeternityBlakejs from '@aeternity/blakejs';
23
+ const {
24
+ blake2b
25
+ } = _aeternityBlakejs;
18
26
 
19
27
  /**
20
28
  * Calculate 256bits Blake2b hash of `input`
@@ -23,6 +31,6 @@ import { blake2b } from 'blakejs';
23
31
  * @return {Buffer} Hash
24
32
  */
25
33
  export function hash(input) {
26
- return Buffer.from(blake2b(input, null, 32)); // 256 bits
34
+ return _Buffer.from(blake2b(input, undefined, 32)); // 256 bits
27
35
  }
28
- //# sourceMappingURL=crypto-ts.js.map
36
+ //# sourceMappingURL=crypto-ts.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/crypto-ts.ts"],"names":["hash","input","from","blake2b","undefined"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,8BAAwB,oBAAxB;;;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,IAAT,CAAeC,KAAf,EAAoC;AACzC,SAAO,QAAOC,IAAP,CAAYC,OAAO,CAACF,KAAD,EAAQG,SAAR,EAAmB,EAAnB,CAAnB,CAAP,CADyC,CACS;AACnD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 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\nimport { blake2b } from '@aeternity/blakejs'\nimport type { Data } from 'blakejs'\n\n/**\n * Calculate 256bits Blake2b hash of `input`\n * @rtype (input: String) => hash: String\n * @param {Data} input - Data to hash\n * @return {Buffer} Hash\n */\nexport function hash (input: Data): Buffer {\n return Buffer.from(blake2b(input, undefined, 32)) // 256 bits\n}\n"],"file":"crypto-ts.mjs"}
@@ -1,3 +1,8 @@
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+
1
6
  /*
2
7
  * ISC License (ISC)
3
8
  * Copyright 2018 aeternity developers
@@ -20,14 +25,14 @@
20
25
  * @module @aeternity/aepp-sdk/es/utils/crypto
21
26
  * @example import { Crypto } from '@aeternity/aepp-sdk'
22
27
  */
23
- import bs58check from 'bs58check';
24
28
  import nacl from 'tweetnacl';
25
29
  import aesjs from 'aes-js';
26
30
  import shajs from 'sha.js';
27
- import { str2buf, toBytes } from './bytes';
28
- import { decode } from '../tx/builder/helpers';
29
- import { hash } from './crypto-ts';
30
- export * from './crypto-ts';
31
+ import { str2buf } from "./bytes.mjs";
32
+ import { encode, decode } from "../tx/builder/helpers.mjs";
33
+ import { hash } from "./crypto-ts.mjs";
34
+ import { NotImplementedError } from "./errors.mjs";
35
+ export * from "./crypto-ts.mjs";
31
36
  const Ecb = aesjs.ModeOfOperation.ecb;
32
37
  /**
33
38
  * Generate address from secret key
@@ -38,8 +43,10 @@ const Ecb = aesjs.ModeOfOperation.ecb;
38
43
 
39
44
  export function getAddressFromPriv(secret) {
40
45
  const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret));
41
- const publicBuffer = Buffer.from(keys.publicKey);
42
- return `ak_${encodeBase58Check(publicBuffer)}`;
46
+
47
+ const publicBuffer = _Buffer.from(keys.publicKey);
48
+
49
+ return encode(publicBuffer, 'ak');
43
50
  }
44
51
  /**
45
52
  * Check if address is valid
@@ -51,24 +58,14 @@ export function getAddressFromPriv(secret) {
51
58
 
52
59
  export function isAddressValid(address) {
53
60
  let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ak';
54
- if (typeof address !== 'string') return false;
55
61
 
56
62
  try {
57
- return decode(address, prefix).length === 32;
63
+ decode(address, prefix);
64
+ return true;
58
65
  } catch (e) {
59
66
  return false;
60
67
  }
61
68
  }
62
- /**
63
- * Parse decimal address and return base58Check encoded address with prefix 'ak'
64
- * @rtype (input: String) => address: String
65
- * @param {String} decimalAddress - Address
66
- * @return {String} address
67
- */
68
-
69
- export function addressFromDecimal(decimalAddress) {
70
- return aeEncodeKey(toBytes(decimalAddress, true));
71
- }
72
69
  /**
73
70
  * Calculate SHA256 hash of `input`
74
71
  * @rtype (input: String) => hash: String
@@ -88,64 +85,6 @@ export function sha256hash(input) {
88
85
  export function salt() {
89
86
  return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));
90
87
  }
91
- /**
92
- * Base64check encode given `input`
93
- * @rtype (input: String|buffer) => Buffer
94
- * @param {String} input - Data to encode
95
- * @return {Buffer} Base64check encoded data
96
- */
97
-
98
- export function encodeBase64Check(input) {
99
- const buffer = Buffer.from(input);
100
- const checksum = checkSumFn(input);
101
- const payloadWithChecksum = Buffer.concat([buffer, checksum], buffer.length + 4);
102
- return payloadWithChecksum.toString('base64');
103
- }
104
- export function checkSumFn(payload) {
105
- return sha256hash(sha256hash(payload)).slice(0, 4);
106
- }
107
-
108
- function decodeRaw(buffer) {
109
- const payload = buffer.slice(0, -4);
110
- const checksum = buffer.slice(-4);
111
- const newChecksum = checkSumFn(payload);
112
- if (!checksum.equals(newChecksum)) return;
113
- return payload;
114
- }
115
- /**
116
- * Base64check decode given `str`
117
- * @rtype (str: String) => Buffer
118
- * @param {String} str - Data to decode
119
- * @return {Buffer} Base64check decoded data
120
- */
121
-
122
-
123
- export function decodeBase64Check(str) {
124
- const buffer = Buffer.from(str, 'base64');
125
- const payload = decodeRaw(buffer);
126
- if (!payload) throw new Error('Invalid checksum');
127
- return Buffer.from(payload);
128
- }
129
- /**
130
- * Base58 encode given `input`
131
- * @rtype (input: String) => String
132
- * @param {String|Buffer} input - Data to encode
133
- * @return {String} Base58 encoded data
134
- */
135
-
136
- export function encodeBase58Check(input) {
137
- return bs58check.encode(Buffer.from(input));
138
- }
139
- /**
140
- * Base58 decode given `str`
141
- * @rtype (str: String) => Buffer
142
- * @param {String} str - Data to decode
143
- * @return {Buffer} Base58 decoded data
144
- */
145
-
146
- export function decodeBase58Check(str) {
147
- return bs58check.decode(str);
148
- }
149
88
  /**
150
89
  * Converts a positive integer to the smallest possible
151
90
  * representation in a binary digit representation
@@ -155,7 +94,8 @@ export function decodeBase58Check(str) {
155
94
  */
156
95
 
157
96
  export function encodeUnsigned(value) {
158
- const binary = Buffer.allocUnsafe(4);
97
+ const binary = _Buffer.allocUnsafe(4);
98
+
159
99
  binary.writeUInt32BE(value);
160
100
  return binary.slice(binary.findIndex(i => i !== 0));
161
101
  } // Todo Duplicated in tx builder. remove
@@ -170,8 +110,10 @@ export function encodeUnsigned(value) {
170
110
 
171
111
  export function encodeContractAddress(owner, nonce) {
172
112
  const publicKey = decode(owner, 'ak');
173
- const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)]);
174
- return `ct_${encodeBase58Check(hash(binary))}`;
113
+
114
+ const binary = _Buffer.concat([publicKey, encodeUnsigned(nonce)]);
115
+
116
+ return encode(hash(binary), 'ct');
175
117
  } // KEY-PAIR HELPERS
176
118
 
177
119
  /**
@@ -195,8 +137,10 @@ export function generateKeyPair() {
195
137
  let raw = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
196
138
  // <node>/apps/aens/test/aens_test_utils.erl
197
139
  const keyPair = nacl.sign.keyPair();
198
- const publicBuffer = Buffer.from(keyPair.publicKey);
199
- const secretBuffer = Buffer.from(keyPair.secretKey);
140
+
141
+ const publicBuffer = _Buffer.from(keyPair.publicKey);
142
+
143
+ const secretBuffer = _Buffer.from(keyPair.secretKey);
200
144
 
201
145
  if (raw) {
202
146
  return {
@@ -205,7 +149,7 @@ export function generateKeyPair() {
205
149
  };
206
150
  } else {
207
151
  return {
208
- publicKey: `ak_${encodeBase58Check(publicBuffer)}`,
152
+ publicKey: encode(publicBuffer, 'ak'),
209
153
  secretKey: secretBuffer.toString('hex')
210
154
  };
211
155
  }
@@ -232,10 +176,11 @@ export function encryptKey(password, binaryData) {
232
176
  */
233
177
 
234
178
  export function decryptKey(password, encrypted) {
235
- const encryptedBytes = Buffer.from(encrypted);
179
+ const encryptedBytes = _Buffer.from(encrypted);
180
+
236
181
  const hashedPasswordBytes = sha256hash(password);
237
182
  const aesEcb = new Ecb(hashedPasswordBytes);
238
- return Buffer.from(aesEcb.decrypt(encryptedBytes));
183
+ return _Buffer.from(aesEcb.decrypt(encryptedBytes));
239
184
  } // SIGNATURES
240
185
 
241
186
  /**
@@ -247,7 +192,7 @@ export function decryptKey(password, encrypted) {
247
192
  */
248
193
 
249
194
  export function sign(data, privateKey) {
250
- return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));
195
+ return nacl.sign.detached(_Buffer.from(data), _Buffer.from(privateKey));
251
196
  }
252
197
  /**
253
198
  * Verify that signature was signed by public key
@@ -262,10 +207,12 @@ export function verify(str, signature, publicKey) {
262
207
  return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey);
263
208
  }
264
209
  export function messageToHash(message) {
265
- const p = Buffer.from('aeternity Signed Message:\n', 'utf8');
266
- const msg = Buffer.from(message, 'utf8');
267
- if (msg.length >= 0xFD) throw new Error('message too long');
268
- return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]));
210
+ const p = _Buffer.from('aeternity Signed Message:\n', 'utf8');
211
+
212
+ const msg = _Buffer.from(message, 'utf8');
213
+
214
+ if (msg.length >= 0xFD) throw new NotImplementedError('Message too long');
215
+ return hash(_Buffer.concat([_Buffer.from([p.length]), p, _Buffer.from([msg.length]), msg]));
269
216
  }
270
217
  export function signMessage(message, privateKey) {
271
218
  return sign(messageToHash(message), privateKey);
@@ -273,19 +220,6 @@ export function signMessage(message, privateKey) {
273
220
  export function verifyMessage(str, signature, publicKey) {
274
221
  return verify(messageToHash(str), signature, publicKey);
275
222
  }
276
- /**
277
- * æternity readable public keys are the base58-encoded public key, prepended
278
- * with 'ak_'
279
- * @rtype (binaryKey: Buffer) => String
280
- * @param {Buffer} binaryKey - Key to encode
281
- * @return {String} Encoded key
282
- */
283
-
284
- export function aeEncodeKey(binaryKey) {
285
- const publicKeyBuffer = Buffer.from(binaryKey, 'hex');
286
- const pubKeyAddress = encodeBase58Check(publicKeyBuffer);
287
- return `ak_${pubKeyAddress}`;
288
- }
289
223
  /**
290
224
  * Check key pair for validity
291
225
  *
@@ -297,8 +231,9 @@ export function aeEncodeKey(binaryKey) {
297
231
  */
298
232
 
299
233
  export function isValidKeypair(privateKey, publicKey) {
300
- const message = Buffer.from('TheMessage');
234
+ const message = _Buffer.from('TheMessage');
235
+
301
236
  const signature = sign(message, privateKey);
302
237
  return verify(message, signature, publicKey);
303
238
  }
304
- //# sourceMappingURL=crypto.js.map
239
+ //# sourceMappingURL=crypto.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/crypto.js"],"names":["nacl","aesjs","shajs","str2buf","encode","decode","hash","NotImplementedError","Ecb","ModeOfOperation","ecb","getAddressFromPriv","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","from","publicKey","isAddressValid","address","prefix","e","sha256hash","input","update","digest","salt","Math","floor","random","Number","MAX_SAFE_INTEGER","encodeUnsigned","value","binary","allocUnsafe","writeUInt32BE","slice","findIndex","i","encodeContractAddress","owner","nonce","concat","generateKeyPairFromSecret","generateKeyPair","raw","secretBuffer","secretKey","toString","encryptKey","password","binaryData","hashedPasswordBytes","aesEcb","encrypt","decryptKey","encrypted","encryptedBytes","decrypt","data","privateKey","detached","verify","str","signature","Uint8Array","messageToHash","message","p","msg","length","signMessage","verifyMessage","isValidKeypair"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,OAAOA,IAAP,MAAiB,WAAjB;AACA,OAAOC,KAAP,MAAkB,QAAlB;AACA,OAAOC,KAAP,MAAkB,QAAlB;SAESC,O;SACAC,M,EAAQC,M;SACRC,I;SACAC,mB;;AAIT,MAAMC,GAAG,GAAGP,KAAK,CAACQ,eAAN,CAAsBC,GAAlC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,kBAAT,CAA6BC,MAA7B,EAAqC;AAC1C,QAAMC,IAAI,GAAGb,IAAI,CAACc,IAAL,CAAUC,OAAV,CAAkBC,aAAlB,CAAgCb,OAAO,CAACS,MAAD,CAAvC,CAAb;;AACA,QAAMK,YAAY,GAAG,QAAOC,IAAP,CAAYL,IAAI,CAACM,SAAjB,CAArB;;AACA,SAAOf,MAAM,CAACa,YAAD,EAAe,IAAf,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,cAAT,CAAyBC,OAAzB,EAAiD;AAAA,MAAfC,MAAe,uEAAN,IAAM;;AACtD,MAAI;AACFjB,IAAAA,MAAM,CAACgB,OAAD,EAAUC,MAAV,CAAN;AACA,WAAO,IAAP;AACD,GAHD,CAGE,OAAOC,CAAP,EAAU;AACV,WAAO,KAAP;AACD;AACF;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,UAAT,CAAqBC,KAArB,EAA4B;AACjC,SAAOvB,KAAK,CAAC,QA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A;;AACA,OAAO,SAASyD,cAAT,CAAyBb,UAAzB,EAAqC5C,SAArC,EAAgD;AACrD,QAAMmD,OAAO,GAAG,QAAOpD,IAAP,CAAY,YAAZ,CAAhB;;AACA,QAAMiD,SAAS,GAAGrD,IAAI,CAACwD,OAAD,EAAUP,UAAV,CAAtB;AACA,SAAOE,MAAM,CAACK,OAAD,EAAUH,SAAV,EAAqBhD,SAArB,CAAb;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 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 * Crypto module\n * @module @aeternity/aepp-sdk/es/utils/crypto\n * @example import { Crypto } from '@aeternity/aepp-sdk'\n */\n\nimport nacl from 'tweetnacl'\nimport aesjs from 'aes-js'\nimport shajs from 'sha.js'\n\nimport { str2buf } from './bytes'\nimport { encode, decode } from '../tx/builder/helpers'\nimport { hash } from './crypto-ts'\nimport { NotImplementedError } from './errors'\n\nexport * from './crypto-ts'\n\nconst Ecb = aesjs.ModeOfOperation.ecb\n\n/**\n * Generate address from secret key\n * @rtype (secret: String) => tx: Promise[String]\n * @param {String} secret - Private key\n * @return {String} Public key\n */\nexport function getAddressFromPriv (secret) {\n const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))\n const publicBuffer = Buffer.from(keys.publicKey)\n return encode(publicBuffer, 'ak')\n}\n\n/**\n * Check if address is valid\n * @rtype (input: String) => valid: Boolean\n * @param {String} address - Address\n * @param {String} prefix Transaction prefix. Default: 'ak'\n * @return {Boolean} valid\n */\nexport function isAddressValid (address, prefix = 'ak') {\n try {\n decode(address, prefix)\n return true\n } catch (e) {\n return false\n }\n}\n\n/**\n * Calculate SHA256 hash of `input`\n * @rtype (input: String) => hash: String\n * @param {String} input - Data to hash\n * @return {String} Hash\n */\nexport function sha256hash (input) {\n return shajs('sha256').update(input).digest()\n}\n\n/**\n * Generate a random salt (positive integer)\n * @rtype () => salt: Number\n * @return {Number} random salt\n */\nexport function salt () {\n return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))\n}\n\n/**\n * Converts a positive integer to the smallest possible\n * representation in a binary digit representation\n * @rtype (value: Number) => Buffer\n * @param {Number} value - Value to encode\n * @return {Buffer} - Encoded data\n */\nexport function encodeUnsigned (value) {\n const binary = Buffer.allocUnsafe(4)\n binary.writeUInt32BE(value)\n return binary.slice(binary.findIndex(i => i !== 0))\n}\n\n// Todo Duplicated in tx builder. remove\n/**\n * Compute contract address\n * @rtype (owner: String, nonce: Number) => String\n * @param {String} owner - Address of contract owner\n * @param {Number} nonce - Round when contract was created\n * @return {String} - Contract address\n */\nexport function encodeContractAddress (owner, nonce) {\n const publicKey = decode(owner, 'ak')\n const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])\n return encode(hash(binary), 'ct')\n}\n\n// KEY-PAIR HELPERS\n\n/**\n * Generate keyPair from secret key\n * @rtype (secret: Uint8Array) => KeyPair\n * @param {Uint8Array} secret - secret key\n * @return {Object} - Object with Private(privateKey) and Public(publicKey) keys\n */\nexport function generateKeyPairFromSecret (secret) {\n return nacl.sign.keyPair.fromSecretKey(secret)\n}\n\n/**\n * Generate a random ED25519 keypair\n * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}\n * @param {Boolean} raw - Whether to return raw (binary) keys\n * @return {Object} Key pair\n */\nexport function generateKeyPair (raw = false) {\n // <node>/apps/aens/test/aens_test_utils.erl\n const keyPair = nacl.sign.keyPair()\n\n const publicBuffer = Buffer.from(keyPair.publicKey)\n const secretBuffer = Buffer.from(keyPair.secretKey)\n\n if (raw) {\n return {\n publicKey: publicBuffer,\n secretKey: secretBuffer\n }\n } else {\n return {\n publicKey: encode(publicBuffer, 'ak'),\n secretKey: secretBuffer.toString('hex')\n }\n }\n}\n\n/**\n * Encrypt given data using `password`\n * @rtype (password: String, binaryData: Buffer) => Uint8Array\n * @param {String} password - Password to encrypt with\n * @param {Buffer} binaryData - Data to encrypt\n * @return {Uint8Array} Encrypted data\n */\nexport function encryptKey (password, binaryData) {\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return aesEcb.encrypt(binaryData)\n}\n\n/**\n * Decrypt given data using `password`\n * @rtype (password: String, encrypted: String) => Uint8Array\n * @param {String} password - Password to decrypt with\n * @param {String} encrypted - Data to decrypt\n * @return {Buffer} Decrypted data\n */\nexport function decryptKey (password, encrypted) {\n const encryptedBytes = Buffer.from(encrypted)\n const hashedPasswordBytes = sha256hash(password)\n const aesEcb = new Ecb(hashedPasswordBytes)\n return Buffer.from(aesEcb.decrypt(encryptedBytes))\n}\n\n// SIGNATURES\n\n/**\n * Generate signature\n * @rtype (data: String|Buffer, privateKey: Buffer) => Buffer\n * @param {String|Buffer} data - Data to sign\n * @param {String|Buffer} privateKey - Key to sign with\n * @return {Buffer|Uint8Array} Signature\n */\nexport function sign (data, privateKey) {\n return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey))\n}\n\n/**\n * Verify that signature was signed by public key\n * @rtype (str: String, signature: Buffer, publicKey: Buffer) => Boolean\n * @param {String|Buffer} str - Data to verify\n * @param {Buffer} signature - Signature to verify\n * @param {Buffer} publicKey - Key to verify against\n * @return {Boolean} Valid?\n */\nexport function verify (str, signature, publicKey) {\n return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey)\n}\n\nexport function messageToHash (message) {\n const p = Buffer.from('aeternity Signed Message:\\n', 'utf8')\n const msg = Buffer.from(message, 'utf8')\n if (msg.length >= 0xFD) throw new NotImplementedError('Message too long')\n return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))\n}\n\nexport function signMessage (message, privateKey) {\n return sign(messageToHash(message), privateKey)\n}\n\nexport function verifyMessage (str, signature, publicKey) {\n return verify(messageToHash(str), signature, publicKey)\n}\n\n/**\n * Check key pair for validity\n *\n * Sign a message, and then verifying that signature\n * @rtype (privateKey: Buffer, publicKey: Buffer) => Boolean\n * @param {Buffer} privateKey - Private key to verify\n * @param {Buffer} publicKey - Public key to verify\n * @return {Boolean} Valid?\n */\nexport function isValidKeypair (privateKey, publicKey) {\n const message = Buffer.from('TheMessage')\n const signature = sign(message, privateKey)\n return verify(message, signature, publicKey)\n}\n"],"file":"crypto.mjs"}