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.
Files changed (86) hide show
  1. package/dist/jcc-wallet.min.js +57 -0
  2. package/lib/constant.d.ts +8 -0
  3. package/lib/constant.js +18 -0
  4. package/lib/constant.js.map +1 -0
  5. package/lib/hd/constant.d.ts +26 -0
  6. package/lib/hd/constant.js +56 -0
  7. package/lib/hd/constant.js.map +1 -0
  8. package/lib/hd/eos.plugin.d.ts +5 -0
  9. package/lib/hd/eos.plugin.js +70 -0
  10. package/lib/hd/eos.plugin.js.map +1 -0
  11. package/lib/hd/ethereum.plugin.d.ts +6 -0
  12. package/lib/hd/ethereum.plugin.js +120 -0
  13. package/lib/hd/ethereum.plugin.js.map +1 -0
  14. package/lib/hd/index.d.ts +228 -0
  15. package/lib/hd/index.js +382 -0
  16. package/lib/hd/index.js.map +1 -0
  17. package/lib/hd/plugins.d.ts +11 -0
  18. package/lib/hd/plugins.js +39 -0
  19. package/lib/hd/plugins.js.map +1 -0
  20. package/lib/hd/swtc.plugin.d.ts +2 -0
  21. package/lib/hd/swtc.plugin.js +86 -0
  22. package/lib/hd/swtc.plugin.js.map +1 -0
  23. package/lib/hd/tron.plugin.d.ts +5 -0
  24. package/lib/hd/tron.plugin.js +62 -0
  25. package/lib/hd/tron.plugin.js.map +1 -0
  26. package/lib/index.d.ts +25 -0
  27. package/lib/index.js +60 -0
  28. package/lib/index.js.map +1 -0
  29. package/lib/jingchangWallet.d.ts +273 -0
  30. package/lib/jingchangWallet.js +531 -0
  31. package/lib/jingchangWallet.js.map +1 -0
  32. package/lib/minify-ethereumjs-util/account.d.ts +1 -0
  33. package/lib/minify-ethereumjs-util/account.js +22 -0
  34. package/lib/minify-ethereumjs-util/account.js.map +1 -0
  35. package/lib/minify-ethereumjs-util/bytes.d.ts +7 -0
  36. package/lib/minify-ethereumjs-util/bytes.js +100 -0
  37. package/lib/minify-ethereumjs-util/bytes.js.map +1 -0
  38. package/lib/minify-ethereumjs-util/constants.d.ts +4 -0
  39. package/lib/minify-ethereumjs-util/constants.js +9 -0
  40. package/lib/minify-ethereumjs-util/constants.js.map +1 -0
  41. package/lib/minify-ethereumjs-util/helper.d.ts +5 -0
  42. package/lib/minify-ethereumjs-util/helper.js +16 -0
  43. package/lib/minify-ethereumjs-util/helper.js.map +1 -0
  44. package/lib/minify-ethereumjs-util/internal.d.ts +8 -0
  45. package/lib/minify-ethereumjs-util/internal.js +33 -0
  46. package/lib/minify-ethereumjs-util/internal.js.map +1 -0
  47. package/lib/minify-ethereumjs-util/signature.d.ts +13 -0
  48. package/lib/minify-ethereumjs-util/signature.js +45 -0
  49. package/lib/minify-ethereumjs-util/signature.js.map +1 -0
  50. package/lib/minify-swtc-keypair/address-codec.d.ts +16 -0
  51. package/lib/minify-swtc-keypair/address-codec.js +166 -0
  52. package/lib/minify-swtc-keypair/address-codec.js.map +1 -0
  53. package/lib/minify-swtc-keypair/index.d.ts +25 -0
  54. package/lib/minify-swtc-keypair/index.js +178 -0
  55. package/lib/minify-swtc-keypair/index.js.map +1 -0
  56. package/lib/minify-swtc-keypair/sha512.d.ts +9 -0
  57. package/lib/minify-swtc-keypair/sha512.js +33 -0
  58. package/lib/minify-swtc-keypair/sha512.js.map +1 -0
  59. package/lib/minify-swtc-keypair/utils.d.ts +13 -0
  60. package/lib/minify-swtc-keypair/utils.js +63 -0
  61. package/lib/minify-swtc-keypair/utils.js.map +1 -0
  62. package/lib/minify-tron/address.d.ts +6 -0
  63. package/lib/minify-tron/address.js +11 -0
  64. package/lib/minify-tron/address.js.map +1 -0
  65. package/lib/minify-tron/base58.d.ts +2 -0
  66. package/lib/minify-tron/base58.js +67 -0
  67. package/lib/minify-tron/base58.js.map +1 -0
  68. package/lib/minify-tron/bytes.d.ts +2 -0
  69. package/lib/minify-tron/bytes.js +23 -0
  70. package/lib/minify-tron/bytes.js.map +1 -0
  71. package/lib/minify-tron/code.d.ts +3 -0
  72. package/lib/minify-tron/code.js +56 -0
  73. package/lib/minify-tron/code.js.map +1 -0
  74. package/lib/minify-tron/crypto.d.ts +7 -0
  75. package/lib/minify-tron/crypto.js +83 -0
  76. package/lib/minify-tron/crypto.js.map +1 -0
  77. package/lib/minify-tron/message.d.ts +4 -0
  78. package/lib/minify-tron/message.js +42 -0
  79. package/lib/minify-tron/message.js.map +1 -0
  80. package/lib/types.d.ts +103 -0
  81. package/lib/types.js +16 -0
  82. package/lib/types.js.map +1 -0
  83. package/lib/util/index.d.ts +22 -0
  84. package/lib/util/index.js +100 -0
  85. package/lib/util/index.js.map +1 -0
  86. package/package.json +22 -17
package/lib/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /**
3
+ * MIT License
4
+ * Copyright (c) 2018 JCC Dex
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ * SOFTWARE.
20
+ * @author https://github.com/GinMu
21
+ */
22
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
23
+ if (k2 === undefined) k2 = k;
24
+ var desc = Object.getOwnPropertyDescriptor(m, k);
25
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
26
+ desc = { enumerable: true, get: function() { return m[k]; } };
27
+ }
28
+ Object.defineProperty(o, k2, desc);
29
+ }) : (function(o, m, k, k2) {
30
+ if (k2 === undefined) k2 = k;
31
+ o[k2] = m[k];
32
+ }));
33
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
34
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
35
+ }) : function(o, v) {
36
+ o["default"] = v;
37
+ });
38
+ var __importStar = (this && this.__importStar) || function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
46
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
47
+ };
48
+ var __importDefault = (this && this.__importDefault) || function (mod) {
49
+ return (mod && mod.__esModule) ? mod : { "default": mod };
50
+ };
51
+ Object.defineProperty(exports, "__esModule", { value: true });
52
+ exports.HDWallet = exports.hdWallet = exports.JingchangWallet = void 0;
53
+ const jingchangWallet_1 = __importDefault(require("./jingchangWallet"));
54
+ exports.JingchangWallet = jingchangWallet_1.default;
55
+ const hdWallet = __importStar(require("./hd"));
56
+ exports.hdWallet = hdWallet;
57
+ const hd_1 = require("./hd");
58
+ Object.defineProperty(exports, "HDWallet", { enumerable: true, get: function () { return hd_1.HDWallet; } });
59
+ __exportStar(require("./hd/plugins"), exports);
60
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,wEAAgD;AAIvC,0BAJF,yBAAe,CAIE;AAHxB,+CAAiC;AAGP,4BAAQ;AAFlC,6BAAgC;AAEI,yFAF3B,aAAQ,OAE2B;AAD5C,+CAA6B"}
@@ -0,0 +1,273 @@
1
+ import { IEncrypt, IJingchangWalletModel, IKeypairsModel, IKeystoreModel, IKeyPair } from "./types";
2
+ /**
3
+ * api of jingchang wallet
4
+ *
5
+ * @export
6
+ * @class JingchangWallet
7
+ */
8
+ export default class JingchangWallet {
9
+ static readonly version = "1.0";
10
+ private static readonly _name;
11
+ private static readonly _walletID;
12
+ private _jingchangWallet;
13
+ /**
14
+ * if the value is true, support save multiple wallet keystore for each type, otherwise only support one.
15
+ *
16
+ * @private
17
+ * @type {boolean}
18
+ * @memberof JingchangWallet
19
+ */
20
+ private _multiple;
21
+ /**
22
+ * if the value is true, use the default swt keystore's password which be generated in the beginning as password for other type.
23
+ *
24
+ * @private
25
+ * @type {boolean}
26
+ * @memberof JingchangWallet
27
+ */
28
+ private _samePassword;
29
+ /**
30
+ * Creates an instance of JingchangWallet.
31
+ * @param {IJingchangWalletModel} wallet
32
+ * @param {boolean} [multiple=false] if the value is true, support save multiple wallet keystore for each type, otherwise only support one.
33
+ * @param {boolean} [samePassword=true] if the value is true, use the default swt keystore's password which be generated
34
+ * in the beginning as password for other type.
35
+ * @memberof JingchangWallet
36
+ */
37
+ constructor(wallet: IJingchangWalletModel, multiple?: boolean, samePassword?: boolean);
38
+ /**
39
+ * check jingchang wallet is valid or not
40
+ *
41
+ * @static
42
+ * @param {*} wallet
43
+ * @returns {boolean} return true if valid.
44
+ * @memberof JingchangWallet
45
+ */
46
+ static isValid(wallet: any): boolean;
47
+ /**
48
+ * create a jingchang wallet
49
+ *
50
+ * @static
51
+ * @param {string} password password for keystore
52
+ * @param {string} [secret] swtc chain's secret
53
+ * @param {string} [alias] wallet name
54
+ * @returns {Promise<IJingchangWalletModel>} resolve jingchang wallet if success.
55
+ * @memberof JingchangWallet
56
+ */
57
+ static generate(password: string, secret?: string, alias?: string): Promise<IJingchangWalletModel>;
58
+ /**
59
+ * get jingchang wallet from local storage
60
+ *
61
+ * @static
62
+ * @returns {(IJingchangWalletModel | null)} return jingchang wallet or null
63
+ * @memberof JingchangWallet
64
+ */
65
+ static get(): IJingchangWalletModel | null;
66
+ /**
67
+ * clear jingchang wallet from local storage
68
+ *
69
+ * @static
70
+ * @memberof JingchangWallet
71
+ */
72
+ static clear(): void;
73
+ /**
74
+ * save jingchang wallet to local storage.
75
+ *
76
+ * @static
77
+ * @param {IJingchangWalletModel} wallet
78
+ * @memberof JingchangWallet
79
+ */
80
+ static save(wallet: IJingchangWalletModel): void;
81
+ /**
82
+ * derive key pair with secret
83
+ *
84
+ * @static
85
+ * @param {string} secret
86
+ * @param {string} [chain="swt"]
87
+ * @returns {IKeyPair} for privateKey, it's length should be 64 when call `decryptWithPrivateKey`, but the origin derived
88
+ * privateKey's length is 66 that contains prefix `00` for `secp256k1` or `ED` for `ed25519`, so removed it.
89
+ * @memberof JingchangWallet
90
+ */
91
+ static deriveKeyPair(secret: string, chain?: string): IKeyPair;
92
+ /**
93
+ * encrypt data with public key
94
+ *
95
+ * @static
96
+ * @param {string} message
97
+ * @param {string} publicKey
98
+ * @returns {Promise<IEncrypt>}
99
+ * @memberof JingchangWallet
100
+ */
101
+ static encryptWithPublicKey(message: string, publicKey: string): Promise<IEncrypt>;
102
+ /**
103
+ * decrypt data with private key
104
+ *
105
+ * @static
106
+ * @param {IEncrypt} message
107
+ * @param {string} privateKey the privateKey's length should be 64
108
+ * @returns {Promise<string>}
109
+ * @memberof JingchangWallet
110
+ */
111
+ static decryptWithPrivateKey(message: IEncrypt, privateKey: string): Promise<string>;
112
+ /**
113
+ * get wallets from jingchang wallet
114
+ *
115
+ * @static
116
+ * @param {IJingchangWalletModel} jcWallet
117
+ * @returns {Array<IKeystoreModel>} return wallets if valid, otherwise return empty array.
118
+ * @memberof JingchangWallet
119
+ */
120
+ static getWallets(keystore: IJingchangWalletModel): Array<IKeystoreModel>;
121
+ /**
122
+ * set property of _jingchangWallet
123
+ *
124
+ * @param {IJingchangWalletModel} wallet
125
+ * @memberof JingchangWallet
126
+ */
127
+ setJingchangWallet(wallet: IJingchangWalletModel): void;
128
+ /**
129
+ * get default wallet's keystore address for each type
130
+ *
131
+ * @param {string} [type="swt"]
132
+ * @returns {Promise<string>} resolve address if success
133
+ * @memberof JingchangWallet
134
+ */
135
+ getAddress(type?: string): Promise<string>;
136
+ /**
137
+ * get default wallet keystore with type
138
+ *
139
+ * @param {string} [type="swt"]
140
+ * @returns {Promise<IKeystoreModel>} resolve default wallet keystore if success.
141
+ * @memberof JingchangWallet
142
+ */
143
+ getWalletWithType(type?: string): Promise<IKeystoreModel>;
144
+ /**
145
+ * get wallet keystore with address
146
+ *
147
+ * @param {string} address
148
+ * @returns {Promise<IKeystoreModel>} resolve wallet keystore if success.
149
+ * @memberof JingchangWallet
150
+ */
151
+ getWalletWithAddress(address: string): Promise<IKeystoreModel>;
152
+ /**
153
+ * check if has default wallet for each type
154
+ *
155
+ * @param {string} [type="swt"]
156
+ * @returns {boolean} return true if has default
157
+ * @memberof JingchangWallet
158
+ */
159
+ hasDefault(type?: string): boolean;
160
+ /**
161
+ * get the default wallet keystore's secret with type.
162
+ *
163
+ * @param {string} password
164
+ * @param {string} [type="swt"]
165
+ * @returns {Promise<string>}
166
+ * @memberof JingchangWallet
167
+ */
168
+ getSecretWithType(password: string, type?: string): Promise<string>;
169
+ /**
170
+ * get the wallet keystore's secret with address.
171
+ *
172
+ * @param {string} password
173
+ * @param {string} address
174
+ * @returns {Promise<string>}
175
+ * @memberof JingchangWallet resolve secret if success.
176
+ */
177
+ getSecretWithAddress(password: string, address: string): Promise<string>;
178
+ /**
179
+ * change the whole jingchang wallet password, if you set property of _samePassword is false, will throw an error
180
+ *
181
+ * @param {string} oldPassword
182
+ * @param {string} newPassword
183
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
184
+ * @memberof JingchangWallet
185
+ */
186
+ changeWholePassword(oldPassword: string, newPassword: string): Promise<IJingchangWalletModel>;
187
+ /**
188
+ * change the keystore password with address, if you set the property of _samePassword is true, will throw an error
189
+ *
190
+ * @param {string} address
191
+ * @param {string} oldPassword
192
+ * @param {string} newPassword
193
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
194
+ * @memberof JingchangWallet
195
+ */
196
+ changePasswordWithAddress(address: string, oldPassword: string, newPassword: string): Promise<IJingchangWalletModel>;
197
+ /**
198
+ * replace keystore, if forget password
199
+ *
200
+ * @param {string} secret
201
+ * @param {string} password
202
+ * @param {(secret: string) => string} retriveSecret
203
+ * @returns {Promise<IJingchangWalletModel>}
204
+ * @memberof JingchangWallet
205
+ */
206
+ replaceKeystore(secret: string, password: string, retriveSecret: (secret: string) => string): Promise<IJingchangWalletModel>;
207
+ /**
208
+ * remove default wallet keystore of the given type
209
+ *
210
+ * @param {string} [type="swt"]
211
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
212
+ * @memberof JingchangWallet
213
+ */
214
+ removeWalletWithType(type?: string): Promise<IJingchangWalletModel>;
215
+ /**
216
+ * remove wallet keystore of the given address
217
+ *
218
+ * @param {string} address
219
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
220
+ * @memberof JingchangWallet
221
+ */
222
+ removeWalletWithAddress(address: string): Promise<IJingchangWalletModel>;
223
+ /**
224
+ * set defalut wallet keystore for each type
225
+ *
226
+ * @param {string} address
227
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
228
+ * @memberof JingchangWallet
229
+ */
230
+ setDefaultWallet(address: string): Promise<IJingchangWalletModel>;
231
+ /**
232
+ * import secret
233
+ *
234
+ * @param {string} secret
235
+ * @param {string} password
236
+ * @param {string} type
237
+ * @param {(secret: string) => string} retriveSecret
238
+ * @param {string} [alias] wallet name
239
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
240
+ * @memberof JingchangWallet
241
+ */
242
+ importSecret(secret: string, password: string, type: string, retriveSecret: (secret: string) => string, alias?: string): Promise<IJingchangWalletModel>;
243
+ /**
244
+ * find wallet keystore according to filter function
245
+ *
246
+ * @protected
247
+ * @param {(wallet: IKeystoreModel) => boolean} filter
248
+ * @returns {IKeystoreModel} return wallet keystore if existent, otherwise throw `keystore is invalid` if the jingchang wallet is invalid
249
+ * or throw `wallet is empty` if the wallet isn't existent
250
+ * @memberof JingchangWallet
251
+ */
252
+ protected findWallet(filter: (wallet: IKeystoreModel) => boolean): IKeystoreModel;
253
+ /**
254
+ * encrypt data
255
+ *
256
+ * @protected
257
+ * @param {string} password
258
+ * @param {IKeypairsModel} keypairs
259
+ * @returns {IKeystoreModel}
260
+ * @memberof JingchangWallet
261
+ */
262
+ protected getEncryptData(password: string, keypairs: IKeypairsModel): IKeystoreModel;
263
+ /**
264
+ * save wallet keystore to jingchang wallet
265
+ *
266
+ * @private
267
+ * @param {string} password
268
+ * @param {IKeypairsModel} keypairs
269
+ * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
270
+ * @memberof JingchangWallet
271
+ */
272
+ private saveWallet;
273
+ }