Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aljones15 opened this issue Aug 1, 2022 · 0 comments
Open

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

aljones15 opened this issue Aug 1, 2022 · 0 comments
Assignees

Comments

@aljones15
Copy link

aljones15 commented Aug 1, 2022

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-method-key#60

@aljones15 aljones15 changed the title Should this library throw errors from the did:key spec Should this library throw errors from the did:key spec? Aug 1, 2022
@aljones15 aljones15 self-assigned this Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant