epistery 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/wallet.js +8 -2
- package/client/witness.js +38 -13
- package/package.json +1 -1
package/client/wallet.js
CHANGED
|
@@ -50,7 +50,12 @@ export class Wallet {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
// Factory method to create appropriate wallet type from saved data
|
|
53
|
+
// Factory method to create appropriate wallet type from saved data.
|
|
54
|
+
// The three rivet types — web3, browser (rivet), and fido — are the only
|
|
55
|
+
// valid identities. Anything else is a legacy/unsupported entry (e.g. the
|
|
56
|
+
// pre-2.0 plaintext "local" browser wallet, which is NOT a rivet). Return
|
|
57
|
+
// null rather than throw so one dead entry can't abort the whole load; the
|
|
58
|
+
// caller skips and purges it.
|
|
54
59
|
static async fromJSON(data, ethers) {
|
|
55
60
|
if (data.source === "web3") {
|
|
56
61
|
return await Web3Wallet.fromJSON(data, ethers);
|
|
@@ -59,7 +64,8 @@ export class Wallet {
|
|
|
59
64
|
} else if (data.source === "fido") {
|
|
60
65
|
return await FidoWallet.fromJSON(data, ethers);
|
|
61
66
|
}
|
|
62
|
-
|
|
67
|
+
console.warn(`[epistery] Ignoring unsupported wallet source: ${data.source}`);
|
|
68
|
+
return null;
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
// Abstract methods - must be implemented by subclasses
|
package/client/witness.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
Web3Wallet,
|
|
11
11
|
RivetWallet,
|
|
12
12
|
FidoWallet,
|
|
13
|
-
} from "./wallet.js?v=
|
|
13
|
+
} from "./wallet.js?v=8";
|
|
14
14
|
|
|
15
15
|
// Global ethers variable - will be loaded dynamically if needed
|
|
16
16
|
let ethers;
|
|
@@ -252,30 +252,55 @@ export default class Witness {
|
|
|
252
252
|
|
|
253
253
|
this.server = storageData.server;
|
|
254
254
|
|
|
255
|
-
//
|
|
255
|
+
// Purge legacy/unsupported wallets. Only the three rivet types (web3,
|
|
256
|
+
// browser "rivet", fido) may engage an epistery site. The pre-2.0 plaintext
|
|
257
|
+
// "local" browser wallet is NOT a rivet; scrub it from storage so no exposed
|
|
258
|
+
// private key is left behind (hygiene — the security is the rivet, not
|
|
259
|
+
// hiding this). A single legacy entry must never abort the load of the rest.
|
|
260
|
+
const RIVET_SOURCES = new Set(["web3", "rivet", "fido"]);
|
|
261
|
+
const before = storageData.wallets.length;
|
|
262
|
+
storageData.wallets = storageData.wallets.filter((w) =>
|
|
263
|
+
RIVET_SOURCES.has((w.wallet || w)?.source),
|
|
264
|
+
);
|
|
265
|
+
const purged = before - storageData.wallets.length;
|
|
266
|
+
if (
|
|
267
|
+
purged > 0 &&
|
|
268
|
+
!storageData.wallets.some((w) => w.id === storageData.defaultWalletId)
|
|
269
|
+
) {
|
|
270
|
+
storageData.defaultWalletId = storageData.wallets[0]?.id || null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Persist when we migrated the old single-wallet format OR purged a legacy
|
|
274
|
+
// wallet — either way the on-disk shape must reflect what we just normalized.
|
|
256
275
|
const currentData = localStorage.getItem("epistery");
|
|
257
276
|
if (currentData) {
|
|
258
277
|
const parsed = JSON.parse(currentData);
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
278
|
+
const migrated =
|
|
279
|
+
parsed.wallet && !parsed.wallets && storageData.wallets.length > 0;
|
|
280
|
+
if (migrated || purged > 0) {
|
|
281
|
+
if (purged > 0) {
|
|
282
|
+
console.warn(
|
|
283
|
+
`[epistery] Purged ${purged} legacy non-rivet wallet(s) from storage.`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
264
286
|
localStorage.setItem("epistery", JSON.stringify(storageData));
|
|
265
|
-
console.log("[epistery] Migration complete - wallet preserved");
|
|
266
287
|
}
|
|
267
288
|
}
|
|
268
289
|
|
|
269
|
-
// Load the default wallet if it exists
|
|
290
|
+
// Load the default wallet if it exists. fromJSON returns null for an
|
|
291
|
+
// unsupported source — skip rather than crash.
|
|
270
292
|
if (storageData.defaultWalletId && ethers) {
|
|
271
293
|
const walletData = storageData.wallets.find(
|
|
272
294
|
(w) => w.id === storageData.defaultWalletId,
|
|
273
295
|
);
|
|
274
296
|
if (walletData) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
297
|
+
const wallet = await Wallet.fromJSON(walletData.wallet, ethers);
|
|
298
|
+
if (wallet) {
|
|
299
|
+
this.wallet = wallet;
|
|
300
|
+
this.wallet.id = walletData.id;
|
|
301
|
+
this.wallet.label = walletData.label;
|
|
302
|
+
this.wallet.createdAt = walletData.createdAt;
|
|
303
|
+
}
|
|
279
304
|
}
|
|
280
305
|
}
|
|
281
306
|
}
|
package/package.json
CHANGED