bsecret

module
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0

README

bsecret

CI Release Go version License

[!WARNING] Experimental software. bsecret is part of bstack, the applications and patterns built on BSV Layered Multicast. It is published to be built on and improved. Interfaces, formats and behavior may change rapidly between releases; pin an exact version.

Secrets management on Bitcoin, replicated by overlay hosts that hold ciphertext and never a key. A secret is encrypted once under a random key; the key is wrapped to the members of a group's current epoch; and when the group removes a member, the vault must re-key everything it holds before it does anything else.

The TypeScript host module under host/ is frozen: bug fixes only. New behavior goes to its Go twin under module/, written to bcommon's module contract and mounted by a Go overlay engine (docs/host.md). The bsecret-host image runs the TypeScript module.

How it works

  • A secret is a keyed object. Each version is encrypted under its own random content key, committed to before anyone holds it (BRC-369). The ciphertext is public; the key is wrapped to the owner's wallet and under the key of one epoch of a borg group.
  • Readers are a group's members. Adding a reader is adding a member. Removing one begins a new epoch whose key the removed member never receives.
  • Revoke forces rotation, checked by every host. A vault is a chain of mined tokens. Once it acknowledges a new epoch, no host admits anything onto that chain but the re-keying or retirement of what it held, until nothing is left under an earlier epoch. Hosts cannot make an owner acknowledge: readers and auditors see a vault that has not.
  • The chain is the audit trail. Anyone with block headers verifies which versions the owner listed, in what order, under which epoch, and how long each stayed listed under an epoch a removed member held. No cooperation from a host or the owner is needed. The trail proves what the owner signed; that a version's key is wrapped under the epoch it names is checked by the members who open it.
  • Hosts are replicas, not authorities. A host can withhold; it cannot forge, alter or decrypt.
  • Pseudonymous, not hidden. Values, names and claims are inside the ciphertext. The organization's key, the vault's and secrets' identifiers, the display name, labels, sizes and timing are public: on chain, and at the hosts unless a host makes the crypt private, answering only its organizations and their groups' members (who sees what).
  • Honest about what removal does. A removed member keeps everything it could read. Removal protects what is written after the vault re-keys.

Install

$ go install github.com/lightwebinc/bsecret/cmd/bsecret@latest
$ go install github.com/lightwebinc/borg/cmd/borg@latest   # the owner also runs borg

Or download a static binary for Linux or macOS (amd64, arm64) from Releases, or build the image ghcr.io/lightwebinc/bsecret (make docker-build).

Example: a vault on mainnet

The owner is a borg organization with a group that has run borg org signer once (borg). No node is needed: by default bsecret reads from WhatsOnChain and broadcasts through GorillaPool's public arcade, checking every proof against the headers; use your own node where you have one. Nothing is mined for you: fund the bsecret home with a payment from your own wallet.

$ bsecret -network main init -borg ~/.borg      # a home around the organization's identity
identity     02c6…9a1e
fund address 1EUY…zipY (main)
$ # send about 20,000 sat from your own wallet to the fund address (a vault and ninety versions cost under 10,000)
$ bsecret fund -txid <txid of that payment>     # once mined; or fund -beef FILE at once
$ bsecret crypt new example                     # give the printed BSECRET_CRYPTS line to your hosts
$ bsecret vault create engineering              # a vault on a borg group; its display name is drawn at random
$ bsecret put db/password < new-password.txt    # a version, listed in a mined token
$ bsecret get db/password | psql ...            # a member reads, every check in order
$ borg org remove <key> -group engineering      # the removal is borg's: a new epoch
$ bsecret rotate -set db/password=new.txt -same-all   # acknowledge, re-key, sweep
$ bsecret -org <key> -vault <id> audit -free    # anyone: the trail, from headers

The owner's bsecret home is made around the identity of its borg home and shares nothing else with it: the group's chain and its epoch keys are read from the hall's hosts by borg's own packages. Members and auditors need no coin. The full walk on mainnet or testnet is docs/examples.md; a sandbox on one machine that needs no coin is QUICKSTART.md.

Documentation

If you want to Read
Run it on mainnet or testnet, step by step docs/examples.md
Try it on one machine with no coin (a private regtest chain) QUICKSTART.md
Understand the ideas and use it day to day docs/user-guide.md
Set every key, flag and environment variable docs/configuration.md
Look up a command or an exit code docs/usage.md
Serve secrets to a sidecar, Vault Agent or the External Secrets Operator docs/usage.md, docs/examples.md
See how the pieces fit docs/architecture.md
Run an overlay host that carries a crypt docs/host.md
Know the defaults and caps, what was measured, and what things cost docs/limits.md
Implement a compatible owner, reader, auditor or host docs/spec.md (the specification)
Know what cannot change once published docs/frozen.md
Know what comes next docs/roadmap.md

Build and test

$ (cd host && npm ci)   # once: the TypeScript package's dependencies
$ make verify           # gofmt, vet, dependency set, licenses, typecheck, vectors, tests
$ make bsecret          # the command, bin/bsecret
$ make module           # the host module, host/bundle/bsecret-module.js
$ make vectors          # regenerate the golden vectors, both languages
$ make e2e REFERENCE_HOST=/path/to/host   # the module on a local reference overlay host
$ make e2e-client REFERENCE_HOST=/path/to/host BORG_MODULE=/path/to/borg-module.js
                        # the command and borg's, against two local hosts loading both modules
$ make docker-build     # the command's and the local chain's images
$ make quickstart-check # QUICKSTART.md, run as written

Go 1.27.2 or later, and Node 24 for the TypeScript package under host/ (make verify NODE=/path/to/node24 when it is not on PATH). The direct Go dependencies are go-sdk v1.7.5, bcommon v0.35.1 and borg v0.7.7 (exact tags in go.mod, asserted by make verify), and nothing else but bcommon's devkit, which only the tests and the devchain and vectors commands import.

The record layer exists twice, held to one set of vectors: internal/secrec in Go, and host/ in TypeScript. Each reads what the other writes (testdata/vectors, testdata/ts). host/ is also the host module: the topic manager tm_bsecret_<crypt> and the lookup service ls_bsecret, bundled into one file an overlay host loads by path.

Security

Report a vulnerability privately: SECURITY.md.

License

Apache 2.0; see LICENSE, NOTICE and LICENSE-THIRD-PARTY.

Directories

Path Synopsis
cmd
bsecret command
Command bsecret keeps an organization's secrets on overlay hosts, and reads them as a member of the group a vault is keyed to: it creates an identity home around a borg organization's key, creates crypts and vaults, writes each version of a secret under a fresh content key wrapped to the group's current epoch, acknowledges a new epoch of the group and re-keys everything the vault held, retires and retracts, reads a secret with every check made in the signed order, audits a vault's trail from block headers alone, pays a host's 402 for the priced questions, and settles the payments a host accepted as its payee.
Command bsecret keeps an organization's secrets on overlay hosts, and reads them as a member of the group a vault is keyed to: it creates an identity home around a borg organization's key, creates crypts and vaults, writes each version of a secret under a fresh content key wrapped to the group's current epoch, acknowledges a new epoch of the group and re-keys everything the vault held, retires and retracts, reads a secret with every check made in the signed order, audits a vault's trail from block headers alone, pays a host's 402 for the priced questions, and settles the payments a host accepted as its payee.
devchain command
Command devchain is a local stand-in chain for trying bsecret without a node, a settlement service or any coin: bcommon devkit's devchain (a node's JSON-RPC at /rpc, its asset API under /api/v1/ and a header source at /v1/root/<height> and /v1/tip, every transaction mined at once).
Command devchain is a local stand-in chain for trying bsecret without a node, a settlement service or any coin: bcommon devkit's devchain (a node's JSON-RPC at /rpc, its asset API under /api/v1/ and a header source at /v1/root/<height> and /v1/tip, every transaction mined at once).
vectors command
Command vectors writes the golden vectors under testdata/vectors, or with -check compares them byte for byte and writes nothing (bcommon devkit's vectors runner over this repository's generator).
Command vectors writes the golden vectors under testdata/vectors, or with -check compares them byte for byte and writes nothing (bcommon devkit's vectors runner over this repository's generator).
internal
config
Package config resolves the bsecret command's settings: flags, then BSECRET_* in the environment, then the config file, then the built-in default.
Package config resolves the bsecret command's settings: flags, then BSECRET_* in the environment, then the config file, then the built-in default.
engine
Package engine is a bsecret publisher: the owner's tooling (docs/spec.md sections 7, 8, 12 and 13), run from one identity's home.
Package engine is a bsecret publisher: the owner's tooling (docs/spec.md sections 7, 8, 12 and 13), run from one identity's home.
secrec
Package secrec is the byte-level contract of bsecret: the vault record that rides a mined chain token, the secret record that rides an unmined carrier, the payload a secret's ciphertext holds, the BRC-369 keyed content around it, the wrap of a content key under a group epoch's key and to the owner's own wallet, the crypt, label and name grammars, the vault fold, and the lookup question classes.
Package secrec is the byte-level contract of bsecret: the vault record that rides a mined chain token, the secret record that rides an unmined carrier, the payload a secret's ciphertext holds, the BRC-369 keyed content around it, the wrap of a content key under a group epoch's key and to the owner's own wallet, the crypt, label and name grammars, the vault fold, and the lookup question classes.
state
Package state is an identity's durable record in its home: the funding trees its carriers and vaults spend, the vaults it owns (each vault's chain of mined tokens and every version it published), the objects persisted before they are published, the sweeps it built, every content key commitment it ever published or listed, and, for a reader, the latest token of each vault it has verified.
Package state is an identity's durable record in its home: the funding trees its carriers and vaults spend, the vaults it owns (each vault's chain of mined tokens and every version it published), the objects persisted before they are published, the sweeps it built, every content key commitment it ever published or listed, and, for a reader, the latest token of each vault it has verified.
testhost
Package testhost is the local stand-ins this module's tests run against: an overlay host that carries bsecret crypts and borg halls, a plane, a terms route, and an organization's borg tooling reduced to what a vault needs of it.
Package testhost is the local stand-ins this module's tests run against: an overlay host that carries bsecret crypts and borg halls, a plane, a terms route, and an organization's borg tooling reduced to what a vault needs of it.
vectors
Package vectors generates the golden vectors under testdata/vectors from the codec in internal/secrec.
Package vectors generates the golden vectors under testdata/vectors from the codec in internal/secrec.
vread
Package vread asks overlay hosts the ls_bsecret questions and checks every answer itself (docs/spec.md sections 10.2, 13 and 14): a vault token's record, lock and field signature, its proof against the reader's own headers and its descent by spends from the vault's first token; a secret carrier by the host's own admission rules and by SPV through its funding parent; a sweep by its proof.
Package vread asks overlay hosts the ls_bsecret questions and checks every answer itself (docs/spec.md sections 10.2, 13 and 14): a vault token's record, lock and field signature, its proof against the reader's own headers and its descent by spends from the vault's first token; a secret carrier by the host's own admission rules and by SPV through its funding parent; a sweep by its proof.
Package module is the bsecret overlay module in Go: `tm_bsecret_<crypt>` for each configured crypt and `ls_bsecret` for all of them, written to bcommon's engine-neutral contract (github.com/lightwebinc/bcommon/module) so that any Go overlay host that carries the adapter mounts it.
Package module is the bsecret overlay module in Go: `tm_bsecret_<crypt>` for each configured crypt and `ls_bsecret` for all of them, written to bcommon's engine-neutral contract (github.com/lightwebinc/bcommon/module) so that any Go overlay host that carries the adapter mounts it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL