From e551413237b52aa6c48f78f5603b14930955638d Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 5 Dec 2023 13:00:28 -0600 Subject: [PATCH] fix spec --- .web5-spec/credentials.ts | 41 +++++---------------------------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/.web5-spec/credentials.ts b/.web5-spec/credentials.ts index c2a2787d3..6cd58d55f 100644 --- a/.web5-spec/credentials.ts +++ b/.web5-spec/credentials.ts @@ -1,46 +1,22 @@ import { Request, Response } from 'express'; -import { VerifiableCredential, SignOptions } from '@web5/credentials'; -import { DidKeyMethod, PortableDid } from '@web5/dids'; -import { Ed25519, PrivateKeyJwk } from '@web5/crypto'; +import { VerifiableCredential } from '@web5/credentials'; +import { DidKeyMethod } from '@web5/dids'; import { paths } from './openapi.js'; -type Signer = (data: Uint8Array) => Promise; - -let _ownDid: PortableDid; - -async function getOwnDid(): Promise { - if(_ownDid) { - return _ownDid; - } - _ownDid = await DidKeyMethod.create(); - return _ownDid; -} - export async function credentialIssue(req: Request, res: Response) { const body: paths["/credentials/issue"]["post"]["requestBody"]["content"]["application/json"] = req.body; - const ownDid = await getOwnDid() - - // build signing options - const [signingKeyPair] = ownDid.keySet.verificationMethodKeys!; - const subjectIssuerDid = body.credential.credentialSubject["id"] as string; - const signer = EdDsaSigner(signingKeyPair.privateKeyJwk as PrivateKeyJwk); - const signOptions: SignOptions = { - issuerDid : ownDid.did, - subjectDid : subjectIssuerDid, - kid : '#' + ownDid.did.split(':')[2], - signer : signer - }; + const ownDid = await DidKeyMethod.create(); const vc: VerifiableCredential = VerifiableCredential.create({ type: body.credential.type[body.credential.type.length - 1], issuer: body.credential.issuer, - subject: subjectIssuerDid, + subject: body.credential.credentialSubject["id"] as string, data: body.credential.credentialSubject }); - const vcJwt: string = await vc.sign(signOptions); + const vcJwt: string = await vc.sign({did: ownDid}); const resp: paths["/credentials/issue"]["post"]["responses"]["200"]["content"]["application/json"] = { @@ -48,11 +24,4 @@ export async function credentialIssue(req: Request, res: Response) { }; res.json(resp); -} - -function EdDsaSigner(privateKey: PrivateKeyJwk): Signer { - return async (data: Uint8Array): Promise => { - const signature = await Ed25519.sign({ data, key: privateKey}); - return signature; - }; } \ No newline at end of file