did-btcr2-js

ADR 147: Only the Method That Signs an Update Must Be a BIP340 Multikey, and Both Update Paths Check That Method

Context

The specification checks the method that signs

Specification pull request 389 (“Check the type, controller and key of the method that signs an update”) merged on 2026-10-08. It changes “Construct BTCR2 Signed Update” of “Update” and “Check update.proof” of “Resolve”. Each step finds the method through capabilityInvocation. Then it raises INVALID_DID_UPDATE if a condition is true “of the embedded verification method object, or of the verification method that the reference names”:

The specification has no rule for the other verification methods of a DID document. The only rule for the document is conformance to DID Core v1.1. Specification issue 388 (“Which verification methods can a did:btcr2 document hold?”) is open. Option 1 of the issue keeps the rule of the old specification: only the method that signs must be a BIP340 Multikey. Option 2 requires a secp256k1 Multikey for each method. A comment on the issue favors option 1.

The library checked each method, but not the method that signs

ADR 057 made one predicate, isMultikeyVerificationMethod, the rule for each verification method: the type Multikey and a publicKeyMultibase that starts with zQ3s. The DidVerificationMethod constructor and the DidDocument validation applied it. The rule had three gaps against the specification:

  1. A document with a method of another type failed, for example an Ed25519 authentication key. The specification does not refuse it.
  2. The rule did not apply to a method that capabilityInvocation embeds. On the read path, no check compared the controller of the method that signs with the DID, or checked the type of an embedded method. For the key, the read path only decoded it, and the decoder accepts other text for the same key.
  3. The prefix zQ3s is not the condition of the specification. It does not prove a 35-byte value, a valid point, or the canonical text.

The write path signed what a resolver refuses

Updater.sign(did, unsignedUpdate, verificationMethod, signer) got the method object from the caller. It did not find the method through capabilityInvocation: only DidBtcr2.update did. It needed a # in the method id. It compared the key of the signer with the key of the method only if the method had a publicKeyMultibase (ADR 051).

Updater.sign also signed an unsigned update with any sourceHash, targetHash, @context, or patch. A resolver refuses such an update after the announcement. An announced update is permanent, so the DID then no longer resolves.

The decoder accepts other text for the same key

The base58btc decoder of multiformats ignores a run of UTF-16 code units above U+00FF directly after the z header. Thus z, then U+0100, then the rest of a canonical key text decodes to the same 35 bytes and the same key. A probe found 63232 such code points at that position: each code point from U+0100 to U+FFFF, except the surrogates. An astral character, which is two surrogates, gives the same result. The rule of ADR 057 refused the reference form of this text only by chance, because the text does not start with zQ3s. The rule did not apply to an embedded method.

Examples

Input Before After
A DID document with a member of verificationMethod of another type, for example an Ed25519 key for authentication only DidDocumentError INVALID_DID_DOCUMENT. The resolver refuses an update that adds the method. Valid
An update signed by an embedded capabilityInvocation method of type JsonWebKey2020 with a valid secp256k1 key The resolver applies the update INVALID_DID_UPDATE: Invalid update: verificationMethod.type must equal "Multikey"
An update signed by an embedded method whose key text is z, U+0100, and the rest of the canonical text The resolver applies the update INVALID_DID_UPDATE, with the cause Invalid publicKeyMultibase: not the base58btc encoding of the key
Updater.sign with the method id <did>?key=1, which capabilityInvocation lists Refused: the id must contain a fragment Signs
Updater.sign with the method id did:btcr2:<other>#key, whose controller is the DID An error of the cryptosuite INVALID_DID_UPDATE: the id is not under the DID
Updater.sign with an unsigned update whose sourceHash is not the hash of the source document Signs. A resolver refuses the announced update. INVALID_DID_UPDATE: Invalid unsignedUpdate: sourceHash is not the hash of sourceDocument.
DidBtcr2.update with a method of type JsonWebKey2020 INVALID_DID_DOCUMENT INVALID_DID_UPDATE
api.btcr2.update with a patch that removes capabilityInvocation Signs and announces. Nobody can update the DID again. INVALID_DID_UPDATE before any chain read

Decision

1. Only the method that signs must be a BIP340 Multikey

The library follows option 1 of issue 388. This change removes the rule of ADR 057 for each method:

Reason: the merged specification gives the three conditions only for the method that signs. For the document, the text requires only DID Core v1.1. If issue 388 selects option 2, a later change adds the rule again.

2. One internal function checks the method that signs

signingMethodProblem(method, did) returns the first condition that the method fails, or undefined. The function is in packages/method/src/utils/signing-method.ts. index.ts does not export the module. The precedent is utils/base64url-hash.ts (ADR 146). The conditions, in this order:

  1. type equals Multikey. The rule text is type must equal "Multikey".
  2. controller equals the DID. The rule text is controller must equal "<did>".
  3. publicKeyMultibase is a string that SchnorrMultikey.fromVerificationMethod decodes, and the base58btc text of the decoded key equals the value. The rule text is publicKeyMultibase must encode a secp256k1 public key as a BIP340 Multikey.

If publicKeyMultibase is a string, a key failure also gives a cause with a type and a message. For a decode error, the cause gives the type and the message of that error. For text that is not the canonical encoding of the key, the type is VERIFICATION_METHOD_ERROR. The message is then Invalid publicKeyMultibase: not the base58btc encoding of the key. A missing publicKeyMultibase, or a value that is not a string, gives no cause.

Reason for the text comparison: the decoder accepts other text for the same bytes, but the specification allows one encoding. A strict decoder in the cryptosuite is a later change. The comparison covers only publicKeyMultibase. The decoder also accepts other text for a proofValue, and the resolver does not refuse it. The strict decoder covers both values.

3. The resolver checks the method that signs

Resolver.applyUpdate calls signingMethodProblem for the method that the proof names, in the embedded form and in the reference form. The check runs after the method lookup and before the proof time window, in the order of the specification. It also runs before the signature verification, so a failure names the field of the method.

A failure raises a ResolveError of type INVALID_DID_UPDATE. The message is Invalid update: verificationMethod. and the rule text. If the failure has a cause, : and the message of the cause follow. The data is { verificationMethodId, field, actual, cause }, and cause is present only if the failure has a cause.

4. The aggregation communication key comes from a method that can sign

ADR 066 binds the communication key to capabilityInvocation[0]. Its invariant is “transport-authenticated as D implies control of a capabilityInvocation key of D implies authorized to update D”. After the change of decision 1, capabilityInvocation[0] can be a method that cannot sign an update. The resolver refuses an update that such a method signs, so the invariant does not hold.

getAggregationCommunicationKey now calls signingMethodProblem before it decodes the key. A failure raises a DidDocumentError of type INVALID_DID_DOCUMENT. The message is Cannot derive aggregation communication key: verificationMethod. and the rule text, with the cause message if the failure has a cause. resolveBtcr2SenderPk catches the error and returns undefined for such an x1 genesis document. The Nostr transport and the HTTP transport then drop the opt-in, as for a document with no usable key.

5. Updater.signingMethod finds and checks the method on the write path

The new public function Updater.signingMethod(sourceDocument, verificationMethodId) does these steps, in this order:

  1. It checks the shape of sourceDocument: an object, a did:btcr2 id, and arrays for capabilityInvocation and verificationMethod if they are present.
  2. It resolves the id to an absolute DID URL under the DID (decision 6).
  3. It finds the entry of capabilityInvocation that identifies the id, in the reference form or the embedded form. A reference entry must name a member of verificationMethod.
  4. It applies signingMethodProblem to the method.

Each failure raises an UpdateError of type INVALID_DID_UPDATE. The method-check error has the message and the data of the read path. Each error after step 2 names the absolute id in data.verificationMethodId.

Updater.sign(sourceDocument, unsignedUpdate, verificationMethodId, signer) replaces Updater.sign(did, unsignedUpdate, verificationMethod, signer). The DID is sourceDocument.id. Updater.sign calls Updater.signingMethod first, so the caller cannot give a method that the document does not authorize. Related changes:

Each error of the signer, of the key comparison, and of the proof also names the absolute id in data.verificationMethodId.

Reason: one function makes the lookup and the checks of the specification for each write path. The read path uses the same lookup and the same checks. Thus an update that the write path signs is one that a resolver accepts.

6. The method id is a DID URL under the DID

The internal function absoluteMethodId applies two rules:

  1. A relative id resolves only in the # form (Appendix.absoluteDidUrl). A relative ?key=1 or /keys/1 fails. An absolute URI that is not a DID URL also fails. The message is Invalid verificationMethodId: expected a DID URL or a relative DID URL that starts with "#"; got "<id>".
  2. The absolute id must be the DID, then #, ?, or /, then more text. An id under another DID fails. The message is Invalid verificationMethodId: expected "<did>" followed by a fragment, a query, or a path; got "<id>".

Thus Updater.sign accepts <did>#key-1, <did>?key=1, and <did>/keys/1. The old rule “the method id must contain a fragment” had no ADR.

Reason: the section “Relative DID URLs” of DID Core v1.1 lets a relative DID URL hold a path, a query, or a fragment. The resolved URL references a resource in the same DID document. The section “Data Structures” of the specification requires an implementation to resolve a relative DID URL against the document id before a comparison.

An id under another DID fails the Retrieve Verification Method algorithm of Controlled Identifiers v1.0 (section 3.3). The controller of the method is not that other DID. The proof is separate from the DID document, so it names the method by an absolute DID URL. On each path, the library resolves only the # form of a relative DID URL (Appendix.absoluteDidUrl, ADR 091 and ADR 092).

The specification does not name this rule yet. A draft specification issue proposes the rule. Until the specification names the rule, the read path does not check it. The specification lets a resolver treat each URL of a DID document as an opaque string, except the beacon serviceEndpoint.

7. Updater.sign checks the unsigned update

After Updater.signingMethod and before the signer, the internal function checkUnsignedUpdate makes six checks, in this order:

  1. unsignedUpdate is an object with no own proof member.
  2. targetVersionId is an integer of 2 or more.
  3. @context is the BTCR2 update context.
  4. sourceHash is the hash of sourceDocument.
  5. Updater.construct(sourceDocument, patch, targetVersionId - 1) gives a valid DID document. A failure has the error of Updater.construct in data.cause.
  6. targetHash is the hash of that document.

Each message starts with Invalid unsignedUpdate: , and the type is INVALID_DID_UPDATE. Updater.sign still signs an update with an extra property, because the read path accepts it.

Reason: a resolver refuses such an update after the announcement, and the DID then no longer resolves. The failure is permanent, and the library holds the data to find it: the source document and the unsigned update.

Updater.sign gets no version of the source document. The caller must make sure that targetVersionId is that version plus 1. The api makes this check (decision 9).

Two related changes:

8. getSigningMethod uses the rules of the write path

DidBtcr2.getSigningMethod(document, methodId) and the api btcr2.getSigningMethod return Updater.signingMethod(document, methodId ?? '#initialKey'). They read only capabilityInvocation, with no assertionMethod fallback. A failure raises an UpdateError of type INVALID_DID_UPDATE. Before, the error was a MethodError of type METHOD_NOT_SUPPORTED or a DidError of code InternalError.

Before, the functions returned the method that the id names if it had a publicKeyMultibase. They searched verificationMethod and each verification relationship, so the result could be an authentication-only method that Updater.sign refuses.

The api does not export Updater (ADR 132). getSigningMethod is the api path to Updater.signingMethod.

9. The api checks the version and refuses a lock-out

btcr2.signUpdate(source: SourceState, unsignedUpdate, verificationMethodId, signer) replaces signUpdate(did, unsignedUpdate, verificationMethod, signer). source is the pair { document, versionId }, as for constructUpdate. The api calls Updater.sign(source.document, unsignedUpdate, verificationMethodId, signer). The api no longer checks for a publicKeyMultibase, because Updater.signingMethod checks the key. signUpdate also makes two version checks:

The two version checks run before Updater.sign. Thus an integer targetVersionId that is not source.versionId + 1 gets this message, also if the Updater refuses the update for another reason. If source is not an object, signUpdate throws an Error with the message source must be an object.

The api also refuses a lock-out. A target document locks out the DID if no entry of capabilityInvocation passes Updater.signingMethod and deactivated is not true. Nobody can then update or deactivate the DID. Three functions refuse it:

The data is { did, methods }. Each item of methods is { verificationMethodId, reason }. verificationMethodId is the absolute id of an entry of capabilityInvocation, or undefined if the entry has no usable id. reason is the message of the Updater.signingMethod error for that entry.

signUpdate runs the guard after Updater.sign. Thus each other refusal of the Updater keeps its own message, for example the message for a wrong @context. A signature has no effect before the announcement, so the api can discard it. update runs the guard before the derive step, before any chain read, and before any signature. The guard skips a source document with no method that can sign, and a patch that Updater.construct refuses. The Updater then names the cause.

The derive step of update uses only the capabilityInvocation methods that pass Updater.signingMethod, in the reference form and the embedded form. The messages are No capabilityInvocation method that can sign an update of DID <did> publishes the signer's key. and <n> capabilityInvocation methods that can sign an update of DID <did> publish the signer's key: <ids>. More text follows each message.

Reason: the api guard criterion (ADR 135). The api refuses a write only if the failure is permanent for the DID and the api already holds the data to find it. A lock-out is permanent, and the api holds the target document. A resolver refuses an update with another targetVersionId, and the api holds source.versionId.

10. The aggregation service reads the DID before the first ?, /, or #

AggregationService took the DID of an absolute proof id with split('#')[0]. Thus it refused a <did>?key=1 proof id that Updater.sign signs. It now uses split(/[?/#]/)[0]. A DID contains no ?, /, or #. A relative id (#initialKey) still passes this check, and the proof verification after it refuses the id, as the resolver does.

The JSDoc of genesisDocument in the participant and the participant runner gives the conditions of decision 4.

11. The test vectors do not change

This change does not regenerate the vectors. The pinned signed updates have no proof.invocationTarget. The resolver refuses such an update at the proof.invocationTarget check, before the new method check. Thus packages/api/lib/verify-scenarios.ts gives the same pass or fail result as before. The pinned n24 vector keeps the old patch until the next regeneration.

The generator changes:

The rules with signRefuses are update-context-mismatch, proof-method-unauthorized, proof-method-not-found, source-hash-mismatch, target-hash-mismatch, patch-apply-failure, document-id-mismatch, and document-not-conformant.

Alternatives

Consequences

Superseded.

Unchanged.

Implementation

References