@solana/transactions
Advanced tools
Comparing version 2.0.0-experimental.fbdf21a to 2.0.0-experimental.fc4e943
@@ -0,1 +1,58 @@ | ||
import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers'; | ||
import { getAddressFromPublicKey, getAddressComparator, getAddressCodec } from '@solana/addresses'; | ||
import { getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU8Codec } from '@solana/codecs-numbers'; | ||
import { combineCodec } from '@solana/codecs-core'; | ||
import { signBytes } from '@solana/keys'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/unsigned-transaction.ts | ||
function getUnsignedTransaction(transaction) { | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
return unsignedTransaction; | ||
} else { | ||
return transaction; | ||
} | ||
} | ||
// src/blockhash.ts | ||
function assertIsBlockhash(putativeBlockhash) { | ||
try { | ||
if ( | ||
// Lowest value (32 bytes of zeroes) | ||
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255) | ||
putativeBlockhash.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes3 = base58.serialize(putativeBlockhash); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, { | ||
cause: e | ||
}); | ||
} | ||
} | ||
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) { | ||
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) { | ||
return transaction; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
lifetimeConstraint: blockhashLifetimeConstraint | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
// src/create-transaction.ts | ||
@@ -13,2 +70,84 @@ function createTransaction({ | ||
// ../instructions/dist/index.browser.js | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_WRITABLE_BITMASK = 1; | ||
function isSignerRole(role) { | ||
return role >= 2; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
// src/durable-nonce.ts | ||
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111"; | ||
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111"; | ||
function assertIsDurableNonceTransaction(transaction) { | ||
if (!isDurableNonceTransaction(transaction)) { | ||
throw new Error("Transaction is not a durable nonce transaction"); | ||
} | ||
} | ||
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) { | ||
return { | ||
accounts: [ | ||
{ address: nonceAccountAddress, role: AccountRole.WRITABLE }, | ||
{ | ||
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS, | ||
role: AccountRole.READONLY | ||
}, | ||
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER } | ||
], | ||
data: new Uint8Array([4, 0, 0, 0]), | ||
programAddress: SYSTEM_PROGRAM_ADDRESS | ||
}; | ||
} | ||
function isAdvanceNonceAccountInstruction(instruction) { | ||
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data | ||
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts | ||
instruction.accounts?.length === 3 && // First account is nonce account address | ||
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar | ||
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account | ||
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER; | ||
} | ||
function isAdvanceNonceAccountInstructionData(data) { | ||
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0; | ||
} | ||
function isDurableNonceTransaction(transaction) { | ||
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]); | ||
} | ||
function setTransactionLifetimeUsingDurableNonce({ | ||
nonce, | ||
nonceAccountAddress, | ||
nonceAuthorityAddress | ||
}, transaction) { | ||
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction); | ||
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) { | ||
return transaction; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [ | ||
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress), | ||
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions | ||
], | ||
lifetimeConstraint: { | ||
nonce | ||
} | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
// src/fee-payer.ts | ||
@@ -19,19 +158,6 @@ function setTransactionFeePayer(feePayer, transaction) { | ||
} | ||
let out; | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
out = { | ||
...unsignedTransaction, | ||
feePayer | ||
}; | ||
} else { | ||
out = { | ||
...transaction, | ||
feePayer | ||
}; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
feePayer | ||
}; | ||
Object.freeze(out); | ||
@@ -42,25 +168,7 @@ return out; | ||
// src/instructions.ts | ||
function replaceInstructions(transaction, nextInstructions) { | ||
let out; | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
out = { | ||
...unsignedTransaction, | ||
instructions: nextInstructions | ||
}; | ||
} else { | ||
out = { | ||
...transaction, | ||
instructions: nextInstructions | ||
}; | ||
} | ||
return out; | ||
} | ||
function appendTransactionInstruction(instruction, transaction) { | ||
const nextInstructions = [...transaction.instructions, instruction]; | ||
const out = replaceInstructions(transaction, nextInstructions); | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [...transaction.instructions, instruction] | ||
}; | ||
Object.freeze(out); | ||
@@ -70,10 +178,663 @@ return out; | ||
function prependTransactionInstruction(instruction, transaction) { | ||
const nextInstructions = [instruction, ...transaction.instructions]; | ||
const out = replaceInstructions(transaction, nextInstructions); | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [instruction, ...transaction.instructions] | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
function upsert(addressMap, address, update) { | ||
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY }); | ||
} | ||
var TYPE = Symbol("AddressMapTypeProperty"); | ||
function getAddressMapFromInstructions(feePayer, instructions) { | ||
const addressMap = { | ||
[feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER } | ||
}; | ||
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set(); | ||
for (const instruction of instructions) { | ||
upsert(addressMap, instruction.programAddress, (entry) => { | ||
addressesOfInvokedPrograms.add(instruction.programAddress); | ||
if (TYPE in entry) { | ||
if (isWritableRole(entry.role)) { | ||
switch (entry[TYPE]) { | ||
case 0 /* FEE_PAYER */: | ||
throw new Error( | ||
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.` | ||
); | ||
default: | ||
throw new Error( | ||
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.` | ||
); | ||
} | ||
} | ||
if (entry[TYPE] === 2 /* STATIC */) { | ||
return entry; | ||
} | ||
} | ||
return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY }; | ||
}); | ||
let addressComparator; | ||
if (!instruction.accounts) { | ||
continue; | ||
} | ||
for (const account of instruction.accounts) { | ||
upsert(addressMap, account.address, (entry) => { | ||
const { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
address: _, | ||
...accountMeta | ||
} = account; | ||
if (TYPE in entry) { | ||
switch (entry[TYPE]) { | ||
case 0 /* FEE_PAYER */: | ||
return entry; | ||
case 1 /* LOOKUP_TABLE */: { | ||
const nextRole = mergeRoles(entry.role, accountMeta.role); | ||
if ("lookupTableAddress" in accountMeta) { | ||
const shouldReplaceEntry = ( | ||
// Consider using the new LOOKUP_TABLE if its address is different... | ||
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one. | ||
(addressComparator || (addressComparator = getAddressComparator()))( | ||
accountMeta.lookupTableAddress, | ||
entry.lookupTableAddress | ||
) < 0 | ||
); | ||
if (shouldReplaceEntry) { | ||
return { | ||
[TYPE]: 1 /* LOOKUP_TABLE */, | ||
...accountMeta, | ||
role: nextRole | ||
}; | ||
} | ||
} else if (isSignerRole(accountMeta.role)) { | ||
return { | ||
[TYPE]: 2 /* STATIC */, | ||
role: nextRole | ||
}; | ||
} | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} | ||
case 2 /* STATIC */: { | ||
const nextRole = mergeRoles(entry.role, accountMeta.role); | ||
if ( | ||
// Check to see if this address represents a program that is invoked | ||
// in this transaction. | ||
addressesOfInvokedPrograms.has(account.address) | ||
) { | ||
if (isWritableRole(accountMeta.role)) { | ||
throw new Error( | ||
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.` | ||
); | ||
} | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as | ||
// long as they are not require to sign the transaction. | ||
!isSignerRole(entry.role)) { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 1 /* LOOKUP_TABLE */, | ||
role: nextRole | ||
}; | ||
} else { | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if ("lookupTableAddress" in accountMeta) { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 1 /* LOOKUP_TABLE */ | ||
}; | ||
} else { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 2 /* STATIC */ | ||
}; | ||
} | ||
}); | ||
} | ||
} | ||
return addressMap; | ||
} | ||
function getOrderedAccountsFromAddressMap(addressMap) { | ||
let addressComparator; | ||
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => { | ||
if (leftEntry[TYPE] !== rightEntry[TYPE]) { | ||
if (leftEntry[TYPE] === 0 /* FEE_PAYER */) { | ||
return -1; | ||
} else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) { | ||
return 1; | ||
} else if (leftEntry[TYPE] === 2 /* STATIC */) { | ||
return -1; | ||
} else if (rightEntry[TYPE] === 2 /* STATIC */) { | ||
return 1; | ||
} | ||
} | ||
const leftIsSigner = isSignerRole(leftEntry.role); | ||
if (leftIsSigner !== isSignerRole(rightEntry.role)) { | ||
return leftIsSigner ? -1 : 1; | ||
} | ||
const leftIsWritable = isWritableRole(leftEntry.role); | ||
if (leftIsWritable !== isWritableRole(rightEntry.role)) { | ||
return leftIsWritable ? -1 : 1; | ||
} | ||
addressComparator || (addressComparator = getAddressComparator()); | ||
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) { | ||
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress); | ||
} else { | ||
return addressComparator(leftAddress, rightAddress); | ||
} | ||
}).map(([address, addressMeta]) => ({ | ||
address, | ||
...addressMeta | ||
})); | ||
return orderedAccounts; | ||
} | ||
function getCompiledAddressTableLookups(orderedAccounts) { | ||
var _a; | ||
const index = {}; | ||
for (const account of orderedAccounts) { | ||
if (!("lookupTableAddress" in account)) { | ||
continue; | ||
} | ||
const entry = index[_a = account.lookupTableAddress] || (index[_a] = { | ||
readableIndices: [], | ||
writableIndices: [] | ||
}); | ||
if (account.role === AccountRole.WRITABLE) { | ||
entry.writableIndices.push(account.addressIndex); | ||
} else { | ||
entry.readableIndices.push(account.addressIndex); | ||
} | ||
} | ||
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({ | ||
lookupTableAddress, | ||
...index[lookupTableAddress] | ||
})); | ||
} | ||
export { appendTransactionInstruction, createTransaction, prependTransactionInstruction, setTransactionFeePayer }; | ||
// src/compile-header.ts | ||
function getCompiledMessageHeader(orderedAccounts) { | ||
let numReadonlyNonSignerAccounts = 0; | ||
let numReadonlySignerAccounts = 0; | ||
let numSignerAccounts = 0; | ||
for (const account of orderedAccounts) { | ||
if ("lookupTableAddress" in account) { | ||
break; | ||
} | ||
const accountIsWritable = isWritableRole(account.role); | ||
if (isSignerRole(account.role)) { | ||
numSignerAccounts++; | ||
if (!accountIsWritable) { | ||
numReadonlySignerAccounts++; | ||
} | ||
} else if (!accountIsWritable) { | ||
numReadonlyNonSignerAccounts++; | ||
} | ||
} | ||
return { | ||
numReadonlyNonSignerAccounts, | ||
numReadonlySignerAccounts, | ||
numSignerAccounts | ||
}; | ||
} | ||
// src/compile-instructions.ts | ||
function getAccountIndex(orderedAccounts) { | ||
const out = {}; | ||
for (const [index, account] of orderedAccounts.entries()) { | ||
out[account.address] = index; | ||
} | ||
return out; | ||
} | ||
function getCompiledInstructions(instructions, orderedAccounts) { | ||
const accountIndex = getAccountIndex(orderedAccounts); | ||
return instructions.map(({ accounts, data, programAddress }) => { | ||
return { | ||
programAddressIndex: accountIndex[programAddress], | ||
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null, | ||
...data ? { data } : null | ||
}; | ||
}); | ||
} | ||
// src/compile-lifetime-token.ts | ||
function getCompiledLifetimeToken(lifetimeConstraint) { | ||
if ("nonce" in lifetimeConstraint) { | ||
return lifetimeConstraint.nonce; | ||
} | ||
return lifetimeConstraint.blockhash; | ||
} | ||
// src/compile-static-accounts.ts | ||
function getCompiledStaticAccounts(orderedAccounts) { | ||
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account); | ||
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex); | ||
return orderedStaticAccounts.map(({ address }) => address); | ||
} | ||
// src/message.ts | ||
function compileMessage(transaction) { | ||
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions); | ||
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap); | ||
return { | ||
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null, | ||
header: getCompiledMessageHeader(orderedAccounts), | ||
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts), | ||
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint), | ||
staticAccounts: getCompiledStaticAccounts(orderedAccounts), | ||
version: transaction.version | ||
}; | ||
} | ||
// src/compile-transaction.ts | ||
function getCompiledTransaction(transaction) { | ||
const compiledMessage = compileMessage(transaction); | ||
let signatures; | ||
if ("signatures" in transaction) { | ||
signatures = []; | ||
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) { | ||
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0)); | ||
} | ||
} else { | ||
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0))); | ||
} | ||
return { | ||
compiledMessage, | ||
signatures | ||
}; | ||
} | ||
function addressSerializerCompat(compat) { | ||
const codec = getAddressCodec(); | ||
return { | ||
description: compat?.description ?? codec.description, | ||
deserialize: codec.decode, | ||
fixedSize: codec.fixedSize, | ||
maxSize: codec.maxSize, | ||
serialize: codec.encode | ||
}; | ||
} | ||
function getAddressTableLookupCodec() { | ||
return struct( | ||
[ | ||
[ | ||
"lookupTableAddress", | ||
addressSerializerCompat( | ||
__DEV__ ? { | ||
description: "The address of the address lookup table account from which instruction addresses should be looked up" | ||
} : void 0 | ||
) | ||
], | ||
[ | ||
"writableIndices", | ||
array(u8(), { | ||
...__DEV__ ? { | ||
description: "The indices of the accounts in the lookup table that should be loaded as writeable" | ||
} : null, | ||
size: shortU16() | ||
}) | ||
], | ||
[ | ||
"readableIndices", | ||
array(u8(), { | ||
...__DEV__ ? { | ||
description: "The indices of the accounts in the lookup table that should be loaded as read-only" | ||
} : void 0, | ||
size: shortU16() | ||
}) | ||
] | ||
], | ||
__DEV__ ? { | ||
description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" | ||
} : void 0 | ||
); | ||
} | ||
var memoizedU8Codec; | ||
function getMemoizedU8Codec() { | ||
if (!memoizedU8Codec) | ||
memoizedU8Codec = getU8Codec(); | ||
return memoizedU8Codec; | ||
} | ||
function getMemoizedU8CodecDescription(description) { | ||
const codec = getMemoizedU8Codec(); | ||
return { | ||
...codec, | ||
description: description ?? codec.description | ||
}; | ||
} | ||
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0; | ||
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0; | ||
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0; | ||
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0; | ||
function getMessageHeaderCodec() { | ||
return getStructCodec( | ||
[ | ||
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)], | ||
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)], | ||
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)] | ||
], | ||
{ | ||
description: messageHeaderDescription | ||
} | ||
); | ||
} | ||
function getInstructionCodec() { | ||
return mapSerializer( | ||
struct([ | ||
[ | ||
"programAddressIndex", | ||
u8( | ||
__DEV__ ? { | ||
description: "The index of the program being called, according to the well-ordered accounts list for this transaction" | ||
} : void 0 | ||
) | ||
], | ||
[ | ||
"accountIndices", | ||
array( | ||
u8({ | ||
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : "" | ||
}), | ||
{ | ||
description: __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "", | ||
size: shortU16() | ||
} | ||
) | ||
], | ||
[ | ||
"data", | ||
bytes({ | ||
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "", | ||
size: shortU16() | ||
}) | ||
] | ||
]), | ||
(value) => { | ||
if (value.accountIndices !== void 0 && value.data !== void 0) { | ||
return value; | ||
} | ||
return { | ||
...value, | ||
accountIndices: value.accountIndices ?? [], | ||
data: value.data ?? new Uint8Array(0) | ||
}; | ||
}, | ||
(value) => { | ||
if (value.accountIndices.length && value.data.byteLength) { | ||
return value; | ||
} | ||
const { accountIndices, data, ...rest } = value; | ||
return { | ||
...rest, | ||
...accountIndices.length ? { accountIndices } : null, | ||
...data.byteLength ? { data } : null | ||
}; | ||
} | ||
); | ||
} | ||
var VERSION_FLAG_MASK = 128; | ||
var BASE_CONFIG = { | ||
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "", | ||
fixedSize: null, | ||
maxSize: 1 | ||
}; | ||
function decode(bytes3, offset = 0) { | ||
const firstByte = bytes3[offset]; | ||
if ((firstByte & VERSION_FLAG_MASK) === 0) { | ||
return ["legacy", offset]; | ||
} else { | ||
const version = firstByte ^ VERSION_FLAG_MASK; | ||
return [version, offset + 1]; | ||
} | ||
} | ||
function encode(value) { | ||
if (value === "legacy") { | ||
return new Uint8Array(); | ||
} | ||
if (value < 0 || value > 127) { | ||
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`); | ||
} | ||
return new Uint8Array([value | VERSION_FLAG_MASK]); | ||
} | ||
function getTransactionVersionDecoder() { | ||
return { | ||
...BASE_CONFIG, | ||
decode | ||
}; | ||
} | ||
function getTransactionVersionEncoder() { | ||
return { | ||
...BASE_CONFIG, | ||
encode | ||
}; | ||
} | ||
function getTransactionVersionCodec() { | ||
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder()); | ||
} | ||
// src/serializers/unimplemented.ts | ||
function getError(type, name) { | ||
const functionSuffix = name + type[0].toUpperCase() + type.slice(1); | ||
return new Error( | ||
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}` | ||
); | ||
} | ||
function getUnimplementedDecoder(name) { | ||
return () => { | ||
throw getError("decoder", name); | ||
}; | ||
} | ||
// src/serializers/message.ts | ||
var BASE_CONFIG2 = { | ||
description: __DEV__ ? "The wire format of a Solana transaction message" : "", | ||
fixedSize: null, | ||
maxSize: null | ||
}; | ||
function serialize(compiledMessage) { | ||
if (compiledMessage.version === "legacy") { | ||
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage); | ||
} else { | ||
return mapSerializer( | ||
struct([ | ||
...getPreludeStructSerializerTuple(), | ||
["addressTableLookups", getAddressTableLookupsSerializer()] | ||
]), | ||
(value) => { | ||
if (value.version === "legacy") { | ||
return value; | ||
} | ||
return { | ||
...value, | ||
addressTableLookups: value.addressTableLookups ?? [] | ||
}; | ||
} | ||
).serialize(compiledMessage); | ||
} | ||
} | ||
function toSerializer(codec) { | ||
return { | ||
description: codec.description, | ||
deserialize: codec.decode, | ||
fixedSize: codec.fixedSize, | ||
maxSize: codec.maxSize, | ||
serialize: codec.encode | ||
}; | ||
} | ||
function getPreludeStructSerializerTuple() { | ||
return [ | ||
["version", toSerializer(getTransactionVersionCodec())], | ||
["header", toSerializer(getMessageHeaderCodec())], | ||
[ | ||
"staticAccounts", | ||
array(toSerializer(getAddressCodec()), { | ||
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "", | ||
size: shortU16() | ||
}) | ||
], | ||
[ | ||
"lifetimeToken", | ||
string({ | ||
description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "", | ||
encoding: base58, | ||
size: 32 | ||
}) | ||
], | ||
[ | ||
"instructions", | ||
array(getInstructionCodec(), { | ||
description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "", | ||
size: shortU16() | ||
}) | ||
] | ||
]; | ||
} | ||
function getAddressTableLookupsSerializer() { | ||
return array(getAddressTableLookupCodec(), { | ||
...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null, | ||
size: shortU16() | ||
}); | ||
} | ||
function getCompiledMessageEncoder() { | ||
return { | ||
...BASE_CONFIG2, | ||
deserialize: getUnimplementedDecoder("CompiledMessage"), | ||
serialize | ||
}; | ||
} | ||
// src/serializers/transaction.ts | ||
var BASE_CONFIG3 = { | ||
description: __DEV__ ? "The wire format of a Solana transaction" : "", | ||
fixedSize: null, | ||
maxSize: null | ||
}; | ||
function serialize2(transaction) { | ||
const compiledTransaction = getCompiledTransaction(transaction); | ||
return struct([ | ||
[ | ||
"signatures", | ||
array(bytes({ size: 64 }), { | ||
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null, | ||
size: shortU16() | ||
}) | ||
], | ||
["compiledMessage", getCompiledMessageEncoder()] | ||
]).serialize(compiledTransaction); | ||
} | ||
function getTransactionEncoder() { | ||
return { | ||
...BASE_CONFIG3, | ||
deserialize: getUnimplementedDecoder("CompiledMessage"), | ||
serialize: serialize2 | ||
}; | ||
} | ||
function assertIsTransactionSignature(putativeTransactionSignature) { | ||
try { | ||
if ( | ||
// Lowest value (64 bytes of zeroes) | ||
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255) | ||
putativeTransactionSignature.length > 88 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 64."); | ||
} | ||
const bytes3 = base58.serialize(putativeTransactionSignature); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 64) { | ||
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, { | ||
cause: e | ||
}); | ||
} | ||
} | ||
function isTransactionSignature(putativeTransactionSignature) { | ||
if ( | ||
// Lowest value (64 bytes of zeroes) | ||
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255) | ||
putativeTransactionSignature.length > 88 | ||
) { | ||
return false; | ||
} | ||
const bytes3 = base58.serialize(putativeTransactionSignature); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 64) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
async function getCompiledMessageSignature(message, secretKey) { | ||
const wireMessageBytes = getCompiledMessageEncoder().serialize(message); | ||
const signature = await signBytes(secretKey, wireMessageBytes); | ||
return signature; | ||
} | ||
function getSignatureFromTransaction(transaction) { | ||
const signature = transaction.signatures[transaction.feePayer]; | ||
if (!signature) { | ||
throw new Error( | ||
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer." | ||
); | ||
} | ||
return signature; | ||
} | ||
async function signTransaction(keyPairs, transaction) { | ||
const compiledMessage = compileMessage(transaction); | ||
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {}; | ||
const publicKeySignaturePairs = await Promise.all( | ||
keyPairs.map( | ||
(keyPair) => Promise.all([ | ||
getAddressFromPublicKey(keyPair.publicKey), | ||
getCompiledMessageSignature(compiledMessage, keyPair.privateKey) | ||
]) | ||
) | ||
); | ||
for (const [signerPublicKey, signature] of publicKeySignaturePairs) { | ||
nextSignatures[signerPublicKey] = signature; | ||
} | ||
const out = { | ||
...transaction, | ||
signatures: nextSignatures | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
function transactionSignature(putativeTransactionSignature) { | ||
assertIsTransactionSignature(putativeTransactionSignature); | ||
return putativeTransactionSignature; | ||
} | ||
// src/wire-transaction.ts | ||
function getBase64EncodedWireTransaction(transaction) { | ||
const wireTransactionBytes = getTransactionEncoder().serialize(transaction); | ||
{ | ||
return btoa(String.fromCharCode(...wireTransactionBytes)); | ||
} | ||
} | ||
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -0,1 +1,58 @@ | ||
import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers'; | ||
import { getAddressFromPublicKey, getAddressComparator, getAddressCodec } from '@solana/addresses'; | ||
import { getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU8Codec } from '@solana/codecs-numbers'; | ||
import { combineCodec } from '@solana/codecs-core'; | ||
import { signBytes } from '@solana/keys'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/unsigned-transaction.ts | ||
function getUnsignedTransaction(transaction) { | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
return unsignedTransaction; | ||
} else { | ||
return transaction; | ||
} | ||
} | ||
// src/blockhash.ts | ||
function assertIsBlockhash(putativeBlockhash) { | ||
try { | ||
if ( | ||
// Lowest value (32 bytes of zeroes) | ||
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255) | ||
putativeBlockhash.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes3 = base58.serialize(putativeBlockhash); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, { | ||
cause: e | ||
}); | ||
} | ||
} | ||
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) { | ||
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) { | ||
return transaction; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
lifetimeConstraint: blockhashLifetimeConstraint | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
// src/create-transaction.ts | ||
@@ -13,2 +70,84 @@ function createTransaction({ | ||
// ../instructions/dist/index.browser.js | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_WRITABLE_BITMASK = 1; | ||
function isSignerRole(role) { | ||
return role >= 2; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
// src/durable-nonce.ts | ||
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111"; | ||
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111"; | ||
function assertIsDurableNonceTransaction(transaction) { | ||
if (!isDurableNonceTransaction(transaction)) { | ||
throw new Error("Transaction is not a durable nonce transaction"); | ||
} | ||
} | ||
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) { | ||
return { | ||
accounts: [ | ||
{ address: nonceAccountAddress, role: AccountRole.WRITABLE }, | ||
{ | ||
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS, | ||
role: AccountRole.READONLY | ||
}, | ||
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER } | ||
], | ||
data: new Uint8Array([4, 0, 0, 0]), | ||
programAddress: SYSTEM_PROGRAM_ADDRESS | ||
}; | ||
} | ||
function isAdvanceNonceAccountInstruction(instruction) { | ||
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data | ||
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts | ||
instruction.accounts?.length === 3 && // First account is nonce account address | ||
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar | ||
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account | ||
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER; | ||
} | ||
function isAdvanceNonceAccountInstructionData(data) { | ||
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0; | ||
} | ||
function isDurableNonceTransaction(transaction) { | ||
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]); | ||
} | ||
function setTransactionLifetimeUsingDurableNonce({ | ||
nonce, | ||
nonceAccountAddress, | ||
nonceAuthorityAddress | ||
}, transaction) { | ||
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction); | ||
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) { | ||
return transaction; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [ | ||
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress), | ||
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions | ||
], | ||
lifetimeConstraint: { | ||
nonce | ||
} | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
// src/fee-payer.ts | ||
@@ -19,19 +158,6 @@ function setTransactionFeePayer(feePayer, transaction) { | ||
} | ||
let out; | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
out = { | ||
...unsignedTransaction, | ||
feePayer | ||
}; | ||
} else { | ||
out = { | ||
...transaction, | ||
feePayer | ||
}; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
feePayer | ||
}; | ||
Object.freeze(out); | ||
@@ -42,25 +168,7 @@ return out; | ||
// src/instructions.ts | ||
function replaceInstructions(transaction, nextInstructions) { | ||
let out; | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
out = { | ||
...unsignedTransaction, | ||
instructions: nextInstructions | ||
}; | ||
} else { | ||
out = { | ||
...transaction, | ||
instructions: nextInstructions | ||
}; | ||
} | ||
return out; | ||
} | ||
function appendTransactionInstruction(instruction, transaction) { | ||
const nextInstructions = [...transaction.instructions, instruction]; | ||
const out = replaceInstructions(transaction, nextInstructions); | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [...transaction.instructions, instruction] | ||
}; | ||
Object.freeze(out); | ||
@@ -70,10 +178,663 @@ return out; | ||
function prependTransactionInstruction(instruction, transaction) { | ||
const nextInstructions = [instruction, ...transaction.instructions]; | ||
const out = replaceInstructions(transaction, nextInstructions); | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [instruction, ...transaction.instructions] | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
function upsert(addressMap, address, update) { | ||
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY }); | ||
} | ||
var TYPE = Symbol("AddressMapTypeProperty"); | ||
function getAddressMapFromInstructions(feePayer, instructions) { | ||
const addressMap = { | ||
[feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER } | ||
}; | ||
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set(); | ||
for (const instruction of instructions) { | ||
upsert(addressMap, instruction.programAddress, (entry) => { | ||
addressesOfInvokedPrograms.add(instruction.programAddress); | ||
if (TYPE in entry) { | ||
if (isWritableRole(entry.role)) { | ||
switch (entry[TYPE]) { | ||
case 0 /* FEE_PAYER */: | ||
throw new Error( | ||
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.` | ||
); | ||
default: | ||
throw new Error( | ||
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.` | ||
); | ||
} | ||
} | ||
if (entry[TYPE] === 2 /* STATIC */) { | ||
return entry; | ||
} | ||
} | ||
return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY }; | ||
}); | ||
let addressComparator; | ||
if (!instruction.accounts) { | ||
continue; | ||
} | ||
for (const account of instruction.accounts) { | ||
upsert(addressMap, account.address, (entry) => { | ||
const { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
address: _, | ||
...accountMeta | ||
} = account; | ||
if (TYPE in entry) { | ||
switch (entry[TYPE]) { | ||
case 0 /* FEE_PAYER */: | ||
return entry; | ||
case 1 /* LOOKUP_TABLE */: { | ||
const nextRole = mergeRoles(entry.role, accountMeta.role); | ||
if ("lookupTableAddress" in accountMeta) { | ||
const shouldReplaceEntry = ( | ||
// Consider using the new LOOKUP_TABLE if its address is different... | ||
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one. | ||
(addressComparator || (addressComparator = getAddressComparator()))( | ||
accountMeta.lookupTableAddress, | ||
entry.lookupTableAddress | ||
) < 0 | ||
); | ||
if (shouldReplaceEntry) { | ||
return { | ||
[TYPE]: 1 /* LOOKUP_TABLE */, | ||
...accountMeta, | ||
role: nextRole | ||
}; | ||
} | ||
} else if (isSignerRole(accountMeta.role)) { | ||
return { | ||
[TYPE]: 2 /* STATIC */, | ||
role: nextRole | ||
}; | ||
} | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} | ||
case 2 /* STATIC */: { | ||
const nextRole = mergeRoles(entry.role, accountMeta.role); | ||
if ( | ||
// Check to see if this address represents a program that is invoked | ||
// in this transaction. | ||
addressesOfInvokedPrograms.has(account.address) | ||
) { | ||
if (isWritableRole(accountMeta.role)) { | ||
throw new Error( | ||
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.` | ||
); | ||
} | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as | ||
// long as they are not require to sign the transaction. | ||
!isSignerRole(entry.role)) { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 1 /* LOOKUP_TABLE */, | ||
role: nextRole | ||
}; | ||
} else { | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if ("lookupTableAddress" in accountMeta) { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 1 /* LOOKUP_TABLE */ | ||
}; | ||
} else { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 2 /* STATIC */ | ||
}; | ||
} | ||
}); | ||
} | ||
} | ||
return addressMap; | ||
} | ||
function getOrderedAccountsFromAddressMap(addressMap) { | ||
let addressComparator; | ||
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => { | ||
if (leftEntry[TYPE] !== rightEntry[TYPE]) { | ||
if (leftEntry[TYPE] === 0 /* FEE_PAYER */) { | ||
return -1; | ||
} else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) { | ||
return 1; | ||
} else if (leftEntry[TYPE] === 2 /* STATIC */) { | ||
return -1; | ||
} else if (rightEntry[TYPE] === 2 /* STATIC */) { | ||
return 1; | ||
} | ||
} | ||
const leftIsSigner = isSignerRole(leftEntry.role); | ||
if (leftIsSigner !== isSignerRole(rightEntry.role)) { | ||
return leftIsSigner ? -1 : 1; | ||
} | ||
const leftIsWritable = isWritableRole(leftEntry.role); | ||
if (leftIsWritable !== isWritableRole(rightEntry.role)) { | ||
return leftIsWritable ? -1 : 1; | ||
} | ||
addressComparator || (addressComparator = getAddressComparator()); | ||
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) { | ||
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress); | ||
} else { | ||
return addressComparator(leftAddress, rightAddress); | ||
} | ||
}).map(([address, addressMeta]) => ({ | ||
address, | ||
...addressMeta | ||
})); | ||
return orderedAccounts; | ||
} | ||
function getCompiledAddressTableLookups(orderedAccounts) { | ||
var _a; | ||
const index = {}; | ||
for (const account of orderedAccounts) { | ||
if (!("lookupTableAddress" in account)) { | ||
continue; | ||
} | ||
const entry = index[_a = account.lookupTableAddress] || (index[_a] = { | ||
readableIndices: [], | ||
writableIndices: [] | ||
}); | ||
if (account.role === AccountRole.WRITABLE) { | ||
entry.writableIndices.push(account.addressIndex); | ||
} else { | ||
entry.readableIndices.push(account.addressIndex); | ||
} | ||
} | ||
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({ | ||
lookupTableAddress, | ||
...index[lookupTableAddress] | ||
})); | ||
} | ||
export { appendTransactionInstruction, createTransaction, prependTransactionInstruction, setTransactionFeePayer }; | ||
// src/compile-header.ts | ||
function getCompiledMessageHeader(orderedAccounts) { | ||
let numReadonlyNonSignerAccounts = 0; | ||
let numReadonlySignerAccounts = 0; | ||
let numSignerAccounts = 0; | ||
for (const account of orderedAccounts) { | ||
if ("lookupTableAddress" in account) { | ||
break; | ||
} | ||
const accountIsWritable = isWritableRole(account.role); | ||
if (isSignerRole(account.role)) { | ||
numSignerAccounts++; | ||
if (!accountIsWritable) { | ||
numReadonlySignerAccounts++; | ||
} | ||
} else if (!accountIsWritable) { | ||
numReadonlyNonSignerAccounts++; | ||
} | ||
} | ||
return { | ||
numReadonlyNonSignerAccounts, | ||
numReadonlySignerAccounts, | ||
numSignerAccounts | ||
}; | ||
} | ||
// src/compile-instructions.ts | ||
function getAccountIndex(orderedAccounts) { | ||
const out = {}; | ||
for (const [index, account] of orderedAccounts.entries()) { | ||
out[account.address] = index; | ||
} | ||
return out; | ||
} | ||
function getCompiledInstructions(instructions, orderedAccounts) { | ||
const accountIndex = getAccountIndex(orderedAccounts); | ||
return instructions.map(({ accounts, data, programAddress }) => { | ||
return { | ||
programAddressIndex: accountIndex[programAddress], | ||
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null, | ||
...data ? { data } : null | ||
}; | ||
}); | ||
} | ||
// src/compile-lifetime-token.ts | ||
function getCompiledLifetimeToken(lifetimeConstraint) { | ||
if ("nonce" in lifetimeConstraint) { | ||
return lifetimeConstraint.nonce; | ||
} | ||
return lifetimeConstraint.blockhash; | ||
} | ||
// src/compile-static-accounts.ts | ||
function getCompiledStaticAccounts(orderedAccounts) { | ||
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account); | ||
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex); | ||
return orderedStaticAccounts.map(({ address }) => address); | ||
} | ||
// src/message.ts | ||
function compileMessage(transaction) { | ||
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions); | ||
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap); | ||
return { | ||
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null, | ||
header: getCompiledMessageHeader(orderedAccounts), | ||
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts), | ||
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint), | ||
staticAccounts: getCompiledStaticAccounts(orderedAccounts), | ||
version: transaction.version | ||
}; | ||
} | ||
// src/compile-transaction.ts | ||
function getCompiledTransaction(transaction) { | ||
const compiledMessage = compileMessage(transaction); | ||
let signatures; | ||
if ("signatures" in transaction) { | ||
signatures = []; | ||
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) { | ||
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0)); | ||
} | ||
} else { | ||
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0))); | ||
} | ||
return { | ||
compiledMessage, | ||
signatures | ||
}; | ||
} | ||
function addressSerializerCompat(compat) { | ||
const codec = getAddressCodec(); | ||
return { | ||
description: compat?.description ?? codec.description, | ||
deserialize: codec.decode, | ||
fixedSize: codec.fixedSize, | ||
maxSize: codec.maxSize, | ||
serialize: codec.encode | ||
}; | ||
} | ||
function getAddressTableLookupCodec() { | ||
return struct( | ||
[ | ||
[ | ||
"lookupTableAddress", | ||
addressSerializerCompat( | ||
__DEV__ ? { | ||
description: "The address of the address lookup table account from which instruction addresses should be looked up" | ||
} : void 0 | ||
) | ||
], | ||
[ | ||
"writableIndices", | ||
array(u8(), { | ||
...__DEV__ ? { | ||
description: "The indices of the accounts in the lookup table that should be loaded as writeable" | ||
} : null, | ||
size: shortU16() | ||
}) | ||
], | ||
[ | ||
"readableIndices", | ||
array(u8(), { | ||
...__DEV__ ? { | ||
description: "The indices of the accounts in the lookup table that should be loaded as read-only" | ||
} : void 0, | ||
size: shortU16() | ||
}) | ||
] | ||
], | ||
__DEV__ ? { | ||
description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" | ||
} : void 0 | ||
); | ||
} | ||
var memoizedU8Codec; | ||
function getMemoizedU8Codec() { | ||
if (!memoizedU8Codec) | ||
memoizedU8Codec = getU8Codec(); | ||
return memoizedU8Codec; | ||
} | ||
function getMemoizedU8CodecDescription(description) { | ||
const codec = getMemoizedU8Codec(); | ||
return { | ||
...codec, | ||
description: description ?? codec.description | ||
}; | ||
} | ||
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0; | ||
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0; | ||
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0; | ||
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0; | ||
function getMessageHeaderCodec() { | ||
return getStructCodec( | ||
[ | ||
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)], | ||
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)], | ||
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)] | ||
], | ||
{ | ||
description: messageHeaderDescription | ||
} | ||
); | ||
} | ||
function getInstructionCodec() { | ||
return mapSerializer( | ||
struct([ | ||
[ | ||
"programAddressIndex", | ||
u8( | ||
__DEV__ ? { | ||
description: "The index of the program being called, according to the well-ordered accounts list for this transaction" | ||
} : void 0 | ||
) | ||
], | ||
[ | ||
"accountIndices", | ||
array( | ||
u8({ | ||
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : "" | ||
}), | ||
{ | ||
description: __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "", | ||
size: shortU16() | ||
} | ||
) | ||
], | ||
[ | ||
"data", | ||
bytes({ | ||
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "", | ||
size: shortU16() | ||
}) | ||
] | ||
]), | ||
(value) => { | ||
if (value.accountIndices !== void 0 && value.data !== void 0) { | ||
return value; | ||
} | ||
return { | ||
...value, | ||
accountIndices: value.accountIndices ?? [], | ||
data: value.data ?? new Uint8Array(0) | ||
}; | ||
}, | ||
(value) => { | ||
if (value.accountIndices.length && value.data.byteLength) { | ||
return value; | ||
} | ||
const { accountIndices, data, ...rest } = value; | ||
return { | ||
...rest, | ||
...accountIndices.length ? { accountIndices } : null, | ||
...data.byteLength ? { data } : null | ||
}; | ||
} | ||
); | ||
} | ||
var VERSION_FLAG_MASK = 128; | ||
var BASE_CONFIG = { | ||
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "", | ||
fixedSize: null, | ||
maxSize: 1 | ||
}; | ||
function decode(bytes3, offset = 0) { | ||
const firstByte = bytes3[offset]; | ||
if ((firstByte & VERSION_FLAG_MASK) === 0) { | ||
return ["legacy", offset]; | ||
} else { | ||
const version = firstByte ^ VERSION_FLAG_MASK; | ||
return [version, offset + 1]; | ||
} | ||
} | ||
function encode(value) { | ||
if (value === "legacy") { | ||
return new Uint8Array(); | ||
} | ||
if (value < 0 || value > 127) { | ||
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`); | ||
} | ||
return new Uint8Array([value | VERSION_FLAG_MASK]); | ||
} | ||
function getTransactionVersionDecoder() { | ||
return { | ||
...BASE_CONFIG, | ||
decode | ||
}; | ||
} | ||
function getTransactionVersionEncoder() { | ||
return { | ||
...BASE_CONFIG, | ||
encode | ||
}; | ||
} | ||
function getTransactionVersionCodec() { | ||
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder()); | ||
} | ||
// src/serializers/unimplemented.ts | ||
function getError(type, name) { | ||
const functionSuffix = name + type[0].toUpperCase() + type.slice(1); | ||
return new Error( | ||
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}` | ||
); | ||
} | ||
function getUnimplementedDecoder(name) { | ||
return () => { | ||
throw getError("decoder", name); | ||
}; | ||
} | ||
// src/serializers/message.ts | ||
var BASE_CONFIG2 = { | ||
description: __DEV__ ? "The wire format of a Solana transaction message" : "", | ||
fixedSize: null, | ||
maxSize: null | ||
}; | ||
function serialize(compiledMessage) { | ||
if (compiledMessage.version === "legacy") { | ||
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage); | ||
} else { | ||
return mapSerializer( | ||
struct([ | ||
...getPreludeStructSerializerTuple(), | ||
["addressTableLookups", getAddressTableLookupsSerializer()] | ||
]), | ||
(value) => { | ||
if (value.version === "legacy") { | ||
return value; | ||
} | ||
return { | ||
...value, | ||
addressTableLookups: value.addressTableLookups ?? [] | ||
}; | ||
} | ||
).serialize(compiledMessage); | ||
} | ||
} | ||
function toSerializer(codec) { | ||
return { | ||
description: codec.description, | ||
deserialize: codec.decode, | ||
fixedSize: codec.fixedSize, | ||
maxSize: codec.maxSize, | ||
serialize: codec.encode | ||
}; | ||
} | ||
function getPreludeStructSerializerTuple() { | ||
return [ | ||
["version", toSerializer(getTransactionVersionCodec())], | ||
["header", toSerializer(getMessageHeaderCodec())], | ||
[ | ||
"staticAccounts", | ||
array(toSerializer(getAddressCodec()), { | ||
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "", | ||
size: shortU16() | ||
}) | ||
], | ||
[ | ||
"lifetimeToken", | ||
string({ | ||
description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "", | ||
encoding: base58, | ||
size: 32 | ||
}) | ||
], | ||
[ | ||
"instructions", | ||
array(getInstructionCodec(), { | ||
description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "", | ||
size: shortU16() | ||
}) | ||
] | ||
]; | ||
} | ||
function getAddressTableLookupsSerializer() { | ||
return array(getAddressTableLookupCodec(), { | ||
...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null, | ||
size: shortU16() | ||
}); | ||
} | ||
function getCompiledMessageEncoder() { | ||
return { | ||
...BASE_CONFIG2, | ||
deserialize: getUnimplementedDecoder("CompiledMessage"), | ||
serialize | ||
}; | ||
} | ||
// src/serializers/transaction.ts | ||
var BASE_CONFIG3 = { | ||
description: __DEV__ ? "The wire format of a Solana transaction" : "", | ||
fixedSize: null, | ||
maxSize: null | ||
}; | ||
function serialize2(transaction) { | ||
const compiledTransaction = getCompiledTransaction(transaction); | ||
return struct([ | ||
[ | ||
"signatures", | ||
array(bytes({ size: 64 }), { | ||
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null, | ||
size: shortU16() | ||
}) | ||
], | ||
["compiledMessage", getCompiledMessageEncoder()] | ||
]).serialize(compiledTransaction); | ||
} | ||
function getTransactionEncoder() { | ||
return { | ||
...BASE_CONFIG3, | ||
deserialize: getUnimplementedDecoder("CompiledMessage"), | ||
serialize: serialize2 | ||
}; | ||
} | ||
function assertIsTransactionSignature(putativeTransactionSignature) { | ||
try { | ||
if ( | ||
// Lowest value (64 bytes of zeroes) | ||
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255) | ||
putativeTransactionSignature.length > 88 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 64."); | ||
} | ||
const bytes3 = base58.serialize(putativeTransactionSignature); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 64) { | ||
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, { | ||
cause: e | ||
}); | ||
} | ||
} | ||
function isTransactionSignature(putativeTransactionSignature) { | ||
if ( | ||
// Lowest value (64 bytes of zeroes) | ||
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255) | ||
putativeTransactionSignature.length > 88 | ||
) { | ||
return false; | ||
} | ||
const bytes3 = base58.serialize(putativeTransactionSignature); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 64) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
async function getCompiledMessageSignature(message, secretKey) { | ||
const wireMessageBytes = getCompiledMessageEncoder().serialize(message); | ||
const signature = await signBytes(secretKey, wireMessageBytes); | ||
return signature; | ||
} | ||
function getSignatureFromTransaction(transaction) { | ||
const signature = transaction.signatures[transaction.feePayer]; | ||
if (!signature) { | ||
throw new Error( | ||
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer." | ||
); | ||
} | ||
return signature; | ||
} | ||
async function signTransaction(keyPairs, transaction) { | ||
const compiledMessage = compileMessage(transaction); | ||
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {}; | ||
const publicKeySignaturePairs = await Promise.all( | ||
keyPairs.map( | ||
(keyPair) => Promise.all([ | ||
getAddressFromPublicKey(keyPair.publicKey), | ||
getCompiledMessageSignature(compiledMessage, keyPair.privateKey) | ||
]) | ||
) | ||
); | ||
for (const [signerPublicKey, signature] of publicKeySignaturePairs) { | ||
nextSignatures[signerPublicKey] = signature; | ||
} | ||
const out = { | ||
...transaction, | ||
signatures: nextSignatures | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
function transactionSignature(putativeTransactionSignature) { | ||
assertIsTransactionSignature(putativeTransactionSignature); | ||
return putativeTransactionSignature; | ||
} | ||
// src/wire-transaction.ts | ||
function getBase64EncodedWireTransaction(transaction) { | ||
const wireTransactionBytes = getTransactionEncoder().serialize(transaction); | ||
{ | ||
return btoa(String.fromCharCode(...wireTransactionBytes)); | ||
} | ||
} | ||
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -0,1 +1,58 @@ | ||
import { base58, struct, array, bytes, shortU16, mapSerializer, string, u8 } from '@metaplex-foundation/umi-serializers'; | ||
import { getAddressFromPublicKey, getAddressComparator, getAddressCodec } from '@solana/addresses'; | ||
import { getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU8Codec } from '@solana/codecs-numbers'; | ||
import { combineCodec } from '@solana/codecs-core'; | ||
import { signBytes } from '@solana/keys'; | ||
// ../build-scripts/env-shim.ts | ||
var __DEV__ = /* @__PURE__ */ (() => process["env"].NODE_ENV === "development")(); | ||
// src/unsigned-transaction.ts | ||
function getUnsignedTransaction(transaction) { | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
return unsignedTransaction; | ||
} else { | ||
return transaction; | ||
} | ||
} | ||
// src/blockhash.ts | ||
function assertIsBlockhash(putativeBlockhash) { | ||
try { | ||
if ( | ||
// Lowest value (32 bytes of zeroes) | ||
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255) | ||
putativeBlockhash.length > 44 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 32."); | ||
} | ||
const bytes3 = base58.serialize(putativeBlockhash); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 32) { | ||
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, { | ||
cause: e | ||
}); | ||
} | ||
} | ||
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) { | ||
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) { | ||
return transaction; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
lifetimeConstraint: blockhashLifetimeConstraint | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
// src/create-transaction.ts | ||
@@ -13,2 +70,84 @@ function createTransaction({ | ||
// ../instructions/dist/index.node.js | ||
var AccountRole = /* @__PURE__ */ ((AccountRole2) => { | ||
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */ | ||
3] = "WRITABLE_SIGNER"; | ||
AccountRole2[AccountRole2["READONLY_SIGNER"] = /* 2 */ | ||
2] = "READONLY_SIGNER"; | ||
AccountRole2[AccountRole2["WRITABLE"] = /* 1 */ | ||
1] = "WRITABLE"; | ||
AccountRole2[AccountRole2["READONLY"] = /* 0 */ | ||
0] = "READONLY"; | ||
return AccountRole2; | ||
})(AccountRole || {}); | ||
var IS_WRITABLE_BITMASK = 1; | ||
function isSignerRole(role) { | ||
return role >= 2; | ||
} | ||
function isWritableRole(role) { | ||
return (role & IS_WRITABLE_BITMASK) !== 0; | ||
} | ||
function mergeRoles(roleA, roleB) { | ||
return roleA | roleB; | ||
} | ||
// src/durable-nonce.ts | ||
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111"; | ||
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111"; | ||
function assertIsDurableNonceTransaction(transaction) { | ||
if (!isDurableNonceTransaction(transaction)) { | ||
throw new Error("Transaction is not a durable nonce transaction"); | ||
} | ||
} | ||
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) { | ||
return { | ||
accounts: [ | ||
{ address: nonceAccountAddress, role: AccountRole.WRITABLE }, | ||
{ | ||
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS, | ||
role: AccountRole.READONLY | ||
}, | ||
{ address: nonceAuthorityAddress, role: AccountRole.READONLY_SIGNER } | ||
], | ||
data: new Uint8Array([4, 0, 0, 0]), | ||
programAddress: SYSTEM_PROGRAM_ADDRESS | ||
}; | ||
} | ||
function isAdvanceNonceAccountInstruction(instruction) { | ||
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data | ||
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts | ||
instruction.accounts?.length === 3 && // First account is nonce account address | ||
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar | ||
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account | ||
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole.READONLY_SIGNER; | ||
} | ||
function isAdvanceNonceAccountInstructionData(data) { | ||
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0; | ||
} | ||
function isDurableNonceTransaction(transaction) { | ||
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]); | ||
} | ||
function setTransactionLifetimeUsingDurableNonce({ | ||
nonce, | ||
nonceAccountAddress, | ||
nonceAuthorityAddress | ||
}, transaction) { | ||
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction); | ||
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) { | ||
return transaction; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [ | ||
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress), | ||
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions | ||
], | ||
lifetimeConstraint: { | ||
nonce | ||
} | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
// src/fee-payer.ts | ||
@@ -19,19 +158,6 @@ function setTransactionFeePayer(feePayer, transaction) { | ||
} | ||
let out; | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
out = { | ||
...unsignedTransaction, | ||
feePayer | ||
}; | ||
} else { | ||
out = { | ||
...transaction, | ||
feePayer | ||
}; | ||
} | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
feePayer | ||
}; | ||
Object.freeze(out); | ||
@@ -42,25 +168,7 @@ return out; | ||
// src/instructions.ts | ||
function replaceInstructions(transaction, nextInstructions) { | ||
let out; | ||
if ("signatures" in transaction) { | ||
const { | ||
signatures: _, | ||
// eslint-disable-line @typescript-eslint/no-unused-vars | ||
...unsignedTransaction | ||
} = transaction; | ||
out = { | ||
...unsignedTransaction, | ||
instructions: nextInstructions | ||
}; | ||
} else { | ||
out = { | ||
...transaction, | ||
instructions: nextInstructions | ||
}; | ||
} | ||
return out; | ||
} | ||
function appendTransactionInstruction(instruction, transaction) { | ||
const nextInstructions = [...transaction.instructions, instruction]; | ||
const out = replaceInstructions(transaction, nextInstructions); | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [...transaction.instructions, instruction] | ||
}; | ||
Object.freeze(out); | ||
@@ -70,10 +178,663 @@ return out; | ||
function prependTransactionInstruction(instruction, transaction) { | ||
const nextInstructions = [instruction, ...transaction.instructions]; | ||
const out = replaceInstructions(transaction, nextInstructions); | ||
const out = { | ||
...getUnsignedTransaction(transaction), | ||
instructions: [instruction, ...transaction.instructions] | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
function upsert(addressMap, address, update) { | ||
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY }); | ||
} | ||
var TYPE = Symbol("AddressMapTypeProperty"); | ||
function getAddressMapFromInstructions(feePayer, instructions) { | ||
const addressMap = { | ||
[feePayer]: { [TYPE]: 0 /* FEE_PAYER */, role: AccountRole.WRITABLE_SIGNER } | ||
}; | ||
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set(); | ||
for (const instruction of instructions) { | ||
upsert(addressMap, instruction.programAddress, (entry) => { | ||
addressesOfInvokedPrograms.add(instruction.programAddress); | ||
if (TYPE in entry) { | ||
if (isWritableRole(entry.role)) { | ||
switch (entry[TYPE]) { | ||
case 0 /* FEE_PAYER */: | ||
throw new Error( | ||
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.` | ||
); | ||
default: | ||
throw new Error( | ||
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.` | ||
); | ||
} | ||
} | ||
if (entry[TYPE] === 2 /* STATIC */) { | ||
return entry; | ||
} | ||
} | ||
return { [TYPE]: 2 /* STATIC */, role: AccountRole.READONLY }; | ||
}); | ||
let addressComparator; | ||
if (!instruction.accounts) { | ||
continue; | ||
} | ||
for (const account of instruction.accounts) { | ||
upsert(addressMap, account.address, (entry) => { | ||
const { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
address: _, | ||
...accountMeta | ||
} = account; | ||
if (TYPE in entry) { | ||
switch (entry[TYPE]) { | ||
case 0 /* FEE_PAYER */: | ||
return entry; | ||
case 1 /* LOOKUP_TABLE */: { | ||
const nextRole = mergeRoles(entry.role, accountMeta.role); | ||
if ("lookupTableAddress" in accountMeta) { | ||
const shouldReplaceEntry = ( | ||
// Consider using the new LOOKUP_TABLE if its address is different... | ||
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one. | ||
(addressComparator || (addressComparator = getAddressComparator()))( | ||
accountMeta.lookupTableAddress, | ||
entry.lookupTableAddress | ||
) < 0 | ||
); | ||
if (shouldReplaceEntry) { | ||
return { | ||
[TYPE]: 1 /* LOOKUP_TABLE */, | ||
...accountMeta, | ||
role: nextRole | ||
}; | ||
} | ||
} else if (isSignerRole(accountMeta.role)) { | ||
return { | ||
[TYPE]: 2 /* STATIC */, | ||
role: nextRole | ||
}; | ||
} | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} | ||
case 2 /* STATIC */: { | ||
const nextRole = mergeRoles(entry.role, accountMeta.role); | ||
if ( | ||
// Check to see if this address represents a program that is invoked | ||
// in this transaction. | ||
addressesOfInvokedPrograms.has(account.address) | ||
) { | ||
if (isWritableRole(accountMeta.role)) { | ||
throw new Error( | ||
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.` | ||
); | ||
} | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as | ||
// long as they are not require to sign the transaction. | ||
!isSignerRole(entry.role)) { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 1 /* LOOKUP_TABLE */, | ||
role: nextRole | ||
}; | ||
} else { | ||
if (entry.role !== nextRole) { | ||
return { | ||
...entry, | ||
role: nextRole | ||
}; | ||
} else { | ||
return entry; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if ("lookupTableAddress" in accountMeta) { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 1 /* LOOKUP_TABLE */ | ||
}; | ||
} else { | ||
return { | ||
...accountMeta, | ||
[TYPE]: 2 /* STATIC */ | ||
}; | ||
} | ||
}); | ||
} | ||
} | ||
return addressMap; | ||
} | ||
function getOrderedAccountsFromAddressMap(addressMap) { | ||
let addressComparator; | ||
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => { | ||
if (leftEntry[TYPE] !== rightEntry[TYPE]) { | ||
if (leftEntry[TYPE] === 0 /* FEE_PAYER */) { | ||
return -1; | ||
} else if (rightEntry[TYPE] === 0 /* FEE_PAYER */) { | ||
return 1; | ||
} else if (leftEntry[TYPE] === 2 /* STATIC */) { | ||
return -1; | ||
} else if (rightEntry[TYPE] === 2 /* STATIC */) { | ||
return 1; | ||
} | ||
} | ||
const leftIsSigner = isSignerRole(leftEntry.role); | ||
if (leftIsSigner !== isSignerRole(rightEntry.role)) { | ||
return leftIsSigner ? -1 : 1; | ||
} | ||
const leftIsWritable = isWritableRole(leftEntry.role); | ||
if (leftIsWritable !== isWritableRole(rightEntry.role)) { | ||
return leftIsWritable ? -1 : 1; | ||
} | ||
addressComparator || (addressComparator = getAddressComparator()); | ||
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) { | ||
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress); | ||
} else { | ||
return addressComparator(leftAddress, rightAddress); | ||
} | ||
}).map(([address, addressMeta]) => ({ | ||
address, | ||
...addressMeta | ||
})); | ||
return orderedAccounts; | ||
} | ||
function getCompiledAddressTableLookups(orderedAccounts) { | ||
var _a; | ||
const index = {}; | ||
for (const account of orderedAccounts) { | ||
if (!("lookupTableAddress" in account)) { | ||
continue; | ||
} | ||
const entry = index[_a = account.lookupTableAddress] || (index[_a] = { | ||
readableIndices: [], | ||
writableIndices: [] | ||
}); | ||
if (account.role === AccountRole.WRITABLE) { | ||
entry.writableIndices.push(account.addressIndex); | ||
} else { | ||
entry.readableIndices.push(account.addressIndex); | ||
} | ||
} | ||
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({ | ||
lookupTableAddress, | ||
...index[lookupTableAddress] | ||
})); | ||
} | ||
export { appendTransactionInstruction, createTransaction, prependTransactionInstruction, setTransactionFeePayer }; | ||
// src/compile-header.ts | ||
function getCompiledMessageHeader(orderedAccounts) { | ||
let numReadonlyNonSignerAccounts = 0; | ||
let numReadonlySignerAccounts = 0; | ||
let numSignerAccounts = 0; | ||
for (const account of orderedAccounts) { | ||
if ("lookupTableAddress" in account) { | ||
break; | ||
} | ||
const accountIsWritable = isWritableRole(account.role); | ||
if (isSignerRole(account.role)) { | ||
numSignerAccounts++; | ||
if (!accountIsWritable) { | ||
numReadonlySignerAccounts++; | ||
} | ||
} else if (!accountIsWritable) { | ||
numReadonlyNonSignerAccounts++; | ||
} | ||
} | ||
return { | ||
numReadonlyNonSignerAccounts, | ||
numReadonlySignerAccounts, | ||
numSignerAccounts | ||
}; | ||
} | ||
// src/compile-instructions.ts | ||
function getAccountIndex(orderedAccounts) { | ||
const out = {}; | ||
for (const [index, account] of orderedAccounts.entries()) { | ||
out[account.address] = index; | ||
} | ||
return out; | ||
} | ||
function getCompiledInstructions(instructions, orderedAccounts) { | ||
const accountIndex = getAccountIndex(orderedAccounts); | ||
return instructions.map(({ accounts, data, programAddress }) => { | ||
return { | ||
programAddressIndex: accountIndex[programAddress], | ||
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null, | ||
...data ? { data } : null | ||
}; | ||
}); | ||
} | ||
// src/compile-lifetime-token.ts | ||
function getCompiledLifetimeToken(lifetimeConstraint) { | ||
if ("nonce" in lifetimeConstraint) { | ||
return lifetimeConstraint.nonce; | ||
} | ||
return lifetimeConstraint.blockhash; | ||
} | ||
// src/compile-static-accounts.ts | ||
function getCompiledStaticAccounts(orderedAccounts) { | ||
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account); | ||
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex); | ||
return orderedStaticAccounts.map(({ address }) => address); | ||
} | ||
// src/message.ts | ||
function compileMessage(transaction) { | ||
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions); | ||
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap); | ||
return { | ||
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null, | ||
header: getCompiledMessageHeader(orderedAccounts), | ||
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts), | ||
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint), | ||
staticAccounts: getCompiledStaticAccounts(orderedAccounts), | ||
version: transaction.version | ||
}; | ||
} | ||
// src/compile-transaction.ts | ||
function getCompiledTransaction(transaction) { | ||
const compiledMessage = compileMessage(transaction); | ||
let signatures; | ||
if ("signatures" in transaction) { | ||
signatures = []; | ||
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) { | ||
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0)); | ||
} | ||
} else { | ||
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0))); | ||
} | ||
return { | ||
compiledMessage, | ||
signatures | ||
}; | ||
} | ||
function addressSerializerCompat(compat) { | ||
const codec = getAddressCodec(); | ||
return { | ||
description: compat?.description ?? codec.description, | ||
deserialize: codec.decode, | ||
fixedSize: codec.fixedSize, | ||
maxSize: codec.maxSize, | ||
serialize: codec.encode | ||
}; | ||
} | ||
function getAddressTableLookupCodec() { | ||
return struct( | ||
[ | ||
[ | ||
"lookupTableAddress", | ||
addressSerializerCompat( | ||
__DEV__ ? { | ||
description: "The address of the address lookup table account from which instruction addresses should be looked up" | ||
} : void 0 | ||
) | ||
], | ||
[ | ||
"writableIndices", | ||
array(u8(), { | ||
...__DEV__ ? { | ||
description: "The indices of the accounts in the lookup table that should be loaded as writeable" | ||
} : null, | ||
size: shortU16() | ||
}) | ||
], | ||
[ | ||
"readableIndices", | ||
array(u8(), { | ||
...__DEV__ ? { | ||
description: "The indices of the accounts in the lookup table that should be loaded as read-only" | ||
} : void 0, | ||
size: shortU16() | ||
}) | ||
] | ||
], | ||
__DEV__ ? { | ||
description: "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" | ||
} : void 0 | ||
); | ||
} | ||
var memoizedU8Codec; | ||
function getMemoizedU8Codec() { | ||
if (!memoizedU8Codec) | ||
memoizedU8Codec = getU8Codec(); | ||
return memoizedU8Codec; | ||
} | ||
function getMemoizedU8CodecDescription(description) { | ||
const codec = getMemoizedU8Codec(); | ||
return { | ||
...codec, | ||
description: description ?? codec.description | ||
}; | ||
} | ||
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0; | ||
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0; | ||
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0; | ||
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0; | ||
function getMessageHeaderCodec() { | ||
return getStructCodec( | ||
[ | ||
["numSignerAccounts", getMemoizedU8CodecDescription(numSignerAccountsDescription)], | ||
["numReadonlySignerAccounts", getMemoizedU8CodecDescription(numReadonlySignerAccountsDescription)], | ||
["numReadonlyNonSignerAccounts", getMemoizedU8CodecDescription(numReadonlyNonSignerAccountsDescription)] | ||
], | ||
{ | ||
description: messageHeaderDescription | ||
} | ||
); | ||
} | ||
function getInstructionCodec() { | ||
return mapSerializer( | ||
struct([ | ||
[ | ||
"programAddressIndex", | ||
u8( | ||
__DEV__ ? { | ||
description: "The index of the program being called, according to the well-ordered accounts list for this transaction" | ||
} : void 0 | ||
) | ||
], | ||
[ | ||
"accountIndices", | ||
array( | ||
u8({ | ||
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : "" | ||
}), | ||
{ | ||
description: __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "", | ||
size: shortU16() | ||
} | ||
) | ||
], | ||
[ | ||
"data", | ||
bytes({ | ||
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "", | ||
size: shortU16() | ||
}) | ||
] | ||
]), | ||
(value) => { | ||
if (value.accountIndices !== void 0 && value.data !== void 0) { | ||
return value; | ||
} | ||
return { | ||
...value, | ||
accountIndices: value.accountIndices ?? [], | ||
data: value.data ?? new Uint8Array(0) | ||
}; | ||
}, | ||
(value) => { | ||
if (value.accountIndices.length && value.data.byteLength) { | ||
return value; | ||
} | ||
const { accountIndices, data, ...rest } = value; | ||
return { | ||
...rest, | ||
...accountIndices.length ? { accountIndices } : null, | ||
...data.byteLength ? { data } : null | ||
}; | ||
} | ||
); | ||
} | ||
var VERSION_FLAG_MASK = 128; | ||
var BASE_CONFIG = { | ||
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "", | ||
fixedSize: null, | ||
maxSize: 1 | ||
}; | ||
function decode(bytes3, offset = 0) { | ||
const firstByte = bytes3[offset]; | ||
if ((firstByte & VERSION_FLAG_MASK) === 0) { | ||
return ["legacy", offset]; | ||
} else { | ||
const version = firstByte ^ VERSION_FLAG_MASK; | ||
return [version, offset + 1]; | ||
} | ||
} | ||
function encode(value) { | ||
if (value === "legacy") { | ||
return new Uint8Array(); | ||
} | ||
if (value < 0 || value > 127) { | ||
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`); | ||
} | ||
return new Uint8Array([value | VERSION_FLAG_MASK]); | ||
} | ||
function getTransactionVersionDecoder() { | ||
return { | ||
...BASE_CONFIG, | ||
decode | ||
}; | ||
} | ||
function getTransactionVersionEncoder() { | ||
return { | ||
...BASE_CONFIG, | ||
encode | ||
}; | ||
} | ||
function getTransactionVersionCodec() { | ||
return combineCodec(getTransactionVersionEncoder(), getTransactionVersionDecoder()); | ||
} | ||
// src/serializers/unimplemented.ts | ||
function getError(type, name) { | ||
const functionSuffix = name + type[0].toUpperCase() + type.slice(1); | ||
return new Error( | ||
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}` | ||
); | ||
} | ||
function getUnimplementedDecoder(name) { | ||
return () => { | ||
throw getError("decoder", name); | ||
}; | ||
} | ||
// src/serializers/message.ts | ||
var BASE_CONFIG2 = { | ||
description: __DEV__ ? "The wire format of a Solana transaction message" : "", | ||
fixedSize: null, | ||
maxSize: null | ||
}; | ||
function serialize(compiledMessage) { | ||
if (compiledMessage.version === "legacy") { | ||
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage); | ||
} else { | ||
return mapSerializer( | ||
struct([ | ||
...getPreludeStructSerializerTuple(), | ||
["addressTableLookups", getAddressTableLookupsSerializer()] | ||
]), | ||
(value) => { | ||
if (value.version === "legacy") { | ||
return value; | ||
} | ||
return { | ||
...value, | ||
addressTableLookups: value.addressTableLookups ?? [] | ||
}; | ||
} | ||
).serialize(compiledMessage); | ||
} | ||
} | ||
function toSerializer(codec) { | ||
return { | ||
description: codec.description, | ||
deserialize: codec.decode, | ||
fixedSize: codec.fixedSize, | ||
maxSize: codec.maxSize, | ||
serialize: codec.encode | ||
}; | ||
} | ||
function getPreludeStructSerializerTuple() { | ||
return [ | ||
["version", toSerializer(getTransactionVersionCodec())], | ||
["header", toSerializer(getMessageHeaderCodec())], | ||
[ | ||
"staticAccounts", | ||
array(toSerializer(getAddressCodec()), { | ||
description: __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "", | ||
size: shortU16() | ||
}) | ||
], | ||
[ | ||
"lifetimeToken", | ||
string({ | ||
description: __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "", | ||
encoding: base58, | ||
size: 32 | ||
}) | ||
], | ||
[ | ||
"instructions", | ||
array(getInstructionCodec(), { | ||
description: __DEV__ ? "A compact-array of instructions belonging to this transaction" : "", | ||
size: shortU16() | ||
}) | ||
] | ||
]; | ||
} | ||
function getAddressTableLookupsSerializer() { | ||
return array(getAddressTableLookupCodec(), { | ||
...__DEV__ ? { description: "A compact array of address table lookups belonging to this transaction" } : null, | ||
size: shortU16() | ||
}); | ||
} | ||
function getCompiledMessageEncoder() { | ||
return { | ||
...BASE_CONFIG2, | ||
deserialize: getUnimplementedDecoder("CompiledMessage"), | ||
serialize | ||
}; | ||
} | ||
// src/serializers/transaction.ts | ||
var BASE_CONFIG3 = { | ||
description: __DEV__ ? "The wire format of a Solana transaction" : "", | ||
fixedSize: null, | ||
maxSize: null | ||
}; | ||
function serialize2(transaction) { | ||
const compiledTransaction = getCompiledTransaction(transaction); | ||
return struct([ | ||
[ | ||
"signatures", | ||
array(bytes({ size: 64 }), { | ||
...__DEV__ ? { description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } : null, | ||
size: shortU16() | ||
}) | ||
], | ||
["compiledMessage", getCompiledMessageEncoder()] | ||
]).serialize(compiledTransaction); | ||
} | ||
function getTransactionEncoder() { | ||
return { | ||
...BASE_CONFIG3, | ||
deserialize: getUnimplementedDecoder("CompiledMessage"), | ||
serialize: serialize2 | ||
}; | ||
} | ||
function assertIsTransactionSignature(putativeTransactionSignature) { | ||
try { | ||
if ( | ||
// Lowest value (64 bytes of zeroes) | ||
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255) | ||
putativeTransactionSignature.length > 88 | ||
) { | ||
throw new Error("Expected input string to decode to a byte array of length 64."); | ||
} | ||
const bytes3 = base58.serialize(putativeTransactionSignature); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 64) { | ||
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`); | ||
} | ||
} catch (e) { | ||
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, { | ||
cause: e | ||
}); | ||
} | ||
} | ||
function isTransactionSignature(putativeTransactionSignature) { | ||
if ( | ||
// Lowest value (64 bytes of zeroes) | ||
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255) | ||
putativeTransactionSignature.length > 88 | ||
) { | ||
return false; | ||
} | ||
const bytes3 = base58.serialize(putativeTransactionSignature); | ||
const numBytes = bytes3.byteLength; | ||
if (numBytes !== 64) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
async function getCompiledMessageSignature(message, secretKey) { | ||
const wireMessageBytes = getCompiledMessageEncoder().serialize(message); | ||
const signature = await signBytes(secretKey, wireMessageBytes); | ||
return signature; | ||
} | ||
function getSignatureFromTransaction(transaction) { | ||
const signature = transaction.signatures[transaction.feePayer]; | ||
if (!signature) { | ||
throw new Error( | ||
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer." | ||
); | ||
} | ||
return signature; | ||
} | ||
async function signTransaction(keyPairs, transaction) { | ||
const compiledMessage = compileMessage(transaction); | ||
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {}; | ||
const publicKeySignaturePairs = await Promise.all( | ||
keyPairs.map( | ||
(keyPair) => Promise.all([ | ||
getAddressFromPublicKey(keyPair.publicKey), | ||
getCompiledMessageSignature(compiledMessage, keyPair.privateKey) | ||
]) | ||
) | ||
); | ||
for (const [signerPublicKey, signature] of publicKeySignaturePairs) { | ||
nextSignatures[signerPublicKey] = signature; | ||
} | ||
const out = { | ||
...transaction, | ||
signatures: nextSignatures | ||
}; | ||
Object.freeze(out); | ||
return out; | ||
} | ||
function transactionSignature(putativeTransactionSignature) { | ||
assertIsTransactionSignature(putativeTransactionSignature); | ||
return putativeTransactionSignature; | ||
} | ||
// src/wire-transaction.ts | ||
function getBase64EncodedWireTransaction(transaction) { | ||
const wireTransactionBytes = getTransactionEncoder().serialize(transaction); | ||
{ | ||
return Buffer.from(wireTransactionBytes).toString("base64"); | ||
} | ||
} | ||
export { appendTransactionInstruction, assertIsBlockhash, assertIsDurableNonceTransaction, assertIsTransactionSignature, createTransaction, getBase64EncodedWireTransaction, getSignatureFromTransaction, getTransactionEncoder, isTransactionSignature, prependTransactionInstruction, setTransactionFeePayer, setTransactionLifetimeUsingBlockhash, setTransactionLifetimeUsingDurableNonce, signTransaction, transactionSignature }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -5,8 +5,19 @@ this.globalThis = this.globalThis || {}; | ||
function T({version:r}){let n={instructions:[],version:r};return Object.freeze(n),n}function d(r,n){if("feePayer"in n&&r===n.feePayer)return n;let t;if("signatures"in n){let{signatures:e,...s}=n;t={...s,feePayer:r};}else t={...n,feePayer:r};return Object.freeze(t),t}function i(r,n){let t;if("signatures"in r){let{signatures:e,...s}=r;t={...s,instructions:n};}else t={...r,instructions:n};return t}function m(r,n){let t=[...n.instructions,r],e=i(n,t);return Object.freeze(e),e}function x(r,n){let t=[r,...n.instructions],e=i(n,t);return Object.freeze(e),e} | ||
var dr=Object.defineProperty;var ur=(e,r,n)=>r in e?dr(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var y=(e,r,n)=>(ur(e,typeof r!="symbol"?r+"":r,n),n);var S=e=>{let r=e.reduce((o,i)=>o+i.length,0),n=new Uint8Array(r),t=0;return e.forEach(o=>{n.set(o,t),t+=o.length;}),n},le=(e,r)=>{if(e.length>=r)return e;let n=new Uint8Array(r).fill(0);return n.set(e),n},L=(e,r)=>le(e.slice(0,r),r);var b=class extends Error{constructor(n){super(`Serializer [${n}] cannot deserialize empty buffers.`);y(this,"name","DeserializingEmptyBufferError");}},x=class extends Error{constructor(n,t,o){super(`Serializer [${n}] expected ${t} bytes, got ${o}.`);y(this,"name","NotEnoughBytesError");}},I=class extends Error{constructor(n){n??(n="Expected a fixed-size serializer, got a variable-size one.");super(n);y(this,"name","ExpectedFixedSizeSerializerError");}};function _(e,r,n){return {description:n??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r,serialize:t=>L(e.serialize(t),r),deserialize:(t,o=0)=>{if(t=t.slice(o,o+r),t.length<r)throw new x("fixSerializer",r,t.length);e.fixedSize!==null&&(t=L(t,e.fixedSize));let[i]=e.deserialize(t,0);return [i,o+r]}}}function k(e,r,n){return {description:e.description,fixedSize:e.fixedSize,maxSize:e.maxSize,serialize:t=>e.serialize(r(t)),deserialize:(t,o=0)=>{let[i,s]=e.deserialize(t,o);return n?[n(i,t,o),s]:[i,s]}}}var M=class extends Error{constructor(n,t,o){let i=`Expected a string of base ${t}, got [${n}].`;super(i);y(this,"name","InvalidBaseStringError");this.cause=o;}};var fe=e=>{let r=e.length,n=BigInt(r);return {description:`base${r}`,fixedSize:null,maxSize:null,serialize(t){if(!t.match(new RegExp(`^[${e}]*$`)))throw new M(t,r);if(t==="")return new Uint8Array;let o=[...t],i=o.findIndex(f=>f!==e[0]);i=i===-1?o.length:i;let s=Array(i).fill(0);if(i===o.length)return Uint8Array.from(s);let c=o.slice(i),u=0n,d=1n;for(let f=c.length-1;f>=0;f-=1)u+=d*BigInt(e.indexOf(c[f])),d*=n;let l=[];for(;u>0n;)l.unshift(Number(u%256n)),u/=256n;return Uint8Array.from(s.concat(l))},deserialize(t,o=0){if(t.length===0)return ["",0];let i=t.slice(o),s=i.findIndex(l=>l!==0);s=s===-1?i.length:s;let c=e[0].repeat(s);if(s===i.length)return [c,t.length];let u=i.slice(s).reduce((l,f)=>l*256n+BigInt(f),0n),d=[];for(;u>0n;)d.unshift(e[Number(u%n)]),u/=n;return [c+d.join(""),t.length]}}};var E=fe("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var me=e=>e.replace(/\u0000/g,"");var Z={description:"utf8",fixedSize:null,maxSize:null,serialize(e){return new TextEncoder().encode(e)},deserialize(e,r=0){let n=new TextDecoder().decode(e.slice(r));return [me(n),e.length]}};var P;(function(e){e.Little="le",e.Big="be";})(P||(P={}));var V=class extends RangeError{constructor(n,t,o,i){super(`Serializer [${n}] expected number to be between ${t} and ${o}, got ${i}.`);y(this,"name","NumberOutOfRangeError");}};function F(e){let r,n=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===P.Little,n+=r?"(le)":"(be)"),{description:e.options.description??n,fixedSize:e.size,maxSize:e.size,serialize(t){e.range&&J(e.name,e.range[0],e.range[1],t);let o=new ArrayBuffer(e.size);return e.set(new DataView(o),t,r),new Uint8Array(o)},deserialize(t,o=0){let i=t.slice(o,o+e.size);mr("i8",i,e.size);let s=fr(i);return [e.get(s,r),o+e.size]}}}var lr=e=>e.buffer.slice(e.byteOffset,e.byteLength+e.byteOffset),fr=e=>new DataView(lr(e)),J=(e,r,n,t)=>{if(t<r||t>n)throw new V(e,r,n,t)},mr=(e,r,n)=>{if(r.length===0)throw new b(e);if(r.length<n)throw new x(e,n,r.length)};var w=(e={})=>F({name:"u8",size:1,range:[0,+"0xff"],set:(r,n)=>r.setUint8(0,Number(n)),get:r=>r.getUint8(0),options:e});var R=(e={})=>F({name:"u32",size:4,range:[0,+"0xffffffff"],set:(r,n,t)=>r.setUint32(0,Number(n),t),get:(r,n)=>r.getUint32(0,n),options:e});var p=(e={})=>({description:e.description??"shortU16",fixedSize:null,maxSize:3,serialize:r=>{J("shortU16",0,65535,r);let n=[0];for(let t=0;;t+=1){let o=r>>t*7;if(o===0)break;let i=127&o;n[t]=i,t>0&&(n[t-1]|=128);}return new Uint8Array(n)},deserialize:(r,n=0)=>{let t=0,o=0;for(;++o;){let i=o-1,s=r[n+i],c=127&s;if(t|=c<<i*7,!(s&128))break}return [t,n+o]}});var W=class extends Error{constructor(n,t,o){super(`Expected [${n}] to have ${t} items, got ${o}.`);y(this,"name","InvalidNumberOfItemsError");}},H=class extends Error{constructor(n,t){super(`The remainder of the buffer (${n} bytes) cannot be split into chunks of ${t} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${n} modulo ${t} should be equal to zero.`);y(this,"name","InvalidArrayLikeRemainderSizeError");}},j=class extends Error{constructor(n){super(`Unrecognized array-like serializer size: ${JSON.stringify(n)}`);y(this,"name","UnrecognizedArrayLikeSerializerSizeError");}};function v(e){return e.reduce((r,n)=>r===null||n===null?null:r+n,0)}function ge(e,r,n,t){if(typeof e=="number")return [e,t];if(typeof e=="object")return e.deserialize(n,t);if(e==="remainder"){let o=v(r);if(o===null)throw new I('Serializers of "remainder" size must have fixed-size items.');let i=n.slice(t).length;if(i%o!==0)throw new H(i,o);return [i/o,t]}throw new j(e)}function D(e){return typeof e=="object"?e.description:`${e}`}function Q(e,r){if(typeof e!="number")return null;if(e===0)return 0;let n=v(r);return n===null?null:n*e}function pe(e,r){return typeof e=="object"?e.serialize(r):new Uint8Array}function h(e,r={}){let n=r.size??R();if(n==="remainder"&&e.fixedSize===null)throw new I('Serializers of "remainder" size must have fixed-size items.');return {description:r.description??`array(${e.description}; ${D(n)})`,fixedSize:Q(n,[e.fixedSize]),maxSize:Q(n,[e.maxSize]),serialize:t=>{if(typeof n=="number"&&t.length!==n)throw new W("array",n,t.length);return S([pe(n,t.length),...t.map(o=>e.serialize(o))])},deserialize:(t,o=0)=>{if(typeof n=="object"&&t.slice(o).length===0)return [[],o];let[i,s]=ge(n,[e.fixedSize],t,o);o=s;let c=[];for(let u=0;u<i;u+=1){let[d,l]=e.deserialize(t,o);c.push(d),o=l;}return [c,o]}}}function U(e={}){let r=e.size??"variable",n=e.description??`bytes(${D(r)})`,t={description:n,fixedSize:null,maxSize:null,serialize:o=>new Uint8Array(o),deserialize:(o,i=0)=>{let s=o.slice(i);return [s,i+s.length]}};return r==="variable"?t:typeof r=="number"?_(t,r,n):{description:n,fixedSize:null,maxSize:null,serialize:o=>{let i=t.serialize(o),s=r.serialize(i.length);return S([s,i])},deserialize:(o,i=0)=>{if(o.slice(i).length===0)throw new b("bytes");let[s,c]=r.deserialize(o,i),u=Number(s);i=c;let d=o.slice(i,i+u);if(d.length<u)throw new x("bytes",u,d.length);let[l,f]=t.deserialize(d);return i+=f,[l,i]}}}function ee(e={}){let r=e.size??R(),n=e.encoding??Z,t=e.description??`string(${n.description}; ${D(r)})`;return r==="variable"?{...n,description:t}:typeof r=="number"?_(n,r,t):{description:t,fixedSize:null,maxSize:null,serialize:o=>{let i=n.serialize(o),s=r.serialize(i.length);return S([s,i])},deserialize:(o,i=0)=>{if(o.slice(i).length===0)throw new b("string");let[s,c]=r.deserialize(o,i),u=Number(s);i=c;let d=o.slice(i,i+u);if(d.length<u)throw new x("string",u,d.length);let[l,f]=n.deserialize(d);return i+=f,[l,i]}}}function T(e,r={}){let n=e.map(([t,o])=>`${String(t)}: ${o.description}`).join(", ");return {description:r.description??`struct(${n})`,fixedSize:v(e.map(([,t])=>t.fixedSize)),maxSize:v(e.map(([,t])=>t.maxSize)),serialize:t=>{let o=e.map(([i,s])=>s.serialize(t[i]));return S(o)},deserialize:(t,o=0)=>{let i={};return e.forEach(([s,c])=>{let[u,d]=c.deserialize(t,o);o=d,i[s]=u;}),[i,o]}}}function A(e){if("signatures"in e){let{signatures:r,...n}=e;return n}else return e}function qt(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let n=E.serialize(e).byteLength;if(n!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${n}`)}catch(r){throw new Error(`\`${e}\` is not a blockhash`,{cause:r})}}function Xt(e,r){if("lifetimeConstraint"in r&&r.lifetimeConstraint.blockhash===e.blockhash&&r.lifetimeConstraint.lastValidBlockHeight===e.lastValidBlockHeight)return r;let n={...A(r),lifetimeConstraint:e};return Object.freeze(n),n}function Qt({version:e}){let r={instructions:[],version:e};return Object.freeze(r),r}var g=(e=>(e[e.WRITABLE_SIGNER=3]="WRITABLE_SIGNER",e[e.READONLY_SIGNER=2]="READONLY_SIGNER",e[e.WRITABLE=1]="WRITABLE",e[e.READONLY=0]="READONLY",e))(g||{});var gr=1;function B(e){return e>=2}function C(e){return (e&gr)!==0}function re(e,r){return e|r}var ye="SysvarRecentB1ockHashes11111111111111111111",he="11111111111111111111111111111111";function uo(e){if(!xe(e))throw new Error("Transaction is not a durable nonce transaction")}function pr(e,r){return {accounts:[{address:e,role:g.WRITABLE},{address:ye,role:g.READONLY},{address:r,role:g.READONLY_SIGNER}],data:new Uint8Array([4,0,0,0]),programAddress:he}}function yr(e){return e.programAddress===he&&e.data!=null&&hr(e.data)&&e.accounts?.length===3&&e.accounts[0].address!=null&&e.accounts[0].role===g.WRITABLE&&e.accounts[1].address===ye&&e.accounts[1].role===g.READONLY&&e.accounts[2].address!=null&&e.accounts[2].role===g.READONLY_SIGNER}function hr(e){return e.byteLength===4&&e[0]===4&&e[1]===0&&e[2]===0&&e[3]===0}function xe(e){return "lifetimeConstraint"in e&&typeof e.lifetimeConstraint.nonce=="string"&&e.instructions[0]!=null&&yr(e.instructions[0])}function lo({nonce:e,nonceAccountAddress:r,nonceAuthorityAddress:n},t){let o=xe(t);if(o&&t.lifetimeConstraint.nonce===e&&t.instructions[0].accounts[0].address===r&&t.instructions[0].accounts[2].address===n)return t;let i={...A(t),instructions:[pr(r,n),...o?t.instructions.slice(1):t.instructions],lifetimeConstraint:{nonce:e}};return Object.freeze(i),i}function po(e,r){if("feePayer"in r&&e===r.feePayer)return r;let n={...A(r),feePayer:e};return Object.freeze(n),n}function To(e,r){let n={...A(r),instructions:[...r.instructions,e]};return Object.freeze(n),n}function So(e,r){let n={...A(r),instructions:[e,...r.instructions]};return Object.freeze(n),n}function $(e,r,n=0){if(r.length-n<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function N(e,r,n,t=0){let o=n.length-t;if(o<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${o}.`)}var K=e=>{let r=e.filter(i=>i.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let n=r.reduce((i,s)=>i+s.length,0),t=new Uint8Array(n),o=0;return r.forEach(i=>{t.set(i,o),o+=i.length;}),t},xr=(e,r)=>{if(e.length>=r)return e;let n=new Uint8Array(r).fill(0);return n.set(e),n},ne=(e,r)=>xr(e.length<=r?e:e.slice(0,r),r);function z(e,r,n){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(n===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:n??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function Te(e,r,n){return {description:n??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function te(e,r,n){return {...Te(e,r,n),encode:t=>ne(e.encode(t),r)}}function oe(e,r,n){return {...Te(e,r,n),decode:(t,o=0)=>{N("fixCodec",r,t,o),(o>0||t.length>r)&&(t=t.slice(o,o+r)),e.fixedSize!==null&&(t=ne(t,e.fixedSize));let[i]=e.decode(t,0);return [i,o+r]}}}function Se(e,r){return {description:e.description,encode:n=>e.encode(r(n)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function Tr(e,r,n,t){if(t<r||t>n)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${n}], got ${t}.`)}function be(e){let r,n=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===0,n+=r?"(le)":"(be)"),{description:e.options.description??n,fixedSize:e.size,littleEndian:r,maxSize:e.size}}function Ae(e){let r=be(e);return {description:r.description,encode(n){e.range&&Tr(e.name,e.range[0],e.range[1],n);let t=new ArrayBuffer(e.size);return e.set(new DataView(t),n,r.littleEndian),new Uint8Array(t)},fixedSize:r.fixedSize,maxSize:r.maxSize}}function ze(e){let r=be(e);return {decode(n,t=0){$(r.description,n,t),N(r.description,e.size,n,t);let o=new DataView(Sr(n,t,e.size));return [e.get(o,r.littleEndian),t+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function Sr(e,r,n){let t=e.byteOffset+(r??0),o=n??e.byteLength;return e.buffer.slice(t,t+o)}var Ee=(e={})=>Ae({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,n,t)=>r.setUint32(0,n,t),size:4}),Ie=(e={})=>ze({get:(r,n)=>r.getUint32(0,n),name:"u32",options:e,size:4});var we=(e={})=>Ae({name:"u8",options:e,range:[0,+"0xff"],set:(r,n)=>r.setUint8(0,n),size:1}),Be=(e={})=>ze({get:r=>r.getUint8(0),name:"u8",options:e,size:1}),Ce=(e={})=>z(we(e),Be(e));function br(e,r,n=r){if(!r.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${n}].`)}var Ar=e=>{let r=e.length,n=BigInt(r);return {description:`base${r}`,encode(t){if(br(e,t),t==="")return new Uint8Array;let o=[...t],i=o.findIndex(f=>f!==e[0]);i=i===-1?o.length:i;let s=Array(i).fill(0);if(i===o.length)return Uint8Array.from(s);let c=o.slice(i),u=0n,d=1n;for(let f=c.length-1;f>=0;f-=1)u+=d*BigInt(e.indexOf(c[f])),d*=n;let l=[];for(;u>0n;)l.unshift(Number(u%256n)),u/=256n;return Uint8Array.from(s.concat(l))},fixedSize:null,maxSize:null}},zr=e=>{let r=e.length,n=BigInt(r);return {decode(t,o=0){let i=o===0?t:t.slice(o);if(i.length===0)return ["",0];let s=i.findIndex(l=>l!==0);s=s===-1?i.length:s;let c=e[0].repeat(s);if(s===i.length)return [c,t.length];let u=i.slice(s).reduce((l,f)=>l*256n+BigInt(f),0n),d=[];for(;u>0n;)d.unshift(e[Number(u%n)]),u/=n;return [c+d.join(""),t.length]},description:`base${r}`,fixedSize:null,maxSize:null}};var ve="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",De=()=>Ar(ve),Ne=()=>zr(ve);var Er=e=>e.replace(/\u0000/g,"");var Ir=globalThis.TextDecoder,wr=globalThis.TextEncoder,Br=()=>{let e;return {description:"utf8",encode:r=>new Uint8Array((e||(e=new wr)).encode(r)),fixedSize:null,maxSize:null}},Cr=()=>{let e;return {decode(r,n=0){let t=(e||(e=new Ir)).decode(r.slice(n));return [Er(t),r.length]},description:"utf8",fixedSize:null,maxSize:null}};var _e=(e={})=>{let r=e.size??Ee(),n=e.encoding??Br(),t=e.description??`string(${n.description}; ${Re(r)})`;return r==="variable"?{...n,description:t}:typeof r=="number"?te(n,r,t):{description:t,encode:o=>{let i=n.encode(o),s=r.encode(i.length);return K([s,i])},fixedSize:null,maxSize:null}},ke=(e={})=>{let r=e.size??Ie(),n=e.encoding??Cr(),t=e.description??`string(${n.description}; ${Re(r)})`;return r==="variable"?{...n,description:t}:typeof r=="number"?oe(n,r,t):{decode:(o,i=0)=>{$("string",o,i);let[s,c]=r.decode(o,i),u=Number(s);i=c;let d=o.slice(i,i+u);N("string",u,d);let[l,f]=n.decode(d);return i+=f,[l,i]},description:t,fixedSize:null,maxSize:null}};function Re(e){return typeof e=="object"?e.description:`${e}`}function Ue(){if(!globalThis.isSecureContext)throw new Error("Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts")}async function $e(){if(Ue(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.exportKey!="function")throw new Error("No key export implementation could be found")}async function Oe(){if(Ue(),typeof globalThis.crypto>"u"||typeof globalThis.crypto.subtle?.sign!="function")throw new Error("No signing implementation could be found")}var ie,se;function Le(){return ie||(ie=De()),ie}function vr(){return se||(se=Ne()),se}function Dr(e){try{if(e.length<32||e.length>44)throw new Error("Expected input string to decode to a byte array of length 32.");let t=Le().encode(e).byteLength;if(t!==32)throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${t}`)}catch(r){throw new Error(`\`${e}\` is not a base-58 encoded address`,{cause:r})}}function Nr(e){return Dr(e),e}function _r(e){return Se(_e({description:e?.description??"Base58EncodedAddress",encoding:Le(),size:32}),r=>Nr(r))}function Me(e){return ke({description:e?.description??"Base58EncodedAddress",encoding:vr(),size:32})}function Y(e){return z(_r(e),Me(e))}function O(){return new Intl.Collator("en",{caseFirst:"lower",ignorePunctuation:!1,localeMatcher:"best fit",numeric:!1,sensitivity:"variant",usage:"sort"}).compare}async function Pe(e){if(await $e(),e.type!=="public"||e.algorithm.name!=="Ed25519")throw new Error("The `CryptoKey` must be an `Ed25519` public key");let r=await crypto.subtle.exportKey("raw",e),[n]=Me().decode(new Uint8Array(r));return n}function Ve(e,r,n){e[r]=n(e[r]??{role:g.READONLY});}var m=Symbol("AddressMapTypeProperty");function Fe(e,r){let n={[e]:{[m]:0,role:g.WRITABLE_SIGNER}},t=new Set;for(let o of r){Ve(n,o.programAddress,s=>{if(t.add(o.programAddress),m in s){if(C(s.role))switch(s[m]){case 0:throw new Error(`This transaction includes an address (\`${o.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`);default:throw new Error(`This transaction includes an address (\`${o.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`)}if(s[m]===2)return s}return {[m]:2,role:g.READONLY}});let i;if(o.accounts)for(let s of o.accounts)Ve(n,s.address,c=>{let{address:u,...d}=s;if(m in c)switch(c[m]){case 0:return c;case 1:{let l=re(c.role,d.role);if("lookupTableAddress"in d){if(c.lookupTableAddress!==d.lookupTableAddress&&(i||(i=O()))(d.lookupTableAddress,c.lookupTableAddress)<0)return {[m]:1,...d,role:l}}else if(B(d.role))return {[m]:2,role:l};return c.role!==l?{...c,role:l}:c}case 2:{let l=re(c.role,d.role);if(t.has(s.address)){if(C(d.role))throw new Error(`This transaction includes an address (\`${s.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`);return c.role!==l?{...c,role:l}:c}else return "lookupTableAddress"in d&&!B(c.role)?{...d,[m]:1,role:l}:c.role!==l?{...c,role:l}:c}}return "lookupTableAddress"in d?{...d,[m]:1}:{...d,[m]:2}});}return n}function We(e){let r;return Object.entries(e).sort(([t,o],[i,s])=>{if(o[m]!==s[m]){if(o[m]===0)return -1;if(s[m]===0)return 1;if(o[m]===2)return -1;if(s[m]===2)return 1}let c=B(o.role);if(c!==B(s.role))return c?-1:1;let u=C(o.role);return u!==C(s.role)?u?-1:1:(r||(r=O()),o[m]===1&&s[m]===1&&o.lookupTableAddress!==s.lookupTableAddress?r(o.lookupTableAddress,s.lookupTableAddress):r(t,i))}).map(([t,o])=>({address:t,...o}))}function He(e){var n;let r={};for(let t of e){if(!("lookupTableAddress"in t))continue;let o=r[n=t.lookupTableAddress]||(r[n]={readableIndices:[],writableIndices:[]});t.role===g.WRITABLE?o.writableIndices.push(t.addressIndex):o.readableIndices.push(t.addressIndex);}return Object.keys(r).sort(O()).map(t=>({lookupTableAddress:t,...r[t]}))}function je(e){let r=0,n=0,t=0;for(let o of e){if("lookupTableAddress"in o)break;let i=C(o.role);B(o.role)?(t++,i||n++):i||r++;}return {numReadonlyNonSignerAccounts:r,numReadonlySignerAccounts:n,numSignerAccounts:t}}function kr(e){let r={};for(let[n,t]of e.entries())r[t.address]=n;return r}function Ke(e,r){let n=kr(r);return e.map(({accounts:t,data:o,programAddress:i})=>({programAddressIndex:n[i],...t?{accountIndices:t.map(({address:s})=>n[s])}:null,...o?{data:o}:null}))}function Ye(e){return "nonce"in e?e.nonce:e.blockhash}function Ge(e){let r=e.findIndex(t=>"lookupTableAddress"in t);return (r===-1?e:e.slice(0,r)).map(({address:t})=>t)}function G(e){let r=Fe(e.feePayer,e.instructions),n=We(r);return {...e.version!=="legacy"?{addressTableLookups:He(n)}:null,header:je(n),instructions:Ke(e.instructions,n),lifetimeToken:Ye(e.lifetimeConstraint),staticAccounts:Ge(n),version:e.version}}function qe(e){let r=G(e),n;if("signatures"in e){n=[];for(let t=0;t<r.header.numSignerAccounts;t++)n[t]=e.signatures[r.staticAccounts[t]]??new Uint8Array(Array(64).fill(0));}else n=Array(r.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));return {compiledMessage:r,signatures:n}}function Rr(e){let r=Y();return {description:e?.description??r.description,deserialize:r.decode,fixedSize:r.fixedSize,maxSize:r.maxSize,serialize:r.encode}}function Xe(){return T([["lookupTableAddress",Rr(void 0)],["writableIndices",h(w(),{size:p()})],["readableIndices",h(w(),{size:p()})]],void 0)}function Ze(e){return e.reduce((r,n)=>r===null||n===null?null:r+n,0)}function Je(e,r){let n=e.map(([t,o])=>`${String(t)}: ${o.description}`).join(", ");return {description:r??`struct(${n})`,fixedSize:Ze(e.map(([,t])=>t.fixedSize)),maxSize:Ze(e.map(([,t])=>t.maxSize))}}function Qe(e,r={}){return {...Je(e,r.description),encode:n=>{let t=e.map(([o,i])=>i.encode(n[o]));return K(t)}}}function er(e,r={}){return {...Je(e,r.description),decode:(n,t=0)=>{let o={};return e.forEach(([i,s])=>{let[c,u]=s.decode(n,t);t=u,o[i]=c;}),[o,t]}}}function rr(e,r={}){return z(Qe(e,r),er(e,r))}var ae;function Ur(){return ae||(ae=Ce()),ae}function ce(e){let r=Ur();return {...r,description:e??r.description}}var $r=void 0,Or=void 0,Lr=void 0,Mr=void 0;function nr(){return rr([["numSignerAccounts",ce($r)],["numReadonlySignerAccounts",ce(Or)],["numReadonlyNonSignerAccounts",ce(Lr)]],{description:Mr})}function tr(){return k(T([["programAddressIndex",w(void 0)],["accountIndices",h(w({description:""}),{description:"",size:p()})],["data",U({description:"",size:p()})]]),e=>e.accountIndices!==void 0&&e.data!==void 0?e:{...e,accountIndices:e.accountIndices??[],data:e.data??new Uint8Array(0)},e=>{if(e.accountIndices.length&&e.data.byteLength)return e;let{accountIndices:r,data:n,...t}=e;return {...t,...r.length?{accountIndices:r}:null,...n.byteLength?{data:n}:null}})}var de=128,or={description:"",fixedSize:null,maxSize:1};function Pr(e,r=0){let n=e[r];return n&de?[n^de,r+1]:["legacy",r]}function Vr(e){if(e==="legacy")return new Uint8Array;if(e<0||e>127)throw new Error(`Transaction version must be in the range [0, 127]. \`${e}\` given.`);return new Uint8Array([e|de])}function Fr(){return {...or,decode:Pr}}function Wr(){return {...or,encode:Vr}}function ir(){return z(Wr(),Fr())}function Hr(e,r){let n=r+e[0].toUpperCase()+e.slice(1);return new Error(`No ${e} exists for ${r}. Use \`get${n}()\` if you need a ${e}, and \`get${r}Codec()\` if you need to both encode and decode ${r}`)}function q(e){return ()=>{throw Hr("decoder",e)}}var jr={description:"",fixedSize:null,maxSize:null};function Kr(e){return e.version==="legacy"?T(sr()).serialize(e):k(T([...sr(),["addressTableLookups",Yr()]]),r=>r.version==="legacy"?r:{...r,addressTableLookups:r.addressTableLookups??[]}).serialize(e)}function ue(e){return {description:e.description,deserialize:e.decode,fixedSize:e.fixedSize,maxSize:e.maxSize,serialize:e.encode}}function sr(){return [["version",ue(ir())],["header",ue(nr())],["staticAccounts",h(ue(Y()),{description:"",size:p()})],["lifetimeToken",ee({description:"",encoding:E,size:32})],["instructions",h(tr(),{description:"",size:p()})]]}function Yr(){return h(Xe(),{size:p()})}function X(){return {...jr,deserialize:q("CompiledMessage"),serialize:Kr}}var Gr={description:"",fixedSize:null,maxSize:null};function qr(e){let r=qe(e);return T([["signatures",h(U({size:64}),{size:p()})],["compiledMessage",X()]]).serialize(r)}function ar(){return {...Gr,deserialize:q("CompiledMessage"),serialize:qr}}async function cr(e,r){await Oe();let n=await crypto.subtle.sign("Ed25519",e,r);return new Uint8Array(n)}function Xr(e){try{if(e.length<64||e.length>88)throw new Error("Expected input string to decode to a byte array of length 64.");let n=E.serialize(e).byteLength;if(n!==64)throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${n}`)}catch(r){throw new Error(`\`${e}\` is not a transaction signature`,{cause:r})}}function Ns(e){return !(e.length<64||e.length>88||E.serialize(e).byteLength!==64)}async function Zr(e,r){let n=X().serialize(e);return await cr(r,n)}function _s(e){let r=e.signatures[e.feePayer];if(!r)throw new Error("Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer.");return r}async function ks(e,r){let n=G(r),t="signatures"in r?{...r.signatures}:{},o=await Promise.all(e.map(s=>Promise.all([Pe(s.publicKey),Zr(n,s.privateKey)])));for(let[s,c]of o)t[s]=c;let i={...r,signatures:t};return Object.freeze(i),i}function Rs(e){return Xr(e),e}function Ls(e){let r=ar().serialize(e);return btoa(String.fromCharCode(...r))} | ||
exports.appendTransactionInstruction = m; | ||
exports.createTransaction = T; | ||
exports.prependTransactionInstruction = x; | ||
exports.setTransactionFeePayer = d; | ||
exports.appendTransactionInstruction = To; | ||
exports.assertIsBlockhash = qt; | ||
exports.assertIsDurableNonceTransaction = uo; | ||
exports.assertIsTransactionSignature = Xr; | ||
exports.createTransaction = Qt; | ||
exports.getBase64EncodedWireTransaction = Ls; | ||
exports.getSignatureFromTransaction = _s; | ||
exports.getTransactionEncoder = ar; | ||
exports.isTransactionSignature = Ns; | ||
exports.prependTransactionInstruction = So; | ||
exports.setTransactionFeePayer = po; | ||
exports.setTransactionLifetimeUsingBlockhash = Xt; | ||
exports.setTransactionLifetimeUsingDurableNonce = lo; | ||
exports.signTransaction = ks; | ||
exports.transactionSignature = Rs; | ||
@@ -13,0 +24,0 @@ return exports; |
@@ -1,2 +0,7 @@ | ||
import { Blockhash } from '@solana/rpc-core'; | ||
import { IDurableNonceTransaction } from './durable-nonce'; | ||
import { ITransactionWithSignatures } from './signatures'; | ||
import { BaseTransaction } from './types'; | ||
export type Blockhash = string & { | ||
readonly __brand: unique symbol; | ||
}; | ||
type BlockhashLifetimeConstraint = Readonly<{ | ||
@@ -9,3 +14,6 @@ blockhash: Blockhash; | ||
} | ||
export declare function assertIsBlockhash(putativeBlockhash: string): asserts putativeBlockhash is Blockhash; | ||
export declare function setTransactionLifetimeUsingBlockhash<TTransaction extends BaseTransaction & IDurableNonceTransaction>(blockhashLifetimeConstraint: BlockhashLifetimeConstraint, transaction: TTransaction | (TTransaction & ITransactionWithSignatures)): Omit<TTransaction, keyof ITransactionWithSignatures | 'lifetimeConstraint'> & ITransactionWithBlockhashLifetime; | ||
export declare function setTransactionLifetimeUsingBlockhash<TTransaction extends BaseTransaction | (BaseTransaction & ITransactionWithBlockhashLifetime)>(blockhashLifetimeConstraint: BlockhashLifetimeConstraint, transaction: TTransaction | (TTransaction & ITransactionWithSignatures)): Omit<TTransaction, keyof ITransactionWithSignatures> & ITransactionWithBlockhashLifetime; | ||
export {}; | ||
//# sourceMappingURL=blockhash.d.ts.map |
@@ -0,4 +1,7 @@ | ||
import { Base58EncodedAddress } from '@solana/addresses'; | ||
import { IInstruction, IInstructionWithAccounts, IInstructionWithData } from '@solana/instructions'; | ||
import { ReadonlyAccount, ReadonlySignerAccount, WritableAccount } from '@solana/instructions/dist/types/accounts'; | ||
type AdvanceNonceAccountInstruction<TNonceAccountAddress extends string = string, TNonceAuthorityAddress extends string = string> = IInstruction<'11111111111111111111111111111111'> & IInstructionWithAccounts<[ | ||
import { ITransactionWithSignatures } from './signatures'; | ||
import { BaseTransaction } from './types'; | ||
type AdvanceNonceAccountInstruction<TNonceAccountAddress extends string = string, TNonceAuthorityAddress extends string = string> = IInstruction<'11111111111111111111111111111111'> & IInstructionWithAccounts<readonly [ | ||
WritableAccount<TNonceAccountAddress>, | ||
@@ -9,15 +12,25 @@ ReadonlyAccount<'SysvarRecentB1ockHashes11111111111111111111'>, | ||
type AdvanceNonceAccountInstructionData = Uint8Array & { | ||
readonly __advanceNonceAccountInstructionData: unique symbol; | ||
readonly __brand: unique symbol; | ||
}; | ||
type NonceLifetimeConstraint = Readonly<{ | ||
nonce: string; | ||
type DurableNonceConfig<TNonceAccountAddress extends string = string, TNonceAuthorityAddress extends string = string, TNonceValue extends string = string> = Readonly<{ | ||
readonly nonce: Nonce<TNonceValue>; | ||
readonly nonceAccountAddress: Base58EncodedAddress<TNonceAccountAddress>; | ||
readonly nonceAuthorityAddress: Base58EncodedAddress<TNonceAuthorityAddress>; | ||
}>; | ||
export interface IDurableNonceTransaction<TNonceAccountAddress extends string = string, TNonceAuthorityAddress extends string = string> { | ||
readonly instructions: [ | ||
export type Nonce<TNonceValue extends string = string> = TNonceValue & { | ||
readonly __brand: unique symbol; | ||
}; | ||
type NonceLifetimeConstraint<TNonceValue extends string = string> = Readonly<{ | ||
nonce: Nonce<TNonceValue>; | ||
}>; | ||
export interface IDurableNonceTransaction<TNonceAccountAddress extends string = string, TNonceAuthorityAddress extends string = string, TNonceValue extends string = string> { | ||
readonly instructions: readonly [ | ||
AdvanceNonceAccountInstruction<TNonceAccountAddress, TNonceAuthorityAddress>, | ||
...IInstruction[] | ||
]; | ||
readonly lifetimeConstraint: NonceLifetimeConstraint; | ||
readonly lifetimeConstraint: NonceLifetimeConstraint<TNonceValue>; | ||
} | ||
export declare function assertIsDurableNonceTransaction(transaction: BaseTransaction | (BaseTransaction & IDurableNonceTransaction)): asserts transaction is BaseTransaction & IDurableNonceTransaction; | ||
export declare function setTransactionLifetimeUsingDurableNonce<TTransaction extends BaseTransaction, TNonceAccountAddress extends string = string, TNonceAuthorityAddress extends string = string, TNonceValue extends string = string>({ nonce, nonceAccountAddress, nonceAuthorityAddress, }: DurableNonceConfig<TNonceAccountAddress, TNonceAuthorityAddress, TNonceValue>, transaction: TTransaction | (TTransaction & IDurableNonceTransaction)): Omit<TTransaction, keyof ITransactionWithSignatures> & IDurableNonceTransaction<TNonceAccountAddress, TNonceAuthorityAddress, TNonceValue>; | ||
export {}; | ||
//# sourceMappingURL=durable-nonce.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { Base58EncodedAddress } from '@solana/keys'; | ||
import { Base58EncodedAddress } from '@solana/addresses'; | ||
import { ITransactionWithSignatures } from './signatures'; | ||
@@ -7,3 +7,4 @@ import { BaseTransaction } from './types'; | ||
} | ||
export declare function setTransactionFeePayer<TFeePayerAddress extends string, TTransaction extends BaseTransaction>(feePayer: Base58EncodedAddress<TFeePayerAddress>, transaction: TTransaction | (TTransaction & ITransactionWithFeePayer<TFeePayerAddress>) | (TTransaction & ITransactionWithSignatures) | (TTransaction & ITransactionWithFeePayer<TFeePayerAddress> & ITransactionWithSignatures)): (TTransaction & ITransactionWithFeePayer<TFeePayerAddress>) | (Omit<TTransaction, keyof ITransactionWithSignatures> & ITransactionWithFeePayer<TFeePayerAddress>); | ||
export declare function setTransactionFeePayer<TFeePayerAddress extends string, TTransaction extends BaseTransaction>(feePayer: Base58EncodedAddress<TFeePayerAddress>, transaction: (TTransaction & ITransactionWithSignatures) | (TTransaction & ITransactionWithFeePayer<string> & ITransactionWithSignatures)): Omit<TTransaction, keyof ITransactionWithSignatures> & ITransactionWithFeePayer<TFeePayerAddress>; | ||
export declare function setTransactionFeePayer<TFeePayerAddress extends string, TTransaction extends BaseTransaction>(feePayer: Base58EncodedAddress<TFeePayerAddress>, transaction: TTransaction | (TTransaction & ITransactionWithFeePayer<string>)): TTransaction & ITransactionWithFeePayer<TFeePayerAddress>; | ||
//# sourceMappingURL=fee-payer.d.ts.map |
@@ -6,4 +6,6 @@ export * from './blockhash'; | ||
export * from './instructions'; | ||
export * from './serializers'; | ||
export * from './signatures'; | ||
export * from './types'; | ||
export * from './wire-transaction'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,12 +0,19 @@ | ||
import { Base58EncodedAddress } from '@solana/keys'; | ||
type Base64EncodedSignature = string & { | ||
readonly __base64EncodedSignature: unique symbol; | ||
}; | ||
import { Base58EncodedAddress } from '@solana/addresses'; | ||
import { Ed25519Signature } from '@solana/keys'; | ||
import { ITransactionWithFeePayer } from './fee-payer'; | ||
import { compileMessage } from './message'; | ||
export interface IFullySignedTransaction extends ITransactionWithSignatures { | ||
readonly __fullySignedTransaction: unique symbol; | ||
readonly __brand: unique symbol; | ||
} | ||
export interface ITransactionWithSignatures { | ||
readonly signatures: Readonly<Record<Base58EncodedAddress, Base64EncodedSignature>>; | ||
readonly signatures: Readonly<Record<Base58EncodedAddress, Ed25519Signature>>; | ||
} | ||
export {}; | ||
export type TransactionSignature = string & { | ||
readonly __brand: unique symbol; | ||
}; | ||
export declare function assertIsTransactionSignature(putativeTransactionSignature: string): asserts putativeTransactionSignature is TransactionSignature; | ||
export declare function isTransactionSignature(putativeTransactionSignature: string): putativeTransactionSignature is TransactionSignature; | ||
export declare function getSignatureFromTransaction(transaction: ITransactionWithFeePayer & ITransactionWithSignatures): TransactionSignature; | ||
export declare function signTransaction<TTransaction extends Parameters<typeof compileMessage>[0]>(keyPairs: CryptoKeyPair[], transaction: TTransaction | (TTransaction & ITransactionWithSignatures)): Promise<TTransaction & ITransactionWithSignatures>; | ||
export declare function transactionSignature(putativeTransactionSignature: string): TransactionSignature; | ||
//# sourceMappingURL=signatures.d.ts.map |
import { IAccountMeta, IInstruction } from '@solana/instructions'; | ||
/** A string of bytes that are definitely a serialized message */ | ||
export type SerializedMessageBytes = Uint8Array & { | ||
readonly __serializedMessageBytes: unique symbol; | ||
}; | ||
export type SerializedMessageBytesBase64 = string & { | ||
readonly __serializedMessageBytesBase64: unique symbol; | ||
}; | ||
export type BaseTransaction = Readonly<{ | ||
@@ -3,0 +10,0 @@ instructions: readonly IInstruction[]; |
{ | ||
"name": "@solana/transactions", | ||
"version": "2.0.0-experimental.fbdf21a", | ||
"version": "2.0.0-experimental.fc4e943", | ||
"description": "Helpers for creating and serializing transactions", | ||
@@ -49,26 +49,27 @@ "exports": { | ||
"dependencies": { | ||
"@metaplex-foundation/umi-serializers": "^0.8.2" | ||
"@metaplex-foundation/umi-serializers": "^0.8.9", | ||
"@solana/addresses": "2.0.0-experimental.fc4e943", | ||
"@solana/codecs-core": "2.0.0-experimental.fc4e943", | ||
"@solana/codecs-data-structures": "2.0.0-experimental.fc4e943", | ||
"@solana/codecs-numbers": "2.0.0-experimental.fc4e943", | ||
"@solana/keys": "2.0.0-experimental.fc4e943" | ||
}, | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^1.0.0", | ||
"@swc/core": "^1.3.18", | ||
"@swc/jest": "^0.2.23", | ||
"@types/jest": "^29.5.0", | ||
"@typescript-eslint/eslint-plugin": "^5.57.1", | ||
"@typescript-eslint/parser": "^5.57.1", | ||
"@solana/eslint-config-solana": "^1.0.2", | ||
"@swc/jest": "^0.2.28", | ||
"@types/jest": "^29.5.5", | ||
"@types/node": "^20.6.3", | ||
"@typescript-eslint/eslint-plugin": "^6.7.0", | ||
"@typescript-eslint/parser": "^6.3.0", | ||
"agadoo": "^3.0.0", | ||
"eslint": "^8.37.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-sort-keys-fix": "^1.1.2", | ||
"jest": "^29.5.0", | ||
"jest-runner-eslint": "^2.0.0", | ||
"jest": "^29.7.0", | ||
"jest-runner-eslint": "^2.1.0", | ||
"jest-runner-prettier": "^1.0.0", | ||
"postcss": "^8.4.12", | ||
"prettier": "^2.7.1", | ||
"ts-node": "^10.9.1", | ||
"tsup": "6.7.0", | ||
"typescript": "^5.0.3", | ||
"prettier": "^2.8", | ||
"tsup": "7.2.0", | ||
"typescript": "^5.2.2", | ||
"version-from-git": "^1.1.1", | ||
"@solana/instructions": "2.0.0-development", | ||
"@solana/keys": "2.0.0-experimental.fbdf21a", | ||
"@solana/rpc-core": "2.0.0-development", | ||
"@solana/instructions": "2.0.0-experimental.fc4e943", | ||
"build-scripts": "0.0.0", | ||
@@ -92,7 +93,8 @@ "test-config": "0.0.0", | ||
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks", | ||
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json", | ||
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent", | ||
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent", | ||
"test:treeshakability:browser": "agadoo dist/index.browser.js", | ||
"test:treeshakability:native": "agadoo dist/index.node.js", | ||
"test:treeshakability:node": "agadoo dist/index.native.js", | ||
"test:treeshakability:native": "agadoo dist/index.native.js", | ||
"test:treeshakability:node": "agadoo dist/index.node.js", | ||
"test:typecheck": "tsc --noEmit", | ||
@@ -99,0 +101,0 @@ "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
899913
21
43
7099
6
+ Added@solana/codecs-data-structures@2.0.0-experimental.fc4e943
+ Added@solana/addresses@2.0.0-experimental.fc4e943(transitive)
+ Added@solana/assertions@2.0.0-experimental.fc4e943(transitive)
+ Added@solana/codecs-core@2.0.0-experimental.fc4e943(transitive)
+ Added@solana/codecs-data-structures@2.0.0-experimental.fc4e943(transitive)
+ Added@solana/codecs-numbers@2.0.0-experimental.fc4e943(transitive)
+ Added@solana/codecs-strings@2.0.0-experimental.fc4e943(transitive)
+ Added@solana/keys@2.0.0-experimental.fc4e943(transitive)
+ Addedfastestsmallesttextencoderdecoder@1.0.22(transitive)