@solana/web3.js 1.56.2 → 1.59.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 +583 -16
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +582 -16
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +583 -16
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3062 -2931
- package/lib/index.esm.js +582 -16
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +837 -714
- 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 +583 -16
- 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/account-keys.ts +79 -0
- package/src/message/compiled-keys.ts +165 -0
- package/src/message/index.ts +2 -0
- package/src/message/legacy.ts +34 -2
- package/src/message/v0.ts +137 -0
- package/src/programs/secp256k1.ts +5 -7
- package/src/programs/vote.ts +109 -2
- package/src/publickey.ts +12 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/message.ts +147 -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,
|
|
@@ -8308,12 +8317,14 @@ var solanaWeb3 = (function (exports) {
|
|
|
8308
8317
|
|
|
8309
8318
|
function isPublicKeyData(value) {
|
|
8310
8319
|
return value._bn !== undefined;
|
|
8311
|
-
}
|
|
8320
|
+
} // local counter used by PublicKey.unique()
|
|
8321
|
+
|
|
8322
|
+
|
|
8323
|
+
let uniquePublicKeyCounter = 1;
|
|
8312
8324
|
/**
|
|
8313
8325
|
* A public key
|
|
8314
8326
|
*/
|
|
8315
8327
|
|
|
8316
|
-
|
|
8317
8328
|
class PublicKey extends Struct$1 {
|
|
8318
8329
|
/** @internal */
|
|
8319
8330
|
|
|
@@ -8346,6 +8357,16 @@ var solanaWeb3 = (function (exports) {
|
|
|
8346
8357
|
}
|
|
8347
8358
|
}
|
|
8348
8359
|
}
|
|
8360
|
+
/**
|
|
8361
|
+
* Returns a unique PublicKey for tests and benchmarks using acounter
|
|
8362
|
+
*/
|
|
8363
|
+
|
|
8364
|
+
|
|
8365
|
+
static unique() {
|
|
8366
|
+
const key = new PublicKey(uniquePublicKeyCounter);
|
|
8367
|
+
uniquePublicKeyCounter += 1;
|
|
8368
|
+
return new PublicKey(key.toBuffer());
|
|
8369
|
+
}
|
|
8349
8370
|
/**
|
|
8350
8371
|
* Default public key value. (All zeros)
|
|
8351
8372
|
*/
|
|
@@ -10885,10 +10906,74 @@ var solanaWeb3 = (function (exports) {
|
|
|
10885
10906
|
value: 'TransactionExpiredTimeoutError'
|
|
10886
10907
|
});
|
|
10887
10908
|
|
|
10909
|
+
class MessageAccountKeys {
|
|
10910
|
+
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
10911
|
+
this.staticAccountKeys = void 0;
|
|
10912
|
+
this.accountKeysFromLookups = void 0;
|
|
10913
|
+
this.staticAccountKeys = staticAccountKeys;
|
|
10914
|
+
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
10915
|
+
}
|
|
10916
|
+
|
|
10917
|
+
keySegments() {
|
|
10918
|
+
const keySegments = [this.staticAccountKeys];
|
|
10919
|
+
|
|
10920
|
+
if (this.accountKeysFromLookups) {
|
|
10921
|
+
keySegments.push(this.accountKeysFromLookups.writable);
|
|
10922
|
+
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
10923
|
+
}
|
|
10924
|
+
|
|
10925
|
+
return keySegments;
|
|
10926
|
+
}
|
|
10927
|
+
|
|
10928
|
+
get(index) {
|
|
10929
|
+
for (const keySegment of this.keySegments()) {
|
|
10930
|
+
if (index < keySegment.length) {
|
|
10931
|
+
return keySegment[index];
|
|
10932
|
+
} else {
|
|
10933
|
+
index -= keySegment.length;
|
|
10934
|
+
}
|
|
10935
|
+
}
|
|
10936
|
+
|
|
10937
|
+
return;
|
|
10938
|
+
}
|
|
10939
|
+
|
|
10940
|
+
get length() {
|
|
10941
|
+
return this.keySegments().flat().length;
|
|
10942
|
+
}
|
|
10943
|
+
|
|
10944
|
+
compileInstructions(instructions) {
|
|
10945
|
+
// Bail early if any account indexes would overflow a u8
|
|
10946
|
+
const U8_MAX = 255;
|
|
10947
|
+
|
|
10948
|
+
if (this.length > U8_MAX + 1) {
|
|
10949
|
+
throw new Error('Account index overflow encountered during compilation');
|
|
10950
|
+
}
|
|
10951
|
+
|
|
10952
|
+
const keyIndexMap = new Map();
|
|
10953
|
+
this.keySegments().flat().forEach((key, index) => {
|
|
10954
|
+
keyIndexMap.set(key.toBase58(), index);
|
|
10955
|
+
});
|
|
10956
|
+
|
|
10957
|
+
const findKeyIndex = key => {
|
|
10958
|
+
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
10959
|
+
if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
|
|
10960
|
+
return keyIndex;
|
|
10961
|
+
};
|
|
10962
|
+
|
|
10963
|
+
return instructions.map(instruction => {
|
|
10964
|
+
return {
|
|
10965
|
+
programIdIndex: findKeyIndex(instruction.programId),
|
|
10966
|
+
accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
|
|
10967
|
+
data: instruction.data
|
|
10968
|
+
};
|
|
10969
|
+
});
|
|
10970
|
+
}
|
|
10971
|
+
|
|
10972
|
+
}
|
|
10973
|
+
|
|
10888
10974
|
/**
|
|
10889
10975
|
* Layout for a public key
|
|
10890
10976
|
*/
|
|
10891
|
-
|
|
10892
10977
|
const publicKey = (property = 'publicKey') => {
|
|
10893
10978
|
return blob(32, property);
|
|
10894
10979
|
};
|
|
@@ -10952,6 +11037,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
10952
11037
|
const voteInit = (property = 'voteInit') => {
|
|
10953
11038
|
return struct([publicKey('nodePubkey'), publicKey('authorizedVoter'), publicKey('authorizedWithdrawer'), u8('commission')], property);
|
|
10954
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
|
+
};
|
|
10955
11047
|
function getAlloc(type, fields) {
|
|
10956
11048
|
const getItemAlloc = item => {
|
|
10957
11049
|
if (item.span >= 0) {
|
|
@@ -10964,6 +11056,11 @@ var solanaWeb3 = (function (exports) {
|
|
|
10964
11056
|
if (Array.isArray(field)) {
|
|
10965
11057
|
return field.length * getItemAlloc(item.elementLayout);
|
|
10966
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]);
|
|
10967
11064
|
} // Couldn't determine allocated size of layout
|
|
10968
11065
|
|
|
10969
11066
|
|
|
@@ -11010,6 +11107,129 @@ var solanaWeb3 = (function (exports) {
|
|
|
11010
11107
|
}
|
|
11011
11108
|
}
|
|
11012
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
|
+
|
|
11013
11233
|
/**
|
|
11014
11234
|
* List of instructions to be processed atomically
|
|
11015
11235
|
*/
|
|
@@ -11047,6 +11267,27 @@ var solanaWeb3 = (function (exports) {
|
|
|
11047
11267
|
return [];
|
|
11048
11268
|
}
|
|
11049
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
|
+
|
|
11050
11291
|
isAccountSigner(index) {
|
|
11051
11292
|
return index < this.header.numRequiredSignatures;
|
|
11052
11293
|
}
|
|
@@ -11136,7 +11377,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
11136
11377
|
for (let i = 0; i < accountCount; i++) {
|
|
11137
11378
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
11138
11379
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
11139
|
-
accountKeys.push(
|
|
11380
|
+
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
11140
11381
|
}
|
|
11141
11382
|
|
|
11142
11383
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -11175,12 +11416,6 @@ var solanaWeb3 = (function (exports) {
|
|
|
11175
11416
|
|
|
11176
11417
|
}
|
|
11177
11418
|
|
|
11178
|
-
function assert$1 (condition, message) {
|
|
11179
|
-
if (!condition) {
|
|
11180
|
-
throw new Error(message || 'Assertion failed');
|
|
11181
|
-
}
|
|
11182
|
-
}
|
|
11183
|
-
|
|
11184
11419
|
/**
|
|
11185
11420
|
* Message constructor arguments
|
|
11186
11421
|
*/
|
|
@@ -11203,6 +11438,102 @@ var solanaWeb3 = (function (exports) {
|
|
|
11203
11438
|
return 0;
|
|
11204
11439
|
}
|
|
11205
11440
|
|
|
11441
|
+
get numAccountKeysFromLookups() {
|
|
11442
|
+
let count = 0;
|
|
11443
|
+
|
|
11444
|
+
for (const lookup of this.addressTableLookups) {
|
|
11445
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
11446
|
+
}
|
|
11447
|
+
|
|
11448
|
+
return count;
|
|
11449
|
+
}
|
|
11450
|
+
|
|
11451
|
+
getAccountKeys(args) {
|
|
11452
|
+
let accountKeysFromLookups;
|
|
11453
|
+
|
|
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');
|
|
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');
|
|
11464
|
+
}
|
|
11465
|
+
|
|
11466
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
11467
|
+
}
|
|
11468
|
+
|
|
11469
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
11470
|
+
const accountKeysFromLookups = {
|
|
11471
|
+
writable: [],
|
|
11472
|
+
readonly: []
|
|
11473
|
+
};
|
|
11474
|
+
|
|
11475
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
11476
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
11477
|
+
|
|
11478
|
+
if (!tableAccount) {
|
|
11479
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
11480
|
+
}
|
|
11481
|
+
|
|
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
|
+
}
|
|
11497
|
+
}
|
|
11498
|
+
|
|
11499
|
+
return accountKeysFromLookups;
|
|
11500
|
+
}
|
|
11501
|
+
|
|
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 || [];
|
|
11510
|
+
|
|
11511
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
11512
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
11513
|
+
|
|
11514
|
+
if (extractResult !== undefined) {
|
|
11515
|
+
const [addressTableLookup, {
|
|
11516
|
+
writable,
|
|
11517
|
+
readonly
|
|
11518
|
+
}] = extractResult;
|
|
11519
|
+
addressTableLookups.push(addressTableLookup);
|
|
11520
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
11521
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
11522
|
+
}
|
|
11523
|
+
}
|
|
11524
|
+
|
|
11525
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
11526
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
11527
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
11528
|
+
return new MessageV0({
|
|
11529
|
+
header,
|
|
11530
|
+
staticAccountKeys,
|
|
11531
|
+
recentBlockhash: args.recentBlockhash,
|
|
11532
|
+
compiledInstructions,
|
|
11533
|
+
addressTableLookups
|
|
11534
|
+
});
|
|
11535
|
+
}
|
|
11536
|
+
|
|
11206
11537
|
serialize() {
|
|
11207
11538
|
const encodedStaticAccountKeysLength = Array();
|
|
11208
11539
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -12097,6 +12428,114 @@ var solanaWeb3 = (function (exports) {
|
|
|
12097
12428
|
|
|
12098
12429
|
}
|
|
12099
12430
|
|
|
12431
|
+
class TransactionMessage {
|
|
12432
|
+
constructor(args) {
|
|
12433
|
+
this.accountKeys = void 0;
|
|
12434
|
+
this.instructions = void 0;
|
|
12435
|
+
this.recentBlockhash = void 0;
|
|
12436
|
+
this.accountKeys = args.accountKeys;
|
|
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 instructions = [];
|
|
12458
|
+
|
|
12459
|
+
for (const compiledIx of compiledInstructions) {
|
|
12460
|
+
const keys = [];
|
|
12461
|
+
|
|
12462
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
12463
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
12464
|
+
|
|
12465
|
+
if (pubkey === undefined) {
|
|
12466
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
12467
|
+
}
|
|
12468
|
+
|
|
12469
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
12470
|
+
let isWritable;
|
|
12471
|
+
|
|
12472
|
+
if (isSigner) {
|
|
12473
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
12474
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
12475
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
12476
|
+
} else {
|
|
12477
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
12478
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
12479
|
+
}
|
|
12480
|
+
|
|
12481
|
+
keys.push({
|
|
12482
|
+
pubkey,
|
|
12483
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
12484
|
+
isWritable
|
|
12485
|
+
});
|
|
12486
|
+
}
|
|
12487
|
+
|
|
12488
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
12489
|
+
|
|
12490
|
+
if (programId === undefined) {
|
|
12491
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
12492
|
+
}
|
|
12493
|
+
|
|
12494
|
+
instructions.push(new TransactionInstruction({
|
|
12495
|
+
programId,
|
|
12496
|
+
data: toBuffer(compiledIx.data),
|
|
12497
|
+
keys
|
|
12498
|
+
}));
|
|
12499
|
+
}
|
|
12500
|
+
|
|
12501
|
+
return new TransactionMessage({
|
|
12502
|
+
accountKeys,
|
|
12503
|
+
instructions,
|
|
12504
|
+
recentBlockhash
|
|
12505
|
+
});
|
|
12506
|
+
}
|
|
12507
|
+
|
|
12508
|
+
compileToLegacyMessage() {
|
|
12509
|
+
const payerKey = this.accountKeys.get(0);
|
|
12510
|
+
|
|
12511
|
+
if (payerKey === undefined) {
|
|
12512
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
12513
|
+
}
|
|
12514
|
+
|
|
12515
|
+
return Message.compile({
|
|
12516
|
+
payerKey,
|
|
12517
|
+
recentBlockhash: this.recentBlockhash,
|
|
12518
|
+
instructions: this.instructions
|
|
12519
|
+
});
|
|
12520
|
+
}
|
|
12521
|
+
|
|
12522
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
12523
|
+
const payerKey = this.accountKeys.get(0);
|
|
12524
|
+
|
|
12525
|
+
if (payerKey === undefined) {
|
|
12526
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
12527
|
+
}
|
|
12528
|
+
|
|
12529
|
+
return MessageV0.compile({
|
|
12530
|
+
payerKey,
|
|
12531
|
+
recentBlockhash: this.recentBlockhash,
|
|
12532
|
+
instructions: this.instructions,
|
|
12533
|
+
addressLookupTableAccounts
|
|
12534
|
+
});
|
|
12535
|
+
}
|
|
12536
|
+
|
|
12537
|
+
}
|
|
12538
|
+
|
|
12100
12539
|
/**
|
|
12101
12540
|
* Versioned transaction class
|
|
12102
12541
|
*/
|
|
@@ -19563,12 +20002,46 @@ var solanaWeb3 = (function (exports) {
|
|
|
19563
20002
|
|
|
19564
20003
|
return res.result;
|
|
19565
20004
|
}
|
|
20005
|
+
/**
|
|
20006
|
+
* Simulate a transaction
|
|
20007
|
+
*
|
|
20008
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
20009
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
20010
|
+
*/
|
|
20011
|
+
|
|
20012
|
+
|
|
19566
20013
|
/**
|
|
19567
20014
|
* Simulate a transaction
|
|
19568
20015
|
*/
|
|
20016
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
20017
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
20018
|
+
if ('message' in transactionOrMessage) {
|
|
20019
|
+
const versionedTx = transactionOrMessage;
|
|
20020
|
+
const wireTransaction = versionedTx.serialize();
|
|
20021
|
+
const encodedTransaction = buffer.Buffer.from(wireTransaction).toString('base64');
|
|
20022
|
+
|
|
20023
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
20024
|
+
throw new Error('Invalid arguments');
|
|
20025
|
+
}
|
|
20026
|
+
|
|
20027
|
+
const config = configOrSigners || {};
|
|
20028
|
+
config.encoding = 'base64';
|
|
20029
|
+
|
|
20030
|
+
if (!('commitment' in config)) {
|
|
20031
|
+
config.commitment = this.commitment;
|
|
20032
|
+
}
|
|
19569
20033
|
|
|
20034
|
+
const args = [encodedTransaction, config];
|
|
20035
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
20036
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
20037
|
+
|
|
20038
|
+
if ('error' in res) {
|
|
20039
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
20040
|
+
}
|
|
20041
|
+
|
|
20042
|
+
return res.result;
|
|
20043
|
+
}
|
|
19570
20044
|
|
|
19571
|
-
async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
|
|
19572
20045
|
let transaction;
|
|
19573
20046
|
|
|
19574
20047
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -19584,6 +20057,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
19584
20057
|
transaction._message = transaction._json = undefined;
|
|
19585
20058
|
}
|
|
19586
20059
|
|
|
20060
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
20061
|
+
throw new Error('Invalid arguments');
|
|
20062
|
+
}
|
|
20063
|
+
|
|
20064
|
+
const signers = configOrSigners;
|
|
20065
|
+
|
|
19587
20066
|
if (transaction.nonceInfo && signers) {
|
|
19588
20067
|
transaction.sign(...signers);
|
|
19589
20068
|
} else {
|
|
@@ -19666,10 +20145,32 @@ var solanaWeb3 = (function (exports) {
|
|
|
19666
20145
|
}
|
|
19667
20146
|
/**
|
|
19668
20147
|
* Sign and send a transaction
|
|
20148
|
+
*
|
|
20149
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
20150
|
+
* VersionedTransaction}
|
|
19669
20151
|
*/
|
|
19670
20152
|
|
|
19671
20153
|
|
|
19672
|
-
|
|
20154
|
+
/**
|
|
20155
|
+
* Sign and send a transaction
|
|
20156
|
+
*/
|
|
20157
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
20158
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
20159
|
+
if ('message' in transaction) {
|
|
20160
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
20161
|
+
throw new Error('Invalid arguments');
|
|
20162
|
+
}
|
|
20163
|
+
|
|
20164
|
+
const wireTransaction = transaction.serialize();
|
|
20165
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
20166
|
+
}
|
|
20167
|
+
|
|
20168
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
20169
|
+
throw new Error('Invalid arguments');
|
|
20170
|
+
}
|
|
20171
|
+
|
|
20172
|
+
const signers = signersOrOptions;
|
|
20173
|
+
|
|
19673
20174
|
if (transaction.nonceInfo) {
|
|
19674
20175
|
transaction.sign(...signers);
|
|
19675
20176
|
} else {
|
|
@@ -21154,662 +21655,208 @@ var solanaWeb3 = (function (exports) {
|
|
|
21154
21655
|
}
|
|
21155
21656
|
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
21156
21657
|
|
|
21157
|
-
|
|
21158
|
-
|
|
21658
|
+
// Various per round constants calculations
|
|
21659
|
+
const [SHA3_PI, SHA3_ROTL, _SHA3_IOTA] = [[], [], []];
|
|
21660
|
+
const _0n$1 = BigInt(0);
|
|
21661
|
+
const _1n$1 = BigInt(1);
|
|
21662
|
+
const _2n$1 = BigInt(2);
|
|
21663
|
+
const _7n = BigInt(7);
|
|
21664
|
+
const _256n = BigInt(256);
|
|
21665
|
+
const _0x71n = BigInt(0x71);
|
|
21666
|
+
for (let round = 0, R = _1n$1, x = 1, y = 0; round < 24; round++) {
|
|
21667
|
+
// Pi
|
|
21668
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
|
21669
|
+
SHA3_PI.push(2 * (5 * y + x));
|
|
21670
|
+
// Rotational
|
|
21671
|
+
SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
|
|
21672
|
+
// Iota
|
|
21673
|
+
let t = _0n$1;
|
|
21674
|
+
for (let j = 0; j < 7; j++) {
|
|
21675
|
+
R = ((R << _1n$1) ^ ((R >> _7n) * _0x71n)) % _256n;
|
|
21676
|
+
if (R & _2n$1)
|
|
21677
|
+
t ^= _1n$1 << ((_1n$1 << BigInt(j)) - _1n$1);
|
|
21678
|
+
}
|
|
21679
|
+
_SHA3_IOTA.push(t);
|
|
21680
|
+
}
|
|
21681
|
+
const [SHA3_IOTA_H, SHA3_IOTA_L] = u64$2.split(_SHA3_IOTA, true);
|
|
21682
|
+
// Left rotation (without 0, 32, 64)
|
|
21683
|
+
const rotlH = (h, l, s) => s > 32 ? u64$2.rotlBH(h, l, s) : u64$2.rotlSH(h, l, s);
|
|
21684
|
+
const rotlL = (h, l, s) => s > 32 ? u64$2.rotlBL(h, l, s) : u64$2.rotlSL(h, l, s);
|
|
21685
|
+
// Same as keccakf1600, but allows to skip some rounds
|
|
21686
|
+
function keccakP(s, rounds = 24) {
|
|
21687
|
+
const B = new Uint32Array(5 * 2);
|
|
21688
|
+
// NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
|
|
21689
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
|
21690
|
+
// Theta θ
|
|
21691
|
+
for (let x = 0; x < 10; x++)
|
|
21692
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
|
21693
|
+
for (let x = 0; x < 10; x += 2) {
|
|
21694
|
+
const idx1 = (x + 8) % 10;
|
|
21695
|
+
const idx0 = (x + 2) % 10;
|
|
21696
|
+
const B0 = B[idx0];
|
|
21697
|
+
const B1 = B[idx0 + 1];
|
|
21698
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
|
21699
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
|
21700
|
+
for (let y = 0; y < 50; y += 10) {
|
|
21701
|
+
s[x + y] ^= Th;
|
|
21702
|
+
s[x + y + 1] ^= Tl;
|
|
21703
|
+
}
|
|
21704
|
+
}
|
|
21705
|
+
// Rho (ρ) and Pi (π)
|
|
21706
|
+
let curH = s[2];
|
|
21707
|
+
let curL = s[3];
|
|
21708
|
+
for (let t = 0; t < 24; t++) {
|
|
21709
|
+
const shift = SHA3_ROTL[t];
|
|
21710
|
+
const Th = rotlH(curH, curL, shift);
|
|
21711
|
+
const Tl = rotlL(curH, curL, shift);
|
|
21712
|
+
const PI = SHA3_PI[t];
|
|
21713
|
+
curH = s[PI];
|
|
21714
|
+
curL = s[PI + 1];
|
|
21715
|
+
s[PI] = Th;
|
|
21716
|
+
s[PI + 1] = Tl;
|
|
21717
|
+
}
|
|
21718
|
+
// Chi (χ)
|
|
21719
|
+
for (let y = 0; y < 50; y += 10) {
|
|
21720
|
+
for (let x = 0; x < 10; x++)
|
|
21721
|
+
B[x] = s[y + x];
|
|
21722
|
+
for (let x = 0; x < 10; x++)
|
|
21723
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
|
21724
|
+
}
|
|
21725
|
+
// Iota (ι)
|
|
21726
|
+
s[0] ^= SHA3_IOTA_H[round];
|
|
21727
|
+
s[1] ^= SHA3_IOTA_L[round];
|
|
21728
|
+
}
|
|
21729
|
+
B.fill(0);
|
|
21730
|
+
}
|
|
21731
|
+
class Keccak extends Hash {
|
|
21732
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
21733
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
21734
|
+
super();
|
|
21735
|
+
this.blockLen = blockLen;
|
|
21736
|
+
this.suffix = suffix;
|
|
21737
|
+
this.outputLen = outputLen;
|
|
21738
|
+
this.enableXOF = enableXOF;
|
|
21739
|
+
this.rounds = rounds;
|
|
21740
|
+
this.pos = 0;
|
|
21741
|
+
this.posOut = 0;
|
|
21742
|
+
this.finished = false;
|
|
21743
|
+
this.destroyed = false;
|
|
21744
|
+
// Can be passed from user as dkLen
|
|
21745
|
+
assert$3.number(outputLen);
|
|
21746
|
+
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
|
21747
|
+
if (0 >= this.blockLen || this.blockLen >= 200)
|
|
21748
|
+
throw new Error('Sha3 supports only keccak-f1600 function');
|
|
21749
|
+
this.state = new Uint8Array(200);
|
|
21750
|
+
this.state32 = u32$1(this.state);
|
|
21751
|
+
}
|
|
21752
|
+
keccak() {
|
|
21753
|
+
keccakP(this.state32, this.rounds);
|
|
21754
|
+
this.posOut = 0;
|
|
21755
|
+
this.pos = 0;
|
|
21756
|
+
}
|
|
21757
|
+
update(data) {
|
|
21758
|
+
assert$3.exists(this);
|
|
21759
|
+
const { blockLen, state } = this;
|
|
21760
|
+
data = toBytes(data);
|
|
21761
|
+
const len = data.length;
|
|
21762
|
+
for (let pos = 0; pos < len;) {
|
|
21763
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
21764
|
+
for (let i = 0; i < take; i++)
|
|
21765
|
+
state[this.pos++] ^= data[pos++];
|
|
21766
|
+
if (this.pos === blockLen)
|
|
21767
|
+
this.keccak();
|
|
21768
|
+
}
|
|
21769
|
+
return this;
|
|
21770
|
+
}
|
|
21771
|
+
finish() {
|
|
21772
|
+
if (this.finished)
|
|
21773
|
+
return;
|
|
21774
|
+
this.finished = true;
|
|
21775
|
+
const { state, suffix, pos, blockLen } = this;
|
|
21776
|
+
// Do the padding
|
|
21777
|
+
state[pos] ^= suffix;
|
|
21778
|
+
if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
|
|
21779
|
+
this.keccak();
|
|
21780
|
+
state[blockLen - 1] ^= 0x80;
|
|
21781
|
+
this.keccak();
|
|
21782
|
+
}
|
|
21783
|
+
writeInto(out) {
|
|
21784
|
+
assert$3.exists(this, false);
|
|
21785
|
+
assert$3.bytes(out);
|
|
21786
|
+
this.finish();
|
|
21787
|
+
const bufferOut = this.state;
|
|
21788
|
+
const { blockLen } = this;
|
|
21789
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
21790
|
+
if (this.posOut >= blockLen)
|
|
21791
|
+
this.keccak();
|
|
21792
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
21793
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
21794
|
+
this.posOut += take;
|
|
21795
|
+
pos += take;
|
|
21796
|
+
}
|
|
21797
|
+
return out;
|
|
21798
|
+
}
|
|
21799
|
+
xofInto(out) {
|
|
21800
|
+
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
|
|
21801
|
+
if (!this.enableXOF)
|
|
21802
|
+
throw new Error('XOF is not possible for this instance');
|
|
21803
|
+
return this.writeInto(out);
|
|
21804
|
+
}
|
|
21805
|
+
xof(bytes) {
|
|
21806
|
+
assert$3.number(bytes);
|
|
21807
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
21808
|
+
}
|
|
21809
|
+
digestInto(out) {
|
|
21810
|
+
assert$3.output(out, this);
|
|
21811
|
+
if (this.finished)
|
|
21812
|
+
throw new Error('digest() was already called');
|
|
21813
|
+
this.writeInto(out);
|
|
21814
|
+
this.destroy();
|
|
21815
|
+
return out;
|
|
21816
|
+
}
|
|
21817
|
+
digest() {
|
|
21818
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
21819
|
+
}
|
|
21820
|
+
destroy() {
|
|
21821
|
+
this.destroyed = true;
|
|
21822
|
+
this.state.fill(0);
|
|
21823
|
+
}
|
|
21824
|
+
_cloneInto(to) {
|
|
21825
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
21826
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
|
21827
|
+
to.state32.set(this.state32);
|
|
21828
|
+
to.pos = this.pos;
|
|
21829
|
+
to.posOut = this.posOut;
|
|
21830
|
+
to.finished = this.finished;
|
|
21831
|
+
to.rounds = rounds;
|
|
21832
|
+
// Suffix can change in cSHAKE
|
|
21833
|
+
to.suffix = suffix;
|
|
21834
|
+
to.outputLen = outputLen;
|
|
21835
|
+
to.enableXOF = enableXOF;
|
|
21836
|
+
to.destroyed = this.destroyed;
|
|
21837
|
+
return to;
|
|
21838
|
+
}
|
|
21839
|
+
}
|
|
21840
|
+
const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
|
|
21841
|
+
gen(0x06, 144, 224 / 8);
|
|
21159
21842
|
/**
|
|
21160
|
-
*
|
|
21161
|
-
*
|
|
21162
|
-
* @version 0.8.0
|
|
21163
|
-
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
21164
|
-
* @copyright Chen, Yi-Cyuan 2015-2018
|
|
21165
|
-
* @license MIT
|
|
21843
|
+
* SHA3-256 hash function
|
|
21844
|
+
* @param message - that would be hashed
|
|
21166
21845
|
*/
|
|
21167
|
-
|
|
21168
|
-
(
|
|
21169
|
-
|
|
21170
|
-
|
|
21171
|
-
|
|
21172
|
-
|
|
21173
|
-
|
|
21174
|
-
|
|
21175
|
-
|
|
21176
|
-
|
|
21177
|
-
|
|
21178
|
-
|
|
21179
|
-
|
|
21180
|
-
|
|
21181
|
-
if (NODE_JS) {
|
|
21182
|
-
root = commonjsGlobal;
|
|
21183
|
-
} else if (WEB_WORKER) {
|
|
21184
|
-
root = self;
|
|
21185
|
-
}
|
|
21186
|
-
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && 'object' === 'object' && module.exports;
|
|
21187
|
-
var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
21188
|
-
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
21189
|
-
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
|
21190
|
-
var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
|
|
21191
|
-
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
|
21192
|
-
var PADDING = [6, 1536, 393216, 100663296];
|
|
21193
|
-
var SHIFT = [0, 8, 16, 24];
|
|
21194
|
-
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
|
|
21195
|
-
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
|
|
21196
|
-
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
|
|
21197
|
-
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
|
|
21198
|
-
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
|
|
21199
|
-
var BITS = [224, 256, 384, 512];
|
|
21200
|
-
var SHAKE_BITS = [128, 256];
|
|
21201
|
-
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest'];
|
|
21202
|
-
var CSHAKE_BYTEPAD = {
|
|
21203
|
-
'128': 168,
|
|
21204
|
-
'256': 136
|
|
21205
|
-
};
|
|
21206
|
-
|
|
21207
|
-
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
|
|
21208
|
-
Array.isArray = function (obj) {
|
|
21209
|
-
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
21210
|
-
};
|
|
21211
|
-
}
|
|
21212
|
-
|
|
21213
|
-
if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
|
|
21214
|
-
ArrayBuffer.isView = function (obj) {
|
|
21215
|
-
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
21216
|
-
};
|
|
21217
|
-
}
|
|
21218
|
-
|
|
21219
|
-
var createOutputMethod = function (bits, padding, outputType) {
|
|
21220
|
-
return function (message) {
|
|
21221
|
-
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
21222
|
-
};
|
|
21223
|
-
};
|
|
21224
|
-
|
|
21225
|
-
var createShakeOutputMethod = function (bits, padding, outputType) {
|
|
21226
|
-
return function (message, outputBits) {
|
|
21227
|
-
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
|
21228
|
-
};
|
|
21229
|
-
};
|
|
21230
|
-
|
|
21231
|
-
var createCshakeOutputMethod = function (bits, padding, outputType) {
|
|
21232
|
-
return function (message, outputBits, n, s) {
|
|
21233
|
-
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
|
|
21234
|
-
};
|
|
21235
|
-
};
|
|
21236
|
-
|
|
21237
|
-
var createKmacOutputMethod = function (bits, padding, outputType) {
|
|
21238
|
-
return function (key, message, outputBits, s) {
|
|
21239
|
-
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
|
21240
|
-
};
|
|
21241
|
-
};
|
|
21242
|
-
|
|
21243
|
-
var createOutputMethods = function (method, createMethod, bits, padding) {
|
|
21244
|
-
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
21245
|
-
var type = OUTPUT_TYPES[i];
|
|
21246
|
-
method[type] = createMethod(bits, padding, type);
|
|
21247
|
-
}
|
|
21248
|
-
return method;
|
|
21249
|
-
};
|
|
21250
|
-
|
|
21251
|
-
var createMethod = function (bits, padding) {
|
|
21252
|
-
var method = createOutputMethod(bits, padding, 'hex');
|
|
21253
|
-
method.create = function () {
|
|
21254
|
-
return new Keccak(bits, padding, bits);
|
|
21255
|
-
};
|
|
21256
|
-
method.update = function (message) {
|
|
21257
|
-
return method.create().update(message);
|
|
21258
|
-
};
|
|
21259
|
-
return createOutputMethods(method, createOutputMethod, bits, padding);
|
|
21260
|
-
};
|
|
21261
|
-
|
|
21262
|
-
var createShakeMethod = function (bits, padding) {
|
|
21263
|
-
var method = createShakeOutputMethod(bits, padding, 'hex');
|
|
21264
|
-
method.create = function (outputBits) {
|
|
21265
|
-
return new Keccak(bits, padding, outputBits);
|
|
21266
|
-
};
|
|
21267
|
-
method.update = function (message, outputBits) {
|
|
21268
|
-
return method.create(outputBits).update(message);
|
|
21269
|
-
};
|
|
21270
|
-
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
|
|
21271
|
-
};
|
|
21272
|
-
|
|
21273
|
-
var createCshakeMethod = function (bits, padding) {
|
|
21274
|
-
var w = CSHAKE_BYTEPAD[bits];
|
|
21275
|
-
var method = createCshakeOutputMethod(bits, padding, 'hex');
|
|
21276
|
-
method.create = function (outputBits, n, s) {
|
|
21277
|
-
if (!n && !s) {
|
|
21278
|
-
return methods['shake' + bits].create(outputBits);
|
|
21279
|
-
} else {
|
|
21280
|
-
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
|
|
21281
|
-
}
|
|
21282
|
-
};
|
|
21283
|
-
method.update = function (message, outputBits, n, s) {
|
|
21284
|
-
return method.create(outputBits, n, s).update(message);
|
|
21285
|
-
};
|
|
21286
|
-
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
|
21287
|
-
};
|
|
21288
|
-
|
|
21289
|
-
var createKmacMethod = function (bits, padding) {
|
|
21290
|
-
var w = CSHAKE_BYTEPAD[bits];
|
|
21291
|
-
var method = createKmacOutputMethod(bits, padding, 'hex');
|
|
21292
|
-
method.create = function (key, outputBits, s) {
|
|
21293
|
-
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
21294
|
-
};
|
|
21295
|
-
method.update = function (key, message, outputBits, s) {
|
|
21296
|
-
return method.create(key, outputBits, s).update(message);
|
|
21297
|
-
};
|
|
21298
|
-
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
|
21299
|
-
};
|
|
21300
|
-
|
|
21301
|
-
var algorithms = [
|
|
21302
|
-
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
|
21303
|
-
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
21304
|
-
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
21305
|
-
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
21306
|
-
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
|
21307
|
-
];
|
|
21308
|
-
|
|
21309
|
-
var methods = {}, methodNames = [];
|
|
21310
|
-
|
|
21311
|
-
for (var i = 0; i < algorithms.length; ++i) {
|
|
21312
|
-
var algorithm = algorithms[i];
|
|
21313
|
-
var bits = algorithm.bits;
|
|
21314
|
-
for (var j = 0; j < bits.length; ++j) {
|
|
21315
|
-
var methodName = algorithm.name + '_' + bits[j];
|
|
21316
|
-
methodNames.push(methodName);
|
|
21317
|
-
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
|
|
21318
|
-
if (algorithm.name !== 'sha3') {
|
|
21319
|
-
var newMethodName = algorithm.name + bits[j];
|
|
21320
|
-
methodNames.push(newMethodName);
|
|
21321
|
-
methods[newMethodName] = methods[methodName];
|
|
21322
|
-
}
|
|
21323
|
-
}
|
|
21324
|
-
}
|
|
21325
|
-
|
|
21326
|
-
function Keccak(bits, padding, outputBits) {
|
|
21327
|
-
this.blocks = [];
|
|
21328
|
-
this.s = [];
|
|
21329
|
-
this.padding = padding;
|
|
21330
|
-
this.outputBits = outputBits;
|
|
21331
|
-
this.reset = true;
|
|
21332
|
-
this.finalized = false;
|
|
21333
|
-
this.block = 0;
|
|
21334
|
-
this.start = 0;
|
|
21335
|
-
this.blockCount = (1600 - (bits << 1)) >> 5;
|
|
21336
|
-
this.byteCount = this.blockCount << 2;
|
|
21337
|
-
this.outputBlocks = outputBits >> 5;
|
|
21338
|
-
this.extraBytes = (outputBits & 31) >> 3;
|
|
21339
|
-
|
|
21340
|
-
for (var i = 0; i < 50; ++i) {
|
|
21341
|
-
this.s[i] = 0;
|
|
21342
|
-
}
|
|
21343
|
-
}
|
|
21344
|
-
|
|
21345
|
-
Keccak.prototype.update = function (message) {
|
|
21346
|
-
if (this.finalized) {
|
|
21347
|
-
throw new Error(FINALIZE_ERROR);
|
|
21348
|
-
}
|
|
21349
|
-
var notString, type = typeof message;
|
|
21350
|
-
if (type !== 'string') {
|
|
21351
|
-
if (type === 'object') {
|
|
21352
|
-
if (message === null) {
|
|
21353
|
-
throw new Error(INPUT_ERROR);
|
|
21354
|
-
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
21355
|
-
message = new Uint8Array(message);
|
|
21356
|
-
} else if (!Array.isArray(message)) {
|
|
21357
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
|
|
21358
|
-
throw new Error(INPUT_ERROR);
|
|
21359
|
-
}
|
|
21360
|
-
}
|
|
21361
|
-
} else {
|
|
21362
|
-
throw new Error(INPUT_ERROR);
|
|
21363
|
-
}
|
|
21364
|
-
notString = true;
|
|
21365
|
-
}
|
|
21366
|
-
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
|
|
21367
|
-
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
|
21368
|
-
|
|
21369
|
-
while (index < length) {
|
|
21370
|
-
if (this.reset) {
|
|
21371
|
-
this.reset = false;
|
|
21372
|
-
blocks[0] = this.block;
|
|
21373
|
-
for (i = 1; i < blockCount + 1; ++i) {
|
|
21374
|
-
blocks[i] = 0;
|
|
21375
|
-
}
|
|
21376
|
-
}
|
|
21377
|
-
if (notString) {
|
|
21378
|
-
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
21379
|
-
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
21380
|
-
}
|
|
21381
|
-
} else {
|
|
21382
|
-
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
21383
|
-
code = message.charCodeAt(index);
|
|
21384
|
-
if (code < 0x80) {
|
|
21385
|
-
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
21386
|
-
} else if (code < 0x800) {
|
|
21387
|
-
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
|
21388
|
-
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
21389
|
-
} else if (code < 0xd800 || code >= 0xe000) {
|
|
21390
|
-
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
|
21391
|
-
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
21392
|
-
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
21393
|
-
} else {
|
|
21394
|
-
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
21395
|
-
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
|
21396
|
-
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
21397
|
-
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
21398
|
-
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
21399
|
-
}
|
|
21400
|
-
}
|
|
21401
|
-
}
|
|
21402
|
-
this.lastByteIndex = i;
|
|
21403
|
-
if (i >= byteCount) {
|
|
21404
|
-
this.start = i - byteCount;
|
|
21405
|
-
this.block = blocks[blockCount];
|
|
21406
|
-
for (i = 0; i < blockCount; ++i) {
|
|
21407
|
-
s[i] ^= blocks[i];
|
|
21408
|
-
}
|
|
21409
|
-
f(s);
|
|
21410
|
-
this.reset = true;
|
|
21411
|
-
} else {
|
|
21412
|
-
this.start = i;
|
|
21413
|
-
}
|
|
21414
|
-
}
|
|
21415
|
-
return this;
|
|
21416
|
-
};
|
|
21417
|
-
|
|
21418
|
-
Keccak.prototype.encode = function (x, right) {
|
|
21419
|
-
var o = x & 255, n = 1;
|
|
21420
|
-
var bytes = [o];
|
|
21421
|
-
x = x >> 8;
|
|
21422
|
-
o = x & 255;
|
|
21423
|
-
while (o > 0) {
|
|
21424
|
-
bytes.unshift(o);
|
|
21425
|
-
x = x >> 8;
|
|
21426
|
-
o = x & 255;
|
|
21427
|
-
++n;
|
|
21428
|
-
}
|
|
21429
|
-
if (right) {
|
|
21430
|
-
bytes.push(n);
|
|
21431
|
-
} else {
|
|
21432
|
-
bytes.unshift(n);
|
|
21433
|
-
}
|
|
21434
|
-
this.update(bytes);
|
|
21435
|
-
return bytes.length;
|
|
21436
|
-
};
|
|
21437
|
-
|
|
21438
|
-
Keccak.prototype.encodeString = function (str) {
|
|
21439
|
-
var notString, type = typeof str;
|
|
21440
|
-
if (type !== 'string') {
|
|
21441
|
-
if (type === 'object') {
|
|
21442
|
-
if (str === null) {
|
|
21443
|
-
throw new Error(INPUT_ERROR);
|
|
21444
|
-
} else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
|
|
21445
|
-
str = new Uint8Array(str);
|
|
21446
|
-
} else if (!Array.isArray(str)) {
|
|
21447
|
-
if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
|
|
21448
|
-
throw new Error(INPUT_ERROR);
|
|
21449
|
-
}
|
|
21450
|
-
}
|
|
21451
|
-
} else {
|
|
21452
|
-
throw new Error(INPUT_ERROR);
|
|
21453
|
-
}
|
|
21454
|
-
notString = true;
|
|
21455
|
-
}
|
|
21456
|
-
var bytes = 0, length = str.length;
|
|
21457
|
-
if (notString) {
|
|
21458
|
-
bytes = length;
|
|
21459
|
-
} else {
|
|
21460
|
-
for (var i = 0; i < str.length; ++i) {
|
|
21461
|
-
var code = str.charCodeAt(i);
|
|
21462
|
-
if (code < 0x80) {
|
|
21463
|
-
bytes += 1;
|
|
21464
|
-
} else if (code < 0x800) {
|
|
21465
|
-
bytes += 2;
|
|
21466
|
-
} else if (code < 0xd800 || code >= 0xe000) {
|
|
21467
|
-
bytes += 3;
|
|
21468
|
-
} else {
|
|
21469
|
-
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
|
21470
|
-
bytes += 4;
|
|
21471
|
-
}
|
|
21472
|
-
}
|
|
21473
|
-
}
|
|
21474
|
-
bytes += this.encode(bytes * 8);
|
|
21475
|
-
this.update(str);
|
|
21476
|
-
return bytes;
|
|
21477
|
-
};
|
|
21478
|
-
|
|
21479
|
-
Keccak.prototype.bytepad = function (strs, w) {
|
|
21480
|
-
var bytes = this.encode(w);
|
|
21481
|
-
for (var i = 0; i < strs.length; ++i) {
|
|
21482
|
-
bytes += this.encodeString(strs[i]);
|
|
21483
|
-
}
|
|
21484
|
-
var paddingBytes = w - bytes % w;
|
|
21485
|
-
var zeros = [];
|
|
21486
|
-
zeros.length = paddingBytes;
|
|
21487
|
-
this.update(zeros);
|
|
21488
|
-
return this;
|
|
21489
|
-
};
|
|
21490
|
-
|
|
21491
|
-
Keccak.prototype.finalize = function () {
|
|
21492
|
-
if (this.finalized) {
|
|
21493
|
-
return;
|
|
21494
|
-
}
|
|
21495
|
-
this.finalized = true;
|
|
21496
|
-
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
|
|
21497
|
-
blocks[i >> 2] |= this.padding[i & 3];
|
|
21498
|
-
if (this.lastByteIndex === this.byteCount) {
|
|
21499
|
-
blocks[0] = blocks[blockCount];
|
|
21500
|
-
for (i = 1; i < blockCount + 1; ++i) {
|
|
21501
|
-
blocks[i] = 0;
|
|
21502
|
-
}
|
|
21503
|
-
}
|
|
21504
|
-
blocks[blockCount - 1] |= 0x80000000;
|
|
21505
|
-
for (i = 0; i < blockCount; ++i) {
|
|
21506
|
-
s[i] ^= blocks[i];
|
|
21507
|
-
}
|
|
21508
|
-
f(s);
|
|
21509
|
-
};
|
|
21510
|
-
|
|
21511
|
-
Keccak.prototype.toString = Keccak.prototype.hex = function () {
|
|
21512
|
-
this.finalize();
|
|
21513
|
-
|
|
21514
|
-
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
21515
|
-
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
21516
|
-
var hex = '', block;
|
|
21517
|
-
while (j < outputBlocks) {
|
|
21518
|
-
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
21519
|
-
block = s[i];
|
|
21520
|
-
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
|
|
21521
|
-
HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
|
|
21522
|
-
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
|
21523
|
-
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
21524
|
-
}
|
|
21525
|
-
if (j % blockCount === 0) {
|
|
21526
|
-
f(s);
|
|
21527
|
-
i = 0;
|
|
21528
|
-
}
|
|
21529
|
-
}
|
|
21530
|
-
if (extraBytes) {
|
|
21531
|
-
block = s[i];
|
|
21532
|
-
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
|
|
21533
|
-
if (extraBytes > 1) {
|
|
21534
|
-
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
|
|
21535
|
-
}
|
|
21536
|
-
if (extraBytes > 2) {
|
|
21537
|
-
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
|
|
21538
|
-
}
|
|
21539
|
-
}
|
|
21540
|
-
return hex;
|
|
21541
|
-
};
|
|
21542
|
-
|
|
21543
|
-
Keccak.prototype.arrayBuffer = function () {
|
|
21544
|
-
this.finalize();
|
|
21545
|
-
|
|
21546
|
-
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
21547
|
-
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
21548
|
-
var bytes = this.outputBits >> 3;
|
|
21549
|
-
var buffer;
|
|
21550
|
-
if (extraBytes) {
|
|
21551
|
-
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
|
|
21552
|
-
} else {
|
|
21553
|
-
buffer = new ArrayBuffer(bytes);
|
|
21554
|
-
}
|
|
21555
|
-
var array = new Uint32Array(buffer);
|
|
21556
|
-
while (j < outputBlocks) {
|
|
21557
|
-
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
21558
|
-
array[j] = s[i];
|
|
21559
|
-
}
|
|
21560
|
-
if (j % blockCount === 0) {
|
|
21561
|
-
f(s);
|
|
21562
|
-
}
|
|
21563
|
-
}
|
|
21564
|
-
if (extraBytes) {
|
|
21565
|
-
array[i] = s[i];
|
|
21566
|
-
buffer = buffer.slice(0, bytes);
|
|
21567
|
-
}
|
|
21568
|
-
return buffer;
|
|
21569
|
-
};
|
|
21570
|
-
|
|
21571
|
-
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
|
|
21572
|
-
|
|
21573
|
-
Keccak.prototype.digest = Keccak.prototype.array = function () {
|
|
21574
|
-
this.finalize();
|
|
21575
|
-
|
|
21576
|
-
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
21577
|
-
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
21578
|
-
var array = [], offset, block;
|
|
21579
|
-
while (j < outputBlocks) {
|
|
21580
|
-
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
21581
|
-
offset = j << 2;
|
|
21582
|
-
block = s[i];
|
|
21583
|
-
array[offset] = block & 0xFF;
|
|
21584
|
-
array[offset + 1] = (block >> 8) & 0xFF;
|
|
21585
|
-
array[offset + 2] = (block >> 16) & 0xFF;
|
|
21586
|
-
array[offset + 3] = (block >> 24) & 0xFF;
|
|
21587
|
-
}
|
|
21588
|
-
if (j % blockCount === 0) {
|
|
21589
|
-
f(s);
|
|
21590
|
-
}
|
|
21591
|
-
}
|
|
21592
|
-
if (extraBytes) {
|
|
21593
|
-
offset = j << 2;
|
|
21594
|
-
block = s[i];
|
|
21595
|
-
array[offset] = block & 0xFF;
|
|
21596
|
-
if (extraBytes > 1) {
|
|
21597
|
-
array[offset + 1] = (block >> 8) & 0xFF;
|
|
21598
|
-
}
|
|
21599
|
-
if (extraBytes > 2) {
|
|
21600
|
-
array[offset + 2] = (block >> 16) & 0xFF;
|
|
21601
|
-
}
|
|
21602
|
-
}
|
|
21603
|
-
return array;
|
|
21604
|
-
};
|
|
21605
|
-
|
|
21606
|
-
function Kmac(bits, padding, outputBits) {
|
|
21607
|
-
Keccak.call(this, bits, padding, outputBits);
|
|
21608
|
-
}
|
|
21609
|
-
|
|
21610
|
-
Kmac.prototype = new Keccak();
|
|
21611
|
-
|
|
21612
|
-
Kmac.prototype.finalize = function () {
|
|
21613
|
-
this.encode(this.outputBits, true);
|
|
21614
|
-
return Keccak.prototype.finalize.call(this);
|
|
21615
|
-
};
|
|
21616
|
-
|
|
21617
|
-
var f = function (s) {
|
|
21618
|
-
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
|
21619
|
-
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
|
21620
|
-
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
|
21621
|
-
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
|
21622
|
-
for (n = 0; n < 48; n += 2) {
|
|
21623
|
-
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
|
21624
|
-
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
|
21625
|
-
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
|
21626
|
-
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
|
21627
|
-
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
|
21628
|
-
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
|
21629
|
-
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
|
21630
|
-
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
|
21631
|
-
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
|
21632
|
-
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
|
21633
|
-
|
|
21634
|
-
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
|
21635
|
-
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
|
21636
|
-
s[0] ^= h;
|
|
21637
|
-
s[1] ^= l;
|
|
21638
|
-
s[10] ^= h;
|
|
21639
|
-
s[11] ^= l;
|
|
21640
|
-
s[20] ^= h;
|
|
21641
|
-
s[21] ^= l;
|
|
21642
|
-
s[30] ^= h;
|
|
21643
|
-
s[31] ^= l;
|
|
21644
|
-
s[40] ^= h;
|
|
21645
|
-
s[41] ^= l;
|
|
21646
|
-
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
|
21647
|
-
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
|
21648
|
-
s[2] ^= h;
|
|
21649
|
-
s[3] ^= l;
|
|
21650
|
-
s[12] ^= h;
|
|
21651
|
-
s[13] ^= l;
|
|
21652
|
-
s[22] ^= h;
|
|
21653
|
-
s[23] ^= l;
|
|
21654
|
-
s[32] ^= h;
|
|
21655
|
-
s[33] ^= l;
|
|
21656
|
-
s[42] ^= h;
|
|
21657
|
-
s[43] ^= l;
|
|
21658
|
-
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
|
21659
|
-
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
|
21660
|
-
s[4] ^= h;
|
|
21661
|
-
s[5] ^= l;
|
|
21662
|
-
s[14] ^= h;
|
|
21663
|
-
s[15] ^= l;
|
|
21664
|
-
s[24] ^= h;
|
|
21665
|
-
s[25] ^= l;
|
|
21666
|
-
s[34] ^= h;
|
|
21667
|
-
s[35] ^= l;
|
|
21668
|
-
s[44] ^= h;
|
|
21669
|
-
s[45] ^= l;
|
|
21670
|
-
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
|
21671
|
-
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
|
21672
|
-
s[6] ^= h;
|
|
21673
|
-
s[7] ^= l;
|
|
21674
|
-
s[16] ^= h;
|
|
21675
|
-
s[17] ^= l;
|
|
21676
|
-
s[26] ^= h;
|
|
21677
|
-
s[27] ^= l;
|
|
21678
|
-
s[36] ^= h;
|
|
21679
|
-
s[37] ^= l;
|
|
21680
|
-
s[46] ^= h;
|
|
21681
|
-
s[47] ^= l;
|
|
21682
|
-
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
|
21683
|
-
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
|
21684
|
-
s[8] ^= h;
|
|
21685
|
-
s[9] ^= l;
|
|
21686
|
-
s[18] ^= h;
|
|
21687
|
-
s[19] ^= l;
|
|
21688
|
-
s[28] ^= h;
|
|
21689
|
-
s[29] ^= l;
|
|
21690
|
-
s[38] ^= h;
|
|
21691
|
-
s[39] ^= l;
|
|
21692
|
-
s[48] ^= h;
|
|
21693
|
-
s[49] ^= l;
|
|
21694
|
-
|
|
21695
|
-
b0 = s[0];
|
|
21696
|
-
b1 = s[1];
|
|
21697
|
-
b32 = (s[11] << 4) | (s[10] >>> 28);
|
|
21698
|
-
b33 = (s[10] << 4) | (s[11] >>> 28);
|
|
21699
|
-
b14 = (s[20] << 3) | (s[21] >>> 29);
|
|
21700
|
-
b15 = (s[21] << 3) | (s[20] >>> 29);
|
|
21701
|
-
b46 = (s[31] << 9) | (s[30] >>> 23);
|
|
21702
|
-
b47 = (s[30] << 9) | (s[31] >>> 23);
|
|
21703
|
-
b28 = (s[40] << 18) | (s[41] >>> 14);
|
|
21704
|
-
b29 = (s[41] << 18) | (s[40] >>> 14);
|
|
21705
|
-
b20 = (s[2] << 1) | (s[3] >>> 31);
|
|
21706
|
-
b21 = (s[3] << 1) | (s[2] >>> 31);
|
|
21707
|
-
b2 = (s[13] << 12) | (s[12] >>> 20);
|
|
21708
|
-
b3 = (s[12] << 12) | (s[13] >>> 20);
|
|
21709
|
-
b34 = (s[22] << 10) | (s[23] >>> 22);
|
|
21710
|
-
b35 = (s[23] << 10) | (s[22] >>> 22);
|
|
21711
|
-
b16 = (s[33] << 13) | (s[32] >>> 19);
|
|
21712
|
-
b17 = (s[32] << 13) | (s[33] >>> 19);
|
|
21713
|
-
b48 = (s[42] << 2) | (s[43] >>> 30);
|
|
21714
|
-
b49 = (s[43] << 2) | (s[42] >>> 30);
|
|
21715
|
-
b40 = (s[5] << 30) | (s[4] >>> 2);
|
|
21716
|
-
b41 = (s[4] << 30) | (s[5] >>> 2);
|
|
21717
|
-
b22 = (s[14] << 6) | (s[15] >>> 26);
|
|
21718
|
-
b23 = (s[15] << 6) | (s[14] >>> 26);
|
|
21719
|
-
b4 = (s[25] << 11) | (s[24] >>> 21);
|
|
21720
|
-
b5 = (s[24] << 11) | (s[25] >>> 21);
|
|
21721
|
-
b36 = (s[34] << 15) | (s[35] >>> 17);
|
|
21722
|
-
b37 = (s[35] << 15) | (s[34] >>> 17);
|
|
21723
|
-
b18 = (s[45] << 29) | (s[44] >>> 3);
|
|
21724
|
-
b19 = (s[44] << 29) | (s[45] >>> 3);
|
|
21725
|
-
b10 = (s[6] << 28) | (s[7] >>> 4);
|
|
21726
|
-
b11 = (s[7] << 28) | (s[6] >>> 4);
|
|
21727
|
-
b42 = (s[17] << 23) | (s[16] >>> 9);
|
|
21728
|
-
b43 = (s[16] << 23) | (s[17] >>> 9);
|
|
21729
|
-
b24 = (s[26] << 25) | (s[27] >>> 7);
|
|
21730
|
-
b25 = (s[27] << 25) | (s[26] >>> 7);
|
|
21731
|
-
b6 = (s[36] << 21) | (s[37] >>> 11);
|
|
21732
|
-
b7 = (s[37] << 21) | (s[36] >>> 11);
|
|
21733
|
-
b38 = (s[47] << 24) | (s[46] >>> 8);
|
|
21734
|
-
b39 = (s[46] << 24) | (s[47] >>> 8);
|
|
21735
|
-
b30 = (s[8] << 27) | (s[9] >>> 5);
|
|
21736
|
-
b31 = (s[9] << 27) | (s[8] >>> 5);
|
|
21737
|
-
b12 = (s[18] << 20) | (s[19] >>> 12);
|
|
21738
|
-
b13 = (s[19] << 20) | (s[18] >>> 12);
|
|
21739
|
-
b44 = (s[29] << 7) | (s[28] >>> 25);
|
|
21740
|
-
b45 = (s[28] << 7) | (s[29] >>> 25);
|
|
21741
|
-
b26 = (s[38] << 8) | (s[39] >>> 24);
|
|
21742
|
-
b27 = (s[39] << 8) | (s[38] >>> 24);
|
|
21743
|
-
b8 = (s[48] << 14) | (s[49] >>> 18);
|
|
21744
|
-
b9 = (s[49] << 14) | (s[48] >>> 18);
|
|
21745
|
-
|
|
21746
|
-
s[0] = b0 ^ (~b2 & b4);
|
|
21747
|
-
s[1] = b1 ^ (~b3 & b5);
|
|
21748
|
-
s[10] = b10 ^ (~b12 & b14);
|
|
21749
|
-
s[11] = b11 ^ (~b13 & b15);
|
|
21750
|
-
s[20] = b20 ^ (~b22 & b24);
|
|
21751
|
-
s[21] = b21 ^ (~b23 & b25);
|
|
21752
|
-
s[30] = b30 ^ (~b32 & b34);
|
|
21753
|
-
s[31] = b31 ^ (~b33 & b35);
|
|
21754
|
-
s[40] = b40 ^ (~b42 & b44);
|
|
21755
|
-
s[41] = b41 ^ (~b43 & b45);
|
|
21756
|
-
s[2] = b2 ^ (~b4 & b6);
|
|
21757
|
-
s[3] = b3 ^ (~b5 & b7);
|
|
21758
|
-
s[12] = b12 ^ (~b14 & b16);
|
|
21759
|
-
s[13] = b13 ^ (~b15 & b17);
|
|
21760
|
-
s[22] = b22 ^ (~b24 & b26);
|
|
21761
|
-
s[23] = b23 ^ (~b25 & b27);
|
|
21762
|
-
s[32] = b32 ^ (~b34 & b36);
|
|
21763
|
-
s[33] = b33 ^ (~b35 & b37);
|
|
21764
|
-
s[42] = b42 ^ (~b44 & b46);
|
|
21765
|
-
s[43] = b43 ^ (~b45 & b47);
|
|
21766
|
-
s[4] = b4 ^ (~b6 & b8);
|
|
21767
|
-
s[5] = b5 ^ (~b7 & b9);
|
|
21768
|
-
s[14] = b14 ^ (~b16 & b18);
|
|
21769
|
-
s[15] = b15 ^ (~b17 & b19);
|
|
21770
|
-
s[24] = b24 ^ (~b26 & b28);
|
|
21771
|
-
s[25] = b25 ^ (~b27 & b29);
|
|
21772
|
-
s[34] = b34 ^ (~b36 & b38);
|
|
21773
|
-
s[35] = b35 ^ (~b37 & b39);
|
|
21774
|
-
s[44] = b44 ^ (~b46 & b48);
|
|
21775
|
-
s[45] = b45 ^ (~b47 & b49);
|
|
21776
|
-
s[6] = b6 ^ (~b8 & b0);
|
|
21777
|
-
s[7] = b7 ^ (~b9 & b1);
|
|
21778
|
-
s[16] = b16 ^ (~b18 & b10);
|
|
21779
|
-
s[17] = b17 ^ (~b19 & b11);
|
|
21780
|
-
s[26] = b26 ^ (~b28 & b20);
|
|
21781
|
-
s[27] = b27 ^ (~b29 & b21);
|
|
21782
|
-
s[36] = b36 ^ (~b38 & b30);
|
|
21783
|
-
s[37] = b37 ^ (~b39 & b31);
|
|
21784
|
-
s[46] = b46 ^ (~b48 & b40);
|
|
21785
|
-
s[47] = b47 ^ (~b49 & b41);
|
|
21786
|
-
s[8] = b8 ^ (~b0 & b2);
|
|
21787
|
-
s[9] = b9 ^ (~b1 & b3);
|
|
21788
|
-
s[18] = b18 ^ (~b10 & b12);
|
|
21789
|
-
s[19] = b19 ^ (~b11 & b13);
|
|
21790
|
-
s[28] = b28 ^ (~b20 & b22);
|
|
21791
|
-
s[29] = b29 ^ (~b21 & b23);
|
|
21792
|
-
s[38] = b38 ^ (~b30 & b32);
|
|
21793
|
-
s[39] = b39 ^ (~b31 & b33);
|
|
21794
|
-
s[48] = b48 ^ (~b40 & b42);
|
|
21795
|
-
s[49] = b49 ^ (~b41 & b43);
|
|
21796
|
-
|
|
21797
|
-
s[0] ^= RC[n];
|
|
21798
|
-
s[1] ^= RC[n + 1];
|
|
21799
|
-
}
|
|
21800
|
-
};
|
|
21801
|
-
|
|
21802
|
-
if (COMMON_JS) {
|
|
21803
|
-
module.exports = methods;
|
|
21804
|
-
} else {
|
|
21805
|
-
for (i = 0; i < methodNames.length; ++i) {
|
|
21806
|
-
root[methodNames[i]] = methods[methodNames[i]];
|
|
21807
|
-
}
|
|
21808
|
-
}
|
|
21809
|
-
})();
|
|
21810
|
-
} (sha3$1));
|
|
21811
|
-
|
|
21812
|
-
var sha3 = sha3$1.exports;
|
|
21846
|
+
gen(0x06, 136, 256 / 8);
|
|
21847
|
+
gen(0x06, 104, 384 / 8);
|
|
21848
|
+
gen(0x06, 72, 512 / 8);
|
|
21849
|
+
gen(0x01, 144, 224 / 8);
|
|
21850
|
+
/**
|
|
21851
|
+
* keccak-256 hash function. Different from SHA3-256.
|
|
21852
|
+
* @param message - that would be hashed
|
|
21853
|
+
*/
|
|
21854
|
+
const keccak_256 = gen(0x01, 136, 256 / 8);
|
|
21855
|
+
gen(0x01, 104, 384 / 8);
|
|
21856
|
+
gen(0x01, 72, 512 / 8);
|
|
21857
|
+
const genShake = (suffix, blockLen, outputLen) => wrapConstructorWithOpts((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === undefined ? outputLen : opts.dkLen, true));
|
|
21858
|
+
genShake(0x1f, 168, 128 / 8);
|
|
21859
|
+
genShake(0x1f, 136, 256 / 8);
|
|
21813
21860
|
|
|
21814
21861
|
// HMAC (RFC 2104)
|
|
21815
21862
|
class HMAC extends Hash {
|
|
@@ -22868,7 +22915,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22868
22915
|
assert$1(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
22869
22916
|
|
|
22870
22917
|
try {
|
|
22871
|
-
return buffer.Buffer.from(
|
|
22918
|
+
return buffer.Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
22872
22919
|
} catch (error) {
|
|
22873
22920
|
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
22874
22921
|
}
|
|
@@ -22968,7 +23015,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
22968
23015
|
/* isCompressed */
|
|
22969
23016
|
).slice(1); // throw away leading byte
|
|
22970
23017
|
|
|
22971
|
-
const messageHash = buffer.Buffer.from(
|
|
23018
|
+
const messageHash = buffer.Buffer.from(keccak_256(toBuffer(message)));
|
|
22972
23019
|
const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
|
|
22973
23020
|
return this.createInstructionWithPublicKey({
|
|
22974
23021
|
publicKey,
|
|
@@ -23862,6 +23909,33 @@ var solanaWeb3 = (function (exports) {
|
|
|
23862
23909
|
}
|
|
23863
23910
|
};
|
|
23864
23911
|
}
|
|
23912
|
+
/**
|
|
23913
|
+
* Decode an authorize instruction and retrieve the instruction params.
|
|
23914
|
+
*/
|
|
23915
|
+
|
|
23916
|
+
|
|
23917
|
+
static decodeAuthorizeWithSeed(instruction) {
|
|
23918
|
+
this.checkProgramId(instruction.programId);
|
|
23919
|
+
this.checkKeyLength(instruction.keys, 3);
|
|
23920
|
+
const {
|
|
23921
|
+
voteAuthorizeWithSeedArgs: {
|
|
23922
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
23923
|
+
currentAuthorityDerivedKeySeed,
|
|
23924
|
+
newAuthorized,
|
|
23925
|
+
voteAuthorizationType
|
|
23926
|
+
}
|
|
23927
|
+
} = decodeData$1(VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed, instruction.data);
|
|
23928
|
+
return {
|
|
23929
|
+
currentAuthorityDerivedKeyBasePubkey: instruction.keys[2].pubkey,
|
|
23930
|
+
currentAuthorityDerivedKeyOwnerPubkey: new PublicKey(currentAuthorityDerivedKeyOwnerPubkey),
|
|
23931
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
23932
|
+
newAuthorizedPubkey: new PublicKey(newAuthorized),
|
|
23933
|
+
voteAuthorizationType: {
|
|
23934
|
+
index: voteAuthorizationType
|
|
23935
|
+
},
|
|
23936
|
+
votePubkey: instruction.keys[0].pubkey
|
|
23937
|
+
};
|
|
23938
|
+
}
|
|
23865
23939
|
/**
|
|
23866
23940
|
* Decode a withdraw instruction and retrieve the instruction params.
|
|
23867
23941
|
*/
|
|
@@ -23918,6 +23992,10 @@ var solanaWeb3 = (function (exports) {
|
|
|
23918
23992
|
Withdraw: {
|
|
23919
23993
|
index: 3,
|
|
23920
23994
|
layout: struct([u32('instruction'), ns64('lamports')])
|
|
23995
|
+
},
|
|
23996
|
+
AuthorizeWithSeed: {
|
|
23997
|
+
index: 10,
|
|
23998
|
+
layout: struct([u32('instruction'), voteAuthorizeWithSeedArgs()])
|
|
23921
23999
|
}
|
|
23922
24000
|
});
|
|
23923
24001
|
/**
|
|
@@ -24046,6 +24124,49 @@ var solanaWeb3 = (function (exports) {
|
|
|
24046
24124
|
data
|
|
24047
24125
|
});
|
|
24048
24126
|
}
|
|
24127
|
+
/**
|
|
24128
|
+
* Generate a transaction that authorizes a new Voter or Withdrawer on the Vote account
|
|
24129
|
+
* where the current Voter or Withdrawer authority is a derived key.
|
|
24130
|
+
*/
|
|
24131
|
+
|
|
24132
|
+
|
|
24133
|
+
static authorizeWithSeed(params) {
|
|
24134
|
+
const {
|
|
24135
|
+
currentAuthorityDerivedKeyBasePubkey,
|
|
24136
|
+
currentAuthorityDerivedKeyOwnerPubkey,
|
|
24137
|
+
currentAuthorityDerivedKeySeed,
|
|
24138
|
+
newAuthorizedPubkey,
|
|
24139
|
+
voteAuthorizationType,
|
|
24140
|
+
votePubkey
|
|
24141
|
+
} = params;
|
|
24142
|
+
const type = VOTE_INSTRUCTION_LAYOUTS.AuthorizeWithSeed;
|
|
24143
|
+
const data = encodeData(type, {
|
|
24144
|
+
voteAuthorizeWithSeedArgs: {
|
|
24145
|
+
currentAuthorityDerivedKeyOwnerPubkey: toBuffer(currentAuthorityDerivedKeyOwnerPubkey.toBuffer()),
|
|
24146
|
+
currentAuthorityDerivedKeySeed: currentAuthorityDerivedKeySeed,
|
|
24147
|
+
newAuthorized: toBuffer(newAuthorizedPubkey.toBuffer()),
|
|
24148
|
+
voteAuthorizationType: voteAuthorizationType.index
|
|
24149
|
+
}
|
|
24150
|
+
});
|
|
24151
|
+
const keys = [{
|
|
24152
|
+
pubkey: votePubkey,
|
|
24153
|
+
isSigner: false,
|
|
24154
|
+
isWritable: true
|
|
24155
|
+
}, {
|
|
24156
|
+
pubkey: SYSVAR_CLOCK_PUBKEY,
|
|
24157
|
+
isSigner: false,
|
|
24158
|
+
isWritable: false
|
|
24159
|
+
}, {
|
|
24160
|
+
pubkey: currentAuthorityDerivedKeyBasePubkey,
|
|
24161
|
+
isSigner: true,
|
|
24162
|
+
isWritable: false
|
|
24163
|
+
}];
|
|
24164
|
+
return new Transaction().add({
|
|
24165
|
+
keys,
|
|
24166
|
+
programId: this.programId,
|
|
24167
|
+
data
|
|
24168
|
+
});
|
|
24169
|
+
}
|
|
24049
24170
|
/**
|
|
24050
24171
|
* Generate a transaction to withdraw from a Vote account.
|
|
24051
24172
|
*/
|
|
@@ -24392,6 +24513,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
24392
24513
|
exports.Lockup = Lockup;
|
|
24393
24514
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|
|
24394
24515
|
exports.Message = Message;
|
|
24516
|
+
exports.MessageAccountKeys = MessageAccountKeys;
|
|
24395
24517
|
exports.MessageV0 = MessageV0;
|
|
24396
24518
|
exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
|
|
24397
24519
|
exports.NonceAccount = NonceAccount;
|
|
@@ -24426,6 +24548,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
24426
24548
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
24427
24549
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
24428
24550
|
exports.TransactionInstruction = TransactionInstruction;
|
|
24551
|
+
exports.TransactionMessage = TransactionMessage;
|
|
24429
24552
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
24430
24553
|
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
24431
24554
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|