UNPKG

5.08 kBTypeScriptView Raw
1/// <reference types="node" />
2export { default as hdkey } from './hdkey';
3export { default as thirdparty } from './thirdparty';
4interface V3Params {
5 kdf: string;
6 cipher: string;
7 salt: string | Buffer;
8 iv: string | Buffer;
9 uuid: string | Buffer;
10 dklen: number;
11 c: number;
12 n: number;
13 r: number;
14 p: number;
15}
16interface ScryptKDFParamsOut {
17 dklen: number;
18 n: number;
19 p: number;
20 r: number;
21 salt: string;
22}
23interface PBKDFParamsOut {
24 c: number;
25 dklen: number;
26 prf: string;
27 salt: string;
28}
29declare type KDFParamsOut = ScryptKDFParamsOut | PBKDFParamsOut;
30interface V1Keystore {
31 Address: string;
32 Crypto: {
33 CipherText: string;
34 IV: string;
35 KeyHeader: {
36 Kdf: string;
37 KdfParams: {
38 DkLen: number;
39 N: number;
40 P: number;
41 R: number;
42 SaltLen: number;
43 };
44 Version: string;
45 };
46 MAC: string;
47 Salt: string;
48 };
49 Id: string;
50 Version: string;
51}
52interface V3Keystore {
53 crypto: {
54 cipher: string;
55 cipherparams: {
56 iv: string;
57 };
58 ciphertext: string;
59 kdf: string;
60 kdfparams: KDFParamsOut;
61 mac: string;
62 };
63 id: string;
64 version: number;
65}
66interface EthSaleKeystore {
67 encseed: string;
68 ethaddr: string;
69 btcaddr: string;
70 email: string;
71}
72export default class Wallet {
73 private readonly privateKey?;
74 private publicKey;
75 constructor(privateKey?: Buffer | undefined, publicKey?: Buffer | undefined);
76 /**
77 * Create an instance based on a new random key.
78 *
79 * @param icapDirect setting this to `true` will generate an address suitable for the `ICAP Direct mode`
80 */
81 static generate(icapDirect?: boolean): Wallet;
82 /**
83 * Create an instance where the address is valid against the supplied pattern (**this will be very slow**)
84 */
85 static generateVanityAddress(pattern: RegExp | string): Wallet;
86 /**
87 * Create an instance based on a public key (certain methods will not be available)
88 *
89 * This method only accepts uncompressed Ethereum-style public keys, unless
90 * the `nonStrict` flag is set to true.
91 */
92 static fromPublicKey(publicKey: Buffer, nonStrict?: boolean): Wallet;
93 /**
94 * Create an instance based on a BIP32 extended public key (xpub)
95 */
96 static fromExtendedPublicKey(extendedPublicKey: string): Wallet;
97 /**
98 * Create an instance based on a raw private key
99 */
100 static fromPrivateKey(privateKey: Buffer): Wallet;
101 /**
102 * Create an instance based on a BIP32 extended private key (xprv)
103 */
104 static fromExtendedPrivateKey(extendedPrivateKey: string): Wallet;
105 /**
106 * Import a wallet (Version 1 of the Ethereum wallet format).
107 *
108 * @param input A JSON serialized string, or an object representing V1 Keystore.
109 * @param password The keystore password.
110 */
111 static fromV1(input: string | V1Keystore, password: string): Promise<Wallet>;
112 /**
113 * Import a wallet (Version 3 of the Ethereum wallet format). Set `nonStrict` true to accept files with mixed-caps.
114 *
115 * @param input A JSON serialized string, or an object representing V3 Keystore.
116 * @param password The keystore password.
117 */
118 static fromV3(input: string | V3Keystore, password: string, nonStrict?: boolean): Promise<Wallet>;
119 static fromEthSale(input: string | EthSaleKeystore, password: string): Wallet;
120 /**
121 * Returns the wallet's public key.
122 */
123 private get pubKey();
124 /**
125 * Returns the wallet's private key.
126 */
127 private get privKey();
128 /**
129 * Returns the wallet's private key.
130 *
131 */
132 getPrivateKey(): Buffer;
133 getPrivateKeyString(): string;
134 /**
135 * Returns the wallet's public key.
136 */
137 getPublicKey(): Buffer;
138 /**
139 * Returns the wallet's public key as a "0x" prefixed hex string
140 */
141 getPublicKeyString(): string;
142 /**
143 * Returns the wallet's address.
144 */
145 getAddress(): Buffer;
146 /**
147 * Returns the wallet's address as a "0x" prefixed hex string
148 */
149 getAddressString(): string;
150 /**
151 * Returns the wallet's private key as a "0x" prefixed hex string checksummed
152 * according to [EIP 55](https://github.com/ethereum/EIPs/issues/55).
153 */
154 getChecksumAddressString(): string;
155 /**
156 * Returns an Etherem Version 3 Keystore Format object representing the wallet
157 *
158 * @param password The password used to encrypt the Keystore.
159 * @param opts The options for the keystore. See [its spec](https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition) for more info.
160 */
161 toV3(password: string, opts?: Partial<V3Params>): Promise<V3Keystore>;
162 /**
163 * Return the suggested filename for V3 keystores.
164 */
165 getV3Filename(timestamp?: number): string;
166 toV3String(password: string, opts?: Partial<V3Params>): Promise<string>;
167}
168
\No newline at end of file