@solana/web3.js 1.90.1 → 1.90.2
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 +78 -20
- 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
|
@@ -672,6 +672,31 @@ class CompiledKeys {
|
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
|
|
675
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
679
|
+
*/
|
|
680
|
+
function guardedShift(byteArray) {
|
|
681
|
+
if (byteArray.length === 0) {
|
|
682
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
683
|
+
}
|
|
684
|
+
return byteArray.shift();
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
689
|
+
* the array.
|
|
690
|
+
*/
|
|
691
|
+
function guardedSplice(byteArray, ...args) {
|
|
692
|
+
const [start] = args;
|
|
693
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
694
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
695
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
696
|
+
}
|
|
697
|
+
return byteArray.splice(...args);
|
|
698
|
+
}
|
|
699
|
+
|
|
675
700
|
/**
|
|
676
701
|
* An instruction to execute by a program
|
|
677
702
|
*
|
|
@@ -813,32 +838,28 @@ class Message {
|
|
|
813
838
|
static from(buffer) {
|
|
814
839
|
// Slice up wire data
|
|
815
840
|
let byteArray = [...buffer];
|
|
816
|
-
const numRequiredSignatures = byteArray
|
|
841
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
817
842
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
818
843
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
819
844
|
}
|
|
820
|
-
const numReadonlySignedAccounts = byteArray
|
|
821
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
845
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
846
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
822
847
|
const accountCount = decodeLength(byteArray);
|
|
823
848
|
let accountKeys = [];
|
|
824
849
|
for (let i = 0; i < accountCount; i++) {
|
|
825
|
-
const account = byteArray
|
|
826
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
850
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
827
851
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
828
852
|
}
|
|
829
|
-
const recentBlockhash = byteArray
|
|
830
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
853
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
831
854
|
const instructionCount = decodeLength(byteArray);
|
|
832
855
|
let instructions = [];
|
|
833
856
|
for (let i = 0; i < instructionCount; i++) {
|
|
834
|
-
const programIdIndex = byteArray
|
|
857
|
+
const programIdIndex = guardedShift(byteArray);
|
|
835
858
|
const accountCount = decodeLength(byteArray);
|
|
836
|
-
const accounts = byteArray
|
|
837
|
-
byteArray = byteArray.slice(accountCount);
|
|
859
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
838
860
|
const dataLength = decodeLength(byteArray);
|
|
839
|
-
const dataSlice = byteArray
|
|
861
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
840
862
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
841
|
-
byteArray = byteArray.slice(dataLength);
|
|
842
863
|
instructions.push({
|
|
843
864
|
programIdIndex,
|
|
844
865
|
accounts,
|
|
@@ -1043,30 +1064,30 @@ class MessageV0 {
|
|
|
1043
1064
|
}
|
|
1044
1065
|
static deserialize(serializedMessage) {
|
|
1045
1066
|
let byteArray = [...serializedMessage];
|
|
1046
|
-
const prefix = byteArray
|
|
1067
|
+
const prefix = guardedShift(byteArray);
|
|
1047
1068
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1048
1069
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1049
1070
|
const version = maskedPrefix;
|
|
1050
1071
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1051
1072
|
const header = {
|
|
1052
|
-
numRequiredSignatures: byteArray
|
|
1053
|
-
numReadonlySignedAccounts: byteArray
|
|
1054
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1073
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1074
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1075
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1055
1076
|
};
|
|
1056
1077
|
const staticAccountKeys = [];
|
|
1057
1078
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1058
1079
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1059
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1080
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1060
1081
|
}
|
|
1061
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1082
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1062
1083
|
const instructionCount = decodeLength(byteArray);
|
|
1063
1084
|
const compiledInstructions = [];
|
|
1064
1085
|
for (let i = 0; i < instructionCount; i++) {
|
|
1065
|
-
const programIdIndex = byteArray
|
|
1086
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1066
1087
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1067
|
-
const accountKeyIndexes = byteArray
|
|
1088
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1068
1089
|
const dataLength = decodeLength(byteArray);
|
|
1069
|
-
const data = new Uint8Array(byteArray
|
|
1090
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1070
1091
|
compiledInstructions.push({
|
|
1071
1092
|
programIdIndex,
|
|
1072
1093
|
accountKeyIndexes,
|
|
@@ -1076,11 +1097,11 @@ class MessageV0 {
|
|
|
1076
1097
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1077
1098
|
const addressTableLookups = [];
|
|
1078
1099
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1079
|
-
const accountKey = new PublicKey(byteArray
|
|
1100
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1080
1101
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1081
|
-
const writableIndexes = byteArray
|
|
1102
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1082
1103
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1083
|
-
const readonlyIndexes = byteArray
|
|
1104
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1084
1105
|
addressTableLookups.push({
|
|
1085
1106
|
accountKey,
|
|
1086
1107
|
writableIndexes,
|
|
@@ -1871,8 +1892,7 @@ class Transaction {
|
|
|
1871
1892
|
const signatureCount = decodeLength(byteArray);
|
|
1872
1893
|
let signatures = [];
|
|
1873
1894
|
for (let i = 0; i < signatureCount; i++) {
|
|
1874
|
-
const signature = byteArray
|
|
1875
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1895
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1876
1896
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1877
1897
|
}
|
|
1878
1898
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2047,7 +2067,7 @@ class VersionedTransaction {
|
|
|
2047
2067
|
const signatures = [];
|
|
2048
2068
|
const signaturesLength = decodeLength(byteArray);
|
|
2049
2069
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2050
|
-
signatures.push(new Uint8Array(byteArray
|
|
2070
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2051
2071
|
}
|
|
2052
2072
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2053
2073
|
return new VersionedTransaction(message, signatures);
|
|
@@ -5098,7 +5118,7 @@ const LogsNotificationResult = type({
|
|
|
5098
5118
|
|
|
5099
5119
|
/** @internal */
|
|
5100
5120
|
const COMMON_HTTP_HEADERS = {
|
|
5101
|
-
'solana-client': `js/${"
|
|
5121
|
+
'solana-client': `js/${"1.90.2" }`
|
|
5102
5122
|
};
|
|
5103
5123
|
|
|
5104
5124
|
/**
|
|
@@ -10058,10 +10078,8 @@ class ValidatorInfo {
|
|
|
10058
10078
|
if (configKeyCount !== 2) return null;
|
|
10059
10079
|
const configKeys = [];
|
|
10060
10080
|
for (let i = 0; i < 2; i++) {
|
|
10061
|
-
const publicKey = new PublicKey(byteArray
|
|
10062
|
-
|
|
10063
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
10064
|
-
byteArray = byteArray.slice(1);
|
|
10081
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
10082
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
10065
10083
|
configKeys.push({
|
|
10066
10084
|
publicKey,
|
|
10067
10085
|
isSigner
|