@holochain/client 0.18.0-dev.1 → 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 +12 -1
- package/lib/api/app/websocket.d.ts +8 -1
- package/lib/api/app/websocket.js +10 -0
- 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, InstalledAppId, MembraneProof, NetworkInfo, NetworkSeed, Nonce256Bit, RoleName, Timestamp, Transformer, 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
|
*/
|
|
@@ -227,4 +235,7 @@ export interface AppWebsocketConnectionOptions extends WebsocketConnectionOption
|
|
|
227
235
|
token?: AppAuthenticationToken;
|
|
228
236
|
callZomeTransform?: CallZomeTransform;
|
|
229
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* @public
|
|
240
|
+
*/
|
|
230
241
|
export type CallZomeTransform = Transformer<CallZomeRequest | CallZomeRequestSigned, Promise<CallZomeRequestSigned>, CallZomeResponseGeneric<Uint8Array>, CallZomeResponse>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnsubscribeFunction } from "emittery";
|
|
2
2
|
import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
|
|
3
|
-
import { AppInfo } from "../admin/index.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
|
/**
|
|
@@ -19,6 +19,7 @@ export declare class AppWebsocket implements AppClient {
|
|
|
19
19
|
cachedAppInfo?: AppInfo | null;
|
|
20
20
|
private readonly appInfoRequester;
|
|
21
21
|
private readonly callZomeRequester;
|
|
22
|
+
private readonly provideMemproofRequester;
|
|
22
23
|
private readonly createCloneCellRequester;
|
|
23
24
|
private readonly enableCloneCellRequester;
|
|
24
25
|
private readonly disableCloneCellRequester;
|
|
@@ -39,6 +40,12 @@ export declare class AppWebsocket implements AppClient {
|
|
|
39
40
|
* @returns The app's {@link AppInfo}.
|
|
40
41
|
*/
|
|
41
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>;
|
|
42
49
|
/**
|
|
43
50
|
* Get a cell id by its role name or clone id.
|
|
44
51
|
*
|
package/lib/api/app/websocket.js
CHANGED
|
@@ -25,6 +25,7 @@ export class AppWebsocket {
|
|
|
25
25
|
cachedAppInfo;
|
|
26
26
|
appInfoRequester;
|
|
27
27
|
callZomeRequester;
|
|
28
|
+
provideMemproofRequester;
|
|
28
29
|
createCloneCellRequester;
|
|
29
30
|
enableCloneCellRequester;
|
|
30
31
|
disableCloneCellRequester;
|
|
@@ -39,6 +40,7 @@ export class AppWebsocket {
|
|
|
39
40
|
this.cachedAppInfo = appInfo;
|
|
40
41
|
this.appInfoRequester = AppWebsocket.requester(this.client, "app_info", this.defaultTimeout);
|
|
41
42
|
this.callZomeRequester = AppWebsocket.requester(this.client, "call_zome", this.defaultTimeout, this.callZomeTransform);
|
|
43
|
+
this.provideMemproofRequester = AppWebsocket.requester(this.client, "provide_memproofs", this.defaultTimeout);
|
|
42
44
|
this.createCloneCellRequester = AppWebsocket.requester(this.client, "create_clone_cell", this.defaultTimeout);
|
|
43
45
|
this.enableCloneCellRequester = AppWebsocket.requester(this.client, "enable_clone_cell", this.defaultTimeout);
|
|
44
46
|
this.disableCloneCellRequester = AppWebsocket.requester(this.client, "disable_clone_cell", this.defaultTimeout);
|
|
@@ -105,6 +107,14 @@ export class AppWebsocket {
|
|
|
105
107
|
this.cachedAppInfo = appInfo;
|
|
106
108
|
return appInfo;
|
|
107
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
|
+
}
|
|
108
118
|
/**
|
|
109
119
|
* Get a cell id by its role name or clone id.
|
|
110
120
|
*
|
package/package.json
CHANGED