Open turbocrime opened 9 months ago
Some initial thoughts:
@penumbra-zone/view-service
and that imports a ton of things itself, it's not a big deal.isomorphic code targeting standard browser DOM first
relates to the core of this issue and could be another unrelated issue about reducing offscreen api complexity.the transport, router, and services are not correctly delimited
current in-page transport dynamically creates an internal router, with a generated method per rpc endpoint. this can be simplified to a single stream and single unary transport method meeting the appropriate interface
Goal: ConnectRPC/Protobuf
ServiceImpl
s should be third-party hostablemy notes on this goal. read this as a conceptual sketch - suggestions, counterpoints, and disagreements welcome
brief
in the interest of an open ecosystem, we should make our service implementations directly useful to developers of complementary and alternative tools and wallets. this requires designing our implementations in such a way that they can operate as a 'drop-in' component within diverse environments.
current
our implementations are tightly coupled to our browser extension - they directly message and control lifecycle of extension documents, directly access extension sessionStorage and localStorage, and directly query indexedDb.
some functionality and types are imported from other packages, such as our types package, greatly obfuscating the dependency graph.
breakdown
approach
HandlerContext and contextValues
much of this can be achieved by using HandlerContext to access contextValues, instead of directly interacting with other parts of the extension. this makes awareness of the runtime the responsibility of the runtime adapter.
in routing-refactor, contextValues were used to simply inject broad storage access, to maintain existing use. now that routing-refactor has landed, it would be a good first step to begin abstracting storage access into context values.
it may be possible to use 'interceptors' configured by the adapter to inject things like interactive approval.
offscreen.html
in a chrome extension, offscreen.html is the appropriate location to run code targeting the standard browser dom.
this may seem like a drastic choice, but we are already entering services via the chrome runtime, which is the way into offscreen, so this would involve minimal change. either the connection manager or the adapter would become the new boundary. service implementations themselves would continue to operate identically, except for offscreenClient, which would no longer be necessary - handlers could just call wasm directly as needed.
offscreenClient would be removed, and the only offscreen lifecycle management necessary would become launch upon first client connection, and terminate upon last client close.
potential difficulty: access to @penumbra-zone/services functionality - but this should be minimized and abstracted.
when is the host responsible?
development of things like interactive transaction approval has been a complicated point for service impls, involving specialized tools located within the router package that manage things like document lifecycle and intra-extension messaging. impl awareness of extension architecture and message formats is a failure: it means we have tightly coupled the impl to our extension.
if the service implemenation needs some specific functionality from the host such as interactive approval, define a conceptually simple interface - hopefully a static object or Promise - that can be injected via context. the host is responsible for abstracting its design to meet that interface.