@solana/transactions 6.2.0 → 6.3.0-canary-20260310152357

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -217,7 +217,12 @@ function makeSignaturesMap(signerAddresses, signatures) {
217
217
  return Object.freeze(signaturesMap);
218
218
  }
219
219
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
220
- function compiledInstructionIsAdvanceNonceInstruction(instruction, staticAddresses) {
220
+ function compiledV1InstructionIsAdvanceNonceInstruction(instructionHeader, instructionPayload, staticAddresses) {
221
+ return staticAddresses[instructionHeader.programAccountIndex] === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
222
+ isAdvanceNonceAccountInstructionData(instructionPayload.instructionData) && // Test for exactly 3 accounts
223
+ instructionHeader.numInstructionAccounts === 3;
224
+ }
225
+ function compiledLegacyInstructionIsAdvanceNonceInstruction(instruction, staticAddresses) {
221
226
  return staticAddresses[instruction.programAddressIndex] === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
222
227
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
223
228
  instruction.accountIndices?.length === 3;
@@ -226,26 +231,61 @@ function isAdvanceNonceAccountInstructionData(data) {
226
231
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
227
232
  }
228
233
  async function getTransactionLifetimeConstraintFromCompiledTransactionMessage(compiledTransactionMessage) {
229
- const firstInstruction = compiledTransactionMessage.instructions[0];
230
- const { staticAccounts } = compiledTransactionMessage;
231
- if (firstInstruction && compiledInstructionIsAdvanceNonceInstruction(firstInstruction, staticAccounts)) {
232
- const nonceAccountAddress = staticAccounts[firstInstruction.accountIndices[0]];
233
- if (!nonceAccountAddress) {
234
- throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, {
235
- nonce: compiledTransactionMessage.lifetimeToken
236
- });
234
+ const { version } = compiledTransactionMessage;
235
+ if (version === "legacy" || version === 0) {
236
+ const firstInstruction = compiledTransactionMessage.instructions[0];
237
+ const { staticAccounts } = compiledTransactionMessage;
238
+ if (firstInstruction && compiledLegacyInstructionIsAdvanceNonceInstruction(firstInstruction, staticAccounts)) {
239
+ const nonceAccountAddress = staticAccounts[firstInstruction.accountIndices[0]];
240
+ if (!nonceAccountAddress) {
241
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, {
242
+ nonce: compiledTransactionMessage.lifetimeToken
243
+ });
244
+ }
245
+ return {
246
+ nonce: compiledTransactionMessage.lifetimeToken,
247
+ nonceAccountAddress
248
+ };
249
+ } else {
250
+ return {
251
+ blockhash: compiledTransactionMessage.lifetimeToken,
252
+ // This is not known from the compiled message, so we set it to the maximum possible value
253
+ lastValidBlockHeight: 0xffffffffffffffffn
254
+ };
237
255
  }
238
- return {
239
- nonce: compiledTransactionMessage.lifetimeToken,
240
- nonceAccountAddress
241
- };
242
- } else {
243
- return {
244
- blockhash: compiledTransactionMessage.lifetimeToken,
245
- // This is not known from the compiled message, so we set it to the maximum possible value
246
- lastValidBlockHeight: 0xffffffffffffffffn
247
- };
248
256
  }
257
+ if (version === 1) {
258
+ const firstInstructionHeader = compiledTransactionMessage.instructionHeaders[0];
259
+ const firstInstructionPayload = compiledTransactionMessage.instructionPayloads[0];
260
+ const { staticAccounts } = compiledTransactionMessage;
261
+ if (firstInstructionHeader && firstInstructionPayload && compiledV1InstructionIsAdvanceNonceInstruction(
262
+ firstInstructionHeader,
263
+ firstInstructionPayload,
264
+ staticAccounts
265
+ )) {
266
+ const nonceAccountAddress = staticAccounts[firstInstructionPayload.instructionAccountIndices[0]];
267
+ if (!nonceAccountAddress) {
268
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__INVALID_NONCE_ACCOUNT_INDEX, {
269
+ nonce: compiledTransactionMessage.lifetimeToken,
270
+ nonceAccountIndex: firstInstructionPayload.instructionAccountIndices[0],
271
+ numberOfStaticAccounts: staticAccounts.length
272
+ });
273
+ }
274
+ return {
275
+ nonce: compiledTransactionMessage.lifetimeToken,
276
+ nonceAccountAddress
277
+ };
278
+ } else {
279
+ return {
280
+ blockhash: compiledTransactionMessage.lifetimeToken,
281
+ // This is not known from the compiled message, so we set it to the maximum possible value
282
+ lastValidBlockHeight: 0xffffffffffffffffn
283
+ };
284
+ }
285
+ }
286
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, {
287
+ unsupportedVersion: version
288
+ });
249
289
  }
250
290
  function isTransactionWithBlockhashLifetime(transaction) {
251
291
  return "lifetimeConstraint" in transaction && "blockhash" in transaction.lifetimeConstraint && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint" && rpcTypes.isBlockhash(transaction.lifetimeConstraint.blockhash);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/codecs/signatures-encoder.ts","../src/codecs/transaction-codec.ts","../src/lifetime.ts","../src/compile-transaction.ts","../src/signatures.ts","../src/wire-transaction.ts","../src/transaction-size.ts","../src/sendable-transaction.ts","../src/transaction-message-size.ts"],"names":["SolanaError","SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES","transformEncoder","getArrayEncoder","fixEncoderSize","getBytesEncoder","getShortU16Encoder","SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES","getTransactionVersionDecoder","SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES","SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST","SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED","getPredicateEncoder","getStructEncoder","SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES","createEncoder","getPredicateDecoder","transformDecoder","getStructDecoder","getArrayDecoder","fixDecoderSize","getBytesDecoder","getShortU16Decoder","createDecoder","SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES","combineCodec","getTupleDecoder","padRightDecoder","getU8Decoder","getAddressDecoder","SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH","SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE","isBlockhash","SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME","isAddress","SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME","compileTransactionMessage","getCompiledTransactionMessageEncoder","isTransactionMessageWithBlockhashLifetime","isTransactionMessageWithDurableNonceLifetime","getBase58Decoder","SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING","getAddressFromPublicKey","signBytes","bytesEqual","SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION","SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING","getBase64Decoder","SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,sBAAsB,aAAA,EAAgD;AAC3E,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA;AAC9C,EAAA,IAAI,UAAA,CAAW,WAAW,CAAA,EAAG;AACzB,IAAA,MAAM,IAAIA,mBAAYC,qEAA8D,CAAA;AAAA,EACxF;AAEA,EAAA,OAAO,UAAA,CAAW,IAAI,CAAA,SAAA,KAAa;AAC/B,IAAA,IAAI,CAAC,SAAA,EAAW;AACZ,MAAA,OAAO,IAAI,UAAA,CAAW,EAAE,CAAA,CAAE,KAAK,CAAC,CAAA;AAAA,IACpC;AACA,IAAA,OAAO,SAAA;AA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AA;AAClD;AC1DO,SAAS,0BACZ,kBAAA,EACM;AACN,EAAA,OAAO,kBAAA,CAAmB,kBAAA,CAAmB,kBAAkB,CAAC,CAAA;AACpE;AAeO,SAAS,oCAGZ,kBAAA,EAC6E;AAC7E,EAAA,OAAO,yBAAA,CAA0B,kBAAkB,CAAA,IAAK,sBAAA;AAC5D;AAiBO,SAAS,0CAGZ,kBAAA,EACqF;AACrF,EAAA,MAAM,eAAA,GAAkB,0BAA0B,kBAAkB,CAAA;AACpE,EAAA,IAAI,kBAAkB,sBAAA,EAAwB;AAC1C,IAAA,MAAM,IAAIhD,mBAAYgD,oDAAAA,EAA+C;AAAA,MACjE,eAAA;AAAA,MACA,oBAAA,EAAsB;AAAA,KACzB,CAAA;AAAA,EACL;AACJ","file":"index.browser.cjs","sourcesContent":["import { FixedSizeEncoder, fixEncoderSize, transformEncoder, VariableSizeEncoder } from '@solana/codecs-core';\nimport { getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';\nimport { getShortU16Encoder } from '@solana/codecs-numbers';\nimport { SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES, SolanaError } from '@solana/errors';\nimport { SignatureBytes } from '@solana/keys';\n\nimport { SignaturesMap } from '../transaction';\n\nfunction getSignaturesToEncode(signaturesMap: SignaturesMap): SignatureBytes[] {\n const signatures = Object.values(signaturesMap);\n if (signatures.length === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES);\n }\n\n return signatures.map(signature => {\n if (!signature) {\n return new Uint8Array(64).fill(0) as SignatureBytes;\n }\n return signature;\n });\n}\n\n/**\n * Signatures encoder used for legacy and v0 transactions, which encode signatures\n * as an array with a u16-short size prefix\n *\n * @internal\n */\nexport function getSignaturesEncoderWithSizePrefix(): VariableSizeEncoder<SignaturesMap> {\n return transformEncoder(\n getArrayEncoder(fixEncoderSize(getBytesEncoder(), 64), { size: getShortU16Encoder() }),\n getSignaturesToEncode,\n );\n}\n\n/**\n * Signatures encoder used for v1 transactions, which encode signatures\n * as a known-size array\n *\n * @param size Known number of signatures for the transaction\n *\n * @internal\n */\nexport function getSignaturesEncoderWithLength(size: number): FixedSizeEncoder<SignaturesMap> {\n return transformEncoder(\n getArrayEncoder(fixEncoderSize(getBytesEncoder(), 64), { description: 'signatures', size }),\n getSignaturesToEncode,\n );\n}\n","import { Address, getAddressDecoder } from '@solana/addresses';\nimport {\n combineCodec,\n createDecoder,\n createEncoder,\n fixDecoderSize,\n padRightDecoder,\n ReadonlyUint8Array,\n transformDecoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\nimport {\n getArrayDecoder,\n getBytesDecoder,\n getBytesEncoder,\n getPredicateDecoder,\n getPredicateEncoder,\n getStructDecoder,\n getStructEncoder,\n getTupleDecoder,\n} from '@solana/codecs-data-structures';\nimport { getShortU16Decoder, getU8Decoder } from '@solana/codecs-numbers';\nimport {\n SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES,\n SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES,\n SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES,\n SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH,\n SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES,\n SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED,\n SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST,\n SolanaError,\n} from '@solana/errors';\nimport { SignatureBytes } from '@solana/keys';\nimport { getTransactionVersionDecoder } from '@solana/transaction-messages';\n\nimport { SignaturesMap, Transaction, TransactionMessageBytes } from '../transaction';\nimport { getSignaturesEncoderWithLength, getSignaturesEncoderWithSizePrefix } from './signatures-encoder';\n\ntype EnvelopeShape = 'messageFirst' | 'signaturesFirst';\n\nconst SIGNATURE_COUNT_FLAG_MASK = 0b10000000;\nconst VERSION_FLAG_MASK = 0b01111111;\n\nfunction getEnvelopeShapeFromMessageBytes(messageBytes: ReadonlyUint8Array): EnvelopeShape {\n if (messageBytes.length === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES);\n }\n\n const version = getTransactionVersionDecoder().decode(messageBytes);\n return version === 1 ? 'messageFirst' : 'signaturesFirst';\n}\n\nfunction getEnvelopeShapeFromTransactionBytes(transactionBytes: ReadonlyUint8Array): EnvelopeShape {\n if (transactionBytes.length === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES);\n }\n const firstByte = transactionBytes[0];\n if ((firstByte & SIGNATURE_COUNT_FLAG_MASK) === 0) {\n // First byte is a signature count, so signatures come first\n return 'signaturesFirst';\n }\n // If the first byte is not a signature count, then we must have message bytes first,\n // and the first byte of the message must be the version byte\n const version = firstByte & VERSION_FLAG_MASK;\n if (version === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST, {\n firstByte,\n transactionBytes,\n });\n }\n if (version === 1) {\n return 'messageFirst';\n }\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, {\n unsupportedVersion: version,\n });\n}\n\n/**\n * Returns an encoder that you can use to encode a {@link Transaction} to a byte array in a wire\n * format appropriate for sending to the Solana network for execution.\n */\nexport function getTransactionEncoder(): VariableSizeEncoder<Transaction> {\n return getPredicateEncoder(\n (transaction: Transaction) => getEnvelopeShapeFromMessageBytes(transaction.messageBytes) === 'signaturesFirst',\n getTransactionEncoderWithSignaturesFirst(),\n getTransactionEncoderWithMessageFirst(),\n );\n}\n\nfunction getTransactionEncoderWithSignaturesFirst(): VariableSizeEncoder<Transaction> {\n return getStructEncoder([\n ['signatures', getSignaturesEncoderWithSizePrefix()],\n ['messageBytes', getBytesEncoder()],\n ]);\n}\n\nfunction getSignatureCountForVersionedOrThrow(messageBytes: ReadonlyUint8Array, offset: number): number {\n if (messageBytes.length < offset + 2) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES, {\n messageBytes,\n });\n }\n return messageBytes[offset + 1]; // second byte\n}\n\nfunction getTransactionEncoderWithMessageFirst(): VariableSizeEncoder<Transaction> {\n const bytesEncoder = getBytesEncoder();\n\n return createEncoder({\n getSizeFromValue: (transaction: Transaction) => {\n const signatureCount = getSignatureCountForVersionedOrThrow(transaction.messageBytes, 0);\n return transaction.messageBytes.length + signatureCount * 64;\n },\n write: (transaction: Transaction, bytes: Uint8Array, offset: number) => {\n // 1. Encode messageBytes first\n offset = bytesEncoder.write(transaction.messageBytes, bytes, offset);\n\n // 2. Extract signature count from second byte\n const signatureCount = getSignatureCountForVersionedOrThrow(transaction.messageBytes, 0);\n\n // 3. Encode signatures with the extracted length\n const signaturesEncoder = getSignaturesEncoderWithLength(signatureCount);\n offset = signaturesEncoder.write(transaction.signatures, bytes, offset);\n\n return offset;\n },\n });\n}\n\n/**\n * Returns a decoder that you can use to convert a byte array in the Solana transaction wire format\n * to a {@link Transaction} object.\n *\n * @example\n * ```ts\n * import { getTransactionDecoder } from '@solana/transactions';\n *\n * const transactionDecoder = getTransactionDecoder();\n * const transaction = transactionDecoder.decode(wireTransactionBytes);\n * for (const [address, signature] in Object.entries(transaction.signatures)) {\n * console.log(`Signature by ${address}`, signature);\n * }\n * ```\n */\n\nexport function getTransactionDecoder(): VariableSizeDecoder<Transaction> {\n return getPredicateDecoder(\n (transactionBytes: ReadonlyUint8Array) =>\n getEnvelopeShapeFromTransactionBytes(transactionBytes) === 'signaturesFirst',\n getTransactionDecoderWithSignaturesFirst(),\n getTransactionDecoderWithMessageFirst(),\n );\n}\n\nfunction getTransactionDecoderWithSignaturesFirst(): VariableSizeDecoder<Transaction> {\n return transformDecoder(\n getStructDecoder([\n ['signatures', getArrayDecoder(fixDecoderSize(getBytesDecoder(), 64), { size: getShortU16Decoder() })],\n ['messageBytes', getBytesDecoder()],\n ]),\n decodePartiallyDecodedLegacyOrV0Transaction,\n );\n}\n\nfunction getTransactionDecoderWithMessageFirst(): VariableSizeDecoder<Transaction> {\n return transformDecoder(\n getPartiallyDecodedTransactionDecoderWithMessageFirst(),\n decodePartiallyDecodedV1Transaction,\n );\n}\n\nfunction getPartiallyDecodedTransactionDecoderWithMessageFirst(): VariableSizeDecoder<PartiallyDecodedTransaction> {\n return createDecoder({\n read(bytes, offset) {\n // 1. Message comes first, so read signature count from message bytes\n const signatureCount = getSignatureCountForVersionedOrThrow(bytes, offset);\n const signatureByteLength = signatureCount * 64;\n\n // 2. Read the message, which is all bytes except the last {signatureByteLength} bytes\n // Note that this is based on an assumption that we want to read the rest of the input bytes\n // as a transaction, which allows us to avoid decoding the entire message bytes to read each field\n // This is the same logic as using `getBytesDecoder` to read the message bytes when they are trailing\n const messageBytesLength = bytes.length - offset - signatureByteLength;\n if (messageBytesLength < 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES, {\n numExpectedSignatures: signatureCount,\n transactionBytes: bytes.subarray(offset),\n transactionBytesLength: bytes.length - offset,\n });\n }\n const messageBytes = bytes.subarray(offset, offset + messageBytesLength);\n\n // 3. Read the signature bytes, which are the remaining bytes\n const [signatures, finalOffset] = getArrayDecoder(fixDecoderSize(getBytesDecoder(), 64), {\n size: signatureCount,\n }).read(bytes, offset + messageBytesLength);\n\n return [\n {\n messageBytes: messageBytes as unknown as TransactionMessageBytes,\n signatures,\n },\n finalOffset,\n ];\n },\n });\n}\n\n/**\n * Returns a codec that you can use to encode from or decode to a {@link Transaction}\n *\n * @see {@link getTransactionDecoder}\n * @see {@link getTransactionEncoder}\n */\nexport function getTransactionCodec(): VariableSizeCodec<Transaction> {\n return combineCodec(getTransactionEncoder(), getTransactionDecoder());\n}\n\ntype PartiallyDecodedTransaction = {\n messageBytes: ReadonlyUint8Array;\n signatures: ReadonlyUint8Array[];\n};\n\nfunction decodePartiallyDecodedLegacyOrV0Transaction(transaction: PartiallyDecodedTransaction): Transaction {\n const { messageBytes, signatures } = transaction;\n\n /*\n Relevant message structure is at the start:\n - transaction version (0 bytes for legacy transactions, 1 byte for versioned transactions)\n - `numRequiredSignatures` (1 byte, we verify this matches the length of signatures)\n - `numReadOnlySignedAccounts` (1 byte, not used here)\n - `numReadOnlyUnsignedAccounts` (1 byte, not used here)\n - static addresses, with signers first. This is an array of addresses, prefixed with a short-u16 length\n */\n\n const signerAddressesDecoder = getTupleDecoder([\n // read transaction version\n getTransactionVersionDecoder(),\n // read first byte of header, `numSignerAccounts`\n // padRight to skip the next 2 bytes, `numReadOnlySignedAccounts` and `numReadOnlyUnsignedAccounts` which we don't need\n padRightDecoder(getU8Decoder(), 2),\n // read static addresses\n getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() }),\n ]);\n const [_txVersion, numRequiredSignatures, staticAddresses] = signerAddressesDecoder.decode(messageBytes);\n\n const signerAddresses = staticAddresses.slice(0, numRequiredSignatures);\n\n // signer addresses and signatures must be the same length\n // we encode an all-zero signature when the signature is missing\n if (signerAddresses.length !== signatures.length) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH, {\n numRequiredSignatures,\n signaturesLength: signatures.length,\n signerAddresses,\n });\n }\n\n // combine the signer addresses + signatures into the signatures map\n const signaturesMap = makeSignaturesMap(signerAddresses, signatures);\n\n return {\n messageBytes: messageBytes as TransactionMessageBytes,\n signatures: Object.freeze(signaturesMap),\n };\n}\n\nfunction decodePartiallyDecodedV1Transaction(transaction: PartiallyDecodedTransaction): Transaction {\n const { messageBytes, signatures } = transaction;\n\n /*\n Relevant message structure is at the start:\n - transaction version (1 byte for versioned transactions)\n - `numRequiredSignatures` (1 byte, we verify this matches the length of signatures)\n - `numReadOnlySignedAccounts` (1 byte, not used here)\n - `numReadOnlyUnsignedAccounts` (1 byte, not used here)\n - transaction config mask (4 bytes, not used here)\n - lifetime specifier (4 bytes, not used here)\n - num instructions (1 byte, not used here)\n - num addresses (1 byte, not used here because we only need to read `numRequiredSignatures` addresses)\n - static addresses, with signers first. This is an array of addresses, with no prefix\n */\n\n const numRequiredSignatures = messageBytes[1]; // second byte\n\n /**\n * Static addresses start after:\n * - 1 byte transaction version\n * - 3 bytes for the header (`numRequiredSignatures`, `numReadOnlySignedAccounts`, and `numReadOnlyUnsignedAccounts`)\n * - 4 bytes for transaction config mask\n * - 4 bytes for lifetime specifier\n * - 1 byte for num instructions\n * - 1 byte for num addresses\n */\n const staticAddressOffset = 1 + 3 + 4 + 4 + 1 + 1;\n\n const signerAddresses = getArrayDecoder(getAddressDecoder(), { size: numRequiredSignatures }).decode(\n messageBytes,\n staticAddressOffset,\n );\n\n if (signerAddresses.length !== signatures.length) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH, {\n numRequiredSignatures,\n signaturesLength: signatures.length,\n signerAddresses,\n });\n }\n\n const signaturesMap = makeSignaturesMap(signerAddresses, signatures);\n\n return {\n messageBytes: messageBytes as TransactionMessageBytes,\n signatures: signaturesMap,\n };\n}\n\nfunction makeSignaturesMap(signerAddresses: Address[], signatures: ReadonlyUint8Array[]): SignaturesMap {\n // combine the signer addresses + signatures into the signatures map\n const signaturesMap: SignaturesMap = {};\n signerAddresses.forEach((address, index) => {\n const signatureForAddress = signatures[index];\n if (signatureForAddress.every(b => b === 0)) {\n signaturesMap[address] = null;\n } else {\n signaturesMap[address] = signatureForAddress as SignatureBytes;\n }\n });\n\n return Object.freeze(signaturesMap);\n}\n","import { type Address, isAddress } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME,\n SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME,\n SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE,\n SolanaError,\n} from '@solana/errors';\nimport { type Blockhash, isBlockhash, type Slot } from '@solana/rpc-types';\nimport type {\n CompiledTransactionMessage,\n CompiledTransactionMessageWithLifetime,\n Nonce,\n TransactionMessage,\n TransactionMessageWithBlockhashLifetime,\n TransactionMessageWithDurableNonceLifetime,\n} from '@solana/transaction-messages';\n\nimport type { Transaction } from './transaction';\n\n/**\n * A constraint which, when applied to a transaction, makes that transaction eligible to land on the\n * network. The transaction will continue to be eligible to land until the network considers the\n * `blockhash` to be expired.\n *\n * This can happen when the network proceeds past the `lastValidBlockHeight` for which the blockhash\n * is considered valid, or when the network switches to a fork where that blockhash is not present.\n */\nexport type TransactionBlockhashLifetime = {\n /**\n * A recent blockhash observed by the transaction proposer.\n *\n * The transaction will be considered eligible to land until the network determines this\n * blockhash to be too old, or has switched to a fork where it is not present.\n */\n blockhash: Blockhash;\n /**\n * This is the block height beyond which the network will consider the blockhash to be too old\n * to make a transaction eligible to land.\n */\n lastValidBlockHeight: Slot;\n};\n\n/**\n * A constraint which, when applied to a transaction, makes that transaction eligible to land on the\n * network.\n *\n * The transaction will continue to be eligible to land until the network considers the `nonce` to\n * have advanced. This can happen when the nonce account in which this nonce is found is destroyed,\n * or the nonce value within changes.\n */\nexport type TransactionDurableNonceLifetime = {\n /**\n * A value contained in the account with address `nonceAccountAddress` at the time the\n * transaction was prepared.\n *\n * The transaction will be considered eligible to land until the nonce account ceases to exist\n * or contain this value.\n */\n nonce: Nonce;\n /** The account that contains the `nonce` value */\n nonceAccountAddress: Address;\n};\n\n/**\n * A transaction whose ability to land on the network is determined by some evanescent criteria.\n *\n * This describes a window of time after which a transaction is constructed and before which it will\n * no longer be accepted by the network.\n *\n * No transaction can land on Solana without having a `lifetimeConstraint` set.\n */\nexport type TransactionWithLifetime = {\n readonly lifetimeConstraint: TransactionBlockhashLifetime | TransactionDurableNonceLifetime;\n};\n\n/**\n * A transaction whose lifetime is determined by the age of a blockhash observed on the network.\n *\n * The transaction will continue to be eligible to land until the network considers the `blockhash`\n * to be expired.\n */\nexport type TransactionWithBlockhashLifetime = {\n readonly lifetimeConstraint: TransactionBlockhashLifetime;\n};\n\n/**\n * A transaction whose lifetime is determined by a nonce.\n *\n * The transaction will continue to be eligible to land until the network considers the `nonce` to\n * have advanced. This can happen when the nonce account in which this nonce is found is destroyed,\n * or the nonce value within changes.\n */\nexport type TransactionWithDurableNonceLifetime = {\n readonly lifetimeConstraint: TransactionDurableNonceLifetime;\n};\n\n/**\n * Helper type that sets the lifetime constraint of a transaction to be the same as the\n * lifetime constraint of the provided transaction message.\n *\n * If the transaction message has no explicit lifetime constraint, neither will the transaction.\n */\nexport type SetTransactionLifetimeFromTransactionMessage<\n TTransaction extends Transaction,\n TTransactionMessage extends TransactionMessage,\n> = TTransactionMessage extends { lifetimeConstraint: unknown }\n ? TTransactionMessage['lifetimeConstraint'] extends TransactionMessageWithBlockhashLifetime['lifetimeConstraint']\n ? TransactionWithBlockhashLifetime & TTransaction\n : TTransactionMessage['lifetimeConstraint'] extends TransactionMessageWithDurableNonceLifetime['lifetimeConstraint']\n ? TransactionWithDurableNonceLifetime & TTransaction\n : TransactionWithLifetime & TTransaction\n : TTransaction;\n\nconst SYSTEM_PROGRAM_ADDRESS = '11111111111111111111111111111111' as Address;\n\nfunction compiledInstructionIsAdvanceNonceInstruction(\n instruction: CompiledTransactionMessage['instructions'][number],\n staticAddresses: Address[],\n): instruction is typeof instruction & { accountIndices: [number, number, number] } {\n return (\n staticAddresses[instruction.programAddressIndex] === SYSTEM_PROGRAM_ADDRESS &&\n // Test for `AdvanceNonceAccount` instruction data\n instruction.data != null &&\n isAdvanceNonceAccountInstructionData(instruction.data) &&\n // Test for exactly 3 accounts\n instruction.accountIndices?.length === 3\n );\n}\n\nfunction isAdvanceNonceAccountInstructionData(data: ReadonlyUint8Array): boolean {\n // AdvanceNonceAccount is the fifth instruction in the System Program (index 4)\n return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;\n}\n\n/**\n * Get the lifetime constraint for a transaction from a compiled transaction message that includes a lifetime token.\n * @param compiledTransactionMessage A compiled transaction message that includes a lifetime token\n * @returns A lifetime constraint for the transaction\n * Note that this is less precise than checking a decompiled instruction, as we can't inspect\n * the address or role of input accounts (which may be in lookup tables). However, this is\n * sufficient for all valid advance durable nonce instructions.\n * Note that the program address must not be in a lookup table, see [this answer on StackExchange](https://solana.stackexchange.com/a/16224/289)\n * @see {@link isAdvanceNonceAccountInstruction}\n * Note that this function is async to allow for future implementations that may fetch `lastValidBlockHeight` using an RPC\n */\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function getTransactionLifetimeConstraintFromCompiledTransactionMessage(\n compiledTransactionMessage: CompiledTransactionMessage & CompiledTransactionMessageWithLifetime,\n): Promise<TransactionBlockhashLifetime | TransactionDurableNonceLifetime> {\n const firstInstruction = compiledTransactionMessage.instructions[0];\n const { staticAccounts } = compiledTransactionMessage;\n\n // We need to check if the first instruction is an AdvanceNonceAccount instruction\n if (firstInstruction && compiledInstructionIsAdvanceNonceInstruction(firstInstruction, staticAccounts)) {\n const nonceAccountAddress = staticAccounts[firstInstruction.accountIndices[0]];\n if (!nonceAccountAddress) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, {\n nonce: compiledTransactionMessage.lifetimeToken,\n });\n }\n return {\n nonce: compiledTransactionMessage.lifetimeToken as Nonce,\n nonceAccountAddress,\n };\n } else {\n return {\n blockhash: compiledTransactionMessage.lifetimeToken as Blockhash,\n // This is not known from the compiled message, so we set it to the maximum possible value\n lastValidBlockHeight: 0xffffffffffffffffn,\n };\n }\n}\n\n/**\n * A type guard that returns `true` if the transaction conforms to the\n * {@link TransactionWithBlockhashLifetime} type, and refines its type for use in your\n * program.\n *\n * @example\n * ```ts\n * import { isTransactionWithBlockhashLifetime } from '@solana/transactions';\n *\n * if (isTransactionWithBlockhashLifetime(transaction)) {\n * // At this point, `transaction` has been refined to a `TransactionWithBlockhashLifetime`.\n * const { blockhash } = transaction.lifetimeConstraint;\n * const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();\n * setBlockhashIsValid(blockhashIsValid);\n * } else {\n * setError(\n * `${getSignatureFromTransaction(transaction)} does not have a blockhash-based lifetime`,\n * );\n * }\n * ```\n */\nexport function isTransactionWithBlockhashLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): transaction is Transaction & TransactionWithBlockhashLifetime {\n return (\n 'lifetimeConstraint' in transaction &&\n 'blockhash' in transaction.lifetimeConstraint &&\n typeof transaction.lifetimeConstraint.blockhash === 'string' &&\n typeof transaction.lifetimeConstraint.lastValidBlockHeight === 'bigint' &&\n isBlockhash(transaction.lifetimeConstraint.blockhash)\n );\n}\n\n/**\n * From time to time you might acquire a transaction, that you expect to have a\n * blockhash-based lifetime, from for example a wallet. Use this function to\n * assert that such a transaction actually has a blockhash-based lifetime.\n *\n * @example\n * ```ts\n * import { assertIsTransactionWithBlockhashLifetime } from '@solana/transactions';\n *\n * try {\n * // If this type assertion function doesn't throw, then\n * // Typescript will upcast `transaction` to `TransactionWithBlockhashLifetime`.\n * assertIsTransactionWithBlockhashLifetime(transaction);\n * // At this point, `transaction` is a `TransactionWithBlockhashLifetime` that can be used\n * // with the RPC.\n * const { blockhash } = transaction.lifetimeConstraint;\n * const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();\n * } catch (e) {\n * // `transaction` turned out not to have a blockhash-based lifetime\n * }\n * ```\n */\nexport function assertIsTransactionWithBlockhashLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): asserts transaction is Transaction & TransactionWithBlockhashLifetime {\n if (!isTransactionWithBlockhashLifetime(transaction)) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME);\n }\n}\n\n/**\n * A type guard that returns `true` if the transaction conforms to the\n * {@link TransactionWithDurableNonceLifetime} type, and refines its type for use in your\n * program.\n *\n * @example\n * ```ts\n * import { isTransactionWithDurableNonceLifetime } from '@solana/transactions';\n * import { fetchNonce } from \"@solana-program/system\";\n *\n * if (isTransactionWithDurableNonceLifetime(transaction)) {\n * // At this point, `transaction` has been refined to a\n * // `TransactionWithDurableNonceLifetime`.\n * const { nonce, nonceAccountAddress } = transaction.lifetimeConstraint;\n * const { data: { blockhash: actualNonce } } = await fetchNonce(nonceAccountAddress);\n * setNonceIsValid(nonce === actualNonce);\n * } else {\n * setError(\n * `${getSignatureFromTransaction(transaction)} does not have a nonce-based lifetime`,\n * );\n * }\n * ```\n */\nexport function isTransactionWithDurableNonceLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): transaction is Transaction & TransactionWithDurableNonceLifetime {\n return (\n 'lifetimeConstraint' in transaction &&\n 'nonce' in transaction.lifetimeConstraint &&\n typeof transaction.lifetimeConstraint.nonce === 'string' &&\n typeof transaction.lifetimeConstraint.nonceAccountAddress === 'string' &&\n isAddress(transaction.lifetimeConstraint.nonceAccountAddress)\n );\n}\n\n/**\n * From time to time you might acquire a transaction, that you expect to have a\n * nonce-based lifetime, from for example a wallet. Use this function to assert\n * that such a transaction actually has a nonce-based lifetime.\n *\n * @example\n * ```ts\n * import { assertIsTransactionWithDurableNonceLifetime } from '@solana/transactions';\n *\n * try {\n * // If this type assertion function doesn't throw, then\n * // Typescript will upcast `transaction` to `TransactionWithDurableNonceLifetime`.\n * assertIsTransactionWithDurableNonceLifetime(transaction);\n * // At this point, `transaction` is a `TransactionWithDurableNonceLifetime` that can be used\n * // with the RPC.\n * const { nonce, nonceAccountAddress } = transaction.lifetimeConstraint;\n * const { data: { blockhash: actualNonce } } = await fetchNonce(nonceAccountAddress);\n * } catch (e) {\n * // `transaction` turned out not to have a nonce-based lifetime\n * }\n * ```\n */\nexport function assertIsTransactionWithDurableNonceLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): asserts transaction is Transaction & TransactionWithDurableNonceLifetime {\n if (!isTransactionWithDurableNonceLifetime(transaction)) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);\n }\n}\n","import {\n compileTransactionMessage,\n getCompiledTransactionMessageEncoder,\n isTransactionMessageWithBlockhashLifetime,\n isTransactionMessageWithDurableNonceLifetime,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n} from '@solana/transaction-messages';\n\nimport type { TransactionWithLifetime } from './lifetime';\nimport type { SignaturesMap, TransactionFromTransactionMessage, TransactionMessageBytes } from './transaction';\n\n/**\n * Returns a {@link Transaction} object for a given {@link TransactionMessage}.\n *\n * This includes the compiled bytes of the transaction message, and a map of signatures. This map\n * will have a key for each address that is required to sign the transaction. The transaction will\n * not yet have signatures for any of these addresses.\n *\n * Whether a transaction message is ready to be compiled or not is enforced for you at the type\n * level. In order to be signable, a transaction message must:\n *\n * - have a version and a list of zero or more instructions (ie. conform to\n * {@link TransactionMessage})\n * - have a fee payer set (ie. conform to {@link TransactionMessageWithFeePayer})\n * - have a lifetime specified (ie. conform to {@link TransactionMessageWithBlockhashLifetime} or\n * {@link TransactionMessageWithDurableNonceLifetime})\n */\nexport function compileTransaction<TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer>(\n transactionMessage: TTransactionMessage,\n): Readonly<TransactionFromTransactionMessage<TTransactionMessage>> {\n type ReturnType = Readonly<TransactionFromTransactionMessage<TTransactionMessage>>;\n\n const compiledMessage = compileTransactionMessage(transactionMessage);\n const messageBytes = getCompiledTransactionMessageEncoder().encode(compiledMessage) as TransactionMessageBytes;\n\n const transactionSigners = compiledMessage.staticAccounts.slice(0, compiledMessage.header.numSignerAccounts);\n const signatures: SignaturesMap = {};\n for (const signerAddress of transactionSigners) {\n signatures[signerAddress] = null;\n }\n\n let lifetimeConstraint: TransactionWithLifetime['lifetimeConstraint'] | undefined;\n if (isTransactionMessageWithBlockhashLifetime(transactionMessage)) {\n lifetimeConstraint = {\n blockhash: transactionMessage.lifetimeConstraint.blockhash,\n lastValidBlockHeight: transactionMessage.lifetimeConstraint.lastValidBlockHeight,\n };\n } else if (isTransactionMessageWithDurableNonceLifetime(transactionMessage)) {\n lifetimeConstraint = {\n nonce: transactionMessage.lifetimeConstraint.nonce,\n nonceAccountAddress: transactionMessage.instructions[0].accounts[0].address,\n };\n }\n\n return Object.freeze({\n ...(lifetimeConstraint ? { lifetimeConstraint } : undefined),\n messageBytes: messageBytes,\n signatures: Object.freeze(signatures),\n }) as ReturnType;\n}\n","import { Address, getAddressFromPublicKey } from '@solana/addresses';\nimport { bytesEqual, Decoder } from '@solana/codecs-core';\nimport { getBase58Decoder } from '@solana/codecs-strings';\nimport {\n SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION,\n SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING,\n SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING,\n SolanaError,\n} from '@solana/errors';\nimport { Signature, SignatureBytes, signBytes } from '@solana/keys';\nimport { NominalType } from '@solana/nominal-types';\n\nimport { Transaction } from './transaction';\n\n/**\n * Represents a transaction that is signed by all of its required signers. Being fully signed is a\n * prerequisite of functions designed to land transactions on the network.\n */\nexport type FullySignedTransaction = NominalType<'transactionSignedness', 'fullySigned'>;\n\nlet base58Decoder: Decoder<string> | undefined;\n\n/**\n * Given a transaction signed by its fee payer, this method will return the {@link Signature} that\n * uniquely identifies it. This string can be used to look up transactions at a later date, for\n * example on a Solana block explorer.\n *\n * @example\n * ```ts\n * import { getSignatureFromTransaction } from '@solana/transactions';\n *\n * const signature = getSignatureFromTransaction(tx);\n * console.debug(`Inspect this transaction at https://explorer.solana.com/tx/${signature}`);\n * ```\n */\nexport function getSignatureFromTransaction(transaction: Transaction): Signature {\n if (!base58Decoder) base58Decoder = getBase58Decoder();\n\n // We have ordered signatures from the compiled message accounts\n // first signature is the fee payer\n const signatureBytes = Object.values(transaction.signatures)[0];\n if (!signatureBytes) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING);\n }\n const transactionSignature = base58Decoder.decode(signatureBytes);\n return transactionSignature as Signature;\n}\n\n/**\n * Given an array of `CryptoKey` objects which are private keys pertaining to addresses that are\n * required to sign a transaction, this method will return a new signed transaction of type\n * {@link Transaction}.\n *\n * Though the resulting transaction might have every signature it needs to land on the network, this\n * function will not assert that it does. A partially signed transaction cannot be landed on the\n * network, but can be serialized and deserialized.\n *\n * @example\n * ```ts\n * import { generateKeyPair } from '@solana/keys';\n * import { partiallySignTransaction } from '@solana/transactions';\n *\n * const partiallySignedTransaction = await partiallySignTransaction([myPrivateKey], tx);\n * ```\n *\n * @see {@link signTransaction} if you want to assert that the transaction has all of its required\n * signatures after signing.\n */\nexport async function partiallySignTransaction<TTransaction extends Transaction>(\n keyPairs: CryptoKeyPair[],\n transaction: TTransaction,\n): Promise<TTransaction> {\n let newSignatures: Record<Address, SignatureBytes> | undefined;\n let unexpectedSigners: Set<Address> | undefined;\n\n await Promise.all(\n keyPairs.map(async keyPair => {\n const address = await getAddressFromPublicKey(keyPair.publicKey);\n const existingSignature = transaction.signatures[address];\n\n // Check if the address is expected to sign the transaction\n if (existingSignature === undefined) {\n // address is not an expected signer for this transaction\n unexpectedSigners ||= new Set();\n unexpectedSigners.add(address);\n return;\n }\n\n // Return if there are any unexpected signers already since we won't be using signatures\n if (unexpectedSigners) {\n return;\n }\n\n const newSignature = await signBytes(keyPair.privateKey, transaction.messageBytes);\n\n if (existingSignature !== null && bytesEqual(newSignature, existingSignature)) {\n // already have the same signature set\n return;\n }\n\n newSignatures ||= {};\n newSignatures[address] = newSignature;\n }),\n );\n\n if (unexpectedSigners && unexpectedSigners.size > 0) {\n const expectedSigners = Object.keys(transaction.signatures);\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION, {\n expectedAddresses: expectedSigners,\n unexpectedAddresses: [...unexpectedSigners],\n });\n }\n\n if (!newSignatures) {\n return transaction;\n }\n\n return Object.freeze({\n ...transaction,\n signatures: Object.freeze({\n ...transaction.signatures,\n ...newSignatures,\n }),\n });\n}\n\n/**\n * Given an array of `CryptoKey` objects which are private keys pertaining to addresses that are\n * required to sign a transaction, this method will return a new signed transaction of type\n * {@link FullySignedTransaction}.\n *\n * This function will throw unless the resulting transaction is fully signed.\n *\n * @example\n * ```ts\n * import { generateKeyPair } from '@solana/keys';\n * import { signTransaction } from '@solana/transactions';\n *\n * const signedTransaction = await signTransaction([myPrivateKey], tx);\n * ```\n *\n * @see {@link partiallySignTransaction} if you want to sign the transaction without asserting that\n * the resulting transaction is fully signed.\n */\nexport async function signTransaction<TTransaction extends Transaction>(\n keyPairs: CryptoKeyPair[],\n transaction: TTransaction,\n): Promise<FullySignedTransaction & TTransaction> {\n const out = await partiallySignTransaction(keyPairs, transaction);\n assertIsFullySignedTransaction(out);\n Object.freeze(out);\n return out;\n}\n\n/**\n * Checks whether a given {@link Transaction} is fully signed.\n *\n * @example\n * ```ts\n * import { isFullySignedTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * if (isFullySignedTransaction(transaction)) {\n * // At this point we know that the transaction is signed and can be sent to the network.\n * }\n * ```\n */\nexport function isFullySignedTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): transaction is FullySignedTransaction & TTransaction {\n return Object.entries(transaction.signatures).every(([_, signatureBytes]) => !!signatureBytes);\n}\n\n/**\n * From time to time you might acquire a {@link Transaction}, that you expect to be fully signed,\n * from an untrusted network API or user input. Use this function to assert that such a transaction\n * is fully signed.\n *\n * @example\n * ```ts\n * import { assertIsFullySignedTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * try {\n * // If this type assertion function doesn't throw, then Typescript will upcast `transaction`\n * // to `FullySignedTransaction`.\n * assertIsFullySignedTransaction(transaction);\n * // At this point we know that the transaction is signed and can be sent to the network.\n * await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });\n * } catch(e) {\n * if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING)) {\n * setError(`Missing signatures for ${e.context.addresses.join(', ')}`);\n * }\n * throw;\n * }\n * ```\n */\nexport function assertIsFullySignedTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): asserts transaction is FullySignedTransaction & TTransaction {\n const missingSigs: Address[] = [];\n Object.entries(transaction.signatures).forEach(([address, signatureBytes]) => {\n if (!signatureBytes) {\n missingSigs.push(address as Address);\n }\n });\n\n if (missingSigs.length > 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING, {\n addresses: missingSigs,\n });\n }\n}\n","import { getBase64Decoder } from '@solana/codecs-strings';\nimport { Brand, EncodedString } from '@solana/nominal-types';\n\nimport { getTransactionEncoder } from './codecs';\nimport { Transaction } from './transaction';\n\n/** Represents the wire format of a transaction as a base64-encoded string. */\nexport type Base64EncodedWireTransaction = Brand<EncodedString<string, 'base64'>, 'Base64EncodedWireTransaction'>;\n\n/**\n * Given a signed transaction, this method returns the transaction as a string that conforms to the\n * {@link Base64EncodedWireTransaction} type.\n *\n * @example\n * ```ts\n * import { getBase64EncodedWireTransaction, signTransaction } from '@solana/transactions';\n *\n * const serializedTransaction = getBase64EncodedWireTransaction(signedTransaction);\n * const signature = await rpc.sendTransaction(serializedTransaction, { encoding: 'base64' }).send();\n * ```\n */\nexport function getBase64EncodedWireTransaction(transaction: Transaction): Base64EncodedWireTransaction {\n const wireTransactionBytes = getTransactionEncoder().encode(transaction);\n return getBase64Decoder().decode(wireTransactionBytes) as Base64EncodedWireTransaction;\n}\n","import { SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, SolanaError } from '@solana/errors';\nimport type { NominalType } from '@solana/nominal-types';\nimport type { TransactionMessage, TransactionMessageWithinSizeLimit } from '@solana/transaction-messages';\n\nimport { getTransactionEncoder } from './codecs';\nimport { Transaction } from './transaction';\n\n/**\n * The maximum size of a transaction packet in bytes.\n */\nexport const TRANSACTION_PACKET_SIZE = 1280;\n\n/**\n * The size of the transaction packet header in bytes.\n * This includes the IPv6 header and the fragment header.\n */\nexport const TRANSACTION_PACKET_HEADER =\n 40 /* 40 bytes is the size of the IPv6 header. */ + 8; /* 8 bytes is the size of the fragment header. */\n\n/**\n * The maximum size of a transaction in bytes.\n *\n * Note that this excludes the transaction packet header.\n * In other words, this is how much content we can fit in a transaction packet.\n */\nexport const TRANSACTION_SIZE_LIMIT = TRANSACTION_PACKET_SIZE - TRANSACTION_PACKET_HEADER;\n\n/**\n * Gets the size of a given transaction in bytes.\n *\n * @example\n * ```ts\n * const transactionSize = getTransactionSize(transaction);\n * ```\n */\nexport function getTransactionSize(transaction: Transaction): number {\n return getTransactionEncoder().getSizeFromValue(transaction);\n}\n\n/**\n * A type guard that checks if a transaction is within the size limit.\n */\nexport type TransactionWithinSizeLimit = NominalType<'transactionSize', 'withinLimit'>;\n\n/**\n * Helper type that adds the `TransactionWithinSizeLimit` flag to\n * a transaction if and only if the provided transaction message\n * is also within the size limit.\n */\nexport type SetTransactionWithinSizeLimitFromTransactionMessage<\n TTransaction extends Transaction,\n TTransactionMessage extends TransactionMessage,\n> = TTransactionMessage extends TransactionMessageWithinSizeLimit\n ? TransactionWithinSizeLimit & TTransaction\n : TTransaction;\n\n/**\n * Checks if a transaction is within the size limit.\n *\n * @typeParam TTransaction - The type of the given transaction.\n *\n * @example\n * ```ts\n * if (isTransactionWithinSizeLimit(transaction)) {\n * transaction satisfies TransactionWithinSizeLimit;\n * }\n * ```\n */\nexport function isTransactionWithinSizeLimit<TTransaction extends Transaction>(\n transaction: TTransaction,\n): transaction is TransactionWithinSizeLimit & TTransaction {\n return getTransactionSize(transaction) <= TRANSACTION_SIZE_LIMIT;\n}\n\n/**\n * Asserts that a given transaction is within the size limit.\n *\n * Throws a {@link SolanaError} of code {@link SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT}\n * if the transaction exceeds the size limit.\n *\n * @typeParam TTransaction - The type of the given transaction.\n *\n * @example\n * ```ts\n * assertIsTransactionWithinSizeLimit(transaction);\n * transaction satisfies TransactionWithinSizeLimit;\n * ```\n */\nexport function assertIsTransactionWithinSizeLimit<TTransaction extends Transaction>(\n transaction: TTransaction,\n): asserts transaction is TransactionWithinSizeLimit & TTransaction {\n const transactionSize = getTransactionSize(transaction);\n if (transactionSize > TRANSACTION_SIZE_LIMIT) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, {\n transactionSize,\n transactionSizeLimit: TRANSACTION_SIZE_LIMIT,\n });\n }\n}\n","import { assertIsFullySignedTransaction, FullySignedTransaction, isFullySignedTransaction } from './signatures';\nimport { Transaction } from './transaction';\nimport {\n assertIsTransactionWithinSizeLimit,\n isTransactionWithinSizeLimit,\n TransactionWithinSizeLimit,\n} from './transaction-size';\n\n/**\n * Helper type that includes all transaction types required\n * for the transaction to be sent to the network.\n *\n * @see {@link isSendableTransaction}\n * @see {@link assertIsSendableTransaction}\n */\nexport type SendableTransaction = FullySignedTransaction & TransactionWithinSizeLimit;\n\n/**\n * Checks if a transaction has all the required\n * conditions to be sent to the network.\n *\n * @example\n * ```ts\n * import { isSendableTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * if (isSendableTransaction(transaction)) {\n * // At this point we know that the transaction can be sent to the network.\n * }\n * ```\n *\n * @see {@link assertIsSendableTransaction}\n */\nexport function isSendableTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): transaction is SendableTransaction & TTransaction {\n return isFullySignedTransaction(transaction) && isTransactionWithinSizeLimit(transaction);\n}\n\n/**\n * Asserts that a given transaction has all the\n * required conditions to be sent to the network.\n *\n * From time to time you might acquire a {@link Transaction}\n * from an untrusted network API or user input and you are not sure\n * that it has all the required conditions to be sent to the network\n * — such as being fully signed and within the size limit.\n * This function can be used to assert that such a transaction\n * is in fact sendable.\n *\n * @example\n * ```ts\n * import { assertIsSendableTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * try {\n * // If this type assertion function doesn't throw, then Typescript will upcast `transaction`\n * // to `SendableTransaction`.\n * assertIsSendableTransaction(transaction);\n * // At this point we know that the transaction can be sent to the network.\n * await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });\n * } catch(e) {\n * if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING)) {\n * setError(`Missing signatures for ${e.context.addresses.join(', ')}`);\n * } else if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT)) {\n * setError(`Transaction exceeds size limit of ${e.context.transactionSizeLimit} bytes`);\n * }\n * throw;\n * }\n * ```\n */\nexport function assertIsSendableTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): asserts transaction is SendableTransaction & TTransaction {\n assertIsFullySignedTransaction(transaction);\n assertIsTransactionWithinSizeLimit(transaction);\n}\n","import { SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, SolanaError } from '@solana/errors';\nimport type {\n TransactionMessage,\n TransactionMessageWithFeePayer,\n TransactionMessageWithinSizeLimit,\n} from '@solana/transaction-messages';\n\nimport { compileTransaction } from './compile-transaction';\nimport { getTransactionSize, TRANSACTION_SIZE_LIMIT } from './transaction-size';\n\n/**\n * Gets the compiled transaction size of a given transaction message in bytes.\n *\n * @example\n * ```ts\n * const transactionSize = getTransactionMessageSize(transactionMessage);\n * ```\n */\nexport function getTransactionMessageSize(\n transactionMessage: TransactionMessage & TransactionMessageWithFeePayer,\n): number {\n return getTransactionSize(compileTransaction(transactionMessage));\n}\n\n/**\n * Checks if a transaction message is within the size limit\n * when compiled into a transaction.\n *\n * @typeParam TTransactionMessage - The type of the given transaction message.\n *\n * @example\n * ```ts\n * if (isTransactionMessageWithinSizeLimit(transactionMessage)) {\n * transactionMessage satisfies TransactionMessageWithinSizeLimit;\n * }\n * ```\n */\nexport function isTransactionMessageWithinSizeLimit<\n TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer,\n>(\n transactionMessage: TTransactionMessage,\n): transactionMessage is TransactionMessageWithinSizeLimit & TTransactionMessage {\n return getTransactionMessageSize(transactionMessage) <= TRANSACTION_SIZE_LIMIT;\n}\n\n/**\n * Asserts that a given transaction message is within the size limit\n * when compiled into a transaction.\n *\n * Throws a {@link SolanaError} of code {@link SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT}\n * if the transaction message exceeds the size limit.\n *\n * @typeParam TTransactionMessage - The type of the given transaction message.\n *\n * @example\n * ```ts\n * assertIsTransactionMessageWithinSizeLimit(transactionMessage);\n * transactionMessage satisfies TransactionMessageWithinSizeLimit;\n * ```\n */\nexport function assertIsTransactionMessageWithinSizeLimit<\n TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer,\n>(\n transactionMessage: TTransactionMessage,\n): asserts transactionMessage is TransactionMessageWithinSizeLimit & TTransactionMessage {\n const transactionSize = getTransactionMessageSize(transactionMessage);\n if (transactionSize > TRANSACTION_SIZE_LIMIT) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, {\n transactionSize,\n transactionSizeLimit: TRANSACTION_SIZE_LIMIT,\n });\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/codecs/signatures-encoder.ts","../src/codecs/transaction-codec.ts","../src/lifetime.ts","../src/compile-transaction.ts","../src/signatures.ts","../src/wire-transaction.ts","../src/transaction-size.ts","../src/sendable-transaction.ts","../src/transaction-message-size.ts"],"names":["SolanaError","SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES","transformEncoder","getArrayEncoder","fixEncoderSize","getBytesEncoder","getShortU16Encoder","SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES","getTransactionVersionDecoder","SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES","SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST","SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED","getPredicateEncoder","getStructEncoder","SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES","createEncoder","getPredicateDecoder","transformDecoder","getStructDecoder","getArrayDecoder","fixDecoderSize","getBytesDecoder","getShortU16Decoder","createDecoder","SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES","combineCodec","getTupleDecoder","padRightDecoder","getU8Decoder","getAddressDecoder","SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH","SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE","SOLANA_ERROR__TRANSACTION__INVALID_NONCE_ACCOUNT_INDEX","isBlockhash","SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME","isAddress","SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME","compileTransactionMessage","getCompiledTransactionMessageEncoder","isTransactionMessageWithBlockhashLifetime","isTransactionMessageWithDurableNonceLifetime","getBase58Decoder","SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING","getAddressFromPublicKey","signBytes","bytesEqual","SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION","SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING","getBase64Decoder","SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,sBAAsB,aAAA,EAAgD;AAC3E,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,aAAa,CAAA;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,EAAA,MAAM,eAAA,GAAkB,mBAAmB,WAAW,CAAA;AACtD,EAAA,IAAI,kBAAkB,sBAAA,EAAwB;AAC1C,IAAA,MAAM,IAAIhD,mBAAYiD,oDAAA,EAA+C;AAAA,MACjE,eAAA;AAAA,MACA,oBAAA,EAAsB;AAAA,KACzB,CAAA;AAAA,EACL;AACJ;;;ACjEO,SAAS,sBACZ,WAAA,EACiD;AACjD,EAAA,OAAO,wBAAA,CAAyB,WAAW,CAAA,IAAK,4BAAA,CAA6B,WAAW,CAAA;AAC5F;AAkCO,SAAS,4BACZ,WAAA,EACyD;AACzD,EAAA,8BAAA,CAA+B,WAAW,CAAA;AAC1C,EAAA,kCAAA,CAAmC,WAAW,CAAA;AAClD;AC1DO,SAAS,0BACZ,kBAAA,EACM;AACN,EAAA,OAAO,kBAAA,CAAmB,kBAAA,CAAmB,kBAAkB,CAAC,CAAA;AACpE;AAeO,SAAS,oCAGZ,kBAAA,EAC6E;AAC7E,EAAA,OAAO,yBAAA,CAA0B,kBAAkB,CAAA,IAAK,sBAAA;AAC5D;AAiBO,SAAS,0CAGZ,kBAAA,EACqF;AACrF,EAAA,MAAM,eAAA,GAAkB,0BAA0B,kBAAkB,CAAA;AACpE,EAAA,IAAI,kBAAkB,sBAAA,EAAwB;AAC1C,IAAA,MAAM,IAAIjD,mBAAYiD,oDAAAA,EAA+C;AAAA,MACjE,eAAA;AAAA,MACA,oBAAA,EAAsB;AAAA,KACzB,CAAA;AAAA,EACL;AACJ","file":"index.browser.cjs","sourcesContent":["import { FixedSizeEncoder, fixEncoderSize, transformEncoder, VariableSizeEncoder } from '@solana/codecs-core';\nimport { getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';\nimport { getShortU16Encoder } from '@solana/codecs-numbers';\nimport { SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES, SolanaError } from '@solana/errors';\nimport { SignatureBytes } from '@solana/keys';\n\nimport { SignaturesMap } from '../transaction';\n\nfunction getSignaturesToEncode(signaturesMap: SignaturesMap): SignatureBytes[] {\n const signatures = Object.values(signaturesMap);\n if (signatures.length === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES);\n }\n\n return signatures.map(signature => {\n if (!signature) {\n return new Uint8Array(64).fill(0) as SignatureBytes;\n }\n return signature;\n });\n}\n\n/**\n * Signatures encoder used for legacy and v0 transactions, which encode signatures\n * as an array with a u16-short size prefix\n *\n * @internal\n */\nexport function getSignaturesEncoderWithSizePrefix(): VariableSizeEncoder<SignaturesMap> {\n return transformEncoder(\n getArrayEncoder(fixEncoderSize(getBytesEncoder(), 64), { size: getShortU16Encoder() }),\n getSignaturesToEncode,\n );\n}\n\n/**\n * Signatures encoder used for v1 transactions, which encode signatures\n * as a known-size array\n *\n * @param size Known number of signatures for the transaction\n *\n * @internal\n */\nexport function getSignaturesEncoderWithLength(size: number): FixedSizeEncoder<SignaturesMap> {\n return transformEncoder(\n getArrayEncoder(fixEncoderSize(getBytesEncoder(), 64), { description: 'signatures', size }),\n getSignaturesToEncode,\n );\n}\n","import { Address, getAddressDecoder } from '@solana/addresses';\nimport {\n combineCodec,\n createDecoder,\n createEncoder,\n fixDecoderSize,\n padRightDecoder,\n ReadonlyUint8Array,\n transformDecoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\nimport {\n getArrayDecoder,\n getBytesDecoder,\n getBytesEncoder,\n getPredicateDecoder,\n getPredicateEncoder,\n getStructDecoder,\n getStructEncoder,\n getTupleDecoder,\n} from '@solana/codecs-data-structures';\nimport { getShortU16Decoder, getU8Decoder } from '@solana/codecs-numbers';\nimport {\n SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES,\n SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES,\n SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES,\n SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH,\n SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES,\n SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED,\n SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST,\n SolanaError,\n} from '@solana/errors';\nimport { SignatureBytes } from '@solana/keys';\nimport { getTransactionVersionDecoder } from '@solana/transaction-messages';\n\nimport { SignaturesMap, Transaction, TransactionMessageBytes } from '../transaction';\nimport { getSignaturesEncoderWithLength, getSignaturesEncoderWithSizePrefix } from './signatures-encoder';\n\ntype EnvelopeShape = 'messageFirst' | 'signaturesFirst';\n\nconst SIGNATURE_COUNT_FLAG_MASK = 0b10000000;\nconst VERSION_FLAG_MASK = 0b01111111;\n\nfunction getEnvelopeShapeFromMessageBytes(messageBytes: ReadonlyUint8Array): EnvelopeShape {\n if (messageBytes.length === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES);\n }\n\n const version = getTransactionVersionDecoder().decode(messageBytes);\n return version === 1 ? 'messageFirst' : 'signaturesFirst';\n}\n\nfunction getEnvelopeShapeFromTransactionBytes(transactionBytes: ReadonlyUint8Array): EnvelopeShape {\n if (transactionBytes.length === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES);\n }\n const firstByte = transactionBytes[0];\n if ((firstByte & SIGNATURE_COUNT_FLAG_MASK) === 0) {\n // First byte is a signature count, so signatures come first\n return 'signaturesFirst';\n }\n // If the first byte is not a signature count, then we must have message bytes first,\n // and the first byte of the message must be the version byte\n const version = firstByte & VERSION_FLAG_MASK;\n if (version === 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST, {\n firstByte,\n transactionBytes,\n });\n }\n if (version === 1) {\n return 'messageFirst';\n }\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, {\n unsupportedVersion: version,\n });\n}\n\n/**\n * Returns an encoder that you can use to encode a {@link Transaction} to a byte array in a wire\n * format appropriate for sending to the Solana network for execution.\n */\nexport function getTransactionEncoder(): VariableSizeEncoder<Transaction> {\n return getPredicateEncoder(\n (transaction: Transaction) => getEnvelopeShapeFromMessageBytes(transaction.messageBytes) === 'signaturesFirst',\n getTransactionEncoderWithSignaturesFirst(),\n getTransactionEncoderWithMessageFirst(),\n );\n}\n\nfunction getTransactionEncoderWithSignaturesFirst(): VariableSizeEncoder<Transaction> {\n return getStructEncoder([\n ['signatures', getSignaturesEncoderWithSizePrefix()],\n ['messageBytes', getBytesEncoder()],\n ]);\n}\n\nfunction getSignatureCountForVersionedOrThrow(messageBytes: ReadonlyUint8Array, offset: number): number {\n if (messageBytes.length < offset + 2) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES, {\n messageBytes,\n });\n }\n return messageBytes[offset + 1]; // second byte\n}\n\nfunction getTransactionEncoderWithMessageFirst(): VariableSizeEncoder<Transaction> {\n const bytesEncoder = getBytesEncoder();\n\n return createEncoder({\n getSizeFromValue: (transaction: Transaction) => {\n const signatureCount = getSignatureCountForVersionedOrThrow(transaction.messageBytes, 0);\n return transaction.messageBytes.length + signatureCount * 64;\n },\n write: (transaction: Transaction, bytes: Uint8Array, offset: number) => {\n // 1. Encode messageBytes first\n offset = bytesEncoder.write(transaction.messageBytes, bytes, offset);\n\n // 2. Extract signature count from second byte\n const signatureCount = getSignatureCountForVersionedOrThrow(transaction.messageBytes, 0);\n\n // 3. Encode signatures with the extracted length\n const signaturesEncoder = getSignaturesEncoderWithLength(signatureCount);\n offset = signaturesEncoder.write(transaction.signatures, bytes, offset);\n\n return offset;\n },\n });\n}\n\n/**\n * Returns a decoder that you can use to convert a byte array in the Solana transaction wire format\n * to a {@link Transaction} object.\n *\n * @example\n * ```ts\n * import { getTransactionDecoder } from '@solana/transactions';\n *\n * const transactionDecoder = getTransactionDecoder();\n * const transaction = transactionDecoder.decode(wireTransactionBytes);\n * for (const [address, signature] in Object.entries(transaction.signatures)) {\n * console.log(`Signature by ${address}`, signature);\n * }\n * ```\n */\n\nexport function getTransactionDecoder(): VariableSizeDecoder<Transaction> {\n return getPredicateDecoder(\n (transactionBytes: ReadonlyUint8Array) =>\n getEnvelopeShapeFromTransactionBytes(transactionBytes) === 'signaturesFirst',\n getTransactionDecoderWithSignaturesFirst(),\n getTransactionDecoderWithMessageFirst(),\n );\n}\n\nfunction getTransactionDecoderWithSignaturesFirst(): VariableSizeDecoder<Transaction> {\n return transformDecoder(\n getStructDecoder([\n ['signatures', getArrayDecoder(fixDecoderSize(getBytesDecoder(), 64), { size: getShortU16Decoder() })],\n ['messageBytes', getBytesDecoder()],\n ]),\n decodePartiallyDecodedLegacyOrV0Transaction,\n );\n}\n\nfunction getTransactionDecoderWithMessageFirst(): VariableSizeDecoder<Transaction> {\n return transformDecoder(\n getPartiallyDecodedTransactionDecoderWithMessageFirst(),\n decodePartiallyDecodedV1Transaction,\n );\n}\n\nfunction getPartiallyDecodedTransactionDecoderWithMessageFirst(): VariableSizeDecoder<PartiallyDecodedTransaction> {\n return createDecoder({\n read(bytes, offset) {\n // 1. Message comes first, so read signature count from message bytes\n const signatureCount = getSignatureCountForVersionedOrThrow(bytes, offset);\n const signatureByteLength = signatureCount * 64;\n\n // 2. Read the message, which is all bytes except the last {signatureByteLength} bytes\n // Note that this is based on an assumption that we want to read the rest of the input bytes\n // as a transaction, which allows us to avoid decoding the entire message bytes to read each field\n // This is the same logic as using `getBytesDecoder` to read the message bytes when they are trailing\n const messageBytesLength = bytes.length - offset - signatureByteLength;\n if (messageBytesLength < 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES, {\n numExpectedSignatures: signatureCount,\n transactionBytes: bytes.subarray(offset),\n transactionBytesLength: bytes.length - offset,\n });\n }\n const messageBytes = bytes.subarray(offset, offset + messageBytesLength);\n\n // 3. Read the signature bytes, which are the remaining bytes\n const [signatures, finalOffset] = getArrayDecoder(fixDecoderSize(getBytesDecoder(), 64), {\n size: signatureCount,\n }).read(bytes, offset + messageBytesLength);\n\n return [\n {\n messageBytes: messageBytes as unknown as TransactionMessageBytes,\n signatures,\n },\n finalOffset,\n ];\n },\n });\n}\n\n/**\n * Returns a codec that you can use to encode from or decode to a {@link Transaction}\n *\n * @see {@link getTransactionDecoder}\n * @see {@link getTransactionEncoder}\n */\nexport function getTransactionCodec(): VariableSizeCodec<Transaction> {\n return combineCodec(getTransactionEncoder(), getTransactionDecoder());\n}\n\ntype PartiallyDecodedTransaction = {\n messageBytes: ReadonlyUint8Array;\n signatures: ReadonlyUint8Array[];\n};\n\nfunction decodePartiallyDecodedLegacyOrV0Transaction(transaction: PartiallyDecodedTransaction): Transaction {\n const { messageBytes, signatures } = transaction;\n\n /*\n Relevant message structure is at the start:\n - transaction version (0 bytes for legacy transactions, 1 byte for versioned transactions)\n - `numRequiredSignatures` (1 byte, we verify this matches the length of signatures)\n - `numReadOnlySignedAccounts` (1 byte, not used here)\n - `numReadOnlyUnsignedAccounts` (1 byte, not used here)\n - static addresses, with signers first. This is an array of addresses, prefixed with a short-u16 length\n */\n\n const signerAddressesDecoder = getTupleDecoder([\n // read transaction version\n getTransactionVersionDecoder(),\n // read first byte of header, `numSignerAccounts`\n // padRight to skip the next 2 bytes, `numReadOnlySignedAccounts` and `numReadOnlyUnsignedAccounts` which we don't need\n padRightDecoder(getU8Decoder(), 2),\n // read static addresses\n getArrayDecoder(getAddressDecoder(), { size: getShortU16Decoder() }),\n ]);\n const [_txVersion, numRequiredSignatures, staticAddresses] = signerAddressesDecoder.decode(messageBytes);\n\n const signerAddresses = staticAddresses.slice(0, numRequiredSignatures);\n\n // signer addresses and signatures must be the same length\n // we encode an all-zero signature when the signature is missing\n if (signerAddresses.length !== signatures.length) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH, {\n numRequiredSignatures,\n signaturesLength: signatures.length,\n signerAddresses,\n });\n }\n\n // combine the signer addresses + signatures into the signatures map\n const signaturesMap = makeSignaturesMap(signerAddresses, signatures);\n\n return {\n messageBytes: messageBytes as TransactionMessageBytes,\n signatures: Object.freeze(signaturesMap),\n };\n}\n\nfunction decodePartiallyDecodedV1Transaction(transaction: PartiallyDecodedTransaction): Transaction {\n const { messageBytes, signatures } = transaction;\n\n /*\n Relevant message structure is at the start:\n - transaction version (1 byte for versioned transactions)\n - `numRequiredSignatures` (1 byte, we verify this matches the length of signatures)\n - `numReadOnlySignedAccounts` (1 byte, not used here)\n - `numReadOnlyUnsignedAccounts` (1 byte, not used here)\n - transaction config mask (4 bytes, not used here)\n - lifetime specifier (4 bytes, not used here)\n - num instructions (1 byte, not used here)\n - num addresses (1 byte, not used here because we only need to read `numRequiredSignatures` addresses)\n - static addresses, with signers first. This is an array of addresses, with no prefix\n */\n\n const numRequiredSignatures = messageBytes[1]; // second byte\n\n /**\n * Static addresses start after:\n * - 1 byte transaction version\n * - 3 bytes for the header (`numRequiredSignatures`, `numReadOnlySignedAccounts`, and `numReadOnlyUnsignedAccounts`)\n * - 4 bytes for transaction config mask\n * - 4 bytes for lifetime specifier\n * - 1 byte for num instructions\n * - 1 byte for num addresses\n */\n const staticAddressOffset = 1 + 3 + 4 + 4 + 1 + 1;\n\n const signerAddresses = getArrayDecoder(getAddressDecoder(), { size: numRequiredSignatures }).decode(\n messageBytes,\n staticAddressOffset,\n );\n\n if (signerAddresses.length !== signatures.length) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH, {\n numRequiredSignatures,\n signaturesLength: signatures.length,\n signerAddresses,\n });\n }\n\n const signaturesMap = makeSignaturesMap(signerAddresses, signatures);\n\n return {\n messageBytes: messageBytes as TransactionMessageBytes,\n signatures: signaturesMap,\n };\n}\n\nfunction makeSignaturesMap(signerAddresses: Address[], signatures: ReadonlyUint8Array[]): SignaturesMap {\n // combine the signer addresses + signatures into the signatures map\n const signaturesMap: SignaturesMap = {};\n signerAddresses.forEach((address, index) => {\n const signatureForAddress = signatures[index];\n if (signatureForAddress.every(b => b === 0)) {\n signaturesMap[address] = null;\n } else {\n signaturesMap[address] = signatureForAddress as SignatureBytes;\n }\n });\n\n return Object.freeze(signaturesMap);\n}\n","import { type Address, isAddress } from '@solana/addresses';\nimport { ReadonlyUint8Array } from '@solana/codecs-core';\nimport {\n SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME,\n SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME,\n SOLANA_ERROR__TRANSACTION__INVALID_NONCE_ACCOUNT_INDEX,\n SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE,\n SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED,\n SolanaError,\n} from '@solana/errors';\nimport { type Blockhash, isBlockhash, type Slot } from '@solana/rpc-types';\nimport type {\n CompiledTransactionMessage,\n CompiledTransactionMessageWithLifetime,\n LegacyCompiledTransactionMessage,\n Nonce,\n TransactionMessage,\n TransactionMessageWithBlockhashLifetime,\n TransactionMessageWithDurableNonceLifetime,\n V1CompiledTransactionMessage,\n} from '@solana/transaction-messages';\n\nimport type { Transaction } from './transaction';\n\n/**\n * A constraint which, when applied to a transaction, makes that transaction eligible to land on the\n * network. The transaction will continue to be eligible to land until the network considers the\n * `blockhash` to be expired.\n *\n * This can happen when the network proceeds past the `lastValidBlockHeight` for which the blockhash\n * is considered valid, or when the network switches to a fork where that blockhash is not present.\n */\nexport type TransactionBlockhashLifetime = {\n /**\n * A recent blockhash observed by the transaction proposer.\n *\n * The transaction will be considered eligible to land until the network determines this\n * blockhash to be too old, or has switched to a fork where it is not present.\n */\n blockhash: Blockhash;\n /**\n * This is the block height beyond which the network will consider the blockhash to be too old\n * to make a transaction eligible to land.\n */\n lastValidBlockHeight: Slot;\n};\n\n/**\n * A constraint which, when applied to a transaction, makes that transaction eligible to land on the\n * network.\n *\n * The transaction will continue to be eligible to land until the network considers the `nonce` to\n * have advanced. This can happen when the nonce account in which this nonce is found is destroyed,\n * or the nonce value within changes.\n */\nexport type TransactionDurableNonceLifetime = {\n /**\n * A value contained in the account with address `nonceAccountAddress` at the time the\n * transaction was prepared.\n *\n * The transaction will be considered eligible to land until the nonce account ceases to exist\n * or contain this value.\n */\n nonce: Nonce;\n /** The account that contains the `nonce` value */\n nonceAccountAddress: Address;\n};\n\n/**\n * A transaction whose ability to land on the network is determined by some evanescent criteria.\n *\n * This describes a window of time after which a transaction is constructed and before which it will\n * no longer be accepted by the network.\n *\n * No transaction can land on Solana without having a `lifetimeConstraint` set.\n */\nexport type TransactionWithLifetime = {\n readonly lifetimeConstraint: TransactionBlockhashLifetime | TransactionDurableNonceLifetime;\n};\n\n/**\n * A transaction whose lifetime is determined by the age of a blockhash observed on the network.\n *\n * The transaction will continue to be eligible to land until the network considers the `blockhash`\n * to be expired.\n */\nexport type TransactionWithBlockhashLifetime = {\n readonly lifetimeConstraint: TransactionBlockhashLifetime;\n};\n\n/**\n * A transaction whose lifetime is determined by a nonce.\n *\n * The transaction will continue to be eligible to land until the network considers the `nonce` to\n * have advanced. This can happen when the nonce account in which this nonce is found is destroyed,\n * or the nonce value within changes.\n */\nexport type TransactionWithDurableNonceLifetime = {\n readonly lifetimeConstraint: TransactionDurableNonceLifetime;\n};\n\n/**\n * Helper type that sets the lifetime constraint of a transaction to be the same as the\n * lifetime constraint of the provided transaction message.\n *\n * If the transaction message has no explicit lifetime constraint, neither will the transaction.\n */\nexport type SetTransactionLifetimeFromTransactionMessage<\n TTransaction extends Transaction,\n TTransactionMessage extends TransactionMessage,\n> = TTransactionMessage extends { lifetimeConstraint: unknown }\n ? TTransactionMessage['lifetimeConstraint'] extends TransactionMessageWithBlockhashLifetime['lifetimeConstraint']\n ? TransactionWithBlockhashLifetime & TTransaction\n : TTransactionMessage['lifetimeConstraint'] extends TransactionMessageWithDurableNonceLifetime['lifetimeConstraint']\n ? TransactionWithDurableNonceLifetime & TTransaction\n : TransactionWithLifetime & TTransaction\n : TTransaction;\n\nconst SYSTEM_PROGRAM_ADDRESS = '11111111111111111111111111111111' as Address;\n\nfunction compiledV1InstructionIsAdvanceNonceInstruction(\n instructionHeader: V1CompiledTransactionMessage['instructionHeaders'][number],\n instructionPayload: V1CompiledTransactionMessage['instructionPayloads'][number],\n staticAddresses: Address[],\n): instructionHeader is typeof instructionHeader & { programAccountIndex: number } {\n return (\n staticAddresses[instructionHeader.programAccountIndex] === SYSTEM_PROGRAM_ADDRESS &&\n // Test for `AdvanceNonceAccount` instruction data\n isAdvanceNonceAccountInstructionData(instructionPayload.instructionData) &&\n // Test for exactly 3 accounts\n instructionHeader.numInstructionAccounts === 3\n );\n}\n\nfunction compiledLegacyInstructionIsAdvanceNonceInstruction(\n instruction: LegacyCompiledTransactionMessage['instructions'][number],\n staticAddresses: Address[],\n): instruction is typeof instruction & { accountIndices: [number, number, number] } {\n return (\n staticAddresses[instruction.programAddressIndex] === SYSTEM_PROGRAM_ADDRESS &&\n // Test for `AdvanceNonceAccount` instruction data\n instruction.data != null &&\n isAdvanceNonceAccountInstructionData(instruction.data) &&\n // Test for exactly 3 accounts\n instruction.accountIndices?.length === 3\n );\n}\n\nfunction isAdvanceNonceAccountInstructionData(data: ReadonlyUint8Array): boolean {\n // AdvanceNonceAccount is the fifth instruction in the System Program (index 4)\n return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;\n}\n\n/**\n * Get the lifetime constraint for a transaction from a compiled transaction message that includes a lifetime token.\n * @param compiledTransactionMessage A compiled transaction message that includes a lifetime token\n * @returns A lifetime constraint for the transaction\n * Note that this is less precise than checking a decompiled instruction, as we can't inspect\n * the address or role of input accounts (which may be in lookup tables). However, this is\n * sufficient for all valid advance durable nonce instructions.\n * Note that the program address must not be in a lookup table, see [this answer on StackExchange](https://solana.stackexchange.com/a/16224/289)\n * @see {@link isAdvanceNonceAccountInstruction}\n * Note that this function is async to allow for future implementations that may fetch `lastValidBlockHeight` using an RPC\n */\n// eslint-disable-next-line @typescript-eslint/require-await\nexport async function getTransactionLifetimeConstraintFromCompiledTransactionMessage(\n compiledTransactionMessage: CompiledTransactionMessage & CompiledTransactionMessageWithLifetime,\n): Promise<TransactionBlockhashLifetime | TransactionDurableNonceLifetime> {\n // We need to check if the first instruction is an AdvanceNonceAccount instruction\n const { version } = compiledTransactionMessage;\n\n if (version === 'legacy' || version === 0) {\n const firstInstruction = compiledTransactionMessage.instructions[0];\n const { staticAccounts } = compiledTransactionMessage;\n\n if (firstInstruction && compiledLegacyInstructionIsAdvanceNonceInstruction(firstInstruction, staticAccounts)) {\n const nonceAccountAddress = staticAccounts[firstInstruction.accountIndices[0]];\n if (!nonceAccountAddress) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, {\n nonce: compiledTransactionMessage.lifetimeToken,\n });\n }\n return {\n nonce: compiledTransactionMessage.lifetimeToken as Nonce,\n nonceAccountAddress,\n };\n } else {\n return {\n blockhash: compiledTransactionMessage.lifetimeToken as Blockhash,\n // This is not known from the compiled message, so we set it to the maximum possible value\n lastValidBlockHeight: 0xffffffffffffffffn,\n };\n }\n }\n\n if (version === 1) {\n const firstInstructionHeader = compiledTransactionMessage.instructionHeaders[0];\n const firstInstructionPayload = compiledTransactionMessage.instructionPayloads[0];\n const { staticAccounts } = compiledTransactionMessage;\n\n if (\n firstInstructionHeader &&\n firstInstructionPayload &&\n compiledV1InstructionIsAdvanceNonceInstruction(\n firstInstructionHeader,\n firstInstructionPayload,\n staticAccounts,\n )\n ) {\n const nonceAccountAddress = staticAccounts[firstInstructionPayload.instructionAccountIndices[0]];\n if (!nonceAccountAddress) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__INVALID_NONCE_ACCOUNT_INDEX, {\n nonce: compiledTransactionMessage.lifetimeToken,\n nonceAccountIndex: firstInstructionPayload.instructionAccountIndices[0],\n numberOfStaticAccounts: staticAccounts.length,\n });\n }\n return {\n nonce: compiledTransactionMessage.lifetimeToken as Nonce,\n nonceAccountAddress,\n };\n } else {\n return {\n blockhash: compiledTransactionMessage.lifetimeToken as Blockhash,\n // This is not known from the compiled message, so we set it to the maximum possible value\n lastValidBlockHeight: 0xffffffffffffffffn,\n };\n }\n }\n\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, {\n unsupportedVersion: version,\n });\n}\n\n/**\n * A type guard that returns `true` if the transaction conforms to the\n * {@link TransactionWithBlockhashLifetime} type, and refines its type for use in your\n * program.\n *\n * @example\n * ```ts\n * import { isTransactionWithBlockhashLifetime } from '@solana/transactions';\n *\n * if (isTransactionWithBlockhashLifetime(transaction)) {\n * // At this point, `transaction` has been refined to a `TransactionWithBlockhashLifetime`.\n * const { blockhash } = transaction.lifetimeConstraint;\n * const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();\n * setBlockhashIsValid(blockhashIsValid);\n * } else {\n * setError(\n * `${getSignatureFromTransaction(transaction)} does not have a blockhash-based lifetime`,\n * );\n * }\n * ```\n */\nexport function isTransactionWithBlockhashLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): transaction is Transaction & TransactionWithBlockhashLifetime {\n return (\n 'lifetimeConstraint' in transaction &&\n 'blockhash' in transaction.lifetimeConstraint &&\n typeof transaction.lifetimeConstraint.blockhash === 'string' &&\n typeof transaction.lifetimeConstraint.lastValidBlockHeight === 'bigint' &&\n isBlockhash(transaction.lifetimeConstraint.blockhash)\n );\n}\n\n/**\n * From time to time you might acquire a transaction, that you expect to have a\n * blockhash-based lifetime, from for example a wallet. Use this function to\n * assert that such a transaction actually has a blockhash-based lifetime.\n *\n * @example\n * ```ts\n * import { assertIsTransactionWithBlockhashLifetime } from '@solana/transactions';\n *\n * try {\n * // If this type assertion function doesn't throw, then\n * // Typescript will upcast `transaction` to `TransactionWithBlockhashLifetime`.\n * assertIsTransactionWithBlockhashLifetime(transaction);\n * // At this point, `transaction` is a `TransactionWithBlockhashLifetime` that can be used\n * // with the RPC.\n * const { blockhash } = transaction.lifetimeConstraint;\n * const { value: blockhashIsValid } = await rpc.isBlockhashValid(blockhash).send();\n * } catch (e) {\n * // `transaction` turned out not to have a blockhash-based lifetime\n * }\n * ```\n */\nexport function assertIsTransactionWithBlockhashLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): asserts transaction is Transaction & TransactionWithBlockhashLifetime {\n if (!isTransactionWithBlockhashLifetime(transaction)) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME);\n }\n}\n\n/**\n * A type guard that returns `true` if the transaction conforms to the\n * {@link TransactionWithDurableNonceLifetime} type, and refines its type for use in your\n * program.\n *\n * @example\n * ```ts\n * import { isTransactionWithDurableNonceLifetime } from '@solana/transactions';\n * import { fetchNonce } from \"@solana-program/system\";\n *\n * if (isTransactionWithDurableNonceLifetime(transaction)) {\n * // At this point, `transaction` has been refined to a\n * // `TransactionWithDurableNonceLifetime`.\n * const { nonce, nonceAccountAddress } = transaction.lifetimeConstraint;\n * const { data: { blockhash: actualNonce } } = await fetchNonce(nonceAccountAddress);\n * setNonceIsValid(nonce === actualNonce);\n * } else {\n * setError(\n * `${getSignatureFromTransaction(transaction)} does not have a nonce-based lifetime`,\n * );\n * }\n * ```\n */\nexport function isTransactionWithDurableNonceLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): transaction is Transaction & TransactionWithDurableNonceLifetime {\n return (\n 'lifetimeConstraint' in transaction &&\n 'nonce' in transaction.lifetimeConstraint &&\n typeof transaction.lifetimeConstraint.nonce === 'string' &&\n typeof transaction.lifetimeConstraint.nonceAccountAddress === 'string' &&\n isAddress(transaction.lifetimeConstraint.nonceAccountAddress)\n );\n}\n\n/**\n * From time to time you might acquire a transaction, that you expect to have a\n * nonce-based lifetime, from for example a wallet. Use this function to assert\n * that such a transaction actually has a nonce-based lifetime.\n *\n * @example\n * ```ts\n * import { assertIsTransactionWithDurableNonceLifetime } from '@solana/transactions';\n *\n * try {\n * // If this type assertion function doesn't throw, then\n * // Typescript will upcast `transaction` to `TransactionWithDurableNonceLifetime`.\n * assertIsTransactionWithDurableNonceLifetime(transaction);\n * // At this point, `transaction` is a `TransactionWithDurableNonceLifetime` that can be used\n * // with the RPC.\n * const { nonce, nonceAccountAddress } = transaction.lifetimeConstraint;\n * const { data: { blockhash: actualNonce } } = await fetchNonce(nonceAccountAddress);\n * } catch (e) {\n * // `transaction` turned out not to have a nonce-based lifetime\n * }\n * ```\n */\nexport function assertIsTransactionWithDurableNonceLifetime(\n transaction: Transaction | (Transaction & TransactionWithLifetime),\n): asserts transaction is Transaction & TransactionWithDurableNonceLifetime {\n if (!isTransactionWithDurableNonceLifetime(transaction)) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME);\n }\n}\n","import {\n compileTransactionMessage,\n getCompiledTransactionMessageEncoder,\n isTransactionMessageWithBlockhashLifetime,\n isTransactionMessageWithDurableNonceLifetime,\n TransactionMessage,\n TransactionMessageWithFeePayer,\n} from '@solana/transaction-messages';\n\nimport type { TransactionWithLifetime } from './lifetime';\nimport type { SignaturesMap, TransactionFromTransactionMessage, TransactionMessageBytes } from './transaction';\n\n/**\n * Returns a {@link Transaction} object for a given {@link TransactionMessage}.\n *\n * This includes the compiled bytes of the transaction message, and a map of signatures. This map\n * will have a key for each address that is required to sign the transaction. The transaction will\n * not yet have signatures for any of these addresses.\n *\n * Whether a transaction message is ready to be compiled or not is enforced for you at the type\n * level. In order to be signable, a transaction message must:\n *\n * - have a version and a list of zero or more instructions (ie. conform to\n * {@link TransactionMessage})\n * - have a fee payer set (ie. conform to {@link TransactionMessageWithFeePayer})\n * - have a lifetime specified (ie. conform to {@link TransactionMessageWithBlockhashLifetime} or\n * {@link TransactionMessageWithDurableNonceLifetime})\n */\nexport function compileTransaction<TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer>(\n transactionMessage: TTransactionMessage,\n): Readonly<TransactionFromTransactionMessage<TTransactionMessage>> {\n type ReturnType = Readonly<TransactionFromTransactionMessage<TTransactionMessage>>;\n\n const compiledMessage = compileTransactionMessage(transactionMessage);\n const messageBytes = getCompiledTransactionMessageEncoder().encode(compiledMessage) as TransactionMessageBytes;\n\n const transactionSigners = compiledMessage.staticAccounts.slice(0, compiledMessage.header.numSignerAccounts);\n const signatures: SignaturesMap = {};\n for (const signerAddress of transactionSigners) {\n signatures[signerAddress] = null;\n }\n\n let lifetimeConstraint: TransactionWithLifetime['lifetimeConstraint'] | undefined;\n if (isTransactionMessageWithBlockhashLifetime(transactionMessage)) {\n lifetimeConstraint = {\n blockhash: transactionMessage.lifetimeConstraint.blockhash,\n lastValidBlockHeight: transactionMessage.lifetimeConstraint.lastValidBlockHeight,\n };\n } else if (isTransactionMessageWithDurableNonceLifetime(transactionMessage)) {\n lifetimeConstraint = {\n nonce: transactionMessage.lifetimeConstraint.nonce,\n nonceAccountAddress: transactionMessage.instructions[0].accounts[0].address,\n };\n }\n\n return Object.freeze({\n ...(lifetimeConstraint ? { lifetimeConstraint } : undefined),\n messageBytes: messageBytes,\n signatures: Object.freeze(signatures),\n }) as ReturnType;\n}\n","import { Address, getAddressFromPublicKey } from '@solana/addresses';\nimport { bytesEqual, Decoder } from '@solana/codecs-core';\nimport { getBase58Decoder } from '@solana/codecs-strings';\nimport {\n SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION,\n SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING,\n SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING,\n SolanaError,\n} from '@solana/errors';\nimport { Signature, SignatureBytes, signBytes } from '@solana/keys';\nimport { NominalType } from '@solana/nominal-types';\n\nimport { Transaction } from './transaction';\n\n/**\n * Represents a transaction that is signed by all of its required signers. Being fully signed is a\n * prerequisite of functions designed to land transactions on the network.\n */\nexport type FullySignedTransaction = NominalType<'transactionSignedness', 'fullySigned'>;\n\nlet base58Decoder: Decoder<string> | undefined;\n\n/**\n * Given a transaction signed by its fee payer, this method will return the {@link Signature} that\n * uniquely identifies it. This string can be used to look up transactions at a later date, for\n * example on a Solana block explorer.\n *\n * @example\n * ```ts\n * import { getSignatureFromTransaction } from '@solana/transactions';\n *\n * const signature = getSignatureFromTransaction(tx);\n * console.debug(`Inspect this transaction at https://explorer.solana.com/tx/${signature}`);\n * ```\n */\nexport function getSignatureFromTransaction(transaction: Transaction): Signature {\n if (!base58Decoder) base58Decoder = getBase58Decoder();\n\n // We have ordered signatures from the compiled message accounts\n // first signature is the fee payer\n const signatureBytes = Object.values(transaction.signatures)[0];\n if (!signatureBytes) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING);\n }\n const transactionSignature = base58Decoder.decode(signatureBytes);\n return transactionSignature as Signature;\n}\n\n/**\n * Given an array of `CryptoKey` objects which are private keys pertaining to addresses that are\n * required to sign a transaction, this method will return a new signed transaction of type\n * {@link Transaction}.\n *\n * Though the resulting transaction might have every signature it needs to land on the network, this\n * function will not assert that it does. A partially signed transaction cannot be landed on the\n * network, but can be serialized and deserialized.\n *\n * @example\n * ```ts\n * import { generateKeyPair } from '@solana/keys';\n * import { partiallySignTransaction } from '@solana/transactions';\n *\n * const partiallySignedTransaction = await partiallySignTransaction([myPrivateKey], tx);\n * ```\n *\n * @see {@link signTransaction} if you want to assert that the transaction has all of its required\n * signatures after signing.\n */\nexport async function partiallySignTransaction<TTransaction extends Transaction>(\n keyPairs: CryptoKeyPair[],\n transaction: TTransaction,\n): Promise<TTransaction> {\n let newSignatures: Record<Address, SignatureBytes> | undefined;\n let unexpectedSigners: Set<Address> | undefined;\n\n await Promise.all(\n keyPairs.map(async keyPair => {\n const address = await getAddressFromPublicKey(keyPair.publicKey);\n const existingSignature = transaction.signatures[address];\n\n // Check if the address is expected to sign the transaction\n if (existingSignature === undefined) {\n // address is not an expected signer for this transaction\n unexpectedSigners ||= new Set();\n unexpectedSigners.add(address);\n return;\n }\n\n // Return if there are any unexpected signers already since we won't be using signatures\n if (unexpectedSigners) {\n return;\n }\n\n const newSignature = await signBytes(keyPair.privateKey, transaction.messageBytes);\n\n if (existingSignature !== null && bytesEqual(newSignature, existingSignature)) {\n // already have the same signature set\n return;\n }\n\n newSignatures ||= {};\n newSignatures[address] = newSignature;\n }),\n );\n\n if (unexpectedSigners && unexpectedSigners.size > 0) {\n const expectedSigners = Object.keys(transaction.signatures);\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION, {\n expectedAddresses: expectedSigners,\n unexpectedAddresses: [...unexpectedSigners],\n });\n }\n\n if (!newSignatures) {\n return transaction;\n }\n\n return Object.freeze({\n ...transaction,\n signatures: Object.freeze({\n ...transaction.signatures,\n ...newSignatures,\n }),\n });\n}\n\n/**\n * Given an array of `CryptoKey` objects which are private keys pertaining to addresses that are\n * required to sign a transaction, this method will return a new signed transaction of type\n * {@link FullySignedTransaction}.\n *\n * This function will throw unless the resulting transaction is fully signed.\n *\n * @example\n * ```ts\n * import { generateKeyPair } from '@solana/keys';\n * import { signTransaction } from '@solana/transactions';\n *\n * const signedTransaction = await signTransaction([myPrivateKey], tx);\n * ```\n *\n * @see {@link partiallySignTransaction} if you want to sign the transaction without asserting that\n * the resulting transaction is fully signed.\n */\nexport async function signTransaction<TTransaction extends Transaction>(\n keyPairs: CryptoKeyPair[],\n transaction: TTransaction,\n): Promise<FullySignedTransaction & TTransaction> {\n const out = await partiallySignTransaction(keyPairs, transaction);\n assertIsFullySignedTransaction(out);\n Object.freeze(out);\n return out;\n}\n\n/**\n * Checks whether a given {@link Transaction} is fully signed.\n *\n * @example\n * ```ts\n * import { isFullySignedTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * if (isFullySignedTransaction(transaction)) {\n * // At this point we know that the transaction is signed and can be sent to the network.\n * }\n * ```\n */\nexport function isFullySignedTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): transaction is FullySignedTransaction & TTransaction {\n return Object.entries(transaction.signatures).every(([_, signatureBytes]) => !!signatureBytes);\n}\n\n/**\n * From time to time you might acquire a {@link Transaction}, that you expect to be fully signed,\n * from an untrusted network API or user input. Use this function to assert that such a transaction\n * is fully signed.\n *\n * @example\n * ```ts\n * import { assertIsFullySignedTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * try {\n * // If this type assertion function doesn't throw, then Typescript will upcast `transaction`\n * // to `FullySignedTransaction`.\n * assertIsFullySignedTransaction(transaction);\n * // At this point we know that the transaction is signed and can be sent to the network.\n * await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });\n * } catch(e) {\n * if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING)) {\n * setError(`Missing signatures for ${e.context.addresses.join(', ')}`);\n * }\n * throw;\n * }\n * ```\n */\nexport function assertIsFullySignedTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): asserts transaction is FullySignedTransaction & TTransaction {\n const missingSigs: Address[] = [];\n Object.entries(transaction.signatures).forEach(([address, signatureBytes]) => {\n if (!signatureBytes) {\n missingSigs.push(address as Address);\n }\n });\n\n if (missingSigs.length > 0) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING, {\n addresses: missingSigs,\n });\n }\n}\n","import { getBase64Decoder } from '@solana/codecs-strings';\nimport { Brand, EncodedString } from '@solana/nominal-types';\n\nimport { getTransactionEncoder } from './codecs';\nimport { Transaction } from './transaction';\n\n/** Represents the wire format of a transaction as a base64-encoded string. */\nexport type Base64EncodedWireTransaction = Brand<EncodedString<string, 'base64'>, 'Base64EncodedWireTransaction'>;\n\n/**\n * Given a signed transaction, this method returns the transaction as a string that conforms to the\n * {@link Base64EncodedWireTransaction} type.\n *\n * @example\n * ```ts\n * import { getBase64EncodedWireTransaction, signTransaction } from '@solana/transactions';\n *\n * const serializedTransaction = getBase64EncodedWireTransaction(signedTransaction);\n * const signature = await rpc.sendTransaction(serializedTransaction, { encoding: 'base64' }).send();\n * ```\n */\nexport function getBase64EncodedWireTransaction(transaction: Transaction): Base64EncodedWireTransaction {\n const wireTransactionBytes = getTransactionEncoder().encode(transaction);\n return getBase64Decoder().decode(wireTransactionBytes) as Base64EncodedWireTransaction;\n}\n","import { SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, SolanaError } from '@solana/errors';\nimport type { NominalType } from '@solana/nominal-types';\nimport type { TransactionMessage, TransactionMessageWithinSizeLimit } from '@solana/transaction-messages';\n\nimport { getTransactionEncoder } from './codecs';\nimport { Transaction } from './transaction';\n\n/**\n * The maximum size of a transaction packet in bytes.\n */\nexport const TRANSACTION_PACKET_SIZE = 1280;\n\n/**\n * The size of the transaction packet header in bytes.\n * This includes the IPv6 header and the fragment header.\n */\nexport const TRANSACTION_PACKET_HEADER =\n 40 /* 40 bytes is the size of the IPv6 header. */ + 8; /* 8 bytes is the size of the fragment header. */\n\n/**\n * The maximum size of a transaction in bytes.\n *\n * Note that this excludes the transaction packet header.\n * In other words, this is how much content we can fit in a transaction packet.\n */\nexport const TRANSACTION_SIZE_LIMIT = TRANSACTION_PACKET_SIZE - TRANSACTION_PACKET_HEADER;\n\n/**\n * Gets the size of a given transaction in bytes.\n *\n * @example\n * ```ts\n * const transactionSize = getTransactionSize(transaction);\n * ```\n */\nexport function getTransactionSize(transaction: Transaction): number {\n return getTransactionEncoder().getSizeFromValue(transaction);\n}\n\n/**\n * A type guard that checks if a transaction is within the size limit.\n */\nexport type TransactionWithinSizeLimit = NominalType<'transactionSize', 'withinLimit'>;\n\n/**\n * Helper type that adds the `TransactionWithinSizeLimit` flag to\n * a transaction if and only if the provided transaction message\n * is also within the size limit.\n */\nexport type SetTransactionWithinSizeLimitFromTransactionMessage<\n TTransaction extends Transaction,\n TTransactionMessage extends TransactionMessage,\n> = TTransactionMessage extends TransactionMessageWithinSizeLimit\n ? TransactionWithinSizeLimit & TTransaction\n : TTransaction;\n\n/**\n * Checks if a transaction is within the size limit.\n *\n * @typeParam TTransaction - The type of the given transaction.\n *\n * @example\n * ```ts\n * if (isTransactionWithinSizeLimit(transaction)) {\n * transaction satisfies TransactionWithinSizeLimit;\n * }\n * ```\n */\nexport function isTransactionWithinSizeLimit<TTransaction extends Transaction>(\n transaction: TTransaction,\n): transaction is TransactionWithinSizeLimit & TTransaction {\n return getTransactionSize(transaction) <= TRANSACTION_SIZE_LIMIT;\n}\n\n/**\n * Asserts that a given transaction is within the size limit.\n *\n * Throws a {@link SolanaError} of code {@link SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT}\n * if the transaction exceeds the size limit.\n *\n * @typeParam TTransaction - The type of the given transaction.\n *\n * @example\n * ```ts\n * assertIsTransactionWithinSizeLimit(transaction);\n * transaction satisfies TransactionWithinSizeLimit;\n * ```\n */\nexport function assertIsTransactionWithinSizeLimit<TTransaction extends Transaction>(\n transaction: TTransaction,\n): asserts transaction is TransactionWithinSizeLimit & TTransaction {\n const transactionSize = getTransactionSize(transaction);\n if (transactionSize > TRANSACTION_SIZE_LIMIT) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, {\n transactionSize,\n transactionSizeLimit: TRANSACTION_SIZE_LIMIT,\n });\n }\n}\n","import { assertIsFullySignedTransaction, FullySignedTransaction, isFullySignedTransaction } from './signatures';\nimport { Transaction } from './transaction';\nimport {\n assertIsTransactionWithinSizeLimit,\n isTransactionWithinSizeLimit,\n TransactionWithinSizeLimit,\n} from './transaction-size';\n\n/**\n * Helper type that includes all transaction types required\n * for the transaction to be sent to the network.\n *\n * @see {@link isSendableTransaction}\n * @see {@link assertIsSendableTransaction}\n */\nexport type SendableTransaction = FullySignedTransaction & TransactionWithinSizeLimit;\n\n/**\n * Checks if a transaction has all the required\n * conditions to be sent to the network.\n *\n * @example\n * ```ts\n * import { isSendableTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * if (isSendableTransaction(transaction)) {\n * // At this point we know that the transaction can be sent to the network.\n * }\n * ```\n *\n * @see {@link assertIsSendableTransaction}\n */\nexport function isSendableTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): transaction is SendableTransaction & TTransaction {\n return isFullySignedTransaction(transaction) && isTransactionWithinSizeLimit(transaction);\n}\n\n/**\n * Asserts that a given transaction has all the\n * required conditions to be sent to the network.\n *\n * From time to time you might acquire a {@link Transaction}\n * from an untrusted network API or user input and you are not sure\n * that it has all the required conditions to be sent to the network\n * — such as being fully signed and within the size limit.\n * This function can be used to assert that such a transaction\n * is in fact sendable.\n *\n * @example\n * ```ts\n * import { assertIsSendableTransaction } from '@solana/transactions';\n *\n * const transaction = getTransactionDecoder().decode(transactionBytes);\n * try {\n * // If this type assertion function doesn't throw, then Typescript will upcast `transaction`\n * // to `SendableTransaction`.\n * assertIsSendableTransaction(transaction);\n * // At this point we know that the transaction can be sent to the network.\n * await sendAndConfirmTransaction(transaction, { commitment: 'confirmed' });\n * } catch(e) {\n * if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING)) {\n * setError(`Missing signatures for ${e.context.addresses.join(', ')}`);\n * } else if (isSolanaError(e, SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT)) {\n * setError(`Transaction exceeds size limit of ${e.context.transactionSizeLimit} bytes`);\n * }\n * throw;\n * }\n * ```\n */\nexport function assertIsSendableTransaction<TTransaction extends Transaction>(\n transaction: TTransaction,\n): asserts transaction is SendableTransaction & TTransaction {\n assertIsFullySignedTransaction(transaction);\n assertIsTransactionWithinSizeLimit(transaction);\n}\n","import { SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, SolanaError } from '@solana/errors';\nimport type {\n TransactionMessage,\n TransactionMessageWithFeePayer,\n TransactionMessageWithinSizeLimit,\n} from '@solana/transaction-messages';\n\nimport { compileTransaction } from './compile-transaction';\nimport { getTransactionSize, TRANSACTION_SIZE_LIMIT } from './transaction-size';\n\n/**\n * Gets the compiled transaction size of a given transaction message in bytes.\n *\n * @example\n * ```ts\n * const transactionSize = getTransactionMessageSize(transactionMessage);\n * ```\n */\nexport function getTransactionMessageSize(\n transactionMessage: TransactionMessage & TransactionMessageWithFeePayer,\n): number {\n return getTransactionSize(compileTransaction(transactionMessage));\n}\n\n/**\n * Checks if a transaction message is within the size limit\n * when compiled into a transaction.\n *\n * @typeParam TTransactionMessage - The type of the given transaction message.\n *\n * @example\n * ```ts\n * if (isTransactionMessageWithinSizeLimit(transactionMessage)) {\n * transactionMessage satisfies TransactionMessageWithinSizeLimit;\n * }\n * ```\n */\nexport function isTransactionMessageWithinSizeLimit<\n TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer,\n>(\n transactionMessage: TTransactionMessage,\n): transactionMessage is TransactionMessageWithinSizeLimit & TTransactionMessage {\n return getTransactionMessageSize(transactionMessage) <= TRANSACTION_SIZE_LIMIT;\n}\n\n/**\n * Asserts that a given transaction message is within the size limit\n * when compiled into a transaction.\n *\n * Throws a {@link SolanaError} of code {@link SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT}\n * if the transaction message exceeds the size limit.\n *\n * @typeParam TTransactionMessage - The type of the given transaction message.\n *\n * @example\n * ```ts\n * assertIsTransactionMessageWithinSizeLimit(transactionMessage);\n * transactionMessage satisfies TransactionMessageWithinSizeLimit;\n * ```\n */\nexport function assertIsTransactionMessageWithinSizeLimit<\n TTransactionMessage extends TransactionMessage & TransactionMessageWithFeePayer,\n>(\n transactionMessage: TTransactionMessage,\n): asserts transactionMessage is TransactionMessageWithinSizeLimit & TTransactionMessage {\n const transactionSize = getTransactionMessageSize(transactionMessage);\n if (transactionSize > TRANSACTION_SIZE_LIMIT) {\n throw new SolanaError(SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, {\n transactionSize,\n transactionSizeLimit: TRANSACTION_SIZE_LIMIT,\n });\n }\n}\n"]}
@@ -2,7 +2,7 @@ import { getAddressDecoder, isAddress, getAddressFromPublicKey } from '@solana/a
2
2
  import { createEncoder, transformDecoder, fixDecoderSize, createDecoder, combineCodec, padRightDecoder, bytesEqual, transformEncoder, fixEncoderSize } from '@solana/codecs-core';
3
3
  import { getPredicateEncoder, getStructEncoder, getBytesEncoder, getPredicateDecoder, getStructDecoder, getArrayDecoder, getBytesDecoder, getTupleDecoder, getArrayEncoder } from '@solana/codecs-data-structures';
4
4
  import { getShortU16Decoder, getU8Decoder, getShortU16Encoder } from '@solana/codecs-numbers';
5
- import { SolanaError, SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES, SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH, SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING, SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING, SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES, SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES, SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES, SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES } from '@solana/errors';
5
+ import { SolanaError, SOLANA_ERROR__TRANSACTION__SIGNATURE_COUNT_TOO_HIGH_FOR_TRANSACTION_BYTES, SOLANA_ERROR__TRANSACTION__MESSAGE_SIGNATURES_MISMATCH, SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, SOLANA_ERROR__TRANSACTION__INVALID_NONCE_ACCOUNT_INDEX, SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, SOLANA_ERROR__TRANSACTION__EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION__EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION__FEE_PAYER_SIGNATURE_MISSING, SOLANA_ERROR__TRANSACTION__ADDRESSES_CANNOT_SIGN_TRANSACTION, SOLANA_ERROR__TRANSACTION__SIGNATURES_MISSING, SOLANA_ERROR__TRANSACTION__EXCEEDS_SIZE_LIMIT, SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_MESSAGE_BYTES, SOLANA_ERROR__TRANSACTION__MALFORMED_MESSAGE_BYTES, SOLANA_ERROR__TRANSACTION__CANNOT_DECODE_EMPTY_TRANSACTION_BYTES, SOLANA_ERROR__TRANSACTION__VERSION_ZERO_MUST_BE_ENCODED_WITH_SIGNATURES_FIRST, SOLANA_ERROR__TRANSACTION__CANNOT_ENCODE_WITH_EMPTY_SIGNATURES } from '@solana/errors';
6
6
  import { getTransactionVersionDecoder, compileTransactionMessage, getCompiledTransactionMessageEncoder, isTransactionMessageWithBlockhashLifetime, isTransactionMessageWithDurableNonceLifetime } from '@solana/transaction-messages';
7
7
  import { isBlockhash } from '@solana/rpc-types';
8
8
  import { getBase58Decoder, getBase64Decoder } from '@solana/codecs-strings';
@@ -215,7 +215,12 @@ function makeSignaturesMap(signerAddresses, signatures) {
215
215
  return Object.freeze(signaturesMap);
216
216
  }
217
217
  var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
218
- function compiledInstructionIsAdvanceNonceInstruction(instruction, staticAddresses) {
218
+ function compiledV1InstructionIsAdvanceNonceInstruction(instructionHeader, instructionPayload, staticAddresses) {
219
+ return staticAddresses[instructionHeader.programAccountIndex] === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
220
+ isAdvanceNonceAccountInstructionData(instructionPayload.instructionData) && // Test for exactly 3 accounts
221
+ instructionHeader.numInstructionAccounts === 3;
222
+ }
223
+ function compiledLegacyInstructionIsAdvanceNonceInstruction(instruction, staticAddresses) {
219
224
  return staticAddresses[instruction.programAddressIndex] === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
220
225
  instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
221
226
  instruction.accountIndices?.length === 3;
@@ -224,26 +229,61 @@ function isAdvanceNonceAccountInstructionData(data) {
224
229
  return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
225
230
  }
226
231
  async function getTransactionLifetimeConstraintFromCompiledTransactionMessage(compiledTransactionMessage) {
227
- const firstInstruction = compiledTransactionMessage.instructions[0];
228
- const { staticAccounts } = compiledTransactionMessage;
229
- if (firstInstruction && compiledInstructionIsAdvanceNonceInstruction(firstInstruction, staticAccounts)) {
230
- const nonceAccountAddress = staticAccounts[firstInstruction.accountIndices[0]];
231
- if (!nonceAccountAddress) {
232
- throw new SolanaError(SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, {
233
- nonce: compiledTransactionMessage.lifetimeToken
234
- });
232
+ const { version } = compiledTransactionMessage;
233
+ if (version === "legacy" || version === 0) {
234
+ const firstInstruction = compiledTransactionMessage.instructions[0];
235
+ const { staticAccounts } = compiledTransactionMessage;
236
+ if (firstInstruction && compiledLegacyInstructionIsAdvanceNonceInstruction(firstInstruction, staticAccounts)) {
237
+ const nonceAccountAddress = staticAccounts[firstInstruction.accountIndices[0]];
238
+ if (!nonceAccountAddress) {
239
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__NONCE_ACCOUNT_CANNOT_BE_IN_LOOKUP_TABLE, {
240
+ nonce: compiledTransactionMessage.lifetimeToken
241
+ });
242
+ }
243
+ return {
244
+ nonce: compiledTransactionMessage.lifetimeToken,
245
+ nonceAccountAddress
246
+ };
247
+ } else {
248
+ return {
249
+ blockhash: compiledTransactionMessage.lifetimeToken,
250
+ // This is not known from the compiled message, so we set it to the maximum possible value
251
+ lastValidBlockHeight: 0xffffffffffffffffn
252
+ };
235
253
  }
236
- return {
237
- nonce: compiledTransactionMessage.lifetimeToken,
238
- nonceAccountAddress
239
- };
240
- } else {
241
- return {
242
- blockhash: compiledTransactionMessage.lifetimeToken,
243
- // This is not known from the compiled message, so we set it to the maximum possible value
244
- lastValidBlockHeight: 0xffffffffffffffffn
245
- };
246
254
  }
255
+ if (version === 1) {
256
+ const firstInstructionHeader = compiledTransactionMessage.instructionHeaders[0];
257
+ const firstInstructionPayload = compiledTransactionMessage.instructionPayloads[0];
258
+ const { staticAccounts } = compiledTransactionMessage;
259
+ if (firstInstructionHeader && firstInstructionPayload && compiledV1InstructionIsAdvanceNonceInstruction(
260
+ firstInstructionHeader,
261
+ firstInstructionPayload,
262
+ staticAccounts
263
+ )) {
264
+ const nonceAccountAddress = staticAccounts[firstInstructionPayload.instructionAccountIndices[0]];
265
+ if (!nonceAccountAddress) {
266
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__INVALID_NONCE_ACCOUNT_INDEX, {
267
+ nonce: compiledTransactionMessage.lifetimeToken,
268
+ nonceAccountIndex: firstInstructionPayload.instructionAccountIndices[0],
269
+ numberOfStaticAccounts: staticAccounts.length
270
+ });
271
+ }
272
+ return {
273
+ nonce: compiledTransactionMessage.lifetimeToken,
274
+ nonceAccountAddress
275
+ };
276
+ } else {
277
+ return {
278
+ blockhash: compiledTransactionMessage.lifetimeToken,
279
+ // This is not known from the compiled message, so we set it to the maximum possible value
280
+ lastValidBlockHeight: 0xffffffffffffffffn
281
+ };
282
+ }
283
+ }
284
+ throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, {
285
+ unsupportedVersion: version
286
+ });
247
287
  }
248
288
  function isTransactionWithBlockhashLifetime(transaction) {
249
289
  return "lifetimeConstraint" in transaction && "blockhash" in transaction.lifetimeConstraint && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint" && isBlockhash(transaction.lifetimeConstraint.blockhash);