@solana/web3.js 1.87.5 → 1.87.7
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 +51 -33
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +51 -33
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +51 -33
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +51 -33
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +51 -33
- 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 +51 -33
- package/lib/index.native.js.map +1 -1
- package/package.json +23 -23
- 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/utils/makeWebsocketUrl.ts +1 -1
- package/src/validator-info.ts +5 -4
package/lib/index.esm.js
CHANGED
|
@@ -678,6 +678,31 @@ class CompiledKeys {
|
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
680
|
|
|
681
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
685
|
+
*/
|
|
686
|
+
function guardedShift(byteArray) {
|
|
687
|
+
if (byteArray.length === 0) {
|
|
688
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
689
|
+
}
|
|
690
|
+
return byteArray.shift();
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
695
|
+
* the array.
|
|
696
|
+
*/
|
|
697
|
+
function guardedSplice(byteArray, ...args) {
|
|
698
|
+
const [start] = args;
|
|
699
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
700
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
701
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
702
|
+
}
|
|
703
|
+
return byteArray.splice(...args);
|
|
704
|
+
}
|
|
705
|
+
|
|
681
706
|
/**
|
|
682
707
|
* An instruction to execute by a program
|
|
683
708
|
*
|
|
@@ -819,32 +844,28 @@ class Message {
|
|
|
819
844
|
static from(buffer) {
|
|
820
845
|
// Slice up wire data
|
|
821
846
|
let byteArray = [...buffer];
|
|
822
|
-
const numRequiredSignatures = byteArray
|
|
847
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
823
848
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
824
849
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
825
850
|
}
|
|
826
|
-
const numReadonlySignedAccounts = byteArray
|
|
827
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
851
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
852
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
828
853
|
const accountCount = decodeLength(byteArray);
|
|
829
854
|
let accountKeys = [];
|
|
830
855
|
for (let i = 0; i < accountCount; i++) {
|
|
831
|
-
const account = byteArray
|
|
832
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
856
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
833
857
|
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
834
858
|
}
|
|
835
|
-
const recentBlockhash = byteArray
|
|
836
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
859
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
837
860
|
const instructionCount = decodeLength(byteArray);
|
|
838
861
|
let instructions = [];
|
|
839
862
|
for (let i = 0; i < instructionCount; i++) {
|
|
840
|
-
const programIdIndex = byteArray
|
|
863
|
+
const programIdIndex = guardedShift(byteArray);
|
|
841
864
|
const accountCount = decodeLength(byteArray);
|
|
842
|
-
const accounts = byteArray
|
|
843
|
-
byteArray = byteArray.slice(accountCount);
|
|
865
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
844
866
|
const dataLength = decodeLength(byteArray);
|
|
845
|
-
const dataSlice = byteArray
|
|
867
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
846
868
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
847
|
-
byteArray = byteArray.slice(dataLength);
|
|
848
869
|
instructions.push({
|
|
849
870
|
programIdIndex,
|
|
850
871
|
accounts,
|
|
@@ -1049,30 +1070,30 @@ class MessageV0 {
|
|
|
1049
1070
|
}
|
|
1050
1071
|
static deserialize(serializedMessage) {
|
|
1051
1072
|
let byteArray = [...serializedMessage];
|
|
1052
|
-
const prefix = byteArray
|
|
1073
|
+
const prefix = guardedShift(byteArray);
|
|
1053
1074
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1054
1075
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1055
1076
|
const version = maskedPrefix;
|
|
1056
1077
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1057
1078
|
const header = {
|
|
1058
|
-
numRequiredSignatures: byteArray
|
|
1059
|
-
numReadonlySignedAccounts: byteArray
|
|
1060
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1079
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1080
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1081
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1061
1082
|
};
|
|
1062
1083
|
const staticAccountKeys = [];
|
|
1063
1084
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1064
1085
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1065
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1086
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1066
1087
|
}
|
|
1067
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1088
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1068
1089
|
const instructionCount = decodeLength(byteArray);
|
|
1069
1090
|
const compiledInstructions = [];
|
|
1070
1091
|
for (let i = 0; i < instructionCount; i++) {
|
|
1071
|
-
const programIdIndex = byteArray
|
|
1092
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1072
1093
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1073
|
-
const accountKeyIndexes = byteArray
|
|
1094
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1074
1095
|
const dataLength = decodeLength(byteArray);
|
|
1075
|
-
const data = new Uint8Array(byteArray
|
|
1096
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1076
1097
|
compiledInstructions.push({
|
|
1077
1098
|
programIdIndex,
|
|
1078
1099
|
accountKeyIndexes,
|
|
@@ -1082,11 +1103,11 @@ class MessageV0 {
|
|
|
1082
1103
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1083
1104
|
const addressTableLookups = [];
|
|
1084
1105
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1085
|
-
const accountKey = new PublicKey(byteArray
|
|
1106
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1086
1107
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1087
|
-
const writableIndexes = byteArray
|
|
1108
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1088
1109
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1089
|
-
const readonlyIndexes = byteArray
|
|
1110
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1090
1111
|
addressTableLookups.push({
|
|
1091
1112
|
accountKey,
|
|
1092
1113
|
writableIndexes,
|
|
@@ -1858,8 +1879,7 @@ class Transaction {
|
|
|
1858
1879
|
const signatureCount = decodeLength(byteArray);
|
|
1859
1880
|
let signatures = [];
|
|
1860
1881
|
for (let i = 0; i < signatureCount; i++) {
|
|
1861
|
-
const signature = byteArray
|
|
1862
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1882
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1863
1883
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1864
1884
|
}
|
|
1865
1885
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -2034,7 +2054,7 @@ class VersionedTransaction {
|
|
|
2034
2054
|
const signatures = [];
|
|
2035
2055
|
const signaturesLength = decodeLength(byteArray);
|
|
2036
2056
|
for (let i = 0; i < signaturesLength; i++) {
|
|
2037
|
-
signatures.push(new Uint8Array(byteArray
|
|
2057
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
2038
2058
|
}
|
|
2039
2059
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
2040
2060
|
return new VersionedTransaction(message, signatures);
|
|
@@ -5799,7 +5819,7 @@ function makeWebsocketUrl(endpoint) {
|
|
|
5799
5819
|
const startPort = portWithColon == null ? null : parseInt(portWithColon.slice(1), 10);
|
|
5800
5820
|
const websocketPort =
|
|
5801
5821
|
// Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
5802
|
-
// is
|
|
5822
|
+
// is explicitly specifying the endpoint port (HTTP-based RPC), assuming
|
|
5803
5823
|
// we're directly trying to connect to solana-validator's ws listening port.
|
|
5804
5824
|
// When the endpoint omits the port, we're connecting to the protocol
|
|
5805
5825
|
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
@@ -7337,7 +7357,7 @@ const LogsNotificationResult = type({
|
|
|
7337
7357
|
|
|
7338
7358
|
/** @internal */
|
|
7339
7359
|
const COMMON_HTTP_HEADERS = {
|
|
7340
|
-
'solana-client': `js/${"
|
|
7360
|
+
'solana-client': `js/${"1.87.7" }`
|
|
7341
7361
|
};
|
|
7342
7362
|
|
|
7343
7363
|
/**
|
|
@@ -12272,10 +12292,8 @@ class ValidatorInfo {
|
|
|
12272
12292
|
if (configKeyCount !== 2) return null;
|
|
12273
12293
|
const configKeys = [];
|
|
12274
12294
|
for (let i = 0; i < 2; i++) {
|
|
12275
|
-
const publicKey = new PublicKey(byteArray
|
|
12276
|
-
|
|
12277
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
12278
|
-
byteArray = byteArray.slice(1);
|
|
12295
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
12296
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
12279
12297
|
configKeys.push({
|
|
12280
12298
|
publicKey,
|
|
12281
12299
|
isSigner
|