-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
<issuer-instance>/credentials/<credentialId>
endpoint.
- Loading branch information
Showing
5 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
import {CapabilityAgent} from '@digitalbazaar/webkms-client'; | ||
import {createZcapClient} from './helpers.js'; | ||
|
||
export async function assertStoredCredential({ | ||
configId, credentialId, zcapClient, capability, expectedCredential} = {}) { | ||
const url = `${configId}/credentials/${encodeURIComponent(credentialId)}`; | ||
|
||
let error; | ||
let result; | ||
try { | ||
result = await zcapClient.read({url, capability}); | ||
} catch(e) { | ||
error = e; | ||
} | ||
assertNoError(error); | ||
should.exist(result.data); | ||
should.exist(result.data.verifiableCredential); | ||
result.data.verifiableCredential.should.deep.equal(expectedCredential); | ||
|
||
// fail to fetch using unauthorized party | ||
{ | ||
let error; | ||
let result; | ||
try { | ||
const secret = crypto.randomUUID(); | ||
const handle = 'test'; | ||
const capabilityAgent = await CapabilityAgent.fromSecret({ | ||
secret, handle | ||
}); | ||
const zcapClient = createZcapClient({capabilityAgent}); | ||
result = await zcapClient.read({url, capability}); | ||
} catch(e) { | ||
error = e; | ||
} | ||
should.not.exist(result); | ||
should.exist(error?.data?.name); | ||
error.status.should.equal(403); | ||
error.data.name.should.equal('NotAllowedError'); | ||
} | ||
} |