Keys & Crypto API Reference¶
Keys¶
PubKey
¶
Construction Examples:
xpub661MyMwAqRbcFvXwqbgwigDczeocqeBEibKMCkoc31RiyB464Ybc1z8sWMnR38JdeCBJPPkSM7mKahcBX2nPX9KYVTz3cotpLmSkMxrp99Lpubkey(03b2123025f45648c3f31fd4b7d3e1ec3344769ab3f53dec5af9b8a9a95385cbd5)[0f9e8d7c/3]b2123025f45648c3f31fd4b7d3e1ec3344769ab3f53dec5af9b8a9a95385cbd5
→ See Key Construction and Key Structure for more details.
PubKey<SingleKey>|PubKey<Xpub>PubKey<SinglePath>|PubKey<MultiPath>PubKey<Definite>|PubKey<Indefinite>
Coerces from:
SecKey– converted into a public key (key origin preserved)Bytes<33>– single public key (with no key origin, always compressed)Bytes<32>– single x-only public key (with no key origin)Bytes<78>–Xpubencoded using the BIP32 serialization format (only the immediate parent origin is known)
To fully preserve key origin information, use the
str()/repr()encoding instead of Bytes.
Underlying type: miniscript::DescriptorPublicKey
(Not to be confused with pk())
Rust source code: src/stdlib/keys.rs:91
The key identifier as defined in
BIP 32
(HASH160 of the public key).
The key fingerprint as defined in BIP 32
(first four bytes of the identifier).
Aliased as: PubKey->is_xkey
Whether this key has an underived /* wildcard modifier.
Whether this is a multi-path key.
Whether this is an X-only key (X-only are always SingleKey).
0x00000000 if there's none.
The full derivation path from the master_fingerprint.
Only available for single-path keys.
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.
The chain code as defined in BIP 32.
Only available for definite Xpub keys.
SecKey
¶
Construction Examples:
xprv9s21ZrQH143K37CBUxq5bSXTyHwKc5KwYWsm6onCYDmiPBBDyiz3bYwvHYH9NXzsY6mDiXmhf77Ym2EJkGreLHB3s6MH5tRkfKQT9uDQ4r2L4oC7AMPJkKPwuVipfFaKcJKBhsR3kmXy89f7oAFhSQSPWLNXocJ(WIF)seckey(e215fcbcb22c3118fb1974b7188922b760b14a24f94d06d5b45d127c278aba77)
→ See Key Construction and Key Structure for more details.
SecKey<SingleKey>|SecKey<Xpriv>SecKey<SinglePath>|SecKey<MultiPath>SecKey<Definite>|SecKey<Indefinite>
Coerces from:
Bytes<32>– single secret key (with no key origin)Bytes<78>–Xprivencoded using the BIP32 serialization format (only the immediate parent origin is known)
To fully preserve key origin information, use the
str()/repr()encoding instead of Bytes.
Underlying type: miniscript::DescriptorSecretKey
Rust source code: src/stdlib/keys.rs:96
Aliased as: SecKey->is_xkey
SecKey->...
¶
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.
Generate a random single secret key.
Rust source code: src/stdlib/keys.rs:102
Generate a random Xpriv.
Rust source code: src/stdlib/keys.rs:109
Construct Xpriv from seed bytes.
Rust source code: src/stdlib/keys.rs:117
xpriv::from_mnemonic()
¶
Construct Xpriv from a BIP 39 mnemonic phrase.
Alias for bip39::to_xpriv() and also possible using bip39().
See the BIP 39 reference for more information.
Minsc source code: src/stdlib/bip39.minsc:11
Rust source code: src/stdlib/keys.rs:139
singles()
¶
singles(PubKey<MultiPath>) -> Array<PubKey<SinglePath>>
singles(SecKey<MultiPath>) -> Array<SecKey<SinglePath>>
singles(Descriptor<MultiPath>) -> Array<Descriptor<SinglePath>>
This should also work with
Policy<MultiPath>, but currently doesn't.
Rust source code: src/stdlib/keys.rs:126
derived()
¶
Rust source code: src/stdlib/keys.rs:161
xderived()
¶
Rust source code: src/stdlib/keys.rs:202
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:23
The provably unspendable NUMS key suggested in BIP 341
for use as a Taproot internal key.
KeySource
¶
Hashing¶
Rust source code: src/stdlib/crypto.rs:51
Rust source code: src/stdlib/crypto.rs:54
Rust source code: src/stdlib/crypto.rs:57
Rust source code: src/stdlib/crypto.rs:60
Hash
¶
Signing¶
Rust source code: src/stdlib/crypto.rs:64
Rust source code: src/stdlib/crypto.rs:79
Rust source code: src/stdlib/crypto.rs:86
Rust source code: src/stdlib/crypto.rs:99
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 Ints),
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.
Generate a random Bytes sequence of length size
Rust source code: src/stdlib/crypto.rs:106
Generate a random signed 64-bit integer in the [−2⁶³ , 2⁶³−1] range
Rust source code: src/stdlib/crypto.rs:115
Generate a random 64-bit float in the [0.0 , 1.0) range
Rust source code: src/stdlib/crypto.rs:122
Generate a random unsigned 32-bit integer in the [0 , 2³²−1] range
Minsc source code: src/stdlib/stdlib.minsc:87
Generate a random signed 32-bit integer in the [−2³¹ , 2³¹−1] range
Minsc source code: src/stdlib/stdlib.minsc:88
Generate a random integer in the [min , max] range (min <= N <= max)
Minsc source code: src/stdlib/stdlib.minsc:89
Generate a random float in the [min, max) range (min <= N < max)
Minsc source code: src/stdlib/stdlib.minsc:90