@solana/web3.js 1.55.0 → 1.55.1
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/lib/index.browser.cjs.js +63 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +63 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +63 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +63 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +63 -32
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +63 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- package/src/message/legacy.ts +9 -12
- package/src/message/v0.ts +29 -12
- package/src/transaction/legacy.ts +2 -2
- package/src/transaction/versioned.ts +2 -1
- package/src/utils/guarded-array-utils.ts +34 -0
- package/src/validator-info.ts +5 -4
package/lib/index.esm.js
CHANGED
|
@@ -534,6 +534,44 @@ function encodeLength(bytes, len) {
|
|
|
534
534
|
}
|
|
535
535
|
}
|
|
536
536
|
|
|
537
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
538
|
+
/**
|
|
539
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
540
|
+
*/
|
|
541
|
+
|
|
542
|
+
function guardedShift(byteArray) {
|
|
543
|
+
if (byteArray.length === 0) {
|
|
544
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return byteArray.shift();
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
551
|
+
* the array.
|
|
552
|
+
*/
|
|
553
|
+
|
|
554
|
+
function guardedSplice(byteArray, ...args) {
|
|
555
|
+
var _args$;
|
|
556
|
+
|
|
557
|
+
const [start] = args;
|
|
558
|
+
|
|
559
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
560
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
561
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
return byteArray.splice(...args);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* An instruction to execute by a program
|
|
569
|
+
*
|
|
570
|
+
* @property {number} programIdIndex
|
|
571
|
+
* @property {number[]} accounts
|
|
572
|
+
* @property {string} data
|
|
573
|
+
*/
|
|
574
|
+
|
|
537
575
|
/**
|
|
538
576
|
* List of instructions to be processed atomically
|
|
539
577
|
*/
|
|
@@ -646,37 +684,33 @@ class Message {
|
|
|
646
684
|
static from(buffer) {
|
|
647
685
|
// Slice up wire data
|
|
648
686
|
let byteArray = [...buffer];
|
|
649
|
-
const numRequiredSignatures = byteArray
|
|
687
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
650
688
|
|
|
651
689
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
652
690
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
653
691
|
}
|
|
654
692
|
|
|
655
|
-
const numReadonlySignedAccounts = byteArray
|
|
656
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
693
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
694
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
657
695
|
const accountCount = decodeLength(byteArray);
|
|
658
696
|
let accountKeys = [];
|
|
659
697
|
|
|
660
698
|
for (let i = 0; i < accountCount; i++) {
|
|
661
|
-
const account = byteArray
|
|
662
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
699
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
663
700
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
664
701
|
}
|
|
665
702
|
|
|
666
|
-
const recentBlockhash = byteArray
|
|
667
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
703
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
668
704
|
const instructionCount = decodeLength(byteArray);
|
|
669
705
|
let instructions = [];
|
|
670
706
|
|
|
671
707
|
for (let i = 0; i < instructionCount; i++) {
|
|
672
|
-
const programIdIndex = byteArray
|
|
708
|
+
const programIdIndex = guardedShift(byteArray);
|
|
673
709
|
const accountCount = decodeLength(byteArray);
|
|
674
|
-
const accounts = byteArray
|
|
675
|
-
byteArray = byteArray.slice(accountCount);
|
|
710
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
676
711
|
const dataLength = decodeLength(byteArray);
|
|
677
|
-
const dataSlice = byteArray
|
|
712
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
678
713
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
679
|
-
byteArray = byteArray.slice(dataLength);
|
|
680
714
|
instructions.push({
|
|
681
715
|
programIdIndex,
|
|
682
716
|
accounts,
|
|
@@ -799,33 +833,33 @@ class MessageV0 {
|
|
|
799
833
|
|
|
800
834
|
static deserialize(serializedMessage) {
|
|
801
835
|
let byteArray = [...serializedMessage];
|
|
802
|
-
const prefix = byteArray
|
|
836
|
+
const prefix = guardedShift(byteArray);
|
|
803
837
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
804
838
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
805
839
|
const version = maskedPrefix;
|
|
806
840
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
807
841
|
const header = {
|
|
808
|
-
numRequiredSignatures: byteArray
|
|
809
|
-
numReadonlySignedAccounts: byteArray
|
|
810
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
842
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
843
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
844
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
811
845
|
};
|
|
812
846
|
const staticAccountKeys = [];
|
|
813
847
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
814
848
|
|
|
815
849
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
816
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
850
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
817
851
|
}
|
|
818
852
|
|
|
819
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
853
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
820
854
|
const instructionCount = decodeLength(byteArray);
|
|
821
855
|
const compiledInstructions = [];
|
|
822
856
|
|
|
823
857
|
for (let i = 0; i < instructionCount; i++) {
|
|
824
|
-
const programIdIndex = byteArray
|
|
858
|
+
const programIdIndex = guardedShift(byteArray);
|
|
825
859
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
826
|
-
const accountKeyIndexes = byteArray
|
|
860
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
827
861
|
const dataLength = decodeLength(byteArray);
|
|
828
|
-
const data = new Uint8Array(byteArray
|
|
862
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
829
863
|
compiledInstructions.push({
|
|
830
864
|
programIdIndex,
|
|
831
865
|
accountKeyIndexes,
|
|
@@ -837,11 +871,11 @@ class MessageV0 {
|
|
|
837
871
|
const addressTableLookups = [];
|
|
838
872
|
|
|
839
873
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
840
|
-
const accountKey = new PublicKey(byteArray
|
|
874
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
841
875
|
const writableIndexesLength = decodeLength(byteArray);
|
|
842
|
-
const writableIndexes = byteArray
|
|
876
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
843
877
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
844
|
-
const readonlyIndexes = byteArray
|
|
878
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
845
879
|
addressTableLookups.push({
|
|
846
880
|
accountKey,
|
|
847
881
|
writableIndexes,
|
|
@@ -1572,8 +1606,7 @@ class Transaction {
|
|
|
1572
1606
|
let signatures = [];
|
|
1573
1607
|
|
|
1574
1608
|
for (let i = 0; i < signatureCount; i++) {
|
|
1575
|
-
const signature = byteArray
|
|
1576
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1609
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1577
1610
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1578
1611
|
}
|
|
1579
1612
|
|
|
@@ -1665,7 +1698,7 @@ class VersionedTransaction {
|
|
|
1665
1698
|
const signaturesLength = decodeLength(byteArray);
|
|
1666
1699
|
|
|
1667
1700
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1668
|
-
signatures.push(new Uint8Array(byteArray
|
|
1701
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1669
1702
|
}
|
|
1670
1703
|
|
|
1671
1704
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4089,7 +4122,7 @@ const LogsNotificationResult = type({
|
|
|
4089
4122
|
|
|
4090
4123
|
/** @internal */
|
|
4091
4124
|
const COMMON_HTTP_HEADERS = {
|
|
4092
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4125
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.55.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4093
4126
|
};
|
|
4094
4127
|
/**
|
|
4095
4128
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -8843,10 +8876,8 @@ class ValidatorInfo {
|
|
|
8843
8876
|
const configKeys = [];
|
|
8844
8877
|
|
|
8845
8878
|
for (let i = 0; i < 2; i++) {
|
|
8846
|
-
const publicKey = new PublicKey(byteArray
|
|
8847
|
-
|
|
8848
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8849
|
-
byteArray = byteArray.slice(1);
|
|
8879
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
8880
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8850
8881
|
configKeys.push({
|
|
8851
8882
|
publicKey,
|
|
8852
8883
|
isSigner
|