@solana/web3.js 1.43.5 → 1.43.7

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.43.5",
3
+ "version": "1.43.7",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -35,26 +35,6 @@
35
35
  "/lib",
36
36
  "/src"
37
37
  ],
38
- "scripts": {
39
- "build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen",
40
- "build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
41
- "clean": "rimraf ./coverage ./lib",
42
- "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
43
- "dev": "cross-env NODE_ENV=development rollup -c",
44
- "doc": "set -ex; typedoc --treatWarningsAsErrors",
45
- "type:gen": "./scripts/typegen.sh",
46
- "lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
47
- "lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
48
- "type:check": "tsc -p tsconfig.json --noEmit",
49
- "ok": "run-s lint test doc type:check",
50
- "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
51
- "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
52
- "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
53
- "test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\" }' ts-mocha --require esm './test/**/*.test.ts'",
54
- "test:cover": "nyc --reporter=lcov npm run test",
55
- "test:live": "TEST_LIVE=1 npm run test",
56
- "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
57
- },
58
38
  "dependencies": {
59
39
  "@babel/runtime": "^7.12.5",
60
40
  "@ethersproject/sha2": "^5.5.0",
@@ -138,5 +118,25 @@
138
118
  },
139
119
  "engines": {
140
120
  "node": ">=12.20.0"
121
+ },
122
+ "scripts": {
123
+ "build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen",
124
+ "build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
125
+ "clean": "rimraf ./coverage ./lib",
126
+ "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
127
+ "dev": "cross-env NODE_ENV=development rollup -c",
128
+ "doc": "set -ex; typedoc --treatWarningsAsErrors",
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": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\" }' ts-mocha --require esm './test/**/*.test.ts'",
138
+ "test:cover": "nyc --reporter=lcov npm run test",
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/message.ts CHANGED
@@ -8,6 +8,7 @@ import * as Layout from './layout';
8
8
  import {PACKET_DATA_SIZE} from './transaction-constants';
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.shift() as number;
226
- const numReadonlySignedAccounts = byteArray.shift() as number;
227
- const numReadonlyUnsignedAccounts = byteArray.shift() as number;
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.slice(0, PUBKEY_LENGTH);
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.slice(0, PUBKEY_LENGTH);
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.shift() as number;
242
+ const programIdIndex = guardedShift(byteArray);
244
243
  const accountCount = shortvec.decodeLength(byteArray);
245
- const accounts = byteArray.slice(0, accountCount);
246
- byteArray = byteArray.slice(accountCount);
244
+ const accounts = guardedSplice(byteArray, 0, accountCount);
247
245
  const dataLength = shortvec.decodeLength(byteArray);
248
- const dataSlice = byteArray.slice(0, dataLength);
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,
@@ -15,6 +15,7 @@ import invariant from './util/assert';
15
15
  import type {Signer} from './keypair';
16
16
  import type {Blockhash} from './blockhash';
17
17
  import type {CompiledInstruction} from './message';
18
+ import {guardedSplice} from './util/guarded-array-utils';
18
19
 
19
20
  /**
20
21
  * Transaction signature as base-58 encoded string
@@ -142,6 +143,11 @@ export type TransactionCtorFields_DEPRECATED = {
142
143
  recentBlockhash?: Blockhash;
143
144
  };
144
145
 
146
+ // For backward compatibility; an unfortunate consequence of being
147
+ // forced to over-export types by the documentation generator.
148
+ // See https://github.com/solana-labs/solana/pull/25820
149
+ export type TransactionCtorFields = TransactionCtorFields_DEPRECATED;
150
+
145
151
  /**
146
152
  * List of Transaction object fields that may be initialized at construction
147
153
  */
@@ -788,8 +794,7 @@ export class Transaction {
788
794
  const signatureCount = shortvec.decodeLength(byteArray);
789
795
  let signatures = [];
790
796
  for (let i = 0; i < signatureCount; i++) {
791
- const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
792
- byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
797
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
793
798
  signatures.push(bs58.encode(Buffer.from(signature)));
794
799
  }
795
800
 
@@ -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 './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(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