Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@typeberry/trie

Package Overview
Dependencies
Maintainers
0
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typeberry/trie - npm Package Compare versions

Comparing version 0.0.1-46c9206 to 0.0.1-707e1a2

index.d.ts

6

package.json
{
"name": "@typeberry/trie",
"version": "0.0.1-46c9206",
"main": "trie.js",
"version": "0.0.1-707e1a2",
"main": "index.js",
"author": "Fluffy Labs",
"license": "MPL-2.0"
}
}

@@ -0,21 +1,49 @@

/**
* A variable-length blob of bytes with a concise text representation.
*
* The structure is used as convenience wrapper for [`Uint8Array`],
* especially if the data is coming from a hex-encoded string.
*/
export declare class BytesBlob {
readonly buffer: Uint8Array;
readonly length: number;
private constructor();
protected constructor(data: Uint8Array);
/**
* Display a hex-encoded version of this byte blob.
*/
toString(): string;
static fromBlob(v: Uint8Array): BytesBlob;
/** Compare the sequence to another one. */
isEqualTo(other: BytesBlob): boolean;
/** Create a new [`BytesBlob'] by converting given UTF-u encoded string into bytes. */
static fromString(v: string): BytesBlob;
/** Create a new [`BytesBlob`] from existing [`Uint8Array`]. */
static from(v: Uint8Array): BytesBlob;
/** Create a new [`BytesBlob`] by concatenating data from multiple `Uint8Array`s. */
static copyFromBlobs(v: Uint8Array, ...rest: Uint8Array[]): BytesBlob;
/** Create a new [`BytesBlob`] from an array of bytes. */
static fromNumbers(v: number[]): BytesBlob;
/** Parse a hex-encoded bytes blob without `0x` prefix. */
static parseBlobNoPrefix(v: string): BytesBlob;
/** Parse a hex-encoded bytes blob with `0x` prefix. */
static parseBlob(v: string): BytesBlob;
}
export declare class Bytes<T extends number> {
readonly raw: Uint8Array;
/**
* A convenience wrapper for a fix-length sequence of bytes.
*/
export declare class Bytes<T extends number> extends BytesBlob {
/** Length of the bytes array. */
readonly length: T;
private constructor();
toString(): string;
isEqualTo(other: Bytes<T>): boolean;
/** Raw bytes array. */
get raw(): Uint8Array;
/** Create new [`Bytes<X>`] given a backing buffer and it's length. */
static fromBlob<X extends number>(v: Uint8Array, len: X): Bytes<X>;
/** Create an empty [`Bytes<X>`] of given length. */
static zero<X extends number>(len: X): Bytes<X>;
/** Create a [`Bytes<X>`] with all bytes filled with given input number. */
static fill<X extends number>(len: X, input: number): Bytes<X>;
/** Parse a hex-encoded fixed-length bytes without `0x` prefix. */
static parseBytesNoPrefix<X extends number>(v: string, len: X): Bytes<X>;
/** Parse a hex-encoded fixed-length bytes with `0x` prefix. */
static parseBytes<X extends number>(v: string, len: X): Bytes<X>;
}
import { Bytes, BytesBlob } from "@typeberry/bytes";
import type { OpaqueHash } from "@typeberry/hash";
import { type Opaque } from "@typeberry/utils";
export type Hash = Bytes<32>;
export type StateKey = Opaque<Bytes<32>, "stateKey">;
export type StateKey = Opaque<OpaqueHash, "stateKey">;
export type TruncatedStateKey = Opaque<Bytes<31>, "stateKey">;
export type TrieHash = Opaque<Hash, "trie">;
export type ValueHash = Opaque<Hash, "trieValue">;
/**
* A state commitment.
*
* https://graypaper.fluffylabs.dev/#/387103d/0cb0000cb400
*/
export type TrieHash = Opaque<OpaqueHash, "trie">;
export type ValueHash = Opaque<OpaqueHash, "trieValue">;
/** Regular hash length */

@@ -48,2 +53,5 @@ export declare const HASH_BYTES = 32;

readonly data: Uint8Array;
constructor(
/** Exactly 512 bits / 64 bytes */
data?: Uint8Array);
/** Returns the type of the node */

@@ -50,0 +58,0 @@ getNodeType(): NodeType;

@@ -0,1 +1,2 @@

import { HashDictionary } from "@typeberry/collections";
import type { TrieHash, TrieNode } from "./nodes";

@@ -13,3 +14,3 @@ /**

readonly hasher: TrieHasher;
protected readonly nodes: Map<string, TrieNode>;
protected readonly nodes: HashDictionary<TrieHash, TrieNode>;
constructor(hasher: TrieHasher);

@@ -22,7 +23,7 @@ get(hash: TrieHash): TrieNode | null;

* Before calling `toString` the first bit is set to 0, to maintain compatibility
* with branch nodes, which have the left subtree stripped out of the first bit (since it's
* a branch node identifier).
* with branch nodes, which have the left subtree stripped out of the first bit
* (since it's a branch node identifier).
*
*/
protected static hashCompatStr(hash: TrieHash): string;
protected static withHashCompat<T>(hash: TrieHash, exe: (hash: TrieHash) => T): T;
}

@@ -29,0 +30,0 @@ /**

@@ -11,4 +11,5 @@ import { type BytesBlob } from "@typeberry/bytes";

set(key: StateKey, value: BytesBlob, maybeValueHash?: TrieHash): void;
remove(_: StateKey): void;
getRoot(): TrieHash;
toString(): string;
}

@@ -19,1 +19,5 @@ /**

export declare function ensure<T, U extends T>(a: T, condition: boolean, message?: string): U;
/** A class that adds `toString` method that prints all properties of an object. */
export declare abstract class WithDebug {
toString(): string;
}

@@ -15,1 +15,2 @@ /**

export * from "./opaque";
export * from "./result";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc