@holochain/client 0.18.0-dev.5 → 0.18.0-dev.9
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 +31 -2
- package/lib/api/admin/websocket.d.ts +2 -1
- package/lib/api/admin/websocket.js +3 -0
- package/lib/api/app/types.d.ts +8 -0
- package/lib/api/app/websocket.d.ts +6 -0
- package/lib/api/app/websocket.js +9 -0
- package/lib/api/zome-call-signing.d.ts +6 -4
- package/lib/api/zome-call-signing.js +3 -5
- package/lib/hdk/link.d.ts +1 -5
- package/lib/types.d.ts +2 -29
- package/lib/types.js +5 -1
- package/lib/utils/base64.d.ts +4 -3
- package/lib/utils/base64.js +3 -3
- package/lib/utils/fake-hash.d.ts +4 -4
- package/lib/utils/fake-hash.js +17 -20
- package/lib/utils/hash-parts.d.ts +5 -5
- package/lib/utils/hash-parts.js +11 -8
- package/package.json +2 -1
package/lib/api/admin/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Action, DhtOp, Entry, ZomeCallCapGrant } from "../../hdk/index.js";
|
|
2
|
-
import { ActionHash, AgentPubKey, CellId, DnaHash, DnaProperties, Duration, HoloHash, HoloHashB64, InstalledAppId, KitsuneAgent, KitsuneSpace, RoleName, Signature, Timestamp, WasmHash } from "../../types.js";
|
|
2
|
+
import { ActionHash, AgentPubKey, CellId, DnaHash, DnaHashB64, DnaProperties, Duration, HoloHash, HoloHashB64, InstalledAppId, KitsuneAgent, KitsuneSpace, RoleName, Signature, Timestamp, WasmHash } from "../../types.js";
|
|
3
3
|
import { Requester } from "../common.js";
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
@@ -52,7 +52,7 @@ export type PausedAppReason = {
|
|
|
52
52
|
/**
|
|
53
53
|
* @public
|
|
54
54
|
*/
|
|
55
|
-
export type DisabledAppReason = "never_started" | "user" | {
|
|
55
|
+
export type DisabledAppReason = "never_started" | "user" | "not_started_after_providing_memproofs" | {
|
|
56
56
|
error: string;
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
@@ -234,6 +234,7 @@ export type CoordinatorZome = ZomeDefinition;
|
|
|
234
234
|
export type DnaDefinition = {
|
|
235
235
|
name: string;
|
|
236
236
|
modifiers: DnaModifiers;
|
|
237
|
+
lineage: DnaHashB64[];
|
|
237
238
|
integrity_zomes: IntegrityZome[];
|
|
238
239
|
coordinator_zomes: CoordinatorZome[];
|
|
239
240
|
};
|
|
@@ -245,6 +246,14 @@ export type GetDnaDefinitionRequest = DnaHash;
|
|
|
245
246
|
* @public
|
|
246
247
|
*/
|
|
247
248
|
export type GetDnaDefinitionResponse = DnaDefinition;
|
|
249
|
+
/**
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
export type GetCompatibleCellsRequest = DnaHashB64;
|
|
253
|
+
/**
|
|
254
|
+
* @public
|
|
255
|
+
*/
|
|
256
|
+
export type GetCompatibleCellsResponse = Set<[InstalledAppId, Set<CellId>]>;
|
|
248
257
|
/**
|
|
249
258
|
* @public
|
|
250
259
|
*/
|
|
@@ -610,6 +619,26 @@ export type DnaManifest = {
|
|
|
610
619
|
* The order is significant: it determines initialization order.
|
|
611
620
|
*/
|
|
612
621
|
zomes: Array<ZomeManifest>;
|
|
622
|
+
/**
|
|
623
|
+
* A list of past "ancestors" of this DNA.
|
|
624
|
+
*
|
|
625
|
+
* Whenever a DNA is created which is intended to be used as a migration from
|
|
626
|
+
* a previous DNA, the lineage should be updated to include the hash of the
|
|
627
|
+
* DNA being migrated from. DNA hashes may also be removed from this list if
|
|
628
|
+
* it is desired to remove them from the lineage.
|
|
629
|
+
*
|
|
630
|
+
* The meaning of the "ancestor" relationship is as follows:
|
|
631
|
+
* - For any DNA, there is a migration path from any of its ancestors to itself.
|
|
632
|
+
* - When an app depends on a DnaHash via UseExisting, it means that any installed
|
|
633
|
+
* DNA in the lineage which contains that DnaHash can be used.
|
|
634
|
+
* - The app's Coordinator interface is expected to be compatible across the lineage.
|
|
635
|
+
* (Though this cannot be enforced, since Coordinators can be swapped out at
|
|
636
|
+
* will by the user, the intention is still there.)
|
|
637
|
+
*
|
|
638
|
+
* Holochain does nothing to ensure the correctness of the lineage, it is up to
|
|
639
|
+
* the app developer to make the necessary guarantees.
|
|
640
|
+
*/
|
|
641
|
+
lineage: DnaHashB64[];
|
|
613
642
|
};
|
|
614
643
|
/**
|
|
615
644
|
* @public
|
|
@@ -2,7 +2,7 @@ import { CapSecret, GrantedFunctions } from "../../hdk/index.js";
|
|
|
2
2
|
import type { AgentPubKey, CellId } from "../../types.js";
|
|
3
3
|
import { WsClient } from "../client.js";
|
|
4
4
|
import { Requester, Transformer, WebsocketConnectionOptions } from "../common.js";
|
|
5
|
-
import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpNetworkStatsRequest, DumpNetworkStatsResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, IssueAppAuthenticationTokenRequest, IssueAppAuthenticationTokenResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, StorageInfoRequest, StorageInfoResponse, UninstallAppRequest, UninstallAppResponse, UpdateCoordinatorsRequest, UpdateCoordinatorsResponse } from "./types.js";
|
|
5
|
+
import { AddAgentInfoRequest, AddAgentInfoResponse, AdminApi, AgentInfoRequest, AgentInfoResponse, AttachAppInterfaceRequest, AttachAppInterfaceResponse, DeleteCloneCellRequest, DeleteCloneCellResponse, DisableAppRequest, DisableAppResponse, DumpFullStateRequest, DumpFullStateResponse, DumpNetworkStatsRequest, DumpNetworkStatsResponse, DumpStateRequest, DumpStateResponse, EnableAppRequest, EnableAppResponse, GenerateAgentPubKeyRequest, GenerateAgentPubKeyResponse, GetCompatibleCellsRequest, GetCompatibleCellsResponse, GetDnaDefinitionRequest, GetDnaDefinitionResponse, GrantZomeCallCapabilityRequest, GrantZomeCallCapabilityResponse, InstallAppRequest, InstallAppResponse, IssueAppAuthenticationTokenRequest, IssueAppAuthenticationTokenResponse, ListAppInterfacesRequest, ListAppInterfacesResponse, ListAppsRequest, ListAppsResponse, ListCellIdsRequest, ListCellIdsResponse, ListDnasRequest, ListDnasResponse, RegisterDnaRequest, RegisterDnaResponse, StorageInfoRequest, StorageInfoResponse, UninstallAppRequest, UninstallAppResponse, UpdateCoordinatorsRequest, UpdateCoordinatorsResponse } from "./types.js";
|
|
6
6
|
/**
|
|
7
7
|
* A class for interacting with a conductor's Admin API.
|
|
8
8
|
*
|
|
@@ -61,6 +61,7 @@ export declare class AdminWebsocket implements AdminApi {
|
|
|
61
61
|
* Get the DNA definition for the specified DNA hash.
|
|
62
62
|
*/
|
|
63
63
|
getDnaDefinition: Requester<GetDnaDefinitionRequest, GetDnaDefinitionResponse>;
|
|
64
|
+
getCompatibleCells: Requester<GetCompatibleCellsRequest, GetCompatibleCellsResponse>;
|
|
64
65
|
/**
|
|
65
66
|
* Uninstall the specified app from Holochain.
|
|
66
67
|
*/
|
|
@@ -78,6 +78,9 @@ export class AdminWebsocket {
|
|
|
78
78
|
* Get the DNA definition for the specified DNA hash.
|
|
79
79
|
*/
|
|
80
80
|
getDnaDefinition = this._requester("get_dna_definition");
|
|
81
|
+
/// Find installed cells which use a DNA that's forward-compatible with the given DNA hash.
|
|
82
|
+
/// Namely, this finds cells with DNAs whose manifest lists the given DNA hash in its `lineage` field.
|
|
83
|
+
getCompatibleCells = this._requester("get_compatible_cells");
|
|
81
84
|
/**
|
|
82
85
|
* Uninstall the specified app from Holochain.
|
|
83
86
|
*/
|
package/lib/api/app/types.d.ts
CHANGED
|
@@ -90,6 +90,14 @@ export type ProvideMemproofsRequest = MemproofMap;
|
|
|
90
90
|
* @public
|
|
91
91
|
*/
|
|
92
92
|
export type ProvideMemproofsResponse = void;
|
|
93
|
+
/**
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export type EnableRequest = void;
|
|
97
|
+
/**
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export type EnableResponse = void;
|
|
93
101
|
/**
|
|
94
102
|
* @public
|
|
95
103
|
*/
|
|
@@ -20,6 +20,7 @@ export declare class AppWebsocket implements AppClient {
|
|
|
20
20
|
private readonly appInfoRequester;
|
|
21
21
|
private readonly callZomeRequester;
|
|
22
22
|
private readonly provideMemproofRequester;
|
|
23
|
+
private readonly enableAppRequester;
|
|
23
24
|
private readonly createCloneCellRequester;
|
|
24
25
|
private readonly enableCloneCellRequester;
|
|
25
26
|
private readonly disableCloneCellRequester;
|
|
@@ -46,6 +47,11 @@ export declare class AppWebsocket implements AppClient {
|
|
|
46
47
|
* @param memproofs - A map of {@link MembraneProof}s.
|
|
47
48
|
*/
|
|
48
49
|
provideMemproofs(memproofs: MemproofMap): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Enablie an app only if the app is in the `AppStatus::Disabled(DisabledAppReason::NotStartedAfterProvidingMemproofs)`
|
|
52
|
+
* state. Attempting to enable the app from other states (other than Running) will fail.
|
|
53
|
+
*/
|
|
54
|
+
enableApp(): Promise<void>;
|
|
49
55
|
/**
|
|
50
56
|
* Get a cell id by its role name or clone id.
|
|
51
57
|
*
|
package/lib/api/app/websocket.js
CHANGED
|
@@ -26,6 +26,7 @@ export class AppWebsocket {
|
|
|
26
26
|
appInfoRequester;
|
|
27
27
|
callZomeRequester;
|
|
28
28
|
provideMemproofRequester;
|
|
29
|
+
enableAppRequester;
|
|
29
30
|
createCloneCellRequester;
|
|
30
31
|
enableCloneCellRequester;
|
|
31
32
|
disableCloneCellRequester;
|
|
@@ -41,6 +42,7 @@ export class AppWebsocket {
|
|
|
41
42
|
this.appInfoRequester = AppWebsocket.requester(this.client, "app_info", this.defaultTimeout);
|
|
42
43
|
this.callZomeRequester = AppWebsocket.requester(this.client, "call_zome", this.defaultTimeout, this.callZomeTransform);
|
|
43
44
|
this.provideMemproofRequester = AppWebsocket.requester(this.client, "provide_memproofs", this.defaultTimeout);
|
|
45
|
+
this.enableAppRequester = AppWebsocket.requester(this.client, "enable_app", this.defaultTimeout);
|
|
44
46
|
this.createCloneCellRequester = AppWebsocket.requester(this.client, "create_clone_cell", this.defaultTimeout);
|
|
45
47
|
this.enableCloneCellRequester = AppWebsocket.requester(this.client, "enable_clone_cell", this.defaultTimeout);
|
|
46
48
|
this.disableCloneCellRequester = AppWebsocket.requester(this.client, "disable_clone_cell", this.defaultTimeout);
|
|
@@ -115,6 +117,13 @@ export class AppWebsocket {
|
|
|
115
117
|
async provideMemproofs(memproofs) {
|
|
116
118
|
await this.provideMemproofRequester(memproofs);
|
|
117
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Enablie an app only if the app is in the `AppStatus::Disabled(DisabledAppReason::NotStartedAfterProvidingMemproofs)`
|
|
122
|
+
* state. Attempting to enable the app from other states (other than Running) will fail.
|
|
123
|
+
*/
|
|
124
|
+
async enableApp() {
|
|
125
|
+
await this.enableAppRequester();
|
|
126
|
+
}
|
|
118
127
|
/**
|
|
119
128
|
* Get a cell id by its role name or clone id.
|
|
120
129
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type KeyPair } from "libsodium-wrappers";
|
|
2
2
|
import type { CapSecret } from "../hdk/capabilities.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { CellId } from "../types.js";
|
|
4
|
+
import { AgentPubKey } from "../types.js";
|
|
4
5
|
/**
|
|
5
6
|
* @public
|
|
6
7
|
*/
|
|
@@ -33,13 +34,14 @@ export declare const setSigningCredentials: (cellId: CellId, credentials: Signin
|
|
|
33
34
|
/**
|
|
34
35
|
* Generates a key pair for signing zome calls.
|
|
35
36
|
*
|
|
36
|
-
* @param agentPubKey - The agent pub key to take 4 last bytes (= DHT location)
|
|
37
|
-
* from (optional).
|
|
38
37
|
* @returns The signing key pair and an agent pub key based on the public key.
|
|
39
38
|
*
|
|
40
39
|
* @public
|
|
41
40
|
*/
|
|
42
|
-
export declare const generateSigningKeyPair: (
|
|
41
|
+
export declare const generateSigningKeyPair: () => Promise<[
|
|
42
|
+
KeyPair,
|
|
43
|
+
AgentPubKey
|
|
44
|
+
]>;
|
|
43
45
|
/**
|
|
44
46
|
* @public
|
|
45
47
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _sodium from "libsodium-wrappers";
|
|
2
|
+
import { AgentPubKey } from "../types.js";
|
|
2
3
|
import { encodeHashToBase64 } from "../utils/base64.js";
|
|
3
4
|
const signingCredentials = new Map();
|
|
4
5
|
/**
|
|
@@ -27,18 +28,15 @@ export const setSigningCredentials = (cellId, credentials) => {
|
|
|
27
28
|
/**
|
|
28
29
|
* Generates a key pair for signing zome calls.
|
|
29
30
|
*
|
|
30
|
-
* @param agentPubKey - The agent pub key to take 4 last bytes (= DHT location)
|
|
31
|
-
* from (optional).
|
|
32
31
|
* @returns The signing key pair and an agent pub key based on the public key.
|
|
33
32
|
*
|
|
34
33
|
* @public
|
|
35
34
|
*/
|
|
36
|
-
export const generateSigningKeyPair = async (
|
|
35
|
+
export const generateSigningKeyPair = async () => {
|
|
37
36
|
await _sodium.ready;
|
|
38
37
|
const sodium = _sodium;
|
|
39
38
|
const keyPair = sodium.crypto_sign_keypair();
|
|
40
|
-
const
|
|
41
|
-
const signingKey = new Uint8Array([132, 32, 36].concat(...keyPair.publicKey).concat(...locationBytes));
|
|
39
|
+
const signingKey = new AgentPubKey(keyPair.publicKey);
|
|
42
40
|
return [keyPair, signingKey];
|
|
43
41
|
};
|
|
44
42
|
/**
|
package/lib/hdk/link.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { ActionHash, AgentPubKey,
|
|
2
|
-
/**
|
|
3
|
-
* @public
|
|
4
|
-
*/
|
|
5
|
-
export type AnyLinkableHash = EntryHash | ActionHash | ExternalHash;
|
|
1
|
+
import { ActionHash, AgentPubKey, Timestamp, AnyLinkableHash } from "../types.js";
|
|
6
2
|
/**
|
|
7
3
|
* An internal zome index within the DNA, from 0 to 255.
|
|
8
4
|
*
|
package/lib/types.d.ts
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
|
+
import { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash } from "@spartan-hc/holo-hash";
|
|
1
2
|
/**
|
|
2
3
|
* @public
|
|
3
4
|
*/
|
|
4
|
-
export
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export type AgentPubKey = HoloHash;
|
|
9
|
-
/**
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
export type DnaHash = HoloHash;
|
|
13
|
-
/**
|
|
14
|
-
* @public
|
|
15
|
-
*/
|
|
16
|
-
export type WasmHash = HoloHash;
|
|
17
|
-
/**
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export type EntryHash = HoloHash;
|
|
21
|
-
/**
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export type ActionHash = HoloHash;
|
|
25
|
-
/**
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export type AnyDhtHash = HoloHash;
|
|
29
|
-
/**
|
|
30
|
-
* @public
|
|
31
|
-
*/
|
|
32
|
-
export type ExternalHash = HoloHash;
|
|
5
|
+
export { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash, };
|
|
33
6
|
/**
|
|
34
7
|
* @public
|
|
35
8
|
*/
|
package/lib/types.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash, } from "@spartan-hc/holo-hash";
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash, };
|
package/lib/utils/base64.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HoloHashB64 } from "../types.js";
|
|
2
|
+
import { HoloHash } from "@spartan-hc/holo-hash";
|
|
2
3
|
/**
|
|
3
4
|
* Decodes a Base64 encoded string to a byte array hash.
|
|
4
5
|
*
|
|
@@ -7,7 +8,7 @@ import { HoloHash, HoloHashB64 } from "../types.js";
|
|
|
7
8
|
*
|
|
8
9
|
* @public
|
|
9
10
|
*/
|
|
10
|
-
export declare function decodeHashFromBase64(hash:
|
|
11
|
+
export declare function decodeHashFromBase64(hash: string): HoloHash;
|
|
11
12
|
/**
|
|
12
13
|
* Encode a byte array hash to a Base64 string.
|
|
13
14
|
*
|
|
@@ -16,4 +17,4 @@ export declare function decodeHashFromBase64(hash: HoloHashB64): HoloHash;
|
|
|
16
17
|
*
|
|
17
18
|
* @public
|
|
18
19
|
*/
|
|
19
|
-
export declare function encodeHashToBase64(hash:
|
|
20
|
+
export declare function encodeHashToBase64(hash: Uint8Array): HoloHashB64;
|
package/lib/utils/base64.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HoloHash } from "@spartan-hc/holo-hash";
|
|
2
2
|
/**
|
|
3
3
|
* Decodes a Base64 encoded string to a byte array hash.
|
|
4
4
|
*
|
|
@@ -8,7 +8,7 @@ import { Base64 } from "js-base64";
|
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
10
|
export function decodeHashFromBase64(hash) {
|
|
11
|
-
return
|
|
11
|
+
return new HoloHash(hash);
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Encode a byte array hash to a Base64 string.
|
|
@@ -19,5 +19,5 @@ export function decodeHashFromBase64(hash) {
|
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
21
|
export function encodeHashToBase64(hash) {
|
|
22
|
-
return
|
|
22
|
+
return String(new HoloHash(hash));
|
|
23
23
|
}
|
package/lib/utils/fake-hash.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { DnaHash, ActionHash, AgentPubKey, EntryHash } from "../types.js";
|
|
|
5
5
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
6
|
*
|
|
7
7
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
8
|
-
* @returns An
|
|
8
|
+
* @returns An instance of EntryHash.
|
|
9
9
|
*
|
|
10
10
|
* @public
|
|
11
11
|
*/
|
|
@@ -14,7 +14,7 @@ export declare function fakeEntryHash(coreByte?: number | undefined): Promise<En
|
|
|
14
14
|
* Generate a valid agent key of a non-existing agent.
|
|
15
15
|
*
|
|
16
16
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
17
|
-
* @returns An
|
|
17
|
+
* @returns An instance ofAgentPubKey.
|
|
18
18
|
*
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
@@ -23,7 +23,7 @@ export declare function fakeAgentPubKey(coreByte?: number | undefined): Promise<
|
|
|
23
23
|
* Generate a valid hash of a non-existing action.
|
|
24
24
|
*
|
|
25
25
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
26
|
-
* @returns An
|
|
26
|
+
* @returns An instance of ActionHash.
|
|
27
27
|
*
|
|
28
28
|
* @public
|
|
29
29
|
*/
|
|
@@ -32,7 +32,7 @@ export declare function fakeActionHash(coreByte?: number | undefined): Promise<A
|
|
|
32
32
|
* Generate a valid hash of a non-existing DNA.
|
|
33
33
|
*
|
|
34
34
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
35
|
-
* @returns A
|
|
35
|
+
* @returns A instance of DnaHash.
|
|
36
36
|
*
|
|
37
37
|
* @public
|
|
38
38
|
*/
|
package/lib/utils/fake-hash.js
CHANGED
|
@@ -1,60 +1,57 @@
|
|
|
1
1
|
import { range } from "lodash-es";
|
|
2
2
|
import { randomByteArray } from "../api/zome-call-signing.js";
|
|
3
|
-
import {
|
|
4
|
-
async function fakeValidHash(prefix, coreByte) {
|
|
5
|
-
let core;
|
|
6
|
-
if (coreByte === undefined) {
|
|
7
|
-
core = await randomByteArray(32);
|
|
8
|
-
}
|
|
9
|
-
else {
|
|
10
|
-
core = Uint8Array.from(range(0, 32).map(() => coreByte));
|
|
11
|
-
}
|
|
12
|
-
const checksum = dhtLocationFrom32(core);
|
|
13
|
-
return new Uint8Array([...prefix, ...core, ...Array.from(checksum)]);
|
|
14
|
-
}
|
|
3
|
+
import { DnaHash, ActionHash, AgentPubKey, EntryHash } from "../types.js";
|
|
15
4
|
/**
|
|
16
5
|
* Generate a valid hash of a non-existing entry.
|
|
17
6
|
*
|
|
18
7
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
19
8
|
*
|
|
20
9
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
21
|
-
* @returns An
|
|
10
|
+
* @returns An instance of EntryHash.
|
|
22
11
|
*
|
|
23
12
|
* @public
|
|
24
13
|
*/
|
|
25
14
|
export async function fakeEntryHash(coreByte = undefined) {
|
|
26
|
-
return
|
|
15
|
+
return new EntryHash(coreByte
|
|
16
|
+
? Uint8Array.from(range(0, 32).map(() => coreByte))
|
|
17
|
+
: await randomByteArray(32));
|
|
27
18
|
}
|
|
28
19
|
/**
|
|
29
20
|
* Generate a valid agent key of a non-existing agent.
|
|
30
21
|
*
|
|
31
22
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
32
|
-
* @returns An
|
|
23
|
+
* @returns An instance ofAgentPubKey.
|
|
33
24
|
*
|
|
34
25
|
* @public
|
|
35
26
|
*/
|
|
36
27
|
export async function fakeAgentPubKey(coreByte = undefined) {
|
|
37
|
-
return
|
|
28
|
+
return new AgentPubKey(coreByte
|
|
29
|
+
? Uint8Array.from(range(0, 32).map(() => coreByte))
|
|
30
|
+
: await randomByteArray(32));
|
|
38
31
|
}
|
|
39
32
|
/**
|
|
40
33
|
* Generate a valid hash of a non-existing action.
|
|
41
34
|
*
|
|
42
35
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
43
|
-
* @returns An
|
|
36
|
+
* @returns An instance of ActionHash.
|
|
44
37
|
*
|
|
45
38
|
* @public
|
|
46
39
|
*/
|
|
47
40
|
export async function fakeActionHash(coreByte = undefined) {
|
|
48
|
-
return
|
|
41
|
+
return new ActionHash(coreByte
|
|
42
|
+
? Uint8Array.from(range(0, 32).map(() => coreByte))
|
|
43
|
+
: await randomByteArray(32));
|
|
49
44
|
}
|
|
50
45
|
/**
|
|
51
46
|
* Generate a valid hash of a non-existing DNA.
|
|
52
47
|
*
|
|
53
48
|
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
54
|
-
* @returns A
|
|
49
|
+
* @returns A instance of DnaHash.
|
|
55
50
|
*
|
|
56
51
|
* @public
|
|
57
52
|
*/
|
|
58
53
|
export async function fakeDnaHash(coreByte = undefined) {
|
|
59
|
-
return
|
|
54
|
+
return new DnaHash(coreByte
|
|
55
|
+
? Uint8Array.from(range(0, 32).map(() => coreByte))
|
|
56
|
+
: await randomByteArray(32));
|
|
60
57
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HoloHash } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash).
|
|
4
4
|
*
|
|
@@ -23,7 +23,7 @@ export declare const HASH_TYPE_PREFIX: {
|
|
|
23
23
|
*
|
|
24
24
|
* @public
|
|
25
25
|
*/
|
|
26
|
-
export declare function sliceHashType(hash:
|
|
26
|
+
export declare function sliceHashType(hash: HoloHash | Uint8Array): Uint8Array;
|
|
27
27
|
/**
|
|
28
28
|
* Get core hash from a Holochain hash (32 bytes).
|
|
29
29
|
*
|
|
@@ -34,7 +34,7 @@ export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash
|
|
|
34
34
|
*
|
|
35
35
|
* @public
|
|
36
36
|
*/
|
|
37
|
-
export declare function sliceCore32(hash:
|
|
37
|
+
export declare function sliceCore32(hash: HoloHash | Uint8Array): Uint8Array;
|
|
38
38
|
/**
|
|
39
39
|
* Get DHT location (last 4 bytes) from a hash.
|
|
40
40
|
*
|
|
@@ -45,7 +45,7 @@ export declare function sliceCore32(hash: AgentPubKey | EntryHash | ActionHash):
|
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
47
|
*/
|
|
48
|
-
export declare function sliceDhtLocation(hash:
|
|
48
|
+
export declare function sliceDhtLocation(hash: HoloHash | Uint8Array): Uint8Array;
|
|
49
49
|
/**
|
|
50
50
|
* Generate DHT location (last 4 bytes) from a core hash (middle 32 bytes).
|
|
51
51
|
*
|
|
@@ -68,4 +68,4 @@ export declare function dhtLocationFrom32(hashCore: Uint8Array): Uint8Array;
|
|
|
68
68
|
*
|
|
69
69
|
* @public
|
|
70
70
|
*/
|
|
71
|
-
export declare function hashFrom32AndType(hashCore:
|
|
71
|
+
export declare function hashFrom32AndType(hashCore: Uint8Array, hashType: "Agent" | "Entry" | "Dna" | "Action" | "External"): Uint8Array;
|
package/lib/utils/hash-parts.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import blake2b from "@bitgo/blake2b";
|
|
2
|
+
import { HoloHash } from "../types.js";
|
|
2
3
|
const HASH_TYPE_START = 0;
|
|
3
4
|
const HASH_TYPE_BYTE_LENGTH = 3;
|
|
4
5
|
const CORE_HASH_BYTE_LENGTH = 32;
|
|
@@ -28,7 +29,9 @@ export const HASH_TYPE_PREFIX = {
|
|
|
28
29
|
* @public
|
|
29
30
|
*/
|
|
30
31
|
export function sliceHashType(hash) {
|
|
31
|
-
|
|
32
|
+
if (!(hash instanceof HoloHash))
|
|
33
|
+
hash = new HoloHash(hash);
|
|
34
|
+
return hash.getPrefix();
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Get core hash from a Holochain hash (32 bytes).
|
|
@@ -41,9 +44,11 @@ export function sliceHashType(hash) {
|
|
|
41
44
|
* @public
|
|
42
45
|
*/
|
|
43
46
|
export function sliceCore32(hash) {
|
|
47
|
+
if (!(hash instanceof HoloHash))
|
|
48
|
+
hash = new HoloHash(hash);
|
|
44
49
|
const start = HASH_TYPE_START + HASH_TYPE_BYTE_LENGTH;
|
|
45
50
|
const end = start + CORE_HASH_BYTE_LENGTH;
|
|
46
|
-
return
|
|
51
|
+
return hash.bytes(start, end);
|
|
47
52
|
}
|
|
48
53
|
/**
|
|
49
54
|
* Get DHT location (last 4 bytes) from a hash.
|
|
@@ -56,9 +61,11 @@ export function sliceCore32(hash) {
|
|
|
56
61
|
* @public
|
|
57
62
|
*/
|
|
58
63
|
export function sliceDhtLocation(hash) {
|
|
64
|
+
if (hash instanceof Uint8Array)
|
|
65
|
+
hash = new HoloHash(hash);
|
|
59
66
|
const start = HASH_TYPE_START + HASH_TYPE_BYTE_LENGTH + CORE_HASH_BYTE_LENGTH;
|
|
60
67
|
const end = start + DHT_LOCATION_BYTE_LENGTH;
|
|
61
|
-
return
|
|
68
|
+
return hash.bytes(start, end);
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* Generate DHT location (last 4 bytes) from a core hash (middle 32 bytes).
|
|
@@ -94,9 +101,5 @@ export function dhtLocationFrom32(hashCore) {
|
|
|
94
101
|
* @public
|
|
95
102
|
*/
|
|
96
103
|
export function hashFrom32AndType(hashCore, hashType) {
|
|
97
|
-
return
|
|
98
|
-
...HASH_TYPE_PREFIX[hashType],
|
|
99
|
-
...hashCore,
|
|
100
|
-
...dhtLocationFrom32(hashCore),
|
|
101
|
-
]);
|
|
104
|
+
return new HoloHash(hashCore).toType(hashType === "Agent" ? "AgentPubKey" : hashType + "Hash");
|
|
102
105
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holochain/client",
|
|
3
|
-
"version": "0.18.0-dev.
|
|
3
|
+
"version": "0.18.0-dev.9",
|
|
4
4
|
"description": "A JavaScript client for the Holochain Conductor API",
|
|
5
5
|
"author": "Holochain Foundation <info@holochain.org> (https://holochain.org)",
|
|
6
6
|
"license": "CAL-1.0",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@bitgo/blake2b": "^3.2.4",
|
|
46
46
|
"@holochain/serialization": "^0.1.0-beta-rc.3",
|
|
47
47
|
"@msgpack/msgpack": "^2.8.0",
|
|
48
|
+
"@spartan-hc/holo-hash": "^0.7.0",
|
|
48
49
|
"emittery": "^1.0.1",
|
|
49
50
|
"isomorphic-ws": "^5.0.0",
|
|
50
51
|
"js-base64": "^3.7.5",
|