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-2cf3b53 to 0.0.1-386317e

index.d.ts

68

index.js

@@ -35,11 +35,40 @@ 'use strict';

}
/** Decode contained bytes as string. */
asText() {
const decoder = new TextDecoder();
return decoder.decode(this.buffer);
}
/** Compare the sequence to another one. */
isEqualTo(other) {
if (this.length !== other.length) {
return false;
}
for (let i = 0; i < this.length; i++) {
if (this.buffer[i] !== other.buffer[i]) {
return false;
}
}
return true;
}
/** Create a new [`BytesBlob'] by converting given UTF-u encoded string into bytes. */
static fromString(v) {
const encoder = new TextEncoder();
return BytesBlob.fromBlob(encoder.encode(v));
return BytesBlob.from(encoder.encode(v));
}
/** Create a new [`BytesBlob`] from existing [`Uint8Array`]. */
static fromBlob(v) {
static from(v) {
return new BytesBlob(v);
}
/** Create a new [`BytesBlob`] by concatenating data from multiple `Uint8Array`s. */
static copyFromBlobs(v, ...rest) {
const totalLength = v.length + rest.reduce((a, v) => a + v.length, 0);
const buffer = new Uint8Array(totalLength);
buffer.set(v, 0);
let offset = v.length;
for (const r of rest) {
buffer.set(r, offset);
offset += r.length;
}
return new BytesBlob(buffer);
}
/** Create a new [`BytesBlob`] from an array of bytes. */

@@ -76,24 +105,12 @@ static fromNumbers(v) {

*/
class Bytes {
class Bytes extends BytesBlob {
constructor(raw, len) {
super(raw);
check(raw.byteLength === len, `Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`);
this.raw = raw;
this.length = len;
}
/** Return hex encoding of the sequence. */
toString() {
return bytesToHexString(this.raw);
/** Raw bytes array. */
get raw() {
return this.buffer;
}
/** Compare the sequence to another one. */
isEqualTo(other) {
if (this.length !== other.length) {
return false;
}
for (let i = 0; i < this.length; i++) {
if (this.raw[i] !== other.raw[i]) {
return false;
}
}
return true;
}
/** Create new [`Bytes<X>`] given a backing buffer and it's length. */

@@ -268,5 +285,6 @@ static fromBlob(v, len) {

class TrieNode {
constructor() {
/** Exactly 512 bits / 64 bytes */
this.data = new Uint8Array(64);
constructor(
/** Exactly 512 bits / 64 bytes */
data = new Uint8Array(64)) {
this.data = data;
}

@@ -392,3 +410,3 @@ /** Returns the type of the node */

const len = this.getValueLength();
return BytesBlob.fromBlob(this.node.data.subarray(HASH_BYTES, HASH_BYTES + len));
return BytesBlob.from(this.node.data.subarray(HASH_BYTES, HASH_BYTES + len));
}

@@ -414,2 +432,6 @@ /**

}
/** Return number of items in the dictionary. */
get size() {
return this.map.size;
}
/** Return true if the key is present in the dictionary. */

@@ -416,0 +438,0 @@ has(key) {

{
"name": "@typeberry/trie",
"version": "0.0.1-2cf3b53",
"version": "0.0.1-386317e",
"main": "index.js",

@@ -5,0 +5,0 @@ "author": "Fluffy Labs",

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