@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.
- package/README.md +2 -1
- package/dist/auth/index.d.ts +2 -4
- package/dist/auth/providers/mock-auth-provider.d.ts +0 -1
- package/dist/auth/providers/offchain-auth-provider.d.ts +3 -4
- package/dist/auth/providers/phantom-wallet-provider.d.ts +3 -2
- package/dist/auth/providers/privy-wallet-provider.d.ts +10 -7
- package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +3 -2
- package/dist/auth/solana-rpc.d.ts +8 -0
- package/dist/index.js +310 -2682
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +310 -2682
- package/dist/index.mjs.map +1 -1
- package/dist/{index.native-DoiNBZlU.js → index.native-DI_Xgv-n.js} +205 -2558
- package/dist/index.native-DI_Xgv-n.js.map +1 -0
- package/dist/{index.native-DlMO7aHv.mjs → index.native-DWI_i6-6.mjs} +202 -2556
- package/dist/index.native-DWI_i6-6.mjs.map +1 -0
- package/dist/index.native.js +2 -2
- package/dist/index.native.mjs +2 -2
- package/dist/{phantom-wallet-provider-DWG1LVJf.mjs → phantom-wallet-provider-DDwgNMg_.mjs} +7 -18
- package/dist/phantom-wallet-provider-DDwgNMg_.mjs.map +1 -0
- package/dist/{phantom-wallet-provider-DUdnFoyb.js → phantom-wallet-provider-fyOrJZP6.js} +7 -18
- package/dist/phantom-wallet-provider-fyOrJZP6.js.map +1 -0
- package/dist/{privy-wallet-provider-Kv6H3xcS.js → privy-wallet-provider-BIr9lDS7.js} +69 -90
- package/dist/privy-wallet-provider-BIr9lDS7.js.map +1 -0
- package/dist/{privy-wallet-provider-CyNLekvY.mjs → privy-wallet-provider-D7VoQCYf.mjs} +68 -89
- package/dist/privy-wallet-provider-D7VoQCYf.mjs.map +1 -0
- package/dist/{solana-mobile-wallet-provider-BfHBucO0.js → solana-mobile-wallet-provider-Cush-URL.js} +39 -25
- package/dist/solana-mobile-wallet-provider-Cush-URL.js.map +1 -0
- package/dist/{solana-mobile-wallet-provider-CKOSbLRd.mjs → solana-mobile-wallet-provider-DgcGxDoL.mjs} +39 -25
- package/dist/solana-mobile-wallet-provider-DgcGxDoL.mjs.map +1 -0
- package/package.json +2 -2
- package/dist/index.native-DlMO7aHv.mjs.map +0 -1
- package/dist/index.native-DoiNBZlU.js.map +0 -1
- package/dist/phantom-wallet-provider-DUdnFoyb.js.map +0 -1
- package/dist/phantom-wallet-provider-DWG1LVJf.mjs.map +0 -1
- package/dist/privy-wallet-provider-CyNLekvY.mjs.map +0 -1
- package/dist/privy-wallet-provider-Kv6H3xcS.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-BfHBucO0.js.map +0 -1
- package/dist/solana-mobile-wallet-provider-CKOSbLRd.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { getActiveSessionManager, genAuthNonce, genSolanaMessage, createSessionWithSignature, getConfig, revokeSession, WebSessionManager, ReactNativeSessionManager, init as init$1, reconnectWithNewAuth, deriveUserIdentityFromIdToken, subscribe, getIdToken as getIdToken$1, convertRemainingAccounts, buildSetDocumentsTransaction } from '@bounded-sh/core';
|
|
2
2
|
export * from '@bounded-sh/core';
|
|
3
3
|
export { aggregate, count, docId, get, getConfig, getFiles, getMany, queryAggregate, runExpression, runExpressionMany, runQuery, runQueryMany, search, set, setFile, setMany, signAndSubmitTransaction, signMessage, signTransaction, subscribe } from '@bounded-sh/core';
|
|
4
|
-
import { Keypair, VersionedTransaction, Transaction, Connection, PublicKey, VersionedMessage } from '@solana/web3.js';
|
|
5
4
|
import * as React$1 from 'react';
|
|
5
|
+
import { VersionedTransaction, Transaction, Connection, PublicKey, VersionedMessage } from '@solana/web3.js';
|
|
6
6
|
import * as anchor from '@coral-xyz/anchor';
|
|
7
7
|
import * as ReactDOM$1 from 'react-dom/client';
|
|
8
8
|
|
|
@@ -226,9 +226,7 @@ class MockAuthProvider {
|
|
|
226
226
|
}
|
|
227
227
|
async signMessageMock(message) {
|
|
228
228
|
const address = getPlatform().sessionStorage.getItem('test-user-address') || DEFAULT_TEST_ADDRESS;
|
|
229
|
-
|
|
230
|
-
// mock provider deterministic so mockAuth exercises the same integrity check.
|
|
231
|
-
const signature = await this.generateOffchainSignature(message);
|
|
229
|
+
const signature = `mock_sig_${Math.random().toString(36).substring(2, 15)}`;
|
|
232
230
|
console.log('[MockAuth] Mock message signed:', {
|
|
233
231
|
address,
|
|
234
232
|
message,
|
|
@@ -236,13 +234,6 @@ class MockAuthProvider {
|
|
|
236
234
|
});
|
|
237
235
|
return signature;
|
|
238
236
|
}
|
|
239
|
-
async generateOffchainSignature(message) {
|
|
240
|
-
const platform = getPlatform();
|
|
241
|
-
const data = platform.textEncode(message);
|
|
242
|
-
const hashBuffer = await platform.sha256(data);
|
|
243
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
244
|
-
return platform.btoa(String.fromCharCode(...hashArray));
|
|
245
|
-
}
|
|
246
237
|
/**
|
|
247
238
|
* Mock transaction signing - returns the transaction as-is (no actual signing)
|
|
248
239
|
*/
|
|
@@ -301,9 +292,9 @@ class MockAuthProvider {
|
|
|
301
292
|
/**
|
|
302
293
|
* OffchainAuthProvider wraps a real auth provider (e.g., Phantom) for the poofnet environment.
|
|
303
294
|
*
|
|
304
|
-
* For signMessageMock, this shows a custom confirmation modal and
|
|
305
|
-
*
|
|
306
|
-
*
|
|
295
|
+
* For signMessageMock, this shows a custom confirmation modal and then delegates
|
|
296
|
+
* to the wrapped provider for a real detached signature over the exact offchain
|
|
297
|
+
* transaction message.
|
|
307
298
|
*/
|
|
308
299
|
class OffchainAuthProvider {
|
|
309
300
|
constructor(wrappedProvider, config = {}) {
|
|
@@ -371,8 +362,7 @@ class OffchainAuthProvider {
|
|
|
371
362
|
throw new Error("Transaction rejected by user");
|
|
372
363
|
}
|
|
373
364
|
}
|
|
374
|
-
|
|
375
|
-
const signature = await this.generateMockSignature(message);
|
|
365
|
+
const signature = await this.wrappedProvider.signMessage(message);
|
|
376
366
|
// Callback: signing complete
|
|
377
367
|
(_d = (_c = this.config).onSigningComplete) === null || _d === void 0 ? void 0 : _d.call(_c, signature);
|
|
378
368
|
return signature;
|
|
@@ -981,26 +971,12 @@ class OffchainAuthProvider {
|
|
|
981
971
|
}
|
|
982
972
|
`;
|
|
983
973
|
}
|
|
984
|
-
async generateMockSignature(message) {
|
|
985
|
-
// Generate a deterministic signature using SHA-256 hash of message
|
|
986
|
-
// This can be verified on the backend by hashing the same message
|
|
987
|
-
const platform = getPlatform();
|
|
988
|
-
const data = platform.textEncode(message);
|
|
989
|
-
const hashBuffer = await platform.sha256(data);
|
|
990
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
991
|
-
const base64 = platform.btoa(String.fromCharCode(...hashArray));
|
|
992
|
-
return base64;
|
|
993
|
-
}
|
|
994
974
|
}
|
|
995
975
|
|
|
996
976
|
function getDefaultExportFromCjs (x) {
|
|
997
977
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
998
978
|
}
|
|
999
979
|
|
|
1000
|
-
function getDefaultExportFromNamespaceIfNotNamed (n) {
|
|
1001
|
-
return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
980
|
var safeBuffer = {exports: {}};
|
|
1005
981
|
|
|
1006
982
|
var buffer = {};
|
|
@@ -3590,2444 +3566,24 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
3590
3566
|
default: bs58
|
|
3591
3567
|
});
|
|
3592
3568
|
|
|
3593
|
-
function commonjsRequire(path) {
|
|
3594
|
-
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.');
|
|
3595
|
-
}
|
|
3596
|
-
|
|
3597
|
-
var naclFast = {exports: {}};
|
|
3598
|
-
|
|
3599
|
-
var _nodeResolve_empty = {};
|
|
3600
|
-
|
|
3601
|
-
var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
|
|
3602
|
-
__proto__: null,
|
|
3603
|
-
default: _nodeResolve_empty
|
|
3604
|
-
});
|
|
3605
|
-
|
|
3606
|
-
var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
|
|
3607
|
-
|
|
3608
|
-
var hasRequiredNaclFast;
|
|
3609
|
-
|
|
3610
|
-
function requireNaclFast () {
|
|
3611
|
-
if (hasRequiredNaclFast) return naclFast.exports;
|
|
3612
|
-
hasRequiredNaclFast = 1;
|
|
3613
|
-
(function (module) {
|
|
3614
|
-
(function(nacl) {
|
|
3615
|
-
|
|
3616
|
-
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
|
|
3617
|
-
// Public domain.
|
|
3618
|
-
//
|
|
3619
|
-
// Implementation derived from TweetNaCl version 20140427.
|
|
3620
|
-
// See for details: http://tweetnacl.cr.yp.to/
|
|
3621
|
-
|
|
3622
|
-
var gf = function(init) {
|
|
3623
|
-
var i, r = new Float64Array(16);
|
|
3624
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
3625
|
-
return r;
|
|
3626
|
-
};
|
|
3627
|
-
|
|
3628
|
-
// Pluggable, initialized in high-level API below.
|
|
3629
|
-
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
3630
|
-
|
|
3631
|
-
var _0 = new Uint8Array(16);
|
|
3632
|
-
var _9 = new Uint8Array(32); _9[0] = 9;
|
|
3633
|
-
|
|
3634
|
-
var gf0 = gf(),
|
|
3635
|
-
gf1 = gf([1]),
|
|
3636
|
-
_121665 = gf([0xdb41, 1]),
|
|
3637
|
-
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
|
|
3638
|
-
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
|
|
3639
|
-
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
|
|
3640
|
-
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
|
|
3641
|
-
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
3642
|
-
|
|
3643
|
-
function ts64(x, i, h, l) {
|
|
3644
|
-
x[i] = (h >> 24) & 0xff;
|
|
3645
|
-
x[i+1] = (h >> 16) & 0xff;
|
|
3646
|
-
x[i+2] = (h >> 8) & 0xff;
|
|
3647
|
-
x[i+3] = h & 0xff;
|
|
3648
|
-
x[i+4] = (l >> 24) & 0xff;
|
|
3649
|
-
x[i+5] = (l >> 16) & 0xff;
|
|
3650
|
-
x[i+6] = (l >> 8) & 0xff;
|
|
3651
|
-
x[i+7] = l & 0xff;
|
|
3652
|
-
}
|
|
3653
|
-
|
|
3654
|
-
function vn(x, xi, y, yi, n) {
|
|
3655
|
-
var i,d = 0;
|
|
3656
|
-
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
|
|
3657
|
-
return (1 & ((d - 1) >>> 8)) - 1;
|
|
3658
|
-
}
|
|
3659
|
-
|
|
3660
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
3661
|
-
return vn(x,xi,y,yi,16);
|
|
3662
|
-
}
|
|
3663
|
-
|
|
3664
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
3665
|
-
return vn(x,xi,y,yi,32);
|
|
3666
|
-
}
|
|
3667
|
-
|
|
3668
|
-
function core_salsa20(o, p, k, c) {
|
|
3669
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
3670
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
3671
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
3672
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
3673
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
3674
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
3675
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
3676
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
3677
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
3678
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
3679
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
3680
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
3681
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
3682
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
3683
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
3684
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
3685
|
-
|
|
3686
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
3687
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
3688
|
-
x15 = j15, u;
|
|
3689
|
-
|
|
3690
|
-
for (var i = 0; i < 20; i += 2) {
|
|
3691
|
-
u = x0 + x12 | 0;
|
|
3692
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
3693
|
-
u = x4 + x0 | 0;
|
|
3694
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3695
|
-
u = x8 + x4 | 0;
|
|
3696
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
3697
|
-
u = x12 + x8 | 0;
|
|
3698
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3699
|
-
|
|
3700
|
-
u = x5 + x1 | 0;
|
|
3701
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
3702
|
-
u = x9 + x5 | 0;
|
|
3703
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3704
|
-
u = x13 + x9 | 0;
|
|
3705
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
3706
|
-
u = x1 + x13 | 0;
|
|
3707
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3708
|
-
|
|
3709
|
-
u = x10 + x6 | 0;
|
|
3710
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
3711
|
-
u = x14 + x10 | 0;
|
|
3712
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3713
|
-
u = x2 + x14 | 0;
|
|
3714
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
3715
|
-
u = x6 + x2 | 0;
|
|
3716
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3717
|
-
|
|
3718
|
-
u = x15 + x11 | 0;
|
|
3719
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
3720
|
-
u = x3 + x15 | 0;
|
|
3721
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3722
|
-
u = x7 + x3 | 0;
|
|
3723
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
3724
|
-
u = x11 + x7 | 0;
|
|
3725
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3726
|
-
|
|
3727
|
-
u = x0 + x3 | 0;
|
|
3728
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
3729
|
-
u = x1 + x0 | 0;
|
|
3730
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3731
|
-
u = x2 + x1 | 0;
|
|
3732
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
3733
|
-
u = x3 + x2 | 0;
|
|
3734
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3735
|
-
|
|
3736
|
-
u = x5 + x4 | 0;
|
|
3737
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
3738
|
-
u = x6 + x5 | 0;
|
|
3739
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3740
|
-
u = x7 + x6 | 0;
|
|
3741
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
3742
|
-
u = x4 + x7 | 0;
|
|
3743
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3744
|
-
|
|
3745
|
-
u = x10 + x9 | 0;
|
|
3746
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
3747
|
-
u = x11 + x10 | 0;
|
|
3748
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3749
|
-
u = x8 + x11 | 0;
|
|
3750
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
3751
|
-
u = x9 + x8 | 0;
|
|
3752
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3753
|
-
|
|
3754
|
-
u = x15 + x14 | 0;
|
|
3755
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
3756
|
-
u = x12 + x15 | 0;
|
|
3757
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3758
|
-
u = x13 + x12 | 0;
|
|
3759
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
3760
|
-
u = x14 + x13 | 0;
|
|
3761
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3762
|
-
}
|
|
3763
|
-
x0 = x0 + j0 | 0;
|
|
3764
|
-
x1 = x1 + j1 | 0;
|
|
3765
|
-
x2 = x2 + j2 | 0;
|
|
3766
|
-
x3 = x3 + j3 | 0;
|
|
3767
|
-
x4 = x4 + j4 | 0;
|
|
3768
|
-
x5 = x5 + j5 | 0;
|
|
3769
|
-
x6 = x6 + j6 | 0;
|
|
3770
|
-
x7 = x7 + j7 | 0;
|
|
3771
|
-
x8 = x8 + j8 | 0;
|
|
3772
|
-
x9 = x9 + j9 | 0;
|
|
3773
|
-
x10 = x10 + j10 | 0;
|
|
3774
|
-
x11 = x11 + j11 | 0;
|
|
3775
|
-
x12 = x12 + j12 | 0;
|
|
3776
|
-
x13 = x13 + j13 | 0;
|
|
3777
|
-
x14 = x14 + j14 | 0;
|
|
3778
|
-
x15 = x15 + j15 | 0;
|
|
3779
|
-
|
|
3780
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
3781
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
3782
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
3783
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
3784
|
-
|
|
3785
|
-
o[ 4] = x1 >>> 0 & 0xff;
|
|
3786
|
-
o[ 5] = x1 >>> 8 & 0xff;
|
|
3787
|
-
o[ 6] = x1 >>> 16 & 0xff;
|
|
3788
|
-
o[ 7] = x1 >>> 24 & 0xff;
|
|
3789
|
-
|
|
3790
|
-
o[ 8] = x2 >>> 0 & 0xff;
|
|
3791
|
-
o[ 9] = x2 >>> 8 & 0xff;
|
|
3792
|
-
o[10] = x2 >>> 16 & 0xff;
|
|
3793
|
-
o[11] = x2 >>> 24 & 0xff;
|
|
3794
|
-
|
|
3795
|
-
o[12] = x3 >>> 0 & 0xff;
|
|
3796
|
-
o[13] = x3 >>> 8 & 0xff;
|
|
3797
|
-
o[14] = x3 >>> 16 & 0xff;
|
|
3798
|
-
o[15] = x3 >>> 24 & 0xff;
|
|
3799
|
-
|
|
3800
|
-
o[16] = x4 >>> 0 & 0xff;
|
|
3801
|
-
o[17] = x4 >>> 8 & 0xff;
|
|
3802
|
-
o[18] = x4 >>> 16 & 0xff;
|
|
3803
|
-
o[19] = x4 >>> 24 & 0xff;
|
|
3804
|
-
|
|
3805
|
-
o[20] = x5 >>> 0 & 0xff;
|
|
3806
|
-
o[21] = x5 >>> 8 & 0xff;
|
|
3807
|
-
o[22] = x5 >>> 16 & 0xff;
|
|
3808
|
-
o[23] = x5 >>> 24 & 0xff;
|
|
3809
|
-
|
|
3810
|
-
o[24] = x6 >>> 0 & 0xff;
|
|
3811
|
-
o[25] = x6 >>> 8 & 0xff;
|
|
3812
|
-
o[26] = x6 >>> 16 & 0xff;
|
|
3813
|
-
o[27] = x6 >>> 24 & 0xff;
|
|
3814
|
-
|
|
3815
|
-
o[28] = x7 >>> 0 & 0xff;
|
|
3816
|
-
o[29] = x7 >>> 8 & 0xff;
|
|
3817
|
-
o[30] = x7 >>> 16 & 0xff;
|
|
3818
|
-
o[31] = x7 >>> 24 & 0xff;
|
|
3819
|
-
|
|
3820
|
-
o[32] = x8 >>> 0 & 0xff;
|
|
3821
|
-
o[33] = x8 >>> 8 & 0xff;
|
|
3822
|
-
o[34] = x8 >>> 16 & 0xff;
|
|
3823
|
-
o[35] = x8 >>> 24 & 0xff;
|
|
3824
|
-
|
|
3825
|
-
o[36] = x9 >>> 0 & 0xff;
|
|
3826
|
-
o[37] = x9 >>> 8 & 0xff;
|
|
3827
|
-
o[38] = x9 >>> 16 & 0xff;
|
|
3828
|
-
o[39] = x9 >>> 24 & 0xff;
|
|
3829
|
-
|
|
3830
|
-
o[40] = x10 >>> 0 & 0xff;
|
|
3831
|
-
o[41] = x10 >>> 8 & 0xff;
|
|
3832
|
-
o[42] = x10 >>> 16 & 0xff;
|
|
3833
|
-
o[43] = x10 >>> 24 & 0xff;
|
|
3834
|
-
|
|
3835
|
-
o[44] = x11 >>> 0 & 0xff;
|
|
3836
|
-
o[45] = x11 >>> 8 & 0xff;
|
|
3837
|
-
o[46] = x11 >>> 16 & 0xff;
|
|
3838
|
-
o[47] = x11 >>> 24 & 0xff;
|
|
3839
|
-
|
|
3840
|
-
o[48] = x12 >>> 0 & 0xff;
|
|
3841
|
-
o[49] = x12 >>> 8 & 0xff;
|
|
3842
|
-
o[50] = x12 >>> 16 & 0xff;
|
|
3843
|
-
o[51] = x12 >>> 24 & 0xff;
|
|
3844
|
-
|
|
3845
|
-
o[52] = x13 >>> 0 & 0xff;
|
|
3846
|
-
o[53] = x13 >>> 8 & 0xff;
|
|
3847
|
-
o[54] = x13 >>> 16 & 0xff;
|
|
3848
|
-
o[55] = x13 >>> 24 & 0xff;
|
|
3849
|
-
|
|
3850
|
-
o[56] = x14 >>> 0 & 0xff;
|
|
3851
|
-
o[57] = x14 >>> 8 & 0xff;
|
|
3852
|
-
o[58] = x14 >>> 16 & 0xff;
|
|
3853
|
-
o[59] = x14 >>> 24 & 0xff;
|
|
3854
|
-
|
|
3855
|
-
o[60] = x15 >>> 0 & 0xff;
|
|
3856
|
-
o[61] = x15 >>> 8 & 0xff;
|
|
3857
|
-
o[62] = x15 >>> 16 & 0xff;
|
|
3858
|
-
o[63] = x15 >>> 24 & 0xff;
|
|
3859
|
-
}
|
|
3860
|
-
|
|
3861
|
-
function core_hsalsa20(o,p,k,c) {
|
|
3862
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
3863
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
3864
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
3865
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
3866
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
3867
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
3868
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
3869
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
3870
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
3871
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
3872
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
3873
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
3874
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
3875
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
3876
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
3877
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
3878
|
-
|
|
3879
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
3880
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
3881
|
-
x15 = j15, u;
|
|
3882
|
-
|
|
3883
|
-
for (var i = 0; i < 20; i += 2) {
|
|
3884
|
-
u = x0 + x12 | 0;
|
|
3885
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
3886
|
-
u = x4 + x0 | 0;
|
|
3887
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3888
|
-
u = x8 + x4 | 0;
|
|
3889
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
3890
|
-
u = x12 + x8 | 0;
|
|
3891
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3892
|
-
|
|
3893
|
-
u = x5 + x1 | 0;
|
|
3894
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
3895
|
-
u = x9 + x5 | 0;
|
|
3896
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3897
|
-
u = x13 + x9 | 0;
|
|
3898
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
3899
|
-
u = x1 + x13 | 0;
|
|
3900
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3901
|
-
|
|
3902
|
-
u = x10 + x6 | 0;
|
|
3903
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
3904
|
-
u = x14 + x10 | 0;
|
|
3905
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3906
|
-
u = x2 + x14 | 0;
|
|
3907
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
3908
|
-
u = x6 + x2 | 0;
|
|
3909
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3910
|
-
|
|
3911
|
-
u = x15 + x11 | 0;
|
|
3912
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
3913
|
-
u = x3 + x15 | 0;
|
|
3914
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3915
|
-
u = x7 + x3 | 0;
|
|
3916
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
3917
|
-
u = x11 + x7 | 0;
|
|
3918
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3919
|
-
|
|
3920
|
-
u = x0 + x3 | 0;
|
|
3921
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
3922
|
-
u = x1 + x0 | 0;
|
|
3923
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3924
|
-
u = x2 + x1 | 0;
|
|
3925
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
3926
|
-
u = x3 + x2 | 0;
|
|
3927
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3928
|
-
|
|
3929
|
-
u = x5 + x4 | 0;
|
|
3930
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
3931
|
-
u = x6 + x5 | 0;
|
|
3932
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3933
|
-
u = x7 + x6 | 0;
|
|
3934
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
3935
|
-
u = x4 + x7 | 0;
|
|
3936
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3937
|
-
|
|
3938
|
-
u = x10 + x9 | 0;
|
|
3939
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
3940
|
-
u = x11 + x10 | 0;
|
|
3941
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3942
|
-
u = x8 + x11 | 0;
|
|
3943
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
3944
|
-
u = x9 + x8 | 0;
|
|
3945
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3946
|
-
|
|
3947
|
-
u = x15 + x14 | 0;
|
|
3948
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
3949
|
-
u = x12 + x15 | 0;
|
|
3950
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3951
|
-
u = x13 + x12 | 0;
|
|
3952
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
3953
|
-
u = x14 + x13 | 0;
|
|
3954
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3955
|
-
}
|
|
3956
|
-
|
|
3957
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
3958
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
3959
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
3960
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
3961
|
-
|
|
3962
|
-
o[ 4] = x5 >>> 0 & 0xff;
|
|
3963
|
-
o[ 5] = x5 >>> 8 & 0xff;
|
|
3964
|
-
o[ 6] = x5 >>> 16 & 0xff;
|
|
3965
|
-
o[ 7] = x5 >>> 24 & 0xff;
|
|
3966
|
-
|
|
3967
|
-
o[ 8] = x10 >>> 0 & 0xff;
|
|
3968
|
-
o[ 9] = x10 >>> 8 & 0xff;
|
|
3969
|
-
o[10] = x10 >>> 16 & 0xff;
|
|
3970
|
-
o[11] = x10 >>> 24 & 0xff;
|
|
3971
|
-
|
|
3972
|
-
o[12] = x15 >>> 0 & 0xff;
|
|
3973
|
-
o[13] = x15 >>> 8 & 0xff;
|
|
3974
|
-
o[14] = x15 >>> 16 & 0xff;
|
|
3975
|
-
o[15] = x15 >>> 24 & 0xff;
|
|
3976
|
-
|
|
3977
|
-
o[16] = x6 >>> 0 & 0xff;
|
|
3978
|
-
o[17] = x6 >>> 8 & 0xff;
|
|
3979
|
-
o[18] = x6 >>> 16 & 0xff;
|
|
3980
|
-
o[19] = x6 >>> 24 & 0xff;
|
|
3981
|
-
|
|
3982
|
-
o[20] = x7 >>> 0 & 0xff;
|
|
3983
|
-
o[21] = x7 >>> 8 & 0xff;
|
|
3984
|
-
o[22] = x7 >>> 16 & 0xff;
|
|
3985
|
-
o[23] = x7 >>> 24 & 0xff;
|
|
3986
|
-
|
|
3987
|
-
o[24] = x8 >>> 0 & 0xff;
|
|
3988
|
-
o[25] = x8 >>> 8 & 0xff;
|
|
3989
|
-
o[26] = x8 >>> 16 & 0xff;
|
|
3990
|
-
o[27] = x8 >>> 24 & 0xff;
|
|
3991
|
-
|
|
3992
|
-
o[28] = x9 >>> 0 & 0xff;
|
|
3993
|
-
o[29] = x9 >>> 8 & 0xff;
|
|
3994
|
-
o[30] = x9 >>> 16 & 0xff;
|
|
3995
|
-
o[31] = x9 >>> 24 & 0xff;
|
|
3996
|
-
}
|
|
3997
|
-
|
|
3998
|
-
function crypto_core_salsa20(out,inp,k,c) {
|
|
3999
|
-
core_salsa20(out,inp,k,c);
|
|
4000
|
-
}
|
|
4001
|
-
|
|
4002
|
-
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
4003
|
-
core_hsalsa20(out,inp,k,c);
|
|
4004
|
-
}
|
|
4005
|
-
|
|
4006
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
4007
|
-
// "expand 32-byte k"
|
|
4008
|
-
|
|
4009
|
-
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
4010
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
4011
|
-
var u, i;
|
|
4012
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
4013
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
4014
|
-
while (b >= 64) {
|
|
4015
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4016
|
-
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
4017
|
-
u = 1;
|
|
4018
|
-
for (i = 8; i < 16; i++) {
|
|
4019
|
-
u = u + (z[i] & 0xff) | 0;
|
|
4020
|
-
z[i] = u & 0xff;
|
|
4021
|
-
u >>>= 8;
|
|
4022
|
-
}
|
|
4023
|
-
b -= 64;
|
|
4024
|
-
cpos += 64;
|
|
4025
|
-
mpos += 64;
|
|
4026
|
-
}
|
|
4027
|
-
if (b > 0) {
|
|
4028
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4029
|
-
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
4030
|
-
}
|
|
4031
|
-
return 0;
|
|
4032
|
-
}
|
|
4033
|
-
|
|
4034
|
-
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
4035
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
4036
|
-
var u, i;
|
|
4037
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
4038
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
4039
|
-
while (b >= 64) {
|
|
4040
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4041
|
-
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
4042
|
-
u = 1;
|
|
4043
|
-
for (i = 8; i < 16; i++) {
|
|
4044
|
-
u = u + (z[i] & 0xff) | 0;
|
|
4045
|
-
z[i] = u & 0xff;
|
|
4046
|
-
u >>>= 8;
|
|
4047
|
-
}
|
|
4048
|
-
b -= 64;
|
|
4049
|
-
cpos += 64;
|
|
4050
|
-
}
|
|
4051
|
-
if (b > 0) {
|
|
4052
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4053
|
-
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
4054
|
-
}
|
|
4055
|
-
return 0;
|
|
4056
|
-
}
|
|
4057
|
-
|
|
4058
|
-
function crypto_stream(c,cpos,d,n,k) {
|
|
4059
|
-
var s = new Uint8Array(32);
|
|
4060
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
4061
|
-
var sn = new Uint8Array(8);
|
|
4062
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
4063
|
-
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
4064
|
-
}
|
|
4065
|
-
|
|
4066
|
-
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
4067
|
-
var s = new Uint8Array(32);
|
|
4068
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
4069
|
-
var sn = new Uint8Array(8);
|
|
4070
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
4071
|
-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
4072
|
-
}
|
|
4073
|
-
|
|
4074
|
-
/*
|
|
4075
|
-
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
4076
|
-
* https://github.com/floodyberry/poly1305-donna
|
|
4077
|
-
*/
|
|
4078
|
-
|
|
4079
|
-
var poly1305 = function(key) {
|
|
4080
|
-
this.buffer = new Uint8Array(16);
|
|
4081
|
-
this.r = new Uint16Array(10);
|
|
4082
|
-
this.h = new Uint16Array(10);
|
|
4083
|
-
this.pad = new Uint16Array(8);
|
|
4084
|
-
this.leftover = 0;
|
|
4085
|
-
this.fin = 0;
|
|
4086
|
-
|
|
4087
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
4088
|
-
|
|
4089
|
-
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
4090
|
-
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
4091
|
-
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
4092
|
-
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
4093
|
-
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
4094
|
-
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
4095
|
-
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
4096
|
-
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
4097
|
-
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
4098
|
-
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
4099
|
-
|
|
4100
|
-
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
4101
|
-
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
4102
|
-
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
4103
|
-
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
4104
|
-
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
4105
|
-
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
4106
|
-
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
4107
|
-
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
4108
|
-
};
|
|
4109
|
-
|
|
4110
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
4111
|
-
var hibit = this.fin ? 0 : (1 << 11);
|
|
4112
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
4113
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
4114
|
-
|
|
4115
|
-
var h0 = this.h[0],
|
|
4116
|
-
h1 = this.h[1],
|
|
4117
|
-
h2 = this.h[2],
|
|
4118
|
-
h3 = this.h[3],
|
|
4119
|
-
h4 = this.h[4],
|
|
4120
|
-
h5 = this.h[5],
|
|
4121
|
-
h6 = this.h[6],
|
|
4122
|
-
h7 = this.h[7],
|
|
4123
|
-
h8 = this.h[8],
|
|
4124
|
-
h9 = this.h[9];
|
|
4125
|
-
|
|
4126
|
-
var r0 = this.r[0],
|
|
4127
|
-
r1 = this.r[1],
|
|
4128
|
-
r2 = this.r[2],
|
|
4129
|
-
r3 = this.r[3],
|
|
4130
|
-
r4 = this.r[4],
|
|
4131
|
-
r5 = this.r[5],
|
|
4132
|
-
r6 = this.r[6],
|
|
4133
|
-
r7 = this.r[7],
|
|
4134
|
-
r8 = this.r[8],
|
|
4135
|
-
r9 = this.r[9];
|
|
4136
|
-
|
|
4137
|
-
while (bytes >= 16) {
|
|
4138
|
-
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
4139
|
-
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
4140
|
-
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
4141
|
-
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
4142
|
-
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
4143
|
-
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
4144
|
-
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
4145
|
-
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
4146
|
-
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
4147
|
-
h9 += ((t7 >>> 5)) | hibit;
|
|
4148
|
-
|
|
4149
|
-
c = 0;
|
|
4150
|
-
|
|
4151
|
-
d0 = c;
|
|
4152
|
-
d0 += h0 * r0;
|
|
4153
|
-
d0 += h1 * (5 * r9);
|
|
4154
|
-
d0 += h2 * (5 * r8);
|
|
4155
|
-
d0 += h3 * (5 * r7);
|
|
4156
|
-
d0 += h4 * (5 * r6);
|
|
4157
|
-
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
4158
|
-
d0 += h5 * (5 * r5);
|
|
4159
|
-
d0 += h6 * (5 * r4);
|
|
4160
|
-
d0 += h7 * (5 * r3);
|
|
4161
|
-
d0 += h8 * (5 * r2);
|
|
4162
|
-
d0 += h9 * (5 * r1);
|
|
4163
|
-
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
4164
|
-
|
|
4165
|
-
d1 = c;
|
|
4166
|
-
d1 += h0 * r1;
|
|
4167
|
-
d1 += h1 * r0;
|
|
4168
|
-
d1 += h2 * (5 * r9);
|
|
4169
|
-
d1 += h3 * (5 * r8);
|
|
4170
|
-
d1 += h4 * (5 * r7);
|
|
4171
|
-
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
4172
|
-
d1 += h5 * (5 * r6);
|
|
4173
|
-
d1 += h6 * (5 * r5);
|
|
4174
|
-
d1 += h7 * (5 * r4);
|
|
4175
|
-
d1 += h8 * (5 * r3);
|
|
4176
|
-
d1 += h9 * (5 * r2);
|
|
4177
|
-
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
4178
|
-
|
|
4179
|
-
d2 = c;
|
|
4180
|
-
d2 += h0 * r2;
|
|
4181
|
-
d2 += h1 * r1;
|
|
4182
|
-
d2 += h2 * r0;
|
|
4183
|
-
d2 += h3 * (5 * r9);
|
|
4184
|
-
d2 += h4 * (5 * r8);
|
|
4185
|
-
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
4186
|
-
d2 += h5 * (5 * r7);
|
|
4187
|
-
d2 += h6 * (5 * r6);
|
|
4188
|
-
d2 += h7 * (5 * r5);
|
|
4189
|
-
d2 += h8 * (5 * r4);
|
|
4190
|
-
d2 += h9 * (5 * r3);
|
|
4191
|
-
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
4192
|
-
|
|
4193
|
-
d3 = c;
|
|
4194
|
-
d3 += h0 * r3;
|
|
4195
|
-
d3 += h1 * r2;
|
|
4196
|
-
d3 += h2 * r1;
|
|
4197
|
-
d3 += h3 * r0;
|
|
4198
|
-
d3 += h4 * (5 * r9);
|
|
4199
|
-
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
4200
|
-
d3 += h5 * (5 * r8);
|
|
4201
|
-
d3 += h6 * (5 * r7);
|
|
4202
|
-
d3 += h7 * (5 * r6);
|
|
4203
|
-
d3 += h8 * (5 * r5);
|
|
4204
|
-
d3 += h9 * (5 * r4);
|
|
4205
|
-
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
4206
|
-
|
|
4207
|
-
d4 = c;
|
|
4208
|
-
d4 += h0 * r4;
|
|
4209
|
-
d4 += h1 * r3;
|
|
4210
|
-
d4 += h2 * r2;
|
|
4211
|
-
d4 += h3 * r1;
|
|
4212
|
-
d4 += h4 * r0;
|
|
4213
|
-
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
4214
|
-
d4 += h5 * (5 * r9);
|
|
4215
|
-
d4 += h6 * (5 * r8);
|
|
4216
|
-
d4 += h7 * (5 * r7);
|
|
4217
|
-
d4 += h8 * (5 * r6);
|
|
4218
|
-
d4 += h9 * (5 * r5);
|
|
4219
|
-
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
4220
|
-
|
|
4221
|
-
d5 = c;
|
|
4222
|
-
d5 += h0 * r5;
|
|
4223
|
-
d5 += h1 * r4;
|
|
4224
|
-
d5 += h2 * r3;
|
|
4225
|
-
d5 += h3 * r2;
|
|
4226
|
-
d5 += h4 * r1;
|
|
4227
|
-
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
4228
|
-
d5 += h5 * r0;
|
|
4229
|
-
d5 += h6 * (5 * r9);
|
|
4230
|
-
d5 += h7 * (5 * r8);
|
|
4231
|
-
d5 += h8 * (5 * r7);
|
|
4232
|
-
d5 += h9 * (5 * r6);
|
|
4233
|
-
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
4234
|
-
|
|
4235
|
-
d6 = c;
|
|
4236
|
-
d6 += h0 * r6;
|
|
4237
|
-
d6 += h1 * r5;
|
|
4238
|
-
d6 += h2 * r4;
|
|
4239
|
-
d6 += h3 * r3;
|
|
4240
|
-
d6 += h4 * r2;
|
|
4241
|
-
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
4242
|
-
d6 += h5 * r1;
|
|
4243
|
-
d6 += h6 * r0;
|
|
4244
|
-
d6 += h7 * (5 * r9);
|
|
4245
|
-
d6 += h8 * (5 * r8);
|
|
4246
|
-
d6 += h9 * (5 * r7);
|
|
4247
|
-
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
4248
|
-
|
|
4249
|
-
d7 = c;
|
|
4250
|
-
d7 += h0 * r7;
|
|
4251
|
-
d7 += h1 * r6;
|
|
4252
|
-
d7 += h2 * r5;
|
|
4253
|
-
d7 += h3 * r4;
|
|
4254
|
-
d7 += h4 * r3;
|
|
4255
|
-
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
4256
|
-
d7 += h5 * r2;
|
|
4257
|
-
d7 += h6 * r1;
|
|
4258
|
-
d7 += h7 * r0;
|
|
4259
|
-
d7 += h8 * (5 * r9);
|
|
4260
|
-
d7 += h9 * (5 * r8);
|
|
4261
|
-
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
4262
|
-
|
|
4263
|
-
d8 = c;
|
|
4264
|
-
d8 += h0 * r8;
|
|
4265
|
-
d8 += h1 * r7;
|
|
4266
|
-
d8 += h2 * r6;
|
|
4267
|
-
d8 += h3 * r5;
|
|
4268
|
-
d8 += h4 * r4;
|
|
4269
|
-
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
4270
|
-
d8 += h5 * r3;
|
|
4271
|
-
d8 += h6 * r2;
|
|
4272
|
-
d8 += h7 * r1;
|
|
4273
|
-
d8 += h8 * r0;
|
|
4274
|
-
d8 += h9 * (5 * r9);
|
|
4275
|
-
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
4276
|
-
|
|
4277
|
-
d9 = c;
|
|
4278
|
-
d9 += h0 * r9;
|
|
4279
|
-
d9 += h1 * r8;
|
|
4280
|
-
d9 += h2 * r7;
|
|
4281
|
-
d9 += h3 * r6;
|
|
4282
|
-
d9 += h4 * r5;
|
|
4283
|
-
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
4284
|
-
d9 += h5 * r4;
|
|
4285
|
-
d9 += h6 * r3;
|
|
4286
|
-
d9 += h7 * r2;
|
|
4287
|
-
d9 += h8 * r1;
|
|
4288
|
-
d9 += h9 * r0;
|
|
4289
|
-
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
4290
|
-
|
|
4291
|
-
c = (((c << 2) + c)) | 0;
|
|
4292
|
-
c = (c + d0) | 0;
|
|
4293
|
-
d0 = c & 0x1fff;
|
|
4294
|
-
c = (c >>> 13);
|
|
4295
|
-
d1 += c;
|
|
4296
|
-
|
|
4297
|
-
h0 = d0;
|
|
4298
|
-
h1 = d1;
|
|
4299
|
-
h2 = d2;
|
|
4300
|
-
h3 = d3;
|
|
4301
|
-
h4 = d4;
|
|
4302
|
-
h5 = d5;
|
|
4303
|
-
h6 = d6;
|
|
4304
|
-
h7 = d7;
|
|
4305
|
-
h8 = d8;
|
|
4306
|
-
h9 = d9;
|
|
4307
|
-
|
|
4308
|
-
mpos += 16;
|
|
4309
|
-
bytes -= 16;
|
|
4310
|
-
}
|
|
4311
|
-
this.h[0] = h0;
|
|
4312
|
-
this.h[1] = h1;
|
|
4313
|
-
this.h[2] = h2;
|
|
4314
|
-
this.h[3] = h3;
|
|
4315
|
-
this.h[4] = h4;
|
|
4316
|
-
this.h[5] = h5;
|
|
4317
|
-
this.h[6] = h6;
|
|
4318
|
-
this.h[7] = h7;
|
|
4319
|
-
this.h[8] = h8;
|
|
4320
|
-
this.h[9] = h9;
|
|
4321
|
-
};
|
|
4322
|
-
|
|
4323
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
4324
|
-
var g = new Uint16Array(10);
|
|
4325
|
-
var c, mask, f, i;
|
|
4326
|
-
|
|
4327
|
-
if (this.leftover) {
|
|
4328
|
-
i = this.leftover;
|
|
4329
|
-
this.buffer[i++] = 1;
|
|
4330
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
4331
|
-
this.fin = 1;
|
|
4332
|
-
this.blocks(this.buffer, 0, 16);
|
|
4333
|
-
}
|
|
4334
|
-
|
|
4335
|
-
c = this.h[1] >>> 13;
|
|
4336
|
-
this.h[1] &= 0x1fff;
|
|
4337
|
-
for (i = 2; i < 10; i++) {
|
|
4338
|
-
this.h[i] += c;
|
|
4339
|
-
c = this.h[i] >>> 13;
|
|
4340
|
-
this.h[i] &= 0x1fff;
|
|
4341
|
-
}
|
|
4342
|
-
this.h[0] += (c * 5);
|
|
4343
|
-
c = this.h[0] >>> 13;
|
|
4344
|
-
this.h[0] &= 0x1fff;
|
|
4345
|
-
this.h[1] += c;
|
|
4346
|
-
c = this.h[1] >>> 13;
|
|
4347
|
-
this.h[1] &= 0x1fff;
|
|
4348
|
-
this.h[2] += c;
|
|
4349
|
-
|
|
4350
|
-
g[0] = this.h[0] + 5;
|
|
4351
|
-
c = g[0] >>> 13;
|
|
4352
|
-
g[0] &= 0x1fff;
|
|
4353
|
-
for (i = 1; i < 10; i++) {
|
|
4354
|
-
g[i] = this.h[i] + c;
|
|
4355
|
-
c = g[i] >>> 13;
|
|
4356
|
-
g[i] &= 0x1fff;
|
|
4357
|
-
}
|
|
4358
|
-
g[9] -= (1 << 13);
|
|
4359
|
-
|
|
4360
|
-
mask = (c ^ 1) - 1;
|
|
4361
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
4362
|
-
mask = ~mask;
|
|
4363
|
-
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
4364
|
-
|
|
4365
|
-
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
4366
|
-
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
4367
|
-
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
4368
|
-
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
4369
|
-
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
4370
|
-
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
4371
|
-
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
4372
|
-
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
4373
|
-
|
|
4374
|
-
f = this.h[0] + this.pad[0];
|
|
4375
|
-
this.h[0] = f & 0xffff;
|
|
4376
|
-
for (i = 1; i < 8; i++) {
|
|
4377
|
-
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
4378
|
-
this.h[i] = f & 0xffff;
|
|
4379
|
-
}
|
|
4380
|
-
|
|
4381
|
-
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
4382
|
-
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
4383
|
-
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
4384
|
-
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
4385
|
-
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
4386
|
-
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
4387
|
-
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
4388
|
-
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
4389
|
-
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
4390
|
-
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
4391
|
-
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
4392
|
-
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
4393
|
-
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
4394
|
-
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
4395
|
-
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
4396
|
-
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
4397
|
-
};
|
|
4398
|
-
|
|
4399
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
4400
|
-
var i, want;
|
|
4401
|
-
|
|
4402
|
-
if (this.leftover) {
|
|
4403
|
-
want = (16 - this.leftover);
|
|
4404
|
-
if (want > bytes)
|
|
4405
|
-
want = bytes;
|
|
4406
|
-
for (i = 0; i < want; i++)
|
|
4407
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
4408
|
-
bytes -= want;
|
|
4409
|
-
mpos += want;
|
|
4410
|
-
this.leftover += want;
|
|
4411
|
-
if (this.leftover < 16)
|
|
4412
|
-
return;
|
|
4413
|
-
this.blocks(this.buffer, 0, 16);
|
|
4414
|
-
this.leftover = 0;
|
|
4415
|
-
}
|
|
4416
|
-
|
|
4417
|
-
if (bytes >= 16) {
|
|
4418
|
-
want = bytes - (bytes % 16);
|
|
4419
|
-
this.blocks(m, mpos, want);
|
|
4420
|
-
mpos += want;
|
|
4421
|
-
bytes -= want;
|
|
4422
|
-
}
|
|
4423
|
-
|
|
4424
|
-
if (bytes) {
|
|
4425
|
-
for (i = 0; i < bytes; i++)
|
|
4426
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
4427
|
-
this.leftover += bytes;
|
|
4428
|
-
}
|
|
4429
|
-
};
|
|
4430
|
-
|
|
4431
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
4432
|
-
var s = new poly1305(k);
|
|
4433
|
-
s.update(m, mpos, n);
|
|
4434
|
-
s.finish(out, outpos);
|
|
4435
|
-
return 0;
|
|
4436
|
-
}
|
|
4437
|
-
|
|
4438
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
4439
|
-
var x = new Uint8Array(16);
|
|
4440
|
-
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
4441
|
-
return crypto_verify_16(h,hpos,x,0);
|
|
4442
|
-
}
|
|
4443
|
-
|
|
4444
|
-
function crypto_secretbox(c,m,d,n,k) {
|
|
4445
|
-
var i;
|
|
4446
|
-
if (d < 32) return -1;
|
|
4447
|
-
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
4448
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
4449
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
4450
|
-
return 0;
|
|
4451
|
-
}
|
|
4452
|
-
|
|
4453
|
-
function crypto_secretbox_open(m,c,d,n,k) {
|
|
4454
|
-
var i;
|
|
4455
|
-
var x = new Uint8Array(32);
|
|
4456
|
-
if (d < 32) return -1;
|
|
4457
|
-
crypto_stream(x,0,32,n,k);
|
|
4458
|
-
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
4459
|
-
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
4460
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
4461
|
-
return 0;
|
|
4462
|
-
}
|
|
4463
|
-
|
|
4464
|
-
function set25519(r, a) {
|
|
4465
|
-
var i;
|
|
4466
|
-
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
4467
|
-
}
|
|
4468
|
-
|
|
4469
|
-
function car25519(o) {
|
|
4470
|
-
var i, v, c = 1;
|
|
4471
|
-
for (i = 0; i < 16; i++) {
|
|
4472
|
-
v = o[i] + c + 65535;
|
|
4473
|
-
c = Math.floor(v / 65536);
|
|
4474
|
-
o[i] = v - c * 65536;
|
|
4475
|
-
}
|
|
4476
|
-
o[0] += c-1 + 37 * (c-1);
|
|
4477
|
-
}
|
|
4478
|
-
|
|
4479
|
-
function sel25519(p, q, b) {
|
|
4480
|
-
var t, c = ~(b-1);
|
|
4481
|
-
for (var i = 0; i < 16; i++) {
|
|
4482
|
-
t = c & (p[i] ^ q[i]);
|
|
4483
|
-
p[i] ^= t;
|
|
4484
|
-
q[i] ^= t;
|
|
4485
|
-
}
|
|
4486
|
-
}
|
|
4487
|
-
|
|
4488
|
-
function pack25519(o, n) {
|
|
4489
|
-
var i, j, b;
|
|
4490
|
-
var m = gf(), t = gf();
|
|
4491
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
4492
|
-
car25519(t);
|
|
4493
|
-
car25519(t);
|
|
4494
|
-
car25519(t);
|
|
4495
|
-
for (j = 0; j < 2; j++) {
|
|
4496
|
-
m[0] = t[0] - 0xffed;
|
|
4497
|
-
for (i = 1; i < 15; i++) {
|
|
4498
|
-
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
4499
|
-
m[i-1] &= 0xffff;
|
|
4500
|
-
}
|
|
4501
|
-
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
4502
|
-
b = (m[15]>>16) & 1;
|
|
4503
|
-
m[14] &= 0xffff;
|
|
4504
|
-
sel25519(t, m, 1-b);
|
|
4505
|
-
}
|
|
4506
|
-
for (i = 0; i < 16; i++) {
|
|
4507
|
-
o[2*i] = t[i] & 0xff;
|
|
4508
|
-
o[2*i+1] = t[i]>>8;
|
|
4509
|
-
}
|
|
4510
|
-
}
|
|
4511
|
-
|
|
4512
|
-
function neq25519(a, b) {
|
|
4513
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
4514
|
-
pack25519(c, a);
|
|
4515
|
-
pack25519(d, b);
|
|
4516
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
4517
|
-
}
|
|
4518
|
-
|
|
4519
|
-
function par25519(a) {
|
|
4520
|
-
var d = new Uint8Array(32);
|
|
4521
|
-
pack25519(d, a);
|
|
4522
|
-
return d[0] & 1;
|
|
4523
|
-
}
|
|
4524
|
-
|
|
4525
|
-
function unpack25519(o, n) {
|
|
4526
|
-
var i;
|
|
4527
|
-
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
4528
|
-
o[15] &= 0x7fff;
|
|
4529
|
-
}
|
|
4530
|
-
|
|
4531
|
-
function A(o, a, b) {
|
|
4532
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
4533
|
-
}
|
|
4534
|
-
|
|
4535
|
-
function Z(o, a, b) {
|
|
4536
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
4537
|
-
}
|
|
4538
|
-
|
|
4539
|
-
function M(o, a, b) {
|
|
4540
|
-
var v, c,
|
|
4541
|
-
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
4542
|
-
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
4543
|
-
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
4544
|
-
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
4545
|
-
b0 = b[0],
|
|
4546
|
-
b1 = b[1],
|
|
4547
|
-
b2 = b[2],
|
|
4548
|
-
b3 = b[3],
|
|
4549
|
-
b4 = b[4],
|
|
4550
|
-
b5 = b[5],
|
|
4551
|
-
b6 = b[6],
|
|
4552
|
-
b7 = b[7],
|
|
4553
|
-
b8 = b[8],
|
|
4554
|
-
b9 = b[9],
|
|
4555
|
-
b10 = b[10],
|
|
4556
|
-
b11 = b[11],
|
|
4557
|
-
b12 = b[12],
|
|
4558
|
-
b13 = b[13],
|
|
4559
|
-
b14 = b[14],
|
|
4560
|
-
b15 = b[15];
|
|
4561
|
-
|
|
4562
|
-
v = a[0];
|
|
4563
|
-
t0 += v * b0;
|
|
4564
|
-
t1 += v * b1;
|
|
4565
|
-
t2 += v * b2;
|
|
4566
|
-
t3 += v * b3;
|
|
4567
|
-
t4 += v * b4;
|
|
4568
|
-
t5 += v * b5;
|
|
4569
|
-
t6 += v * b6;
|
|
4570
|
-
t7 += v * b7;
|
|
4571
|
-
t8 += v * b8;
|
|
4572
|
-
t9 += v * b9;
|
|
4573
|
-
t10 += v * b10;
|
|
4574
|
-
t11 += v * b11;
|
|
4575
|
-
t12 += v * b12;
|
|
4576
|
-
t13 += v * b13;
|
|
4577
|
-
t14 += v * b14;
|
|
4578
|
-
t15 += v * b15;
|
|
4579
|
-
v = a[1];
|
|
4580
|
-
t1 += v * b0;
|
|
4581
|
-
t2 += v * b1;
|
|
4582
|
-
t3 += v * b2;
|
|
4583
|
-
t4 += v * b3;
|
|
4584
|
-
t5 += v * b4;
|
|
4585
|
-
t6 += v * b5;
|
|
4586
|
-
t7 += v * b6;
|
|
4587
|
-
t8 += v * b7;
|
|
4588
|
-
t9 += v * b8;
|
|
4589
|
-
t10 += v * b9;
|
|
4590
|
-
t11 += v * b10;
|
|
4591
|
-
t12 += v * b11;
|
|
4592
|
-
t13 += v * b12;
|
|
4593
|
-
t14 += v * b13;
|
|
4594
|
-
t15 += v * b14;
|
|
4595
|
-
t16 += v * b15;
|
|
4596
|
-
v = a[2];
|
|
4597
|
-
t2 += v * b0;
|
|
4598
|
-
t3 += v * b1;
|
|
4599
|
-
t4 += v * b2;
|
|
4600
|
-
t5 += v * b3;
|
|
4601
|
-
t6 += v * b4;
|
|
4602
|
-
t7 += v * b5;
|
|
4603
|
-
t8 += v * b6;
|
|
4604
|
-
t9 += v * b7;
|
|
4605
|
-
t10 += v * b8;
|
|
4606
|
-
t11 += v * b9;
|
|
4607
|
-
t12 += v * b10;
|
|
4608
|
-
t13 += v * b11;
|
|
4609
|
-
t14 += v * b12;
|
|
4610
|
-
t15 += v * b13;
|
|
4611
|
-
t16 += v * b14;
|
|
4612
|
-
t17 += v * b15;
|
|
4613
|
-
v = a[3];
|
|
4614
|
-
t3 += v * b0;
|
|
4615
|
-
t4 += v * b1;
|
|
4616
|
-
t5 += v * b2;
|
|
4617
|
-
t6 += v * b3;
|
|
4618
|
-
t7 += v * b4;
|
|
4619
|
-
t8 += v * b5;
|
|
4620
|
-
t9 += v * b6;
|
|
4621
|
-
t10 += v * b7;
|
|
4622
|
-
t11 += v * b8;
|
|
4623
|
-
t12 += v * b9;
|
|
4624
|
-
t13 += v * b10;
|
|
4625
|
-
t14 += v * b11;
|
|
4626
|
-
t15 += v * b12;
|
|
4627
|
-
t16 += v * b13;
|
|
4628
|
-
t17 += v * b14;
|
|
4629
|
-
t18 += v * b15;
|
|
4630
|
-
v = a[4];
|
|
4631
|
-
t4 += v * b0;
|
|
4632
|
-
t5 += v * b1;
|
|
4633
|
-
t6 += v * b2;
|
|
4634
|
-
t7 += v * b3;
|
|
4635
|
-
t8 += v * b4;
|
|
4636
|
-
t9 += v * b5;
|
|
4637
|
-
t10 += v * b6;
|
|
4638
|
-
t11 += v * b7;
|
|
4639
|
-
t12 += v * b8;
|
|
4640
|
-
t13 += v * b9;
|
|
4641
|
-
t14 += v * b10;
|
|
4642
|
-
t15 += v * b11;
|
|
4643
|
-
t16 += v * b12;
|
|
4644
|
-
t17 += v * b13;
|
|
4645
|
-
t18 += v * b14;
|
|
4646
|
-
t19 += v * b15;
|
|
4647
|
-
v = a[5];
|
|
4648
|
-
t5 += v * b0;
|
|
4649
|
-
t6 += v * b1;
|
|
4650
|
-
t7 += v * b2;
|
|
4651
|
-
t8 += v * b3;
|
|
4652
|
-
t9 += v * b4;
|
|
4653
|
-
t10 += v * b5;
|
|
4654
|
-
t11 += v * b6;
|
|
4655
|
-
t12 += v * b7;
|
|
4656
|
-
t13 += v * b8;
|
|
4657
|
-
t14 += v * b9;
|
|
4658
|
-
t15 += v * b10;
|
|
4659
|
-
t16 += v * b11;
|
|
4660
|
-
t17 += v * b12;
|
|
4661
|
-
t18 += v * b13;
|
|
4662
|
-
t19 += v * b14;
|
|
4663
|
-
t20 += v * b15;
|
|
4664
|
-
v = a[6];
|
|
4665
|
-
t6 += v * b0;
|
|
4666
|
-
t7 += v * b1;
|
|
4667
|
-
t8 += v * b2;
|
|
4668
|
-
t9 += v * b3;
|
|
4669
|
-
t10 += v * b4;
|
|
4670
|
-
t11 += v * b5;
|
|
4671
|
-
t12 += v * b6;
|
|
4672
|
-
t13 += v * b7;
|
|
4673
|
-
t14 += v * b8;
|
|
4674
|
-
t15 += v * b9;
|
|
4675
|
-
t16 += v * b10;
|
|
4676
|
-
t17 += v * b11;
|
|
4677
|
-
t18 += v * b12;
|
|
4678
|
-
t19 += v * b13;
|
|
4679
|
-
t20 += v * b14;
|
|
4680
|
-
t21 += v * b15;
|
|
4681
|
-
v = a[7];
|
|
4682
|
-
t7 += v * b0;
|
|
4683
|
-
t8 += v * b1;
|
|
4684
|
-
t9 += v * b2;
|
|
4685
|
-
t10 += v * b3;
|
|
4686
|
-
t11 += v * b4;
|
|
4687
|
-
t12 += v * b5;
|
|
4688
|
-
t13 += v * b6;
|
|
4689
|
-
t14 += v * b7;
|
|
4690
|
-
t15 += v * b8;
|
|
4691
|
-
t16 += v * b9;
|
|
4692
|
-
t17 += v * b10;
|
|
4693
|
-
t18 += v * b11;
|
|
4694
|
-
t19 += v * b12;
|
|
4695
|
-
t20 += v * b13;
|
|
4696
|
-
t21 += v * b14;
|
|
4697
|
-
t22 += v * b15;
|
|
4698
|
-
v = a[8];
|
|
4699
|
-
t8 += v * b0;
|
|
4700
|
-
t9 += v * b1;
|
|
4701
|
-
t10 += v * b2;
|
|
4702
|
-
t11 += v * b3;
|
|
4703
|
-
t12 += v * b4;
|
|
4704
|
-
t13 += v * b5;
|
|
4705
|
-
t14 += v * b6;
|
|
4706
|
-
t15 += v * b7;
|
|
4707
|
-
t16 += v * b8;
|
|
4708
|
-
t17 += v * b9;
|
|
4709
|
-
t18 += v * b10;
|
|
4710
|
-
t19 += v * b11;
|
|
4711
|
-
t20 += v * b12;
|
|
4712
|
-
t21 += v * b13;
|
|
4713
|
-
t22 += v * b14;
|
|
4714
|
-
t23 += v * b15;
|
|
4715
|
-
v = a[9];
|
|
4716
|
-
t9 += v * b0;
|
|
4717
|
-
t10 += v * b1;
|
|
4718
|
-
t11 += v * b2;
|
|
4719
|
-
t12 += v * b3;
|
|
4720
|
-
t13 += v * b4;
|
|
4721
|
-
t14 += v * b5;
|
|
4722
|
-
t15 += v * b6;
|
|
4723
|
-
t16 += v * b7;
|
|
4724
|
-
t17 += v * b8;
|
|
4725
|
-
t18 += v * b9;
|
|
4726
|
-
t19 += v * b10;
|
|
4727
|
-
t20 += v * b11;
|
|
4728
|
-
t21 += v * b12;
|
|
4729
|
-
t22 += v * b13;
|
|
4730
|
-
t23 += v * b14;
|
|
4731
|
-
t24 += v * b15;
|
|
4732
|
-
v = a[10];
|
|
4733
|
-
t10 += v * b0;
|
|
4734
|
-
t11 += v * b1;
|
|
4735
|
-
t12 += v * b2;
|
|
4736
|
-
t13 += v * b3;
|
|
4737
|
-
t14 += v * b4;
|
|
4738
|
-
t15 += v * b5;
|
|
4739
|
-
t16 += v * b6;
|
|
4740
|
-
t17 += v * b7;
|
|
4741
|
-
t18 += v * b8;
|
|
4742
|
-
t19 += v * b9;
|
|
4743
|
-
t20 += v * b10;
|
|
4744
|
-
t21 += v * b11;
|
|
4745
|
-
t22 += v * b12;
|
|
4746
|
-
t23 += v * b13;
|
|
4747
|
-
t24 += v * b14;
|
|
4748
|
-
t25 += v * b15;
|
|
4749
|
-
v = a[11];
|
|
4750
|
-
t11 += v * b0;
|
|
4751
|
-
t12 += v * b1;
|
|
4752
|
-
t13 += v * b2;
|
|
4753
|
-
t14 += v * b3;
|
|
4754
|
-
t15 += v * b4;
|
|
4755
|
-
t16 += v * b5;
|
|
4756
|
-
t17 += v * b6;
|
|
4757
|
-
t18 += v * b7;
|
|
4758
|
-
t19 += v * b8;
|
|
4759
|
-
t20 += v * b9;
|
|
4760
|
-
t21 += v * b10;
|
|
4761
|
-
t22 += v * b11;
|
|
4762
|
-
t23 += v * b12;
|
|
4763
|
-
t24 += v * b13;
|
|
4764
|
-
t25 += v * b14;
|
|
4765
|
-
t26 += v * b15;
|
|
4766
|
-
v = a[12];
|
|
4767
|
-
t12 += v * b0;
|
|
4768
|
-
t13 += v * b1;
|
|
4769
|
-
t14 += v * b2;
|
|
4770
|
-
t15 += v * b3;
|
|
4771
|
-
t16 += v * b4;
|
|
4772
|
-
t17 += v * b5;
|
|
4773
|
-
t18 += v * b6;
|
|
4774
|
-
t19 += v * b7;
|
|
4775
|
-
t20 += v * b8;
|
|
4776
|
-
t21 += v * b9;
|
|
4777
|
-
t22 += v * b10;
|
|
4778
|
-
t23 += v * b11;
|
|
4779
|
-
t24 += v * b12;
|
|
4780
|
-
t25 += v * b13;
|
|
4781
|
-
t26 += v * b14;
|
|
4782
|
-
t27 += v * b15;
|
|
4783
|
-
v = a[13];
|
|
4784
|
-
t13 += v * b0;
|
|
4785
|
-
t14 += v * b1;
|
|
4786
|
-
t15 += v * b2;
|
|
4787
|
-
t16 += v * b3;
|
|
4788
|
-
t17 += v * b4;
|
|
4789
|
-
t18 += v * b5;
|
|
4790
|
-
t19 += v * b6;
|
|
4791
|
-
t20 += v * b7;
|
|
4792
|
-
t21 += v * b8;
|
|
4793
|
-
t22 += v * b9;
|
|
4794
|
-
t23 += v * b10;
|
|
4795
|
-
t24 += v * b11;
|
|
4796
|
-
t25 += v * b12;
|
|
4797
|
-
t26 += v * b13;
|
|
4798
|
-
t27 += v * b14;
|
|
4799
|
-
t28 += v * b15;
|
|
4800
|
-
v = a[14];
|
|
4801
|
-
t14 += v * b0;
|
|
4802
|
-
t15 += v * b1;
|
|
4803
|
-
t16 += v * b2;
|
|
4804
|
-
t17 += v * b3;
|
|
4805
|
-
t18 += v * b4;
|
|
4806
|
-
t19 += v * b5;
|
|
4807
|
-
t20 += v * b6;
|
|
4808
|
-
t21 += v * b7;
|
|
4809
|
-
t22 += v * b8;
|
|
4810
|
-
t23 += v * b9;
|
|
4811
|
-
t24 += v * b10;
|
|
4812
|
-
t25 += v * b11;
|
|
4813
|
-
t26 += v * b12;
|
|
4814
|
-
t27 += v * b13;
|
|
4815
|
-
t28 += v * b14;
|
|
4816
|
-
t29 += v * b15;
|
|
4817
|
-
v = a[15];
|
|
4818
|
-
t15 += v * b0;
|
|
4819
|
-
t16 += v * b1;
|
|
4820
|
-
t17 += v * b2;
|
|
4821
|
-
t18 += v * b3;
|
|
4822
|
-
t19 += v * b4;
|
|
4823
|
-
t20 += v * b5;
|
|
4824
|
-
t21 += v * b6;
|
|
4825
|
-
t22 += v * b7;
|
|
4826
|
-
t23 += v * b8;
|
|
4827
|
-
t24 += v * b9;
|
|
4828
|
-
t25 += v * b10;
|
|
4829
|
-
t26 += v * b11;
|
|
4830
|
-
t27 += v * b12;
|
|
4831
|
-
t28 += v * b13;
|
|
4832
|
-
t29 += v * b14;
|
|
4833
|
-
t30 += v * b15;
|
|
4834
|
-
|
|
4835
|
-
t0 += 38 * t16;
|
|
4836
|
-
t1 += 38 * t17;
|
|
4837
|
-
t2 += 38 * t18;
|
|
4838
|
-
t3 += 38 * t19;
|
|
4839
|
-
t4 += 38 * t20;
|
|
4840
|
-
t5 += 38 * t21;
|
|
4841
|
-
t6 += 38 * t22;
|
|
4842
|
-
t7 += 38 * t23;
|
|
4843
|
-
t8 += 38 * t24;
|
|
4844
|
-
t9 += 38 * t25;
|
|
4845
|
-
t10 += 38 * t26;
|
|
4846
|
-
t11 += 38 * t27;
|
|
4847
|
-
t12 += 38 * t28;
|
|
4848
|
-
t13 += 38 * t29;
|
|
4849
|
-
t14 += 38 * t30;
|
|
4850
|
-
// t15 left as is
|
|
4851
|
-
|
|
4852
|
-
// first car
|
|
4853
|
-
c = 1;
|
|
4854
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
4855
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
4856
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
4857
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
4858
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
4859
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
4860
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
4861
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
4862
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
4863
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
4864
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
4865
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
4866
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
4867
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
4868
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
4869
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
4870
|
-
t0 += c-1 + 37 * (c-1);
|
|
4871
|
-
|
|
4872
|
-
// second car
|
|
4873
|
-
c = 1;
|
|
4874
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
4875
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
4876
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
4877
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
4878
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
4879
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
4880
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
4881
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
4882
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
4883
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
4884
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
4885
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
4886
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
4887
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
4888
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
4889
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
4890
|
-
t0 += c-1 + 37 * (c-1);
|
|
4891
|
-
|
|
4892
|
-
o[ 0] = t0;
|
|
4893
|
-
o[ 1] = t1;
|
|
4894
|
-
o[ 2] = t2;
|
|
4895
|
-
o[ 3] = t3;
|
|
4896
|
-
o[ 4] = t4;
|
|
4897
|
-
o[ 5] = t5;
|
|
4898
|
-
o[ 6] = t6;
|
|
4899
|
-
o[ 7] = t7;
|
|
4900
|
-
o[ 8] = t8;
|
|
4901
|
-
o[ 9] = t9;
|
|
4902
|
-
o[10] = t10;
|
|
4903
|
-
o[11] = t11;
|
|
4904
|
-
o[12] = t12;
|
|
4905
|
-
o[13] = t13;
|
|
4906
|
-
o[14] = t14;
|
|
4907
|
-
o[15] = t15;
|
|
4908
|
-
}
|
|
4909
|
-
|
|
4910
|
-
function S(o, a) {
|
|
4911
|
-
M(o, a, a);
|
|
4912
|
-
}
|
|
4913
|
-
|
|
4914
|
-
function inv25519(o, i) {
|
|
4915
|
-
var c = gf();
|
|
4916
|
-
var a;
|
|
4917
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
4918
|
-
for (a = 253; a >= 0; a--) {
|
|
4919
|
-
S(c, c);
|
|
4920
|
-
if(a !== 2 && a !== 4) M(c, c, i);
|
|
4921
|
-
}
|
|
4922
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
4923
|
-
}
|
|
4924
|
-
|
|
4925
|
-
function pow2523(o, i) {
|
|
4926
|
-
var c = gf();
|
|
4927
|
-
var a;
|
|
4928
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
4929
|
-
for (a = 250; a >= 0; a--) {
|
|
4930
|
-
S(c, c);
|
|
4931
|
-
if(a !== 1) M(c, c, i);
|
|
4932
|
-
}
|
|
4933
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
4934
|
-
}
|
|
4935
|
-
|
|
4936
|
-
function crypto_scalarmult(q, n, p) {
|
|
4937
|
-
var z = new Uint8Array(32);
|
|
4938
|
-
var x = new Float64Array(80), r, i;
|
|
4939
|
-
var a = gf(), b = gf(), c = gf(),
|
|
4940
|
-
d = gf(), e = gf(), f = gf();
|
|
4941
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
4942
|
-
z[31]=(n[31]&127)|64;
|
|
4943
|
-
z[0]&=248;
|
|
4944
|
-
unpack25519(x,p);
|
|
4945
|
-
for (i = 0; i < 16; i++) {
|
|
4946
|
-
b[i]=x[i];
|
|
4947
|
-
d[i]=a[i]=c[i]=0;
|
|
4948
|
-
}
|
|
4949
|
-
a[0]=d[0]=1;
|
|
4950
|
-
for (i=254; i>=0; --i) {
|
|
4951
|
-
r=(z[i>>>3]>>>(i&7))&1;
|
|
4952
|
-
sel25519(a,b,r);
|
|
4953
|
-
sel25519(c,d,r);
|
|
4954
|
-
A(e,a,c);
|
|
4955
|
-
Z(a,a,c);
|
|
4956
|
-
A(c,b,d);
|
|
4957
|
-
Z(b,b,d);
|
|
4958
|
-
S(d,e);
|
|
4959
|
-
S(f,a);
|
|
4960
|
-
M(a,c,a);
|
|
4961
|
-
M(c,b,e);
|
|
4962
|
-
A(e,a,c);
|
|
4963
|
-
Z(a,a,c);
|
|
4964
|
-
S(b,a);
|
|
4965
|
-
Z(c,d,f);
|
|
4966
|
-
M(a,c,_121665);
|
|
4967
|
-
A(a,a,d);
|
|
4968
|
-
M(c,c,a);
|
|
4969
|
-
M(a,d,f);
|
|
4970
|
-
M(d,b,x);
|
|
4971
|
-
S(b,e);
|
|
4972
|
-
sel25519(a,b,r);
|
|
4973
|
-
sel25519(c,d,r);
|
|
4974
|
-
}
|
|
4975
|
-
for (i = 0; i < 16; i++) {
|
|
4976
|
-
x[i+16]=a[i];
|
|
4977
|
-
x[i+32]=c[i];
|
|
4978
|
-
x[i+48]=b[i];
|
|
4979
|
-
x[i+64]=d[i];
|
|
4980
|
-
}
|
|
4981
|
-
var x32 = x.subarray(32);
|
|
4982
|
-
var x16 = x.subarray(16);
|
|
4983
|
-
inv25519(x32,x32);
|
|
4984
|
-
M(x16,x16,x32);
|
|
4985
|
-
pack25519(q,x16);
|
|
4986
|
-
return 0;
|
|
4987
|
-
}
|
|
4988
|
-
|
|
4989
|
-
function crypto_scalarmult_base(q, n) {
|
|
4990
|
-
return crypto_scalarmult(q, n, _9);
|
|
4991
|
-
}
|
|
4992
|
-
|
|
4993
|
-
function crypto_box_keypair(y, x) {
|
|
4994
|
-
randombytes(x, 32);
|
|
4995
|
-
return crypto_scalarmult_base(y, x);
|
|
4996
|
-
}
|
|
4997
|
-
|
|
4998
|
-
function crypto_box_beforenm(k, y, x) {
|
|
4999
|
-
var s = new Uint8Array(32);
|
|
5000
|
-
crypto_scalarmult(s, x, y);
|
|
5001
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
5002
|
-
}
|
|
5003
|
-
|
|
5004
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
5005
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
5006
|
-
|
|
5007
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
5008
|
-
var k = new Uint8Array(32);
|
|
5009
|
-
crypto_box_beforenm(k, y, x);
|
|
5010
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
5011
|
-
}
|
|
5012
|
-
|
|
5013
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
5014
|
-
var k = new Uint8Array(32);
|
|
5015
|
-
crypto_box_beforenm(k, y, x);
|
|
5016
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
5017
|
-
}
|
|
5018
|
-
|
|
5019
|
-
var K = [
|
|
5020
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
5021
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
5022
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
5023
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
5024
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
5025
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
5026
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
5027
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
5028
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
5029
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
5030
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
5031
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
5032
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
5033
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
5034
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
5035
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
5036
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
5037
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
5038
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
5039
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
5040
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
5041
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
5042
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
5043
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
5044
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
5045
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
5046
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
5047
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
5048
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
5049
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
5050
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
5051
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
5052
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
5053
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
5054
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
5055
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
5056
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
5057
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
5058
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
5059
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
5060
|
-
];
|
|
5061
|
-
|
|
5062
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
5063
|
-
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
5064
|
-
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
5065
|
-
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
5066
|
-
th, tl, i, j, h, l, a, b, c, d;
|
|
5067
|
-
|
|
5068
|
-
var ah0 = hh[0],
|
|
5069
|
-
ah1 = hh[1],
|
|
5070
|
-
ah2 = hh[2],
|
|
5071
|
-
ah3 = hh[3],
|
|
5072
|
-
ah4 = hh[4],
|
|
5073
|
-
ah5 = hh[5],
|
|
5074
|
-
ah6 = hh[6],
|
|
5075
|
-
ah7 = hh[7],
|
|
5076
|
-
|
|
5077
|
-
al0 = hl[0],
|
|
5078
|
-
al1 = hl[1],
|
|
5079
|
-
al2 = hl[2],
|
|
5080
|
-
al3 = hl[3],
|
|
5081
|
-
al4 = hl[4],
|
|
5082
|
-
al5 = hl[5],
|
|
5083
|
-
al6 = hl[6],
|
|
5084
|
-
al7 = hl[7];
|
|
5085
|
-
|
|
5086
|
-
var pos = 0;
|
|
5087
|
-
while (n >= 128) {
|
|
5088
|
-
for (i = 0; i < 16; i++) {
|
|
5089
|
-
j = 8 * i + pos;
|
|
5090
|
-
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
5091
|
-
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
5092
|
-
}
|
|
5093
|
-
for (i = 0; i < 80; i++) {
|
|
5094
|
-
bh0 = ah0;
|
|
5095
|
-
bh1 = ah1;
|
|
5096
|
-
bh2 = ah2;
|
|
5097
|
-
bh3 = ah3;
|
|
5098
|
-
bh4 = ah4;
|
|
5099
|
-
bh5 = ah5;
|
|
5100
|
-
bh6 = ah6;
|
|
5101
|
-
bh7 = ah7;
|
|
5102
|
-
|
|
5103
|
-
bl0 = al0;
|
|
5104
|
-
bl1 = al1;
|
|
5105
|
-
bl2 = al2;
|
|
5106
|
-
bl3 = al3;
|
|
5107
|
-
bl4 = al4;
|
|
5108
|
-
bl5 = al5;
|
|
5109
|
-
bl6 = al6;
|
|
5110
|
-
bl7 = al7;
|
|
5111
|
-
|
|
5112
|
-
// add
|
|
5113
|
-
h = ah7;
|
|
5114
|
-
l = al7;
|
|
5115
|
-
|
|
5116
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5117
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5118
|
-
|
|
5119
|
-
// Sigma1
|
|
5120
|
-
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
5121
|
-
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
5122
|
-
|
|
5123
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5124
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5125
|
-
|
|
5126
|
-
// Ch
|
|
5127
|
-
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
5128
|
-
l = (al4 & al5) ^ (~al4 & al6);
|
|
5129
|
-
|
|
5130
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5131
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5132
|
-
|
|
5133
|
-
// K
|
|
5134
|
-
h = K[i*2];
|
|
5135
|
-
l = K[i*2+1];
|
|
5136
|
-
|
|
5137
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5138
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5139
|
-
|
|
5140
|
-
// w
|
|
5141
|
-
h = wh[i%16];
|
|
5142
|
-
l = wl[i%16];
|
|
5143
|
-
|
|
5144
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5145
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5146
|
-
|
|
5147
|
-
b += a >>> 16;
|
|
5148
|
-
c += b >>> 16;
|
|
5149
|
-
d += c >>> 16;
|
|
5150
|
-
|
|
5151
|
-
th = c & 0xffff | d << 16;
|
|
5152
|
-
tl = a & 0xffff | b << 16;
|
|
5153
|
-
|
|
5154
|
-
// add
|
|
5155
|
-
h = th;
|
|
5156
|
-
l = tl;
|
|
5157
|
-
|
|
5158
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5159
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5160
|
-
|
|
5161
|
-
// Sigma0
|
|
5162
|
-
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
5163
|
-
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
5164
|
-
|
|
5165
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5166
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5167
|
-
|
|
5168
|
-
// Maj
|
|
5169
|
-
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
5170
|
-
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
5171
|
-
|
|
5172
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5173
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5174
|
-
|
|
5175
|
-
b += a >>> 16;
|
|
5176
|
-
c += b >>> 16;
|
|
5177
|
-
d += c >>> 16;
|
|
5178
|
-
|
|
5179
|
-
bh7 = (c & 0xffff) | (d << 16);
|
|
5180
|
-
bl7 = (a & 0xffff) | (b << 16);
|
|
5181
|
-
|
|
5182
|
-
// add
|
|
5183
|
-
h = bh3;
|
|
5184
|
-
l = bl3;
|
|
5185
|
-
|
|
5186
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5187
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5188
|
-
|
|
5189
|
-
h = th;
|
|
5190
|
-
l = tl;
|
|
5191
|
-
|
|
5192
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5193
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5194
|
-
|
|
5195
|
-
b += a >>> 16;
|
|
5196
|
-
c += b >>> 16;
|
|
5197
|
-
d += c >>> 16;
|
|
5198
|
-
|
|
5199
|
-
bh3 = (c & 0xffff) | (d << 16);
|
|
5200
|
-
bl3 = (a & 0xffff) | (b << 16);
|
|
5201
|
-
|
|
5202
|
-
ah1 = bh0;
|
|
5203
|
-
ah2 = bh1;
|
|
5204
|
-
ah3 = bh2;
|
|
5205
|
-
ah4 = bh3;
|
|
5206
|
-
ah5 = bh4;
|
|
5207
|
-
ah6 = bh5;
|
|
5208
|
-
ah7 = bh6;
|
|
5209
|
-
ah0 = bh7;
|
|
5210
|
-
|
|
5211
|
-
al1 = bl0;
|
|
5212
|
-
al2 = bl1;
|
|
5213
|
-
al3 = bl2;
|
|
5214
|
-
al4 = bl3;
|
|
5215
|
-
al5 = bl4;
|
|
5216
|
-
al6 = bl5;
|
|
5217
|
-
al7 = bl6;
|
|
5218
|
-
al0 = bl7;
|
|
5219
|
-
|
|
5220
|
-
if (i%16 === 15) {
|
|
5221
|
-
for (j = 0; j < 16; j++) {
|
|
5222
|
-
// add
|
|
5223
|
-
h = wh[j];
|
|
5224
|
-
l = wl[j];
|
|
5225
|
-
|
|
5226
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5227
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5228
|
-
|
|
5229
|
-
h = wh[(j+9)%16];
|
|
5230
|
-
l = wl[(j+9)%16];
|
|
5231
|
-
|
|
5232
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5233
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5234
|
-
|
|
5235
|
-
// sigma0
|
|
5236
|
-
th = wh[(j+1)%16];
|
|
5237
|
-
tl = wl[(j+1)%16];
|
|
5238
|
-
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
5239
|
-
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
5240
|
-
|
|
5241
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5242
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5243
|
-
|
|
5244
|
-
// sigma1
|
|
5245
|
-
th = wh[(j+14)%16];
|
|
5246
|
-
tl = wl[(j+14)%16];
|
|
5247
|
-
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
5248
|
-
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
5249
|
-
|
|
5250
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5251
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5252
|
-
|
|
5253
|
-
b += a >>> 16;
|
|
5254
|
-
c += b >>> 16;
|
|
5255
|
-
d += c >>> 16;
|
|
5256
|
-
|
|
5257
|
-
wh[j] = (c & 0xffff) | (d << 16);
|
|
5258
|
-
wl[j] = (a & 0xffff) | (b << 16);
|
|
5259
|
-
}
|
|
5260
|
-
}
|
|
5261
|
-
}
|
|
5262
|
-
|
|
5263
|
-
// add
|
|
5264
|
-
h = ah0;
|
|
5265
|
-
l = al0;
|
|
5266
|
-
|
|
5267
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5268
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5269
|
-
|
|
5270
|
-
h = hh[0];
|
|
5271
|
-
l = hl[0];
|
|
5272
|
-
|
|
5273
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5274
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5275
|
-
|
|
5276
|
-
b += a >>> 16;
|
|
5277
|
-
c += b >>> 16;
|
|
5278
|
-
d += c >>> 16;
|
|
5279
|
-
|
|
5280
|
-
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
5281
|
-
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
5282
|
-
|
|
5283
|
-
h = ah1;
|
|
5284
|
-
l = al1;
|
|
5285
|
-
|
|
5286
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5287
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5288
|
-
|
|
5289
|
-
h = hh[1];
|
|
5290
|
-
l = hl[1];
|
|
5291
|
-
|
|
5292
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5293
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5294
|
-
|
|
5295
|
-
b += a >>> 16;
|
|
5296
|
-
c += b >>> 16;
|
|
5297
|
-
d += c >>> 16;
|
|
5298
|
-
|
|
5299
|
-
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
5300
|
-
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
5301
|
-
|
|
5302
|
-
h = ah2;
|
|
5303
|
-
l = al2;
|
|
5304
|
-
|
|
5305
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5306
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5307
|
-
|
|
5308
|
-
h = hh[2];
|
|
5309
|
-
l = hl[2];
|
|
5310
|
-
|
|
5311
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5312
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5313
|
-
|
|
5314
|
-
b += a >>> 16;
|
|
5315
|
-
c += b >>> 16;
|
|
5316
|
-
d += c >>> 16;
|
|
5317
|
-
|
|
5318
|
-
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
5319
|
-
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
5320
|
-
|
|
5321
|
-
h = ah3;
|
|
5322
|
-
l = al3;
|
|
5323
|
-
|
|
5324
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5325
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5326
|
-
|
|
5327
|
-
h = hh[3];
|
|
5328
|
-
l = hl[3];
|
|
5329
|
-
|
|
5330
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5331
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5332
|
-
|
|
5333
|
-
b += a >>> 16;
|
|
5334
|
-
c += b >>> 16;
|
|
5335
|
-
d += c >>> 16;
|
|
5336
|
-
|
|
5337
|
-
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
5338
|
-
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
5339
|
-
|
|
5340
|
-
h = ah4;
|
|
5341
|
-
l = al4;
|
|
5342
|
-
|
|
5343
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5344
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5345
|
-
|
|
5346
|
-
h = hh[4];
|
|
5347
|
-
l = hl[4];
|
|
5348
|
-
|
|
5349
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5350
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5351
|
-
|
|
5352
|
-
b += a >>> 16;
|
|
5353
|
-
c += b >>> 16;
|
|
5354
|
-
d += c >>> 16;
|
|
5355
|
-
|
|
5356
|
-
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
5357
|
-
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
5358
|
-
|
|
5359
|
-
h = ah5;
|
|
5360
|
-
l = al5;
|
|
5361
|
-
|
|
5362
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5363
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5364
|
-
|
|
5365
|
-
h = hh[5];
|
|
5366
|
-
l = hl[5];
|
|
5367
|
-
|
|
5368
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5369
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5370
|
-
|
|
5371
|
-
b += a >>> 16;
|
|
5372
|
-
c += b >>> 16;
|
|
5373
|
-
d += c >>> 16;
|
|
5374
|
-
|
|
5375
|
-
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
5376
|
-
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
5377
|
-
|
|
5378
|
-
h = ah6;
|
|
5379
|
-
l = al6;
|
|
5380
|
-
|
|
5381
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5382
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5383
|
-
|
|
5384
|
-
h = hh[6];
|
|
5385
|
-
l = hl[6];
|
|
5386
|
-
|
|
5387
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5388
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5389
|
-
|
|
5390
|
-
b += a >>> 16;
|
|
5391
|
-
c += b >>> 16;
|
|
5392
|
-
d += c >>> 16;
|
|
5393
|
-
|
|
5394
|
-
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
5395
|
-
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
5396
|
-
|
|
5397
|
-
h = ah7;
|
|
5398
|
-
l = al7;
|
|
5399
|
-
|
|
5400
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5401
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5402
|
-
|
|
5403
|
-
h = hh[7];
|
|
5404
|
-
l = hl[7];
|
|
5405
|
-
|
|
5406
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5407
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5408
|
-
|
|
5409
|
-
b += a >>> 16;
|
|
5410
|
-
c += b >>> 16;
|
|
5411
|
-
d += c >>> 16;
|
|
5412
|
-
|
|
5413
|
-
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
5414
|
-
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
5415
|
-
|
|
5416
|
-
pos += 128;
|
|
5417
|
-
n -= 128;
|
|
5418
|
-
}
|
|
5419
|
-
|
|
5420
|
-
return n;
|
|
5421
|
-
}
|
|
5422
|
-
|
|
5423
|
-
function crypto_hash(out, m, n) {
|
|
5424
|
-
var hh = new Int32Array(8),
|
|
5425
|
-
hl = new Int32Array(8),
|
|
5426
|
-
x = new Uint8Array(256),
|
|
5427
|
-
i, b = n;
|
|
5428
|
-
|
|
5429
|
-
hh[0] = 0x6a09e667;
|
|
5430
|
-
hh[1] = 0xbb67ae85;
|
|
5431
|
-
hh[2] = 0x3c6ef372;
|
|
5432
|
-
hh[3] = 0xa54ff53a;
|
|
5433
|
-
hh[4] = 0x510e527f;
|
|
5434
|
-
hh[5] = 0x9b05688c;
|
|
5435
|
-
hh[6] = 0x1f83d9ab;
|
|
5436
|
-
hh[7] = 0x5be0cd19;
|
|
5437
|
-
|
|
5438
|
-
hl[0] = 0xf3bcc908;
|
|
5439
|
-
hl[1] = 0x84caa73b;
|
|
5440
|
-
hl[2] = 0xfe94f82b;
|
|
5441
|
-
hl[3] = 0x5f1d36f1;
|
|
5442
|
-
hl[4] = 0xade682d1;
|
|
5443
|
-
hl[5] = 0x2b3e6c1f;
|
|
5444
|
-
hl[6] = 0xfb41bd6b;
|
|
5445
|
-
hl[7] = 0x137e2179;
|
|
5446
|
-
|
|
5447
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
5448
|
-
n %= 128;
|
|
5449
|
-
|
|
5450
|
-
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
5451
|
-
x[n] = 128;
|
|
5452
|
-
|
|
5453
|
-
n = 256-128*(n<112?1:0);
|
|
5454
|
-
x[n-9] = 0;
|
|
5455
|
-
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
5456
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
5457
|
-
|
|
5458
|
-
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
5459
|
-
|
|
5460
|
-
return 0;
|
|
5461
|
-
}
|
|
5462
|
-
|
|
5463
|
-
function add(p, q) {
|
|
5464
|
-
var a = gf(), b = gf(), c = gf(),
|
|
5465
|
-
d = gf(), e = gf(), f = gf(),
|
|
5466
|
-
g = gf(), h = gf(), t = gf();
|
|
5467
|
-
|
|
5468
|
-
Z(a, p[1], p[0]);
|
|
5469
|
-
Z(t, q[1], q[0]);
|
|
5470
|
-
M(a, a, t);
|
|
5471
|
-
A(b, p[0], p[1]);
|
|
5472
|
-
A(t, q[0], q[1]);
|
|
5473
|
-
M(b, b, t);
|
|
5474
|
-
M(c, p[3], q[3]);
|
|
5475
|
-
M(c, c, D2);
|
|
5476
|
-
M(d, p[2], q[2]);
|
|
5477
|
-
A(d, d, d);
|
|
5478
|
-
Z(e, b, a);
|
|
5479
|
-
Z(f, d, c);
|
|
5480
|
-
A(g, d, c);
|
|
5481
|
-
A(h, b, a);
|
|
5482
|
-
|
|
5483
|
-
M(p[0], e, f);
|
|
5484
|
-
M(p[1], h, g);
|
|
5485
|
-
M(p[2], g, f);
|
|
5486
|
-
M(p[3], e, h);
|
|
5487
|
-
}
|
|
5488
|
-
|
|
5489
|
-
function cswap(p, q, b) {
|
|
5490
|
-
var i;
|
|
5491
|
-
for (i = 0; i < 4; i++) {
|
|
5492
|
-
sel25519(p[i], q[i], b);
|
|
5493
|
-
}
|
|
5494
|
-
}
|
|
5495
|
-
|
|
5496
|
-
function pack(r, p) {
|
|
5497
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
5498
|
-
inv25519(zi, p[2]);
|
|
5499
|
-
M(tx, p[0], zi);
|
|
5500
|
-
M(ty, p[1], zi);
|
|
5501
|
-
pack25519(r, ty);
|
|
5502
|
-
r[31] ^= par25519(tx) << 7;
|
|
5503
|
-
}
|
|
5504
|
-
|
|
5505
|
-
function scalarmult(p, q, s) {
|
|
5506
|
-
var b, i;
|
|
5507
|
-
set25519(p[0], gf0);
|
|
5508
|
-
set25519(p[1], gf1);
|
|
5509
|
-
set25519(p[2], gf1);
|
|
5510
|
-
set25519(p[3], gf0);
|
|
5511
|
-
for (i = 255; i >= 0; --i) {
|
|
5512
|
-
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
5513
|
-
cswap(p, q, b);
|
|
5514
|
-
add(q, p);
|
|
5515
|
-
add(p, p);
|
|
5516
|
-
cswap(p, q, b);
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
|
|
5520
|
-
function scalarbase(p, s) {
|
|
5521
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
5522
|
-
set25519(q[0], X);
|
|
5523
|
-
set25519(q[1], Y);
|
|
5524
|
-
set25519(q[2], gf1);
|
|
5525
|
-
M(q[3], X, Y);
|
|
5526
|
-
scalarmult(p, q, s);
|
|
5527
|
-
}
|
|
5528
|
-
|
|
5529
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
5530
|
-
var d = new Uint8Array(64);
|
|
5531
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
5532
|
-
var i;
|
|
5533
|
-
|
|
5534
|
-
if (!seeded) randombytes(sk, 32);
|
|
5535
|
-
crypto_hash(d, sk, 32);
|
|
5536
|
-
d[0] &= 248;
|
|
5537
|
-
d[31] &= 127;
|
|
5538
|
-
d[31] |= 64;
|
|
5539
|
-
|
|
5540
|
-
scalarbase(p, d);
|
|
5541
|
-
pack(pk, p);
|
|
5542
|
-
|
|
5543
|
-
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
5544
|
-
return 0;
|
|
5545
|
-
}
|
|
5546
|
-
|
|
5547
|
-
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]);
|
|
5548
|
-
|
|
5549
|
-
function modL(r, x) {
|
|
5550
|
-
var carry, i, j, k;
|
|
5551
|
-
for (i = 63; i >= 32; --i) {
|
|
5552
|
-
carry = 0;
|
|
5553
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
5554
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
5555
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
5556
|
-
x[j] -= carry * 256;
|
|
5557
|
-
}
|
|
5558
|
-
x[j] += carry;
|
|
5559
|
-
x[i] = 0;
|
|
5560
|
-
}
|
|
5561
|
-
carry = 0;
|
|
5562
|
-
for (j = 0; j < 32; j++) {
|
|
5563
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
5564
|
-
carry = x[j] >> 8;
|
|
5565
|
-
x[j] &= 255;
|
|
5566
|
-
}
|
|
5567
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
5568
|
-
for (i = 0; i < 32; i++) {
|
|
5569
|
-
x[i+1] += x[i] >> 8;
|
|
5570
|
-
r[i] = x[i] & 255;
|
|
5571
|
-
}
|
|
5572
|
-
}
|
|
5573
|
-
|
|
5574
|
-
function reduce(r) {
|
|
5575
|
-
var x = new Float64Array(64), i;
|
|
5576
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
5577
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
5578
|
-
modL(r, x);
|
|
5579
|
-
}
|
|
5580
|
-
|
|
5581
|
-
// Note: difference from C - smlen returned, not passed as argument.
|
|
5582
|
-
function crypto_sign(sm, m, n, sk) {
|
|
5583
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
5584
|
-
var i, j, x = new Float64Array(64);
|
|
5585
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
5586
|
-
|
|
5587
|
-
crypto_hash(d, sk, 32);
|
|
5588
|
-
d[0] &= 248;
|
|
5589
|
-
d[31] &= 127;
|
|
5590
|
-
d[31] |= 64;
|
|
5591
|
-
|
|
5592
|
-
var smlen = n + 64;
|
|
5593
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
5594
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
5595
|
-
|
|
5596
|
-
crypto_hash(r, sm.subarray(32), n+32);
|
|
5597
|
-
reduce(r);
|
|
5598
|
-
scalarbase(p, r);
|
|
5599
|
-
pack(sm, p);
|
|
5600
|
-
|
|
5601
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
5602
|
-
crypto_hash(h, sm, n + 64);
|
|
5603
|
-
reduce(h);
|
|
5604
|
-
|
|
5605
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
5606
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
5607
|
-
for (i = 0; i < 32; i++) {
|
|
5608
|
-
for (j = 0; j < 32; j++) {
|
|
5609
|
-
x[i+j] += h[i] * d[j];
|
|
5610
|
-
}
|
|
5611
|
-
}
|
|
5612
|
-
|
|
5613
|
-
modL(sm.subarray(32), x);
|
|
5614
|
-
return smlen;
|
|
5615
|
-
}
|
|
5616
|
-
|
|
5617
|
-
function unpackneg(r, p) {
|
|
5618
|
-
var t = gf(), chk = gf(), num = gf(),
|
|
5619
|
-
den = gf(), den2 = gf(), den4 = gf(),
|
|
5620
|
-
den6 = gf();
|
|
5621
|
-
|
|
5622
|
-
set25519(r[2], gf1);
|
|
5623
|
-
unpack25519(r[1], p);
|
|
5624
|
-
S(num, r[1]);
|
|
5625
|
-
M(den, num, D);
|
|
5626
|
-
Z(num, num, r[2]);
|
|
5627
|
-
A(den, r[2], den);
|
|
5628
|
-
|
|
5629
|
-
S(den2, den);
|
|
5630
|
-
S(den4, den2);
|
|
5631
|
-
M(den6, den4, den2);
|
|
5632
|
-
M(t, den6, num);
|
|
5633
|
-
M(t, t, den);
|
|
5634
|
-
|
|
5635
|
-
pow2523(t, t);
|
|
5636
|
-
M(t, t, num);
|
|
5637
|
-
M(t, t, den);
|
|
5638
|
-
M(t, t, den);
|
|
5639
|
-
M(r[0], t, den);
|
|
5640
|
-
|
|
5641
|
-
S(chk, r[0]);
|
|
5642
|
-
M(chk, chk, den);
|
|
5643
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
5644
|
-
|
|
5645
|
-
S(chk, r[0]);
|
|
5646
|
-
M(chk, chk, den);
|
|
5647
|
-
if (neq25519(chk, num)) return -1;
|
|
5648
|
-
|
|
5649
|
-
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
5650
|
-
|
|
5651
|
-
M(r[3], r[0], r[1]);
|
|
5652
|
-
return 0;
|
|
5653
|
-
}
|
|
5654
|
-
|
|
5655
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
5656
|
-
var i;
|
|
5657
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
5658
|
-
var p = [gf(), gf(), gf(), gf()],
|
|
5659
|
-
q = [gf(), gf(), gf(), gf()];
|
|
5660
|
-
|
|
5661
|
-
if (n < 64) return -1;
|
|
5662
|
-
|
|
5663
|
-
if (unpackneg(q, pk)) return -1;
|
|
5664
|
-
|
|
5665
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
5666
|
-
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
5667
|
-
crypto_hash(h, m, n);
|
|
5668
|
-
reduce(h);
|
|
5669
|
-
scalarmult(p, q, h);
|
|
5670
|
-
|
|
5671
|
-
scalarbase(q, sm.subarray(32));
|
|
5672
|
-
add(p, q);
|
|
5673
|
-
pack(t, p);
|
|
5674
|
-
|
|
5675
|
-
n -= 64;
|
|
5676
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
5677
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
5678
|
-
return -1;
|
|
5679
|
-
}
|
|
5680
|
-
|
|
5681
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
5682
|
-
return n;
|
|
5683
|
-
}
|
|
5684
|
-
|
|
5685
|
-
var crypto_secretbox_KEYBYTES = 32,
|
|
5686
|
-
crypto_secretbox_NONCEBYTES = 24,
|
|
5687
|
-
crypto_secretbox_ZEROBYTES = 32,
|
|
5688
|
-
crypto_secretbox_BOXZEROBYTES = 16,
|
|
5689
|
-
crypto_scalarmult_BYTES = 32,
|
|
5690
|
-
crypto_scalarmult_SCALARBYTES = 32,
|
|
5691
|
-
crypto_box_PUBLICKEYBYTES = 32,
|
|
5692
|
-
crypto_box_SECRETKEYBYTES = 32,
|
|
5693
|
-
crypto_box_BEFORENMBYTES = 32,
|
|
5694
|
-
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
5695
|
-
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
5696
|
-
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
5697
|
-
crypto_sign_BYTES = 64,
|
|
5698
|
-
crypto_sign_PUBLICKEYBYTES = 32,
|
|
5699
|
-
crypto_sign_SECRETKEYBYTES = 64,
|
|
5700
|
-
crypto_sign_SEEDBYTES = 32,
|
|
5701
|
-
crypto_hash_BYTES = 64;
|
|
5702
|
-
|
|
5703
|
-
nacl.lowlevel = {
|
|
5704
|
-
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
5705
|
-
crypto_stream_xor: crypto_stream_xor,
|
|
5706
|
-
crypto_stream: crypto_stream,
|
|
5707
|
-
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
5708
|
-
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
5709
|
-
crypto_onetimeauth: crypto_onetimeauth,
|
|
5710
|
-
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
5711
|
-
crypto_verify_16: crypto_verify_16,
|
|
5712
|
-
crypto_verify_32: crypto_verify_32,
|
|
5713
|
-
crypto_secretbox: crypto_secretbox,
|
|
5714
|
-
crypto_secretbox_open: crypto_secretbox_open,
|
|
5715
|
-
crypto_scalarmult: crypto_scalarmult,
|
|
5716
|
-
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
5717
|
-
crypto_box_beforenm: crypto_box_beforenm,
|
|
5718
|
-
crypto_box_afternm: crypto_box_afternm,
|
|
5719
|
-
crypto_box: crypto_box,
|
|
5720
|
-
crypto_box_open: crypto_box_open,
|
|
5721
|
-
crypto_box_keypair: crypto_box_keypair,
|
|
5722
|
-
crypto_hash: crypto_hash,
|
|
5723
|
-
crypto_sign: crypto_sign,
|
|
5724
|
-
crypto_sign_keypair: crypto_sign_keypair,
|
|
5725
|
-
crypto_sign_open: crypto_sign_open,
|
|
5726
|
-
|
|
5727
|
-
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
5728
|
-
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
5729
|
-
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
5730
|
-
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
5731
|
-
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
5732
|
-
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
5733
|
-
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
5734
|
-
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
5735
|
-
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
5736
|
-
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
5737
|
-
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
5738
|
-
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
5739
|
-
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
5740
|
-
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
5741
|
-
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
5742
|
-
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
5743
|
-
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
5744
|
-
|
|
5745
|
-
gf: gf,
|
|
5746
|
-
D: D,
|
|
5747
|
-
L: L,
|
|
5748
|
-
pack25519: pack25519,
|
|
5749
|
-
unpack25519: unpack25519,
|
|
5750
|
-
M: M,
|
|
5751
|
-
A: A,
|
|
5752
|
-
S: S,
|
|
5753
|
-
Z: Z,
|
|
5754
|
-
pow2523: pow2523,
|
|
5755
|
-
add: add,
|
|
5756
|
-
set25519: set25519,
|
|
5757
|
-
modL: modL,
|
|
5758
|
-
scalarmult: scalarmult,
|
|
5759
|
-
scalarbase: scalarbase,
|
|
5760
|
-
};
|
|
5761
|
-
|
|
5762
|
-
/* High-level API */
|
|
5763
|
-
|
|
5764
|
-
function checkLengths(k, n) {
|
|
5765
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
5766
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
5767
|
-
}
|
|
5768
|
-
|
|
5769
|
-
function checkBoxLengths(pk, sk) {
|
|
5770
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
5771
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
5772
|
-
}
|
|
5773
|
-
|
|
5774
|
-
function checkArrayTypes() {
|
|
5775
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
5776
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
5777
|
-
throw new TypeError('unexpected type, use Uint8Array');
|
|
5778
|
-
}
|
|
5779
|
-
}
|
|
5780
|
-
|
|
5781
|
-
function cleanup(arr) {
|
|
5782
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
5783
|
-
}
|
|
5784
|
-
|
|
5785
|
-
nacl.randomBytes = function(n) {
|
|
5786
|
-
var b = new Uint8Array(n);
|
|
5787
|
-
randombytes(b, n);
|
|
5788
|
-
return b;
|
|
5789
|
-
};
|
|
5790
|
-
|
|
5791
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
5792
|
-
checkArrayTypes(msg, nonce, key);
|
|
5793
|
-
checkLengths(key, nonce);
|
|
5794
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
5795
|
-
var c = new Uint8Array(m.length);
|
|
5796
|
-
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
5797
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
5798
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
5799
|
-
};
|
|
5800
|
-
|
|
5801
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
5802
|
-
checkArrayTypes(box, nonce, key);
|
|
5803
|
-
checkLengths(key, nonce);
|
|
5804
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
5805
|
-
var m = new Uint8Array(c.length);
|
|
5806
|
-
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
5807
|
-
if (c.length < 32) return null;
|
|
5808
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
5809
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
5810
|
-
};
|
|
5811
|
-
|
|
5812
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
5813
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
5814
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
5815
|
-
|
|
5816
|
-
nacl.scalarMult = function(n, p) {
|
|
5817
|
-
checkArrayTypes(n, p);
|
|
5818
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
5819
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
5820
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
5821
|
-
crypto_scalarmult(q, n, p);
|
|
5822
|
-
return q;
|
|
5823
|
-
};
|
|
5824
|
-
|
|
5825
|
-
nacl.scalarMult.base = function(n) {
|
|
5826
|
-
checkArrayTypes(n);
|
|
5827
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
5828
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
5829
|
-
crypto_scalarmult_base(q, n);
|
|
5830
|
-
return q;
|
|
5831
|
-
};
|
|
5832
|
-
|
|
5833
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
5834
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
5835
|
-
|
|
5836
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
5837
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
5838
|
-
return nacl.secretbox(msg, nonce, k);
|
|
5839
|
-
};
|
|
5840
|
-
|
|
5841
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
5842
|
-
checkArrayTypes(publicKey, secretKey);
|
|
5843
|
-
checkBoxLengths(publicKey, secretKey);
|
|
5844
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
5845
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
5846
|
-
return k;
|
|
5847
|
-
};
|
|
5848
|
-
|
|
5849
|
-
nacl.box.after = nacl.secretbox;
|
|
5850
|
-
|
|
5851
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
5852
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
5853
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
5854
|
-
};
|
|
5855
|
-
|
|
5856
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
5857
|
-
|
|
5858
|
-
nacl.box.keyPair = function() {
|
|
5859
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
5860
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
5861
|
-
crypto_box_keypair(pk, sk);
|
|
5862
|
-
return {publicKey: pk, secretKey: sk};
|
|
5863
|
-
};
|
|
5864
|
-
|
|
5865
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
5866
|
-
checkArrayTypes(secretKey);
|
|
5867
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
5868
|
-
throw new Error('bad secret key size');
|
|
5869
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
5870
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
5871
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
5872
|
-
};
|
|
5873
|
-
|
|
5874
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
5875
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
5876
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
5877
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
5878
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
5879
|
-
|
|
5880
|
-
nacl.sign = function(msg, secretKey) {
|
|
5881
|
-
checkArrayTypes(msg, secretKey);
|
|
5882
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
5883
|
-
throw new Error('bad secret key size');
|
|
5884
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
5885
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
5886
|
-
return signedMsg;
|
|
5887
|
-
};
|
|
5888
|
-
|
|
5889
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
5890
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
5891
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
5892
|
-
throw new Error('bad public key size');
|
|
5893
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
5894
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
5895
|
-
if (mlen < 0) return null;
|
|
5896
|
-
var m = new Uint8Array(mlen);
|
|
5897
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
5898
|
-
return m;
|
|
5899
|
-
};
|
|
5900
|
-
|
|
5901
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
5902
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
5903
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
5904
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
5905
|
-
return sig;
|
|
5906
|
-
};
|
|
5907
|
-
|
|
5908
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
5909
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
5910
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
5911
|
-
throw new Error('bad signature size');
|
|
5912
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
5913
|
-
throw new Error('bad public key size');
|
|
5914
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
5915
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
5916
|
-
var i;
|
|
5917
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
5918
|
-
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
5919
|
-
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
5920
|
-
};
|
|
5921
|
-
|
|
5922
|
-
nacl.sign.keyPair = function() {
|
|
5923
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
5924
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
5925
|
-
crypto_sign_keypair(pk, sk);
|
|
5926
|
-
return {publicKey: pk, secretKey: sk};
|
|
5927
|
-
};
|
|
5928
|
-
|
|
5929
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
5930
|
-
checkArrayTypes(secretKey);
|
|
5931
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
5932
|
-
throw new Error('bad secret key size');
|
|
5933
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
5934
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
5935
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
5936
|
-
};
|
|
5937
|
-
|
|
5938
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
5939
|
-
checkArrayTypes(seed);
|
|
5940
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
5941
|
-
throw new Error('bad seed size');
|
|
5942
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
5943
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
5944
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
5945
|
-
crypto_sign_keypair(pk, sk, true);
|
|
5946
|
-
return {publicKey: pk, secretKey: sk};
|
|
5947
|
-
};
|
|
5948
|
-
|
|
5949
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
5950
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
5951
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
5952
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
5953
|
-
|
|
5954
|
-
nacl.hash = function(msg) {
|
|
5955
|
-
checkArrayTypes(msg);
|
|
5956
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
5957
|
-
crypto_hash(h, msg, msg.length);
|
|
5958
|
-
return h;
|
|
5959
|
-
};
|
|
5960
|
-
|
|
5961
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
5962
|
-
|
|
5963
|
-
nacl.verify = function(x, y) {
|
|
5964
|
-
checkArrayTypes(x, y);
|
|
5965
|
-
// Zero length arguments are considered not equal.
|
|
5966
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
5967
|
-
if (x.length !== y.length) return false;
|
|
5968
|
-
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
5969
|
-
};
|
|
5970
|
-
|
|
5971
|
-
nacl.setPRNG = function(fn) {
|
|
5972
|
-
randombytes = fn;
|
|
5973
|
-
};
|
|
5974
|
-
|
|
5975
|
-
(function() {
|
|
5976
|
-
// Initialize PRNG if environment provides CSPRNG.
|
|
5977
|
-
// If not, methods calling randombytes will throw.
|
|
5978
|
-
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
5979
|
-
if (crypto && crypto.getRandomValues) {
|
|
5980
|
-
// Browsers.
|
|
5981
|
-
var QUOTA = 65536;
|
|
5982
|
-
nacl.setPRNG(function(x, n) {
|
|
5983
|
-
var i, v = new Uint8Array(n);
|
|
5984
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
5985
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
5986
|
-
}
|
|
5987
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
5988
|
-
cleanup(v);
|
|
5989
|
-
});
|
|
5990
|
-
} else if (typeof commonjsRequire !== 'undefined') {
|
|
5991
|
-
// Node.js.
|
|
5992
|
-
crypto = require$$0;
|
|
5993
|
-
if (crypto && crypto.randomBytes) {
|
|
5994
|
-
nacl.setPRNG(function(x, n) {
|
|
5995
|
-
var i, v = crypto.randomBytes(n);
|
|
5996
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
5997
|
-
cleanup(v);
|
|
5998
|
-
});
|
|
5999
|
-
}
|
|
6000
|
-
}
|
|
6001
|
-
})();
|
|
6002
|
-
|
|
6003
|
-
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
6004
|
-
} (naclFast));
|
|
6005
|
-
return naclFast.exports;
|
|
6006
|
-
}
|
|
6007
|
-
|
|
6008
|
-
var naclFastExports = requireNaclFast();
|
|
6009
|
-
var nacl = /*@__PURE__*/getDefaultExportFromCjs(naclFastExports);
|
|
6010
|
-
|
|
6011
3569
|
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
6012
3570
|
//
|
|
6013
3571
|
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
6014
3572
|
// Bounded account address; it signs the auth challenge exactly like a wallet.
|
|
6015
3573
|
//
|
|
6016
|
-
//
|
|
6017
|
-
//
|
|
6018
|
-
//
|
|
6019
|
-
//
|
|
6020
|
-
// 2. tweetnacl keypair in platform storage (React Native / older browsers) —
|
|
6021
|
-
// the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
|
|
6022
|
-
// treat it as a low-stakes guest identity and tell users to upgrade
|
|
6023
|
-
// (link an email) before they care about not losing it.
|
|
3574
|
+
// Guest auth has one backend: WebCrypto Ed25519 + IndexedDB. The key is
|
|
3575
|
+
// NON-EXTRACTABLE: an XSS can ask it to sign but can never read the private
|
|
3576
|
+
// bytes. If WebCrypto or IndexedDB is unavailable, guest auth fails closed
|
|
3577
|
+
// instead of silently creating an extractable/stored-secret credential.
|
|
6024
3578
|
//
|
|
6025
|
-
//
|
|
3579
|
+
// The public output is a base58 address + a base64
|
|
6026
3580
|
// detached signature, which is the format the session endpoint already accepts.
|
|
6027
|
-
const
|
|
3581
|
+
const LEGACY_STORED_SECRET_KEY = 'bounded_guest_key_v1';
|
|
6028
3582
|
const IDB_NAME = 'bounded-guest';
|
|
6029
3583
|
const IDB_STORE = 'keys';
|
|
6030
3584
|
const IDB_KEY = 'ed25519';
|
|
3585
|
+
const GUEST_KEY_REQUIREMENT = 'Guest auth requires non-extractable WebCrypto Ed25519 keys persisted in IndexedDB; ' +
|
|
3586
|
+
'stored-secret guest credentials are disabled.';
|
|
6031
3587
|
function toBase64(bytes) {
|
|
6032
3588
|
let bin = '';
|
|
6033
3589
|
for (let i = 0; i < bytes.length; i++)
|
|
@@ -6062,10 +3618,17 @@ function idbPut(db, key, val) {
|
|
|
6062
3618
|
r.onerror = () => reject(r.error);
|
|
6063
3619
|
});
|
|
6064
3620
|
}
|
|
6065
|
-
|
|
3621
|
+
function guestKeyUnavailable(cause) {
|
|
3622
|
+
const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';
|
|
3623
|
+
return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);
|
|
3624
|
+
}
|
|
3625
|
+
async function webCryptoKey() {
|
|
6066
3626
|
const s = subtle();
|
|
6067
|
-
if (!s
|
|
6068
|
-
|
|
3627
|
+
if (!s)
|
|
3628
|
+
throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));
|
|
3629
|
+
if (typeof globalThis.indexedDB === 'undefined') {
|
|
3630
|
+
throw guestKeyUnavailable(new Error('IndexedDB is unavailable.'));
|
|
3631
|
+
}
|
|
6069
3632
|
try {
|
|
6070
3633
|
const db = await idb();
|
|
6071
3634
|
let pair = (await idbGet(db, IDB_KEY));
|
|
@@ -6089,49 +3652,23 @@ async function tryWebCrypto() {
|
|
|
6089
3652
|
},
|
|
6090
3653
|
};
|
|
6091
3654
|
}
|
|
6092
|
-
catch (
|
|
6093
|
-
|
|
6094
|
-
}
|
|
6095
|
-
}
|
|
6096
|
-
// ----- tweetnacl (stored-secret) fallback ------------------------------------
|
|
6097
|
-
function fallbackKey() {
|
|
6098
|
-
const store = getPlatform().storage;
|
|
6099
|
-
let secret;
|
|
6100
|
-
const saved = store.getItem(FALLBACK_STORE_KEY);
|
|
6101
|
-
if (saved) {
|
|
6102
|
-
secret = bs58.decode(saved);
|
|
6103
|
-
}
|
|
6104
|
-
else {
|
|
6105
|
-
const kp = Keypair.generate();
|
|
6106
|
-
secret = kp.secretKey; // 64 bytes
|
|
6107
|
-
store.setItem(FALLBACK_STORE_KEY, bs58.encode(secret));
|
|
3655
|
+
catch (error) {
|
|
3656
|
+
throw guestKeyUnavailable(error);
|
|
6108
3657
|
}
|
|
6109
|
-
const kp = Keypair.fromSecretKey(secret);
|
|
6110
|
-
const address = kp.publicKey.toBase58();
|
|
6111
|
-
return {
|
|
6112
|
-
address,
|
|
6113
|
-
nonExtractable: false,
|
|
6114
|
-
async sign(message) {
|
|
6115
|
-
const data = new TextEncoder().encode(message);
|
|
6116
|
-
const sig = nacl.sign.detached(data, secret);
|
|
6117
|
-
return toBase64(sig);
|
|
6118
|
-
},
|
|
6119
|
-
};
|
|
6120
3658
|
}
|
|
6121
3659
|
let cached = null;
|
|
6122
3660
|
/** Get (or create) this device's durable guest key. */
|
|
6123
3661
|
async function getGuestKey() {
|
|
6124
|
-
var _a;
|
|
6125
3662
|
if (cached)
|
|
6126
3663
|
return cached;
|
|
6127
|
-
cached =
|
|
3664
|
+
cached = await webCryptoKey();
|
|
6128
3665
|
return cached;
|
|
6129
3666
|
}
|
|
6130
3667
|
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
6131
3668
|
async function clearGuestKey() {
|
|
6132
3669
|
cached = null;
|
|
6133
3670
|
try {
|
|
6134
|
-
getPlatform().storage.removeItem(
|
|
3671
|
+
getPlatform().storage.removeItem(LEGACY_STORED_SECRET_KEY);
|
|
6135
3672
|
}
|
|
6136
3673
|
catch (_a) { }
|
|
6137
3674
|
try {
|
|
@@ -6673,6 +4210,50 @@ const MODAL_CSS = `
|
|
|
6673
4210
|
#bounded-auth-modal .hidden{display:none;}
|
|
6674
4211
|
@media (max-width:480px){#bounded-auth-modal .ba-card{max-width:none;border-radius:16px;}}`;
|
|
6675
4212
|
|
|
4213
|
+
const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
4214
|
+
const SUPPORTED_SOLANA_NETWORKS = new Set([
|
|
4215
|
+
"solana_devnet",
|
|
4216
|
+
"solana_mainnet",
|
|
4217
|
+
"surfnet",
|
|
4218
|
+
]);
|
|
4219
|
+
function normalizeSolanaRpcUrl(rpcUrl) {
|
|
4220
|
+
if (typeof rpcUrl !== "string")
|
|
4221
|
+
return null;
|
|
4222
|
+
const trimmed = rpcUrl.trim();
|
|
4223
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
4224
|
+
}
|
|
4225
|
+
function isSupportedSolanaRpcNetwork(network) {
|
|
4226
|
+
return typeof network === "string" && SUPPORTED_SOLANA_NETWORKS.has(network);
|
|
4227
|
+
}
|
|
4228
|
+
function resolveSolanaWalletStandardChain(network, context) {
|
|
4229
|
+
switch (network) {
|
|
4230
|
+
case "solana_devnet":
|
|
4231
|
+
return "solana:devnet";
|
|
4232
|
+
case "solana_mainnet":
|
|
4233
|
+
return "solana:mainnet";
|
|
4234
|
+
case "surfnet":
|
|
4235
|
+
return "solana:localnet";
|
|
4236
|
+
case undefined:
|
|
4237
|
+
case null:
|
|
4238
|
+
case "":
|
|
4239
|
+
throw new Error(`${context} requires an explicit Solana network. ` +
|
|
4240
|
+
`Provide one of: solana_devnet, solana_mainnet, surfnet.`);
|
|
4241
|
+
default:
|
|
4242
|
+
throw new Error(`${context} does not support Solana network "${network}". ` +
|
|
4243
|
+
`Expected one of: solana_devnet, solana_mainnet, surfnet.`);
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
function resolveSolanaRpcUrl(explicitRpcUrl, network, context) {
|
|
4247
|
+
if (network != null && network !== "" && !isSupportedSolanaRpcNetwork(network)) {
|
|
4248
|
+
throw new Error(`${context} does not support Solana network "${network}". ` +
|
|
4249
|
+
`Expected one of: solana_devnet, solana_mainnet, surfnet.`);
|
|
4250
|
+
}
|
|
4251
|
+
const rpcUrl = normalizeSolanaRpcUrl(explicitRpcUrl);
|
|
4252
|
+
if (rpcUrl)
|
|
4253
|
+
return rpcUrl;
|
|
4254
|
+
throw new Error(`${context} requires an explicit Solana RPC URL. Pass config.rpcUrl before signing or submitting onchain transactions.`);
|
|
4255
|
+
}
|
|
4256
|
+
|
|
6676
4257
|
const PKCE_STORE_KEY = 'bounded.oidc.pkce';
|
|
6677
4258
|
// Active session store (Web on web, RN on React Native) — selected by config,
|
|
6678
4259
|
// not by `typeof window` (truthy on RN). OIDC redirect/popup is web-only, but the
|
|
@@ -6979,7 +4560,7 @@ async function exchangeCode(code, verifier, redirectUri) {
|
|
|
6979
4560
|
let currentAuthProvider = null;
|
|
6980
4561
|
let currentAuthMethod = null;
|
|
6981
4562
|
let initConfig = null;
|
|
6982
|
-
// --- localStorage helpers: track which auth method the
|
|
4563
|
+
// --- localStorage helpers: track which auth method created the active session ---
|
|
6983
4564
|
const STORED_AUTH_METHOD_KEY$1 = 'bounded_last_auth_method';
|
|
6984
4565
|
function getStoredAuthMethod() {
|
|
6985
4566
|
try {
|
|
@@ -7003,7 +4584,7 @@ function setStoredAuthMethod(method) {
|
|
|
7003
4584
|
}
|
|
7004
4585
|
}
|
|
7005
4586
|
/**
|
|
7006
|
-
* Clears the session if it was created
|
|
4587
|
+
* Clears the session if it was created by a different auth method.
|
|
7007
4588
|
* Returns true if the session was cleared, false if the session is compatible.
|
|
7008
4589
|
*
|
|
7009
4590
|
* Dispatches to the correct session manager based on the current auth method
|
|
@@ -7011,18 +4592,17 @@ function setStoredAuthMethod(method) {
|
|
|
7011
4592
|
* are properly cleared.
|
|
7012
4593
|
*/
|
|
7013
4594
|
function clearIncompatibleSession() {
|
|
7014
|
-
if (getStoredAuthMethod()
|
|
7015
|
-
return false;
|
|
4595
|
+
if (getStoredAuthMethod() === currentAuthMethod) {
|
|
4596
|
+
return false;
|
|
7016
4597
|
}
|
|
7017
|
-
//
|
|
7018
|
-
//
|
|
7019
|
-
// Clear both managers — on web the RN manager is a no-op (not configured),
|
|
7020
|
-
// on RN the web manager is a no-op (no localStorage).
|
|
4598
|
+
// Clear both managers: on web the RN manager is a no-op (not configured),
|
|
4599
|
+
// and on RN the web manager is a no-op (no localStorage).
|
|
7021
4600
|
WebSessionManager.clearSession();
|
|
7022
4601
|
try {
|
|
7023
4602
|
ReactNativeSessionManager.clearSession();
|
|
7024
4603
|
}
|
|
7025
4604
|
catch ( /* not configured on web */_a) { /* not configured on web */ }
|
|
4605
|
+
setStoredAuthMethod(null);
|
|
7026
4606
|
return true;
|
|
7027
4607
|
}
|
|
7028
4608
|
// Lazy loaders for web-only providers.
|
|
@@ -7041,17 +4621,99 @@ async function loadSolanaMobileWalletProvider() {
|
|
|
7041
4621
|
const mod = await Promise.resolve().then(function () { return solanaMobileWalletProvider; });
|
|
7042
4622
|
return mod.SolanaMobileWalletProvider;
|
|
7043
4623
|
}
|
|
4624
|
+
function requireWebPrivyConfig(config) {
|
|
4625
|
+
if (!config.privyConfig || typeof config.privyConfig.appId !== 'string' || config.privyConfig.appId.trim() === '') {
|
|
4626
|
+
throw new Error('Privy auth requires config.privyConfig.appId; no default Privy app is used.');
|
|
4627
|
+
}
|
|
4628
|
+
if (!config.privyConfig.config || typeof config.privyConfig.config !== 'object') {
|
|
4629
|
+
throw new Error('Privy auth requires config.privyConfig.config for the app-scoped Privy provider.');
|
|
4630
|
+
}
|
|
4631
|
+
return config.privyConfig;
|
|
4632
|
+
}
|
|
4633
|
+
function getConfiguredSolanaNetwork(config) {
|
|
4634
|
+
if (typeof config.chain !== 'string')
|
|
4635
|
+
return null;
|
|
4636
|
+
const chain = config.chain.trim();
|
|
4637
|
+
if (chain === '' || chain === 'offchain')
|
|
4638
|
+
return null;
|
|
4639
|
+
return chain;
|
|
4640
|
+
}
|
|
4641
|
+
function mobileWalletClusterFromNetwork(network) {
|
|
4642
|
+
switch (network) {
|
|
4643
|
+
case "solana_devnet":
|
|
4644
|
+
return "devnet";
|
|
4645
|
+
case "solana_mainnet":
|
|
4646
|
+
return "mainnet-beta";
|
|
4647
|
+
case "surfnet":
|
|
4648
|
+
return "localnet";
|
|
4649
|
+
case null:
|
|
4650
|
+
return null;
|
|
4651
|
+
default:
|
|
4652
|
+
resolveSolanaWalletStandardChain(network, "Mobile wallet auth");
|
|
4653
|
+
return null;
|
|
4654
|
+
}
|
|
4655
|
+
}
|
|
4656
|
+
function requireMobileWalletConfig(config) {
|
|
4657
|
+
var _a, _b, _c;
|
|
4658
|
+
const configuredNetwork = getConfiguredSolanaNetwork(config);
|
|
4659
|
+
const cluster = (_b = (_a = config.mobileWalletConfig) === null || _a === void 0 ? void 0 : _a.cluster) !== null && _b !== void 0 ? _b : mobileWalletClusterFromNetwork(configuredNetwork);
|
|
4660
|
+
if (!cluster) {
|
|
4661
|
+
throw new Error("Mobile wallet auth requires an explicit Solana network. " +
|
|
4662
|
+
"Pass config.chain as solana_devnet, solana_mainnet, or surfnet, " +
|
|
4663
|
+
"or pass mobileWalletConfig.cluster.");
|
|
4664
|
+
}
|
|
4665
|
+
return Object.assign(Object.assign({}, ((_c = config.mobileWalletConfig) !== null && _c !== void 0 ? _c : {})), { cluster });
|
|
4666
|
+
}
|
|
4667
|
+
function isLocalOrTestUrl(value) {
|
|
4668
|
+
if (!value)
|
|
4669
|
+
return false;
|
|
4670
|
+
try {
|
|
4671
|
+
const hostname = new URL(value).hostname.toLowerCase();
|
|
4672
|
+
return hostname === 'localhost' ||
|
|
4673
|
+
hostname === '127.0.0.1' ||
|
|
4674
|
+
hostname === '::1' ||
|
|
4675
|
+
hostname.endsWith('.localhost') ||
|
|
4676
|
+
hostname.endsWith('.test');
|
|
4677
|
+
}
|
|
4678
|
+
catch (_a) {
|
|
4679
|
+
return false;
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
function assertMockAuthLocalOnly(config) {
|
|
4683
|
+
const requiredEndpoints = [
|
|
4684
|
+
config.apiUrl,
|
|
4685
|
+
config.wsApiUrl,
|
|
4686
|
+
config.authApiUrl,
|
|
4687
|
+
];
|
|
4688
|
+
const optionalEndpoints = [
|
|
4689
|
+
config.rpcUrl,
|
|
4690
|
+
config.humanAuthApiUrl,
|
|
4691
|
+
config.functionsUrl,
|
|
4692
|
+
].filter((value) => typeof value === 'string' && value.trim() !== '');
|
|
4693
|
+
if (requiredEndpoints.every(isLocalOrTestUrl) && optionalEndpoints.every(isLocalOrTestUrl)) {
|
|
4694
|
+
return;
|
|
4695
|
+
}
|
|
4696
|
+
throw new Error("mockAuth is local/test-only. Pass explicit localhost/.test apiUrl, wsApiUrl, and authApiUrl values; " +
|
|
4697
|
+
"mockAuth cannot be used with Bounded production or staging endpoints.");
|
|
4698
|
+
}
|
|
7044
4699
|
async function hotSwapToMWAProvider(config) {
|
|
7045
|
-
var _a
|
|
7046
|
-
const rpcUrl = (
|
|
4700
|
+
var _a;
|
|
4701
|
+
const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
|
|
4702
|
+
const configuredNetwork = getConfiguredSolanaNetwork(config);
|
|
7047
4703
|
const SolanaMobileWalletProvider = await loadSolanaMobileWalletProvider();
|
|
7048
|
-
const mwaConfig =
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
4704
|
+
const mwaConfig = config.mobileWalletConfig
|
|
4705
|
+
? requireMobileWalletConfig(config)
|
|
4706
|
+
: {
|
|
4707
|
+
appIdentity: {
|
|
4708
|
+
name: config.name || undefined,
|
|
4709
|
+
uri: getPlatform().getLocationOrigin(),
|
|
4710
|
+
},
|
|
4711
|
+
cluster: (_a = mobileWalletClusterFromNetwork(configuredNetwork)) !== null && _a !== void 0 ? _a : undefined,
|
|
4712
|
+
};
|
|
4713
|
+
if (!mwaConfig.cluster) {
|
|
4714
|
+
throw new Error("Mobile wallet auth requires config.chain or mobileWalletConfig.cluster before switching providers.");
|
|
4715
|
+
}
|
|
4716
|
+
const mwaProvider = new SolanaMobileWalletProvider(rpcUrl, mwaConfig, configuredNetwork);
|
|
7055
4717
|
let provider = mwaProvider;
|
|
7056
4718
|
if (config.chain === "offchain") {
|
|
7057
4719
|
provider = new OffchainAuthProvider(mwaProvider);
|
|
@@ -7066,11 +4728,8 @@ async function hotSwapToMWAProvider(config) {
|
|
|
7066
4728
|
setAuthProviderInstance(provider);
|
|
7067
4729
|
return provider;
|
|
7068
4730
|
}
|
|
7069
|
-
const SOLANA_DEVNET_RPC_URL = "https://idelle-8nxsep-fast-devnet.helius-rpc.com";
|
|
7070
|
-
const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
7071
|
-
const SURFNET_RPC_URL$2 = "https://surfpool.fly.dev";
|
|
7072
4731
|
async function getAuthProvider(config) {
|
|
7073
|
-
var _a, _b
|
|
4732
|
+
var _a, _b;
|
|
7074
4733
|
if (currentAuthProvider) {
|
|
7075
4734
|
return currentAuthProvider;
|
|
7076
4735
|
}
|
|
@@ -7080,21 +4739,17 @@ async function getAuthProvider(config) {
|
|
|
7080
4739
|
initConfig = config;
|
|
7081
4740
|
// If mockAuth is enabled, use MockAuthProvider regardless of authMethod
|
|
7082
4741
|
if (config.mockAuth) {
|
|
4742
|
+
assertMockAuthLocalOnly(config);
|
|
7083
4743
|
console.log("[MockAuth] Mock authentication enabled");
|
|
7084
4744
|
currentAuthProvider = new MockAuthProvider();
|
|
7085
4745
|
return currentAuthProvider;
|
|
7086
4746
|
}
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
if (storedMethod && !validAuthMethods.includes(storedMethod)) {
|
|
7094
|
-
// Invalid stored value — clear it
|
|
7095
|
-
setStoredAuthMethod(null);
|
|
7096
|
-
}
|
|
7097
|
-
const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null;
|
|
4747
|
+
const authMethod = config.authMethod;
|
|
4748
|
+
if (!authMethod) {
|
|
4749
|
+
throw new Error("authMethod is required to initialize auth provider; configure the single intended auth method explicitly.");
|
|
4750
|
+
}
|
|
4751
|
+
const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
|
|
4752
|
+
const configuredNetwork = getConfiguredSolanaNetwork(config);
|
|
7098
4753
|
currentAuthMethod = authMethod;
|
|
7099
4754
|
// Clear, actionable error when the BROWSER build (`bounded-sh`) is loaded in a
|
|
7100
4755
|
// non-browser (Node) runtime. The wallet providers below need `window`; without
|
|
@@ -7106,8 +4761,8 @@ async function getAuthProvider(config) {
|
|
|
7106
4761
|
if (typeof window === 'undefined' && browserWalletMethods.includes(authMethod)) {
|
|
7107
4762
|
throw new Error(`bounded-sh: '${authMethod}' auth requires a browser, but no \`window\` was found ` +
|
|
7108
4763
|
`(you're likely running in Node). In server/Node code, import from 'bounded-sh/server' ` +
|
|
7109
|
-
`instead of 'bounded-sh' — it signs with
|
|
7110
|
-
`
|
|
4764
|
+
`instead of 'bounded-sh' — it signs with an explicit keypair passed to createWalletClient({ keypair }) ` +
|
|
4765
|
+
`and needs no browser.`);
|
|
7111
4766
|
}
|
|
7112
4767
|
switch (authMethod) {
|
|
7113
4768
|
case "email":
|
|
@@ -7124,7 +4779,7 @@ async function getAuthProvider(config) {
|
|
|
7124
4779
|
break;
|
|
7125
4780
|
case "phantom": {
|
|
7126
4781
|
const { PhantomWalletProvider } = await loadPhantomWalletProvider();
|
|
7127
|
-
currentAuthProvider = new PhantomWalletProvider(rpcUrl, config.phantomConfig);
|
|
4782
|
+
currentAuthProvider = new PhantomWalletProvider(rpcUrl, config.phantomConfig, configuredNetwork);
|
|
7128
4783
|
// MWA hot-swap is always available (custom modal shows MWA button on Android)
|
|
7129
4784
|
currentAuthProvider.onSwitchToMWA =
|
|
7130
4785
|
() => hotSwapToMWAProvider(config);
|
|
@@ -7134,8 +4789,9 @@ async function getAuthProvider(config) {
|
|
|
7134
4789
|
// Web Privy: a co-equal login route alongside email/phantom/guest. The
|
|
7135
4790
|
// Privy embedded/external Solana wallet signs the SIWS challenge, so the
|
|
7136
4791
|
// session is minted through the same wallet path as Phantom.
|
|
4792
|
+
const privyConfig = requireWebPrivyConfig(config);
|
|
7137
4793
|
const PrivyWalletProvider = await loadPrivyWalletProvider();
|
|
7138
|
-
currentAuthProvider = new PrivyWalletProvider((
|
|
4794
|
+
currentAuthProvider = new PrivyWalletProvider((_a = config.name) !== null && _a !== void 0 ? _a : null, (_b = config.logoUrl) !== null && _b !== void 0 ? _b : null, privyConfig, rpcUrl, configuredNetwork);
|
|
7139
4795
|
break;
|
|
7140
4796
|
}
|
|
7141
4797
|
case "privy-expo":
|
|
@@ -7150,7 +4806,7 @@ async function getAuthProvider(config) {
|
|
|
7150
4806
|
break;
|
|
7151
4807
|
case "mobile-wallet-adapter": {
|
|
7152
4808
|
const SolanaMobileWalletProvider = await loadSolanaMobileWalletProvider();
|
|
7153
|
-
currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, config
|
|
4809
|
+
currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, requireMobileWalletConfig(config), configuredNetwork);
|
|
7154
4810
|
break;
|
|
7155
4811
|
}
|
|
7156
4812
|
case "onboard":
|
|
@@ -7183,7 +4839,7 @@ function assertBrowserAuthEnv(method) {
|
|
|
7183
4839
|
throw new Error(`bounded-sh: '${method}' is a browser/React-Native auth flow — it needs \`window\`/\`localStorage\` ` +
|
|
7184
4840
|
`to persist the session, which Node doesn't have (the session would be silently dropped, then every ` +
|
|
7185
4841
|
`request 403s). In Node/server code import from 'bounded-sh/server' and sign with a keypair ` +
|
|
7186
|
-
`
|
|
4842
|
+
`by using createWalletClient({ keypair }).`);
|
|
7187
4843
|
}
|
|
7188
4844
|
}
|
|
7189
4845
|
/**
|
|
@@ -7220,13 +4876,14 @@ async function signInAnonymously() {
|
|
|
7220
4876
|
* (web localStorage / RN storage) and identity model. `init()` must have run first.
|
|
7221
4877
|
*/
|
|
7222
4878
|
async function loginWithPrivy(options) {
|
|
7223
|
-
var _a, _b
|
|
4879
|
+
var _a, _b;
|
|
7224
4880
|
assertBrowserAuthEnv('loginWithPrivy');
|
|
7225
4881
|
const coreConfig = await getConfig();
|
|
7226
4882
|
let provider;
|
|
7227
4883
|
if (getPlatform().hasDOM) {
|
|
4884
|
+
const privyConfig = requireWebPrivyConfig(coreConfig);
|
|
7228
4885
|
const PrivyWalletProvider = await loadPrivyWalletProvider();
|
|
7229
|
-
provider = new PrivyWalletProvider((_a = coreConfig.name) !== null && _a !== void 0 ? _a : null, (_b = coreConfig.logoUrl) !== null && _b !== void 0 ? _b : null,
|
|
4886
|
+
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));
|
|
7230
4887
|
currentAuthMethod = 'privy';
|
|
7231
4888
|
}
|
|
7232
4889
|
else {
|
|
@@ -7372,15 +5029,13 @@ async function logout$1() {
|
|
|
7372
5029
|
throw new Error("Auth provider not initialized. Please call init() first.");
|
|
7373
5030
|
}
|
|
7374
5031
|
// Revoke the refresh-token family server-side BEFORE the provider clears the
|
|
7375
|
-
// local session (so we still have the token + issuer to revoke).
|
|
7376
|
-
//
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7381
|
-
|
|
7382
|
-
}
|
|
7383
|
-
catch ( /* proceed with local logout regardless */_b) { /* proceed with local logout regardless */ }
|
|
5032
|
+
// local session (so we still have the token + issuer to revoke). If revoke
|
|
5033
|
+
// fails, surface the error and leave local state intact so callers do not
|
|
5034
|
+
// mistake a local-only logout for server revocation.
|
|
5035
|
+
const sm = getActiveSessionManager();
|
|
5036
|
+
const refreshToken = sm.getRefreshToken();
|
|
5037
|
+
if (refreshToken)
|
|
5038
|
+
await revokeSession(refreshToken, (_a = sm.getIssuer()) !== null && _a !== void 0 ? _a : undefined);
|
|
7384
5039
|
await currentAuthProvider.logout();
|
|
7385
5040
|
setStoredAuthMethod(null);
|
|
7386
5041
|
currentAuthProvider = null;
|
|
@@ -7835,7 +5490,7 @@ class PhantomWalletProvider {
|
|
|
7835
5490
|
setLoginOverrides(opts) {
|
|
7836
5491
|
this.loginOverrides = opts;
|
|
7837
5492
|
}
|
|
7838
|
-
constructor(networkUrl = null, config = {}) {
|
|
5493
|
+
constructor(networkUrl = null, config = {}, configuredNetwork = null) {
|
|
7839
5494
|
this.containerElement = null;
|
|
7840
5495
|
this.root = null;
|
|
7841
5496
|
this.phantomMethods = null;
|
|
@@ -7848,6 +5503,7 @@ class PhantomWalletProvider {
|
|
|
7848
5503
|
/** Callback to swap to a Mobile Wallet Adapter provider when the user clicks "Connect Mobile Wallet" */
|
|
7849
5504
|
this.onSwitchToMWA = null;
|
|
7850
5505
|
this.networkUrl = networkUrl;
|
|
5506
|
+
this.configuredNetwork = configuredNetwork;
|
|
7851
5507
|
this.config = config;
|
|
7852
5508
|
if (typeof window === 'undefined') {
|
|
7853
5509
|
throw new Error('PhantomWalletProvider can only be instantiated in a browser environment');
|
|
@@ -7874,9 +5530,9 @@ class PhantomWalletProvider {
|
|
|
7874
5530
|
hasSocialProviders() {
|
|
7875
5531
|
return this.resolvedProviders.some(p => p !== 'injected');
|
|
7876
5532
|
}
|
|
7877
|
-
static getInstance(networkUrl, config) {
|
|
5533
|
+
static getInstance(networkUrl, config, configuredNetwork = null) {
|
|
7878
5534
|
if (!PhantomWalletProvider.instance) {
|
|
7879
|
-
new PhantomWalletProvider(networkUrl, config);
|
|
5535
|
+
new PhantomWalletProvider(networkUrl, config, configuredNetwork);
|
|
7880
5536
|
}
|
|
7881
5537
|
return PhantomWalletProvider.instance;
|
|
7882
5538
|
}
|
|
@@ -8778,7 +6434,7 @@ class PhantomWalletProvider {
|
|
|
8778
6434
|
}
|
|
8779
6435
|
const rpcUrl = this.getRpcUrl(solTransactionData.network);
|
|
8780
6436
|
const connection = new Connection(rpcUrl, 'confirmed');
|
|
8781
|
-
const isSurfnet = rpcUrl === SURFNET_RPC_URL
|
|
6437
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
8782
6438
|
try {
|
|
8783
6439
|
const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
|
|
8784
6440
|
const app_id = solTransactionData.appId;
|
|
@@ -9000,7 +6656,7 @@ class PhantomWalletProvider {
|
|
|
9000
6656
|
}
|
|
9001
6657
|
const rpcUrl = this.getRpcUrl();
|
|
9002
6658
|
const connection = new Connection(rpcUrl, 'confirmed');
|
|
9003
|
-
const isSurfnet = rpcUrl === SURFNET_RPC_URL
|
|
6659
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
9004
6660
|
try {
|
|
9005
6661
|
// Get fresh blockhash and set it on the transaction before signing
|
|
9006
6662
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
@@ -9133,19 +6789,7 @@ class PhantomWalletProvider {
|
|
|
9133
6789
|
* Private Helpers
|
|
9134
6790
|
* ----------------------------------------------------------- */
|
|
9135
6791
|
getRpcUrl(network) {
|
|
9136
|
-
|
|
9137
|
-
return this.networkUrl;
|
|
9138
|
-
}
|
|
9139
|
-
if (network === 'solana_devnet') {
|
|
9140
|
-
return SOLANA_DEVNET_RPC_URL;
|
|
9141
|
-
}
|
|
9142
|
-
else if (network === 'solana_mainnet') {
|
|
9143
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
9144
|
-
}
|
|
9145
|
-
else if (network === 'surfnet') {
|
|
9146
|
-
return SURFNET_RPC_URL$2;
|
|
9147
|
-
}
|
|
9148
|
-
return SOLANA_MAINNET_RPC_URL; // default to mainnet
|
|
6792
|
+
return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, "Phantom wallet Solana transaction");
|
|
9149
6793
|
}
|
|
9150
6794
|
async signAndSendViaPhantom(transaction) {
|
|
9151
6795
|
var _a, _b, _c;
|
|
@@ -9592,8 +7236,10 @@ async function signWithFreshActivation(theme, signFn, noResultError = 'MWA retur
|
|
|
9592
7236
|
* normalized to `solana:mainnet`.
|
|
9593
7237
|
*/
|
|
9594
7238
|
function mapChainToWalletStandard(input) {
|
|
9595
|
-
if (!input)
|
|
9596
|
-
|
|
7239
|
+
if (!input) {
|
|
7240
|
+
throw new Error("Solana mobile wallet auth requires an explicit cluster. " +
|
|
7241
|
+
"Pass mobileWalletConfig.cluster or config.chain.");
|
|
7242
|
+
}
|
|
9597
7243
|
let s = String(input).toLowerCase();
|
|
9598
7244
|
while (s.startsWith('solana:'))
|
|
9599
7245
|
s = s.slice('solana:'.length);
|
|
@@ -9605,7 +7251,22 @@ function mapChainToWalletStandard(input) {
|
|
|
9605
7251
|
return 'solana:testnet';
|
|
9606
7252
|
if (s === 'localnet')
|
|
9607
7253
|
return 'solana:localnet';
|
|
9608
|
-
|
|
7254
|
+
throw new Error(`Solana mobile wallet auth does not support cluster "${input}". ` +
|
|
7255
|
+
"Expected mainnet-beta, devnet, testnet, or localnet.");
|
|
7256
|
+
}
|
|
7257
|
+
function mapClusterToRpcNetwork(input) {
|
|
7258
|
+
if (!input)
|
|
7259
|
+
return null;
|
|
7260
|
+
let s = String(input).toLowerCase();
|
|
7261
|
+
while (s.startsWith('solana:'))
|
|
7262
|
+
s = s.slice('solana:'.length);
|
|
7263
|
+
if (s === 'mainnet-beta' || s === 'mainnet')
|
|
7264
|
+
return 'solana_mainnet';
|
|
7265
|
+
if (s === 'devnet')
|
|
7266
|
+
return 'solana_devnet';
|
|
7267
|
+
if (s === 'localnet')
|
|
7268
|
+
return 'surfnet';
|
|
7269
|
+
return null;
|
|
9609
7270
|
}
|
|
9610
7271
|
/**
|
|
9611
7272
|
* Serialize a Transaction/VersionedTransaction to a Uint8Array wire payload
|
|
@@ -9781,7 +7442,8 @@ async function registerMobileWalletAdapter(config) {
|
|
|
9781
7442
|
* acceptable given the alternative was broken on Seeker.
|
|
9782
7443
|
*/
|
|
9783
7444
|
class SolanaMobileWalletProvider {
|
|
9784
|
-
constructor(networkUrl = null, config = {}) {
|
|
7445
|
+
constructor(networkUrl = null, config = {}, configuredNetwork = null) {
|
|
7446
|
+
var _a;
|
|
9785
7447
|
/** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
|
|
9786
7448
|
this.wallet = null;
|
|
9787
7449
|
/**
|
|
@@ -9795,6 +7457,7 @@ class SolanaMobileWalletProvider {
|
|
|
9795
7457
|
/** Cached public key string for the connected MWA wallet (native). */
|
|
9796
7458
|
this.nativeAddress = null;
|
|
9797
7459
|
this.networkUrl = networkUrl;
|
|
7460
|
+
this.configuredNetwork = configuredNetwork;
|
|
9798
7461
|
this.config = config;
|
|
9799
7462
|
// Allow construction in true React Native environments: getPlatform().hasDOM
|
|
9800
7463
|
// is false there even though `typeof window === 'object'` (RN exposes a
|
|
@@ -9823,7 +7486,7 @@ class SolanaMobileWalletProvider {
|
|
|
9823
7486
|
name: 'Bounded App',
|
|
9824
7487
|
uri: fallbackUri,
|
|
9825
7488
|
};
|
|
9826
|
-
this.cluster = config.cluster
|
|
7489
|
+
this.cluster = (_a = config.cluster) !== null && _a !== void 0 ? _a : '';
|
|
9827
7490
|
// Hydrate cached MWA auth_token from storage on native so we can
|
|
9828
7491
|
// skip the wallet-pick popup after a cold-start when the underlying
|
|
9829
7492
|
// wallet authorization is still valid. Sync storage call per the
|
|
@@ -9840,15 +7503,15 @@ class SolanaMobileWalletProvider {
|
|
|
9840
7503
|
}
|
|
9841
7504
|
}
|
|
9842
7505
|
}
|
|
9843
|
-
catch (
|
|
7506
|
+
catch (_b) {
|
|
9844
7507
|
// Corrupt or unreadable cache — ignore. login() will re-auth.
|
|
9845
7508
|
}
|
|
9846
7509
|
}
|
|
9847
7510
|
SolanaMobileWalletProvider.instance = this;
|
|
9848
7511
|
}
|
|
9849
|
-
static getInstance(networkUrl, config) {
|
|
7512
|
+
static getInstance(networkUrl, config, configuredNetwork = null) {
|
|
9850
7513
|
if (!SolanaMobileWalletProvider.instance) {
|
|
9851
|
-
new SolanaMobileWalletProvider(networkUrl, config);
|
|
7514
|
+
new SolanaMobileWalletProvider(networkUrl, config, configuredNetwork);
|
|
9852
7515
|
}
|
|
9853
7516
|
return SolanaMobileWalletProvider.instance;
|
|
9854
7517
|
}
|
|
@@ -9903,7 +7566,13 @@ class SolanaMobileWalletProvider {
|
|
|
9903
7566
|
return wallet.accounts[0];
|
|
9904
7567
|
}
|
|
9905
7568
|
/** Returns the active wallet-standard chain identifier (e.g. 'solana:mainnet'). */
|
|
9906
|
-
getChain() {
|
|
7569
|
+
getChain(network) {
|
|
7570
|
+
if (network) {
|
|
7571
|
+
return resolveSolanaWalletStandardChain(network, "Solana mobile wallet transaction");
|
|
7572
|
+
}
|
|
7573
|
+
if (this.configuredNetwork) {
|
|
7574
|
+
return resolveSolanaWalletStandardChain(this.configuredNetwork, "Solana mobile wallet transaction");
|
|
7575
|
+
}
|
|
9907
7576
|
return mapChainToWalletStandard(this.cluster);
|
|
9908
7577
|
}
|
|
9909
7578
|
/**
|
|
@@ -10365,7 +8034,7 @@ class SolanaMobileWalletProvider {
|
|
|
10365
8034
|
const connectedPubkey = new PublicKey(this.nativeAddress);
|
|
10366
8035
|
const rpcUrl = this.getRpcUrl();
|
|
10367
8036
|
const connection = new Connection(rpcUrl, 'confirmed');
|
|
10368
|
-
const isSurfnet = rpcUrl === SURFNET_RPC_URL
|
|
8037
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
10369
8038
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
10370
8039
|
const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
|
|
10371
8040
|
if (isLegacyTransaction) {
|
|
@@ -10423,7 +8092,7 @@ class SolanaMobileWalletProvider {
|
|
|
10423
8092
|
const chain = this.getChain();
|
|
10424
8093
|
const rpcUrl = this.getRpcUrl();
|
|
10425
8094
|
const connection = new Connection(rpcUrl, 'confirmed');
|
|
10426
|
-
const isSurfnet = rpcUrl === SURFNET_RPC_URL
|
|
8095
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
10427
8096
|
try {
|
|
10428
8097
|
// Preserve existing prep: refresh blockhash and set fee payer.
|
|
10429
8098
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
|
|
@@ -10503,10 +8172,10 @@ class SolanaMobileWalletProvider {
|
|
|
10503
8172
|
const account = await this.ensureAuthorized();
|
|
10504
8173
|
const connectedPubkey = new PublicKey(account.publicKey);
|
|
10505
8174
|
const wallet = await this.ensureWallet();
|
|
10506
|
-
const chain = this.getChain();
|
|
8175
|
+
const chain = this.getChain(solTransactionData.network);
|
|
10507
8176
|
const rpcUrl = this.getRpcUrl(solTransactionData.network);
|
|
10508
8177
|
const connection = new Connection(rpcUrl, 'confirmed');
|
|
10509
|
-
const isSurfnet = rpcUrl === SURFNET_RPC_URL
|
|
8178
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
10510
8179
|
try {
|
|
10511
8180
|
const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
|
|
10512
8181
|
const app_id = solTransactionData.appId;
|
|
@@ -10682,19 +8351,8 @@ class SolanaMobileWalletProvider {
|
|
|
10682
8351
|
* Private Helpers
|
|
10683
8352
|
* ----------------------------------------------------------- */
|
|
10684
8353
|
getRpcUrl(network) {
|
|
10685
|
-
|
|
10686
|
-
|
|
10687
|
-
}
|
|
10688
|
-
if (network === 'solana_devnet') {
|
|
10689
|
-
return SOLANA_DEVNET_RPC_URL;
|
|
10690
|
-
}
|
|
10691
|
-
else if (network === 'solana_mainnet') {
|
|
10692
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
10693
|
-
}
|
|
10694
|
-
else if (network === 'surfnet') {
|
|
10695
|
-
return SURFNET_RPC_URL$2;
|
|
10696
|
-
}
|
|
10697
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
8354
|
+
var _a;
|
|
8355
|
+
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");
|
|
10698
8356
|
}
|
|
10699
8357
|
}
|
|
10700
8358
|
SolanaMobileWalletProvider.instance = null;
|
|
@@ -10706,7 +8364,6 @@ var solanaMobileWalletProvider = /*#__PURE__*/Object.freeze({
|
|
|
10706
8364
|
registerMobileWalletAdapter: registerMobileWalletAdapter
|
|
10707
8365
|
});
|
|
10708
8366
|
|
|
10709
|
-
const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
|
|
10710
8367
|
// @privy-io/react-auth(/solana) are OPTIONAL peer deps. They are loaded lazily
|
|
10711
8368
|
// via dynamic import() rather than a static top-level import: a static import
|
|
10712
8369
|
// would (a) in the ESM bundle still be a bare `import` the consumer resolves —
|
|
@@ -10739,31 +8396,28 @@ async function loadSolanaKit() {
|
|
|
10739
8396
|
}
|
|
10740
8397
|
return solanaKit;
|
|
10741
8398
|
}
|
|
10742
|
-
|
|
10743
|
-
appId
|
|
10744
|
-
|
|
10745
|
-
embeddedWallets: {
|
|
10746
|
-
solana: {
|
|
10747
|
-
createOnLogin: "users-without-wallets"
|
|
10748
|
-
}
|
|
10749
|
-
},
|
|
10750
|
-
appearance: {
|
|
10751
|
-
walletChainType: 'solana-only'
|
|
10752
|
-
},
|
|
10753
|
-
externalWallets: { solana: { connectors: privySolana.toSolanaWalletConnectors() } }
|
|
8399
|
+
function requirePrivyWalletConfig(privyConfig) {
|
|
8400
|
+
if (!privyConfig || typeof privyConfig.appId !== 'string' || privyConfig.appId.trim() === '') {
|
|
8401
|
+
throw new Error('Privy auth requires config.privyConfig.appId; no default Privy app is used.');
|
|
10754
8402
|
}
|
|
10755
|
-
|
|
8403
|
+
if (!privyConfig.config || typeof privyConfig.config !== 'object') {
|
|
8404
|
+
throw new Error('Privy auth requires config.privyConfig.config for the app-scoped Privy provider.');
|
|
8405
|
+
}
|
|
8406
|
+
return {
|
|
8407
|
+
appId: privyConfig.appId,
|
|
8408
|
+
config: privyConfig.config,
|
|
8409
|
+
};
|
|
8410
|
+
}
|
|
10756
8411
|
class PrivyWalletProvider {
|
|
10757
|
-
constructor(appName, appLogoUrl, privyConfig, networkUrl = null) {
|
|
8412
|
+
constructor(appName, appLogoUrl, privyConfig, networkUrl = null, configuredNetwork = null) {
|
|
10758
8413
|
this.containerElement = null;
|
|
10759
|
-
this.chainId =
|
|
8414
|
+
this.chainId = null;
|
|
10760
8415
|
this.root = null;
|
|
10761
8416
|
this.privyMethods = null;
|
|
10762
8417
|
this.pendingLogin = null;
|
|
10763
8418
|
// Resolved Solana RPC URLs (computed in the constructor; consumed in
|
|
10764
8419
|
// initialize() where @solana/kit is lazily loaded to build the transports).
|
|
10765
|
-
this.
|
|
10766
|
-
this.rpcMainnetUrl = SOLANA_MAINNET_RPC_URL;
|
|
8420
|
+
this.configuredRpcUrl = null;
|
|
10767
8421
|
// This is used to store the pending transaction until the wallet is connected for workaround for the wallet not being connected after login completion
|
|
10768
8422
|
this.pendingTransaction = null;
|
|
10769
8423
|
// This is used to store pending signTransaction calls until the wallet is connected
|
|
@@ -10772,41 +8426,37 @@ class PrivyWalletProvider {
|
|
|
10772
8426
|
this.pendingSignMessage = null;
|
|
10773
8427
|
// This is used to store pending signAndSubmitTransaction calls until the wallet is connected
|
|
10774
8428
|
this.pendingSignAndSubmitTransaction = null;
|
|
10775
|
-
this.networkUrl = networkUrl;
|
|
8429
|
+
this.networkUrl = normalizeSolanaRpcUrl(networkUrl);
|
|
8430
|
+
this.configuredNetwork = configuredNetwork;
|
|
10776
8431
|
if (typeof window === 'undefined') {
|
|
10777
8432
|
throw new Error('PrivyWalletProvider can only be instantiated in a browser environment');
|
|
10778
8433
|
}
|
|
8434
|
+
const requiredPrivyConfig = requirePrivyWalletConfig(privyConfig);
|
|
10779
8435
|
if (PrivyWalletProvider.instance) {
|
|
10780
8436
|
return PrivyWalletProvider.instance;
|
|
10781
8437
|
}
|
|
10782
8438
|
this.containerElement = null;
|
|
10783
8439
|
this.root = null;
|
|
10784
8440
|
this.privyMethods = null;
|
|
10785
|
-
this.privyConfig =
|
|
10786
|
-
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10791
|
-
|
|
10792
|
-
|
|
10793
|
-
|
|
8441
|
+
this.privyConfig = requiredPrivyConfig;
|
|
8442
|
+
if (!this.privyConfig.config.appearance) {
|
|
8443
|
+
this.privyConfig.config.appearance = {};
|
|
8444
|
+
}
|
|
8445
|
+
if (appName != null && appName != '' && !this.privyConfig.config.appearance.landingHeader) {
|
|
8446
|
+
this.privyConfig.config.appearance.landingHeader = appName;
|
|
8447
|
+
}
|
|
8448
|
+
if (appLogoUrl != null && appLogoUrl != '' && !this.privyConfig.config.appearance.logo) {
|
|
8449
|
+
this.privyConfig.config.appearance.logo = appLogoUrl;
|
|
10794
8450
|
}
|
|
10795
8451
|
// (externalWallets connectors are configured in initialize() once the
|
|
10796
8452
|
// Privy SDK is lazily loaded — see loadPrivyModules.)
|
|
10797
8453
|
// Resolve Solana RPC URLs for v3. The @solana/kit transports are built
|
|
10798
8454
|
// lazily in initialize() so a non-Privy consumer never needs @solana/kit.
|
|
10799
|
-
this.
|
|
10800
|
-
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
|
|
10804
|
-
this.chainId = 'solana:mainnet';
|
|
10805
|
-
}
|
|
10806
|
-
else if (networkUrl.includes('devnet')) {
|
|
10807
|
-
this.rpcDevnetUrl = networkUrl;
|
|
10808
|
-
this.chainId = 'solana:devnet';
|
|
10809
|
-
}
|
|
8455
|
+
if (this.networkUrl || configuredNetwork) {
|
|
8456
|
+
this.configuredRpcUrl = resolveSolanaRpcUrl(this.networkUrl, configuredNetwork, "Privy Solana RPC");
|
|
8457
|
+
}
|
|
8458
|
+
if (configuredNetwork) {
|
|
8459
|
+
this.chainId = resolveSolanaWalletStandardChain(configuredNetwork, "Privy Solana transaction");
|
|
10810
8460
|
}
|
|
10811
8461
|
const existingProviders = document.querySelectorAll('[data-privy-provider]');
|
|
10812
8462
|
existingProviders.forEach(el => el.remove());
|
|
@@ -10821,9 +8471,9 @@ class PrivyWalletProvider {
|
|
|
10821
8471
|
PrivyWalletProvider.instance = this;
|
|
10822
8472
|
}
|
|
10823
8473
|
// Optional: Provide a static method to get the instance
|
|
10824
|
-
static getInstance(appName, appLogoUrl, privyConfig) {
|
|
8474
|
+
static getInstance(appName, appLogoUrl, privyConfig, networkUrl = null, configuredNetwork = null) {
|
|
10825
8475
|
if (!PrivyWalletProvider.instance) {
|
|
10826
|
-
new PrivyWalletProvider(appName, appLogoUrl, privyConfig);
|
|
8476
|
+
new PrivyWalletProvider(appName, appLogoUrl, privyConfig, networkUrl, configuredNetwork);
|
|
10827
8477
|
}
|
|
10828
8478
|
return PrivyWalletProvider.instance;
|
|
10829
8479
|
}
|
|
@@ -10833,19 +8483,17 @@ class PrivyWalletProvider {
|
|
|
10833
8483
|
// Build the Solana RPC transports now that we're on the async path, so
|
|
10834
8484
|
// @solana/kit can be lazily imported (kept out of the entry bundle).
|
|
10835
8485
|
const { createSolanaRpc, createSolanaRpcSubscriptions } = await loadSolanaKit();
|
|
10836
|
-
if (!this.privyConfig.config.solana) {
|
|
8486
|
+
if (this.configuredRpcUrl && this.chainId && !this.privyConfig.config.solana) {
|
|
10837
8487
|
this.privyConfig.config.solana = {};
|
|
10838
8488
|
}
|
|
10839
|
-
this.
|
|
10840
|
-
|
|
10841
|
-
|
|
10842
|
-
|
|
10843
|
-
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
}
|
|
10848
|
-
};
|
|
8489
|
+
if (this.configuredRpcUrl && this.chainId) {
|
|
8490
|
+
this.privyConfig.config.solana.rpcs = {
|
|
8491
|
+
[this.chainId]: {
|
|
8492
|
+
rpc: createSolanaRpc(this.configuredRpcUrl),
|
|
8493
|
+
rpcSubscriptions: createSolanaRpcSubscriptions(this.configuredRpcUrl.replace('https://', 'wss://'))
|
|
8494
|
+
}
|
|
8495
|
+
};
|
|
8496
|
+
}
|
|
10849
8497
|
// Ensure externalWallets connectors are always configured — required for
|
|
10850
8498
|
// useWallets().ready to resolve even when no browser extension is present.
|
|
10851
8499
|
if (!this.privyConfig.config.externalWallets && privySolana) {
|
|
@@ -11181,7 +8829,7 @@ class PrivyWalletProvider {
|
|
|
11181
8829
|
try {
|
|
11182
8830
|
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
11183
8831
|
// Just sign, don't submit - return raw signed bytes (same as original runTransaction)
|
|
11184
|
-
const signedTx = await this.signTransactionRaw(tx, privyWallet);
|
|
8832
|
+
const signedTx = await this.signTransactionRaw(tx, privyWallet, solTransactionData.network);
|
|
11185
8833
|
return {
|
|
11186
8834
|
signedTransaction: signedTx, // Raw Uint8Array from Privy
|
|
11187
8835
|
blockNumber: 0,
|
|
@@ -11190,7 +8838,7 @@ class PrivyWalletProvider {
|
|
|
11190
8838
|
};
|
|
11191
8839
|
}
|
|
11192
8840
|
// Sign and submit using shared helper
|
|
11193
|
-
const { signature, txInfo } = await this.signAndSubmitInternal(tx, privyWallet, rpcUrl, connection);
|
|
8841
|
+
const { signature, txInfo } = await this.signAndSubmitInternal(tx, privyWallet, rpcUrl, connection, solTransactionData.network);
|
|
11194
8842
|
return {
|
|
11195
8843
|
transactionSignature: signature,
|
|
11196
8844
|
blockNumber: (txInfo === null || txInfo === void 0 ? void 0 : txInfo.slot) || 0,
|
|
@@ -11362,26 +9010,25 @@ class PrivyWalletProvider {
|
|
|
11362
9010
|
}
|
|
11363
9011
|
// ============ Private Helpers ============
|
|
11364
9012
|
getRpcUrl(network) {
|
|
11365
|
-
|
|
11366
|
-
|
|
11367
|
-
|
|
11368
|
-
if (network
|
|
11369
|
-
return
|
|
11370
|
-
}
|
|
11371
|
-
else if (network === 'solana_mainnet') {
|
|
11372
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
9013
|
+
return resolveSolanaRpcUrl(this.networkUrl, network !== null && network !== void 0 ? network : this.configuredNetwork, "Privy Solana transaction");
|
|
9014
|
+
}
|
|
9015
|
+
getChainId(network) {
|
|
9016
|
+
if (network) {
|
|
9017
|
+
return resolveSolanaWalletStandardChain(network, "Privy Solana transaction");
|
|
11373
9018
|
}
|
|
11374
|
-
|
|
11375
|
-
return
|
|
9019
|
+
if (this.chainId)
|
|
9020
|
+
return this.chainId;
|
|
9021
|
+
if (this.configuredNetwork) {
|
|
9022
|
+
return resolveSolanaWalletStandardChain(this.configuredNetwork, "Privy Solana transaction");
|
|
11376
9023
|
}
|
|
11377
|
-
|
|
9024
|
+
throw new Error("Privy Solana transaction requires config.chain as solana_devnet, solana_mainnet, or surfnet.");
|
|
11378
9025
|
}
|
|
11379
9026
|
/**
|
|
11380
9027
|
* Internal sign transaction - serializes and signs via Privy
|
|
11381
9028
|
* Returns the raw result from Privy (Uint8Array)
|
|
11382
9029
|
* This mirrors exactly what runTransaction was doing
|
|
11383
9030
|
*/
|
|
11384
|
-
async signTransactionRaw(transaction, privyWallet) {
|
|
9031
|
+
async signTransactionRaw(transaction, privyWallet, network) {
|
|
11385
9032
|
var _a;
|
|
11386
9033
|
// Serialize the transaction
|
|
11387
9034
|
// Use duck typing instead of instanceof to handle multiple @solana/web3.js versions
|
|
@@ -11397,7 +9044,7 @@ class PrivyWalletProvider {
|
|
|
11397
9044
|
const result = await ((_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.signTransaction({
|
|
11398
9045
|
transaction: serializedForSign,
|
|
11399
9046
|
wallet: privyWallet,
|
|
11400
|
-
chain: this.
|
|
9047
|
+
chain: this.getChainId(network)
|
|
11401
9048
|
}));
|
|
11402
9049
|
// Privy returns { signedTransaction: Uint8Array }, unwrap it
|
|
11403
9050
|
const signedTx = (result === null || result === void 0 ? void 0 : result.signedTransaction) || result;
|
|
@@ -11442,13 +9089,13 @@ class PrivyWalletProvider {
|
|
|
11442
9089
|
* For Surfnet: sign with signTransactionRaw, then sendRawTransaction
|
|
11443
9090
|
* For non-Surfnet: use Privy's signAndSendTransaction (combined operation)
|
|
11444
9091
|
*/
|
|
11445
|
-
async signAndSubmitInternal(transaction, privyWallet, rpcUrl, connection) {
|
|
9092
|
+
async signAndSubmitInternal(transaction, privyWallet, rpcUrl, connection, network) {
|
|
11446
9093
|
var _a;
|
|
11447
|
-
const isSurfnet = rpcUrl === SURFNET_RPC_URL
|
|
9094
|
+
const isSurfnet = rpcUrl === SURFNET_RPC_URL;
|
|
11448
9095
|
let signature;
|
|
11449
9096
|
if (isSurfnet) {
|
|
11450
9097
|
// For Surfnet: sign with signTransactionRaw, then sendRawTransaction
|
|
11451
|
-
const signedTx = await this.signTransactionRaw(transaction, privyWallet);
|
|
9098
|
+
const signedTx = await this.signTransactionRaw(transaction, privyWallet, network);
|
|
11452
9099
|
signature = await connection.sendRawTransaction(signedTx);
|
|
11453
9100
|
}
|
|
11454
9101
|
else {
|
|
@@ -11466,7 +9113,7 @@ class PrivyWalletProvider {
|
|
|
11466
9113
|
const result = await ((_a = this.privyMethods) === null || _a === void 0 ? void 0 : _a.useSendTransactionSolana.signAndSendTransaction({
|
|
11467
9114
|
transaction: serializedTx,
|
|
11468
9115
|
wallet: privyWallet,
|
|
11469
|
-
chain: this.
|
|
9116
|
+
chain: this.getChainId(network)
|
|
11470
9117
|
}));
|
|
11471
9118
|
// Handle case where signature might be bytes instead of string
|
|
11472
9119
|
const rawSig = result.signature;
|
|
@@ -11533,16 +9180,7 @@ class PrivyWalletProvider {
|
|
|
11533
9180
|
}
|
|
11534
9181
|
let privyWallet = this.privyMethods.wallets.find((wallet) => wallet.address === sessionAddress);
|
|
11535
9182
|
if (!privyWallet) {
|
|
11536
|
-
|
|
11537
|
-
const accessToken = await this.privyMethods.getAccessToken();
|
|
11538
|
-
await this.createSession(this.privyMethods.wallets[0].address, accessToken, this.privyMethods.identityToken);
|
|
11539
|
-
setCurrentUser({ address: this.privyMethods.wallets[0].address, provider: this });
|
|
11540
|
-
const session = await getActiveSessionManager().getSession();
|
|
11541
|
-
sessionAddress = session === null || session === void 0 ? void 0 : session.address;
|
|
11542
|
-
if (!sessionAddress) {
|
|
11543
|
-
throw new Error('No wallet connected or logged in to sign message');
|
|
11544
|
-
}
|
|
11545
|
-
privyWallet = this.privyMethods.wallets[0];
|
|
9183
|
+
throw new Error('Active Privy wallets do not include the authenticated session wallet; please log in again.');
|
|
11546
9184
|
}
|
|
11547
9185
|
// Use the Privy signMessage hook for Solana wallets
|
|
11548
9186
|
// The message needs to be passed as a Uint8Array
|
|
@@ -11572,22 +9210,21 @@ class PrivyWalletProvider {
|
|
|
11572
9210
|
// Privy-specific token verification — it arrives as a Solana signature and is
|
|
11573
9211
|
// recorded server-side as authMethod 'phantom'.
|
|
11574
9212
|
async createSession(address, _accessToken, _idToken) {
|
|
11575
|
-
var _a, _b, _c, _d
|
|
11576
|
-
|
|
11577
|
-
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];
|
|
9213
|
+
var _a, _b, _c, _d;
|
|
9214
|
+
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);
|
|
11578
9215
|
if (!privyWallet) {
|
|
11579
|
-
throw new Error('No Privy Solana wallet
|
|
9216
|
+
throw new Error('No Privy Solana wallet matching the requested session address is available.');
|
|
11580
9217
|
}
|
|
11581
9218
|
const nonce = await genAuthNonce();
|
|
11582
9219
|
const message = await genSolanaMessage(address, nonce);
|
|
11583
9220
|
const messageBytes = getPlatform().textEncode(message);
|
|
11584
9221
|
// Low-level Privy sign hook — signs WITHOUT touching the session (the public
|
|
11585
9222
|
// signMessage() bootstraps sessions, which would recurse here).
|
|
11586
|
-
const signResult = await ((
|
|
9223
|
+
const signResult = await ((_c = this.privyMethods) === null || _c === void 0 ? void 0 : _c.signMessage({
|
|
11587
9224
|
message: messageBytes,
|
|
11588
9225
|
wallet: privyWallet,
|
|
11589
9226
|
}));
|
|
11590
|
-
const signatureBytes = (
|
|
9227
|
+
const signatureBytes = (_d = signResult === null || signResult === void 0 ? void 0 : signResult.signature) !== null && _d !== void 0 ? _d : signResult;
|
|
11591
9228
|
// base64-encoded detached signature (matches Phantom + guest providers).
|
|
11592
9229
|
const signature = bufferExports.Buffer.from(signatureBytes).toString('base64');
|
|
11593
9230
|
const createSessionResult = await createSessionWithSignature(address, message, signature);
|
|
@@ -11669,7 +9306,6 @@ var privyWalletProvider = /*#__PURE__*/Object.freeze({
|
|
|
11669
9306
|
* to host Privy's React context, this provider expects the RN app itself
|
|
11670
9307
|
* to render <PrivyProvider> and then bridge the hooks via setPrivyMethods().
|
|
11671
9308
|
*/
|
|
11672
|
-
const SURFNET_RPC_URL = 'https://surfpool.fly.dev';
|
|
11673
9309
|
// -----------------------------------------------------------------------
|
|
11674
9310
|
// Provider implementation
|
|
11675
9311
|
// -----------------------------------------------------------------------
|
|
@@ -11677,7 +9313,7 @@ class PrivyExpoProvider {
|
|
|
11677
9313
|
constructor(appId, networkUrl = null) {
|
|
11678
9314
|
this.privyMethods = null;
|
|
11679
9315
|
this.appId = appId;
|
|
11680
|
-
this.networkUrl = networkUrl;
|
|
9316
|
+
this.networkUrl = normalizeSolanaRpcUrl(networkUrl);
|
|
11681
9317
|
}
|
|
11682
9318
|
/**
|
|
11683
9319
|
* Bridge Privy hooks from the app's React tree into this provider.
|
|
@@ -11962,15 +9598,7 @@ class PrivyExpoProvider {
|
|
|
11962
9598
|
return { signature, txInfo };
|
|
11963
9599
|
}
|
|
11964
9600
|
getRpcUrl(network) {
|
|
11965
|
-
|
|
11966
|
-
return this.networkUrl;
|
|
11967
|
-
if (network === 'solana_devnet')
|
|
11968
|
-
return SOLANA_DEVNET_RPC_URL;
|
|
11969
|
-
if (network === 'solana_mainnet')
|
|
11970
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
11971
|
-
if (network === 'surfnet')
|
|
11972
|
-
return SURFNET_RPC_URL;
|
|
11973
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
9601
|
+
return resolveSolanaRpcUrl(this.networkUrl, network, "Privy Expo Solana transaction");
|
|
11974
9602
|
}
|
|
11975
9603
|
async ensureReady(timeoutMs = 15000) {
|
|
11976
9604
|
if (!this.privyMethods) {
|