consolidate into lib

This commit is contained in:
timlucmiptev 2020-09-30 09:40:26 +03:00 committed by ixv
parent ce2ce2f586
commit ca760c2a61
5 changed files with 45 additions and 25 deletions

View File

@ -8,6 +8,11 @@ Converts a base58 zpub to hex
+bip84 "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs" +bip84 "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
``` ```
### btc-address
```
=btca -build-file %/lib/btc-address.hoon
```
### decoded hex from base58 ### decoded hex from base58
Get the public key (start at 45 and take 33 bytes): Get the public key (start at 45 and take 33 bytes):
``` ```

View File

@ -1,7 +1,7 @@
/+ bip84, bip32 /+ btca=btc-address
:- %say :- %say
|= [[now=@da eny=@uvJ bec=beak] [zpub=tape ~] ~] |= [[now=@da eny=@uvJ bec=beak] [zpub=tape ~] ~]
:- %noun :- %noun
=/ bs=(list @ux) =/ bs=[(list @ux) (list @ux)]
(zpub-bytes:bip84 zpub) (parse-zpub:btca zpub)
(pubkey-to-point:bip32 bs) bs

View File

@ -1,11 +0,0 @@
|%
++ pubkey-to-point
|= pubkey-bytes=(list @ux)
^- pont:secp:crypto
=/ as-atom=@
(rap 3 (flop (swag [45 33] pubkey-bytes)))
(decompress-point:secp256k1:secp:crypto as-atom)
++ is-point
|= pubkey=(list @ux) ^- ?
%.y
--

View File

@ -1,10 +0,0 @@
|%
++ zpub-bytes
|= zpub=tape
^- (list @ux)
=/ as-atom=@
(de-base58:mimes:html zpub)
%+ turn
(flop (rip 3 as-atom))
|=(bytes=@ `@ux`bytes)
--

36
lib/btc-address.hoon Normal file
View File

@ -0,0 +1,36 @@
|%
:: bytes rip: 0x6261 -> ~[98 97]
::
+$ pubkey (list @ux)
+$ chaincode (list @ux)
++ big-endian-brip
|= a=@ux
^- (list @ux)
(flop (rip 3 a))
:: bytes 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
^- pont:secp:crypto
=/ as-atom=@
(rap 3 (flop (swag [45 33] pubkey-bytes)))
(decompress-point:secp256k1:secp:crypto as-atom)
::
++ is-point
|= pubkey=pubkey ^- ?
-:(mule |.((pubkey-to-point pubkey)))
--