@solana/web3.js 1.37.1 → 1.37.3
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 +54 -19
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +54 -19
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +54 -19
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +54 -19
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +54 -19
- 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/package.json +24 -24
- package/src/connection.ts +11 -1
- package/src/message.ts +9 -12
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.37.
|
|
3
|
+
"version": "1.37.3",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -36,28 +36,6 @@
|
|
|
36
36
|
"/module.flow.js",
|
|
37
37
|
"/src"
|
|
38
38
|
],
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen; npm run flow:gen; npm run flow:check",
|
|
41
|
-
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
42
|
-
"clean": "rimraf ./coverage ./lib",
|
|
43
|
-
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
|
|
44
|
-
"dev": "cross-env NODE_ENV=development rollup -c",
|
|
45
|
-
"doc": "set -ex; typedoc --treatWarningsAsErrors",
|
|
46
|
-
"flow:check": "flow check-contents < module.flow.js",
|
|
47
|
-
"flow:gen": "flowgen lib/index.d.ts -o module.flow.js",
|
|
48
|
-
"type:gen": "./scripts/typegen.sh",
|
|
49
|
-
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
50
|
-
"lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
|
|
51
|
-
"type:check": "tsc -p tsconfig.json --noEmit",
|
|
52
|
-
"ok": "run-s lint test doc type:check",
|
|
53
|
-
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
54
|
-
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
55
|
-
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
56
|
-
"test": "mocha -r ts-node/register './test/**/*.test.ts'",
|
|
57
|
-
"test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
|
|
58
|
-
"test:live": "TEST_LIVE=1 npm run test",
|
|
59
|
-
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
60
|
-
},
|
|
61
39
|
"dependencies": {
|
|
62
40
|
"@babel/runtime": "^7.12.5",
|
|
63
41
|
"@ethersproject/sha2": "^5.5.0",
|
|
@@ -138,5 +116,27 @@
|
|
|
138
116
|
},
|
|
139
117
|
"engines": {
|
|
140
118
|
"node": ">=12.20.0"
|
|
119
|
+
},
|
|
120
|
+
"scripts": {
|
|
121
|
+
"build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen; npm run flow:gen; npm run flow:check",
|
|
122
|
+
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
123
|
+
"clean": "rimraf ./coverage ./lib",
|
|
124
|
+
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
|
|
125
|
+
"dev": "cross-env NODE_ENV=development rollup -c",
|
|
126
|
+
"doc": "set -ex; typedoc --treatWarningsAsErrors",
|
|
127
|
+
"flow:check": "flow check-contents < module.flow.js",
|
|
128
|
+
"flow:gen": "flowgen lib/index.d.ts -o module.flow.js",
|
|
129
|
+
"type:gen": "./scripts/typegen.sh",
|
|
130
|
+
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
131
|
+
"lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
|
|
132
|
+
"type:check": "tsc -p tsconfig.json --noEmit",
|
|
133
|
+
"ok": "run-s lint test doc type:check",
|
|
134
|
+
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
135
|
+
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
136
|
+
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
137
|
+
"test": "mocha -r ts-node/register './test/**/*.test.ts'",
|
|
138
|
+
"test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
|
|
139
|
+
"test:live": "TEST_LIVE=1 npm run test",
|
|
140
|
+
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
141
141
|
}
|
|
142
|
-
}
|
|
142
|
+
}
|
package/src/connection.ts
CHANGED
|
@@ -3878,7 +3878,14 @@ export class Connection {
|
|
|
3878
3878
|
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>> {
|
|
3879
3879
|
let transaction;
|
|
3880
3880
|
if (transactionOrMessage instanceof Transaction) {
|
|
3881
|
-
|
|
3881
|
+
let originalTx: Transaction = transactionOrMessage;
|
|
3882
|
+
transaction = new Transaction({
|
|
3883
|
+
recentBlockhash: originalTx.recentBlockhash,
|
|
3884
|
+
nonceInfo: originalTx.nonceInfo,
|
|
3885
|
+
feePayer: originalTx.feePayer,
|
|
3886
|
+
signatures: [...originalTx.signatures],
|
|
3887
|
+
});
|
|
3888
|
+
transaction.instructions = transactionOrMessage.instructions;
|
|
3882
3889
|
} else {
|
|
3883
3890
|
transaction = Transaction.populate(transactionOrMessage);
|
|
3884
3891
|
}
|
|
@@ -4154,6 +4161,9 @@ export class Connection {
|
|
|
4154
4161
|
Object.values(this._accountChangeSubscriptions).forEach(
|
|
4155
4162
|
s => (s.subscriptionId = null),
|
|
4156
4163
|
);
|
|
4164
|
+
Object.values(this._logsSubscriptions).forEach(
|
|
4165
|
+
s => (s.subscriptionId = null),
|
|
4166
|
+
);
|
|
4157
4167
|
Object.values(this._programAccountChangeSubscriptions).forEach(
|
|
4158
4168
|
s => (s.subscriptionId = null),
|
|
4159
4169
|
);
|
package/src/message.ts
CHANGED
|
@@ -8,6 +8,7 @@ import * as Layout from './layout';
|
|
|
8
8
|
import {PACKET_DATA_SIZE} from './transaction';
|
|
9
9
|
import * as shortvec from './util/shortvec-encoding';
|
|
10
10
|
import {toBuffer} from './util/to-buffer';
|
|
11
|
+
import {guardedShift, guardedSplice} from './util/guarded-array-utils';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The message header, identifying signed and read-only account
|
|
@@ -222,32 +223,28 @@ export class Message {
|
|
|
222
223
|
// Slice up wire data
|
|
223
224
|
let byteArray = [...buffer];
|
|
224
225
|
|
|
225
|
-
const numRequiredSignatures = byteArray
|
|
226
|
-
const numReadonlySignedAccounts = byteArray
|
|
227
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
226
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
227
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
228
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
228
229
|
|
|
229
230
|
const accountCount = shortvec.decodeLength(byteArray);
|
|
230
231
|
let accountKeys = [];
|
|
231
232
|
for (let i = 0; i < accountCount; i++) {
|
|
232
|
-
const account = byteArray
|
|
233
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
233
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
234
234
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
const recentBlockhash = byteArray
|
|
238
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
237
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
239
238
|
|
|
240
239
|
const instructionCount = shortvec.decodeLength(byteArray);
|
|
241
240
|
let instructions: CompiledInstruction[] = [];
|
|
242
241
|
for (let i = 0; i < instructionCount; i++) {
|
|
243
|
-
const programIdIndex = byteArray
|
|
242
|
+
const programIdIndex = guardedShift(byteArray);
|
|
244
243
|
const accountCount = shortvec.decodeLength(byteArray);
|
|
245
|
-
const accounts = byteArray
|
|
246
|
-
byteArray = byteArray.slice(accountCount);
|
|
244
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
247
245
|
const dataLength = shortvec.decodeLength(byteArray);
|
|
248
|
-
const dataSlice = byteArray
|
|
246
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
249
247
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
250
|
-
byteArray = byteArray.slice(dataLength);
|
|
251
248
|
instructions.push({
|
|
252
249
|
programIdIndex,
|
|
253
250
|
accounts,
|
package/src/transaction.ts
CHANGED
|
@@ -11,6 +11,7 @@ import invariant from './util/assert';
|
|
|
11
11
|
import type {Signer} from './keypair';
|
|
12
12
|
import type {Blockhash} from './blockhash';
|
|
13
13
|
import type {CompiledInstruction} from './message';
|
|
14
|
+
import {guardedSplice} from './util/guarded-array-utils';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Transaction signature as base-58 encoded string
|
|
@@ -666,8 +667,7 @@ export class Transaction {
|
|
|
666
667
|
const signatureCount = shortvec.decodeLength(byteArray);
|
|
667
668
|
let signatures = [];
|
|
668
669
|
for (let i = 0; i < signatureCount; i++) {
|
|
669
|
-
const signature = byteArray
|
|
670
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
670
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
671
671
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
672
672
|
}
|
|
673
673
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
5
|
+
*/
|
|
6
|
+
export function guardedShift<T>(byteArray: T[]): T {
|
|
7
|
+
if (byteArray.length === 0) {
|
|
8
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
9
|
+
}
|
|
10
|
+
return byteArray.shift() as T;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
15
|
+
* the array.
|
|
16
|
+
*/
|
|
17
|
+
export function guardedSplice<T>(
|
|
18
|
+
byteArray: T[],
|
|
19
|
+
...args:
|
|
20
|
+
| [start: number, deleteCount?: number]
|
|
21
|
+
| [start: number, deleteCount: number, ...items: T[]]
|
|
22
|
+
): T[] {
|
|
23
|
+
var _args$;
|
|
24
|
+
const [start] = args;
|
|
25
|
+
if (
|
|
26
|
+
args.length === 2 // Implies that `deleteCount` was supplied
|
|
27
|
+
? start +
|
|
28
|
+
((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) >
|
|
29
|
+
byteArray.length
|
|
30
|
+
: start >= byteArray.length
|
|
31
|
+
) {
|
|
32
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
33
|
+
}
|
|
34
|
+
return byteArray.splice(
|
|
35
|
+
...(args as Parameters<typeof Array.prototype.splice>),
|
|
36
|
+
);
|
|
37
|
+
}
|
package/src/validator-info.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import * as Layout from './layout';
|
|
10
10
|
import * as shortvec from './util/shortvec-encoding';
|
|
11
11
|
import {PublicKey} from './publickey';
|
|
12
|
+
import {guardedShift, guardedSplice} from './util/guarded-array-utils';
|
|
12
13
|
|
|
13
14
|
export const VALIDATOR_INFO_KEY = new PublicKey(
|
|
14
15
|
'Va1idator1nfo111111111111111111111111111111',
|
|
@@ -85,10 +86,10 @@ export class ValidatorInfo {
|
|
|
85
86
|
|
|
86
87
|
const configKeys: Array<ConfigKey> = [];
|
|
87
88
|
for (let i = 0; i < 2; i++) {
|
|
88
|
-
const publicKey = new PublicKey(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
const publicKey = new PublicKey(
|
|
90
|
+
guardedSplice(byteArray, 0, PUBKEY_LENGTH),
|
|
91
|
+
);
|
|
92
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
92
93
|
configKeys.push({publicKey, isSigner});
|
|
93
94
|
}
|
|
94
95
|
|