jcc_wallet 3.0.1 → 3.0.3

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 (47) hide show
  1. package/dist/jcc-wallet.min.js +78 -0
  2. package/lib/constant/index.d.ts +8 -0
  3. package/lib/constant/index.js +18 -0
  4. package/lib/constant/index.js.map +1 -0
  5. package/lib/eth/index.d.ts +37 -0
  6. package/lib/eth/index.js +98 -0
  7. package/lib/eth/index.js.map +1 -0
  8. package/lib/hd/constant.d.ts +26 -0
  9. package/lib/hd/constant.js +56 -0
  10. package/lib/hd/constant.js.map +1 -0
  11. package/lib/hd/eos.plugin.d.ts +5 -0
  12. package/lib/hd/eos.plugin.js +73 -0
  13. package/lib/hd/eos.plugin.js.map +1 -0
  14. package/lib/hd/ethereum.plugin.d.ts +5 -0
  15. package/lib/hd/ethereum.plugin.js +101 -0
  16. package/lib/hd/ethereum.plugin.js.map +1 -0
  17. package/lib/hd/index.d.ts +228 -0
  18. package/lib/hd/index.js +394 -0
  19. package/lib/hd/index.js.map +1 -0
  20. package/lib/hd/plugins.d.ts +2 -0
  21. package/lib/hd/plugins.js +36 -0
  22. package/lib/hd/plugins.js.map +1 -0
  23. package/lib/hd/swtc.plugin.d.ts +6 -0
  24. package/lib/hd/swtc.plugin.js +72 -0
  25. package/lib/hd/swtc.plugin.js.map +1 -0
  26. package/lib/hd/tron.plugin.d.ts +5 -0
  27. package/lib/hd/tron.plugin.js +67 -0
  28. package/lib/hd/tron.plugin.js.map +1 -0
  29. package/lib/index.d.ts +26 -0
  30. package/lib/index.js +62 -0
  31. package/lib/index.js.map +1 -0
  32. package/lib/jingchangWallet/index.d.ts +273 -0
  33. package/lib/jingchangWallet/index.js +713 -0
  34. package/lib/jingchangWallet/index.js.map +1 -0
  35. package/lib/moac/index.d.ts +29 -0
  36. package/lib/moac/index.js +58 -0
  37. package/lib/moac/index.js.map +1 -0
  38. package/lib/types/index.d.ts +90 -0
  39. package/lib/types/index.js +3 -0
  40. package/lib/types/index.js.map +1 -0
  41. package/lib/util/index.d.ts +22 -0
  42. package/lib/util/index.js +90 -0
  43. package/lib/util/index.js.map +1 -0
  44. package/lib/x-wallet/index.d.ts +22 -0
  45. package/lib/x-wallet/index.js +86 -0
  46. package/lib/x-wallet/index.js.map +1 -0
  47. package/package.json +2 -2
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XWallet = void 0;
4
+ var wallet_1 = require("@swtc/wallet");
5
+ // import { KeyPair } from "@swtc/wallet";
6
+ var common_1 = require("@swtc/common");
7
+ var XWallet = function (chain) {
8
+ return {
9
+ wallet: (0, wallet_1.Factory)(chain),
10
+ /**
11
+ * get address of wallet
12
+ *
13
+ * @param {IKeyPair | string} key is a keypair object or secret
14
+ *
15
+ * @returns {string} return address of wallet, return null if failed
16
+ */
17
+ address: function (key) {
18
+ try {
19
+ if (typeof key === "string") {
20
+ var wallet = this.wallet.fromSecret(key);
21
+ return wallet.address;
22
+ }
23
+ var keypair = this.wallet.KeyPair;
24
+ if (key.privateKey) {
25
+ return keypair.deriveAddress(keypair.deriveKeyPair(key.privateKey).publicKey);
26
+ }
27
+ if (key.publicKey) {
28
+ return keypair.deriveAddress(key.publicKey);
29
+ }
30
+ return null;
31
+ }
32
+ catch (error) {
33
+ return null;
34
+ }
35
+ },
36
+ isValidAddress: function (address) {
37
+ return this.wallet.isValidAddress(address);
38
+ },
39
+ isValidSecret: function (secret) {
40
+ return this.wallet.isValidSecret(secret);
41
+ },
42
+ hash: function (message) {
43
+ return (0, common_1.funcBytesToHex)(this.wallet.hash(message));
44
+ },
45
+ sign: function (message, privateKey) {
46
+ return this.wallet.KeyPair.sign(message, privateKey);
47
+ },
48
+ verify: function (message, signature, address, keypair) {
49
+ if (address !== this.address(keypair)) {
50
+ return false;
51
+ }
52
+ // check public key
53
+ if (!keypair.publicKey) {
54
+ keypair = this.wallet.KeyPair.deriveKeyPair(keypair.privateKey);
55
+ }
56
+ return this.wallet.KeyPair.verify(message, signature, keypair.publicKey);
57
+ },
58
+ recover: function () {
59
+ return "swtclib does not support.";
60
+ },
61
+ proxy: function (functionName) {
62
+ var _a;
63
+ var args = [];
64
+ for (var _i = 1; _i < arguments.length; _i++) {
65
+ args[_i - 1] = arguments[_i];
66
+ }
67
+ return (_a = this.wallet)[functionName].apply(_a, args);
68
+ }
69
+ };
70
+ };
71
+ exports.XWallet = XWallet;
72
+ //# sourceMappingURL=swtc.plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swtc.plugin.js","sourceRoot":"","sources":["../../src/hd/swtc.plugin.ts"],"names":[],"mappings":";;;AAAA,uCAAwD;AACxD,0CAA0C;AAC1C,uCAA4D;AAO5D,IAAM,OAAO,GAAG,UAAC,KAAa;IAC5B,OAAO;QACL,MAAM,EAAE,IAAA,gBAAa,EAAC,KAAK,CAAC;QAC5B;;;;;;WAMG;QACH,OAAO,YAAC,GAAsB;YAC5B,IAAI;gBACF,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;oBAC3B,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;oBAC3C,OAAO,MAAM,CAAC,OAAiB,CAAC;iBACjC;gBAED,IAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;gBACpC,IAAI,GAAG,CAAC,UAAU,EAAE;oBAClB,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,SAAS,CAAW,CAAC;iBACzF;gBACD,IAAI,GAAG,CAAC,SAAS,EAAE;oBACjB,OAAO,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAW,CAAC;iBACvD;gBAED,OAAO,IAAI,CAAC;aACb;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,IAAI,CAAC;aACb;QACH,CAAC;QAED,cAAc,YAAC,OAAe;YA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HDPlugin {
3
+ checkPrivateKey(privateKey: string): string;
4
+ }
5
+ export declare const plugin: ITronPlugin;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plugin = void 0;
4
+ var TronWeb = require("tronweb");
5
+ exports.plugin = {
6
+ checkPrivateKey: function (privateKey) {
7
+ // check and cut swtc keypair lib add prefix 00
8
+ return privateKey.length === 66 ? privateKey.substring(2) : privateKey;
9
+ },
10
+ address: function (key) {
11
+ if (key.privateKey) {
12
+ var privateKey = this.checkPrivateKey(key.privateKey);
13
+ var wallet = TronWeb.address.fromPrivateKey(privateKey);
14
+ return wallet;
15
+ }
16
+ if (key.publicKey) {
17
+ // TODO: length of ethereum publick key of keypaire is 128, but swtc lib keypair is 64
18
+ // so, if you want get address from public key, get it from private first
19
+ var pubBytes = TronWeb.utils.code.hexStr2byteArray(key.publicKey);
20
+ var comCddressBytes = TronWeb.utils.crypto.computeAddress(pubBytes);
21
+ return TronWeb.utils.crypto.getBase58CheckAddress(comCddressBytes);
22
+ }
23
+ return null;
24
+ },
25
+ isValidAddress: function (address) {
26
+ return TronWeb.utils.crypto.isAddressValid(address);
27
+ },
28
+ isValidSecret: function (secret) {
29
+ try {
30
+ var comPriKeyBytes = TronWeb.utils.code.hexStr2byteArray(this.checkPrivateKey(secret));
31
+ var pubBytes = TronWeb.utils.crypto.getPubKeyFromPriKey(comPriKeyBytes);
32
+ var comCddressBytes = TronWeb.utils.crypto.computeAddress(pubBytes);
33
+ var address = TronWeb.utils.crypto.getBase58CheckAddress(comCddressBytes);
34
+ return this.isValidAddress(address);
35
+ }
36
+ catch (error) {
37
+ return false;
38
+ }
39
+ },
40
+ hash: function (message) {
41
+ return TronWeb.utils.message.hashMessage(message);
42
+ },
43
+ /**
44
+ *
45
+ * @param message message content, let message is "\x19Ethereum Signed Message:\n" + message.length + message, match web3.accounts.sign function
46
+ * @param privateKey private key
47
+ * @returns signature string
48
+ */
49
+ sign: function (message, privateKey) {
50
+ var key = this.checkPrivateKey(privateKey).toLowerCase();
51
+ return TronWeb.Trx.signMessageV2(message, key);
52
+ },
53
+ verify: function (message, signature, address) {
54
+ return this.recover(message, signature) === address;
55
+ },
56
+ recover: function (message, signature) {
57
+ return TronWeb.Trx.verifyMessageV2(message, signature);
58
+ },
59
+ proxy: function (functionName) {
60
+ var args = [];
61
+ for (var _i = 1; _i < arguments.length; _i++) {
62
+ args[_i - 1] = arguments[_i];
63
+ }
64
+ return TronWeb[functionName].apply(TronWeb, args);
65
+ }
66
+ };
67
+ //# sourceMappingURL=tron.plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.plugin.js","sourceRoot":"","sources":["../../src/hd/tron.plugin.ts"],"names":[],"mappings":";;;AAAA,IAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAOtB,QAAA,MAAM,GAAgB;IACjC,eAAe,YAAC,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,YAAC,GAAa;QACnB,IAAI,GAAG,CAAC,UAAU,EAAE;YAClB,IAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACxD,IAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;YAC1D,OAAO,MAAgB,CAAC;SACzB;QACD,IAAI,GAAG,CAAC,SAAS,EAAE;YACjB,sFAAsF;YACtF,yEAAyE;YACzE,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACpE,IAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAA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OAAO,EAAE,SAAS,CAAC,KAAK,OAAO,CAAC;IACtD,CAAC;IACD,OAAO,YAAC,OAAe,EAAE,SAAiB;QACxC,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,EAAE,SAAS,CAAW,CAAC;IACnE,CAAC;IACD,KAAK,YAAC,YAAY;QAAE,cAAO;aAAP,UAAO,EAAP,qBAAO,EAAP,IAAO;YAAP,6BAAO;;QACzB,OAAO,OAAO,CAAC,YAAY,CAAC,OAArB,OAAO,EAAkB,IAAI,EAAE;IACxC,CAAC;CACF,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,26 @@
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 * as ethWallet from "./eth";
22
+ import JingchangWallet from "./jingchangWallet";
23
+ import * as moacWallet from "./moac";
24
+ import * as hdWallet from "./hd";
25
+ export * from "./x-wallet";
26
+ export { ethWallet, JingchangWallet, moacWallet, hdWallet };
package/lib/index.js ADDED
@@ -0,0 +1,62 @@
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.moacWallet = exports.JingchangWallet = exports.ethWallet = void 0;
53
+ var ethWallet = __importStar(require("./eth"));
54
+ exports.ethWallet = ethWallet;
55
+ var jingchangWallet_1 = __importDefault(require("./jingchangWallet"));
56
+ exports.JingchangWallet = jingchangWallet_1.default;
57
+ var moacWallet = __importStar(require("./moac"));
58
+ exports.moacWallet = moacWallet;
59
+ var hdWallet = __importStar(require("./hd"));
60
+ exports.hdWallet = hdWallet;
61
+ __exportStar(require("./x-wallet"), exports);
62
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAmC;AAO1B,8BAAS;AANlB,sEAAgD;AAM5B,0BANb,yBAAe,CAMa;AALnC,iDAAqC;AAKA,gCAAU;AAJ/C,6CAAiC;AAIgB,4BAAQ;AAFzD,6CAA2B"}
@@ -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
+ }