@swimmingkiim/trust-sdk 0.1.32 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/agent.ts DELETED
@@ -1,99 +0,0 @@
1
- import { createAgent, IResolver, IDataStore, IKeyManager, IDIDManager, TAgent } from '@veramo/core'
2
- import { CredentialPlugin, ICredentialIssuer, ICredentialVerifier } from '@veramo/credential-w3c'
3
- import { DIDManager } from '@veramo/did-manager'
4
- import { EthrDIDProvider } from '@veramo/did-provider-ethr'
5
- import { KeyDIDProvider } from '@veramo/did-provider-key'
6
- import { DIDResolverPlugin } from '@veramo/did-resolver'
7
- import { KeyManager } from '@veramo/key-manager'
8
- import { KeyManagementSystem, SecretBox } from '@veramo/kms-local'
9
- import { Entities, KeyStore, DIDStore, PrivateKeyStore, IDataStoreORM, DataStore, DataStoreORM } from '@veramo/data-store'
10
- import { Resolver } from 'did-resolver'
11
- import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
12
- import { getResolver as keyDidResolver } from 'key-did-resolver'
13
- import { DataSource } from 'typeorm'
14
- import 'reflect-metadata'
15
-
16
- export type Agent = TAgent<IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & ICredentialIssuer & ICredentialVerifier>
17
-
18
- const DATABASE_FILE = '/tmp/database.sqlite'
19
- const SECRET_KEY = process.env.AGENT_SECRET_KEY
20
- if (!SECRET_KEY) {
21
- throw new Error("AGENT_SECRET_KEY environment variable is required")
22
- }
23
-
24
- // Database Configuration
25
- let dbConfig: any = {
26
- synchronize: true,
27
- logging: false,
28
- entities: Entities,
29
- };
30
-
31
- if (process.env.DB_HOST || process.env.INSTANCE_CONNECTION_NAME) {
32
- console.log('[Agent] Using PostgreSQL Database');
33
- dbConfig.type = 'postgres';
34
- if (process.env.INSTANCE_CONNECTION_NAME) {
35
- dbConfig.extra = {
36
- socketPath: `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`
37
- };
38
- } else {
39
- dbConfig.host = process.env.DB_HOST;
40
- dbConfig.port = Number(process.env.DB_PORT) || 5432;
41
- }
42
- dbConfig.username = process.env.DB_USER;
43
- dbConfig.password = process.env.DB_PASSWORD;
44
- dbConfig.database = process.env.DB_NAME;
45
- } else {
46
- console.log('[Agent] Using SQLite Database (Ephemeral)');
47
- dbConfig.type = 'sqlite';
48
- dbConfig.database = DATABASE_FILE;
49
- }
50
-
51
- const dbConnection = new DataSource(dbConfig)
52
-
53
- const DID_NETWORK = process.env.DID_NETWORK || 'base-sepolia';
54
- const RPC_URL = process.env.RPC_URL || 'https://sepolia.base.org';
55
-
56
- export const agent: Agent = createAgent<IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver & ICredentialIssuer & ICredentialVerifier>({
57
- plugins: [
58
- new KeyManager({
59
- store: new KeyStore(dbConnection),
60
- kms: {
61
- local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(SECRET_KEY))),
62
- },
63
- }),
64
- new DIDManager({
65
- store: new DIDStore(dbConnection),
66
- defaultProvider: 'did:key',
67
- providers: {
68
- 'did:ethr': new EthrDIDProvider({
69
- defaultKms: 'local',
70
- network: DID_NETWORK,
71
- rpcUrl: RPC_URL,
72
- }),
73
- 'did:key': new KeyDIDProvider({
74
- defaultKms: 'local',
75
- }),
76
- },
77
- }),
78
- new DIDResolverPlugin({
79
- resolver: new Resolver({
80
- ...ethrDidResolver({
81
- networks: [
82
- { name: DID_NETWORK, rpcUrl: RPC_URL }
83
- ]
84
- }),
85
- ...keyDidResolver(),
86
- }),
87
- }),
88
- new CredentialPlugin(),
89
- new DataStore(dbConnection),
90
- new DataStoreORM(dbConnection),
91
- ],
92
- })
93
-
94
- export const initAgent = async (): Promise<Agent> => {
95
- if (!dbConnection.isInitialized) {
96
- await dbConnection.initialize()
97
- }
98
- return agent
99
- }