app-bitcoin-new icon indicating copy to clipboard operation
app-bitcoin-new copied to clipboard

Compare generated taproot addresses with the expected ones in the JS client library

Open bigspider opened this issue 2 years ago • 6 comments

#166 solved this for the Python and Rust clients; still to do for the JS client.

bigspider avatar Jun 14 '23 11:06 bigspider

For Javascript, you can use https://bitcoinerlab.com/modules/descriptors Let me know if you need some assistance. I'm happy to help.

landabaso avatar Jul 12 '23 06:07 landabaso

For Javascript, you can use https://bitcoinerlab.com/modules/descriptors Let me know if you need some assistance. I'm happy to help.

Thanks! Last time I checked, there was a circular dependency, as that module directly imported ledger-bitcoin for the hardware integration. Perhaps, if the hardware wallet integration part is moved to a separate module, that would be feasible.

Would that work for taproot scripts, as well?

bigspider avatar Jul 12 '23 07:07 bigspider

Ah, I see your point regarding the circular dependency. To resolve this, I could attempt to decouple the hardware wallet integration as you say. Alternatively, it might be worth considering importing ledger-bitcoin as a peerDependency in bitcoinerlab. I'll explore both approaches and get back to you with an update.

As for your question about taproot scripts, the current version does not support it. I haven't started incorporating taproot functionality as of yet. Is this a necessary requirement?

landabaso avatar Jul 12 '23 07:07 landabaso

I'm having trouble reproducing the circular dependency issue you mentioned. I suspect that my assumptions about the workflow might be different from what you're actually trying to do.

From my understanding, you're intending to add tests using a third-party library. This library would compute addresses for a descriptor, which you would then compare with the results from the Ledger client, correct?

Here are the steps I took for a quick test, based on my understanding:

cd bitcoin_client_js/
npm install --save-dev @bitcoinerlab/secp256k1
npm install --save-dev @bitcoinerlab/descriptors

Then I created a test in src/__tests__/bitcoinerlab.ts:

import * as secp256k1 from '@bitcoinerlab/secp256k1';
import * as descriptors from '@bitcoinerlab/descriptors';
const { Descriptor } = descriptors.DescriptorsFactory(secp256k1);

describe('BitcoinerLab Quick Experiment', () => {
  const descriptor = new Descriptor({
    expression:
      'wpkh(02f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9)'
  });
  const address = descriptor.getAddress();
  it('same address', () => {
    expect('bc1q0ht9tyks4vh7p5p904t340cr9nvahy7u3re7zg').toEqual(address);
  });
});

Running the test with npm run test src/__tests__/bitcoinerlab.ts worked without issues, and I was also able to build the project successfully.

~~EDIT: I just had a thought - could the issue be arising due to differences in npm versions? For reference, I conducted my test using npm v17.9.1.~~

EDIT2: After further inspection of the PR referenced in this issue, I now understand the context better. It appears you're aiming to conduct runtime tests, not offline ones, which means this would not be a devDependency. I'll revisit the idea of either decoupling the packages or using it as a peerDependency.

landabaso avatar Jul 12 '23 08:07 landabaso

Solved for Segwit in #189, still to do for Taproot Scripts.

bigspider avatar Jul 28 '23 09:07 bigspider

Solved for the python client (all address types) in #227.

bigspider avatar Feb 15 '24 12:02 bigspider