UNPKG

@btc-vision/transaction

Version:

OPNet transaction library allows you to create and sign transactions for the OPNet network.

25 lines (24 loc) 839 B
import bitcoin, { networks, opcodes, script } from '@btc-vision/bitcoin'; export class TimeLockGenerator { static generateTimeLockAddress(publicKey, network = networks.bitcoin, csvBlocks = TimeLockGenerator.CSV_BLOCKS) { const witnessScript = script.compile([ script.number.encode(csvBlocks), opcodes.OP_CHECKSEQUENCEVERIFY, opcodes.OP_DROP, publicKey, opcodes.OP_CHECKSIG, ]); const p2wsh = bitcoin.payments.p2wsh({ redeem: { output: witnessScript }, network, }); if (!p2wsh.address) { throw new Error('Failed to generate P2WSH address'); } return { address: p2wsh.address, witnessScript: witnessScript, }; } } TimeLockGenerator.CSV_BLOCKS = 75;