@holochain/hc-spin 0.400.0-dev.3 → 0.500.0-dev.0

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.
@@ -3,6 +3,3 @@ const electron = require("electron");
3
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@holochain/hc-spin",
3
- "version": "0.400.0-dev.3",
4
- "holochainVersion": "0.4.0-dev.16",
3
+ "version": "0.500.0-dev.0",
4
+ "holochainVersion": "0.5.0-dev.6",
5
5
  "description": "CLI to run Holochain aps during development.",
6
6
  "author": "matthme",
7
7
  "homepage": "https://developer.holochain.org",
@@ -35,14 +35,15 @@
35
35
  "dependencies": {
36
36
  "@electron-toolkit/preload": "^3.0.0",
37
37
  "@electron-toolkit/utils": "^3.0.0",
38
- "@holochain/client": "0.18.0-dev.0",
39
- "@holochain/hc-spin-rust-utils": "^0.300.1",
38
+ "@holochain/client": "0.19.0-dev.5",
39
+ "@holochain/hc-spin-rust-utils": "0.500.0-dev.0",
40
40
  "@msgpack/msgpack": "^2.8.0",
41
41
  "bufferutil": "4.0.8",
42
42
  "commander": "11.1.0",
43
43
  "electron": "^29.3.1",
44
44
  "electron-context-menu": "3.6.1",
45
45
  "get-port": "7.0.0",
46
+ "js-sha512": "^0.9.0",
46
47
  "nanoid": "5.0.4",
47
48
  "split": "1.0.1"
48
49
  },
package/src/main/index.ts CHANGED
@@ -6,7 +6,7 @@ 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 { ZomeCallNapi, ZomeCallSigner, ZomeCallUnsignedNapi } from '@holochain/hc-spin-rust-utils';
9
+ import { ZomeCallSigner } from '@holochain/hc-spin-rust-utils';
10
10
  import { createHappWindow } from './windows';
11
11
  import getPort from 'get-port';
12
12
  import {
@@ -21,6 +21,7 @@ import {
21
21
  import { validateCliArgs } from './validateArgs';
22
22
  import { encode } from '@msgpack/msgpack';
23
23
  import { menu } from './menu';
24
+ import { sha512 } from 'js-sha512';
24
25
 
25
26
  const rustUtils = require('@holochain/hc-spin-rust-utils');
26
27
 
@@ -128,50 +129,42 @@ contextMenu({
128
129
  ],
129
130
  });
130
131
 
131
- const handleSignZomeCall = async (e: IpcMainInvokeEvent, request: CallZomeRequest) => {
132
+ const handleSignZomeCall = async (
133
+ e: IpcMainInvokeEvent,
134
+ request: CallZomeRequest,
135
+ ): Promise<CallZomeRequestSigned> => {
132
136
  const windowInfo = WINDOW_INFO_MAP[e.sender.id];
137
+ if (!request.provenance)
138
+ return Promise.reject(
139
+ 'Call zome request has provenance field not set. This should be set by the js-client.',
140
+ );
133
141
  if (request.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
134
142
  return Promise.reject('Agent public key unauthorized.');
135
143
 
136
- // console.log("Got zome call request: ", request);
137
- const zomeCallUnsignedNapi: ZomeCallUnsignedNapi = {
138
- provenance: Array.from(request.provenance),
139
- cellId: [Array.from(request.cell_id[0]), Array.from(request.cell_id[1])],
140
- zomeName: request.zome_name,
141
- fnName: request.fn_name,
142
- payload: Array.from(encode(request.payload)),
143
- nonce: Array.from(await randomNonce()),
144
- expiresAt: getNonceExpiration(),
144
+ const zomeCallToSign: CallZomeRequest = {
145
+ cell_id: request.cell_id,
146
+ zome_name: request.zome_name,
147
+ fn_name: request.fn_name,
148
+ payload: encode(request.payload),
149
+ provenance: request.provenance,
150
+ nonce: await randomNonce(),
151
+ expires_at: getNonceExpiration(),
145
152
  };
146
153
 
147
- const zomeCallSignedNapi: ZomeCallNapi =
148
- await windowInfo.zomeCallSigner.signZomeCall(zomeCallUnsignedNapi);
149
-
150
- const zomeCallSigned: CallZomeRequestSigned = {
151
- provenance: Uint8Array.from(zomeCallSignedNapi.provenance),
152
- cap_secret: null,
153
- cell_id: [
154
- Uint8Array.from(zomeCallSignedNapi.cellId[0]),
155
- Uint8Array.from(zomeCallSignedNapi.cellId[1]),
156
- ],
157
- zome_name: zomeCallSignedNapi.zomeName,
158
- fn_name: zomeCallSignedNapi.fnName,
159
- payload: Uint8Array.from(zomeCallSignedNapi.payload),
160
- signature: Uint8Array.from(zomeCallSignedNapi.signature),
161
- expires_at: zomeCallSignedNapi.expiresAt,
162
- nonce: Uint8Array.from(zomeCallSignedNapi.nonce),
163
- };
154
+ const zomeCallBytes = encode(zomeCallToSign);
155
+ const bytesHash = sha512.array(zomeCallBytes);
164
156
 
165
- return zomeCallSigned;
166
- };
157
+ const signature: number[] = await windowInfo.zomeCallSigner.signZomeCall(
158
+ bytesHash,
159
+ Array.from(request.provenance),
160
+ );
167
161
 
168
- // https://github.com/holochain/holochain-client-js/issues/221
169
- const handleSignZomeCallLegacy = async (e: IpcMainInvokeEvent, request: ZomeCallUnsignedNapi) => {
170
- const windowInfo = WINDOW_INFO_MAP[e.sender.id];
171
- if (request.provenance.toString() !== Array.from(windowInfo.agentPubKey).toString())
172
- return Promise.reject('Agent public key unauthorized.');
162
+ const signedZomeCall: CallZomeRequestSigned = {
163
+ bytes: zomeCallBytes,
164
+ signature: Uint8Array.from(signature),
165
+ };
173
166
 
174
- return windowInfo.zomeCallSigner.signZomeCall(request);
167
+ return signedZomeCall;
175
168
  };
176
169
 
177
170
  async function startLocalServices(): Promise<[string, string]> {
@@ -288,7 +281,6 @@ async function spawnSandboxes(
288
281
  // Some APIs can only be used after this event occurs.
289
282
  app.whenReady().then(async () => {
290
283
  ipcMain.handle('sign-zome-call', handleSignZomeCall);
291
- ipcMain.handle('sign-zome-call-legacy', handleSignZomeCallLegacy);
292
284
 
293
285
  let happTargetDir: string | undefined;
294
286
  // TODO unpack assets to UI dir if webhapp is passed
@@ -1,15 +1,8 @@
1
1
  // See the Electron documentation for details on how to use preload scripts:
2
2
  // https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
3
+ import { CallZomeRequest } from '@holochain/client';
3
4
  import { contextBridge, ipcRenderer } from 'electron';
4
- import { ZomeCallUnsignedNapi } from '@holochain/hc-spin-rust-utils';
5
- import { CallZomeRequestUnsigned } from '@holochain/client';
6
5
 
7
6
  contextBridge.exposeInMainWorld('__HC_ZOME_CALL_SIGNER__', {
8
- signZomeCall: (zomeCall: CallZomeRequestUnsigned) =>
9
- ipcRenderer.invoke('sign-zome-call', zomeCall),
10
- });
11
-
12
- contextBridge.exposeInMainWorld('electronAPI', {
13
- signZomeCall: (zomeCall: ZomeCallUnsignedNapi) =>
14
- ipcRenderer.invoke('sign-zome-call-legacy', zomeCall),
7
+ signZomeCall: (zomeCall: CallZomeRequest) => ipcRenderer.invoke('sign-zome-call', zomeCall),
15
8
  });