did-btcr2-js

ADR 141: The Resolver Removes Only the Top-Level Proof Before It Hashes an Update

Context

The resolver hashes the unsigned form of each BTCR2 Signed Update at two algorithm steps of the specification (Resolve):

  1. Apply update. “Create unsigned_update by removing the proof property from update, hash it with the JSON Document Hashing algorithm, and append the hash to update_hash_history.”
  2. Confirm Duplicate Update. The step uses the same words. It compares the hash with the entry of update_hash_history for the targetVersionId of the update.

The specification (Data Structures) defines a BTCR2 Signed Update as the properties of a BTCR2 Unsigned Update “and one additional property”, proof. Thus both steps remove only that top-level property.

The two steps of the resolver did not agree:

A patch can add a member named proof, for example in a service:

[
  {
    "op": "add",
    "path": "/service/-",
    "value": { "id": "did:btcr2:k1...#nested", "type": "LinkedDomains", "serviceEndpoint": "https://example.com", "proof": { "value": "a" } }
  }
]

For such an update, the two steps computed different hashes. If two Beacon Signals announced the same update, the resolver applied the update at the first signal. At the second signal, the hash did not match the history entry, and the resolver raised LATE_PUBLISHING. The DID did not resolve past that point.

Decision

1. One function makes the hash of the unsigned update

Resolver.unsignedUpdateHash removes the top-level proof property with an object rest destructure. Then it hashes the result with canonicalHashBytes. The Apply step and the Confirm Duplicate step both call this function.

The specification uses the same words at the two steps. One function makes sure that the two steps cannot compute different hashes again.

2. A nested member named proof is data of the update

The hash keeps each member named proof below the top level. The member is part of the patch, and the signature of the update covers it. Thus two updates that differ only in a nested proof member have different hashes. A duplicate check that compares them raises LATE_PUBLISHING.

3. JSONUtils.deleteKeys stays in the common package

The resolver does not call JSONUtils.deleteKeys any more. No other source file in the packages calls it. This ADR does not remove the function from the common package, because its removal is a MAJOR change of the common package. A separate change removes it.

Alternatives

Consequences

Implementation

References