did-btcr2-js

ADR 129: defaults.cas, One CAS Endpoint for All Networks

Context

The config file of the CLI held the CAS values only in a profile cas block. A user with one IPFS node for all networks had to repeat the URL, the user, and the password in each profile. The environment variable BTCR2_CAS_GATEWAY gave one gateway for all networks, but it had two limits:

  1. It is not in the config file, so config list does not show it.
  2. The environment layer wins over the profile layer, so a profile cannot set another gateway.

The CLI also merged the CAS gateway and the CAS RPC URL as two separate values. The api uses the RPC URL if one is set (rpcUrl wins over gateway). So an RPC URL from a lower layer won over a gateway from a higher layer. For example, --cas-gateway had no effect if the profile set cas.rpcUrl. A shared layer below the profile makes this problem larger: a profile cas.gateway would have no effect under a shared RPC URL.

CAS data does not belong to one network. A content identifier addresses the same bytes on each network.

Decision

The config file has a defaults.cas block.

Layer Example
Flag --cas-rpc-url, --cas-gateway, --cas-rpc-user, --cas-timeout
Environment BTCR2_CAS_RPC_URL, BTCR2_CAS_GATEWAY, BTCR2_CAS_RPC_USER, BTCR2_CAS_RPC_PASS, BTCR2_CAS_TIMEOUT
Profile profiles.<name>.cas.*
Config defaults defaults.cas.*
Built-in the gateway https://trustless-gateway.link, the timeout 30000 ms

The CAS endpoint is one unit. The highest layer that sets gateway or rpcUrl gives the gateway, the RPC URL, the RPC user, and the RPC password. A lower layer adds no endpoint value. In that layer, the RPC URL wins over the gateway, as in the api.

There is no defaults.btc. A Bitcoin endpoint serves the chain of one network. The same Esplora or Bitcoin Core URL for two networks is a configuration error.

Alternatives

Consequences

Positive. One IPFS node serves each network from one entry in the config file. A profile can replace the endpoint of defaults.cas with its own gateway or RPC URL, and the replacement always has an effect. config effective and config doctor show the resolved endpoint.

Negative. A flag or an environment gateway now wins over an RPC URL of a lower layer. Before this ADR, the RPC URL won. So BTCR2_CAS_GATEWAY together with a profile cas.rpcUrl now reads through the gateway, and --publish-to-cas always fails. Use defaults.cas.gateway for a shared gateway instead. The provenance file does not tell the profile from defaults.cas.

Tests. The cli tests cover defaults.cas on each network, the gateway and the timeout of defaults.cas, a profile URL without the credentials of defaults.cas, a profile value for each key, a blank profile value, the environment and the flag over defaults.cas, a profile gateway over a defaults.cas URL, a flag gateway over a profile URL, the gateway and the URL of one layer, incomplete credentials in defaults.cas, no change to a Bitcoin value, config set and config validate of the keys, and config effective with redaction.