@holochain/client 0.12.7 → 0.12.8

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,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Action, DhtOp, Entry, ZomeCallCapGrant } from "../../hdk/index.js";
2
3
  import { ActionHash, AgentPubKey, CellId, DnaHash, DnaProperties, Duration, HoloHash, HoloHashB64, InstalledAppId, KitsuneAgent, KitsuneSpace, RoleName, Signature, Timestamp, WasmHash } from "../../types.js";
3
4
  import { Requester } from "../common.js";
@@ -6,7 +7,7 @@ import { DisableCloneCellRequest } from "../index.js";
6
7
  * @public
7
8
  */
8
9
  export type AttachAppInterfaceRequest = {
9
- port?: number;
10
+ port: number;
10
11
  };
11
12
  /**
12
13
  * @public
@@ -126,7 +127,7 @@ export type AppInfo = {
126
127
  /**
127
128
  * @public
128
129
  */
129
- export type MembraneProof = Uint8Array;
130
+ export type MembraneProof = Buffer;
130
131
  /**
131
132
  * @public
132
133
  */
@@ -162,7 +163,7 @@ export type DumpStateResponse = any;
162
163
  */
163
164
  export type DumpFullStateRequest = {
164
165
  cell_id: CellId;
165
- dht_ops_cursor?: number;
166
+ dht_ops_cursor: number | undefined;
166
167
  };
167
168
  /**
168
169
  * @public
@@ -194,7 +195,7 @@ export type RegisterDnaResponse = HoloHash;
194
195
  */
195
196
  export type DnaModifiers = {
196
197
  network_seed: NetworkSeed;
197
- properties: Uint8Array;
198
+ properties: DnaProperties;
198
199
  origin_time: Timestamp;
199
200
  quantum_time: Duration;
200
201
  };
@@ -251,16 +252,6 @@ export type UninstallAppRequest = {
251
252
  * @public
252
253
  */
253
254
  export type UninstallAppResponse = null;
254
- /**
255
- * @public
256
- */
257
- export type UpdateCoordinatorsRequest = {
258
- dna_hash: DnaHash;
259
- } & CoordinatorSource;
260
- /**
261
- * @public
262
- */
263
- export type UpdateCoordinatorsResponse = void;
264
255
  /**
265
256
  * @public
266
257
  */
@@ -382,33 +373,12 @@ export type NetworkSeed = string;
382
373
  * @public
383
374
  */
384
375
  export type InstallAppRequest = {
385
- /**
386
- * The agent to use when creating Cells for this App.
387
- */
388
376
  agent_key: AgentPubKey;
389
- /**
390
- * The unique identifier for an installed app in this conductor.
391
- * If not specified, it will be derived from the app name in the bundle manifest.
392
- */
393
377
  installed_app_id?: InstalledAppId;
394
- /**
395
- * Include proof-of-membrane-membership data for cells that require it,
396
- * keyed by the CellNick specified in the app bundle manifest.
397
- */
398
378
  membrane_proofs: {
399
379
  [key: string]: MembraneProof;
400
380
  };
401
- /**
402
- * Optional global network seed override. If set will override the network seed value for all
403
- * DNAs in the bundle.
404
- */
405
381
  network_seed?: NetworkSeed;
406
- /**
407
- * Optional: If app installation fails due to genesis failure, normally the app will be immediately uninstalled.
408
- * When this flag is set, the app is left installed with empty cells intact. This can be useful for
409
- * using graft_records_onto_source_chain, or for diagnostics.
410
- */
411
- ignore_genesis_failure?: boolean;
412
382
  } & AppBundleSource;
413
383
  /**
414
384
  * @public
@@ -530,41 +500,13 @@ export type InstallAppDnaPayload = {
530
500
  * @public
531
501
  */
532
502
  export type ZomeLocation = Location;
533
- /**
534
- * @public
535
- */
536
- export interface ZomeDependency {
537
- name: ZomeName;
538
- }
539
503
  /**
540
504
  * @public
541
505
  */
542
506
  export type ZomeManifest = {
543
507
  name: string;
544
508
  hash?: string;
545
- dependencies?: ZomeDependency[];
546
509
  } & ZomeLocation;
547
- /**
548
- * @public
549
- */
550
- export interface CoordinatorManifest {
551
- zomes: Array<ZomeManifest>;
552
- }
553
- /**
554
- * @public
555
- */
556
- export interface CoordinatorBundle {
557
- manifest: CoordinatorManifest;
558
- resources: ResourceMap;
559
- }
560
- /**
561
- * @public
562
- */
563
- export type CoordinatorSource = {
564
- path: string;
565
- } | {
566
- bundle: CoordinatorBundle;
567
- };
568
510
  /**
569
511
  * @public
570
512
  */
@@ -682,46 +624,6 @@ export interface FullStateDump {
682
624
  source_chain_dump: SourceChainJsonDump;
683
625
  integration_dump: FullIntegrationStateDump;
684
626
  }
685
- /**
686
- * @public
687
- */
688
- export interface DnaStorageInfo {
689
- authored_data_size: number;
690
- authored_data_size_on_disk: number;
691
- dht_data_size: number;
692
- dht_data_size_on_disk: number;
693
- cache_data_size: number;
694
- cache_data_size_on_disk: number;
695
- used_by: Array<InstalledAppId>;
696
- }
697
- /**
698
- * @public
699
- */
700
- export interface DnaStorageBlob {
701
- dna: DnaStorageInfo;
702
- }
703
- /**
704
- * @public
705
- */
706
- export interface StorageInfo {
707
- blobs: Array<DnaStorageBlob>;
708
- }
709
- /**
710
- * @public
711
- */
712
- export type StorageInfoRequest = void;
713
- /**
714
- * @public
715
- */
716
- export type StorageInfoResponse = StorageInfo;
717
- /**
718
- * @public
719
- */
720
- export type DumpNetworkStatsRequest = void;
721
- /**
722
- * @public
723
- */
724
- export type DumpNetworkStatsResponse = string;
725
627
  /**
726
628
  * @public
727
629
  */
@@ -744,6 +646,4 @@ export interface AdminApi {
744
646
  addAgentInfo: Requester<AddAgentInfoRequest, AddAgentInfoResponse>;
745
647
  deleteCloneCell: Requester<DeleteCloneCellRequest, DeleteCloneCellResponse>;
746
648
  grantZomeCallCapability: Requester<GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse>;
747
- storageInfo: Requester<StorageInfoRequest, StorageInfoResponse>;
748
- dumpNetworkStats: Requester<DumpNetworkStatsRequest, DumpNetworkStatsResponse>;
749
649
  }
@@ -2,7 +2,7 @@ import { CapSecret, GrantedFunctions } from "../../hdk/capabilities.js";
2
2
  import type { AgentPubKey, CellId } from "../../types.js";
3
3
  import { WsClient } from "../client.js";
4
4
  import { Requester, Transformer } 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, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, 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, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, UninstallAppRequest, UninstallAppResponse } from "./types.js";
6
6
  /**
7
7
  * A class for interacting with a conductor's Admin API.
8
8
  *
@@ -25,7 +25,7 @@ export declare class AdminWebsocket implements AdminApi {
25
25
  * @param defaultTimeout - The default timeout for any request.
26
26
  * @returns A promise for a new connected instance.
27
27
  */
28
- static connect(url: URL, defaultTimeout?: number): Promise<AdminWebsocket>;
28
+ static connect(url: string, defaultTimeout?: number): Promise<AdminWebsocket>;
29
29
  _requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
30
30
  /**
31
31
  * Send a request to open the given port for {@link AppWebsocket} connections.
@@ -70,10 +70,6 @@ export declare class AdminWebsocket implements AdminApi {
70
70
  * Install the specified app into Holochain.
71
71
  */
72
72
  installApp: Requester<InstallAppRequest, InstallAppResponse>;
73
- /**
74
- * Update coordinators for an installed app.
75
- */
76
- updateCoordinators: Requester<UpdateCoordinatorsRequest, UpdateCoordinatorsResponse>;
77
73
  /**
78
74
  * List all registered DNAs.
79
75
  */
@@ -107,8 +103,6 @@ export declare class AdminWebsocket implements AdminApi {
107
103
  * calls.
108
104
  */
109
105
  grantZomeCallCapability: Requester<GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse>;
110
- storageInfo: Requester<StorageInfoRequest, StorageInfoResponse>;
111
- dumpNetworkStats: Requester<DumpNetworkStatsRequest, DumpNetworkStatsResponse>;
112
106
  /**
113
107
  * Grant a capability for signing zome calls.
114
108
  *
@@ -34,7 +34,7 @@ export class AdminWebsocket {
34
34
  // Check if we are in the launcher's environment, and if so, redirect the url to connect to
35
35
  const env = getLauncherEnvironment();
36
36
  if (env?.ADMIN_INTERFACE_PORT) {
37
- url = new URL(`ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`);
37
+ url = `ws://127.0.0.1:${env.ADMIN_INTERFACE_PORT}`;
38
38
  }
39
39
  const wsClient = await WsClient.connect(url);
40
40
  return new AdminWebsocket(wsClient, defaultTimeout);
@@ -85,10 +85,6 @@ export class AdminWebsocket {
85
85
  * Install the specified app into Holochain.
86
86
  */
87
87
  installApp = this._requester("install_app");
88
- /**
89
- * Update coordinators for an installed app.
90
- */
91
- updateCoordinators = this._requester("update_coordinators");
92
88
  /**
93
89
  * List all registered DNAs.
94
90
  */
@@ -122,8 +118,6 @@ export class AdminWebsocket {
122
118
  * calls.
123
119
  */
124
120
  grantZomeCallCapability = this._requester("grant_zome_call_capability");
125
- storageInfo = this._requester("storage_info");
126
- dumpNetworkStats = this._requester("dump_network_stats");
127
121
  // zome call signing related methods
128
122
  /**
129
123
  * Grant a capability for signing zome calls.
@@ -159,7 +153,7 @@ export class AdminWebsocket {
159
153
  * granted for all zomes and functions.
160
154
  */
161
155
  authorizeSigningCredentials = async (cellId, functions) => {
162
- const [keyPair, signingKey] = await generateSigningKeyPair();
156
+ const [keyPair, signingKey] = generateSigningKeyPair();
163
157
  const capSecret = await this.grantSigningKey(cellId, functions || { [GrantedFunctionsType.All]: null }, signingKey);
164
158
  setSigningCredentials(cellId, { capSecret, keyPair, signingKey });
165
159
  };
@@ -1,5 +1,5 @@
1
1
  import { AgentPubKey, CellId, DnaHash, DnaProperties, InstalledAppId, NetworkInfo, RoleName, Timestamp } from "../../types.js";
2
- import { AppInfo, ClonedCell, FunctionName, MembraneProof, NetworkSeed, ZomeName } from "../admin/types.js";
2
+ import { AppInfo, ClonedCell, FunctionName, MembraneProof, NetworkSeed, ZomeName } from "../admin/index.js";
3
3
  import { Requester } from "../common.js";
4
4
  /**
5
5
  * @public
@@ -114,17 +114,9 @@ export type EnableCloneCellResponse = CreateCloneCellResponse;
114
114
  */
115
115
  export interface NetworkInfoRequest {
116
116
  /**
117
- * The calling agent
118
- */
119
- agent_pub_key: AgentPubKey;
120
- /**
121
- * Get network info for these DNAs
117
+ * The DNAs for which to get network info
122
118
  */
123
119
  dnas: DnaHash[];
124
- /**
125
- * Timestamp in ms since which received amount of bytes from peers will be returned. Defaults to UNIX_EPOCH.
126
- */
127
- last_time_queried?: number;
128
120
  }
129
121
  /**
130
122
  * @public
@@ -23,8 +23,8 @@ export declare class AppWebsocket extends Emittery implements AppApi {
23
23
  * @param defaultTimeout - Timeout to default to for all operations.
24
24
  * @returns A new instance of an AppWebsocket.
25
25
  */
26
- static connect(url: URL, defaultTimeout?: number): Promise<AppWebsocket>;
27
- _requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
26
+ static connect(url: string, defaultTimeout?: number): Promise<AppWebsocket>;
27
+ _requester: <ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO> | undefined) => (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
28
28
  /**
29
29
  * Request the app's info, including all cell infos.
30
30
  *
@@ -1,11 +1,11 @@
1
1
  import { hashZomeCall } from "@holochain/serialization";
2
2
  import { decode, encode } from "@msgpack/msgpack";
3
- import _sodium from "libsodium-wrappers";
4
3
  import Emittery from "emittery";
5
- import { getLauncherEnvironment, signZomeCallTauri, signZomeCallElectron, getHostZomeCallSigner, } from "../../environments/launcher.js";
4
+ import nacl from "tweetnacl";
5
+ import { getHostZomeCallSigner, getLauncherEnvironment, isLauncher, signZomeCallTauri, } from "../../environments/launcher.js";
6
6
  import { encodeHashToBase64 } from "../../utils/base64.js";
7
7
  import { WsClient } from "../client.js";
8
- import { DEFAULT_TIMEOUT, catchError, promiseTimeout, requesterTransformer, } from "../common.js";
8
+ import { catchError, DEFAULT_TIMEOUT, promiseTimeout, requesterTransformer, } from "../common.js";
9
9
  import { getNonceExpiration, getSigningCredentials, randomNonce, } from "../zome-call-signing.js";
10
10
  /**
11
11
  * A class to establish a websocket connection to an App interface of a
@@ -19,15 +19,6 @@ export class AppWebsocket extends Emittery {
19
19
  overrideInstalledAppId;
20
20
  constructor(client, defaultTimeout, overrideInstalledAppId) {
21
21
  super();
22
- // Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
23
- // Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
24
- Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
25
- const to_bind = this[name];
26
- if (typeof to_bind === "function") {
27
- this[name] =
28
- to_bind.bind(this);
29
- }
30
- });
31
22
  this.client = client;
32
23
  this.defaultTimeout =
33
24
  defaultTimeout === undefined ? DEFAULT_TIMEOUT : defaultTimeout;
@@ -44,16 +35,14 @@ export class AppWebsocket extends Emittery {
44
35
  // Check if we are in the launcher's environment, and if so, redirect the url to connect to
45
36
  const env = getLauncherEnvironment();
46
37
  if (env?.APP_INTERFACE_PORT) {
47
- url = new URL(`ws://127.0.0.1:${env.APP_INTERFACE_PORT}`);
38
+ url = `ws://127.0.0.1:${env.APP_INTERFACE_PORT}`;
48
39
  }
49
40
  const wsClient = await WsClient.connect(url);
50
41
  const appWebsocket = new AppWebsocket(wsClient, defaultTimeout, env?.INSTALLED_APP_ID);
51
42
  wsClient.on("signal", (signal) => appWebsocket.emit("signal", signal));
52
43
  return appWebsocket;
53
44
  }
54
- _requester(tag, transformer) {
55
- return requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer);
56
- }
45
+ _requester = (tag, transformer) => requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer);
57
46
  /**
58
47
  * Request the app's info, including all cell infos.
59
48
  *
@@ -102,16 +91,10 @@ const callZomeTransform = {
102
91
  if (hostSigner) {
103
92
  return hostSigner.signZomeCall(request);
104
93
  }
105
- else {
106
- const env = getLauncherEnvironment();
107
- if (!env) {
108
- return signZomeCall(request);
109
- }
110
- if (env.FRAMEWORK === "electron") {
111
- return signZomeCallElectron(request);
112
- }
94
+ else if (isLauncher) {
113
95
  return signZomeCallTauri(request);
114
96
  }
97
+ return signZomeCall(request);
115
98
  },
116
99
  output: (response) => decode(response),
117
100
  };
@@ -145,11 +128,9 @@ export const signZomeCall = async (request) => {
145
128
  expires_at: getNonceExpiration(),
146
129
  };
147
130
  const hashedZomeCall = await hashZomeCall(unsignedZomeCallPayload);
148
- await _sodium.ready;
149
- const sodium = _sodium;
150
- const signature = sodium
151
- .crypto_sign(hashedZomeCall, signingCredentialsForCell.keyPair.privateKey)
152
- .subarray(0, sodium.crypto_sign_BYTES);
131
+ const signature = nacl
132
+ .sign(hashedZomeCall, signingCredentialsForCell.keyPair.secretKey)
133
+ .subarray(0, nacl.sign.signatureLength);
153
134
  const signedZomeCall = {
154
135
  ...unsignedZomeCallPayload,
155
136
  signature,
@@ -1,6 +1,6 @@
1
1
  import { UnsubscribeFunction } from "emittery";
2
2
  import { AgentPubKey, RoleName } from "../../index.js";
3
- import { AppInfoResponse, AppSignal, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, DisableCloneCellRequest, EnableCloneCellRequest, EnableCloneCellResponse, NetworkInfoRequest, NetworkInfoResponse } from "../app/index.js";
3
+ import { AppInfoResponse, AppSignal, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, DisableCloneCellRequest, EnableCloneCellRequest, EnableCloneCellResponse } from "../app/index.js";
4
4
  import { CreateCloneCellRequest, CreateCloneCellResponse, DisableCloneCellResponse } from "../index.js";
5
5
  /**
6
6
  * @public
@@ -34,10 +34,6 @@ export type AppEnableCloneCellRequest = Omit<EnableCloneCellRequest, "app_id">;
34
34
  * @public
35
35
  */
36
36
  export type AppDisableCloneCellRequest = Omit<DisableCloneCellRequest, "app_id">;
37
- /**
38
- * @public
39
- */
40
- export type AppAgentNetworkInfoRequest = Omit<NetworkInfoRequest, "agent_pub_key">;
41
37
  /**
42
38
  * @public
43
39
  */
@@ -55,5 +51,4 @@ export interface AppAgentClient {
55
51
  createCloneCell(args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse>;
56
52
  enableCloneCell(args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse>;
57
53
  disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
58
- networkInfo(args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse>;
59
54
  }
@@ -1,9 +1,7 @@
1
1
  import Emittery, { UnsubscribeFunction } from "emittery";
2
2
  import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
3
- import { AppInfo } from "../admin/types.js";
4
- import { AppSignalCb, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse } from "../app/types.js";
5
- import { AppWebsocket } from "../app/websocket.js";
6
- import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppAgentNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
3
+ import { AppInfo, AppSignalCb, AppWebsocket, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse } from "../index.js";
4
+ import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
7
5
  /**
8
6
  * A class to establish a websocket connection to an App interface, for a
9
7
  * specific agent and app.
@@ -31,7 +29,7 @@ export declare class AppAgentWebsocket implements AppAgentClient {
31
29
  * @param defaultTimeout - Timeout to default to for all operations.
32
30
  * @returns A new instance of an AppAgentWebsocket.
33
31
  */
34
- static connect(url: URL, installed_app_id: InstalledAppId, defaultTimeout?: number): Promise<AppAgentWebsocket>;
32
+ static connect(url: string, installed_app_id: InstalledAppId, defaultTimeout?: number): Promise<AppAgentWebsocket>;
35
33
  /**
36
34
  * Get a cell id by its role name or clone id.
37
35
  *
@@ -68,12 +66,6 @@ export declare class AppAgentWebsocket implements AppAgentClient {
68
66
  * @param args - Specify the clone cell to disable.
69
67
  */
70
68
  disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
71
- /**
72
- * Request network info about gossip status.
73
- * @param args - Specify the DNAs for which you want network info
74
- * @returns Network info for the specified DNAs
75
- */
76
- networkInfo(args: AppAgentNetworkInfoRequest): Promise<NetworkInfoResponse>;
77
69
  /**
78
70
  * Register an event listener for signals.
79
71
  *
@@ -1,9 +1,8 @@
1
1
  import Emittery from "emittery";
2
2
  import { omit } from "lodash-es";
3
3
  import { getLauncherEnvironment } from "../../environments/launcher.js";
4
- import { CellType } from "../admin/types.js";
5
- import { AppWebsocket } from "../app/websocket.js";
6
4
  import { getBaseRoleNameFromCloneId, isCloneId } from "../common.js";
5
+ import { AppWebsocket, CellType, } from "../index.js";
7
6
  /**
8
7
  * A class to establish a websocket connection to an App interface, for a
9
8
  * specific agent and app.
@@ -19,15 +18,6 @@ export class AppAgentWebsocket {
19
18
  constructor(appWebsocket, installedAppId, myPubKey) {
20
19
  this.appWebsocket = appWebsocket;
21
20
  this.emitter = new Emittery();
22
- // Ensure all super methods are bound to this instance because Emittery relies on `this` being the instance.
23
- // Please retain until the upstream is fixed https://github.com/sindresorhus/emittery/issues/86.
24
- Object.getOwnPropertyNames(Emittery.prototype).forEach((name) => {
25
- const to_bind = this.emitter[name];
26
- if (typeof to_bind === "function") {
27
- this.emitter[name] =
28
- to_bind.bind(this.emitter);
29
- }
30
- });
31
21
  const env = getLauncherEnvironment();
32
22
  this.installedAppId = env?.INSTALLED_APP_ID || installedAppId;
33
23
  this.myPubKey = myPubKey;
@@ -102,7 +92,12 @@ export class AppAgentWebsocket {
102
92
  * @returns The zome call's response.
103
93
  */
104
94
  async callZome(request, timeout) {
105
- if (!("provenance" in request)) {
95
+ if ("provenance" in request) {
96
+ if ("role_name" in request && request.role_name) {
97
+ throw new Error("Cannot find other agent's cells based on role name. Use cell id when providing a provenance.");
98
+ }
99
+ }
100
+ else {
106
101
  request = {
107
102
  ...request,
108
103
  provenance: this.myPubKey,
@@ -114,7 +109,7 @@ export class AppAgentWebsocket {
114
109
  const zomeCallPayload = {
115
110
  ...omit(request, "role_name"),
116
111
  provenance: this.myPubKey,
117
- cell_id,
112
+ cell_id: [cell_id[0], cell_id[1]],
118
113
  };
119
114
  return this.appWebsocket.callZome(zomeCallPayload, timeout);
120
115
  }
@@ -160,17 +155,6 @@ export class AppAgentWebsocket {
160
155
  ...args,
161
156
  });
162
157
  }
163
- /**
164
- * Request network info about gossip status.
165
- * @param args - Specify the DNAs for which you want network info
166
- * @returns Network info for the specified DNAs
167
- */
168
- async networkInfo(args) {
169
- return this.appWebsocket.networkInfo({
170
- ...args,
171
- agent_pub_key: this.myPubKey,
172
- });
173
- }
174
158
  /**
175
159
  * Register an event listener for signals.
176
160
  *
@@ -1,28 +1,30 @@
1
1
  /// <reference types="ws" />
2
+ import { decode } from "@msgpack/msgpack";
2
3
  import Emittery from "emittery";
3
- import IsoWebSocket from "isomorphic-ws";
4
+ import Websocket from "isomorphic-ws";
4
5
  /**
5
- * A WebSocket client which can make requests and receive responses,
6
+ * A Websocket client which can make requests and receive responses,
6
7
  * as well as send and receive signals.
7
8
  *
8
- * Uses Holochain's WireMessage for communication.
9
+ * Uses Holochain's websocket WireMessage for communication.
9
10
  *
10
11
  * @public
11
12
  */
12
13
  export declare class WsClient extends Emittery {
13
- socket: IsoWebSocket;
14
- url: URL | undefined;
15
- private pendingRequests;
16
- private index;
17
- constructor(socket: IsoWebSocket, url: URL);
18
- private setupSocket;
14
+ socket: Websocket;
15
+ pendingRequests: Record<number, {
16
+ resolve: (msg: unknown) => ReturnType<typeof decode>;
17
+ reject: (error: Error) => void;
18
+ }>;
19
+ index: number;
20
+ constructor(socket: Websocket);
19
21
  /**
20
22
  * Instance factory for creating WsClients.
21
23
  *
22
- * @param url - The WebSocket URL to connect to.
24
+ * @param url - The `ws://` URL to connect to.
23
25
  * @returns An new instance of the WsClient.
24
26
  */
25
- static connect(url: URL): Promise<WsClient>;
27
+ static connect(url: string): Promise<WsClient>;
26
28
  /**
27
29
  * Sends data as a signal.
28
30
  *
@@ -35,12 +37,10 @@ export declare class WsClient extends Emittery {
35
37
  * @param request - The request to send over the websocket.
36
38
  * @returns
37
39
  */
38
- request<Response>(request: unknown): Promise<Response>;
39
- private sendMessage;
40
+ request<Req, Res>(request: Req): Promise<Res>;
40
41
  private handleResponse;
41
42
  /**
42
43
  * Close the websocket connection.
43
44
  */
44
- close(code?: number): Promise<CloseEvent>;
45
+ close(code?: number): Promise<void>;
45
46
  }
46
- export { IsoWebSocket };