1
- // filename: setup.ts
2
-
3
1
// imports:
4
2
// Core interfaces
5
- import { createAgent , IDataStore , IDataStoreORM , IDIDManager , IKeyManager , IResolver } from '@veramo/core'
3
+ import { createAgent , IDataStore , IDataStoreORM , IDIDManager , IKeyManager } from '@veramo/core'
6
4
7
5
// Core identity manager plugin. This allows you to create and manage DIDs by orchestrating different DID provider packages.
8
6
// This implements `IDIDManager`
@@ -12,85 +10,73 @@ import { DIDManager } from '@veramo/did-manager'
12
10
// This implements `IKeyManager`
13
11
import { KeyManager } from '@veramo/key-manager'
14
12
15
- // This plugin allows us to create and manage `did:ethr ` DIDs. (used by DIDManager)
16
- import { EthrDIDProvider } from '@veramo/did-provider-ethr '
13
+ // This plugin allows us to create and manage `did:peer ` DIDs (used by DIDManager)
14
+ import { PeerDIDProvider } from '@veramo/did-provider-peer '
17
15
18
16
// A key management system that uses a local database to store keys (used by KeyManager)
19
17
import { KeyManagementSystem , SecretBox } from '@veramo/kms-local'
20
18
21
19
// Storage plugin using TypeORM to link to a database
22
20
import { Entities , KeyStore , DIDStore , migrations , PrivateKeyStore } from '@veramo/data-store'
23
21
22
+ // TypeORM is installed with '@veramo/data-store'
23
+ import { DataSource } from 'typeorm'
24
+
25
+ // Core interfaces
26
+ import { IResolver } from '@veramo/core'
27
+
24
28
// Core DID resolver plugin. This plugin orchestrates different DID resolver drivers to resolve the corresponding DID Documents for the given DIDs.
25
29
// This plugin implements `IResolver`
26
30
import { DIDResolverPlugin } from '@veramo/did-resolver'
27
31
28
- // the did:ethr resolver package
29
- import { getResolver as ethrDidResolver } from 'ethr- did-resolver '
32
+ // the did:peer resolver package
33
+ import { getResolver as peerDidResolver } from '@veramo/ did-provider-peer '
30
34
// the did:web resolver package
31
35
import { getResolver as webDidResolver } from 'web-did-resolver'
32
36
33
- // TypeORM is installed with '@veramo/data-store'
34
- import { DataSource } from 'typeorm'
35
-
36
- // filename: setup.ts
37
-
38
- // ... imports
37
+ // This plugin allows us to issue and verify W3C Verifiable Credentials with JWT proof format
38
+ import { CredentialPlugin , ICredentialIssuer , ICredentialVerifier } from '@veramo/credential-w3c'
39
39
40
40
// CONSTANTS
41
- // You will need to get a project ID from infura https://www.infura.io
42
- const INFURA_PROJECT_ID = '3586660d179141e3801c3895de1c2eba'
43
41
44
42
// This is a raw X25519 private key, provided as an example.
45
43
// You can run `npx @veramo/cli config create-secret-key` in a terminal to generate a new key.
46
44
// In a production app, this MUST NOT be hardcoded in your source code.
47
45
const DB_ENCRYPTION_KEY = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa830c'
48
46
49
- // filename: setup.ts
50
-
51
- // ... imports & CONSTANTS
52
-
53
47
// DB setup:
54
48
let dbConnection = new DataSource ( {
55
- type : 'expo' ,
56
- driver : require ( 'expo-sqlite' ) ,
57
- database : 'veramo.sqlite' ,
58
- migrations : migrations ,
59
- migrationsRun : true ,
60
- logging : [ 'error' , 'info' , 'warn' ] ,
61
- entities : Entities ,
62
- } ) . initialize ( )
63
-
64
- // filename: src/veramo/setup.ts
65
-
66
- // ... imports & CONSTANTS & DB setup
67
-
68
- // Veramo agent setup
69
- export const agent = createAgent < IDIDManager & IKeyManager & IDataStore & IDataStoreORM > ( {
70
- plugins : [
71
- new KeyManager ( {
72
- store : new KeyStore ( dbConnection ) ,
73
- kms : {
74
- local : new KeyManagementSystem ( new PrivateKeyStore ( dbConnection , new SecretBox ( DB_ENCRYPTION_KEY ) ) ) ,
75
- } ,
76
- } ) ,
77
- new DIDManager ( {
78
- store : new DIDStore ( dbConnection ) ,
79
- defaultProvider : 'did:ethr:goerli' ,
80
- providers : {
81
- 'did:ethr:goerli' : new EthrDIDProvider ( {
82
- defaultKms : 'local' ,
83
- network : 'goerli' ,
84
- name : 'goerli' ,
85
- rpcUrl : 'https://goerli.infura.io/v3/' + INFURA_PROJECT_ID ,
86
- gas : 1000001 ,
87
- ttl : 31104001 ,
88
- } ) ,
89
- } ,
90
- } ) ,
91
- new DIDResolverPlugin ( {
92
- ...ethrDidResolver ( { infuraProjectId : INFURA_PROJECT_ID } ) , // and set it up to support `did:ethr`
49
+ type : 'expo' ,
50
+ driver : require ( 'expo-sqlite' ) ,
51
+ database : 'veramo.sqlite' ,
52
+ migrations : migrations ,
53
+ migrationsRun : true ,
54
+ logging : [ 'error' , 'info' , 'warn' ] ,
55
+ entities : Entities ,
56
+ } ) . initialize ( )
57
+
58
+ // Veramo agent setup
59
+ export const agent = createAgent < IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & ICredentialIssuer & ICredentialVerifier > ( {
60
+ plugins : [
61
+ new KeyManager ( {
62
+ store : new KeyStore ( dbConnection ) ,
63
+ kms : {
64
+ local : new KeyManagementSystem ( new PrivateKeyStore ( dbConnection , new SecretBox ( DB_ENCRYPTION_KEY ) ) ) ,
65
+ } ,
66
+ } ) ,
67
+ new DIDManager ( {
68
+ store : new DIDStore ( dbConnection ) ,
69
+ defaultProvider : 'did:peer' ,
70
+ providers : {
71
+ 'did:peer' : new PeerDIDProvider ( {
72
+ defaultKms : 'local'
73
+ } ) ,
74
+ } ,
75
+ } ) ,
76
+ new DIDResolverPlugin ( {
77
+ ...peerDidResolver ( ) , // and set it up to support `did:peer`
93
78
...webDidResolver ( ) , // and `did:web`
94
79
} ) ,
95
- ] ,
96
- } )
80
+ new CredentialPlugin ( ) ,
81
+ ] ,
82
+ } )
0 commit comments