@solana/web3.js 1.41.3 → 1.41.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/lib/index.browser.cjs.js +90 -4
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +137 -50
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +107 -7
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +30 -4
- package/lib/index.esm.js +155 -54
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +12204 -12118
- 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/package.json +2 -1
- package/src/system-program.ts +39 -10
package/lib/index.d.ts
CHANGED
|
@@ -2632,7 +2632,7 @@ declare module '@solana/web3.js' {
|
|
|
2632
2632
|
/** Account that will receive transferred lamports */
|
|
2633
2633
|
toPubkey: PublicKey;
|
|
2634
2634
|
/** Amount of lamports to transfer */
|
|
2635
|
-
lamports: number;
|
|
2635
|
+
lamports: number | bigint;
|
|
2636
2636
|
};
|
|
2637
2637
|
/**
|
|
2638
2638
|
* Assign system transaction params
|
|
@@ -2782,7 +2782,31 @@ declare module '@solana/web3.js' {
|
|
|
2782
2782
|
/** Account that will receive transferred lamports */
|
|
2783
2783
|
toPubkey: PublicKey;
|
|
2784
2784
|
/** Amount of lamports to transfer */
|
|
2785
|
-
lamports: number;
|
|
2785
|
+
lamports: number | bigint;
|
|
2786
|
+
/** Seed to use to derive the funding account address */
|
|
2787
|
+
seed: string;
|
|
2788
|
+
/** Program id to use to derive the funding account address */
|
|
2789
|
+
programId: PublicKey;
|
|
2790
|
+
};
|
|
2791
|
+
/** Decoded transfer system transaction instruction */
|
|
2792
|
+
export type DecodedTransferInstruction = {
|
|
2793
|
+
/** Account that will transfer lamports */
|
|
2794
|
+
fromPubkey: PublicKey;
|
|
2795
|
+
/** Account that will receive transferred lamports */
|
|
2796
|
+
toPubkey: PublicKey;
|
|
2797
|
+
/** Amount of lamports to transfer */
|
|
2798
|
+
lamports: bigint;
|
|
2799
|
+
};
|
|
2800
|
+
/** Decoded transferWithSeed system transaction instruction */
|
|
2801
|
+
export type DecodedTransferWithSeedInstruction = {
|
|
2802
|
+
/** Account that will transfer lamports */
|
|
2803
|
+
fromPubkey: PublicKey;
|
|
2804
|
+
/** Base public key to use to derive the funding account address */
|
|
2805
|
+
basePubkey: PublicKey;
|
|
2806
|
+
/** Account that will receive transferred lamports */
|
|
2807
|
+
toPubkey: PublicKey;
|
|
2808
|
+
/** Amount of lamports to transfer */
|
|
2809
|
+
lamports: bigint;
|
|
2786
2810
|
/** Seed to use to derive the funding account address */
|
|
2787
2811
|
seed: string;
|
|
2788
2812
|
/** Program id to use to derive the funding account address */
|
|
@@ -2807,13 +2831,15 @@ declare module '@solana/web3.js' {
|
|
|
2807
2831
|
/**
|
|
2808
2832
|
* Decode a transfer system instruction and retrieve the instruction params.
|
|
2809
2833
|
*/
|
|
2810
|
-
static decodeTransfer(
|
|
2834
|
+
static decodeTransfer(
|
|
2835
|
+
instruction: TransactionInstruction,
|
|
2836
|
+
): DecodedTransferInstruction;
|
|
2811
2837
|
/**
|
|
2812
2838
|
* Decode a transfer with seed system instruction and retrieve the instruction params.
|
|
2813
2839
|
*/
|
|
2814
2840
|
static decodeTransferWithSeed(
|
|
2815
2841
|
instruction: TransactionInstruction,
|
|
2816
|
-
):
|
|
2842
|
+
): DecodedTransferWithSeedInstruction;
|
|
2817
2843
|
/**
|
|
2818
2844
|
* Decode an allocate system instruction and retrieve the instruction params.
|
|
2819
2845
|
*/
|
package/lib/index.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import nacl from 'tweetnacl';
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
2
|
+
import { Buffer as Buffer$1 } from 'buffer';
|
|
3
3
|
import BN from 'bn.js';
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import { serialize, deserialize, deserializeUnchecked } from 'borsh';
|
|
6
6
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
7
|
-
import
|
|
7
|
+
import { blob } from '@solana/buffer-layout';
|
|
8
|
+
import fetch from 'cross-fetch';
|
|
8
9
|
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
|
|
9
10
|
import { Client } from 'rpc-websockets';
|
|
10
11
|
import RpcClient from 'jayson/lib/client/browser';
|
|
@@ -14,12 +15,12 @@ import secp256k1 from 'secp256k1';
|
|
|
14
15
|
import sha3 from 'js-sha3';
|
|
15
16
|
|
|
16
17
|
const toBuffer = arr => {
|
|
17
|
-
if (Buffer.isBuffer(arr)) {
|
|
18
|
+
if (Buffer$1.isBuffer(arr)) {
|
|
18
19
|
return arr;
|
|
19
20
|
} else if (arr instanceof Uint8Array) {
|
|
20
|
-
return Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
21
|
+
return Buffer$1.from(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
21
22
|
} else {
|
|
22
|
-
return Buffer.from(arr);
|
|
23
|
+
return Buffer$1.from(arr);
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
|
|
@@ -1746,7 +1747,7 @@ class Struct {
|
|
|
1746
1747
|
}
|
|
1747
1748
|
|
|
1748
1749
|
encode() {
|
|
1749
|
-
return Buffer.from(serialize(SOLANA_SCHEMA, this));
|
|
1750
|
+
return Buffer$1.from(serialize(SOLANA_SCHEMA, this));
|
|
1750
1751
|
}
|
|
1751
1752
|
|
|
1752
1753
|
static decode(data) {
|
|
@@ -1863,13 +1864,13 @@ class PublicKey extends Struct {
|
|
|
1863
1864
|
|
|
1864
1865
|
|
|
1865
1866
|
toBuffer() {
|
|
1866
|
-
const b = this._bn.toArrayLike(Buffer);
|
|
1867
|
+
const b = this._bn.toArrayLike(Buffer$1);
|
|
1867
1868
|
|
|
1868
1869
|
if (b.length === 32) {
|
|
1869
1870
|
return b;
|
|
1870
1871
|
}
|
|
1871
1872
|
|
|
1872
|
-
const zeroPad = Buffer.alloc(32);
|
|
1873
|
+
const zeroPad = Buffer$1.alloc(32);
|
|
1873
1874
|
b.copy(zeroPad, 32 - b.length);
|
|
1874
1875
|
return zeroPad;
|
|
1875
1876
|
}
|
|
@@ -1891,9 +1892,9 @@ class PublicKey extends Struct {
|
|
|
1891
1892
|
|
|
1892
1893
|
|
|
1893
1894
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
1894
|
-
const buffer = Buffer.concat([fromPublicKey.toBuffer(), Buffer.from(seed), programId.toBuffer()]);
|
|
1895
|
+
const buffer = Buffer$1.concat([fromPublicKey.toBuffer(), Buffer$1.from(seed), programId.toBuffer()]);
|
|
1895
1896
|
const hash = sha256(new Uint8Array(buffer)).slice(2);
|
|
1896
|
-
return new PublicKey(Buffer.from(hash, 'hex'));
|
|
1897
|
+
return new PublicKey(Buffer$1.from(hash, 'hex'));
|
|
1897
1898
|
}
|
|
1898
1899
|
/**
|
|
1899
1900
|
* Derive a program address from seeds and a program ID.
|
|
@@ -1903,15 +1904,15 @@ class PublicKey extends Struct {
|
|
|
1903
1904
|
|
|
1904
1905
|
|
|
1905
1906
|
static createProgramAddressSync(seeds, programId) {
|
|
1906
|
-
let buffer = Buffer.alloc(0);
|
|
1907
|
+
let buffer = Buffer$1.alloc(0);
|
|
1907
1908
|
seeds.forEach(function (seed) {
|
|
1908
1909
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
1909
1910
|
throw new TypeError(`Max seed length exceeded`);
|
|
1910
1911
|
}
|
|
1911
1912
|
|
|
1912
|
-
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
1913
|
+
buffer = Buffer$1.concat([buffer, toBuffer(seed)]);
|
|
1913
1914
|
});
|
|
1914
|
-
buffer = Buffer.concat([buffer, programId.toBuffer(), Buffer.from('ProgramDerivedAddress')]);
|
|
1915
|
+
buffer = Buffer$1.concat([buffer, programId.toBuffer(), Buffer$1.from('ProgramDerivedAddress')]);
|
|
1915
1916
|
let hash = sha256(new Uint8Array(buffer)).slice(2);
|
|
1916
1917
|
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
1917
1918
|
|
|
@@ -1947,7 +1948,7 @@ class PublicKey extends Struct {
|
|
|
1947
1948
|
|
|
1948
1949
|
while (nonce != 0) {
|
|
1949
1950
|
try {
|
|
1950
|
-
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
|
|
1951
|
+
const seedsWithNonce = seeds.concat(Buffer$1.from([nonce]));
|
|
1951
1952
|
address = this.createProgramAddressSync(seedsWithNonce, programId);
|
|
1952
1953
|
} catch (err) {
|
|
1953
1954
|
if (err instanceof TypeError) {
|
|
@@ -2123,13 +2124,13 @@ const rustString = (property = 'string') => {
|
|
|
2123
2124
|
|
|
2124
2125
|
rslShim.encode = (str, b, offset) => {
|
|
2125
2126
|
const data = {
|
|
2126
|
-
chars: Buffer.from(str, 'utf8')
|
|
2127
|
+
chars: Buffer$1.from(str, 'utf8')
|
|
2127
2128
|
};
|
|
2128
2129
|
return _encode(data, b, offset);
|
|
2129
2130
|
};
|
|
2130
2131
|
|
|
2131
2132
|
rslShim.alloc = str => {
|
|
2132
|
-
return BufferLayout.u32().span + BufferLayout.u32().span + Buffer.from(str, 'utf8').length;
|
|
2133
|
+
return BufferLayout.u32().span + BufferLayout.u32().span + Buffer$1.from(str, 'utf8').length;
|
|
2133
2134
|
};
|
|
2134
2135
|
|
|
2135
2136
|
return rslShim;
|
|
@@ -2259,16 +2260,16 @@ class Message {
|
|
|
2259
2260
|
encodeLength(dataCount, data.length);
|
|
2260
2261
|
return {
|
|
2261
2262
|
programIdIndex,
|
|
2262
|
-
keyIndicesCount: Buffer.from(keyIndicesCount),
|
|
2263
|
+
keyIndicesCount: Buffer$1.from(keyIndicesCount),
|
|
2263
2264
|
keyIndices: accounts,
|
|
2264
|
-
dataLength: Buffer.from(dataCount),
|
|
2265
|
+
dataLength: Buffer$1.from(dataCount),
|
|
2265
2266
|
data
|
|
2266
2267
|
};
|
|
2267
2268
|
});
|
|
2268
2269
|
let instructionCount = [];
|
|
2269
2270
|
encodeLength(instructionCount, instructions.length);
|
|
2270
|
-
let instructionBuffer = Buffer.alloc(PACKET_DATA_SIZE);
|
|
2271
|
-
Buffer.from(instructionCount).copy(instructionBuffer);
|
|
2271
|
+
let instructionBuffer = Buffer$1.alloc(PACKET_DATA_SIZE);
|
|
2272
|
+
Buffer$1.from(instructionCount).copy(instructionBuffer);
|
|
2272
2273
|
let instructionBufferLength = instructionCount.length;
|
|
2273
2274
|
instructions.forEach(instruction => {
|
|
2274
2275
|
const instructionLayout = BufferLayout.struct([BufferLayout.u8('programIdIndex'), BufferLayout.blob(instruction.keyIndicesCount.length, 'keyIndicesCount'), BufferLayout.seq(BufferLayout.u8('keyIndex'), instruction.keyIndices.length, 'keyIndices'), BufferLayout.blob(instruction.dataLength.length, 'dataLength'), BufferLayout.seq(BufferLayout.u8('userdatum'), instruction.data.length, 'data')]);
|
|
@@ -2278,14 +2279,14 @@ class Message {
|
|
|
2278
2279
|
instructionBuffer = instructionBuffer.slice(0, instructionBufferLength);
|
|
2279
2280
|
const signDataLayout = BufferLayout.struct([BufferLayout.blob(1, 'numRequiredSignatures'), BufferLayout.blob(1, 'numReadonlySignedAccounts'), BufferLayout.blob(1, 'numReadonlyUnsignedAccounts'), BufferLayout.blob(keyCount.length, 'keyCount'), BufferLayout.seq(publicKey('key'), numKeys, 'keys'), publicKey('recentBlockhash')]);
|
|
2280
2281
|
const transaction = {
|
|
2281
|
-
numRequiredSignatures: Buffer.from([this.header.numRequiredSignatures]),
|
|
2282
|
-
numReadonlySignedAccounts: Buffer.from([this.header.numReadonlySignedAccounts]),
|
|
2283
|
-
numReadonlyUnsignedAccounts: Buffer.from([this.header.numReadonlyUnsignedAccounts]),
|
|
2284
|
-
keyCount: Buffer.from(keyCount),
|
|
2282
|
+
numRequiredSignatures: Buffer$1.from([this.header.numRequiredSignatures]),
|
|
2283
|
+
numReadonlySignedAccounts: Buffer$1.from([this.header.numReadonlySignedAccounts]),
|
|
2284
|
+
numReadonlyUnsignedAccounts: Buffer$1.from([this.header.numReadonlyUnsignedAccounts]),
|
|
2285
|
+
keyCount: Buffer$1.from(keyCount),
|
|
2285
2286
|
keys: this.accountKeys.map(key => toBuffer(key.toBytes())),
|
|
2286
2287
|
recentBlockhash: bs58.decode(this.recentBlockhash)
|
|
2287
2288
|
};
|
|
2288
|
-
let signData = Buffer.alloc(2048);
|
|
2289
|
+
let signData = Buffer$1.alloc(2048);
|
|
2289
2290
|
const length = signDataLayout.encode(transaction, signData);
|
|
2290
2291
|
instructionBuffer.copy(signData, length);
|
|
2291
2292
|
return signData.slice(0, length + instructionBuffer.length);
|
|
@@ -2307,7 +2308,7 @@ class Message {
|
|
|
2307
2308
|
for (let i = 0; i < accountCount; i++) {
|
|
2308
2309
|
const account = byteArray.slice(0, PUBKEY_LENGTH);
|
|
2309
2310
|
byteArray = byteArray.slice(PUBKEY_LENGTH);
|
|
2310
|
-
accountKeys.push(bs58.encode(Buffer.from(account)));
|
|
2311
|
+
accountKeys.push(bs58.encode(Buffer$1.from(account)));
|
|
2311
2312
|
}
|
|
2312
2313
|
|
|
2313
2314
|
const recentBlockhash = byteArray.slice(0, PUBKEY_LENGTH);
|
|
@@ -2322,7 +2323,7 @@ class Message {
|
|
|
2322
2323
|
byteArray = byteArray.slice(accountCount);
|
|
2323
2324
|
const dataLength = decodeLength(byteArray);
|
|
2324
2325
|
const dataSlice = byteArray.slice(0, dataLength);
|
|
2325
|
-
const data = bs58.encode(Buffer.from(dataSlice));
|
|
2326
|
+
const data = bs58.encode(Buffer$1.from(dataSlice));
|
|
2326
2327
|
byteArray = byteArray.slice(dataLength);
|
|
2327
2328
|
instructions.push({
|
|
2328
2329
|
programIdIndex,
|
|
@@ -2337,7 +2338,7 @@ class Message {
|
|
|
2337
2338
|
numReadonlySignedAccounts,
|
|
2338
2339
|
numReadonlyUnsignedAccounts
|
|
2339
2340
|
},
|
|
2340
|
-
recentBlockhash: bs58.encode(Buffer.from(recentBlockhash)),
|
|
2341
|
+
recentBlockhash: bs58.encode(Buffer$1.from(recentBlockhash)),
|
|
2341
2342
|
accountKeys,
|
|
2342
2343
|
instructions
|
|
2343
2344
|
};
|
|
@@ -2355,7 +2356,7 @@ function assert (condition, message) {
|
|
|
2355
2356
|
/**
|
|
2356
2357
|
* Default (empty) signature
|
|
2357
2358
|
*/
|
|
2358
|
-
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
2359
|
+
const DEFAULT_SIGNATURE = Buffer$1.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
2359
2360
|
/**
|
|
2360
2361
|
* Account metadata used to define instructions
|
|
2361
2362
|
*/
|
|
@@ -2379,7 +2380,7 @@ class TransactionInstruction {
|
|
|
2379
2380
|
constructor(opts) {
|
|
2380
2381
|
this.keys = void 0;
|
|
2381
2382
|
this.programId = void 0;
|
|
2382
|
-
this.data = Buffer.alloc(0);
|
|
2383
|
+
this.data = Buffer$1.alloc(0);
|
|
2383
2384
|
this.programId = opts.programId;
|
|
2384
2385
|
this.keys = opts.keys;
|
|
2385
2386
|
|
|
@@ -2862,7 +2863,7 @@ class Transaction {
|
|
|
2862
2863
|
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
|
2863
2864
|
}
|
|
2864
2865
|
|
|
2865
|
-
this.signatures[index].signature = Buffer.from(signature);
|
|
2866
|
+
this.signatures[index].signature = Buffer$1.from(signature);
|
|
2866
2867
|
}
|
|
2867
2868
|
/**
|
|
2868
2869
|
* Verify signatures of a complete, signed Transaction
|
|
@@ -2928,15 +2929,15 @@ class Transaction {
|
|
|
2928
2929
|
const signatureCount = [];
|
|
2929
2930
|
encodeLength(signatureCount, signatures.length);
|
|
2930
2931
|
const transactionLength = signatureCount.length + signatures.length * 64 + signData.length;
|
|
2931
|
-
const wireTransaction = Buffer.alloc(transactionLength);
|
|
2932
|
+
const wireTransaction = Buffer$1.alloc(transactionLength);
|
|
2932
2933
|
assert(signatures.length < 256);
|
|
2933
|
-
Buffer.from(signatureCount).copy(wireTransaction, 0);
|
|
2934
|
+
Buffer$1.from(signatureCount).copy(wireTransaction, 0);
|
|
2934
2935
|
signatures.forEach(({
|
|
2935
2936
|
signature
|
|
2936
2937
|
}, index) => {
|
|
2937
2938
|
if (signature !== null) {
|
|
2938
2939
|
assert(signature.length === 64, `signature has invalid length`);
|
|
2939
|
-
Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2940
|
+
Buffer$1.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2940
2941
|
}
|
|
2941
2942
|
});
|
|
2942
2943
|
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
|
@@ -2987,7 +2988,7 @@ class Transaction {
|
|
|
2987
2988
|
for (let i = 0; i < signatureCount; i++) {
|
|
2988
2989
|
const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
|
|
2989
2990
|
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
2990
|
-
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2991
|
+
signatures.push(bs58.encode(Buffer$1.from(signature)));
|
|
2991
2992
|
}
|
|
2992
2993
|
|
|
2993
2994
|
return Transaction.populate(Message.from(byteArray), signatures);
|
|
@@ -3076,13 +3077,113 @@ function sleep(ms) {
|
|
|
3076
3077
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
3077
3078
|
}
|
|
3078
3079
|
|
|
3080
|
+
const encodeDecode = (layout) => {
|
|
3081
|
+
const decode = layout.decode.bind(layout);
|
|
3082
|
+
const encode = layout.encode.bind(layout);
|
|
3083
|
+
return { decode, encode };
|
|
3084
|
+
};
|
|
3085
|
+
|
|
3086
|
+
var node = {};
|
|
3087
|
+
|
|
3088
|
+
Object.defineProperty(node, "__esModule", { value: true });
|
|
3089
|
+
let converter;
|
|
3090
|
+
{
|
|
3091
|
+
try {
|
|
3092
|
+
converter = require('bindings')('bigint_buffer');
|
|
3093
|
+
}
|
|
3094
|
+
catch (e) {
|
|
3095
|
+
console.warn('bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)');
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
/**
|
|
3099
|
+
* Convert a little-endian buffer into a BigInt.
|
|
3100
|
+
* @param buf The little-endian buffer to convert
|
|
3101
|
+
* @returns A BigInt with the little-endian representation of buf.
|
|
3102
|
+
*/
|
|
3103
|
+
function toBigIntLE(buf) {
|
|
3104
|
+
if (converter === undefined) {
|
|
3105
|
+
const reversed = Buffer.from(buf);
|
|
3106
|
+
reversed.reverse();
|
|
3107
|
+
const hex = reversed.toString('hex');
|
|
3108
|
+
if (hex.length === 0) {
|
|
3109
|
+
return BigInt(0);
|
|
3110
|
+
}
|
|
3111
|
+
return BigInt(`0x${hex}`);
|
|
3112
|
+
}
|
|
3113
|
+
return converter.toBigInt(buf, false);
|
|
3114
|
+
}
|
|
3115
|
+
var toBigIntLE_1 = node.toBigIntLE = toBigIntLE;
|
|
3116
|
+
/**
|
|
3117
|
+
* Convert a big-endian buffer into a BigInt
|
|
3118
|
+
* @param buf The big-endian buffer to convert.
|
|
3119
|
+
* @returns A BigInt with the big-endian representation of buf.
|
|
3120
|
+
*/
|
|
3121
|
+
function toBigIntBE(buf) {
|
|
3122
|
+
if (converter === undefined) {
|
|
3123
|
+
const hex = buf.toString('hex');
|
|
3124
|
+
if (hex.length === 0) {
|
|
3125
|
+
return BigInt(0);
|
|
3126
|
+
}
|
|
3127
|
+
return BigInt(`0x${hex}`);
|
|
3128
|
+
}
|
|
3129
|
+
return converter.toBigInt(buf, true);
|
|
3130
|
+
}
|
|
3131
|
+
node.toBigIntBE = toBigIntBE;
|
|
3132
|
+
/**
|
|
3133
|
+
* Convert a BigInt to a little-endian buffer.
|
|
3134
|
+
* @param num The BigInt to convert.
|
|
3135
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
3136
|
+
* @returns A little-endian buffer representation of num.
|
|
3137
|
+
*/
|
|
3138
|
+
function toBufferLE(num, width) {
|
|
3139
|
+
if (converter === undefined) {
|
|
3140
|
+
const hex = num.toString(16);
|
|
3141
|
+
const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
3142
|
+
buffer.reverse();
|
|
3143
|
+
return buffer;
|
|
3144
|
+
}
|
|
3145
|
+
// Allocation is done here, since it is slower using napi in C
|
|
3146
|
+
return converter.fromBigInt(num, Buffer.allocUnsafe(width), false);
|
|
3147
|
+
}
|
|
3148
|
+
var toBufferLE_1 = node.toBufferLE = toBufferLE;
|
|
3149
|
+
/**
|
|
3150
|
+
* Convert a BigInt to a big-endian buffer.
|
|
3151
|
+
* @param num The BigInt to convert.
|
|
3152
|
+
* @param width The number of bytes that the resulting buffer should be.
|
|
3153
|
+
* @returns A big-endian buffer representation of num.
|
|
3154
|
+
*/
|
|
3155
|
+
function toBufferBE(num, width) {
|
|
3156
|
+
if (converter === undefined) {
|
|
3157
|
+
const hex = num.toString(16);
|
|
3158
|
+
return Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
3159
|
+
}
|
|
3160
|
+
return converter.fromBigInt(num, Buffer.allocUnsafe(width), true);
|
|
3161
|
+
}
|
|
3162
|
+
node.toBufferBE = toBufferBE;
|
|
3163
|
+
|
|
3164
|
+
const bigInt = (length) => (property) => {
|
|
3165
|
+
const layout = blob(length, property);
|
|
3166
|
+
const { encode, decode } = encodeDecode(layout);
|
|
3167
|
+
const bigIntLayout = layout;
|
|
3168
|
+
bigIntLayout.decode = (buffer, offset) => {
|
|
3169
|
+
const src = decode(buffer, offset);
|
|
3170
|
+
return toBigIntLE_1(Buffer.from(src));
|
|
3171
|
+
};
|
|
3172
|
+
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
3173
|
+
const src = toBufferLE_1(bigInt, length);
|
|
3174
|
+
return encode(src, buffer, offset);
|
|
3175
|
+
};
|
|
3176
|
+
return bigIntLayout;
|
|
3177
|
+
};
|
|
3178
|
+
const u64 = bigInt(8);
|
|
3179
|
+
|
|
3079
3180
|
/**
|
|
3080
3181
|
* Populate a buffer of instruction data using an InstructionType
|
|
3081
3182
|
* @internal
|
|
3082
3183
|
*/
|
|
3083
3184
|
function encodeData(type, fields) {
|
|
3084
3185
|
const allocLength = type.layout.span >= 0 ? type.layout.span : getAlloc(type, fields);
|
|
3085
|
-
const data = Buffer.alloc(allocLength);
|
|
3186
|
+
const data = Buffer$1.alloc(allocLength);
|
|
3086
3187
|
const layoutFields = Object.assign({
|
|
3087
3188
|
instruction: type.index
|
|
3088
3189
|
}, fields);
|
|
@@ -3465,7 +3566,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
3465
3566
|
},
|
|
3466
3567
|
Transfer: {
|
|
3467
3568
|
index: 2,
|
|
3468
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'),
|
|
3569
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('lamports')])
|
|
3469
3570
|
},
|
|
3470
3571
|
CreateWithSeed: {
|
|
3471
3572
|
index: 3,
|
|
@@ -3501,7 +3602,7 @@ const SYSTEM_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
3501
3602
|
},
|
|
3502
3603
|
TransferWithSeed: {
|
|
3503
3604
|
index: 11,
|
|
3504
|
-
layout: BufferLayout.struct([BufferLayout.u32('instruction'),
|
|
3605
|
+
layout: BufferLayout.struct([BufferLayout.u32('instruction'), u64('lamports'), rustString('seed'), publicKey('programId')])
|
|
3505
3606
|
}
|
|
3506
3607
|
});
|
|
3507
3608
|
/**
|
|
@@ -3554,7 +3655,7 @@ class SystemProgram {
|
|
|
3554
3655
|
if ('basePubkey' in params) {
|
|
3555
3656
|
const type = SYSTEM_INSTRUCTION_LAYOUTS.TransferWithSeed;
|
|
3556
3657
|
data = encodeData(type, {
|
|
3557
|
-
lamports: params.lamports,
|
|
3658
|
+
lamports: BigInt(params.lamports),
|
|
3558
3659
|
seed: params.seed,
|
|
3559
3660
|
programId: toBuffer(params.programId.toBuffer())
|
|
3560
3661
|
});
|
|
@@ -3574,7 +3675,7 @@ class SystemProgram {
|
|
|
3574
3675
|
} else {
|
|
3575
3676
|
const type = SYSTEM_INSTRUCTION_LAYOUTS.Transfer;
|
|
3576
3677
|
data = encodeData(type, {
|
|
3577
|
-
lamports: params.lamports
|
|
3678
|
+
lamports: BigInt(params.lamports)
|
|
3578
3679
|
});
|
|
3579
3680
|
keys = [{
|
|
3580
3681
|
pubkey: params.fromPubkey,
|
|
@@ -3982,7 +4083,7 @@ class Loader {
|
|
|
3982
4083
|
|
|
3983
4084
|
while (array.length > 0) {
|
|
3984
4085
|
const bytes = array.slice(0, chunkSize);
|
|
3985
|
-
const data = Buffer.alloc(chunkSize + 16);
|
|
4086
|
+
const data = Buffer$1.alloc(chunkSize + 16);
|
|
3986
4087
|
dataLayout.encode({
|
|
3987
4088
|
instruction: 0,
|
|
3988
4089
|
// Load instruction
|
|
@@ -4017,7 +4118,7 @@ class Loader {
|
|
|
4017
4118
|
|
|
4018
4119
|
{
|
|
4019
4120
|
const dataLayout = BufferLayout.struct([BufferLayout.u32('instruction')]);
|
|
4020
|
-
const data = Buffer.alloc(dataLayout.span);
|
|
4121
|
+
const data = Buffer$1.alloc(dataLayout.span);
|
|
4021
4122
|
dataLayout.encode({
|
|
4022
4123
|
instruction: 1 // Finalize instruction
|
|
4023
4124
|
|
|
@@ -4493,7 +4594,7 @@ function makeWebsocketUrl(endpoint) {
|
|
|
4493
4594
|
|
|
4494
4595
|
const PublicKeyFromString = coerce(instance(PublicKey), string(), value => new PublicKey(value));
|
|
4495
4596
|
const RawAccountDataResult = tuple([string(), literal('base64')]);
|
|
4496
|
-
const BufferFromRawAccountData = coerce(instance(Buffer), RawAccountDataResult, value => Buffer.from(value[0], 'base64'));
|
|
4597
|
+
const BufferFromRawAccountData = coerce(instance(Buffer$1), RawAccountDataResult, value => Buffer$1.from(value[0], 'base64'));
|
|
4497
4598
|
/**
|
|
4498
4599
|
* Attempt to use a recent blockhash for up to 30 seconds
|
|
4499
4600
|
* @internal
|
|
@@ -4676,7 +4777,7 @@ const BlockProductionResponseStruct = jsonRpcResultAndContext(type({
|
|
|
4676
4777
|
*/
|
|
4677
4778
|
|
|
4678
4779
|
function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddleware, disableRetryOnRateLimit) {
|
|
4679
|
-
const fetch = customFetch ? customFetch :
|
|
4780
|
+
const fetch$1 = customFetch ? customFetch : fetch;
|
|
4680
4781
|
let agentManager;
|
|
4681
4782
|
|
|
4682
4783
|
{
|
|
@@ -4694,7 +4795,7 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
|
|
|
4694
4795
|
reject(error);
|
|
4695
4796
|
}
|
|
4696
4797
|
});
|
|
4697
|
-
return await fetch(...modifiedFetchArgs);
|
|
4798
|
+
return await fetch$1(...modifiedFetchArgs);
|
|
4698
4799
|
};
|
|
4699
4800
|
}
|
|
4700
4801
|
|
|
@@ -4718,7 +4819,7 @@ function createRpcClient(url, useHttps, httpHeaders, customFetch, fetchMiddlewar
|
|
|
4718
4819
|
if (fetchWithMiddleware) {
|
|
4719
4820
|
res = await fetchWithMiddleware(url, options);
|
|
4720
4821
|
} else {
|
|
4721
|
-
res = await fetch(url, options);
|
|
4822
|
+
res = await fetch$1(url, options);
|
|
4722
4823
|
}
|
|
4723
4824
|
|
|
4724
4825
|
if (res.status !== 429
|
|
@@ -4922,7 +5023,7 @@ const KeyedAccountInfoResult = type({
|
|
|
4922
5023
|
pubkey: PublicKeyFromString,
|
|
4923
5024
|
account: AccountInfoResult
|
|
4924
5025
|
});
|
|
4925
|
-
const ParsedOrRawAccountData = coerce(union([instance(Buffer), ParsedAccountDataResult]), union([RawAccountDataResult, ParsedAccountDataResult]), value => {
|
|
5026
|
+
const ParsedOrRawAccountData = coerce(union([instance(Buffer$1), ParsedAccountDataResult]), union([RawAccountDataResult, ParsedAccountDataResult]), value => {
|
|
4926
5027
|
if (Array.isArray(value)) {
|
|
4927
5028
|
return create(value, BufferFromRawAccountData);
|
|
4928
5029
|
} else {
|
|
@@ -8080,7 +8181,7 @@ class Ed25519Program {
|
|
|
8080
8181
|
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
8081
8182
|
const messageDataOffset = signatureOffset + signature.length;
|
|
8082
8183
|
const numSignatures = 1;
|
|
8083
|
-
const instructionData = Buffer.alloc(messageDataOffset + message.length);
|
|
8184
|
+
const instructionData = Buffer$1.alloc(messageDataOffset + message.length);
|
|
8084
8185
|
const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
|
|
8085
8186
|
: instructionIndex;
|
|
8086
8187
|
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
@@ -8951,7 +9052,7 @@ class Secp256k1Program {
|
|
|
8951
9052
|
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8952
9053
|
|
|
8953
9054
|
try {
|
|
8954
|
-
return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
9055
|
+
return Buffer$1.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8955
9056
|
} catch (error) {
|
|
8956
9057
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8957
9058
|
}
|
|
@@ -8996,9 +9097,9 @@ class Secp256k1Program {
|
|
|
8996
9097
|
|
|
8997
9098
|
if (typeof rawAddress === 'string') {
|
|
8998
9099
|
if (rawAddress.startsWith('0x')) {
|
|
8999
|
-
ethAddress = Buffer.from(rawAddress.substr(2), 'hex');
|
|
9100
|
+
ethAddress = Buffer$1.from(rawAddress.substr(2), 'hex');
|
|
9000
9101
|
} else {
|
|
9001
|
-
ethAddress = Buffer.from(rawAddress, 'hex');
|
|
9102
|
+
ethAddress = Buffer$1.from(rawAddress, 'hex');
|
|
9002
9103
|
}
|
|
9003
9104
|
} else {
|
|
9004
9105
|
ethAddress = rawAddress;
|
|
@@ -9010,7 +9111,7 @@ class Secp256k1Program {
|
|
|
9010
9111
|
const signatureOffset = dataStart + ethAddress.length;
|
|
9011
9112
|
const messageDataOffset = signatureOffset + signature.length + 1;
|
|
9012
9113
|
const numSignatures = 1;
|
|
9013
|
-
const instructionData = Buffer.alloc(SECP256K1_INSTRUCTION_LAYOUT.span + message.length);
|
|
9114
|
+
const instructionData = Buffer$1.alloc(SECP256K1_INSTRUCTION_LAYOUT.span + message.length);
|
|
9014
9115
|
SECP256K1_INSTRUCTION_LAYOUT.encode({
|
|
9015
9116
|
numSignatures,
|
|
9016
9117
|
signatureOffset,
|
|
@@ -9049,7 +9150,7 @@ class Secp256k1Program {
|
|
|
9049
9150
|
const privateKey = toBuffer(pkey);
|
|
9050
9151
|
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
|
|
9051
9152
|
|
|
9052
|
-
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
9153
|
+
const messageHash = Buffer$1.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
9053
9154
|
const {
|
|
9054
9155
|
signature,
|
|
9055
9156
|
recid: recoveryId
|
|
@@ -9134,7 +9235,7 @@ class ValidatorInfo {
|
|
|
9134
9235
|
|
|
9135
9236
|
if (configKeys[0].publicKey.equals(VALIDATOR_INFO_KEY)) {
|
|
9136
9237
|
if (configKeys[1].isSigner) {
|
|
9137
|
-
const rawInfo = rustString().decode(Buffer.from(byteArray));
|
|
9238
|
+
const rawInfo = rustString().decode(Buffer$1.from(byteArray));
|
|
9138
9239
|
const info = JSON.parse(rawInfo);
|
|
9139
9240
|
assert$7(info, InfoString);
|
|
9140
9241
|
return new ValidatorInfo(configKeys[1].publicKey, info);
|