@solana/web3.js 1.57.0 → 1.59.1
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 +460 -121
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +460 -121
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +460 -121
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +105 -1
- package/lib/index.esm.js +460 -121
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +726 -831
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +5 -13
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +460 -121
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -2
- package/src/connection.ts +106 -2
- package/src/layout.ts +22 -0
- package/src/message/legacy.ts +34 -2
- package/src/message/v0.ts +90 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
- package/src/transaction/index.ts +1 -0
- package/src/transaction/message.ts +138 -0
package/lib/index.iife.js
CHANGED
|
@@ -2417,6 +2417,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2417
2417
|
var assert$3 = assert$2;
|
|
2418
2418
|
|
|
2419
2419
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2420
|
+
const u32$1 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
2420
2421
|
// Cast array to view
|
|
2421
2422
|
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
2422
2423
|
// The rotate right (circular right shift) operation for uint32
|
|
@@ -2455,6 +2456,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
2455
2456
|
hashC.create = () => hashConstructor();
|
|
2456
2457
|
return hashC;
|
|
2457
2458
|
}
|
|
2459
|
+
function wrapConstructorWithOpts(hashCons) {
|
|
2460
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
2461
|
+
const tmp = hashCons({});
|
|
2462
|
+
hashC.outputLen = tmp.outputLen;
|
|
2463
|
+
hashC.blockLen = tmp.blockLen;
|
|
2464
|
+
hashC.create = (opts) => hashCons(opts);
|
|
2465
|
+
return hashC;
|
|
2466
|
+
}
|
|
2458
2467
|
|
|
2459
2468
|
// Polyfill for Safari 14
|
|
2460
2469
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
@@ -2832,22 +2841,22 @@ var solanaWeb3 = (function (exports) {
|
|
|
2832
2841
|
});
|
|
2833
2842
|
|
|
2834
2843
|
/*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
2835
|
-
const _0n$
|
|
2836
|
-
const _1n$
|
|
2837
|
-
const _2n$
|
|
2844
|
+
const _0n$2 = BigInt(0);
|
|
2845
|
+
const _1n$2 = BigInt(1);
|
|
2846
|
+
const _2n$2 = BigInt(2);
|
|
2838
2847
|
const _255n = BigInt(255);
|
|
2839
|
-
const CURVE_ORDER = _2n$
|
|
2848
|
+
const CURVE_ORDER = _2n$2 ** BigInt(252) + BigInt('27742317777372353535851937790883648493');
|
|
2840
2849
|
const CURVE$1 = Object.freeze({
|
|
2841
2850
|
a: BigInt(-1),
|
|
2842
2851
|
d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
|
|
2843
|
-
P: _2n$
|
|
2852
|
+
P: _2n$2 ** _255n - BigInt(19),
|
|
2844
2853
|
l: CURVE_ORDER,
|
|
2845
2854
|
n: CURVE_ORDER,
|
|
2846
2855
|
h: BigInt(8),
|
|
2847
2856
|
Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
|
|
2848
2857
|
Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
|
|
2849
2858
|
});
|
|
2850
|
-
const MAX_256B = _2n$
|
|
2859
|
+
const MAX_256B = _2n$2 ** BigInt(256);
|
|
2851
2860
|
const SQRT_M1 = BigInt('19681161376707505956807079304988542015446066515923890162744021073123829784752');
|
|
2852
2861
|
BigInt('6853475219497561581579357271197624642482790079785650197046958215289687604742');
|
|
2853
2862
|
BigInt('25063068953384623474111414158702152701244531502492656460079210482610430750235');
|
|
@@ -2867,7 +2876,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2867
2876
|
}
|
|
2868
2877
|
if (p.equals(Point$1.ZERO))
|
|
2869
2878
|
return ExtendedPoint.ZERO;
|
|
2870
|
-
return new ExtendedPoint(p.x, p.y, _1n$
|
|
2879
|
+
return new ExtendedPoint(p.x, p.y, _1n$2, mod$1(p.x * p.y));
|
|
2871
2880
|
}
|
|
2872
2881
|
static toAffineBatch(points) {
|
|
2873
2882
|
const toInv = invertBatch$1(points.map((p) => p.z));
|
|
@@ -2892,11 +2901,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
2892
2901
|
double() {
|
|
2893
2902
|
const { x: X1, y: Y1, z: Z1 } = this;
|
|
2894
2903
|
const { a } = CURVE$1;
|
|
2895
|
-
const A = mod$1(X1 ** _2n$
|
|
2896
|
-
const B = mod$1(Y1 ** _2n$
|
|
2897
|
-
const C = mod$1(_2n$
|
|
2904
|
+
const A = mod$1(X1 ** _2n$2);
|
|
2905
|
+
const B = mod$1(Y1 ** _2n$2);
|
|
2906
|
+
const C = mod$1(_2n$2 * mod$1(Z1 ** _2n$2));
|
|
2898
2907
|
const D = mod$1(a * A);
|
|
2899
|
-
const E = mod$1(mod$1((X1 + Y1) ** _2n$
|
|
2908
|
+
const E = mod$1(mod$1((X1 + Y1) ** _2n$2) - A - B);
|
|
2900
2909
|
const G = D + B;
|
|
2901
2910
|
const F = G - C;
|
|
2902
2911
|
const H = D - B;
|
|
@@ -2913,10 +2922,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
2913
2922
|
const A = mod$1((Y1 - X1) * (Y2 + X2));
|
|
2914
2923
|
const B = mod$1((Y1 + X1) * (Y2 - X2));
|
|
2915
2924
|
const F = mod$1(B - A);
|
|
2916
|
-
if (F === _0n$
|
|
2925
|
+
if (F === _0n$2)
|
|
2917
2926
|
return this.double();
|
|
2918
|
-
const C = mod$1(Z1 * _2n$
|
|
2919
|
-
const D = mod$1(T1 * _2n$
|
|
2927
|
+
const C = mod$1(Z1 * _2n$2 * T2);
|
|
2928
|
+
const D = mod$1(T1 * _2n$2 * Z2);
|
|
2920
2929
|
const E = D + C;
|
|
2921
2930
|
const G = B + A;
|
|
2922
2931
|
const H = D - C;
|
|
@@ -2973,7 +2982,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
2973
2982
|
n >>= shiftBy;
|
|
2974
2983
|
if (wbits > windowSize) {
|
|
2975
2984
|
wbits -= maxNumber;
|
|
2976
|
-
n += _1n$
|
|
2985
|
+
n += _1n$2;
|
|
2977
2986
|
}
|
|
2978
2987
|
if (wbits === 0) {
|
|
2979
2988
|
let pr = precomputes[offset];
|
|
@@ -2997,19 +3006,19 @@ var solanaWeb3 = (function (exports) {
|
|
|
2997
3006
|
let n = normalizeScalar$1(scalar, CURVE$1.l, false);
|
|
2998
3007
|
const G = ExtendedPoint.BASE;
|
|
2999
3008
|
const P0 = ExtendedPoint.ZERO;
|
|
3000
|
-
if (n === _0n$
|
|
3009
|
+
if (n === _0n$2)
|
|
3001
3010
|
return P0;
|
|
3002
|
-
if (this.equals(P0) || n === _1n$
|
|
3011
|
+
if (this.equals(P0) || n === _1n$2)
|
|
3003
3012
|
return this;
|
|
3004
3013
|
if (this.equals(G))
|
|
3005
3014
|
return this.wNAF(n);
|
|
3006
3015
|
let p = P0;
|
|
3007
3016
|
let d = this;
|
|
3008
|
-
while (n > _0n$
|
|
3009
|
-
if (n & _1n$
|
|
3017
|
+
while (n > _0n$2) {
|
|
3018
|
+
if (n & _1n$2)
|
|
3010
3019
|
p = p.add(d);
|
|
3011
3020
|
d = d.double();
|
|
3012
|
-
n >>= _1n$
|
|
3021
|
+
n >>= _1n$2;
|
|
3013
3022
|
}
|
|
3014
3023
|
return p;
|
|
3015
3024
|
}
|
|
@@ -3024,7 +3033,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3024
3033
|
const ax = mod$1(x * invZ);
|
|
3025
3034
|
const ay = mod$1(y * invZ);
|
|
3026
3035
|
const zz = mod$1(z * invZ);
|
|
3027
|
-
if (zz !== _1n$
|
|
3036
|
+
if (zz !== _1n$2)
|
|
3028
3037
|
throw new Error('invZ was invalid');
|
|
3029
3038
|
return new Point$1(ax, ay);
|
|
3030
3039
|
}
|
|
@@ -3038,8 +3047,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
3038
3047
|
legacyRist();
|
|
3039
3048
|
}
|
|
3040
3049
|
}
|
|
3041
|
-
ExtendedPoint.BASE = new ExtendedPoint(CURVE$1.Gx, CURVE$1.Gy, _1n$
|
|
3042
|
-
ExtendedPoint.ZERO = new ExtendedPoint(_0n$
|
|
3050
|
+
ExtendedPoint.BASE = new ExtendedPoint(CURVE$1.Gx, CURVE$1.Gy, _1n$2, mod$1(CURVE$1.Gx * CURVE$1.Gy));
|
|
3051
|
+
ExtendedPoint.ZERO = new ExtendedPoint(_0n$2, _1n$2, _1n$2, _0n$2);
|
|
3043
3052
|
function assertExtPoint(other) {
|
|
3044
3053
|
if (!(other instanceof ExtendedPoint))
|
|
3045
3054
|
throw new TypeError('ExtendedPoint expected');
|
|
@@ -3068,12 +3077,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
3068
3077
|
if (!strict && y >= MAX_256B)
|
|
3069
3078
|
throw new Error('Expected 0 < hex < 2**256');
|
|
3070
3079
|
const y2 = mod$1(y * y);
|
|
3071
|
-
const u = mod$1(y2 - _1n$
|
|
3072
|
-
const v = mod$1(d * y2 + _1n$
|
|
3080
|
+
const u = mod$1(y2 - _1n$2);
|
|
3081
|
+
const v = mod$1(d * y2 + _1n$2);
|
|
3073
3082
|
let { isValid, value: x } = uvRatio(u, v);
|
|
3074
3083
|
if (!isValid)
|
|
3075
3084
|
throw new Error('Point.fromHex: invalid y coordinate');
|
|
3076
|
-
const isXOdd = (x & _1n$
|
|
3085
|
+
const isXOdd = (x & _1n$2) === _1n$2;
|
|
3077
3086
|
const isLastByteOdd = (hex[31] & 0x80) !== 0;
|
|
3078
3087
|
if (isLastByteOdd !== isXOdd) {
|
|
3079
3088
|
x = mod$1(-x);
|
|
@@ -3085,7 +3094,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3085
3094
|
}
|
|
3086
3095
|
toRawBytes() {
|
|
3087
3096
|
const bytes = numberTo32BytesLE(this.y);
|
|
3088
|
-
bytes[31] |= this.x & _1n$
|
|
3097
|
+
bytes[31] |= this.x & _1n$2 ? 0x80 : 0;
|
|
3089
3098
|
return bytes;
|
|
3090
3099
|
}
|
|
3091
3100
|
toHex() {
|
|
@@ -3093,7 +3102,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3093
3102
|
}
|
|
3094
3103
|
toX25519() {
|
|
3095
3104
|
const { y } = this;
|
|
3096
|
-
const u = mod$1((_1n$
|
|
3105
|
+
const u = mod$1((_1n$2 + y) * invert$1(_1n$2 - y));
|
|
3097
3106
|
return numberTo32BytesLE(u);
|
|
3098
3107
|
}
|
|
3099
3108
|
isTorsionFree() {
|
|
@@ -3116,7 +3125,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3116
3125
|
}
|
|
3117
3126
|
}
|
|
3118
3127
|
Point$1.BASE = new Point$1(CURVE$1.Gx, CURVE$1.Gy);
|
|
3119
|
-
Point$1.ZERO = new Point$1(_0n$
|
|
3128
|
+
Point$1.ZERO = new Point$1(_0n$2, _1n$2);
|
|
3120
3129
|
class Signature$1 {
|
|
3121
3130
|
constructor(r, s) {
|
|
3122
3131
|
this.r = r;
|
|
@@ -3196,7 +3205,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3196
3205
|
return numberTo32BytesBE(num).reverse();
|
|
3197
3206
|
}
|
|
3198
3207
|
function edIsNegative(num) {
|
|
3199
|
-
return (mod$1(num) & _1n$
|
|
3208
|
+
return (mod$1(num) & _1n$2) === _1n$2;
|
|
3200
3209
|
}
|
|
3201
3210
|
function bytesToNumberLE(uint8a) {
|
|
3202
3211
|
if (!(uint8a instanceof Uint8Array))
|
|
@@ -3205,37 +3214,37 @@ var solanaWeb3 = (function (exports) {
|
|
|
3205
3214
|
}
|
|
3206
3215
|
function mod$1(a, b = CURVE$1.P) {
|
|
3207
3216
|
const res = a % b;
|
|
3208
|
-
return res >= _0n$
|
|
3217
|
+
return res >= _0n$2 ? res : b + res;
|
|
3209
3218
|
}
|
|
3210
3219
|
function invert$1(number, modulo = CURVE$1.P) {
|
|
3211
|
-
if (number === _0n$
|
|
3220
|
+
if (number === _0n$2 || modulo <= _0n$2) {
|
|
3212
3221
|
throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
|
|
3213
3222
|
}
|
|
3214
3223
|
let a = mod$1(number, modulo);
|
|
3215
3224
|
let b = modulo;
|
|
3216
|
-
let x = _0n$
|
|
3217
|
-
while (a !== _0n$
|
|
3225
|
+
let x = _0n$2, u = _1n$2;
|
|
3226
|
+
while (a !== _0n$2) {
|
|
3218
3227
|
const q = b / a;
|
|
3219
3228
|
const r = b % a;
|
|
3220
3229
|
const m = x - u * q;
|
|
3221
3230
|
b = a, a = r, x = u, u = m;
|
|
3222
3231
|
}
|
|
3223
3232
|
const gcd = b;
|
|
3224
|
-
if (gcd !== _1n$
|
|
3233
|
+
if (gcd !== _1n$2)
|
|
3225
3234
|
throw new Error('invert: does not exist');
|
|
3226
3235
|
return mod$1(x, modulo);
|
|
3227
3236
|
}
|
|
3228
3237
|
function invertBatch$1(nums, p = CURVE$1.P) {
|
|
3229
3238
|
const tmp = new Array(nums.length);
|
|
3230
3239
|
const lastMultiplied = nums.reduce((acc, num, i) => {
|
|
3231
|
-
if (num === _0n$
|
|
3240
|
+
if (num === _0n$2)
|
|
3232
3241
|
return acc;
|
|
3233
3242
|
tmp[i] = acc;
|
|
3234
3243
|
return mod$1(acc * num, p);
|
|
3235
|
-
}, _1n$
|
|
3244
|
+
}, _1n$2);
|
|
3236
3245
|
const inverted = invert$1(lastMultiplied, p);
|
|
3237
3246
|
nums.reduceRight((acc, num, i) => {
|
|
3238
|
-
if (num === _0n$
|
|
3247
|
+
if (num === _0n$2)
|
|
3239
3248
|
return acc;
|
|
3240
3249
|
tmp[i] = mod$1(acc * tmp[i], p);
|
|
3241
3250
|
return mod$1(acc * num, p);
|
|
@@ -3245,7 +3254,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3245
3254
|
function pow2$1(x, power) {
|
|
3246
3255
|
const { P } = CURVE$1;
|
|
3247
3256
|
let res = x;
|
|
3248
|
-
while (power-- > _0n$
|
|
3257
|
+
while (power-- > _0n$2) {
|
|
3249
3258
|
res *= res;
|
|
3250
3259
|
res %= P;
|
|
3251
3260
|
}
|
|
@@ -3260,8 +3269,8 @@ var solanaWeb3 = (function (exports) {
|
|
|
3260
3269
|
const _80n = BigInt(80);
|
|
3261
3270
|
const x2 = (x * x) % P;
|
|
3262
3271
|
const b2 = (x2 * x) % P;
|
|
3263
|
-
const b4 = (pow2$1(b2, _2n$
|
|
3264
|
-
const b5 = (pow2$1(b4, _1n$
|
|
3272
|
+
const b4 = (pow2$1(b2, _2n$2) * b2) % P;
|
|
3273
|
+
const b5 = (pow2$1(b4, _1n$2) * x) % P;
|
|
3265
3274
|
const b10 = (pow2$1(b5, _5n) * b5) % P;
|
|
3266
3275
|
const b20 = (pow2$1(b10, _10n) * b10) % P;
|
|
3267
3276
|
const b40 = (pow2$1(b20, _20n) * b20) % P;
|
|
@@ -3269,7 +3278,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3269
3278
|
const b160 = (pow2$1(b80, _80n) * b80) % P;
|
|
3270
3279
|
const b240 = (pow2$1(b160, _80n) * b80) % P;
|
|
3271
3280
|
const b250 = (pow2$1(b240, _10n) * b10) % P;
|
|
3272
|
-
const pow_p_5_8 = (pow2$1(b250, _2n$
|
|
3281
|
+
const pow_p_5_8 = (pow2$1(b250, _2n$2) * x) % P;
|
|
3273
3282
|
return { pow_p_5_8, b2 };
|
|
3274
3283
|
}
|
|
3275
3284
|
function uvRatio(u, v) {
|
|
@@ -3307,11 +3316,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
3307
3316
|
num = BigInt(num);
|
|
3308
3317
|
if (typeof num === 'bigint' && num < max) {
|
|
3309
3318
|
if (strict) {
|
|
3310
|
-
if (_0n$
|
|
3319
|
+
if (_0n$2 < num)
|
|
3311
3320
|
return num;
|
|
3312
3321
|
}
|
|
3313
3322
|
else {
|
|
3314
|
-
if (_0n$
|
|
3323
|
+
if (_0n$2 <= num)
|
|
3315
3324
|
return num;
|
|
3316
3325
|
}
|
|
3317
3326
|
}
|
|
@@ -3415,7 +3424,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3415
3424
|
hash = ensureBytes$1(hash);
|
|
3416
3425
|
if (hash.length < 40 || hash.length > 1024)
|
|
3417
3426
|
throw new Error('Expected 40-1024 bytes of private key as per FIPS 186');
|
|
3418
|
-
return mod$1(bytesToNumberLE(hash), CURVE$1.l - _1n$
|
|
3427
|
+
return mod$1(bytesToNumberLE(hash), CURVE$1.l - _1n$2) + _1n$2;
|
|
3419
3428
|
},
|
|
3420
3429
|
randomBytes: (bytesLength = 32) => {
|
|
3421
3430
|
if (crypto$2.web) {
|
|
@@ -3448,7 +3457,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
3448
3457
|
precompute(windowSize = 8, point = Point$1.BASE) {
|
|
3449
3458
|
const cached = point.equals(Point$1.BASE) ? point : new Point$1(point.x, point.y);
|
|
3450
3459
|
cached._setWindowSize(windowSize);
|
|
3451
|
-
cached.multiply(_2n$
|
|
3460
|
+
cached.multiply(_2n$2);
|
|
3452
3461
|
return cached;
|
|
3453
3462
|
},
|
|
3454
3463
|
sha512Sync: undefined,
|
|
@@ -10965,7 +10974,6 @@ var solanaWeb3 = (function (exports) {
|
|
|
10965
10974
|
/**
|
|
10966
10975
|
* Layout for a public key
|
|
10967
10976
|
*/
|
|
10968
|
-
|
|
10969
10977
|
const publicKey = (property = 'publicKey') => {
|
|
10970
10978
|
return blob(32, property);
|
|
10971
10979
|
};
|
|
@@ -11029,6 +11037,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
11029
11037
|
const voteInit = (property = 'voteInit') => {
|
|
11030
11038
|
return struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), u8('commission')], property);
|
|
11031
11039
|
};
|
|
11040
|
+
/**
|
|
11041
|
+
* Layout for a VoteAuthorizeWithSeedArgs object
|
|
11042
|
+
*/
|
|
11043
|
+
|
|
11044
|
+
const voteAuthorizeWithSeedArgs = (property = 'voteAuthorizeWithSeedArgs') => {
|
|
11045
|
+
return struct([u32('voteAuthorizationType'), publicKey('currentAuthorityDerivedKeyOwnerPubkey'), rustString('currentAuthorityDerivedKeySeed'), publicKey('newAuthorized')], property);
|
|
11046
|
+
};
|
|
11032
11047
|
function getAlloc(type, fields) {
|
|
11033
11048
|
const getItemAlloc = item => {
|
|
11034
11049
|
if (item.span >= 0) {
|
|
@@ -11041,6 +11056,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
11041
11056
|
if (Array.isArray(field)) {
|
|
11042
11057
|
return field.length * getItemAlloc(item.elementLayout);
|
|
11043
11058
|
}
|
|
11059
|
+
} else if ('fields' in item) {
|
|
11060
|
+
// This is a `Structure` whose size needs to be recursively measured.
|
|
11061
|
+
return getAlloc({
|
|
11062
|
+
layout: item
|
|
11063
|
+
}, fields[item.property]);
|
|
11044
11064
|
} // Couldn't determine allocated size of layout
|
|
11045
11065
|
|
|
11046
11066
|
|
|
@@ -11087,6 +11107,129 @@ var solanaWeb3 = (function (exports) {
|
|
|
11087
11107
|
}
|
|
11088
11108
|
}
|
|
11089
11109
|
|
|
11110
|
+
function assert$1 (condition, message) {
|
|
11111
|
+
if (!condition) {
|
|
11112
|
+
throw new Error(message || 'Assertion failed');
|
|
11113
|
+
}
|
|
11114
|
+
}
|
|
11115
|
+
|
|
11116
|
+
class CompiledKeys {
|
|
11117
|
+
constructor(payer, keyMetaMap) {
|
|
11118
|
+
this.payer = void 0;
|
|
11119
|
+
this.keyMetaMap = void 0;
|
|
11120
|
+
this.payer = payer;
|
|
11121
|
+
this.keyMetaMap = keyMetaMap;
|
|
11122
|
+
}
|
|
11123
|
+
|
|
11124
|
+
static compile(instructions, payer) {
|
|
11125
|
+
const keyMetaMap = new Map();
|
|
11126
|
+
|
|
11127
|
+
const getOrInsertDefault = pubkey => {
|
|
11128
|
+
const address = pubkey.toBase58();
|
|
11129
|
+
let keyMeta = keyMetaMap.get(address);
|
|
11130
|
+
|
|
11131
|
+
if (keyMeta === undefined) {
|
|
11132
|
+
keyMeta = {
|
|
11133
|
+
isSigner: false,
|
|
11134
|
+
isWritable: false,
|
|
11135
|
+
isInvoked: false
|
|
11136
|
+
};
|
|
11137
|
+
keyMetaMap.set(address, keyMeta);
|
|
11138
|
+
}
|
|
11139
|
+
|
|
11140
|
+
return keyMeta;
|
|
11141
|
+
};
|
|
11142
|
+
|
|
11143
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
11144
|
+
payerKeyMeta.isSigner = true;
|
|
11145
|
+
payerKeyMeta.isWritable = true;
|
|
11146
|
+
|
|
11147
|
+
for (const ix of instructions) {
|
|
11148
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
11149
|
+
|
|
11150
|
+
for (const accountMeta of ix.keys) {
|
|
11151
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
11152
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
11153
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
11154
|
+
}
|
|
11155
|
+
}
|
|
11156
|
+
|
|
11157
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
11158
|
+
}
|
|
11159
|
+
|
|
11160
|
+
getMessageComponents() {
|
|
11161
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
11162
|
+
assert$1(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
11163
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
11164
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
11165
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
11166
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
11167
|
+
const header = {
|
|
11168
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
11169
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
11170
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
11171
|
+
}; // sanity checks
|
|
11172
|
+
|
|
11173
|
+
{
|
|
11174
|
+
assert$1(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
11175
|
+
const [payerAddress] = writableSigners[0];
|
|
11176
|
+
assert$1(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
11177
|
+
}
|
|
11178
|
+
const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
|
|
11179
|
+
return [header, staticAccountKeys];
|
|
11180
|
+
}
|
|
11181
|
+
|
|
11182
|
+
extractTableLookup(lookupTable) {
|
|
11183
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
11184
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
11185
|
+
|
|
11186
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
11187
|
+
return;
|
|
11188
|
+
}
|
|
11189
|
+
|
|
11190
|
+
return [{
|
|
11191
|
+
accountKey: lookupTable.key,
|
|
11192
|
+
writableIndexes,
|
|
11193
|
+
readonlyIndexes
|
|
11194
|
+
}, {
|
|
11195
|
+
writable: drainedWritableKeys,
|
|
11196
|
+
readonly: drainedReadonlyKeys
|
|
11197
|
+
}];
|
|
11198
|
+
}
|
|
11199
|
+
/** @internal */
|
|
11200
|
+
|
|
11201
|
+
|
|
11202
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
11203
|
+
const lookupTableIndexes = new Array();
|
|
11204
|
+
const drainedKeys = new Array();
|
|
11205
|
+
|
|
11206
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
11207
|
+
if (keyMetaFilter(keyMeta)) {
|
|
11208
|
+
const key = new PublicKey(address);
|
|
11209
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
11210
|
+
|
|
11211
|
+
if (lookupTableIndex >= 0) {
|
|
11212
|
+
assert$1(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
11213
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
11214
|
+
drainedKeys.push(key);
|
|
11215
|
+
this.keyMetaMap.delete(address);
|
|
11216
|
+
}
|
|
11217
|
+
}
|
|
11218
|
+
}
|
|
11219
|
+
|
|
11220
|
+
return [lookupTableIndexes, drainedKeys];
|
|
11221
|
+
}
|
|
11222
|
+
|
|
11223
|
+
}
|
|
11224
|
+
|
|
11225
|
+
/**
|
|
11226
|
+
* An instruction to execute by a program
|
|
11227
|
+
*
|
|
11228
|
+
* @property {number} programIdIndex
|
|
11229
|
+
* @property {number[]} accounts
|
|
11230
|
+
* @property {string} data
|
|
11231
|
+
*/
|
|
11232
|
+
|
|
11090
11233
|
/**
|
|
11091
11234
|
* List of instructions to be processed atomically
|
|
11092
11235
|
*/
|
|
@@ -11124,6 +11267,27 @@ var solanaWeb3 = (function (exports) {
|
|
|
11124
11267
|
return [];
|
|
11125
11268
|
}
|
|
11126
11269
|
|
|
11270
|
+
getAccountKeys() {
|
|
11271
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
11272
|
+
}
|
|
11273
|
+
|
|
11274
|
+
static compile(args) {
|
|
11275
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
11276
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
11277
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
11278
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
11279
|
+
programIdIndex: ix.programIdIndex,
|
|
11280
|
+
accounts: ix.accountKeyIndexes,
|
|
11281
|
+
data: bs58$1.encode(ix.data)
|
|
11282
|
+
}));
|
|
11283
|
+
return new Message({
|
|
11284
|
+
header,
|
|
11285
|
+
accountKeys: staticAccountKeys,
|
|
11286
|
+
recentBlockhash: args.recentBlockhash,
|
|
11287
|
+
instructions
|
|
11288
|
+
});
|
|
11289
|
+
}
|
|
11290
|
+
|
|
11127
11291
|
isAccountSigner(index) {
|
|
11128
11292
|
return index < this.header.numRequiredSignatures;
|
|
11129
11293
|
}
|
|
@@ -11213,7 +11377,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
11213
11377
|
for (let i = 0; i < accountCount; i++) {
|
|
11214
11378
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
11215
11379
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
11216
|
-
accountKeys.push(
|
|
11380
|
+
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
11217
11381
|
}
|
|
11218
11382
|
|
|
11219
11383
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -11252,151 +11416,97 @@ var solanaWeb3 = (function (exports) {
|
|
|
11252
11416
|
|
|
11253
11417
|
}
|
|
11254
11418
|
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
}
|
|
11259
|
-
}
|
|
11419
|
+
/**
|
|
11420
|
+
* Message constructor arguments
|
|
11421
|
+
*/
|
|
11260
11422
|
|
|
11261
|
-
class
|
|
11262
|
-
constructor(
|
|
11263
|
-
this.
|
|
11264
|
-
this.
|
|
11265
|
-
this.
|
|
11266
|
-
this.
|
|
11423
|
+
class MessageV0 {
|
|
11424
|
+
constructor(args) {
|
|
11425
|
+
this.header = void 0;
|
|
11426
|
+
this.staticAccountKeys = void 0;
|
|
11427
|
+
this.recentBlockhash = void 0;
|
|
11428
|
+
this.compiledInstructions = void 0;
|
|
11429
|
+
this.addressTableLookups = void 0;
|
|
11430
|
+
this.header = args.header;
|
|
11431
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
11432
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
11433
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
11434
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
11267
11435
|
}
|
|
11268
11436
|
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
const getOrInsertDefault = pubkey => {
|
|
11273
|
-
const address = pubkey.toBase58();
|
|
11274
|
-
let keyMeta = keyMetaMap.get(address);
|
|
11437
|
+
get version() {
|
|
11438
|
+
return 0;
|
|
11439
|
+
}
|
|
11275
11440
|
|
|
11276
|
-
|
|
11277
|
-
|
|
11278
|
-
isSigner: false,
|
|
11279
|
-
isWritable: false,
|
|
11280
|
-
isInvoked: false
|
|
11281
|
-
};
|
|
11282
|
-
keyMetaMap.set(address, keyMeta);
|
|
11283
|
-
}
|
|
11441
|
+
get numAccountKeysFromLookups() {
|
|
11442
|
+
let count = 0;
|
|
11284
11443
|
|
|
11285
|
-
|
|
11286
|
-
|
|
11444
|
+
for (const lookup of this.addressTableLookups) {
|
|
11445
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
11446
|
+
}
|
|
11287
11447
|
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
payerKeyMeta.isWritable = true;
|
|
11448
|
+
return count;
|
|
11449
|
+
}
|
|
11291
11450
|
|
|
11292
|
-
|
|
11293
|
-
|
|
11451
|
+
getAccountKeys(args) {
|
|
11452
|
+
let accountKeysFromLookups;
|
|
11294
11453
|
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
11454
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
11455
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
11456
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
11299
11457
|
}
|
|
11458
|
+
|
|
11459
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
11460
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
11461
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
11462
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
11463
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
11300
11464
|
}
|
|
11301
11465
|
|
|
11302
|
-
return new
|
|
11466
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
11303
11467
|
}
|
|
11304
11468
|
|
|
11305
|
-
|
|
11306
|
-
const
|
|
11307
|
-
|
|
11308
|
-
|
|
11309
|
-
|
|
11310
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
11311
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
11312
|
-
const header = {
|
|
11313
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
11314
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
11315
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
11316
|
-
}; // sanity checks
|
|
11469
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
11470
|
+
const accountKeysFromLookups = {
|
|
11471
|
+
writable: [],
|
|
11472
|
+
readonly: []
|
|
11473
|
+
};
|
|
11317
11474
|
|
|
11318
|
-
{
|
|
11319
|
-
|
|
11320
|
-
const [payerAddress] = writableSigners[0];
|
|
11321
|
-
assert$1(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
11322
|
-
}
|
|
11323
|
-
const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
|
|
11324
|
-
return [header, staticAccountKeys];
|
|
11325
|
-
}
|
|
11475
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
11476
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
11326
11477
|
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11478
|
+
if (!tableAccount) {
|
|
11479
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
11480
|
+
}
|
|
11330
11481
|
|
|
11331
|
-
|
|
11332
|
-
|
|
11482
|
+
for (const index of tableLookup.writableIndexes) {
|
|
11483
|
+
if (index < tableAccount.state.addresses.length) {
|
|
11484
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
11485
|
+
} else {
|
|
11486
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
11487
|
+
}
|
|
11488
|
+
}
|
|
11489
|
+
|
|
11490
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
11491
|
+
if (index < tableAccount.state.addresses.length) {
|
|
11492
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
11493
|
+
} else {
|
|
11494
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
11495
|
+
}
|
|
11496
|
+
}
|
|
11333
11497
|
}
|
|
11334
11498
|
|
|
11335
|
-
return
|
|
11336
|
-
accountKey: lookupTable.key,
|
|
11337
|
-
writableIndexes,
|
|
11338
|
-
readonlyIndexes
|
|
11339
|
-
}, {
|
|
11340
|
-
writable: drainedWritableKeys,
|
|
11341
|
-
readonly: drainedReadonlyKeys
|
|
11342
|
-
}];
|
|
11499
|
+
return accountKeysFromLookups;
|
|
11343
11500
|
}
|
|
11344
|
-
/** @internal */
|
|
11345
11501
|
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
const
|
|
11349
|
-
const
|
|
11350
|
-
|
|
11351
|
-
|
|
11352
|
-
|
|
11353
|
-
|
|
11354
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
11355
|
-
|
|
11356
|
-
if (lookupTableIndex >= 0) {
|
|
11357
|
-
assert$1(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
11358
|
-
lookupTableIndexes.push(lookupTableIndex);
|
|
11359
|
-
drainedKeys.push(key);
|
|
11360
|
-
this.keyMetaMap.delete(address);
|
|
11361
|
-
}
|
|
11362
|
-
}
|
|
11363
|
-
}
|
|
11364
|
-
|
|
11365
|
-
return [lookupTableIndexes, drainedKeys];
|
|
11366
|
-
}
|
|
11367
|
-
|
|
11368
|
-
}
|
|
11369
|
-
|
|
11370
|
-
/**
|
|
11371
|
-
* Message constructor arguments
|
|
11372
|
-
*/
|
|
11373
|
-
|
|
11374
|
-
class MessageV0 {
|
|
11375
|
-
constructor(args) {
|
|
11376
|
-
this.header = void 0;
|
|
11377
|
-
this.staticAccountKeys = void 0;
|
|
11378
|
-
this.recentBlockhash = void 0;
|
|
11379
|
-
this.compiledInstructions = void 0;
|
|
11380
|
-
this.addressTableLookups = void 0;
|
|
11381
|
-
this.header = args.header;
|
|
11382
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
11383
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
11384
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
11385
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
11386
|
-
}
|
|
11387
|
-
|
|
11388
|
-
get version() {
|
|
11389
|
-
return 0;
|
|
11390
|
-
}
|
|
11391
|
-
|
|
11392
|
-
static compile(args) {
|
|
11393
|
-
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
11394
|
-
const addressTableLookups = new Array();
|
|
11395
|
-
const accountKeysFromLookups = {
|
|
11396
|
-
writable: new Array(),
|
|
11397
|
-
readonly: new Array()
|
|
11398
|
-
};
|
|
11399
|
-
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
11502
|
+
static compile(args) {
|
|
11503
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
11504
|
+
const addressTableLookups = new Array();
|
|
11505
|
+
const accountKeysFromLookups = {
|
|
11506
|
+
writable: new Array(),
|
|
11507
|
+
readonly: new Array()
|
|
11508
|
+
};
|
|
11509
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
11400
11510
|
|
|
11401
11511
|
for (const lookupTable of lookupTableAccounts) {
|
|
11402
11512
|
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
@@ -12318,6 +12428,108 @@ var solanaWeb3 = (function (exports) {
|
|
|
12318
12428
|
|
|
12319
12429
|
}
|
|
12320
12430
|
|
|
12431
|
+
class TransactionMessage {
|
|
12432
|
+
constructor(args) {
|
|
12433
|
+
this.payerKey = void 0;
|
|
12434
|
+
this.instructions = void 0;
|
|
12435
|
+
this.recentBlockhash = void 0;
|
|
12436
|
+
this.payerKey = args.payerKey;
|
|
12437
|
+
this.instructions = args.instructions;
|
|
12438
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
12439
|
+
}
|
|
12440
|
+
|
|
12441
|
+
static decompile(message, args) {
|
|
12442
|
+
const {
|
|
12443
|
+
header,
|
|
12444
|
+
compiledInstructions,
|
|
12445
|
+
recentBlockhash
|
|
12446
|
+
} = message;
|
|
12447
|
+
const {
|
|
12448
|
+
numRequiredSignatures,
|
|
12449
|
+
numReadonlySignedAccounts,
|
|
12450
|
+
numReadonlyUnsignedAccounts
|
|
12451
|
+
} = header;
|
|
12452
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
12453
|
+
assert$1(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
12454
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
12455
|
+
assert$1(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
12456
|
+
const accountKeys = message.getAccountKeys(args);
|
|
12457
|
+
const payerKey = accountKeys.get(0);
|
|
12458
|
+
|
|
12459
|
+
if (payerKey === undefined) {
|
|
12460
|
+
throw new Error('Failed to decompile message because no account keys were found');
|
|
12461
|
+
}
|
|
12462
|
+
|
|
12463
|
+
const instructions = [];
|
|
12464
|
+
|
|
12465
|
+
for (const compiledIx of compiledInstructions) {
|
|
12466
|
+
const keys = [];
|
|
12467
|
+
|
|
12468
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
12469
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
12470
|
+
|
|
12471
|
+
if (pubkey === undefined) {
|
|
12472
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
12473
|
+
}
|
|
12474
|
+
|
|
12475
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
12476
|
+
let isWritable;
|
|
12477
|
+
|
|
12478
|
+
if (isSigner) {
|
|
12479
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
12480
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
12481
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
12482
|
+
} else {
|
|
12483
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
12484
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
12485
|
+
}
|
|
12486
|
+
|
|
12487
|
+
keys.push({
|
|
12488
|
+
pubkey,
|
|
12489
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
12490
|
+
isWritable
|
|
12491
|
+
});
|
|
12492
|
+
}
|
|
12493
|
+
|
|
12494
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
12495
|
+
|
|
12496
|
+
if (programId === undefined) {
|
|
12497
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
12498
|
+
}
|
|
12499
|
+
|
|
12500
|
+
instructions.push(new TransactionInstruction({
|
|
12501
|
+
programId,
|
|
12502
|
+
data: toBuffer(compiledIx.data),
|
|
12503
|
+
keys
|
|
12504
|
+
}));
|
|
12505
|
+
}
|
|
12506
|
+
|
|
12507
|
+
return new TransactionMessage({
|
|
12508
|
+
payerKey,
|
|
12509
|
+
instructions,
|
|
12510
|
+
recentBlockhash
|
|
12511
|
+
});
|
|
12512
|
+
}
|
|
12513
|
+
|
|
12514
|
+
compileToLegacyMessage() {
|
|
12515
|
+
return Message.compile({
|
|
12516
|
+
payerKey: this.payerKey,
|
|
12517
|
+
recentBlockhash: this.recentBlockhash,
|
|
12518
|
+
instructions: this.instructions
|
|
12519
|
+
});
|
|
12520
|
+
}
|
|
12521
|
+
|
|
12522
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
12523
|
+
return MessageV0.compile({
|
|
12524
|
+
payerKey: this.payerKey,
|
|
12525
|
+
recentBlockhash: this.recentBlockhash,
|
|
12526
|
+
instructions: this.instructions,
|
|
12527
|
+
addressLookupTableAccounts
|
|
12528
|
+
});
|
|
12529
|
+
}
|
|
12530
|
+
|
|
12531
|
+
}
|
|
12532
|
+
|
|
12321
12533
|
/**
|
|
12322
12534
|
* Versioned transaction class
|
|
12323
12535
|
*/
|
|
@@ -19784,12 +19996,46 @@ var solanaWeb3 = (function (exports) {
|
|
|
19784
19996
|
|
|
19785
19997
|
return res.result;
|
|
19786
19998
|
}
|
|
19999
|
+
/**
|
|
20000
|
+
* Simulate a transaction
|
|
20001
|
+
*
|
|
20002
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
20003
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
20004
|
+
*/
|
|
20005
|
+
|
|
20006
|
+
|
|
19787
20007
|
/**
|
|
19788
20008
|
* Simulate a transaction
|
|
19789
20009
|
*/
|
|
20010
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
20011
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
20012
|
+
if ('message' in transactionOrMessage) {
|
|
20013
|
+
const versionedTx = transactionOrMessage;
|
|
20014
|
+
const wireTransaction = versionedTx.serialize();
|
|
20015
|
+
const encodedTransaction = buffer.Buffer.from(wireTransaction).toString('base64');
|
|
20016
|
+
|
|
20017
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
20018
|
+
throw new Error('Invalid arguments');
|
|
20019
|
+
}
|
|
20020
|
+
|
|
20021
|
+
const config = configOrSigners || {};
|
|
20022
|
+
config.encoding = 'base64';
|
|
20023
|
+
|
|
20024
|
+
if (!('commitment' in config)) {
|
|
20025
|
+
config.commitment = this.commitment;
|
|
20026
|
+
}
|
|
20027
|
+
|
|
20028
|
+
const args = [encodedTransaction, config];
|
|
20029
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
20030
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
20031
|
+
|
|
20032
|
+
if ('error' in res) {
|
|
20033
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
20034
|
+
}
|
|
19790
20035
|
|
|
20036
|
+
return res.result;
|
|
20037
|
+
}
|
|
19791
20038
|
|
|
19792
|
-
async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
|
|
19793
20039
|
let transaction;
|
|
19794
20040
|
|
|
19795
20041
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -19805,6 +20051,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
19805
20051
|
transaction._message = transaction._json = undefined;
|
|
19806
20052
|
}
|
|
19807
20053
|
|
|
20054
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
20055
|
+
throw new Error('Invalid arguments');
|
|
20056
|
+
}
|
|
20057
|
+
|
|
20058
|
+
const signers = configOrSigners;
|
|
20059
|
+
|
|
19808
20060
|
if (transaction.nonceInfo && signers) {
|
|
19809
20061
|
transaction.sign(...signers);
|
|
19810
20062
|
} else {
|
|
@@ -19885,12 +20137,34 @@ var solanaWeb3 = (function (exports) {
|
|
|
19885
20137
|
|
|
19886
20138
|
return res.result;
|
|
19887
20139
|
}
|
|
20140
|
+
/**
|
|
20141
|
+
* Sign and send a transaction
|
|
20142
|
+
*
|
|
20143
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
20144
|
+
* VersionedTransaction}
|
|
20145
|
+
*/
|
|
20146
|
+
|
|
20147
|
+
|
|
19888
20148
|
/**
|
|
19889
20149
|
* Sign and send a transaction
|
|
19890
20150
|
*/
|
|
20151
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
20152
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
20153
|
+
if ('message' in transaction) {
|
|
20154
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
20155
|
+
throw new Error('Invalid arguments');
|
|
20156
|
+
}
|
|
19891
20157
|
|
|
20158
|
+
const wireTransaction = transaction.serialize();
|
|
20159
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
20160
|
+
}
|
|
20161
|
+
|
|
20162
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
20163
|
+
throw new Error('Invalid arguments');
|
|
20164
|
+
}
|
|
20165
|
+
|
|
20166
|
+
const signers = signersOrOptions;
|
|
19892
20167
|
|
|
19893
|
-
async sendTransaction(transaction, signers, options) {
|
|
19894
20168
|
if (transaction.nonceInfo) {
|
|
19895
20169
|
transaction.sign(...signers);
|
|
19896
20170
|
} else {
|
|
@@ -21375,662 +21649,208 @@ var solanaWeb3 = (function (exports) {
|
|
|
21375
21649
|
}
|
|
21376
21650
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
21377
21651
|
|
|
21378
|
-
|
|
21379
|
-
|
|
21652
|
+
// Various per round constants calculations
|
|
21653
|
+
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
|
|
21654
|
+
const _0n$1 = BigInt(0);
|
|
21655
|
+
const _1n$1 = BigInt(1);
|
|
21656
|
+
const _2n$1 = BigInt(2);
|
|
21657
|
+
const _7n = BigInt(7);
|
|
21658
|
+
const _256n = BigInt(256);
|
|
21659
|
+
const _0x71n = BigInt(0x71);
|
|
21660
|
+
for (let round = 0, R = _1n$1, x = 1, y = 0; round < 24; round++) {
|
|
21661
|
+
// Pi
|
|
21662
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
21663
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
21664
|
+
// Rotational
|
|
21665
|
+
SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
|
|
21666
|
+
// Iota
|
|
21667
|
+
let t = _0n$1;
|
|
21668
|
+
for (let j = 0; j < 7; j++) {
|
|
21669
|
+
R = ((R << _1n$1) ^ ((R >> _7n) * _0x71n)) % _256n;
|
|
21670
|
+
if (R & _2n$1)
|
|
21671
|
+
t ^= _1n$1 << ((_1n$1 << BigInt(j)) - _1n$1);
|
|
21672
|
+
}
|
|
21673
|
+
_SHA3_IOTA.push(t);
|
|
21674
|
+
}
|
|
21675
|
+
const [SHA3_IOTA_H, SHA3_IOTA_L] = u64$2.split(_SHA3_IOTA, true);
|
|
21676
|
+
// Left rotation (without 0, 32, 64)
|
|
21677
|
+
const rotlH = (h, l, s) => s > 32 ? u64$2.rotlBH(h, l, s) : u64$2.rotlSH(h, l, s);
|
|
21678
|
+
const rotlL = (h, l, s) => s > 32 ? u64$2.rotlBL(h, l, s) : u64$2.rotlSL(h, l, s);
|
|
21679
|
+
// Same as keccakf1600, but allows to skip some rounds
|
|
21680
|
+
function keccakP(s, rounds = 24) {
|
|
21681
|
+
const B = new Uint32Array(5 * 2);
|
|
21682
|
+
// NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
|
|
21683
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
21684
|
+
// Theta θ
|
|
21685
|
+
for (let x = 0; x < 10; x++)
|
|
21686
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
21687
|
+
for (let x = 0; x < 10; x += 2) {
|
|
21688
|
+
const idx1 = (x + 8) % 10;
|
|
21689
|
+
const idx0 = (x + 2) % 10;
|
|
21690
|
+
const B0 = B[idx0];
|
|
21691
|
+
const B1 = B[idx0 + 1];
|
|
21692
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
21693
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
21694
|
+
for (let y = 0; y < 50; y += 10) {
|
|
21695
|
+
s[x + y] ^= Th;
|
|
21696
|
+
s[x + y + 1] ^= Tl;
|
|
21697
|
+
}
|
|
21698
|
+
}
|
|
21699
|
+
// Rho (ρ) and Pi (π)
|
|
21700
|
+
let curH = s[2];
|
|
21701
|
+
let curL = s[3];
|
|
21702
|
+
for (let t = 0; t < 24; t++) {
|
|
21703
|
+
const shift = SHA3_ROTL[t];
|
|
21704
|
+
const Th = rotlH(curH, curL, shift);
|
|
21705
|
+
const Tl = rotlL(curH, curL, shift);
|
|
21706
|
+
const PI = SHA3_PI[t];
|
|
21707
|
+
curH = s[PI];
|
|
21708
|
+
curL = s[PI + 1];
|
|
21709
|
+
s[PI] = Th;
|
|
21710
|
+
s[PI + 1] = Tl;
|
|
21711
|
+
}
|
|
21712
|
+
// Chi (χ)
|
|
21713
|
+
for (let y = 0; y < 50; y += 10) {
|
|
21714
|
+
for (let x = 0; x < 10; x++)
|
|
21715
|
+
B[x] = s[y + x];
|
|
21716
|
+
for (let x = 0; x < 10; x++)
|
|
21717
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
21718
|
+
}
|
|
21719
|
+
// Iota (ι)
|
|
21720
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
21721
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
21722
|
+
}
|
|
21723
|
+
B.fill(0);
|
|
21724
|
+
}
|
|
21725
|
+
class Keccak extends Hash {
|
|
21726
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
21727
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
21728
|
+
super();
|
|
21729
|
+
this.blockLen = blockLen;
|
|
21730
|
+
this.suffix = suffix;
|
|
21731
|
+
this.outputLen = outputLen;
|
|
21732
|
+
this.enableXOF = enableXOF;
|
|
21733
|
+
this.rounds = rounds;
|
|
21734
|
+
this.pos = 0;
|
|
21735
|
+
this.posOut = 0;
|
|
21736
|
+
this.finished = false;
|
|
21737
|
+
this.destroyed = false;
|
|
21738
|
+
// Can be passed from user as dkLen
|
|
21739
|
+
assert$3.number(outputLen);
|
|
21740
|
+
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
|
21741
|
+
if (0 >= this.blockLen || this.blockLen >= 200)
|
|
21742
|
+
throw new Error('Sha3 supports only keccak-f1600 function');
|
|
21743
|
+
this.state = new Uint8Array(200);
|
|
21744
|
+
this.state32 = u32$1(this.state);
|
|
21745
|
+
}
|
|
21746
|
+
keccak() {
|
|
21747
|
+
keccakP(this.state32, this.rounds);
|
|
21748
|
+
this.posOut = 0;
|
|
21749
|
+
this.pos = 0;
|
|
21750
|
+
}
|
|
21751
|
+
update(data) {
|
|
21752
|
+
assert$3.exists(this);
|
|
21753
|
+
const { blockLen, state } = this;
|
|
21754
|
+
data = toBytes(data);
|
|
21755
|
+
const len = data.length;
|
|
21756
|
+
for (let pos = 0; pos < len;) {
|
|
21757
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
21758
|
+
for (let i = 0; i < take; i++)
|
|
21759
|
+
state[this.pos++] ^= data[pos++];
|
|
21760
|
+
if (this.pos === blockLen)
|
|
21761
|
+
this.keccak();
|
|
21762
|
+
}
|
|
21763
|
+
return this;
|
|
21764
|
+
}
|
|
21765
|
+
finish() {
|
|
21766
|
+
if (this.finished)
|
|
21767
|
+
return;
|
|
21768
|
+
this.finished = true;
|
|
21769
|
+
const { state, suffix, pos, blockLen } = this;
|
|
21770
|
+
// Do the padding
|
|
21771
|
+
state[pos] ^= suffix;
|
|
21772
|
+
if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
|
|
21773
|
+
this.keccak();
|
|
21774
|
+
state[blockLen - 1] ^= 0x80;
|
|
21775
|
+
this.keccak();
|
|
21776
|
+
}
|
|
21777
|
+
writeInto(out) {
|
|
21778
|
+
assert$3.exists(this, false);
|
|
21779
|
+
assert$3.bytes(out);
|
|
21780
|
+
this.finish();
|
|
21781
|
+
const bufferOut = this.state;
|
|
21782
|
+
const { blockLen } = this;
|
|
21783
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
21784
|
+
if (this.posOut >= blockLen)
|
|
21785
|
+
this.keccak();
|
|
21786
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
21787
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
21788
|
+
this.posOut += take;
|
|
21789
|
+
pos += take;
|
|
21790
|
+
}
|
|
21791
|
+
return out;
|
|
21792
|
+
}
|
|
21793
|
+
xofInto(out) {
|
|
21794
|
+
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
|
|
21795
|
+
if (!this.enableXOF)
|
|
21796
|
+
throw new Error('XOF is not possible for this instance');
|
|
21797
|
+
return this.writeInto(out);
|
|
21798
|
+
}
|
|
21799
|
+
xof(bytes) {
|
|
21800
|
+
assert$3.number(bytes);
|
|
21801
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
21802
|
+
}
|
|
21803
|
+
digestInto(out) {
|
|
21804
|
+
assert$3.output(out, this);
|
|
21805
|
+
if (this.finished)
|
|
21806
|
+
throw new Error('digest() was already called');
|
|
21807
|
+
this.writeInto(out);
|
|
21808
|
+
this.destroy();
|
|
21809
|
+
return out;
|
|
21810
|
+
}
|
|
21811
|
+
digest() {
|
|
21812
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
21813
|
+
}
|
|
21814
|
+
destroy() {
|
|
21815
|
+
this.destroyed = true;
|
|
21816
|
+
this.state.fill(0);
|
|
21817
|
+
}
|
|
21818
|
+
_cloneInto(to) {
|
|
21819
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
21820
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
21821
|
+
to.state32.set(this.state32);
|
|
21822
|
+
to.pos = this.pos;
|
|
21823
|
+
to.posOut = this.posOut;
|
|
21824
|
+
to.finished = this.finished;
|
|
21825
|
+
to.rounds = rounds;
|
|
21826
|
+
// Suffix can change in cSHAKE
|
|
21827
|
+
to.suffix = suffix;
|
|
21828
|
+
to.outputLen = outputLen;
|
|
21829
|
+
to.enableXOF = enableXOF;
|
|
21830
|
+
to.destroyed = this.destroyed;
|
|
21831
|
+
return to;
|
|
21832
|
+
}
|
|
21833
|
+
}
|
|
21834
|
+
const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
|
|
21835
|
+
gen(0x06, 144, 224 / 8);
|
|
21380
21836
|
/**
|
|
21381
|
-
*
|
|
21382
|
-
*
|
|
21383
|
-
* @version 0.8.0
|
|
21384
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
21385
|
-
* @copyright Chen, Yi-Cyuan 2015-2018
|
|
21386
|
-
* @license MIT
|
|
21837
|
+
* SHA3-256 hash function
|
|
21838
|
+
* @param message - that would be hashed
|
|
21387
21839
|
*/
|
|
21388
|
-
|
|
21389
|
-
(
|
|
21390
|
-
|
|
21391
|
-
|
|
21392
|
-
|
|
21393
|
-
|
|
21394
|
-
|
|
21395
|
-
|
|
21396
|
-
|
|
21397
|
-
|
|
21398
|
-
|
|
21399
|
-
|
|
21400
|
-
|
|
21401
|
-
|
|
21402
|
-
if (NODE_JS) {
|
|
21403
|
-
root = commonjsGlobal;
|
|
21404
|
-
} else if (WEB_WORKER) {
|
|
21405
|
-
root = self;
|
|
21406
|
-
}
|
|
21407
|
-
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && 'object' === 'object' && module.exports;
|
|
21408
|
-
var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
21409
|
-
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
21410
|
-
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
|
21411
|
-
var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
|
|
21412
|
-
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
|
21413
|
-
var PADDING = [6, 1536, 393216, 100663296];
|
|
21414
|
-
var SHIFT = [0, 8, 16, 24];
|
|
21415
|
-
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
|
|
21416
|
-
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
|
|
21417
|
-
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
|
|
21418
|
-
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
|
|
21419
|
-
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
|
|
21420
|
-
var BITS = [224, 256, 384, 512];
|
|
21421
|
-
var SHAKE_BITS = [128, 256];
|
|
21422
|
-
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest'];
|
|
21423
|
-
var CSHAKE_BYTEPAD = {
|
|
21424
|
-
'128': 168,
|
|
21425
|
-
'256': 136
|
|
21426
|
-
};
|
|
21427
|
-
|
|
21428
|
-
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
|
|
21429
|
-
Array.isArray = function (obj) {
|
|
21430
|
-
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
21431
|
-
};
|
|
21432
|
-
}
|
|
21433
|
-
|
|
21434
|
-
if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
21435
|
-
ArrayBuffer.isView = function (obj) {
|
|
21436
|
-
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
21437
|
-
};
|
|
21438
|
-
}
|
|
21439
|
-
|
|
21440
|
-
var createOutputMethod = function (bits, padding, outputType) {
|
|
21441
|
-
return function (message) {
|
|
21442
|
-
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
21443
|
-
};
|
|
21444
|
-
};
|
|
21445
|
-
|
|
21446
|
-
var createShakeOutputMethod = function (bits, padding, outputType) {
|
|
21447
|
-
return function (message, outputBits) {
|
|
21448
|
-
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
|
21449
|
-
};
|
|
21450
|
-
};
|
|
21451
|
-
|
|
21452
|
-
var createCshakeOutputMethod = function (bits, padding, outputType) {
|
|
21453
|
-
return function (message, outputBits, n, s) {
|
|
21454
|
-
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
|
|
21455
|
-
};
|
|
21456
|
-
};
|
|
21457
|
-
|
|
21458
|
-
var createKmacOutputMethod = function (bits, padding, outputType) {
|
|
21459
|
-
return function (key, message, outputBits, s) {
|
|
21460
|
-
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
|
21461
|
-
};
|
|
21462
|
-
};
|
|
21463
|
-
|
|
21464
|
-
var createOutputMethods = function (method, createMethod, bits, padding) {
|
|
21465
|
-
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
21466
|
-
var type = OUTPUT_TYPES[i];
|
|
21467
|
-
method[type] = createMethod(bits, padding, type);
|
|
21468
|
-
}
|
|
21469
|
-
return method;
|
|
21470
|
-
};
|
|
21471
|
-
|
|
21472
|
-
var createMethod = function (bits, padding) {
|
|
21473
|
-
var method = createOutputMethod(bits, padding, 'hex');
|
|
21474
|
-
method.create = function () {
|
|
21475
|
-
return new Keccak(bits, padding, bits);
|
|
21476
|
-
};
|
|
21477
|
-
method.update = function (message) {
|
|
21478
|
-
return method.create().update(message);
|
|
21479
|
-
};
|
|
21480
|
-
return createOutputMethods(method, createOutputMethod, bits, padding);
|
|
21481
|
-
};
|
|
21482
|
-
|
|
21483
|
-
var createShakeMethod = function (bits, padding) {
|
|
21484
|
-
var method = createShakeOutputMethod(bits, padding, 'hex');
|
|
21485
|
-
method.create = function (outputBits) {
|
|
21486
|
-
return new Keccak(bits, padding, outputBits);
|
|
21487
|
-
};
|
|
21488
|
-
method.update = function (message, outputBits) {
|
|
21489
|
-
return method.create(outputBits).update(message);
|
|
21490
|
-
};
|
|
21491
|
-
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
|
|
21492
|
-
};
|
|
21493
|
-
|
|
21494
|
-
var createCshakeMethod = function (bits, padding) {
|
|
21495
|
-
var w = CSHAKE_BYTEPAD[bits];
|
|
21496
|
-
var method = createCshakeOutputMethod(bits, padding, 'hex');
|
|
21497
|
-
method.create = function (outputBits, n, s) {
|
|
21498
|
-
if (!n && !s) {
|
|
21499
|
-
return methods['shake' + bits].create(outputBits);
|
|
21500
|
-
} else {
|
|
21501
|
-
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
|
|
21502
|
-
}
|
|
21503
|
-
};
|
|
21504
|
-
method.update = function (message, outputBits, n, s) {
|
|
21505
|
-
return method.create(outputBits, n, s).update(message);
|
|
21506
|
-
};
|
|
21507
|
-
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
|
21508
|
-
};
|
|
21509
|
-
|
|
21510
|
-
var createKmacMethod = function (bits, padding) {
|
|
21511
|
-
var w = CSHAKE_BYTEPAD[bits];
|
|
21512
|
-
var method = createKmacOutputMethod(bits, padding, 'hex');
|
|
21513
|
-
method.create = function (key, outputBits, s) {
|
|
21514
|
-
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
21515
|
-
};
|
|
21516
|
-
method.update = function (key, message, outputBits, s) {
|
|
21517
|
-
return method.create(key, outputBits, s).update(message);
|
|
21518
|
-
};
|
|
21519
|
-
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
|
21520
|
-
};
|
|
21521
|
-
|
|
21522
|
-
var algorithms = [
|
|
21523
|
-
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
|
21524
|
-
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
21525
|
-
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
21526
|
-
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
21527
|
-
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
|
21528
|
-
];
|
|
21529
|
-
|
|
21530
|
-
var methods = {}, methodNames = [];
|
|
21531
|
-
|
|
21532
|
-
for (var i = 0; i < algorithms.length; ++i) {
|
|
21533
|
-
var algorithm = algorithms[i];
|
|
21534
|
-
var bits = algorithm.bits;
|
|
21535
|
-
for (var j = 0; j < bits.length; ++j) {
|
|
21536
|
-
var methodName = algorithm.name + '_' + bits[j];
|
|
21537
|
-
methodNames.push(methodName);
|
|
21538
|
-
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
|
|
21539
|
-
if (algorithm.name !== 'sha3') {
|
|
21540
|
-
var newMethodName = algorithm.name + bits[j];
|
|
21541
|
-
methodNames.push(newMethodName);
|
|
21542
|
-
methods[newMethodName] = methods[methodName];
|
|
21543
|
-
}
|
|
21544
|
-
}
|
|
21545
|
-
}
|
|
21546
|
-
|
|
21547
|
-
function Keccak(bits, padding, outputBits) {
|
|
21548
|
-
this.blocks = [];
|
|
21549
|
-
this.s = [];
|
|
21550
|
-
this.padding = padding;
|
|
21551
|
-
this.outputBits = outputBits;
|
|
21552
|
-
this.reset = true;
|
|
21553
|
-
this.finalized = false;
|
|
21554
|
-
this.block = 0;
|
|
21555
|
-
this.start = 0;
|
|
21556
|
-
this.blockCount = (1600 - (bits << 1)) >> 5;
|
|
21557
|
-
this.byteCount = this.blockCount << 2;
|
|
21558
|
-
this.outputBlocks = outputBits >> 5;
|
|
21559
|
-
this.extraBytes = (outputBits & 31) >> 3;
|
|
21560
|
-
|
|
21561
|
-
for (var i = 0; i < 50; ++i) {
|
|
21562
|
-
this.s[i] = 0;
|
|
21563
|
-
}
|
|
21564
|
-
}
|
|
21565
|
-
|
|
21566
|
-
Keccak.prototype.update = function (message) {
|
|
21567
|
-
if (this.finalized) {
|
|
21568
|
-
throw new Error(FINALIZE_ERROR);
|
|
21569
|
-
}
|
|
21570
|
-
var notString, type = typeof message;
|
|
21571
|
-
if (type !== 'string') {
|
|
21572
|
-
if (type === 'object') {
|
|
21573
|
-
if (message === null) {
|
|
21574
|
-
throw new Error(INPUT_ERROR);
|
|
21575
|
-
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
21576
|
-
message = new Uint8Array(message);
|
|
21577
|
-
} else if (!Array.isArray(message)) {
|
|
21578
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
21579
|
-
throw new Error(INPUT_ERROR);
|
|
21580
|
-
}
|
|
21581
|
-
}
|
|
21582
|
-
} else {
|
|
21583
|
-
throw new Error(INPUT_ERROR);
|
|
21584
|
-
}
|
|
21585
|
-
notString = true;
|
|
21586
|
-
}
|
|
21587
|
-
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
|
|
21588
|
-
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
|
21589
|
-
|
|
21590
|
-
while (index < length) {
|
|
21591
|
-
if (this.reset) {
|
|
21592
|
-
this.reset = false;
|
|
21593
|
-
blocks[0] = this.block;
|
|
21594
|
-
for (i = 1; i < blockCount + 1; ++i) {
|
|
21595
|
-
blocks[i] = 0;
|
|
21596
|
-
}
|
|
21597
|
-
}
|
|
21598
|
-
if (notString) {
|
|
21599
|
-
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
21600
|
-
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
21601
|
-
}
|
|
21602
|
-
} else {
|
|
21603
|
-
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
21604
|
-
code = message.charCodeAt(index);
|
|
21605
|
-
if (code < 0x80) {
|
|
21606
|
-
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
21607
|
-
} else if (code < 0x800) {
|
|
21608
|
-
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
|
21609
|
-
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
21610
|
-
} else if (code < 0xd800 || code >= 0xe000) {
|
|
21611
|
-
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
|
21612
|
-
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
21613
|
-
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
21614
|
-
} else {
|
|
21615
|
-
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
21616
|
-
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
|
21617
|
-
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
21618
|
-
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
21619
|
-
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
21620
|
-
}
|
|
21621
|
-
}
|
|
21622
|
-
}
|
|
21623
|
-
this.lastByteIndex = i;
|
|
21624
|
-
if (i >= byteCount) {
|
|
21625
|
-
this.start = i - byteCount;
|
|
21626
|
-
this.block = blocks[blockCount];
|
|
21627
|
-
for (i = 0; i < blockCount; ++i) {
|
|
21628
|
-
s[i] ^= blocks[i];
|
|
21629
|
-
}
|
|
21630
|
-
f(s);
|
|
21631
|
-
this.reset = true;
|
|
21632
|
-
} else {
|
|
21633
|
-
this.start = i;
|
|
21634
|
-
}
|
|
21635
|
-
}
|
|
21636
|
-
return this;
|
|
21637
|
-
};
|
|
21638
|
-
|
|
21639
|
-
Keccak.prototype.encode = function (x, right) {
|
|
21640
|
-
var o = x & 255, n = 1;
|
|
21641
|
-
var bytes = [o];
|
|
21642
|
-
x = x >> 8;
|
|
21643
|
-
o = x & 255;
|
|
21644
|
-
while (o > 0) {
|
|
21645
|
-
bytes.unshift(o);
|
|
21646
|
-
x = x >> 8;
|
|
21647
|
-
o = x & 255;
|
|
21648
|
-
++n;
|
|
21649
|
-
}
|
|
21650
|
-
if (right) {
|
|
21651
|
-
bytes.push(n);
|
|
21652
|
-
} else {
|
|
21653
|
-
bytes.unshift(n);
|
|
21654
|
-
}
|
|
21655
|
-
this.update(bytes);
|
|
21656
|
-
return bytes.length;
|
|
21657
|
-
};
|
|
21658
|
-
|
|
21659
|
-
Keccak.prototype.encodeString = function (str) {
|
|
21660
|
-
var notString, type = typeof str;
|
|
21661
|
-
if (type !== 'string') {
|
|
21662
|
-
if (type === 'object') {
|
|
21663
|
-
if (str === null) {
|
|
21664
|
-
throw new Error(INPUT_ERROR);
|
|
21665
|
-
} else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
|
|
21666
|
-
str = new Uint8Array(str);
|
|
21667
|
-
} else if (!Array.isArray(str)) {
|
|
21668
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
|
|
21669
|
-
throw new Error(INPUT_ERROR);
|
|
21670
|
-
}
|
|
21671
|
-
}
|
|
21672
|
-
} else {
|
|
21673
|
-
throw new Error(INPUT_ERROR);
|
|
21674
|
-
}
|
|
21675
|
-
notString = true;
|
|
21676
|
-
}
|
|
21677
|
-
var bytes = 0, length = str.length;
|
|
21678
|
-
if (notString) {
|
|
21679
|
-
bytes = length;
|
|
21680
|
-
} else {
|
|
21681
|
-
for (var i = 0; i < str.length; ++i) {
|
|
21682
|
-
var code = str.charCodeAt(i);
|
|
21683
|
-
if (code < 0x80) {
|
|
21684
|
-
bytes += 1;
|
|
21685
|
-
} else if (code < 0x800) {
|
|
21686
|
-
bytes += 2;
|
|
21687
|
-
} else if (code < 0xd800 || code >= 0xe000) {
|
|
21688
|
-
bytes += 3;
|
|
21689
|
-
} else {
|
|
21690
|
-
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
|
21691
|
-
bytes += 4;
|
|
21692
|
-
}
|
|
21693
|
-
}
|
|
21694
|
-
}
|
|
21695
|
-
bytes += this.encode(bytes * 8);
|
|
21696
|
-
this.update(str);
|
|
21697
|
-
return bytes;
|
|
21698
|
-
};
|
|
21699
|
-
|
|
21700
|
-
Keccak.prototype.bytepad = function (strs, w) {
|
|
21701
|
-
var bytes = this.encode(w);
|
|
21702
|
-
for (var i = 0; i < strs.length; ++i) {
|
|
21703
|
-
bytes += this.encodeString(strs[i]);
|
|
21704
|
-
}
|
|
21705
|
-
var paddingBytes = w - bytes % w;
|
|
21706
|
-
var zeros = [];
|
|
21707
|
-
zeros.length = paddingBytes;
|
|
21708
|
-
this.update(zeros);
|
|
21709
|
-
return this;
|
|
21710
|
-
};
|
|
21711
|
-
|
|
21712
|
-
Keccak.prototype.finalize = function () {
|
|
21713
|
-
if (this.finalized) {
|
|
21714
|
-
return;
|
|
21715
|
-
}
|
|
21716
|
-
this.finalized = true;
|
|
21717
|
-
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
|
|
21718
|
-
blocks[i >> 2] |= this.padding[i & 3];
|
|
21719
|
-
if (this.lastByteIndex === this.byteCount) {
|
|
21720
|
-
blocks[0] = blocks[blockCount];
|
|
21721
|
-
for (i = 1; i < blockCount + 1; ++i) {
|
|
21722
|
-
blocks[i] = 0;
|
|
21723
|
-
}
|
|
21724
|
-
}
|
|
21725
|
-
blocks[blockCount - 1] |= 0x80000000;
|
|
21726
|
-
for (i = 0; i < blockCount; ++i) {
|
|
21727
|
-
s[i] ^= blocks[i];
|
|
21728
|
-
}
|
|
21729
|
-
f(s);
|
|
21730
|
-
};
|
|
21731
|
-
|
|
21732
|
-
Keccak.prototype.toString = Keccak.prototype.hex = function () {
|
|
21733
|
-
this.finalize();
|
|
21734
|
-
|
|
21735
|
-
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
21736
|
-
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
21737
|
-
var hex = '', block;
|
|
21738
|
-
while (j < outputBlocks) {
|
|
21739
|
-
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
21740
|
-
block = s[i];
|
|
21741
|
-
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
|
|
21742
|
-
HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
|
|
21743
|
-
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
|
21744
|
-
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
21745
|
-
}
|
|
21746
|
-
if (j % blockCount === 0) {
|
|
21747
|
-
f(s);
|
|
21748
|
-
i = 0;
|
|
21749
|
-
}
|
|
21750
|
-
}
|
|
21751
|
-
if (extraBytes) {
|
|
21752
|
-
block = s[i];
|
|
21753
|
-
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
|
|
21754
|
-
if (extraBytes > 1) {
|
|
21755
|
-
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
|
|
21756
|
-
}
|
|
21757
|
-
if (extraBytes > 2) {
|
|
21758
|
-
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
|
|
21759
|
-
}
|
|
21760
|
-
}
|
|
21761
|
-
return hex;
|
|
21762
|
-
};
|
|
21763
|
-
|
|
21764
|
-
Keccak.prototype.arrayBuffer = function () {
|
|
21765
|
-
this.finalize();
|
|
21766
|
-
|
|
21767
|
-
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
21768
|
-
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
21769
|
-
var bytes = this.outputBits >> 3;
|
|
21770
|
-
var buffer;
|
|
21771
|
-
if (extraBytes) {
|
|
21772
|
-
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
|
|
21773
|
-
} else {
|
|
21774
|
-
buffer = new ArrayBuffer(bytes);
|
|
21775
|
-
}
|
|
21776
|
-
var array = new Uint32Array(buffer);
|
|
21777
|
-
while (j < outputBlocks) {
|
|
21778
|
-
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
21779
|
-
array[j] = s[i];
|
|
21780
|
-
}
|
|
21781
|
-
if (j % blockCount === 0) {
|
|
21782
|
-
f(s);
|
|
21783
|
-
}
|
|
21784
|
-
}
|
|
21785
|
-
if (extraBytes) {
|
|
21786
|
-
array[i] = s[i];
|
|
21787
|
-
buffer = buffer.slice(0, bytes);
|
|
21788
|
-
}
|
|
21789
|
-
return buffer;
|
|
21790
|
-
};
|
|
21791
|
-
|
|
21792
|
-
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
|
|
21793
|
-
|
|
21794
|
-
Keccak.prototype.digest = Keccak.prototype.array = function () {
|
|
21795
|
-
this.finalize();
|
|
21796
|
-
|
|
21797
|
-
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
21798
|
-
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
21799
|
-
var array = [], offset, block;
|
|
21800
|
-
while (j < outputBlocks) {
|
|
21801
|
-
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
21802
|
-
offset = j << 2;
|
|
21803
|
-
block = s[i];
|
|
21804
|
-
array[offset] = block & 0xFF;
|
|
21805
|
-
array[offset + 1] = (block >> 8) & 0xFF;
|
|
21806
|
-
array[offset + 2] = (block >> 16) & 0xFF;
|
|
21807
|
-
array[offset + 3] = (block >> 24) & 0xFF;
|
|
21808
|
-
}
|
|
21809
|
-
if (j % blockCount === 0) {
|
|
21810
|
-
f(s);
|
|
21811
|
-
}
|
|
21812
|
-
}
|
|
21813
|
-
if (extraBytes) {
|
|
21814
|
-
offset = j << 2;
|
|
21815
|
-
block = s[i];
|
|
21816
|
-
array[offset] = block & 0xFF;
|
|
21817
|
-
if (extraBytes > 1) {
|
|
21818
|
-
array[offset + 1] = (block >> 8) & 0xFF;
|
|
21819
|
-
}
|
|
21820
|
-
if (extraBytes > 2) {
|
|
21821
|
-
array[offset + 2] = (block >> 16) & 0xFF;
|
|
21822
|
-
}
|
|
21823
|
-
}
|
|
21824
|
-
return array;
|
|
21825
|
-
};
|
|
21826
|
-
|
|
21827
|
-
function Kmac(bits, padding, outputBits) {
|
|
21828
|
-
Keccak.call(this, bits, padding, outputBits);
|
|
21829
|
-
}
|
|
21830
|
-
|
|
21831
|
-
Kmac.prototype = new Keccak();
|
|
21832
|
-
|
|
21833
|
-
Kmac.prototype.finalize = function () {
|
|
21834
|
-
this.encode(this.outputBits, true);
|
|
21835
|
-
return Keccak.prototype.finalize.call(this);
|
|
21836
|
-
};
|
|
21837
|
-
|
|
21838
|
-
var f = function (s) {
|
|
21839
|
-
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
|
21840
|
-
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
|
21841
|
-
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
|
21842
|
-
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
|
21843
|
-
for (n = 0; n < 48; n += 2) {
|
|
21844
|
-
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
|
21845
|
-
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
|
21846
|
-
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
|
21847
|
-
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
|
21848
|
-
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
|
21849
|
-
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
|
21850
|
-
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
|
21851
|
-
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
|
21852
|
-
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
|
21853
|
-
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
|
21854
|
-
|
|
21855
|
-
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
|
21856
|
-
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
|
21857
|
-
s[0] ^= h;
|
|
21858
|
-
s[1] ^= l;
|
|
21859
|
-
s[10] ^= h;
|
|
21860
|
-
s[11] ^= l;
|
|
21861
|
-
s[20] ^= h;
|
|
21862
|
-
s[21] ^= l;
|
|
21863
|
-
s[30] ^= h;
|
|
21864
|
-
s[31] ^= l;
|
|
21865
|
-
s[40] ^= h;
|
|
21866
|
-
s[41] ^= l;
|
|
21867
|
-
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
|
21868
|
-
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
|
21869
|
-
s[2] ^= h;
|
|
21870
|
-
s[3] ^= l;
|
|
21871
|
-
s[12] ^= h;
|
|
21872
|
-
s[13] ^= l;
|
|
21873
|
-
s[22] ^= h;
|
|
21874
|
-
s[23] ^= l;
|
|
21875
|
-
s[32] ^= h;
|
|
21876
|
-
s[33] ^= l;
|
|
21877
|
-
s[42] ^= h;
|
|
21878
|
-
s[43] ^= l;
|
|
21879
|
-
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
|
21880
|
-
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
|
21881
|
-
s[4] ^= h;
|
|
21882
|
-
s[5] ^= l;
|
|
21883
|
-
s[14] ^= h;
|
|
21884
|
-
s[15] ^= l;
|
|
21885
|
-
s[24] ^= h;
|
|
21886
|
-
s[25] ^= l;
|
|
21887
|
-
s[34] ^= h;
|
|
21888
|
-
s[35] ^= l;
|
|
21889
|
-
s[44] ^= h;
|
|
21890
|
-
s[45] ^= l;
|
|
21891
|
-
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
|
21892
|
-
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
|
21893
|
-
s[6] ^= h;
|
|
21894
|
-
s[7] ^= l;
|
|
21895
|
-
s[16] ^= h;
|
|
21896
|
-
s[17] ^= l;
|
|
21897
|
-
s[26] ^= h;
|
|
21898
|
-
s[27] ^= l;
|
|
21899
|
-
s[36] ^= h;
|
|
21900
|
-
s[37] ^= l;
|
|
21901
|
-
s[46] ^= h;
|
|
21902
|
-
s[47] ^= l;
|
|
21903
|
-
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
|
21904
|
-
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
|
21905
|
-
s[8] ^= h;
|
|
21906
|
-
s[9] ^= l;
|
|
21907
|
-
s[18] ^= h;
|
|
21908
|
-
s[19] ^= l;
|
|
21909
|
-
s[28] ^= h;
|
|
21910
|
-
s[29] ^= l;
|
|
21911
|
-
s[38] ^= h;
|
|
21912
|
-
s[39] ^= l;
|
|
21913
|
-
s[48] ^= h;
|
|
21914
|
-
s[49] ^= l;
|
|
21915
|
-
|
|
21916
|
-
b0 = s[0];
|
|
21917
|
-
b1 = s[1];
|
|
21918
|
-
b32 = (s[11] << 4) | (s[10] >>> 28);
|
|
21919
|
-
b33 = (s[10] << 4) | (s[11] >>> 28);
|
|
21920
|
-
b14 = (s[20] << 3) | (s[21] >>> 29);
|
|
21921
|
-
b15 = (s[21] << 3) | (s[20] >>> 29);
|
|
21922
|
-
b46 = (s[31] << 9) | (s[30] >>> 23);
|
|
21923
|
-
b47 = (s[30] << 9) | (s[31] >>> 23);
|
|
21924
|
-
b28 = (s[40] << 18) | (s[41] >>> 14);
|
|
21925
|
-
b29 = (s[41] << 18) | (s[40] >>> 14);
|
|
21926
|
-
b20 = (s[2] << 1) | (s[3] >>> 31);
|
|
21927
|
-
b21 = (s[3] << 1) | (s[2] >>> 31);
|
|
21928
|
-
b2 = (s[13] << 12) | (s[12] >>> 20);
|
|
21929
|
-
b3 = (s[12] << 12) | (s[13] >>> 20);
|
|
21930
|
-
b34 = (s[22] << 10) | (s[23] >>> 22);
|
|
21931
|
-
b35 = (s[23] << 10) | (s[22] >>> 22);
|
|
21932
|
-
b16 = (s[33] << 13) | (s[32] >>> 19);
|
|
21933
|
-
b17 = (s[32] << 13) | (s[33] >>> 19);
|
|
21934
|
-
b48 = (s[42] << 2) | (s[43] >>> 30);
|
|
21935
|
-
b49 = (s[43] << 2) | (s[42] >>> 30);
|
|
21936
|
-
b40 = (s[5] << 30) | (s[4] >>> 2);
|
|
21937
|
-
b41 = (s[4] << 30) | (s[5] >>> 2);
|
|
21938
|
-
b22 = (s[14] << 6) | (s[15] >>> 26);
|
|
21939
|
-
b23 = (s[15] << 6) | (s[14] >>> 26);
|
|
21940
|
-
b4 = (s[25] << 11) | (s[24] >>> 21);
|
|
21941
|
-
b5 = (s[24] << 11) | (s[25] >>> 21);
|
|
21942
|
-
b36 = (s[34] << 15) | (s[35] >>> 17);
|
|
21943
|
-
b37 = (s[35] << 15) | (s[34] >>> 17);
|
|
21944
|
-
b18 = (s[45] << 29) | (s[44] >>> 3);
|
|
21945
|
-
b19 = (s[44] << 29) | (s[45] >>> 3);
|
|
21946
|
-
b10 = (s[6] << 28) | (s[7] >>> 4);
|
|
21947
|
-
b11 = (s[7] << 28) | (s[6] >>> 4);
|
|
21948
|
-
b42 = (s[17] << 23) | (s[16] >>> 9);
|
|
21949
|
-
b43 = (s[16] << 23) | (s[17] >>> 9);
|
|
21950
|
-
b24 = (s[26] << 25) | (s[27] >>> 7);
|
|
21951
|
-
b25 = (s[27] << 25) | (s[26] >>> 7);
|
|
21952
|
-
b6 = (s[36] << 21) | (s[37] >>> 11);
|
|
21953
|
-
b7 = (s[37] << 21) | (s[36] >>> 11);
|
|
21954
|
-
b38 = (s[47] << 24) | (s[46] >>> 8);
|
|
21955
|
-
b39 = (s[46] << 24) | (s[47] >>> 8);
|
|
21956
|
-
b30 = (s[8] << 27) | (s[9] >>> 5);
|
|
21957
|
-
b31 = (s[9] << 27) | (s[8] >>> 5);
|
|
21958
|
-
b12 = (s[18] << 20) | (s[19] >>> 12);
|
|
21959
|
-
b13 = (s[19] << 20) | (s[18] >>> 12);
|
|
21960
|
-
b44 = (s[29] << 7) | (s[28] >>> 25);
|
|
21961
|
-
b45 = (s[28] << 7) | (s[29] >>> 25);
|
|
21962
|
-
b26 = (s[38] << 8) | (s[39] >>> 24);
|
|
21963
|
-
b27 = (s[39] << 8) | (s[38] >>> 24);
|
|
21964
|
-
b8 = (s[48] << 14) | (s[49] >>> 18);
|
|
21965
|
-
b9 = (s[49] << 14) | (s[48] >>> 18);
|
|
21966
|
-
|
|
21967
|
-
s[0] = b0 ^ (~b2 & b4);
|
|
21968
|
-
s[1] = b1 ^ (~b3 & b5);
|
|
21969
|
-
s[10] = b10 ^ (~b12 & b14);
|
|
21970
|
-
s[11] = b11 ^ (~b13 & b15);
|
|
21971
|
-
s[20] = b20 ^ (~b22 & b24);
|
|
21972
|
-
s[21] = b21 ^ (~b23 & b25);
|
|
21973
|
-
s[30] = b30 ^ (~b32 & b34);
|
|
21974
|
-
s[31] = b31 ^ (~b33 & b35);
|
|
21975
|
-
s[40] = b40 ^ (~b42 & b44);
|
|
21976
|
-
s[41] = b41 ^ (~b43 & b45);
|
|
21977
|
-
s[2] = b2 ^ (~b4 & b6);
|
|
21978
|
-
s[3] = b3 ^ (~b5 & b7);
|
|
21979
|
-
s[12] = b12 ^ (~b14 & b16);
|
|
21980
|
-
s[13] = b13 ^ (~b15 & b17);
|
|
21981
|
-
s[22] = b22 ^ (~b24 & b26);
|
|
21982
|
-
s[23] = b23 ^ (~b25 & b27);
|
|
21983
|
-
s[32] = b32 ^ (~b34 & b36);
|
|
21984
|
-
s[33] = b33 ^ (~b35 & b37);
|
|
21985
|
-
s[42] = b42 ^ (~b44 & b46);
|
|
21986
|
-
s[43] = b43 ^ (~b45 & b47);
|
|
21987
|
-
s[4] = b4 ^ (~b6 & b8);
|
|
21988
|
-
s[5] = b5 ^ (~b7 & b9);
|
|
21989
|
-
s[14] = b14 ^ (~b16 & b18);
|
|
21990
|
-
s[15] = b15 ^ (~b17 & b19);
|
|
21991
|
-
s[24] = b24 ^ (~b26 & b28);
|
|
21992
|
-
s[25] = b25 ^ (~b27 & b29);
|
|
21993
|
-
s[34] = b34 ^ (~b36 & b38);
|
|
21994
|
-
s[35] = b35 ^ (~b37 & b39);
|
|
21995
|
-
s[44] = b44 ^ (~b46 & b48);
|
|
21996
|
-
s[45] = b45 ^ (~b47 & b49);
|
|
21997
|
-
s[6] = b6 ^ (~b8 & b0);
|
|
21998
|
-
s[7] = b7 ^ (~b9 & b1);
|
|
21999
|
-
s[16] = b16 ^ (~b18 & b10);
|
|
22000
|
-
s[17] = b17 ^ (~b19 & b11);
|
|
22001
|
-
s[26] = b26 ^ (~b28 & b20);
|
|
22002
|
-
s[27] = b27 ^ (~b29 & b21);
|
|
22003
|
-
s[36] = b36 ^ (~b38 & b30);
|
|
22004
|
-
s[37] = b37 ^ (~b39 & b31);
|
|
22005
|
-
s[46] = b46 ^ (~b48 & b40);
|
|
22006
|
-
s[47] = b47 ^ (~b49 & b41);
|
|
22007
|
-
s[8] = b8 ^ (~b0 & b2);
|
|
22008
|
-
s[9] = b9 ^ (~b1 & b3);
|
|
22009
|
-
s[18] = b18 ^ (~b10 & b12);
|
|
22010
|
-
s[19] = b19 ^ (~b11 & b13);
|
|
22011
|
-
s[28] = b28 ^ (~b20 & b22);
|
|
22012
|
-
s[29] = b29 ^ (~b21 & b23);
|
|
22013
|
-
s[38] = b38 ^ (~b30 & b32);
|
|
22014
|
-
s[39] = b39 ^ (~b31 & b33);
|
|
22015
|
-
s[48] = b48 ^ (~b40 & b42);
|
|
22016
|
-
s[49] = b49 ^ (~b41 & b43);
|
|
22017
|
-
|
|
22018
|
-
s[0] ^= RC[n];
|
|
22019
|
-
s[1] ^= RC[n + 1];
|
|
22020
|
-
}
|
|
22021
|
-
};
|
|
22022
|
-
|
|
22023
|
-
if (COMMON_JS) {
|
|
22024
|
-
module.exports = methods;
|
|
22025
|
-
} else {
|
|
22026
|
-
for (i = 0; i < methodNames.length; ++i) {
|
|
22027
|
-
root[methodNames[i]] = methods[methodNames[i]];
|
|
22028
|
-
}
|
|
22029
|
-
}
|
|
22030
|
-
})();
|
|
22031
|
-
} (sha3$1));
|
|
22032
|
-
|
|
22033
|
-
var sha3 = sha3$1.exports;
|
|
21840
|
+
gen(0x06, 136, 256 / 8);
|
|
21841
|
+
gen(0x06, 104, 384 / 8);
|
|
21842
|
+
gen(0x06, 72, 512 / 8);
|
|
21843
|
+
gen(0x01, 144, 224 / 8);
|
|
21844
|
+
/**
|
|
21845
|
+
* keccak-256 hash function. Different from SHA3-256.
|
|
21846
|
+
* @param message - that would be hashed
|
|
21847
|
+
*/
|
|
21848
|
+
const keccak_256 = gen(0x01, 136, 256 / 8);
|
|
21849
|
+
gen(0x01, 104, 384 / 8);
|
|
21850
|
+
gen(0x01, 72, 512 / 8);
|
|
21851
|
+
const genShake = (suffix, blockLen, outputLen) => wrapConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
|
|
21852
|
+
genShake(0x1f, 168, 128 / 8);
|
|
21853
|
+
genShake(0x1f, 136, 256 / 8);
|
|
22034
21854
|
|
|
22035
21855
|
// HMAC (RFC 2104)
|
|
22036
21856
|
class HMAC extends Hash {
|
|
@@ -23089,7 +22909,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
23089
22909
|
assert$1(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
23090
22910
|
|
|
23091
22911
|
try {
|
|
23092
|
-
return buffer.Buffer.from(
|
|
22912
|
+
return buffer.Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
23093
22913
|
} catch (error) {
|
|
23094
22914
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
23095
22915
|
}
|
|
@@ -23189,7 +23009,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
23189
23009
|
/* isCompressed */
|
|
23190
23010
|
).slice(1); // throw away leading byte
|
|
23191
23011
|
|
|
23192
|
-
const messageHash = buffer.Buffer.from(
|
|
23012
|
+
const messageHash = buffer.Buffer.from(keccak_256(toBuffer(message)));
|
|
23193
23013
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
23194
23014
|
return this.createInstructionWithPublicKey({
|
|
23195
23015
|
publicKey,
|
|
@@ -24083,6 +23903,33 @@ var solanaWeb3 = (function (exports) {
|
|
|
24083
23903
|
}
|
|
24084
23904
|
};
|
|
24085
23905
|
}
|
|
23906
|
+
/**
|
|
23907
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
23908
|
+
*/
|
|
23909
|
+
|
|
23910
|
+
|
|
23911
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
23912
|
+
this.checkProgramId(instruction.programId);
|
|
23913
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
23914
|
+
const {
|
|
23915
|
+
voteAuthorizeWithSeedArgs: {
|
|
23916
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
23917
|
+
currentAuthorityDerivedKeySeed,
|
|
23918
|
+
newAuthorized,
|
|
23919
|
+
voteAuthorizationType
|
|
23920
|
+
}
|
|
23921
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
23922
|
+
return {
|
|
23923
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
23924
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
23925
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
23926
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
23927
|
+
voteAuthorizationType: {
|
|
23928
|
+
index: voteAuthorizationType
|
|
23929
|
+
},
|
|
23930
|
+
votePubkey: instruction.keys[0].pubkey
|
|
23931
|
+
};
|
|
23932
|
+
}
|
|
24086
23933
|
/**
|
|
24087
23934
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
24088
23935
|
*/
|
|
@@ -24139,6 +23986,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
24139
23986
|
Withdraw: {
|
|
24140
23987
|
index: 3,
|
|
24141
23988
|
layout: struct([u32('instruction'), ns64('lamports')])
|
|
23989
|
+
},
|
|
23990
|
+
AuthorizeWithSeed: {
|
|
23991
|
+
index: 10,
|
|
23992
|
+
layout: struct([u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
24142
23993
|
}
|
|
24143
23994
|
});
|
|
24144
23995
|
/**
|
|
@@ -24267,6 +24118,49 @@ var solanaWeb3 = (function (exports) {
|
|
|
24267
24118
|
data
|
|
24268
24119
|
});
|
|
24269
24120
|
}
|
|
24121
|
+
/**
|
|
24122
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
24123
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
24124
|
+
*/
|
|
24125
|
+
|
|
24126
|
+
|
|
24127
|
+
static authorizeWithSeed(params) {
|
|
24128
|
+
const {
|
|
24129
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
24130
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
24131
|
+
currentAuthorityDerivedKeySeed,
|
|
24132
|
+
newAuthorizedPubkey,
|
|
24133
|
+
voteAuthorizationType,
|
|
24134
|
+
votePubkey
|
|
24135
|
+
} = params;
|
|
24136
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
24137
|
+
const data = encodeData(type, {
|
|
24138
|
+
voteAuthorizeWithSeedArgs: {
|
|
24139
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
24140
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
24141
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
24142
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
24143
|
+
}
|
|
24144
|
+
});
|
|
24145
|
+
const keys = [{
|
|
24146
|
+
pubkey: votePubkey,
|
|
24147
|
+
isSigner: false,
|
|
24148
|
+
isWritable: true
|
|
24149
|
+
}, {
|
|
24150
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
24151
|
+
isSigner: false,
|
|
24152
|
+
isWritable: false
|
|
24153
|
+
}, {
|
|
24154
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
24155
|
+
isSigner: true,
|
|
24156
|
+
isWritable: false
|
|
24157
|
+
}];
|
|
24158
|
+
return new Transaction().add({
|
|
24159
|
+
keys,
|
|
24160
|
+
programId: this.programId,
|
|
24161
|
+
data
|
|
24162
|
+
});
|
|
24163
|
+
}
|
|
24270
24164
|
/**
|
|
24271
24165
|
* Generate a transaction to withdraw from a Vote account.
|
|
24272
24166
|
*/
|
|
@@ -24648,6 +24542,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
24648
24542
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
24649
24543
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
24650
24544
|
exports.TransactionInstruction = TransactionInstruction;
|
|
24545
|
+
exports.TransactionMessage = TransactionMessage;
|
|
24651
24546
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
24652
24547
|
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
24653
24548
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|