scure-btc-signer
scure-btc-signer copied to clipboard
Feature: return hash in P2Ret for hash based payments
It would be helpful to have original hash included in returned P2Ret for hash based payments: p2sh, p2pkh, p2wsh, p2wpkh.
type P2Ret = {
type: string;
script: Bytes;
address?: string;
// for p2sh, p2pkh, p2wsh, p2wpkh
hash?: Bytes,
redeemScript?: Bytes;
witnessScript?: Bytes;
};
Could you show an example code describing how returning hash could help?
For internal usage and some kind of tests it can be useful. For example to match that p2pkh and p2wpkh payments use the same keypair if hashes are the same.
Current solution: parse provided script or address. But there is original hash inside functions so it can be reused when returned.
The reference from bitcoinjs-lib: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/p2pkh.ts#L52-L56
It would be helpful to have hash exposed by p2* to work with CashAddr.
import { Address } from 'cashaddr';
const payment = btc.p2pkh(PubKey);
const address = Address().encode(payment);