@solana/web3.js 1.56.2 → 1.56.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.cjs.js +63 -32
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +63 -32
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +63 -32
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +63 -32
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +63 -32
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +63 -32
- package/lib/index.native.js.map +1 -1
- package/package.json +22 -22
- package/src/message/legacy.ts +9 -12
- package/src/message/v0.ts +29 -12
- package/src/transaction/legacy.ts +2 -2
- package/src/transaction/versioned.ts +2 -1
- package/src/utils/guarded-array-utils.ts +34 -0
- 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.56.
|
|
3
|
+
"version": "1.56.3",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -36,26 +36,6 @@
|
|
|
36
36
|
"/lib",
|
|
37
37
|
"/src"
|
|
38
38
|
],
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "npm run clean; cross-env NODE_ENV=production rollup -c; npm run type:gen",
|
|
41
|
-
"build:fixtures": "set -ex; ./test/fixtures/noop-program/build.sh",
|
|
42
|
-
"clean": "rimraf ./coverage ./lib",
|
|
43
|
-
"codecov": "set -ex; npm run test:cover; cat ./coverage/lcov.info | codecov",
|
|
44
|
-
"dev": "cross-env NODE_ENV=development rollup -c",
|
|
45
|
-
"doc": "set -ex; typedoc --treatWarningsAsErrors",
|
|
46
|
-
"type:gen": "./scripts/typegen.sh",
|
|
47
|
-
"lint": "set -ex; npm run pretty; eslint . --ext .js,.ts",
|
|
48
|
-
"lint:fix": "npm run pretty:fix && eslint . --fix --ext .js,.ts",
|
|
49
|
-
"type:check": "tsc -p tsconfig.json --noEmit",
|
|
50
|
-
"ok": "run-s lint test doc type:check",
|
|
51
|
-
"pretty": "prettier --check '{,{src,test}/**/}*.{j,t}s'",
|
|
52
|
-
"pretty:fix": "prettier --write '{,{src,test}/**/}*.{j,t}s'",
|
|
53
|
-
"re": "semantic-release --repository-url git@github.com:solana-labs/solana-web3.js.git",
|
|
54
|
-
"test": "cross-env TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\", \"target\": \"es2019\" }' ts-mocha --require esm './test/**/*.test.ts'",
|
|
55
|
-
"test:cover": "nyc --reporter=lcov npm run test",
|
|
56
|
-
"test:live": "TEST_LIVE=1 npm run test",
|
|
57
|
-
"test:live-with-test-validator": "start-server-and-test 'solana-test-validator --reset --quiet' http://localhost:8899/health test:live"
|
|
58
|
-
},
|
|
59
39
|
"dependencies": {
|
|
60
40
|
"@babel/runtime": "^7.12.5",
|
|
61
41
|
"@noble/ed25519": "^1.7.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\", \"target\": \"es2019\" }' 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/legacy.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
MessageAddressTableLookup,
|
|
14
14
|
MessageCompiledInstruction,
|
|
15
15
|
} from './index';
|
|
16
|
+
import {guardedShift, guardedSplice} from '../utils/guarded-array-utils';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* An instruction to execute by a program
|
|
@@ -232,7 +233,7 @@ export class Message {
|
|
|
232
233
|
// Slice up wire data
|
|
233
234
|
let byteArray = [...buffer];
|
|
234
235
|
|
|
235
|
-
const numRequiredSignatures = byteArray
|
|
236
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
236
237
|
if (
|
|
237
238
|
numRequiredSignatures !==
|
|
238
239
|
(numRequiredSignatures & VERSION_PREFIX_MASK)
|
|
@@ -242,31 +243,27 @@ export class Message {
|
|
|
242
243
|
);
|
|
243
244
|
}
|
|
244
245
|
|
|
245
|
-
const numReadonlySignedAccounts = byteArray
|
|
246
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
246
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
247
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
247
248
|
|
|
248
249
|
const accountCount = shortvec.decodeLength(byteArray);
|
|
249
250
|
let accountKeys = [];
|
|
250
251
|
for (let i = 0; i < accountCount; i++) {
|
|
251
|
-
const account = byteArray
|
|
252
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
252
|
+
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
253
253
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
const recentBlockhash = byteArray
|
|
257
|
-
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
256
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
258
257
|
|
|
259
258
|
const instructionCount = shortvec.decodeLength(byteArray);
|
|
260
259
|
let instructions: CompiledInstruction[] = [];
|
|
261
260
|
for (let i = 0; i < instructionCount; i++) {
|
|
262
|
-
const programIdIndex = byteArray
|
|
261
|
+
const programIdIndex = guardedShift(byteArray);
|
|
263
262
|
const accountCount = shortvec.decodeLength(byteArray);
|
|
264
|
-
const accounts = byteArray
|
|
265
|
-
byteArray = byteArray.slice(accountCount);
|
|
263
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
266
264
|
const dataLength = shortvec.decodeLength(byteArray);
|
|
267
|
-
const dataSlice = byteArray
|
|
265
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
268
266
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
269
|
-
byteArray = byteArray.slice(dataLength);
|
|
270
267
|
instructions.push({
|
|
271
268
|
programIdIndex,
|
|
272
269
|
accounts,
|
package/src/message/v0.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {PublicKey, PUBLIC_KEY_LENGTH} from '../publickey';
|
|
|
12
12
|
import * as shortvec from '../utils/shortvec-encoding';
|
|
13
13
|
import assert from '../utils/assert';
|
|
14
14
|
import {PACKET_DATA_SIZE, VERSION_PREFIX_MASK} from '../transaction/constants';
|
|
15
|
+
import {guardedShift, guardedSplice} from '../utils/guarded-array-utils';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Message constructor arguments
|
|
@@ -254,7 +255,7 @@ export class MessageV0 {
|
|
|
254
255
|
static deserialize(serializedMessage: Uint8Array): MessageV0 {
|
|
255
256
|
let byteArray = [...serializedMessage];
|
|
256
257
|
|
|
257
|
-
const prefix = byteArray
|
|
258
|
+
const prefix = guardedShift(byteArray);
|
|
258
259
|
const maskedPrefix = prefix & VERSION_PREFIX_MASK;
|
|
259
260
|
assert(
|
|
260
261
|
prefix !== maskedPrefix,
|
|
@@ -268,29 +269,35 @@ export class MessageV0 {
|
|
|
268
269
|
);
|
|
269
270
|
|
|
270
271
|
const header: MessageHeader = {
|
|
271
|
-
numRequiredSignatures: byteArray
|
|
272
|
-
numReadonlySignedAccounts: byteArray
|
|
273
|
-
numReadonlyUnsignedAccounts: byteArray
|
|
272
|
+
numRequiredSignatures: guardedShift(byteArray),
|
|
273
|
+
numReadonlySignedAccounts: guardedShift(byteArray),
|
|
274
|
+
numReadonlyUnsignedAccounts: guardedShift(byteArray),
|
|
274
275
|
};
|
|
275
276
|
|
|
276
277
|
const staticAccountKeys = [];
|
|
277
278
|
const staticAccountKeysLength = shortvec.decodeLength(byteArray);
|
|
278
279
|
for (let i = 0; i < staticAccountKeysLength; i++) {
|
|
279
280
|
staticAccountKeys.push(
|
|
280
|
-
new PublicKey(byteArray
|
|
281
|
+
new PublicKey(guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH)),
|
|
281
282
|
);
|
|
282
283
|
}
|
|
283
284
|
|
|
284
|
-
const recentBlockhash = bs58.encode(
|
|
285
|
+
const recentBlockhash = bs58.encode(
|
|
286
|
+
guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH),
|
|
287
|
+
);
|
|
285
288
|
|
|
286
289
|
const instructionCount = shortvec.decodeLength(byteArray);
|
|
287
290
|
const compiledInstructions: MessageCompiledInstruction[] = [];
|
|
288
291
|
for (let i = 0; i < instructionCount; i++) {
|
|
289
|
-
const programIdIndex = byteArray
|
|
292
|
+
const programIdIndex = guardedShift(byteArray);
|
|
290
293
|
const accountKeyIndexesLength = shortvec.decodeLength(byteArray);
|
|
291
|
-
const accountKeyIndexes =
|
|
294
|
+
const accountKeyIndexes = guardedSplice(
|
|
295
|
+
byteArray,
|
|
296
|
+
0,
|
|
297
|
+
accountKeyIndexesLength,
|
|
298
|
+
);
|
|
292
299
|
const dataLength = shortvec.decodeLength(byteArray);
|
|
293
|
-
const data = new Uint8Array(byteArray
|
|
300
|
+
const data = new Uint8Array(guardedSplice(byteArray, 0, dataLength));
|
|
294
301
|
compiledInstructions.push({
|
|
295
302
|
programIdIndex,
|
|
296
303
|
accountKeyIndexes,
|
|
@@ -301,11 +308,21 @@ export class MessageV0 {
|
|
|
301
308
|
const addressTableLookupsCount = shortvec.decodeLength(byteArray);
|
|
302
309
|
const addressTableLookups: MessageAddressTableLookup[] = [];
|
|
303
310
|
for (let i = 0; i < addressTableLookupsCount; i++) {
|
|
304
|
-
const accountKey = new PublicKey(
|
|
311
|
+
const accountKey = new PublicKey(
|
|
312
|
+
guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH),
|
|
313
|
+
);
|
|
305
314
|
const writableIndexesLength = shortvec.decodeLength(byteArray);
|
|
306
|
-
const writableIndexes =
|
|
315
|
+
const writableIndexes = guardedSplice(
|
|
316
|
+
byteArray,
|
|
317
|
+
0,
|
|
318
|
+
writableIndexesLength,
|
|
319
|
+
);
|
|
307
320
|
const readonlyIndexesLength = shortvec.decodeLength(byteArray);
|
|
308
|
-
const readonlyIndexes =
|
|
321
|
+
const readonlyIndexes = guardedSplice(
|
|
322
|
+
byteArray,
|
|
323
|
+
0,
|
|
324
|
+
readonlyIndexesLength,
|
|
325
|
+
);
|
|
309
326
|
addressTableLookups.push({
|
|
310
327
|
accountKey,
|
|
311
328
|
writableIndexes,
|
|
@@ -12,6 +12,7 @@ import type {Signer} from '../keypair';
|
|
|
12
12
|
import type {Blockhash} from '../blockhash';
|
|
13
13
|
import type {CompiledInstruction} from '../message';
|
|
14
14
|
import {sign, verify} from '../utils/ed25519';
|
|
15
|
+
import {guardedSplice} from '../utils/guarded-array-utils';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Transaction signature as base-58 encoded string
|
|
@@ -803,8 +804,7 @@ export class Transaction {
|
|
|
803
804
|
const signatureCount = shortvec.decodeLength(byteArray);
|
|
804
805
|
let signatures = [];
|
|
805
806
|
for (let i = 0; i < signatureCount; i++) {
|
|
806
|
-
const signature = byteArray
|
|
807
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
807
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES);
|
|
808
808
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
809
809
|
}
|
|
810
810
|
|
|
@@ -7,6 +7,7 @@ import {SIGNATURE_LENGTH_IN_BYTES} from './constants';
|
|
|
7
7
|
import * as shortvec from '../utils/shortvec-encoding';
|
|
8
8
|
import * as Layout from '../layout';
|
|
9
9
|
import {sign} from '../utils/ed25519';
|
|
10
|
+
import {guardedSplice} from '../utils/guarded-array-utils';
|
|
10
11
|
|
|
11
12
|
export type TransactionVersion = 'legacy' | 0;
|
|
12
13
|
|
|
@@ -77,7 +78,7 @@ export class VersionedTransaction {
|
|
|
77
78
|
const signaturesLength = shortvec.decodeLength(byteArray);
|
|
78
79
|
for (let i = 0; i < signaturesLength; i++) {
|
|
79
80
|
signatures.push(
|
|
80
|
-
new Uint8Array(byteArray
|
|
81
|
+
new Uint8Array(guardedSplice(byteArray, 0, SIGNATURE_LENGTH_IN_BYTES)),
|
|
81
82
|
);
|
|
82
83
|
}
|
|
83
84
|
|
|
@@ -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
|
+
}
|
package/src/validator-info.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import * as Layout from './layout';
|
|
10
10
|
import * as shortvec from './utils/shortvec-encoding';
|
|
11
11
|
import {PublicKey, PUBLIC_KEY_LENGTH} from './publickey';
|
|
12
|
+
import {guardedShift, guardedSplice} from './utils/guarded-array-utils';
|
|
12
13
|
|
|
13
14
|
export const VALIDATOR_INFO_KEY = new PublicKey(
|
|
14
15
|
'Va1idator1nfo111111111111111111111111111111',
|
|
@@ -83,10 +84,10 @@ export class ValidatorInfo {
|
|
|
83
84
|
|
|
84
85
|
const configKeys: Array<ConfigKey> = [];
|
|
85
86
|
for (let i = 0; i < 2; i++) {
|
|
86
|
-
const publicKey = new PublicKey(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const publicKey = new PublicKey(
|
|
88
|
+
guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH),
|
|
89
|
+
);
|
|
90
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
90
91
|
configKeys.push({publicKey, isSigner});
|
|
91
92
|
}
|
|
92
93
|
|