From e8c9f65341bdca43e564ab06e10e4c4ff41565ab Mon Sep 17 00:00:00 2001 From: John Hopkins Date: Mon, 4 Mar 2024 10:20:58 -0300 Subject: [PATCH 1/3] added a few lines to clarify how to generate your secret key --- docs/node_tutorials/node_setup_identifiers.md | 144 ++++++++++-------- 1 file changed, 84 insertions(+), 60 deletions(-) diff --git a/docs/node_tutorials/node_setup_identifiers.md b/docs/node_tutorials/node_setup_identifiers.md index bd3a5ce..b438de6 100644 --- a/docs/node_tutorials/node_setup_identifiers.md +++ b/docs/node_tutorials/node_setup_identifiers.md @@ -55,6 +55,12 @@ Install `sqlite` yarn add sqlite3 typeorm ``` +Generate your secret key and save for later in a safe place + +```bash +npx @veramo/cli config create-secret-key +``` + Add a tsconfig.json to your project ```json @@ -75,6 +81,9 @@ Add a tsconfig.json to your project ## Bootstrap Veramo We bootstrap Veramo by creating a setup file and initializing the agent. Create a setup file in `src/veramo/setup.ts` + +In this file we'll use that secret key that we generated in an earlier step, so have it handy. + and import the following dependencies: ```typescript @@ -87,85 +96,98 @@ import { IDataStoreORM, IKeyManager, ICredentialPlugin, -} from '@veramo/core' +} from "@veramo/core"; // Core identity manager plugin -import { DIDManager } from '@veramo/did-manager' +import { DIDManager } from "@veramo/did-manager"; // Ethr did identity provider -import { EthrDIDProvider } from '@veramo/did-provider-ethr' +import { EthrDIDProvider } from "@veramo/did-provider-ethr"; // Core key manager plugin -import { KeyManager } from '@veramo/key-manager' +import { KeyManager } from "@veramo/key-manager"; // Custom key management system for RN -import { KeyManagementSystem, SecretBox } from '@veramo/kms-local' +import { KeyManagementSystem, SecretBox } from "@veramo/kms-local"; // W3C Verifiable Credential plugin -import { CredentialPlugin } from '@veramo/credential-w3c' +import { CredentialPlugin } from "@veramo/credential-w3c"; // Custom resolvers -import { DIDResolverPlugin } from '@veramo/did-resolver' -import { Resolver } from 'did-resolver' -import { getResolver as ethrDidResolver } from 'ethr-did-resolver' -import { getResolver as webDidResolver } from 'web-did-resolver' +import { DIDResolverPlugin } from "@veramo/did-resolver"; +import { Resolver } from "did-resolver"; +import { getResolver as ethrDidResolver } from "ethr-did-resolver"; +import { getResolver as webDidResolver } from "web-did-resolver"; // Storage plugin using TypeOrm -import { Entities, KeyStore, DIDStore, PrivateKeyStore, migrations } from '@veramo/data-store' +import { + Entities, + KeyStore, + DIDStore, + PrivateKeyStore, + migrations, +} from "@veramo/data-store"; // TypeORM is installed with `@veramo/data-store` -import { DataSource } from 'typeorm' +import { DataSource } from "typeorm"; ``` Create some variables that we will use later ```ts // This will be the name for the local sqlite database for demo purposes -const DATABASE_FILE = 'database.sqlite' +const DATABASE_FILE = "database.sqlite"; // You will need to get a project ID from infura https://www.infura.io -const INFURA_PROJECT_ID = '' +const INFURA_PROJECT_ID = ""; -// This will be the secret key for the KMS +// This will be the secret key for the KMS (replace this with your secret key) const KMS_SECRET_KEY = - '< you can generate a key by running `npx @veramo/cli config create-secret-key` in a terminal>' + "< you can generate a key by running `npx @veramo/cli config create-secret-key` in a terminal>"; ``` Initialise a database using TypeORM ```ts const dbConnection = new DataSource({ - type: 'sqlite', + type: "sqlite", database: DATABASE_FILE, synchronize: false, migrations, migrationsRun: true, - logging: ['error', 'info', 'warn'], + logging: ["error", "info", "warn"], entities: Entities, -}).initialize() +}).initialize(); ``` Create the agent by using the createAgent method from `@veramo/core` ```ts export const agent = createAgent< - IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & ICredentialPlugin + IDIDManager & + IKeyManager & + IDataStore & + IDataStoreORM & + IResolver & + ICredentialPlugin >({ plugins: [ new KeyManager({ store: new KeyStore(dbConnection), kms: { - local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(KMS_SECRET_KEY))), + local: new KeyManagementSystem( + new PrivateKeyStore(dbConnection, new SecretBox(KMS_SECRET_KEY)) + ), }, }), new DIDManager({ store: new DIDStore(dbConnection), - defaultProvider: 'did:ethr:goerli', + defaultProvider: "did:ethr:goerli", providers: { - 'did:ethr:goerli': new EthrDIDProvider({ - defaultKms: 'local', - network: 'goerli', - rpcUrl: 'https://goerli.infura.io/v3/' + INFURA_PROJECT_ID, + "did:ethr:goerli": new EthrDIDProvider({ + defaultKms: "local", + network: "goerli", + rpcUrl: "https://goerli.infura.io/v3/" + INFURA_PROJECT_ID, }), }, }), @@ -177,7 +199,7 @@ export const agent = createAgent< }), new CredentialPlugin(), ], -}) +}); ``` > **Note:** @@ -202,91 +224,93 @@ Create 4 files `./src/create-identifier.ts`, `./src/list-identifiers.ts`, `./src Add the following code to `./src/list-identifiers.ts` ```ts -import { agent } from './veramo/setup.js' +import { agent } from "./veramo/setup.js"; async function main() { - const identifiers = await agent.didManagerFind() + const identifiers = await agent.didManagerFind(); - console.log(`There are ${identifiers.length} identifiers`) + console.log(`There are ${identifiers.length} identifiers`); if (identifiers.length > 0) { identifiers.map((id) => { - console.log(id) - console.log('..................') - }) + console.log(id); + console.log(".................."); + }); } } -main().catch(console.log) +main().catch(console.log); ``` Add the following code to `./src/create-identifier.ts` ```ts -import { agent } from './veramo/setup.js' +import { agent } from "./veramo/setup.js"; async function main() { - const identifier = await agent.didManagerCreate({ alias: 'default' }) - console.log(`New identifier created`) - console.log(JSON.stringify(identifier, null, 2)) + const identifier = await agent.didManagerCreate({ alias: "default" }); + console.log(`New identifier created`); + console.log(JSON.stringify(identifier, null, 2)); } -main().catch(console.log) +main().catch(console.log); ``` Add the following code to `./src/create-credential.ts` ```ts -import { agent } from './veramo/setup.js' +import { agent } from "./veramo/setup.js"; async function main() { - const identifier = await agent.didManagerGetByAlias({ alias: 'default' }) + const identifier = await agent.didManagerGetByAlias({ alias: "default" }); const verifiableCredential = await agent.createVerifiableCredential({ credential: { issuer: { id: identifier.did }, credentialSubject: { - id: 'did:web:example.com', - you: 'Rock', + id: "did:web:example.com", + you: "Rock", }, }, - proofFormat: 'jwt', - }) - console.log(`New credential created`) - console.log(JSON.stringify(verifiableCredential, null, 2)) + proofFormat: "jwt", + }); + console.log(`New credential created`); + console.log(JSON.stringify(verifiableCredential, null, 2)); } -main().catch(console.log) +main().catch(console.log); ``` Add the following code to `./src/verify-credential.ts` ```ts -import { agent } from './veramo/setup.js' +import { agent } from "./veramo/setup.js"; async function main() { const result = await agent.verifyCredential({ credential: { credentialSubject: { - you: 'Rock', - id: 'did:web:example.com', + you: "Rock", + id: "did:web:example.com", }, issuer: { - id: 'did:ethr:goerli:0x0350eeeea1410c5b152f1a88e0ffe8bb8a0bc3df868b740eb2352b1dbf93b59c16', + id: + "did:ethr:goerli:0x0350eeeea1410c5b152f1a88e0ffe8bb8a0bc3df868b740eb2352b1dbf93b59c16", }, - type: ['VerifiableCredential'], - '@context': ['https://www.w3.org/2018/credentials/v1'], - issuanceDate: '2022-10-28T11:54:22.000Z', + type: ["VerifiableCredential"], + "@context": ["https://www.w3.org/2018/credentials/v1"], + issuanceDate: "2022-10-28T11:54:22.000Z", proof: { - type: 'JwtProof2020', - jwt: 'eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InlvdSI6IlJvY2sifX0sInN1YiI6ImRpZDp3ZWI6ZXhhbXBsZS5jb20iLCJuYmYiOjE2NjY5NTgwNjIsImlzcyI6ImRpZDpldGhyOmdvZXJsaToweDAzNTBlZWVlYTE0MTBjNWIxNTJmMWE4OGUwZmZlOGJiOGEwYmMzZGY4NjhiNzQwZWIyMzUyYjFkYmY5M2I1OWMxNiJ9.EPeuQBpkK13V9wu66SLg7u8ebY2OS8b2Biah2Vw-RI-Atui2rtujQkVc2t9m1Eqm4XQFECfysgQBdWwnSDvIjw', + type: "JwtProof2020", + jwt: + "eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InlvdSI6IlJvY2sifX0sInN1YiI6ImRpZDp3ZWI6ZXhhbXBsZS5jb20iLCJuYmYiOjE2NjY5NTgwNjIsImlzcyI6ImRpZDpldGhyOmdvZXJsaToweDAzNTBlZWVlYTE0MTBjNWIxNTJmMWE4OGUwZmZlOGJiOGEwYmMzZGY4NjhiNzQwZWIyMzUyYjFkYmY5M2I1OWMxNiJ9.EPeuQBpkK13V9wu66SLg7u8ebY2OS8b2Biah2Vw-RI-Atui2rtujQkVc2t9m1Eqm4XQFECfysgQBdWwnSDvIjw", }, }, - }) - console.log(`Credential verified`, result.verified) + }); + console.log(`Credential verified`, result.verified); } -main().catch(console.log) +main().catch(console.log); ``` ### List Identifiers From e26c0333235295594b1eefcc3a3cf197fdae7fcd Mon Sep 17 00:00:00 2001 From: John Hopkins Date: Mon, 4 Mar 2024 10:38:08 -0300 Subject: [PATCH 2/3] moved line which was interrrupting existing text --- docs/node_tutorials/node_setup_identifiers.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/node_tutorials/node_setup_identifiers.md b/docs/node_tutorials/node_setup_identifiers.md index b438de6..d89e301 100644 --- a/docs/node_tutorials/node_setup_identifiers.md +++ b/docs/node_tutorials/node_setup_identifiers.md @@ -80,11 +80,9 @@ Add a tsconfig.json to your project ## Bootstrap Veramo -We bootstrap Veramo by creating a setup file and initializing the agent. Create a setup file in `src/veramo/setup.ts` +We bootstrap Veramo by creating a setup file and initializing the agent. Create a setup file in `src/veramo/setup.ts` and import the following dependencies: -In this file we'll use that secret key that we generated in an earlier step, so have it handy. - -and import the following dependencies: +Note: In this file we'll use that secret key that we generated in an earlier step, so have it handy. ```typescript // Core interfaces From b25d1a0eb0c771b85f3e523f4e8fbb21c31fb190 Mon Sep 17 00:00:00 2001 From: John Hopkins Date: Mon, 4 Mar 2024 14:37:11 -0300 Subject: [PATCH 3/3] reverting formatting --- docs/node_tutorials/node_setup_identifiers.md | 133 ++++++++---------- 1 file changed, 59 insertions(+), 74 deletions(-) diff --git a/docs/node_tutorials/node_setup_identifiers.md b/docs/node_tutorials/node_setup_identifiers.md index d89e301..10cd7b5 100644 --- a/docs/node_tutorials/node_setup_identifiers.md +++ b/docs/node_tutorials/node_setup_identifiers.md @@ -94,98 +94,85 @@ import { IDataStoreORM, IKeyManager, ICredentialPlugin, -} from "@veramo/core"; +} from '@veramo/core' // Core identity manager plugin -import { DIDManager } from "@veramo/did-manager"; +import { DIDManager } from '@veramo/did-manager' // Ethr did identity provider -import { EthrDIDProvider } from "@veramo/did-provider-ethr"; +import { EthrDIDProvider } from '@veramo/did-provider-ethr' // Core key manager plugin -import { KeyManager } from "@veramo/key-manager"; +import { KeyManager } from '@veramo/key-manager' // Custom key management system for RN -import { KeyManagementSystem, SecretBox } from "@veramo/kms-local"; +import { KeyManagementSystem, SecretBox } from '@veramo/kms-local' // W3C Verifiable Credential plugin -import { CredentialPlugin } from "@veramo/credential-w3c"; +import { CredentialPlugin } from '@veramo/credential-w3c' // Custom resolvers -import { DIDResolverPlugin } from "@veramo/did-resolver"; -import { Resolver } from "did-resolver"; -import { getResolver as ethrDidResolver } from "ethr-did-resolver"; -import { getResolver as webDidResolver } from "web-did-resolver"; +import { DIDResolverPlugin } from '@veramo/did-resolver' +import { Resolver } from 'did-resolver' +import { getResolver as ethrDidResolver } from 'ethr-did-resolver' +import { getResolver as webDidResolver } from 'web-did-resolver' // Storage plugin using TypeOrm -import { - Entities, - KeyStore, - DIDStore, - PrivateKeyStore, - migrations, -} from "@veramo/data-store"; +import { Entities, KeyStore, DIDStore, PrivateKeyStore, migrations } from '@veramo/data-store' // TypeORM is installed with `@veramo/data-store` -import { DataSource } from "typeorm"; +import { DataSource } from 'typeorm' ``` Create some variables that we will use later ```ts // This will be the name for the local sqlite database for demo purposes -const DATABASE_FILE = "database.sqlite"; +const DATABASE_FILE = 'database.sqlite' // You will need to get a project ID from infura https://www.infura.io -const INFURA_PROJECT_ID = ""; +const INFURA_PROJECT_ID = '' // This will be the secret key for the KMS (replace this with your secret key) const KMS_SECRET_KEY = - "< you can generate a key by running `npx @veramo/cli config create-secret-key` in a terminal>"; + '< you can generate a key by running `npx @veramo/cli config create-secret-key` in a terminal>' ``` Initialise a database using TypeORM ```ts const dbConnection = new DataSource({ - type: "sqlite", + type: 'sqlite', database: DATABASE_FILE, synchronize: false, migrations, migrationsRun: true, - logging: ["error", "info", "warn"], + logging: ['error', 'info', 'warn'], entities: Entities, -}).initialize(); +}).initialize() ``` Create the agent by using the createAgent method from `@veramo/core` ```ts export const agent = createAgent< - IDIDManager & - IKeyManager & - IDataStore & - IDataStoreORM & - IResolver & - ICredentialPlugin + IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & ICredentialPlugin >({ plugins: [ new KeyManager({ store: new KeyStore(dbConnection), kms: { - local: new KeyManagementSystem( - new PrivateKeyStore(dbConnection, new SecretBox(KMS_SECRET_KEY)) - ), + local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(KMS_SECRET_KEY))), }, }), new DIDManager({ store: new DIDStore(dbConnection), - defaultProvider: "did:ethr:goerli", + defaultProvider: 'did:ethr:goerli', providers: { - "did:ethr:goerli": new EthrDIDProvider({ - defaultKms: "local", - network: "goerli", - rpcUrl: "https://goerli.infura.io/v3/" + INFURA_PROJECT_ID, + 'did:ethr:goerli': new EthrDIDProvider({ + defaultKms: 'local', + network: 'goerli', + rpcUrl: 'https://goerli.infura.io/v3/' + INFURA_PROJECT_ID, }), }, }), @@ -197,7 +184,7 @@ export const agent = createAgent< }), new CredentialPlugin(), ], -}); +}) ``` > **Note:** @@ -222,93 +209,91 @@ Create 4 files `./src/create-identifier.ts`, `./src/list-identifiers.ts`, `./src Add the following code to `./src/list-identifiers.ts` ```ts -import { agent } from "./veramo/setup.js"; +import { agent } from './veramo/setup.js' async function main() { - const identifiers = await agent.didManagerFind(); + const identifiers = await agent.didManagerFind() - console.log(`There are ${identifiers.length} identifiers`); + console.log(`There are ${identifiers.length} identifiers`) if (identifiers.length > 0) { identifiers.map((id) => { - console.log(id); - console.log(".................."); - }); + console.log(id) + console.log('..................') + }) } } -main().catch(console.log); +main().catch(console.log) ``` Add the following code to `./src/create-identifier.ts` ```ts -import { agent } from "./veramo/setup.js"; +import { agent } from './veramo/setup.js' async function main() { - const identifier = await agent.didManagerCreate({ alias: "default" }); - console.log(`New identifier created`); - console.log(JSON.stringify(identifier, null, 2)); + const identifier = await agent.didManagerCreate({ alias: 'default' }) + console.log(`New identifier created`) + console.log(JSON.stringify(identifier, null, 2)) } -main().catch(console.log); +main().catch(console.log) ``` Add the following code to `./src/create-credential.ts` ```ts -import { agent } from "./veramo/setup.js"; +import { agent } from './veramo/setup.js' async function main() { - const identifier = await agent.didManagerGetByAlias({ alias: "default" }); + const identifier = await agent.didManagerGetByAlias({ alias: 'default' }) const verifiableCredential = await agent.createVerifiableCredential({ credential: { issuer: { id: identifier.did }, credentialSubject: { - id: "did:web:example.com", - you: "Rock", + id: 'did:web:example.com', + you: 'Rock', }, }, - proofFormat: "jwt", - }); - console.log(`New credential created`); - console.log(JSON.stringify(verifiableCredential, null, 2)); + proofFormat: 'jwt', + }) + console.log(`New credential created`) + console.log(JSON.stringify(verifiableCredential, null, 2)) } -main().catch(console.log); +main().catch(console.log) ``` Add the following code to `./src/verify-credential.ts` ```ts -import { agent } from "./veramo/setup.js"; +import { agent } from './veramo/setup.js' async function main() { const result = await agent.verifyCredential({ credential: { credentialSubject: { - you: "Rock", - id: "did:web:example.com", + you: 'Rock', + id: 'did:web:example.com', }, issuer: { - id: - "did:ethr:goerli:0x0350eeeea1410c5b152f1a88e0ffe8bb8a0bc3df868b740eb2352b1dbf93b59c16", + id: 'did:ethr:goerli:0x0350eeeea1410c5b152f1a88e0ffe8bb8a0bc3df868b740eb2352b1dbf93b59c16', }, - type: ["VerifiableCredential"], - "@context": ["https://www.w3.org/2018/credentials/v1"], - issuanceDate: "2022-10-28T11:54:22.000Z", + type: ['VerifiableCredential'], + '@context': ['https://www.w3.org/2018/credentials/v1'], + issuanceDate: '2022-10-28T11:54:22.000Z', proof: { - type: "JwtProof2020", - jwt: - "eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InlvdSI6IlJvY2sifX0sInN1YiI6ImRpZDp3ZWI6ZXhhbXBsZS5jb20iLCJuYmYiOjE2NjY5NTgwNjIsImlzcyI6ImRpZDpldGhyOmdvZXJsaToweDAzNTBlZWVlYTE0MTBjNWIxNTJmMWE4OGUwZmZlOGJiOGEwYmMzZGY4NjhiNzQwZWIyMzUyYjFkYmY5M2I1OWMxNiJ9.EPeuQBpkK13V9wu66SLg7u8ebY2OS8b2Biah2Vw-RI-Atui2rtujQkVc2t9m1Eqm4XQFECfysgQBdWwnSDvIjw", + type: 'JwtProof2020', + jwt: 'eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QifQ.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIl0sImNyZWRlbnRpYWxTdWJqZWN0Ijp7InlvdSI6IlJvY2sifX0sInN1YiI6ImRpZDp3ZWI6ZXhhbXBsZS5jb20iLCJuYmYiOjE2NjY5NTgwNjIsImlzcyI6ImRpZDpldGhyOmdvZXJsaToweDAzNTBlZWVlYTE0MTBjNWIxNTJmMWE4OGUwZmZlOGJiOGEwYmMzZGY4NjhiNzQwZWIyMzUyYjFkYmY5M2I1OWMxNiJ9.EPeuQBpkK13V9wu66SLg7u8ebY2OS8b2Biah2Vw-RI-Atui2rtujQkVc2t9m1Eqm4XQFECfysgQBdWwnSDvIjw', }, }, - }); - console.log(`Credential verified`, result.verified); + }) + console.log(`Credential verified`, result.verified) } -main().catch(console.log); +main().catch(console.log) ``` ### List Identifiers