@aeternity/aepp-sdk 11.0.1 → 12.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 (376) hide show
  1. package/LICENSE +1 -1
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +12 -19
  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/AeSdk.d.ts +37 -0
  10. package/es/AeSdk.mjs +81 -0
  11. package/es/AeSdk.mjs.map +1 -0
  12. package/es/AeSdkAepp.d.ts +69 -0
  13. package/es/AeSdkAepp.mjs +175 -0
  14. package/es/AeSdkAepp.mjs.map +1 -0
  15. package/es/AeSdkBase.d.ts +212 -0
  16. package/es/AeSdkBase.mjs +310 -0
  17. package/es/AeSdkBase.mjs.map +1 -0
  18. package/es/AeSdkWallet.d.ts +103 -0
  19. package/es/AeSdkWallet.mjs +322 -0
  20. package/es/AeSdkWallet.mjs.map +1 -0
  21. package/es/Node.d.ts +44 -0
  22. package/es/Node.mjs +141 -0
  23. package/es/Node.mjs.map +1 -0
  24. package/es/account/Base.d.ts +65 -0
  25. package/es/account/Base.mjs +123 -0
  26. package/es/account/Base.mjs.map +1 -0
  27. package/es/account/Memory.d.ts +25 -0
  28. package/es/account/Memory.mjs +81 -0
  29. package/es/account/Memory.mjs.map +1 -0
  30. package/es/account/Rpc.d.ts +27 -0
  31. package/es/account/Rpc.mjs +79 -0
  32. package/es/account/Rpc.mjs.map +1 -0
  33. package/es/aens.d.ts +209 -0
  34. package/es/aens.mjs +332 -0
  35. package/es/aens.mjs.map +1 -0
  36. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  37. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  46. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  47. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  51. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  52. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  54. package/es/aepp-wallet-communication/schema.d.ts +90 -46
  55. package/es/aepp-wallet-communication/schema.mjs +214 -0
  56. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  57. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  58. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  60. package/es/apis/compiler/compiler.d.ts +92 -0
  61. package/es/apis/compiler/compiler.mjs +576 -0
  62. package/es/apis/compiler/compiler.mjs.map +1 -0
  63. package/es/apis/compiler/index.d.ts +2 -0
  64. package/es/apis/compiler/index.mjs +3 -0
  65. package/es/apis/compiler/index.mjs.map +1 -0
  66. package/es/apis/compiler/models/index.d.ts +248 -0
  67. package/es/apis/compiler/models/index.mjs +48 -0
  68. package/es/apis/compiler/models/index.mjs.map +1 -0
  69. package/es/apis/compiler/models/mappers.d.ts +23 -0
  70. package/es/apis/compiler/models/mappers.mjs +585 -0
  71. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  72. package/es/apis/compiler/models/parameters.d.ts +13 -0
  73. package/es/apis/compiler/models/parameters.mjs +71 -0
  74. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  75. package/es/apis/node/index.d.ts +2 -0
  76. package/es/apis/node/index.mjs +3 -0
  77. package/es/apis/node/index.mjs.map +1 -0
  78. package/es/apis/node/models/index.d.ts +1061 -0
  79. package/es/apis/node/models/index.mjs +2 -0
  80. package/es/apis/node/models/index.mjs.map +1 -0
  81. package/es/apis/node/models/mappers.d.ts +95 -0
  82. package/es/apis/node/models/mappers.mjs +4164 -0
  83. package/es/apis/node/models/mappers.mjs.map +1 -0
  84. package/es/apis/node/models/parameters.d.ts +17 -0
  85. package/es/apis/node/models/parameters.mjs +165 -0
  86. package/es/apis/node/models/parameters.mjs.map +1 -0
  87. package/es/apis/node/node.d.ts +215 -0
  88. package/es/apis/node/node.mjs +1165 -0
  89. package/es/apis/node/node.mjs.map +1 -0
  90. package/es/chain.d.ts +220 -0
  91. package/es/chain.mjs +524 -0
  92. package/es/chain.mjs.map +1 -0
  93. package/es/channel/handlers.d.ts +34 -0
  94. package/es/channel/handlers.mjs +147 -112
  95. package/es/channel/handlers.mjs.map +1 -1
  96. package/es/channel/index.d.ts +634 -0
  97. package/es/channel/index.mjs +898 -900
  98. package/es/channel/index.mjs.map +1 -1
  99. package/es/channel/internal.d.ts +100 -0
  100. package/es/channel/internal.mjs +97 -51
  101. package/es/channel/internal.mjs.map +1 -1
  102. package/es/contract/Compiler.d.ts +17 -0
  103. package/es/contract/Compiler.mjs +67 -0
  104. package/es/contract/Compiler.mjs.map +1 -0
  105. package/es/contract/aci.d.ts +125 -0
  106. package/es/contract/aci.mjs +199 -180
  107. package/es/contract/aci.mjs.map +1 -1
  108. package/es/contract/ga.d.ts +68 -0
  109. package/es/contract/ga.mjs +190 -0
  110. package/es/contract/ga.mjs.map +1 -0
  111. package/es/contract/methods.d.ts +68 -0
  112. package/es/contract/methods.mjs +101 -0
  113. package/es/contract/methods.mjs.map +1 -0
  114. package/es/index.d.ts +32 -0
  115. package/es/index.mjs +32 -40
  116. package/es/index.mjs.map +1 -1
  117. package/es/oracle.d.ts +154 -0
  118. package/es/oracle.mjs +288 -0
  119. package/es/oracle.mjs.map +1 -0
  120. package/es/spend.d.ts +61 -0
  121. package/es/spend.mjs +122 -0
  122. package/es/spend.mjs.map +1 -0
  123. package/es/tx/builder/constants.d.ts +41 -0
  124. package/es/tx/builder/constants.mjs +11 -19
  125. package/es/tx/builder/constants.mjs.map +1 -1
  126. package/es/tx/builder/field-types.d.ts +62 -0
  127. package/es/tx/builder/field-types.mjs +62 -10
  128. package/es/tx/builder/field-types.mjs.map +1 -1
  129. package/es/tx/builder/helpers.d.ts +131 -0
  130. package/es/tx/builder/helpers.mjs +71 -169
  131. package/es/tx/builder/helpers.mjs.map +1 -1
  132. package/es/tx/builder/index.d.ts +75 -0
  133. package/es/tx/builder/index.mjs +141 -323
  134. package/es/tx/builder/index.mjs.map +1 -1
  135. package/es/tx/builder/schema.d.ts +350 -0
  136. package/es/tx/builder/schema.mjs +173 -510
  137. package/es/tx/builder/schema.mjs.map +1 -1
  138. package/es/tx/index.d.ts +63 -0
  139. package/es/tx/index.mjs +171 -265
  140. package/es/tx/index.mjs.map +1 -1
  141. package/es/tx/min-fee.d.ts +20 -0
  142. package/es/tx/min-fee.mjs +148 -0
  143. package/es/tx/min-fee.mjs.map +1 -0
  144. package/es/tx/validator.d.ts +19 -0
  145. package/es/tx/validator.mjs +64 -71
  146. package/es/tx/validator.mjs.map +1 -1
  147. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  149. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  151. package/es/typings/bip32-path/index.d.mjs +2 -0
  152. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  153. package/es/typings/blakejs/index.d.mjs.map +1 -1
  154. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  155. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  156. package/es/utils/amount-formatter.d.ts +42 -0
  157. package/es/utils/amount-formatter.mjs +28 -41
  158. package/es/utils/amount-formatter.mjs.map +1 -1
  159. package/es/utils/autorest.d.ts +6 -0
  160. package/es/utils/autorest.mjs +97 -0
  161. package/es/utils/autorest.mjs.map +1 -0
  162. package/es/utils/bignumber.d.ts +13 -0
  163. package/es/utils/bignumber.mjs +10 -8
  164. package/es/utils/bignumber.mjs.map +1 -1
  165. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  166. package/es/utils/bytes.mjs +10 -14
  167. package/es/utils/bytes.mjs.map +1 -1
  168. package/es/utils/crypto.d.ts +103 -0
  169. package/es/utils/crypto.mjs +60 -68
  170. package/es/utils/crypto.mjs.map +1 -1
  171. package/es/utils/encoder.d.ts +26 -0
  172. package/es/utils/encoder.mjs +47 -51
  173. package/es/utils/encoder.mjs.map +1 -1
  174. package/es/{errors.d.ts → utils/errors.d.ts} +254 -57
  175. package/es/utils/errors.mjs +318 -125
  176. package/es/utils/errors.mjs.map +1 -1
  177. package/es/utils/hd-wallet.d.ts +34 -0
  178. package/es/utils/hd-wallet.mjs +27 -16
  179. package/es/utils/hd-wallet.mjs.map +1 -1
  180. package/es/utils/json-big.d.ts +5 -0
  181. package/es/utils/json-big.mjs +10 -14
  182. package/es/utils/json-big.mjs.map +1 -1
  183. package/es/utils/keystore.d.ts +51 -0
  184. package/es/utils/keystore.mjs +98 -193
  185. package/es/utils/keystore.mjs.map +1 -1
  186. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  187. package/es/utils/mptree.mjs +13 -14
  188. package/es/utils/mptree.mjs.map +1 -1
  189. package/es/utils/other.d.ts +14 -0
  190. package/es/utils/other.mjs +21 -36
  191. package/es/utils/other.mjs.map +1 -1
  192. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  193. package/es/utils/semver-satisfies.mjs.map +1 -1
  194. package/es/utils/string.d.ts +24 -0
  195. package/es/utils/string.mjs +8 -10
  196. package/es/utils/string.mjs.map +1 -1
  197. package/package.json +49 -39
  198. package/src/AeSdk.ts +65 -0
  199. package/src/AeSdkAepp.ts +167 -0
  200. package/src/AeSdkBase.ts +320 -0
  201. package/src/AeSdkWallet.ts +332 -0
  202. package/src/Node.ts +167 -0
  203. package/src/account/Base.ts +114 -0
  204. package/src/account/Memory.ts +83 -0
  205. package/src/account/Rpc.ts +67 -0
  206. package/src/aens.ts +391 -0
  207. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  208. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  209. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  210. package/{es/utils/crypto-ts.mjs → src/aepp-wallet-communication/connection-proxy.ts} +16 -17
  211. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  212. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  213. package/src/aepp-wallet-communication/schema.ts +181 -0
  214. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  215. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  216. package/src/apis/compiler/compiler.ts +585 -0
  217. package/src/apis/compiler/index.ts +2 -0
  218. package/src/apis/compiler/models/index.ts +301 -0
  219. package/src/apis/compiler/models/mappers.ts +583 -0
  220. package/src/apis/compiler/models/parameters.ts +93 -0
  221. package/src/apis/node/code-model-v4.yaml +10046 -0
  222. package/src/apis/node/index.ts +2 -0
  223. package/src/apis/node/models/index.ts +1253 -0
  224. package/src/apis/node/models/mappers.ts +4278 -0
  225. package/src/apis/node/models/parameters.ts +188 -0
  226. package/src/apis/node/node.ts +1299 -0
  227. package/src/chain.ts +444 -0
  228. package/src/channel/{handlers.js → handlers.ts} +220 -128
  229. package/src/channel/index.ts +991 -0
  230. package/src/channel/internal.ts +345 -0
  231. package/src/contract/Compiler.ts +66 -0
  232. package/src/contract/aci.ts +529 -0
  233. package/src/contract/ga.ts +178 -0
  234. package/src/contract/methods.ts +118 -0
  235. package/src/index.ts +51 -0
  236. package/src/oracle.ts +342 -0
  237. package/src/spend.ts +152 -0
  238. package/src/tx/builder/{constants.js → constants.ts} +12 -16
  239. package/src/tx/builder/field-types.ts +111 -0
  240. package/src/tx/builder/helpers.ts +253 -0
  241. package/src/tx/builder/index.ts +394 -0
  242. package/src/tx/builder/schema.ts +771 -0
  243. package/src/tx/index.ts +199 -0
  244. package/src/tx/min-fee.ts +136 -0
  245. package/src/tx/validator.ts +226 -0
  246. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  247. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  248. package/src/typings/bip32-path/index.d.ts +33 -0
  249. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  250. package/src/utils/amount-formatter.ts +29 -42
  251. package/src/utils/autorest.ts +90 -0
  252. package/src/utils/bignumber.ts +9 -11
  253. package/src/utils/bytes.ts +12 -14
  254. package/src/utils/crypto.ts +217 -0
  255. package/src/utils/encoder.ts +52 -55
  256. package/src/utils/errors.ts +268 -134
  257. package/src/utils/hd-wallet.ts +134 -0
  258. package/src/utils/json-big.ts +26 -0
  259. package/src/utils/keystore.ts +179 -0
  260. package/src/utils/mptree.ts +14 -14
  261. package/src/utils/other.ts +28 -43
  262. package/src/utils/string.ts +8 -10
  263. package/es/account/base.mjs +0 -179
  264. package/es/account/base.mjs.map +0 -1
  265. package/es/account/memory.mjs +0 -99
  266. package/es/account/memory.mjs.map +0 -1
  267. package/es/account/multiple.mjs +0 -179
  268. package/es/account/multiple.mjs.map +0 -1
  269. package/es/ae/aens.mjs +0 -404
  270. package/es/ae/aens.mjs.map +0 -1
  271. package/es/ae/aepp.mjs +0 -45
  272. package/es/ae/aepp.mjs.map +0 -1
  273. package/es/ae/contract.mjs +0 -159
  274. package/es/ae/contract.mjs.map +0 -1
  275. package/es/ae/index.mjs +0 -207
  276. package/es/ae/index.mjs.map +0 -1
  277. package/es/ae/oracle.mjs +0 -339
  278. package/es/ae/oracle.mjs.map +0 -1
  279. package/es/ae/universal.mjs +0 -45
  280. package/es/ae/universal.mjs.map +0 -1
  281. package/es/ae/wallet.mjs +0 -50
  282. package/es/ae/wallet.mjs.map +0 -1
  283. package/es/amount-formatter.d.ts +0 -58
  284. package/es/bignumber.d.ts +0 -18
  285. package/es/chain/index.mjs +0 -272
  286. package/es/chain/index.mjs.map +0 -1
  287. package/es/chain/node.mjs +0 -442
  288. package/es/chain/node.mjs.map +0 -1
  289. package/es/contract/compiler.mjs +0 -115
  290. package/es/contract/compiler.mjs.map +0 -1
  291. package/es/contract/ga/helpers.mjs +0 -30
  292. package/es/contract/ga/helpers.mjs.map +0 -1
  293. package/es/contract/ga/index.mjs +0 -178
  294. package/es/contract/ga/index.mjs.map +0 -1
  295. package/es/crypto-ts.d.ts +0 -9
  296. package/es/encoder.d.ts +0 -26
  297. package/es/node-pool/index.mjs +0 -188
  298. package/es/node-pool/index.mjs.map +0 -1
  299. package/es/node.mjs +0 -133
  300. package/es/node.mjs.map +0 -1
  301. package/es/other.d.ts +0 -31
  302. package/es/string.d.ts +0 -26
  303. package/es/tx/tx-object.mjs +0 -283
  304. package/es/tx/tx-object.mjs.map +0 -1
  305. package/es/tx/tx.mjs +0 -938
  306. package/es/tx/tx.mjs.map +0 -1
  307. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs +0 -132
  308. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +0 -1
  309. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +0 -183
  310. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +0 -1
  311. package/es/utils/aepp-wallet-communication/connection/index.mjs +0 -87
  312. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +0 -1
  313. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs +0 -98
  314. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +0 -1
  315. package/es/utils/aepp-wallet-communication/helpers.mjs +0 -92
  316. package/es/utils/aepp-wallet-communication/helpers.mjs.map +0 -1
  317. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +0 -375
  318. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +0 -1
  319. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +0 -275
  320. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +0 -1
  321. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +0 -541
  322. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +0 -1
  323. package/es/utils/aepp-wallet-communication/schema.mjs +0 -102
  324. package/es/utils/aepp-wallet-communication/schema.mjs.map +0 -1
  325. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +0 -110
  326. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +0 -1
  327. package/es/utils/async-init.mjs +0 -64
  328. package/es/utils/async-init.mjs.map +0 -1
  329. package/es/utils/crypto-ts.mjs.map +0 -1
  330. package/es/utils/swagger.mjs +0 -164
  331. package/es/utils/swagger.mjs.map +0 -1
  332. package/src/account/base.js +0 -153
  333. package/src/account/memory.js +0 -83
  334. package/src/account/multiple.js +0 -162
  335. package/src/ae/aens.js +0 -361
  336. package/src/ae/aepp.js +0 -45
  337. package/src/ae/contract.js +0 -148
  338. package/src/ae/index.js +0 -168
  339. package/src/ae/oracle.js +0 -311
  340. package/src/ae/universal.js +0 -47
  341. package/src/ae/wallet.js +0 -50
  342. package/src/chain/index.js +0 -269
  343. package/src/chain/node.js +0 -320
  344. package/src/channel/index.js +0 -903
  345. package/src/channel/internal.js +0 -236
  346. package/src/contract/aci.js +0 -376
  347. package/src/contract/compiler.js +0 -100
  348. package/src/contract/ga/helpers.js +0 -19
  349. package/src/contract/ga/index.js +0 -150
  350. package/src/index.js +0 -89
  351. package/src/node-pool/index.js +0 -172
  352. package/src/node.js +0 -116
  353. package/src/tx/builder/field-types.js +0 -61
  354. package/src/tx/builder/helpers.js +0 -334
  355. package/src/tx/builder/index.js +0 -465
  356. package/src/tx/builder/schema.js +0 -1100
  357. package/src/tx/index.js +0 -301
  358. package/src/tx/tx-object.js +0 -187
  359. package/src/tx/tx.js +0 -631
  360. package/src/tx/validator.js +0 -181
  361. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -119
  362. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -165
  363. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  364. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -86
  365. package/src/utils/aepp-wallet-communication/helpers.js +0 -60
  366. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -294
  367. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -232
  368. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -401
  369. package/src/utils/aepp-wallet-communication/schema.ts +0 -80
  370. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -92
  371. package/src/utils/async-init.js +0 -45
  372. package/src/utils/crypto.js +0 -219
  373. package/src/utils/hd-wallet.js +0 -100
  374. package/src/utils/json-big.js +0 -26
  375. package/src/utils/keystore.js +0 -219
  376. package/src/utils/swagger.js +0 -156
package/src/aens.ts ADDED
@@ -0,0 +1,391 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2022 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ /**
19
+ * Aens methods - routines to interact with the æternity naming system
20
+ *
21
+ * The high-level description of the naming system is
22
+ * https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol
23
+ * repository.
24
+ */
25
+
26
+ import { salt } from './utils/crypto'
27
+ import { commitmentHash, isAuctionName, Pointer } from './tx/builder/helpers'
28
+ import { CLIENT_TTL, NAME_TTL, TX_TYPE, AensName } from './tx/builder/schema'
29
+ import { ArgumentError } from './utils/errors'
30
+ import { EncodedData } from './utils/encoder'
31
+ import BigNumber from 'bignumber.js'
32
+ import { send, SendOptions } from './spend'
33
+ import { getName, height } from './chain'
34
+ import { _buildTx, BuildTxOptions } from './tx'
35
+ import { TransformNodeType } from './Node'
36
+ import { NameEntry } from './apis/node'
37
+ import AccountBase from './account/Base'
38
+
39
+ interface KeyPointers {
40
+ [key: string]: string | Buffer
41
+ }
42
+
43
+ /**
44
+ * Revoke a name
45
+ * @param name - Name hash
46
+ * @param options - Options
47
+ * @param options.onAccount - Make operation on specific account from sdk (you pass
48
+ * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
49
+ * @param options.fee - fee
50
+ * @param options.ttl - ttl
51
+ * @param options.nonce - nonce
52
+ * @returns Transaction result
53
+ * @example
54
+ * ```js
55
+ * const name = 'test.chain'
56
+ * const nameObject = await sdkInstance.aensQuery(name)
57
+ *
58
+ * await sdkInstance.aensRevoke(name, { fee, ttl , nonce })
59
+ * // or
60
+ * await nameObject.revoke({ fee, ttl, nonce })
61
+ * ```
62
+ */
63
+ export async function aensRevoke (
64
+ name: AensName, options: AensRevokeOptions
65
+ ): ReturnType<typeof send> {
66
+ const nameRevokeTx = await _buildTx(TX_TYPE.nameRevoke, {
67
+ ...options,
68
+ nameId: name,
69
+ accountId: await options.onAccount.address(options)
70
+ })
71
+ return await send(nameRevokeTx, options)
72
+ }
73
+
74
+ interface AensRevokeOptions extends
75
+ BuildTxOptions<TX_TYPE.nameRevoke, 'nameId' | 'accountId'>,
76
+ SendOptions {}
77
+
78
+ /**
79
+ * Update a name
80
+ * @param name - AENS name
81
+ * @param pointers - Map of pointer keys to corresponding addresses
82
+ * @param options - Options
83
+ * @param options.extendPointers - Get the pointers from the node and merge with provided
84
+ * ones. Pointers with the same type will be overwritten
85
+ * @param options.onAccount - Make operation on specific account from sdk (you
86
+ * pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
87
+ * @param options.fee - fee
88
+ * @param options.ttl - ttl
89
+ * @param options.nonce - nonce
90
+ * @param options.nameTtl - Name ttl represented in number of
91
+ * blocks (Max value is 50000 blocks)
92
+ * @param options.clientTtl=84600 a suggestion as to how long any
93
+ * clients should cache this information
94
+ * @throws Invalid pointer array error
95
+ * @example
96
+ * ```js
97
+ * const name = 'test.chain'
98
+ * const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']
99
+ * const nameObject = await sdkInstance.aensQuery(name)
100
+ *
101
+ * await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })
102
+ * // or
103
+ * await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })
104
+ * ```
105
+ */
106
+ export async function aensUpdate (
107
+ name: AensName, pointers: KeyPointers, { extendPointers, ...options }: AensUpdateOptions
108
+ ): ReturnType<typeof send> {
109
+ const allPointers = {
110
+ ...extendPointers === true && Object.fromEntries(
111
+ (await getName(name, options)).pointers
112
+ .map(({ key, id }: { key: string, id: string }) => [key, id])
113
+ ),
114
+ ...pointers
115
+ }
116
+
117
+ const nameUpdateTx = await _buildTx(TX_TYPE.nameUpdate, {
118
+ clientTtl: CLIENT_TTL,
119
+ nameTtl: NAME_TTL,
120
+ ...options,
121
+ nameId: name,
122
+ accountId: await options.onAccount.address(options),
123
+ pointers: Object.entries(allPointers).map(([key, id]) => ({ key, id: id.toString() }))
124
+ })
125
+
126
+ return await send(nameUpdateTx, options)
127
+ }
128
+
129
+ interface AensUpdateOptions extends
130
+ BuildTxOptions<TX_TYPE.nameUpdate, 'nameId' | 'accountId' | 'pointers' | 'clientTtl' | 'nameTtl'>,
131
+ SendOptions {
132
+ extendPointers?: boolean
133
+ clientTtl?: number
134
+ nameTtl?: number
135
+ }
136
+
137
+ /**
138
+ * Transfer a domain to another account
139
+ * @param name - AENS name
140
+ * @param account - Recipient account publick key
141
+ * @param options - Options
142
+ * @param options.onAccount - Make operation on specific account from sdk (you pass
143
+ * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
144
+ * @param options.fee - fee
145
+ * @param options.ttl - ttl
146
+ * @param options.nonce - nonce
147
+ * @returns Transaction result
148
+ * @example
149
+ * ```js
150
+ * const name = 'test.chain'
151
+ * const recipientPub = 'ak_asd23dasdas...'
152
+ * const nameObject = await sdkInstance.aensQuery(name)
153
+ *
154
+ * await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })
155
+ * // or
156
+ * await nameObject.transfer(recipientPub, { ttl, fee, nonce })
157
+ * ```
158
+ */
159
+ export async function aensTransfer (
160
+ name: AensName, account: EncodedData<'ak'>, options: AensTransferOptions
161
+ ): ReturnType<typeof send> {
162
+ const nameTransferTx = await _buildTx(TX_TYPE.nameTransfer, {
163
+ ...options,
164
+ nameId: name,
165
+ accountId: await options.onAccount.address(options),
166
+ recipientId: account
167
+ })
168
+
169
+ return await send(nameTransferTx, options)
170
+ }
171
+
172
+ interface AensTransferOptions extends
173
+ BuildTxOptions<TX_TYPE.nameTransfer, 'nameId' | 'accountId' | 'recipientId'>,
174
+ SendOptions {}
175
+
176
+ /**
177
+ * Query the AENS name info from the node
178
+ * and return the object with info and predefined functions for manipulating name
179
+ * @param name - AENS name
180
+ * @param opt - Options
181
+ * @returns
182
+ * @example
183
+ * ```js
184
+ * const nameObject = sdkInstance.aensQuery('test.chain')
185
+ * console.log(nameObject)
186
+ * {
187
+ * id, // name hash
188
+ * pointers, // array of pointers
189
+ * update, // Update name function
190
+ * extendTtl, // Extend Ttl name function
191
+ * transfer, // Transfer name function
192
+ * revoke // Revoke name function
193
+ * }
194
+ * ```
195
+ */
196
+ export async function aensQuery (
197
+ name: AensName,
198
+ opt: Parameters<typeof getName>[1] & Parameters<typeof aensUpdate>[2]
199
+ & Parameters<typeof aensTransfer>[2]
200
+ ): Promise<Readonly<
201
+ TransformNodeType<NameEntry> & {
202
+ id: EncodedData<'nm'>
203
+ owner: EncodedData<'ak'>
204
+ pointers: KeyPointers | Pointer[]
205
+ ttl: number
206
+ update: (
207
+ pointers: KeyPointers,
208
+ options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {
209
+ onAccount?: AccountBase
210
+ }
211
+ ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>
212
+ transfer: (
213
+ account: EncodedData<'ak'>,
214
+ options?: Parameters<typeof aensQuery>[1]
215
+ ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>
216
+ revoke: (options?: Omit<Parameters<typeof aensRevoke>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {
217
+ onAccount?: AccountBase
218
+ }
219
+ ) => ReturnType<typeof aensRevoke>
220
+ extendTtl: (
221
+ nameTtl: number,
222
+ options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'>
223
+ ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>
224
+ }
225
+ >> {
226
+ const nameEntry = await getName(name, opt)
227
+ return Object.freeze({
228
+ ...nameEntry,
229
+ id: nameEntry.id as EncodedData<'nm'>,
230
+ owner: nameEntry.owner as EncodedData<'ak'>,
231
+ async update (pointers, options) {
232
+ return {
233
+ ...await aensUpdate(name, pointers, { ...opt, ...options }),
234
+ ...await aensQuery(name, { ...opt, ...options })
235
+ }
236
+ },
237
+ async transfer (account, options) {
238
+ return {
239
+ ...await aensTransfer(name, account, { ...opt, ...options }),
240
+ ...await aensQuery(name, { ...opt, ...options })
241
+ }
242
+ },
243
+ async revoke (options) {
244
+ return await aensRevoke(name, { ...opt, ...options })
245
+ },
246
+ async extendTtl (nameTtl = NAME_TTL, options) {
247
+ if (nameTtl > NAME_TTL || nameTtl <= 0) {
248
+ throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl)
249
+ }
250
+
251
+ return {
252
+ ...await aensUpdate(name, {}, { ...opt, ...options, nameTtl, extendPointers: true }),
253
+ ...await aensQuery(name, { ...opt, ...options })
254
+ }
255
+ }
256
+ })
257
+ }
258
+
259
+ /**
260
+ * Claim a previously preclaimed registration. This can only be done after the
261
+ * preclaim step
262
+ * @param name - AENS name
263
+ * @param salt - Salt from pre-claim, or 0 if it's a bid
264
+ * @param options - options
265
+ * @param options.onAccount - Make operation on specific account from sdk (you pass
266
+ * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
267
+ * @param options.fee - fee
268
+ * @param options.ttl - ttl
269
+ * @param options.nonce - nonce
270
+ * @param options.nameFee - Name Fee (By default calculated by sdk)
271
+ * @returns the result of the claim
272
+ * @example
273
+ * ```js
274
+ * const name = 'test.chain'
275
+ * const salt = preclaimResult.salt // salt from pre-claim transaction
276
+ *
277
+ * await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })
278
+ * ```
279
+ */
280
+ export async function aensClaim (
281
+ name: AensName, salt: number, options: AensClaimOptions
282
+ ): Promise<AensClaimReturnType> {
283
+ const claimTx = await _buildTx(TX_TYPE.nameClaim, {
284
+ ...options,
285
+ accountId: await options.onAccount.address(options),
286
+ nameSalt: salt,
287
+ name
288
+ })
289
+
290
+ const result = await send(claimTx, options)
291
+ if (!isAuctionName(name)) {
292
+ const nameInter = result.blockHeight != null && result.blockHeight > 0
293
+ ? await aensQuery(name, options)
294
+ : {}
295
+ return Object.assign(result, nameInter)
296
+ }
297
+ return result
298
+ }
299
+
300
+ type AensClaimOptionsType = BuildTxOptions<TX_TYPE.nameClaim, 'accountId' | 'nameSalt' | 'name'>
301
+ & SendOptions & Parameters<typeof aensQuery>[1]
302
+ interface AensClaimOptions extends AensClaimOptionsType {}
303
+ interface AensClaimReturnType extends
304
+ Awaited<ReturnType<typeof send>>,
305
+ Partial<Awaited<ReturnType<typeof aensQuery>>> {}
306
+
307
+ /**
308
+ * Preclaim a name. Sends a hash of the name and a random salt to the node
309
+ * @param name - AENS name
310
+ * @param options - Options
311
+ * @param options.onAccount - Make operation on specific account from sdk (you pass
312
+ * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
313
+ * @param options.fee - fee
314
+ * @param options.ttl - ttl
315
+ * @param options.nonce - nonce
316
+ * @example
317
+ * ```js
318
+ * const name = 'test.chain'
319
+ * const salt = preclaimResult.salt // salt from pre-claim transaction
320
+ *
321
+ * await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })
322
+ * {
323
+ * ...transactionResult,
324
+ * claim, // Claim function (options={}) => claimTransactionResult
325
+ * salt,
326
+ * commitmentId
327
+ * }
328
+ * ```
329
+ */
330
+ export async function aensPreclaim (
331
+ name: AensName, options: AensPreclaimOptions
332
+ ): Promise<Readonly<
333
+ Awaited<ReturnType<typeof send>> & {
334
+ height: number
335
+ salt: number
336
+ commitmentId: string
337
+ claim: (opts?: Parameters<typeof aensClaim>[2]) => ReturnType<typeof aensClaim>
338
+ }
339
+ >> {
340
+ const _salt = salt()
341
+ const currentHeight = await height(options)
342
+ const commitmentId = commitmentHash(name, _salt)
343
+
344
+ const preclaimTx = await _buildTx(TX_TYPE.namePreClaim, {
345
+ ...options,
346
+ accountId: await options.onAccount.address(options),
347
+ commitmentId
348
+ })
349
+
350
+ return Object.freeze({
351
+ ...await send(preclaimTx, options),
352
+ height: currentHeight,
353
+ salt: _salt,
354
+ commitmentId,
355
+ async claim (opts?: Parameters<typeof aensClaim>[2]) {
356
+ return await aensClaim(name, _salt, { ...options, ...opts })
357
+ }
358
+ })
359
+ }
360
+
361
+ interface AensPreclaimOptions extends
362
+ BuildTxOptions<TX_TYPE.namePreClaim, 'accountId' | 'commitmentId'>,
363
+ SendOptions,
364
+ AensClaimOptions {}
365
+
366
+ /**
367
+ * Bid to name auction
368
+ * @param name - Domain name
369
+ * @param nameFee - Name fee (bid fee)
370
+ * @param options - Options
371
+ * @param options.onAccount - Make operation on specific account from sdk (you pass
372
+ * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)
373
+ * @param options.fee - fee
374
+ * @param options.ttl - ttl
375
+ * @param options.nonce - nonce
376
+ * @returns Transaction result
377
+ * @example
378
+ * ```js
379
+ * const name = 'test.chain'
380
+ * const bidFee = computeBidFee(name, startFee, incrementPercentage)
381
+ *
382
+ * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })
383
+ * ```
384
+ */
385
+ export async function aensBid (
386
+ name: AensName,
387
+ nameFee: number | string | BigNumber,
388
+ options: Omit<Parameters<typeof aensClaim>[2], 'nameFee'>
389
+ ): ReturnType<typeof aensClaim> {
390
+ return await aensClaim(name, 0, { ...options, nameFee })
391
+ }
@@ -0,0 +1,68 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2022 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ import { AlreadyConnectedError, NoWalletConnectedError } from '../../utils/errors'
19
+
20
+ /**
21
+ * Browser connection base interface
22
+ */
23
+ export default abstract class BrowserConnection {
24
+ debug: boolean
25
+
26
+ protected constructor ({ debug = false }: { debug?: boolean }) {
27
+ this.debug = debug
28
+ }
29
+
30
+ /**
31
+ * Connect
32
+ * @param onMessage - Message handler
33
+ * @param onDisconnect - trigger when runtime connection in closed
34
+ */
35
+ connect (
36
+ onMessage: (message: any, origin: string, source: any) => void,
37
+ onDisconnect: () => void
38
+ ): void {
39
+ if (this.isConnected()) throw new AlreadyConnectedError('You already connected')
40
+ }
41
+
42
+ /**
43
+ * Disconnect
44
+ */
45
+ disconnect (): void {
46
+ if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before')
47
+ }
48
+
49
+ /**
50
+ * Send message
51
+ */
52
+ protected receiveMessage (message: any): void {
53
+ if (this.debug) console.log('Receive message:', message)
54
+ }
55
+
56
+ /**
57
+ * Send message
58
+ */
59
+ sendMessage (message: any): void {
60
+ if (this.debug) console.log('Send message:', message)
61
+ }
62
+
63
+ /**
64
+ * Check if connected
65
+ * @returns Is connected
66
+ */
67
+ abstract isConnected (): boolean
68
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2022 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ import { Runtime } from 'webextension-polyfill'
19
+ import BrowserConnection from './Browser'
20
+
21
+ /**
22
+ * BrowserRuntimeConnection
23
+ * Handle browser runtime communication
24
+ */
25
+ export default class BrowserRuntimeConnection extends BrowserConnection {
26
+ port: Runtime.Port
27
+
28
+ constructor ({ port, ...options }: { port: Runtime.Port, debug: boolean }) {
29
+ super(options)
30
+ this.port = port
31
+ }
32
+
33
+ disconnect (): void {
34
+ super.disconnect()
35
+ this.port.disconnect()
36
+ }
37
+
38
+ connect (
39
+ onMessage: (message: any, origin: string, source: Runtime.Port) => void,
40
+ onDisconnect: () => void
41
+ ): void {
42
+ super.connect(onMessage, onDisconnect)
43
+ this.port.onMessage.addListener((message, port) => {
44
+ this.receiveMessage(message)
45
+ onMessage(message, port.name, port)
46
+ })
47
+ this.port.onDisconnect.addListener(onDisconnect)
48
+ }
49
+
50
+ sendMessage (message: any): void {
51
+ super.sendMessage(message)
52
+ this.port.postMessage(message)
53
+ }
54
+
55
+ isConnected (): boolean {
56
+ return this.port.onMessage.hasListeners()
57
+ }
58
+ }
@@ -0,0 +1,111 @@
1
+ /*
2
+ * ISC License (ISC)
3
+ * Copyright (c) 2022 aeternity developers
4
+ *
5
+ * Permission to use, copy, modify, and/or distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ * PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+
18
+ import BrowserConnection from './Browser'
19
+ import { MESSAGE_DIRECTION } from '../schema'
20
+ import { InternalError, RpcConnectionError } from '../../utils/errors'
21
+
22
+ export type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>
23
+
24
+ /**
25
+ * Browser window Post Message connector module
26
+ */
27
+ export default class BrowserWindowMessageConnection extends BrowserConnection {
28
+ origin?: string
29
+ sendDirection?: MESSAGE_DIRECTION
30
+ receiveDirection: MESSAGE_DIRECTION
31
+ listener?: (this: Window, ev: MessageEvent<any>) => void
32
+ #onDisconnect?: () => void
33
+ #target?: ImplPostMessage
34
+ #self: ImplPostMessage
35
+
36
+ /**
37
+ * @param options - Options
38
+ * @param options.target Target window for message
39
+ * @param options.self Host window for message
40
+ * @param options.origin Origin of receiver
41
+ * @param options.sendDirection Wrapping messages into additional struct
42
+ * `({ type: 'to_aepp' || 'to_waellet', data })`
43
+ * Used for handling messages between content script and page
44
+ * @param options.receiveDirection Unwrapping messages from additional struct
45
+ */
46
+ constructor ({
47
+ target,
48
+ self = window,
49
+ origin,
50
+ sendDirection,
51
+ receiveDirection = MESSAGE_DIRECTION.to_aepp,
52
+ ...options
53
+ }: {
54
+ target?: ImplPostMessage
55
+ self?: ImplPostMessage
56
+ origin?: string
57
+ sendDirection?: MESSAGE_DIRECTION
58
+ receiveDirection?: MESSAGE_DIRECTION
59
+ debug?: boolean
60
+ } = {}) {
61
+ super(options)
62
+ this.#target = target
63
+ this.#self = self
64
+ this.origin = origin
65
+ this.sendDirection = sendDirection
66
+ this.receiveDirection = receiveDirection
67
+ }
68
+
69
+ isConnected (): boolean {
70
+ return this.listener != null
71
+ }
72
+
73
+ connect (
74
+ onMessage: (message: any, origin: string, source: MessageEventSource | null) => void,
75
+ onDisconnect: () => void
76
+ ): void {
77
+ super.connect(onMessage, onDisconnect)
78
+ this.listener = (message: MessageEvent<any>) => {
79
+ if (typeof message.data !== 'object') return
80
+ if (this.origin != null && this.origin !== message.origin) return
81
+ if (this.#target != null && this.#target !== message.source) return
82
+ this.receiveMessage(message)
83
+ let { data } = message
84
+ if (data.type != null) {
85
+ if (message.data.type !== this.receiveDirection) return
86
+ data = data.data
87
+ }
88
+ onMessage(data, message.origin, message.source)
89
+ }
90
+ this.#self.addEventListener('message', this.listener)
91
+ this.#onDisconnect = onDisconnect
92
+ }
93
+
94
+ disconnect (): void {
95
+ super.disconnect()
96
+ if (this.listener == null || this.#onDisconnect == null) {
97
+ throw new InternalError('Expected to not happen, required for TS')
98
+ }
99
+ this.#self.removeEventListener('message', this.listener)
100
+ delete this.listener
101
+ this.#onDisconnect()
102
+ this.#onDisconnect = undefined
103
+ }
104
+
105
+ sendMessage (msg: any): void {
106
+ if (this.#target == null) throw new RpcConnectionError('Can\'t send messages without target')
107
+ const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg
108
+ super.sendMessage(message)
109
+ this.#target.postMessage(message, this.origin ?? '*')
110
+ }
111
+ }
@@ -1,11 +1,6 @@
1
- import _buffer from "buffer";
2
- const {
3
- Buffer: _Buffer
4
- } = _buffer;
5
-
6
1
  /*
7
2
  * ISC License (ISC)
8
- * Copyright 2021 aeternity developers
3
+ * Copyright (c) 2022 aeternity developers
9
4
  *
10
5
  * Permission to use, copy, modify, and/or distribute this software for any
11
6
  * purpose with or without fee is hereby granted, provided that the above
@@ -19,18 +14,22 @@ const {
19
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
15
  * PERFORMANCE OF THIS SOFTWARE.
21
16
  */
22
- import _aeternityBlakejs from '@aeternity/blakejs';
23
- const {
24
- blake2b
25
- } = _aeternityBlakejs;
17
+
18
+ import BrowserConnection from './connection/Browser'
26
19
 
27
20
  /**
28
- * Calculate 256bits Blake2b hash of `input`
29
- * @rtype (input: String) => hash: String
30
- * @param {Data} input - Data to hash
31
- * @return {Buffer} Hash
21
+ * Browser connection proxy
22
+ * Provide functionality to easily forward messages from one connection to another and back
23
+ * @param con1 - first connection
24
+ * @param con2 - second connection
25
+ * @returns a function to stop proxying
32
26
  */
33
- export function hash(input) {
34
- return _Buffer.from(blake2b(input, undefined, 32)); // 256 bits
27
+ export default (con1: BrowserConnection, con2: BrowserConnection): () => void => {
28
+ con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect())
29
+ con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect())
30
+
31
+ return () => {
32
+ con1.disconnect()
33
+ con2.disconnect()
34
+ }
35
35
  }
36
- //# sourceMappingURL=crypto-ts.mjs.map