@holochain/client
Advanced tools
Comparing version 0.18.0-dev.6 to 0.18.0-dev.9
import { type KeyPair } from "libsodium-wrappers"; | ||
import type { CapSecret } from "../hdk/capabilities.js"; | ||
import type { AgentPubKey, CellId } from "../types.js"; | ||
import type { CellId } from "../types.js"; | ||
import { AgentPubKey } from "../types.js"; | ||
/** | ||
@@ -36,4 +37,2 @@ * @public | ||
* | ||
* @param agentPubKey - The agent pub key to take 4 last bytes (= DHT location) | ||
* from (optional). | ||
* @returns The signing key pair and an agent pub key based on the public key. | ||
@@ -43,3 +42,6 @@ * | ||
*/ | ||
export declare const generateSigningKeyPair: (agentPubKey?: AgentPubKey) => Promise<[KeyPair, AgentPubKey]>; | ||
export declare const generateSigningKeyPair: () => Promise<[ | ||
KeyPair, | ||
AgentPubKey | ||
]>; | ||
/** | ||
@@ -46,0 +48,0 @@ * @public |
import _sodium from "libsodium-wrappers"; | ||
import { AgentPubKey } from "../types.js"; | ||
import { encodeHashToBase64 } from "../utils/base64.js"; | ||
@@ -30,4 +31,2 @@ const signingCredentials = new Map(); | ||
* | ||
* @param agentPubKey - The agent pub key to take 4 last bytes (= DHT location) | ||
* from (optional). | ||
* @returns The signing key pair and an agent pub key based on the public key. | ||
@@ -37,8 +36,7 @@ * | ||
*/ | ||
export const generateSigningKeyPair = async (agentPubKey) => { | ||
export const generateSigningKeyPair = async () => { | ||
await _sodium.ready; | ||
const sodium = _sodium; | ||
const keyPair = sodium.crypto_sign_keypair(); | ||
const locationBytes = agentPubKey ? agentPubKey.subarray(35) : [0, 0, 0, 0]; | ||
const signingKey = new Uint8Array([132, 32, 36].concat(...keyPair.publicKey).concat(...locationBytes)); | ||
const signingKey = new AgentPubKey(keyPair.publicKey); | ||
return [keyPair, signingKey]; | ||
@@ -45,0 +43,0 @@ }; |
@@ -1,7 +0,3 @@ | ||
import { ActionHash, AgentPubKey, EntryHash, ExternalHash, Timestamp } from "../types.js"; | ||
import { ActionHash, AgentPubKey, Timestamp, AnyLinkableHash } from "../types.js"; | ||
/** | ||
* @public | ||
*/ | ||
export type AnyLinkableHash = EntryHash | ActionHash | ExternalHash; | ||
/** | ||
* An internal zome index within the DNA, from 0 to 255. | ||
@@ -8,0 +4,0 @@ * |
@@ -0,36 +1,9 @@ | ||
import { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash } from "@spartan-hc/holo-hash"; | ||
/** | ||
* @public | ||
*/ | ||
export type HoloHash = Uint8Array; | ||
export { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash, }; | ||
/** | ||
* @public | ||
*/ | ||
export type AgentPubKey = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type DnaHash = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type WasmHash = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type EntryHash = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type ActionHash = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type AnyDhtHash = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type ExternalHash = HoloHash; | ||
/** | ||
* @public | ||
*/ | ||
export type KitsuneAgent = Uint8Array; | ||
@@ -37,0 +10,0 @@ /** |
@@ -1,1 +0,5 @@ | ||
export {}; | ||
import { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash, } from "@spartan-hc/holo-hash"; | ||
/** | ||
* @public | ||
*/ | ||
export { HoloHash, AgentPubKey, DnaHash, WasmHash, EntryHash, ActionHash, AnyDhtHash, AnyLinkableHash, ExternalHash, }; |
@@ -1,2 +0,3 @@ | ||
import { HoloHash, HoloHashB64 } from "../types.js"; | ||
import { HoloHashB64 } from "../types.js"; | ||
import { HoloHash } from "@spartan-hc/holo-hash"; | ||
/** | ||
@@ -10,3 +11,3 @@ * Decodes a Base64 encoded string to a byte array hash. | ||
*/ | ||
export declare function decodeHashFromBase64(hash: HoloHashB64): HoloHash; | ||
export declare function decodeHashFromBase64(hash: string): HoloHash; | ||
/** | ||
@@ -20,2 +21,2 @@ * Encode a byte array hash to a Base64 string. | ||
*/ | ||
export declare function encodeHashToBase64(hash: HoloHash): HoloHashB64; | ||
export declare function encodeHashToBase64(hash: Uint8Array): HoloHashB64; |
@@ -1,2 +0,2 @@ | ||
import { Base64 } from "js-base64"; | ||
import { HoloHash } from "@spartan-hc/holo-hash"; | ||
/** | ||
@@ -11,3 +11,3 @@ * Decodes a Base64 encoded string to a byte array hash. | ||
export function decodeHashFromBase64(hash) { | ||
return Base64.toUint8Array(hash.slice(1)); | ||
return new HoloHash(hash); | ||
} | ||
@@ -23,3 +23,3 @@ /** | ||
export function encodeHashToBase64(hash) { | ||
return `u${Base64.fromUint8Array(hash, true)}`; | ||
return String(new HoloHash(hash)); | ||
} |
@@ -8,3 +8,3 @@ import { DnaHash, ActionHash, AgentPubKey, EntryHash } from "../types.js"; | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns An {@link EntryHash}. | ||
* @returns An instance of EntryHash. | ||
* | ||
@@ -18,3 +18,3 @@ * @public | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns An {@link AgentPubKey}. | ||
* @returns An instance ofAgentPubKey. | ||
* | ||
@@ -28,3 +28,3 @@ * @public | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns An {@link ActionHash}. | ||
* @returns An instance of ActionHash. | ||
* | ||
@@ -38,3 +38,3 @@ * @public | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns A {@link DnaHash}. | ||
* @returns A instance of DnaHash. | ||
* | ||
@@ -41,0 +41,0 @@ * @public |
import { range } from "lodash-es"; | ||
import { randomByteArray } from "../api/zome-call-signing.js"; | ||
import { dhtLocationFrom32 } from "./hash-parts.js"; | ||
async function fakeValidHash(prefix, coreByte) { | ||
let core; | ||
if (coreByte === undefined) { | ||
core = await randomByteArray(32); | ||
} | ||
else { | ||
core = Uint8Array.from(range(0, 32).map(() => coreByte)); | ||
} | ||
const checksum = dhtLocationFrom32(core); | ||
return new Uint8Array([...prefix, ...core, ...Array.from(checksum)]); | ||
} | ||
import { DnaHash, ActionHash, AgentPubKey, EntryHash } from "../types.js"; | ||
/** | ||
@@ -21,3 +10,3 @@ * Generate a valid hash of a non-existing entry. | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns An {@link EntryHash}. | ||
* @returns An instance of EntryHash. | ||
* | ||
@@ -27,3 +16,5 @@ * @public | ||
export async function fakeEntryHash(coreByte = undefined) { | ||
return fakeValidHash([0x84, 0x21, 0x24], coreByte); | ||
return new EntryHash(coreByte | ||
? Uint8Array.from(range(0, 32).map(() => coreByte)) | ||
: await randomByteArray(32)); | ||
} | ||
@@ -34,3 +25,3 @@ /** | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns An {@link AgentPubKey}. | ||
* @returns An instance ofAgentPubKey. | ||
* | ||
@@ -40,3 +31,5 @@ * @public | ||
export async function fakeAgentPubKey(coreByte = undefined) { | ||
return fakeValidHash([0x84, 0x20, 0x24], coreByte); | ||
return new AgentPubKey(coreByte | ||
? Uint8Array.from(range(0, 32).map(() => coreByte)) | ||
: await randomByteArray(32)); | ||
} | ||
@@ -47,3 +40,3 @@ /** | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns An {@link ActionHash}. | ||
* @returns An instance of ActionHash. | ||
* | ||
@@ -53,3 +46,5 @@ * @public | ||
export async function fakeActionHash(coreByte = undefined) { | ||
return fakeValidHash([0x84, 0x29, 0x24], coreByte); | ||
return new ActionHash(coreByte | ||
? Uint8Array.from(range(0, 32).map(() => coreByte)) | ||
: await randomByteArray(32)); | ||
} | ||
@@ -60,3 +55,3 @@ /** | ||
* @param coreByte - Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. | ||
* @returns A {@link DnaHash}. | ||
* @returns A instance of DnaHash. | ||
* | ||
@@ -66,3 +61,5 @@ * @public | ||
export async function fakeDnaHash(coreByte = undefined) { | ||
return fakeValidHash([0x84, 0x2d, 0x24], coreByte); | ||
return new DnaHash(coreByte | ||
? Uint8Array.from(range(0, 32).map(() => coreByte)) | ||
: await randomByteArray(32)); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { ActionHash, AgentPubKey, EntryHash } from "../types.js"; | ||
import { HoloHash } from "../types.js"; | ||
/** | ||
@@ -26,3 +26,3 @@ * Hash type labels and their 3 byte values (forming the first 3 bytes of hash). | ||
*/ | ||
export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array; | ||
export declare function sliceHashType(hash: HoloHash | Uint8Array): Uint8Array; | ||
/** | ||
@@ -38,3 +38,3 @@ * Get core hash from a Holochain hash (32 bytes). | ||
*/ | ||
export declare function sliceCore32(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array; | ||
export declare function sliceCore32(hash: HoloHash | Uint8Array): Uint8Array; | ||
/** | ||
@@ -50,3 +50,3 @@ * Get DHT location (last 4 bytes) from a hash. | ||
*/ | ||
export declare function sliceDhtLocation(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array; | ||
export declare function sliceDhtLocation(hash: HoloHash | Uint8Array): Uint8Array; | ||
/** | ||
@@ -74,2 +74,2 @@ * Generate DHT location (last 4 bytes) from a core hash (middle 32 bytes). | ||
*/ | ||
export declare function hashFrom32AndType(hashCore: AgentPubKey | EntryHash | ActionHash, hashType: "Agent" | "Entry" | "Dna" | "Action" | "External"): Uint8Array; | ||
export declare function hashFrom32AndType(hashCore: Uint8Array, hashType: "Agent" | "Entry" | "Dna" | "Action" | "External"): Uint8Array; |
import blake2b from "@bitgo/blake2b"; | ||
import { HoloHash } from "../types.js"; | ||
const HASH_TYPE_START = 0; | ||
@@ -31,3 +32,5 @@ const HASH_TYPE_BYTE_LENGTH = 3; | ||
export function sliceHashType(hash) { | ||
return Uint8Array.from(hash.slice(0, 3)); | ||
if (!(hash instanceof HoloHash)) | ||
hash = new HoloHash(hash); | ||
return hash.getPrefix(); | ||
} | ||
@@ -45,5 +48,7 @@ /** | ||
export function sliceCore32(hash) { | ||
if (!(hash instanceof HoloHash)) | ||
hash = new HoloHash(hash); | ||
const start = HASH_TYPE_START + HASH_TYPE_BYTE_LENGTH; | ||
const end = start + CORE_HASH_BYTE_LENGTH; | ||
return Uint8Array.from(hash.slice(start, end)); | ||
return hash.bytes(start, end); | ||
} | ||
@@ -61,5 +66,7 @@ /** | ||
export function sliceDhtLocation(hash) { | ||
if (hash instanceof Uint8Array) | ||
hash = new HoloHash(hash); | ||
const start = HASH_TYPE_START + HASH_TYPE_BYTE_LENGTH + CORE_HASH_BYTE_LENGTH; | ||
const end = start + DHT_LOCATION_BYTE_LENGTH; | ||
return Uint8Array.from(hash.slice(start, end)); | ||
return hash.bytes(start, end); | ||
} | ||
@@ -100,7 +107,3 @@ /** | ||
export function hashFrom32AndType(hashCore, hashType) { | ||
return Uint8Array.from([ | ||
...HASH_TYPE_PREFIX[hashType], | ||
...hashCore, | ||
...dhtLocationFrom32(hashCore), | ||
]); | ||
return new HoloHash(hashCore).toType(hashType === "Agent" ? "AgentPubKey" : hashType + "Hash"); | ||
} |
{ | ||
"name": "@holochain/client", | ||
"version": "0.18.0-dev.6", | ||
"version": "0.18.0-dev.9", | ||
"description": "A JavaScript client for the Holochain Conductor API", | ||
@@ -48,2 +48,3 @@ "author": "Holochain Foundation <info@holochain.org> (https://holochain.org)", | ||
"@msgpack/msgpack": "^2.8.0", | ||
"@spartan-hc/holo-hash": "^0.7.0", | ||
"emittery": "^1.0.1", | ||
@@ -50,0 +51,0 @@ "isomorphic-ws": "^5.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
132338
10
3632
+ Added@spartan-hc/holo-hash@^0.7.0
+ Added@spartan-hc/holo-hash@0.7.0(transitive)
+ Added@whi/xor-digest@0.1.0(transitive)