-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: PatStLouis <[email protected]>
- Loading branch information
1 parent
cfc1914
commit 6996312
Showing
5 changed files
with
142 additions
and
53 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,29 @@ | ||
import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey'; | ||
import {decodeSecretKeySeed} from 'bnid'; | ||
import {Ed25519Signature2020} from '@digitalbazaar/ed25519-signature-2020'; | ||
import {ZcapClient} from '@digitalbazaar/ezcap'; | ||
|
||
export async function makeZcapRequest(settings, body) { | ||
const capability = JSON.parse(settings.zcap.capability); | ||
const controller = capability.controller; | ||
// only supports did key | ||
const id = controller + '#' + controller.slice('did:key:'.length); | ||
const verificationKeyPair = await Ed25519Multikey.generate({ | ||
id, | ||
controller, | ||
seed: decodeSecretKeySeed({ | ||
secretKeySeed: process.env[settings.zcap.keySeed] | ||
}) | ||
}); | ||
const zcapClient = new ZcapClient({ | ||
SuiteClass: Ed25519Signature2020, | ||
invocationSigner: verificationKeyPair.signer(), | ||
delegationSigner: verificationKeyPair.signer(), | ||
}); | ||
const response = await zcapClient.write({ | ||
url: settings.endpoint, | ||
json: body, | ||
capability: JSON.parse(settings.zcap.capability) | ||
}); | ||
return response; | ||
} |