chaingate
Version:
Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO
35 lines (34 loc) • 1.41 kB
JavaScript
;
/**
* Shared utilities for UTXO-family connectors (UtxoConnector, BchConnector).
*
* These functions are extracted to avoid code duplication between connectors
* that share identical logic for private key extraction.
* @internal
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPrivateKeyGetter = createPrivateKeyGetter;
const HDWallet_1 = require("../../Wallet/SigningWallet/HDWallet/HDWallet");
const PrivateKeyWallet_1 = require("../../Wallet/SigningWallet/PrivateKeyWallet/PrivateKeyWallet");
const errors_1 = require("../../errors");
/**
* Creates a function that extracts the private key from the wallet.
* @internal
*/
function createPrivateKeyGetter(wallet, index, derivationPath) {
if (wallet instanceof HDWallet_1.HDWallet) {
const fullPath = `${derivationPath}/${index}`;
return async () => {
const derived = await wallet.derive(fullPath);
return new Uint8Array(derived.privateKey.raw);
};
}
if (wallet instanceof PrivateKeyWallet_1.PrivateKeyWallet) {
return async () => {
const pk = await wallet.getPrivateKey();
return new Uint8Array(pk.raw);
};
}
throw new errors_1.UnsupportedOperationError(`Wallet type '${wallet.walletType}' does not support signing transactions. ` +
`A signing wallet (HD or private key) is required.`);
}