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

@helios-lang/codec-utils

Package Overview
Dependencies
Maintainers
0
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@helios-lang/codec-utils - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

2

package.json
{
"name": "@helios-lang/codec-utils",
"version": "0.3.2",
"version": "0.3.3",
"description": "Primitive manipulation functions commonly used in encoding and decoding algorithms",

@@ -5,0 +5,0 @@ "main": "src/index.js",

import { maskBits } from "./ops.js"
/**
* Read non-byte aligned numbers
* @typedef {{
* eof(): boolean
* moveToByteBoundary(force?: boolean): void
* readBits(n: number): number
* readByte(): number
* }} BitReader
* @import { BitReader } from "../index.js"
*/

@@ -12,0 +6,0 @@

import { padBits } from "./ops.js"
/**
* BitWriter turns a string of '0's and '1's into a list of bytes.
* Finalization pads the bits using '0*1' if not yet aligned with the byte boundary.
* @typedef {{
* length: number
* finalize(force?: boolean): number[]
* padToByteBoundary(force?: boolean): void
* pop(n: number): string
* writeBits(bitChars: string): BitWriter
* writeByte(byte: number): BitWriter
* }} BitWriter
* @import { BitWriter } from "../index.js"
*/

@@ -15,0 +6,0 @@

export { makeBitReader } from "./BitReader.js"
export { makeBitWriter } from "./BitWriter.js"
export { byteToBits, getBit, maskBits, padBits } from "./ops.js"
/**
* @typedef {import("./BitReader.js").BitReader} BitReader
* @typedef {import("./BitWriter.js").BitWriter} BitWriter
*/
import { makeBitReader, makeBitWriter, padBits } from "../bits/index.js"
/**
* @typedef {{
* alphabet: string
* padChar: string
* strict: boolean
* decode(encoded: string): number[]
* decodeRaw(encoded: string): number[]
* encode(bytes: number[]): string
* encodeRaw(bytes: number[]): number[]
* isValid(encoded: string): boolean
* }} Base32
* @import { Base32, Base32Props } from "../index.js"
*/
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
* @typedef {{
* alphabet?: string
* } | {
* alphabet?: string
* padChar: string
* strict?: boolean
* }} Base32Props
*/
export const BASE32_DEFAULT_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567"

@@ -108,57 +87,2 @@

/**
* Checks if all the characters in `s` are in the given base32 alphabet.
* Checks lengths if their pad characters at the end
* @param {string} encoded
* @returns {boolean}
*/
isValid(encoded) {
let n = encoded.length
if (
this.padChar.length == 1 &&
(this.strict || encoded.endsWith(this.padChar))
) {
if (encoded.length % 8 != 0) {
return false
}
const iPad = encoded.indexOf(this.padChar)
for (let i = iPad + 1; i < n; i++) {
if (encoded.at(i) != this.padChar) {
return false
}
}
const nPad = n - iPad
if (nPad != 6 && nPad != 4 && nPad != 3 && nPad != 1) {
return false
}
encoded = encoded.slice(0, iPad)
n = iPad
}
// the last char can't be any possible number
return encoded.split("").every((c, i) => {
const code = this.alphabet.indexOf(c.toLowerCase())
if (code < 0) {
return false
}
if (i == n - 1) {
const nBitsExtra = n * 5 - Math.floor((n * 5) / 8) * 8
return (((1 << nBitsExtra) - 1) & code) == 0
} else {
return true
}
})
}
/**
* @param {number[]} bytes

@@ -180,41 +104,3 @@ * @returns {number[]} list of numbers between 0 and 32

/**
* Trims the padding, asserting it is correctly formed
* @private
* @param {string} encoded
* @returns {string}
*/
trimPadding(encoded) {
if (this.padChar.length == 1) {
let n = encoded.length
while (n >= 0 && encoded.at(n - 1) == this.padChar) {
n -= 1
}
// length alignment is only checked if there are some padding characters at the end
if (
(this.strict || n < encoded.length) &&
encoded.length % 8 != 0
) {
throw new Error("invalid length (expected multiple of 8)")
}
const nPad = encoded.length - n
if (nPad != 0) {
if (nPad != 6 && nPad != 4 && nPad != 3 && nPad != 1) {
throw new Error(
"invalid number of base32 padding characters"
)
}
}
return encoded.slice(0, n)
} else {
return encoded
}
}
/**
* @param {string} encoded
* @returns {number[]} numbers between 0 and 32

@@ -308,2 +194,95 @@ */

}
/**
* Checks if all the characters in `encoded` are in the given base32 alphabet.
* Checks lengths if their pad characters at the end
* @param {string} encoded
* @returns {boolean}
*/
isValid(encoded) {
let n = encoded.length
if (
this.padChar.length == 1 &&
(this.strict || encoded.endsWith(this.padChar))
) {
if (encoded.length % 8 != 0) {
return false
}
const iPad = encoded.indexOf(this.padChar)
for (let i = iPad + 1; i < n; i++) {
if (encoded.at(i) != this.padChar) {
return false
}
}
const nPad = n - iPad
if (nPad != 6 && nPad != 4 && nPad != 3 && nPad != 1) {
return false
}
encoded = encoded.slice(0, iPad)
n = iPad
}
// the last char can't be any possible number
return encoded.split("").every((c, i) => {
const code = this.alphabet.indexOf(c.toLowerCase())
if (code < 0) {
return false
}
if (i == n - 1) {
const nBitsExtra = n * 5 - Math.floor((n * 5) / 8) * 8
return (((1 << nBitsExtra) - 1) & code) == 0
} else {
return true
}
})
}
/**
* Trims the padding, asserting it is correctly formed
* @private
* @param {string} encoded
* @returns {string}
*/
trimPadding(encoded) {
if (this.padChar.length == 1) {
let n = encoded.length
while (n >= 0 && encoded.at(n - 1) == this.padChar) {
n -= 1
}
// length alignment is only checked if there are some padding characters at the end
if (
(this.strict || n < encoded.length) &&
encoded.length % 8 != 0
) {
throw new Error("invalid length (expected multiple of 8)")
}
const nPad = encoded.length - n
if (nPad != 0) {
if (nPad != 6 && nPad != 4 && nPad != 3 && nPad != 1) {
throw new Error(
"invalid number of base32 padding characters"
)
}
}
return encoded.slice(0, n)
} else {
return encoded
}
}
}

@@ -310,0 +289,0 @@

import { makeBitReader, makeBitWriter, padBits } from "../bits/index.js"
/**
* @typedef {{
* alphabet: string
* padChar: string
* strict: boolean
* decode(encoded: string): number[]
* decodeRaw(encoded: string): number[]
* encode(bytes: number[]): string
* encodeRaw(bytes: number[]): number[]
* isValid(encoded: string): boolean
* }} Base64
* @import { Base64, Base64Props } from "../index.js"
*/
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
* @typedef {{
* alphabet?: string
* } | {
* alphabet?: string
* padChar: string
* strict?: boolean
* }} Base64Props
*/
/**
* Rfc 4648

@@ -36,2 +15,8 @@ * @type {string}

/**
* @type {string}
*/
export const BASE64_URL_SAFE_ALPHABET =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
/**
* Rfc 4648

@@ -38,0 +23,0 @@ * @type {string}

import { hexToBytes } from "./base16.js"
/**
* @typedef {string | number[] | {value: number[]} | {bytes: number[]} | Uint8Array} ByteArrayLike
* @import { ByteArrayLike } from "../index.js"
*/

@@ -6,0 +6,0 @@

import { hexToBytes } from "./base16.js"
/**
* @typedef {import("./ByteStream.js").ByteStream} ByteStream
* @typedef {import("./ByteArrayLike.js").ByteArrayLike} ByteArrayLike
* @import { BytesLike } from "../index.js"
*/
/**
* @typedef {ByteArrayLike | ByteStream} BytesLike
*/
/**
* Permissive conversion to bytes

@@ -14,0 +9,0 @@ * @param {BytesLike} b

import { toUint8Array } from "./ByteArrayLike.js"
/**
* @typedef {import("./ByteArrayLike.js").ByteArrayLike} ByteArrayLike
* @import { ByteArrayLike, ByteStream } from "../index.js"
*/
/**
* @typedef {{
* bytes: Uint8Array
* pos: number
* copy(): ByteStream
* isAtEnd(): boolean
* peekOne(): number
* peekMany(n: number): number[]
* peekRemaining(): number[]
* shiftOne(): number
* shiftMany(n: number): number[]
* shiftRemaining(): number[]
* }} ByteStream
*/
/**
* @param {ByteStream |
* ByteArrayLike | {
* bytes: ByteStream | ByteArrayLike
* } | {
* bytes: ByteArrayLike
* pos?: number
* }} args
* }} args
* @returns {ByteStream}

@@ -39,3 +21,3 @@ */

} else if ("pos" in args && "bytes" in args) {
return new ByteStreamImpl(toUint8Array(args.bytes), args.pos)
return args
} else if ("value" in args) {

@@ -54,8 +36,5 @@ return new ByteStreamImpl(toUint8Array(args))

} else if ("pos" in bytes && "bytes" in bytes) {
return new ByteStreamImpl(toUint8Array(bytes.bytes), bytes.pos)
return bytes
} else {
return new ByteStreamImpl(
toUint8Array(bytes),
"pos" in args ? args.pos : 0
)
return new ByteStreamImpl(toUint8Array(bytes), 0)
}

@@ -62,0 +41,0 @@ }

@@ -18,3 +18,4 @@ export { bytesToHex, hexToBytes, isValidHex } from "./base16.js"

BASE64_DEFAULT_PAD_CHAR,
BASE64_DEFAULT_PROPS
BASE64_DEFAULT_PROPS,
BASE64_URL_SAFE_ALPHABET
} from "./base64.js"

@@ -30,8 +31,1 @@ export { toBytes } from "./BytesLike.js"

} from "./ops.js"
/**
* @typedef {import("./base32.js").Base32} Base32
* @typedef {import("./base64.js").Base64} Base64
* @typedef {import("./BytesLike.js").BytesLike} BytesLike
* @typedef {import("./ByteStream.js").ByteStream} ByteStream
*/

@@ -68,11 +68,117 @@ export { segmentArray } from "./array/index.js"

/**
* @typedef {import("./bits/index.js").BitReader} BitReader
* @typedef {import("./bits/index.js").BitWriter} BitWriter
* @typedef {import("./bytes/index.js").Base32} Base32
* @typedef {import("./bytes/index.js").Base64} Base64
* @typedef {import("./bytes/index.js").BytesLike} BytesLike
* @typedef {import("./bytes/index.js").ByteStream} ByteStream
* @typedef {import("./int/index.js").IntLike} IntLike
* @typedef {import("./int/index.js").UInt64} UInt64
* @typedef {import("./string/index.js").StringWriter} StringWriter
* @typedef {object} Base32
* @prop {string} alphabet
* @prop {string} padChar
* @prop {boolean} strict
* @prop {(encoded: string) => number[]} decode
* @prop {(encoded: string) => number[]} decodeRaw
* @prop {(bytes: number[]) => string} encode
* @prop {(bytes: number[]) => number[]} encodeRaw
* @prop {(encoded: string) => boolean} isValid
*/
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
* @typedef {{
* alphabet?: string
* } | {
* alphabet?: string
* padChar: string
* strict?: boolean
* }} Base32Props
*/
/**
* @typedef {object} Base64
* @prop {string} alphabet
* @prop {string} padChar
* @prop {boolean} strict
* @prop {(encoded: string) => number[]} decode
* @prop {(encoded: string) => number[]} decodeRaw
* @prop {(bytes: number[]) => string} encode
* @prop {(bytes: number[]) => number[]} encodeRaw
* @prop {(encoded: string) => boolean} isValid
*/
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
* @typedef {{
* alphabet?: string
* } | {
* alphabet?: string
* padChar: string
* strict?: boolean
* }} Base64Props
*/
/**
* Read non-byte aligned numbers
* @typedef {object} BitReader
* @prop {() => boolean} eof
* @prop {(force?: boolean) => void} moveToByteBoundary
* @prop {(n: number) => number} readBits
* @prop {() => number} readByte
*/
/**
* BitWriter turns a string of '0's and '1's into a list of bytes.
* Finalization pads the bits using '0*1' if not yet aligned with the byte boundary.
* @typedef {object} BitWriter
* @prop {number} length
* @prop {(force?: boolean) => number[]} finalize
* @prop {(force?: boolean) => void} padToByteBoundary
* @prop {(n: number) => string} pop
* @prop {(bitChars: string) => BitWriter} writeBits
* @prop {(byte: number) => BitWriter} writeByte
*/
/**
* @typedef {string | number[] | {value: number[]} | {bytes: number[]} | Uint8Array} ByteArrayLike
*/
/**
* @typedef {ByteArrayLike | ByteStream} BytesLike
*/
/**
* @typedef {object} ByteStream
* @prop {Uint8Array} bytes
* @prop {number} pos
* @prop {() => ByteStream} copy
* @prop {() => boolean} isAtEnd
* @prop {() => number} peekOne
* @prop {(n: number) => number[]} peekMany
* @prop {() => number[]} peekRemaining
* @prop {() => number} shiftOne
* @prop {(n: number) => number[]} shiftMany
* @prop {() => number[]} shiftRemaining
*/
/**
* @typedef {number | bigint} IntLike
*/
/**
* @typedef {object} StringWriter
* @prop {() => string} finalize
* @prop {(part: string) => StringWriter} write
* @prop {(line: string) => StringWriter} writeLine
*/
/**
* UInt64 number (represented by 2 UInt32 numbers)
* If performance is very important: create an initial prototype of your algorithm using this class, and then inline all the operations (eg. how it was done for sha2_512)
* @typedef {object} UInt64
* @prop {number} high
* @prop {number} low
* @prop {(other: UInt64) => UInt64} add
* @prop {(other: UInt64) => UInt64} and
* @prop {(other: UInt64) => UInt64} xor
* @prop {(other: UInt64) => boolean} eq
* @prop {() => UInt64} not
* @prop {(n: number) => UInt64} rotr
* @prop {(n: number) => UInt64} shiftr
* @prop {(littleEndian?: boolean) => number[]} toBytes
*/
/**
* @typedef {import("./IntLike.js").IntLike} IntLike
* @import { IntLike } from "../index.js"
*/

@@ -4,0 +4,0 @@

/**
* @typedef {import("./IntLike.js").IntLike} IntLike
* @import { IntLike } from "../index.js"
*/

@@ -4,0 +4,0 @@

@@ -7,6 +7,1 @@ export { toInt } from "./IntLike.js"

export { decodeZigZag, encodeZigZag } from "./zigzag.js"
/**
* @typedef {import("./IntLike.js").IntLike} IntLike
* @typedef {import("./UInt64.js").UInt64} UInt64
*/
/**
* @typedef {number | bigint} IntLike
* @import { IntLike } from "../index.js"
*/

@@ -4,0 +4,0 @@

@@ -5,5 +5,5 @@ import { padBytes } from "../bytes/ops.js"

/**
* @typedef {import("./IntLike.js").IntLike} IntLike
*
* @import { IntLike } from "../index.js"
*/
/**

@@ -10,0 +10,0 @@ * Little Endian bytes to bigint (doesnt need to be 32 bytes long)

/**
* UInt64 number (represented by 2 UInt32 numbers)
* If performance is very important: create an initial prototype of your algorithm using this class, and then inline all the operations (eg. how it was done for sha2_512)
* @typedef {{
* high: number
* low: number
* add(other: UInt64): UInt64
* and(other: UInt64): UInt64
* xor(other: UInt64): UInt64
* eq(other: UInt64): boolean
* not(): UInt64
* rotr(n: number): UInt64
* shiftr(n: number): UInt64
* toBytes(littleEndian?: boolean): number[]
* }} UInt64
* @import { UInt64 } from "../index.js"
*/

@@ -17,0 +4,0 @@

/**
* @typedef {import("./IntLike.js").IntLike} IntLike
* @import { IntLike } from "../index.js"
*/

@@ -4,0 +4,0 @@

export { makeStringWriter } from "./StringWriter.js"
export { decodeUtf8, encodeUtf8, isValidUtf8 } from "./utf8.js"
export { removeWhitespace, replaceTabs } from "./whitespace.js"
/**
* @typedef {import("./StringWriter.js").StringWriter} StringWriter
*/
/**
* @typedef {{
* finalize(): string
* write(part: string): StringWriter
* writeLine(line: string): StringWriter
* }} StringWriter
* @import { StringWriter } from "../index.js"
*/

@@ -8,0 +4,0 @@

/**
* Read non-byte aligned numbers
* @typedef {{
* eof(): boolean
* moveToByteBoundary(force?: boolean): void
* readBits(n: number): number
* readByte(): number
* }} BitReader
* @import { BitReader } from "../index.js"
*/

@@ -22,11 +16,3 @@ /**

}): BitReader;
/**
* Read non-byte aligned numbers
*/
export type BitReader = {
eof(): boolean;
moveToByteBoundary(force?: boolean): void;
readBits(n: number): number;
readByte(): number;
};
import type { BitReader } from "../index.js";
//# sourceMappingURL=BitReader.d.ts.map
/**
* BitWriter turns a string of '0's and '1's into a list of bytes.
* Finalization pads the bits using '0*1' if not yet aligned with the byte boundary.
* @typedef {{
* length: number
* finalize(force?: boolean): number[]
* padToByteBoundary(force?: boolean): void
* pop(n: number): string
* writeBits(bitChars: string): BitWriter
* writeByte(byte: number): BitWriter
* }} BitWriter
* @import { BitWriter } from "../index.js"
*/

@@ -18,14 +9,3 @@ /**

export function makeBitWriter(_args?: {}): BitWriter;
/**
* BitWriter turns a string of '0's and '1's into a list of bytes.
* Finalization pads the bits using '0*1' if not yet aligned with the byte boundary.
*/
export type BitWriter = {
length: number;
finalize(force?: boolean): number[];
padToByteBoundary(force?: boolean): void;
pop(n: number): string;
writeBits(bitChars: string): BitWriter;
writeByte(byte: number): BitWriter;
};
import type { BitWriter } from "../index.js";
//# sourceMappingURL=BitWriter.d.ts.map
export { makeBitReader } from "./BitReader.js";
export { makeBitWriter } from "./BitWriter.js";
export type BitReader = import("./BitReader.js").BitReader;
export type BitWriter = import("./BitWriter.js").BitWriter;
export { byteToBits, getBit, maskBits, padBits } from "./ops.js";
//# sourceMappingURL=index.d.ts.map

@@ -26,24 +26,4 @@ /**

/**
* @typedef {{
* alphabet: string
* padChar: string
* strict: boolean
* decode(encoded: string): number[]
* decodeRaw(encoded: string): number[]
* encode(bytes: number[]): string
* encodeRaw(bytes: number[]): number[]
* isValid(encoded: string): boolean
* }} Base32
* @import { Base32, Base32Props } from "../index.js"
*/
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
* @typedef {{
* alphabet?: string
* } | {
* alphabet?: string
* padChar: string
* strict?: boolean
* }} Base32Props
*/
export const BASE32_DEFAULT_ALPHABET: "abcdefghijklmnopqrstuvwxyz234567";

@@ -56,23 +36,4 @@ export const BASE32_DEFAULT_PAD_CHAR: "=";

export const BASE32_DEFAULT_PROPS: Base32Props;
export type Base32 = {
alphabet: string;
padChar: string;
strict: boolean;
decode(encoded: string): number[];
decodeRaw(encoded: string): number[];
encode(bytes: number[]): string;
encodeRaw(bytes: number[]): number[];
isValid(encoded: string): boolean;
};
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
*/
export type Base32Props = {
alphabet?: string;
} | {
alphabet?: string;
padChar: string;
strict?: boolean;
};
import type { Base32Props } from "../index.js";
import type { Base32 } from "../index.js";
//# sourceMappingURL=base32.d.ts.map

@@ -23,25 +23,5 @@ /**

/**
* @typedef {{
* alphabet: string
* padChar: string
* strict: boolean
* decode(encoded: string): number[]
* decodeRaw(encoded: string): number[]
* encode(bytes: number[]): string
* encodeRaw(bytes: number[]): number[]
* isValid(encoded: string): boolean
* }} Base64
* @import { Base64, Base64Props } from "../index.js"
*/
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
* @typedef {{
* alphabet?: string
* } | {
* alphabet?: string
* padChar: string
* strict?: boolean
* }} Base64Props
*/
/**
* Rfc 4648

@@ -52,2 +32,6 @@ * @type {string}

/**
* @type {string}
*/
export const BASE64_URL_SAFE_ALPHABET: string;
/**
* Rfc 4648

@@ -62,23 +46,4 @@ * @type {string}

export const BASE64_DEFAULT_PROPS: Base64Props;
export type Base64 = {
alphabet: string;
padChar: string;
strict: boolean;
decode(encoded: string): number[];
decodeRaw(encoded: string): number[];
encode(bytes: number[]): string;
encodeRaw(bytes: number[]): number[];
isValid(encoded: string): boolean;
};
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
*/
export type Base64Props = {
alphabet?: string;
} | {
alphabet?: string;
padChar: string;
strict?: boolean;
};
import type { Base64Props } from "../index.js";
import type { Base64 } from "../index.js";
//# sourceMappingURL=base64.d.ts.map
/**
* @typedef {string | number[] | {value: number[]} | {bytes: number[]} | Uint8Array} ByteArrayLike
* @import { ByteArrayLike } from "../index.js"
*/

@@ -9,7 +9,3 @@ /**

export function toUint8Array(bytes: ByteArrayLike): Uint8Array;
export type ByteArrayLike = string | number[] | {
value: number[];
} | {
bytes: number[];
} | Uint8Array;
import type { ByteArrayLike } from "../index.js";
//# sourceMappingURL=ByteArrayLike.d.ts.map
/**
* @typedef {import("./ByteStream.js").ByteStream} ByteStream
* @typedef {import("./ByteArrayLike.js").ByteArrayLike} ByteArrayLike
* @import { BytesLike } from "../index.js"
*/
/**
* @typedef {ByteArrayLike | ByteStream} BytesLike
*/
/**
* Permissive conversion to bytes

@@ -14,5 +10,3 @@ * @param {BytesLike} b

export function toBytes(b: BytesLike): number[];
export type ByteStream = import("./ByteStream.js").ByteStream;
export type ByteArrayLike = import("./ByteArrayLike.js").ByteArrayLike;
export type BytesLike = ByteArrayLike | ByteStream;
import type { BytesLike } from "../index.js";
//# sourceMappingURL=BytesLike.d.ts.map
/**
* @typedef {import("./ByteArrayLike.js").ByteArrayLike} ByteArrayLike
* @import { ByteArrayLike, ByteStream } from "../index.js"
*/
/**
* @typedef {{
* bytes: Uint8Array
* pos: number
* copy(): ByteStream
* isAtEnd(): boolean
* peekOne(): number
* peekMany(n: number): number[]
* peekRemaining(): number[]
* shiftOne(): number
* shiftMany(n: number): number[]
* shiftRemaining(): number[]
* }} ByteStream
*/
/**
* @param {ByteStream |
* ByteArrayLike | {
* bytes: ByteStream | ByteArrayLike
* } | {
* bytes: ByteArrayLike
* pos?: number
* }} args
* }} args
* @returns {ByteStream}

@@ -30,19 +13,5 @@ */

bytes: ByteStream | ByteArrayLike;
} | {
bytes: ByteArrayLike;
pos?: number;
}): ByteStream;
export type ByteArrayLike = import("./ByteArrayLike.js").ByteArrayLike;
export type ByteStream = {
bytes: Uint8Array;
pos: number;
copy(): ByteStream;
isAtEnd(): boolean;
peekOne(): number;
peekMany(n: number): number[];
peekRemaining(): number[];
shiftOne(): number;
shiftMany(n: number): number[];
shiftRemaining(): number[];
};
import type { ByteStream } from "../index.js";
import type { ByteArrayLike } from "../index.js";
//# sourceMappingURL=ByteStream.d.ts.map
export { toBytes } from "./BytesLike.js";
export { makeByteStream } from "./ByteStream.js";
export type Base32 = import("./base32.js").Base32;
export type Base64 = import("./base64.js").Base64;
export type BytesLike = import("./BytesLike.js").BytesLike;
export type ByteStream = import("./ByteStream.js").ByteStream;
export { bytesToHex, hexToBytes, isValidHex } from "./base16.js";
export { decodeBase32, encodeBase32, isValidBase32, makeBase32, BASE32_DEFAULT_ALPHABET, BASE32_DEFAULT_PAD_CHAR, BASE32_DEFAULT_PROPS } from "./base32.js";
export { decodeBase64, encodeBase64, isValidBase64, makeBase64, BASE64_DEFAULT_ALPHABET, BASE64_DEFAULT_PAD_CHAR, BASE64_DEFAULT_PROPS } from "./base64.js";
export { decodeBase64, encodeBase64, isValidBase64, makeBase64, BASE64_DEFAULT_ALPHABET, BASE64_DEFAULT_PAD_CHAR, BASE64_DEFAULT_PROPS, BASE64_URL_SAFE_ALPHABET } from "./base64.js";
export { compareBytes, dummyBytes, equalsBytes, padBytes, prepadBytes } from "./ops.js";
//# sourceMappingURL=index.d.ts.map
export { segmentArray } from "./array/index.js";
export type BitReader = import("./bits/index.js").BitReader;
export type BitWriter = import("./bits/index.js").BitWriter;
export type Base32 = import("./bytes/index.js").Base32;
export type Base64 = import("./bytes/index.js").Base64;
export type BytesLike = import("./bytes/index.js").BytesLike;
export type ByteStream = import("./bytes/index.js").ByteStream;
export type IntLike = import("./int/index.js").IntLike;
export type UInt64 = import("./int/index.js").UInt64;
export type StringWriter = import("./string/index.js").StringWriter;
export type Base32 = {
alphabet: string;
padChar: string;
strict: boolean;
decode: (encoded: string) => number[];
decodeRaw: (encoded: string) => number[];
encode: (bytes: number[]) => string;
encodeRaw: (bytes: number[]) => number[];
isValid: (encoded: string) => boolean;
};
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
*/
export type Base32Props = {
alphabet?: string;
} | {
alphabet?: string;
padChar: string;
strict?: boolean;
};
export type Base64 = {
alphabet: string;
padChar: string;
strict: boolean;
decode: (encoded: string) => number[];
decodeRaw: (encoded: string) => number[];
encode: (bytes: number[]) => string;
encodeRaw: (bytes: number[]) => number[];
isValid: (encoded: string) => boolean;
};
/**
* In the first case the encoding operates without padding (and encoded strings with padding are invalid)
* In the second case the padding character is specified. Strict defaults to false in which case unpadded encoded strings are also valid
*/
export type Base64Props = {
alphabet?: string;
} | {
alphabet?: string;
padChar: string;
strict?: boolean;
};
/**
* Read non-byte aligned numbers
*/
export type BitReader = {
eof: () => boolean;
moveToByteBoundary: (force?: boolean) => void;
readBits: (n: number) => number;
readByte: () => number;
};
/**
* BitWriter turns a string of '0's and '1's into a list of bytes.
* Finalization pads the bits using '0*1' if not yet aligned with the byte boundary.
*/
export type BitWriter = {
length: number;
finalize: (force?: boolean) => number[];
padToByteBoundary: (force?: boolean) => void;
pop: (n: number) => string;
writeBits: (bitChars: string) => BitWriter;
writeByte: (byte: number) => BitWriter;
};
export type ByteArrayLike = string | number[] | {
value: number[];
} | {
bytes: number[];
} | Uint8Array;
export type BytesLike = ByteArrayLike | ByteStream;
export type ByteStream = {
bytes: Uint8Array;
pos: number;
copy: () => ByteStream;
isAtEnd: () => boolean;
peekOne: () => number;
peekMany: (n: number) => number[];
peekRemaining: () => number[];
shiftOne: () => number;
shiftMany: (n: number) => number[];
shiftRemaining: () => number[];
};
export type IntLike = number | bigint;
export type StringWriter = {
finalize: () => string;
write: (part: string) => StringWriter;
writeLine: (line: string) => StringWriter;
};
/**
* UInt64 number (represented by 2 UInt32 numbers)
* If performance is very important: create an initial prototype of your algorithm using this class, and then inline all the operations (eg. how it was done for sha2_512)
*/
export type UInt64 = {
high: number;
low: number;
add: (other: UInt64) => UInt64;
and: (other: UInt64) => UInt64;
xor: (other: UInt64) => UInt64;
eq: (other: UInt64) => boolean;
not: () => UInt64;
rotr: (n: number) => UInt64;
shiftr: (n: number) => UInt64;
toBytes: (littleEndian?: boolean) => number[];
};
export { byteToBits, getBit, makeBitReader, makeBitWriter, maskBits, padBits } from "./bits/index.js";

@@ -12,0 +106,0 @@ export { bytesToHex, compareBytes, decodeBase32, decodeBase64, dummyBytes, encodeBase32, encodeBase64, equalsBytes, hexToBytes, isValidBase32, isValidBase64, isValidHex, makeBase32, makeBase64, makeByteStream, padBytes, prepadBytes, toBytes, BASE32_DEFAULT_ALPHABET, BASE32_DEFAULT_PAD_CHAR, BASE32_DEFAULT_PROPS, BASE64_DEFAULT_ALPHABET, BASE64_DEFAULT_PAD_CHAR, BASE64_DEFAULT_PROPS } from "./bytes/index.js";

@@ -16,3 +16,3 @@ /**

export function encodeBase58(x: IntLike): string;
export type IntLike = import("./IntLike.js").IntLike;
import type { IntLike } from "../index.js";
//# sourceMappingURL=base58.d.ts.map
/**
* @typedef {import("./IntLike.js").IntLike} IntLike
* @import { IntLike } from "../index.js"
*/

@@ -17,3 +17,3 @@ /**

export function decodeIntBE(bytes: number[] | Uint8Array): bigint;
export type IntLike = import("./IntLike.js").IntLike;
import type { IntLike } from "../index.js";
//# sourceMappingURL=be.d.ts.map
export { toInt } from "./IntLike.js";
export type IntLike = import("./IntLike.js").IntLike;
export type UInt64 = import("./UInt64.js").UInt64;
export { makeUInt64, makeUInt64Fast, UINT64_ZERO } from "./UInt64.js";

@@ -5,0 +3,0 @@ export { decodeBase58, encodeBase58 } from "./base58.js";

/**
* @typedef {number | bigint} IntLike
* @import { IntLike } from "../index.js"
*/

@@ -10,3 +10,3 @@ /**

export function toInt(arg: IntLike): number;
export type IntLike = number | bigint;
import type { IntLike } from "../index.js";
//# sourceMappingURL=IntLike.d.ts.map
/**
* @typedef {import("./IntLike.js").IntLike} IntLike
*
* @import { IntLike } from "../index.js"
*/

@@ -17,3 +16,3 @@ /**

export function encodeIntLE32(x: IntLike): number[];
export type IntLike = import("./IntLike.js").IntLike;
import type { IntLike } from "../index.js";
//# sourceMappingURL=le.d.ts.map
/**
* UInt64 number (represented by 2 UInt32 numbers)
* If performance is very important: create an initial prototype of your algorithm using this class, and then inline all the operations (eg. how it was done for sha2_512)
* @typedef {{
* high: number
* low: number
* add(other: UInt64): UInt64
* and(other: UInt64): UInt64
* xor(other: UInt64): UInt64
* eq(other: UInt64): boolean
* not(): UInt64
* rotr(n: number): UInt64
* shiftr(n: number): UInt64
* toBytes(littleEndian?: boolean): number[]
* }} UInt64
* @import { UInt64 } from "../index.js"
*/

@@ -49,18 +36,3 @@ /**

export const UINT64_ZERO: UInt64;
/**
* UInt64 number (represented by 2 UInt32 numbers)
* If performance is very important: create an initial prototype of your algorithm using this class, and then inline all the operations (eg. how it was done for sha2_512)
*/
export type UInt64 = {
high: number;
low: number;
add(other: UInt64): UInt64;
and(other: UInt64): UInt64;
xor(other: UInt64): UInt64;
eq(other: UInt64): boolean;
not(): UInt64;
rotr(n: number): UInt64;
shiftr(n: number): UInt64;
toBytes(littleEndian?: boolean): number[];
};
import type { UInt64 } from "../index.js";
//# sourceMappingURL=UInt64.d.ts.map
/**
* @typedef {import("./IntLike.js").IntLike} IntLike
* @import { IntLike } from "../index.js"
*/

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

export function decodeZigZag(x: IntLike): bigint;
export type IntLike = import("./IntLike.js").IntLike;
import type { IntLike } from "../index.js";
//# sourceMappingURL=zigzag.d.ts.map
export { makeStringWriter } from "./StringWriter.js";
export type StringWriter = import("./StringWriter.js").StringWriter;
export { decodeUtf8, encodeUtf8, isValidUtf8 } from "./utf8.js";
export { removeWhitespace, replaceTabs } from "./whitespace.js";
//# sourceMappingURL=index.d.ts.map
/**
* @typedef {{
* finalize(): string
* write(part: string): StringWriter
* writeLine(line: string): StringWriter
* }} StringWriter
* @import { StringWriter } from "../index.js"
*/

@@ -13,7 +9,3 @@ /**

export function makeStringWriter(_args?: {}): StringWriter;
export type StringWriter = {
finalize(): string;
write(part: string): StringWriter;
writeLine(line: string): StringWriter;
};
import type { StringWriter } from "../index.js";
//# sourceMappingURL=StringWriter.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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