Skip to content

Commit 23a7859

Browse files
committed
fix: preserve public key
1 parent 089fe25 commit 23a7859

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

infrastructure/evault-core/src/core/db/db.service.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,34 @@ export class DbService {
799799
}
800800
}
801801

802+
// Copy User node with public key if it exists
803+
try {
804+
const userResult = await this.runQueryInternal(
805+
`MATCH (u:User { eName: $eName }) RETURN u.publicKey AS publicKey`,
806+
{ eName },
807+
);
808+
809+
if (userResult.records.length > 0) {
810+
const publicKey = userResult.records[0].get("publicKey");
811+
if (publicKey) {
812+
console.log(
813+
`[MIGRATION] Copying User node with public key for eName: ${eName}`,
814+
);
815+
await targetDbService.runQuery(
816+
`MERGE (u:User { eName: $eName })
817+
SET u.publicKey = $publicKey`,
818+
{ eName, publicKey },
819+
);
820+
console.log(
821+
`[MIGRATION] User node with public key copied successfully`,
822+
);
823+
}
824+
}
825+
} catch (error) {
826+
console.error(`[MIGRATION ERROR] Failed to copy User node:`, error);
827+
// Don't fail the migration if User node copy fails
828+
}
829+
802830
console.log(
803831
`[MIGRATION] Successfully copied ${count} metaEnvelopes for eName: ${eName}`,
804832
);

platforms/emover-api/src/services/MigrationService.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,52 @@ export class MigrationService extends EventEmitter {
6969
message: "Provisioning new evault...",
7070
});
7171

72+
// Get public key from old evault
73+
console.log(
74+
`[MIGRATION] Retrieving public key from old evault for ${eName}`,
75+
);
76+
let publicKey = "0x0000000000000000000000000000000000000000"; // Default fallback
77+
78+
try {
79+
const whoisResponse = await axios.get(
80+
new URL("/whois", migration.oldEvaultUri || "").toString(),
81+
{
82+
headers: {
83+
"X-ENAME": eName,
84+
},
85+
},
86+
);
87+
if (whoisResponse.data.publicKey) {
88+
publicKey = whoisResponse.data.publicKey;
89+
console.log(
90+
`[MIGRATION] Retrieved public key from old evault: ${publicKey.substring(0, 20)}...`,
91+
);
92+
migration.logs += `[MIGRATION] Retrieved public key from old evault\n`;
93+
} else {
94+
console.warn(
95+
`[MIGRATION] No public key found in old evault, using default`,
96+
);
97+
migration.logs += `[MIGRATION] Warning: No public key found in old evault, using default\n`;
98+
}
99+
} catch (error) {
100+
console.error(
101+
`[MIGRATION ERROR] Failed to retrieve public key from old evault:`,
102+
error,
103+
);
104+
migration.logs += `[MIGRATION ERROR] Failed to retrieve public key, using default\n`;
105+
// Continue with default public key - don't fail the migration
106+
}
107+
72108
// Get entropy from registry
73109
const entropyResponse = await axios.get(
74110
new URL("/entropy", this.registryUrl).toString(),
75111
);
76112
const registryEntropy = entropyResponse.data.token;
77113

78-
// Provision new evault
114+
// Provision new evault with preserved public key
115+
console.log(
116+
`[MIGRATION] Provisioning new evault with public key: ${publicKey.substring(0, 20)}...`,
117+
);
79118
const provisionResponse = await axios.post(
80119
new URL("/provision", provisionerUrl).toString(),
81120
{
@@ -84,7 +123,7 @@ export class MigrationService extends EventEmitter {
84123
verificationId:
85124
process.env.DEMO_VERIFICATION_CODE ||
86125
"d66b7138-538a-465f-a6ce-f6985854c3f4",
87-
publicKey: "0x0000000000000000000000000000000000000000",
126+
publicKey: publicKey,
88127
},
89128
);
90129

@@ -103,8 +142,12 @@ export class MigrationService extends EventEmitter {
103142
migration.newEvaultId = evaultId;
104143
migration.newEvaultUri = uri;
105144
migration.logs += `[MIGRATION] New evault provisioned: ${evaultId}, URI: ${uri}\n`;
145+
migration.logs += `[MIGRATION] Public key preserved: ${publicKey.substring(0, 20)}...\n`;
106146
await this.migrationRepository.save(migration);
107147

148+
// Note: Public key will be copied automatically when copying metaEnvelopes
149+
// (User node is copied as part of the copyMetaEnvelopes operation)
150+
108151
console.log(
109152
`[MIGRATION] New evault provisioned: ${evaultId} for ${eName}`,
110153
);

0 commit comments

Comments
 (0)