@solana/web3.js 1.76.0 → 1.76.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 +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.native.js
CHANGED
|
@@ -693,6 +693,31 @@ class CompiledKeys {
|
|
|
693
693
|
}
|
|
694
694
|
}
|
|
695
695
|
|
|
696
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
700
|
+
*/
|
|
701
|
+
function guardedShift(byteArray) {
|
|
702
|
+
if (byteArray.length === 0) {
|
|
703
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
704
|
+
}
|
|
705
|
+
return byteArray.shift();
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
710
|
+
* the array.
|
|
711
|
+
*/
|
|
712
|
+
function guardedSplice(byteArray, ...args) {
|
|
713
|
+
const [start] = args;
|
|
714
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
715
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
716
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
717
|
+
}
|
|
718
|
+
return byteArray.splice(...args);
|
|
719
|
+
}
|
|
720
|
+
|
|
696
721
|
/**
|
|
697
722
|
* An instruction to execute by a program
|
|
698
723
|
*
|
|
@@ -830,32 +855,28 @@ class Message {
|
|
|
830
855
|
static from(buffer$1) {
|
|
831
856
|
// Slice up wire data
|
|
832
857
|
let byteArray = [...buffer$1];
|
|
833
|
-
const numRequiredSignatures = byteArray
|
|
858
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
834
859
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
835
860
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
836
861
|
}
|
|
837
|
-
const numReadonlySignedAccounts = byteArray
|
|
838
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
862
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
863
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
839
864
|
const accountCount = decodeLength(byteArray);
|
|
840
865
|
let accountKeys = [];
|
|
841
866
|
for (let i = 0; i < accountCount; i++) {
|
|
842
|
-
const account = byteArray
|
|
843
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
867
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
844
868
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
845
869
|
}
|
|
846
|
-
const recentBlockhash = byteArray
|
|
847
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
870
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
848
871
|
const instructionCount = decodeLength(byteArray);
|
|
849
872
|
let instructions = [];
|
|
850
873
|
for (let i = 0; i < instructionCount; i++) {
|
|
851
|
-
const programIdIndex = byteArray
|
|
874
|
+
const programIdIndex = guardedShift(byteArray);
|
|
852
875
|
const accountCount = decodeLength(byteArray);
|
|
853
|
-
const accounts = byteArray
|
|
854
|
-
byteArray = byteArray.slice(accountCount);
|
|
876
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
855
877
|
const dataLength = decodeLength(byteArray);
|
|
856
|
-
const dataSlice = byteArray
|
|
878
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
857
879
|
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
858
|
-
byteArray = byteArray.slice(dataLength);
|
|
859
880
|
instructions.push({
|
|
860
881
|
programIdIndex,
|
|
861
882
|
accounts,
|
|
@@ -1060,30 +1081,30 @@ class MessageV0 {
|
|
|
1060
1081
|
}
|
|
1061
1082
|
static deserialize(serializedMessage) {
|
|
1062
1083
|
let byteArray = [...serializedMessage];
|
|
1063
|
-
const prefix = byteArray
|
|
1084
|
+
const prefix = guardedShift(byteArray);
|
|
1064
1085
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1065
1086
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1066
1087
|
const version = maskedPrefix;
|
|
1067
1088
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1068
1089
|
const header = {
|
|
1069
|
-
numRequiredSignatures: byteArray
|
|
1070
|
-
numReadonlySignedAccounts: byteArray
|
|
1071
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1090
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1091
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1092
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1072
1093
|
};
|
|
1073
1094
|
const staticAccountKeys = [];
|
|
1074
1095
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1075
1096
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1076
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1097
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1077
1098
|
}
|
|
1078
|
-
const recentBlockhash = bs58__default.default.encode(byteArray
|
|
1099
|
+
const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1079
1100
|
const instructionCount = decodeLength(byteArray);
|
|
1080
1101
|
const compiledInstructions = [];
|
|
1081
1102
|
for (let i = 0; i < instructionCount; i++) {
|
|
1082
|
-
const programIdIndex = byteArray
|
|
1103
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1083
1104
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1084
|
-
const accountKeyIndexes = byteArray
|
|
1105
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1085
1106
|
const dataLength = decodeLength(byteArray);
|
|
1086
|
-
const data = new Uint8Array(byteArray
|
|
1107
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1087
1108
|
compiledInstructions.push({
|
|
1088
1109
|
programIdIndex,
|
|
1089
1110
|
accountKeyIndexes,
|
|
@@ -1093,11 +1114,11 @@ class MessageV0 {
|
|
|
1093
1114
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1094
1115
|
const addressTableLookups = [];
|
|
1095
1116
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1096
|
-
const accountKey = new PublicKey(byteArray
|
|
1117
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1097
1118
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1098
|
-
const writableIndexes = byteArray
|
|
1119
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1099
1120
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1100
|
-
const readonlyIndexes = byteArray
|
|
1121
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1101
1122
|
addressTableLookups.push({
|
|
1102
1123
|
accountKey,
|
|
1103
1124
|
writableIndexes,
|
|
@@ -1772,8 +1793,7 @@ class Transaction {
|
|
|
1772
1793
|
const signatureCount = decodeLength(byteArray);
|
|
1773
1794
|
let signatures = [];
|
|
1774
1795
|
for (let i = 0; i < signatureCount; i++) {
|
|
1775
|
-
const signature = byteArray
|
|
1776
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1796
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1777
1797
|
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1778
1798
|
}
|
|
1779
1799
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -1943,7 +1963,7 @@ class VersionedTransaction {
|
|
|
1943
1963
|
const signatures = [];
|
|
1944
1964
|
const signaturesLength = decodeLength(byteArray);
|
|
1945
1965
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1946
|
-
signatures.push(new Uint8Array(byteArray
|
|
1966
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1947
1967
|
}
|
|
1948
1968
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1949
1969
|
return new VersionedTransaction(message, signatures);
|
|
@@ -4433,7 +4453,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4433
4453
|
|
|
4434
4454
|
/** @internal */
|
|
4435
4455
|
const COMMON_HTTP_HEADERS = {
|
|
4436
|
-
'solana-client': `js/${"
|
|
4456
|
+
'solana-client': `js/${"1.76.1" }`
|
|
4437
4457
|
};
|
|
4438
4458
|
|
|
4439
4459
|
/**
|
|
@@ -9220,10 +9240,8 @@ class ValidatorInfo {
|
|
|
9220
9240
|
if (configKeyCount !== 2) return null;
|
|
9221
9241
|
const configKeys = [];
|
|
9222
9242
|
for (let i = 0; i < 2; i++) {
|
|
9223
|
-
const publicKey = new PublicKey(byteArray
|
|
9224
|
-
|
|
9225
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9226
|
-
byteArray = byteArray.slice(1);
|
|
9243
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9244
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9227
9245
|
configKeys.push({
|
|
9228
9246
|
publicKey,
|
|
9229
9247
|
isSigner
|