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

@solana/addresses

Package Overview
Dependencies
Maintainers
14
Versions
1294
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/addresses - npm Package Compare versions

Comparing version 2.0.0-experimental.c237089 to 2.0.0-experimental.c7ef49c

dist/types/address.d.ts.map

61

dist/index.browser.js

@@ -1,6 +0,18 @@

import { base58, string } from '@metaplex-foundation/umi-serializers';
import { mapEncoder, combineCodec } from '@solana/codecs-core';
import { getStringEncoder, getStringDecoder, getBase58Encoder, getBase58Decoder } from '@solana/codecs-strings';
import { assertKeyExporterIsAvailable, assertDigestCapabilityIsAvailable } from '@solana/assertions';
// ../build-scripts/env-shim.ts
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
// src/address.ts
var memoizedBase58Encoder;
var memoizedBase58Decoder;
function getMemoizedBase58Encoder() {
if (!memoizedBase58Encoder)
memoizedBase58Encoder = getBase58Encoder();
return memoizedBase58Encoder;
}
function getMemoizedBase58Decoder() {
if (!memoizedBase58Decoder)
memoizedBase58Decoder = getBase58Decoder();
return memoizedBase58Decoder;
}
function isAddress(putativeBase58EncodedAddress) {

@@ -14,3 +26,4 @@ if (

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -31,3 +44,4 @@ if (numBytes !== 32) {

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -47,9 +61,22 @@ if (numBytes !== 32) {

}
function getAddressCodec(config) {
return string({
description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
encoding: base58,
function getAddressEncoder(config) {
return mapEncoder(
getStringEncoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Encoder(),
size: 32
}),
(putativeAddress) => address(putativeAddress)
);
}
function getAddressDecoder(config) {
return getStringDecoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Decoder(),
size: 32
});
}
function getAddressCodec(config) {
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
}
function getAddressComparator() {

@@ -218,3 +245,3 @@ return new Intl.Collator("en", {

const base58EncodedAddressCodec = getAddressCodec();
const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
const addressBytesBuffer = await crypto.subtle.digest(

@@ -228,3 +255,3 @@ "SHA-256",

}
return base58EncodedAddressCodec.deserialize(addressBytes)[0];
return base58EncodedAddressCodec.decode(addressBytes)[0];
}

@@ -258,3 +285,3 @@ async function getProgramDerivedAddress({

}) {
const { serialize, deserialize } = getAddressCodec();
const { encode, decode } = getAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;

@@ -264,3 +291,3 @@ if (seedBytes.byteLength > MAX_SEED_LENGTH) {

}
const programAddressBytes = serialize(programAddress);
const programAddressBytes = encode(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {

@@ -271,6 +298,6 @@ throw new Error(`programAddress cannot end with the PDA marker`);

"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
return decode(addressBytes)[0];
}

@@ -283,8 +310,8 @@ async function getAddressFromPublicKey(publicKey) {

const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };
export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressDecoder, getAddressEncoder, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

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

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
var mergeBytes = (bytesArr) => {
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
// ../codecs-core/dist/index.browser.js
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
if (bytes.length - offset <= 0) {
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
}
}
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
const bytesLength = bytes.length - offset;
if (bytesLength < expected) {
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
}
}
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;
bytesArr.forEach((arr) => {
nonEmptyByteArrays.forEach((arr) => {
result.set(arr, offset);

@@ -31,34 +42,52 @@ offset += arr.length;

};
var fixBytes = (bytes, length) => padBytes(bytes.slice(0, length), length);
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
var DeserializingEmptyBufferError = class extends Error {
constructor(serializer) {
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
__publicField(this, "name", "DeserializingEmptyBufferError");
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
function combineCodec(encoder, decoder, description) {
if (encoder.fixedSize !== decoder.fixedSize) {
throw new Error(
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
);
}
};
var NotEnoughBytesError = class extends Error {
constructor(serializer, expected, actual) {
super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
__publicField(this, "name", "NotEnoughBytesError");
if (encoder.maxSize !== decoder.maxSize) {
throw new Error(
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
);
}
};
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
function fixSerializer(serializer, fixedBytes, description) {
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 {
description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
decode: decoder.decode,
description: description ?? encoder.description,
encode: encoder.encode,
fixedSize: encoder.fixedSize,
maxSize: encoder.maxSize
};
}
function fixCodecHelper(data, fixedBytes, description) {
return {
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
fixedSize: fixedBytes,
maxSize: fixedBytes,
serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
deserialize: (buffer, offset = 0) => {
buffer = buffer.slice(offset, offset + fixedBytes);
if (buffer.length < fixedBytes) {
throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
maxSize: 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) => {
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
if (offset > 0 || bytes.length > fixedBytes) {
bytes = bytes.slice(offset, offset + fixedBytes);
}
if (serializer.fixedSize !== null) {
buffer = fixBytes(buffer, serializer.fixedSize);
if (decoder.fixedSize !== null) {
bytes = fixBytes(bytes, decoder.fixedSize);
}
const [value] = serializer.deserialize(buffer, 0);
const [value] = decoder.decode(bytes, 0);
return [value, offset + fixedBytes];

@@ -68,29 +97,99 @@ }

}
function mapEncoder(encoder, unmap) {
return {
description: encoder.description,
encode: (value) => encoder.encode(unmap(value)),
fixedSize: encoder.fixedSize,
maxSize: encoder.maxSize
};
}
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
var InvalidBaseStringError = class extends Error {
constructor(value, base, cause) {
const message = `Expected a string of base ${base}, got [${value}].`;
super(message);
__publicField(this, "name", "InvalidBaseStringError");
this.cause = cause;
// ../codecs-numbers/dist/index.browser.js
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
if (value < min || value > max) {
throw new Error(
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
);
}
};
}
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 numberEncoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
description: codecData.description,
encode(value) {
if (input.range) {
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
};
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, 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
};
}
function toArrayBuffer(bytes, offset, length) {
const bytesOffset = bytes.byteOffset + (offset ?? 0);
const bytesLength = length ?? bytes.byteLength;
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
}
var getU32Encoder = (options = {}) => numberEncoderFactory({
name: "u32",
options,
range: [0, Number("0xffffffff")],
set: (view, value, le) => view.setUint32(0, value, le),
size: 4
});
var getU32Decoder = (options = {}) => numberDecoderFactory({
get: (view, le) => view.getUint32(0, le),
name: "u32",
options,
size: 4
});
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
var baseX = (alphabet) => {
const base = alphabet.length;
// ../codecs-strings/dist/index.browser.js
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
}
}
var getBaseXEncoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
description: `base${base}`,
fixedSize: null,
maxSize: null,
serialize(value) {
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
throw new InvalidBaseStringError(value, base);
}
encode(value) {
assertValidBaseString(alphabet4, value);
if (value === "")
return new Uint8Array();
const chars = [...value];
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
trailIndex = trailIndex === -1 ? chars.length : trailIndex;

@@ -104,3 +203,3 @@ const leadingZeroes = Array(trailIndex).fill(0);

for (let i = tailChars.length - 1; i >= 0; i -= 1) {
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
baseXPower *= baseBigInt;

@@ -115,26 +214,35 @@ }

},
deserialize(buffer, offset = 0) {
if (buffer.length === 0)
fixedSize: null,
maxSize: null
};
};
var getBaseXDecoder = (alphabet4) => {
const base = alphabet4.length;
const baseBigInt = BigInt(base);
return {
decode(rawBytes, offset = 0) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
if (bytes.length === 0)
return ["", 0];
const bytes = buffer.slice(offset);
let trailIndex = bytes.findIndex((n) => n !== 0);
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
const leadingZeroes = alphabet[0].repeat(trailIndex);
const leadingZeroes = alphabet4[0].repeat(trailIndex);
if (trailIndex === bytes.length)
return [leadingZeroes, buffer.length];
return [leadingZeroes, rawBytes.length];
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
const tailChars = [];
while (base10Number > 0n) {
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
base10Number /= baseBigInt;
}
return [leadingZeroes + tailChars.join(""), buffer.length];
}
return [leadingZeroes + tailChars.join(""), rawBytes.length];
},
description: `base${base}`,
fixedSize: null,
maxSize: null
};
};
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
var removeNullCharacters = (value) => (

@@ -144,133 +252,90 @@ // eslint-disable-next-line no-control-regex

);
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
var utf8 = {
description: "utf8",
fixedSize: null,
maxSize: null,
serialize(value) {
return new TextEncoder().encode(value);
},
deserialize(buffer, offset = 0) {
const value = new TextDecoder().decode(buffer.slice(offset));
return [removeNullCharacters(value), buffer.length];
}
var e = globalThis.TextDecoder;
var o = globalThis.TextEncoder;
var getUtf8Encoder = () => {
let textEncoder;
return {
description: "utf8",
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
fixedSize: null,
maxSize: null
};
};
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
var Endian;
(function(Endian2) {
Endian2["Little"] = "le";
Endian2["Big"] = "be";
})(Endian || (Endian = {}));
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
var NumberOutOfRangeError = class extends RangeError {
constructor(serializer, min, max, actual) {
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
__publicField(this, "name", "NumberOutOfRangeError");
}
};
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
function numberFactory(input) {
let littleEndian;
let defaultDescription = input.name;
if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
var getUtf8Decoder = () => {
let textDecoder;
return {
description: input.options.description ?? defaultDescription,
fixedSize: input.size,
maxSize: input.size,
serialize(value) {
if (input.range) {
assertRange(input.name, input.range[0], input.range[1], value);
}
const buffer = new ArrayBuffer(input.size);
input.set(new DataView(buffer), value, littleEndian);
return new Uint8Array(buffer);
decode(bytes, offset = 0) {
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
return [removeNullCharacters(value), bytes.length];
},
deserialize(bytes, offset = 0) {
const slice = bytes.slice(offset, offset + input.size);
assertEnoughBytes("i8", slice, input.size);
const view = toDataView(slice);
return [input.get(view, littleEndian), offset + input.size];
}
description: "utf8",
fixedSize: null,
maxSize: null
};
}
var toArrayBuffer = (array) => array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
var toDataView = (array) => new DataView(toArrayBuffer(array));
var assertRange = (serializer, min, max, value) => {
if (value < min || value > max) {
throw new NumberOutOfRangeError(serializer, min, max, value);
}
};
var assertEnoughBytes = (serializer, bytes, expected) => {
if (bytes.length === 0) {
throw new DeserializingEmptyBufferError(serializer);
var getStringEncoder = (options = {}) => {
const size = options.size ?? getU32Encoder();
const encoding = options.encoding ?? getUtf8Encoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
if (size === "variable") {
return { ...encoding, description };
}
if (bytes.length < expected) {
throw new NotEnoughBytesError(serializer, expected, bytes.length);
if (typeof size === "number") {
return fixEncoder(encoding, size, description);
}
return {
description,
encode: (value) => {
const contentBytes = encoding.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
},
fixedSize: null,
maxSize: null
};
};
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
var u32 = (options = {}) => numberFactory({
name: "u32",
size: 4,
range: [0, Number("0xffffffff")],
set: (view, value, le) => view.setUint32(0, Number(value), le),
get: (view, le) => view.getUint32(0, le),
options
});
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
function getSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
function string(options = {}) {
const size = options.size ?? u32();
const encoding = options.encoding ?? utf8;
var getStringDecoder = (options = {}) => {
const size = options.size ?? getU32Decoder();
const encoding = options.encoding ?? getUtf8Decoder();
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
if (size === "variable") {
return {
...encoding,
description
};
return { ...encoding, description };
}
if (typeof size === "number") {
return fixSerializer(encoding, size, description);
return fixDecoder(encoding, size, description);
}
return {
description,
fixedSize: null,
maxSize: null,
serialize: (value) => {
const contentBytes = encoding.serialize(value);
const lengthBytes = size.serialize(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
},
deserialize: (buffer, offset = 0) => {
if (buffer.slice(offset).length === 0) {
throw new DeserializingEmptyBufferError("string");
}
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
decode: (bytes, offset = 0) => {
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
const length = Number(lengthBigInt);
offset = lengthOffset;
const contentBuffer = buffer.slice(offset, offset + length);
if (contentBuffer.length < length) {
throw new NotEnoughBytesError("string", length, contentBuffer.length);
}
const [value, contentOffset] = encoding.deserialize(contentBuffer);
const contentBytes = bytes.slice(offset, offset + length);
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
const [value, contentOffset] = encoding.decode(contentBytes);
offset += contentOffset;
return [value, offset];
}
},
description,
fixedSize: null,
maxSize: null
};
};
function getSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
// src/address.ts
var memoizedBase58Encoder;
var memoizedBase58Decoder;
function getMemoizedBase58Encoder() {
if (!memoizedBase58Encoder)
memoizedBase58Encoder = getBase58Encoder();
return memoizedBase58Encoder;
}
function getMemoizedBase58Decoder() {
if (!memoizedBase58Decoder)
memoizedBase58Decoder = getBase58Decoder();
return memoizedBase58Decoder;
}
function isAddress(putativeBase58EncodedAddress) {

@@ -284,3 +349,4 @@ if (

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -301,3 +367,4 @@ if (numBytes !== 32) {

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -307,5 +374,5 @@ if (numBytes !== 32) {

}
} catch (e) {
} catch (e2) {
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
cause: e
cause: e2
});

@@ -318,9 +385,22 @@ }

}
function getAddressCodec(config) {
return string({
description: config?.description ?? ("A 32-byte account address" ),
encoding: base58,
function getAddressEncoder(config) {
return mapEncoder(
getStringEncoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Encoder(),
size: 32
}),
(putativeAddress) => address(putativeAddress)
);
}
function getAddressDecoder(config) {
return getStringDecoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Decoder(),
size: 32
});
}
function getAddressCodec(config) {
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
}
function getAddressComparator() {

@@ -510,3 +590,3 @@ return new Intl.Collator("en", {

const base58EncodedAddressCodec = getAddressCodec();
const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
const addressBytesBuffer = await crypto.subtle.digest(

@@ -520,3 +600,3 @@ "SHA-256",

}
return base58EncodedAddressCodec.deserialize(addressBytes)[0];
return base58EncodedAddressCodec.decode(addressBytes)[0];
}

@@ -535,7 +615,7 @@ async function getProgramDerivedAddress({

return [address2, bumpSeed];
} catch (e) {
if (e instanceof PointOnCurveError) {
} catch (e2) {
if (e2 instanceof PointOnCurveError) {
bumpSeed--;
} else {
throw e;
throw e2;
}

@@ -551,3 +631,3 @@ }

}) {
const { serialize, deserialize } = getAddressCodec();
const { encode, decode } = getAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;

@@ -557,3 +637,3 @@ if (seedBytes.byteLength > MAX_SEED_LENGTH) {

}
const programAddressBytes = serialize(programAddress);
const programAddressBytes = encode(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {

@@ -564,6 +644,6 @@ throw new Error(`programAddress cannot end with the PDA marker`);

"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
return decode(addressBytes)[0];
}

@@ -578,3 +658,3 @@

const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;

@@ -589,2 +669,4 @@ }

exports.getAddressComparator = getAddressComparator;
exports.getAddressDecoder = getAddressDecoder;
exports.getAddressEncoder = getAddressEncoder;
exports.getAddressFromPublicKey = getAddressFromPublicKey;

@@ -591,0 +673,0 @@ exports.getProgramDerivedAddress = getProgramDerivedAddress;

@@ -1,6 +0,18 @@

import { base58, string } from '@metaplex-foundation/umi-serializers';
import { mapEncoder, combineCodec } from '@solana/codecs-core';
import { getStringEncoder, getStringDecoder, getBase58Encoder, getBase58Decoder } from '@solana/codecs-strings';
import { assertKeyExporterIsAvailable, assertDigestCapabilityIsAvailable } from '@solana/assertions';
// ../build-scripts/env-shim.ts
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
// src/address.ts
var memoizedBase58Encoder;
var memoizedBase58Decoder;
function getMemoizedBase58Encoder() {
if (!memoizedBase58Encoder)
memoizedBase58Encoder = getBase58Encoder();
return memoizedBase58Encoder;
}
function getMemoizedBase58Decoder() {
if (!memoizedBase58Decoder)
memoizedBase58Decoder = getBase58Decoder();
return memoizedBase58Decoder;
}
function isAddress(putativeBase58EncodedAddress) {

@@ -14,3 +26,4 @@ if (

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -31,3 +44,4 @@ if (numBytes !== 32) {

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -47,9 +61,22 @@ if (numBytes !== 32) {

}
function getAddressCodec(config) {
return string({
description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
encoding: base58,
function getAddressEncoder(config) {
return mapEncoder(
getStringEncoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Encoder(),
size: 32
}),
(putativeAddress) => address(putativeAddress)
);
}
function getAddressDecoder(config) {
return getStringDecoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Decoder(),
size: 32
});
}
function getAddressCodec(config) {
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
}
function getAddressComparator() {

@@ -218,3 +245,3 @@ return new Intl.Collator("en", {

const base58EncodedAddressCodec = getAddressCodec();
const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
const addressBytesBuffer = await crypto.subtle.digest(

@@ -228,3 +255,3 @@ "SHA-256",

}
return base58EncodedAddressCodec.deserialize(addressBytes)[0];
return base58EncodedAddressCodec.decode(addressBytes)[0];
}

@@ -258,3 +285,3 @@ async function getProgramDerivedAddress({

}) {
const { serialize, deserialize } = getAddressCodec();
const { encode, decode } = getAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;

@@ -264,3 +291,3 @@ if (seedBytes.byteLength > MAX_SEED_LENGTH) {

}
const programAddressBytes = serialize(programAddress);
const programAddressBytes = encode(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {

@@ -271,6 +298,6 @@ throw new Error(`programAddress cannot end with the PDA marker`);

"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
return decode(addressBytes)[0];
}

@@ -283,8 +310,6 @@ async function getAddressFromPublicKey(publicKey) {

const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map
export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressDecoder, getAddressEncoder, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };

@@ -1,6 +0,18 @@

import { base58, string } from '@metaplex-foundation/umi-serializers';
import { mapEncoder, combineCodec } from '@solana/codecs-core';
import { getStringEncoder, getStringDecoder, getBase58Encoder, getBase58Decoder } from '@solana/codecs-strings';
import { assertKeyExporterIsAvailable, assertDigestCapabilityIsAvailable } from '@solana/assertions';
// ../build-scripts/env-shim.ts
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
// src/address.ts
var memoizedBase58Encoder;
var memoizedBase58Decoder;
function getMemoizedBase58Encoder() {
if (!memoizedBase58Encoder)
memoizedBase58Encoder = getBase58Encoder();
return memoizedBase58Encoder;
}
function getMemoizedBase58Decoder() {
if (!memoizedBase58Decoder)
memoizedBase58Decoder = getBase58Decoder();
return memoizedBase58Decoder;
}
function isAddress(putativeBase58EncodedAddress) {

@@ -14,3 +26,4 @@ if (

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -31,3 +44,4 @@ if (numBytes !== 32) {

}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const base58Encoder = getMemoizedBase58Encoder();
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;

@@ -47,9 +61,22 @@ if (numBytes !== 32) {

}
function getAddressCodec(config) {
return string({
description: config?.description ?? (__DEV__ ? "A 32-byte account address" : ""),
encoding: base58,
function getAddressEncoder(config) {
return mapEncoder(
getStringEncoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Encoder(),
size: 32
}),
(putativeAddress) => address(putativeAddress)
);
}
function getAddressDecoder(config) {
return getStringDecoder({
description: config?.description ?? "Base58EncodedAddress",
encoding: getMemoizedBase58Decoder(),
size: 32
});
}
function getAddressCodec(config) {
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
}
function getAddressComparator() {

@@ -218,3 +245,3 @@ return new Intl.Collator("en", {

const base58EncodedAddressCodec = getAddressCodec();
const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
const addressBytesBuffer = await crypto.subtle.digest(

@@ -228,3 +255,3 @@ "SHA-256",

}
return base58EncodedAddressCodec.deserialize(addressBytes)[0];
return base58EncodedAddressCodec.decode(addressBytes)[0];
}

@@ -258,3 +285,3 @@ async function getProgramDerivedAddress({

}) {
const { serialize, deserialize } = getAddressCodec();
const { encode, decode } = getAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;

@@ -264,3 +291,3 @@ if (seedBytes.byteLength > MAX_SEED_LENGTH) {

}
const programAddressBytes = serialize(programAddress);
const programAddressBytes = encode(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {

@@ -271,6 +298,6 @@ throw new Error(`programAddress cannot end with the PDA marker`);

"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
return decode(addressBytes)[0];
}

@@ -283,8 +310,8 @@ async function getAddressFromPublicKey(publicKey) {

const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
const [base58EncodedAddress] = getAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
return base58EncodedAddress;
}
export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };
export { address, assertIsAddress, assertIsProgramDerivedAddress, createAddressWithSeed, getAddressCodec, getAddressComparator, getAddressDecoder, getAddressEncoder, getAddressFromPublicKey, getProgramDerivedAddress, isAddress, isProgramDerivedAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map

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

var G=Object.defineProperty;var W=(e,r,t)=>r in e?G(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var x=(e,r,t)=>(W(e,typeof r!="symbol"?r+"":r,t),t);var I=e=>{let r=e.reduce((s,o)=>s+o.length,0),t=new Uint8Array(r),n=0;return e.forEach(s=>{t.set(s,n),n+=s.length;}),t},_=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},E=(e,r)=>_(e.slice(0,r),r);var h=class extends Error{constructor(t){super(`Serializer [${t}] cannot deserialize empty buffers.`);x(this,"name","DeserializingEmptyBufferError");}},y=class extends Error{constructor(t,n,s){super(`Serializer [${t}] expected ${n} bytes, got ${s}.`);x(this,"name","NotEnoughBytesError");}};function D(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:n=>E(e.serialize(n),r),deserialize:(n,s=0)=>{if(n=n.slice(s,s+r),n.length<r)throw new y("fixSerializer",r,n.length);e.fixedSize!==null&&(n=E(n,e.fixedSize));let[o]=e.deserialize(n,0);return [o,s+r]}}}var A=class extends Error{constructor(t,n,s){let o=`Expected a string of base ${n}, got [${t}].`;super(o);x(this,"name","InvalidBaseStringError");this.cause=s;}};var $=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,fixedSize:null,maxSize:null,serialize(n){if(!n.match(new RegExp(`^[${e}]*$`)))throw new A(n,r);if(n==="")return new Uint8Array;let s=[...n],o=s.findIndex(p=>p!==e[0]);o=o===-1?s.length:o;let i=Array(o).fill(0);if(o===s.length)return Uint8Array.from(i);let l=s.slice(o),d=0n,c=1n;for(let p=l.length-1;p>=0;p-=1)d+=c*BigInt(e.indexOf(l[p])),c*=t;let f=[];for(;d>0n;)f.unshift(Number(d%256n)),d/=256n;return Uint8Array.from(i.concat(f))},deserialize(n,s=0){if(n.length===0)return ["",0];let o=n.slice(s),i=o.findIndex(f=>f!==0);i=i===-1?o.length:i;let l=e[0].repeat(i);if(i===o.length)return [l,n.length];let d=o.slice(i).reduce((f,p)=>f*256n+BigInt(p),0n),c=[];for(;d>0n;)c.unshift(e[Number(d%t)]),d/=t;return [l+c.join(""),n.length]}}};var b=$("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var U=e=>e.replace(/\u0000/g,"");var T={description:"utf8",fixedSize:null,maxSize:null,serialize(e){return new TextEncoder().encode(e)},deserialize(e,r=0){let t=new TextDecoder().decode(e.slice(r));return [U(t),e.length]}};var z;(function(e){e.Little="le",e.Big="be";})(z||(z={}));var S=class extends RangeError{constructor(t,n,s,o){super(`Serializer [${t}] expected number to be between ${n} and ${s}, got ${o}.`);x(this,"name","NumberOutOfRangeError");}};function R(e){let r,t=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===z.Little,t+=r?"(le)":"(be)"),{description:e.options.description??t,fixedSize:e.size,maxSize:e.size,serialize(n){e.range&&Y(e.name,e.range[0],e.range[1],n);let s=new ArrayBuffer(e.size);return e.set(new DataView(s),n,r),new Uint8Array(s)},deserialize(n,s=0){let o=n.slice(s,s+e.size);J("i8",o,e.size);let i=Z(o);return [e.get(i,r),s+e.size]}}}var q=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),Z=e=>new DataView(q(e)),Y=(e,r,t,n)=>{if(n<r||n>t)throw new S(e,r,t,n)},J=(e,r,t)=>{if(r.length===0)throw new h(e);if(r.length<t)throw new y(e,t,r.length)};var P=(e={})=>R({name:"u32",size:4,range:[0,+"0xffffffff"],set:(r,t,n)=>r.setUint32(0,Number(t),n),get:(r,t)=>r.getUint32(0,t),options:e});function L(e){return typeof e=="object"?e.description:`${e}`}function C(e={}){let r=e.size??P(),t=e.encoding??T,n=e.description??`string(${t.description}; ${L(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?D(t,r,n):{description:n,fixedSize:null,maxSize:null,serialize:s=>{let o=t.serialize(s),i=r.serialize(o.length);return I([i,o])},deserialize:(s,o=0)=>{if(s.slice(o).length===0)throw new h("string");let[i,l]=r.deserialize(s,o),d=Number(i);o=l;let c=s.slice(o,o+d);if(c.length<d)throw new y("string",d,c.length);let[f,p]=t.deserialize(c);return o+=p,[f,o]}}}function O(e){return !(e.length<32||e.length>44||b.serialize(e).byteLength!==32)}function N(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=b.serialize(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}}function br(e){return N(e),e}function w(e){return C({description:e?.description??"",encoding:b,size:32})}function wr(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function k(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}async function K(){if(k(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.digest!="function")throw new Error("No digest implementation could be found")}async function F(){if(k(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}var Q=37095705934669439343138083508754565189542113879843219016388785533085940283555n,m=57896044618658097711785492504343953926634992332820282019728792003956564819949n,V=19681161376707505956807079304988542015446066515923890162744021073123829784752n;function u(e){let r=e%m;return r>=0n?r:m+r}function g(e,r){let t=e;for(;r-- >0n;)t*=t,t%=m;return t}function ee(e){let t=e*e%m*e%m,n=g(t,2n)*t%m,s=g(n,1n)*e%m,o=g(s,5n)*s%m,i=g(o,10n)*o%m,l=g(i,20n)*i%m,d=g(l,40n)*l%m,c=g(d,80n)*d%m,f=g(c,80n)*d%m,p=g(f,10n)*o%m;return g(p,2n)*e%m}function re(e,r){let t=u(r*r*r),n=u(t*t*r),s=ee(e*n),o=u(e*t*s),i=u(r*o*o),l=o,d=u(o*V),c=i===e,f=i===u(-e),p=i===u(-e*V);return c&&(o=l),(f||p)&&(o=d),(u(o)&1n)===1n&&(o=u(-o)),!c&&!f?null:o}function X(e,r){let t=u(e*e),n=u(t-1n),s=u(Q*t+1n),o=re(n,s);if(o===null)return !1;let i=(r&128)!==0;return !(o===0n&&i)}function te(e){let r=e.toString(16);return r.length===1?`0${r}`:r}function ne(e){let t=`0x${e.reduce((n,s,o)=>`${te(o===31?s&-129:s)}${n}`,"")}`;return BigInt(t)}async function M(e){if(e.byteLength!==32)return !1;let r=ne(e);return X(r,e[31])}function $r(e){return Array.isArray(e)&&e.length===2&&typeof e[0]=="string"&&typeof e[1]=="number"&&e[1]>=0&&e[1]<=255&&O(e[0])}function Ur(e){if(!(Array.isArray(e)&&e.length===2&&typeof e[0]=="string"&&typeof e[1]=="number"))throw new Error("Expected given program derived address to have the following format: [Base58EncodedAddress, ProgramDerivedAddressBump].");if(e[1]<0||e[1]>255)throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${e[1]}.`);N(e[0]);}var H=32,j=16,B=[80,114,111,103,114,97,109,68,101,114,105,118,101,100,65,100,100,114,101,115,115],v=class extends Error{};async function oe({programAddress:e,seeds:r}){if(await K(),r.length>j)throw new Error(`A maximum of ${j} seeds may be supplied when creating an address`);let t,n=r.reduce((d,c,f)=>{let p=typeof c=="string"?(t||(t=new TextEncoder)).encode(c):c;if(p.byteLength>H)throw new Error(`The seed at index ${f} exceeds the maximum length of 32 bytes`);return d.push(...p),d},[]),s=w(),o=s.serialize(e),i=await crypto.subtle.digest("SHA-256",new Uint8Array([...n,...o,...B])),l=new Uint8Array(i);if(await M(l))throw new v("Invalid seeds; point must fall off the Ed25519 curve");return s.deserialize(l)[0]}async function Rr({programAddress:e,seeds:r}){let t=255;for(;t>0;)try{return [await oe({programAddress:e,seeds:[...r,new Uint8Array([t])]}),t]}catch(n){if(n instanceof v)t--;else throw n}throw new Error("Unable to find a viable program address bump seed")}async function Lr({baseAddress:e,programAddress:r,seed:t}){let{serialize:n,deserialize:s}=w(),o=typeof t=="string"?new TextEncoder().encode(t):t;if(o.byteLength>H)throw new Error("The seed exceeds the maximum length of 32 bytes");let i=n(r);if(i.length>=B.length&&i.slice(-B.length).every((c,f)=>c===B[f]))throw new Error("programAddress cannot end with the PDA marker");let l=await crypto.subtle.digest("SHA-256",new Uint8Array([...n(e),...o,...i])),d=new Uint8Array(l);return s(d)[0]}async function Xr(e){if(await F(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let r=await crypto.subtle.exportKey("raw",e),[t]=w().deserialize(new Uint8Array(r));return t}
function y(e,r,t=0){if(r.length-t<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function h(e,r,t,n=0){let s=t.length-n;if(s<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${s}.`)}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,i)=>o+i.length,0),n=new Uint8Array(t),s=0;return r.forEach(o=>{n.set(o,s),s+=o.length;}),n},Y=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},C=(e,r)=>Y(e.length<=r?e:e.slice(0,r),r);function x(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 D(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function U(e,r,t){return {...D(e,r,t),encode:n=>C(e.encode(n),r)}}function T(e,r,t){return {...D(e,r,t),decode:(n,s=0)=>{h("fixCodec",r,n,s),(s>0||n.length>r)&&(n=n.slice(s,s+r)),e.fixedSize!==null&&(n=C(n,e.fixedSize));let[o]=e.decode(n,0);return [o,s+r]}}}function $(e,r){return {description:e.description,encode:t=>e.encode(r(t)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function J(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 P(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 Q(e){let r=P(e);return {description:r.description,encode(t){e.range&&J(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 ee(e){let r=P(e);return {decode(t,n=0){y(r.description,t,n),h(r.description,e.size,t,n);let s=new DataView(re(t,n,e.size));return [e.get(s,r.littleEndian),n+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function re(e,r,t){let n=e.byteOffset+(r??0),s=t??e.byteLength;return e.buffer.slice(n,n+s)}var N=(e={})=>Q({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,t,n)=>r.setUint32(0,t,n),size:4}),F=(e={})=>ee({get:(r,t)=>r.getUint32(0,t),name:"u32",options:e,size:4});function te(e,r,t=r){if(!r.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${t}].`)}var ne=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,encode(n){if(te(e,n),n==="")return new Uint8Array;let s=[...n],o=s.findIndex(g=>g!==e[0]);o=o===-1?s.length:o;let i=Array(o).fill(0);if(o===s.length)return Uint8Array.from(i);let a=s.slice(o),d=0n,c=1n;for(let g=a.length-1;g>=0;g-=1)d+=c*BigInt(e.indexOf(a[g])),c*=t;let f=[];for(;d>0n;)f.unshift(Number(d%256n)),d/=256n;return Uint8Array.from(i.concat(f))},fixedSize:null,maxSize:null}},oe=e=>{let r=e.length,t=BigInt(r);return {decode(n,s=0){let o=s===0?n:n.slice(s);if(o.length===0)return ["",0];let i=o.findIndex(f=>f!==0);i=i===-1?o.length:i;let a=e[0].repeat(i);if(i===o.length)return [a,n.length];let d=o.slice(i).reduce((f,g)=>f*256n+BigInt(g),0n),c=[];for(;d>0n;)c.unshift(e[Number(d%t)]),d/=t;return [a+c.join(""),n.length]},description:`base${r}`,fixedSize:null,maxSize:null}};var _="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",O=()=>ne(_),R=()=>oe(_);var se=e=>e.replace(/\u0000/g,"");var ie=globalThis.TextDecoder,de=globalThis.TextEncoder,ce=()=>{let e;return {description:"utf8",encode:r=>new Uint8Array((e||(e=new de)).encode(r)),fixedSize:null,maxSize:null}},ae=()=>{let e;return {decode(r,t=0){let n=(e||(e=new ie)).decode(r.slice(t));return [se(n),r.length]},description:"utf8",fixedSize:null,maxSize:null}};var L=(e={})=>{let r=e.size??N(),t=e.encoding??ce(),n=e.description??`string(${t.description}; ${K(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?U(t,r,n):{description:n,encode:s=>{let o=t.encode(s),i=r.encode(o.length);return I([i,o])},fixedSize:null,maxSize:null}},k=(e={})=>{let r=e.size??F(),t=e.encoding??ae(),n=e.description??`string(${t.description}; ${K(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?T(t,r,n):{decode:(s,o=0)=>{y("string",s,o);let[i,a]=r.decode(s,o),d=Number(i);o=a;let c=s.slice(o,o+d);h("string",d,c);let[f,g]=t.decode(c);return o+=g,[f,o]},description:n,fixedSize:null,maxSize:null}};function K(e){return typeof e=="object"?e.description:`${e}`}var v,A;function z(){return v||(v=O()),v}function fe(){return A||(A=R()),A}function M(e){return !(e.length<32||e.length>44||z().encode(e).byteLength!==32)}function w(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let n=z().encode(e).byteLength;if(n!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${n}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}}function ge(e){return w(e),e}function ue(e){return $(L({description:e?.description??"Base58EncodedAddress",encoding:z(),size:32}),r=>ge(r))}function B(e){return k({description:e?.description??"Base58EncodedAddress",encoding:fe(),size:32})}function S(e){return x(ue(e),B(e))}function Fe(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function X(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}async function H(){if(X(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.digest!="function")throw new Error("No digest implementation could be found")}async function V(){if(X(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}var le=37095705934669439343138083508754565189542113879843219016388785533085940283555n,u=57896044618658097711785492504343953926634992332820282019728792003956564819949n,G=19681161376707505956807079304988542015446066515923890162744021073123829784752n;function l(e){let r=e%u;return r>=0n?r:u+r}function m(e,r){let t=e;for(;r-- >0n;)t*=t,t%=u;return t}function me(e){let t=e*e%u*e%u,n=m(t,2n)*t%u,s=m(n,1n)*e%u,o=m(s,5n)*s%u,i=m(o,10n)*o%u,a=m(i,20n)*i%u,d=m(a,40n)*a%u,c=m(d,80n)*d%u,f=m(c,80n)*d%u,g=m(f,10n)*o%u;return m(g,2n)*e%u}function pe(e,r){let t=l(r*r*r),n=l(t*t*r),s=me(e*n),o=l(e*t*s),i=l(r*o*o),a=o,d=l(o*G),c=i===e,f=i===l(-e),g=i===l(-e*G);return c&&(o=a),(f||g)&&(o=d),(l(o)&1n)===1n&&(o=l(-o)),!c&&!f?null:o}function j(e,r){let t=l(e*e),n=l(t-1n),s=l(le*t+1n),o=pe(n,s);if(o===null)return !1;let i=(r&128)!==0;return !(o===0n&&i)}function he(e){let r=e.toString(16);return r.length===1?`0${r}`:r}function ye(e){let t=`0x${e.reduce((n,s,o)=>`${he(o===31?s&-129:s)}${n}`,"")}`;return BigInt(t)}async function W(e){if(e.byteLength!==32)return !1;let r=ye(e);return j(r,e[31])}function qe(e){return Array.isArray(e)&&e.length===2&&typeof e[0]=="string"&&typeof e[1]=="number"&&e[1]>=0&&e[1]<=255&&M(e[0])}function Ze(e){if(!(Array.isArray(e)&&e.length===2&&typeof e[0]=="string"&&typeof e[1]=="number"))throw new Error("Expected given program derived address to have the following format: [Base58EncodedAddress, ProgramDerivedAddressBump].");if(e[1]<0||e[1]>255)throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${e[1]}.`);w(e[0]);}var Z=32,q=16,b=[80,114,111,103,114,97,109,68,101,114,105,118,101,100,65,100,100,114,101,115,115],E=class extends Error{};async function xe({programAddress:e,seeds:r}){if(await H(),r.length>q)throw new Error(`A maximum of ${q} seeds may be supplied when creating an address`);let t,n=r.reduce((d,c,f)=>{let g=typeof c=="string"?(t||(t=new TextEncoder)).encode(c):c;if(g.byteLength>Z)throw new Error(`The seed at index ${f} exceeds the maximum length of 32 bytes`);return d.push(...g),d},[]),s=S(),o=s.encode(e),i=await crypto.subtle.digest("SHA-256",new Uint8Array([...n,...o,...b])),a=new Uint8Array(i);if(await W(a))throw new E("Invalid seeds; point must fall off the Ed25519 curve");return s.decode(a)[0]}async function Ye({programAddress:e,seeds:r}){let t=255;for(;t>0;)try{return [await xe({programAddress:e,seeds:[...r,new Uint8Array([t])]}),t]}catch(n){if(n instanceof E)t--;else throw n}throw new Error("Unable to find a viable program address bump seed")}async function Je({baseAddress:e,programAddress:r,seed:t}){let{encode:n,decode:s}=S(),o=typeof t=="string"?new TextEncoder().encode(t):t;if(o.byteLength>Z)throw new Error("The seed exceeds the maximum length of 32 bytes");let i=n(r);if(i.length>=b.length&&i.slice(-b.length).every((c,f)=>c===b[f]))throw new Error("programAddress cannot end with the PDA marker");let a=await crypto.subtle.digest("SHA-256",new Uint8Array([...n(e),...o,...i])),d=new Uint8Array(a);return s(d)[0]}async function or(e){if(await V(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let r=await crypto.subtle.exportKey("raw",e),[t]=B().decode(new Uint8Array(r));return t}
exports.address = br;
exports.assertIsAddress = N;
exports.assertIsProgramDerivedAddress = Ur;
exports.createAddressWithSeed = Lr;
exports.getAddressCodec = w;
exports.getAddressComparator = wr;
exports.getAddressFromPublicKey = Xr;
exports.getProgramDerivedAddress = Rr;
exports.isAddress = O;
exports.isProgramDerivedAddress = $r;
exports.address = ge;
exports.assertIsAddress = w;
exports.assertIsProgramDerivedAddress = Ze;
exports.createAddressWithSeed = Je;
exports.getAddressCodec = S;
exports.getAddressComparator = Fe;
exports.getAddressDecoder = B;
exports.getAddressEncoder = ue;
exports.getAddressFromPublicKey = or;
exports.getProgramDerivedAddress = Ye;
exports.isAddress = M;
exports.isProgramDerivedAddress = qe;

@@ -19,0 +21,0 @@ return exports;

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

import { Serializer } from '@metaplex-foundation/umi-serializers';
import { Codec, Decoder, Encoder } from '@solana/codecs-core';
export type Base58EncodedAddress<TAddress extends string = string> = TAddress & {

@@ -8,6 +8,12 @@ readonly __brand: unique symbol;

export declare function address<TAddress extends string = string>(putativeBase58EncodedAddress: TAddress): Base58EncodedAddress<TAddress>;
export declare function getAddressEncoder(config?: Readonly<{
description: string;
}>): Encoder<Base58EncodedAddress>;
export declare function getAddressDecoder(config?: Readonly<{
description: string;
}>): Decoder<Base58EncodedAddress>;
export declare function getAddressCodec(config?: Readonly<{
description: string;
}>): Serializer<Base58EncodedAddress>;
}>): Codec<Base58EncodedAddress>;
export declare function getAddressComparator(): (x: string, y: string) => number;
//# sourceMappingURL=address.d.ts.map
{
"name": "@solana/addresses",
"version": "2.0.0-experimental.c237089",
"version": "2.0.0-experimental.c7ef49c",
"description": "Helpers for generating account addresses",

@@ -52,4 +52,5 @@ "exports": {

"dependencies": {
"@metaplex-foundation/umi-serializers": "^0.8.9",
"@solana/assertions": "2.0.0-experimental.c237089"
"@solana/assertions": "2.0.0-experimental.c7ef49c",
"@solana/codecs-core": "2.0.0-experimental.c7ef49c",
"@solana/codecs-strings": "2.0.0-experimental.c7ef49c"
},

@@ -91,3 +92,3 @@ "devDependencies": {

"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",

@@ -94,0 +95,0 @@ "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.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

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