did-btcr2-js

ADR 150: The Api Refuses an Unknown publishToCas Value, and Each Option Refusal Has the Type INVALID_OPTIONS

Context

The api did not check the publishToCas value

announce.publishToCas selects the CAS publication policy of an update (ADR 071, ADR 073). The type PublishToCasMode has three values: 'never', 'auto', and 'always'. The default is 'never', so CAS publication is opt-in (ADR 073, decision 1).

The type does not apply at run time. A caller without the TypeScript types can give any value, for example a value from a JSON configuration file. The default of DidMethodApi.update applies only to undefined. #planCasPublication stopped the publication only for the string 'never'. Thus each other value acted as 'auto'.

The api checked announce.feeRate at run time, but not announce.publishToCas. The cli is not affected, because it refuses another --publish-to-cas value at parse time.

Two failure modes

  1. With a writable CAS, a value such as null or 'Never' published the signed update before the broadcast. For a CAS beacon, it also published the CAS Announcement. A CAS publication is permanent: the controller cannot remove the update from the CAS.
  2. With a read-only CAS, a typo of 'always' such as 'Always' skipped the publication silently. Then the update spent the beacon UTXO. The caller asked for a guarantee that the update reached the CAS (ADR 073, decision 3), and did not get it.

Examples

publishToCas CAS Before After
null, 'Never', 'none', false, 0 writable The api publishes the signed update, then broadcasts. UpdateError of type INVALID_OPTIONS, before any I/O
'Always', 'always ' read-only The api skips the publication, then broadcasts. UpdateError of type INVALID_OPTIONS, before any I/O
undefined any No publication (the default 'never') No change
'never', 'auto', 'always' any The policy of ADR 073 No change

The specification texts for the publication

The specification does not define the api options. These texts apply to a CAS publication:

The SHOULD texts apply to the DID controller, not to the implementation. The default 'never' lets the controller obey them. A value that the api did not check took this choice away from the controller.

The specification texts for the error type

Before this change, four other option refusals of the write path had the type INVALID_DID_UPDATE:

The resolver already uses INVALID_OPTIONS for a resolution option that is not valid, for example minConf, versionId, and versionTime.

Decision

1. The api refuses each other value

DidMethodApi.update refuses a publishToCas value other than 'never', 'auto', and 'always'. undefined still gives the default 'never'. The api does not normalize a value, for example 'Never' to 'never'. Thus the api does not guess a policy for the caller.

2. The check runs first in update()

The publishToCas check is the first check of update(). It runs before the feeRate checks and before the check of a deactivated source document. Thus the api refuses the value before any read, signature, CAS publication, or broadcast.

The other write paths call update():

3. The message does not hold the value

The message is `announce.publishToCas` must be 'never', 'auto', or 'always'.. data.publishToCas holds the value. String() throws a TypeError for an object without a prototype, so the message does not hold the value. The feeRate message still holds String(feeRate). This change does not change that message.

4. Each option refusal has the type INVALID_OPTIONS

The new refusal and the four other option refusals of the write path are an UpdateError of type INVALID_OPTIONS. An api option is not a part of a BTCR2 Update or of a DID document. INVALID_DID_UPDATE refines INVALID_DID_DOCUMENT, which DID Resolution defines for a malformed DID document, with the status code 500. INVALID_OPTIONS names options that are not valid, with the status code 400. The caller gave the wrong value, so the code 400 fits.

The other refusals of the write path keep the type INVALID_DID_UPDATE. Examples are a deactivated source document (ADR 100), an update after which no method can sign an update (ADR 147), the derivation of the method and the beacon, the funding check, and the network mismatch.

5. Each judgment call conforms to the specification texts

Judgment call Text Result
The api refuses the value. It does not normalize the value. Privacy Considerations: updates are “NOT REQUIRED to be public”. Conforms. A refusal publishes nothing. The specification does not define the api options.
An api option refusal has the type INVALID_OPTIONS. DID Resolution: INVALID_OPTIONS for options that “are invalid”. Errors: INVALID_DID_UPDATE refines INVALID_DID_DOCUMENT. Conforms. The specification names no error for an update option. INVALID_OPTIONS has the nearest meaning.
updateDid with a DID resolves before the check. The specification gives no order for the api checks. Conforms. A resolution publishes nothing.

Alternatives

Consequences

Unchanged.

Implementation

References