Skip to content

Commit

Permalink
fix(schemas): update schemas scripts to read in SEED from environment
Browse files Browse the repository at this point in the history
- update READMEs of iam and database-client
- add database-client build steps in start scripts
  • Loading branch information
shavinac committed May 9, 2022
1 parent 9e5b99f commit 2983c42
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
4 changes: 3 additions & 1 deletion database-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ yarn run test:integration

## Running the Ceramic integration tests in Docker

Still work-in-progress. IMPORTANT this will overwrite your `schemas/scripts/create-model.json` and `schemas/scripts/publish-model.json` files! Make a backup of these files!
IMPORTANT this will overwrite your `schemas/scripts/create-model.json` and `schemas/scripts/publish-model.json` files! Make a backup of these files!

```bash
docker-compose up -d
```

Tests are flaky the first time, possibly due to connection issues with the Ceramic node. If tests fail due to an error like `request to http://localhost:7007/api/v0/streams failed, reason: connect ECONNREFUSED 127.0.0.1:7007`, try running `docker-compose up -d` again to re-run the tests.
1 change: 1 addition & 0 deletions database-client/integration-tests/run-ceramic-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ echo "Starting up Ceramic..."

# TODO - not needed once we publish + persist our schemas to ceramic testnet
# === create & publish model to ceramic ===
export SEED="06be7d9853096fca06d6da9268a8a66ecaab2a7249ccd63c70fead97aafefa02" # TEST SEED, DO NOT USE IN PROD
yarn workspace @dpopp/schemas create-model
yarn workspace @dpopp/schemas publish-model

Expand Down
10 changes: 3 additions & 7 deletions iam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ $ lerna bootstrap
$ yarn start:iam
```

Then send a POST request to `http://localhost:65535/api/v0.0.0/verify` with the following JSON body:
Then send a POST request to `http://localhost:65535/api/v0.0.0/challenge` with the following JSON body:

```
{
"payload": {
"address": "0x010",
"type": "Simple",
"proofs": {
"valid": "true",
"username": "test"
}
"address": "0x71C7656EC7ab88b098defB751B7401B5f6d8976F",
"type": "Simple"
}
}
```
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"test:iam": "yarn workspace @dpopp/iam test",
"test:identity": "yarn workspace @dpopp/identity test",
"prettier": "lerna run prettier",
"build": "yarn build:identity && yarn build:iam && yarn build:app",
"build": "yarn build:identity && yarn build:database-client && yarn build:iam && yarn build:app",
"build:database-client": "yarn workspace @dpopp/database-client build",
"build:identity": "yarn workspace @dpopp/identity build",
"build:iam": "yarn workspace @dpopp/iam build",
"build:app": "yarn workspace @dpopp/app build",
Expand All @@ -43,9 +44,9 @@
"iam": "yarn workspace @dpopp/iam",
"identity": "yarn workspace @dpopp/identity",
"types": "yarn workspace @dpopp/types",
"prestart": "yarn build:identity",
"pretest": "yarn build:identity",
"postinstall": "yarn build:identity",
"prestart": "yarn build:identity && yarn build:database-client",
"pretest": "yarn build:identity && yarn build:database-client",
"postinstall": "yarn build:identity && yarn build:database-client",
"test:ceramic-integration": "yarn workspace @dpopp/database-client test:integration"
},
"engines": {
Expand Down
21 changes: 8 additions & 13 deletions schemas/scripts/create-model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@ 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;

// The seed must be provided as an environment variable
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,
]);
throw new Error("Missing SEED environment variable");
}
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');
const seed = fromString(SEED, "base16");

// Create and authenticate the DID
const did = new DID({
provider: new Ed25519Provider(SEED),
provider: new Ed25519Provider(seed),
resolver: getResolver(),
});
await did.authenticate();

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

// Create a manager for the model
Expand Down
4 changes: 3 additions & 1 deletion schemas/scripts/publish-model.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { CeramicClient } from "@ceramicnetwork/http-client";
import { ModelManager } from "@glazed/devtools";

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

// Load and create a manager for the model
const bytes = await readFile(new URL("create-model.json", import.meta.url));
Expand Down

0 comments on commit 2983c42

Please sign in to comment.