jcc_wallet 4.0.3 → 4.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.
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Factory = void 0;
7
7
  const address_codec_1 = require("./address-codec");
8
8
  const utils_1 = require("./utils");
9
- const utils_2 = require("@noble/curves/abstract/utils");
9
+ const utils_js_1 = require("@noble/curves/abstract/utils.js");
10
10
  const sha512_1 = __importDefault(require("./sha512"));
11
- const sha256_1 = require("@noble/hashes/sha256");
12
- const ripemd160_1 = require("@noble/hashes/ripemd160");
13
- const ed25519_1 = require("@noble/curves/ed25519");
14
- const secp256k1_1 = require("@noble/curves/secp256k1");
15
- const utils_3 = require("@noble/hashes/utils");
11
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
12
+ const legacy_js_1 = require("@noble/hashes/legacy.js");
13
+ const ed25519_js_1 = require("@noble/curves/ed25519.js");
14
+ const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
15
+ const utils_js_2 = require("@noble/hashes/utils.js");
16
16
  function assert(condition, message) {
17
17
  if (!condition) {
18
18
  throw new Error(message || "Assertion failed");
@@ -21,11 +21,11 @@ function assert(condition, message) {
21
21
  const SECP256K1_PREFIX = "00";
22
22
  const ED25519_PREFIX = "ED";
23
23
  const computePublicKeyHash = (publicKeyBytes) => {
24
- const hash256 = sha256_1.sha256
24
+ const hash256 = sha2_js_1.sha256
25
25
  .create()
26
26
  .update(publicKeyBytes)
27
27
  .digest();
28
- const hash160 = ripemd160_1.ripemd160
28
+ const hash160 = legacy_js_1.ripemd160
29
29
  .create()
30
30
  .update(hash256)
31
31
  .digest();
@@ -36,20 +36,20 @@ const Factory = (alphabet) => {
36
36
  const secp256k1 = {
37
37
  deriveKeypair: (entropy, options) => {
38
38
  const derived = (0, utils_1.derivePrivateKey)(entropy, options);
39
- const privateKey = (0, utils_2.bytesToHex)((0, utils_2.numberToBytesBE)(derived, 32));
39
+ const privateKey = (0, utils_js_1.bytesToHex)((0, utils_js_1.numberToBytesBE)(derived, 32));
40
40
  return {
41
41
  privateKey: SECP256K1_PREFIX + privateKey,
42
- publicKey: secp256k1_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toHex(true)
42
+ publicKey: secp256k1_js_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toHex(true)
43
43
  };
44
44
  },
45
45
  deriveKeypairWithPrivateKey: (rawPrivateKey) => {
46
46
  const privateKey = rawPrivateKey.toUpperCase();
47
- const publicKey = secp256k1_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toHex(true);
47
+ const publicKey = secp256k1_js_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toHex(true);
48
48
  return { privateKey: SECP256K1_PREFIX + privateKey, publicKey };
49
49
  },
50
50
  sign(message, privateKey) {
51
51
  const signHash = sha512_1.default.half(message);
52
- return secp256k1_1.secp256k1.sign(signHash, privateKey, {
52
+ return secp256k1_js_1.secp256k1.sign(signHash, privateKey, {
53
53
  // "Canonical" signatures
54
54
  lowS: true,
55
55
  // Would fail tests if signatures aren't deterministic
@@ -60,30 +60,30 @@ const Factory = (alphabet) => {
60
60
  },
61
61
  verify(message, signature, publicKey) {
62
62
  const signHash = sha512_1.default.half(message);
63
- return secp256k1_1.secp256k1.verify(signature, signHash, publicKey);
63
+ return secp256k1_js_1.secp256k1.verify(signature, signHash, publicKey);
64
64
  }
65
65
  };
66
66
  const ed25519 = {
67
67
  deriveKeypair: (entropy) => {
68
68
  const rawPrivateKey = sha512_1.default.half(entropy);
69
- const privateKey = (0, utils_2.bytesToHex)(rawPrivateKey);
70
- const pub = ed25519_1.ed25519.getPublicKey(privateKey);
69
+ const privateKey = (0, utils_js_1.bytesToHex)(rawPrivateKey);
70
+ const pub = ed25519_js_1.ed25519.getPublicKey(privateKey);
71
71
  return {
72
72
  privateKey: ED25519_PREFIX + privateKey,
73
- publicKey: ED25519_PREFIX + (0, utils_2.bytesToHex)(pub)
73
+ publicKey: ED25519_PREFIX + (0, utils_js_1.bytesToHex)(pub)
74
74
  };
75
75
  },
76
76
  deriveKeypairWithPrivateKey: (rawPrivateKey) => {
77
77
  const privateKey = rawPrivateKey.toUpperCase();
78
- const pub = ed25519_1.ed25519.getPublicKey(privateKey);
79
- return { privateKey: ED25519_PREFIX + privateKey, publicKey: ED25519_PREFIX + (0, utils_2.bytesToHex)(pub) };
78
+ const pub = ed25519_js_1.ed25519.getPublicKey(privateKey);
79
+ return { privateKey: ED25519_PREFIX + privateKey, publicKey: ED25519_PREFIX + (0, utils_js_1.bytesToHex)(pub) };
80
80
  },
81
81
  sign(message, privateKey) {
82
- const buf = ed25519_1.ed25519.sign(message, privateKey);
83
- return (0, utils_2.bytesToHex)(buf).toUpperCase();
82
+ const buf = ed25519_js_1.ed25519.sign(message, privateKey);
83
+ return (0, utils_js_1.bytesToHex)(buf).toUpperCase();
84
84
  },
85
85
  verify(message, signature, publicKey) {
86
- return ed25519_1.ed25519.verify(message, Buffer.from(signature, "hex"), publicKey);
86
+ return ed25519_js_1.ed25519.verify(message, Buffer.from(signature, "hex"), publicKey);
87
87
  }
88
88
  };
89
89
  const deriveKeyPair = (seed, algorithm) => {
@@ -112,13 +112,13 @@ const Factory = (alphabet) => {
112
112
  try {
113
113
  deriveKeyPair(secret);
114
114
  }
115
- catch (_) {
115
+ catch (_a) {
116
116
  return false;
117
117
  }
118
118
  return true;
119
119
  };
120
120
  const deriveAddress = (pk) => {
121
- return addressCodec.encodeAccountID(Buffer.from(computePublicKeyHash(Buffer.from((0, utils_2.hexToBytes)(pk)))));
121
+ return addressCodec.encodeAccountID(Buffer.from(computePublicKeyHash(Buffer.from((0, utils_js_1.hexToBytes)(pk)))));
122
122
  };
123
123
  const fromSecret = (secret, algorithm) => {
124
124
  const keypair = deriveKeyPair(secret, algorithm);
@@ -130,7 +130,7 @@ const Factory = (alphabet) => {
130
130
  };
131
131
  const generate = (options) => {
132
132
  assert(!options.entropy || options.entropy.length >= 16, "entropy too short");
133
- const entropy = options.entropy ? options.entropy.slice(0, 16) : (0, utils_3.randomBytes)(16);
133
+ const entropy = options.entropy ? options.entropy.slice(0, 16) : (0, utils_js_2.randomBytes)(16);
134
134
  const type = options.algorithm === "ed25519" ? "ed25519" : "secp256k1";
135
135
  const secret = addressCodec.encodeSeed(entropy, type);
136
136
  const keypair = deriveKeyPair(secret);
@@ -1,5 +1,5 @@
1
1
  export default class Sha512 {
2
- hash: import("@noble/hashes/utils").Hash<import("@noble/hashes/sha512").SHA512>;
2
+ hash: import("@noble/hashes/utils").Hash<import("@noble/hashes/utils").Hash<any>>;
3
3
  static half(input: any): Uint8Array;
4
4
  add(bytes: any): this;
5
5
  addU32(i: number): this;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@noble/curves/abstract/utils");
4
- const sha512_1 = require("@noble/hashes/sha512");
3
+ const utils_js_1 = require("@noble/curves/abstract/utils.js");
4
+ const sha2_js_1 = require("@noble/hashes/sha2.js");
5
5
  class Sha512 {
6
6
  constructor() {
7
7
  // instantiate empty sha512 hash
8
- this.hash = sha512_1.sha512.create();
8
+ this.hash = sha2_js_1.sha512.create();
9
9
  }
10
10
  static half(input) {
11
11
  return new Sha512().add(input).first256();
@@ -26,7 +26,7 @@ class Sha512 {
26
26
  return this.finish().slice(0, 32);
27
27
  }
28
28
  first256BigInt() {
29
- return (0, utils_1.bytesToNumberBE)(this.first256());
29
+ return (0, utils_js_1.bytesToNumberBE)(this.first256());
30
30
  }
31
31
  }
32
32
  exports.default = Sha512;
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.derivePrivateKey = derivePrivateKey;
7
- const secp256k1_1 = require("@noble/curves/secp256k1");
7
+ const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
8
8
  const sha512_1 = __importDefault(require("./sha512"));
9
9
  const ZERO = BigInt(0);
10
10
  function deriveScalar(bytes, discrim) {
11
- const order = secp256k1_1.secp256k1.CURVE.n;
11
+ const order = secp256k1_js_1.secp256k1.CURVE.n;
12
12
  for (let i = 0; i <= 4294967295; i++) {
13
13
  // We hash the bytes to find a 256-bit number, looping until we are sure it
14
14
  // is less than the order of the curve.
@@ -46,7 +46,7 @@ function deriveScalar(bytes, discrim) {
46
46
  */
47
47
  function derivePrivateKey(seed, opts = {}) {
48
48
  const root = opts.validator;
49
- const order = secp256k1_1.secp256k1.CURVE.n;
49
+ const order = secp256k1_js_1.secp256k1.CURVE.n;
50
50
  // This private generator represents the `root` private key, and is what's
51
51
  // used by validators for signing when a keypair is generated from a seed.
52
52
  const privateGen = deriveScalar(seed);
@@ -54,7 +54,7 @@ function derivePrivateKey(seed, opts = {}) {
54
54
  // As returned by validation_create for a given seed
55
55
  return privateGen;
56
56
  }
57
- const publicGen = secp256k1_1.secp256k1.ProjectivePoint.BASE.multiply(privateGen).toRawBytes(true);
57
+ const publicGen = secp256k1_js_1.secp256k1.ProjectivePoint.BASE.multiply(privateGen).toRawBytes(true);
58
58
  // A seed can generate many keypairs as a function of the seed and a uint32.
59
59
  // Almost everyone just uses the first account, `0`.
60
60
  const accountIndex = opts.accountIndex || 0;
@@ -12,7 +12,7 @@ const address_1 = require("./address");
12
12
  const code_1 = require("./code");
13
13
  const base58_1 = require("./base58");
14
14
  const bytes_1 = require("./bytes");
15
- const secp256k1_1 = require("@noble/curves/secp256k1");
15
+ const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
16
16
  const crypto_1 = require("ethers/crypto");
17
17
  function normalizePrivateKeyBytes(priKeyBytes) {
18
18
  return (0, code_1.hexStr2byteArray)((0, bytes_1.byteArray2hexStr)(priKeyBytes).padStart(64, "0"));
@@ -61,7 +61,7 @@ function getAddressFromPriKey(priKeyBytes) {
61
61
  return computeAddress(pubBytes);
62
62
  }
63
63
  function getPubKeyFromPriKey(priKeyBytes) {
64
- const pubkey = secp256k1_1.secp256k1.ProjectivePoint.fromPrivateKey(new Uint8Array(normalizePrivateKeyBytes(priKeyBytes)));
64
+ const pubkey = secp256k1_js_1.secp256k1.ProjectivePoint.fromPrivateKey(new Uint8Array(normalizePrivateKeyBytes(priKeyBytes)));
65
65
  const x = pubkey.x;
66
66
  const y = pubkey.y;
67
67
  const xHex = x.toString(16).padStart(64, "0");
package/lib/util/index.js CHANGED
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.encryptWallet = exports.encryptContact = exports.encrypt = exports.decrypt = exports.isEmptyPlainObject = void 0;
7
7
  const keccak_js_1 = require("ethereum-cryptography/keccak.js");
8
8
  const aes_1 = require("ethereum-cryptography/aes");
9
- const utils_1 = require("@noble/hashes/utils");
10
- const scrypt_1 = require("@noble/hashes/scrypt");
9
+ const utils_js_1 = require("@noble/hashes/utils.js");
10
+ const scrypt_js_1 = require("@noble/hashes/scrypt.js");
11
11
  const constant_1 = require("../constant");
12
12
  const is_plain_object_1 = __importDefault(require("is-plain-object"));
13
13
  const isEmptyPlainObject = (obj) => {
@@ -34,7 +34,7 @@ const decrypt = async (password, encryptData) => {
34
34
  }
35
35
  const iv = Buffer.from(encryptData.crypto.iv, "hex");
36
36
  const kdfparams = encryptData.crypto.kdfparams;
37
- const derivedKey = (0, scrypt_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
37
+ const derivedKey = (0, scrypt_js_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
38
38
  N: kdfparams.n,
39
39
  r: kdfparams.r,
40
40
  p: kdfparams.p,
@@ -61,15 +61,15 @@ exports.decrypt = decrypt;
61
61
  * @returns {IKeystoreModel}
62
62
  */
63
63
  const encrypt = async (password, data, opts) => {
64
- const iv = opts.iv || Buffer.from((0, utils_1.randomBytes)(16)).toString("hex");
64
+ const iv = opts.iv || Buffer.from((0, utils_js_1.randomBytes)(16)).toString("hex");
65
65
  const kdfparams = {
66
66
  dklen: opts.dklen || 32,
67
67
  n: opts.n || 4096,
68
68
  p: opts.p || 1,
69
69
  r: opts.r || 8,
70
- salt: opts.salt || Buffer.from((0, utils_1.randomBytes)(32)).toString("hex")
70
+ salt: opts.salt || Buffer.from((0, utils_js_1.randomBytes)(32)).toString("hex")
71
71
  };
72
- const derivedKey = (0, scrypt_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
72
+ const derivedKey = (0, scrypt_js_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
73
73
  N: kdfparams.n,
74
74
  r: kdfparams.r,
75
75
  p: kdfparams.p,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jcc_wallet",
3
- "version": "4.0.3",
3
+ "version": "4.0.4",
4
4
  "description": "Toolkit of wallet to manage multiple chains & support multiple keystores for each chain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -53,8 +53,8 @@
53
53
  "@types/chai": "^4.3.16",
54
54
  "@types/jest": "^29.5.12",
55
55
  "@types/node": "^20.14.10",
56
- "@typescript-eslint/eslint-plugin": "^7.12.0",
57
- "@typescript-eslint/parser": "^7.12.0",
56
+ "@typescript-eslint/eslint-plugin": "^8.48.1",
57
+ "@typescript-eslint/parser": "^8.48.1",
58
58
  "babel-jest": "^29.7.0",
59
59
  "babel-loader": "^9.1.3",
60
60
  "chai": "^4.2.0",
@@ -80,25 +80,19 @@
80
80
  "pretty-quick": "^2.0.1",
81
81
  "sinon": "^17.0.1",
82
82
  "ts-loader": "^9.5.1",
83
- "typescript": "^5.4.5",
84
- "typescript-eslint": "^7.12.0",
83
+ "typescript": "5.7.2",
84
+ "typescript-eslint": "^8.48.1",
85
85
  "webpack": "^5.89.0",
86
86
  "webpack-bundle-analyzer": "^4.10.1",
87
87
  "webpack-cli": "^5.1.4"
88
88
  },
89
- "resolutions": {
90
- "@noble/curves": "^1.4.2",
91
- "@noble/hashes": "^1.4.0",
92
- "buffer": "^6.0.3"
93
- },
94
89
  "dependencies": {
95
- "@scure/bip32": "^1.4.0",
96
- "base-x": "^4.0.0",
97
- "bip39": "^3.0.4",
98
- "bip44-constants": "^123.0.0",
90
+ "base-x": "^4.0.1",
91
+ "bip39": "^3.1.0",
92
+ "bip44-constants": "^396.0.0",
99
93
  "clone-deep": "^4.0.1",
100
- "ethereum-cryptography": "^2.2.1",
101
- "ethers": "^6.13.1",
94
+ "ethereum-cryptography": "^3.2.0",
95
+ "ethers": "^6.16.0",
102
96
  "lockr": "^0.8.5"
103
97
  },
104
98
  "sideEffects": false,