Skip to content

Commit cf22525

Browse files
committed
fix: web3-adapter format
1 parent 3810775 commit cf22525

File tree

2 files changed

+88
-44
lines changed

2 files changed

+88
-44
lines changed

infrastructure/web3-adapter/src/evault/evault.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,10 @@ export class EVaultClient {
190190
private async requestPlatformToken(): Promise<TokenInfo> {
191191
try {
192192
const response = await fetch(
193-
new URL("/platforms/certification", this.registryUrl).toString(),
193+
new URL(
194+
"/platforms/certification",
195+
this.registryUrl,
196+
).toString(),
194197
{
195198
method: "POST",
196199
headers: {
@@ -204,7 +207,7 @@ export class EVaultClient {
204207
throw new Error(`HTTP error! status: ${response.status}`);
205208
}
206209

207-
const data = await response.json() as PlatformTokenResponse;
210+
const data = (await response.json()) as PlatformTokenResponse;
208211
const now = Date.now();
209212
const expiresAt = data.expiresAt || now + 3600000; // Default 1 hour
210213

infrastructure/web3-adapter/src/index.ts

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import { v4 as uuidv4 } from "uuid";
1717
export async function spinUpEVault(
1818
registryUrl: string,
1919
provisionerUrl: string,
20-
verificationCode?: string
20+
verificationCode?: string,
2121
): Promise<{ w3id: string; uri: string }> {
2222
const DEMO_CODE_W3DS = "d66b7138-538a-465f-a6ce-f6985854c3f4";
2323
const finalVerificationCode = verificationCode || DEMO_CODE_W3DS;
2424

2525
try {
2626
const entropyResponse = await axios.get(
27-
new URL("/entropy", registryUrl).toString()
27+
new URL("/entropy", registryUrl).toString(),
2828
);
2929
const registryEntropy = entropyResponse.data.token;
3030

@@ -36,11 +36,13 @@ export async function spinUpEVault(
3636
registryEntropy,
3737
namespace,
3838
verificationId: finalVerificationCode,
39-
}
39+
},
4040
);
4141

4242
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+
);
4446
}
4547

4648
return {
@@ -49,9 +51,13 @@ export async function spinUpEVault(
4951
};
5052
} catch (error) {
5153
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+
);
5357
}
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+
);
5561
}
5662
}
5763

@@ -91,32 +97,40 @@ export async function createGroupEVault(
9197
owner: string;
9298
charter?: string;
9399
},
94-
verificationCode?: string
100+
verificationCode?: string,
95101
): Promise<{ w3id: string; uri: string; manifestId: string }> {
96102
const DEMO_CODE_W3DS = "d66b7138-538a-465f-a6ce-f6985854c3f4";
97103
const finalVerificationCode = verificationCode || DEMO_CODE_W3DS;
98104

99105
try {
100106
// 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+
103113
// Step 2: Create GroupManifest with exponential backoff
104114
const manifestId = await createGroupManifestWithRetry(
105115
registryUrl,
106116
evault.w3id,
107-
groupData
117+
groupData,
108118
);
109119

110120
return {
111121
w3id: evault.w3id,
112122
uri: evault.uri,
113-
manifestId
123+
manifestId,
114124
};
115125
} catch (error) {
116126
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+
);
118130
}
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+
);
120134
}
121135
}
122136

@@ -135,10 +149,10 @@ async function createGroupManifestWithRetry(
135149
owner: string;
136150
charter?: string;
137151
},
138-
maxRetries = 10
152+
maxRetries = 10,
139153
): Promise<string> {
140154
const now = new Date().toISOString();
141-
155+
142156
const groupManifest: GroupManifest = {
143157
eName: w3id,
144158
name: groupData.name,
@@ -154,13 +168,15 @@ async function createGroupManifestWithRetry(
154168

155169
for (let attempt = 1; attempt <= maxRetries; attempt++) {
156170
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+
159175
const response = await axios.get(
160-
new URL(`resolve?w3id=${w3id}`, registryUrl).toString()
176+
new URL(`resolve?w3id=${w3id}`, registryUrl).toString(),
161177
);
162178
const endpoint = new URL("/graphql", response.data.uri).toString();
163-
179+
164180
const { GraphQLClient } = await import("graphql-request");
165181
const client = new GraphQLClient(endpoint);
166182

@@ -186,23 +202,33 @@ async function createGroupManifestWithRetry(
186202
};
187203
}
188204

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+
},
194213
},
195-
});
214+
);
196215

197216
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+
);
199221
return manifestId;
200-
201222
} 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+
);
203227

204228
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+
);
206232
throw error;
207233
}
208234

@@ -229,7 +255,7 @@ export class Web3Adapter {
229255
dbPath: string;
230256
registryUrl: string;
231257
platform: string;
232-
provisionerUrl?: string;
258+
provisionerUrl?: string;
233259
},
234260
) {
235261
this.readPaths();
@@ -277,8 +303,8 @@ export class Web3Adapter {
277303
data.id as string,
278304
);
279305

280-
if (!this.mapping[tableName]) return
281-
console.log("We get here?")
306+
if (!this.mapping[tableName]) return;
307+
console.log("We get here?");
282308
// If we already have a mapping, use that global ID
283309
if (existingGlobalId) {
284310
if (this.lockedIds.includes(existingGlobalId)) return;
@@ -372,15 +398,22 @@ export class Web3Adapter {
372398
*/
373399
async spinUpEVault(
374400
verificationCode?: string,
375-
provisionerUrl?: string
401+
provisionerUrl?: string,
376402
): Promise<{ w3id: string; uri: string }> {
377-
const finalProvisionerUrl = provisionerUrl || this.config.provisionerUrl;
378-
403+
const finalProvisionerUrl =
404+
provisionerUrl || this.config.provisionerUrl;
405+
379406
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+
);
381410
}
382411

383-
return spinUpEVault(this.config.registryUrl, finalProvisionerUrl, verificationCode);
412+
return spinUpEVault(
413+
this.config.registryUrl,
414+
finalProvisionerUrl,
415+
verificationCode,
416+
);
384417
}
385418

386419
/**
@@ -401,14 +434,22 @@ export class Web3Adapter {
401434
charter?: string;
402435
},
403436
verificationCode?: string,
404-
provisionerUrl?: string
437+
provisionerUrl?: string,
405438
): Promise<{ w3id: string; uri: string; manifestId: string }> {
406-
const finalProvisionerUrl = provisionerUrl || this.config.provisionerUrl;
407-
439+
const finalProvisionerUrl =
440+
provisionerUrl || this.config.provisionerUrl;
441+
408442
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+
);
410446
}
411447

412-
return createGroupEVault(this.config.registryUrl, finalProvisionerUrl, groupData, verificationCode);
448+
return createGroupEVault(
449+
this.config.registryUrl,
450+
finalProvisionerUrl,
451+
groupData,
452+
verificationCode,
453+
);
413454
}
414455
}

0 commit comments

Comments
 (0)