Skip to content

Should this library throw errors from the did:key spec? #46

Description

@aljones15

The did:key spec now contains multiple normative statements about did:key. While we do throw many errors related to those statements, we don't throw them in a way that conforms to the spec.

I'm proposing that checks that can be made at the general level of any did:key be made here and then checks related to key material be made in their respective libraries.

That means the following checks need to be made in this library:

  • MUST raise invalidDid error if scheme is not did (NOTE: this check might be needed elsewhere)
  • MUST raise invalidDid error if method is not key (this check is did:key specific)
  • MUST raise invalidDid if version is not convertible to a positive integer value.
  • MUST raise invalidDid if the multibaseValue does not begin with the letter z.

The errors might be specific to the didResolver:

  • If "didDocument.id" is not a valid DID, an invalidDid error MUST be raised
  • If verificationMethod.id is not a valid DID URL, an invalidDidUrl error MUST be raised.
  • For Signature Verification Methods, if options.enableExperimentalPublicKeyTypes is set to false and publicKeyFormat is not Multikey, JsonWebKey2020, or Ed25519VerificationKey2020, an invalidPublicKeyType error MUST be raised.
  • For Encryption Verification Methods, if options.enableExperimentalPublicKeyTypes is set to false and publicKeyFormat is not Multikey, JsonWebKey2020, or X25519KeyAgreementKey2020, an invalidPublicKeyType error MUST be raised.
  • If verificationMethod.controller is not a valid DID, an invalidDid error MUST be raised.

We can throw an error like this:

export class InvalidDid extends Error {
  constructor(message) {
    super(message);
    this.name = 'InvalidDidError';
    this.code = 'invalidDid';
  }
}

export class InvalidDidUrl extends Error {
  constructor(message) {
    super(message);
    this.name = 'InvalidDidUrlError';
    this.code = 'invalidDidUrl';
  }
}

Related:
digitalbazaar/ed25519-verification-key-2020#18
w3c-ccg/did-key-spec#60

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions