@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.
Files changed (60) hide show
  1. package/dist/enums/index.d.ts +0 -1
  2. package/dist/enums/index.d.ts.map +1 -1
  3. package/dist/enums/index.js +0 -1
  4. package/dist/identities/PrivateKey.d.ts.map +1 -1
  5. package/dist/identities/PrivateKey.js +3 -4
  6. package/dist/index.js +32 -45
  7. package/dist/transactions/Deserializer.d.ts.map +1 -1
  8. package/dist/transactions/Deserializer.js +18 -16
  9. package/dist/transactions/builders/AbstractTransactionBuilder.d.ts +1 -2
  10. package/dist/transactions/builders/AbstractTransactionBuilder.d.ts.map +1 -1
  11. package/dist/transactions/builders/AbstractTransactionBuilder.js +7 -13
  12. package/dist/transactions/types/AbstractTransaction.d.ts.map +1 -1
  13. package/dist/transactions/types/AbstractTransaction.js +4 -6
  14. package/dist/types.d.ts +2 -4
  15. package/dist/types.d.ts.map +1 -1
  16. package/dist/utils/TransactionUtils.d.ts.map +1 -1
  17. package/dist/utils/TransactionUtils.js +14 -12
  18. package/package.json +1 -1
  19. package/src/enums/index.ts +0 -1
  20. package/src/identities/PrivateKey.ts +3 -4
  21. package/src/transactions/Deserializer.ts +22 -19
  22. package/src/transactions/builders/AbstractTransactionBuilder.ts +7 -15
  23. package/src/transactions/types/AbstractTransaction.ts +4 -6
  24. package/src/types.ts +2 -4
  25. package/src/utils/TransactionUtils.ts +11 -8
  26. package/tests/fixtures/identity.json +2 -1
  27. package/tests/fixtures/message-sign.json +1 -1
  28. package/tests/fixtures/sign-compact.json +1 -1
  29. package/tests/fixtures/transactions/evm-sign.json +7 -7
  30. package/tests/fixtures/transactions/multipayment-empty.json +7 -7
  31. package/tests/fixtures/transactions/multipayment-single.json +7 -7
  32. package/tests/fixtures/transactions/multipayment.json +7 -7
  33. package/tests/fixtures/transactions/transfer-0.json +7 -7
  34. package/tests/fixtures/transactions/transfer-large-amount.json +7 -7
  35. package/tests/fixtures/transactions/transfer-legacy-second-signature.json +8 -8
  36. package/tests/fixtures/transactions/transfer.json +7 -7
  37. package/tests/fixtures/transactions/unvote.json +7 -7
  38. package/tests/fixtures/transactions/username-registration.json +7 -7
  39. package/tests/fixtures/transactions/username-resignation.json +7 -7
  40. package/tests/fixtures/transactions/validator-registration.json +8 -8
  41. package/tests/fixtures/transactions/validator-resignation.json +7 -7
  42. package/tests/fixtures/transactions/vote.json +7 -7
  43. package/tests/unit/identities/PublicKey.test.ts +3 -4
  44. package/tests/unit/transactions/Deserializer.test.ts +12 -11
  45. package/tests/unit/transactions/Serializer.test.ts +5 -6
  46. package/tests/unit/transactions/builders/EvmCallBuilder.test.ts +7 -14
  47. package/tests/unit/transactions/builders/MultipaymentBuilder.test.ts +15 -29
  48. package/tests/unit/transactions/builders/TransferBuilder.test.ts +15 -29
  49. package/tests/unit/transactions/builders/UnvoteBuilder.test.ts +7 -14
  50. package/tests/unit/transactions/builders/UsernameRegistrationBuilder.test.ts +8 -15
  51. package/tests/unit/transactions/builders/UsernameResignationBuilder.test.ts +7 -14
  52. package/tests/unit/transactions/builders/ValidatorRegistrationBuilder.test.ts +9 -18
  53. package/tests/unit/transactions/builders/ValidatorResignationBuilder.test.ts +7 -14
  54. package/tests/unit/transactions/builders/VoteBuilder.test.ts +7 -14
  55. package/tests/unit/transactions/types/AbstractTransaction.test.ts +6 -8
  56. package/tests/unit/utils/TransactionUtils.test.ts +5 -7
  57. package/dist/enums/Constants.d.ts +0 -5
  58. package/dist/enums/Constants.d.ts.map +0 -1
  59. package/dist/enums/Constants.js +0 -5
  60. package/src/enums/Constants.ts +0 -4
@@ -1,5 +1,4 @@
1
1
  export * from "./AbiFunction";
2
- export * from "./Constants";
3
2
  export * from "./ContractAbiType";
4
3
  export * from "./ContractAddresses";
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enums/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enums/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
@@ -1,4 +1,3 @@
1
1
  export * from "./AbiFunction";
2
- export * from "./Constants";
3
2
  export * from "./ContractAbiType";
4
3
  export * from "./ContractAddresses";
@@ -1 +1 @@
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;IAWpD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQnD"}
1
+ {"version":3,"file":"PrivateKey.d.ts","sourceRoot":"","sources":["../../src/identities/PrivateKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAkC,MAAM,QAAQ,CAAC;AAKhE,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;IAWpD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQnD"}
@@ -9,9 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import * as WIF from "wif";
11
11
  import { ethers, keccak256, sha256, toUtf8Bytes } from "ethers";
12
- import { signAsync } from "@noble/secp256k1";
13
- import { Constants } from "@/enums/Constants";
14
12
  import { Network } from "@/configuration/Network";
13
+ import { signAsync } from "@noble/secp256k1";
15
14
  export class PrivateKey {
16
15
  constructor(keyPair) {
17
16
  this.privateKey = keyPair.privateKey.substring(2);
@@ -34,7 +33,7 @@ export class PrivateKey {
34
33
  return {
35
34
  r: signature.r.toString(16).padStart(64, "0"),
36
35
  s: signature.s.toString(16).padStart(64, "0"),
37
- v: signature.recovery + Constants.ETHEREUM_RECOVERY_ID_OFFSET,
36
+ v: signature.recovery,
38
37
  };
39
38
  });
40
39
  }
@@ -42,7 +41,7 @@ export class PrivateKey {
42
41
  return __awaiter(this, void 0, void 0, function* () {
43
42
  const hash = keccak256("0x" + message).slice(2);
44
43
  const signature = yield signAsync(hash, this.privateKey);
45
- const v = signature.recovery + Constants.ETHEREUM_RECOVERY_ID_OFFSET;
44
+ const v = signature.recovery;
46
45
  // @see https://github.com/ArkEcosystem/mainsail/blob/16e50d45dcfbf15b20245f11b123634f0fd0b713/packages/utils/source/format-ecdsa-signature.ts#L2
47
46
  return signature.toCompactHex() + v.toString(16).padStart(2, "0");
48
47
  });
package/dist/index.js CHANGED
@@ -46,13 +46,6 @@ var AbiFunction = /* @__PURE__ */ ((AbiFunction2) => {
46
46
  return AbiFunction2;
47
47
  })(AbiFunction || {});
48
48
 
49
- // src/enums/Constants.ts
50
- var Constants = /* @__PURE__ */ ((Constants2) => {
51
- Constants2["EIP_1559_PREFIX"] = "02";
52
- Constants2[Constants2["ETHEREUM_RECOVERY_ID_OFFSET"] = 27] = "ETHEREUM_RECOVERY_ID_OFFSET";
53
- return Constants2;
54
- })(Constants || {});
55
-
56
49
  // src/enums/ContractAbiType.ts
57
50
  var ContractAbiType = /* @__PURE__ */ ((ContractAbiType2) => {
58
51
  ContractAbiType2["CUSTOM"] = "custom";
@@ -23525,13 +23518,13 @@ var PrivateKey = class _PrivateKey {
23525
23518
  return {
23526
23519
  r: signature.r.toString(16).padStart(64, "0"),
23527
23520
  s: signature.s.toString(16).padStart(64, "0"),
23528
- v: signature.recovery + 27 /* ETHEREUM_RECOVERY_ID_OFFSET */
23521
+ v: signature.recovery
23529
23522
  };
23530
23523
  }
23531
23524
  async signToEcdsa(message) {
23532
23525
  const hash2 = keccak256("0x" + message).slice(2);
23533
23526
  const signature = await signAsync(hash2, this.privateKey);
23534
- const v = signature.recovery + 27 /* ETHEREUM_RECOVERY_ID_OFFSET */;
23527
+ const v = signature.recovery;
23535
23528
  return signature.toCompactHex() + v.toString(16).padStart(2, "0");
23536
23529
  }
23537
23530
  };
@@ -24932,18 +24925,17 @@ var AbstractTransactionBuilder = class {
24932
24925
  value: "0",
24933
24926
  senderPublicKey: "",
24934
24927
  gasPrice: "5",
24928
+ gasLimit: 1e6,
24935
24929
  nonce: "1",
24936
- network: Network.get().chainId(),
24937
- gas: 1e6,
24938
24930
  data: ""
24939
24931
  }
24940
24932
  );
24941
24933
  }
24942
- gas(gas) {
24943
- if (gas instanceof bignumber_default) {
24944
- gas = gas.toFixed();
24934
+ gasLimit(gasLimit) {
24935
+ if (gasLimit instanceof bignumber_default) {
24936
+ gasLimit = gasLimit.toFixed();
24945
24937
  }
24946
- this.transaction.data.gas = gas;
24938
+ this.transaction.data.gasLimit = gasLimit;
24947
24939
  return this;
24948
24940
  }
24949
24941
  to(to) {
@@ -24961,10 +24953,6 @@ var AbstractTransactionBuilder = class {
24961
24953
  this.transaction.data.nonce = nonce;
24962
24954
  return this;
24963
24955
  }
24964
- network(network) {
24965
- this.transaction.data.network = network;
24966
- return this;
24967
- }
24968
24956
  async sign(passphrase) {
24969
24957
  this.transaction.data.senderPublicKey = PublicKey.fromPassphrase(passphrase).publicKey;
24970
24958
  this.transaction = await this.transaction.sign(PrivateKey.fromPassphrase(passphrase));
@@ -24973,7 +24961,7 @@ var AbstractTransactionBuilder = class {
24973
24961
  }
24974
24962
  async legacySecondSign(passphrase, secondPassprase) {
24975
24963
  await this.sign(passphrase);
24976
- this.transaction = await this.transaction.legacySecondSign(PrivateKey.fromPassphrase(secondPassprase));
24964
+ await this.transaction.legacySecondSign(PrivateKey.fromPassphrase(secondPassprase));
24977
24965
  return this;
24978
24966
  }
24979
24967
  verify() {
@@ -24994,26 +24982,25 @@ var AbstractTransactionBuilder = class {
24994
24982
  var TransactionUtils = class {
24995
24983
  static toBuffer(transaction, skipSignature = false) {
24996
24984
  const fields = [
24997
- toBeArray(transaction["network"] ?? 0),
24998
24985
  toBeArray(transaction["nonce"] ? transaction["nonce"] : 0),
24999
- toBeArray(0),
25000
24986
  toBeArray(transaction["gasPrice"] ?? 0),
25001
- toBeArray(transaction["gas"] ?? 0),
24987
+ toBeArray(transaction["gasLimit"] ?? 0),
25002
24988
  transaction["to"] ?? "0x",
25003
24989
  toBeArray(transaction["value"] ? transaction["value"] : 0),
25004
- transaction["data"] && transaction["data"].startsWith("0x") ? transaction["data"] : "0x" + (transaction["data"] ?? ""),
25005
- []
24990
+ transaction["data"] && transaction["data"].startsWith("0x") ? transaction["data"] : "0x" + (transaction["data"] ?? "")
25006
24991
  ];
25007
- if (!skipSignature && transaction["v"] && transaction["r"] && transaction["s"]) {
25008
- fields.push(toBeArray(transaction["v"] - 27 /* ETHEREUM_RECOVERY_ID_OFFSET */));
24992
+ if (!skipSignature && transaction["v"] !== void 0 && transaction["r"] && transaction["s"]) {
24993
+ fields.push(toBeArray(transaction["v"] + Network.get().chainId() * 2 + 35));
25009
24994
  fields.push("0x" + transaction["r"]);
25010
24995
  fields.push("0x" + transaction["s"]);
25011
24996
  if (transaction.legacySecondSignature) {
25012
24997
  fields.push(`0x${transaction.legacySecondSignature}`);
25013
24998
  }
24999
+ } else {
25000
+ fields.push(toBeArray(Network.get().chainId()), toBeArray(0), toBeArray(0));
25014
25001
  }
25015
25002
  const encoded = encodeRlp(fields);
25016
- const payload = "02" /* EIP_1559_PREFIX */ + encoded.substring(2);
25003
+ const payload = encoded.substring(2);
25017
25004
  return Buffer.from(payload, "hex");
25018
25005
  }
25019
25006
  static toHash(transaction, skipSignature = false) {
@@ -25075,9 +25062,8 @@ var AbstractTransaction = class {
25075
25062
  toObject() {
25076
25063
  return [
25077
25064
  "gasPrice",
25078
- "network",
25079
25065
  "hash",
25080
- "gas",
25066
+ "gasLimit",
25081
25067
  "nonce",
25082
25068
  "senderPublicKey",
25083
25069
  "legacySecondSignature",
@@ -25108,14 +25094,14 @@ var AbstractTransaction = class {
25108
25094
  return Serializer.new(this).serialize(skipSignature);
25109
25095
  }
25110
25096
  recoverPublicKey() {
25111
- if (!this.data.v || !this.data.r || !this.data.s) {
25097
+ if (this.data.v === void 0 || !this.data.r || !this.data.s) {
25112
25098
  throw new Error("Transaction signature is missing");
25113
25099
  }
25114
25100
  return PublicKey.recover(
25115
25101
  Buffer.from(this.hash(true), "hex"),
25116
25102
  BigInt(`0x${this.data.r}`),
25117
25103
  BigInt(`0x${this.data.s}`),
25118
- this.data.v - 27 /* ETHEREUM_RECOVERY_ID_OFFSET */
25104
+ this.data.v
25119
25105
  );
25120
25106
  }
25121
25107
  };
@@ -28246,7 +28232,7 @@ var Deserializer = class _Deserializer {
28246
28232
  this.SIGNATURE_SIZE = 64;
28247
28233
  this.RECOVERY_SIZE = 1;
28248
28234
  this.serialized = serialized;
28249
- this.encoded_rlp = "0x" + serialized.substring(2);
28235
+ this.encoded_rlp = "0x" + serialized;
28250
28236
  }
28251
28237
  static new(serialized) {
28252
28238
  return new _Deserializer(serialized);
@@ -28254,18 +28240,20 @@ var Deserializer = class _Deserializer {
28254
28240
  deserialize() {
28255
28241
  const decodedRlp = decodeRlp(this.encoded_rlp);
28256
28242
  const data = {
28257
- network: Number(decodedRlp[0]),
28258
- nonce: _Deserializer.parseNumber(decodedRlp[1]),
28259
- gasPrice: _Deserializer.parseNumber(decodedRlp[3]).toString(),
28260
- gas: _Deserializer.parseNumber(decodedRlp[4]).toString(),
28261
- to: _Deserializer.parseAddress(decodedRlp[5]),
28262
- value: _Deserializer.parseBigNumber(decodedRlp[6]),
28263
- data: _Deserializer.parseHex(decodedRlp[7])
28243
+ nonce: _Deserializer.parseNumber(decodedRlp[0]),
28244
+ gasPrice: _Deserializer.parseNumber(decodedRlp[1]).toString(),
28245
+ gasLimit: _Deserializer.parseNumber(decodedRlp[2]).toString(),
28246
+ to: _Deserializer.parseAddress(decodedRlp[3]),
28247
+ value: _Deserializer.parseBigNumber(decodedRlp[4]),
28248
+ data: _Deserializer.parseHex(decodedRlp[5])
28264
28249
  };
28265
- if (decodedRlp.length === 12) {
28266
- data["v"] = _Deserializer.parseNumber(decodedRlp[9]) + 27 /* ETHEREUM_RECOVERY_ID_OFFSET */;
28267
- data["r"] = _Deserializer.parseHex(decodedRlp[10]);
28268
- data["s"] = _Deserializer.parseHex(decodedRlp[11]);
28250
+ if (decodedRlp.length >= 9) {
28251
+ data["v"] = _Deserializer.parseNumber(decodedRlp[6]) - (Network.get().chainId() * 2 + 35);
28252
+ data["r"] = _Deserializer.parseHex(decodedRlp[7]);
28253
+ data["s"] = _Deserializer.parseHex(decodedRlp[8]);
28254
+ if (decodedRlp.length === 10) {
28255
+ data.legacySecondSignature = decodedRlp[9].toString().slice(2);
28256
+ }
28269
28257
  }
28270
28258
  const transaction = this.guessTransactionFromData(data);
28271
28259
  transaction.data = data;
@@ -28347,7 +28335,6 @@ export {
28347
28335
  AbstractTransactionBuilder,
28348
28336
  Address,
28349
28337
  Abi_Consensus_default as ConsensusContract,
28350
- Constants,
28351
28338
  ContractAbiType,
28352
28339
  ContractAddresses,
28353
28340
  Deserializer,
@@ -1 +1 @@
1
- {"version":3,"file":"Deserializer.d.ts","sourceRoot":"","sources":["../../src/transactions/Deserializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAInE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAgB1D,qBAAa,YAAY;IACxB,cAAc,SAAM;IACpB,aAAa,SAAK;IAElB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;gBAEP,UAAU,EAAE,MAAM;IAK9B,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IAI5C,WAAW,IAAI,YAAY;IA6B3B,MAAM,CAAC,aAAa,CACnB,IAAI,EAAE,eAAe,EACrB,OAAO,GAAE,eAA2C,GAClD,SAAS,GAAG,IAAI;IAiBnB,OAAO,CAAC,wBAAwB;IAgDhC,OAAO,CAAC,MAAM,CAAC,WAAW;IAI1B,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B,OAAO,CAAC,MAAM,CAAC,YAAY;IAI3B,OAAO,CAAC,MAAM,CAAC,QAAQ;CAGvB"}
1
+ {"version":3,"file":"Deserializer.d.ts","sourceRoot":"","sources":["../../src/transactions/Deserializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAenE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAK1D,qBAAa,YAAY;IACxB,cAAc,SAAM;IACpB,aAAa,SAAK;IAElB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;gBAEP,UAAU,EAAE,MAAM;IAK9B,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,YAAY;IAI5C,WAAW,IAAI,YAAY;IAgC3B,MAAM,CAAC,aAAa,CACnB,IAAI,EAAE,eAAe,EACrB,OAAO,GAAE,eAA2C,GAClD,SAAS,GAAG,IAAI;IAiBnB,OAAO,CAAC,wBAAwB;IAgDhC,OAAO,CAAC,MAAM,CAAC,WAAW;IAI1B,OAAO,CAAC,MAAM,CAAC,cAAc;IAI7B,OAAO,CAAC,MAAM,CAAC,YAAY;IAI3B,OAAO,CAAC,MAAM,CAAC,QAAQ;CAGvB"}
@@ -1,17 +1,17 @@
1
+ import { EvmCall, Multipayment, Unvote, UsernameRegistration, UsernameResignation, ValidatorRegistration, ValidatorResignation, Vote, } from "./types";
2
+ import { AbiDecoder } from "@/utils";
3
+ import { AbiFunction } from "@/enums";
1
4
  import BigNumber from "bignumber.js";
2
- import { Constants } from "@/enums/Constants";
3
5
  import { ContractAbiType } from "@/enums/ContractAbiType";
6
+ import { Network } from "@/configuration/Network";
4
7
  import { Transfer } from "./types/Transfer";
5
8
  import { decodeRlp } from "ethers";
6
- import { EvmCall, Multipayment, Unvote, UsernameRegistration, UsernameResignation, ValidatorRegistration, ValidatorResignation, Vote, } from "./types";
7
- import { AbiFunction } from "@/enums";
8
- import { AbiDecoder } from "@/utils";
9
9
  export class Deserializer {
10
10
  constructor(serialized) {
11
11
  this.SIGNATURE_SIZE = 64;
12
12
  this.RECOVERY_SIZE = 1;
13
13
  this.serialized = serialized;
14
- this.encoded_rlp = "0x" + serialized.substring(2);
14
+ this.encoded_rlp = "0x" + serialized;
15
15
  }
16
16
  static new(serialized) {
17
17
  return new Deserializer(serialized);
@@ -19,18 +19,20 @@ export class Deserializer {
19
19
  deserialize() {
20
20
  const decodedRlp = decodeRlp(this.encoded_rlp);
21
21
  const data = {
22
- network: Number(decodedRlp[0]),
23
- nonce: Deserializer.parseNumber(decodedRlp[1]),
24
- gasPrice: Deserializer.parseNumber(decodedRlp[3]).toString(),
25
- gas: Deserializer.parseNumber(decodedRlp[4]).toString(),
26
- to: Deserializer.parseAddress(decodedRlp[5]),
27
- value: Deserializer.parseBigNumber(decodedRlp[6]),
28
- data: Deserializer.parseHex(decodedRlp[7]),
22
+ nonce: Deserializer.parseNumber(decodedRlp[0]),
23
+ gasPrice: Deserializer.parseNumber(decodedRlp[1]).toString(),
24
+ gasLimit: Deserializer.parseNumber(decodedRlp[2]).toString(),
25
+ to: Deserializer.parseAddress(decodedRlp[3]),
26
+ value: Deserializer.parseBigNumber(decodedRlp[4]),
27
+ data: Deserializer.parseHex(decodedRlp[5]),
29
28
  };
30
- if (decodedRlp.length === 12) {
31
- data["v"] = Deserializer.parseNumber(decodedRlp[9]) + Constants.ETHEREUM_RECOVERY_ID_OFFSET;
32
- data["r"] = Deserializer.parseHex(decodedRlp[10]);
33
- data["s"] = Deserializer.parseHex(decodedRlp[11]);
29
+ if (decodedRlp.length >= 9) {
30
+ data["v"] = Deserializer.parseNumber(decodedRlp[6]) - (Network.get().chainId() * 2 + 35);
31
+ data["r"] = Deserializer.parseHex(decodedRlp[7]);
32
+ data["s"] = Deserializer.parseHex(decodedRlp[8]);
33
+ if (decodedRlp.length === 10) {
34
+ data.legacySecondSignature = decodedRlp[9].toString().slice(2);
35
+ }
34
36
  }
35
37
  const transaction = this.guessTransactionFromData(data);
36
38
  transaction.data = data;
@@ -3,11 +3,10 @@ import BigNumber from "bignumber.js";
3
3
  export declare abstract class AbstractTransactionBuilder<T extends ITransactionBuilder<T>> implements ITransactionBuilder<T> {
4
4
  transaction: ITransaction;
5
5
  constructor(data?: Record<string, unknown>);
6
- gas(gas: string | BigNumber): T;
6
+ gasLimit(gasLimit: string | BigNumber): T;
7
7
  to(to: string): T;
8
8
  gasPrice(gasPrice: string | BigNumber): T;
9
9
  nonce(nonce: string): T;
10
- network(network: number): T;
11
10
  sign(passphrase: string): Promise<T>;
12
11
  legacySecondSign(passphrase: string, secondPassprase: string): Promise<T>;
13
12
  verify(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractTransactionBuilder.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/AbstractTransactionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAK7E,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,8BAAsB,0BAA0B,CAAC,CAAC,SAAS,mBAAmB,CAAC,CAAC,CAAC,CAAE,YAAW,mBAAmB,CAAC,CAAC,CAAC;IAC5G,WAAW,EAAE,YAAY,CAAC;gBAErB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcnC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC;IAU/B,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC;IAMjB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC;IAUzC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;IAMvB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC;IAMrB,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAUpC,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ/E,MAAM,IAAI,OAAO;IAIjB,QAAQ,IAAI,eAAe;IAI3B,MAAM,IAAI,MAAM;IAIhB,QAAQ,IAAI,MAAM;IAIzB,SAAS,CAAC,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;CACvF"}
1
+ {"version":3,"file":"AbstractTransactionBuilder.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/AbstractTransactionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE7E,OAAO,SAAS,MAAM,cAAc,CAAC;AAIrC,8BAAsB,0BAA0B,CAAC,CAAC,SAAS,mBAAmB,CAAC,CAAC,CAAC,CAAE,YAAW,mBAAmB,CAAC,CAAC,CAAC;IAC5G,WAAW,EAAE,YAAY,CAAC;gBAErB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAanC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC;IAUzC,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC;IAMjB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC;IAUzC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;IAMjB,IAAI,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAUpC,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ/E,MAAM,IAAI,OAAO;IAIjB,QAAQ,IAAI,eAAe;IAI3B,MAAM,IAAI,MAAM;IAIhB,QAAQ,IAAI,MAAM;IAIzB,SAAS,CAAC,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;CACvF"}
@@ -7,27 +7,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Network } from "@/configuration/Network";
10
+ import BigNumber from "bignumber.js";
11
11
  import { PrivateKey } from "@/identities/PrivateKey";
12
12
  import { PublicKey } from "@/identities/PublicKey";
13
- import BigNumber from "bignumber.js";
14
13
  export class AbstractTransactionBuilder {
15
14
  constructor(data) {
16
15
  this.transaction = this.getTransactionInstance(data !== null && data !== void 0 ? data : {
17
16
  value: "0",
18
17
  senderPublicKey: "",
19
18
  gasPrice: "5",
19
+ gasLimit: 1000000,
20
20
  nonce: "1",
21
- network: Network.get().chainId(),
22
- gas: 1000000,
23
21
  data: "",
24
22
  });
25
23
  }
26
- gas(gas) {
27
- if (gas instanceof BigNumber) {
28
- gas = gas.toFixed();
24
+ gasLimit(gasLimit) {
25
+ if (gasLimit instanceof BigNumber) {
26
+ gasLimit = gasLimit.toFixed();
29
27
  }
30
- this.transaction.data.gas = gas;
28
+ this.transaction.data.gasLimit = gasLimit;
31
29
  return this;
32
30
  }
33
31
  to(to) {
@@ -45,10 +43,6 @@ export class AbstractTransactionBuilder {
45
43
  this.transaction.data.nonce = nonce;
46
44
  return this;
47
45
  }
48
- network(network) {
49
- this.transaction.data.network = network;
50
- return this;
51
- }
52
46
  sign(passphrase) {
53
47
  return __awaiter(this, void 0, void 0, function* () {
54
48
  this.transaction.data.senderPublicKey = PublicKey.fromPassphrase(passphrase).publicKey;
@@ -60,7 +54,7 @@ export class AbstractTransactionBuilder {
60
54
  legacySecondSign(passphrase, secondPassprase) {
61
55
  return __awaiter(this, void 0, void 0, function* () {
62
56
  yield this.sign(passphrase);
63
- this.transaction = yield this.transaction.legacySecondSign(PrivateKey.fromPassphrase(secondPassprase));
57
+ yield this.transaction.legacySecondSign(PrivateKey.fromPassphrase(secondPassprase));
64
58
  return this;
65
59
  });
66
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractTransaction.d.ts","sourceRoot":"","sources":["../../../src/transactions/types/AbstractTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAIxD,OAA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C;IAQrE,aAAa,IAAI,IAAI;IAOrB,MAAM,IAAI,OAAO;IAWjB,QAAQ,IAAI,eAAe;IA4B3B,MAAM,IAAI,MAAM;IAIhB,IAAI,CAAC,aAAa,UAAQ,GAAG,MAAM;IAInC,SAAS,CAAC,aAAa,UAAQ,GAAG,MAAM;IAI/C,SAAS,CAAC,gBAAgB,IAAI,SAAS;CAYvC"}
@@ -8,11 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { Address } from "@/identities/Address";
11
- import { Constants } from "@/enums/Constants";
11
+ import BigNumber from "bignumber.js";
12
12
  import { PublicKey } from "@/identities/PublicKey";
13
13
  import { Serializer } from "@/transactions/Serializer";
14
14
  import { TransactionUtils } from "@/utils/TransactionUtils";
15
- import BigNumber from "bignumber.js";
16
15
  export class AbstractTransaction {
17
16
  constructor(data) {
18
17
  this.data = Object.assign({}, data);
@@ -55,9 +54,8 @@ export class AbstractTransaction {
55
54
  toObject() {
56
55
  return [
57
56
  "gasPrice",
58
- "network",
59
57
  "hash",
60
- "gas",
58
+ "gasLimit",
61
59
  "nonce",
62
60
  "senderPublicKey",
63
61
  "legacySecondSignature",
@@ -88,9 +86,9 @@ export class AbstractTransaction {
88
86
  return Serializer.new(this).serialize(skipSignature);
89
87
  }
90
88
  recoverPublicKey() {
91
- if (!this.data.v || !this.data.r || !this.data.s) {
89
+ if (this.data.v === undefined || !this.data.r || !this.data.s) {
92
90
  throw new Error("Transaction signature is missing");
93
91
  }
94
- return PublicKey.recover(Buffer.from(this.hash(true), "hex"), BigInt(`0x${this.data.r}`), BigInt(`0x${this.data.s}`), this.data.v - Constants.ETHEREUM_RECOVERY_ID_OFFSET);
92
+ return PublicKey.recover(Buffer.from(this.hash(true), "hex"), BigInt(`0x${this.data.r}`), BigInt(`0x${this.data.s}`), this.data.v);
95
93
  }
96
94
  }
package/dist/types.d.ts CHANGED
@@ -2,10 +2,9 @@ import BigNumber from "bignumber.js";
2
2
  import { Result } from "ethers";
3
3
  export interface TransactionData {
4
4
  gasPrice?: string | null;
5
- network?: number | string | null;
5
+ gasLimit?: string | null;
6
6
  legacySecondSignature?: number | string | null;
7
7
  hash?: string | null;
8
- gas?: string | null;
9
8
  nonce?: number | string | null;
10
9
  senderPublicKey?: string | null;
11
10
  to?: string | null;
@@ -41,11 +40,10 @@ export interface ITransaction {
41
40
  }
42
41
  export interface ITransactionBuilder<T extends ITransactionBuilder<T>> {
43
42
  transaction: ITransaction;
44
- gas(gas: string | BigNumber): T;
43
+ gasLimit(gasLimit: string | BigNumber): T;
45
44
  gasPrice(gasPrice: string | BigNumber): T;
46
45
  to(to: string): T;
47
46
  nonce(nonce: string): T;
48
- network(network: number): T;
49
47
  sign(passphrase: string): Promise<T>;
50
48
  legacySecondSign(passphrase: string, secondPassphrase: string): Promise<T>;
51
49
  verify(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACjC,qBAAqB,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC/C,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,CAAC,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sourceRoot":"","sources":["../../src/utils/TransactionUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,gBAAgB;WACd,QAAQ,CAAC,WAAW,EAAE,eAAe,EAAE,aAAa,UAAQ,GAAG,MAAM;WAkCrE,MAAM,CAAC,WAAW,EAAE,eAAe,EAAE,aAAa,UAAQ,GAAG,MAAM;CAKjF"}
@@ -1,31 +1,33 @@
1
1
  import { encodeRlp, keccak256, toBeArray } from "ethers";
2
- import { Constants } from "@/enums/Constants";
2
+ import { Network } from "@/configuration/Network";
3
3
  export class TransactionUtils {
4
4
  static toBuffer(transaction, skipSignature = false) {
5
- var _a, _b, _c, _d, _e;
5
+ var _a, _b, _c, _d;
6
6
  const fields = [
7
- toBeArray((_a = transaction["network"]) !== null && _a !== void 0 ? _a : 0),
8
7
  toBeArray(transaction["nonce"] ? transaction["nonce"] : 0),
9
- toBeArray(0),
10
- toBeArray((_b = transaction["gasPrice"]) !== null && _b !== void 0 ? _b : 0),
11
- toBeArray((_c = transaction["gas"]) !== null && _c !== void 0 ? _c : 0),
12
- (_d = transaction["to"]) !== null && _d !== void 0 ? _d : "0x",
8
+ toBeArray((_a = transaction["gasPrice"]) !== null && _a !== void 0 ? _a : 0),
9
+ toBeArray((_b = transaction["gasLimit"]) !== null && _b !== void 0 ? _b : 0),
10
+ (_c = transaction["to"]) !== null && _c !== void 0 ? _c : "0x",
13
11
  toBeArray(transaction["value"] ? transaction["value"] : 0),
14
12
  transaction["data"] && transaction["data"].startsWith("0x")
15
13
  ? transaction["data"]
16
- : "0x" + ((_e = transaction["data"]) !== null && _e !== void 0 ? _e : ""),
17
- [],
14
+ : "0x" + ((_d = transaction["data"]) !== null && _d !== void 0 ? _d : ""),
18
15
  ];
19
- if (!skipSignature && transaction["v"] && transaction["r"] && transaction["s"]) {
20
- fields.push(toBeArray(transaction["v"] - Constants.ETHEREUM_RECOVERY_ID_OFFSET));
16
+ if (!skipSignature && transaction["v"] !== undefined && transaction["r"] && transaction["s"]) {
17
+ fields.push(toBeArray(transaction["v"] + Network.get().chainId() * 2 + 35));
21
18
  fields.push("0x" + transaction["r"]);
22
19
  fields.push("0x" + transaction["s"]);
23
20
  if (transaction.legacySecondSignature) {
24
21
  fields.push(`0x${transaction.legacySecondSignature}`);
25
22
  }
26
23
  }
24
+ else {
25
+ // Push chainId + 0s for r and s
26
+ fields.push(toBeArray(Network.get().chainId()), toBeArray(0), toBeArray(0));
27
+ }
28
+ // TODO: second signature handling
27
29
  const encoded = encodeRlp(fields);
28
- const payload = Constants.EIP_1559_PREFIX + encoded.substring(2);
30
+ const payload = encoded.substring(2);
29
31
  return Buffer.from(payload, "hex");
30
32
  }
31
33
  static toHash(transaction, skipSignature = false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkecosystem/typescript-crypto",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
4
4
  "engines": {
5
5
  "node": ">=20.12.2"
6
6
  },
@@ -1,4 +1,3 @@
1
1
  export * from "./AbiFunction";
2
- export * from "./Constants";
3
2
  export * from "./ContractAbiType";
4
3
  export * from "./ContractAddresses";
@@ -1,10 +1,9 @@
1
1
  import * as WIF from "wif";
2
2
 
3
3
  import { ethers, keccak256, sha256, toUtf8Bytes } from "ethers";
4
- import { signAsync } from "@noble/secp256k1";
5
4
 
6
- import { Constants } from "@/enums/Constants";
7
5
  import { Network } from "@/configuration/Network";
6
+ import { signAsync } from "@noble/secp256k1";
8
7
 
9
8
  interface RecoverableSignature {
10
9
  r: string;
@@ -42,7 +41,7 @@ export class PrivateKey {
42
41
  return {
43
42
  r: signature.r.toString(16).padStart(64, "0"),
44
43
  s: signature.s.toString(16).padStart(64, "0"),
45
- v: signature.recovery + Constants.ETHEREUM_RECOVERY_ID_OFFSET,
44
+ v: signature.recovery,
46
45
  };
47
46
  }
48
47
 
@@ -50,7 +49,7 @@ export class PrivateKey {
50
49
  const hash = keccak256("0x" + message).slice(2);
51
50
  const signature = await signAsync(hash, this.privateKey);
52
51
 
53
- const v = signature.recovery + Constants.ETHEREUM_RECOVERY_ID_OFFSET;
52
+ const v = signature.recovery;
54
53
  // @see https://github.com/ArkEcosystem/mainsail/blob/16e50d45dcfbf15b20245f11b123634f0fd0b713/packages/utils/source/format-ecdsa-signature.ts#L2
55
54
  return signature.toCompactHex() + v.toString(16).padStart(2, "0");
56
55
  }
@@ -1,10 +1,4 @@
1
1
  import { AbiResult, ITransaction, TransactionData } from "@/types";
2
-
3
- import BigNumber from "bignumber.js";
4
- import { Constants } from "@/enums/Constants";
5
- import { ContractAbiType } from "@/enums/ContractAbiType";
6
- import { Transfer } from "./types/Transfer";
7
- import { decodeRlp } from "ethers";
8
2
  import {
9
3
  EvmCall,
10
4
  Multipayment,
@@ -15,8 +9,14 @@ import {
15
9
  ValidatorResignation,
16
10
  Vote,
17
11
  } from "./types";
18
- import { AbiFunction } from "@/enums";
12
+
19
13
  import { AbiDecoder } from "@/utils";
14
+ import { AbiFunction } from "@/enums";
15
+ import BigNumber from "bignumber.js";
16
+ import { ContractAbiType } from "@/enums/ContractAbiType";
17
+ import { Network } from "@/configuration/Network";
18
+ import { Transfer } from "./types/Transfer";
19
+ import { decodeRlp } from "ethers";
20
20
 
21
21
  export class Deserializer {
22
22
  SIGNATURE_SIZE = 64;
@@ -27,7 +27,7 @@ export class Deserializer {
27
27
 
28
28
  constructor(serialized: string) {
29
29
  this.serialized = serialized;
30
- this.encoded_rlp = "0x" + serialized.substring(2);
30
+ this.encoded_rlp = "0x" + serialized;
31
31
  }
32
32
 
33
33
  static new(serialized: string): Deserializer {
@@ -38,19 +38,22 @@ export class Deserializer {
38
38
  const decodedRlp = decodeRlp(this.encoded_rlp);
39
39
 
40
40
  const data: TransactionData = {
41
- network: Number(decodedRlp[0]),
42
- nonce: Deserializer.parseNumber(decodedRlp[1] as string),
43
- gasPrice: Deserializer.parseNumber(decodedRlp[3] as string).toString(),
44
- gas: Deserializer.parseNumber(decodedRlp[4] as string).toString(),
45
- to: Deserializer.parseAddress(decodedRlp[5] as string),
46
- value: Deserializer.parseBigNumber(decodedRlp[6] as string),
47
- data: Deserializer.parseHex(decodedRlp[7] as string),
41
+ nonce: Deserializer.parseNumber(decodedRlp[0] as string),
42
+ gasPrice: Deserializer.parseNumber(decodedRlp[1] as string).toString(),
43
+ gasLimit: Deserializer.parseNumber(decodedRlp[2] as string).toString(),
44
+ to: Deserializer.parseAddress(decodedRlp[3] as string),
45
+ value: Deserializer.parseBigNumber(decodedRlp[4] as string),
46
+ data: Deserializer.parseHex(decodedRlp[5] as string),
48
47
  };
49
48
 
50
- if (decodedRlp.length === 12) {
51
- data["v"] = Deserializer.parseNumber(decodedRlp[9] as string) + Constants.ETHEREUM_RECOVERY_ID_OFFSET;
52
- data["r"] = Deserializer.parseHex(decodedRlp[10] as string);
53
- data["s"] = Deserializer.parseHex(decodedRlp[11] as string);
49
+ if (decodedRlp.length >= 9) {
50
+ data["v"] = Deserializer.parseNumber(decodedRlp[6] as string) - (Network.get().chainId() * 2 + 35);
51
+ data["r"] = Deserializer.parseHex(decodedRlp[7] as string);
52
+ data["s"] = Deserializer.parseHex(decodedRlp[8] as string);
53
+
54
+ if (decodedRlp.length === 10) {
55
+ data.legacySecondSignature = decodedRlp[9].toString().slice(2);
56
+ }
54
57
  }
55
58
 
56
59
  const transaction = this.guessTransactionFromData(data);