@holochain/client 0.12.2 → 0.12.3
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 +90 -37
- package/lib/api/app-agent/websocket.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,46 +25,99 @@ npm install --save-exact @holochain/client
|
|
|
25
25
|
|
|
26
26
|
### Use AppAgentWebsocket with implicit zome call signing
|
|
27
27
|
```typescript
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
import { AdminWebsocket, AppAgentWebsocket, CellType } from "@holochain/client";
|
|
29
|
+
|
|
30
|
+
const adminWs = await AdminWebsocket.connect("ws://127.0.0.1:65000");
|
|
31
|
+
const agent_key = await adminWs.generateAgentPubKey();
|
|
32
|
+
const role_name = "role";
|
|
33
|
+
const installed_app_id = "test-app";
|
|
34
|
+
const appInfo = await adminWs.installApp({
|
|
35
|
+
agent_key,
|
|
36
|
+
path: "path/to/happ/file",
|
|
37
|
+
installed_app_id,
|
|
38
|
+
membrane_proofs: {},
|
|
39
|
+
});
|
|
40
|
+
await adminWs.enableApp({ installed_app_id });
|
|
41
|
+
if (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {
|
|
42
|
+
process.exit();
|
|
43
|
+
}
|
|
44
|
+
const { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];
|
|
45
|
+
await adminWs.authorizeSigningCredentials(cell_id);
|
|
46
|
+
await adminWs.attachAppInterface({ port: 65001 });
|
|
47
|
+
const appAgentWs = await AppAgentWebsocket.connect(
|
|
48
|
+
"ws://127.0.0.1:65001",
|
|
49
|
+
installed_app_id
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
let signalCb;
|
|
53
|
+
const signalReceived = new Promise<void>((resolve) => {
|
|
54
|
+
signalCb = (signal) => {
|
|
55
|
+
console.log("signal received", signal);
|
|
56
|
+
// act on signal
|
|
57
|
+
resolve();
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
appAgentWs.on("signal", signalCb);
|
|
62
|
+
|
|
63
|
+
// trigger an emit_signal
|
|
64
|
+
await appAgentWs.callZome({
|
|
65
|
+
role_name,
|
|
66
|
+
zome_name: "zome",
|
|
67
|
+
fn_name: "emitter",
|
|
68
|
+
payload: null,
|
|
69
|
+
});
|
|
70
|
+
await signalReceived;
|
|
71
|
+
|
|
72
|
+
await appAgentWs.appWebsocket.client.close();
|
|
73
|
+
await adminWs.client.close();
|
|
47
74
|
```
|
|
48
75
|
|
|
49
76
|
### Use AppWebsocket with implicit zome call signing
|
|
50
77
|
```typescript
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
import { AdminWebsocket, AppWebsocket, CellType } from "@holochain/client";
|
|
79
|
+
|
|
80
|
+
const adminWs = await AdminWebsocket.connect("ws://127.0.0.1:65000");
|
|
81
|
+
const agent_key = await adminWs.generateAgentPubKey();
|
|
82
|
+
const installed_app_id = "test-app";
|
|
83
|
+
const appInfo = await adminWs.installApp({
|
|
84
|
+
agent_key,
|
|
85
|
+
path: "path/to/happ/file",
|
|
86
|
+
installed_app_id,
|
|
87
|
+
membrane_proofs: {},
|
|
88
|
+
});
|
|
89
|
+
await adminWs.enableApp({ installed_app_id });
|
|
90
|
+
if (!(CellType.Provisioned in appInfo.cell_info["role"][0])) {
|
|
91
|
+
process.exit();
|
|
92
|
+
}
|
|
93
|
+
const { cell_id } = appInfo.cell_info["role"][0][CellType.Provisioned];
|
|
94
|
+
await adminWs.authorizeSigningCredentials(cell_id);
|
|
95
|
+
await adminWs.attachAppInterface({ port: 65001 });
|
|
96
|
+
const appWs = await AppWebsocket.connect("ws://127.0.0.1:65001");
|
|
97
|
+
|
|
98
|
+
let signalCb;
|
|
99
|
+
const signalReceived = new Promise<void>((resolve) => {
|
|
100
|
+
signalCb = (signal) => {
|
|
101
|
+
console.log("signal received", signal);
|
|
102
|
+
// act on signal
|
|
103
|
+
resolve();
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
appWs.on("signal", signalCb);
|
|
108
|
+
|
|
109
|
+
// trigger an emit_signal
|
|
110
|
+
await appWs.callZome({
|
|
111
|
+
cell_id,
|
|
112
|
+
zome_name: "zome",
|
|
113
|
+
fn_name: "emitter",
|
|
114
|
+
provenance: agent_key,
|
|
115
|
+
payload: null,
|
|
116
|
+
});
|
|
117
|
+
await signalReceived;
|
|
118
|
+
|
|
119
|
+
await appWs.client.close();
|
|
120
|
+
await adminWs.client.close();
|
|
68
121
|
```
|
|
69
122
|
|
|
70
123
|
### Managing zome call signing credentials in a pure JavaScript browser application
|
|
@@ -119,7 +172,7 @@ nix-shell
|
|
|
119
172
|
|
|
120
173
|
Holochain is an open source project. We welcome all sorts of participation and are actively working on increasing surface area to accept it. Please see our [contribution guidelines](/CONTRIBUTING.md) for our general practices and protocols on participating in the community, as well as specific expectations around things like code formatting, testing practices, continuous integration, etc.
|
|
121
174
|
|
|
122
|
-
* Connect with us on
|
|
175
|
+
* Connect with us on [Discord](https://discord.gg/k55DS5dmPH)
|
|
123
176
|
|
|
124
177
|
## License
|
|
125
178
|
|
|
@@ -92,7 +92,14 @@ export class AppAgentWebsocket {
|
|
|
92
92
|
* @returns The zome call's response.
|
|
93
93
|
*/
|
|
94
94
|
async callZome(request, timeout) {
|
|
95
|
-
if (
|
|
95
|
+
if ("provenance" in request) {
|
|
96
|
+
if (request.provenance !== this.myPubKey &&
|
|
97
|
+
"role_name" in request &&
|
|
98
|
+
request.role_name) {
|
|
99
|
+
throw new Error("Cannot find other agent's cells based on role name. Use cell id when providing a provenance.");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
96
103
|
request = {
|
|
97
104
|
...request,
|
|
98
105
|
provenance: this.myPubKey,
|
|
@@ -111,9 +118,7 @@ export class AppAgentWebsocket {
|
|
|
111
118
|
else if ("cell_id" in request && request.cell_id) {
|
|
112
119
|
return this.appWebsocket.callZome(request, timeout);
|
|
113
120
|
}
|
|
114
|
-
|
|
115
|
-
throw new Error("callZome requires a role_name or cell_id arg");
|
|
116
|
-
}
|
|
121
|
+
throw new Error("callZome requires a role_name or cell_id arg");
|
|
117
122
|
}
|
|
118
123
|
/**
|
|
119
124
|
* Clone an existing provisioned cell.
|
package/package.json
CHANGED