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 REQUEST] - MerklePath.fromTSC() method #93

Open
sirdeggen opened this issue Jun 17, 2024 · 3 comments
Open

[FEATURE REQUEST] - MerklePath.fromTSC() method #93

sirdeggen opened this issue Jun 17, 2024 · 3 comments

Comments

@sirdeggen
Copy link
Collaborator

Summary

Create MerklePath from TSC standard merkle proof using WoC api.

Motivation

Probably a bunch of apps have stored merkle proofs in TSC format and this gives them an opportunity to use that data quickly in construction of BUMP for use in BEEF transactions for SPV.

Description

It's already implemented elsewhere, this issue is to discuss whether incorporation within the MerklePath module here is something other people want or not.

Additional References

Existing implementation which may be copied in if so desired.

@sirdeggen sirdeggen changed the title [FEATURE REQUEST] [FEATURE REQUEST] - MerklePath.fromTSC() method Jun 17, 2024
@sirdeggen
Copy link
Collaborator Author

I sort of wrote this in beef.ö.network but it requires a lookup so, not really a direct conversion.

async function convertTSCtoBUMP(tsc) {
    const txid = tsc.txOrId
    const header = await woc.getHeader(tsc.target)
    const bump = {}
    bump.blockHeight = header.height
    bump.path = []
    const leafOfInterest = { hash: txid, txid: true, offset: tsc.index }
    tsc.nodes.map((hash, idx) => {
        const offset = tsc.index >> idx ^ 1
        const leaf = { offset }
        if (hash === '*') leaf.duplicate = true
        else leaf.hash = hash
        if (idx === 0) {
            if (tsc.index % 2) bump.path.push([leafOfInterest, leaf])
            else bump.path.push([leaf, leafOfInterest])
        }
        else bump.path.push([leaf])
    })
    const merklePath = new MerklePath(bump.blockHeight, bump.path)
    if (header.merkleroot !== merklePath.computeRoot(txid)) throw new Error('Invalid Merkle Path')
    return merklePath
}

Open to adding this to compat module, but probably assume that you have the full header data to convert rather than looking it up.

@sirdeggen
Copy link
Collaborator Author

Not sure the constructor does the trimming functionality?

@tonesnotes
Copy link
Contributor

It's a good idea. Add an input blockHeight argument and externalize the required lookup. The Babbage wallet proven transaction table schema stores serialized TSC format proof in one column and the height in a second column.

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

No branches or pull requests

2 participants