did-btcr2-js

ADR 145: A Historical Resolution Processes the Full History and Returns the Requested State

Context

The specification keeps the requested state

Specification pull request 391 (“Keep a conflicting update fatal for historical resolution”, merged 2026-10-09) closes specification issue 386. It changes “Process Next Update” of “Resolve”.

Before the change, step 1 and step 5 resolved current_document as didDocument. Step 1 tested versionId. Step 5 tested versionTime against the block mediantime of the tuple. The resolver did not process the rest of the updates.

After the change, step 1 and step 5 copy the state to a new variable, requested_state. The specification defines it: “the state at the version that resolutionOptions.versionId or resolutionOptions.versionTime requests, a copy of current_document, current_version_id, block_confirmations and block_mediantime, the values didDocumentMetadata is built from. The resolver keeps these copies while it processes the rest of the updates (starts empty).”

Each of the two steps copies only if requested_state is empty. Step 2 runs if no tuple is left or if the document is deactivated. If requested_state is not empty, step 2 sets the four values from it and resolves current_document. Otherwise step 2 raises NOT_FOUND if versionId is set, as before.

The pull request also removes a condition from the rule for unused sidecar data. The rule “Sidecar Data that the resolver did not use has no effect on the result” now applies also to a request with versionId or versionTime.

The resolver stopped at the requested version

ADR 111 implemented the old steps 1 and 5: the resolver ended the resolution at the requested version. Thus the resolver did not check a later update with the steps of “Process Next Update”. An error that these steps find, for example LATE_PUBLISHING or INVALID_DID_UPDATE from “Apply update”, did not fail a historical request. Example: a history has a valid version 2, a valid version 3, and a later beacon signal with a second, different version 3.

Request Specification This library before
no option LATE_PUBLISHING LATE_PUBLISHING
versionId: "2" LATE_PUBLISHING version 2
versionTime after version 2 and before version 3 LATE_PUBLISHING version 2

ADR 068 recorded a part of this case as a residual risk. The window of a versionTime request is the history up to versionTime. A second, different update for a version in the window failed a versionTime request. A gap or two different updates of one version after the window did not. A versionId request did not check a second, different update of the requested version, or an update of a later version.

Decision

1. Step 1 and step 5 keep the requested state, and step 2 restores it

The resolver holds requested_state in the private field #requestedState, with four values: the document, the version, confirmations, and updated. At step 1 and at step 5, the resolver keeps the current values in requested_state if requested_state is empty. Then it continues. At step 2, if requested_state is not empty, the resolver sets the four values from it and completes. Otherwise, the NOT_FOUND rule of ADR 111 applies.

requested_state holds a reference to the document, not a copy. For each update, the resolver makes a new current document, because JSONPatch.apply patches a clone. Thus the document in requested_state does not change. If a future JSONPatch.apply patches in place, the resolver must copy the document at step 1 and step 5.

2. An error in a later update fails the request

The resolver processes each update after the requested version with the checks of a request for the current version. Thus one history gives one answer about its integrity: a historical request fails if a request for the current version fails. The errors include LATE_PUBLISHING, INVALID_DID_UPDATE, MISSING_UPDATE_DATA, and the INTERNAL_ERROR of the maxDiscoveryRounds limit.

3. The order of the tests before step 5 stays

Two tests run before the step 5 test, and neither keeps the requested state:

  1. The resolver ignores a tuple at a beacon address that the document no longer has (step 4).
  2. A duplicate of an applied version goes to the duplicate branch (ADR 068, decision 1). The step 5 condition “The tuple’s targetVersionId is more than current_version_id” gives the same result. Footnote 4 of “Process Next Update” gives the reason: the block of a duplicate can be after versionTime, and the next version can be before it.

4. The metadata is the metadata of the requested version

confirmations and updated come from requested_state. Thus they report the block of the update that yields the requested version, not the block of a later update. deactivated comes from the document in requested_state, so a later deactivation does not change it.

Alternatives

Consequences

Superseded.

Implementation

References