did-btcr2-js

btcr2 resolve

Resolves the DID document of a did:btcr2 identifier and prints the resolution result on stdout. The command is read-only and needs no keystore: it never touches the keystore, never asks for a passphrase, and never reads the session. The identifier encodes the network. So resolve works with no config against the public defaults of each network: the mempool.space Esplora REST endpoints and the public https://trustless-gateway.link IPFS gateway for CAS reads.

If the identifier has an identifier record in <home>/dids.json, the sidecar data of the record joins the resolution options (ADR 133). -i also accepts the name of a record. resolve reads the records file but never writes it. See identifier.md.

The CLI drives the sans-I/O Resolver state machine through @did-btcr2/api. The api fetches the beacon signals from the Bitcoin REST endpoint. With --btc-signal-discovery fullnode, it scans blocks over Bitcoin Core RPC instead. The api fetches a genesis document, a CAS announcement, or a signed update from the configured CAS by hash, if the sidecar data does not supply it. Use -r or -p to pass resolution options (a version pin, sidecar data, a discovery limit).

Synopsis

btcr2 resolve [options] -i <identifier>
btcr2 read [options] -i <identifier>          # 'read' is an alias

btcr2 resolve -i did:btcr2:k1qq...
btcr2 resolve -i did:btcr2:x1qh... -r '<json>'
btcr2 resolve -i did:btcr2:x1qh... -p <path-to-json-file>
btcr2 resolve -i did:btcr2:x1qh... --genesis-document ./genesis.json
btcr2 resolve -i alice                          # the name of an identifier record

There are no subcommands and no arguments. The required -i flag carries the identifier or the name of its record.

Options

Flag Value Default Description
-i, --identifier <identifier> A did:btcr2 identifier string: did:btcr2: and a Bech32m body. The HRP is k (deterministic, a 33-byte compressed secp256k1 public key) or x (external, a 32-byte genesis document hash). The encoded network must be one of bitcoin, testnet3, testnet4, signet, mutinynet, regtest. none (required) The identifier to resolve, or the name of its identifier record. A value that does not start with did: is a name. An unknown name fails with No identifier record has the name "<name>". An identifier starts with "did:btcr2:". The command decodes and validates the identifier before any I/O. A malformed identifier fails at once (for example Invalid did: <value>). An identifier with a reserved network value (6 to 11) or a custom network value (12 to 15) fails at decode with Invalid network (reserved): <n> or Invalid network (custom network not supported): <n> (ADR 107).
-r, --resolution-options <json> An inline JSON string. See “Resolution options JSON” below for the shape. none The resolution options. The command adds the sidecar data of the identifier record (see below), and passes the rest to the resolver as it is. Non-JSON input fails with Invalid resolution options. Must be a valid JSON string. (INVALID_ARGUMENT_ERROR). If both -r and -p are present, -r wins and the command ignores -p without a message.
-p, --resolution-options-path <path> The path of a file with the same JSON shape as -r. none The file form of -r. An unreadable path or non-JSON content fails with Invalid resolution options path. Must be a valid path to a JSON file. (INVALID_ARGUMENT_ERROR).
--min-conf <n> A positive integer (minimum 1). Another value fails at parse time with --min-conf must be a positive integer (minimum 1). 6 (the specification value) The minimum number of block confirmations that a beacon signal needs before resolution applies it (ADR 105). The flag overrides a minConf inside -r or -p. Pass 1 to see a fresh update after one block.
--genesis-document <path> The path of the JSON genesis document of an external (x) identifier, for example the file that btcr2 genesis build wrote. An unreadable path or non-JSON content fails with Invalid genesis document path. Must be a valid path to a JSON file.. A JSON value that is not an object fails with Invalid genesis document. The file must contain a JSON object.. none Fills sidecar.genesisDocument of the resolution options. The flag wins over a sidecar.genesisDocument inside -r or -p. For a k identifier, the command refuses the flag with --genesis-document applies only to external identifiers (x). before it reads the file (ADR 108).
-h, --help none n/a Print the help of the command and exit.

The validation order (from the source): the command finds the identifier of a record name first. Then it decodes the identifier, then checks --genesis-document against the identifier type, then parses -r, then -p, then reads the genesis document file. It reads the identifier record last, before the resolution. An invalid identifier therefore fails before the command looks at a bad options string.

The --help text of resolve matches the source.

Sidecar data of the identifier record

If the identifier has an identifier record, the command adds the sidecar data of the record to the resolution options (ADR 133). create, update, deactivate, and identifier add --sidecar put the sidecar data into the record. So an identifier that the CLI made and updated resolves with no sidecar flag.

Resolution options JSON (the -r or -p value)

The JSON object is the ResolutionOptions type of @did-btcr2/method. Each field is optional. An empty object {} equals no options.

Field Type Meaning
versionId string The version of the DID document to resolve, as an ASCII string of an integer. The versions start at "1", the genesis document. The resolver keeps the DID document at this version, processes the rest of the history, and returns the kept DID document. An error in a later update fails the resolution. A version that the history does not reach fails with NOT_FOUND. Mutually exclusive with versionTime: a request with both fails with INVALID_OPTIONS.
versionTime string An XML datetime in UTC with the Z designator and no fraction (for example '2026-07-01T00:00:00Z'). The resolver keeps the DID document before the first new version whose block mediantime (median time past) is after that instant. A mediantime equal to the instant is not after it. The resolver then processes the rest of the history and returns the kept DID document, or the current DID document if it kept none. An error in a later update fails the resolution. A value in another form fails with INVALID_OPTIONS.
maxDiscoveryRounds number An opt-in upper bound on the number of beacon discovery rounds. Unset, absent, or not positive means no limit. The resolver always stops, because it does not query a beacon address twice. A positive value is a resource guard. A run over the limit fails with INTERNAL_ERROR. With versionId or versionTime, the count includes the rounds after the requested version.
sidecar object The off-chain data bundle. See below.
accept string An HTTP Accept header value (RFC 9110, section 12.5.1), for example "application/did". The value has no effect. Another string fails with INVALID_OPTIONS.
expandRelativeUrls boolean false has no effect. true returns a copy of the DID document in which each relative DID URL is absolute (DID Resolution v1, section 4.4, step 6). The resolver resolves each string id of a map and each string item of the five verification relationships against the identifier (RFC 3986, section 5). For example, #key-1 becomes <identifier>#key-1. @context, each serviceEndpoint value, a value with a scheme, and a value that starts with // stay unchanged (ADR 162). Do not pass the copy to update -s or deactivate -s.
noCache boolean or string true, false, "true", or "false". The resolver keeps no cache, so the value has no effect.

Another field fails with FEATURE_NOT_SUPPORTED, and a wrong value of a field in the table fails with INVALID_OPTIONS (ADR 157). The resolver checks the options before any network request.

The resolver also checks the JSON type of these sidecar fields: @context must be a string, and updates, casUpdates, and smtProofs must be arrays. A value of another JSON type, also null, fails with INVALID_OPTIONS, for an identifier with or without a record (ADR 164). For example, -r '{"sidecar":{"updates":5}}' fails with Failed to resolve DID <identifier>: Invalid resolution option sidecar.updates: expected an array, got 5. and exit code 1. The resolver does not check the type of genesisDocument. It hashes each value, and a value with another hash fails with INVALID_DID (ADR 160). The resolver also does not check an item of an array or a field with another name.

The sidecar fields:

Field Type Meaning
@context string The optional context string https://btcr2.dev/context/v1.
genesisDocument object The genesis document. An x identifier needs it, unless the api can fetch the document from the configured CAS by its hash. The resolver replaces each did:btcr2:_ with the identifier and adds no member (ADR 148). The @context must be an array of strings and JSON objects, with https://www.w3.org/ns/did/v1.1 as the first item and https://btcr2.dev/context/v1 as an item (ADR 171). verificationMethod and service are optional. The members must conform to DID Core v1.1 (ADR 149). For example, the controller of each verification method must be a DID. Without @context, the command fails with Failed to resolve DID <identifier>: Invalid "@context": @context must be an array and exit code 1. A document with no JCS form (RFC 8785) fails with Failed to resolve DID <identifier>: Invalid genesis document: Cannot canonicalize: ... and exit code 1 (ADR 154).
updates array of SignedBTCR2Update The signed updates. Necessary if the identifier has published updates that the api cannot fetch from the CAS. The resolver ignores an update with no JCS form (RFC 8785), because it has no hash (ADR 154). It also ignores an update that is not a JSON object (ADR 160).
casUpdates array of CASAnnouncement The CAS announcements (maps of identifier to signed update hash). Necessary for CAS beacon updates that the api cannot fetch from the CAS. If an announcement has no entry for the identifier, its beacon signal announces no update for the identifier. The resolver ignores an announcement with no JCS form (RFC 8785), because it has no hash (ADR 154). It also ignores an announcement that is not a JSON object (ADR 160). An entry of another identifier has no effect. The value of an entry for the identifier must be a base64url SHA-256 hash: 43 characters, no padding, zero pad bits. If a beacon signal names the announcement, another value, also an empty string, fails the resolution with MISSING_UPDATE_DATA: The value of the CAS announcement entry for <identifier> is not a base64url SHA-256 hash. (ADR 146).
smtProofs array of SMTProof The SMT proofs (id, collapsed, hashes, optional nonce and updateId, all base64url without padding). Sidecar data is the only channel for an SMT proof. A proof has no content address on chain, so the api cannot fetch it from a CAS. The resolver ignores a proof whose id does not decode to 32 bytes, for example an id with non-zero pad bits (ADR 146). An ignored proof that no beacon signal needs has no effect. If a beacon signal needs a proof that the sidecar data does not hold or that the resolver ignores, resolution fails with MISSING_UPDATE_DATA: SMT proof required but not in sidecar (root hash: ...).

How the @did-btcr2/api layer satisfies each data need:

Output

Exit codes: 0 on success, 1 on an error. Errors go to stderr. A CLI-typed error (an invalid identifier network, bad -r or -p input, a config problem) prints the message only, unless --verbose is set. Then it prints the full structured error. A resolution failure from the api layer (a network failure, missing sidecar data, an unreachable endpoint) is a plain Error with a cause chain. It prints with its stack, with or without --verbose. An identifier that does not decode, also one with a correct prefix but an invalid Bech32m body, fails as a method error of type INVALID_DID and prints as one line (Invalid did: ... or Invalid method-specific id (Bech32m decoding failed: ...)). A valid DID of another method fails with the type METHOD_NOT_SUPPORTED (Invalid did method: ...). A refused resolution option is an api-layer failure: Failed to resolve DID <did>: ... with the reason.

Environment and configuration

resolve reads the network from the identifier. Then it resolves the Bitcoin and CAS endpoints of that network through the standard CLI precedence chain:

flag  >  environment variable  >  profile in config.json  >  built-in default of the network

A blank value at one layer defers to the next layer. It does not mask the next layer.

Profile selection: the --profile <name> flag, else defaults.profile of the config file, else the profile with the name of the network of the identifier. A mutinynet identifier selects profiles.mutinynet. An active profile applies also to an identifier of another network, and then the command prints the warning above. resolve does not read defaults.network of the config file. That key steers a command without an identifier, such as create, init, and quickstart. The identifier always fixes the network.

The settings that feed this command:

Setting Flag Env var config.json key Built-in default
Home directory (holds the records file dids.json) --home <dir> BTCR2_HOME n/a ~/.btcr2 (Linux and macOS). On Windows %LOCALAPPDATA%\btcr2, else %APPDATA%\btcr2
Config file -c, --config <path> none n/a <home>/config.json
Active profile --profile <name> none defaults.profile the network name of the identifier
Output format -o, --output <format> (json | text) BTCR2_OUTPUT defaults.output text
Bitcoin REST endpoint --btc-rest <url> BTCR2_BTC_REST profiles.<name>.btc.rest per network, see below
Bitcoin Core RPC URL --btc-rpc-url <url> BTCR2_BTC_RPC_URL profiles.<name>.btc.rpcUrl http://localhost:18443 (regtest only), none elsewhere
RPC username --btc-rpc-user <user> BTCR2_BTC_RPC_USER profiles.<name>.btc.rpcUser none
RPC password none (never argv) BTCR2_BTC_RPC_PASS profiles.<name>.btc.rpcPass none
RPC password file none BTCR2_BTC_RPC_PASS_FILE none none
RPC wallet --btc-rpc-wallet <name> none profiles.<name>.btc.wallet none
Extra REST headers --btc-rest-header <header> (repeatable, 'Key: Value') none profiles.<name>.btc.headers none
Extra RPC headers --btc-rpc-header <header> (repeatable, 'Key: Value') none profiles.<name>.btc.rpcHeaders none
Beacon signal discovery --btc-signal-discovery <mode> (indexer | fullnode) BTCR2_BTC_SIGNAL_DISCOVERY profiles.<name>.btc.signalDiscovery indexer
Bitcoin timeout (ms) --btc-timeout <ms> (finite number, 1 or more) BTCR2_BTC_TIMEOUT profiles.<name>.btc.timeoutMs no limit
CAS gateway (read-only) --cas-gateway <url> BTCR2_CAS_GATEWAY profiles.<name>.cas.gateway, then defaults.cas.gateway https://trustless-gateway.link
CAS RPC endpoint (writable) --cas-rpc-url <url> BTCR2_CAS_RPC_URL profiles.<name>.cas.rpcUrl, then defaults.cas.rpcUrl none
CAS RPC username --cas-rpc-user <user> BTCR2_CAS_RPC_USER profiles.<name>.cas.rpcUser, then defaults.cas.rpcUser none
CAS RPC password none (never argv) BTCR2_CAS_RPC_PASS profiles.<name>.cas.rpcPass, then defaults.cas.rpcPass none
CAS RPC password file none BTCR2_CAS_RPC_PASS_FILE none none
CAS timeout (ms) --cas-timeout <ms> (finite number, 0 or more. 0 disables the timeout) BTCR2_CAS_TIMEOUT profiles.<name>.cas.timeoutMs, then defaults.cas.timeoutMs 30000

The built-in Bitcoin REST defaults per network (from @did-btcr2/api):

Network REST default
bitcoin https://mempool.space/api
testnet3 https://mempool.space/testnet/api
testnet4 https://mempool.space/testnet4/api
signet https://mempool.space/signet/api
mutinynet https://mutinynet.com/api
regtest http://localhost:3000 (REST), http://localhost:18443 (RPC, no default credentials)

Behavior details, all checked against the source:

Global flags

See the docs README for the shared global flags. resolve uses: -o, --output (text or the JSON envelope), --verbose (the full structured error for a CLI-typed error), the connection overrides (--btc-rest, --btc-rpc-url, --btc-rpc-user, --btc-rpc-wallet, --btc-rest-header, --btc-rpc-header, --btc-signal-discovery, --btc-timeout, --cas-gateway, --cas-rpc-url, --cas-timeout), the state location flags (--home, -c, --config, --profile), and --quiet (suppresses the network warning). The command accepts --keystore and --passphrase-file, but they have no effect on it.

Examples

# No config: the identifier encodes mainnet ('bitcoin'), so the CLI uses https://mempool.space/api
btcr2 resolve -i did:btcr2:k1qqpyerymt5aaxm2jyh7za2594hgrq24uhqanxe5h94rf42flxkwhvmqd03t47

# The same, through the alias
btcr2 read -i did:btcr2:k1qqpyerymt5aaxm2jyh7za2594hgrq24uhqanxe5h94rf42flxkwhvmqd03t47

# The JSON envelope ({ "action": "resolve", "data": ... })
btcr2 -o json resolve -i did:btcr2:k1qqpyerymt5aaxm2jyh7za2594hgrq24uhqanxe5h94rf42flxkwhvmqd03t47

# Pin one version of the document
btcr2 resolve -i did:btcr2:k1qq... -r '{"versionId":"2"}'

# Resolve the document as it was at a point in time (UTC, no sub-second precision)
btcr2 resolve -i did:btcr2:k1qq... -r '{"versionTime":"2026-07-01T00:00:00Z"}'

# An external (x) identifier with sidecar data from a file
btcr2 resolve -i did:btcr2:x1qh... -p ./resolution-options.json

# An external (x) identifier with the genesis document that genesis build wrote
btcr2 resolve -i did:btcr2:x1qh... --genesis-document ./genesis.json

# An identifier by the name of its record. The record supplies the sidecar data
btcr2 resolve -i alice --min-conf 1

# Limit the beacon discovery rounds as a resource guard
btcr2 resolve -i did:btcr2:k1qq... -r '{"maxDiscoveryRounds":3}'

# Override the Bitcoin REST endpoint and limit the request time
btcr2 --btc-rest 'https://mutinynet.com/api' --btc-timeout 15000 resolve -i did:btcr2:k1qq...

# Use your own IPFS gateway for the CAS reads
btcr2 --cas-gateway 'http://127.0.0.1:8080' resolve -i did:btcr2:x1qh...

A resolution-options.json for an external identifier with sidecar updates:

{
  "sidecar": {
    "genesisDocument": { "id": "did:btcr2:_", "@context": ["..."] },
    "updates": [ { "patch": [ ... ], "proof": { ... }, "targetVersionId": 2 } ],
    "smtProofs": [ { "id": "...", "collapsed": "...", "hashes": [ "..." ] } ]
  }
}

See also