@solana/web3.js 1.57.0 → 1.57.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 +63 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +63 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +63 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +63 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +63 -32
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +63 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- 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
|
@@ -645,6 +645,44 @@ function encodeLength(bytes, len) {
|
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
649
|
+
/**
|
|
650
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
651
|
+
*/
|
|
652
|
+
|
|
653
|
+
function guardedShift(byteArray) {
|
|
654
|
+
if (byteArray.length === 0) {
|
|
655
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return byteArray.shift();
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
662
|
+
* the array.
|
|
663
|
+
*/
|
|
664
|
+
|
|
665
|
+
function guardedSplice(byteArray, ...args) {
|
|
666
|
+
var _args$;
|
|
667
|
+
|
|
668
|
+
const [start] = args;
|
|
669
|
+
|
|
670
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
671
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
672
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
return byteArray.splice(...args);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* An instruction to execute by a program
|
|
680
|
+
*
|
|
681
|
+
* @property {number} programIdIndex
|
|
682
|
+
* @property {number[]} accounts
|
|
683
|
+
* @property {string} data
|
|
684
|
+
*/
|
|
685
|
+
|
|
648
686
|
/**
|
|
649
687
|
* List of instructions to be processed atomically
|
|
650
688
|
*/
|
|
@@ -757,37 +795,33 @@ class Message {
|
|
|
757
795
|
static from(buffer$1) {
|
|
758
796
|
// Slice up wire data
|
|
759
797
|
let byteArray = [...buffer$1];
|
|
760
|
-
const numRequiredSignatures = byteArray
|
|
798
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
761
799
|
|
|
762
800
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
763
801
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
764
802
|
}
|
|
765
803
|
|
|
766
|
-
const numReadonlySignedAccounts = byteArray
|
|
767
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
804
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
805
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
768
806
|
const accountCount = decodeLength(byteArray);
|
|
769
807
|
let accountKeys = [];
|
|
770
808
|
|
|
771
809
|
for (let i = 0; i < accountCount; i++) {
|
|
772
|
-
const account = byteArray
|
|
773
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
810
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
774
811
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
775
812
|
}
|
|
776
813
|
|
|
777
|
-
const recentBlockhash = byteArray
|
|
778
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
814
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
779
815
|
const instructionCount = decodeLength(byteArray);
|
|
780
816
|
let instructions = [];
|
|
781
817
|
|
|
782
818
|
for (let i = 0; i < instructionCount; i++) {
|
|
783
|
-
const programIdIndex = byteArray
|
|
819
|
+
const programIdIndex = guardedShift(byteArray);
|
|
784
820
|
const accountCount = decodeLength(byteArray);
|
|
785
|
-
const accounts = byteArray
|
|
786
|
-
byteArray = byteArray.slice(accountCount);
|
|
821
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
787
822
|
const dataLength = decodeLength(byteArray);
|
|
788
|
-
const dataSlice = byteArray
|
|
823
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
789
824
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
790
|
-
byteArray = byteArray.slice(dataLength);
|
|
791
825
|
instructions.push({
|
|
792
826
|
programIdIndex,
|
|
793
827
|
accounts,
|
|
@@ -1054,33 +1088,33 @@ class MessageV0 {
|
|
|
1054
1088
|
|
|
1055
1089
|
static deserialize(serializedMessage) {
|
|
1056
1090
|
let byteArray = [...serializedMessage];
|
|
1057
|
-
const prefix = byteArray
|
|
1091
|
+
const prefix = guardedShift(byteArray);
|
|
1058
1092
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1059
1093
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1060
1094
|
const version = maskedPrefix;
|
|
1061
1095
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1062
1096
|
const header = {
|
|
1063
|
-
numRequiredSignatures: byteArray
|
|
1064
|
-
numReadonlySignedAccounts: byteArray
|
|
1065
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1097
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1098
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1099
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1066
1100
|
};
|
|
1067
1101
|
const staticAccountKeys = [];
|
|
1068
1102
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1069
1103
|
|
|
1070
1104
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1071
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1105
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1072
1106
|
}
|
|
1073
1107
|
|
|
1074
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1108
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1075
1109
|
const instructionCount = decodeLength(byteArray);
|
|
1076
1110
|
const compiledInstructions = [];
|
|
1077
1111
|
|
|
1078
1112
|
for (let i = 0; i < instructionCount; i++) {
|
|
1079
|
-
const programIdIndex = byteArray
|
|
1113
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1080
1114
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1081
|
-
const accountKeyIndexes = byteArray
|
|
1115
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1082
1116
|
const dataLength = decodeLength(byteArray);
|
|
1083
|
-
const data = new Uint8Array(byteArray
|
|
1117
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1084
1118
|
compiledInstructions.push({
|
|
1085
1119
|
programIdIndex,
|
|
1086
1120
|
accountKeyIndexes,
|
|
@@ -1092,11 +1126,11 @@ class MessageV0 {
|
|
|
1092
1126
|
const addressTableLookups = [];
|
|
1093
1127
|
|
|
1094
1128
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1095
|
-
const accountKey = new PublicKey(byteArray
|
|
1129
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1096
1130
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1097
|
-
const writableIndexes = byteArray
|
|
1131
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1098
1132
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1099
|
-
const readonlyIndexes = byteArray
|
|
1133
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1100
1134
|
addressTableLookups.push({
|
|
1101
1135
|
accountKey,
|
|
1102
1136
|
writableIndexes,
|
|
@@ -1827,8 +1861,7 @@ class Transaction {
|
|
|
1827
1861
|
let signatures = [];
|
|
1828
1862
|
|
|
1829
1863
|
for (let i = 0; i < signatureCount; i++) {
|
|
1830
|
-
const signature = byteArray
|
|
1831
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1864
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1832
1865
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1833
1866
|
}
|
|
1834
1867
|
|
|
@@ -1920,7 +1953,7 @@ class VersionedTransaction {
|
|
|
1920
1953
|
const signaturesLength = decodeLength(byteArray);
|
|
1921
1954
|
|
|
1922
1955
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1923
|
-
signatures.push(new Uint8Array(byteArray
|
|
1956
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1924
1957
|
}
|
|
1925
1958
|
|
|
1926
1959
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4379,7 +4412,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4379
4412
|
|
|
4380
4413
|
/** @internal */
|
|
4381
4414
|
const COMMON_HTTP_HEADERS = {
|
|
4382
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4415
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4383
4416
|
};
|
|
4384
4417
|
/**
|
|
4385
4418
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9157,10 +9190,8 @@ class ValidatorInfo {
|
|
|
9157
9190
|
const configKeys = [];
|
|
9158
9191
|
|
|
9159
9192
|
for (let i = 0; i < 2; i++) {
|
|
9160
|
-
const publicKey = new PublicKey(byteArray
|
|
9161
|
-
|
|
9162
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9163
|
-
byteArray = byteArray.slice(1);
|
|
9193
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9194
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9164
9195
|
configKeys.push({
|
|
9165
9196
|
publicKey,
|
|
9166
9197
|
isSigner
|