@holochain/client 0.17.0-dev.2 → 0.17.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tsdoc-metadata.json +1 -1
- package/lib/utils/fake-hash.d.ts +8 -4
- package/lib/utils/fake-hash.js +25 -12
- package/lib/utils/hash-parts.d.ts +71 -0
- package/lib/utils/hash-parts.js +94 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/package.json +3 -1
package/lib/tsdoc-metadata.json
CHANGED
package/lib/utils/fake-hash.d.ts
CHANGED
|
@@ -4,32 +4,36 @@ 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.
|
|
7
8
|
* @returns An {@link EntryHash}.
|
|
8
9
|
*
|
|
9
10
|
* @public
|
|
10
11
|
*/
|
|
11
|
-
export declare function fakeEntryHash(): Promise<EntryHash>;
|
|
12
|
+
export declare function fakeEntryHash(coreByte?: number | undefined): Promise<EntryHash>;
|
|
12
13
|
/**
|
|
13
14
|
* Generate a valid agent key of a non-existing agent.
|
|
14
15
|
*
|
|
16
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
15
17
|
* @returns An {@link AgentPubKey}.
|
|
16
18
|
*
|
|
17
19
|
* @public
|
|
18
20
|
*/
|
|
19
|
-
export declare function fakeAgentPubKey(): Promise<AgentPubKey>;
|
|
21
|
+
export declare function fakeAgentPubKey(coreByte?: number | undefined): Promise<AgentPubKey>;
|
|
20
22
|
/**
|
|
21
23
|
* Generate a valid hash of a non-existing action.
|
|
22
24
|
*
|
|
25
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
23
26
|
* @returns An {@link ActionHash}.
|
|
24
27
|
*
|
|
25
28
|
* @public
|
|
26
29
|
*/
|
|
27
|
-
export declare function fakeActionHash(): Promise<ActionHash>;
|
|
30
|
+
export declare function fakeActionHash(coreByte?: number | undefined): Promise<ActionHash>;
|
|
28
31
|
/**
|
|
29
32
|
* Generate a valid hash of a non-existing DNA.
|
|
30
33
|
*
|
|
34
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
31
35
|
* @returns A {@link DnaHash}.
|
|
32
36
|
*
|
|
33
37
|
* @public
|
|
34
38
|
*/
|
|
35
|
-
export declare function fakeDnaHash(): Promise<DnaHash>;
|
|
39
|
+
export declare function fakeDnaHash(coreByte?: number | undefined): Promise<DnaHash>;
|
package/lib/utils/fake-hash.js
CHANGED
|
@@ -1,47 +1,60 @@
|
|
|
1
|
+
import { range } from "lodash-es";
|
|
1
2
|
import { randomByteArray } from "../api/zome-call-signing.js";
|
|
3
|
+
import { dhtLocationFrom32 } from "./hash-parts.js";
|
|
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
|
+
}
|
|
2
15
|
/**
|
|
3
16
|
* Generate a valid hash of a non-existing entry.
|
|
4
17
|
*
|
|
5
18
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
19
|
*
|
|
20
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
7
21
|
* @returns An {@link EntryHash}.
|
|
8
22
|
*
|
|
9
23
|
* @public
|
|
10
24
|
*/
|
|
11
|
-
export async function fakeEntryHash() {
|
|
12
|
-
|
|
13
|
-
return new Uint8Array([0x84, 0x21, 0x24, ...randomBytes]);
|
|
25
|
+
export async function fakeEntryHash(coreByte = undefined) {
|
|
26
|
+
return fakeValidHash([0x84, 0x21, 0x24], coreByte);
|
|
14
27
|
}
|
|
15
28
|
/**
|
|
16
29
|
* Generate a valid agent key of a non-existing agent.
|
|
17
30
|
*
|
|
31
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
18
32
|
* @returns An {@link AgentPubKey}.
|
|
19
33
|
*
|
|
20
34
|
* @public
|
|
21
35
|
*/
|
|
22
|
-
export async function fakeAgentPubKey() {
|
|
23
|
-
|
|
24
|
-
return new Uint8Array([0x84, 0x20, 0x24, ...randomBytes]);
|
|
36
|
+
export async function fakeAgentPubKey(coreByte = undefined) {
|
|
37
|
+
return fakeValidHash([0x84, 0x20, 0x24], coreByte);
|
|
25
38
|
}
|
|
26
39
|
/**
|
|
27
40
|
* Generate a valid hash of a non-existing action.
|
|
28
41
|
*
|
|
42
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
29
43
|
* @returns An {@link ActionHash}.
|
|
30
44
|
*
|
|
31
45
|
* @public
|
|
32
46
|
*/
|
|
33
|
-
export async function fakeActionHash() {
|
|
34
|
-
|
|
35
|
-
return new Uint8Array([0x84, 0x29, 0x24, ...randomBytes]);
|
|
47
|
+
export async function fakeActionHash(coreByte = undefined) {
|
|
48
|
+
return fakeValidHash([0x84, 0x29, 0x24], coreByte);
|
|
36
49
|
}
|
|
37
50
|
/**
|
|
38
51
|
* Generate a valid hash of a non-existing DNA.
|
|
39
52
|
*
|
|
53
|
+
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes.
|
|
40
54
|
* @returns A {@link DnaHash}.
|
|
41
55
|
*
|
|
42
56
|
* @public
|
|
43
57
|
*/
|
|
44
|
-
export async function fakeDnaHash() {
|
|
45
|
-
|
|
46
|
-
return new Uint8Array([0x84, 0x2d, 0x24, ...randomBytes]);
|
|
58
|
+
export async function fakeDnaHash(coreByte = undefined) {
|
|
59
|
+
return fakeValidHash([0x84, 0x2d, 0x24], coreByte);
|
|
47
60
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ActionHash, AgentPubKey, EntryHash } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash)
|
|
4
|
+
*
|
|
5
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare const HASH_TYPE_PREFIX: {
|
|
10
|
+
Agent: Uint8Array;
|
|
11
|
+
Entry: Uint8Array;
|
|
12
|
+
Dna: Uint8Array;
|
|
13
|
+
Action: Uint8Array;
|
|
14
|
+
External: Uint8Array;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get dht location (last 4 bytes) from a hash
|
|
18
|
+
*
|
|
19
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
20
|
+
*
|
|
21
|
+
* @param hash - The full 39 byte hash.
|
|
22
|
+
* @returns The last 4 bytes of the hash.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function sliceDhtLocation(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Get core (center 32 bytes) from a hash
|
|
29
|
+
*
|
|
30
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
31
|
+
*
|
|
32
|
+
* @param hash - The full 39 byte hash.
|
|
33
|
+
* @returns The core 32 bytes of the hash.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export declare function sliceCore32(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
|
|
38
|
+
/**
|
|
39
|
+
* Get hash type (initial 3 bytes) from a hash
|
|
40
|
+
*
|
|
41
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
42
|
+
*
|
|
43
|
+
* @param hash - The full 39 byte hash.
|
|
44
|
+
* @returns The initial 3 bytes of the hash.
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
|
|
49
|
+
/**
|
|
50
|
+
* Generate dht location (last 4 bytes) from a core hash (middle 32 bytes)
|
|
51
|
+
*
|
|
52
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
53
|
+
*
|
|
54
|
+
* @param hashCore - The core 32 bytes of the hash.
|
|
55
|
+
* @returns The last 4 bytes of the hash.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export declare function dhtLocationFrom32(hashCore: Uint8Array): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Generate full hash from a core hash (middle 32 bytes) and hash type label
|
|
62
|
+
*
|
|
63
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
64
|
+
*
|
|
65
|
+
* @param hashCore - The core 32 bytes of the hash.
|
|
66
|
+
* @param hashType - The type of the hash.
|
|
67
|
+
* @returns The full 39 byte hash.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export declare function hashFrom32AndType(hashCore: AgentPubKey | EntryHash | ActionHash, hashType: "Agent" | "Entry" | "Dna" | "Action" | "External"): Uint8Array;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import blake2b from "@bitgo/blake2b";
|
|
2
|
+
/**
|
|
3
|
+
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash)
|
|
4
|
+
*
|
|
5
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export const HASH_TYPE_PREFIX = {
|
|
10
|
+
Agent: Uint8Array.from([132, 32, 36]),
|
|
11
|
+
Entry: Uint8Array.from([132, 33, 36]),
|
|
12
|
+
Dna: Uint8Array.from([132, 45, 36]),
|
|
13
|
+
Action: Uint8Array.from([132, 41, 36]),
|
|
14
|
+
External: Uint8Array.from([132, 47, 36]),
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get dht location (last 4 bytes) from a hash
|
|
18
|
+
*
|
|
19
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
20
|
+
*
|
|
21
|
+
* @param hash - The full 39 byte hash.
|
|
22
|
+
* @returns The last 4 bytes of the hash.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export function sliceDhtLocation(hash) {
|
|
27
|
+
return Uint8Array.from(hash.slice(36, 40));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get core (center 32 bytes) from a hash
|
|
31
|
+
*
|
|
32
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
33
|
+
*
|
|
34
|
+
* @param hash - The full 39 byte hash.
|
|
35
|
+
* @returns The core 32 bytes of the hash.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export function sliceCore32(hash) {
|
|
40
|
+
return Uint8Array.from(hash.slice(3, 36));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get hash type (initial 3 bytes) from a hash
|
|
44
|
+
*
|
|
45
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
46
|
+
*
|
|
47
|
+
* @param hash - The full 39 byte hash.
|
|
48
|
+
* @returns The initial 3 bytes of the hash.
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
export function sliceHashType(hash) {
|
|
53
|
+
return Uint8Array.from(hash.slice(0, 3));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate dht location (last 4 bytes) from a core hash (middle 32 bytes)
|
|
57
|
+
*
|
|
58
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
59
|
+
*
|
|
60
|
+
* @param hashCore - The core 32 bytes of the hash.
|
|
61
|
+
* @returns The last 4 bytes of the hash.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
export function dhtLocationFrom32(hashCore) {
|
|
66
|
+
const hash = new Uint8Array(16);
|
|
67
|
+
blake2b(hash.length).update(hashCore).digest(hash);
|
|
68
|
+
const out = hash.slice(0, 4);
|
|
69
|
+
[4, 8, 12].forEach((i) => {
|
|
70
|
+
out[0] ^= hash[i];
|
|
71
|
+
out[1] ^= hash[i + 1];
|
|
72
|
+
out[2] ^= hash[i + 2];
|
|
73
|
+
out[3] ^= hash[i + 3];
|
|
74
|
+
});
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generate full hash from a core hash (middle 32 bytes) and hash type label
|
|
79
|
+
*
|
|
80
|
+
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
81
|
+
*
|
|
82
|
+
* @param hashCore - The core 32 bytes of the hash.
|
|
83
|
+
* @param hashType - The type of the hash.
|
|
84
|
+
* @returns The full 39 byte hash.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export function hashFrom32AndType(hashCore, hashType) {
|
|
89
|
+
return Uint8Array.from([
|
|
90
|
+
...HASH_TYPE_PREFIX[hashType],
|
|
91
|
+
...hashCore,
|
|
92
|
+
...dhtLocationFrom32(hashCore),
|
|
93
|
+
]);
|
|
94
|
+
}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holochain/client",
|
|
3
|
-
"version": "0.17.0-dev.
|
|
3
|
+
"version": "0.17.0-dev.3",
|
|
4
4
|
"description": "A JavaScript client for the Holochain Conductor API",
|
|
5
5
|
"author": "Holochain Foundation <info@holochain.org> (http://holochain.org)",
|
|
6
6
|
"license": "CAL-1.0",
|
|
@@ -33,12 +33,14 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"lint": "eslint --fix --ext .ts src test .eslintrc.cjs",
|
|
35
35
|
"test:app-agent": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/e2e/app-agent-websocket.ts",
|
|
36
|
+
"test:utils": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/e2e/utils.ts",
|
|
36
37
|
"test": "RUST_LOG=error RUST_BACKTRACE=1 node --loader ts-node/esm test/index.ts",
|
|
37
38
|
"build:lib": "rimraf ./lib && tsc -p tsconfig.build.json",
|
|
38
39
|
"build:docs": "api-extractor run --local && api-documenter markdown -i docs/temp -o docs",
|
|
39
40
|
"build": "npm run build:lib && npm run build:docs"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
43
|
+
"@bitgo/blake2b": "^3.2.4",
|
|
42
44
|
"@holochain/serialization": "^0.1.0-beta-rc.3",
|
|
43
45
|
"@msgpack/msgpack": "^2.8.0",
|
|
44
46
|
"@tauri-apps/api": "^1.4.0",
|