@holochain/client 0.12.7 → 0.12.8
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/lib/api/admin/types.d.ts +5 -105
- package/lib/api/admin/websocket.d.ts +2 -8
- package/lib/api/admin/websocket.js +2 -8
- package/lib/api/app/types.d.ts +2 -10
- package/lib/api/app/websocket.d.ts +2 -2
- package/lib/api/app/websocket.js +10 -29
- package/lib/api/app-agent/types.d.ts +1 -6
- package/lib/api/app-agent/websocket.d.ts +3 -11
- package/lib/api/app-agent/websocket.js +8 -24
- package/lib/api/client.d.ts +15 -15
- package/lib/api/client.js +26 -53
- package/lib/api/common.d.ts +1 -9
- package/lib/api/common.js +6 -22
- package/lib/api/index.d.ts +2 -2
- package/lib/api/index.js +2 -2
- package/lib/api/zome-call-signing.d.ts +8 -7
- package/lib/api/zome-call-signing.js +13 -15
- package/lib/environments/launcher.d.ts +3 -25
- package/lib/environments/launcher.js +4 -34
- package/lib/hdk/action.d.ts +3 -13
- package/lib/hdk/capabilities.d.ts +4 -14
- package/lib/hdk/capabilities.js +0 -9
- package/lib/hdk/index.d.ts +0 -1
- package/lib/hdk/index.js +0 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/types.d.ts +1 -10
- package/lib/utils/fake-hash.d.ts +4 -8
- package/lib/utils/fake-hash.js +12 -25
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/package.json +1 -1
- package/lib/hdk/link.d.ts +0 -48
- package/lib/hdk/link.js +0 -1
- package/lib/utils/hash-parts.d.ts +0 -71
- package/lib/utils/hash-parts.js +0 -94
package/lib/api/client.js
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
import { decode, encode } from "@msgpack/msgpack";
|
|
2
2
|
import Emittery from "emittery";
|
|
3
|
-
import
|
|
3
|
+
import Websocket 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
|
-
* Uses Holochain's WireMessage for communication.
|
|
9
|
+
* Uses Holochain's websocket WireMessage for communication.
|
|
10
10
|
*
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
13
|
export class WsClient extends Emittery {
|
|
14
14
|
socket;
|
|
15
|
-
url;
|
|
16
15
|
pendingRequests;
|
|
17
16
|
index;
|
|
18
|
-
constructor(socket
|
|
17
|
+
constructor(socket) {
|
|
19
18
|
super();
|
|
20
19
|
this.socket = socket;
|
|
21
|
-
this.url = url;
|
|
22
20
|
this.pendingRequests = {};
|
|
23
21
|
this.index = 0;
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
setupSocket() {
|
|
27
|
-
this.socket.onmessage = async (serializedMessage) => {
|
|
22
|
+
socket.onmessage = async (serializedMessage) => {
|
|
28
23
|
// If data is not a buffer (nodejs), it will be a blob (browser)
|
|
29
24
|
let deserializedData;
|
|
30
|
-
if (
|
|
31
|
-
serializedMessage.data instanceof
|
|
25
|
+
if (typeof window === "object" &&
|
|
26
|
+
serializedMessage.data instanceof window.Blob) {
|
|
32
27
|
deserializedData = await serializedMessage.data.arrayBuffer();
|
|
33
28
|
}
|
|
34
29
|
else {
|
|
@@ -69,7 +64,7 @@ export class WsClient extends Emittery {
|
|
|
69
64
|
console.error(`Got unrecognized Websocket message type: ${message.type}`);
|
|
70
65
|
}
|
|
71
66
|
};
|
|
72
|
-
|
|
67
|
+
socket.onclose = (event) => {
|
|
73
68
|
const pendingRequestIds = Object.keys(this.pendingRequests).map((id) => parseInt(id));
|
|
74
69
|
if (pendingRequestIds.length) {
|
|
75
70
|
pendingRequestIds.forEach((id) => {
|
|
@@ -83,17 +78,20 @@ export class WsClient extends Emittery {
|
|
|
83
78
|
/**
|
|
84
79
|
* Instance factory for creating WsClients.
|
|
85
80
|
*
|
|
86
|
-
* @param url - The
|
|
81
|
+
* @param url - The `ws://` URL to connect to.
|
|
87
82
|
* @returns An new instance of the WsClient.
|
|
88
83
|
*/
|
|
89
84
|
static connect(url) {
|
|
90
85
|
return new Promise((resolve, reject) => {
|
|
91
|
-
const socket = new
|
|
86
|
+
const socket = new Websocket(url);
|
|
87
|
+
// make sure that there are no uncaught connection
|
|
88
|
+
// errors because that causes nodejs thread to crash
|
|
89
|
+
// with uncaught exception
|
|
92
90
|
socket.onerror = () => {
|
|
93
91
|
reject(new Error(`could not connect to holochain conductor, please check that a conductor service is running and available at ${url}`));
|
|
94
92
|
};
|
|
95
93
|
socket.onopen = () => {
|
|
96
|
-
const client = new WsClient(socket
|
|
94
|
+
const client = new WsClient(socket);
|
|
97
95
|
resolve(client);
|
|
98
96
|
};
|
|
99
97
|
});
|
|
@@ -116,43 +114,25 @@ export class WsClient extends Emittery {
|
|
|
116
114
|
* @param request - The request to send over the websocket.
|
|
117
115
|
* @returns
|
|
118
116
|
*/
|
|
119
|
-
|
|
117
|
+
request(request) {
|
|
120
118
|
if (this.socket.readyState === this.socket.OPEN) {
|
|
119
|
+
const id = this.index;
|
|
120
|
+
const encodedMsg = encode({
|
|
121
|
+
id,
|
|
122
|
+
type: "request",
|
|
123
|
+
data: encode(request),
|
|
124
|
+
});
|
|
121
125
|
const promise = new Promise((resolve, reject) => {
|
|
122
|
-
this.
|
|
126
|
+
this.pendingRequests[id] = { resolve, reject };
|
|
123
127
|
});
|
|
128
|
+
this.socket.send(encodedMsg);
|
|
129
|
+
this.index += 1;
|
|
124
130
|
return promise;
|
|
125
131
|
}
|
|
126
|
-
else if (this.url) {
|
|
127
|
-
const response = new Promise((resolve, reject) => {
|
|
128
|
-
// typescript forgets in this promise scope that this.url is not undefined
|
|
129
|
-
const socket = new IsoWebSocket(this.url);
|
|
130
|
-
this.socket = socket;
|
|
131
|
-
socket.onerror = () => {
|
|
132
|
-
reject(new Error(`could not connect to Holochain conductor, please check that a conductor service is running and available at ${this.url}`));
|
|
133
|
-
};
|
|
134
|
-
socket.onopen = () => {
|
|
135
|
-
this.sendMessage(request, resolve, reject);
|
|
136
|
-
};
|
|
137
|
-
this.setupSocket();
|
|
138
|
-
});
|
|
139
|
-
return response;
|
|
140
|
-
}
|
|
141
132
|
else {
|
|
142
133
|
return Promise.reject(new Error("Socket is not open"));
|
|
143
134
|
}
|
|
144
135
|
}
|
|
145
|
-
sendMessage(request, resolve, reject) {
|
|
146
|
-
const id = this.index;
|
|
147
|
-
const encodedMsg = encode({
|
|
148
|
-
id,
|
|
149
|
-
type: "request",
|
|
150
|
-
data: encode(request),
|
|
151
|
-
});
|
|
152
|
-
this.socket.send(encodedMsg);
|
|
153
|
-
this.pendingRequests[id] = { resolve, reject };
|
|
154
|
-
this.index += 1;
|
|
155
|
-
}
|
|
156
136
|
handleResponse(msg) {
|
|
157
137
|
const id = msg.id;
|
|
158
138
|
if (this.pendingRequests[id]) {
|
|
@@ -171,14 +151,8 @@ export class WsClient extends Emittery {
|
|
|
171
151
|
/**
|
|
172
152
|
* Close the websocket connection.
|
|
173
153
|
*/
|
|
174
|
-
close(code
|
|
175
|
-
const closedPromise = new Promise((resolve) =>
|
|
176
|
-
// for an unknown reason "addEventListener" is seen as a non-callable
|
|
177
|
-
// property and gives a ts2349 error
|
|
178
|
-
// type assertion as workaround
|
|
179
|
-
this.socket.addEventListener("close", (event) => resolve(event))
|
|
180
|
-
// }
|
|
181
|
-
);
|
|
154
|
+
close(code) {
|
|
155
|
+
const closedPromise = new Promise((resolve) => this.socket.on("close", resolve));
|
|
182
156
|
this.socket.close(code);
|
|
183
157
|
return closedPromise;
|
|
184
158
|
}
|
|
@@ -200,4 +174,3 @@ function assertHolochainSignal(signal) {
|
|
|
200
174
|
}
|
|
201
175
|
throw new Error(`unknown signal format ${JSON.stringify(signal, null, 4)}`);
|
|
202
176
|
}
|
|
203
|
-
export { IsoWebSocket };
|
package/lib/api/common.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RoleName } from "../types.js";
|
|
2
|
-
export declare const DEFAULT_TIMEOUT =
|
|
2
|
+
export declare const DEFAULT_TIMEOUT = 15000;
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
@@ -30,14 +30,6 @@ export type Tagged<T> = {
|
|
|
30
30
|
* @public
|
|
31
31
|
*/
|
|
32
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>;
|
|
33
|
-
/**
|
|
34
|
-
* Error thrown when response from Holochain is an error.
|
|
35
|
-
*
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export declare class HolochainError extends Error {
|
|
39
|
-
constructor(name: string, message: string);
|
|
40
|
-
}
|
|
41
33
|
export declare const catchError: (res: any) => Promise<any>;
|
|
42
34
|
export declare const promiseTimeout: (promise: Promise<unknown>, tag: string, ms: number) => Promise<unknown>;
|
|
43
35
|
/**
|
package/lib/api/common.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const ERROR_TYPE = "error";
|
|
2
|
-
export const DEFAULT_TIMEOUT =
|
|
2
|
+
export const DEFAULT_TIMEOUT = 15000;
|
|
3
3
|
/**
|
|
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
|
|
@@ -19,32 +19,16 @@ const identityTransformer = {
|
|
|
19
19
|
input: identity,
|
|
20
20
|
output: identity,
|
|
21
21
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Error thrown when response from Holochain is an error.
|
|
24
|
-
*
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
export class HolochainError extends Error {
|
|
28
|
-
constructor(name, message) {
|
|
29
|
-
super();
|
|
30
|
-
this.name = name;
|
|
31
|
-
this.message = message;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// this determines the error format of all error responses
|
|
35
22
|
export const catchError = (res) => {
|
|
36
|
-
|
|
37
|
-
const error = new HolochainError(res.data.type, res.data.data);
|
|
38
|
-
return Promise.reject(error);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
return Promise.resolve(res);
|
|
42
|
-
}
|
|
23
|
+
return res.type === ERROR_TYPE ? Promise.reject(res) : Promise.resolve(res);
|
|
43
24
|
};
|
|
44
25
|
export const promiseTimeout = (promise, tag, ms) => {
|
|
45
26
|
let id;
|
|
46
27
|
const timeout = new Promise((_, reject) => {
|
|
47
|
-
id = setTimeout(() =>
|
|
28
|
+
id = setTimeout(() => {
|
|
29
|
+
clearTimeout(id);
|
|
30
|
+
reject(new Error(`Timed out in ${ms}ms: ${tag}`));
|
|
31
|
+
}, ms);
|
|
48
32
|
});
|
|
49
33
|
return new Promise((res, rej) => {
|
|
50
34
|
Promise.race([promise, timeout])
|
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 {
|
|
6
|
-
export {
|
|
5
|
+
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 {
|
|
6
|
-
export {
|
|
5
|
+
export { CloneId } from "./common.js";
|
|
6
|
+
export { WsClient } from "./client.js";
|
|
7
7
|
export * from "./zome-call-signing.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import nacl from "tweetnacl";
|
|
2
|
+
import { CapSecret } from "../hdk/capabilities.js";
|
|
3
|
+
import { AgentPubKey, CellId } from "../types.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
6
6
|
*/
|
|
@@ -10,7 +10,7 @@ export type Nonce256Bit = Uint8Array;
|
|
|
10
10
|
*/
|
|
11
11
|
export interface SigningCredentials {
|
|
12
12
|
capSecret: CapSecret;
|
|
13
|
-
keyPair:
|
|
13
|
+
keyPair: nacl.SignKeyPair;
|
|
14
14
|
signingKey: AgentPubKey;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -33,13 +33,14 @@ export declare const setSigningCredentials: (cellId: CellId, credentials: Signin
|
|
|
33
33
|
/**
|
|
34
34
|
* Generates a key pair for signing zome calls.
|
|
35
35
|
*
|
|
36
|
-
* @param agentPubKey - The agent pub key to take 4 last bytes (= DHT location)
|
|
37
|
-
* from (optional).
|
|
38
36
|
* @returns The signing key pair and an agent pub key based on the public key.
|
|
39
37
|
*
|
|
40
38
|
* @public
|
|
41
39
|
*/
|
|
42
|
-
export declare const generateSigningKeyPair: (
|
|
40
|
+
export declare const generateSigningKeyPair: () => [
|
|
41
|
+
nacl.SignKeyPair,
|
|
42
|
+
AgentPubKey
|
|
43
|
+
];
|
|
43
44
|
/**
|
|
44
45
|
* @public
|
|
45
46
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nacl from "tweetnacl";
|
|
2
2
|
import { encodeHashToBase64 } from "../utils/base64.js";
|
|
3
3
|
const signingCredentials = new Map();
|
|
4
4
|
/**
|
|
@@ -27,24 +27,19 @@ export const setSigningCredentials = (cellId, credentials) => {
|
|
|
27
27
|
/**
|
|
28
28
|
* Generates a key pair for signing zome calls.
|
|
29
29
|
*
|
|
30
|
-
* @param agentPubKey - The agent pub key to take 4 last bytes (= DHT location)
|
|
31
|
-
* from (optional).
|
|
32
30
|
* @returns The signing key pair and an agent pub key based on the public key.
|
|
33
31
|
*
|
|
34
32
|
* @public
|
|
35
33
|
*/
|
|
36
|
-
export const generateSigningKeyPair =
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
const keyPair = sodium.crypto_sign_keypair();
|
|
40
|
-
const locationBytes = agentPubKey ? agentPubKey.subarray(35) : [0, 0, 0, 0];
|
|
41
|
-
const signingKey = new Uint8Array([132, 32, 36].concat(...keyPair.publicKey).concat(...locationBytes));
|
|
34
|
+
export const generateSigningKeyPair = () => {
|
|
35
|
+
const keyPair = nacl.sign.keyPair();
|
|
36
|
+
const signingKey = new Uint8Array([132, 32, 36].concat(...keyPair.publicKey).concat(...[0, 0, 0, 0]));
|
|
42
37
|
return [keyPair, signingKey];
|
|
43
38
|
};
|
|
44
39
|
/**
|
|
45
40
|
* @public
|
|
46
41
|
*/
|
|
47
|
-
export const randomCapSecret =
|
|
42
|
+
export const randomCapSecret = () => randomByteArray(64);
|
|
48
43
|
/**
|
|
49
44
|
* @public
|
|
50
45
|
*/
|
|
@@ -53,12 +48,15 @@ export const randomNonce = async () => randomByteArray(32);
|
|
|
53
48
|
* @public
|
|
54
49
|
*/
|
|
55
50
|
export const randomByteArray = async (length) => {
|
|
56
|
-
if (
|
|
57
|
-
|
|
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));
|
|
58
59
|
}
|
|
59
|
-
await _sodium.ready;
|
|
60
|
-
const sodium = _sodium;
|
|
61
|
-
return sodium.randombytes_buf(length);
|
|
62
60
|
};
|
|
63
61
|
/**
|
|
64
62
|
* @public
|
|
@@ -1,45 +1,23 @@
|
|
|
1
|
-
import { CallZomeRequest } from "../api/app/types.js";
|
|
2
|
-
import { CallZomeRequestSigned, CallZomeRequestUnsigned } from "../api/app/websocket.js";
|
|
3
1
|
import { InstalledAppId } from "../types.js";
|
|
2
|
+
import { CallZomeRequest, CallZomeRequestSigned } from "../api/index.js";
|
|
4
3
|
export interface LauncherEnvironment {
|
|
5
4
|
APP_INTERFACE_PORT?: number;
|
|
6
5
|
ADMIN_INTERFACE_PORT?: number;
|
|
7
6
|
INSTALLED_APP_ID?: InstalledAppId;
|
|
8
|
-
FRAMEWORK?: "tauri" | "electron";
|
|
9
7
|
}
|
|
10
8
|
export interface HostZomeCallSigner {
|
|
11
9
|
signZomeCall: (request: CallZomeRequest) => Promise<CallZomeRequestSigned>;
|
|
12
10
|
}
|
|
13
11
|
declare const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__";
|
|
14
12
|
declare const __HC_ZOME_CALL_SIGNER__ = "__HC_ZOME_CALL_SIGNER__";
|
|
15
|
-
export declare const isLauncher:
|
|
13
|
+
export declare const isLauncher: boolean;
|
|
16
14
|
export declare const getLauncherEnvironment: () => LauncherEnvironment | undefined;
|
|
17
15
|
export declare const getHostZomeCallSigner: () => HostZomeCallSigner | undefined;
|
|
18
16
|
declare global {
|
|
19
17
|
interface Window {
|
|
20
|
-
[__HC_LAUNCHER_ENV__]
|
|
18
|
+
[__HC_LAUNCHER_ENV__]: LauncherEnvironment | undefined;
|
|
21
19
|
[__HC_ZOME_CALL_SIGNER__]?: HostZomeCallSigner;
|
|
22
|
-
electronAPI?: {
|
|
23
|
-
signZomeCall: (data: CallZomeRequestUnsignedElectron) => CallZomeRequestSignedElectron;
|
|
24
|
-
};
|
|
25
20
|
}
|
|
26
21
|
}
|
|
27
|
-
interface CallZomeRequestSignedElectron extends Omit<CallZomeRequestSigned, "cap_secret" | "cell_id" | "provenance" | "nonce" | "zome_name" | "fn_name" | "expires_at"> {
|
|
28
|
-
cellId: [Array<number>, Array<number>];
|
|
29
|
-
provenance: Array<number>;
|
|
30
|
-
zomeName: string;
|
|
31
|
-
fnName: string;
|
|
32
|
-
nonce: Array<number>;
|
|
33
|
-
expiresAt: number;
|
|
34
|
-
}
|
|
35
|
-
interface CallZomeRequestUnsignedElectron extends Omit<CallZomeRequestUnsigned, "cap_secret" | "cell_id" | "provenance" | "nonce" | "zome_name" | "fn_name" | "expires_at"> {
|
|
36
|
-
cellId: [Array<number>, Array<number>];
|
|
37
|
-
provenance: Array<number>;
|
|
38
|
-
zomeName: string;
|
|
39
|
-
fnName: string;
|
|
40
|
-
nonce: Array<number>;
|
|
41
|
-
expiresAt: number;
|
|
42
|
-
}
|
|
43
22
|
export declare const signZomeCallTauri: (request: CallZomeRequest) => Promise<CallZomeRequestSigned>;
|
|
44
|
-
export declare const signZomeCallElectron: (request: CallZomeRequest) => Promise<CallZomeRequestSigned>;
|
|
45
23
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { encode } from "@msgpack/msgpack";
|
|
2
1
|
import { invoke } from "@tauri-apps/api/tauri";
|
|
3
|
-
import { getNonceExpiration, randomNonce } from "../api/
|
|
2
|
+
import { getNonceExpiration, randomNonce, } from "../api/index.js";
|
|
3
|
+
import { encode } from "@msgpack/msgpack";
|
|
4
4
|
const __HC_LAUNCHER_ENV__ = "__HC_LAUNCHER_ENV__";
|
|
5
5
|
const __HC_ZOME_CALL_SIGNER__ = "__HC_ZOME_CALL_SIGNER__";
|
|
6
|
-
export const isLauncher =
|
|
7
|
-
export const getLauncherEnvironment = () => isLauncher
|
|
6
|
+
export const isLauncher = typeof window === "object" && __HC_LAUNCHER_ENV__ in window;
|
|
7
|
+
export const getLauncherEnvironment = () => isLauncher ? window[__HC_LAUNCHER_ENV__] : undefined;
|
|
8
8
|
export const getHostZomeCallSigner = () => globalThis.window && globalThis.window[__HC_ZOME_CALL_SIGNER__];
|
|
9
9
|
export const signZomeCallTauri = async (request) => {
|
|
10
10
|
const zomeCallUnsigned = {
|
|
@@ -33,33 +33,3 @@ export const signZomeCallTauri = async (request) => {
|
|
|
33
33
|
};
|
|
34
34
|
return signedZomeCall;
|
|
35
35
|
};
|
|
36
|
-
export const signZomeCallElectron = async (request) => {
|
|
37
|
-
if (!window.electronAPI) {
|
|
38
|
-
throw Error("Unable to signZomeCallElectron. window.electronAPI not defined");
|
|
39
|
-
}
|
|
40
|
-
const zomeCallUnsignedElectron = {
|
|
41
|
-
provenance: Array.from(request.provenance),
|
|
42
|
-
cellId: [Array.from(request.cell_id[0]), Array.from(request.cell_id[1])],
|
|
43
|
-
zomeName: request.zome_name,
|
|
44
|
-
fnName: request.fn_name,
|
|
45
|
-
payload: Array.from(encode(request.payload)),
|
|
46
|
-
nonce: Array.from(await randomNonce()),
|
|
47
|
-
expiresAt: getNonceExpiration(),
|
|
48
|
-
};
|
|
49
|
-
const zomeCallSignedElectron = await window.electronAPI.signZomeCall(zomeCallUnsignedElectron);
|
|
50
|
-
const zomeCallSigned = {
|
|
51
|
-
provenance: Uint8Array.from(zomeCallSignedElectron.provenance),
|
|
52
|
-
cap_secret: null,
|
|
53
|
-
cell_id: [
|
|
54
|
-
Uint8Array.from(zomeCallSignedElectron.cellId[0]),
|
|
55
|
-
Uint8Array.from(zomeCallSignedElectron.cellId[1]),
|
|
56
|
-
],
|
|
57
|
-
zome_name: zomeCallSignedElectron.zomeName,
|
|
58
|
-
fn_name: zomeCallSignedElectron.fnName,
|
|
59
|
-
payload: Uint8Array.from(zomeCallSignedElectron.payload),
|
|
60
|
-
signature: Uint8Array.from(zomeCallSignedElectron.signature),
|
|
61
|
-
expires_at: zomeCallSignedElectron.expiresAt,
|
|
62
|
-
nonce: Uint8Array.from(zomeCallSignedElectron.nonce),
|
|
63
|
-
};
|
|
64
|
-
return zomeCallSigned;
|
|
65
|
-
};
|
package/lib/hdk/action.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AgentPubKey, DnaHash, EntryHash, ActionHash, HoloHashed, Signature, Timestamp } from "../types.js";
|
|
2
|
-
import {
|
|
3
|
-
import { LinkTag, LinkType, RateWeight } from "./link.js";
|
|
2
|
+
import { EntryType } from "./entry.js";
|
|
4
3
|
/**
|
|
5
4
|
* @public
|
|
6
5
|
*/
|
|
@@ -8,13 +7,6 @@ export interface SignedActionHashed<H extends Action = Action> {
|
|
|
8
7
|
hashed: HoloHashed<H>;
|
|
9
8
|
signature: Signature;
|
|
10
9
|
}
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
export interface RegisterAgentActivity {
|
|
15
|
-
action: SignedActionHashed;
|
|
16
|
-
cached_entry?: Entry;
|
|
17
|
-
}
|
|
18
10
|
/**
|
|
19
11
|
* @public
|
|
20
12
|
*/
|
|
@@ -83,10 +75,8 @@ export interface CreateLink {
|
|
|
83
75
|
prev_action: ActionHash;
|
|
84
76
|
base_address: EntryHash;
|
|
85
77
|
target_address: EntryHash;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
tag: LinkTag;
|
|
89
|
-
weight: RateWeight;
|
|
78
|
+
zome_id: number;
|
|
79
|
+
tag: any;
|
|
90
80
|
}
|
|
91
81
|
/**
|
|
92
82
|
* @public
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FunctionName, ZomeName } from "../api/
|
|
1
|
+
import { FunctionName, ZomeName } from "../api/index.js";
|
|
2
2
|
import { AgentPubKey } from "../types.js";
|
|
3
3
|
/**
|
|
4
4
|
* @public
|
|
@@ -38,22 +38,12 @@ export interface ZomeCallCapGrant {
|
|
|
38
38
|
/**
|
|
39
39
|
* @public
|
|
40
40
|
*/
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
Transferable = "Transferable",
|
|
44
|
-
Assigned = "Assigned"
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @public
|
|
48
|
-
*/
|
|
49
|
-
export type CapAccess = {
|
|
50
|
-
[CapAccessType.Unrestricted]: null;
|
|
51
|
-
} | {
|
|
52
|
-
[CapAccessType.Transferable]: {
|
|
41
|
+
export type CapAccess = "Unrestricted" | {
|
|
42
|
+
Transferable: {
|
|
53
43
|
secret: CapSecret;
|
|
54
44
|
};
|
|
55
45
|
} | {
|
|
56
|
-
|
|
46
|
+
Assigned: {
|
|
57
47
|
secret: CapSecret;
|
|
58
48
|
assignees: AgentPubKey[];
|
|
59
49
|
};
|
package/lib/hdk/capabilities.js
CHANGED
|
@@ -6,12 +6,3 @@ export var GrantedFunctionsType;
|
|
|
6
6
|
GrantedFunctionsType["All"] = "All";
|
|
7
7
|
GrantedFunctionsType["Listed"] = "Listed";
|
|
8
8
|
})(GrantedFunctionsType || (GrantedFunctionsType = {}));
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export var CapAccessType;
|
|
13
|
-
(function (CapAccessType) {
|
|
14
|
-
CapAccessType["Unrestricted"] = "Unrestricted";
|
|
15
|
-
CapAccessType["Transferable"] = "Transferable";
|
|
16
|
-
CapAccessType["Assigned"] = "Assigned";
|
|
17
|
-
})(CapAccessType || (CapAccessType = {}));
|
package/lib/hdk/index.d.ts
CHANGED
package/lib/hdk/index.js
CHANGED
package/lib/tsdoc-metadata.json
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -26,10 +26,6 @@ export type ActionHash = HoloHash;
|
|
|
26
26
|
* @public
|
|
27
27
|
*/
|
|
28
28
|
export type AnyDhtHash = HoloHash;
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export type ExternalHash = HoloHash;
|
|
33
29
|
/**
|
|
34
30
|
* @public
|
|
35
31
|
*/
|
|
@@ -82,7 +78,7 @@ export type CellId = [DnaHash, AgentPubKey];
|
|
|
82
78
|
/**
|
|
83
79
|
* @public
|
|
84
80
|
*/
|
|
85
|
-
export type DnaProperties =
|
|
81
|
+
export type DnaProperties = any;
|
|
86
82
|
/**
|
|
87
83
|
* @public
|
|
88
84
|
*/
|
|
@@ -117,11 +113,6 @@ export interface HoloHashed<T> {
|
|
|
117
113
|
*/
|
|
118
114
|
export interface NetworkInfo {
|
|
119
115
|
fetch_pool_info: FetchPoolInfo;
|
|
120
|
-
current_number_of_peers: number;
|
|
121
|
-
arc_size: number;
|
|
122
|
-
total_network_peers: number;
|
|
123
|
-
bytes_since_last_time_queried: number;
|
|
124
|
-
completed_rounds_since_last_time_queried: number;
|
|
125
116
|
}
|
|
126
117
|
/**
|
|
127
118
|
* @public
|
package/lib/utils/fake-hash.d.ts
CHANGED
|
@@ -4,36 +4,32 @@ import { DnaHash, ActionHash, AgentPubKey, EntryHash } from "../types.js";
|
|
|
4
4
|
*
|
|
5
5
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
6
|
*
|
|
7
|
-
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
8
7
|
* @returns An {@link EntryHash}.
|
|
9
8
|
*
|
|
10
9
|
* @public
|
|
11
10
|
*/
|
|
12
|
-
export declare function fakeEntryHash(
|
|
11
|
+
export declare function fakeEntryHash(): Promise<EntryHash>;
|
|
13
12
|
/**
|
|
14
13
|
* Generate a valid agent key of a non-existing agent.
|
|
15
14
|
*
|
|
16
|
-
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
17
15
|
* @returns An {@link AgentPubKey}.
|
|
18
16
|
*
|
|
19
17
|
* @public
|
|
20
18
|
*/
|
|
21
|
-
export declare function fakeAgentPubKey(
|
|
19
|
+
export declare function fakeAgentPubKey(): Promise<AgentPubKey>;
|
|
22
20
|
/**
|
|
23
21
|
* Generate a valid hash of a non-existing action.
|
|
24
22
|
*
|
|
25
|
-
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
26
23
|
* @returns An {@link ActionHash}.
|
|
27
24
|
*
|
|
28
25
|
* @public
|
|
29
26
|
*/
|
|
30
|
-
export declare function fakeActionHash(
|
|
27
|
+
export declare function fakeActionHash(): Promise<ActionHash>;
|
|
31
28
|
/**
|
|
32
29
|
* Generate a valid hash of a non-existing DNA.
|
|
33
30
|
*
|
|
34
|
-
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
35
31
|
* @returns A {@link DnaHash}.
|
|
36
32
|
*
|
|
37
33
|
* @public
|
|
38
34
|
*/
|
|
39
|
-
export declare function fakeDnaHash(
|
|
35
|
+
export declare function fakeDnaHash(): Promise<DnaHash>;
|