@solana/web3.js 1.90.0 → 1.91.0
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 +64 -14
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +64 -14
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +64 -14
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +24 -12
- package/lib/index.esm.js +64 -14
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +474 -93
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +8 -7
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +64 -14
- package/lib/index.native.js.map +1 -1
- package/package.json +5 -62
- package/src/connection.ts +7 -7
- package/src/programs/stake.ts +22 -5
- package/src/programs/vote.ts +46 -3
package/lib/index.iife.js
CHANGED
|
@@ -2381,11 +2381,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
2381
2381
|
}
|
|
2382
2382
|
} (buffer));
|
|
2383
2383
|
|
|
2384
|
-
function number$
|
|
2384
|
+
function number$2(n) {
|
|
2385
2385
|
if (!Number.isSafeInteger(n) || n < 0)
|
|
2386
2386
|
throw new Error(`Wrong positive integer: ${n}`);
|
|
2387
2387
|
}
|
|
2388
|
-
function bytes(b, ...lengths) {
|
|
2388
|
+
function bytes$1(b, ...lengths) {
|
|
2389
2389
|
if (!(b instanceof Uint8Array))
|
|
2390
2390
|
throw new Error('Expected Uint8Array');
|
|
2391
2391
|
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
@@ -2394,17 +2394,17 @@ var solanaWeb3 = (function (exports) {
|
|
|
2394
2394
|
function hash(hash) {
|
|
2395
2395
|
if (typeof hash !== 'function' || typeof hash.create !== 'function')
|
|
2396
2396
|
throw new Error('Hash should be wrapped by utils.wrapConstructor');
|
|
2397
|
-
number$
|
|
2398
|
-
number$
|
|
2397
|
+
number$2(hash.outputLen);
|
|
2398
|
+
number$2(hash.blockLen);
|
|
2399
2399
|
}
|
|
2400
|
-
function exists(instance, checkFinished = true) {
|
|
2400
|
+
function exists$1(instance, checkFinished = true) {
|
|
2401
2401
|
if (instance.destroyed)
|
|
2402
2402
|
throw new Error('Hash instance has been destroyed');
|
|
2403
2403
|
if (checkFinished && instance.finished)
|
|
2404
2404
|
throw new Error('Hash#digest() has already been called');
|
|
2405
2405
|
}
|
|
2406
|
-
function output(out, instance) {
|
|
2407
|
-
bytes(out);
|
|
2406
|
+
function output$1(out, instance) {
|
|
2407
|
+
bytes$1(out);
|
|
2408
2408
|
const min = instance.outputLen;
|
|
2409
2409
|
if (out.length < min) {
|
|
2410
2410
|
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
@@ -2421,20 +2421,19 @@ var solanaWeb3 = (function (exports) {
|
|
|
2421
2421
|
// Makes the utils un-importable in browsers without a bundler.
|
|
2422
2422
|
// Once node.js 18 is deprecated, we can just drop the import.
|
|
2423
2423
|
const u8a$1 = (a) => a instanceof Uint8Array;
|
|
2424
|
-
const u32$1 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
2425
2424
|
// Cast array to view
|
|
2426
|
-
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2425
|
+
const createView$1 = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2427
2426
|
// The rotate right (circular right shift) operation for uint32
|
|
2428
|
-
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
|
2427
|
+
const rotr$1 = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
|
2429
2428
|
// big-endian hardware is rare. Just in case someone still decides to run hashes:
|
|
2430
2429
|
// early-throw an error because we don't support BE yet.
|
|
2431
|
-
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
2432
|
-
if (!isLE)
|
|
2430
|
+
const isLE$1 = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
2431
|
+
if (!isLE$1)
|
|
2433
2432
|
throw new Error('Non little-endian hardware is not supported');
|
|
2434
2433
|
/**
|
|
2435
2434
|
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
2436
2435
|
*/
|
|
2437
|
-
function utf8ToBytes$
|
|
2436
|
+
function utf8ToBytes$2(str) {
|
|
2438
2437
|
if (typeof str !== 'string')
|
|
2439
2438
|
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
2440
2439
|
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
@@ -2444,9 +2443,9 @@ var solanaWeb3 = (function (exports) {
|
|
|
2444
2443
|
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
2445
2444
|
* Keep in mind for future mutable operations.
|
|
2446
2445
|
*/
|
|
2447
|
-
function toBytes(data) {
|
|
2446
|
+
function toBytes$1(data) {
|
|
2448
2447
|
if (typeof data === 'string')
|
|
2449
|
-
data = utf8ToBytes$
|
|
2448
|
+
data = utf8ToBytes$2(data);
|
|
2450
2449
|
if (!u8a$1(data))
|
|
2451
2450
|
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
2452
2451
|
return data;
|
|
@@ -2466,14 +2465,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
2466
2465
|
return r;
|
|
2467
2466
|
}
|
|
2468
2467
|
// For runtime check if class implements interface
|
|
2469
|
-
class Hash {
|
|
2468
|
+
let Hash$1 = class Hash {
|
|
2470
2469
|
// Safe version that clones internal state
|
|
2471
2470
|
clone() {
|
|
2472
2471
|
return this._cloneInto();
|
|
2473
2472
|
}
|
|
2474
|
-
}
|
|
2475
|
-
function wrapConstructor(hashCons) {
|
|
2476
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
2473
|
+
};
|
|
2474
|
+
function wrapConstructor$1(hashCons) {
|
|
2475
|
+
const hashC = (msg) => hashCons().update(toBytes$1(msg)).digest();
|
|
2477
2476
|
const tmp = hashCons();
|
|
2478
2477
|
hashC.outputLen = tmp.outputLen;
|
|
2479
2478
|
hashC.blockLen = tmp.blockLen;
|
|
@@ -2491,7 +2490,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2491
2490
|
}
|
|
2492
2491
|
|
|
2493
2492
|
// Polyfill for Safari 14
|
|
2494
|
-
function setBigUint64(view, byteOffset, value, isLE) {
|
|
2493
|
+
function setBigUint64$1(view, byteOffset, value, isLE) {
|
|
2495
2494
|
if (typeof view.setBigUint64 === 'function')
|
|
2496
2495
|
return view.setBigUint64(byteOffset, value, isLE);
|
|
2497
2496
|
const _32n = BigInt(32);
|
|
@@ -2504,7 +2503,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2504
2503
|
view.setUint32(byteOffset + l, wl, isLE);
|
|
2505
2504
|
}
|
|
2506
2505
|
// Base SHA2 class (RFC 6234)
|
|
2507
|
-
class SHA2 extends Hash {
|
|
2506
|
+
let SHA2$1 = class SHA2 extends Hash$1 {
|
|
2508
2507
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
2509
2508
|
super();
|
|
2510
2509
|
this.blockLen = blockLen;
|
|
@@ -2516,18 +2515,18 @@ var solanaWeb3 = (function (exports) {
|
|
|
2516
2515
|
this.pos = 0;
|
|
2517
2516
|
this.destroyed = false;
|
|
2518
2517
|
this.buffer = new Uint8Array(blockLen);
|
|
2519
|
-
this.view = createView(this.buffer);
|
|
2518
|
+
this.view = createView$1(this.buffer);
|
|
2520
2519
|
}
|
|
2521
2520
|
update(data) {
|
|
2522
|
-
exists(this);
|
|
2521
|
+
exists$1(this);
|
|
2523
2522
|
const { view, buffer, blockLen } = this;
|
|
2524
|
-
data = toBytes(data);
|
|
2523
|
+
data = toBytes$1(data);
|
|
2525
2524
|
const len = data.length;
|
|
2526
2525
|
for (let pos = 0; pos < len;) {
|
|
2527
2526
|
const take = Math.min(blockLen - this.pos, len - pos);
|
|
2528
2527
|
// Fast path: we have at least one block in input, cast it to view and process
|
|
2529
2528
|
if (take === blockLen) {
|
|
2530
|
-
const dataView = createView(data);
|
|
2529
|
+
const dataView = createView$1(data);
|
|
2531
2530
|
for (; blockLen <= len - pos; pos += blockLen)
|
|
2532
2531
|
this.process(dataView, pos);
|
|
2533
2532
|
continue;
|
|
@@ -2545,8 +2544,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
2545
2544
|
return this;
|
|
2546
2545
|
}
|
|
2547
2546
|
digestInto(out) {
|
|
2548
|
-
exists(this);
|
|
2549
|
-
output(out, this);
|
|
2547
|
+
exists$1(this);
|
|
2548
|
+
output$1(out, this);
|
|
2550
2549
|
this.finished = true;
|
|
2551
2550
|
// Padding
|
|
2552
2551
|
// We can avoid allocation of buffer for padding completely if it
|
|
@@ -2567,9 +2566,9 @@ var solanaWeb3 = (function (exports) {
|
|
|
2567
2566
|
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
2568
2567
|
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
2569
2568
|
// So we just write lowest 64 bits of that value.
|
|
2570
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
2569
|
+
setBigUint64$1(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
2571
2570
|
this.process(view, 0);
|
|
2572
|
-
const oview = createView(out);
|
|
2571
|
+
const oview = createView$1(out);
|
|
2573
2572
|
const len = this.outputLen;
|
|
2574
2573
|
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
|
2575
2574
|
if (len % 4)
|
|
@@ -2600,26 +2599,26 @@ var solanaWeb3 = (function (exports) {
|
|
|
2600
2599
|
to.buffer.set(buffer);
|
|
2601
2600
|
return to;
|
|
2602
2601
|
}
|
|
2603
|
-
}
|
|
2602
|
+
};
|
|
2604
2603
|
|
|
2605
|
-
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2606
|
-
const _32n = /* @__PURE__ */ BigInt(32);
|
|
2604
|
+
const U32_MASK64$1 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
2605
|
+
const _32n$1 = /* @__PURE__ */ BigInt(32);
|
|
2607
2606
|
// We are not using BigUint64Array, because they are extremely slow as per 2022
|
|
2608
|
-
function fromBig(n, le = false) {
|
|
2607
|
+
function fromBig$1(n, le = false) {
|
|
2609
2608
|
if (le)
|
|
2610
|
-
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
2611
|
-
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
2609
|
+
return { h: Number(n & U32_MASK64$1), l: Number((n >> _32n$1) & U32_MASK64$1) };
|
|
2610
|
+
return { h: Number((n >> _32n$1) & U32_MASK64$1) | 0, l: Number(n & U32_MASK64$1) | 0 };
|
|
2612
2611
|
}
|
|
2613
|
-
function split(lst, le = false) {
|
|
2612
|
+
function split$1(lst, le = false) {
|
|
2614
2613
|
let Ah = new Uint32Array(lst.length);
|
|
2615
2614
|
let Al = new Uint32Array(lst.length);
|
|
2616
2615
|
for (let i = 0; i < lst.length; i++) {
|
|
2617
|
-
const { h, l } = fromBig(lst[i], le);
|
|
2616
|
+
const { h, l } = fromBig$1(lst[i], le);
|
|
2618
2617
|
[Ah[i], Al[i]] = [h, l];
|
|
2619
2618
|
}
|
|
2620
2619
|
return [Ah, Al];
|
|
2621
2620
|
}
|
|
2622
|
-
const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
|
|
2621
|
+
const toBig = (h, l) => (BigInt(h >>> 0) << _32n$1) | BigInt(l >>> 0);
|
|
2623
2622
|
// for Shift in [0, 32)
|
|
2624
2623
|
const shrSH = (h, _l, s) => h >>> s;
|
|
2625
2624
|
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
@@ -2633,11 +2632,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
2633
2632
|
const rotr32H = (_h, l) => l;
|
|
2634
2633
|
const rotr32L = (h, _l) => h;
|
|
2635
2634
|
// Left rotate for Shift in [1, 32)
|
|
2636
|
-
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
|
|
2637
|
-
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
|
|
2635
|
+
const rotlSH$1 = (h, l, s) => (h << s) | (l >>> (32 - s));
|
|
2636
|
+
const rotlSL$1 = (h, l, s) => (l << s) | (h >>> (32 - s));
|
|
2638
2637
|
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
2639
|
-
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
2640
|
-
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
2638
|
+
const rotlBH$1 = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
2639
|
+
const rotlBL$1 = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
2641
2640
|
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
2642
2641
|
// simple take carry out of low bit sum by shift, we need to use division.
|
|
2643
2642
|
function add(Ah, Al, Bh, Bl) {
|
|
@@ -2653,11 +2652,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
2653
2652
|
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
|
|
2654
2653
|
// prettier-ignore
|
|
2655
2654
|
const u64$1 = {
|
|
2656
|
-
fromBig, split, toBig,
|
|
2655
|
+
fromBig: fromBig$1, split: split$1, toBig,
|
|
2657
2656
|
shrSH, shrSL,
|
|
2658
2657
|
rotrSH, rotrSL, rotrBH, rotrBL,
|
|
2659
2658
|
rotr32H, rotr32L,
|
|
2660
|
-
rotlSH, rotlSL, rotlBH, rotlBL,
|
|
2659
|
+
rotlSH: rotlSH$1, rotlSL: rotlSL$1, rotlBH: rotlBH$1, rotlBL: rotlBL$1,
|
|
2661
2660
|
add, add3L, add3H, add4L, add4H, add5H, add5L,
|
|
2662
2661
|
};
|
|
2663
2662
|
var u64$2 = u64$1;
|
|
@@ -2689,7 +2688,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2689
2688
|
// Temporary buffer, not used to store anything between runs
|
|
2690
2689
|
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
2691
2690
|
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
2692
|
-
class SHA512 extends SHA2 {
|
|
2691
|
+
class SHA512 extends SHA2$1 {
|
|
2693
2692
|
constructor() {
|
|
2694
2693
|
super(128, 64, 16, false);
|
|
2695
2694
|
// We cannot use array here since array allows indexing by variable which means optimizer/compiler cannot use registers.
|
|
@@ -2816,7 +2815,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2816
2815
|
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
2817
2816
|
}
|
|
2818
2817
|
}
|
|
2819
|
-
const sha512 = /* @__PURE__ */ wrapConstructor(() => new SHA512());
|
|
2818
|
+
const sha512 = /* @__PURE__ */ wrapConstructor$1(() => new SHA512());
|
|
2820
2819
|
|
|
2821
2820
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2822
2821
|
// 100 lines of code in the file are duplicated from noble-hashes (utils).
|
|
@@ -2948,7 +2947,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2948
2947
|
/**
|
|
2949
2948
|
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
2950
2949
|
*/
|
|
2951
|
-
function utf8ToBytes(str) {
|
|
2950
|
+
function utf8ToBytes$1(str) {
|
|
2952
2951
|
if (typeof str !== 'string')
|
|
2953
2952
|
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
2954
2953
|
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
@@ -3103,7 +3102,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3103
3102
|
numberToBytesLE: numberToBytesLE,
|
|
3104
3103
|
numberToHexUnpadded: numberToHexUnpadded,
|
|
3105
3104
|
numberToVarBytesBE: numberToVarBytesBE,
|
|
3106
|
-
utf8ToBytes: utf8ToBytes,
|
|
3105
|
+
utf8ToBytes: utf8ToBytes$1,
|
|
3107
3106
|
validateObject: validateObject
|
|
3108
3107
|
});
|
|
3109
3108
|
|
|
@@ -4132,7 +4131,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
4132
4131
|
function ed25519_domain(data, ctx, phflag) {
|
|
4133
4132
|
if (ctx.length > 255)
|
|
4134
4133
|
throw new Error('Context is too big');
|
|
4135
|
-
return concatBytes$1(utf8ToBytes$
|
|
4134
|
+
return concatBytes$1(utf8ToBytes$2('SigEd25519 no Ed25519 collisions'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
|
|
4136
4135
|
}
|
|
4137
4136
|
/* @__PURE__ */ twistedEdwards({
|
|
4138
4137
|
...ed25519Defaults,
|
|
@@ -7772,16 +7771,216 @@ var solanaWeb3 = (function (exports) {
|
|
|
7772
7771
|
|
|
7773
7772
|
var bs58$1 = /*@__PURE__*/getDefaultExportFromCjs(bs58);
|
|
7774
7773
|
|
|
7774
|
+
function number$1(n) {
|
|
7775
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
7776
|
+
throw new Error(`Wrong positive integer: ${n}`);
|
|
7777
|
+
}
|
|
7778
|
+
// copied from utils
|
|
7779
|
+
function isBytes$1(a) {
|
|
7780
|
+
return (a instanceof Uint8Array ||
|
|
7781
|
+
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
|
7782
|
+
}
|
|
7783
|
+
function bytes(b, ...lengths) {
|
|
7784
|
+
if (!isBytes$1(b))
|
|
7785
|
+
throw new Error('Expected Uint8Array');
|
|
7786
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
7787
|
+
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
7788
|
+
}
|
|
7789
|
+
function exists(instance, checkFinished = true) {
|
|
7790
|
+
if (instance.destroyed)
|
|
7791
|
+
throw new Error('Hash instance has been destroyed');
|
|
7792
|
+
if (checkFinished && instance.finished)
|
|
7793
|
+
throw new Error('Hash#digest() has already been called');
|
|
7794
|
+
}
|
|
7795
|
+
function output(out, instance) {
|
|
7796
|
+
bytes(out);
|
|
7797
|
+
const min = instance.outputLen;
|
|
7798
|
+
if (out.length < min) {
|
|
7799
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
7800
|
+
}
|
|
7801
|
+
}
|
|
7802
|
+
|
|
7803
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7804
|
+
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
7805
|
+
// node.js versions earlier than v19 don't declare it in global scope.
|
|
7806
|
+
// For node.js, package.json#exports field mapping rewrites import
|
|
7807
|
+
// from `crypto` to `cryptoNode`, which imports native module.
|
|
7808
|
+
// Makes the utils un-importable in browsers without a bundler.
|
|
7809
|
+
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
|
7810
|
+
const u32$1 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
7811
|
+
function isBytes(a) {
|
|
7812
|
+
return (a instanceof Uint8Array ||
|
|
7813
|
+
(a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array'));
|
|
7814
|
+
}
|
|
7815
|
+
// Cast array to view
|
|
7816
|
+
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
7817
|
+
// The rotate right (circular right shift) operation for uint32
|
|
7818
|
+
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
|
7819
|
+
// big-endian hardware is rare. Just in case someone still decides to run hashes:
|
|
7820
|
+
// early-throw an error because we don't support BE yet.
|
|
7821
|
+
// Other libraries would silently corrupt the data instead of throwing an error,
|
|
7822
|
+
// when they don't support it.
|
|
7823
|
+
const isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
7824
|
+
if (!isLE)
|
|
7825
|
+
throw new Error('Non little-endian hardware is not supported');
|
|
7826
|
+
/**
|
|
7827
|
+
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
7828
|
+
*/
|
|
7829
|
+
function utf8ToBytes(str) {
|
|
7830
|
+
if (typeof str !== 'string')
|
|
7831
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
7832
|
+
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
7833
|
+
}
|
|
7834
|
+
/**
|
|
7835
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
7836
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
7837
|
+
* Keep in mind for future mutable operations.
|
|
7838
|
+
*/
|
|
7839
|
+
function toBytes(data) {
|
|
7840
|
+
if (typeof data === 'string')
|
|
7841
|
+
data = utf8ToBytes(data);
|
|
7842
|
+
if (!isBytes(data))
|
|
7843
|
+
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
7844
|
+
return data;
|
|
7845
|
+
}
|
|
7846
|
+
// For runtime check if class implements interface
|
|
7847
|
+
class Hash {
|
|
7848
|
+
// Safe version that clones internal state
|
|
7849
|
+
clone() {
|
|
7850
|
+
return this._cloneInto();
|
|
7851
|
+
}
|
|
7852
|
+
}
|
|
7853
|
+
function wrapConstructor(hashCons) {
|
|
7854
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
7855
|
+
const tmp = hashCons();
|
|
7856
|
+
hashC.outputLen = tmp.outputLen;
|
|
7857
|
+
hashC.blockLen = tmp.blockLen;
|
|
7858
|
+
hashC.create = () => hashCons();
|
|
7859
|
+
return hashC;
|
|
7860
|
+
}
|
|
7861
|
+
|
|
7862
|
+
// Polyfill for Safari 14
|
|
7863
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
7864
|
+
if (typeof view.setBigUint64 === 'function')
|
|
7865
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
7866
|
+
const _32n = BigInt(32);
|
|
7867
|
+
const _u32_max = BigInt(0xffffffff);
|
|
7868
|
+
const wh = Number((value >> _32n) & _u32_max);
|
|
7869
|
+
const wl = Number(value & _u32_max);
|
|
7870
|
+
const h = isLE ? 4 : 0;
|
|
7871
|
+
const l = isLE ? 0 : 4;
|
|
7872
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
7873
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
7874
|
+
}
|
|
7875
|
+
// Base SHA2 class (RFC 6234)
|
|
7876
|
+
class SHA2 extends Hash {
|
|
7877
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
7878
|
+
super();
|
|
7879
|
+
this.blockLen = blockLen;
|
|
7880
|
+
this.outputLen = outputLen;
|
|
7881
|
+
this.padOffset = padOffset;
|
|
7882
|
+
this.isLE = isLE;
|
|
7883
|
+
this.finished = false;
|
|
7884
|
+
this.length = 0;
|
|
7885
|
+
this.pos = 0;
|
|
7886
|
+
this.destroyed = false;
|
|
7887
|
+
this.buffer = new Uint8Array(blockLen);
|
|
7888
|
+
this.view = createView(this.buffer);
|
|
7889
|
+
}
|
|
7890
|
+
update(data) {
|
|
7891
|
+
exists(this);
|
|
7892
|
+
const { view, buffer, blockLen } = this;
|
|
7893
|
+
data = toBytes(data);
|
|
7894
|
+
const len = data.length;
|
|
7895
|
+
for (let pos = 0; pos < len;) {
|
|
7896
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
7897
|
+
// Fast path: we have at least one block in input, cast it to view and process
|
|
7898
|
+
if (take === blockLen) {
|
|
7899
|
+
const dataView = createView(data);
|
|
7900
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
7901
|
+
this.process(dataView, pos);
|
|
7902
|
+
continue;
|
|
7903
|
+
}
|
|
7904
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
7905
|
+
this.pos += take;
|
|
7906
|
+
pos += take;
|
|
7907
|
+
if (this.pos === blockLen) {
|
|
7908
|
+
this.process(view, 0);
|
|
7909
|
+
this.pos = 0;
|
|
7910
|
+
}
|
|
7911
|
+
}
|
|
7912
|
+
this.length += data.length;
|
|
7913
|
+
this.roundClean();
|
|
7914
|
+
return this;
|
|
7915
|
+
}
|
|
7916
|
+
digestInto(out) {
|
|
7917
|
+
exists(this);
|
|
7918
|
+
output(out, this);
|
|
7919
|
+
this.finished = true;
|
|
7920
|
+
// Padding
|
|
7921
|
+
// We can avoid allocation of buffer for padding completely if it
|
|
7922
|
+
// was previously not allocated here. But it won't change performance.
|
|
7923
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
7924
|
+
let { pos } = this;
|
|
7925
|
+
// append the bit '1' to the message
|
|
7926
|
+
buffer[pos++] = 0b10000000;
|
|
7927
|
+
this.buffer.subarray(pos).fill(0);
|
|
7928
|
+
// we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
|
|
7929
|
+
if (this.padOffset > blockLen - pos) {
|
|
7930
|
+
this.process(view, 0);
|
|
7931
|
+
pos = 0;
|
|
7932
|
+
}
|
|
7933
|
+
// Pad until full block byte with zeros
|
|
7934
|
+
for (let i = pos; i < blockLen; i++)
|
|
7935
|
+
buffer[i] = 0;
|
|
7936
|
+
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
7937
|
+
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
7938
|
+
// So we just write lowest 64 bits of that value.
|
|
7939
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
7940
|
+
this.process(view, 0);
|
|
7941
|
+
const oview = createView(out);
|
|
7942
|
+
const len = this.outputLen;
|
|
7943
|
+
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
|
7944
|
+
if (len % 4)
|
|
7945
|
+
throw new Error('_sha2: outputLen should be aligned to 32bit');
|
|
7946
|
+
const outLen = len / 4;
|
|
7947
|
+
const state = this.get();
|
|
7948
|
+
if (outLen > state.length)
|
|
7949
|
+
throw new Error('_sha2: outputLen bigger than state');
|
|
7950
|
+
for (let i = 0; i < outLen; i++)
|
|
7951
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
7952
|
+
}
|
|
7953
|
+
digest() {
|
|
7954
|
+
const { buffer, outputLen } = this;
|
|
7955
|
+
this.digestInto(buffer);
|
|
7956
|
+
const res = buffer.slice(0, outputLen);
|
|
7957
|
+
this.destroy();
|
|
7958
|
+
return res;
|
|
7959
|
+
}
|
|
7960
|
+
_cloneInto(to) {
|
|
7961
|
+
to || (to = new this.constructor());
|
|
7962
|
+
to.set(...this.get());
|
|
7963
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
7964
|
+
to.length = length;
|
|
7965
|
+
to.pos = pos;
|
|
7966
|
+
to.finished = finished;
|
|
7967
|
+
to.destroyed = destroyed;
|
|
7968
|
+
if (length % blockLen)
|
|
7969
|
+
to.buffer.set(buffer);
|
|
7970
|
+
return to;
|
|
7971
|
+
}
|
|
7972
|
+
}
|
|
7973
|
+
|
|
7775
7974
|
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
|
7776
7975
|
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
|
7777
7976
|
// Choice: a ? b : c
|
|
7778
|
-
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
7977
|
+
const Chi$1 = (a, b, c) => (a & b) ^ (~a & c);
|
|
7779
7978
|
// Majority function, true if any two inpust is true
|
|
7780
|
-
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
7979
|
+
const Maj$1 = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
7781
7980
|
// Round constants:
|
|
7782
7981
|
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
7783
7982
|
// prettier-ignore
|
|
7784
|
-
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
7983
|
+
const SHA256_K$1 = /* @__PURE__ */ new Uint32Array([
|
|
7785
7984
|
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
7786
7985
|
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
7787
7986
|
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
@@ -7793,25 +7992,25 @@ var solanaWeb3 = (function (exports) {
|
|
|
7793
7992
|
]);
|
|
7794
7993
|
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
|
7795
7994
|
// prettier-ignore
|
|
7796
|
-
const IV = /* @__PURE__ */ new Uint32Array([
|
|
7995
|
+
const IV$1 = /* @__PURE__ */ new Uint32Array([
|
|
7797
7996
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
7798
7997
|
]);
|
|
7799
7998
|
// Temporary buffer, not used to store anything between runs
|
|
7800
7999
|
// Named this way because it matches specification.
|
|
7801
|
-
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
7802
|
-
class SHA256 extends SHA2 {
|
|
8000
|
+
const SHA256_W$1 = /* @__PURE__ */ new Uint32Array(64);
|
|
8001
|
+
let SHA256$1 = class SHA256 extends SHA2 {
|
|
7803
8002
|
constructor() {
|
|
7804
8003
|
super(64, 32, 8, false);
|
|
7805
8004
|
// We cannot use array here since array allows indexing by variable
|
|
7806
8005
|
// which means optimizer/compiler cannot use registers.
|
|
7807
|
-
this.A = IV[0] | 0;
|
|
7808
|
-
this.B = IV[1] | 0;
|
|
7809
|
-
this.C = IV[2] | 0;
|
|
7810
|
-
this.D = IV[3] | 0;
|
|
7811
|
-
this.E = IV[4] | 0;
|
|
7812
|
-
this.F = IV[5] | 0;
|
|
7813
|
-
this.G = IV[6] | 0;
|
|
7814
|
-
this.H = IV[7] | 0;
|
|
8006
|
+
this.A = IV$1[0] | 0;
|
|
8007
|
+
this.B = IV$1[1] | 0;
|
|
8008
|
+
this.C = IV$1[2] | 0;
|
|
8009
|
+
this.D = IV$1[3] | 0;
|
|
8010
|
+
this.E = IV$1[4] | 0;
|
|
8011
|
+
this.F = IV$1[5] | 0;
|
|
8012
|
+
this.G = IV$1[6] | 0;
|
|
8013
|
+
this.H = IV$1[7] | 0;
|
|
7815
8014
|
}
|
|
7816
8015
|
get() {
|
|
7817
8016
|
const { A, B, C, D, E, F, G, H } = this;
|
|
@@ -7831,21 +8030,21 @@ var solanaWeb3 = (function (exports) {
|
|
|
7831
8030
|
process(view, offset) {
|
|
7832
8031
|
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
7833
8032
|
for (let i = 0; i < 16; i++, offset += 4)
|
|
7834
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
8033
|
+
SHA256_W$1[i] = view.getUint32(offset, false);
|
|
7835
8034
|
for (let i = 16; i < 64; i++) {
|
|
7836
|
-
const W15 = SHA256_W[i - 15];
|
|
7837
|
-
const W2 = SHA256_W[i - 2];
|
|
8035
|
+
const W15 = SHA256_W$1[i - 15];
|
|
8036
|
+
const W2 = SHA256_W$1[i - 2];
|
|
7838
8037
|
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
|
|
7839
8038
|
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
|
|
7840
|
-
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
|
8039
|
+
SHA256_W$1[i] = (s1 + SHA256_W$1[i - 7] + s0 + SHA256_W$1[i - 16]) | 0;
|
|
7841
8040
|
}
|
|
7842
8041
|
// Compression function main loop, 64 rounds
|
|
7843
8042
|
let { A, B, C, D, E, F, G, H } = this;
|
|
7844
8043
|
for (let i = 0; i < 64; i++) {
|
|
7845
8044
|
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
7846
|
-
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
8045
|
+
const T1 = (H + sigma1 + Chi$1(E, F, G) + SHA256_K$1[i] + SHA256_W$1[i]) | 0;
|
|
7847
8046
|
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
7848
|
-
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
|
8047
|
+
const T2 = (sigma0 + Maj$1(A, B, C)) | 0;
|
|
7849
8048
|
H = G;
|
|
7850
8049
|
G = F;
|
|
7851
8050
|
F = E;
|
|
@@ -7867,18 +8066,18 @@ var solanaWeb3 = (function (exports) {
|
|
|
7867
8066
|
this.set(A, B, C, D, E, F, G, H);
|
|
7868
8067
|
}
|
|
7869
8068
|
roundClean() {
|
|
7870
|
-
SHA256_W.fill(0);
|
|
8069
|
+
SHA256_W$1.fill(0);
|
|
7871
8070
|
}
|
|
7872
8071
|
destroy() {
|
|
7873
8072
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
7874
8073
|
this.buffer.fill(0);
|
|
7875
8074
|
}
|
|
7876
|
-
}
|
|
8075
|
+
};
|
|
7877
8076
|
/**
|
|
7878
8077
|
* SHA2-256 hash function
|
|
7879
8078
|
* @param message - data that would be hashed
|
|
7880
8079
|
*/
|
|
7881
|
-
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
8080
|
+
const sha256$1 = /* @__PURE__ */ wrapConstructor(() => new SHA256$1());
|
|
7882
8081
|
|
|
7883
8082
|
var lib = {};
|
|
7884
8083
|
|
|
@@ -9127,7 +9326,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
9127
9326
|
/* eslint-disable require-await */
|
|
9128
9327
|
static async createWithSeed(fromPublicKey, seed, programId) {
|
|
9129
9328
|
const buffer$1 = buffer.Buffer.concat([fromPublicKey.toBuffer(), buffer.Buffer.from(seed), programId.toBuffer()]);
|
|
9130
|
-
const publicKeyBytes = sha256(buffer$1);
|
|
9329
|
+
const publicKeyBytes = sha256$1(buffer$1);
|
|
9131
9330
|
return new PublicKey(publicKeyBytes);
|
|
9132
9331
|
}
|
|
9133
9332
|
|
|
@@ -9144,7 +9343,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
9144
9343
|
buffer$1 = buffer.Buffer.concat([buffer$1, toBuffer(seed)]);
|
|
9145
9344
|
});
|
|
9146
9345
|
buffer$1 = buffer.Buffer.concat([buffer$1, programId.toBuffer(), buffer.Buffer.from('ProgramDerivedAddress')]);
|
|
9147
|
-
const publicKeyBytes = sha256(buffer$1);
|
|
9346
|
+
const publicKeyBytes = sha256$1(buffer$1);
|
|
9148
9347
|
if (isOnCurve(publicKeyBytes)) {
|
|
9149
9348
|
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
9150
9349
|
}
|
|
@@ -21944,7 +22143,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21944
22143
|
/**
|
|
21945
22144
|
* Deregister an account notification callback
|
|
21946
22145
|
*
|
|
21947
|
-
* @param
|
|
22146
|
+
* @param clientSubscriptionId client subscription id to deregister
|
|
21948
22147
|
*/
|
|
21949
22148
|
async removeAccountChangeListener(clientSubscriptionId) {
|
|
21950
22149
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'account change');
|
|
@@ -21990,7 +22189,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
21990
22189
|
/**
|
|
21991
22190
|
* Deregister an account notification callback
|
|
21992
22191
|
*
|
|
21993
|
-
* @param
|
|
22192
|
+
* @param clientSubscriptionId client subscription id to deregister
|
|
21994
22193
|
*/
|
|
21995
22194
|
async removeProgramAccountChangeListener(clientSubscriptionId) {
|
|
21996
22195
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'program account change');
|
|
@@ -22014,7 +22213,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22014
22213
|
/**
|
|
22015
22214
|
* Deregister a logs callback.
|
|
22016
22215
|
*
|
|
22017
|
-
* @param
|
|
22216
|
+
* @param clientSubscriptionId client subscription id to deregister.
|
|
22018
22217
|
*/
|
|
22019
22218
|
async removeOnLogsListener(clientSubscriptionId) {
|
|
22020
22219
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'logs');
|
|
@@ -22059,7 +22258,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22059
22258
|
/**
|
|
22060
22259
|
* Deregister a slot notification callback
|
|
22061
22260
|
*
|
|
22062
|
-
* @param
|
|
22261
|
+
* @param clientSubscriptionId client subscription id to deregister
|
|
22063
22262
|
*/
|
|
22064
22263
|
async removeSlotChangeListener(clientSubscriptionId) {
|
|
22065
22264
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'slot change');
|
|
@@ -22094,7 +22293,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22094
22293
|
/**
|
|
22095
22294
|
* Deregister a slot update notification callback
|
|
22096
22295
|
*
|
|
22097
|
-
* @param
|
|
22296
|
+
* @param clientSubscriptionId client subscription id to deregister
|
|
22098
22297
|
*/
|
|
22099
22298
|
async removeSlotUpdateListener(clientSubscriptionId) {
|
|
22100
22299
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'slot update');
|
|
@@ -22244,7 +22443,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22244
22443
|
/**
|
|
22245
22444
|
* Deregister a signature notification callback
|
|
22246
22445
|
*
|
|
22247
|
-
* @param
|
|
22446
|
+
* @param clientSubscriptionId client subscription id to deregister
|
|
22248
22447
|
*/
|
|
22249
22448
|
async removeSignatureListener(clientSubscriptionId) {
|
|
22250
22449
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'signature result');
|
|
@@ -22278,7 +22477,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22278
22477
|
/**
|
|
22279
22478
|
* Deregister a root notification callback
|
|
22280
22479
|
*
|
|
22281
|
-
* @param
|
|
22480
|
+
* @param clientSubscriptionId client subscription id to deregister
|
|
22282
22481
|
*/
|
|
22283
22482
|
async removeRootChangeListener(clientSubscriptionId) {
|
|
22284
22483
|
await this._unsubscribeClientSubscription(clientSubscriptionId, 'root change');
|
|
@@ -22917,6 +23116,30 @@ var solanaWeb3 = (function (exports) {
|
|
|
22917
23116
|
}
|
|
22918
23117
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
22919
23118
|
|
|
23119
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
23120
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
|
23121
|
+
// We are not using BigUint64Array, because they are extremely slow as per 2022
|
|
23122
|
+
function fromBig(n, le = false) {
|
|
23123
|
+
if (le)
|
|
23124
|
+
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
23125
|
+
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
23126
|
+
}
|
|
23127
|
+
function split(lst, le = false) {
|
|
23128
|
+
let Ah = new Uint32Array(lst.length);
|
|
23129
|
+
let Al = new Uint32Array(lst.length);
|
|
23130
|
+
for (let i = 0; i < lst.length; i++) {
|
|
23131
|
+
const { h, l } = fromBig(lst[i], le);
|
|
23132
|
+
[Ah[i], Al[i]] = [h, l];
|
|
23133
|
+
}
|
|
23134
|
+
return [Ah, Al];
|
|
23135
|
+
}
|
|
23136
|
+
// Left rotate for Shift in [1, 32)
|
|
23137
|
+
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
|
|
23138
|
+
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
|
|
23139
|
+
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
23140
|
+
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
23141
|
+
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
23142
|
+
|
|
22920
23143
|
// SHA3 (keccak) is based on a new design: basically, the internal state is bigger than output size.
|
|
22921
23144
|
// It's called a sponge function.
|
|
22922
23145
|
// Various per round constants calculations
|
|
@@ -23108,6 +23331,114 @@ var solanaWeb3 = (function (exports) {
|
|
|
23108
23331
|
*/
|
|
23109
23332
|
const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
|
|
23110
23333
|
|
|
23334
|
+
// SHA2-256 need to try 2^128 hashes to execute birthday attack.
|
|
23335
|
+
// BTC network is doing 2^67 hashes/sec as per early 2023.
|
|
23336
|
+
// Choice: a ? b : c
|
|
23337
|
+
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
23338
|
+
// Majority function, true if any two inpust is true
|
|
23339
|
+
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
23340
|
+
// Round constants:
|
|
23341
|
+
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
23342
|
+
// prettier-ignore
|
|
23343
|
+
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
|
23344
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
23345
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
23346
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
23347
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
23348
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
23349
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
23350
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
23351
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
23352
|
+
]);
|
|
23353
|
+
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
|
23354
|
+
// prettier-ignore
|
|
23355
|
+
const IV = /* @__PURE__ */ new Uint32Array([
|
|
23356
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
23357
|
+
]);
|
|
23358
|
+
// Temporary buffer, not used to store anything between runs
|
|
23359
|
+
// Named this way because it matches specification.
|
|
23360
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
23361
|
+
class SHA256 extends SHA2$1 {
|
|
23362
|
+
constructor() {
|
|
23363
|
+
super(64, 32, 8, false);
|
|
23364
|
+
// We cannot use array here since array allows indexing by variable
|
|
23365
|
+
// which means optimizer/compiler cannot use registers.
|
|
23366
|
+
this.A = IV[0] | 0;
|
|
23367
|
+
this.B = IV[1] | 0;
|
|
23368
|
+
this.C = IV[2] | 0;
|
|
23369
|
+
this.D = IV[3] | 0;
|
|
23370
|
+
this.E = IV[4] | 0;
|
|
23371
|
+
this.F = IV[5] | 0;
|
|
23372
|
+
this.G = IV[6] | 0;
|
|
23373
|
+
this.H = IV[7] | 0;
|
|
23374
|
+
}
|
|
23375
|
+
get() {
|
|
23376
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
23377
|
+
return [A, B, C, D, E, F, G, H];
|
|
23378
|
+
}
|
|
23379
|
+
// prettier-ignore
|
|
23380
|
+
set(A, B, C, D, E, F, G, H) {
|
|
23381
|
+
this.A = A | 0;
|
|
23382
|
+
this.B = B | 0;
|
|
23383
|
+
this.C = C | 0;
|
|
23384
|
+
this.D = D | 0;
|
|
23385
|
+
this.E = E | 0;
|
|
23386
|
+
this.F = F | 0;
|
|
23387
|
+
this.G = G | 0;
|
|
23388
|
+
this.H = H | 0;
|
|
23389
|
+
}
|
|
23390
|
+
process(view, offset) {
|
|
23391
|
+
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
23392
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
23393
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
23394
|
+
for (let i = 16; i < 64; i++) {
|
|
23395
|
+
const W15 = SHA256_W[i - 15];
|
|
23396
|
+
const W2 = SHA256_W[i - 2];
|
|
23397
|
+
const s0 = rotr$1(W15, 7) ^ rotr$1(W15, 18) ^ (W15 >>> 3);
|
|
23398
|
+
const s1 = rotr$1(W2, 17) ^ rotr$1(W2, 19) ^ (W2 >>> 10);
|
|
23399
|
+
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
|
23400
|
+
}
|
|
23401
|
+
// Compression function main loop, 64 rounds
|
|
23402
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
23403
|
+
for (let i = 0; i < 64; i++) {
|
|
23404
|
+
const sigma1 = rotr$1(E, 6) ^ rotr$1(E, 11) ^ rotr$1(E, 25);
|
|
23405
|
+
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
23406
|
+
const sigma0 = rotr$1(A, 2) ^ rotr$1(A, 13) ^ rotr$1(A, 22);
|
|
23407
|
+
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
|
23408
|
+
H = G;
|
|
23409
|
+
G = F;
|
|
23410
|
+
F = E;
|
|
23411
|
+
E = (D + T1) | 0;
|
|
23412
|
+
D = C;
|
|
23413
|
+
C = B;
|
|
23414
|
+
B = A;
|
|
23415
|
+
A = (T1 + T2) | 0;
|
|
23416
|
+
}
|
|
23417
|
+
// Add the compressed chunk to the current hash value
|
|
23418
|
+
A = (A + this.A) | 0;
|
|
23419
|
+
B = (B + this.B) | 0;
|
|
23420
|
+
C = (C + this.C) | 0;
|
|
23421
|
+
D = (D + this.D) | 0;
|
|
23422
|
+
E = (E + this.E) | 0;
|
|
23423
|
+
F = (F + this.F) | 0;
|
|
23424
|
+
G = (G + this.G) | 0;
|
|
23425
|
+
H = (H + this.H) | 0;
|
|
23426
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
23427
|
+
}
|
|
23428
|
+
roundClean() {
|
|
23429
|
+
SHA256_W.fill(0);
|
|
23430
|
+
}
|
|
23431
|
+
destroy() {
|
|
23432
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
23433
|
+
this.buffer.fill(0);
|
|
23434
|
+
}
|
|
23435
|
+
}
|
|
23436
|
+
/**
|
|
23437
|
+
* SHA2-256 hash function
|
|
23438
|
+
* @param message - data that would be hashed
|
|
23439
|
+
*/
|
|
23440
|
+
const sha256 = /* @__PURE__ */ wrapConstructor$1(() => new SHA256());
|
|
23441
|
+
|
|
23111
23442
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
23112
23443
|
// Short Weierstrass curve. The formula is: y² = x³ + ax + b
|
|
23113
23444
|
function validatePointOpts(curve) {
|
|
@@ -24039,13 +24370,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
24039
24370
|
}
|
|
24040
24371
|
|
|
24041
24372
|
// HMAC (RFC 2104)
|
|
24042
|
-
class HMAC extends Hash {
|
|
24373
|
+
class HMAC extends Hash$1 {
|
|
24043
24374
|
constructor(hash$1, _key) {
|
|
24044
24375
|
super();
|
|
24045
24376
|
this.finished = false;
|
|
24046
24377
|
this.destroyed = false;
|
|
24047
24378
|
hash(hash$1);
|
|
24048
|
-
const key = toBytes(_key);
|
|
24379
|
+
const key = toBytes$1(_key);
|
|
24049
24380
|
this.iHash = hash$1.create();
|
|
24050
24381
|
if (typeof this.iHash.update !== 'function')
|
|
24051
24382
|
throw new Error('Expected instance of class which extends utils.Hash');
|
|
@@ -24067,13 +24398,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
24067
24398
|
pad.fill(0);
|
|
24068
24399
|
}
|
|
24069
24400
|
update(buf) {
|
|
24070
|
-
exists(this);
|
|
24401
|
+
exists$1(this);
|
|
24071
24402
|
this.iHash.update(buf);
|
|
24072
24403
|
return this;
|
|
24073
24404
|
}
|
|
24074
24405
|
digestInto(out) {
|
|
24075
|
-
exists(this);
|
|
24076
|
-
bytes(out, this.outputLen);
|
|
24406
|
+
exists$1(this);
|
|
24407
|
+
bytes$1(out, this.outputLen);
|
|
24077
24408
|
this.finished = true;
|
|
24078
24409
|
this.iHash.digestInto(out);
|
|
24079
24410
|
this.oHash.update(out);
|
|
@@ -24971,12 +25302,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
24971
25302
|
/**
|
|
24972
25303
|
* Generate a Transaction that splits Stake tokens into another stake account
|
|
24973
25304
|
*/
|
|
24974
|
-
static split(params
|
|
25305
|
+
static split(params,
|
|
25306
|
+
// Compute the cost of allocating the new stake account in lamports
|
|
25307
|
+
rentExemptReserve) {
|
|
24975
25308
|
const transaction = new Transaction();
|
|
24976
25309
|
transaction.add(SystemProgram.createAccount({
|
|
24977
25310
|
fromPubkey: params.authorizedPubkey,
|
|
24978
25311
|
newAccountPubkey: params.splitStakePubkey,
|
|
24979
|
-
lamports:
|
|
25312
|
+
lamports: rentExemptReserve,
|
|
24980
25313
|
space: this.space,
|
|
24981
25314
|
programId: this.programId
|
|
24982
25315
|
}));
|
|
@@ -24987,7 +25320,9 @@ var solanaWeb3 = (function (exports) {
|
|
|
24987
25320
|
* Generate a Transaction that splits Stake tokens into another account
|
|
24988
25321
|
* derived from a base public key and seed
|
|
24989
25322
|
*/
|
|
24990
|
-
static splitWithSeed(params
|
|
25323
|
+
static splitWithSeed(params,
|
|
25324
|
+
// If this stake account is new, compute the cost of allocating it in lamports
|
|
25325
|
+
rentExemptReserve) {
|
|
24991
25326
|
const {
|
|
24992
25327
|
stakePubkey,
|
|
24993
25328
|
authorizedPubkey,
|
|
@@ -25004,6 +25339,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
25004
25339
|
space: this.space,
|
|
25005
25340
|
programId: this.programId
|
|
25006
25341
|
}));
|
|
25342
|
+
if (rentExemptReserve && rentExemptReserve > 0) {
|
|
25343
|
+
transaction.add(SystemProgram.transfer({
|
|
25344
|
+
fromPubkey: params.authorizedPubkey,
|
|
25345
|
+
toPubkey: splitStakePubkey,
|
|
25346
|
+
lamports: rentExemptReserve
|
|
25347
|
+
}));
|
|
25348
|
+
}
|
|
25007
25349
|
return transaction.add(this.splitInstruction({
|
|
25008
25350
|
stakePubkey,
|
|
25009
25351
|
authorizedPubkey,
|
|
@@ -25134,8 +25476,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
25134
25476
|
* Max space of a Stake account
|
|
25135
25477
|
*
|
|
25136
25478
|
* This is generated from the solana-stake-program StakeState struct as
|
|
25137
|
-
* `
|
|
25138
|
-
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.
|
|
25479
|
+
* `StakeStateV2::size_of()`:
|
|
25480
|
+
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.StakeStateV2.html
|
|
25139
25481
|
*/
|
|
25140
25482
|
StakeProgram.space = 200;
|
|
25141
25483
|
|
|
@@ -25177,6 +25519,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
25177
25519
|
* Withdraw from vote account transaction params
|
|
25178
25520
|
*/
|
|
25179
25521
|
|
|
25522
|
+
/**
|
|
25523
|
+
* Update validator identity (node pubkey) vote account instruction params.
|
|
25524
|
+
*/
|
|
25525
|
+
|
|
25180
25526
|
/**
|
|
25181
25527
|
* Vote Instruction class
|
|
25182
25528
|
*/
|
|
@@ -25323,6 +25669,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
25323
25669
|
index: 3,
|
|
25324
25670
|
layout: struct([u32('instruction'), ns64('lamports')])
|
|
25325
25671
|
},
|
|
25672
|
+
UpdateValidatorIdentity: {
|
|
25673
|
+
index: 4,
|
|
25674
|
+
layout: struct([u32('instruction')])
|
|
25675
|
+
},
|
|
25326
25676
|
AuthorizeWithSeed: {
|
|
25327
25677
|
index: 10,
|
|
25328
25678
|
layout: struct([u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
@@ -25540,10 +25890,41 @@ var solanaWeb3 = (function (exports) {
|
|
|
25540
25890
|
*/
|
|
25541
25891
|
static safeWithdraw(params, currentVoteAccountBalance, rentExemptMinimum) {
|
|
25542
25892
|
if (params.lamports > currentVoteAccountBalance - rentExemptMinimum) {
|
|
25543
|
-
throw new Error('Withdraw will leave vote account with
|
|
25893
|
+
throw new Error('Withdraw will leave vote account with insufficient funds.');
|
|
25544
25894
|
}
|
|
25545
25895
|
return VoteProgram.withdraw(params);
|
|
25546
25896
|
}
|
|
25897
|
+
|
|
25898
|
+
/**
|
|
25899
|
+
* Generate a transaction to update the validator identity (node pubkey) of a Vote account.
|
|
25900
|
+
*/
|
|
25901
|
+
static updateValidatorIdentity(params) {
|
|
25902
|
+
const {
|
|
25903
|
+
votePubkey,
|
|
25904
|
+
authorizedWithdrawerPubkey,
|
|
25905
|
+
nodePubkey
|
|
25906
|
+
} = params;
|
|
25907
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.UpdateValidatorIdentity;
|
|
25908
|
+
const data = encodeData(type);
|
|
25909
|
+
const keys = [{
|
|
25910
|
+
pubkey: votePubkey,
|
|
25911
|
+
isSigner: false,
|
|
25912
|
+
isWritable: true
|
|
25913
|
+
}, {
|
|
25914
|
+
pubkey: nodePubkey,
|
|
25915
|
+
isSigner: true,
|
|
25916
|
+
isWritable: false
|
|
25917
|
+
}, {
|
|
25918
|
+
pubkey: authorizedWithdrawerPubkey,
|
|
25919
|
+
isSigner: true,
|
|
25920
|
+
isWritable: false
|
|
25921
|
+
}];
|
|
25922
|
+
return new Transaction().add({
|
|
25923
|
+
keys,
|
|
25924
|
+
programId: this.programId,
|
|
25925
|
+
data
|
|
25926
|
+
});
|
|
25927
|
+
}
|
|
25547
25928
|
}
|
|
25548
25929
|
VoteProgram.programId = new PublicKey('Vote111111111111111111111111111111111111111');
|
|
25549
25930
|
/**
|
|
@@ -25555,7 +25936,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
25555
25936
|
*
|
|
25556
25937
|
* KEEP IN SYNC WITH `VoteState::size_of()` in https://github.com/solana-labs/solana/blob/a474cb24b9238f5edcc982f65c0b37d4a1046f7e/sdk/program/src/vote/state/mod.rs#L340-L342
|
|
25557
25938
|
*/
|
|
25558
|
-
VoteProgram.space =
|
|
25939
|
+
VoteProgram.space = 3762;
|
|
25559
25940
|
|
|
25560
25941
|
const VALIDATOR_INFO_KEY = new PublicKey('Va1idator1nfo111111111111111111111111111111');
|
|
25561
25942
|
|