-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implement a publicMethodFor() helper function. #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how useful this is to devs (not having contact with this code in a while). I'm presuming people are needing this ... in which case I approve.
test/driver.spec.js
Outdated
'zB12NYF8RrR3h41TDCTJojY59usg3mbtbjnFs7Eud1Y6u'); | ||
}); | ||
|
||
it('should return undefined if key is not found for purpose', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return a NotFoundError? Otherwise the consumer of this API has the null check the response right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an error seemed too drastic of a response (since not having a key in a did document for a given purpose is a normal condition). I could add that, if you feel strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think an error would be better. I'm having difficulty imagining how returning undefined
does not lead to an error anyhow. Likely the typical cannot access foo of undefined
error.
Did you have some specific use pattern in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattcollier Np; changed to throw error when not found. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question about return value of publicMethodFor
0d8a56e
to
fe91c18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, just a few more nits.
test/driver.spec.js
Outdated
error = e; | ||
} | ||
|
||
expect(error).to.be.exist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(error).to.be.exist; | |
expect(error).to.exist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops.
test/driver.spec.js
Outdated
|
||
expect(error).to.be.exist; | ||
expect(error.message).to | ||
.match(/No verification method found for purpose/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can avoid regex with .to.contain()
lib/DidKeyDriver.js
Outdated
* @returns {object} Returns the public key object (obtained from the DID | ||
* Document), without a `@context`. Returns undefined if no key is found | ||
* for that purpose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs updating now.
@mattcollier Thanks for the catch; all updated. |
This PR adds a convenience function that can be used in conjunction with a
.get()
to start with adid:key
DID, and end up with a key for a specific purpose.For example,
This addition matches the convenience
methodFor
function that gets returned withgenerate()
. The main difference is -- since it's returned bygenerate()
,methodFor
has access to the private key material (and so, can be used for decryption, signing, etc).Whereas
publicMethodFor
only has access to the public key material (extracted from the DID Document), and is useful by consumers that need those keys for verification and encryption (to a known DID recipient).