import * as superagent from 'superagent'; import * as bitcoin from '@bitgo/utxo-lib'; import { BaseCoin } from './v2/baseCoin'; import { EnvironmentName } from './v2/environments'; import { NodeCallback, RequestTracer as IRequestTracer, V1Network } from './v2/types'; import * as Bluebird from 'bluebird'; declare const supportedRequestMethods: readonly ["get", "post", "put", "del", "patch"]; export interface BitGoOptions { env?: EnvironmentName; clientId?: string; clientSecret?: string; accessToken?: string; userAgent?: string; customRootURI?: string; customBitcoinNetwork?: V1Network; customSigningAddress?: string; serverXpub?: string; stellarFederationServerUrl?: string; useProduction?: boolean; refreshToken?: string; validate?: boolean; proxy?: string; etherscanApiToken?: string; hmacVerification?: boolean; authVersion?: 2 | 3; } export interface User { username: string; } export interface BitGoJson { user?: User; token?: string; extensionKey?: string; } /** * @deprecated */ export interface DeprecatedVerifyAddressOptions { address?: string; } export interface VerifyPasswordOptions { password?: string; } export interface EncryptOptions { input?: string; password?: string; } export interface DecryptOptions { input?: string; password?: string; } export interface SplitSecretOptions { seed: string; passwords: string[]; m: number; } export interface SplitSecret { xpub: string; m: number; n: number; seedShares: any; } export interface ReconstituteSecretOptions { shards: string[]; passwords: string[]; } export interface ReconstitutedSecret { xpub: string; xprv: string; seed: string; } export interface VerifyShardsOptions { shards: string[]; passwords: string[]; m: number; xpub: string; } export interface GetEcdhSecretOptions { otherPubKeyHex: string; eckey: bitcoin.ECPair; } export interface AccessTokenOptions { accessToken: string; } export interface TokenIssuanceResponse { derivationPath: string; encryptedToken: string; encryptedECDHXprv?: string; } export interface TokenIssuance { token: string; ecdhXprv?: string; } export interface CalculateHmacSubjectOptions { urlPath: string; text: string; timestamp: number; method: typeof supportedRequestMethods[number]; statusCode?: number; } export interface CalculateRequestHmacOptions { url: string; text: string; timestamp: number; token: string; method: typeof supportedRequestMethods[number]; } export interface CalculateRequestHeadersOptions { url: string; text: string; token: string; method: typeof supportedRequestMethods[number]; } export interface RequestHeaders { hmac: string; timestamp: number; tokenHash: string; } export interface VerifyResponseOptions extends CalculateRequestHeadersOptions { hmac: string; url: string; text: string; timestamp: number; method: typeof supportedRequestMethods[number]; statusCode?: number; } export interface VerifyResponseInfo { isValid: boolean; expectedHmac: string; signatureSubject: string; isInResponseValidityWindow: boolean; verificationTime: number; } export interface AuthenticateOptions { username: string; password: string; otp?: string; trust?: number; forceSMS?: boolean; extensible?: boolean; forceV1Auth?: boolean; } export interface ProcessedAuthenticationOptions { email: string; password: string; forceSMS: boolean; otp?: string; trust?: number; extensible?: boolean; extensionAddress?: string; forceV1Auth?: boolean; } export interface AddAccessTokenOptions { label: string; otp?: string; duration?: number; ipRestrict?: string[]; txValueLimit?: number; scope: string[]; } export interface RemoveAccessTokenOptions { id?: string; label?: string; } export interface GetUserOptions { id: string; } export interface ChangePasswordOptions { oldPassword: string; newPassword: string; } export interface UnlockOptions { otp?: string; duration?: number; } export interface ExtendTokenOptions { duration?: string; } export interface GetSharingKeyOptions { email: string; } export interface PingOptions { reqId?: IRequestTracer; } /** * @deprecated */ export interface EstimateFeeOptions { numBlocks?: number; maxFee?: number; inputs?: string[]; txSize?: number; cpfpAware?: boolean; } /** * @deprecated */ export interface WebhookOptions { url: string; type: string; } export interface ListWebhookNotificationsOptions { prevId?: string; limit?: number; } export interface BitGoSimulateWebhookOptions { webhookId: string; blockId: string; } export interface AuthenticateWithAuthCodeOptions { authCode: string; } /** * @deprecated */ export interface VerifyPushTokenOptions { pushVerificationToken: string; } export interface BitGoRequest extends superagent.Request { result: (optionalField?: string) => Bluebird; end: (callback?: NodeCallback) => void; } export interface BitGo { get(url: string, callback?: NodeCallback): BitGoRequest; post(url: string, callback?: NodeCallback): BitGoRequest; put(url: string, callback?: NodeCallback): BitGoRequest; del(url: string, callback?: NodeCallback): BitGoRequest; patch(url: string, callback?: NodeCallback): BitGoRequest; } export declare class BitGo { private static _testnetWarningMessage; private static _constants; private static _constantsExpire; private readonly _env; /** * Expose env property for backwards compatibility * @deprecated */ readonly env: EnvironmentName; private readonly _baseUrl; private readonly _baseApiUrl; private readonly _baseApiUrlV2; private _user?; private _keychains; private _wallets; private readonly _clientId?; private readonly _clientSecret?; private _token?; private _refreshToken?; private readonly _userAgent; private readonly _promise; private _validate; private readonly _proxy?; private _reqId?; private _ecdhXprv?; private _extensionKey?; private _markets?; private _blockchain?; private _travelRule?; private _pendingApprovals?; private _hmacVerification; private readonly _authVersion; /** * Constructor for BitGo Object */ constructor(params?: BitGoOptions); /** * This is a patching function which can apply our authorization * headers to any outbound request. * @param method */ private createPatch; /** * Calculate the HMAC for the given key and message * @param key {String} - the key to use for the HMAC * @param message {String} - the actual message to HMAC * @returns {*} - the result of the HMAC operation */ calculateHMAC(key: string, message: string): string; /** * Create a basecoin object * @param coinName */ coin(coinName: string): BaseCoin; /** * Create a basecoin object for a virtual token * @param tokenName * @param callback */ token(tokenName: string, callback?: NodeCallback): Bluebird; /** * */ getValidate(): boolean; /** * */ setValidate(validate: boolean): void; /** * Return the current BitGo environment */ getEnv(): EnvironmentName; /** * Return the current auth version used for requests to the BitGo server */ getAuthVersion(): number; /** * Clear out all state from this BitGo object, effectively logging out the current user. */ clear(): void; /** * Helper function to return a rejected promise or call callback with error * * @deprecated */ reject(msg: string, callback?: NodeCallback): Bluebird; /** * Gets the version of the BitGoJS package */ version(): string; /** * Serialize this BitGo object to a JSON object. * * Caution: contains sensitive data */ toJSON(): BitGoJson; /** * Deserialize a JSON serialized BitGo object. * * Overwrites the properties on the current BitGo object with * those of the deserialzed object. * * @param json */ fromJSON(json: BitGoJson): void; /** * Get the current user */ user(): User | undefined; /** * Verify a Bitcoin address is a valid base58 address * @deprecated */ verifyAddress(params?: DeprecatedVerifyAddressOptions): boolean; /** */ verifyPassword(params?: VerifyPasswordOptions, callback?: NodeCallback): Bluebird; /** * Utility function to encrypt locally. */ encrypt(params?: EncryptOptions): string; /** * Decrypt an encrypted string locally. */ decrypt(params?: DecryptOptions): string; /** * Generate a random password * @param {Number} numWords Number of 32-bit words * @returns {String} base58 random password */ generateRandomPassword(numWords?: number): string; /** * Split a secret into shards using Shamir Secret Sharing. * @param seed A hexadecimal secret to split * @param passwords An array of the passwords used to encrypt each share * @param m The threshold number of shards necessary to reconstitute the secret */ splitSecret({ seed, passwords, m }: SplitSecretOptions): SplitSecret; /** * Reconstitute a secret which was sharded with `splitSecret`. * @param shards * @param passwords */ reconstituteSecret({ shards, passwords }: ReconstituteSecretOptions): ReconstitutedSecret; /** * * @param shards * @param passwords * @param m * @param xpub Optional xpub to verify the results against */ verifyShards({ shards, passwords, m, xpub }: VerifyShardsOptions): boolean; /** * Construct an ECDH secret from a private key and other user's public key */ getECDHSecret({ otherPubKeyHex, eckey }: GetEcdhSecretOptions): string; /** * Gets the user's private keychain, used for receiving shares */ getECDHSharingKeychain(params?: Record, callback?: NodeCallback): Bluebird; /** * Get bitcoin market data */ markets(): any; /** * Get the latest bitcoin prices * (Deprecated: Will be removed in the future) use `bitgo.markets().latest()` * @deprecated */ market(params?: Record, callback?: NodeCallback): Bluebird; /** * Get market data from yesterday * (Deprecated: Will be removed in the future) use bitgo.markets().yesterday() */ yesterday(params?: Record, callback?: NodeCallback): Bluebird; /** * Synchronous method for activating an access token. */ authenticateWithAccessToken({ accessToken }: AccessTokenOptions): void; /** * * @param responseBody Response body object * @param password Password for the symmetric decryption */ handleTokenIssuance(responseBody: TokenIssuanceResponse, password?: string): TokenIssuance; /** * Calculate the subject string that is to be HMAC'ed for a HTTP request or response * @param urlPath request url, including query params * @param text request body text * @param timestamp request timestamp from `Date.now()` * @param statusCode Only set for HTTP responses, leave blank for requests * @param method request method * @returns {string} */ calculateHMACSubject({ urlPath, text, timestamp, statusCode, method }: CalculateHmacSubjectOptions): string; /** * Calculate the HMAC for an HTTP request */ calculateRequestHMAC({ url: urlPath, text, timestamp, token, method }: CalculateRequestHmacOptions): string; /** * Calculate request headers with HMAC */ calculateRequestHeaders({ url, text, token, method }: CalculateRequestHeadersOptions): RequestHeaders; /** * Verify the HMAC for an HTTP response */ verifyResponse({ url: urlPath, statusCode, text, timestamp, token, hmac, method }: VerifyResponseOptions): VerifyResponseInfo; /** * Process the username, password and otp into an object containing the username and hashed password, ready to * send to bitgo for authentication. */ preprocessAuthenticationParams({ username, password, otp, forceSMS, extensible, trust }: AuthenticateOptions): ProcessedAuthenticationOptions; /** * Login to the bitgo platform. */ authenticate(params: AuthenticateOptions, callback?: NodeCallback): Bluebird; /** * @param params * - operatingSystem: one of ios, android * - pushToken: hex-formatted token for the respective native push notification service * @param callback * @returns {*} * @deprecated */ registerPushToken(params: any, callback?: NodeCallback): Bluebird; /** * * @param params * - pushVerificationToken: the token received via push notification to confirm the device's mobility * @param callback * @deprecated */ verifyPushToken(params: VerifyPushTokenOptions, callback?: NodeCallback): Bluebird; /** * Login to the bitgo system using an authcode generated via Oauth */ authenticateWithAuthCode(params: AuthenticateWithAuthCodeOptions, callback?: NodeCallback): Bluebird; /** * Use refresh token to get new access token. * If the refresh token is null/defined, then we use the stored token from auth */ refreshToken(params?: { refreshToken?: string; }, callback?: NodeCallback): Bluebird; /** * * listAccessTokens * Get information on all of the BitGo access tokens on the user * @return { * id: * label: * user: * enterprise * client: * scope: * created: * expires: * origin: * isExtensible: * extensionAddress:
* unlock: * } */ listAccessTokens(params?: Record, callback?: NodeCallback): Bluebird; /** * addAccessToken * Add a BitGo API Access Token to the current user account * @param params { * otp: (required) * label: (required)