@arkecosystem/typescript-crypto 0.0.3 → 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 -626
- 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 +4 -2
- 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 +8 -5
- 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 +103 -8
- 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
@@ -2,31 +2,31 @@ import fixtureIdentity from "@tests/fixtures/identity.json";
|
|
2
2
|
import fixtureSignCompact from "@tests/fixtures/sign-compact.json";
|
3
3
|
import { PrivateKey } from "@/identities/PrivateKey";
|
4
4
|
|
5
|
-
it(
|
5
|
+
it("should parse the private key from passphrase", () => {
|
6
6
|
const actual = PrivateKey.fromPassphrase(fixtureIdentity.passphrase);
|
7
7
|
|
8
8
|
expect(actual.privateKey).toEqual(fixtureIdentity.data.privateKey);
|
9
9
|
});
|
10
10
|
|
11
|
-
it(
|
11
|
+
it("should parse the private key from hex", () => {
|
12
12
|
const actual = PrivateKey.fromHex(fixtureIdentity.data.privateKey);
|
13
13
|
|
14
14
|
expect(actual.privateKey).toEqual(fixtureIdentity.data.privateKey);
|
15
15
|
});
|
16
16
|
|
17
|
-
it(
|
17
|
+
it("should parse the private key from wif", () => {
|
18
18
|
const actual = PrivateKey.fromWif(fixtureIdentity.data.wif);
|
19
19
|
|
20
20
|
expect(actual.privateKey).toEqual(fixtureIdentity.data.privateKey);
|
21
21
|
});
|
22
22
|
|
23
|
-
it(
|
23
|
+
it("should parse the private key from wif", () => {
|
24
24
|
const actual = PrivateKey.fromWif(fixtureIdentity.data.wif);
|
25
25
|
|
26
26
|
expect(actual.privateKey).toEqual(fixtureIdentity.data.privateKey);
|
27
27
|
});
|
28
28
|
|
29
|
-
it(
|
29
|
+
it("should sign compact correctly", async () => {
|
30
30
|
const privateKey = PrivateKey.fromPassphrase(fixtureSignCompact.passphrase);
|
31
31
|
const signature = await privateKey.sign(fixtureSignCompact.data.message);
|
32
32
|
|
@@ -4,36 +4,36 @@ import fixtureTransaction from "@tests/fixtures/transactions/transfer.json";
|
|
4
4
|
import { PublicKey } from "@/identities/PublicKey";
|
5
5
|
import { TransactionUtils } from "@/utils/TransactionUtils";
|
6
6
|
|
7
|
-
it(
|
7
|
+
it("should get the address from passphrase", () => {
|
8
8
|
const actual = PublicKey.fromPassphrase(fixture.passphrase);
|
9
9
|
|
10
10
|
expect(actual.publicKey).toEqual(fixture.data.publicKey);
|
11
11
|
});
|
12
12
|
|
13
|
-
it(
|
13
|
+
it("should get the address from hex", () => {
|
14
14
|
const actual = PublicKey.fromHex(fixture.data.publicKey);
|
15
15
|
|
16
16
|
expect(actual.publicKey).toEqual(fixture.data.publicKey);
|
17
17
|
});
|
18
18
|
|
19
|
-
it(
|
19
|
+
it("should recover a public key", () => {
|
20
20
|
const hash = TransactionUtils.toHash(fixtureTransaction.data, true);
|
21
21
|
const v = fixtureTransaction.data.v - 27;
|
22
22
|
const r = BigInt(`0x${fixtureTransaction.data.r}`);
|
23
23
|
const s = BigInt(`0x${fixtureTransaction.data.s}`);
|
24
24
|
|
25
|
-
const actual = PublicKey.recover(Buffer.from(hash,
|
25
|
+
const actual = PublicKey.recover(Buffer.from(hash, "hex"), r, s, v);
|
26
26
|
|
27
27
|
expect(actual.publicKey).toEqual(fixture.data.publicKey);
|
28
28
|
});
|
29
29
|
|
30
|
-
it(
|
30
|
+
it("should throw error with invalid recovery id", () => {
|
31
31
|
const hash = TransactionUtils.toHash(fixtureTransaction.data, true);
|
32
32
|
const r = BigInt(`0x${fixtureTransaction.data.r}`);
|
33
33
|
const s = BigInt(`0x${fixtureTransaction.data.s}`);
|
34
34
|
|
35
|
-
expect(() => PublicKey.recover(Buffer.from(hash,
|
36
|
-
expect(() => PublicKey.recover(Buffer.from(hash,
|
37
|
-
expect(() => PublicKey.recover(Buffer.from(hash,
|
38
|
-
expect(() => PublicKey.recover(Buffer.from(hash,
|
35
|
+
expect(() => PublicKey.recover(Buffer.from(hash, "hex"), r, s, 4)).toThrow("recovery id invalid");
|
36
|
+
expect(() => PublicKey.recover(Buffer.from(hash, "hex"), r, s, 5)).toThrow("recovery id invalid");
|
37
|
+
expect(() => PublicKey.recover(Buffer.from(hash, "hex"), r, s, 26)).toThrow("recovery id invalid");
|
38
|
+
expect(() => PublicKey.recover(Buffer.from(hash, "hex"), r, s, 27)).toThrow("recovery id invalid");
|
39
39
|
});
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import fixture from "@tests/fixtures/identity.json";
|
2
2
|
import { WIF } from "@/identities/WIF";
|
3
3
|
|
4
|
-
it(
|
4
|
+
it("it should get the wif from passphrase", () => {
|
5
5
|
const actual = WIF.fromPassphrase(fixture.passphrase);
|
6
6
|
|
7
7
|
expect(actual).toEqual(fixture.data.wif);
|
@@ -1,138 +1,156 @@
|
|
1
1
|
import { Deserializer } from "@/transactions/Deserializer";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
EvmCall,
|
4
|
+
Multipayment,
|
5
|
+
Unvote,
|
6
|
+
UsernameRegistration,
|
7
|
+
UsernameResignation,
|
8
|
+
ValidatorRegistration,
|
9
|
+
ValidatorResignation,
|
10
|
+
Vote,
|
11
|
+
} from "@/transactions/types";
|
3
12
|
import { Transfer } from "@/transactions/types/Transfer";
|
4
13
|
import fixtureTransfer from "@tests/fixtures/transactions/transfer.json";
|
5
14
|
|
6
15
|
function assertDeserialized(fixture: any, keys: string[]) {
|
7
|
-
|
8
|
-
|
9
|
-
|
16
|
+
const deserializer = Deserializer.new(fixture["serialized"]);
|
17
|
+
const transaction = deserializer.deserialize();
|
18
|
+
for (const key in keys) {
|
10
19
|
try {
|
11
|
-
expect(transaction.data[key]).toEqual(fixture[
|
20
|
+
expect(transaction.data[key]).toEqual(fixture["data"][key]);
|
12
21
|
} catch (e) {
|
13
|
-
console.log(`Mismatch in ${key}`)
|
22
|
+
console.log(`Mismatch in ${key}`);
|
14
23
|
|
15
|
-
throw e
|
24
|
+
throw e;
|
16
25
|
}
|
17
26
|
}
|
18
27
|
|
19
|
-
|
20
|
-
|
28
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture["serialized"]);
|
29
|
+
expect(transaction.verify()).toBe(true);
|
21
30
|
|
22
|
-
|
31
|
+
return transaction;
|
23
32
|
}
|
24
33
|
|
25
34
|
const getFixture = async (name: string) => {
|
26
35
|
return (await import(`@tests/fixtures/transactions/${name}.json`)).default;
|
27
36
|
};
|
28
37
|
|
29
|
-
it(
|
30
|
-
|
38
|
+
it("should deserialize transfer", () => {
|
39
|
+
const transaction = assertDeserialized(fixtureTransfer, [
|
40
|
+
"hash",
|
41
|
+
"nonce",
|
42
|
+
"gasPrice",
|
43
|
+
"gas",
|
44
|
+
"value",
|
45
|
+
"v",
|
46
|
+
"r",
|
47
|
+
"s",
|
48
|
+
]);
|
31
49
|
|
32
|
-
|
33
|
-
|
50
|
+
expect(transaction).toBeInstanceOf(Transfer);
|
51
|
+
expect(transaction.data["value"]).toEqual("100000000");
|
34
52
|
});
|
35
53
|
|
36
|
-
it(
|
37
|
-
const fixture = await getFixture(
|
54
|
+
it("should deserialize a transfer signed with a passphrase", async () => {
|
55
|
+
const fixture = await getFixture("transfer");
|
38
56
|
|
39
|
-
const transaction = assertDeserialized(fixture, [
|
57
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
40
58
|
|
41
59
|
expect(transaction).toBeInstanceOf(Transfer);
|
42
60
|
});
|
43
61
|
|
44
|
-
it(
|
45
|
-
const fixture = await getFixture(
|
62
|
+
it("should deserialize a transfer signed with a passphrase with 0 value", async () => {
|
63
|
+
const fixture = await getFixture("transfer-0");
|
46
64
|
|
47
|
-
const transaction = assertDeserialized(fixture, [
|
65
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
48
66
|
|
49
67
|
expect(transaction).toBeInstanceOf(EvmCall);
|
50
68
|
});
|
51
69
|
|
52
|
-
it(
|
53
|
-
const fixture = await getFixture(
|
70
|
+
it("should deserialize a vote signed with a passphrase", async () => {
|
71
|
+
const fixture = await getFixture("vote");
|
54
72
|
|
55
|
-
const transaction = assertDeserialized(fixture, [
|
73
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
56
74
|
|
57
|
-
expect(transaction.data[
|
75
|
+
expect(transaction.data["vote"]).toEqual("0xC3bBE9B1CeE1ff85Ad72b87414B0E9B7F2366763");
|
58
76
|
|
59
|
-
expect(transaction.data[
|
77
|
+
expect(transaction.data["hash"]).toEqual(fixture["data"]["hash"]);
|
60
78
|
|
61
79
|
expect(transaction).toBeInstanceOf(Vote);
|
62
80
|
});
|
63
81
|
|
64
|
-
it(
|
65
|
-
const fixture = await getFixture(
|
82
|
+
it("should deserialize a unvote signed with a passphrase", async () => {
|
83
|
+
const fixture = await getFixture("unvote");
|
66
84
|
|
67
|
-
const transaction = assertDeserialized(fixture, [
|
85
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
68
86
|
|
69
87
|
expect(transaction).toBeInstanceOf(Unvote);
|
70
88
|
});
|
71
89
|
|
72
|
-
it(
|
73
|
-
const fixture = await getFixture(
|
90
|
+
it("should deserialize a validator registration signed with a passphrase", async () => {
|
91
|
+
const fixture = await getFixture("validator-registration");
|
74
92
|
|
75
|
-
const transaction = assertDeserialized(fixture, [
|
93
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
76
94
|
|
77
95
|
expect(transaction).toBeInstanceOf(ValidatorRegistration);
|
78
96
|
});
|
79
97
|
|
80
|
-
it(
|
81
|
-
const fixture = await getFixture(
|
98
|
+
it("should deserialize a validator resignation signed with a passphrase", async () => {
|
99
|
+
const fixture = await getFixture("validator-resignation");
|
82
100
|
|
83
|
-
const transaction = assertDeserialized(fixture, [
|
101
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
84
102
|
|
85
103
|
expect(transaction).toBeInstanceOf(ValidatorResignation);
|
86
104
|
});
|
87
105
|
|
88
|
-
it(
|
89
|
-
const fixture = await getFixture(
|
106
|
+
it("should deserialize a username registration signed with a passphrase", async () => {
|
107
|
+
const fixture = await getFixture("username-registration");
|
90
108
|
|
91
|
-
const transaction = assertDeserialized(fixture, [
|
109
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
92
110
|
|
93
111
|
expect(transaction).toBeInstanceOf(UsernameRegistration);
|
94
112
|
});
|
95
113
|
|
96
|
-
it(
|
97
|
-
const fixture = await getFixture(
|
114
|
+
it("should deserialize a username resignation signed with a passphrase", async () => {
|
115
|
+
const fixture = await getFixture("username-resignation");
|
98
116
|
|
99
|
-
const transaction = assertDeserialized(fixture, [
|
117
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
100
118
|
|
101
119
|
expect(transaction).toBeInstanceOf(UsernameResignation);
|
102
120
|
});
|
103
121
|
|
104
|
-
it(
|
105
|
-
const fixture = await getFixture(
|
122
|
+
it("should deserialize a multipayment signed with a passphrase", async () => {
|
123
|
+
const fixture = await getFixture("multipayment");
|
106
124
|
|
107
|
-
const transaction = assertDeserialized(fixture, [
|
125
|
+
const transaction = assertDeserialized(fixture, ["hash", "nonce", "gasPrice", "gas", "value", "v", "r", "s"]);
|
108
126
|
|
109
127
|
expect(transaction).toBeInstanceOf(Multipayment);
|
110
128
|
});
|
111
129
|
|
112
|
-
it(
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
130
|
+
it("should parse number", () => {
|
131
|
+
expect((Deserializer as any).parseNumber("0x01")).toEqual(1);
|
132
|
+
expect((Deserializer as any).parseNumber("0x0100")).toEqual(256);
|
133
|
+
expect((Deserializer as any).parseNumber("0x010000")).toEqual(65536);
|
134
|
+
expect((Deserializer as any).parseNumber("0x")).toEqual(0);
|
117
135
|
});
|
118
136
|
|
119
|
-
it(
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
137
|
+
it("should parse hex", () => {
|
138
|
+
expect((Deserializer as any).parseHex("0x01")).toEqual("01");
|
139
|
+
expect((Deserializer as any).parseHex("0x0100")).toEqual("0100");
|
140
|
+
expect((Deserializer as any).parseHex("0x010000")).toEqual("010000");
|
141
|
+
expect((Deserializer as any).parseHex("0x")).toEqual("");
|
142
|
+
expect((Deserializer as any).parseHex("0x52B7D2DCC80CD2E4000000")).toEqual("52B7D2DCC80CD2E4000000");
|
125
143
|
});
|
126
144
|
|
127
|
-
it(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
145
|
+
it("should parse big_number", () => {
|
146
|
+
expect((Deserializer as any).parseBigNumber("0x01")).toEqual("1");
|
147
|
+
expect((Deserializer as any).parseBigNumber("0x0100")).toEqual("256");
|
148
|
+
expect((Deserializer as any).parseBigNumber("0x010000")).toEqual("65536");
|
149
|
+
expect((Deserializer as any).parseBigNumber("0x")).toEqual("0");
|
150
|
+
expect((Deserializer as any).parseBigNumber("0x52B7D2DCC80CD2E4000000")).toEqual("100000000000000000000000000");
|
133
151
|
});
|
134
152
|
|
135
|
-
it(
|
136
|
-
|
137
|
-
|
153
|
+
it("should parse address", () => {
|
154
|
+
expect((Deserializer as any).parseAddress("0x52B7D2DCC80CD2E4000000")).toEqual("0x52B7D2DCC80CD2E4000000");
|
155
|
+
expect((Deserializer as any).parseAddress("0x")).toBe(undefined);
|
138
156
|
});
|
@@ -1,9 +1,19 @@
|
|
1
1
|
import fixtureTransfer from "@tests/fixtures/transactions/transfer.json";
|
2
2
|
|
3
3
|
import { Transfer } from "@/transactions/types/Transfer";
|
4
|
+
import { Serializer } from "../../../src/transactions/Serializer";
|
4
5
|
|
5
6
|
it("should serialize a transfer transaction", () => {
|
6
7
|
const transaction = new Transfer(fixtureTransfer.data);
|
7
8
|
|
8
|
-
expect(
|
9
|
+
expect(new Serializer(transaction).serialize().toString("hex")).toEqual(fixtureTransfer["serialized"]);
|
10
|
+
});
|
11
|
+
|
12
|
+
it("should serialize a transfer transaction without a signature", () => {
|
13
|
+
const transaction = new Transfer(fixtureTransfer.data);
|
14
|
+
|
15
|
+
// We slice the first few bytes because the serialization is different when the transaction is signed
|
16
|
+
expect(new Serializer(transaction).serialize(true).toString("hex").slice(4)).toEqual(
|
17
|
+
fixtureTransfer["serialized"].slice(6, 90),
|
18
|
+
);
|
9
19
|
});
|
@@ -7,10 +7,10 @@ it("should build a transaction", async () => {
|
|
7
7
|
const transaction = (
|
8
8
|
await EvmCallBuilder.new()
|
9
9
|
.payload(fixture.data.data)
|
10
|
-
.
|
10
|
+
.to(fixture.data.to)
|
11
11
|
.nonce(fixture.data.nonce)
|
12
12
|
.gasPrice(fixture.data.gasPrice)
|
13
|
-
.
|
13
|
+
.gas(fixture.data.gas)
|
14
14
|
.network(fixture.data.network)
|
15
15
|
.sign(identityFixture.passphrase)
|
16
16
|
).transaction;
|
@@ -18,32 +18,99 @@ it("should build a transaction", async () => {
|
|
18
18
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
19
19
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
20
20
|
expect(transaction.data.network).toBe(fixture.data.network);
|
21
|
-
expect(transaction.data.
|
22
|
-
expect(transaction.data.
|
21
|
+
expect(transaction.data.gas).toBe(fixture.data.gas);
|
22
|
+
expect(transaction.data.to).toBe(fixture.data.to);
|
23
23
|
expect(transaction.data.value).toBe(fixture.data.value);
|
24
24
|
expect(transaction.data.v).toBe(fixture.data.v);
|
25
25
|
expect(transaction.data.r).toBe(fixture.data.r);
|
26
26
|
expect(transaction.data.s).toBe(fixture.data.s);
|
27
|
-
expect(transaction.data.
|
27
|
+
expect(transaction.data.hash).toBe(fixture.data.hash);
|
28
28
|
|
29
29
|
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
30
30
|
expect(transaction.verify()).toBe(true);
|
31
31
|
});
|
32
32
|
|
33
33
|
it("should sign a transaction", async () => {
|
34
|
-
const transaction = (await EvmCallBuilder.new(fixture.data).sign(identityFixture.passphrase)).transaction;
|
34
|
+
const transaction = (await EvmCallBuilder.new({ ...fixture.data }).sign(identityFixture.passphrase)).transaction;
|
35
35
|
|
36
36
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
37
37
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
38
38
|
expect(transaction.data.network).toBe(fixture.data.network);
|
39
|
-
expect(transaction.data.
|
40
|
-
expect(transaction.data.
|
39
|
+
expect(transaction.data.gas).toBe(fixture.data.gas);
|
40
|
+
expect(transaction.data.to).toBe(fixture.data.to);
|
41
41
|
expect(transaction.data.value).toBe(fixture.data.value);
|
42
42
|
expect(transaction.data.v).toBe(fixture.data.v);
|
43
43
|
expect(transaction.data.r).toBe(fixture.data.r);
|
44
44
|
expect(transaction.data.s).toBe(fixture.data.s);
|
45
|
-
expect(transaction.data.
|
45
|
+
expect(transaction.data.hash).toBe(fixture.data.hash);
|
46
46
|
|
47
47
|
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
48
48
|
expect(transaction.verify()).toBe(true);
|
49
49
|
});
|
50
|
+
|
51
|
+
it("should verify", async () => {
|
52
|
+
const transaction = await EvmCallBuilder.new({ ...fixture.data }).sign(identityFixture.passphrase);
|
53
|
+
|
54
|
+
expect(transaction.verify()).toBe(true);
|
55
|
+
});
|
56
|
+
|
57
|
+
it("should convert to an array", async () => {
|
58
|
+
const transaction = await EvmCallBuilder.new({ ...fixture.data }).sign(identityFixture.passphrase);
|
59
|
+
|
60
|
+
expect(transaction.toObject()).toEqual({
|
61
|
+
data: fixture.data.data,
|
62
|
+
to: fixture.data.to,
|
63
|
+
value: fixture.data.value,
|
64
|
+
gasPrice: fixture.data.gasPrice,
|
65
|
+
gas: fixture.data.gas,
|
66
|
+
network: fixture.data.network,
|
67
|
+
nonce: fixture.data.nonce,
|
68
|
+
v: fixture.data.v,
|
69
|
+
r: fixture.data.r,
|
70
|
+
s: fixture.data.s,
|
71
|
+
senderPublicKey: fixture.data.senderPublicKey,
|
72
|
+
hash: fixture.data.hash,
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
it("should convert to json", async () => {
|
77
|
+
const transaction = await EvmCallBuilder.new({ ...fixture.data }).sign(identityFixture.passphrase);
|
78
|
+
|
79
|
+
expect(transaction.toJson()).toEqual(
|
80
|
+
JSON.stringify({
|
81
|
+
gasPrice: fixture.data.gasPrice,
|
82
|
+
network: fixture.data.network,
|
83
|
+
hash: fixture.data.hash,
|
84
|
+
gas: fixture.data.gas,
|
85
|
+
nonce: fixture.data.nonce,
|
86
|
+
senderPublicKey: fixture.data.senderPublicKey,
|
87
|
+
to: fixture.data.to,
|
88
|
+
value: fixture.data.value,
|
89
|
+
data: fixture.data.data,
|
90
|
+
r: fixture.data.r,
|
91
|
+
s: fixture.data.s,
|
92
|
+
v: fixture.data.v,
|
93
|
+
}),
|
94
|
+
);
|
95
|
+
});
|
96
|
+
|
97
|
+
it("should convert to string", async () => {
|
98
|
+
const transaction = await EvmCallBuilder.new({ ...fixture.data }).sign(identityFixture.passphrase);
|
99
|
+
|
100
|
+
expect(transaction.toString()).toEqual(
|
101
|
+
JSON.stringify({
|
102
|
+
gasPrice: fixture.data.gasPrice,
|
103
|
+
network: fixture.data.network,
|
104
|
+
hash: fixture.data.hash,
|
105
|
+
gas: fixture.data.gas,
|
106
|
+
nonce: fixture.data.nonce,
|
107
|
+
senderPublicKey: fixture.data.senderPublicKey,
|
108
|
+
to: fixture.data.to,
|
109
|
+
value: fixture.data.value,
|
110
|
+
data: fixture.data.data,
|
111
|
+
r: fixture.data.r,
|
112
|
+
s: fixture.data.s,
|
113
|
+
v: fixture.data.v,
|
114
|
+
}),
|
115
|
+
);
|
116
|
+
});
|