blockchain-wallet-ts
Version:
TypeScript wrapper for Blockchain.info's wallet API
102 lines (101 loc) • 3.45 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const BlockchainHDWallet_1 = __importDefault(require("./BlockchainHDWallet"));
const ApiClient_1 = __importDefault(require("./Providers/ApiClient"));
class BlockchainWallet extends ApiClient_1.default {
/**
* Blockchain Wallet constructor.
*/
constructor(config) {
super(config);
this.guid = config.guid;
this.password = config.password;
}
/**
* API Base path.
*/
get basePath() {
return `/merchant/${this.guid}`;
}
/**
* Parameters to be included in every API request.
*/
get baseParams() {
return { password: this.password };
}
/**
* Initiate a payment to the given address.
*/
pay(params) {
return this.request(`/payment`, params);
}
/**
* Initiate a payment to multiple recipients.
*/
payMany(params) {
return this.request(`/sendmany`, Object.assign(Object.assign({}, this.requestParams(params)), { recipients: JSON.stringify(params.recipients) }));
}
/**
* Wallet balance in satoshis.
*/
get balance() {
return this.request(`/balance`);
}
/**
* Enable HD wallet functionality for the current wallet.
*/
enableHD() {
return __awaiter(this, void 0, void 0, function* () {
yield this.request(`/enableHD`).then((data) => {
return new BlockchainHDWallet_1.default({
guid: this.guid,
password: this.password,
http: this.http,
apiKey: this.apiKey,
xpub: data.extendedPublicKey,
index: data.index,
});
});
});
}
/**
* Active HD accounts connected to this wallet.
*/
get accounts() {
return this.request(`/accounts`);
}
/**
* Fetch HD xPubs for this wallet.
*/
get xpubs() {
return this.request(`/accounts/xpubs`);
}
/**
* Create HD account.
*/
createHD(params) {
return this.request(`/accounts/create`, params).then((wallet) => {
return new BlockchainHDWallet_1.default({
xpub: wallet.xpub,
index: 0,
http: this.http,
apiKey: this.apiKey,
guid: this.guid,
password: this.password,
});
});
}
}
exports.default = BlockchainWallet;