Scripts

object Scripts

Created by PM on 02/12/2016.

Functions

applyFees
Link copied to clipboard
common
fun applyFees(amount_us: Satoshi, amount_them: Satoshi, fee: Satoshi): Pair<Satoshi, Satoshi>
cltvTimeout
Link copied to clipboard
common
fun cltvTimeout(tx: Transaction): Long

This function interprets the locktime for the given transaction, and returns the block height before which this tx cannot be published. By convention in bitcoin, depending of the value of locktime it might be a number of blocks or a number of seconds since epoch. This function does not support the case when the locktime is a number of seconds that is not way in the past. NB: We use this property in lightning to store data in this field.

csvTimeout
Link copied to clipboard
common
fun csvTimeout(tx: Transaction): Long
der
Link copied to clipboard
common
fun der(sig: ByteVector64, sigHash: Int): ByteVector
encodeNumber
Link copied to clipboard
common
fun encodeNumber(n: Long): ScriptElt

minimal encoding of a number into a script element:

extractPaymentHashFromClaimHtlcTimeout
Link copied to clipboard
common
fun extractPaymentHashFromClaimHtlcTimeout(): (ScriptWitness) -> ByteVector?

Extract the payment hash from a timed-out received htlc.

extractPaymentHashFromHtlcTimeout
Link copied to clipboard
common
fun extractPaymentHashFromHtlcTimeout(): (ScriptWitness) -> ByteVector?

Extract the payment hash from a 2nd-stage HTLC Timeout transaction's witness script

extractPreimageFromClaimHtlcSuccess
Link copied to clipboard
common
fun extractPreimageFromClaimHtlcSuccess(): (ScriptWitness) -> ByteVector32?

Extract the payment preimage from from a fulfilled offered htlc.

extractPreimageFromHtlcSuccess
Link copied to clipboard
common
fun extractPreimageFromHtlcSuccess(): (ScriptWitness) -> ByteVector32?

Extract the payment preimage from a 2nd-stage HTLC Success transaction's witness script

htlcOffered
Link copied to clipboard
common
fun htlcOffered(localHtlcPubkey: PublicKey, remoteHtlcPubkey: PublicKey, revocationPubKey: PublicKey, paymentHash: ByteArray): List<ScriptElt>
htlcReceived
Link copied to clipboard
common
fun htlcReceived(localHtlcPubkey: PublicKey, remoteHtlcPubkey: PublicKey, revocationPubKey: PublicKey, paymentHash: ByteArray, lockTime: CltvExpiry): List<ScriptElt>
multiSig2of2
Link copied to clipboard
common
fun multiSig2of2(pubkey1: PublicKey, pubkey2: PublicKey): List<ScriptElt>
toAnchor
Link copied to clipboard
common
fun toAnchor(fundingPubkey: PublicKey): List<ScriptElt>
toLocalDelayed
Link copied to clipboard
common
fun toLocalDelayed(revocationPubkey: PublicKey, toSelfDelay: CltvExpiryDelta, localDelayedPaymentPubkey: PublicKey): List<ScriptElt>
toRemoteDelayed
Link copied to clipboard
common
fun toRemoteDelayed(pub: PublicKey): List<ScriptElt>
witness2of2
Link copied to clipboard
common
fun witness2of2(sig1: ByteVector64, sig2: ByteVector64, pubkey1: PublicKey, pubkey2: PublicKey): ScriptWitness
witnessClaimHtlcSuccessFromCommitTx
Link copied to clipboard
common
fun witnessClaimHtlcSuccessFromCommitTx(localSig: ByteVector64, paymentPreimage: ByteVector32, htlcOffered: ByteVector): ScriptWitness

If remote publishes its commit tx where there was a remote->local htlc, then local uses this script to claim its funds using a payment preimage (consumes htlcOffered script from commit tx)

witnessClaimHtlcTimeoutFromCommitTx
Link copied to clipboard
common
fun witnessClaimHtlcTimeoutFromCommitTx(localSig: ByteVector64, htlcReceivedScript: ByteVector): ScriptWitness

If remote publishes its commit tx where there was a local->remote htlc, then local uses this script to claim its funds after timeout (consumes htlcReceived script from commit tx)

witnessHtlcSuccess
Link copied to clipboard
common
fun witnessHtlcSuccess(localSig: ByteVector64, remoteSig: ByteVector64, paymentPreimage: ByteVector32, htlcOfferedScript: ByteVector): ScriptWitness

This is the witness script of the 2nd-stage HTLC Success transaction (consumes htlcOffered script from commit tx) local signature is created with SIGHASH_ALL flag remote signature is created with SIGHASH_SINGLE || SIGHASH_ANYONECANPAY

witnessHtlcTimeout
Link copied to clipboard
common
fun witnessHtlcTimeout(localSig: ByteVector64, remoteSig: ByteVector64, htlcOfferedScript: ByteVector): ScriptWitness

This is the witness script of the 2nd-stage HTLC Timeout transaction (consumes htlcOffered script from commit tx) local signature is created with SIGHASH_ALL remote signature is created with SIGHASH_SINGLE || SIGHASH_ANYONECANPAY

witnessHtlcWithRevocationSig
Link copied to clipboard
common
fun witnessHtlcWithRevocationSig(revocationSig: ByteVector64, revocationPubkey: PublicKey, htlcScript: ByteVector): ScriptWitness

This witness script spends (steals) a [htlcOffered] or [htlcReceived] output using a revocation key as a punishment for having published a revoked transaction

witnessToLocalDelayedAfterDelay
Link copied to clipboard
common
fun witnessToLocalDelayedAfterDelay(localSig: ByteVector64, toLocalDelayedScript: ByteVector): ScriptWitness

This witness script spends a [toLocalDelayed] output using a local sig after a delay

witnessToLocalDelayedWithRevocationSig
Link copied to clipboard
common
fun witnessToLocalDelayedWithRevocationSig(revocationSig: ByteVector64, toLocalScript: ByteVector): ScriptWitness

This witness script spends (steals) a [toLocalDelayed] output using a revocation key as a punishment for having published a revoked transaction

witnessToRemoteDelayedAfterDelay
Link copied to clipboard
common
fun witnessToRemoteDelayedAfterDelay(localSig: ByteVector64, toRemoteDelayedScript: ByteVector): ScriptWitness

This witness script spends a [toLocalDelayed] output using a local sig after a delay