embit/docs/api
2022-06-01 12:58:35 +02:00
..
descriptor add docs layout 2021-08-04 16:30:29 +02:00
ec add bip32 docs 2021-08-20 01:16:14 +02:00
liquid add docs layout 2021-08-04 16:30:29 +02:00
_sidebar.md add docs for ec.PrivateKey 2021-08-14 22:43:26 +02:00
base58.md add more docs, remove bcur module 2021-08-10 15:45:24 +02:00
bech32.md add more docs, remove bcur module 2021-08-10 15:45:24 +02:00
bip32.md add transaction docs 2022-04-24 21:16:16 +02:00
bip39.md add bip39 docs 2021-08-04 19:26:56 +02:00
compact.md add more docs, remove bcur module 2021-08-10 15:45:24 +02:00
hashes.md add more docs, remove bcur module 2021-08-10 15:45:24 +02:00
networks.md add networks docs 2021-08-04 20:04:10 +02:00
psbt.md add docs layout 2021-08-04 16:30:29 +02:00
psbtview.md add docs layout 2021-08-04 16:30:29 +02:00
README.md add transaction docs 2022-04-24 21:16:16 +02:00
script.md add docs layout 2021-08-04 16:30:29 +02:00
slip39.md add docs layout 2021-08-04 16:30:29 +02:00
transaction.md add support for signing with descriptor and descriptor keys 2022-06-01 12:58:35 +02:00

Overview

Basics

Almost all classes have .parse(bytes) and .serialize() functions to create class instances from bytearray and other way around. They can also read from / write to streams like files or ByteIO objects using read_from(stream) and write_to(stream) methods.

The only exception is Descriptor that is purely string-based and doesn't have any binary representation.

For example:

# parsing pubkey from bytes
from embit.ec import PublicKey
from binascii import unhexlify
pub = PublicKey.parse(b"\x02\x01\x8a\x76\x85\x41\xc9\x46...\x85")

# reading raw transaction from file
from embit.transaction import Transaction
with open("raw.tx", "rb") as f:
	tx = Transaction.read_from(f)

# serialize to bytes
sec = pub.serialize()
# write to binary file
with open("raw2.tx", "wb") as f:
	tx.write_to(f)

Some classes also have string representations. If they don't - we assume hex representation. You can use .from_string() and .to_string() methods for that, or just call str(something):

from embit.bip32 import HDKey
from embit.ec import PublicKey, PrivateKey

xpub = HDKey.from_string("xpub6BysnKqL9EKxKwWxrgwU97FBNybxNZKKfGQgqurJy3BYGSJZBk4biPTzJCCMZ5wsqfxskrrUiJYQexJFX7qkA4DYB2DiADY7Fcto4wxLva4")
prv = PrivateKey.from_string("L16MDExY5qQ6ABZCvRRD3v3rXV4R3y2THZu56eFLLnGjhbqX7Gq7")
# hex representation:
pub = PublicKey.from_string("02018a768541c946e907bd6961f403edd820e76cddb40cefb3c5cf3ae47cea6186")

Modules

Library is splitted into modules, list of modules sorted by topic:

Keys:

  • ec - individual elliptic curve keys (PrivateKey, PublicKey) and signatures (Signature, SchnorrSig)
  • bip39 - helper functions for mnemonics
  • bip32 - extended private and public keys (HDKey)

Scripts:

  • script - basic bitcoin scripts (Script) and helper functions
  • descriptor - descriptors (Descriptor) and miniscript functions

Transactions:

  • transaction - raw transactions (Transaction)
  • psbt - psbt transactions (PSBT)
  • psbtview - RAM-optimized pbst transaction for embedded devices, doesn't read the whole transaction to memory but only gets the part you need right now (PSBTView)

Helpers:

  • networks - constants for different Bitcoin networks
  • base58 encoding - used for WIFs and legacy addresses
  • bech32 encoding - used for segwit and taproot addresses
  • compact - often used for serializations
  • hashes - common bitcoin hash functions like tagged_hash, double_sha256 etc

Extensions / experimental:

  • liquid - support for confidential assets, liquid transactions, blinded descriptors and psets (elements version of psbt)
  • slip39 - shamir secret sharing scheme