Skip to content

Commit

Permalink
Add more structure to the test list
Browse files Browse the repository at this point in the history
  • Loading branch information
finn-block committed Oct 16, 2023
1 parent 6cbe8da commit 342b3b3
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 84 deletions.
12 changes: 9 additions & 3 deletions cmd/web5-spec-test/report-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

SDK: [{{ .TestServerID.Name }}]({{ .TestServerID.Url }}) ({{ .TestServerID.Language }})

| Test | Pass | Details |
| ---- | ---- | ------- |{{ range $test, $result := .Results }}
| `{{ $test }}` | {{ if $result }}:x: | ```{{ $result }}```{{ else }}:heavy_check_mark: |{{ end }} |{{ end }}
{{ range $groupName, $results := .Results }}

## {{ $groupName }}

| Feature | Result |
| ------- | ------ |{{ range $test, $result := $results }}
| {{ $test }} | {{ if $result }}:x: {{ $result }}{{ else }}:heavy_check_mark:{{ end }} |{{ end }}

{{ end }}
5 changes: 4 additions & 1 deletion cmd/web5-spec-test/report-template.txt
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 }}
2 changes: 1 addition & 1 deletion cmd/web5-spec-test/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var templates = template.Must(template.New("").ParseFS(reportTemplateFS, "report

type Report struct {
TestServerID openapi.TestServerID
Results map[string]error
Results map[string]map[string]error
}

func (r Report) IsPassing() bool {
Expand Down
16 changes: 16 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ info:
title: web5 SDK test server
version: 0.1.0
paths:
/did-ion/create:
post:
operationId: did_ion_create
responses:
"200":
content:
application/json:
schema:
$ref: "#/components/schemas/DIDIonCreateResponse"
/credentials/issue:
post:
operationId: credential_issue
Expand Down Expand Up @@ -198,3 +207,10 @@ components:
type: string
url:
type: string
DIDIonCreateResponse:
type: object
required:
- did
properties:
did:
type: string
107 changes: 107 additions & 0 deletions openapi/openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 50 additions & 37 deletions sdks/web5-js/credentials.ts
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;
};
}
17 changes: 17 additions & 0 deletions sdks/web5-js/did-ion.ts
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);
}
Loading

0 comments on commit 342b3b3

Please sign in to comment.