-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathbbs.agent.test.ts
More file actions
160 lines (148 loc) · 4.81 KB
/
bbs.agent.test.ts
File metadata and controls
160 lines (148 loc) · 4.81 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// noinspection ES6PreferShortImport
/**
* This runs a suite of ./shared tests using an agent configured for local operations,
* using a SQLite db for storage of credentials, presentations, messages as well as keys and DIDs.
*
* This suite also runs a ganache local blockchain to run through some examples of DIDComm using did:ethr identifiers.
*/
import { createAgent } from '../packages/core/src/index.js'
import {
IAgentOptions,
ICredentialPlugin,
IDataStore,
IDataStoreORM,
IDIDManager,
IKeyManager,
IResolver,
TAgent,
} from '../packages/core-types/src/index.js'
import { DIDManager } from '../packages/did-manager/src/index.js'
import { DIDResolverPlugin } from '../packages/did-resolver/src/index.js'
import { CredentialPlugin } from '../packages/credential-w3c/src/index.js'
import { Resolver } from 'did-resolver'
import { EthrDIDProvider } from '../packages/did-provider-ethr/src/index.js'
import { KeyManagementSystem, SecretBox } from '../packages/kms-local/src/index.js'
import {
DataStoreORM,
DIDStore,
Entities,
KeyStore,
migrations,
PrivateKeyStore,
} from '../packages/data-store/src/index.js'
import { DataSource } from 'typeorm'
import { getResolver as ethrDidResolver } from 'ethr-did-resolver'
import * as fs from 'fs'
import { jest } from '@jest/globals'
import * as path from 'path';
import {
ContextDoc,
BbsDefaultContexts,
BbsSelectiveDisclosureCredentialPlugin,
CredentialProviderBBS,
CustomKeyManager,
VeramoBbsBlsSignature
} from '../packages/credential-bbs/src/index.js'
import citizenVocab from "../packages/credential-bbs/src/custom_contexts/citizenVocab.json"
// Shared tests
import verifiableDataBBS from './shared/verifiableDataBBS.js'
jest.setTimeout(120000)
// This will be the secret key for the KMS
const KMS_SECRET_KEY = '11b574d316903ced6cc3f4787bbcc3047d9c72d1da4d83e36fe714ef785d10c1'
jest.setTimeout(600000)
const customContext: Record<string, ContextDoc> = {
"https://w3id.org/citizenship/v1": citizenVocab,
}
let bbsContextMaps = [BbsDefaultContexts, customContext]
let bbsSuites = [new VeramoBbsBlsSignature()]
const bbs = new CredentialProviderBBS({
contextMaps: bbsContextMaps,
suites: bbsSuites
})
let dbConnection: any
let agent: TAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
ICredentialPlugin
>
let databaseFile: string
const database_test = path.normalize(path.resolve() + '/__tests__/fixtures/bbs_database_test.sqlite.tmp')
const setup = async (options?: IAgentOptions): Promise<boolean> => {
databaseFile = options?.context?.databaseFile || ':memory:'
dbConnection = new DataSource({
type: 'sqlite',
database: database_test,
synchronize: false,
migrations,
migrationsRun: true,
logging: ['error', 'info', 'warn'],
entities: [...Entities]
}).initialize()
agent = createAgent<IDIDManager & IKeyManager & IDataStore & IDataStoreORM & IResolver &
ICredentialPlugin>({
plugins: [
new CustomKeyManager({
store: new KeyStore(dbConnection),
kms: {
local: new KeyManagementSystem(new PrivateKeyStore(dbConnection, new SecretBox(KMS_SECRET_KEY))),
},
}),
new DIDManager({
store: new DIDStore(dbConnection),
defaultProvider: 'did:ethr:sepolia',
providers: {
'did:ethr:sepolia': new EthrDIDProvider({
defaultKms: 'local',
network: 'sepolia',
rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/fTk2Z4HtEe0uc2Lt73cIww13r4_REbj8',
name: 'sepolia',
registry: '0x03d5003bf0e79c5f5223588f347eba39afbc3818',
gas: 100000,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
})
},
}),
new DIDResolverPlugin({
resolver: new Resolver({
...ethrDidResolver(
{
networks: [
{
name: 'sepolia',
chainId: 11155111,
rpcUrl: 'https://eth-sepolia.g.alchemy.com/v2/fTk2Z4HtEe0uc2Lt73cIww13r4_REbj8',
registry: '0x03d5003bf0e79c5f5223588f347eba39afbc3818'
}
]
})
}),
}),
new CredentialPlugin({ issuers: [bbs] }),
new BbsSelectiveDisclosureCredentialPlugin({ contextMaps: bbsContextMaps, suites: bbsSuites }),
new DataStoreORM(dbConnection),
],
})
return true
}
const tearDown = async (): Promise<boolean> => {
try {
await (await dbConnection).dropDatabase()
await (await dbConnection).close()
} catch (e) {
// nop
}
try {
fs.unlinkSync(databaseFile)
} catch (e) {
// nop
}
return true
}
const getAgent = () => agent
const testContext = { getAgent, setup, tearDown }
describe('BBS Local integration tests', () => {
verifiableDataBBS(testContext)
})