@solana/web3.js 1.77.3 → 1.77.4
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 +50 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +50 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +50 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +50 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +50 -32
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +50 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +21 -21
- 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.esm.js
CHANGED
|
@@ -665,6 +665,31 @@ class CompiledKeys {
|
|
|
665
665
|
}
|
|
666
666
|
}
|
|
667
667
|
|
|
668
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
672
|
+
*/
|
|
673
|
+
function guardedShift(byteArray) {
|
|
674
|
+
if (byteArray.length === 0) {
|
|
675
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
676
|
+
}
|
|
677
|
+
return byteArray.shift();
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
682
|
+
* the array.
|
|
683
|
+
*/
|
|
684
|
+
function guardedSplice(byteArray, ...args) {
|
|
685
|
+
const [start] = args;
|
|
686
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
687
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
688
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
689
|
+
}
|
|
690
|
+
return byteArray.splice(...args);
|
|
691
|
+
}
|
|
692
|
+
|
|
668
693
|
/**
|
|
669
694
|
* An instruction to execute by a program
|
|
670
695
|
*
|
|
@@ -802,32 +827,28 @@ class Message {
|
|
|
802
827
|
static from(buffer) {
|
|
803
828
|
// Slice up wire data
|
|
804
829
|
let byteArray = [...buffer];
|
|
805
|
-
const numRequiredSignatures = byteArray
|
|
830
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
806
831
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
807
832
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
808
833
|
}
|
|
809
|
-
const numReadonlySignedAccounts = byteArray
|
|
810
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
834
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
835
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
811
836
|
const accountCount = decodeLength(byteArray);
|
|
812
837
|
let accountKeys = [];
|
|
813
838
|
for (let i = 0; i < accountCount; i++) {
|
|
814
|
-
const account = byteArray
|
|
815
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
839
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
816
840
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
817
841
|
}
|
|
818
|
-
const recentBlockhash = byteArray
|
|
819
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
842
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
820
843
|
const instructionCount = decodeLength(byteArray);
|
|
821
844
|
let instructions = [];
|
|
822
845
|
for (let i = 0; i < instructionCount; i++) {
|
|
823
|
-
const programIdIndex = byteArray
|
|
846
|
+
const programIdIndex = guardedShift(byteArray);
|
|
824
847
|
const accountCount = decodeLength(byteArray);
|
|
825
|
-
const accounts = byteArray
|
|
826
|
-
byteArray = byteArray.slice(accountCount);
|
|
848
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
827
849
|
const dataLength = decodeLength(byteArray);
|
|
828
|
-
const dataSlice = byteArray
|
|
850
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
829
851
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
830
|
-
byteArray = byteArray.slice(dataLength);
|
|
831
852
|
instructions.push({
|
|
832
853
|
programIdIndex,
|
|
833
854
|
accounts,
|
|
@@ -1032,30 +1053,30 @@ class MessageV0 {
|
|
|
1032
1053
|
}
|
|
1033
1054
|
static deserialize(serializedMessage) {
|
|
1034
1055
|
let byteArray = [...serializedMessage];
|
|
1035
|
-
const prefix = byteArray
|
|
1056
|
+
const prefix = guardedShift(byteArray);
|
|
1036
1057
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1037
1058
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1038
1059
|
const version = maskedPrefix;
|
|
1039
1060
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1040
1061
|
const header = {
|
|
1041
|
-
numRequiredSignatures: byteArray
|
|
1042
|
-
numReadonlySignedAccounts: byteArray
|
|
1043
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1062
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1063
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1064
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1044
1065
|
};
|
|
1045
1066
|
const staticAccountKeys = [];
|
|
1046
1067
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1047
1068
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1048
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1069
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1049
1070
|
}
|
|
1050
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1071
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1051
1072
|
const instructionCount = decodeLength(byteArray);
|
|
1052
1073
|
const compiledInstructions = [];
|
|
1053
1074
|
for (let i = 0; i < instructionCount; i++) {
|
|
1054
|
-
const programIdIndex = byteArray
|
|
1075
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1055
1076
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1056
|
-
const accountKeyIndexes = byteArray
|
|
1077
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1057
1078
|
const dataLength = decodeLength(byteArray);
|
|
1058
|
-
const data = new Uint8Array(byteArray
|
|
1079
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1059
1080
|
compiledInstructions.push({
|
|
1060
1081
|
programIdIndex,
|
|
1061
1082
|
accountKeyIndexes,
|
|
@@ -1065,11 +1086,11 @@ class MessageV0 {
|
|
|
1065
1086
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1066
1087
|
const addressTableLookups = [];
|
|
1067
1088
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1068
|
-
const accountKey = new PublicKey(byteArray
|
|
1089
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1069
1090
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1070
|
-
const writableIndexes = byteArray
|
|
1091
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1071
1092
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1072
|
-
const readonlyIndexes = byteArray
|
|
1093
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1073
1094
|
addressTableLookups.push({
|
|
1074
1095
|
accountKey,
|
|
1075
1096
|
writableIndexes,
|
|
@@ -1752,8 +1773,7 @@ class Transaction {
|
|
|
1752
1773
|
const signatureCount = decodeLength(byteArray);
|
|
1753
1774
|
let signatures = [];
|
|
1754
1775
|
for (let i = 0; i < signatureCount; i++) {
|
|
1755
|
-
const signature = byteArray
|
|
1756
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1776
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1757
1777
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1758
1778
|
}
|
|
1759
1779
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -1923,7 +1943,7 @@ class VersionedTransaction {
|
|
|
1923
1943
|
const signatures = [];
|
|
1924
1944
|
const signaturesLength = decodeLength(byteArray);
|
|
1925
1945
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1926
|
-
signatures.push(new Uint8Array(byteArray
|
|
1946
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1927
1947
|
}
|
|
1928
1948
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1929
1949
|
return new VersionedTransaction(message, signatures);
|
|
@@ -4441,7 +4461,7 @@ const LogsNotificationResult = type({
|
|
|
4441
4461
|
|
|
4442
4462
|
/** @internal */
|
|
4443
4463
|
const COMMON_HTTP_HEADERS = {
|
|
4444
|
-
'solana-client': `js/${"
|
|
4464
|
+
'solana-client': `js/${"1.77.4" }`
|
|
4445
4465
|
};
|
|
4446
4466
|
|
|
4447
4467
|
/**
|
|
@@ -9231,10 +9251,8 @@ class ValidatorInfo {
|
|
|
9231
9251
|
if (configKeyCount !== 2) return null;
|
|
9232
9252
|
const configKeys = [];
|
|
9233
9253
|
for (let i = 0; i < 2; i++) {
|
|
9234
|
-
const publicKey = new PublicKey(byteArray
|
|
9235
|
-
|
|
9236
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9237
|
-
byteArray = byteArray.slice(1);
|
|
9254
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9255
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9238
9256
|
configKeys.push({
|
|
9239
9257
|
publicKey,
|
|
9240
9258
|
isSigner
|