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
package/lib/hd/index.js
ADDED
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.HDWallet = exports.getBIP44Chain = exports.BIP44ChainMap = exports.BIP44Chain = void 0;
|
|
27
|
+
const minify_swtc_keypair_1 = require("../minify-swtc-keypair");
|
|
28
|
+
const BIP39 = __importStar(require("bip39"));
|
|
29
|
+
const bip32_1 = require("@scure/bip32");
|
|
30
|
+
const constant_1 = require("./constant");
|
|
31
|
+
Object.defineProperty(exports, "BIP44Chain", { enumerable: true, get: function () { return constant_1.BIP44Chain; } });
|
|
32
|
+
Object.defineProperty(exports, "BIP44ChainMap", { enumerable: true, get: function () { return constant_1.BIP44ChainMap; } });
|
|
33
|
+
Object.defineProperty(exports, "getBIP44Chain", { enumerable: true, get: function () { return constant_1.getBIP44Chain; } });
|
|
34
|
+
const plugins_1 = require("./plugins");
|
|
35
|
+
const types_1 = require("../types");
|
|
36
|
+
const keypair = (0, minify_swtc_keypair_1.Factory)(types_1.Alphabet.JINGTUM);
|
|
37
|
+
class HDWallet {
|
|
38
|
+
/**
|
|
39
|
+
* generate hd wallet
|
|
40
|
+
*
|
|
41
|
+
* @param {any} opt options of generate, like:
|
|
42
|
+
* {
|
|
43
|
+
* mnemonic: "world list", // optional
|
|
44
|
+
* // see also:bip39 https://github.com/bitcoinjs/bip39/tree/master/ts_src/wordlists
|
|
45
|
+
* // language attribute appears with mnemonic attribute
|
|
46
|
+
* language: english default/chinese_simplified/...
|
|
47
|
+
* secret: "secret string", // optional, default this coding rules of SWTC chain
|
|
48
|
+
* keypair: {privateKey: "xxxx", publicKey: "xxxx"}
|
|
49
|
+
* }
|
|
50
|
+
* way of create hd wallet
|
|
51
|
+
* 1. {mnemonic: "xxx", language:"english"}
|
|
52
|
+
* 2. {secret: "xxxx"}
|
|
53
|
+
* 3. {keypair: {....}, path:{....}}
|
|
54
|
+
* @returns {object} return hd wallet object
|
|
55
|
+
*/
|
|
56
|
+
constructor(opt) {
|
|
57
|
+
/**
|
|
58
|
+
* hd wallet is root or not
|
|
59
|
+
*
|
|
60
|
+
* @returns {boolean} return hd wallet root or not
|
|
61
|
+
*/
|
|
62
|
+
this.isRoot = () => {
|
|
63
|
+
return this._path.chain + this._path.account + this._path.change + this._path.index === 0;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* generate hd wallet by derive path, obey BIP44 protocol
|
|
67
|
+
*
|
|
68
|
+
* @param {any} opt options of derive, like:
|
|
69
|
+
* {
|
|
70
|
+
* chain: BIP44Chain.ETH, //chain code defined in bip44
|
|
71
|
+
* account: 0, // account for what purpose
|
|
72
|
+
* change: 0, // optional attrube,default always 0, for change account after transfer
|
|
73
|
+
* index: 0, // accout index
|
|
74
|
+
* }
|
|
75
|
+
* @returns {object} return hd wallet object
|
|
76
|
+
*/
|
|
77
|
+
this.deriveWallet = (opt) => {
|
|
78
|
+
if (isNaN(opt.chain) || isNaN(opt.account) || isNaN(opt.index)) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const hdKeypair = HDWallet.getHDKeypair(this._secret, opt.chain, opt.account, opt.index);
|
|
82
|
+
return new HDWallet({
|
|
83
|
+
keypair: hdKeypair,
|
|
84
|
+
path: { chain: opt.chain, account: opt.account, change: 0, index: opt.index }
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* get wallet secret
|
|
89
|
+
*
|
|
90
|
+
* @returns {string} return wallet secret
|
|
91
|
+
*/
|
|
92
|
+
this.secret = () => {
|
|
93
|
+
return this._secret;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* get wallet mnemonic
|
|
97
|
+
*
|
|
98
|
+
* @returns {IMnemonic} return IMnemonic object
|
|
99
|
+
*/
|
|
100
|
+
this.mnemonic = () => {
|
|
101
|
+
return this._mnemonic;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* get chain of hd wallet
|
|
105
|
+
*
|
|
106
|
+
* @returns {string} return chain of hd wallet
|
|
107
|
+
*/
|
|
108
|
+
this.chain = () => {
|
|
109
|
+
return this.isRoot() ? constant_1.BIP44ChainMap.get(constant_1.BIP44Chain.SWTC) : constant_1.BIP44ChainMap.get(this._path.chain);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* get address of hd wallet
|
|
113
|
+
*
|
|
114
|
+
* @returns {string} return address of hd wallet
|
|
115
|
+
*/
|
|
116
|
+
this.address = () => {
|
|
117
|
+
if (!this._address) {
|
|
118
|
+
const chain = this.chain();
|
|
119
|
+
this._address = (0, plugins_1.getPluginByType)(chain).address(this._secret ? this._secret : this._keypair, chain);
|
|
120
|
+
}
|
|
121
|
+
return this._address;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* check address valid or not
|
|
125
|
+
* @param {string} address
|
|
126
|
+
* @returns {boolean} true valid, false invalid
|
|
127
|
+
*/
|
|
128
|
+
this.isValidAddress = (address) => {
|
|
129
|
+
return (0, plugins_1.getPluginByType)(this.chain()).isValidAddress(address);
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* check secret valid or not
|
|
133
|
+
*
|
|
134
|
+
* @param {string} secret
|
|
135
|
+
* @returns {boolean} true valid, false invalid
|
|
136
|
+
*/
|
|
137
|
+
this.isValidSecret = (address) => {
|
|
138
|
+
return (0, plugins_1.getPluginByType)(this.chain()).isValidSecret(address);
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* hash message
|
|
142
|
+
*
|
|
143
|
+
* @param {string} message
|
|
144
|
+
* @returns {string} return hash of message
|
|
145
|
+
*/
|
|
146
|
+
this.hash = (message) => {
|
|
147
|
+
return (0, plugins_1.getPluginByType)(this.chain()).hash(message);
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* sign message
|
|
151
|
+
* @notice how to operate message(raw or hashed) is different in native sdk of different chain
|
|
152
|
+
* to avoid confusion, we assume that native sdk will automatically hashed message
|
|
153
|
+
* if not the case of native sdk, we hash this message in lower level(plugin), for example ethereum sdk
|
|
154
|
+
* @param {string} message
|
|
155
|
+
* @returns {string} return signature string
|
|
156
|
+
*/
|
|
157
|
+
this.sign = (message) => {
|
|
158
|
+
return (0, plugins_1.getPluginByType)(this.chain()).sign(message, this._keypair.privateKey);
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* verify signature valid or not
|
|
162
|
+
*
|
|
163
|
+
* @param {string} message origin message
|
|
164
|
+
* @param {string} signature signature
|
|
165
|
+
* @param {string} address account which sign
|
|
166
|
+
* @param {IKeyPair} keypair keypair object, usually to provide public key, private key not required
|
|
167
|
+
*
|
|
168
|
+
* @returns {boolean} true valid, false invalid
|
|
169
|
+
*/
|
|
170
|
+
this.verify = (messgae, signature, address, keypair) => {
|
|
171
|
+
if (!address) {
|
|
172
|
+
address = this.address();
|
|
173
|
+
}
|
|
174
|
+
if (!keypair) {
|
|
175
|
+
keypair = this._keypair;
|
|
176
|
+
}
|
|
177
|
+
return (0, plugins_1.getPluginByType)(this.chain()).verify(messgae, signature, address, keypair);
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* recover address/account from signature
|
|
181
|
+
*
|
|
182
|
+
* @param {string} message origin message
|
|
183
|
+
* @param {string} signature signature
|
|
184
|
+
*
|
|
185
|
+
* @returns {string} return address
|
|
186
|
+
*/
|
|
187
|
+
this.recover = (messgae, signature) => {
|
|
188
|
+
return (0, plugins_1.getPluginByType)(this.chain()).recover(messgae, signature);
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* get specified chain wallet api
|
|
192
|
+
*
|
|
193
|
+
* @returns {IHDPlugin} return hd plugin object
|
|
194
|
+
*/
|
|
195
|
+
this.getWalletApi = () => {
|
|
196
|
+
return (0, plugins_1.getPluginByType)(this.chain());
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* get keypair of hd wallet
|
|
200
|
+
*
|
|
201
|
+
* @returns {IKeyPair} return keypair of message
|
|
202
|
+
*/
|
|
203
|
+
this.keypair = () => {
|
|
204
|
+
return this._keypair;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* get path of hd wallet
|
|
208
|
+
*
|
|
209
|
+
* @returns {IBIP44Path} return path of wallet
|
|
210
|
+
*/
|
|
211
|
+
this.path = () => {
|
|
212
|
+
return this._path;
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* set keypair
|
|
216
|
+
* @param {IKeyPair} keypair
|
|
217
|
+
*/
|
|
218
|
+
this.setKeypair = (keypair) => {
|
|
219
|
+
this._keypair = keypair;
|
|
220
|
+
};
|
|
221
|
+
if (!opt) {
|
|
222
|
+
throw new Error("undefined parameters: " + opt);
|
|
223
|
+
}
|
|
224
|
+
this._path = {
|
|
225
|
+
chain: 0,
|
|
226
|
+
account: 0,
|
|
227
|
+
change: 0,
|
|
228
|
+
index: 0
|
|
229
|
+
};
|
|
230
|
+
if (opt.mnemonic) {
|
|
231
|
+
this._secret = HDWallet.getSecretFromMnemonic(opt.mnemonic, opt.language);
|
|
232
|
+
this._keypair = HDWallet.getKeypairFromSecret(this._secret);
|
|
233
|
+
this._mnemonic = { mnemonic: opt.mnemonic, language: opt.language };
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
if (opt.secret) {
|
|
237
|
+
this._secret = opt.secret;
|
|
238
|
+
this._keypair = HDWallet.getKeypairFromSecret(this._secret);
|
|
239
|
+
this._mnemonic = { mnemonic: HDWallet.getMnemonicFromSecret(this._secret, opt.language), language: opt.language };
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
// wallet create by keypair, which only for sign message and tx
|
|
243
|
+
if (opt.keypair) {
|
|
244
|
+
if (opt.path) {
|
|
245
|
+
this._keypair = opt.keypair;
|
|
246
|
+
this._mnemonic = null;
|
|
247
|
+
this._secret = null;
|
|
248
|
+
this._path = opt.path;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
this._keypair = opt.keypair;
|
|
252
|
+
this._mnemonic = null;
|
|
253
|
+
this._secret = null;
|
|
254
|
+
}
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
// parameter error;
|
|
258
|
+
throw new Error("invalid parameters: " + opt);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exports.HDWallet = HDWallet;
|
|
262
|
+
/**
|
|
263
|
+
* generate mnemonic
|
|
264
|
+
*
|
|
265
|
+
* @static
|
|
266
|
+
* @param {number} len strength of random bytes, default 128
|
|
267
|
+
* @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39
|
|
268
|
+
* @returns {string} return mnemonic string, spilt by blank
|
|
269
|
+
*/
|
|
270
|
+
HDWallet.generateMnemonic = (len = 128, language = "english") => {
|
|
271
|
+
BIP39.setDefaultWordlist(language);
|
|
272
|
+
return BIP39.generateMnemonic(len);
|
|
273
|
+
};
|
|
274
|
+
/**
|
|
275
|
+
* get secret from mnemonic, obey encode rule base58 for jingtum
|
|
276
|
+
*
|
|
277
|
+
* @static
|
|
278
|
+
* @param {string} mnemonic mnemonic words
|
|
279
|
+
* @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39
|
|
280
|
+
* @returns {string} return secret string
|
|
281
|
+
*/
|
|
282
|
+
HDWallet.getSecretFromMnemonic = (mnemonic, language = "english") => {
|
|
283
|
+
BIP39.setDefaultWordlist(language);
|
|
284
|
+
const entropy = BIP39.mnemonicToEntropy(mnemonic);
|
|
285
|
+
return keypair.addressCodec.encodeSeed(Buffer.from(entropy, "hex"));
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* get mnemonic from secret, obey encode rule base58 for jingtum
|
|
289
|
+
*
|
|
290
|
+
* @static
|
|
291
|
+
* @param {string} secret secret string
|
|
292
|
+
* @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39
|
|
293
|
+
* @returns {string} return mnemonic word list
|
|
294
|
+
*/
|
|
295
|
+
HDWallet.getMnemonicFromSecret = (secret, language = "english") => {
|
|
296
|
+
BIP39.setDefaultWordlist(language);
|
|
297
|
+
const entropy = keypair.addressCodec.decodeSeed(secret).bytes;
|
|
298
|
+
return BIP39.entropyToMnemonic(entropy);
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* get keypair from secret
|
|
302
|
+
*
|
|
303
|
+
* @static
|
|
304
|
+
* @param {string} secret secret string
|
|
305
|
+
* @returns {object} return keypair object
|
|
306
|
+
*/
|
|
307
|
+
HDWallet.getKeypairFromSecret = (secret) => {
|
|
308
|
+
return keypair.deriveKeyPair(secret);
|
|
309
|
+
};
|
|
310
|
+
/**
|
|
311
|
+
* get hd wallet key pair
|
|
312
|
+
*
|
|
313
|
+
* @static
|
|
314
|
+
* @param {string} rootSecret root secret
|
|
315
|
+
* @param {number} chain chain index number
|
|
316
|
+
* @param {number} account bip44 account index for purpose
|
|
317
|
+
* @param {number} index bip44 last level index
|
|
318
|
+
* @returns {IKeyPair} return keypair object
|
|
319
|
+
*/
|
|
320
|
+
HDWallet.getHDKeypair = (rootSecret, chain, account = 0, index) => {
|
|
321
|
+
const bip44Chain = (0, constant_1.getBIP44Chain)(chain);
|
|
322
|
+
if (bip44Chain.length === 0) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
const chainIdx = (bip44Chain[0][0] << 1) >> 1;
|
|
326
|
+
const mnemonic = HDWallet.getMnemonicFromSecret(rootSecret);
|
|
327
|
+
const seed = BIP39.mnemonicToSeedSync(mnemonic);
|
|
328
|
+
const b32 = bip32_1.HDKey.fromMasterSeed(seed);
|
|
329
|
+
const privateKey = b32.derive(`m/44'/${chainIdx}'/${account}'/0/${index}`).privateKey;
|
|
330
|
+
return keypair.deriveKeyPair(Buffer.from(privateKey).toString("hex"));
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* generate hd wallet
|
|
334
|
+
*
|
|
335
|
+
* @static
|
|
336
|
+
* @param {any} opt options of generate, like:
|
|
337
|
+
* {
|
|
338
|
+
* len: 128/160/192/224/256, default is 128, determines number of mnemonic word
|
|
339
|
+
* language: english default/chinese_simplified/chinese_traditional/czech/korean/french/japanese/... see also:bip39 https://github.com/bitcoinjs/bip39/tree/master/ts_src/wordlists
|
|
340
|
+
* }
|
|
341
|
+
* @returns {object} return hd wallet object
|
|
342
|
+
*/
|
|
343
|
+
HDWallet.generate = (opt) => {
|
|
344
|
+
if (!opt) {
|
|
345
|
+
opt = {};
|
|
346
|
+
}
|
|
347
|
+
const mnemonic = HDWallet.generateMnemonic(opt.len, opt.language);
|
|
348
|
+
return new HDWallet({ mnemonic, language: opt.language });
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* create hd wallet from secret
|
|
352
|
+
*
|
|
353
|
+
* @static
|
|
354
|
+
* @param {string} secret secret string
|
|
355
|
+
* @returns {object} return hd wallet object
|
|
356
|
+
*/
|
|
357
|
+
HDWallet.fromSecret = (secret) => {
|
|
358
|
+
return new HDWallet({ secret });
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* create hd wallet from mnemonic
|
|
362
|
+
*
|
|
363
|
+
* @static
|
|
364
|
+
* @param {IMnemonic} mnemonic object like
|
|
365
|
+
* {mnemonic: "abc abc ...", language: "english"}
|
|
366
|
+
* @returns {object} return hd wallet object
|
|
367
|
+
*/
|
|
368
|
+
HDWallet.fromMnemonic = (mnemonic) => {
|
|
369
|
+
return new HDWallet({ mnemonic: mnemonic.mnemonic, language: mnemonic.language });
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* create hd wallet from keypair
|
|
373
|
+
*
|
|
374
|
+
* @static
|
|
375
|
+
* @param {IKeyPair} keypair object like
|
|
376
|
+
* {publicKey: "public key...", privateKey: "private key..."}
|
|
377
|
+
* @returns {object} return hd wallet object
|
|
378
|
+
*/
|
|
379
|
+
HDWallet.fromKeypair = (keypair) => {
|
|
380
|
+
return new HDWallet({ keypair });
|
|
381
|
+
};
|
|
382
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hd/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAiD;AACjD,6CAA+B;AAC/B,wCAAqC;AACrC,yCAAsE;AAM7D,2FANA,qBAAU,OAMA;AAAE,8FANA,wBAAa,OAMA;AAAE,8FANA,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,CAAC;QACT,GAAG,GAAG,EAAE,CAAC;IACX,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAElE,OAAO,IAAI,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC5D,CAAC,AAPqB,CAOpB;AAEF;;;;;;GAMG;AACW,mBAAU,GAAG,CAAC,MAAc,EAAY,EAAE;IACtD,OAAO,IAAI,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AAClC,CAAC,AAFuB,CAEtB;AAEF;;;;;;;GAOG;AACW,qBAAY,GAAG,CAAC,QAAmB,EAAY,EAAE;IAC7D,OAAO,IAAI,QAAQ,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;AACpF,CAAC,AAFyB,CAExB;AAEF;;;;;;;GAOG;AACW,oBAAW,GAAG,CAAC,OAAiB,EAAY,EAAE;IAC1D,OAAO,IAAI,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AACnC,CAAC,AAFwB,CAEvB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IHDPlugin } from "../types";
|
|
2
|
+
export declare const bvcadtWallet: IHDPlugin;
|
|
3
|
+
export declare const callWallet: IHDPlugin;
|
|
4
|
+
export declare const rippleWallet: IHDPlugin;
|
|
5
|
+
export declare const stmWallet: IHDPlugin;
|
|
6
|
+
export declare const bizainWallet: IHDPlugin;
|
|
7
|
+
export declare const jtWallet: IHDPlugin;
|
|
8
|
+
export declare const ethWallet: import("./ethereum.plugin").IEthereumPlugin;
|
|
9
|
+
export declare const moacWallet: import("./ethereum.plugin").IEthereumPlugin;
|
|
10
|
+
export declare const eosWallet: import("./eos.plugin").IEosPlugin;
|
|
11
|
+
export declare function getPluginByType<T extends IHDPlugin>(type: string): T;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eosWallet = exports.moacWallet = exports.ethWallet = exports.jtWallet = exports.bizainWallet = exports.stmWallet = exports.rippleWallet = exports.callWallet = exports.bvcadtWallet = void 0;
|
|
4
|
+
exports.getPluginByType = getPluginByType;
|
|
5
|
+
const ethereum_plugin_1 = require("./ethereum.plugin");
|
|
6
|
+
const ethereum_plugin_2 = require("./ethereum.plugin");
|
|
7
|
+
const ethereum_plugin_3 = require("./ethereum.plugin");
|
|
8
|
+
const ethereum_plugin_4 = require("./ethereum.plugin");
|
|
9
|
+
const tron_plugin_1 = require("./tron.plugin");
|
|
10
|
+
const eos_plugin_1 = require("./eos.plugin");
|
|
11
|
+
const types_1 = require("../types");
|
|
12
|
+
const swtc_plugin_1 = require("./swtc.plugin");
|
|
13
|
+
exports.bvcadtWallet = (0, swtc_plugin_1.SWTCPlugin)(types_1.Alphabet.BVCADT);
|
|
14
|
+
exports.callWallet = (0, swtc_plugin_1.SWTCPlugin)(types_1.Alphabet.CALL);
|
|
15
|
+
exports.rippleWallet = (0, swtc_plugin_1.SWTCPlugin)(types_1.Alphabet.RIPPLE);
|
|
16
|
+
exports.stmWallet = (0, swtc_plugin_1.SWTCPlugin)(types_1.Alphabet.STREAM);
|
|
17
|
+
exports.bizainWallet = (0, swtc_plugin_1.SWTCPlugin)(types_1.Alphabet.BIZAIN);
|
|
18
|
+
exports.jtWallet = (0, swtc_plugin_1.SWTCPlugin)(types_1.Alphabet.JINGTUM);
|
|
19
|
+
exports.ethWallet = ethereum_plugin_1.plugin;
|
|
20
|
+
exports.moacWallet = ethereum_plugin_1.plugin;
|
|
21
|
+
exports.eosWallet = eos_plugin_1.plugin;
|
|
22
|
+
const pluginMap = {
|
|
23
|
+
ethereum: ethereum_plugin_1.plugin,
|
|
24
|
+
bsc: ethereum_plugin_2.plugin,
|
|
25
|
+
heco: ethereum_plugin_3.plugin,
|
|
26
|
+
polygon: ethereum_plugin_4.plugin,
|
|
27
|
+
tron: tron_plugin_1.plugin,
|
|
28
|
+
eos: eos_plugin_1.plugin,
|
|
29
|
+
bvcadt: exports.bvcadtWallet,
|
|
30
|
+
call: exports.callWallet,
|
|
31
|
+
ripple: exports.rippleWallet,
|
|
32
|
+
stream: exports.stmWallet,
|
|
33
|
+
bizain: exports.bizainWallet,
|
|
34
|
+
jingtum: exports.jtWallet
|
|
35
|
+
};
|
|
36
|
+
function getPluginByType(type) {
|
|
37
|
+
return pluginMap[type];
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../../src/hd/plugins.ts"],"names":[],"mappings":";;;AAsCA,0CAEC;AAxCD,uDAA6D;AAC7D,uDAAwD;AACxD,uDAAyD;AACzD,uDAA4D;AAC5D,+CAAqD;AACrD,6CAAmD;AACnD,oCAA+C;AAC/C,+CAA2C;AAE9B,QAAA,YAAY,GAAG,IAAA,wBAAU,EAAC,gBAAQ,CAAC,MAAM,CAAC,CAAC;AAC3C,QAAA,UAAU,GAAG,IAAA,wBAAU,EAAC,gBAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,QAAA,YAAY,GAAG,IAAA,wBAAU,EAAC,gBAAQ,CAAC,MAAM,CAAC,CAAC;AAC3C,QAAA,SAAS,GAAG,IAAA,wBAAU,EAAC,gBAAQ,CAAC,MAAM,CAAC,CAAC;AACxC,QAAA,YAAY,GAAG,IAAA,wBAAU,EAAC,gBAAQ,CAAC,MAAM,CAAC,CAAC;AAC3C,QAAA,QAAQ,GAAG,IAAA,wBAAU,EAAC,gBAAQ,CAAC,OAAO,CAAC,CAAC;AACxC,QAAA,SAAS,GAAG,wBAAc,CAAC;AAC3B,QAAA,UAAU,GAAG,wBAAc,CAAC;AAC5B,QAAA,SAAS,GAAG,mBAAS,CAAC;AAMnC,MAAM,SAAS,GAAe;IAC5B,QAAQ,EAAE,wBAAc;IACxB,GAAG,EAAE,wBAAS;IACd,IAAI,EAAE,wBAAU;IAChB,OAAO,EAAE,wBAAa;IACtB,IAAI,EAAE,oBAAU;IAChB,GAAG,EAAE,mBAAS;IACd,MAAM,EAAE,oBAAY;IACpB,IAAI,EAAE,kBAAU;IAChB,MAAM,EAAE,oBAAY;IACpB,MAAM,EAAE,iBAAS;IACjB,MAAM,EAAE,oBAAY;IACpB,OAAO,EAAE,gBAAQ;CAClB,CAAC;AAEF,SAAgB,eAAe,CAAsB,IAAY;IAC/D,OAAO,SAAS,CAAC,IAAI,CAAM,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SWTCPlugin = void 0;
|
|
4
|
+
const minify_swtc_keypair_1 = require("../minify-swtc-keypair");
|
|
5
|
+
const utils_1 = require("@noble/curves/abstract/utils");
|
|
6
|
+
const SWTCPlugin = (alphabet) => {
|
|
7
|
+
const Wallet = (0, minify_swtc_keypair_1.Factory)(alphabet);
|
|
8
|
+
const isValidAddress = (address) => {
|
|
9
|
+
return Wallet.isValidAddress(address);
|
|
10
|
+
};
|
|
11
|
+
const isValidSecret = (secret) => {
|
|
12
|
+
return Wallet.isValidSecret(secret);
|
|
13
|
+
};
|
|
14
|
+
const hash = (message) => {
|
|
15
|
+
return (0, utils_1.bytesToHex)(Wallet.hash(message)).toUpperCase();
|
|
16
|
+
};
|
|
17
|
+
const sign = (message, privateKey) => {
|
|
18
|
+
return Wallet.sign(message, privateKey);
|
|
19
|
+
};
|
|
20
|
+
const address = (key) => {
|
|
21
|
+
try {
|
|
22
|
+
if (typeof key === "string") {
|
|
23
|
+
const w = Wallet.fromSecret(key);
|
|
24
|
+
return w.address;
|
|
25
|
+
}
|
|
26
|
+
if (key.privateKey) {
|
|
27
|
+
const keypair = Wallet.deriveKeyPair(key.privateKey);
|
|
28
|
+
return Wallet.deriveAddress(keypair.publicKey);
|
|
29
|
+
}
|
|
30
|
+
if (key.publicKey) {
|
|
31
|
+
return Wallet.deriveAddress(key.publicKey);
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
catch (_) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const verify = (message, signature, addr, keypair) => {
|
|
40
|
+
try {
|
|
41
|
+
if (addr !== address(keypair)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if (!keypair.publicKey) {
|
|
45
|
+
keypair = Wallet.deriveKeyPair(keypair.privateKey);
|
|
46
|
+
}
|
|
47
|
+
return Wallet.verify(message, signature, keypair.publicKey);
|
|
48
|
+
}
|
|
49
|
+
catch (_) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const recover = () => {
|
|
54
|
+
throw new Error("swtclib does not support.");
|
|
55
|
+
};
|
|
56
|
+
const getAddress = (secret) => {
|
|
57
|
+
try {
|
|
58
|
+
const wallet = Wallet.fromSecret(secret);
|
|
59
|
+
return wallet.address;
|
|
60
|
+
}
|
|
61
|
+
catch (_) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const createWallet = (opt = {}) => {
|
|
66
|
+
try {
|
|
67
|
+
return Wallet.generate(opt);
|
|
68
|
+
}
|
|
69
|
+
catch (_) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
isValidAddress,
|
|
75
|
+
isValidSecret,
|
|
76
|
+
hash,
|
|
77
|
+
sign,
|
|
78
|
+
verify,
|
|
79
|
+
createWallet,
|
|
80
|
+
getAddress,
|
|
81
|
+
recover,
|
|
82
|
+
address
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
exports.SWTC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AAgB,EAAE;QACnE,IAAI,CAAC;YACH,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,cAAc;QACd,aAAa;QACb,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,YAAY;QACZ,UAAU;QACV,OAAO;QACP,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AArFW,QAAA,UAAU,cAqFrB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plugin = void 0;
|
|
4
|
+
const crypto_1 = require("../minify-tron/crypto");
|
|
5
|
+
const code_1 = require("../minify-tron/code");
|
|
6
|
+
const message_1 = require("../minify-tron/message");
|
|
7
|
+
exports.plugin = {
|
|
8
|
+
checkPrivateKey(privateKey) {
|
|
9
|
+
// check and cut swtc keypair lib add prefix 00
|
|
10
|
+
return privateKey.length === 66 ? privateKey.substring(2) : privateKey;
|
|
11
|
+
},
|
|
12
|
+
address(key) {
|
|
13
|
+
if (key.privateKey) {
|
|
14
|
+
const privateKey = exports.plugin.checkPrivateKey(key.privateKey);
|
|
15
|
+
const wallet = (0, crypto_1.pkToAddress)(privateKey);
|
|
16
|
+
return wallet;
|
|
17
|
+
}
|
|
18
|
+
if (key.publicKey) {
|
|
19
|
+
// TODO: length of ethereum publick key of keypaire is 128, but swtc lib keypair is 64
|
|
20
|
+
// so, if you want get address from public key, get it from private first
|
|
21
|
+
const pubBytes = (0, code_1.hexStr2byteArray)(key.publicKey);
|
|
22
|
+
const comCddressBytes = (0, crypto_1.computeAddress)(pubBytes);
|
|
23
|
+
return (0, crypto_1.getBase58CheckAddress)(comCddressBytes);
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
},
|
|
27
|
+
isValidAddress(address) {
|
|
28
|
+
return (0, crypto_1.isAddressValid)(address);
|
|
29
|
+
},
|
|
30
|
+
isValidSecret(secret) {
|
|
31
|
+
try {
|
|
32
|
+
const comPriKeyBytes = (0, code_1.hexStr2byteArray)(exports.plugin.checkPrivateKey(secret));
|
|
33
|
+
const pubBytes = (0, crypto_1.getPubKeyFromPriKey)(comPriKeyBytes);
|
|
34
|
+
const comCddressBytes = (0, crypto_1.computeAddress)(pubBytes);
|
|
35
|
+
const address = (0, crypto_1.getBase58CheckAddress)(comCddressBytes);
|
|
36
|
+
return exports.plugin.isValidAddress(address);
|
|
37
|
+
}
|
|
38
|
+
catch (_) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
hash(message) {
|
|
43
|
+
return (0, message_1.hashMessage)(message);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param message message content, let message is "\x19Ethereum Signed Message:\n" + message.length + message, match web3.accounts.sign function
|
|
48
|
+
* @param privateKey private key
|
|
49
|
+
* @returns signature string
|
|
50
|
+
*/
|
|
51
|
+
sign(message, privateKey) {
|
|
52
|
+
const key = exports.plugin.checkPrivateKey(privateKey).toLowerCase();
|
|
53
|
+
return (0, message_1.signMessage)(message, key);
|
|
54
|
+
},
|
|
55
|
+
verify(message, signature, address) {
|
|
56
|
+
return exports.plugin.recover(message, signature) === address;
|
|
57
|
+
},
|
|
58
|
+
recover(message, signature) {
|
|
59
|
+
return (0, message_1.verifyMessage)(message, signature);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=tron.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tron.plugin.js","sourceRoot":"","sources":["../../src/hd/tron.plugin.ts"],"names":[],"mappings":";;;AACA,kDAM+B;AAC/B,8CAAuD;AACvD,oDAAiF;AAMpE,QAAA,MAAM,GAAgB;IACjC,eAAe,CAAC,UAAkB;QAChC,+CAA+C;QAC/C,O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D,IAAI,CAAC,OAAe;QAClB,OAAO,IAAA,qBAAW,EAAC,OAAO,CAAW,CAAC;IACxC,CAAC;IACD;;;;;OAKG;IACH,IAAI,CAAC,OAAe,EAAE,UAAkB;QACtC,MAAM,GAAG,GAAG,cAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QAE7D,OAAO,IAAA,qBAAW,EAAC,OAAO,EAAE,GAAG,CAAW,CAAC;IAC7C,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,OAAO,IAAA,uBAAa,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;CACF,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
* Copyright (c) 2018 JCC Dex
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
* copies or substantial portions of the Software.
|
|
12
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
13
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
14
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
15
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
16
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
17
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
18
|
+
* SOFTWARE.
|
|
19
|
+
* @author https://github.com/GinMu
|
|
20
|
+
*/
|
|
21
|
+
import JingchangWallet from "./jingchangWallet";
|
|
22
|
+
import * as hdWallet from "./hd";
|
|
23
|
+
import { HDWallet } from "./hd";
|
|
24
|
+
export * from "./hd/plugins";
|
|
25
|
+
export { JingchangWallet, hdWallet, HDWallet };
|