mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 08:34:25 +03:00
WIP: key derivation *should* be working for I/IL/IR
This commit is contained in:
parent
ded87398de
commit
3b7d3985f2
@ -6,10 +6,36 @@ Converts a base58 zpub to hex
|
||||
```
|
||||
|
||||
### btc-address
|
||||
Test xpub parsing
|
||||
**Import lib; optionally set up env**
|
||||
```
|
||||
=btca -build-file %/lib/btc-address/hoon
|
||||
=px (parse-xpub:btca "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs")
|
||||
=pubk ?~ pp ~ pubk.u.pp
|
||||
(is-point:btca pubk)
|
||||
=xpub "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
|
||||
```
|
||||
|
||||
**Test child public key from xpub**
|
||||
```
|
||||
(child-from-xpub:btca xpub 1)
|
||||
(child-from-xpub:btca xpub (dec (bex 31)))
|
||||
|
||||
:: should error as index is too high (hardened key range)
|
||||
(child-from-xpub:btca xpub (bex 31))
|
||||
```
|
||||
|
||||
**Test xpub parsing**
|
||||
```
|
||||
(parse-xpub:btca xpub)
|
||||
```
|
||||
|
||||
**Test addition and ECC point checking**
|
||||
```
|
||||
=px (parse-xpub:btca xpub)
|
||||
=pubk ?~ px ~ pubk.u.px
|
||||
(is-point:btca pubk)
|
||||
=index 256
|
||||
`@ux`(add (lsh 3 4 (big-endian-brap:btca pubk)) index)
|
||||
```
|
||||
|
||||
**Test computing I**
|
||||
```
|
||||
(bind px |=(px=parsed-xpub:btca (compute-i:btca px 1)))
|
||||
```
|
||||
|
@ -1,9 +1,10 @@
|
||||
|%
|
||||
+$ pubkey (list @ux)
|
||||
+$ chaincode (list @ux)
|
||||
+$ parsed-xpub [cc=chaincode pubk=pubkey]
|
||||
+$ il-ir [il=(list @ux) ir=(list @ux)]
|
||||
:: 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)
|
||||
@ -40,6 +41,27 @@
|
||||
~
|
||||
::
|
||||
++ compute-i
|
||||
|= pp=parsed-xpub
|
||||
%.y
|
||||
|= [=parsed-xpub index=@ud]
|
||||
^- il-ir
|
||||
~| 'Public key cannot use a hardened index'
|
||||
?> (lth index (bex 31))
|
||||
:: "append" index to pubkey as 4 bytes
|
||||
=/ data=@
|
||||
%+ add
|
||||
(lsh 3 4 (big-endian-brap pubk.parsed-xpub))
|
||||
index
|
||||
=/ chaincode=@
|
||||
(big-endian-brap cc.parsed-xpub)
|
||||
=/ i=(list @ux)
|
||||
(big-endian-brip (hmac-sha512:hmac:crypto chaincode data))
|
||||
=/ il=(list @ux) (swag [0 32] i)
|
||||
=/ ir=(list @ux) (swag [32 32] i)
|
||||
[il ir]
|
||||
++ child-from-xpub
|
||||
|= [xpub=tape index=@ud]
|
||||
=/ is=(unit il-ir)
|
||||
%+ bind
|
||||
(parse-xpub xpub)
|
||||
|=(px=parsed-xpub (compute-i px index))
|
||||
is
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user