Skip to content

Commit

Permalink
feat(schemas): adds ceramic schemas and scripts
Browse files Browse the repository at this point in the history
- add [email protected] to the root package.json

[passportxyz#36]
  • Loading branch information
farque65 authored and shavinac committed May 9, 2022
1 parent aa26ab6 commit e57ebdc
Show file tree
Hide file tree
Showing 13 changed files with 5,134 additions and 161 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
},
"resolutions": {
"csstype": "3.0.10",
"**/@types/react": "17.0.2"
"**/@types/react": "17.0.2",
"leveldown": "6.1.1"
}
}
37 changes: 37 additions & 0 deletions schemas/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# ceramic
.pinning.store

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.eslintcache

npm-debug.log*
yarn-debug.log*
yarn-error.log*
33 changes: 32 additions & 1 deletion schemas/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
# Ceramic Schemas and Data Models
# Glaze demo app

Example Web app using [Glaze libraries](https://developers.ceramic.network/tools/glaze/overview/).

## Setup

1. Install dependencies using `yarn install`
1. Start a local Ceramic node using `yarn ceramic`
1. Publish the model to your Ceramic node with `yarn publish-model`

## Scripts

In the project directory, you can run:

### `yarn start`

Runs the app in the development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

### `yarn build`

Builds the app for production to the `build` folder.

### `yarn create-model`

Runs the `create-model.mjs` script.
This is only needed to make changes to the model used by the app.
A hex-encoded 32-byte `SEED` environment variable must be present to create a key DID for the model when running the script.

## License

Apache-2.0 OR MIT
43 changes: 43 additions & 0 deletions schemas/models/Passports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Passport",
"description": "User Passport storing stamps",
"type": "object",
"properties": {
"issuanceDate": {
"type": "string",
"format": "date-time",
"title": "issuanceDate",
"maxLength": 30
},
"expiryDate": {
"type": "string",
"format": "date-time",
"title": "dateUpdated",
"maxLength": 30
},
"stamps": {
"type": "array",
"title": "stamps",
"items": {
"type": "object",
"title": "stampItem",
"properties": {
"provider": {
"type": "string"
},
"credential": {
"$ref": "#/definitions/VerifiableCredential"
}
}
}
}
},
"definitions": {
"VerifiableCredential": {
"type": "string",
"pattern": "^ceramic://.+(\\?version=.+)?"
}
},
"additionalProperties": false
}
58 changes: 58 additions & 0 deletions schemas/models/VerifiableCredentials.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "VerifiableCredential",
"description": "A [[VerifiableCredential]] is fact-checking review/attestation of claims made about a credentialSubject",
"type": "object",
"properties": {
"@context": {
"type": "array",
"items": {
"type": "string"
}
},
"type": {
"type": "array",
"items": {
"type": "string"
}
},
"credentialSubject": {
"type": "object",
"properties": {
"id": { "type": "string" },
"@context": {
"type": "array",
"items": {
"type": "object"
}
},
"root": { "type": "string" },
"address": { "type": "string" },
"challenge": { "type": "string" }
}
},
"issuer": { "type": "string" },
"issuanceDate": { "type": "string" },
"expirationDate": { "type": "string" },
"proof": {
"type": "object",
"properties": {
"type": { "type": "string" },
"proofPurpose": { "type": "string" },
"verificationMethod": { "type": "string" },
"created": { "type": "string" },
"jws": { "type": "string" }
}
}
},
"required": [
"@context",
"type",
"credentialSubject",
"issuer",
"issuanceDate",
"expirationDate",
"proof"
],
"additionalProperties": false
}
2 changes: 2 additions & 0 deletions schemas/models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Passport } from "./Passports.json";
export { default as VerifiableCredentials } from "./VerifiableCredentials.json";
27 changes: 27 additions & 0 deletions schemas/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@dpopp/schemas",
"version": "0.0.1",
"private": true,
"scripts": {
"clean": "rimraf node_modules",
"ceramic": "ceramic daemon",
"create-model": "node --experimental-json-modules ./scripts/create-model.mjs",
"publish-model": "node --experimental-json-modules ./scripts/publish-model.mjs"
},
"dependencies": {
"@ceramicnetwork/http-client": "^2.0.0",
"dids": "^3.0.0",
"dotenv": "^16.0.0",
"key-did-provider-ed25519": "^2.0.0",
"key-did-resolver": "^2.0.0",
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@ceramicnetwork/cli": "^2.0.2",
"@glazed/devtools": "^0.1.6",
"@types/node": "^16.11.6"
},
"resolutions": {
"leveldown": "6.1.1"
}
}
1 change: 1 addition & 0 deletions schemas/scripts/create-model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"schemas":{"kjzl6cwe1jw146wqb0fdjbbaahu9ckynyhjzraaim5e0a4kqusgt7fci5st0si1":{"alias":"VerifiableCredential","commits":[{"jws":{"payload":"AXESIER9Hd3VnwjxL_S9GkXZVc00pD3lfZW83lKcxnVodXi9","signatures":[{"signature":"Z-9n7QFIpDjyHZKvyuLojNqsT0Fs5ggY7m3wRMBef5hw_BvhDiv2aLhhicuqYiP1ICcABgqMuaEIKZWnUfSaAw","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa2Y2NEN0RkF0bVNudDJhM0hyRnlvMWkxQnpSMmZ0bmRqckhieTFicXY4TjVyI3o2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41ciJ9"}],"link":"bafyreicepuo53vm7bdys75f5djc5svongssd3zl5sw6n4uu4yz2wq5lyxu"},"linkedBlock":"omRkYXRhp2R0eXBlZm9iamVjdGV0aXRsZXRWZXJpZmlhYmxlQ3JlZGVudGlhbGckc2NoZW1heCdodHRwOi8vanNvbi1zY2hlbWEub3JnL2RyYWZ0LTA3L3NjaGVtYSNocmVxdWlyZWSHaEBjb250ZXh0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t4r2b1c9cg96mv6hh2id8u6a16sdibm00jiyyfjot4x58udmo74"},"kjzl6cwe1jw147voouul91nizwtb1zcz8p0cfn0q9wig69sl6f8vg74b9it0yht":{"alias":"Passport","commits":[{"jws":{"payload":"AXESILFJa64ncTCIX5ldU77eUKSE5e7z7nyQxJR3yRegRPUN","signatures":[{"signature":"qAedQY7MplbjSKcqI53PoRCAhlX-6pEdJsjYVSvoXLxUG_YF7COcstTZeg1rq-_Oy_Y894ipMXUgRXcG4v0oAQ","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa2Y2NEN0RkF0bVNudDJhM0hyRnlvMWkxQnpSMmZ0bmRqckhieTFicXY4TjVyI3o2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41ciJ9"}],"link":"bafyreifrjfv24j3rgcef7gk5ko7n4ufeqts6547opsimjfdxzel2arhvbu"},"linkedBlock":"omRkYXRhp2R0eXBlZm9iamVjdGV0aXRsZWhQYXNzcG9ydGckc2NoZW1heCdodHRwOi8vanNvbi1zY2hlbWEub3JnL2RyYWZ0LTA3L3NjaGVtYSNqcHJvcGVydGllc6Nmc3RhbXBzo2R0eXBlZWFycmF5ZWl0ZW1zo2R0eXBlZm9iamVjdGV0aXRsZWlzdGFtcEl0ZW1qcHJvcGVydGllc6JocHJvdmlkZXKhZHR5cGVmc3RyaW5namNyZWRlbnRpYWyhZCRyZWZ4IiMvZGVmaW5pdGlvbnMvVmVyaWZpYWJsZUNyZWRlbnRpYWxldGl0bGVmc3RhbXBzamV4cGlyeURhdGWkZHR5cGVmc3RyaW5nZXRpdGxla2RhdGVVcGRhdGVkZmZvcm1hdGlkYXRlLXRpbWVpbWF4TGVuZ3RoGB5saXNzdWFuY2VEYXRlpGR0eXBlZnN0cmluZ2V0aXRsZWxpc3N1YW5jZURhdGVmZm9ybWF0aWRhdGUtdGltZWltYXhMZW5ndGgYHmtkZWZpbml0aW9uc6F0VmVyaWZpYWJsZUNyZWRlbnRpYWyiZHR5cGVmc3RyaW5nZ3BhdHRlcm54HF5jZXJhbWljOi8vLisoXD92ZXJzaW9uPS4rKT9rZGVzY3JpcHRpb254HFVzZXIgUGFzc3BvcnQgc3RvcmluZyBzdGFtcHN0YWRkaXRpb25hbFByb3BlcnRpZXP0ZmhlYWRlcqJmdW5pcXVlcDd2cnFJcndLa0xpbmdxUXprY29udHJvbGxlcnOBeDhkaWQ6a2V5Ono2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41cg=="}],"dependencies":{},"version":"k3y52l7qbv1fry01bkrdj4brb3dcem3galtugf7p6uf770lnalof3n6mo3pqetam8"}},"definitions":{"kjzl6cwe1jw145yjj8f4b6fjnzud3uy29utvqx7eqr7xb98kq90rrkuzbljvo1y":{"alias":"Passport","commits":[{"jws":{"payload":"AXESIACgqLWl1orELlshBixnmfH9YHflb8z6qi5N0ZbShJHi","signatures":[{"signature":"xAo1Nrvi2ISQaCx6FdwN0-xJZ4H8A19UqDFkf7lbD9USRmGhHE1ntKB_U1RT2xdL9Ap8143ctwmEBRO07Rl5Cw","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa2Y2NEN0RkF0bVNudDJhM0hyRnlvMWkxQnpSMmZ0bmRqckhieTFicXY4TjVyI3o2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41ciJ9"}],"link":"bafyreiaauculljowrlcc4wzbaywgpgpr7vqhpzlpzt5kulsn2glnfber4i"},"linkedBlock":"omRkYXRho2RuYW1laFBhc3Nwb3J0ZnNjaGVtYXhLY2VyYW1pYzovL2szeTUybDdxYnYxZnJ5MDFia3JkajRicmIzZGNlbTNnYWx0dWdmN3A2dWY3NzBsbmFsb2YzbjZtbzNwcWV0YW04a2Rlc2NyaXB0aW9ueBxVc2VyIFBhc3Nwb3J0IHN0b3Jpbmcgc3RhbXBzZmhlYWRlcqNmc2NoZW1heEtjZXJhbWljOi8vazN5NTJsN3FidjFmcnkxZnA0czBud2RhcmgwdmFodXNhcnBwb3NnZXZ5MHBlbWl5a3ltZDJvcmQ2c3d0aGFyY3dmdW5pcXVlcEhiUDR4M1hVTXhYdGppMldrY29udHJvbGxlcnOBeDhkaWQ6a2V5Ono2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41cg=="}],"schema":"kjzl6cwe1jw147voouul91nizwtb1zcz8p0cfn0q9wig69sl6f8vg74b9it0yht","version":"k3y52l7qbv1frxmdmwrvinhqjumvx7g28638hrg4ou9kcw1ozeo5hg4cb6h9d71ts"},"kjzl6cwe1jw147g1cb2awlanpocmy9mso0ln8u9buq3twsl8mkoao8hwylenwgc":{"alias":"VerifiableCredential","commits":[{"jws":{"payload":"AXESILba5Yiltyhq-C3fPQaDeXmoXGs9goXJcIdY9L3Xov4t","signatures":[{"signature":"zCj5bORTotjmn7MJTMVWQNHWlLj07GVSj-9TFQsEx-Sk2sH6LUd2MaKzx6LCwnnCAax0P_oRpof-Vh66Jz1HCw","protected":"eyJhbGciOiJFZERTQSIsImtpZCI6ImRpZDprZXk6ejZNa2Y2NEN0RkF0bVNudDJhM0hyRnlvMWkxQnpSMmZ0bmRqckhieTFicXY4TjVyI3o2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41ciJ9"}],"link":"bafyreifw3lsyrjnxfbvpqlo7hudig6lzvbogwpmcqxexbb2y6s65pix6fu"},"linkedBlock":"omRkYXRho2RuYW1ldFZlcmlmaWFibGVDcmVkZW50aWFsZnNjaGVtYXhLY2VyYW1pYzovL2szeTUybDdxYnYxZnJ4dDRyMmIxYzljZzk2bXY2aGgyaWQ4dTZhMTZzZGlibTAwaml5eWZqb3Q0eDU4dWRtbzc0a2Rlc2NyaXB0aW9ueGdBIFtbVmVyaWZpYWJsZUNyZWRlbnRpYWxdXSBpcyBmYWN0LWNoZWNraW5nIHJldmlldy9hdHRlc3RhdGlvbiBvZiBjbGFpbXMgbWFkZSBhYm91dCBhIGNyZWRlbnRpYWxTdWJqZWN0ZmhlYWRlcqNmc2NoZW1heEtjZXJhbWljOi8vazN5NTJsN3FidjFmcnkxZnA0czBud2RhcmgwdmFodXNhcnBwb3NnZXZ5MHBlbWl5a3ltZDJvcmQ2c3d0aGFyY3dmdW5pcXVlcGZjT09pYlVibTdDcERsR1VrY29udHJvbGxlcnOBeDhkaWQ6a2V5Ono2TWtmNjRDdEZBdG1TbnQyYTNIckZ5bzFpMUJ6UjJmdG5kanJIYnkxYnF2OE41cg=="}],"schema":"kjzl6cwe1jw146wqb0fdjbbaahu9ckynyhjzraaim5e0a4kqusgt7fci5st0si1","version":"k3y52l7qbv1frxwy1jiodjrfsml5v7oi3us9xav6cahn8p7b1cj0rwcfee089ys5c"}},"tiles":{}}
63 changes: 63 additions & 0 deletions schemas/scripts/create-model.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { writeFile } from "node:fs/promises";
import { CeramicClient } from "@ceramicnetwork/http-client";
import { ModelManager } from "@glazed/devtools";
import { DID } from "dids";
import { Ed25519Provider } from "key-did-provider-ed25519";
import { getResolver } from "key-did-resolver";
import { fromString } from "uint8arrays";
import Passport from "../models/Passports.json" assert { type: "json" };
import VerifiableCredentials from "../models/VerifiableCredentials.json" assert { type: "json" };

// import 'dotenv/config' // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
import dotenv from "dotenv";
dotenv.config();

const models = [Passport, VerifiableCredentials];

let SEED = process.env.SEED;

if (!process.env.SEED) {
// throw new Error('Missing SEED environment variable');
// SEED = new Uint32Array(32);
SEED = new Uint8Array([
6, 190, 125, 152, 83, 9, 111, 202, 6, 214, 218, 146, 104, 168, 166, 110,
202, 171, 42, 114, 73, 204, 214, 60, 112, 254, 173, 151, 170, 254, 250, 2,
]);
}
console.log("VIEW SEE ", SEED, SEED.length);
// The seed must be provided as an environment variable
// const seed = fromString(process.env.SEED, 'base16');
// const seed = fromString(SEED, 'base16');
// Create and authenticate the DID
const did = new DID({
provider: new Ed25519Provider(SEED),
resolver: getResolver(),
});
await did.authenticate();

// Connect to the local Ceramic node
const ceramic = new CeramicClient("http://localhost:7007");
ceramic.did = did;

// Create a manager for the model
const manager = new ModelManager(ceramic);

// read in files from models directory
models.forEach(async (model) => {
// Pass in schema name and json
const schemaId = await manager.createSchema(model.title, model);

// Create the definition using the created schema ID
await manager.createDefinition(model.title, {
name: model.title,
description: model.description,
schema: manager.getSchemaURL(schemaId),
});

await writeFile(
new URL("create-model.json", import.meta.url),
JSON.stringify(manager.toJSON())
);
});

console.log("Encoded model written to scripts/create-model.json file");
1 change: 1 addition & 0 deletions schemas/scripts/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"definitions":{"VerifiableCredential":"kjzl6cwe1jw146zr8jqi7b35xtkdaptrthwyveot7zf7opl3z03ws646tp3hejc","Passport":"kjzl6cwe1jw14929jlu8tlcrxd44hr2qxup3uomz40ckkmotgndnp783tat8iwz"},"schemas":{"Passport":"ceramic://k3y52l7qbv1frxqk1k892dlaug9uz7vcdr2rts8n349pwvpmx6bbgq0h8zzkuf7cw","VerifiableCredential":"ceramic://k3y52l7qbv1frxjo15a8oaa30fwi9sgzxp40jzsp4slv4r3kuogpu6ztquhu3s4qo"},"tiles":{}}
1 change: 1 addition & 0 deletions schemas/scripts/publish-model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"definitions":{"Passport":"kjzl6cwe1jw145yjj8f4b6fjnzud3uy29utvqx7eqr7xb98kq90rrkuzbljvo1y","VerifiableCredential":"kjzl6cwe1jw147g1cb2awlanpocmy9mso0ln8u9buq3twsl8mkoao8hwylenwgc"},"schemas":{"VerifiableCredential":"ceramic://k3y52l7qbv1frxt4r2b1c9cg96mv6hh2id8u6a16sdibm00jiyyfjot4x58udmo74","Passport":"ceramic://k3y52l7qbv1fry01bkrdj4brb3dcem3galtugf7p6uf770lnalof3n6mo3pqetam8"},"tiles":{}}
19 changes: 19 additions & 0 deletions schemas/scripts/publish-model.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { readFile, writeFile } from "node:fs/promises";
import { CeramicClient } from "@ceramicnetwork/http-client";
import { ModelManager } from "@glazed/devtools";

// Connect to the local Ceramic node
const ceramic = new CeramicClient("http://localhost:7007");

// Load and create a manager for the model
const bytes = await readFile(new URL("create-model.json", import.meta.url));
const manager = ModelManager.fromJSON(ceramic, JSON.parse(bytes.toString()));

// Write model to JSON file
const model = await manager.toPublished();
await writeFile(
new URL("publish-model.json", import.meta.url),
JSON.stringify(model)
);

console.log("Model written to publish-model.json file:", model);
Loading

0 comments on commit e57ebdc

Please sign in to comment.