@holochain/client 0.18.0-dev.4 → 0.18.0-dev.5
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/hash-parts.d.ts +10 -10
- package/lib/utils/hash-parts.js +21 -13
- package/package.json +1 -1
package/lib/tsdoc-metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionHash, AgentPubKey, EntryHash } from "../types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash)
|
|
3
|
+
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash).
|
|
4
4
|
*
|
|
5
5
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
6
|
*
|
|
@@ -14,18 +14,18 @@ export declare const HASH_TYPE_PREFIX: {
|
|
|
14
14
|
External: Uint8Array;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* Get
|
|
17
|
+
* Get hash type (initial 3 bytes) from a hash.
|
|
18
18
|
*
|
|
19
19
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
20
20
|
*
|
|
21
21
|
* @param hash - The full 39 byte hash.
|
|
22
|
-
* @returns The
|
|
22
|
+
* @returns The initial 3 bytes of the hash.
|
|
23
23
|
*
|
|
24
24
|
* @public
|
|
25
25
|
*/
|
|
26
|
-
export declare function
|
|
26
|
+
export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
|
|
27
27
|
/**
|
|
28
|
-
* Get core
|
|
28
|
+
* Get core hash from a Holochain hash (32 bytes).
|
|
29
29
|
*
|
|
30
30
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
31
31
|
*
|
|
@@ -36,18 +36,18 @@ export declare function sliceDhtLocation(hash: AgentPubKey | EntryHash | ActionH
|
|
|
36
36
|
*/
|
|
37
37
|
export declare function sliceCore32(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
|
|
38
38
|
/**
|
|
39
|
-
* Get
|
|
39
|
+
* Get DHT location (last 4 bytes) from a hash.
|
|
40
40
|
*
|
|
41
41
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
42
42
|
*
|
|
43
43
|
* @param hash - The full 39 byte hash.
|
|
44
|
-
* @returns The
|
|
44
|
+
* @returns The last 4 bytes of the hash.
|
|
45
45
|
*
|
|
46
46
|
* @public
|
|
47
47
|
*/
|
|
48
|
-
export declare function
|
|
48
|
+
export declare function sliceDhtLocation(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
|
|
49
49
|
/**
|
|
50
|
-
* Generate
|
|
50
|
+
* Generate DHT location (last 4 bytes) from a core hash (middle 32 bytes).
|
|
51
51
|
*
|
|
52
52
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
53
53
|
*
|
|
@@ -58,7 +58,7 @@ export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash
|
|
|
58
58
|
*/
|
|
59
59
|
export declare function dhtLocationFrom32(hashCore: Uint8Array): Uint8Array;
|
|
60
60
|
/**
|
|
61
|
-
* Generate full hash from a core hash (middle 32 bytes) and hash type label
|
|
61
|
+
* Generate full hash from a core hash (middle 32 bytes) and hash type label.
|
|
62
62
|
*
|
|
63
63
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
64
64
|
*
|
package/lib/utils/hash-parts.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import blake2b from "@bitgo/blake2b";
|
|
2
|
+
const HASH_TYPE_START = 0;
|
|
3
|
+
const HASH_TYPE_BYTE_LENGTH = 3;
|
|
4
|
+
const CORE_HASH_BYTE_LENGTH = 32;
|
|
5
|
+
const DHT_LOCATION_BYTE_LENGTH = 4;
|
|
2
6
|
/**
|
|
3
|
-
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash)
|
|
7
|
+
* Hash type labels and their 3 byte values (forming the first 3 bytes of hash).
|
|
4
8
|
*
|
|
5
9
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
6
10
|
*
|
|
@@ -14,20 +18,20 @@ export const HASH_TYPE_PREFIX = {
|
|
|
14
18
|
External: Uint8Array.from([132, 47, 36]),
|
|
15
19
|
};
|
|
16
20
|
/**
|
|
17
|
-
* Get
|
|
21
|
+
* Get hash type (initial 3 bytes) from a hash.
|
|
18
22
|
*
|
|
19
23
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
20
24
|
*
|
|
21
25
|
* @param hash - The full 39 byte hash.
|
|
22
|
-
* @returns The
|
|
26
|
+
* @returns The initial 3 bytes of the hash.
|
|
23
27
|
*
|
|
24
28
|
* @public
|
|
25
29
|
*/
|
|
26
|
-
export function
|
|
27
|
-
return Uint8Array.from(hash.slice(
|
|
30
|
+
export function sliceHashType(hash) {
|
|
31
|
+
return Uint8Array.from(hash.slice(0, 3));
|
|
28
32
|
}
|
|
29
33
|
/**
|
|
30
|
-
* Get core
|
|
34
|
+
* Get core hash from a Holochain hash (32 bytes).
|
|
31
35
|
*
|
|
32
36
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
33
37
|
*
|
|
@@ -37,23 +41,27 @@ export function sliceDhtLocation(hash) {
|
|
|
37
41
|
* @public
|
|
38
42
|
*/
|
|
39
43
|
export function sliceCore32(hash) {
|
|
40
|
-
|
|
44
|
+
const start = HASH_TYPE_START + HASH_TYPE_BYTE_LENGTH;
|
|
45
|
+
const end = start + CORE_HASH_BYTE_LENGTH;
|
|
46
|
+
return Uint8Array.from(hash.slice(start, end));
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
|
-
* Get
|
|
49
|
+
* Get DHT location (last 4 bytes) from a hash.
|
|
44
50
|
*
|
|
45
51
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
46
52
|
*
|
|
47
53
|
* @param hash - The full 39 byte hash.
|
|
48
|
-
* @returns The
|
|
54
|
+
* @returns The last 4 bytes of the hash.
|
|
49
55
|
*
|
|
50
56
|
* @public
|
|
51
57
|
*/
|
|
52
|
-
export function
|
|
53
|
-
|
|
58
|
+
export function sliceDhtLocation(hash) {
|
|
59
|
+
const start = HASH_TYPE_START + HASH_TYPE_BYTE_LENGTH + CORE_HASH_BYTE_LENGTH;
|
|
60
|
+
const end = start + DHT_LOCATION_BYTE_LENGTH;
|
|
61
|
+
return Uint8Array.from(hash.slice(start, end));
|
|
54
62
|
}
|
|
55
63
|
/**
|
|
56
|
-
* Generate
|
|
64
|
+
* Generate DHT location (last 4 bytes) from a core hash (middle 32 bytes).
|
|
57
65
|
*
|
|
58
66
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
59
67
|
*
|
|
@@ -75,7 +83,7 @@ export function dhtLocationFrom32(hashCore) {
|
|
|
75
83
|
return out;
|
|
76
84
|
}
|
|
77
85
|
/**
|
|
78
|
-
* Generate full hash from a core hash (middle 32 bytes) and hash type label
|
|
86
|
+
* Generate full hash from a core hash (middle 32 bytes) and hash type label.
|
|
79
87
|
*
|
|
80
88
|
* From https://github.com/holochain/holochain/blob/develop/crates/holo_hash/src/hash_type/primitive.rs
|
|
81
89
|
*
|
package/package.json
CHANGED