UNPKG

23 kBTypeScriptView Raw
1import * as utxolib from '@bitgo/utxo-lib';
2import { BaseCoin } from './v2/baseCoin';
3import { EnvironmentName } from './v2/environments';
4import { NodeCallback, RequestTracer as IRequestTracer, V1Network } from './v2/types';
5import * as Bluebird from 'bluebird';
6import { BitGoRequest } from './api';
7declare const supportedRequestMethods: readonly ["get", "post", "put", "del", "patch"];
8export interface BitGoOptions {
9 env?: EnvironmentName;
10 clientId?: string;
11 clientSecret?: string;
12 accessToken?: string;
13 userAgent?: string;
14 customRootURI?: string;
15 customBitcoinNetwork?: V1Network;
16 customSigningAddress?: string;
17 serverXpub?: string;
18 stellarFederationServerUrl?: string;
19 useProduction?: boolean;
20 refreshToken?: string;
21 validate?: boolean;
22 proxy?: string;
23 etherscanApiToken?: string;
24 hmacVerification?: boolean;
25 authVersion?: 2 | 3;
26}
27export interface User {
28 username: string;
29}
30export interface BitGoJson {
31 user?: User;
32 token?: string;
33 extensionKey?: string;
34 ecdhXprv?: string;
35}
36/**
37 * @deprecated
38 */
39export interface DeprecatedVerifyAddressOptions {
40 address?: string;
41}
42export interface VerifyPasswordOptions {
43 password?: string;
44}
45export interface EncryptOptions {
46 input?: string;
47 password?: string;
48}
49export interface DecryptOptions {
50 input?: string;
51 password?: string;
52}
53export interface SplitSecretOptions {
54 seed: string;
55 passwords: string[];
56 m: number;
57}
58export interface SplitSecret {
59 xpub: string;
60 m: number;
61 n: number;
62 seedShares: any;
63}
64export interface ReconstituteSecretOptions {
65 shards: string[];
66 passwords: string[];
67}
68export interface ReconstitutedSecret {
69 xpub: string;
70 xprv: string;
71 seed: string;
72}
73export interface VerifyShardsOptions {
74 shards: string[];
75 passwords: string[];
76 m: number;
77 xpub: string;
78}
79export interface GetEcdhSecretOptions {
80 otherPubKeyHex: string;
81 eckey: utxolib.ECPair.ECPairInterface;
82}
83export interface AccessTokenOptions {
84 accessToken: string;
85}
86export interface TokenIssuanceResponse {
87 derivationPath: string;
88 encryptedToken: string;
89 encryptedECDHXprv?: string;
90}
91export interface TokenIssuance {
92 token: string;
93 ecdhXprv?: string;
94}
95export interface CalculateHmacSubjectOptions {
96 urlPath: string;
97 text: string;
98 timestamp: number;
99 method: typeof supportedRequestMethods[number];
100 statusCode?: number;
101}
102export interface CalculateRequestHmacOptions {
103 url: string;
104 text: string;
105 timestamp: number;
106 token: string;
107 method: typeof supportedRequestMethods[number];
108}
109export interface CalculateRequestHeadersOptions {
110 url: string;
111 text: string;
112 token: string;
113 method: typeof supportedRequestMethods[number];
114}
115export interface RequestHeaders {
116 hmac: string;
117 timestamp: number;
118 tokenHash: string;
119}
120export interface VerifyResponseOptions extends CalculateRequestHeadersOptions {
121 hmac: string;
122 url: string;
123 text: string;
124 timestamp: number;
125 method: typeof supportedRequestMethods[number];
126 statusCode?: number;
127}
128export interface VerifyResponseInfo {
129 isValid: boolean;
130 expectedHmac: string;
131 signatureSubject: string;
132 isInResponseValidityWindow: boolean;
133 verificationTime: number;
134}
135export interface AuthenticateOptions {
136 username: string;
137 password: string;
138 otp?: string;
139 trust?: number;
140 forceSMS?: boolean;
141 extensible?: boolean;
142 forceV1Auth?: boolean;
143}
144export interface ProcessedAuthenticationOptions {
145 email: string;
146 password: string;
147 forceSMS: boolean;
148 otp?: string;
149 trust?: number;
150 extensible?: boolean;
151 extensionAddress?: string;
152 forceV1Auth?: boolean;
153}
154export interface AddAccessTokenOptions {
155 label: string;
156 otp?: string;
157 duration?: number;
158 ipRestrict?: string[];
159 txValueLimit?: number;
160 scope: string[];
161}
162export interface RemoveAccessTokenOptions {
163 id?: string;
164 label?: string;
165}
166export interface GetUserOptions {
167 id: string;
168}
169export interface ChangePasswordOptions {
170 oldPassword: string;
171 newPassword: string;
172}
173export interface UnlockOptions {
174 otp?: string;
175 duration?: number;
176}
177export interface ExtendTokenOptions {
178 duration?: string;
179}
180export interface GetSharingKeyOptions {
181 email: string;
182}
183export interface PingOptions {
184 reqId?: IRequestTracer;
185}
186/**
187 * @deprecated
188 */
189export interface EstimateFeeOptions {
190 numBlocks?: number;
191 maxFee?: number;
192 inputs?: string[];
193 txSize?: number;
194 cpfpAware?: boolean;
195}
196/**
197 * @deprecated
198 */
199export interface WebhookOptions {
200 url: string;
201 type: string;
202}
203export interface ListWebhookNotificationsOptions {
204 prevId?: string;
205 limit?: number;
206}
207export interface BitGoSimulateWebhookOptions {
208 webhookId: string;
209 blockId: string;
210}
211export interface AuthenticateWithAuthCodeOptions {
212 authCode: string;
213}
214/**
215 * @deprecated
216 */
217export interface VerifyPushTokenOptions {
218 pushVerificationToken: string;
219}
220/**
221 * @deprecated
222 */
223export interface RegisterPushTokenOptions {
224 pushToken: unknown;
225 operatingSystem: unknown;
226}
227export interface BitGo {
228 get(url: string): BitGoRequest;
229 post(url: string): BitGoRequest;
230 put(url: string): BitGoRequest;
231 del(url: string): BitGoRequest;
232 patch(url: string): BitGoRequest;
233}
234export declare class BitGo {
235 private static _testnetWarningMessage;
236 private static _constants;
237 private static _constantsExpire;
238 private readonly _env;
239 /**
240 * Expose env property for backwards compatibility
241 * @deprecated
242 */
243 readonly env: EnvironmentName;
244 private readonly _baseUrl;
245 private readonly _baseApiUrl;
246 private readonly _baseApiUrlV2;
247 private _user?;
248 private _keychains;
249 private _wallets;
250 private readonly _clientId?;
251 private readonly _clientSecret?;
252 private _token?;
253 private _refreshToken?;
254 private readonly _userAgent;
255 private _validate;
256 private readonly _proxy?;
257 private _reqId?;
258 private _ecdhXprv?;
259 private _extensionKey?;
260 private _markets?;
261 private _blockchain?;
262 private _travelRule?;
263 private _pendingApprovals?;
264 private _hmacVerification;
265 private readonly _authVersion;
266 /**
267 * Constructor for BitGo Object
268 */
269 constructor(params?: BitGoOptions);
270 /**
271 * This is a patching function which can apply our authorization
272 * headers to any outbound request.
273 * @param method
274 */
275 private createPatch;
276 /**
277 * Calculate the HMAC for the given key and message
278 * @param key {String} - the key to use for the HMAC
279 * @param message {String} - the actual message to HMAC
280 * @returns {*} - the result of the HMAC operation
281 */
282 calculateHMAC(key: string, message: string): string;
283 /**
284 * Create a basecoin object
285 * @param coinName
286 */
287 coin(coinName: string): BaseCoin;
288 /**
289 * Create a basecoin object for a virtual token
290 * @param tokenName
291 * @param callback
292 */
293 token(tokenName: string, callback?: NodeCallback<BaseCoin>): Bluebird<BaseCoin>;
294 /**
295 *
296 */
297 getValidate(): boolean;
298 /**
299 *
300 */
301 setValidate(validate: boolean): void;
302 /**
303 * Return the current BitGo environment
304 */
305 getEnv(): EnvironmentName;
306 /**
307 * Return the current auth version used for requests to the BitGo server
308 */
309 getAuthVersion(): number;
310 /**
311 * Clear out all state from this BitGo object, effectively logging out the current user.
312 */
313 clear(): void;
314 /**
315 * Gets the version of the BitGoJS package
316 */
317 version(): string;
318 /**
319 * Serialize this BitGo object to a JSON object.
320 *
321 * Caution: contains sensitive data
322 */
323 toJSON(): BitGoJson;
324 /**
325 * Deserialize a JSON serialized BitGo object.
326 *
327 * Overwrites the properties on the current BitGo object with
328 * those of the deserialzed object.
329 *
330 * @param json
331 */
332 fromJSON(json: BitGoJson): void;
333 /**
334 * Get the current user
335 */
336 user(): User | undefined;
337 /**
338 * Verify a Bitcoin address is a valid base58 address
339 * @deprecated
340 */
341 verifyAddress(params?: DeprecatedVerifyAddressOptions): boolean;
342 /**
343 */
344 verifyPassword(params?: VerifyPasswordOptions): Promise<any>;
345 /**
346 * Utility function to encrypt locally.
347 */
348 encrypt(params?: EncryptOptions): string;
349 /**
350 * Decrypt an encrypted string locally.
351 */
352 decrypt(params?: DecryptOptions): string;
353 /**
354 * Generate a random password
355 * @param {Number} numWords Number of 32-bit words
356 * @returns {String} base58 random password
357 */
358 generateRandomPassword(numWords?: number): string;
359 /**
360 * Split a secret into shards using Shamir Secret Sharing.
361 * @param seed A hexadecimal secret to split
362 * @param passwords An array of the passwords used to encrypt each share
363 * @param m The threshold number of shards necessary to reconstitute the secret
364 */
365 splitSecret({ seed, passwords, m }: SplitSecretOptions): SplitSecret;
366 /**
367 * Reconstitute a secret which was sharded with `splitSecret`.
368 * @param shards
369 * @param passwords
370 */
371 reconstituteSecret({ shards, passwords }: ReconstituteSecretOptions): ReconstitutedSecret;
372 /**
373 *
374 * @param shards
375 * @param passwords
376 * @param m
377 * @param xpub Optional xpub to verify the results against
378 */
379 verifyShards({ shards, passwords, m, xpub }: VerifyShardsOptions): boolean;
380 /**
381 * @deprecated - use `getSharedSecret()`
382 */
383 getECDHSecret({ otherPubKeyHex, eckey }: GetEcdhSecretOptions): string;
384 /**
385 * Gets the user's private keychain, used for receiving shares
386 */
387 getECDHSharingKeychain(): Promise<any>;
388 /**
389 * Get bitcoin market data
390 *
391 * @deprecated
392 */
393 markets(): any;
394 /**
395 * Get the latest bitcoin prices
396 * (Deprecated: Will be removed in the future) use `bitgo.markets().latest()`
397 * @deprecated
398 */
399 market(): Promise<any>;
400 /**
401 * Get market data from yesterday
402 * (Deprecated: Will be removed in the future) use bitgo.markets().yesterday()
403 * @deprecated
404 */
405 yesterday(): Promise<any>;
406 /**
407 * Synchronous method for activating an access token.
408 */
409 authenticateWithAccessToken({ accessToken }: AccessTokenOptions): void;
410 /**
411 *
412 * @param responseBody Response body object
413 * @param password Password for the symmetric decryption
414 */
415 handleTokenIssuance(responseBody: TokenIssuanceResponse, password?: string): TokenIssuance;
416 /**
417 * Calculate the subject string that is to be HMAC'ed for a HTTP request or response
418 * @param urlPath request url, including query params
419 * @param text request body text
420 * @param timestamp request timestamp from `Date.now()`
421 * @param statusCode Only set for HTTP responses, leave blank for requests
422 * @param method request method
423 * @returns {string}
424 */
425 calculateHMACSubject({ urlPath, text, timestamp, statusCode, method }: CalculateHmacSubjectOptions): string;
426 /**
427 * Calculate the HMAC for an HTTP request
428 */
429 calculateRequestHMAC({ url: urlPath, text, timestamp, token, method }: CalculateRequestHmacOptions): string;
430 /**
431 * Calculate request headers with HMAC
432 */
433 calculateRequestHeaders({ url, text, token, method }: CalculateRequestHeadersOptions): RequestHeaders;
434 /**
435 * Verify the HMAC for an HTTP response
436 */
437 verifyResponse({ url: urlPath, statusCode, text, timestamp, token, hmac, method }: VerifyResponseOptions): VerifyResponseInfo;
438 /**
439 * Process the username, password and otp into an object containing the username and hashed password, ready to
440 * send to bitgo for authentication.
441 */
442 preprocessAuthenticationParams({ username, password, otp, forceSMS, extensible, trust }: AuthenticateOptions): ProcessedAuthenticationOptions;
443 /**
444 * Login to the bitgo platform.
445 */
446 authenticate(params: AuthenticateOptions): Promise<any>;
447 /**
448 * @param params
449 * - operatingSystem: one of ios, android
450 * - pushToken: hex-formatted token for the respective native push notification service
451 * @returns {*}
452 * @deprecated
453 */
454 registerPushToken(params: RegisterPushTokenOptions): Promise<any>;
455 /**
456 * @param params
457 * - pushVerificationToken: the token received via push notification to confirm the device's mobility
458 * @deprecated
459 */
460 verifyPushToken(params: VerifyPushTokenOptions): Promise<any>;
461 /**
462 * Login to the bitgo system using an authcode generated via Oauth
463 */
464 authenticateWithAuthCode(params: AuthenticateWithAuthCodeOptions): Promise<any>;
465 /**
466 * Use refresh token to get new access token.
467 * If the refresh token is null/defined, then we use the stored token from auth
468 */
469 refreshToken(params?: {
470 refreshToken?: string;
471 }): Promise<any>;
472 /**
473 *
474 * listAccessTokens
475 * Get information on all of the BitGo access tokens on the user
476 * @return {
477 * id: <id of the token>
478 * label: <the user-provided label for this token>
479 * user: <id of the user on the token>
480 * enterprise <id of the enterprise this token is valid for>
481 * client: <the auth client that this token belongs to>
482 * scope: <list of allowed OAuth scope values>
483 * created: <date the token was created>
484 * expires: <date the token will expire>
485 * origin: <the origin for which this token is valid>
486 * isExtensible: <flag indicating if the token can be extended>
487 * extensionAddress: <address whose private key's signature is necessary for extensions>
488 * unlock: <info for actions that require an unlock before firing>
489 * }
490 */
491 listAccessTokens(): Promise<any>;
492 /**
493 * addAccessToken
494 * Add a BitGo API Access Token to the current user account
495 * @param params {
496 * otp: (required) <valid otp code>
497 * label: (required) <label for the token>
498 * duration: <length of time in seconds the token will be valid for>
499 * ipRestrict: <array of IP address strings to whitelist>
500 * txValueLimit: <number of outgoing satoshis allowed on this token>
501 * scope: (required) <authorization scope of the requested token>
502 * }
503 * @return {
504 * id: <id of the token>
505 * token: <access token hex string to be used for BitGo API request verification>
506 * label: <user-provided label for this token>
507 * user: <id of the user on the token>
508 * enterprise <id of the enterprise this token is valid for>
509 * client: <the auth client that this token belongs to>
510 * scope: <list of allowed OAuth scope values>
511 * created: <date the token was created>
512 * expires: <date the token will expire>
513 * origin: <the origin for which this token is valid>
514 * isExtensible: <flag indicating if the token can be extended>
515 * extensionAddress: <address whose private key's signature is necessary for extensions>
516 * unlock: <info for actions that require an unlock before firing>
517 * }
518 */
519 addAccessToken(params: AddAccessTokenOptions): Promise<any>;
520 /**
521 * Sets the expire time of an access token matching either the id or label to the current date, effectively deleting it
522 *
523 * Params:
524 * id: <id of the access token to be deleted>
525 * label: <label of the access token to be deleted>
526 *
527 * Returns:
528 * id: <id of the token>
529 * label: <user-provided label for this token>
530 * user: <id of the user on the token>
531 * enterprise <id of the enterprise this token is valid for>
532 * client: <the auth client that this token belongs to>
533 * scope: <list of allowed OAuth scope values>
534 * created: <date the token was created>
535 * expires: <date the token will expire>
536 * origin: <the origin for which this token is valid>
537 * isExtensible: <flag indicating if the token can be extended>
538 * extensionAddress: <address whose private key's signature is ne*cessary for extensions>
539 * unlock: <info for actions that require an unlock before firing>
540 * @param params
541 */
542 removeAccessToken({ id, label }: RemoveAccessTokenOptions): Promise<any>;
543 /**
544 * Logout of BitGo
545 */
546 logout(): Promise<any>;
547 /**
548 * Get a user by ID (name/email only)
549 * @param id
550 *
551 * @deprecated
552 */
553 getUser({ id }: GetUserOptions): Promise<any>;
554 /**
555 * Change the password of the currently logged in user.
556 * Also change all v1 and v2 keychain passwords if they match the
557 * given oldPassword. Returns nothing on success.
558 * @param oldPassword {String} - the current password
559 * @param newPassword {String} - the new password
560 */
561 changePassword({ oldPassword, newPassword }: ChangePasswordOptions): Promise<any>;
562 /**
563 * Get the current logged in user
564 */
565 me(): Promise<any>;
566 /**
567 * Unlock the session by providing OTP
568 * @param {string} otp Required OTP code for the account.
569 * @param {number} duration Desired duration of the unlock in seconds (default=600, max=3600).
570 */
571 unlock({ otp, duration }: UnlockOptions): Promise<any>;
572 /**
573 * Lock the session
574 */
575 lock(): Promise<any>;
576 /**
577 * Get the current session
578 */
579 session(): Promise<any>;
580 /**
581 * Trigger a push/sms for the OTP code
582 * @param {boolean} params.forceSMS If set to true, will use SMS to send the OTP to the user even if they have other 2FA method set up.
583 * @deprecated
584 */
585 sendOTP(params?: {
586 forceSMS?: boolean;
587 }): Promise<any>;
588 /**
589 * Extend token, provided the current token is extendable
590 * @param params
591 * - duration: duration in seconds by which to extend the token, starting at the current time
592 */
593 extendToken(params?: ExtendTokenOptions): Promise<any>;
594 /**
595 * Get a key for sharing a wallet with a user
596 * @param email email of user to share wallet with
597 */
598 getSharingKey({ email }: GetSharingKeyOptions): Promise<any>;
599 /**
600 * Test connectivity to the server
601 * @param params
602 */
603 ping({ reqId }?: PingOptions): Promise<any>;
604 /**
605 * Get the blockchain object.
606 * @deprecated
607 */
608 blockchain(): any;
609 /**
610 * Get the user's keychains object.
611 * @deprecated
612 */
613 keychains(): any;
614 /**
615 * Get the user's wallets object.
616 * @deprecated
617 */
618 wallets(): any;
619 /**
620 * Get the travel rule object
621 * @deprecated
622 */
623 travelRule(): any;
624 /**
625 * Get pending approvals that can be approved/ or rejected
626 * @deprecated
627 */
628 pendingApprovals(): any;
629 /**
630 * A factory method to create a new Wallet object, initialized with the wallet params
631 * Can be used to reconstitute a wallet from cached data
632 * @param walletParams
633 * @deprecated
634 */
635 newWalletObject(walletParams: any): any;
636 /**
637 * Create a url for calling BitGo platform APIs
638 * @param path
639 * @param version
640 */
641 url(path: string, version?: number): string;
642 /**
643 * Create a url for calling BitGo microservice APIs
644 */
645 microservicesUrl(path: string): string;
646 /**
647 * Get all the address labels on all of the user's wallets
648 *
649 * @deprecated
650 */
651 labels(): Promise<any>;
652 /**
653 * Estimates approximate fee per kb needed for a tx to get into a block
654 * @param {number} params.numBlocks target blocks for the transaction to be confirmed
655 * @param {number} params.maxFee maximum fee willing to be paid (for safety)
656 * @param {array[string]} params.inputs list of unconfirmed txIds from which this transaction uses inputs
657 * @param {number} params.txSize estimated transaction size in bytes, optional parameter used for CPFP estimation.
658 * @param {boolean} params.cpfpAware flag indicating fee should take into account CPFP
659 * @deprecated
660 */
661 estimateFee(params?: EstimateFeeOptions): Promise<any>;
662 /**
663 * Get BitGo's guarantee using an instant id
664 * @param params
665 * @deprecated
666 */
667 instantGuarantee(params: {
668 id: string;
669 }): Promise<any>;
670 /**
671 * Get a target address for payment of a BitGo fee
672 * @deprecated
673 */
674 getBitGoFeeAddress(): Promise<any>;
675 /**
676 * Gets an address object (including the wallet id) for a given address.
677 * @param {string} params.address The address to look up.
678 * @deprecated
679 */
680 getWalletAddress({ address }: {
681 address: string;
682 }): Promise<any>;
683 /**
684 * Fetch list of user webhooks
685 *
686 * @returns {*}
687 * @deprecated
688 */
689 listWebhooks(): Promise<any>;
690 /**
691 * Add new user webhook
692 *
693 * @param params
694 * @returns {*}
695 * @deprecated
696 */
697 addWebhook(params: WebhookOptions): Promise<any>;
698 /**
699 * Remove user webhook
700 *
701 * @param params
702 * @returns {*}
703 * @deprecated
704 */
705 removeWebhook(params: WebhookOptions): Promise<any>;
706 /**
707 * Fetch list of webhook notifications for the user
708 *
709 * @param params
710 * @returns {*}
711 */
712 listWebhookNotifications(params?: ListWebhookNotificationsOptions): Promise<any>;
713 /**
714 * Simulate a user webhook
715 *
716 * @param params
717 * @returns {*}
718 */
719 simulateWebhook(params: BitGoSimulateWebhookOptions): Promise<any>;
720 /**
721 * Fetch useful constant values from the BitGo server.
722 * These values do change infrequently, so they need to be fetched,
723 * but are unlikely to change during the lifetime of a BitGo object,
724 * so they can safely cached.
725 */
726 fetchConstants(): Promise<any>;
727 /**
728 * Synchronously get constants which are relevant to the client.
729 *
730 * Note: This function has a known race condition. It may return different values over time,
731 * especially if called shortly after creation of the BitGo object.
732 *
733 * New code should call fetchConstants() directly instead.
734 *
735 * @deprecated
736 * @return {Object} The client constants object
737 */
738 getConstants(): any;
739 /**
740 * V1 method for calculating miner fee amounts, given the number and
741 * type of transaction inputs, along with a fee rate in satoshis per vkB.
742 *
743 * This method should not be used for new code.
744 *
745 * @deprecated
746 * @param params
747 * @return {any}
748 */
749 calculateMinerFeeInfo(params: any): Promise<any>;
750 /**
751 * Set a request tracer to provide request IDs during multi-request workflows
752 */
753 setRequestTracer(reqTracer: IRequestTracer): void;
754}
755export {};
756//# sourceMappingURL=bitgo.d.ts.map
\No newline at end of file