@solana/web3.js 1.20.1 → 1.20.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.esm.js +78 -2014
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +75 -45
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +72 -41
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +1647 -3826
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +10 -2
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +27 -27
- package/src/connection.ts +3 -4
- package/src/message.ts +9 -12
- package/src/secp256k1-program.ts +1 -1
- package/src/transaction.ts +3 -3
- package/src/util/assert.ts +8 -0
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/util/url.ts +3 -5
- 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.20.
|
|
3
|
+
"version": "1.20.3",
|
|
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",
|
|
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",
|
|
@@ -139,5 +114,30 @@
|
|
|
139
114
|
"tslib": "^2.1.0",
|
|
140
115
|
"typedoc": "^0.21.0-beta.2",
|
|
141
116
|
"typescript": "^4.3.2"
|
|
117
|
+
},
|
|
118
|
+
"scripts": {
|
|
119
|
+
"build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen; npm run flow:gen; npm run flow:check",
|
|
120
|
+
"build:browser-test": "rollup -c test/rollup.config.js",
|
|
121
|
+
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
122
|
+
"clean": "rimraf ./coverage ./lib",
|
|
123
|
+
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
|
|
124
|
+
"dev": "cross-env NODE_ENV=development rollup -c",
|
|
125
|
+
"doc": "set -ex; typedoc",
|
|
126
|
+
"flow:check": "flow check-contents < module.flow.js",
|
|
127
|
+
"flow:gen": "flowgen lib/index.d.ts -o module.flow.js",
|
|
128
|
+
"type:gen": "./scripts/typegen.sh",
|
|
129
|
+
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
130
|
+
"lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
|
|
131
|
+
"ok": "run-s lint test doc",
|
|
132
|
+
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
133
|
+
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
134
|
+
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
135
|
+
"test": "mocha -r ts-node/register './test/**/*.test.ts'",
|
|
136
|
+
"test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
|
|
137
|
+
"test:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
|
|
138
|
+
"test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
|
|
139
|
+
"test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
|
|
140
|
+
"test:live": "TEST_LIVE=1 npm run test",
|
|
141
|
+
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
142
142
|
}
|
|
143
|
-
}
|
|
143
|
+
}
|
package/src/connection.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
1
|
import bs58 from 'bs58';
|
|
3
2
|
import {Buffer} from 'buffer';
|
|
4
|
-
import {parse as urlParse} from 'url';
|
|
5
3
|
import fetch, {Response} from 'node-fetch';
|
|
6
4
|
import {
|
|
7
5
|
type as pick,
|
|
@@ -34,6 +32,7 @@ import {Signer} from './keypair';
|
|
|
34
32
|
import {MS_PER_SLOT} from './timing';
|
|
35
33
|
import {Transaction} from './transaction';
|
|
36
34
|
import {Message} from './message';
|
|
35
|
+
import assert from './util/assert';
|
|
37
36
|
import {sleep} from './util/sleep';
|
|
38
37
|
import {promiseTimeout} from './util/promise-timeout';
|
|
39
38
|
import {toBuffer} from './util/to-buffer';
|
|
@@ -2025,7 +2024,7 @@ export class Connection {
|
|
|
2025
2024
|
endpoint: string,
|
|
2026
2025
|
commitmentOrConfig?: Commitment | ConnectionConfig,
|
|
2027
2026
|
) {
|
|
2028
|
-
let url =
|
|
2027
|
+
let url = new URL(endpoint);
|
|
2029
2028
|
const useHttps = url.protocol === 'https:';
|
|
2030
2029
|
|
|
2031
2030
|
let wsEndpoint;
|
|
@@ -2046,7 +2045,7 @@ export class Connection {
|
|
|
2046
2045
|
this._rpcWsEndpoint = wsEndpoint || makeWebsocketUrl(endpoint);
|
|
2047
2046
|
|
|
2048
2047
|
this._rpcClient = createRpcClient(
|
|
2049
|
-
url.
|
|
2048
|
+
url.toString(),
|
|
2050
2049
|
useHttps,
|
|
2051
2050
|
httpHeaders,
|
|
2052
2051
|
fetchMiddleware,
|
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
|
|
@@ -178,32 +179,28 @@ export class Message {
|
|
|
178
179
|
// Slice up wire data
|
|
179
180
|
let byteArray = [...buffer];
|
|
180
181
|
|
|
181
|
-
const numRequiredSignatures = byteArray
|
|
182
|
-
const numReadonlySignedAccounts = byteArray
|
|
183
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
182
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
183
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
184
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
184
185
|
|
|
185
186
|
const accountCount = shortvec.decodeLength(byteArray);
|
|
186
187
|
let accountKeys = [];
|
|
187
188
|
for (let i = 0; i < accountCount; i++) {
|
|
188
|
-
const account = byteArray
|
|
189
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
189
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
190
190
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
const recentBlockhash = byteArray
|
|
194
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
193
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
195
194
|
|
|
196
195
|
const instructionCount = shortvec.decodeLength(byteArray);
|
|
197
196
|
let instructions: CompiledInstruction[] = [];
|
|
198
197
|
for (let i = 0; i < instructionCount; i++) {
|
|
199
|
-
const programIdIndex = byteArray
|
|
198
|
+
const programIdIndex = guardedShift(byteArray);
|
|
200
199
|
const accountCount = shortvec.decodeLength(byteArray);
|
|
201
|
-
const accounts = byteArray
|
|
202
|
-
byteArray = byteArray.slice(accountCount);
|
|
200
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
203
201
|
const dataLength = shortvec.decodeLength(byteArray);
|
|
204
|
-
const dataSlice = byteArray
|
|
202
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
205
203
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
206
|
-
byteArray = byteArray.slice(dataLength);
|
|
207
204
|
instructions.push({
|
|
208
205
|
programIdIndex,
|
|
209
206
|
accounts,
|
package/src/secp256k1-program.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {Buffer} from 'buffer';
|
|
2
2
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
3
3
|
import secp256k1 from 'secp256k1';
|
|
4
|
-
import assert from 'assert';
|
|
5
4
|
import {keccak_256} from 'js-sha3';
|
|
6
5
|
|
|
7
6
|
import {PublicKey} from './publickey';
|
|
8
7
|
import {TransactionInstruction} from './transaction';
|
|
8
|
+
import assert from './util/assert';
|
|
9
9
|
import {toBuffer} from './util/to-buffer';
|
|
10
10
|
|
|
11
11
|
const {publicKeyCreate, ecdsaSign} = secp256k1;
|
package/src/transaction.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import invariant from 'assert';
|
|
2
1
|
import nacl from 'tweetnacl';
|
|
3
2
|
import bs58 from 'bs58';
|
|
4
3
|
import {Buffer} from 'buffer';
|
|
@@ -7,9 +6,11 @@ import {Message} from './message';
|
|
|
7
6
|
import {PublicKey} from './publickey';
|
|
8
7
|
import * as shortvec from './util/shortvec-encoding';
|
|
9
8
|
import {toBuffer} from './util/to-buffer';
|
|
9
|
+
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
|
|
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
|
+
}
|
package/src/util/url.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {format as urlFormat, parse as urlParse} from 'url';
|
|
2
|
-
|
|
3
1
|
export function makeWebsocketUrl(endpoint: string) {
|
|
4
|
-
let url =
|
|
2
|
+
let url = new URL(endpoint);
|
|
5
3
|
const useHttps = url.protocol === 'https:';
|
|
6
4
|
|
|
7
5
|
url.protocol = useHttps ? 'wss:' : 'ws:';
|
|
@@ -13,8 +11,8 @@ export function makeWebsocketUrl(endpoint: string) {
|
|
|
13
11
|
// When the endpoint omits the port, we're connecting to the protocol
|
|
14
12
|
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
15
13
|
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
16
|
-
if (url.port !==
|
|
14
|
+
if (url.port !== '') {
|
|
17
15
|
url.port = String(Number(url.port) + 1);
|
|
18
16
|
}
|
|
19
|
-
return
|
|
17
|
+
return url.toString();
|
|
20
18
|
}
|
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
|
|