@@ -17,14 +17,14 @@ import { v4 as uuidv4 } from "uuid";
17
17
export async function spinUpEVault (
18
18
registryUrl : string ,
19
19
provisionerUrl : string ,
20
- verificationCode ?: string
20
+ verificationCode ?: string ,
21
21
) : Promise < { w3id : string ; uri : string } > {
22
22
const DEMO_CODE_W3DS = "d66b7138-538a-465f-a6ce-f6985854c3f4" ;
23
23
const finalVerificationCode = verificationCode || DEMO_CODE_W3DS ;
24
24
25
25
try {
26
26
const entropyResponse = await axios . get (
27
- new URL ( "/entropy" , registryUrl ) . toString ( )
27
+ new URL ( "/entropy" , registryUrl ) . toString ( ) ,
28
28
) ;
29
29
const registryEntropy = entropyResponse . data . token ;
30
30
@@ -36,11 +36,13 @@ export async function spinUpEVault(
36
36
registryEntropy,
37
37
namespace,
38
38
verificationId : finalVerificationCode ,
39
- }
39
+ } ,
40
40
) ;
41
41
42
42
if ( ! provisionResponse . data . success ) {
43
- throw new Error ( `Failed to provision eVault: ${ provisionResponse . data . message || 'Unknown error' } ` ) ;
43
+ throw new Error (
44
+ `Failed to provision eVault: ${ provisionResponse . data . message || "Unknown error" } ` ,
45
+ ) ;
44
46
}
45
47
46
48
return {
@@ -49,9 +51,13 @@ export async function spinUpEVault(
49
51
} ;
50
52
} catch ( error ) {
51
53
if ( axios . isAxiosError ( error ) ) {
52
- throw new Error ( `Failed to spin up eVault: ${ error . response ?. data ?. message || error . message } ` ) ;
54
+ throw new Error (
55
+ `Failed to spin up eVault: ${ error . response ?. data ?. message || error . message } ` ,
56
+ ) ;
53
57
}
54
- throw new Error ( `Failed to spin up eVault: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
58
+ throw new Error (
59
+ `Failed to spin up eVault: ${ error instanceof Error ? error . message : "Unknown error" } ` ,
60
+ ) ;
55
61
}
56
62
}
57
63
@@ -91,32 +97,40 @@ export async function createGroupEVault(
91
97
owner : string ;
92
98
charter ?: string ;
93
99
} ,
94
- verificationCode ?: string
100
+ verificationCode ?: string ,
95
101
) : Promise < { w3id : string ; uri : string ; manifestId : string } > {
96
102
const DEMO_CODE_W3DS = "d66b7138-538a-465f-a6ce-f6985854c3f4" ;
97
103
const finalVerificationCode = verificationCode || DEMO_CODE_W3DS ;
98
104
99
105
try {
100
106
// Step 1: Spin up the eVault
101
- const evault = await spinUpEVault ( registryUrl , provisionerUrl , finalVerificationCode ) ;
102
-
107
+ const evault = await spinUpEVault (
108
+ registryUrl ,
109
+ provisionerUrl ,
110
+ finalVerificationCode ,
111
+ ) ;
112
+
103
113
// Step 2: Create GroupManifest with exponential backoff
104
114
const manifestId = await createGroupManifestWithRetry (
105
115
registryUrl ,
106
116
evault . w3id ,
107
- groupData
117
+ groupData ,
108
118
) ;
109
119
110
120
return {
111
121
w3id : evault . w3id ,
112
122
uri : evault . uri ,
113
- manifestId
123
+ manifestId,
114
124
} ;
115
125
} catch ( error ) {
116
126
if ( axios . isAxiosError ( error ) ) {
117
- throw new Error ( `Failed to create group eVault: ${ error . response ?. data ?. message || error . message } ` ) ;
127
+ throw new Error (
128
+ `Failed to create group eVault: ${ error . response ?. data ?. message || error . message } ` ,
129
+ ) ;
118
130
}
119
- throw new Error ( `Failed to create group eVault: ${ error instanceof Error ? error . message : 'Unknown error' } ` ) ;
131
+ throw new Error (
132
+ `Failed to create group eVault: ${ error instanceof Error ? error . message : "Unknown error" } ` ,
133
+ ) ;
120
134
}
121
135
}
122
136
@@ -135,10 +149,10 @@ async function createGroupManifestWithRetry(
135
149
owner : string ;
136
150
charter ?: string ;
137
151
} ,
138
- maxRetries = 10
152
+ maxRetries = 10 ,
139
153
) : Promise < string > {
140
154
const now = new Date ( ) . toISOString ( ) ;
141
-
155
+
142
156
const groupManifest : GroupManifest = {
143
157
eName : w3id ,
144
158
name : groupData . name ,
@@ -154,13 +168,15 @@ async function createGroupManifestWithRetry(
154
168
155
169
for ( let attempt = 1 ; attempt <= maxRetries ; attempt ++ ) {
156
170
try {
157
- console . log ( `Attempting to create GroupManifest in eVault (attempt ${ attempt } /${ maxRetries } )` ) ;
158
-
171
+ console . log (
172
+ `Attempting to create GroupManifest in eVault (attempt ${ attempt } /${ maxRetries } )` ,
173
+ ) ;
174
+
159
175
const response = await axios . get (
160
- new URL ( `resolve?w3id=${ w3id } ` , registryUrl ) . toString ( )
176
+ new URL ( `resolve?w3id=${ w3id } ` , registryUrl ) . toString ( ) ,
161
177
) ;
162
178
const endpoint = new URL ( "/graphql" , response . data . uri ) . toString ( ) ;
163
-
179
+
164
180
const { GraphQLClient } = await import ( "graphql-request" ) ;
165
181
const client = new GraphQLClient ( endpoint ) ;
166
182
@@ -186,23 +202,33 @@ async function createGroupManifestWithRetry(
186
202
} ;
187
203
}
188
204
189
- const result = await client . request < MetaEnvelopeResponse > ( STORE_META_ENVELOPE , {
190
- input : {
191
- ontology : "550e8400-e29b-41d4-a716-446655440001" , // GroupManifest schema ID
192
- payload : groupManifest ,
193
- acl : [ "*" ] ,
205
+ const result = await client . request < MetaEnvelopeResponse > (
206
+ STORE_META_ENVELOPE ,
207
+ {
208
+ input : {
209
+ ontology : "550e8400-e29b-41d4-a716-446655440001" , // GroupManifest schema ID
210
+ payload : groupManifest ,
211
+ acl : [ "*" ] ,
212
+ } ,
194
213
} ,
195
- } ) ;
214
+ ) ;
196
215
197
216
const manifestId = result . storeMetaEnvelope . metaEnvelope . id ;
198
- console . log ( "GroupManifest created successfully in eVault:" , manifestId ) ;
217
+ console . log (
218
+ "GroupManifest created successfully in eVault:" ,
219
+ manifestId ,
220
+ ) ;
199
221
return manifestId ;
200
-
201
222
} catch ( error ) {
202
- console . error ( `Failed to create GroupManifest in eVault (attempt ${ attempt } /${ maxRetries } ):` , error ) ;
223
+ console . error (
224
+ `Failed to create GroupManifest in eVault (attempt ${ attempt } /${ maxRetries } ):` ,
225
+ error ,
226
+ ) ;
203
227
204
228
if ( attempt === maxRetries ) {
205
- console . error ( "Max retries reached, giving up on GroupManifest creation" ) ;
229
+ console . error (
230
+ "Max retries reached, giving up on GroupManifest creation" ,
231
+ ) ;
206
232
throw error ;
207
233
}
208
234
@@ -229,7 +255,7 @@ export class Web3Adapter {
229
255
dbPath : string ;
230
256
registryUrl : string ;
231
257
platform : string ;
232
- provisionerUrl ?: string ;
258
+ provisionerUrl ?: string ;
233
259
} ,
234
260
) {
235
261
this . readPaths ( ) ;
@@ -277,8 +303,8 @@ export class Web3Adapter {
277
303
data . id as string ,
278
304
) ;
279
305
280
- if ( ! this . mapping [ tableName ] ) return
281
- console . log ( "We get here?" )
306
+ if ( ! this . mapping [ tableName ] ) return ;
307
+ console . log ( "We get here?" ) ;
282
308
// If we already have a mapping, use that global ID
283
309
if ( existingGlobalId ) {
284
310
if ( this . lockedIds . includes ( existingGlobalId ) ) return ;
@@ -372,15 +398,22 @@ export class Web3Adapter {
372
398
*/
373
399
async spinUpEVault (
374
400
verificationCode ?: string ,
375
- provisionerUrl ?: string
401
+ provisionerUrl ?: string ,
376
402
) : Promise < { w3id : string ; uri : string } > {
377
- const finalProvisionerUrl = provisionerUrl || this . config . provisionerUrl ;
378
-
403
+ const finalProvisionerUrl =
404
+ provisionerUrl || this . config . provisionerUrl ;
405
+
379
406
if ( ! finalProvisionerUrl ) {
380
- throw new Error ( "Provisioner URL is required. Please provide it in config or as parameter." ) ;
407
+ throw new Error (
408
+ "Provisioner URL is required. Please provide it in config or as parameter." ,
409
+ ) ;
381
410
}
382
411
383
- return spinUpEVault ( this . config . registryUrl , finalProvisionerUrl , verificationCode ) ;
412
+ return spinUpEVault (
413
+ this . config . registryUrl ,
414
+ finalProvisionerUrl ,
415
+ verificationCode ,
416
+ ) ;
384
417
}
385
418
386
419
/**
@@ -401,14 +434,22 @@ export class Web3Adapter {
401
434
charter ?: string ;
402
435
} ,
403
436
verificationCode ?: string ,
404
- provisionerUrl ?: string
437
+ provisionerUrl ?: string ,
405
438
) : Promise < { w3id : string ; uri : string ; manifestId : string } > {
406
- const finalProvisionerUrl = provisionerUrl || this . config . provisionerUrl ;
407
-
439
+ const finalProvisionerUrl =
440
+ provisionerUrl || this . config . provisionerUrl ;
441
+
408
442
if ( ! finalProvisionerUrl ) {
409
- throw new Error ( "Provisioner URL is required. Please provide it in config or as parameter." ) ;
443
+ throw new Error (
444
+ "Provisioner URL is required. Please provide it in config or as parameter." ,
445
+ ) ;
410
446
}
411
447
412
- return createGroupEVault ( this . config . registryUrl , finalProvisionerUrl , groupData , verificationCode ) ;
448
+ return createGroupEVault (
449
+ this . config . registryUrl ,
450
+ finalProvisionerUrl ,
451
+ groupData ,
452
+ verificationCode ,
453
+ ) ;
413
454
}
414
455
}
0 commit comments