-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVeramoSetup.ts
125 lines (109 loc) · 3.78 KB
/
VeramoSetup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Core interfaces
import { createAgent, IDIDManager, IResolver, IDataStore, IKeyManager, IMessageHandler } from "@veramo/core";
// Core identity manager plugin
import { DIDManager } from "@veramo/did-manager";
// Ethr did identity provider
import { EthrDIDProvider } from "@veramo/did-provider-ethr";
// Web did identity provider
import { WebDIDProvider } from "@veramo/did-provider-web";
// Core key manager plugin
import { KeyManager } from "@veramo/key-manager";
// ION did identity provider
import { IonDIDProvider } from "@veramo/did-provider-ion";
// Custom key management system for RN
import { KeyManagementSystem } from "@veramo/kms-local";
// Credential Issuer
import { CredentialIssuer, ICredentialIssuer } from "@veramo/credential-w3c";
import { ISelectiveDisclosure } from "@veramo/selective-disclosure";
import { IDIDComm } from "@veramo/did-comm";
// Custom resolvers
import { DIDResolverPlugin } from "@veramo/did-resolver";
import { Resolver } from "did-resolver";
import { getUniversalResolverFor } from "@veramo/did-resolver/build/universal-resolver";
import { getResolver as ethrDidResolver } from "ethr-did-resolver";
import { getResolver as webDidResolver } from "web-did-resolver";
import { getDidIonResolver } from "@veramo/did-provider-ion";
import { MessageHandler } from "@veramo/message-handler";
import { W3cMessageHandler } from "@veramo/credential-w3c";
import { JwtMessageHandler } from "@veramo/did-jwt";
// Storage plugin using TypeOrm
import { Entities, KeyStore, DIDStore, IDataStoreORM, DataStore, DataStoreORM } from "@veramo/data-store";
// TypeORM is installed with daf-typeorm
import { createConnection } from "typeorm";
// Load Environment Vars
import * as dotenv from "dotenv";
import { getDidKeyResolver, KeyDIDProvider } from "@veramo/did-provider-key";
dotenv.config();
// This will be the name for the local sqlite database for demo purposes
const DATABASE_FILE = "database.sqlite";
// You will need to get a project ID from infura https://www.infura.io
const INFURA_PROJECT_ID = process.env.INFURA_PROJECT_ID;
const dbConnection = createConnection({
type: "sqlite",
database: DATABASE_FILE,
synchronize: true,
logging: ["error", "info", "warn"],
entities: Entities,
});
export const veramoAgent = createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
ICredentialIssuer &
IMessageHandler &
IDIDComm &
ISelectiveDisclosure
>({
plugins: [
new KeyManager({
store: new KeyStore(dbConnection),
kms: {
local: new KeyManagementSystem(),
},
}),
new DIDManager({
store: new DIDStore(dbConnection),
defaultProvider: "did:ethr:rinkeby",
providers: {
"did:ethr:rinkeby": new EthrDIDProvider({
defaultKms: "local",
network: "rinkeby",
rpcUrl: "https://rinkeby.infura.io/v3/" + INFURA_PROJECT_ID,
}),
"did:web": new WebDIDProvider({
defaultKms: "local",
}),
"did:ion": new IonDIDProvider({
defaultKms: "local",
}),
"did:key": new KeyDIDProvider({
defaultKms: "local",
}),
},
}),
new DIDResolverPlugin({
resolver: new Resolver({
ethr: ethrDidResolver({
networks: [
{
name: "rinkeby",
rpcUrl: "https://rinkeby.infura.io/v3/" + INFURA_PROJECT_ID,
},
],
}).ethr,
web: webDidResolver().web,
ion: getDidIonResolver().ion,
key: getDidKeyResolver().key,
...getUniversalResolverFor(["io", "elem", "sov"]),
}),
}),
new CredentialIssuer(),
new MessageHandler({
messageHandlers: [new JwtMessageHandler(), new W3cMessageHandler()],
}),
new DataStore(dbConnection),
new DataStoreORM(dbConnection),
],
});