Expand description
§Stackmate
A set of composite functions that uses rust-bitcoin & bdk and exposes a simplified C interface to build descriptor based wallets.
§Workflow
- Use key functions generate_master/import_master and derive a parent key at a hardened path with a variable account number. Currently purpose is fixed at 84’ for Native-native only.
- Use extended key format to create string policies. More on policies.
- Use the compile function to get a general descriptor (keys ending in /*).
- Use wallet functions by passing your descriptor and node_address as primary inputss.
- Electrum over ssl is the recommended way to interact with the wallet with format of ‘ssl://electrum.blockstream.info:60002’.
- “default” can be used as a string for the node_address which will use Blockstream servers. Recommened client to use tor with this setting.
- Bitcoin-core RPC is supported but not advised unless on desktop where a node is connected to locally.
- Core RPC (currently) requies node_address to follow the format of ‘https://address:port?auth=username:password’.
- Outputs of each function are JSON stringified native structs specified as ‘FFI Outputs’ in under module documentation.
- Use every function in combination with cstring_free to free their output pointers. This will keep things safe.
§Building a transaction
- Build a transaction with a default fixed fee of 1000 sats
- Get weight of the transaction for a given descriptor
- Use get absolute fee to get the fee needed to be paid for the transaction given variable fee rate and fixed weight.
- Build transaction with the absolute fee chosen, sign & broadcast.
§Tor controls are in BETA. Use with caution.
Modules§
Functions§
- broadcast_
tx ⚠ - Broadcasts a signed transaction to a remote node.
- build_
tx ⚠ - Builds a transaction for a given descriptor wallet. Supports sending to multiple outputs. TxOutputs have to be provided as a stringified JSON array.
- check_
xpub ⚠ - Checks if an extended public key is valid. Do not use the key source while checking an xpub i.e. remove [fingerprint/derivation/path/values] and only provide the xpub/tpub.
- compile⚠
- Compiles a policy into a descriptor of the specified script type. Use wpkh for a single signature Native native wallet (default). Use wsh for a scripted Native native wallet.
- cstring_
free ⚠ - After using any other function, pass the output pointer into cstring_free(ptr: *mut c_char) to clear memory. ALWAYS use this in combination with any other function. Failure to do so can lead to memory bugs.
- days_
to_ ⚠blocks - Convert days to bitcoin blocks as height. Does not consider the current block height. Add to get_height to get the expected block height after the given time in days.
- decode_
psbt ⚠ - Decodes a PSBT and returns all outputs of the transaction and total size. “miner” is used in the ‘to’ field of an output to indicate fee.
- derive_
to_ ⚠path - Derives child keys from a master xprv. Allows passing a custom derivation path string.
- derive_
wallet_ ⚠account - Derives hardened child keys from a master xprv. Follows the BIP32 standard of m/purpose’/network’/account’. Network path is inferred from the master xprv.
- estimate_
network_ ⚠fee - Gets the current network fee (in sats/vbyte) for a given confirmation target.
- fee_
absolute_ ⚠to_ rate - Converts a given absolute_fee (in sats) to fee rate (in sats/vbyte); given some transaction weight.
- fee_
rate_ ⚠to_ absolute - Converts a given fee_rate (in sats/vbyte) to absolute fee (in sats); given some transaction weight.
- generate_
master ⚠ - Generates a mnemonic phrase of a given length. Defaults to 24 words. A master xprv is created from the mnemonic and passphrase.
- get_
address ⚠ - Gets a new address for a descriptor wallet at a given index. Client must keep track of address indexes and ENSURE prevention of address reuse.
- get_
height ⚠ - Gets the current block height.
- get_
weight ⚠ - Gets the weight of a transaction built with a given descriptor.
- import_
master ⚠ - Creates a master xprv given a mnemonic and passphrase.
- policy_
id ⚠ - Gets the policy id from a given descriptor.
- shared_
secret ⚠ - Computes a Diffie Hellman shared secret
- sign_
message ⚠ - Signs a message using schnorr signature scheme
- sign_tx⚠
- Signs a PSBT with a descriptor. Can only be used with descriptors containing private key(s).
- sync_
balance ⚠ - Syncs to a remote node and fetches balance of a descriptor wallet.
- sync_
history ⚠ - Syncs to a remote node and fetches history of a descriptor wallet.
- tor_
progress ⚠ - Get bootstrap progress from tor daemon. Wait ~1s after calling tor_start() before calling this. BETA: Careful with this.
- tor_
start ⚠ - Switch on tor daemon. BETA: Careful with this.
- tor_
stop ⚠ - Shutdown tor daemon. BETA: Careful with this.
- verify_
signature ⚠ - Signs a message using schnorr signature scheme Private key extracted from extended private key.
- xprv_
to_ ⚠ec - Converts an xprv into EC keys with XOnlyPub..