UNPKG

@azpool/chia-client

Version:

TypeScript client for Chia node peer RPC interface

153 lines 5.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Wallet = void 0; const RpcClient_1 = require("./RpcClient"); // @ts-ignore const chia_utils_1 = require("chia-utils"); const defaultProtocol = "https"; const defaultHostname = process.env.CHIA__HOSTNAME || "0.0.0.0"; const defaultPort = parseInt(process.env.CHIA__WALLET__PORT || '9256') || 9256; const defaultCaCertPath = process.env.CHIA__CA_CERT_PATH || false; const defaultCertPath = process.env.CHIA__WALLET__CERT_PATH || ''; const defaultKeyPath = process.env.CHIA__WALLET__KEY_PATH || ''; const defaultBackupHost = process.env.CHIA__WALLET__BACKUP_HOST || "https://backup.chia.net"; class Wallet extends RpcClient_1.RpcClient { constructor(options) { super({ protocol: (options === null || options === void 0 ? void 0 : options.protocol) || defaultProtocol, hostname: (options === null || options === void 0 ? void 0 : options.hostname) || defaultHostname, port: (options === null || options === void 0 ? void 0 : options.port) || defaultPort, caCertPath: (options === null || options === void 0 ? void 0 : options.caCertPath) || defaultCaCertPath, certPath: (options === null || options === void 0 ? void 0 : options.certPath) || defaultCertPath, keyPath: (options === null || options === void 0 ? void 0 : options.keyPath) || defaultKeyPath, }); } async logIn(fingerprint) { return this.request("log_in", { host: defaultBackupHost, fingerprint, type: "start", }); } async logInAndRestore(fingerprint, filePath) { return this.request("log_in", { host: defaultBackupHost, fingerprint, type: "restore_backup", file_path: filePath, }); } async logInAndSkip(fingerprint) { return this.request("log_in", { host: defaultBackupHost, fingerprint, type: "skip", }); } async getPublicKeys() { const { public_key_fingerprints } = await this.request("get_public_keys", {}); return public_key_fingerprints; } async getPrivateKey(fingerprint) { const { private_key } = await this.request("get_private_key", { fingerprint }); return private_key; } async generateMnemonic() { const { mnemonic } = await this.request("generate_mnemonic", {}); return mnemonic; } async addKey(mnemonic, type = "new_wallet") { return this.request("add_key", { mnemonic, type, }); } async deleteKey(fingerprint) { return this.request("delete_key", { fingerprint }); } async deleteAllKeys() { return this.request("delete_all_keys", {}); } async getSyncStatus() { const { syncing } = await this.request("get_sync_status", {}); return syncing; } async getSyncStatusV2() { return await this.request("get_sync_status", {}); } async getHeightInfo() { const { height } = await this.request("get_height_info", {}); return height; } async farmBlock(address) { return this.request("farm_block", { address }); } async getWallets() { const { wallets } = await this.request("get_wallets", {}); return wallets; } async getWalletBalance(walletId) { const { wallet_balance } = await this.request("get_wallet_balance", { wallet_id: walletId }); return wallet_balance; } async getTransaction(walletId, transactionId) { const { transaction } = await this.request("get_transaction", { wallet_id: walletId, transaction_id: transactionId, }); return transaction; } async getTransactionV2(walletId, transactionId) { return await this.request("get_transaction", { wallet_id: walletId, transaction_id: transactionId, }); } async getTransactions(walletId, start, end) { const { transactions } = await this.request("get_transactions", { wallet_id: walletId, start: start, end: end }); return transactions; } async getNextAddress(walletId) { const { address } = await this.request("get_next_address", { wallet_id: walletId, new_address: true }); return address; } async sendTransaction(walletId, amount, address, fee) { const { transaction } = await this.request("send_transaction", { wallet_id: walletId, amount, address, fee, }); return transaction; } async sendTransactionV2(walletId, amount, address, fee) { return await this.request("send_transaction", { wallet_id: walletId, amount, address, fee, }); } async sendTransactionMultiV2(walletId, additions, fee) { return await this.request("send_transaction_multi", { wallet_id: walletId, additions: additions, fee, }); } async createBackup(filePath) { return this.request("create_backup", { file_path: filePath }); } /* https://github.com/CMEONE/chia-utils */ addressToPuzzleHash(address) { return chia_utils_1.address_to_puzzle_hash(address); } puzzleHashToAddress(puzzleHash) { return chia_utils_1.puzzle_hash_to_address(puzzleHash); } getCoinInfo(parentCoinInfo, puzzleHash, amount) { return chia_utils_1.get_coin_info(parentCoinInfo, puzzleHash, amount / 1000000000000); } } exports.Wallet = Wallet; //# sourceMappingURL=Wallet.js.map