@solana/transactions 2.0.0-experimental.d48113d → 2.0.0-experimental.d4b2978
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/LICENSE +1 -1
- package/dist/index.browser.cjs +267 -234
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +264 -235
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +758 -350
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +264 -237
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +267 -234
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +264 -235
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +17 -11
- package/dist/types/accounts.d.ts.map +1 -1
- package/dist/types/blockhash.d.ts.map +1 -1
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -1
- package/dist/types/durable-nonce.d.ts +3 -1
- package/dist/types/durable-nonce.d.ts.map +1 -1
- package/dist/types/fee-payer.d.ts +2 -1
- package/dist/types/fee-payer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/serializers/address-table-lookup.d.ts +5 -3
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -1
- package/dist/types/serializers/header.d.ts +4 -2
- package/dist/types/serializers/header.d.ts.map +1 -1
- package/dist/types/serializers/index.d.ts +2 -0
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts +4 -2
- package/dist/types/serializers/instruction.d.ts.map +1 -1
- package/dist/types/serializers/message.d.ts +4 -4
- package/dist/types/serializers/message.d.ts.map +1 -1
- package/dist/types/serializers/transaction-version.d.ts +4 -4
- package/dist/types/serializers/transaction-version.d.ts.map +1 -1
- package/dist/types/serializers/transaction.d.ts.map +1 -1
- package/dist/types/signatures.d.ts +9 -1
- package/dist/types/signatures.d.ts.map +1 -1
- package/package.json +19 -13
package/LICENSE
CHANGED
package/dist/index.browser.cjs
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var umiSerializers = require('@metaplex-foundation/umi-serializers');
|
|
4
4
|
var addresses = require('@solana/addresses');
|
|
5
|
+
var codecsCore = require('@solana/codecs-core');
|
|
6
|
+
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
7
|
+
var codecsNumbers = require('@solana/codecs-numbers');
|
|
8
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
5
9
|
var keys = require('@solana/keys');
|
|
6
10
|
|
|
7
11
|
// ../build-scripts/env-shim.ts
|
|
@@ -31,8 +35,8 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
31
35
|
) {
|
|
32
36
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
33
37
|
}
|
|
34
|
-
const
|
|
35
|
-
const numBytes =
|
|
38
|
+
const bytes2 = umiSerializers.base58.serialize(putativeBlockhash);
|
|
39
|
+
const numBytes = bytes2.byteLength;
|
|
36
40
|
if (numBytes !== 32) {
|
|
37
41
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
38
42
|
}
|
|
@@ -230,7 +234,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
230
234
|
const shouldReplaceEntry = (
|
|
231
235
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
232
236
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
233
|
-
(addressComparator || (addressComparator = addresses.
|
|
237
|
+
(addressComparator || (addressComparator = addresses.getAddressComparator()))(
|
|
234
238
|
accountMeta.lookupTableAddress,
|
|
235
239
|
entry.lookupTableAddress
|
|
236
240
|
) < 0
|
|
@@ -336,7 +340,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
336
340
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
337
341
|
return leftIsWritable ? -1 : 1;
|
|
338
342
|
}
|
|
339
|
-
addressComparator || (addressComparator = addresses.
|
|
343
|
+
addressComparator || (addressComparator = addresses.getAddressComparator());
|
|
340
344
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
341
345
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
342
346
|
} else {
|
|
@@ -365,7 +369,7 @@ function getCompiledAddressTableLookups(orderedAccounts) {
|
|
|
365
369
|
entry.readableIndices.push(account.addressIndex);
|
|
366
370
|
}
|
|
367
371
|
}
|
|
368
|
-
return Object.keys(index).sort(addresses.
|
|
372
|
+
return Object.keys(index).sort(addresses.getAddressComparator()).map((lookupTableAddress) => ({
|
|
369
373
|
lookupTableAddress,
|
|
370
374
|
...index[lookupTableAddress]
|
|
371
375
|
}));
|
|
@@ -444,159 +448,124 @@ function compileMessage(transaction) {
|
|
|
444
448
|
version: transaction.version
|
|
445
449
|
};
|
|
446
450
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
451
|
+
|
|
452
|
+
// src/compile-transaction.ts
|
|
453
|
+
function getCompiledTransaction(transaction) {
|
|
454
|
+
const compiledMessage = compileMessage(transaction);
|
|
455
|
+
let signatures;
|
|
456
|
+
if ("signatures" in transaction) {
|
|
457
|
+
signatures = [];
|
|
458
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
459
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
460
|
+
}
|
|
461
|
+
} else {
|
|
462
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
compiledMessage,
|
|
466
|
+
signatures
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
470
|
+
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
471
|
+
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
472
|
+
var addressTableLookupDescription = __DEV__ ? "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" : "addressTableLookup";
|
|
473
|
+
var memoizedAddressTableLookupEncoder;
|
|
474
|
+
function getAddressTableLookupEncoder() {
|
|
475
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
476
|
+
memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
|
|
458
477
|
[
|
|
459
|
-
"
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
478
|
+
["lookupTableAddress", addresses.getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
479
|
+
[
|
|
480
|
+
"writableIndices",
|
|
481
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
482
|
+
description: writableIndicesDescription,
|
|
483
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
484
|
+
})
|
|
485
|
+
],
|
|
486
|
+
[
|
|
487
|
+
"readableIndices",
|
|
488
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
489
|
+
description: readableIndicesDescription,
|
|
490
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
491
|
+
})
|
|
492
|
+
]
|
|
466
493
|
],
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
description: "The indices of the accounts in the lookup table that should be loaded as read-only"
|
|
472
|
-
} : void 0,
|
|
473
|
-
size: umiSerializers.shortU16()
|
|
474
|
-
})
|
|
475
|
-
]
|
|
476
|
-
],
|
|
477
|
-
__DEV__ ? {
|
|
478
|
-
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"
|
|
479
|
-
} : void 0
|
|
480
|
-
);
|
|
494
|
+
{ description: addressTableLookupDescription }
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
return memoizedAddressTableLookupEncoder;
|
|
481
498
|
}
|
|
482
|
-
|
|
483
|
-
|
|
499
|
+
var memoizedU8Encoder;
|
|
500
|
+
function getMemoizedU8Encoder() {
|
|
501
|
+
if (!memoizedU8Encoder)
|
|
502
|
+
memoizedU8Encoder = codecsNumbers.getU8Encoder();
|
|
503
|
+
return memoizedU8Encoder;
|
|
504
|
+
}
|
|
505
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
506
|
+
const encoder = getMemoizedU8Encoder();
|
|
507
|
+
return {
|
|
508
|
+
...encoder,
|
|
509
|
+
description: description ?? encoder.description
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
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;
|
|
513
|
+
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;
|
|
514
|
+
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
515
|
+
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
516
|
+
function getMessageHeaderEncoder() {
|
|
517
|
+
return codecsDataStructures.getStructEncoder(
|
|
484
518
|
[
|
|
485
|
-
[
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
__DEV__ ? {
|
|
489
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
490
|
-
} : void 0
|
|
491
|
-
)
|
|
492
|
-
],
|
|
493
|
-
[
|
|
494
|
-
"numReadonlySignerAccounts",
|
|
495
|
-
umiSerializers.u8(
|
|
496
|
-
__DEV__ ? {
|
|
497
|
-
description: "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"
|
|
498
|
-
} : void 0
|
|
499
|
-
)
|
|
500
|
-
],
|
|
501
|
-
[
|
|
502
|
-
"numReadonlyNonSignerAccounts",
|
|
503
|
-
umiSerializers.u8(
|
|
504
|
-
__DEV__ ? {
|
|
505
|
-
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
506
|
-
} : void 0
|
|
507
|
-
)
|
|
508
|
-
]
|
|
519
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
520
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
521
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
509
522
|
],
|
|
510
|
-
|
|
511
|
-
description:
|
|
512
|
-
} : void 0
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
function getInstructionCodec() {
|
|
516
|
-
return umiSerializers.mapSerializer(
|
|
517
|
-
umiSerializers.struct([
|
|
518
|
-
[
|
|
519
|
-
"programAddressIndex",
|
|
520
|
-
umiSerializers.u8(
|
|
521
|
-
__DEV__ ? {
|
|
522
|
-
description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
|
|
523
|
-
} : void 0
|
|
524
|
-
)
|
|
525
|
-
],
|
|
526
|
-
[
|
|
527
|
-
"accountIndices",
|
|
528
|
-
umiSerializers.array(
|
|
529
|
-
umiSerializers.u8({
|
|
530
|
-
description: __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : ""
|
|
531
|
-
}),
|
|
532
|
-
{
|
|
533
|
-
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" : "",
|
|
534
|
-
size: umiSerializers.shortU16()
|
|
535
|
-
}
|
|
536
|
-
)
|
|
537
|
-
],
|
|
538
|
-
[
|
|
539
|
-
"data",
|
|
540
|
-
umiSerializers.bytes({
|
|
541
|
-
description: __DEV__ ? "An optional buffer of data passed to the instruction" : "",
|
|
542
|
-
size: umiSerializers.shortU16()
|
|
543
|
-
})
|
|
544
|
-
]
|
|
545
|
-
]),
|
|
546
|
-
(value) => {
|
|
547
|
-
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
548
|
-
return value;
|
|
549
|
-
}
|
|
550
|
-
return {
|
|
551
|
-
...value,
|
|
552
|
-
accountIndices: value.accountIndices ?? [],
|
|
553
|
-
data: value.data ?? new Uint8Array(0)
|
|
554
|
-
};
|
|
555
|
-
},
|
|
556
|
-
(value) => {
|
|
557
|
-
if (value.accountIndices.length && value.data.byteLength) {
|
|
558
|
-
return value;
|
|
559
|
-
}
|
|
560
|
-
const { accountIndices, data, ...rest } = value;
|
|
561
|
-
return {
|
|
562
|
-
...rest,
|
|
563
|
-
...accountIndices.length ? { accountIndices } : null,
|
|
564
|
-
...data.byteLength ? { data } : null
|
|
565
|
-
};
|
|
523
|
+
{
|
|
524
|
+
description: messageHeaderDescription
|
|
566
525
|
}
|
|
567
526
|
);
|
|
568
527
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
)
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
528
|
+
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
529
|
+
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
530
|
+
var accountIndicesDescription = __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" : "accountIndices";
|
|
531
|
+
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
532
|
+
var memoizedGetInstructionEncoder;
|
|
533
|
+
function getInstructionEncoder() {
|
|
534
|
+
if (!memoizedGetInstructionEncoder) {
|
|
535
|
+
memoizedGetInstructionEncoder = codecsCore.mapEncoder(
|
|
536
|
+
codecsDataStructures.getStructEncoder([
|
|
537
|
+
["programAddressIndex", codecsNumbers.getU8Encoder({ description: programAddressIndexDescription })],
|
|
538
|
+
[
|
|
539
|
+
"accountIndices",
|
|
540
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
|
|
541
|
+
description: accountIndicesDescription,
|
|
542
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
543
|
+
})
|
|
544
|
+
],
|
|
545
|
+
["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
|
|
546
|
+
]),
|
|
547
|
+
// Convert an instruction to have all fields defined
|
|
548
|
+
(instruction) => {
|
|
549
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
550
|
+
return instruction;
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
...instruction,
|
|
554
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
555
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
return memoizedGetInstructionEncoder;
|
|
581
561
|
}
|
|
582
|
-
|
|
583
|
-
// src/serializers/transaction-version.ts
|
|
584
562
|
var VERSION_FLAG_MASK = 128;
|
|
585
563
|
var BASE_CONFIG = {
|
|
586
564
|
description: __DEV__ ? "A single byte that encodes the version of the transaction" : "",
|
|
587
565
|
fixedSize: null,
|
|
588
566
|
maxSize: 1
|
|
589
567
|
};
|
|
590
|
-
function
|
|
591
|
-
const firstByte = bytes3[offset];
|
|
592
|
-
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
593
|
-
return ["legacy", offset];
|
|
594
|
-
} else {
|
|
595
|
-
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
596
|
-
return [version, offset + 1];
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
function serialize(value) {
|
|
568
|
+
function encode(value) {
|
|
600
569
|
if (value === "legacy") {
|
|
601
570
|
return new Uint8Array();
|
|
602
571
|
}
|
|
@@ -605,132 +574,117 @@ function serialize(value) {
|
|
|
605
574
|
}
|
|
606
575
|
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
607
576
|
}
|
|
608
|
-
function
|
|
577
|
+
function getTransactionVersionEncoder() {
|
|
609
578
|
return {
|
|
610
579
|
...BASE_CONFIG,
|
|
611
|
-
|
|
612
|
-
serialize
|
|
580
|
+
encode
|
|
613
581
|
};
|
|
614
582
|
}
|
|
615
583
|
|
|
616
584
|
// src/serializers/message.ts
|
|
617
|
-
var
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
(value)
|
|
632
|
-
|
|
633
|
-
return value;
|
|
634
|
-
}
|
|
635
|
-
return {
|
|
636
|
-
...value,
|
|
637
|
-
addressTableLookups: value.addressTableLookups ?? []
|
|
638
|
-
};
|
|
585
|
+
var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
|
|
586
|
+
var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
|
|
587
|
+
var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
|
|
588
|
+
var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
|
|
589
|
+
function getCompiledMessageLegacyEncoder() {
|
|
590
|
+
return codecsDataStructures.getStructEncoder(getPreludeStructEncoderTuple());
|
|
591
|
+
}
|
|
592
|
+
function getCompiledMessageVersionedEncoder() {
|
|
593
|
+
return codecsCore.mapEncoder(
|
|
594
|
+
codecsDataStructures.getStructEncoder([
|
|
595
|
+
...getPreludeStructEncoderTuple(),
|
|
596
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
597
|
+
]),
|
|
598
|
+
(value) => {
|
|
599
|
+
if (value.version === "legacy") {
|
|
600
|
+
return value;
|
|
639
601
|
}
|
|
640
|
-
|
|
641
|
-
|
|
602
|
+
return {
|
|
603
|
+
...value,
|
|
604
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
);
|
|
642
608
|
}
|
|
643
|
-
function
|
|
609
|
+
function getPreludeStructEncoderTuple() {
|
|
644
610
|
return [
|
|
645
|
-
["version",
|
|
646
|
-
["header",
|
|
611
|
+
["version", getTransactionVersionEncoder()],
|
|
612
|
+
["header", getMessageHeaderEncoder()],
|
|
647
613
|
[
|
|
648
614
|
"staticAccounts",
|
|
649
|
-
|
|
650
|
-
description:
|
|
651
|
-
size:
|
|
615
|
+
codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), {
|
|
616
|
+
description: staticAccountsDescription,
|
|
617
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
652
618
|
})
|
|
653
619
|
],
|
|
654
620
|
[
|
|
655
621
|
"lifetimeToken",
|
|
656
|
-
|
|
657
|
-
description:
|
|
658
|
-
encoding:
|
|
622
|
+
codecsStrings.getStringEncoder({
|
|
623
|
+
description: lifetimeTokenDescription,
|
|
624
|
+
encoding: codecsStrings.getBase58Encoder(),
|
|
659
625
|
size: 32
|
|
660
626
|
})
|
|
661
627
|
],
|
|
662
628
|
[
|
|
663
629
|
"instructions",
|
|
664
|
-
|
|
665
|
-
description:
|
|
666
|
-
size:
|
|
630
|
+
codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
|
|
631
|
+
description: instructionsDescription,
|
|
632
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
667
633
|
})
|
|
668
634
|
]
|
|
669
635
|
];
|
|
670
636
|
}
|
|
671
|
-
function
|
|
672
|
-
return
|
|
673
|
-
|
|
674
|
-
size:
|
|
637
|
+
function getAddressTableLookupArrayEncoder() {
|
|
638
|
+
return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
639
|
+
description: addressTableLookupsDescription,
|
|
640
|
+
size: codecsNumbers.getShortU16Encoder()
|
|
675
641
|
});
|
|
676
642
|
}
|
|
643
|
+
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
677
644
|
function getCompiledMessageEncoder() {
|
|
678
645
|
return {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
646
|
+
description: messageDescription,
|
|
647
|
+
encode: (compiledMessage) => {
|
|
648
|
+
if (compiledMessage.version === "legacy") {
|
|
649
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
650
|
+
} else {
|
|
651
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
fixedSize: null,
|
|
655
|
+
maxSize: null
|
|
682
656
|
};
|
|
683
657
|
}
|
|
684
658
|
|
|
685
|
-
// src/
|
|
686
|
-
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
async function signTransaction(keyPair, transaction) {
|
|
692
|
-
const compiledMessage = compileMessage(transaction);
|
|
693
|
-
const [signerPublicKey, signature] = await Promise.all([
|
|
694
|
-
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
695
|
-
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
696
|
-
]);
|
|
697
|
-
const nextSignatures = {
|
|
698
|
-
..."signatures" in transaction ? transaction.signatures : null,
|
|
699
|
-
...{ [signerPublicKey]: signature }
|
|
700
|
-
};
|
|
701
|
-
const out = {
|
|
702
|
-
...transaction,
|
|
703
|
-
signatures: nextSignatures
|
|
704
|
-
};
|
|
705
|
-
Object.freeze(out);
|
|
706
|
-
return out;
|
|
659
|
+
// src/serializers/unimplemented.ts
|
|
660
|
+
function getError(type, name) {
|
|
661
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
662
|
+
return new Error(
|
|
663
|
+
`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}`
|
|
664
|
+
);
|
|
707
665
|
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
const compiledMessage = compileMessage(transaction);
|
|
712
|
-
let signatures;
|
|
713
|
-
if ("signatures" in transaction) {
|
|
714
|
-
signatures = [];
|
|
715
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
716
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
717
|
-
}
|
|
718
|
-
} else {
|
|
719
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
720
|
-
}
|
|
721
|
-
return {
|
|
722
|
-
compiledMessage,
|
|
723
|
-
signatures
|
|
666
|
+
function getUnimplementedDecoder(name) {
|
|
667
|
+
return () => {
|
|
668
|
+
throw getError("decoder", name);
|
|
724
669
|
};
|
|
725
670
|
}
|
|
726
671
|
|
|
727
672
|
// src/serializers/transaction.ts
|
|
728
|
-
var
|
|
673
|
+
var BASE_CONFIG2 = {
|
|
729
674
|
description: __DEV__ ? "The wire format of a Solana transaction" : "",
|
|
730
675
|
fixedSize: null,
|
|
731
676
|
maxSize: null
|
|
732
677
|
};
|
|
733
|
-
function
|
|
678
|
+
function toSerializer(encoder) {
|
|
679
|
+
return {
|
|
680
|
+
description: encoder.description,
|
|
681
|
+
deserialize: getUnimplementedDecoder(encoder.description),
|
|
682
|
+
fixedSize: encoder.fixedSize,
|
|
683
|
+
maxSize: encoder.maxSize,
|
|
684
|
+
serialize: encoder.encode
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
function serialize(transaction) {
|
|
734
688
|
const compiledTransaction = getCompiledTransaction(transaction);
|
|
735
689
|
return umiSerializers.struct([
|
|
736
690
|
[
|
|
@@ -740,16 +694,91 @@ function serialize3(transaction) {
|
|
|
740
694
|
size: umiSerializers.shortU16()
|
|
741
695
|
})
|
|
742
696
|
],
|
|
743
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
697
|
+
["compiledMessage", toSerializer(getCompiledMessageEncoder())]
|
|
744
698
|
]).serialize(compiledTransaction);
|
|
745
699
|
}
|
|
746
700
|
function getTransactionEncoder() {
|
|
747
701
|
return {
|
|
748
|
-
...
|
|
702
|
+
...BASE_CONFIG2,
|
|
749
703
|
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
750
|
-
serialize
|
|
704
|
+
serialize
|
|
751
705
|
};
|
|
752
706
|
}
|
|
707
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
708
|
+
try {
|
|
709
|
+
if (
|
|
710
|
+
// Lowest value (64 bytes of zeroes)
|
|
711
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
712
|
+
putativeTransactionSignature.length > 88
|
|
713
|
+
) {
|
|
714
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
715
|
+
}
|
|
716
|
+
const bytes2 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
717
|
+
const numBytes = bytes2.byteLength;
|
|
718
|
+
if (numBytes !== 64) {
|
|
719
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
720
|
+
}
|
|
721
|
+
} catch (e) {
|
|
722
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
723
|
+
cause: e
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
728
|
+
if (
|
|
729
|
+
// Lowest value (64 bytes of zeroes)
|
|
730
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
731
|
+
putativeTransactionSignature.length > 88
|
|
732
|
+
) {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
const bytes2 = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
736
|
+
const numBytes = bytes2.byteLength;
|
|
737
|
+
if (numBytes !== 64) {
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
return true;
|
|
741
|
+
}
|
|
742
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
743
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(message);
|
|
744
|
+
const signature = await keys.signBytes(secretKey, wireMessageBytes);
|
|
745
|
+
return signature;
|
|
746
|
+
}
|
|
747
|
+
function getSignatureFromTransaction(transaction) {
|
|
748
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
749
|
+
if (!signatureBytes) {
|
|
750
|
+
throw new Error(
|
|
751
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
const transactionSignature2 = umiSerializers.base58.deserialize(signatureBytes)[0];
|
|
755
|
+
return transactionSignature2;
|
|
756
|
+
}
|
|
757
|
+
async function signTransaction(keyPairs, transaction) {
|
|
758
|
+
const compiledMessage = compileMessage(transaction);
|
|
759
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
760
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
761
|
+
keyPairs.map(
|
|
762
|
+
(keyPair) => Promise.all([
|
|
763
|
+
addresses.getAddressFromPublicKey(keyPair.publicKey),
|
|
764
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
765
|
+
])
|
|
766
|
+
)
|
|
767
|
+
);
|
|
768
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
769
|
+
nextSignatures[signerPublicKey] = signature;
|
|
770
|
+
}
|
|
771
|
+
const out = {
|
|
772
|
+
...transaction,
|
|
773
|
+
signatures: nextSignatures
|
|
774
|
+
};
|
|
775
|
+
Object.freeze(out);
|
|
776
|
+
return out;
|
|
777
|
+
}
|
|
778
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
779
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
780
|
+
return putativeTransactionSignature;
|
|
781
|
+
}
|
|
753
782
|
|
|
754
783
|
// src/wire-transaction.ts
|
|
755
784
|
function getBase64EncodedWireTransaction(transaction) {
|
|
@@ -762,12 +791,16 @@ function getBase64EncodedWireTransaction(transaction) {
|
|
|
762
791
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
763
792
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
764
793
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
794
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
765
795
|
exports.createTransaction = createTransaction;
|
|
766
796
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
797
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
798
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
799
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
800
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
767
801
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
768
802
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
769
803
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
770
804
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
771
805
|
exports.signTransaction = signTransaction;
|
|
772
|
-
|
|
773
|
-
//# sourceMappingURL=index.browser.cjs.map
|
|
806
|
+
exports.transactionSignature = transactionSignature;
|