@holochain/client 0.13.0 → 0.14.1
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 +6 -3
- package/lib/api/admin/types.d.ts +81 -81
- package/lib/api/admin/websocket.js +2 -2
- package/lib/api/app/types.d.ts +25 -17
- package/lib/api/app/websocket.d.ts +1 -1
- package/lib/api/app/websocket.js +7 -7
- package/lib/api/app-agent/types.d.ts +7 -7
- package/lib/api/app-agent/websocket.d.ts +3 -1
- package/lib/api/app-agent/websocket.js +2 -1
- package/lib/api/client.d.ts +6 -5
- package/lib/api/client.js +14 -7
- package/lib/api/common.d.ts +5 -5
- package/lib/api/common.js +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/zome-call-signing.d.ts +15 -9
- package/lib/api/zome-call-signing.js +11 -16
- package/lib/environments/launcher.d.ts +2 -1
- package/lib/environments/launcher.js +5 -5
- package/lib/hdk/action.d.ts +3 -3
- package/lib/hdk/capabilities.d.ts +5 -5
- package/lib/hdk/countersigning.d.ts +4 -4
- package/lib/hdk/dht-ops.d.ts +1 -1
- package/lib/hdk/entry.d.ts +4 -4
- package/lib/hdk/link.d.ts +5 -0
- package/lib/hdk/link.js +1 -0
- package/lib/hdk/record.d.ts +2 -2
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +27 -23
- package/package.json +10 -11
package/lib/api/app/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AgentPubKey, CellId, DnaHash, DnaProperties, InstalledAppId, NetworkInfo, RoleName, Timestamp } from "../../types.js";
|
|
2
|
-
import { AppInfo, ClonedCell, FunctionName, MembraneProof, NetworkSeed, ZomeName } from "../admin/
|
|
2
|
+
import { AppInfo, ClonedCell, FunctionName, MembraneProof, NetworkSeed, ZomeName } from "../admin/types.js";
|
|
3
3
|
import { Requester } from "../common.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type CallZomeRequestGeneric<Payload> = {
|
|
8
8
|
cell_id: CellId;
|
|
9
9
|
zome_name: ZomeName;
|
|
10
10
|
fn_name: FunctionName;
|
|
@@ -14,25 +14,25 @@ export declare type CallZomeRequestGeneric<Payload> = {
|
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export type CallZomeRequest = CallZomeRequestGeneric<any>;
|
|
18
18
|
/**
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export type CallZomeResponseGeneric<Payload> = Payload;
|
|
22
22
|
/**
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type CallZomeResponse = CallZomeResponseGeneric<any>;
|
|
26
26
|
/**
|
|
27
27
|
* @public
|
|
28
28
|
*/
|
|
29
|
-
export
|
|
29
|
+
export type AppInfoRequest = {
|
|
30
30
|
installed_app_id: InstalledAppId;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
33
33
|
* @public
|
|
34
34
|
*/
|
|
35
|
-
export
|
|
35
|
+
export type AppInfoResponse = AppInfo;
|
|
36
36
|
/**
|
|
37
37
|
* @public
|
|
38
38
|
*/
|
|
@@ -83,7 +83,7 @@ export interface CreateCloneCellRequest {
|
|
|
83
83
|
/**
|
|
84
84
|
* @public
|
|
85
85
|
*/
|
|
86
|
-
export
|
|
86
|
+
export type CreateCloneCellResponse = ClonedCell;
|
|
87
87
|
/**
|
|
88
88
|
* @public
|
|
89
89
|
*/
|
|
@@ -100,23 +100,31 @@ export interface DisableCloneCellRequest {
|
|
|
100
100
|
/**
|
|
101
101
|
* @public
|
|
102
102
|
*/
|
|
103
|
-
export
|
|
103
|
+
export type DisableCloneCellResponse = void;
|
|
104
104
|
/**
|
|
105
105
|
* @public
|
|
106
106
|
*/
|
|
107
|
-
export
|
|
107
|
+
export type EnableCloneCellRequest = DisableCloneCellRequest;
|
|
108
108
|
/**
|
|
109
109
|
* @public
|
|
110
110
|
*/
|
|
111
|
-
export
|
|
111
|
+
export type EnableCloneCellResponse = CreateCloneCellResponse;
|
|
112
112
|
/**
|
|
113
113
|
* @public
|
|
114
114
|
*/
|
|
115
115
|
export interface NetworkInfoRequest {
|
|
116
116
|
/**
|
|
117
|
-
* The
|
|
117
|
+
* The calling agent
|
|
118
|
+
*/
|
|
119
|
+
agent_pub_key: AgentPubKey;
|
|
120
|
+
/**
|
|
121
|
+
* Get network info for these DNAs
|
|
118
122
|
*/
|
|
119
123
|
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;
|
|
120
128
|
}
|
|
121
129
|
/**
|
|
122
130
|
* @public
|
|
@@ -128,7 +136,7 @@ export declare const SignalType: {
|
|
|
128
136
|
/**
|
|
129
137
|
* @public
|
|
130
138
|
*/
|
|
131
|
-
export
|
|
139
|
+
export type Signal = {
|
|
132
140
|
[SignalType.App]: EncodedAppSignal;
|
|
133
141
|
} | {
|
|
134
142
|
[SignalType.System]: unknown;
|
|
@@ -136,7 +144,7 @@ export declare type Signal = {
|
|
|
136
144
|
/**
|
|
137
145
|
* @public
|
|
138
146
|
*/
|
|
139
|
-
export
|
|
147
|
+
export type EncodedAppSignal = {
|
|
140
148
|
cell_id: CellId;
|
|
141
149
|
zome_name: string;
|
|
142
150
|
signal: Uint8Array;
|
|
@@ -144,7 +152,7 @@ export declare type EncodedAppSignal = {
|
|
|
144
152
|
/**
|
|
145
153
|
* @public
|
|
146
154
|
*/
|
|
147
|
-
export
|
|
155
|
+
export type AppSignal = {
|
|
148
156
|
cell_id: CellId;
|
|
149
157
|
zome_name: string;
|
|
150
158
|
payload: unknown;
|
|
@@ -152,11 +160,11 @@ export declare type AppSignal = {
|
|
|
152
160
|
/**
|
|
153
161
|
* @public
|
|
154
162
|
*/
|
|
155
|
-
export
|
|
163
|
+
export type AppSignalCb = (signal: AppSignal) => void;
|
|
156
164
|
/**
|
|
157
165
|
* @public
|
|
158
166
|
*/
|
|
159
|
-
export
|
|
167
|
+
export type NetworkInfoResponse = NetworkInfo[];
|
|
160
168
|
/**
|
|
161
169
|
* @public
|
|
162
170
|
*/
|
|
@@ -24,7 +24,7 @@ export declare class AppWebsocket extends Emittery implements AppApi {
|
|
|
24
24
|
* @returns A new instance of an AppWebsocket.
|
|
25
25
|
*/
|
|
26
26
|
static connect(url: string, defaultTimeout?: number): Promise<AppWebsocket>;
|
|
27
|
-
_requester
|
|
27
|
+
_requester<ReqI, ReqO, ResI, ResO>(tag: string, transformer?: Transformer<ReqI, ReqO, ResI, ResO>): (req: ReqI, timeout?: number | undefined) => Promise<ResO>;
|
|
28
28
|
/**
|
|
29
29
|
* Request the app's info, including all cell infos.
|
|
30
30
|
*
|
package/lib/api/app/websocket.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { hashZomeCall } from "@holochain/serialization";
|
|
2
2
|
import { decode, encode } from "@msgpack/msgpack";
|
|
3
|
+
import * as ed25519 from "@noble/ed25519";
|
|
3
4
|
import Emittery from "emittery";
|
|
4
|
-
import nacl from "tweetnacl";
|
|
5
5
|
import { getLauncherEnvironment, isLauncher, signZomeCallTauri, } from "../../environments/launcher.js";
|
|
6
6
|
import { encodeHashToBase64 } from "../../utils/base64.js";
|
|
7
7
|
import { WsClient } from "../client.js";
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_TIMEOUT, catchError, 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
|
|
@@ -42,7 +42,9 @@ export class AppWebsocket extends Emittery {
|
|
|
42
42
|
wsClient.on("signal", (signal) => appWebsocket.emit("signal", signal));
|
|
43
43
|
return appWebsocket;
|
|
44
44
|
}
|
|
45
|
-
_requester
|
|
45
|
+
_requester(tag, transformer) {
|
|
46
|
+
return requesterTransformer((req, timeout) => promiseTimeout(this.client.request(req), tag, timeout || this.defaultTimeout).then(catchError), tag, transformer);
|
|
47
|
+
}
|
|
46
48
|
/**
|
|
47
49
|
* Request the app's info, including all cell infos.
|
|
48
50
|
*
|
|
@@ -120,13 +122,11 @@ export const signZomeCall = async (request) => {
|
|
|
120
122
|
fn_name: request.fn_name,
|
|
121
123
|
provenance: signingCredentialsForCell.signingKey,
|
|
122
124
|
payload: encode(request.payload),
|
|
123
|
-
nonce:
|
|
125
|
+
nonce: randomNonce(),
|
|
124
126
|
expires_at: getNonceExpiration(),
|
|
125
127
|
};
|
|
126
128
|
const hashedZomeCall = await hashZomeCall(unsignedZomeCallPayload);
|
|
127
|
-
const signature =
|
|
128
|
-
.sign(hashedZomeCall, signingCredentialsForCell.keyPair.secretKey)
|
|
129
|
-
.subarray(0, nacl.sign.signatureLength);
|
|
129
|
+
const signature = await ed25519.signAsync(hashedZomeCall, signingCredentialsForCell.keyPair.privateKey);
|
|
130
130
|
const signedZomeCall = {
|
|
131
131
|
...unsignedZomeCallPayload,
|
|
132
132
|
signature,
|
|
@@ -5,35 +5,35 @@ import { CreateCloneCellRequest, CreateCloneCellResponse, DisableCloneCellRespon
|
|
|
5
5
|
/**
|
|
6
6
|
* @public
|
|
7
7
|
*/
|
|
8
|
-
export
|
|
8
|
+
export type NonProvenanceCallZomeRequest = Omit<CallZomeRequest, "provenance">;
|
|
9
9
|
/**
|
|
10
10
|
* @public
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type RoleNameCallZomeRequest = Omit<NonProvenanceCallZomeRequest, "cell_id"> & {
|
|
13
13
|
role_name: RoleName;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export type RoleNameCallZomeRequestSigned = Omit<CallZomeRequestSigned, "cell_id"> & {
|
|
19
19
|
role_name: RoleName;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
22
|
* @public
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
24
|
+
export type AppAgentCallZomeRequest = NonProvenanceCallZomeRequest | RoleNameCallZomeRequest | CallZomeRequestSigned | RoleNameCallZomeRequestSigned;
|
|
25
25
|
/**
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
28
|
+
export type AppCreateCloneCellRequest = Omit<CreateCloneCellRequest, "app_id">;
|
|
29
29
|
/**
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
|
-
export
|
|
32
|
+
export type AppEnableCloneCellRequest = Omit<EnableCloneCellRequest, "app_id">;
|
|
33
33
|
/**
|
|
34
34
|
* @public
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export type AppDisableCloneCellRequest = Omit<DisableCloneCellRequest, "app_id">;
|
|
37
37
|
/**
|
|
38
38
|
* @public
|
|
39
39
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Emittery, { UnsubscribeFunction } from "emittery";
|
|
2
2
|
import { AgentPubKey, CellId, InstalledAppId, RoleName } from "../../types.js";
|
|
3
|
-
import { AppInfo
|
|
3
|
+
import { AppInfo } from "../admin/types.js";
|
|
4
|
+
import { AppSignalCb, CallZomeResponse, CreateCloneCellResponse, DisableCloneCellResponse, EnableCloneCellResponse } from "../app/types.js";
|
|
5
|
+
import { AppWebsocket } from "../app/websocket.js";
|
|
4
6
|
import { AppAgentCallZomeRequest, AppAgentClient, AppAgentEvents, AppCreateCloneCellRequest, AppDisableCloneCellRequest, AppEnableCloneCellRequest } from "./types.js";
|
|
5
7
|
/**
|
|
6
8
|
* A class to establish a websocket connection to an App interface, for a
|
|
@@ -1,8 +1,9 @@
|
|
|
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";
|
|
4
6
|
import { getBaseRoleNameFromCloneId, isCloneId } from "../common.js";
|
|
5
|
-
import { AppWebsocket, CellType, } from "../index.js";
|
|
6
7
|
/**
|
|
7
8
|
* A class to establish a websocket connection to an App interface, for a
|
|
8
9
|
* specific agent and app.
|
package/lib/api/client.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="ws" />
|
|
2
2
|
import { decode } from "@msgpack/msgpack";
|
|
3
3
|
import Emittery from "emittery";
|
|
4
|
-
import
|
|
4
|
+
import IsoWebSocket from "isomorphic-ws";
|
|
5
5
|
/**
|
|
6
|
-
* A
|
|
6
|
+
* A WebSocket client which can make requests and receive responses,
|
|
7
7
|
* as well as send and receive signals.
|
|
8
8
|
*
|
|
9
9
|
* Uses Holochain's websocket WireMessage for communication.
|
|
@@ -11,13 +11,13 @@ import Websocket from "isomorphic-ws";
|
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export declare class WsClient extends Emittery {
|
|
14
|
-
socket:
|
|
14
|
+
socket: IsoWebSocket;
|
|
15
15
|
pendingRequests: Record<number, {
|
|
16
16
|
resolve: (msg: unknown) => ReturnType<typeof decode>;
|
|
17
17
|
reject: (error: Error) => void;
|
|
18
18
|
}>;
|
|
19
19
|
index: number;
|
|
20
|
-
constructor(socket:
|
|
20
|
+
constructor(socket: IsoWebSocket);
|
|
21
21
|
/**
|
|
22
22
|
* Instance factory for creating WsClients.
|
|
23
23
|
*
|
|
@@ -42,5 +42,6 @@ export declare class WsClient extends Emittery {
|
|
|
42
42
|
/**
|
|
43
43
|
* Close the websocket connection.
|
|
44
44
|
*/
|
|
45
|
-
close(code?: number): Promise<
|
|
45
|
+
close(code?: number): Promise<CloseEvent>;
|
|
46
46
|
}
|
|
47
|
+
export { IsoWebSocket };
|
package/lib/api/client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { decode, encode } from "@msgpack/msgpack";
|
|
2
2
|
import Emittery from "emittery";
|
|
3
|
-
import
|
|
3
|
+
import IsoWebSocket from "isomorphic-ws";
|
|
4
4
|
import { SignalType } from "./app/types.js";
|
|
5
5
|
/**
|
|
6
|
-
* A
|
|
6
|
+
* A WebSocket client which can make requests and receive responses,
|
|
7
7
|
* as well as send and receive signals.
|
|
8
8
|
*
|
|
9
9
|
* Uses Holochain's websocket WireMessage for communication.
|
|
@@ -22,8 +22,8 @@ export class WsClient extends Emittery {
|
|
|
22
22
|
socket.onmessage = async (serializedMessage) => {
|
|
23
23
|
// If data is not a buffer (nodejs), it will be a blob (browser)
|
|
24
24
|
let deserializedData;
|
|
25
|
-
if (
|
|
26
|
-
serializedMessage.data instanceof window.Blob) {
|
|
25
|
+
if (globalThis.window &&
|
|
26
|
+
serializedMessage.data instanceof globalThis.window.Blob) {
|
|
27
27
|
deserializedData = await serializedMessage.data.arrayBuffer();
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
@@ -83,7 +83,7 @@ export class WsClient extends Emittery {
|
|
|
83
83
|
*/
|
|
84
84
|
static connect(url) {
|
|
85
85
|
return new Promise((resolve, reject) => {
|
|
86
|
-
const socket = new
|
|
86
|
+
const socket = new IsoWebSocket(url);
|
|
87
87
|
// make sure that there are no uncaught connection
|
|
88
88
|
// errors because that causes nodejs thread to crash
|
|
89
89
|
// with uncaught exception
|
|
@@ -151,8 +151,14 @@ export class WsClient extends Emittery {
|
|
|
151
151
|
/**
|
|
152
152
|
* Close the websocket connection.
|
|
153
153
|
*/
|
|
154
|
-
close(code) {
|
|
155
|
-
const closedPromise = new Promise((resolve) =>
|
|
154
|
+
close(code = 1000) {
|
|
155
|
+
const closedPromise = new Promise((resolve) =>
|
|
156
|
+
// for an unknown reason "addEventListener" is seen as a non-callable
|
|
157
|
+
// property and gives a ts2349 error
|
|
158
|
+
// type assertion as workaround
|
|
159
|
+
this.socket.addEventListener("close", (event) => resolve(event))
|
|
160
|
+
// }
|
|
161
|
+
);
|
|
156
162
|
this.socket.close(code);
|
|
157
163
|
return closedPromise;
|
|
158
164
|
}
|
|
@@ -174,3 +180,4 @@ function assertHolochainSignal(signal) {
|
|
|
174
180
|
}
|
|
175
181
|
throw new Error(`unknown signal format ${JSON.stringify(signal, null, 4)}`);
|
|
176
182
|
}
|
|
183
|
+
export { IsoWebSocket };
|
package/lib/api/common.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { RoleName } from "../types.js";
|
|
2
|
-
export declare const DEFAULT_TIMEOUT =
|
|
2
|
+
export declare const DEFAULT_TIMEOUT = 60000;
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type Transformer<ReqI, ReqO, ResI, ResO> = {
|
|
7
7
|
input: (req: ReqI) => ReqO;
|
|
8
8
|
output: (res: ResI) => ResO;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type Requester<Req, Res> = (req: Req, timeout?: number) => Promise<Res>;
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export type RequesterUnit<Res> = () => Promise<Res>;
|
|
18
18
|
/**
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
|
-
export
|
|
21
|
+
export type Tagged<T> = {
|
|
22
22
|
type: string;
|
|
23
23
|
data: T;
|
|
24
24
|
};
|
package/lib/api/common.js
CHANGED
package/lib/api/index.d.ts
CHANGED
|
@@ -2,6 +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 { IsoWebSocket, WsClient } from "./client.js";
|
|
5
6
|
export { CloneId, Requester, Transformer } from "./common.js";
|
|
6
|
-
export { WsClient } from "./client.js";
|
|
7
7
|
export * from "./zome-call-signing.js";
|
package/lib/api/index.js
CHANGED
|
@@ -2,6 +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 { IsoWebSocket, WsClient } from "./client.js";
|
|
5
6
|
export { CloneId } from "./common.js";
|
|
6
|
-
export { WsClient } from "./client.js";
|
|
7
7
|
export * from "./zome-call-signing.js";
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import nacl from "tweetnacl";
|
|
2
1
|
import { CapSecret } from "../hdk/capabilities.js";
|
|
3
2
|
import { AgentPubKey, CellId } from "../types.js";
|
|
4
3
|
/**
|
|
5
4
|
* @public
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
6
|
+
export type Nonce256Bit = Uint8Array;
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface KeyPair {
|
|
11
|
+
privateKey: Uint8Array;
|
|
12
|
+
publicKey: Uint8Array;
|
|
13
|
+
}
|
|
8
14
|
/**
|
|
9
15
|
* @public
|
|
10
16
|
*/
|
|
11
17
|
export interface SigningCredentials {
|
|
12
18
|
capSecret: CapSecret;
|
|
13
|
-
keyPair:
|
|
19
|
+
keyPair: KeyPair;
|
|
14
20
|
signingKey: AgentPubKey;
|
|
15
21
|
}
|
|
16
22
|
/**
|
|
@@ -37,22 +43,22 @@ export declare const setSigningCredentials: (cellId: CellId, credentials: Signin
|
|
|
37
43
|
*
|
|
38
44
|
* @public
|
|
39
45
|
*/
|
|
40
|
-
export declare const generateSigningKeyPair: () => [
|
|
41
|
-
|
|
46
|
+
export declare const generateSigningKeyPair: () => Promise<[
|
|
47
|
+
KeyPair,
|
|
42
48
|
AgentPubKey
|
|
43
|
-
]
|
|
49
|
+
]>;
|
|
44
50
|
/**
|
|
45
51
|
* @public
|
|
46
52
|
*/
|
|
47
|
-
export declare const randomCapSecret: () =>
|
|
53
|
+
export declare const randomCapSecret: () => CapSecret;
|
|
48
54
|
/**
|
|
49
55
|
* @public
|
|
50
56
|
*/
|
|
51
|
-
export declare const randomNonce: () =>
|
|
57
|
+
export declare const randomNonce: () => Nonce256Bit;
|
|
52
58
|
/**
|
|
53
59
|
* @public
|
|
54
60
|
*/
|
|
55
|
-
export declare const randomByteArray: (length: number) =>
|
|
61
|
+
export declare const randomByteArray: (length: number) => Uint8Array;
|
|
56
62
|
/**
|
|
57
63
|
* @public
|
|
58
64
|
*/
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as ed25519 from "@noble/ed25519";
|
|
2
2
|
import { encodeHashToBase64 } from "../utils/base64.js";
|
|
3
|
+
if (!globalThis.crypto) {
|
|
4
|
+
import("node:crypto").then((webcrypto) => (globalThis.crypto = webcrypto));
|
|
5
|
+
}
|
|
3
6
|
const signingCredentials = new Map();
|
|
4
7
|
/**
|
|
5
8
|
* Get credentials for signing zome calls.
|
|
@@ -31,9 +34,11 @@ export const setSigningCredentials = (cellId, credentials) => {
|
|
|
31
34
|
*
|
|
32
35
|
* @public
|
|
33
36
|
*/
|
|
34
|
-
export const generateSigningKeyPair = () => {
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
+
export const generateSigningKeyPair = async () => {
|
|
38
|
+
const privateKey = ed25519.utils.randomPrivateKey();
|
|
39
|
+
const publicKey = await ed25519.getPublicKeyAsync(privateKey);
|
|
40
|
+
const keyPair = { privateKey, publicKey };
|
|
41
|
+
const signingKey = new Uint8Array([132, 32, 36].concat(...publicKey).concat(...[0, 0, 0, 0]));
|
|
37
42
|
return [keyPair, signingKey];
|
|
38
43
|
};
|
|
39
44
|
/**
|
|
@@ -43,21 +48,11 @@ export const randomCapSecret = () => randomByteArray(64);
|
|
|
43
48
|
/**
|
|
44
49
|
* @public
|
|
45
50
|
*/
|
|
46
|
-
export const randomNonce =
|
|
51
|
+
export const randomNonce = () => randomByteArray(32);
|
|
47
52
|
/**
|
|
48
53
|
* @public
|
|
49
54
|
*/
|
|
50
|
-
export const randomByteArray =
|
|
51
|
-
if (typeof window !== "undefined" &&
|
|
52
|
-
"crypto" in window &&
|
|
53
|
-
"getRandomValues" in window.crypto) {
|
|
54
|
-
return window.crypto.getRandomValues(new Uint8Array(length));
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const crypto = await import("crypto");
|
|
58
|
-
return new Uint8Array(crypto.randomBytes(length));
|
|
59
|
-
}
|
|
60
|
-
};
|
|
55
|
+
export const randomByteArray = (length) => globalThis.crypto.getRandomValues(new Uint8Array(length));
|
|
61
56
|
/**
|
|
62
57
|
* @public
|
|
63
58
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { CallZomeRequest } from "../api/app/types.js";
|
|
2
|
+
import { CallZomeRequestSigned } from "../api/app/websocket.js";
|
|
1
3
|
import { InstalledAppId } from "../types.js";
|
|
2
|
-
import { CallZomeRequest, CallZomeRequestSigned } from "../api/index.js";
|
|
3
4
|
export interface LauncherEnvironment {
|
|
4
5
|
APP_INTERFACE_PORT?: number;
|
|
5
6
|
ADMIN_INTERFACE_PORT?: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { invoke } from "@tauri-apps/api/tauri";
|
|
2
|
-
import { getNonceExpiration, randomNonce, } from "../api/index.js";
|
|
3
1
|
import { encode } from "@msgpack/msgpack";
|
|
2
|
+
import { invoke } from "@tauri-apps/api/tauri";
|
|
3
|
+
import { getNonceExpiration, randomNonce } from "../api/zome-call-signing.js";
|
|
4
4
|
const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__";
|
|
5
|
-
export const isLauncher =
|
|
6
|
-
export const getLauncherEnvironment = () => isLauncher ? window[__HC_LAUNCHER_ENV__] : undefined;
|
|
5
|
+
export const isLauncher = globalThis.window && __HC_LAUNCHER_ENV__ in globalThis.window;
|
|
6
|
+
export const getLauncherEnvironment = () => isLauncher ? globalThis.window[__HC_LAUNCHER_ENV__] : undefined;
|
|
7
7
|
export const signZomeCallTauri = async (request) => {
|
|
8
8
|
const zomeCallUnsigned = {
|
|
9
9
|
provenance: Array.from(request.provenance),
|
|
@@ -11,7 +11,7 @@ export const signZomeCallTauri = async (request) => {
|
|
|
11
11
|
zome_name: request.zome_name,
|
|
12
12
|
fn_name: request.fn_name,
|
|
13
13
|
payload: Array.from(encode(request.payload)),
|
|
14
|
-
nonce: Array.from(
|
|
14
|
+
nonce: Array.from(randomNonce()),
|
|
15
15
|
expires_at: getNonceExpiration(),
|
|
16
16
|
};
|
|
17
17
|
const signedZomeCallTauri = await invoke("sign_zome_call", { zomeCallUnsigned });
|
package/lib/hdk/action.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface SignedActionHashed<H extends Action = Action> {
|
|
|
10
10
|
/**
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type ActionHashed = HoloHashed<Action>;
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
16
16
|
*/
|
|
@@ -29,11 +29,11 @@ export declare enum ActionType {
|
|
|
29
29
|
/**
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
|
-
export
|
|
32
|
+
export type Action = Dna | AgentValidationPkg | InitZomesComplete | CreateLink | DeleteLink | OpenChain | CloseChain | Delete | NewEntryAction;
|
|
33
33
|
/**
|
|
34
34
|
* @public
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export type NewEntryAction = Create | Update;
|
|
37
37
|
/**
|
|
38
38
|
* @public
|
|
39
39
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FunctionName, ZomeName } from "../api/
|
|
1
|
+
import { FunctionName, ZomeName } from "../api/admin/types.js";
|
|
2
2
|
import { AgentPubKey } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type CapSecret = Uint8Array;
|
|
7
7
|
/**
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
@@ -22,7 +22,7 @@ export declare enum GrantedFunctionsType {
|
|
|
22
22
|
/**
|
|
23
23
|
* @public
|
|
24
24
|
*/
|
|
25
|
-
export
|
|
25
|
+
export type GrantedFunctions = {
|
|
26
26
|
[GrantedFunctionsType.All]: null;
|
|
27
27
|
} | {
|
|
28
28
|
[GrantedFunctionsType.Listed]: [ZomeName, FunctionName][];
|
|
@@ -38,7 +38,7 @@ export interface ZomeCallCapGrant {
|
|
|
38
38
|
/**
|
|
39
39
|
* @public
|
|
40
40
|
*/
|
|
41
|
-
export
|
|
41
|
+
export type CapAccess = "Unrestricted" | {
|
|
42
42
|
Transferable: {
|
|
43
43
|
secret: CapSecret;
|
|
44
44
|
};
|
|
@@ -51,7 +51,7 @@ export declare type CapAccess = "Unrestricted" | {
|
|
|
51
51
|
/**
|
|
52
52
|
* @public
|
|
53
53
|
*/
|
|
54
|
-
export
|
|
54
|
+
export type CapGrant = {
|
|
55
55
|
ChainAuthor: AgentPubKey;
|
|
56
56
|
} | {
|
|
57
57
|
RemoteAgent: ZomeCallCapGrant;
|
|
@@ -28,7 +28,7 @@ export interface CounterSigningSessionTimes {
|
|
|
28
28
|
/**
|
|
29
29
|
* @public
|
|
30
30
|
*/
|
|
31
|
-
export
|
|
31
|
+
export type ActionBase = {
|
|
32
32
|
Create: CreateBase;
|
|
33
33
|
} | {
|
|
34
34
|
Update: UpdateBase;
|
|
@@ -50,15 +50,15 @@ export interface UpdateBase {
|
|
|
50
50
|
/**
|
|
51
51
|
* @public
|
|
52
52
|
*/
|
|
53
|
-
export
|
|
53
|
+
export type CounterSigningAgents = Array<[AgentPubKey, Array<Role>]>;
|
|
54
54
|
/**
|
|
55
55
|
* @public
|
|
56
56
|
*/
|
|
57
|
-
export
|
|
57
|
+
export type PreflightBytes = Uint8Array;
|
|
58
58
|
/**
|
|
59
59
|
* @public
|
|
60
60
|
*/
|
|
61
|
-
export
|
|
61
|
+
export type Role = number;
|
|
62
62
|
/**
|
|
63
63
|
* @public
|
|
64
64
|
*/
|
package/lib/hdk/dht-ops.d.ts
CHANGED
package/lib/hdk/entry.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CounterSigningSessionData } from "./countersigning.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type EntryVisibility = {
|
|
8
8
|
Public: null;
|
|
9
9
|
} | {
|
|
10
10
|
Private: null;
|
|
@@ -12,7 +12,7 @@ export declare type EntryVisibility = {
|
|
|
12
12
|
/**
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type AppEntryDef = {
|
|
16
16
|
entry_index: number;
|
|
17
17
|
zome_index: number;
|
|
18
18
|
visibility: EntryVisibility;
|
|
@@ -20,7 +20,7 @@ export declare type AppEntryDef = {
|
|
|
20
20
|
/**
|
|
21
21
|
* @public
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
23
|
+
export type EntryType = "Agent" | {
|
|
24
24
|
App: AppEntryDef;
|
|
25
25
|
} | "CapClaim" | "CapGrant";
|
|
26
26
|
/**
|
|
@@ -33,4 +33,4 @@ export interface EntryContent<E extends string, C> {
|
|
|
33
33
|
/**
|
|
34
34
|
* @public
|
|
35
35
|
*/
|
|
36
|
-
export
|
|
36
|
+
export type Entry = EntryContent<"Agent", AgentPubKey> | EntryContent<"App", Uint8Array> | EntryContent<"CounterSign", [CounterSigningSessionData, Uint8Array]> | EntryContent<"CapGrant", ZomeCallCapGrant> | EntryContent<"CapClaim", CapClaim>;
|