@solana/web3.js 1.58.0 → 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.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$1 = BigInt(0);
2836
- const _1n$1 = BigInt(1);
2837
- const _2n$1 = BigInt(2);
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$1 ** BigInt(252) + BigInt('27742317777372353535851937790883648493');
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$1 ** _255n - BigInt(19),
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$1 ** BigInt(256);
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$1, mod$1(p.x * p.y));
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$1);
2896
- const B = mod$1(Y1 ** _2n$1);
2897
- const C = mod$1(_2n$1 * mod$1(Z1 ** _2n$1));
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$1) - A - B);
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$1)
2925
+ if (F === _0n$2)
2917
2926
  return this.double();
2918
- const C = mod$1(Z1 * _2n$1 * T2);
2919
- const D = mod$1(T1 * _2n$1 * Z2);
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$1;
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$1)
3009
+ if (n === _0n$2)
3001
3010
  return P0;
3002
- if (this.equals(P0) || n === _1n$1)
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$1) {
3009
- if (n & _1n$1)
3017
+ while (n > _0n$2) {
3018
+ if (n & _1n$2)
3010
3019
  p = p.add(d);
3011
3020
  d = d.double();
3012
- n >>= _1n$1;
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$1)
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$1, mod$1(CURVE$1.Gx * CURVE$1.Gy));
3042
- ExtendedPoint.ZERO = new ExtendedPoint(_0n$1, _1n$1, _1n$1, _0n$1);
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$1);
3072
- const v = mod$1(d * y2 + _1n$1);
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$1) === _1n$1;
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$1 ? 0x80 : 0;
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$1 + y) * invert$1(_1n$1 - y));
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$1, _1n$1);
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$1) === _1n$1;
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$1 ? res : b + res;
3217
+ return res >= _0n$2 ? res : b + res;
3209
3218
  }
3210
3219
  function invert$1(number, modulo = CURVE$1.P) {
3211
- if (number === _0n$1 || modulo <= _0n$1) {
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$1, u = _1n$1;
3217
- while (a !== _0n$1) {
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$1)
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$1)
3240
+ if (num === _0n$2)
3232
3241
  return acc;
3233
3242
  tmp[i] = acc;
3234
3243
  return mod$1(acc * num, p);
3235
- }, _1n$1);
3244
+ }, _1n$2);
3236
3245
  const inverted = invert$1(lastMultiplied, p);
3237
3246
  nums.reduceRight((acc, num, i) => {
3238
- if (num === _0n$1)
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$1) {
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$1) * b2) % P;
3264
- const b5 = (pow2$1(b4, _1n$1) * x) % P;
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$1) * x) % P;
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$1 < num)
3319
+ if (_0n$2 < num)
3311
3320
  return num;
3312
3321
  }
3313
3322
  else {
3314
- if (_0n$1 <= num)
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$1) + _1n$1;
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$1);
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
 
@@ -21635,662 +21655,208 @@ var solanaWeb3 = (function (exports) {
21635
21655
  }
21636
21656
  Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
21637
21657
 
21638
- var sha3$1 = {exports: {}};
21639
-
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);
21640
21842
  /**
21641
- * [js-sha3]{@link https://github.com/emn178/js-sha3}
21642
- *
21643
- * @version 0.8.0
21644
- * @author Chen, Yi-Cyuan [emn178@gmail.com]
21645
- * @copyright Chen, Yi-Cyuan 2015-2018
21646
- * @license MIT
21843
+ * SHA3-256 hash function
21844
+ * @param message - that would be hashed
21647
21845
  */
21648
-
21649
- (function (module) {
21650
- /*jslint bitwise: true */
21651
- (function () {
21652
-
21653
- var INPUT_ERROR = 'input is invalid type';
21654
- var FINALIZE_ERROR = 'finalize already called';
21655
- var WINDOW = typeof window === 'object';
21656
- var root = WINDOW ? window : {};
21657
- if (root.JS_SHA3_NO_WINDOW) {
21658
- WINDOW = false;
21659
- }
21660
- var WEB_WORKER = !WINDOW && typeof self === 'object';
21661
- var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
21662
- if (NODE_JS) {
21663
- root = commonjsGlobal;
21664
- } else if (WEB_WORKER) {
21665
- root = self;
21666
- }
21667
- var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && 'object' === 'object' && module.exports;
21668
- var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
21669
- var HEX_CHARS = '0123456789abcdef'.split('');
21670
- var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
21671
- var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
21672
- var KECCAK_PADDING = [1, 256, 65536, 16777216];
21673
- var PADDING = [6, 1536, 393216, 100663296];
21674
- var SHIFT = [0, 8, 16, 24];
21675
- var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
21676
- 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
21677
- 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
21678
- 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
21679
- 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
21680
- var BITS = [224, 256, 384, 512];
21681
- var SHAKE_BITS = [128, 256];
21682
- var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest'];
21683
- var CSHAKE_BYTEPAD = {
21684
- '128': 168,
21685
- '256': 136
21686
- };
21687
-
21688
- if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
21689
- Array.isArray = function (obj) {
21690
- return Object.prototype.toString.call(obj) === '[object Array]';
21691
- };
21692
- }
21693
-
21694
- if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
21695
- ArrayBuffer.isView = function (obj) {
21696
- return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
21697
- };
21698
- }
21699
-
21700
- var createOutputMethod = function (bits, padding, outputType) {
21701
- return function (message) {
21702
- return new Keccak(bits, padding, bits).update(message)[outputType]();
21703
- };
21704
- };
21705
-
21706
- var createShakeOutputMethod = function (bits, padding, outputType) {
21707
- return function (message, outputBits) {
21708
- return new Keccak(bits, padding, outputBits).update(message)[outputType]();
21709
- };
21710
- };
21711
-
21712
- var createCshakeOutputMethod = function (bits, padding, outputType) {
21713
- return function (message, outputBits, n, s) {
21714
- return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
21715
- };
21716
- };
21717
-
21718
- var createKmacOutputMethod = function (bits, padding, outputType) {
21719
- return function (key, message, outputBits, s) {
21720
- return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
21721
- };
21722
- };
21723
-
21724
- var createOutputMethods = function (method, createMethod, bits, padding) {
21725
- for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
21726
- var type = OUTPUT_TYPES[i];
21727
- method[type] = createMethod(bits, padding, type);
21728
- }
21729
- return method;
21730
- };
21731
-
21732
- var createMethod = function (bits, padding) {
21733
- var method = createOutputMethod(bits, padding, 'hex');
21734
- method.create = function () {
21735
- return new Keccak(bits, padding, bits);
21736
- };
21737
- method.update = function (message) {
21738
- return method.create().update(message);
21739
- };
21740
- return createOutputMethods(method, createOutputMethod, bits, padding);
21741
- };
21742
-
21743
- var createShakeMethod = function (bits, padding) {
21744
- var method = createShakeOutputMethod(bits, padding, 'hex');
21745
- method.create = function (outputBits) {
21746
- return new Keccak(bits, padding, outputBits);
21747
- };
21748
- method.update = function (message, outputBits) {
21749
- return method.create(outputBits).update(message);
21750
- };
21751
- return createOutputMethods(method, createShakeOutputMethod, bits, padding);
21752
- };
21753
-
21754
- var createCshakeMethod = function (bits, padding) {
21755
- var w = CSHAKE_BYTEPAD[bits];
21756
- var method = createCshakeOutputMethod(bits, padding, 'hex');
21757
- method.create = function (outputBits, n, s) {
21758
- if (!n && !s) {
21759
- return methods['shake' + bits].create(outputBits);
21760
- } else {
21761
- return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
21762
- }
21763
- };
21764
- method.update = function (message, outputBits, n, s) {
21765
- return method.create(outputBits, n, s).update(message);
21766
- };
21767
- return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
21768
- };
21769
-
21770
- var createKmacMethod = function (bits, padding) {
21771
- var w = CSHAKE_BYTEPAD[bits];
21772
- var method = createKmacOutputMethod(bits, padding, 'hex');
21773
- method.create = function (key, outputBits, s) {
21774
- return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
21775
- };
21776
- method.update = function (key, message, outputBits, s) {
21777
- return method.create(key, outputBits, s).update(message);
21778
- };
21779
- return createOutputMethods(method, createKmacOutputMethod, bits, padding);
21780
- };
21781
-
21782
- var algorithms = [
21783
- { name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
21784
- { name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
21785
- { name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
21786
- { name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
21787
- { name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
21788
- ];
21789
-
21790
- var methods = {}, methodNames = [];
21791
-
21792
- for (var i = 0; i < algorithms.length; ++i) {
21793
- var algorithm = algorithms[i];
21794
- var bits = algorithm.bits;
21795
- for (var j = 0; j < bits.length; ++j) {
21796
- var methodName = algorithm.name + '_' + bits[j];
21797
- methodNames.push(methodName);
21798
- methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
21799
- if (algorithm.name !== 'sha3') {
21800
- var newMethodName = algorithm.name + bits[j];
21801
- methodNames.push(newMethodName);
21802
- methods[newMethodName] = methods[methodName];
21803
- }
21804
- }
21805
- }
21806
-
21807
- function Keccak(bits, padding, outputBits) {
21808
- this.blocks = [];
21809
- this.s = [];
21810
- this.padding = padding;
21811
- this.outputBits = outputBits;
21812
- this.reset = true;
21813
- this.finalized = false;
21814
- this.block = 0;
21815
- this.start = 0;
21816
- this.blockCount = (1600 - (bits << 1)) >> 5;
21817
- this.byteCount = this.blockCount << 2;
21818
- this.outputBlocks = outputBits >> 5;
21819
- this.extraBytes = (outputBits & 31) >> 3;
21820
-
21821
- for (var i = 0; i < 50; ++i) {
21822
- this.s[i] = 0;
21823
- }
21824
- }
21825
-
21826
- Keccak.prototype.update = function (message) {
21827
- if (this.finalized) {
21828
- throw new Error(FINALIZE_ERROR);
21829
- }
21830
- var notString, type = typeof message;
21831
- if (type !== 'string') {
21832
- if (type === 'object') {
21833
- if (message === null) {
21834
- throw new Error(INPUT_ERROR);
21835
- } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
21836
- message = new Uint8Array(message);
21837
- } else if (!Array.isArray(message)) {
21838
- if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
21839
- throw new Error(INPUT_ERROR);
21840
- }
21841
- }
21842
- } else {
21843
- throw new Error(INPUT_ERROR);
21844
- }
21845
- notString = true;
21846
- }
21847
- var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
21848
- blockCount = this.blockCount, index = 0, s = this.s, i, code;
21849
-
21850
- while (index < length) {
21851
- if (this.reset) {
21852
- this.reset = false;
21853
- blocks[0] = this.block;
21854
- for (i = 1; i < blockCount + 1; ++i) {
21855
- blocks[i] = 0;
21856
- }
21857
- }
21858
- if (notString) {
21859
- for (i = this.start; index < length && i < byteCount; ++index) {
21860
- blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
21861
- }
21862
- } else {
21863
- for (i = this.start; index < length && i < byteCount; ++index) {
21864
- code = message.charCodeAt(index);
21865
- if (code < 0x80) {
21866
- blocks[i >> 2] |= code << SHIFT[i++ & 3];
21867
- } else if (code < 0x800) {
21868
- blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
21869
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
21870
- } else if (code < 0xd800 || code >= 0xe000) {
21871
- blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
21872
- blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
21873
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
21874
- } else {
21875
- code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
21876
- blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
21877
- blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
21878
- blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
21879
- blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
21880
- }
21881
- }
21882
- }
21883
- this.lastByteIndex = i;
21884
- if (i >= byteCount) {
21885
- this.start = i - byteCount;
21886
- this.block = blocks[blockCount];
21887
- for (i = 0; i < blockCount; ++i) {
21888
- s[i] ^= blocks[i];
21889
- }
21890
- f(s);
21891
- this.reset = true;
21892
- } else {
21893
- this.start = i;
21894
- }
21895
- }
21896
- return this;
21897
- };
21898
-
21899
- Keccak.prototype.encode = function (x, right) {
21900
- var o = x & 255, n = 1;
21901
- var bytes = [o];
21902
- x = x >> 8;
21903
- o = x & 255;
21904
- while (o > 0) {
21905
- bytes.unshift(o);
21906
- x = x >> 8;
21907
- o = x & 255;
21908
- ++n;
21909
- }
21910
- if (right) {
21911
- bytes.push(n);
21912
- } else {
21913
- bytes.unshift(n);
21914
- }
21915
- this.update(bytes);
21916
- return bytes.length;
21917
- };
21918
-
21919
- Keccak.prototype.encodeString = function (str) {
21920
- var notString, type = typeof str;
21921
- if (type !== 'string') {
21922
- if (type === 'object') {
21923
- if (str === null) {
21924
- throw new Error(INPUT_ERROR);
21925
- } else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) {
21926
- str = new Uint8Array(str);
21927
- } else if (!Array.isArray(str)) {
21928
- if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) {
21929
- throw new Error(INPUT_ERROR);
21930
- }
21931
- }
21932
- } else {
21933
- throw new Error(INPUT_ERROR);
21934
- }
21935
- notString = true;
21936
- }
21937
- var bytes = 0, length = str.length;
21938
- if (notString) {
21939
- bytes = length;
21940
- } else {
21941
- for (var i = 0; i < str.length; ++i) {
21942
- var code = str.charCodeAt(i);
21943
- if (code < 0x80) {
21944
- bytes += 1;
21945
- } else if (code < 0x800) {
21946
- bytes += 2;
21947
- } else if (code < 0xd800 || code >= 0xe000) {
21948
- bytes += 3;
21949
- } else {
21950
- code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
21951
- bytes += 4;
21952
- }
21953
- }
21954
- }
21955
- bytes += this.encode(bytes * 8);
21956
- this.update(str);
21957
- return bytes;
21958
- };
21959
-
21960
- Keccak.prototype.bytepad = function (strs, w) {
21961
- var bytes = this.encode(w);
21962
- for (var i = 0; i < strs.length; ++i) {
21963
- bytes += this.encodeString(strs[i]);
21964
- }
21965
- var paddingBytes = w - bytes % w;
21966
- var zeros = [];
21967
- zeros.length = paddingBytes;
21968
- this.update(zeros);
21969
- return this;
21970
- };
21971
-
21972
- Keccak.prototype.finalize = function () {
21973
- if (this.finalized) {
21974
- return;
21975
- }
21976
- this.finalized = true;
21977
- var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
21978
- blocks[i >> 2] |= this.padding[i & 3];
21979
- if (this.lastByteIndex === this.byteCount) {
21980
- blocks[0] = blocks[blockCount];
21981
- for (i = 1; i < blockCount + 1; ++i) {
21982
- blocks[i] = 0;
21983
- }
21984
- }
21985
- blocks[blockCount - 1] |= 0x80000000;
21986
- for (i = 0; i < blockCount; ++i) {
21987
- s[i] ^= blocks[i];
21988
- }
21989
- f(s);
21990
- };
21991
-
21992
- Keccak.prototype.toString = Keccak.prototype.hex = function () {
21993
- this.finalize();
21994
-
21995
- var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
21996
- extraBytes = this.extraBytes, i = 0, j = 0;
21997
- var hex = '', block;
21998
- while (j < outputBlocks) {
21999
- for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
22000
- block = s[i];
22001
- hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
22002
- HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
22003
- HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
22004
- HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
22005
- }
22006
- if (j % blockCount === 0) {
22007
- f(s);
22008
- i = 0;
22009
- }
22010
- }
22011
- if (extraBytes) {
22012
- block = s[i];
22013
- hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
22014
- if (extraBytes > 1) {
22015
- hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
22016
- }
22017
- if (extraBytes > 2) {
22018
- hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
22019
- }
22020
- }
22021
- return hex;
22022
- };
22023
-
22024
- Keccak.prototype.arrayBuffer = function () {
22025
- this.finalize();
22026
-
22027
- var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
22028
- extraBytes = this.extraBytes, i = 0, j = 0;
22029
- var bytes = this.outputBits >> 3;
22030
- var buffer;
22031
- if (extraBytes) {
22032
- buffer = new ArrayBuffer((outputBlocks + 1) << 2);
22033
- } else {
22034
- buffer = new ArrayBuffer(bytes);
22035
- }
22036
- var array = new Uint32Array(buffer);
22037
- while (j < outputBlocks) {
22038
- for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
22039
- array[j] = s[i];
22040
- }
22041
- if (j % blockCount === 0) {
22042
- f(s);
22043
- }
22044
- }
22045
- if (extraBytes) {
22046
- array[i] = s[i];
22047
- buffer = buffer.slice(0, bytes);
22048
- }
22049
- return buffer;
22050
- };
22051
-
22052
- Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
22053
-
22054
- Keccak.prototype.digest = Keccak.prototype.array = function () {
22055
- this.finalize();
22056
-
22057
- var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
22058
- extraBytes = this.extraBytes, i = 0, j = 0;
22059
- var array = [], offset, block;
22060
- while (j < outputBlocks) {
22061
- for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
22062
- offset = j << 2;
22063
- block = s[i];
22064
- array[offset] = block & 0xFF;
22065
- array[offset + 1] = (block >> 8) & 0xFF;
22066
- array[offset + 2] = (block >> 16) & 0xFF;
22067
- array[offset + 3] = (block >> 24) & 0xFF;
22068
- }
22069
- if (j % blockCount === 0) {
22070
- f(s);
22071
- }
22072
- }
22073
- if (extraBytes) {
22074
- offset = j << 2;
22075
- block = s[i];
22076
- array[offset] = block & 0xFF;
22077
- if (extraBytes > 1) {
22078
- array[offset + 1] = (block >> 8) & 0xFF;
22079
- }
22080
- if (extraBytes > 2) {
22081
- array[offset + 2] = (block >> 16) & 0xFF;
22082
- }
22083
- }
22084
- return array;
22085
- };
22086
-
22087
- function Kmac(bits, padding, outputBits) {
22088
- Keccak.call(this, bits, padding, outputBits);
22089
- }
22090
-
22091
- Kmac.prototype = new Keccak();
22092
-
22093
- Kmac.prototype.finalize = function () {
22094
- this.encode(this.outputBits, true);
22095
- return Keccak.prototype.finalize.call(this);
22096
- };
22097
-
22098
- var f = function (s) {
22099
- var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
22100
- b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
22101
- b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
22102
- b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
22103
- for (n = 0; n < 48; n += 2) {
22104
- c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
22105
- c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
22106
- c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
22107
- c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
22108
- c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
22109
- c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
22110
- c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
22111
- c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
22112
- c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
22113
- c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
22114
-
22115
- h = c8 ^ ((c2 << 1) | (c3 >>> 31));
22116
- l = c9 ^ ((c3 << 1) | (c2 >>> 31));
22117
- s[0] ^= h;
22118
- s[1] ^= l;
22119
- s[10] ^= h;
22120
- s[11] ^= l;
22121
- s[20] ^= h;
22122
- s[21] ^= l;
22123
- s[30] ^= h;
22124
- s[31] ^= l;
22125
- s[40] ^= h;
22126
- s[41] ^= l;
22127
- h = c0 ^ ((c4 << 1) | (c5 >>> 31));
22128
- l = c1 ^ ((c5 << 1) | (c4 >>> 31));
22129
- s[2] ^= h;
22130
- s[3] ^= l;
22131
- s[12] ^= h;
22132
- s[13] ^= l;
22133
- s[22] ^= h;
22134
- s[23] ^= l;
22135
- s[32] ^= h;
22136
- s[33] ^= l;
22137
- s[42] ^= h;
22138
- s[43] ^= l;
22139
- h = c2 ^ ((c6 << 1) | (c7 >>> 31));
22140
- l = c3 ^ ((c7 << 1) | (c6 >>> 31));
22141
- s[4] ^= h;
22142
- s[5] ^= l;
22143
- s[14] ^= h;
22144
- s[15] ^= l;
22145
- s[24] ^= h;
22146
- s[25] ^= l;
22147
- s[34] ^= h;
22148
- s[35] ^= l;
22149
- s[44] ^= h;
22150
- s[45] ^= l;
22151
- h = c4 ^ ((c8 << 1) | (c9 >>> 31));
22152
- l = c5 ^ ((c9 << 1) | (c8 >>> 31));
22153
- s[6] ^= h;
22154
- s[7] ^= l;
22155
- s[16] ^= h;
22156
- s[17] ^= l;
22157
- s[26] ^= h;
22158
- s[27] ^= l;
22159
- s[36] ^= h;
22160
- s[37] ^= l;
22161
- s[46] ^= h;
22162
- s[47] ^= l;
22163
- h = c6 ^ ((c0 << 1) | (c1 >>> 31));
22164
- l = c7 ^ ((c1 << 1) | (c0 >>> 31));
22165
- s[8] ^= h;
22166
- s[9] ^= l;
22167
- s[18] ^= h;
22168
- s[19] ^= l;
22169
- s[28] ^= h;
22170
- s[29] ^= l;
22171
- s[38] ^= h;
22172
- s[39] ^= l;
22173
- s[48] ^= h;
22174
- s[49] ^= l;
22175
-
22176
- b0 = s[0];
22177
- b1 = s[1];
22178
- b32 = (s[11] << 4) | (s[10] >>> 28);
22179
- b33 = (s[10] << 4) | (s[11] >>> 28);
22180
- b14 = (s[20] << 3) | (s[21] >>> 29);
22181
- b15 = (s[21] << 3) | (s[20] >>> 29);
22182
- b46 = (s[31] << 9) | (s[30] >>> 23);
22183
- b47 = (s[30] << 9) | (s[31] >>> 23);
22184
- b28 = (s[40] << 18) | (s[41] >>> 14);
22185
- b29 = (s[41] << 18) | (s[40] >>> 14);
22186
- b20 = (s[2] << 1) | (s[3] >>> 31);
22187
- b21 = (s[3] << 1) | (s[2] >>> 31);
22188
- b2 = (s[13] << 12) | (s[12] >>> 20);
22189
- b3 = (s[12] << 12) | (s[13] >>> 20);
22190
- b34 = (s[22] << 10) | (s[23] >>> 22);
22191
- b35 = (s[23] << 10) | (s[22] >>> 22);
22192
- b16 = (s[33] << 13) | (s[32] >>> 19);
22193
- b17 = (s[32] << 13) | (s[33] >>> 19);
22194
- b48 = (s[42] << 2) | (s[43] >>> 30);
22195
- b49 = (s[43] << 2) | (s[42] >>> 30);
22196
- b40 = (s[5] << 30) | (s[4] >>> 2);
22197
- b41 = (s[4] << 30) | (s[5] >>> 2);
22198
- b22 = (s[14] << 6) | (s[15] >>> 26);
22199
- b23 = (s[15] << 6) | (s[14] >>> 26);
22200
- b4 = (s[25] << 11) | (s[24] >>> 21);
22201
- b5 = (s[24] << 11) | (s[25] >>> 21);
22202
- b36 = (s[34] << 15) | (s[35] >>> 17);
22203
- b37 = (s[35] << 15) | (s[34] >>> 17);
22204
- b18 = (s[45] << 29) | (s[44] >>> 3);
22205
- b19 = (s[44] << 29) | (s[45] >>> 3);
22206
- b10 = (s[6] << 28) | (s[7] >>> 4);
22207
- b11 = (s[7] << 28) | (s[6] >>> 4);
22208
- b42 = (s[17] << 23) | (s[16] >>> 9);
22209
- b43 = (s[16] << 23) | (s[17] >>> 9);
22210
- b24 = (s[26] << 25) | (s[27] >>> 7);
22211
- b25 = (s[27] << 25) | (s[26] >>> 7);
22212
- b6 = (s[36] << 21) | (s[37] >>> 11);
22213
- b7 = (s[37] << 21) | (s[36] >>> 11);
22214
- b38 = (s[47] << 24) | (s[46] >>> 8);
22215
- b39 = (s[46] << 24) | (s[47] >>> 8);
22216
- b30 = (s[8] << 27) | (s[9] >>> 5);
22217
- b31 = (s[9] << 27) | (s[8] >>> 5);
22218
- b12 = (s[18] << 20) | (s[19] >>> 12);
22219
- b13 = (s[19] << 20) | (s[18] >>> 12);
22220
- b44 = (s[29] << 7) | (s[28] >>> 25);
22221
- b45 = (s[28] << 7) | (s[29] >>> 25);
22222
- b26 = (s[38] << 8) | (s[39] >>> 24);
22223
- b27 = (s[39] << 8) | (s[38] >>> 24);
22224
- b8 = (s[48] << 14) | (s[49] >>> 18);
22225
- b9 = (s[49] << 14) | (s[48] >>> 18);
22226
-
22227
- s[0] = b0 ^ (~b2 & b4);
22228
- s[1] = b1 ^ (~b3 & b5);
22229
- s[10] = b10 ^ (~b12 & b14);
22230
- s[11] = b11 ^ (~b13 & b15);
22231
- s[20] = b20 ^ (~b22 & b24);
22232
- s[21] = b21 ^ (~b23 & b25);
22233
- s[30] = b30 ^ (~b32 & b34);
22234
- s[31] = b31 ^ (~b33 & b35);
22235
- s[40] = b40 ^ (~b42 & b44);
22236
- s[41] = b41 ^ (~b43 & b45);
22237
- s[2] = b2 ^ (~b4 & b6);
22238
- s[3] = b3 ^ (~b5 & b7);
22239
- s[12] = b12 ^ (~b14 & b16);
22240
- s[13] = b13 ^ (~b15 & b17);
22241
- s[22] = b22 ^ (~b24 & b26);
22242
- s[23] = b23 ^ (~b25 & b27);
22243
- s[32] = b32 ^ (~b34 & b36);
22244
- s[33] = b33 ^ (~b35 & b37);
22245
- s[42] = b42 ^ (~b44 & b46);
22246
- s[43] = b43 ^ (~b45 & b47);
22247
- s[4] = b4 ^ (~b6 & b8);
22248
- s[5] = b5 ^ (~b7 & b9);
22249
- s[14] = b14 ^ (~b16 & b18);
22250
- s[15] = b15 ^ (~b17 & b19);
22251
- s[24] = b24 ^ (~b26 & b28);
22252
- s[25] = b25 ^ (~b27 & b29);
22253
- s[34] = b34 ^ (~b36 & b38);
22254
- s[35] = b35 ^ (~b37 & b39);
22255
- s[44] = b44 ^ (~b46 & b48);
22256
- s[45] = b45 ^ (~b47 & b49);
22257
- s[6] = b6 ^ (~b8 & b0);
22258
- s[7] = b7 ^ (~b9 & b1);
22259
- s[16] = b16 ^ (~b18 & b10);
22260
- s[17] = b17 ^ (~b19 & b11);
22261
- s[26] = b26 ^ (~b28 & b20);
22262
- s[27] = b27 ^ (~b29 & b21);
22263
- s[36] = b36 ^ (~b38 & b30);
22264
- s[37] = b37 ^ (~b39 & b31);
22265
- s[46] = b46 ^ (~b48 & b40);
22266
- s[47] = b47 ^ (~b49 & b41);
22267
- s[8] = b8 ^ (~b0 & b2);
22268
- s[9] = b9 ^ (~b1 & b3);
22269
- s[18] = b18 ^ (~b10 & b12);
22270
- s[19] = b19 ^ (~b11 & b13);
22271
- s[28] = b28 ^ (~b20 & b22);
22272
- s[29] = b29 ^ (~b21 & b23);
22273
- s[38] = b38 ^ (~b30 & b32);
22274
- s[39] = b39 ^ (~b31 & b33);
22275
- s[48] = b48 ^ (~b40 & b42);
22276
- s[49] = b49 ^ (~b41 & b43);
22277
-
22278
- s[0] ^= RC[n];
22279
- s[1] ^= RC[n + 1];
22280
- }
22281
- };
22282
-
22283
- if (COMMON_JS) {
22284
- module.exports = methods;
22285
- } else {
22286
- for (i = 0; i < methodNames.length; ++i) {
22287
- root[methodNames[i]] = methods[methodNames[i]];
22288
- }
22289
- }
22290
- })();
22291
- } (sha3$1));
22292
-
22293
- 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);
22294
21860
 
22295
21861
  // HMAC (RFC 2104)
22296
21862
  class HMAC extends Hash {
@@ -23349,7 +22915,7 @@ var solanaWeb3 = (function (exports) {
23349
22915
  assert$1(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
23350
22916
 
23351
22917
  try {
23352
- return buffer.Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
22918
+ return buffer.Buffer.from(keccak_256(toBuffer(publicKey))).slice(-ETHEREUM_ADDRESS_BYTES);
23353
22919
  } catch (error) {
23354
22920
  throw new Error(`Error constructing Ethereum address: ${error}`);
23355
22921
  }
@@ -23449,7 +23015,7 @@ var solanaWeb3 = (function (exports) {
23449
23015
  /* isCompressed */
23450
23016
  ).slice(1); // throw away leading byte
23451
23017
 
23452
- const messageHash = buffer.Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
23018
+ const messageHash = buffer.Buffer.from(keccak_256(toBuffer(message)));
23453
23019
  const [signature, recoveryId] = ecdsaSign(messageHash, privateKey);
23454
23020
  return this.createInstructionWithPublicKey({
23455
23021
  publicKey,
@@ -24343,6 +23909,33 @@ var solanaWeb3 = (function (exports) {
24343
23909
  }
24344
23910
  };
24345
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
+ }
24346
23939
  /**
24347
23940
  * Decode a withdraw instruction and retrieve the instruction params.
24348
23941
  */
@@ -24399,6 +23992,10 @@ var solanaWeb3 = (function (exports) {
24399
23992
  Withdraw: {
24400
23993
  index: 3,
24401
23994
  layout: struct([u32('instruction'), ns64('lamports')])
23995
+ },
23996
+ AuthorizeWithSeed: {
23997
+ index: 10,
23998
+ layout: struct([u32('instruction'), voteAuthorizeWithSeedArgs()])
24402
23999
  }
24403
24000
  });
24404
24001
  /**
@@ -24527,6 +24124,49 @@ var solanaWeb3 = (function (exports) {
24527
24124
  data
24528
24125
  });
24529
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
+ }
24530
24170
  /**
24531
24171
  * Generate a transaction to withdraw from a Vote account.
24532
24172
  */