Skip to content

Commit 0ed2bd1

Browse files
committed
feature: added toolbox and consolidated logic
1 parent e0d0e56 commit 0ed2bd1

331 files changed

Lines changed: 352815 additions & 7843 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 12765 additions & 3469 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
"@aws-sdk/lib-dynamodb": "^3.1004.0",
3333
"@grpc/grpc-js": "^1.14.3",
3434
"@grpc/proto-loader": "^0.8.0",
35-
"@veramo/core": "^7.0.0",
36-
"@veramo/credential-w3c": "^7.0.0",
37-
"@veramo/did-manager": "^7.0.0",
38-
"@veramo/did-provider-key": "^7.0.0",
39-
"@veramo/did-resolver": "^7.0.0",
40-
"@veramo/key-manager": "^7.0.0",
41-
"@veramo/kms-local": "^7.0.0",
35+
"@veramo/core": "^6.0.0",
36+
"@veramo/credential-w3c": "^6.0.0",
37+
"@veramo/did-manager": "^6.0.0",
38+
"@veramo/did-provider-key": "^6.0.0",
39+
"@veramo/did-resolver": "^6.0.0",
40+
"@veramo/key-manager": "^6.0.0",
41+
"@veramo/kms-local": "^6.0.0",
4242
"ajv-draft-04": "^1.0.0",
4343
"ajv-formats": "^3.0.1",
4444
"aws-cdk-lib": "^2.241.0",

services/learner-context-handler/src/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import {
88
QueryCommand
99
} from "@aws-sdk/lib-dynamodb";
1010
import {
11-
createPresentationFromSelection,
12-
verifyPresentation,
11+
createToolbox,
1312
type PresentationMetadata,
1413
type SelectedClaim,
1514
type SelectedCredential
16-
} from "../../../packages/veramo-wrapper/src/index.js";
15+
} from "../../../toolbox/src/index.js";
1716

1817
const ddbDocClient = DynamoDBDocumentClient.from(new DynamoDBClient({}));
1918
const EVENT_TABLE = process.env.EVENT_TABLE_NAME ?? "";
2019
const CREDENTIAL_TABLE = process.env.CREDENTIAL_TABLE_NAME ?? "";
2120
const GRAPH_PROJECTION_TABLE = process.env.GRAPH_PROJECTION_TABLE_NAME ?? "";
2221
const TRUSTED_ISSUERS = (process.env.TRUSTED_ISSUERS ?? "").split(",").map((issuer) => issuer.trim()).filter(Boolean);
22+
let toolboxPromise: Promise<Awaited<ReturnType<typeof createToolbox>>> | undefined;
2323

2424
interface HttpEvent {
2525
rawPath?: string;
@@ -398,7 +398,8 @@ async function handleCreatePresentation(event: HttpEvent) {
398398
expirationDate: request.expirationDate
399399
};
400400

401-
const vp = createPresentationFromSelection(policyOutcome.allowedCredentials, metadata);
401+
const toolbox = await getToolbox();
402+
const vp = toolbox.presentation.createFromSelection(policyOutcome.allowedCredentials, metadata);
402403

403404
return json(200, {
404405
status: "created",
@@ -421,7 +422,8 @@ async function handleVerifyPresentation(event: HttpEvent) {
421422
});
422423
}
423424

424-
const result = verifyPresentation(request.vp, TRUSTED_ISSUERS);
425+
const toolbox = await getToolbox();
426+
const result = toolbox.presentation.verify(request.vp, TRUSTED_ISSUERS);
425427
const approvedContent = result.approvedContent.map((credential) => ({
426428
sessionId: `verified_${credential.credentialId}`,
427429
credentialId: credential.credentialId,
@@ -781,3 +783,13 @@ function json(statusCode: number, payload: Record<string, unknown>) {
781783
body: JSON.stringify(payload)
782784
};
783785
}
786+
787+
async function getToolbox(): Promise<Awaited<ReturnType<typeof createToolbox>>> {
788+
if (!toolboxPromise) {
789+
toolboxPromise = createToolbox({
790+
did: { method: "did:key" },
791+
validation: { strict: true }
792+
});
793+
}
794+
return toolboxPromise;
795+
}

services/persist-handler/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { createHash } from "node:crypto";
33
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
44
import { DynamoDBDocumentClient, PutCommand, UpdateCommand } from "@aws-sdk/lib-dynamodb";
55
import type { SQSEvent } from "aws-lambda";
6-
import { createToolbox } from "../../../toolbox/index.js";
7-
import type { CaliperEvent } from "../../../toolbox/index.js";
6+
import { createToolbox } from "../../../toolbox/src/index.js";
7+
import type { CaliperEvent } from "../../../toolbox/src/index.js";
88
import {
99
buildCredentialItem,
1010
buildEventItems,
@@ -311,7 +311,6 @@ async function buildProjectedCredentialPayload(input: {
311311
graphDigest: sourceEventHashes.join(",")
312312
});
313313
const signed = await toolbox.caliper.sign(unsigned);
314-
315314
if (signed.verifiableCredential && typeof signed.verifiableCredential === "object") {
316315
return signed.verifiableCredential;
317316
}

toolbox/README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Credential Toolbox SDK
2+
3+
TypeScript SDK for creating, signing, verifying, and transporting digital credentials across:
4+
5+
- W3C Verifiable Credentials
6+
- Open Badges 3
7+
- Comprehensive Learner Record 2
8+
- Caliper Credential (Caliper v1.2 event-set VC)
9+
- DID methods (`did:key`, locally configured `did:web`)
10+
11+
## Install
12+
13+
```bash
14+
npm install
15+
```
16+
17+
## Build And Validate
18+
19+
```bash
20+
npm run build
21+
npm run typecheck
22+
npm run lint
23+
npm run test
24+
```
25+
26+
## Example Commands
27+
28+
```bash
29+
npm run example:export-validator -- --type=ob3 --format=jwt
30+
npm run example:export-validator:clr2
31+
npm run example:export-validator:caliper
32+
npm run example:caliper-rich
33+
```
34+
35+
## Verify A Credential File
36+
37+
Use the Veramo-backed helper to verify credential files produced by this project (JWT text, SDK `SignedCredential` JSON, or validator-style VC JSON):
38+
39+
```ts
40+
import { verifyCredentialFile } from "@credential-toolbox/sdk";
41+
42+
const result = await verifyCredentialFile({
43+
credentialPath: "examples/export-validator/output/caliper.jwt.txt"
44+
});
45+
46+
console.log(result.format); // jwt | signed | verifiableCredential
47+
console.log(result.verification.valid);
48+
```
49+
50+
Or via npm script:
51+
52+
```bash
53+
npm run verify:credential -- --file=examples/export-validator/output/caliper.jwt.txt
54+
```
55+
56+
## Architecture Contract
57+
58+
This repository is a **single library** that uses DDD + Clean Architecture with explicit layers:
59+
60+
```text
61+
src/
62+
domain/
63+
application/
64+
infrastructure/
65+
interface/
66+
```
67+
68+
### Layer Responsibilities
69+
70+
- `src/domain`: core types, entities/value objects, service interfaces, no framework dependencies
71+
- `src/application`: use-case orchestration and bounded-context services (`ob3`, `clr2`, transport)
72+
- `src/infrastructure`: external adapters (Veramo, DID/crypto integration)
73+
- `src/interface`: public SDK composition and entrypoints (`createToolbox`)
74+
75+
### Dependency Rules (Must Keep)
76+
77+
- Domain must not import infrastructure or Veramo
78+
- Application depends on domain contracts only
79+
- Infrastructure implements domain/application interfaces
80+
- Interface composes services and exposes stable API
81+
82+
## Veramo Boundary
83+
84+
Veramo must remain isolated in:
85+
86+
- `src/infrastructure/veramo`
87+
88+
Do not import Veramo types or plugins into `domain`, `application`, or `interface`.
89+
90+
## Public API
91+
92+
```ts
93+
import { createToolbox } from "@credential-toolbox/sdk";
94+
95+
const toolbox = await createToolbox({
96+
did: {
97+
method: "did:web",
98+
defaultDomain: "example.org",
99+
webPath: "issuers/main"
100+
}
101+
});
102+
103+
const issuer = await toolbox.did.create({ method: "web" });
104+
```
105+
106+
## Contributor Guidance
107+
108+
When adding features:
109+
110+
1. Start with domain contracts
111+
2. Implement orchestration in application services
112+
3. Add or extend infrastructure adapters
113+
4. Wire through interface layer only
114+
115+
If a change breaks these boundaries, redesign the change instead of bypassing the architecture.

toolbox/assets/Untitled

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tim.couper+badgedesign@gmail.com
36 KB
Loading

toolbox/assets/sample_badgetemplate.svg

Lines changed: 186 additions & 0 deletions
Loading
16.7 KB
Loading
Lines changed: 12 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)