UNPKG

6.33 kBTypeScriptView Raw
1/// <reference types="node" />
2import { BIP32 } from 'bip32';
3export declare type IdentityKeyPair = {
4 key: string;
5 keyID: string;
6 address: string;
7 appsNodeKey: string;
8 salt: string;
9};
10/**
11 * The BlockstackWallet class manages the hierarchical derivation
12 * paths for a standard blockstack client wallet. This includes paths
13 * for bitcoin payment address, blockstack identity addresses, blockstack
14 * application specific addresses.
15 * @private
16 */
17export declare class BlockstackWallet {
18 rootNode: BIP32;
19 constructor(rootNode: BIP32);
20 toBase58(): string;
21 /**
22 * Initialize a blockstack wallet from a seed buffer
23 * @param {Buffer} seed - the input seed for initializing the root node
24 * of the hierarchical wallet
25 * @return {BlockstackWallet} the constructed wallet
26 */
27 static fromSeedBuffer(seed: Buffer): BlockstackWallet;
28 /**
29 * Initialize a blockstack wallet from a base58 string
30 * @param {string} keychain - the Base58 string used to initialize
31 * the root node of the hierarchical wallet
32 * @return {BlockstackWallet} the constructed wallet
33 */
34 static fromBase58(keychain: string): BlockstackWallet;
35 /**
36 * Initialize a blockstack wallet from an encrypted phrase & password. Throws
37 * if the password is incorrect. Supports all formats of Blockstack phrases.
38 * @param {string} data - The encrypted phrase as a hex-encoded string
39 * @param {string} password - The plain password
40 * @return {Promise<BlockstackWallet>} the constructed wallet
41 */
42 static fromEncryptedMnemonic(data: string, password: string): Promise<BlockstackWallet>;
43 /**
44 * Generate a BIP-39 12 word mnemonic
45 * @return {Promise<string>} space-separated 12 word phrase
46 */
47 static generateMnemonic(): string;
48 /**
49 * Encrypt a mnemonic phrase with a password
50 * @param {string} mnemonic - Raw mnemonic phrase
51 * @param {string} password - Password to encrypt mnemonic with
52 * @return {Promise<string>} Hex-encoded encrypted mnemonic
53 */
54 static encryptMnemonic(mnemonic: string, password: string): Promise<string>;
55 getIdentityPrivateKeychain(): BIP32;
56 getBitcoinPrivateKeychain(): BIP32;
57 getBitcoinNode(addressIndex: number, chainType?: string): BIP32;
58 getIdentityAddressNode(identityIndex: number): BIP32;
59 static getAppsNode(identityNode: BIP32): BIP32;
60 /**
61 * Get a salt for use with creating application specific addresses
62 * @return {String} the salt
63 */
64 getIdentitySalt(): string;
65 /**
66 * Get a bitcoin receive address at a given index
67 * @param {number} addressIndex - the index of the address
68 * @return {String} address
69 */
70 getBitcoinAddress(addressIndex: number): string;
71 /**
72 * Get the private key hex-string for a given bitcoin receive address
73 * @param {number} addressIndex - the index of the address
74 * @return {String} the hex-string. this will be either 64
75 * characters long to denote an uncompressed bitcoin address, or 66
76 * characters long for a compressed bitcoin address.
77 */
78 getBitcoinPrivateKey(addressIndex: number): string;
79 /**
80 * Get the root node for the bitcoin public keychain
81 * @return {String} base58-encoding of the public node
82 */
83 getBitcoinPublicKeychain(): BIP32;
84 /**
85 * Get the root node for the identity public keychain
86 * @return {String} base58-encoding of the public node
87 */
88 getIdentityPublicKeychain(): BIP32;
89 static getNodeFromBitcoinKeychain(keychainBase58: string, addressIndex: number, chainType?: string): BIP32;
90 /**
91 * Get a bitcoin address given a base-58 encoded bitcoin node
92 * (usually called the account node)
93 * @param {String} keychainBase58 - base58-encoding of the node
94 * @param {number} addressIndex - index of the address to get
95 * @param {String} chainType - either 'EXTERNAL_ADDRESS' (for a
96 * "receive" address) or 'CHANGE_ADDRESS'
97 * @return {String} the address
98 */
99 static getAddressFromBitcoinKeychain(keychainBase58: string, addressIndex: number, chainType?: string): string;
100 /**
101 * Get a ECDSA private key hex-string for an application-specific
102 * address.
103 * @param {String} appsNodeKey - the base58-encoded private key for
104 * applications node (the `appsNodeKey` return in getIdentityKeyPair())
105 * @param {String} salt - a string, used to salt the
106 * application-specific addresses
107 * @param {String} appDomain - the appDomain to generate a key for
108 * @return {String} the private key hex-string. this will be a 64
109 * character string
110 */
111 static getLegacyAppPrivateKey(appsNodeKey: string, salt: string, appDomain: string): string;
112 static getAddressFromBIP32Node(node: BIP32): string;
113 /**
114 * Get a ECDSA private key hex-string for an application-specific
115 * address.
116 * @param {String} appsNodeKey - the base58-encoded private key for
117 * applications node (the `appsNodeKey` return in getIdentityKeyPair())
118 * @param {String} salt - a string, used to salt the
119 * application-specific addresses
120 * @param {String} appDomain - the appDomain to generate a key for
121 * @return {String} the private key hex-string. this will be a 64
122 * character string
123 */
124 static getAppPrivateKey(appsNodeKey: string, salt: string, appDomain: string): string;
125 /**
126 * Get the keypair information for a given identity index. This
127 * information is used to obtain the private key for an identity address
128 * and derive application specific keys for that address.
129 * @param {number} addressIndex - the identity index
130 * @param {boolean} alwaysUncompressed - if true, always return a
131 * private-key hex string corresponding to the uncompressed address
132 * @return {Object} an IdentityKeyPair type object with keys:
133 * .key {String} - the private key hex-string
134 * .keyID {String} - the public key hex-string
135 * .address {String} - the identity address
136 * .appsNodeKey {String} - the base-58 encoding of the applications node
137 * .salt {String} - the salt used for creating app-specific addresses
138 */
139 getIdentityKeyPair(addressIndex: number, alwaysUncompressed?: boolean): IdentityKeyPair;
140}