@@ -5,14 +5,21 @@ import signify, {
5
5
messagize ,
6
6
d ,
7
7
Siger ,
8
- } from '../src/index. ts' ;
8
+ } from 'signify- ts' ;
9
9
10
- export function createTimestamp ( ) {
10
+ const URL = 'http://127.0.0.1:3901' ;
11
+ const BOOT_URL = 'http://127.0.0.1:3903' ;
12
+ const SCHEMA_SAID = 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao' ;
13
+ const WITNESS_AIDS : string [ ] = [ ] ; // ['BBilc4-L3tFUnfM_wJr4S4OJanAv_VmF_dJNN6vkf2Ha'];
14
+ const SCHEMA_OOBI =
15
+ 'http://vlei-server:7723/oobi/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao' ;
16
+
17
+ function createTimestamp ( ) {
11
18
const dt = new Date ( ) . toISOString ( ) . replace ( 'Z' , '000+00:00' ) ;
12
19
return dt ;
13
20
}
14
21
15
- export async function connect ( url : string , bootUrl : string ) {
22
+ async function connect ( url : string , bootUrl : string ) {
16
23
const client = new signify . SignifyClient (
17
24
url ,
18
25
signify . randomPasscode ( ) ,
@@ -26,7 +33,7 @@ export async function connect(url: string, bootUrl: string) {
26
33
return client ;
27
34
}
28
35
29
- export async function createIdentifier (
36
+ async function createIdentifier (
30
37
client : signify . SignifyClient ,
31
38
name : string ,
32
39
witnesses : string [ ]
@@ -48,15 +55,15 @@ export async function createIdentifier(
48
55
return aid . prefix ;
49
56
}
50
57
51
- export async function getAgentOobi (
52
- client : SignifyClient ,
58
+ async function getAgentOobi (
59
+ client : signify . SignifyClient ,
53
60
name : string
54
61
) : Promise < string > {
55
62
const result = await client . oobis ( ) . get ( name , 'agent' ) ;
56
63
return result . oobis [ 0 ] ;
57
64
}
58
65
59
- export async function resolveOobi (
66
+ async function resolveOobi (
60
67
client : SignifyClient ,
61
68
oobi : string ,
62
69
alias : string
@@ -66,7 +73,7 @@ export async function resolveOobi(
66
73
await waitOperation ( client , op . name , 5000 ) ;
67
74
}
68
75
69
- export async function createRegistry (
76
+ async function createRegistry (
70
77
client : SignifyClient ,
71
78
name : string ,
72
79
registryName : string
@@ -82,7 +89,7 @@ export async function createRegistry(
82
89
return registries [ 0 ] ;
83
90
}
84
91
85
- export async function issueCredential (
92
+ async function issueCredential (
86
93
client : SignifyClient ,
87
94
name : string ,
88
95
args : { registry : string ; schema : string ; recipient : string ; data : unknown }
@@ -142,7 +149,7 @@ interface Notification {
142
149
a : { r : string ; d ?: string ; m ?: string } ;
143
150
}
144
151
145
- export async function waitForNotification (
152
+ async function waitForNotification (
146
153
client : SignifyClient ,
147
154
route : string
148
155
) : Promise < Notification > {
@@ -159,7 +166,7 @@ export async function waitForNotification(
159
166
}
160
167
}
161
168
162
- export async function admitCredential (
169
+ async function admitCredential (
163
170
client : SignifyClient ,
164
171
name : string ,
165
172
said : string ,
@@ -172,7 +179,7 @@ export async function admitCredential(
172
179
await client . ipex ( ) . submitAdmit ( name , admit , sigs , end , [ recipient ] ) ;
173
180
}
174
181
175
- export async function wait < T > ( fn : ( ) => Promise < T > , timeout : number = 10000 ) {
182
+ async function wait < T > ( fn : ( ) => Promise < T > , timeout : number = 10000 ) {
176
183
const start = Date . now ( ) ;
177
184
const errors : Error [ ] = [ ] ;
178
185
while ( Date . now ( ) - start < timeout ) {
@@ -188,7 +195,7 @@ export async function wait<T>(fn: () => Promise<T>, timeout: number = 10000) {
188
195
throw new RetryError ( `Retry failed after ${ Date . now ( ) - start } ms` , errors ) ;
189
196
}
190
197
191
- export async function waitOperation (
198
+ async function waitOperation (
192
199
client : SignifyClient ,
193
200
name : string ,
194
201
timeout ?: number
@@ -213,11 +220,75 @@ export async function waitOperation(
213
220
}
214
221
}
215
222
216
- export class RetryError extends Error {
223
+ class RetryError extends Error {
217
224
constructor (
218
225
message : string ,
219
226
public errors : Error [ ]
220
227
) {
221
228
super ( message ) ;
222
229
}
223
230
}
231
+
232
+ test (
233
+ 'Single issuer holder' ,
234
+ async ( ) => {
235
+ await signify . ready ( ) ;
236
+ const issuerClient = await connect ( URL , BOOT_URL ) ;
237
+ const holderClient = await connect ( URL , BOOT_URL ) ;
238
+
239
+ await issuerClient . state ( ) ;
240
+ await holderClient . state ( ) ;
241
+
242
+ // Create two identifiers, one for each client
243
+ const issuerPrefix = await createIdentifier (
244
+ issuerClient ,
245
+ 'issuer' ,
246
+ WITNESS_AIDS
247
+ ) ;
248
+ const holderPrefix = await createIdentifier (
249
+ holderClient ,
250
+ 'holder' ,
251
+ WITNESS_AIDS
252
+ ) ;
253
+
254
+ // Exchange OOBIs
255
+ const issuerOobi = await getAgentOobi ( issuerClient , 'issuer' ) ;
256
+ const holderOobi = await getAgentOobi ( holderClient , 'holder' ) ;
257
+ await resolveOobi ( issuerClient , holderOobi , 'holder' ) ;
258
+ await resolveOobi ( issuerClient , SCHEMA_OOBI , 'schema' ) ;
259
+ await resolveOobi ( holderClient , issuerOobi , 'issuer' ) ;
260
+ await resolveOobi ( holderClient , SCHEMA_OOBI , 'schema' ) ;
261
+
262
+ await createRegistry ( issuerClient , 'issuer' , 'vLEI' ) ;
263
+
264
+ const registires = await issuerClient . registries ( ) . list ( 'issuer' ) ;
265
+ await issueCredential ( issuerClient , 'issuer' , {
266
+ registry : registires [ 0 ] . regk ,
267
+ schema : SCHEMA_SAID ,
268
+ recipient : holderPrefix ,
269
+ data : {
270
+ LEI : '5493001KJTIIGC8Y1R17' ,
271
+ } ,
272
+ } ) ;
273
+
274
+ const grantNotification = await waitForNotification (
275
+ holderClient ,
276
+ '/exn/ipex/grant'
277
+ ) ;
278
+
279
+ await admitCredential (
280
+ holderClient ,
281
+ 'holder' ,
282
+ grantNotification . a . d ! ,
283
+ issuerPrefix
284
+ ) ;
285
+
286
+ await holderClient . notifications ( ) . mark ( grantNotification . i ) ;
287
+
288
+ await wait ( async ( ) => {
289
+ const creds = await holderClient . credentials ( ) . list ( ) ;
290
+ assert ( creds . length >= 1 ) ;
291
+ } ) ;
292
+ } ,
293
+ 1000 * 60 * 5
294
+ ) ;
0 commit comments