@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.esm.js
CHANGED
|
@@ -611,6 +611,44 @@ function encodeLength(bytes, len) {
|
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
613
|
|
|
614
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
615
|
+
/**
|
|
616
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
617
|
+
*/
|
|
618
|
+
|
|
619
|
+
function guardedShift(byteArray) {
|
|
620
|
+
if (byteArray.length === 0) {
|
|
621
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return byteArray.shift();
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
628
|
+
* the array.
|
|
629
|
+
*/
|
|
630
|
+
|
|
631
|
+
function guardedSplice(byteArray, ...args) {
|
|
632
|
+
var _args$;
|
|
633
|
+
|
|
634
|
+
const [start] = args;
|
|
635
|
+
|
|
636
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
637
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
638
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return byteArray.splice(...args);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* An instruction to execute by a program
|
|
646
|
+
*
|
|
647
|
+
* @property {number} programIdIndex
|
|
648
|
+
* @property {number[]} accounts
|
|
649
|
+
* @property {string} data
|
|
650
|
+
*/
|
|
651
|
+
|
|
614
652
|
/**
|
|
615
653
|
* List of instructions to be processed atomically
|
|
616
654
|
*/
|
|
@@ -723,37 +761,33 @@ class Message {
|
|
|
723
761
|
static from(buffer) {
|
|
724
762
|
// Slice up wire data
|
|
725
763
|
let byteArray = [...buffer];
|
|
726
|
-
const numRequiredSignatures = byteArray
|
|
764
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
727
765
|
|
|
728
766
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
729
767
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
730
768
|
}
|
|
731
769
|
|
|
732
|
-
const numReadonlySignedAccounts = byteArray
|
|
733
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
770
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
771
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
734
772
|
const accountCount = decodeLength(byteArray);
|
|
735
773
|
let accountKeys = [];
|
|
736
774
|
|
|
737
775
|
for (let i = 0; i < accountCount; i++) {
|
|
738
|
-
const account = byteArray
|
|
739
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
776
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
740
777
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
741
778
|
}
|
|
742
779
|
|
|
743
|
-
const recentBlockhash = byteArray
|
|
744
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
780
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
745
781
|
const instructionCount = decodeLength(byteArray);
|
|
746
782
|
let instructions = [];
|
|
747
783
|
|
|
748
784
|
for (let i = 0; i < instructionCount; i++) {
|
|
749
|
-
const programIdIndex = byteArray
|
|
785
|
+
const programIdIndex = guardedShift(byteArray);
|
|
750
786
|
const accountCount = decodeLength(byteArray);
|
|
751
|
-
const accounts = byteArray
|
|
752
|
-
byteArray = byteArray.slice(accountCount);
|
|
787
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
753
788
|
const dataLength = decodeLength(byteArray);
|
|
754
|
-
const dataSlice = byteArray
|
|
789
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
755
790
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
756
|
-
byteArray = byteArray.slice(dataLength);
|
|
757
791
|
instructions.push({
|
|
758
792
|
programIdIndex,
|
|
759
793
|
accounts,
|
|
@@ -1020,33 +1054,33 @@ class MessageV0 {
|
|
|
1020
1054
|
|
|
1021
1055
|
static deserialize(serializedMessage) {
|
|
1022
1056
|
let byteArray = [...serializedMessage];
|
|
1023
|
-
const prefix = byteArray
|
|
1057
|
+
const prefix = guardedShift(byteArray);
|
|
1024
1058
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1025
1059
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1026
1060
|
const version = maskedPrefix;
|
|
1027
1061
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1028
1062
|
const header = {
|
|
1029
|
-
numRequiredSignatures: byteArray
|
|
1030
|
-
numReadonlySignedAccounts: byteArray
|
|
1031
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1063
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1064
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1065
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1032
1066
|
};
|
|
1033
1067
|
const staticAccountKeys = [];
|
|
1034
1068
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1035
1069
|
|
|
1036
1070
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1037
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1071
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1038
1072
|
}
|
|
1039
1073
|
|
|
1040
|
-
const recentBlockhash = bs58.encode(byteArray
|
|
1074
|
+
const recentBlockhash = bs58.encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1041
1075
|
const instructionCount = decodeLength(byteArray);
|
|
1042
1076
|
const compiledInstructions = [];
|
|
1043
1077
|
|
|
1044
1078
|
for (let i = 0; i < instructionCount; i++) {
|
|
1045
|
-
const programIdIndex = byteArray
|
|
1079
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1046
1080
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1047
|
-
const accountKeyIndexes = byteArray
|
|
1081
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1048
1082
|
const dataLength = decodeLength(byteArray);
|
|
1049
|
-
const data = new Uint8Array(byteArray
|
|
1083
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1050
1084
|
compiledInstructions.push({
|
|
1051
1085
|
programIdIndex,
|
|
1052
1086
|
accountKeyIndexes,
|
|
@@ -1058,11 +1092,11 @@ class MessageV0 {
|
|
|
1058
1092
|
const addressTableLookups = [];
|
|
1059
1093
|
|
|
1060
1094
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1061
|
-
const accountKey = new PublicKey(byteArray
|
|
1095
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1062
1096
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1063
|
-
const writableIndexes = byteArray
|
|
1097
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1064
1098
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1065
|
-
const readonlyIndexes = byteArray
|
|
1099
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1066
1100
|
addressTableLookups.push({
|
|
1067
1101
|
accountKey,
|
|
1068
1102
|
writableIndexes,
|
|
@@ -1793,8 +1827,7 @@ class Transaction {
|
|
|
1793
1827
|
let signatures = [];
|
|
1794
1828
|
|
|
1795
1829
|
for (let i = 0; i < signatureCount; i++) {
|
|
1796
|
-
const signature = byteArray
|
|
1797
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1830
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1798
1831
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1799
1832
|
}
|
|
1800
1833
|
|
|
@@ -1886,7 +1919,7 @@ class VersionedTransaction {
|
|
|
1886
1919
|
const signaturesLength = decodeLength(byteArray);
|
|
1887
1920
|
|
|
1888
1921
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1889
|
-
signatures.push(new Uint8Array(byteArray
|
|
1922
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1890
1923
|
}
|
|
1891
1924
|
|
|
1892
1925
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4345,7 +4378,7 @@ const LogsNotificationResult = type({
|
|
|
4345
4378
|
|
|
4346
4379
|
/** @internal */
|
|
4347
4380
|
const COMMON_HTTP_HEADERS = {
|
|
4348
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4381
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4349
4382
|
};
|
|
4350
4383
|
/**
|
|
4351
4384
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9123,10 +9156,8 @@ class ValidatorInfo {
|
|
|
9123
9156
|
const configKeys = [];
|
|
9124
9157
|
|
|
9125
9158
|
for (let i = 0; i < 2; i++) {
|
|
9126
|
-
const publicKey = new PublicKey(byteArray
|
|
9127
|
-
|
|
9128
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9129
|
-
byteArray = byteArray.slice(1);
|
|
9159
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9160
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9130
9161
|
configKeys.push({
|
|
9131
9162
|
publicKey,
|
|
9132
9163
|
isSigner
|