UNPKG

11.5 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as Bluebird from 'bluebird';
3import { BitGo } from '../bitgo';
4import { NodeCallback } from './types';
5import { RequestTracer } from './internal/util';
6import { Wallet } from './wallet';
7import { Wallets } from './wallets';
8import { Markets } from './markets';
9import { Webhooks } from './webhooks';
10import { PendingApprovals } from './pendingApprovals';
11import { Keychain, Keychains } from './keychains';
12import { Enterprises } from './enterprises';
13import { BaseCoin as AccountLibBasecoin } from '@bitgo/account-lib';
14import { InitiateRecoveryOptions } from './recovery/initiate';
15export declare type TransactionType = AccountLibBasecoin.TransactionType;
16export interface TransactionRecipient {
17 address: string;
18 amount: string | number;
19 memo?: string;
20}
21export interface TransactionFee {
22 fee: string;
23 feeRate?: number;
24 size?: number;
25}
26export interface TransactionExplanation {
27 displayOrder: string[];
28 id: string;
29 outputs: TransactionRecipient[];
30 outputAmount: string;
31 changeOutputs: TransactionRecipient[];
32 changeAmount: string;
33 fee: TransactionFee;
34 proxy?: string;
35 producers?: string[];
36}
37export interface KeyPair {
38 pub?: string;
39 prv: string;
40}
41export interface VerifyAddressOptions {
42 address: string;
43 addressType?: string;
44 keychains?: {
45 pub: string;
46 }[];
47 error?: string;
48 coinSpecific?: AddressCoinSpecific;
49}
50export interface TransactionParams {
51 recipients?: TransactionRecipient[];
52 walletPassphrase?: string;
53 type?: string;
54}
55export interface AddressVerificationData {
56 coinSpecific?: AddressCoinSpecific;
57 chain?: number;
58 index?: number;
59}
60export interface VerificationOptions {
61 disableNetworking?: boolean;
62 keychains?: {
63 user?: Keychain;
64 backup?: Keychain;
65 bitgo?: Keychain;
66 };
67 addresses?: {
68 [address: string]: AddressVerificationData;
69 };
70 allowPaygoOutput?: boolean;
71 considerMigratedFromAddressInternal?: boolean;
72}
73export interface VerifyTransactionOptions {
74 txPrebuild: TransactionPrebuild;
75 txParams: TransactionParams;
76 wallet: Wallet;
77 verification?: VerificationOptions;
78 reqId?: RequestTracer;
79}
80export interface SupplementGenerateWalletOptions {
81 label: string;
82 m: number;
83 n: number;
84 enterprise?: string;
85 disableTransactionNotifications?: boolean;
86 gasPrice?: number | string;
87 eip1559?: {
88 maxFeePerGas: number | string;
89 maxPriorityFeePerGas?: number | string;
90 };
91 walletVersion?: number;
92 keys: string[];
93 isCold: boolean;
94 keySignatures?: {
95 backup: string;
96 bitgo: string;
97 };
98 rootPrivateKey?: string;
99 disableKRSEmail?: boolean;
100}
101export interface FeeEstimateOptions {
102 numBlocks?: number;
103 hop?: boolean;
104 recipient?: string;
105 data?: string;
106 amount?: string;
107}
108export interface ExtraPrebuildParamsOptions {
109 [index: string]: unknown;
110}
111export interface PresignTransactionOptions {
112 [index: string]: unknown;
113}
114export interface PrecreateBitGoOptions {
115 [index: string]: unknown;
116}
117export interface VerifyRecoveryTransactionOptions {
118 [index: string]: unknown;
119}
120export interface ParseTransactionOptions {
121 [index: string]: unknown;
122}
123export interface ParsedTransaction {
124 [index: string]: unknown;
125}
126export interface SignTransactionOptions {
127 [index: string]: unknown;
128}
129export interface KeychainsTriplet {
130 userKeychain: Keychain;
131 backupKeychain: Keychain;
132 bitgoKeychain: Keychain;
133}
134export interface TransactionPrebuild {
135 txBase64?: string;
136 txHex?: string;
137 txInfo?: unknown;
138 wallet?: Wallet;
139 buildParams?: any;
140 consolidateId?: string;
141}
142export interface AddressCoinSpecific {
143 outputScript?: string;
144 redeemScript?: string;
145 witnessScript?: string;
146 baseAddress?: string;
147 pendingChainInitialization?: boolean;
148 forwarderVersion?: number;
149}
150export interface FullySignedTransaction {
151 txHex: string;
152}
153export interface HalfSignedUtxoTransaction {
154 txHex: string;
155}
156export interface HalfSignedAccountTransaction {
157 halfSigned?: {
158 txHex?: string;
159 payload?: string;
160 txBase64?: string;
161 };
162}
163export declare type SignedTransaction = HalfSignedAccountTransaction | HalfSignedUtxoTransaction | FullySignedTransaction;
164export declare abstract class BaseCoin {
165 protected readonly bitgo: BitGo;
166 protected readonly _url: string;
167 protected readonly _enterprises: Enterprises;
168 protected readonly _wallets: Wallets;
169 protected readonly _keychains: Keychains;
170 protected readonly _webhooks: Webhooks;
171 protected readonly _pendingApprovals: PendingApprovals;
172 protected readonly _markets: Markets;
173 protected static readonly _coinTokenPatternSeparator = ":";
174 protected constructor(bitgo: BitGo);
175 url(suffix: string): string;
176 wallets(): Wallets;
177 enterprises(): Enterprises;
178 keychains(): Keychains;
179 webhooks(): Webhooks;
180 pendingApprovals(): PendingApprovals;
181 markets(): Markets;
182 static get coinTokenPatternSeparator(): string;
183 get type(): string;
184 /**
185 * Name of the chain which supports this coin (eg, 'btc', 'eth')
186 */
187 abstract getChain(): string;
188 /**
189 * Name of the coin family (eg. for tbtc, this would be btc)
190 */
191 abstract getFamily(): string;
192 /**
193 * Human readable full name for the coin
194 */
195 abstract getFullName(): string;
196 /**
197 * Flag for sending value of 0.
198 * @returns {boolean} True if okay to send 0 value, false otherwise
199 */
200 valuelessTransferAllowed(): boolean;
201 /**
202 * Flag for sending data along with transactions
203 * @returns {boolean} True if okay to send tx data (ETH), false otherwise
204 */
205 transactionDataAllowed(): boolean;
206 /**
207 * Flag for determining whether this coin supports account consolidations
208 * from its receive addresses to the root address.
209 * @returns {boolean} True if okay to consolidate over this coin; false, otherwise
210 */
211 allowsAccountConsolidations(): boolean;
212 /**
213 * Returns the factor between the base unit and its smallest subdivison
214 * @return {number}
215 */
216 abstract getBaseFactor(): number | string;
217 /**
218 * Convert a currency amount represented in base units (satoshi, wei, atoms, drops, stroops)
219 * to big units (btc, eth, xrp, xlm)
220 */
221 baseUnitsToBigUnits(baseUnits: string | number): string;
222 /**
223 * Convert a currency amount represented in big units (btc, eth, xrp, xlm)
224 * to base units (satoshi, wei, atoms, drops, stroops)
225 * @param bigUnits
226 */
227 bigUnitsToBaseUnits(bigUnits: string | number): string;
228 /**
229 * Sign message with private key
230 *
231 * @param key
232 * @param message
233 * @param callback
234 */
235 signMessage(key: {
236 prv: string;
237 }, message: string, callback?: NodeCallback<Buffer>): Bluebird<Buffer>;
238 /**
239 * Verify that a transaction prebuild complies with the original intention
240 */
241 abstract verifyTransaction(params: VerifyTransactionOptions, callback?: NodeCallback<boolean>): Bluebird<boolean>;
242 /**
243 * Verify that an address belongs to a wallet
244 * @returns {boolean}
245 */
246 abstract verifyAddress(params: VerifyAddressOptions): boolean;
247 /**
248 * convert address into desired address format.
249 * @param address
250 * @param format
251 */
252 canonicalAddress(address: string, format?: unknown): string;
253 /**
254 * Check whether a coin supports blockTarget for transactions to be included in
255 * @returns {boolean}
256 */
257 supportsBlockTarget(): boolean;
258 /**
259 * Hook to add additional parameters to the wallet generation
260 * @param walletParams
261 * @param keychains
262 * @return {*}
263 */
264 supplementGenerateWallet(walletParams: SupplementGenerateWalletOptions, keychains: KeychainsTriplet): Bluebird<any>;
265 /**
266 * Get extra parameters for prebuilding a tx. Add things like hop transaction params
267 */
268 getExtraPrebuildParams(buildParams: ExtraPrebuildParamsOptions, callback?: NodeCallback<Record<string, unknown>>): Bluebird<Record<string, unknown>>;
269 /**
270 * Modify prebuild after receiving it from the server. Add things like nlocktime
271 */
272 postProcessPrebuild(prebuildResponse: TransactionPrebuild, callback?: NodeCallback<TransactionPrebuild>): Bluebird<TransactionPrebuild>;
273 /**
274 * Coin-specific things done before signing a transaction, i.e. verification
275 */
276 presignTransaction(params: PresignTransactionOptions, callback?: NodeCallback<TransactionPrebuild>): Bluebird<TransactionPrebuild>;
277 /**
278 * Create a new wallet object from a wallet data object
279 * @param walletParams
280 */
281 newWalletObject(walletParams: any): Wallet;
282 /**
283 * Fetch fee estimate information from the server
284 * @param {Object} params The params passed into the function
285 * @param {Integer} params.numBlocks The number of blocks to target for conformation (Only works for btc)
286 * @param callback
287 * @returns {Object} The info returned from the merchant server
288 */
289 feeEstimate(params: FeeEstimateOptions, callback?: NodeCallback<any>): Bluebird<any>;
290 /**
291 * The cold wallet tool uses this function to derive an extended key that is based on the passed key and seed
292 * @param key
293 * @param seed
294 * @returns {{key: string, derivationPath: string}}
295 */
296 deriveKeyWithSeed({ key, seed }: {
297 key: string;
298 seed: string;
299 }): {
300 key: string;
301 derivationPath: string;
302 };
303 /**
304 * Specifies what key we will need for signing - right now we just need the
305 * user key.
306 */
307 keyIdsForSigning(): number[];
308 /**
309 * Perform additional checks before adding a bitgo key. Base controller
310 * is a no-op, but coin-specific controller may do something
311 * @param params
312 */
313 preCreateBitGo(params: PrecreateBitGoOptions): void;
314 /**
315 * @deprecated - use getBip32Keys() in conjunction with isValidAddress instead
316 */
317 initiateRecovery(params: InitiateRecoveryOptions): never;
318 verifyRecoveryTransaction(txInfo: VerifyRecoveryTransactionOptions): Bluebird<any>;
319 abstract parseTransaction(params: ParseTransactionOptions, callback?: NodeCallback<ParsedTransaction>): Bluebird<ParsedTransaction>;
320 /**
321 * Generate a key pair on the curve used by the coin
322 *
323 * @param seed
324 */
325 abstract generateKeyPair(seed?: Buffer): KeyPair;
326 /**
327 * Return boolean indicating whether input is valid public key for the coin.
328 *
329 * @param {String} pub the pub to be checked
330 * @returns {Boolean} is it valid?
331 */
332 abstract isValidPub(pub: string): boolean;
333 /**
334 * Return wether the given m of n wallet signers/ key amounts are valid for the coin
335 */
336 isValidMofNSetup({ m, n }: {
337 m?: number;
338 n?: number;
339 }): boolean;
340 /**
341 * Check if `address` is a plausibly valid address for the given coin.
342 *
343 * Does not verify that the address belongs to a wallet. For that,
344 * use [[verifyAddress]]
345 * @param address
346 */
347 abstract isValidAddress(address: string): boolean;
348 /**
349 * Sign a transaction
350 */
351 abstract signTransaction(params: SignTransactionOptions): Promise<SignedTransaction>;
352}
353//# sourceMappingURL=baseCoin.d.ts.map
\No newline at end of file