BIP-32
1 Extended Keys
xmeta
xpub
xpriv
2 Serialization
string->xpub
xpub->string
string->xpriv
xpriv->string
3 Key Derivation
CKDpub
CKDpriv
N
4 Derivation Paths
string->path
xpub-derive-path
xpriv-derive-path
8.12

BIP-32🔗ℹ

Marc Burns <marc@kn0x.io>

 (require bip32) package: bip32

Provides a Racket implementation of Bitcoin Improvement Proposal 32.

1 Extended Keys🔗ℹ

struct

(struct xmeta (version
    depth
    parent-fingerprint
    child-index
    chain-code))
  version : bytes?
  depth : byte?
  parent-fingerprint : bytes?
  child-index : exact-nonnegative-integer?
  chain-code : bytes?
Extended public or private key metadata.

struct

(struct xpub (point))

  point : jacobian-point?
Extended public key. Subtype of xmeta.

struct

(struct xpriv (exponent))

  exponent : exact-nonnegative-integer?
Extended private key. Subtype of xmeta.

2 Serialization🔗ℹ

procedure

(string->xpub str)  xpub?

  str : string?
Parses str as an xpub.

procedure

(xpub->string x)  string?

  x : xpub?
Converts an xpub to its string representation.

procedure

(string->xpriv str)  xpriv?

  str : string?
Parses str as an xpriv.

procedure

(xpriv->string x)  string?

  x : xpriv?
Converts an xpriv to its string representation.

3 Key Derivation🔗ℹ

procedure

(CKDpub x i)  xpub?

  x : xpub?
  i : exact-nonnegative-integer?
Derives the ith child of x. Hardened derivations are not possible, so i must be less than 231.

procedure

(CKDpriv x i)  xpriv?

  x : xpriv?
  i : exact-nonnegative-integer?
Derives the ith child of x. When i is less than 231, a non-hardened derivation is performed. Otherwise, a hardened derivation is performed.

An error will be raised if i is equal to or greater than 232.

procedure

(N x)  xpub?

  x : xpriv?
Returns the public key corresponding to x.

4 Derivation Paths🔗ℹ

procedure

(string->path str)  (listof/c exact-nonnegative-integer?)

  str : string?
Parses the path string str.

procedure

(xpub-derive-path root path)  xpub?

  root : xpub?
  path : (listof/c exact-nonnegative-integer?)
Folds CKDpub over the elements of path with initial xpub root.

procedure

(xpriv-derive-path root path)  xpriv?

  root : xpriv?
  path : (listof/c exact-nonnegative-integer?)
Folds CKDpriv over the elements of path with initial xpriv root.