forked from linera-io/linera-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate trusted from untrusted client calls
- Loading branch information
Showing
7 changed files
with
87 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type CallRequest = { | ||
type: "client_call"; | ||
arguments: [any]; | ||
function: string; | ||
}; | ||
|
||
export async function callClientFunction(name: string, ...args: any): Promise<any> { | ||
return await chrome.runtime.sendMessage({ | ||
type: "client_call", | ||
function: name, | ||
arguments: args, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,43 @@ | ||
import './setup.ts'; | ||
import * as wasm from './client/linera_web.js'; | ||
import initWasm from './client/linera_web.js'; | ||
|
||
import wasmModuleUrl from './client/linera_web_bg.wasm?url'; | ||
import * as messaging from '@/messaging'; | ||
|
||
chrome.sidePanel.setPanelBehavior({ | ||
openPanelOnActionClick: true, | ||
}).catch((error) => console.error(error)); | ||
|
||
chrome.runtime.onInstalled.addListener(async () => { | ||
const windowId = (await chrome.windows.getCurrent()).id; | ||
if (windowId === undefined) return; | ||
chrome.action.setPopup({ popup: "src/popup/welcome.html" }); | ||
await chrome.action.openPopup({ windowId }); | ||
}); | ||
|
||
self.addEventListener("activate", async () => { | ||
await initWasm((await fetch(wasmModuleUrl)).arrayBuffer()); | ||
console.log("Client worker initialized"); | ||
}); | ||
|
||
chrome.runtime.onMessage.addListener((message: messaging.CallRequest, sender, respond) => { | ||
let functionName = message.function; | ||
|
||
if (sender.origin === self.location.origin) { | ||
console.log("Received message from extension", message); | ||
} else { | ||
console.log("Received message from content script", message); | ||
functionName = "dapp_" + functionName; | ||
} | ||
|
||
if (!(functionName in wasm)) { | ||
console.error("Attempted to call undefined function", functionName); | ||
return false; | ||
} | ||
|
||
let func = wasm[functionName as keyof typeof wasm] as (...args: any) => any; | ||
|
||
func.apply(wasm, message.arguments).then(respond); | ||
|
||
return true; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters