@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
@@ -21,7 +21,8 @@
21
21
  * @example import { AmountFormatter } from '@aeternity/aepp-sdk'
22
22
  */
23
23
  import BigNumber from 'bignumber.js';
24
- import { isBigNumber } from './bignumber';
24
+ import { isBigNumber } from "./bignumber.mjs";
25
+ import { ArgumentError, InvalidDenominationError } from "./errors.mjs";
25
26
  /**
26
27
  * AE amount formats
27
28
  */
@@ -96,9 +97,9 @@ export const formatAmount = function (value) {
96
97
  targetDenomination = AE_AMOUNT_FORMATS.AETTOS
97
98
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
98
99
  const denominations = Object.values(AE_AMOUNT_FORMATS);
99
- if (!denominations.includes(denomination)) throw new Error(`Invalid denomination: ${denomination}`);
100
- if (!denominations.includes(targetDenomination)) throw new Error(`Invalid target denomination: ${targetDenomination}`);
101
- if (!isBigNumber(value)) throw new Error(`Value ${value === null || value === void 0 ? void 0 : value.toString()} is not type of number`);
100
+ if (!denominations.includes(denomination)) throw new InvalidDenominationError(`Invalid denomination: ${denomination}`);
101
+ if (!denominations.includes(targetDenomination)) throw new InvalidDenominationError(`Invalid target denomination: ${targetDenomination}`);
102
+ if (!isBigNumber(value)) throw new ArgumentError('value', `a number`, value);
102
103
  return new BigNumber(value).shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination]).toFixed();
103
104
  };
104
105
  const prefixes = [{
@@ -117,11 +118,17 @@ const prefixes = [{
117
118
 
118
119
  const getNearestPrefix = exponent => prefixes.reduce((p, n) => Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p);
119
120
 
120
- const getLowerBoundPrefix = exponent => prefixes.find(p => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1];
121
+ const getLowerBoundPrefix = exponent => {
122
+ var _prefixes$find;
123
+
124
+ return (_prefixes$find = prefixes.find(p => p.magnitude <= exponent)) !== null && _prefixes$find !== void 0 ? _prefixes$find : prefixes[prefixes.length - 1];
125
+ };
121
126
 
122
127
  export default (rawValue => {
128
+ var _value$e;
129
+
123
130
  const value = new BigNumber(rawValue);
124
- const exp = value.e ?? 0;
131
+ const exp = (_value$e = value.e) !== null && _value$e !== void 0 ? _value$e : 0;
125
132
  const {
126
133
  name,
127
134
  magnitude
@@ -129,4 +136,4 @@ export default (rawValue => {
129
136
  const v = value.shiftedBy(-magnitude).precision(9 + Math.min(exp - magnitude, 0)).toFixed();
130
137
  return `${v}${name !== '' ? ' ' : ''}${name}`;
131
138
  });
132
- //# sourceMappingURL=amount-formatter.js.map
139
+ //# sourceMappingURL=amount-formatter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/amount-formatter.ts"],"names":["BigNumber","isBigNumber","ArgumentError","InvalidDenominationError","AE_AMOUNT_FORMATS","AE","MILI_AE","MICRO_AE","NANO_AE","PICO_AE","FEMTO_AE","AETTOS","DENOMINATION_MAGNITUDE","toAe","value","denomination","formatAmount","targetDenomination","toAettos","denominations","Object","values","includes","shiftedBy","toFixed","prefixes","name","magnitude","getNearestPrefix","exponent","reduce","p","n","Math","abs","getLowerBoundPrefix","find","length","rawValue","exp","e","v","precision","min"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,W;SACAC,a,EAAeC,wB;AAExB;AACA;AACA;;AACA,OAAO,MAAMC,iBAAiB,GAAG;AAC/BC,EAAAA,EAAE,EAAE,IAD2B;AAE/BC,EAAAA,OAAO,EAAE,QAFsB;AAG/BC,EAAAA,QAAQ,EAAE,SAHqB;AAI/BC,EAAAA,OAAO,EAAE,QAJsB;AAK/BC,EAAAA,OAAO,EAAE,QALsB;AAM/BC,EAAAA,QAAQ,EAAE,SANqB;AAO/BC,EAAAA,MAAM,EAAE;AAPuB,CAA1B;AAUP;AACA;AACA;;AACA,OAAO,MAAMC,sBAAsB,GAAG;AACpC,GAACR,iBAAiB,CAACC,EAAnB,GAAwB,CADY;AAEpC,GAACD,iBAAiB,CAACE,OAAnB,GAA6B,CAAC,CAFM;AAGpC,GAACF,iBAAiB,CAACG,QAAnB,GAA8B,CAAC,CAHK;AAIpC,GAACH,iBAAiB,CAACI,OAAnB,GAA6B,CAAC,CAJM;AAKpC,GAACJ,iBAAiB,CAACK,OAAnB,GAA6B,CAAC,EALM;AAMpC,GAACL,iBAAiB,CAACM,QAAnB,GAA8B,CAAC,EANK;AAOpC,GAACN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QC,IAAAA;AAAR,MAAsB,CAACY,GAAG,GAAG,CAAN,GAAUX,gBAAV,GAA6BO,mBAA9B,EAAmDI,GAAnD,CAA5B;AACA,QAAME,CAAC,GAAG3B,KAAK,CACZS,SADO,CACG,CAACI,SADJ,EAEPe,SAFO,CAEG,IAAIT,IAAI,CAACU,GAAL,CAASJ,GAAG,GAAGZ,SAAf,EAA0B,CAA1B,CAFP,EAGPH,OAHO,EAAV;AAIA,SAAQ,GAAEiB,CAAE,GAAEf,IAAI,KAAK,EAAT,GAAc,GAAd,GAAoB,EAAG,GAAEA,IAAK,EAA5C;AACD,CAVD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 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 * Amount Formatter\n * @module @aeternity/aepp-sdk/es/utils/amount-formatter\n * @example import { AmountFormatter } from '@aeternity/aepp-sdk'\n */\nimport BigNumber from 'bignumber.js'\nimport { isBigNumber } from './bignumber'\nimport { ArgumentError, InvalidDenominationError } from './errors'\n\n/**\n * AE amount formats\n */\nexport const AE_AMOUNT_FORMATS = {\n AE: 'ae',\n MILI_AE: 'miliAE',\n MICRO_AE: 'microAE',\n NANO_AE: 'nanoAE',\n PICO_AE: 'picoAE',\n FEMTO_AE: 'femtoAE',\n AETTOS: 'aettos'\n}\n\n/**\n * DENOMINATION_MAGNITUDE\n */\nexport const DENOMINATION_MAGNITUDE = {\n [AE_AMOUNT_FORMATS.AE]: 0,\n [AE_AMOUNT_FORMATS.MILI_AE]: -3,\n [AE_AMOUNT_FORMATS.MICRO_AE]: -6,\n [AE_AMOUNT_FORMATS.NANO_AE]: -9,\n [AE_AMOUNT_FORMATS.PICO_AE]: -12,\n [AE_AMOUNT_FORMATS.FEMTO_AE]: -15,\n [AE_AMOUNT_FORMATS.AETTOS]: -18\n}\n\n/**\n * Convert amount to AE\n * @param {String|Number|BigNumber} value amount to convert\n * @param {Object} [options={}] options\n * @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']\n * @return {String}\n */\nexport const toAe = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS } = {}\n): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE })\n\n/**\n * Convert amount to aettos\n * @param {String|Number|BigNumber} value amount to convert\n * @param {Object} [options={}] options\n * @param {String} [options.denomination='ae'] denomination of amount, can be ['ae', 'aettos']\n * @return {String}\n */\nexport const toAettos = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AE } = {}\n): string => formatAmount(value, { denomination })\n\n/**\n * Convert amount from one to other denomination\n * @param {String|Number|BigNumber} value amount to convert\n * @param {Object} [options={}] options\n * @param {String} [options.denomination='aettos'] denomination of amount, can be ['ae', 'aettos']\n * @param {String} [options.targetDenomination='aettos'] target denomination, can be ['ae', 'aettos']\n * @return {String}\n */\nexport const formatAmount = (\n value: string | number | BigNumber,\n { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS } = {}\n): string => {\n const denominations = Object.values(AE_AMOUNT_FORMATS)\n if (!denominations.includes(denomination)) throw new InvalidDenominationError(`Invalid denomination: ${denomination}`)\n if (!denominations.includes(targetDenomination)) throw new InvalidDenominationError(`Invalid target denomination: ${targetDenomination}`)\n if (!isBigNumber(value)) throw new ArgumentError('value', `a number`, value)\n\n return new BigNumber(value)\n .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])\n .toFixed()\n}\n\ninterface Prefix {\n name: string\n magnitude: number\n}\n\nconst prefixes: Prefix[] = [\n { name: 'exa', magnitude: 18 },\n { name: 'giga', magnitude: 9 },\n { name: '', magnitude: 0 },\n { name: 'pico', magnitude: -12 }\n]\n\nconst getNearestPrefix = (exponent: number): Prefix => prefixes.reduce((p, n) => (\n Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p))\n\nconst getLowerBoundPrefix = (exponent: number): Prefix => prefixes\n .find(p => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1]\n\nexport default (rawValue: string | number | BigNumber): string => {\n const value: BigNumber = new BigNumber(rawValue)\n\n const exp = value.e ?? 0\n const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp)\n const v = value\n .shiftedBy(-magnitude)\n .precision(9 + Math.min(exp - magnitude, 0))\n .toFixed()\n return `${v}${name !== '' ? ' ' : ''}${name}`\n}\n"],"file":"amount-formatter.mjs"}
@@ -1,12 +1,6 @@
1
- import _path from "ramda/src/path";
2
- import _flatten from "ramda/src/flatten";
3
- import _identical from "ramda/src/identical";
4
- import _uniqWith from "ramda/src/uniqWith";
5
- import _without from "ramda/src/without";
6
-
7
1
  /*
8
2
  * ISC License (ISC)
9
- * Copyright (c) 2018 aeternity developers
3
+ * Copyright (c) 2022 aeternity developers
10
4
  *
11
5
  * Permission to use, copy, modify, and/or distribute this software for any
12
6
  * purpose with or without fee is hereby granted, provided that the above
@@ -45,7 +39,7 @@ function asyncInit() {
45
39
  }, instance);
46
40
  }
47
41
 
48
- const AsyncInit = stampit({
42
+ export default stampit({
49
43
  deepConf: {
50
44
  AsyncInit: {
51
45
  initializers: []
@@ -58,10 +52,13 @@ const AsyncInit = stampit({
58
52
  composables
59
53
  } = _ref;
60
54
  const conf = stamp.compose.deepConfiguration.AsyncInit;
61
- conf.initializers = _without([asyncInit], _uniqWith(_identical, _flatten(composables.map(c => _path(['compose', 'deepConfiguration', 'AsyncInit', 'initializers'], c) || (c.compose || c).initializers || []))));
55
+ conf.initializers = composables.map(c => {
56
+ var _c$compose, _c$compose$deepConfig, _c$compose$deepConfig2;
57
+
58
+ return (c === null || c === void 0 ? void 0 : (_c$compose = c.compose) === null || _c$compose === void 0 ? void 0 : (_c$compose$deepConfig = _c$compose.deepConfiguration) === null || _c$compose$deepConfig === void 0 ? void 0 : (_c$compose$deepConfig2 = _c$compose$deepConfig.AsyncInit) === null || _c$compose$deepConfig2 === void 0 ? void 0 : _c$compose$deepConfig2.initializers) || (c.compose || c).initializers || [];
59
+ }).flat(Infinity).filter((f, idx, arr) => !arr.slice(0, idx).includes(f)).filter(f => f !== asyncInit);
62
60
  stamp.compose.initializers = [asyncInit];
63
61
  }
64
62
 
65
63
  });
66
- export default AsyncInit;
67
- //# sourceMappingURL=async-init.js.map
64
+ //# sourceMappingURL=async-init.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/async-init.js"],"names":["stampit","asyncInit","options","stamp","args","instance","compose","deepConfiguration","AsyncInit","initializers","reduce","init","Promise","resolve","ret","call","undefined","deepConf","composers","composables","conf","map","c","flat","Infinity","filter","f","idx","arr","slice","includes"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;;AAEA,SAASC,SAAT,GAA6D;AAAA,MAAzCC,OAAyC,uEAA/B,EAA+B;AAAA,MAA3B;AAAEC,IAAAA,KAAF;AAASC,IAAAA,IAAT;AAAeC,IAAAA;AAAf,GAA2B;AAC3D,SAAOF,KAAK,CAACG,OAAN,CAAcC,iBAAd,C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CAAV,EAAaF,GAAb,EAAkBG,QAAlB,CAA2BJ,CAA3B,CANR,EAOjBD,MAPiB,CAOVC,CAAC,IAAIA,CAAC,KAAKzB,SAPD,CAApB;AAQAE,IAAAA,KAAK,CAACG,OAAN,CAAcG,YAAd,GAA6B,CAACR,SAAD,CAA7B;AACD;;AAboB,CAAD,CAAtB","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2022 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 stampit from '@stamp/it'\n\nfunction asyncInit (options = {}, { stamp, args, instance }) {\n return stamp.compose.deepConfiguration.AsyncInit.initializers.reduce(async (instance, init) => {\n instance = await Promise.resolve(instance)\n if (typeof init === 'function') {\n const ret = await Promise.resolve(init.call(instance, options, { stamp, args, instance }))\n return ret === undefined ? instance : ret\n }\n return instance\n }, instance)\n}\n\nexport default stampit({\n deepConf: { AsyncInit: { initializers: [] } },\n composers ({ stamp, composables }) {\n const conf = stamp.compose.deepConfiguration.AsyncInit\n conf.initializers = composables\n .map(c =>\n c?.compose?.deepConfiguration?.AsyncInit?.initializers ||\n (c.compose || c).initializers ||\n [])\n .flat(Infinity)\n .filter((f, idx, arr) => !arr.slice(0, idx).includes(f))\n .filter(f => f !== asyncInit)\n stamp.compose.initializers = [asyncInit]\n }\n})\n"],"file":"async-init.mjs"}
@@ -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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,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,15 +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
- import ed2curve from 'ed2curve';
25
28
  import nacl from 'tweetnacl';
26
29
  import aesjs from 'aes-js';
27
- import shajs from 'sha.js';
28
- import { str2buf, toBytes } from './bytes';
29
- import { decode } from '../tx/builder/helpers';
30
- import { hash } from './crypto-ts';
31
- export * from './crypto-ts';
30
+ import { str2buf } from "./bytes.mjs";
31
+ import { encode, decode, sha256hash } from "./encoder.mjs";
32
+ import { hash } from "./crypto-ts.mjs";
33
+ import { NotImplementedError } from "./errors.mjs";
34
+ export * from "./crypto-ts.mjs";
35
+ export { sha256hash };
32
36
  const Ecb = aesjs.ModeOfOperation.ecb;
33
37
  /**
34
38
  * Generate address from secret key
@@ -39,8 +43,10 @@ const Ecb = aesjs.ModeOfOperation.ecb;
39
43
 
40
44
  export function getAddressFromPriv(secret) {
41
45
  const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret));
42
- const publicBuffer = Buffer.from(keys.publicKey);
43
- return `ak_${encodeBase58Check(publicBuffer)}`;
46
+
47
+ const publicBuffer = _Buffer.from(keys.publicKey);
48
+
49
+ return encode(publicBuffer, 'ak');
44
50
  }
45
51
  /**
46
52
  * Check if address is valid
@@ -52,34 +58,14 @@ export function getAddressFromPriv(secret) {
52
58
 
53
59
  export function isAddressValid(address) {
54
60
  let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'ak';
55
- if (typeof address !== 'string') return false;
56
61
 
57
62
  try {
58
- return decode(address, prefix).length === 32;
63
+ decode(address, prefix);
64
+ return true;
59
65
  } catch (e) {
60
66
  return false;
61
67
  }
62
68
  }
63
- /**
64
- * Parse decimal address and return base58Check encoded address with prefix 'ak'
65
- * @rtype (input: String) => address: String
66
- * @param {String} decimalAddress - Address
67
- * @return {String} address
68
- */
69
-
70
- export function addressFromDecimal(decimalAddress) {
71
- return aeEncodeKey(toBytes(decimalAddress, true));
72
- }
73
- /**
74
- * Calculate SHA256 hash of `input`
75
- * @rtype (input: String) => hash: String
76
- * @param {String} input - Data to hash
77
- * @return {String} Hash
78
- */
79
-
80
- export function sha256hash(input) {
81
- return shajs('sha256').update(input).digest();
82
- }
83
69
  /**
84
70
  * Generate a random salt (positive integer)
85
71
  * @rtype () => salt: Number
@@ -89,64 +75,6 @@ export function sha256hash(input) {
89
75
  export function salt() {
90
76
  return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER));
91
77
  }
92
- /**
93
- * Base64check encode given `input`
94
- * @rtype (input: String|buffer) => Buffer
95
- * @param {String} input - Data to encode
96
- * @return {Buffer} Base64check encoded data
97
- */
98
-
99
- export function encodeBase64Check(input) {
100
- const buffer = Buffer.from(input);
101
- const checksum = checkSumFn(input);
102
- const payloadWithChecksum = Buffer.concat([buffer, checksum], buffer.length + 4);
103
- return payloadWithChecksum.toString('base64');
104
- }
105
- export function checkSumFn(payload) {
106
- return sha256hash(sha256hash(payload)).slice(0, 4);
107
- }
108
-
109
- function decodeRaw(buffer) {
110
- const payload = buffer.slice(0, -4);
111
- const checksum = buffer.slice(-4);
112
- const newChecksum = checkSumFn(payload);
113
- if (!checksum.equals(newChecksum)) return;
114
- return payload;
115
- }
116
- /**
117
- * Base64check decode given `str`
118
- * @rtype (str: String) => Buffer
119
- * @param {String} str - Data to decode
120
- * @return {Buffer} Base64check decoded data
121
- */
122
-
123
-
124
- export function decodeBase64Check(str) {
125
- const buffer = Buffer.from(str, 'base64');
126
- const payload = decodeRaw(buffer);
127
- if (!payload) throw new Error('Invalid checksum');
128
- return Buffer.from(payload);
129
- }
130
- /**
131
- * Base58 encode given `input`
132
- * @rtype (input: String) => String
133
- * @param {String|Buffer} input - Data to encode
134
- * @return {String} Base58 encoded data
135
- */
136
-
137
- export function encodeBase58Check(input) {
138
- return bs58check.encode(Buffer.from(input));
139
- }
140
- /**
141
- * Base58 decode given `str`
142
- * @rtype (str: String) => Buffer
143
- * @param {String} str - Data to decode
144
- * @return {Buffer} Base58 decoded data
145
- */
146
-
147
- export function decodeBase58Check(str) {
148
- return bs58check.decode(str);
149
- }
150
78
  /**
151
79
  * Converts a positive integer to the smallest possible
152
80
  * representation in a binary digit representation
@@ -156,7 +84,8 @@ export function decodeBase58Check(str) {
156
84
  */
157
85
 
158
86
  export function encodeUnsigned(value) {
159
- const binary = Buffer.allocUnsafe(4);
87
+ const binary = _Buffer.allocUnsafe(4);
88
+
160
89
  binary.writeUInt32BE(value);
161
90
  return binary.slice(binary.findIndex(i => i !== 0));
162
91
  } // Todo Duplicated in tx builder. remove
@@ -171,8 +100,10 @@ export function encodeUnsigned(value) {
171
100
 
172
101
  export function encodeContractAddress(owner, nonce) {
173
102
  const publicKey = decode(owner, 'ak');
174
- const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)]);
175
- return `ct_${encodeBase58Check(hash(binary))}`;
103
+
104
+ const binary = _Buffer.concat([publicKey, encodeUnsigned(nonce)]);
105
+
106
+ return encode(hash(binary), 'ct');
176
107
  } // KEY-PAIR HELPERS
177
108
 
178
109
  /**
@@ -187,7 +118,7 @@ export function generateKeyPairFromSecret(secret) {
187
118
  }
188
119
  /**
189
120
  * Generate a random ED25519 keypair
190
- * @rtype (raw: Boolean) => {publicKey: String, secretKey: String} | {publicKey: Buffer, secretKey: Buffer}
121
+ * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}
191
122
  * @param {Boolean} raw - Whether to return raw (binary) keys
192
123
  * @return {Object} Key pair
193
124
  */
@@ -196,8 +127,10 @@ export function generateKeyPair() {
196
127
  let raw = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
197
128
  // <node>/apps/aens/test/aens_test_utils.erl
198
129
  const keyPair = nacl.sign.keyPair();
199
- const publicBuffer = Buffer.from(keyPair.publicKey);
200
- const secretBuffer = Buffer.from(keyPair.secretKey);
130
+
131
+ const publicBuffer = _Buffer.from(keyPair.publicKey);
132
+
133
+ const secretBuffer = _Buffer.from(keyPair.secretKey);
201
134
 
202
135
  if (raw) {
203
136
  return {
@@ -206,7 +139,7 @@ export function generateKeyPair() {
206
139
  };
207
140
  } else {
208
141
  return {
209
- publicKey: `ak_${encodeBase58Check(publicBuffer)}`,
142
+ publicKey: encode(publicBuffer, 'ak'),
210
143
  secretKey: secretBuffer.toString('hex')
211
144
  };
212
145
  }
@@ -233,10 +166,11 @@ export function encryptKey(password, binaryData) {
233
166
  */
234
167
 
235
168
  export function decryptKey(password, encrypted) {
236
- const encryptedBytes = Buffer.from(encrypted);
169
+ const encryptedBytes = _Buffer.from(encrypted);
170
+
237
171
  const hashedPasswordBytes = sha256hash(password);
238
172
  const aesEcb = new Ecb(hashedPasswordBytes);
239
- return Buffer.from(aesEcb.decrypt(encryptedBytes));
173
+ return _Buffer.from(aesEcb.decrypt(encryptedBytes));
240
174
  } // SIGNATURES
241
175
 
242
176
  /**
@@ -248,7 +182,7 @@ export function decryptKey(password, encrypted) {
248
182
  */
249
183
 
250
184
  export function sign(data, privateKey) {
251
- return nacl.sign.detached(Buffer.from(data), Buffer.from(privateKey));
185
+ return nacl.sign.detached(_Buffer.from(data), _Buffer.from(privateKey));
252
186
  }
253
187
  /**
254
188
  * Verify that signature was signed by public key
@@ -263,10 +197,12 @@ export function verify(str, signature, publicKey) {
263
197
  return nacl.sign.detached.verify(new Uint8Array(str), signature, publicKey);
264
198
  }
265
199
  export function messageToHash(message) {
266
- const p = Buffer.from('aeternity Signed Message:\n', 'utf8');
267
- const msg = Buffer.from(message, 'utf8');
268
- if (msg.length >= 0xFD) throw new Error('message too long');
269
- return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]));
200
+ const p = _Buffer.from('aeternity Signed Message:\n', 'utf8');
201
+
202
+ const msg = _Buffer.from(message, 'utf8');
203
+
204
+ if (msg.length >= 0xFD) throw new NotImplementedError('Message too long');
205
+ return hash(_Buffer.concat([_Buffer.from([p.length]), p, _Buffer.from([msg.length]), msg]));
270
206
  }
271
207
  export function signMessage(message, privateKey) {
272
208
  return sign(messageToHash(message), privateKey);
@@ -274,19 +210,6 @@ export function signMessage(message, privateKey) {
274
210
  export function verifyMessage(str, signature, publicKey) {
275
211
  return verify(messageToHash(str), signature, publicKey);
276
212
  }
277
- /**
278
- * æternity readable public keys are the base58-encoded public key, prepended
279
- * with 'ak_'
280
- * @rtype (binaryKey: Buffer) => String
281
- * @param {Buffer} binaryKey - Key to encode
282
- * @return {String} Encoded key
283
- */
284
-
285
- export function aeEncodeKey(binaryKey) {
286
- const publicKeyBuffer = Buffer.from(binaryKey, 'hex');
287
- const pubKeyAddress = encodeBase58Check(publicKeyBuffer);
288
- return `ak_${pubKeyAddress}`;
289
- }
290
213
  /**
291
214
  * Check key pair for validity
292
215
  *
@@ -298,46 +221,9 @@ export function aeEncodeKey(binaryKey) {
298
221
  */
299
222
 
300
223
  export function isValidKeypair(privateKey, publicKey) {
301
- const message = Buffer.from('TheMessage');
224
+ const message = _Buffer.from('TheMessage');
225
+
302
226
  const signature = sign(message, privateKey);
303
227
  return verify(message, signature, publicKey);
304
228
  }
305
- /**
306
- * This function encrypts a message using base58check encoded and 'ak' prefixed
307
- * publicKey such that only the corresponding secretKey will
308
- * be able to decrypt
309
- * @rtype (msg: String, publicKey: String) => Object
310
- * @param {Buffer} msg - Data to encode
311
- * @param {String} publicKey - Public key
312
- * @return {Object}
313
- */
314
-
315
- export function encryptData(msg, publicKey) {
316
- const ephemeralKeyPair = nacl.box.keyPair();
317
- const pubKeyUInt8Array = decode(publicKey, 'ak');
318
- const nonce = nacl.randomBytes(nacl.box.nonceLength);
319
- const encryptedMessage = nacl.box(Buffer.from(msg), nonce, ed2curve.convertPublicKey(pubKeyUInt8Array), ephemeralKeyPair.secretKey);
320
- return {
321
- ciphertext: Buffer.from(encryptedMessage).toString('hex'),
322
- ephemPubKey: Buffer.from(ephemeralKeyPair.publicKey).toString('hex'),
323
- nonce: Buffer.from(nonce).toString('hex'),
324
- version: 'x25519-xsalsa20-poly1305'
325
- };
326
- }
327
- /**
328
- * This function decrypt a message using secret key
329
- * @rtype (secretKey: String, encryptedData: Object) => Buffer|null
330
- * @param {String} secretKey - Secret key
331
- * @param {Object} encryptedData - Encrypted data
332
- * @return {Buffer|null}
333
- */
334
-
335
- export function decryptData(secretKey, encryptedData) {
336
- const receiverSecretKeyUint8Array = ed2curve.convertSecretKey(Buffer.from(secretKey, 'hex'));
337
- const nonce = Buffer.from(encryptedData.nonce, 'hex');
338
- const ciphertext = Buffer.from(encryptedData.ciphertext, 'hex');
339
- const ephemPubKey = Buffer.from(encryptedData.ephemPubKey, 'hex');
340
- const decrypted = nacl.box.open(ciphertext, nonce, ephemPubKey, receiverSecretKeyUint8Array);
341
- return decrypted ? Buffer.from(decrypted) : decrypted;
342
- }
343
- //# sourceMappingURL=crypto.js.map
229
+ //# sourceMappingURL=crypto.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/crypto.js"],"names":["nacl","aesjs","str2buf","encode","decode","sha256hash","hash","NotImplementedError","Ecb","ModeOfOperation","ecb","getAddressFromPriv","secret","keys","sign","keyPair","fromSecretKey","publicBuffer","from","publicKey","isAddressValid","address","prefix","e","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;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AG,QAAOjD,IAAP,CAAY,6BAAZ,EAA2C,MAA3C,CAAV;;AACA,QAAMkD,GAAG,GAAG,QAAOlD,IAAP,CAAYgD,OAAZ,EAAqB,MAArB,CAAZ;;AACA,MAAIE,GAAG,CAACC,MAAJ,IAAc,IAAlB,EAAwB,MAAM,IAAI9D,mBAAJ,CAAwB,kBAAxB,CAAN;AACxB,SAAOD,IAAI,CAAC,QAAOmC,MAAP,CAAc,CAAC,QAAOvB,IAAP,CAAY,CAACiD,CAAC,CAACE,MAAH,CAAZ,CAAD,EAA0BF,CAA1B,EAA6B,QAAOjD,IAAP,CAAY,CAACkD,GAAG,CAACC,MAAL,CAAZ,CAA7B,EAAwDD,GAAxD,CAAd,CAAD,CAAX;AACD;AAED,OAAO,SAASE,WAAT,CAAsBJ,OAAtB,EAA+BP,UAA/B,EAA2C;AAChD,SAAO7C,IAAI,CAACmD,aAAa,CAACC,OAAD,CAAd,EAAyBP,UAAzB,CAAX;AACD;AAED,OAAO,SAASY,aAAT,CAAwBT,GAAxB,EAA6BC,SAA7B,EAAwC5C,SAAxC,EAAmD;AACxD,SAAO0C,MAAM,CAACI,aAAa,CAACH,GAAD,CAAd,EAAqBC,SAArB,EAAgC5C,SAAhC,CAAb;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASqD,cAAT,CAAyBb,UAAzB,EAAqCxC,SAArC,EAAgD;AACrD,QAAM+C,OAAO,GAAG,QAAOhD,IAAP,CAAY,YAAZ,CAAhB;;AACA,QAAM6C,SAAS,GAAGjD,IAAI,CAACoD,OAAD,EAAUP,UAAV,CAAtB;AACA,SAAOE,MAAM,CAACK,OAAD,EAAUH,SAAV,EAAqB5C,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'\n\nimport { str2buf } from './bytes'\nimport { encode, decode, sha256hash } from './encoder'\nimport { hash } from './crypto-ts'\nimport { NotImplementedError } from './errors'\n\nexport * from './crypto-ts'\nexport { sha256hash }\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 * 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"}