Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decoupling zome call signer logic from js-client #224

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 90 additions & 40 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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, ... }:
Expand All @@ -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
];
};
};
};
}
}
12 changes: 8 additions & 4 deletions src/api/app/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { decode, encode } from "@msgpack/msgpack";
import Emittery from "emittery";
import nacl from "tweetnacl";
import {
getHostZomeCallSigner,
getLauncherEnvironment,
isLauncher,
signZomeCallTauri,
Expand Down Expand Up @@ -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),
};
Expand Down
9 changes: 9 additions & 0 deletions src/environments/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ export interface LauncherEnvironment {
INSTALLED_APP_ID?: InstalledAppId;
}

export interface HostZomeCallSigner {
signZomeCall: (request: CallZomeRequest) => Promise<CallZomeRequestSigned>;
}

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;

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;
}
}

Expand Down
Loading