Skip to main content

Multisig

Struct Multisig 

Source
pub struct Multisig {
    pub threshold: u8,
}
Expand description

Multisig (M-of-N) script template.

Creates scripts that require M signatures from a set of N public keys. The threshold M is stored in the template; the public keys are provided when creating the locking script.

§Signature Order

Signatures in the unlocking script must appear in the same order as their corresponding public keys in the locking script. The OP_CHECKMULTISIG opcode walks through keys and signatures in order, matching each signature to the next available key.

Fields§

§threshold: u8

M — the number of required signatures.

Implementations§

Source§

impl Multisig

Source

pub fn new(threshold: u8) -> Self

Creates a new Multisig template with the given threshold.

§Arguments
  • threshold - The number of signatures required (M). Must be 1-16.
Source

pub fn lock_from_keys(&self, pubkeys: &[PublicKey]) -> Result<LockingScript>

Creates a multisig locking script from public keys.

This is the recommended API. Keys are encoded in compressed form (33 bytes).

§Arguments
  • pubkeys - The N public keys. Must have 1-16 keys, and threshold <= N.
Source

pub fn unlock( signers: &[PrivateKey], sign_outputs: SignOutputs, anyone_can_pay: bool, ) -> ScriptTemplateUnlock

Creates an unlock template for spending a multisig output.

§Arguments
  • signers - The M private keys to sign with. Must be in the same order as their corresponding public keys appear in the locking script.
  • sign_outputs - Which outputs to sign.
  • anyone_can_pay - Whether to allow other inputs to be added.
Source

pub fn sign_with_sighash( signers: &[PrivateKey], sighash: &[u8; 32], sign_outputs: SignOutputs, anyone_can_pay: bool, ) -> Result<UnlockingScript>

Signs with a precomputed sighash.

§Arguments
  • signers - The M private keys to sign with (in pubkey order).
  • sighash - The precomputed sighash to sign.
  • sign_outputs - Which outputs to sign (for the scope byte).
  • anyone_can_pay - Whether to allow other inputs to be added.

Trait Implementations§

Source§

impl Clone for Multisig

Source§

fn clone(&self) -> Multisig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Multisig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ScriptTemplate for Multisig

Source§

fn lock(&self, params: &[u8]) -> Result<LockingScript>

Creates a multisig locking script from concatenated 33-byte compressed public keys.

The params slice must be a multiple of 33 bytes (each key is 33 bytes compressed).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V