@holochain/client 0.18.0-dev.0 → 0.18.0-dev.2
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 +52 -24
- package/lib/api/admin/types.d.ts +9 -4
- package/lib/api/app/types.d.ts +15 -1
- package/lib/api/app/websocket.d.ts +11 -2
- package/lib/api/app/websocket.js +18 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,64 +30,92 @@ npm install --save-exact @holochain/client
|
|
|
30
30
|
|
|
31
31
|
## Sample usage
|
|
32
32
|
|
|
33
|
-
### Use
|
|
33
|
+
### Use AppWebsocket with implicit zome call signing
|
|
34
34
|
```typescript
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
import {
|
|
36
|
+
AdminWebsocket,
|
|
37
|
+
AppWebsocket,
|
|
38
|
+
CellType,
|
|
39
|
+
type ActionHash,
|
|
40
|
+
type CallZomeRequest,
|
|
41
|
+
} from "@holochain/client";
|
|
42
|
+
|
|
43
|
+
const adminWs = await AdminWebsocket.connect({
|
|
44
|
+
url: new URL("ws://127.0.0.1:65000"),
|
|
45
|
+
wsClientOptions: { origin: "my-happ" },
|
|
46
|
+
});
|
|
38
47
|
const agent_key = await adminWs.generateAgentPubKey();
|
|
39
|
-
const role_name = "
|
|
48
|
+
const role_name = "foo";
|
|
40
49
|
const installed_app_id = "test-app";
|
|
41
50
|
const appInfo = await adminWs.installApp({
|
|
42
51
|
agent_key,
|
|
43
|
-
path: "
|
|
52
|
+
path: "./test/e2e/fixture/test.happ",
|
|
44
53
|
installed_app_id,
|
|
45
54
|
membrane_proofs: {},
|
|
46
55
|
});
|
|
47
56
|
await adminWs.enableApp({ installed_app_id });
|
|
48
57
|
if (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {
|
|
49
|
-
|
|
58
|
+
throw new Error(`No cell found under role name ${role_name}`);
|
|
50
59
|
}
|
|
51
60
|
const { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];
|
|
52
61
|
await adminWs.authorizeSigningCredentials(cell_id);
|
|
53
|
-
await adminWs.attachAppInterface({ port: 65001 });
|
|
54
|
-
const
|
|
62
|
+
await adminWs.attachAppInterface({ port: 65001, allowed_origins: "my-happ" });
|
|
63
|
+
const issuedToken = await adminWs.issueAppAuthenticationToken({
|
|
64
|
+
installed_app_id,
|
|
65
|
+
});
|
|
66
|
+
const appWs = await AppWebsocket.connect({
|
|
67
|
+
url: new URL("ws://127.0.0.1:65001"),
|
|
68
|
+
token: issuedToken.token,
|
|
69
|
+
wsClientOptions: { origin: "my-happ" },
|
|
70
|
+
});
|
|
55
71
|
|
|
56
72
|
const zomeCallPayload: CallZomeRequest = {
|
|
57
73
|
cell_id,
|
|
58
|
-
zome_name: "
|
|
59
|
-
fn_name: "
|
|
74
|
+
zome_name: "foo",
|
|
75
|
+
fn_name: "foo",
|
|
60
76
|
provenance: agent_key,
|
|
61
|
-
payload:
|
|
77
|
+
payload: null,
|
|
62
78
|
};
|
|
63
79
|
|
|
64
|
-
const response: ActionHash = await
|
|
80
|
+
const response: ActionHash = await appWs.callZome(zomeCallPayload, 30000);
|
|
81
|
+
console.log("zome call response is", response);
|
|
65
82
|
|
|
66
|
-
await
|
|
83
|
+
await appWs.client.close();
|
|
67
84
|
await adminWs.client.close();
|
|
68
85
|
```
|
|
69
86
|
|
|
70
|
-
###
|
|
87
|
+
### Subscribe to signals
|
|
71
88
|
```typescript
|
|
72
89
|
import { AdminWebsocket, AppWebsocket, CellType } from "@holochain/client";
|
|
73
90
|
|
|
74
|
-
const adminWs = await AdminWebsocket.connect({
|
|
91
|
+
const adminWs = await AdminWebsocket.connect({
|
|
92
|
+
url: new URL("ws://127.0.0.1:65000"),
|
|
93
|
+
wsClientOptions: { origin: "my-happ" },
|
|
94
|
+
});
|
|
75
95
|
const agent_key = await adminWs.generateAgentPubKey();
|
|
96
|
+
const role_name = "foo";
|
|
76
97
|
const installed_app_id = "test-app";
|
|
77
98
|
const appInfo = await adminWs.installApp({
|
|
78
99
|
agent_key,
|
|
79
|
-
path: "
|
|
100
|
+
path: "./test/e2e/fixture/test.happ",
|
|
80
101
|
installed_app_id,
|
|
81
102
|
membrane_proofs: {},
|
|
82
103
|
});
|
|
83
104
|
await adminWs.enableApp({ installed_app_id });
|
|
84
|
-
if (!(CellType.Provisioned in appInfo.cell_info[
|
|
85
|
-
|
|
105
|
+
if (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {
|
|
106
|
+
throw new Error(`No cell found under role name ${role_name}`);
|
|
86
107
|
}
|
|
87
|
-
const { cell_id } = appInfo.cell_info[
|
|
108
|
+
const { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];
|
|
88
109
|
await adminWs.authorizeSigningCredentials(cell_id);
|
|
89
|
-
await adminWs.attachAppInterface({ port: 65001 });
|
|
90
|
-
const
|
|
110
|
+
await adminWs.attachAppInterface({ port: 65001, allowed_origins: "my-happ" });
|
|
111
|
+
const issuedToken = await adminWs.issueAppAuthenticationToken({
|
|
112
|
+
installed_app_id,
|
|
113
|
+
});
|
|
114
|
+
const appWs = await AppWebsocket.connect({
|
|
115
|
+
url: new URL("ws://127.0.0.1:65001"),
|
|
116
|
+
token: issuedToken.token,
|
|
117
|
+
wsClientOptions: { origin: "my-happ" },
|
|
118
|
+
});
|
|
91
119
|
|
|
92
120
|
let signalCb;
|
|
93
121
|
const signalReceived = new Promise<void>((resolve) => {
|
|
@@ -103,7 +131,7 @@ appWs.on("signal", signalCb);
|
|
|
103
131
|
// trigger an emit_signal
|
|
104
132
|
await appWs.callZome({
|
|
105
133
|
cell_id,
|
|
106
|
-
zome_name: "
|
|
134
|
+
zome_name: "foo",
|
|
107
135
|
fn_name: "emitter",
|
|
108
136
|
provenance: agent_key,
|
|
109
137
|
payload: null,
|
|
@@ -165,7 +193,7 @@ Holochain is an open source project. We welcome all sorts of participation and
|
|
|
165
193
|
|
|
166
194
|
[](https://github.com/holochain/cryptographic-autonomy-license)
|
|
167
195
|
|
|
168
|
-
Copyright (C) 2020-
|
|
196
|
+
Copyright (C) 2020-2024, Holochain Foundation
|
|
169
197
|
|
|
170
198
|
This program is free software: you can redistribute it and/or modify it under the terms of the license
|
|
171
199
|
provided in the LICENSE file (CAL-1.0). This program is distributed in the hope that it will be useful,
|
package/lib/api/admin/types.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type InstalledAppInfoStatus = {
|
|
|
66
66
|
disabled: {
|
|
67
67
|
reason: DisabledAppReason;
|
|
68
68
|
};
|
|
69
|
-
} | "running";
|
|
69
|
+
} | "awaiting_memproofs" | "running";
|
|
70
70
|
/**
|
|
71
71
|
* @public
|
|
72
72
|
*/
|
|
@@ -125,6 +125,12 @@ export type AppInfo = {
|
|
|
125
125
|
* @public
|
|
126
126
|
*/
|
|
127
127
|
export type MembraneProof = Uint8Array;
|
|
128
|
+
/**
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export type MemproofMap = {
|
|
132
|
+
[key: string]: MembraneProof;
|
|
133
|
+
};
|
|
128
134
|
/**
|
|
129
135
|
* @public
|
|
130
136
|
*/
|
|
@@ -356,6 +362,7 @@ export type AppManifest = {
|
|
|
356
362
|
name: string;
|
|
357
363
|
description?: string;
|
|
358
364
|
roles: Array<AppRoleManifest>;
|
|
365
|
+
membrane_proofs_deferred: boolean;
|
|
359
366
|
};
|
|
360
367
|
/**
|
|
361
368
|
* @public
|
|
@@ -393,9 +400,7 @@ export type InstallAppRequest = {
|
|
|
393
400
|
* Include proof-of-membrane-membership data for cells that require it,
|
|
394
401
|
* keyed by the CellNick specified in the app bundle manifest.
|
|
395
402
|
*/
|
|
396
|
-
membrane_proofs:
|
|
397
|
-
[key: string]: MembraneProof;
|
|
398
|
-
};
|
|
403
|
+
membrane_proofs: MemproofMap;
|
|
399
404
|
/**
|
|
400
405
|
* Optional global network seed override. If set will override the network seed value for all
|
|
401
406
|
* DNAs in the bundle.
|
package/lib/api/app/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UnsubscribeFunction } from "emittery";
|
|
2
|
-
import { AgentPubKey, AppAuthenticationToken, AppInfo, CapSecret, CellId, ClonedCell, DnaHash, DnaProperties, FunctionName, MembraneProof, NetworkInfo, NetworkSeed, Nonce256Bit, RoleName, Timestamp, WebsocketConnectionOptions, ZomeName } from "../../index.js";
|
|
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";
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
@@ -82,6 +82,14 @@ export type CallZomeResponse = CallZomeResponseGeneric<any>;
|
|
|
82
82
|
* @public
|
|
83
83
|
*/
|
|
84
84
|
export type AppInfoResponse = AppInfo | null;
|
|
85
|
+
/**
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export type ProvideMemproofsRequest = MemproofMap;
|
|
89
|
+
/**
|
|
90
|
+
* @public
|
|
91
|
+
*/
|
|
92
|
+
export type ProvideMemproofsResponse = void;
|
|
85
93
|
/**
|
|
86
94
|
* @public
|
|
87
95
|
*/
|
|
@@ -214,6 +222,7 @@ export interface AppClient {
|
|
|
214
222
|
on<Name extends keyof AppEvents>(eventName: Name | readonly Name[], listener: AppSignalCb): UnsubscribeFunction;
|
|
215
223
|
appInfo(): Promise<AppInfoResponse>;
|
|
216
224
|
myPubKey: AgentPubKey;
|
|
225
|
+
installedAppId: InstalledAppId;
|
|
217
226
|
createCloneCell(args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse>;
|
|
218
227
|
enableCloneCell(args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse>;
|
|
219
228
|
disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
|
|
@@ -224,4 +233,9 @@ export interface AppClient {
|
|
|
224
233
|
*/
|
|
225
234
|
export interface AppWebsocketConnectionOptions extends WebsocketConnectionOptions {
|
|
226
235
|
token?: AppAuthenticationToken;
|
|
236
|
+
callZomeTransform?: CallZomeTransform;
|
|
227
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
241
|
+
export type CallZomeTransform = Transformer<CallZomeRequest | CallZomeRequestSigned, Promise<CallZomeRequestSigned>, CallZomeResponseGeneric<Uint8Array>, CallZomeResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnsubscribeFunction } from "emittery";
|
|
2
|
-
import { AgentPubKey, CellId, RoleName } from "../../types.js";
|
|
3
|
-
import { AppInfo } from "../admin/index.js";
|
|
2
|
+
import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
|
|
3
|
+
import { AppInfo, MemproofMap } from "../admin/index.js";
|
|
4
4
|
import { AppCallZomeRequest, AppClient, AppEvents, AppNetworkInfoRequest, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest, AppSignalCb, CallZomeRequest, CallZomeRequestSigned, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse, NetworkInfoResponse, AppWebsocketConnectionOptions } from "./types.js";
|
|
5
5
|
import { WsClient } from "../client.js";
|
|
6
6
|
/**
|
|
@@ -12,11 +12,14 @@ import { WsClient } from "../client.js";
|
|
|
12
12
|
export declare class AppWebsocket implements AppClient {
|
|
13
13
|
readonly client: WsClient;
|
|
14
14
|
readonly myPubKey: AgentPubKey;
|
|
15
|
+
readonly installedAppId: InstalledAppId;
|
|
15
16
|
private readonly defaultTimeout;
|
|
16
17
|
private readonly emitter;
|
|
18
|
+
private readonly callZomeTransform;
|
|
17
19
|
cachedAppInfo?: AppInfo | null;
|
|
18
20
|
private readonly appInfoRequester;
|
|
19
21
|
private readonly callZomeRequester;
|
|
22
|
+
private readonly provideMemproofRequester;
|
|
20
23
|
private readonly createCloneCellRequester;
|
|
21
24
|
private readonly enableCloneCellRequester;
|
|
22
25
|
private readonly disableCloneCellRequester;
|
|
@@ -37,6 +40,12 @@ export declare class AppWebsocket implements AppClient {
|
|
|
37
40
|
* @returns The app's {@link AppInfo}.
|
|
38
41
|
*/
|
|
39
42
|
appInfo(timeout?: number): Promise<AppInfo>;
|
|
43
|
+
/**
|
|
44
|
+
* Provide membrane proofs for the app.
|
|
45
|
+
*
|
|
46
|
+
* @param memproofs - A map of {@link MembraneProof}s.
|
|
47
|
+
*/
|
|
48
|
+
provideMemproofs(memproofs: MemproofMap): Promise<void>;
|
|
40
49
|
/**
|
|
41
50
|
* Get a cell id by its role name or clone id.
|
|
42
51
|
*
|
package/lib/api/app/websocket.js
CHANGED
|
@@ -18,23 +18,29 @@ import { WsClient } from "../client.js";
|
|
|
18
18
|
export class AppWebsocket {
|
|
19
19
|
client;
|
|
20
20
|
myPubKey;
|
|
21
|
+
installedAppId;
|
|
21
22
|
defaultTimeout;
|
|
22
23
|
emitter;
|
|
24
|
+
callZomeTransform;
|
|
23
25
|
cachedAppInfo;
|
|
24
26
|
appInfoRequester;
|
|
25
27
|
callZomeRequester;
|
|
28
|
+
provideMemproofRequester;
|
|
26
29
|
createCloneCellRequester;
|
|
27
30
|
enableCloneCellRequester;
|
|
28
31
|
disableCloneCellRequester;
|
|
29
32
|
networkInfoRequester;
|
|
30
|
-
constructor(client, appInfo, defaultTimeout) {
|
|
33
|
+
constructor(client, appInfo, callZomeTransform, defaultTimeout) {
|
|
31
34
|
this.client = client;
|
|
32
35
|
this.myPubKey = appInfo.agent_pub_key;
|
|
36
|
+
this.installedAppId = appInfo.installed_app_id;
|
|
33
37
|
this.defaultTimeout = defaultTimeout ?? DEFAULT_TIMEOUT;
|
|
38
|
+
this.callZomeTransform = callZomeTransform ?? defaultCallZomeTransform;
|
|
34
39
|
this.emitter = new Emittery();
|
|
35
40
|
this.cachedAppInfo = appInfo;
|
|
36
41
|
this.appInfoRequester = AppWebsocket.requester(this.client, "app_info", this.defaultTimeout);
|
|
37
|
-
this.callZomeRequester = AppWebsocket.requester(this.client, "call_zome", this.defaultTimeout, callZomeTransform);
|
|
42
|
+
this.callZomeRequester = AppWebsocket.requester(this.client, "call_zome", this.defaultTimeout, this.callZomeTransform);
|
|
43
|
+
this.provideMemproofRequester = AppWebsocket.requester(this.client, "provide_memproofs", this.defaultTimeout);
|
|
38
44
|
this.createCloneCellRequester = AppWebsocket.requester(this.client, "create_clone_cell", this.defaultTimeout);
|
|
39
45
|
this.enableCloneCellRequester = AppWebsocket.requester(this.client, "enable_clone_cell", this.defaultTimeout);
|
|
40
46
|
this.disableCloneCellRequester = AppWebsocket.requester(this.client, "disable_clone_cell", this.defaultTimeout);
|
|
@@ -85,7 +91,7 @@ export class AppWebsocket {
|
|
|
85
91
|
if (!appInfo) {
|
|
86
92
|
throw new HolochainError("AppNotFound", `The app your connection token was issued for was not found. The app needs to be installed and enabled.`);
|
|
87
93
|
}
|
|
88
|
-
return new AppWebsocket(client, appInfo, options.defaultTimeout);
|
|
94
|
+
return new AppWebsocket(client, appInfo, options.callZomeTransform, options.defaultTimeout);
|
|
89
95
|
}
|
|
90
96
|
/**
|
|
91
97
|
* Request the app's info, including all cell infos.
|
|
@@ -101,6 +107,14 @@ export class AppWebsocket {
|
|
|
101
107
|
this.cachedAppInfo = appInfo;
|
|
102
108
|
return appInfo;
|
|
103
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Provide membrane proofs for the app.
|
|
112
|
+
*
|
|
113
|
+
* @param memproofs - A map of {@link MembraneProof}s.
|
|
114
|
+
*/
|
|
115
|
+
async provideMemproofs(memproofs) {
|
|
116
|
+
await this.provideMemproofRequester(memproofs);
|
|
117
|
+
}
|
|
104
118
|
/**
|
|
105
119
|
* Get a cell id by its role name or clone id.
|
|
106
120
|
*
|
|
@@ -236,7 +250,7 @@ export class AppWebsocket {
|
|
|
236
250
|
return false;
|
|
237
251
|
}
|
|
238
252
|
}
|
|
239
|
-
const
|
|
253
|
+
const defaultCallZomeTransform = {
|
|
240
254
|
input: async (request) => {
|
|
241
255
|
if ("signature" in request) {
|
|
242
256
|
return request;
|
package/package.json
CHANGED