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

@solana/addresses

Package Overview
Dependencies
Maintainers
12
Versions
1295
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.7a52c02 to 2.0.0-experimental.7b33fcb

dist/types/computed-address.d.ts

46

dist/index.browser.js

@@ -6,2 +6,17 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
function isBase58EncodedAddress(putativeBase58EncodedAddress) {
if (
// Lowest address (32 bytes of zeroes)
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
putativeBase58EncodedAddress.length > 44
) {
return false;
}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;
if (numBytes !== 32) {
return false;
}
return true;
}
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {

@@ -27,2 +42,6 @@ try {

}
function address(putativeBase58EncodedAddress) {
assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
return putativeBase58EncodedAddress;
}
function getBase58EncodedAddressCodec(config) {

@@ -136,3 +155,3 @@ return string({

// src/program-derived-address.ts
// src/computed-address.ts
var MAX_SEED_LENGTH = 32;

@@ -213,3 +232,24 @@ var MAX_SEEDS = 16;

}
async function getBase58EncodedAddressFromPublicKey(publicKey) {
async function createAddressWithSeed({
baseAddress,
programAddress,
seed
}) {
const { serialize, deserialize } = getBase58EncodedAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
}
const programAddressBytes = serialize(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
throw new Error(`programAddress cannot end with the PDA marker`);
}
const addressBytesBuffer = await crypto.subtle.digest(
"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
}
async function getAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();

@@ -224,4 +264,4 @@ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {

export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, getProgramDerivedAddress };
export { address, assertIsBase58EncodedAddress, createAddressWithSeed, getAddressFromPublicKey, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getProgramDerivedAddress, isBase58EncodedAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

77

dist/index.development.js

@@ -12,3 +12,3 @@ this.globalThis = this.globalThis || {};

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
// ../../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) => {

@@ -33,3 +33,3 @@ const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
// ../../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 {

@@ -48,3 +48,3 @@ constructor(serializer) {

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.2/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
// ../../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) {

@@ -70,3 +70,3 @@ return {

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
// ../../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 {

@@ -81,3 +81,3 @@ constructor(value, base, cause) {

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
// ../../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) => {

@@ -136,6 +136,6 @@ const base = alphabet.length;

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
// ../../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.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
var removeNullCharacters = (value) => (

@@ -146,3 +146,3 @@ // eslint-disable-next-line no-control-regex

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.2/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
var utf8 = {

@@ -161,3 +161,3 @@ description: "utf8",

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
var Endian;

@@ -169,3 +169,3 @@ (function(Endian2) {

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
// ../../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 {

@@ -178,3 +178,3 @@ constructor(serializer, min, max, actual) {

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
// ../../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) {

@@ -223,3 +223,3 @@ let littleEndian;

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.2/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
// ../../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({

@@ -234,3 +234,3 @@ name: "u32",

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
function getSizeDescription(size) {

@@ -240,3 +240,3 @@ return typeof size === "object" ? size.description : `${size}`;

// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.5/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
function string(options = {}) {

@@ -283,2 +283,17 @@ const size = options.size ?? u32();

// src/base58.ts
function isBase58EncodedAddress(putativeBase58EncodedAddress) {
if (
// Lowest address (32 bytes of zeroes)
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
putativeBase58EncodedAddress.length > 44
) {
return false;
}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;
if (numBytes !== 32) {
return false;
}
return true;
}
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {

@@ -304,2 +319,6 @@ try {

}
function address(putativeBase58EncodedAddress) {
assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
return putativeBase58EncodedAddress;
}
function getBase58EncodedAddressCodec(config) {

@@ -434,3 +453,3 @@ return string({

// src/program-derived-address.ts
// src/computed-address.ts
var MAX_SEED_LENGTH = 32;

@@ -511,5 +530,26 @@ var MAX_SEEDS = 16;

}
async function createAddressWithSeed({
baseAddress,
programAddress,
seed
}) {
const { serialize, deserialize } = getBase58EncodedAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
}
const programAddressBytes = serialize(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
throw new Error(`programAddress cannot end with the PDA marker`);
}
const addressBytesBuffer = await crypto.subtle.digest(
"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
}
// src/public-key.ts
async function getBase58EncodedAddressFromPublicKey(publicKey) {
async function getAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();

@@ -524,7 +564,10 @@ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {

exports.address = address;
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
exports.createAddressWithSeed = createAddressWithSeed;
exports.getAddressFromPublicKey = getAddressFromPublicKey;
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
exports.getBase58EncodedAddressFromPublicKey = getBase58EncodedAddressFromPublicKey;
exports.getProgramDerivedAddress = getProgramDerivedAddress;
exports.isBase58EncodedAddress = isBase58EncodedAddress;

@@ -531,0 +574,0 @@ return exports;

@@ -6,2 +6,17 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
function isBase58EncodedAddress(putativeBase58EncodedAddress) {
if (
// Lowest address (32 bytes of zeroes)
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
putativeBase58EncodedAddress.length > 44
) {
return false;
}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;
if (numBytes !== 32) {
return false;
}
return true;
}
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {

@@ -27,2 +42,6 @@ try {

}
function address(putativeBase58EncodedAddress) {
assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
return putativeBase58EncodedAddress;
}
function getBase58EncodedAddressCodec(config) {

@@ -136,3 +155,3 @@ return string({

// src/program-derived-address.ts
// src/computed-address.ts
var MAX_SEED_LENGTH = 32;

@@ -213,3 +232,24 @@ var MAX_SEEDS = 16;

}
async function getBase58EncodedAddressFromPublicKey(publicKey) {
async function createAddressWithSeed({
baseAddress,
programAddress,
seed
}) {
const { serialize, deserialize } = getBase58EncodedAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
}
const programAddressBytes = serialize(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
throw new Error(`programAddress cannot end with the PDA marker`);
}
const addressBytesBuffer = await crypto.subtle.digest(
"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
}
async function getAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();

@@ -224,4 +264,4 @@ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {

export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, getProgramDerivedAddress };
export { address, assertIsBase58EncodedAddress, createAddressWithSeed, getAddressFromPublicKey, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getProgramDerivedAddress, isBase58EncodedAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map

@@ -6,2 +6,17 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")();
function isBase58EncodedAddress(putativeBase58EncodedAddress) {
if (
// Lowest address (32 bytes of zeroes)
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
putativeBase58EncodedAddress.length > 44
) {
return false;
}
const bytes = base58.serialize(putativeBase58EncodedAddress);
const numBytes = bytes.byteLength;
if (numBytes !== 32) {
return false;
}
return true;
}
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {

@@ -27,2 +42,6 @@ try {

}
function address(putativeBase58EncodedAddress) {
assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
return putativeBase58EncodedAddress;
}
function getBase58EncodedAddressCodec(config) {

@@ -136,3 +155,3 @@ return string({

// src/program-derived-address.ts
// src/computed-address.ts
var MAX_SEED_LENGTH = 32;

@@ -213,3 +232,24 @@ var MAX_SEEDS = 16;

}
async function getBase58EncodedAddressFromPublicKey(publicKey) {
async function createAddressWithSeed({
baseAddress,
programAddress,
seed
}) {
const { serialize, deserialize } = getBase58EncodedAddressCodec();
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
}
const programAddressBytes = serialize(programAddress);
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
throw new Error(`programAddress cannot end with the PDA marker`);
}
const addressBytesBuffer = await crypto.subtle.digest(
"SHA-256",
new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
);
const addressBytes = new Uint8Array(addressBytesBuffer);
return deserialize(addressBytes)[0];
}
async function getAddressFromPublicKey(publicKey) {
await assertKeyExporterIsAvailable();

@@ -224,4 +264,4 @@ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {

export { assertIsBase58EncodedAddress, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getBase58EncodedAddressFromPublicKey, getProgramDerivedAddress };
export { address, assertIsBase58EncodedAddress, createAddressWithSeed, getAddressFromPublicKey, getBase58EncodedAddressCodec, getBase58EncodedAddressComparator, getProgramDerivedAddress, isBase58EncodedAddress };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map

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

var X=Object.defineProperty;var M=(e,r,t)=>r in e?X(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var x=(e,r,t)=>(M(e,typeof r!="symbol"?r+"":r,t),t);var v=e=>{let r=e.reduce((i,o)=>i+o.length,0),t=new Uint8Array(r),n=0;return e.forEach(i=>{t.set(i,n),n+=i.length;}),t},_=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},h=(e,r)=>_(e.slice(0,r),r);var b=class extends Error{constructor(t){super(`Serializer [${t}] cannot deserialize empty buffers.`);x(this,"name","DeserializingEmptyBufferError");}},y=class extends Error{constructor(t,n,i){super(`Serializer [${t}] expected ${n} bytes, got ${i}.`);x(this,"name","NotEnoughBytesError");}};function I(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:n=>h(e.serialize(n),r),deserialize:(n,i=0)=>{if(n=n.slice(i,i+r),n.length<r)throw new y("fixSerializer",r,n.length);e.fixedSize!==null&&(n=h(n,e.fixedSize));let[o]=e.deserialize(n,0);return [o,i+r]}}}var E=class extends Error{constructor(t,n,i){let o=`Expected a string of base ${n}, got [${t}].`;super(o);x(this,"name","InvalidBaseStringError");this.cause=i;}};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 E(n,r);if(n==="")return new Uint8Array;let i=[...n],o=i.findIndex(d=>d!==e[0]);o=o===-1?i.length:o;let s=Array(o).fill(0);if(o===i.length)return Uint8Array.from(s);let f=i.slice(o),c=0n,l=1n;for(let d=f.length-1;d>=0;d-=1)c+=l*BigInt(e.indexOf(f[d])),l*=t;let u=[];for(;c>0n;)u.unshift(Number(c%256n)),c/=256n;return Uint8Array.from(s.concat(u))},deserialize(n,i=0){if(n.length===0)return ["",0];let o=n.slice(i),s=o.findIndex(u=>u!==0);s=s===-1?o.length:s;let f=e[0].repeat(s);if(s===o.length)return [f,n.length];let c=o.slice(s).reduce((u,d)=>u*256n+BigInt(d),0n),l=[];for(;c>0n;)l.unshift(e[Number(c%t)]),c/=t;return [f+l.join(""),n.length]}}};var w=$("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var T=e=>e.replace(/\u0000/g,"");var C={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 [T(t),e.length]}};var z;(function(e){e.Little="le",e.Big="be";})(z||(z={}));var S=class extends RangeError{constructor(t,n,i,o){super(`Serializer [${t}] expected number to be between ${n} and ${i}, got ${o}.`);x(this,"name","NumberOutOfRangeError");}};function U(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&&H(e.name,e.range[0],e.range[1],n);let i=new ArrayBuffer(e.size);return e.set(new DataView(i),n,r),new Uint8Array(i)},deserialize(n,i=0){let o=n.slice(i,i+e.size);W("i8",o,e.size);let s=G(o);return [e.get(s,r),i+e.size]}}}var j=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),G=e=>new DataView(j(e)),H=(e,r,t,n)=>{if(n<r||n>t)throw new S(e,r,t,n)},W=(e,r,t)=>{if(r.length===0)throw new b(e);if(r.length<t)throw new y(e,t,r.length)};var D=(e={})=>U({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 R(e){return typeof e=="object"?e.description:`${e}`}function N(e={}){let r=e.size??D(),t=e.encoding??C,n=e.description??`string(${t.description}; ${R(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?I(t,r,n):{description:n,fixedSize:null,maxSize:null,serialize:i=>{let o=t.serialize(i),s=r.serialize(o.length);return v([s,o])},deserialize:(i,o=0)=>{if(i.slice(o).length===0)throw new b("string");let[s,f]=r.deserialize(i,o),c=Number(s);o=f;let l=i.slice(o,o+c);if(l.length<c)throw new y("string",c,l.length);let[u,d]=t.deserialize(l);return o+=d,[u,o]}}}function xr(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=w.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 A(e){return N({description:e?.description??"",encoding:w,size:32})}function br(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function P(){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 O(){if(P(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.digest!="function")throw new Error("No digest implementation could be found")}async function L(){if(P(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}var Z=37095705934669439343138083508754565189542113879843219016388785533085940283555n,p=57896044618658097711785492504343953926634992332820282019728792003956564819949n,K=19681161376707505956807079304988542015446066515923890162744021073123829784752n;function m(e){let r=e%p;return r>=0n?r:p+r}function g(e,r){let t=e;for(;r-- >0n;)t*=t,t%=p;return t}function q(e){let t=e*e%p*e%p,n=g(t,2n)*t%p,i=g(n,1n)*e%p,o=g(i,5n)*i%p,s=g(o,10n)*o%p,f=g(s,20n)*s%p,c=g(f,40n)*f%p,l=g(c,80n)*c%p,u=g(l,80n)*c%p,d=g(u,10n)*o%p;return g(d,2n)*e%p}function Y(e,r){let t=m(r*r*r),n=m(t*t*r),i=q(e*n),o=m(e*t*i),s=m(r*o*o),f=o,c=m(o*K),l=s===e,u=s===m(-e),d=s===m(-e*K);return l&&(o=f),(u||d)&&(o=c),(m(o)&1n)===1n&&(o=m(-o)),!l&&!u?null:o}function k(e,r){let t=m(e*e),n=m(t-1n),i=m(Z*t+1n),o=Y(n,i);if(o===null)return !1;let s=(r&128)!==0;return !(o===0n&&s)}function J(e){let r=e.toString(16);return r.length===1?`0${r}`:r}function Q(e){let t=`0x${e.reduce((n,i,o)=>`${J(o===31?i&-129:i)}${n}`,"")}`;return BigInt(t)}async function V(e){if(e.byteLength!==32)return !1;let r=Q(e);return k(r,e[31])}var ee=32,F=16,re=[80,114,111,103,114,97,109,68,101,114,105,118,101,100,65,100,100,114,101,115,115],B=class extends Error{};async function te({programAddress:e,seeds:r}){if(await O(),r.length>F)throw new Error(`A maximum of ${F} seeds may be supplied when creating an address`);let t,n=r.reduce((c,l,u)=>{let d=typeof l=="string"?(t||(t=new TextEncoder)).encode(l):l;if(d.byteLength>ee)throw new Error(`The seed at index ${u} exceeds the maximum length of 32 bytes`);return c.push(...d),c},[]),i=A(),o=i.serialize(e),s=await crypto.subtle.digest("SHA-256",new Uint8Array([...n,...o,...re])),f=new Uint8Array(s);if(await V(f))throw new B("Invalid seeds; point must fall off the Ed25519 curve");return i.deserialize(f)[0]}async function $r({programAddress:e,seeds:r}){let t=255;for(;t>0;)try{return {bumpSeed:t,pda:await te({programAddress:e,seeds:[...r,new Uint8Array([t])]})}}catch(n){if(n instanceof B)t--;else throw n}throw new Error("Unable to find a viable program address bump seed")}async function Lr(e){if(await L(),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]=A().deserialize(new Uint8Array(r));return t}
var j=Object.defineProperty;var H=(e,r,t)=>r in e?j(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t;var x=(e,r,t)=>(H(e,typeof r!="symbol"?r+"":r,t),t);var I=e=>{let r=e.reduce((i,o)=>i+o.length,0),t=new Uint8Array(r),n=0;return e.forEach(i=>{t.set(i,n),n+=i.length;}),t},_=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},w=(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,i){super(`Serializer [${t}] expected ${n} bytes, got ${i}.`);x(this,"name","NotEnoughBytesError");}};function T(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:n=>w(e.serialize(n),r),deserialize:(n,i=0)=>{if(n=n.slice(i,i+r),n.length<r)throw new y("fixSerializer",r,n.length);e.fixedSize!==null&&(n=w(n,e.fixedSize));let[o]=e.deserialize(n,0);return [o,i+r]}}}var A=class extends Error{constructor(t,n,i){let o=`Expected a string of base ${n}, got [${t}].`;super(o);x(this,"name","InvalidBaseStringError");this.cause=i;}};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 i=[...n],o=i.findIndex(u=>u!==e[0]);o=o===-1?i.length:o;let s=Array(o).fill(0);if(o===i.length)return Uint8Array.from(s);let l=i.slice(o),c=0n,d=1n;for(let u=l.length-1;u>=0;u-=1)c+=d*BigInt(e.indexOf(l[u])),d*=t;let f=[];for(;c>0n;)f.unshift(Number(c%256n)),c/=256n;return Uint8Array.from(s.concat(f))},deserialize(n,i=0){if(n.length===0)return ["",0];let o=n.slice(i),s=o.findIndex(f=>f!==0);s=s===-1?o.length:s;let l=e[0].repeat(s);if(s===o.length)return [l,n.length];let c=o.slice(s).reduce((f,u)=>f*256n+BigInt(u),0n),d=[];for(;c>0n;)d.unshift(e[Number(c%t)]),c/=t;return [l+d.join(""),n.length]}}};var b=$("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var U=e=>e.replace(/\u0000/g,"");var C={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,i,o){super(`Serializer [${t}] expected number to be between ${n} and ${i}, 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&&Z(e.name,e.range[0],e.range[1],n);let i=new ArrayBuffer(e.size);return e.set(new DataView(i),n,r),new Uint8Array(i)},deserialize(n,i=0){let o=n.slice(i,i+e.size);q("i8",o,e.size);let s=W(o);return [e.get(s,r),i+e.size]}}}var G=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),W=e=>new DataView(G(e)),Z=(e,r,t,n)=>{if(n<r||n>t)throw new S(e,r,t,n)},q=(e,r,t)=>{if(r.length===0)throw new h(e);if(r.length<t)throw new y(e,t,r.length)};var D=(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 P(e){return typeof e=="object"?e.description:`${e}`}function N(e={}){let r=e.size??D(),t=e.encoding??C,n=e.description??`string(${t.description}; ${P(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?T(t,r,n):{description:n,fixedSize:null,maxSize:null,serialize:i=>{let o=t.serialize(i),s=r.serialize(o.length);return I([s,o])},deserialize:(i,o=0)=>{if(i.slice(o).length===0)throw new h("string");let[s,l]=r.deserialize(i,o),c=Number(s);o=l;let d=i.slice(o,o+c);if(d.length<c)throw new y("string",c,d.length);let[f,u]=t.deserialize(d);return o+=u,[f,o]}}}function hr(e){return !(e.length<32||e.length>44||b.serialize(e).byteLength!==32)}function Y(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 Y(e),e}function E(e){return N({description:e?.description??"",encoding:b,size:32})}function Er(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function L(){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 O(){if(L(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.digest!="function")throw new Error("No digest implementation could be found")}async function k(){if(L(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}var J=37095705934669439343138083508754565189542113879843219016388785533085940283555n,p=57896044618658097711785492504343953926634992332820282019728792003956564819949n,K=19681161376707505956807079304988542015446066515923890162744021073123829784752n;function m(e){let r=e%p;return r>=0n?r:p+r}function g(e,r){let t=e;for(;r-- >0n;)t*=t,t%=p;return t}function Q(e){let t=e*e%p*e%p,n=g(t,2n)*t%p,i=g(n,1n)*e%p,o=g(i,5n)*i%p,s=g(o,10n)*o%p,l=g(s,20n)*s%p,c=g(l,40n)*l%p,d=g(c,80n)*c%p,f=g(d,80n)*c%p,u=g(f,10n)*o%p;return g(u,2n)*e%p}function ee(e,r){let t=m(r*r*r),n=m(t*t*r),i=Q(e*n),o=m(e*t*i),s=m(r*o*o),l=o,c=m(o*K),d=s===e,f=s===m(-e),u=s===m(-e*K);return d&&(o=l),(f||u)&&(o=c),(m(o)&1n)===1n&&(o=m(-o)),!d&&!f?null:o}function V(e,r){let t=m(e*e),n=m(t-1n),i=m(J*t+1n),o=ee(n,i);if(o===null)return !1;let s=(r&128)!==0;return !(o===0n&&s)}function re(e){let r=e.toString(16);return r.length===1?`0${r}`:r}function te(e){let t=`0x${e.reduce((n,i,o)=>`${re(o===31?i&-129:i)}${n}`,"")}`;return BigInt(t)}async function F(e){if(e.byteLength!==32)return !1;let r=te(e);return V(r,e[31])}var M=32,X=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 ne({programAddress:e,seeds:r}){if(await O(),r.length>X)throw new Error(`A maximum of ${X} seeds may be supplied when creating an address`);let t,n=r.reduce((c,d,f)=>{let u=typeof d=="string"?(t||(t=new TextEncoder)).encode(d):d;if(u.byteLength>M)throw new Error(`The seed at index ${f} exceeds the maximum length of 32 bytes`);return c.push(...u),c},[]),i=E(),o=i.serialize(e),s=await crypto.subtle.digest("SHA-256",new Uint8Array([...n,...o,...B])),l=new Uint8Array(s);if(await F(l))throw new v("Invalid seeds; point must fall off the Ed25519 curve");return i.deserialize(l)[0]}async function Ur({programAddress:e,seeds:r}){let t=255;for(;t>0;)try{return {bumpSeed:t,pda:await ne({programAddress:e,seeds:[...r,new Uint8Array([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 Rr({baseAddress:e,programAddress:r,seed:t}){let{serialize:n,deserialize:i}=E(),o=typeof t=="string"?new TextEncoder().encode(t):t;if(o.byteLength>M)throw new Error("The seed exceeds the maximum length of 32 bytes");let s=n(r);if(s.length>=B.length&&s.slice(-B.length).every((d,f)=>d===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,...s])),c=new Uint8Array(l);return i(c)[0]}async function Vr(e){if(await k(),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]=E().deserialize(new Uint8Array(r));return t}
exports.assertIsBase58EncodedAddress = xr;
exports.getBase58EncodedAddressCodec = A;
exports.getBase58EncodedAddressComparator = br;
exports.getBase58EncodedAddressFromPublicKey = Lr;
exports.getProgramDerivedAddress = $r;
exports.address = br;
exports.assertIsBase58EncodedAddress = Y;
exports.createAddressWithSeed = Rr;
exports.getAddressFromPublicKey = Vr;
exports.getBase58EncodedAddressCodec = E;
exports.getBase58EncodedAddressComparator = Er;
exports.getProgramDerivedAddress = Ur;
exports.isBase58EncodedAddress = hr;

@@ -14,0 +17,0 @@ return exports;

import { Serializer } from '@metaplex-foundation/umi-serializers';
export type Base58EncodedAddress<TAddress extends string = string> = TAddress & {
readonly __base58EncodedAddress: unique symbol;
readonly __brand: unique symbol;
};
export declare function isBase58EncodedAddress(putativeBase58EncodedAddress: string): putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;
export declare function assertIsBase58EncodedAddress(putativeBase58EncodedAddress: string): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;
export declare function address<TAddress extends string = string>(putativeBase58EncodedAddress: TAddress): Base58EncodedAddress<TAddress>;
export declare function getBase58EncodedAddressCodec(config?: Readonly<{

@@ -7,0 +9,0 @@ description: string;

export * from './base58';
export * from './program-derived-address';
export * from './computed-address';
export * from './public-key';
//# sourceMappingURL=index.d.ts.map
import { Base58EncodedAddress } from './base58';
export declare function getBase58EncodedAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress>;
export declare function getAddressFromPublicKey(publicKey: CryptoKey): Promise<Base58EncodedAddress>;
//# sourceMappingURL=public-key.d.ts.map
{
"name": "@solana/addresses",
"version": "2.0.0-experimental.7a52c02",
"version": "2.0.0-experimental.7b33fcb",
"description": "Helpers for generating account addresses",

@@ -52,11 +52,11 @@ "exports": {

"dependencies": {
"@metaplex-foundation/umi-serializers": "^0.8.5",
"@solana/assertions": "2.0.0-experimental.7a52c02"
"@metaplex-foundation/umi-serializers": "^0.8.9",
"@solana/assertions": "2.0.0-experimental.7b33fcb"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.2",
"@swc/jest": "^0.2.27",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@swc/jest": "^0.2.28",
"@types/jest": "^29.5.5",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.3.0",
"agadoo": "^3.0.0",

@@ -66,9 +66,9 @@ "eslint": "^8.45.0",

"eslint-plugin-sort-keys-fix": "^1.1.2",
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.6.4",
"jest-runner-eslint": "^2.1.0",
"jest-runner-prettier": "^1.0.0",
"prettier": "^3.0.1",
"prettier": "^2.8",
"tsup": "7.2.0",
"typescript": "^5.1.6",
"typescript": "^5.2.2",
"version-from-git": "^1.1.1",

@@ -92,7 +92,8 @@ "build-scripts": "0.0.0",

"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*",
"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",

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

@@ -54,3 +54,3 @@ [![npm][npm-image]][npm-url]

### `getBase58EncodedAddressFromPublicKey()`
### `getAddressFromPublicKey()`

@@ -60,5 +60,5 @@ Given a public `CryptoKey`, this method will return its associated `Base58EncodedAddress`.

```ts
import { getBase58EncodedAddressFromPublicKey } from '@solana/addresses';
import { getAddressFromPublicKey } from '@solana/addresses';
const address = await getBase58EncodedAddressFromPublicKey(publicKey);
const address = await getAddressFromPublicKey(publicKey);
```

@@ -65,0 +65,0 @@

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