L4: generate per-install EIP-6963 provider UUID

Replace the hardcoded UUID with a per-install UUID generated via
crypto.randomUUID() and persisted in chrome.storage.local. The content
script sends the UUID to the inpage script via postMessage, which
updates providerInfo and re-announces the provider.
This commit is contained in:
2026-02-27 11:39:37 -08:00
parent da58c81285
commit a6195730d9
2 changed files with 27 additions and 1 deletions

View File

@@ -13,6 +13,23 @@ if (typeof browser !== "undefined") {
(document.head || document.documentElement).appendChild(script);
}
// Generate a stable per-install provider UUID for EIP-6963 and send it to
// the inpage script via postMessage so it can update providerInfo.
const storageApi =
typeof browser !== "undefined" ? browser.storage : chrome.storage;
storageApi.local.get("providerUUID", (res) => {
let uuid = res.providerUUID;
if (!uuid) {
uuid = crypto.randomUUID();
storageApi.local.set({ providerUUID: uuid });
}
window.postMessage(
{ type: "AUTISTMASK_PROVIDER_UUID", uuid },
"*",
);
});
// Relay requests from the page to the background script
window.addEventListener("message", (event) => {
if (event.source !== window) return;

View File

@@ -156,7 +156,7 @@
);
const providerInfo = {
uuid: "f3c5b2a1-8d4e-4f6a-9c7b-1e2d3a4b5c6d",
uuid: crypto.randomUUID(),
name: "AutistMask",
icon: ICON_SVG,
rdns: "berlin.sneak.autistmask",
@@ -170,6 +170,15 @@
);
}
// Accept a stable per-install UUID from the content script.
// Re-announce with the updated providerInfo so dApps see the correct UUID.
window.addEventListener("message", (event) => {
if (event.source !== window) return;
if (event.data?.type !== "AUTISTMASK_PROVIDER_UUID") return;
providerInfo.uuid = event.data.uuid;
announceProvider();
});
window.addEventListener("eip6963:requestProvider", announceProvider);
announceProvider();
})();