jcc_wallet 4.0.5 → 4.0.7
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 +24 -24
- package/lib/hd/eos.plugin.d.ts +2 -1
- package/lib/hd/eos.plugin.js +20 -0
- package/lib/hd/ethereum.plugin.d.ts +2 -1
- package/lib/hd/ethereum.plugin.js +16 -0
- package/lib/hd/index.d.ts +1 -1
- package/lib/hd/index.js +7 -4
- package/lib/hd/swtc.plugin.js +10 -1
- package/lib/hd/tron.plugin.d.ts +2 -1
- package/lib/hd/tron.plugin.js +19 -0
- package/lib/types.d.ts +1 -0
- package/package.json +1 -1
package/lib/hd/eos.plugin.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IHDPlugin } from "../types";
|
|
1
|
+
import { IHDPlugin, IKeyPair } from "../types";
|
|
2
2
|
export interface IEosPlugin extends IHDPlugin {
|
|
3
3
|
checkPrivateKey(privateKey: string): string;
|
|
4
4
|
privateKeyToLegacyString(privateKey: string): string;
|
|
5
|
+
getKeyPairFromPrivateKey(privateKey: string): IKeyPair | null;
|
|
5
6
|
}
|
|
6
7
|
export declare const plugin: IEosPlugin;
|
package/lib/hd/eos.plugin.js
CHANGED
|
@@ -77,5 +77,25 @@ exports.plugin = {
|
|
|
77
77
|
recover(message, signature) {
|
|
78
78
|
const s = Signature_1.Signature.fromString(signature);
|
|
79
79
|
return s.recover(message).toLegacyString();
|
|
80
|
+
},
|
|
81
|
+
getKeyPairFromPrivateKey(privateKey) {
|
|
82
|
+
try {
|
|
83
|
+
const key = exports.plugin.checkPrivateKey(privateKey);
|
|
84
|
+
if (!exports.plugin.isValidSecret(key)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const eosPrivateKey = exports.plugin.privateKeyToLegacyString(key);
|
|
88
|
+
const pk = PrivateKey_1.PrivateKey.fromString(eosPrivateKey);
|
|
89
|
+
const pubKey = pk.getPublicKey();
|
|
90
|
+
const point = pubKey.toPoint();
|
|
91
|
+
const publicKey = point.toHex(true);
|
|
92
|
+
return {
|
|
93
|
+
privateKey: key,
|
|
94
|
+
publicKey
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
80
100
|
}
|
|
81
101
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { IHDPlugin } from "../types";
|
|
1
|
+
import { IKeyPair, IHDPlugin } from "../types";
|
|
2
2
|
export interface IEthereumPlugin extends IHDPlugin {
|
|
3
3
|
checkPrivateKey(privateKey: string): string;
|
|
4
4
|
decryptKeystore(password: string, encryptData: any): Promise<string>;
|
|
5
|
+
getKeyPairFromPrivateKey(privateKey: string): IKeyPair | null;
|
|
5
6
|
}
|
|
6
7
|
export declare const plugin: IEthereumPlugin;
|
|
@@ -111,5 +111,21 @@ exports.plugin = {
|
|
|
111
111
|
const priv = (0, utils_js_1.randomBytes)(32);
|
|
112
112
|
const address = exports.plugin.getAddress((0, bytes_1.bytesToHex)(priv));
|
|
113
113
|
return { address, secret: (0, bytes_1.bytesToHex)(priv) };
|
|
114
|
+
},
|
|
115
|
+
getKeyPairFromPrivateKey(privateKey) {
|
|
116
|
+
try {
|
|
117
|
+
const key = exports.plugin.checkPrivateKey(privateKey);
|
|
118
|
+
if (!exports.plugin.isValidSecret(key)) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const publicKey = secp256k1_js_1.secp256k1.ProjectivePoint.fromPrivateKey(Buffer.from((0, internal_1.stripHexPrefix)(key), "hex")).toHex(false);
|
|
122
|
+
return {
|
|
123
|
+
privateKey: key,
|
|
124
|
+
publicKey: publicKey.substring(2)
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (_a) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
114
130
|
}
|
|
115
131
|
};
|
package/lib/hd/index.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ export declare class HDWallet {
|
|
|
71
71
|
* @param {number} index bip44 last level index
|
|
72
72
|
* @returns {IKeyPair} return keypair object
|
|
73
73
|
*/
|
|
74
|
-
static getHDKeypair: (rootSecret: string, chain: number, account: number, index: number) => IKeyPair;
|
|
74
|
+
static getHDKeypair: (rootSecret: string, chain: number, account: number, index: number, change?: number) => IKeyPair;
|
|
75
75
|
/**
|
|
76
76
|
* generate hd wallet
|
|
77
77
|
*
|
package/lib/hd/index.js
CHANGED
|
@@ -88,10 +88,13 @@ class HDWallet {
|
|
|
88
88
|
if (isNaN(opt.chain) || isNaN(opt.account) || isNaN(opt.index)) {
|
|
89
89
|
return null;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
if (isNaN(opt.change)) {
|
|
92
|
+
opt.change = 0;
|
|
93
|
+
}
|
|
94
|
+
const hdKeypair = HDWallet.getHDKeypair(this._secret, opt.chain, opt.account, opt.index, opt.change);
|
|
92
95
|
return new HDWallet({
|
|
93
96
|
keypair: hdKeypair,
|
|
94
|
-
path: { chain: opt.chain, account: opt.account, change:
|
|
97
|
+
path: { chain: opt.chain, account: opt.account, change: opt.change, index: opt.index }
|
|
95
98
|
});
|
|
96
99
|
};
|
|
97
100
|
/**
|
|
@@ -327,7 +330,7 @@ HDWallet.getKeypairFromSecret = (secret) => {
|
|
|
327
330
|
* @param {number} index bip44 last level index
|
|
328
331
|
* @returns {IKeyPair} return keypair object
|
|
329
332
|
*/
|
|
330
|
-
HDWallet.getHDKeypair = (rootSecret, chain, account = 0, index) => {
|
|
333
|
+
HDWallet.getHDKeypair = (rootSecret, chain, account = 0, index, change = 0) => {
|
|
331
334
|
const bip44Chain = (0, constant_1.getBIP44Chain)(chain);
|
|
332
335
|
if (bip44Chain.length === 0) {
|
|
333
336
|
return null;
|
|
@@ -336,7 +339,7 @@ HDWallet.getHDKeypair = (rootSecret, chain, account = 0, index) => {
|
|
|
336
339
|
const mnemonic = HDWallet.getMnemonicFromSecret(rootSecret);
|
|
337
340
|
const seed = BIP39.mnemonicToSeedSync(mnemonic);
|
|
338
341
|
const b32 = bip32_1.HDKey.fromMasterSeed(seed);
|
|
339
|
-
const privateKey = b32.derive(`m/44'/${chainIdx}'/${account}'
|
|
342
|
+
const privateKey = b32.derive(`m/44'/${chainIdx}'/${account}'/${change}/${index}`).privateKey;
|
|
340
343
|
return keypair.deriveKeyPair(Buffer.from(privateKey).toString("hex"));
|
|
341
344
|
};
|
|
342
345
|
/**
|
package/lib/hd/swtc.plugin.js
CHANGED
|
@@ -70,6 +70,14 @@ const SWTCPlugin = (alphabet) => {
|
|
|
70
70
|
return null;
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
+
const getKeyPairFromPrivateKey = (privateKey) => {
|
|
74
|
+
try {
|
|
75
|
+
return Wallet.deriveKeyPair(privateKey);
|
|
76
|
+
}
|
|
77
|
+
catch (_a) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
73
81
|
return {
|
|
74
82
|
isValidAddress,
|
|
75
83
|
isValidSecret,
|
|
@@ -79,7 +87,8 @@ const SWTCPlugin = (alphabet) => {
|
|
|
79
87
|
createWallet,
|
|
80
88
|
getAddress,
|
|
81
89
|
recover,
|
|
82
|
-
address
|
|
90
|
+
address,
|
|
91
|
+
getKeyPairFromPrivateKey
|
|
83
92
|
};
|
|
84
93
|
};
|
|
85
94
|
exports.SWTCPlugin = SWTCPlugin;
|
package/lib/hd/tron.plugin.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { IHDPlugin } from "../types";
|
|
1
|
+
import { IHDPlugin, IKeyPair } from "../types";
|
|
2
2
|
export interface ITronPlugin extends IHDPlugin {
|
|
3
3
|
checkPrivateKey(privateKey: string): string;
|
|
4
|
+
getKeyPairFromPrivateKey(privateKey: string): IKeyPair | null;
|
|
4
5
|
}
|
|
5
6
|
export declare const plugin: ITronPlugin;
|
package/lib/hd/tron.plugin.js
CHANGED
|
@@ -57,5 +57,24 @@ exports.plugin = {
|
|
|
57
57
|
},
|
|
58
58
|
recover(message, signature) {
|
|
59
59
|
return (0, message_1.verifyMessage)(message, signature);
|
|
60
|
+
},
|
|
61
|
+
getKeyPairFromPrivateKey(privateKey) {
|
|
62
|
+
try {
|
|
63
|
+
const key = exports.plugin.checkPrivateKey(privateKey);
|
|
64
|
+
if (!exports.plugin.isValidSecret(key)) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
const pubBytes = (0, crypto_1.getPubKeyFromPriKey)((0, code_1.hexStr2byteArray)(key));
|
|
68
|
+
const publicKey = Array.from(pubBytes)
|
|
69
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
70
|
+
.join("");
|
|
71
|
+
return {
|
|
72
|
+
privateKey: key,
|
|
73
|
+
publicKey
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (_a) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
60
79
|
}
|
|
61
80
|
};
|
package/lib/types.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ export interface IHDPlugin {
|
|
|
89
89
|
getAddress?(secret: string): string;
|
|
90
90
|
createWallet?(opts?: ICreateOptionsModel): IWalletModel;
|
|
91
91
|
proxy?(functionName: string, ...args: any[]): any;
|
|
92
|
+
getKeyPairFromPrivateKey?(privateKey: string): IKeyPair | null;
|
|
92
93
|
}
|
|
93
94
|
export declare enum Alphabet {
|
|
94
95
|
JINGTUM = "jpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65rkm8oFqi1tuvAxyz",
|