@aeternity/aepp-sdk 13.0.0 → 13.1.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 (276) 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 +27068 -16862
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdkBase.d.ts +11 -3
  10. package/es/AeSdkBase.mjs +24 -3
  11. package/es/AeSdkBase.mjs.map +1 -1
  12. package/es/AeSdkMethods.d.ts +9 -14
  13. package/es/AeSdkMethods.mjs +20 -49
  14. package/es/AeSdkMethods.mjs.map +1 -1
  15. package/es/AeSdkWallet.mjs +28 -5
  16. package/es/AeSdkWallet.mjs.map +1 -1
  17. package/es/Middleware.d.ts +38 -0
  18. package/es/Middleware.mjs +90 -0
  19. package/es/Middleware.mjs.map +1 -0
  20. package/es/MiddlewareSubscriber.d.ts +30 -0
  21. package/es/MiddlewareSubscriber.mjs +198 -0
  22. package/es/MiddlewareSubscriber.mjs.map +1 -0
  23. package/es/Node.d.ts +1 -1
  24. package/es/Node.mjs.map +1 -1
  25. package/es/account/Base.d.ts +14 -2
  26. package/es/account/Base.mjs.map +1 -1
  27. package/es/account/Generalized.d.ts +1 -0
  28. package/es/account/Generalized.mjs +5 -0
  29. package/es/account/Generalized.mjs.map +1 -1
  30. package/es/account/Ledger.d.ts +1 -0
  31. package/es/account/Ledger.mjs +5 -0
  32. package/es/account/Ledger.mjs.map +1 -1
  33. package/es/account/Memory.d.ts +2 -0
  34. package/es/account/Memory.mjs +18 -0
  35. package/es/account/Memory.mjs.map +1 -1
  36. package/es/account/Rpc.d.ts +1 -6
  37. package/es/account/Rpc.mjs +24 -10
  38. package/es/account/Rpc.mjs.map +1 -1
  39. package/es/aens.d.ts +1 -1
  40. package/es/aens.mjs +1 -1
  41. package/es/aens.mjs.map +1 -1
  42. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -2
  43. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  44. package/es/aepp-wallet-communication/rpc/types.d.ts +10 -0
  45. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  46. package/es/aepp-wallet-communication/schema.d.ts +1 -8
  47. package/es/aepp-wallet-communication/schema.mjs +1 -14
  48. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  49. package/es/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  50. package/es/aepp-wallet-communication/wallet-detector.mjs +0 -3
  51. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  52. package/es/apis/compiler/compiler.mjs +15 -1
  53. package/es/apis/compiler/compiler.mjs.map +1 -1
  54. package/es/apis/compiler/models/index.d.ts +1 -7
  55. package/es/apis/compiler/models/index.mjs.map +1 -1
  56. package/es/apis/compiler/models/mappers.d.ts +0 -1
  57. package/es/apis/compiler/models/mappers.mjs +0 -43
  58. package/es/apis/compiler/models/mappers.mjs.map +1 -1
  59. package/es/apis/middleware/index.d.ts +2 -0
  60. package/es/apis/middleware/index.mjs +3 -0
  61. package/es/apis/middleware/index.mjs.map +1 -0
  62. package/es/apis/middleware/middleware.d.ts +309 -0
  63. package/es/apis/middleware/middleware.mjs +1527 -0
  64. package/es/apis/middleware/middleware.mjs.map +1 -0
  65. package/es/apis/middleware/models/index.d.ts +1496 -0
  66. package/es/apis/middleware/models/index.mjs +364 -0
  67. package/es/apis/middleware/models/index.mjs.map +1 -0
  68. package/es/apis/middleware/models/mappers.d.ts +102 -0
  69. package/es/apis/middleware/models/mappers.mjs +3334 -0
  70. package/es/apis/middleware/models/mappers.mjs.map +1 -0
  71. package/es/apis/middleware/models/parameters.d.ts +43 -0
  72. package/es/apis/middleware/models/parameters.mjs +417 -0
  73. package/es/apis/middleware/models/parameters.mjs.map +1 -0
  74. package/es/chain.d.ts +2 -1
  75. package/es/chain.mjs +4 -2
  76. package/es/chain.mjs.map +1 -1
  77. package/es/channel/Base.d.ts +1 -1
  78. package/es/channel/Base.mjs +1 -4
  79. package/es/channel/Base.mjs.map +1 -1
  80. package/es/channel/internal.mjs +2 -0
  81. package/es/channel/internal.mjs.map +1 -1
  82. package/es/contract/Contract.d.ts +1 -2
  83. package/es/contract/Contract.mjs +1 -1
  84. package/es/contract/Contract.mjs.map +1 -1
  85. package/es/contract/compiler/Base.d.ts +21 -0
  86. package/es/contract/compiler/Base.mjs.map +1 -1
  87. package/es/contract/compiler/Cli.d.ts +2 -0
  88. package/es/contract/compiler/Cli.mjs +24 -3
  89. package/es/contract/compiler/Cli.mjs.map +1 -1
  90. package/es/contract/compiler/Http.d.ts +2 -0
  91. package/es/contract/compiler/Http.mjs +22 -2
  92. package/es/contract/compiler/Http.mjs.map +1 -1
  93. package/es/contract/compiler/HttpNode.d.ts +1 -0
  94. package/es/contract/compiler/HttpNode.mjs +5 -0
  95. package/es/contract/compiler/HttpNode.mjs.map +1 -1
  96. package/es/deprecated.d.ts +14 -0
  97. package/es/deprecated.mjs +22 -0
  98. package/es/deprecated.mjs.map +1 -0
  99. package/es/index-browser.d.ts +20 -14
  100. package/es/index-browser.mjs +19 -15
  101. package/es/index-browser.mjs.map +1 -1
  102. package/es/tx/builder/constants.d.ts +0 -1
  103. package/es/tx/builder/constants.mjs +0 -1
  104. package/es/tx/builder/constants.mjs.map +1 -1
  105. package/es/tx/builder/field-types/coin-amount.d.ts +1 -1
  106. package/es/tx/builder/field-types/coin-amount.mjs +2 -1
  107. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -1
  108. package/es/tx/builder/field-types/deposit.d.ts +1 -1
  109. package/es/tx/builder/field-types/entry.mjs +2 -1
  110. package/es/tx/builder/field-types/entry.mjs.map +1 -1
  111. package/es/tx/builder/field-types/index.d.ts +2 -2
  112. package/es/tx/builder/helpers.d.ts +8 -1
  113. package/es/tx/builder/helpers.mjs +53 -9
  114. package/es/tx/builder/helpers.mjs.map +1 -1
  115. package/es/tx/builder/index.d.ts +4 -2
  116. package/es/tx/builder/index.mjs +0 -1
  117. package/es/tx/builder/index.mjs.map +1 -1
  118. package/es/tx/builder/schema.d.ts +9 -9
  119. package/es/tx/execution-cost.d.ts +17 -0
  120. package/es/tx/execution-cost.mjs +17 -0
  121. package/es/tx/execution-cost.mjs.map +1 -1
  122. package/es/tx/validator.mjs +6 -3
  123. package/es/tx/validator.mjs.map +1 -1
  124. package/es/utils/amount-formatter.d.ts +1 -2
  125. package/es/utils/amount-formatter.mjs +2 -2
  126. package/es/utils/amount-formatter.mjs.map +1 -1
  127. package/es/utils/autorest.mjs +6 -8
  128. package/es/utils/autorest.mjs.map +1 -1
  129. package/es/utils/crypto.d.ts +1 -0
  130. package/es/utils/crypto.mjs +12 -2
  131. package/es/utils/crypto.mjs.map +1 -1
  132. package/es/utils/errors.d.ts +2 -2
  133. package/es/utils/errors.mjs.map +1 -1
  134. package/es/utils/other.d.ts +1 -0
  135. package/es/utils/other.mjs +5 -0
  136. package/es/utils/other.mjs.map +1 -1
  137. package/es/utils/typed-data.d.ts +45 -0
  138. package/es/utils/typed-data.mjs +71 -0
  139. package/es/utils/typed-data.mjs.map +1 -0
  140. package/package.json +23 -4
  141. package/src/AeSdkBase.ts +30 -5
  142. package/src/AeSdkMethods.ts +31 -50
  143. package/src/AeSdkWallet.ts +27 -5
  144. package/src/Middleware.ts +141 -0
  145. package/src/MiddlewareSubscriber.ts +207 -0
  146. package/src/Node.ts +1 -1
  147. package/src/account/Base.ts +20 -3
  148. package/src/account/Generalized.ts +5 -0
  149. package/src/account/Ledger.ts +5 -0
  150. package/src/account/Memory.ts +15 -0
  151. package/src/account/Rpc.ts +19 -7
  152. package/src/aens.ts +1 -1
  153. package/src/aepp-wallet-communication/rpc/RpcClient.ts +11 -3
  154. package/src/aepp-wallet-communication/rpc/types.ts +11 -0
  155. package/src/aepp-wallet-communication/schema.ts +2 -17
  156. package/src/aepp-wallet-communication/wallet-detector.ts +1 -2
  157. package/src/apis/compiler/compiler.ts +8 -1
  158. package/src/apis/compiler/models/index.ts +1 -8
  159. package/src/apis/compiler/models/mappers.ts +0 -36
  160. package/src/apis/middleware/index.ts +2 -0
  161. package/src/apis/middleware/middleware.ts +1807 -0
  162. package/src/apis/middleware/models/index.ts +1747 -0
  163. package/src/apis/middleware/models/mappers.ts +3370 -0
  164. package/src/apis/middleware/models/parameters.ts +463 -0
  165. package/src/chain.ts +3 -2
  166. package/src/channel/Base.ts +5 -5
  167. package/src/channel/internal.ts +2 -0
  168. package/src/contract/Contract.ts +2 -1
  169. package/src/contract/compiler/Base.ts +26 -0
  170. package/src/contract/compiler/Cli.ts +27 -3
  171. package/src/contract/compiler/Http.ts +21 -2
  172. package/src/contract/compiler/HttpNode.ts +6 -0
  173. package/src/deprecated.ts +23 -0
  174. package/src/index-browser.ts +77 -15
  175. package/src/tx/builder/constants.ts +0 -1
  176. package/src/tx/builder/field-types/coin-amount.ts +2 -1
  177. package/src/tx/builder/field-types/entry.ts +1 -1
  178. package/src/tx/builder/helpers.ts +54 -9
  179. package/src/tx/builder/index.ts +6 -9
  180. package/src/tx/execution-cost.ts +17 -0
  181. package/src/tx/validator.ts +4 -2
  182. package/src/utils/amount-formatter.ts +1 -1
  183. package/src/utils/autorest.ts +5 -10
  184. package/src/utils/crypto.ts +12 -2
  185. package/src/utils/errors.ts +2 -2
  186. package/src/utils/other.ts +5 -0
  187. package/src/utils/typed-data.ts +95 -0
  188. package/types-legacy/ts4.2/AeSdkBase.d.ts +11 -3
  189. package/types-legacy/ts4.2/AeSdkMethods.d.ts +9 -14
  190. package/types-legacy/ts4.2/Middleware.d.ts +46 -0
  191. package/types-legacy/ts4.2/MiddlewareSubscriber.d.ts +30 -0
  192. package/types-legacy/ts4.2/Node.d.ts +1 -1
  193. package/types-legacy/ts4.2/account/Base.d.ts +14 -2
  194. package/types-legacy/ts4.2/account/Generalized.d.ts +1 -0
  195. package/types-legacy/ts4.2/account/Ledger.d.ts +1 -0
  196. package/types-legacy/ts4.2/account/Memory.d.ts +2 -0
  197. package/types-legacy/ts4.2/account/Rpc.d.ts +1 -6
  198. package/types-legacy/ts4.2/aens.d.ts +1 -1
  199. package/types-legacy/ts4.2/aepp-wallet-communication/rpc/types.d.ts +10 -0
  200. package/types-legacy/ts4.2/aepp-wallet-communication/schema.d.ts +1 -8
  201. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  202. package/types-legacy/ts4.2/apis/compiler/models/index.d.ts +1 -7
  203. package/types-legacy/ts4.2/apis/compiler/models/mappers.d.ts +0 -1
  204. package/types-legacy/ts4.2/apis/middleware/index.d.ts +2 -0
  205. package/types-legacy/ts4.2/apis/middleware/middleware.d.ts +309 -0
  206. package/types-legacy/ts4.2/apis/middleware/models/index.d.ts +1496 -0
  207. package/types-legacy/ts4.2/apis/middleware/models/mappers.d.ts +102 -0
  208. package/types-legacy/ts4.2/apis/middleware/models/parameters.d.ts +43 -0
  209. package/types-legacy/ts4.2/chain.d.ts +2 -1
  210. package/types-legacy/ts4.2/channel/Base.d.ts +1 -1
  211. package/types-legacy/ts4.2/contract/Contract.d.ts +1 -2
  212. package/types-legacy/ts4.2/contract/compiler/Base.d.ts +21 -0
  213. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +2 -0
  214. package/types-legacy/ts4.2/contract/compiler/Http.d.ts +2 -0
  215. package/types-legacy/ts4.2/contract/compiler/HttpNode.d.ts +1 -0
  216. package/types-legacy/ts4.2/deprecated.d.ts +14 -0
  217. package/types-legacy/ts4.2/index-browser.d.ts +20 -14
  218. package/types-legacy/ts4.2/tx/builder/constants.d.ts +0 -1
  219. package/types-legacy/ts4.2/tx/builder/field-types/coin-amount.d.ts +1 -1
  220. package/types-legacy/ts4.2/tx/builder/field-types/deposit.d.ts +1 -1
  221. package/types-legacy/ts4.2/tx/builder/field-types/index.d.ts +2 -2
  222. package/types-legacy/ts4.2/tx/builder/helpers.d.ts +8 -1
  223. package/types-legacy/ts4.2/tx/builder/index.d.ts +4 -2
  224. package/types-legacy/ts4.2/tx/builder/schema.d.ts +9 -9
  225. package/types-legacy/ts4.2/tx/execution-cost.d.ts +17 -0
  226. package/types-legacy/ts4.2/utils/amount-formatter.d.ts +1 -2
  227. package/types-legacy/ts4.2/utils/crypto.d.ts +1 -0
  228. package/types-legacy/ts4.2/utils/errors.d.ts +2 -2
  229. package/types-legacy/ts4.2/utils/other.d.ts +1 -0
  230. package/types-legacy/ts4.2/utils/typed-data.d.ts +60 -0
  231. package/types-legacy/ts4.5/AeSdkBase.d.ts +11 -3
  232. package/types-legacy/ts4.5/AeSdkMethods.d.ts +9 -14
  233. package/types-legacy/ts4.5/Middleware.d.ts +46 -0
  234. package/types-legacy/ts4.5/MiddlewareSubscriber.d.ts +30 -0
  235. package/types-legacy/ts4.5/Node.d.ts +1 -1
  236. package/types-legacy/ts4.5/account/Base.d.ts +14 -2
  237. package/types-legacy/ts4.5/account/Generalized.d.ts +1 -0
  238. package/types-legacy/ts4.5/account/Ledger.d.ts +1 -0
  239. package/types-legacy/ts4.5/account/Memory.d.ts +2 -0
  240. package/types-legacy/ts4.5/account/Rpc.d.ts +1 -6
  241. package/types-legacy/ts4.5/aens.d.ts +1 -1
  242. package/types-legacy/ts4.5/aepp-wallet-communication/rpc/types.d.ts +10 -0
  243. package/types-legacy/ts4.5/aepp-wallet-communication/schema.d.ts +1 -8
  244. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +1 -1
  245. package/types-legacy/ts4.5/apis/compiler/models/index.d.ts +1 -7
  246. package/types-legacy/ts4.5/apis/compiler/models/mappers.d.ts +0 -1
  247. package/types-legacy/ts4.5/apis/middleware/index.d.ts +2 -0
  248. package/types-legacy/ts4.5/apis/middleware/middleware.d.ts +309 -0
  249. package/types-legacy/ts4.5/apis/middleware/models/index.d.ts +1496 -0
  250. package/types-legacy/ts4.5/apis/middleware/models/mappers.d.ts +102 -0
  251. package/types-legacy/ts4.5/apis/middleware/models/parameters.d.ts +43 -0
  252. package/types-legacy/ts4.5/chain.d.ts +2 -1
  253. package/types-legacy/ts4.5/channel/Base.d.ts +1 -1
  254. package/types-legacy/ts4.5/contract/Contract.d.ts +1 -2
  255. package/types-legacy/ts4.5/contract/compiler/Base.d.ts +21 -0
  256. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +2 -0
  257. package/types-legacy/ts4.5/contract/compiler/Http.d.ts +2 -0
  258. package/types-legacy/ts4.5/contract/compiler/HttpNode.d.ts +1 -0
  259. package/types-legacy/ts4.5/deprecated.d.ts +14 -0
  260. package/types-legacy/ts4.5/index-browser.d.ts +20 -14
  261. package/types-legacy/ts4.5/tx/builder/constants.d.ts +0 -1
  262. package/types-legacy/ts4.5/tx/builder/field-types/coin-amount.d.ts +1 -1
  263. package/types-legacy/ts4.5/tx/builder/field-types/deposit.d.ts +1 -1
  264. package/types-legacy/ts4.5/tx/builder/field-types/index.d.ts +2 -2
  265. package/types-legacy/ts4.5/tx/builder/helpers.d.ts +8 -1
  266. package/types-legacy/ts4.5/tx/builder/index.d.ts +4 -2
  267. package/types-legacy/ts4.5/tx/builder/schema.d.ts +9 -9
  268. package/types-legacy/ts4.5/tx/execution-cost.d.ts +17 -0
  269. package/types-legacy/ts4.5/utils/amount-formatter.d.ts +1 -2
  270. package/types-legacy/ts4.5/utils/crypto.d.ts +1 -0
  271. package/types-legacy/ts4.5/utils/errors.d.ts +2 -2
  272. package/types-legacy/ts4.5/utils/other.d.ts +1 -0
  273. package/types-legacy/ts4.5/utils/typed-data.d.ts +60 -0
  274. package/es/typings/@aeternity__aepp-calldata/index.d.mjs +0 -2
  275. package/es/typings/@aeternity__aepp-calldata/index.d.mjs.map +0 -1
  276. package/src/typings/@aeternity__aepp-calldata/index.d.ts +0 -20
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-data.mjs","names":["ContractByteArrayEncoder","AciTypeResolver","canonicalize","decode","hash","messagePrefixLength","concatBuffers","hashJson","data","_canonicalize","encodeFateValue","value","aci","contractByteArrayEncoder","aciTypeResolver","isCustomType","encode","resolveType","decodeFateValue","decodeWithType","hashDomain","domain","domainAci","record","name","type","option","hashTypedData","Uint8Array"],"sources":["../../src/utils/typed-data.ts"],"sourcesContent":["// js extension is required for mjs build\n// @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216\n// eslint-disable-next-line import/extensions\nimport ContractByteArrayEncoder from '@aeternity/aepp-calldata/src/ContractByteArrayEncoder.js';\n// @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216\n// eslint-disable-next-line import/extensions\nimport AciTypeResolver from '@aeternity/aepp-calldata/src/AciTypeResolver.js';\nimport canonicalize from 'canonicalize';\nimport { Encoded, decode } from './encoder';\nimport { hash, messagePrefixLength } from './crypto';\nimport { concatBuffers } from './other';\n\n/**\n * Hashes arbitrary object, can be used to inline the aci hash to contract source code\n */\nexport function hashJson(data: unknown): Buffer {\n return hash(canonicalize(data) ?? '');\n}\n\n// TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215\n// based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129\nexport type AciValue = 'void' | 'unit' | 'int' | 'bool' | 'string' | 'bits' | 'hash' | 'signature'\n| 'address' | 'contract_pubkey' | 'Chain.ttl' | 'Chain.ga_meta_tx' | 'Chain.paying_for_tx'\n| 'Chain.base_tx' | 'AENS.pointee' | 'AENS.name' | 'MCL_BLS12_381.fr' | 'MCL_BLS12_381.fp'\n| { 'Set.set': readonly [AciValue] }\n| { bytes: number }\n| { list: readonly [AciValue] }\n| { map: readonly [AciValue, AciValue] }\n| { tuple: readonly AciValue[] }\n| { record: ReadonlyArray<{ name: string; type: AciValue }> }\n| { variant: ReadonlyArray<{ [key: string]: readonly AciValue[] }> }\n| { option: readonly [AciValue] }\n| { oracle: readonly [AciValue, AciValue] }\n| { oracle_query: readonly [AciValue, AciValue] };\n\nexport interface Domain {\n name?: string;\n version?: number;\n networkId?: string;\n contractAddress?: Encoded.ContractAddress;\n}\n\n// TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216\nexport function encodeFateValue(\n value: unknown,\n aci: AciValue,\n): Encoded.ContractBytearray {\n const contractByteArrayEncoder = new ContractByteArrayEncoder();\n const aciTypeResolver = new AciTypeResolver([]);\n aciTypeResolver.isCustomType = () => false;\n return contractByteArrayEncoder.encode(aciTypeResolver.resolveType(aci), value);\n}\n\n// TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216\nexport function decodeFateValue(\n value: Encoded.ContractBytearray,\n aci: AciValue,\n): Encoded.ContractBytearray {\n const contractByteArrayEncoder = new ContractByteArrayEncoder();\n const aciTypeResolver = new AciTypeResolver([]);\n aciTypeResolver.isCustomType = () => false;\n return contractByteArrayEncoder.decodeWithType(value, aciTypeResolver.resolveType(aci));\n}\n\n/**\n * Hashes domain object, can be used to inline domain hash to contract source code\n */\nexport function hashDomain(domain: Domain): Buffer {\n const domainAci = {\n record: [{\n name: 'name',\n type: { option: ['string'] },\n }, {\n name: 'version',\n type: { option: ['int'] },\n }, {\n name: 'networkId',\n type: { option: ['string'] },\n }, {\n name: 'contractAddress',\n type: { option: ['contract_pubkey'] },\n }],\n } as const;\n return hash(decode(encodeFateValue(domain, domainAci)));\n}\n\nexport function hashTypedData(\n data: Encoded.ContractBytearray,\n aci: AciValue,\n domain: Domain,\n): Buffer {\n return hash(concatBuffers([\n messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data)),\n ]));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,wBAAwB,MAAM,0DAA0D;AAC/F;AACA;AACA,OAAOC,eAAe,MAAM,iDAAiD;AAC7E,OAAOC,YAAY,MAAM,cAAc;AAAC,SACtBC,MAAM;AAAA,SACfC,IAAI,EAAEC,mBAAmB;AAAA,SACzBC,aAAa;AAEtB;AACA;AACA;AACA,OAAO,SAASC,QAAQA,CAACC,IAAa,EAAU;EAAA,IAAAC,aAAA;EAC9C,OAAOL,IAAI,EAAAK,aAAA,GAACP,YAAY,CAACM,IAAI,CAAC,cAAAC,aAAA,cAAAA,aAAA,GAAI,EAAE,CAAC;AACvC;;AAEA;AACA;;AAsBA;AACA,OAAO,SAASC,eAAeA,CAC7BC,KAAc,EACdC,GAAa,EACc;EAC3B,MAAMC,wBAAwB,GAAG,IAAIb,wBAAwB,EAAE;EAC/D,MAAMc,eAAe,GAAG,IAAIb,eAAe,CAAC,EAAE,CAAC;EAC/Ca,eAAe,CAACC,YAAY,GAAG,MAAM,KAAK;EAC1C,OAAOF,wBAAwB,CAACG,MAAM,CAACF,eAAe,CAACG,WAAW,CAACL,GAAG,CAAC,EAAED,KAAK,CAAC;AACjF;;AAEA;AACA,OAAO,SAASO,eAAeA,CAC7BP,KAAgC,EAChCC,GAAa,EACc;EAC3B,MAAMC,wBAAwB,GAAG,IAAIb,wBAAwB,EAAE;EAC/D,MAAMc,eAAe,GAAG,IAAIb,eAAe,CAAC,EAAE,CAAC;EAC/Ca,eAAe,CAACC,YAAY,GAAG,MAAM,KAAK;EAC1C,OAAOF,wBAAwB,CAACM,cAAc,CAACR,KAAK,EAAEG,eAAe,CAACG,WAAW,CAACL,GAAG,CAAC,CAAC;AACzF;;AAEA;AACA;AACA;AACA,OAAO,SAASQ,UAAUA,CAACC,MAAc,EAAU;EACjD,MAAMC,SAAS,GAAG;IAChBC,MAAM,EAAE,CAAC;MACPC,IAAI,EAAE,MAAM;MACZC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,QAAQ;MAAE;IAC7B,CAAC,EAAE;MACDF,IAAI,EAAE,SAAS;MACfC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,KAAK;MAAE;IAC1B,CAAC,EAAE;MACDF,IAAI,EAAE,WAAW;MACjBC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,QAAQ;MAAE;IAC7B,CAAC,EAAE;MACDF,IAAI,EAAE,iBAAiB;MACvBC,IAAI,EAAE;QAAEC,MAAM,EAAE,CAAC,iBAAiB;MAAE;IACtC,CAAC;EACH,CAAU;EACV,OAAOtB,IAAI,CAACD,MAAM,CAACO,eAAe,CAACW,MAAM,EAAEC,SAAS,CAAC,CAAC,CAAC;AACzD;AAEA,OAAO,SAASK,aAAaA,CAC3BnB,IAA+B,EAC/BI,GAAa,EACbS,MAAc,EACN;EACR,OAAOjB,IAAI,CAACE,aAAa,CAAC,CACxBD,mBAAmB,EAAE,IAAIuB,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,EAAER,UAAU,CAACC,MAAM,CAAC,EAAEd,QAAQ,CAACK,GAAG,CAAC,EAAER,IAAI,CAACD,MAAM,CAACK,IAAI,CAAC,CAAC,CAChG,CAAC,CAAC;AACL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeternity/aepp-sdk",
3
- "version": "13.0.0",
3
+ "version": "13.1.0",
4
4
  "description": "SDK for the æternity blockchain",
5
5
  "main": "dist/aepp-sdk.js",
6
6
  "types": "es/index.d.ts",
@@ -8,11 +8,17 @@
8
8
  "<4.5": {
9
9
  "es/index.d.ts": [
10
10
  "./types-legacy/ts4.2/index.d.ts"
11
+ ],
12
+ "es/index-browser.d.ts": [
13
+ "./types-legacy/ts4.2/index-browser.d.ts"
11
14
  ]
12
15
  },
13
16
  "<4.7": {
14
17
  "es/index.d.ts": [
15
18
  "./types-legacy/ts4.5/index.d.ts"
19
+ ],
20
+ "es/index-browser.d.ts": [
21
+ "./types-legacy/ts4.5/index-browser.d.ts"
16
22
  ]
17
23
  }
18
24
  },
@@ -23,9 +29,15 @@
23
29
  },
24
30
  "exports": {
25
31
  "node": {
32
+ "types@<4.5": "./types-legacy/ts4.2/index.d.ts",
33
+ "types@<4.7": "./types-legacy/ts4.5/index.d.ts",
34
+ "types": "./es/index.d.ts",
26
35
  "import": "./es/index.mjs",
27
36
  "default": "./dist/aepp-sdk.js"
28
37
  },
38
+ "types@<4.5": "./types-legacy/ts4.2/index-browser.d.ts",
39
+ "types@<4.7": "./types-legacy/ts4.5/index-browser.d.ts",
40
+ "types": "./es/index-browser.d.ts",
29
41
  "import": "./es/index-browser.mjs",
30
42
  "default": "./dist/aepp-sdk.browser.js"
31
43
  },
@@ -34,7 +46,10 @@
34
46
  "build:assets": "node tooling/fetch-aesophia-cli.mjs",
35
47
  "build:types": "tsc && node tooling/downlevel/run.mjs",
36
48
  "build:es": "babel src --config-file ./babel.esm.config.js --out-dir es --extensions .js,.ts --out-file-extension .mjs --source-maps true",
37
- "build:api": "node tooling/autorest/compiler-prepare.mjs && autorest tooling/autorest/compiler.yaml && autorest tooling/autorest/node.yaml",
49
+ "build:api:node": "autorest tooling/autorest/node.yaml",
50
+ "build:api:compiler": "node tooling/autorest/compiler-prepare.mjs && autorest tooling/autorest/compiler.yaml",
51
+ "build:api:middleware": "node tooling/autorest/middleware-prepare.mjs && autorest tooling/autorest/middleware.yaml",
52
+ "build:api": "npm run build:api:node && npm run build:api:compiler && npm run build:api:middleware",
38
53
  "build:generate": "ts-node --transpileOnly tooling/generate-schema.ts",
39
54
  "build": "npm run build:api && npm run build:generate && webpack && npm run build:types && npm run build:es && npm run build:assets",
40
55
  "docs:examples": "node tooling/docs/examples-to-md.js examples/node/*.mjs",
@@ -47,7 +62,7 @@
47
62
  "test:unit": "mocha './test/unit/'",
48
63
  "test:watch": "mocha './test/unit/' './test/integration/' --watch",
49
64
  "prepare": "npm run build",
50
- "prepublishOnly": "test/examples.sh && npm run docs:examples && npm run docs:api",
65
+ "prepublishOnly": "test/examples.sh",
51
66
  "release": "standard-version --skip.tag --infile docs/CHANGELOG.md",
52
67
  "release-alpha": "npm run release -- --prerelease alpha",
53
68
  "release-beta": "npm run release -- --prerelease beta"
@@ -74,13 +89,16 @@
74
89
  "@types/uuid": "^9.0.1",
75
90
  "@types/webextension-polyfill": "^0.10.0",
76
91
  "@types/websocket": "^1.0.5",
92
+ "@types/ws": "^8.5.4",
77
93
  "aes-js": "^3.1.2",
78
94
  "bignumber.js": "^9.1.1",
79
95
  "bip32-path": "^0.4.2",
80
96
  "blakejs": "^1.2.1",
81
97
  "bs58": "^5.0.0",
82
98
  "buffer": "^6.0.3",
99
+ "canonicalize": "^2.0.0",
83
100
  "events": "^3.3.0",
101
+ "isomorphic-ws": "^5.0.0",
84
102
  "json-bigint": "^1.0.0",
85
103
  "process": "^0.11.10",
86
104
  "rlp": "^3.0.0",
@@ -88,7 +106,8 @@
88
106
  "tweetnacl": "^1.0.3",
89
107
  "tweetnacl-auth": "^1.0.1",
90
108
  "varuint-bitcoin": "^1.1.2",
91
- "websocket": "^1.0.34"
109
+ "websocket": "^1.0.34",
110
+ "ws": "^8.13.0"
92
111
  },
93
112
  "repository": {
94
113
  "type": "git",
package/src/AeSdkBase.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import Node from './Node';
2
2
  import AccountBase from './account/Base';
3
- import { CompilerError, DuplicateNodeError, NodeNotFoundError } from './utils/errors';
3
+ import {
4
+ CompilerError, DuplicateNodeError, NodeNotFoundError, NotImplementedError, TypeError,
5
+ } from './utils/errors';
4
6
  import { Encoded } from './utils/encoder';
5
7
  import CompilerBase from './contract/compiler/Base';
6
- import AeSdkMethods, { OnAccount, getValueOrErrorProxy } from './AeSdkMethods';
8
+ import AeSdkMethods, { OnAccount, getValueOrErrorProxy, AeSdkMethodsOptions } from './AeSdkMethods';
7
9
 
8
10
  type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & { name: string };
9
11
 
@@ -23,7 +25,7 @@ export default class AeSdkBase extends AeSdkMethods {
23
25
  * @param options.nodes - Array of nodes
24
26
  */
25
27
  constructor(
26
- { nodes = [], ...options }: ConstructorParameters<typeof AeSdkMethods>[0] & {
28
+ { nodes = [], ...options }: AeSdkMethodsOptions & {
27
29
  nodes?: Array<{ name: string; instance: Node }>;
28
30
  } = {},
29
31
  ) {
@@ -127,6 +129,19 @@ export default class AeSdkBase extends AeSdkMethods {
127
129
  return [];
128
130
  }
129
131
 
132
+ /**
133
+ * Resolves an account
134
+ * @param account - ak-address, instance of AccountBase, or keypair
135
+ */
136
+ _resolveAccount(account: OnAccount = this._options.onAccount): AccountBase {
137
+ if (typeof account === 'string') throw new NotImplementedError('Address in AccountResolver');
138
+ if (typeof account === 'object') return account;
139
+ throw new TypeError(
140
+ 'Account should be an address (ak-prefixed string), '
141
+ + `or instance of AccountBase, got ${String(account)} instead`,
142
+ );
143
+ }
144
+
130
145
  get address(): Encoded.AccountAddress {
131
146
  return this._resolveAccount().address;
132
147
  }
@@ -153,15 +168,25 @@ export default class AeSdkBase extends AeSdkMethods {
153
168
  return this._resolveAccount(onAccount).signMessage(message, options);
154
169
  }
155
170
 
156
- override _getOptions(): {
171
+ async signTypedData(
172
+ data: Encoded.ContractBytearray,
173
+ aci: Parameters<AccountBase['signTypedData']>[1],
174
+ { onAccount, ...options }: { onAccount?: OnAccount } & Parameters<AccountBase['signTypedData']>[2] = {},
175
+ ): Promise<Encoded.Signature> {
176
+ return this._resolveAccount(onAccount).signTypedData(data, aci, options);
177
+ }
178
+
179
+ override _getOptions(callOptions: AeSdkMethodsOptions = {}): {
157
180
  onNode: Node;
158
181
  onAccount: AccountBase;
159
182
  onCompiler: CompilerBase;
160
183
  } {
161
184
  return {
162
- ...super._getOptions(),
185
+ ...this._options,
163
186
  onNode: getValueOrErrorProxy(() => this.api),
164
187
  onCompiler: getValueOrErrorProxy(() => this.compilerApi),
188
+ ...callOptions,
189
+ onAccount: getValueOrErrorProxy(() => this._resolveAccount(callOptions.onAccount)),
165
190
  };
166
191
  }
167
192
  }
@@ -11,25 +11,27 @@ import Node from './Node';
11
11
  import { TxParamsAsync } from './tx/builder/schema.generated';
12
12
  import AccountBase from './account/Base';
13
13
  import { Encoded } from './utils/encoder';
14
- import { ArgumentError, NotImplementedError, TypeError } from './utils/errors';
14
+ import CompilerBase from './contract/compiler/Base';
15
15
 
16
16
  export type OnAccount = Encoded.AccountAddress | AccountBase | undefined;
17
17
 
18
- export function getValueOrErrorProxy<Value extends object>(valueCb: () => Value): Value {
19
- return new Proxy({}, {
20
- ...Object.fromEntries([
18
+ export function getValueOrErrorProxy<Value extends object | undefined>(
19
+ valueCb: () => Value,
20
+ ): NonNullable<Value> {
21
+ return new Proxy(
22
+ {},
23
+ Object.fromEntries(([
21
24
  'apply', 'construct', 'defineProperty', 'deleteProperty', 'getOwnPropertyDescriptor',
22
25
  'getPrototypeOf', 'isExtensible', 'ownKeys', 'preventExtensions', 'set', 'setPrototypeOf',
23
- ].map((name) => [name, () => { throw new NotImplementedError(`${name} proxy request`); }])),
24
- get(t: {}, property: string | symbol, receiver: any) {
25
- const target = valueCb();
26
- const value = Reflect.get(target, property, receiver);
27
- return typeof value === 'function' ? value.bind(target) : value;
28
- },
29
- has(t: {}, property: string | symbol) {
30
- return Reflect.has(valueCb(), property);
31
- },
32
- }) as Value;
26
+ 'get', 'has',
27
+ ] as const).map((name) => [name, (t: {}, ...args: unknown[]) => {
28
+ const target = valueCb() as object; // to get a native exception in case it missed
29
+ const res = (Reflect[name] as any)(target, ...args);
30
+ return typeof res === 'function' && name === 'get'
31
+ ? res.bind(target) // otherwise it fails with attempted to get private field on non-instance
32
+ : res;
33
+ }])),
34
+ ) as NonNullable<Value>;
33
35
  }
34
36
 
35
37
  const { InvalidTxError: _2, ...chainMethodsOther } = chainMethods;
@@ -51,9 +53,8 @@ type GetMethodsOptions <Methods extends { [key: string]: Function }> =
51
53
  ? Args[Decrement<Args['length']>] : never
52
54
  };
53
55
  type MethodsOptions = GetMethodsOptions<typeof methods>;
54
- interface AeSdkMethodsOptions
56
+ export interface AeSdkMethodsOptions
55
57
  extends Partial<UnionToIntersection<MethodsOptions[keyof MethodsOptions]>> {
56
- nodes?: Array<{ name: string; instance: Node }>;
57
58
  }
58
59
 
59
60
  /**
@@ -79,24 +80,15 @@ class AeSdkMethods {
79
80
  Object.assign(this._options, options);
80
81
  }
81
82
 
82
- /**
83
- * Resolves an account
84
- * @param account - ak-address, instance of AccountBase, or keypair
85
- */
86
- // eslint-disable-next-line class-methods-use-this
87
- _resolveAccount(account?: OnAccount): AccountBase {
88
- if (typeof account === 'string') throw new NotImplementedError('Address in AccountResolver');
89
- if (typeof account === 'object') return account;
90
- throw new TypeError(
91
- 'Account should be an address (ak-prefixed string), '
92
- + `or instance of AccountBase, got ${String(account)} instead`,
93
- );
94
- }
95
-
96
- _getOptions(): AeSdkMethodsOptions & { onAccount: AccountBase } {
83
+ _getOptions(
84
+ callOptions: AeSdkMethodsOptions = {},
85
+ ): AeSdkMethodsOptions & { onAccount: AccountBase; onCompiler: CompilerBase; onNode: Node } {
97
86
  return {
98
87
  ...this._options,
99
- onAccount: getValueOrErrorProxy(() => this._resolveAccount()),
88
+ onAccount: getValueOrErrorProxy(() => this._options.onAccount),
89
+ onNode: getValueOrErrorProxy(() => this._options.onNode),
90
+ onCompiler: getValueOrErrorProxy(() => this._options.onCompiler),
91
+ ...callOptions,
100
92
  };
101
93
  }
102
94
 
@@ -107,16 +99,7 @@ class AeSdkMethods {
107
99
  async initializeContract<Methods extends ContractMethodsBase>(
108
100
  options?: Omit<Parameters<typeof Contract.initialize>[0], 'onNode'> & { onNode?: Node },
109
101
  ): Promise<Contract<Methods>> {
110
- const { onNode, onCompiler, ...otherOptions } = this._getOptions();
111
- if (onCompiler == null || onNode == null) {
112
- throw new ArgumentError('onCompiler, onNode', 'provided', null);
113
- }
114
- return Contract.initialize<Methods>({
115
- ...otherOptions,
116
- onNode,
117
- onCompiler,
118
- ...options,
119
- });
102
+ return Contract.initialize<Methods>(this._getOptions(options as AeSdkMethodsOptions));
120
103
  }
121
104
  }
122
105
 
@@ -147,18 +130,16 @@ Object.assign(AeSdkMethods.prototype, mapObject<Function, Function>(
147
130
  methods,
148
131
  ([name, handler]) => [
149
132
  name,
150
- function methodWrapper(...args: any[]) {
133
+ function methodWrapper(this: AeSdkMethods, ...args: any[]) {
151
134
  args.length = handler.length;
152
135
  const options = args[args.length - 1];
153
- args[args.length - 1] = {
154
- ...this._getOptions(),
155
- ...options,
156
- ...options?.onAccount != null && { onAccount: this._resolveAccount(options.onAccount) },
157
- };
136
+ args[args.length - 1] = this._getOptions(options);
158
137
  return handler(...args);
159
138
  },
160
139
  ],
161
140
  ));
162
141
 
163
- export default AeSdkMethods as new (options?: ConstructorParameters<typeof AeSdkMethods>[0]) =>
164
- AeSdkMethods & AeSdkMethodsTransformed;
142
+ type AeSdkMethodsTyped = AeSdkMethods & AeSdkMethodsTransformed;
143
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
144
+ const AeSdkMethodsTyped = AeSdkMethods as new (options?: AeSdkMethodsOptions) => AeSdkMethodsTyped;
145
+ export default AeSdkMethodsTyped;
@@ -4,7 +4,7 @@ import verifyTransaction from './tx/validator';
4
4
  import RpcClient from './aepp-wallet-communication/rpc/RpcClient';
5
5
  import {
6
6
  METHODS, RPC_STATUS, SUBSCRIPTION_TYPES, WALLET_TYPE,
7
- RpcBroadcastError, RpcInvalidTransactionError,
7
+ RpcInvalidTransactionError,
8
8
  RpcNotAuthorizeError, RpcPermissionDenyError, RpcUnsupportedProtocolError,
9
9
  } from './aepp-wallet-communication/schema';
10
10
  import { InternalError, UnknownRpcClientError } from './utils/errors';
@@ -242,14 +242,21 @@ export default class AeSdkWallet extends AeSdk {
242
242
  await this.onAskAccounts(id, params, origin);
243
243
  return this.addresses();
244
244
  },
245
- [METHODS.sign]: async ({ tx, onAccount = this.address, returnSigned }, origin) => {
245
+ [METHODS.sign]: async (
246
+ {
247
+ tx, onAccount = this.address, returnSigned, innerTx,
248
+ },
249
+ origin,
250
+ ) => {
246
251
  if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
247
252
  if (!this.addresses().includes(onAccount)) {
248
253
  throw new RpcPermissionDenyError(onAccount);
249
254
  }
250
255
 
251
- const parameters = { onAccount, aeppOrigin: origin, aeppRpcClientId: id };
252
- if (returnSigned) {
256
+ const parameters = {
257
+ onAccount, aeppOrigin: origin, aeppRpcClientId: id, innerTx,
258
+ };
259
+ if (returnSigned || innerTx === true) {
253
260
  return { signedTransaction: await this.signTransaction(tx, parameters) };
254
261
  }
255
262
  try {
@@ -259,7 +266,7 @@ export default class AeSdkWallet extends AeSdk {
259
266
  } catch (error) {
260
267
  const validation = await verifyTransaction(tx, this.api);
261
268
  if (validation.length > 0) throw new RpcInvalidTransactionError(validation);
262
- throw new RpcBroadcastError(error.message);
269
+ throw error;
263
270
  }
264
271
  },
265
272
  [METHODS.signMessage]: async ({ message, onAccount = this.address }, origin) => {
@@ -273,6 +280,21 @@ export default class AeSdkWallet extends AeSdk {
273
280
  signature: Buffer.from(await this.signMessage(message, parameters)).toString('hex'),
274
281
  };
275
282
  },
283
+ [METHODS.signTypedData]: async ({
284
+ domain, aci, data, onAccount = this.address,
285
+ }, origin) => {
286
+ if (!this._isRpcClientConnected(id)) throw new RpcNotAuthorizeError();
287
+ if (!this.addresses().includes(onAccount)) {
288
+ throw new RpcPermissionDenyError(onAccount);
289
+ }
290
+
291
+ const parameters = {
292
+ ...domain, onAccount, aeppOrigin: origin, aeppRpcClientId: id,
293
+ };
294
+ return {
295
+ signature: await this.signTypedData(data, aci, parameters),
296
+ };
297
+ },
276
298
  },
277
299
  ),
278
300
  };
@@ -0,0 +1,141 @@
1
+ // eslint-disable-next-line max-classes-per-file
2
+ import BigNumber from 'bignumber.js';
3
+ import { OperationArguments, OperationSpec } from '@azure/core-client';
4
+ import {
5
+ genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,
6
+ genVersionCheckPolicy, genRetryOnFailurePolicy,
7
+ } from './utils/autorest';
8
+ import { Middleware as MiddlewareApi, MiddlewareOptionalParams, ErrorResponse } from './apis/middleware';
9
+ import { mapObject } from './utils/other';
10
+ import { Encoded } from './utils/encoder';
11
+ import { ConsensusProtocolVersion } from './tx/builder/constants';
12
+
13
+ const bigIntPropertyNames = [] as const;
14
+
15
+ const numberPropertyNames = [] as const;
16
+
17
+ class MiddlewareTransformed extends MiddlewareApi {
18
+ override async sendOperationRequest(
19
+ operationArguments: OperationArguments,
20
+ operationSpec: OperationSpec,
21
+ ): Promise<any> {
22
+ const args = mapObject(
23
+ operationArguments,
24
+ ([key, value]) => [key, this.#encodeArg(value)],
25
+ ) as OperationArguments;
26
+ return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));
27
+ }
28
+
29
+ #mapData(data: any, transform: {
30
+ bigInt: (v: any) => any;
31
+ number: (v: any) => any;
32
+ }): unknown {
33
+ if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));
34
+ if (data != null && typeof data === 'object') {
35
+ return mapObject(data, ([key, value]) => {
36
+ if (value == null) return [key, value];
37
+ if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];
38
+ if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];
39
+ return [key, this.#mapData(value, transform)];
40
+ });
41
+ }
42
+ return data;
43
+ }
44
+
45
+ #encodeArg(data: any): any {
46
+ return this.#mapData(data, {
47
+ bigInt: (value) => {
48
+ if (value instanceof BigNumber) return value.toFixed();
49
+ return value.toString();
50
+ },
51
+ number: (value) => value.toString(),
52
+ });
53
+ }
54
+
55
+ #decodeRes(data: any): any {
56
+ return this.#mapData(data, {
57
+ bigInt: (value) => BigInt(value),
58
+ number: (value) => +value,
59
+ });
60
+ }
61
+ }
62
+
63
+ type BigIntPropertyNames = typeof bigIntPropertyNames[number];
64
+ type NumberPropertyNames = typeof numberPropertyNames[number];
65
+ type PreserveOptional<NewType, OrigType> =
66
+ OrigType extends undefined ? NewType | undefined : NewType;
67
+ export type TransformMiddlewareType<Type> =
68
+ Type extends (...args: infer Args) => infer Ret
69
+ ? (...args: TransformMiddlewareType<Args>) => TransformMiddlewareType<Ret>
70
+ : Type extends [infer Item, ...infer Rest]
71
+ ? [TransformMiddlewareType<Item>, ...TransformMiddlewareType<Rest>]
72
+ : Type extends Array<infer Item>
73
+ ? Array<TransformMiddlewareType<Item>>
74
+ : Type extends Promise<infer T>
75
+ ? Promise<TransformMiddlewareType<T>>
76
+ : Type extends { [P in any]: any }
77
+ ? {
78
+ [Property in keyof Type]:
79
+ Property extends BigIntPropertyNames
80
+ ? PreserveOptional<bigint, Type[Property]>
81
+ : Property extends NumberPropertyNames
82
+ ? PreserveOptional<number, Type[Property]>
83
+ : Property extends 'txHash'
84
+ ? PreserveOptional<Encoded.TxHash, Type[Property]>
85
+ : Property extends 'bytecode'
86
+ ? PreserveOptional<Encoded.ContractBytearray, Type[Property]>
87
+ : TransformMiddlewareType<Type[Property]>
88
+ }
89
+ : Type;
90
+ type MiddlewareTransformedApi = new (...args: ConstructorParameters<typeof MiddlewareApi>) => {
91
+ [Name in keyof InstanceType<typeof MiddlewareApi>]:
92
+ Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'
93
+ ? MiddlewareApi[Name] : TransformMiddlewareType<MiddlewareApi[Name]>
94
+ };
95
+
96
+ export interface MiddlewareInfo {
97
+ url: string;
98
+ nodeNetworkId: string;
99
+ version: string;
100
+ consensusProtocolVersion: ConsensusProtocolVersion;
101
+ }
102
+
103
+ export default class Middleware
104
+ extends (MiddlewareTransformed as unknown as MiddlewareTransformedApi) {
105
+ /**
106
+ * @param url - Url for middleware API
107
+ * @param options - Options
108
+ * @param options.ignoreVersion - Don't check node version
109
+ * @param options.retryCount - Amount of extra requests to do in case of failure
110
+ * @param options.retryOverallDelay - Time in ms to wait between all retries
111
+ */
112
+ constructor(
113
+ url: string,
114
+ {
115
+ ignoreVersion = false, retryCount = 3, retryOverallDelay = 800, ...options
116
+ }: MiddlewareOptionalParams & {
117
+ ignoreVersion?: boolean;
118
+ retryCount?: number;
119
+ retryOverallDelay?: number;
120
+ } = {},
121
+ ) {
122
+ // eslint-disable-next-line constructor-super
123
+ super(url, {
124
+ allowInsecureConnection: true,
125
+ additionalPolicies: [
126
+ genRequestQueuesPolicy(),
127
+ genCombineGetRequestsPolicy(),
128
+ genRetryOnFailurePolicy(retryCount, retryOverallDelay),
129
+ genErrorFormatterPolicy((body: ErrorResponse) => ` ${body.error}`),
130
+ ],
131
+ ...options,
132
+ });
133
+ if (!ignoreVersion) {
134
+ const statusPromise = this.getStatus();
135
+ const versionPromise = statusPromise.then(({ mdwVersion }) => mdwVersion, (error) => error);
136
+ this.pipeline.addPolicy(
137
+ genVersionCheckPolicy('middleware', '/v2/status', versionPromise, '1.47.0', '2.0.0'),
138
+ );
139
+ }
140
+ }
141
+ }