Skip to content

Commit

Permalink
xpub
Browse files Browse the repository at this point in the history
  • Loading branch information
basilesportif authored and ixv committed May 27, 2021
1 parent cbe9d36 commit 26d1830
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 7 additions & 4 deletions lib/btc.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
`@ux`(rash - hex)
++ xpub-type
|= =xpub
^- bipt
^- [=bipt =network]
=/ prefix=tape (scag 4 (trip xpub))
?: =("xpub" prefix) %44
?: =("ypub" prefix) %49
?: =("zpub" prefix) %84
?: =("tpub" prefix) [%44 %testnet]
?: =("upub" prefix) [%49 %testnet]
?: =("vpub" prefix) [%84 %testnet]
?: =("xpub" prefix) [%44 %main]
?: =("ypub" prefix) [%49 %main]
?: =("zpub" prefix) [%84 %main]
~|("invalid xpub: {<xpub>}" !!)
:: big endian sha256: input and output are both MSB first (big endian)
::
Expand Down
13 changes: 12 additions & 1 deletion tests/btc.hoon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/+ *test, *btc
/+ *test, *btc, bip32
|%
+$ xpub-vec [=xpub pubkey=hexb]
+$ pubkey-vec [=bipt =network pubkey=hexb =address]
+$ script-pubkey-vec [=address spk=hexb]
++ vectors
Expand All @@ -11,6 +12,12 @@
:: below use mnemonic:
:: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
::
++ xpubs
^- (list xpub-vec)
:~ :* 'vpub5Y6cjg78GGuNLsaPhmYsiw4gYX3HoQiRBiSwDaBXKUafCt9bNwWQiitDk5VZ5BVxYnQdwoTyXSs2JHRPAgjAvtbBrf8ZhDYe2jWAqvZVnsc'
33^0x2.e7ab.2537.b5d4.9e97.0309.aae0.6e9e.49f3.6ce1.c9fe.bbd4.4ec8.e0d1.cca0.b4f9.c319
==
==
++ pubkeys
^- (list pubkey-vec)
:~ :* %84
Expand Down Expand Up @@ -95,7 +102,11 @@
=((to-atoms:bit 5 bits) atoms)
==
~|("base32 bit manipulation failed" !!)
:: xpubs
::
~& > (from-extended:bip32 (trip 'vpub5baxyhXRwCQ1N4KuQfdVSfnYahk6HDRCqDhQJjgSbxo8SzP5ghgHugxZuQ9TpfGC2oTBYdVi8thxMGhqjcVbNPMBNRKMX9x1PZW4LXNyq7q'))
:: pubkey to address
::
?. %+ levy pubkeys:vectors
|= [=bipt =network pubkey=hexb =address]
=(address (pubkey-to-address bipt network pubkey))
Expand Down

0 comments on commit 26d1830

Please sign in to comment.