@arkecosystem/typescript-crypto 0.0.4 → 0.0.5
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/.github/workflows/ci.yml +23 -23
- package/.github/workflows/format.yml +80 -0
- package/.github/workflows/publish.yml +1 -1
- package/.prettierrc.json +8 -0
- package/dist/enums/ContractAbiType.d.ts.map +1 -1
- package/dist/exceptions/index.d.ts.map +1 -1
- package/dist/identities/PrivateKey.d.ts +2 -2
- package/dist/identities/PrivateKey.d.ts.map +1 -1
- package/dist/identities/PrivateKey.js +1 -1
- package/dist/identities/WIF.d.ts.map +1 -1
- package/dist/identities/WIF.js +2 -2
- package/dist/index.js +532 -627
- package/dist/networks/AbstractNetwork.d.ts +1 -1
- package/dist/networks/AbstractNetwork.d.ts.map +1 -1
- package/dist/networks/Mainnet.d.ts +1 -1
- package/dist/networks/Mainnet.d.ts.map +1 -1
- package/dist/networks/Mainnet.js +1 -1
- package/dist/networks/Testnet.d.ts +1 -1
- package/dist/networks/Testnet.d.ts.map +1 -1
- package/dist/networks/Testnet.js +1 -1
- package/dist/transactions/Deserializer.d.ts +5 -5
- package/dist/transactions/Deserializer.d.ts.map +1 -1
- package/dist/transactions/Deserializer.js +18 -18
- package/dist/transactions/Serializer.d.ts +0 -1
- package/dist/transactions/Serializer.d.ts.map +1 -1
- package/dist/transactions/Serializer.js +0 -3
- package/dist/transactions/builders/AbstractTransactionBuilder.d.ts +7 -6
- package/dist/transactions/builders/AbstractTransactionBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/AbstractTransactionBuilder.js +15 -8
- package/dist/transactions/builders/EvmCallBuilder.d.ts +3 -3
- package/dist/transactions/builders/EvmCallBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/MultipaymentBuilder.d.ts +5 -4
- package/dist/transactions/builders/MultipaymentBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/MultipaymentBuilder.js +6 -2
- package/dist/transactions/builders/TransferBuilder.d.ts +4 -3
- package/dist/transactions/builders/TransferBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/TransferBuilder.js +4 -0
- package/dist/transactions/builders/UnvoteBuilder.d.ts +3 -3
- package/dist/transactions/builders/UnvoteBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/UnvoteBuilder.js +1 -1
- package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts +3 -3
- package/dist/transactions/builders/UsernameRegistrationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/UsernameRegistrationBuilder.js +1 -1
- package/dist/transactions/builders/UsernameResignationBuilder.d.ts +3 -3
- package/dist/transactions/builders/UsernameResignationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/UsernameResignationBuilder.js +1 -1
- package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts +3 -3
- package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/ValidatorRegistrationBuilder.js +1 -1
- package/dist/transactions/builders/ValidatorResignationBuilder.d.ts +3 -3
- package/dist/transactions/builders/ValidatorResignationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/ValidatorResignationBuilder.js +1 -1
- package/dist/transactions/builders/VoteBuilder.d.ts +3 -3
- package/dist/transactions/builders/VoteBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/VoteBuilder.js +1 -1
- package/dist/transactions/types/AbstractTransaction.d.ts +2 -5
- package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -1
- package/dist/transactions/types/AbstractTransaction.js +13 -15
- package/dist/transactions/types/EvmCall.d.ts +0 -3
- package/dist/transactions/types/EvmCall.d.ts.map +1 -1
- package/dist/transactions/types/EvmCall.js +0 -8
- package/dist/transactions/types/Multipayment.d.ts +1 -3
- package/dist/transactions/types/Multipayment.d.ts.map +1 -1
- package/dist/transactions/types/Multipayment.js +1 -8
- package/dist/transactions/types/Transfer.d.ts +0 -3
- package/dist/transactions/types/Transfer.d.ts.map +1 -1
- package/dist/transactions/types/Transfer.js +0 -8
- package/dist/transactions/types/Unvote.d.ts +0 -3
- package/dist/transactions/types/Unvote.d.ts.map +1 -1
- package/dist/transactions/types/Unvote.js +0 -8
- package/dist/transactions/types/UsernameRegistration.d.ts +1 -3
- package/dist/transactions/types/UsernameRegistration.d.ts.map +1 -1
- package/dist/transactions/types/UsernameRegistration.js +0 -7
- package/dist/transactions/types/UsernameResignation.d.ts +0 -3
- package/dist/transactions/types/UsernameResignation.d.ts.map +1 -1
- package/dist/transactions/types/UsernameResignation.js +0 -7
- package/dist/transactions/types/ValidatorRegistration.d.ts +1 -3
- package/dist/transactions/types/ValidatorRegistration.d.ts.map +1 -1
- package/dist/transactions/types/ValidatorRegistration.js +0 -8
- package/dist/transactions/types/ValidatorResignation.d.ts +0 -3
- package/dist/transactions/types/ValidatorResignation.d.ts.map +1 -1
- package/dist/transactions/types/ValidatorResignation.js +0 -8
- package/dist/transactions/types/Vote.d.ts +1 -3
- package/dist/transactions/types/Vote.d.ts.map +1 -1
- package/dist/transactions/types/Vote.js +0 -8
- package/dist/types.d.ts +19 -19
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/Abi/ArgumentDecoder.js +6 -6
- package/dist/utils/Abi/json/Abi.Consensus.json +15 -45
- package/dist/utils/Abi/json/Abi.Usernames.json +9 -27
- package/dist/utils/AbiDecoder.d.ts.map +1 -1
- package/dist/utils/AbiDecoder.js +3 -0
- package/dist/utils/AbiEncoder.d.ts +1 -1
- package/dist/utils/AbiEncoder.d.ts.map +1 -1
- package/dist/utils/AbiEncoder.js +2 -1
- package/dist/utils/Message.d.ts +1 -1
- package/dist/utils/Message.d.ts.map +1 -1
- package/dist/utils/Message.js +1 -1
- package/dist/utils/TransactionUtils.d.ts +0 -1
- package/dist/utils/TransactionUtils.d.ts.map +1 -1
- package/dist/utils/TransactionUtils.js +15 -18
- package/dist/utils/UnitConverter.d.ts.map +1 -1
- package/dist/utils/UnitConverter.js +12 -12
- package/eslint.config.mjs +19 -0
- package/jest.config.ts +6 -6
- package/package.json +6 -2
- package/src/enums/Constants.ts +1 -1
- package/src/enums/ContractAbiType.ts +4 -4
- package/src/exceptions/index.ts +1 -1
- package/src/identities/PrivateKey.ts +3 -3
- package/src/identities/WIF.ts +2 -3
- package/src/networks/AbstractNetwork.ts +3 -3
- package/src/networks/Mainnet.ts +3 -3
- package/src/networks/Testnet.ts +1 -1
- package/src/transactions/Deserializer.ts +39 -30
- package/src/transactions/Serializer.ts +1 -5
- package/src/transactions/builders/AbstractTransactionBuilder.ts +20 -11
- package/src/transactions/builders/EvmCallBuilder.ts +3 -3
- package/src/transactions/builders/MultipaymentBuilder.ts +13 -6
- package/src/transactions/builders/TransferBuilder.ts +8 -3
- package/src/transactions/builders/UnvoteBuilder.ts +4 -4
- package/src/transactions/builders/UsernameRegistrationBuilder.ts +4 -4
- package/src/transactions/builders/UsernameResignationBuilder.ts +4 -4
- package/src/transactions/builders/ValidatorRegistrationBuilder.ts +4 -4
- package/src/transactions/builders/ValidatorResignationBuilder.ts +4 -4
- package/src/transactions/builders/VoteBuilder.ts +4 -4
- package/src/transactions/types/AbstractTransaction.ts +17 -24
- package/src/transactions/types/EvmCall.ts +0 -15
- package/src/transactions/types/Multipayment.ts +3 -15
- package/src/transactions/types/Transfer.ts +0 -15
- package/src/transactions/types/Unvote.ts +0 -15
- package/src/transactions/types/UsernameRegistration.ts +1 -13
- package/src/transactions/types/UsernameResignation.ts +0 -14
- package/src/transactions/types/ValidatorRegistration.ts +1 -14
- package/src/transactions/types/ValidatorResignation.ts +0 -15
- package/src/transactions/types/Vote.ts +1 -14
- package/src/types.ts +19 -19
- package/src/utils/Abi/ArgumentDecoder.ts +6 -6
- package/src/utils/Abi/json/Abi.Consensus.json +1641 -1671
- package/src/utils/Abi/json/Abi.Multipayment.json +108 -108
- package/src/utils/Abi/json/Abi.Usernames.json +880 -898
- package/src/utils/AbiBase.ts +1 -1
- package/src/utils/AbiDecoder.ts +6 -3
- package/src/utils/AbiEncoder.ts +3 -2
- package/src/utils/Message.ts +1 -1
- package/src/utils/TransactionUtils.ts +24 -28
- package/src/utils/UnitConverter.ts +29 -29
- package/tests/fixtures/global.json +4 -4
- package/tests/fixtures/identity.json +10 -10
- package/tests/fixtures/transactions/evm-sign.json +4 -4
- package/tests/fixtures/transactions/multipayment-empty.json +4 -4
- package/tests/fixtures/transactions/multipayment-single.json +4 -4
- package/tests/fixtures/transactions/multipayment.json +4 -4
- package/tests/fixtures/transactions/transfer-0.json +4 -4
- package/tests/fixtures/transactions/transfer-large-amount.json +4 -4
- package/tests/fixtures/transactions/transfer.json +4 -4
- package/tests/fixtures/transactions/unvote.json +4 -4
- package/tests/fixtures/transactions/username-registration.json +4 -4
- package/tests/fixtures/transactions/username-resignation.json +4 -4
- package/tests/fixtures/transactions/validator-registration.json +4 -4
- package/tests/fixtures/transactions/validator-resignation.json +4 -4
- package/tests/fixtures/transactions/vote.json +4 -4
- package/tests/unit/configuration/Network.test.ts +52 -0
- package/tests/unit/identities/Address.test.ts +4 -4
- package/tests/unit/identities/PrivateKey.test.ts +5 -5
- package/tests/unit/identities/PublicKey.test.ts +9 -9
- package/tests/unit/identities/WIF.test.ts +1 -1
- package/tests/unit/transactions/Deserializer.test.ts +81 -63
- package/tests/unit/transactions/Serializer.test.ts +11 -1
- package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +76 -9
- package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +125 -17
- package/tests/unit/transactions/builders/TransferBuilder.test.ts +146 -47
- package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +79 -12
- package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +75 -8
- package/tests/unit/transactions/builders/VoteBuilder.test.ts +75 -8
- package/tests/unit/transactions/types/AbstractTransaction.test.ts +27 -30
- package/tests/unit/transactions/types/EvmCall.test.ts +22 -0
- package/tests/unit/transactions/types/Multipayment.test.ts +38 -0
- package/tests/unit/transactions/types/Transfer.test.ts +18 -0
- package/tests/unit/transactions/types/Unvote.test.ts +18 -0
- package/tests/unit/transactions/types/UsernameRegistration.test.ts +22 -0
- package/tests/unit/transactions/types/UsernameResignation.test.ts +18 -0
- package/tests/unit/transactions/types/ValidatorRegistration.test.ts +22 -0
- package/tests/unit/transactions/types/ValidatorResignation.test.ts +18 -0
- package/tests/unit/transactions/types/Vote.test.ts +20 -0
- package/tests/unit/utils/Abi/ArgumentDecoder.test.ts +17 -16
- package/tests/unit/utils/AbiEncoder.test.ts +2 -2
- package/tests/unit/utils/Message.test.ts +1 -1
- package/tests/unit/utils/TransactionUtils.test.ts +1 -5
- package/tests/unit/utils/UnitConverter.test.ts +81 -47
- package/tsconfig.json +1 -1
- package/.eslintrc.js +0 -12
- package/prettier.config.js +0 -8
@@ -5,7 +5,16 @@ import { Constants } from "@/enums/Constants";
|
|
5
5
|
import { ContractAbiType } from "@/enums/ContractAbiType";
|
6
6
|
import { Transfer } from "./types/Transfer";
|
7
7
|
import { decodeRlp } from "ethers";
|
8
|
-
import {
|
8
|
+
import {
|
9
|
+
EvmCall,
|
10
|
+
Multipayment,
|
11
|
+
Unvote,
|
12
|
+
UsernameRegistration,
|
13
|
+
UsernameResignation,
|
14
|
+
ValidatorRegistration,
|
15
|
+
ValidatorResignation,
|
16
|
+
Vote,
|
17
|
+
} from "./types";
|
9
18
|
import { AbiFunction } from "@/enums";
|
10
19
|
import { AbiDecoder } from "@/utils";
|
11
20
|
|
@@ -32,8 +41,8 @@ export class Deserializer {
|
|
32
41
|
network: Number(decodedRlp[0]),
|
33
42
|
nonce: Deserializer.parseNumber(decodedRlp[1] as string),
|
34
43
|
gasPrice: Deserializer.parseNumber(decodedRlp[3] as string).toString(),
|
35
|
-
|
36
|
-
|
44
|
+
gas: Deserializer.parseNumber(decodedRlp[4] as string).toString(),
|
45
|
+
to: Deserializer.parseAddress(decodedRlp[5] as string),
|
37
46
|
value: Deserializer.parseBigNumber(decodedRlp[6] as string),
|
38
47
|
data: Deserializer.parseHex(decodedRlp[7] as string),
|
39
48
|
};
|
@@ -49,12 +58,32 @@ export class Deserializer {
|
|
49
58
|
transaction.data = data;
|
50
59
|
transaction.recoverSender();
|
51
60
|
|
52
|
-
transaction.data["
|
61
|
+
transaction.data["hash"] = transaction.hash();
|
53
62
|
|
54
63
|
return transaction;
|
55
64
|
}
|
56
65
|
|
57
|
-
|
66
|
+
static decodePayload(
|
67
|
+
data: TransactionData,
|
68
|
+
abiType: ContractAbiType = ContractAbiType.CONSENSUS,
|
69
|
+
): AbiResult | null {
|
70
|
+
const payload = data.data;
|
71
|
+
|
72
|
+
if (!payload) {
|
73
|
+
return null;
|
74
|
+
}
|
75
|
+
|
76
|
+
const decoder = new AbiDecoder(abiType);
|
77
|
+
try {
|
78
|
+
return decoder.decodeFunctionData(payload);
|
79
|
+
} catch {
|
80
|
+
//
|
81
|
+
}
|
82
|
+
|
83
|
+
return null;
|
84
|
+
}
|
85
|
+
|
86
|
+
private guessTransactionFromData(data: TransactionData): ITransaction {
|
58
87
|
const multipaymentPayloadData = Deserializer.decodePayload(data, ContractAbiType.MULTIPAYMENT);
|
59
88
|
if (multipaymentPayloadData !== null) {
|
60
89
|
const functionName = multipaymentPayloadData.functionName;
|
@@ -99,42 +128,22 @@ export class Deserializer {
|
|
99
128
|
}
|
100
129
|
}
|
101
130
|
|
102
|
-
return new EvmCall(data)
|
103
|
-
}
|
104
|
-
|
105
|
-
static decodePayload(
|
106
|
-
data: TransactionData,
|
107
|
-
abiType: ContractAbiType = ContractAbiType.CONSENSUS,
|
108
|
-
): AbiResult | null {
|
109
|
-
const payload = data.data;
|
110
|
-
|
111
|
-
if (! payload) {
|
112
|
-
return null;
|
113
|
-
}
|
114
|
-
|
115
|
-
const decoder = new AbiDecoder(abiType);
|
116
|
-
try {
|
117
|
-
return decoder.decodeFunctionData(payload);
|
118
|
-
} catch (e) {
|
119
|
-
//
|
120
|
-
}
|
121
|
-
|
122
|
-
return null;
|
131
|
+
return new EvmCall(data);
|
123
132
|
}
|
124
133
|
|
125
|
-
static parseNumber(value: string): number {
|
134
|
+
private static parseNumber(value: string): number {
|
126
135
|
return value === "0x" ? 0 : Number(value);
|
127
136
|
}
|
128
137
|
|
129
|
-
static parseBigNumber(value: string): string {
|
138
|
+
private static parseBigNumber(value: string): string {
|
130
139
|
return (value === "0x" ? new BigNumber(0) : new BigNumber(value)).toString(10);
|
131
140
|
}
|
132
141
|
|
133
|
-
static parseAddress(value: string): string | undefined {
|
142
|
+
private static parseAddress(value: string): string | undefined {
|
134
143
|
return value === "0x" ? undefined : value;
|
135
144
|
}
|
136
145
|
|
137
|
-
static parseHex(value: string): string {
|
146
|
+
private static parseHex(value: string): string {
|
138
147
|
return value.replace(/^0x/, "");
|
139
148
|
}
|
140
149
|
}
|
@@ -12,11 +12,7 @@ export class Serializer {
|
|
12
12
|
return new this(transaction);
|
13
13
|
}
|
14
14
|
|
15
|
-
|
16
|
-
return transaction.serialize(skipSignature);
|
17
|
-
}
|
18
|
-
|
19
|
-
serialize(skipSignature: boolean = false): Buffer {
|
15
|
+
serialize(skipSignature = false): Buffer {
|
20
16
|
this.transaction.serialized = TransactionUtils.toBuffer(this.transaction.data, skipSignature);
|
21
17
|
|
22
18
|
return this.transaction.serialized;
|
@@ -3,11 +3,12 @@ import { ITransaction, ITransactionBuilder, TransactionData } from "@/types";
|
|
3
3
|
import { Network } from "@/configuration/Network";
|
4
4
|
import { PrivateKey } from "@/identities/PrivateKey";
|
5
5
|
import { PublicKey } from "@/identities/PublicKey";
|
6
|
+
import BigNumber from "bignumber.js";
|
6
7
|
|
7
8
|
export abstract class AbstractTransactionBuilder<T extends ITransactionBuilder<T>> implements ITransactionBuilder<T> {
|
8
9
|
public transaction: ITransaction;
|
9
10
|
|
10
|
-
constructor(data?: Record<string,
|
11
|
+
constructor(data?: Record<string, unknown>) {
|
11
12
|
this.transaction = this.getTransactionInstance(
|
12
13
|
data ?? {
|
13
14
|
value: "0",
|
@@ -15,25 +16,33 @@ export abstract class AbstractTransactionBuilder<T extends ITransactionBuilder<T
|
|
15
16
|
gasPrice: "5",
|
16
17
|
nonce: "1",
|
17
18
|
network: Network.get().chainId(),
|
18
|
-
|
19
|
+
gas: 1_000_000,
|
19
20
|
data: "",
|
20
21
|
},
|
21
22
|
);
|
22
23
|
}
|
23
24
|
|
24
|
-
public
|
25
|
-
|
25
|
+
public gas(gas: string | BigNumber): T {
|
26
|
+
if (gas instanceof BigNumber) {
|
27
|
+
gas = gas.toFixed();
|
28
|
+
}
|
29
|
+
|
30
|
+
this.transaction.data.gas = gas;
|
26
31
|
|
27
32
|
return this as unknown as T;
|
28
33
|
}
|
29
34
|
|
30
|
-
public
|
31
|
-
this.transaction.data.
|
35
|
+
public to(to: string): T {
|
36
|
+
this.transaction.data.to = to;
|
32
37
|
|
33
38
|
return this as unknown as T;
|
34
39
|
}
|
35
40
|
|
36
|
-
public gasPrice(gasPrice: string): T {
|
41
|
+
public gasPrice(gasPrice: string | BigNumber): T {
|
42
|
+
if (gasPrice instanceof BigNumber) {
|
43
|
+
gasPrice = gasPrice.toFixed();
|
44
|
+
}
|
45
|
+
|
37
46
|
this.transaction.data.gasPrice = gasPrice;
|
38
47
|
|
39
48
|
return this as unknown as T;
|
@@ -56,7 +65,7 @@ export abstract class AbstractTransactionBuilder<T extends ITransactionBuilder<T
|
|
56
65
|
|
57
66
|
this.transaction = await this.transaction.sign(PrivateKey.fromPassphrase(passphrase));
|
58
67
|
|
59
|
-
this.transaction.data.
|
68
|
+
this.transaction.data.hash = this.transaction.hash();
|
60
69
|
|
61
70
|
return this as unknown as T;
|
62
71
|
}
|
@@ -65,8 +74,8 @@ export abstract class AbstractTransactionBuilder<T extends ITransactionBuilder<T
|
|
65
74
|
return this.transaction.verify();
|
66
75
|
}
|
67
76
|
|
68
|
-
public
|
69
|
-
return this.transaction.
|
77
|
+
public toObject(): TransactionData {
|
78
|
+
return this.transaction.toObject();
|
70
79
|
}
|
71
80
|
|
72
81
|
public toJson(): string {
|
@@ -77,5 +86,5 @@ export abstract class AbstractTransactionBuilder<T extends ITransactionBuilder<T
|
|
77
86
|
return this.toJson();
|
78
87
|
}
|
79
88
|
|
80
|
-
protected abstract getTransactionInstance(data?: Record<string,
|
89
|
+
protected abstract getTransactionInstance(data?: Record<string, unknown>): ITransaction;
|
81
90
|
}
|
@@ -5,11 +5,11 @@ import { EvmCall } from "@/transactions/types/EvmCall";
|
|
5
5
|
import { Helpers } from "@/utils/Helpers";
|
6
6
|
|
7
7
|
export class EvmCallBuilder extends AbstractTransactionBuilder<IEvmCallBuilder> implements IEvmCallBuilder {
|
8
|
-
public constructor(data?: Record<string,
|
8
|
+
public constructor(data?: Record<string, unknown>) {
|
9
9
|
super(data);
|
10
10
|
}
|
11
11
|
|
12
|
-
public static new(data?: Record<string,
|
12
|
+
public static new(data?: Record<string, unknown>): IEvmCallBuilder {
|
13
13
|
return new this(data);
|
14
14
|
}
|
15
15
|
|
@@ -18,7 +18,7 @@ export class EvmCallBuilder extends AbstractTransactionBuilder<IEvmCallBuilder>
|
|
18
18
|
return this;
|
19
19
|
}
|
20
20
|
|
21
|
-
protected getTransactionInstance(data?: Record<string,
|
21
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
22
22
|
return new EvmCall(data as TransactionData);
|
23
23
|
}
|
24
24
|
}
|
@@ -3,25 +3,32 @@ import { IMultipaymentBuilder, ITransaction, TransactionData } from "@/types";
|
|
3
3
|
import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
|
4
4
|
import { ContractAddresses } from "@/enums/ContractAddresses";
|
5
5
|
import { Multipayment } from "@/transactions/types/Multipayment";
|
6
|
+
import BigNumber from "bignumber.js";
|
6
7
|
|
7
8
|
export class MultipaymentBuilder
|
8
9
|
extends AbstractTransactionBuilder<IMultipaymentBuilder>
|
9
10
|
implements IMultipaymentBuilder
|
10
11
|
{
|
11
|
-
public constructor(data?: Record<string,
|
12
|
+
public constructor(data?: Record<string, unknown>) {
|
12
13
|
super(data);
|
13
14
|
|
14
|
-
this.
|
15
|
+
this.to(ContractAddresses.MULTIPAYMENT);
|
15
16
|
}
|
16
17
|
|
17
|
-
public static new(data?: Record<string,
|
18
|
+
public static new(data?: Record<string, unknown>): IMultipaymentBuilder {
|
18
19
|
return new this(data);
|
19
20
|
}
|
20
21
|
|
21
|
-
public pay(address: string, amount: string): IMultipaymentBuilder {
|
22
|
-
|
22
|
+
public pay(address: string, amount: string | BigNumber): IMultipaymentBuilder {
|
23
|
+
const payload: [string[], string[]] = this.transaction.data["pay"] as [string[], string[]];
|
23
24
|
payload[0].push(address);
|
25
|
+
|
26
|
+
if (amount instanceof BigNumber) {
|
27
|
+
amount = amount.toFixed();
|
28
|
+
}
|
29
|
+
|
24
30
|
payload[1].push(amount);
|
31
|
+
|
25
32
|
this.transaction.data.pay = payload;
|
26
33
|
|
27
34
|
this.transaction.data.value = (BigInt(this.transaction.data.value ?? 0) + BigInt(amount)).toString();
|
@@ -31,7 +38,7 @@ export class MultipaymentBuilder
|
|
31
38
|
return this;
|
32
39
|
}
|
33
40
|
|
34
|
-
protected getTransactionInstance(data?: Record<string,
|
41
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
35
42
|
return new Multipayment(data as TransactionData);
|
36
43
|
}
|
37
44
|
}
|
@@ -2,13 +2,18 @@ import { ITransaction, ITransferBuilder, TransactionData } from "@/types";
|
|
2
2
|
|
3
3
|
import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
|
4
4
|
import { Transfer } from "@/transactions/types/Transfer";
|
5
|
+
import BigNumber from "bignumber.js";
|
5
6
|
|
6
7
|
export class TransferBuilder extends AbstractTransactionBuilder<ITransferBuilder> implements ITransferBuilder {
|
7
|
-
public static new(data?: Record<string,
|
8
|
+
public static new(data?: Record<string, unknown>): ITransferBuilder {
|
8
9
|
return new this(data);
|
9
10
|
}
|
10
11
|
|
11
|
-
public value(value: string): ITransferBuilder {
|
12
|
+
public value(value: string | BigNumber): ITransferBuilder {
|
13
|
+
if (value instanceof BigNumber) {
|
14
|
+
value = value.toFixed();
|
15
|
+
}
|
16
|
+
|
12
17
|
this.transaction.data.value = value;
|
13
18
|
|
14
19
|
this.transaction.refreshPayloadData();
|
@@ -16,7 +21,7 @@ export class TransferBuilder extends AbstractTransactionBuilder<ITransferBuilder
|
|
16
21
|
return this;
|
17
22
|
}
|
18
23
|
|
19
|
-
protected getTransactionInstance(data?: Record<string,
|
24
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
20
25
|
return new Transfer(data as TransactionData);
|
21
26
|
}
|
22
27
|
}
|
@@ -5,17 +5,17 @@ import { ContractAddresses } from "@/enums/ContractAddresses";
|
|
5
5
|
import { Unvote } from "@/transactions/types/Unvote";
|
6
6
|
|
7
7
|
export class UnvoteBuilder extends AbstractTransactionBuilder<IBasicTransactionBuilder> {
|
8
|
-
public constructor(data?: Record<string,
|
8
|
+
public constructor(data?: Record<string, unknown>) {
|
9
9
|
super(data);
|
10
10
|
|
11
|
-
this.
|
11
|
+
this.to(ContractAddresses.CONSENSUS);
|
12
12
|
}
|
13
13
|
|
14
|
-
public static new(data?: Record<string,
|
14
|
+
public static new(data?: Record<string, unknown>): IBasicTransactionBuilder {
|
15
15
|
return new this(data);
|
16
16
|
}
|
17
17
|
|
18
|
-
protected getTransactionInstance(data?: Record<string,
|
18
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
19
19
|
return new Unvote(data as TransactionData);
|
20
20
|
}
|
21
21
|
}
|
@@ -9,13 +9,13 @@ export class UsernameRegistrationBuilder
|
|
9
9
|
extends AbstractTransactionBuilder<IUsernameRegistrationBuilder>
|
10
10
|
implements IUsernameRegistrationBuilder
|
11
11
|
{
|
12
|
-
public constructor(data?: Record<string,
|
12
|
+
public constructor(data?: Record<string, unknown>) {
|
13
13
|
super(data);
|
14
14
|
|
15
|
-
this.
|
15
|
+
this.to(ContractAddresses.USERNAMES);
|
16
16
|
}
|
17
17
|
|
18
|
-
public static new(data?: Record<string,
|
18
|
+
public static new(data?: Record<string, unknown>): IUsernameRegistrationBuilder {
|
19
19
|
return new this(data);
|
20
20
|
}
|
21
21
|
|
@@ -29,7 +29,7 @@ export class UsernameRegistrationBuilder
|
|
29
29
|
return this;
|
30
30
|
}
|
31
31
|
|
32
|
-
protected getTransactionInstance(data?: Record<string,
|
32
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
33
33
|
return new UsernameRegistration(data as TransactionData);
|
34
34
|
}
|
35
35
|
}
|
@@ -5,17 +5,17 @@ import { ContractAddresses } from "@/enums/ContractAddresses";
|
|
5
5
|
import { UsernameResignation } from "@/transactions/types/UsernameResignation";
|
6
6
|
|
7
7
|
export class UsernameResignationBuilder extends AbstractTransactionBuilder<IBasicTransactionBuilder> {
|
8
|
-
public constructor(data?: Record<string,
|
8
|
+
public constructor(data?: Record<string, unknown>) {
|
9
9
|
super(data);
|
10
10
|
|
11
|
-
this.
|
11
|
+
this.to(ContractAddresses.USERNAMES);
|
12
12
|
}
|
13
13
|
|
14
|
-
public static new(data?: Record<string,
|
14
|
+
public static new(data?: Record<string, unknown>): IBasicTransactionBuilder {
|
15
15
|
return new this(data);
|
16
16
|
}
|
17
17
|
|
18
|
-
protected getTransactionInstance(data?: Record<string,
|
18
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
19
19
|
return new UsernameResignation(data as TransactionData);
|
20
20
|
}
|
21
21
|
}
|
@@ -9,13 +9,13 @@ export class ValidatorRegistrationBuilder
|
|
9
9
|
extends AbstractTransactionBuilder<IValidatorRegistrationBuilder>
|
10
10
|
implements IValidatorRegistrationBuilder
|
11
11
|
{
|
12
|
-
public constructor(data?: Record<string,
|
12
|
+
public constructor(data?: Record<string, unknown>) {
|
13
13
|
super(data);
|
14
14
|
|
15
|
-
this.
|
15
|
+
this.to(ContractAddresses.CONSENSUS);
|
16
16
|
}
|
17
17
|
|
18
|
-
public static new(data?: Record<string,
|
18
|
+
public static new(data?: Record<string, unknown>): IValidatorRegistrationBuilder {
|
19
19
|
return new this(data);
|
20
20
|
}
|
21
21
|
|
@@ -29,7 +29,7 @@ export class ValidatorRegistrationBuilder
|
|
29
29
|
return this;
|
30
30
|
}
|
31
31
|
|
32
|
-
protected getTransactionInstance(data?: Record<string,
|
32
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
33
33
|
return new ValidatorRegistration(data as TransactionData);
|
34
34
|
}
|
35
35
|
}
|
@@ -5,17 +5,17 @@ import { ContractAddresses } from "@/enums/ContractAddresses";
|
|
5
5
|
import { ValidatorResignation } from "@/transactions/types/ValidatorResignation";
|
6
6
|
|
7
7
|
export class ValidatorResignationBuilder extends AbstractTransactionBuilder<IBasicTransactionBuilder> {
|
8
|
-
public constructor(data?: Record<string,
|
8
|
+
public constructor(data?: Record<string, unknown>) {
|
9
9
|
super(data);
|
10
10
|
|
11
|
-
this.
|
11
|
+
this.to(ContractAddresses.CONSENSUS);
|
12
12
|
}
|
13
13
|
|
14
|
-
public static new(data?: Record<string,
|
14
|
+
public static new(data?: Record<string, unknown>): IBasicTransactionBuilder {
|
15
15
|
return new this(data);
|
16
16
|
}
|
17
17
|
|
18
|
-
protected getTransactionInstance(data?: Record<string,
|
18
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
19
19
|
return new ValidatorResignation(data as TransactionData);
|
20
20
|
}
|
21
21
|
}
|
@@ -5,13 +5,13 @@ import { ContractAddresses } from "@/enums/ContractAddresses";
|
|
5
5
|
import { Vote } from "@/transactions/types/Vote";
|
6
6
|
|
7
7
|
export class VoteBuilder extends AbstractTransactionBuilder<IVoteBuilder> implements IVoteBuilder {
|
8
|
-
public constructor(data?: Record<string,
|
8
|
+
public constructor(data?: Record<string, unknown>) {
|
9
9
|
super(data);
|
10
10
|
|
11
|
-
this.
|
11
|
+
this.to(ContractAddresses.CONSENSUS);
|
12
12
|
}
|
13
13
|
|
14
|
-
public static new(data?: Record<string,
|
14
|
+
public static new(data?: Record<string, unknown>): IVoteBuilder {
|
15
15
|
return new this(data);
|
16
16
|
}
|
17
17
|
|
@@ -23,7 +23,7 @@ export class VoteBuilder extends AbstractTransactionBuilder<IVoteBuilder> implem
|
|
23
23
|
return this;
|
24
24
|
}
|
25
25
|
|
26
|
-
protected getTransactionInstance(data?: Record<string,
|
26
|
+
protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
|
27
27
|
return new Vote(data as TransactionData);
|
28
28
|
}
|
29
29
|
}
|
@@ -1,13 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import { ITransaction, TransactionData } from "@/types";
|
2
2
|
|
3
3
|
import { Address } from "@/identities/Address";
|
4
4
|
import { Constants } from "@/enums/Constants";
|
5
|
-
import { ContractAbiType } from "@/enums/ContractAbiType";
|
6
|
-
import { Network } from "@/configuration/Network";
|
7
5
|
import { PrivateKey } from "@/identities/PrivateKey";
|
8
6
|
import { PublicKey } from "@/identities/PublicKey";
|
9
7
|
import { Serializer } from "@/transactions/Serializer";
|
10
8
|
import { TransactionUtils } from "@/utils/TransactionUtils";
|
9
|
+
import BigNumber from "bignumber.js";
|
11
10
|
|
12
11
|
export abstract class AbstractTransaction implements ITransaction {
|
13
12
|
public data: TransactionData;
|
@@ -27,10 +26,6 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
27
26
|
return this;
|
28
27
|
}
|
29
28
|
|
30
|
-
public getId(): string {
|
31
|
-
return TransactionUtils.getId(this.data);
|
32
|
-
}
|
33
|
-
|
34
29
|
public async sign(privateKey: PrivateKey): Promise<ITransaction> {
|
35
30
|
const hash = TransactionUtils.toBuffer(this.data, true).toString("hex");
|
36
31
|
|
@@ -47,7 +42,7 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
47
42
|
const publicKey = this.recoverPublicKey();
|
48
43
|
|
49
44
|
this.data["senderPublicKey"] = publicKey.publicKey;
|
50
|
-
this.data["
|
45
|
+
this.data["from"] = Address.fromPublicKey(publicKey.publicKey);
|
51
46
|
}
|
52
47
|
|
53
48
|
public verify(): boolean {
|
@@ -61,23 +56,28 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
61
56
|
return recoveredPublicKey.publicKey === senderPublicKey;
|
62
57
|
}
|
63
58
|
|
64
|
-
public
|
59
|
+
public toObject(): TransactionData {
|
65
60
|
return [
|
66
61
|
"gasPrice",
|
67
62
|
"network",
|
68
|
-
"
|
69
|
-
"
|
63
|
+
"hash",
|
64
|
+
"gas",
|
70
65
|
"nonce",
|
71
66
|
"senderPublicKey",
|
72
|
-
"
|
67
|
+
"to",
|
73
68
|
"value",
|
74
69
|
"data",
|
75
70
|
"r",
|
76
71
|
"s",
|
77
72
|
"v",
|
78
73
|
].reduce((acc: TransactionData, key) => {
|
79
|
-
|
80
|
-
|
74
|
+
let value = this.data[key];
|
75
|
+
if (typeof value === "bigint") {
|
76
|
+
value = BigNumber(value).toFixed();
|
77
|
+
}
|
78
|
+
|
79
|
+
if (value !== undefined) {
|
80
|
+
acc[key] = value;
|
81
81
|
}
|
82
82
|
|
83
83
|
return acc;
|
@@ -85,14 +85,14 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
85
85
|
}
|
86
86
|
|
87
87
|
public toJson(): string {
|
88
|
-
return JSON.stringify(this.
|
88
|
+
return JSON.stringify(this.toObject());
|
89
89
|
}
|
90
90
|
|
91
|
-
public hash(skipSignature
|
91
|
+
public hash(skipSignature = false): string {
|
92
92
|
return TransactionUtils.toHash(this.data, skipSignature);
|
93
93
|
}
|
94
94
|
|
95
|
-
public serialize(skipSignature
|
95
|
+
public serialize(skipSignature = false): Buffer {
|
96
96
|
return Serializer.new(this).serialize(skipSignature);
|
97
97
|
}
|
98
98
|
|
@@ -108,11 +108,4 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
108
108
|
this.data.v - Constants.ETHEREUM_RECOVERY_ID_OFFSET,
|
109
109
|
);
|
110
110
|
}
|
111
|
-
|
112
|
-
protected decodePayload(
|
113
|
-
data: TransactionData,
|
114
|
-
type: ContractAbiType = ContractAbiType.CONSENSUS,
|
115
|
-
): AbiResult | null {
|
116
|
-
throw new Error("Method not implemented.");
|
117
|
-
}
|
118
111
|
}
|
@@ -1,22 +1,7 @@
|
|
1
|
-
import { AbiResult, TransactionData } from "@/types";
|
2
|
-
|
3
1
|
import { AbstractTransaction } from "./AbstractTransaction";
|
4
|
-
import { ContractAbiType } from "@/enums/ContractAbiType";
|
5
|
-
import { Deserializer } from "@/transactions/Deserializer";
|
6
2
|
|
7
3
|
export class EvmCall extends AbstractTransaction {
|
8
4
|
getPayload(): string {
|
9
5
|
return this.data["data"] || "";
|
10
6
|
}
|
11
|
-
|
12
|
-
protected decodePayload(
|
13
|
-
data: TransactionData,
|
14
|
-
type: ContractAbiType = ContractAbiType.CONSENSUS,
|
15
|
-
): AbiResult | null {
|
16
|
-
if (!data["data"]) {
|
17
|
-
return null;
|
18
|
-
}
|
19
|
-
|
20
|
-
return Deserializer.decodePayload(data, type);
|
21
|
-
}
|
22
7
|
}
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import { TransactionData } from "@/types";
|
2
2
|
|
3
3
|
import { AbiDecoder } from "@/utils/AbiDecoder";
|
4
4
|
import { AbiEncoder } from "@/utils/AbiEncoder";
|
5
5
|
import { AbiFunction } from "@/enums/AbiFunction";
|
6
6
|
import { AbstractTransaction } from "./AbstractTransaction";
|
7
7
|
import { ContractAbiType } from "@/enums/ContractAbiType";
|
8
|
-
import { Deserializer } from "@/transactions/Deserializer";
|
9
8
|
|
10
9
|
export class Multipayment extends AbstractTransaction {
|
11
10
|
public constructor(data: TransactionData) {
|
@@ -28,24 +27,13 @@ export class Multipayment extends AbstractTransaction {
|
|
28
27
|
}
|
29
28
|
|
30
29
|
getPayload(): string {
|
31
|
-
if (!this.data["pay"]) {
|
30
|
+
if (!this.data["pay"] || (Array.isArray(this.data["pay"]) && this.data["pay"].length === 0)) {
|
32
31
|
return "";
|
33
32
|
}
|
34
33
|
|
35
34
|
return new AbiEncoder(ContractAbiType.MULTIPAYMENT).encodeFunctionCall(
|
36
35
|
AbiFunction.MULTIPAYMENT,
|
37
|
-
this.data["pay"] as
|
36
|
+
this.data["pay"] as unknown[],
|
38
37
|
);
|
39
38
|
}
|
40
|
-
|
41
|
-
protected decodePayload(
|
42
|
-
data: TransactionData,
|
43
|
-
type: ContractAbiType = ContractAbiType.CONSENSUS,
|
44
|
-
): AbiResult | null {
|
45
|
-
if (!data["data"]) {
|
46
|
-
return null;
|
47
|
-
}
|
48
|
-
|
49
|
-
return Deserializer.decodePayload(data, ContractAbiType.MULTIPAYMENT);
|
50
|
-
}
|
51
39
|
}
|
@@ -1,22 +1,7 @@
|
|
1
|
-
import { AbiResult, TransactionData } from "@/types";
|
2
|
-
|
3
1
|
import { AbstractTransaction } from "./AbstractTransaction";
|
4
|
-
import { ContractAbiType } from "@/enums/ContractAbiType";
|
5
|
-
import { Deserializer } from "@/transactions/Deserializer";
|
6
2
|
|
7
3
|
export class Transfer extends AbstractTransaction {
|
8
4
|
getPayload(): string {
|
9
5
|
return "";
|
10
6
|
}
|
11
|
-
|
12
|
-
protected decodePayload(
|
13
|
-
data: TransactionData,
|
14
|
-
type: ContractAbiType = ContractAbiType.CONSENSUS,
|
15
|
-
): AbiResult | null {
|
16
|
-
if (!data["data"]) {
|
17
|
-
return null;
|
18
|
-
}
|
19
|
-
|
20
|
-
return Deserializer.decodePayload(data, type);
|
21
|
-
}
|
22
7
|
}
|
@@ -1,24 +1,9 @@
|
|
1
|
-
import { AbiResult, TransactionData } from "@/types";
|
2
|
-
|
3
1
|
import { AbiEncoder } from "@/utils/AbiEncoder";
|
4
2
|
import { AbiFunction } from "@/enums/AbiFunction";
|
5
3
|
import { AbstractTransaction } from "./AbstractTransaction";
|
6
|
-
import { ContractAbiType } from "@/enums/ContractAbiType";
|
7
|
-
import { Deserializer } from "@/transactions/Deserializer";
|
8
4
|
|
9
5
|
export class Unvote extends AbstractTransaction {
|
10
6
|
getPayload(): string {
|
11
7
|
return new AbiEncoder().encodeFunctionCall(AbiFunction.UNVOTE, []);
|
12
8
|
}
|
13
|
-
|
14
|
-
protected decodePayload(
|
15
|
-
data: TransactionData,
|
16
|
-
type: ContractAbiType = ContractAbiType.CONSENSUS,
|
17
|
-
): AbiResult | null {
|
18
|
-
if (!data["data"]) {
|
19
|
-
return null;
|
20
|
-
}
|
21
|
-
|
22
|
-
return Deserializer.decodePayload(data, type);
|
23
|
-
}
|
24
9
|
}
|