did-btcr2-js

ADR 159: Three Packages Get New Names That Start at 0.1.0: common Becomes std, cryptosuite Becomes integrity, and keypair Becomes keys

Context

Two packages have high major numbers

@did-btcr2/common went above 1.0 before its API was stable. After that, each break of its API gave a new major version. @did-btcr2/cryptosuite followed the same path. Both packages are now at 11.0.0. The other eight packages are 0.x, for example @did-btcr2/keypair 0.13.3 and @did-btcr2/method 0.74.0.

npm never accepts a version number a second time. Semver orders 11.0.0 above each 0.x version. Thus a range such as * and an update tool take 11.0.0 in place of a later 0.x release. The only path back to 0.x is a new package name.

Three names do not tell what the package holds

The other packages have short names that tell their content: smt, bitcoin, key-manager, method, aggregation, api, and cli. The name common tells only that other packages use the package. The name cryptosuite names one part of its package: the package also holds BIP340DataIntegrityProof and SchnorrMultikey. The name keypair names one kind of class. The package also holds public keys, secret keys, and signers.

A dependent takes the classes of the renamed packages

bitcoin, key-manager, method, aggregation, and api take, return, throw, or re-export classes of the three packages. A class of an old package and the class of the same name in a new package are two classes. A consumer can thus get a mix of old and new classes if a dependent moves to a new package in a PATCH release.

Decision

1. The new names

The code, the exports, the error types, and the result shapes do not change. Each export keeps its name. The std description in package.json is “Shared types, errors, JCS canonicalization, hashing, and JSON Patch for the did-btcr2-js packages.”

2. The directories move

git mv moves packages/common to packages/std, packages/cryptosuite to packages/integrity, and packages/keypair to packages/keys. The move holds 87 tracked files: 28 in std, 36 in integrity, and 23 in keys. Git keeps the history of each file. Each of the 10 package directories thus has the short name of its package. pnpm --filter std and the package list of scripts/coverage-report.mjs need no name map.

The move does not keep dead files under a new name:

3. Each new name starts at 0.1.0

4. Each new package starts a new CHANGELOG

The rename deletes the moved CHANGELOG.md of each package. The changeset writes a new file with the header # @did-btcr2/std (or integrity, or keys) and the entry ## 0.1.0. The entry links the old file at commit 9c260b13, for example https://github.com/dcdpr/did-btcr2-js/blob/9c260b13/packages/common/CHANGELOG.md. Thus each name has one history, and the old record stays available.

5. No shim, no alias package, no re-export of the old names

No package re-exports @did-btcr2/common, @did-btcr2/cryptosuite, or @did-btcr2/keypair. No new version of an old name re-exports a new package. A consumer changes its imports. The READMEs do not name the old packages. The CHANGELOG entry, this ADR, and the npm deprecation text hold the link from the old name to the new name.

6. Each dependent gets a MINOR release

The change is a break of each dependent, because the identity of each class from a renamed package changes:

  1. instanceof gives false between an old class and a new class. For example, a std ResolveError is not instanceof the common DidMethodError.
  2. TypeScript refuses an old class in place of a new class if the class has a #private member (TS2322). These classes are the key classes of keys and the SchnorrMultikey of integrity. The std error classes have no #private member, so TypeScript accepts them.
  3. Published code reads the class. The resolutionErrorCode function of api 0.36.0 gives INVALID_DID for a common ResolveError of the type INVALID_DID. It gives INTERNAL_ERROR for a std ResolveError of the same type.

A PATCH release puts the break into old installs. For example, api 0.36.0 needs @did-btcr2/method ^0.74.0. A method 0.74.1 on std throws a std ResolveError, and api 0.36.0 then reports INTERNAL_ERROR in place of the real error type. A MINOR release of a 0.x package is outside the range ^0.y.z, so an old install keeps the old graph.

The new versions are: bitcoin 0.12.0, key-manager 0.8.0, method 0.75.0, aggregation 0.9.0, and api 0.37.0. bitcoin uses only std. Its declarations use only the std type aliases Bytes and UnixTimestamp. But it throws the std MethodError, so a caller gets a new error class.

7. The cli version follows its command surface

The cli gets a PATCH release (0.29.11). The cli library exports CLIError. CLIError extends the DidMethodError that the api exports, and that class is the std class. By the rule of decision 6, this is a break of the cli library surface. PATCH is still the lowest viable bump:

  1. No published package depends on the cli, so no caret range can pull a new cli into an old graph.
  2. The cli version follows its command surface: the commands, the flags, and the output. The rename changes none of them.
  3. cli 0.29.7 to 0.29.10 got PATCH releases for the api MINOR releases 0.33.0 to 0.36.0. For example, api 0.36.0 changed didResolutionMetadata.error of DidResolutionResult to an error object, and the cli type CommandResult exports DidResolutionResult by reference.

8. The old names get a deprecation after the publish

After the first publish of the new names, each old name gets npm deprecate for all its versions. The text names the new package, for example: “Renamed to @did-btcr2/std. Install @did-btcr2/std. This package gets no new versions.” The old versions stay available. An install of an old version prints the text. ADR 004 used the same step for the @did-btc1 scope.

9. The lockfile keeps each resolution

10. Concept names stay

The rename changes package names only. A name of a specification concept or a crypto concept stays:

11. Each judgment call conforms to the specification texts

The did:btcr2 specification does not name the packages of an implementation, so no decision of this ADR depends on a specification text.

Alternatives

Merge common into keypair. Rejected. keypair then holds DID error types, JCS, and JSON Patch, so its scope is a mix. bitcoin then depends on a key package that it does not use. cryptosuite stays at 11.0.0.

The same name, with a 0.x release after 11.0.0. Rejected. Semver orders 11.0.0 above each 0.x version, so a range such as * and an update tool take 11.0.0 in place of the 0.x release.

Keep the high major numbers. Rejected. This is correct semver and needs no change. But the major number grows with each break, and the names stay unlike the other names.

Continue the version numbers, as ADR 004 did for the scope rename (@did-btc1/common@1.1.0 to @did-btcr2/common@2.0.0). Rejected. std then starts at 12.0.0, and the high major numbers stay.

Keep the directory names. Rejected. Three of the 10 directories then have names that are not the names of their packages. pnpm --filter common no longer matches a package, and the coverage report needs a name map.

Keep the old CHANGELOG under the new header. Rejected. changesets puts ## 0.1.0 above ## 11.0.0, so the std file lists 9 versions (9.2.0 to 11.0.0) that std never had.

Keep the old CHANGELOG as HISTORY.md next to a new CHANGELOG.md. Rejected. One of the two files is then a legacy file, and the link of decision 4 gives the same record.

"version": "0.1.0" in each new package.json and no changeset entry. Rejected. A later minor changeset then gives std 0.2.0 before the first publish. A std release gives keys 0.1.1. The new CHANGELOG gets no ## 0.1.0 entry.

An alias package or a shim under each old name. Rejected. It keeps two names for one class and hides the rename. ADR 004 made the same choice for the @did-btc1 scope.

PATCH for the dependents. Rejected. Caret ranges pull a PATCH into old installs, and old and new classes then mix (decision 6).

MINOR for the cli. Rejected. No package depends on the cli, and the rename does not change its command surface (decision 7).

A plain pnpm install in place of the lockfile edit. Rejected. It changes the versions of eslint, rimraf, and typescript-eslint in a commit that must change only names.

No sort step for the lockfile. Rejected. The reorder then goes into the diff of an unrelated later change.

Consequences

Superseded.

Unchanged.

Implementation

References