did-btcr2-js

ADR 133: The CLI Keeps an Identifier Record for Each Identifier

Context

The CLI keeps state in its home (ADR 079): the config file, the keystore, and the session. It keeps no state about the identifiers that it makes or updates.

  1. create prints the identifier, the key URN, and the public key. Then it forgets them. The keystore holds keys, with a name tag. No key names an identifier.
  2. To find the key of a k identifier, a user decodes the identifier and compares the genesis bytes with each public key of the keystore. An x identifier and a key that an update adds have no such link.
  3. update and deactivate print the signed update, the CAS announcement, and the SMT proof. The user must keep them. The next resolution needs them as sidecar data if no CAS holds them. The user writes the resolution options file by hand.
  4. No command lists the identifiers of a user.

Other tools keep this state. Veramo keeps a record for each managed identifier (the DID, an alias, the keys, the services) in a local store, and veramo did list prints them. A Bitcoin Core wallet keeps its own transactions.

Decision

The CLI keeps one identifier record for each identifier in <home>/dids.json. The file sits next to config.json and keystore.json.

{
  "v": 1,
  "identifiers": {
    "did:btcr2:k1q...": {
      "name": "alice",
      "added": "2026-09-29T18:00:00.000Z",
      "keys": [ "urn:kms:secp256k1:05c5..." ],
      "signingKey": "urn:kms:secp256k1:05c5...",
      "txids": [ "396e..." ],
      "sidecar": { "updates": [ ] }
    }
  }
}
Field Meaning
name Optional. A unique name. A command accepts the name in place of the identifier.
added The time of the first record.
keys The URNs of the keys that the CLI used for the identifier, in the order of first use.
signingKey The key that signs the next update if --signing-key is not given. One of keys.
txids The beacon signal transactions of the updates that the CLI broadcast.
deactivated Present and true after deactivate.
sidecar The sidecar data of the identifier: the same object as resolutionOptions.sidecar.

The CLI records an identifier automatically.

Command What the record gets
create The identifier and the --name. For a stored key or a generated key: the key, as the signing key. For -t x --document: the genesis document, in the sidecar data.
update The signing key (it becomes the signing key of the record), the txid, the signed update, the CAS announcement, the SMT proof, and the sidecar data of the source resolution.
deactivate The same as update, and deactivated: true.
identifier add The name, the key of --key, and the sidecar data of --sidecar.

The commands use the record.

The signing key order of update and deactivate changes (ADR 127 gave the old order):

Layer Source
Flag --signing-key <ref>
Identifier record The signingKey of the record
Active profile identity.default
Keystore The active key

If the record names a key that the keystore does not hold, the command refuses: The record of <identifier> names the signing key <urn>, but the keystore does not hold it. Use --signing-key <ref> to select a key. Use "btcr2 identifier add <identifier> -k <ref>" to change the key of the record. A fall back to the next layer would sign with a key that the DID document does not name, and the api would then fail with a less clear error (ADR 104).

The identifier command group gets five subcommands. All five are offline.

Subcommand Action
list (ls) Prints a summary of each record: the identifier, the name, the network, the type, the keys, the signing key, the number of updates, and deactivated. -n, --network and -k, --key <ref> filter the list.
show <ref> Prints the full record.
add <ref> Adds an identifier to the records, or adds data to its record: --name, -k, --key <ref>, --sidecar <path>. For a new record of a k identifier with no --key, it links the stored key whose public key is the genesis bytes.
remove <ref> (rm) Removes the record. The keys stay in the keystore.
sidecar <ref> Prints the sidecar data of the record. --out <path> writes it to a new file (0600).

config path also prints dids, the path of the records file.

The cli test suite runs each test in a new, empty home. A mocha root hook sets BTCR2_HOME to a temporary directory named btcr2 before each test. Without it, a test of create writes a record into the real home of the user.

Alternatives

Consequences

Positive. btcr2 identifier list prints the identifiers of the user and their keys. update -i alice signs with the right key and resolves the source with the stored sidecar data, with no flag. resolve -i alice needs no resolution options file for an own identifier. A user can give the sidecar data of an identifier to a peer as one file, and the peer can import it.

Negative.

Tests. The cli tests cover: