blockchain-payments-node
Version:
Blockahain.info Payments wrapper for Node.js
110 lines (109 loc) • 3.73 kB
TypeScript
import { BlockchainApi } from './Interfaces/BlockchainApi';
/**
* Blockchain.info Payments API (V2)
*
* @link https://www.blockchain.com/api/api_receive
*/
export default class BlockchainPayments {
/**
* Webhook callback secret key. Used to validate incoming webhooks.
*
* @note You decide the value of this.
* @link https://www.blockchain.com/api/api_receive
*/
private readonly webhookSecret?;
/**
* Bitcoin BIP 32 wallet xPub
*
* @link https://api.blockchain.info/v2/apikey/request/
* @link https://blog.blockonomics.co/how-to-find-your-xpub-key-with-these-8-popular-bitcoin-wallets-ce8ea665ffdc
*/
private xpub;
/**
* Blockchain.info API Key
*
* @link https://api.blockchain.info/v2/apikey/request/
*/
private readonly apiKey;
/**
* Blockchain.info Payments API client.
*/
private api;
/**
* Blockchain Payments constructor
*/
constructor({ apiKey, xpub, webhookSecret }: ConstructorOptions);
/**
* Handle an API request error.
*/
private handleException;
/**
* Prepare querystring, including the API key using the given data.
*/
private buildQuery;
/**
* Create a payment address.
*/
createAddress(options: Method.Options.createPayment): Promise<BlockchainApi.GenerateAddress.Response>;
/**
* Monitor any Bitcoin address for incoming payments.
*/
watchAddress({ onNotification, confirmations, type, address, webhookUrl, }: Method.Options.monitorAddress): Promise<BlockchainApi.BalanceUpdates.Response>;
/**
* Stop address watching for the given watcher ID.
* IDs are returned by the watchAddress() method's response body.
*/
stopWatch(id: number): Promise<BlockchainApi.StopBalanceUpdates.Response>;
/**
* Update the currently used xPub to the given xPub.
*/
setXPub(xpub: string): void;
}
/**
* Options and responses for BlockchainPayments methods.
*/
declare namespace Method {
namespace Options {
interface createPayment {
/**
* URL to receive notifications whenever you receive a payment to the returned address.
*/
webhookUrl: string;
}
interface monitorAddress {
/**
* Bitcoin address to monitor.
*/
address: BlockchainApi.BalanceUpdates.Request['addr'];
/**
* URL to receive notifications on whenever you receive a payment for the submitted address.
*/
webhookUrl: BlockchainApi.BalanceUpdates.Request['callback'];
/**
* Request notification behaviour.
* Likely whether to keep or end notifying the provided callback URL once the transaction reaches the
* specified number of confirmations.
*/
onNotification?: BlockchainApi.BalanceUpdates.Request['onNotification'];
/**
* Number of confirmations to wait for before sending a notification to your callback URL.
* (Default: 3)
*/
confirmations?: BlockchainApi.BalanceUpdates.Request['confs'];
/**
* Address operation (send/receive) you would like to receive notifications for.
* (Default: 'ALL')
*/
type?: BlockchainApi.BalanceUpdates.Request['op'];
}
}
}
/**
* BlockchainPayments constructor options.
*/
interface ConstructorOptions {
xpub: string;
apiKey: string;
webhookSecret?: string;
}
export {};