working btc-bridge

This commit is contained in:
timlucmiptev 2020-10-02 13:40:57 +03:00 committed by ixv
parent a0645a0c30
commit 48183e57be
4 changed files with 48 additions and 18 deletions

View File

@ -1,7 +1,7 @@
:: bippy-bridge.hoon
:: Provider for accessing BTC full node
:: btc-bridge.hoon
:: Proxy for accessing BTC full node
::
/- *bippy-bridge
/- *btc-bridge
/+ dbug, default-agent
|%
+$ versioned-state
@ -24,15 +24,16 @@
::
++ on-init
^- (quip card _this)
~& > '%bippy-bridge initialized successfully'
`this
~& > '%btc-bridge initialized successfully'
:- ~[[%pass /response %agent [our.bowl %btc-node-hook] %watch /response]]
this
++ on-save
^- vase
!>(state)
++ on-load
|= old-state=vase
^- (quip card _this)
~& > '%bippy-bridge recompiled successfully'
~& > '%btc-bridge recompiled successfully'
`this(state !<(versioned-state old-state))
++ on-poke
|= [=mark =vase]

View File

@ -61,7 +61,11 @@
:: because we handle permissioning at higher-level agents.
::
?> (team:title our.bowl src.bowl)
`this
?+ pax (on-watch:def pax)
[%response ~]
~& > "%btc-node-hook: subscription on {pax}"
`this
==
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-agent on-agent:def
@ -181,6 +185,15 @@
|= btc-resp=btc-node-hook-response
^- (quip card _state)
:_ state
:: If the head term is a type of call we are watching, then
:: broadcast it to subscribers on the response path
::
=/ broadcast-response=(list card)
?: (~(has in watched-calls) -.btc-resp)
~[[%give %fact ~[/response] %noun !>(3)]]
~
%+ weld
broadcast-response
^- (list card)
?+ -.btc-resp
:: By default we just print all RPC responses that are not

View File

@ -11,32 +11,29 @@ The below requires norsyr's fix to `decompress-point` in order to work.
**Import lib; optionally set up env**
```
=btca -build-file %/lib/btc-address/hoon
=mnemonic="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
=bip32 -build-file %/lib/bip32/hoon
=ecc secp256k1:secp:crypto
=xpub "xpub6DnWFmBQfQm1wxvKkCJjXwE6H4v8FTwUuhjDQ9ZpJnFDfhA8Dwmg71yPKyjUE93D2CB6MdnWNvGmwsb3fpd4oRJ2YcyMZoMpLU3BjpmQAny"
=parent-zpub "zpub6rmyMSPvm5aexi2PidLFG5ERHCeNQgT3KrkXT6pEPK82zFntRUE5MqwEZCanG5NPzmDvfJ9vAr6NxzTx9FAPTAEN1JFPcL1M7CXNd5WKcP9"
=zpub "zpub6sLyD5WyhVybzoATevSndC5jmhHjfxKjDA5A21DXzoYUJyFyfUo9cW7WX7veTkKVzHjh2Npvfcm5KTT89go29p3PJtscYH4CiYzVbwV5iJW"
=zpub "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
```
**Test child public key from xpub**
```
`@ux`(child-from-xpub:btca xpub 0)
`@ux`(child-from-xpub:btca zpub 0)
(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))
(child-from-xpub:btca zpub (bex 31))
```
**Same, with Jose's bip32 library**
```
`@ux`(compress-point:secp256k1:secp:crypto pub:(derive-public:(from-extended:bip32 xpub) 0))
`@ux`(compress-point:secp256k1:secp:crypto pub:(derive-public:(from-extended:bip32 zpub) 0))
:: get same zpub point as above starting from parent-zpub
`@ux`(compress-point:ecc pub:(derive-public:(derive-public:(from-extended:bip32 parent-zpub) 0) 0))
:: get 0 index in non-change account
`@ux`(compress-point:ecc pub:(derive-public:(derive-public:(from-extended:bip32 zpub) 0) 0))
```
## Deprecated: Sample Child Derivations
## Deprecated: `btc-address` Child Derivations
**Test xpub parsing**
```

19
ted/ph/add.hoon Normal file
View File

@ -0,0 +1,19 @@
/- spider
/+ *ph-io, bip32
=, strand=strand:spider
=, secp256k1:secp:crypto
^- thread:spider
|= args=vase
=/ m (strand ,vase)
=/ zpub=tape
"zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
=/ pubkey
derive-public:(from-extended:bip32 zpub)
;< ~ bind:m start-simple
;< ~ bind:m (raw-ship ~bud ~)
;< ~ bind:m (dojo ~bud "|start %btc-node-store")
;< ~ bind:m (dojo ~bud "|start %btc-node-hook")
;< ~ bind:m (dojo ~bud "(add 9 299)")
;< ~ bind:m (wait-for-output ~bud "308")
;< ~ bind:m end-simple
(pure:m *vase)