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
1331
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.805f482 to 2.0.0-experimental.82bbf6f

dist/types/computed-address.d.ts

29

dist/index.browser.js

@@ -134,3 +134,3 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

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

@@ -211,3 +211,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();

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

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

56

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 = {}) {

@@ -432,3 +432,3 @@ const size = options.size ?? u32();

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

@@ -509,5 +509,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();

@@ -523,5 +544,6 @@ if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {

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

@@ -528,0 +550,0 @@

@@ -134,3 +134,3 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

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

@@ -211,3 +211,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();

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

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

@@ -134,3 +134,3 @@ import { base58, string } from '@metaplex-foundation/umi-serializers';

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

@@ -211,3 +211,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();

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

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

@@ -5,9 +5,10 @@ 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},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,i){super(`Serializer [${t}] expected ${n} bytes, got ${i}.`);x(this,"name","NotEnoughBytesError");}};function C(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:n=>E(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=E(n,e.fixedSize));let[o]=e.deserialize(n,0);return [o,i+r]}}}var w=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 w(n,r);if(n==="")return new Uint8Array;let i=[...n],o=i.findIndex(p=>p!==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 p=l.length-1;p>=0;p-=1)c+=d*BigInt(e.indexOf(l[p])),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,p)=>f*256n+BigInt(p),0n),d=[];for(;c>0n;)d.unshift(e[Number(c%t)]),c/=t;return [l+d.join(""),n.length]}}};var z=$("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var U=e=>e.replace(/\u0000/g,"");var D={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 S;(function(e){e.Little="le",e.Big="be";})(S||(S={}));var A=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===S.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 A(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 N=(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 T(e={}){let r=e.size??N(),t=e.encoding??D,n=e.description??`string(${t.description}; ${P(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?C(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,p]=t.deserialize(d);return o+=p,[f,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=z.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 b(e){return T({description:e?.description??"",encoding:z,size:32})}function hr(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}function O(){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 L(){if(O(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.digest!="function")throw new Error("No digest implementation could be found")}async function k(){if(O(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}var Y=37095705934669439343138083508754565189542113879843219016388785533085940283555n,u=57896044618658097711785492504343953926634992332820282019728792003956564819949n,K=19681161376707505956807079304988542015446066515923890162744021073123829784752n;function m(e){let r=e%u;return r>=0n?r:u+r}function g(e,r){let t=e;for(;r-- >0n;)t*=t,t%=u;return t}function J(e){let t=e*e%u*e%u,n=g(t,2n)*t%u,i=g(n,1n)*e%u,o=g(i,5n)*i%u,s=g(o,10n)*o%u,l=g(s,20n)*s%u,c=g(l,40n)*l%u,d=g(c,80n)*c%u,f=g(d,80n)*c%u,p=g(f,10n)*o%u;return g(p,2n)*e%u}function Q(e,r){let t=m(r*r*r),n=m(t*t*r),i=J(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),p=s===m(-e*K);return d&&(o=l),(f||p)&&(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(Y*t+1n),o=Q(n,i);if(o===null)return !1;let s=(r&128)!==0;return !(o===0n&&s)}function ee(e){let r=e.toString(16);return r.length===1?`0${r}`:r}function re(e){let t=`0x${e.reduce((n,i,o)=>`${ee(o===31?i&-129:i)}${n}`,"")}`;return BigInt(t)}async function F(e){if(e.byteLength!==32)return !1;let r=re(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 te({programAddress:e,seeds:r}){if(await L(),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 p=typeof d=="string"?(t||(t=new TextEncoder)).encode(d):d;if(p.byteLength>M)throw new Error(`The seed at index ${f} exceeds the maximum length of 32 bytes`);return c.push(...p),c},[]),i=b(),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 _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 v)t--;else throw n}throw new Error("Unable to find a viable program address bump seed")}async function $r({baseAddress:e,programAddress:r,seed:t}){let{serialize:n,deserialize:i}=b(),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 kr(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]=b().deserialize(new Uint8Array(r));return t}
exports.assertIsBase58EncodedAddress = xr;
exports.getBase58EncodedAddressCodec = A;
exports.getBase58EncodedAddressComparator = br;
exports.getBase58EncodedAddressFromPublicKey = Lr;
exports.getProgramDerivedAddress = $r;
exports.createAddressWithSeed = $r;
exports.getAddressFromPublicKey = kr;
exports.getBase58EncodedAddressCodec = b;
exports.getBase58EncodedAddressComparator = hr;
exports.getProgramDerivedAddress = _r;

@@ -14,0 +15,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;
};

@@ -5,0 +5,0 @@ export declare function assertIsBase58EncodedAddress(putativeBase58EncodedAddress: string): asserts putativeBase58EncodedAddress is Base58EncodedAddress<typeof putativeBase58EncodedAddress>;

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.805f482",
"version": "2.0.0-experimental.82bbf6f",
"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.805f482"
"@metaplex-foundation/umi-serializers": "^0.8.9",
"@solana/assertions": "2.0.0-experimental.82bbf6f"
},
"devDependencies": {
"@solana/eslint-config-solana": "^1.0.2",
"@swc/jest": "^0.2.27",
"@swc/jest": "^0.2.28",
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^6.3.0",
"@typescript-eslint/parser": "^6.3.0",
"agadoo": "^3.0.0",

@@ -67,6 +67,6 @@ "eslint": "^8.45.0",

"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.2",
"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",

@@ -92,2 +92,3 @@ "typescript": "^5.1.6",

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

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