2020-09-30 13:32:09 +03:00
|
|
|
## NOTE
|
|
|
|
The below requires norsyr's fix to `decompress-point` in order to work.
|
2020-09-28 11:09:04 +03:00
|
|
|
|
2020-10-01 14:53:47 +03:00
|
|
|
## Working with BTC RPC Library
|
2020-09-28 11:09:04 +03:00
|
|
|
```
|
2020-10-03 13:54:31 +03:00
|
|
|
|start :btc-bridge
|
2020-10-01 14:53:47 +03:00
|
|
|
:btc-node-hook|command [%credentials 'http://127.0.0.1:18443' 'poopman' 'chAiM31eeJ1MK3y8BC3mR9q2']
|
2020-10-03 13:54:31 +03:00
|
|
|
:btc-node-hook|command [%ping ~]
|
2020-10-03 10:57:16 +03:00
|
|
|
:btc-node-hook|command [%watch %get-block-count]
|
2020-10-01 14:53:47 +03:00
|
|
|
:btc-node-hook|action [%get-block-count ~]
|
2020-10-03 10:57:16 +03:00
|
|
|
:btc-node-hook|command [%unwatch %get-block-count]
|
2020-09-28 11:09:04 +03:00
|
|
|
```
|
2020-09-28 14:08:14 +03:00
|
|
|
|
2020-10-01 14:53:47 +03:00
|
|
|
## btc-address
|
2020-09-30 11:12:52 +03:00
|
|
|
**Import lib; optionally set up env**
|
2020-09-30 09:40:26 +03:00
|
|
|
```
|
2020-09-30 10:05:52 +03:00
|
|
|
=btca -build-file %/lib/btc-address/hoon
|
2020-10-02 13:40:57 +03:00
|
|
|
=mnemonic="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
|
|
|
|
|
2020-09-30 13:32:09 +03:00
|
|
|
=bip32 -build-file %/lib/bip32/hoon
|
2020-09-30 16:42:40 +03:00
|
|
|
=ecc secp256k1:secp:crypto
|
2020-10-02 13:40:57 +03:00
|
|
|
=zpub "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
|
2020-09-30 11:12:52 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
**Test child public key from xpub**
|
|
|
|
```
|
2020-10-02 13:40:57 +03:00
|
|
|
`@ux`(child-from-xpub:btca zpub 0)
|
2020-09-30 11:12:52 +03:00
|
|
|
(child-from-xpub:btca xpub (dec (bex 31)))
|
|
|
|
|
|
|
|
:: should error as index is too high (hardened key range)
|
2020-10-02 13:40:57 +03:00
|
|
|
(child-from-xpub:btca zpub (bex 31))
|
2020-09-30 11:12:52 +03:00
|
|
|
```
|
|
|
|
|
2020-09-30 13:32:09 +03:00
|
|
|
**Same, with Jose's bip32 library**
|
|
|
|
```
|
2020-10-02 13:40:57 +03:00
|
|
|
:: get 0 index in non-change account
|
|
|
|
`@ux`(compress-point:ecc pub:(derive-public:(derive-public:(from-extended:bip32 zpub) 0) 0))
|
2020-09-30 13:32:09 +03:00
|
|
|
```
|
|
|
|
|
2020-10-04 11:56:38 +03:00
|
|
|
## BIP 173 (Bech32 Addresses)
|
|
|
|
```
|
|
|
|
=bip173 -build-file %/lib/bip173/hoon
|
|
|
|
```
|
|
|
|
|
2020-10-04 17:16:35 +03:00
|
|
|
### Bech32 Algo
|
|
|
|
- hash = hash160(pubkey)
|
|
|
|
- words = convert(hash, 8bitTo5bit)
|
|
|
|
- encode('bc', [0x00 words])
|
|
|
|
|
|
|
|
### BTC pubkey -> address hashing (Hash-160)
|
2020-10-04 16:07:07 +03:00
|
|
|
Uses the example data here:
|
|
|
|
https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
|
|
|
|
|
|
|
|
That one starts with pubkey below. The following runs it through sha256 and ripemd160 to yield the hash:
|
2020-10-04 17:16:35 +03:00
|
|
|
```
|
|
|
|
0xf54a.5851.e937.2b87.810a.8e60.cdd2.e7cf.d80b.6e31
|
|
|
|
```
|
|
|
|
|
2020-10-04 16:07:07 +03:00
|
|
|
Use `@uc` to make the Hash-160 into a BTC P2PKH address
|
|
|
|
```
|
|
|
|
=pubkey 0x2.5086.3ad6.4a87.ae8a.2fe8.3c1a.f1a8.403c.b53f.53e4.86d8.511d.ad8a.0488.7e5b.2352
|
2020-10-04 19:03:22 +03:00
|
|
|
(hash-160:bip173 pubkey)
|
|
|
|
`@uc`(hash-160:bip173 pubkey)`@uc`(hash-160:bip173 pubkey)
|
|
|
|
```
|
|
|
|
|
|
|
|
### trailing zeros
|
|
|
|
Need to test with this because it shows need to input num bytes
|
|
|
|
```
|
|
|
|
0x3.f3c1.3839.3683.93e7.0caf.4148.4775.b805.312d.58be.d157.1308.3d27.5cf5.6998.0100
|
2020-10-04 16:07:07 +03:00
|
|
|
```
|
|
|
|
|
2020-10-02 13:40:57 +03:00
|
|
|
## Deprecated: `btc-address` Child Derivations
|
2020-09-30 16:42:40 +03:00
|
|
|
|
2020-09-30 11:12:52 +03:00
|
|
|
**Test xpub parsing**
|
|
|
|
```
|
|
|
|
(parse-xpub:btca xpub)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Test addition and ECC point checking**
|
|
|
|
```
|
2020-09-30 16:15:37 +03:00
|
|
|
=px (parse-xpub:btca xpub)
|
2020-09-30 11:12:52 +03:00
|
|
|
=pubk ?~ px ~ pubk.u.px
|
2020-09-30 10:05:52 +03:00
|
|
|
(is-point:btca pubk)
|
2020-09-30 13:32:09 +03:00
|
|
|
(pubkey-to-point:btca pubk)
|
2020-09-30 11:12:52 +03:00
|
|
|
=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)))
|
2020-09-28 14:08:14 +03:00
|
|
|
```
|
2020-10-04 16:07:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
0xf54a.5851.e937.2b87.810a.8e60.cdd2.e7cf.d80b.6e31
|
|
|
|
|
|
|
|
0x2.b092.22c4.98c3.ab97.ce2b.6c4d.e68f.07d4.b031.589c.4d6b.bd31.7791.068f.7347.5201
|
|
|
|
|
|
|
|
0x2.5086.3ad6.4a87.ae8a.2fe8.3c1a.f1a8.403c.b53f.53e4.86d8.511d.ad8a.0488.7e5b.2352
|
2020-10-04 19:03:22 +03:00
|
|
|
0x2.3db4.d241.5936.c340.3de9.b0d9.e5e9.5dfb.43e6.0acd.aec9.0c9d.c17a.5c7c.26be.3150
|
|
|
|
|