@caict/bop-typescript-sdk 1.0.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 (115) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +5 -0
  4. package/README.md +112 -0
  5. package/package.json +90 -0
  6. package/src/bop/bop-base/README.md +5 -0
  7. package/src/bop/bop-base/base.ts +366 -0
  8. package/src/bop/bop-base/index.ts +83 -0
  9. package/src/bop/bop-base/permit.ts +116 -0
  10. package/src/bop/bop-base/test/base.test.ts +867 -0
  11. package/src/bop/bop-base/test/index.test.ts +69 -0
  12. package/src/bop/bop-base/test/permit.test.ts +125 -0
  13. package/src/bop/bop-base/tsconfig.json +8 -0
  14. package/src/bop/bop-proto/README.md +2 -0
  15. package/src/bop/bop-proto/bop-ws.proto +266 -0
  16. package/src/bop/bop-proto/bop-ws.ts +4447 -0
  17. package/src/bop/bop-proto/bop.proto +898 -0
  18. package/src/bop/bop-proto/bop.ts +12890 -0
  19. package/src/bop/bop-proto/tsconfig.json +8 -0
  20. package/src/bop/bop-ws/index.ts +315 -0
  21. package/src/bop/bop-ws/sample/sample.ts +107 -0
  22. package/src/bop/bop-ws/tsconfig.json +8 -0
  23. package/src/bop/index.ts +14 -0
  24. package/src/bop-sdk/index.ts +22 -0
  25. package/src/bop-sdk/interface/abstract-service/abstract-account.ts +23 -0
  26. package/src/bop-sdk/interface/abstract-service/abstract-chain.ts +9 -0
  27. package/src/bop-sdk/interface/abstract-service/abstract-contract.ts +16 -0
  28. package/src/bop-sdk/interface/abstract-service/abstract-ledger.ts +15 -0
  29. package/src/bop-sdk/interface/abstract-service/abstract-provider.ts +13 -0
  30. package/src/bop-sdk/interface/abstract-service/abstract-signer.ts +133 -0
  31. package/src/bop-sdk/interface/abstract-service/abstract-transaction.ts +86 -0
  32. package/src/bop-sdk/interface/provider-ws.ts +10 -0
  33. package/src/bop-sdk/interface/provider.ts +22 -0
  34. package/src/bop-sdk/interface/service/3rd.ts +54 -0
  35. package/src/bop-sdk/interface/service/account.ts +86 -0
  36. package/src/bop-sdk/interface/service/chain.ts +27 -0
  37. package/src/bop-sdk/interface/service/contract.ts +51 -0
  38. package/src/bop-sdk/interface/service/helper.ts +426 -0
  39. package/src/bop-sdk/interface/service/ledger.ts +75 -0
  40. package/src/bop-sdk/interface/service/offline/check/index.js +138 -0
  41. package/src/bop-sdk/interface/service/offline/common/constant.js +6 -0
  42. package/src/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
  43. package/src/bop-sdk/interface/service/offline/common/util.js +511 -0
  44. package/src/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
  45. package/src/bop-sdk/interface/service/offline/exception/errors.js +90 -0
  46. package/src/bop-sdk/interface/service/offline/exception/index.js +5 -0
  47. package/src/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
  48. package/src/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
  49. package/src/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
  50. package/src/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
  51. package/src/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
  52. package/src/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
  53. package/src/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
  54. package/src/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
  55. package/src/bop-sdk/interface/service/offline/operation/index.js +20 -0
  56. package/src/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
  57. package/src/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
  58. package/src/bop-sdk/interface/service/offline/transaction/index.js +988 -0
  59. package/src/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
  60. package/src/bop-sdk/interface/service/offline/validate/account.js +152 -0
  61. package/src/bop-sdk/interface/service/offline/validate/contract.js +101 -0
  62. package/src/bop-sdk/interface/service/offline/validate/index.js +10 -0
  63. package/src/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
  64. package/src/bop-sdk/interface/service/transaction.ts +731 -0
  65. package/src/bop-sdk/interface/signer.ts +46 -0
  66. package/src/bop-sdk/interface/test/3rd.test.ts +1571 -0
  67. package/src/bop-sdk/interface/test/account.test.ts +284 -0
  68. package/src/bop-sdk/interface/test/chain.test.ts +45 -0
  69. package/src/bop-sdk/interface/test/contract.test.ts +283 -0
  70. package/src/bop-sdk/interface/test/ledger.test.ts +166 -0
  71. package/src/bop-sdk/interface/test/provider.test.ts +407 -0
  72. package/src/bop-sdk/interface/test/signer.test.ts +105 -0
  73. package/src/bop-sdk/interface/test/transaction.test.ts +713 -0
  74. package/src/bop-sdk/proto/bop-sdk-common.proto +159 -0
  75. package/src/bop-sdk/proto/bop-sdk-common.ts +829 -0
  76. package/src/bop-sdk/proto/bop-sdk-interface.proto +581 -0
  77. package/src/bop-sdk/proto/bop-sdk-interface.ts +10839 -0
  78. package/src/bop-sdk/proto/bop-sdk-utils.proto +86 -0
  79. package/src/bop-sdk/proto/bop-sdk-utils.ts +1495 -0
  80. package/src/bop-sdk/utils/abi/abi-coder.ts +147 -0
  81. package/src/bop-sdk/utils/abi/address.ts +109 -0
  82. package/src/bop-sdk/utils/abi/bignumber.ts +403 -0
  83. package/src/bop-sdk/utils/abi/bytes.ts +565 -0
  84. package/src/bop-sdk/utils/abi/coders/abstract-coder.ts +239 -0
  85. package/src/bop-sdk/utils/abi/coders/address.ts +58 -0
  86. package/src/bop-sdk/utils/abi/coders/anonymous.ts +25 -0
  87. package/src/bop-sdk/utils/abi/coders/array.ts +275 -0
  88. package/src/bop-sdk/utils/abi/coders/boolean.ts +21 -0
  89. package/src/bop-sdk/utils/abi/coders/bytes.ts +36 -0
  90. package/src/bop-sdk/utils/abi/coders/fixed-bytes.ts +35 -0
  91. package/src/bop-sdk/utils/abi/coders/null.ts +25 -0
  92. package/src/bop-sdk/utils/abi/coders/number.ts +56 -0
  93. package/src/bop-sdk/utils/abi/coders/string.ts +24 -0
  94. package/src/bop-sdk/utils/abi/coders/tuple.ts +73 -0
  95. package/src/bop-sdk/utils/abi/constants/addresses.ts +1 -0
  96. package/src/bop-sdk/utils/abi/constants/bignumbers.ts +30 -0
  97. package/src/bop-sdk/utils/abi/constants/hashes.ts +2 -0
  98. package/src/bop-sdk/utils/abi/constants/index.ts +15 -0
  99. package/src/bop-sdk/utils/abi/constants/strings.ts +2 -0
  100. package/src/bop-sdk/utils/abi/fragments.ts +1243 -0
  101. package/src/bop-sdk/utils/abi/id.ts +6 -0
  102. package/src/bop-sdk/utils/abi/index.ts +46 -0
  103. package/src/bop-sdk/utils/abi/interface.ts +921 -0
  104. package/src/bop-sdk/utils/abi/keccak256.ts +9 -0
  105. package/src/bop-sdk/utils/abi/properties.ts +172 -0
  106. package/src/bop-sdk/utils/abi/strings/bytes32.ts +40 -0
  107. package/src/bop-sdk/utils/abi/strings/idna.ts +258 -0
  108. package/src/bop-sdk/utils/abi/strings/index.ts +28 -0
  109. package/src/bop-sdk/utils/abi/strings/utf8.ts +373 -0
  110. package/src/bop-sdk/utils/encryption-address.ts +501 -0
  111. package/src/bop-sdk/utils/encryption-crypto.ts +427 -0
  112. package/src/bop-sdk/utils/encryption-mnemonics.ts +120 -0
  113. package/src/bop-sdk/utils/index.ts +27 -0
  114. package/src/bop-sdk/utils/logger.ts +480 -0
  115. package/src/index.ts +35 -0
@@ -0,0 +1,86 @@
1
+ import {
2
+ GetTxPoolSizeResponse,
3
+ GetTransactionCacheResponse,
4
+ GetTransactionHistoryResponse,
5
+ OffLineTxResponse,
6
+ OpCreateAccountParams,
7
+ OpCreateContractParams,
8
+ OpGasSendParams,
9
+ OpContractInvokeParams,
10
+ OpSetMetadataParams,
11
+ OpSetPrivParams,
12
+ OpBatchGasSend,
13
+ OpBatchContractInvoke,
14
+ SubmitTransactionParams,
15
+ SubmitTransactionResponse,
16
+ TestTransactionRequest,
17
+ TestTransactionResponse,
18
+ } from "bop-sdk/proto/bop-sdk-interface";
19
+ import { Signer } from "./abstract-signer";
20
+
21
+ export abstract class transaction {
22
+ abstract getTxPoolSize(): Promise<GetTxPoolSizeResponse>;
23
+ abstract getTxPoolTransactions(
24
+ limit?: number,
25
+ address?: string,
26
+ hash?: string,
27
+ ): Promise<GetTransactionCacheResponse>;
28
+ abstract getTransactionHistory(
29
+ seq?: number,
30
+ start?: number,
31
+ limit?: number,
32
+ hash?: string,
33
+ ): Promise<GetTransactionHistoryResponse>;
34
+ //构建离线交易数据
35
+ abstract buildAccountCreateTx(
36
+ params: OpCreateAccountParams,
37
+ signer: Signer[],
38
+ sourceAddress?: string,
39
+ ): Promise<OffLineTxResponse>;
40
+ abstract buildContractCreateTx(
41
+ params: OpCreateContractParams,
42
+ signer: Signer[],
43
+ sourceAddress?: string,
44
+ ): Promise<OffLineTxResponse>;
45
+ abstract buildGasSendTx(
46
+ params: OpGasSendParams,
47
+ signer: Signer[],
48
+ sourceAddress?: string,
49
+ ): Promise<OffLineTxResponse>;
50
+ abstract buildContractInvokeTx(
51
+ params: OpContractInvokeParams,
52
+ signer: Signer[],
53
+ sourceAddress?: string,
54
+ ): Promise<OffLineTxResponse>;
55
+ abstract buildSetMetadataTx(
56
+ params: OpSetMetadataParams,
57
+ signer: Signer[],
58
+ sourceAddress?: string,
59
+ ): Promise<OffLineTxResponse>;
60
+ abstract buildSetPrivilegeTx(
61
+ params: OpSetPrivParams,
62
+ signer: Signer[],
63
+ sourceAddress?: string,
64
+ ): Promise<OffLineTxResponse>;
65
+
66
+ //构建离线批量交易数据
67
+ abstract buildBatchGasSend(
68
+ params: OpBatchGasSend,
69
+ signer: Signer[],
70
+ sourceAddress?: string,
71
+ ): Promise<OffLineTxResponse>;
72
+
73
+ abstract buildBatchContractInvoke(
74
+ params: OpBatchContractInvoke,
75
+ signer: Signer[],
76
+ sourceAddress?: string,
77
+ ): Promise<OffLineTxResponse>;
78
+
79
+ abstract submitTransaction(
80
+ params: SubmitTransactionParams,
81
+ ): Promise<SubmitTransactionResponse>;
82
+
83
+ abstract estimateGas(
84
+ transaction: TestTransactionRequest,
85
+ ): Promise<TestTransactionResponse>;
86
+ }
@@ -0,0 +1,10 @@
1
+ import { WsConfig, BopWsInterface } from "../../bop/bop-ws";
2
+
3
+ //未拓展新功能,直接接入Bop平台的ws
4
+ export class WsProviderByBop {
5
+ public bop: BopWsInterface;
6
+
7
+ constructor(config: WsConfig) {
8
+ this.bop = new BopWsInterface(config.url, config.heartBeatInterval);
9
+ }
10
+ }
@@ -0,0 +1,22 @@
1
+ import { Provider } from "./abstract-service/abstract-provider";
2
+ import { BopInterface } from "../../bop/bop-base";
3
+ import { ChainByBop } from "./service/chain";
4
+ import { LedgerByBop } from "./service/ledger";
5
+ import { AccountByBop } from "./service/account";
6
+ import { TransactionByBop } from "./service/transaction";
7
+ import { ContractByBop } from "./service/contract";
8
+ import { BopByBop } from "./service/3rd";
9
+
10
+ export class ProviderByBop extends Provider {
11
+ public bop: BopByBop;
12
+
13
+ constructor(bop: BopInterface) {
14
+ super();
15
+ this.chain = new ChainByBop(bop);
16
+ this.ledger = new LedgerByBop(bop);
17
+ this.account = new AccountByBop(bop);
18
+ this.transaction = new TransactionByBop(bop);
19
+ this.contract = new ContractByBop(bop);
20
+ this.bop = new BopByBop(bop);
21
+ }
22
+ }
@@ -0,0 +1,54 @@
1
+ import { BopInterface } from "../../../bop/bop-base";
2
+ import {
3
+ ApplyRequest,
4
+ ApplyResponse,
5
+ ApplyStatusRequest,
6
+ ApplyStatusResponse,
7
+ DetailRequest,
8
+ DetailResponse,
9
+ GetTransactionCacheRequest,
10
+ GetTransactionCachePlatResponse,
11
+ DiscardRequest,
12
+ DiscardResponse,
13
+ QueryRequest,
14
+ QueryResponse,
15
+ } from "../../../bop/bop-proto/bop";
16
+
17
+ export class BopByBop {
18
+ readonly bopInterface: BopInterface;
19
+
20
+ constructor(bop: BopInterface) {
21
+ this.bopInterface = bop;
22
+ }
23
+
24
+ public async apply(params: ApplyRequest): Promise<ApplyResponse> {
25
+ return this.bopInterface.callService("permit_apply", params);
26
+ }
27
+
28
+ public async status(
29
+ params: ApplyStatusRequest,
30
+ ): Promise<ApplyStatusResponse> {
31
+ return this.bopInterface.callService("permit_status", params);
32
+ }
33
+
34
+ public async detail(params: DetailRequest): Promise<DetailResponse> {
35
+ return this.bopInterface.callService("permit_detail", params);
36
+ }
37
+
38
+ public async getTransactionCache(
39
+ params: GetTransactionCacheRequest,
40
+ ): Promise<GetTransactionCachePlatResponse> {
41
+ return this.bopInterface.callService(
42
+ "base_getTransactionCachePlat",
43
+ params,
44
+ );
45
+ }
46
+
47
+ public async discard(params: DiscardRequest): Promise<DiscardResponse> {
48
+ return this.bopInterface.callService("base_discard", params);
49
+ }
50
+
51
+ public async query(params: QueryRequest): Promise<QueryResponse> {
52
+ return this.bopInterface.callService("base_query", params);
53
+ }
54
+ }
@@ -0,0 +1,86 @@
1
+ import { GetAccountBaseRequest, GetAccountRequest } from "bop/bop-proto/bop";
2
+ import {
3
+ GetAccountBalanceResponse,
4
+ GetAccountIncreaseNonceResponse,
5
+ GetAccountMetadataResponse,
6
+ GetAccountPrivResponse,
7
+ GetAccountResponse,
8
+ } from "../../../bop-sdk/proto/bop-sdk-interface";
9
+ import { BopInterface } from "../../../bop/bop-base";
10
+ import { account } from "../abstract-service/abstract-account";
11
+ import * as trans from "./helper";
12
+ import { SdkStatusCode } from "../../../bop-sdk/proto/bop-sdk-common";
13
+
14
+ export class AccountByBop extends account {
15
+ readonly bopInterface: BopInterface;
16
+ constructor(bop: BopInterface) {
17
+ super();
18
+ this.bopInterface = bop;
19
+ }
20
+
21
+ public async getAccount(address: string): Promise<GetAccountResponse> {
22
+ const request: GetAccountBaseRequest = {
23
+ address: address,
24
+ };
25
+ return trans.AccountAccountResultToAccountInfo(
26
+ await this.bopInterface.callService("base_getAccountBase", request),
27
+ );
28
+ }
29
+
30
+ public async getAccountMetadata(
31
+ address: string,
32
+ seq?: number,
33
+ key?: string,
34
+ ): Promise<GetAccountMetadataResponse> {
35
+ let request: GetAccountRequest = {
36
+ address: address,
37
+ };
38
+ if (seq !== undefined) request.height = seq;
39
+ if (key !== undefined) {
40
+ request.key = key;
41
+ if (key.length < 1 || key.length > 1024) {
42
+ let response: GetAccountMetadataResponse = {
43
+ errorCode: SdkStatusCode.INVALID_DATAKEY_ERROR,
44
+ errorDesc: "The length of key must be between 1 and 1024",
45
+ };
46
+ return response;
47
+ }
48
+ }
49
+ return trans.AccountAccountToAccountMetadatas(
50
+ await this.bopInterface.callService("base_getAccount", request),
51
+ );
52
+ }
53
+
54
+ public async getAccountIncreaseNonce(
55
+ address: string,
56
+ ): Promise<GetAccountIncreaseNonceResponse> {
57
+ const request: GetAccountBaseRequest = {
58
+ address: address,
59
+ };
60
+ return trans.AccountAccountResultToIncreaseNonce(
61
+ await this.bopInterface.callService("base_getAccountBase", request),
62
+ );
63
+ }
64
+
65
+ public async getAccountBalance(
66
+ address: string,
67
+ ): Promise<GetAccountBalanceResponse> {
68
+ const request: GetAccountBaseRequest = {
69
+ address: address,
70
+ };
71
+ return trans.AccountAccountResultToBalance(
72
+ await this.bopInterface.callService("base_getAccountBase", request),
73
+ );
74
+ }
75
+
76
+ public async getAccountPriv(
77
+ address: string,
78
+ ): Promise<GetAccountPrivResponse> {
79
+ const request: GetAccountBaseRequest = {
80
+ address: address,
81
+ };
82
+ return trans.AccountAccountResultToPriv(
83
+ await this.bopInterface.callService("base_getAccountBase", request),
84
+ );
85
+ }
86
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ GetChainInfoResponse,
3
+ GetNetworkIdResponse,
4
+ } from "../../../bop-sdk/proto/bop-sdk-interface";
5
+ import { BopInterface } from "../../../bop/bop-base";
6
+ import { chain } from "../abstract-service/abstract-chain";
7
+ import * as trans from "./helper";
8
+
9
+ export class ChainByBop extends chain {
10
+ readonly bopInterface: BopInterface;
11
+ constructor(bop: BopInterface) {
12
+ super();
13
+ this.bopInterface = bop;
14
+ }
15
+
16
+ public async getChainInfo(): Promise<GetChainInfoResponse> {
17
+ return trans.ChainHelloToChainInfo(
18
+ await this.bopInterface.callService("base_hello"),
19
+ );
20
+ }
21
+
22
+ public async getNetworkId(): Promise<GetNetworkIdResponse> {
23
+ return trans.ChainHelloToNetworkId(
24
+ await this.bopInterface.callService("base_hello"),
25
+ );
26
+ }
27
+ }
@@ -0,0 +1,51 @@
1
+ import { GetAccountBaseRequest } from "bop/bop-proto/bop";
2
+ import {
3
+ CheckContractAccountResponse,
4
+ GetContractInfoResponse,
5
+ CallContractRequest,
6
+ CallContractResponse,
7
+ } from "../../../bop-sdk/proto/bop-sdk-interface";
8
+ import { BopInterface } from "../../../bop/bop-base";
9
+ import { contract } from "../abstract-service/abstract-contract";
10
+ import * as trans from "./helper";
11
+
12
+ export class ContractByBop extends contract {
13
+ readonly bopInterface: BopInterface;
14
+ constructor(bop: BopInterface) {
15
+ super();
16
+ this.bopInterface = bop;
17
+ }
18
+
19
+ public async checkContractAccount(
20
+ address: string,
21
+ ): Promise<CheckContractAccountResponse> {
22
+ const request: GetAccountBaseRequest = {
23
+ address: address,
24
+ };
25
+ return trans.ContractAccountResultToCheckContractAccount(
26
+ await this.bopInterface.callService("base_getAccountBase", request),
27
+ );
28
+ }
29
+
30
+ public async getContractInfo(
31
+ address: string,
32
+ ): Promise<GetContractInfoResponse> {
33
+ const request: GetAccountBaseRequest = {
34
+ address: address,
35
+ };
36
+ return trans.ContractAccountResultToGetContractInfo(
37
+ await this.bopInterface.callService("base_getAccountBase", request),
38
+ );
39
+ }
40
+
41
+ public async callContract(
42
+ transaction: CallContractRequest,
43
+ ): Promise<CallContractResponse> {
44
+ transaction.optType = 2;
45
+
46
+ return await this.bopInterface.callService(
47
+ "base_callContract",
48
+ transaction,
49
+ );
50
+ }
51
+ }