@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/lib/index.browser.esm.js
CHANGED
|
@@ -60,10 +60,13 @@ class PublicKey {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Default public key value. (All zeros)
|
|
64
64
|
*/
|
|
65
65
|
|
|
66
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Checks if two publicKeys are equal
|
|
69
|
+
*/
|
|
67
70
|
equals(publicKey) {
|
|
68
71
|
return this._bn.eq(publicKey._bn);
|
|
69
72
|
}
|
|
@@ -168,9 +171,19 @@ class PublicKey {
|
|
|
168
171
|
|
|
169
172
|
throw new Error("Unable to find a viable program address nonce");
|
|
170
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Check that a pubkey is on the ed25519 curve.
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
static isOnCurve(pubkey) {
|
|
180
|
+
return is_on_curve(pubkey) == 1;
|
|
181
|
+
}
|
|
171
182
|
|
|
172
183
|
} // @ts-ignore
|
|
173
184
|
|
|
185
|
+
_defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
186
|
+
|
|
174
187
|
let naclLowLevel = nacl__default.lowlevel; // Check that a pubkey is on the curve.
|
|
175
188
|
// This function and its dependents were sourced from:
|
|
176
189
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
@@ -1255,6 +1268,36 @@ function encodeLength(bytes, len) {
|
|
|
1255
1268
|
}
|
|
1256
1269
|
}
|
|
1257
1270
|
|
|
1271
|
+
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
1272
|
+
/**
|
|
1273
|
+
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
1274
|
+
*/
|
|
1275
|
+
|
|
1276
|
+
function guardedShift(byteArray) {
|
|
1277
|
+
if (byteArray.length === 0) {
|
|
1278
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
return byteArray.shift();
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Delegates to `Array#splice`, but throws if the section being spliced out extends past the end of
|
|
1285
|
+
* the array.
|
|
1286
|
+
*/
|
|
1287
|
+
|
|
1288
|
+
function guardedSplice(byteArray, ...args) {
|
|
1289
|
+
var _args$;
|
|
1290
|
+
|
|
1291
|
+
const [start] = args;
|
|
1292
|
+
|
|
1293
|
+
if (args.length === 2 // Implies that `deleteCount` was supplied
|
|
1294
|
+
? start + ((_args$ = args[1]) !== null && _args$ !== void 0 ? _args$ : 0) > byteArray.length : start >= byteArray.length) {
|
|
1295
|
+
throw new Error(END_OF_BUFFER_ERROR_MESSAGE);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
return byteArray.splice(...args);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1258
1301
|
/**
|
|
1259
1302
|
* The message header, identifying signed and read-only account
|
|
1260
1303
|
*/
|
|
@@ -1339,32 +1382,28 @@ class Message {
|
|
|
1339
1382
|
static from(buffer) {
|
|
1340
1383
|
// Slice up wire data
|
|
1341
1384
|
let byteArray = [...buffer];
|
|
1342
|
-
const numRequiredSignatures = byteArray
|
|
1343
|
-
const numReadonlySignedAccounts = byteArray
|
|
1344
|
-
const numReadonlyUnsignedAccounts = byteArray
|
|
1385
|
+
const numRequiredSignatures = guardedShift(byteArray);
|
|
1386
|
+
const numReadonlySignedAccounts = guardedShift(byteArray);
|
|
1387
|
+
const numReadonlyUnsignedAccounts = guardedShift(byteArray);
|
|
1345
1388
|
const accountCount = decodeLength(byteArray);
|
|
1346
1389
|
let accountKeys = [];
|
|
1347
1390
|
|
|
1348
1391
|
for (let i = 0; i < accountCount; i++) {
|
|
1349
|
-
const account = byteArray
|
|
1350
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1392
|
+
const account = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1351
1393
|
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
1352
1394
|
}
|
|
1353
1395
|
|
|
1354
|
-
const recentBlockhash = byteArray
|
|
1355
|
-
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
1396
|
+
const recentBlockhash = guardedSplice(byteArray, 0, PUBKEY_LENGTH);
|
|
1356
1397
|
const instructionCount = decodeLength(byteArray);
|
|
1357
1398
|
let instructions = [];
|
|
1358
1399
|
|
|
1359
1400
|
for (let i = 0; i < instructionCount; i++) {
|
|
1360
|
-
const programIdIndex = byteArray
|
|
1401
|
+
const programIdIndex = guardedShift(byteArray);
|
|
1361
1402
|
const accountCount = decodeLength(byteArray);
|
|
1362
|
-
const accounts = byteArray
|
|
1363
|
-
byteArray = byteArray.slice(accountCount);
|
|
1403
|
+
const accounts = guardedSplice(byteArray, 0, accountCount);
|
|
1364
1404
|
const dataLength = decodeLength(byteArray);
|
|
1365
|
-
const dataSlice = byteArray
|
|
1405
|
+
const dataSlice = guardedSplice(byteArray, 0, dataLength);
|
|
1366
1406
|
const data = bs58.encode(Buffer.from(dataSlice));
|
|
1367
|
-
byteArray = byteArray.slice(dataLength);
|
|
1368
1407
|
instructions.push({
|
|
1369
1408
|
programIdIndex,
|
|
1370
1409
|
accounts,
|
|
@@ -1984,8 +2023,7 @@ class Transaction {
|
|
|
1984
2023
|
let signatures = [];
|
|
1985
2024
|
|
|
1986
2025
|
for (let i = 0; i < signatureCount; i++) {
|
|
1987
|
-
const signature = byteArray
|
|
1988
|
-
byteArray = byteArray.slice(SIGNATURE_LENGTH);
|
|
2026
|
+
const signature = guardedSplice(byteArray, 0, SIGNATURE_LENGTH);
|
|
1989
2027
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
1990
2028
|
}
|
|
1991
2029
|
|
|
@@ -7038,12 +7076,18 @@ class Lockup {
|
|
|
7038
7076
|
this.epoch = epoch;
|
|
7039
7077
|
this.custodian = custodian;
|
|
7040
7078
|
}
|
|
7079
|
+
/**
|
|
7080
|
+
* Default, inactive Lockup value
|
|
7081
|
+
*/
|
|
7082
|
+
|
|
7041
7083
|
|
|
7042
7084
|
}
|
|
7043
7085
|
/**
|
|
7044
7086
|
* Create stake account transaction params
|
|
7045
7087
|
*/
|
|
7046
7088
|
|
|
7089
|
+
_defineProperty(Lockup, "default", new Lockup(0, 0, PublicKey.default));
|
|
7090
|
+
|
|
7047
7091
|
/**
|
|
7048
7092
|
* Stake Instruction class
|
|
7049
7093
|
*/
|
|
@@ -7319,8 +7363,9 @@ class StakeProgram {
|
|
|
7319
7363
|
const {
|
|
7320
7364
|
stakePubkey,
|
|
7321
7365
|
authorized,
|
|
7322
|
-
lockup
|
|
7366
|
+
lockup: maybeLockup
|
|
7323
7367
|
} = params;
|
|
7368
|
+
const lockup = maybeLockup || Lockup.default;
|
|
7324
7369
|
const type = STAKE_INSTRUCTION_LAYOUTS.Initialize;
|
|
7325
7370
|
const data = encodeData(type, {
|
|
7326
7371
|
authorized: {
|
|
@@ -7876,10 +7921,8 @@ class ValidatorInfo {
|
|
|
7876
7921
|
const configKeys = [];
|
|
7877
7922
|
|
|
7878
7923
|
for (let i = 0; i < 2; i++) {
|
|
7879
|
-
const publicKey = new PublicKey(byteArray
|
|
7880
|
-
|
|
7881
|
-
const isSigner = byteArray.slice(0, 1)[0] === 1;
|
|
7882
|
-
byteArray = byteArray.slice(1);
|
|
7924
|
+
const publicKey = new PublicKey(guardedSplice(byteArray, 0, PUBKEY_LENGTH));
|
|
7925
|
+
const isSigner = guardedShift(byteArray) === 1;
|
|
7883
7926
|
configKeys.push({
|
|
7884
7927
|
publicKey,
|
|
7885
7928
|
isSigner
|