Skip to content

Keys & Crypto

Keys

PubKey

Construction Examples:

  • xpub661MyMwAqRbcFvXwqbgwigDczeocqeBEibKMCkoc31RiyB464Ybc1z8sWMnR38JdeCBJPPkSM7mKahcBX2nPX9KYVTz3cotpLmSkMxrp99L
  • pubkey(03b2123025f45648c3f31fd4b7d3e1ec3344769ab3f53dec5af9b8a9a95385cbd5)
  • [0f9e8d7c/3]b2123025f45648c3f31fd4b7d3e1ec3344769ab3f53dec5af9b8a9a95385cbd5

→ See Key Construction and Key Structure for more details.

Variations:

Coerces from:

To fully preserve key origin information, use the str()/repr() encoding instead of Bytes.

Underlying type: miniscript::DescriptorPublicKey

pubkey()

(Not to be confused with pk())

Rust source code: src/stdlib/keys.rs:N/A

identifier Hash opt

The key identifier as defined in BIP 32 (HASH160 of the public key).

Only available for definite keys.

fingerprint Hash opt

The key fingerprint as defined in BIP 32 (first four bytes of the identifier).

Only available for definite keys.

is_xpub Bool

Aliased as: PubKey->is_xkey

is_definite Bool

is_wildcard Bool

Whether this key has an underived /* wildcard modifier.

is_multipath Bool

Whether this is a multi-path key.

is_xonly Bool

Whether this is an X-only key (X-only are always SingleKey).

chain_code Hash opt

The chain code as defined in BIP 32.

Only available for definite Xpub keys.

master_fingerprint Hash

0x00000000 if there's none.

derivation_path Array<Int> opt

The full derivation path from the master_fingerprint.

Only available for single-path keys.

derivation_paths Array<Array<Int>>

For multi-path keys, an array of all expanded derivation paths.

For single-path keys, an array with a single element equal to derivation_path.

SecKey

Construction Examples:

  • xprv9s21ZrQH143K37CBUxq5bSXTyHwKc5KwYWsm6onCYDmiPBBDyiz3bYwvHYH9NXzsY6mDiXmhf77Ym2EJkGreLHB3s6MH5tRkfKQT9uDQ4r2
  • L4oC7AMPJkKPwuVipfFaKcJKBhsR3kmXy89f7oAFhSQSPWLNXocJ (WIF)
  • seckey(e215fcbcb22c3118fb1974b7188922b760b14a24f94d06d5b45d127c278aba77)

→ See Key Construction and Key Structure for more details.

Variations:

Coerces from:

To fully preserve key origin information, use the str()/repr() encoding instead of Bytes.

Underlying type: miniscript::DescriptorSecretKey

seckey()

seckey(Bytes|SecKey) -> SecKey

Rust source code: src/stdlib/keys.rs:N/A

pubkey PubKey

is_xpriv Bool

Aliased as: SecKey->is_xkey

...

With the exception of is_xpub and is_xonly, all of the PubKey fields are available on SecKey too. They are not repeated here for brevity.

seckey::rand()

seckey::rand(network: Network = testnet) -> SecKey<SingleKey>

Generate a random single secret key.

Rust source code: src/stdlib/keys.rs:N/A

xpriv::rand()

xpriv::rand(network: Network = testnet) -> SecKey<Xpriv>

Generate a random Xpriv.

Rust source code: src/stdlib/keys.rs:N/A

xpriv::from_seed()

xpriv::from_seed(seed: Bytes, network: Network = testnet) -> SecKey<Xpriv>

Construct Xpriv from seed.

Rust source code: src/stdlib/keys.rs:N/A

xonly()

Rust source code: src/stdlib/keys.rs:N/A

singles()

Rust source code: src/stdlib/keys.rs:N/A

derived()

Rust source code: src/stdlib/keys.rs:N/A

xderived()

Rust source code: src/stdlib/keys.rs:N/A

xNUMS()

xNUMS(seed: Bytes, version: Bytes = BIP32_MAIN) -> PubKey<Xpub>

Derive a unique, deterministic, provably unspendable Xpub based on the given seed. Unlike NUMS, outside observers cannot tell its unspendable without access to the seed.

Minsc source code: src/stdlib/btc.minsc:N/A

NUMS PubKey<SingleKey>

NUMS = 0x50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0

The provably unspendable NUMS key suggested in BIP 341 for use as a Taproot internal key.

BIP32_MAIN Bytes

BIP32_MAIN = 0x0488b21e

BIP32_TEST Bytes

BIP32_TEST = 0x043587cf

Hashing

hash::sha256()

hash::sha256(Bytes) -> Hash

Rust source code: src/stdlib/crypto.rs:N/A

hash::sha256d()

hash::sha256d(Bytes) -> Hash

Rust source code: src/stdlib/crypto.rs:N/A

hash::ripemd160()

hash::ripemd160(Bytes) -> Hash

Rust source code: src/stdlib/crypto.rs:N/A

hash::hash160()

hash::hash160(Bytes) -> Hash

Rust source code: src/stdlib/crypto.rs:N/A

Hash

Signing

ecdsa::sign()

ecdsa::sign(sk: SecKey, msg: Hash, compact_sig: Bool = false) -> Bytes

Rust source code: src/stdlib/crypto.rs:N/A

ecdsa::verify()

ecdsa::verify(pk: PubKey, msg: Hash, signature: Bytes) -> Bool

Rust source code: src/stdlib/crypto.rs:N/A

schnorr::sign()

schnorr::sign(sk: SecKey, msg: Hash, aux_rand: Bool = false) -> Bytes

Rust source code: src/stdlib/crypto.rs:N/A

schnorr::verify()

schnorr::verify(pk: PubKey, msg: Hash, signature: Bytes) -> Bool

Rust source code: src/stdlib/crypto.rs:N/A

RNG

Minsc provides a CSPRNG based on the rand crate's default ThreadRng, which uses ChaCha12 with OS RNG seeding. See its Security section for more details.

Deterministic randomness based on an explicit seed is supported by providing the seed parameter. The seed can be any Bytes sequence (or Bytes-coercible, including Strings and Numbers), and will be hashed using SHA256 to seed ChaCha12.

When used without a seed, the RNG is the only possible source of non-determinism in Minsc.

rand::bytes()

rand::bytes(size: Int, seed: Bytes = None) -> Bytes

Rust source code: src/stdlib/crypto.rs:N/A

rand::i64()

rand::i64(seed: Bytes = None) -> Int

Rust source code: src/stdlib/crypto.rs:N/A

rand::f64()

rand::f64(seed: Bytes = None) -> Float

Rust source code: src/stdlib/crypto.rs:N/A

rand::u32()

rand::u32(seed: Bytes = None) -> Int

Minsc source code: src/stdlib/stdlib.minsc:N/A

rand::i32()

rand::i32(seed: Bytes = None) -> Int

Minsc source code: src/stdlib/stdlib.minsc:N/A

rand::range()

rand::range(start: Int, end: Int, seed: Bytes = None) -> Int

Minsc source code: src/stdlib/stdlib.minsc:N/A

rand::frange()

rand::frange(start: Float, end: Float, seed: Bytes = None) -> Float

Minsc source code: src/stdlib/stdlib.minsc:N/A