@caict/bop-typescript-sdk 1.0.2 → 1.0.3

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 (256) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/base.tsconfig.json +14 -0
  3. package/dist/bop/bop-base/base.d.ts +24 -0
  4. package/dist/bop/bop-base/base.js +253 -0
  5. package/dist/bop/bop-base/base.js.map +1 -0
  6. package/dist/bop/bop-base/index.d.ts +18 -0
  7. package/dist/bop/bop-base/index.js +69 -0
  8. package/dist/bop/bop-base/index.js.map +1 -0
  9. package/dist/bop/bop-base/permit.d.ts +11 -0
  10. package/dist/bop/bop-base/permit.js +104 -0
  11. package/dist/bop/bop-base/permit.js.map +1 -0
  12. package/dist/bop/bop-base/test/base.test.d.ts +1 -0
  13. package/dist/bop/bop-base/test/base.test.js +772 -0
  14. package/dist/bop/bop-base/test/base.test.js.map +1 -0
  15. package/dist/bop/bop-base/test/index.test.d.ts +1 -0
  16. package/dist/bop/bop-base/test/index.test.js +89 -0
  17. package/dist/bop/bop-base/test/index.test.js.map +1 -0
  18. package/dist/bop/bop-base/test/permit.test.d.ts +1 -0
  19. package/dist/bop/bop-base/test/permit.test.js +140 -0
  20. package/dist/bop/bop-base/test/permit.test.js.map +1 -0
  21. package/dist/bop/bop-proto/bop-ws.d.ts +325 -0
  22. package/dist/bop/bop-proto/bop-ws.js +3599 -0
  23. package/dist/bop/bop-proto/bop-ws.js.map +1 -0
  24. package/dist/bop/bop-proto/bop.d.ts +903 -0
  25. package/dist/bop/bop-proto/bop.js +10421 -0
  26. package/dist/bop/bop-proto/bop.js.map +1 -0
  27. package/dist/bop/bop-ws/index.d.ts +43 -0
  28. package/dist/bop/bop-ws/index.js +265 -0
  29. package/dist/bop/bop-ws/index.js.map +1 -0
  30. package/dist/bop/bop-ws/sample/sample.d.ts +1 -0
  31. package/dist/bop/bop-ws/sample/sample.js +96 -0
  32. package/dist/bop/bop-ws/sample/sample.js.map +1 -0
  33. package/dist/bop/index.d.ts +5 -0
  34. package/dist/bop/index.js +37 -0
  35. package/dist/bop/index.js.map +1 -0
  36. package/dist/bop-sdk/index.d.ts +13 -0
  37. package/dist/bop-sdk/index.js +45 -0
  38. package/dist/bop-sdk/index.js.map +1 -0
  39. package/dist/bop-sdk/interface/abstract-service/abstract-account.d.ts +8 -0
  40. package/dist/bop-sdk/interface/abstract-service/abstract-account.js +7 -0
  41. package/dist/bop-sdk/interface/abstract-service/abstract-account.js.map +1 -0
  42. package/dist/bop-sdk/interface/abstract-service/abstract-chain.d.ts +5 -0
  43. package/dist/bop-sdk/interface/abstract-service/abstract-chain.js +7 -0
  44. package/dist/bop-sdk/interface/abstract-service/abstract-chain.js.map +1 -0
  45. package/dist/bop-sdk/interface/abstract-service/abstract-contract.d.ts +6 -0
  46. package/dist/bop-sdk/interface/abstract-service/abstract-contract.js +7 -0
  47. package/dist/bop-sdk/interface/abstract-service/abstract-contract.js.map +1 -0
  48. package/dist/bop-sdk/interface/abstract-service/abstract-ledger.d.ts +8 -0
  49. package/dist/bop-sdk/interface/abstract-service/abstract-ledger.js +7 -0
  50. package/dist/bop-sdk/interface/abstract-service/abstract-ledger.js.map +1 -0
  51. package/dist/bop-sdk/interface/abstract-service/abstract-provider.d.ts +12 -0
  52. package/dist/bop-sdk/interface/abstract-service/abstract-provider.js +7 -0
  53. package/dist/bop-sdk/interface/abstract-service/abstract-provider.js.map +1 -0
  54. package/dist/bop-sdk/interface/abstract-service/abstract-signer.d.ts +17 -0
  55. package/dist/bop-sdk/interface/abstract-service/abstract-signer.js +109 -0
  56. package/dist/bop-sdk/interface/abstract-service/abstract-signer.js.map +1 -0
  57. package/dist/bop-sdk/interface/abstract-service/abstract-transaction.d.ts +17 -0
  58. package/dist/bop-sdk/interface/abstract-service/abstract-transaction.js +7 -0
  59. package/dist/bop-sdk/interface/abstract-service/abstract-transaction.js.map +1 -0
  60. package/dist/bop-sdk/interface/provider-ws.d.ts +5 -0
  61. package/dist/bop-sdk/interface/provider-ws.js +12 -0
  62. package/dist/bop-sdk/interface/provider-ws.js.map +1 -0
  63. package/dist/bop-sdk/interface/provider.d.ts +7 -0
  64. package/dist/bop-sdk/interface/provider.js +23 -0
  65. package/dist/bop-sdk/interface/provider.js.map +1 -0
  66. package/dist/bop-sdk/interface/service/3rd.d.ts +12 -0
  67. package/dist/bop-sdk/interface/service/3rd.js +49 -0
  68. package/dist/bop-sdk/interface/service/3rd.js.map +1 -0
  69. package/dist/bop-sdk/interface/service/account.d.ts +12 -0
  70. package/dist/bop-sdk/interface/service/account.js +98 -0
  71. package/dist/bop-sdk/interface/service/account.js.map +1 -0
  72. package/dist/bop-sdk/interface/service/chain.d.ts +9 -0
  73. package/dist/bop-sdk/interface/service/chain.js +55 -0
  74. package/dist/bop-sdk/interface/service/chain.js.map +1 -0
  75. package/dist/bop-sdk/interface/service/contract.d.ts +10 -0
  76. package/dist/bop-sdk/interface/service/contract.js +67 -0
  77. package/dist/bop-sdk/interface/service/contract.js.map +1 -0
  78. package/dist/bop-sdk/interface/service/helper.d.ts +20 -0
  79. package/dist/bop-sdk/interface/service/helper.js +383 -0
  80. package/dist/bop-sdk/interface/service/helper.js.map +1 -0
  81. package/dist/bop-sdk/interface/service/ledger.d.ts +12 -0
  82. package/dist/bop-sdk/interface/service/ledger.js +89 -0
  83. package/dist/bop-sdk/interface/service/ledger.js.map +1 -0
  84. package/dist/bop-sdk/interface/service/offline/check/index.js +138 -0
  85. package/dist/bop-sdk/interface/service/offline/common/constant.js +6 -0
  86. package/dist/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
  87. package/dist/bop-sdk/interface/service/offline/common/util.js +511 -0
  88. package/dist/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
  89. package/dist/bop-sdk/interface/service/offline/exception/errors.js +90 -0
  90. package/dist/bop-sdk/interface/service/offline/exception/index.js +5 -0
  91. package/dist/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
  92. package/dist/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
  93. package/dist/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
  94. package/dist/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
  95. package/dist/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
  96. package/dist/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
  97. package/dist/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
  98. package/dist/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
  99. package/dist/bop-sdk/interface/service/offline/operation/index.js +20 -0
  100. package/dist/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
  101. package/dist/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
  102. package/dist/bop-sdk/interface/service/offline/transaction/index.js +988 -0
  103. package/dist/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
  104. package/dist/bop-sdk/interface/service/offline/validate/account.js +152 -0
  105. package/dist/bop-sdk/interface/service/offline/validate/contract.js +101 -0
  106. package/dist/bop-sdk/interface/service/offline/validate/index.js +10 -0
  107. package/dist/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
  108. package/dist/bop-sdk/interface/service/transaction.d.ts +21 -0
  109. package/dist/bop-sdk/interface/service/transaction.js +591 -0
  110. package/dist/bop-sdk/interface/service/transaction.js.map +1 -0
  111. package/dist/bop-sdk/interface/signer.d.ts +12 -0
  112. package/dist/bop-sdk/interface/signer.js +53 -0
  113. package/dist/bop-sdk/interface/signer.js.map +1 -0
  114. package/dist/bop-sdk/interface/test/3rd.test.d.ts +1 -0
  115. package/dist/bop-sdk/interface/test/3rd.test.js +1524 -0
  116. package/dist/bop-sdk/interface/test/3rd.test.js.map +1 -0
  117. package/dist/bop-sdk/interface/test/account.test.d.ts +1 -0
  118. package/dist/bop-sdk/interface/test/account.test.js +225 -0
  119. package/dist/bop-sdk/interface/test/account.test.js.map +1 -0
  120. package/dist/bop-sdk/interface/test/chain.test.d.ts +1 -0
  121. package/dist/bop-sdk/interface/test/chain.test.js +72 -0
  122. package/dist/bop-sdk/interface/test/chain.test.js.map +1 -0
  123. package/dist/bop-sdk/interface/test/contract.test.d.ts +1 -0
  124. package/dist/bop-sdk/interface/test/contract.test.js +266 -0
  125. package/dist/bop-sdk/interface/test/contract.test.js.map +1 -0
  126. package/dist/bop-sdk/interface/test/ledger.test.d.ts +1 -0
  127. package/dist/bop-sdk/interface/test/ledger.test.js +167 -0
  128. package/dist/bop-sdk/interface/test/ledger.test.js.map +1 -0
  129. package/dist/bop-sdk/interface/test/provider.test.d.ts +1 -0
  130. package/dist/bop-sdk/interface/test/provider.test.js +295 -0
  131. package/dist/bop-sdk/interface/test/provider.test.js.map +1 -0
  132. package/dist/bop-sdk/interface/test/signer.test.d.ts +1 -0
  133. package/dist/bop-sdk/interface/test/signer.test.js +87 -0
  134. package/dist/bop-sdk/interface/test/signer.test.js.map +1 -0
  135. package/dist/bop-sdk/interface/test/transaction.test.d.ts +1 -0
  136. package/dist/bop-sdk/interface/test/transaction.test.js +663 -0
  137. package/dist/bop-sdk/interface/test/transaction.test.js.map +1 -0
  138. package/dist/bop-sdk/proto/bop-sdk-common.d.ts +225 -0
  139. package/dist/bop-sdk/proto/bop-sdk-common.js +831 -0
  140. package/dist/bop-sdk/proto/bop-sdk-common.js.map +1 -0
  141. package/dist/bop-sdk/proto/bop-sdk-interface.d.ts +623 -0
  142. package/dist/bop-sdk/proto/bop-sdk-interface.js +8623 -0
  143. package/dist/bop-sdk/proto/bop-sdk-interface.js.map +1 -0
  144. package/dist/bop-sdk/proto/bop-sdk-utils.d.ts +107 -0
  145. package/dist/bop-sdk/proto/bop-sdk-utils.js +1160 -0
  146. package/dist/bop-sdk/proto/bop-sdk-utils.js.map +1 -0
  147. package/dist/bop-sdk/utils/abi/abi-coder.d.ts +16 -0
  148. package/dist/bop-sdk/utils/abi/abi-coder.js +101 -0
  149. package/dist/bop-sdk/utils/abi/abi-coder.js.map +1 -0
  150. package/dist/bop-sdk/utils/abi/address.d.ts +8 -0
  151. package/dist/bop-sdk/utils/abi/address.js +116 -0
  152. package/dist/bop-sdk/utils/abi/address.js.map +1 -0
  153. package/dist/bop-sdk/utils/abi/bignumber.d.ts +39 -0
  154. package/dist/bop-sdk/utils/abi/bignumber.js +316 -0
  155. package/dist/bop-sdk/utils/abi/bignumber.js.map +1 -0
  156. package/dist/bop-sdk/utils/abi/bytes.d.ts +41 -0
  157. package/dist/bop-sdk/utils/abi/bytes.js +423 -0
  158. package/dist/bop-sdk/utils/abi/bytes.js.map +1 -0
  159. package/dist/bop-sdk/utils/abi/coders/abstract-coder.d.ts +52 -0
  160. package/dist/bop-sdk/utils/abi/coders/abstract-coder.js +164 -0
  161. package/dist/bop-sdk/utils/abi/coders/abstract-coder.js.map +1 -0
  162. package/dist/bop-sdk/utils/abi/coders/address.d.ts +7 -0
  163. package/dist/bop-sdk/utils/abi/coders/address.js +52 -0
  164. package/dist/bop-sdk/utils/abi/coders/address.js.map +1 -0
  165. package/dist/bop-sdk/utils/abi/coders/anonymous.d.ts +8 -0
  166. package/dist/bop-sdk/utils/abi/coders/anonymous.js +22 -0
  167. package/dist/bop-sdk/utils/abi/coders/anonymous.js.map +1 -0
  168. package/dist/bop-sdk/utils/abi/coders/array.d.ts +13 -0
  169. package/dist/bop-sdk/utils/abi/coders/array.js +220 -0
  170. package/dist/bop-sdk/utils/abi/coders/array.js.map +1 -0
  171. package/dist/bop-sdk/utils/abi/coders/boolean.d.ts +7 -0
  172. package/dist/bop-sdk/utils/abi/coders/boolean.js +20 -0
  173. package/dist/bop-sdk/utils/abi/coders/boolean.js.map +1 -0
  174. package/dist/bop-sdk/utils/abi/coders/bytes.d.ts +11 -0
  175. package/dist/bop-sdk/utils/abi/coders/bytes.js +33 -0
  176. package/dist/bop-sdk/utils/abi/coders/bytes.js.map +1 -0
  177. package/dist/bop-sdk/utils/abi/coders/fixed-bytes.d.ts +9 -0
  178. package/dist/bop-sdk/utils/abi/coders/fixed-bytes.js +28 -0
  179. package/dist/bop-sdk/utils/abi/coders/fixed-bytes.js.map +1 -0
  180. package/dist/bop-sdk/utils/abi/coders/null.d.ts +7 -0
  181. package/dist/bop-sdk/utils/abi/coders/null.js +24 -0
  182. package/dist/bop-sdk/utils/abi/coders/null.js.map +1 -0
  183. package/dist/bop-sdk/utils/abi/coders/number.d.ts +10 -0
  184. package/dist/bop-sdk/utils/abi/coders/number.js +45 -0
  185. package/dist/bop-sdk/utils/abi/coders/number.js.map +1 -0
  186. package/dist/bop-sdk/utils/abi/coders/string.d.ts +8 -0
  187. package/dist/bop-sdk/utils/abi/coders/string.js +21 -0
  188. package/dist/bop-sdk/utils/abi/coders/string.js.map +1 -0
  189. package/dist/bop-sdk/utils/abi/coders/tuple.d.ts +10 -0
  190. package/dist/bop-sdk/utils/abi/coders/tuple.js +60 -0
  191. package/dist/bop-sdk/utils/abi/coders/tuple.js.map +1 -0
  192. package/dist/bop-sdk/utils/abi/constants/addresses.d.ts +1 -0
  193. package/dist/bop-sdk/utils/abi/constants/addresses.js +5 -0
  194. package/dist/bop-sdk/utils/abi/constants/addresses.js.map +1 -0
  195. package/dist/bop-sdk/utils/abi/constants/bignumbers.d.ts +10 -0
  196. package/dist/bop-sdk/utils/abi/constants/bignumbers.js +21 -0
  197. package/dist/bop-sdk/utils/abi/constants/bignumbers.js.map +1 -0
  198. package/dist/bop-sdk/utils/abi/constants/hashes.d.ts +1 -0
  199. package/dist/bop-sdk/utils/abi/constants/hashes.js +5 -0
  200. package/dist/bop-sdk/utils/abi/constants/hashes.js.map +1 -0
  201. package/dist/bop-sdk/utils/abi/constants/index.d.ts +4 -0
  202. package/dist/bop-sdk/utils/abi/constants/index.js +19 -0
  203. package/dist/bop-sdk/utils/abi/constants/index.js.map +1 -0
  204. package/dist/bop-sdk/utils/abi/constants/strings.d.ts +1 -0
  205. package/dist/bop-sdk/utils/abi/constants/strings.js +6 -0
  206. package/dist/bop-sdk/utils/abi/constants/strings.js.map +1 -0
  207. package/dist/bop-sdk/utils/abi/fragments.d.ts +84 -0
  208. package/dist/bop-sdk/utils/abi/fragments.js +919 -0
  209. package/dist/bop-sdk/utils/abi/fragments.js.map +1 -0
  210. package/dist/bop-sdk/utils/abi/id.d.ts +1 -0
  211. package/dist/bop-sdk/utils/abi/id.js +10 -0
  212. package/dist/bop-sdk/utils/abi/id.js.map +1 -0
  213. package/dist/bop-sdk/utils/abi/index.d.ts +4 -0
  214. package/dist/bop-sdk/utils/abi/index.js +21 -0
  215. package/dist/bop-sdk/utils/abi/index.js.map +1 -0
  216. package/dist/bop-sdk/utils/abi/interface.d.ts +83 -0
  217. package/dist/bop-sdk/utils/abi/interface.js +663 -0
  218. package/dist/bop-sdk/utils/abi/interface.js.map +1 -0
  219. package/dist/bop-sdk/utils/abi/keccak256.d.ts +2 -0
  220. package/dist/bop-sdk/utils/abi/keccak256.js +13 -0
  221. package/dist/bop-sdk/utils/abi/keccak256.js.map +1 -0
  222. package/dist/bop-sdk/utils/abi/properties.d.ts +16 -0
  223. package/dist/bop-sdk/utils/abi/properties.js +141 -0
  224. package/dist/bop-sdk/utils/abi/properties.js.map +1 -0
  225. package/dist/bop-sdk/utils/abi/strings/bytes32.d.ts +3 -0
  226. package/dist/bop-sdk/utils/abi/strings/bytes32.js +36 -0
  227. package/dist/bop-sdk/utils/abi/strings/bytes32.js.map +1 -0
  228. package/dist/bop-sdk/utils/abi/strings/idna.d.ts +4 -0
  229. package/dist/bop-sdk/utils/abi/strings/idna.js +200 -0
  230. package/dist/bop-sdk/utils/abi/strings/idna.js.map +1 -0
  231. package/dist/bop-sdk/utils/abi/strings/index.d.ts +4 -0
  232. package/dist/bop-sdk/utils/abi/strings/index.js +17 -0
  233. package/dist/bop-sdk/utils/abi/strings/index.js.map +1 -0
  234. package/dist/bop-sdk/utils/abi/strings/utf8.d.ts +26 -0
  235. package/dist/bop-sdk/utils/abi/strings/utf8.js +265 -0
  236. package/dist/bop-sdk/utils/abi/strings/utf8.js.map +1 -0
  237. package/dist/bop-sdk/utils/encryption-address.d.ts +25 -0
  238. package/dist/bop-sdk/utils/encryption-address.js +426 -0
  239. package/dist/bop-sdk/utils/encryption-address.js.map +1 -0
  240. package/dist/bop-sdk/utils/encryption-crypto.d.ts +16 -0
  241. package/dist/bop-sdk/utils/encryption-crypto.js +406 -0
  242. package/dist/bop-sdk/utils/encryption-crypto.js.map +1 -0
  243. package/dist/bop-sdk/utils/encryption-mnemonics.d.ts +7 -0
  244. package/dist/bop-sdk/utils/encryption-mnemonics.js +129 -0
  245. package/dist/bop-sdk/utils/encryption-mnemonics.js.map +1 -0
  246. package/dist/bop-sdk/utils/index.d.ts +13 -0
  247. package/dist/bop-sdk/utils/index.js +22 -0
  248. package/dist/bop-sdk/utils/index.js.map +1 -0
  249. package/dist/bop-sdk/utils/logger.d.ts +52 -0
  250. package/dist/bop-sdk/utils/logger.js +377 -0
  251. package/dist/bop-sdk/utils/logger.js.map +1 -0
  252. package/dist/index.d.ts +4 -0
  253. package/dist/index.js +18 -0
  254. package/dist/index.js.map +1 -0
  255. package/package.json +92 -88
  256. package/tsconfig.json +24 -0
@@ -0,0 +1,188 @@
1
+ const long = require("long");
2
+ const chain_pb = require("../proto/chain_pb");
3
+ const is = require("is-type-of");
4
+ const keypair = require("@caict/bif-encryption");
5
+ const errors = require("../exception");
6
+
7
+ function payCoin(args = {}) {
8
+ const { from, to, amount, input, metadata } = args;
9
+
10
+ const payCoin = new chain_pb.OperationPayCoin();
11
+ payCoin.setDestAddress(to);
12
+ if (amount !== 0 && amount !== "0") {
13
+ payCoin.setAmount(long.fromValue(amount));
14
+ }
15
+ if (input) {
16
+ payCoin.setInput(input);
17
+ }
18
+ let operation = new chain_pb.Operation();
19
+ operation.setType(chain_pb.Operation.Type.PAY_COIN);
20
+ operation.setPayCoin(payCoin);
21
+ if (metadata) {
22
+ operation.setMetadata(Uint8Array.from(Buffer.from(metadata, "utf8")));
23
+ }
24
+ if (from) {
25
+ operation.setSourceAddress(from);
26
+ }
27
+ return operation;
28
+ }
29
+
30
+ function activateAccount(args = {}) {
31
+ const { to, initBalance } = args;
32
+
33
+ const defaultTxThreshold = 1;
34
+ const defaultMasterWeight = 1;
35
+
36
+ let threshold = new chain_pb.AccountThreshold();
37
+ threshold.setTxThreshold(defaultTxThreshold);
38
+
39
+ let privilege = new chain_pb.AccountPrivilege();
40
+ privilege.setThresholds(threshold);
41
+ privilege.setMasterWeight(defaultMasterWeight);
42
+
43
+ let createAccount = new chain_pb.OperationCreateAccount();
44
+ createAccount.setDestAddress(to);
45
+ if (initBalance !== 0 && initBalance !== "0") {
46
+ createAccount.setInitBalance(long.fromValue(initBalance));
47
+ }
48
+ createAccount.setPriv(privilege);
49
+
50
+ let operation = new chain_pb.Operation();
51
+ operation.setType(chain_pb.Operation.Type.CREATE_ACCOUNT);
52
+ operation.setCreateAccount(createAccount);
53
+ return operation;
54
+ }
55
+
56
+ function setMetadata(args = {}) {
57
+ const { key, value, version, deleteFlag } = args;
58
+
59
+ const setMetadata = new chain_pb.OperationSetMetadata();
60
+ setMetadata.setKey(key);
61
+ setMetadata.setValue(value);
62
+ setMetadata.setVersion(version);
63
+ setMetadata.setDeleteFlag(deleteFlag);
64
+ let operation = new chain_pb.Operation();
65
+ operation.setType(chain_pb.Operation.Type.SET_METADATA);
66
+ operation.setSetMetadata(setMetadata);
67
+ return operation;
68
+ }
69
+
70
+ function createContract(args = {}) {
71
+ const { initBalance, payload, sourceAddress, initInput, type } = args;
72
+
73
+ const defaultTxThreshold = 1;
74
+ const defaultMasterWeight = 0;
75
+
76
+ const threshold = new chain_pb.AccountThreshold();
77
+ threshold.setTxThreshold(defaultTxThreshold);
78
+
79
+ const privilege = new chain_pb.AccountPrivilege();
80
+ privilege.setThresholds(threshold);
81
+ if (defaultMasterWeight !== 0 && defaultMasterWeight !== "0") {
82
+ privilege.setMasterWeight(defaultMasterWeight);
83
+ }
84
+
85
+ const contractMsg = new chain_pb.Contract();
86
+ contractMsg.setPayload(payload);
87
+ contractMsg.setType(type);
88
+ const createAccount = new chain_pb.OperationCreateAccount();
89
+ if (initBalance !== 0 && initBalance !== "0") {
90
+ createAccount.setInitBalance(long.fromValue(initBalance));
91
+ }
92
+ createAccount.setPriv(privilege);
93
+ createAccount.setContract(contractMsg);
94
+ if (initInput) {
95
+ createAccount.setInitInput(initInput);
96
+ }
97
+
98
+ const operation = new chain_pb.Operation();
99
+ operation.setType(chain_pb.Operation.Type.CREATE_ACCOUNT);
100
+ operation.setCreateAccount(createAccount);
101
+ if (sourceAddress) {
102
+ operation.setSourceAddress(sourceAddress);
103
+ }
104
+ return operation;
105
+ }
106
+
107
+ function isAvailableValue(str, from = -1, to = long.MAX_VALUE) {
108
+ const reg = /^(0|([1-9]\d*))$/;
109
+ return (
110
+ is.string(str) &&
111
+ reg.test(str) &&
112
+ long.fromValue(str).greaterThan(from) &&
113
+ long.fromValue(str).lessThanOrEqual(to)
114
+ );
115
+ }
116
+
117
+ function accountSetPrivilegeOperation(args = {}) {
118
+ const { signers } = args;
119
+ const { typeThresholds } = args;
120
+ const signerList = [];
121
+ const typeThresholdsList = [];
122
+ const signer = new chain_pb.Signer();
123
+ if (is.array(signers) && signers.length > 0) {
124
+ let msg = "";
125
+ signers.some((item) => {
126
+ if (!keypair.isAddress(item.address)) {
127
+ msg = "INVALID_SIGNER_ADDRESS_ERROR";
128
+ return true;
129
+ }
130
+ let maxInt32 = Math.pow(2, 32) - 1;
131
+ if (!isAvailableValue(item.weight, -1, maxInt32)) {
132
+ msg = "INVALID_SIGNER_WEIGHT_ERROR";
133
+ return true;
134
+ }
135
+ signer.setAddress(item.address);
136
+ signer.setWeight(item.weight);
137
+ signerList.push(signer);
138
+ });
139
+
140
+ if (msg !== "") {
141
+ return this._responseError(errors[msg]);
142
+ }
143
+ }
144
+ const typeThreshold = new chain_pb.OperationTypeThreshold();
145
+ if (is.array(typeThresholds) && typeThresholds.length > 0) {
146
+ let msg = "";
147
+ typeThresholds.some((item) => {
148
+ if (!isAvailableValue(item.type, -1, 100)) {
149
+ msg = "INVALID_OPERATION_TYPE_ERROR";
150
+ return true;
151
+ }
152
+
153
+ if (!isAvailableValue(item.threshold)) {
154
+ msg = "INVALID_TYPE_THRESHOLD_ERROR";
155
+ return true;
156
+ }
157
+ typeThreshold.setType(item.type);
158
+ typeThreshold.setThreshold(item.threshold);
159
+ typeThresholdsList.push(typeThreshold);
160
+ });
161
+
162
+ if (msg !== "") {
163
+ return this._responseError(errors[msg]);
164
+ }
165
+ }
166
+
167
+ const setPrivilege = new chain_pb.OperationSetPrivilege();
168
+ setPrivilege.setSignersList(signerList);
169
+ setPrivilege.setTxThreshold(args.txThreshold);
170
+ setPrivilege.setTypeThresholdsList(typeThresholdsList);
171
+ let maxInt32 = Math.pow(2, 32) - 1;
172
+ if (isAvailableValue(args.masterWeight, 1, maxInt32)) {
173
+ setPrivilege.setMasterWeight(args.masterWeight);
174
+ }
175
+
176
+ let operation = new chain_pb.Operation();
177
+ operation.setType(chain_pb.Operation.Type.SET_PRIVILEGE);
178
+ operation.setSetPrivilege(setPrivilege);
179
+ return operation;
180
+ }
181
+
182
+ module.exports = {
183
+ payCoin,
184
+ accountSetPrivilegeOperation,
185
+ activateAccount,
186
+ setMetadata,
187
+ createContract,
188
+ };
@@ -0,0 +1,152 @@
1
+ const is = require("is-type-of");
2
+ const keypair = require("@caict/bif-encryption");
3
+ const errors = require("../exception");
4
+ const proto = exports;
5
+
6
+ proto.accountActivateOperation = function (args) {
7
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
8
+ return this._responseError(errors.REQUEST_NULL_ERROR);
9
+ }
10
+
11
+ const schema = {
12
+ sourceAddress: {
13
+ required: true,
14
+ address: true,
15
+ },
16
+ destAddress: {
17
+ required: true,
18
+ address: true,
19
+ },
20
+ initBalance: {
21
+ required: true,
22
+ numeric: true,
23
+ },
24
+ };
25
+
26
+ if (!this._validate(args, schema).tag) {
27
+ const { msg } = this._validate(args, schema);
28
+ return this._responseError(errors[msg]);
29
+ }
30
+
31
+ return this._responseData(true);
32
+ };
33
+
34
+ proto.accountSetMetadataOperation = function (args) {
35
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
36
+ return this._responseError(errors.REQUEST_NULL_ERROR);
37
+ }
38
+
39
+ const schema = {
40
+ key: {
41
+ required: true,
42
+ string: true,
43
+ },
44
+ value: {
45
+ required: true,
46
+ string: true,
47
+ },
48
+ sourceAddress: {
49
+ required: true,
50
+ address: true,
51
+ },
52
+ deleteFlag: {
53
+ required: false,
54
+ boolean: true,
55
+ },
56
+ };
57
+
58
+ if (!this._validate(args, schema).tag) {
59
+ const { msg } = this._validate(args, schema);
60
+ return this._responseError(errors[msg]);
61
+ }
62
+
63
+ let { value } = args;
64
+
65
+ if (!is.string(value) || value.trim().length === 0 || value.length > 256000) {
66
+ return this._responseError(errors.INVALID_DATAVALUE_ERROR);
67
+ }
68
+
69
+ if (args.version && !this._isAvailableVersion(args.version)) {
70
+ return this._responseError(errors.INVALID_DATAVERSION_ERROR);
71
+ }
72
+
73
+ return this._responseData(true);
74
+ };
75
+
76
+ proto.accountSetPrivilegeOperation = function (args = {}) {
77
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
78
+ return this._responseError(errors.REQUEST_NULL_ERROR);
79
+ }
80
+
81
+ const schema = {
82
+ sourceAddress: {
83
+ required: false,
84
+ address: true,
85
+ },
86
+ };
87
+
88
+ if (!this._validate(args, schema).tag) {
89
+ const { msg } = this._validate(args, schema);
90
+ return this._responseError(errors[msg]);
91
+ }
92
+
93
+ let maxInt32 = Math.pow(2, 32) - 1;
94
+
95
+ if (
96
+ !is.undefined(args.masterWeight) &&
97
+ !this._isAvailableValue(args.masterWeight, -1, maxInt32)
98
+ ) {
99
+ return this._responseError(errors.INVALID_MASTERWEIGHT_ERROR);
100
+ }
101
+
102
+ console.log(args.txThreshold);
103
+ if (
104
+ !is.undefined(args.txThreshold) &&
105
+ !this._isAvailableValue(args.txThreshold, -1, maxInt32)
106
+ ) {
107
+ return this._responseError(errors.INVALID_TX_THRESHOLD_ERROR);
108
+ }
109
+
110
+ const { signers } = args;
111
+ const { typeThresholds } = args;
112
+
113
+ if (is.array(signers) && signers.length > 0) {
114
+ let msg = "";
115
+ signers.some((item) => {
116
+ if (!keypair.isAddress(item.address)) {
117
+ msg = "INVALID_SIGNER_ADDRESS_ERROR";
118
+ return true;
119
+ }
120
+
121
+ if (!this._isAvailableValue(item.weight, -1, maxInt32)) {
122
+ msg = "INVALID_SIGNER_WEIGHT_ERROR";
123
+ return true;
124
+ }
125
+ });
126
+
127
+ if (msg !== "") {
128
+ return this._responseError(errors[msg]);
129
+ }
130
+ }
131
+
132
+ if (is.array(typeThresholds) && typeThresholds.length > 0) {
133
+ let msg = "";
134
+ typeThresholds.some((item) => {
135
+ if (!this._isAvailableValue(item.type, -1, 100)) {
136
+ msg = "INVALID_OPERATION_TYPE_ERROR";
137
+ return true;
138
+ }
139
+
140
+ if (!this._isAvailableValue(item.threshold)) {
141
+ msg = "INVALID_TYPE_THRESHOLD_ERROR";
142
+ return true;
143
+ }
144
+ });
145
+
146
+ if (msg !== "") {
147
+ return this._responseError(errors[msg]);
148
+ }
149
+ }
150
+
151
+ return this._responseData(true);
152
+ };
@@ -0,0 +1,101 @@
1
+ const is = require("is-type-of");
2
+ const errors = require("../exception");
3
+ const proto = exports;
4
+ const chain_pb = require("../proto/chain_pb");
5
+
6
+ proto.contractCreateOperation = function (args) {
7
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
8
+ return this._responseError(errors.REQUEST_NULL_ERROR);
9
+ }
10
+
11
+ const schema = {
12
+ sourceAddress: {
13
+ required: true,
14
+ string: true,
15
+ address: true,
16
+ },
17
+ };
18
+
19
+ if (!this._validate(args, schema).tag) {
20
+ const { msg } = this._validate(args, schema);
21
+ return this._responseError(errors[msg]);
22
+ }
23
+
24
+ const evm = chain_pb.Contract.ContractType.EVM;
25
+ const javascript = chain_pb.Contract.ContractType.JAVASCRIPT;
26
+ const system = chain_pb.Contract.ContractType.SYSTEM;
27
+ if (
28
+ args.type != evm &&
29
+ args.type != javascript &&
30
+ args.type != system &&
31
+ args.type != null &&
32
+ args.type != ""
33
+ ) {
34
+ return this._responseError(errors.INVALID_CONTRACT_TYPE_ERROR);
35
+ }
36
+
37
+ if (!is.string(args.payload) || args.payload.trim().length === 0) {
38
+ return this._responseError(errors.PAYLOAD_EMPTY_ERROR);
39
+ }
40
+
41
+ return this._responseData(true);
42
+ };
43
+
44
+ proto.contractInvokeOperation = function (args) {
45
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
46
+ return this._responseError(errors.REQUEST_NULL_ERROR);
47
+ }
48
+
49
+ const schema = {
50
+ contractAddress: {
51
+ required: true,
52
+ address: true,
53
+ },
54
+ sourceAddress: {
55
+ required: false,
56
+ address: true,
57
+ },
58
+ amount: {
59
+ required: true,
60
+ numeric: true,
61
+ },
62
+ };
63
+
64
+ if (!this._validate(args, schema).tag) {
65
+ const { msg } = this._validate(args, schema);
66
+ return this._responseError(errors[msg]);
67
+ }
68
+
69
+ if (!is.undefined(args.amount)) {
70
+ if (!this._isAvailableValue(args.amount)) {
71
+ return this._responseError(errors.INVALID_AMOUNT_ERROR);
72
+ }
73
+ }
74
+
75
+ return this._responseData(true);
76
+ };
77
+ proto.contractInvokeRequestOperation = function (args) {
78
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
79
+ return this._responseError(errors.REQUEST_NULL_ERROR);
80
+ }
81
+
82
+ const schema = {
83
+ senderAddress: {
84
+ required: true,
85
+ address: true,
86
+ },
87
+ };
88
+
89
+ if (!this._validate(args, schema).tag) {
90
+ const { msg } = this._validate(args, schema);
91
+ return this._responseError(errors[msg]);
92
+ }
93
+
94
+ if (!is.undefined(args.amount)) {
95
+ if (!this._isAvailableValue(args.amount)) {
96
+ return this._responseError(errors.INVALID_AMOUNT_ERROR);
97
+ }
98
+ }
99
+
100
+ return this._responseData(true);
101
+ };
@@ -0,0 +1,10 @@
1
+ const wrap = require("co-wrap-all");
2
+ const merge = require("merge-descriptors");
3
+ module.exports = Operation;
4
+ function Operation() {}
5
+ const proto = Operation.prototype;
6
+ merge(proto, require("../common/util"));
7
+ merge(proto, require("./transaction"));
8
+ merge(proto, require("./account"));
9
+ merge(proto, require("./contract"));
10
+ wrap(proto);
@@ -0,0 +1,51 @@
1
+ const is = require("is-type-of");
2
+ const errors = require("../exception");
3
+ const proto = exports;
4
+
5
+ proto.SendOperation = function (args) {
6
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
7
+ return this._responseError(errors.REQUEST_NULL_ERROR);
8
+ }
9
+
10
+ const schema = {
11
+ sourceAddress: {
12
+ required: true,
13
+ address: true,
14
+ },
15
+ destAddress: {
16
+ required: true,
17
+ address: true,
18
+ },
19
+ amount: {
20
+ required: true,
21
+ numeric: true,
22
+ },
23
+ };
24
+
25
+ if (!this._validate(args, schema).tag) {
26
+ const { msg } = this._validate(args, schema);
27
+ return this._responseError(errors[msg]);
28
+ }
29
+
30
+ return this._responseData(true);
31
+ };
32
+
33
+ proto.GasSendRequestOperation = function (args) {
34
+ if (is.array(args) || !is.object(args) || JSON.stringify(args) === "{}") {
35
+ return this._responseError(errors.REQUEST_NULL_ERROR);
36
+ }
37
+
38
+ const schema = {
39
+ senderAddress: {
40
+ required: true,
41
+ address: true,
42
+ },
43
+ };
44
+
45
+ if (!this._validate(args, schema).tag) {
46
+ const { msg } = this._validate(args, schema);
47
+ return this._responseError(errors[msg]);
48
+ }
49
+
50
+ return this._responseData(true);
51
+ };
@@ -0,0 +1,21 @@
1
+ import { GetTxPoolSizeResponse, GetTransactionCacheResponse, GetTransactionHistoryResponse, OffLineTxResponse, SubmitTransactionParams, SubmitTransactionResponse, OpCreateAccountParams, OpCreateContractParams, OpGasSendParams, OpContractInvokeParams, OpSetMetadataParams, OpSetPrivParams, OpBatchGasSend, OpBatchContractInvoke, TestTransactionRequest, TestTransactionResponse } from "../../../bop-sdk/proto/bop-sdk-interface";
2
+ import { Signer } from "../abstract-service/abstract-signer";
3
+ import { BopInterface } from "../../../bop/bop-base";
4
+ import { transaction } from "../abstract-service/abstract-transaction";
5
+ export declare class TransactionByBop extends transaction {
6
+ readonly bopInterface: BopInterface;
7
+ constructor(bop: BopInterface);
8
+ getTxPoolSize(): Promise<GetTxPoolSizeResponse>;
9
+ getTxPoolTransactions(limit?: number, address?: string, hash?: string): Promise<GetTransactionCacheResponse>;
10
+ getTransactionHistory(seq?: number, start?: number, limit?: number, hash?: string): Promise<GetTransactionHistoryResponse>;
11
+ submitTransaction(params: SubmitTransactionParams): Promise<SubmitTransactionResponse>;
12
+ estimateGas(transaction: TestTransactionRequest): Promise<TestTransactionResponse>;
13
+ buildAccountCreateTx(params: OpCreateAccountParams, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
14
+ buildContractCreateTx(params: OpCreateContractParams, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
15
+ buildGasSendTx(params: OpGasSendParams, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
16
+ buildContractInvokeTx(params: OpContractInvokeParams, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
17
+ buildSetMetadataTx(params: OpSetMetadataParams, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
18
+ buildSetPrivilegeTx(params: OpSetPrivParams, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
19
+ buildBatchGasSend(params: OpBatchGasSend, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
20
+ buildBatchContractInvoke(params: OpBatchContractInvoke, signer: Signer[], sourceAddress?: string): Promise<OffLineTxResponse>;
21
+ }