@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.native.js
CHANGED
|
@@ -639,6 +639,44 @@ function encodeLength(bytes, len) {
|
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
|
|
642
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
643
|
+
/**
|
|
644
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
645
|
+
*/
|
|
646
|
+
|
|
647
|
+
function guardedShift(byteArray) {
|
|
648
|
+
if (byteArray.length === 0) {
|
|
649
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return byteArray.shift();
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
656
|
+
* the array.
|
|
657
|
+
*/
|
|
658
|
+
|
|
659
|
+
function guardedSplice(byteArray, ...args) {
|
|
660
|
+
var _args$;
|
|
661
|
+
|
|
662
|
+
const [start] = args;
|
|
663
|
+
|
|
664
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
665
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
666
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
return byteArray.splice(...args);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* An instruction to execute by a program
|
|
674
|
+
*
|
|
675
|
+
* @property {number} programIdIndex
|
|
676
|
+
* @property {number[]} accounts
|
|
677
|
+
* @property {string} data
|
|
678
|
+
*/
|
|
679
|
+
|
|
642
680
|
/**
|
|
643
681
|
* List of instructions to be processed atomically
|
|
644
682
|
*/
|
|
@@ -751,37 +789,33 @@ class Message {
|
|
|
751
789
|
static from(buffer$1) {
|
|
752
790
|
// Slice up wire data
|
|
753
791
|
let byteArray = [...buffer$1];
|
|
754
|
-
const numRequiredSignatures = byteArray
|
|
792
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
755
793
|
|
|
756
794
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
757
795
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
758
796
|
}
|
|
759
797
|
|
|
760
|
-
const numReadonlySignedAccounts = byteArray
|
|
761
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
798
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
799
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
762
800
|
const accountCount = decodeLength(byteArray);
|
|
763
801
|
let accountKeys = [];
|
|
764
802
|
|
|
765
803
|
for (let i = 0; i < accountCount; i++) {
|
|
766
|
-
const account = byteArray
|
|
767
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
804
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
768
805
|
accountKeys.push(bs58__default["default"].encode(buffer.Buffer.from(account)));
|
|
769
806
|
}
|
|
770
807
|
|
|
771
|
-
const recentBlockhash = byteArray
|
|
772
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
808
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
773
809
|
const instructionCount = decodeLength(byteArray);
|
|
774
810
|
let instructions = [];
|
|
775
811
|
|
|
776
812
|
for (let i = 0; i < instructionCount; i++) {
|
|
777
|
-
const programIdIndex = byteArray
|
|
813
|
+
const programIdIndex = guardedShift(byteArray);
|
|
778
814
|
const accountCount = decodeLength(byteArray);
|
|
779
|
-
const accounts = byteArray
|
|
780
|
-
byteArray = byteArray.slice(accountCount);
|
|
815
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
781
816
|
const dataLength = decodeLength(byteArray);
|
|
782
|
-
const dataSlice = byteArray
|
|
817
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
783
818
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
784
|
-
byteArray = byteArray.slice(dataLength);
|
|
785
819
|
instructions.push({
|
|
786
820
|
programIdIndex,
|
|
787
821
|
accounts,
|
|
@@ -1048,33 +1082,33 @@ class MessageV0 {
|
|
|
1048
1082
|
|
|
1049
1083
|
static deserialize(serializedMessage) {
|
|
1050
1084
|
let byteArray = [...serializedMessage];
|
|
1051
|
-
const prefix = byteArray
|
|
1085
|
+
const prefix = guardedShift(byteArray);
|
|
1052
1086
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1053
1087
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1054
1088
|
const version = maskedPrefix;
|
|
1055
1089
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1056
1090
|
const header = {
|
|
1057
|
-
numRequiredSignatures: byteArray
|
|
1058
|
-
numReadonlySignedAccounts: byteArray
|
|
1059
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1091
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1092
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1093
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1060
1094
|
};
|
|
1061
1095
|
const staticAccountKeys = [];
|
|
1062
1096
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1063
1097
|
|
|
1064
1098
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1065
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1099
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1066
1100
|
}
|
|
1067
1101
|
|
|
1068
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1102
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1069
1103
|
const instructionCount = decodeLength(byteArray);
|
|
1070
1104
|
const compiledInstructions = [];
|
|
1071
1105
|
|
|
1072
1106
|
for (let i = 0; i < instructionCount; i++) {
|
|
1073
|
-
const programIdIndex = byteArray
|
|
1107
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1074
1108
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1075
|
-
const accountKeyIndexes = byteArray
|
|
1109
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1076
1110
|
const dataLength = decodeLength(byteArray);
|
|
1077
|
-
const data = new Uint8Array(byteArray
|
|
1111
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1078
1112
|
compiledInstructions.push({
|
|
1079
1113
|
programIdIndex,
|
|
1080
1114
|
accountKeyIndexes,
|
|
@@ -1086,11 +1120,11 @@ class MessageV0 {
|
|
|
1086
1120
|
const addressTableLookups = [];
|
|
1087
1121
|
|
|
1088
1122
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1089
|
-
const accountKey = new PublicKey(byteArray
|
|
1123
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1090
1124
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1091
|
-
const writableIndexes = byteArray
|
|
1125
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1092
1126
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1093
|
-
const readonlyIndexes = byteArray
|
|
1127
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1094
1128
|
addressTableLookups.push({
|
|
1095
1129
|
accountKey,
|
|
1096
1130
|
writableIndexes,
|
|
@@ -1821,8 +1855,7 @@ class Transaction {
|
|
|
1821
1855
|
let signatures = [];
|
|
1822
1856
|
|
|
1823
1857
|
for (let i = 0; i < signatureCount; i++) {
|
|
1824
|
-
const signature = byteArray
|
|
1825
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1858
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1826
1859
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1827
1860
|
}
|
|
1828
1861
|
|
|
@@ -1914,7 +1947,7 @@ class VersionedTransaction {
|
|
|
1914
1947
|
const signaturesLength = decodeLength(byteArray);
|
|
1915
1948
|
|
|
1916
1949
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1917
|
-
signatures.push(new Uint8Array(byteArray
|
|
1950
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1918
1951
|
}
|
|
1919
1952
|
|
|
1920
1953
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
@@ -4313,7 +4346,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4313
4346
|
|
|
4314
4347
|
/** @internal */
|
|
4315
4348
|
const COMMON_HTTP_HEADERS = {
|
|
4316
|
-
'solana-client': `js/${(_process$env$npm_pack = "
|
|
4349
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.57.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4317
4350
|
};
|
|
4318
4351
|
/**
|
|
4319
4352
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -9091,10 +9124,8 @@ class ValidatorInfo {
|
|
|
9091
9124
|
const configKeys = [];
|
|
9092
9125
|
|
|
9093
9126
|
for (let i = 0; i < 2; i++) {
|
|
9094
|
-
const publicKey = new PublicKey(byteArray
|
|
9095
|
-
|
|
9096
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9097
|
-
byteArray = byteArray.slice(1);
|
|
9127
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9128
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9098
9129
|
configKeys.push({
|
|
9099
9130
|
publicKey,
|
|
9100
9131
|
isSigner
|