did-btcr2-js

ADR 151: The Common Package Removes JSONUtils.deleteKeys and 11 Error Types That No Code Uses

Context

JSONUtils.deleteKeys

JSONUtils.deleteKeys(value, keys) returns a copy of a JSON value without the keys in keys. It removes a key at each depth, also in the items of an array.

The specification (Resolve, Apply update) removes only the top-level proof property before it hashes an 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.” The Confirm Duplicate Update step uses the same words.

Before ADR 141, the Apply step of the resolver called JSONUtils.deleteKeys(update, ['proof']). Thus a patch that added a member named proof gave a different hash at the two steps. ADR 141 replaced the call with an object rest destructure in Resolver.unsignedUpdateHash.

ADR 141, decision 3, kept the function: “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.”

No source file in the packages calls the function. Only 4 tests in packages/common/tests/utils-json.spec.ts and the demo script packages/common/lib/test-json-utils.ts call it.

11 members of MethodErrorCode

MethodErrorCode holds the error types of a DidMethodError. No code in src, lib, or tests of a package reads or raises these 11 members:

Member Also a named export of the common package
INVALID_DID_DOCUMENT_LENGTH no
INVALID_PREVIOUS_DID_PROOF yes
INVALID_PUBLIC_KEY yes
INVALID_PUBLIC_KEY_MULTIBASE yes
INVALID_PUBLIC_KEY_LENGTH yes
INVALID_PUBLIC_KEY_TYPE yes
INVALID_SIGNATURE yes
UNSUPPORTED_PUBLIC_KEY_TYPE no
INVALID_SIDECAR_DATA yes
INVALID_UPDATE no
MISSING_RESOLUTION_OPTIONS yes

No cited specification defines these error types:

The api uses Object.values(MethodErrorCode) as the set of error types that a resolution result can carry. The api does not report another type. For an error with another type, the api uses the type of the nearest cause that is in this set, or else INTERNAL_ERROR. No code raises the 11 types, so no resolution result holds them.

Decision

1. The common package removes JSONUtils.deleteKeys

This change removes the function, its JSDoc, its tests, and its demo lines. defineOwn stays, because JSONUtils.sanitize and other functions of JSONUtils use it.

To remove a top-level key, use an object rest destructure, as Resolver.unsignedUpdateHash does (ADR 141, decision 1):

const { proof: _, ...unsignedUpdate } = update;

This form removes only the top-level key, as the specification requires. A deep removal is not an operation of the specification.

2. The common package removes the 11 members of MethodErrorCode

This change removes the 11 members and their JSDoc from the enum. It also removes the 8 named exports in the table.

4 other members also have no reader. They stay for these reasons:

3. One MAJOR release holds the removals

The common package needs a MAJOR release for each removal. Both removals go into the next MAJOR release of the common package, with each other breaking change of that release. Thus the dependent packages get one dependency uptake, not two.

4. Each judgment call conforms to the specification texts

Judgment call Text Result
Remove the deep key removal. Resolve, Apply update: “Create unsigned_update by removing the proof property from update”. Conforms. The specification removes one top-level property. The packages keep no function for a deep removal.
Remove the 11 error types. did:btcr2 Errors allows “Additional error types defined in the Errors section of DID Resolution v1”. Conforms. Neither specification defines the 11 types, and no code raises them.

Alternatives

Consequences

Superseded.

Unchanged.

Implementation

References