-
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
Changes from 5 commits
e7f822d
ee0ce1f
98e5ee4
2625a46
fe91c18
86cc7d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -76,7 +76,7 @@ describe('did:key method driver', () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
describe('generate', async () => { | ||||||
describe('generate', () => { | ||||||
it('should generate and get round trip', async () => { | ||||||
const { | ||||||
didDocument, keyPairs, methodFor | ||||||
|
@@ -98,7 +98,52 @@ describe('did:key method driver', () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
describe('computeId', async () => { | ||||||
describe('publicMethodFor', () => { | ||||||
mattcollier marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
it('should find a key for a did doc and purpose', async () => { | ||||||
const did = 'did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH'; | ||||||
// First, get the did document | ||||||
const didDocument = await didKeyDriver.get({did}); | ||||||
// Then publicMethodFor can be used to fetch key data | ||||||
const keyAgreementData = didKeyDriver.publicMethodFor({ | ||||||
didDocument, purpose: 'keyAgreement' | ||||||
}); | ||||||
expect(keyAgreementData).to.have | ||||||
.property('type', 'X25519KeyAgreementKey2020'); | ||||||
expect(keyAgreementData).to.have | ||||||
.property('publicKeyMultibase', | ||||||
'zJhNWeSVLMYccCk7iopQW4guaSJTojqpMEELgSLhKwRr'); | ||||||
|
||||||
const authKeyData = didKeyDriver.publicMethodFor({ | ||||||
didDocument, purpose: 'authentication' | ||||||
}); | ||||||
expect(authKeyData).to.have | ||||||
.property('type', 'Ed25519VerificationKey2020'); | ||||||
expect(authKeyData).to.have | ||||||
.property('publicKeyMultibase', | ||||||
'zB12NYF8RrR3h41TDCTJojY59usg3mbtbjnFs7Eud1Y6u'); | ||||||
}); | ||||||
|
||||||
it('should throw error if key is not found for purpose', async () => { | ||||||
const did = 'did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH'; | ||||||
// First, get the did document | ||||||
const didDocument = await didKeyDriver.get({did}); | ||||||
|
||||||
let error; | ||||||
try { | ||||||
didKeyDriver.publicMethodFor({ | ||||||
didDocument, purpose: 'invalidPurpose' | ||||||
}); | ||||||
} catch(e) { | ||||||
error = e; | ||||||
} | ||||||
|
||||||
expect(error).to.be.exist; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops. |
||||||
expect(error.message).to | ||||||
.match(/No verification method found for purpose/); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can avoid regex with |
||||||
}); | ||||||
}); | ||||||
|
||||||
describe('computeId', () => { | ||||||
const keyPair = {fingerprint: () => '12345'}; | ||||||
|
||||||
it('should set the key id based on fingerprint', 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.
This needs updating now.