@solana/web3.js 1.73.3 → 1.73.5
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/README.md +0 -3
- package/lib/index.browser.cjs.js +54 -37
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +54 -37
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +54 -37
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +54 -37
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +54 -37
- 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 +54 -37
- package/lib/index.native.js.map +1 -1
- package/package.json +21 -24
- package/src/connection.ts +1 -1
- 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/README.md
CHANGED
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
3
3
|
[![semantic-release][semantic-release-image]][semantic-release-url]
|
|
4
4
|
<br />
|
|
5
|
-
[![codecov][codecov-image]][codecov-url]
|
|
6
5
|
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
7
6
|
|
|
8
7
|
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
9
8
|
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
10
|
-
[codecov-image]: https://codecov.io/gh/solana-labs/solana-web3.js/branch/master/graph/badge.svg
|
|
11
|
-
[codecov-url]: https://codecov.io/gh/solana-labs/solana-web3.js
|
|
12
9
|
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js.svg?style=flat
|
|
13
10
|
[npm-image]: https://img.shields.io/npm/v/@solana/web3.js.svg?style=flat
|
|
14
11
|
[npm-url]: https://www.npmjs.com/package/@solana/web3.js
|
package/lib/index.browser.cjs.js
CHANGED
|
@@ -634,8 +634,8 @@ class CompiledKeys {
|
|
|
634
634
|
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
635
635
|
for (const accountMeta of ix.keys) {
|
|
636
636
|
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
637
|
-
keyMeta.isSigner
|
|
638
|
-
keyMeta.isWritable
|
|
637
|
+
keyMeta.isSigner ||= accountMeta.isSigner;
|
|
638
|
+
keyMeta.isWritable ||= accountMeta.isWritable;
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
return new CompiledKeys(payer, keyMetaMap);
|
|
@@ -700,6 +700,31 @@ class CompiledKeys {
|
|
|
700
700
|
}
|
|
701
701
|
}
|
|
702
702
|
|
|
703
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
707
|
+
*/
|
|
708
|
+
function guardedShift(byteArray) {
|
|
709
|
+
if (byteArray.length === 0) {
|
|
710
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
711
|
+
}
|
|
712
|
+
return byteArray.shift();
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
717
|
+
* the array.
|
|
718
|
+
*/
|
|
719
|
+
function guardedSplice(byteArray, ...args) {
|
|
720
|
+
const [start] = args;
|
|
721
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
722
|
+
? start + (args[1] ?? 0) > byteArray.length : start >= byteArray.length) {
|
|
723
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
724
|
+
}
|
|
725
|
+
return byteArray.splice(...args);
|
|
726
|
+
}
|
|
727
|
+
|
|
703
728
|
/**
|
|
704
729
|
* An instruction to execute by a program
|
|
705
730
|
*
|
|
@@ -837,32 +862,28 @@ class Message {
|
|
|
837
862
|
static from(buffer$1) {
|
|
838
863
|
// Slice up wire data
|
|
839
864
|
let byteArray = [...buffer$1];
|
|
840
|
-
const numRequiredSignatures = byteArray
|
|
865
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
841
866
|
if (numRequiredSignatures !== (numRequiredSignatures & VERSION_PREFIX_MASK)) {
|
|
842
867
|
throw new Error('Versioned messages must be deserialized with VersionedMessage.deserialize()');
|
|
843
868
|
}
|
|
844
|
-
const numReadonlySignedAccounts = byteArray
|
|
845
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
869
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
870
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
846
871
|
const accountCount = decodeLength(byteArray);
|
|
847
872
|
let accountKeys = [];
|
|
848
873
|
for (let i = 0; i < accountCount; i++) {
|
|
849
|
-
const account = byteArray
|
|
850
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
874
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
851
875
|
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
852
876
|
}
|
|
853
|
-
const recentBlockhash = byteArray
|
|
854
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
877
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
855
878
|
const instructionCount = decodeLength(byteArray);
|
|
856
879
|
let instructions = [];
|
|
857
880
|
for (let i = 0; i < instructionCount; i++) {
|
|
858
|
-
const programIdIndex = byteArray
|
|
881
|
+
const programIdIndex = guardedShift(byteArray);
|
|
859
882
|
const accountCount = decodeLength(byteArray);
|
|
860
|
-
const accounts = byteArray
|
|
861
|
-
byteArray = byteArray.slice(accountCount);
|
|
883
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
862
884
|
const dataLength = decodeLength(byteArray);
|
|
863
|
-
const dataSlice = byteArray
|
|
885
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
864
886
|
const data = bs58__default["default"].encode(buffer.Buffer.from(dataSlice));
|
|
865
|
-
byteArray = byteArray.slice(dataLength);
|
|
866
887
|
instructions.push({
|
|
867
888
|
programIdIndex,
|
|
868
889
|
accounts,
|
|
@@ -1067,30 +1088,30 @@ class MessageV0 {
|
|
|
1067
1088
|
}
|
|
1068
1089
|
static deserialize(serializedMessage) {
|
|
1069
1090
|
let byteArray = [...serializedMessage];
|
|
1070
|
-
const prefix = byteArray
|
|
1091
|
+
const prefix = guardedShift(byteArray);
|
|
1071
1092
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
1072
1093
|
assert(prefix !== maskedPrefix, `Expected versioned message but received legacy message`);
|
|
1073
1094
|
const version = maskedPrefix;
|
|
1074
1095
|
assert(version === 0, `Expected versioned message with version 0 but found version ${version}`);
|
|
1075
1096
|
const header = {
|
|
1076
|
-
numRequiredSignatures: byteArray
|
|
1077
|
-
numReadonlySignedAccounts: byteArray
|
|
1078
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
1097
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
1098
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
1099
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray)
|
|
1079
1100
|
};
|
|
1080
1101
|
const staticAccountKeys = [];
|
|
1081
1102
|
const staticAccountKeysLength = decodeLength(byteArray);
|
|
1082
1103
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
1083
|
-
staticAccountKeys.push(new PublicKey(byteArray
|
|
1104
|
+
staticAccountKeys.push(new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)));
|
|
1084
1105
|
}
|
|
1085
|
-
const recentBlockhash = bs58__default["default"].encode(byteArray
|
|
1106
|
+
const recentBlockhash = bs58__default["default"].encode(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1086
1107
|
const instructionCount = decodeLength(byteArray);
|
|
1087
1108
|
const compiledInstructions = [];
|
|
1088
1109
|
for (let i = 0; i < instructionCount; i++) {
|
|
1089
|
-
const programIdIndex = byteArray
|
|
1110
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1090
1111
|
const accountKeyIndexesLength = decodeLength(byteArray);
|
|
1091
|
-
const accountKeyIndexes = byteArray
|
|
1112
|
+
const accountKeyIndexes = guardedSplice(byteArray, 0, accountKeyIndexesLength);
|
|
1092
1113
|
const dataLength = decodeLength(byteArray);
|
|
1093
|
-
const data = new Uint8Array(byteArray
|
|
1114
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
1094
1115
|
compiledInstructions.push({
|
|
1095
1116
|
programIdIndex,
|
|
1096
1117
|
accountKeyIndexes,
|
|
@@ -1100,11 +1121,11 @@ class MessageV0 {
|
|
|
1100
1121
|
const addressTableLookupsCount = decodeLength(byteArray);
|
|
1101
1122
|
const addressTableLookups = [];
|
|
1102
1123
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
1103
|
-
const accountKey = new PublicKey(byteArray
|
|
1124
|
+
const accountKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
1104
1125
|
const writableIndexesLength = decodeLength(byteArray);
|
|
1105
|
-
const writableIndexes = byteArray
|
|
1126
|
+
const writableIndexes = guardedSplice(byteArray, 0, writableIndexesLength);
|
|
1106
1127
|
const readonlyIndexesLength = decodeLength(byteArray);
|
|
1107
|
-
const readonlyIndexes = byteArray
|
|
1128
|
+
const readonlyIndexes = guardedSplice(byteArray, 0, readonlyIndexesLength);
|
|
1108
1129
|
addressTableLookups.push({
|
|
1109
1130
|
accountKey,
|
|
1110
1131
|
writableIndexes,
|
|
@@ -1779,8 +1800,7 @@ class Transaction {
|
|
|
1779
1800
|
const signatureCount = decodeLength(byteArray);
|
|
1780
1801
|
let signatures = [];
|
|
1781
1802
|
for (let i = 0; i < signatureCount; i++) {
|
|
1782
|
-
const signature = byteArray
|
|
1783
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
1803
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
1784
1804
|
signatures.push(bs58__default["default"].encode(buffer.Buffer.from(signature)));
|
|
1785
1805
|
}
|
|
1786
1806
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -1950,7 +1970,7 @@ class VersionedTransaction {
|
|
|
1950
1970
|
const signatures = [];
|
|
1951
1971
|
const signaturesLength = decodeLength(byteArray);
|
|
1952
1972
|
for (let i = 0; i < signaturesLength; i++) {
|
|
1953
|
-
signatures.push(new Uint8Array(byteArray
|
|
1973
|
+
signatures.push(new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)));
|
|
1954
1974
|
}
|
|
1955
1975
|
const message = VersionedMessage.deserialize(new Uint8Array(byteArray));
|
|
1956
1976
|
return new VersionedTransaction(message, signatures);
|
|
@@ -4428,7 +4448,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4428
4448
|
|
|
4429
4449
|
/** @internal */
|
|
4430
4450
|
const COMMON_HTTP_HEADERS = {
|
|
4431
|
-
'solana-client': `js/${"
|
|
4451
|
+
'solana-client': `js/${"1.73.5" }`
|
|
4432
4452
|
};
|
|
4433
4453
|
|
|
4434
4454
|
/**
|
|
@@ -6472,7 +6492,7 @@ class Connection {
|
|
|
6472
6492
|
throw new Error('Invalid arguments');
|
|
6473
6493
|
}
|
|
6474
6494
|
const wireTransaction = transaction.serialize();
|
|
6475
|
-
return await this.sendRawTransaction(wireTransaction,
|
|
6495
|
+
return await this.sendRawTransaction(wireTransaction, signersOrOptions);
|
|
6476
6496
|
}
|
|
6477
6497
|
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6478
6498
|
throw new Error('Invalid arguments');
|
|
@@ -6633,12 +6653,11 @@ class Connection {
|
|
|
6633
6653
|
* @internal
|
|
6634
6654
|
*/
|
|
6635
6655
|
_onSubscriptionStateChange(clientSubscriptionId, callback) {
|
|
6636
|
-
var _this$_subscriptionSt;
|
|
6637
6656
|
const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
|
|
6638
6657
|
if (hash == null) {
|
|
6639
6658
|
return () => {};
|
|
6640
6659
|
}
|
|
6641
|
-
const stateChangeCallbacks =
|
|
6660
|
+
const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash] ||= new Set();
|
|
6642
6661
|
stateChangeCallbacks.add(callback);
|
|
6643
6662
|
return () => {
|
|
6644
6663
|
stateChangeCallbacks.delete(callback);
|
|
@@ -9199,10 +9218,8 @@ class ValidatorInfo {
|
|
|
9199
9218
|
if (configKeyCount !== 2) return null;
|
|
9200
9219
|
const configKeys = [];
|
|
9201
9220
|
for (let i = 0; i < 2; i++) {
|
|
9202
|
-
const publicKey = new PublicKey(byteArray
|
|
9203
|
-
|
|
9204
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
9205
|
-
byteArray = byteArray.slice(1);
|
|
9221
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH));
|
|
9222
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
9206
9223
|
configKeys.push({
|
|
9207
9224
|
publicKey,
|
|
9208
9225
|
isSigner
|