@arkecosystem/typescript-crypto 0.0.2 → 0.0.4
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/index.js +5 -4
- package/dist/transactions/builders/ValidatorRegistrationBuilder.d.ts.map +1 -1
- package/dist/transactions/builders/ValidatorRegistrationBuilder.js +3 -1
- package/dist/transactions/types/AbstractTransaction.d.ts +1 -1
- package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -1
- package/dist/transactions/types/AbstractTransaction.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/Message.d.ts.map +1 -1
- package/dist/utils/Message.js +0 -4
- package/dist/utils/TransactionUtils.js +2 -2
- package/package.json +5 -1
- package/src/transactions/builders/ValidatorRegistrationBuilder.ts +4 -1
- package/src/transactions/types/AbstractTransaction.ts +2 -2
- package/src/types.ts +1 -1
- package/src/utils/Message.ts +0 -5
- package/src/utils/TransactionUtils.ts +2 -2
- package/tests/unit/transactions/Deserializer.test.ts +1 -1
- package/tests/unit/transactions/Serializer.test.ts +1 -1
- package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +2 -2
- package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +4 -4
- package/tests/unit/transactions/builders/TransferBuilder.test.ts +3 -3
- package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +2 -2
- package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +2 -2
- package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +2 -2
- package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +30 -2
- package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +2 -2
- package/tests/unit/transactions/builders/VoteBuilder.test.ts +2 -2
- package/tests/unit/transactions/types/AbstractTransaction.test.ts +2 -2
- package/tests/unit/utils/TransactionUtils.test.ts +1 -1
package/dist/index.js
CHANGED
@@ -23650,11 +23650,11 @@ var TransactionUtils = class {
|
|
23650
23650
|
}
|
23651
23651
|
const encoded = encodeRlp(fields);
|
23652
23652
|
const payload = "02" /* EIP_1559_PREFIX */ + encoded.substring(2);
|
23653
|
-
return Buffer.from(payload);
|
23653
|
+
return Buffer.from(payload, "hex");
|
23654
23654
|
}
|
23655
23655
|
static toHash(transaction, skipSignature = false) {
|
23656
23656
|
const encoding = this.toBuffer(transaction, skipSignature);
|
23657
|
-
return keccak256("0x" + encoding.toString("
|
23657
|
+
return keccak256("0x" + encoding.toString("hex")).substring(2);
|
23658
23658
|
}
|
23659
23659
|
static getId(transaction) {
|
23660
23660
|
return this.toHash(transaction, false);
|
@@ -23692,7 +23692,7 @@ var AbstractTransaction = class {
|
|
23692
23692
|
return TransactionUtils.getId(this.data);
|
23693
23693
|
}
|
23694
23694
|
async sign(privateKey) {
|
23695
|
-
const hash2 = TransactionUtils.toBuffer(this.data, true).toString("
|
23695
|
+
const hash2 = TransactionUtils.toBuffer(this.data, true).toString("hex");
|
23696
23696
|
const signature = await privateKey.sign(hash2);
|
23697
23697
|
this.data["v"] = signature.v;
|
23698
23698
|
this.data["r"] = signature.r;
|
@@ -28328,7 +28328,8 @@ var ValidatorRegistrationBuilder = class extends AbstractTransactionBuilder {
|
|
28328
28328
|
return new this(data);
|
28329
28329
|
}
|
28330
28330
|
validatorPublicKey(validatorPublicKey) {
|
28331
|
-
|
28331
|
+
validatorPublicKey = Helpers.removeLeadingHexZero(validatorPublicKey);
|
28332
|
+
this.transaction.data.validatorPublicKey = `0x${validatorPublicKey}`;
|
28332
28333
|
this.transaction.refreshPayloadData();
|
28333
28334
|
return this;
|
28334
28335
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ValidatorRegistrationBuilder.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/ValidatorRegistrationBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAmB,MAAM,SAAS,CAAC;AAEvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;
|
1
|
+
{"version":3,"file":"ValidatorRegistrationBuilder.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/ValidatorRegistrationBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B,EAAmB,MAAM,SAAS,CAAC;AAEvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAK1E,qBAAa,4BACZ,SAAQ,0BAA0B,CAAC,6BAA6B,CAChE,YAAW,6BAA6B;gBAErB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;WAM/B,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,6BAA6B;IAIrE,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,GAAG,6BAA6B;IAUpF,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,YAAY;CAG1E"}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
|
2
2
|
import { ContractAddresses } from "@/enums/ContractAddresses";
|
3
3
|
import { ValidatorRegistration } from "@/transactions/types/ValidatorRegistration";
|
4
|
+
import { Helpers } from "@/utils";
|
4
5
|
export class ValidatorRegistrationBuilder extends AbstractTransactionBuilder {
|
5
6
|
constructor(data) {
|
6
7
|
super(data);
|
@@ -10,7 +11,8 @@ export class ValidatorRegistrationBuilder extends AbstractTransactionBuilder {
|
|
10
11
|
return new this(data);
|
11
12
|
}
|
12
13
|
validatorPublicKey(validatorPublicKey) {
|
13
|
-
|
14
|
+
validatorPublicKey = Helpers.removeLeadingHexZero(validatorPublicKey);
|
15
|
+
this.transaction.data.validatorPublicKey = `0x${validatorPublicKey}`;
|
14
16
|
this.transaction.refreshPayloadData();
|
15
17
|
return this;
|
16
18
|
}
|
@@ -7,7 +7,7 @@ export declare abstract class AbstractTransaction implements ITransaction {
|
|
7
7
|
serialized: Buffer | undefined;
|
8
8
|
constructor(data: TransactionData);
|
9
9
|
abstract getPayload(): string;
|
10
|
-
refreshPayloadData():
|
10
|
+
refreshPayloadData(): ITransaction;
|
11
11
|
getId(): string;
|
12
12
|
sign(privateKey: PrivateKey): Promise<ITransaction>;
|
13
13
|
recoverSender(): void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"AbstractTransaction.d.ts","sourceRoot":"","sources":["../../../src/transactions/types/AbstractTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAInE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAInD,8BAAsB,mBAAoB,YAAW,YAAY;IACzD,IAAI,EAAE,eAAe,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEnB,IAAI,EAAE,eAAe;aAMxB,UAAU,IAAI,MAAM;IAE7B,kBAAkB,IAAI,
|
1
|
+
{"version":3,"file":"AbstractTransaction.d.ts","sourceRoot":"","sources":["../../../src/transactions/types/AbstractTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAInE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAInD,8BAAsB,mBAAoB,YAAW,YAAY;IACzD,IAAI,EAAE,eAAe,CAAC;IACtB,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEnB,IAAI,EAAE,eAAe;aAMxB,UAAU,IAAI,MAAM;IAE7B,kBAAkB,IAAI,YAAY;IAMlC,KAAK,IAAI,MAAM;IAIT,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAYzD,aAAa,IAAI,IAAI;IAOrB,MAAM,IAAI,OAAO;IAWjB,OAAO,IAAI,eAAe;IAuB1B,MAAM,IAAI,MAAM;IAIhB,IAAI,CAAC,aAAa,GAAE,OAAe,GAAG,MAAM;IAI5C,SAAS,CAAC,aAAa,GAAE,OAAe,GAAG,MAAM;IAIxD,SAAS,CAAC,gBAAgB,IAAI,SAAS;IAavC,SAAS,CAAC,aAAa,CACtB,IAAI,EAAE,eAAe,EACrB,IAAI,GAAE,eAA2C,GAC/C,SAAS,GAAG,IAAI;CAGnB"}
|
@@ -27,7 +27,7 @@ export class AbstractTransaction {
|
|
27
27
|
}
|
28
28
|
sign(privateKey) {
|
29
29
|
return __awaiter(this, void 0, void 0, function* () {
|
30
|
-
const hash = TransactionUtils.toBuffer(this.data, true).toString("
|
30
|
+
const hash = TransactionUtils.toBuffer(this.data, true).toString("hex");
|
31
31
|
const signature = yield privateKey.sign(hash);
|
32
32
|
this.data["v"] = signature.v;
|
33
33
|
this.data["r"] = signature.r;
|
package/dist/types.d.ts
CHANGED
@@ -27,7 +27,7 @@ export interface ITransaction {
|
|
27
27
|
data: TransactionData;
|
28
28
|
serialized: Buffer | undefined;
|
29
29
|
getPayload(): string;
|
30
|
-
refreshPayloadData():
|
30
|
+
refreshPayloadData(): ITransaction;
|
31
31
|
getId(): string;
|
32
32
|
sign(privateKey: any): Promise<ITransaction>;
|
33
33
|
recoverSender(): void;
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,EAAE,MAAM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M,GAAG,4BAA4B,CAAC;CACzD;AAED,MAAM,WAAW,eAAgB,SAAQ,mBAAmB,CAAC,eAAe,CAAC;IAC5E,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAAC;CAC1C;AAED,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB,CAAC,oBAAoB,CAAC;IACtF,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAAC;CAC3D;AAED,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB,CAAC,wBAAwB,CAAC;CAAG"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/utils/Message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"Message.d.ts","sourceRoot":"","sources":["../../src/utils/Message.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxC,qBAAa,OAAO;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,aAAa;IAMlC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO;WAI9B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAaxE,MAAM,IAAI,OAAO;IAQjB,QAAQ,IAAI,MAAM;IAIlB,OAAO,IAAI,MAAM,EAAE;IAInB,MAAM,IAAI,aAAa;CAOvB"}
|
package/dist/utils/Message.js
CHANGED
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
10
10
|
import { PrivateKey } from "@/identities/PrivateKey";
|
11
11
|
import { PublicKey } from "@/identities/PublicKey";
|
12
12
|
import { keccak256 } from "ethers";
|
13
|
-
// import { verify } from "tiny-secp256k1";
|
14
13
|
import { verify } from "@noble/secp256k1";
|
15
14
|
export class Message {
|
16
15
|
constructor(message) {
|
@@ -37,9 +36,6 @@ export class Message {
|
|
37
36
|
const message = Buffer.from(keccak256(Buffer.from(this.message)).slice(2), "hex");
|
38
37
|
const signature = Buffer.from(this.signature.slice(0, 128), "hex");
|
39
38
|
const publicKey = Buffer.from(this.publicKey, "hex");
|
40
|
-
// const r = signature.subarray(0, 32).readBigInt64BE();
|
41
|
-
// const s = signature.subarray(32, 64).readBigInt64BE();
|
42
|
-
// const v = Number(signature.subarray(64, 66).toString("hex"));
|
43
39
|
return verify(signature, message, publicKey);
|
44
40
|
}
|
45
41
|
toString() {
|
@@ -23,11 +23,11 @@ export class TransactionUtils {
|
|
23
23
|
}
|
24
24
|
const encoded = encodeRlp(fields);
|
25
25
|
const payload = Constants.EIP_1559_PREFIX + encoded.substring(2);
|
26
|
-
return Buffer.from(payload);
|
26
|
+
return Buffer.from(payload, 'hex');
|
27
27
|
}
|
28
28
|
static toHash(transaction, skipSignature = false) {
|
29
29
|
const encoding = this.toBuffer(transaction, skipSignature);
|
30
|
-
return keccak256('0x' + encoding.toString('
|
30
|
+
return keccak256('0x' + encoding.toString('hex')).substring(2);
|
31
31
|
}
|
32
32
|
static getId(transaction) {
|
33
33
|
return this.toHash(transaction, false);
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arkecosystem/typescript-crypto",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.4",
|
4
4
|
"engines": {
|
5
5
|
"node": ">=20.12.2"
|
6
6
|
},
|
@@ -13,6 +13,10 @@
|
|
13
13
|
".": {
|
14
14
|
"import": "./dist/index.js",
|
15
15
|
"require": "./dist/index.js"
|
16
|
+
},
|
17
|
+
"./types": {
|
18
|
+
"import": "./dist/types.js",
|
19
|
+
"require": "./dist/types.js"
|
16
20
|
}
|
17
21
|
},
|
18
22
|
"bugs": {
|
@@ -3,6 +3,7 @@ import { ITransaction, IValidatorRegistrationBuilder, TransactionData } from "@/
|
|
3
3
|
import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
|
4
4
|
import { ContractAddresses } from "@/enums/ContractAddresses";
|
5
5
|
import { ValidatorRegistration } from "@/transactions/types/ValidatorRegistration";
|
6
|
+
import { Helpers } from "@/utils";
|
6
7
|
|
7
8
|
export class ValidatorRegistrationBuilder
|
8
9
|
extends AbstractTransactionBuilder<IValidatorRegistrationBuilder>
|
@@ -19,7 +20,9 @@ export class ValidatorRegistrationBuilder
|
|
19
20
|
}
|
20
21
|
|
21
22
|
public validatorPublicKey(validatorPublicKey: string): IValidatorRegistrationBuilder {
|
22
|
-
|
23
|
+
validatorPublicKey = Helpers.removeLeadingHexZero(validatorPublicKey);
|
24
|
+
|
25
|
+
this.transaction.data.validatorPublicKey = `0x${validatorPublicKey}`;
|
23
26
|
|
24
27
|
this.transaction.refreshPayloadData();
|
25
28
|
|
@@ -21,7 +21,7 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
21
21
|
|
22
22
|
public abstract getPayload(): string;
|
23
23
|
|
24
|
-
public refreshPayloadData():
|
24
|
+
public refreshPayloadData(): ITransaction {
|
25
25
|
this.data.data = this.getPayload();
|
26
26
|
|
27
27
|
return this;
|
@@ -32,7 +32,7 @@ export abstract class AbstractTransaction implements ITransaction {
|
|
32
32
|
}
|
33
33
|
|
34
34
|
public async sign(privateKey: PrivateKey): Promise<ITransaction> {
|
35
|
-
const hash = TransactionUtils.toBuffer(this.data, true).toString("
|
35
|
+
const hash = TransactionUtils.toBuffer(this.data, true).toString("hex");
|
36
36
|
|
37
37
|
const signature = await privateKey.sign(hash);
|
38
38
|
|
package/src/types.ts
CHANGED
package/src/utils/Message.ts
CHANGED
@@ -2,7 +2,6 @@ import { PrivateKey } from "@/identities/PrivateKey";
|
|
2
2
|
import { PublicKey } from "@/identities/PublicKey";
|
3
3
|
import { SignedMessage } from "@/types";
|
4
4
|
import { keccak256 } from "ethers";
|
5
|
-
// import { verify } from "tiny-secp256k1";
|
6
5
|
import { verify } from "@noble/secp256k1";
|
7
6
|
|
8
7
|
export class Message {
|
@@ -38,10 +37,6 @@ export class Message {
|
|
38
37
|
const signature = Buffer.from(this.signature.slice(0, 128), "hex");
|
39
38
|
const publicKey = Buffer.from(this.publicKey, "hex");
|
40
39
|
|
41
|
-
// const r = signature.subarray(0, 32).readBigInt64BE();
|
42
|
-
// const s = signature.subarray(32, 64).readBigInt64BE();
|
43
|
-
// const v = Number(signature.subarray(64, 66).toString("hex"));
|
44
|
-
|
45
40
|
return verify(signature, message, publicKey);
|
46
41
|
}
|
47
42
|
|
@@ -28,13 +28,13 @@ export class TransactionUtils {
|
|
28
28
|
|
29
29
|
const payload = Constants.EIP_1559_PREFIX + encoded.substring(2);
|
30
30
|
|
31
|
-
return Buffer.from(payload);
|
31
|
+
return Buffer.from(payload, 'hex');
|
32
32
|
}
|
33
33
|
|
34
34
|
public static toHash(transaction: TransactionData, skipSignature: boolean = false): string {
|
35
35
|
const encoding = this.toBuffer(transaction, skipSignature);
|
36
36
|
|
37
|
-
return keccak256('0x' + encoding.toString('
|
37
|
+
return keccak256('0x' + encoding.toString('hex')).substring(2);
|
38
38
|
}
|
39
39
|
|
40
40
|
public static getId(transaction: TransactionData): string {
|
@@ -16,7 +16,7 @@ function assertDeserialized(fixture: any, keys: string[]) {
|
|
16
16
|
}
|
17
17
|
}
|
18
18
|
|
19
|
-
expect(transaction.serialize().toString('
|
19
|
+
expect(transaction.serialize().toString('hex')).toEqual(fixture['serialized']);
|
20
20
|
expect(transaction.verify()).toBe(true);
|
21
21
|
|
22
22
|
return transaction
|
@@ -5,5 +5,5 @@ import { Transfer } from "@/transactions/types/Transfer";
|
|
5
5
|
it("should serialize a transfer transaction", () => {
|
6
6
|
const transaction = new Transfer(fixtureTransfer.data);
|
7
7
|
|
8
|
-
expect(fixtureTransfer["serialized"]).toEqual(transaction.serialize().toString("
|
8
|
+
expect(fixtureTransfer["serialized"]).toEqual(transaction.serialize().toString("hex"));
|
9
9
|
});
|
@@ -26,7 +26,7 @@ it("should build a transaction", async () => {
|
|
26
26
|
expect(transaction.data.s).toBe(fixture.data.s);
|
27
27
|
expect(transaction.data.id).toBe(fixture.data.id);
|
28
28
|
|
29
|
-
expect(transaction.serialize().toString("
|
29
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
30
30
|
expect(transaction.verify()).toBe(true);
|
31
31
|
});
|
32
32
|
|
@@ -44,6 +44,6 @@ it("should sign a transaction", async () => {
|
|
44
44
|
expect(transaction.data.s).toBe(fixture.data.s);
|
45
45
|
expect(transaction.data.id).toBe(fixture.data.id);
|
46
46
|
|
47
|
-
expect(transaction.serialize().toString("
|
47
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
48
48
|
expect(transaction.verify()).toBe(true);
|
49
49
|
});
|
@@ -27,7 +27,7 @@ it("should build a transaction", async () => {
|
|
27
27
|
expect(transaction.data.s).toBe(fixture.data.s);
|
28
28
|
expect(transaction.data.id).toBe(fixture.data.id);
|
29
29
|
|
30
|
-
expect(transaction.serialize().toString("
|
30
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
31
31
|
expect(transaction.verify()).toBe(true);
|
32
32
|
});
|
33
33
|
|
@@ -45,7 +45,7 @@ it("should sign a transaction", async () => {
|
|
45
45
|
expect(transaction.data.s).toBe(fixture.data.s);
|
46
46
|
expect(transaction.data.id).toBe(fixture.data.id);
|
47
47
|
|
48
|
-
expect(transaction.serialize().toString("
|
48
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
49
49
|
expect(transaction.verify()).toBe(true);
|
50
50
|
});
|
51
51
|
|
@@ -70,7 +70,7 @@ it("should build a transaction with a single payment", async () => {
|
|
70
70
|
expect(transaction.data.s).toBe(fixtureSingle.data.s);
|
71
71
|
expect(transaction.data.id).toBe(fixtureSingle.data.id);
|
72
72
|
|
73
|
-
expect(transaction.serialize().toString("
|
73
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixtureSingle.serialized);
|
74
74
|
expect(transaction.verify()).toBe(true);
|
75
75
|
});
|
76
76
|
|
@@ -94,6 +94,6 @@ it("should build a transaction with an empty payment", async () => {
|
|
94
94
|
expect(transaction.data.s).toBe(fixtureEmpty.data.s);
|
95
95
|
expect(transaction.data.id).toBe(fixtureEmpty.data.id);
|
96
96
|
|
97
|
-
expect(transaction.serialize().toString("
|
97
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixtureEmpty.serialized);
|
98
98
|
expect(transaction.verify()).toBe(true);
|
99
99
|
});
|
@@ -25,7 +25,7 @@ it("should build a transaction", async () => {
|
|
25
25
|
expect(transaction.data.s).toBe(fixtureTransfer.data.s);
|
26
26
|
expect(transaction.data.id).toBe(fixtureTransfer.data.id);
|
27
27
|
|
28
|
-
expect(transaction.serialize().toString("
|
28
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixtureTransfer.serialized);
|
29
29
|
expect(transaction.verify()).toBe(true);
|
30
30
|
});
|
31
31
|
|
@@ -43,7 +43,7 @@ it("should sign a transaction", async () => {
|
|
43
43
|
expect(transaction.data.s).toBe(fixtureTransfer.data.s);
|
44
44
|
expect(transaction.data.id).toBe(fixtureTransfer.data.id);
|
45
45
|
|
46
|
-
expect(transaction.serialize().toString("
|
46
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixtureTransfer.serialized);
|
47
47
|
expect(transaction.verify()).toBe(true);
|
48
48
|
});
|
49
49
|
|
@@ -68,6 +68,6 @@ it("should handle large amounts", async () => {
|
|
68
68
|
expect(transaction.data.s).toBe(fixtureTransferLargeAmount.data.s);
|
69
69
|
expect(transaction.data.id).toBe(fixtureTransferLargeAmount.data.id);
|
70
70
|
|
71
|
-
expect(transaction.serialize().toString("
|
71
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixtureTransferLargeAmount.serialized);
|
72
72
|
expect(transaction.verify()).toBe(true);
|
73
73
|
});
|
@@ -24,7 +24,7 @@ it("should build a transaction", async () => {
|
|
24
24
|
expect(transaction.data.s).toBe(fixture.data.s);
|
25
25
|
expect(transaction.data.id).toBe(fixture.data.id);
|
26
26
|
|
27
|
-
expect(transaction.serialize().toString("
|
27
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
28
28
|
expect(transaction.verify()).toBe(true);
|
29
29
|
});
|
30
30
|
|
@@ -42,6 +42,6 @@ it("should sign a transaction", async () => {
|
|
42
42
|
expect(transaction.data.s).toBe(fixture.data.s);
|
43
43
|
expect(transaction.data.id).toBe(fixture.data.id);
|
44
44
|
|
45
|
-
expect(transaction.serialize().toString("
|
45
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
46
46
|
expect(transaction.verify()).toBe(true);
|
47
47
|
});
|
@@ -26,7 +26,7 @@ it("should build a transaction", async () => {
|
|
26
26
|
expect(transaction.data.s).toBe(fixture.data.s);
|
27
27
|
expect(transaction.data.id).toBe(fixture.data.id);
|
28
28
|
|
29
|
-
expect(transaction.serialize().toString("
|
29
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
30
30
|
expect(transaction.verify()).toBe(true);
|
31
31
|
});
|
32
32
|
|
@@ -45,7 +45,7 @@ it("should sign a transaction", async () => {
|
|
45
45
|
expect(transaction.data.s).toBe(fixture.data.s);
|
46
46
|
expect(transaction.data.id).toBe(fixture.data.id);
|
47
47
|
|
48
|
-
expect(transaction.serialize().toString("
|
48
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
49
49
|
expect(transaction.verify()).toBe(true);
|
50
50
|
});
|
51
51
|
|
@@ -24,7 +24,7 @@ it("should build a transaction", async () => {
|
|
24
24
|
expect(transaction.data.s).toBe(fixture.data.s);
|
25
25
|
expect(transaction.data.id).toBe(fixture.data.id);
|
26
26
|
|
27
|
-
expect(transaction.serialize().toString("
|
27
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
28
28
|
expect(transaction.verify()).toBe(true);
|
29
29
|
});
|
30
30
|
|
@@ -43,6 +43,6 @@ it("should sign a transaction", async () => {
|
|
43
43
|
expect(transaction.data.s).toBe(fixture.data.s);
|
44
44
|
expect(transaction.data.id).toBe(fixture.data.id);
|
45
45
|
|
46
|
-
expect(transaction.serialize().toString("
|
46
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
47
47
|
expect(transaction.verify()).toBe(true);
|
48
48
|
});
|
@@ -4,6 +4,34 @@ import identityFixture from "@tests/fixtures/identity.json";
|
|
4
4
|
import { ValidatorRegistrationBuilder } from "@/transactions/builders/ValidatorRegistrationBuilder";
|
5
5
|
|
6
6
|
it("should build a transaction", async () => {
|
7
|
+
const transaction = (
|
8
|
+
await ValidatorRegistrationBuilder.new()
|
9
|
+
.validatorPublicKey(
|
10
|
+
"30954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c0624",
|
11
|
+
)
|
12
|
+
.nonce(fixture.data.nonce)
|
13
|
+
.gasPrice(fixture.data.gasPrice)
|
14
|
+
.gasLimit(fixture.data.gasLimit)
|
15
|
+
.network(fixture.data.network)
|
16
|
+
.sign(identityFixture.passphrase)
|
17
|
+
).transaction;
|
18
|
+
|
19
|
+
expect(transaction.data.gasPrice).toBe(fixture.data.gasPrice);
|
20
|
+
expect(transaction.data.nonce).toBe(fixture.data.nonce);
|
21
|
+
expect(transaction.data.network).toBe(fixture.data.network);
|
22
|
+
expect(transaction.data.gasLimit).toBe(fixture.data.gasLimit);
|
23
|
+
expect(transaction.data.recipientAddress).toBe(fixture.data.recipientAddress);
|
24
|
+
expect(transaction.data.value).toBe(fixture.data.value);
|
25
|
+
expect(transaction.data.v).toBe(fixture.data.v);
|
26
|
+
expect(transaction.data.r).toBe(fixture.data.r);
|
27
|
+
expect(transaction.data.s).toBe(fixture.data.s);
|
28
|
+
expect(transaction.data.id).toBe(fixture.data.id);
|
29
|
+
|
30
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
31
|
+
expect(transaction.verify()).toBe(true);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("should handle validator public key with leading 0x", async () => {
|
7
35
|
const transaction = (
|
8
36
|
await ValidatorRegistrationBuilder.new()
|
9
37
|
.validatorPublicKey(
|
@@ -27,7 +55,7 @@ it("should build a transaction", async () => {
|
|
27
55
|
expect(transaction.data.s).toBe(fixture.data.s);
|
28
56
|
expect(transaction.data.id).toBe(fixture.data.id);
|
29
57
|
|
30
|
-
expect(transaction.serialize().toString("
|
58
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
31
59
|
expect(transaction.verify()).toBe(true);
|
32
60
|
});
|
33
61
|
|
@@ -46,6 +74,6 @@ it("should sign a transaction", async () => {
|
|
46
74
|
expect(transaction.data.s).toBe(fixture.data.s);
|
47
75
|
expect(transaction.data.id).toBe(fixture.data.id);
|
48
76
|
|
49
|
-
expect(transaction.serialize().toString("
|
77
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
50
78
|
expect(transaction.verify()).toBe(true);
|
51
79
|
});
|
@@ -24,7 +24,7 @@ it("should build a transaction", async () => {
|
|
24
24
|
expect(transaction.data.s).toBe(fixture.data.s);
|
25
25
|
expect(transaction.data.id).toBe(fixture.data.id);
|
26
26
|
|
27
|
-
expect(transaction.serialize().toString("
|
27
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
28
28
|
expect(transaction.verify()).toBe(true);
|
29
29
|
});
|
30
30
|
|
@@ -43,6 +43,6 @@ it("should sign a transaction", async () => {
|
|
43
43
|
expect(transaction.data.s).toBe(fixture.data.s);
|
44
44
|
expect(transaction.data.id).toBe(fixture.data.id);
|
45
45
|
|
46
|
-
expect(transaction.serialize().toString("
|
46
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
47
47
|
expect(transaction.verify()).toBe(true);
|
48
48
|
});
|
@@ -25,7 +25,7 @@ it("should build a transaction", async () => {
|
|
25
25
|
expect(transaction.data.s).toBe(fixture.data.s);
|
26
26
|
expect(transaction.data.id).toBe(fixture.data.id);
|
27
27
|
|
28
|
-
expect(transaction.serialize().toString("
|
28
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
29
29
|
expect(transaction.verify()).toBe(true);
|
30
30
|
});
|
31
31
|
|
@@ -43,6 +43,6 @@ it("should sign a transaction", async () => {
|
|
43
43
|
expect(transaction.data.s).toBe(fixture.data.s);
|
44
44
|
expect(transaction.data.id).toBe(fixture.data.id);
|
45
45
|
|
46
|
-
expect(transaction.serialize().toString("
|
46
|
+
expect(transaction.serialize().toString("hex")).toEqual(fixture.serialized);
|
47
47
|
expect(transaction.verify()).toBe(true);
|
48
48
|
});
|
@@ -126,13 +126,13 @@ it("should generate a hash for the transaction without signature", () => {
|
|
126
126
|
it("should serialize the transaction with signature", () => {
|
127
127
|
const transaction = new Transfer(fixture.data);
|
128
128
|
|
129
|
-
expect(transaction.serialize().toString("
|
129
|
+
expect(transaction.serialize().toString("hex")).toBe(fixture.serialized);
|
130
130
|
});
|
131
131
|
|
132
132
|
it("should serialize the transaction without signature", () => {
|
133
133
|
const transaction = new Transfer(fixture.data);
|
134
134
|
|
135
|
-
const serialized = transaction.serialize(true).toString("
|
135
|
+
const serialized = transaction.serialize(true).toString("hex");
|
136
136
|
|
137
137
|
expect(serialized).toHaveLength(88);
|
138
138
|
|
@@ -6,7 +6,7 @@ it("should convert a transaction to a buffer with a signature", () => {
|
|
6
6
|
const buffer = TransactionUtils.toBuffer(fixture.data);
|
7
7
|
|
8
8
|
expect(buffer).toBeInstanceOf(Buffer);
|
9
|
-
expect(buffer.toString("
|
9
|
+
expect(buffer.toString("hex")).toBe(fixture.serialized);
|
10
10
|
});
|
11
11
|
|
12
12
|
it("should convert a transaction to a buffer without a signature", () => {
|