New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@solana/codecs-strings

Package Overview
Dependencies
Maintainers
14
Versions
1211
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/codecs-strings - npm Package Compare versions

Comparing version 2.0.0-experimental.8894dc1 to 2.0.0-experimental.89b469e

259

dist/index.browser.js

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

import { combineCodec, fixEncoder, mergeBytes, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { createEncoder, createDecoder, combineCodec, fixEncoder, getEncodedSize, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { getU32Encoder, getU32Decoder } from '@solana/codecs-numbers';

@@ -11,23 +11,20 @@

var getBaseXEncoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
description: `base${base}`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => {
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "")
return value.length;
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
},
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
const chars = [...value];
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
const leadingZeroes = Array(trailIndex).fill(0);
if (trailIndex === chars.length)
return Uint8Array.from(leadingZeroes);
const tailChars = chars.slice(trailIndex);
let base10Number = 0n;
let baseXPower = 1n;
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
baseXPower *= baseBigInt;
return offset;
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "") {
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
return offset + leadingZeroes.length;
}
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
const tailBytes = [];

@@ -38,13 +35,11 @@ while (base10Number > 0n) {

}
return Uint8Array.from(leadingZeroes.concat(tailBytes));
},
fixedSize: null,
maxSize: null
};
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
decode(rawBytes, offset = 0) {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -58,16 +53,26 @@ if (bytes.length === 0)

return [leadingZeroes, rawBytes.length];
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = [];
while (base10Number > 0n) {
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
base10Number /= baseBigInt;
}
return [leadingZeroes + tailChars.join(""), rawBytes.length];
},
description: `base${base}`,
fixedSize: null,
maxSize: null
};
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
return [leadingZeroes + tailChars, rawBytes.length];
}
});
};
var getBaseXCodec = (alphabet4) => combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
function partitionLeadingZeroes(value, zeroCharacter) {
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
}
function getBaseXFromBigInt(value, alphabet4) {
const base = BigInt(alphabet4.length);
const tailChars = [];
while (value > 0n) {
tailChars.unshift(alphabet4[Number(value % base)]);
value /= base;
}
return tailChars.join("");
}

@@ -79,21 +84,18 @@ // src/base10.ts

var getBase10Codec = () => getBaseXCodec(alphabet);
var getBase16Encoder = () => ({
description: "base16",
encode(value) {
var getBase16Encoder = () => createEncoder({
getSizeFromValue: (value) => Math.ceil(value.length / 2),
write(value, bytes, offset) {
const lowercaseValue = value.toLowerCase();
assertValidBaseString("0123456789abcdef", lowercaseValue, value);
const matches = lowercaseValue.match(/.{1,2}/g);
return Uint8Array.from(matches ? matches.map((byte) => parseInt(byte, 16)) : []);
},
fixedSize: null,
maxSize: null
const hexBytes = matches ? matches.map((byte) => parseInt(byte, 16)) : [];
bytes.set(hexBytes, offset);
return hexBytes.length + offset;
}
});
var getBase16Decoder = () => ({
decode(bytes, offset = 0) {
var getBase16Decoder = () => createDecoder({
read(bytes, offset) {
const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
return [value, bytes.length];
},
description: "base16",
fixedSize: null,
maxSize: null
}
});

@@ -107,16 +109,16 @@ var getBase16Codec = () => combineCodec(getBase16Encoder(), getBase16Decoder());

var getBase58Codec = () => getBaseXCodec(alphabet2);
var getBaseXResliceEncoder = (alphabet4, bits) => ({
description: `base${alphabet4.length}`,
encode(value) {
var getBaseXResliceEncoder = (alphabet4, bits) => createEncoder({
getSizeFromValue: (value) => Math.floor(value.length * bits / 8),
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
return offset;
const charIndices = [...value].map((c) => alphabet4.indexOf(c));
return new Uint8Array(reslice(charIndices, bits, 8, false));
},
fixedSize: null,
maxSize: null
const reslicedBytes = reslice(charIndices, bits, 8, false);
bytes.set(reslicedBytes, offset);
return reslicedBytes.length + offset;
}
});
var getBaseXResliceDecoder = (alphabet4, bits) => ({
decode(rawBytes, offset = 0) {
var getBaseXResliceDecoder = (alphabet4, bits) => createDecoder({
read(rawBytes, offset = 0) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -127,6 +129,3 @@ if (bytes.length === 0)

return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
},
description: `base${alphabet4.length}`,
fixedSize: null,
maxSize: null
}
});

@@ -154,8 +153,6 @@ var getBaseXResliceCodec = (alphabet4, bits) => combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));

{
return {
description: `base64`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => {
try {
const bytes = atob(value).split("").map((c) => c.charCodeAt(0));
return new Uint8Array(bytes);
return atob(value).length;
} catch (e2) {

@@ -165,5 +162,12 @@ throw new Error(`Expected a string of base 64, got [${value}].`);

},
fixedSize: null,
maxSize: null
};
write(value, bytes, offset) {
try {
const bytesToAdd = atob(value).split("").map((c) => c.charCodeAt(0));
bytes.set(bytesToAdd, offset);
return bytesToAdd.length + offset;
} catch (e2) {
throw new Error(`Expected a string of base 64, got [${value}].`);
}
}
});
}

@@ -173,12 +177,9 @@ };

{
return {
decode(bytes, offset = 0) {
return createDecoder({
read(bytes, offset = 0) {
const slice = bytes.slice(offset);
const value = btoa(String.fromCharCode(...slice));
return [value, bytes.length];
},
description: `base64`,
fixedSize: null,
maxSize: null
};
}
});
}

@@ -202,20 +203,19 @@ };

let textEncoder;
return {
description: "utf8",
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
fixedSize: null,
maxSize: null
};
return createEncoder({
getSizeFromValue: (value) => (textEncoder ||= new o()).encode(value).length,
write: (value, bytes, offset) => {
const bytesToAdd = (textEncoder ||= new o()).encode(value);
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getUtf8Decoder = () => {
let textDecoder;
return {
decode(bytes, offset = 0) {
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
return createDecoder({
read(bytes, offset) {
const value = (textDecoder ||= new e()).decode(bytes.slice(offset));
return [removeNullCharacters(value), bytes.length];
},
description: "utf8",
fixedSize: null,
maxSize: null
};
}
});
};

@@ -225,37 +225,36 @@ var getUtf8Codec = () => combineCodec(getUtf8Encoder(), getUtf8Decoder());

// src/string.ts
var getStringEncoder = (options = {}) => {
const size = options.size ?? getU32Encoder();
const encoding = options.encoding ?? getUtf8Encoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
function getStringEncoder(config = {}) {
const size = config.size ?? getU32Encoder();
const encoding = config.encoding ?? getUtf8Encoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixEncoder(encoding, size, description);
return fixEncoder(encoding, size);
}
return {
description,
encode: (value) => {
const contentBytes = encoding.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
return createEncoder({
getSizeFromValue: (value) => {
const contentSize = getEncodedSize(value, encoding);
return getEncodedSize(contentSize, size) + contentSize;
},
fixedSize: null,
maxSize: null
};
};
var getStringDecoder = (options = {}) => {
const size = options.size ?? getU32Decoder();
const encoding = options.encoding ?? getUtf8Decoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
write: (value, bytes, offset) => {
const contentSize = getEncodedSize(value, encoding);
offset = size.write(contentSize, bytes, offset);
return encoding.write(value, bytes, offset);
}
});
}
function getStringDecoder(config = {}) {
const size = config.size ?? getU32Decoder();
const encoding = config.encoding ?? getUtf8Decoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixDecoder(encoding, size, description);
return fixDecoder(encoding, size);
}
return {
decode: (bytes, offset = 0) => {
return createDecoder({
read: (bytes, offset = 0) => {
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
const length = Number(lengthBigInt);

@@ -265,18 +264,12 @@ offset = lengthOffset;

assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
const [value, contentOffset] = encoding.decode(contentBytes);
const [value, contentOffset] = encoding.read(contentBytes, 0);
offset += contentOffset;
return [value, offset];
},
description,
fixedSize: null,
maxSize: null
};
};
var getStringCodec = (options = {}) => combineCodec(getStringEncoder(options), getStringDecoder(options));
function getSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
});
}
function getStringCodec(config = {}) {
return combineCodec(getStringEncoder(config), getStringDecoder(config));
}
export { assertValidBaseString, getBase10Codec, getBase10Decoder, getBase10Encoder, getBase16Codec, getBase16Decoder, getBase16Encoder, getBase58Codec, getBase58Decoder, getBase58Encoder, getBase64Codec, getBase64Decoder, getBase64Encoder, getBaseXCodec, getBaseXDecoder, getBaseXEncoder, getBaseXResliceCodec, getBaseXResliceDecoder, getBaseXResliceEncoder, getStringCodec, getStringDecoder, getStringEncoder, getUtf8Codec, getUtf8Decoder, getUtf8Encoder, padNullCharacters, removeNullCharacters };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

@@ -24,19 +24,2 @@ this.globalThis = this.globalThis || {};

}
var mergeBytes = (byteArrays) => {
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
if (nonEmptyByteArrays.length === 0) {
return byteArrays.length ? byteArrays[0] : new Uint8Array();
}
if (nonEmptyByteArrays.length === 1) {
return nonEmptyByteArrays[0];
}
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
const result = new Uint8Array(totalLength);
let offset = 0;
nonEmptyByteArrays.forEach((arr) => {
result.set(arr, offset);
offset += arr.length;
});
return result;
};
var padBytes = (bytes, length) => {

@@ -50,4 +33,29 @@ if (bytes.length >= length)

var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
function combineCodec(encoder, decoder, description) {
if (encoder.fixedSize !== decoder.fixedSize) {
function getEncodedSize(value, encoder) {
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
}
function createEncoder(encoder) {
return Object.freeze({
...encoder,
encode: (value) => {
const bytes = new Uint8Array(getEncodedSize(value, encoder));
encoder.write(value, bytes, 0);
return bytes;
}
});
}
function createDecoder(decoder) {
return Object.freeze({
...decoder,
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
});
}
function isFixedSize(codec) {
return "fixedSize" in codec && typeof codec.fixedSize === "number";
}
function combineCodec(encoder, decoder) {
if (isFixedSize(encoder) !== isFixedSize(decoder)) {
throw new Error(`Encoder and decoder must either both be fixed-size or variable-size.`);
}
if (isFixedSize(encoder) && isFixedSize(decoder) && encoder.fixedSize !== decoder.fixedSize) {
throw new Error(

@@ -57,3 +65,3 @@ `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`

}
if (encoder.maxSize !== decoder.maxSize) {
if (!isFixedSize(encoder) && !isFixedSize(decoder) && encoder.maxSize !== decoder.maxSize) {
throw new Error(

@@ -63,32 +71,26 @@ `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`

}
if (description === void 0 && encoder.description !== decoder.description) {
throw new Error(
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
);
}
return {
...decoder,
...encoder,
decode: decoder.decode,
description: description ?? encoder.description,
encode: encoder.encode,
fixedSize: encoder.fixedSize,
maxSize: encoder.maxSize
read: decoder.read,
write: encoder.write
};
}
function fixCodecHelper(data, fixedBytes, description) {
return {
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
function fixEncoder(encoder, fixedBytes) {
return createEncoder({
fixedSize: fixedBytes,
maxSize: fixedBytes
};
write: (value, bytes, offset) => {
const variableByteArray = encoder.encode(value);
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
bytes.set(fixedByteArray, offset);
return offset + fixedBytes;
}
});
}
function fixEncoder(encoder, fixedBytes, description) {
return {
...fixCodecHelper(encoder, fixedBytes, description),
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
};
}
function fixDecoder(decoder, fixedBytes, description) {
return {
...fixCodecHelper(decoder, fixedBytes, description),
decode: (bytes, offset = 0) => {
function fixDecoder(decoder, fixedBytes) {
return createDecoder({
fixedSize: fixedBytes,
read: (bytes, offset) => {
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);

@@ -98,9 +100,9 @@ if (offset > 0 || bytes.length > fixedBytes) {

}
if (decoder.fixedSize !== null) {
if (isFixedSize(decoder)) {
bytes = fixBytes(bytes, decoder.fixedSize);
}
const [value] = decoder.decode(bytes, 0);
const [value] = decoder.read(bytes, 0);
return [value, offset + fixedBytes];
}
};
});
}

@@ -110,23 +112,20 @@

var getBaseXEncoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
description: `base${base}`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => {
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "")
return value.length;
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
},
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
const chars = [...value];
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
const leadingZeroes = Array(trailIndex).fill(0);
if (trailIndex === chars.length)
return Uint8Array.from(leadingZeroes);
const tailChars = chars.slice(trailIndex);
let base10Number = 0n;
let baseXPower = 1n;
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
baseXPower *= baseBigInt;
return offset;
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "") {
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
return offset + leadingZeroes.length;
}
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
const tailBytes = [];

@@ -137,13 +136,11 @@ while (base10Number > 0n) {

}
return Uint8Array.from(leadingZeroes.concat(tailBytes));
},
fixedSize: null,
maxSize: null
};
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
decode(rawBytes, offset = 0) {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -157,16 +154,26 @@ if (bytes.length === 0)

return [leadingZeroes, rawBytes.length];
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = [];
while (base10Number > 0n) {
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
base10Number /= baseBigInt;
}
return [leadingZeroes + tailChars.join(""), rawBytes.length];
},
description: `base${base}`,
fixedSize: null,
maxSize: null
};
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
return [leadingZeroes + tailChars, rawBytes.length];
}
});
};
var getBaseXCodec = (alphabet4) => combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
function partitionLeadingZeroes(value, zeroCharacter) {
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
}
function getBaseXFromBigInt(value, alphabet4) {
const base = BigInt(alphabet4.length);
const tailChars = [];
while (value > 0n) {
tailChars.unshift(alphabet4[Number(value % base)]);
value /= base;
}
return tailChars.join("");
}

@@ -180,21 +187,18 @@ // src/base10.ts

// src/base16.ts
var getBase16Encoder = () => ({
description: "base16",
encode(value) {
var getBase16Encoder = () => createEncoder({
getSizeFromValue: (value) => Math.ceil(value.length / 2),
write(value, bytes, offset) {
const lowercaseValue = value.toLowerCase();
assertValidBaseString("0123456789abcdef", lowercaseValue, value);
const matches = lowercaseValue.match(/.{1,2}/g);
return Uint8Array.from(matches ? matches.map((byte) => parseInt(byte, 16)) : []);
},
fixedSize: null,
maxSize: null
const hexBytes = matches ? matches.map((byte) => parseInt(byte, 16)) : [];
bytes.set(hexBytes, offset);
return hexBytes.length + offset;
}
});
var getBase16Decoder = () => ({
decode(bytes, offset = 0) {
var getBase16Decoder = () => createDecoder({
read(bytes, offset) {
const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
return [value, bytes.length];
},
description: "base16",
fixedSize: null,
maxSize: null
}
});

@@ -210,16 +214,16 @@ var getBase16Codec = () => combineCodec(getBase16Encoder(), getBase16Decoder());

// src/baseX-reslice.ts
var getBaseXResliceEncoder = (alphabet4, bits) => ({
description: `base${alphabet4.length}`,
encode(value) {
var getBaseXResliceEncoder = (alphabet4, bits) => createEncoder({
getSizeFromValue: (value) => Math.floor(value.length * bits / 8),
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
return offset;
const charIndices = [...value].map((c) => alphabet4.indexOf(c));
return new Uint8Array(reslice(charIndices, bits, 8, false));
},
fixedSize: null,
maxSize: null
const reslicedBytes = reslice(charIndices, bits, 8, false);
bytes.set(reslicedBytes, offset);
return reslicedBytes.length + offset;
}
});
var getBaseXResliceDecoder = (alphabet4, bits) => ({
decode(rawBytes, offset = 0) {
var getBaseXResliceDecoder = (alphabet4, bits) => createDecoder({
read(rawBytes, offset = 0) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -230,6 +234,3 @@ if (bytes.length === 0)

return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
},
description: `base${alphabet4.length}`,
fixedSize: null,
maxSize: null
}
});

@@ -257,8 +258,6 @@ var getBaseXResliceCodec = (alphabet4, bits) => combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));

{
return {
description: `base64`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => {
try {
const bytes = atob(value).split("").map((c) => c.charCodeAt(0));
return new Uint8Array(bytes);
return atob(value).length;
} catch (e2) {

@@ -268,5 +267,12 @@ throw new Error(`Expected a string of base 64, got [${value}].`);

},
fixedSize: null,
maxSize: null
};
write(value, bytes, offset) {
try {
const bytesToAdd = atob(value).split("").map((c) => c.charCodeAt(0));
bytes.set(bytesToAdd, offset);
return bytesToAdd.length + offset;
} catch (e2) {
throw new Error(`Expected a string of base 64, got [${value}].`);
}
}
});
}

@@ -276,12 +282,9 @@ };

{
return {
decode(bytes, offset = 0) {
return createDecoder({
read(bytes, offset = 0) {
const slice = bytes.slice(offset);
const value = btoa(String.fromCharCode(...slice));
return [value, bytes.length];
},
description: `base64`,
fixedSize: null,
maxSize: null
};
}
});
}

@@ -306,21 +309,9 @@ };

}
function sharedNumberFactory(input) {
let littleEndian;
let defaultDescription = input.name;
if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === 0;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
return {
description: input.options.description ?? defaultDescription,
fixedSize: input.size,
littleEndian,
maxSize: input.size
};
function isLittleEndian(config) {
return (config == null ? void 0 : config.endian) === 1 ? false : true;
}
function numberEncoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
description: codecData.description,
encode(value) {
return createEncoder({
fixedSize: input.size,
write(value, bytes, offset) {
if (input.range) {

@@ -330,31 +321,27 @@ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);

const arrayBuffer = new ArrayBuffer(input.size);
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
return new Uint8Array(arrayBuffer);
},
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
bytes.set(new Uint8Array(arrayBuffer), offset);
return offset + input.size;
}
});
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
return createDecoder({
fixedSize: input.size,
read(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
return [input.get(view, codecData.littleEndian), offset + input.size];
},
description: codecData.description,
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
}
});
}
function toArrayBuffer(bytes, offset, length) {
const bytesOffset = bytes.byteOffset + (offset ?? 0);
const bytesLength = length ?? bytes.byteLength;
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
const bytesLength = length != null ? length : bytes.byteLength;
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
}
var getU32Encoder = (options = {}) => numberEncoderFactory({
var getU32Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u32",
options,
range: [0, Number("0xffffffff")],

@@ -364,6 +351,6 @@ set: (view, value, le) => view.setUint32(0, value, le),

});
var getU32Decoder = (options = {}) => numberDecoderFactory({
var getU32Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view, le) => view.getUint32(0, le),
name: "u32",
options,
size: 4

@@ -379,20 +366,19 @@ });

let textEncoder;
return {
description: "utf8",
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
fixedSize: null,
maxSize: null
};
return createEncoder({
getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
write: (value, bytes, offset) => {
const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getUtf8Decoder = () => {
let textDecoder;
return {
decode(bytes, offset = 0) {
return createDecoder({
read(bytes, offset) {
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
return [removeNullCharacters(value), bytes.length];
},
description: "utf8",
fixedSize: null,
maxSize: null
};
}
});
};

@@ -402,37 +388,38 @@ var getUtf8Codec = () => combineCodec(getUtf8Encoder(), getUtf8Decoder());

// src/string.ts
var getStringEncoder = (options = {}) => {
const size = options.size ?? getU32Encoder();
const encoding = options.encoding ?? getUtf8Encoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
function getStringEncoder(config = {}) {
var _a, _b;
const size = (_a = config.size) != null ? _a : getU32Encoder();
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixEncoder(encoding, size, description);
return fixEncoder(encoding, size);
}
return {
description,
encode: (value) => {
const contentBytes = encoding.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
return createEncoder({
getSizeFromValue: (value) => {
const contentSize = getEncodedSize(value, encoding);
return getEncodedSize(contentSize, size) + contentSize;
},
fixedSize: null,
maxSize: null
};
};
var getStringDecoder = (options = {}) => {
const size = options.size ?? getU32Decoder();
const encoding = options.encoding ?? getUtf8Decoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
write: (value, bytes, offset) => {
const contentSize = getEncodedSize(value, encoding);
offset = size.write(contentSize, bytes, offset);
return encoding.write(value, bytes, offset);
}
});
}
function getStringDecoder(config = {}) {
var _a, _b;
const size = (_a = config.size) != null ? _a : getU32Decoder();
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixDecoder(encoding, size, description);
return fixDecoder(encoding, size);
}
return {
decode: (bytes, offset = 0) => {
return createDecoder({
read: (bytes, offset = 0) => {
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
const length = Number(lengthBigInt);

@@ -442,15 +429,11 @@ offset = lengthOffset;

assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
const [value, contentOffset] = encoding.decode(contentBytes);
const [value, contentOffset] = encoding.read(contentBytes, 0);
offset += contentOffset;
return [value, offset];
},
description,
fixedSize: null,
maxSize: null
};
};
var getStringCodec = (options = {}) => combineCodec(getStringEncoder(options), getStringDecoder(options));
function getSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
});
}
function getStringCodec(config = {}) {
return combineCodec(getStringEncoder(config), getStringDecoder(config));
}

@@ -457,0 +440,0 @@ exports.assertValidBaseString = assertValidBaseString;

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

import { combineCodec, mapEncoder, mapDecoder, fixEncoder, mergeBytes, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { createEncoder, createDecoder, combineCodec, mapEncoder, mapDecoder, fixEncoder, getEncodedSize, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { getU32Encoder, getU32Decoder } from '@solana/codecs-numbers';

@@ -11,23 +11,20 @@

var getBaseXEncoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
description: `base${base}`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => {
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "")
return value.length;
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
},
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
const chars = [...value];
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
const leadingZeroes = Array(trailIndex).fill(0);
if (trailIndex === chars.length)
return Uint8Array.from(leadingZeroes);
const tailChars = chars.slice(trailIndex);
let base10Number = 0n;
let baseXPower = 1n;
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
baseXPower *= baseBigInt;
return offset;
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "") {
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
return offset + leadingZeroes.length;
}
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
const tailBytes = [];

@@ -38,13 +35,11 @@ while (base10Number > 0n) {

}
return Uint8Array.from(leadingZeroes.concat(tailBytes));
},
fixedSize: null,
maxSize: null
};
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
decode(rawBytes, offset = 0) {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -58,16 +53,26 @@ if (bytes.length === 0)

return [leadingZeroes, rawBytes.length];
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = [];
while (base10Number > 0n) {
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
base10Number /= baseBigInt;
}
return [leadingZeroes + tailChars.join(""), rawBytes.length];
},
description: `base${base}`,
fixedSize: null,
maxSize: null
};
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
return [leadingZeroes + tailChars, rawBytes.length];
}
});
};
var getBaseXCodec = (alphabet4) => combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
function partitionLeadingZeroes(value, zeroCharacter) {
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
}
function getBaseXFromBigInt(value, alphabet4) {
const base = BigInt(alphabet4.length);
const tailChars = [];
while (value > 0n) {
tailChars.unshift(alphabet4[Number(value % base)]);
value /= base;
}
return tailChars.join("");
}

@@ -79,21 +84,18 @@ // src/base10.ts

var getBase10Codec = () => getBaseXCodec(alphabet);
var getBase16Encoder = () => ({
description: "base16",
encode(value) {
var getBase16Encoder = () => createEncoder({
getSizeFromValue: (value) => Math.ceil(value.length / 2),
write(value, bytes, offset) {
const lowercaseValue = value.toLowerCase();
assertValidBaseString("0123456789abcdef", lowercaseValue, value);
const matches = lowercaseValue.match(/.{1,2}/g);
return Uint8Array.from(matches ? matches.map((byte) => parseInt(byte, 16)) : []);
},
fixedSize: null,
maxSize: null
const hexBytes = matches ? matches.map((byte) => parseInt(byte, 16)) : [];
bytes.set(hexBytes, offset);
return hexBytes.length + offset;
}
});
var getBase16Decoder = () => ({
decode(bytes, offset = 0) {
var getBase16Decoder = () => createDecoder({
read(bytes, offset) {
const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
return [value, bytes.length];
},
description: "base16",
fixedSize: null,
maxSize: null
}
});

@@ -107,16 +109,16 @@ var getBase16Codec = () => combineCodec(getBase16Encoder(), getBase16Decoder());

var getBase58Codec = () => getBaseXCodec(alphabet2);
var getBaseXResliceEncoder = (alphabet4, bits) => ({
description: `base${alphabet4.length}`,
encode(value) {
var getBaseXResliceEncoder = (alphabet4, bits) => createEncoder({
getSizeFromValue: (value) => Math.floor(value.length * bits / 8),
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
return offset;
const charIndices = [...value].map((c) => alphabet4.indexOf(c));
return new Uint8Array(reslice(charIndices, bits, 8, false));
},
fixedSize: null,
maxSize: null
const reslicedBytes = reslice(charIndices, bits, 8, false);
bytes.set(reslicedBytes, offset);
return reslicedBytes.length + offset;
}
});
var getBaseXResliceDecoder = (alphabet4, bits) => ({
decode(rawBytes, offset = 0) {
var getBaseXResliceDecoder = (alphabet4, bits) => createDecoder({
read(rawBytes, offset = 0) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -127,6 +129,3 @@ if (bytes.length === 0)

return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
},
description: `base${alphabet4.length}`,
fixedSize: null,
maxSize: null
}
});

@@ -180,20 +179,19 @@ var getBaseXResliceCodec = (alphabet4, bits) => combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));

let textEncoder;
return {
description: "utf8",
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
fixedSize: null,
maxSize: null
};
return createEncoder({
getSizeFromValue: (value) => (textEncoder ||= new o()).encode(value).length,
write: (value, bytes, offset) => {
const bytesToAdd = (textEncoder ||= new o()).encode(value);
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getUtf8Decoder = () => {
let textDecoder;
return {
decode(bytes, offset = 0) {
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
return createDecoder({
read(bytes, offset) {
const value = (textDecoder ||= new e()).decode(bytes.slice(offset));
return [removeNullCharacters(value), bytes.length];
},
description: "utf8",
fixedSize: null,
maxSize: null
};
}
});
};

@@ -203,37 +201,36 @@ var getUtf8Codec = () => combineCodec(getUtf8Encoder(), getUtf8Decoder());

// src/string.ts
var getStringEncoder = (options = {}) => {
const size = options.size ?? getU32Encoder();
const encoding = options.encoding ?? getUtf8Encoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
function getStringEncoder(config = {}) {
const size = config.size ?? getU32Encoder();
const encoding = config.encoding ?? getUtf8Encoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixEncoder(encoding, size, description);
return fixEncoder(encoding, size);
}
return {
description,
encode: (value) => {
const contentBytes = encoding.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
return createEncoder({
getSizeFromValue: (value) => {
const contentSize = getEncodedSize(value, encoding);
return getEncodedSize(contentSize, size) + contentSize;
},
fixedSize: null,
maxSize: null
};
};
var getStringDecoder = (options = {}) => {
const size = options.size ?? getU32Decoder();
const encoding = options.encoding ?? getUtf8Decoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
write: (value, bytes, offset) => {
const contentSize = getEncodedSize(value, encoding);
offset = size.write(contentSize, bytes, offset);
return encoding.write(value, bytes, offset);
}
});
}
function getStringDecoder(config = {}) {
const size = config.size ?? getU32Decoder();
const encoding = config.encoding ?? getUtf8Decoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixDecoder(encoding, size, description);
return fixDecoder(encoding, size);
}
return {
decode: (bytes, offset = 0) => {
return createDecoder({
read: (bytes, offset = 0) => {
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
const length = Number(lengthBigInt);

@@ -243,15 +240,11 @@ offset = lengthOffset;

assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
const [value, contentOffset] = encoding.decode(contentBytes);
const [value, contentOffset] = encoding.read(contentBytes, 0);
offset += contentOffset;
return [value, offset];
},
description,
fixedSize: null,
maxSize: null
};
};
var getStringCodec = (options = {}) => combineCodec(getStringEncoder(options), getStringDecoder(options));
function getSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
});
}
function getStringCodec(config = {}) {
return combineCodec(getStringEncoder(config), getStringDecoder(config));
}

@@ -258,0 +251,0 @@ export { assertValidBaseString, getBase10Codec, getBase10Decoder, getBase10Encoder, getBase16Codec, getBase16Decoder, getBase16Encoder, getBase58Codec, getBase58Decoder, getBase58Encoder, getBase64Codec, getBase64Decoder, getBase64Encoder, getBaseXCodec, getBaseXDecoder, getBaseXEncoder, getBaseXResliceCodec, getBaseXResliceDecoder, getBaseXResliceEncoder, getStringCodec, getStringDecoder, getStringEncoder, getUtf8Codec, getUtf8Decoder, getUtf8Encoder, padNullCharacters, removeNullCharacters };

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

import { combineCodec, fixEncoder, mergeBytes, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { createEncoder, createDecoder, combineCodec, fixEncoder, getEncodedSize, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
import { getU32Encoder, getU32Decoder } from '@solana/codecs-numbers';

@@ -11,23 +11,20 @@

var getBaseXEncoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
description: `base${base}`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => {
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "")
return value.length;
const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
},
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
const chars = [...value];
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
const leadingZeroes = Array(trailIndex).fill(0);
if (trailIndex === chars.length)
return Uint8Array.from(leadingZeroes);
const tailChars = chars.slice(trailIndex);
let base10Number = 0n;
let baseXPower = 1n;
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
baseXPower *= baseBigInt;
return offset;
const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
if (tailChars === "") {
bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
return offset + leadingZeroes.length;
}
let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
const tailBytes = [];

@@ -38,13 +35,11 @@ while (base10Number > 0n) {

}
return Uint8Array.from(leadingZeroes.concat(tailBytes));
},
fixedSize: null,
maxSize: null
};
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
decode(rawBytes, offset = 0) {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -58,16 +53,26 @@ if (bytes.length === 0)

return [leadingZeroes, rawBytes.length];
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = [];
while (base10Number > 0n) {
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
base10Number /= baseBigInt;
}
return [leadingZeroes + tailChars.join(""), rawBytes.length];
},
description: `base${base}`,
fixedSize: null,
maxSize: null
};
const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
return [leadingZeroes + tailChars, rawBytes.length];
}
});
};
var getBaseXCodec = (alphabet4) => combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
function partitionLeadingZeroes(value, zeroCharacter) {
const leadingZeroIndex = [...value].findIndex((c) => c !== zeroCharacter);
return leadingZeroIndex === -1 ? [value, ""] : [value.slice(0, leadingZeroIndex), value.slice(leadingZeroIndex)];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
return [...value].reduce((sum, char) => sum * base + BigInt(alphabet4.indexOf(char)), 0n);
}
function getBaseXFromBigInt(value, alphabet4) {
const base = BigInt(alphabet4.length);
const tailChars = [];
while (value > 0n) {
tailChars.unshift(alphabet4[Number(value % base)]);
value /= base;
}
return tailChars.join("");
}

@@ -79,21 +84,18 @@ // src/base10.ts

var getBase10Codec = () => getBaseXCodec(alphabet);
var getBase16Encoder = () => ({
description: "base16",
encode(value) {
var getBase16Encoder = () => createEncoder({
getSizeFromValue: (value) => Math.ceil(value.length / 2),
write(value, bytes, offset) {
const lowercaseValue = value.toLowerCase();
assertValidBaseString("0123456789abcdef", lowercaseValue, value);
const matches = lowercaseValue.match(/.{1,2}/g);
return Uint8Array.from(matches ? matches.map((byte) => parseInt(byte, 16)) : []);
},
fixedSize: null,
maxSize: null
const hexBytes = matches ? matches.map((byte) => parseInt(byte, 16)) : [];
bytes.set(hexBytes, offset);
return hexBytes.length + offset;
}
});
var getBase16Decoder = () => ({
decode(bytes, offset = 0) {
var getBase16Decoder = () => createDecoder({
read(bytes, offset) {
const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
return [value, bytes.length];
},
description: "base16",
fixedSize: null,
maxSize: null
}
});

@@ -107,16 +109,16 @@ var getBase16Codec = () => combineCodec(getBase16Encoder(), getBase16Decoder());

var getBase58Codec = () => getBaseXCodec(alphabet2);
var getBaseXResliceEncoder = (alphabet4, bits) => ({
description: `base${alphabet4.length}`,
encode(value) {
var getBaseXResliceEncoder = (alphabet4, bits) => createEncoder({
getSizeFromValue: (value) => Math.floor(value.length * bits / 8),
write(value, bytes, offset) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
return offset;
const charIndices = [...value].map((c) => alphabet4.indexOf(c));
return new Uint8Array(reslice(charIndices, bits, 8, false));
},
fixedSize: null,
maxSize: null
const reslicedBytes = reslice(charIndices, bits, 8, false);
bytes.set(reslicedBytes, offset);
return reslicedBytes.length + offset;
}
});
var getBaseXResliceDecoder = (alphabet4, bits) => ({
decode(rawBytes, offset = 0) {
var getBaseXResliceDecoder = (alphabet4, bits) => createDecoder({
read(rawBytes, offset = 0) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);

@@ -127,6 +129,3 @@ if (bytes.length === 0)

return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
},
description: `base${alphabet4.length}`,
fixedSize: null,
maxSize: null
}
});

@@ -157,11 +156,11 @@ var getBaseXResliceCodec = (alphabet4, bits) => combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));

{
return {
description: `base64`,
encode(value) {
return createEncoder({
getSizeFromValue: (value) => Buffer.from(value, "base64").length,
write(value, bytes, offset) {
assertValidBaseString(alphabet3, value.replace(/=/g, ""));
return new Uint8Array(Buffer.from(value, "base64"));
},
fixedSize: null,
maxSize: null
};
const buffer = Buffer.from(value, "base64");
bytes.set(buffer, offset);
return buffer.length + offset;
}
});
}

@@ -171,8 +170,5 @@ };

{
return {
decode: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString("base64"), bytes.length],
description: `base64`,
fixedSize: null,
maxSize: null
};
return createDecoder({
read: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString("base64"), bytes.length]
});
}

@@ -196,20 +192,19 @@ };

let textEncoder;
return {
description: "utf8",
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
fixedSize: null,
maxSize: null
};
return createEncoder({
getSizeFromValue: (value) => (textEncoder ||= new o()).encode(value).length,
write: (value, bytes, offset) => {
const bytesToAdd = (textEncoder ||= new o()).encode(value);
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getUtf8Decoder = () => {
let textDecoder;
return {
decode(bytes, offset = 0) {
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
return createDecoder({
read(bytes, offset) {
const value = (textDecoder ||= new e()).decode(bytes.slice(offset));
return [removeNullCharacters(value), bytes.length];
},
description: "utf8",
fixedSize: null,
maxSize: null
};
}
});
};

@@ -219,37 +214,36 @@ var getUtf8Codec = () => combineCodec(getUtf8Encoder(), getUtf8Decoder());

// src/string.ts
var getStringEncoder = (options = {}) => {
const size = options.size ?? getU32Encoder();
const encoding = options.encoding ?? getUtf8Encoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
function getStringEncoder(config = {}) {
const size = config.size ?? getU32Encoder();
const encoding = config.encoding ?? getUtf8Encoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixEncoder(encoding, size, description);
return fixEncoder(encoding, size);
}
return {
description,
encode: (value) => {
const contentBytes = encoding.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
return createEncoder({
getSizeFromValue: (value) => {
const contentSize = getEncodedSize(value, encoding);
return getEncodedSize(contentSize, size) + contentSize;
},
fixedSize: null,
maxSize: null
};
};
var getStringDecoder = (options = {}) => {
const size = options.size ?? getU32Decoder();
const encoding = options.encoding ?? getUtf8Decoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
write: (value, bytes, offset) => {
const contentSize = getEncodedSize(value, encoding);
offset = size.write(contentSize, bytes, offset);
return encoding.write(value, bytes, offset);
}
});
}
function getStringDecoder(config = {}) {
const size = config.size ?? getU32Decoder();
const encoding = config.encoding ?? getUtf8Decoder();
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixDecoder(encoding, size, description);
return fixDecoder(encoding, size);
}
return {
decode: (bytes, offset = 0) => {
return createDecoder({
read: (bytes, offset = 0) => {
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
const length = Number(lengthBigInt);

@@ -259,15 +253,11 @@ offset = lengthOffset;

assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
const [value, contentOffset] = encoding.decode(contentBytes);
const [value, contentOffset] = encoding.read(contentBytes, 0);
offset += contentOffset;
return [value, offset];
},
description,
fixedSize: null,
maxSize: null
};
};
var getStringCodec = (options = {}) => combineCodec(getStringEncoder(options), getStringDecoder(options));
function getSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
});
}
function getStringCodec(config = {}) {
return combineCodec(getStringEncoder(config), getStringDecoder(config));
}

@@ -274,0 +264,0 @@ export { assertValidBaseString, getBase10Codec, getBase10Decoder, getBase10Encoder, getBase16Codec, getBase16Decoder, getBase16Encoder, getBase58Codec, getBase58Decoder, getBase58Encoder, getBase64Codec, getBase64Decoder, getBase64Encoder, getBaseXCodec, getBaseXDecoder, getBaseXEncoder, getBaseXResliceCodec, getBaseXResliceDecoder, getBaseXResliceEncoder, getStringCodec, getStringDecoder, getStringEncoder, getUtf8Codec, getUtf8Decoder, getUtf8Encoder, padNullCharacters, removeNullCharacters };

@@ -5,31 +5,31 @@ this.globalThis = this.globalThis || {};

function u(e,r,t=r){if(!r.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${t}].`)}function S(e,r,t=0){if(r.length-t<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function x(e,r,t,n=0){let i=t.length-n;if(i<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${i}.`)}var I=e=>{let r=e.filter(o=>o.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let t=r.reduce((o,c)=>o+c.length,0),n=new Uint8Array(t),i=0;return r.forEach(o=>{n.set(o,i),i+=o.length;}),n},H=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},U=(e,r)=>H(e.length<=r?e:e.slice(0,r),r);function d(e,r,t){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(t===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:t??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function y(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function w(e,r,t){return {...y(e,r,t),encode:n=>U(e.encode(n),r)}}function N(e,r,t){return {...y(e,r,t),decode:(n,i=0)=>{x("fixCodec",r,n,i),(i>0||n.length>r)&&(n=n.slice(i,i+r)),e.fixedSize!==null&&(n=U(n,e.fixedSize));let[o]=e.decode(n,0);return [o,i+r]}}}var z=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,encode(n){if(u(e,n),n==="")return new Uint8Array;let i=[...n],o=i.findIndex(g=>g!==e[0]);o=o===-1?i.length:o;let c=Array(o).fill(0);if(o===i.length)return Uint8Array.from(c);let a=i.slice(o),s=0n,m=1n;for(let g=a.length-1;g>=0;g-=1)s+=m*BigInt(e.indexOf(a[g])),m*=t;let l=[];for(;s>0n;)l.unshift(Number(s%256n)),s/=256n;return Uint8Array.from(c.concat(l))},fixedSize:null,maxSize:null}},p=e=>{let r=e.length,t=BigInt(r);return {decode(n,i=0){let o=i===0?n:n.slice(i);if(o.length===0)return ["",0];let c=o.findIndex(l=>l!==0);c=c===-1?o.length:c;let a=e[0].repeat(c);if(c===o.length)return [a,n.length];let s=o.slice(c).reduce((l,g)=>l*256n+BigInt(g),0n),m=[];for(;s>0n;)m.unshift(e[Number(s%t)]),s/=t;return [a+m.join(""),n.length]},description:`base${r}`,fixedSize:null,maxSize:null}},h=e=>d(z(e),p(e));var E="0123456789",me=()=>z(E),le=()=>p(E),ue=()=>h(E);var P=()=>({description:"base16",encode(e){let r=e.toLowerCase();u("0123456789abcdef",r,e);let t=r.match(/.{1,2}/g);return Uint8Array.from(t?t.map(n=>parseInt(n,16)):[])},fixedSize:null,maxSize:null}),W=()=>({decode(e,r=0){return [e.slice(r).reduce((n,i)=>n+i.toString(16).padStart(2,"0"),""),e.length]},description:"base16",fixedSize:null,maxSize:null}),Be=()=>d(P(),W());var C="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Ie=()=>z(C),Ue=()=>p(C),ye=()=>h(C);var B=(e,r)=>({description:`base${e.length}`,encode(t){if(u(e,t),t==="")return new Uint8Array;let n=[...t].map(i=>e.indexOf(i));return new Uint8Array(O(n,r,8,!1))},fixedSize:null,maxSize:null}),b=(e,r)=>({decode(t,n=0){let i=n===0?t:t.slice(n);return i.length===0?["",t.length]:[O([...i],8,r,!0).map(c=>e[c]).join(""),t.length]},description:`base${e.length}`,fixedSize:null,maxSize:null}),Te=(e,r)=>d(B(e,r),b(e,r));function O(e,r,t,n){let i=[],o=0,c=0,a=(1<<t)-1;for(let s of e)for(o=o<<r|s,c+=r;c>=t;)c-=t,i.push(o>>c&a);return n&&c>0&&i.push(o<<t-c&a),i}var j=()=>({description:"base64",encode(e){try{let r=atob(e).split("").map(t=>t.charCodeAt(0));return new Uint8Array(r)}catch{throw new Error(`Expected a string of base 64, got [${e}].`)}},fixedSize:null,maxSize:null}),M=()=>({decode(e,r=0){let t=e.slice(r);return [btoa(String.fromCharCode(...t)),e.length]},description:"base64",fixedSize:null,maxSize:null}),Pe=()=>d(j(),M());var _=e=>e.replace(/\u0000/g,""),Me=(e,r)=>e.padEnd(r,"\0");function G(e,r,t,n){if(n<r||n>t)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${t}], got ${n}.`)}function T(e){let r,t=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===0,t+=r?"(le)":"(be)"),{description:e.options.description??t,fixedSize:e.size,littleEndian:r,maxSize:e.size}}function J(e){let r=T(e);return {description:r.description,encode(t){e.range&&G(e.name,e.range[0],e.range[1],t);let n=new ArrayBuffer(e.size);return e.set(new DataView(n),t,r.littleEndian),new Uint8Array(n)},fixedSize:r.fixedSize,maxSize:r.maxSize}}function Z(e){let r=T(e);return {decode(t,n=0){S(r.description,t,n),x(r.description,e.size,t,n);let i=new DataView(q(t,n,e.size));return [e.get(i,r.littleEndian),n+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function q(e,r,t){let n=e.byteOffset+(r??0),i=t??e.byteLength;return e.buffer.slice(n,n+i)}var X=(e={})=>J({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,t,n)=>r.setUint32(0,t,n),size:4}),V=(e={})=>Z({get:(r,t)=>r.getUint32(0,t),name:"u32",options:e,size:4});var R=globalThis.TextDecoder,L=globalThis.TextEncoder;var v=()=>{let e;return {description:"utf8",encode:r=>new Uint8Array((e||(e=new L)).encode(r)),fixedSize:null,maxSize:null}},D=()=>{let e;return {decode(r,t=0){let n=(e||(e=new R)).decode(r.slice(t));return [_(n),r.length]},description:"utf8",fixedSize:null,maxSize:null}},cr=()=>d(v(),D());var K=(e={})=>{let r=e.size??X(),t=e.encoding??v(),n=e.description??`string(${t.description}; ${k(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?w(t,r,n):{description:n,encode:i=>{let o=t.encode(i),c=r.encode(o.length);return I([c,o])},fixedSize:null,maxSize:null}},Q=(e={})=>{let r=e.size??V(),t=e.encoding??D(),n=e.description??`string(${t.description}; ${k(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?N(t,r,n):{decode:(i,o=0)=>{S("string",i,o);let[c,a]=r.decode(i,o),s=Number(c);o=a;let m=i.slice(o,o+s);x("string",s,m);let[l,g]=t.decode(m);return o+=g,[l,o]},description:n,fixedSize:null,maxSize:null}},Er=(e={})=>d(K(e),Q(e));function k(e){return typeof e=="object"?e.description:`${e}`}
function l(e,r,t=r){if(!r.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${t}].`)}function C(e,r,t=0){if(r.length-t<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function z(e,r,t,n=0){let i=t.length-n;if(i<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${i}.`)}var Z=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},H=(e,r)=>Z(e.length<=r?e:e.slice(0,r),r);function S(e,r){return "fixedSize"in r?r.fixedSize:r.getSizeFromValue(e)}function a(e){return Object.freeze({...e,encode:r=>{let t=new Uint8Array(S(r,e));return e.write(r,t,0),t}})}function s(e){return Object.freeze({...e,decode:(r,t=0)=>e.read(r,t)[0]})}function m(e){return "fixedSize"in e&&typeof e.fixedSize=="number"}function d(e,r){if(m(e)!==m(r))throw new Error("Encoder and decoder must either both be fixed-size or variable-size.");if(m(e)&&m(r)&&e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(!m(e)&&!m(r)&&e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);return {...r,...e,decode:r.decode,encode:e.encode,read:r.read,write:e.write}}function F(e,r){return a({fixedSize:r,write:(t,n,i)=>{let c=e.encode(t),o=c.length>r?c.slice(0,r):c;return n.set(o,i),i+r}})}function N(e,r){return s({fixedSize:r,read:(t,n)=>{z("fixCodec",r,t,n),(n>0||t.length>r)&&(t=t.slice(n,n+r)),m(e)&&(t=H(t,e.fixedSize));let[i]=e.read(t,0);return [i,n+r]}})}var x=e=>a({getSizeFromValue:r=>{let[t,n]=A(r,e[0]);if(n==="")return r.length;let i=O(n,e);return t.length+Math.ceil(i.toString(16).length/2)},write(r,t,n){if(l(e,r),r==="")return n;let[i,c]=A(r,e[0]);if(c==="")return t.set(new Uint8Array(i.length).fill(0),n),n+i.length;let o=O(c,e),g=[];for(;o>0n;)g.unshift(Number(o%256n)),o/=256n;let u=[...Array(i.length).fill(0),...g];return t.set(u,n),n+u.length}}),b=e=>s({read(r,t){let n=t===0?r:r.slice(t);if(n.length===0)return ["",0];let i=n.findIndex(u=>u!==0);i=i===-1?n.length:i;let c=e[0].repeat(i);if(i===n.length)return [c,r.length];let o=n.slice(i).reduce((u,E)=>u*256n+BigInt(E),0n),g=J(o,e);return [c+g,r.length]}}),h=e=>d(x(e),b(e));function A(e,r){let t=[...e].findIndex(n=>n!==r);return t===-1?[e,""]:[e.slice(0,t),e.slice(t)]}function O(e,r){let t=BigInt(r.length);return [...e].reduce((n,i)=>n*t+BigInt(r.indexOf(i)),0n)}function J(e,r){let t=BigInt(r.length),n=[];for(;e>0n;)n.unshift(r[Number(e%t)]),e/=t;return n.join("")}var p="0123456789",be=()=>x(p),Ee=()=>b(p),Ce=()=>h(p);var P=()=>a({getSizeFromValue:e=>Math.ceil(e.length/2),write(e,r,t){let n=e.toLowerCase();l("0123456789abcdef",n,e);let i=n.match(/.{1,2}/g),c=i?i.map(o=>parseInt(o,16)):[];return r.set(c,t),c.length+t}}),q=()=>s({read(e,r){return [e.slice(r).reduce((n,i)=>n+i.toString(16).padStart(2,"0"),""),e.length]}}),Ve=()=>d(P(),q());var D="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Te=()=>x(D),ye=()=>b(D),Ae=()=>h(D);var B=(e,r)=>a({getSizeFromValue:t=>Math.floor(t.length*r/8),write(t,n,i){if(l(e,t),t==="")return i;let c=[...t].map(g=>e.indexOf(g)),o=_(c,r,8,!1);return n.set(o,i),o.length+i}}),I=(e,r)=>s({read(t,n=0){let i=n===0?t:t.slice(n);return i.length===0?["",t.length]:[_([...i],8,r,!0).map(o=>e[o]).join(""),t.length]}}),je=(e,r)=>d(B(e,r),I(e,r));function _(e,r,t,n){let i=[],c=0,o=0,g=(1<<t)-1;for(let u of e)for(c=c<<r|u,o+=r;o>=t;)o-=t,i.push(c>>o&g);return n&&o>0&&i.push(c<<t-o&g),i}var K=()=>a({getSizeFromValue:e=>{try{return atob(e).length}catch{throw new Error(`Expected a string of base 64, got [${e}].`)}},write(e,r,t){try{let n=atob(e).split("").map(i=>i.charCodeAt(0));return r.set(n,t),n.length+t}catch{throw new Error(`Expected a string of base 64, got [${e}].`)}}}),Q=()=>s({read(e,r=0){let t=e.slice(r);return [btoa(String.fromCharCode(...t)),e.length]}}),qe=()=>d(K(),Q());var $=e=>e.replace(/\u0000/g,""),Ye=(e,r)=>e.padEnd(r,"\0");function Y(e,r,t,n){if(n<r||n>t)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${t}], got ${n}.`)}function L(e){return (e==null?void 0:e.endian)!==1}function ee(e){return a({fixedSize:e.size,write(r,t,n){e.range&&Y(e.name,e.range[0],e.range[1],r);let i=new ArrayBuffer(e.size);return e.set(new DataView(i),r,L(e.config)),t.set(new Uint8Array(i),n),n+e.size}})}function re(e){return s({fixedSize:e.size,read(r,t=0){C(e.name,r,t),z(e.name,e.size,r,t);let n=new DataView(te(r,t,e.size));return [e.get(n,L(e.config)),t+e.size]}})}function te(e,r,t){let n=e.byteOffset+(r!=null?r:0),i=t!=null?t:e.byteLength;return e.buffer.slice(n,n+i)}var R=(e={})=>ee({config:e,name:"u32",range:[0,+"0xffffffff"],set:(r,t,n)=>r.setUint32(0,t,n),size:4}),M=(e={})=>re({config:e,get:(r,t)=>r.getUint32(0,t),name:"u32",size:4});var j=globalThis.TextDecoder,v=globalThis.TextEncoder;var w=()=>{let e;return a({getSizeFromValue:r=>(e||(e=new v)).encode(r).length,write:(r,t,n)=>{let i=(e||(e=new v)).encode(r);return t.set(i,n),n+i.length}})},V=()=>{let e;return s({read(r,t){let n=(e||(e=new j)).decode(r.slice(t));return [$(n),r.length]}})},mr=()=>d(w(),V());function ne(e={}){var n,i;let r=(n=e.size)!=null?n:R(),t=(i=e.encoding)!=null?i:w();return r==="variable"?t:typeof r=="number"?F(t,r):a({getSizeFromValue:c=>{let o=S(c,t);return S(o,r)+o},write:(c,o,g)=>{let u=S(c,t);return g=r.write(u,o,g),t.write(c,o,g)}})}function ie(e={}){var n,i;let r=(n=e.size)!=null?n:M(),t=(i=e.encoding)!=null?i:V();return r==="variable"?t:typeof r=="number"?N(t,r):s({read:(c,o=0)=>{C("string",c,o);let[g,u]=r.read(c,o),E=Number(g);o=u;let U=c.slice(o,o+E);z("string",E,U);let[k,W]=t.read(U,0);return o+=W,[k,o]}})}function Nr(e={}){return d(ne(e),ie(e))}
exports.assertValidBaseString = u;
exports.getBase10Codec = ue;
exports.getBase10Decoder = le;
exports.getBase10Encoder = me;
exports.getBase16Codec = Be;
exports.getBase16Decoder = W;
exports.assertValidBaseString = l;
exports.getBase10Codec = Ce;
exports.getBase10Decoder = Ee;
exports.getBase10Encoder = be;
exports.getBase16Codec = Ve;
exports.getBase16Decoder = q;
exports.getBase16Encoder = P;
exports.getBase58Codec = ye;
exports.getBase58Decoder = Ue;
exports.getBase58Encoder = Ie;
exports.getBase64Codec = Pe;
exports.getBase64Decoder = M;
exports.getBase64Encoder = j;
exports.getBase58Codec = Ae;
exports.getBase58Decoder = ye;
exports.getBase58Encoder = Te;
exports.getBase64Codec = qe;
exports.getBase64Decoder = Q;
exports.getBase64Encoder = K;
exports.getBaseXCodec = h;
exports.getBaseXDecoder = p;
exports.getBaseXEncoder = z;
exports.getBaseXResliceCodec = Te;
exports.getBaseXResliceDecoder = b;
exports.getBaseXDecoder = b;
exports.getBaseXEncoder = x;
exports.getBaseXResliceCodec = je;
exports.getBaseXResliceDecoder = I;
exports.getBaseXResliceEncoder = B;
exports.getStringCodec = Er;
exports.getStringDecoder = Q;
exports.getStringEncoder = K;
exports.getUtf8Codec = cr;
exports.getUtf8Decoder = D;
exports.getUtf8Encoder = v;
exports.padNullCharacters = Me;
exports.removeNullCharacters = _;
exports.getStringCodec = Nr;
exports.getStringDecoder = ie;
exports.getStringEncoder = ne;
exports.getUtf8Codec = mr;
exports.getUtf8Decoder = V;
exports.getUtf8Encoder = w;
exports.padNullCharacters = Ye;
exports.removeNullCharacters = $;

@@ -36,0 +36,0 @@ return exports;

/** Encodes strings in base10. */
export declare const getBase10Encoder: () => import("@solana/codecs-core").Encoder<string>;
export declare const getBase10Encoder: () => import("@solana/codecs-core").VariableSizeEncoder<string>;
/** Decodes strings in base10. */
export declare const getBase10Decoder: () => import("@solana/codecs-core").Decoder<string>;
export declare const getBase10Decoder: () => import("@solana/codecs-core").VariableSizeDecoder<string>;
/** Encodes and decodes strings in base10. */
export declare const getBase10Codec: () => import("@solana/codecs-core").Codec<string>;
export declare const getBase10Codec: () => import("@solana/codecs-core").VariableSizeCodec<string>;
//# sourceMappingURL=base10.d.ts.map

@@ -1,8 +0,8 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
/** Encodes strings in base16. */
export declare const getBase16Encoder: () => Encoder<string>;
export declare const getBase16Encoder: () => VariableSizeEncoder<string>;
/** Decodes strings in base16. */
export declare const getBase16Decoder: () => Decoder<string>;
export declare const getBase16Decoder: () => VariableSizeDecoder<string>;
/** Encodes and decodes strings in base16. */
export declare const getBase16Codec: () => Codec<string>;
export declare const getBase16Codec: () => VariableSizeCodec<string>;
//# sourceMappingURL=base16.d.ts.map
/** Encodes strings in base58. */
export declare const getBase58Encoder: () => import("@solana/codecs-core").Encoder<string>;
export declare const getBase58Encoder: () => import("@solana/codecs-core").VariableSizeEncoder<string>;
/** Decodes strings in base58. */
export declare const getBase58Decoder: () => import("@solana/codecs-core").Decoder<string>;
export declare const getBase58Decoder: () => import("@solana/codecs-core").VariableSizeDecoder<string>;
/** Encodes and decodes strings in base58. */
export declare const getBase58Codec: () => import("@solana/codecs-core").Codec<string>;
export declare const getBase58Codec: () => import("@solana/codecs-core").VariableSizeCodec<string>;
//# sourceMappingURL=base58.d.ts.map

@@ -1,8 +0,8 @@

import { Decoder, Encoder } from '@solana/codecs-core';
import { VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
/** Encodes strings in base64. */
export declare const getBase64Encoder: () => Encoder<string>;
export declare const getBase64Encoder: () => VariableSizeEncoder<string>;
/** Decodes strings in base64. */
export declare const getBase64Decoder: () => Decoder<string>;
export declare const getBase64Decoder: () => VariableSizeDecoder<string>;
/** Encodes and decodes strings in base64. */
export declare const getBase64Codec: () => import("@solana/codecs-core").Codec<string, string>;
export declare const getBase64Codec: () => VariableSizeCodec<string>;
//# sourceMappingURL=base64.d.ts.map

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

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
/**

@@ -6,3 +6,3 @@ * Encodes a string using a custom alphabet by reslicing the bits of the byte array.

*/
export declare const getBaseXResliceEncoder: (alphabet: string, bits: number) => Encoder<string>;
export declare const getBaseXResliceEncoder: (alphabet: string, bits: number) => VariableSizeEncoder<string>;
/**

@@ -12,3 +12,3 @@ * Decodes a string using a custom alphabet by reslicing the bits of the byte array.

*/
export declare const getBaseXResliceDecoder: (alphabet: string, bits: number) => Decoder<string>;
export declare const getBaseXResliceDecoder: (alphabet: string, bits: number) => VariableSizeDecoder<string>;
/**

@@ -21,3 +21,3 @@ * A string serializer that reslices bytes into custom chunks

*/
export declare const getBaseXResliceCodec: (alphabet: string, bits: number) => Codec<string>;
export declare const getBaseXResliceCodec: (alphabet: string, bits: number) => VariableSizeCodec<string>;
//# sourceMappingURL=baseX-reslice.d.ts.map

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

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
/**

@@ -7,3 +7,3 @@ * Encodes a string using a custom alphabet by dividing

*/
export declare const getBaseXEncoder: (alphabet: string) => Encoder<string>;
export declare const getBaseXEncoder: (alphabet: string) => VariableSizeEncoder<string>;
/**

@@ -14,3 +14,3 @@ * Decodes a string using a custom alphabet by dividing

*/
export declare const getBaseXDecoder: (alphabet: string) => Decoder<string>;
export declare const getBaseXDecoder: (alphabet: string) => VariableSizeDecoder<string>;
/**

@@ -25,3 +25,3 @@ * A string codec that requires a custom alphabet and uses

*/
export declare const getBaseXCodec: (alphabet: string) => Codec<string>;
export declare const getBaseXCodec: (alphabet: string) => VariableSizeCodec<string>;
//# sourceMappingURL=baseX.d.ts.map

@@ -1,5 +0,5 @@

import { BaseCodecOptions, Codec, Decoder, Encoder } from '@solana/codecs-core';
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
import { NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
/** Defines the options for string codecs. */
export type StringCodecOptions<TPrefix extends NumberCodec | NumberEncoder | NumberDecoder, TEncoding extends Codec<string> | Encoder<string> | Decoder<string>> = BaseCodecOptions & {
/** Defines the config for string codecs. */
export type StringCodecConfig<TPrefix extends NumberCodec | NumberEncoder | NumberDecoder, TEncoding extends Codec<string> | Encoder<string> | Decoder<string>> = {
/**

@@ -20,7 +20,28 @@ * The size of the string. It can be one of the following:

/** Encodes strings from a given encoding and size strategy. */
export declare const getStringEncoder: (options?: StringCodecOptions<NumberEncoder, Encoder<string>>) => Encoder<string>;
export declare function getStringEncoder<TSize extends number>(config: StringCodecConfig<NumberEncoder, Encoder<string>> & {
size: TSize;
}): FixedSizeEncoder<string, TSize>;
export declare function getStringEncoder<TSize extends number>(config: StringCodecConfig<NumberEncoder, Encoder<string>> & {
size: 'variable';
encoding: FixedSizeEncoder<string, TSize>;
}): FixedSizeEncoder<string, TSize>;
export declare function getStringEncoder(config?: StringCodecConfig<NumberEncoder, Encoder<string>>): VariableSizeEncoder<string>;
/** Decodes strings from a given encoding and size strategy. */
export declare const getStringDecoder: (options?: StringCodecOptions<NumberDecoder, Decoder<string>>) => Decoder<string>;
export declare function getStringDecoder<TSize extends number>(config: StringCodecConfig<NumberDecoder, Decoder<string>> & {
size: TSize;
}): FixedSizeDecoder<string, TSize>;
export declare function getStringDecoder<TSize extends number>(config: StringCodecConfig<NumberDecoder, Decoder<string>> & {
size: 'variable';
encoding: FixedSizeDecoder<string, TSize>;
}): FixedSizeDecoder<string, TSize>;
export declare function getStringDecoder(config?: StringCodecConfig<NumberDecoder, Decoder<string>>): VariableSizeDecoder<string>;
/** Encodes and decodes strings from a given encoding and size strategy. */
export declare const getStringCodec: (options?: StringCodecOptions<NumberCodec, Codec<string>>) => Codec<string>;
export declare function getStringCodec<TSize extends number>(config: StringCodecConfig<NumberCodec, Codec<string>> & {
size: TSize;
}): FixedSizeCodec<string, string, TSize>;
export declare function getStringCodec<TSize extends number>(config: StringCodecConfig<NumberCodec, Codec<string>> & {
size: 'variable';
encoding: FixedSizeCodec<string, string, TSize>;
}): FixedSizeCodec<string, string, TSize>;
export declare function getStringCodec(config?: StringCodecConfig<NumberCodec, Codec<string>>): VariableSizeCodec<string>;
//# sourceMappingURL=string.d.ts.map

@@ -1,8 +0,8 @@

import { Codec, Decoder, Encoder } from '@solana/codecs-core';
import { Codec, VariableSizeDecoder, VariableSizeEncoder } from '@solana/codecs-core';
/** Encodes UTF-8 strings using the native `TextEncoder` API. */
export declare const getUtf8Encoder: () => Encoder<string>;
export declare const getUtf8Encoder: () => VariableSizeEncoder<string>;
/** Decodes UTF-8 strings using the native `TextDecoder` API. */
export declare const getUtf8Decoder: () => Decoder<string>;
export declare const getUtf8Decoder: () => VariableSizeDecoder<string>;
/** Encodes and decodes UTF-8 strings using the native `TextEncoder` and `TextDecoder` API. */
export declare const getUtf8Codec: () => Codec<string>;
//# sourceMappingURL=utf8.d.ts.map
{
"name": "@solana/codecs-strings",
"version": "2.0.0-experimental.8894dc1",
"version": "2.0.0-experimental.89b469e",
"description": "Codecs for strings of different sizes and encodings",

@@ -52,9 +52,10 @@ "exports": {

"dependencies": {
"@solana/codecs-core": "2.0.0-experimental.8894dc1",
"@solana/codecs-numbers": "2.0.0-experimental.8894dc1"
"@solana/codecs-core": "2.0.0-experimental.89b469e",
"@solana/codecs-numbers": "2.0.0-experimental.89b469e"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.2",
"@swc/jest": "^0.2.28",
"@types/jest": "^29.5.5",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.5.6",
"@types/node": "^20.9.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",

@@ -64,10 +65,10 @@ "@typescript-eslint/parser": "^6.3.0",

"eslint": "^8.45.0",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-jest": "^27.4.2",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.6.4",
"jest-runner-eslint": "^2.1.0",
"jest-environment-jsdom": "^29.7.0",
"jest-runner-eslint": "^2.1.2",
"jest-runner-prettier": "^1.0.0",
"prettier": "^2.8",
"tsup": "7.2.0",
"prettier": "^3.1",
"tsup": "^8.0.1",
"typescript": "^5.2.2",

@@ -96,8 +97,8 @@ "version-from-git": "^1.1.1",

"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*",
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
"test:treeshakability:browser": "agadoo dist/index.browser.js",
"test:treeshakability:native": "agadoo dist/index.node.js",
"test:treeshakability:node": "agadoo dist/index.native.js",
"test:treeshakability:native": "agadoo dist/index.native.js",
"test:treeshakability:node": "agadoo dist/index.node.js",
"test:typecheck": "tsc --noEmit",

@@ -104,0 +105,0 @@ "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent",

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