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