@holochain/client 0.18.0-dev.8 → 0.19.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.
package/README.md CHANGED
@@ -15,12 +15,12 @@ A JavaScript client for the Holochain Conductor API (works with browsers as well
15
15
 
16
16
  ## Installation
17
17
 
18
+ **JS client v0.19.x** is compatible with **Holochain v0.5.x**.
19
+
18
20
  **JS client v0.18.x** is compatible with **Holochain v0.4.x**.
19
21
 
20
22
  **JS client v0.17.x** is compatible with **Holochain v0.3.x**.
21
23
 
22
- **JS client v0.16.x** is compatible with **Holochain v0.2.x**.
23
-
24
24
  To install from NPM, run
25
25
  ```bash
26
26
  npm install --save-exact @holochain/client
@@ -180,6 +180,22 @@ export type GenerateAgentPubKeyRequest = void;
180
180
  * @public
181
181
  */
182
182
  export type GenerateAgentPubKeyResponse = AgentPubKey;
183
+ /**
184
+ * @public
185
+ */
186
+ export type RevokeAgentKeyRequest = {
187
+ agent_key: AgentPubKey;
188
+ app_id: InstalledAppId;
189
+ };
190
+ /**
191
+ * Contains a list of errors of the cells where deletion was unsuccessful.
192
+ *
193
+ * If the key could not be deleted from all cells, the call
194
+ * {@link RevokeAgentKeyRequest} can be re-attempted to delete the key from the remaining cells.
195
+ *
196
+ * @public
197
+ */
198
+ export type RevokeAgentKeyResponse = [CellId, string][];
183
199
  /**
184
200
  * @public
185
201
  */
@@ -398,8 +414,11 @@ export type NetworkSeed = string;
398
414
  export type InstallAppRequest = {
399
415
  /**
400
416
  * The agent to use when creating Cells for this App.
417
+ * If not specified, a new agent will be generated by Holochain.
418
+ * If DPKI is enabled (default), and the agent key is not specified here,
419
+ * a new agent key will be derived from the DPKI device seed and registered with DPKI.
401
420
  */
402
- agent_key: AgentPubKey;
421
+ agent_key?: AgentPubKey;
403
422
  /**
404
423
  * The unique identifier for an installed app in this conductor.
405
424
  * If not specified, it will be derived from the app name in the bundle manifest.
@@ -523,7 +542,7 @@ export interface DeleteCloneCellRequest {
523
542
  /**
524
543
  * The clone id or cell id of the clone cell
525
544
  */
526
- clone_cell_id: RoleName | CellId;
545
+ clone_cell_id: RoleName | DnaHash;
527
546
  }
528
547
  /**
529
548
  * @public
@@ -2,7 +2,7 @@ import { CapSecret, GrantedFunctions } from "../../hdk/index.js";
2
2
  import type { AgentPubKey, CellId } from "../../types.js";
3
3
  import { WsClient } from "../client.js";
4
4
  import { Requester, Transformer, WebsocketConnectionOptions } from "../common.js";
5
- import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpNetworkStatsRequest, DumpNetworkStatsResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetCompatibleCellsRequest, GetCompatibleCellsResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, IssueAppAuthenticationTokenRequest, IssueAppAuthenticationTokenResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, StorageInfoRequest, StorageInfoResponse, UninstallAppRequest, UninstallAppResponse, UpdateCoordinatorsRequest, UpdateCoordinatorsResponse } from "./types.js";
5
+ import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpNetworkStatsRequest, DumpNetworkStatsResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetCompatibleCellsRequest, GetCompatibleCellsResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, IssueAppAuthenticationTokenRequest, IssueAppAuthenticationTokenResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, RevokeAgentKeyRequest, RevokeAgentKeyResponse, StorageInfoRequest, StorageInfoResponse, UninstallAppRequest, UninstallAppResponse, UpdateCoordinatorsRequest, UpdateCoordinatorsResponse } from "./types.js";
6
6
  /**
7
7
  * A class for interacting with a conductor's Admin API.
8
8
  *
@@ -51,6 +51,10 @@ export declare class AdminWebsocket implements AdminApi {
51
51
  * Generate a new agent pub key.
52
52
  */
53
53
  generateAgentPubKey: Requester<GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse>;
54
+ /**
55
+ * Generate a new agent pub key.
56
+ */
57
+ revokeAgentKey: Requester<RevokeAgentKeyRequest, RevokeAgentKeyResponse>;
54
58
  /**
55
59
  * Register a DNA for later app installation.
56
60
  *
@@ -68,6 +68,10 @@ export class AdminWebsocket {
68
68
  * Generate a new agent pub key.
69
69
  */
70
70
  generateAgentPubKey = this._requester("generate_agent_pub_key");
71
+ /**
72
+ * Generate a new agent pub key.
73
+ */
74
+ revokeAgentKey = this._requester("revoke_agent_key");
71
75
  /**
72
76
  * Register a DNA for later app installation.
73
77
  *
@@ -1,5 +1,5 @@
1
1
  import { UnsubscribeFunction } from "emittery";
2
- import { AgentPubKey, AppAuthenticationToken, AppInfo, CapSecret, CellId, ClonedCell, DnaHash, DnaProperties, FunctionName, InstalledAppId, MembraneProof, MemproofMap, NetworkInfo, NetworkSeed, Nonce256Bit, RoleName, Timestamp, Transformer, WebsocketConnectionOptions, ZomeName } from "../../index.js";
2
+ import { AgentPubKey, AppAuthenticationToken, AppInfo, CapSecret, CellId, ClonedCell, DnaHash, DnaProperties, EntryHash, FunctionName, InstalledAppId, MembraneProof, MemproofMap, NetworkInfo, NetworkSeed, Nonce256Bit, RoleName, Timestamp, Transformer, WebsocketConnectionOptions, ZomeName } from "../../index.js";
3
3
  /**
4
4
  * @public
5
5
  */
@@ -40,7 +40,7 @@ export type AppNetworkInfoRequest = Omit<NetworkInfoRequest, "agent_pub_key">;
40
40
  * @public
41
41
  */
42
42
  export interface AppEvents {
43
- signal: AppSignal;
43
+ signal: Signal;
44
44
  }
45
45
  /**
46
46
  * @public
@@ -152,7 +152,7 @@ export interface DisableCloneCellRequest {
152
152
  /**
153
153
  * The clone id or cell id of the clone cell
154
154
  */
155
- clone_cell_id: RoleName | CellId;
155
+ clone_cell_id: RoleName | DnaHash;
156
156
  }
157
157
  /**
158
158
  * @public
@@ -193,10 +193,18 @@ export declare const SignalType: {
193
193
  /**
194
194
  * @public
195
195
  */
196
- export type Signal = {
196
+ export type RawSignal = {
197
197
  [SignalType.App]: EncodedAppSignal;
198
198
  } | {
199
- [SignalType.System]: unknown;
199
+ [SignalType.System]: SystemSignal;
200
+ };
201
+ /**
202
+ * @public
203
+ */
204
+ export type Signal = {
205
+ [SignalType.App]: AppSignal;
206
+ } | {
207
+ [SignalType.System]: SystemSignal;
200
208
  };
201
209
  /**
202
210
  * @public
@@ -217,7 +225,13 @@ export type AppSignal = {
217
225
  /**
218
226
  * @public
219
227
  */
220
- export type AppSignalCb = (signal: AppSignal) => void;
228
+ export type SystemSignal = {
229
+ SuccessfulCountersigning: EntryHash;
230
+ };
231
+ /**
232
+ * @public
233
+ */
234
+ export type SignalCb = (signal: Signal) => void;
221
235
  /**
222
236
  * @public
223
237
  */
@@ -227,7 +241,7 @@ export type NetworkInfoResponse = NetworkInfo[];
227
241
  */
228
242
  export interface AppClient {
229
243
  callZome(args: AppCallZomeRequest, timeout?: number): Promise<any>;
230
- on<Name extends keyof AppEvents>(eventName: Name | readonly Name[], listener: AppSignalCb): UnsubscribeFunction;
244
+ on<Name extends keyof AppEvents>(eventName: Name | readonly Name[], listener: SignalCb): UnsubscribeFunction;
231
245
  appInfo(): Promise<AppInfoResponse>;
232
246
  myPubKey: AgentPubKey;
233
247
  installedAppId: InstalledAppId;
@@ -1,7 +1,7 @@
1
1
  import { UnsubscribeFunction } from "emittery";
2
2
  import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
3
3
  import { AppInfo, MemproofMap } from "../admin/index.js";
4
- import { AppCallZomeRequest, AppClient, AppEvents, AppNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse, AppWebsocketConnectionOptions } from "./types.js";
4
+ import { AppCallZomeRequest, AppClient, AppEvents, AppNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest, SignalCb, CallZomeRequest, CallZomeRequestSigned, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse, AppWebsocketConnectionOptions } from "./types.js";
5
5
  import { WsClient } from "../client.js";
6
6
  /**
7
7
  * A class to establish a websocket connection to an App interface, for a
@@ -101,7 +101,7 @@ export declare class AppWebsocket implements AppClient {
101
101
  * @param listener - The function to call when event is triggered.
102
102
  * @returns A function to unsubscribe the event listener.
103
103
  */
104
- on<Name extends keyof AppEvents>(eventName: Name | readonly Name[], listener: AppSignalCb): UnsubscribeFunction;
104
+ on<Name extends keyof AppEvents>(eventName: Name | readonly Name[], listener: SignalCb): UnsubscribeFunction;
105
105
  private static requester;
106
106
  private containsCell;
107
107
  }
@@ -57,9 +57,7 @@ export class AppWebsocket {
57
57
  }
58
58
  });
59
59
  this.client.on("signal", (signal) => {
60
- if (this.containsCell(signal.cell_id)) {
61
- this.emitter.emit("signal", signal).catch(console.error);
62
- }
60
+ this.emitter.emit("signal", signal).catch(console.error);
63
61
  });
64
62
  }
65
63
  /**
package/lib/api/client.js CHANGED
@@ -52,18 +52,21 @@ export class WsClient extends Emittery {
52
52
  const deserializedSignal = decode(message.data);
53
53
  assertHolochainSignal(deserializedSignal);
54
54
  if (SignalType.System in deserializedSignal) {
55
- // We have received a system signal, do nothing
56
- return;
55
+ this.emit("signal", {
56
+ System: deserializedSignal[SignalType.System],
57
+ });
58
+ }
59
+ else {
60
+ const encodedAppSignal = deserializedSignal[SignalType.App];
61
+ // In order to return readable content to the UI, the signal payload must also be deserialized.
62
+ const payload = decode(encodedAppSignal.signal);
63
+ const signal = {
64
+ cell_id: encodedAppSignal.cell_id,
65
+ zome_name: encodedAppSignal.zome_name,
66
+ payload,
67
+ };
68
+ this.emit("signal", { App: signal });
57
69
  }
58
- const encodedAppSignal = deserializedSignal[SignalType.App];
59
- // In order to return readable content to the UI, the signal payload must also be deserialized.
60
- const payload = decode(encodedAppSignal.signal);
61
- const signal = {
62
- cell_id: encodedAppSignal.cell_id,
63
- zome_name: encodedAppSignal.zome_name,
64
- payload,
65
- };
66
- this.emit("signal", signal);
67
70
  }
68
71
  else if (message.type === "response") {
69
72
  this.handleResponse(message);
@@ -18,6 +18,23 @@ export interface PreflightRequest {
18
18
  action_base: ActionBase;
19
19
  preflight_bytes: PreflightBytes;
20
20
  }
21
+ /**
22
+ * @public
23
+ */
24
+ export interface PreflightResponse {
25
+ /**
26
+ * The request associated with this response.
27
+ */
28
+ request: PreflightRequest;
29
+ /**
30
+ * The chain state declaration for the agent that produced this response.
31
+ */
32
+ agent_state: CountersigningAgentState;
33
+ /**
34
+ * The signature of this response, by the agent that created it.
35
+ */
36
+ signature: Signature;
37
+ }
21
38
  /**
22
39
  * @public
23
40
  */
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.47.0"
8
+ "packageVersion": "7.47.9"
9
9
  }
10
10
  ]
11
11
  }
@@ -0,0 +1,11 @@
1
+ import { CellId } from "../types.js";
2
+ /**
3
+ * Check if two cell ids are identical.
4
+ *
5
+ * @param cellId1 - Cell id 1 to compare.
6
+ * @param cellId2 - Cell id 1 to compare.
7
+ * @returns True if the cell ids are identical.
8
+ *
9
+ * @public
10
+ */
11
+ export declare const isSameCell: (cellId1: CellId, cellId2: CellId) => boolean;
@@ -0,0 +1,17 @@
1
+ import { encodeHashToBase64 } from "./base64.js";
2
+ /**
3
+ * Check if two cell ids are identical.
4
+ *
5
+ * @param cellId1 - Cell id 1 to compare.
6
+ * @param cellId2 - Cell id 1 to compare.
7
+ * @returns True if the cell ids are identical.
8
+ *
9
+ * @public
10
+ */
11
+ export const isSameCell = (cellId1, cellId2) => {
12
+ const dnaHashB64_1 = encodeHashToBase64(cellId1[0]);
13
+ const agentPubKeyB64_1 = encodeHashToBase64(cellId1[1]);
14
+ const dnaHashB64_2 = encodeHashToBase64(cellId2[0]);
15
+ const agentPubKeyB64_2 = encodeHashToBase64(cellId2[1]);
16
+ return dnaHashB64_1 === dnaHashB64_2 && agentPubKeyB64_1 === agentPubKeyB64_2;
17
+ };
@@ -1,3 +1,4 @@
1
1
  export * from "./base64.js";
2
2
  export * from "./fake-hash.js";
3
3
  export * from "./hash-parts.js";
4
+ export * from "./cell.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./base64.js";
2
2
  export * from "./fake-hash.js";
3
3
  export * from "./hash-parts.js";
4
+ export * from "./cell.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain/client",
3
- "version": "0.18.0-dev.8",
3
+ "version": "0.19.0-dev.0",
4
4
  "description": "A JavaScript client for the Holochain Conductor API",
5
5
  "author": "Holochain Foundation <info@holochain.org> (https://holochain.org)",
6
6
  "license": "CAL-1.0",