@solana/transactions 2.0.0-experimental.68e85dc → 2.0.0-experimental.6910664
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 +323 -11
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +326 -15
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +479 -9
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +326 -17
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +323 -9
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +328 -15
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +20 -17
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/decompile-transaction.d.ts +7 -0
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +2 -3
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts +4 -2
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +1 -0
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +9 -9
|
@@ -186,7 +186,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
186
186
|
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
187
187
|
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole.WRITABLE && // Second account is recent blockhashes sysvar
|
|
188
188
|
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole.READONLY && // Third account is nonce authority account
|
|
189
|
-
instruction.accounts[2].address != null && instruction.accounts[2].role
|
|
189
|
+
instruction.accounts[2].address != null && isSignerRole(instruction.accounts[2].role);
|
|
190
190
|
}
|
|
191
191
|
function isAdvanceNonceAccountInstructionData(data) {
|
|
192
192
|
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
@@ -194,21 +194,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
194
194
|
function isDurableNonceTransaction(transaction) {
|
|
195
195
|
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
196
196
|
}
|
|
197
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
198
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
199
|
+
}
|
|
197
200
|
function setTransactionLifetimeUsingDurableNonce({
|
|
198
201
|
nonce,
|
|
199
202
|
nonceAccountAddress,
|
|
200
203
|
nonceAuthorityAddress
|
|
201
204
|
}, transaction) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
+
let newInstructions;
|
|
206
|
+
const firstInstruction = transaction.instructions[0];
|
|
207
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
208
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
209
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
210
|
+
return transaction;
|
|
211
|
+
} else {
|
|
212
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
newInstructions = [
|
|
216
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
217
|
+
...transaction.instructions.slice(1)
|
|
218
|
+
];
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
newInstructions = [
|
|
222
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
223
|
+
...transaction.instructions
|
|
224
|
+
];
|
|
205
225
|
}
|
|
206
226
|
const out = {
|
|
207
227
|
...getUnsignedTransaction(transaction),
|
|
208
|
-
instructions:
|
|
209
|
-
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
210
|
-
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
211
|
-
],
|
|
228
|
+
instructions: newInstructions,
|
|
212
229
|
lifetimeConstraint: {
|
|
213
230
|
nonce
|
|
214
231
|
}
|
|
@@ -285,6 +302,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
285
302
|
return paddedBytes;
|
|
286
303
|
};
|
|
287
304
|
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
305
|
+
function combineCodec(encoder, decoder, description) {
|
|
306
|
+
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
if (encoder.maxSize !== decoder.maxSize) {
|
|
312
|
+
throw new Error(
|
|
313
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
if (description === void 0 && encoder.description !== decoder.description) {
|
|
317
|
+
throw new Error(
|
|
318
|
+
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
return {
|
|
322
|
+
decode: decoder.decode,
|
|
323
|
+
description: description ?? encoder.description,
|
|
324
|
+
encode: encoder.encode,
|
|
325
|
+
fixedSize: encoder.fixedSize,
|
|
326
|
+
maxSize: encoder.maxSize
|
|
327
|
+
};
|
|
328
|
+
}
|
|
288
329
|
function fixCodecHelper(data, fixedBytes, description) {
|
|
289
330
|
return {
|
|
290
331
|
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
@@ -322,6 +363,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
322
363
|
maxSize: encoder.maxSize
|
|
323
364
|
};
|
|
324
365
|
}
|
|
366
|
+
function mapDecoder(decoder, map) {
|
|
367
|
+
return {
|
|
368
|
+
decode: (bytes, offset = 0) => {
|
|
369
|
+
const [value, length] = decoder.decode(bytes, offset);
|
|
370
|
+
return [map(value, bytes, offset), length];
|
|
371
|
+
},
|
|
372
|
+
description: decoder.description,
|
|
373
|
+
fixedSize: decoder.fixedSize,
|
|
374
|
+
maxSize: decoder.maxSize
|
|
375
|
+
};
|
|
376
|
+
}
|
|
325
377
|
|
|
326
378
|
// ../codecs-numbers/dist/index.browser.js
|
|
327
379
|
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
@@ -401,6 +453,25 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
401
453
|
fixedSize: null,
|
|
402
454
|
maxSize: 3
|
|
403
455
|
});
|
|
456
|
+
var getShortU16Decoder = (options = {}) => ({
|
|
457
|
+
decode: (bytes, offset = 0) => {
|
|
458
|
+
let value = 0;
|
|
459
|
+
let byteCount = 0;
|
|
460
|
+
while (++byteCount) {
|
|
461
|
+
const byteIndex = byteCount - 1;
|
|
462
|
+
const currentByte = bytes[offset + byteIndex];
|
|
463
|
+
const nextSevenBits = 127 & currentByte;
|
|
464
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
465
|
+
if ((currentByte & 128) === 0) {
|
|
466
|
+
break;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return [value, offset + byteCount];
|
|
470
|
+
},
|
|
471
|
+
description: options.description ?? "shortU16",
|
|
472
|
+
fixedSize: null,
|
|
473
|
+
maxSize: 3
|
|
474
|
+
});
|
|
404
475
|
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
405
476
|
name: "u32",
|
|
406
477
|
options,
|
|
@@ -421,11 +492,39 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
421
492
|
set: (view, value) => view.setUint8(0, value),
|
|
422
493
|
size: 1
|
|
423
494
|
});
|
|
495
|
+
var getU8Decoder = (options = {}) => numberDecoderFactory({
|
|
496
|
+
get: (view) => view.getUint8(0),
|
|
497
|
+
name: "u8",
|
|
498
|
+
options,
|
|
499
|
+
size: 1
|
|
500
|
+
});
|
|
424
501
|
|
|
425
502
|
// ../codecs-data-structures/dist/index.browser.js
|
|
426
503
|
function sumCodecSizes(sizes) {
|
|
427
504
|
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
428
505
|
}
|
|
506
|
+
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
507
|
+
if (typeof size === "number") {
|
|
508
|
+
return [size, offset];
|
|
509
|
+
}
|
|
510
|
+
if (typeof size === "object") {
|
|
511
|
+
return size.decode(bytes, offset);
|
|
512
|
+
}
|
|
513
|
+
if (size === "remainder") {
|
|
514
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
515
|
+
if (childrenSize === null) {
|
|
516
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
517
|
+
}
|
|
518
|
+
const remainder = bytes.slice(offset).length;
|
|
519
|
+
if (remainder % childrenSize !== 0) {
|
|
520
|
+
throw new Error(
|
|
521
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${childrenSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${childrenSize} should be equal to zero.`
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
return [remainder / childrenSize, offset];
|
|
525
|
+
}
|
|
526
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
527
|
+
}
|
|
429
528
|
function getArrayLikeCodecSizeDescription(size) {
|
|
430
529
|
return typeof size === "object" ? size.description : `${size}`;
|
|
431
530
|
}
|
|
@@ -467,6 +566,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
467
566
|
}
|
|
468
567
|
};
|
|
469
568
|
}
|
|
569
|
+
function getArrayDecoder(item, options = {}) {
|
|
570
|
+
const size = options.size ?? getU32Decoder();
|
|
571
|
+
return {
|
|
572
|
+
...arrayCodecHelper(item, size, options.description),
|
|
573
|
+
decode: (bytes, offset = 0) => {
|
|
574
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
575
|
+
return [[], offset];
|
|
576
|
+
}
|
|
577
|
+
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
578
|
+
offset = newOffset;
|
|
579
|
+
const values = [];
|
|
580
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
581
|
+
const [value, newOffset2] = item.decode(bytes, offset);
|
|
582
|
+
values.push(value);
|
|
583
|
+
offset = newOffset2;
|
|
584
|
+
}
|
|
585
|
+
return [values, offset];
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
470
589
|
function getBytesEncoder(options = {}) {
|
|
471
590
|
const size = options.size ?? "variable";
|
|
472
591
|
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
@@ -492,6 +611,40 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
492
611
|
}
|
|
493
612
|
};
|
|
494
613
|
}
|
|
614
|
+
function getBytesDecoder(options = {}) {
|
|
615
|
+
const size = options.size ?? "variable";
|
|
616
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
617
|
+
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
618
|
+
const byteDecoder = {
|
|
619
|
+
decode: (bytes, offset = 0) => {
|
|
620
|
+
const slice = bytes.slice(offset);
|
|
621
|
+
return [slice, offset + slice.length];
|
|
622
|
+
},
|
|
623
|
+
description,
|
|
624
|
+
fixedSize: null,
|
|
625
|
+
maxSize: null
|
|
626
|
+
};
|
|
627
|
+
if (size === "variable") {
|
|
628
|
+
return byteDecoder;
|
|
629
|
+
}
|
|
630
|
+
if (typeof size === "number") {
|
|
631
|
+
return fixDecoder(byteDecoder, size, description);
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
...byteDecoder,
|
|
635
|
+
decode: (bytes, offset = 0) => {
|
|
636
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
637
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
638
|
+
const length = Number(lengthBigInt);
|
|
639
|
+
offset = lengthOffset;
|
|
640
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
641
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
642
|
+
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
643
|
+
offset += contentOffset;
|
|
644
|
+
return [value, offset];
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
}
|
|
495
648
|
function structCodecHelper(fields, description) {
|
|
496
649
|
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
497
650
|
return {
|
|
@@ -509,6 +662,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
509
662
|
}
|
|
510
663
|
};
|
|
511
664
|
}
|
|
665
|
+
function getStructDecoder(fields, options = {}) {
|
|
666
|
+
return {
|
|
667
|
+
...structCodecHelper(fields, options.description),
|
|
668
|
+
decode: (bytes, offset = 0) => {
|
|
669
|
+
const struct = {};
|
|
670
|
+
fields.forEach(([key, codec]) => {
|
|
671
|
+
const [value, newOffset] = codec.decode(bytes, offset);
|
|
672
|
+
offset = newOffset;
|
|
673
|
+
struct[key] = value;
|
|
674
|
+
});
|
|
675
|
+
return [struct, offset];
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
}
|
|
512
679
|
|
|
513
680
|
// ../codecs-strings/dist/index.browser.js
|
|
514
681
|
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
@@ -1041,6 +1208,123 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1041
1208
|
};
|
|
1042
1209
|
}
|
|
1043
1210
|
|
|
1211
|
+
// ../functional/dist/index.browser.js
|
|
1212
|
+
function pipe(init, ...fns) {
|
|
1213
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
// src/decompile-transaction.ts
|
|
1217
|
+
function getAccountMetas(message) {
|
|
1218
|
+
const { header } = message;
|
|
1219
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
1220
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
1221
|
+
const accountMetas = [];
|
|
1222
|
+
let accountIndex = 0;
|
|
1223
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
1224
|
+
accountMetas.push({
|
|
1225
|
+
address: message.staticAccounts[accountIndex],
|
|
1226
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
1227
|
+
});
|
|
1228
|
+
accountIndex++;
|
|
1229
|
+
}
|
|
1230
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1231
|
+
accountMetas.push({
|
|
1232
|
+
address: message.staticAccounts[accountIndex],
|
|
1233
|
+
role: AccountRole.READONLY_SIGNER
|
|
1234
|
+
});
|
|
1235
|
+
accountIndex++;
|
|
1236
|
+
}
|
|
1237
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1238
|
+
accountMetas.push({
|
|
1239
|
+
address: message.staticAccounts[accountIndex],
|
|
1240
|
+
role: AccountRole.WRITABLE
|
|
1241
|
+
});
|
|
1242
|
+
accountIndex++;
|
|
1243
|
+
}
|
|
1244
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
1245
|
+
accountMetas.push({
|
|
1246
|
+
address: message.staticAccounts[accountIndex],
|
|
1247
|
+
role: AccountRole.READONLY
|
|
1248
|
+
});
|
|
1249
|
+
accountIndex++;
|
|
1250
|
+
}
|
|
1251
|
+
return accountMetas;
|
|
1252
|
+
}
|
|
1253
|
+
function convertInstruction(instruction, accountMetas) {
|
|
1254
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
1255
|
+
if (!programAddress) {
|
|
1256
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1257
|
+
}
|
|
1258
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
1259
|
+
const { data } = instruction;
|
|
1260
|
+
return {
|
|
1261
|
+
programAddress,
|
|
1262
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
1263
|
+
...data && data.length ? { data } : {}
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
1267
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1268
|
+
return {
|
|
1269
|
+
blockhash: messageLifetimeToken,
|
|
1270
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
1271
|
+
// U64 MAX
|
|
1272
|
+
};
|
|
1273
|
+
} else {
|
|
1274
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1275
|
+
assertIsAddress(nonceAccountAddress);
|
|
1276
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1277
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
1278
|
+
return {
|
|
1279
|
+
nonce: messageLifetimeToken,
|
|
1280
|
+
nonceAccountAddress,
|
|
1281
|
+
nonceAuthorityAddress
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
function convertSignatures(compiledTransaction) {
|
|
1286
|
+
const {
|
|
1287
|
+
compiledMessage: { staticAccounts },
|
|
1288
|
+
signatures
|
|
1289
|
+
} = compiledTransaction;
|
|
1290
|
+
return signatures.reduce((acc, sig, index) => {
|
|
1291
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
1292
|
+
if (allZeros)
|
|
1293
|
+
return acc;
|
|
1294
|
+
const address2 = staticAccounts[index];
|
|
1295
|
+
return { ...acc, [address2]: sig };
|
|
1296
|
+
}, {});
|
|
1297
|
+
}
|
|
1298
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
1299
|
+
const { compiledMessage } = compiledTransaction;
|
|
1300
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
1301
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
1302
|
+
}
|
|
1303
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
1304
|
+
if (!feePayer)
|
|
1305
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
1306
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
1307
|
+
const instructions = compiledMessage.instructions.map(
|
|
1308
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
1309
|
+
);
|
|
1310
|
+
const firstInstruction = instructions[0];
|
|
1311
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
1312
|
+
compiledMessage.lifetimeToken,
|
|
1313
|
+
firstInstruction,
|
|
1314
|
+
lastValidBlockHeight
|
|
1315
|
+
);
|
|
1316
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
1317
|
+
return pipe(
|
|
1318
|
+
createTransaction({ version: compiledMessage.version }),
|
|
1319
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1320
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
1321
|
+
return appendTransactionInstruction(instruction, acc);
|
|
1322
|
+
}, tx),
|
|
1323
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1324
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1044
1328
|
// src/serializers/address-table-lookup.ts
|
|
1045
1329
|
var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
|
|
1046
1330
|
var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
|
|
@@ -1072,6 +1356,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1072
1356
|
}
|
|
1073
1357
|
return memoizedAddressTableLookupEncoder;
|
|
1074
1358
|
}
|
|
1359
|
+
var memoizedAddressTableLookupDecoder;
|
|
1360
|
+
function getAddressTableLookupDecoder() {
|
|
1361
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
1362
|
+
memoizedAddressTableLookupDecoder = getStructDecoder(
|
|
1363
|
+
[
|
|
1364
|
+
["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
1365
|
+
[
|
|
1366
|
+
"writableIndices",
|
|
1367
|
+
getArrayDecoder(getU8Decoder(), {
|
|
1368
|
+
description: writableIndicesDescription,
|
|
1369
|
+
size: getShortU16Decoder()
|
|
1370
|
+
})
|
|
1371
|
+
],
|
|
1372
|
+
[
|
|
1373
|
+
"readableIndices",
|
|
1374
|
+
getArrayDecoder(getU8Decoder(), {
|
|
1375
|
+
description: readableIndicesDescription,
|
|
1376
|
+
size: getShortU16Decoder()
|
|
1377
|
+
})
|
|
1378
|
+
]
|
|
1379
|
+
],
|
|
1380
|
+
{ description: addressTableLookupDescription }
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
return memoizedAddressTableLookupDecoder;
|
|
1384
|
+
}
|
|
1075
1385
|
|
|
1076
1386
|
// src/serializers/header.ts
|
|
1077
1387
|
var memoizedU8Encoder;
|
|
@@ -1087,6 +1397,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1087
1397
|
description: description ?? encoder.description
|
|
1088
1398
|
};
|
|
1089
1399
|
}
|
|
1400
|
+
var memoizedU8Decoder;
|
|
1401
|
+
function getMemoizedU8Decoder() {
|
|
1402
|
+
if (!memoizedU8Decoder)
|
|
1403
|
+
memoizedU8Decoder = getU8Decoder();
|
|
1404
|
+
return memoizedU8Decoder;
|
|
1405
|
+
}
|
|
1406
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
1407
|
+
const decoder = getMemoizedU8Decoder();
|
|
1408
|
+
return {
|
|
1409
|
+
...decoder,
|
|
1410
|
+
description: description ?? decoder.description
|
|
1411
|
+
};
|
|
1412
|
+
}
|
|
1090
1413
|
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1091
1414
|
var numReadonlySignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" ;
|
|
1092
1415
|
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
@@ -1103,6 +1426,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1103
1426
|
}
|
|
1104
1427
|
);
|
|
1105
1428
|
}
|
|
1429
|
+
function getMessageHeaderDecoder() {
|
|
1430
|
+
return getStructDecoder(
|
|
1431
|
+
[
|
|
1432
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
1433
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
1434
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1435
|
+
],
|
|
1436
|
+
{
|
|
1437
|
+
description: messageHeaderDescription
|
|
1438
|
+
}
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1106
1441
|
|
|
1107
1442
|
// src/serializers/instruction.ts
|
|
1108
1443
|
var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
|
|
@@ -1139,6 +1474,37 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1139
1474
|
}
|
|
1140
1475
|
return memoizedGetInstructionEncoder;
|
|
1141
1476
|
}
|
|
1477
|
+
var memoizedGetInstructionDecoder;
|
|
1478
|
+
function getInstructionDecoder() {
|
|
1479
|
+
if (!memoizedGetInstructionDecoder) {
|
|
1480
|
+
memoizedGetInstructionDecoder = mapDecoder(
|
|
1481
|
+
getStructDecoder([
|
|
1482
|
+
["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
|
|
1483
|
+
[
|
|
1484
|
+
"accountIndices",
|
|
1485
|
+
getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
|
|
1486
|
+
description: accountIndicesDescription,
|
|
1487
|
+
size: getShortU16Decoder()
|
|
1488
|
+
})
|
|
1489
|
+
],
|
|
1490
|
+
["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
|
|
1491
|
+
]),
|
|
1492
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
1493
|
+
(instruction) => {
|
|
1494
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
1495
|
+
return instruction;
|
|
1496
|
+
}
|
|
1497
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
1498
|
+
return {
|
|
1499
|
+
...rest,
|
|
1500
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1501
|
+
...data.byteLength ? { data } : null
|
|
1502
|
+
};
|
|
1503
|
+
}
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
return memoizedGetInstructionDecoder;
|
|
1507
|
+
}
|
|
1142
1508
|
|
|
1143
1509
|
// src/serializers/transaction-version.ts
|
|
1144
1510
|
var VERSION_FLAG_MASK = 128;
|
|
@@ -1147,6 +1513,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1147
1513
|
fixedSize: null,
|
|
1148
1514
|
maxSize: 1
|
|
1149
1515
|
};
|
|
1516
|
+
function decode(bytes, offset = 0) {
|
|
1517
|
+
const firstByte = bytes[offset];
|
|
1518
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1519
|
+
return ["legacy", offset];
|
|
1520
|
+
} else {
|
|
1521
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1522
|
+
return [version, offset + 1];
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1150
1525
|
function encode(value) {
|
|
1151
1526
|
if (value === "legacy") {
|
|
1152
1527
|
return new Uint8Array();
|
|
@@ -1156,6 +1531,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1156
1531
|
}
|
|
1157
1532
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1158
1533
|
}
|
|
1534
|
+
function getTransactionVersionDecoder() {
|
|
1535
|
+
return {
|
|
1536
|
+
...BASE_CONFIG,
|
|
1537
|
+
decode
|
|
1538
|
+
};
|
|
1539
|
+
}
|
|
1159
1540
|
function getTransactionVersionEncoder() {
|
|
1160
1541
|
return {
|
|
1161
1542
|
...BASE_CONFIG,
|
|
@@ -1216,12 +1597,47 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1216
1597
|
]
|
|
1217
1598
|
];
|
|
1218
1599
|
}
|
|
1600
|
+
function getPreludeStructDecoderTuple() {
|
|
1601
|
+
return [
|
|
1602
|
+
["version", getTransactionVersionDecoder()],
|
|
1603
|
+
["header", getMessageHeaderDecoder()],
|
|
1604
|
+
[
|
|
1605
|
+
"staticAccounts",
|
|
1606
|
+
getArrayDecoder(getAddressDecoder(), {
|
|
1607
|
+
description: staticAccountsDescription,
|
|
1608
|
+
size: getShortU16Decoder()
|
|
1609
|
+
})
|
|
1610
|
+
],
|
|
1611
|
+
[
|
|
1612
|
+
"lifetimeToken",
|
|
1613
|
+
getStringDecoder({
|
|
1614
|
+
description: lifetimeTokenDescription,
|
|
1615
|
+
encoding: getBase58Decoder(),
|
|
1616
|
+
size: 32
|
|
1617
|
+
})
|
|
1618
|
+
],
|
|
1619
|
+
[
|
|
1620
|
+
"instructions",
|
|
1621
|
+
getArrayDecoder(getInstructionDecoder(), {
|
|
1622
|
+
description: instructionsDescription,
|
|
1623
|
+
size: getShortU16Decoder()
|
|
1624
|
+
})
|
|
1625
|
+
],
|
|
1626
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
1627
|
+
];
|
|
1628
|
+
}
|
|
1219
1629
|
function getAddressTableLookupArrayEncoder() {
|
|
1220
1630
|
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
1221
1631
|
description: addressTableLookupsDescription,
|
|
1222
1632
|
size: getShortU16Encoder()
|
|
1223
1633
|
});
|
|
1224
1634
|
}
|
|
1635
|
+
function getAddressTableLookupArrayDecoder() {
|
|
1636
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
1637
|
+
description: addressTableLookupsDescription,
|
|
1638
|
+
size: getShortU16Decoder()
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1225
1641
|
var messageDescription = "The wire format of a Solana transaction message" ;
|
|
1226
1642
|
function getCompiledMessageEncoder() {
|
|
1227
1643
|
return {
|
|
@@ -1237,10 +1653,23 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1237
1653
|
maxSize: null
|
|
1238
1654
|
};
|
|
1239
1655
|
}
|
|
1656
|
+
function getCompiledMessageDecoder() {
|
|
1657
|
+
return mapDecoder(
|
|
1658
|
+
getStructDecoder(getPreludeStructDecoderTuple(), {
|
|
1659
|
+
description: messageDescription
|
|
1660
|
+
}),
|
|
1661
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
1662
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
1663
|
+
return restOfMessage;
|
|
1664
|
+
}
|
|
1665
|
+
return { ...restOfMessage, addressTableLookups };
|
|
1666
|
+
}
|
|
1667
|
+
);
|
|
1668
|
+
}
|
|
1240
1669
|
|
|
1241
1670
|
// src/serializers/transaction.ts
|
|
1242
|
-
var transactionDescription = "The wire format of a Solana transaction" ;
|
|
1243
1671
|
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
1672
|
+
var transactionDescription = "The wire format of a Solana transaction" ;
|
|
1244
1673
|
function getCompiledTransactionEncoder() {
|
|
1245
1674
|
return getStructEncoder(
|
|
1246
1675
|
[
|
|
@@ -1258,9 +1687,38 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1258
1687
|
}
|
|
1259
1688
|
);
|
|
1260
1689
|
}
|
|
1690
|
+
function getSignatureDecoder() {
|
|
1691
|
+
return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
1692
|
+
}
|
|
1693
|
+
function getCompiledTransactionDecoder() {
|
|
1694
|
+
return getStructDecoder(
|
|
1695
|
+
[
|
|
1696
|
+
[
|
|
1697
|
+
"signatures",
|
|
1698
|
+
getArrayDecoder(getSignatureDecoder(), {
|
|
1699
|
+
description: signaturesDescription,
|
|
1700
|
+
size: getShortU16Decoder()
|
|
1701
|
+
})
|
|
1702
|
+
],
|
|
1703
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
1704
|
+
],
|
|
1705
|
+
{
|
|
1706
|
+
description: transactionDescription
|
|
1707
|
+
}
|
|
1708
|
+
);
|
|
1709
|
+
}
|
|
1261
1710
|
function getTransactionEncoder() {
|
|
1262
1711
|
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
1263
1712
|
}
|
|
1713
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
1714
|
+
return mapDecoder(
|
|
1715
|
+
getCompiledTransactionDecoder(),
|
|
1716
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
1717
|
+
);
|
|
1718
|
+
}
|
|
1719
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
1720
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
1721
|
+
}
|
|
1264
1722
|
|
|
1265
1723
|
// ../keys/dist/index.browser.js
|
|
1266
1724
|
async function signBytes(key, data) {
|
|
@@ -1345,6 +1803,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1345
1803
|
assertIsTransactionSignature(putativeTransactionSignature);
|
|
1346
1804
|
return putativeTransactionSignature;
|
|
1347
1805
|
}
|
|
1806
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
1807
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
1808
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
1809
|
+
requiredSigners.forEach((address2) => {
|
|
1810
|
+
if (!transaction.signatures[address2]) {
|
|
1811
|
+
throw new Error(`Transaction is missing signature for address \`${address2}\``);
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
}
|
|
1348
1815
|
|
|
1349
1816
|
// src/wire-transaction.ts
|
|
1350
1817
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -1358,9 +1825,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1358
1825
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1359
1826
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1360
1827
|
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
1828
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
1361
1829
|
exports.createTransaction = createTransaction;
|
|
1362
1830
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
1363
1831
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1832
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
1833
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1364
1834
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1365
1835
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1366
1836
|
exports.isTransactionSignature = isTransactionSignature;
|