diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/platform.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/platform.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/platform.js b/packages/meshbay-hub/src/meshbay_hub/static/platform.js index 8bf09b4..19f12a6 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/platform.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/platform.js @@ -508,9 +508,36 @@ export async function setUiLocale(code) { return bridge.setLocale(code); } +/** + * The account's keys, held by the desktop application's main process + * (`meshbay-client/src/keyring.js`): the bundle master key and the identity on + * every node. The page asks for public keys, signatures and agreements. + * + * Null in a browser. `available()` is false in the application too where the + * OS has no key storage — identities kept there and lost at the next start + * would strand the account on every node — and the page then keeps its keys as + * a browser does. + */ +let _keysAvailable = null; +export const keys = (bridge && bridge.keys) ? { + ...bridge.keys, + async available() { + if (_keysAvailable === null) { + try { _keysAvailable = Boolean(await bridge.keys.available()); } + catch { _keysAvailable = false; } + } + return _keysAvailable; + }, +} : null; + +/** Whether this page's keys are held by the application rather than here. */ +export async function nativeKeys() { + return Boolean(keys && await keys.available()); +} + export default { isNative, hubBase, capabilities, secrets, nativeSave, apiFetch, device, bridgeMessage, folder, rootPicker, node, - cast, minimizeToTray, setTrayLabels, setUiLocale }; + cast, minimizeToTray, setTrayLabels, setUiLocale, keys, nativeKeys }; // Also a global, because `transport.js` is loaded as a classic script — it // predates the module graph and exposes `MeshBayTransport` the same way. The @@ -520,5 +547,6 @@ if (typeof window !== 'undefined') { window.MeshBayPlatform = { isNative, hubBase, capabilities, secrets, nativeSave, apiFetch, device, bridgeMessage, folder, rootPicker, node, - cast, minimizeToTray, setTrayLabels, setUiLocale }; + cast, minimizeToTray, setTrayLabels, setUiLocale, + keys, nativeKeys }; } |