@aeternity/aepp-sdk 12.0.0 → 12.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 (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 +20764 -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 +35 -33
  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 +170 -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
@@ -1,226 +1,230 @@
1
- import { verify, hash } from '../utils/crypto'
2
- import { encode, decode } from './builder/helpers'
3
- import BigNumber from 'bignumber.js'
1
+ import BigNumber from 'bignumber.js';
2
+ import { hash, verify } from '../utils/crypto';
4
3
  import {
5
- PROTOCOL_VM_ABI, RawTxObject, TxSchema, TxParamsCommon, TX_TYPE, TxTypeSchemas, CtVersion
6
- } from './builder/schema'
7
- import { TxUnpacked, unpackTx } from './builder'
8
- import calculateMinFee from './min-fee'
9
- import { UnsupportedProtocolError } from '../utils/errors'
10
- import { concatBuffers, isKeyOfObject } from '../utils/other'
11
- import { EncodedData } from '../utils/encoder'
12
- import Node from '../Node'
4
+ CtVersion,
5
+ PROTOCOL_VM_ABI,
6
+ RawTxObject,
7
+ TxParamsCommon,
8
+ TxSchema,
9
+ TxTypeSchemas,
10
+ } from './builder/schema';
11
+ import { Tag } from './builder/constants';
12
+ import { TxUnpacked, unpackTx } from './builder';
13
+ import { UnsupportedProtocolError } from '../utils/errors';
14
+ import { concatBuffers, isKeyOfObject } from '../utils/other';
15
+ import {
16
+ decode, encode, Encoded, Encoding,
17
+ } from '../utils/encoder';
18
+ import Node from '../Node';
13
19
 
14
20
  interface Account {
15
- balance: bigint
16
- id: EncodedData<'ak'>
17
- nonce: number
21
+ balance: bigint;
22
+ id: Encoded.AccountAddress;
23
+ nonce: number;
18
24
  }
19
25
 
20
26
  export interface ValidatorResult {
21
- message: string
22
- key: string
23
- checkedKeys: string[]
27
+ message: string;
28
+ key: string;
29
+ checkedKeys: string[];
24
30
  }
25
31
 
26
32
  type Validator = (
27
33
  tx: {
28
- encodedTx: TxUnpacked<TxSchema>
29
- signatures: Buffer[]
34
+ encodedTx: TxUnpacked<TxSchema>;
35
+ signatures: Buffer[];
30
36
  tx: TxUnpacked<TxSchema> & {
31
- tx: TxTypeSchemas[TX_TYPE.signed]
32
- }
33
- nonce?: number
34
- ttl?: number
35
- amount?: number
36
- fee?: number
37
- nameFee?: number
38
- ctVersion?: Partial<CtVersion>
39
- abiVersion?: number
40
- contractId?: EncodedData<'ct'>
37
+ tx: TxTypeSchemas[Tag.SignedTx];
38
+ };
39
+ nonce?: number;
40
+ ttl?: number;
41
+ amount?: number;
42
+ fee?: number;
43
+ nameFee?: number;
44
+ ctVersion?: Partial<CtVersion>;
45
+ abiVersion?: number;
46
+ contractId?: Encoded.ContractAddress;
41
47
  },
42
48
  options: {
43
- account?: Account
44
- nodeNetworkId: string
45
- parentTxTypes: TX_TYPE[]
46
- node: Node
47
- txType: TX_TYPE
48
- height: number
49
- consensusProtocolVersion: number
49
+ account?: Account;
50
+ nodeNetworkId: string;
51
+ parentTxTypes: Tag[];
52
+ node: Node;
53
+ txType: Tag;
54
+ height: number;
55
+ consensusProtocolVersion: number;
50
56
  }
51
- ) => ValidatorResult[] | Promise<ValidatorResult[]>
57
+ ) => ValidatorResult[] | Promise<ValidatorResult[]>;
58
+
59
+ const validators: Validator[] = [];
52
60
 
53
- const validators: Validator[] = [
61
+ const getSenderAddress = (
62
+ tx: TxParamsCommon | RawTxObject<TxSchema>,
63
+ ): Encoded.AccountAddress | undefined => [
64
+ 'senderId', 'accountId', 'ownerId', 'callerId',
65
+ 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId',
66
+ ]
67
+ .map((key: keyof TxSchema) => tx[key])
68
+ .filter((a) => a)
69
+ .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as Encoded.AccountAddress | undefined;
70
+
71
+ /**
72
+ * Transaction Validator
73
+ * This function validates some of transaction properties,
74
+ * to make sure it can be posted it to the chain
75
+ * @category transaction builder
76
+ * @param transaction - Base64Check-encoded transaction
77
+ * @param node - Node to validate transaction against
78
+ * @param parentTxTypes - Types of parent transactions
79
+ * @returns Array with verification errors
80
+ * @example const errors = await verifyTransaction(transaction, node)
81
+ */
82
+ export default async function verifyTransaction(
83
+ transaction: Encoded.Transaction | Encoded.Poi,
84
+ node: Node,
85
+ parentTxTypes: Tag[] = [],
86
+ ): Promise<ValidatorResult[]> {
87
+ const { tx, txType } = unpackTx<Tag.SignedTx>(transaction);
88
+ const address = getSenderAddress(tx)
89
+ ?? (txType === Tag.SignedTx ? getSenderAddress(tx.encodedTx.tx) : undefined);
90
+ const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([
91
+ address == null
92
+ ? undefined
93
+ : node.getAccountByPubkey(address)
94
+ .catch(() => ({ id: address, balance: 0n, nonce: 0 }))
95
+ // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
96
+ .then((acc) => ({ ...acc, id: acc.id as Encoded.AccountAddress })),
97
+ node.getCurrentKeyBlockHeight(),
98
+ node.getNodeInfo(),
99
+ ]);
100
+
101
+ return (await Promise.all(
102
+ validators.map((v) => v(
103
+ tx as any,
104
+ {
105
+ txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes,
106
+ },
107
+ )),
108
+ )).flat();
109
+ }
110
+
111
+ validators.push(
54
112
  ({ encodedTx, signatures }, { account, nodeNetworkId, parentTxTypes }) => {
55
- if ((encodedTx ?? signatures) === undefined) return []
56
- if (account == null) return []
57
- if (signatures.length !== 1) return [] // TODO: Support multisignature?
113
+ if ((encodedTx ?? signatures) === undefined) return [];
114
+ if (account == null) return [];
115
+ if (signatures.length !== 1) return []; // TODO: Support multisignature?
58
116
  const prefix = Buffer.from([
59
117
  nodeNetworkId,
60
- ...parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : []
61
- ].join('-'))
62
- const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded])
63
- const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)])
64
- const decodedPub = decode(account.id)
65
- if (verify(txWithNetworkId, signatures[0], decodedPub) ||
66
- verify(txHashWithNetworkId, signatures[0], decodedPub)) return []
118
+ ...parentTxTypes.includes(Tag.PayingForTx) ? ['inner_tx'] : [],
119
+ ].join('-'));
120
+ const txWithNetworkId = concatBuffers([prefix, encodedTx.rlpEncoded]);
121
+ const txHashWithNetworkId = concatBuffers([prefix, hash(encodedTx.rlpEncoded)]);
122
+ const decodedPub = decode(account.id);
123
+ if (verify(txWithNetworkId, signatures[0], decodedPub)
124
+ || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];
67
125
  return [{
68
- message: 'Signature cannot be verified, please ensure that you transaction have' +
69
- ' the correct prefix and the correct private key for the sender address',
126
+ message: 'Signature cannot be verified, please ensure that you transaction have'
127
+ + ' the correct prefix and the correct private key for the sender address',
70
128
  key: 'InvalidSignature',
71
- checkedKeys: ['encodedTx', 'signatures']
72
- }]
129
+ checkedKeys: ['encodedTx', 'signatures'],
130
+ }];
73
131
  },
74
132
  async ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {
75
- if ((encodedTx ?? tx) === undefined) return []
76
- return await verifyTransaction(
77
- encode((encodedTx ?? tx).rlpEncoded, 'tx'),
133
+ if ((encodedTx ?? tx) === undefined) return [];
134
+ return verifyTransaction(
135
+ encode((encodedTx ?? tx).rlpEncoded, Encoding.Transaction),
78
136
  node,
79
- [...parentTxTypes, txType]
80
- )
81
- },
82
- (tx: any, { txType }) => {
83
- if (tx.fee === undefined) return []
84
- const minFee = calculateMinFee(txType, { params: tx, vsn: tx.VSN })
85
- if (minFee.lte(tx.fee)) return []
86
- return [{
87
- message: `Fee ${tx.fee as string} is too low, minimum fee for this transaction is ${minFee.toString()}`,
88
- key: 'InsufficientFee',
89
- checkedKeys: ['fee']
90
- }]
137
+ [...parentTxTypes, txType],
138
+ );
91
139
  },
92
140
  ({ ttl }, { height }) => {
93
- if (ttl === undefined) return []
94
- ttl = +ttl
95
- if (ttl === 0 || ttl >= height) return []
141
+ if (ttl === undefined) return [];
142
+ ttl = +ttl;
143
+ if (ttl === 0 || ttl >= height) return [];
96
144
  return [{
97
145
  message: `TTL ${ttl} is already expired, current height is ${height}`,
98
146
  key: 'ExpiredTTL',
99
- checkedKeys: ['ttl']
100
- }]
147
+ checkedKeys: ['ttl'],
148
+ }];
101
149
  },
102
- ({ amount, fee, nameFee, tx }, { account, parentTxTypes, txType }) => {
103
- if (account == null) return []
104
- if ((amount ?? fee ?? nameFee) === undefined) return []
105
- fee ??= 0
150
+ ({
151
+ amount, fee, nameFee, tx,
152
+ }, { account, parentTxTypes, txType }) => {
153
+ if (account == null) return [];
154
+ if ((amount ?? fee ?? nameFee) === undefined) return [];
155
+ fee ??= 0;
106
156
  const cost = new BigNumber(fee).plus(nameFee ?? 0).plus(amount ?? 0)
107
- .plus(txType === TX_TYPE.payingFor ? (tx.tx.encodedTx.tx).fee : 0)
108
- .minus(parentTxTypes.includes(TX_TYPE.payingFor) ? fee : 0)
109
- if (cost.lte(account.balance.toString())) return []
157
+ .plus(txType === Tag.PayingForTx ? (tx.tx.encodedTx.tx).fee : 0)
158
+ .minus(parentTxTypes.includes(Tag.PayingForTx) ? fee : 0);
159
+ if (cost.lte(account.balance.toString())) return [];
110
160
  return [{
111
161
  message: `Account balance ${account.balance.toString()} is not enough to execute the transaction that costs ${cost.toFixed()}`,
112
162
  key: 'InsufficientBalance',
113
- checkedKeys: ['amount', 'fee', 'nameFee']
114
- }]
163
+ checkedKeys: ['amount', 'fee', 'nameFee'],
164
+ }];
115
165
  },
116
166
  ({ nonce }, { account, parentTxTypes }) => {
117
- if (nonce == null || account == null || parentTxTypes.includes(TX_TYPE.gaMeta)) return []
118
- nonce = +nonce
119
- const validNonce = account.nonce + 1
120
- if (nonce === validNonce) return []
167
+ if (nonce == null || account == null || parentTxTypes.includes(Tag.GaMetaTx)) return [];
168
+ nonce = +nonce;
169
+ const validNonce = account.nonce + 1;
170
+ if (nonce === validNonce) return [];
121
171
  return [{
122
172
  ...nonce < validNonce
123
173
  ? {
124
- message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
125
- key: 'NonceAlreadyUsed'
126
- }
174
+ message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,
175
+ key: 'NonceAlreadyUsed',
176
+ }
127
177
  : {
128
- message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,
129
- key: 'NonceHigh'
130
- },
131
- checkedKeys: ['nonce']
132
- }]
178
+ message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,
179
+ key: 'NonceHigh',
180
+ },
181
+ checkedKeys: ['nonce'],
182
+ }];
133
183
  },
134
184
  ({ ctVersion, abiVersion }, { txType, consensusProtocolVersion }) => {
135
185
  if (!isKeyOfObject(consensusProtocolVersion, PROTOCOL_VM_ABI)) {
136
- throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`)
186
+ throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`);
137
187
  }
138
- const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
188
+ const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
139
189
 
140
190
  // If not contract create tx
141
- if (ctVersion == null) ctVersion = { abiVersion }
142
- const txProtocol = protocol[txType as keyof typeof protocol]
143
- if (txProtocol == null) return []
191
+ if (ctVersion == null) ctVersion = { abiVersion };
192
+ const txProtocol = protocol[txType as keyof typeof protocol];
193
+ if (txProtocol == null) return [];
144
194
  if (Object.entries(ctVersion).some(
145
195
  ([
146
196
  key,
147
- value
197
+ value,
148
198
  ]: [
149
199
  key:keyof typeof txProtocol,
150
- value:any]) => !(txProtocol[key].includes(+value as never)))) {
200
+ value:any]) => !(txProtocol[key].includes(+value as never)),
201
+ )) {
151
202
  return [{
152
203
  message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,
153
204
  key: 'VmAndAbiVersionMismatch',
154
- checkedKeys: ['ctVersion', 'abiVersion']
155
- }]
205
+ checkedKeys: ['ctVersion', 'abiVersion'],
206
+ }];
156
207
  }
157
- return []
208
+ return [];
158
209
  },
159
210
  async ({ contractId }, { txType, node }) => {
160
- if (TX_TYPE.contractCall !== txType) return []
161
- contractId = contractId as EncodedData<'ct'>
211
+ if (Tag.ContractCallTx !== txType) return [];
212
+ contractId = contractId as Encoded.ContractAddress;
162
213
  try {
163
- const { active } = await node.getContract(contractId)
164
- if (active) return []
214
+ const { active } = await node.getContract(contractId);
215
+ if (active) return [];
165
216
  return [{
166
217
  message: `Contract ${contractId} is not active`,
167
218
  key: 'ContractNotActive',
168
- checkedKeys: ['contractId']
169
- }]
219
+ checkedKeys: ['contractId'],
220
+ }];
170
221
  } catch (error) {
171
- if (error.response?.parsedBody?.reason == null) throw error
222
+ if (error.response?.parsedBody?.reason == null) throw error;
172
223
  return [{
173
224
  message: error.response.parsedBody.reason,
174
225
  key: 'ContractNotFound',
175
- checkedKeys: ['contractId']
176
- }]
226
+ checkedKeys: ['contractId'],
227
+ }];
177
228
  }
178
- }
179
- ]
180
-
181
- const getSenderAddress = (
182
- tx: TxParamsCommon | RawTxObject<TxSchema>
183
- ): EncodedData<'ak'> | undefined => [
184
- 'senderId', 'accountId', 'ownerId', 'callerId',
185
- 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'
186
- ]
187
- .map((key: keyof TxSchema) => tx[key])
188
- .filter(a => a)
189
- .map((a) => a?.toString().replace(/^ok_/, 'ak_'))[0] as EncodedData<'ak'> | undefined
190
-
191
- /**
192
- * Transaction Validator
193
- * This function validates some of transaction properties,
194
- * to make sure it can be posted it to the chain
195
- * @param transaction - Base64Check-encoded transaction
196
- * @param node - Node to validate transaction against
197
- * @param parentTxTypes - Types of parent transactions
198
- * @returns Array with verification errors
199
- * @example const errors = await verifyTransaction(transaction, node)
200
- */
201
- export default async function verifyTransaction (
202
- transaction: EncodedData<'tx' | 'pi'>,
203
- node: Node,
204
- parentTxTypes: TX_TYPE[] = []
205
- ): Promise<ValidatorResult[]> {
206
- const { tx, txType } = unpackTx<TX_TYPE.signed>(transaction)
207
- const address = getSenderAddress(tx) ??
208
- (txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : undefined)
209
- const [account, { height }, { consensusProtocolVersion, nodeNetworkId }] = await Promise.all([
210
- address == null
211
- ? undefined
212
- : node.getAccountByPubkey(address)
213
- .catch(() => ({ id: address, balance: 0n, nonce: 0 }))
214
- // TODO: remove after fixing https://github.com/aeternity/aepp-sdk-js/issues/1537
215
- .then(acc => ({ ...acc, id: acc.id as EncodedData<'ak'> })),
216
- node.getCurrentKeyBlockHeight(),
217
- node.getNodeInfo()
218
- ])
219
-
220
- return (await Promise.all(
221
- validators.map(v => v(
222
- tx as any,
223
- { txType, node, account, height, consensusProtocolVersion, nodeNetworkId, parentTxTypes }
224
- ))
225
- )).flat()
226
- }
229
+ },
230
+ );
@@ -1,3 +1,3 @@
1
1
  declare module '@aeternity/argon2-browser/dist/argon2-bundled.min.js' {
2
- export * from 'argon2-browser'
2
+ export * from 'argon2-browser';
3
3
  }
@@ -1,3 +1,5 @@
1
1
  declare module '@aeternity/uuid' {
2
- export * from 'uuid'
2
+ // Already depends on @types/uuid
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
+ export * from 'uuid';
3
5
  }
@@ -2,32 +2,32 @@
2
2
 
3
3
  declare module 'bip32-path' {
4
4
  interface BipPath {
5
- toPathArray: () => number[]
5
+ toPathArray: () => number[];
6
6
  /**
7
7
  * returns a text encoded path. Set to noRoot to true to omit the m/ prefix.
8
8
  * Set oldStyle true to use h instead of ' for marking hardened nodes.
9
9
  */
10
- toString: (noRoot: boolean, oldStyle: boolean) => string
10
+ toString: (noRoot: boolean, oldStyle: boolean) => string;
11
11
 
12
12
  /**
13
13
  * returns true if the input is a valid path string
14
14
  */
15
- validateString: (path: string) => boolean
15
+ validateString: (path: string) => boolean;
16
16
 
17
17
  /**
18
18
  * returns true if the input is a valid binary path array
19
19
  */
20
- validatePathArray: (path: string) => boolean
20
+ validatePathArray: (path: string) => boolean;
21
21
  }
22
22
 
23
23
  /**
24
24
  * creates an instance from a path written as text.
25
25
  * Set reqRoot to true if the m/ prefix is mandatory.
26
26
  */
27
- export const fromString: (text: string, reqRoot?: boolean) => BipPath
27
+ export const fromString: (text: string, reqRoot?: boolean) => BipPath;
28
28
 
29
29
  /**
30
30
  * creates an instance from a binary path array
31
31
  */
32
- export const fromPathArray: (path: string) => BipPath
32
+ export const fromPathArray: (path: string) => BipPath;
33
33
  }
@@ -1,33 +1,5 @@
1
- declare module 'blakejs' {
2
- interface Context {
3
- b: Uint8Array
4
- h: Uint32Array
5
- t: number
6
- c: number
7
- outlen: number
8
- }
9
-
10
- export type Data = Buffer | Uint8Array | string
11
-
12
- type Key = Uint8Array | null
13
-
14
- export const blake2b: (data: Data, key?: Key, outlen?: number) => Uint8Array
15
-
16
- export const blake2bFinal: (context: Context) => Uint8Array
17
-
18
- export const blake2bHex: (data: Data, key?: Key, outlen?: number) => string
19
-
20
- export const blake2bInit: (outlen?: number, key?: Key) => Context
21
-
22
- export const blake2bUpdate: (context: Context, data: Data) => void
23
-
24
- export const blake2s: (data: Data, key?: Key, outlen?: number) => Uint8Array
25
-
26
- export const blake2sFinal: (context: Context) => Uint8Array
27
-
28
- export const blake2sHex: (data: Data, key?: Key, outlen?: number) => string
29
-
30
- export const blake2sInit: (outlen?: number, key?: Key) => Context
31
-
32
- export const blake2sUpdate: (context: Context, data: Data) => void
1
+ declare module 'blakejs/blake2b.js' {
2
+ export {
3
+ Blake2bCTX, blake2bInit, blake2bUpdate, blake2bFinal, blake2b, blake2bHex,
4
+ } from 'blakejs';
33
5
  }
@@ -0,0 +1,5 @@
1
+ declare module 'sha.js/sha256.js' {
2
+ import { sha256 } from 'sha.js';
3
+
4
+ export default sha256;
5
+ }
@@ -5,10 +5,10 @@ declare module 'tweetnacl-auth' {
5
5
  * Authenticates the given message with the secret key.
6
6
  * (In other words, returns HMAC-SHA-512-256 of the message under the key.)
7
7
  */
8
- export default function (message: Uint8Array, key: Uint8Array): Uint8Array
8
+ export default function (message: Uint8Array, key: Uint8Array): Uint8Array;
9
9
 
10
10
  /**
11
11
  * Returns HMAC-SHA-512 (without truncation) of the message under the key
12
12
  */
13
- export const full: (message: Uint8Array, key: Uint8Array) => Uint8Array
13
+ export const full: (message: Uint8Array, key: Uint8Array) => Uint8Array;
14
14
  }
@@ -14,9 +14,9 @@
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 BigNumber from 'bignumber.js'
18
- import { isBigNumber } from './bignumber'
19
- import { ArgumentError } from './errors'
17
+ import BigNumber from 'bignumber.js';
18
+ import { isBigNumber } from './bignumber';
19
+ import { ArgumentError } from './errors';
20
20
 
21
21
  export enum AE_AMOUNT_FORMATS {
22
22
  AE = 'ae',
@@ -25,7 +25,7 @@ export enum AE_AMOUNT_FORMATS {
25
25
  NANO_AE = 'nanoAE',
26
26
  PICO_AE = 'picoAE',
27
27
  FEMTO_AE = 'femtoAE',
28
- AETTOS = 'aettos'
28
+ AETTOS = 'aettos',
29
29
  }
30
30
 
31
31
  /**
@@ -38,77 +38,77 @@ const DENOMINATION_MAGNITUDE = {
38
38
  [AE_AMOUNT_FORMATS.NANO_AE]: -9,
39
39
  [AE_AMOUNT_FORMATS.PICO_AE]: -12,
40
40
  [AE_AMOUNT_FORMATS.FEMTO_AE]: -15,
41
- [AE_AMOUNT_FORMATS.AETTOS]: -18
42
- } as const
41
+ [AE_AMOUNT_FORMATS.AETTOS]: -18,
42
+ } as const;
43
43
 
44
44
  /**
45
- * Convert amount to AE
45
+ * Convert amount from one to other denomination
46
46
  * @param value - amount to convert
47
47
  * @param options - options
48
48
  * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
49
+ * @param options.targetDenomination - target denomination,
50
+ * can be ['ae', 'aettos']
49
51
  */
50
- export const toAe = (
51
- value: string | number | BigNumber,
52
- { denomination = AE_AMOUNT_FORMATS.AETTOS }: { denomination?: AE_AMOUNT_FORMATS } = {}
53
- ): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE })
52
+ export const formatAmount = (
53
+ value: string | number | bigint | BigNumber,
54
+ { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS }:
55
+ { denomination?: AE_AMOUNT_FORMATS; targetDenomination?: AE_AMOUNT_FORMATS },
56
+ ): string => {
57
+ if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value);
58
+
59
+ return new BigNumber(typeof value === 'bigint' ? value.toString() : value)
60
+ .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])
61
+ .toFixed();
62
+ };
54
63
 
55
64
  /**
56
- * Convert amount to aettos
65
+ * Convert amount to AE
57
66
  * @param value - amount to convert
58
67
  * @param options - options
59
68
  * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
60
69
  */
61
- export const toAettos = (
70
+ export const toAe = (
62
71
  value: string | number | BigNumber,
63
- { denomination = AE_AMOUNT_FORMATS.AE }: { denomination?: AE_AMOUNT_FORMATS } = {}
64
- ): string => formatAmount(value, { denomination })
72
+ { denomination = AE_AMOUNT_FORMATS.AETTOS }: { denomination?: AE_AMOUNT_FORMATS } = {},
73
+ ): string => formatAmount(value, { denomination, targetDenomination: AE_AMOUNT_FORMATS.AE });
65
74
 
66
75
  /**
67
- * Convert amount from one to other denomination
76
+ * Convert amount to aettos
68
77
  * @param value - amount to convert
69
78
  * @param options - options
70
79
  * @param options.denomination - denomination of amount, can be ['ae', 'aettos']
71
- * @param options.targetDenomination - target denomination,
72
- * can be ['ae', 'aettos']
73
80
  */
74
- export const formatAmount = (
75
- value: string | number | bigint | BigNumber,
76
- { denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS }:
77
- { denomination?: AE_AMOUNT_FORMATS, targetDenomination?: AE_AMOUNT_FORMATS }
78
- ): string => {
79
- if (!isBigNumber(value)) throw new ArgumentError('value', 'a number', value)
80
-
81
- return new BigNumber(typeof value === 'bigint' ? value.toString() : value)
82
- .shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])
83
- .toFixed()
84
- }
81
+ export const toAettos = (
82
+ value: string | number | BigNumber,
83
+ { denomination = AE_AMOUNT_FORMATS.AE }: { denomination?: AE_AMOUNT_FORMATS } = {},
84
+ ): string => formatAmount(value, { denomination });
85
85
 
86
86
  interface Prefix {
87
- name: string
88
- magnitude: number
87
+ name: string;
88
+ magnitude: number;
89
89
  }
90
90
 
91
91
  const prefixes: Prefix[] = [
92
92
  { name: 'exa', magnitude: 18 },
93
93
  { name: 'giga', magnitude: 9 },
94
94
  { name: '', magnitude: 0 },
95
- { name: 'pico', magnitude: -12 }
96
- ]
95
+ { name: 'pico', magnitude: -12 },
96
+ ];
97
97
 
98
98
  const getNearestPrefix = (exponent: number): Prefix => prefixes.reduce((p, n) => (
99
- Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p))
99
+ Math.abs(n.magnitude - exponent) < Math.abs(p.magnitude - exponent) ? n : p));
100
100
 
101
101
  const getLowerBoundPrefix = (exponent: number): Prefix => prefixes
102
- .find(p => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1]
102
+ .find((p) => p.magnitude <= exponent) ?? prefixes[prefixes.length - 1];
103
103
 
104
104
  export default (rawValue: string | number | BigNumber): string => {
105
- const value: BigNumber = new BigNumber(rawValue)
105
+ const value: BigNumber = new BigNumber(rawValue);
106
106
 
107
- const exp = value.e ?? 0
108
- const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp)
107
+ const exp = value.e ?? 0;
108
+ const { name, magnitude } = (exp < 0 ? getNearestPrefix : getLowerBoundPrefix)(exp);
109
109
  const v = value
110
110
  .shiftedBy(-magnitude)
111
111
  .precision(9 + Math.min(exp - magnitude, 0))
112
- .toFixed()
113
- return `${v}${name !== '' ? ' ' : ''}${name}`
114
- }
112
+ .toFixed();
113
+ return `${v}${name !== '' ? ' ' : ''}${name}`;
114
+ };