jcc_wallet 4.0.8 → 4.0.12
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 +31 -54
- package/lib/minify-eosjs/PrivateKey.d.ts +1 -2
- package/lib/minify-eosjs/PrivateKey.js +2 -1
- package/lib/minify-eosjs/Signature.d.ts +1 -2
- package/lib/minify-eosjs/Signature.js +2 -1
- package/lib/minify-swtc-keypair/index.js +2 -2
- package/lib/minify-tron/crypto.d.ts +1 -1
- package/lib/minify-tron/crypto.js +5 -7
- package/lib/minify-tron/message.js +23 -16
- package/lib/util/index.js +13 -2
- package/package.json +40 -5
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* rewrite curves
|
|
5
5
|
*/
|
|
6
|
-
import BN from "bn.js";
|
|
7
6
|
import { Key, KeyType } from "./eosjs-numeric";
|
|
8
7
|
import { ProjPointType, CurveFn } from "@noble/curves/abstract/weierstrass.js";
|
|
9
8
|
import { PublicKey, Signature } from "./eosjs-key-conversions";
|
|
@@ -21,7 +20,7 @@ export declare class PrivateKey {
|
|
|
21
20
|
/** Retrieve the public key from a private key */
|
|
22
21
|
getPublicKey(): PublicKey;
|
|
23
22
|
/** Sign a message or hashed message digest with private key */
|
|
24
|
-
sign(data:
|
|
23
|
+
sign(data: string | Uint8Array, shouldHash?: boolean, encoding?: BufferEncoding): Signature;
|
|
25
24
|
/** Validate a private key */
|
|
26
25
|
isValid(): boolean;
|
|
27
26
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.PrivateKey = void 0;
|
|
9
9
|
const eosjs_numeric_1 = require("./eosjs-numeric");
|
|
10
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
10
11
|
const eosjs_key_conversions_1 = require("./eosjs-key-conversions");
|
|
11
12
|
/** Represents/stores a private key and provides easy conversion for use with `elliptic` lib */
|
|
12
13
|
class PrivateKey {
|
|
@@ -41,7 +42,7 @@ class PrivateKey {
|
|
|
41
42
|
if (typeof data === "string") {
|
|
42
43
|
data = Buffer.from(data, encoding);
|
|
43
44
|
}
|
|
44
|
-
data =
|
|
45
|
+
data = (0, sha2_js_1.sha256)(data);
|
|
45
46
|
}
|
|
46
47
|
let tries = 0;
|
|
47
48
|
let signature;
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Key, KeyType } from "./eosjs-numeric";
|
|
7
7
|
import { PublicKey } from "./eosjs-key-conversions";
|
|
8
|
-
import { BN } from "bn.js";
|
|
9
8
|
import { CurveFn, SignatureType, RecoveredSignatureType } from "@noble/curves/abstract/weierstrass.js";
|
|
10
9
|
/** Represents/stores a Signature and provides easy conversion for use with `elliptic` lib */
|
|
11
10
|
export declare class Signature {
|
|
@@ -30,5 +29,5 @@ export declare class Signature {
|
|
|
30
29
|
/** Get key type from signature */
|
|
31
30
|
getType(): KeyType;
|
|
32
31
|
/** Recover a public key from a message or hashed message digest and signature */
|
|
33
|
-
recover(data:
|
|
32
|
+
recover(data: string | Uint8Array, shouldHash?: boolean, encoding?: BufferEncoding): PublicKey;
|
|
34
33
|
}
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
exports.Signature = void 0;
|
|
9
9
|
const eosjs_numeric_1 = require("./eosjs-numeric");
|
|
10
10
|
const eosjs_key_conversions_1 = require("./eosjs-key-conversions");
|
|
11
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
11
12
|
const bn_utils_1 = require("./bn-utils");
|
|
12
13
|
/** Represents/stores a Signature and provides easy conversion for use with `elliptic` lib */
|
|
13
14
|
class Signature {
|
|
@@ -89,7 +90,7 @@ class Signature {
|
|
|
89
90
|
if (typeof data === "string") {
|
|
90
91
|
data = Buffer.from(data, encoding);
|
|
91
92
|
}
|
|
92
|
-
data =
|
|
93
|
+
data = (0, sha2_js_1.sha256)(data);
|
|
93
94
|
}
|
|
94
95
|
const sig = this.toRecoveredSignature();
|
|
95
96
|
const recoveredPublicKey = sig.recoverPublicKey(data);
|
|
@@ -55,12 +55,12 @@ const Factory = (alphabet) => {
|
|
|
55
55
|
// Would fail tests if signatures aren't deterministic
|
|
56
56
|
extraEntropy: undefined
|
|
57
57
|
})
|
|
58
|
-
.toDERHex(
|
|
58
|
+
.toDERHex()
|
|
59
59
|
.toUpperCase();
|
|
60
60
|
},
|
|
61
61
|
verify(message, signature, publicKey) {
|
|
62
62
|
const signHash = sha512_1.default.half(message);
|
|
63
|
-
return secp256k1_js_1.secp256k1.verify(signature, signHash, publicKey);
|
|
63
|
+
return secp256k1_js_1.secp256k1.verify((0, utils_js_1.hexToBytes)(signature), signHash, (0, utils_js_1.hexToBytes)(publicKey));
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
const ed25519 = {
|
|
@@ -3,5 +3,5 @@ export declare function isAddressValid(base58Str: any): boolean;
|
|
|
3
3
|
export declare function computeAddress(pubBytes: any): any[];
|
|
4
4
|
export declare function getAddressFromPriKey(priKeyBytes: any): any[];
|
|
5
5
|
export declare function getPubKeyFromPriKey(priKeyBytes: any): any[];
|
|
6
|
-
export declare function SHA256(msgBytes: any):
|
|
6
|
+
export declare function SHA256(msgBytes: any): number[];
|
|
7
7
|
export declare function pkToAddress(privateKey: any, strict?: boolean): string;
|
|
@@ -13,7 +13,9 @@ const code_1 = require("./code");
|
|
|
13
13
|
const base58_1 = require("./base58");
|
|
14
14
|
const bytes_1 = require("./bytes");
|
|
15
15
|
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
16
|
-
const
|
|
16
|
+
const keccak_js_1 = require("ethereum-cryptography/keccak.js");
|
|
17
|
+
const sha256_js_1 = require("ethereum-cryptography/sha256.js");
|
|
18
|
+
const utils_js_1 = require("ethereum-cryptography/utils.js");
|
|
17
19
|
function normalizePrivateKeyBytes(priKeyBytes) {
|
|
18
20
|
return (0, code_1.hexStr2byteArray)((0, bytes_1.byteArray2hexStr)(priKeyBytes).padStart(64, "0"));
|
|
19
21
|
}
|
|
@@ -50,9 +52,7 @@ function isAddressValid(base58Str) {
|
|
|
50
52
|
function computeAddress(pubBytes) {
|
|
51
53
|
if (pubBytes.length === 65)
|
|
52
54
|
pubBytes = pubBytes.slice(1);
|
|
53
|
-
const hash = (0,
|
|
54
|
-
.toString()
|
|
55
|
-
.substring(2);
|
|
55
|
+
const hash = (0, utils_js_1.toHex)((0, keccak_js_1.keccak256)(new Uint8Array(pubBytes)));
|
|
56
56
|
const addressHex = address_1.ADDRESS_PREFIX + hash.substring(24);
|
|
57
57
|
return (0, code_1.hexStr2byteArray)(addressHex);
|
|
58
58
|
}
|
|
@@ -71,9 +71,7 @@ function getPubKeyFromPriKey(priKeyBytes) {
|
|
|
71
71
|
return pubkeyBytes;
|
|
72
72
|
}
|
|
73
73
|
function SHA256(msgBytes) {
|
|
74
|
-
|
|
75
|
-
const hashHex = (0, crypto_1.sha256)("0x" + msgHex).replace(/^0x/, "");
|
|
76
|
-
return (0, code_1.hexStr2byteArray)(hashHex);
|
|
74
|
+
return Array.from((0, sha256_js_1.sha256)(new Uint8Array(msgBytes)));
|
|
77
75
|
}
|
|
78
76
|
function pkToAddress(privateKey, strict = false) {
|
|
79
77
|
const com_priKeyBytes = (0, code_1.hexStr2byteArray)(privateKey, strict);
|
|
@@ -5,37 +5,44 @@ exports.TRON_MESSAGE_PREFIX = void 0;
|
|
|
5
5
|
exports.hashMessage = hashMessage;
|
|
6
6
|
exports.signMessage = signMessage;
|
|
7
7
|
exports.verifyMessage = verifyMessage;
|
|
8
|
-
const address_1 = require("./address");
|
|
9
8
|
const crypto_1 = require("./crypto");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const joinSignature = (splitSig) => crypto_2.Signature.from(splitSig).serialized;
|
|
9
|
+
const secp256k1_js_1 = require("@noble/curves/secp256k1.js");
|
|
10
|
+
const keccak_js_1 = require("ethereum-cryptography/keccak.js");
|
|
11
|
+
const utils_js_1 = require("ethereum-cryptography/utils.js");
|
|
12
|
+
const bytes_1 = require("../minify-ethereumjs-util/bytes");
|
|
15
13
|
exports.TRON_MESSAGE_PREFIX = "\x19TRON Signed Message:\n";
|
|
16
|
-
function
|
|
14
|
+
function normalizeMessage(message) {
|
|
17
15
|
if (typeof message === "string") {
|
|
18
|
-
|
|
16
|
+
return (0, utils_js_1.utf8ToBytes)(message);
|
|
19
17
|
}
|
|
20
18
|
if (Array.isArray(message)) {
|
|
21
|
-
|
|
19
|
+
return new Uint8Array(message);
|
|
22
20
|
}
|
|
23
|
-
return
|
|
21
|
+
return message;
|
|
22
|
+
}
|
|
23
|
+
function hashMessage(message) {
|
|
24
|
+
const messageBytes = normalizeMessage(message);
|
|
25
|
+
return (0, bytes_1.bytesToHex)((0, keccak_js_1.keccak256)((0, bytes_1.concatBytes)((0, utils_js_1.utf8ToBytes)(exports.TRON_MESSAGE_PREFIX), (0, utils_js_1.utf8ToBytes)(String(messageBytes.length)), messageBytes)));
|
|
24
26
|
}
|
|
25
27
|
function signMessage(message, privateKey) {
|
|
26
28
|
if (!privateKey.match(/^0x/)) {
|
|
27
29
|
privateKey = "0x" + privateKey;
|
|
28
30
|
}
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
return
|
|
31
|
+
const messageDigest = (0, bytes_1.hexToBytes)(hashMessage(message));
|
|
32
|
+
const signature = secp256k1_js_1.secp256k1.sign(messageDigest, (0, bytes_1.hexToBytes)(privateKey));
|
|
33
|
+
const serialized = (0, bytes_1.concatBytes)(signature.toCompactRawBytes(), new Uint8Array([signature.recovery + 27]));
|
|
34
|
+
return (0, bytes_1.bytesToHex)(serialized);
|
|
33
35
|
}
|
|
34
36
|
function verifyMessage(message, signature) {
|
|
35
37
|
if (!signature.match(/^0x/)) {
|
|
36
38
|
signature = "0x" + signature;
|
|
37
39
|
}
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
+
const signatureBytes = (0, bytes_1.hexToBytes)(signature);
|
|
41
|
+
const recovery = signatureBytes[64] >= 27 ? signatureBytes[64] - 27 : signatureBytes[64];
|
|
42
|
+
const recovered = secp256k1_js_1.secp256k1.Signature.fromCompact(signatureBytes.subarray(0, 64))
|
|
43
|
+
.addRecoveryBit(recovery)
|
|
44
|
+
.recoverPublicKey((0, bytes_1.hexToBytes)(hashMessage(message)))
|
|
45
|
+
.toRawBytes(false);
|
|
46
|
+
const base58Address = (0, crypto_1.getBase58CheckAddress)((0, crypto_1.computeAddress)(Array.from(recovered)));
|
|
40
47
|
return base58Address;
|
|
41
48
|
}
|
package/lib/util/index.js
CHANGED
|
@@ -10,6 +10,17 @@ const utils_js_1 = require("@noble/hashes/utils.js");
|
|
|
10
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
|
+
// Constant-time buffer comparison to prevent MAC timing attacks
|
|
14
|
+
function equalConstTime(b1, b2) {
|
|
15
|
+
if (b1.length !== b2.length) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
let res = 0;
|
|
19
|
+
for (let i = 0; i < b1.length; i++) {
|
|
20
|
+
res |= b1[i] ^ b2[i];
|
|
21
|
+
}
|
|
22
|
+
return res === 0;
|
|
23
|
+
}
|
|
13
24
|
const isEmptyPlainObject = (obj) => {
|
|
14
25
|
const isPlain = (0, is_plain_object_1.default)(obj);
|
|
15
26
|
if (!isPlain) {
|
|
@@ -45,7 +56,7 @@ const decrypt = async (password, encryptData) => {
|
|
|
45
56
|
.create()
|
|
46
57
|
.update(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
|
|
47
58
|
.digest();
|
|
48
|
-
if (Buffer.from(mac).
|
|
59
|
+
if (!equalConstTime(Buffer.from(mac), Buffer.from(encryptData.mac, "hex"))) {
|
|
49
60
|
throw new Error(constant_1.PASSWORD_IS_WRONG);
|
|
50
61
|
}
|
|
51
62
|
const buf = await (0, aes_1.decrypt)(ciphertext, derivedKey.slice(0, 16), iv, "aes-128-ctr");
|
|
@@ -64,7 +75,7 @@ const encrypt = async (password, data, opts) => {
|
|
|
64
75
|
const iv = opts.iv || Buffer.from((0, utils_js_1.randomBytes)(16)).toString("hex");
|
|
65
76
|
const kdfparams = {
|
|
66
77
|
dklen: opts.dklen || 32,
|
|
67
|
-
n: opts.n ||
|
|
78
|
+
n: opts.n || 16384,
|
|
68
79
|
p: opts.p || 1,
|
|
69
80
|
r: opts.r || 8,
|
|
70
81
|
salt: opts.salt || Buffer.from((0, utils_js_1.randomBytes)(32)).toString("hex")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jcc_wallet",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.12",
|
|
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",
|
|
@@ -75,26 +75,61 @@
|
|
|
75
75
|
"karma-mocha": "^2.0.1",
|
|
76
76
|
"karma-webpack": "^5.0.1",
|
|
77
77
|
"mocha": "^10.2.0",
|
|
78
|
-
"node-polyfill-webpack-plugin": "^4.0.0",
|
|
79
78
|
"prettier": "^1.19.1",
|
|
80
79
|
"pretty-quick": "^2.0.1",
|
|
81
80
|
"sinon": "^17.0.1",
|
|
82
81
|
"ts-loader": "^9.5.1",
|
|
83
82
|
"typescript": "5.7.2",
|
|
84
83
|
"typescript-eslint": "^8.48.1",
|
|
85
|
-
"webpack": "^5.
|
|
84
|
+
"webpack": "^5.106.2",
|
|
86
85
|
"webpack-bundle-analyzer": "^4.10.1",
|
|
87
86
|
"webpack-cli": "^5.1.4"
|
|
88
87
|
},
|
|
89
88
|
"dependencies": {
|
|
89
|
+
"@noble/curves": "1.9.7",
|
|
90
|
+
"@noble/hashes": "1.8.0",
|
|
91
|
+
"@scure/bip32": "1.7.0",
|
|
90
92
|
"base-x": "^4.0.1",
|
|
91
93
|
"bip39": "^3.1.0",
|
|
92
94
|
"bip44-constants": "^396.0.0",
|
|
95
|
+
"bn.js": "5.2.3",
|
|
96
|
+
"buffer": "^6.0.3",
|
|
93
97
|
"clone-deep": "^4.0.1",
|
|
94
98
|
"ethereum-cryptography": "^3.2.0",
|
|
95
|
-
"ethers": "^6.16.0",
|
|
96
99
|
"lockr": "^0.8.5"
|
|
97
100
|
},
|
|
98
101
|
"sideEffects": false,
|
|
99
|
-
"packageManager": "yarn@4.0.0-rc.48"
|
|
102
|
+
"packageManager": "yarn@4.0.0-rc.48",
|
|
103
|
+
"overrides": {
|
|
104
|
+
"elliptic": "6.6.1",
|
|
105
|
+
"flatted": "3.4.2",
|
|
106
|
+
"lodash": "4.18.1",
|
|
107
|
+
"follow-redirects": "1.16.0",
|
|
108
|
+
"qs": "6.15.1",
|
|
109
|
+
"fast-uri": "3.1.2",
|
|
110
|
+
"picomatch": "4.0.4",
|
|
111
|
+
"socket.io-parser": "4.2.6",
|
|
112
|
+
"serialize-javascript": "7.0.5",
|
|
113
|
+
"babel-plugin-istanbul": "8.0.2",
|
|
114
|
+
"bn.js": "5.2.3",
|
|
115
|
+
"diff": "5.2.2",
|
|
116
|
+
"@noble/curves": "1.9.7",
|
|
117
|
+
"@noble/hashes": "1.8.0"
|
|
118
|
+
},
|
|
119
|
+
"resolutions": {
|
|
120
|
+
"elliptic": "6.6.1",
|
|
121
|
+
"flatted": "3.4.2",
|
|
122
|
+
"lodash": "4.18.1",
|
|
123
|
+
"follow-redirects": "1.16.0",
|
|
124
|
+
"qs": "6.15.1",
|
|
125
|
+
"fast-uri": "3.1.2",
|
|
126
|
+
"picomatch": "4.0.4",
|
|
127
|
+
"socket.io-parser": "4.2.6",
|
|
128
|
+
"serialize-javascript": "7.0.5",
|
|
129
|
+
"babel-plugin-istanbul": "8.0.2",
|
|
130
|
+
"bn.js": "5.2.3",
|
|
131
|
+
"diff": "5.2.2",
|
|
132
|
+
"@noble/curves": "1.9.7",
|
|
133
|
+
"@noble/hashes": "1.8.0"
|
|
134
|
+
}
|
|
100
135
|
}
|