From d915eacc309be9d53d562c62b1108f6e2738af15 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 26 Jan 2024 16:08:44 +0100 Subject: [PATCH 1/2] decoupling zome call signer logic from js-client --- src/api/app/websocket.ts | 12 ++++++++---- src/environments/launcher.ts | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/api/app/websocket.ts b/src/api/app/websocket.ts index 83379788..4dbfa814 100644 --- a/src/api/app/websocket.ts +++ b/src/api/app/websocket.ts @@ -3,6 +3,7 @@ import { decode, encode } from "@msgpack/msgpack"; import Emittery from "emittery"; import nacl from "tweetnacl"; import { + getHostZomeCallSigner, getLauncherEnvironment, isLauncher, signZomeCallTauri, @@ -193,10 +194,13 @@ const callZomeTransform: Transformer< if ("signature" in request) { return request; } - const signedZomeCall = isLauncher - ? await signZomeCallTauri(request) - : await signZomeCall(request); - return signedZomeCall; + const hostSigner = getHostZomeCallSigner(); + if (hostSigner) { + return hostSigner.signZomeCall(request); + } else if (isLauncher) { + return signZomeCallTauri(request); + } + return signZomeCall(request); }, output: (response) => decode(response), }; diff --git a/src/environments/launcher.ts b/src/environments/launcher.ts index 9345b2d8..4f4c4725 100644 --- a/src/environments/launcher.ts +++ b/src/environments/launcher.ts @@ -15,7 +15,12 @@ export interface LauncherEnvironment { INSTALLED_APP_ID?: InstalledAppId; } +export interface HostZomeCallSigner { + signZomeCall: (request: CallZomeRequest) => Promise; +} + const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__"; +const __HC_ZOME_CALL_SIGNER__ = "__HC_ZOME_CALL_SIGNER__"; export const isLauncher = typeof window === "object" && __HC_LAUNCHER_ENV__ in window; @@ -23,9 +28,13 @@ export const isLauncher = export const getLauncherEnvironment = (): LauncherEnvironment | undefined => isLauncher ? window[__HC_LAUNCHER_ENV__] : undefined; +export const getHostZomeCallSigner = (): HostZomeCallSigner | undefined => + globalThis.window && globalThis.window[__HC_ZOME_CALL_SIGNER__]; + declare global { interface Window { [__HC_LAUNCHER_ENV__]: LauncherEnvironment | undefined; + [__HC_ZOME_CALL_SIGNER__]?: HostZomeCallSigner; } } From 7b3b19fd8c6c2a76cec120f4d553ae1c2e6e6bdf Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 26 Jan 2024 18:50:25 +0100 Subject: [PATCH 2/2] updated flake.nix --- flake.lock | 130 ++++++++++++++++++++++++++++++++++++----------------- flake.nix | 10 +++-- 2 files changed, 96 insertions(+), 44 deletions(-) diff --git a/flake.lock b/flake.lock index a8b82470..e0e242cc 100644 --- a/flake.lock +++ b/flake.lock @@ -61,11 +61,11 @@ "crate2nix": { "flake": false, "locked": { - "lastModified": 1675642992, - "narHash": "sha256-uDBDZuiq7qyg82Udp82/r4zg5HKfIzBQqgl2U9THiQM=", + "lastModified": 1693149153, + "narHash": "sha256-HUszQcnIal1FFRAWraODDbxTp0HECwczRTD+Zf0v9o0=", "owner": "kolloch", "repo": "crate2nix", - "rev": "45fc83132c8c91c77a1cd61fe0c945411d1edba8", + "rev": "8749f46953b46d44fd181b002399e4a20371f323", "type": "github" }, "original": { @@ -74,6 +74,22 @@ "type": "github" } }, + "empty": { + "flake": false, + "locked": { + "lastModified": 1683792623, + "narHash": "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo=", + "owner": "steveej", + "repo": "empty", + "rev": "8e328e450e4cd32e072eba9e99fe92cf2a1ef5cf", + "type": "github" + }, + "original": { + "owner": "steveej", + "repo": "empty", + "type": "github" + } + }, "flake-compat": { "flake": false, "locked": { @@ -139,12 +155,15 @@ } }, "flake-utils_2": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1659877975, - "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", "owner": "numtide", "repo": "flake-utils", - "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", "type": "github" }, "original": { @@ -156,16 +175,16 @@ "holochain": { "flake": false, "locked": { - "lastModified": 1675455504, - "narHash": "sha256-619bpPtO0IUSzPzLNzHERuvqGblpjO65rsw3jdxoEkQ=", + "lastModified": 1697824272, + "narHash": "sha256-4hkleGaiYeeUw2/rk/OSY1/eHejUstbvAhYmebq7eVQ=", "owner": "holochain", "repo": "holochain", - "rev": "ed5b7bb461c2a8bfd4d2633bad604a20b8f2da03", + "rev": "4e3eacc8473d9bef0467b3465f20c6f63eed636b", "type": "github" }, "original": { "owner": "holochain", - "ref": "holochain-0.1.3", + "ref": "holochain-0.1.7", "repo": "holochain", "type": "github" } @@ -176,40 +195,40 @@ "cargo-rdme": "cargo-rdme", "crane": "crane", "crate2nix": "crate2nix", + "empty": "empty", "flake-compat": "flake-compat_2", "flake-parts": "flake-parts", "holochain": [ "holonix", - "versions", - "holochain" + "empty" ], "lair": [ "holonix", - "versions", - "lair" + "empty" ], "launcher": [ "holonix", - "versions", - "launcher" + "empty" ], "nix-filter": "nix-filter", "nixpkgs": "nixpkgs", "pre-commit-hooks-nix": "pre-commit-hooks-nix", + "repo-git": "repo-git", "rust-overlay": "rust-overlay_2", "scaffolding": [ "holonix", - "versions", - "scaffolding" + "empty" ], - "versions": "versions" + "versions": [ + "versions" + ] }, "locked": { - "lastModified": 1677668983, - "narHash": "sha256-w/dx+Dp+IkdCUUstJREEAjvhpPLYsYRgDpxjtN+viS4=", + "lastModified": 1706272097, + "narHash": "sha256-ICC1YhFy5CJTJY+GlrtdgI1U75SxrFGkfyCF9mSrxz4=", "owner": "holochain", "repo": "holochain", - "rev": "c6573bcd88817d8adcddedba00d10a37c196b86f", + "rev": "a619123dd47d43cc0e0a647366612837520343ab", "type": "github" }, "original": { @@ -221,16 +240,16 @@ "lair": { "flake": false, "locked": { - "lastModified": 1670953460, - "narHash": "sha256-cqOr7iWzsNeomYQiiFggzG5Dr4X0ysnTkjtA8iwDLAQ=", + "lastModified": 1691746070, + "narHash": "sha256-CHsTI4yIlkfnYWx2sNgzAoDBvKTLIChybzyJNbB1sMU=", "owner": "holochain", "repo": "lair", - "rev": "cbfbefefe43073904a914c8181a450209a74167b", + "rev": "6ab41b60744515f1760669db6fc5272298a5f324", "type": "github" }, "original": { "owner": "holochain", - "ref": "lair_keystore-v0.2.3", + "ref": "lair_keystore-v0.3.0", "repo": "lair", "type": "github" } @@ -269,11 +288,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1677407201, - "narHash": "sha256-3blwdI9o1BAprkvlByHvtEm5HAIRn/XPjtcfiunpY7s=", + "lastModified": 1705856552, + "narHash": "sha256-JXfnuEf5Yd6bhMs/uvM67/joxYKoysyE3M2k6T3eWbg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7f5639fa3b68054ca0b062866dc62b22c3f11505", + "rev": "612f97239e2cc474c13c9dafa0df378058c5ad8d", "type": "github" }, "original": { @@ -316,13 +335,26 @@ "type": "github" } }, + "repo-git": { + "flake": false, + "locked": { + "narHash": "sha256-d6xi4mKdjkX2JFicDIv5niSzpyI0m/Hnm8GGAIU04kY=", + "type": "file", + "url": "file:/dev/null" + }, + "original": { + "type": "file", + "url": "file:/dev/null" + } + }, "root": { "inputs": { "holonix": "holonix", "nixpkgs": [ "holonix", "nixpkgs" - ] + ], + "versions": "versions" } }, "rust-overlay": { @@ -361,11 +393,11 @@ ] }, "locked": { - "lastModified": 1677638104, - "narHash": "sha256-vbdOoDYnQ1QYSchMb3fYGCLYeta3XwmGvMrlXchST5s=", + "lastModified": 1706235145, + "narHash": "sha256-3jh5nahTlcsX6QFcMPqxtLn9p9CgT9RSce5GLqjcpi4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "f388187efb41ce4195b2f4de0b6bb463d3cd0a76", + "rev": "3a57c4e29cb2beb777b2e6ae7309a680585b8b2f", "type": "github" }, "original": { @@ -377,11 +409,11 @@ "scaffolding": { "flake": false, "locked": { - "lastModified": 1677514461, - "narHash": "sha256-xflYnH6whXRqXFAqY2MHVXTWWcesn9OzZuyNhdXjsgo=", + "lastModified": 1705075437, + "narHash": "sha256-QKfavCQniePQBpgP/QuFfUhQvo7Sil8o57QGieu3Jt0=", "owner": "holochain", "repo": "scaffolding", - "rev": "c245d306110f3a5408f1dbe15d6a3725884ef3f4", + "rev": "58564c43bc2a03bf35731178c144015452dd6711", "type": "github" }, "original": { @@ -391,6 +423,21 @@ "type": "github" } }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "versions": { "inputs": { "holochain": "holochain", @@ -399,10 +446,13 @@ "scaffolding": "scaffolding" }, "locked": { - "lastModified": 1677514543, - "narHash": "sha256-SkVzM+QIfTZ0TuA9tuvF7ML9aLTdwNqzqrK5/TuCLlI=", - "path": "./versions/0_1", - "type": "path" + "dir": "versions/0_1", + "lastModified": 1706272097, + "narHash": "sha256-ICC1YhFy5CJTJY+GlrtdgI1U75SxrFGkfyCF9mSrxz4=", + "owner": "holochain", + "repo": "holochain", + "rev": "a619123dd47d43cc0e0a647366612837520343ab", + "type": "github" }, "original": { "dir": "versions/0_1", diff --git a/flake.nix b/flake.nix index 7149f8aa..3c31f65c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,8 +2,10 @@ description = "Nix shell for Holochain app development"; inputs = { - holonix.url = "github:holochain/holochain"; nixpkgs.follows = "holonix/nixpkgs"; + versions.url = "github:holochain/holochain?dir=versions/0_1"; + holonix.url = "github:holochain/holochain"; + holonix.inputs.versions.follows = "versions"; }; outputs = inputs@{ holonix, ... }: @@ -14,12 +16,12 @@ perSystem = { config, system, pkgs, ... }: { devShells.default = pkgs.mkShell { - inputsFrom = [ holonix.devShells.${system}.holonix ]; + inputsFrom = [ holonix.devShells.${system}.holochainBinaries ]; packages = with pkgs; [ # add further packages from nixpkgs - nodejs + # nodejs ]; }; }; }; -} +} \ No newline at end of file