@bounded-sh/client 0.0.17 → 0.0.19

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.
Files changed (39) hide show
  1. package/README.md +2 -1
  2. package/dist/auth/index.d.ts +2 -4
  3. package/dist/auth/providers/mock-auth-provider.d.ts +0 -1
  4. package/dist/auth/providers/offchain-auth-provider.d.ts +3 -4
  5. package/dist/auth/providers/phantom-wallet-provider.d.ts +3 -2
  6. package/dist/auth/providers/privy-wallet-provider.d.ts +10 -7
  7. package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +3 -2
  8. package/dist/auth/solana-rpc.d.ts +8 -0
  9. package/dist/index.js +310 -2682
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +310 -2682
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/{index.native-DoiNBZlU.js → index.native-DI_Xgv-n.js} +205 -2558
  14. package/dist/index.native-DI_Xgv-n.js.map +1 -0
  15. package/dist/{index.native-DlMO7aHv.mjs → index.native-DWI_i6-6.mjs} +202 -2556
  16. package/dist/index.native-DWI_i6-6.mjs.map +1 -0
  17. package/dist/index.native.js +2 -2
  18. package/dist/index.native.mjs +2 -2
  19. package/dist/{phantom-wallet-provider-DWG1LVJf.mjs → phantom-wallet-provider-DDwgNMg_.mjs} +7 -18
  20. package/dist/phantom-wallet-provider-DDwgNMg_.mjs.map +1 -0
  21. package/dist/{phantom-wallet-provider-DUdnFoyb.js → phantom-wallet-provider-fyOrJZP6.js} +7 -18
  22. package/dist/phantom-wallet-provider-fyOrJZP6.js.map +1 -0
  23. package/dist/{privy-wallet-provider-Kv6H3xcS.js → privy-wallet-provider-BIr9lDS7.js} +69 -90
  24. package/dist/privy-wallet-provider-BIr9lDS7.js.map +1 -0
  25. package/dist/{privy-wallet-provider-CyNLekvY.mjs → privy-wallet-provider-D7VoQCYf.mjs} +68 -89
  26. package/dist/privy-wallet-provider-D7VoQCYf.mjs.map +1 -0
  27. package/dist/{solana-mobile-wallet-provider-BfHBucO0.js → solana-mobile-wallet-provider-Cush-URL.js} +39 -25
  28. package/dist/solana-mobile-wallet-provider-Cush-URL.js.map +1 -0
  29. package/dist/{solana-mobile-wallet-provider-CKOSbLRd.mjs → solana-mobile-wallet-provider-DgcGxDoL.mjs} +39 -25
  30. package/dist/solana-mobile-wallet-provider-DgcGxDoL.mjs.map +1 -0
  31. package/package.json +2 -2
  32. package/dist/index.native-DlMO7aHv.mjs.map +0 -1
  33. package/dist/index.native-DoiNBZlU.js.map +0 -1
  34. package/dist/phantom-wallet-provider-DUdnFoyb.js.map +0 -1
  35. package/dist/phantom-wallet-provider-DWG1LVJf.mjs.map +0 -1
  36. package/dist/privy-wallet-provider-CyNLekvY.mjs.map +0 -1
  37. package/dist/privy-wallet-provider-Kv6H3xcS.js.map +0 -1
  38. package/dist/solana-mobile-wallet-provider-BfHBucO0.js.map +0 -1
  39. package/dist/solana-mobile-wallet-provider-CKOSbLRd.mjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@bounded-sh/core');
4
- var web3_js = require('@solana/web3.js');
5
4
  var React$1 = require('react');
5
+ var web3_js = require('@solana/web3.js');
6
6
  var anchor = require('@coral-xyz/anchor');
7
7
  var ReactDOM$1 = require('react-dom/client');
8
8
 
@@ -247,9 +247,7 @@ class MockAuthProvider {
247
247
  }
248
248
  async signMessageMock(message) {
249
249
  const address = getPlatform().sessionStorage.getItem('test-user-address') || DEFAULT_TEST_ADDRESS;
250
- // Offchain transactions are verified by hashing the exact message. Keep the
251
- // mock provider deterministic so mockAuth exercises the same integrity check.
252
- const signature = await this.generateOffchainSignature(message);
250
+ const signature = `mock_sig_${Math.random().toString(36).substring(2, 15)}`;
253
251
  console.log('[MockAuth] Mock message signed:', {
254
252
  address,
255
253
  message,
@@ -257,13 +255,6 @@ class MockAuthProvider {
257
255
  });
258
256
  return signature;
259
257
  }
260
- async generateOffchainSignature(message) {
261
- const platform = getPlatform();
262
- const data = platform.textEncode(message);
263
- const hashBuffer = await platform.sha256(data);
264
- const hashArray = Array.from(new Uint8Array(hashBuffer));
265
- return platform.btoa(String.fromCharCode(...hashArray));
266
- }
267
258
  /**
268
259
  * Mock transaction signing - returns the transaction as-is (no actual signing)
269
260
  */
@@ -322,9 +313,9 @@ class MockAuthProvider {
322
313
  /**
323
314
  * OffchainAuthProvider wraps a real auth provider (e.g., Phantom) for the poofnet environment.
324
315
  *
325
- * For signMessageMock, this shows a custom confirmation modal and generates a mock signature.
326
- * This is used for offchain transaction signing. For real wallet signing, use signMessage
327
- * which delegates to the wrapped provider.
316
+ * For signMessageMock, this shows a custom confirmation modal and then delegates
317
+ * to the wrapped provider for a real detached signature over the exact offchain
318
+ * transaction message.
328
319
  */
329
320
  class OffchainAuthProvider {
330
321
  constructor(wrappedProvider, config = {}) {
@@ -392,8 +383,7 @@ class OffchainAuthProvider {
392
383
  throw new Error("Transaction rejected by user");
393
384
  }
394
385
  }
395
- // Generate mock signature (hash of message)
396
- const signature = await this.generateMockSignature(message);
386
+ const signature = await this.wrappedProvider.signMessage(message);
397
387
  // Callback: signing complete
398
388
  (_d = (_c = this.config).onSigningComplete) === null || _d === void 0 ? void 0 : _d.call(_c, signature);
399
389
  return signature;
@@ -1002,26 +992,12 @@ class OffchainAuthProvider {
1002
992
  }
1003
993
  `;
1004
994
  }
1005
- async generateMockSignature(message) {
1006
- // Generate a deterministic signature using SHA-256 hash of message
1007
- // This can be verified on the backend by hashing the same message
1008
- const platform = getPlatform();
1009
- const data = platform.textEncode(message);
1010
- const hashBuffer = await platform.sha256(data);
1011
- const hashArray = Array.from(new Uint8Array(hashBuffer));
1012
- const base64 = platform.btoa(String.fromCharCode(...hashArray));
1013
- return base64;
1014
- }
1015
995
  }
1016
996
 
1017
997
  function getDefaultExportFromCjs (x) {
1018
998
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1019
999
  }
1020
1000
 
1021
- function getDefaultExportFromNamespaceIfNotNamed (n) {
1022
- return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
1023
- }
1024
-
1025
1001
  var safeBuffer = {exports: {}};
1026
1002
 
1027
1003
  var buffer = {};
@@ -3611,2444 +3587,24 @@ var index = /*#__PURE__*/Object.freeze({
3611
3587
  default: bs58
3612
3588
  });
3613
3589
 
3614
- function commonjsRequire(path) {
3615
- throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
3616
- }
3617
-
3618
- var naclFast = {exports: {}};
3619
-
3620
- var _nodeResolve_empty = {};
3621
-
3622
- var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
3623
- __proto__: null,
3624
- default: _nodeResolve_empty
3625
- });
3626
-
3627
- var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
3628
-
3629
- var hasRequiredNaclFast;
3630
-
3631
- function requireNaclFast () {
3632
- if (hasRequiredNaclFast) return naclFast.exports;
3633
- hasRequiredNaclFast = 1;
3634
- (function (module) {
3635
- (function(nacl) {
3636
-
3637
- // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
3638
- // Public domain.
3639
- //
3640
- // Implementation derived from TweetNaCl version 20140427.
3641
- // See for details: http://tweetnacl.cr.yp.to/
3642
-
3643
- var gf = function(init) {
3644
- var i, r = new Float64Array(16);
3645
- if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
3646
- return r;
3647
- };
3648
-
3649
- // Pluggable, initialized in high-level API below.
3650
- var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
3651
-
3652
- var _0 = new Uint8Array(16);
3653
- var _9 = new Uint8Array(32); _9[0] = 9;
3654
-
3655
- var gf0 = gf(),
3656
- gf1 = gf([1]),
3657
- _121665 = gf([0xdb41, 1]),
3658
- D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
3659
- D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
3660
- X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
3661
- Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
3662
- I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
3663
-
3664
- function ts64(x, i, h, l) {
3665
- x[i] = (h >> 24) & 0xff;
3666
- x[i+1] = (h >> 16) & 0xff;
3667
- x[i+2] = (h >> 8) & 0xff;
3668
- x[i+3] = h & 0xff;
3669
- x[i+4] = (l >> 24) & 0xff;
3670
- x[i+5] = (l >> 16) & 0xff;
3671
- x[i+6] = (l >> 8) & 0xff;
3672
- x[i+7] = l & 0xff;
3673
- }
3674
-
3675
- function vn(x, xi, y, yi, n) {
3676
- var i,d = 0;
3677
- for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
3678
- return (1 & ((d - 1) >>> 8)) - 1;
3679
- }
3680
-
3681
- function crypto_verify_16(x, xi, y, yi) {
3682
- return vn(x,xi,y,yi,16);
3683
- }
3684
-
3685
- function crypto_verify_32(x, xi, y, yi) {
3686
- return vn(x,xi,y,yi,32);
3687
- }
3688
-
3689
- function core_salsa20(o, p, k, c) {
3690
- var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
3691
- j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
3692
- j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
3693
- j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
3694
- j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
3695
- j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
3696
- j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
3697
- j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
3698
- j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
3699
- j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
3700
- j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
3701
- j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
3702
- j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
3703
- j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
3704
- j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
3705
- j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
3706
-
3707
- var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
3708
- x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
3709
- x15 = j15, u;
3710
-
3711
- for (var i = 0; i < 20; i += 2) {
3712
- u = x0 + x12 | 0;
3713
- x4 ^= u<<7 | u>>>(32-7);
3714
- u = x4 + x0 | 0;
3715
- x8 ^= u<<9 | u>>>(32-9);
3716
- u = x8 + x4 | 0;
3717
- x12 ^= u<<13 | u>>>(32-13);
3718
- u = x12 + x8 | 0;
3719
- x0 ^= u<<18 | u>>>(32-18);
3720
-
3721
- u = x5 + x1 | 0;
3722
- x9 ^= u<<7 | u>>>(32-7);
3723
- u = x9 + x5 | 0;
3724
- x13 ^= u<<9 | u>>>(32-9);
3725
- u = x13 + x9 | 0;
3726
- x1 ^= u<<13 | u>>>(32-13);
3727
- u = x1 + x13 | 0;
3728
- x5 ^= u<<18 | u>>>(32-18);
3729
-
3730
- u = x10 + x6 | 0;
3731
- x14 ^= u<<7 | u>>>(32-7);
3732
- u = x14 + x10 | 0;
3733
- x2 ^= u<<9 | u>>>(32-9);
3734
- u = x2 + x14 | 0;
3735
- x6 ^= u<<13 | u>>>(32-13);
3736
- u = x6 + x2 | 0;
3737
- x10 ^= u<<18 | u>>>(32-18);
3738
-
3739
- u = x15 + x11 | 0;
3740
- x3 ^= u<<7 | u>>>(32-7);
3741
- u = x3 + x15 | 0;
3742
- x7 ^= u<<9 | u>>>(32-9);
3743
- u = x7 + x3 | 0;
3744
- x11 ^= u<<13 | u>>>(32-13);
3745
- u = x11 + x7 | 0;
3746
- x15 ^= u<<18 | u>>>(32-18);
3747
-
3748
- u = x0 + x3 | 0;
3749
- x1 ^= u<<7 | u>>>(32-7);
3750
- u = x1 + x0 | 0;
3751
- x2 ^= u<<9 | u>>>(32-9);
3752
- u = x2 + x1 | 0;
3753
- x3 ^= u<<13 | u>>>(32-13);
3754
- u = x3 + x2 | 0;
3755
- x0 ^= u<<18 | u>>>(32-18);
3756
-
3757
- u = x5 + x4 | 0;
3758
- x6 ^= u<<7 | u>>>(32-7);
3759
- u = x6 + x5 | 0;
3760
- x7 ^= u<<9 | u>>>(32-9);
3761
- u = x7 + x6 | 0;
3762
- x4 ^= u<<13 | u>>>(32-13);
3763
- u = x4 + x7 | 0;
3764
- x5 ^= u<<18 | u>>>(32-18);
3765
-
3766
- u = x10 + x9 | 0;
3767
- x11 ^= u<<7 | u>>>(32-7);
3768
- u = x11 + x10 | 0;
3769
- x8 ^= u<<9 | u>>>(32-9);
3770
- u = x8 + x11 | 0;
3771
- x9 ^= u<<13 | u>>>(32-13);
3772
- u = x9 + x8 | 0;
3773
- x10 ^= u<<18 | u>>>(32-18);
3774
-
3775
- u = x15 + x14 | 0;
3776
- x12 ^= u<<7 | u>>>(32-7);
3777
- u = x12 + x15 | 0;
3778
- x13 ^= u<<9 | u>>>(32-9);
3779
- u = x13 + x12 | 0;
3780
- x14 ^= u<<13 | u>>>(32-13);
3781
- u = x14 + x13 | 0;
3782
- x15 ^= u<<18 | u>>>(32-18);
3783
- }
3784
- x0 = x0 + j0 | 0;
3785
- x1 = x1 + j1 | 0;
3786
- x2 = x2 + j2 | 0;
3787
- x3 = x3 + j3 | 0;
3788
- x4 = x4 + j4 | 0;
3789
- x5 = x5 + j5 | 0;
3790
- x6 = x6 + j6 | 0;
3791
- x7 = x7 + j7 | 0;
3792
- x8 = x8 + j8 | 0;
3793
- x9 = x9 + j9 | 0;
3794
- x10 = x10 + j10 | 0;
3795
- x11 = x11 + j11 | 0;
3796
- x12 = x12 + j12 | 0;
3797
- x13 = x13 + j13 | 0;
3798
- x14 = x14 + j14 | 0;
3799
- x15 = x15 + j15 | 0;
3800
-
3801
- o[ 0] = x0 >>> 0 & 0xff;
3802
- o[ 1] = x0 >>> 8 & 0xff;
3803
- o[ 2] = x0 >>> 16 & 0xff;
3804
- o[ 3] = x0 >>> 24 & 0xff;
3805
-
3806
- o[ 4] = x1 >>> 0 & 0xff;
3807
- o[ 5] = x1 >>> 8 & 0xff;
3808
- o[ 6] = x1 >>> 16 & 0xff;
3809
- o[ 7] = x1 >>> 24 & 0xff;
3810
-
3811
- o[ 8] = x2 >>> 0 & 0xff;
3812
- o[ 9] = x2 >>> 8 & 0xff;
3813
- o[10] = x2 >>> 16 & 0xff;
3814
- o[11] = x2 >>> 24 & 0xff;
3815
-
3816
- o[12] = x3 >>> 0 & 0xff;
3817
- o[13] = x3 >>> 8 & 0xff;
3818
- o[14] = x3 >>> 16 & 0xff;
3819
- o[15] = x3 >>> 24 & 0xff;
3820
-
3821
- o[16] = x4 >>> 0 & 0xff;
3822
- o[17] = x4 >>> 8 & 0xff;
3823
- o[18] = x4 >>> 16 & 0xff;
3824
- o[19] = x4 >>> 24 & 0xff;
3825
-
3826
- o[20] = x5 >>> 0 & 0xff;
3827
- o[21] = x5 >>> 8 & 0xff;
3828
- o[22] = x5 >>> 16 & 0xff;
3829
- o[23] = x5 >>> 24 & 0xff;
3830
-
3831
- o[24] = x6 >>> 0 & 0xff;
3832
- o[25] = x6 >>> 8 & 0xff;
3833
- o[26] = x6 >>> 16 & 0xff;
3834
- o[27] = x6 >>> 24 & 0xff;
3835
-
3836
- o[28] = x7 >>> 0 & 0xff;
3837
- o[29] = x7 >>> 8 & 0xff;
3838
- o[30] = x7 >>> 16 & 0xff;
3839
- o[31] = x7 >>> 24 & 0xff;
3840
-
3841
- o[32] = x8 >>> 0 & 0xff;
3842
- o[33] = x8 >>> 8 & 0xff;
3843
- o[34] = x8 >>> 16 & 0xff;
3844
- o[35] = x8 >>> 24 & 0xff;
3845
-
3846
- o[36] = x9 >>> 0 & 0xff;
3847
- o[37] = x9 >>> 8 & 0xff;
3848
- o[38] = x9 >>> 16 & 0xff;
3849
- o[39] = x9 >>> 24 & 0xff;
3850
-
3851
- o[40] = x10 >>> 0 & 0xff;
3852
- o[41] = x10 >>> 8 & 0xff;
3853
- o[42] = x10 >>> 16 & 0xff;
3854
- o[43] = x10 >>> 24 & 0xff;
3855
-
3856
- o[44] = x11 >>> 0 & 0xff;
3857
- o[45] = x11 >>> 8 & 0xff;
3858
- o[46] = x11 >>> 16 & 0xff;
3859
- o[47] = x11 >>> 24 & 0xff;
3860
-
3861
- o[48] = x12 >>> 0 & 0xff;
3862
- o[49] = x12 >>> 8 & 0xff;
3863
- o[50] = x12 >>> 16 & 0xff;
3864
- o[51] = x12 >>> 24 & 0xff;
3865
-
3866
- o[52] = x13 >>> 0 & 0xff;
3867
- o[53] = x13 >>> 8 & 0xff;
3868
- o[54] = x13 >>> 16 & 0xff;
3869
- o[55] = x13 >>> 24 & 0xff;
3870
-
3871
- o[56] = x14 >>> 0 & 0xff;
3872
- o[57] = x14 >>> 8 & 0xff;
3873
- o[58] = x14 >>> 16 & 0xff;
3874
- o[59] = x14 >>> 24 & 0xff;
3875
-
3876
- o[60] = x15 >>> 0 & 0xff;
3877
- o[61] = x15 >>> 8 & 0xff;
3878
- o[62] = x15 >>> 16 & 0xff;
3879
- o[63] = x15 >>> 24 & 0xff;
3880
- }
3881
-
3882
- function core_hsalsa20(o,p,k,c) {
3883
- var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
3884
- j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
3885
- j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
3886
- j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
3887
- j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
3888
- j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
3889
- j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
3890
- j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
3891
- j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
3892
- j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
3893
- j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
3894
- j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
3895
- j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
3896
- j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
3897
- j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
3898
- j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
3899
-
3900
- var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
3901
- x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
3902
- x15 = j15, u;
3903
-
3904
- for (var i = 0; i < 20; i += 2) {
3905
- u = x0 + x12 | 0;
3906
- x4 ^= u<<7 | u>>>(32-7);
3907
- u = x4 + x0 | 0;
3908
- x8 ^= u<<9 | u>>>(32-9);
3909
- u = x8 + x4 | 0;
3910
- x12 ^= u<<13 | u>>>(32-13);
3911
- u = x12 + x8 | 0;
3912
- x0 ^= u<<18 | u>>>(32-18);
3913
-
3914
- u = x5 + x1 | 0;
3915
- x9 ^= u<<7 | u>>>(32-7);
3916
- u = x9 + x5 | 0;
3917
- x13 ^= u<<9 | u>>>(32-9);
3918
- u = x13 + x9 | 0;
3919
- x1 ^= u<<13 | u>>>(32-13);
3920
- u = x1 + x13 | 0;
3921
- x5 ^= u<<18 | u>>>(32-18);
3922
-
3923
- u = x10 + x6 | 0;
3924
- x14 ^= u<<7 | u>>>(32-7);
3925
- u = x14 + x10 | 0;
3926
- x2 ^= u<<9 | u>>>(32-9);
3927
- u = x2 + x14 | 0;
3928
- x6 ^= u<<13 | u>>>(32-13);
3929
- u = x6 + x2 | 0;
3930
- x10 ^= u<<18 | u>>>(32-18);
3931
-
3932
- u = x15 + x11 | 0;
3933
- x3 ^= u<<7 | u>>>(32-7);
3934
- u = x3 + x15 | 0;
3935
- x7 ^= u<<9 | u>>>(32-9);
3936
- u = x7 + x3 | 0;
3937
- x11 ^= u<<13 | u>>>(32-13);
3938
- u = x11 + x7 | 0;
3939
- x15 ^= u<<18 | u>>>(32-18);
3940
-
3941
- u = x0 + x3 | 0;
3942
- x1 ^= u<<7 | u>>>(32-7);
3943
- u = x1 + x0 | 0;
3944
- x2 ^= u<<9 | u>>>(32-9);
3945
- u = x2 + x1 | 0;
3946
- x3 ^= u<<13 | u>>>(32-13);
3947
- u = x3 + x2 | 0;
3948
- x0 ^= u<<18 | u>>>(32-18);
3949
-
3950
- u = x5 + x4 | 0;
3951
- x6 ^= u<<7 | u>>>(32-7);
3952
- u = x6 + x5 | 0;
3953
- x7 ^= u<<9 | u>>>(32-9);
3954
- u = x7 + x6 | 0;
3955
- x4 ^= u<<13 | u>>>(32-13);
3956
- u = x4 + x7 | 0;
3957
- x5 ^= u<<18 | u>>>(32-18);
3958
-
3959
- u = x10 + x9 | 0;
3960
- x11 ^= u<<7 | u>>>(32-7);
3961
- u = x11 + x10 | 0;
3962
- x8 ^= u<<9 | u>>>(32-9);
3963
- u = x8 + x11 | 0;
3964
- x9 ^= u<<13 | u>>>(32-13);
3965
- u = x9 + x8 | 0;
3966
- x10 ^= u<<18 | u>>>(32-18);
3967
-
3968
- u = x15 + x14 | 0;
3969
- x12 ^= u<<7 | u>>>(32-7);
3970
- u = x12 + x15 | 0;
3971
- x13 ^= u<<9 | u>>>(32-9);
3972
- u = x13 + x12 | 0;
3973
- x14 ^= u<<13 | u>>>(32-13);
3974
- u = x14 + x13 | 0;
3975
- x15 ^= u<<18 | u>>>(32-18);
3976
- }
3977
-
3978
- o[ 0] = x0 >>> 0 & 0xff;
3979
- o[ 1] = x0 >>> 8 & 0xff;
3980
- o[ 2] = x0 >>> 16 & 0xff;
3981
- o[ 3] = x0 >>> 24 & 0xff;
3982
-
3983
- o[ 4] = x5 >>> 0 & 0xff;
3984
- o[ 5] = x5 >>> 8 & 0xff;
3985
- o[ 6] = x5 >>> 16 & 0xff;
3986
- o[ 7] = x5 >>> 24 & 0xff;
3987
-
3988
- o[ 8] = x10 >>> 0 & 0xff;
3989
- o[ 9] = x10 >>> 8 & 0xff;
3990
- o[10] = x10 >>> 16 & 0xff;
3991
- o[11] = x10 >>> 24 & 0xff;
3992
-
3993
- o[12] = x15 >>> 0 & 0xff;
3994
- o[13] = x15 >>> 8 & 0xff;
3995
- o[14] = x15 >>> 16 & 0xff;
3996
- o[15] = x15 >>> 24 & 0xff;
3997
-
3998
- o[16] = x6 >>> 0 & 0xff;
3999
- o[17] = x6 >>> 8 & 0xff;
4000
- o[18] = x6 >>> 16 & 0xff;
4001
- o[19] = x6 >>> 24 & 0xff;
4002
-
4003
- o[20] = x7 >>> 0 & 0xff;
4004
- o[21] = x7 >>> 8 & 0xff;
4005
- o[22] = x7 >>> 16 & 0xff;
4006
- o[23] = x7 >>> 24 & 0xff;
4007
-
4008
- o[24] = x8 >>> 0 & 0xff;
4009
- o[25] = x8 >>> 8 & 0xff;
4010
- o[26] = x8 >>> 16 & 0xff;
4011
- o[27] = x8 >>> 24 & 0xff;
4012
-
4013
- o[28] = x9 >>> 0 & 0xff;
4014
- o[29] = x9 >>> 8 & 0xff;
4015
- o[30] = x9 >>> 16 & 0xff;
4016
- o[31] = x9 >>> 24 & 0xff;
4017
- }
4018
-
4019
- function crypto_core_salsa20(out,inp,k,c) {
4020
- core_salsa20(out,inp,k,c);
4021
- }
4022
-
4023
- function crypto_core_hsalsa20(out,inp,k,c) {
4024
- core_hsalsa20(out,inp,k,c);
4025
- }
4026
-
4027
- var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
4028
- // "expand 32-byte k"
4029
-
4030
- function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
4031
- var z = new Uint8Array(16), x = new Uint8Array(64);
4032
- var u, i;
4033
- for (i = 0; i < 16; i++) z[i] = 0;
4034
- for (i = 0; i < 8; i++) z[i] = n[i];
4035
- while (b >= 64) {
4036
- crypto_core_salsa20(x,z,k,sigma);
4037
- for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
4038
- u = 1;
4039
- for (i = 8; i < 16; i++) {
4040
- u = u + (z[i] & 0xff) | 0;
4041
- z[i] = u & 0xff;
4042
- u >>>= 8;
4043
- }
4044
- b -= 64;
4045
- cpos += 64;
4046
- mpos += 64;
4047
- }
4048
- if (b > 0) {
4049
- crypto_core_salsa20(x,z,k,sigma);
4050
- for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
4051
- }
4052
- return 0;
4053
- }
4054
-
4055
- function crypto_stream_salsa20(c,cpos,b,n,k) {
4056
- var z = new Uint8Array(16), x = new Uint8Array(64);
4057
- var u, i;
4058
- for (i = 0; i < 16; i++) z[i] = 0;
4059
- for (i = 0; i < 8; i++) z[i] = n[i];
4060
- while (b >= 64) {
4061
- crypto_core_salsa20(x,z,k,sigma);
4062
- for (i = 0; i < 64; i++) c[cpos+i] = x[i];
4063
- u = 1;
4064
- for (i = 8; i < 16; i++) {
4065
- u = u + (z[i] & 0xff) | 0;
4066
- z[i] = u & 0xff;
4067
- u >>>= 8;
4068
- }
4069
- b -= 64;
4070
- cpos += 64;
4071
- }
4072
- if (b > 0) {
4073
- crypto_core_salsa20(x,z,k,sigma);
4074
- for (i = 0; i < b; i++) c[cpos+i] = x[i];
4075
- }
4076
- return 0;
4077
- }
4078
-
4079
- function crypto_stream(c,cpos,d,n,k) {
4080
- var s = new Uint8Array(32);
4081
- crypto_core_hsalsa20(s,n,k,sigma);
4082
- var sn = new Uint8Array(8);
4083
- for (var i = 0; i < 8; i++) sn[i] = n[i+16];
4084
- return crypto_stream_salsa20(c,cpos,d,sn,s);
4085
- }
4086
-
4087
- function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
4088
- var s = new Uint8Array(32);
4089
- crypto_core_hsalsa20(s,n,k,sigma);
4090
- var sn = new Uint8Array(8);
4091
- for (var i = 0; i < 8; i++) sn[i] = n[i+16];
4092
- return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
4093
- }
4094
-
4095
- /*
4096
- * Port of Andrew Moon's Poly1305-donna-16. Public domain.
4097
- * https://github.com/floodyberry/poly1305-donna
4098
- */
4099
-
4100
- var poly1305 = function(key) {
4101
- this.buffer = new Uint8Array(16);
4102
- this.r = new Uint16Array(10);
4103
- this.h = new Uint16Array(10);
4104
- this.pad = new Uint16Array(8);
4105
- this.leftover = 0;
4106
- this.fin = 0;
4107
-
4108
- var t0, t1, t2, t3, t4, t5, t6, t7;
4109
-
4110
- t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
4111
- t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
4112
- t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
4113
- t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
4114
- t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
4115
- this.r[5] = ((t4 >>> 1)) & 0x1ffe;
4116
- t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
4117
- t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
4118
- t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
4119
- this.r[9] = ((t7 >>> 5)) & 0x007f;
4120
-
4121
- this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
4122
- this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
4123
- this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
4124
- this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
4125
- this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
4126
- this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
4127
- this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
4128
- this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
4129
- };
4130
-
4131
- poly1305.prototype.blocks = function(m, mpos, bytes) {
4132
- var hibit = this.fin ? 0 : (1 << 11);
4133
- var t0, t1, t2, t3, t4, t5, t6, t7, c;
4134
- var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
4135
-
4136
- var h0 = this.h[0],
4137
- h1 = this.h[1],
4138
- h2 = this.h[2],
4139
- h3 = this.h[3],
4140
- h4 = this.h[4],
4141
- h5 = this.h[5],
4142
- h6 = this.h[6],
4143
- h7 = this.h[7],
4144
- h8 = this.h[8],
4145
- h9 = this.h[9];
4146
-
4147
- var r0 = this.r[0],
4148
- r1 = this.r[1],
4149
- r2 = this.r[2],
4150
- r3 = this.r[3],
4151
- r4 = this.r[4],
4152
- r5 = this.r[5],
4153
- r6 = this.r[6],
4154
- r7 = this.r[7],
4155
- r8 = this.r[8],
4156
- r9 = this.r[9];
4157
-
4158
- while (bytes >= 16) {
4159
- t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
4160
- t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
4161
- t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
4162
- t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
4163
- t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
4164
- h5 += ((t4 >>> 1)) & 0x1fff;
4165
- t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
4166
- t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
4167
- t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
4168
- h9 += ((t7 >>> 5)) | hibit;
4169
-
4170
- c = 0;
4171
-
4172
- d0 = c;
4173
- d0 += h0 * r0;
4174
- d0 += h1 * (5 * r9);
4175
- d0 += h2 * (5 * r8);
4176
- d0 += h3 * (5 * r7);
4177
- d0 += h4 * (5 * r6);
4178
- c = (d0 >>> 13); d0 &= 0x1fff;
4179
- d0 += h5 * (5 * r5);
4180
- d0 += h6 * (5 * r4);
4181
- d0 += h7 * (5 * r3);
4182
- d0 += h8 * (5 * r2);
4183
- d0 += h9 * (5 * r1);
4184
- c += (d0 >>> 13); d0 &= 0x1fff;
4185
-
4186
- d1 = c;
4187
- d1 += h0 * r1;
4188
- d1 += h1 * r0;
4189
- d1 += h2 * (5 * r9);
4190
- d1 += h3 * (5 * r8);
4191
- d1 += h4 * (5 * r7);
4192
- c = (d1 >>> 13); d1 &= 0x1fff;
4193
- d1 += h5 * (5 * r6);
4194
- d1 += h6 * (5 * r5);
4195
- d1 += h7 * (5 * r4);
4196
- d1 += h8 * (5 * r3);
4197
- d1 += h9 * (5 * r2);
4198
- c += (d1 >>> 13); d1 &= 0x1fff;
4199
-
4200
- d2 = c;
4201
- d2 += h0 * r2;
4202
- d2 += h1 * r1;
4203
- d2 += h2 * r0;
4204
- d2 += h3 * (5 * r9);
4205
- d2 += h4 * (5 * r8);
4206
- c = (d2 >>> 13); d2 &= 0x1fff;
4207
- d2 += h5 * (5 * r7);
4208
- d2 += h6 * (5 * r6);
4209
- d2 += h7 * (5 * r5);
4210
- d2 += h8 * (5 * r4);
4211
- d2 += h9 * (5 * r3);
4212
- c += (d2 >>> 13); d2 &= 0x1fff;
4213
-
4214
- d3 = c;
4215
- d3 += h0 * r3;
4216
- d3 += h1 * r2;
4217
- d3 += h2 * r1;
4218
- d3 += h3 * r0;
4219
- d3 += h4 * (5 * r9);
4220
- c = (d3 >>> 13); d3 &= 0x1fff;
4221
- d3 += h5 * (5 * r8);
4222
- d3 += h6 * (5 * r7);
4223
- d3 += h7 * (5 * r6);
4224
- d3 += h8 * (5 * r5);
4225
- d3 += h9 * (5 * r4);
4226
- c += (d3 >>> 13); d3 &= 0x1fff;
4227
-
4228
- d4 = c;
4229
- d4 += h0 * r4;
4230
- d4 += h1 * r3;
4231
- d4 += h2 * r2;
4232
- d4 += h3 * r1;
4233
- d4 += h4 * r0;
4234
- c = (d4 >>> 13); d4 &= 0x1fff;
4235
- d4 += h5 * (5 * r9);
4236
- d4 += h6 * (5 * r8);
4237
- d4 += h7 * (5 * r7);
4238
- d4 += h8 * (5 * r6);
4239
- d4 += h9 * (5 * r5);
4240
- c += (d4 >>> 13); d4 &= 0x1fff;
4241
-
4242
- d5 = c;
4243
- d5 += h0 * r5;
4244
- d5 += h1 * r4;
4245
- d5 += h2 * r3;
4246
- d5 += h3 * r2;
4247
- d5 += h4 * r1;
4248
- c = (d5 >>> 13); d5 &= 0x1fff;
4249
- d5 += h5 * r0;
4250
- d5 += h6 * (5 * r9);
4251
- d5 += h7 * (5 * r8);
4252
- d5 += h8 * (5 * r7);
4253
- d5 += h9 * (5 * r6);
4254
- c += (d5 >>> 13); d5 &= 0x1fff;
4255
-
4256
- d6 = c;
4257
- d6 += h0 * r6;
4258
- d6 += h1 * r5;
4259
- d6 += h2 * r4;
4260
- d6 += h3 * r3;
4261
- d6 += h4 * r2;
4262
- c = (d6 >>> 13); d6 &= 0x1fff;
4263
- d6 += h5 * r1;
4264
- d6 += h6 * r0;
4265
- d6 += h7 * (5 * r9);
4266
- d6 += h8 * (5 * r8);
4267
- d6 += h9 * (5 * r7);
4268
- c += (d6 >>> 13); d6 &= 0x1fff;
4269
-
4270
- d7 = c;
4271
- d7 += h0 * r7;
4272
- d7 += h1 * r6;
4273
- d7 += h2 * r5;
4274
- d7 += h3 * r4;
4275
- d7 += h4 * r3;
4276
- c = (d7 >>> 13); d7 &= 0x1fff;
4277
- d7 += h5 * r2;
4278
- d7 += h6 * r1;
4279
- d7 += h7 * r0;
4280
- d7 += h8 * (5 * r9);
4281
- d7 += h9 * (5 * r8);
4282
- c += (d7 >>> 13); d7 &= 0x1fff;
4283
-
4284
- d8 = c;
4285
- d8 += h0 * r8;
4286
- d8 += h1 * r7;
4287
- d8 += h2 * r6;
4288
- d8 += h3 * r5;
4289
- d8 += h4 * r4;
4290
- c = (d8 >>> 13); d8 &= 0x1fff;
4291
- d8 += h5 * r3;
4292
- d8 += h6 * r2;
4293
- d8 += h7 * r1;
4294
- d8 += h8 * r0;
4295
- d8 += h9 * (5 * r9);
4296
- c += (d8 >>> 13); d8 &= 0x1fff;
4297
-
4298
- d9 = c;
4299
- d9 += h0 * r9;
4300
- d9 += h1 * r8;
4301
- d9 += h2 * r7;
4302
- d9 += h3 * r6;
4303
- d9 += h4 * r5;
4304
- c = (d9 >>> 13); d9 &= 0x1fff;
4305
- d9 += h5 * r4;
4306
- d9 += h6 * r3;
4307
- d9 += h7 * r2;
4308
- d9 += h8 * r1;
4309
- d9 += h9 * r0;
4310
- c += (d9 >>> 13); d9 &= 0x1fff;
4311
-
4312
- c = (((c << 2) + c)) | 0;
4313
- c = (c + d0) | 0;
4314
- d0 = c & 0x1fff;
4315
- c = (c >>> 13);
4316
- d1 += c;
4317
-
4318
- h0 = d0;
4319
- h1 = d1;
4320
- h2 = d2;
4321
- h3 = d3;
4322
- h4 = d4;
4323
- h5 = d5;
4324
- h6 = d6;
4325
- h7 = d7;
4326
- h8 = d8;
4327
- h9 = d9;
4328
-
4329
- mpos += 16;
4330
- bytes -= 16;
4331
- }
4332
- this.h[0] = h0;
4333
- this.h[1] = h1;
4334
- this.h[2] = h2;
4335
- this.h[3] = h3;
4336
- this.h[4] = h4;
4337
- this.h[5] = h5;
4338
- this.h[6] = h6;
4339
- this.h[7] = h7;
4340
- this.h[8] = h8;
4341
- this.h[9] = h9;
4342
- };
4343
-
4344
- poly1305.prototype.finish = function(mac, macpos) {
4345
- var g = new Uint16Array(10);
4346
- var c, mask, f, i;
4347
-
4348
- if (this.leftover) {
4349
- i = this.leftover;
4350
- this.buffer[i++] = 1;
4351
- for (; i < 16; i++) this.buffer[i] = 0;
4352
- this.fin = 1;
4353
- this.blocks(this.buffer, 0, 16);
4354
- }
4355
-
4356
- c = this.h[1] >>> 13;
4357
- this.h[1] &= 0x1fff;
4358
- for (i = 2; i < 10; i++) {
4359
- this.h[i] += c;
4360
- c = this.h[i] >>> 13;
4361
- this.h[i] &= 0x1fff;
4362
- }
4363
- this.h[0] += (c * 5);
4364
- c = this.h[0] >>> 13;
4365
- this.h[0] &= 0x1fff;
4366
- this.h[1] += c;
4367
- c = this.h[1] >>> 13;
4368
- this.h[1] &= 0x1fff;
4369
- this.h[2] += c;
4370
-
4371
- g[0] = this.h[0] + 5;
4372
- c = g[0] >>> 13;
4373
- g[0] &= 0x1fff;
4374
- for (i = 1; i < 10; i++) {
4375
- g[i] = this.h[i] + c;
4376
- c = g[i] >>> 13;
4377
- g[i] &= 0x1fff;
4378
- }
4379
- g[9] -= (1 << 13);
4380
-
4381
- mask = (c ^ 1) - 1;
4382
- for (i = 0; i < 10; i++) g[i] &= mask;
4383
- mask = ~mask;
4384
- for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
4385
-
4386
- this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
4387
- this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
4388
- this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
4389
- this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
4390
- this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
4391
- this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
4392
- this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
4393
- this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
4394
-
4395
- f = this.h[0] + this.pad[0];
4396
- this.h[0] = f & 0xffff;
4397
- for (i = 1; i < 8; i++) {
4398
- f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
4399
- this.h[i] = f & 0xffff;
4400
- }
4401
-
4402
- mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
4403
- mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
4404
- mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
4405
- mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
4406
- mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
4407
- mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
4408
- mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
4409
- mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
4410
- mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
4411
- mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
4412
- mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
4413
- mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
4414
- mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
4415
- mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
4416
- mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
4417
- mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
4418
- };
4419
-
4420
- poly1305.prototype.update = function(m, mpos, bytes) {
4421
- var i, want;
4422
-
4423
- if (this.leftover) {
4424
- want = (16 - this.leftover);
4425
- if (want > bytes)
4426
- want = bytes;
4427
- for (i = 0; i < want; i++)
4428
- this.buffer[this.leftover + i] = m[mpos+i];
4429
- bytes -= want;
4430
- mpos += want;
4431
- this.leftover += want;
4432
- if (this.leftover < 16)
4433
- return;
4434
- this.blocks(this.buffer, 0, 16);
4435
- this.leftover = 0;
4436
- }
4437
-
4438
- if (bytes >= 16) {
4439
- want = bytes - (bytes % 16);
4440
- this.blocks(m, mpos, want);
4441
- mpos += want;
4442
- bytes -= want;
4443
- }
4444
-
4445
- if (bytes) {
4446
- for (i = 0; i < bytes; i++)
4447
- this.buffer[this.leftover + i] = m[mpos+i];
4448
- this.leftover += bytes;
4449
- }
4450
- };
4451
-
4452
- function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
4453
- var s = new poly1305(k);
4454
- s.update(m, mpos, n);
4455
- s.finish(out, outpos);
4456
- return 0;
4457
- }
4458
-
4459
- function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
4460
- var x = new Uint8Array(16);
4461
- crypto_onetimeauth(x,0,m,mpos,n,k);
4462
- return crypto_verify_16(h,hpos,x,0);
4463
- }
4464
-
4465
- function crypto_secretbox(c,m,d,n,k) {
4466
- var i;
4467
- if (d < 32) return -1;
4468
- crypto_stream_xor(c,0,m,0,d,n,k);
4469
- crypto_onetimeauth(c, 16, c, 32, d - 32, c);
4470
- for (i = 0; i < 16; i++) c[i] = 0;
4471
- return 0;
4472
- }
4473
-
4474
- function crypto_secretbox_open(m,c,d,n,k) {
4475
- var i;
4476
- var x = new Uint8Array(32);
4477
- if (d < 32) return -1;
4478
- crypto_stream(x,0,32,n,k);
4479
- if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
4480
- crypto_stream_xor(m,0,c,0,d,n,k);
4481
- for (i = 0; i < 32; i++) m[i] = 0;
4482
- return 0;
4483
- }
4484
-
4485
- function set25519(r, a) {
4486
- var i;
4487
- for (i = 0; i < 16; i++) r[i] = a[i]|0;
4488
- }
4489
-
4490
- function car25519(o) {
4491
- var i, v, c = 1;
4492
- for (i = 0; i < 16; i++) {
4493
- v = o[i] + c + 65535;
4494
- c = Math.floor(v / 65536);
4495
- o[i] = v - c * 65536;
4496
- }
4497
- o[0] += c-1 + 37 * (c-1);
4498
- }
4499
-
4500
- function sel25519(p, q, b) {
4501
- var t, c = ~(b-1);
4502
- for (var i = 0; i < 16; i++) {
4503
- t = c & (p[i] ^ q[i]);
4504
- p[i] ^= t;
4505
- q[i] ^= t;
4506
- }
4507
- }
4508
-
4509
- function pack25519(o, n) {
4510
- var i, j, b;
4511
- var m = gf(), t = gf();
4512
- for (i = 0; i < 16; i++) t[i] = n[i];
4513
- car25519(t);
4514
- car25519(t);
4515
- car25519(t);
4516
- for (j = 0; j < 2; j++) {
4517
- m[0] = t[0] - 0xffed;
4518
- for (i = 1; i < 15; i++) {
4519
- m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
4520
- m[i-1] &= 0xffff;
4521
- }
4522
- m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
4523
- b = (m[15]>>16) & 1;
4524
- m[14] &= 0xffff;
4525
- sel25519(t, m, 1-b);
4526
- }
4527
- for (i = 0; i < 16; i++) {
4528
- o[2*i] = t[i] & 0xff;
4529
- o[2*i+1] = t[i]>>8;
4530
- }
4531
- }
4532
-
4533
- function neq25519(a, b) {
4534
- var c = new Uint8Array(32), d = new Uint8Array(32);
4535
- pack25519(c, a);
4536
- pack25519(d, b);
4537
- return crypto_verify_32(c, 0, d, 0);
4538
- }
4539
-
4540
- function par25519(a) {
4541
- var d = new Uint8Array(32);
4542
- pack25519(d, a);
4543
- return d[0] & 1;
4544
- }
4545
-
4546
- function unpack25519(o, n) {
4547
- var i;
4548
- for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
4549
- o[15] &= 0x7fff;
4550
- }
4551
-
4552
- function A(o, a, b) {
4553
- for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
4554
- }
4555
-
4556
- function Z(o, a, b) {
4557
- for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
4558
- }
4559
-
4560
- function M(o, a, b) {
4561
- var v, c,
4562
- t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
4563
- t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
4564
- t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
4565
- t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
4566
- b0 = b[0],
4567
- b1 = b[1],
4568
- b2 = b[2],
4569
- b3 = b[3],
4570
- b4 = b[4],
4571
- b5 = b[5],
4572
- b6 = b[6],
4573
- b7 = b[7],
4574
- b8 = b[8],
4575
- b9 = b[9],
4576
- b10 = b[10],
4577
- b11 = b[11],
4578
- b12 = b[12],
4579
- b13 = b[13],
4580
- b14 = b[14],
4581
- b15 = b[15];
4582
-
4583
- v = a[0];
4584
- t0 += v * b0;
4585
- t1 += v * b1;
4586
- t2 += v * b2;
4587
- t3 += v * b3;
4588
- t4 += v * b4;
4589
- t5 += v * b5;
4590
- t6 += v * b6;
4591
- t7 += v * b7;
4592
- t8 += v * b8;
4593
- t9 += v * b9;
4594
- t10 += v * b10;
4595
- t11 += v * b11;
4596
- t12 += v * b12;
4597
- t13 += v * b13;
4598
- t14 += v * b14;
4599
- t15 += v * b15;
4600
- v = a[1];
4601
- t1 += v * b0;
4602
- t2 += v * b1;
4603
- t3 += v * b2;
4604
- t4 += v * b3;
4605
- t5 += v * b4;
4606
- t6 += v * b5;
4607
- t7 += v * b6;
4608
- t8 += v * b7;
4609
- t9 += v * b8;
4610
- t10 += v * b9;
4611
- t11 += v * b10;
4612
- t12 += v * b11;
4613
- t13 += v * b12;
4614
- t14 += v * b13;
4615
- t15 += v * b14;
4616
- t16 += v * b15;
4617
- v = a[2];
4618
- t2 += v * b0;
4619
- t3 += v * b1;
4620
- t4 += v * b2;
4621
- t5 += v * b3;
4622
- t6 += v * b4;
4623
- t7 += v * b5;
4624
- t8 += v * b6;
4625
- t9 += v * b7;
4626
- t10 += v * b8;
4627
- t11 += v * b9;
4628
- t12 += v * b10;
4629
- t13 += v * b11;
4630
- t14 += v * b12;
4631
- t15 += v * b13;
4632
- t16 += v * b14;
4633
- t17 += v * b15;
4634
- v = a[3];
4635
- t3 += v * b0;
4636
- t4 += v * b1;
4637
- t5 += v * b2;
4638
- t6 += v * b3;
4639
- t7 += v * b4;
4640
- t8 += v * b5;
4641
- t9 += v * b6;
4642
- t10 += v * b7;
4643
- t11 += v * b8;
4644
- t12 += v * b9;
4645
- t13 += v * b10;
4646
- t14 += v * b11;
4647
- t15 += v * b12;
4648
- t16 += v * b13;
4649
- t17 += v * b14;
4650
- t18 += v * b15;
4651
- v = a[4];
4652
- t4 += v * b0;
4653
- t5 += v * b1;
4654
- t6 += v * b2;
4655
- t7 += v * b3;
4656
- t8 += v * b4;
4657
- t9 += v * b5;
4658
- t10 += v * b6;
4659
- t11 += v * b7;
4660
- t12 += v * b8;
4661
- t13 += v * b9;
4662
- t14 += v * b10;
4663
- t15 += v * b11;
4664
- t16 += v * b12;
4665
- t17 += v * b13;
4666
- t18 += v * b14;
4667
- t19 += v * b15;
4668
- v = a[5];
4669
- t5 += v * b0;
4670
- t6 += v * b1;
4671
- t7 += v * b2;
4672
- t8 += v * b3;
4673
- t9 += v * b4;
4674
- t10 += v * b5;
4675
- t11 += v * b6;
4676
- t12 += v * b7;
4677
- t13 += v * b8;
4678
- t14 += v * b9;
4679
- t15 += v * b10;
4680
- t16 += v * b11;
4681
- t17 += v * b12;
4682
- t18 += v * b13;
4683
- t19 += v * b14;
4684
- t20 += v * b15;
4685
- v = a[6];
4686
- t6 += v * b0;
4687
- t7 += v * b1;
4688
- t8 += v * b2;
4689
- t9 += v * b3;
4690
- t10 += v * b4;
4691
- t11 += v * b5;
4692
- t12 += v * b6;
4693
- t13 += v * b7;
4694
- t14 += v * b8;
4695
- t15 += v * b9;
4696
- t16 += v * b10;
4697
- t17 += v * b11;
4698
- t18 += v * b12;
4699
- t19 += v * b13;
4700
- t20 += v * b14;
4701
- t21 += v * b15;
4702
- v = a[7];
4703
- t7 += v * b0;
4704
- t8 += v * b1;
4705
- t9 += v * b2;
4706
- t10 += v * b3;
4707
- t11 += v * b4;
4708
- t12 += v * b5;
4709
- t13 += v * b6;
4710
- t14 += v * b7;
4711
- t15 += v * b8;
4712
- t16 += v * b9;
4713
- t17 += v * b10;
4714
- t18 += v * b11;
4715
- t19 += v * b12;
4716
- t20 += v * b13;
4717
- t21 += v * b14;
4718
- t22 += v * b15;
4719
- v = a[8];
4720
- t8 += v * b0;
4721
- t9 += v * b1;
4722
- t10 += v * b2;
4723
- t11 += v * b3;
4724
- t12 += v * b4;
4725
- t13 += v * b5;
4726
- t14 += v * b6;
4727
- t15 += v * b7;
4728
- t16 += v * b8;
4729
- t17 += v * b9;
4730
- t18 += v * b10;
4731
- t19 += v * b11;
4732
- t20 += v * b12;
4733
- t21 += v * b13;
4734
- t22 += v * b14;
4735
- t23 += v * b15;
4736
- v = a[9];
4737
- t9 += v * b0;
4738
- t10 += v * b1;
4739
- t11 += v * b2;
4740
- t12 += v * b3;
4741
- t13 += v * b4;
4742
- t14 += v * b5;
4743
- t15 += v * b6;
4744
- t16 += v * b7;
4745
- t17 += v * b8;
4746
- t18 += v * b9;
4747
- t19 += v * b10;
4748
- t20 += v * b11;
4749
- t21 += v * b12;
4750
- t22 += v * b13;
4751
- t23 += v * b14;
4752
- t24 += v * b15;
4753
- v = a[10];
4754
- t10 += v * b0;
4755
- t11 += v * b1;
4756
- t12 += v * b2;
4757
- t13 += v * b3;
4758
- t14 += v * b4;
4759
- t15 += v * b5;
4760
- t16 += v * b6;
4761
- t17 += v * b7;
4762
- t18 += v * b8;
4763
- t19 += v * b9;
4764
- t20 += v * b10;
4765
- t21 += v * b11;
4766
- t22 += v * b12;
4767
- t23 += v * b13;
4768
- t24 += v * b14;
4769
- t25 += v * b15;
4770
- v = a[11];
4771
- t11 += v * b0;
4772
- t12 += v * b1;
4773
- t13 += v * b2;
4774
- t14 += v * b3;
4775
- t15 += v * b4;
4776
- t16 += v * b5;
4777
- t17 += v * b6;
4778
- t18 += v * b7;
4779
- t19 += v * b8;
4780
- t20 += v * b9;
4781
- t21 += v * b10;
4782
- t22 += v * b11;
4783
- t23 += v * b12;
4784
- t24 += v * b13;
4785
- t25 += v * b14;
4786
- t26 += v * b15;
4787
- v = a[12];
4788
- t12 += v * b0;
4789
- t13 += v * b1;
4790
- t14 += v * b2;
4791
- t15 += v * b3;
4792
- t16 += v * b4;
4793
- t17 += v * b5;
4794
- t18 += v * b6;
4795
- t19 += v * b7;
4796
- t20 += v * b8;
4797
- t21 += v * b9;
4798
- t22 += v * b10;
4799
- t23 += v * b11;
4800
- t24 += v * b12;
4801
- t25 += v * b13;
4802
- t26 += v * b14;
4803
- t27 += v * b15;
4804
- v = a[13];
4805
- t13 += v * b0;
4806
- t14 += v * b1;
4807
- t15 += v * b2;
4808
- t16 += v * b3;
4809
- t17 += v * b4;
4810
- t18 += v * b5;
4811
- t19 += v * b6;
4812
- t20 += v * b7;
4813
- t21 += v * b8;
4814
- t22 += v * b9;
4815
- t23 += v * b10;
4816
- t24 += v * b11;
4817
- t25 += v * b12;
4818
- t26 += v * b13;
4819
- t27 += v * b14;
4820
- t28 += v * b15;
4821
- v = a[14];
4822
- t14 += v * b0;
4823
- t15 += v * b1;
4824
- t16 += v * b2;
4825
- t17 += v * b3;
4826
- t18 += v * b4;
4827
- t19 += v * b5;
4828
- t20 += v * b6;
4829
- t21 += v * b7;
4830
- t22 += v * b8;
4831
- t23 += v * b9;
4832
- t24 += v * b10;
4833
- t25 += v * b11;
4834
- t26 += v * b12;
4835
- t27 += v * b13;
4836
- t28 += v * b14;
4837
- t29 += v * b15;
4838
- v = a[15];
4839
- t15 += v * b0;
4840
- t16 += v * b1;
4841
- t17 += v * b2;
4842
- t18 += v * b3;
4843
- t19 += v * b4;
4844
- t20 += v * b5;
4845
- t21 += v * b6;
4846
- t22 += v * b7;
4847
- t23 += v * b8;
4848
- t24 += v * b9;
4849
- t25 += v * b10;
4850
- t26 += v * b11;
4851
- t27 += v * b12;
4852
- t28 += v * b13;
4853
- t29 += v * b14;
4854
- t30 += v * b15;
4855
-
4856
- t0 += 38 * t16;
4857
- t1 += 38 * t17;
4858
- t2 += 38 * t18;
4859
- t3 += 38 * t19;
4860
- t4 += 38 * t20;
4861
- t5 += 38 * t21;
4862
- t6 += 38 * t22;
4863
- t7 += 38 * t23;
4864
- t8 += 38 * t24;
4865
- t9 += 38 * t25;
4866
- t10 += 38 * t26;
4867
- t11 += 38 * t27;
4868
- t12 += 38 * t28;
4869
- t13 += 38 * t29;
4870
- t14 += 38 * t30;
4871
- // t15 left as is
4872
-
4873
- // first car
4874
- c = 1;
4875
- v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
4876
- v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
4877
- v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
4878
- v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
4879
- v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
4880
- v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
4881
- v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
4882
- v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
4883
- v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
4884
- v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
4885
- v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
4886
- v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
4887
- v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
4888
- v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
4889
- v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
4890
- v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
4891
- t0 += c-1 + 37 * (c-1);
4892
-
4893
- // second car
4894
- c = 1;
4895
- v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
4896
- v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
4897
- v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
4898
- v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
4899
- v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
4900
- v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
4901
- v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
4902
- v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
4903
- v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
4904
- v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
4905
- v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
4906
- v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
4907
- v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
4908
- v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
4909
- v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
4910
- v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
4911
- t0 += c-1 + 37 * (c-1);
4912
-
4913
- o[ 0] = t0;
4914
- o[ 1] = t1;
4915
- o[ 2] = t2;
4916
- o[ 3] = t3;
4917
- o[ 4] = t4;
4918
- o[ 5] = t5;
4919
- o[ 6] = t6;
4920
- o[ 7] = t7;
4921
- o[ 8] = t8;
4922
- o[ 9] = t9;
4923
- o[10] = t10;
4924
- o[11] = t11;
4925
- o[12] = t12;
4926
- o[13] = t13;
4927
- o[14] = t14;
4928
- o[15] = t15;
4929
- }
4930
-
4931
- function S(o, a) {
4932
- M(o, a, a);
4933
- }
4934
-
4935
- function inv25519(o, i) {
4936
- var c = gf();
4937
- var a;
4938
- for (a = 0; a < 16; a++) c[a] = i[a];
4939
- for (a = 253; a >= 0; a--) {
4940
- S(c, c);
4941
- if(a !== 2 && a !== 4) M(c, c, i);
4942
- }
4943
- for (a = 0; a < 16; a++) o[a] = c[a];
4944
- }
4945
-
4946
- function pow2523(o, i) {
4947
- var c = gf();
4948
- var a;
4949
- for (a = 0; a < 16; a++) c[a] = i[a];
4950
- for (a = 250; a >= 0; a--) {
4951
- S(c, c);
4952
- if(a !== 1) M(c, c, i);
4953
- }
4954
- for (a = 0; a < 16; a++) o[a] = c[a];
4955
- }
4956
-
4957
- function crypto_scalarmult(q, n, p) {
4958
- var z = new Uint8Array(32);
4959
- var x = new Float64Array(80), r, i;
4960
- var a = gf(), b = gf(), c = gf(),
4961
- d = gf(), e = gf(), f = gf();
4962
- for (i = 0; i < 31; i++) z[i] = n[i];
4963
- z[31]=(n[31]&127)|64;
4964
- z[0]&=248;
4965
- unpack25519(x,p);
4966
- for (i = 0; i < 16; i++) {
4967
- b[i]=x[i];
4968
- d[i]=a[i]=c[i]=0;
4969
- }
4970
- a[0]=d[0]=1;
4971
- for (i=254; i>=0; --i) {
4972
- r=(z[i>>>3]>>>(i&7))&1;
4973
- sel25519(a,b,r);
4974
- sel25519(c,d,r);
4975
- A(e,a,c);
4976
- Z(a,a,c);
4977
- A(c,b,d);
4978
- Z(b,b,d);
4979
- S(d,e);
4980
- S(f,a);
4981
- M(a,c,a);
4982
- M(c,b,e);
4983
- A(e,a,c);
4984
- Z(a,a,c);
4985
- S(b,a);
4986
- Z(c,d,f);
4987
- M(a,c,_121665);
4988
- A(a,a,d);
4989
- M(c,c,a);
4990
- M(a,d,f);
4991
- M(d,b,x);
4992
- S(b,e);
4993
- sel25519(a,b,r);
4994
- sel25519(c,d,r);
4995
- }
4996
- for (i = 0; i < 16; i++) {
4997
- x[i+16]=a[i];
4998
- x[i+32]=c[i];
4999
- x[i+48]=b[i];
5000
- x[i+64]=d[i];
5001
- }
5002
- var x32 = x.subarray(32);
5003
- var x16 = x.subarray(16);
5004
- inv25519(x32,x32);
5005
- M(x16,x16,x32);
5006
- pack25519(q,x16);
5007
- return 0;
5008
- }
5009
-
5010
- function crypto_scalarmult_base(q, n) {
5011
- return crypto_scalarmult(q, n, _9);
5012
- }
5013
-
5014
- function crypto_box_keypair(y, x) {
5015
- randombytes(x, 32);
5016
- return crypto_scalarmult_base(y, x);
5017
- }
5018
-
5019
- function crypto_box_beforenm(k, y, x) {
5020
- var s = new Uint8Array(32);
5021
- crypto_scalarmult(s, x, y);
5022
- return crypto_core_hsalsa20(k, _0, s, sigma);
5023
- }
5024
-
5025
- var crypto_box_afternm = crypto_secretbox;
5026
- var crypto_box_open_afternm = crypto_secretbox_open;
5027
-
5028
- function crypto_box(c, m, d, n, y, x) {
5029
- var k = new Uint8Array(32);
5030
- crypto_box_beforenm(k, y, x);
5031
- return crypto_box_afternm(c, m, d, n, k);
5032
- }
5033
-
5034
- function crypto_box_open(m, c, d, n, y, x) {
5035
- var k = new Uint8Array(32);
5036
- crypto_box_beforenm(k, y, x);
5037
- return crypto_box_open_afternm(m, c, d, n, k);
5038
- }
5039
-
5040
- var K = [
5041
- 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
5042
- 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
5043
- 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
5044
- 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
5045
- 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
5046
- 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
5047
- 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
5048
- 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
5049
- 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
5050
- 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
5051
- 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
5052
- 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
5053
- 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
5054
- 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
5055
- 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
5056
- 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
5057
- 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
5058
- 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
5059
- 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
5060
- 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
5061
- 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
5062
- 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
5063
- 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
5064
- 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
5065
- 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
5066
- 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
5067
- 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
5068
- 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
5069
- 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
5070
- 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
5071
- 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
5072
- 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
5073
- 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
5074
- 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
5075
- 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
5076
- 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
5077
- 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
5078
- 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
5079
- 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
5080
- 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
5081
- ];
5082
-
5083
- function crypto_hashblocks_hl(hh, hl, m, n) {
5084
- var wh = new Int32Array(16), wl = new Int32Array(16),
5085
- bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
5086
- bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
5087
- th, tl, i, j, h, l, a, b, c, d;
5088
-
5089
- var ah0 = hh[0],
5090
- ah1 = hh[1],
5091
- ah2 = hh[2],
5092
- ah3 = hh[3],
5093
- ah4 = hh[4],
5094
- ah5 = hh[5],
5095
- ah6 = hh[6],
5096
- ah7 = hh[7],
5097
-
5098
- al0 = hl[0],
5099
- al1 = hl[1],
5100
- al2 = hl[2],
5101
- al3 = hl[3],
5102
- al4 = hl[4],
5103
- al5 = hl[5],
5104
- al6 = hl[6],
5105
- al7 = hl[7];
5106
-
5107
- var pos = 0;
5108
- while (n >= 128) {
5109
- for (i = 0; i < 16; i++) {
5110
- j = 8 * i + pos;
5111
- wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
5112
- wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
5113
- }
5114
- for (i = 0; i < 80; i++) {
5115
- bh0 = ah0;
5116
- bh1 = ah1;
5117
- bh2 = ah2;
5118
- bh3 = ah3;
5119
- bh4 = ah4;
5120
- bh5 = ah5;
5121
- bh6 = ah6;
5122
- bh7 = ah7;
5123
-
5124
- bl0 = al0;
5125
- bl1 = al1;
5126
- bl2 = al2;
5127
- bl3 = al3;
5128
- bl4 = al4;
5129
- bl5 = al5;
5130
- bl6 = al6;
5131
- bl7 = al7;
5132
-
5133
- // add
5134
- h = ah7;
5135
- l = al7;
5136
-
5137
- a = l & 0xffff; b = l >>> 16;
5138
- c = h & 0xffff; d = h >>> 16;
5139
-
5140
- // Sigma1
5141
- h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
5142
- l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
5143
-
5144
- a += l & 0xffff; b += l >>> 16;
5145
- c += h & 0xffff; d += h >>> 16;
5146
-
5147
- // Ch
5148
- h = (ah4 & ah5) ^ (~ah4 & ah6);
5149
- l = (al4 & al5) ^ (~al4 & al6);
5150
-
5151
- a += l & 0xffff; b += l >>> 16;
5152
- c += h & 0xffff; d += h >>> 16;
5153
-
5154
- // K
5155
- h = K[i*2];
5156
- l = K[i*2+1];
5157
-
5158
- a += l & 0xffff; b += l >>> 16;
5159
- c += h & 0xffff; d += h >>> 16;
5160
-
5161
- // w
5162
- h = wh[i%16];
5163
- l = wl[i%16];
5164
-
5165
- a += l & 0xffff; b += l >>> 16;
5166
- c += h & 0xffff; d += h >>> 16;
5167
-
5168
- b += a >>> 16;
5169
- c += b >>> 16;
5170
- d += c >>> 16;
5171
-
5172
- th = c & 0xffff | d << 16;
5173
- tl = a & 0xffff | b << 16;
5174
-
5175
- // add
5176
- h = th;
5177
- l = tl;
5178
-
5179
- a = l & 0xffff; b = l >>> 16;
5180
- c = h & 0xffff; d = h >>> 16;
5181
-
5182
- // Sigma0
5183
- h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
5184
- l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
5185
-
5186
- a += l & 0xffff; b += l >>> 16;
5187
- c += h & 0xffff; d += h >>> 16;
5188
-
5189
- // Maj
5190
- h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
5191
- l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
5192
-
5193
- a += l & 0xffff; b += l >>> 16;
5194
- c += h & 0xffff; d += h >>> 16;
5195
-
5196
- b += a >>> 16;
5197
- c += b >>> 16;
5198
- d += c >>> 16;
5199
-
5200
- bh7 = (c & 0xffff) | (d << 16);
5201
- bl7 = (a & 0xffff) | (b << 16);
5202
-
5203
- // add
5204
- h = bh3;
5205
- l = bl3;
5206
-
5207
- a = l & 0xffff; b = l >>> 16;
5208
- c = h & 0xffff; d = h >>> 16;
5209
-
5210
- h = th;
5211
- l = tl;
5212
-
5213
- a += l & 0xffff; b += l >>> 16;
5214
- c += h & 0xffff; d += h >>> 16;
5215
-
5216
- b += a >>> 16;
5217
- c += b >>> 16;
5218
- d += c >>> 16;
5219
-
5220
- bh3 = (c & 0xffff) | (d << 16);
5221
- bl3 = (a & 0xffff) | (b << 16);
5222
-
5223
- ah1 = bh0;
5224
- ah2 = bh1;
5225
- ah3 = bh2;
5226
- ah4 = bh3;
5227
- ah5 = bh4;
5228
- ah6 = bh5;
5229
- ah7 = bh6;
5230
- ah0 = bh7;
5231
-
5232
- al1 = bl0;
5233
- al2 = bl1;
5234
- al3 = bl2;
5235
- al4 = bl3;
5236
- al5 = bl4;
5237
- al6 = bl5;
5238
- al7 = bl6;
5239
- al0 = bl7;
5240
-
5241
- if (i%16 === 15) {
5242
- for (j = 0; j < 16; j++) {
5243
- // add
5244
- h = wh[j];
5245
- l = wl[j];
5246
-
5247
- a = l & 0xffff; b = l >>> 16;
5248
- c = h & 0xffff; d = h >>> 16;
5249
-
5250
- h = wh[(j+9)%16];
5251
- l = wl[(j+9)%16];
5252
-
5253
- a += l & 0xffff; b += l >>> 16;
5254
- c += h & 0xffff; d += h >>> 16;
5255
-
5256
- // sigma0
5257
- th = wh[(j+1)%16];
5258
- tl = wl[(j+1)%16];
5259
- h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
5260
- l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
5261
-
5262
- a += l & 0xffff; b += l >>> 16;
5263
- c += h & 0xffff; d += h >>> 16;
5264
-
5265
- // sigma1
5266
- th = wh[(j+14)%16];
5267
- tl = wl[(j+14)%16];
5268
- h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
5269
- l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
5270
-
5271
- a += l & 0xffff; b += l >>> 16;
5272
- c += h & 0xffff; d += h >>> 16;
5273
-
5274
- b += a >>> 16;
5275
- c += b >>> 16;
5276
- d += c >>> 16;
5277
-
5278
- wh[j] = (c & 0xffff) | (d << 16);
5279
- wl[j] = (a & 0xffff) | (b << 16);
5280
- }
5281
- }
5282
- }
5283
-
5284
- // add
5285
- h = ah0;
5286
- l = al0;
5287
-
5288
- a = l & 0xffff; b = l >>> 16;
5289
- c = h & 0xffff; d = h >>> 16;
5290
-
5291
- h = hh[0];
5292
- l = hl[0];
5293
-
5294
- a += l & 0xffff; b += l >>> 16;
5295
- c += h & 0xffff; d += h >>> 16;
5296
-
5297
- b += a >>> 16;
5298
- c += b >>> 16;
5299
- d += c >>> 16;
5300
-
5301
- hh[0] = ah0 = (c & 0xffff) | (d << 16);
5302
- hl[0] = al0 = (a & 0xffff) | (b << 16);
5303
-
5304
- h = ah1;
5305
- l = al1;
5306
-
5307
- a = l & 0xffff; b = l >>> 16;
5308
- c = h & 0xffff; d = h >>> 16;
5309
-
5310
- h = hh[1];
5311
- l = hl[1];
5312
-
5313
- a += l & 0xffff; b += l >>> 16;
5314
- c += h & 0xffff; d += h >>> 16;
5315
-
5316
- b += a >>> 16;
5317
- c += b >>> 16;
5318
- d += c >>> 16;
5319
-
5320
- hh[1] = ah1 = (c & 0xffff) | (d << 16);
5321
- hl[1] = al1 = (a & 0xffff) | (b << 16);
5322
-
5323
- h = ah2;
5324
- l = al2;
5325
-
5326
- a = l & 0xffff; b = l >>> 16;
5327
- c = h & 0xffff; d = h >>> 16;
5328
-
5329
- h = hh[2];
5330
- l = hl[2];
5331
-
5332
- a += l & 0xffff; b += l >>> 16;
5333
- c += h & 0xffff; d += h >>> 16;
5334
-
5335
- b += a >>> 16;
5336
- c += b >>> 16;
5337
- d += c >>> 16;
5338
-
5339
- hh[2] = ah2 = (c & 0xffff) | (d << 16);
5340
- hl[2] = al2 = (a & 0xffff) | (b << 16);
5341
-
5342
- h = ah3;
5343
- l = al3;
5344
-
5345
- a = l & 0xffff; b = l >>> 16;
5346
- c = h & 0xffff; d = h >>> 16;
5347
-
5348
- h = hh[3];
5349
- l = hl[3];
5350
-
5351
- a += l & 0xffff; b += l >>> 16;
5352
- c += h & 0xffff; d += h >>> 16;
5353
-
5354
- b += a >>> 16;
5355
- c += b >>> 16;
5356
- d += c >>> 16;
5357
-
5358
- hh[3] = ah3 = (c & 0xffff) | (d << 16);
5359
- hl[3] = al3 = (a & 0xffff) | (b << 16);
5360
-
5361
- h = ah4;
5362
- l = al4;
5363
-
5364
- a = l & 0xffff; b = l >>> 16;
5365
- c = h & 0xffff; d = h >>> 16;
5366
-
5367
- h = hh[4];
5368
- l = hl[4];
5369
-
5370
- a += l & 0xffff; b += l >>> 16;
5371
- c += h & 0xffff; d += h >>> 16;
5372
-
5373
- b += a >>> 16;
5374
- c += b >>> 16;
5375
- d += c >>> 16;
5376
-
5377
- hh[4] = ah4 = (c & 0xffff) | (d << 16);
5378
- hl[4] = al4 = (a & 0xffff) | (b << 16);
5379
-
5380
- h = ah5;
5381
- l = al5;
5382
-
5383
- a = l & 0xffff; b = l >>> 16;
5384
- c = h & 0xffff; d = h >>> 16;
5385
-
5386
- h = hh[5];
5387
- l = hl[5];
5388
-
5389
- a += l & 0xffff; b += l >>> 16;
5390
- c += h & 0xffff; d += h >>> 16;
5391
-
5392
- b += a >>> 16;
5393
- c += b >>> 16;
5394
- d += c >>> 16;
5395
-
5396
- hh[5] = ah5 = (c & 0xffff) | (d << 16);
5397
- hl[5] = al5 = (a & 0xffff) | (b << 16);
5398
-
5399
- h = ah6;
5400
- l = al6;
5401
-
5402
- a = l & 0xffff; b = l >>> 16;
5403
- c = h & 0xffff; d = h >>> 16;
5404
-
5405
- h = hh[6];
5406
- l = hl[6];
5407
-
5408
- a += l & 0xffff; b += l >>> 16;
5409
- c += h & 0xffff; d += h >>> 16;
5410
-
5411
- b += a >>> 16;
5412
- c += b >>> 16;
5413
- d += c >>> 16;
5414
-
5415
- hh[6] = ah6 = (c & 0xffff) | (d << 16);
5416
- hl[6] = al6 = (a & 0xffff) | (b << 16);
5417
-
5418
- h = ah7;
5419
- l = al7;
5420
-
5421
- a = l & 0xffff; b = l >>> 16;
5422
- c = h & 0xffff; d = h >>> 16;
5423
-
5424
- h = hh[7];
5425
- l = hl[7];
5426
-
5427
- a += l & 0xffff; b += l >>> 16;
5428
- c += h & 0xffff; d += h >>> 16;
5429
-
5430
- b += a >>> 16;
5431
- c += b >>> 16;
5432
- d += c >>> 16;
5433
-
5434
- hh[7] = ah7 = (c & 0xffff) | (d << 16);
5435
- hl[7] = al7 = (a & 0xffff) | (b << 16);
5436
-
5437
- pos += 128;
5438
- n -= 128;
5439
- }
5440
-
5441
- return n;
5442
- }
5443
-
5444
- function crypto_hash(out, m, n) {
5445
- var hh = new Int32Array(8),
5446
- hl = new Int32Array(8),
5447
- x = new Uint8Array(256),
5448
- i, b = n;
5449
-
5450
- hh[0] = 0x6a09e667;
5451
- hh[1] = 0xbb67ae85;
5452
- hh[2] = 0x3c6ef372;
5453
- hh[3] = 0xa54ff53a;
5454
- hh[4] = 0x510e527f;
5455
- hh[5] = 0x9b05688c;
5456
- hh[6] = 0x1f83d9ab;
5457
- hh[7] = 0x5be0cd19;
5458
-
5459
- hl[0] = 0xf3bcc908;
5460
- hl[1] = 0x84caa73b;
5461
- hl[2] = 0xfe94f82b;
5462
- hl[3] = 0x5f1d36f1;
5463
- hl[4] = 0xade682d1;
5464
- hl[5] = 0x2b3e6c1f;
5465
- hl[6] = 0xfb41bd6b;
5466
- hl[7] = 0x137e2179;
5467
-
5468
- crypto_hashblocks_hl(hh, hl, m, n);
5469
- n %= 128;
5470
-
5471
- for (i = 0; i < n; i++) x[i] = m[b-n+i];
5472
- x[n] = 128;
5473
-
5474
- n = 256-128*(n<112?1:0);
5475
- x[n-9] = 0;
5476
- ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
5477
- crypto_hashblocks_hl(hh, hl, x, n);
5478
-
5479
- for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
5480
-
5481
- return 0;
5482
- }
5483
-
5484
- function add(p, q) {
5485
- var a = gf(), b = gf(), c = gf(),
5486
- d = gf(), e = gf(), f = gf(),
5487
- g = gf(), h = gf(), t = gf();
5488
-
5489
- Z(a, p[1], p[0]);
5490
- Z(t, q[1], q[0]);
5491
- M(a, a, t);
5492
- A(b, p[0], p[1]);
5493
- A(t, q[0], q[1]);
5494
- M(b, b, t);
5495
- M(c, p[3], q[3]);
5496
- M(c, c, D2);
5497
- M(d, p[2], q[2]);
5498
- A(d, d, d);
5499
- Z(e, b, a);
5500
- Z(f, d, c);
5501
- A(g, d, c);
5502
- A(h, b, a);
5503
-
5504
- M(p[0], e, f);
5505
- M(p[1], h, g);
5506
- M(p[2], g, f);
5507
- M(p[3], e, h);
5508
- }
5509
-
5510
- function cswap(p, q, b) {
5511
- var i;
5512
- for (i = 0; i < 4; i++) {
5513
- sel25519(p[i], q[i], b);
5514
- }
5515
- }
5516
-
5517
- function pack(r, p) {
5518
- var tx = gf(), ty = gf(), zi = gf();
5519
- inv25519(zi, p[2]);
5520
- M(tx, p[0], zi);
5521
- M(ty, p[1], zi);
5522
- pack25519(r, ty);
5523
- r[31] ^= par25519(tx) << 7;
5524
- }
5525
-
5526
- function scalarmult(p, q, s) {
5527
- var b, i;
5528
- set25519(p[0], gf0);
5529
- set25519(p[1], gf1);
5530
- set25519(p[2], gf1);
5531
- set25519(p[3], gf0);
5532
- for (i = 255; i >= 0; --i) {
5533
- b = (s[(i/8)|0] >> (i&7)) & 1;
5534
- cswap(p, q, b);
5535
- add(q, p);
5536
- add(p, p);
5537
- cswap(p, q, b);
5538
- }
5539
- }
5540
-
5541
- function scalarbase(p, s) {
5542
- var q = [gf(), gf(), gf(), gf()];
5543
- set25519(q[0], X);
5544
- set25519(q[1], Y);
5545
- set25519(q[2], gf1);
5546
- M(q[3], X, Y);
5547
- scalarmult(p, q, s);
5548
- }
5549
-
5550
- function crypto_sign_keypair(pk, sk, seeded) {
5551
- var d = new Uint8Array(64);
5552
- var p = [gf(), gf(), gf(), gf()];
5553
- var i;
5554
-
5555
- if (!seeded) randombytes(sk, 32);
5556
- crypto_hash(d, sk, 32);
5557
- d[0] &= 248;
5558
- d[31] &= 127;
5559
- d[31] |= 64;
5560
-
5561
- scalarbase(p, d);
5562
- pack(pk, p);
5563
-
5564
- for (i = 0; i < 32; i++) sk[i+32] = pk[i];
5565
- return 0;
5566
- }
5567
-
5568
- var L = new Float64Array([0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]);
5569
-
5570
- function modL(r, x) {
5571
- var carry, i, j, k;
5572
- for (i = 63; i >= 32; --i) {
5573
- carry = 0;
5574
- for (j = i - 32, k = i - 12; j < k; ++j) {
5575
- x[j] += carry - 16 * x[i] * L[j - (i - 32)];
5576
- carry = Math.floor((x[j] + 128) / 256);
5577
- x[j] -= carry * 256;
5578
- }
5579
- x[j] += carry;
5580
- x[i] = 0;
5581
- }
5582
- carry = 0;
5583
- for (j = 0; j < 32; j++) {
5584
- x[j] += carry - (x[31] >> 4) * L[j];
5585
- carry = x[j] >> 8;
5586
- x[j] &= 255;
5587
- }
5588
- for (j = 0; j < 32; j++) x[j] -= carry * L[j];
5589
- for (i = 0; i < 32; i++) {
5590
- x[i+1] += x[i] >> 8;
5591
- r[i] = x[i] & 255;
5592
- }
5593
- }
5594
-
5595
- function reduce(r) {
5596
- var x = new Float64Array(64), i;
5597
- for (i = 0; i < 64; i++) x[i] = r[i];
5598
- for (i = 0; i < 64; i++) r[i] = 0;
5599
- modL(r, x);
5600
- }
5601
-
5602
- // Note: difference from C - smlen returned, not passed as argument.
5603
- function crypto_sign(sm, m, n, sk) {
5604
- var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
5605
- var i, j, x = new Float64Array(64);
5606
- var p = [gf(), gf(), gf(), gf()];
5607
-
5608
- crypto_hash(d, sk, 32);
5609
- d[0] &= 248;
5610
- d[31] &= 127;
5611
- d[31] |= 64;
5612
-
5613
- var smlen = n + 64;
5614
- for (i = 0; i < n; i++) sm[64 + i] = m[i];
5615
- for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
5616
-
5617
- crypto_hash(r, sm.subarray(32), n+32);
5618
- reduce(r);
5619
- scalarbase(p, r);
5620
- pack(sm, p);
5621
-
5622
- for (i = 32; i < 64; i++) sm[i] = sk[i];
5623
- crypto_hash(h, sm, n + 64);
5624
- reduce(h);
5625
-
5626
- for (i = 0; i < 64; i++) x[i] = 0;
5627
- for (i = 0; i < 32; i++) x[i] = r[i];
5628
- for (i = 0; i < 32; i++) {
5629
- for (j = 0; j < 32; j++) {
5630
- x[i+j] += h[i] * d[j];
5631
- }
5632
- }
5633
-
5634
- modL(sm.subarray(32), x);
5635
- return smlen;
5636
- }
5637
-
5638
- function unpackneg(r, p) {
5639
- var t = gf(), chk = gf(), num = gf(),
5640
- den = gf(), den2 = gf(), den4 = gf(),
5641
- den6 = gf();
5642
-
5643
- set25519(r[2], gf1);
5644
- unpack25519(r[1], p);
5645
- S(num, r[1]);
5646
- M(den, num, D);
5647
- Z(num, num, r[2]);
5648
- A(den, r[2], den);
5649
-
5650
- S(den2, den);
5651
- S(den4, den2);
5652
- M(den6, den4, den2);
5653
- M(t, den6, num);
5654
- M(t, t, den);
5655
-
5656
- pow2523(t, t);
5657
- M(t, t, num);
5658
- M(t, t, den);
5659
- M(t, t, den);
5660
- M(r[0], t, den);
5661
-
5662
- S(chk, r[0]);
5663
- M(chk, chk, den);
5664
- if (neq25519(chk, num)) M(r[0], r[0], I);
5665
-
5666
- S(chk, r[0]);
5667
- M(chk, chk, den);
5668
- if (neq25519(chk, num)) return -1;
5669
-
5670
- if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
5671
-
5672
- M(r[3], r[0], r[1]);
5673
- return 0;
5674
- }
5675
-
5676
- function crypto_sign_open(m, sm, n, pk) {
5677
- var i;
5678
- var t = new Uint8Array(32), h = new Uint8Array(64);
5679
- var p = [gf(), gf(), gf(), gf()],
5680
- q = [gf(), gf(), gf(), gf()];
5681
-
5682
- if (n < 64) return -1;
5683
-
5684
- if (unpackneg(q, pk)) return -1;
5685
-
5686
- for (i = 0; i < n; i++) m[i] = sm[i];
5687
- for (i = 0; i < 32; i++) m[i+32] = pk[i];
5688
- crypto_hash(h, m, n);
5689
- reduce(h);
5690
- scalarmult(p, q, h);
5691
-
5692
- scalarbase(q, sm.subarray(32));
5693
- add(p, q);
5694
- pack(t, p);
5695
-
5696
- n -= 64;
5697
- if (crypto_verify_32(sm, 0, t, 0)) {
5698
- for (i = 0; i < n; i++) m[i] = 0;
5699
- return -1;
5700
- }
5701
-
5702
- for (i = 0; i < n; i++) m[i] = sm[i + 64];
5703
- return n;
5704
- }
5705
-
5706
- var crypto_secretbox_KEYBYTES = 32,
5707
- crypto_secretbox_NONCEBYTES = 24,
5708
- crypto_secretbox_ZEROBYTES = 32,
5709
- crypto_secretbox_BOXZEROBYTES = 16,
5710
- crypto_scalarmult_BYTES = 32,
5711
- crypto_scalarmult_SCALARBYTES = 32,
5712
- crypto_box_PUBLICKEYBYTES = 32,
5713
- crypto_box_SECRETKEYBYTES = 32,
5714
- crypto_box_BEFORENMBYTES = 32,
5715
- crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
5716
- crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
5717
- crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
5718
- crypto_sign_BYTES = 64,
5719
- crypto_sign_PUBLICKEYBYTES = 32,
5720
- crypto_sign_SECRETKEYBYTES = 64,
5721
- crypto_sign_SEEDBYTES = 32,
5722
- crypto_hash_BYTES = 64;
5723
-
5724
- nacl.lowlevel = {
5725
- crypto_core_hsalsa20: crypto_core_hsalsa20,
5726
- crypto_stream_xor: crypto_stream_xor,
5727
- crypto_stream: crypto_stream,
5728
- crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
5729
- crypto_stream_salsa20: crypto_stream_salsa20,
5730
- crypto_onetimeauth: crypto_onetimeauth,
5731
- crypto_onetimeauth_verify: crypto_onetimeauth_verify,
5732
- crypto_verify_16: crypto_verify_16,
5733
- crypto_verify_32: crypto_verify_32,
5734
- crypto_secretbox: crypto_secretbox,
5735
- crypto_secretbox_open: crypto_secretbox_open,
5736
- crypto_scalarmult: crypto_scalarmult,
5737
- crypto_scalarmult_base: crypto_scalarmult_base,
5738
- crypto_box_beforenm: crypto_box_beforenm,
5739
- crypto_box_afternm: crypto_box_afternm,
5740
- crypto_box: crypto_box,
5741
- crypto_box_open: crypto_box_open,
5742
- crypto_box_keypair: crypto_box_keypair,
5743
- crypto_hash: crypto_hash,
5744
- crypto_sign: crypto_sign,
5745
- crypto_sign_keypair: crypto_sign_keypair,
5746
- crypto_sign_open: crypto_sign_open,
5747
-
5748
- crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
5749
- crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
5750
- crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
5751
- crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
5752
- crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
5753
- crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
5754
- crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
5755
- crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
5756
- crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
5757
- crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
5758
- crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
5759
- crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
5760
- crypto_sign_BYTES: crypto_sign_BYTES,
5761
- crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
5762
- crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
5763
- crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
5764
- crypto_hash_BYTES: crypto_hash_BYTES,
5765
-
5766
- gf: gf,
5767
- D: D,
5768
- L: L,
5769
- pack25519: pack25519,
5770
- unpack25519: unpack25519,
5771
- M: M,
5772
- A: A,
5773
- S: S,
5774
- Z: Z,
5775
- pow2523: pow2523,
5776
- add: add,
5777
- set25519: set25519,
5778
- modL: modL,
5779
- scalarmult: scalarmult,
5780
- scalarbase: scalarbase,
5781
- };
5782
-
5783
- /* High-level API */
5784
-
5785
- function checkLengths(k, n) {
5786
- if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
5787
- if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
5788
- }
5789
-
5790
- function checkBoxLengths(pk, sk) {
5791
- if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
5792
- if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
5793
- }
5794
-
5795
- function checkArrayTypes() {
5796
- for (var i = 0; i < arguments.length; i++) {
5797
- if (!(arguments[i] instanceof Uint8Array))
5798
- throw new TypeError('unexpected type, use Uint8Array');
5799
- }
5800
- }
5801
-
5802
- function cleanup(arr) {
5803
- for (var i = 0; i < arr.length; i++) arr[i] = 0;
5804
- }
5805
-
5806
- nacl.randomBytes = function(n) {
5807
- var b = new Uint8Array(n);
5808
- randombytes(b, n);
5809
- return b;
5810
- };
5811
-
5812
- nacl.secretbox = function(msg, nonce, key) {
5813
- checkArrayTypes(msg, nonce, key);
5814
- checkLengths(key, nonce);
5815
- var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
5816
- var c = new Uint8Array(m.length);
5817
- for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
5818
- crypto_secretbox(c, m, m.length, nonce, key);
5819
- return c.subarray(crypto_secretbox_BOXZEROBYTES);
5820
- };
5821
-
5822
- nacl.secretbox.open = function(box, nonce, key) {
5823
- checkArrayTypes(box, nonce, key);
5824
- checkLengths(key, nonce);
5825
- var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
5826
- var m = new Uint8Array(c.length);
5827
- for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
5828
- if (c.length < 32) return null;
5829
- if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
5830
- return m.subarray(crypto_secretbox_ZEROBYTES);
5831
- };
5832
-
5833
- nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
5834
- nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
5835
- nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
5836
-
5837
- nacl.scalarMult = function(n, p) {
5838
- checkArrayTypes(n, p);
5839
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
5840
- if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
5841
- var q = new Uint8Array(crypto_scalarmult_BYTES);
5842
- crypto_scalarmult(q, n, p);
5843
- return q;
5844
- };
5845
-
5846
- nacl.scalarMult.base = function(n) {
5847
- checkArrayTypes(n);
5848
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
5849
- var q = new Uint8Array(crypto_scalarmult_BYTES);
5850
- crypto_scalarmult_base(q, n);
5851
- return q;
5852
- };
5853
-
5854
- nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
5855
- nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
5856
-
5857
- nacl.box = function(msg, nonce, publicKey, secretKey) {
5858
- var k = nacl.box.before(publicKey, secretKey);
5859
- return nacl.secretbox(msg, nonce, k);
5860
- };
5861
-
5862
- nacl.box.before = function(publicKey, secretKey) {
5863
- checkArrayTypes(publicKey, secretKey);
5864
- checkBoxLengths(publicKey, secretKey);
5865
- var k = new Uint8Array(crypto_box_BEFORENMBYTES);
5866
- crypto_box_beforenm(k, publicKey, secretKey);
5867
- return k;
5868
- };
5869
-
5870
- nacl.box.after = nacl.secretbox;
5871
-
5872
- nacl.box.open = function(msg, nonce, publicKey, secretKey) {
5873
- var k = nacl.box.before(publicKey, secretKey);
5874
- return nacl.secretbox.open(msg, nonce, k);
5875
- };
5876
-
5877
- nacl.box.open.after = nacl.secretbox.open;
5878
-
5879
- nacl.box.keyPair = function() {
5880
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
5881
- var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
5882
- crypto_box_keypair(pk, sk);
5883
- return {publicKey: pk, secretKey: sk};
5884
- };
5885
-
5886
- nacl.box.keyPair.fromSecretKey = function(secretKey) {
5887
- checkArrayTypes(secretKey);
5888
- if (secretKey.length !== crypto_box_SECRETKEYBYTES)
5889
- throw new Error('bad secret key size');
5890
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
5891
- crypto_scalarmult_base(pk, secretKey);
5892
- return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
5893
- };
5894
-
5895
- nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
5896
- nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
5897
- nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
5898
- nacl.box.nonceLength = crypto_box_NONCEBYTES;
5899
- nacl.box.overheadLength = nacl.secretbox.overheadLength;
5900
-
5901
- nacl.sign = function(msg, secretKey) {
5902
- checkArrayTypes(msg, secretKey);
5903
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
5904
- throw new Error('bad secret key size');
5905
- var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
5906
- crypto_sign(signedMsg, msg, msg.length, secretKey);
5907
- return signedMsg;
5908
- };
5909
-
5910
- nacl.sign.open = function(signedMsg, publicKey) {
5911
- checkArrayTypes(signedMsg, publicKey);
5912
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
5913
- throw new Error('bad public key size');
5914
- var tmp = new Uint8Array(signedMsg.length);
5915
- var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
5916
- if (mlen < 0) return null;
5917
- var m = new Uint8Array(mlen);
5918
- for (var i = 0; i < m.length; i++) m[i] = tmp[i];
5919
- return m;
5920
- };
5921
-
5922
- nacl.sign.detached = function(msg, secretKey) {
5923
- var signedMsg = nacl.sign(msg, secretKey);
5924
- var sig = new Uint8Array(crypto_sign_BYTES);
5925
- for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
5926
- return sig;
5927
- };
5928
-
5929
- nacl.sign.detached.verify = function(msg, sig, publicKey) {
5930
- checkArrayTypes(msg, sig, publicKey);
5931
- if (sig.length !== crypto_sign_BYTES)
5932
- throw new Error('bad signature size');
5933
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
5934
- throw new Error('bad public key size');
5935
- var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
5936
- var m = new Uint8Array(crypto_sign_BYTES + msg.length);
5937
- var i;
5938
- for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
5939
- for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
5940
- return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
5941
- };
5942
-
5943
- nacl.sign.keyPair = function() {
5944
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
5945
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
5946
- crypto_sign_keypair(pk, sk);
5947
- return {publicKey: pk, secretKey: sk};
5948
- };
5949
-
5950
- nacl.sign.keyPair.fromSecretKey = function(secretKey) {
5951
- checkArrayTypes(secretKey);
5952
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
5953
- throw new Error('bad secret key size');
5954
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
5955
- for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
5956
- return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
5957
- };
5958
-
5959
- nacl.sign.keyPair.fromSeed = function(seed) {
5960
- checkArrayTypes(seed);
5961
- if (seed.length !== crypto_sign_SEEDBYTES)
5962
- throw new Error('bad seed size');
5963
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
5964
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
5965
- for (var i = 0; i < 32; i++) sk[i] = seed[i];
5966
- crypto_sign_keypair(pk, sk, true);
5967
- return {publicKey: pk, secretKey: sk};
5968
- };
5969
-
5970
- nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
5971
- nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
5972
- nacl.sign.seedLength = crypto_sign_SEEDBYTES;
5973
- nacl.sign.signatureLength = crypto_sign_BYTES;
5974
-
5975
- nacl.hash = function(msg) {
5976
- checkArrayTypes(msg);
5977
- var h = new Uint8Array(crypto_hash_BYTES);
5978
- crypto_hash(h, msg, msg.length);
5979
- return h;
5980
- };
5981
-
5982
- nacl.hash.hashLength = crypto_hash_BYTES;
5983
-
5984
- nacl.verify = function(x, y) {
5985
- checkArrayTypes(x, y);
5986
- // Zero length arguments are considered not equal.
5987
- if (x.length === 0 || y.length === 0) return false;
5988
- if (x.length !== y.length) return false;
5989
- return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
5990
- };
5991
-
5992
- nacl.setPRNG = function(fn) {
5993
- randombytes = fn;
5994
- };
5995
-
5996
- (function() {
5997
- // Initialize PRNG if environment provides CSPRNG.
5998
- // If not, methods calling randombytes will throw.
5999
- var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
6000
- if (crypto && crypto.getRandomValues) {
6001
- // Browsers.
6002
- var QUOTA = 65536;
6003
- nacl.setPRNG(function(x, n) {
6004
- var i, v = new Uint8Array(n);
6005
- for (i = 0; i < n; i += QUOTA) {
6006
- crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
6007
- }
6008
- for (i = 0; i < n; i++) x[i] = v[i];
6009
- cleanup(v);
6010
- });
6011
- } else if (typeof commonjsRequire !== 'undefined') {
6012
- // Node.js.
6013
- crypto = require$$0;
6014
- if (crypto && crypto.randomBytes) {
6015
- nacl.setPRNG(function(x, n) {
6016
- var i, v = crypto.randomBytes(n);
6017
- for (i = 0; i < n; i++) x[i] = v[i];
6018
- cleanup(v);
6019
- });
6020
- }
6021
- }
6022
- })();
6023
-
6024
- })(module.exports ? module.exports : (self.nacl = self.nacl || {}));
6025
- } (naclFast));
6026
- return naclFast.exports;
6027
- }
6028
-
6029
- var naclFastExports = requireNaclFast();
6030
- var nacl = /*@__PURE__*/getDefaultExportFromCjs(naclFastExports);
6031
-
6032
3590
  // guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
6033
3591
  //
6034
3592
  // A guest is an ed25519 keypair generated on the device. Its public key is the
6035
3593
  // Bounded account address; it signs the auth challenge exactly like a wallet.
6036
3594
  //
6037
- // Two backends, chosen automatically:
6038
- // 1. WebCrypto Ed25519 + IndexedDB (browsers that support it) — the key is
6039
- // NON-EXTRACTABLE: an XSS can ask it to *sign* but can never read the
6040
- // private bytes. This is the secure default.
6041
- // 2. tweetnacl keypair in platform storage (React Native / older browsers) —
6042
- // the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
6043
- // treat it as a low-stakes guest identity and tell users to upgrade
6044
- // (link an email) before they care about not losing it.
3595
+ // Guest auth has one backend: WebCrypto Ed25519 + IndexedDB. The key is
3596
+ // NON-EXTRACTABLE: an XSS can ask it to sign but can never read the private
3597
+ // bytes. If WebCrypto or IndexedDB is unavailable, guest auth fails closed
3598
+ // instead of silently creating an extractable/stored-secret credential.
6045
3599
  //
6046
- // Either way the public output is identical: a base58 address + a base64
3600
+ // The public output is a base58 address + a base64
6047
3601
  // detached signature, which is the format the session endpoint already accepts.
6048
- const FALLBACK_STORE_KEY = 'bounded_guest_key_v1';
3602
+ const LEGACY_STORED_SECRET_KEY = 'bounded_guest_key_v1';
6049
3603
  const IDB_NAME = 'bounded-guest';
6050
3604
  const IDB_STORE = 'keys';
6051
3605
  const IDB_KEY = 'ed25519';
3606
+ const GUEST_KEY_REQUIREMENT = 'Guest auth requires non-extractable WebCrypto Ed25519 keys persisted in IndexedDB; ' +
3607
+ 'stored-secret guest credentials are disabled.';
6052
3608
  function toBase64(bytes) {
6053
3609
  let bin = '';
6054
3610
  for (let i = 0; i < bytes.length; i++)
@@ -6083,10 +3639,17 @@ function idbPut(db, key, val) {
6083
3639
  r.onerror = () => reject(r.error);
6084
3640
  });
6085
3641
  }
6086
- async function tryWebCrypto() {
3642
+ function guestKeyUnavailable(cause) {
3643
+ const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';
3644
+ return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);
3645
+ }
3646
+ async function webCryptoKey() {
6087
3647
  const s = subtle();
6088
- if (!s || typeof globalThis.indexedDB === 'undefined')
6089
- return null;
3648
+ if (!s)
3649
+ throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));
3650
+ if (typeof globalThis.indexedDB === 'undefined') {
3651
+ throw guestKeyUnavailable(new Error('IndexedDB is unavailable.'));
3652
+ }
6090
3653
  try {
6091
3654
  const db = await idb();
6092
3655
  let pair = (await idbGet(db, IDB_KEY));
@@ -6110,49 +3673,23 @@ async function tryWebCrypto() {
6110
3673
  },
6111
3674
  };
6112
3675
  }
6113
- catch (_a) {
6114
- return null; // engine lacks Ed25519 / IndexedDB blocked → fall back
6115
- }
6116
- }
6117
- // ----- tweetnacl (stored-secret) fallback ------------------------------------
6118
- function fallbackKey() {
6119
- const store = getPlatform().storage;
6120
- let secret;
6121
- const saved = store.getItem(FALLBACK_STORE_KEY);
6122
- if (saved) {
6123
- secret = bs58.decode(saved);
6124
- }
6125
- else {
6126
- const kp = web3_js.Keypair.generate();
6127
- secret = kp.secretKey; // 64 bytes
6128
- store.setItem(FALLBACK_STORE_KEY, bs58.encode(secret));
3676
+ catch (error) {
3677
+ throw guestKeyUnavailable(error);
6129
3678
  }
6130
- const kp = web3_js.Keypair.fromSecretKey(secret);
6131
- const address = kp.publicKey.toBase58();
6132
- return {
6133
- address,
6134
- nonExtractable: false,
6135
- async sign(message) {
6136
- const data = new TextEncoder().encode(message);
6137
- const sig = nacl.sign.detached(data, secret);
6138
- return toBase64(sig);
6139
- },
6140
- };
6141
3679
  }
6142
3680
  let cached = null;
6143
3681
  /** Get (or create) this device's durable guest key. */
6144
3682
  async function getGuestKey() {
6145
- var _a;
6146
3683
  if (cached)
6147
3684
  return cached;
6148
- cached = (_a = (await tryWebCrypto())) !== null && _a !== void 0 ? _a : fallbackKey();
3685
+ cached = await webCryptoKey();
6149
3686
  return cached;
6150
3687
  }
6151
3688
  /** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
6152
3689
  async function clearGuestKey() {
6153
3690
  cached = null;
6154
3691
  try {
6155
- getPlatform().storage.removeItem(FALLBACK_STORE_KEY);
3692
+ getPlatform().storage.removeItem(LEGACY_STORED_SECRET_KEY);
6156
3693
  }
6157
3694
  catch (_a) { }
6158
3695
  try {
@@ -6694,6 +4231,50 @@ const MODAL_CSS = `
6694
4231
  #bounded-auth-modal .hidden{display:none;}
6695
4232
  @media (max-width:480px){#bounded-auth-modal .ba-card{max-width:none;border-radius:16px;}}`;
6696
4233
 
4234
+ const SURFNET_RPC_URL = "https://surfpool.fly.dev";
4235
+ const SUPPORTED_SOLANA_NETWORKS = new Set([
4236
+ "solana_devnet",
4237
+ "solana_mainnet",
4238
+ "surfnet",
4239
+ ]);
4240
+ function normalizeSolanaRpcUrl(rpcUrl) {
4241
+ if (typeof rpcUrl !== "string")
4242
+ return null;
4243
+ const trimmed = rpcUrl.trim();
4244
+ return trimmed.length > 0 ? trimmed : null;
4245
+ }
4246
+ function isSupportedSolanaRpcNetwork(network) {
4247
+ return typeof network === "string" && SUPPORTED_SOLANA_NETWORKS.has(network);
4248
+ }
4249
+ function resolveSolanaWalletStandardChain(network, context) {
4250
+ switch (network) {
4251
+ case "solana_devnet":
4252
+ return "solana:devnet";
4253
+ case "solana_mainnet":
4254
+ return "solana:mainnet";
4255
+ case "surfnet":
4256
+ return "solana:localnet";
4257
+ case undefined:
4258
+ case null:
4259
+ case "":
4260
+ throw new Error(`${context} requires an explicit Solana network. ` +
4261
+ `Provide one of: solana_devnet, solana_mainnet, surfnet.`);
4262
+ default:
4263
+ throw new Error(`${context} does not support Solana network "${network}". ` +
4264
+ `Expected one of: solana_devnet, solana_mainnet, surfnet.`);
4265
+ }
4266
+ }
4267
+ function resolveSolanaRpcUrl(explicitRpcUrl, network, context) {
4268
+ if (network != null && network !== "" && !isSupportedSolanaRpcNetwork(network)) {
4269
+ throw new Error(`${context} does not support Solana network "${network}". ` +
4270
+ `Expected one of: solana_devnet, solana_mainnet, surfnet.`);
4271
+ }
4272
+ const rpcUrl = normalizeSolanaRpcUrl(explicitRpcUrl);
4273
+ if (rpcUrl)
4274
+ return rpcUrl;
4275
+ throw new Error(`${context} requires an explicit Solana RPC URL. Pass config.rpcUrl before signing or submitting onchain transactions.`);
4276
+ }
4277
+
6697
4278
  const PKCE_STORE_KEY = 'bounded.oidc.pkce';
6698
4279
  // Active session store (Web on web, RN on React Native) — selected by config,
6699
4280
  // not by `typeof window` (truthy on RN). OIDC redirect/popup is web-only, but the
@@ -7000,7 +4581,7 @@ async function exchangeCode(code, verifier, redirectUri) {
7000
4581
  let currentAuthProvider = null;
7001
4582
  let currentAuthMethod = null;
7002
4583
  let initConfig = null;
7003
- // --- localStorage helpers: track which auth method the user last logged in with ---
4584
+ // --- localStorage helpers: track which auth method created the active session ---
7004
4585
  const STORED_AUTH_METHOD_KEY$1 = 'bounded_last_auth_method';
7005
4586
  function getStoredAuthMethod() {
7006
4587
  try {
@@ -7024,7 +4605,7 @@ function setStoredAuthMethod(method) {
7024
4605
  }
7025
4606
  }
7026
4607
  /**
7027
- * Clears the session if it was created before auth method tracking (legacy session).
4608
+ * Clears the session if it was created by a different auth method.
7028
4609
  * Returns true if the session was cleared, false if the session is compatible.
7029
4610
  *
7030
4611
  * Dispatches to the correct session manager based on the current auth method
@@ -7032,18 +4613,17 @@ function setStoredAuthMethod(method) {
7032
4613
  * are properly cleared.
7033
4614
  */
7034
4615
  function clearIncompatibleSession() {
7035
- if (getStoredAuthMethod() !== null) {
7036
- return false; // Auth method is tracked — session is compatible
4616
+ if (getStoredAuthMethod() === currentAuthMethod) {
4617
+ return false;
7037
4618
  }
7038
- // Legacy session (no stored auth method) — clear it so the user re-authenticates
7039
- // with the correct provider.
7040
- // Clear both managers — on web the RN manager is a no-op (not configured),
7041
- // on RN the web manager is a no-op (no localStorage).
4619
+ // Clear both managers: on web the RN manager is a no-op (not configured),
4620
+ // and on RN the web manager is a no-op (no localStorage).
7042
4621
  core.WebSessionManager.clearSession();
7043
4622
  try {
7044
4623
  core.ReactNativeSessionManager.clearSession();
7045
4624
  }
7046
4625
  catch ( /* not configured on web */_a) { /* not configured on web */ }
4626
+ setStoredAuthMethod(null);
7047
4627
  return true;
7048
4628
  }
7049
4629
  // Lazy loaders for web-only providers.
@@ -7062,17 +4642,99 @@ async function loadSolanaMobileWalletProvider() {
7062
4642
  const mod = await Promise.resolve().then(function () { return solanaMobileWalletProvider; });
7063
4643
  return mod.SolanaMobileWalletProvider;
7064
4644
  }
4645
+ function requireWebPrivyConfig(config) {
4646
+ if (!config.privyConfig || typeof config.privyConfig.appId !== 'string' || config.privyConfig.appId.trim() === '') {
4647
+ throw new Error('Privy auth requires config.privyConfig.appId; no default Privy app is used.');
4648
+ }
4649
+ if (!config.privyConfig.config || typeof config.privyConfig.config !== 'object') {
4650
+ throw new Error('Privy auth requires config.privyConfig.config for the app-scoped Privy provider.');
4651
+ }
4652
+ return config.privyConfig;
4653
+ }
4654
+ function getConfiguredSolanaNetwork(config) {
4655
+ if (typeof config.chain !== 'string')
4656
+ return null;
4657
+ const chain = config.chain.trim();
4658
+ if (chain === '' || chain === 'offchain')
4659
+ return null;
4660
+ return chain;
4661
+ }
4662
+ function mobileWalletClusterFromNetwork(network) {
4663
+ switch (network) {
4664
+ case "solana_devnet":
4665
+ return "devnet";
4666
+ case "solana_mainnet":
4667
+ return "mainnet-beta";
4668
+ case "surfnet":
4669
+ return "localnet";
4670
+ case null:
4671
+ return null;
4672
+ default:
4673
+ resolveSolanaWalletStandardChain(network, "Mobile wallet auth");
4674
+ return null;
4675
+ }
4676
+ }
4677
+ function requireMobileWalletConfig(config) {
4678
+ var _a, _b, _c;
4679
+ const configuredNetwork = getConfiguredSolanaNetwork(config);
4680
+ const cluster = (_b = (_a = config.mobileWalletConfig) === null || _a === void 0 ? void 0 : _a.cluster) !== null && _b !== void 0 ? _b : mobileWalletClusterFromNetwork(configuredNetwork);
4681
+ if (!cluster) {
4682
+ throw new Error("Mobile wallet auth requires an explicit Solana network. " +
4683
+ "Pass config.chain as solana_devnet, solana_mainnet, or surfnet, " +
4684
+ "or pass mobileWalletConfig.cluster.");
4685
+ }
4686
+ return Object.assign(Object.assign({}, ((_c = config.mobileWalletConfig) !== null && _c !== void 0 ? _c : {})), { cluster });
4687
+ }
4688
+ function isLocalOrTestUrl(value) {
4689
+ if (!value)
4690
+ return false;
4691
+ try {
4692
+ const hostname = new URL(value).hostname.toLowerCase();
4693
+ return hostname === 'localhost' ||
4694
+ hostname === '127.0.0.1' ||
4695
+ hostname === '::1' ||
4696
+ hostname.endsWith('.localhost') ||
4697
+ hostname.endsWith('.test');
4698
+ }
4699
+ catch (_a) {
4700
+ return false;
4701
+ }
4702
+ }
4703
+ function assertMockAuthLocalOnly(config) {
4704
+ const requiredEndpoints = [
4705
+ config.apiUrl,
4706
+ config.wsApiUrl,
4707
+ config.authApiUrl,
4708
+ ];
4709
+ const optionalEndpoints = [
4710
+ config.rpcUrl,
4711
+ config.humanAuthApiUrl,
4712
+ config.functionsUrl,
4713
+ ].filter((value) => typeof value === 'string' && value.trim() !== '');
4714
+ if (requiredEndpoints.every(isLocalOrTestUrl) && optionalEndpoints.every(isLocalOrTestUrl)) {
4715
+ return;
4716
+ }
4717
+ throw new Error("mockAuth is local/test-only. Pass explicit localhost/.test apiUrl, wsApiUrl, and authApiUrl values; " +
4718
+ "mockAuth cannot be used with Bounded production or staging endpoints.");
4719
+ }
7065
4720
  async function hotSwapToMWAProvider(config) {
7066
- var _a, _b;
7067
- const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null;
4721
+ var _a;
4722
+ const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
4723
+ const configuredNetwork = getConfiguredSolanaNetwork(config);
7068
4724
  const SolanaMobileWalletProvider = await loadSolanaMobileWalletProvider();
7069
- const mwaConfig = (_b = config.mobileWalletConfig) !== null && _b !== void 0 ? _b : {
7070
- appIdentity: {
7071
- name: config.name || undefined,
7072
- uri: getPlatform().getLocationOrigin(),
7073
- },
7074
- };
7075
- const mwaProvider = new SolanaMobileWalletProvider(rpcUrl, mwaConfig);
4725
+ const mwaConfig = config.mobileWalletConfig
4726
+ ? requireMobileWalletConfig(config)
4727
+ : {
4728
+ appIdentity: {
4729
+ name: config.name || undefined,
4730
+ uri: getPlatform().getLocationOrigin(),
4731
+ },
4732
+ cluster: (_a = mobileWalletClusterFromNetwork(configuredNetwork)) !== null && _a !== void 0 ? _a : undefined,
4733
+ };
4734
+ if (!mwaConfig.cluster) {
4735
+ throw new Error("Mobile wallet auth requires config.chain or mobileWalletConfig.cluster before switching providers.");
4736
+ }
4737
+ const mwaProvider = new SolanaMobileWalletProvider(rpcUrl, mwaConfig, configuredNetwork);
7076
4738
  let provider = mwaProvider;
7077
4739
  if (config.chain === "offchain") {
7078
4740
  provider = new OffchainAuthProvider(mwaProvider);
@@ -7087,11 +4749,8 @@ async function hotSwapToMWAProvider(config) {
7087
4749
  setAuthProviderInstance(provider);
7088
4750
  return provider;
7089
4751
  }
7090
- const SOLANA_DEVNET_RPC_URL = "https://idelle-8nxsep-fast-devnet.helius-rpc.com";
7091
- const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
7092
- const SURFNET_RPC_URL$2 = "https://surfpool.fly.dev";
7093
4752
  async function getAuthProvider(config) {
7094
- var _a, _b, _c;
4753
+ var _a, _b;
7095
4754
  if (currentAuthProvider) {
7096
4755
  return currentAuthProvider;
7097
4756
  }
@@ -7101,21 +4760,17 @@ async function getAuthProvider(config) {
7101
4760
  initConfig = config;
7102
4761
  // If mockAuth is enabled, use MockAuthProvider regardless of authMethod
7103
4762
  if (config.mockAuth) {
4763
+ assertMockAuthLocalOnly(config);
7104
4764
  console.log("[MockAuth] Mock authentication enabled");
7105
4765
  currentAuthProvider = new MockAuthProvider();
7106
4766
  return currentAuthProvider;
7107
4767
  }
7108
- // If the user previously logged in with a specific method, use that instead
7109
- const validAuthMethods = ['email', 'phantom', 'wallet', 'rainbowkit', 'coinbase-smart-wallet', 'onboard', 'mobile-wallet-adapter', 'guest', 'privy', 'privy-expo', 'none'];
7110
- const storedMethod = getStoredAuthMethod();
7111
- const authMethod = (storedMethod && validAuthMethods.includes(storedMethod))
7112
- ? storedMethod
7113
- : (config.authMethod || "email");
7114
- if (storedMethod && !validAuthMethods.includes(storedMethod)) {
7115
- // Invalid stored value — clear it
7116
- setStoredAuthMethod(null);
7117
- }
7118
- const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null;
4768
+ const authMethod = config.authMethod;
4769
+ if (!authMethod) {
4770
+ throw new Error("authMethod is required to initialize auth provider; configure the single intended auth method explicitly.");
4771
+ }
4772
+ const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
4773
+ const configuredNetwork = getConfiguredSolanaNetwork(config);
7119
4774
  currentAuthMethod = authMethod;
7120
4775
  // Clear, actionable error when the BROWSER build (`bounded-sh`) is loaded in a
7121
4776
  // non-browser (Node) runtime. The wallet providers below need `window`; without
@@ -7127,8 +4782,8 @@ async function getAuthProvider(config) {
7127
4782
  if (typeof window === 'undefined' && browserWalletMethods.includes(authMethod)) {
7128
4783
  throw new Error(`bounded-sh: '${authMethod}' auth requires a browser, but no \`window\` was found ` +
7129
4784
  `(you're likely running in Node). In server/Node code, import from 'bounded-sh/server' ` +
7130
- `instead of 'bounded-sh' — it signs with a keypair (pass it via createWalletClient({ keypair }), ` +
7131
- `or set BOUNDED_PRIVATE_KEY) and needs no browser.`);
4785
+ `instead of 'bounded-sh' — it signs with an explicit keypair passed to createWalletClient({ keypair }) ` +
4786
+ `and needs no browser.`);
7132
4787
  }
7133
4788
  switch (authMethod) {
7134
4789
  case "email":
@@ -7145,7 +4800,7 @@ async function getAuthProvider(config) {
7145
4800
  break;
7146
4801
  case "phantom": {
7147
4802
  const { PhantomWalletProvider } = await loadPhantomWalletProvider();
7148
- currentAuthProvider = new PhantomWalletProvider(rpcUrl, config.phantomConfig);
4803
+ currentAuthProvider = new PhantomWalletProvider(rpcUrl, config.phantomConfig, configuredNetwork);
7149
4804
  // MWA hot-swap is always available (custom modal shows MWA button on Android)
7150
4805
  currentAuthProvider.onSwitchToMWA =
7151
4806
  () => hotSwapToMWAProvider(config);
@@ -7155,8 +4810,9 @@ async function getAuthProvider(config) {
7155
4810
  // Web Privy: a co-equal login route alongside email/phantom/guest. The
7156
4811
  // Privy embedded/external Solana wallet signs the SIWS challenge, so the
7157
4812
  // session is minted through the same wallet path as Phantom.
4813
+ const privyConfig = requireWebPrivyConfig(config);
7158
4814
  const PrivyWalletProvider = await loadPrivyWalletProvider();
7159
- currentAuthProvider = new PrivyWalletProvider((_b = config.name) !== null && _b !== void 0 ? _b : null, (_c = config.logoUrl) !== null && _c !== void 0 ? _c : null, config.privyConfig, rpcUrl);
4815
+ currentAuthProvider = new PrivyWalletProvider((_a = config.name) !== null && _a !== void 0 ? _a : null, (_b = config.logoUrl) !== null && _b !== void 0 ? _b : null, privyConfig, rpcUrl, configuredNetwork);
7160
4816
  break;
7161
4817
  }
7162
4818
  case "privy-expo":
@@ -7171,7 +4827,7 @@ async function getAuthProvider(config) {
7171
4827
  break;
7172
4828
  case "mobile-wallet-adapter": {
7173
4829
  const SolanaMobileWalletProvider = await loadSolanaMobileWalletProvider();
7174
- currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, config.mobileWalletConfig);
4830
+ currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, requireMobileWalletConfig(config), configuredNetwork);
7175
4831
  break;
7176
4832
  }
7177
4833
  case "onboard":
@@ -7204,7 +4860,7 @@ function assertBrowserAuthEnv(method) {
7204
4860
  throw new Error(`bounded-sh: '${method}' is a browser/React-Native auth flow — it needs \`window\`/\`localStorage\` ` +
7205
4861
  `to persist the session, which Node doesn't have (the session would be silently dropped, then every ` +
7206
4862
  `request 403s). In Node/server code import from 'bounded-sh/server' and sign with a keypair ` +
7207
- `(createWalletClient({ keypair }) or BOUNDED_PRIVATE_KEY).`);
4863
+ `by using createWalletClient({ keypair }).`);
7208
4864
  }
7209
4865
  }
7210
4866
  /**
@@ -7241,13 +4897,14 @@ async function signInAnonymously() {
7241
4897
  * (web localStorage / RN storage) and identity model. `init()` must have run first.
7242
4898
  */
7243
4899
  async function loginWithPrivy(options) {
7244
- var _a, _b, _c;
4900
+ var _a, _b;
7245
4901
  assertBrowserAuthEnv('loginWithPrivy');
7246
4902
  const coreConfig = await core.getConfig();
7247
4903
  let provider;
7248
4904
  if (getPlatform().hasDOM) {
4905
+ const privyConfig = requireWebPrivyConfig(coreConfig);
7249
4906
  const PrivyWalletProvider = await loadPrivyWalletProvider();
7250
- provider = new PrivyWalletProvider((_a = coreConfig.name) !== null && _a !== void 0 ? _a : null, (_b = coreConfig.logoUrl) !== null && _b !== void 0 ? _b : null, coreConfig.privyConfig, (_c = coreConfig.rpcUrl) !== null && _c !== void 0 ? _c : null);
4907
+ provider = new PrivyWalletProvider((_a = coreConfig.name) !== null && _a !== void 0 ? _a : null, (_b = coreConfig.logoUrl) !== null && _b !== void 0 ? _b : null, privyConfig, normalizeSolanaRpcUrl(coreConfig.rpcUrl), getConfiguredSolanaNetwork(coreConfig));
7251
4908
  currentAuthMethod = 'privy';
7252
4909
  }
7253
4910
  else {
@@ -7393,15 +5050,13 @@ async function logout$1() {
7393
5050
  throw new Error("Auth provider not initialized. Please call init() first.");
7394
5051
  }
7395
5052
  // Revoke the refresh-token family server-side BEFORE the provider clears the
7396
- // local session (so we still have the token + issuer to revoke). Best-effort:
7397
- // revokeSession swallows errors so logout never hangs/fails on a network blip.
7398
- try {
7399
- const sm = core.getActiveSessionManager();
7400
- const refreshToken = sm.getRefreshToken();
7401
- if (refreshToken)
7402
- await core.revokeSession(refreshToken, (_a = sm.getIssuer()) !== null && _a !== void 0 ? _a : undefined);
7403
- }
7404
- catch ( /* proceed with local logout regardless */_b) { /* proceed with local logout regardless */ }
5053
+ // local session (so we still have the token + issuer to revoke). If revoke
5054
+ // fails, surface the error and leave local state intact so callers do not
5055
+ // mistake a local-only logout for server revocation.
5056
+ const sm = core.getActiveSessionManager();
5057
+ const refreshToken = sm.getRefreshToken();
5058
+ if (refreshToken)
5059
+ await core.revokeSession(refreshToken, (_a = sm.getIssuer()) !== null && _a !== void 0 ? _a : undefined);
7405
5060
  await currentAuthProvider.logout();
7406
5061
  setStoredAuthMethod(null);
7407
5062
  currentAuthProvider = null;
@@ -7856,7 +5511,7 @@ class PhantomWalletProvider {
7856
5511
  setLoginOverrides(opts) {
7857
5512
  this.loginOverrides = opts;
7858
5513
  }
7859
- constructor(networkUrl = null, config = {}) {
5514
+ constructor(networkUrl = null, config = {}, configuredNetwork = null) {
7860
5515
  this.containerElement = null;
7861
5516
  this.root = null;
7862
5517
  this.phantomMethods = null;
@@ -7869,6 +5524,7 @@ class PhantomWalletProvider {
7869
5524
  /** Callback to swap to a Mobile Wallet Adapter provider when the user clicks "Connect Mobile Wallet" */
7870
5525
  this.onSwitchToMWA = null;
7871
5526
  this.networkUrl = networkUrl;
5527
+ this.configuredNetwork = configuredNetwork;
7872
5528
  this.config = config;
7873
5529
  if (typeof window === 'undefined') {
7874
5530
  throw new Error('PhantomWalletProvider can only be instantiated in a browser environment');
@@ -7895,9 +5551,9 @@ class PhantomWalletProvider {
7895
5551
  hasSocialProviders() {
7896
5552
  return this.resolvedProviders.some(p => p !== 'injected');
7897
5553
  }
7898
- static getInstance(networkUrl, config) {
5554
+ static getInstance(networkUrl, config, configuredNetwork = null) {
7899
5555
  if (!PhantomWalletProvider.instance) {
7900
- new PhantomWalletProvider(networkUrl, config);
5556
+ new PhantomWalletProvider(networkUrl, config, configuredNetwork);
7901
5557
  }
7902
5558
  return PhantomWalletProvider.instance;
7903
5559
  }
@@ -8799,7 +6455,7 @@ class PhantomWalletProvider {
8799
6455
  }
8800
6456
  const rpcUrl = this.getRpcUrl(solTransactionData.network);
8801
6457
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
8802
- const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
6458
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
8803
6459
  try {
8804
6460
  const remainingAccounts = core.convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
8805
6461
  const app_id = solTransactionData.appId;
@@ -9021,7 +6677,7 @@ class PhantomWalletProvider {
9021
6677
  }
9022
6678
  const rpcUrl = this.getRpcUrl();
9023
6679
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
9024
- const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
6680
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
9025
6681
  try {
9026
6682
  // Get fresh blockhash and set it on the transaction before signing
9027
6683
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
@@ -9154,19 +6810,7 @@ class PhantomWalletProvider {
9154
6810
  * Private Helpers
9155
6811
  * ----------------------------------------------------------- */
9156
6812
  getRpcUrl(network) {
9157
- if (this.networkUrl) {
9158
- return this.networkUrl;
9159
- }
9160
- if (network === 'solana_devnet') {
9161
- return SOLANA_DEVNET_RPC_URL;
9162
- }
9163
- else if (network === 'solana_mainnet') {
9164
- return SOLANA_MAINNET_RPC_URL;
9165
- }
9166
- else if (network === 'surfnet') {
9167
- return SURFNET_RPC_URL$2;
9168
- }
9169
- return SOLANA_MAINNET_RPC_URL; // default to mainnet
6813
+ return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, "Phantom wallet Solana transaction");
9170
6814
  }
9171
6815
  async signAndSendViaPhantom(transaction) {
9172
6816
  var _a, _b, _c;
@@ -9613,8 +7257,10 @@ async function signWithFreshActivation(theme, signFn, noResultError = 'MWA retur
9613
7257
  * normalized to `solana:mainnet`.
9614
7258
  */
9615
7259
  function mapChainToWalletStandard(input) {
9616
- if (!input)
9617
- return 'solana:mainnet';
7260
+ if (!input) {
7261
+ throw new Error("Solana mobile wallet auth requires an explicit cluster. " +
7262
+ "Pass mobileWalletConfig.cluster or config.chain.");
7263
+ }
9618
7264
  let s = String(input).toLowerCase();
9619
7265
  while (s.startsWith('solana:'))
9620
7266
  s = s.slice('solana:'.length);
@@ -9626,7 +7272,22 @@ function mapChainToWalletStandard(input) {
9626
7272
  return 'solana:testnet';
9627
7273
  if (s === 'localnet')
9628
7274
  return 'solana:localnet';
9629
- return 'solana:mainnet';
7275
+ throw new Error(`Solana mobile wallet auth does not support cluster "${input}". ` +
7276
+ "Expected mainnet-beta, devnet, testnet, or localnet.");
7277
+ }
7278
+ function mapClusterToRpcNetwork(input) {
7279
+ if (!input)
7280
+ return null;
7281
+ let s = String(input).toLowerCase();
7282
+ while (s.startsWith('solana:'))
7283
+ s = s.slice('solana:'.length);
7284
+ if (s === 'mainnet-beta' || s === 'mainnet')
7285
+ return 'solana_mainnet';
7286
+ if (s === 'devnet')
7287
+ return 'solana_devnet';
7288
+ if (s === 'localnet')
7289
+ return 'surfnet';
7290
+ return null;
9630
7291
  }
9631
7292
  /**
9632
7293
  * Serialize a Transaction/VersionedTransaction to a Uint8Array wire payload
@@ -9802,7 +7463,8 @@ async function registerMobileWalletAdapter(config) {
9802
7463
  * acceptable given the alternative was broken on Seeker.
9803
7464
  */
9804
7465
  class SolanaMobileWalletProvider {
9805
- constructor(networkUrl = null, config = {}) {
7466
+ constructor(networkUrl = null, config = {}, configuredNetwork = null) {
7467
+ var _a;
9806
7468
  /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
9807
7469
  this.wallet = null;
9808
7470
  /**
@@ -9816,6 +7478,7 @@ class SolanaMobileWalletProvider {
9816
7478
  /** Cached public key string for the connected MWA wallet (native). */
9817
7479
  this.nativeAddress = null;
9818
7480
  this.networkUrl = networkUrl;
7481
+ this.configuredNetwork = configuredNetwork;
9819
7482
  this.config = config;
9820
7483
  // Allow construction in true React Native environments: getPlatform().hasDOM
9821
7484
  // is false there even though `typeof window === 'object'` (RN exposes a
@@ -9844,7 +7507,7 @@ class SolanaMobileWalletProvider {
9844
7507
  name: 'Bounded App',
9845
7508
  uri: fallbackUri,
9846
7509
  };
9847
- this.cluster = config.cluster || 'mainnet-beta';
7510
+ this.cluster = (_a = config.cluster) !== null && _a !== void 0 ? _a : '';
9848
7511
  // Hydrate cached MWA auth_token from storage on native so we can
9849
7512
  // skip the wallet-pick popup after a cold-start when the underlying
9850
7513
  // wallet authorization is still valid. Sync storage call per the
@@ -9861,15 +7524,15 @@ class SolanaMobileWalletProvider {
9861
7524
  }
9862
7525
  }
9863
7526
  }
9864
- catch (_a) {
7527
+ catch (_b) {
9865
7528
  // Corrupt or unreadable cache — ignore. login() will re-auth.
9866
7529
  }
9867
7530
  }
9868
7531
  SolanaMobileWalletProvider.instance = this;
9869
7532
  }
9870
- static getInstance(networkUrl, config) {
7533
+ static getInstance(networkUrl, config, configuredNetwork = null) {
9871
7534
  if (!SolanaMobileWalletProvider.instance) {
9872
- new SolanaMobileWalletProvider(networkUrl, config);
7535
+ new SolanaMobileWalletProvider(networkUrl, config, configuredNetwork);
9873
7536
  }
9874
7537
  return SolanaMobileWalletProvider.instance;
9875
7538
  }
@@ -9924,7 +7587,13 @@ class SolanaMobileWalletProvider {
9924
7587
  return wallet.accounts[0];
9925
7588
  }
9926
7589
  /** Returns the active wallet-standard chain identifier (e.g. 'solana:mainnet'). */
9927
- getChain() {
7590
+ getChain(network) {
7591
+ if (network) {
7592
+ return resolveSolanaWalletStandardChain(network, "Solana mobile wallet transaction");
7593
+ }
7594
+ if (this.configuredNetwork) {
7595
+ return resolveSolanaWalletStandardChain(this.configuredNetwork, "Solana mobile wallet transaction");
7596
+ }
9928
7597
  return mapChainToWalletStandard(this.cluster);
9929
7598
  }
9930
7599
  /**
@@ -10386,7 +8055,7 @@ class SolanaMobileWalletProvider {
10386
8055
  const connectedPubkey = new web3_js.PublicKey(this.nativeAddress);
10387
8056
  const rpcUrl = this.getRpcUrl();
10388
8057
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
10389
- const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
8058
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
10390
8059
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
10391
8060
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
10392
8061
  if (isLegacyTransaction) {
@@ -10444,7 +8113,7 @@ class SolanaMobileWalletProvider {
10444
8113
  const chain = this.getChain();
10445
8114
  const rpcUrl = this.getRpcUrl();
10446
8115
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
10447
- const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
8116
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
10448
8117
  try {
10449
8118
  // Preserve existing prep: refresh blockhash and set fee payer.
10450
8119
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
@@ -10524,10 +8193,10 @@ class SolanaMobileWalletProvider {
10524
8193
  const account = await this.ensureAuthorized();
10525
8194
  const connectedPubkey = new web3_js.PublicKey(account.publicKey);
10526
8195
  const wallet = await this.ensureWallet();
10527
- const chain = this.getChain();
8196
+ const chain = this.getChain(solTransactionData.network);
10528
8197
  const rpcUrl = this.getRpcUrl(solTransactionData.network);
10529
8198
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
10530
- const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
8199
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
10531
8200
  try {
10532
8201
  const remainingAccounts = core.convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
10533
8202
  const app_id = solTransactionData.appId;
@@ -10703,19 +8372,8 @@ class SolanaMobileWalletProvider {
10703
8372
  * Private Helpers
10704
8373
  * ----------------------------------------------------------- */
10705
8374
  getRpcUrl(network) {
10706
- if (this.networkUrl) {
10707
- return this.networkUrl;
10708
- }
10709
- if (network === 'solana_devnet') {
10710
- return SOLANA_DEVNET_RPC_URL;
10711
- }
10712
- else if (network === 'solana_mainnet') {
10713
- return SOLANA_MAINNET_RPC_URL;
10714
- }
10715
- else if (network === 'surfnet') {
10716
- return SURFNET_RPC_URL$2;
10717
- }
10718
- return SOLANA_MAINNET_RPC_URL;
8375
+ var _a;
8376
+ return resolveSolanaRpcUrl(this.networkUrl, (_a = network !== null && network !== void 0 ? network : this.configuredNetwork) !== null && _a !== void 0 ? _a : mapClusterToRpcNetwork(this.cluster), "Solana mobile wallet transaction");
10719
8377
  }
10720
8378
  }
10721
8379
  SolanaMobileWalletProvider.instance = null;
@@ -10727,7 +8385,6 @@ var solanaMobileWalletProvider = /*#__PURE__*/Object.freeze({
10727
8385
  registerMobileWalletAdapter: registerMobileWalletAdapter
10728
8386
  });
10729
8387
 
10730
- const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
10731
8388
  // @privy-io/react-auth(/solana) are OPTIONAL peer deps. They are loaded lazily
10732
8389
  // via dynamic import() rather than a static top-level import: a static import
10733
8390
  // would (a) in the ESM bundle still be a bare `import` the consumer resolves —
@@ -10760,31 +8417,28 @@ async function loadSolanaKit() {
10760
8417
  }
10761
8418
  return solanaKit;
10762
8419
  }
10763
- const getDefaultPrivyConfig = () => ({
10764
- appId: "cm4ve714908o27dk2yurpnfhd",
10765
- config: {
10766
- embeddedWallets: {
10767
- solana: {
10768
- createOnLogin: "users-without-wallets"
10769
- }
10770
- },
10771
- appearance: {
10772
- walletChainType: 'solana-only'
10773
- },
10774
- externalWallets: { solana: { connectors: privySolana.toSolanaWalletConnectors() } }
8420
+ function requirePrivyWalletConfig(privyConfig) {
8421
+ if (!privyConfig || typeof privyConfig.appId !== 'string' || privyConfig.appId.trim() === '') {
8422
+ throw new Error('Privy auth requires config.privyConfig.appId; no default Privy app is used.');
10775
8423
  }
10776
- });
8424
+ if (!privyConfig.config || typeof privyConfig.config !== 'object') {
8425
+ throw new Error('Privy auth requires config.privyConfig.config for the app-scoped Privy provider.');
8426
+ }
8427
+ return {
8428
+ appId: privyConfig.appId,
8429
+ config: privyConfig.config,
8430
+ };
8431
+ }
10777
8432
  class PrivyWalletProvider {
10778
- constructor(appName, appLogoUrl, privyConfig, networkUrl = null) {
8433
+ constructor(appName, appLogoUrl, privyConfig, networkUrl = null, configuredNetwork = null) {
10779
8434
  this.containerElement = null;
10780
- this.chainId = 'solana:mainnet';
8435
+ this.chainId = null;
10781
8436
  this.root = null;
10782
8437
  this.privyMethods = null;
10783
8438
  this.pendingLogin = null;
10784
8439
  // Resolved Solana RPC URLs (computed in the constructor; consumed in
10785
8440
  // initialize() where @solana/kit is lazily loaded to build the transports).
10786
- this.rpcDevnetUrl = SOLANA_DEVNET_RPC_URL;
10787
- this.rpcMainnetUrl = SOLANA_MAINNET_RPC_URL;
8441
+ this.configuredRpcUrl = null;
10788
8442
  // This is used to store the pending transaction until the wallet is connected for workaround for the wallet not being connected after login completion
10789
8443
  this.pendingTransaction = null;
10790
8444
  // This is used to store pending signTransaction calls until the wallet is connected
@@ -10793,41 +8447,37 @@ class PrivyWalletProvider {
10793
8447
  this.pendingSignMessage = null;
10794
8448
  // This is used to store pending signAndSubmitTransaction calls until the wallet is connected
10795
8449
  this.pendingSignAndSubmitTransaction = null;
10796
- this.networkUrl = networkUrl;
8450
+ this.networkUrl = normalizeSolanaRpcUrl(networkUrl);
8451
+ this.configuredNetwork = configuredNetwork;
10797
8452
  if (typeof window === 'undefined') {
10798
8453
  throw new Error('PrivyWalletProvider can only be instantiated in a browser environment');
10799
8454
  }
8455
+ const requiredPrivyConfig = requirePrivyWalletConfig(privyConfig);
10800
8456
  if (PrivyWalletProvider.instance) {
10801
8457
  return PrivyWalletProvider.instance;
10802
8458
  }
10803
8459
  this.containerElement = null;
10804
8460
  this.root = null;
10805
8461
  this.privyMethods = null;
10806
- this.privyConfig = privyConfig !== null && privyConfig !== void 0 ? privyConfig : getDefaultPrivyConfig();
10807
- // Only use the appName and appLogoUrl if no privyConfig is provided
10808
- if (privyConfig == null) {
10809
- if (appName != null && appName != '') {
10810
- this.privyConfig.config.appearance.landingHeader = appName;
10811
- }
10812
- if (appLogoUrl != null && appLogoUrl != '') {
10813
- this.privyConfig.config.appearance.logo = appLogoUrl;
10814
- }
8462
+ this.privyConfig = requiredPrivyConfig;
8463
+ if (!this.privyConfig.config.appearance) {
8464
+ this.privyConfig.config.appearance = {};
8465
+ }
8466
+ if (appName != null && appName != '' && !this.privyConfig.config.appearance.landingHeader) {
8467
+ this.privyConfig.config.appearance.landingHeader = appName;
8468
+ }
8469
+ if (appLogoUrl != null && appLogoUrl != '' && !this.privyConfig.config.appearance.logo) {
8470
+ this.privyConfig.config.appearance.logo = appLogoUrl;
10815
8471
  }
10816
8472
  // (externalWallets connectors are configured in initialize() once the
10817
8473
  // Privy SDK is lazily loaded — see loadPrivyModules.)
10818
8474
  // Resolve Solana RPC URLs for v3. The @solana/kit transports are built
10819
8475
  // lazily in initialize() so a non-Privy consumer never needs @solana/kit.
10820
- this.rpcDevnetUrl = SOLANA_DEVNET_RPC_URL;
10821
- this.rpcMainnetUrl = SOLANA_MAINNET_RPC_URL;
10822
- if (networkUrl != null) {
10823
- if (networkUrl.includes('mainnet')) {
10824
- this.rpcMainnetUrl = networkUrl;
10825
- this.chainId = 'solana:mainnet';
10826
- }
10827
- else if (networkUrl.includes('devnet')) {
10828
- this.rpcDevnetUrl = networkUrl;
10829
- this.chainId = 'solana:devnet';
10830
- }
8476
+ if (this.networkUrl || configuredNetwork) {
8477
+ this.configuredRpcUrl = resolveSolanaRpcUrl(this.networkUrl, configuredNetwork, "Privy Solana RPC");
8478
+ }
8479
+ if (configuredNetwork) {
8480
+ this.chainId = resolveSolanaWalletStandardChain(configuredNetwork, "Privy Solana transaction");
10831
8481
  }
10832
8482
  const existingProviders = document.querySelectorAll('[data-privy-provider]');
10833
8483
  existingProviders.forEach(el => el.remove());
@@ -10842,9 +8492,9 @@ class PrivyWalletProvider {
10842
8492
  PrivyWalletProvider.instance = this;
10843
8493
  }
10844
8494
  // Optional: Provide a static method to get the instance
10845
- static getInstance(appName, appLogoUrl, privyConfig) {
8495
+ static getInstance(appName, appLogoUrl, privyConfig, networkUrl = null, configuredNetwork = null) {
10846
8496
  if (!PrivyWalletProvider.instance) {
10847
- new PrivyWalletProvider(appName, appLogoUrl, privyConfig);
8497
+ new PrivyWalletProvider(appName, appLogoUrl, privyConfig, networkUrl, configuredNetwork);
10848
8498
  }
10849
8499
  return PrivyWalletProvider.instance;
10850
8500
  }
@@ -10854,19 +8504,17 @@ class PrivyWalletProvider {
10854
8504
  // Build the Solana RPC transports now that we're on the async path, so
10855
8505
  // @solana/kit can be lazily imported (kept out of the entry bundle).
10856
8506
  const { createSolanaRpc, createSolanaRpcSubscriptions } = await loadSolanaKit();
10857
- if (!this.privyConfig.config.solana) {
8507
+ if (this.configuredRpcUrl && this.chainId && !this.privyConfig.config.solana) {
10858
8508
  this.privyConfig.config.solana = {};
10859
8509
  }
10860
- this.privyConfig.config.solana.rpcs = {
10861
- 'solana:devnet': {
10862
- rpc: createSolanaRpc(this.rpcDevnetUrl),
10863
- rpcSubscriptions: createSolanaRpcSubscriptions(this.rpcDevnetUrl.replace('https://', 'wss://'))
10864
- },
10865
- 'solana:mainnet': {
10866
- rpc: createSolanaRpc(this.rpcMainnetUrl),
10867
- rpcSubscriptions: createSolanaRpcSubscriptions(this.rpcMainnetUrl.replace('https://', 'wss://'))
10868
- }
10869
- };
8510
+ if (this.configuredRpcUrl && this.chainId) {
8511
+ this.privyConfig.config.solana.rpcs = {
8512
+ [this.chainId]: {
8513
+ rpc: createSolanaRpc(this.configuredRpcUrl),
8514
+ rpcSubscriptions: createSolanaRpcSubscriptions(this.configuredRpcUrl.replace('https://', 'wss://'))
8515
+ }
8516
+ };
8517
+ }
10870
8518
  // Ensure externalWallets connectors are always configured — required for
10871
8519
  // useWallets().ready to resolve even when no browser extension is present.
10872
8520
  if (!this.privyConfig.config.externalWallets && privySolana) {
@@ -11202,7 +8850,7 @@ class PrivyWalletProvider {
11202
8850
  try {
11203
8851
  if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
11204
8852
  // Just sign, don't submit - return raw signed bytes (same as original runTransaction)
11205
- const signedTx = await this.signTransactionRaw(tx, privyWallet);
8853
+ const signedTx = await this.signTransactionRaw(tx, privyWallet, solTransactionData.network);
11206
8854
  return {
11207
8855
  signedTransaction: signedTx, // Raw Uint8Array from Privy
11208
8856
  blockNumber: 0,
@@ -11211,7 +8859,7 @@ class PrivyWalletProvider {
11211
8859
  };
11212
8860
  }
11213
8861
  // Sign and submit using shared helper
11214
- const { signature, txInfo } = await this.signAndSubmitInternal(tx, privyWallet, rpcUrl, connection);
8862
+ const { signature, txInfo } = await this.signAndSubmitInternal(tx, privyWallet, rpcUrl, connection, solTransactionData.network);
11215
8863
  return {
11216
8864
  transactionSignature: signature,
11217
8865
  blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
@@ -11383,26 +9031,25 @@ class PrivyWalletProvider {
11383
9031
  }
11384
9032
  // ============ Private Helpers ============
11385
9033
  getRpcUrl(network) {
11386
- if (this.networkUrl) {
11387
- return this.networkUrl;
11388
- }
11389
- if (network === 'solana_devnet') {
11390
- return SOLANA_DEVNET_RPC_URL;
11391
- }
11392
- else if (network === 'solana_mainnet') {
11393
- return SOLANA_MAINNET_RPC_URL;
9034
+ return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, "Privy Solana transaction");
9035
+ }
9036
+ getChainId(network) {
9037
+ if (network) {
9038
+ return resolveSolanaWalletStandardChain(network, "Privy Solana transaction");
11394
9039
  }
11395
- else if (network === 'surfnet') {
11396
- return SURFNET_RPC_URL$1;
9040
+ if (this.chainId)
9041
+ return this.chainId;
9042
+ if (this.configuredNetwork) {
9043
+ return resolveSolanaWalletStandardChain(this.configuredNetwork, "Privy Solana transaction");
11397
9044
  }
11398
- return SOLANA_MAINNET_RPC_URL; // default to mainnet
9045
+ throw new Error("Privy Solana transaction requires config.chain as solana_devnet, solana_mainnet, or surfnet.");
11399
9046
  }
11400
9047
  /**
11401
9048
  * Internal sign transaction - serializes and signs via Privy
11402
9049
  * Returns the raw result from Privy (Uint8Array)
11403
9050
  * This mirrors exactly what runTransaction was doing
11404
9051
  */
11405
- async signTransactionRaw(transaction, privyWallet) {
9052
+ async signTransactionRaw(transaction, privyWallet, network) {
11406
9053
  var _a;
11407
9054
  // Serialize the transaction
11408
9055
  // Use duck typing instead of instanceof to handle multiple @solana/web3.js versions
@@ -11418,7 +9065,7 @@ class PrivyWalletProvider {
11418
9065
  const result = await ((_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.signTransaction({
11419
9066
  transaction: serializedForSign,
11420
9067
  wallet: privyWallet,
11421
- chain: this.chainId
9068
+ chain: this.getChainId(network)
11422
9069
  }));
11423
9070
  // Privy returns { signedTransaction: Uint8Array }, unwrap it
11424
9071
  const signedTx = (result === null || result === void 0 ? void 0 : result.signedTransaction) || result;
@@ -11463,13 +9110,13 @@ class PrivyWalletProvider {
11463
9110
  * For Surfnet: sign with signTransactionRaw, then sendRawTransaction
11464
9111
  * For non-Surfnet: use Privy's signAndSendTransaction (combined operation)
11465
9112
  */
11466
- async signAndSubmitInternal(transaction, privyWallet, rpcUrl, connection) {
9113
+ async signAndSubmitInternal(transaction, privyWallet, rpcUrl, connection, network) {
11467
9114
  var _a;
11468
- const isSurfnet = rpcUrl === SURFNET_RPC_URL$1;
9115
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
11469
9116
  let signature;
11470
9117
  if (isSurfnet) {
11471
9118
  // For Surfnet: sign with signTransactionRaw, then sendRawTransaction
11472
- const signedTx = await this.signTransactionRaw(transaction, privyWallet);
9119
+ const signedTx = await this.signTransactionRaw(transaction, privyWallet, network);
11473
9120
  signature = await connection.sendRawTransaction(signedTx);
11474
9121
  }
11475
9122
  else {
@@ -11487,7 +9134,7 @@ class PrivyWalletProvider {
11487
9134
  const result = await ((_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.useSendTransactionSolana.signAndSendTransaction({
11488
9135
  transaction: serializedTx,
11489
9136
  wallet: privyWallet,
11490
- chain: this.chainId
9137
+ chain: this.getChainId(network)
11491
9138
  }));
11492
9139
  // Handle case where signature might be bytes instead of string
11493
9140
  const rawSig = result.signature;
@@ -11554,16 +9201,7 @@ class PrivyWalletProvider {
11554
9201
  }
11555
9202
  let privyWallet = this.privyMethods.wallets.find((wallet) => wallet.address === sessionAddress);
11556
9203
  if (!privyWallet) {
11557
- // Session address is not a privy wallet, just default to the first wallet
11558
- const accessToken = await this.privyMethods.getAccessToken();
11559
- await this.createSession(this.privyMethods.wallets[0].address, accessToken, this.privyMethods.identityToken);
11560
- setCurrentUser({ address: this.privyMethods.wallets[0].address, provider: this });
11561
- const session = await core.getActiveSessionManager().getSession();
11562
- sessionAddress = session === null || session === void 0 ? void 0 : session.address;
11563
- if (!sessionAddress) {
11564
- throw new Error('No wallet connected or logged in to sign message');
11565
- }
11566
- privyWallet = this.privyMethods.wallets[0];
9204
+ throw new Error('Active Privy wallets do not include the authenticated session wallet; please log in again.');
11567
9205
  }
11568
9206
  // Use the Privy signMessage hook for Solana wallets
11569
9207
  // The message needs to be passed as a Uint8Array
@@ -11593,22 +9231,21 @@ class PrivyWalletProvider {
11593
9231
  // Privy-specific token verification — it arrives as a Solana signature and is
11594
9232
  // recorded server-side as authMethod 'phantom'.
11595
9233
  async createSession(address, _accessToken, _idToken) {
11596
- var _a, _b, _c, _d, _e, _f, _g;
11597
- // Resolve the Privy wallet for this address (fall back to the first wallet).
11598
- const privyWallet = (_c = (_b = (_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.wallets) === null || _b === void 0 ? void 0 : _b.find((w) => w.address === address)) !== null && _c !== void 0 ? _c : (_e = (_d = this.privyMethods) === null || _d === void 0 ? void 0 : _d.wallets) === null || _e === void 0 ? void 0 : _e[0];
9234
+ var _a, _b, _c, _d;
9235
+ const privyWallet = (_b = (_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.wallets) === null || _b === void 0 ? void 0 : _b.find((w) => w.address === address);
11599
9236
  if (!privyWallet) {
11600
- throw new Error('No Privy Solana wallet available to mint a session.');
9237
+ throw new Error('No Privy Solana wallet matching the requested session address is available.');
11601
9238
  }
11602
9239
  const nonce = await core.genAuthNonce();
11603
9240
  const message = await core.genSolanaMessage(address, nonce);
11604
9241
  const messageBytes = getPlatform().textEncode(message);
11605
9242
  // Low-level Privy sign hook — signs WITHOUT touching the session (the public
11606
9243
  // signMessage() bootstraps sessions, which would recurse here).
11607
- const signResult = await ((_f = this.privyMethods) === null || _f === void 0 ? void 0 : _f.signMessage({
9244
+ const signResult = await ((_c = this.privyMethods) === null || _c === void 0 ? void 0 : _c.signMessage({
11608
9245
  message: messageBytes,
11609
9246
  wallet: privyWallet,
11610
9247
  }));
11611
- const signatureBytes = (_g = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _g !== void 0 ? _g : signResult;
9248
+ const signatureBytes = (_d = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _d !== void 0 ? _d : signResult;
11612
9249
  // base64-encoded detached signature (matches Phantom + guest providers).
11613
9250
  const signature = bufferExports.Buffer.from(signatureBytes).toString('base64');
11614
9251
  const createSessionResult = await core.createSessionWithSignature(address, message, signature);
@@ -11690,7 +9327,6 @@ var privyWalletProvider = /*#__PURE__*/Object.freeze({
11690
9327
  * to host Privy's React context, this provider expects the RN app itself
11691
9328
  * to render <PrivyProvider> and then bridge the hooks via setPrivyMethods().
11692
9329
  */
11693
- const SURFNET_RPC_URL = 'https://surfpool.fly.dev';
11694
9330
  // -----------------------------------------------------------------------
11695
9331
  // Provider implementation
11696
9332
  // -----------------------------------------------------------------------
@@ -11698,7 +9334,7 @@ class PrivyExpoProvider {
11698
9334
  constructor(appId, networkUrl = null) {
11699
9335
  this.privyMethods = null;
11700
9336
  this.appId = appId;
11701
- this.networkUrl = networkUrl;
9337
+ this.networkUrl = normalizeSolanaRpcUrl(networkUrl);
11702
9338
  }
11703
9339
  /**
11704
9340
  * Bridge Privy hooks from the app's React tree into this provider.
@@ -11983,15 +9619,7 @@ class PrivyExpoProvider {
11983
9619
  return { signature, txInfo };
11984
9620
  }
11985
9621
  getRpcUrl(network) {
11986
- if (this.networkUrl)
11987
- return this.networkUrl;
11988
- if (network === 'solana_devnet')
11989
- return SOLANA_DEVNET_RPC_URL;
11990
- if (network === 'solana_mainnet')
11991
- return SOLANA_MAINNET_RPC_URL;
11992
- if (network === 'surfnet')
11993
- return SURFNET_RPC_URL;
11994
- return SOLANA_MAINNET_RPC_URL;
9622
+ return resolveSolanaRpcUrl(this.networkUrl, network, "Privy Expo Solana transaction");
11995
9623
  }
11996
9624
  async ensureReady(timeoutMs = 15000) {
11997
9625
  if (!this.privyMethods) {