/vault_trigger.ts Secret
Last active
June 27, 2024 22:34
vault_trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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