@solana/web3.js 1.53.0 → 1.53.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.53.0",
3
+ "version": "1.53.1",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -36,26 +36,6 @@
36
36
  "/lib",
37
37
  "/src"
38
38
  ],
39
- "scripts": {
40
- "build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen",
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
- "type:gen": "./scripts/typegen.sh",
47
- "lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
48
- "lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
49
- "type:check": "tsc -p tsconfig.json --noEmit",
50
- "ok": "run-s lint test doc type:check",
51
- "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
52
- "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
53
- "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
54
- "test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\", \"target\": \"es2019\" }' ts-mocha --require esm './test/**/*.test.ts'",
55
- "test:cover": "nyc --reporter=lcov npm run test",
56
- "test:live": "TEST_LIVE=1 npm run test",
57
- "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
58
- },
59
39
  "dependencies": {
60
40
  "@babel/runtime": "^7.12.5",
61
41
  "@ethersproject/sha2": "^5.5.0",
@@ -140,5 +120,25 @@
140
120
  },
141
121
  "engines": {
142
122
  "node": ">=12.20.0"
123
+ },
124
+ "scripts": {
125
+ "build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen",
126
+ "build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
127
+ "clean": "rimraf ./coverage ./lib",
128
+ "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
129
+ "dev": "cross-env NODE_ENV=development rollup -c",
130
+ "doc": "set -ex; typedoc --treatWarningsAsErrors",
131
+ "type:gen": "./scripts/typegen.sh",
132
+ "lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
133
+ "lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
134
+ "type:check": "tsc -p tsconfig.json --noEmit",
135
+ "ok": "run-s lint test doc type:check",
136
+ "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
137
+ "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
138
+ "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
139
+ "test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\", \"target\": \"es2019\" }' ts-mocha --require esm './test/**/*.test.ts'",
140
+ "test:cover": "nyc --reporter=lcov npm run test",
141
+ "test:live": "TEST_LIVE=1 npm run test",
142
+ "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
143
143
  }
144
- }
144
+ }
@@ -9,6 +9,7 @@ import {PACKET_DATA_SIZE} from '../transaction/constants';
9
9
  import * as shortvec from '../utils/shortvec-encoding';
10
10
  import {toBuffer} from '../utils/to-buffer';
11
11
  import {CompiledInstruction, MessageHeader} from './index';
12
+ import {guardedShift, guardedSplice} from '../utils/guarded-array-utils';
12
13
 
13
14
  /**
14
15
  * Message constructor arguments
@@ -192,32 +193,28 @@ export class Message {
192
193
  // Slice up wire data
193
194
  let byteArray = [...buffer];
194
195
 
195
- const numRequiredSignatures = byteArray.shift() as number;
196
- const numReadonlySignedAccounts = byteArray.shift() as number;
197
- const numReadonlyUnsignedAccounts = byteArray.shift() as number;
196
+ const numRequiredSignatures = guardedShift(byteArray);
197
+ const numReadonlySignedAccounts = guardedShift(byteArray);
198
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
198
199
 
199
200
  const accountCount = shortvec.decodeLength(byteArray);
200
201
  let accountKeys = [];
201
202
  for (let i = 0; i < accountCount; i++) {
202
- const account = byteArray.slice(0, PUBKEY_LENGTH);
203
- byteArray = byteArray.slice(PUBKEY_LENGTH);
203
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
204
204
  accountKeys.push(bs58.encode(Buffer.from(account)));
205
205
  }
206
206
 
207
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
208
- byteArray = byteArray.slice(PUBKEY_LENGTH);
207
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
209
208
 
210
209
  const instructionCount = shortvec.decodeLength(byteArray);
211
210
  let instructions: CompiledInstruction[] = [];
212
211
  for (let i = 0; i < instructionCount; i++) {
213
- const programIdIndex = byteArray.shift() as number;
212
+ const programIdIndex = guardedShift(byteArray);
214
213
  const accountCount = shortvec.decodeLength(byteArray);
215
- const accounts = byteArray.slice(0, accountCount);
216
- byteArray = byteArray.slice(accountCount);
214
+ const accounts = guardedSplice(byteArray, 0, accountCount);
217
215
  const dataLength = shortvec.decodeLength(byteArray);
218
- const dataSlice = byteArray.slice(0, dataLength);
216
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
219
217
  const data = bs58.encode(Buffer.from(dataSlice));
220
- byteArray = byteArray.slice(dataLength);
221
218
  instructions.push({
222
219
  programIdIndex,
223
220
  accounts,
@@ -12,6 +12,7 @@ import invariant from '../utils/assert';
12
12
  import type {Signer} from '../keypair';
13
13
  import type {Blockhash} from '../blockhash';
14
14
  import type {CompiledInstruction} from '../message';
15
+ import {guardedSplice} from '../utils/guarded-array-utils';
15
16
 
16
17
  /**
17
18
  * Transaction signature as base-58 encoded string
@@ -805,8 +806,7 @@ export class Transaction {
805
806
  const signatureCount = shortvec.decodeLength(byteArray);
806
807
  let signatures = [];
807
808
  for (let i = 0; i < signatureCount; i++) {
808
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
809
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
809
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
810
810
  signatures.push(bs58.encode(Buffer.from(signature)));
811
811
  }
812
812
 
@@ -0,0 +1,34 @@
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
+ const [start] = args;
24
+ if (
25
+ args.length === 2 // Implies that `deleteCount` was supplied
26
+ ? start + (args[1] ?? 0) > byteArray.length
27
+ : start >= byteArray.length
28
+ ) {
29
+ throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
30
+ }
31
+ return byteArray.splice(
32
+ ...(args as Parameters<typeof Array.prototype.splice>),
33
+ );
34
+ }
@@ -9,6 +9,7 @@ import {
9
9
  import * as Layout from './layout';
10
10
  import * as shortvec from './utils/shortvec-encoding';
11
11
  import {PublicKey} from './publickey';
12
+ import {guardedShift, guardedSplice} from './utils/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(byteArray.slice(0, PUBKEY_LENGTH));
89
- byteArray = byteArray.slice(PUBKEY_LENGTH);
90
- const isSigner = byteArray.slice(0, 1)[0] === 1;
91
- byteArray = byteArray.slice(1);
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