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

@solana/signers

Package Overview
Dependencies
Maintainers
14
Versions
998
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/signers - npm Package Compare versions

Comparing version 2.0.0-experimental.0eb69ae to 2.0.0-experimental.0f3404a

dist/types/add-signers.d.ts

95

dist/index.browser.js

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

import { isSignerRole } from '@solana/instructions';
import { getAddressFromPublicKey, isAddress } from '@solana/addresses';

@@ -11,2 +12,6 @@ import { generateKeyPair, signBytes } from '@solana/keys';

deduplicated[signer.address] = signer;
} else if (deduplicated[signer.address] !== signer) {
throw new Error(
`Multiple distinct signers were identified for address "${signer.address}". Please ensure that you are using the same signer instance for each address.`
);
}

@@ -26,2 +31,27 @@ });

}
function addSignersToInstruction(signers, instruction) {
if (!instruction.accounts || instruction.accounts.length === 0) {
return instruction;
}
const signerByAddress = new Map(deduplicateSigners(signers).map((signer) => [signer.address, signer]));
return Object.freeze({
...instruction,
accounts: instruction.accounts.map((account) => {
const signer = signerByAddress.get(account.address);
if (!isSignerRole(account.role) || "signer" in account || !signer) {
return account;
}
return Object.freeze({ ...account, signer });
})
});
}
function addSignersToTransaction(signers, transaction) {
if (transaction.instructions.length === 0) {
return transaction;
}
return Object.freeze({
...transaction,
instructions: transaction.instructions.map((instruction) => addSignersToInstruction(signers, instruction))
});
}

@@ -140,5 +170,4 @@ // src/message-partial-signer.ts

async function partiallySignTransactionWithSigners(transaction, config = {}) {
const signers = config.signers ?? [];
const { partialSigners, modifyingSigners } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers]),
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner)),
{ identifySendingSigner: false }

@@ -154,6 +183,5 @@ );

async function signAndSendTransactionWithSigners(transaction, config = {}) {
const signers = config.signers ?? [];
const abortSignal = config.abortSignal;
const { partialSigners, modifyingSigners, sendingSigner } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers])
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner))
);

@@ -167,12 +195,11 @@ abortSignal?.throwIfAborted();

);
if (sendingSigner) {
abortSignal?.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
return signature;
if (!sendingSigner) {
throw new Error(
"No `TransactionSendingSigner` was identified. Please provide a valid `ITransactionWithSingleSendingSigner` transaction."
);
}
if (config.fallbackSender) {
assertTransactionIsFullySigned(signedTransaction);
return config.fallbackSender(signedTransaction);
}
throw new Error("No TransactionSendingSigner was identified and no fallback sender was provided.");
abortSignal?.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
abortSignal?.throwIfAborted();
return signature;
}

@@ -211,7 +238,10 @@ function categorizeTransactionSigners(signers, config = {}) {

async function signModifyingAndPartialTransactionSigners(transaction, modifyingSigners = [], partialSigners = [], abortSignal) {
const modifiedTransaction = await modifyingSigners.reduce(async (transaction2, modifyingSigner) => {
abortSignal?.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
}, Promise.resolve(transaction));
const modifiedTransaction = await modifyingSigners.reduce(
async (transaction2, modifyingSigner) => {
abortSignal?.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
},
Promise.resolve(transaction)
);
abortSignal?.throwIfAborted();

@@ -244,4 +274,31 @@ const signatureDictionaries = await Promise.all(

export { assertIsKeyPairSigner, assertIsMessageModifyingSigner, assertIsMessagePartialSigner, assertIsMessageSigner, assertIsTransactionModifyingSigner, assertIsTransactionPartialSigner, assertIsTransactionSendingSigner, assertIsTransactionSigner, createNoopSigner, createSignableMessage, createSignerFromKeyPair, generateKeyPairSigner, getSignersFromInstruction, getSignersFromTransaction, isKeyPairSigner, isMessageModifyingSigner, isMessagePartialSigner, isMessageSigner, isTransactionModifyingSigner, isTransactionPartialSigner, isTransactionSendingSigner, isTransactionSigner, partiallySignTransactionWithSigners, signAndSendTransactionWithSigners, signTransactionWithSigners };
// src/transaction-with-single-sending-signer.ts
function isTransactionWithSingleSendingSigner(transaction) {
try {
assertIsTransactionWithSingleSendingSigner(transaction);
return true;
} catch {
return false;
}
}
function assertIsTransactionWithSingleSendingSigner(transaction) {
const signers = getSignersFromTransaction(transaction);
const sendingSigners = signers.filter(isTransactionSendingSigner);
if (sendingSigners.length === 0) {
const error = new Error("No `TransactionSendingSigner` was identified.");
error.name = "MissingTransactionSendingSignerError";
throw error;
}
const sendingOnlySigners = sendingSigners.filter(
(signer) => !isTransactionPartialSigner(signer) && !isTransactionModifyingSigner(signer)
);
if (sendingOnlySigners.length > 1) {
const error = new Error("More than one `TransactionSendingSigner` was identified.");
error.name = "MultipleTransactionSendingSignersError";
throw error;
}
}
export { addSignersToInstruction, addSignersToTransaction, assertIsKeyPairSigner, assertIsMessageModifyingSigner, assertIsMessagePartialSigner, assertIsMessageSigner, assertIsTransactionModifyingSigner, assertIsTransactionPartialSigner, assertIsTransactionSendingSigner, assertIsTransactionSigner, assertIsTransactionWithSingleSendingSigner, createNoopSigner, createSignableMessage, createSignerFromKeyPair, generateKeyPairSigner, getSignersFromInstruction, getSignersFromTransaction, isKeyPairSigner, isMessageModifyingSigner, isMessagePartialSigner, isMessageSigner, isTransactionModifyingSigner, isTransactionPartialSigner, isTransactionSendingSigner, isTransactionSigner, isTransactionWithSingleSendingSigner, partiallySignTransactionWithSigners, signAndSendTransactionWithSigners, signTransactionWithSigners };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

799

dist/index.development.js

@@ -11,2 +11,6 @@ this.globalThis = this.globalThis || {};

deduplicated[signer.address] = signer;
} else if (deduplicated[signer.address] !== signer) {
throw new Error(
`Multiple distinct signers were identified for address "${signer.address}". Please ensure that you are using the same signer instance for each address.`
);
}

@@ -28,2 +32,34 @@ });

// ../instructions/dist/index.browser.js
function isSignerRole(role) {
return role >= 2;
}
// src/add-signers.ts
function addSignersToInstruction(signers, instruction) {
if (!instruction.accounts || instruction.accounts.length === 0) {
return instruction;
}
const signerByAddress = new Map(deduplicateSigners(signers).map((signer) => [signer.address, signer]));
return Object.freeze({
...instruction,
accounts: instruction.accounts.map((account) => {
const signer = signerByAddress.get(account.address);
if (!isSignerRole(account.role) || "signer" in account || !signer) {
return account;
}
return Object.freeze({ ...account, signer });
})
});
}
function addSignersToTransaction(signers, transaction) {
if (transaction.instructions.length === 0) {
return transaction;
}
return Object.freeze({
...transaction,
instructions: transaction.instructions.map((instruction) => addSignersToInstruction(signers, instruction))
});
}
// ../codecs-core/dist/index.browser.js

@@ -41,19 +77,2 @@ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {

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

@@ -67,19 +86,47 @@ if (bytes.length >= length)

var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
function fixCodecHelper(data, fixedBytes, description) {
return {
description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
function getEncodedSize(value, encoder) {
return "fixedSize" in encoder ? encoder.fixedSize : encoder.getSizeFromValue(value);
}
function createEncoder(encoder) {
return Object.freeze({
...encoder,
encode: (value) => {
const bytes = new Uint8Array(getEncodedSize(value, encoder));
encoder.write(value, bytes, 0);
return bytes;
}
});
}
function createDecoder(decoder) {
return Object.freeze({
...decoder,
decode: (bytes, offset = 0) => decoder.read(bytes, offset)[0]
});
}
function isFixedSize(codec) {
return "fixedSize" in codec && typeof codec.fixedSize === "number";
}
function assertIsFixedSize(codec, message) {
if (!isFixedSize(codec)) {
throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
}
}
function isVariableSize(codec) {
return !isFixedSize(codec);
}
function fixEncoder(encoder, fixedBytes) {
return createEncoder({
fixedSize: fixedBytes,
maxSize: fixedBytes
};
write: (value, bytes, offset) => {
const variableByteArray = encoder.encode(value);
const fixedByteArray = variableByteArray.length > fixedBytes ? variableByteArray.slice(0, fixedBytes) : variableByteArray;
bytes.set(fixedByteArray, offset);
return offset + fixedBytes;
}
});
}
function fixEncoder(encoder, fixedBytes, description) {
return {
...fixCodecHelper(encoder, fixedBytes, description),
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
};
}
function fixDecoder(decoder, fixedBytes, description) {
return {
...fixCodecHelper(decoder, fixedBytes, description),
decode: (bytes, offset = 0) => {
function fixDecoder(decoder, fixedBytes) {
return createDecoder({
fixedSize: fixedBytes,
read: (bytes, offset) => {
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);

@@ -89,17 +136,15 @@ if (offset > 0 || bytes.length > fixedBytes) {

}
if (decoder.fixedSize !== null) {
if (isFixedSize(decoder)) {
bytes = fixBytes(bytes, decoder.fixedSize);
}
const [value] = decoder.decode(bytes, 0);
const [value] = decoder.read(bytes, 0);
return [value, offset + fixedBytes];
}
};
});
}
function mapEncoder(encoder, unmap) {
return {
description: encoder.description,
encode: (value) => encoder.encode(unmap(value)),
fixedSize: encoder.fixedSize,
maxSize: encoder.maxSize
};
return createEncoder({
...isVariableSize(encoder) ? { ...encoder, getSizeFromValue: (value) => encoder.getSizeFromValue(unmap(value)) } : encoder,
write: (value, bytes, offset) => encoder.write(unmap(value), bytes, offset)
});
}

@@ -115,22 +160,9 @@

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

@@ -140,22 +172,18 @@ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);

const arrayBuffer = new ArrayBuffer(input.size);
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
return new Uint8Array(arrayBuffer);
},
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
input.set(new DataView(arrayBuffer), value, isLittleEndian(input.config));
bytes.set(new Uint8Array(arrayBuffer), offset);
return offset + input.size;
}
});
}
function numberDecoderFactory(input) {
const codecData = sharedNumberFactory(input);
return {
decode(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
return createDecoder({
fixedSize: input.size,
read(bytes, offset = 0) {
assertByteArrayIsNotEmptyForCodec(input.name, bytes, offset);
assertByteArrayHasEnoughBytesForCodec(input.name, input.size, bytes, offset);
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
return [input.get(view, codecData.littleEndian), offset + input.size];
},
description: codecData.description,
fixedSize: codecData.fixedSize,
maxSize: codecData.maxSize
};
return [input.get(view, isLittleEndian(input.config)), offset + input.size];
}
});
}

@@ -167,26 +195,29 @@ function toArrayBuffer(bytes, offset, length) {

}
var getShortU16Encoder = (config = {}) => {
var _a;
return {
description: (_a = config.description) != null ? _a : "shortU16",
encode: (value) => {
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
const bytes = [0];
for (let ii = 0; ; ii += 1) {
const alignedValue = value >> ii * 7;
if (alignedValue === 0) {
break;
}
const nextSevenBits = 127 & alignedValue;
bytes[ii] = nextSevenBits;
if (ii > 0) {
bytes[ii - 1] |= 128;
}
var getShortU16Encoder = () => createEncoder({
getSizeFromValue: (value) => {
if (value <= 127)
return 1;
if (value <= 16383)
return 2;
return 3;
},
maxSize: 3,
write: (value, bytes, offset) => {
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
const shortU16Bytes = [0];
for (let ii = 0; ; ii += 1) {
const alignedValue = value >> ii * 7;
if (alignedValue === 0) {
break;
}
return new Uint8Array(bytes);
},
fixedSize: null,
maxSize: 3
};
};
const nextSevenBits = 127 & alignedValue;
shortU16Bytes[ii] = nextSevenBits;
if (ii > 0) {
shortU16Bytes[ii - 1] |= 128;
}
}
bytes.set(shortU16Bytes, offset);
return offset + shortU16Bytes.length;
}
});
var getU32Encoder = (config = {}) => numberEncoderFactory({

@@ -205,4 +236,3 @@ config,

});
var getU8Encoder = (config = {}) => numberEncoderFactory({
config,
var getU8Encoder = () => numberEncoderFactory({
name: "u8",

@@ -221,23 +251,20 @@ range: [0, Number("0xff")],

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

@@ -248,13 +275,11 @@ while (base10Number > 0n) {

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

@@ -268,15 +293,25 @@ if (bytes.length === 0)

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

@@ -293,58 +328,56 @@ var getBase58Encoder = () => getBaseXEncoder(alphabet2);

let textEncoder;
return {
description: "utf8",
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
fixedSize: null,
maxSize: null
};
return createEncoder({
getSizeFromValue: (value) => (textEncoder || (textEncoder = new o())).encode(value).length,
write: (value, bytes, offset) => {
const bytesToAdd = (textEncoder || (textEncoder = new o())).encode(value);
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getUtf8Decoder = () => {
let textDecoder;
return {
decode(bytes, offset = 0) {
return createDecoder({
read(bytes, offset) {
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
return [removeNullCharacters(value), bytes.length];
},
description: "utf8",
fixedSize: null,
maxSize: null
};
}
});
};
var getStringEncoder = (config = {}) => {
var _a, _b, _c;
function getStringEncoder(config = {}) {
var _a, _b;
const size = (_a = config.size) != null ? _a : getU32Encoder();
const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixEncoder(encoding, size, description);
return fixEncoder(encoding, size);
}
return {
description,
encode: (value) => {
const contentBytes = encoding.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
return createEncoder({
getSizeFromValue: (value) => {
const contentSize = getEncodedSize(value, encoding);
return getEncodedSize(contentSize, size) + contentSize;
},
fixedSize: null,
maxSize: null
};
};
var getStringDecoder = (config = {}) => {
var _a, _b, _c;
write: (value, bytes, offset) => {
const contentSize = getEncodedSize(value, encoding);
offset = size.write(contentSize, bytes, offset);
return encoding.write(value, bytes, offset);
}
});
}
function getStringDecoder(config = {}) {
var _a, _b;
const size = (_a = config.size) != null ? _a : getU32Decoder();
const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
if (size === "variable") {
return { ...encoding, description };
return encoding;
}
if (typeof size === "number") {
return fixDecoder(encoding, size, description);
return fixDecoder(encoding, size);
}
return {
decode: (bytes, offset = 0) => {
return createDecoder({
read: (bytes, offset = 0) => {
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
const [lengthBigInt, lengthOffset] = size.read(bytes, offset);
const length = Number(lengthBigInt);

@@ -354,13 +387,7 @@ offset = lengthOffset;

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

@@ -479,20 +506,10 @@

}
function getAddressEncoder(config) {
var _a;
function getAddressEncoder() {
return mapEncoder(
getStringEncoder({
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
encoding: getMemoizedBase58Encoder(),
size: 32
}),
getStringEncoder({ encoding: getMemoizedBase58Encoder(), size: 32 }),
(putativeAddress) => address(putativeAddress)
);
}
function getAddressDecoder(config) {
var _a;
return getStringDecoder({
description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
encoding: getMemoizedBase58Decoder(),
size: 32
});
function getAddressDecoder() {
return getStringDecoder({ encoding: getMemoizedBase58Decoder(), size: 32 });
}

@@ -515,4 +532,3 @@ function getAddressComparator() {

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

@@ -542,19 +558,2 @@

// ../codecs-data-structures/dist/index.browser.js
function sumCodecSizes(sizes) {
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
}
function getArrayLikeCodecSizeDescription(size) {
return typeof size === "object" ? size.description : `${size}`;
}
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
if (typeof size !== "number")
return null;
if (size === 0)
return 0;
const childrenSize = sumCodecSizes(childrenSizes);
return childrenSize === null ? null : childrenSize * size;
}
function getArrayLikeCodecSizePrefix(size, realSize) {
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
}
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {

@@ -565,36 +564,59 @@ if (expected !== actual) {

}
function arrayCodecHelper(item, size, description) {
if (size === "remainder" && item.fixedSize === null) {
throw new Error('Codecs of "remainder" size must have fixed-size items.');
}
return {
description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
};
function sumCodecSizes(sizes) {
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
}
function getFixedSize(codec) {
return isFixedSize(codec) ? codec.fixedSize : null;
}
function getMaxSize(codec) {
var _a;
return isFixedSize(codec) ? codec.fixedSize : (_a = codec.maxSize) != null ? _a : null;
}
function getArrayEncoder(item, config = {}) {
var _a;
var _a, _b;
const size = (_a = config.size) != null ? _a : getU32Encoder();
return {
...arrayCodecHelper(item, size, config.description),
encode: (value) => {
if (size === "remainder") {
assertIsFixedSize(item, 'Codecs of "remainder" size must have fixed-size items.');
}
const fixedSize = computeArrayLikeCodecSize(size, getFixedSize(item));
const maxSize = (_b = computeArrayLikeCodecSize(size, getMaxSize(item))) != null ? _b : void 0;
return createEncoder({
...fixedSize !== null ? { fixedSize } : {
getSizeFromValue: (array) => {
const prefixSize = typeof size === "object" ? getEncodedSize(array.length, size) : 0;
return prefixSize + [...array].reduce((all, value) => all + getEncodedSize(value, item), 0);
},
maxSize
},
write: (array, bytes, offset) => {
if (typeof size === "number") {
assertValidNumberOfItemsForCodec("array", size, value.length);
assertValidNumberOfItemsForCodec("array", size, array.length);
}
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
if (typeof size === "object") {
offset = size.write(array.length, bytes, offset);
}
array.forEach((value) => {
offset = item.write(value, bytes, offset);
});
return offset;
}
};
});
}
function computeArrayLikeCodecSize(size, itemSize) {
if (typeof size !== "number")
return null;
if (size === 0)
return 0;
return itemSize === null ? null : itemSize * size;
}
function getBytesEncoder(config = {}) {
var _a, _b;
var _a;
const size = (_a = config.size) != null ? _a : "variable";
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
const byteEncoder = {
description,
encode: (value) => value,
fixedSize: null,
maxSize: null
};
const byteEncoder = createEncoder({
getSizeFromValue: (value) => value.length,
write: (value, bytes, offset) => {
bytes.set(value, offset);
return offset + value.length;
}
});
if (size === "variable") {

@@ -604,30 +626,32 @@ return byteEncoder;

if (typeof size === "number") {
return fixEncoder(byteEncoder, size, description);
return fixEncoder(byteEncoder, size);
}
return {
...byteEncoder,
encode: (value) => {
const contentBytes = byteEncoder.encode(value);
const lengthBytes = size.encode(contentBytes.length);
return mergeBytes([lengthBytes, contentBytes]);
return createEncoder({
getSizeFromValue: (value) => getEncodedSize(value.length, size) + value.length,
write: (value, bytes, offset) => {
offset = size.write(value.length, bytes, offset);
return byteEncoder.write(value, bytes, offset);
}
};
});
}
function structCodecHelper(fields, description) {
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
return {
description: description != null ? description : `struct(${fieldDescriptions})`,
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
};
}
function getStructEncoder(fields, config = {}) {
return {
...structCodecHelper(fields, config.description),
encode: (struct) => {
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
return mergeBytes(fieldBytes);
function getStructEncoder(fields) {
var _a;
const fieldCodecs = fields.map(([, codec]) => codec);
const fixedSize = sumCodecSizes(fieldCodecs.map(getFixedSize));
const maxSize = (_a = sumCodecSizes(fieldCodecs.map(getMaxSize))) != null ? _a : void 0;
return createEncoder({
...fixedSize === null ? {
getSizeFromValue: (value) => fields.map(([key, codec]) => getEncodedSize(value[key], codec)).reduce((all, one) => all + one, 0),
maxSize
} : { fixedSize },
write: (struct, bytes, offset) => {
fields.forEach(([key, codec]) => {
offset = codec.write(struct[key], bytes, offset);
});
return offset;
}
};
});
}
// ../transactions/dist/index.browser.js
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {

@@ -645,3 +669,3 @@ AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */

var IS_WRITABLE_BITMASK = 1;
function isSignerRole(role) {
function isSignerRole2(role) {
return role >= 2;

@@ -720,3 +744,3 @@ }

}
} else if (isSignerRole(accountMeta.role)) {
} else if (isSignerRole2(accountMeta.role)) {
return {

@@ -758,3 +782,3 @@ [TYPE]: 2,

// long as they are not require to sign the transaction.
!isSignerRole(entry.role)) {
!isSignerRole2(entry.role)) {
return {

@@ -810,4 +834,4 @@ ...accountMeta,

}
const leftIsSigner = isSignerRole(leftEntry.role);
if (leftIsSigner !== isSignerRole(rightEntry.role)) {
const leftIsSigner = isSignerRole2(leftEntry.role);
if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
return leftIsSigner ? -1 : 1;

@@ -862,3 +886,3 @@ }

const accountIsWritable = isWritableRole(account.role);
if (isSignerRole(account.role)) {
if (isSignerRole2(account.role)) {
numSignerAccounts++;

@@ -918,29 +942,16 @@ if (!accountIsWritable) {

}
var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
var addressTableLookupDescription = "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" ;
var memoizedAddressTableLookupEncoder;
function getAddressTableLookupEncoder() {
if (!memoizedAddressTableLookupEncoder) {
memoizedAddressTableLookupEncoder = getStructEncoder(
memoizedAddressTableLookupEncoder = getStructEncoder([
["lookupTableAddress", getAddressEncoder()],
[
["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
[
"writableIndices",
getArrayEncoder(getU8Encoder(), {
description: writableIndicesDescription,
size: getShortU16Encoder()
})
],
[
"readableIndices",
getArrayEncoder(getU8Encoder(), {
description: readableIndicesDescription,
size: getShortU16Encoder()
})
]
"writableIndices",
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
],
{ description: addressTableLookupDescription }
);
[
"readableIndices",
getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })
]
]);
}

@@ -955,29 +966,9 @@ return memoizedAddressTableLookupEncoder;

}
function getMemoizedU8EncoderDescription(description) {
const encoder = getMemoizedU8Encoder();
return {
...encoder,
description: description != null ? description : encoder.description
};
}
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
var numReadonlySignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" ;
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
function getMessageHeaderEncoder() {
return getStructEncoder(
[
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
],
{
description: messageHeaderDescription
}
);
return getStructEncoder([
["numSignerAccounts", getMemoizedU8Encoder()],
["numReadonlySignerAccounts", getMemoizedU8Encoder()],
["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
]);
}
var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
var accountIndicesDescription = "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ;
var dataDescription = "An optional buffer of data passed to the instruction" ;
var memoizedGetInstructionEncoder;

@@ -988,11 +979,5 @@ function getInstructionEncoder() {

getStructEncoder([
["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
[
"accountIndices",
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
description: accountIndicesDescription,
size: getShortU16Encoder()
})
],
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
["programAddressIndex", getU8Encoder()],
["accountIndices", getArrayEncoder(getU8Encoder(), { size: getShortU16Encoder() })],
["data", getBytesEncoder({ size: getShortU16Encoder() })]
]),

@@ -1016,26 +1001,18 @@ // Convert an instruction to have all fields defined

var VERSION_FLAG_MASK = 128;
var BASE_CONFIG = {
description: "A single byte that encodes the version of the transaction" ,
fixedSize: null,
maxSize: 1
};
function encode(value) {
if (value === "legacy") {
return new Uint8Array();
}
if (value < 0 || value > 127) {
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
}
return new Uint8Array([value | VERSION_FLAG_MASK]);
}
function getTransactionVersionEncoder() {
return {
...BASE_CONFIG,
encode
};
return createEncoder({
getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
maxSize: 1,
write: (value, bytes, offset) => {
if (value === "legacy") {
return offset;
}
if (value < 0 || value > 127) {
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
}
bytes.set([value | VERSION_FLAG_MASK], offset);
return offset + 1;
}
});
}
var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
function getCompiledMessageLegacyEncoder() {

@@ -1066,46 +1043,27 @@ return getStructEncoder(getPreludeStructEncoderTuple());

["header", getMessageHeaderEncoder()],
[
"staticAccounts",
getArrayEncoder(getAddressEncoder(), {
description: staticAccountsDescription,
size: getShortU16Encoder()
})
],
[
"lifetimeToken",
getStringEncoder({
description: lifetimeTokenDescription,
encoding: getBase58Encoder(),
size: 32
})
],
[
"instructions",
getArrayEncoder(getInstructionEncoder(), {
description: instructionsDescription,
size: getShortU16Encoder()
})
]
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
["lifetimeToken", getStringEncoder({ encoding: getBase58Encoder(), size: 32 })],
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
];
}
function getAddressTableLookupArrayEncoder() {
return getArrayEncoder(getAddressTableLookupEncoder(), {
description: addressTableLookupsDescription,
size: getShortU16Encoder()
});
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
}
var messageDescription = "The wire format of a Solana transaction message" ;
function getCompiledMessageEncoder() {
return {
description: messageDescription,
encode: (compiledMessage) => {
return createEncoder({
getSizeFromValue: (compiledMessage) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
} else {
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
}
},
fixedSize: null,
maxSize: null
};
write: (compiledMessage, bytes, offset) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
} else {
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
}
}
});
}

@@ -1134,3 +1092,3 @@ async function partiallySignTransaction(keyPairs, transaction) {

var _a, _b;
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole(a.role))) != null ? _b : [];
return (_b = (_a = i.accounts) == null ? void 0 : _a.filter((a) => isSignerRole2(a.role))) != null ? _b : [];
}).map((a) => a.address);

@@ -1259,6 +1217,4 @@ const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);

async function partiallySignTransactionWithSigners(transaction, config = {}) {
var _a;
const signers = (_a = config.signers) != null ? _a : [];
const { partialSigners, modifyingSigners } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers]),
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner)),
{ identifySendingSigner: false }

@@ -1274,7 +1230,5 @@ );

async function signAndSendTransactionWithSigners(transaction, config = {}) {
var _a;
const signers = (_a = config.signers) != null ? _a : [];
const abortSignal = config.abortSignal;
const { partialSigners, modifyingSigners, sendingSigner } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers])
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner))
);

@@ -1288,12 +1242,11 @@ abortSignal == null ? void 0 : abortSignal.throwIfAborted();

);
if (sendingSigner) {
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
return signature;
if (!sendingSigner) {
throw new Error(
"No `TransactionSendingSigner` was identified. Please provide a valid `ITransactionWithSingleSendingSigner` transaction."
);
}
if (config.fallbackSender) {
assertTransactionIsFullySigned(signedTransaction);
return config.fallbackSender(signedTransaction);
}
throw new Error("No TransactionSendingSigner was identified and no fallback sender was provided.");
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
return signature;
}

@@ -1334,7 +1287,10 @@ function categorizeTransactionSigners(signers, config = {}) {

var _a;
const modifiedTransaction = await modifyingSigners.reduce(async (transaction2, modifyingSigner) => {
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
}, Promise.resolve(transaction));
const modifiedTransaction = await modifyingSigners.reduce(
async (transaction2, modifyingSigner) => {
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
},
Promise.resolve(transaction)
);
abortSignal == null ? void 0 : abortSignal.throwIfAborted();

@@ -1367,2 +1323,31 @@ const signatureDictionaries = await Promise.all(

// src/transaction-with-single-sending-signer.ts
function isTransactionWithSingleSendingSigner(transaction) {
try {
assertIsTransactionWithSingleSendingSigner(transaction);
return true;
} catch {
return false;
}
}
function assertIsTransactionWithSingleSendingSigner(transaction) {
const signers = getSignersFromTransaction(transaction);
const sendingSigners = signers.filter(isTransactionSendingSigner);
if (sendingSigners.length === 0) {
const error = new Error("No `TransactionSendingSigner` was identified.");
error.name = "MissingTransactionSendingSignerError";
throw error;
}
const sendingOnlySigners = sendingSigners.filter(
(signer) => !isTransactionPartialSigner(signer) && !isTransactionModifyingSigner(signer)
);
if (sendingOnlySigners.length > 1) {
const error = new Error("More than one `TransactionSendingSigner` was identified.");
error.name = "MultipleTransactionSendingSignersError";
throw error;
}
}
exports.addSignersToInstruction = addSignersToInstruction;
exports.addSignersToTransaction = addSignersToTransaction;
exports.assertIsKeyPairSigner = assertIsKeyPairSigner;

@@ -1376,2 +1361,3 @@ exports.assertIsMessageModifyingSigner = assertIsMessageModifyingSigner;

exports.assertIsTransactionSigner = assertIsTransactionSigner;
exports.assertIsTransactionWithSingleSendingSigner = assertIsTransactionWithSingleSendingSigner;
exports.createNoopSigner = createNoopSigner;

@@ -1391,2 +1377,3 @@ exports.createSignableMessage = createSignableMessage;

exports.isTransactionSigner = isTransactionSigner;
exports.isTransactionWithSingleSendingSigner = isTransactionWithSingleSendingSigner;
exports.partiallySignTransactionWithSigners = partiallySignTransactionWithSigners;

@@ -1393,0 +1380,0 @@ exports.signAndSendTransactionWithSigners = signAndSendTransactionWithSigners;

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

import { isSignerRole } from '@solana/instructions';
import { getAddressFromPublicKey, isAddress } from '@solana/addresses';

@@ -11,2 +12,6 @@ import { generateKeyPair, signBytes } from '@solana/keys';

deduplicated[signer.address] = signer;
} else if (deduplicated[signer.address] !== signer) {
throw new Error(
`Multiple distinct signers were identified for address "${signer.address}". Please ensure that you are using the same signer instance for each address.`
);
}

@@ -26,2 +31,27 @@ });

}
function addSignersToInstruction(signers, instruction) {
if (!instruction.accounts || instruction.accounts.length === 0) {
return instruction;
}
const signerByAddress = new Map(deduplicateSigners(signers).map((signer) => [signer.address, signer]));
return Object.freeze({
...instruction,
accounts: instruction.accounts.map((account) => {
const signer = signerByAddress.get(account.address);
if (!isSignerRole(account.role) || "signer" in account || !signer) {
return account;
}
return Object.freeze({ ...account, signer });
})
});
}
function addSignersToTransaction(signers, transaction) {
if (transaction.instructions.length === 0) {
return transaction;
}
return Object.freeze({
...transaction,
instructions: transaction.instructions.map((instruction) => addSignersToInstruction(signers, instruction))
});
}

@@ -140,5 +170,4 @@ // src/message-partial-signer.ts

async function partiallySignTransactionWithSigners(transaction, config = {}) {
const signers = config.signers ?? [];
const { partialSigners, modifyingSigners } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers]),
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner)),
{ identifySendingSigner: false }

@@ -154,6 +183,5 @@ );

async function signAndSendTransactionWithSigners(transaction, config = {}) {
const signers = config.signers ?? [];
const abortSignal = config.abortSignal;
const { partialSigners, modifyingSigners, sendingSigner } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers])
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner))
);

@@ -167,12 +195,11 @@ abortSignal?.throwIfAborted();

);
if (sendingSigner) {
abortSignal?.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
return signature;
if (!sendingSigner) {
throw new Error(
"No `TransactionSendingSigner` was identified. Please provide a valid `ITransactionWithSingleSendingSigner` transaction."
);
}
if (config.fallbackSender) {
assertTransactionIsFullySigned(signedTransaction);
return config.fallbackSender(signedTransaction);
}
throw new Error("No TransactionSendingSigner was identified and no fallback sender was provided.");
abortSignal?.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
abortSignal?.throwIfAborted();
return signature;
}

@@ -211,7 +238,10 @@ function categorizeTransactionSigners(signers, config = {}) {

async function signModifyingAndPartialTransactionSigners(transaction, modifyingSigners = [], partialSigners = [], abortSignal) {
const modifiedTransaction = await modifyingSigners.reduce(async (transaction2, modifyingSigner) => {
abortSignal?.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
}, Promise.resolve(transaction));
const modifiedTransaction = await modifyingSigners.reduce(
async (transaction2, modifyingSigner) => {
abortSignal?.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
},
Promise.resolve(transaction)
);
abortSignal?.throwIfAborted();

@@ -244,4 +274,29 @@ const signatureDictionaries = await Promise.all(

export { assertIsKeyPairSigner, assertIsMessageModifyingSigner, assertIsMessagePartialSigner, assertIsMessageSigner, assertIsTransactionModifyingSigner, assertIsTransactionPartialSigner, assertIsTransactionSendingSigner, assertIsTransactionSigner, createNoopSigner, createSignableMessage, createSignerFromKeyPair, generateKeyPairSigner, getSignersFromInstruction, getSignersFromTransaction, isKeyPairSigner, isMessageModifyingSigner, isMessagePartialSigner, isMessageSigner, isTransactionModifyingSigner, isTransactionPartialSigner, isTransactionSendingSigner, isTransactionSigner, partiallySignTransactionWithSigners, signAndSendTransactionWithSigners, signTransactionWithSigners };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map
// src/transaction-with-single-sending-signer.ts
function isTransactionWithSingleSendingSigner(transaction) {
try {
assertIsTransactionWithSingleSendingSigner(transaction);
return true;
} catch {
return false;
}
}
function assertIsTransactionWithSingleSendingSigner(transaction) {
const signers = getSignersFromTransaction(transaction);
const sendingSigners = signers.filter(isTransactionSendingSigner);
if (sendingSigners.length === 0) {
const error = new Error("No `TransactionSendingSigner` was identified.");
error.name = "MissingTransactionSendingSignerError";
throw error;
}
const sendingOnlySigners = sendingSigners.filter(
(signer) => !isTransactionPartialSigner(signer) && !isTransactionModifyingSigner(signer)
);
if (sendingOnlySigners.length > 1) {
const error = new Error("More than one `TransactionSendingSigner` was identified.");
error.name = "MultipleTransactionSendingSignersError";
throw error;
}
}
export { addSignersToInstruction, addSignersToTransaction, assertIsKeyPairSigner, assertIsMessageModifyingSigner, assertIsMessagePartialSigner, assertIsMessageSigner, assertIsTransactionModifyingSigner, assertIsTransactionPartialSigner, assertIsTransactionSendingSigner, assertIsTransactionSigner, assertIsTransactionWithSingleSendingSigner, createNoopSigner, createSignableMessage, createSignerFromKeyPair, generateKeyPairSigner, getSignersFromInstruction, getSignersFromTransaction, isKeyPairSigner, isMessageModifyingSigner, isMessagePartialSigner, isMessageSigner, isTransactionModifyingSigner, isTransactionPartialSigner, isTransactionSendingSigner, isTransactionSigner, isTransactionWithSingleSendingSigner, partiallySignTransactionWithSigners, signAndSendTransactionWithSigners, signTransactionWithSigners };

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

import { isSignerRole } from '@solana/instructions';
import { getAddressFromPublicKey, isAddress } from '@solana/addresses';

@@ -11,2 +12,6 @@ import { generateKeyPair, signBytes } from '@solana/keys';

deduplicated[signer.address] = signer;
} else if (deduplicated[signer.address] !== signer) {
throw new Error(
`Multiple distinct signers were identified for address "${signer.address}". Please ensure that you are using the same signer instance for each address.`
);
}

@@ -26,2 +31,27 @@ });

}
function addSignersToInstruction(signers, instruction) {
if (!instruction.accounts || instruction.accounts.length === 0) {
return instruction;
}
const signerByAddress = new Map(deduplicateSigners(signers).map((signer) => [signer.address, signer]));
return Object.freeze({
...instruction,
accounts: instruction.accounts.map((account) => {
const signer = signerByAddress.get(account.address);
if (!isSignerRole(account.role) || "signer" in account || !signer) {
return account;
}
return Object.freeze({ ...account, signer });
})
});
}
function addSignersToTransaction(signers, transaction) {
if (transaction.instructions.length === 0) {
return transaction;
}
return Object.freeze({
...transaction,
instructions: transaction.instructions.map((instruction) => addSignersToInstruction(signers, instruction))
});
}

@@ -140,5 +170,4 @@ // src/message-partial-signer.ts

async function partiallySignTransactionWithSigners(transaction, config = {}) {
const signers = config.signers ?? [];
const { partialSigners, modifyingSigners } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers]),
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner)),
{ identifySendingSigner: false }

@@ -154,6 +183,5 @@ );

async function signAndSendTransactionWithSigners(transaction, config = {}) {
const signers = config.signers ?? [];
const abortSignal = config.abortSignal;
const { partialSigners, modifyingSigners, sendingSigner } = categorizeTransactionSigners(
deduplicateSigners([...getSignersFromTransaction(transaction).filter(isTransactionSigner), ...signers])
deduplicateSigners(getSignersFromTransaction(transaction).filter(isTransactionSigner))
);

@@ -167,12 +195,11 @@ abortSignal?.throwIfAborted();

);
if (sendingSigner) {
abortSignal?.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
return signature;
if (!sendingSigner) {
throw new Error(
"No `TransactionSendingSigner` was identified. Please provide a valid `ITransactionWithSingleSendingSigner` transaction."
);
}
if (config.fallbackSender) {
assertTransactionIsFullySigned(signedTransaction);
return config.fallbackSender(signedTransaction);
}
throw new Error("No TransactionSendingSigner was identified and no fallback sender was provided.");
abortSignal?.throwIfAborted();
const [signature] = await sendingSigner.signAndSendTransactions([signedTransaction], { abortSignal });
abortSignal?.throwIfAborted();
return signature;
}

@@ -211,7 +238,10 @@ function categorizeTransactionSigners(signers, config = {}) {

async function signModifyingAndPartialTransactionSigners(transaction, modifyingSigners = [], partialSigners = [], abortSignal) {
const modifiedTransaction = await modifyingSigners.reduce(async (transaction2, modifyingSigner) => {
abortSignal?.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
}, Promise.resolve(transaction));
const modifiedTransaction = await modifyingSigners.reduce(
async (transaction2, modifyingSigner) => {
abortSignal?.throwIfAborted();
const [tx] = await modifyingSigner.modifyAndSignTransactions([await transaction2], { abortSignal });
return Object.freeze(tx);
},
Promise.resolve(transaction)
);
abortSignal?.throwIfAborted();

@@ -244,4 +274,31 @@ const signatureDictionaries = await Promise.all(

export { assertIsKeyPairSigner, assertIsMessageModifyingSigner, assertIsMessagePartialSigner, assertIsMessageSigner, assertIsTransactionModifyingSigner, assertIsTransactionPartialSigner, assertIsTransactionSendingSigner, assertIsTransactionSigner, createNoopSigner, createSignableMessage, createSignerFromKeyPair, generateKeyPairSigner, getSignersFromInstruction, getSignersFromTransaction, isKeyPairSigner, isMessageModifyingSigner, isMessagePartialSigner, isMessageSigner, isTransactionModifyingSigner, isTransactionPartialSigner, isTransactionSendingSigner, isTransactionSigner, partiallySignTransactionWithSigners, signAndSendTransactionWithSigners, signTransactionWithSigners };
// src/transaction-with-single-sending-signer.ts
function isTransactionWithSingleSendingSigner(transaction) {
try {
assertIsTransactionWithSingleSendingSigner(transaction);
return true;
} catch {
return false;
}
}
function assertIsTransactionWithSingleSendingSigner(transaction) {
const signers = getSignersFromTransaction(transaction);
const sendingSigners = signers.filter(isTransactionSendingSigner);
if (sendingSigners.length === 0) {
const error = new Error("No `TransactionSendingSigner` was identified.");
error.name = "MissingTransactionSendingSignerError";
throw error;
}
const sendingOnlySigners = sendingSigners.filter(
(signer) => !isTransactionPartialSigner(signer) && !isTransactionModifyingSigner(signer)
);
if (sendingOnlySigners.length > 1) {
const error = new Error("More than one `TransactionSendingSigner` was identified.");
error.name = "MultipleTransactionSendingSignersError";
throw error;
}
}
export { addSignersToInstruction, addSignersToTransaction, assertIsKeyPairSigner, assertIsMessageModifyingSigner, assertIsMessagePartialSigner, assertIsMessageSigner, assertIsTransactionModifyingSigner, assertIsTransactionPartialSigner, assertIsTransactionSendingSigner, assertIsTransactionSigner, assertIsTransactionWithSingleSendingSigner, createNoopSigner, createSignableMessage, createSignerFromKeyPair, generateKeyPairSigner, getSignersFromInstruction, getSignersFromTransaction, isKeyPairSigner, isMessageModifyingSigner, isMessagePartialSigner, isMessageSigner, isTransactionModifyingSigner, isTransactionPartialSigner, isTransactionSendingSigner, isTransactionSigner, isTransactionWithSingleSendingSigner, partiallySignTransactionWithSigners, signAndSendTransactionWithSigners, signTransactionWithSigners };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map

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

function A(e){let n={};return e.forEach(r=>{n[r.address]||(n[r.address]=r);}),Object.values(n)}function De(e){var n;return A(((n=e.accounts)!=null?n:[]).flatMap(r=>"signer"in r?r.signer:[]))}function _(e){return A(e.instructions.flatMap(De))}function I(e,n,r=0){if(n.length-r<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function b(e,n,r,t=0){let i=r.length-t;if(i<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${i}.`)}var w=e=>{let n=e.filter(o=>o.length);if(n.length===0)return e.length?e[0]:new Uint8Array;if(n.length===1)return n[0];let r=n.reduce((o,s)=>o+s.length,0),t=new Uint8Array(r),i=0;return n.forEach(o=>{t.set(o,i),i+=o.length;}),t},Me=(e,n)=>{if(e.length>=n)return e;let r=new Uint8Array(n).fill(0);return r.set(e),r},W=(e,n)=>Me(e.length<=n?e:e.slice(0,n),n);function se(e,n,r){return {description:r!=null?r:`fixed(${n}, ${e.description})`,fixedSize:n,maxSize:n}}function k(e,n,r){return {...se(e,n,r),encode:t=>W(e.encode(t),n)}}function j(e,n,r){return {...se(e,n,r),decode:(t,i=0)=>{b("fixCodec",n,t,i),(i>0||t.length>n)&&(t=t.slice(i,i+n)),e.fixedSize!==null&&(t=W(t,e.fixedSize));let[o]=e.decode(t,0);return [o,i+n]}}}function v(e,n){return {description:e.description,encode:r=>e.encode(n(r)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function ae(e,n,r,t){if(t<n||t>r)throw new Error(`Codec [${e}] expected number to be in the range [${n}, ${r}], got ${t}.`)}function ce(e){var t;let n,r=e.name;return e.size>1&&(n=!("endian"in e.config)||e.config.endian===0,r+=n?"(le)":"(be)"),{description:(t=e.config.description)!=null?t:r,fixedSize:e.size,littleEndian:n,maxSize:e.size}}function de(e){let n=ce(e);return {description:n.description,encode(r){e.range&&ae(e.name,e.range[0],e.range[1],r);let t=new ArrayBuffer(e.size);return e.set(new DataView(t),r,n.littleEndian),new Uint8Array(t)},fixedSize:n.fixedSize,maxSize:n.maxSize}}function ke(e){let n=ce(e);return {decode(r,t=0){I(n.description,r,t),b(n.description,e.size,r,t);let i=new DataView(Pe(r,t,e.size));return [e.get(i,n.littleEndian),t+e.size]},description:n.description,fixedSize:n.fixedSize,maxSize:n.maxSize}}function Pe(e,n,r){let t=e.byteOffset+(n!=null?n:0),i=r!=null?r:e.byteLength;return e.buffer.slice(t,t+i)}var S=(e={})=>{var n;return {description:(n=e.description)!=null?n:"shortU16",encode:r=>{ae("shortU16",0,65535,r);let t=[0];for(let i=0;;i+=1){let o=r>>i*7;if(o===0)break;let s=127&o;t[i]=s,i>0&&(t[i-1]|=128);}return new Uint8Array(t)},fixedSize:null,maxSize:3}};var $=(e={})=>de({config:e,name:"u32",range:[0,+"0xffffffff"],set:(n,r,t)=>n.setUint32(0,r,t),size:4}),K=(e={})=>ke({config:e,get:(n,r)=>n.getUint32(0,r),name:"u32",size:4});var y=(e={})=>de({config:e,name:"u8",range:[0,+"0xff"],set:(n,r)=>n.setUint8(0,r),size:1});function $e(e,n,r=n){if(!n.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${r}].`)}var Ue=e=>{let n=e.length,r=BigInt(n);return {description:`base${n}`,encode(t){if($e(e,t),t==="")return new Uint8Array;let i=[...t],o=i.findIndex(m=>m!==e[0]);o=o===-1?i.length:o;let s=Array(o).fill(0);if(o===i.length)return Uint8Array.from(s);let a=i.slice(o),c=0n,d=1n;for(let m=a.length-1;m>=0;m-=1)c+=d*BigInt(e.indexOf(a[m])),d*=r;let u=[];for(;c>0n;)u.unshift(Number(c%256n)),c/=256n;return Uint8Array.from(s.concat(u))},fixedSize:null,maxSize:null}},Ne=e=>{let n=e.length,r=BigInt(n);return {decode(t,i=0){let o=i===0?t:t.slice(i);if(o.length===0)return ["",0];let s=o.findIndex(u=>u!==0);s=s===-1?o.length:s;let a=e[0].repeat(s);if(s===o.length)return [a,t.length];let c=o.slice(s).reduce((u,m)=>u*256n+BigInt(m),0n),d=[];for(;c>0n;)d.unshift(e[Number(c%r)]),c/=r;return [a+d.join(""),t.length]},description:`base${n}`,fixedSize:null,maxSize:null}};var ue="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",U=()=>Ue(ue),V=()=>Ne(ue);var Oe=e=>e.replace(/\u0000/g,"");var Re=globalThis.TextDecoder,Le=globalThis.TextEncoder,Fe=()=>{let e;return {description:"utf8",encode:n=>new Uint8Array((e||(e=new Le)).encode(n)),fixedSize:null,maxSize:null}},_e=()=>{let e;return {decode(n,r=0){let t=(e||(e=new Re)).decode(n.slice(r));return [Oe(t),n.length]},description:"utf8",fixedSize:null,maxSize:null}};var N=(e={})=>{var i,o,s;let n=(i=e.size)!=null?i:$(),r=(o=e.encoding)!=null?o:Fe(),t=(s=e.description)!=null?s:`string(${r.description}; ${ge(n)})`;return n==="variable"?{...r,description:t}:typeof n=="number"?k(r,n,t):{description:t,encode:a=>{let c=r.encode(a),d=n.encode(c.length);return w([d,c])},fixedSize:null,maxSize:null}},H=(e={})=>{var i,o,s;let n=(i=e.size)!=null?i:K(),r=(o=e.encoding)!=null?o:_e(),t=(s=e.description)!=null?s:`string(${r.description}; ${ge(n)})`;return n==="variable"?{...r,description:t}:typeof n=="number"?j(r,n,t):{decode:(a,c=0)=>{I("string",a,c);let[d,u]=n.decode(a,c),m=Number(d);c=u;let oe=a.slice(c,c+m);b("string",m,oe);let[Ce,Be]=r.decode(oe);return c+=Be,[Ce,c]},description:t,fixedSize:null,maxSize:null}};function ge(e){return typeof e=="object"?e.description:`${e}`}function G(){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")}var h;async function We(e){return h===void 0&&(h=new Promise(n=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{n(h=!1);}).then(()=>{n(h=!0);});})),typeof h=="boolean"?h:await h}async function fe(){var e;if(G(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.generateKey)!="function")throw new Error("No key generation implementation could be found");if(!await We(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
function y(e){let n={};return e.forEach(r=>{if(!n[r.address])n[r.address]=r;else if(n[r.address]!==r)throw new Error(`Multiple distinct signers were identified for address "${r.address}". Please ensure that you are using the same signer instance for each address.`)}),Object.values(n)}function Oe(e){var n;return y(((n=e.accounts)!=null?n:[]).flatMap(r=>"signer"in r?r.signer:[]))}function B(e){return y(e.instructions.flatMap(Oe))}function ie(e){return e>=2}function We(e,n){if(!n.accounts||n.accounts.length===0)return n;let r=new Map(y(e).map(t=>[t.address,t]));return Object.freeze({...n,accounts:n.accounts.map(t=>{let i=r.get(t.address);return !ie(t.role)||"signer"in t||!i?t:Object.freeze({...t,signer:i})})})}function Fn(e,n){return n.instructions.length===0?n:Object.freeze({...n,instructions:n.instructions.map(r=>We(e,r))})}function M(e,n,r=0){if(n.length-r<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function E(e,n,r,t=0){let i=r.length-t;if(i<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${i}.`)}var Ue=(e,n)=>{if(e.length>=n)return e;let r=new Uint8Array(n).fill(0);return r.set(e),r},Fe=(e,n)=>Ue(e.length<=n?e:e.slice(0,n),n);function S(e,n){return "fixedSize"in n?n.fixedSize:n.getSizeFromValue(e)}function l(e){return Object.freeze({...e,encode:n=>{let r=new Uint8Array(S(n,e));return e.write(n,r,0),r}})}function p(e){return Object.freeze({...e,decode:(n,r=0)=>e.read(n,r)[0]})}function I(e){return "fixedSize"in e&&typeof e.fixedSize=="number"}function se(e,n){if(!I(e))throw new Error(n!=null?n:"Expected a fixed-size codec, got a variable-size one.")}function Le(e){return !I(e)}function N(e,n){return l({fixedSize:n,write:(r,t,i)=>{let o=e.encode(r),s=o.length>n?o.slice(0,n):o;return t.set(s,i),i+n}})}function V(e,n){return p({fixedSize:n,read:(r,t)=>{E("fixCodec",n,r,t),(t>0||r.length>n)&&(r=r.slice(t,t+n)),I(e)&&(r=Fe(r,e.fixedSize));let[i]=e.read(r,0);return [i,t+n]}})}function z(e,n){return l({...Le(e)?{...e,getSizeFromValue:r=>e.getSizeFromValue(n(r))}:e,write:(r,t,i)=>e.write(n(r),t,i)})}function oe(e,n,r,t){if(t<n||t>r)throw new Error(`Codec [${e}] expected number to be in the range [${n}, ${r}], got ${t}.`)}function ae(e){return (e==null?void 0:e.endian)!==1}function ce(e){return l({fixedSize:e.size,write(n,r,t){e.range&&oe(e.name,e.range[0],e.range[1],n);let i=new ArrayBuffer(e.size);return e.set(new DataView(i),n,ae(e.config)),r.set(new Uint8Array(i),t),t+e.size}})}function _e(e){return p({fixedSize:e.size,read(n,r=0){M(e.name,n,r),E(e.name,e.size,n,r);let t=new DataView($e(n,r,e.size));return [e.get(t,ae(e.config)),r+e.size]}})}function $e(e,n,r){let t=e.byteOffset+(n!=null?n:0),i=r!=null?r:e.byteLength;return e.buffer.slice(t,t+i)}var h=()=>l({getSizeFromValue:e=>e<=127?1:e<=16383?2:3,maxSize:3,write:(e,n,r)=>{oe("shortU16",0,65535,e);let t=[0];for(let i=0;;i+=1){let o=e>>i*7;if(o===0)break;let s=127&o;t[i]=s,i>0&&(t[i-1]|=128);}return n.set(t,r),r+t.length}});var O=(e={})=>ce({config:e,name:"u32",range:[0,+"0xffffffff"],set:(n,r,t)=>n.setUint32(0,r,t),size:4}),K=(e={})=>_e({config:e,get:(n,r)=>n.getUint32(0,r),name:"u32",size:4});var A=()=>ce({name:"u8",range:[0,+"0xff"],set:(e,n)=>e.setUint8(0,n),size:1});function Ve(e,n,r=n){if(!n.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${r}].`)}var Ke=e=>l({getSizeFromValue:n=>{let[r,t]=de(n,e[0]);if(t==="")return n.length;let i=ge(t,e);return r.length+Math.ceil(i.toString(16).length/2)},write(n,r,t){if(Ve(e,n),n==="")return t;let[i,o]=de(n,e[0]);if(o==="")return r.set(new Uint8Array(i.length).fill(0),t),t+i.length;let s=ge(o,e),a=[];for(;s>0n;)a.unshift(Number(s%256n)),s/=256n;let c=[...Array(i.length).fill(0),...a];return r.set(c,t),t+c.length}}),je=e=>p({read(n,r){let t=r===0?n:n.slice(r);if(t.length===0)return ["",0];let i=t.findIndex(c=>c!==0);i=i===-1?t.length:i;let o=e[0].repeat(i);if(i===t.length)return [o,n.length];let s=t.slice(i).reduce((c,d)=>c*256n+BigInt(d),0n),a=Ge(s,e);return [o+a,n.length]}});function de(e,n){let r=[...e].findIndex(t=>t!==n);return r===-1?[e,""]:[e.slice(0,r),e.slice(r)]}function ge(e,n){let r=BigInt(n.length);return [...e].reduce((t,i)=>t*r+BigInt(n.indexOf(i)),0n)}function Ge(e,n){let r=BigInt(n.length),t=[];for(;e>0n;)t.unshift(n[Number(e%r)]),e/=r;return t.join("")}var fe="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",W=()=>Ke(fe),j=()=>je(fe);var Ye=e=>e.replace(/\u0000/g,"");var He=globalThis.TextDecoder,ue=globalThis.TextEncoder,Xe=()=>{let e;return l({getSizeFromValue:n=>(e||(e=new ue)).encode(n).length,write:(n,r,t)=>{let i=(e||(e=new ue)).encode(n);return r.set(i,t),t+i.length}})},Ze=()=>{let e;return p({read(n,r){let t=(e||(e=new He)).decode(n.slice(r));return [Ye(t),n.length]}})};function U(e={}){var t,i;let n=(t=e.size)!=null?t:O(),r=(i=e.encoding)!=null?i:Xe();return n==="variable"?r:typeof n=="number"?N(r,n):l({getSizeFromValue:o=>{let s=S(o,r);return S(s,n)+s},write:(o,s,a)=>{let c=S(o,r);return a=n.write(c,s,a),r.write(o,s,a)}})}function G(e={}){var t,i;let n=(t=e.size)!=null?t:K(),r=(i=e.encoding)!=null?i:Ze();return n==="variable"?r:typeof n=="number"?V(r,n):p({read:(o,s=0)=>{M("string",o,s);let[a,c]=n.read(o,s),d=Number(a);s=c;let f=o.slice(s,s+d);E("string",d,f);let[te,Re]=r.read(f,0);return s+=Re,[te,s]}})}function Y(){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")}var b;async function qe(e){return b===void 0&&(b=new Promise(n=>{e.generateKey("Ed25519",!1,["sign","verify"]).catch(()=>{n(b=!1);}).then(()=>{n(b=!0);});})),typeof b=="boolean"?b:await b}async function le(){var e;if(Y(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.generateKey)!="function")throw new Error("No key generation implementation could be found");if(!await qe(globalThis.crypto.subtle))throw new Error(`This runtime does not support the generation of Ed25519 key pairs.
Install and import \`@solana/webcrypto-ed25519-polyfill\` before generating keys in environments that do not support Ed25519.
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function le(){var e;if(G(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.exportKey)!="function")throw new Error("No key export implementation could be found")}async function me(){var e;if(G(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.sign)!="function")throw new Error("No signing implementation could be found")}var Y,X;function q(){return Y||(Y=U()),Y}function je(){return X||(X=V()),X}function pe(e){return !(e.length<32||e.length>44||q().encode(e).byteLength!==32)}function Se(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=q().encode(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(n){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:n})}}function Ke(e){return Se(e),e}function Z(e){var n;return v(N({description:(n=e==null?void 0:e.description)!=null?n:"Address",encoding:q(),size:32}),r=>Ke(r))}function ye(e){var n;return H({description:(n=e==null?void 0:e.description)!=null?n:"Address",encoding:je(),size:32})}function O(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}async function R(e){if(await le(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let n=await crypto.subtle.exportKey("raw",e),[r]=ye().decode(new Uint8Array(n));return r}async function he(){return await fe(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function L(e,n){await me();let r=await crypto.subtle.sign("Ed25519",e,n);return new Uint8Array(r)}function J(e){return e.reduce((n,r)=>n===null||r===null?null:n+r,0)}function He(e){return typeof e=="object"?e.description:`${e}`}function Te(e,n){if(typeof e!="number")return null;if(e===0)return 0;let r=J(n);return r===null?null:r*e}function Ge(e,n){return typeof e=="object"?e.encode(n):new Uint8Array}function Ye(e,n,r){if(n!==r)throw new Error(`Expected [${e}] to have ${n} items, got ${r}.`)}function Xe(e,n,r){if(n==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:r!=null?r:`array(${e.description}; ${He(n)})`,fixedSize:Te(n,[e.fixedSize]),maxSize:Te(n,[e.maxSize])}}function T(e,n={}){var t;let r=(t=n.size)!=null?t:$();return {...Xe(e,r,n.description),encode:i=>(typeof r=="number"&&Ye("array",r,i.length),w([Ge(r,i.length),...i.map(o=>e.encode(o))]))}}function xe(e={}){var o,s;let n=(o=e.size)!=null?o:"variable",r=typeof n=="object"?n.description:`${n}`,t=(s=e.description)!=null?s:`bytes(${r})`,i={description:t,encode:a=>a,fixedSize:null,maxSize:null};return n==="variable"?i:typeof n=="number"?k(i,n,t):{...i,encode:a=>{let c=i.encode(a),d=n.encode(c.length);return w([d,c])}}}function qe(e,n){let r=e.map(([t,i])=>`${String(t)}: ${i.description}`).join(", ");return {description:n!=null?n:`struct(${r})`,fixedSize:J(e.map(([,t])=>t.fixedSize)),maxSize:J(e.map(([,t])=>t.maxSize))}}function z(e,n={}){return {...qe(e,n.description),encode:r=>{let t=e.map(([i,o])=>o.encode(r[i]));return w(t)}}}var C=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(C||{}),Ze=1;function E(e){return e>=2}function B(e){return (e&Ze)!==0}function Ae(e,n){return e|n}function be(e,n,r){var t;e[n]=r((t=e[n])!=null?t:{role:C.READONLY});}var f=Symbol("AddressMapTypeProperty");function Je(e,n){let r={[e]:{[f]:0,role:C.WRITABLE_SIGNER}},t=new Set;for(let i of n){be(r,i.programAddress,s=>{if(t.add(i.programAddress),f in s){if(B(s.role))switch(s[f]){case 0:throw new Error(`This transaction includes an address (\`${i.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`);default:throw new Error(`This transaction includes an address (\`${i.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`)}if(s[f]===2)return s}return {[f]:2,role:C.READONLY}});let o;if(i.accounts)for(let s of i.accounts)be(r,s.address,a=>{let{address:c,...d}=s;if(f in a)switch(a[f]){case 0:return a;case 1:{let u=Ae(a.role,d.role);if("lookupTableAddress"in d){if(a.lookupTableAddress!==d.lookupTableAddress&&(o||(o=O()))(d.lookupTableAddress,a.lookupTableAddress)<0)return {[f]:1,...d,role:u}}else if(E(d.role))return {[f]:2,role:u};return a.role!==u?{...a,role:u}:a}case 2:{let u=Ae(a.role,d.role);if(t.has(s.address)){if(B(d.role))throw new Error(`This transaction includes an address (\`${s.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`);return a.role!==u?{...a,role:u}:a}else return "lookupTableAddress"in d&&!E(a.role)?{...d,[f]:1,role:u}:a.role!==u?{...a,role:u}:a}}return "lookupTableAddress"in d?{...d,[f]:1}:{...d,[f]:2}});}return r}function Qe(e){let n;return Object.entries(e).sort(([t,i],[o,s])=>{if(i[f]!==s[f]){if(i[f]===0)return -1;if(s[f]===0)return 1;if(i[f]===2)return -1;if(s[f]===2)return 1}let a=E(i.role);if(a!==E(s.role))return a?-1:1;let c=B(i.role);return c!==B(s.role)?c?-1:1:(n||(n=O()),i[f]===1&&s[f]===1&&i.lookupTableAddress!==s.lookupTableAddress?n(i.lookupTableAddress,s.lookupTableAddress):n(t,o))}).map(([t,i])=>({address:t,...i}))}function en(e){var r;let n={};for(let t of e){if(!("lookupTableAddress"in t))continue;let i=n[r=t.lookupTableAddress]||(n[r]={readableIndices:[],writableIndices:[]});t.role===C.WRITABLE?i.writableIndices.push(t.addressIndex):i.readableIndices.push(t.addressIndex);}return Object.keys(n).sort(O()).map(t=>({lookupTableAddress:t,...n[t]}))}function nn(e){let n=0,r=0,t=0;for(let i of e){if("lookupTableAddress"in i)break;let o=B(i.role);E(i.role)?(t++,o||r++):o||n++;}return {numReadonlyNonSignerAccounts:n,numReadonlySignerAccounts:r,numSignerAccounts:t}}function rn(e){let n={};for(let[r,t]of e.entries())n[t.address]=r;return n}function tn(e,n){let r=rn(n);return e.map(({accounts:t,data:i,programAddress:o})=>({programAddressIndex:r[o],...t?{accountIndices:t.map(({address:s})=>r[s])}:null,...i?{data:i}:null}))}function on(e){return "nonce"in e?e.nonce:e.blockhash}function sn(e){let n=e.findIndex(t=>"lookupTableAddress"in t);return (n===-1?e:e.slice(0,n)).map(({address:t})=>t)}function an(e){let n=Je(e.feePayer,e.instructions),r=Qe(n);return {...e.version!=="legacy"?{addressTableLookups:en(r)}:null,header:nn(r),instructions:tn(e.instructions,r),lifetimeToken:on(e.lifetimeConstraint),staticAccounts:sn(r),version:e.version}}var cn="lookupTableAddress",dn="writableIndices",un="readableIndices",gn="addressTableLookup",Q;function fn(){return Q||(Q=z([["lookupTableAddress",Z({description:cn})],["writableIndices",T(y(),{description:dn,size:S()})],["readableIndices",T(y(),{description:un,size:S()})]],{description:gn})),Q}var ee;function ln(){return ee||(ee=y()),ee}function ne(e){let n=ln();return {...n,description:e!=null?e:n.description}}var mn=void 0,pn=void 0,Sn=void 0,yn=void 0;function hn(){return z([["numSignerAccounts",ne(mn)],["numReadonlySignerAccounts",ne(pn)],["numReadonlyNonSignerAccounts",ne(Sn)]],{description:yn})}var Tn="programAddressIndex",xn=void 0,An="accountIndices",bn="data",re;function wn(){return re||(re=v(z([["programAddressIndex",y({description:Tn})],["accountIndices",T(y({description:xn}),{description:An,size:S()})],["data",xe({description:bn,size:S()})]]),e=>{var n,r;return e.accountIndices!==void 0&&e.data!==void 0?e:{...e,accountIndices:(n=e.accountIndices)!=null?n:[],data:(r=e.data)!=null?r:new Uint8Array(0)}})),re}var zn=128,En={description:"",fixedSize:null,maxSize:1};function In(e){if(e==="legacy")return new Uint8Array;if(e<0||e>127)throw new Error(`Transaction version must be in the range [0, 127]. \`${e}\` given.`);return new Uint8Array([e|zn])}function vn(){return {...En,encode:In}}var Cn="staticAccounts",Bn="lifetimeToken",Dn="instructions",Mn="addressTableLookups";function kn(){return z(we())}function Pn(){return v(z([...we(),["addressTableLookups",$n()]]),e=>{var n;return e.version==="legacy"?e:{...e,addressTableLookups:(n=e.addressTableLookups)!=null?n:[]}})}function we(){return [["version",vn()],["header",hn()],["staticAccounts",T(Z(),{description:Cn,size:S()})],["lifetimeToken",N({description:Bn,encoding:U(),size:32})],["instructions",T(wn(),{description:Dn,size:S()})]]}function $n(){return T(fn(),{description:Mn,size:S()})}var Un="message";function Nn(){return {description:Un,encode:e=>e.version==="legacy"?kn().encode(e):Pn().encode(e),fixedSize:null,maxSize:null}}async function ze(e,n){let r=an(n),t="signatures"in n?{...n.signatures}:{},i=Nn().encode(r),o=await Promise.all(e.map(a=>Promise.all([R(a.publicKey),L(a.privateKey,i)])));for(let[a,c]of o)t[a]=c;let s={...n,signatures:t};return Object.freeze(s),s}function te(e){let n=e.instructions.flatMap(t=>{var i,o;return (o=(i=t.accounts)==null?void 0:i.filter(s=>E(s.role)))!=null?o:[]}).map(t=>t.address);new Set([e.feePayer,...n]).forEach(t=>{if(!e.signatures[t])throw new Error(`Transaction is missing signature for address \`${t}\``)});}function D(e){return "signMessages"in e&&typeof e.signMessages=="function"}function Ur(e){if(!D(e))throw new Error("The provided value does not implement the MessagePartialSigner interface")}function p(e){return "signTransactions"in e&&typeof e.signTransactions=="function"}function Rr(e){if(!p(e))throw new Error("The provided value does not implement the TransactionPartialSigner interface")}function On(e){return "keyPair"in e&&typeof e.keyPair=="object"&&D(e)&&p(e)}function Xr(e){if(!On(e))throw new Error("The provided value does not implement the KeyPairSigner interface")}async function Rn(e){let n=await R(e.publicKey);return Object.freeze({address:n,keyPair:e,signMessages:t=>Promise.all(t.map(async i=>Object.freeze({[n]:await L(e.privateKey,i.content)}))),signTransactions:t=>Promise.all(t.map(async i=>{let o=await ze([e],i);return Object.freeze({[n]:o.signatures[n]})}))})}async function qr(){return Rn(await he())}function ie(e){return pe(e.address)&&"modifyAndSignMessages"in e&&typeof e.modifyAndSignMessages=="function"}function nt(e){if(!ie(e))throw new Error("The provided value does not implement the MessageModifyingSigner interface")}function Ln(e){return D(e)||ie(e)}function ct(e){if(!Ln(e))throw new Error("The provided value does not implement any of the MessageSigner interfaces")}function gt(e){return Object.freeze({address:e,signMessages:async r=>r.map(()=>Object.freeze({})),signTransactions:async r=>r.map(()=>Object.freeze({}))})}function x(e){return "modifyAndSignTransactions"in e&&typeof e.modifyAndSignTransactions=="function"}function mt(e){if(!x(e))throw new Error("The provided value does not implement the TransactionModifyingSigner interface")}function M(e){return "signAndSendTransactions"in e&&typeof e.signAndSendTransactions=="function"}function yt(e){if(!M(e))throw new Error("The provided value does not implement the TransactionSendingSigner interface")}function F(e){return p(e)||x(e)||M(e)}function It(e){if(!F(e))throw new Error("The provided value does not implement any of the TransactionSigner interfaces")}async function Fn(e,n={}){var o;let r=(o=n.signers)!=null?o:[],{partialSigners:t,modifyingSigners:i}=Ee(A([..._(e).filter(F),...r]),{identifySendingSigner:!1});return Ie(e,i,t,n.abortSignal)}async function Vt(e,n={}){let r=await Fn(e,n);return te(r),r}async function Ht(e,n={}){var c;let r=(c=n.signers)!=null?c:[],t=n.abortSignal,{partialSigners:i,modifyingSigners:o,sendingSigner:s}=Ee(A([..._(e).filter(F),...r]));t==null||t.throwIfAborted();let a=await Ie(e,o,i,t);if(s){t==null||t.throwIfAborted();let[d]=await s.signAndSendTransactions([a],{abortSignal:t});return d}if(n.fallbackSender)return te(a),n.fallbackSender(a);throw new Error("No TransactionSendingSigner was identified and no fallback sender was provided.")}function Ee(e,n={}){var a;let t=((a=n.identifySendingSigner)!=null?a:!0)?_n(e):null,i=e.filter(c=>c!==t&&(x(c)||p(c))),o=Wn(i),s=i.filter(p).filter(c=>!o.includes(c));return Object.freeze({modifyingSigners:o,partialSigners:s,sendingSigner:t})}function _n(e){let n=e.filter(M);if(n.length===0)return null;let r=n.filter(t=>!x(t)&&!p(t));return r.length>0?r[0]:n[0]}function Wn(e){let n=e.filter(x);if(n.length===0)return [];let r=n.filter(t=>!p(t));return r.length>0?r:[n[0]]}async function Ie(e,n=[],r=[],t){var a;let i=await n.reduce(async(c,d)=>{t==null||t.throwIfAborted();let[u]=await d.modifyAndSignTransactions([await c],{abortSignal:t});return Object.freeze(u)},Promise.resolve(e));t==null||t.throwIfAborted();let o=await Promise.all(r.map(async c=>{let[d]=await c.signTransactions([i],{abortSignal:t});return d})),s={...i,signatures:Object.freeze(o.reduce((c,d)=>({...c,...d}),(a=i.signatures)!=null?a:{}))};return Object.freeze(s)}var ve=globalThis.TextEncoder;function Qt(e,n={}){return Object.freeze({content:typeof e=="string"?new ve().encode(e):e,signatures:Object.freeze({...n})})}
For a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20`)}async function me(){var e;if(Y(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.exportKey)!="function")throw new Error("No key export implementation could be found")}async function Se(){var e;if(Y(),typeof globalThis.crypto>"u"||typeof((e=globalThis.crypto.subtle)==null?void 0:e.sign)!="function")throw new Error("No signing implementation could be found")}var H,X;function Z(){return H||(H=W()),H}function Je(){return X||(X=j()),X}function pe(e){return !(e.length<32||e.length>44||Z().encode(e).byteLength!==32)}function Te(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().encode(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(n){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:n})}}function Qe(e){return Te(e),e}function q(){return z(U({encoding:Z(),size:32}),e=>Qe(e))}function ye(){return G({encoding:Je(),size:32})}function F(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}async function L(e){if(await me(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let n=await crypto.subtle.exportKey("raw",e);return ye().decode(new Uint8Array(n))}async function he(){return await le(),await crypto.subtle.generateKey("Ed25519",!1,["sign","verify"])}async function _(e,n){await Se();let r=await crypto.subtle.sign("Ed25519",e,n);return new Uint8Array(r)}function rn(e,n,r){if(n!==r)throw new Error(`Expected [${e}] to have ${n} items, got ${r}.`)}function Ae(e){return e.reduce((n,r)=>n===null||r===null?null:n+r,0)}function we(e){return I(e)?e.fixedSize:null}function xe(e){var n;return I(e)?e.fixedSize:(n=e.maxSize)!=null?n:null}function w(e,n={}){var o,s;let r=(o=n.size)!=null?o:O();r==="remainder"&&se(e,'Codecs of "remainder" size must have fixed-size items.');let t=be(r,we(e)),i=(s=be(r,xe(e)))!=null?s:void 0;return l({...t!==null?{fixedSize:t}:{getSizeFromValue:a=>(typeof r=="object"?S(a.length,r):0)+[...a].reduce((d,f)=>d+S(f,e),0),maxSize:i},write:(a,c,d)=>(typeof r=="number"&&rn("array",r,a.length),typeof r=="object"&&(d=r.write(a.length,c,d)),a.forEach(f=>{d=e.write(f,c,d);}),d)})}function be(e,n){return typeof e!="number"?null:e===0?0:n===null?null:n*e}function Ee(e={}){var t;let n=(t=e.size)!=null?t:"variable",r=l({getSizeFromValue:i=>i.length,write:(i,o,s)=>(o.set(i,s),s+i.length)});return n==="variable"?r:typeof n=="number"?N(r,n):l({getSizeFromValue:i=>S(i.length,n)+i.length,write:(i,o,s)=>(s=n.write(i.length,o,s),r.write(i,o,s))})}function v(e){var i;let n=e.map(([,o])=>o),r=Ae(n.map(we)),t=(i=Ae(n.map(xe)))!=null?i:void 0;return l({...r===null?{getSizeFromValue:o=>e.map(([s,a])=>S(o[s],a)).reduce((s,a)=>s+a,0),maxSize:t}:{fixedSize:r},write:(o,s,a)=>(e.forEach(([c,d])=>{a=d.write(o[c],s,a);}),a)})}var D=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(D||{}),tn=1;function C(e){return e>=2}function P(e){return (e&tn)!==0}function Ie(e,n){return e|n}function ze(e,n,r){var t;e[n]=r((t=e[n])!=null?t:{role:D.READONLY});}var u=Symbol("AddressMapTypeProperty");function sn(e,n){let r={[e]:{[u]:0,role:D.WRITABLE_SIGNER}},t=new Set;for(let i of n){ze(r,i.programAddress,s=>{if(t.add(i.programAddress),u in s){if(P(s.role))switch(s[u]){case 0:throw new Error(`This transaction includes an address (\`${i.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`);default:throw new Error(`This transaction includes an address (\`${i.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`)}if(s[u]===2)return s}return {[u]:2,role:D.READONLY}});let o;if(i.accounts)for(let s of i.accounts)ze(r,s.address,a=>{let{address:c,...d}=s;if(u in a)switch(a[u]){case 0:return a;case 1:{let f=Ie(a.role,d.role);if("lookupTableAddress"in d){if(a.lookupTableAddress!==d.lookupTableAddress&&(o||(o=F()))(d.lookupTableAddress,a.lookupTableAddress)<0)return {[u]:1,...d,role:f}}else if(C(d.role))return {[u]:2,role:f};return a.role!==f?{...a,role:f}:a}case 2:{let f=Ie(a.role,d.role);if(t.has(s.address)){if(P(d.role))throw new Error(`This transaction includes an address (\`${s.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`);return a.role!==f?{...a,role:f}:a}else return "lookupTableAddress"in d&&!C(a.role)?{...d,[u]:1,role:f}:a.role!==f?{...a,role:f}:a}}return "lookupTableAddress"in d?{...d,[u]:1}:{...d,[u]:2}});}return r}function on(e){let n;return Object.entries(e).sort(([t,i],[o,s])=>{if(i[u]!==s[u]){if(i[u]===0)return -1;if(s[u]===0)return 1;if(i[u]===2)return -1;if(s[u]===2)return 1}let a=C(i.role);if(a!==C(s.role))return a?-1:1;let c=P(i.role);return c!==P(s.role)?c?-1:1:(n||(n=F()),i[u]===1&&s[u]===1&&i.lookupTableAddress!==s.lookupTableAddress?n(i.lookupTableAddress,s.lookupTableAddress):n(t,o))}).map(([t,i])=>({address:t,...i}))}function an(e){var r;let n={};for(let t of e){if(!("lookupTableAddress"in t))continue;let i=n[r=t.lookupTableAddress]||(n[r]={readableIndices:[],writableIndices:[]});t.role===D.WRITABLE?i.writableIndices.push(t.addressIndex):i.readableIndices.push(t.addressIndex);}return Object.keys(n).sort(F()).map(t=>({lookupTableAddress:t,...n[t]}))}function cn(e){let n=0,r=0,t=0;for(let i of e){if("lookupTableAddress"in i)break;let o=P(i.role);C(i.role)?(t++,o||r++):o||n++;}return {numReadonlyNonSignerAccounts:n,numReadonlySignerAccounts:r,numSignerAccounts:t}}function dn(e){let n={};for(let[r,t]of e.entries())n[t.address]=r;return n}function gn(e,n){let r=dn(n);return e.map(({accounts:t,data:i,programAddress:o})=>({programAddressIndex:r[o],...t?{accountIndices:t.map(({address:s})=>r[s])}:null,...i?{data:i}:null}))}function un(e){return "nonce"in e?e.nonce:e.blockhash}function fn(e){let n=e.findIndex(t=>"lookupTableAddress"in t);return (n===-1?e:e.slice(0,n)).map(({address:t})=>t)}function ln(e){let n=sn(e.feePayer,e.instructions),r=on(n);return {...e.version!=="legacy"?{addressTableLookups:an(r)}:null,header:cn(r),instructions:gn(e.instructions,r),lifetimeToken:un(e.lifetimeConstraint),staticAccounts:fn(r),version:e.version}}var J;function mn(){return J||(J=v([["lookupTableAddress",q()],["writableIndices",w(A(),{size:h()})],["readableIndices",w(A(),{size:h()})]])),J}var Q;function ee(){return Q||(Q=A()),Q}function Sn(){return v([["numSignerAccounts",ee()],["numReadonlySignerAccounts",ee()],["numReadonlyNonSignerAccounts",ee()]])}var ne;function pn(){return ne||(ne=z(v([["programAddressIndex",A()],["accountIndices",w(A(),{size:h()})],["data",Ee({size:h()})]]),e=>{var n,r;return e.accountIndices!==void 0&&e.data!==void 0?e:{...e,accountIndices:(n=e.accountIndices)!=null?n:[],data:(r=e.data)!=null?r:new Uint8Array(0)}})),ne}var Tn=128;function yn(){return l({getSizeFromValue:e=>e==="legacy"?0:1,maxSize:1,write:(e,n,r)=>{if(e==="legacy")return r;if(e<0||e>127)throw new Error(`Transaction version must be in the range [0, 127]. \`${e}\` given.`);return n.set([e|Tn],r),r+1}})}function ve(){return v(Be())}function Ce(){return z(v([...Be(),["addressTableLookups",hn()]]),e=>{var n;return e.version==="legacy"?e:{...e,addressTableLookups:(n=e.addressTableLookups)!=null?n:[]}})}function Be(){return [["version",yn()],["header",Sn()],["staticAccounts",w(q(),{size:h()})],["lifetimeToken",U({encoding:W(),size:32})],["instructions",w(pn(),{size:h()})]]}function hn(){return w(mn(),{size:h()})}function An(){return l({getSizeFromValue:e=>e.version==="legacy"?ve().getSizeFromValue(e):Ce().getSizeFromValue(e),write:(e,n,r)=>e.version==="legacy"?ve().write(e,n,r):Ce().write(e,n,r)})}async function Me(e,n){let r=ln(n),t="signatures"in n?{...n.signatures}:{},i=An().encode(r),o=await Promise.all(e.map(a=>Promise.all([L(a.publicKey),_(a.privateKey,i)])));for(let[a,c]of o)t[a]=c;let s={...n,signatures:t};return Object.freeze(s),s}function De(e){let n=e.instructions.flatMap(t=>{var i,o;return (o=(i=t.accounts)==null?void 0:i.filter(s=>C(s.role)))!=null?o:[]}).map(t=>t.address);new Set([e.feePayer,...n]).forEach(t=>{if(!e.signatures[t])throw new Error(`Transaction is missing signature for address \`${t}\``)});}function k(e){return "signMessages"in e&&typeof e.signMessages=="function"}function zr(e){if(!k(e))throw new Error("The provided value does not implement the MessagePartialSigner interface")}function m(e){return "signTransactions"in e&&typeof e.signTransactions=="function"}function Br(e){if(!m(e))throw new Error("The provided value does not implement the TransactionPartialSigner interface")}function bn(e){return "keyPair"in e&&typeof e.keyPair=="object"&&k(e)&&m(e)}function Lr(e){if(!bn(e))throw new Error("The provided value does not implement the KeyPairSigner interface")}async function wn(e){let n=await L(e.publicKey);return Object.freeze({address:n,keyPair:e,signMessages:t=>Promise.all(t.map(async i=>Object.freeze({[n]:await _(e.privateKey,i.content)}))),signTransactions:t=>Promise.all(t.map(async i=>{let o=await Me([e],i);return Object.freeze({[n]:o.signatures[n]})}))})}async function _r(){return wn(await he())}function re(e){return pe(e.address)&&"modifyAndSignMessages"in e&&typeof e.modifyAndSignMessages=="function"}function Gr(e){if(!re(e))throw new Error("The provided value does not implement the MessageModifyingSigner interface")}function xn(e){return k(e)||re(e)}function Qr(e){if(!xn(e))throw new Error("The provided value does not implement any of the MessageSigner interfaces")}function rt(e){return Object.freeze({address:e,signMessages:async r=>r.map(()=>Object.freeze({})),signTransactions:async r=>r.map(()=>Object.freeze({}))})}function T(e){return "modifyAndSignTransactions"in e&&typeof e.modifyAndSignTransactions=="function"}function st(e){if(!T(e))throw new Error("The provided value does not implement the TransactionModifyingSigner interface")}function x(e){return "signAndSendTransactions"in e&&typeof e.signAndSendTransactions=="function"}function ct(e){if(!x(e))throw new Error("The provided value does not implement the TransactionSendingSigner interface")}function $(e){return m(e)||T(e)||x(e)}function Tt(e){if(!$(e))throw new Error("The provided value does not implement any of the TransactionSigner interfaces")}async function En(e,n={}){let{partialSigners:r,modifyingSigners:t}=Pe(y(B(e).filter($)),{identifySendingSigner:!1});return ke(e,t,r,n.abortSignal)}async function Rt(e,n={}){let r=await En(e,n);return De(r),r}async function Ot(e,n={}){let r=n.abortSignal,{partialSigners:t,modifyingSigners:i,sendingSigner:o}=Pe(y(B(e).filter($)));r==null||r.throwIfAborted();let s=await ke(e,i,t,r);if(!o)throw new Error("No `TransactionSendingSigner` was identified. Please provide a valid `ITransactionWithSingleSendingSigner` transaction.");r==null||r.throwIfAborted();let[a]=await o.signAndSendTransactions([s],{abortSignal:r});return r==null||r.throwIfAborted(),a}function Pe(e,n={}){var a;let t=((a=n.identifySendingSigner)!=null?a:!0)?In(e):null,i=e.filter(c=>c!==t&&(T(c)||m(c))),o=zn(i),s=i.filter(m).filter(c=>!o.includes(c));return Object.freeze({modifyingSigners:o,partialSigners:s,sendingSigner:t})}function In(e){let n=e.filter(x);if(n.length===0)return null;let r=n.filter(t=>!T(t)&&!m(t));return r.length>0?r[0]:n[0]}function zn(e){let n=e.filter(T);if(n.length===0)return [];let r=n.filter(t=>!m(t));return r.length>0?r:[n[0]]}async function ke(e,n=[],r=[],t){var a;let i=await n.reduce(async(c,d)=>{t==null||t.throwIfAborted();let[f]=await d.modifyAndSignTransactions([await c],{abortSignal:t});return Object.freeze(f)},Promise.resolve(e));t==null||t.throwIfAborted();let o=await Promise.all(r.map(async c=>{let[d]=await c.signTransactions([i],{abortSignal:t});return d})),s={...i,signatures:Object.freeze(o.reduce((c,d)=>({...c,...d}),(a=i.signatures)!=null?a:{}))};return Object.freeze(s)}var Ne=globalThis.TextEncoder;function Vt(e,n={}){return Object.freeze({content:typeof e=="string"?new Ne().encode(e):e,signatures:Object.freeze({...n})})}function qt(e){try{return vn(e),!0}catch{return !1}}function vn(e){let r=B(e).filter(x);if(r.length===0){let i=new Error("No `TransactionSendingSigner` was identified.");throw i.name="MissingTransactionSendingSignerError",i}if(r.filter(i=>!m(i)&&!T(i)).length>1){let i=new Error("More than one `TransactionSendingSigner` was identified.");throw i.name="MultipleTransactionSendingSignersError",i}}
exports.assertIsKeyPairSigner = Xr;
exports.assertIsMessageModifyingSigner = nt;
exports.assertIsMessagePartialSigner = Ur;
exports.assertIsMessageSigner = ct;
exports.assertIsTransactionModifyingSigner = mt;
exports.assertIsTransactionPartialSigner = Rr;
exports.assertIsTransactionSendingSigner = yt;
exports.assertIsTransactionSigner = It;
exports.createNoopSigner = gt;
exports.createSignableMessage = Qt;
exports.createSignerFromKeyPair = Rn;
exports.generateKeyPairSigner = qr;
exports.getSignersFromInstruction = De;
exports.getSignersFromTransaction = _;
exports.isKeyPairSigner = On;
exports.isMessageModifyingSigner = ie;
exports.isMessagePartialSigner = D;
exports.isMessageSigner = Ln;
exports.isTransactionModifyingSigner = x;
exports.isTransactionPartialSigner = p;
exports.isTransactionSendingSigner = M;
exports.isTransactionSigner = F;
exports.partiallySignTransactionWithSigners = Fn;
exports.signAndSendTransactionWithSigners = Ht;
exports.signTransactionWithSigners = Vt;
exports.addSignersToInstruction = We;
exports.addSignersToTransaction = Fn;
exports.assertIsKeyPairSigner = Lr;
exports.assertIsMessageModifyingSigner = Gr;
exports.assertIsMessagePartialSigner = zr;
exports.assertIsMessageSigner = Qr;
exports.assertIsTransactionModifyingSigner = st;
exports.assertIsTransactionPartialSigner = Br;
exports.assertIsTransactionSendingSigner = ct;
exports.assertIsTransactionSigner = Tt;
exports.assertIsTransactionWithSingleSendingSigner = vn;
exports.createNoopSigner = rt;
exports.createSignableMessage = Vt;
exports.createSignerFromKeyPair = wn;
exports.generateKeyPairSigner = _r;
exports.getSignersFromInstruction = Oe;
exports.getSignersFromTransaction = B;
exports.isKeyPairSigner = bn;
exports.isMessageModifyingSigner = re;
exports.isMessagePartialSigner = k;
exports.isMessageSigner = xn;
exports.isTransactionModifyingSigner = T;
exports.isTransactionPartialSigner = m;
exports.isTransactionSendingSigner = x;
exports.isTransactionSigner = $;
exports.isTransactionWithSingleSendingSigner = qt;
exports.partiallySignTransactionWithSigners = En;
exports.signAndSendTransactionWithSigners = Ot;
exports.signTransactionWithSigners = Rt;

@@ -38,0 +42,0 @@ return exports;

@@ -9,10 +9,12 @@ import { AccountRole, IAccountLookupMeta, IAccountMeta, IInstruction } from '@solana/instructions';

}
/** A variation of the IInstruction type that allows IAccountSignerMeta in its accounts array. */
type IAccountMetaWithWithSigner<TSigner extends TransactionSigner = TransactionSigner> = IAccountMeta | IAccountLookupMeta | IAccountSignerMeta<string, TSigner>;
export type IInstructionWithSigners<TProgramAddress extends string = string, TSigner extends TransactionSigner = TransactionSigner, TAccounts extends readonly IAccountMetaWithWithSigner<TSigner>[] = readonly IAccountMetaWithWithSigner<TSigner>[]> = IInstruction<TProgramAddress, TAccounts>;
/** A variation of the instruction type that allows IAccountSignerMeta in its account metas. */
export type IInstructionWithSigners<TSigner extends TransactionSigner = TransactionSigner, TAccounts extends readonly IAccountMetaWithWithSigner<TSigner>[] = readonly IAccountMetaWithWithSigner<TSigner>[]> = Pick<IInstruction<string, TAccounts>, 'accounts'>;
/** A variation of the transaction type that allows IAccountSignerMeta in its account metas. */
export type ITransactionWithSigners<TSigner extends TransactionSigner = TransactionSigner, TAccounts extends readonly IAccountMetaWithWithSigner<TSigner>[] = readonly IAccountMetaWithWithSigner<TSigner>[]> = Pick<BaseTransaction<TransactionVersion, IInstruction & IInstructionWithSigners<TSigner, TAccounts>>, 'instructions'>;
/** Extract all signers from an instruction that may contain IAccountSignerMeta accounts. */
export declare function getSignersFromInstruction<TSigner extends TransactionSigner = TransactionSigner>(instruction: IInstructionWithSigners<string, TSigner>): readonly TSigner[];
export declare function getSignersFromInstruction<TSigner extends TransactionSigner = TransactionSigner>(instruction: IInstructionWithSigners<TSigner>): readonly TSigner[];
/** Extract all signers from a transaction that may contain IAccountSignerMeta accounts. */
export declare function getSignersFromTransaction<TSigner extends TransactionSigner = TransactionSigner, TInstruction extends IInstructionWithSigners<string, TSigner> = IInstructionWithSigners<string, TSigner>>(transaction: BaseTransaction<TransactionVersion, TInstruction>): readonly TSigner[];
export declare function getSignersFromTransaction<TSigner extends TransactionSigner = TransactionSigner, TTransaction extends ITransactionWithSigners<TSigner> = ITransactionWithSigners<TSigner>>(transaction: TTransaction): readonly TSigner[];
export {};
//# sourceMappingURL=account-signer-meta.d.ts.map
export * from './account-signer-meta';
export * from './add-signers';
export * from './keypair-signer';

@@ -13,3 +14,4 @@ export * from './message-modifying-signer';

export * from './transaction-signer';
export * from './transaction-with-single-sending-signer';
export * from './types';
//# sourceMappingURL=index.d.ts.map
import { SignatureBytes } from '@solana/keys';
import { CompilableTransaction, IFullySignedTransaction, ITransactionWithSignatures, TransactionVersion } from '@solana/transactions';
import { IInstructionWithSigners } from './account-signer-meta';
import { TransactionSigner } from './transaction-signer';
type CompilableTransactionWithSigners = CompilableTransaction<TransactionVersion, IInstructionWithSigners<string, TransactionSigner>> & Partial<ITransactionWithSignatures>;
import { CompilableTransaction, IFullySignedTransaction, ITransactionWithSignatures } from '@solana/transactions';
import { ITransactionWithSigners } from './account-signer-meta';
import { ITransactionWithSingleSendingSigner } from './transaction-with-single-sending-signer';
type CompilableTransactionWithSigners = CompilableTransaction & ITransactionWithSigners & Partial<ITransactionWithSignatures>;
/**

@@ -13,3 +13,2 @@ * Signs a transaction using any signers that may be stored in IAccountSignerMeta instruction accounts

abortSignal?: AbortSignal;
signers?: readonly TransactionSigner[];
}): Promise<TTransaction & ITransactionWithSignatures>;

@@ -24,3 +23,2 @@ /**

abortSignal?: AbortSignal;
signers?: readonly TransactionSigner[];
}): Promise<TTransaction & IFullySignedTransaction>;

@@ -33,8 +31,6 @@ /**

*/
export declare function signAndSendTransactionWithSigners<TTransaction extends CompilableTransactionWithSigners = CompilableTransactionWithSigners>(transaction: TTransaction, config?: {
export declare function signAndSendTransactionWithSigners<TTransaction extends CompilableTransactionWithSigners & ITransactionWithSingleSendingSigner = CompilableTransactionWithSigners & ITransactionWithSingleSendingSigner>(transaction: TTransaction, config?: {
abortSignal?: AbortSignal;
fallbackSender?: (transaction: TTransaction & IFullySignedTransaction) => Promise<SignatureBytes>;
signers?: readonly TransactionSigner[];
}): Promise<SignatureBytes>;
export {};
//# sourceMappingURL=sign-transaction.d.ts.map
{
"name": "@solana/signers",
"version": "2.0.0-experimental.0eb69ae",
"version": "2.0.0-experimental.0f3404a",
"description": "An abstraction layer over signing messages and transactions in Solana",

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

"dependencies": {
"@solana/addresses": "2.0.0-experimental.0eb69ae",
"@solana/instructions": "2.0.0-experimental.0eb69ae",
"@solana/keys": "2.0.0-experimental.0eb69ae",
"@solana/transactions": "2.0.0-experimental.0eb69ae"
"@solana/addresses": "2.0.0-experimental.0f3404a",
"@solana/instructions": "2.0.0-experimental.0f3404a",
"@solana/keys": "2.0.0-experimental.0f3404a",
"@solana/transactions": "2.0.0-experimental.0f3404a"
},

@@ -72,3 +72,3 @@ "devDependencies": {

"jest-runner-prettier": "^1.0.0",
"prettier": "^2.8",
"prettier": "^3.1",
"tsup": "^8.0.1",

@@ -75,0 +75,0 @@ "typescript": "^5.2.2",

@@ -394,6 +394,6 @@ [![npm][npm-image]][npm-url]

Extends the `IInstruction` type to allow `IAccountSignerMetas` to be used inside the instruction's `accounts` array.
Composable type that allows `IAccountSignerMetas` to be used inside the instruction's `accounts` array.
```ts
const myInstructionWithSigners: IInstructionWithSigners = {
const myInstructionWithSigners: IInstruction & IInstructionWithSigners = {
programAddress: address('1234..5678'),

@@ -410,2 +410,17 @@ accounts: [

#### `ITransactionWithSigners`
Composable type that allows `IAccountSignerMetas` to be used inside all of the transaction's account metas.
```ts
const myTransactionWithSigners: BaseTransaction & ITransactionWithSigners = {
instructions: [
myInstructionA as IInstruction & IInstructionWithSigners,
myInstructionB as IInstruction & IInstructionWithSigners,
myInstructionC as IInstruction,
],
version: 0,
};
```
### Functions

@@ -441,2 +456,35 @@

#### `addSignersToInstruction()`
Helper function that adds the provided signers to any of the applicable account metas. For an account meta to match a provided signer it:
- Must have a signer role (`AccountRole.READONLY_SIGNER` or `AccountRole.WRITABLE_SIGNER`).
- Must have the same address as the provided signer.
- Must not have an attached signer already.
```ts
const myInstruction: IInstruction = {
accounts: [
{ address: '1111' as Address, role: AccountRole.READONLY_SIGNER },
{ address: '2222' as Address, role: AccountRole.WRITABLE_SIGNER },
],
// ...
};
const signerA: TransactionSigner<'1111'>;
const signerB: TransactionSigner<'2222'>;
const myInstructionWithSigners = addSignersToInstruction([mySignerA, mySignerB], myInstruction);
// myInstructionWithSigners.accounts[0].signer === mySignerA
// myInstructionWithSigners.accounts[1].signer === mySignerB
```
#### `addSignersToTransaction()`
Similarly to `addSignersToInstruction`, this function adds signer to all the applicable account metas of all the instructions inside a transaction.
```ts
const myTransactionWithSigners = addSignersToTransaction(mySigners, myTransaction);
```
## Signing transactions with signers

@@ -455,11 +503,10 @@

```ts
const mySignedTransaction = partiallySignTransactionWithSigners(myTransaction);
const mySignedTransaction = await partiallySignTransactionWithSigners(myTransaction);
```
It also accepts an optional `AbortSignal` and an additional array of signers that will be merged with the ones extracted from the transaction, if any.
It also accepts an optional `AbortSignal` that will be propagated to all signers.
```ts
const mySignedTransaction = partiallySignTransactionWithSigners(myTransaction, {
const mySignedTransaction = await partiallySignTransactionWithSigners(myTransaction, {
abortSignal: myAbortController.signal,
signers: [myOtherSigner],
});

@@ -475,8 +522,7 @@ ```

```ts
const mySignedTransaction = signTransactionWithSigners(myTransaction);
const mySignedTransaction = await signTransactionWithSigners(myTransaction);
// With additional config.
const mySignedTransaction = signTransactionWithSigners(myTransaction, {
const mySignedTransaction = await signTransactionWithSigners(myTransaction, {
abortSignal: myAbortController.signal,
signers: [myOtherSigner],
});

@@ -493,29 +539,38 @@

```ts
const myTransactionSignature = signAndSendTransactionWithSigners(myTransaction);
const myTransactionSignature = await signAndSendTransactionWithSigners(myTransaction);
// With additional config.
const myTransactionSignature = signAndSendTransactionWithSigners(myTransaction, {
const myTransactionSignature = await signAndSendTransactionWithSigners(myTransaction, {
abortSignal: myAbortController.signal,
signers: [myOtherSigner],
});
```
Similarly to the `partiallySignTransactionWithSigners` function, it first uses all `TransactionModifyingSigners` sequentially before using all `TransactionPartialSigners` in parallel. It then sends the transaction using the first `TransactionSendingSigner` it finds. Any other sending signer that does not implement another transaction signer interface will be ignored.
Similarly to the `partiallySignTransactionWithSigners` function, it first uses all `TransactionModifyingSigners` sequentially before using all `TransactionPartialSigners` in parallel. It then sends the transaction using the `TransactionSendingSigner` it identified.
If no `TransactionSendingSigner` is extracted from the transaction or explicitly provided, the `fallbackSender` third argument will be used to send the transaction. If no fallback sender is provided and no sending signer is identified, an error will be thrown.
Here as well, composite transaction signers are treated such that at least one sending signer is used if any. When a `TransactionSigner` implements more than one interface, use it as a:
- `TransactionSendingSigner`, if no other `TransactionSendingSigner` exists.
- `TransactionModifyingSigner`, if no other `TransactionModifyingSigner` exists.
- `TransactionPartialSigner`, otherwise.
The provided transaction must be of type `ITransactionWithSingleSendingSigner` meaning that it must contain exactly one `TransactionSendingSigner` inside its account metas. If more than one composite signers implement the `TransactionSendingSigner` interface, one of them will be selected as the sending signer.
Therefore, you may use the `assertIsTransactionWithSingleSendingSigner()` function to ensure the transaction is of the expected type.
```ts
const fallbackSender = async (transaction: CompilableTransaction) => {
const encodedTransaction = getBase64EncodedWireTransaction(transaction);
const signature = await rpc.sendTransaction(encodedTransaction).send();
return getBase58Encoder().encode(signature);
};
const myTransactionSignature = signAndSendTransactionWithSigners(myTransaction, { fallbackSender });
assertIsTransactionWithSingleSendingSigner(myTransaction);
const myTransactionSignature = await signAndSendTransactionWithSigners(myTransaction);
```
Here as well, composite transaction signers are treated such that at least one sending signer is used if any. When a `TransactionSigner` implements more than one interface, use it as a:
Alternatively, you may use the `isTransactionWithSingleSendingSigner()` function to provide a fallback in case the transaction does not contain any sending signer.
- `TransactionSendingSigner`, if no other `TransactionSendingSigner` exist.
- `TransactionModifyingSigner`, if no other `TransactionModifyingSigner` exist.
- `TransactionPartialSigner`, otherwise.
```ts
let transactionSignature: SignatureBytes;
if (isTransactionWithSingleSendingSigner(transaction)) {
transactionSignature = await signAndSendTransactionWithSigners(transaction);
} else {
const signedTransaction = await signTransactionWithSigners(transaction);
const encodedTransaction = getBase64EncodedWireTransaction(signedTransaction);
transactionSignature = await rpc.sendTransaction(encodedTransaction).send();
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc