From 9cc193415292fed2cddce48710cc4054e882da35 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Fri, 12 Jan 2024 16:43:39 -0300 Subject: [PATCH] alert on web --- example-web/my-app/src/App.js | 2 ++ example-web/my-app/src/index.js | 17 +++++++++++++++++ src/pages/content/index.tsx | 2 ++ src/pages/dialog/signin.tsx | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/example-web/my-app/src/App.js b/example-web/my-app/src/App.js index 56b7d2a4..2cf0b771 100644 --- a/example-web/my-app/src/App.js +++ b/example-web/my-app/src/App.js @@ -12,6 +12,8 @@ function App() { window.postMessage({ type: "init-req-credential" }, "*"); }; + + return (
diff --git a/example-web/my-app/src/index.js b/example-web/my-app/src/index.js index 2cb1087e..4f26578e 100644 --- a/example-web/my-app/src/index.js +++ b/example-web/my-app/src/index.js @@ -4,6 +4,23 @@ import './index.css'; import App from './App'; const root = ReactDOM.createRoot(document.getElementById('root')); + +window.addEventListener( + "message", + (event) => { + // Accept messages only from same window + if (event.source !== window) { + return; + } + if (event.data.type && event.data.type === "signify-signature") { + + alert("Signed headers received\n"+ JSON.stringify(event.data.data.headers, null, 2)); + } + }, + false +); + + root.render( diff --git a/src/pages/content/index.tsx b/src/pages/content/index.tsx index 8a9f7b6d..be3f973a 100644 --- a/src/pages/content/index.tsx +++ b/src/pages/content/index.tsx @@ -33,6 +33,8 @@ window.addEventListener( "init-req-identifier" ); break; + default: + break; } } }, diff --git a/src/pages/dialog/signin.tsx b/src/pages/dialog/signin.tsx index 2868c146..86c7ee21 100644 --- a/src/pages/dialog/signin.tsx +++ b/src/pages/dialog/signin.tsx @@ -9,9 +9,10 @@ export const SigninItem = ({ signin }: { signin: any }): JSX.Element => { signin: signin, }, }); - alert("Signed headers received\n"+ JSON.stringify(headers.data.headers, null, 2)); const element = document.getElementById("__root"); if (element) element.remove(); + // Communicate headers to web page + window.postMessage({ type: "signify-signature", data: headers.data }, "*"); }; return (