@arkecosystem/typescript-crypto 0.0.10 → 0.0.11
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/dist/enums/index.d.ts +0 -1
- package/dist/enums/index.d.ts.map +1 -1
- package/dist/enums/index.js +0 -1
- package/dist/identities/PrivateKey.d.ts.map +1 -1
- package/dist/identities/PrivateKey.js +3 -4
- package/dist/index.js +32 -45
- package/dist/transactions/Deserializer.d.ts.map +1 -1
- package/dist/transactions/Deserializer.js +18 -16
- package/dist/transactions/builders/AbstractTransactionBuilder.d.ts +1 -2
- package/dist/transactions/builders/AbstractTransactionBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/AbstractTransactionBuilder.js +7 -13
- package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -1
- package/dist/transactions/types/AbstractTransaction.js +4 -6
- package/dist/types.d.ts +2 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/TransactionUtils.d.ts.map +1 -1
- package/dist/utils/TransactionUtils.js +14 -12
- package/package.json +1 -1
- package/src/enums/index.ts +0 -1
- package/src/identities/PrivateKey.ts +3 -4
- package/src/transactions/Deserializer.ts +22 -19
- package/src/transactions/builders/AbstractTransactionBuilder.ts +7 -15
- package/src/transactions/types/AbstractTransaction.ts +4 -6
- package/src/types.ts +2 -4
- package/src/utils/TransactionUtils.ts +11 -8
- package/tests/fixtures/identity.json +2 -1
- package/tests/fixtures/message-sign.json +1 -1
- package/tests/fixtures/sign-compact.json +1 -1
- package/tests/fixtures/transactions/evm-sign.json +7 -7
- package/tests/fixtures/transactions/multipayment-empty.json +7 -7
- package/tests/fixtures/transactions/multipayment-single.json +7 -7
- package/tests/fixtures/transactions/multipayment.json +7 -7
- package/tests/fixtures/transactions/transfer-0.json +7 -7
- package/tests/fixtures/transactions/transfer-large-amount.json +7 -7
- package/tests/fixtures/transactions/transfer-legacy-second-signature.json +8 -8
- package/tests/fixtures/transactions/transfer.json +7 -7
- package/tests/fixtures/transactions/unvote.json +7 -7
- package/tests/fixtures/transactions/username-registration.json +7 -7
- package/tests/fixtures/transactions/username-resignation.json +7 -7
- package/tests/fixtures/transactions/validator-registration.json +8 -8
- package/tests/fixtures/transactions/validator-resignation.json +7 -7
- package/tests/fixtures/transactions/vote.json +7 -7
- package/tests/unit/identities/PublicKey.test.ts +3 -4
- package/tests/unit/transactions/Deserializer.test.ts +12 -11
- package/tests/unit/transactions/Serializer.test.ts +5 -6
- package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +7 -14
- package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +15 -29
- package/tests/unit/transactions/builders/TransferBuilder.test.ts +15 -29
- package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +7 -14
- package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +8 -15
- package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +7 -14
- package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +9 -18
- package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +7 -14
- package/tests/unit/transactions/builders/VoteBuilder.test.ts +7 -14
- package/tests/unit/transactions/types/AbstractTransaction.test.ts +6 -8
- package/tests/unit/utils/TransactionUtils.test.ts +5 -7
- package/dist/enums/Constants.d.ts +0 -5
- package/dist/enums/Constants.d.ts.map +0 -1
- package/dist/enums/Constants.js +0 -5
- package/src/enums/Constants.ts +0 -4
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { ValidatorRegistrationBuilder } from "@/transactions/builders/ValidatorRegistrationBuilder";
|
|
1
2
|
import fixture from "@tests/fixtures/transactions/validator-registration.json";
|
|
2
3
|
import identityFixture from "@tests/fixtures/identity.json";
|
|
3
4
|
|
|
4
|
-
import { ValidatorRegistrationBuilder } from "@/transactions/builders/ValidatorRegistrationBuilder";
|
|
5
|
-
|
|
6
5
|
it("should build a transaction", async () => {
|
|
7
6
|
const transaction = (
|
|
8
7
|
await ValidatorRegistrationBuilder.new()
|
|
@@ -11,16 +10,14 @@ it("should build a transaction", async () => {
|
|
|
11
10
|
)
|
|
12
11
|
.nonce(fixture.data.nonce)
|
|
13
12
|
.gasPrice(fixture.data.gasPrice)
|
|
14
|
-
.
|
|
13
|
+
.gasLimit(fixture.data.gasLimit)
|
|
15
14
|
.value(fixture.data.value)
|
|
16
|
-
.network(fixture.data.network)
|
|
17
15
|
.sign(identityFixture.passphrase)
|
|
18
16
|
).transaction;
|
|
19
17
|
|
|
20
18
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
21
19
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
22
|
-
expect(transaction.data.
|
|
23
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
20
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
24
21
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
25
22
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
26
23
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -40,16 +37,14 @@ it("should handle validator public key with leading 0x", async () => {
|
|
|
40
37
|
)
|
|
41
38
|
.nonce(fixture.data.nonce)
|
|
42
39
|
.gasPrice(fixture.data.gasPrice)
|
|
43
|
-
.
|
|
40
|
+
.gasLimit(fixture.data.gasLimit)
|
|
44
41
|
.value(fixture.data.value)
|
|
45
|
-
.network(fixture.data.network)
|
|
46
42
|
.sign(identityFixture.passphrase)
|
|
47
43
|
).transaction;
|
|
48
44
|
|
|
49
45
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
50
46
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
51
|
-
expect(transaction.data.
|
|
52
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
47
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
53
48
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
54
49
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
55
50
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -67,8 +62,7 @@ it("should sign a transaction", async () => {
|
|
|
67
62
|
|
|
68
63
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
69
64
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
70
|
-
expect(transaction.data.
|
|
71
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
65
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
72
66
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
73
67
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
74
68
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -94,8 +88,7 @@ it("should convert to an array", async () => {
|
|
|
94
88
|
to: fixture.data.to,
|
|
95
89
|
value: fixture.data.value,
|
|
96
90
|
gasPrice: fixture.data.gasPrice,
|
|
97
|
-
|
|
98
|
-
network: fixture.data.network,
|
|
91
|
+
gasLimit: fixture.data.gasLimit,
|
|
99
92
|
nonce: fixture.data.nonce,
|
|
100
93
|
v: fixture.data.v,
|
|
101
94
|
r: fixture.data.r,
|
|
@@ -111,9 +104,8 @@ it("should convert to json", async () => {
|
|
|
111
104
|
expect(transaction.toJson()).toEqual(
|
|
112
105
|
JSON.stringify({
|
|
113
106
|
gasPrice: fixture.data.gasPrice,
|
|
114
|
-
network: fixture.data.network,
|
|
115
107
|
hash: fixture.data.hash,
|
|
116
|
-
|
|
108
|
+
gasLimit: fixture.data.gasLimit,
|
|
117
109
|
nonce: fixture.data.nonce,
|
|
118
110
|
senderPublicKey: fixture.data.senderPublicKey,
|
|
119
111
|
to: fixture.data.to,
|
|
@@ -132,9 +124,8 @@ it("should convert to string", async () => {
|
|
|
132
124
|
expect(transaction.toString()).toEqual(
|
|
133
125
|
JSON.stringify({
|
|
134
126
|
gasPrice: fixture.data.gasPrice,
|
|
135
|
-
network: fixture.data.network,
|
|
136
127
|
hash: fixture.data.hash,
|
|
137
|
-
|
|
128
|
+
gasLimit: fixture.data.gasLimit,
|
|
138
129
|
nonce: fixture.data.nonce,
|
|
139
130
|
senderPublicKey: fixture.data.senderPublicKey,
|
|
140
131
|
to: fixture.data.to,
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
+
import { ValidatorResignationBuilder } from "@/transactions/builders/ValidatorResignationBuilder";
|
|
1
2
|
import fixture from "@tests/fixtures/transactions/validator-resignation.json";
|
|
2
3
|
import identityFixture from "@tests/fixtures/identity.json";
|
|
3
4
|
|
|
4
|
-
import { ValidatorResignationBuilder } from "@/transactions/builders/ValidatorResignationBuilder";
|
|
5
|
-
|
|
6
5
|
it("should build a transaction", async () => {
|
|
7
6
|
const transaction = (
|
|
8
7
|
await ValidatorResignationBuilder.new()
|
|
9
8
|
.nonce(fixture.data.nonce)
|
|
10
9
|
.gasPrice(fixture.data.gasPrice)
|
|
11
|
-
.
|
|
12
|
-
.network(fixture.data.network)
|
|
10
|
+
.gasLimit(fixture.data.gasLimit)
|
|
13
11
|
.sign(identityFixture.passphrase)
|
|
14
12
|
).transaction;
|
|
15
13
|
|
|
16
14
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
17
15
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
18
|
-
expect(transaction.data.
|
|
19
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
16
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
20
17
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
21
18
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
22
19
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -34,8 +31,7 @@ it("should sign a transaction", async () => {
|
|
|
34
31
|
|
|
35
32
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
36
33
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
37
|
-
expect(transaction.data.
|
|
38
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
34
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
39
35
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
40
36
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
41
37
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -61,8 +57,7 @@ it("should convert to an array", async () => {
|
|
|
61
57
|
to: fixture.data.to,
|
|
62
58
|
value: fixture.data.value,
|
|
63
59
|
gasPrice: fixture.data.gasPrice,
|
|
64
|
-
|
|
65
|
-
network: fixture.data.network,
|
|
60
|
+
gasLimit: fixture.data.gasLimit,
|
|
66
61
|
nonce: fixture.data.nonce,
|
|
67
62
|
v: fixture.data.v,
|
|
68
63
|
r: fixture.data.r,
|
|
@@ -78,9 +73,8 @@ it("should convert to json", async () => {
|
|
|
78
73
|
expect(transaction.toJson()).toEqual(
|
|
79
74
|
JSON.stringify({
|
|
80
75
|
gasPrice: fixture.data.gasPrice,
|
|
81
|
-
network: fixture.data.network,
|
|
82
76
|
hash: fixture.data.hash,
|
|
83
|
-
|
|
77
|
+
gasLimit: fixture.data.gasLimit,
|
|
84
78
|
nonce: fixture.data.nonce,
|
|
85
79
|
senderPublicKey: fixture.data.senderPublicKey,
|
|
86
80
|
to: fixture.data.to,
|
|
@@ -99,9 +93,8 @@ it("should convert to string", async () => {
|
|
|
99
93
|
expect(transaction.toString()).toEqual(
|
|
100
94
|
JSON.stringify({
|
|
101
95
|
gasPrice: fixture.data.gasPrice,
|
|
102
|
-
network: fixture.data.network,
|
|
103
96
|
hash: fixture.data.hash,
|
|
104
|
-
|
|
97
|
+
gasLimit: fixture.data.gasLimit,
|
|
105
98
|
nonce: fixture.data.nonce,
|
|
106
99
|
senderPublicKey: fixture.data.senderPublicKey,
|
|
107
100
|
to: fixture.data.to,
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
+
import { VoteBuilder } from "@/transactions/builders/VoteBuilder";
|
|
1
2
|
import fixture from "@tests/fixtures/transactions/vote.json";
|
|
2
3
|
import identityFixture from "@tests/fixtures/identity.json";
|
|
3
4
|
|
|
4
|
-
import { VoteBuilder } from "@/transactions/builders/VoteBuilder";
|
|
5
|
-
|
|
6
5
|
it("should build a transaction", async () => {
|
|
7
6
|
const transaction = (
|
|
8
7
|
await VoteBuilder.new()
|
|
9
8
|
.vote("0xc3bbe9b1cee1ff85ad72b87414b0e9b7f2366763")
|
|
10
9
|
.nonce(fixture.data.nonce)
|
|
11
10
|
.gasPrice(fixture.data.gasPrice)
|
|
12
|
-
.
|
|
13
|
-
.network(fixture.data.network)
|
|
11
|
+
.gasLimit(fixture.data.gasLimit)
|
|
14
12
|
.sign(identityFixture.passphrase)
|
|
15
13
|
).transaction;
|
|
16
14
|
|
|
17
15
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
18
16
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
19
|
-
expect(transaction.data.
|
|
20
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
17
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
21
18
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
22
19
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
23
20
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -34,8 +31,7 @@ it("should sign a transaction", async () => {
|
|
|
34
31
|
|
|
35
32
|
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
|
36
33
|
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
|
37
|
-
expect(transaction.data.
|
|
38
|
-
expect(transaction.data.gas).toBe(fixture.data.gas);
|
|
34
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
|
39
35
|
expect(transaction.data.to).toBe(fixture.data.to);
|
|
40
36
|
expect(transaction.data.value).toBe(fixture.data.value);
|
|
41
37
|
expect(transaction.data.v).toBe(fixture.data.v);
|
|
@@ -61,8 +57,7 @@ it("should convert to an array", async () => {
|
|
|
61
57
|
to: fixture.data.to,
|
|
62
58
|
value: fixture.data.value,
|
|
63
59
|
gasPrice: fixture.data.gasPrice,
|
|
64
|
-
|
|
65
|
-
network: fixture.data.network,
|
|
60
|
+
gasLimit: fixture.data.gasLimit,
|
|
66
61
|
nonce: fixture.data.nonce,
|
|
67
62
|
v: fixture.data.v,
|
|
68
63
|
r: fixture.data.r,
|
|
@@ -78,9 +73,8 @@ it("should convert to json", async () => {
|
|
|
78
73
|
expect(transaction.toJson()).toEqual(
|
|
79
74
|
JSON.stringify({
|
|
80
75
|
gasPrice: fixture.data.gasPrice,
|
|
81
|
-
network: fixture.data.network,
|
|
82
76
|
hash: fixture.data.hash,
|
|
83
|
-
|
|
77
|
+
gasLimit: fixture.data.gasLimit,
|
|
84
78
|
nonce: fixture.data.nonce,
|
|
85
79
|
senderPublicKey: fixture.data.senderPublicKey,
|
|
86
80
|
to: fixture.data.to,
|
|
@@ -99,9 +93,8 @@ it("should convert to string", async () => {
|
|
|
99
93
|
expect(transaction.toString()).toEqual(
|
|
100
94
|
JSON.stringify({
|
|
101
95
|
gasPrice: fixture.data.gasPrice,
|
|
102
|
-
network: fixture.data.network,
|
|
103
96
|
hash: fixture.data.hash,
|
|
104
|
-
|
|
97
|
+
gasLimit: fixture.data.gasLimit,
|
|
105
98
|
nonce: fixture.data.nonce,
|
|
106
99
|
senderPublicKey: fixture.data.senderPublicKey,
|
|
107
100
|
to: fixture.data.to,
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import fixture from "@tests/fixtures/transactions/transfer.json";
|
|
2
|
-
import fixtureGlobal from "@tests/fixtures/global.json";
|
|
3
|
-
|
|
4
1
|
import { AbstractTransaction } from "@/transactions/types/AbstractTransaction";
|
|
5
2
|
import { PrivateKey } from "@/identities/PrivateKey";
|
|
6
|
-
import { TransactionData } from "@/types";
|
|
7
3
|
import { Transfer } from "@/transactions/types/Transfer";
|
|
4
|
+
import fixture from "@tests/fixtures/transactions/transfer.json";
|
|
5
|
+
import fixtureGlobal from "@tests/fixtures/global.json";
|
|
8
6
|
|
|
9
7
|
class Transaction extends AbstractTransaction {
|
|
10
8
|
getPayload(): string {
|
|
@@ -94,9 +92,8 @@ it("should convert the transaction to json", () => {
|
|
|
94
92
|
expect(transaction.toJson()).toEqual(
|
|
95
93
|
JSON.stringify({
|
|
96
94
|
gasPrice: fixture.data["gasPrice"],
|
|
97
|
-
network: fixture.data["network"],
|
|
98
95
|
hash: fixture.data["hash"],
|
|
99
|
-
|
|
96
|
+
gasLimit: fixture.data["gasLimit"],
|
|
100
97
|
nonce: fixture.data["nonce"],
|
|
101
98
|
senderPublicKey: fixture.data["senderPublicKey"],
|
|
102
99
|
to: fixture.data["to"],
|
|
@@ -135,8 +132,9 @@ it("should serialize the transaction without signature", () => {
|
|
|
135
132
|
|
|
136
133
|
const serialized = transaction.serialize(true).toString("hex");
|
|
137
134
|
|
|
138
|
-
expect(serialized).toHaveLength(
|
|
135
|
+
expect(serialized).toHaveLength(86);
|
|
139
136
|
|
|
140
137
|
// We don't store serialized without the signature in the fixtures so we do a partial check
|
|
141
|
-
|
|
138
|
+
const trimmedSerialized = serialized.substring(1, serialized.length - 9); // Remove leading char and last 9 chars (dummy signature)
|
|
139
|
+
expect(fixture.serialized).toContain(trimmedSerialized);
|
|
142
140
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fixture from "@tests/fixtures/transactions/transfer.json";
|
|
2
1
|
import { TransactionUtils } from "@/utils/TransactionUtils";
|
|
2
|
+
import fixture from "@tests/fixtures/transactions/transfer.json";
|
|
3
3
|
|
|
4
4
|
it("should convert a transaction to a buffer with a signature", () => {
|
|
5
5
|
const buffer = TransactionUtils.toBuffer(fixture.data);
|
|
@@ -16,30 +16,28 @@ it("should convert a transaction to a buffer without a signature", () => {
|
|
|
16
16
|
|
|
17
17
|
it("should convert a transaction to a buffer using fallback values if missing", () => {
|
|
18
18
|
const result = TransactionUtils.toBuffer({
|
|
19
|
-
network: undefined,
|
|
20
19
|
nonce: undefined,
|
|
21
20
|
gasPrice: undefined,
|
|
22
21
|
gasLimit: undefined,
|
|
23
|
-
|
|
22
|
+
to: undefined,
|
|
24
23
|
value: undefined,
|
|
25
24
|
data: undefined,
|
|
26
25
|
}).toString("hex");
|
|
27
26
|
|
|
28
|
-
expect(result).toEqual("
|
|
27
|
+
expect(result).toEqual("cb808080808080822e248080");
|
|
29
28
|
});
|
|
30
29
|
|
|
31
30
|
it("should convert a transaction to a buffer handling data starting with 0x", () => {
|
|
32
31
|
const result = TransactionUtils.toBuffer({
|
|
33
|
-
network: undefined,
|
|
34
32
|
nonce: undefined,
|
|
35
33
|
gasPrice: undefined,
|
|
36
34
|
gasLimit: undefined,
|
|
37
|
-
|
|
35
|
+
to: undefined,
|
|
38
36
|
value: undefined,
|
|
39
37
|
data: "0x1234567890",
|
|
40
38
|
}).toString("hex");
|
|
41
39
|
|
|
42
|
-
expect(result).toEqual("
|
|
40
|
+
expect(result).toEqual("d08080808080851234567890822e248080");
|
|
43
41
|
});
|
|
44
42
|
|
|
45
43
|
it("should convert a transaction to a hash with a signature", () => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/enums/Constants.ts"],"names":[],"mappings":"AAAA,oBAAY,SAAS;IACpB,eAAe,OAAO;IACtB,2BAA2B,KAAK;CAChC"}
|
package/dist/enums/Constants.js
DELETED
package/src/enums/Constants.ts
DELETED