urbit/bippy-scratch.md

145 lines
4.3 KiB
Markdown
Raw Normal View History

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-13 12:25:37 +03:00
## Set Credentials and Ping Servers
```
2020-10-13 15:31:15 +03:00
:btc-bridge|command [%become-host [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-password='8e12e5bad1808aed64627192165304e9b804f971efa34f36ae93e9fb088fe22c'] [rpc-url='http://localhost:50002']]
2020-10-13 12:25:37 +03:00
:btc-bridge|rpc-action [%brpc %get-block-count ~]
2020-10-13 15:31:15 +03:00
:btc-bridge|rpc-action [%erpc %get-address-balance [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']]
2020-10-07 14:18:30 +03:00
```
2020-10-13 14:31:08 +03:00
## Transactions
bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66
```
createrawtransaction '[{"txid" : "033f693fdf995a5ea7fe5c951ab6858c7e6a5fffc58579922cd4fc319c614c5b", "vout" : 0}]' '{"bc1qwsqxh3sdjqgdxl7ewgxftdfm8jjajta5xmv8eu" : 0.00001}'
```
2020-10-05 10:55:10 +03:00
## Handling XPubs
**Import lib; optionally set up env**
2020-10-05 14:42:52 +03:00
XPub is BIP84, mnemonic:
abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
2020-09-30 09:40:26 +03:00
```
2020-10-05 14:42:52 +03:00
=b -build-file %/lib/btc-scratch/hoon
=xpub "zpub6rFR7y4Q2AijBEqTUquhVz398htDFrtymD9xYYfG1m4wAcvPhXNfE3EfH1r1ADqtfSdVCToUG868RvUUkgDKf31mGDtKsAYz2oz2AGutZYs"
```
### Getting BIP84 Address from `xpub`
```
(~(address bip84:b %main xpub))
```
2020-10-05 14:42:52 +03:00
### with `~norsyr-torryn`'s bip32 library
2020-09-30 13:32:09 +03:00
```
2020-10-05 14:42:52 +03:00
=bip32 -build-file %/lib/bip32/hoon
=ecc secp256k1:secp:crypto
2020-10-02 13:40:57 +03:00
:: get 0 index in non-change account
2020-10-05 14:42:52 +03:00
`@ux`(compress-point:ecc pub:(derive-public:(derive-public:(from-extended:bip32 xpub) 0) 0))
2020-09-30 13:32:09 +03:00
```
2020-10-13 14:31:08 +03:00
## Legacy BTC Address Parsing
```
:: yields the initial addresss
`@uc`(scan "17xg1BZLn63zCxdTxbsFLoWpQeSnD7zSHW" fim:ag)
:: as a cord
`@t`(scot %uc `@uc`(scan "17xg1BZLn63zCxdTxbsFLoWpQeSnD7zSHW" fim:ag))
```
2020-10-04 11:56:38 +03:00
## BIP 173 (Bech32 Addresses)
```
2020-10-04 19:11:21 +03:00
=btc -build-file %/lib/btc/hoon
2020-10-04 11:56:38 +03:00
```
2020-10-04 17:16:35 +03:00
### Bech32 Algo
- hash = hash160(pubkey)
2020-10-05 10:55:10 +03:00
- 5-bit-words = convert-bits(8, 5, hash-atom)
- encode("bc", [0, 5-bit-words])
2020-10-04 17:16:35 +03:00
### 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
2020-10-05 10:55:10 +03:00
That one starts with pubkey below. The following runs it through sha256 and ripemd160 to get Hash-160:
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:11:21 +03:00
(hash-160:btc pubkey)
`@uc`(hash-160:btc pubkey)`@uc`(hash-160:btc pubkey)
```
2020-10-05 14:42:52 +03:00
### trailing zero
s
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-05 10:49:09 +03:00
### bip173 test pubkey
Pubkey
0x2.79be.667e.f9dc.bbac.55a0.6295.ce87.0b07.029b.fcdb.2dce.28d9.59f2.815b.16f8.1798
Hash-160 (has leading 0s, so good to check)
751e76e8199196d454941c45d1b3a323f1433bd6
0xf54a.5851.e937.2b87.810a.8e60.cdd2.e7cf.d80b.6e31
### bip84 public keys
From seed mnemonic:
```
process child keen cargo design install parrot hold pole unveil dance reason drink cash fix
0x2.88b5.a58a.5c26.6cef.d41b.f329.9165.46cc.1703.c4d9.a32e.1ea3.ef3d.1823.c493.05ac
0x3.289a.4e24.4381.8992.fe20.0831.3551.a3af.2266.ef3d.2038.5df9.6daa.92e3.4df2.16c4
0x3.109a.2082.eaa6.8925.1465.5393.d635.7fb9.d9b5.e191.3826.8837.69cd.db88.7a4b.b4f0
```
2020-10-05 10:55:10 +03:00
## Deprecated: `btc-address` library
Left here just for reference
**Test child public key from xpub**
```
=btca -build-file %/lib/btc-address/hoon
=ecc secp256k1:secp:crypto
`@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 zpub (bex 31))
```
2020-09-30 16:42:40 +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)
=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)
=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-07 14:18:30 +03:00
0x3.1589.edf6.2798.1d49.77a1.d4e2.58b8.aeaa.060a.d518.94e1.e122.406f.af29.b197.c1f1
2020-10-14 10:07:56 +03:00
## Signing Scratch
=unsigned 0x100.0000.015a.800f.d903.679a.cfe9.d4e2.fedb.752b.24c4.d7a5.74b4.c82a.113d.fb99.3b38.64b7.7201.0000.0019.76a9.1495.3de6.57be.4b30.5f60.6d9a.9fbd.35b0.70a6.8247.5788.acff.ffff.ff01.c09e.e605.0000.0000.1976.a914.dd6c.ce9f.255a.8cc1.7bda.8ba0.373d.f8e8.61cb.866e.88ac.0000.0000.0100.0000
=txhash (shay (met 3 unsigned) (swp 3 unsigned))
=privkey 0xdc57.c6d0.6737.6c36.bbed.632c.9d00.f037.6786.7f33.7d5a.86b5.b030.8a60.004f.08ee