Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mahnunchik opened this issue Feb 18, 2023 · 3 comments
Open

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

mahnunchik opened this issue Feb 18, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@mahnunchik
Copy link
Contributor

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
Copy link
Owner

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

@mahnunchik
Copy link
Contributor Author

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

@paulmillr paulmillr added the enhancement New feature or request label Jul 11, 2023
@mahnunchik
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants