@holochain/client 0.18.0-dev.6 → 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/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
|
@@ -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",
|