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

WIP: feat: add pubkeyToPkh and addrToPkh to keyUtils #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

coolaj86
Copy link
Member

@coolaj86 coolaj86 commented Aug 14, 2024

Overview

We have a few conflicting concerns:

To solve this we can do any of:

  • leave more tedium to the developer (current)
  • add new convenience methods to keyUtils (proposed)
  • create a hard dependency on DashKeys (reasonable, but not prefered)

The Cumbersome Code

In particular, going from the tx draft to the tx final + signed requires a bit more ceremony than I'd like:

        let draftTx = dashTx.legacy.draftSingleOutput({ utxos, inputs, output });
        console.log('DEBUG draftTx', draftTx);

        // See https://github.com/dashhive/DashTx.js/pull/77
        for (let input of draftTx.inputs) {
            let addressInfo = keysMap[input.address];
            Object.assign(input, {
                publicKey: addressInfo.publicKey,
                pubKeyHash: addressInfo.pubKeyHash,
            });
        }
        for (let output of draftTx.outputs) {
            if (output.pubKeyHash) {
                continue;
            }
            if (!output.address) {
                throw new Error(`output is missing 'address' and 'pubKeyHash'`);
            }
            let pkhBytes = await DashKeys.addrToPkh(output.address, {
                version: 'mainnet',
            });
            Object.assign(output, {
                pubKeyHash: DashKeys.utils.bytesToHex(pkhBytes),
            });
        }

        draftTx.inputs.sort(DashTx.sortInputs);
        draftTx.outputs.sort(DashTx.sortOutputs);

@coolaj86 coolaj86 changed the title feat: add pubkeyToPkh and addrToPkh to keyUtils WIP: feat: add pubkeyToPkh and addrToPkh to keyUtils Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant