@solana/web3.js 1.29.2 → 1.29.4

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/module.flow.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.15.0
5
5
  */
6
6
 
7
7
  declare module "@solana/web3.js" {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.29.2",
3
+ "version": "1.29.4",
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": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen; npm run flow:gen; npm run flow:check",
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 --treatWarningsAsErrors",
47
- "flow:check": "flow check-contents < module.flow.js",
48
- "flow:gen": "flowgen lib/index.d.ts -o module.flow.js",
49
- "type:gen": "./scripts/typegen.sh",
50
- "lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
51
- "lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
52
- "ok": "run-s lint test doc",
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
  "@solana/buffer-layout": "^3.0.0",
@@ -69,7 +44,7 @@
69
44
  "bs58": "^4.0.1",
70
45
  "buffer": "6.0.1",
71
46
  "cross-fetch": "^3.1.4",
72
- "crypto-hash": "^1.2.2",
47
+ "ethers": "^5.5.1",
73
48
  "jayson": "^3.4.4",
74
49
  "js-sha3": "^0.8.0",
75
50
  "rpc-websockets": "^7.4.2",
@@ -88,7 +63,7 @@
88
63
  "@commitlint/travis-cli": "^13.1.0",
89
64
  "@rollup/plugin-alias": "^3.1.2",
90
65
  "@rollup/plugin-babel": "^5.2.3",
91
- "@rollup/plugin-commonjs": "^20.0.0",
66
+ "@rollup/plugin-commonjs": "^21.0.0",
92
67
  "@rollup/plugin-json": "^4.1.0",
93
68
  "@rollup/plugin-multi-entry": "^4.0.0",
94
69
  "@rollup/plugin-node-resolve": "^13.0.0",
@@ -112,7 +87,7 @@
112
87
  "cross-env": "7.0.3",
113
88
  "eslint": "^7.19.0",
114
89
  "eslint-config-prettier": "^8.0.0",
115
- "eslint-plugin-import": "2.24.2",
90
+ "eslint-plugin-import": "2.25.2",
116
91
  "eslint-plugin-mocha": "^9.0.0",
117
92
  "eslint-plugin-prettier": "^4.0.0",
118
93
  "esm": "^3.2.25",
@@ -128,7 +103,7 @@
128
103
  "prettier": "^2.3.0",
129
104
  "puppeteer": "^10.2.0",
130
105
  "rimraf": "3.0.2",
131
- "rollup": "2.57.0",
106
+ "rollup": "2.58.0",
132
107
  "rollup-plugin-dts": "^4.0.0",
133
108
  "rollup-plugin-node-polyfills": "^0.2.1",
134
109
  "rollup-plugin-terser": "^7.0.2",
@@ -142,5 +117,30 @@
142
117
  },
143
118
  "engines": {
144
119
  "node": ">=12.20.0"
120
+ },
121
+ "scripts": {
122
+ "build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen; npm run flow:gen; npm run flow:check",
123
+ "build:browser-test": "rollup -c test/rollup.config.js",
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
+ "flow:check": "flow check-contents < module.flow.js",
130
+ "flow:gen": "flowgen lib/index.d.ts -o module.flow.js",
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
+ "ok": "run-s lint test doc",
135
+ "pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
136
+ "pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
137
+ "re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
138
+ "test": "mocha -r ts-node/register './test/**/*.test.ts'",
139
+ "test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
140
+ "test:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
141
+ "test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
142
+ "test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
143
+ "test:live": "TEST_LIVE=1 npm run test",
144
+ "test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
145
145
  }
146
- }
146
+ }
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
@@ -205,32 +206,28 @@ export class Message {
205
206
  // Slice up wire data
206
207
  let byteArray = [...buffer];
207
208
 
208
- const numRequiredSignatures = byteArray.shift() as number;
209
- const numReadonlySignedAccounts = byteArray.shift() as number;
210
- const numReadonlyUnsignedAccounts = byteArray.shift() as number;
209
+ const numRequiredSignatures = guardedShift(byteArray);
210
+ const numReadonlySignedAccounts = guardedShift(byteArray);
211
+ const numReadonlyUnsignedAccounts = guardedShift(byteArray);
211
212
 
212
213
  const accountCount = shortvec.decodeLength(byteArray);
213
214
  let accountKeys = [];
214
215
  for (let i = 0; i < accountCount; i++) {
215
- const account = byteArray.slice(0, PUBKEY_LENGTH);
216
- byteArray = byteArray.slice(PUBKEY_LENGTH);
216
+ const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
217
217
  accountKeys.push(bs58.encode(Buffer.from(account)));
218
218
  }
219
219
 
220
- const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
221
- byteArray = byteArray.slice(PUBKEY_LENGTH);
220
+ const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
222
221
 
223
222
  const instructionCount = shortvec.decodeLength(byteArray);
224
223
  let instructions: CompiledInstruction[] = [];
225
224
  for (let i = 0; i < instructionCount; i++) {
226
- const programIdIndex = byteArray.shift() as number;
225
+ const programIdIndex = guardedShift(byteArray);
227
226
  const accountCount = shortvec.decodeLength(byteArray);
228
- const accounts = byteArray.slice(0, accountCount);
229
- byteArray = byteArray.slice(accountCount);
227
+ const accounts = guardedSplice(byteArray, 0, accountCount);
230
228
  const dataLength = shortvec.decodeLength(byteArray);
231
- const dataSlice = byteArray.slice(0, dataLength);
229
+ const dataSlice = guardedSplice(byteArray, 0, dataLength);
232
230
  const data = bs58.encode(Buffer.from(dataSlice));
233
- byteArray = byteArray.slice(dataLength);
234
231
  instructions.push({
235
232
  programIdIndex,
236
233
  accounts,
package/src/publickey.ts CHANGED
@@ -2,7 +2,7 @@ import BN from 'bn.js';
2
2
  import bs58 from 'bs58';
3
3
  import {Buffer} from 'buffer';
4
4
  import nacl from 'tweetnacl';
5
- import {sha256} from 'crypto-hash';
5
+ import {ethers} from 'ethers';
6
6
 
7
7
  import {Struct, SOLANA_SCHEMA} from './util/borsh-schema';
8
8
  import {toBuffer} from './util/to-buffer';
@@ -120,6 +120,7 @@ export class PublicKey extends Struct {
120
120
  * The program ID will also serve as the owner of the public key, giving
121
121
  * it permission to write data to the account.
122
122
  */
123
+ /* eslint-disable require-await */
123
124
  static async createWithSeed(
124
125
  fromPublicKey: PublicKey,
125
126
  seed: string,
@@ -130,13 +131,14 @@ export class PublicKey extends Struct {
130
131
  Buffer.from(seed),
131
132
  programId.toBuffer(),
132
133
  ]);
133
- const hash = await sha256(new Uint8Array(buffer));
134
+ const hash = ethers.utils.sha256(new Uint8Array(buffer)).slice(2);
134
135
  return new PublicKey(Buffer.from(hash, 'hex'));
135
136
  }
136
137
 
137
138
  /**
138
139
  * Derive a program address from seeds and a program ID.
139
140
  */
141
+ /* eslint-disable require-await */
140
142
  static async createProgramAddress(
141
143
  seeds: Array<Buffer | Uint8Array>,
142
144
  programId: PublicKey,
@@ -153,7 +155,7 @@ export class PublicKey extends Struct {
153
155
  programId.toBuffer(),
154
156
  Buffer.from('ProgramDerivedAddress'),
155
157
  ]);
156
- let hash = await sha256(new Uint8Array(buffer));
158
+ let hash = ethers.utils.sha256(new Uint8Array(buffer)).slice(2);
157
159
  let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
158
160
  if (is_on_curve(publicKeyBytes)) {
159
161
  throw new Error(`Invalid seeds, address must fall off the curve`);
@@ -10,6 +10,7 @@ import invariant from './util/assert';
10
10
  import type {Signer} from './keypair';
11
11
  import type {Blockhash} from './blockhash';
12
12
  import type {CompiledInstruction} from './message';
13
+ import {guardedSplice} from './util/guarded-array-utils';
13
14
 
14
15
  /**
15
16
  * Transaction signature as base-58 encoded string
@@ -655,8 +656,7 @@ export class Transaction {
655
656
  const signatureCount = shortvec.decodeLength(byteArray);
656
657
  let signatures = [];
657
658
  for (let i = 0; i < signatureCount; i++) {
658
- const signature = byteArray.slice(0, SIGNATURE_LENGTH);
659
- byteArray = byteArray.slice(SIGNATURE_LENGTH);
659
+ const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
660
660
  signatures.push(bs58.encode(Buffer.from(signature)));
661
661
  }
662
662
 
@@ -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',
@@ -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