@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.browser.cjs.js
CHANGED
|
@@ -562,6 +562,44 @@ function encodeLength(bytes, len) {
|
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
566
|
+
/**
|
|
567
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
568
|
+
*/
|
|
569
|
+
|
|
570
|
+
function guardedShift(byteArray) {
|
|
571
|
+
if (byteArray.length === 0) {
|
|
572
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return byteArray.shift();
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
579
|
+
* the array.
|
|
580
|
+
*/
|
|
581
|
+
|
|
582
|
+
function guardedSplice(byteArray, ...args) {
|
|
583
|
+
var _args$;
|
|
584
|
+
|
|
585
|
+
const [start] = args;
|
|
586
|
+
|
|
587
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
588
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
589
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return byteArray.splice(...args);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
* An instruction to execute by a program
|
|
597
|
+
*
|
|
598
|
+
* @property {number} programIdIndex
|
|
599
|
+
* @property {number[]} accounts
|
|
600
|
+
* @property {string} data
|
|
601
|
+
*/
|
|
602
|
+
|
|
565
603
|
/**
|
|
566
604
|
* List of instructions to be processed atomically
|
|
567
605
|
*/
|
|
@@ -674,37 +712,33 @@ class Message {
|
|
|
674
712
|
static from(buffer$1) {
|
|
675
713
|
// Slice up wire data
|
|
676
714
|
let byteArray = [...buffer$1];
|
|
677
|
-
const numRequiredSignatures = byteArray
|
|
715
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
678
716
|
|
|
679
717
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
680
718
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
681
719
|
}
|
|
682
720
|
|
|
683
|
-
const numReadonlySignedAccounts = byteArray
|
|
684
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
721
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
722
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
685
723
|
const accountCount = decodeLength(byteArray);
|
|
686
724
|
let accountKeys = [];
|
|
687
725
|
|
|
688
726
|
for (let i = 0; i < accountCount; i++) {
|
|
689
|
-
const account = byteArray
|
|
690
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
727
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
691
728
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
692
729
|
}
|
|
693
730
|
|
|
694
|
-
const recentBlockhash = byteArray
|
|
695
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
731
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
696
732
|
const instructionCount = decodeLength(byteArray);
|
|
697
733
|
let instructions = [];
|
|
698
734
|
|
|
699
735
|
for (let i = 0; i < instructionCount; i++) {
|
|
700
|
-
const programIdIndex = byteArray
|
|
736
|
+
const programIdIndex = guardedShift(byteArray);
|
|
701
737
|
const accountCount = decodeLength(byteArray);
|
|
702
|
-
const accounts = byteArray
|
|
703
|
-
byteArray = byteArray.slice(accountCount);
|
|
738
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
704
739
|
const dataLength = decodeLength(byteArray);
|
|
705
|
-
const dataSlice = byteArray
|
|
740
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
706
741
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
707
|
-
byteArray = byteArray.slice(dataLength);
|
|
708
742
|
instructions.push({
|
|
709
743
|
programIdIndex,
|
|
710
744
|
accounts,
|
|
@@ -827,33 +861,33 @@ class MessageV0 {
|
|
|
827
861
|
|
|
828
862
|
static deserialize(serializedMessage) {
|
|
829
863
|
let byteArray = [...serializedMessage];
|
|
830
|
-
const prefix = byteArray
|
|
864
|
+
const prefix = guardedShift(byteArray);
|
|
831
865
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
832
866
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
833
867
|
const version = maskedPrefix;
|
|
834
868
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
835
869
|
const header = {
|
|
836
|
-
numRequiredSignatures: byteArray
|
|
837
|
-
numReadonlySignedAccounts: byteArray
|
|
838
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
870
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
871
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
872
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
839
873
|
};
|
|
840
874
|
const staticAccountKeys = [];
|
|
841
875
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
842
876
|
|
|
843
877
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
844
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
878
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
845
879
|
}
|
|
846
880
|
|
|
847
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
881
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
848
882
|
const instructionCount = decodeLength(byteArray);
|
|
849
883
|
const compiledInstructions = [];
|
|
850
884
|
|
|
851
885
|
for (let i = 0; i < instructionCount; i++) {
|
|
852
|
-
const programIdIndex = byteArray
|
|
886
|
+
const programIdIndex = guardedShift(byteArray);
|
|
853
887
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
854
|
-
const accountKeyIndexes = byteArray
|
|
888
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
855
889
|
const dataLength = decodeLength(byteArray);
|
|
856
|
-
const data = new Uint8Array(byteArray
|
|
890
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
857
891
|
compiledInstructions.push({
|
|
858
892
|
programIdIndex,
|
|
859
893
|
accountKeyIndexes,
|
|
@@ -865,11 +899,11 @@ class MessageV0 {
|
|
|
865
899
|
const addressTableLookups = [];
|
|
866
900
|
|
|
867
901
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
868
|
-
const accountKey = new PublicKey(byteArray
|
|
902
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
869
903
|
const writableIndexesLength = decodeLength(byteArray);
|
|
870
|
-
const writableIndexes = byteArray
|
|
904
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
871
905
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
872
|
-
const readonlyIndexes = byteArray
|
|
906
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
873
907
|
addressTableLookups.push({
|
|
874
908
|
accountKey,
|
|
875
909
|
writableIndexes,
|
|
@@ -1600,8 +1634,7 @@ class Transaction {
|
|
|
1600
1634
|
let signatures = [];
|
|
1601
1635
|
|
|
1602
1636
|
for (let i = 0; i < signatureCount; i++) {
|
|
1603
|
-
const signature = byteArray
|
|
1604
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1637
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1605
1638
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1606
1639
|
}
|
|
1607
1640
|
|
|
@@ -1693,7 +1726,7 @@ class VersionedTransaction {
|
|
|
1693
1726
|
const signaturesLength = decodeLength(byteArray);
|
|
1694
1727
|
|
|
1695
1728
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1696
|
-
signatures.push(new Uint8Array(byteArray
|
|
1729
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1697
1730
|
}
|
|
1698
1731
|
|
|
1699
1732
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4057,7 +4090,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4057
4090
|
|
|
4058
4091
|
/** @internal */
|
|
4059
4092
|
const COMMON_HTTP_HEADERS = {
|
|
4060
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4093
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.55.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4061
4094
|
};
|
|
4062
4095
|
/**
|
|
4063
4096
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -8811,10 +8844,8 @@ class ValidatorInfo {
|
|
|
8811
8844
|
const configKeys = [];
|
|
8812
8845
|
|
|
8813
8846
|
for (let i = 0; i < 2; i++) {
|
|
8814
|
-
const publicKey = new PublicKey(byteArray
|
|
8815
|
-
|
|
8816
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
8817
|
-
byteArray = byteArray.slice(1);
|
|
8847
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
8848
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
8818
8849
|
configKeys.push({
|
|
8819
8850
|
publicKey,
|
|
8820
8851
|
isSigner
|