diff --git a/CHANGELOG.md b/CHANGELOG.md index 90554a9..b9b30a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- Run a Pubky Swaps provider on this stack's LND and Electrum (`pubky-swaps` profile) for the apps' swap route journeys - Run a local Spark regtest network on this chain (`spark` profile, `./spark`): the last public Spark operators and the Spark service provider that matches them, patched for Spark SDK 0.28 wallets, mempool.space, and commands to stop operators, mine to timelock maturity, fund addresses and read an exit's on-chain state - Deploy Bitkit's public regtest staging without Blocktank from `staging/`, replacing `*.stag0.blocktank.to` - Add local Orchestra and LayerZero providers with bridge lifecycle controls, real Arbitrum credits/refunds and a Core bridge smoke suite diff --git a/README.md b/README.md index d13dc50..7b030c1 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ payment controls, proof verification, the optional Shop overlay and simulation l - **Homegate**: Pubky Homeserver signup gatekeeper with local admin API mock - **Pubky marketplace fixture** (opt-in `marketplace` profile): Pubky testnet, Paykit Server and a purchase driver for the marketplace wallet journey - **Payment Request fixture** (opt-in `payment-requests` profile): rc8 issuer and controlled peer on the marketplace Pubky testnet +- **Pubky Swaps provider** (opt-in `pubky-swaps` profile): the swap route's counterparty on this stack's LND and Electrum, for the apps' swap route journeys - **Spark regtest** (opt-in `spark` profile, `./spark`): Spark operators, the Spark service provider and mempool.space on this chain, for local Spark development, offline E2E and emergency-exit tests ## Quick Start @@ -726,6 +727,38 @@ The `spark` profile runs a Spark network of your own on this chain: three Spark 4. Run `./spark mine` once per package, until the app waits for the timelock. 5. Run `./spark mature`, then `./spark mine` for the refunds and the sweep to Savings. +#### Pubky Swaps + +The `pubky-swaps` profile runs a Pubky Swaps provider (`coreyphillips/pubky-swap` at `f45e204`, the commit bitkit-core's Pubky Swaps client pins) on this stack's LND and Electrum. It is the counterparty of the apps' swap route: a Spending-only wallet pays a contact's on-chain address by paying the provider's hold invoice over Lightning, and the provider pays the address on chain. The apps' journeys `paykit-swap-route.xml` (J1) and `paykit-swap-restore.xml` (J2) use it with the `marketplace` and `payment-requests` fixtures. They land in each app's `journeys/` with the swap route ([synonymdev/bitkit-ios#1170](https://github.com/synonymdev/bitkit-ios/pull/1170), [synonymdev/bitkit-android#1732](https://github.com/synonymdev/bitkit-android/pull/1732)). + +```bash +docker compose up -d # chain, Electrum, LND, LNURL server +./bitcoin-cli fund # mature coins for the chain's wallet +./bitcoin-cli send 1 "$(docker compose exec -T lnd lncli --lnddir /home/lnd/.lnd --network regtest newaddress p2wkh | jq -r .address)" -m 6 +docker compose --profile pubky-swaps up -d --build pubky-swap # first build takes a while +docker compose logs pubky-swap | grep "Provider pubky" # the provider's pubky: save it as a contact in the wallet +./pubky-marketplace up && ./pubky-marketplace seed # Pubky testnet and homeserver the apps sign up on +docker compose --profile marketplace --profile payment-requests up -d --no-build fixture-issuer rc56-peer +curl -s 127.0.0.1:23012/health | jq -r .pubky # the on-chain-only contact J1 pays +``` + +- **Provider.** It shares LND's network namespace, so it dials LND's gRPC on `127.0.0.1:10009` with the TLS cert and admin macaroon LND wrote to `./lnd`, and it waits for the macaroon on a fresh stack. It offers swaps of 10,000 to 1,000,000 sats (base fee 100 sats, 2,500 ppm, one confirmation) and runs with `--no-homeserver`, so a wallet finds it only among its contacts. Wallets reach it over iroh by its pubky, which needs outbound internet. Its throwaway Pubky identity is made on first start and kept in the `pubky_swap_data` volume, so the pubky survives restarts; remove the volume for a new one. Its claims and refunds go through LND's on-chain wallet, funded above. +- **Wallet.** Build the app with the marketplace fixture's homeserver (see [Pubky Marketplace Journey](#pubky-marketplace-journey)) and the swap route on (`PUBKY_SWAPS_ROUTES=true` on Android). Create a new wallet, open a 500,000-sat channel from `curl -H 'Host: 127.0.0.1:23010' 127.0.0.1:23010/generate/channel` (start the `lnurl-pay` fixture with `docker compose --profile lnurl-pay up -d --build --wait lnurl-server-fixture`), leave Savings empty, create a Pubky profile, and save the provider's and the `fixture-issuer`'s pubkys as contacts. +- **Issuer contact.** J1 pays the `fixture-issuer` as a saved contact, which needs the issuer linked to the wallet and holding the wallet's private payment list. After saving the contact, link the issuer to the wallet and sync until it reports the link, then send the wallet its payment list: + + ```bash + TO_APP=$(jq -nc --arg pubky "$APP_PUBKY" '{peer_pubky:$pubky,peer_path:"bitkit/wallet"}') + curl -fsS -X POST http://127.0.0.1:23012/link -H 'content-type: application/json' -d "$TO_APP" | jq + curl -fsS -X POST http://127.0.0.1:23012/sync -H 'content-type: application/json' -d "$TO_APP" | jq # repeat while the app advances its handshake + curl -fsS -X POST http://127.0.0.1:23012/endpoints -H 'content-type: application/json' -d "$(jq -c '. + {action:"restore"}' <<<"$TO_APP")" | jq # private_payment_list.sent is 1 + ``` + + Without the payment list, tapping the contact shows that it hasn't enabled payments. +- **Android emulator.** Run `adb reverse tcp: tcp:` for 6286, 6287, 6288, 15411, 15412, 60001, 23735, 23000 and 23010 before the first launch. +- **iOS simulator.** The `127.0.0.1` URLs work as they are. +- **Mining.** The provider's lockup confirms with `./bitcoin-cli mine 1`; the wallet's claim needs one more block. +- **Logs.** `docker compose logs -f pubky-swap` shows `hold invoice accepted`, `HTLC funded; awaiting client claim` and `client claimed; hold invoice settled` for a swap that completes. + #### Pubky Marketplace Journey Use this section for the Bitkit marketplace wallet journey (`journeys/pubky-marketplace` in [bitkit-ios](https://github.com/synonymdev/bitkit-ios/tree/master/journeys/pubky-marketplace) and [bitkit-android](https://github.com/synonymdev/bitkit-android/tree/master/journeys/pubky-marketplace)). The `marketplace` profile adds the integration fixture that the journey lists: a Pubky testnet, Paykit Server `722ef268` (v0.1.0-rc4) with `/setup` and `x-bitkit-claim=watch-only-account-v1`, and a purchase driver. That revision emits the Pubky grant auth URL (`pubkyauth://signin_grant` with `cid` and `cpk`) that the apps' Paykit SDK (0.1.0-rc55) requires; the merge of [pubky/paykit-server#2](https://github.com/pubky/paykit-server/pull/2) (`867fc883`) emits the legacy URL, which the apps reject. It reuses this stack's regtest `bitcoind` and Electrum on `tcp://127.0.0.1:60001`. A plain `docker compose up -d` does not start it, and `./pubky-marketplace` starts only the chain and fixture services, so run it without the full stack. It needs Docker, `git`, `curl` and `jq` on the host, and outbound internet during the first build and during setup approval (see the setup relay note in [docs/pubky-marketplace.md](docs/pubky-marketplace.md)). diff --git a/docker-compose.yml b/docker-compose.yml index 6bfe9db..66fa3b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -646,6 +646,26 @@ services: FIXTURE_PORT: 3013 BITCOIN_RPC_URL: http://bitcoind:43782 + # Pubky Swaps provider (profile "pubky-swaps"), the swap route's counterparty in the apps' J1 and J2 journeys: it takes a + # wallet's hold invoice on LND and pays the contact's address on chain. It shares LND's network namespace, so it dials LND's + # gRPC on 127.0.0.1 with the TLS cert LND wrote; the apps reach it over iroh by its pubky, which it logs on start. Its + # throwaway identity is made on first start and kept in the pubky_swap_data volume. See README "Pubky Swaps". + pubky-swap: + profiles: [pubky-swaps] + image: bitkit-docker/pubky-swap:${PUBKY_SWAP_TAG:-f45e204} + build: + context: ./pubky-swap + args: + PUBKY_SWAP_REV: ${PUBKY_SWAP_REV:-f45e204ee7646dc91983d90e4782d40760b6c72b} + restart: unless-stopped + network_mode: service:lnd + depends_on: + - lnd + - electrs + volumes: + - './lnd:/lnd:ro' + - 'pubky_swap_data:/data' + # --------------------------------------------------------------------------- # Shop on staging with our own Paykit Server (profile "shop-mixed"). Paykit Server v0.1.0-rc11 (662dca06, paykit-rs ad3c7224 = # v0.1.0-rc72, the version the Bitkit send-fix builds pin) resolves Pubky on mainnet, so it serves Synonym's staging homeserver, @@ -1023,6 +1043,7 @@ volumes: shop_mixed_postgres_data: shop_mixed_state: shop_order_postgres_data: + pubky_swap_data: secrets: usdt_upstream: diff --git a/pubky-swap/Dockerfile b/pubky-swap/Dockerfile new file mode 100644 index 0000000..b8cfe24 --- /dev/null +++ b/pubky-swap/Dockerfile @@ -0,0 +1,22 @@ +FROM rust:1.98.1-bookworm@sha256:93ce27a88655056a51dbdd8f5f2d7ddc071c7b0070fb288a37b5a285fc83971e AS builder +# The LND backend compiles LND's protos. +RUN apt-get update && apt-get install -y --no-install-recommends protobuf-compiler \ + && rm -rf /var/lib/apt/lists/* +# The pubky-swap commit bitkit-core's Pubky Swaps client pins (swap-common in its Cargo.toml). +ARG PUBKY_SWAP_REV=f45e204ee7646dc91983d90e4782d40760b6c72b +WORKDIR /usr/src/pubky-swap +RUN git init -q . && git fetch -q --depth 1 https://github.com/coreyphillips/pubky-swap "$PUBKY_SWAP_REV" \ + && git checkout -q FETCH_HEAD +# No cache mounts: the QA boxes build without BuildKit, and this image is built rarely. +RUN cargo build --release --locked -p swap-provider --features full \ + && install -Dm755 target/release/swap-provider /out/swap-provider +COPY keygen /usr/src/keygen +RUN cd /usr/src/keygen && cargo build --release --locked \ + && install -Dm755 target/release/pubky-swap-keygen /out/pubky-swap-keygen + +FROM debian:bookworm-slim@sha256:3783cc01769c7b2b1b83a5c5ad96c815348e28ed7da68e2e3687004faa906251 +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* +COPY --from=builder /out/ /usr/local/bin/ +COPY entrypoint.sh /usr/local/bin/pubky-swap-entrypoint +ENTRYPOINT ["/usr/local/bin/pubky-swap-entrypoint"] diff --git a/pubky-swap/entrypoint.sh b/pubky-swap/entrypoint.sh new file mode 100755 index 0000000..0117dcb --- /dev/null +++ b/pubky-swap/entrypoint.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Runs the Pubky Swaps provider on bitkit-docker's LND and Electrum. Its Pubky identity is a throwaway phrase made on first +# start and kept in the data volume, so the pubky the apps save as a contact survives restarts. +set -eu +phrase=/data/recovery-phrase +if [ ! -s "$phrase" ]; then + umask 077 + pubky-swap-keygen > "$phrase" +fi +export PUBKY_SWAP_RECOVERY_PHRASE__FILE="$phrase" +macaroon=/lnd/data/chain/bitcoin/regtest/admin.macaroon +until [ -s "$macaroon" ]; do + echo "waiting for LND's macaroon" + sleep 2 +done +# the provider connects to Electrum once at startup, and runs without its chain watcher if Electrum is not up yet +until bash -c 'exec 3<>/dev/tcp/electrs/60001' 2>/dev/null; do + echo "waiting for Electrum" + sleep 2 +done +exec swap-provider \ + --network regtest \ + --directions submarine,reverse \ + --min-amount 10000 \ + --max-amount 1000000 \ + --base-fee 100 \ + --fee-ppm 2500 \ + --confirmations 1 \ + --wallet lnd \ + --lnd-address https://127.0.0.1:10009 \ + --lnd-cert /lnd/tls.cert \ + --lnd-macaroon "$macaroon" \ + --electrum-url tcp://electrs:60001 \ + --data-dir /data \ + --no-homeserver \ + "$@" diff --git a/pubky-swap/keygen/Cargo.lock b/pubky-swap/keygen/Cargo.lock new file mode 100644 index 0000000..b6e5081 --- /dev/null +++ b/pubky-swap/keygen/Cargo.lock @@ -0,0 +1,225 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "arrayvec" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" + +[[package]] +name = "bip39" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90dbd31c98227229239363921e60fcf5e558e43ec69094d46fc4996f08d1d5bc" +dependencies = [ + "bitcoin_hashes", + "rand", + "rand_core", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bca4c7abb40c8817d77403c880988cfd484f23ab2365726afb2f798363e2c4a2" +dependencies = [ + "hex-conservative", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hex-conservative" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3fef046dca3ca91ee1408a8c1b80ab777e80a4d308d1bf4e7adb3fcb047e08" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pubky-swap-keygen" +version = "0.1.0" +dependencies = [ + "bip39", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e058c7de0b26af77780c769414d6257830bb240f3c38477dbc2c16e5f54d6d4c" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "unicode-normalization" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75cd3fb03d5288b3ba9a1ee103ac7e9cbb59f0b03d64f8ddfcc04dd42758a85d" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "zerocopy" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] diff --git a/pubky-swap/keygen/Cargo.toml b/pubky-swap/keygen/Cargo.toml new file mode 100644 index 0000000..4992c27 --- /dev/null +++ b/pubky-swap/keygen/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "pubky-swap-keygen" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] +bip39 = { version = "2.2", features = ["rand"] } diff --git a/pubky-swap/keygen/src/main.rs b/pubky-swap/keygen/src/main.rs new file mode 100644 index 0000000..3669f6e --- /dev/null +++ b/pubky-swap/keygen/src/main.rs @@ -0,0 +1,4 @@ +//! Prints a fresh 12-word BIP39 phrase: the regtest provider's throwaway Pubky identity. +fn main() { + println!("{}", bip39::Mnemonic::generate(12).expect("12 words is a valid length")); +}