@arkecosystem/typescript-crypto 0.0.5 → 0.0.7

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.
@@ -1,7 +1,7 @@
1
- import { ethers, sha256 } from "ethers";
1
+ import { ethers, sha256, toUtf8Bytes } from "ethers";
2
2
  export class Address {
3
3
  static fromPassphrase(passphrase) {
4
- return this.fromPrivateKey(sha256(Buffer.from(passphrase)));
4
+ return this.fromPrivateKey(sha256(toUtf8Bytes(passphrase)));
5
5
  }
6
6
  static fromPublicKey(publicKey) {
7
7
  return ethers.computeAddress(`0x${publicKey}`);
@@ -1 +1 @@
1
- {"version":3,"file":"PrivateKey.d.ts","sourceRoot":"","sources":["../../src/identities/PrivateKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAqB,MAAM,QAAQ,CAAC;AAMnD,UAAU,oBAAoB;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,qBAAa,UAAU;IACf,UAAU,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,CAAC,MAAM;IAIlC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;IAIrD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAMvC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAMjC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAW1D"}
1
+ {"version":3,"file":"PrivateKey.d.ts","sourceRoot":"","sources":["../../src/identities/PrivateKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAkC,MAAM,QAAQ,CAAC;AAMhE,UAAU,oBAAoB;IAC7B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED,qBAAa,UAAU;IACf,UAAU,EAAE,MAAM,CAAC;gBAEd,OAAO,EAAE,MAAM,CAAC,MAAM;IAIlC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU;IAIrD,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAMvC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAMjC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAW1D"}
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import * as WIF from "wif";
11
- import { ethers, keccak256, sha256 } from "ethers";
11
+ import { ethers, keccak256, sha256, toUtf8Bytes } from "ethers";
12
12
  import { signAsync } from "@noble/secp256k1";
13
13
  import { Constants } from "@/enums/Constants";
14
14
  import { Network } from "@/configuration/Network";
@@ -17,7 +17,7 @@ export class PrivateKey {
17
17
  this.privateKey = keyPair.privateKey.substring(2);
18
18
  }
19
19
  static fromPassphrase(passphrase) {
20
- return PrivateKey.fromHex(sha256(Buffer.from(passphrase)));
20
+ return PrivateKey.fromHex(sha256(toUtf8Bytes(passphrase)));
21
21
  }
22
22
  static fromHex(hex) {
23
23
  const wallet = new ethers.Wallet(hex);
@@ -1,11 +1,11 @@
1
- import { sha256, SigningKey } from "ethers";
1
+ import { sha256, SigningKey, toUtf8Bytes } from "ethers";
2
2
  import { Signature } from "@noble/secp256k1";
3
3
  export class PublicKey {
4
4
  constructor(publicKey) {
5
5
  this.publicKey = publicKey;
6
6
  }
7
7
  static fromPassphrase(passphrase) {
8
- const publicKey = SigningKey.computePublicKey(sha256(Buffer.from(passphrase)), true).substring(2);
8
+ const publicKey = SigningKey.computePublicKey(sha256(toUtf8Bytes(passphrase)), true).substring(2);
9
9
  return new PublicKey(publicKey);
10
10
  }
11
11
  static fromHex(publicKey) {
package/dist/index.js CHANGED
@@ -22691,7 +22691,7 @@ var wordlists = {
22691
22691
  // src/identities/Address.ts
22692
22692
  var Address = class {
22693
22693
  static fromPassphrase(passphrase) {
22694
- return this.fromPrivateKey(sha2562(Buffer.from(passphrase)));
22694
+ return this.fromPrivateKey(sha2562(toUtf8Bytes(passphrase)));
22695
22695
  }
22696
22696
  static fromPublicKey(publicKey) {
22697
22697
  return ethers_exports.computeAddress(`0x${publicKey}`);
@@ -23509,7 +23509,7 @@ var PrivateKey = class _PrivateKey {
23509
23509
  this.privateKey = keyPair.privateKey.substring(2);
23510
23510
  }
23511
23511
  static fromPassphrase(passphrase) {
23512
- return _PrivateKey.fromHex(sha2562(Buffer.from(passphrase)));
23512
+ return _PrivateKey.fromHex(sha2562(toUtf8Bytes(passphrase)));
23513
23513
  }
23514
23514
  static fromHex(hex) {
23515
23515
  const wallet = new ethers_exports.Wallet(hex);
@@ -23536,7 +23536,7 @@ var PublicKey = class _PublicKey {
23536
23536
  this.publicKey = publicKey;
23537
23537
  }
23538
23538
  static fromPassphrase(passphrase) {
23539
- const publicKey = SigningKey.computePublicKey(sha2562(Buffer.from(passphrase)), true).substring(2);
23539
+ const publicKey = SigningKey.computePublicKey(sha2562(toUtf8Bytes(passphrase)), true).substring(2);
23540
23540
  return new _PublicKey(publicKey);
23541
23541
  }
23542
23542
  static fromHex(publicKey) {
@@ -27809,7 +27809,7 @@ var AbiBase = class {
27809
27809
  const abi = this.contractAbi(type, customAbi);
27810
27810
  this.interface = new Interface(JSON.parse(JSON.stringify(abi)).abi);
27811
27811
  }
27812
- contractAbi(type = "consensus" /* CONSENSUS */, customAbi) {
27812
+ contractAbi(type, customAbi) {
27813
27813
  switch (type) {
27814
27814
  case "consensus" /* CONSENSUS */:
27815
27815
  return Abi_Consensus_default;
@@ -28084,6 +28084,14 @@ var ValidatorRegistrationBuilder = class extends AbstractTransactionBuilder {
28084
28084
  this.transaction.refreshPayloadData();
28085
28085
  return this;
28086
28086
  }
28087
+ value(value) {
28088
+ if (value instanceof bignumber_default) {
28089
+ value = value.toFixed();
28090
+ }
28091
+ this.transaction.data.value = value;
28092
+ this.transaction.refreshPayloadData();
28093
+ return this;
28094
+ }
28087
28095
  getTransactionInstance(data) {
28088
28096
  return new ValidatorRegistration(data);
28089
28097
  }
@@ -28265,9 +28273,6 @@ var Deserializer = class _Deserializer {
28265
28273
  return new Multipayment(data);
28266
28274
  }
28267
28275
  }
28268
- if (data.value !== "0") {
28269
- return new Transfer(data);
28270
- }
28271
28276
  const consensusPayloadData = _Deserializer.decodePayload(data);
28272
28277
  if (consensusPayloadData !== null) {
28273
28278
  const functionName = consensusPayloadData.functionName;
@@ -28294,6 +28299,9 @@ var Deserializer = class _Deserializer {
28294
28299
  return new UsernameResignation(data);
28295
28300
  }
28296
28301
  }
28302
+ if (data.value !== "0") {
28303
+ return new Transfer(data);
28304
+ }
28297
28305
  return new EvmCall(data);
28298
28306
  }
28299
28307
  static parseNumber(value) {
@@ -60,9 +60,6 @@ export class Deserializer {
60
60
  return new Multipayment(data);
61
61
  }
62
62
  }
63
- if (data.value !== "0") {
64
- return new Transfer(data);
65
- }
66
63
  const consensusPayloadData = Deserializer.decodePayload(data);
67
64
  if (consensusPayloadData !== null) {
68
65
  const functionName = consensusPayloadData.functionName;
@@ -89,6 +86,9 @@ export class Deserializer {
89
86
  return new UsernameResignation(data);
90
87
  }
91
88
  }
89
+ if (data.value !== "0") {
90
+ return new Transfer(data);
91
+ }
92
92
  return new EvmCall(data);
93
93
  }
94
94
  static parseNumber(value) {
@@ -1,9 +1,11 @@
1
1
  import { ITransaction, IValidatorRegistrationBuilder } from "@/types";
2
2
  import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
3
+ import BigNumber from "bignumber.js";
3
4
  export declare class ValidatorRegistrationBuilder extends AbstractTransactionBuilder<IValidatorRegistrationBuilder> implements IValidatorRegistrationBuilder {
4
5
  constructor(data?: Record<string, unknown>);
5
6
  static new(data?: Record<string, unknown>): IValidatorRegistrationBuilder;
6
7
  validatorPublicKey(validatorPublicKey: string): IValidatorRegistrationBuilder;
8
+ value(value: string | BigNumber): IValidatorRegistrationBuilder;
7
9
  protected getTransactionInstance(data?: Record<string, unknown>): ITransaction;
8
10
  }
9
11
  //# sourceMappingURL=ValidatorRegistrationBuilder.d.ts.map
@@ -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;AAK1E,qBAAa,4BACZ,SAAQ,0BAA0B,CAAC,6BAA6B,CAChE,YAAW,6BAA6B;gBAErB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;WAMnC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,6BAA6B;IAIzE,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,GAAG,6BAA6B;IAUpF,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;CAG9E"}
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;AAI1E,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,qBAAa,4BACZ,SAAQ,0BAA0B,CAAC,6BAA6B,CAChE,YAAW,6BAA6B;gBAErB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;WAMnC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,6BAA6B;IAIzE,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,GAAG,6BAA6B;IAU7E,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,6BAA6B;IAYtE,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;CAG9E"}
@@ -2,6 +2,7 @@ import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
2
2
  import { ContractAddresses } from "@/enums/ContractAddresses";
3
3
  import { ValidatorRegistration } from "@/transactions/types/ValidatorRegistration";
4
4
  import { Helpers } from "@/utils";
5
+ import BigNumber from "bignumber.js";
5
6
  export class ValidatorRegistrationBuilder extends AbstractTransactionBuilder {
6
7
  constructor(data) {
7
8
  super(data);
@@ -16,6 +17,14 @@ export class ValidatorRegistrationBuilder extends AbstractTransactionBuilder {
16
17
  this.transaction.refreshPayloadData();
17
18
  return this;
18
19
  }
20
+ value(value) {
21
+ if (value instanceof BigNumber) {
22
+ value = value.toFixed();
23
+ }
24
+ this.transaction.data.value = value;
25
+ this.transaction.refreshPayloadData();
26
+ return this;
27
+ }
19
28
  getTransactionInstance(data) {
20
29
  return new ValidatorRegistration(data);
21
30
  }
package/dist/types.d.ts CHANGED
@@ -57,6 +57,7 @@ export interface IVoteBuilder extends ITransactionBuilder<IVoteBuilder> {
57
57
  }
58
58
  export interface IValidatorRegistrationBuilder extends ITransactionBuilder<IValidatorRegistrationBuilder> {
59
59
  validatorPublicKey(validatorPublicKey: string): IValidatorRegistrationBuilder;
60
+ value(value: string | BigNumber): IValidatorRegistrationBuilder;
60
61
  }
61
62
  export interface IUsernameRegistrationBuilder extends ITransactionBuilder<IUsernameRegistrationBuilder> {
62
63
  username(username: string): IUsernameRegistrationBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRo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UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACrC,MAAM,IAAI,OAAO,CAAC;IAClB,QAAQ,IAAI,eAAe,CAAC;IAC5B,MAAM,IAAI,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAiB,SAAQ,mBAAmB,CAAC,gBAAgB,CAAC;IAC9E,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,gBAAgB,CAAC;CACnD;AAED,MAAM,WAAW,YAAa,SAAQ,mBAAmB,CAAC,YAAY,CAAC;IACtE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;CACjC;AAED,MAAM,WAAW,6BAA8B,SAAQ,mBAAmB,CAAC,6BAA6B,CAAC;IACxG,kBAAkB,CAAC,kBAAkB,EAAE,MAAM,GAAG,6BAA6B,CAAC;IAC9E,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,6BAA6B,CAAC;CAChE;AAED,MAAM,WAAW,4BAA6B,SAAQ,mBAAmB,CAAC,4BAA4B,CAAC;IACtG,QAAQ,CAAC,QAAQ,EAAE,MAAM,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,SAAS,GAAG,oBAAoB,CAAC;CACvE;AAED,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB,CAAC,wBAAwB,CAAC;CAAG"}
@@ -2,7 +2,7 @@ import { ContractAbiType } from "@/enums/ContractAbiType";
2
2
  import { Interface } from "ethers";
3
3
  export declare abstract class AbiBase {
4
4
  protected interface: Interface;
5
- constructor(type?: ContractAbiType, customAbi?: string);
5
+ constructor(type?: ContractAbiType, customAbi?: object);
6
6
  private contractAbi;
7
7
  }
8
8
  //# sourceMappingURL=AbiBase.d.ts.map
@@ -8,7 +8,7 @@ export class AbiBase {
8
8
  const abi = this.contractAbi(type, customAbi);
9
9
  this.interface = new Interface(JSON.parse(JSON.stringify(abi)).abi);
10
10
  }
11
- contractAbi(type = ContractAbiType.CONSENSUS, customAbi) {
11
+ contractAbi(type, customAbi) {
12
12
  switch (type) {
13
13
  case ContractAbiType.CONSENSUS:
14
14
  return ConsensusContract;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkecosystem/typescript-crypto",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "engines": {
5
5
  "node": ">=20.12.2"
6
6
  },
@@ -1,8 +1,8 @@
1
- import { ethers, sha256 } from "ethers";
1
+ import { ethers, sha256, toUtf8Bytes } from "ethers";
2
2
 
3
3
  export class Address {
4
4
  static fromPassphrase(passphrase: string): string {
5
- return this.fromPrivateKey(sha256(Buffer.from(passphrase)));
5
+ return this.fromPrivateKey(sha256(toUtf8Bytes(passphrase)));
6
6
  }
7
7
 
8
8
  static fromPublicKey(publicKey: string): string {
@@ -1,6 +1,6 @@
1
1
  import * as WIF from "wif";
2
2
 
3
- import { ethers, keccak256, sha256 } from "ethers";
3
+ import { ethers, keccak256, sha256, toUtf8Bytes } from "ethers";
4
4
  import { signAsync } from "@noble/secp256k1";
5
5
 
6
6
  import { Constants } from "@/enums/Constants";
@@ -20,7 +20,7 @@ export class PrivateKey {
20
20
  }
21
21
 
22
22
  static fromPassphrase(passphrase: string): PrivateKey {
23
- return PrivateKey.fromHex(sha256(Buffer.from(passphrase)));
23
+ return PrivateKey.fromHex(sha256(toUtf8Bytes(passphrase)));
24
24
  }
25
25
 
26
26
  static fromHex(hex: string): PrivateKey {
@@ -1,4 +1,4 @@
1
- import { sha256, SigningKey } from "ethers";
1
+ import { sha256, SigningKey, toUtf8Bytes } from "ethers";
2
2
  import { Signature } from "@noble/secp256k1";
3
3
 
4
4
  export class PublicKey {
@@ -9,7 +9,7 @@ export class PublicKey {
9
9
  }
10
10
 
11
11
  static fromPassphrase(passphrase: string): PublicKey {
12
- const publicKey = SigningKey.computePublicKey(sha256(Buffer.from(passphrase)), true).substring(2);
12
+ const publicKey = SigningKey.computePublicKey(sha256(toUtf8Bytes(passphrase)), true).substring(2);
13
13
 
14
14
  return new PublicKey(publicKey);
15
15
  }
@@ -92,10 +92,6 @@ export class Deserializer {
92
92
  }
93
93
  }
94
94
 
95
- if (data.value !== "0") {
96
- return new Transfer(data);
97
- }
98
-
99
95
  const consensusPayloadData = Deserializer.decodePayload(data);
100
96
  if (consensusPayloadData !== null) {
101
97
  const functionName = consensusPayloadData.functionName;
@@ -128,6 +124,10 @@ export class Deserializer {
128
124
  }
129
125
  }
130
126
 
127
+ if (data.value !== "0") {
128
+ return new Transfer(data);
129
+ }
130
+
131
131
  return new EvmCall(data);
132
132
  }
133
133
 
@@ -4,6 +4,7 @@ import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
4
4
  import { ContractAddresses } from "@/enums/ContractAddresses";
5
5
  import { ValidatorRegistration } from "@/transactions/types/ValidatorRegistration";
6
6
  import { Helpers } from "@/utils";
7
+ import BigNumber from "bignumber.js";
7
8
 
8
9
  export class ValidatorRegistrationBuilder
9
10
  extends AbstractTransactionBuilder<IValidatorRegistrationBuilder>
@@ -29,6 +30,18 @@ export class ValidatorRegistrationBuilder
29
30
  return this;
30
31
  }
31
32
 
33
+ public value(value: string | BigNumber): IValidatorRegistrationBuilder {
34
+ if (value instanceof BigNumber) {
35
+ value = value.toFixed();
36
+ }
37
+
38
+ this.transaction.data.value = value;
39
+
40
+ this.transaction.refreshPayloadData();
41
+
42
+ return this;
43
+ }
44
+
32
45
  protected getTransactionInstance(data?: Record<string, unknown>): ITransaction {
33
46
  return new ValidatorRegistration(data as TransactionData);
34
47
  }
package/src/types.ts CHANGED
@@ -69,6 +69,7 @@ export interface IVoteBuilder extends ITransactionBuilder<IVoteBuilder> {
69
69
 
70
70
  export interface IValidatorRegistrationBuilder extends ITransactionBuilder<IValidatorRegistrationBuilder> {
71
71
  validatorPublicKey(validatorPublicKey: string): IValidatorRegistrationBuilder;
72
+ value(value: string | BigNumber): IValidatorRegistrationBuilder;
72
73
  }
73
74
 
74
75
  export interface IUsernameRegistrationBuilder extends ITransactionBuilder<IUsernameRegistrationBuilder> {
@@ -7,13 +7,13 @@ import UsernamesContract from "./Abi/json/Abi.Usernames.json";
7
7
  export abstract class AbiBase {
8
8
  protected interface: Interface;
9
9
 
10
- constructor(type: ContractAbiType = ContractAbiType.CONSENSUS, customAbi?: string) {
10
+ constructor(type: ContractAbiType = ContractAbiType.CONSENSUS, customAbi?: object) {
11
11
  const abi = this.contractAbi(type, customAbi);
12
12
 
13
13
  this.interface = new Interface(JSON.parse(JSON.stringify(abi)).abi);
14
14
  }
15
15
 
16
- private contractAbi(type: ContractAbiType = ContractAbiType.CONSENSUS, customAbi?: unknown): object {
16
+ private contractAbi(type: ContractAbiType, customAbi?: object): object {
17
17
  switch (type) {
18
18
  case ContractAbiType.CONSENSUS:
19
19
  return ConsensusContract;
@@ -5,14 +5,14 @@
5
5
  "gasPrice": "5000000000",
6
6
  "gas": "200000",
7
7
  "to": "0x535B3D7A252fa034Ed71F0C53ec0C6F784cB64E1",
8
- "value": "0",
8
+ "value": "250000000000000000000",
9
9
  "data": "602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000",
10
10
  "v": 28,
11
- "r": "57216346b5252f6db63a2c78b5bc0a3697d2247377e9d9ef1b67849a87eb2413",
12
- "s": "66ea02477fc19671b3b626e3c4d33939a8ba43004f0a56e900efc1e580739d11",
11
+ "r": "94cc05fc2abfdf0d84b5aa8a0d7ecfc7e07076e137d97781725daa568cda3b72",
12
+ "s": "6fde8095be44340cc34f12d192cec63289c0eba759e3df25b6e89c05786588cd",
13
13
  "senderPublicKey": "0243333347c8cbf4e3cbc7a96964181d02a2b0c854faa2fef86b4b8d92afcf473d",
14
14
  "from": "0x1E6747BEAa5B4076a6A98D735DF8c35a70D18Bdd",
15
- "hash": "5064b50091b8e5d50ec1d1eb7c5b71cdcf9c7355bba18ee0efeaeacb0b1c95d5"
15
+ "hash": "a3a35d0fe9429b43833b4f4b8ec90cc56f431d68e24d10602967d9eab68caf6b"
16
16
  },
17
- "serialized": "02f8ef822710018085012a05f20083030d4094535b3d7a252fa034ed71f0c53ec0c6f784cb64e180b884602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000c001a057216346b5252f6db63a2c78b5bc0a3697d2247377e9d9ef1b67849a87eb2413a066ea02477fc19671b3b626e3c4d33939a8ba43004f0a56e900efc1e580739d11"
17
+ "serialized": "02f8f8822710018085012a05f20083030d4094535b3d7a252fa034ed71f0c53ec0c6f784cb64e1890d8d726b7177a80000b884602a9eee0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003030954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c062400000000000000000000000000000000c001a094cc05fc2abfdf0d84b5aa8a0d7ecfc7e07076e137d97781725daa568cda3b72a06fde8095be44340cc34f12d192cec63289c0eba759e3df25b6e89c05786588cd"
18
18
  }
@@ -12,6 +12,7 @@ it("should build a transaction", async () => {
12
12
  .nonce(fixture.data.nonce)
13
13
  .gasPrice(fixture.data.gasPrice)
14
14
  .gas(fixture.data.gas)
15
+ .value(fixture.data.value)
15
16
  .network(fixture.data.network)
16
17
  .sign(identityFixture.passphrase)
17
18
  ).transaction;
@@ -40,6 +41,7 @@ it("should handle validator public key with leading 0x", async () => {
40
41
  .nonce(fixture.data.nonce)
41
42
  .gasPrice(fixture.data.gasPrice)
42
43
  .gas(fixture.data.gas)
44
+ .value(fixture.data.value)
43
45
  .network(fixture.data.network)
44
46
  .sign(identityFixture.passphrase)
45
47
  ).transaction;
@@ -1,5 +1,6 @@
1
1
  import { AbiDecoder } from "@/utils/AbiDecoder";
2
2
  import { ContractAbiType } from "@/enums/ContractAbiType";
3
+ import MultipaymentAbi from "@/utils/Abi/json/Abi.Multipayment.json";
3
4
 
4
5
  it("should decode a vote function call", () => {
5
6
  const decoder = new AbiDecoder();
@@ -23,8 +24,13 @@ it("should decode an unvote function call", () => {
23
24
  expect(decodedData.args).toEqual([]);
24
25
  });
25
26
 
26
- it("should decode a multipayment function call", () => {
27
- const decoder = new AbiDecoder(ContractAbiType.MULTIPAYMENT);
27
+ it("should throw an error if custom abi is not passed", () => {
28
+ expect(() => new AbiDecoder(ContractAbiType.CUSTOM)).toThrow("Invalid contract type");
29
+ });
30
+
31
+ // We'll re-use the multipayment contract for this test
32
+ it("should decode using a custom abi", () => {
33
+ const decoder = new AbiDecoder(ContractAbiType.CUSTOM, MultipaymentAbi);
28
34
 
29
35
  const args = [
30
36
  ["0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A", "0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A"],
@@ -38,7 +44,3 @@ it("should decode a multipayment function call", () => {
38
44
  expect(decodedData.args[0]).toEqual(args[0]);
39
45
  expect(decodedData.args[1].map((value: BigInt) => value.toString())).toEqual(args[1]);
40
46
  });
41
-
42
- it("should throw an error if custom abi is not passed", () => {
43
- expect(() => new AbiDecoder(ContractAbiType.CUSTOM)).toThrow("Invalid contract type");
44
- });
@@ -1,5 +1,6 @@
1
1
  import { AbiEncoder } from "@/utils/AbiEncoder";
2
2
  import { ContractAbiType } from "@/enums/ContractAbiType";
3
+ import MultipaymentAbi from "@/utils/Abi/json/Abi.Multipayment.json";
3
4
 
4
5
  it("should encode a vote function call", () => {
5
6
  const encoder = new AbiEncoder();
@@ -28,3 +29,20 @@ it("should encode a multipayment function call", () => {
28
29
 
29
30
  expect(encodedData).toBe(expectedEncodedData);
30
31
  });
32
+
33
+ // We'll re-use the multipayment contract for this test
34
+ it("should encode using a custom abi", () => {
35
+ const encoder = new AbiEncoder(ContractAbiType.CUSTOM, MultipaymentAbi);
36
+
37
+ const functionName = "pay";
38
+ const args = [
39
+ ["0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A", "0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A"],
40
+ ["100000000", "200000000"],
41
+ ];
42
+ const expectedEncodedData =
43
+ "084ce708000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690a000000000000000000000000b693449adda7efc015d87944eae8b7c37eb1690a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000005f5e100000000000000000000000000000000000000000000000000000000000bebc200";
44
+
45
+ const encodedData = encoder.encodeFunctionCall(functionName, args);
46
+
47
+ expect(encodedData).toBe(expectedEncodedData);
48
+ });
@@ -1,5 +1,4 @@
1
1
  import fixture from "@tests/fixtures/transactions/transfer.json";
2
-
3
2
  import { TransactionUtils } from "@/utils/TransactionUtils";
4
3
 
5
4
  it("should convert a transaction to a buffer with a signature", () => {
@@ -15,6 +14,34 @@ it("should convert a transaction to a buffer without a signature", () => {
15
14
  expect(buffer).toBeInstanceOf(Buffer);
16
15
  });
17
16
 
17
+ it("should convert a transaction to a buffer using fallback values if missing", () => {
18
+ const result = TransactionUtils.toBuffer({
19
+ network: undefined,
20
+ nonce: undefined,
21
+ gasPrice: undefined,
22
+ gasLimit: undefined,
23
+ recipientAddress: undefined,
24
+ value: undefined,
25
+ data: undefined,
26
+ }).toString("hex");
27
+
28
+ expect(result).toEqual("02c98080808080808080c0");
29
+ });
30
+
31
+ it("should convert a transaction to a buffer handling data starting with 0x", () => {
32
+ const result = TransactionUtils.toBuffer({
33
+ network: undefined,
34
+ nonce: undefined,
35
+ gasPrice: undefined,
36
+ gasLimit: undefined,
37
+ recipientAddress: undefined,
38
+ value: undefined,
39
+ data: "0x1234567890",
40
+ }).toString("hex");
41
+
42
+ expect(result).toEqual("02ce80808080808080851234567890c0");
43
+ });
44
+
18
45
  it("should convert a transaction to a hash with a signature", () => {
19
46
  expect(TransactionUtils.toHash(fixture.data)).toBe(fixture.data.hash);
20
47
  });
@@ -35,7 +35,7 @@ it.each([
35
35
  [1000, "1000000000000000000000"],
36
36
  [10000, "10000000000000000000000"],
37
37
  ])("should parse units into ark [%s]", (amount, formattedAmount) => {
38
- const arkValue = UnitConverter.parseUnits(amount, "ark");
38
+ const arkValue = UnitConverter.parseUnits(amount);
39
39
 
40
40
  expect(arkValue.toFixed()).toEqual(formattedAmount);
41
41
  });
@@ -71,7 +71,7 @@ it.each([
71
71
  ["1000000000000000000000", 1000],
72
72
  ["10000000000000000000000", 10000],
73
73
  ])("should format units from ark [%s]", (formattedAmount, amount) => {
74
- const formattedValue = UnitConverter.formatUnits(formattedAmount, "ark");
74
+ const formattedValue = UnitConverter.formatUnits(formattedAmount);
75
75
 
76
76
  expect(formattedValue).toEqual(amount);
77
77
  });