@solana/web3.js 1.88.0 → 1.88.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.cjs.js
CHANGED
|
@@ -708,6 +708,31 @@ class CompiledKeys {
|
|
|
708
708
|
}
|
|
709
709
|
}
|
|
710
710
|
|
|
711
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
715
|
+
*/
|
|
716
|
+
function guardedShift(byteArray) {
|
|
717
|
+
if (byteArray.length === 0) {
|
|
718
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
719
|
+
}
|
|
720
|
+
return byteArray.shift();
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
725
|
+
* the array.
|
|
726
|
+
*/
|
|
727
|
+
function guardedSplice(byteArray, ...args) {
|
|
728
|
+
const [start] = args;
|
|
729
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
730
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
731
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
732
|
+
}
|
|
733
|
+
return byteArray.splice(...args);
|
|
734
|
+
}
|
|
735
|
+
|
|
711
736
|
/**
|
|
712
737
|
* An instruction to execute by a program
|
|
713
738
|
*
|
|
@@ -849,32 +874,28 @@ class Message {
|
|
|
849
874
|
static from(buffer$1) {
|
|
850
875
|
// Slice up wire data
|
|
851
876
|
let byteArray = [...buffer$1];
|
|
852
|
-
const numRequiredSignatures = byteArray
|
|
877
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
853
878
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
854
879
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
855
880
|
}
|
|
856
|
-
const numReadonlySignedAccounts = byteArray
|
|
857
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
881
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
882
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
858
883
|
const accountCount = decodeLength(byteArray);
|
|
859
884
|
let accountKeys = [];
|
|
860
885
|
for (let i = 0; i < accountCount; i++) {
|
|
861
|
-
const account = byteArray
|
|
862
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
886
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
863
887
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
864
888
|
}
|
|
865
|
-
const recentBlockhash = byteArray
|
|
866
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
889
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
867
890
|
const instructionCount = decodeLength(byteArray);
|
|
868
891
|
let instructions = [];
|
|
869
892
|
for (let i = 0; i < instructionCount; i++) {
|
|
870
|
-
const programIdIndex = byteArray
|
|
893
|
+
const programIdIndex = guardedShift(byteArray);
|
|
871
894
|
const accountCount = decodeLength(byteArray);
|
|
872
|
-
const accounts = byteArray
|
|
873
|
-
byteArray = byteArray.slice(accountCount);
|
|
895
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
874
896
|
const dataLength = decodeLength(byteArray);
|
|
875
|
-
const dataSlice = byteArray
|
|
897
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
876
898
|
const data = bs58__default.default.encode(buffer.Buffer.from(dataSlice));
|
|
877
|
-
byteArray = byteArray.slice(dataLength);
|
|
878
899
|
instructions.push({
|
|
879
900
|
programIdIndex,
|
|
880
901
|
accounts,
|
|
@@ -1079,30 +1100,30 @@ class MessageV0 {
|
|
|
1079
1100
|
}
|
|
1080
1101
|
static deserialize(serializedMessage) {
|
|
1081
1102
|
let byteArray = [...serializedMessage];
|
|
1082
|
-
const prefix = byteArray
|
|
1103
|
+
const prefix = guardedShift(byteArray);
|
|
1083
1104
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1084
1105
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1085
1106
|
const version = maskedPrefix;
|
|
1086
1107
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1087
1108
|
const header = {
|
|
1088
|
-
numRequiredSignatures: byteArray
|
|
1089
|
-
numReadonlySignedAccounts: byteArray
|
|
1090
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1109
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1110
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1111
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1091
1112
|
};
|
|
1092
1113
|
const staticAccountKeys = [];
|
|
1093
1114
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1094
1115
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1095
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1116
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1096
1117
|
}
|
|
1097
|
-
const recentBlockhash = bs58__default.default.encode(byteArray
|
|
1118
|
+
const recentBlockhash = bs58__default.default.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1098
1119
|
const instructionCount = decodeLength(byteArray);
|
|
1099
1120
|
const compiledInstructions = [];
|
|
1100
1121
|
for (let i = 0; i < instructionCount; i++) {
|
|
1101
|
-
const programIdIndex = byteArray
|
|
1122
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1102
1123
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1103
|
-
const accountKeyIndexes = byteArray
|
|
1124
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1104
1125
|
const dataLength = decodeLength(byteArray);
|
|
1105
|
-
const data = new Uint8Array(byteArray
|
|
1126
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1106
1127
|
compiledInstructions.push({
|
|
1107
1128
|
programIdIndex,
|
|
1108
1129
|
accountKeyIndexes,
|
|
@@ -1112,11 +1133,11 @@ class MessageV0 {
|
|
|
1112
1133
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1113
1134
|
const addressTableLookups = [];
|
|
1114
1135
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1115
|
-
const accountKey = new PublicKey(byteArray
|
|
1136
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1116
1137
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1117
|
-
const writableIndexes = byteArray
|
|
1138
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1118
1139
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1119
|
-
const readonlyIndexes = byteArray
|
|
1140
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1120
1141
|
addressTableLookups.push({
|
|
1121
1142
|
accountKey,
|
|
1122
1143
|
writableIndexes,
|
|
@@ -1902,8 +1923,7 @@ class Transaction {
|
|
|
1902
1923
|
const signatureCount = decodeLength(byteArray);
|
|
1903
1924
|
let signatures = [];
|
|
1904
1925
|
for (let i = 0; i < signatureCount; i++) {
|
|
1905
|
-
const signature = byteArray
|
|
1906
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1926
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1907
1927
|
signatures.push(bs58__default.default.encode(buffer.Buffer.from(signature)));
|
|
1908
1928
|
}
|
|
1909
1929
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2078,7 +2098,7 @@ class VersionedTransaction {
|
|
|
2078
2098
|
const signatures = [];
|
|
2079
2099
|
const signaturesLength = decodeLength(byteArray);
|
|
2080
2100
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2081
|
-
signatures.push(new Uint8Array(byteArray
|
|
2101
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2082
2102
|
}
|
|
2083
2103
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2084
2104
|
return new VersionedTransaction(message, signatures);
|
|
@@ -5789,7 +5809,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
5789
5809
|
|
|
5790
5810
|
/** @internal */
|
|
5791
5811
|
const COMMON_HTTP_HEADERS = {
|
|
5792
|
-
'solana-client': `js/${"
|
|
5812
|
+
'solana-client': `js/${"1.88.1" }`
|
|
5793
5813
|
};
|
|
5794
5814
|
|
|
5795
5815
|
/**
|
|
@@ -10724,10 +10744,8 @@ class ValidatorInfo {
|
|
|
10724
10744
|
if (configKeyCount !== 2) return null;
|
|
10725
10745
|
const configKeys = [];
|
|
10726
10746
|
for (let i = 0; i < 2; i++) {
|
|
10727
|
-
const publicKey = new PublicKey(byteArray
|
|
10728
|
-
|
|
10729
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10730
|
-
byteArray = byteArray.slice(1);
|
|
10747
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10748
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10731
10749
|
configKeys.push({
|
|
10732
10750
|
publicKey,
|
|
10733
10751
|
isSigner
|