@aeternity/aepp-sdk 12.0.0 → 12.1.2

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 (283) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +2 -1
  5. package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +20765 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/AeSdk.d.ts +7 -7
  10. package/es/AeSdk.mjs.map +1 -1
  11. package/es/AeSdkAepp.d.ts +4 -3
  12. package/es/AeSdkAepp.mjs +2 -1
  13. package/es/AeSdkAepp.mjs.map +1 -1
  14. package/es/AeSdkBase.d.ts +22 -21
  15. package/es/AeSdkBase.mjs +25 -21
  16. package/es/AeSdkBase.mjs.map +1 -1
  17. package/es/AeSdkWallet.d.ts +4 -3
  18. package/es/AeSdkWallet.mjs +5 -1
  19. package/es/AeSdkWallet.mjs.map +1 -1
  20. package/es/Node.d.ts +7 -10
  21. package/es/Node.mjs +63 -57
  22. package/es/Node.mjs.map +1 -1
  23. package/es/account/Base.d.ts +7 -4
  24. package/es/account/Base.mjs +3 -3
  25. package/es/account/Base.mjs.map +1 -1
  26. package/es/account/Memory.d.ts +5 -4
  27. package/es/account/Memory.mjs +24 -2
  28. package/es/account/Memory.mjs.map +1 -1
  29. package/es/account/Rpc.d.ts +6 -6
  30. package/es/account/Rpc.mjs +3 -2
  31. package/es/account/Rpc.mjs.map +1 -1
  32. package/es/aens.d.ts +27 -14
  33. package/es/aens.mjs +27 -21
  34. package/es/aens.mjs.map +1 -1
  35. package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
  36. package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
  37. package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
  38. package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
  39. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
  40. package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
  41. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
  42. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
  43. package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
  44. package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
  45. package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
  46. package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
  47. package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
  48. package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
  49. package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
  50. package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
  51. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  52. package/es/aepp-wallet-communication/schema.d.ts +17 -2
  53. package/es/aepp-wallet-communication/schema.mjs +54 -17
  54. package/es/aepp-wallet-communication/schema.mjs.map +1 -1
  55. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
  56. package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
  57. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  58. package/es/apis/node/models/index.d.ts +6 -2
  59. package/es/apis/node/models/index.mjs.map +1 -1
  60. package/es/apis/node/models/mappers.mjs +4 -2
  61. package/es/apis/node/models/mappers.mjs.map +1 -1
  62. package/es/chain.d.ts +92 -64
  63. package/es/chain.mjs +190 -154
  64. package/es/chain.mjs.map +1 -1
  65. package/es/channel/handlers.d.ts +3 -3
  66. package/es/channel/handlers.mjs +42 -44
  67. package/es/channel/handlers.mjs.map +1 -1
  68. package/es/channel/index.d.ts +43 -52
  69. package/es/channel/index.mjs +46 -49
  70. package/es/channel/index.mjs.map +1 -1
  71. package/es/channel/internal.d.ts +16 -15
  72. package/es/channel/internal.mjs +67 -62
  73. package/es/channel/internal.mjs.map +1 -1
  74. package/es/contract/Compiler.d.ts +1 -0
  75. package/es/contract/Compiler.mjs +5 -4
  76. package/es/contract/Compiler.mjs.map +1 -1
  77. package/es/contract/aci.d.ts +17 -15
  78. package/es/contract/aci.mjs +58 -45
  79. package/es/contract/aci.mjs.map +1 -1
  80. package/es/contract/ga.d.ts +16 -15
  81. package/es/contract/ga.mjs +12 -7
  82. package/es/contract/ga.mjs.map +1 -1
  83. package/es/contract/methods.d.ts +9 -6
  84. package/es/contract/methods.mjs +9 -6
  85. package/es/contract/methods.mjs.map +1 -1
  86. package/es/deprecated/index.d.ts +143 -0
  87. package/es/deprecated/index.mjs +162 -0
  88. package/es/deprecated/index.mjs.map +1 -0
  89. package/es/deprecated/methods.d.ts +18 -0
  90. package/es/deprecated/methods.mjs +26 -0
  91. package/es/deprecated/methods.mjs.map +1 -0
  92. package/es/index.d.ts +4 -1
  93. package/es/index.mjs +4 -1
  94. package/es/index.mjs.map +1 -1
  95. package/es/oracle.d.ts +69 -62
  96. package/es/oracle.mjs +121 -103
  97. package/es/oracle.mjs.map +1 -1
  98. package/es/spend.d.ts +16 -15
  99. package/es/spend.mjs +19 -30
  100. package/es/spend.mjs.map +1 -1
  101. package/es/tx/builder/address.d.ts +25 -0
  102. package/es/tx/builder/address.mjs +45 -0
  103. package/es/tx/builder/address.mjs.map +1 -0
  104. package/es/tx/builder/constants.d.ts +55 -26
  105. package/es/tx/builder/constants.mjs +60 -38
  106. package/es/tx/builder/constants.mjs.map +1 -1
  107. package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
  108. package/es/tx/builder/field-types/coin-amount.mjs +26 -0
  109. package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
  110. package/es/tx/builder/field-types/deposit.d.ts +15 -0
  111. package/es/tx/builder/field-types/deposit.mjs +19 -0
  112. package/es/tx/builder/field-types/deposit.mjs.map +1 -0
  113. package/es/tx/builder/field-types/fee.d.ts +25 -0
  114. package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
  115. package/es/tx/builder/field-types/fee.mjs.map +1 -0
  116. package/es/tx/builder/field-types/field.d.ts +6 -0
  117. package/es/tx/builder/field-types/field.mjs +15 -0
  118. package/es/tx/builder/field-types/field.mjs.map +1 -0
  119. package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
  120. package/es/tx/builder/field-types/gas-limit.mjs +33 -0
  121. package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
  122. package/es/tx/builder/field-types/gas-price.d.ts +8 -0
  123. package/es/tx/builder/field-types/gas-price.mjs +18 -0
  124. package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
  125. package/es/tx/builder/field-types/index.d.ts +70 -0
  126. package/es/tx/builder/field-types/index.mjs +25 -0
  127. package/es/tx/builder/field-types/index.mjs.map +1 -0
  128. package/es/tx/builder/field-types/name-fee.d.ts +20 -0
  129. package/es/tx/builder/field-types/name-fee.mjs +24 -0
  130. package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
  131. package/es/tx/builder/field-types/name-id.d.ts +14 -0
  132. package/es/tx/builder/field-types/name-id.mjs +19 -0
  133. package/es/tx/builder/field-types/name-id.mjs.map +1 -0
  134. package/es/tx/builder/field-types/name.d.ts +13 -0
  135. package/es/tx/builder/field-types/name.mjs +18 -0
  136. package/es/tx/builder/field-types/name.mjs.map +1 -0
  137. package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
  138. package/es/tx/builder/field-types/short-u-int.mjs +12 -0
  139. package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
  140. package/es/tx/builder/field-types/u-int.d.ts +8 -0
  141. package/es/tx/builder/field-types/u-int.mjs +14 -0
  142. package/es/tx/builder/field-types/u-int.mjs.map +1 -0
  143. package/es/tx/builder/helpers.d.ts +27 -33
  144. package/es/tx/builder/helpers.mjs +41 -47
  145. package/es/tx/builder/helpers.mjs.map +1 -1
  146. package/es/tx/builder/index.d.ts +25 -12
  147. package/es/tx/builder/index.mjs +74 -83
  148. package/es/tx/builder/index.mjs.map +1 -1
  149. package/es/tx/builder/schema.d.ts +995 -144
  150. package/es/tx/builder/schema.mjs +121 -170
  151. package/es/tx/builder/schema.mjs.map +1 -1
  152. package/es/tx/index.d.ts +28 -27
  153. package/es/tx/index.mjs +97 -117
  154. package/es/tx/index.mjs.map +1 -1
  155. package/es/tx/validator.d.ts +4 -3
  156. package/es/tx/validator.mjs +79 -92
  157. package/es/tx/validator.mjs.map +1 -1
  158. package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
  159. package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
  160. package/es/typings/bip32-path/index.d.mjs.map +1 -1
  161. package/es/typings/blakejs/index.d.mjs.map +1 -1
  162. package/es/typings/sha-js/index.d.mjs +2 -0
  163. package/es/typings/sha-js/index.d.mjs.map +1 -0
  164. package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
  165. package/es/utils/amount-formatter.d.ts +9 -9
  166. package/es/utils/amount-formatter.mjs +17 -17
  167. package/es/utils/amount-formatter.mjs.map +1 -1
  168. package/es/utils/autorest.mjs +7 -7
  169. package/es/utils/autorest.mjs.map +1 -1
  170. package/es/utils/bignumber.mjs +2 -1
  171. package/es/utils/bignumber.mjs.map +1 -1
  172. package/es/utils/bytes.mjs +1 -1
  173. package/es/utils/bytes.mjs.map +1 -1
  174. package/es/utils/crypto.d.ts +8 -23
  175. package/es/utils/crypto.mjs +15 -41
  176. package/es/utils/crypto.mjs.map +1 -1
  177. package/es/utils/encoder-types.d.ts +61 -0
  178. package/es/utils/encoder-types.mjs +36 -0
  179. package/es/utils/encoder-types.mjs.map +1 -0
  180. package/es/utils/encoder.d.ts +6 -7
  181. package/es/utils/encoder.mjs +42 -26
  182. package/es/utils/encoder.mjs.map +1 -1
  183. package/es/utils/errors.d.ts +1 -11
  184. package/es/utils/errors.mjs +4 -20
  185. package/es/utils/errors.mjs.map +1 -1
  186. package/es/utils/hd-wallet.d.ts +18 -2
  187. package/es/utils/hd-wallet.mjs +64 -34
  188. package/es/utils/hd-wallet.mjs.map +1 -1
  189. package/es/utils/json-big.mjs +2 -2
  190. package/es/utils/json-big.mjs.map +1 -1
  191. package/es/utils/keystore.mjs +4 -2
  192. package/es/utils/keystore.mjs.map +1 -1
  193. package/es/utils/mptree.d.ts +2 -2
  194. package/es/utils/mptree.mjs +11 -6
  195. package/es/utils/mptree.mjs.map +1 -1
  196. package/es/utils/other.d.ts +8 -2
  197. package/es/utils/other.mjs +15 -3
  198. package/es/utils/other.mjs.map +1 -1
  199. package/es/utils/semver-satisfies.d.ts +1 -1
  200. package/es/utils/semver-satisfies.mjs +2 -2
  201. package/es/utils/semver-satisfies.mjs.map +1 -1
  202. package/es/utils/string.mjs.map +1 -1
  203. package/package.json +36 -34
  204. package/src/AeSdk.ts +30 -27
  205. package/src/AeSdkAepp.ts +93 -84
  206. package/src/AeSdkBase.ts +148 -130
  207. package/src/AeSdkWallet.ts +172 -156
  208. package/src/Node.ts +108 -102
  209. package/src/account/Base.ts +42 -32
  210. package/src/account/Memory.ts +45 -30
  211. package/src/account/Rpc.ts +32 -30
  212. package/src/aens.ts +124 -108
  213. package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
  214. package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
  215. package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
  216. package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
  217. package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
  218. package/src/aepp-wallet-communication/rpc/types.ts +32 -32
  219. package/src/aepp-wallet-communication/schema.ts +117 -74
  220. package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
  221. package/src/apis/node/code-model-v4.yaml +54 -20
  222. package/src/apis/node/models/index.ts +6 -2
  223. package/src/apis/node/models/mappers.ts +4 -2
  224. package/src/chain.ts +286 -228
  225. package/src/channel/handlers.ts +424 -372
  226. package/src/channel/index.ts +285 -251
  227. package/src/channel/internal.ts +248 -232
  228. package/src/contract/Compiler.ts +22 -21
  229. package/src/contract/aci.ts +267 -258
  230. package/src/contract/ga.ts +93 -72
  231. package/src/contract/methods.ts +32 -27
  232. package/src/deprecated/index.ts +172 -0
  233. package/src/deprecated/methods.ts +25 -0
  234. package/src/index.ts +37 -32
  235. package/src/oracle.ts +211 -189
  236. package/src/spend.ts +82 -70
  237. package/src/tx/builder/address.ts +50 -0
  238. package/src/tx/builder/constants.ts +82 -52
  239. package/src/tx/builder/field-types/coin-amount.ts +27 -0
  240. package/src/tx/builder/field-types/deposit.ts +21 -0
  241. package/src/tx/builder/field-types/fee.ts +143 -0
  242. package/src/tx/builder/field-types/field.ts +9 -0
  243. package/src/tx/builder/field-types/gas-limit.ts +41 -0
  244. package/src/tx/builder/field-types/gas-price.ts +16 -0
  245. package/src/tx/builder/field-types/index.ts +45 -0
  246. package/src/tx/builder/field-types/name-fee.ts +32 -0
  247. package/src/tx/builder/field-types/name-id.ts +20 -0
  248. package/src/tx/builder/field-types/name.ts +18 -0
  249. package/src/tx/builder/field-types/short-u-int.ts +11 -0
  250. package/src/tx/builder/field-types/u-int.ts +16 -0
  251. package/src/tx/builder/helpers.ts +112 -117
  252. package/src/tx/builder/index.ts +203 -197
  253. package/src/tx/builder/schema.ts +421 -465
  254. package/src/tx/index.ts +128 -135
  255. package/src/tx/validator.ts +165 -161
  256. package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
  257. package/src/typings/@aeternity__uuid/index.d.ts +3 -1
  258. package/src/typings/bip32-path/index.d.ts +6 -6
  259. package/src/typings/blakejs/index.d.ts +4 -32
  260. package/src/typings/sha-js/index.d.ts +5 -0
  261. package/src/typings/tweetnacl-auth/index.d.ts +2 -2
  262. package/src/utils/amount-formatter.ts +41 -41
  263. package/src/utils/autorest.ts +57 -54
  264. package/src/utils/bignumber.ts +7 -6
  265. package/src/utils/bytes.ts +19 -19
  266. package/src/utils/crypto.ts +82 -94
  267. package/src/utils/encoder-types.ts +63 -0
  268. package/src/utils/encoder.ts +104 -56
  269. package/src/utils/errors.ts +246 -264
  270. package/src/utils/hd-wallet.ts +114 -82
  271. package/src/utils/json-big.ts +16 -15
  272. package/src/utils/keystore.ts +65 -62
  273. package/src/utils/mptree.ts +59 -56
  274. package/src/utils/other.ts +26 -18
  275. package/src/utils/semver-satisfies.ts +15 -11
  276. package/src/utils/string.ts +10 -10
  277. package/es/tx/builder/field-types.d.ts +0 -62
  278. package/es/tx/builder/field-types.mjs +0 -126
  279. package/es/tx/builder/field-types.mjs.map +0 -1
  280. package/es/tx/min-fee.d.ts +0 -20
  281. package/es/tx/min-fee.mjs.map +0 -1
  282. package/src/tx/builder/field-types.ts +0 -111
  283. package/src/tx/min-fee.ts +0 -136
package/src/Node.ts CHANGED
@@ -1,40 +1,88 @@
1
- import BigNumber from 'bignumber.js'
2
- import { OperationArguments, OperationSpec } from '@azure/core-client'
1
+ // eslint-disable-next-line max-classes-per-file
2
+ import BigNumber from 'bignumber.js';
3
+ import { OperationArguments, OperationSpec } from '@azure/core-client';
3
4
  import {
4
5
  genRequestQueuesPolicy, genCombineGetRequestsPolicy, genErrorFormatterPolicy,
5
- genVersionCheckPolicy
6
- } from './utils/autorest'
7
- import { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node/'
8
- import { mapObject } from './utils/other'
9
- import { EncodedData } from './utils/encoder'
10
- import { MissingParamError } from './utils/errors'
6
+ genVersionCheckPolicy,
7
+ } from './utils/autorest';
8
+ import { Node as NodeApi, NodeOptionalParams, ErrorModel } from './apis/node';
9
+ import { mapObject } from './utils/other';
10
+ import { Encoded } from './utils/encoder';
11
+ import { MissingParamError } from './utils/errors';
11
12
 
12
13
  /**
13
14
  * Obtain networkId from account or node
14
15
  */
15
- export async function getNetworkId ({ networkId }: { networkId?: string } = {}): Promise<string> {
16
- const res = networkId ?? this.networkId ?? (await this.api?.getStatus()).networkId
17
- if (res != null) return res
18
- throw new MissingParamError('networkId is not provided')
16
+ export async function getNetworkId({ networkId }: { networkId?: string } = {}): Promise<string> {
17
+ const res = networkId ?? this.networkId ?? (await this.api?.getStatus())?.networkId;
18
+ if (res != null) return res;
19
+ throw new MissingParamError('networkId is not provided');
19
20
  }
20
21
 
21
22
  const bigIntPropertyNames = [
22
23
  'balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount',
23
24
  'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal',
24
- 'responderAmountFinal', 'gasPrice', 'deposit'
25
- ] as const
25
+ 'responderAmountFinal', 'gasPrice', 'deposit',
26
+ ] as const;
26
27
 
27
28
  const numberPropertyNames = [
28
29
  'time', 'gas', 'gasUsed', 'nameSalt',
29
- 'nonce', 'nextNonce', 'height', 'blockHeight', 'top', 'topBlockHeight', 'ttl',
30
+ 'nonce', 'nextNonce', 'height', 'blockHeight', 'top', 'topBlockHeight',
31
+ 'ttl', 'nameTtl', 'clientTtl',
30
32
  'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight',
31
- 'version', 'solutions'
32
- ] as const
33
+ 'version', 'solutions', 'round',
34
+ ] as const;
33
35
 
34
- type BigIntPropertyNames = typeof bigIntPropertyNames[number]
35
- type NumberPropertyNames = typeof numberPropertyNames[number]
36
+ class NodeTransformed extends NodeApi {
37
+ async sendOperationRequest(
38
+ operationArguments: OperationArguments,
39
+ operationSpec: OperationSpec,
40
+ ): Promise<any> {
41
+ const args = mapObject(
42
+ operationArguments,
43
+ ([key, value]) => [key, this.#encodeArg(value)],
44
+ ) as OperationArguments;
45
+ return this.#decodeRes(await super.sendOperationRequest(args, operationSpec));
46
+ }
47
+
48
+ #mapData(data: any, transform: {
49
+ bigInt: (v: any) => any;
50
+ number: (v: any) => any;
51
+ }): unknown {
52
+ if (Array.isArray(data)) return data.map((d) => this.#mapData(d, transform));
53
+ if (data != null && typeof data === 'object') {
54
+ return mapObject(data, ([key, value]) => {
55
+ if (value == null) return [key, value];
56
+ if (bigIntPropertyNames.some((k) => k === key)) return [key, transform.bigInt(value)];
57
+ if (numberPropertyNames.some((k) => k === key)) return [key, transform.number(value)];
58
+ return [key, this.#mapData(value, transform)];
59
+ });
60
+ }
61
+ return data;
62
+ }
63
+
64
+ #encodeArg(data: any): any {
65
+ return this.#mapData(data, {
66
+ bigInt: (value) => {
67
+ if (value instanceof BigNumber) return value.toFixed();
68
+ return value.toString();
69
+ },
70
+ number: (value) => value.toString(),
71
+ });
72
+ }
73
+
74
+ #decodeRes(data: any): any {
75
+ return this.#mapData(data, {
76
+ bigInt: (value) => BigInt(value),
77
+ number: (value) => +value,
78
+ });
79
+ }
80
+ }
81
+
82
+ type BigIntPropertyNames = typeof bigIntPropertyNames[number];
83
+ type NumberPropertyNames = typeof numberPropertyNames[number];
36
84
  type PreserveOptional<NewType, OrigType> =
37
- OrigType extends undefined ? NewType | undefined : NewType
85
+ OrigType extends undefined ? NewType | undefined : NewType;
38
86
  export type TransformNodeType<Type> =
39
87
  Type extends (...args: infer Args) => infer Ret
40
88
  ? (...args: TransformNodeType<Args>) => TransformNodeType<Ret>
@@ -46,38 +94,40 @@ export type TransformNodeType<Type> =
46
94
  ? Promise<TransformNodeType<T>>
47
95
  : Type extends { [P in any]: any }
48
96
  ? {
49
- [Property in keyof Type]:
50
- Property extends BigIntPropertyNames
51
- ? PreserveOptional<bigint, Type[Property]>
52
- : Property extends NumberPropertyNames
53
- ? PreserveOptional<number, Type[Property]>
54
- : Property extends 'txHash'
55
- ? PreserveOptional<EncodedData<'th'>, Type[Property]>
56
- : TransformNodeType<Type[Property]>
57
- }
58
- : Type
59
- type TransformedNode = new (...args: ConstructorParameters<typeof NodeApi>) => {
60
- [Name in keyof InstanceType<typeof NodeApi>]: TransformNodeType<NodeApi[Name]>
61
- }
97
+ [Property in keyof Type]:
98
+ Property extends BigIntPropertyNames
99
+ ? PreserveOptional<bigint, Type[Property]>
100
+ : Property extends NumberPropertyNames
101
+ ? PreserveOptional<number, Type[Property]>
102
+ : Property extends 'txHash'
103
+ ? PreserveOptional<Encoded.TxHash, Type[Property]>
104
+ : TransformNodeType<Type[Property]>
105
+ }
106
+ : Type;
107
+ type NodeTransformedApi = new (...args: ConstructorParameters<typeof NodeApi>) => {
108
+ [Name in keyof InstanceType<typeof NodeApi>]:
109
+ Name extends 'pipeline' | 'sendRequest' | 'sendOperationRequest'
110
+ ? NodeApi[Name] : TransformNodeType<NodeApi[Name]>
111
+ };
62
112
 
63
113
  export interface NodeInfo {
64
- url: string
65
- nodeNetworkId: string
66
- version: string
67
- consensusProtocolVersion: number
114
+ url: string;
115
+ nodeNetworkId: string;
116
+ version: string;
117
+ consensusProtocolVersion: number;
68
118
  }
69
119
 
70
- export default class Node extends (NodeApi as unknown as TransformedNode) {
71
- url: string
120
+ export default class Node extends (NodeTransformed as unknown as NodeTransformedApi) {
121
+ url: string;
72
122
 
73
123
  /**
74
124
  * @param url - Url for node API
75
125
  * @param options - Options
76
126
  * @param options.ignoreVersion - Don't check node version
77
127
  */
78
- constructor (
128
+ constructor(
79
129
  url: string,
80
- { ignoreVersion = false, ...options }: NodeOptionalParams & { ignoreVersion?: boolean } = {}
130
+ { ignoreVersion = false, ...options }: NodeOptionalParams & { ignoreVersion?: boolean } = {},
81
131
  ) {
82
132
  // eslint-disable-next-line constructor-super
83
133
  super(url, {
@@ -85,83 +135,39 @@ export default class Node extends (NodeApi as unknown as TransformedNode) {
85
135
  additionalPolicies: [
86
136
  genRequestQueuesPolicy(),
87
137
  genCombineGetRequestsPolicy(),
88
- genErrorFormatterPolicy((body: ErrorModel) => ` ${body.reason}`)
138
+ genErrorFormatterPolicy((body: ErrorModel) => ` ${body.reason}`),
89
139
  ],
90
- ...options
91
- })
92
- this.url = url
140
+ ...options,
141
+ });
142
+ this.url = url;
93
143
  if (!ignoreVersion) {
94
- const versionPromise = this.getStatus().then(({ nodeVersion }) => nodeVersion)
95
- this.pipeline.addPolicy(genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'))
144
+ const versionPromise = this.getStatus().then(({ nodeVersion }) => nodeVersion);
145
+ this.pipeline.addPolicy(
146
+ genVersionCheckPolicy('node', '/v3/status', versionPromise, '6.2.0', '7.0.0'),
147
+ );
96
148
  }
97
- this.intAsString = true
149
+ this.intAsString = true;
98
150
  }
99
151
 
100
- async getNodeInfo (): Promise<NodeInfo> {
152
+ async getNodeInfo(): Promise<NodeInfo> {
101
153
  const {
102
154
  nodeVersion: version,
103
155
  networkId: nodeNetworkId,
104
156
  protocols,
105
- topBlockHeight
106
- } = await this.getStatus()
157
+ topBlockHeight,
158
+ } = await this.getStatus();
107
159
  const consensusProtocolVersion = protocols
108
160
  .filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)
109
161
  .reduce(
110
- (acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
111
- { effectiveAtHeight: -1, version: 0 }
162
+ (acc, p) => (p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc),
163
+ { effectiveAtHeight: -1, version: 0 },
112
164
  )
113
- .version
165
+ .version;
114
166
  return {
115
167
  url: this.url,
116
168
  nodeNetworkId,
117
169
  version,
118
- consensusProtocolVersion
119
- }
120
- }
121
-
122
- // @ts-expect-error https://github.com/microsoft/TypeScript/issues/27689
123
- async sendOperationRequest (
124
- operationArguments: OperationArguments, operationSpec: OperationSpec
125
- ): Promise<any> {
126
- const args = mapObject(
127
- operationArguments,
128
- ([key, value]) => [key, this.#encodeArg(value)]
129
- ) as OperationArguments
130
- return this.#decodeRes(await super.sendOperationRequest(args, operationSpec))
131
- }
132
-
133
- #mapData (
134
- data: any, transform: {
135
- bigInt: (v: any) => any
136
- number: (v: any) => any
137
- }
138
- ): unknown {
139
- if (Array.isArray(data)) return data.map(d => this.#mapData(d, transform))
140
- if (data != null && typeof data === 'object') {
141
- return mapObject(data, ([key, value]) => {
142
- if (value == null) return [key, value]
143
- if (bigIntPropertyNames.some(k => k === key)) return [key, transform.bigInt(value)]
144
- if (numberPropertyNames.some(k => k === key)) return [key, transform.number(value)]
145
- return [key, this.#mapData(value, transform)]
146
- })
147
- }
148
- return data
149
- }
150
-
151
- #encodeArg (data: any): any {
152
- return this.#mapData(data, {
153
- bigInt: value => {
154
- if (value instanceof BigNumber) return value.toFixed()
155
- return value.toString()
156
- },
157
- number: value => value.toString()
158
- })
159
- }
160
-
161
- #decodeRes (data: any): any {
162
- return this.#mapData(data, {
163
- bigInt: value => BigInt(value),
164
- number: value => +value
165
- })
170
+ consensusProtocolVersion,
171
+ };
166
172
  }
167
173
  }
@@ -14,33 +14,35 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
- import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto'
18
- import { buildTx } from '../tx/builder'
19
- import { decode, EncodedData } from '../utils/encoder'
20
- import { TX_TYPE } from '../tx/builder/schema'
21
- import { getNetworkId } from '../Node'
22
- import { concatBuffers } from '../utils/other'
17
+ import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto';
18
+ import { buildTx } from '../tx/builder';
19
+ import { decode, Encoded } from '../utils/encoder';
20
+ import { Tag } from '../tx/builder/constants';
21
+ import { getNetworkId } from '../Node';
22
+ import { concatBuffers } from '../utils/other';
23
+ import type { createMetaTx } from '../contract/ga';
23
24
 
24
25
  /**
25
26
  * Check is provided object looks like an instance of AccountBase
26
27
  * @param acc - Object to check
27
28
  */
28
- export const isAccountBase = (acc: AccountBase | any): boolean =>
29
- !['sign', 'address', 'signTransaction', 'signMessage'].some(f => typeof acc[f] !== 'function')
29
+ export const isAccountBase = (acc: AccountBase | any): boolean => (
30
+ !['sign', 'address', 'signTransaction', 'signMessage'].some((f) => typeof acc[f] !== 'function')
31
+ );
30
32
 
31
33
  /**
32
34
  * Account is one of the three basic building blocks of an
33
35
  * {@link AeSdk} and provides access to a signing key pair.
34
36
  */
35
37
  export default abstract class AccountBase {
36
- networkId?: string
38
+ networkId?: string;
37
39
 
38
40
  /**
39
41
  * @param options - Options
40
42
  * @param options.networkId - Using for signing transactions
41
43
  */
42
- constructor ({ networkId }: { networkId?: string } = {}) {
43
- this.networkId ??= networkId
44
+ constructor({ networkId }: { networkId?: string } = {}) {
45
+ this.networkId ??= networkId;
44
46
  }
45
47
 
46
48
  /**
@@ -50,24 +52,29 @@ export default abstract class AccountBase {
50
52
  * @param opt.innerTx - Sign as inner transaction for PayingFor
51
53
  * @returns Signed transaction
52
54
  */
53
- async signTransaction (
54
- tx: EncodedData<'tx'>,
55
- { innerTx, networkId, ...options }: { innerTx?: boolean, networkId?: string } = {}
56
- ): Promise<EncodedData<'tx'>> {
57
- const prefixes = [await this.getNetworkId({ networkId })]
58
- if (innerTx === true) prefixes.push('inner_tx')
59
- const rlpBinaryTx = decode(tx)
60
- const txWithNetworkId = concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)])
55
+ async signTransaction(
56
+ tx: Encoded.Transaction,
57
+ { innerTx, networkId, ...options }: {
58
+ innerTx?: boolean;
59
+ networkId?: string;
60
+ authData?: Parameters<typeof createMetaTx>[1];
61
+ authFun?: Parameters<typeof createMetaTx>[2];
62
+ } & Omit<Partial<Parameters<typeof createMetaTx>[3]>, 'onAccount'> = {},
63
+ ): Promise<Encoded.Transaction> {
64
+ const prefixes = [await this.getNetworkId({ networkId })];
65
+ if (innerTx === true) prefixes.push('inner_tx');
66
+ const rlpBinaryTx = decode(tx);
67
+ const txWithNetworkId = concatBuffers([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);
61
68
 
62
- const signatures = [await this.sign(txWithNetworkId, options)]
63
- return buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed).tx
69
+ const signatures = [await this.sign(txWithNetworkId, options)];
70
+ return buildTx({ encodedTx: rlpBinaryTx, signatures }, Tag.SignedTx).tx;
64
71
  }
65
72
 
66
73
  /**
67
74
  * Get network Id
68
75
  * @returns Network Id
69
76
  */
70
- readonly getNetworkId = getNetworkId
77
+ readonly getNetworkId = getNetworkId;
71
78
 
72
79
  /**
73
80
  * Sign message
@@ -75,11 +82,12 @@ export default abstract class AccountBase {
75
82
  * @param opt - Options
76
83
  * @returns Signature as hex string of Uint8Array
77
84
  */
78
- async signMessage (
79
- message: string, { returnHex = false, ...options }: { returnHex?: boolean } = {}
85
+ async signMessage(
86
+ message: string,
87
+ { returnHex = false, ...options }: { returnHex?: boolean } = {},
80
88
  ): Promise<string | Uint8Array> {
81
- const sig = await this.sign(messageToHash(message), options)
82
- return returnHex ? Buffer.from(sig).toString('hex') : sig
89
+ const sig = await this.sign(messageToHash(message), options);
90
+ return returnHex ? Buffer.from(sig).toString('hex') : sig;
83
91
  }
84
92
 
85
93
  /**
@@ -88,14 +96,16 @@ export default abstract class AccountBase {
88
96
  * @param signature - Signature
89
97
  * @param options - Options
90
98
  */
91
- async verifyMessage (
92
- message: string, signature: string | Uint8Array, options?: object
99
+ async verifyMessage(
100
+ message: string,
101
+ signature: string | Uint8Array,
102
+ options?: object,
93
103
  ): Promise<boolean> {
94
104
  return verifyMessageCrypto(
95
105
  message,
96
106
  typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature,
97
- decode(await this.address(options))
98
- )
107
+ decode(await this.address(options)),
108
+ );
99
109
  }
100
110
 
101
111
  /**
@@ -104,11 +114,11 @@ export default abstract class AccountBase {
104
114
  * @param options - Options
105
115
  * @returns Signed data blob
106
116
  */
107
- abstract sign (data: string | Uint8Array, options?: any): Promise<Uint8Array>
117
+ abstract sign(data: string | Uint8Array, options?: any): Promise<Uint8Array>;
108
118
 
109
119
  /**
110
120
  * Obtain account address
111
121
  * @returns Public account address
112
122
  */
113
- abstract address (opt?: object): Promise<EncodedData<'ak'>>
123
+ abstract address(opt?: object): Promise<Encoded.AccountAddress>;
114
124
  }
@@ -14,25 +14,25 @@
14
14
  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
15
  * PERFORMANCE OF THIS SOFTWARE.
16
16
  */
17
- import AccountBase from './Base'
18
- import { sign, isValidKeypair } from '../utils/crypto'
19
- import { isHex } from '../utils/string'
20
- import { decode } from '../tx/builder/helpers'
21
- import { InvalidKeypairError, MissingParamError } from '../utils/errors'
22
- import { EncodedData } from '../utils/encoder'
17
+ import AccountBase from './Base';
18
+ import { sign, isValidKeypair } from '../utils/crypto';
19
+ import { isHex } from '../utils/string';
20
+ import { ArgumentError, InvalidKeypairError, MissingParamError } from '../utils/errors';
21
+ import { decode, Encoded } from '../utils/encoder';
22
+ import { createMetaTx } from '../contract/ga';
23
23
 
24
- const secrets = new WeakMap()
24
+ const secrets = new WeakMap();
25
25
 
26
26
  export interface Keypair {
27
- publicKey: EncodedData<'ak'>
28
- secretKey: string | Uint8Array
27
+ publicKey: Encoded.AccountAddress;
28
+ secretKey: string | Uint8Array;
29
29
  }
30
30
 
31
31
  /**
32
32
  * In-memory account class
33
33
  */
34
34
  export default class AccountMemory extends AccountBase {
35
- isGa: boolean
35
+ isGa: boolean;
36
36
 
37
37
  /**
38
38
  * @param options - Options
@@ -41,43 +41,58 @@ export default class AccountMemory extends AccountBase {
41
41
  * @param options.keypair.secretKey - Private key
42
42
  * @param options.gaId - Address of generalized account
43
43
  */
44
- constructor (
45
- { keypair, gaId, ...options }: { keypair?: Keypair, gaId?: EncodedData<'ak'> } & ConstructorParameters<typeof AccountBase>[0]
44
+ constructor(
45
+ { keypair, gaId, ...options }: { keypair?: Keypair; gaId?: Encoded.AccountAddress }
46
+ & ConstructorParameters<typeof AccountBase>[0],
46
47
  ) {
47
- super(options)
48
+ super(options);
48
49
 
49
- this.isGa = gaId != null
50
+ this.isGa = gaId != null;
50
51
  if (this.isGa && gaId != null) {
51
- decode(gaId)
52
- secrets.set(this, { publicKey: gaId })
53
- return
52
+ decode(gaId);
53
+ secrets.set(this, { publicKey: gaId });
54
+ return;
54
55
  }
55
56
 
56
- if (keypair == null) throw new MissingParamError('Either gaId or keypair is required')
57
+ if (keypair == null) throw new MissingParamError('Either gaId or keypair is required');
57
58
 
58
59
  if (
59
- !Buffer.isBuffer(keypair.secretKey) &&
60
- typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey)
61
- ) throw new InvalidKeypairError('Secret key must be hex string or Buffer')
60
+ !Buffer.isBuffer(keypair.secretKey)
61
+ && typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey)
62
+ ) throw new InvalidKeypairError('Secret key must be hex string or Buffer');
62
63
  const secretKey = typeof keypair.secretKey === 'string'
63
64
  ? Buffer.from(keypair.secretKey, 'hex')
64
- : keypair.secretKey
65
+ : keypair.secretKey;
65
66
  if (!isValidKeypair(secretKey, decode(keypair.publicKey))) {
66
- throw new InvalidKeypairError('Invalid Key Pair')
67
+ throw new InvalidKeypairError('Invalid Key Pair');
67
68
  }
68
69
 
69
70
  secrets.set(this, {
70
71
  secretKey,
71
- publicKey: keypair.publicKey
72
- })
72
+ publicKey: keypair.publicKey,
73
+ });
73
74
  }
74
75
 
75
- async sign (data: string | Uint8Array): Promise<Uint8Array> {
76
- if (this.isGa) throw new InvalidKeypairError('You are trying to sign data using generalized account without keypair')
77
- return sign(data, secrets.get(this).secretKey)
76
+ async sign(data: string | Uint8Array): Promise<Uint8Array> {
77
+ if (this.isGa) throw new InvalidKeypairError('You are trying to sign data using generalized account without keypair');
78
+ return sign(data, secrets.get(this).secretKey);
78
79
  }
79
80
 
80
- async address (): Promise<EncodedData<'ak'>> {
81
- return secrets.get(this).publicKey
81
+ async signTransaction(
82
+ tx: Encoded.Transaction,
83
+ options: Parameters<AccountBase['signTransaction']>[1] = {},
84
+ ): Promise<Encoded.Transaction> {
85
+ if (!this.isGa || options.innerTx === true) return super.signTransaction(tx, options);
86
+ const {
87
+ authData, authFun, onCompiler, onNode,
88
+ } = options;
89
+ if (authFun == null || authData == null || onCompiler == null || onNode == null) {
90
+ throw new ArgumentError('authData, authFun, onCompiler, onNode', 'provided', null);
91
+ }
92
+ return createMetaTx(tx, authData, authFun, { onCompiler, onNode, onAccount: this });
93
+ }
94
+
95
+ async address(): Promise<Encoded.AccountAddress> {
96
+ return secrets.get(this).publicKey;
82
97
  }
83
98
  }
@@ -1,7 +1,7 @@
1
- import AccountBase from './Base'
2
- import { METHODS } from '../aepp-wallet-communication/schema'
3
- import { NotImplementedError } from '../utils/errors'
4
- import { EncodedData } from '../utils/encoder'
1
+ import AccountBase from './Base';
2
+ import { METHODS } from '../aepp-wallet-communication/schema';
3
+ import { NotImplementedError } from '../utils/errors';
4
+ import { Encoded } from '../utils/encoder';
5
5
 
6
6
  /**
7
7
  * Account provided by wallet
@@ -11,34 +11,36 @@ import { EncodedData } from '../utils/encoder'
11
11
  * @returns AccountRpc instance
12
12
  */
13
13
  export default class AccountRpc extends AccountBase {
14
- _rpcClient: any
15
- _address: EncodedData<'ak'>
14
+ _rpcClient: any;
16
15
 
17
- constructor (
18
- { rpcClient, address, ...options }:
19
- { rpcClient: any, address: EncodedData<'ak'> } & ConstructorParameters<typeof AccountBase>[0]
16
+ _address: Encoded.AccountAddress;
17
+
18
+ constructor(
19
+ { rpcClient, address, ...options }: { rpcClient: any; address: Encoded.AccountAddress }
20
+ & ConstructorParameters<typeof AccountBase>[0],
20
21
  ) {
21
- super(options)
22
- this._rpcClient = rpcClient
23
- this._address = address
22
+ super(options);
23
+ this._rpcClient = rpcClient;
24
+ this._address = address;
24
25
  }
25
26
 
26
- async sign (data: string | Uint8Array, options?: any): Promise<Uint8Array> {
27
- throw new NotImplementedError('RAW signing using wallet')
27
+ // eslint-disable-next-line class-methods-use-this
28
+ async sign(): Promise<Uint8Array> {
29
+ throw new NotImplementedError('RAW signing using wallet');
28
30
  }
29
31
 
30
- async address (): Promise<EncodedData<'ak'>> {
31
- return this._address
32
+ async address(): Promise<Encoded.AccountAddress> {
33
+ return this._address;
32
34
  }
33
35
 
34
36
  /**
35
37
  * @returns Signed transaction
36
38
  */
37
- async signTransaction (
38
- tx: EncodedData<'tx'>,
39
- { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {}
40
- ): Promise<EncodedData<'tx'>> {
41
- if (innerTx != null) throw new NotImplementedError('innerTx option in AccountRpc')
39
+ async signTransaction(
40
+ tx: Encoded.Transaction,
41
+ { innerTx, networkId }: Parameters<AccountBase['signTransaction']>[1] = {},
42
+ ): Promise<Encoded.Transaction> {
43
+ if (innerTx != null) throw new NotImplementedError('innerTx option in AccountRpc');
42
44
  const res = await this._rpcClient.request(METHODS.sign, {
43
45
  onAccount: this._address,
44
46
  tx,
@@ -48,20 +50,20 @@ export default class AccountRpc extends AccountBase {
48
50
  * required to maintain backward compatibility with wallets using SDK v11.0.1 and below
49
51
  * @see {@link https://github.com/aeternity/aepp-sdk-js/commit/153fd89a52c4eab39fcd659b356b36d32129c1ba}
50
52
  */
51
- networkId
52
- })
53
- return res.signedTransaction
53
+ networkId,
54
+ });
55
+ return res.signedTransaction;
54
56
  }
55
57
 
56
58
  /**
57
59
  * @returns Signed message
58
60
  */
59
- async signMessage (
60
- message: string, { returnHex = false }: Parameters<AccountBase['signMessage']>[1] = {}
61
+ async signMessage(
62
+ message: string,
63
+ { returnHex = false }: Parameters<AccountBase['signMessage']>[1] = {},
61
64
  ): Promise<string | Uint8Array> {
62
- const { signature } = await this._rpcClient.request(
63
- METHODS.signMessage, { onAccount: this._address, message }
64
- )
65
- return returnHex ? signature : Buffer.from(signature, 'hex')
65
+ const { signature } = await this._rpcClient
66
+ .request(METHODS.signMessage, { onAccount: this._address, message });
67
+ return returnHex ? signature : Buffer.from(signature, 'hex');
66
68
  }
67
69
  }