@solana/transactions 2.0.0-experimental.dfb72ea → 2.0.0-experimental.e00f668
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +48 -40
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +48 -40
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +48 -40
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +48 -40
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +48 -40
- package/dist/index.node.js.map +1 -1
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/decompile-transaction.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/serializers/transaction-version.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.browser.js
CHANGED
|
@@ -1,33 +1,31 @@
|
|
|
1
|
+
import { SolanaError, SOLANA_ERROR__TRANSACTION_EXPECTED_BLOCKHASH_LIFETIME, SOLANA_ERROR__TRANSACTION_EXPECTED_NONCE_LIFETIME, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_FEE_PAYER_MISSING, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, SOLANA_ERROR__BLOCKHASH_BYTE_LENGTH_OUT_OF_RANGE, SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, SOLANA_ERROR__TRANSACTION_VERSION_NUMBER_OUT_OF_RANGE } from '@solana/errors';
|
|
1
2
|
import { getBase58Decoder, getBase64Decoder, getStringEncoder, getBase58Encoder, getStringDecoder } from '@solana/codecs-strings';
|
|
2
3
|
import { getAddressFromPublicKey, assertIsAddress, getAddressComparator, getAddressEncoder, getAddressDecoder } from '@solana/addresses';
|
|
3
4
|
import { pipe } from '@solana/functional';
|
|
4
5
|
import { createEncoder, mapDecoder, combineCodec, mapEncoder, createDecoder } from '@solana/codecs-core';
|
|
5
6
|
import { getStructDecoder, getArrayDecoder, getBytesDecoder, getStructEncoder, getArrayEncoder, getBytesEncoder } from '@solana/codecs-data-structures';
|
|
6
7
|
import { getShortU16Decoder, getShortU16Encoder, getU8Encoder, getU8Decoder } from '@solana/codecs-numbers';
|
|
7
|
-
import { SolanaError, SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE, SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES } from '@solana/errors';
|
|
8
8
|
import { signBytes } from '@solana/keys';
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// src/blockhash.ts
|
|
11
11
|
var base58Encoder;
|
|
12
12
|
function assertIsBlockhash(putativeBlockhash) {
|
|
13
13
|
if (!base58Encoder)
|
|
14
14
|
base58Encoder = getBase58Encoder();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
30
|
-
cause: e
|
|
15
|
+
if (
|
|
16
|
+
// Lowest value (32 bytes of zeroes)
|
|
17
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
18
|
+
putativeBlockhash.length > 44
|
|
19
|
+
) {
|
|
20
|
+
throw new SolanaError(SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, {
|
|
21
|
+
actualLength: putativeBlockhash.length
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
25
|
+
const numBytes = bytes.byteLength;
|
|
26
|
+
if (numBytes !== 32) {
|
|
27
|
+
throw new SolanaError(SOLANA_ERROR__BLOCKHASH_BYTE_LENGTH_OUT_OF_RANGE, {
|
|
28
|
+
actualLength: numBytes
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
31
|
}
|
|
@@ -60,7 +58,7 @@ function isTransactionWithBlockhashLifetime(transaction) {
|
|
|
60
58
|
}
|
|
61
59
|
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
62
60
|
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
63
|
-
throw new
|
|
61
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_EXPECTED_BLOCKHASH_LIFETIME);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
66
64
|
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
@@ -86,8 +84,6 @@ function createTransaction({
|
|
|
86
84
|
Object.freeze(out);
|
|
87
85
|
return out;
|
|
88
86
|
}
|
|
89
|
-
|
|
90
|
-
// ../instructions/dist/index.browser.js
|
|
91
87
|
var AccountRole = /* @__PURE__ */ ((AccountRole2) => {
|
|
92
88
|
AccountRole2[AccountRole2["WRITABLE_SIGNER"] = /* 3 */
|
|
93
89
|
3] = "WRITABLE_SIGNER";
|
|
@@ -109,13 +105,11 @@ function isWritableRole(role) {
|
|
|
109
105
|
function mergeRoles(roleA, roleB) {
|
|
110
106
|
return roleA | roleB;
|
|
111
107
|
}
|
|
112
|
-
|
|
113
|
-
// src/durable-nonce.ts
|
|
114
108
|
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
115
109
|
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
116
110
|
function assertIsDurableNonceTransaction(transaction) {
|
|
117
111
|
if (!isDurableNonceTransaction(transaction)) {
|
|
118
|
-
throw new
|
|
112
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_EXPECTED_NONCE_LIFETIME);
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
@@ -264,8 +258,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
|
|
|
264
258
|
const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
|
|
265
259
|
const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
|
|
266
260
|
if (missing.length > 0) {
|
|
267
|
-
|
|
268
|
-
|
|
261
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_CONTENTS_MISSING, {
|
|
262
|
+
lookupTableAddresses: missing
|
|
263
|
+
});
|
|
269
264
|
}
|
|
270
265
|
const readOnlyMetas = [];
|
|
271
266
|
const writableMetas = [];
|
|
@@ -273,8 +268,13 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
|
|
|
273
268
|
const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
|
|
274
269
|
const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
|
|
275
270
|
if (highestIndex >= addresses.length) {
|
|
276
|
-
throw new
|
|
277
|
-
|
|
271
|
+
throw new SolanaError(
|
|
272
|
+
SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_ADDRESS_LOOKUP_TABLE_INDEX_OUT_OF_RANGE,
|
|
273
|
+
{
|
|
274
|
+
highestKnownIndex: addresses.length - 1,
|
|
275
|
+
highestRequestedIndex: highestIndex,
|
|
276
|
+
lookupTableAddress: lookup.lookupTableAddress
|
|
277
|
+
}
|
|
278
278
|
);
|
|
279
279
|
}
|
|
280
280
|
const readOnlyForLookup = lookup.readableIndices.map((r) => ({
|
|
@@ -297,7 +297,9 @@ function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTab
|
|
|
297
297
|
function convertInstruction(instruction, accountMetas) {
|
|
298
298
|
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
299
299
|
if (!programAddress) {
|
|
300
|
-
throw new
|
|
300
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_INSTRUCTION_PROGRAM_ADDRESS_NOT_FOUND, {
|
|
301
|
+
index: instruction.programAddressIndex
|
|
302
|
+
});
|
|
301
303
|
}
|
|
302
304
|
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
303
305
|
const { data } = instruction;
|
|
@@ -342,8 +344,9 @@ function convertSignatures(compiledTransaction) {
|
|
|
342
344
|
function decompileTransaction(compiledTransaction, config) {
|
|
343
345
|
const { compiledMessage } = compiledTransaction;
|
|
344
346
|
const feePayer = compiledMessage.staticAccounts[0];
|
|
345
|
-
if (!feePayer)
|
|
346
|
-
throw new
|
|
347
|
+
if (!feePayer) {
|
|
348
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_FAILED_TO_DECOMPILE_FEE_PAYER_MISSING);
|
|
349
|
+
}
|
|
347
350
|
const accountMetas = getAccountMetas(compiledMessage);
|
|
348
351
|
const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, config?.addressesByLookupTableAddress ?? {}) : [];
|
|
349
352
|
const transactionMetas = [...accountMetas, ...accountLookupMetas];
|
|
@@ -383,13 +386,13 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
383
386
|
if (isWritableRole(entry.role)) {
|
|
384
387
|
switch (entry[TYPE]) {
|
|
385
388
|
case 0 /* FEE_PAYER */:
|
|
386
|
-
throw new
|
|
387
|
-
|
|
388
|
-
);
|
|
389
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_CANNOT_PAY_FEES, {
|
|
390
|
+
programAddress: instruction.programAddress
|
|
391
|
+
});
|
|
389
392
|
default:
|
|
390
|
-
throw new
|
|
391
|
-
|
|
392
|
-
);
|
|
393
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE, {
|
|
394
|
+
programAddress: instruction.programAddress
|
|
395
|
+
});
|
|
393
396
|
}
|
|
394
397
|
}
|
|
395
398
|
if (entry[TYPE] === 2 /* STATIC */) {
|
|
@@ -454,8 +457,11 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
454
457
|
addressesOfInvokedPrograms.has(account.address)
|
|
455
458
|
) {
|
|
456
459
|
if (isWritableRole(accountMeta.role)) {
|
|
457
|
-
throw new
|
|
458
|
-
|
|
460
|
+
throw new SolanaError(
|
|
461
|
+
SOLANA_ERROR__TRANSACTION_INVOKED_PROGRAMS_MUST_NOT_BE_WRITABLE,
|
|
462
|
+
{
|
|
463
|
+
programAddress: account.address
|
|
464
|
+
}
|
|
459
465
|
);
|
|
460
466
|
}
|
|
461
467
|
if (entry.role !== nextRole) {
|
|
@@ -745,7 +751,9 @@ function getTransactionVersionEncoder() {
|
|
|
745
751
|
return offset;
|
|
746
752
|
}
|
|
747
753
|
if (value < 0 || value > 127) {
|
|
748
|
-
throw new
|
|
754
|
+
throw new SolanaError(SOLANA_ERROR__TRANSACTION_VERSION_NUMBER_OUT_OF_RANGE, {
|
|
755
|
+
actualVersion: value
|
|
756
|
+
});
|
|
749
757
|
}
|
|
750
758
|
bytes.set([value | VERSION_FLAG_MASK], offset);
|
|
751
759
|
return offset + 1;
|