Skip to content

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

Open
coolaj86 wants to merge 1 commit intomainfrom
doc-dashkeys-utils
Open

WIP: feat: add pubkeyToPkh and addrToPkh to keyUtils#77
coolaj86 wants to merge 1 commit intomainfrom
doc-dashkeys-utils

Conversation

@coolaj86
Copy link
Copy Markdown
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