Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Valid fake hashes & additional hash helper utilities #216

Merged
merged 20 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## \[Unreleased\]

### Added
- Utility functions for slicing hashes into their components: `sliceHashType`, `sliceCore32`, `sliceDhtLocation`
- Utility functions for generating hashes from components: `dhtLocationFrom32`, `hashFrom32AndType`:
### Changed
- Utility functions fakeAgentPubKey, fakeEntryHash, fakeActionHash and fakeDnaHash now generate *valid* hashes with a valid final 4 bytes
- Utility functions fakeAgentPubKey, fakeEntryHash, fakeActionHash and fakeDnaHash now optionally take a single parameter `coreByte` which if defined will be repeated for all core 32 bytes of the hash
### Fixed
### Removed

Expand Down
28 changes: 28 additions & 0 deletions docs/client.dhtlocationfrom32.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [dhtLocationFrom32](./client.dhtlocationfrom32.md)

## dhtLocationFrom32() function

Generate dht location (last 4 bytes) from a core hash (middle 32 bytes)

From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs

**Signature:**

```typescript
export declare function dhtLocationFrom32(hashCore: Uint8Array): Uint8Array;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| hashCore | Uint8Array | The core 32 bytes of the hash. |

**Returns:**

Uint8Array

The last 4 bytes of the hash.

9 changes: 8 additions & 1 deletion docs/client.fakeactionhash.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ Generate a valid hash of a non-existing action.
**Signature:**

```typescript
export declare function fakeActionHash(): Promise<ActionHash>;
export declare function fakeActionHash(coreByte?: number | undefined): Promise<ActionHash>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| coreByte | number \| undefined | _(Optional)_ Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. |

**Returns:**

Promise&lt;[ActionHash](./client.actionhash.md)<!-- -->&gt;
Expand Down
9 changes: 8 additions & 1 deletion docs/client.fakeagentpubkey.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ Generate a valid agent key of a non-existing agent.
**Signature:**

```typescript
export declare function fakeAgentPubKey(): Promise<AgentPubKey>;
export declare function fakeAgentPubKey(coreByte?: number | undefined): Promise<AgentPubKey>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| coreByte | number \| undefined | _(Optional)_ Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. |

**Returns:**

Promise&lt;[AgentPubKey](./client.agentpubkey.md)<!-- -->&gt;
Expand Down
9 changes: 8 additions & 1 deletion docs/client.fakednahash.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ Generate a valid hash of a non-existing DNA.
**Signature:**

```typescript
export declare function fakeDnaHash(): Promise<DnaHash>;
export declare function fakeDnaHash(coreByte?: number | undefined): Promise<DnaHash>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| coreByte | number \| undefined | _(Optional)_ Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. |

**Returns:**

Promise&lt;[DnaHash](./client.dnahash.md)<!-- -->&gt;
Expand Down
9 changes: 8 additions & 1 deletion docs/client.fakeentryhash.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/h
**Signature:**

```typescript
export declare function fakeEntryHash(): Promise<EntryHash>;
export declare function fakeEntryHash(coreByte?: number | undefined): Promise<EntryHash>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| coreByte | number \| undefined | _(Optional)_ Optionally specify a byte to repeat for all core 32 bytes. If undefined will generate random core 32 bytes. |

**Returns:**

Promise&lt;[EntryHash](./client.entryhash.md)<!-- -->&gt;
Expand Down
21 changes: 21 additions & 0 deletions docs/client.hash_type_prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [HASH\_TYPE\_PREFIX](./client.hash_type_prefix.md)

## HASH\_TYPE\_PREFIX variable

Hash type labels and their 3 byte values (forming the first 3 bytes of hash)

From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs

**Signature:**

```typescript
HASH_TYPE_PREFIX: {
Agent: Uint8Array;
Entry: Uint8Array;
Dna: Uint8Array;
Action: Uint8Array;
External: Uint8Array;
}
```
29 changes: 29 additions & 0 deletions docs/client.hashfrom32andtype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [hashFrom32AndType](./client.hashfrom32andtype.md)

## hashFrom32AndType() function

Generate full hash from a core hash (middle 32 bytes) and hash type label

From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs

**Signature:**

```typescript
export declare function hashFrom32AndType(hashCore: AgentPubKey | EntryHash | ActionHash, hashType: "Agent" | "Entry" | "Dna" | "Action" | "External"): Uint8Array;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| hashCore | [AgentPubKey](./client.agentpubkey.md) \| [EntryHash](./client.entryhash.md) \| [ActionHash](./client.actionhash.md) | The core 32 bytes of the hash. |
| hashType | "Agent" \| "Entry" \| "Dna" \| "Action" \| "External" | The type of the hash. |

**Returns:**

Uint8Array

The full 39 byte hash.

14 changes: 10 additions & 4 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,20 @@
| Function | Description |
| --- | --- |
| [decodeHashFromBase64(hash)](./client.decodehashfrombase64.md) | Decodes a Base64 encoded string to a byte array hash. |
| [dhtLocationFrom32(hashCore)](./client.dhtlocationfrom32.md) | <p>Generate dht location (last 4 bytes) from a core hash (middle 32 bytes)</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [encodeHashToBase64(hash)](./client.encodehashtobase64.md) | Encode a byte array hash to a Base64 string. |
| [fakeActionHash()](./client.fakeactionhash.md) | Generate a valid hash of a non-existing action. |
| [fakeAgentPubKey()](./client.fakeagentpubkey.md) | Generate a valid agent key of a non-existing agent. |
| [fakeDnaHash()](./client.fakednahash.md) | Generate a valid hash of a non-existing DNA. |
| [fakeEntryHash()](./client.fakeentryhash.md) | <p>Generate a valid hash of a non-existing entry.</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [fakeActionHash(coreByte)](./client.fakeactionhash.md) | Generate a valid hash of a non-existing action. |
| [fakeAgentPubKey(coreByte)](./client.fakeagentpubkey.md) | Generate a valid agent key of a non-existing agent. |
| [fakeDnaHash(coreByte)](./client.fakednahash.md) | Generate a valid hash of a non-existing DNA. |
| [fakeEntryHash(coreByte)](./client.fakeentryhash.md) | <p>Generate a valid hash of a non-existing entry.</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [getDhtOpAction(op)](./client.getdhtopaction.md) | |
| [getDhtOpEntry(op)](./client.getdhtopentry.md) | |
| [getDhtOpSignature(op)](./client.getdhtopsignature.md) | |
| [getDhtOpType(op)](./client.getdhtoptype.md) | |
| [hashFrom32AndType(hashCore, hashType)](./client.hashfrom32andtype.md) | <p>Generate full hash from a core hash (middle 32 bytes) and hash type label</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [sliceCore32(hash)](./client.slicecore32.md) | <p>Get core (center 32 bytes) from a hash</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [sliceDhtLocation(hash)](./client.slicedhtlocation.md) | <p>Get dht location (last 4 bytes) from a hash</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [sliceHashType(hash)](./client.slicehashtype.md) | <p>Get hash type (initial 3 bytes) from a hash</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |

## Interfaces

Expand Down Expand Up @@ -109,6 +114,7 @@
| [getBaseRoleNameFromCloneId](./client.getbaserolenamefromcloneid.md) | Parse a clone id and get the role name part of it. |
| [getNonceExpiration](./client.getnonceexpiration.md) | |
| [getSigningCredentials](./client.getsigningcredentials.md) | Get credentials for signing zome calls. |
| [HASH\_TYPE\_PREFIX](./client.hash_type_prefix.md) | <p>Hash type labels and their 3 byte values (forming the first 3 bytes of hash)</p><p>From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs</p> |
| [isCloneId](./client.iscloneid.md) | Check if a cell's role name is a valid clone id. |
| [randomByteArray](./client.randombytearray.md) | |
| [randomCapSecret](./client.randomcapsecret.md) | |
Expand Down
28 changes: 28 additions & 0 deletions docs/client.slicecore32.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [sliceCore32](./client.slicecore32.md)

## sliceCore32() function

Get core (center 32 bytes) from a hash

From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs

**Signature:**

```typescript
export declare function sliceCore32(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| hash | [AgentPubKey](./client.agentpubkey.md) \| [EntryHash](./client.entryhash.md) \| [ActionHash](./client.actionhash.md) | The full 39 byte hash. |

**Returns:**

Uint8Array

The core 32 bytes of the hash.

28 changes: 28 additions & 0 deletions docs/client.slicedhtlocation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [sliceDhtLocation](./client.slicedhtlocation.md)

## sliceDhtLocation() function

Get dht location (last 4 bytes) from a hash

From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs

**Signature:**

```typescript
export declare function sliceDhtLocation(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| hash | [AgentPubKey](./client.agentpubkey.md) \| [EntryHash](./client.entryhash.md) \| [ActionHash](./client.actionhash.md) | The full 39 byte hash. |

**Returns:**

Uint8Array

The last 4 bytes of the hash.

28 changes: 28 additions & 0 deletions docs/client.slicehashtype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@holochain/client](./client.md) &gt; [sliceHashType](./client.slicehashtype.md)

## sliceHashType() function

Get hash type (initial 3 bytes) from a hash

From https://github.com/holochain/holochain/blob/develop/crates/holo\_hash/src/hash\_type/primitive.rs

**Signature:**

```typescript
export declare function sliceHashType(hash: AgentPubKey | EntryHash | ActionHash): Uint8Array;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| hash | [AgentPubKey](./client.agentpubkey.md) \| [EntryHash](./client.entryhash.md) \| [ActionHash](./client.actionhash.md) | The full 39 byte hash. |

**Returns:**

Uint8Array

The initial 3 bytes of the hash.

Loading