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

@solana/transaction-messages

Package Overview
Dependencies
Maintainers
15
Versions
695
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/transaction-messages - npm Package Compare versions

Comparing version 2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72 to 2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b

dist/types/codecs/message.d.ts

166

dist/index.browser.js

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

import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND } from '@solana/errors';
import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE } from '@solana/errors';
import { assertIsBlockhash } from '@solana/rpc-types';
import { getAddressEncoder, getAddressDecoder, getAddressComparator, assertIsAddress } from '@solana/addresses';
import { combineCodec, transformEncoder, addEncoderSizePrefix, transformDecoder, addDecoderSizePrefix, createEncoder, createDecoder } from '@solana/codecs-core';
import { combineCodec, transformEncoder, addEncoderSizePrefix, transformDecoder, addDecoderSizePrefix, createEncoder, createDecoder, fixEncoderSize, fixDecoderSize } from '@solana/codecs-core';
import { getStructEncoder, getArrayEncoder, getStructDecoder, getArrayDecoder, getStructCodec, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';

@@ -163,2 +163,83 @@ import { getU8Encoder, getShortU16Encoder, getU8Decoder, getShortU16Decoder, getU8Codec } from '@solana/codecs-numbers';

}
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
alphabet: alphabet4,
base: alphabet4.length,
value: givenValue
});
}
}
var getBaseXEncoder = (alphabet4) => {
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 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 = [];
while (base10Number > 0n) {
tailBytes.unshift(Number(base10Number % 256n));
base10Number /= 256n;
}
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
if (bytes.length === 0)
return ["", 0];
let trailIndex = bytes.findIndex((n) => n !== 0);
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
const leadingZeroes = alphabet4[0].repeat(trailIndex);
if (trailIndex === bytes.length)
return [leadingZeroes, rawBytes.length];
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 [leadingZeros, tailChars] = value.split(new RegExp(`((?!${zeroCharacter}).*)`));
return [leadingZeros, tailChars];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
let sum = 0n;
for (const char of value) {
sum *= base;
sum += BigInt(alphabet4.indexOf(char));
}
return sum;
}
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";
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
var VERSION_FLAG_MASK = 128;

@@ -200,2 +281,81 @@ function getTransactionVersionEncoder() {

}
// src/codecs/message.ts
function getCompiledMessageLegacyEncoder() {
return getStructEncoder(getPreludeStructEncoderTuple());
}
function getCompiledMessageVersionedEncoder() {
return transformEncoder(
getStructEncoder([
...getPreludeStructEncoderTuple(),
["addressTableLookups", getAddressTableLookupArrayEncoder()]
]),
(value) => {
if (value.version === "legacy") {
return value;
}
return {
...value,
addressTableLookups: value.addressTableLookups ?? []
};
}
);
}
function getPreludeStructEncoderTuple() {
return [
["version", getTransactionVersionEncoder()],
["header", getMessageHeaderEncoder()],
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
["lifetimeToken", fixEncoderSize(getBase58Encoder(), 32)],
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
];
}
function getPreludeStructDecoderTuple() {
return [
["version", getTransactionVersionDecoder()],
["header", getMessageHeaderDecoder()],
["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
["lifetimeToken", fixDecoderSize(getBase58Decoder(), 32)],
["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
["addressTableLookups", getAddressTableLookupArrayDecoder()]
];
}
function getAddressTableLookupArrayEncoder() {
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
}
function getAddressTableLookupArrayDecoder() {
return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
}
function getCompiledTransactionMessageEncoder() {
return createEncoder({
getSizeFromValue: (compiledMessage) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
} else {
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
}
},
write: (compiledMessage, bytes, offset) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
} else {
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
}
}
});
}
function getCompiledTransactionMessageDecoder() {
return transformDecoder(
getStructDecoder(getPreludeStructDecoderTuple()),
({ addressTableLookups, ...restOfMessage }) => {
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
return restOfMessage;
}
return { ...restOfMessage, addressTableLookups };
}
);
}
function getCompiledTransactionMessageCodec() {
return combineCodec(getCompiledTransactionMessageEncoder(), getCompiledTransactionMessageDecoder());
}
var AddressMapEntryType = /* @__PURE__ */ ((AddressMapEntryType2) => {

@@ -739,4 +899,4 @@ AddressMapEntryType2[AddressMapEntryType2["FEE_PAYER"] = 0] = "FEE_PAYER";

export { ADDRESS_MAP_TYPE_PROPERTY, AddressMapEntryType, appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, createTransactionMessage, decompileTransactionMessage, getAddressMapFromInstructions, getAddressTableLookupCodec, getAddressTableLookupDecoder, getAddressTableLookupEncoder, getCompiledAddressTableLookups, getCompiledInstructions, getCompiledLifetimeToken, getCompiledMessageHeader, getCompiledStaticAccounts, getInstructionCodec, getInstructionDecoder, getInstructionEncoder, getMessageHeaderCodec, getMessageHeaderDecoder, getMessageHeaderEncoder, getOrderedAccountsFromAddressMap, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, newCompileTransactionMessage, newIsAdvanceNonceAccountInstruction, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
export { ADDRESS_MAP_TYPE_PROPERTY, AddressMapEntryType, appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, createTransactionMessage, decompileTransactionMessage, getAddressMapFromInstructions, getAddressTableLookupCodec, getAddressTableLookupDecoder, getAddressTableLookupEncoder, getCompiledAddressTableLookups, getCompiledInstructions, getCompiledLifetimeToken, getCompiledMessageHeader, getCompiledStaticAccounts, getCompiledTransactionMessageCodec, getCompiledTransactionMessageDecoder, getCompiledTransactionMessageEncoder, getInstructionCodec, getInstructionDecoder, getInstructionEncoder, getMessageHeaderCodec, getMessageHeaderDecoder, getMessageHeaderEncoder, getOrderedAccountsFromAddressMap, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, newCompileTransactionMessage, newIsAdvanceNonceAccountInstruction, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.browser.js.map

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

import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND } from '@solana/errors';
import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE } from '@solana/errors';
import { assertIsBlockhash } from '@solana/rpc-types';
import { getAddressEncoder, getAddressDecoder, getAddressComparator, assertIsAddress } from '@solana/addresses';
import { combineCodec, transformEncoder, addEncoderSizePrefix, transformDecoder, addDecoderSizePrefix, createEncoder, createDecoder } from '@solana/codecs-core';
import { combineCodec, transformEncoder, addEncoderSizePrefix, transformDecoder, addDecoderSizePrefix, createEncoder, createDecoder, fixEncoderSize, fixDecoderSize } from '@solana/codecs-core';
import { getStructEncoder, getArrayEncoder, getStructDecoder, getArrayDecoder, getStructCodec, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';

@@ -163,2 +163,83 @@ import { getU8Encoder, getShortU16Encoder, getU8Decoder, getShortU16Decoder, getU8Codec } from '@solana/codecs-numbers';

}
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
alphabet: alphabet4,
base: alphabet4.length,
value: givenValue
});
}
}
var getBaseXEncoder = (alphabet4) => {
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 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 = [];
while (base10Number > 0n) {
tailBytes.unshift(Number(base10Number % 256n));
base10Number /= 256n;
}
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
if (bytes.length === 0)
return ["", 0];
let trailIndex = bytes.findIndex((n) => n !== 0);
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
const leadingZeroes = alphabet4[0].repeat(trailIndex);
if (trailIndex === bytes.length)
return [leadingZeroes, rawBytes.length];
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 [leadingZeros, tailChars] = value.split(new RegExp(`((?!${zeroCharacter}).*)`));
return [leadingZeros, tailChars];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
let sum = 0n;
for (const char of value) {
sum *= base;
sum += BigInt(alphabet4.indexOf(char));
}
return sum;
}
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";
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
var VERSION_FLAG_MASK = 128;

@@ -200,2 +281,81 @@ function getTransactionVersionEncoder() {

}
// src/codecs/message.ts
function getCompiledMessageLegacyEncoder() {
return getStructEncoder(getPreludeStructEncoderTuple());
}
function getCompiledMessageVersionedEncoder() {
return transformEncoder(
getStructEncoder([
...getPreludeStructEncoderTuple(),
["addressTableLookups", getAddressTableLookupArrayEncoder()]
]),
(value) => {
if (value.version === "legacy") {
return value;
}
return {
...value,
addressTableLookups: value.addressTableLookups ?? []
};
}
);
}
function getPreludeStructEncoderTuple() {
return [
["version", getTransactionVersionEncoder()],
["header", getMessageHeaderEncoder()],
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
["lifetimeToken", fixEncoderSize(getBase58Encoder(), 32)],
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
];
}
function getPreludeStructDecoderTuple() {
return [
["version", getTransactionVersionDecoder()],
["header", getMessageHeaderDecoder()],
["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
["lifetimeToken", fixDecoderSize(getBase58Decoder(), 32)],
["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
["addressTableLookups", getAddressTableLookupArrayDecoder()]
];
}
function getAddressTableLookupArrayEncoder() {
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
}
function getAddressTableLookupArrayDecoder() {
return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
}
function getCompiledTransactionMessageEncoder() {
return createEncoder({
getSizeFromValue: (compiledMessage) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
} else {
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
}
},
write: (compiledMessage, bytes, offset) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
} else {
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
}
}
});
}
function getCompiledTransactionMessageDecoder() {
return transformDecoder(
getStructDecoder(getPreludeStructDecoderTuple()),
({ addressTableLookups, ...restOfMessage }) => {
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
return restOfMessage;
}
return { ...restOfMessage, addressTableLookups };
}
);
}
function getCompiledTransactionMessageCodec() {
return combineCodec(getCompiledTransactionMessageEncoder(), getCompiledTransactionMessageDecoder());
}
var AddressMapEntryType = /* @__PURE__ */ ((AddressMapEntryType2) => {

@@ -739,4 +899,4 @@ AddressMapEntryType2[AddressMapEntryType2["FEE_PAYER"] = 0] = "FEE_PAYER";

export { ADDRESS_MAP_TYPE_PROPERTY, AddressMapEntryType, appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, createTransactionMessage, decompileTransactionMessage, getAddressMapFromInstructions, getAddressTableLookupCodec, getAddressTableLookupDecoder, getAddressTableLookupEncoder, getCompiledAddressTableLookups, getCompiledInstructions, getCompiledLifetimeToken, getCompiledMessageHeader, getCompiledStaticAccounts, getInstructionCodec, getInstructionDecoder, getInstructionEncoder, getMessageHeaderCodec, getMessageHeaderDecoder, getMessageHeaderEncoder, getOrderedAccountsFromAddressMap, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, newCompileTransactionMessage, newIsAdvanceNonceAccountInstruction, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
export { ADDRESS_MAP_TYPE_PROPERTY, AddressMapEntryType, appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, createTransactionMessage, decompileTransactionMessage, getAddressMapFromInstructions, getAddressTableLookupCodec, getAddressTableLookupDecoder, getAddressTableLookupEncoder, getCompiledAddressTableLookups, getCompiledInstructions, getCompiledLifetimeToken, getCompiledMessageHeader, getCompiledStaticAccounts, getCompiledTransactionMessageCodec, getCompiledTransactionMessageDecoder, getCompiledTransactionMessageEncoder, getInstructionCodec, getInstructionDecoder, getInstructionEncoder, getMessageHeaderCodec, getMessageHeaderDecoder, getMessageHeaderEncoder, getOrderedAccountsFromAddressMap, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, newCompileTransactionMessage, newIsAdvanceNonceAccountInstruction, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map

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

import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND } from '@solana/errors';
import { SolanaError, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION__INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION__FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE } from '@solana/errors';
import { assertIsBlockhash } from '@solana/rpc-types';
import { getAddressEncoder, getAddressDecoder, getAddressComparator, assertIsAddress } from '@solana/addresses';
import { combineCodec, transformEncoder, addEncoderSizePrefix, transformDecoder, addDecoderSizePrefix, createEncoder, createDecoder } from '@solana/codecs-core';
import { combineCodec, transformEncoder, addEncoderSizePrefix, transformDecoder, addDecoderSizePrefix, createEncoder, createDecoder, fixEncoderSize, fixDecoderSize } from '@solana/codecs-core';
import { getStructEncoder, getArrayEncoder, getStructDecoder, getArrayDecoder, getStructCodec, getBytesEncoder, getBytesDecoder } from '@solana/codecs-data-structures';

@@ -163,2 +163,83 @@ import { getU8Encoder, getShortU16Encoder, getU8Decoder, getShortU16Decoder, getU8Codec } from '@solana/codecs-numbers';

}
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
alphabet: alphabet4,
base: alphabet4.length,
value: givenValue
});
}
}
var getBaseXEncoder = (alphabet4) => {
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 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 = [];
while (base10Number > 0n) {
tailBytes.unshift(Number(base10Number % 256n));
base10Number /= 256n;
}
const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
bytes.set(bytesToAdd, offset);
return offset + bytesToAdd.length;
}
});
};
var getBaseXDecoder = (alphabet4) => {
return createDecoder({
read(rawBytes, offset) {
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
if (bytes.length === 0)
return ["", 0];
let trailIndex = bytes.findIndex((n) => n !== 0);
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
const leadingZeroes = alphabet4[0].repeat(trailIndex);
if (trailIndex === bytes.length)
return [leadingZeroes, rawBytes.length];
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 [leadingZeros, tailChars] = value.split(new RegExp(`((?!${zeroCharacter}).*)`));
return [leadingZeros, tailChars];
}
function getBigIntFromBaseX(value, alphabet4) {
const base = BigInt(alphabet4.length);
let sum = 0n;
for (const char of value) {
sum *= base;
sum += BigInt(alphabet4.indexOf(char));
}
return sum;
}
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";
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
var VERSION_FLAG_MASK = 128;

@@ -200,2 +281,81 @@ function getTransactionVersionEncoder() {

}
// src/codecs/message.ts
function getCompiledMessageLegacyEncoder() {
return getStructEncoder(getPreludeStructEncoderTuple());
}
function getCompiledMessageVersionedEncoder() {
return transformEncoder(
getStructEncoder([
...getPreludeStructEncoderTuple(),
["addressTableLookups", getAddressTableLookupArrayEncoder()]
]),
(value) => {
if (value.version === "legacy") {
return value;
}
return {
...value,
addressTableLookups: value.addressTableLookups ?? []
};
}
);
}
function getPreludeStructEncoderTuple() {
return [
["version", getTransactionVersionEncoder()],
["header", getMessageHeaderEncoder()],
["staticAccounts", getArrayEncoder(getAddressEncoder(), { size: getShortU16Encoder() })],
["lifetimeToken", fixEncoderSize(getBase58Encoder(), 32)],
["instructions", getArrayEncoder(getInstructionEncoder(), { size: getShortU16Encoder() })]
];
}
function getPreludeStructDecoderTuple() {
return [
["version", getTransactionVersionDecoder()],
["header", getMessageHeaderDecoder()],
["staticAccounts", getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() })],
["lifetimeToken", fixDecoderSize(getBase58Decoder(), 32)],
["instructions", getArrayDecoder(getInstructionDecoder(), { size: getShortU16Decoder() })],
["addressTableLookups", getAddressTableLookupArrayDecoder()]
];
}
function getAddressTableLookupArrayEncoder() {
return getArrayEncoder(getAddressTableLookupEncoder(), { size: getShortU16Encoder() });
}
function getAddressTableLookupArrayDecoder() {
return getArrayDecoder(getAddressTableLookupDecoder(), { size: getShortU16Decoder() });
}
function getCompiledTransactionMessageEncoder() {
return createEncoder({
getSizeFromValue: (compiledMessage) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
} else {
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
}
},
write: (compiledMessage, bytes, offset) => {
if (compiledMessage.version === "legacy") {
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
} else {
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
}
}
});
}
function getCompiledTransactionMessageDecoder() {
return transformDecoder(
getStructDecoder(getPreludeStructDecoderTuple()),
({ addressTableLookups, ...restOfMessage }) => {
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
return restOfMessage;
}
return { ...restOfMessage, addressTableLookups };
}
);
}
function getCompiledTransactionMessageCodec() {
return combineCodec(getCompiledTransactionMessageEncoder(), getCompiledTransactionMessageDecoder());
}
var AddressMapEntryType = /* @__PURE__ */ ((AddressMapEntryType2) => {

@@ -739,4 +899,4 @@ AddressMapEntryType2[AddressMapEntryType2["FEE_PAYER"] = 0] = "FEE_PAYER";

export { ADDRESS_MAP_TYPE_PROPERTY, AddressMapEntryType, appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, createTransactionMessage, decompileTransactionMessage, getAddressMapFromInstructions, getAddressTableLookupCodec, getAddressTableLookupDecoder, getAddressTableLookupEncoder, getCompiledAddressTableLookups, getCompiledInstructions, getCompiledLifetimeToken, getCompiledMessageHeader, getCompiledStaticAccounts, getInstructionCodec, getInstructionDecoder, getInstructionEncoder, getMessageHeaderCodec, getMessageHeaderDecoder, getMessageHeaderEncoder, getOrderedAccountsFromAddressMap, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, newCompileTransactionMessage, newIsAdvanceNonceAccountInstruction, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
export { ADDRESS_MAP_TYPE_PROPERTY, AddressMapEntryType, appendTransactionMessageInstruction, appendTransactionMessageInstructions, assertIsDurableNonceTransactionMessage, assertIsTransactionMessageWithBlockhashLifetime, createTransactionMessage, decompileTransactionMessage, getAddressMapFromInstructions, getAddressTableLookupCodec, getAddressTableLookupDecoder, getAddressTableLookupEncoder, getCompiledAddressTableLookups, getCompiledInstructions, getCompiledLifetimeToken, getCompiledMessageHeader, getCompiledStaticAccounts, getCompiledTransactionMessageCodec, getCompiledTransactionMessageDecoder, getCompiledTransactionMessageEncoder, getInstructionCodec, getInstructionDecoder, getInstructionEncoder, getMessageHeaderCodec, getMessageHeaderDecoder, getMessageHeaderEncoder, getOrderedAccountsFromAddressMap, getTransactionVersionCodec, getTransactionVersionDecoder, getTransactionVersionEncoder, newCompileTransactionMessage, newIsAdvanceNonceAccountInstruction, prependTransactionMessageInstruction, prependTransactionMessageInstructions, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, setTransactionMessageLifetimeUsingDurableNonce };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.node.js.map
export * from './address-table-lookup.js';
export * from './header.js';
export * from './instruction.js';
export * from './message.js';
export * from './transaction-version.js';
//# sourceMappingURL=index.d.ts.map
export * from './blockhash.js';
export * from './codecs/index.js';
export * from './compilable-transaction-message.js';
export * from './compile/index.js';

@@ -4,0 +5,0 @@ export * from './create-transaction-message.js';

18

package.json
{
"name": "@solana/transaction-messages",
"version": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"version": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"description": "Helpers for creating transaction messages",

@@ -49,10 +49,10 @@ "exports": {

"dependencies": {
"@solana/addresses": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/codecs-core": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/codecs-data-structures": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/codecs-numbers": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/errors": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/functional": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/instructions": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72",
"@solana/rpc-types": "2.0.0-preview.1.20240410141138.95897483b6e527eed4114ac0db0797c66f2cad72"
"@solana/addresses": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/codecs-core": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/codecs-data-structures": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/codecs-numbers": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/errors": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/functional": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/instructions": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b",
"@solana/rpc-types": "2.0.0-preview.1.20240410141348.7265594ce8ac9480dea2b0f5fe84b24fdacf115b"
},

@@ -59,0 +59,0 @@ "bundlewatch": {

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