mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 20:47:27 +03:00
parse xpub to unit
This commit is contained in:
parent
ca760c2a61
commit
ded87398de
@ -2,20 +2,14 @@
|
||||
## base58
|
||||
Converts a base58 zpub to hex
|
||||
```
|
||||
=zpub-atom (de-base58:mimes:html "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs")
|
||||
=zpub-bytes (turn (flop (rip 3 zpub-atom)) |=(a=@ `@ux`a))
|
||||
|
||||
+bip84 "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
|
||||
```
|
||||
|
||||
### btc-address
|
||||
Test xpub parsing
|
||||
```
|
||||
=btca -build-file %/lib/btc-address.hoon
|
||||
=btca -build-file %/lib/btc-address/hoon
|
||||
=px (parse-xpub:btca "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs")
|
||||
=pubk ?~ pp ~ pubk.u.pp
|
||||
(is-point:btca pubk)
|
||||
```
|
||||
|
||||
### decoded hex from base58
|
||||
Get the public key (start at 45 and take 33 bytes):
|
||||
```
|
||||
=as-atom (rap 3 (flop (swag [45 33] zpub-bytes)))
|
||||
```
|
||||
decompress-point:secp256k1:secp:crypto
|
||||
|
@ -2,6 +2,6 @@
|
||||
:- %say
|
||||
|= [[now=@da eny=@uvJ bec=beak] [zpub=tape ~] ~]
|
||||
:- %noun
|
||||
=/ bs=[(list @ux) (list @ux)]
|
||||
=/ pp=(unit parsed-xpub:btca)
|
||||
(parse-zpub:btca zpub)
|
||||
bs
|
||||
pp
|
||||
|
@ -1,36 +1,45 @@
|
||||
|%
|
||||
:: bytes rip: 0x6261 -> ~[98 97]
|
||||
:: b[ytes]rip: 0x6261 -> ~[98 97]
|
||||
::
|
||||
+$ pubkey (list @ux)
|
||||
+$ chaincode (list @ux)
|
||||
+$ parsed-xpub [cc=chaincode pubk=pubkey]
|
||||
++ big-endian-brip
|
||||
|= a=@ux
|
||||
^- (list @ux)
|
||||
(flop (rip 3 a))
|
||||
:: bytes rap: ~[98 97] -> 0x6261
|
||||
:: b[ytes]rap: ~[98 97] -> 0x6261
|
||||
::
|
||||
++ big-endian-brap
|
||||
|= bytes=(list @ux)
|
||||
^- @ux
|
||||
(swp 3 (rap 3 bytes))
|
||||
::
|
||||
++ parse-zpub
|
||||
|= zpub=tape
|
||||
^- [cc=chaincode pubk=pubkey]
|
||||
=/ as-atom=@ux
|
||||
(de-base58:mimes:html zpub)
|
||||
=/ bytes=(list @ux)
|
||||
(big-endian-brip as-atom)
|
||||
[(swag [13 32] bytes) (swag [45 33] bytes)]
|
||||
::
|
||||
++ pubkey-to-point
|
||||
|= pubkey-bytes=pubkey
|
||||
|= =pubkey
|
||||
^- pont:secp:crypto
|
||||
=/ as-atom=@
|
||||
(rap 3 (flop (swag [45 33] pubkey-bytes)))
|
||||
(decompress-point:secp256k1:secp:crypto as-atom)
|
||||
~& (lent pubkey)
|
||||
%- decompress-point:secp256k1:secp:crypto
|
||||
(big-endian-brap pubkey)
|
||||
::
|
||||
++ is-point
|
||||
|= pubkey=pubkey ^- ?
|
||||
|= =pubkey ^- ?
|
||||
-:(mule |.((pubkey-to-point pubkey)))
|
||||
::
|
||||
++ parse-xpub
|
||||
|= xpub=tape
|
||||
^- (unit parsed-xpub)
|
||||
=/ as-atom=@ux
|
||||
(de-base58:mimes:html xpub)
|
||||
=/ bytes=(list @ux)
|
||||
(big-endian-brip as-atom)
|
||||
=/ pp=parsed-xpub
|
||||
[(swag [13 32] bytes) (swag [45 33] bytes)]
|
||||
?: (is-point pubk.pp)
|
||||
`pp
|
||||
~
|
||||
::
|
||||
++ compute-i
|
||||
|= pp=parsed-xpub
|
||||
%.y
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user