@solana/web3.js 1.1.0 → 1.1.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/util/to-buffer.ts","../../src/publickey.ts","../../src/account.ts","../../src/blockhash.ts","../../src/bpf-loader-deprecated.ts","../../src/layout.ts","../../src/util/shortvec-encoding.ts","../../src/message.ts","../../src/transaction.ts","../../src/sysvar.ts","../../src/agent-manager.ts","../../src/fee-calculator.ts","../../src/nonce-account.ts","../../src/timing.ts","../../src/util/sleep.ts","../../src/util/promise-timeout.ts","../../src/connection.ts","../../src/util/send-and-confirm-transaction.ts","../../src/instruction.ts","../../src/system-program.ts","../../src/loader.ts","../../src/bpf-loader.ts","../../src/stake-program.ts","../../src/secp256k1-program.ts","../../src/validator-info.ts","../../src/vote-account.ts","../../src/util/send-and-confirm-raw-transaction.ts","../../src/util/cluster.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyBkwB,MAAO;;;;;;;;;;;;;;iBAAkkB,MAAO;;kBAAiD,mBAAoB;;;;;;;iBAA4J,SAAU;;kBAAiD,mBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAAppB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAJj0rE;;GAEG;AACH,QAAO,MAAM,gBAAgB,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts","../../src/util/to-buffer.ts","../../src/publickey.ts","../../src/account.ts","../../src/blockhash.ts","../../src/bpf-loader-deprecated.ts","../../src/layout.ts","../../src/util/shortvec-encoding.ts","../../src/util/guarded-array-utils.ts","../../src/message.ts","../../src/transaction.ts","../../src/sysvar.ts","../../src/agent-manager.ts","../../src/fee-calculator.ts","../../src/nonce-account.ts","../../src/timing.ts","../../src/util/sleep.ts","../../src/util/promise-timeout.ts","../../src/connection.ts","../../src/util/send-and-confirm-transaction.ts","../../src/instruction.ts","../../src/system-program.ts","../../src/loader.ts","../../src/bpf-loader.ts","../../src/stake-program.ts","../../src/secp256k1-program.ts","../../src/validator-info.ts","../../src/vote-account.ts","../../src/util/send-and-confirm-raw-transaction.ts","../../src/util/cluster.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAyB00B,MAAO;;;;;;;;;;;;;;iBAAkkB,MAAO;;kBAAiD,mBAAoB;;;;;;;iBAA4J,SAAU;;kBAAiD,mBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAJj0rE;;GAEG;AACH,QAAO,MAAM,gBAAgB,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -36,31 +36,6 @@
36
36
  "/module.flow.js",
37
37
  "/src"
38
38
  ],
39
- "scripts": {
40
- "build": "cross-env NODE_ENV=production rollup -c; npx flowgen lib/types/index.d.ts -o module.flow.js",
41
- "build:browser-test": "rollup -c test/rollup.config.js",
42
- "build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
43
- "clean": "rimraf ./coverage ./lib",
44
- "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
45
- "dev": "cross-env NODE_ENV=development rollup -c",
46
- "doc": "set -ex; typedoc",
47
- "doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/",
48
- "lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
49
- "lint:fix": "npm run pretty:fix && eslint . --fix",
50
- "lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
51
- "ok": "run-s lint test doc",
52
- "prepare": "run-s clean build",
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:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
59
- "test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
60
- "test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
61
- "test:live": "TEST_LIVE=1 npm run test",
62
- "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
63
- },
64
39
  "dependencies": {
65
40
  "@babel/runtime": "^7.12.5",
66
41
  "bn.js": "^5.0.0",
@@ -121,10 +96,11 @@
121
96
  "mocha-headless-chrome": "^3.1.0",
122
97
  "mockttp": "^1.1.0",
123
98
  "mz": "^2.7.0",
99
+ "npm-run-all": "^4.1.5",
124
100
  "nyc": "^15.1.0",
125
101
  "prettier": "^2.0.0",
126
102
  "rimraf": "3.0.2",
127
- "rollup": "2.42.0",
103
+ "rollup": "2.42.4",
128
104
  "rollup-plugin-flat-dts": "^1.0.3",
129
105
  "rollup-plugin-node-polyfills": "^0.2.1",
130
106
  "rollup-plugin-terser": "^7.0.2",
@@ -137,5 +113,29 @@
137
113
  "typedoc": "^0.20.31",
138
114
  "typescript": "^4.1.5",
139
115
  "watch": "^1.0.2"
116
+ },
117
+ "scripts": {
118
+ "build": "cross-env NODE_ENV=production rollup -c; npx flowgen lib/types/index.d.ts -o module.flow.js",
119
+ "build:browser-test": "rollup -c test/rollup.config.js",
120
+ "build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
121
+ "clean": "rimraf ./coverage ./lib",
122
+ "codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
123
+ "dev": "cross-env NODE_ENV=development rollup -c",
124
+ "doc": "set -ex; typedoc",
125
+ "doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/",
126
+ "lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
127
+ "lint:fix": "npm run pretty:fix && eslint . --fix",
128
+ "lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
129
+ "ok": "run-s lint test doc",
130
+ "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
131
+ "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
132
+ "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
133
+ "test": "mocha -r ts-node/register './test/**/*.test.ts'",
134
+ "test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
135
+ "test:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
136
+ "test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
137
+ "test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
138
+ "test:live": "TEST_LIVE=1 npm run test",
139
+ "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
140
140
  }
141
- }
141
+ }
package/src/message.ts CHANGED
@@ -7,6 +7,7 @@ import type {Blockhash} from './blockhash';
7
7
  import * as Layout from './layout';
8
8
  import {PACKET_DATA_SIZE} from './transaction';
9
9
  import * as shortvec from './util/shortvec-encoding';
10
+ import {guardedShift, guardedSplice} from './util/guarded-array-utils';
10
11
 
11
12
  /**
12
13
  * The message header, identifying signed and read-only account
@@ -177,32 +178,28 @@ export class Message {
177
178
  // Slice up wire data
178
179
  let byteArray = [...buffer];
179
180
 
180
- const numRequiredSignatures = byteArray.shift() as number;
181
- const numReadonlySignedAccounts = byteArray.shift() as number;
182
- const numReadonlyUnsignedAccounts = byteArray.shift() as number;
181
+ const numRequiredSignatures = guardedShift(byteArray);
182
+ const numReadonlySignedAccounts = guardedShift(byteArray);
183
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
183
184
 
184
185
  const accountCount = shortvec.decodeLength(byteArray);
185
186
  let accountKeys = [];
186
187
  for (let i = 0; i < accountCount; i++) {
187
- const account = byteArray.slice(0, PUBKEY_LENGTH);
188
- byteArray = byteArray.slice(PUBKEY_LENGTH);
188
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
189
189
  accountKeys.push(bs58.encode(Buffer.from(account)));
190
190
  }
191
191
 
192
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
193
- byteArray = byteArray.slice(PUBKEY_LENGTH);
192
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
194
193
 
195
194
  const instructionCount = shortvec.decodeLength(byteArray);
196
195
  let instructions: CompiledInstruction[] = [];
197
196
  for (let i = 0; i < instructionCount; i++) {
198
- const programIdIndex = byteArray.shift() as number;
197
+ const programIdIndex = guardedShift(byteArray);
199
198
  const accountCount = shortvec.decodeLength(byteArray);
200
- const accounts = byteArray.slice(0, accountCount);
201
- byteArray = byteArray.slice(accountCount);
199
+ const accounts = guardedSplice(byteArray, 0, accountCount);
202
200
  const dataLength = shortvec.decodeLength(byteArray);
203
- const dataSlice = byteArray.slice(0, dataLength);
201
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
204
202
  const data = bs58.encode(Buffer.from(dataSlice));
205
- byteArray = byteArray.slice(dataLength);
206
203
  instructions.push({
207
204
  programIdIndex,
208
205
  accounts,
@@ -10,6 +10,7 @@ import {Account} from './account';
10
10
  import * as shortvec from './util/shortvec-encoding';
11
11
  import type {Blockhash} from './blockhash';
12
12
  import {toBuffer} from './util/to-buffer';
13
+ import {guardedSplice} from './util/guarded-array-utils';
13
14
 
14
15
  /**
15
16
  * @typedef {string} TransactionSignature
@@ -667,8 +668,7 @@ export class Transaction {
667
668
  const signatureCount = shortvec.decodeLength(byteArray);
668
669
  let signatures = [];
669
670
  for (let i = 0; i < signatureCount; i++) {
670
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
671
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
671
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
672
672
  signatures.push(bs58.encode(Buffer.from(signature)));
673
673
  }
674
674
 
@@ -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
+ }
@@ -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',
@@ -87,10 +88,10 @@ export class ValidatorInfo {
87
88
 
88
89
  const configKeys: Array<ConfigKey> = [];
89
90
  for (let i = 0; i < 2; i++) {
90
- const publicKey = new PublicKey(byteArray.slice(0, PUBKEY_LENGTH));
91
- byteArray = byteArray.slice(PUBKEY_LENGTH);
92
- const isSigner = byteArray.slice(0, 1)[0] === 1;
93
- byteArray = byteArray.slice(1);
91
+ const publicKey = new PublicKey(
92
+ guardedSplice(byteArray, 0, PUBKEY_LENGTH),
93
+ );
94
+ const isSigner = guardedShift(byteArray) === 1;
94
95
  configKeys.push({publicKey, isSigner});
95
96
  }
96
97