jcc_wallet 3.0.1 → 4.0.0
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 +57 -0
- package/lib/constant.d.ts +8 -0
- package/lib/constant.js +18 -0
- package/lib/constant.js.map +1 -0
- package/lib/hd/constant.d.ts +26 -0
- package/lib/hd/constant.js +56 -0
- package/lib/hd/constant.js.map +1 -0
- package/lib/hd/eos.plugin.d.ts +5 -0
- package/lib/hd/eos.plugin.js +70 -0
- package/lib/hd/eos.plugin.js.map +1 -0
- package/lib/hd/ethereum.plugin.d.ts +6 -0
- package/lib/hd/ethereum.plugin.js +120 -0
- package/lib/hd/ethereum.plugin.js.map +1 -0
- package/lib/hd/index.d.ts +228 -0
- package/lib/hd/index.js +382 -0
- package/lib/hd/index.js.map +1 -0
- package/lib/hd/plugins.d.ts +11 -0
- package/lib/hd/plugins.js +39 -0
- package/lib/hd/plugins.js.map +1 -0
- package/lib/hd/swtc.plugin.d.ts +2 -0
- package/lib/hd/swtc.plugin.js +86 -0
- package/lib/hd/swtc.plugin.js.map +1 -0
- package/lib/hd/tron.plugin.d.ts +5 -0
- package/lib/hd/tron.plugin.js +62 -0
- package/lib/hd/tron.plugin.js.map +1 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +60 -0
- package/lib/index.js.map +1 -0
- package/lib/jingchangWallet.d.ts +273 -0
- package/lib/jingchangWallet.js +531 -0
- package/lib/jingchangWallet.js.map +1 -0
- package/lib/minify-ethereumjs-util/account.d.ts +1 -0
- package/lib/minify-ethereumjs-util/account.js +22 -0
- package/lib/minify-ethereumjs-util/account.js.map +1 -0
- package/lib/minify-ethereumjs-util/bytes.d.ts +7 -0
- package/lib/minify-ethereumjs-util/bytes.js +100 -0
- package/lib/minify-ethereumjs-util/bytes.js.map +1 -0
- package/lib/minify-ethereumjs-util/constants.d.ts +4 -0
- package/lib/minify-ethereumjs-util/constants.js +9 -0
- package/lib/minify-ethereumjs-util/constants.js.map +1 -0
- package/lib/minify-ethereumjs-util/helper.d.ts +5 -0
- package/lib/minify-ethereumjs-util/helper.js +16 -0
- package/lib/minify-ethereumjs-util/helper.js.map +1 -0
- package/lib/minify-ethereumjs-util/internal.d.ts +8 -0
- package/lib/minify-ethereumjs-util/internal.js +33 -0
- package/lib/minify-ethereumjs-util/internal.js.map +1 -0
- package/lib/minify-ethereumjs-util/signature.d.ts +13 -0
- package/lib/minify-ethereumjs-util/signature.js +45 -0
- package/lib/minify-ethereumjs-util/signature.js.map +1 -0
- package/lib/minify-swtc-keypair/address-codec.d.ts +16 -0
- package/lib/minify-swtc-keypair/address-codec.js +166 -0
- package/lib/minify-swtc-keypair/address-codec.js.map +1 -0
- package/lib/minify-swtc-keypair/index.d.ts +25 -0
- package/lib/minify-swtc-keypair/index.js +178 -0
- package/lib/minify-swtc-keypair/index.js.map +1 -0
- package/lib/minify-swtc-keypair/sha512.d.ts +9 -0
- package/lib/minify-swtc-keypair/sha512.js +33 -0
- package/lib/minify-swtc-keypair/sha512.js.map +1 -0
- package/lib/minify-swtc-keypair/utils.d.ts +13 -0
- package/lib/minify-swtc-keypair/utils.js +63 -0
- package/lib/minify-swtc-keypair/utils.js.map +1 -0
- package/lib/minify-tron/address.d.ts +6 -0
- package/lib/minify-tron/address.js +11 -0
- package/lib/minify-tron/address.js.map +1 -0
- package/lib/minify-tron/base58.d.ts +2 -0
- package/lib/minify-tron/base58.js +67 -0
- package/lib/minify-tron/base58.js.map +1 -0
- package/lib/minify-tron/bytes.d.ts +2 -0
- package/lib/minify-tron/bytes.js +23 -0
- package/lib/minify-tron/bytes.js.map +1 -0
- package/lib/minify-tron/code.d.ts +3 -0
- package/lib/minify-tron/code.js +56 -0
- package/lib/minify-tron/code.js.map +1 -0
- package/lib/minify-tron/crypto.d.ts +7 -0
- package/lib/minify-tron/crypto.js +83 -0
- package/lib/minify-tron/crypto.js.map +1 -0
- package/lib/minify-tron/message.d.ts +4 -0
- package/lib/minify-tron/message.js +42 -0
- package/lib/minify-tron/message.js.map +1 -0
- package/lib/types.d.ts +103 -0
- package/lib/types.js +16 -0
- package/lib/types.js.map +1 -0
- package/lib/util/index.d.ts +22 -0
- package/lib/util/index.js +100 -0
- package/lib/util/index.js.map +1 -0
- package/package.json +22 -17
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const PASSWORD_IS_REQUIRED = "password is required";
|
|
2
|
+
declare const WALLET_IS_EMPTY = "wallet is empty";
|
|
3
|
+
declare const PASSWORD_IS_WRONG = "password is wrong";
|
|
4
|
+
declare const KEYSTORE_IS_INVALID = "keystore is invalid";
|
|
5
|
+
declare const ETH_PASSWORD_IS_WRONG = "ethereum password is wrong";
|
|
6
|
+
declare const SECRET_IS_INVALID = "secret is invalid";
|
|
7
|
+
declare const ADDRESS_IS_EXISTENT = "address is existent";
|
|
8
|
+
export { ADDRESS_IS_EXISTENT, ETH_PASSWORD_IS_WRONG, KEYSTORE_IS_INVALID, PASSWORD_IS_REQUIRED, PASSWORD_IS_WRONG, SECRET_IS_INVALID, WALLET_IS_EMPTY };
|
package/lib/constant.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WALLET_IS_EMPTY = exports.SECRET_IS_INVALID = exports.PASSWORD_IS_WRONG = exports.PASSWORD_IS_REQUIRED = exports.KEYSTORE_IS_INVALID = exports.ETH_PASSWORD_IS_WRONG = exports.ADDRESS_IS_EXISTENT = void 0;
|
|
4
|
+
const PASSWORD_IS_REQUIRED = "password is required";
|
|
5
|
+
exports.PASSWORD_IS_REQUIRED = PASSWORD_IS_REQUIRED;
|
|
6
|
+
const WALLET_IS_EMPTY = "wallet is empty";
|
|
7
|
+
exports.WALLET_IS_EMPTY = WALLET_IS_EMPTY;
|
|
8
|
+
const PASSWORD_IS_WRONG = "password is wrong";
|
|
9
|
+
exports.PASSWORD_IS_WRONG = PASSWORD_IS_WRONG;
|
|
10
|
+
const KEYSTORE_IS_INVALID = "keystore is invalid";
|
|
11
|
+
exports.KEYSTORE_IS_INVALID = KEYSTORE_IS_INVALID;
|
|
12
|
+
const ETH_PASSWORD_IS_WRONG = `ethereum ${PASSWORD_IS_WRONG}`;
|
|
13
|
+
exports.ETH_PASSWORD_IS_WRONG = ETH_PASSWORD_IS_WRONG;
|
|
14
|
+
const SECRET_IS_INVALID = `secret is invalid`;
|
|
15
|
+
exports.SECRET_IS_INVALID = SECRET_IS_INVALID;
|
|
16
|
+
const ADDRESS_IS_EXISTENT = `address is existent`;
|
|
17
|
+
exports.ADDRESS_IS_EXISTENT = ADDRESS_IS_EXISTENT;
|
|
18
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../src/constant.ts"],"names":[],"mappings":";;;AAAA,MAAM,oBAAoB,GAAG,sBAAsB,CAAC;AAYlD,oDAAoB;AAXtB,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAcxC,0CAAe;AAbjB,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAW5C,8CAAiB;AAVnB,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAQhD,kDAAmB;AAPrB,MAAM,qBAAqB,GAAG,YAAY,iBAAiB,EAAE,CAAC;AAM5D,sDAAqB;AALvB,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAS5C,8CAAiB;AARnB,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAGhD,kDAAmB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare enum BIP44Chain {
|
|
2
|
+
BITCOIN = 2147483648,
|
|
3
|
+
BSC = 2147492654,
|
|
4
|
+
EOS = 2147483842,
|
|
5
|
+
TRON = 2147483843,
|
|
6
|
+
ETC = 2147483709,
|
|
7
|
+
ETH = 2147483708,
|
|
8
|
+
HECO = 2147484658,
|
|
9
|
+
MOAC = 2147483962,
|
|
10
|
+
POLYGON = 2147484614,
|
|
11
|
+
RIPPLE = 2147483792,
|
|
12
|
+
SWTC = 2147483963,
|
|
13
|
+
CALL = 2147484281,
|
|
14
|
+
BVCADT = 2399141888,
|
|
15
|
+
STREAM = 2399141889,
|
|
16
|
+
BIZAIN = 2399141890
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* get bip44 chain constant
|
|
20
|
+
*
|
|
21
|
+
* @param {number} chain chain index number
|
|
22
|
+
* @returns {number} bip44 chain constant
|
|
23
|
+
*/
|
|
24
|
+
declare const getBIP44Chain: (chain: number) => any;
|
|
25
|
+
declare const BIP44ChainMap: Map<BIP44Chain, string>;
|
|
26
|
+
export { BIP44Chain, BIP44ChainMap, getBIP44Chain };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBIP44Chain = exports.BIP44ChainMap = exports.BIP44Chain = void 0;
|
|
7
|
+
const bip44_constants_1 = __importDefault(require("bip44-constants"));
|
|
8
|
+
// BIP44 链常量定义
|
|
9
|
+
var BIP44Chain;
|
|
10
|
+
(function (BIP44Chain) {
|
|
11
|
+
BIP44Chain[BIP44Chain["BITCOIN"] = 2147483648] = "BITCOIN";
|
|
12
|
+
BIP44Chain[BIP44Chain["BSC"] = 2147492654] = "BSC";
|
|
13
|
+
BIP44Chain[BIP44Chain["EOS"] = 2147483842] = "EOS";
|
|
14
|
+
BIP44Chain[BIP44Chain["TRON"] = 2147483843] = "TRON";
|
|
15
|
+
BIP44Chain[BIP44Chain["ETC"] = 2147483709] = "ETC";
|
|
16
|
+
BIP44Chain[BIP44Chain["ETH"] = 2147483708] = "ETH";
|
|
17
|
+
BIP44Chain[BIP44Chain["HECO"] = 2147484658] = "HECO";
|
|
18
|
+
BIP44Chain[BIP44Chain["MOAC"] = 2147483962] = "MOAC";
|
|
19
|
+
BIP44Chain[BIP44Chain["POLYGON"] = 2147484614] = "POLYGON";
|
|
20
|
+
BIP44Chain[BIP44Chain["RIPPLE"] = 2147483792] = "RIPPLE";
|
|
21
|
+
BIP44Chain[BIP44Chain["SWTC"] = 2147483963] = "SWTC";
|
|
22
|
+
BIP44Chain[BIP44Chain["CALL"] = 2147484281] = "CALL";
|
|
23
|
+
// not register in bip44, customize setting range: 0x8f000000-0x8fffffff
|
|
24
|
+
BIP44Chain[BIP44Chain["BVCADT"] = 2399141888] = "BVCADT";
|
|
25
|
+
BIP44Chain[BIP44Chain["STREAM"] = 2399141889] = "STREAM";
|
|
26
|
+
BIP44Chain[BIP44Chain["BIZAIN"] = 2399141890] = "BIZAIN";
|
|
27
|
+
})(BIP44Chain || (exports.BIP44Chain = BIP44Chain = {}));
|
|
28
|
+
/**
|
|
29
|
+
* get bip44 chain constant
|
|
30
|
+
*
|
|
31
|
+
* @param {number} chain chain index number
|
|
32
|
+
* @returns {number} bip44 chain constant
|
|
33
|
+
*/
|
|
34
|
+
const getBIP44Chain = (chain) => {
|
|
35
|
+
return bip44_constants_1.default.filter((e) => e[0] === chain);
|
|
36
|
+
};
|
|
37
|
+
exports.getBIP44Chain = getBIP44Chain;
|
|
38
|
+
const BIP44ChainMap = new Map([
|
|
39
|
+
[BIP44Chain.BITCOIN, "bitcoin"],
|
|
40
|
+
[BIP44Chain.BSC, "bsc"],
|
|
41
|
+
[BIP44Chain.EOS, "eos"],
|
|
42
|
+
[BIP44Chain.TRON, "tron"],
|
|
43
|
+
[BIP44Chain.ETC, "etc"],
|
|
44
|
+
[BIP44Chain.ETH, "ethereum"],
|
|
45
|
+
[BIP44Chain.HECO, "heco"],
|
|
46
|
+
[BIP44Chain.MOAC, "moac"],
|
|
47
|
+
[BIP44Chain.POLYGON, "polygon"],
|
|
48
|
+
[BIP44Chain.RIPPLE, "ripple"],
|
|
49
|
+
[BIP44Chain.SWTC, "jingtum"],
|
|
50
|
+
[BIP44Chain.CALL, "call"],
|
|
51
|
+
[BIP44Chain.BVCADT, "bvcadt"],
|
|
52
|
+
[BIP44Chain.STREAM, "stream"],
|
|
53
|
+
[BIP44Chain.BIZAIN, "bizain"]
|
|
54
|
+
]);
|
|
55
|
+
exports.BIP44ChainMap = BIP44ChainMap;
|
|
56
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/hd/constant.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAwC;AAExC,cAAc;AACd,IAAK,UAkBJ;AAlBD,WAAK,UAAU;IACb,0DAAoB,CAAA;IACpB,kDAAgB,CAAA;IAChB,kDAAgB,CAAA;IAChB,oDAAiB,CAAA;IACjB,kDAAgB,CAAA;IAChB,kDAAgB,CAAA;IAChB,oDAAiB,CAAA;IACjB,oDAAiB,CAAA;IACjB,0DAAoB,CAAA;IACpB,wDAAmB,CAAA;IACnB,oDAAiB,CAAA;IACjB,oDAAiB,CAAA;IAEjB,wEAAwE;IACxE,wDAAmB,CAAA;IACnB,wDAAmB,CAAA;IACnB,wDAAmB,CAAA;AACrB,CAAC,EAlBI,UAAU,0BAAV,UAAU,QAkBd;AAED;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,KAAa,EAAO,EAAE;IAC3C,OAAO,yBAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;AACjD,CAAC,CAAC;AAoBkC,sCAAa;AAlBjD,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC;IAC/B,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC;IACvB,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC;IACvB,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;IACzB,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC;IACvB,CAAC,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC;IAC5B,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;IACzB,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;IACzB,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,CAAC;IAC/B,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC7B,CAAC,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC;IAC5B,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC;IACzB,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC7B,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC7B,CAAC,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC9B,CAAC,CAAC;AAEkB,sCAAa"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plugin = void 0;
|
|
4
|
+
const PublicKey = require("eosjs-ecc/lib/key_public");
|
|
5
|
+
const PrivateKey = require("eosjs-ecc/lib/key_private");
|
|
6
|
+
const Signature = require("eosjs-ecc/lib/signature");
|
|
7
|
+
const wif = require("wif");
|
|
8
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
9
|
+
const jcc_common_1 = require("jcc_common");
|
|
10
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
11
|
+
exports.plugin = {
|
|
12
|
+
checkPrivateKey(privateKey) {
|
|
13
|
+
// check and cut swtc keypair lib add prefix 00
|
|
14
|
+
return privateKey.length === 66 ? privateKey.substring(2) : privateKey;
|
|
15
|
+
},
|
|
16
|
+
address(key) {
|
|
17
|
+
if (key.privateKey) {
|
|
18
|
+
const privateKey = exports.plugin.checkPrivateKey(key.privateKey);
|
|
19
|
+
// TODO: secp256k1 version confict fixed, but need refactor later
|
|
20
|
+
const rawPublicKey = Buffer.from(secp256k1_1.secp256k1.ProjectivePoint.fromPrivateKey(privateKey).toRawBytes(true));
|
|
21
|
+
const eosPublicKey = PublicKey(rawPublicKey).toString();
|
|
22
|
+
return eosPublicKey;
|
|
23
|
+
}
|
|
24
|
+
if (key.publicKey) {
|
|
25
|
+
const rawPublicKey = Buffer.from(key.publicKey, "hex");
|
|
26
|
+
const eosPublicKey = PublicKey(rawPublicKey).toString();
|
|
27
|
+
return eosPublicKey;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
},
|
|
31
|
+
isValidAddress(address) {
|
|
32
|
+
return PublicKey.isValid(address);
|
|
33
|
+
},
|
|
34
|
+
isValidSecret(secret) {
|
|
35
|
+
try {
|
|
36
|
+
const privateKey = exports.plugin.checkPrivateKey((0, jcc_common_1.filterOx)(secret));
|
|
37
|
+
const buffer = Buffer.from(privateKey, "hex");
|
|
38
|
+
const eosPrivateKey = wif.encode(128, buffer, false);
|
|
39
|
+
return PrivateKey.isValid(eosPrivateKey);
|
|
40
|
+
}
|
|
41
|
+
catch (_) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
hash(message) {
|
|
46
|
+
return Buffer.from(sha256_1.sha256
|
|
47
|
+
.create()
|
|
48
|
+
.update(message)
|
|
49
|
+
.digest()).toString("hex");
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param message message content, let message is "\x19Ethereum Signed Message:\n" + message.length + message, match web3.accounts.sign function
|
|
54
|
+
* @param privateKey private key
|
|
55
|
+
* @returns signature string
|
|
56
|
+
*/
|
|
57
|
+
sign(message, privateKey) {
|
|
58
|
+
const buffer = Buffer.from(exports.plugin.checkPrivateKey((0, jcc_common_1.filterOx)(privateKey)), "hex");
|
|
59
|
+
const eosPrivateKey = wif.encode(128, buffer, false);
|
|
60
|
+
return Signature.sign(message, eosPrivateKey, "utf8").toString();
|
|
61
|
+
},
|
|
62
|
+
verify(message, signature, address) {
|
|
63
|
+
return exports.plugin.recover(message, signature) === address;
|
|
64
|
+
},
|
|
65
|
+
recover(message, signature) {
|
|
66
|
+
const s = Signature.from(signature);
|
|
67
|
+
return s.recover(message, "utf8").toString();
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=eos.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eos.plugin.js","sourceRoot":"","sources":["../../src/hd/eos.plugin.ts"],"names":[],"mappings":";;;AAAA,MAAM,SAAS,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AACtD,MAAM,UAAU,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACxD,MAAM,SAAS,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACrD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAC3B,uDAAoD;AACpD,2CAAsC;AAEtC,iDAA8C;AAMjC,QAAA,MAAM,GAAe;IAChC,eAAe,CAAC,UAAkB;QAChC,+CAA+C;QAC/C,OAAO,UAAU,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IACzE,CAAC;IACD,OAAO,CAAC,GAAa;QACnB,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC;YACnB,MAAM,UAAU,GAAG,cAAM,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC1D,iEAAiE;YACjE,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,qBAAS,CAAC,eAAe,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;YACxG,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;YACxD,OAAO,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AAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAErD,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;IACnE,CAAC;IACD,MAAM,CAAC,OAAe,EAAE,SAAiB,EAAE,OAAe;QACxD,OAAO,cAAM,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,KAAK,OAAO,CAAC;IACxD,CAAC;IACD,OAAO,CAAC,OAAe,EAAE,SAAiB;QACxC,MAAM,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/C,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.plugin = void 0;
|
|
7
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
8
|
+
const keccak_js_1 = require("ethereum-cryptography/keccak.js");
|
|
9
|
+
const bytes_1 = require("../minify-ethereumjs-util/bytes");
|
|
10
|
+
const internal_1 = require("../minify-ethereumjs-util/internal");
|
|
11
|
+
const signature_1 = require("../minify-ethereumjs-util/signature");
|
|
12
|
+
const account_1 = require("../minify-ethereumjs-util/account");
|
|
13
|
+
const jcc_common_1 = require("jcc_common");
|
|
14
|
+
const constant_1 = require("../constant");
|
|
15
|
+
const scrypt_1 = require("@noble/hashes/scrypt");
|
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
17
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
18
|
+
const isObject = (obj) => {
|
|
19
|
+
return Object.prototype.toString.call(obj) === "[object Object]";
|
|
20
|
+
};
|
|
21
|
+
exports.plugin = {
|
|
22
|
+
checkPrivateKey(privateKey) {
|
|
23
|
+
// check and cut swtc keypair lib add prefix 00
|
|
24
|
+
return privateKey.length === 66 ? privateKey.substring(2) : privateKey;
|
|
25
|
+
},
|
|
26
|
+
address(key) {
|
|
27
|
+
if (key.privateKey) {
|
|
28
|
+
const privateKey = exports.plugin.checkPrivateKey(key.privateKey);
|
|
29
|
+
return exports.plugin.getAddress(privateKey);
|
|
30
|
+
}
|
|
31
|
+
if (key.publicKey) {
|
|
32
|
+
const address = (0, account_1.pubToAddress)(Buffer.from(key.publicKey, "hex"));
|
|
33
|
+
return (0, bytes_1.bytesToHex)(address);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
},
|
|
37
|
+
isValidAddress(address) {
|
|
38
|
+
if (typeof address !== "string") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
return /^(0x)?[0-9a-fA-F]{40}$/.test((0, internal_1.stripHexPrefix)(address));
|
|
42
|
+
},
|
|
43
|
+
getAddress(secret) {
|
|
44
|
+
if (!exports.plugin.isValidSecret(secret)) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const pk = secp256k1_1.secp256k1.ProjectivePoint.fromPrivateKey(Buffer.from((0, internal_1.stripHexPrefix)(secret), "hex")).toHex(false);
|
|
48
|
+
return (0, bytes_1.bytesToHex)((0, account_1.pubToAddress)(Buffer.from(pk.substring(2), "hex")));
|
|
49
|
+
},
|
|
50
|
+
isValidSecret(secret) {
|
|
51
|
+
try {
|
|
52
|
+
return secp256k1_1.secp256k1.utils.isValidPrivateKey(Buffer.from((0, internal_1.stripHexPrefix)(secret), "hex"));
|
|
53
|
+
}
|
|
54
|
+
catch (_) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
hash(message) {
|
|
59
|
+
const hash = (0, bytes_1.bytesToHex)((0, keccak_js_1.keccak256)(Buffer.from(message, "utf-8")));
|
|
60
|
+
return (0, internal_1.stripHexPrefix)(hash);
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param message message content, let message is "\x19Ethereum Signed Message:\n" + message.length + message, match web3.accounts.sign function
|
|
65
|
+
* @param privateKey private key
|
|
66
|
+
* @returns signature string
|
|
67
|
+
*/
|
|
68
|
+
sign(message, privateKey) {
|
|
69
|
+
const key = exports.plugin.checkPrivateKey(privateKey).toLowerCase();
|
|
70
|
+
const hash = (0, keccak_js_1.keccak256)(Buffer.from(message, "utf-8"));
|
|
71
|
+
const signed = (0, signature_1.ecsign)(hash, Buffer.from(key, "hex"));
|
|
72
|
+
return (0, internal_1.stripHexPrefix)((0, bytes_1.bytesToHex)(signed.r)) + (0, internal_1.stripHexPrefix)((0, bytes_1.bytesToHex)(signed.s)) + signed.v.toString(16);
|
|
73
|
+
},
|
|
74
|
+
verify(message, signature, address) {
|
|
75
|
+
return exports.plugin.recover(message, signature) === address;
|
|
76
|
+
},
|
|
77
|
+
recover(message, signature) {
|
|
78
|
+
const hash = (0, keccak_js_1.keccak256)(Buffer.from(message, "utf-8"));
|
|
79
|
+
const r = Buffer.from(Buffer.from(signature.substring(0, 64), "hex"));
|
|
80
|
+
const s = Buffer.from(Buffer.from(signature.substring(64, 128), "hex"));
|
|
81
|
+
const bytes = (0, bytes_1.hexToBytes)("0x" + signature.substring(128, 130));
|
|
82
|
+
const pk = (0, signature_1.ecrecover)(hash, (0, bytes_1.bytesToBigInt)(bytes), r, s);
|
|
83
|
+
const address = (0, account_1.pubToAddress)(Buffer.from(pk));
|
|
84
|
+
return (0, bytes_1.bytesToHex)(address);
|
|
85
|
+
},
|
|
86
|
+
decryptKeystore(password, encryptData) {
|
|
87
|
+
if (!isObject(encryptData)) {
|
|
88
|
+
throw new Error(constant_1.KEYSTORE_IS_INVALID);
|
|
89
|
+
}
|
|
90
|
+
const cryptoData = encryptData.Crypto || encryptData.crypto;
|
|
91
|
+
if ((0, jcc_common_1.isEmptyObject)(cryptoData) || (0, jcc_common_1.isEmptyObject)(cryptoData.cipherparams) || (0, jcc_common_1.isEmptyObject)(cryptoData.kdfparams)) {
|
|
92
|
+
throw new Error(constant_1.KEYSTORE_IS_INVALID);
|
|
93
|
+
}
|
|
94
|
+
const iv = Buffer.from(cryptoData.cipherparams.iv, "hex");
|
|
95
|
+
const kdfparams = cryptoData.kdfparams;
|
|
96
|
+
const derivedKey = (0, scrypt_1.scrypt)(Buffer.from(password), Buffer.from(kdfparams.salt, "hex"), {
|
|
97
|
+
N: kdfparams.n,
|
|
98
|
+
r: kdfparams.r,
|
|
99
|
+
p: kdfparams.p,
|
|
100
|
+
dkLen: kdfparams.dklen
|
|
101
|
+
});
|
|
102
|
+
const ciphertext = Buffer.from(cryptoData.ciphertext, "hex");
|
|
103
|
+
const mac = keccak_js_1.keccak256
|
|
104
|
+
.create()
|
|
105
|
+
.update(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
|
|
106
|
+
.digest();
|
|
107
|
+
if (Buffer.from(mac).toString("hex") !== cryptoData.mac) {
|
|
108
|
+
throw new Error(constant_1.ETH_PASSWORD_IS_WRONG);
|
|
109
|
+
}
|
|
110
|
+
const decipher = crypto_1.default.createDecipheriv("aes-128-ctr", derivedKey.slice(0, 16), iv);
|
|
111
|
+
const seed = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
112
|
+
return seed.toString("hex");
|
|
113
|
+
},
|
|
114
|
+
createWallet() {
|
|
115
|
+
const priv = (0, utils_1.randomBytes)(32);
|
|
116
|
+
const address = exports.plugin.getAddress((0, bytes_1.bytesToHex)(priv));
|
|
117
|
+
return { address, secret: (0, bytes_1.bytesToHex)(priv) };
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=ethereum.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ethereum.plugin.js","sourceRoot":"","sources":["../../src/hd/eth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IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC,GAAG,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CAAC,gCAAqB,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,QAAQ,GAAG,gBAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACrF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,YAAY;QACV,MAAM,IAAI,GAAG,IAAA,mBAAW,EAAC,EAAE,CAAC,CAAC;QAC7B,MAAM,OAAO,GAAG,cAAM,CAAC,UAAU,CAAC,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAC,CAAC;QACpD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAA,kBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;IAC/C,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { BIP44Chain, BIP44ChainMap, getBIP44Chain } from "./constant";
|
|
2
|
+
import { IBIP44Path, IHDPlugin, IKeyPair, IMnemonic } from "../types";
|
|
3
|
+
export { BIP44Chain, BIP44ChainMap, getBIP44Chain };
|
|
4
|
+
export declare class HDWallet {
|
|
5
|
+
private _secret;
|
|
6
|
+
private _mnemonic;
|
|
7
|
+
private _address;
|
|
8
|
+
private _keypair;
|
|
9
|
+
private _path;
|
|
10
|
+
/**
|
|
11
|
+
* generate hd wallet
|
|
12
|
+
*
|
|
13
|
+
* @param {any} opt options of generate, like:
|
|
14
|
+
* {
|
|
15
|
+
* mnemonic: "world list", // optional
|
|
16
|
+
* // see also:bip39 https://github.com/bitcoinjs/bip39/tree/master/ts_src/wordlists
|
|
17
|
+
* // language attribute appears with mnemonic attribute
|
|
18
|
+
* language: english default/chinese_simplified/...
|
|
19
|
+
* secret: "secret string", // optional, default this coding rules of SWTC chain
|
|
20
|
+
* keypair: {privateKey: "xxxx", publicKey: "xxxx"}
|
|
21
|
+
* }
|
|
22
|
+
* way of create hd wallet
|
|
23
|
+
* 1. {mnemonic: "xxx", language:"english"}
|
|
24
|
+
* 2. {secret: "xxxx"}
|
|
25
|
+
* 3. {keypair: {....}, path:{....}}
|
|
26
|
+
* @returns {object} return hd wallet object
|
|
27
|
+
*/
|
|
28
|
+
constructor(opt: any);
|
|
29
|
+
/**
|
|
30
|
+
* generate mnemonic
|
|
31
|
+
*
|
|
32
|
+
* @static
|
|
33
|
+
* @param {number} len strength of random bytes, default 128
|
|
34
|
+
* @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39
|
|
35
|
+
* @returns {string} return mnemonic string, spilt by blank
|
|
36
|
+
*/
|
|
37
|
+
static generateMnemonic: (len?: number, language?: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* get secret from mnemonic, obey encode rule base58 for jingtum
|
|
40
|
+
*
|
|
41
|
+
* @static
|
|
42
|
+
* @param {string} mnemonic mnemonic words
|
|
43
|
+
* @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39
|
|
44
|
+
* @returns {string} return secret string
|
|
45
|
+
*/
|
|
46
|
+
static getSecretFromMnemonic: (mnemonic: string, language?: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* get mnemonic from secret, obey encode rule base58 for jingtum
|
|
49
|
+
*
|
|
50
|
+
* @static
|
|
51
|
+
* @param {string} secret secret string
|
|
52
|
+
* @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39
|
|
53
|
+
* @returns {string} return mnemonic word list
|
|
54
|
+
*/
|
|
55
|
+
static getMnemonicFromSecret: (secret: string, language?: string) => string;
|
|
56
|
+
/**
|
|
57
|
+
* get keypair from secret
|
|
58
|
+
*
|
|
59
|
+
* @static
|
|
60
|
+
* @param {string} secret secret string
|
|
61
|
+
* @returns {object} return keypair object
|
|
62
|
+
*/
|
|
63
|
+
static getKeypairFromSecret: (secret: string) => any;
|
|
64
|
+
/**
|
|
65
|
+
* get hd wallet key pair
|
|
66
|
+
*
|
|
67
|
+
* @static
|
|
68
|
+
* @param {string} rootSecret root secret
|
|
69
|
+
* @param {number} chain chain index number
|
|
70
|
+
* @param {number} account bip44 account index for purpose
|
|
71
|
+
* @param {number} index bip44 last level index
|
|
72
|
+
* @returns {IKeyPair} return keypair object
|
|
73
|
+
*/
|
|
74
|
+
static getHDKeypair: (rootSecret: string, chain: number, account: number, index: number) => IKeyPair;
|
|
75
|
+
/**
|
|
76
|
+
* generate hd wallet
|
|
77
|
+
*
|
|
78
|
+
* @static
|
|
79
|
+
* @param {any} opt options of generate, like:
|
|
80
|
+
* {
|
|
81
|
+
* len: 128/160/192/224/256, default is 128, determines number of mnemonic word
|
|
82
|
+
* language: english default/chinese_simplified/chinese_traditional/czech/korean/french/japanese/... see also:bip39 https://github.com/bitcoinjs/bip39/tree/master/ts_src/wordlists
|
|
83
|
+
* }
|
|
84
|
+
* @returns {object} return hd wallet object
|
|
85
|
+
*/
|
|
86
|
+
static generate: (opt: any) => HDWallet;
|
|
87
|
+
/**
|
|
88
|
+
* create hd wallet from secret
|
|
89
|
+
*
|
|
90
|
+
* @static
|
|
91
|
+
* @param {string} secret secret string
|
|
92
|
+
* @returns {object} return hd wallet object
|
|
93
|
+
*/
|
|
94
|
+
static fromSecret: (secret: string) => HDWallet;
|
|
95
|
+
/**
|
|
96
|
+
* create hd wallet from mnemonic
|
|
97
|
+
*
|
|
98
|
+
* @static
|
|
99
|
+
* @param {IMnemonic} mnemonic object like
|
|
100
|
+
* {mnemonic: "abc abc ...", language: "english"}
|
|
101
|
+
* @returns {object} return hd wallet object
|
|
102
|
+
*/
|
|
103
|
+
static fromMnemonic: (mnemonic: IMnemonic) => HDWallet;
|
|
104
|
+
/**
|
|
105
|
+
* create hd wallet from keypair
|
|
106
|
+
*
|
|
107
|
+
* @static
|
|
108
|
+
* @param {IKeyPair} keypair object like
|
|
109
|
+
* {publicKey: "public key...", privateKey: "private key..."}
|
|
110
|
+
* @returns {object} return hd wallet object
|
|
111
|
+
*/
|
|
112
|
+
static fromKeypair: (keypair: IKeyPair) => HDWallet;
|
|
113
|
+
/**
|
|
114
|
+
* hd wallet is root or not
|
|
115
|
+
*
|
|
116
|
+
* @returns {boolean} return hd wallet root or not
|
|
117
|
+
*/
|
|
118
|
+
isRoot: () => boolean;
|
|
119
|
+
/**
|
|
120
|
+
* generate hd wallet by derive path, obey BIP44 protocol
|
|
121
|
+
*
|
|
122
|
+
* @param {any} opt options of derive, like:
|
|
123
|
+
* {
|
|
124
|
+
* chain: BIP44Chain.ETH, //chain code defined in bip44
|
|
125
|
+
* account: 0, // account for what purpose
|
|
126
|
+
* change: 0, // optional attrube,default always 0, for change account after transfer
|
|
127
|
+
* index: 0, // accout index
|
|
128
|
+
* }
|
|
129
|
+
* @returns {object} return hd wallet object
|
|
130
|
+
*/
|
|
131
|
+
deriveWallet: (opt: any) => HDWallet;
|
|
132
|
+
/**
|
|
133
|
+
* get wallet secret
|
|
134
|
+
*
|
|
135
|
+
* @returns {string} return wallet secret
|
|
136
|
+
*/
|
|
137
|
+
secret: () => string;
|
|
138
|
+
/**
|
|
139
|
+
* get wallet mnemonic
|
|
140
|
+
*
|
|
141
|
+
* @returns {IMnemonic} return IMnemonic object
|
|
142
|
+
*/
|
|
143
|
+
mnemonic: () => IMnemonic;
|
|
144
|
+
/**
|
|
145
|
+
* get chain of hd wallet
|
|
146
|
+
*
|
|
147
|
+
* @returns {string} return chain of hd wallet
|
|
148
|
+
*/
|
|
149
|
+
chain: () => string;
|
|
150
|
+
/**
|
|
151
|
+
* get address of hd wallet
|
|
152
|
+
*
|
|
153
|
+
* @returns {string} return address of hd wallet
|
|
154
|
+
*/
|
|
155
|
+
address: () => string;
|
|
156
|
+
/**
|
|
157
|
+
* check address valid or not
|
|
158
|
+
* @param {string} address
|
|
159
|
+
* @returns {boolean} true valid, false invalid
|
|
160
|
+
*/
|
|
161
|
+
isValidAddress: (address: string) => boolean;
|
|
162
|
+
/**
|
|
163
|
+
* check secret valid or not
|
|
164
|
+
*
|
|
165
|
+
* @param {string} secret
|
|
166
|
+
* @returns {boolean} true valid, false invalid
|
|
167
|
+
*/
|
|
168
|
+
isValidSecret: (address: string) => boolean;
|
|
169
|
+
/**
|
|
170
|
+
* hash message
|
|
171
|
+
*
|
|
172
|
+
* @param {string} message
|
|
173
|
+
* @returns {string} return hash of message
|
|
174
|
+
*/
|
|
175
|
+
hash: (message: string) => string;
|
|
176
|
+
/**
|
|
177
|
+
* sign message
|
|
178
|
+
* @notice how to operate message(raw or hashed) is different in native sdk of different chain
|
|
179
|
+
* to avoid confusion, we assume that native sdk will automatically hashed message
|
|
180
|
+
* if not the case of native sdk, we hash this message in lower level(plugin), for example ethereum sdk
|
|
181
|
+
* @param {string} message
|
|
182
|
+
* @returns {string} return signature string
|
|
183
|
+
*/
|
|
184
|
+
sign: (message: string) => string;
|
|
185
|
+
/**
|
|
186
|
+
* verify signature valid or not
|
|
187
|
+
*
|
|
188
|
+
* @param {string} message origin message
|
|
189
|
+
* @param {string} signature signature
|
|
190
|
+
* @param {string} address account which sign
|
|
191
|
+
* @param {IKeyPair} keypair keypair object, usually to provide public key, private key not required
|
|
192
|
+
*
|
|
193
|
+
* @returns {boolean} true valid, false invalid
|
|
194
|
+
*/
|
|
195
|
+
verify: (messgae: string, signature: string, address?: string, keypair?: IKeyPair) => boolean;
|
|
196
|
+
/**
|
|
197
|
+
* recover address/account from signature
|
|
198
|
+
*
|
|
199
|
+
* @param {string} message origin message
|
|
200
|
+
* @param {string} signature signature
|
|
201
|
+
*
|
|
202
|
+
* @returns {string} return address
|
|
203
|
+
*/
|
|
204
|
+
recover: (messgae: string, signature: string) => string | void;
|
|
205
|
+
/**
|
|
206
|
+
* get specified chain wallet api
|
|
207
|
+
*
|
|
208
|
+
* @returns {IHDPlugin} return hd plugin object
|
|
209
|
+
*/
|
|
210
|
+
getWalletApi: () => IHDPlugin;
|
|
211
|
+
/**
|
|
212
|
+
* get keypair of hd wallet
|
|
213
|
+
*
|
|
214
|
+
* @returns {IKeyPair} return keypair of message
|
|
215
|
+
*/
|
|
216
|
+
keypair: () => IKeyPair;
|
|
217
|
+
/**
|
|
218
|
+
* get path of hd wallet
|
|
219
|
+
*
|
|
220
|
+
* @returns {IBIP44Path} return path of wallet
|
|
221
|
+
*/
|
|
222
|
+
path: () => IBIP44Path;
|
|
223
|
+
/**
|
|
224
|
+
* set keypair
|
|
225
|
+
* @param {IKeyPair} keypair
|
|
226
|
+
*/
|
|
227
|
+
setKeypair: (keypair: IKeyPair) => void;
|
|
228
|
+
}
|