Skip to content

Instantly share code, notes, and snippets.

@xhliu
Last active June 27, 2024 22:34
vault_trigger
export class VaultTriggerWithdrawal extends SmartContract {
@method()
public trigger(
shPreimage: SHPreimage,
sig: Sig,
vaultSPK: ByteString,
feeSPK: ByteString,
vaultAmt: ByteString,
feeAmt: ByteString,
targetSPK: ByteString
) {
// Check sig.
assert(this.checkSig(sig, this.withdrawalPubKey))
// Check sighash preimage.
const s = SigHashUtils.checkSHPreimage(shPreimage)
assert(this.checkSig(s, SigHashUtils.Gx))
// Enforce spent scripts.
const hashSpentScripts = sha256(vaultSPK + feeSPK)
assert(hashSpentScripts == shPreimage.hashSpentScripts, 'hashSpentScripts mismatch')
// Enforce spent amounts.
const hashSpentAmounts = sha256(vaultAmt + feeAmt)
assert(hashSpentAmounts == shPreimage.hashSpentAmounts, 'hashSpentAmounts mismatch')
// Enforce outputs.
const dust = toByteString('2202000000000000')
const hashOutputs = sha256(
vaultAmt + vaultSPK +
dust + targetSPK
)
assert(hashOutputs == shPreimage.hashOutputs, 'hashOutputs mismatch')
}
// Default taproot key spend must be disabled!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment