UNPKG

blockchain-wallet-ts

Version:

TypeScript wrapper for Blockchain.info's wallet API

55 lines (54 loc) 1.75 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = __importDefault(require("axios")); const BlockchainWallet_1 = __importDefault(require("./BlockchainWallet")); class BlockchainApi { /** * Blockchain Wallet constructor */ constructor(config) { this.apiKey = config.apiKey; this.http = axios_1.default.create({ baseURL: config.apiUrl, }); } /** * Create a new wallet. */ createWallet(params) { params.api_code = params.api_code || this.apiKey; // This works around an issue that breaks the API when passing hd=false. // While also keeping 'hd' as an option that id enabled by default. if (params.hd || typeof params.hd === 'undefined') { params.hd = true; } else { delete params.hd; } return this.http.get('/api/v2/create', { params, }).then(({ data }) => { return new BlockchainWallet_1.default({ guid: data.guid, password: params.password, http: this.http, apiKey: this.apiKey, }); }); } /** * Fetch an existing wallet using the given guid and password. */ getWallet(wallet) { return new BlockchainWallet_1.default({ guid: wallet.guid, password: wallet.password, http: this.http, apiKey: this.apiKey, }); } } exports.default = BlockchainApi;