jcc_wallet 4.0.2 → 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.
- package/dist/jcc-wallet.min.js +54 -30
- package/lib/eccrypto.d.ts +3 -3
- package/lib/eccrypto.js +12 -13
- package/lib/hd/constant.d.ts +3 -1
- package/lib/hd/constant.js +5 -1
- package/lib/hd/eos.plugin.js +4 -4
- package/lib/hd/ethereum.plugin.js +6 -6
- package/lib/hd/index.js +17 -7
- package/lib/hd/plugins.js +4 -1
- package/lib/hd/swtc.plugin.js +6 -6
- package/lib/hd/tron.plugin.js +1 -1
- package/lib/index.js +17 -7
- package/lib/jingchangWallet.js +21 -11
- package/lib/minify-eosjs/PrivateKey.d.ts +1 -1
- package/lib/minify-eosjs/PublicKey.d.ts +1 -1
- package/lib/minify-eosjs/Signature.d.ts +1 -1
- package/lib/minify-eosjs/eosjs-key-conversions.d.ts +1 -1
- package/lib/minify-eosjs/eosjs-key-conversions.js +4 -4
- package/lib/minify-eosjs/eosjs-numeric.js +8 -8
- package/lib/minify-ethereumjs-util/account.js +2 -2
- package/lib/minify-ethereumjs-util/signature.js +3 -3
- package/lib/minify-swtc-keypair/address-codec.js +3 -3
- package/lib/minify-swtc-keypair/index.js +32 -43
- package/lib/minify-swtc-keypair/sha512.d.ts +1 -1
- package/lib/minify-swtc-keypair/sha512.js +4 -4
- package/lib/minify-swtc-keypair/utils.js +4 -4
- package/lib/minify-tron/crypto.js +2 -2
- package/lib/util/index.js +6 -6
- package/package.json +10 -16
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Factory = void 0;
|
|
4
7
|
const address_codec_1 = require("./address-codec");
|
|
5
8
|
const utils_1 = require("./utils");
|
|
6
|
-
const
|
|
7
|
-
const sha512_1 = require("
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const hash = (message) => {
|
|
14
|
-
return sha512_1.sha512
|
|
15
|
-
.create()
|
|
16
|
-
.update(message)
|
|
17
|
-
.digest()
|
|
18
|
-
.slice(0, 32);
|
|
19
|
-
};
|
|
20
|
-
const funcHexToBytes = (hex) => {
|
|
21
|
-
const bytes = [];
|
|
22
|
-
for (let c = 0; c < hex.length; c += 2) {
|
|
23
|
-
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
24
|
-
}
|
|
25
|
-
return bytes;
|
|
26
|
-
};
|
|
9
|
+
const utils_js_1 = require("@noble/curves/abstract/utils.js");
|
|
10
|
+
const sha512_1 = __importDefault(require("./sha512"));
|
|
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");
|
|
27
16
|
function assert(condition, message) {
|
|
28
17
|
if (!condition) {
|
|
29
18
|
throw new Error(message || "Assertion failed");
|
|
@@ -32,11 +21,11 @@ function assert(condition, message) {
|
|
|
32
21
|
const SECP256K1_PREFIX = "00";
|
|
33
22
|
const ED25519_PREFIX = "ED";
|
|
34
23
|
const computePublicKeyHash = (publicKeyBytes) => {
|
|
35
|
-
const hash256 =
|
|
24
|
+
const hash256 = sha2_js_1.sha256
|
|
36
25
|
.create()
|
|
37
26
|
.update(publicKeyBytes)
|
|
38
27
|
.digest();
|
|
39
|
-
const hash160 =
|
|
28
|
+
const hash160 = legacy_js_1.ripemd160
|
|
40
29
|
.create()
|
|
41
30
|
.update(hash256)
|
|
42
31
|
.digest();
|
|
@@ -47,20 +36,20 @@ const Factory = (alphabet) => {
|
|
|
47
36
|
const secp256k1 = {
|
|
48
37
|
deriveKeypair: (entropy, options) => {
|
|
49
38
|
const derived = (0, utils_1.derivePrivateKey)(entropy, options);
|
|
50
|
-
const privateKey = (0,
|
|
39
|
+
const privateKey = (0, utils_js_1.bytesToHex)((0, utils_js_1.numberToBytesBE)(derived, 32));
|
|
51
40
|
return {
|
|
52
41
|
privateKey: SECP256K1_PREFIX + privateKey,
|
|
53
|
-
publicKey:
|
|
42
|
+
publicKey: secp256k1_js_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toHex(true)
|
|
54
43
|
};
|
|
55
44
|
},
|
|
56
45
|
deriveKeypairWithPrivateKey: (rawPrivateKey) => {
|
|
57
46
|
const privateKey = rawPrivateKey.toUpperCase();
|
|
58
|
-
const publicKey =
|
|
47
|
+
const publicKey = secp256k1_js_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toHex(true);
|
|
59
48
|
return { privateKey: SECP256K1_PREFIX + privateKey, publicKey };
|
|
60
49
|
},
|
|
61
50
|
sign(message, privateKey) {
|
|
62
|
-
const signHash =
|
|
63
|
-
return
|
|
51
|
+
const signHash = sha512_1.default.half(message);
|
|
52
|
+
return secp256k1_js_1.secp256k1.sign(signHash, privateKey, {
|
|
64
53
|
// "Canonical" signatures
|
|
65
54
|
lowS: true,
|
|
66
55
|
// Would fail tests if signatures aren't deterministic
|
|
@@ -70,31 +59,31 @@ const Factory = (alphabet) => {
|
|
|
70
59
|
.toUpperCase();
|
|
71
60
|
},
|
|
72
61
|
verify(message, signature, publicKey) {
|
|
73
|
-
const signHash =
|
|
74
|
-
return
|
|
62
|
+
const signHash = sha512_1.default.half(message);
|
|
63
|
+
return secp256k1_js_1.secp256k1.verify(signature, signHash, publicKey);
|
|
75
64
|
}
|
|
76
65
|
};
|
|
77
66
|
const ed25519 = {
|
|
78
67
|
deriveKeypair: (entropy) => {
|
|
79
|
-
const rawPrivateKey =
|
|
80
|
-
const privateKey = (0,
|
|
81
|
-
const pub =
|
|
68
|
+
const rawPrivateKey = sha512_1.default.half(entropy);
|
|
69
|
+
const privateKey = (0, utils_js_1.bytesToHex)(rawPrivateKey);
|
|
70
|
+
const pub = ed25519_js_1.ed25519.getPublicKey(privateKey);
|
|
82
71
|
return {
|
|
83
72
|
privateKey: ED25519_PREFIX + privateKey,
|
|
84
|
-
publicKey: ED25519_PREFIX + (0,
|
|
73
|
+
publicKey: ED25519_PREFIX + (0, utils_js_1.bytesToHex)(pub)
|
|
85
74
|
};
|
|
86
75
|
},
|
|
87
76
|
deriveKeypairWithPrivateKey: (rawPrivateKey) => {
|
|
88
77
|
const privateKey = rawPrivateKey.toUpperCase();
|
|
89
|
-
const pub =
|
|
90
|
-
return { privateKey: ED25519_PREFIX + privateKey, publicKey: ED25519_PREFIX + (0,
|
|
78
|
+
const pub = ed25519_js_1.ed25519.getPublicKey(privateKey);
|
|
79
|
+
return { privateKey: ED25519_PREFIX + privateKey, publicKey: ED25519_PREFIX + (0, utils_js_1.bytesToHex)(pub) };
|
|
91
80
|
},
|
|
92
81
|
sign(message, privateKey) {
|
|
93
|
-
const buf =
|
|
94
|
-
return (0,
|
|
82
|
+
const buf = ed25519_js_1.ed25519.sign(message, privateKey);
|
|
83
|
+
return (0, utils_js_1.bytesToHex)(buf).toUpperCase();
|
|
95
84
|
},
|
|
96
85
|
verify(message, signature, publicKey) {
|
|
97
|
-
return
|
|
86
|
+
return ed25519_js_1.ed25519.verify(message, Buffer.from(signature, "hex"), publicKey);
|
|
98
87
|
}
|
|
99
88
|
};
|
|
100
89
|
const deriveKeyPair = (seed, algorithm) => {
|
|
@@ -123,13 +112,13 @@ const Factory = (alphabet) => {
|
|
|
123
112
|
try {
|
|
124
113
|
deriveKeyPair(secret);
|
|
125
114
|
}
|
|
126
|
-
catch (
|
|
115
|
+
catch (_a) {
|
|
127
116
|
return false;
|
|
128
117
|
}
|
|
129
118
|
return true;
|
|
130
119
|
};
|
|
131
120
|
const deriveAddress = (pk) => {
|
|
132
|
-
return addressCodec.encodeAccountID(Buffer.from(computePublicKeyHash(Buffer.from((0,
|
|
121
|
+
return addressCodec.encodeAccountID(Buffer.from(computePublicKeyHash(Buffer.from((0, utils_js_1.hexToBytes)(pk)))));
|
|
133
122
|
};
|
|
134
123
|
const fromSecret = (secret, algorithm) => {
|
|
135
124
|
const keypair = deriveKeyPair(secret, algorithm);
|
|
@@ -141,7 +130,7 @@ const Factory = (alphabet) => {
|
|
|
141
130
|
};
|
|
142
131
|
const generate = (options) => {
|
|
143
132
|
assert(!options.entropy || options.entropy.length >= 16, "entropy too short");
|
|
144
|
-
const entropy = options.entropy ? options.entropy.slice(0, 16) : (0,
|
|
133
|
+
const entropy = options.entropy ? options.entropy.slice(0, 16) : (0, utils_js_2.randomBytes)(16);
|
|
145
134
|
const type = options.algorithm === "ed25519" ? "ed25519" : "secp256k1";
|
|
146
135
|
const secret = addressCodec.encodeSeed(entropy, type);
|
|
147
136
|
const keypair = deriveKeyPair(secret);
|
|
@@ -159,7 +148,7 @@ const Factory = (alphabet) => {
|
|
|
159
148
|
generate,
|
|
160
149
|
fromSecret,
|
|
161
150
|
addressCodec,
|
|
162
|
-
hash,
|
|
151
|
+
hash: sha512_1.default.half,
|
|
163
152
|
sign: (message, privateKey) => {
|
|
164
153
|
const keypair = deriveKeyPair(privateKey);
|
|
165
154
|
if (privateKey.startsWith(ED25519_PREFIX)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default class Sha512 {
|
|
2
|
-
hash: import("@noble/hashes/utils").Hash<import("@noble/hashes/
|
|
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
|
|
4
|
-
const
|
|
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 =
|
|
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,
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
10
|
-
const
|
|
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,
|
|
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,
|
|
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,
|
|
70
|
+
salt: opts.salt || Buffer.from((0, utils_js_1.randomBytes)(32)).toString("hex")
|
|
71
71
|
};
|
|
72
|
-
const derivedKey = (0,
|
|
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
|
+
"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": "^
|
|
57
|
-
"@typescript-eslint/parser": "^
|
|
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": "
|
|
84
|
-
"typescript-eslint": "^
|
|
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
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
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": "^
|
|
101
|
-
"ethers": "^6.
|
|
94
|
+
"ethereum-cryptography": "^3.2.0",
|
|
95
|
+
"ethers": "^6.16.0",
|
|
102
96
|
"lockr": "^0.8.5"
|
|
103
97
|
},
|
|
104
98
|
"sideEffects": false,
|