generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cbe8da
commit 342b3b3
Showing
12 changed files
with
331 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
web5 spec conformance report for {{ .TestServerID.Name }} ({{ .TestServerID.Url }}) | ||
|
||
{{ range $test, $result := .Results }} | ||
{{ range $groupName, $results := .Results }} | ||
{{ $groupName }} | ||
======================{{ range $test, $result := $results }} | ||
{{ $test }}: {{ if $result }}fail: {{ $result }}{{ else }}pass{{ end }}{{ end }} | ||
{{ end }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,62 @@ | ||
import { Request, Response } from 'express'; | ||
import { VcJwt, VerifiableCredential, SignOptions } from '@web5/credentials'; | ||
import { DidKeyMethod, PortableDid } from '@web5/dids'; | ||
import { Ed25519, Jose } from '@web5/crypto'; | ||
import { paths } from './openapi.js'; | ||
import { Request, Response } from "express"; | ||
import { VcJwt, VerifiableCredential, SignOptions, CreateVcOptions } from "@web5/credentials"; | ||
import { DidKeyMethod, PortableDid } from "@web5/dids"; | ||
import { Ed25519, Jose } from "@web5/crypto"; | ||
import { paths } from "./openapi.js"; | ||
|
||
type Signer = (data: Uint8Array) => Promise<Uint8Array>; | ||
|
||
let _ownDid: PortableDid; | ||
|
||
async function getOwnDid(): Promise<PortableDid> { | ||
if(_ownDid) { | ||
return _ownDid; | ||
} | ||
_ownDid = await DidKeyMethod.create(); | ||
if (_ownDid) { | ||
return _ownDid; | ||
} | ||
_ownDid = await DidKeyMethod.create(); | ||
return _ownDid; | ||
} | ||
|
||
export async function issueCredential(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 privateKey = (await Jose.jwkToKey({ key: signingKeyPair.privateKeyJwk!})).keyMaterial; | ||
const subjectIssuerDid = ownDid.did; | ||
const signer = EdDsaSigner(privateKey); | ||
const signOptions: SignOptions = { | ||
issuerDid : ownDid.did, | ||
subjectDid : ownDid.did, | ||
kid : '#' + ownDid.did.split(':')[2], | ||
signer : signer | ||
}; | ||
|
||
const vcJwt: VcJwt = await VerifiableCredential.create(signOptions); | ||
// const resp: paths["/credentials/issue"]["post"]["responses"]["200"]["content"]["application/json"] = { | ||
// verifiableCredential: { | ||
// }, | ||
// } | ||
res.json(vcJwt); | ||
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 privateKey = ( | ||
await Jose.jwkToKey({ key: signingKeyPair.privateKeyJwk! }) | ||
).keyMaterial; | ||
const subjectIssuerDid = ownDid.did; | ||
const signer = EdDsaSigner(privateKey); | ||
const signOptions: SignOptions = { | ||
issuerDid: ownDid.did, | ||
subjectDid: ownDid.did, | ||
kid: "#" + ownDid.did.split(":")[2], | ||
signer: signer, | ||
}; | ||
|
||
const createVcOptions: CreateVcOptions = { | ||
credentialSubject: { id: "???" }, | ||
issuer: { id: "issuer??" }, | ||
}; | ||
|
||
const vcJwt: VcJwt = await VerifiableCredential.create( | ||
signOptions, | ||
createVcOptions | ||
); | ||
|
||
// const resp: paths["/credentials/issue"]["post"]["responses"]["200"]["content"]["application/json"] = { | ||
// verifiableCredential: { | ||
// }, | ||
// } | ||
|
||
res.json(vcJwt); | ||
} | ||
|
||
function EdDsaSigner(privateKey: Uint8Array): Signer { | ||
return async (data: Uint8Array): Promise<Uint8Array> => { | ||
const signature = await Ed25519.sign({ data, key: privateKey}); | ||
return signature; | ||
}; | ||
} | ||
return async (data: Uint8Array): Promise<Uint8Array> => { | ||
const signature = await Ed25519.sign({ data, key: privateKey }); | ||
return signature; | ||
}; | ||
} |
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,17 @@ | ||
import { DidIonMethod } from "@web5/dids"; | ||
import { paths } from "./openapi.js"; | ||
import { Request, Response } from "express"; | ||
|
||
|
||
export async function didIonCreate(req: Request, res: Response) { | ||
// const body: paths["/did-ion/create"]["post"]["requestBody"]["content"]["application/json"] = | ||
// req.body; | ||
const did = await DidIonMethod.create({}); | ||
|
||
const resp: paths["/did-ion/create"]["post"]["responses"]["200"]["content"]["application/json"] = | ||
{ | ||
did: did.did, | ||
}; | ||
|
||
res.json(resp); | ||
} |
Oops, something went wrong.