diff --git a/src/content/index.js b/src/content/index.js index b66b44c..ca0d31b 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -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; diff --git a/src/content/inpage.js b/src/content/inpage.js index 14b1fcf..2a2811c 100644 --- a/src/content/inpage.js +++ b/src/content/inpage.js @@ -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(); })();