@aeternity/aepp-sdk 13.0.1 → 13.2.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 (322) hide show
  1. package/README.md +4 -2
  2. package/bin/aesophia_cli +0 -0
  3. package/dist/aepp-sdk.browser-script.js +1 -1
  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 +28490 -17706
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdkAepp.mjs.map +1 -1
  10. package/es/AeSdkBase.d.ts +21 -3
  11. package/es/AeSdkBase.mjs +51 -3
  12. package/es/AeSdkBase.mjs.map +1 -1
  13. package/es/AeSdkMethods.d.ts +9 -14
  14. package/es/AeSdkMethods.mjs +20 -49
  15. package/es/AeSdkMethods.mjs.map +1 -1
  16. package/es/AeSdkWallet.d.ts +1 -1
  17. package/es/AeSdkWallet.mjs +79 -23
  18. package/es/AeSdkWallet.mjs.map +1 -1
  19. package/es/Middleware.d.ts +38 -0
  20. package/es/Middleware.mjs +90 -0
  21. package/es/Middleware.mjs.map +1 -0
  22. package/es/MiddlewareSubscriber.d.ts +30 -0
  23. package/es/MiddlewareSubscriber.mjs +198 -0
  24. package/es/MiddlewareSubscriber.mjs.map +1 -0
  25. package/es/Node.d.ts +1 -1
  26. package/es/Node.mjs.map +1 -1
  27. package/es/account/Base.d.ts +57 -3
  28. package/es/account/Base.mjs +95 -1
  29. package/es/account/Base.mjs.map +1 -1
  30. package/es/account/Generalized.d.ts +4 -0
  31. package/es/account/Generalized.mjs +20 -0
  32. package/es/account/Generalized.mjs.map +1 -1
  33. package/es/account/Ledger.d.ts +4 -0
  34. package/es/account/Ledger.mjs +20 -0
  35. package/es/account/Ledger.mjs.map +1 -1
  36. package/es/account/LedgerFactory.mjs.map +1 -1
  37. package/es/account/Memory.d.ts +12 -0
  38. package/es/account/Memory.mjs +52 -0
  39. package/es/account/Memory.mjs.map +1 -1
  40. package/es/account/Rpc.d.ts +5 -6
  41. package/es/account/Rpc.mjs +53 -10
  42. package/es/account/Rpc.mjs.map +1 -1
  43. package/es/aens.d.ts +1 -1
  44. package/es/aens.mjs +1 -1
  45. package/es/aens.mjs.map +1 -1
  46. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  48. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  49. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -2
  51. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/rpc/types.d.ts +19 -0
  53. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  54. package/es/aepp-wallet-communication/schema.d.ts +2 -8
  55. package/es/aepp-wallet-communication/schema.mjs +21 -33
  56. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  57. package/es/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  58. package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
  59. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  60. package/es/apis/compiler/compiler.mjs +15 -1
  61. package/es/apis/compiler/compiler.mjs.map +1 -1
  62. package/es/apis/compiler/models/index.d.ts +1 -7
  63. package/es/apis/compiler/models/index.mjs.map +1 -1
  64. package/es/apis/compiler/models/mappers.d.ts +0 -1
  65. package/es/apis/compiler/models/mappers.mjs +0 -43
  66. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  67. package/es/apis/middleware/index.d.ts +2 -0
  68. package/es/apis/middleware/index.mjs +3 -0
  69. package/es/apis/middleware/index.mjs.map +1 -0
  70. package/es/apis/middleware/middleware.d.ts +309 -0
  71. package/es/apis/middleware/middleware.mjs +1527 -0
  72. package/es/apis/middleware/middleware.mjs.map +1 -0
  73. package/es/apis/middleware/models/index.d.ts +1496 -0
  74. package/es/apis/middleware/models/index.mjs +580 -0
  75. package/es/apis/middleware/models/index.mjs.map +1 -0
  76. package/es/apis/middleware/models/mappers.d.ts +102 -0
  77. package/es/apis/middleware/models/mappers.mjs +3334 -0
  78. package/es/apis/middleware/models/mappers.mjs.map +1 -0
  79. package/es/apis/middleware/models/parameters.d.ts +43 -0
  80. package/es/apis/middleware/models/parameters.mjs +417 -0
  81. package/es/apis/middleware/models/parameters.mjs.map +1 -0
  82. package/es/apis/node/node.mjs.map +1 -1
  83. package/es/chain.d.ts +2 -1
  84. package/es/chain.mjs +5 -3
  85. package/es/chain.mjs.map +1 -1
  86. package/es/channel/Base.d.ts +1 -1
  87. package/es/channel/Base.mjs +1 -4
  88. package/es/channel/Base.mjs.map +1 -1
  89. package/es/channel/Contract.mjs.map +1 -1
  90. package/es/channel/Spend.mjs.map +1 -1
  91. package/es/channel/handlers.mjs +2 -2
  92. package/es/channel/handlers.mjs.map +1 -1
  93. package/es/channel/internal.mjs +7 -5
  94. package/es/channel/internal.mjs.map +1 -1
  95. package/es/contract/Contract.mjs +2 -2
  96. package/es/contract/Contract.mjs.map +1 -1
  97. package/es/contract/compiler/Base.d.ts +21 -0
  98. package/es/contract/compiler/Base.mjs.map +1 -1
  99. package/es/contract/compiler/Cli.d.ts +2 -0
  100. package/es/contract/compiler/Cli.mjs +24 -3
  101. package/es/contract/compiler/Cli.mjs.map +1 -1
  102. package/es/contract/compiler/Http.d.ts +2 -0
  103. package/es/contract/compiler/Http.mjs +22 -2
  104. package/es/contract/compiler/Http.mjs.map +1 -1
  105. package/es/contract/compiler/HttpNode.d.ts +1 -0
  106. package/es/contract/compiler/HttpNode.mjs +5 -0
  107. package/es/contract/compiler/HttpNode.mjs.map +1 -1
  108. package/es/contract/delegation-signature.d.ts +2 -1
  109. package/es/contract/delegation-signature.mjs +39 -8
  110. package/es/contract/delegation-signature.mjs.map +1 -1
  111. package/es/contract/ga.mjs.map +1 -1
  112. package/es/deprecated.d.ts +14 -0
  113. package/es/deprecated.mjs +22 -0
  114. package/es/deprecated.mjs.map +1 -0
  115. package/es/index-browser.d.ts +20 -14
  116. package/es/index-browser.mjs +19 -15
  117. package/es/index-browser.mjs.map +1 -1
  118. package/es/oracle.mjs.map +1 -1
  119. package/es/spend.d.ts +2 -1
  120. package/es/spend.mjs +4 -2
  121. package/es/spend.mjs.map +1 -1
  122. package/es/tx/builder/constants.d.ts +0 -1
  123. package/es/tx/builder/constants.mjs +26 -24
  124. package/es/tx/builder/constants.mjs.map +1 -1
  125. package/es/tx/builder/field-types/abi-version.mjs.map +1 -1
  126. package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
  127. package/es/tx/builder/field-types/coin-amount.mjs +2 -1
  128. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  129. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  130. package/es/tx/builder/field-types/deposit.d.ts +1 -1
  131. package/es/tx/builder/field-types/deposit.mjs.map +1 -1
  132. package/es/tx/builder/field-types/entry.mjs +2 -1
  133. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  134. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  135. package/es/tx/builder/field-types/field.mjs.map +1 -1
  136. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -1
  137. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  138. package/es/tx/builder/field-types/index.d.ts +28 -150
  139. package/es/tx/builder/field-types/index.mjs +28 -56
  140. package/es/tx/builder/field-types/index.mjs.map +1 -1
  141. package/es/tx/builder/field-types/map.mjs.map +1 -1
  142. package/es/tx/builder/field-types/mptree.mjs +3 -3
  143. package/es/tx/builder/field-types/mptree.mjs.map +1 -1
  144. package/es/tx/builder/field-types/name-fee.mjs.map +1 -1
  145. package/es/tx/builder/field-types/pointers.mjs.map +1 -1
  146. package/es/tx/builder/field-types/string.mjs.map +1 -1
  147. package/es/tx/builder/field-types/ttl.mjs.map +1 -1
  148. package/es/tx/builder/field-types/u-int.mjs +1 -1
  149. package/es/tx/builder/field-types/u-int.mjs.map +1 -1
  150. package/es/tx/builder/helpers.d.ts +8 -1
  151. package/es/tx/builder/helpers.mjs +53 -9
  152. package/es/tx/builder/helpers.mjs.map +1 -1
  153. package/es/tx/builder/index.d.ts +4 -2
  154. package/es/tx/builder/index.mjs +0 -1
  155. package/es/tx/builder/index.mjs.map +1 -1
  156. package/es/tx/builder/schema.d.ts +9 -9
  157. package/es/tx/builder/schema.mjs +11 -10
  158. package/es/tx/builder/schema.mjs.map +1 -1
  159. package/es/tx/execution-cost.mjs.map +1 -1
  160. package/es/tx/transaction-signer.mjs.map +1 -1
  161. package/es/tx/validator.mjs +6 -3
  162. package/es/tx/validator.mjs.map +1 -1
  163. package/es/utils/amount-formatter.mjs +7 -7
  164. package/es/utils/amount-formatter.mjs.map +1 -1
  165. package/es/utils/autorest.mjs +6 -8
  166. package/es/utils/autorest.mjs.map +1 -1
  167. package/es/utils/bignumber.mjs.map +1 -1
  168. package/es/utils/bytes.mjs.map +1 -1
  169. package/es/utils/crypto.d.ts +1 -0
  170. package/es/utils/crypto.mjs +12 -2
  171. package/es/utils/crypto.mjs.map +1 -1
  172. package/es/utils/encoder-types.mjs +3 -3
  173. package/es/utils/encoder-types.mjs.map +1 -1
  174. package/es/utils/encoder.mjs.map +1 -1
  175. package/es/utils/errors.d.ts +2 -2
  176. package/es/utils/errors.mjs.map +1 -1
  177. package/es/utils/hd-wallet.mjs.map +1 -1
  178. package/es/utils/keystore.mjs.map +1 -1
  179. package/es/utils/other.d.ts +1 -0
  180. package/es/utils/other.mjs +5 -0
  181. package/es/utils/other.mjs.map +1 -1
  182. package/es/utils/semver-satisfies.mjs.map +1 -1
  183. package/es/utils/string.mjs.map +1 -1
  184. package/es/utils/typed-data.d.ts +45 -0
  185. package/es/utils/typed-data.mjs +70 -0
  186. package/es/utils/typed-data.mjs.map +1 -0
  187. package/package.json +56 -37
  188. package/src/AeSdkBase.ts +66 -5
  189. package/src/AeSdkMethods.ts +31 -50
  190. package/src/AeSdkWallet.ts +63 -17
  191. package/src/Middleware.ts +141 -0
  192. package/src/MiddlewareSubscriber.ts +207 -0
  193. package/src/Node.ts +1 -1
  194. package/src/account/Base.ts +102 -4
  195. package/src/account/Generalized.ts +20 -0
  196. package/src/account/Ledger.ts +20 -0
  197. package/src/account/Memory.ts +68 -1
  198. package/src/account/Rpc.ts +54 -7
  199. package/src/aens.ts +1 -1
  200. package/src/aepp-wallet-communication/rpc/RpcClient.ts +11 -3
  201. package/src/aepp-wallet-communication/rpc/types.ts +21 -0
  202. package/src/aepp-wallet-communication/schema.ts +3 -17
  203. package/src/aepp-wallet-communication/wallet-detector.ts +1 -2
  204. package/src/apis/compiler/compiler.ts +8 -1
  205. package/src/apis/compiler/models/index.ts +1 -8
  206. package/src/apis/compiler/models/mappers.ts +0 -36
  207. package/src/apis/middleware/index.ts +2 -0
  208. package/src/apis/middleware/middleware.ts +1807 -0
  209. package/src/apis/middleware/models/index.ts +1747 -0
  210. package/src/apis/middleware/models/mappers.ts +3370 -0
  211. package/src/apis/middleware/models/parameters.ts +463 -0
  212. package/src/chain.ts +4 -3
  213. package/src/channel/Base.ts +5 -5
  214. package/src/channel/internal.ts +2 -0
  215. package/src/contract/Contract.ts +2 -1
  216. package/src/contract/compiler/Base.ts +26 -0
  217. package/src/contract/compiler/Cli.ts +27 -3
  218. package/src/contract/compiler/Http.ts +21 -2
  219. package/src/contract/compiler/HttpNode.ts +6 -0
  220. package/src/contract/delegation-signature.ts +37 -11
  221. package/src/deprecated.ts +23 -0
  222. package/src/index-browser.ts +77 -15
  223. package/src/spend.ts +2 -2
  224. package/src/tx/builder/constants.ts +0 -1
  225. package/src/tx/builder/field-types/coin-amount.ts +2 -1
  226. package/src/tx/builder/field-types/entry.ts +1 -1
  227. package/src/tx/builder/field-types/index.ts +28 -58
  228. package/src/tx/builder/field-types/u-int.ts +1 -1
  229. package/src/tx/builder/helpers.ts +54 -9
  230. package/src/tx/builder/index.ts +6 -9
  231. package/src/tx/validator.ts +4 -2
  232. package/src/utils/autorest.ts +5 -10
  233. package/src/utils/crypto.ts +12 -2
  234. package/src/utils/errors.ts +2 -2
  235. package/src/utils/other.ts +5 -0
  236. package/src/utils/typed-data.ts +95 -0
  237. package/types-legacy/ts4.2/AeSdkBase.d.ts +21 -3
  238. package/types-legacy/ts4.2/AeSdkMethods.d.ts +9 -14
  239. package/types-legacy/ts4.2/AeSdkWallet.d.ts +1 -1
  240. package/types-legacy/ts4.2/Middleware.d.ts +46 -0
  241. package/types-legacy/ts4.2/MiddlewareSubscriber.d.ts +30 -0
  242. package/types-legacy/ts4.2/Node.d.ts +1 -1
  243. package/types-legacy/ts4.2/account/Base.d.ts +57 -3
  244. package/types-legacy/ts4.2/account/Generalized.d.ts +4 -0
  245. package/types-legacy/ts4.2/account/Ledger.d.ts +4 -0
  246. package/types-legacy/ts4.2/account/Memory.d.ts +12 -0
  247. package/types-legacy/ts4.2/account/Rpc.d.ts +5 -6
  248. package/types-legacy/ts4.2/aens.d.ts +1 -1
  249. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +19 -0
  250. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +2 -8
  251. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  252. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -7
  253. package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +0 -1
  254. package/types-legacy/ts4.2/apis/middleware/index.d.ts +2 -0
  255. package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +309 -0
  256. package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +1496 -0
  257. package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +102 -0
  258. package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +43 -0
  259. package/types-legacy/ts4.2/chain.d.ts +2 -1
  260. package/types-legacy/ts4.2/channel/Base.d.ts +1 -1
  261. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +21 -0
  262. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +2 -0
  263. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +2 -0
  264. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +1 -0
  265. package/types-legacy/ts4.2/contract/delegation-signature.d.ts +2 -1
  266. package/types-legacy/ts4.2/deprecated.d.ts +14 -0
  267. package/types-legacy/ts4.2/index-browser.d.ts +20 -14
  268. package/types-legacy/ts4.2/spend.d.ts +2 -1
  269. package/types-legacy/ts4.2/tx/builder/constants.d.ts +0 -1
  270. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
  271. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
  272. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +28 -153
  273. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +8 -1
  274. package/types-legacy/ts4.2/tx/builder/index.d.ts +4 -2
  275. package/types-legacy/ts4.2/tx/builder/schema.d.ts +9 -9
  276. package/types-legacy/ts4.2/utils/crypto.d.ts +1 -0
  277. package/types-legacy/ts4.2/utils/errors.d.ts +2 -2
  278. package/types-legacy/ts4.2/utils/other.d.ts +1 -0
  279. package/types-legacy/ts4.2/utils/typed-data.d.ts +60 -0
  280. package/types-legacy/ts4.5/AeSdkBase.d.ts +21 -3
  281. package/types-legacy/ts4.5/AeSdkMethods.d.ts +9 -14
  282. package/types-legacy/ts4.5/AeSdkWallet.d.ts +1 -1
  283. package/types-legacy/ts4.5/Middleware.d.ts +46 -0
  284. package/types-legacy/ts4.5/MiddlewareSubscriber.d.ts +30 -0
  285. package/types-legacy/ts4.5/Node.d.ts +1 -1
  286. package/types-legacy/ts4.5/account/Base.d.ts +57 -3
  287. package/types-legacy/ts4.5/account/Generalized.d.ts +4 -0
  288. package/types-legacy/ts4.5/account/Ledger.d.ts +4 -0
  289. package/types-legacy/ts4.5/account/Memory.d.ts +12 -0
  290. package/types-legacy/ts4.5/account/Rpc.d.ts +5 -6
  291. package/types-legacy/ts4.5/aens.d.ts +1 -1
  292. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +19 -0
  293. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +2 -8
  294. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  295. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -7
  296. package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +0 -1
  297. package/types-legacy/ts4.5/apis/middleware/index.d.ts +2 -0
  298. package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +309 -0
  299. package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +1496 -0
  300. package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +102 -0
  301. package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +43 -0
  302. package/types-legacy/ts4.5/chain.d.ts +2 -1
  303. package/types-legacy/ts4.5/channel/Base.d.ts +1 -1
  304. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +21 -0
  305. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +2 -0
  306. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +2 -0
  307. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +1 -0
  308. package/types-legacy/ts4.5/contract/delegation-signature.d.ts +2 -1
  309. package/types-legacy/ts4.5/deprecated.d.ts +14 -0
  310. package/types-legacy/ts4.5/index-browser.d.ts +20 -14
  311. package/types-legacy/ts4.5/spend.d.ts +2 -1
  312. package/types-legacy/ts4.5/tx/builder/constants.d.ts +0 -1
  313. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
  314. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
  315. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +28 -153
  316. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +8 -1
  317. package/types-legacy/ts4.5/tx/builder/index.d.ts +4 -2
  318. package/types-legacy/ts4.5/tx/builder/schema.d.ts +9 -9
  319. package/types-legacy/ts4.5/utils/crypto.d.ts +1 -0
  320. package/types-legacy/ts4.5/utils/errors.d.ts +2 -2
  321. package/types-legacy/ts4.5/utils/other.d.ts +1 -0
  322. package/types-legacy/ts4.5/utils/typed-data.d.ts +60 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Ledger.mjs","names":["AccountBase","ArgumentError","NotImplementedError","decode","buildTx","Tag","CLA","GET_ADDRESS","SIGN_TRANSACTION","GET_APP_CONFIGURATION","SIGN_PERSONAL_MESSAGE","AccountLedger","constructor","transport","index","address","scrambleKey","decorateAppAPIMethods","sign","signTransaction","tx","innerTx","networkId","arguments","length","undefined","rawTx","offset","headerLength","networkIdBuffer","_Buffer","from","toSend","maxChunkSize","chunkSize","buffer","alloc","bufferOffset","writeUInt32BE","writeUInt8","copy","push","response","reduce","previous","data","i","send","Promise","resolve","signatures","subarray","tag","SignedTx","encodedTx","signMessage","messageStr","message"],"sources":["../../src/account/Ledger.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountBase from './Base';\nimport { ArgumentError, NotImplementedError } from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\nexport const CLA = 0xe0;\nexport const GET_ADDRESS = 0x02;\nexport const SIGN_TRANSACTION = 0x04;\nexport const GET_APP_CONFIGURATION = 0x06;\nexport const SIGN_PERSONAL_MESSAGE = 0x08;\n\n/**\n * Ledger wallet account class\n */\nexport default class AccountLedger extends AccountBase {\n readonly transport: Transport;\n\n override readonly address: Encoded.AccountAddress;\n\n readonly index: number;\n\n /**\n * @param transport - Connection to Ledger to use\n * @param index - Index of account\n * @param address - Address of account\n */\n constructor(transport: Transport, index: number, address: Encoded.AccountAddress) {\n super();\n this.transport = transport;\n this.index = index;\n this.address = address;\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], scrambleKey);\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using Ledger HW');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountLedger');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n\n const rawTx = decode(tx);\n let offset = 0;\n const headerLength = 4 + 1 + 4;\n const networkIdBuffer = Buffer.from(networkId);\n const toSend = [];\n while (offset !== rawTx.length) {\n const maxChunkSize = offset === 0 ? 150 - headerLength - networkIdBuffer.length : 150;\n const chunkSize = offset + maxChunkSize > rawTx.length\n ? rawTx.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(\n offset === 0 ? headerLength + networkIdBuffer.length + chunkSize : chunkSize,\n );\n if (offset === 0) {\n let bufferOffset = buffer.writeUInt32BE(this.index, 0);\n bufferOffset = buffer.writeUInt32BE(rawTx.length, bufferOffset);\n bufferOffset = buffer.writeUInt8(networkIdBuffer.length, bufferOffset);\n bufferOffset += networkIdBuffer.copy(\n buffer,\n bufferOffset,\n 0,\n networkIdBuffer.length,\n );\n rawTx.copy(buffer, bufferOffset, 0, 150 - bufferOffset);\n } else {\n rawTx.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_TRANSACTION,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n const signatures = [response.subarray(0, 64)];\n\n return buildTx({ tag: Tag.SignedTx, encodedTx: rawTx, signatures });\n }\n\n override async signMessage(messageStr: string): Promise<Uint8Array> {\n let offset = 0;\n const message = Buffer.from(messageStr);\n const toSend = [];\n while (offset !== message.length) {\n const maxChunkSize = offset === 0 ? 150 - 4 - 4 : 150;\n const chunkSize = offset + maxChunkSize > message.length\n ? message.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(offset === 0 ? 4 + 4 + chunkSize : chunkSize);\n if (offset === 0) {\n buffer.writeUInt32BE(this.index, 0);\n buffer.writeUInt32BE(message.length, 4);\n message.copy(buffer, 4 + 4, offset, offset + chunkSize);\n } else {\n message.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_PERSONAL_MESSAGE,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n return response.subarray(0, 64);\n }\n}\n"],"mappings":";;;;OACOA,WAAW;AAAA,SACTC,aAAa,EAAEC,mBAAmB;AAAA,SAClCC,MAAM;AAAA,SACNC,OAAO;AAAA,SACPC,GAAG;AAEZ,OAAO,MAAMC,GAAG,GAAG,IAAI;AACvB,OAAO,MAAMC,WAAW,GAAG,IAAI;AAC/B,OAAO,MAAMC,gBAAgB,GAAG,IAAI;AACpC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;AACzC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;;AAEzC;AACA;AACA;AACA,eAAe,MAAMC,aAAa,SAASX,WAAW,CAAC;EAOrD;AACF;AACA;AACA;AACA;EACEY,WAAWA,CAACC,SAAoB,EAAEC,KAAa,EAAEC,OAA+B,EAAE;IAChF,KAAK,EAAE;IACP,IAAI,CAACF,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB,MAAMC,WAAW,GAAG,KAAK;IACzBH,SAAS,CAACI,qBAAqB,CAAC,IAAI,EAAE,CAAC,iBAAiB,EAAE,aAAa,CAAC,EAAED,WAAW,CAAC;EACxF;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,EACJD,IAAI,CACL;IACH,CAAC,EACDG,OAAO,CAACC,OAAO,CAACnB,OAAA,CAAOM,KAAK,CAAC,CAAC,CAAC,CAAC,CACjC;IACD,OAAOM,QAAQ,CAACS,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;EACjC;AACF"}
1
+ {"version":3,"file":"Ledger.mjs","names":["AccountBase","ArgumentError","NotImplementedError","decode","buildTx","Tag","CLA","GET_ADDRESS","SIGN_TRANSACTION","GET_APP_CONFIGURATION","SIGN_PERSONAL_MESSAGE","AccountLedger","constructor","transport","index","address","scrambleKey","decorateAppAPIMethods","sign","signTypedData","signDelegationToContract","signNameDelegationToContract","signOracleQueryDelegationToContract","signTransaction","tx","innerTx","networkId","arguments","length","undefined","rawTx","offset","headerLength","networkIdBuffer","_Buffer","from","toSend","maxChunkSize","chunkSize","buffer","alloc","bufferOffset","writeUInt32BE","writeUInt8","copy","push","response","reduce","previous","data","i","send","Promise","resolve","signatures","subarray","tag","SignedTx","encodedTx","signMessage","messageStr","message"],"sources":["../../src/account/Ledger.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountBase from './Base';\nimport { ArgumentError, NotImplementedError } from '../utils/errors';\nimport { decode, Encoded } from '../utils/encoder';\nimport { buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\nexport const CLA = 0xe0;\nexport const GET_ADDRESS = 0x02;\nexport const SIGN_TRANSACTION = 0x04;\nexport const GET_APP_CONFIGURATION = 0x06;\nexport const SIGN_PERSONAL_MESSAGE = 0x08;\n\n/**\n * Ledger wallet account class\n */\nexport default class AccountLedger extends AccountBase {\n readonly transport: Transport;\n\n override readonly address: Encoded.AccountAddress;\n\n readonly index: number;\n\n /**\n * @param transport - Connection to Ledger to use\n * @param index - Index of account\n * @param address - Address of account\n */\n constructor(transport: Transport, index: number, address: Encoded.AccountAddress) {\n super();\n this.transport = transport;\n this.index = index;\n this.address = address;\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['signTransaction', 'signMessage'], scrambleKey);\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signTypedData(): Promise<Encoded.Signature> {\n throw new NotImplementedError('Typed data signing using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signNameDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using Ledger HW');\n }\n\n // eslint-disable-next-line class-methods-use-this\n override async signOracleQueryDelegationToContract(): Promise<Encoded.Signature> {\n throw new NotImplementedError('signing delegation to contract using Ledger HW');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountLedger');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n\n const rawTx = decode(tx);\n let offset = 0;\n const headerLength = 4 + 1 + 4;\n const networkIdBuffer = Buffer.from(networkId);\n const toSend = [];\n while (offset !== rawTx.length) {\n const maxChunkSize = offset === 0 ? 150 - headerLength - networkIdBuffer.length : 150;\n const chunkSize = offset + maxChunkSize > rawTx.length\n ? rawTx.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(\n offset === 0 ? headerLength + networkIdBuffer.length + chunkSize : chunkSize,\n );\n if (offset === 0) {\n let bufferOffset = buffer.writeUInt32BE(this.index, 0);\n bufferOffset = buffer.writeUInt32BE(rawTx.length, bufferOffset);\n bufferOffset = buffer.writeUInt8(networkIdBuffer.length, bufferOffset);\n bufferOffset += networkIdBuffer.copy(\n buffer,\n bufferOffset,\n 0,\n networkIdBuffer.length,\n );\n rawTx.copy(buffer, bufferOffset, 0, 150 - bufferOffset);\n } else {\n rawTx.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_TRANSACTION,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n const signatures = [response.subarray(0, 64)];\n\n return buildTx({ tag: Tag.SignedTx, encodedTx: rawTx, signatures });\n }\n\n override async signMessage(messageStr: string): Promise<Uint8Array> {\n let offset = 0;\n const message = Buffer.from(messageStr);\n const toSend = [];\n while (offset !== message.length) {\n const maxChunkSize = offset === 0 ? 150 - 4 - 4 : 150;\n const chunkSize = offset + maxChunkSize > message.length\n ? message.length - offset : maxChunkSize;\n const buffer = Buffer.alloc(offset === 0 ? 4 + 4 + chunkSize : chunkSize);\n if (offset === 0) {\n buffer.writeUInt32BE(this.index, 0);\n buffer.writeUInt32BE(message.length, 4);\n message.copy(buffer, 4 + 4, offset, offset + chunkSize);\n } else {\n message.copy(buffer, 0, offset, offset + chunkSize);\n }\n toSend.push(buffer);\n offset += chunkSize;\n }\n const response = await toSend.reduce(\n async (previous, data, i) => {\n await previous;\n return this.transport.send(\n CLA,\n SIGN_PERSONAL_MESSAGE,\n i === 0 ? 0x00 : 0x80,\n 0x00,\n data,\n );\n },\n Promise.resolve(Buffer.alloc(0)),\n );\n return response.subarray(0, 64);\n }\n}\n"],"mappings":";;;;OACOA,WAAW;AAAA,SACTC,aAAa,EAAEC,mBAAmB;AAAA,SAClCC,MAAM;AAAA,SACNC,OAAO;AAAA,SACPC,GAAG;AAEZ,OAAO,MAAMC,GAAG,GAAG,IAAI;AACvB,OAAO,MAAMC,WAAW,GAAG,IAAI;AAC/B,OAAO,MAAMC,gBAAgB,GAAG,IAAI;AACpC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;AACzC,OAAO,MAAMC,qBAAqB,GAAG,IAAI;;AAEzC;AACA;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,CAAC,GAAG,CAAC,GAAGO,SAAS,GAAGA,SAAS,CAAC;MACzE,IAAIP,MAAM,KAAK,CAAC,EAAE;QAChBQ,MAAM,CAACG,aAAa,CAAC,IAAI,CAAC5B,KAAK,EAAE,CAAC,CAAC;QACnCyB,MAAM,CAACG,aAAa,CAACmB,OAAO,CAACjC,MAAM,EAAE,CAAC,CAAC;QACvCiC,OAAO,CAACjB,IAAI,CAACL,MAAM,EAAE,CAAC,GAAG,CAAC,EAAER,MAAM,EAAEA,MAAM,GAAGO,SAAS,CAAC;MACzD,CAAC,MAAM;QACLuB,OAAO,CAACjB,IAAI,CAACL,MAAM,EAAE,CAAC,EAAER,MAAM,EAAEA,MAAM,GAAGO,SAAS,CAAC;MACrD;MACAF,MAAM,CAACS,IAAI,CAACN,MAAM,CAAC;MACnBR,MAAM,IAAIO,SAAS;IACrB;IACA,MAAMQ,QAAQ,GAAG,MAAMV,MAAM,CAACW,MAAM,CAClC,OAAOC,QAAQ,EAAEC,IAAI,EAAEC,CAAC,KAAK;MAC3B,MAAMF,QAAQ;MACd,OAAO,IAAI,CAACnC,SAAS,CAACsC,IAAI,CACxB7C,GAAG,EACHI,qBAAqB,EACrBwC,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,EACrB,IAAI,EACJD,IACF,CAAC;IACH,CAAC,EACDG,OAAO,CAACC,OAAO,CAACnB,OAAA,CAAOM,KAAK,CAAC,CAAC,CAAC,CACjC,CAAC;IACD,OAAOM,QAAQ,CAACS,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC;EACjC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"LedgerFactory.mjs","names":["AccountLedger","CLA","GET_ADDRESS","GET_APP_CONFIGURATION","UnsupportedVersionError","semverSatisfies","AccountLedgerFactory","constructor","transport","versionCheckPromise","getAppConfiguration","then","_ref","version","args","scrambleKey","decorateAppAPIMethods","response","send","join","getAddress","accountIndex","verify","arguments","length","undefined","buffer","_Buffer","alloc","writeUInt32BE","addressLength","subarray","toString","initialize","discover","node","index","result","account","push","getAccountByPubkey","address"],"sources":["../../src/account/LedgerFactory.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountLedger, { CLA, GET_ADDRESS, GET_APP_CONFIGURATION } from './Ledger';\nimport { UnsupportedVersionError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport semverSatisfies from '../utils/semver-satisfies';\nimport Node from '../Node';\n\n/**\n * A factory class that generates instances of AccountLedger based on provided transport.\n */\nexport default class AccountLedgerFactory {\n readonly transport: Transport;\n\n private readonly versionCheckPromise: Promise<void>;\n\n /**\n * @param transport - Connection to Ledger to use\n */\n constructor(transport: Transport) {\n this.transport = transport;\n this.versionCheckPromise = this.getAppConfiguration().then(({ version }) => {\n const args = [version, '0.4.4', '0.5.0'] as const;\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError('app on ledger', ...args);\n });\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['getAddress', 'getAppConfiguration'], scrambleKey);\n }\n\n /**\n * @returns the version of app installed on Ledger wallet\n */\n async getAppConfiguration(): Promise<{ version: string }> {\n await this.versionCheckPromise;\n const response = await this.transport.send(CLA, GET_APP_CONFIGURATION, 0x00, 0x00);\n return {\n version: [response[1], response[2], response[3]].join('.'),\n };\n }\n\n /**\n * Get `ak_`-prefixed address for a given account index.\n * @param accountIndex - Index of account\n * @param verify - Ask user to confirm address by showing it on the device screen\n */\n async getAddress(accountIndex: number, verify = false): Promise<Encoded.AccountAddress> {\n await this.versionCheckPromise;\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(accountIndex, 0);\n const response = await this.transport.send(\n CLA,\n GET_ADDRESS,\n verify ? 0x01 : 0x00,\n 0x00,\n buffer,\n );\n const addressLength = response[0];\n return response.subarray(1, 1 + addressLength).toString('ascii') as Encoded.AccountAddress;\n }\n\n /**\n * Get an instance of AccountLedger for a given account index.\n * @param accountIndex - Index of account\n */\n async initialize(accountIndex: number): Promise<AccountLedger> {\n await this.versionCheckPromise;\n return new AccountLedger(this.transport, accountIndex, await this.getAddress(accountIndex));\n }\n\n /**\n * Discovers accounts on Ledger that already have been used (has any on-chain transactions).\n * It returns an empty array if none of accounts been used.\n * If a used account is preceded by an unused account then it would be ignored.\n * @param node - Instance of Node to get account information from\n */\n async discover(node: Node): Promise<AccountLedger[]> {\n let index = 0;\n const result = [];\n let account;\n do {\n if (account != null) result.push(account);\n account = await this.initialize(index);\n index += 1;\n } while (await node.getAccountByPubkey(account.address).then(() => true, () => false));\n return result;\n }\n}\n"],"mappings":";;;;OACOA,aAAa,IAAIC,GAAG,EAAEC,WAAW,EAAEC,qBAAqB;AAAA,SACtDC,uBAAuB;AAAA,OAEzBC,eAAe;AAGtB;AACA;AACA;AACA,eAAe,MAAMC,oBAAoB,CAAC;EAKxC;AACF;AACA;EACEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,IAAI,CAACA,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,mBAAmB,GAAG,IAAI,CAACC,mBAAmB,EAAE,CAACC,IAAI,CAACC,IAAA,IAAiB;MAAA,IAAhB;QAAEC;MAAQ,CAAC,GAAAD,IAAA;MACrE,MAAME,IAAI,GAAG,CAACD,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU;MACjD,IAAI,CAACR,eAAe,CAAC,GAAGS,IAAI,CAAC,EAAE,MAAM,IAAIV,uBAAuB,CAAC,eAAe,EAAE,GAAGU,IAAI,CAAC;IAC5F,CAAC,CAAC;IACF,MAAMC,WAAW,GAAG,KAAK;IACzBP,SAAS,CAACQ,qBAAqB,CAAC,IAAI,EAAE,CAAC,YAAY,EAAE,qBAAqB,CAAC,EAAED,WAAW,CAAC;EAC3F;;EAEA;AACF;AACA;EACE,MAAML,mBAAmBA,CAAA,EAAiC;IACxD,MAAM,IAAI,CAACD,mBAAmB;IAC9B,MAAMQ,QAAQ,GAAG,MAAM,IAAI,CAACT,SAAS,CAACU,IAAI,CAACjB,GAAG,EA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;IACX,GAAG;MACD,IAAIA,OAAO,IAAI,IAAI,EAAED,MAAM,CAACE,IAAI,CAACD,OAAO,CAAC;MACzCA,OAAO,GAAG,MAAM,IAAI,CAACL,UAAU,CAACG,KAAK,CAAC;MACtCA,KAAK,IAAI,CAAC;IACZ,CAAC,QAAQ,MAAMD,IAAI,CAACK,kBAAkB,CAACF,OAAO,CAACG,OAAO,CAAC,CAAC9B,IAAI,CAAC,MAAM,IAAI,EAAE,MAAM,KAAK,CAAC;IACrF,OAAO0B,MAAM;EACf;AACF"}
1
+ {"version":3,"file":"LedgerFactory.mjs","names":["AccountLedger","CLA","GET_ADDRESS","GET_APP_CONFIGURATION","UnsupportedVersionError","semverSatisfies","AccountLedgerFactory","constructor","transport","versionCheckPromise","getAppConfiguration","then","_ref","version","args","scrambleKey","decorateAppAPIMethods","response","send","join","getAddress","accountIndex","verify","arguments","length","undefined","buffer","_Buffer","alloc","writeUInt32BE","addressLength","subarray","toString","initialize","discover","node","index","result","account","push","getAccountByPubkey","address"],"sources":["../../src/account/LedgerFactory.ts"],"sourcesContent":["import type Transport from '@ledgerhq/hw-transport';\nimport AccountLedger, { CLA, GET_ADDRESS, GET_APP_CONFIGURATION } from './Ledger';\nimport { UnsupportedVersionError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport semverSatisfies from '../utils/semver-satisfies';\nimport Node from '../Node';\n\n/**\n * A factory class that generates instances of AccountLedger based on provided transport.\n */\nexport default class AccountLedgerFactory {\n readonly transport: Transport;\n\n private readonly versionCheckPromise: Promise<void>;\n\n /**\n * @param transport - Connection to Ledger to use\n */\n constructor(transport: Transport) {\n this.transport = transport;\n this.versionCheckPromise = this.getAppConfiguration().then(({ version }) => {\n const args = [version, '0.4.4', '0.5.0'] as const;\n if (!semverSatisfies(...args)) throw new UnsupportedVersionError('app on ledger', ...args);\n });\n const scrambleKey = 'w0w';\n transport.decorateAppAPIMethods(this, ['getAddress', 'getAppConfiguration'], scrambleKey);\n }\n\n /**\n * @returns the version of app installed on Ledger wallet\n */\n async getAppConfiguration(): Promise<{ version: string }> {\n await this.versionCheckPromise;\n const response = await this.transport.send(CLA, GET_APP_CONFIGURATION, 0x00, 0x00);\n return {\n version: [response[1], response[2], response[3]].join('.'),\n };\n }\n\n /**\n * Get `ak_`-prefixed address for a given account index.\n * @param accountIndex - Index of account\n * @param verify - Ask user to confirm address by showing it on the device screen\n */\n async getAddress(accountIndex: number, verify = false): Promise<Encoded.AccountAddress> {\n await this.versionCheckPromise;\n const buffer = Buffer.alloc(4);\n buffer.writeUInt32BE(accountIndex, 0);\n const response = await this.transport.send(\n CLA,\n GET_ADDRESS,\n verify ? 0x01 : 0x00,\n 0x00,\n buffer,\n );\n const addressLength = response[0];\n return response.subarray(1, 1 + addressLength).toString('ascii') as Encoded.AccountAddress;\n }\n\n /**\n * Get an instance of AccountLedger for a given account index.\n * @param accountIndex - Index of account\n */\n async initialize(accountIndex: number): Promise<AccountLedger> {\n await this.versionCheckPromise;\n return new AccountLedger(this.transport, accountIndex, await this.getAddress(accountIndex));\n }\n\n /**\n * Discovers accounts on Ledger that already have been used (has any on-chain transactions).\n * It returns an empty array if none of accounts been used.\n * If a used account is preceded by an unused account then it would be ignored.\n * @param node - Instance of Node to get account information from\n */\n async discover(node: Node): Promise<AccountLedger[]> {\n let index = 0;\n const result = [];\n let account;\n do {\n if (account != null) result.push(account);\n account = await this.initialize(index);\n index += 1;\n } while (await node.getAccountByPubkey(account.address).then(() => true, () => false));\n return result;\n }\n}\n"],"mappings":";;;;OACOA,aAAa,IAAIC,GAAG,EAAEC,WAAW,EAAEC,qBAAqB;AAAA,SACtDC,uBAAuB;AAAA,OAEzBC,eAAe;AAGtB;AACA;AACA;AACA,eAAe,MAAMC,oBAAoB,CAAC;EAKxC;AACF;AACA;EACEC,WAAWA,CAACC,SAAoB,EAAE;IAChC,IAAI,CAACA,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,mBAAmB,GAAG,IAAI,CAACC,mBAAmB,CAAC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AAI,GAAG,IAAI,EACpB,IAAI,EACJI,MACF,CAAC;IACD,MAAMI,aAAa,GAAGb,QAAQ,CAAC,CAAC,CAAC;IACjC,OAAOA,QAAQ,CAACc,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAGD,aAAa,CAAC,CAACE,QAAQ,CAAC,OAAO,CAAC;EAClE;;EAEA;AACF;AACA;AACA;EACE,MAAMC,UAAUA,CAACZ,YAAoB,EAA0B;IAC7D,MAAM,IAAI,CAACZ,mBAAmB;IAC9B,OAAO,IAAIT,aAAa,CAAC,IAAI,CAACQ,SAAS,EAAEa,YAAY,EAAE,MAAM,IAAI,CAACD,UAAU,CAACC,YAAY,CAAC,CAAC;EAC7F;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,MAAMa,QAAQA,CAACC,IAAU,EAA4B;IACnD,IAAIC,KAAK,GAAG,CAAC;IACb,MAAMC,MAAM,GAAG,EAAE;IACjB,IAAIC,OAAO;IACX,GAAG;MACD,IAAIA,OAAO,IAAI,IAAI,EAAED,MAAM,CAACE,IAAI,CAACD,OAAO,CAAC;MACzCA,OAAO,GAAG,MAAM,IAAI,CAACL,UAAU,CAACG,KAAK,CAAC;MACtCA,KAAK,IAAI,CAAC;IACZ,CAAC,QAAQ,MAAMD,IAAI,CAACK,kBAAkB,CAACF,OAAO,CAACG,OAAO,CAAC,CAAC9B,IAAI,CAAC,MAAM,IAAI,EAAE,MAAM,KAAK,CAAC;IACrF,OAAO0B,MAAM;EACf;AACF"}
@@ -1,5 +1,7 @@
1
1
  import AccountBase from './Base';
2
2
  import { Encoded } from '../utils/encoder';
3
+ import { AciValue } from '../utils/typed-data';
4
+ import { AensName } from '../tx/builder/constants';
3
5
  export declare function getBufferToSign(transaction: Encoded.Transaction, networkId: string, innerTx: boolean): Uint8Array;
4
6
  /**
5
7
  * In-memory account class
@@ -20,4 +22,14 @@ export default class AccountMemory extends AccountBase {
20
22
  networkId?: string;
21
23
  }): Promise<Encoded.Transaction>;
22
24
  signMessage(message: string, options?: any): Promise<Uint8Array>;
25
+ signTypedData(data: Encoded.ContractBytearray, aci: AciValue, { name, version, networkId, contractAddress, ...options }?: Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
26
+ signDelegationToContract(contractAddress: Encoded.ContractAddress, { networkId }?: {
27
+ networkId?: string;
28
+ }): Promise<Encoded.Signature>;
29
+ signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName, { networkId }?: {
30
+ networkId?: string;
31
+ }): Promise<Encoded.Signature>;
32
+ signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId, { networkId }?: {
33
+ networkId?: string;
34
+ }): Promise<Encoded.Signature>;
23
35
  }
@@ -7,8 +7,10 @@ import { generateKeyPairFromSecret, sign, generateKeyPair, hash, messageToHash }
7
7
  import { ArgumentError } from "../utils/errors.mjs";
8
8
  import { decode, encode, Encoding } from "../utils/encoder.mjs";
9
9
  import { concatBuffers } from "../utils/other.mjs";
10
+ import { hashTypedData } from "../utils/typed-data.mjs";
10
11
  import { buildTx } from "../tx/builder/index.mjs";
11
12
  import { Tag } from "../tx/builder/constants.mjs";
13
+ import { produceNameId } from "../tx/builder/helpers.mjs";
12
14
  const secretKeys = new WeakMap();
13
15
  export function getBufferToSign(transaction, networkId, innerTx) {
14
16
  const prefixes = [networkId];
@@ -66,5 +68,55 @@ export default class AccountMemory extends AccountBase {
66
68
  async signMessage(message, options) {
67
69
  return this.sign(messageToHash(message), options);
68
70
  }
71
+ async signTypedData(data, aci) {
72
+ let {
73
+ name,
74
+ version,
75
+ networkId,
76
+ contractAddress,
77
+ ...options
78
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
79
+ const dHash = hashTypedData(data, aci, {
80
+ name,
81
+ version,
82
+ networkId,
83
+ contractAddress
84
+ });
85
+ const signature = await this.sign(dHash, options);
86
+ return encode(signature, Encoding.Signature);
87
+ }
88
+ async signDelegationToContract(contractAddress) {
89
+ let {
90
+ networkId
91
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
92
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
93
+ const payload = concatBuffers([_Buffer.from(networkId), decode(this.address), decode(contractAddress)]);
94
+ const signature = await this.sign(payload);
95
+ return encode(signature, Encoding.Signature);
96
+ }
97
+ async signNameDelegationToContract(contractAddress, name) {
98
+ let {
99
+ networkId
100
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
101
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
102
+ const payload = concatBuffers([_Buffer.from(networkId), decode(this.address), decode(produceNameId(name)), decode(contractAddress)]);
103
+ const signature = await this.sign(payload);
104
+ return encode(signature, Encoding.Signature);
105
+ }
106
+ async signOracleQueryDelegationToContract(contractAddress, oracleQueryId) {
107
+ let {
108
+ networkId
109
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
110
+ const oracleQueryIdDecoded = decode(oracleQueryId);
111
+ const addressDecoded = decode(this.address);
112
+ // TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475
113
+ if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {
114
+ throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);
115
+ }
116
+ if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
117
+ const payload = concatBuffers([_Buffer.from(networkId), oracleQueryIdDecoded, decode(contractAddress)]);
118
+ const signature = await this.sign(payload);
119
+ return encode(signature, Encoding.Signature);
120
+ }
69
121
  }
70
122
  //# sourceMappingURL=Memory.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Memory.mjs","names":["AccountBase","generateKeyPairFromSecret","sign","generateKeyPair","hash","messageToHash","ArgumentError","decode","encode","Encoding","concatBuffers","buildTx","Tag","secretKeys","WeakMap","getBufferToSign","transaction","networkId","innerTx","prefixes","push","rlpBinaryTx","_Buffer","from","join","AccountMemory","constructor","secretKey","length","set","address","get","publicKey","AccountAddress","generate","data","options","signTransaction","arguments","undefined","txWithNetworkId","signatures","tag","SignedTx","encodedTx","signMessage","message"],"sources":["../../src/account/Memory.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n generateKeyPairFromSecret, sign, generateKeyPair, hash, messageToHash,\n} from '../utils/crypto';\nimport { ArgumentError } from '../utils/errors';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../utils/encoder';\nimport { concatBuffers } from '../utils/other';\nimport { buildTx } from '../tx/builder';\nimport { Tag } from '../tx/builder/constants';\n\nconst secretKeys = new WeakMap();\n\nexport function getBufferToSign(\n transaction: Encoded.Transaction,\n networkId: string,\n innerTx: boolean,\n): Uint8Array {\n const prefixes = [networkId];\n if (innerTx) prefixes.push('inner_tx');\n const rlpBinaryTx = decode(transaction);\n return concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);\n}\n\n/**\n * In-memory account class\n */\nexport default class AccountMemory extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n /**\n * @param secretKey - Secret key\n */\n constructor(secretKey: string | Uint8Array) {\n super();\n secretKey = typeof secretKey === 'string' ? Buffer.from(secretKey, 'hex') : secretKey;\n if (secretKey.length !== 64) {\n throw new ArgumentError('secretKey', '64 bytes', secretKey.length);\n }\n secretKeys.set(this, secretKey);\n this.address = encode(\n generateKeyPairFromSecret(secretKeys.get(this)).publicKey,\n Encoding.AccountAddress,\n );\n }\n\n /**\n * Generates a new AccountMemory using a random secret key\n */\n static generate(): AccountMemory {\n return new AccountMemory(generateKeyPair().secretKey);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async sign(data: string | Uint8Array, options?: any): Promise<Uint8Array> {\n return sign(data, secretKeys.get(this));\n }\n\n override async signTransaction(\n transaction: Encoded.Transaction,\n { innerTx, networkId, ...options }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) {\n throw new ArgumentError('networkId', 'provided', networkId);\n }\n const rlpBinaryTx = decode(transaction);\n const txWithNetworkId = getBufferToSign(transaction, networkId, innerTx === true);\n\n const signatures = [await this.sign(txWithNetworkId, options)];\n return buildTx({ tag: Tag.SignedTx, encodedTx: rlpBinaryTx, signatures });\n }\n\n override async signMessage(message: string, options?: any): Promise<Uint8Array> {\n return this.sign(messageToHash(message), options);\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,yBAAyB,EAAEC,IAAI,EAAEC,eAAe,EAAEC,IAAI,EAAEC,aAAa;AAAA,SAE9DC,aAAa;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,aAAa;AAAA,SACbC,OAAO;AAAA,SACPC,GAAG;AAEZ,MAAMC,UAAU,GAAG,IAAIC,OAAO,EAAE;AAEhC,OAAO,SAASC,eAAeA,CAC7BC,WAAgC,EAChCC,SAAiB,EACjBC,OAAgB,EACJ;EACZ,MAAMC,QAAQ,GAAG,CAACF,SAAS,CAAC;EAC5B,IAAIC,OAAO,EAAEC,QAAQ,CAACC,IAAI,CAAC,UAAU,CAAC;EACtC,MAAMC,WAAW,GAAGd,MAAM,CAACS,WAAW,CAAC;EACvC,OAAON,aAAa,CAAC,CAACY,OAAA,CAAOC,IAAI,CAACJ,QAAQ,CAACK,IAAI,CAAC,GAAG,CAAC,CAAC,EAAEpB,IAAI,CAACiB,WAAW,CAAC,CAAC,CAAC;AAC5E;;AAEA;AACA;AACA;AACA,eAAe,MAAMI,aAAa,SAASzB,WAAW,CAAC;EAGrD;AACF;AACA;EACE0B,WAAWA,CAACC,SAA8B,EAAE;IAC1C,KAAK,EAAE;IACPA,SAAS,GAAG,OAAOA,SAAS,KAAK,QAAQ,GAAGL,OAAA,CAAOC,IAAI,CAACI,SAAS,EAAE,KAAK,CAAC,GAAGA,SAAS;IACrF,IAAIA,SAAS,CAACC,MAAM,KAAK,EAAE,EAAE;MAC3B,MAAM,IAAItB,aAAa,CAAC,WAAW,EAAE,UAAU,EAAEqB,SAAS,CAACC,MAAM,CAAC;IACp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AO,IAAI,CAAClC,IAAI,CAACG,aAAa,CAACyC,OAAO,CAAC,EAAEV,OAAO,CAAC;EACnD;AACF"}
1
+ {"version":3,"file":"Memory.mjs","names":["AccountBase","generateKeyPairFromSecret","sign","generateKeyPair","hash","messageToHash","ArgumentError","decode","encode","Encoding","concatBuffers","hashTypedData","buildTx","Tag","produceNameId","secretKeys","WeakMap","getBufferToSign","transaction","networkId","innerTx","prefixes","push","rlpBinaryTx","_Buffer","from","join","AccountMemory","constructor","secretKey","length","set","address","get","publicKey","AccountAddress","generate","data","options","signTransaction","arguments","undefined","txWithNetworkId","signatures","tag","SignedTx","encodedTx","signMessage","message","signTypedData","aci","name","version","contractAddress","dHash","signature","Signature","signDelegationToContract","payload","signNameDelegationToContract","signOracleQueryDelegationToContract","oracleQueryId","oracleQueryIdDecoded","addressDecoded","compare"],"sources":["../../src/account/Memory.ts"],"sourcesContent":["import AccountBase from './Base';\nimport {\n generateKeyPairFromSecret, sign, generateKeyPair, hash, messageToHash,\n} from '../utils/crypto';\nimport { ArgumentError } from '../utils/errors';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../utils/encoder';\nimport { concatBuffers } from '../utils/other';\nimport { hashTypedData, AciValue } from '../utils/typed-data';\nimport { buildTx } from '../tx/builder';\nimport { Tag, AensName } from '../tx/builder/constants';\nimport { produceNameId } from '../tx/builder/helpers';\n\nconst secretKeys = new WeakMap();\n\nexport function getBufferToSign(\n transaction: Encoded.Transaction,\n networkId: string,\n innerTx: boolean,\n): Uint8Array {\n const prefixes = [networkId];\n if (innerTx) prefixes.push('inner_tx');\n const rlpBinaryTx = decode(transaction);\n return concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);\n}\n\n/**\n * In-memory account class\n */\nexport default class AccountMemory extends AccountBase {\n override readonly address: Encoded.AccountAddress;\n\n /**\n * @param secretKey - Secret key\n */\n constructor(secretKey: string | Uint8Array) {\n super();\n secretKey = typeof secretKey === 'string' ? Buffer.from(secretKey, 'hex') : secretKey;\n if (secretKey.length !== 64) {\n throw new ArgumentError('secretKey', '64 bytes', secretKey.length);\n }\n secretKeys.set(this, secretKey);\n this.address = encode(\n generateKeyPairFromSecret(secretKeys.get(this)).publicKey,\n Encoding.AccountAddress,\n );\n }\n\n /**\n * Generates a new AccountMemory using a random secret key\n */\n static generate(): AccountMemory {\n return new AccountMemory(generateKeyPair().secretKey);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async sign(data: string | Uint8Array, options?: any): Promise<Uint8Array> {\n return sign(data, secretKeys.get(this));\n }\n\n override async signTransaction(\n transaction: Encoded.Transaction,\n { innerTx, networkId, ...options }: { innerTx?: boolean; networkId?: string } = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) {\n throw new ArgumentError('networkId', 'provided', networkId);\n }\n const rlpBinaryTx = decode(transaction);\n const txWithNetworkId = getBufferToSign(transaction, networkId, innerTx === true);\n\n const signatures = [await this.sign(txWithNetworkId, options)];\n return buildTx({ tag: Tag.SignedTx, encodedTx: rlpBinaryTx, signatures });\n }\n\n override async signMessage(message: string, options?: any): Promise<Uint8Array> {\n return this.sign(messageToHash(message), options);\n }\n\n override async signTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n {\n name, version, networkId, contractAddress, ...options\n }: Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n const dHash = hashTypedData(data, aci, {\n name, version, networkId, contractAddress,\n });\n const signature = await this.sign(dHash, options);\n return encode(signature, Encoding.Signature);\n }\n\n override async signDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n { networkId }: { networkId?: string } = {},\n ): Promise<Encoded.Signature> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const payload = concatBuffers([\n Buffer.from(networkId),\n decode(this.address),\n decode(contractAddress),\n ]);\n const signature = await this.sign(payload);\n return encode(signature, Encoding.Signature);\n }\n\n override async signNameDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n { networkId }: { networkId?: string } = {},\n ): Promise<Encoded.Signature> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const payload = concatBuffers([\n Buffer.from(networkId),\n decode(this.address),\n decode(produceNameId(name)),\n decode(contractAddress),\n ]);\n const signature = await this.sign(payload);\n return encode(signature, Encoding.Signature);\n }\n\n override async signOracleQueryDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n { networkId }: { networkId?: string } = {},\n ): Promise<Encoded.Signature> {\n const oracleQueryIdDecoded = decode(oracleQueryId);\n const addressDecoded = decode(this.address);\n // TODO: remove after fixing https://github.com/aeternity/aesophia/issues/475\n if (oracleQueryIdDecoded.compare(addressDecoded) === 0) {\n throw new ArgumentError('oracleQueryId', 'not equal to account address', oracleQueryId);\n }\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const payload = concatBuffers([\n Buffer.from(networkId),\n oracleQueryIdDecoded,\n decode(contractAddress),\n ]);\n const signature = await this.sign(payload);\n return encode(signature, Encoding.Signature);\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SAEhBC,yBAAyB,EAAEC,IAAI,EAAEC,eAAe,EAAEC,IAAI,EAAEC,aAAa;AAAA,SAE9DC,aAAa;AAAA,SAEpBC,MAAM,EAAEC,MAAM,EAAWC,QAAQ;AAAA,SAE1BC,aAAa;AAAA,SACbC,aAAa;AAAA,SACbC,OAAO;AAAA,SACPC,GAAG;AAAA,SACHC,aAAa;AAEtB,MAAMC,UAAU,GAAG,IAAIC,OAAO,CAAC,CAAC;AAEhC,OAAO,SAASC,eAAeA,CAC7BC,WAAgC,EAChCC,SAAiB,EACjBC,OAAgB,EACJ;EACZ,MAAMC,QAAQ,GAAG,CAACF,SAAS,CAAC;EAC5B,IAAIC,OAAO,EAAEC,QAAQ,CAACC,IAAI,CAAC,UAAU,CAAC;EACtC,MAAMC,WAAW,GAAGhB,MAAM,CAACW,WAAW,CAAC;EACvC,OAAOR,aAAa,CAAC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MAAE1C;IAAkC,CAAC,GAAAqB,SAAA,CAAAV,MAAA,QAAAU,SAAA,QAAAC,SAAA,GAAAD,SAAA,MAAG,CAAC,CAAC;IAE1C,MAAMsB,oBAAoB,GAAGvD,MAAM,CAACsD,aAAa,CAAC;IAClD,MAAME,cAAc,GAAGxD,MAAM,CAAC,IAAI,CAACyB,OAAO,CAAC;IAC3C;IACA,IAAI8B,oBAAoB,CAACE,OAAO,CAACD,cAAc,CAAC,KAAK,CAAC,EAAE;MACtD,MAAM,IAAIzD,aAAa,CAAC,eAAe,EAAE,8BAA8B,EAAEuD,aAAa,CAAC;IACzF;IACA,IAAI1C,SAAS,IAAI,IAAI,EAAE,MAAM,IAAIb,aAAa,CAAC,WAAW,EAAE,UAAU,EAAEa,SAAS,CAAC;IAClF,MAAMuC,OAAO,GAAGhD,aAAa,CAAC,CAC5Bc,OAAA,CAAOC,IAAI,CAACN,SAAS,CAAC,EACtB2C,oBAAoB,EACpBvD,MAAM,CAAC8C,eAAe,CAAC,CACxB,CAAC;IACF,MAAME,SAAS,GAAG,MAAM,IAAI,CAACrD,IAAI,CAACwD,OAAO,CAAC;IAC1C,OAAOlD,MAAM,CAAC+C,SAAS,EAAE9C,QAAQ,CAAC+C,SAAS,CAAC;EAC9C;AACF"}
@@ -2,6 +2,7 @@ import AccountBase from './Base';
2
2
  import { Encoded } from '../utils/encoder';
3
3
  import RpcClient from '../aepp-wallet-communication/rpc/RpcClient';
4
4
  import { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';
5
+ import { AensName } from '../tx/builder/constants';
5
6
  /**
6
7
  * Account provided by wallet
7
8
  * @param params - Params
@@ -14,12 +15,10 @@ export default class AccountRpc extends AccountBase {
14
15
  readonly address: Encoded.AccountAddress;
15
16
  constructor(rpcClient: RpcClient<WalletApi, AeppApi>, address: Encoded.AccountAddress);
16
17
  sign(): Promise<Uint8Array>;
17
- /**
18
- * @returns Signed transaction
19
- */
20
18
  signTransaction(tx: Encoded.Transaction, { innerTx, networkId }?: Parameters<AccountBase['signTransaction']>[1]): Promise<Encoded.Transaction>;
21
- /**
22
- * @returns Signed message
23
- */
24
19
  signMessage(message: string): Promise<Uint8Array>;
20
+ signTypedData(data: Encoded.ContractBytearray, aci: Parameters<AccountBase['signTypedData']>[1], { name, version, contractAddress, networkId, }?: Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
21
+ signDelegationToContract(contractAddress: Encoded.ContractAddress): Promise<Encoded.Signature>;
22
+ signNameDelegationToContract(contractAddress: Encoded.ContractAddress, name: AensName): Promise<Encoded.Signature>;
23
+ signOracleQueryDelegationToContract(contractAddress: Encoded.ContractAddress, oracleQueryId: Encoded.OracleQueryId): Promise<Encoded.Signature>;
25
24
  }
@@ -23,32 +23,24 @@ export default class AccountRpc extends AccountBase {
23
23
  async sign() {
24
24
  throw new NotImplementedError('RAW signing using wallet');
25
25
  }
26
-
27
- /**
28
- * @returns Signed transaction
29
- */
30
26
  async signTransaction(tx) {
31
27
  let {
32
28
  innerTx,
33
29
  networkId
34
30
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
35
- if (innerTx != null) throw new NotImplementedError('innerTx option in AccountRpc');
36
31
  if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);
37
32
  const res = await this._rpcClient.request(METHODS.sign, {
38
33
  onAccount: this.address,
39
34
  tx,
40
35
  returnSigned: true,
41
- networkId
36
+ networkId,
37
+ innerTx
42
38
  });
43
39
  if (res.signedTransaction == null) {
44
40
  throw new UnsupportedProtocolError('signedTransaction is missed in wallet response');
45
41
  }
46
42
  return res.signedTransaction;
47
43
  }
48
-
49
- /**
50
- * @returns Signed message
51
- */
52
44
  async signMessage(message) {
53
45
  const {
54
46
  signature
@@ -58,5 +50,56 @@ export default class AccountRpc extends AccountBase {
58
50
  });
59
51
  return _Buffer.from(signature, 'hex');
60
52
  }
53
+ async signTypedData(data, aci) {
54
+ let {
55
+ name,
56
+ version,
57
+ contractAddress,
58
+ networkId
59
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
60
+ const {
61
+ signature
62
+ } = await this._rpcClient.request(METHODS.signTypedData, {
63
+ onAccount: this.address,
64
+ domain: {
65
+ name,
66
+ version,
67
+ networkId,
68
+ contractAddress
69
+ },
70
+ aci,
71
+ data
72
+ });
73
+ return signature;
74
+ }
75
+ async signDelegationToContract(contractAddress) {
76
+ const {
77
+ signature
78
+ } = await this._rpcClient.request(METHODS.signDelegationToContract, {
79
+ onAccount: this.address,
80
+ contractAddress
81
+ });
82
+ return signature;
83
+ }
84
+ async signNameDelegationToContract(contractAddress, name) {
85
+ const {
86
+ signature
87
+ } = await this._rpcClient.request(METHODS.signDelegationToContract, {
88
+ onAccount: this.address,
89
+ contractAddress,
90
+ name
91
+ });
92
+ return signature;
93
+ }
94
+ async signOracleQueryDelegationToContract(contractAddress, oracleQueryId) {
95
+ const {
96
+ signature
97
+ } = await this._rpcClient.request(METHODS.signDelegationToContract, {
98
+ onAccount: this.address,
99
+ contractAddress,
100
+ oracleQueryId
101
+ });
102
+ return signature;
103
+ }
61
104
  }
62
105
  //# sourceMappingURL=Rpc.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Rpc.mjs","names":["AccountBase","METHODS","ArgumentError","NotImplementedError","UnsupportedProtocolError","AccountRpc","constructor","rpcClient","address","_rpcClient","sign","signTransaction","tx","innerTx","networkId","arguments","length","undefined","res","request","onAccount","returnSigned","signedTransaction","signMessage","message","signature","_Buffer","from"],"sources":["../../src/account/Rpc.ts"],"sourcesContent":["import AccountBase from './Base';\nimport { METHODS } from '../aepp-wallet-communication/schema';\nimport { ArgumentError, NotImplementedError, UnsupportedProtocolError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport RpcClient from '../aepp-wallet-communication/rpc/RpcClient';\nimport { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';\n\n/**\n * Account provided by wallet\n * @param params - Params\n * @param params.rpcClient - RpcClient instance\n * @param params.address - RPC account address\n * @returns AccountRpc instance\n */\nexport default class AccountRpc extends AccountBase {\n _rpcClient: RpcClient<WalletApi, AeppApi>;\n\n override readonly address: Encoded.AccountAddress;\n\n constructor(rpcClient: RpcClient<WalletApi, AeppApi>, address: Encoded.AccountAddress) {\n super();\n this._rpcClient = rpcClient;\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using wallet');\n }\n\n /**\n * @returns Signed transaction\n */\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n if (innerTx != null) throw new NotImplementedError('innerTx option in AccountRpc');\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const res = await this._rpcClient.request(METHODS.sign, {\n onAccount: this.address,\n tx,\n returnSigned: true,\n networkId,\n });\n if (res.signedTransaction == null) {\n throw new UnsupportedProtocolError('signedTransaction is missed in wallet response');\n }\n return res.signedTransaction;\n }\n\n /**\n * @returns Signed message\n */\n override async signMessage(message: string): Promise<Uint8Array> {\n const { signature } = await this._rpcClient\n .request(METHODS.signMessage, { onAccount: this.address, message });\n return Buffer.from(signature, 'hex');\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SACTC,OAAO;AAAA,SACPC,aAAa,EAAEC,mBAAmB,EAAEC,wBAAwB;AAKrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,UAAU,SAASL,WAAW,CAAC;EAKlDM,WAAWA,CAACC,SAAwC,EAAEC,OAA+B,EAAE;IACrF,KAAK,EAAE;IACP,IAAI,CAACC,UAAU,GAAGF,SAAS;IAC3B,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;;EAEA;EACA,MAAME,IAAIA,CAAA,EAAwB;IAChC,MAAM,IAAIP,mBAAmB,CAAC,0BAA0B,CAAC;EAC3D;;EAEA;AACF;AACA;EACE,MAAeQ,eAAeA,CAC5BC,EAAuB,EAEO;IAAA,IAD9B;MAAEC,OAAO;MAAEC;IAAyD,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAE1E,IAAIF,OAAO,IAAI,IAAI,EAAE,MAAM,IAAIV,mBAAmB,CAAC,8BAA8B,CAAC;IAClF,IAAIW,SAAS,IAAI,IAAI,EAAE,MAAM,IAAIZ,aAAa,CAAC,WAAW,EAAE,UAAU,EAAEY,SAAS,CAAC;IAClF,MAAMI,GAAG,GAAG,MAAM,IAAI,CAACT,UAAU,CAACU,OAAO,CAAClB,OAAO,CAACS,IAAI,EAAE;MACtDU,SAAS,EAAE,IAAI,CAACZ,OAAO;MACvBI,EAAE;MACFS,YAAY,EAAE,IAAI;MAClBP;IACF,CAAC,CAAC;IACF,IAAII,GAAG,CAACI,iBAAiB,IAAI,IAAI,EAAE;MACjC,MAAM,IAAIlB,wBAAwB,CAAC,gDAAgD,CAAC;IACtF;IACA,OAAOc,GAAG,CAACI,iBAAiB;EAC9B;;EAEA;AACF;AACA;EACE,MAAeC,WAAWA,CAACC,OAAe,EAAuB;IAC/D,MAAM;MAAEC;IAAU,CAAC,GAAG,MAAM,IAAI,CAAChB,UAAU,CACxCU,OAAO,CAAClB,OAAO,CAACsB,WAAW,EAAE;MAAEH,SAAS,EAAE,IAAI,CAACZ,OAAO;MAAEgB;IAAQ,CAAC,CAAC;IACrE,OAAOE,OAAA,CAAOC,IAAI,CAACF,SAAS,EAAE,KAAK,CAAC;EACtC;AACF"}
1
+ {"version":3,"file":"Rpc.mjs","names":["AccountBase","METHODS","ArgumentError","NotImplementedError","UnsupportedProtocolError","AccountRpc","constructor","rpcClient","address","_rpcClient","sign","signTransaction","tx","innerTx","networkId","arguments","length","undefined","res","request","onAccount","returnSigned","signedTransaction","signMessage","message","signature","_Buffer","from","signTypedData","data","aci","name","version","contractAddress","domain","signDelegationToContract","signNameDelegationToContract","signOracleQueryDelegationToContract","oracleQueryId"],"sources":["../../src/account/Rpc.ts"],"sourcesContent":["import AccountBase from './Base';\nimport { METHODS } from '../aepp-wallet-communication/schema';\nimport { ArgumentError, NotImplementedError, UnsupportedProtocolError } from '../utils/errors';\nimport { Encoded } from '../utils/encoder';\nimport RpcClient from '../aepp-wallet-communication/rpc/RpcClient';\nimport { AeppApi, WalletApi } from '../aepp-wallet-communication/rpc/types';\nimport { AensName } from '../tx/builder/constants';\n\n/**\n * Account provided by wallet\n * @param params - Params\n * @param params.rpcClient - RpcClient instance\n * @param params.address - RPC account address\n * @returns AccountRpc instance\n */\nexport default class AccountRpc extends AccountBase {\n _rpcClient: RpcClient<WalletApi, AeppApi>;\n\n override readonly address: Encoded.AccountAddress;\n\n constructor(rpcClient: RpcClient<WalletApi, AeppApi>, address: Encoded.AccountAddress) {\n super();\n this._rpcClient = rpcClient;\n this.address = address;\n }\n\n // eslint-disable-next-line class-methods-use-this\n async sign(): Promise<Uint8Array> {\n throw new NotImplementedError('RAW signing using wallet');\n }\n\n override async signTransaction(\n tx: Encoded.Transaction,\n { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {},\n ): Promise<Encoded.Transaction> {\n if (networkId == null) throw new ArgumentError('networkId', 'provided', networkId);\n const res = await this._rpcClient.request(METHODS.sign, {\n onAccount: this.address,\n tx,\n returnSigned: true,\n networkId,\n innerTx,\n });\n if (res.signedTransaction == null) {\n throw new UnsupportedProtocolError('signedTransaction is missed in wallet response');\n }\n return res.signedTransaction;\n }\n\n override async signMessage(message: string): Promise<Uint8Array> {\n const { signature } = await this._rpcClient\n .request(METHODS.signMessage, { onAccount: this.address, message });\n return Buffer.from(signature, 'hex');\n }\n\n override async signTypedData(\n data: Encoded.ContractBytearray,\n aci: Parameters<AccountBase['signTypedData']>[1],\n {\n name, version, contractAddress, networkId,\n }: Parameters<AccountBase['signTypedData']>[2] = {},\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signTypedData, {\n onAccount: this.address,\n domain: {\n name, version, networkId, contractAddress,\n },\n aci,\n data,\n });\n return signature;\n }\n\n override async signDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {\n onAccount: this.address,\n contractAddress,\n });\n return signature;\n }\n\n override async signNameDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n name: AensName,\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {\n onAccount: this.address,\n contractAddress,\n name,\n });\n return signature;\n }\n\n override async signOracleQueryDelegationToContract(\n contractAddress: Encoded.ContractAddress,\n oracleQueryId: Encoded.OracleQueryId,\n ): Promise<Encoded.Signature> {\n const { signature } = await this._rpcClient.request(METHODS.signDelegationToContract, {\n onAccount: this.address,\n contractAddress,\n oracleQueryId,\n });\n return signature;\n }\n}\n"],"mappings":";;;;OAAOA,WAAW;AAAA,SACTC,OAAO;AAAA,SACPC,aAAa,EAAEC,mBAAmB,EAAEC,wBAAwB;AAMrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,UAAU,SAASL,WAAW,CAAC;EAKlDM,WAAWA,CAACC,SAAwC,EAAEC,OAA+B,EAAE;IACrF,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,UAAU,GAAGF,SAAS;IAC3B,IAAI,CAACC,OAAO,GAAGA,OAAO;EACxB;;EAEA;EACA,MAAME,IAAIA,CAAA,EAAwB;IAChC,MAAM,IAAIP,mBAAmB,CAAC,0BAA0B,CAAC;EAC3D;EAEA,MAAeQ,eAAeA,CAC5BC,EAAuB,EAEO;IAAA,IAD9B;MAAEC,OAAO;MAAEC;IAAyD,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAE1E,IAAID,SAAS,IAAI,IAAI,EAAE,MAAM,IAAIZ,aAAa,CAAC,WAAW,EAAE,UAAU,EAAEY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AM,IAAI,CAAChB,UAAU,CAACU,OAAO,CAAClB,OAAO,CAACkC,wBAAwB,EAAE;MACpFf,SAAS,EAAE,IAAI,CAACZ,OAAO;MACvByB;IACF,CAAC,CAAC;IACF,OAAOR,SAAS;EAClB;EAEA,MAAeW,4BAA4BA,CACzCH,eAAwC,EACxCF,IAAc,EACc;IAC5B,MAAM;MAAEN;IAAU,CAAC,GAAG,MAAM,IAAI,CAAChB,UAAU,CAACU,OAAO,CAAClB,OAAO,CAACkC,wBAAwB,EAAE;MACpFf,SAAS,EAAE,IAAI,CAACZ,OAAO;MACvByB,eAAe;MACfF;IACF,CAAC,CAAC;IACF,OAAON,SAAS;EAClB;EAEA,MAAeY,mCAAmCA,CAChDJ,eAAwC,EACxCK,aAAoC,EACR;IAC5B,MAAM;MAAEb;IAAU,CAAC,GAAG,MAAM,IAAI,CAAChB,UAAU,CAACU,OAAO,CAAClB,OAAO,CAACkC,wBAAwB,EAAE;MACpFf,SAAS,EAAE,IAAI,CAACZ,OAAO;MACvByB,eAAe;MACfK;IACF,CAAC,CAAC;IACF,OAAOb,SAAS;EAClB;AACF"}
package/es/aens.d.ts CHANGED
@@ -211,7 +211,7 @@ interface AensPreclaimOptions extends BuildTxOptions<Tag.NamePreclaimTx, 'accoun
211
211
  * @example
212
212
  * ```js
213
213
  * const name = 'test.chain'
214
- * const bidFee = computeBidFee(name, startFee, incrementPercentage)
214
+ * const bidFee = computeBidFee(name, { startFee, increment: 0.42 })
215
215
  *
216
216
  * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })
217
217
  * ```
package/es/aens.mjs CHANGED
@@ -315,7 +315,7 @@ export async function aensPreclaim(name, options) {
315
315
  * @example
316
316
  * ```js
317
317
  * const name = 'test.chain'
318
- * const bidFee = computeBidFee(name, startFee, incrementPercentage)
318
+ * const bidFee = computeBidFee(name, { startFee, increment: 0.42 })
319
319
  *
320
320
  * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })
321
321
  * ```
package/es/aens.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"aens.mjs","names":["genSalt","commitmentHash","isAuctionName","CLIENT_TTL","NAME_TTL","Tag","ArgumentError","sendTransaction","getName","buildTxAsync","aensRevoke","name","options","nameRevokeTx","tag","NameRevokeTx","nameId","accountId","onAccount","address","aensUpdate","pointers","_ref","extendPointers","allPointers","Object","fromEntries","map","_ref2","key","id","nameUpdateTx","clientTtl","nameTtl","NameUpdateTx","entries","_ref3","aensTransfer","account","nameTransferTx","NameTransferTx","recipientId","aensQuery","opt","nameEntry","freeze","owner","update","transfer","revoke","extendTtl","arguments","length","undefined","aensClaim","salt","claimTx","NameClaimTx","nameSalt","result","nameInter","blockHeight","assign","aensPreclaim","commitmentId","preclaimTx","NamePreclaimTx","claim","opts","version","otherOptions","aensBid","nameFee"],"sources":["../src/aens.ts"],"sourcesContent":["/**\n * Aens methods - routines to interact with the æternity naming system\n *\n * The high-level description of the naming system is\n * https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol\n * repository.\n */\n\nimport BigNumber from 'bignumber.js';\nimport { genSalt } from './utils/crypto';\nimport { commitmentHash, isAuctionName } from './tx/builder/helpers';\nimport {\n CLIENT_TTL, NAME_TTL, Tag, AensName,\n} from './tx/builder/constants';\nimport { ArgumentError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport { sendTransaction, SendTransactionOptions, getName } from './chain';\nimport { buildTxAsync, BuildTxOptions } from './tx/builder';\nimport { TransformNodeType } from './Node';\nimport { NameEntry, NamePointer } from './apis/node';\nimport AccountBase from './account/Base';\nimport { AddressEncodings } from './tx/builder/field-types/address';\n\ninterface KeyPointers {\n [key: string]: Encoded.Generic<AddressEncodings>;\n}\n\n/**\n * Revoke a name\n * @category AENS\n * @param name - Name hash\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensRevoke(name, { fee, ttl , nonce })\n * // or\n * await nameObject.revoke({ fee, ttl, nonce })\n * ```\n */\nexport async function aensRevoke(\n name: AensName,\n options: AensRevokeOptions,\n): ReturnType<typeof sendTransaction> {\n const nameRevokeTx = await buildTxAsync({\n ...options,\n tag: Tag.NameRevokeTx,\n nameId: name,\n accountId: options.onAccount.address,\n });\n return sendTransaction(nameRevokeTx, options);\n}\n\ninterface AensRevokeOptions extends\n BuildTxOptions<Tag.NameRevokeTx, 'nameId' | 'accountId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Update a name\n * @category AENS\n * @param name - AENS name\n * @param pointers - Map of pointer keys to corresponding addresses\n * @param options - Options\n * @param options.extendPointers - Get the pointers from the node and merge with provided\n * ones. Pointers with the same type will be overwritten\n * @param options.onAccount - Make operation on specific account from sdk (you\n * pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameTtl - Name ttl represented in number of\n * blocks (Max value is 50000 blocks)\n * @param options.clientTtl=84600 a suggestion as to how long any\n * clients should cache this information\n * @throws Invalid pointer array error\n * @example\n * ```js\n * const name = 'test.chain'\n * const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })\n * // or\n * await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })\n * ```\n */\nexport async function aensUpdate(\n name: AensName,\n pointers: KeyPointers,\n { extendPointers, ...options }: AensUpdateOptions,\n): ReturnType<typeof sendTransaction> {\n const allPointers = {\n ...extendPointers === true && Object.fromEntries(\n (await getName(name, options)).pointers.map(({ key, id }) => [key, id]),\n ),\n ...pointers,\n };\n\n const nameUpdateTx = await buildTxAsync({\n clientTtl: CLIENT_TTL,\n nameTtl: NAME_TTL,\n ...options,\n tag: Tag.NameUpdateTx,\n nameId: name,\n accountId: options.onAccount.address,\n pointers: Object.entries(allPointers)\n .map(([key, id]: [string, Encoded.Generic<AddressEncodings>]) => ({ key, id })),\n });\n\n return sendTransaction(nameUpdateTx, options);\n}\n\ninterface AensUpdateOptions extends\n BuildTxOptions<Tag.NameUpdateTx, 'nameId' | 'accountId' | 'pointers' | 'clientTtl' | 'nameTtl' | 'onNode'>,\n SendTransactionOptions {\n extendPointers?: boolean;\n clientTtl?: number;\n nameTtl?: number;\n}\n\n/**\n * Transfer a domain to another account\n * @category AENS\n * @param name - AENS name\n * @param account - Recipient account publick key\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const recipientPub = 'ak_asd23dasdas...'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })\n * // or\n * await nameObject.transfer(recipientPub, { ttl, fee, nonce })\n * ```\n */\nexport async function aensTransfer(\n name: AensName,\n account: Encoded.AccountAddress,\n options: AensTransferOptions,\n): ReturnType<typeof sendTransaction> {\n const nameTransferTx = await buildTxAsync({\n ...options,\n tag: Tag.NameTransferTx,\n nameId: name,\n accountId: options.onAccount.address,\n recipientId: account,\n });\n\n return sendTransaction(nameTransferTx, options);\n}\n\ninterface AensTransferOptions extends\n BuildTxOptions<Tag.NameTransferTx, 'nameId' | 'accountId' | 'recipientId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Query the AENS name info from the node\n * and return the object with info and predefined functions for manipulating name\n * @category AENS\n * @param name - AENS name\n * @param opt - Options\n * @returns\n * @example\n * ```js\n * const nameObject = sdkInstance.aensQuery('test.chain')\n * console.log(nameObject)\n * {\n * id, // name hash\n * pointers, // array of pointers\n * update, // Update name function\n * extendTtl, // Extend Ttl name function\n * transfer, // Transfer name function\n * revoke // Revoke name function\n * }\n * ```\n */\nexport async function aensQuery(\n name: AensName,\n opt: Parameters<typeof getName>[1] & Parameters<typeof aensUpdate>[2]\n & Parameters<typeof aensTransfer>[2],\n): Promise<Readonly<\n TransformNodeType<NameEntry> & {\n id: Encoded.Name;\n owner: Encoded.AccountAddress;\n pointers: KeyPointers | NamePointer[];\n ttl: number;\n update: (\n pointers: KeyPointers,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n transfer: (\n account: Encoded.AccountAddress,\n options?: Parameters<typeof aensQuery>[1]\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n revoke: (options?: Omit<Parameters<typeof aensRevoke>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensRevoke>;\n extendTtl: (\n nameTtl: number,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'>\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n }\n >> {\n const nameEntry = await getName(name, opt);\n return Object.freeze({\n ...nameEntry,\n id: nameEntry.id as Encoded.Name,\n owner: nameEntry.owner as Encoded.AccountAddress,\n async update(pointers, options) {\n return {\n ...await aensUpdate(name, pointers, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async transfer(account, options) {\n return {\n ...await aensTransfer(name, account, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async revoke(options) {\n return aensRevoke(name, { ...opt, ...options });\n },\n async extendTtl(nameTtl = NAME_TTL, options = {}) {\n if (nameTtl > NAME_TTL || nameTtl <= 0) {\n throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);\n }\n\n return {\n ...await aensUpdate(name, {}, {\n ...opt, ...options, nameTtl, extendPointers: true,\n }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n });\n}\n\n/**\n * Claim a previously preclaimed registration. This can only be done after the\n * preclaim step\n * @category AENS\n * @param name - AENS name\n * @param salt - Salt from pre-claim, or 0 if it's a bid\n * @param options - options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameFee - Name Fee (By default calculated by sdk)\n * @returns the result of the claim\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })\n * ```\n */\nexport async function aensClaim(\n name: AensName,\n salt: number,\n options: AensClaimOptions,\n): Promise<AensClaimReturnType> {\n const claimTx = await buildTxAsync({\n ...options,\n tag: Tag.NameClaimTx,\n accountId: options.onAccount.address,\n nameSalt: salt,\n name,\n });\n\n const result = await sendTransaction(claimTx, options);\n if (!isAuctionName(name)) {\n const nameInter = result.blockHeight != null && result.blockHeight > 0\n ? await aensQuery(name, options)\n : {};\n return Object.assign(result, nameInter);\n }\n return result;\n}\n\ntype AensClaimOptionsType = BuildTxOptions<Tag.NameClaimTx, 'accountId' | 'nameSalt' | 'name'>\n& SendTransactionOptions & Parameters<typeof aensQuery>[1];\ninterface AensClaimOptions extends AensClaimOptionsType {}\ninterface AensClaimReturnType extends\n Awaited<ReturnType<typeof sendTransaction>>,\n Partial<Awaited<ReturnType<typeof aensQuery>>> {}\n\n/**\n * Preclaim a name. Sends a hash of the name and a random salt to the node\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })\n * {\n * ...transactionResult,\n * claim, // Claim function (options={}) => claimTransactionResult\n * salt,\n * commitmentId\n * }\n * ```\n */\nexport async function aensPreclaim(name: AensName, options: AensPreclaimOptions): Promise<Readonly<\nAwaited<ReturnType<typeof sendTransaction>> & {\n salt: number;\n commitmentId: string;\n claim: (opts?: Parameters<typeof aensClaim>[2]) => ReturnType<typeof aensClaim>;\n}\n>> {\n const salt = genSalt();\n const commitmentId = commitmentHash(name, salt);\n\n const preclaimTx = await buildTxAsync({\n ...options,\n tag: Tag.NamePreclaimTx,\n accountId: options.onAccount.address,\n commitmentId,\n });\n\n return Object.freeze({\n ...await sendTransaction(preclaimTx, options),\n salt,\n commitmentId,\n async claim(opts?: Parameters<typeof aensClaim>[2]) {\n const { version, ...otherOptions } = options;\n return aensClaim(name, salt, { ...otherOptions, ...opts });\n },\n });\n}\n\ninterface AensPreclaimOptions extends\n BuildTxOptions<Tag.NamePreclaimTx, 'accountId' | 'commitmentId' | 'onNode'>,\n SendTransactionOptions,\n Omit<AensClaimOptions, 'version'> {}\n\n/**\n * Bid to name auction\n * @category AENS\n * @param name - Domain name\n * @param nameFee - Name fee (bid fee)\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const bidFee = computeBidFee(name, startFee, incrementPercentage)\n *\n * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })\n * ```\n */\nexport async function aensBid(\n name: AensName,\n nameFee: number | string | BigNumber,\n options: Omit<Parameters<typeof aensClaim>[2], 'nameFee'>,\n): ReturnType<typeof aensClaim> {\n return aensClaim(name, 0, { ...options, nameFee });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,SASSA,OAAO;AAAA,SACPC,cAAc,EAAEC,aAAa;AAAA,SAEpCC,UAAU,EAAEC,QAAQ,EAAEC,GAAG;AAAA,SAElBC,aAAa;AAAA,SAEbC,eAAe,EAA0BC,OAAO;AAAA,SAChDC,YAAY;AAUrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAC9BC,IAAc,EACdC,OAA0B,EACU;EACpC,MAAMC,YAAY,GAAG,MAAMJ,YAAY,CAAC;IACtC,GAAGG,OAAO;IACVE,GAAG,EAAET,GAAG,CAACU,YAAY;IACrBC,MAAM,EAAEL,IAAI;IACZM,SAAS,EAAEL,OAAO,CAACM,SAAS,CAACC;EAC/B,CAAC,CAAC;EACF,OAAOZ,eAAe,CAACM,YAAY,EAAED,OAAO,CAAC;AAC/C;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeQ,UAAUA,CAC9BT,IAAc,EACdU,QAAqB,EAAAC,IAAA,EAEe;EAAA,IADpC;IAAEC,cAAc;IAAE,GAAGX;EAA2B,CAAC,GAAAU,IAAA;EAEjD,MAAME,WAAW,GAAG;IAClB,IAAGD,cAAc,KAAK,IAAI,IAAIE,MAAM,CAACC,WAAW,CAC9C,CAAC,MAAMlB,OAAO,CAACG,IAAI,EAAEC,OAAO,CAAC,EAAES,QAAQ,CAACM,GAAG,CAACC,KAAA;MAAA,IAAC;QAAEC,GAAG;QAAEC;MAAG,CAAC,GAAAF,KAAA;MAAA,OAAK,CAACC,GAAG,EAAEC,EAAE,CAAC;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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeI,YAAYA,CAACpD,IAAc,EAAEC,OAA4B,EAM5E;EACD,MAAM2C,IAAI,GAAGvD,OAAO,EAAE;EACtB,MAAMgE,YAAY,GAAG/D,cAAc,CAACU,IAAI,EAAE4C,IAAI,CAAC;EAE/C,MAAMU,UAAU,GAAG,MAAMxD,YAAY,CAAC;IACpC,GAAGG,OAAO;IACVE,GAAG,EAAET,GAAG,CAAC6D,cAAc;IACvBjD,SAAS,EAAEL,OAAO,CAACM,SAAS,CAACC,OAAO;IACpC6C;EACF,CAAC,CAAC;EAEF,OAAOvC,MAAM,CAACoB,MAAM,CAAC;IACnB,IAAG,MAAMtC,eAAe,CAAC0D,UAAU,EAAErD,OAAO,CAAC;IAC7C2C,IAAI;IACJS,YAAY;IACZ,MAAMG,KAAKA,CAACC,IAAsC,EAAE;MAClD,MAAM;QAAEC,OAAO;QAAE,GAAGC;MAAa,CAAC,GAAG1D,OAAO;MAC5C,OAAO0C,SAAS,CAAC3C,IAAI,EAAE4C,IAAI,EAAE;QAAE,GAAGe,YAAY;QAAE,GAAGF;MAAK,CAAC,CAAC;IAC5D;EACF,CAAC,CAAC;AACJ;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,OAAOA,CAC3B5D,IAAc,EACd6D,OAAoC,EACpC5D,OAAyD,EAC3B;EAC9B,OAAO0C,SAAS,CAAC3C,IAAI,EAAE,CAAC,EAAE;IAAE,GAAGC,OAAO;IAAE4D;EAAQ,CAAC,CAAC;AACpD"}
1
+ {"version":3,"file":"aens.mjs","names":["genSalt","commitmentHash","isAuctionName","CLIENT_TTL","NAME_TTL","Tag","ArgumentError","sendTransaction","getName","buildTxAsync","aensRevoke","name","options","nameRevokeTx","tag","NameRevokeTx","nameId","accountId","onAccount","address","aensUpdate","pointers","_ref","extendPointers","allPointers","Object","fromEntries","map","_ref2","key","id","nameUpdateTx","clientTtl","nameTtl","NameUpdateTx","entries","_ref3","aensTransfer","account","nameTransferTx","NameTransferTx","recipientId","aensQuery","opt","nameEntry","freeze","owner","update","transfer","revoke","extendTtl","arguments","length","undefined","aensClaim","salt","claimTx","NameClaimTx","nameSalt","result","nameInter","blockHeight","assign","aensPreclaim","commitmentId","preclaimTx","NamePreclaimTx","claim","opts","version","otherOptions","aensBid","nameFee"],"sources":["../src/aens.ts"],"sourcesContent":["/**\n * Aens methods - routines to interact with the æternity naming system\n *\n * The high-level description of the naming system is\n * https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol\n * repository.\n */\n\nimport BigNumber from 'bignumber.js';\nimport { genSalt } from './utils/crypto';\nimport { commitmentHash, isAuctionName } from './tx/builder/helpers';\nimport {\n CLIENT_TTL, NAME_TTL, Tag, AensName,\n} from './tx/builder/constants';\nimport { ArgumentError } from './utils/errors';\nimport { Encoded } from './utils/encoder';\nimport { sendTransaction, SendTransactionOptions, getName } from './chain';\nimport { buildTxAsync, BuildTxOptions } from './tx/builder';\nimport { TransformNodeType } from './Node';\nimport { NameEntry, NamePointer } from './apis/node';\nimport AccountBase from './account/Base';\nimport { AddressEncodings } from './tx/builder/field-types/address';\n\ninterface KeyPointers {\n [key: string]: Encoded.Generic<AddressEncodings>;\n}\n\n/**\n * Revoke a name\n * @category AENS\n * @param name - Name hash\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensRevoke(name, { fee, ttl , nonce })\n * // or\n * await nameObject.revoke({ fee, ttl, nonce })\n * ```\n */\nexport async function aensRevoke(\n name: AensName,\n options: AensRevokeOptions,\n): ReturnType<typeof sendTransaction> {\n const nameRevokeTx = await buildTxAsync({\n ...options,\n tag: Tag.NameRevokeTx,\n nameId: name,\n accountId: options.onAccount.address,\n });\n return sendTransaction(nameRevokeTx, options);\n}\n\ninterface AensRevokeOptions extends\n BuildTxOptions<Tag.NameRevokeTx, 'nameId' | 'accountId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Update a name\n * @category AENS\n * @param name - AENS name\n * @param pointers - Map of pointer keys to corresponding addresses\n * @param options - Options\n * @param options.extendPointers - Get the pointers from the node and merge with provided\n * ones. Pointers with the same type will be overwritten\n * @param options.onAccount - Make operation on specific account from sdk (you\n * pass publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameTtl - Name ttl represented in number of\n * blocks (Max value is 50000 blocks)\n * @param options.clientTtl=84600 a suggestion as to how long any\n * clients should cache this information\n * @throws Invalid pointer array error\n * @example\n * ```js\n * const name = 'test.chain'\n * const pointersArray = ['ak_asd23dasdas...,' 'ct_asdf34fasdasd...']\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensUpdate(name, pointersArray, { nameTtl, ttl, fee, nonce, clientTtl })\n * // or\n * await nameObject.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })\n * ```\n */\nexport async function aensUpdate(\n name: AensName,\n pointers: KeyPointers,\n { extendPointers, ...options }: AensUpdateOptions,\n): ReturnType<typeof sendTransaction> {\n const allPointers = {\n ...extendPointers === true && Object.fromEntries(\n (await getName(name, options)).pointers.map(({ key, id }) => [key, id]),\n ),\n ...pointers,\n };\n\n const nameUpdateTx = await buildTxAsync({\n clientTtl: CLIENT_TTL,\n nameTtl: NAME_TTL,\n ...options,\n tag: Tag.NameUpdateTx,\n nameId: name,\n accountId: options.onAccount.address,\n pointers: Object.entries(allPointers)\n .map(([key, id]: [string, Encoded.Generic<AddressEncodings>]) => ({ key, id })),\n });\n\n return sendTransaction(nameUpdateTx, options);\n}\n\ninterface AensUpdateOptions extends\n BuildTxOptions<Tag.NameUpdateTx, 'nameId' | 'accountId' | 'pointers' | 'clientTtl' | 'nameTtl' | 'onNode'>,\n SendTransactionOptions {\n extendPointers?: boolean;\n clientTtl?: number;\n nameTtl?: number;\n}\n\n/**\n * Transfer a domain to another account\n * @category AENS\n * @param name - AENS name\n * @param account - Recipient account publick key\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const recipientPub = 'ak_asd23dasdas...'\n * const nameObject = await sdkInstance.aensQuery(name)\n *\n * await sdkInstance.aensTransfer(name, recipientPub, { ttl, fee, nonce })\n * // or\n * await nameObject.transfer(recipientPub, { ttl, fee, nonce })\n * ```\n */\nexport async function aensTransfer(\n name: AensName,\n account: Encoded.AccountAddress,\n options: AensTransferOptions,\n): ReturnType<typeof sendTransaction> {\n const nameTransferTx = await buildTxAsync({\n ...options,\n tag: Tag.NameTransferTx,\n nameId: name,\n accountId: options.onAccount.address,\n recipientId: account,\n });\n\n return sendTransaction(nameTransferTx, options);\n}\n\ninterface AensTransferOptions extends\n BuildTxOptions<Tag.NameTransferTx, 'nameId' | 'accountId' | 'recipientId' | 'onNode'>,\n SendTransactionOptions {}\n\n/**\n * Query the AENS name info from the node\n * and return the object with info and predefined functions for manipulating name\n * @category AENS\n * @param name - AENS name\n * @param opt - Options\n * @returns\n * @example\n * ```js\n * const nameObject = sdkInstance.aensQuery('test.chain')\n * console.log(nameObject)\n * {\n * id, // name hash\n * pointers, // array of pointers\n * update, // Update name function\n * extendTtl, // Extend Ttl name function\n * transfer, // Transfer name function\n * revoke // Revoke name function\n * }\n * ```\n */\nexport async function aensQuery(\n name: AensName,\n opt: Parameters<typeof getName>[1] & Parameters<typeof aensUpdate>[2]\n & Parameters<typeof aensTransfer>[2],\n): Promise<Readonly<\n TransformNodeType<NameEntry> & {\n id: Encoded.Name;\n owner: Encoded.AccountAddress;\n pointers: KeyPointers | NamePointer[];\n ttl: number;\n update: (\n pointers: KeyPointers,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n transfer: (\n account: Encoded.AccountAddress,\n options?: Parameters<typeof aensQuery>[1]\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n revoke: (options?: Omit<Parameters<typeof aensRevoke>[1], 'onNode' | 'onCompiler' | 'onAccount'> & {\n onAccount?: AccountBase;\n }\n ) => ReturnType<typeof aensRevoke>;\n extendTtl: (\n nameTtl: number,\n options?: Omit<Parameters<typeof aensQuery>[1], 'onNode' | 'onCompiler' | 'onAccount'>\n ) => ReturnType<typeof aensUpdate> & ReturnType<typeof aensQuery>;\n }\n >> {\n const nameEntry = await getName(name, opt);\n return Object.freeze({\n ...nameEntry,\n id: nameEntry.id as Encoded.Name,\n owner: nameEntry.owner as Encoded.AccountAddress,\n async update(pointers, options) {\n return {\n ...await aensUpdate(name, pointers, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async transfer(account, options) {\n return {\n ...await aensTransfer(name, account, { ...opt, ...options }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n async revoke(options) {\n return aensRevoke(name, { ...opt, ...options });\n },\n async extendTtl(nameTtl = NAME_TTL, options = {}) {\n if (nameTtl > NAME_TTL || nameTtl <= 0) {\n throw new ArgumentError('nameTtl', `a number between 1 and ${NAME_TTL} blocks`, nameTtl);\n }\n\n return {\n ...await aensUpdate(name, {}, {\n ...opt, ...options, nameTtl, extendPointers: true,\n }),\n ...await aensQuery(name, { ...opt, ...options }),\n };\n },\n });\n}\n\n/**\n * Claim a previously preclaimed registration. This can only be done after the\n * preclaim step\n * @category AENS\n * @param name - AENS name\n * @param salt - Salt from pre-claim, or 0 if it's a bid\n * @param options - options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @param options.nameFee - Name Fee (By default calculated by sdk)\n * @returns the result of the claim\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensClaim(name, salt, { ttl, fee, nonce, nameFee })\n * ```\n */\nexport async function aensClaim(\n name: AensName,\n salt: number,\n options: AensClaimOptions,\n): Promise<AensClaimReturnType> {\n const claimTx = await buildTxAsync({\n ...options,\n tag: Tag.NameClaimTx,\n accountId: options.onAccount.address,\n nameSalt: salt,\n name,\n });\n\n const result = await sendTransaction(claimTx, options);\n if (!isAuctionName(name)) {\n const nameInter = result.blockHeight != null && result.blockHeight > 0\n ? await aensQuery(name, options)\n : {};\n return Object.assign(result, nameInter);\n }\n return result;\n}\n\ntype AensClaimOptionsType = BuildTxOptions<Tag.NameClaimTx, 'accountId' | 'nameSalt' | 'name'>\n& SendTransactionOptions & Parameters<typeof aensQuery>[1];\ninterface AensClaimOptions extends AensClaimOptionsType {}\ninterface AensClaimReturnType extends\n Awaited<ReturnType<typeof sendTransaction>>,\n Partial<Awaited<ReturnType<typeof aensQuery>>> {}\n\n/**\n * Preclaim a name. Sends a hash of the name and a random salt to the node\n * @category AENS\n * @param name - AENS name\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @example\n * ```js\n * const name = 'test.chain'\n * const salt = preclaimResult.salt // salt from pre-claim transaction\n *\n * await sdkInstance.aensPreclaim(name, { ttl, fee, nonce })\n * {\n * ...transactionResult,\n * claim, // Claim function (options={}) => claimTransactionResult\n * salt,\n * commitmentId\n * }\n * ```\n */\nexport async function aensPreclaim(name: AensName, options: AensPreclaimOptions): Promise<Readonly<\nAwaited<ReturnType<typeof sendTransaction>> & {\n salt: number;\n commitmentId: string;\n claim: (opts?: Parameters<typeof aensClaim>[2]) => ReturnType<typeof aensClaim>;\n}\n>> {\n const salt = genSalt();\n const commitmentId = commitmentHash(name, salt);\n\n const preclaimTx = await buildTxAsync({\n ...options,\n tag: Tag.NamePreclaimTx,\n accountId: options.onAccount.address,\n commitmentId,\n });\n\n return Object.freeze({\n ...await sendTransaction(preclaimTx, options),\n salt,\n commitmentId,\n async claim(opts?: Parameters<typeof aensClaim>[2]) {\n const { version, ...otherOptions } = options;\n return aensClaim(name, salt, { ...otherOptions, ...opts });\n },\n });\n}\n\ninterface AensPreclaimOptions extends\n BuildTxOptions<Tag.NamePreclaimTx, 'accountId' | 'commitmentId' | 'onNode'>,\n SendTransactionOptions,\n Omit<AensClaimOptions, 'version'> {}\n\n/**\n * Bid to name auction\n * @category AENS\n * @param name - Domain name\n * @param nameFee - Name fee (bid fee)\n * @param options - Options\n * @param options.onAccount - Make operation on specific account from sdk (you pass\n * publickKey) or using provided KeyPair(Can be keypair object or MemoryAccount)\n * @param options.fee - fee\n * @param options.ttl - ttl\n * @param options.nonce - nonce\n * @returns Transaction result\n * @example\n * ```js\n * const name = 'test.chain'\n * const bidFee = computeBidFee(name, { startFee, increment: 0.42 })\n *\n * await sdkInstance.aensBid(name, 213109412839123, { ttl, fee, nonce })\n * ```\n */\nexport async function aensBid(\n name: AensName,\n nameFee: number | string | BigNumber,\n options: Omit<Parameters<typeof aensClaim>[2], 'nameFee'>,\n): ReturnType<typeof aensClaim> {\n return aensClaim(name, 0, { ...options, nameFee });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AANA,SASSA,OAAO;AAAA,SACPC,cAAc,EAAEC,aAAa;AAAA,SAEpCC,UAAU,EAAEC,QAAQ,EAAEC,GAAG;AA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,cAAc,CAACU,IAAI,EAAE4C,IAAI,CAAC;EAE/C,MAAMU,UAAU,GAAG,MAAMxD,YAAY,CAAC;IACpC,GAAGG,OAAO;IACVE,GAAG,EAAET,GAAG,CAAC6D,cAAc;IACvBjD,SAAS,EAAEL,OAAO,CAACM,SAAS,CAACC,OAAO;IACpC6C;EACF,CAAC,CAAC;EAEF,OAAOvC,MAAM,CAACoB,MAAM,CAAC;IACnB,IAAG,MAAMtC,eAAe,CAAC0D,UAAU,EAAErD,OAAO,CAAC;IAC7C2C,IAAI;IACJS,YAAY;IACZ,MAAMG,KAAKA,CAACC,IAAsC,EAAE;MAClD,MAAM;QAAEC,OAAO;QAAE,GAAGC;MAAa,CAAC,GAAG1D,OAAO;MAC5C,OAAO0C,SAAS,CAAC3C,IAAI,EAAE4C,IAAI,EAAE;QAAE,GAAGe,YAAY;QAAE,GAAGF;MAAK,CAAC,CAAC;IAC5D;EACF,CAAC,CAAC;AACJ;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,OAAOA,CAC3B5D,IAAc,EACd6D,OAAoC,EACpC5D,OAAyD,EAC3B;EAC9B,OAAO0C,SAAS,CAAC3C,IAAI,EAAE,CAAC,EAAE;IAAE,GAAGC,OAAO;IAAE4D;EAAQ,CAAC,CAAC;AACpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"Browser.mjs","names":["AlreadyConnectedError","NoWalletConnectedError","BrowserConnection","constructor","_ref","debug","connect","onMessage","onDisconnect","isConnected","disconnect","receiveMessage","message","console","log","sendMessage"],"sources":["../../../src/aepp-wallet-communication/connection/Browser.ts"],"sourcesContent":["import { AlreadyConnectedError, NoWalletConnectedError } from '../../utils/errors';\n\n/**\n * Browser connection base interface\n * @category aepp wallet communication\n */\nexport default abstract class BrowserConnection {\n debug: boolean;\n\n protected constructor({ debug = false }: { debug?: boolean }) {\n this.debug = debug;\n }\n\n /**\n * Connect\n * @param onMessage - Message handler\n * @param onDisconnect - trigger when runtime connection in closed\n */\n connect(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onMessage: (message: any, origin: string, source: any) => void,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDisconnect: () => void,\n ): void {\n if (this.isConnected()) throw new AlreadyConnectedError('You already connected');\n }\n\n /**\n * Disconnect\n */\n disconnect(): void {\n if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before');\n }\n\n /**\n * Receive message\n */\n protected receiveMessage(message: any): void {\n if (this.debug) console.log('Receive message:', message);\n }\n\n /**\n * Send message\n */\n sendMessage(message: any): void {\n if (this.debug) console.log('Send message:', message);\n }\n\n /**\n * Check if connected\n * @returns Is connected\n */\n abstract isConnected(): boolean;\n}\n"],"mappings":"SAASA,qBAAqB,EAAEC,sBAAsB;AAEtD;AACA;AACA;AACA;AACA,eAAe,MAAeC,iBAAiB,CAAC;EAGpCC,WAAWA,CAAAC,IAAA,EAAyC;IAAA,IAAxC;MAAEC,KAAK,GAAG;IAA2B,CAAC,GAAAD,IAAA;IAC1D,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;;EAEA;AACF;AACA;AACA;AACA;EACEC,OAAOA;EACL;EACAC,SAA8D;EAC9D;EACAC,YAAwB,EAClB;IACN,IAAI,IAAI,CAACC,WAAW,EAAE,EAAE,MAAM,IAAIT,qBAAqB,CAAC,uBAAuB,CAAC;EAClF;;EAEA;AACF;AACA;EACEU,UAAUA,CAAA,EAAS;IACjB,IAAI,CAAC,IAAI,CAACD,WAAW,EAAE,EAAE,MAAM,IAAIR,sBAAsB,CAAC,iDAAiD,CAAC;EAC9G;;EAEA;AACF;AACA;EACYU,cAAcA,CAACC,OAAY,EAAQ;IAC3C,IAAI,IAAI,CAACP,KAAK,EAAEQ,OAAO,CAACC,GAAG,CAAC,kBAAkB,EAAEF,OAAO,CAAC;EAC1D;;EAEA;AACF;AACA;EACEG,WAAWA,CAACH,OAAY,EAAQ;IAC9B,IAAI,IAAI,CAACP,KAAK,EAAEQ,OAAO,CAACC,GAAG,CAAC,eAAe,EAAEF,OAAO,CAAC;EACvD;;EAEA;AACF;AACA;AACA;AAEA"}
1
+ {"version":3,"file":"Browser.mjs","names":["AlreadyConnectedError","NoWalletConnectedError","BrowserConnection","constructor","_ref","debug","connect","onMessage","onDisconnect","isConnected","disconnect","receiveMessage","message","console","log","sendMessage"],"sources":["../../../src/aepp-wallet-communication/connection/Browser.ts"],"sourcesContent":["import { AlreadyConnectedError, NoWalletConnectedError } from '../../utils/errors';\n\n/**\n * Browser connection base interface\n * @category aepp wallet communication\n */\nexport default abstract class BrowserConnection {\n debug: boolean;\n\n protected constructor({ debug = false }: { debug?: boolean }) {\n this.debug = debug;\n }\n\n /**\n * Connect\n * @param onMessage - Message handler\n * @param onDisconnect - trigger when runtime connection in closed\n */\n connect(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onMessage: (message: any, origin: string, source: any) => void,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onDisconnect: () => void,\n ): void {\n if (this.isConnected()) throw new AlreadyConnectedError('You already connected');\n }\n\n /**\n * Disconnect\n */\n disconnect(): void {\n if (!this.isConnected()) throw new NoWalletConnectedError('You dont have connection. Please connect before');\n }\n\n /**\n * Receive message\n */\n protected receiveMessage(message: any): void {\n if (this.debug) console.log('Receive message:', message);\n }\n\n /**\n * Send message\n */\n sendMessage(message: any): void {\n if (this.debug) console.log('Send message:', message);\n }\n\n /**\n * Check if connected\n * @returns Is connected\n */\n abstract isConnected(): boolean;\n}\n"],"mappings":"SAASA,qBAAqB,EAAEC,sBAAsB;AAEtD;AACA;AACA;AACA;AACA,eAAe,MAAeC,iBAAiB,CAAC;EAGpCC,WAAWA,CAAAC,IAAA,EAAyC;IAAA,IAAxC;MAAEC,KAAK,GAAG;IAA2B,CAAC,GAAAD,IAAA;IAC1D,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;;EAEA;AACF;AACA;AACA;AACA;EACEC,OAAOA;EACL;EACAC,SAA8D;EAC9D;EACAC,YAAwB,EAClB;IACN,IAAI,IAAI,CAACC,WAAW,CAAC,CAAC,EAAE,MAAM,IAAIT,qBAAqB,CAAC,uBAAuB,CAAC;EAClF;;EAEA;AACF;AACA;EACEU,UAAUA,CAAA,EAAS;IACjB,IAAI,CAAC,IAAI,CAACD,WAAW,CAAC,CAAC,EAAE,MAAM,IAAIR,sBAAsB,CAAC,iDAAiD,CAAC;EAC9G;;EAEA;AACF;AACA;EACYU,cAAcA,CAACC,OAAY,EAAQ;IAC3C,IAAI,IAAI,CAACP,KAAK,EAAEQ,OAAO,CAACC,GAAG,CAAC,kBAAkB,EAAEF,OAAO,CAAC;EAC1D;;EAEA;AACF;AACA;EACEG,WAAWA,CAACH,OAAY,EAAQ;IAC9B,IAAI,IAAI,CAACP,KAAK,EAAEQ,OAAO,CAACC,GAAG,CAAC,eAAe,EAAEF,OAAO,CAAC;EACvD;;EAEA;AACF;AACA;AACA;AAEA"}
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserRuntime.mjs","names":["BrowserConnection","UnexpectedTsError","_listeners","WeakMap","BrowserRuntimeConnection","constructor","_ref","port","options","_classPrivateFieldInitSpec","writable","value","disconnect","_classPrivateFieldGet","onMessage","removeListener","onDisconnect","_classPrivateFieldSet","undefined","connect","message","_port$sender$url","_port$sender","receiveMessage","sender","url","addListener","sendMessage","postMessage","isConnected"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserRuntime.ts"],"sourcesContent":["import { Runtime } from 'webextension-polyfill';\nimport BrowserConnection from './Browser';\nimport { UnexpectedTsError } from '../../utils/errors';\n\n/**\n * BrowserRuntimeConnection\n * Handle browser runtime communication\n * @category aepp wallet communication\n */\nexport default class BrowserRuntimeConnection extends BrowserConnection {\n port: Runtime.Port;\n\n #listeners?: [(message: any, port: Runtime.Port) => void, () => void];\n\n constructor({ port, ...options }: { port: Runtime.Port; debug: boolean }) {\n super(options);\n this.port = port;\n }\n\n override disconnect(): void {\n super.disconnect();\n this.port.disconnect();\n if (this.#listeners == null) throw new UnexpectedTsError();\n this.port.onMessage.removeListener(this.#listeners[0]);\n this.port.onDisconnect.removeListener(this.#listeners[1]);\n this.#listeners = undefined;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: Runtime.Port) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.#listeners = [\n (message, port) => {\n this.receiveMessage(message);\n // TODO: make `origin` optional because sender url is not available on aepp side\n onMessage(message, port.sender?.url ?? '', port);\n },\n onDisconnect,\n ];\n this.port.onMessage.addListener(this.#listeners[0]);\n this.port.onDisconnect.addListener(this.#listeners[1]);\n }\n\n override sendMessage(message: any): void {\n super.sendMessage(message);\n this.port.postMessage(message);\n }\n\n isConnected(): boolean {\n return this.#listeners != null;\n }\n}\n"],"mappings":";;;;OACOA,iBAAiB;AAAA,SACfC,iBAAiB;AAE1B;AACA;AACA;AACA;AACA;AAJA,IAAAC,UAAA,oBAAAC,OAAA;AAKA,eAAe,MAAMC,wBAAwB,SAASJ,iBAAiB,CAAC;EAKtEK,WAAWA,CAAAC,IAAA,EAA+D;IAAA,IAA9D;MAAEC,IAAI;MAAE,GAAGC;IAAgD,CAAC,GAAAF,IAAA;IACtE,KAAK,CAACE,OAAO,CAAC;IAACC,0BAAA,OAAAP,UAAA;MAAAQ,QAAA;MAAAC,KAAA;IAAA;IACf,IAAI,CAACJ,IAAI,GAAGA,IAAI;EAClB;EAESK,UAAUA,CAAA,EAAS;IAC1B,KAAK,CAACA,UAAU,EAAE;IAClB,IAAI,CAACL,IAAI,CAACK,UAAU,EAAE;IACtB,IAAIC,qBAAA,KAAI,EAAAX,UAAA,KAAe,IAAI,EAAE,MAAM,IAAID,iBAAiB,EAAE;IAC1D,IAAI,CAACM,IAAI,CAACO,SAAS,CAACC,cAAc,CAACF,qBAAA,KAAI,EAAAX,UAAA,EAAY,CAAC,CAAC,CAAC;IACtD,IAAI,CAACK,IAAI,CAACS,YAAY,CAACD,cAAc,CAACF,qBAAA,KAAI,EAAAX,UAAA,EAAY,CAAC,CAAC,CAAC;IACzDe,qBAAA,KAAI,EAAAf,UAAA,EAAcgB,SAAS;EAC7B;EAESC,OAAOA,CACdL,SAAuE,EACvEE,YAAwB,EAClB;IACN,KAAK,CAACG,OAAO,CAACL,SAAS,EAAEE,YAAY,CAAC;IACtCC,qBAAA,KAAI,EAAAf,UAAA,EAAc,CAChB,CAACkB,OAAO,EAAEb,IAAI,KAAK;MAAA,IAAAc,gBAAA,EAAAC,YAAA;MACjB,IAAI,CAACC,cAAc,CAACH,OAAO,CAAC;MAC5B;MACAN,SAAS,CAACM,OAAO,GAAAC,gBAAA,IAAAC,YAAA,GAAEf,IAAI,CAACiB,MAAM,cAAAF,YAAA,uBAAXA,YAAA,CAAaG,GAAG,cAAAJ,gBAAA,cAAAA,gBAAA,GAAI,EAAE,EAAEd,IAAI,CAAC;IAClD,CAAC,EACDS,YAAY,CACb;IACD,IAAI,CAACT,IAAI,CAACO,SAAS,CAACY,WAAW,CAACb,qBAAA,KAAI,EAAAX,UAAA,EAAY,CAAC,CAAC,CAAC;IACnD,IAAI,CAACK,IAAI,CAACS,YAAY,CAACU,WAAW,CAACb,qBAAA,KAAI,EAAAX,UAAA,EAAY,CAAC,CAAC,CAAC;EACxD;EAESyB,WAAWA,CAACP,OAAY,EAAQ;IACvC,KAAK,CAACO,WAAW,CAACP,OAAO,CAAC;IAC1B,IAAI,CAACb,IAAI,CAACqB,WAAW,CAACR,OAAO,CAAC;EAChC;EAEAS,WAAWA,CAAA,EAAY;IACrB,OAAOhB,qBAAA,KAAI,EAAAX,UAAA,KAAe,IAAI;EAChC;AACF"}
1
+ {"version":3,"file":"BrowserRuntime.mjs","names":["BrowserConnection","UnexpectedTsError","_listeners","WeakMap","BrowserRuntimeConnection","constructor","_ref","port","options","_classPrivateFieldInitSpec","writable","value","disconnect","_classPrivateFieldGet","onMessage","removeListener","onDisconnect","_classPrivateFieldSet","undefined","connect","message","_port$sender$url","_port$sender","receiveMessage","sender","url","addListener","sendMessage","postMessage","isConnected"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserRuntime.ts"],"sourcesContent":["import { Runtime } from 'webextension-polyfill';\nimport BrowserConnection from './Browser';\nimport { UnexpectedTsError } from '../../utils/errors';\n\n/**\n * BrowserRuntimeConnection\n * Handle browser runtime communication\n * @category aepp wallet communication\n */\nexport default class BrowserRuntimeConnection extends BrowserConnection {\n port: Runtime.Port;\n\n #listeners?: [(message: any, port: Runtime.Port) => void, () => void];\n\n constructor({ port, ...options }: { port: Runtime.Port; debug: boolean }) {\n super(options);\n this.port = port;\n }\n\n override disconnect(): void {\n super.disconnect();\n this.port.disconnect();\n if (this.#listeners == null) throw new UnexpectedTsError();\n this.port.onMessage.removeListener(this.#listeners[0]);\n this.port.onDisconnect.removeListener(this.#listeners[1]);\n this.#listeners = undefined;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: Runtime.Port) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.#listeners = [\n (message, port) => {\n this.receiveMessage(message);\n // TODO: make `origin` optional because sender url is not available on aepp side\n onMessage(message, port.sender?.url ?? '', port);\n },\n onDisconnect,\n ];\n this.port.onMessage.addListener(this.#listeners[0]);\n this.port.onDisconnect.addListener(this.#listeners[1]);\n }\n\n override sendMessage(message: any): void {\n super.sendMessage(message);\n this.port.postMessage(message);\n }\n\n isConnected(): boolean {\n return this.#listeners != null;\n }\n}\n"],"mappings":";;;;OACOA,iBAAiB;AAAA,SACfC,iBAAiB;AAE1B;AACA;AACA;AACA;AACA;AAJA,IAAAC,UAAA,oBAAAC,OAAA;AAKA,eAAe,MAAMC,wBAAwB,SAASJ,iBAAiB,CAAC;EAKtEK,WAAWA,CAAAC,IAAA,EAA+D;IAAA,IAA9D;MAAEC,IAAI;MAAE,GAAGC;IAAgD,CAAC,GAAAF,IAAA;IACtE,KAAK,CAACE,OAAO,CAAC;I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AAC,CAAC,CAAC;EACxD;EAESyB,WAAWA,CAACP,OAAY,EAAQ;IACvC,KAAK,CAACO,WAAW,CAACP,OAAO,CAAC;IAC1B,IAAI,CAACb,IAAI,CAACqB,WAAW,CAACR,OAAO,CAAC;EAChC;EAEAS,WAAWA,CAAA,EAAY;IACrB,OAAOhB,qBAAA,KAAI,EAAAX,UAAA,KAAe,IAAI;EAChC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"BrowserWindowMessage.mjs","names":["BrowserConnection","MESSAGE_DIRECTION","InternalError","RpcConnectionError","_onDisconnect","WeakMap","_target","_self","BrowserWindowMessageConnection","constructor","target","self","window","origin","sendDirection","receiveDirection","to_aepp","options","arguments","length","undefined","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","isConnected","listener","connect","onMessage","onDisconnect","message","_message$data$jsonrpc","_message$data$data","data","jsonrpc","_classPrivateFieldGet","source","receiveMessage","type","addEventListener","disconnect","removeEventListener","call","sendMessage","msg","_this$origin","postMessage"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserWindowMessage.ts"],"sourcesContent":["import BrowserConnection from './Browser';\nimport { MESSAGE_DIRECTION } from '../schema';\nimport { InternalError, RpcConnectionError } from '../../utils/errors';\n\nexport type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>;\n\n/**\n * Browser window Post Message connector module\n * @category aepp wallet communication\n */\nexport default class BrowserWindowMessageConnection extends BrowserConnection {\n origin?: string;\n\n sendDirection?: MESSAGE_DIRECTION;\n\n receiveDirection: MESSAGE_DIRECTION;\n\n listener?: (this: Window, ev: MessageEvent<any>) => void;\n\n #onDisconnect?: () => void;\n\n #target?: ImplPostMessage;\n\n #self: ImplPostMessage;\n\n /**\n * @param options - Options\n * @param options.target Target window for message\n * @param options.self Host window for message\n * @param options.origin Origin of receiver\n * @param options.sendDirection Wrapping messages into additional struct\n * `({ type: 'to_aepp' || 'to_waellet', data })`\n * Used for handling messages between content script and page\n * @param options.receiveDirection Unwrapping messages from additional struct\n */\n constructor({\n target,\n self = window,\n origin,\n sendDirection,\n receiveDirection = MESSAGE_DIRECTION.to_aepp,\n ...options\n }: {\n target?: ImplPostMessage;\n self?: ImplPostMessage;\n origin?: string;\n sendDirection?: MESSAGE_DIRECTION;\n receiveDirection?: MESSAGE_DIRECTION;\n debug?: boolean;\n } = {}) {\n super(options);\n this.#target = target;\n this.#self = self;\n this.origin = origin;\n this.sendDirection = sendDirection;\n this.receiveDirection = receiveDirection;\n }\n\n isConnected(): boolean {\n return this.listener != null;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: MessageEventSource | null) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.listener = (message: MessageEvent<any>) => {\n // TODO: strict validate origin and source instead of checking message structure\n if (\n typeof message.data !== 'object'\n || (message.data.jsonrpc ?? message.data.data?.jsonrpc) !== '2.0'\n ) return;\n if (this.origin != null && this.origin !== message.origin) return;\n if (this.#target != null && this.#target !== message.source) return;\n this.receiveMessage(message);\n let { data } = message;\n if (data.type != null) {\n if (message.data.type !== this.receiveDirection) return;\n data = data.data;\n }\n onMessage(data, message.origin, message.source);\n };\n this.#self.addEventListener('message', this.listener);\n this.#onDisconnect = onDisconnect;\n }\n\n override disconnect(): void {\n super.disconnect();\n if (this.listener == null || this.#onDisconnect == null) {\n throw new InternalError('Expected to not happen, required for TS');\n }\n this.#self.removeEventListener('message', this.listener);\n delete this.listener;\n this.#onDisconnect();\n this.#onDisconnect = undefined;\n }\n\n override sendMessage(msg: any): void {\n if (this.#target == null) throw new RpcConnectionError('Can\\'t send messages without target');\n const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg;\n super.sendMessage(message);\n this.#target.postMessage(message, this.origin ?? '*');\n }\n}\n"],"mappings":";;;;OAAOA,iBAAiB;AAAA,SACfC,iBAAiB;AAAA,SACjBC,aAAa,EAAEC,kBAAkB;AAAA,IAAAC,aAAA,oBAAAC,OAAA;AAAA,IAAAC,OAAA,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,IAAA,CAAJ,IAAI;IACJlB,qBAAA,KAAI,EAAApB,aAAA,EAAiBgB,SAAS;EAChC;EAESuB,WAAWA,CAACC,GAAQ,EAAQ;IAAA,IAAAC,YAAA;IACnC,IAAIV,qBAAA,KAAI,EAAA7B,OAAA,KAAY,IAAI,EAAE,MAAM,IAAIH,kBAAkB,CAAC,qCAAqC,CAAC;IAC7F,MAAM2B,OAAO,GAAG,IAAI,CAAChB,aAAa,IAAI,IAAI,GAAG;MAAEwB,IAAI,EAAE,IAAI,CAACxB,aAAa;MAAEmB,IAAI,EAAEW;IAAI,CAAC,GAAGA,GAAG;IAC1F,KAAK,CAACD,WAAW,CAACb,OAAO,CAAC;IAC1BK,qBAAA,KAAI,EAAA7B,OAAA,EAASwC,WAAW,CAAChB,OAAO,GAAAe,YAAA,GAAE,IAAI,CAAChC,MAAM,cAAAgC,YAAA,cAAAA,YAAA,GAAI,GAAG,CAAC;EACvD;AACF"}
1
+ {"version":3,"file":"BrowserWindowMessage.mjs","names":["BrowserConnection","MESSAGE_DIRECTION","InternalError","RpcConnectionError","_onDisconnect","WeakMap","_target","_self","BrowserWindowMessageConnection","constructor","target","self","window","origin","sendDirection","receiveDirection","to_aepp","options","arguments","length","undefined","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","isConnected","listener","connect","onMessage","onDisconnect","message","_message$data$jsonrpc","_message$data$data","data","jsonrpc","_classPrivateFieldGet","source","receiveMessage","type","addEventListener","disconnect","removeEventListener","call","sendMessage","msg","_this$origin","postMessage"],"sources":["../../../src/aepp-wallet-communication/connection/BrowserWindowMessage.ts"],"sourcesContent":["import BrowserConnection from './Browser';\nimport { MESSAGE_DIRECTION } from '../schema';\nimport { InternalError, RpcConnectionError } from '../../utils/errors';\n\nexport type ImplPostMessage = Pick<Window, 'addEventListener' | 'removeEventListener' | 'postMessage'>;\n\n/**\n * Browser window Post Message connector module\n * @category aepp wallet communication\n */\nexport default class BrowserWindowMessageConnection extends BrowserConnection {\n origin?: string;\n\n sendDirection?: MESSAGE_DIRECTION;\n\n receiveDirection: MESSAGE_DIRECTION;\n\n listener?: (this: Window, ev: MessageEvent<any>) => void;\n\n #onDisconnect?: () => void;\n\n #target?: ImplPostMessage;\n\n #self: ImplPostMessage;\n\n /**\n * @param options - Options\n * @param options.target Target window for message\n * @param options.self Host window for message\n * @param options.origin Origin of receiver\n * @param options.sendDirection Wrapping messages into additional struct\n * `({ type: 'to_aepp' || 'to_waellet', data })`\n * Used for handling messages between content script and page\n * @param options.receiveDirection Unwrapping messages from additional struct\n */\n constructor({\n target,\n self = window,\n origin,\n sendDirection,\n receiveDirection = MESSAGE_DIRECTION.to_aepp,\n ...options\n }: {\n target?: ImplPostMessage;\n self?: ImplPostMessage;\n origin?: string;\n sendDirection?: MESSAGE_DIRECTION;\n receiveDirection?: MESSAGE_DIRECTION;\n debug?: boolean;\n } = {}) {\n super(options);\n this.#target = target;\n this.#self = self;\n this.origin = origin;\n this.sendDirection = sendDirection;\n this.receiveDirection = receiveDirection;\n }\n\n isConnected(): boolean {\n return this.listener != null;\n }\n\n override connect(\n onMessage: (message: any, origin: string, source: MessageEventSource | null) => void,\n onDisconnect: () => void,\n ): void {\n super.connect(onMessage, onDisconnect);\n this.listener = (message: MessageEvent<any>) => {\n // TODO: strict validate origin and source instead of checking message structure\n if (\n typeof message.data !== 'object'\n || (message.data.jsonrpc ?? message.data.data?.jsonrpc) !== '2.0'\n ) return;\n if (this.origin != null && this.origin !== message.origin) return;\n if (this.#target != null && this.#target !== message.source) return;\n this.receiveMessage(message);\n let { data } = message;\n if (data.type != null) {\n if (message.data.type !== this.receiveDirection) return;\n data = data.data;\n }\n onMessage(data, message.origin, message.source);\n };\n this.#self.addEventListener('message', this.listener);\n this.#onDisconnect = onDisconnect;\n }\n\n override disconnect(): void {\n super.disconnect();\n if (this.listener == null || this.#onDisconnect == null) {\n throw new InternalError('Expected to not happen, required for TS');\n }\n this.#self.removeEventListener('message', this.listener);\n delete this.listener;\n this.#onDisconnect();\n this.#onDisconnect = undefined;\n }\n\n override sendMessage(msg: any): void {\n if (this.#target == null) throw new RpcConnectionError('Can\\'t send messages without target');\n const message = this.sendDirection != null ? { type: this.sendDirection, data: msg } : msg;\n super.sendMessage(message);\n this.#target.postMessage(message, this.origin ?? '*');\n }\n}\n"],"mappings":";;;;OAAOA,iBAAiB;AAAA,SACfC,iBAAiB;AAAA,SACjBC,aAAa,EAAEC,kBAAkB;AAAA,IAAAC,aAAA,oBAAAC,OAAA;AAAA,IAAAC,OAAA,oBAAAD,OAAA;AAAA,IAAAE,KAAA,oBAAAF,OAAA;AAI1C;AACA;AACA;AACA;AACA,eAAe,MAAMG,8BAA8B,SAASR,iBAAiB,CAAC;EAe5E;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACES,WAAWA,CAAA,EAcH;IAAA,IAdI;MACVC,MAAM;MACNC,IAAI,GAAGC,MAAM;MACbC,MAAM;MACNC,aAAa;MACbC,gBAAgB,GAAGd,iBAAiB,CAACe,OAAO;MAC5C,GAAGC;IAQL,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IACJ,KAAK,CAACD,OAAO,CAAC;IAACI,0BAAA,OAAAjB,aAAA;MAAAkB,QAAA;MAAAC,KAAA;IAAA;IAAAF,0BAAA,OAAAf,OAAA;MAAAgB,QAAA;MAAAC,KAAA;IAAA;IAAAF,0BAAA,OAAAd,KAAA;MAAAe,QAAA;MAAAC,KAAA;IAAA;IACfC,qBAAA,KAAI,EAAAlB,OAAA,EAAWI,MAAM;IACrBc,qBAAA,KAAI,EAAAjB,KAAA,EAASI,IAAI;IACjB,IAAI,CAACE,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,aAAa,GAAGA,aAAa;IAClC,IAAI,CAACC,gBAAgB,GAAGA,gBAAgB;EAC1C;EAEAU,WAAWA,CAAA,EAAY;IACrB,OAAO,IAAI,CAACC,QAAQ,IAAI,I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,CAAC;IAClB,IAAI,IAAI,CAACd,QAAQ,IAAI,IAAI,IAAIS,qBAAA,KAAI,EAAA/B,aAAA,KAAkB,IAAI,EAAE;MACvD,MAAM,IAAIF,aAAa,CAAC,yCAAyC,CAAC;IACpE;IACAiC,qBAAA,KAAI,EAAA5B,KAAA,EAAOkC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAACf,QAAQ,CAAC;IACxD,OAAO,IAAI,CAACA,QAAQ;IACpBS,qBAAA,KAAI,EAAA/B,aAAA,EAAAsC,IAAA,CAAJ,IAAI;IACJlB,qBAAA,KAAI,EAAApB,aAAA,EAAiBgB,SAAS;EAChC;EAESuB,WAAWA,CAACC,GAAQ,EAAQ;IAAA,IAAAC,YAAA;IACnC,IAAIV,qBAAA,KAAI,EAAA7B,OAAA,KAAY,IAAI,EAAE,MAAM,IAAIH,kBAAkB,CAAC,qCAAqC,CAAC;IAC7F,MAAM2B,OAAO,GAAG,IAAI,CAAChB,aAAa,IAAI,IAAI,GAAG;MAAEwB,IAAI,EAAE,IAAI,CAACxB,aAAa;MAAEmB,IAAI,EAAEW;IAAI,CAAC,GAAGA,GAAG;IAC1F,KAAK,CAACD,WAAW,CAACb,OAAO,CAAC;IAC1BK,qBAAA,KAAI,EAAA7B,OAAA,EAASwC,WAAW,CAAChB,OAAO,GAAAe,YAAA,GAAE,IAAI,CAAChC,MAAM,cAAAgC,YAAA,cAAAA,YAAA,GAAI,GAAG,CAAC;EACvD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"connection-proxy.mjs","names":["con1","con2","connect","msg","sendMessage","disconnect"],"sources":["../../src/aepp-wallet-communication/connection-proxy.ts"],"sourcesContent":["import BrowserConnection from './connection/Browser';\n\n/**\n * Browser connection proxy\n * Provide functionality to easily forward messages from one connection to another and back\n * @category aepp wallet communication\n * @param con1 - first connection\n * @param con2 - second connection\n * @returns a function to stop proxying\n */\nexport default (con1: BrowserConnection, con2: BrowserConnection): () => void => {\n con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect());\n con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect());\n\n return () => {\n con1.disconnect();\n con2.disconnect();\n };\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,CAACA,IAAuB,EAAEC,IAAuB,KAAiB;EAC/ED,IAAI,CAACE,OAAO,CAAEC,GAAQ,IAAKF,IAAI,CAACG,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMF,IAAI,CAACI,UAAU,EAAE,CAAC;EAC1EJ,IAAI,CAACC,OAAO,CAAEC,GAAQ,IAAKH,IAAI,CAACI,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMH,IAAI,CAACK,UAAU,EAAE,CAAC;EAE1E,OAAO,MAAM;IACXL,IAAI,CAACK,UAAU,EAAE;IACjBJ,IAAI,CAACI,UAAU,EAAE;EACnB,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"connection-proxy.mjs","names":["con1","con2","connect","msg","sendMessage","disconnect"],"sources":["../../src/aepp-wallet-communication/connection-proxy.ts"],"sourcesContent":["import BrowserConnection from './connection/Browser';\n\n/**\n * Browser connection proxy\n * Provide functionality to easily forward messages from one connection to another and back\n * @category aepp wallet communication\n * @param con1 - first connection\n * @param con2 - second connection\n * @returns a function to stop proxying\n */\nexport default (con1: BrowserConnection, con2: BrowserConnection): () => void => {\n con1.connect((msg: any) => con2.sendMessage(msg), () => con2.disconnect());\n con2.connect((msg: any) => con1.sendMessage(msg), () => con1.disconnect());\n\n return () => {\n con1.disconnect();\n con2.disconnect();\n };\n};\n"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gBAAe,CAACA,IAAuB,EAAEC,IAAuB,KAAiB;EAC/ED,IAAI,CAACE,OAAO,CAAEC,GAAQ,IAAKF,IAAI,CAACG,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMF,IAAI,CAACI,UAAU,CAAC,CAAC,CAAC;EAC1EJ,IAAI,CAACC,OAAO,CAAEC,GAAQ,IAAKH,IAAI,CAACI,WAAW,CAACD,GAAG,CAAC,EAAE,MAAMH,IAAI,CAACK,UAAU,CAAC,CAAC,CAAC;EAE1E,OAAO,MAAM;IACXL,IAAI,CAACK,UAAU,CAAC,CAAC;IACjBJ,IAAI,CAACI,UAAU,CAAC,CAAC;EACnB,CAAC;AACH,CAAC"}
@@ -6,6 +6,7 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
6
6
  function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
7
7
  import { RpcError, RpcInternalError, RpcMethodNotFoundError } from "../schema.mjs";
8
8
  import { InvalidRpcMessageError, MissingCallbackError } from "../../utils/errors.mjs";
9
+ import { ensureError } from "../../utils/other.mjs";
9
10
  var _callbacks = /*#__PURE__*/new WeakMap();
10
11
  var _messageId = /*#__PURE__*/new WeakMap();
11
12
  var _methods = /*#__PURE__*/new WeakMap();
@@ -85,11 +86,13 @@ async function _handleMessage2(msg, origin) {
85
86
  const methodName = request.method;
86
87
  result = await _classPrivateFieldGet(this, _methods)[methodName](request.params, origin);
87
88
  } catch (e) {
88
- error = e instanceof RpcError ? e : new RpcInternalError();
89
+ ensureError(e);
90
+ error = e;
89
91
  }
90
92
  if (request.id != null) {
91
- _classPrivateMethodGet(this, _sendResponse, _sendResponse2).call(this, request.id, request.method, result, error);
93
+ _classPrivateMethodGet(this, _sendResponse, _sendResponse2).call(this, request.id, request.method, result, error == null || error instanceof RpcError ? error : new RpcInternalError());
92
94
  }
95
+ if (error != null && !(error instanceof RpcError)) throw error;
93
96
  }
94
97
  function _sendRequest2(id, method, params) {
95
98
  this.connection.sendMessage({