GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Bitcoin mainnet PSBT signing: required limits, typed confirm, fee cap… · gitmoot/keyring@9c8621a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • cmd/keyring
    • bitcoin_import.go
    • bitcoin_import_test.go
    • main.go
  • docs
    • bitcoin.md
    • configuration.md
    • dashboard.md
  • internal
    • admin
      • admin.go
    • bitcoin
      • bitcoin.go
      • bitcoin_test.go
      • mainnet_test.go
      • psbt.go
    • dashboard
      • access.go
      • bitcoin.go
      • bitcoin_mainnet_test.go
      • bitcoin_test.go
      • dashboard.go
      • dashboard_test.go
      • pages.go
      • requests.go
      • services.go
    • instance
      • instance_test.go
      • state.go
    • policy
      • bitcoin_mainnet_test.go
      • bitcoin_test.go
      • policy.go
    • server
      • bitcoin_mainnet_test.go
      • bitcoin_signing.go
      • bitcoin_signing_test.go
      • server.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The key never leaves the keyring machine. The agent holds only a role token, whi
3535

3636
- **API proxy.** Bearer (or another `Authorization` scheme, such as `Key`), header or query-parameter keys, up to two extra secret headers, keys with up to 32 values (numbered or named, with optional labels), and [key pools](docs/proxy.md#key-pools-several-keys-behind-one-service) that try a key's values in the order you set and switch to the next when one is refused or runs out. Paths are normalised, keys echoed back by an API are masked, redirects are not followed. [Proxy](docs/proxy.md)
3737
- **Request signing without handing out the private key.** Apple Ads and App Store Connect JWTs, Sign in with Apple client secrets, APNs push, raw Ed25519, and minisign release signatures. [Apple](docs/apple.md) · [Signing](docs/signing.md)
38-
- **Bitcoin PSBT signing (test networks).** Imported tprv/WIF keys sign the PSBT inputs that are provably theirs (BIP86 taproot key path, BIP84 P2WPKH), only on allowed derivation paths, with per-grant sats limits per PSBT and per day; the key is never shown. Regtest, testnet and signet in phase 1. [Bitcoin](docs/bitcoin.md)
38+
- **Bitcoin PSBT signing.** Imported tprv/xprv/WIF keys sign the PSBT inputs that are provably theirs (BIP86 taproot key path, BIP84 P2WPKH), only on allowed derivation paths, with per-grant sats limits per PSBT and per day; the key is never shown. Regtest, testnet, signet and mainnet; on mainnet the limits are required (at most 200,000 sats per PSBT and 1,000,000 per day), grants take a typed confirmation, the fee is capped at 50,000 sats or 200 sat/vB, and every signature notifies the owner. [Bitcoin](docs/bitcoin.md)
3939
- **OAuth with refresh.** The keyring holds the refresh token and mints access tokens, for Gmail, Drive and any OAuth 2 provider; Google accounts can also come from `gcloud`. [OAuth](docs/oauth.md) · [Google via gcloud](docs/google-gcloud.md)
4040
- **Per-agent access.** Each agent (a *role*) gets only the services, methods and paths it was given, with daily request and byte limits and an end date. Agents find services with `keyring services --search`, ask with `keyring request`, and the owner approves in one tap. [Finding services](docs/proxy.md#finding-services)
4141
- **Projects.** Group a client's services, give an agent a whole project, pause it or let it expire in one place. [Projects](docs/projects.md)
@@ -137,7 +137,7 @@ Next: [turn on the dashboard](docs/dashboard.md), [install on a Mac](deploy/mac/
137137
| [Consent links](docs/consent-links.md) | One-time links for a person to connect their account |
138138
| [Apple](docs/apple.md) | Apple Ads, App Store Connect, Sign in with Apple, APNs |
139139
| [Signing](docs/signing.md) | Ed25519 and minisign |
140-
| [Bitcoin](docs/bitcoin.md) | PSBT signing with imported keys (test networks) |
140+
| [Bitcoin](docs/bitcoin.md) | PSBT signing with imported keys (test networks and mainnet) |
141141
| [Egress proxy](docs/egress-proxy.md) | Tunnels through a person's own proxy |
142142
| [Instance mode](docs/instance-mode.md) | One keyring per person, under a supervisor |
143143
| [Mac install](deploy/mac/README.md) · [Cloudflare](deploy/cloudflare/README.md) | Deployment |
Collapse file

‎cmd/keyring/bitcoin_import.go‎

Copy file name to clipboardExpand all lines: cmd/keyring/bitcoin_import.go
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/gitmoot/keyring/internal/store"
1212
)
1313

14-
// bitcoinImport stores a Bitcoin private key (a master tprv or a WIF key)
14+
// bitcoinImport stores a Bitcoin private key (a master tprv/xprv or a WIF key)
1515
// read from stdin, never from arguments, so it is not in the shell history
1616
// or the process list (#187). The owner keeps the backup: the keyring never
1717
// generates or shows a key. It prints what the owner can check against the
@@ -20,7 +20,7 @@ import (
2020
// service would use is refused (checkBitcoinValue).
2121
func bitcoinImport(configPath, storePath, network, name string, stdin io.Reader, stdout, stderr io.Writer) error {
2222
if network == "" {
23-
return errors.New("pass --network regtest, testnet or signet")
23+
return errors.New("pass --network mainnet, regtest, testnet or signet")
2424
}
2525
if !store.ValidName(name) {
2626
return fmt.Errorf("invalid key name %q: use letters, digits and _", name)
@@ -32,7 +32,7 @@ func bitcoinImport(configPath, storePath, network, name string, stdin io.Reader,
3232
if _, exists := keys[name]; exists {
3333
return fmt.Errorf("%s already exists; import under a new name", name)
3434
}
35-
value, err := readHidden(bufio.NewReader(stdin), stdin, stderr, "Bitcoin key for "+name+" (tprv or WIF, not shown): ")
35+
value, err := readHidden(bufio.NewReader(stdin), stdin, stderr, "Bitcoin key for "+name+" (tprv/xprv or WIF, not shown): ")
3636
if err != nil {
3737
return err
3838
}
Collapse file

‎cmd/keyring/bitcoin_import_test.go‎

Copy file name to clipboardExpand all lines: cmd/keyring/bitcoin_import_test.go
+20-2Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ func TestBitcoinImportFromStdin(t *testing.T) {
6666
}
6767
}
6868

69+
// A mainnet xprv imports with --network mainnet and shows the BIP86 and
70+
// BIP84 vectors' first mainnet addresses.
71+
func TestBitcoinImportMainnet(t *testing.T) {
72+
rules, storePath := bitcoinRules(t)
73+
var out, errOut bytes.Buffer
74+
if code := run([]string{"bitcoin-import", "--config", rules, "--store", storePath, "--network", "mainnet", "BTC_MAIN"}, strings.NewReader(bitcointest.MasterMainnet+"\n"), &out, &errOut); code != 0 {
75+
t.Fatalf("exit %d: %s", code, errOut.String())
76+
}
77+
for _, want := range []string{"network: mainnet", "m/86'/0'/0'/0/0", "bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr", "m/84'/0'/0'/0/0", "bc1qcr8te4kr609gcawutmrza0j4xv80jy8z306fyu"} {
78+
if !strings.Contains(out.String(), want) {
79+
t.Fatalf("output lacks %q:\n%s", want, out.String())
80+
}
81+
}
82+
if strings.Contains(out.String()+errOut.String(), bitcointest.MasterMainnet[:20]) {
83+
t.Fatal("key printed")
84+
}
85+
}
86+
6987
func TestBitcoinImportRefusals(t *testing.T) {
7088
cases := []struct {
7189
name string
@@ -75,8 +93,8 @@ func TestBitcoinImportRefusals(t *testing.T) {
7593
}{
7694
{"key as an argument", []string{"--network", "regtest", "BTC_ORD", bitcointest.Master}, "", ""},
7795
{"no network", []string{"BTC_ORD"}, bitcointest.Master, ""},
78-
{"mainnet", []string{"--network", "mainnet", "BTC_ORD"}, bitcointest.Master, ""},
79-
{"mainnet key on regtest", []string{"--network", "regtest", "BTC_ORD"}, bitcointest.MasterMainnet, ""},
96+
{"tprv on mainnet", []string{"--network", "mainnet", "BTC_ORD"}, bitcointest.Master, "the key is for another network"},
97+
{"mainnet key on regtest", []string{"--network", "regtest", "BTC_ORD"}, bitcointest.MasterMainnet, "the key is for another network"},
8098
{"not a key", []string{"--network", "regtest", "BTC_ORD"}, "hunter2", ""},
8199
{"empty stdin", []string{"--network", "regtest", "BTC_ORD"}, "", ""},
82100
// The bearer service api waits for API_KEY: it would send the key.
Collapse file

‎cmd/keyring/main.go‎

Copy file name to clipboardExpand all lines: cmd/keyring/main.go
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ const usage = `Usage:
5353
keyring list --store FILE print key names (never values)
5454
keyring minisign-keygen --store FILE NAME make a new Ed25519 signing key in the store (never shown) and
5555
print its minisign public key
56-
keyring bitcoin-import --config FILE --store FILE --network regtest|testnet|signet NAME
57-
import a Bitcoin tprv or WIF key from stdin (never shown) and print
56+
keyring bitcoin-import --config FILE --store FILE --network mainnet|regtest|testnet|signet NAME
57+
import a Bitcoin tprv/xprv or WIF key from stdin (never shown) and print
5858
its fingerprint and first receive addresses
5959
keyring new-token make a role token and its hash for the rules file
6060
keyring request --upstream URL --role NAME --service S [--service S ...] [--project P ...] [--note TEXT] [--new TOKENS_DIR]
@@ -108,7 +108,7 @@ func run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
108108
secretFile := fs.String("file", "", "set: import a private file verbatim, or /dev/stdin for a protected pipe (up to 1 MiB)")
109109
adminTokenSHA := fs.String("admin-token-sha256", "", "instance: hex SHA-256 of the supervisor's admin token")
110110
statePath := fs.String("state", "", "instance: keep the sealed state in this file (default: memory only)")
111-
network := fs.String("network", "", "bitcoin-import: regtest, testnet or signet")
111+
network := fs.String("network", "", "bitcoin-import: mainnet, regtest, testnet or signet")
112112
auditPath := fs.String("audit", "", "instance: audit log file (default: stdout)")
113113
containerMode := fs.Bool("container", false, "instance: run in a container reached only through its supervisor (wildcard listen, no source check)")
114114
if err := fs.Parse(rest); err != nil {
Collapse file

‎docs/bitcoin.md‎

Copy file name to clipboardExpand all lines: docs/bitcoin.md
+75-13Lines changed: 75 additions & 13 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Bitcoin PSBT signing (test networks)
1+
# Bitcoin PSBT signing
22

33
A sign-only service with `"auth": "bitcoin-psbt-sign"` holds an imported
44
Bitcoin key and signs the inputs of a PSBT that belong to it. The key never
55
leaves keyring: an agent sends a PSBT and gets it back signed; it never sees
66
the key, and neither does anyone opening the dashboard.
77

8-
Phase 1 signs on **regtest, testnet and signet only**. A service with
9-
`"network": "mainnet"` is refused when the config is loaded. Mainnet is phase
10-
2: it will require the per-grant limits below.
8+
Phase 1 signs on **regtest, testnet and signet**; phase 2 adds **mainnet**,
9+
with required limits, a fee cap and a notification for every signature (see
10+
[Mainnet](#mainnet)).
1111

1212
Keyring signs; it does not finalise, broadcast, pick coins or build
1313
transactions. The caller (for example an inscription tool) does that.
@@ -112,7 +112,7 @@ each agent's grant (section 3).
112112
}
113113
```
114114

115-
- `network`: `regtest`, `testnet` or `signet` (`mainnet` is refused in phase 1).
115+
- `network`: `mainnet`, `regtest`, `testnet` or `signet`.
116116
- `paths` (tprv keys): the derivation path templates keyring signs for.
117117
Hardened steps take `'` or `h`. A trailing `/*` means any non-hardened index
118118
(0 … 2^31-1). The purpose must be `86'` (taproot key path, BIP86: the BIP341
@@ -160,8 +160,8 @@ Grant the role the service like any other. Two optional limits sit next to
160160
missing a limit cannot be kept: a grant with a per-day limit is then refused
161161
with 503, and a corrupt or unsafe file is left alone and refused the same way.
162162

163-
Both limits are optional on test networks and will be required on mainnet in
164-
phase 2. The dashboard grant form shows them for bitcoin services.
163+
Both limits are optional on test networks and required on mainnet (see
164+
[Mainnet](#mainnet)). The dashboard grant form shows them for bitcoin services.
165165

166166
## API
167167

@@ -184,10 +184,15 @@ no-store`):
184184
"txid": "<id of the unsigned transaction>",
185185
"signed": [0, 2],
186186
"external_sats": 65000,
187-
"fee_sats": 5000
187+
"fee_sats": 5000,
188+
"vbytes": 154
188189
}
189190
```
190191

192+
`vbytes` is a size the finalised transaction is never below (see
193+
[Mainnet](#mainnet)), so `fee_sats / vbytes` is never below its real fee
194+
rate.
195+
191196
Taproot inputs get the key-path signature (`tap_key_sig`), P2WPKH inputs a
192197
partial signature; nothing is finalised. Body up to 4 MiB.
193198

@@ -249,12 +254,69 @@ the service (wrong network, a WIF where paths are set) is 503
249254
## Audit and dashboard
250255

251256
Each signature writes one audit line with the role, service and
252-
`"bitcoin": {"network", "txid", "inputs", "external_sats", "fee_sats"}` —
257+
`"bitcoin": {"network", "txid", "inputs", "external_sats", "fee_sats", "vbytes"}` —
253258
never the PSBT or the key. The service page shows the watch-only side
254259
(fingerprint, output descriptors with the account xpubs, first addresses) and
255260
a table of the recent signatures read from the audit log.
256261

257-
## Phase 2
258-
259-
Mainnet: config validation will accept `"network": "mainnet"` only with both
260-
per-grant limits set.
262+
## Mainnet
263+
264+
Phase 2 (owner rules, 2026-11-26, #187). Real bitcoin, so on top of every
265+
rule above:
266+
267+
**Setup.**
268+
269+
1. Import a key of its own: `keyring bitcoin-import --config rules.json
270+
--store keys.json --network mainnet NAME` (an `xprv` or a mainnet WIF). A
271+
key that also backs a test-network service (the same seed, or the same
272+
secret as a test WIF) is refused: the dashboard will not create the
273+
service, the service page warns, and signing answers 503.
274+
2. Set `notify_command` in `rules.json` (see Notifications): a mainnet
275+
service without it is refused at load, `check` and `SIGHUP`, and signing
276+
answers 503 `no owner notification configured`. Instance mode has no
277+
trusted channel for it, so it refuses mainnet services outright.
278+
3. Create the service with `"network": "mainnet"`. Its `paths` may only be
279+
`m/86'/0'/0'/0/*`, `m/86'/0'/0'/1/*`, `m/84'/0'/0'/0/*`,
280+
`m/84'/0'/0'/1/*`, and its `sighash` only `default` and `all` (none,
281+
single and anyonecanpay leave inputs or outputs uncommitted, so a
282+
signature could outlive the PSBT whose sats were checked); the signer
283+
refuses the others on mainnet whatever the list says. A service never
284+
moves between mainnet and the test networks (the dashboard refuses the
285+
edit), so grants never carry across; make a new service instead.
286+
4. Grant one role at a time, with both limits and the typed confirmation.
287+
288+
**Ceilings and required limits.** Every grant on a mainnet service sets both
289+
`bitcoin_max_sats_per_tx` (1 … 200,000) and `bitcoin_max_sats_per_day`
290+
(1 … 1,000,000), the per-PSBT one at most the daily one. A config without
291+
them is refused at load, `check` and `SIGHUP`. Project grants have no limits,
292+
so they never reach a mainnet service: only the role's own grant does, and
293+
switching it off revokes that service alone.
294+
295+
**Typed confirmation.** On the dashboard, creating a mainnet grant, renewing
296+
one that has ended or raising either sats limit, and approving a request for
297+
a mainnet service (which asks for both limits), take the service name and
298+
the daily limit typed again exactly; otherwise nothing is saved.
299+
300+
**Fee cap.** A mainnet PSBT whose fee is above 50,000 sats or whose fee rate
301+
is above 200 sat/vB is refused. The rate is the fee over `vbytes`, a size the
302+
finalised transaction is never below, so the computed rate is never below
303+
the real one: the non-witness part of the transaction exactly, the inputs
304+
keyring signs at their smallest witness (a 64-byte taproot signature, 65
305+
with sighash `all`; a P2WPKH one with the shortest DER signature and the
306+
33-byte key), and every other input with an empty witness and script sig,
307+
even when the PSBT carries it finalised. Keyring's signature does not commit
308+
to another input's witness, so that witness could be stripped or replaced
309+
after signing; padding it never lowers the rate keyring computes.
310+
311+
The check is conservative: the real rate is at most the one checked, and
312+
lower by a lot when other inputs carry large witnesses (an inscription
313+
reveal). Such a PSBT may need a lower fee rate on the inputs keyring signs,
314+
or the keyring inputs signed in a transaction of their own. Inputs keyring
315+
does not sign may be of any kind.
316+
317+
**Notifications.** Every mainnet signature runs `notify_command` (in
318+
`rules.json`) with one line as its last argument, for example
319+
`keyring: mainnet signature by phobos on btc-main: txid …, 65000 sats
320+
external, fee 5000 sats, 32.5 sat/vB`. A refusal sends nothing. See
321+
[configuration](configuration.md#notify_command). It starts once the
322+
signature and its day total are kept, before the reply is written.
Collapse file

‎docs/configuration.md‎

Copy file name to clipboardExpand all lines: docs/configuration.md
+12Lines changed: 12 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,15 @@ A rules file from before the split still holds `services` and `roles`. The servi
4646
`SIGHUP` re-reads the rules file, the access file and the keys. A change to `allow_sources` applies at once; a changed `listen`, `audit_log` or `access_file`, or an invalid file, is refused, and the previous settings stay in use. Daily counts carry over.
4747

4848
A stored Bitcoin private key (`tprv`/`xprv`/WIF) can only be used by a `bitcoin-psbt-sign` service: `check`, the start and `SIGHUP` refuse settings in which another service would use one, and `keyring set` stores one only with `--config rules.json`, to check that first. See [bitcoin.md](bitcoin.md).
49+
50+
### notify_command
51+
52+
`notify_command` in `rules.json` is the owner's notification hook: it runs once for every **mainnet** Bitcoin signature (never for a refusal, never on a test network). It is an argv list, never a shell string: the first entry is the absolute path of a program, at most 32 entries, no NUL bytes; keyring appends one line as the last argument (`keyring: mainnet signature by <role> on <service>: txid …, N sats external, fee N sats, R sat/vB`). It runs in the background for at most 10 seconds; a failure or timeout is written to the audit log and never delays or fails the signature. A change applies on `SIGHUP`.
53+
54+
The service runs as `_keyring` without a desktop session, so desktop notifiers (for example `osascript`) are not expected to work. The owner picks the channel at setup; a network hook works from the service account, for example posting to a URL the owner controls:
55+
56+
```json
57+
"notify_command": ["/usr/bin/curl", "-fsS", "-m", "8", "https://ntfy.example/your-topic", "-d"]
58+
```
59+
60+
It is required for any mainnet service: `check`, the start and `SIGHUP` refuse a mainnet service without it, and signing answers 503 if it is somehow missing. Instance mode has no such setting and refuses mainnet services. See [bitcoin.md](bitcoin.md#mainnet).

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.