@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.
- package/CHANGELOG.md +34 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +112 -0
- package/package.json +90 -0
- package/src/bop/bop-base/README.md +5 -0
- package/src/bop/bop-base/base.ts +366 -0
- package/src/bop/bop-base/index.ts +83 -0
- package/src/bop/bop-base/permit.ts +116 -0
- package/src/bop/bop-base/test/base.test.ts +867 -0
- package/src/bop/bop-base/test/index.test.ts +69 -0
- package/src/bop/bop-base/test/permit.test.ts +125 -0
- package/src/bop/bop-base/tsconfig.json +8 -0
- package/src/bop/bop-proto/README.md +2 -0
- package/src/bop/bop-proto/bop-ws.proto +266 -0
- package/src/bop/bop-proto/bop-ws.ts +4447 -0
- package/src/bop/bop-proto/bop.proto +898 -0
- package/src/bop/bop-proto/bop.ts +12890 -0
- package/src/bop/bop-proto/tsconfig.json +8 -0
- package/src/bop/bop-ws/index.ts +315 -0
- package/src/bop/bop-ws/sample/sample.ts +107 -0
- package/src/bop/bop-ws/tsconfig.json +8 -0
- package/src/bop/index.ts +14 -0
- package/src/bop-sdk/index.ts +22 -0
- package/src/bop-sdk/interface/abstract-service/abstract-account.ts +23 -0
- package/src/bop-sdk/interface/abstract-service/abstract-chain.ts +9 -0
- package/src/bop-sdk/interface/abstract-service/abstract-contract.ts +16 -0
- package/src/bop-sdk/interface/abstract-service/abstract-ledger.ts +15 -0
- package/src/bop-sdk/interface/abstract-service/abstract-provider.ts +13 -0
- package/src/bop-sdk/interface/abstract-service/abstract-signer.ts +133 -0
- package/src/bop-sdk/interface/abstract-service/abstract-transaction.ts +86 -0
- package/src/bop-sdk/interface/provider-ws.ts +10 -0
- package/src/bop-sdk/interface/provider.ts +22 -0
- package/src/bop-sdk/interface/service/3rd.ts +54 -0
- package/src/bop-sdk/interface/service/account.ts +86 -0
- package/src/bop-sdk/interface/service/chain.ts +27 -0
- package/src/bop-sdk/interface/service/contract.ts +51 -0
- package/src/bop-sdk/interface/service/helper.ts +426 -0
- package/src/bop-sdk/interface/service/ledger.ts +75 -0
- package/src/bop-sdk/interface/service/offline/check/index.js +138 -0
- package/src/bop-sdk/interface/service/offline/common/constant.js +6 -0
- package/src/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
- package/src/bop-sdk/interface/service/offline/common/util.js +511 -0
- package/src/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
- package/src/bop-sdk/interface/service/offline/exception/errors.js +90 -0
- package/src/bop-sdk/interface/service/offline/exception/index.js +5 -0
- package/src/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
- package/src/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
- package/src/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
- package/src/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
- package/src/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
- package/src/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
- package/src/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
- package/src/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
- package/src/bop-sdk/interface/service/offline/operation/index.js +20 -0
- package/src/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
- package/src/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
- package/src/bop-sdk/interface/service/offline/transaction/index.js +988 -0
- package/src/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
- package/src/bop-sdk/interface/service/offline/validate/account.js +152 -0
- package/src/bop-sdk/interface/service/offline/validate/contract.js +101 -0
- package/src/bop-sdk/interface/service/offline/validate/index.js +10 -0
- package/src/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
- package/src/bop-sdk/interface/service/transaction.ts +731 -0
- package/src/bop-sdk/interface/signer.ts +46 -0
- package/src/bop-sdk/interface/test/3rd.test.ts +1571 -0
- package/src/bop-sdk/interface/test/account.test.ts +284 -0
- package/src/bop-sdk/interface/test/chain.test.ts +45 -0
- package/src/bop-sdk/interface/test/contract.test.ts +283 -0
- package/src/bop-sdk/interface/test/ledger.test.ts +166 -0
- package/src/bop-sdk/interface/test/provider.test.ts +407 -0
- package/src/bop-sdk/interface/test/signer.test.ts +105 -0
- package/src/bop-sdk/interface/test/transaction.test.ts +713 -0
- package/src/bop-sdk/proto/bop-sdk-common.proto +159 -0
- package/src/bop-sdk/proto/bop-sdk-common.ts +829 -0
- package/src/bop-sdk/proto/bop-sdk-interface.proto +581 -0
- package/src/bop-sdk/proto/bop-sdk-interface.ts +10839 -0
- package/src/bop-sdk/proto/bop-sdk-utils.proto +86 -0
- package/src/bop-sdk/proto/bop-sdk-utils.ts +1495 -0
- package/src/bop-sdk/utils/abi/abi-coder.ts +147 -0
- package/src/bop-sdk/utils/abi/address.ts +109 -0
- package/src/bop-sdk/utils/abi/bignumber.ts +403 -0
- package/src/bop-sdk/utils/abi/bytes.ts +565 -0
- package/src/bop-sdk/utils/abi/coders/abstract-coder.ts +239 -0
- package/src/bop-sdk/utils/abi/coders/address.ts +58 -0
- package/src/bop-sdk/utils/abi/coders/anonymous.ts +25 -0
- package/src/bop-sdk/utils/abi/coders/array.ts +275 -0
- package/src/bop-sdk/utils/abi/coders/boolean.ts +21 -0
- package/src/bop-sdk/utils/abi/coders/bytes.ts +36 -0
- package/src/bop-sdk/utils/abi/coders/fixed-bytes.ts +35 -0
- package/src/bop-sdk/utils/abi/coders/null.ts +25 -0
- package/src/bop-sdk/utils/abi/coders/number.ts +56 -0
- package/src/bop-sdk/utils/abi/coders/string.ts +24 -0
- package/src/bop-sdk/utils/abi/coders/tuple.ts +73 -0
- package/src/bop-sdk/utils/abi/constants/addresses.ts +1 -0
- package/src/bop-sdk/utils/abi/constants/bignumbers.ts +30 -0
- package/src/bop-sdk/utils/abi/constants/hashes.ts +2 -0
- package/src/bop-sdk/utils/abi/constants/index.ts +15 -0
- package/src/bop-sdk/utils/abi/constants/strings.ts +2 -0
- package/src/bop-sdk/utils/abi/fragments.ts +1243 -0
- package/src/bop-sdk/utils/abi/id.ts +6 -0
- package/src/bop-sdk/utils/abi/index.ts +46 -0
- package/src/bop-sdk/utils/abi/interface.ts +921 -0
- package/src/bop-sdk/utils/abi/keccak256.ts +9 -0
- package/src/bop-sdk/utils/abi/properties.ts +172 -0
- package/src/bop-sdk/utils/abi/strings/bytes32.ts +40 -0
- package/src/bop-sdk/utils/abi/strings/idna.ts +258 -0
- package/src/bop-sdk/utils/abi/strings/index.ts +28 -0
- package/src/bop-sdk/utils/abi/strings/utf8.ts +373 -0
- package/src/bop-sdk/utils/encryption-address.ts +501 -0
- package/src/bop-sdk/utils/encryption-crypto.ts +427 -0
- package/src/bop-sdk/utils/encryption-mnemonics.ts +120 -0
- package/src/bop-sdk/utils/index.ts +27 -0
- package/src/bop-sdk/utils/logger.ts +480 -0
- package/src/index.ts +35 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Coder, Reader, Writer } from "./abstract-coder";
|
|
4
|
+
|
|
5
|
+
export class NullCoder extends Coder {
|
|
6
|
+
constructor(localName: string) {
|
|
7
|
+
super("null", "", localName, false);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
defaultValue(): null {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
encode(writer: Writer, value: any): number {
|
|
15
|
+
if (value != null) {
|
|
16
|
+
this._throwError("not null", value);
|
|
17
|
+
}
|
|
18
|
+
return writer.writeBytes([]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
decode(reader: Reader): any {
|
|
22
|
+
reader.readBytes(0);
|
|
23
|
+
return reader.coerce(this.name, null);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { BigNumber, BigNumberish } from "../bignumber";
|
|
4
|
+
import { MaxUint256, NegativeOne, One, Zero } from "../constants";
|
|
5
|
+
|
|
6
|
+
import { Coder, Reader, Writer } from "./abstract-coder";
|
|
7
|
+
|
|
8
|
+
export class NumberCoder extends Coder {
|
|
9
|
+
readonly size: number;
|
|
10
|
+
readonly signed: boolean;
|
|
11
|
+
|
|
12
|
+
constructor(size: number, signed: boolean, localName: string) {
|
|
13
|
+
const name = (signed ? "int" : "uint") + size * 8;
|
|
14
|
+
super(name, name, localName, false);
|
|
15
|
+
|
|
16
|
+
this.size = size;
|
|
17
|
+
this.signed = signed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
defaultValue(): number {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
encode(writer: Writer, value: BigNumberish): number {
|
|
25
|
+
let v = BigNumber.from(value);
|
|
26
|
+
|
|
27
|
+
// Check bounds are safe for encoding
|
|
28
|
+
let maxUintValue = MaxUint256.mask(writer.wordSize * 8);
|
|
29
|
+
if (this.signed) {
|
|
30
|
+
let bounds = maxUintValue.mask(this.size * 8 - 1);
|
|
31
|
+
if (v.gt(bounds) || v.lt(bounds.add(One).mul(NegativeOne))) {
|
|
32
|
+
this._throwError("value out-of-bounds", value);
|
|
33
|
+
}
|
|
34
|
+
} else if (v.lt(Zero) || v.gt(maxUintValue.mask(this.size * 8))) {
|
|
35
|
+
this._throwError("value out-of-bounds", value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
v = v.toTwos(this.size * 8).mask(this.size * 8);
|
|
39
|
+
|
|
40
|
+
if (this.signed) {
|
|
41
|
+
v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return writer.writeValue(v);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
decode(reader: Reader): any {
|
|
48
|
+
let value = reader.readValue().mask(this.size * 8);
|
|
49
|
+
|
|
50
|
+
if (this.signed) {
|
|
51
|
+
value = value.fromTwos(this.size * 8);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return reader.coerce(this.name, value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { toUtf8Bytes, toUtf8String } from "../strings";
|
|
4
|
+
|
|
5
|
+
import { Reader, Writer } from "./abstract-coder";
|
|
6
|
+
import { DynamicBytesCoder } from "./bytes";
|
|
7
|
+
|
|
8
|
+
export class StringCoder extends DynamicBytesCoder {
|
|
9
|
+
constructor(localName: string) {
|
|
10
|
+
super("string", localName);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
defaultValue(): string {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
encode(writer: Writer, value: any): number {
|
|
18
|
+
return super.encode(writer, toUtf8Bytes(value));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
decode(reader: Reader): any {
|
|
22
|
+
return toUtf8String(super.decode(reader));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Coder, Reader, Writer } from "./abstract-coder";
|
|
4
|
+
import { pack, unpack } from "./array";
|
|
5
|
+
|
|
6
|
+
export class TupleCoder extends Coder {
|
|
7
|
+
readonly coders: Array<Coder>;
|
|
8
|
+
|
|
9
|
+
constructor(coders: Array<Coder>, localName: string) {
|
|
10
|
+
let dynamic = false;
|
|
11
|
+
const types: Array<string> = [];
|
|
12
|
+
coders.forEach((coder) => {
|
|
13
|
+
if (coder.dynamic) {
|
|
14
|
+
dynamic = true;
|
|
15
|
+
}
|
|
16
|
+
types.push(coder.type);
|
|
17
|
+
});
|
|
18
|
+
const type = "tuple(" + types.join(",") + ")";
|
|
19
|
+
|
|
20
|
+
super("tuple", type, localName, dynamic);
|
|
21
|
+
this.coders = coders;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
defaultValue(): any {
|
|
25
|
+
const values: any = [];
|
|
26
|
+
this.coders.forEach((coder) => {
|
|
27
|
+
values.push(coder.defaultValue());
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// We only output named properties for uniquely named coders
|
|
31
|
+
const uniqueNames = this.coders.reduce(
|
|
32
|
+
(accum, coder) => {
|
|
33
|
+
const name = coder.localName;
|
|
34
|
+
if (name) {
|
|
35
|
+
if (!accum[name]) {
|
|
36
|
+
accum[name] = 0;
|
|
37
|
+
}
|
|
38
|
+
accum[name]++;
|
|
39
|
+
}
|
|
40
|
+
return accum;
|
|
41
|
+
},
|
|
42
|
+
<{ [name: string]: number }>{},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Add named values
|
|
46
|
+
this.coders.forEach((coder: Coder, index: number) => {
|
|
47
|
+
let name = coder.localName;
|
|
48
|
+
if (!name || uniqueNames[name] !== 1) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (name === "length") {
|
|
53
|
+
name = "_length";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (values[name] != null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
values[name] = values[index];
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return Object.freeze(values);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
encode(writer: Writer, value: Array<any> | { [name: string]: any }): number {
|
|
67
|
+
return pack(writer, this.coders, value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
decode(reader: Reader): any {
|
|
71
|
+
return reader.coerce(this.name, unpack(reader, this.coders));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const AddressZero = "0x0000000000000000000000000000000000000000";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BigNumber } from "../bignumber";
|
|
2
|
+
|
|
3
|
+
const NegativeOne: BigNumber = /*#__PURE__*/ BigNumber.from(-1);
|
|
4
|
+
const Zero: BigNumber = /*#__PURE__*/ BigNumber.from(0);
|
|
5
|
+
const One: BigNumber = /*#__PURE__*/ BigNumber.from(1);
|
|
6
|
+
const Two: BigNumber = /*#__PURE__*/ BigNumber.from(2);
|
|
7
|
+
const WeiPerEther: BigNumber = /*#__PURE__*/ BigNumber.from(
|
|
8
|
+
"1000000000000000000",
|
|
9
|
+
);
|
|
10
|
+
const MaxUint256: BigNumber = /*#__PURE__*/ BigNumber.from(
|
|
11
|
+
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const MinInt256: BigNumber = /*#__PURE__*/ BigNumber.from(
|
|
15
|
+
"-0x8000000000000000000000000000000000000000000000000000000000000000",
|
|
16
|
+
);
|
|
17
|
+
const MaxInt256: BigNumber = /*#__PURE__*/ BigNumber.from(
|
|
18
|
+
"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
NegativeOne,
|
|
23
|
+
Zero,
|
|
24
|
+
One,
|
|
25
|
+
Two,
|
|
26
|
+
WeiPerEther,
|
|
27
|
+
MaxUint256,
|
|
28
|
+
MinInt256,
|
|
29
|
+
MaxInt256,
|
|
30
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export { AddressZero } from "./addresses";
|
|
4
|
+
export {
|
|
5
|
+
NegativeOne,
|
|
6
|
+
Zero,
|
|
7
|
+
One,
|
|
8
|
+
Two,
|
|
9
|
+
WeiPerEther,
|
|
10
|
+
MaxUint256,
|
|
11
|
+
MinInt256,
|
|
12
|
+
MaxInt256,
|
|
13
|
+
} from "./bignumbers";
|
|
14
|
+
export { HashZero } from "./hashes";
|
|
15
|
+
export { EtherSymbol } from "./strings";
|