paulmillr / scure-btc-signer

Audited & minimal library for creating, signing & decoding Bitcoin transactions.
https://paulmillr.com/noble/#scure
MIT License
151 stars 39 forks source link

Feature: return hash in P2Ret for hash based payments #20

Open mahnunchik opened 1 year ago

mahnunchik commented 1 year ago

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;
};
paulmillr commented 1 year ago

Could you show an example code describing how returning hash could help?

mahnunchik commented 1 year ago

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

mahnunchik commented 9 months ago

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);