@holochain/hc-spin 0.200.2 → 0.200.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,8 @@
1
1
  "use strict";
2
2
  const electron = require("electron");
3
- electron.contextBridge.exposeInMainWorld("electronAPI", {
3
+ electron.contextBridge.exposeInMainWorld("__HC_ZOME_CALL_SIGNER__", {
4
4
  signZomeCall: (zomeCall) => electron.ipcRenderer.invoke("sign-zome-call", zomeCall)
5
5
  });
6
+ electron.contextBridge.exposeInMainWorld("electronAPI", {
7
+ signZomeCall: (zomeCall) => electron.ipcRenderer.invoke("sign-zome-call-legacy", zomeCall)
8
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/hc-spin",
3
- "version": "0.200.2",
3
+ "version": "0.200.3",
4
4
  "description": "CLI to run Holochain aps during development.",
5
5
  "author": "matthme",
6
6
  "homepage": "https://developer.holochain.org",
@@ -28,6 +28,7 @@
28
28
  "electron-context-menu": "3.6.1",
29
29
  "get-port": "7.0.0",
30
30
  "@holochain/hc-spin-rust-utils": "0.200.2",
31
+ "@msgpack/msgpack": "^2.8.0",
31
32
  "nanoid": "5.0.4",
32
33
  "split": "1.0.1"
33
34
  },
package/src/main/index.ts CHANGED
@@ -6,11 +6,19 @@ import { Command, Option } from 'commander';
6
6
  import contextMenu from 'electron-context-menu';
7
7
  import split from 'split';
8
8
  import * as childProcess from 'child_process';
9
- import { ZomeCallSigner, ZomeCallUnsignedNapi } from '@holochain/hc-spin-rust-utils';
9
+ import { ZomeCallNapi, ZomeCallSigner, ZomeCallUnsignedNapi } from '@holochain/hc-spin-rust-utils';
10
10
  import { createHappWindow } from './windows';
11
11
  import getPort from 'get-port';
12
- import { AgentPubKey, AppWebsocket } from '@holochain/client';
12
+ import {
13
+ AgentPubKey,
14
+ AppWebsocket,
15
+ CallZomeRequest,
16
+ CallZomeRequestSigned,
17
+ getNonceExpiration,
18
+ randomNonce,
19
+ } from '@holochain/client';
13
20
  import { validateCliArgs } from './validateArgs';
21
+ import { encode } from '@msgpack/msgpack';
14
22
 
15
23
  const rustUtils = require('@holochain/hc-spin-rust-utils');
16
24
 
@@ -91,11 +99,50 @@ contextMenu({
91
99
  showInspectElement: true,
92
100
  });
93
101
 
94
- const handleSignZomeCall = (e: IpcMainInvokeEvent, zomeCall: ZomeCallUnsignedNapi) => {
102
+ const handleSignZomeCall = async (e: IpcMainInvokeEvent, request: CallZomeRequest) => {
95
103
  const windowInfo = WINDOW_INFO_MAP[e.sender.id];
96
- if (zomeCall.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
104
+ if (request.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
97
105
  return Promise.reject('Agent public key unauthorized.');
98
- return windowInfo.zomeCallSigner.signZomeCall(zomeCall);
106
+
107
+ // console.log("Got zome call request: ", request);
108
+ const zomeCallUnsignedNapi: ZomeCallUnsignedNapi = {
109
+ provenance: Array.from(request.provenance),
110
+ cellId: [Array.from(request.cell_id[0]), Array.from(request.cell_id[1])],
111
+ zomeName: request.zome_name,
112
+ fnName: request.fn_name,
113
+ payload: Array.from(encode(request.payload)),
114
+ nonce: Array.from(await randomNonce()),
115
+ expiresAt: getNonceExpiration(),
116
+ };
117
+
118
+ const zomeCallSignedNapi: ZomeCallNapi =
119
+ await windowInfo.zomeCallSigner.signZomeCall(zomeCallUnsignedNapi);
120
+
121
+ const zomeCallSigned: CallZomeRequestSigned = {
122
+ provenance: Uint8Array.from(zomeCallSignedNapi.provenance),
123
+ cap_secret: null,
124
+ cell_id: [
125
+ Uint8Array.from(zomeCallSignedNapi.cellId[0]),
126
+ Uint8Array.from(zomeCallSignedNapi.cellId[1]),
127
+ ],
128
+ zome_name: zomeCallSignedNapi.zomeName,
129
+ fn_name: zomeCallSignedNapi.fnName,
130
+ payload: Uint8Array.from(zomeCallSignedNapi.payload),
131
+ signature: Uint8Array.from(zomeCallSignedNapi.signature),
132
+ expires_at: zomeCallSignedNapi.expiresAt,
133
+ nonce: Uint8Array.from(zomeCallSignedNapi.nonce),
134
+ };
135
+
136
+ return zomeCallSigned;
137
+ };
138
+
139
+ // https://github.com/holochain/holochain-client-js/issues/221
140
+ const handleSignZomeCallLegacy = async (e: IpcMainInvokeEvent, request: ZomeCallUnsignedNapi) => {
141
+ const windowInfo = WINDOW_INFO_MAP[e.sender.id];
142
+ if (request.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
143
+ return Promise.reject('Agent public key unauthorized.');
144
+
145
+ return windowInfo.zomeCallSigner.signZomeCall(request);
99
146
  };
100
147
 
101
148
  async function startLocalServices(): Promise<[string, string]> {
@@ -212,6 +259,7 @@ async function spawnSandboxes(
212
259
  // Some APIs can only be used after this event occurs.
213
260
  app.whenReady().then(async () => {
214
261
  ipcMain.handle('sign-zome-call', handleSignZomeCall);
262
+ ipcMain.handle('sign-zome-call-legacy', handleSignZomeCallLegacy);
215
263
 
216
264
  let happTargetDir: string | undefined;
217
265
  // TODO unpack assets to UI dir if webhapp is passed
@@ -2,7 +2,14 @@
2
2
  // https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
3
3
  import { contextBridge, ipcRenderer } from 'electron';
4
4
  import { ZomeCallUnsignedNapi } from '@holochain/hc-spin-rust-utils';
5
+ import { CallZomeRequestUnsigned } from '@holochain/client';
6
+
7
+ contextBridge.exposeInMainWorld('__HC_ZOME_CALL_SIGNER__', {
8
+ signZomeCall: (zomeCall: CallZomeRequestUnsigned) =>
9
+ ipcRenderer.invoke('sign-zome-call', zomeCall),
10
+ });
5
11
 
6
12
  contextBridge.exposeInMainWorld('electronAPI', {
7
- signZomeCall: (zomeCall: ZomeCallUnsignedNapi) => ipcRenderer.invoke('sign-zome-call', zomeCall),
13
+ signZomeCall: (zomeCall: ZomeCallUnsignedNapi) =>
14
+ ipcRenderer.invoke('sign-zome-call-legacy', zomeCall),
8
15
  });