mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 18:00:17 +01:00
24 lines
693 B
JavaScript
24 lines
693 B
JavaScript
import { SegwitBech32Wallet } from './segwit-bech32-wallet';
|
|
const bitcoin = require('bitcoinjs-lib');
|
|
|
|
export class TaprootWallet extends SegwitBech32Wallet {
|
|
static type = 'taproot';
|
|
static typeReadable = 'P2 TR';
|
|
static segwitType = 'p2wpkh';
|
|
|
|
/**
|
|
* Converts script pub key to a Taproot address if it can. Returns FALSE if it cant.
|
|
*
|
|
* @param scriptPubKey
|
|
* @returns {boolean|string} Either bech32 address or false
|
|
*/
|
|
static scriptPubKeyToAddress(scriptPubKey) {
|
|
try {
|
|
const publicKey = Buffer.from(scriptPubKey, 'hex');
|
|
return bitcoin.address.fromOutputScript(publicKey, bitcoin.networks.bitcoin);
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|