@holochain/client 0.11.13 → 0.11.14
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 +1 -1
- package/lib/api/admin/index.js +0 -1
- package/lib/api/admin/types.d.ts +355 -41
- package/lib/api/admin/types.js +40 -1
- package/lib/api/admin/websocket.d.ts +80 -1
- package/lib/api/admin/websocket.js +82 -4
- package/lib/api/app/index.js +0 -1
- package/lib/api/app/types.d.ts +78 -3
- package/lib/api/app/types.js +3 -1
- package/lib/api/app/websocket.d.ts +54 -0
- package/lib/api/app/websocket.js +48 -1
- package/lib/api/app-agent/index.js +0 -1
- package/lib/api/app-agent/types.d.ts +27 -0
- package/lib/api/app-agent/types.js +0 -1
- package/lib/api/app-agent/websocket.d.ts +57 -0
- package/lib/api/app-agent/websocket.js +57 -1
- package/lib/api/client.d.ts +25 -9
- package/lib/api/client.js +35 -13
- package/lib/api/common.d.ts +30 -1
- package/lib/api/common.js +18 -2
- package/lib/api/index.d.ts +2 -1
- package/lib/api/index.js +1 -1
- package/lib/api/zome-call-signing.d.ts +24 -1
- package/lib/api/zome-call-signing.js +18 -2
- package/lib/environments/launcher.js +0 -1
- package/lib/hdk/action.d.ts +45 -0
- package/lib/hdk/action.js +3 -1
- package/lib/hdk/capabilities.d.ts +21 -0
- package/lib/hdk/capabilities.js +3 -1
- package/lib/hdk/countersigning.d.ts +30 -0
- package/lib/hdk/countersigning.js +0 -1
- package/lib/hdk/dht-ops.d.ts +18 -0
- package/lib/hdk/dht-ops.js +15 -1
- package/lib/hdk/entry.d.ts +15 -0
- package/lib/hdk/entry.js +0 -1
- package/lib/hdk/index.d.ts +1 -0
- package/lib/hdk/index.js +1 -1
- package/lib/hdk/record.d.ts +6 -0
- package/lib/hdk/record.js +0 -1
- package/lib/index.js +0 -1
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types.d.ts +81 -0
- package/lib/types.js +0 -1
- package/lib/utils/base64.d.ts +16 -0
- package/lib/utils/base64.js +16 -1
- package/lib/utils/fake-hash.d.ts +23 -1
- package/lib/utils/fake-hash.js +23 -2
- package/lib/utils/index.js +0 -1
- package/package.json +5 -2
- package/lib/api/admin/index.js.map +0 -1
- package/lib/api/admin/types.js.map +0 -1
- package/lib/api/admin/websocket.js.map +0 -1
- package/lib/api/app/index.js.map +0 -1
- package/lib/api/app/types.js.map +0 -1
- package/lib/api/app/websocket.js.map +0 -1
- package/lib/api/app-agent/index.js.map +0 -1
- package/lib/api/app-agent/types.js.map +0 -1
- package/lib/api/app-agent/websocket.js.map +0 -1
- package/lib/api/client.js.map +0 -1
- package/lib/api/common.js.map +0 -1
- package/lib/api/index.js.map +0 -1
- package/lib/api/zome-call-signing.js.map +0 -1
- package/lib/environments/launcher.js.map +0 -1
- package/lib/hdk/action.js.map +0 -1
- package/lib/hdk/capabilities.js.map +0 -1
- package/lib/hdk/countersigning.js.map +0 -1
- package/lib/hdk/dht-ops.js.map +0 -1
- package/lib/hdk/entry.js.map +0 -1
- package/lib/hdk/index.js.map +0 -1
- package/lib/hdk/record.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils/base64.js.map +0 -1
- package/lib/utils/fake-hash.js.map +0 -1
- package/lib/utils/index.js.map +0 -1
|
@@ -2,6 +2,12 @@ import Emittery, { UnsubscribeFunction } from "emittery";
|
|
|
2
2
|
import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
|
|
3
3
|
import { AppInfo, AppSignalCb, AppWebsocket, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse } from "../index.js";
|
|
4
4
|
import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A class to establish a websocket connection to an App interface, for a
|
|
7
|
+
* specific agent and app.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
5
11
|
export declare class AppAgentWebsocket implements AppAgentClient {
|
|
6
12
|
myPubKey: AgentPubKey;
|
|
7
13
|
readonly appWebsocket: AppWebsocket;
|
|
@@ -9,13 +15,64 @@ export declare class AppAgentWebsocket implements AppAgentClient {
|
|
|
9
15
|
cachedAppInfo?: AppInfo;
|
|
10
16
|
readonly emitter: Emittery<AppAgentEvents>;
|
|
11
17
|
private constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Request the app's info, including all cell infos.
|
|
20
|
+
*
|
|
21
|
+
* @returns The app's {@link AppInfo}.
|
|
22
|
+
*/
|
|
12
23
|
appInfo(): Promise<AppInfo>;
|
|
24
|
+
/**
|
|
25
|
+
* Instance factory for creating AppAgentWebsockets.
|
|
26
|
+
*
|
|
27
|
+
* @param url - The `ws://` URL of the App API to connect to.
|
|
28
|
+
* @param installed_app_id - ID of the App to link to.
|
|
29
|
+
* @param defaultTimeout - Timeout to default to for all operations.
|
|
30
|
+
* @returns A new instance of an AppAgentWebsocket.
|
|
31
|
+
*/
|
|
13
32
|
static connect(url: string, installed_app_id: InstalledAppId, defaultTimeout?: number): Promise<AppAgentWebsocket>;
|
|
33
|
+
/**
|
|
34
|
+
* Get a cell id by its role name or clone id.
|
|
35
|
+
*
|
|
36
|
+
* @param roleName - The role name or clone id of the cell.
|
|
37
|
+
* @param appInfo - The app info containing all cell infos.
|
|
38
|
+
* @returns The cell id or throws an error if not found.
|
|
39
|
+
*/
|
|
14
40
|
getCellIdFromRoleName(roleName: RoleName, appInfo: AppInfo): CellId;
|
|
41
|
+
/**
|
|
42
|
+
* Call a zome.
|
|
43
|
+
*
|
|
44
|
+
* @param request - The zome call arguments.
|
|
45
|
+
* @param timeout - A timeout to override the default.
|
|
46
|
+
* @returns The zome call's response.
|
|
47
|
+
*/
|
|
15
48
|
callZome(request: AppAgentCallZomeRequest, timeout?: number): Promise<CallZomeResponse>;
|
|
49
|
+
/**
|
|
50
|
+
* Clone an existing provisioned cell.
|
|
51
|
+
*
|
|
52
|
+
* @param args - Specify the cell to clone.
|
|
53
|
+
* @returns The created clone cell.
|
|
54
|
+
*/
|
|
16
55
|
createCloneCell(args: AppCreateCloneCellRequest): Promise<CreateCloneCellResponse>;
|
|
56
|
+
/**
|
|
57
|
+
* Enable a disabled clone cell.
|
|
58
|
+
*
|
|
59
|
+
* @param args - Specify the clone cell to enable.
|
|
60
|
+
* @returns The enabled clone cell.
|
|
61
|
+
*/
|
|
17
62
|
enableCloneCell(args: AppEnableCloneCellRequest): Promise<EnableCloneCellResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Disable an enabled clone cell.
|
|
65
|
+
*
|
|
66
|
+
* @param args - Specify the clone cell to disable.
|
|
67
|
+
*/
|
|
18
68
|
disableCloneCell(args: AppDisableCloneCellRequest): Promise<DisableCloneCellResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Register an event listener for signals.
|
|
71
|
+
*
|
|
72
|
+
* @param eventName - Event name to listen to (currently only "signal").
|
|
73
|
+
* @param listener - The function to call when event is triggered.
|
|
74
|
+
* @returns A function to unsubscribe the event listener.
|
|
75
|
+
*/
|
|
19
76
|
on<Name extends keyof AppAgentEvents>(eventName: Name | readonly Name[], listener: AppSignalCb): UnsubscribeFunction;
|
|
20
77
|
private containsCell;
|
|
21
78
|
}
|
|
@@ -18,6 +18,12 @@ function getPubKey(appInfo) {
|
|
|
18
18
|
}
|
|
19
19
|
throw new Error(`This app doesn't have any cells, so we can't return the agent public key for it. This is a known issue, and is going to be fixed in the near future.`);
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A class to establish a websocket connection to an App interface, for a
|
|
23
|
+
* specific agent and app.
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
21
27
|
export class AppAgentWebsocket {
|
|
22
28
|
myPubKey;
|
|
23
29
|
appWebsocket;
|
|
@@ -36,6 +42,11 @@ export class AppAgentWebsocket {
|
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Request the app's info, including all cell infos.
|
|
47
|
+
*
|
|
48
|
+
* @returns The app's {@link AppInfo}.
|
|
49
|
+
*/
|
|
39
50
|
async appInfo() {
|
|
40
51
|
const appInfo = await this.appWebsocket.appInfo({
|
|
41
52
|
installed_app_id: this.installedAppId,
|
|
@@ -43,6 +54,14 @@ export class AppAgentWebsocket {
|
|
|
43
54
|
this.cachedAppInfo = appInfo;
|
|
44
55
|
return appInfo;
|
|
45
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Instance factory for creating AppAgentWebsockets.
|
|
59
|
+
*
|
|
60
|
+
* @param url - The `ws://` URL of the App API to connect to.
|
|
61
|
+
* @param installed_app_id - ID of the App to link to.
|
|
62
|
+
* @param defaultTimeout - Timeout to default to for all operations.
|
|
63
|
+
* @returns A new instance of an AppAgentWebsocket.
|
|
64
|
+
*/
|
|
46
65
|
static async connect(url, installed_app_id, defaultTimeout) {
|
|
47
66
|
const appWebsocket = await AppWebsocket.connect(url, defaultTimeout);
|
|
48
67
|
const appInfo = await appWebsocket.appInfo({
|
|
@@ -53,6 +72,13 @@ export class AppAgentWebsocket {
|
|
|
53
72
|
appAgentWs.cachedAppInfo = appInfo;
|
|
54
73
|
return appAgentWs;
|
|
55
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Get a cell id by its role name or clone id.
|
|
77
|
+
*
|
|
78
|
+
* @param roleName - The role name or clone id of the cell.
|
|
79
|
+
* @param appInfo - The app info containing all cell infos.
|
|
80
|
+
* @returns The cell id or throws an error if not found.
|
|
81
|
+
*/
|
|
56
82
|
getCellIdFromRoleName(roleName, appInfo) {
|
|
57
83
|
if (isCloneId(roleName)) {
|
|
58
84
|
const baseRoleName = getBaseRoleNameFromCloneId(roleName);
|
|
@@ -74,6 +100,13 @@ export class AppAgentWebsocket {
|
|
|
74
100
|
}
|
|
75
101
|
return cell[CellType.Provisioned].cell_id;
|
|
76
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Call a zome.
|
|
105
|
+
*
|
|
106
|
+
* @param request - The zome call arguments.
|
|
107
|
+
* @param timeout - A timeout to override the default.
|
|
108
|
+
* @returns The zome call's response.
|
|
109
|
+
*/
|
|
77
110
|
async callZome(request, timeout) {
|
|
78
111
|
if (!("provenance" in request)) {
|
|
79
112
|
request = {
|
|
@@ -98,6 +131,12 @@ export class AppAgentWebsocket {
|
|
|
98
131
|
throw new Error("callZome requires a role_name or cell_id arg");
|
|
99
132
|
}
|
|
100
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Clone an existing provisioned cell.
|
|
136
|
+
*
|
|
137
|
+
* @param args - Specify the cell to clone.
|
|
138
|
+
* @returns The created clone cell.
|
|
139
|
+
*/
|
|
101
140
|
async createCloneCell(args) {
|
|
102
141
|
const clonedCell = this.appWebsocket.createCloneCell({
|
|
103
142
|
app_id: this.installedAppId,
|
|
@@ -106,18 +145,36 @@ export class AppAgentWebsocket {
|
|
|
106
145
|
this.cachedAppInfo = undefined;
|
|
107
146
|
return clonedCell;
|
|
108
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Enable a disabled clone cell.
|
|
150
|
+
*
|
|
151
|
+
* @param args - Specify the clone cell to enable.
|
|
152
|
+
* @returns The enabled clone cell.
|
|
153
|
+
*/
|
|
109
154
|
async enableCloneCell(args) {
|
|
110
155
|
return this.appWebsocket.enableCloneCell({
|
|
111
156
|
app_id: this.installedAppId,
|
|
112
157
|
...args,
|
|
113
158
|
});
|
|
114
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Disable an enabled clone cell.
|
|
162
|
+
*
|
|
163
|
+
* @param args - Specify the clone cell to disable.
|
|
164
|
+
*/
|
|
115
165
|
async disableCloneCell(args) {
|
|
116
166
|
return this.appWebsocket.disableCloneCell({
|
|
117
167
|
app_id: this.installedAppId,
|
|
118
168
|
...args,
|
|
119
169
|
});
|
|
120
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Register an event listener for signals.
|
|
173
|
+
*
|
|
174
|
+
* @param eventName - Event name to listen to (currently only "signal").
|
|
175
|
+
* @param listener - The function to call when event is triggered.
|
|
176
|
+
* @returns A function to unsubscribe the event listener.
|
|
177
|
+
*/
|
|
121
178
|
on(eventName, listener) {
|
|
122
179
|
return this.emitter.on(eventName, listener);
|
|
123
180
|
}
|
|
@@ -143,4 +200,3 @@ export class AppAgentWebsocket {
|
|
|
143
200
|
}
|
|
144
201
|
const isSameCell = (cellId1, cellId2) => cellId1[0].every((byte, index) => byte === cellId2[0][index]) &&
|
|
145
202
|
cellId1[1].every((byte, index) => byte === cellId2[1][index]);
|
|
146
|
-
//# sourceMappingURL=websocket.js.map
|
package/lib/api/client.d.ts
CHANGED
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
import { decode } from "@msgpack/msgpack";
|
|
3
3
|
import Emittery from "emittery";
|
|
4
4
|
import Websocket from "isomorphic-ws";
|
|
5
|
-
interface HolochainMessage {
|
|
6
|
-
id: number;
|
|
7
|
-
type: "response" | "signal";
|
|
8
|
-
data: ArrayLike<number> | null;
|
|
9
|
-
}
|
|
10
5
|
/**
|
|
11
6
|
* A Websocket client which can make requests and receive responses,
|
|
12
|
-
* as well as send and receive signals
|
|
7
|
+
* as well as send and receive signals.
|
|
13
8
|
*
|
|
14
9
|
* Uses Holochain's websocket WireMessage for communication.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
15
12
|
*/
|
|
16
13
|
export declare class WsClient extends Emittery {
|
|
17
14
|
socket: Websocket;
|
|
@@ -21,10 +18,29 @@ export declare class WsClient extends Emittery {
|
|
|
21
18
|
}>;
|
|
22
19
|
index: number;
|
|
23
20
|
constructor(socket: Websocket);
|
|
21
|
+
/**
|
|
22
|
+
* Instance factory for creating WsClients.
|
|
23
|
+
*
|
|
24
|
+
* @param url - The `ws://` URL to connect to.
|
|
25
|
+
* @returns An new instance of the WsClient.
|
|
26
|
+
*/
|
|
24
27
|
static connect(url: string): Promise<WsClient>;
|
|
28
|
+
/**
|
|
29
|
+
* Sends data as a signal.
|
|
30
|
+
*
|
|
31
|
+
* @param data - Data to send.
|
|
32
|
+
*/
|
|
25
33
|
emitSignal(data: unknown): void;
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Send requests to the connected websocket.
|
|
36
|
+
*
|
|
37
|
+
* @param request - The request to send over the websocket.
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
request<Req, Res>(request: Req): Promise<Res>;
|
|
41
|
+
private handleResponse;
|
|
42
|
+
/**
|
|
43
|
+
* Close the websocket connection.
|
|
44
|
+
*/
|
|
28
45
|
close(): Promise<void>;
|
|
29
46
|
}
|
|
30
|
-
export {};
|
package/lib/api/client.js
CHANGED
|
@@ -4,9 +4,11 @@ import Websocket from "isomorphic-ws";
|
|
|
4
4
|
import { SignalType } from "./app/types.js";
|
|
5
5
|
/**
|
|
6
6
|
* A Websocket client which can make requests and receive responses,
|
|
7
|
-
* as well as send and receive signals
|
|
7
|
+
* as well as send and receive signals.
|
|
8
8
|
*
|
|
9
9
|
* Uses Holochain's websocket WireMessage for communication.
|
|
10
|
+
*
|
|
11
|
+
* @public
|
|
10
12
|
*/
|
|
11
13
|
export class WsClient extends Emittery {
|
|
12
14
|
socket;
|
|
@@ -39,19 +41,20 @@ export class WsClient extends Emittery {
|
|
|
39
41
|
if (message.data === null) {
|
|
40
42
|
throw new Error("received a signal without data");
|
|
41
43
|
}
|
|
42
|
-
const
|
|
43
|
-
assertHolochainSignal(
|
|
44
|
-
if (
|
|
44
|
+
const deserializedSignal = decode(message.data);
|
|
45
|
+
assertHolochainSignal(deserializedSignal);
|
|
46
|
+
if (SignalType.System in deserializedSignal) {
|
|
45
47
|
// We have received a system signal, do nothing
|
|
46
48
|
return;
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
// and this array is nested within the App key within the returned message.
|
|
50
|
-
const cell_id = derializedSignal.App[0];
|
|
50
|
+
const encodedAppSignal = deserializedSignal[SignalType.App];
|
|
51
51
|
// In order to return readible content to the UI, the signal payload must also be deserialized.
|
|
52
|
-
const payload = decode(
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const payload = decode(encodedAppSignal.signal);
|
|
53
|
+
const signal = {
|
|
54
|
+
cell_id: encodedAppSignal.cell_id,
|
|
55
|
+
zome_name: encodedAppSignal.zome_name,
|
|
56
|
+
payload,
|
|
57
|
+
};
|
|
55
58
|
this.emit("signal", signal);
|
|
56
59
|
}
|
|
57
60
|
else if (message.type === "response") {
|
|
@@ -62,6 +65,12 @@ export class WsClient extends Emittery {
|
|
|
62
65
|
}
|
|
63
66
|
};
|
|
64
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Instance factory for creating WsClients.
|
|
70
|
+
*
|
|
71
|
+
* @param url - The `ws://` URL to connect to.
|
|
72
|
+
* @returns An new instance of the WsClient.
|
|
73
|
+
*/
|
|
65
74
|
static connect(url) {
|
|
66
75
|
return new Promise((resolve, reject) => {
|
|
67
76
|
const socket = new Websocket(url);
|
|
@@ -77,6 +86,11 @@ export class WsClient extends Emittery {
|
|
|
77
86
|
};
|
|
78
87
|
});
|
|
79
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Sends data as a signal.
|
|
91
|
+
*
|
|
92
|
+
* @param data - Data to send.
|
|
93
|
+
*/
|
|
80
94
|
emitSignal(data) {
|
|
81
95
|
const encodedMsg = encode({
|
|
82
96
|
type: "signal",
|
|
@@ -84,13 +98,19 @@ export class WsClient extends Emittery {
|
|
|
84
98
|
});
|
|
85
99
|
this.socket.send(encodedMsg);
|
|
86
100
|
}
|
|
87
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Send requests to the connected websocket.
|
|
103
|
+
*
|
|
104
|
+
* @param request - The request to send over the websocket.
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
request(request) {
|
|
88
108
|
const id = this.index;
|
|
89
109
|
this.index += 1;
|
|
90
110
|
const encodedMsg = encode({
|
|
91
111
|
id,
|
|
92
112
|
type: "request",
|
|
93
|
-
data: encode(
|
|
113
|
+
data: encode(request),
|
|
94
114
|
});
|
|
95
115
|
const promise = new Promise((resolve, reject) => {
|
|
96
116
|
this.pendingRequests[id] = { resolve, reject };
|
|
@@ -118,6 +138,9 @@ export class WsClient extends Emittery {
|
|
|
118
138
|
console.error(`Got response with no matching request. id=${id}`);
|
|
119
139
|
}
|
|
120
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Close the websocket connection.
|
|
143
|
+
*/
|
|
121
144
|
close() {
|
|
122
145
|
const closedPromise = new Promise((resolve) => this.socket.on("close", resolve));
|
|
123
146
|
this.socket.close();
|
|
@@ -141,4 +164,3 @@ function assertHolochainSignal(signal) {
|
|
|
141
164
|
}
|
|
142
165
|
throw new Error(`unknown signal format ${JSON.stringify(signal, null, 4)}`);
|
|
143
166
|
}
|
|
144
|
-
//# sourceMappingURL=client.js.map
|
package/lib/api/common.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { RoleName } from "../types.js";
|
|
2
2
|
export declare const DEFAULT_TIMEOUT = 15000;
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
3
6
|
export declare type Transformer<ReqI, ReqO, ResI, ResO> = {
|
|
4
7
|
input: (req: ReqI) => ReqO;
|
|
5
8
|
output: (res: ResI) => ResO;
|
|
6
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
7
13
|
export declare type Requester<Req, Res> = (req: Req, timeout?: number) => Promise<Res>;
|
|
14
|
+
/**
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
8
17
|
export declare type RequesterUnit<Res> = () => Promise<Res>;
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
9
21
|
export declare type Tagged<T> = {
|
|
10
22
|
type: string;
|
|
11
23
|
data: T;
|
|
@@ -14,17 +26,34 @@ export declare type Tagged<T> = {
|
|
|
14
26
|
* Take a Requester function which deals with tagged requests and responses,
|
|
15
27
|
* and return a Requester which deals only with the inner data types, also
|
|
16
28
|
* with the optional Transformer applied to further modify the input and output.
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
17
31
|
*/
|
|
18
32
|
export declare const requesterTransformer: <ReqI, ReqO, ResI, ResO>(requester: Requester<Tagged<ReqO>, Tagged<ResI>>, tag: string, transform?: Transformer<ReqI, ReqO, ResI, ResO>) => (req: ReqI, timeout?: number) => Promise<ResO>;
|
|
19
33
|
export declare const catchError: (res: any) => Promise<any>;
|
|
20
34
|
export declare const promiseTimeout: (promise: Promise<unknown>, tag: string, ms: number) => Promise<unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a cell's role name is a valid clone id.
|
|
37
|
+
*
|
|
38
|
+
* @param roleName - The role name to check.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
21
42
|
export declare const isCloneId: (roleName: RoleName) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Parse a clone id and get the role name part of it.
|
|
45
|
+
*
|
|
46
|
+
* @param roleName - The role name to parse.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
22
49
|
export declare const getBaseRoleNameFromCloneId: (roleName: RoleName) => string;
|
|
23
50
|
/**
|
|
24
51
|
* Identifier of a clone cell, composed of the DNA's role id and the index
|
|
25
52
|
* of the clone, starting at 0.
|
|
26
53
|
*
|
|
27
54
|
* Example: `profiles.0`
|
|
55
|
+
*
|
|
56
|
+
* @public
|
|
28
57
|
*/
|
|
29
58
|
export declare class CloneId {
|
|
30
59
|
private readonly roleName;
|
|
@@ -32,7 +61,7 @@ export declare class CloneId {
|
|
|
32
61
|
constructor(roleName: RoleName, index: number);
|
|
33
62
|
/**
|
|
34
63
|
* Parse a role id of a clone cell to obtain a clone id instance.
|
|
35
|
-
* @param roleName Role id to parse.
|
|
64
|
+
* @param roleName - Role id to parse.
|
|
36
65
|
* @returns A clone id instance.
|
|
37
66
|
*/
|
|
38
67
|
static fromRoleName(roleName: RoleName): CloneId;
|
package/lib/api/common.js
CHANGED
|
@@ -4,6 +4,8 @@ export const DEFAULT_TIMEOUT = 15000;
|
|
|
4
4
|
* Take a Requester function which deals with tagged requests and responses,
|
|
5
5
|
* and return a Requester which deals only with the inner data types, also
|
|
6
6
|
* with the optional Transformer applied to further modify the input and output.
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
7
9
|
*/
|
|
8
10
|
export const requesterTransformer = (requester, tag, transform = identityTransformer) => async (req, timeout) => {
|
|
9
11
|
const transformedInput = await transform.input(req);
|
|
@@ -40,7 +42,20 @@ export const promiseTimeout = (promise, tag, ms) => {
|
|
|
40
42
|
});
|
|
41
43
|
};
|
|
42
44
|
const CLONE_ID_DELIMITER = ".";
|
|
45
|
+
/**
|
|
46
|
+
* Check if a cell's role name is a valid clone id.
|
|
47
|
+
*
|
|
48
|
+
* @param roleName - The role name to check.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
43
52
|
export const isCloneId = (roleName) => roleName.includes(CLONE_ID_DELIMITER);
|
|
53
|
+
/**
|
|
54
|
+
* Parse a clone id and get the role name part of it.
|
|
55
|
+
*
|
|
56
|
+
* @param roleName - The role name to parse.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
44
59
|
export const getBaseRoleNameFromCloneId = (roleName) => {
|
|
45
60
|
if (!isCloneId(roleName)) {
|
|
46
61
|
throw new Error("invalid clone id: no clone id delimiter found in role name");
|
|
@@ -52,6 +67,8 @@ export const getBaseRoleNameFromCloneId = (roleName) => {
|
|
|
52
67
|
* of the clone, starting at 0.
|
|
53
68
|
*
|
|
54
69
|
* Example: `profiles.0`
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
55
72
|
*/
|
|
56
73
|
export class CloneId {
|
|
57
74
|
roleName;
|
|
@@ -62,7 +79,7 @@ export class CloneId {
|
|
|
62
79
|
}
|
|
63
80
|
/**
|
|
64
81
|
* Parse a role id of a clone cell to obtain a clone id instance.
|
|
65
|
-
* @param roleName Role id to parse.
|
|
82
|
+
* @param roleName - Role id to parse.
|
|
66
83
|
* @returns A clone id instance.
|
|
67
84
|
*/
|
|
68
85
|
static fromRoleName(roleName) {
|
|
@@ -79,4 +96,3 @@ export class CloneId {
|
|
|
79
96
|
return this.roleName;
|
|
80
97
|
}
|
|
81
98
|
}
|
|
82
|
-
//# sourceMappingURL=common.js.map
|
package/lib/api/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ export { hashZomeCall } from "@holochain/serialization";
|
|
|
2
2
|
export * from "./admin/index.js";
|
|
3
3
|
export * from "./app-agent/index.js";
|
|
4
4
|
export * from "./app/index.js";
|
|
5
|
-
export { CloneId } from "./common.js";
|
|
5
|
+
export { CloneId, Requester, Transformer } from "./common.js";
|
|
6
|
+
export { WsClient } from "./client.js";
|
|
6
7
|
export * from "./zome-call-signing.js";
|
package/lib/api/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import nacl from "tweetnacl";
|
|
2
2
|
import { CapSecret } from "../hdk/capabilities.js";
|
|
3
3
|
import { AgentPubKey, CellId } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
4
7
|
export declare type Nonce256Bit = Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
5
11
|
export interface SigningCredentials {
|
|
6
12
|
capSecret: CapSecret;
|
|
7
13
|
keyPair: nacl.SignKeyPair;
|
|
@@ -12,25 +18,42 @@ export interface SigningCredentials {
|
|
|
12
18
|
*
|
|
13
19
|
* @param cellId - Cell id to get credentials of.
|
|
14
20
|
* @returns The keys and cap secret required for signing a zome call.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
15
23
|
*/
|
|
16
24
|
export declare const getSigningCredentials: (cellId: CellId) => SigningCredentials | undefined;
|
|
17
25
|
/**
|
|
18
26
|
* Set credentials for signing zome calls.
|
|
19
27
|
*
|
|
20
28
|
* @param cellId - Cell id to set credentials for.
|
|
21
|
-
*
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
22
31
|
*/
|
|
23
32
|
export declare const setSigningCredentials: (cellId: CellId, credentials: SigningCredentials) => void;
|
|
24
33
|
/**
|
|
25
34
|
* Generates a key pair for signing zome calls.
|
|
26
35
|
*
|
|
27
36
|
* @returns The signing key pair and an agent pub key based on the public key.
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
28
39
|
*/
|
|
29
40
|
export declare const generateSigningKeyPair: () => [
|
|
30
41
|
nacl.SignKeyPair,
|
|
31
42
|
AgentPubKey
|
|
32
43
|
];
|
|
44
|
+
/**
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
33
47
|
export declare const randomCapSecret: () => Promise<CapSecret>;
|
|
48
|
+
/**
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
34
51
|
export declare const randomNonce: () => Promise<Nonce256Bit>;
|
|
52
|
+
/**
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
35
55
|
export declare const randomByteArray: (length: number) => Promise<Uint8Array>;
|
|
56
|
+
/**
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
36
59
|
export declare const getNonceExpiration: () => number;
|
|
@@ -6,6 +6,8 @@ const signingCredentials = new Map();
|
|
|
6
6
|
*
|
|
7
7
|
* @param cellId - Cell id to get credentials of.
|
|
8
8
|
* @returns The keys and cap secret required for signing a zome call.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
9
11
|
*/
|
|
10
12
|
export const getSigningCredentials = (cellId) => {
|
|
11
13
|
const cellIdB64 = encodeHashToBase64(cellId[0]).concat(encodeHashToBase64(cellId[1]));
|
|
@@ -15,7 +17,8 @@ export const getSigningCredentials = (cellId) => {
|
|
|
15
17
|
* Set credentials for signing zome calls.
|
|
16
18
|
*
|
|
17
19
|
* @param cellId - Cell id to set credentials for.
|
|
18
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
19
22
|
*/
|
|
20
23
|
export const setSigningCredentials = (cellId, credentials) => {
|
|
21
24
|
const cellIdB64 = encodeHashToBase64(cellId[0]).concat(encodeHashToBase64(cellId[1]));
|
|
@@ -25,14 +28,25 @@ export const setSigningCredentials = (cellId, credentials) => {
|
|
|
25
28
|
* Generates a key pair for signing zome calls.
|
|
26
29
|
*
|
|
27
30
|
* @returns The signing key pair and an agent pub key based on the public key.
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
28
33
|
*/
|
|
29
34
|
export const generateSigningKeyPair = () => {
|
|
30
35
|
const keyPair = nacl.sign.keyPair();
|
|
31
36
|
const signingKey = new Uint8Array([132, 32, 36].concat(...keyPair.publicKey).concat(...[0, 0, 0, 0]));
|
|
32
37
|
return [keyPair, signingKey];
|
|
33
38
|
};
|
|
39
|
+
/**
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
34
42
|
export const randomCapSecret = () => randomByteArray(64);
|
|
43
|
+
/**
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
35
46
|
export const randomNonce = async () => randomByteArray(32);
|
|
47
|
+
/**
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
36
50
|
export const randomByteArray = async (length) => {
|
|
37
51
|
if (typeof window !== "undefined" &&
|
|
38
52
|
"crypto" in window &&
|
|
@@ -44,5 +58,7 @@ export const randomByteArray = async (length) => {
|
|
|
44
58
|
return new Uint8Array(crypto.randomBytes(length));
|
|
45
59
|
}
|
|
46
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
47
64
|
export const getNonceExpiration = () => (Date.now() + 5 * 60 * 1000) * 1000; // 5 mins from now in microseconds
|
|
48
|
-
//# sourceMappingURL=zome-call-signing.js.map
|