@solana/web3.js 1.7.0 → 1.7.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.
- package/lib/index.browser.esm.js +63 -20
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +63 -20
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -3
- package/lib/index.esm.js +63 -20
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +77 -32
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +19 -4
- package/package.json +30 -30
- package/src/message.ts +9 -12
- package/src/publickey.ts +12 -0
- package/src/stake-program.ts +10 -4
- package/src/transaction.ts +2 -2
- package/src/util/guarded-array-utils.ts +37 -0
- package/src/validator-info.ts +5 -4
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.
|
|
4
|
+
* Flowgen v1.14.1
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
declare module "@solana/web3.js" {
|
|
@@ -22,6 +22,11 @@ declare module "@solana/web3.js" {
|
|
|
22
22
|
value: number | string | Buffer | Uint8Array | Array<number>
|
|
23
23
|
): this;
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Default public key value. (All zeros)
|
|
27
|
+
*/
|
|
28
|
+
static default: PublicKey;
|
|
29
|
+
|
|
25
30
|
/**
|
|
26
31
|
* Checks if two publicKeys are equal
|
|
27
32
|
*/
|
|
@@ -75,6 +80,11 @@ declare module "@solana/web3.js" {
|
|
|
75
80
|
seeds: Array<Buffer | Uint8Array>,
|
|
76
81
|
programId: PublicKey
|
|
77
82
|
): Promise<[PublicKey, number]>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check that a pubkey is on the ed25519 curve.
|
|
86
|
+
*/
|
|
87
|
+
static isOnCurve(pubkey: Uint8Array): boolean;
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
/**
|
|
@@ -2390,6 +2400,11 @@ feeCalculator: FeeCalculator,...
|
|
|
2390
2400
|
epoch: number,
|
|
2391
2401
|
custodian: PublicKey
|
|
2392
2402
|
): this;
|
|
2403
|
+
|
|
2404
|
+
/**
|
|
2405
|
+
* Default, inactive Lockup value
|
|
2406
|
+
*/
|
|
2407
|
+
static default: Lockup;
|
|
2393
2408
|
}
|
|
2394
2409
|
|
|
2395
2410
|
/**
|
|
@@ -2414,7 +2429,7 @@ feeCalculator: FeeCalculator,...
|
|
|
2414
2429
|
/**
|
|
2415
2430
|
* Lockup of the new stake account
|
|
2416
2431
|
*/
|
|
2417
|
-
lockup
|
|
2432
|
+
lockup?: Lockup,
|
|
2418
2433
|
|
|
2419
2434
|
/**
|
|
2420
2435
|
* Funding amount
|
|
@@ -2432,7 +2447,7 @@ feeCalculator: FeeCalculator,...
|
|
|
2432
2447
|
basePubkey: PublicKey,
|
|
2433
2448
|
seed: string,
|
|
2434
2449
|
authorized: Authorized,
|
|
2435
|
-
lockup
|
|
2450
|
+
lockup?: Lockup,
|
|
2436
2451
|
lamports: number,
|
|
2437
2452
|
...
|
|
2438
2453
|
};
|
|
@@ -2443,7 +2458,7 @@ feeCalculator: FeeCalculator,...
|
|
|
2443
2458
|
declare export type InitializeStakeParams = {
|
|
2444
2459
|
stakePubkey: PublicKey,
|
|
2445
2460
|
authorized: Authorized,
|
|
2446
|
-
lockup
|
|
2461
|
+
lockup?: Lockup,
|
|
2447
2462
|
...
|
|
2448
2463
|
};
|
|
2449
2464
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.2",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -36,32 +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 generate:dts; npm run generate:flow",
|
|
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
|
-
"generate:dts": "./scripts/typegen.sh",
|
|
49
|
-
"generate:flow": "flowgen lib/index.d.ts -o module.flow.js",
|
|
50
|
-
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
51
|
-
"lint:fix": "npm run pretty:fix && eslint . --fix",
|
|
52
|
-
"lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
|
|
53
|
-
"ok": "run-s lint test doc",
|
|
54
|
-
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
55
|
-
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
56
|
-
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
57
|
-
"test": "mocha -r ts-node/register './test/**/*.test.ts'",
|
|
58
|
-
"test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
|
|
59
|
-
"test:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
|
|
60
|
-
"test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
|
|
61
|
-
"test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
|
|
62
|
-
"test:live": "TEST_LIVE=1 npm run test",
|
|
63
|
-
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
64
|
-
},
|
|
65
39
|
"dependencies": {
|
|
66
40
|
"@babel/runtime": "^7.12.5",
|
|
67
41
|
"bn.js": "^5.0.0",
|
|
@@ -100,7 +74,7 @@
|
|
|
100
74
|
"@types/chai-as-promised": "^7.1.3",
|
|
101
75
|
"@types/mocha": "^8.2.1",
|
|
102
76
|
"@types/mz": "^2.7.3",
|
|
103
|
-
"@types/node": "^
|
|
77
|
+
"@types/node": "^15.0.0",
|
|
104
78
|
"@types/node-fetch": "^2.5.8",
|
|
105
79
|
"@types/secp256k1": "^4.0.1",
|
|
106
80
|
"@types/sinon": "^10.0.0",
|
|
@@ -126,7 +100,7 @@
|
|
|
126
100
|
"nyc": "^15.1.0",
|
|
127
101
|
"prettier": "^2.0.0",
|
|
128
102
|
"rimraf": "3.0.2",
|
|
129
|
-
"rollup": "2.
|
|
103
|
+
"rollup": "2.46.0",
|
|
130
104
|
"rollup-plugin-dts": "^3.0.1",
|
|
131
105
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
132
106
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -138,5 +112,31 @@
|
|
|
138
112
|
"typedoc": "^0.20.31",
|
|
139
113
|
"typescript": "^4.1.5",
|
|
140
114
|
"watch": "^1.0.2"
|
|
115
|
+
},
|
|
116
|
+
"scripts": {
|
|
117
|
+
"build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run generate:dts; npm run generate:flow",
|
|
118
|
+
"build:browser-test": "rollup -c test/rollup.config.js",
|
|
119
|
+
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
120
|
+
"clean": "rimraf ./coverage ./lib",
|
|
121
|
+
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
|
|
122
|
+
"dev": "cross-env NODE_ENV=development rollup -c",
|
|
123
|
+
"doc": "set -ex; typedoc",
|
|
124
|
+
"doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/",
|
|
125
|
+
"generate:dts": "./scripts/typegen.sh",
|
|
126
|
+
"generate:flow": "flowgen lib/index.d.ts -o module.flow.js",
|
|
127
|
+
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
128
|
+
"lint:fix": "npm run pretty:fix && eslint . --fix",
|
|
129
|
+
"lint:watch": "watch 'npm run lint:fix' . --wait=1 --ignoreDirectoryPattern=/doc/",
|
|
130
|
+
"ok": "run-s lint test doc",
|
|
131
|
+
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
132
|
+
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
133
|
+
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
134
|
+
"test": "mocha -r ts-node/register './test/**/*.test.ts'",
|
|
135
|
+
"test:cover": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' nyc --reporter=lcov mocha -r ts-node/register './test/**/*.test.ts'",
|
|
136
|
+
"test:browser": "TEST_LIVE=1 npm run build:browser-test && mocha-headless-chrome -f http://localhost:8080/mocha.html --timeout 180000",
|
|
137
|
+
"test:browser-with-server": "start-server-and-test 'http-server -p 8080' 8080 test:browser",
|
|
138
|
+
"test:browser-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:browser-with-server",
|
|
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';
|
|
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/publickey.ts
CHANGED
|
@@ -39,6 +39,11 @@ export class PublicKey {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Default public key value. (All zeros)
|
|
44
|
+
*/
|
|
45
|
+
static default: PublicKey = new PublicKey('11111111111111111111111111111111');
|
|
46
|
+
|
|
42
47
|
/**
|
|
43
48
|
* Checks if two publicKeys are equal
|
|
44
49
|
*/
|
|
@@ -150,6 +155,13 @@ export class PublicKey {
|
|
|
150
155
|
}
|
|
151
156
|
throw new Error(`Unable to find a viable program address nonce`);
|
|
152
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Check that a pubkey is on the ed25519 curve.
|
|
161
|
+
*/
|
|
162
|
+
static isOnCurve(pubkey: Uint8Array): boolean {
|
|
163
|
+
return is_on_curve(pubkey) == 1;
|
|
164
|
+
}
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
// @ts-ignore
|
package/src/stake-program.ts
CHANGED
|
@@ -59,6 +59,11 @@ export class Lockup {
|
|
|
59
59
|
this.epoch = epoch;
|
|
60
60
|
this.custodian = custodian;
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Default, inactive Lockup value
|
|
65
|
+
*/
|
|
66
|
+
static default: Lockup = new Lockup(0, 0, PublicKey.default);
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
@@ -72,7 +77,7 @@ export type CreateStakeAccountParams = {
|
|
|
72
77
|
/** Authorities of the new stake account */
|
|
73
78
|
authorized: Authorized;
|
|
74
79
|
/** Lockup of the new stake account */
|
|
75
|
-
lockup
|
|
80
|
+
lockup?: Lockup;
|
|
76
81
|
/** Funding amount */
|
|
77
82
|
lamports: number;
|
|
78
83
|
};
|
|
@@ -86,7 +91,7 @@ export type CreateStakeAccountWithSeedParams = {
|
|
|
86
91
|
basePubkey: PublicKey;
|
|
87
92
|
seed: string;
|
|
88
93
|
authorized: Authorized;
|
|
89
|
-
lockup
|
|
94
|
+
lockup?: Lockup;
|
|
90
95
|
lamports: number;
|
|
91
96
|
};
|
|
92
97
|
|
|
@@ -96,7 +101,7 @@ export type CreateStakeAccountWithSeedParams = {
|
|
|
96
101
|
export type InitializeStakeParams = {
|
|
97
102
|
stakePubkey: PublicKey;
|
|
98
103
|
authorized: Authorized;
|
|
99
|
-
lockup
|
|
104
|
+
lockup?: Lockup;
|
|
100
105
|
};
|
|
101
106
|
|
|
102
107
|
/**
|
|
@@ -502,7 +507,8 @@ export class StakeProgram {
|
|
|
502
507
|
* Generate an Initialize instruction to add to a Stake Create transaction
|
|
503
508
|
*/
|
|
504
509
|
static initialize(params: InitializeStakeParams): TransactionInstruction {
|
|
505
|
-
const {stakePubkey, authorized, lockup} = params;
|
|
510
|
+
const {stakePubkey, authorized, lockup: maybeLockup} = params;
|
|
511
|
+
const lockup: Lockup = maybeLockup || Lockup.default;
|
|
506
512
|
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
507
513
|
const data = encodeData(type, {
|
|
508
514
|
authorized: {
|
package/src/transaction.ts
CHANGED
|
@@ -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
|
* 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/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
|
|