I wrote the next operate to construct and signal Taproot (P2TR) transactions utilizing @cmdcode/tapscript. My intention is to help each key-path and script-path spends, and optionally each collectively.
The issue is that it doesn’t work as anticipated:
Script-path spends usually fail to validate (e.g., management block errors, invalid witness, or failed script execution).
Can somebody overview my code and level out what’s mistaken with my logic or implementation?
I’d particularly respect recommendation on find out how to repair script-path failures and any efficiency enhancements for the key-path case.
import { Handle, Signer, Faucet, Tx } from '@cmdcode/tapscript';
protected buildTaprootTx(
senderKey: { publicKey: Uint8Array; privateKey: Uint8Array },
utxos: Array<{ txid: string; vout: quantity; worth: quantity }>,
recipient: string,
amountSat: quantity,
feeSat: quantity,
mode: 'key' | 'script' | 'each',
scriptLeaves: Array = [],
opReturnData?: Uint8Array | string,
changeAddr?: string
): string {
// ... (full code as in my gist, see hyperlink beneath)
}
Questions:
What am I doing mistaken, particularly concerning script-path spending?
Is there a greater strategy to construction or optimize the operate for
efficiency and correctness?In case you spot any apparent bugs or misunderstandings in how I take advantage of
Taproot key/script path logic, please level them out.
Any code overview, recommendations, or working instance references are extremely appreciated. Thanks!
I wrote the next operate to construct and signal Taproot (P2TR) transactions utilizing @cmdcode/tapscript. My intention is to help each key-path and script-path spends, and optionally each collectively.
The issue is that it doesn’t work as anticipated:
Script-path spends usually fail to validate (e.g., management block errors, invalid witness, or failed script execution).
Can somebody overview my code and level out what’s mistaken with my logic or implementation?
I’d particularly respect recommendation on find out how to repair script-path failures and any efficiency enhancements for the key-path case.
import { Handle, Signer, Faucet, Tx } from '@cmdcode/tapscript';
protected buildTaprootTx(
senderKey: { publicKey: Uint8Array; privateKey: Uint8Array },
utxos: Array<{ txid: string; vout: quantity; worth: quantity }>,
recipient: string,
amountSat: quantity,
feeSat: quantity,
mode: 'key' | 'script' | 'each',
scriptLeaves: Array = [],
opReturnData?: Uint8Array | string,
changeAddr?: string
): string {
// ... (full code as in my gist, see hyperlink beneath)
}
Questions:
What am I doing mistaken, particularly concerning script-path spending?
Is there a greater strategy to construction or optimize the operate for
efficiency and correctness?In case you spot any apparent bugs or misunderstandings in how I take advantage of
Taproot key/script path logic, please level them out.
Any code overview, recommendations, or working instance references are extremely appreciated. Thanks!