@aeternity/aepp-sdk 10.0.0 → 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 (424) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +15 -14
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  4. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +13 -40
  5. package/dist/aepp-sdk.browser-script.js.map +1 -1
  6. package/dist/aepp-sdk.browser.js +1 -1
  7. package/dist/aepp-sdk.browser.js.map +1 -1
  8. package/dist/aepp-sdk.js +1 -1
  9. package/dist/aepp-sdk.js.map +1 -1
  10. package/es/AeSdk.d.ts +37 -0
  11. package/es/AeSdk.mjs +81 -0
  12. package/es/AeSdk.mjs.map +1 -0
  13. package/es/AeSdkAepp.d.ts +69 -0
  14. package/es/AeSdkAepp.mjs +175 -0
  15. package/es/AeSdkAepp.mjs.map +1 -0
  16. package/es/AeSdkBase.d.ts +212 -0
  17. package/es/AeSdkBase.mjs +310 -0
  18. package/es/AeSdkBase.mjs.map +1 -0
  19. package/es/AeSdkWallet.d.ts +103 -0
  20. package/es/AeSdkWallet.mjs +322 -0
  21. package/es/AeSdkWallet.mjs.map +1 -0
  22. package/es/Node.d.ts +44 -0
  23. package/es/Node.mjs +141 -0
  24. package/es/Node.mjs.map +1 -0
  25. package/es/account/Base.d.ts +65 -0
  26. package/es/account/Base.mjs +123 -0
  27. package/es/account/Base.mjs.map +1 -0
  28. package/es/account/Memory.d.ts +25 -0
  29. package/es/account/Memory.mjs +81 -0
  30. package/es/account/Memory.mjs.map +1 -0
  31. package/es/account/Rpc.d.ts +27 -0
  32. package/es/account/Rpc.mjs +79 -0
  33. package/es/account/Rpc.mjs.map +1 -0
  34. package/es/aens.d.ts +209 -0
  35. package/es/aens.mjs +332 -0
  36. package/es/aens.mjs.map +1 -0
  37. package/es/aepp-wallet-communication/connection/Browser.d.ts +32 -0
  38. package/es/aepp-wallet-communication/connection/Browser.mjs +70 -0
  39. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +17 -0
  41. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +57 -0
  42. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -0
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +35 -0
  44. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +142 -0
  45. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.d.ts +10 -0
  47. package/{src/utils/crypto-ts.ts → es/aepp-wallet-communication/connection-proxy.mjs} +15 -11
  48. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -0
  49. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +33 -0
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +169 -0
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -0
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +77 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs +3 -0
  54. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -0
  55. package/es/aepp-wallet-communication/schema.d.ts +118 -0
  56. package/es/aepp-wallet-communication/schema.mjs +214 -0
  57. package/es/aepp-wallet-communication/schema.mjs.map +1 -0
  58. package/es/aepp-wallet-communication/wallet-detector.d.ts +24 -0
  59. package/es/aepp-wallet-communication/wallet-detector.mjs +63 -0
  60. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  61. package/es/apis/compiler/compiler.d.ts +92 -0
  62. package/es/apis/compiler/compiler.mjs +576 -0
  63. package/es/apis/compiler/compiler.mjs.map +1 -0
  64. package/es/apis/compiler/index.d.ts +2 -0
  65. package/es/apis/compiler/index.mjs +3 -0
  66. package/es/apis/compiler/index.mjs.map +1 -0
  67. package/es/apis/compiler/models/index.d.ts +248 -0
  68. package/es/apis/compiler/models/index.mjs +48 -0
  69. package/es/apis/compiler/models/index.mjs.map +1 -0
  70. package/es/apis/compiler/models/mappers.d.ts +23 -0
  71. package/es/apis/compiler/models/mappers.mjs +585 -0
  72. package/es/apis/compiler/models/mappers.mjs.map +1 -0
  73. package/es/apis/compiler/models/parameters.d.ts +13 -0
  74. package/es/apis/compiler/models/parameters.mjs +71 -0
  75. package/es/apis/compiler/models/parameters.mjs.map +1 -0
  76. package/es/apis/node/index.d.ts +2 -0
  77. package/es/apis/node/index.mjs +3 -0
  78. package/es/apis/node/index.mjs.map +1 -0
  79. package/es/apis/node/models/index.d.ts +1061 -0
  80. package/es/apis/node/models/index.mjs +2 -0
  81. package/es/apis/node/models/index.mjs.map +1 -0
  82. package/es/apis/node/models/mappers.d.ts +95 -0
  83. package/es/apis/node/models/mappers.mjs +4164 -0
  84. package/es/apis/node/models/mappers.mjs.map +1 -0
  85. package/es/apis/node/models/parameters.d.ts +17 -0
  86. package/es/apis/node/models/parameters.mjs +165 -0
  87. package/es/apis/node/models/parameters.mjs.map +1 -0
  88. package/es/apis/node/node.d.ts +215 -0
  89. package/es/apis/node/node.mjs +1165 -0
  90. package/es/apis/node/node.mjs.map +1 -0
  91. package/es/chain.d.ts +220 -0
  92. package/es/chain.mjs +524 -0
  93. package/es/chain.mjs.map +1 -0
  94. package/es/channel/handlers.d.ts +34 -0
  95. package/es/channel/{handlers.js → handlers.mjs} +163 -130
  96. package/es/channel/handlers.mjs.map +1 -0
  97. package/es/channel/index.d.ts +634 -0
  98. package/es/channel/index.mjs +978 -0
  99. package/es/channel/index.mjs.map +1 -0
  100. package/es/channel/internal.d.ts +100 -0
  101. package/es/channel/internal.mjs +328 -0
  102. package/es/channel/internal.mjs.map +1 -0
  103. package/es/contract/Compiler.d.ts +17 -0
  104. package/es/contract/Compiler.mjs +67 -0
  105. package/es/contract/Compiler.mjs.map +1 -0
  106. package/es/contract/aci.d.ts +125 -0
  107. package/es/contract/aci.mjs +496 -0
  108. package/es/contract/aci.mjs.map +1 -0
  109. package/es/contract/ga.d.ts +68 -0
  110. package/es/contract/ga.mjs +190 -0
  111. package/es/contract/ga.mjs.map +1 -0
  112. package/es/contract/methods.d.ts +68 -0
  113. package/es/contract/methods.mjs +101 -0
  114. package/es/contract/methods.mjs.map +1 -0
  115. package/es/index.d.ts +32 -0
  116. package/es/index.mjs +49 -0
  117. package/es/index.mjs.map +1 -0
  118. package/es/oracle.d.ts +154 -0
  119. package/es/oracle.mjs +288 -0
  120. package/es/oracle.mjs.map +1 -0
  121. package/es/spend.d.ts +61 -0
  122. package/es/spend.mjs +122 -0
  123. package/es/spend.mjs.map +1 -0
  124. package/es/tx/builder/constants.d.ts +41 -0
  125. package/es/tx/builder/constants.mjs +100 -0
  126. package/es/tx/builder/constants.mjs.map +1 -0
  127. package/es/tx/builder/field-types.d.ts +62 -0
  128. package/es/tx/builder/field-types.mjs +126 -0
  129. package/es/tx/builder/field-types.mjs.map +1 -0
  130. package/es/tx/builder/helpers.d.ts +131 -0
  131. package/es/tx/builder/helpers.mjs +223 -0
  132. package/es/tx/builder/helpers.mjs.map +1 -0
  133. package/es/tx/builder/index.d.ts +75 -0
  134. package/es/tx/builder/index.mjs +424 -0
  135. package/es/tx/builder/index.mjs.map +1 -0
  136. package/es/tx/builder/schema.d.ts +350 -0
  137. package/es/tx/builder/schema.mjs +320 -0
  138. package/es/tx/builder/schema.mjs.map +1 -0
  139. package/es/tx/index.d.ts +63 -0
  140. package/es/tx/index.mjs +209 -0
  141. package/es/tx/index.mjs.map +1 -0
  142. package/es/tx/min-fee.d.ts +20 -0
  143. package/es/tx/min-fee.mjs +148 -0
  144. package/es/tx/min-fee.mjs.map +1 -0
  145. package/es/tx/validator.d.ts +19 -0
  146. package/es/tx/validator.mjs +240 -0
  147. package/es/tx/validator.mjs.map +1 -0
  148. package/es/typings/@aeternity__argon2-browser/index.d.mjs +2 -0
  149. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -0
  150. package/es/typings/@aeternity__uuid/index.d.mjs +2 -0
  151. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -0
  152. package/es/typings/bip32-path/index.d.mjs +2 -0
  153. package/es/typings/bip32-path/index.d.mjs.map +1 -0
  154. package/es/typings/blakejs/index.d.mjs +2 -0
  155. package/es/typings/blakejs/index.d.mjs.map +1 -0
  156. package/es/typings/tweetnacl-auth/index.d.mjs +2 -0
  157. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -0
  158. package/es/utils/amount-formatter.d.ts +42 -0
  159. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +38 -44
  160. package/es/utils/amount-formatter.mjs.map +1 -0
  161. package/es/utils/autorest.d.ts +6 -0
  162. package/es/utils/autorest.mjs +97 -0
  163. package/es/utils/autorest.mjs.map +1 -0
  164. package/es/utils/bignumber.d.ts +13 -0
  165. package/es/utils/bignumber.mjs +23 -0
  166. package/es/utils/bignumber.mjs.map +1 -0
  167. package/es/{bytes.d.ts → utils/bytes.d.ts} +10 -13
  168. package/es/utils/{bytes.js → bytes.mjs} +26 -22
  169. package/es/utils/bytes.mjs.map +1 -0
  170. package/es/utils/crypto.d.ts +103 -0
  171. package/es/utils/crypto.mjs +221 -0
  172. package/es/utils/crypto.mjs.map +1 -0
  173. package/es/utils/encoder.d.ts +26 -0
  174. package/es/utils/encoder.mjs +102 -0
  175. package/es/utils/encoder.mjs.map +1 -0
  176. package/es/utils/errors.d.ts +481 -0
  177. package/es/utils/errors.mjs +882 -0
  178. package/es/utils/errors.mjs.map +1 -0
  179. package/es/utils/hd-wallet.d.ts +34 -0
  180. package/es/utils/hd-wallet.mjs +122 -0
  181. package/es/utils/hd-wallet.mjs.map +1 -0
  182. package/es/utils/json-big.d.ts +5 -0
  183. package/es/utils/json-big.mjs +41 -0
  184. package/es/utils/json-big.mjs.map +1 -0
  185. package/es/utils/keystore.d.ts +51 -0
  186. package/es/utils/keystore.mjs +145 -0
  187. package/es/utils/keystore.mjs.map +1 -0
  188. package/es/{mptree.d.ts → utils/mptree.d.ts} +5 -8
  189. package/es/utils/{mptree.js → mptree.mjs} +33 -25
  190. package/es/utils/mptree.mjs.map +1 -0
  191. package/es/utils/other.d.ts +14 -0
  192. package/es/utils/other.mjs +28 -0
  193. package/es/utils/other.mjs.map +1 -0
  194. package/es/{semver-satisfies.d.ts → utils/semver-satisfies.d.ts} +0 -0
  195. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  196. package/es/utils/semver-satisfies.mjs.map +1 -0
  197. package/es/utils/string.d.ts +24 -0
  198. package/es/utils/{string.js → string.mjs} +9 -11
  199. package/es/utils/string.mjs.map +1 -0
  200. package/package.json +67 -64
  201. package/src/AeSdk.ts +65 -0
  202. package/src/AeSdkAepp.ts +167 -0
  203. package/src/AeSdkBase.ts +320 -0
  204. package/src/AeSdkWallet.ts +332 -0
  205. package/src/Node.ts +167 -0
  206. package/src/account/Base.ts +114 -0
  207. package/src/account/Memory.ts +83 -0
  208. package/src/account/Rpc.ts +67 -0
  209. package/src/aens.ts +391 -0
  210. package/src/aepp-wallet-communication/connection/Browser.ts +68 -0
  211. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +58 -0
  212. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +111 -0
  213. package/{es/utils/crypto-ts.js → src/aepp-wallet-communication/connection-proxy.ts} +16 -9
  214. package/src/aepp-wallet-communication/rpc/RpcClient.ts +137 -0
  215. package/src/aepp-wallet-communication/rpc/types.ts +66 -0
  216. package/src/aepp-wallet-communication/schema.ts +181 -0
  217. package/src/aepp-wallet-communication/wallet-detector.ts +71 -0
  218. package/src/apis/compiler/code-model-v4.yaml +2649 -0
  219. package/src/apis/compiler/compiler.ts +585 -0
  220. package/src/apis/compiler/index.ts +2 -0
  221. package/src/apis/compiler/models/index.ts +301 -0
  222. package/src/apis/compiler/models/mappers.ts +583 -0
  223. package/src/apis/compiler/models/parameters.ts +93 -0
  224. package/src/apis/node/code-model-v4.yaml +10046 -0
  225. package/src/apis/node/index.ts +2 -0
  226. package/src/apis/node/models/index.ts +1253 -0
  227. package/src/apis/node/models/mappers.ts +4278 -0
  228. package/src/apis/node/models/parameters.ts +188 -0
  229. package/src/apis/node/node.ts +1299 -0
  230. package/src/chain.ts +444 -0
  231. package/src/channel/{handlers.js → handlers.ts} +238 -143
  232. package/src/channel/index.ts +991 -0
  233. package/src/channel/internal.ts +345 -0
  234. package/src/contract/Compiler.ts +66 -0
  235. package/src/contract/aci.ts +529 -0
  236. package/src/contract/ga.ts +178 -0
  237. package/src/contract/methods.ts +118 -0
  238. package/src/index.ts +51 -0
  239. package/src/oracle.ts +342 -0
  240. package/src/spend.ts +152 -0
  241. package/src/tx/builder/constants.ts +96 -0
  242. package/src/tx/builder/field-types.ts +111 -0
  243. package/src/tx/builder/helpers.ts +253 -0
  244. package/src/tx/builder/index.ts +394 -0
  245. package/src/tx/builder/schema.ts +771 -0
  246. package/src/tx/index.ts +199 -0
  247. package/src/tx/min-fee.ts +136 -0
  248. package/src/tx/validator.ts +226 -0
  249. package/src/typings/@aeternity__argon2-browser/index.d.ts +3 -0
  250. package/src/typings/@aeternity__uuid/index.d.ts +3 -0
  251. package/src/typings/bip32-path/index.d.ts +33 -0
  252. package/src/typings/tweetnacl-auth/index.d.ts +14 -0
  253. package/src/utils/amount-formatter.ts +29 -41
  254. package/src/utils/autorest.ts +90 -0
  255. package/src/utils/bignumber.ts +9 -19
  256. package/src/utils/bytes.ts +15 -16
  257. package/src/utils/crypto.ts +217 -0
  258. package/src/utils/encoder.ts +98 -0
  259. package/src/utils/errors.ts +817 -0
  260. package/src/utils/hd-wallet.ts +134 -0
  261. package/src/utils/json-big.ts +26 -0
  262. package/src/utils/keystore.ts +179 -0
  263. package/src/utils/mptree.ts +26 -20
  264. package/src/utils/other.ts +28 -43
  265. package/src/utils/string.ts +8 -10
  266. package/CHANGELOG.md +0 -1603
  267. package/es/account/base.js +0 -169
  268. package/es/account/base.js.map +0 -1
  269. package/es/account/memory.js +0 -84
  270. package/es/account/memory.js.map +0 -1
  271. package/es/account/multiple.js +0 -178
  272. package/es/account/multiple.js.map +0 -1
  273. package/es/ae/aens.js +0 -408
  274. package/es/ae/aens.js.map +0 -1
  275. package/es/ae/aepp.js +0 -45
  276. package/es/ae/aepp.js.map +0 -1
  277. package/es/ae/contract.js +0 -312
  278. package/es/ae/contract.js.map +0 -1
  279. package/es/ae/index.js +0 -206
  280. package/es/ae/index.js.map +0 -1
  281. package/es/ae/oracle.js +0 -322
  282. package/es/ae/oracle.js.map +0 -1
  283. package/es/ae/universal.js +0 -45
  284. package/es/ae/universal.js.map +0 -1
  285. package/es/ae/wallet.js +0 -50
  286. package/es/ae/wallet.js.map +0 -1
  287. package/es/amount-formatter.d.ts +0 -58
  288. package/es/bignumber.d.ts +0 -24
  289. package/es/chain/index.js +0 -256
  290. package/es/chain/index.js.map +0 -1
  291. package/es/chain/node.js +0 -394
  292. package/es/chain/node.js.map +0 -1
  293. package/es/channel/handlers.js.map +0 -1
  294. package/es/channel/index.js +0 -980
  295. package/es/channel/index.js.map +0 -1
  296. package/es/channel/internal.js +0 -266
  297. package/es/channel/internal.js.map +0 -1
  298. package/es/contract/aci/helpers.js +0 -298
  299. package/es/contract/aci/helpers.js.map +0 -1
  300. package/es/contract/aci/index.js +0 -361
  301. package/es/contract/aci/index.js.map +0 -1
  302. package/es/contract/aci/transformation.js +0 -66
  303. package/es/contract/aci/transformation.js.map +0 -1
  304. package/es/contract/compiler.js +0 -244
  305. package/es/contract/compiler.js.map +0 -1
  306. package/es/contract/ga/helpers.js +0 -22
  307. package/es/contract/ga/helpers.js.map +0 -1
  308. package/es/contract/ga/index.js +0 -170
  309. package/es/contract/ga/index.js.map +0 -1
  310. package/es/contract/index.js +0 -162
  311. package/es/contract/index.js.map +0 -1
  312. package/es/crypto-ts.d.ts +0 -9
  313. package/es/index.js +0 -57
  314. package/es/index.js.map +0 -1
  315. package/es/node-pool/index.js +0 -187
  316. package/es/node-pool/index.js.map +0 -1
  317. package/es/node.js +0 -132
  318. package/es/node.js.map +0 -1
  319. package/es/other.d.ts +0 -31
  320. package/es/string.d.ts +0 -26
  321. package/es/tx/builder/helpers.js +0 -305
  322. package/es/tx/builder/helpers.js.map +0 -1
  323. package/es/tx/builder/index.js +0 -595
  324. package/es/tx/builder/index.js.map +0 -1
  325. package/es/tx/builder/schema.js +0 -814
  326. package/es/tx/builder/schema.js.map +0 -1
  327. package/es/tx/index.js +0 -300
  328. package/es/tx/index.js.map +0 -1
  329. package/es/tx/tx-object.js +0 -276
  330. package/es/tx/tx-object.js.map +0 -1
  331. package/es/tx/tx.js +0 -937
  332. package/es/tx/tx.js.map +0 -1
  333. package/es/tx/validator.js +0 -208
  334. package/es/tx/validator.js.map +0 -1
  335. package/es/typings/blakejs/index.d.js +0 -2
  336. package/es/typings/blakejs/index.d.js.map +0 -1
  337. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -131
  338. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  339. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -184
  340. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  341. package/es/utils/aepp-wallet-communication/connection/index.js +0 -84
  342. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  343. package/es/utils/aepp-wallet-communication/content-script-bridge.js +0 -97
  344. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  345. package/es/utils/aepp-wallet-communication/helpers.js +0 -103
  346. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  347. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -329
  348. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  349. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -270
  350. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  351. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -533
  352. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  353. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  354. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  355. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -109
  356. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  357. package/es/utils/amount-formatter.js.map +0 -1
  358. package/es/utils/async-init.js +0 -67
  359. package/es/utils/async-init.js.map +0 -1
  360. package/es/utils/bignumber.js +0 -28
  361. package/es/utils/bignumber.js.map +0 -1
  362. package/es/utils/bytes.js.map +0 -1
  363. package/es/utils/crypto-ts.js.map +0 -1
  364. package/es/utils/crypto.js +0 -304
  365. package/es/utils/crypto.js.map +0 -1
  366. package/es/utils/hd-wallet.js +0 -112
  367. package/es/utils/hd-wallet.js.map +0 -1
  368. package/es/utils/json-big.js +0 -45
  369. package/es/utils/json-big.js.map +0 -1
  370. package/es/utils/keystore.js +0 -228
  371. package/es/utils/keystore.js.map +0 -1
  372. package/es/utils/mptree.js.map +0 -1
  373. package/es/utils/other.js +0 -43
  374. package/es/utils/other.js.map +0 -1
  375. package/es/utils/semver-satisfies.js.map +0 -1
  376. package/es/utils/string.js.map +0 -1
  377. package/es/utils/swagger.js +0 -132
  378. package/es/utils/swagger.js.map +0 -1
  379. package/src/account/base.js +0 -153
  380. package/src/account/memory.js +0 -78
  381. package/src/account/multiple.js +0 -154
  382. package/src/ae/aens.js +0 -366
  383. package/src/ae/aepp.js +0 -45
  384. package/src/ae/contract.js +0 -285
  385. package/src/ae/index.js +0 -167
  386. package/src/ae/oracle.js +0 -296
  387. package/src/ae/universal.js +0 -47
  388. package/src/ae/wallet.js +0 -50
  389. package/src/chain/index.js +0 -250
  390. package/src/chain/node.js +0 -293
  391. package/src/channel/index.js +0 -898
  392. package/src/channel/internal.js +0 -231
  393. package/src/contract/aci/index.js +0 -317
  394. package/src/contract/aci/transformation.js +0 -72
  395. package/src/contract/compiler.js +0 -195
  396. package/src/contract/ga/helpers.js +0 -17
  397. package/src/contract/ga/index.js +0 -147
  398. package/src/contract/index.js +0 -163
  399. package/src/index.js +0 -90
  400. package/src/node-pool/index.js +0 -171
  401. package/src/node.js +0 -118
  402. package/src/tx/builder/helpers.js +0 -325
  403. package/src/tx/builder/index.js +0 -460
  404. package/src/tx/builder/schema.js +0 -1211
  405. package/src/tx/index.js +0 -301
  406. package/src/tx/tx-object.js +0 -186
  407. package/src/tx/tx.js +0 -622
  408. package/src/tx/validator.js +0 -161
  409. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +0 -114
  410. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -161
  411. package/src/utils/aepp-wallet-communication/connection/index.js +0 -85
  412. package/src/utils/aepp-wallet-communication/content-script-bridge.js +0 -85
  413. package/src/utils/aepp-wallet-communication/helpers.js +0 -70
  414. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -268
  415. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -223
  416. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -390
  417. package/src/utils/aepp-wallet-communication/schema.js +0 -108
  418. package/src/utils/aepp-wallet-communication/wallet-detector.js +0 -91
  419. package/src/utils/async-init.js +0 -41
  420. package/src/utils/crypto.js +0 -312
  421. package/src/utils/hd-wallet.js +0 -115
  422. package/src/utils/json-big.js +0 -26
  423. package/src/utils/keystore.js +0 -223
  424. package/src/utils/swagger.js +0 -133
@@ -0,0 +1,67 @@
1
+ import AccountBase from './Base'
2
+ import { METHODS } from '../aepp-wallet-communication/schema'
3
+ import { NotImplementedError } from '../utils/errors'
4
+ import { EncodedData } from '../utils/encoder'
5
+
6
+ /**
7
+ * Account provided by wallet
8
+ * @param params - Params
9
+ * @param params.rpcClient - RpcClient instance
10
+ * @param params.address - RPC account address
11
+ * @returns AccountRpc instance
12
+ */
13
+ export default class AccountRpc extends AccountBase {
14
+ _rpcClient: any
15
+ _address: EncodedData<'ak'>
16
+
17
+ constructor (
18
+ { rpcClient, address, ...options }:
19
+ { rpcClient: any, address: EncodedData<'ak'> } & ConstructorParameters<typeof AccountBase>[0]
20
+ ) {
21
+ super(options)
22
+ this._rpcClient = rpcClient
23
+ this._address = address
24
+ }
25
+
26
+ async sign (data: string | Uint8Array, options?: any): Promise<Uint8Array> {
27
+ throw new NotImplementedError('RAW signing using wallet')
28
+ }
29
+
30
+ async address (): Promise<EncodedData<'ak'>> {
31
+ return this._address
32
+ }
33
+
34
+ /**
35
+ * @returns Signed transaction
36
+ */
37
+ async signTransaction (
38
+ tx: EncodedData<'tx'>,
39
+ { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {}
40
+ ): Promise<EncodedData<'tx'>> {
41
+ if (innerTx != null) throw new NotImplementedError('innerTx option in AccountRpc')
42
+ const res = await this._rpcClient.request(METHODS.sign, {
43
+ onAccount: this._address,
44
+ tx,
45
+ returnSigned: true,
46
+ /**
47
+ * @deprecated Wallet provided networkId will be used (current network)
48
+ * required to maintain backward compatibility with wallets using SDK v11.0.1 and below
49
+ * @see {@link https://github.com/aeternity/aepp-sdk-js/commit/153fd89a52c4eab39fcd659b356b36d32129c1ba}
50
+ */
51
+ networkId
52
+ })
53
+ return res.signedTransaction
54
+ }
55
+
56
+ /**
57
+ * @returns Signed message
58
+ */
59
+ async signMessage (
60
+ message: string, { returnHex = false }: Parameters<AccountBase['signMessage']>[1] = {}
61
+ ): Promise<string | Uint8Array> {
62
+ const { signature } = await this._rpcClient.request(
63
+ METHODS.signMessage, { onAccount: this._address, message }
64
+ )
65
+ return returnHex ? signature : Buffer.from(signature, 'hex')
66
+ }
67
+ }
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
+ }