@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getActiveSessionManager, genAuthNonce, genSolanaMessage, createSessionWithSignature, getConfig, revokeSession, WebSessionManager, ReactNativeSessionManager, init as init$1, reconnectWithNewAuth, deriveUserIdentityFromIdToken, getIdToken as getIdToken$1, convertRemainingAccounts, buildSetDocumentsTransaction } from '@bounded-sh/core';
|
|
2
|
-
import { Keypair, VersionedTransaction, Transaction, Connection, PublicKey } from '@solana/web3.js';
|
|
3
2
|
import * as React from 'react';
|
|
3
|
+
import { VersionedTransaction, Transaction, Connection, PublicKey } from '@solana/web3.js';
|
|
4
4
|
import * as anchor from '@coral-xyz/anchor';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -223,9 +223,7 @@ class MockAuthProvider {
|
|
|
223
223
|
}
|
|
224
224
|
async signMessageMock(message) {
|
|
225
225
|
const address = getPlatform().sessionStorage.getItem('test-user-address') || DEFAULT_TEST_ADDRESS;
|
|
226
|
-
|
|
227
|
-
// mock provider deterministic so mockAuth exercises the same integrity check.
|
|
228
|
-
const signature = await this.generateOffchainSignature(message);
|
|
226
|
+
const signature = `mock_sig_${Math.random().toString(36).substring(2, 15)}`;
|
|
229
227
|
console.log('[MockAuth] Mock message signed:', {
|
|
230
228
|
address,
|
|
231
229
|
message,
|
|
@@ -233,13 +231,6 @@ class MockAuthProvider {
|
|
|
233
231
|
});
|
|
234
232
|
return signature;
|
|
235
233
|
}
|
|
236
|
-
async generateOffchainSignature(message) {
|
|
237
|
-
const platform = getPlatform();
|
|
238
|
-
const data = platform.textEncode(message);
|
|
239
|
-
const hashBuffer = await platform.sha256(data);
|
|
240
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
241
|
-
return platform.btoa(String.fromCharCode(...hashArray));
|
|
242
|
-
}
|
|
243
234
|
/**
|
|
244
235
|
* Mock transaction signing - returns the transaction as-is (no actual signing)
|
|
245
236
|
*/
|
|
@@ -298,9 +289,9 @@ class MockAuthProvider {
|
|
|
298
289
|
/**
|
|
299
290
|
* OffchainAuthProvider wraps a real auth provider (e.g., Phantom) for the poofnet environment.
|
|
300
291
|
*
|
|
301
|
-
* For signMessageMock, this shows a custom confirmation modal and
|
|
302
|
-
*
|
|
303
|
-
*
|
|
292
|
+
* For signMessageMock, this shows a custom confirmation modal and then delegates
|
|
293
|
+
* to the wrapped provider for a real detached signature over the exact offchain
|
|
294
|
+
* transaction message.
|
|
304
295
|
*/
|
|
305
296
|
class OffchainAuthProvider {
|
|
306
297
|
constructor(wrappedProvider, config = {}) {
|
|
@@ -368,8 +359,7 @@ class OffchainAuthProvider {
|
|
|
368
359
|
throw new Error("Transaction rejected by user");
|
|
369
360
|
}
|
|
370
361
|
}
|
|
371
|
-
|
|
372
|
-
const signature = await this.generateMockSignature(message);
|
|
362
|
+
const signature = await this.wrappedProvider.signMessage(message);
|
|
373
363
|
// Callback: signing complete
|
|
374
364
|
(_d = (_c = this.config).onSigningComplete) === null || _d === void 0 ? void 0 : _d.call(_c, signature);
|
|
375
365
|
return signature;
|
|
@@ -978,26 +968,12 @@ class OffchainAuthProvider {
|
|
|
978
968
|
}
|
|
979
969
|
`;
|
|
980
970
|
}
|
|
981
|
-
async generateMockSignature(message) {
|
|
982
|
-
// Generate a deterministic signature using SHA-256 hash of message
|
|
983
|
-
// This can be verified on the backend by hashing the same message
|
|
984
|
-
const platform = getPlatform();
|
|
985
|
-
const data = platform.textEncode(message);
|
|
986
|
-
const hashBuffer = await platform.sha256(data);
|
|
987
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
988
|
-
const base64 = platform.btoa(String.fromCharCode(...hashArray));
|
|
989
|
-
return base64;
|
|
990
|
-
}
|
|
991
971
|
}
|
|
992
972
|
|
|
993
973
|
function getDefaultExportFromCjs (x) {
|
|
994
974
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
995
975
|
}
|
|
996
976
|
|
|
997
|
-
function getDefaultExportFromNamespaceIfNotNamed (n) {
|
|
998
|
-
return n && Object.prototype.hasOwnProperty.call(n, 'default') && Object.keys(n).length === 1 ? n['default'] : n;
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
977
|
var safeBuffer = {exports: {}};
|
|
1002
978
|
|
|
1003
979
|
var buffer = {};
|
|
@@ -3587,2444 +3563,24 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
3587
3563
|
default: bs58
|
|
3588
3564
|
});
|
|
3589
3565
|
|
|
3590
|
-
function commonjsRequire(path) {
|
|
3591
|
-
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.');
|
|
3592
|
-
}
|
|
3593
|
-
|
|
3594
|
-
var naclFast = {exports: {}};
|
|
3595
|
-
|
|
3596
|
-
var _nodeResolve_empty = {};
|
|
3597
|
-
|
|
3598
|
-
var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
|
|
3599
|
-
__proto__: null,
|
|
3600
|
-
default: _nodeResolve_empty
|
|
3601
|
-
});
|
|
3602
|
-
|
|
3603
|
-
var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
|
|
3604
|
-
|
|
3605
|
-
var hasRequiredNaclFast;
|
|
3606
|
-
|
|
3607
|
-
function requireNaclFast () {
|
|
3608
|
-
if (hasRequiredNaclFast) return naclFast.exports;
|
|
3609
|
-
hasRequiredNaclFast = 1;
|
|
3610
|
-
(function (module) {
|
|
3611
|
-
(function(nacl) {
|
|
3612
|
-
|
|
3613
|
-
// Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
|
|
3614
|
-
// Public domain.
|
|
3615
|
-
//
|
|
3616
|
-
// Implementation derived from TweetNaCl version 20140427.
|
|
3617
|
-
// See for details: http://tweetnacl.cr.yp.to/
|
|
3618
|
-
|
|
3619
|
-
var gf = function(init) {
|
|
3620
|
-
var i, r = new Float64Array(16);
|
|
3621
|
-
if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
|
|
3622
|
-
return r;
|
|
3623
|
-
};
|
|
3624
|
-
|
|
3625
|
-
// Pluggable, initialized in high-level API below.
|
|
3626
|
-
var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
|
|
3627
|
-
|
|
3628
|
-
var _0 = new Uint8Array(16);
|
|
3629
|
-
var _9 = new Uint8Array(32); _9[0] = 9;
|
|
3630
|
-
|
|
3631
|
-
var gf0 = gf(),
|
|
3632
|
-
gf1 = gf([1]),
|
|
3633
|
-
_121665 = gf([0xdb41, 1]),
|
|
3634
|
-
D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
|
|
3635
|
-
D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
|
|
3636
|
-
X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
|
|
3637
|
-
Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
|
|
3638
|
-
I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
|
|
3639
|
-
|
|
3640
|
-
function ts64(x, i, h, l) {
|
|
3641
|
-
x[i] = (h >> 24) & 0xff;
|
|
3642
|
-
x[i+1] = (h >> 16) & 0xff;
|
|
3643
|
-
x[i+2] = (h >> 8) & 0xff;
|
|
3644
|
-
x[i+3] = h & 0xff;
|
|
3645
|
-
x[i+4] = (l >> 24) & 0xff;
|
|
3646
|
-
x[i+5] = (l >> 16) & 0xff;
|
|
3647
|
-
x[i+6] = (l >> 8) & 0xff;
|
|
3648
|
-
x[i+7] = l & 0xff;
|
|
3649
|
-
}
|
|
3650
|
-
|
|
3651
|
-
function vn(x, xi, y, yi, n) {
|
|
3652
|
-
var i,d = 0;
|
|
3653
|
-
for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
|
|
3654
|
-
return (1 & ((d - 1) >>> 8)) - 1;
|
|
3655
|
-
}
|
|
3656
|
-
|
|
3657
|
-
function crypto_verify_16(x, xi, y, yi) {
|
|
3658
|
-
return vn(x,xi,y,yi,16);
|
|
3659
|
-
}
|
|
3660
|
-
|
|
3661
|
-
function crypto_verify_32(x, xi, y, yi) {
|
|
3662
|
-
return vn(x,xi,y,yi,32);
|
|
3663
|
-
}
|
|
3664
|
-
|
|
3665
|
-
function core_salsa20(o, p, k, c) {
|
|
3666
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
3667
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
3668
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
3669
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
3670
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
3671
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
3672
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
3673
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
3674
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
3675
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
3676
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
3677
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
3678
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
3679
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
3680
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
3681
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
3682
|
-
|
|
3683
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
3684
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
3685
|
-
x15 = j15, u;
|
|
3686
|
-
|
|
3687
|
-
for (var i = 0; i < 20; i += 2) {
|
|
3688
|
-
u = x0 + x12 | 0;
|
|
3689
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
3690
|
-
u = x4 + x0 | 0;
|
|
3691
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3692
|
-
u = x8 + x4 | 0;
|
|
3693
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
3694
|
-
u = x12 + x8 | 0;
|
|
3695
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3696
|
-
|
|
3697
|
-
u = x5 + x1 | 0;
|
|
3698
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
3699
|
-
u = x9 + x5 | 0;
|
|
3700
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3701
|
-
u = x13 + x9 | 0;
|
|
3702
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
3703
|
-
u = x1 + x13 | 0;
|
|
3704
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3705
|
-
|
|
3706
|
-
u = x10 + x6 | 0;
|
|
3707
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
3708
|
-
u = x14 + x10 | 0;
|
|
3709
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3710
|
-
u = x2 + x14 | 0;
|
|
3711
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
3712
|
-
u = x6 + x2 | 0;
|
|
3713
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3714
|
-
|
|
3715
|
-
u = x15 + x11 | 0;
|
|
3716
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
3717
|
-
u = x3 + x15 | 0;
|
|
3718
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3719
|
-
u = x7 + x3 | 0;
|
|
3720
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
3721
|
-
u = x11 + x7 | 0;
|
|
3722
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3723
|
-
|
|
3724
|
-
u = x0 + x3 | 0;
|
|
3725
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
3726
|
-
u = x1 + x0 | 0;
|
|
3727
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3728
|
-
u = x2 + x1 | 0;
|
|
3729
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
3730
|
-
u = x3 + x2 | 0;
|
|
3731
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3732
|
-
|
|
3733
|
-
u = x5 + x4 | 0;
|
|
3734
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
3735
|
-
u = x6 + x5 | 0;
|
|
3736
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3737
|
-
u = x7 + x6 | 0;
|
|
3738
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
3739
|
-
u = x4 + x7 | 0;
|
|
3740
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3741
|
-
|
|
3742
|
-
u = x10 + x9 | 0;
|
|
3743
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
3744
|
-
u = x11 + x10 | 0;
|
|
3745
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3746
|
-
u = x8 + x11 | 0;
|
|
3747
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
3748
|
-
u = x9 + x8 | 0;
|
|
3749
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3750
|
-
|
|
3751
|
-
u = x15 + x14 | 0;
|
|
3752
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
3753
|
-
u = x12 + x15 | 0;
|
|
3754
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3755
|
-
u = x13 + x12 | 0;
|
|
3756
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
3757
|
-
u = x14 + x13 | 0;
|
|
3758
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3759
|
-
}
|
|
3760
|
-
x0 = x0 + j0 | 0;
|
|
3761
|
-
x1 = x1 + j1 | 0;
|
|
3762
|
-
x2 = x2 + j2 | 0;
|
|
3763
|
-
x3 = x3 + j3 | 0;
|
|
3764
|
-
x4 = x4 + j4 | 0;
|
|
3765
|
-
x5 = x5 + j5 | 0;
|
|
3766
|
-
x6 = x6 + j6 | 0;
|
|
3767
|
-
x7 = x7 + j7 | 0;
|
|
3768
|
-
x8 = x8 + j8 | 0;
|
|
3769
|
-
x9 = x9 + j9 | 0;
|
|
3770
|
-
x10 = x10 + j10 | 0;
|
|
3771
|
-
x11 = x11 + j11 | 0;
|
|
3772
|
-
x12 = x12 + j12 | 0;
|
|
3773
|
-
x13 = x13 + j13 | 0;
|
|
3774
|
-
x14 = x14 + j14 | 0;
|
|
3775
|
-
x15 = x15 + j15 | 0;
|
|
3776
|
-
|
|
3777
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
3778
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
3779
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
3780
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
3781
|
-
|
|
3782
|
-
o[ 4] = x1 >>> 0 & 0xff;
|
|
3783
|
-
o[ 5] = x1 >>> 8 & 0xff;
|
|
3784
|
-
o[ 6] = x1 >>> 16 & 0xff;
|
|
3785
|
-
o[ 7] = x1 >>> 24 & 0xff;
|
|
3786
|
-
|
|
3787
|
-
o[ 8] = x2 >>> 0 & 0xff;
|
|
3788
|
-
o[ 9] = x2 >>> 8 & 0xff;
|
|
3789
|
-
o[10] = x2 >>> 16 & 0xff;
|
|
3790
|
-
o[11] = x2 >>> 24 & 0xff;
|
|
3791
|
-
|
|
3792
|
-
o[12] = x3 >>> 0 & 0xff;
|
|
3793
|
-
o[13] = x3 >>> 8 & 0xff;
|
|
3794
|
-
o[14] = x3 >>> 16 & 0xff;
|
|
3795
|
-
o[15] = x3 >>> 24 & 0xff;
|
|
3796
|
-
|
|
3797
|
-
o[16] = x4 >>> 0 & 0xff;
|
|
3798
|
-
o[17] = x4 >>> 8 & 0xff;
|
|
3799
|
-
o[18] = x4 >>> 16 & 0xff;
|
|
3800
|
-
o[19] = x4 >>> 24 & 0xff;
|
|
3801
|
-
|
|
3802
|
-
o[20] = x5 >>> 0 & 0xff;
|
|
3803
|
-
o[21] = x5 >>> 8 & 0xff;
|
|
3804
|
-
o[22] = x5 >>> 16 & 0xff;
|
|
3805
|
-
o[23] = x5 >>> 24 & 0xff;
|
|
3806
|
-
|
|
3807
|
-
o[24] = x6 >>> 0 & 0xff;
|
|
3808
|
-
o[25] = x6 >>> 8 & 0xff;
|
|
3809
|
-
o[26] = x6 >>> 16 & 0xff;
|
|
3810
|
-
o[27] = x6 >>> 24 & 0xff;
|
|
3811
|
-
|
|
3812
|
-
o[28] = x7 >>> 0 & 0xff;
|
|
3813
|
-
o[29] = x7 >>> 8 & 0xff;
|
|
3814
|
-
o[30] = x7 >>> 16 & 0xff;
|
|
3815
|
-
o[31] = x7 >>> 24 & 0xff;
|
|
3816
|
-
|
|
3817
|
-
o[32] = x8 >>> 0 & 0xff;
|
|
3818
|
-
o[33] = x8 >>> 8 & 0xff;
|
|
3819
|
-
o[34] = x8 >>> 16 & 0xff;
|
|
3820
|
-
o[35] = x8 >>> 24 & 0xff;
|
|
3821
|
-
|
|
3822
|
-
o[36] = x9 >>> 0 & 0xff;
|
|
3823
|
-
o[37] = x9 >>> 8 & 0xff;
|
|
3824
|
-
o[38] = x9 >>> 16 & 0xff;
|
|
3825
|
-
o[39] = x9 >>> 24 & 0xff;
|
|
3826
|
-
|
|
3827
|
-
o[40] = x10 >>> 0 & 0xff;
|
|
3828
|
-
o[41] = x10 >>> 8 & 0xff;
|
|
3829
|
-
o[42] = x10 >>> 16 & 0xff;
|
|
3830
|
-
o[43] = x10 >>> 24 & 0xff;
|
|
3831
|
-
|
|
3832
|
-
o[44] = x11 >>> 0 & 0xff;
|
|
3833
|
-
o[45] = x11 >>> 8 & 0xff;
|
|
3834
|
-
o[46] = x11 >>> 16 & 0xff;
|
|
3835
|
-
o[47] = x11 >>> 24 & 0xff;
|
|
3836
|
-
|
|
3837
|
-
o[48] = x12 >>> 0 & 0xff;
|
|
3838
|
-
o[49] = x12 >>> 8 & 0xff;
|
|
3839
|
-
o[50] = x12 >>> 16 & 0xff;
|
|
3840
|
-
o[51] = x12 >>> 24 & 0xff;
|
|
3841
|
-
|
|
3842
|
-
o[52] = x13 >>> 0 & 0xff;
|
|
3843
|
-
o[53] = x13 >>> 8 & 0xff;
|
|
3844
|
-
o[54] = x13 >>> 16 & 0xff;
|
|
3845
|
-
o[55] = x13 >>> 24 & 0xff;
|
|
3846
|
-
|
|
3847
|
-
o[56] = x14 >>> 0 & 0xff;
|
|
3848
|
-
o[57] = x14 >>> 8 & 0xff;
|
|
3849
|
-
o[58] = x14 >>> 16 & 0xff;
|
|
3850
|
-
o[59] = x14 >>> 24 & 0xff;
|
|
3851
|
-
|
|
3852
|
-
o[60] = x15 >>> 0 & 0xff;
|
|
3853
|
-
o[61] = x15 >>> 8 & 0xff;
|
|
3854
|
-
o[62] = x15 >>> 16 & 0xff;
|
|
3855
|
-
o[63] = x15 >>> 24 & 0xff;
|
|
3856
|
-
}
|
|
3857
|
-
|
|
3858
|
-
function core_hsalsa20(o,p,k,c) {
|
|
3859
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
3860
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
3861
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
3862
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
3863
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
3864
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
3865
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
3866
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
3867
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
3868
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
3869
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
3870
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
3871
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
3872
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
3873
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
3874
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
3875
|
-
|
|
3876
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
3877
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
3878
|
-
x15 = j15, u;
|
|
3879
|
-
|
|
3880
|
-
for (var i = 0; i < 20; i += 2) {
|
|
3881
|
-
u = x0 + x12 | 0;
|
|
3882
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
3883
|
-
u = x4 + x0 | 0;
|
|
3884
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3885
|
-
u = x8 + x4 | 0;
|
|
3886
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
3887
|
-
u = x12 + x8 | 0;
|
|
3888
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3889
|
-
|
|
3890
|
-
u = x5 + x1 | 0;
|
|
3891
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
3892
|
-
u = x9 + x5 | 0;
|
|
3893
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3894
|
-
u = x13 + x9 | 0;
|
|
3895
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
3896
|
-
u = x1 + x13 | 0;
|
|
3897
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3898
|
-
|
|
3899
|
-
u = x10 + x6 | 0;
|
|
3900
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
3901
|
-
u = x14 + x10 | 0;
|
|
3902
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3903
|
-
u = x2 + x14 | 0;
|
|
3904
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
3905
|
-
u = x6 + x2 | 0;
|
|
3906
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3907
|
-
|
|
3908
|
-
u = x15 + x11 | 0;
|
|
3909
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
3910
|
-
u = x3 + x15 | 0;
|
|
3911
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3912
|
-
u = x7 + x3 | 0;
|
|
3913
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
3914
|
-
u = x11 + x7 | 0;
|
|
3915
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3916
|
-
|
|
3917
|
-
u = x0 + x3 | 0;
|
|
3918
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
3919
|
-
u = x1 + x0 | 0;
|
|
3920
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
3921
|
-
u = x2 + x1 | 0;
|
|
3922
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
3923
|
-
u = x3 + x2 | 0;
|
|
3924
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
3925
|
-
|
|
3926
|
-
u = x5 + x4 | 0;
|
|
3927
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
3928
|
-
u = x6 + x5 | 0;
|
|
3929
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
3930
|
-
u = x7 + x6 | 0;
|
|
3931
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
3932
|
-
u = x4 + x7 | 0;
|
|
3933
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
3934
|
-
|
|
3935
|
-
u = x10 + x9 | 0;
|
|
3936
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
3937
|
-
u = x11 + x10 | 0;
|
|
3938
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
3939
|
-
u = x8 + x11 | 0;
|
|
3940
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
3941
|
-
u = x9 + x8 | 0;
|
|
3942
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
3943
|
-
|
|
3944
|
-
u = x15 + x14 | 0;
|
|
3945
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
3946
|
-
u = x12 + x15 | 0;
|
|
3947
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
3948
|
-
u = x13 + x12 | 0;
|
|
3949
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
3950
|
-
u = x14 + x13 | 0;
|
|
3951
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
3952
|
-
}
|
|
3953
|
-
|
|
3954
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
3955
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
3956
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
3957
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
3958
|
-
|
|
3959
|
-
o[ 4] = x5 >>> 0 & 0xff;
|
|
3960
|
-
o[ 5] = x5 >>> 8 & 0xff;
|
|
3961
|
-
o[ 6] = x5 >>> 16 & 0xff;
|
|
3962
|
-
o[ 7] = x5 >>> 24 & 0xff;
|
|
3963
|
-
|
|
3964
|
-
o[ 8] = x10 >>> 0 & 0xff;
|
|
3965
|
-
o[ 9] = x10 >>> 8 & 0xff;
|
|
3966
|
-
o[10] = x10 >>> 16 & 0xff;
|
|
3967
|
-
o[11] = x10 >>> 24 & 0xff;
|
|
3968
|
-
|
|
3969
|
-
o[12] = x15 >>> 0 & 0xff;
|
|
3970
|
-
o[13] = x15 >>> 8 & 0xff;
|
|
3971
|
-
o[14] = x15 >>> 16 & 0xff;
|
|
3972
|
-
o[15] = x15 >>> 24 & 0xff;
|
|
3973
|
-
|
|
3974
|
-
o[16] = x6 >>> 0 & 0xff;
|
|
3975
|
-
o[17] = x6 >>> 8 & 0xff;
|
|
3976
|
-
o[18] = x6 >>> 16 & 0xff;
|
|
3977
|
-
o[19] = x6 >>> 24 & 0xff;
|
|
3978
|
-
|
|
3979
|
-
o[20] = x7 >>> 0 & 0xff;
|
|
3980
|
-
o[21] = x7 >>> 8 & 0xff;
|
|
3981
|
-
o[22] = x7 >>> 16 & 0xff;
|
|
3982
|
-
o[23] = x7 >>> 24 & 0xff;
|
|
3983
|
-
|
|
3984
|
-
o[24] = x8 >>> 0 & 0xff;
|
|
3985
|
-
o[25] = x8 >>> 8 & 0xff;
|
|
3986
|
-
o[26] = x8 >>> 16 & 0xff;
|
|
3987
|
-
o[27] = x8 >>> 24 & 0xff;
|
|
3988
|
-
|
|
3989
|
-
o[28] = x9 >>> 0 & 0xff;
|
|
3990
|
-
o[29] = x9 >>> 8 & 0xff;
|
|
3991
|
-
o[30] = x9 >>> 16 & 0xff;
|
|
3992
|
-
o[31] = x9 >>> 24 & 0xff;
|
|
3993
|
-
}
|
|
3994
|
-
|
|
3995
|
-
function crypto_core_salsa20(out,inp,k,c) {
|
|
3996
|
-
core_salsa20(out,inp,k,c);
|
|
3997
|
-
}
|
|
3998
|
-
|
|
3999
|
-
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
4000
|
-
core_hsalsa20(out,inp,k,c);
|
|
4001
|
-
}
|
|
4002
|
-
|
|
4003
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
4004
|
-
// "expand 32-byte k"
|
|
4005
|
-
|
|
4006
|
-
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
4007
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
4008
|
-
var u, i;
|
|
4009
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
4010
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
4011
|
-
while (b >= 64) {
|
|
4012
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4013
|
-
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
4014
|
-
u = 1;
|
|
4015
|
-
for (i = 8; i < 16; i++) {
|
|
4016
|
-
u = u + (z[i] & 0xff) | 0;
|
|
4017
|
-
z[i] = u & 0xff;
|
|
4018
|
-
u >>>= 8;
|
|
4019
|
-
}
|
|
4020
|
-
b -= 64;
|
|
4021
|
-
cpos += 64;
|
|
4022
|
-
mpos += 64;
|
|
4023
|
-
}
|
|
4024
|
-
if (b > 0) {
|
|
4025
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4026
|
-
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
4027
|
-
}
|
|
4028
|
-
return 0;
|
|
4029
|
-
}
|
|
4030
|
-
|
|
4031
|
-
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
4032
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
4033
|
-
var u, i;
|
|
4034
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
4035
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
4036
|
-
while (b >= 64) {
|
|
4037
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4038
|
-
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
4039
|
-
u = 1;
|
|
4040
|
-
for (i = 8; i < 16; i++) {
|
|
4041
|
-
u = u + (z[i] & 0xff) | 0;
|
|
4042
|
-
z[i] = u & 0xff;
|
|
4043
|
-
u >>>= 8;
|
|
4044
|
-
}
|
|
4045
|
-
b -= 64;
|
|
4046
|
-
cpos += 64;
|
|
4047
|
-
}
|
|
4048
|
-
if (b > 0) {
|
|
4049
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
4050
|
-
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
4051
|
-
}
|
|
4052
|
-
return 0;
|
|
4053
|
-
}
|
|
4054
|
-
|
|
4055
|
-
function crypto_stream(c,cpos,d,n,k) {
|
|
4056
|
-
var s = new Uint8Array(32);
|
|
4057
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
4058
|
-
var sn = new Uint8Array(8);
|
|
4059
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
4060
|
-
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
4061
|
-
}
|
|
4062
|
-
|
|
4063
|
-
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
4064
|
-
var s = new Uint8Array(32);
|
|
4065
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
4066
|
-
var sn = new Uint8Array(8);
|
|
4067
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
4068
|
-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
4069
|
-
}
|
|
4070
|
-
|
|
4071
|
-
/*
|
|
4072
|
-
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
4073
|
-
* https://github.com/floodyberry/poly1305-donna
|
|
4074
|
-
*/
|
|
4075
|
-
|
|
4076
|
-
var poly1305 = function(key) {
|
|
4077
|
-
this.buffer = new Uint8Array(16);
|
|
4078
|
-
this.r = new Uint16Array(10);
|
|
4079
|
-
this.h = new Uint16Array(10);
|
|
4080
|
-
this.pad = new Uint16Array(8);
|
|
4081
|
-
this.leftover = 0;
|
|
4082
|
-
this.fin = 0;
|
|
4083
|
-
|
|
4084
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
4085
|
-
|
|
4086
|
-
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
4087
|
-
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
4088
|
-
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
4089
|
-
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
4090
|
-
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
4091
|
-
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
4092
|
-
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
4093
|
-
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
4094
|
-
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
4095
|
-
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
4096
|
-
|
|
4097
|
-
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
4098
|
-
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
4099
|
-
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
4100
|
-
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
4101
|
-
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
4102
|
-
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
4103
|
-
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
4104
|
-
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
4105
|
-
};
|
|
4106
|
-
|
|
4107
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
4108
|
-
var hibit = this.fin ? 0 : (1 << 11);
|
|
4109
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
4110
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
4111
|
-
|
|
4112
|
-
var h0 = this.h[0],
|
|
4113
|
-
h1 = this.h[1],
|
|
4114
|
-
h2 = this.h[2],
|
|
4115
|
-
h3 = this.h[3],
|
|
4116
|
-
h4 = this.h[4],
|
|
4117
|
-
h5 = this.h[5],
|
|
4118
|
-
h6 = this.h[6],
|
|
4119
|
-
h7 = this.h[7],
|
|
4120
|
-
h8 = this.h[8],
|
|
4121
|
-
h9 = this.h[9];
|
|
4122
|
-
|
|
4123
|
-
var r0 = this.r[0],
|
|
4124
|
-
r1 = this.r[1],
|
|
4125
|
-
r2 = this.r[2],
|
|
4126
|
-
r3 = this.r[3],
|
|
4127
|
-
r4 = this.r[4],
|
|
4128
|
-
r5 = this.r[5],
|
|
4129
|
-
r6 = this.r[6],
|
|
4130
|
-
r7 = this.r[7],
|
|
4131
|
-
r8 = this.r[8],
|
|
4132
|
-
r9 = this.r[9];
|
|
4133
|
-
|
|
4134
|
-
while (bytes >= 16) {
|
|
4135
|
-
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
4136
|
-
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
4137
|
-
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
4138
|
-
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
4139
|
-
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
4140
|
-
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
4141
|
-
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
4142
|
-
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
4143
|
-
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
4144
|
-
h9 += ((t7 >>> 5)) | hibit;
|
|
4145
|
-
|
|
4146
|
-
c = 0;
|
|
4147
|
-
|
|
4148
|
-
d0 = c;
|
|
4149
|
-
d0 += h0 * r0;
|
|
4150
|
-
d0 += h1 * (5 * r9);
|
|
4151
|
-
d0 += h2 * (5 * r8);
|
|
4152
|
-
d0 += h3 * (5 * r7);
|
|
4153
|
-
d0 += h4 * (5 * r6);
|
|
4154
|
-
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
4155
|
-
d0 += h5 * (5 * r5);
|
|
4156
|
-
d0 += h6 * (5 * r4);
|
|
4157
|
-
d0 += h7 * (5 * r3);
|
|
4158
|
-
d0 += h8 * (5 * r2);
|
|
4159
|
-
d0 += h9 * (5 * r1);
|
|
4160
|
-
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
4161
|
-
|
|
4162
|
-
d1 = c;
|
|
4163
|
-
d1 += h0 * r1;
|
|
4164
|
-
d1 += h1 * r0;
|
|
4165
|
-
d1 += h2 * (5 * r9);
|
|
4166
|
-
d1 += h3 * (5 * r8);
|
|
4167
|
-
d1 += h4 * (5 * r7);
|
|
4168
|
-
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
4169
|
-
d1 += h5 * (5 * r6);
|
|
4170
|
-
d1 += h6 * (5 * r5);
|
|
4171
|
-
d1 += h7 * (5 * r4);
|
|
4172
|
-
d1 += h8 * (5 * r3);
|
|
4173
|
-
d1 += h9 * (5 * r2);
|
|
4174
|
-
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
4175
|
-
|
|
4176
|
-
d2 = c;
|
|
4177
|
-
d2 += h0 * r2;
|
|
4178
|
-
d2 += h1 * r1;
|
|
4179
|
-
d2 += h2 * r0;
|
|
4180
|
-
d2 += h3 * (5 * r9);
|
|
4181
|
-
d2 += h4 * (5 * r8);
|
|
4182
|
-
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
4183
|
-
d2 += h5 * (5 * r7);
|
|
4184
|
-
d2 += h6 * (5 * r6);
|
|
4185
|
-
d2 += h7 * (5 * r5);
|
|
4186
|
-
d2 += h8 * (5 * r4);
|
|
4187
|
-
d2 += h9 * (5 * r3);
|
|
4188
|
-
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
4189
|
-
|
|
4190
|
-
d3 = c;
|
|
4191
|
-
d3 += h0 * r3;
|
|
4192
|
-
d3 += h1 * r2;
|
|
4193
|
-
d3 += h2 * r1;
|
|
4194
|
-
d3 += h3 * r0;
|
|
4195
|
-
d3 += h4 * (5 * r9);
|
|
4196
|
-
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
4197
|
-
d3 += h5 * (5 * r8);
|
|
4198
|
-
d3 += h6 * (5 * r7);
|
|
4199
|
-
d3 += h7 * (5 * r6);
|
|
4200
|
-
d3 += h8 * (5 * r5);
|
|
4201
|
-
d3 += h9 * (5 * r4);
|
|
4202
|
-
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
4203
|
-
|
|
4204
|
-
d4 = c;
|
|
4205
|
-
d4 += h0 * r4;
|
|
4206
|
-
d4 += h1 * r3;
|
|
4207
|
-
d4 += h2 * r2;
|
|
4208
|
-
d4 += h3 * r1;
|
|
4209
|
-
d4 += h4 * r0;
|
|
4210
|
-
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
4211
|
-
d4 += h5 * (5 * r9);
|
|
4212
|
-
d4 += h6 * (5 * r8);
|
|
4213
|
-
d4 += h7 * (5 * r7);
|
|
4214
|
-
d4 += h8 * (5 * r6);
|
|
4215
|
-
d4 += h9 * (5 * r5);
|
|
4216
|
-
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
4217
|
-
|
|
4218
|
-
d5 = c;
|
|
4219
|
-
d5 += h0 * r5;
|
|
4220
|
-
d5 += h1 * r4;
|
|
4221
|
-
d5 += h2 * r3;
|
|
4222
|
-
d5 += h3 * r2;
|
|
4223
|
-
d5 += h4 * r1;
|
|
4224
|
-
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
4225
|
-
d5 += h5 * r0;
|
|
4226
|
-
d5 += h6 * (5 * r9);
|
|
4227
|
-
d5 += h7 * (5 * r8);
|
|
4228
|
-
d5 += h8 * (5 * r7);
|
|
4229
|
-
d5 += h9 * (5 * r6);
|
|
4230
|
-
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
4231
|
-
|
|
4232
|
-
d6 = c;
|
|
4233
|
-
d6 += h0 * r6;
|
|
4234
|
-
d6 += h1 * r5;
|
|
4235
|
-
d6 += h2 * r4;
|
|
4236
|
-
d6 += h3 * r3;
|
|
4237
|
-
d6 += h4 * r2;
|
|
4238
|
-
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
4239
|
-
d6 += h5 * r1;
|
|
4240
|
-
d6 += h6 * r0;
|
|
4241
|
-
d6 += h7 * (5 * r9);
|
|
4242
|
-
d6 += h8 * (5 * r8);
|
|
4243
|
-
d6 += h9 * (5 * r7);
|
|
4244
|
-
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
4245
|
-
|
|
4246
|
-
d7 = c;
|
|
4247
|
-
d7 += h0 * r7;
|
|
4248
|
-
d7 += h1 * r6;
|
|
4249
|
-
d7 += h2 * r5;
|
|
4250
|
-
d7 += h3 * r4;
|
|
4251
|
-
d7 += h4 * r3;
|
|
4252
|
-
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
4253
|
-
d7 += h5 * r2;
|
|
4254
|
-
d7 += h6 * r1;
|
|
4255
|
-
d7 += h7 * r0;
|
|
4256
|
-
d7 += h8 * (5 * r9);
|
|
4257
|
-
d7 += h9 * (5 * r8);
|
|
4258
|
-
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
4259
|
-
|
|
4260
|
-
d8 = c;
|
|
4261
|
-
d8 += h0 * r8;
|
|
4262
|
-
d8 += h1 * r7;
|
|
4263
|
-
d8 += h2 * r6;
|
|
4264
|
-
d8 += h3 * r5;
|
|
4265
|
-
d8 += h4 * r4;
|
|
4266
|
-
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
4267
|
-
d8 += h5 * r3;
|
|
4268
|
-
d8 += h6 * r2;
|
|
4269
|
-
d8 += h7 * r1;
|
|
4270
|
-
d8 += h8 * r0;
|
|
4271
|
-
d8 += h9 * (5 * r9);
|
|
4272
|
-
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
4273
|
-
|
|
4274
|
-
d9 = c;
|
|
4275
|
-
d9 += h0 * r9;
|
|
4276
|
-
d9 += h1 * r8;
|
|
4277
|
-
d9 += h2 * r7;
|
|
4278
|
-
d9 += h3 * r6;
|
|
4279
|
-
d9 += h4 * r5;
|
|
4280
|
-
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
4281
|
-
d9 += h5 * r4;
|
|
4282
|
-
d9 += h6 * r3;
|
|
4283
|
-
d9 += h7 * r2;
|
|
4284
|
-
d9 += h8 * r1;
|
|
4285
|
-
d9 += h9 * r0;
|
|
4286
|
-
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
4287
|
-
|
|
4288
|
-
c = (((c << 2) + c)) | 0;
|
|
4289
|
-
c = (c + d0) | 0;
|
|
4290
|
-
d0 = c & 0x1fff;
|
|
4291
|
-
c = (c >>> 13);
|
|
4292
|
-
d1 += c;
|
|
4293
|
-
|
|
4294
|
-
h0 = d0;
|
|
4295
|
-
h1 = d1;
|
|
4296
|
-
h2 = d2;
|
|
4297
|
-
h3 = d3;
|
|
4298
|
-
h4 = d4;
|
|
4299
|
-
h5 = d5;
|
|
4300
|
-
h6 = d6;
|
|
4301
|
-
h7 = d7;
|
|
4302
|
-
h8 = d8;
|
|
4303
|
-
h9 = d9;
|
|
4304
|
-
|
|
4305
|
-
mpos += 16;
|
|
4306
|
-
bytes -= 16;
|
|
4307
|
-
}
|
|
4308
|
-
this.h[0] = h0;
|
|
4309
|
-
this.h[1] = h1;
|
|
4310
|
-
this.h[2] = h2;
|
|
4311
|
-
this.h[3] = h3;
|
|
4312
|
-
this.h[4] = h4;
|
|
4313
|
-
this.h[5] = h5;
|
|
4314
|
-
this.h[6] = h6;
|
|
4315
|
-
this.h[7] = h7;
|
|
4316
|
-
this.h[8] = h8;
|
|
4317
|
-
this.h[9] = h9;
|
|
4318
|
-
};
|
|
4319
|
-
|
|
4320
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
4321
|
-
var g = new Uint16Array(10);
|
|
4322
|
-
var c, mask, f, i;
|
|
4323
|
-
|
|
4324
|
-
if (this.leftover) {
|
|
4325
|
-
i = this.leftover;
|
|
4326
|
-
this.buffer[i++] = 1;
|
|
4327
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
4328
|
-
this.fin = 1;
|
|
4329
|
-
this.blocks(this.buffer, 0, 16);
|
|
4330
|
-
}
|
|
4331
|
-
|
|
4332
|
-
c = this.h[1] >>> 13;
|
|
4333
|
-
this.h[1] &= 0x1fff;
|
|
4334
|
-
for (i = 2; i < 10; i++) {
|
|
4335
|
-
this.h[i] += c;
|
|
4336
|
-
c = this.h[i] >>> 13;
|
|
4337
|
-
this.h[i] &= 0x1fff;
|
|
4338
|
-
}
|
|
4339
|
-
this.h[0] += (c * 5);
|
|
4340
|
-
c = this.h[0] >>> 13;
|
|
4341
|
-
this.h[0] &= 0x1fff;
|
|
4342
|
-
this.h[1] += c;
|
|
4343
|
-
c = this.h[1] >>> 13;
|
|
4344
|
-
this.h[1] &= 0x1fff;
|
|
4345
|
-
this.h[2] += c;
|
|
4346
|
-
|
|
4347
|
-
g[0] = this.h[0] + 5;
|
|
4348
|
-
c = g[0] >>> 13;
|
|
4349
|
-
g[0] &= 0x1fff;
|
|
4350
|
-
for (i = 1; i < 10; i++) {
|
|
4351
|
-
g[i] = this.h[i] + c;
|
|
4352
|
-
c = g[i] >>> 13;
|
|
4353
|
-
g[i] &= 0x1fff;
|
|
4354
|
-
}
|
|
4355
|
-
g[9] -= (1 << 13);
|
|
4356
|
-
|
|
4357
|
-
mask = (c ^ 1) - 1;
|
|
4358
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
4359
|
-
mask = ~mask;
|
|
4360
|
-
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
4361
|
-
|
|
4362
|
-
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
4363
|
-
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
4364
|
-
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
4365
|
-
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
4366
|
-
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
4367
|
-
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
4368
|
-
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
4369
|
-
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
4370
|
-
|
|
4371
|
-
f = this.h[0] + this.pad[0];
|
|
4372
|
-
this.h[0] = f & 0xffff;
|
|
4373
|
-
for (i = 1; i < 8; i++) {
|
|
4374
|
-
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
4375
|
-
this.h[i] = f & 0xffff;
|
|
4376
|
-
}
|
|
4377
|
-
|
|
4378
|
-
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
4379
|
-
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
4380
|
-
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
4381
|
-
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
4382
|
-
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
4383
|
-
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
4384
|
-
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
4385
|
-
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
4386
|
-
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
4387
|
-
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
4388
|
-
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
4389
|
-
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
4390
|
-
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
4391
|
-
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
4392
|
-
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
4393
|
-
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
4394
|
-
};
|
|
4395
|
-
|
|
4396
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
4397
|
-
var i, want;
|
|
4398
|
-
|
|
4399
|
-
if (this.leftover) {
|
|
4400
|
-
want = (16 - this.leftover);
|
|
4401
|
-
if (want > bytes)
|
|
4402
|
-
want = bytes;
|
|
4403
|
-
for (i = 0; i < want; i++)
|
|
4404
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
4405
|
-
bytes -= want;
|
|
4406
|
-
mpos += want;
|
|
4407
|
-
this.leftover += want;
|
|
4408
|
-
if (this.leftover < 16)
|
|
4409
|
-
return;
|
|
4410
|
-
this.blocks(this.buffer, 0, 16);
|
|
4411
|
-
this.leftover = 0;
|
|
4412
|
-
}
|
|
4413
|
-
|
|
4414
|
-
if (bytes >= 16) {
|
|
4415
|
-
want = bytes - (bytes % 16);
|
|
4416
|
-
this.blocks(m, mpos, want);
|
|
4417
|
-
mpos += want;
|
|
4418
|
-
bytes -= want;
|
|
4419
|
-
}
|
|
4420
|
-
|
|
4421
|
-
if (bytes) {
|
|
4422
|
-
for (i = 0; i < bytes; i++)
|
|
4423
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
4424
|
-
this.leftover += bytes;
|
|
4425
|
-
}
|
|
4426
|
-
};
|
|
4427
|
-
|
|
4428
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
4429
|
-
var s = new poly1305(k);
|
|
4430
|
-
s.update(m, mpos, n);
|
|
4431
|
-
s.finish(out, outpos);
|
|
4432
|
-
return 0;
|
|
4433
|
-
}
|
|
4434
|
-
|
|
4435
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
4436
|
-
var x = new Uint8Array(16);
|
|
4437
|
-
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
4438
|
-
return crypto_verify_16(h,hpos,x,0);
|
|
4439
|
-
}
|
|
4440
|
-
|
|
4441
|
-
function crypto_secretbox(c,m,d,n,k) {
|
|
4442
|
-
var i;
|
|
4443
|
-
if (d < 32) return -1;
|
|
4444
|
-
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
4445
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
4446
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
4447
|
-
return 0;
|
|
4448
|
-
}
|
|
4449
|
-
|
|
4450
|
-
function crypto_secretbox_open(m,c,d,n,k) {
|
|
4451
|
-
var i;
|
|
4452
|
-
var x = new Uint8Array(32);
|
|
4453
|
-
if (d < 32) return -1;
|
|
4454
|
-
crypto_stream(x,0,32,n,k);
|
|
4455
|
-
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
4456
|
-
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
4457
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
4458
|
-
return 0;
|
|
4459
|
-
}
|
|
4460
|
-
|
|
4461
|
-
function set25519(r, a) {
|
|
4462
|
-
var i;
|
|
4463
|
-
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
4464
|
-
}
|
|
4465
|
-
|
|
4466
|
-
function car25519(o) {
|
|
4467
|
-
var i, v, c = 1;
|
|
4468
|
-
for (i = 0; i < 16; i++) {
|
|
4469
|
-
v = o[i] + c + 65535;
|
|
4470
|
-
c = Math.floor(v / 65536);
|
|
4471
|
-
o[i] = v - c * 65536;
|
|
4472
|
-
}
|
|
4473
|
-
o[0] += c-1 + 37 * (c-1);
|
|
4474
|
-
}
|
|
4475
|
-
|
|
4476
|
-
function sel25519(p, q, b) {
|
|
4477
|
-
var t, c = ~(b-1);
|
|
4478
|
-
for (var i = 0; i < 16; i++) {
|
|
4479
|
-
t = c & (p[i] ^ q[i]);
|
|
4480
|
-
p[i] ^= t;
|
|
4481
|
-
q[i] ^= t;
|
|
4482
|
-
}
|
|
4483
|
-
}
|
|
4484
|
-
|
|
4485
|
-
function pack25519(o, n) {
|
|
4486
|
-
var i, j, b;
|
|
4487
|
-
var m = gf(), t = gf();
|
|
4488
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
4489
|
-
car25519(t);
|
|
4490
|
-
car25519(t);
|
|
4491
|
-
car25519(t);
|
|
4492
|
-
for (j = 0; j < 2; j++) {
|
|
4493
|
-
m[0] = t[0] - 0xffed;
|
|
4494
|
-
for (i = 1; i < 15; i++) {
|
|
4495
|
-
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
4496
|
-
m[i-1] &= 0xffff;
|
|
4497
|
-
}
|
|
4498
|
-
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
4499
|
-
b = (m[15]>>16) & 1;
|
|
4500
|
-
m[14] &= 0xffff;
|
|
4501
|
-
sel25519(t, m, 1-b);
|
|
4502
|
-
}
|
|
4503
|
-
for (i = 0; i < 16; i++) {
|
|
4504
|
-
o[2*i] = t[i] & 0xff;
|
|
4505
|
-
o[2*i+1] = t[i]>>8;
|
|
4506
|
-
}
|
|
4507
|
-
}
|
|
4508
|
-
|
|
4509
|
-
function neq25519(a, b) {
|
|
4510
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
4511
|
-
pack25519(c, a);
|
|
4512
|
-
pack25519(d, b);
|
|
4513
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
4514
|
-
}
|
|
4515
|
-
|
|
4516
|
-
function par25519(a) {
|
|
4517
|
-
var d = new Uint8Array(32);
|
|
4518
|
-
pack25519(d, a);
|
|
4519
|
-
return d[0] & 1;
|
|
4520
|
-
}
|
|
4521
|
-
|
|
4522
|
-
function unpack25519(o, n) {
|
|
4523
|
-
var i;
|
|
4524
|
-
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
4525
|
-
o[15] &= 0x7fff;
|
|
4526
|
-
}
|
|
4527
|
-
|
|
4528
|
-
function A(o, a, b) {
|
|
4529
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
4530
|
-
}
|
|
4531
|
-
|
|
4532
|
-
function Z(o, a, b) {
|
|
4533
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
4534
|
-
}
|
|
4535
|
-
|
|
4536
|
-
function M(o, a, b) {
|
|
4537
|
-
var v, c,
|
|
4538
|
-
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
4539
|
-
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
4540
|
-
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
4541
|
-
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
4542
|
-
b0 = b[0],
|
|
4543
|
-
b1 = b[1],
|
|
4544
|
-
b2 = b[2],
|
|
4545
|
-
b3 = b[3],
|
|
4546
|
-
b4 = b[4],
|
|
4547
|
-
b5 = b[5],
|
|
4548
|
-
b6 = b[6],
|
|
4549
|
-
b7 = b[7],
|
|
4550
|
-
b8 = b[8],
|
|
4551
|
-
b9 = b[9],
|
|
4552
|
-
b10 = b[10],
|
|
4553
|
-
b11 = b[11],
|
|
4554
|
-
b12 = b[12],
|
|
4555
|
-
b13 = b[13],
|
|
4556
|
-
b14 = b[14],
|
|
4557
|
-
b15 = b[15];
|
|
4558
|
-
|
|
4559
|
-
v = a[0];
|
|
4560
|
-
t0 += v * b0;
|
|
4561
|
-
t1 += v * b1;
|
|
4562
|
-
t2 += v * b2;
|
|
4563
|
-
t3 += v * b3;
|
|
4564
|
-
t4 += v * b4;
|
|
4565
|
-
t5 += v * b5;
|
|
4566
|
-
t6 += v * b6;
|
|
4567
|
-
t7 += v * b7;
|
|
4568
|
-
t8 += v * b8;
|
|
4569
|
-
t9 += v * b9;
|
|
4570
|
-
t10 += v * b10;
|
|
4571
|
-
t11 += v * b11;
|
|
4572
|
-
t12 += v * b12;
|
|
4573
|
-
t13 += v * b13;
|
|
4574
|
-
t14 += v * b14;
|
|
4575
|
-
t15 += v * b15;
|
|
4576
|
-
v = a[1];
|
|
4577
|
-
t1 += v * b0;
|
|
4578
|
-
t2 += v * b1;
|
|
4579
|
-
t3 += v * b2;
|
|
4580
|
-
t4 += v * b3;
|
|
4581
|
-
t5 += v * b4;
|
|
4582
|
-
t6 += v * b5;
|
|
4583
|
-
t7 += v * b6;
|
|
4584
|
-
t8 += v * b7;
|
|
4585
|
-
t9 += v * b8;
|
|
4586
|
-
t10 += v * b9;
|
|
4587
|
-
t11 += v * b10;
|
|
4588
|
-
t12 += v * b11;
|
|
4589
|
-
t13 += v * b12;
|
|
4590
|
-
t14 += v * b13;
|
|
4591
|
-
t15 += v * b14;
|
|
4592
|
-
t16 += v * b15;
|
|
4593
|
-
v = a[2];
|
|
4594
|
-
t2 += v * b0;
|
|
4595
|
-
t3 += v * b1;
|
|
4596
|
-
t4 += v * b2;
|
|
4597
|
-
t5 += v * b3;
|
|
4598
|
-
t6 += v * b4;
|
|
4599
|
-
t7 += v * b5;
|
|
4600
|
-
t8 += v * b6;
|
|
4601
|
-
t9 += v * b7;
|
|
4602
|
-
t10 += v * b8;
|
|
4603
|
-
t11 += v * b9;
|
|
4604
|
-
t12 += v * b10;
|
|
4605
|
-
t13 += v * b11;
|
|
4606
|
-
t14 += v * b12;
|
|
4607
|
-
t15 += v * b13;
|
|
4608
|
-
t16 += v * b14;
|
|
4609
|
-
t17 += v * b15;
|
|
4610
|
-
v = a[3];
|
|
4611
|
-
t3 += v * b0;
|
|
4612
|
-
t4 += v * b1;
|
|
4613
|
-
t5 += v * b2;
|
|
4614
|
-
t6 += v * b3;
|
|
4615
|
-
t7 += v * b4;
|
|
4616
|
-
t8 += v * b5;
|
|
4617
|
-
t9 += v * b6;
|
|
4618
|
-
t10 += v * b7;
|
|
4619
|
-
t11 += v * b8;
|
|
4620
|
-
t12 += v * b9;
|
|
4621
|
-
t13 += v * b10;
|
|
4622
|
-
t14 += v * b11;
|
|
4623
|
-
t15 += v * b12;
|
|
4624
|
-
t16 += v * b13;
|
|
4625
|
-
t17 += v * b14;
|
|
4626
|
-
t18 += v * b15;
|
|
4627
|
-
v = a[4];
|
|
4628
|
-
t4 += v * b0;
|
|
4629
|
-
t5 += v * b1;
|
|
4630
|
-
t6 += v * b2;
|
|
4631
|
-
t7 += v * b3;
|
|
4632
|
-
t8 += v * b4;
|
|
4633
|
-
t9 += v * b5;
|
|
4634
|
-
t10 += v * b6;
|
|
4635
|
-
t11 += v * b7;
|
|
4636
|
-
t12 += v * b8;
|
|
4637
|
-
t13 += v * b9;
|
|
4638
|
-
t14 += v * b10;
|
|
4639
|
-
t15 += v * b11;
|
|
4640
|
-
t16 += v * b12;
|
|
4641
|
-
t17 += v * b13;
|
|
4642
|
-
t18 += v * b14;
|
|
4643
|
-
t19 += v * b15;
|
|
4644
|
-
v = a[5];
|
|
4645
|
-
t5 += v * b0;
|
|
4646
|
-
t6 += v * b1;
|
|
4647
|
-
t7 += v * b2;
|
|
4648
|
-
t8 += v * b3;
|
|
4649
|
-
t9 += v * b4;
|
|
4650
|
-
t10 += v * b5;
|
|
4651
|
-
t11 += v * b6;
|
|
4652
|
-
t12 += v * b7;
|
|
4653
|
-
t13 += v * b8;
|
|
4654
|
-
t14 += v * b9;
|
|
4655
|
-
t15 += v * b10;
|
|
4656
|
-
t16 += v * b11;
|
|
4657
|
-
t17 += v * b12;
|
|
4658
|
-
t18 += v * b13;
|
|
4659
|
-
t19 += v * b14;
|
|
4660
|
-
t20 += v * b15;
|
|
4661
|
-
v = a[6];
|
|
4662
|
-
t6 += v * b0;
|
|
4663
|
-
t7 += v * b1;
|
|
4664
|
-
t8 += v * b2;
|
|
4665
|
-
t9 += v * b3;
|
|
4666
|
-
t10 += v * b4;
|
|
4667
|
-
t11 += v * b5;
|
|
4668
|
-
t12 += v * b6;
|
|
4669
|
-
t13 += v * b7;
|
|
4670
|
-
t14 += v * b8;
|
|
4671
|
-
t15 += v * b9;
|
|
4672
|
-
t16 += v * b10;
|
|
4673
|
-
t17 += v * b11;
|
|
4674
|
-
t18 += v * b12;
|
|
4675
|
-
t19 += v * b13;
|
|
4676
|
-
t20 += v * b14;
|
|
4677
|
-
t21 += v * b15;
|
|
4678
|
-
v = a[7];
|
|
4679
|
-
t7 += v * b0;
|
|
4680
|
-
t8 += v * b1;
|
|
4681
|
-
t9 += v * b2;
|
|
4682
|
-
t10 += v * b3;
|
|
4683
|
-
t11 += v * b4;
|
|
4684
|
-
t12 += v * b5;
|
|
4685
|
-
t13 += v * b6;
|
|
4686
|
-
t14 += v * b7;
|
|
4687
|
-
t15 += v * b8;
|
|
4688
|
-
t16 += v * b9;
|
|
4689
|
-
t17 += v * b10;
|
|
4690
|
-
t18 += v * b11;
|
|
4691
|
-
t19 += v * b12;
|
|
4692
|
-
t20 += v * b13;
|
|
4693
|
-
t21 += v * b14;
|
|
4694
|
-
t22 += v * b15;
|
|
4695
|
-
v = a[8];
|
|
4696
|
-
t8 += v * b0;
|
|
4697
|
-
t9 += v * b1;
|
|
4698
|
-
t10 += v * b2;
|
|
4699
|
-
t11 += v * b3;
|
|
4700
|
-
t12 += v * b4;
|
|
4701
|
-
t13 += v * b5;
|
|
4702
|
-
t14 += v * b6;
|
|
4703
|
-
t15 += v * b7;
|
|
4704
|
-
t16 += v * b8;
|
|
4705
|
-
t17 += v * b9;
|
|
4706
|
-
t18 += v * b10;
|
|
4707
|
-
t19 += v * b11;
|
|
4708
|
-
t20 += v * b12;
|
|
4709
|
-
t21 += v * b13;
|
|
4710
|
-
t22 += v * b14;
|
|
4711
|
-
t23 += v * b15;
|
|
4712
|
-
v = a[9];
|
|
4713
|
-
t9 += v * b0;
|
|
4714
|
-
t10 += v * b1;
|
|
4715
|
-
t11 += v * b2;
|
|
4716
|
-
t12 += v * b3;
|
|
4717
|
-
t13 += v * b4;
|
|
4718
|
-
t14 += v * b5;
|
|
4719
|
-
t15 += v * b6;
|
|
4720
|
-
t16 += v * b7;
|
|
4721
|
-
t17 += v * b8;
|
|
4722
|
-
t18 += v * b9;
|
|
4723
|
-
t19 += v * b10;
|
|
4724
|
-
t20 += v * b11;
|
|
4725
|
-
t21 += v * b12;
|
|
4726
|
-
t22 += v * b13;
|
|
4727
|
-
t23 += v * b14;
|
|
4728
|
-
t24 += v * b15;
|
|
4729
|
-
v = a[10];
|
|
4730
|
-
t10 += v * b0;
|
|
4731
|
-
t11 += v * b1;
|
|
4732
|
-
t12 += v * b2;
|
|
4733
|
-
t13 += v * b3;
|
|
4734
|
-
t14 += v * b4;
|
|
4735
|
-
t15 += v * b5;
|
|
4736
|
-
t16 += v * b6;
|
|
4737
|
-
t17 += v * b7;
|
|
4738
|
-
t18 += v * b8;
|
|
4739
|
-
t19 += v * b9;
|
|
4740
|
-
t20 += v * b10;
|
|
4741
|
-
t21 += v * b11;
|
|
4742
|
-
t22 += v * b12;
|
|
4743
|
-
t23 += v * b13;
|
|
4744
|
-
t24 += v * b14;
|
|
4745
|
-
t25 += v * b15;
|
|
4746
|
-
v = a[11];
|
|
4747
|
-
t11 += v * b0;
|
|
4748
|
-
t12 += v * b1;
|
|
4749
|
-
t13 += v * b2;
|
|
4750
|
-
t14 += v * b3;
|
|
4751
|
-
t15 += v * b4;
|
|
4752
|
-
t16 += v * b5;
|
|
4753
|
-
t17 += v * b6;
|
|
4754
|
-
t18 += v * b7;
|
|
4755
|
-
t19 += v * b8;
|
|
4756
|
-
t20 += v * b9;
|
|
4757
|
-
t21 += v * b10;
|
|
4758
|
-
t22 += v * b11;
|
|
4759
|
-
t23 += v * b12;
|
|
4760
|
-
t24 += v * b13;
|
|
4761
|
-
t25 += v * b14;
|
|
4762
|
-
t26 += v * b15;
|
|
4763
|
-
v = a[12];
|
|
4764
|
-
t12 += v * b0;
|
|
4765
|
-
t13 += v * b1;
|
|
4766
|
-
t14 += v * b2;
|
|
4767
|
-
t15 += v * b3;
|
|
4768
|
-
t16 += v * b4;
|
|
4769
|
-
t17 += v * b5;
|
|
4770
|
-
t18 += v * b6;
|
|
4771
|
-
t19 += v * b7;
|
|
4772
|
-
t20 += v * b8;
|
|
4773
|
-
t21 += v * b9;
|
|
4774
|
-
t22 += v * b10;
|
|
4775
|
-
t23 += v * b11;
|
|
4776
|
-
t24 += v * b12;
|
|
4777
|
-
t25 += v * b13;
|
|
4778
|
-
t26 += v * b14;
|
|
4779
|
-
t27 += v * b15;
|
|
4780
|
-
v = a[13];
|
|
4781
|
-
t13 += v * b0;
|
|
4782
|
-
t14 += v * b1;
|
|
4783
|
-
t15 += v * b2;
|
|
4784
|
-
t16 += v * b3;
|
|
4785
|
-
t17 += v * b4;
|
|
4786
|
-
t18 += v * b5;
|
|
4787
|
-
t19 += v * b6;
|
|
4788
|
-
t20 += v * b7;
|
|
4789
|
-
t21 += v * b8;
|
|
4790
|
-
t22 += v * b9;
|
|
4791
|
-
t23 += v * b10;
|
|
4792
|
-
t24 += v * b11;
|
|
4793
|
-
t25 += v * b12;
|
|
4794
|
-
t26 += v * b13;
|
|
4795
|
-
t27 += v * b14;
|
|
4796
|
-
t28 += v * b15;
|
|
4797
|
-
v = a[14];
|
|
4798
|
-
t14 += v * b0;
|
|
4799
|
-
t15 += v * b1;
|
|
4800
|
-
t16 += v * b2;
|
|
4801
|
-
t17 += v * b3;
|
|
4802
|
-
t18 += v * b4;
|
|
4803
|
-
t19 += v * b5;
|
|
4804
|
-
t20 += v * b6;
|
|
4805
|
-
t21 += v * b7;
|
|
4806
|
-
t22 += v * b8;
|
|
4807
|
-
t23 += v * b9;
|
|
4808
|
-
t24 += v * b10;
|
|
4809
|
-
t25 += v * b11;
|
|
4810
|
-
t26 += v * b12;
|
|
4811
|
-
t27 += v * b13;
|
|
4812
|
-
t28 += v * b14;
|
|
4813
|
-
t29 += v * b15;
|
|
4814
|
-
v = a[15];
|
|
4815
|
-
t15 += v * b0;
|
|
4816
|
-
t16 += v * b1;
|
|
4817
|
-
t17 += v * b2;
|
|
4818
|
-
t18 += v * b3;
|
|
4819
|
-
t19 += v * b4;
|
|
4820
|
-
t20 += v * b5;
|
|
4821
|
-
t21 += v * b6;
|
|
4822
|
-
t22 += v * b7;
|
|
4823
|
-
t23 += v * b8;
|
|
4824
|
-
t24 += v * b9;
|
|
4825
|
-
t25 += v * b10;
|
|
4826
|
-
t26 += v * b11;
|
|
4827
|
-
t27 += v * b12;
|
|
4828
|
-
t28 += v * b13;
|
|
4829
|
-
t29 += v * b14;
|
|
4830
|
-
t30 += v * b15;
|
|
4831
|
-
|
|
4832
|
-
t0 += 38 * t16;
|
|
4833
|
-
t1 += 38 * t17;
|
|
4834
|
-
t2 += 38 * t18;
|
|
4835
|
-
t3 += 38 * t19;
|
|
4836
|
-
t4 += 38 * t20;
|
|
4837
|
-
t5 += 38 * t21;
|
|
4838
|
-
t6 += 38 * t22;
|
|
4839
|
-
t7 += 38 * t23;
|
|
4840
|
-
t8 += 38 * t24;
|
|
4841
|
-
t9 += 38 * t25;
|
|
4842
|
-
t10 += 38 * t26;
|
|
4843
|
-
t11 += 38 * t27;
|
|
4844
|
-
t12 += 38 * t28;
|
|
4845
|
-
t13 += 38 * t29;
|
|
4846
|
-
t14 += 38 * t30;
|
|
4847
|
-
// t15 left as is
|
|
4848
|
-
|
|
4849
|
-
// first car
|
|
4850
|
-
c = 1;
|
|
4851
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
4852
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
4853
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
4854
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
4855
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
4856
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
4857
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
4858
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
4859
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
4860
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
4861
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
4862
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
4863
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
4864
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
4865
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
4866
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
4867
|
-
t0 += c-1 + 37 * (c-1);
|
|
4868
|
-
|
|
4869
|
-
// second car
|
|
4870
|
-
c = 1;
|
|
4871
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
4872
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
4873
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
4874
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
4875
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
4876
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
4877
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
4878
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
4879
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
4880
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
4881
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
4882
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
4883
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
4884
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
4885
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
4886
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
4887
|
-
t0 += c-1 + 37 * (c-1);
|
|
4888
|
-
|
|
4889
|
-
o[ 0] = t0;
|
|
4890
|
-
o[ 1] = t1;
|
|
4891
|
-
o[ 2] = t2;
|
|
4892
|
-
o[ 3] = t3;
|
|
4893
|
-
o[ 4] = t4;
|
|
4894
|
-
o[ 5] = t5;
|
|
4895
|
-
o[ 6] = t6;
|
|
4896
|
-
o[ 7] = t7;
|
|
4897
|
-
o[ 8] = t8;
|
|
4898
|
-
o[ 9] = t9;
|
|
4899
|
-
o[10] = t10;
|
|
4900
|
-
o[11] = t11;
|
|
4901
|
-
o[12] = t12;
|
|
4902
|
-
o[13] = t13;
|
|
4903
|
-
o[14] = t14;
|
|
4904
|
-
o[15] = t15;
|
|
4905
|
-
}
|
|
4906
|
-
|
|
4907
|
-
function S(o, a) {
|
|
4908
|
-
M(o, a, a);
|
|
4909
|
-
}
|
|
4910
|
-
|
|
4911
|
-
function inv25519(o, i) {
|
|
4912
|
-
var c = gf();
|
|
4913
|
-
var a;
|
|
4914
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
4915
|
-
for (a = 253; a >= 0; a--) {
|
|
4916
|
-
S(c, c);
|
|
4917
|
-
if(a !== 2 && a !== 4) M(c, c, i);
|
|
4918
|
-
}
|
|
4919
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
4920
|
-
}
|
|
4921
|
-
|
|
4922
|
-
function pow2523(o, i) {
|
|
4923
|
-
var c = gf();
|
|
4924
|
-
var a;
|
|
4925
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
4926
|
-
for (a = 250; a >= 0; a--) {
|
|
4927
|
-
S(c, c);
|
|
4928
|
-
if(a !== 1) M(c, c, i);
|
|
4929
|
-
}
|
|
4930
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
4931
|
-
}
|
|
4932
|
-
|
|
4933
|
-
function crypto_scalarmult(q, n, p) {
|
|
4934
|
-
var z = new Uint8Array(32);
|
|
4935
|
-
var x = new Float64Array(80), r, i;
|
|
4936
|
-
var a = gf(), b = gf(), c = gf(),
|
|
4937
|
-
d = gf(), e = gf(), f = gf();
|
|
4938
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
4939
|
-
z[31]=(n[31]&127)|64;
|
|
4940
|
-
z[0]&=248;
|
|
4941
|
-
unpack25519(x,p);
|
|
4942
|
-
for (i = 0; i < 16; i++) {
|
|
4943
|
-
b[i]=x[i];
|
|
4944
|
-
d[i]=a[i]=c[i]=0;
|
|
4945
|
-
}
|
|
4946
|
-
a[0]=d[0]=1;
|
|
4947
|
-
for (i=254; i>=0; --i) {
|
|
4948
|
-
r=(z[i>>>3]>>>(i&7))&1;
|
|
4949
|
-
sel25519(a,b,r);
|
|
4950
|
-
sel25519(c,d,r);
|
|
4951
|
-
A(e,a,c);
|
|
4952
|
-
Z(a,a,c);
|
|
4953
|
-
A(c,b,d);
|
|
4954
|
-
Z(b,b,d);
|
|
4955
|
-
S(d,e);
|
|
4956
|
-
S(f,a);
|
|
4957
|
-
M(a,c,a);
|
|
4958
|
-
M(c,b,e);
|
|
4959
|
-
A(e,a,c);
|
|
4960
|
-
Z(a,a,c);
|
|
4961
|
-
S(b,a);
|
|
4962
|
-
Z(c,d,f);
|
|
4963
|
-
M(a,c,_121665);
|
|
4964
|
-
A(a,a,d);
|
|
4965
|
-
M(c,c,a);
|
|
4966
|
-
M(a,d,f);
|
|
4967
|
-
M(d,b,x);
|
|
4968
|
-
S(b,e);
|
|
4969
|
-
sel25519(a,b,r);
|
|
4970
|
-
sel25519(c,d,r);
|
|
4971
|
-
}
|
|
4972
|
-
for (i = 0; i < 16; i++) {
|
|
4973
|
-
x[i+16]=a[i];
|
|
4974
|
-
x[i+32]=c[i];
|
|
4975
|
-
x[i+48]=b[i];
|
|
4976
|
-
x[i+64]=d[i];
|
|
4977
|
-
}
|
|
4978
|
-
var x32 = x.subarray(32);
|
|
4979
|
-
var x16 = x.subarray(16);
|
|
4980
|
-
inv25519(x32,x32);
|
|
4981
|
-
M(x16,x16,x32);
|
|
4982
|
-
pack25519(q,x16);
|
|
4983
|
-
return 0;
|
|
4984
|
-
}
|
|
4985
|
-
|
|
4986
|
-
function crypto_scalarmult_base(q, n) {
|
|
4987
|
-
return crypto_scalarmult(q, n, _9);
|
|
4988
|
-
}
|
|
4989
|
-
|
|
4990
|
-
function crypto_box_keypair(y, x) {
|
|
4991
|
-
randombytes(x, 32);
|
|
4992
|
-
return crypto_scalarmult_base(y, x);
|
|
4993
|
-
}
|
|
4994
|
-
|
|
4995
|
-
function crypto_box_beforenm(k, y, x) {
|
|
4996
|
-
var s = new Uint8Array(32);
|
|
4997
|
-
crypto_scalarmult(s, x, y);
|
|
4998
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
4999
|
-
}
|
|
5000
|
-
|
|
5001
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
5002
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
5003
|
-
|
|
5004
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
5005
|
-
var k = new Uint8Array(32);
|
|
5006
|
-
crypto_box_beforenm(k, y, x);
|
|
5007
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
5008
|
-
}
|
|
5009
|
-
|
|
5010
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
5011
|
-
var k = new Uint8Array(32);
|
|
5012
|
-
crypto_box_beforenm(k, y, x);
|
|
5013
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
5014
|
-
}
|
|
5015
|
-
|
|
5016
|
-
var K = [
|
|
5017
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
5018
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
5019
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
5020
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
5021
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
5022
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
5023
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
5024
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
5025
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
5026
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
5027
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
5028
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
5029
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
5030
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
5031
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
5032
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
5033
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
5034
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
5035
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
5036
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
5037
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
5038
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
5039
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
5040
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
5041
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
5042
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
5043
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
5044
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
5045
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
5046
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
5047
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
5048
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
5049
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
5050
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
5051
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
5052
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
5053
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
5054
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
5055
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
5056
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
5057
|
-
];
|
|
5058
|
-
|
|
5059
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
5060
|
-
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
5061
|
-
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
5062
|
-
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
5063
|
-
th, tl, i, j, h, l, a, b, c, d;
|
|
5064
|
-
|
|
5065
|
-
var ah0 = hh[0],
|
|
5066
|
-
ah1 = hh[1],
|
|
5067
|
-
ah2 = hh[2],
|
|
5068
|
-
ah3 = hh[3],
|
|
5069
|
-
ah4 = hh[4],
|
|
5070
|
-
ah5 = hh[5],
|
|
5071
|
-
ah6 = hh[6],
|
|
5072
|
-
ah7 = hh[7],
|
|
5073
|
-
|
|
5074
|
-
al0 = hl[0],
|
|
5075
|
-
al1 = hl[1],
|
|
5076
|
-
al2 = hl[2],
|
|
5077
|
-
al3 = hl[3],
|
|
5078
|
-
al4 = hl[4],
|
|
5079
|
-
al5 = hl[5],
|
|
5080
|
-
al6 = hl[6],
|
|
5081
|
-
al7 = hl[7];
|
|
5082
|
-
|
|
5083
|
-
var pos = 0;
|
|
5084
|
-
while (n >= 128) {
|
|
5085
|
-
for (i = 0; i < 16; i++) {
|
|
5086
|
-
j = 8 * i + pos;
|
|
5087
|
-
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
5088
|
-
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
5089
|
-
}
|
|
5090
|
-
for (i = 0; i < 80; i++) {
|
|
5091
|
-
bh0 = ah0;
|
|
5092
|
-
bh1 = ah1;
|
|
5093
|
-
bh2 = ah2;
|
|
5094
|
-
bh3 = ah3;
|
|
5095
|
-
bh4 = ah4;
|
|
5096
|
-
bh5 = ah5;
|
|
5097
|
-
bh6 = ah6;
|
|
5098
|
-
bh7 = ah7;
|
|
5099
|
-
|
|
5100
|
-
bl0 = al0;
|
|
5101
|
-
bl1 = al1;
|
|
5102
|
-
bl2 = al2;
|
|
5103
|
-
bl3 = al3;
|
|
5104
|
-
bl4 = al4;
|
|
5105
|
-
bl5 = al5;
|
|
5106
|
-
bl6 = al6;
|
|
5107
|
-
bl7 = al7;
|
|
5108
|
-
|
|
5109
|
-
// add
|
|
5110
|
-
h = ah7;
|
|
5111
|
-
l = al7;
|
|
5112
|
-
|
|
5113
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5114
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5115
|
-
|
|
5116
|
-
// Sigma1
|
|
5117
|
-
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
5118
|
-
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
5119
|
-
|
|
5120
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5121
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5122
|
-
|
|
5123
|
-
// Ch
|
|
5124
|
-
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
5125
|
-
l = (al4 & al5) ^ (~al4 & al6);
|
|
5126
|
-
|
|
5127
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5128
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5129
|
-
|
|
5130
|
-
// K
|
|
5131
|
-
h = K[i*2];
|
|
5132
|
-
l = K[i*2+1];
|
|
5133
|
-
|
|
5134
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5135
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5136
|
-
|
|
5137
|
-
// w
|
|
5138
|
-
h = wh[i%16];
|
|
5139
|
-
l = wl[i%16];
|
|
5140
|
-
|
|
5141
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5142
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5143
|
-
|
|
5144
|
-
b += a >>> 16;
|
|
5145
|
-
c += b >>> 16;
|
|
5146
|
-
d += c >>> 16;
|
|
5147
|
-
|
|
5148
|
-
th = c & 0xffff | d << 16;
|
|
5149
|
-
tl = a & 0xffff | b << 16;
|
|
5150
|
-
|
|
5151
|
-
// add
|
|
5152
|
-
h = th;
|
|
5153
|
-
l = tl;
|
|
5154
|
-
|
|
5155
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5156
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5157
|
-
|
|
5158
|
-
// Sigma0
|
|
5159
|
-
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
5160
|
-
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
5161
|
-
|
|
5162
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5163
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5164
|
-
|
|
5165
|
-
// Maj
|
|
5166
|
-
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
5167
|
-
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
5168
|
-
|
|
5169
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5170
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5171
|
-
|
|
5172
|
-
b += a >>> 16;
|
|
5173
|
-
c += b >>> 16;
|
|
5174
|
-
d += c >>> 16;
|
|
5175
|
-
|
|
5176
|
-
bh7 = (c & 0xffff) | (d << 16);
|
|
5177
|
-
bl7 = (a & 0xffff) | (b << 16);
|
|
5178
|
-
|
|
5179
|
-
// add
|
|
5180
|
-
h = bh3;
|
|
5181
|
-
l = bl3;
|
|
5182
|
-
|
|
5183
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5184
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5185
|
-
|
|
5186
|
-
h = th;
|
|
5187
|
-
l = tl;
|
|
5188
|
-
|
|
5189
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5190
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5191
|
-
|
|
5192
|
-
b += a >>> 16;
|
|
5193
|
-
c += b >>> 16;
|
|
5194
|
-
d += c >>> 16;
|
|
5195
|
-
|
|
5196
|
-
bh3 = (c & 0xffff) | (d << 16);
|
|
5197
|
-
bl3 = (a & 0xffff) | (b << 16);
|
|
5198
|
-
|
|
5199
|
-
ah1 = bh0;
|
|
5200
|
-
ah2 = bh1;
|
|
5201
|
-
ah3 = bh2;
|
|
5202
|
-
ah4 = bh3;
|
|
5203
|
-
ah5 = bh4;
|
|
5204
|
-
ah6 = bh5;
|
|
5205
|
-
ah7 = bh6;
|
|
5206
|
-
ah0 = bh7;
|
|
5207
|
-
|
|
5208
|
-
al1 = bl0;
|
|
5209
|
-
al2 = bl1;
|
|
5210
|
-
al3 = bl2;
|
|
5211
|
-
al4 = bl3;
|
|
5212
|
-
al5 = bl4;
|
|
5213
|
-
al6 = bl5;
|
|
5214
|
-
al7 = bl6;
|
|
5215
|
-
al0 = bl7;
|
|
5216
|
-
|
|
5217
|
-
if (i%16 === 15) {
|
|
5218
|
-
for (j = 0; j < 16; j++) {
|
|
5219
|
-
// add
|
|
5220
|
-
h = wh[j];
|
|
5221
|
-
l = wl[j];
|
|
5222
|
-
|
|
5223
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5224
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5225
|
-
|
|
5226
|
-
h = wh[(j+9)%16];
|
|
5227
|
-
l = wl[(j+9)%16];
|
|
5228
|
-
|
|
5229
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5230
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5231
|
-
|
|
5232
|
-
// sigma0
|
|
5233
|
-
th = wh[(j+1)%16];
|
|
5234
|
-
tl = wl[(j+1)%16];
|
|
5235
|
-
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
5236
|
-
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
5237
|
-
|
|
5238
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5239
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5240
|
-
|
|
5241
|
-
// sigma1
|
|
5242
|
-
th = wh[(j+14)%16];
|
|
5243
|
-
tl = wl[(j+14)%16];
|
|
5244
|
-
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
5245
|
-
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
5246
|
-
|
|
5247
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5248
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5249
|
-
|
|
5250
|
-
b += a >>> 16;
|
|
5251
|
-
c += b >>> 16;
|
|
5252
|
-
d += c >>> 16;
|
|
5253
|
-
|
|
5254
|
-
wh[j] = (c & 0xffff) | (d << 16);
|
|
5255
|
-
wl[j] = (a & 0xffff) | (b << 16);
|
|
5256
|
-
}
|
|
5257
|
-
}
|
|
5258
|
-
}
|
|
5259
|
-
|
|
5260
|
-
// add
|
|
5261
|
-
h = ah0;
|
|
5262
|
-
l = al0;
|
|
5263
|
-
|
|
5264
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5265
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5266
|
-
|
|
5267
|
-
h = hh[0];
|
|
5268
|
-
l = hl[0];
|
|
5269
|
-
|
|
5270
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5271
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5272
|
-
|
|
5273
|
-
b += a >>> 16;
|
|
5274
|
-
c += b >>> 16;
|
|
5275
|
-
d += c >>> 16;
|
|
5276
|
-
|
|
5277
|
-
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
5278
|
-
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
5279
|
-
|
|
5280
|
-
h = ah1;
|
|
5281
|
-
l = al1;
|
|
5282
|
-
|
|
5283
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5284
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5285
|
-
|
|
5286
|
-
h = hh[1];
|
|
5287
|
-
l = hl[1];
|
|
5288
|
-
|
|
5289
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5290
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5291
|
-
|
|
5292
|
-
b += a >>> 16;
|
|
5293
|
-
c += b >>> 16;
|
|
5294
|
-
d += c >>> 16;
|
|
5295
|
-
|
|
5296
|
-
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
5297
|
-
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
5298
|
-
|
|
5299
|
-
h = ah2;
|
|
5300
|
-
l = al2;
|
|
5301
|
-
|
|
5302
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5303
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5304
|
-
|
|
5305
|
-
h = hh[2];
|
|
5306
|
-
l = hl[2];
|
|
5307
|
-
|
|
5308
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5309
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5310
|
-
|
|
5311
|
-
b += a >>> 16;
|
|
5312
|
-
c += b >>> 16;
|
|
5313
|
-
d += c >>> 16;
|
|
5314
|
-
|
|
5315
|
-
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
5316
|
-
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
5317
|
-
|
|
5318
|
-
h = ah3;
|
|
5319
|
-
l = al3;
|
|
5320
|
-
|
|
5321
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5322
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5323
|
-
|
|
5324
|
-
h = hh[3];
|
|
5325
|
-
l = hl[3];
|
|
5326
|
-
|
|
5327
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5328
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5329
|
-
|
|
5330
|
-
b += a >>> 16;
|
|
5331
|
-
c += b >>> 16;
|
|
5332
|
-
d += c >>> 16;
|
|
5333
|
-
|
|
5334
|
-
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
5335
|
-
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
5336
|
-
|
|
5337
|
-
h = ah4;
|
|
5338
|
-
l = al4;
|
|
5339
|
-
|
|
5340
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5341
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5342
|
-
|
|
5343
|
-
h = hh[4];
|
|
5344
|
-
l = hl[4];
|
|
5345
|
-
|
|
5346
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5347
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5348
|
-
|
|
5349
|
-
b += a >>> 16;
|
|
5350
|
-
c += b >>> 16;
|
|
5351
|
-
d += c >>> 16;
|
|
5352
|
-
|
|
5353
|
-
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
5354
|
-
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
5355
|
-
|
|
5356
|
-
h = ah5;
|
|
5357
|
-
l = al5;
|
|
5358
|
-
|
|
5359
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5360
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5361
|
-
|
|
5362
|
-
h = hh[5];
|
|
5363
|
-
l = hl[5];
|
|
5364
|
-
|
|
5365
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5366
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5367
|
-
|
|
5368
|
-
b += a >>> 16;
|
|
5369
|
-
c += b >>> 16;
|
|
5370
|
-
d += c >>> 16;
|
|
5371
|
-
|
|
5372
|
-
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
5373
|
-
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
5374
|
-
|
|
5375
|
-
h = ah6;
|
|
5376
|
-
l = al6;
|
|
5377
|
-
|
|
5378
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5379
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5380
|
-
|
|
5381
|
-
h = hh[6];
|
|
5382
|
-
l = hl[6];
|
|
5383
|
-
|
|
5384
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5385
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5386
|
-
|
|
5387
|
-
b += a >>> 16;
|
|
5388
|
-
c += b >>> 16;
|
|
5389
|
-
d += c >>> 16;
|
|
5390
|
-
|
|
5391
|
-
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
5392
|
-
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
5393
|
-
|
|
5394
|
-
h = ah7;
|
|
5395
|
-
l = al7;
|
|
5396
|
-
|
|
5397
|
-
a = l & 0xffff; b = l >>> 16;
|
|
5398
|
-
c = h & 0xffff; d = h >>> 16;
|
|
5399
|
-
|
|
5400
|
-
h = hh[7];
|
|
5401
|
-
l = hl[7];
|
|
5402
|
-
|
|
5403
|
-
a += l & 0xffff; b += l >>> 16;
|
|
5404
|
-
c += h & 0xffff; d += h >>> 16;
|
|
5405
|
-
|
|
5406
|
-
b += a >>> 16;
|
|
5407
|
-
c += b >>> 16;
|
|
5408
|
-
d += c >>> 16;
|
|
5409
|
-
|
|
5410
|
-
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
5411
|
-
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
5412
|
-
|
|
5413
|
-
pos += 128;
|
|
5414
|
-
n -= 128;
|
|
5415
|
-
}
|
|
5416
|
-
|
|
5417
|
-
return n;
|
|
5418
|
-
}
|
|
5419
|
-
|
|
5420
|
-
function crypto_hash(out, m, n) {
|
|
5421
|
-
var hh = new Int32Array(8),
|
|
5422
|
-
hl = new Int32Array(8),
|
|
5423
|
-
x = new Uint8Array(256),
|
|
5424
|
-
i, b = n;
|
|
5425
|
-
|
|
5426
|
-
hh[0] = 0x6a09e667;
|
|
5427
|
-
hh[1] = 0xbb67ae85;
|
|
5428
|
-
hh[2] = 0x3c6ef372;
|
|
5429
|
-
hh[3] = 0xa54ff53a;
|
|
5430
|
-
hh[4] = 0x510e527f;
|
|
5431
|
-
hh[5] = 0x9b05688c;
|
|
5432
|
-
hh[6] = 0x1f83d9ab;
|
|
5433
|
-
hh[7] = 0x5be0cd19;
|
|
5434
|
-
|
|
5435
|
-
hl[0] = 0xf3bcc908;
|
|
5436
|
-
hl[1] = 0x84caa73b;
|
|
5437
|
-
hl[2] = 0xfe94f82b;
|
|
5438
|
-
hl[3] = 0x5f1d36f1;
|
|
5439
|
-
hl[4] = 0xade682d1;
|
|
5440
|
-
hl[5] = 0x2b3e6c1f;
|
|
5441
|
-
hl[6] = 0xfb41bd6b;
|
|
5442
|
-
hl[7] = 0x137e2179;
|
|
5443
|
-
|
|
5444
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
5445
|
-
n %= 128;
|
|
5446
|
-
|
|
5447
|
-
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
5448
|
-
x[n] = 128;
|
|
5449
|
-
|
|
5450
|
-
n = 256-128*(n<112?1:0);
|
|
5451
|
-
x[n-9] = 0;
|
|
5452
|
-
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
5453
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
5454
|
-
|
|
5455
|
-
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
5456
|
-
|
|
5457
|
-
return 0;
|
|
5458
|
-
}
|
|
5459
|
-
|
|
5460
|
-
function add(p, q) {
|
|
5461
|
-
var a = gf(), b = gf(), c = gf(),
|
|
5462
|
-
d = gf(), e = gf(), f = gf(),
|
|
5463
|
-
g = gf(), h = gf(), t = gf();
|
|
5464
|
-
|
|
5465
|
-
Z(a, p[1], p[0]);
|
|
5466
|
-
Z(t, q[1], q[0]);
|
|
5467
|
-
M(a, a, t);
|
|
5468
|
-
A(b, p[0], p[1]);
|
|
5469
|
-
A(t, q[0], q[1]);
|
|
5470
|
-
M(b, b, t);
|
|
5471
|
-
M(c, p[3], q[3]);
|
|
5472
|
-
M(c, c, D2);
|
|
5473
|
-
M(d, p[2], q[2]);
|
|
5474
|
-
A(d, d, d);
|
|
5475
|
-
Z(e, b, a);
|
|
5476
|
-
Z(f, d, c);
|
|
5477
|
-
A(g, d, c);
|
|
5478
|
-
A(h, b, a);
|
|
5479
|
-
|
|
5480
|
-
M(p[0], e, f);
|
|
5481
|
-
M(p[1], h, g);
|
|
5482
|
-
M(p[2], g, f);
|
|
5483
|
-
M(p[3], e, h);
|
|
5484
|
-
}
|
|
5485
|
-
|
|
5486
|
-
function cswap(p, q, b) {
|
|
5487
|
-
var i;
|
|
5488
|
-
for (i = 0; i < 4; i++) {
|
|
5489
|
-
sel25519(p[i], q[i], b);
|
|
5490
|
-
}
|
|
5491
|
-
}
|
|
5492
|
-
|
|
5493
|
-
function pack(r, p) {
|
|
5494
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
5495
|
-
inv25519(zi, p[2]);
|
|
5496
|
-
M(tx, p[0], zi);
|
|
5497
|
-
M(ty, p[1], zi);
|
|
5498
|
-
pack25519(r, ty);
|
|
5499
|
-
r[31] ^= par25519(tx) << 7;
|
|
5500
|
-
}
|
|
5501
|
-
|
|
5502
|
-
function scalarmult(p, q, s) {
|
|
5503
|
-
var b, i;
|
|
5504
|
-
set25519(p[0], gf0);
|
|
5505
|
-
set25519(p[1], gf1);
|
|
5506
|
-
set25519(p[2], gf1);
|
|
5507
|
-
set25519(p[3], gf0);
|
|
5508
|
-
for (i = 255; i >= 0; --i) {
|
|
5509
|
-
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
5510
|
-
cswap(p, q, b);
|
|
5511
|
-
add(q, p);
|
|
5512
|
-
add(p, p);
|
|
5513
|
-
cswap(p, q, b);
|
|
5514
|
-
}
|
|
5515
|
-
}
|
|
5516
|
-
|
|
5517
|
-
function scalarbase(p, s) {
|
|
5518
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
5519
|
-
set25519(q[0], X);
|
|
5520
|
-
set25519(q[1], Y);
|
|
5521
|
-
set25519(q[2], gf1);
|
|
5522
|
-
M(q[3], X, Y);
|
|
5523
|
-
scalarmult(p, q, s);
|
|
5524
|
-
}
|
|
5525
|
-
|
|
5526
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
5527
|
-
var d = new Uint8Array(64);
|
|
5528
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
5529
|
-
var i;
|
|
5530
|
-
|
|
5531
|
-
if (!seeded) randombytes(sk, 32);
|
|
5532
|
-
crypto_hash(d, sk, 32);
|
|
5533
|
-
d[0] &= 248;
|
|
5534
|
-
d[31] &= 127;
|
|
5535
|
-
d[31] |= 64;
|
|
5536
|
-
|
|
5537
|
-
scalarbase(p, d);
|
|
5538
|
-
pack(pk, p);
|
|
5539
|
-
|
|
5540
|
-
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
5541
|
-
return 0;
|
|
5542
|
-
}
|
|
5543
|
-
|
|
5544
|
-
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]);
|
|
5545
|
-
|
|
5546
|
-
function modL(r, x) {
|
|
5547
|
-
var carry, i, j, k;
|
|
5548
|
-
for (i = 63; i >= 32; --i) {
|
|
5549
|
-
carry = 0;
|
|
5550
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
5551
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
5552
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
5553
|
-
x[j] -= carry * 256;
|
|
5554
|
-
}
|
|
5555
|
-
x[j] += carry;
|
|
5556
|
-
x[i] = 0;
|
|
5557
|
-
}
|
|
5558
|
-
carry = 0;
|
|
5559
|
-
for (j = 0; j < 32; j++) {
|
|
5560
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
5561
|
-
carry = x[j] >> 8;
|
|
5562
|
-
x[j] &= 255;
|
|
5563
|
-
}
|
|
5564
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
5565
|
-
for (i = 0; i < 32; i++) {
|
|
5566
|
-
x[i+1] += x[i] >> 8;
|
|
5567
|
-
r[i] = x[i] & 255;
|
|
5568
|
-
}
|
|
5569
|
-
}
|
|
5570
|
-
|
|
5571
|
-
function reduce(r) {
|
|
5572
|
-
var x = new Float64Array(64), i;
|
|
5573
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
5574
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
5575
|
-
modL(r, x);
|
|
5576
|
-
}
|
|
5577
|
-
|
|
5578
|
-
// Note: difference from C - smlen returned, not passed as argument.
|
|
5579
|
-
function crypto_sign(sm, m, n, sk) {
|
|
5580
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
5581
|
-
var i, j, x = new Float64Array(64);
|
|
5582
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
5583
|
-
|
|
5584
|
-
crypto_hash(d, sk, 32);
|
|
5585
|
-
d[0] &= 248;
|
|
5586
|
-
d[31] &= 127;
|
|
5587
|
-
d[31] |= 64;
|
|
5588
|
-
|
|
5589
|
-
var smlen = n + 64;
|
|
5590
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
5591
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
5592
|
-
|
|
5593
|
-
crypto_hash(r, sm.subarray(32), n+32);
|
|
5594
|
-
reduce(r);
|
|
5595
|
-
scalarbase(p, r);
|
|
5596
|
-
pack(sm, p);
|
|
5597
|
-
|
|
5598
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
5599
|
-
crypto_hash(h, sm, n + 64);
|
|
5600
|
-
reduce(h);
|
|
5601
|
-
|
|
5602
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
5603
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
5604
|
-
for (i = 0; i < 32; i++) {
|
|
5605
|
-
for (j = 0; j < 32; j++) {
|
|
5606
|
-
x[i+j] += h[i] * d[j];
|
|
5607
|
-
}
|
|
5608
|
-
}
|
|
5609
|
-
|
|
5610
|
-
modL(sm.subarray(32), x);
|
|
5611
|
-
return smlen;
|
|
5612
|
-
}
|
|
5613
|
-
|
|
5614
|
-
function unpackneg(r, p) {
|
|
5615
|
-
var t = gf(), chk = gf(), num = gf(),
|
|
5616
|
-
den = gf(), den2 = gf(), den4 = gf(),
|
|
5617
|
-
den6 = gf();
|
|
5618
|
-
|
|
5619
|
-
set25519(r[2], gf1);
|
|
5620
|
-
unpack25519(r[1], p);
|
|
5621
|
-
S(num, r[1]);
|
|
5622
|
-
M(den, num, D);
|
|
5623
|
-
Z(num, num, r[2]);
|
|
5624
|
-
A(den, r[2], den);
|
|
5625
|
-
|
|
5626
|
-
S(den2, den);
|
|
5627
|
-
S(den4, den2);
|
|
5628
|
-
M(den6, den4, den2);
|
|
5629
|
-
M(t, den6, num);
|
|
5630
|
-
M(t, t, den);
|
|
5631
|
-
|
|
5632
|
-
pow2523(t, t);
|
|
5633
|
-
M(t, t, num);
|
|
5634
|
-
M(t, t, den);
|
|
5635
|
-
M(t, t, den);
|
|
5636
|
-
M(r[0], t, den);
|
|
5637
|
-
|
|
5638
|
-
S(chk, r[0]);
|
|
5639
|
-
M(chk, chk, den);
|
|
5640
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
5641
|
-
|
|
5642
|
-
S(chk, r[0]);
|
|
5643
|
-
M(chk, chk, den);
|
|
5644
|
-
if (neq25519(chk, num)) return -1;
|
|
5645
|
-
|
|
5646
|
-
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
5647
|
-
|
|
5648
|
-
M(r[3], r[0], r[1]);
|
|
5649
|
-
return 0;
|
|
5650
|
-
}
|
|
5651
|
-
|
|
5652
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
5653
|
-
var i;
|
|
5654
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
5655
|
-
var p = [gf(), gf(), gf(), gf()],
|
|
5656
|
-
q = [gf(), gf(), gf(), gf()];
|
|
5657
|
-
|
|
5658
|
-
if (n < 64) return -1;
|
|
5659
|
-
|
|
5660
|
-
if (unpackneg(q, pk)) return -1;
|
|
5661
|
-
|
|
5662
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
5663
|
-
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
5664
|
-
crypto_hash(h, m, n);
|
|
5665
|
-
reduce(h);
|
|
5666
|
-
scalarmult(p, q, h);
|
|
5667
|
-
|
|
5668
|
-
scalarbase(q, sm.subarray(32));
|
|
5669
|
-
add(p, q);
|
|
5670
|
-
pack(t, p);
|
|
5671
|
-
|
|
5672
|
-
n -= 64;
|
|
5673
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
5674
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
5675
|
-
return -1;
|
|
5676
|
-
}
|
|
5677
|
-
|
|
5678
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
5679
|
-
return n;
|
|
5680
|
-
}
|
|
5681
|
-
|
|
5682
|
-
var crypto_secretbox_KEYBYTES = 32,
|
|
5683
|
-
crypto_secretbox_NONCEBYTES = 24,
|
|
5684
|
-
crypto_secretbox_ZEROBYTES = 32,
|
|
5685
|
-
crypto_secretbox_BOXZEROBYTES = 16,
|
|
5686
|
-
crypto_scalarmult_BYTES = 32,
|
|
5687
|
-
crypto_scalarmult_SCALARBYTES = 32,
|
|
5688
|
-
crypto_box_PUBLICKEYBYTES = 32,
|
|
5689
|
-
crypto_box_SECRETKEYBYTES = 32,
|
|
5690
|
-
crypto_box_BEFORENMBYTES = 32,
|
|
5691
|
-
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
5692
|
-
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
5693
|
-
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
5694
|
-
crypto_sign_BYTES = 64,
|
|
5695
|
-
crypto_sign_PUBLICKEYBYTES = 32,
|
|
5696
|
-
crypto_sign_SECRETKEYBYTES = 64,
|
|
5697
|
-
crypto_sign_SEEDBYTES = 32,
|
|
5698
|
-
crypto_hash_BYTES = 64;
|
|
5699
|
-
|
|
5700
|
-
nacl.lowlevel = {
|
|
5701
|
-
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
5702
|
-
crypto_stream_xor: crypto_stream_xor,
|
|
5703
|
-
crypto_stream: crypto_stream,
|
|
5704
|
-
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
5705
|
-
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
5706
|
-
crypto_onetimeauth: crypto_onetimeauth,
|
|
5707
|
-
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
5708
|
-
crypto_verify_16: crypto_verify_16,
|
|
5709
|
-
crypto_verify_32: crypto_verify_32,
|
|
5710
|
-
crypto_secretbox: crypto_secretbox,
|
|
5711
|
-
crypto_secretbox_open: crypto_secretbox_open,
|
|
5712
|
-
crypto_scalarmult: crypto_scalarmult,
|
|
5713
|
-
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
5714
|
-
crypto_box_beforenm: crypto_box_beforenm,
|
|
5715
|
-
crypto_box_afternm: crypto_box_afternm,
|
|
5716
|
-
crypto_box: crypto_box,
|
|
5717
|
-
crypto_box_open: crypto_box_open,
|
|
5718
|
-
crypto_box_keypair: crypto_box_keypair,
|
|
5719
|
-
crypto_hash: crypto_hash,
|
|
5720
|
-
crypto_sign: crypto_sign,
|
|
5721
|
-
crypto_sign_keypair: crypto_sign_keypair,
|
|
5722
|
-
crypto_sign_open: crypto_sign_open,
|
|
5723
|
-
|
|
5724
|
-
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
5725
|
-
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
5726
|
-
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
5727
|
-
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
5728
|
-
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
5729
|
-
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
5730
|
-
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
5731
|
-
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
5732
|
-
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
5733
|
-
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
5734
|
-
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
5735
|
-
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
5736
|
-
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
5737
|
-
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
5738
|
-
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
5739
|
-
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
5740
|
-
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
5741
|
-
|
|
5742
|
-
gf: gf,
|
|
5743
|
-
D: D,
|
|
5744
|
-
L: L,
|
|
5745
|
-
pack25519: pack25519,
|
|
5746
|
-
unpack25519: unpack25519,
|
|
5747
|
-
M: M,
|
|
5748
|
-
A: A,
|
|
5749
|
-
S: S,
|
|
5750
|
-
Z: Z,
|
|
5751
|
-
pow2523: pow2523,
|
|
5752
|
-
add: add,
|
|
5753
|
-
set25519: set25519,
|
|
5754
|
-
modL: modL,
|
|
5755
|
-
scalarmult: scalarmult,
|
|
5756
|
-
scalarbase: scalarbase,
|
|
5757
|
-
};
|
|
5758
|
-
|
|
5759
|
-
/* High-level API */
|
|
5760
|
-
|
|
5761
|
-
function checkLengths(k, n) {
|
|
5762
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
5763
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
5764
|
-
}
|
|
5765
|
-
|
|
5766
|
-
function checkBoxLengths(pk, sk) {
|
|
5767
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
5768
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
5769
|
-
}
|
|
5770
|
-
|
|
5771
|
-
function checkArrayTypes() {
|
|
5772
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
5773
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
5774
|
-
throw new TypeError('unexpected type, use Uint8Array');
|
|
5775
|
-
}
|
|
5776
|
-
}
|
|
5777
|
-
|
|
5778
|
-
function cleanup(arr) {
|
|
5779
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
5780
|
-
}
|
|
5781
|
-
|
|
5782
|
-
nacl.randomBytes = function(n) {
|
|
5783
|
-
var b = new Uint8Array(n);
|
|
5784
|
-
randombytes(b, n);
|
|
5785
|
-
return b;
|
|
5786
|
-
};
|
|
5787
|
-
|
|
5788
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
5789
|
-
checkArrayTypes(msg, nonce, key);
|
|
5790
|
-
checkLengths(key, nonce);
|
|
5791
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
5792
|
-
var c = new Uint8Array(m.length);
|
|
5793
|
-
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
5794
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
5795
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
5796
|
-
};
|
|
5797
|
-
|
|
5798
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
5799
|
-
checkArrayTypes(box, nonce, key);
|
|
5800
|
-
checkLengths(key, nonce);
|
|
5801
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
5802
|
-
var m = new Uint8Array(c.length);
|
|
5803
|
-
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
5804
|
-
if (c.length < 32) return null;
|
|
5805
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
5806
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
5807
|
-
};
|
|
5808
|
-
|
|
5809
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
5810
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
5811
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
5812
|
-
|
|
5813
|
-
nacl.scalarMult = function(n, p) {
|
|
5814
|
-
checkArrayTypes(n, p);
|
|
5815
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
5816
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
5817
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
5818
|
-
crypto_scalarmult(q, n, p);
|
|
5819
|
-
return q;
|
|
5820
|
-
};
|
|
5821
|
-
|
|
5822
|
-
nacl.scalarMult.base = function(n) {
|
|
5823
|
-
checkArrayTypes(n);
|
|
5824
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
5825
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
5826
|
-
crypto_scalarmult_base(q, n);
|
|
5827
|
-
return q;
|
|
5828
|
-
};
|
|
5829
|
-
|
|
5830
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
5831
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
5832
|
-
|
|
5833
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
5834
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
5835
|
-
return nacl.secretbox(msg, nonce, k);
|
|
5836
|
-
};
|
|
5837
|
-
|
|
5838
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
5839
|
-
checkArrayTypes(publicKey, secretKey);
|
|
5840
|
-
checkBoxLengths(publicKey, secretKey);
|
|
5841
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
5842
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
5843
|
-
return k;
|
|
5844
|
-
};
|
|
5845
|
-
|
|
5846
|
-
nacl.box.after = nacl.secretbox;
|
|
5847
|
-
|
|
5848
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
5849
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
5850
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
5851
|
-
};
|
|
5852
|
-
|
|
5853
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
5854
|
-
|
|
5855
|
-
nacl.box.keyPair = function() {
|
|
5856
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
5857
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
5858
|
-
crypto_box_keypair(pk, sk);
|
|
5859
|
-
return {publicKey: pk, secretKey: sk};
|
|
5860
|
-
};
|
|
5861
|
-
|
|
5862
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
5863
|
-
checkArrayTypes(secretKey);
|
|
5864
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
5865
|
-
throw new Error('bad secret key size');
|
|
5866
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
5867
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
5868
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
5869
|
-
};
|
|
5870
|
-
|
|
5871
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
5872
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
5873
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
5874
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
5875
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
5876
|
-
|
|
5877
|
-
nacl.sign = function(msg, secretKey) {
|
|
5878
|
-
checkArrayTypes(msg, secretKey);
|
|
5879
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
5880
|
-
throw new Error('bad secret key size');
|
|
5881
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
5882
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
5883
|
-
return signedMsg;
|
|
5884
|
-
};
|
|
5885
|
-
|
|
5886
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
5887
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
5888
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
5889
|
-
throw new Error('bad public key size');
|
|
5890
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
5891
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
5892
|
-
if (mlen < 0) return null;
|
|
5893
|
-
var m = new Uint8Array(mlen);
|
|
5894
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
5895
|
-
return m;
|
|
5896
|
-
};
|
|
5897
|
-
|
|
5898
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
5899
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
5900
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
5901
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
5902
|
-
return sig;
|
|
5903
|
-
};
|
|
5904
|
-
|
|
5905
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
5906
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
5907
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
5908
|
-
throw new Error('bad signature size');
|
|
5909
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
5910
|
-
throw new Error('bad public key size');
|
|
5911
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
5912
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
5913
|
-
var i;
|
|
5914
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
5915
|
-
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
5916
|
-
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
5917
|
-
};
|
|
5918
|
-
|
|
5919
|
-
nacl.sign.keyPair = function() {
|
|
5920
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
5921
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
5922
|
-
crypto_sign_keypair(pk, sk);
|
|
5923
|
-
return {publicKey: pk, secretKey: sk};
|
|
5924
|
-
};
|
|
5925
|
-
|
|
5926
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
5927
|
-
checkArrayTypes(secretKey);
|
|
5928
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
5929
|
-
throw new Error('bad secret key size');
|
|
5930
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
5931
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
5932
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
5933
|
-
};
|
|
5934
|
-
|
|
5935
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
5936
|
-
checkArrayTypes(seed);
|
|
5937
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
5938
|
-
throw new Error('bad seed size');
|
|
5939
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
5940
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
5941
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
5942
|
-
crypto_sign_keypair(pk, sk, true);
|
|
5943
|
-
return {publicKey: pk, secretKey: sk};
|
|
5944
|
-
};
|
|
5945
|
-
|
|
5946
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
5947
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
5948
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
5949
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
5950
|
-
|
|
5951
|
-
nacl.hash = function(msg) {
|
|
5952
|
-
checkArrayTypes(msg);
|
|
5953
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
5954
|
-
crypto_hash(h, msg, msg.length);
|
|
5955
|
-
return h;
|
|
5956
|
-
};
|
|
5957
|
-
|
|
5958
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
5959
|
-
|
|
5960
|
-
nacl.verify = function(x, y) {
|
|
5961
|
-
checkArrayTypes(x, y);
|
|
5962
|
-
// Zero length arguments are considered not equal.
|
|
5963
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
5964
|
-
if (x.length !== y.length) return false;
|
|
5965
|
-
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
5966
|
-
};
|
|
5967
|
-
|
|
5968
|
-
nacl.setPRNG = function(fn) {
|
|
5969
|
-
randombytes = fn;
|
|
5970
|
-
};
|
|
5971
|
-
|
|
5972
|
-
(function() {
|
|
5973
|
-
// Initialize PRNG if environment provides CSPRNG.
|
|
5974
|
-
// If not, methods calling randombytes will throw.
|
|
5975
|
-
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
5976
|
-
if (crypto && crypto.getRandomValues) {
|
|
5977
|
-
// Browsers.
|
|
5978
|
-
var QUOTA = 65536;
|
|
5979
|
-
nacl.setPRNG(function(x, n) {
|
|
5980
|
-
var i, v = new Uint8Array(n);
|
|
5981
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
5982
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
5983
|
-
}
|
|
5984
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
5985
|
-
cleanup(v);
|
|
5986
|
-
});
|
|
5987
|
-
} else if (typeof commonjsRequire !== 'undefined') {
|
|
5988
|
-
// Node.js.
|
|
5989
|
-
crypto = require$$0;
|
|
5990
|
-
if (crypto && crypto.randomBytes) {
|
|
5991
|
-
nacl.setPRNG(function(x, n) {
|
|
5992
|
-
var i, v = crypto.randomBytes(n);
|
|
5993
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
5994
|
-
cleanup(v);
|
|
5995
|
-
});
|
|
5996
|
-
}
|
|
5997
|
-
}
|
|
5998
|
-
})();
|
|
5999
|
-
|
|
6000
|
-
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
6001
|
-
} (naclFast));
|
|
6002
|
-
return naclFast.exports;
|
|
6003
|
-
}
|
|
6004
|
-
|
|
6005
|
-
var naclFastExports = requireNaclFast();
|
|
6006
|
-
var nacl = /*@__PURE__*/getDefaultExportFromCjs(naclFastExports);
|
|
6007
|
-
|
|
6008
3566
|
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
6009
3567
|
//
|
|
6010
3568
|
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
6011
3569
|
// Bounded account address; it signs the auth challenge exactly like a wallet.
|
|
6012
3570
|
//
|
|
6013
|
-
//
|
|
6014
|
-
//
|
|
6015
|
-
//
|
|
6016
|
-
//
|
|
6017
|
-
// 2. tweetnacl keypair in platform storage (React Native / older browsers) —
|
|
6018
|
-
// the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
|
|
6019
|
-
// treat it as a low-stakes guest identity and tell users to upgrade
|
|
6020
|
-
// (link an email) before they care about not losing it.
|
|
3571
|
+
// Guest auth has one backend: WebCrypto Ed25519 + IndexedDB. The key is
|
|
3572
|
+
// NON-EXTRACTABLE: an XSS can ask it to sign but can never read the private
|
|
3573
|
+
// bytes. If WebCrypto or IndexedDB is unavailable, guest auth fails closed
|
|
3574
|
+
// instead of silently creating an extractable/stored-secret credential.
|
|
6021
3575
|
//
|
|
6022
|
-
//
|
|
3576
|
+
// The public output is a base58 address + a base64
|
|
6023
3577
|
// detached signature, which is the format the session endpoint already accepts.
|
|
6024
|
-
const
|
|
3578
|
+
const LEGACY_STORED_SECRET_KEY = 'bounded_guest_key_v1';
|
|
6025
3579
|
const IDB_NAME = 'bounded-guest';
|
|
6026
3580
|
const IDB_STORE = 'keys';
|
|
6027
3581
|
const IDB_KEY = 'ed25519';
|
|
3582
|
+
const GUEST_KEY_REQUIREMENT = 'Guest auth requires non-extractable WebCrypto Ed25519 keys persisted in IndexedDB; ' +
|
|
3583
|
+
'stored-secret guest credentials are disabled.';
|
|
6028
3584
|
function toBase64(bytes) {
|
|
6029
3585
|
let bin = '';
|
|
6030
3586
|
for (let i = 0; i < bytes.length; i++)
|
|
@@ -6059,10 +3615,17 @@ function idbPut(db, key, val) {
|
|
|
6059
3615
|
r.onerror = () => reject(r.error);
|
|
6060
3616
|
});
|
|
6061
3617
|
}
|
|
6062
|
-
|
|
3618
|
+
function guestKeyUnavailable(cause) {
|
|
3619
|
+
const detail = cause instanceof Error && cause.message ? ` Cause: ${cause.message}` : '';
|
|
3620
|
+
return new Error(`${GUEST_KEY_REQUIREMENT}${detail}`);
|
|
3621
|
+
}
|
|
3622
|
+
async function webCryptoKey() {
|
|
6063
3623
|
const s = subtle();
|
|
6064
|
-
if (!s
|
|
6065
|
-
|
|
3624
|
+
if (!s)
|
|
3625
|
+
throw guestKeyUnavailable(new Error('WebCrypto subtle crypto is unavailable.'));
|
|
3626
|
+
if (typeof globalThis.indexedDB === 'undefined') {
|
|
3627
|
+
throw guestKeyUnavailable(new Error('IndexedDB is unavailable.'));
|
|
3628
|
+
}
|
|
6066
3629
|
try {
|
|
6067
3630
|
const db = await idb();
|
|
6068
3631
|
let pair = (await idbGet(db, IDB_KEY));
|
|
@@ -6086,49 +3649,23 @@ async function tryWebCrypto() {
|
|
|
6086
3649
|
},
|
|
6087
3650
|
};
|
|
6088
3651
|
}
|
|
6089
|
-
catch (
|
|
6090
|
-
|
|
3652
|
+
catch (error) {
|
|
3653
|
+
throw guestKeyUnavailable(error);
|
|
6091
3654
|
}
|
|
6092
3655
|
}
|
|
6093
|
-
// ----- tweetnacl (stored-secret) fallback ------------------------------------
|
|
6094
|
-
function fallbackKey() {
|
|
6095
|
-
const store = getPlatform().storage;
|
|
6096
|
-
let secret;
|
|
6097
|
-
const saved = store.getItem(FALLBACK_STORE_KEY);
|
|
6098
|
-
if (saved) {
|
|
6099
|
-
secret = bs58.decode(saved);
|
|
6100
|
-
}
|
|
6101
|
-
else {
|
|
6102
|
-
const kp = Keypair.generate();
|
|
6103
|
-
secret = kp.secretKey; // 64 bytes
|
|
6104
|
-
store.setItem(FALLBACK_STORE_KEY, bs58.encode(secret));
|
|
6105
|
-
}
|
|
6106
|
-
const kp = Keypair.fromSecretKey(secret);
|
|
6107
|
-
const address = kp.publicKey.toBase58();
|
|
6108
|
-
return {
|
|
6109
|
-
address,
|
|
6110
|
-
nonExtractable: false,
|
|
6111
|
-
async sign(message) {
|
|
6112
|
-
const data = new TextEncoder().encode(message);
|
|
6113
|
-
const sig = nacl.sign.detached(data, secret);
|
|
6114
|
-
return toBase64(sig);
|
|
6115
|
-
},
|
|
6116
|
-
};
|
|
6117
|
-
}
|
|
6118
3656
|
let cached = null;
|
|
6119
3657
|
/** Get (or create) this device's durable guest key. */
|
|
6120
3658
|
async function getGuestKey() {
|
|
6121
|
-
var _a;
|
|
6122
3659
|
if (cached)
|
|
6123
3660
|
return cached;
|
|
6124
|
-
cached =
|
|
3661
|
+
cached = await webCryptoKey();
|
|
6125
3662
|
return cached;
|
|
6126
3663
|
}
|
|
6127
3664
|
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
6128
3665
|
async function clearGuestKey() {
|
|
6129
3666
|
cached = null;
|
|
6130
3667
|
try {
|
|
6131
|
-
getPlatform().storage.removeItem(
|
|
3668
|
+
getPlatform().storage.removeItem(LEGACY_STORED_SECRET_KEY);
|
|
6132
3669
|
}
|
|
6133
3670
|
catch (_a) { }
|
|
6134
3671
|
try {
|
|
@@ -6670,6 +4207,50 @@ const MODAL_CSS = `
|
|
|
6670
4207
|
#bounded-auth-modal .hidden{display:none;}
|
|
6671
4208
|
@media (max-width:480px){#bounded-auth-modal .ba-card{max-width:none;border-radius:16px;}}`;
|
|
6672
4209
|
|
|
4210
|
+
const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
4211
|
+
const SUPPORTED_SOLANA_NETWORKS = new Set([
|
|
4212
|
+
"solana_devnet",
|
|
4213
|
+
"solana_mainnet",
|
|
4214
|
+
"surfnet",
|
|
4215
|
+
]);
|
|
4216
|
+
function normalizeSolanaRpcUrl(rpcUrl) {
|
|
4217
|
+
if (typeof rpcUrl !== "string")
|
|
4218
|
+
return null;
|
|
4219
|
+
const trimmed = rpcUrl.trim();
|
|
4220
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
4221
|
+
}
|
|
4222
|
+
function isSupportedSolanaRpcNetwork(network) {
|
|
4223
|
+
return typeof network === "string" && SUPPORTED_SOLANA_NETWORKS.has(network);
|
|
4224
|
+
}
|
|
4225
|
+
function resolveSolanaWalletStandardChain(network, context) {
|
|
4226
|
+
switch (network) {
|
|
4227
|
+
case "solana_devnet":
|
|
4228
|
+
return "solana:devnet";
|
|
4229
|
+
case "solana_mainnet":
|
|
4230
|
+
return "solana:mainnet";
|
|
4231
|
+
case "surfnet":
|
|
4232
|
+
return "solana:localnet";
|
|
4233
|
+
case undefined:
|
|
4234
|
+
case null:
|
|
4235
|
+
case "":
|
|
4236
|
+
throw new Error(`${context} requires an explicit Solana network. ` +
|
|
4237
|
+
`Provide one of: solana_devnet, solana_mainnet, surfnet.`);
|
|
4238
|
+
default:
|
|
4239
|
+
throw new Error(`${context} does not support Solana network "${network}". ` +
|
|
4240
|
+
`Expected one of: solana_devnet, solana_mainnet, surfnet.`);
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
function resolveSolanaRpcUrl(explicitRpcUrl, network, context) {
|
|
4244
|
+
if (network != null && network !== "" && !isSupportedSolanaRpcNetwork(network)) {
|
|
4245
|
+
throw new Error(`${context} does not support Solana network "${network}". ` +
|
|
4246
|
+
`Expected one of: solana_devnet, solana_mainnet, surfnet.`);
|
|
4247
|
+
}
|
|
4248
|
+
const rpcUrl = normalizeSolanaRpcUrl(explicitRpcUrl);
|
|
4249
|
+
if (rpcUrl)
|
|
4250
|
+
return rpcUrl;
|
|
4251
|
+
throw new Error(`${context} requires an explicit Solana RPC URL. Pass config.rpcUrl before signing or submitting onchain transactions.`);
|
|
4252
|
+
}
|
|
4253
|
+
|
|
6673
4254
|
const PKCE_STORE_KEY = 'bounded.oidc.pkce';
|
|
6674
4255
|
// Active session store (Web on web, RN on React Native) — selected by config,
|
|
6675
4256
|
// not by `typeof window` (truthy on RN). OIDC redirect/popup is web-only, but the
|
|
@@ -6976,7 +4557,7 @@ async function exchangeCode(code, verifier, redirectUri) {
|
|
|
6976
4557
|
let currentAuthProvider = null;
|
|
6977
4558
|
let currentAuthMethod = null;
|
|
6978
4559
|
let initConfig = null;
|
|
6979
|
-
// --- localStorage helpers: track which auth method the
|
|
4560
|
+
// --- localStorage helpers: track which auth method created the active session ---
|
|
6980
4561
|
const STORED_AUTH_METHOD_KEY = 'bounded_last_auth_method';
|
|
6981
4562
|
function getStoredAuthMethod() {
|
|
6982
4563
|
try {
|
|
@@ -7000,7 +4581,7 @@ function setStoredAuthMethod(method) {
|
|
|
7000
4581
|
}
|
|
7001
4582
|
}
|
|
7002
4583
|
/**
|
|
7003
|
-
* Clears the session if it was created
|
|
4584
|
+
* Clears the session if it was created by a different auth method.
|
|
7004
4585
|
* Returns true if the session was cleared, false if the session is compatible.
|
|
7005
4586
|
*
|
|
7006
4587
|
* Dispatches to the correct session manager based on the current auth method
|
|
@@ -7008,47 +4589,128 @@ function setStoredAuthMethod(method) {
|
|
|
7008
4589
|
* are properly cleared.
|
|
7009
4590
|
*/
|
|
7010
4591
|
function clearIncompatibleSession() {
|
|
7011
|
-
if (getStoredAuthMethod()
|
|
7012
|
-
return false;
|
|
4592
|
+
if (getStoredAuthMethod() === currentAuthMethod) {
|
|
4593
|
+
return false;
|
|
7013
4594
|
}
|
|
7014
|
-
//
|
|
7015
|
-
//
|
|
7016
|
-
// Clear both managers — on web the RN manager is a no-op (not configured),
|
|
7017
|
-
// on RN the web manager is a no-op (no localStorage).
|
|
4595
|
+
// Clear both managers: on web the RN manager is a no-op (not configured),
|
|
4596
|
+
// and on RN the web manager is a no-op (no localStorage).
|
|
7018
4597
|
WebSessionManager.clearSession();
|
|
7019
4598
|
try {
|
|
7020
4599
|
ReactNativeSessionManager.clearSession();
|
|
7021
4600
|
}
|
|
7022
4601
|
catch ( /* not configured on web */_a) { /* not configured on web */ }
|
|
4602
|
+
setStoredAuthMethod(null);
|
|
7023
4603
|
return true;
|
|
7024
4604
|
}
|
|
7025
4605
|
// Lazy loaders for web-only providers.
|
|
7026
4606
|
// Using dynamic import() ensures Metro (RN) never resolves these modules.
|
|
7027
4607
|
async function loadPhantomWalletProvider() {
|
|
7028
|
-
const mod = await import('./phantom-wallet-provider-
|
|
4608
|
+
const mod = await import('./phantom-wallet-provider-DDwgNMg_.mjs');
|
|
7029
4609
|
return { PhantomWalletProvider: mod.PhantomWalletProvider };
|
|
7030
4610
|
}
|
|
7031
4611
|
// Web Privy provider (depends on react-dom + @privy-io/react-auth). Lazy so Metro
|
|
7032
4612
|
// never bundles it into the RN build — RN uses the @privy-io/expo provider instead.
|
|
7033
4613
|
async function loadPrivyWalletProvider() {
|
|
7034
|
-
const mod = await import('./privy-wallet-provider-
|
|
4614
|
+
const mod = await import('./privy-wallet-provider-D7VoQCYf.mjs');
|
|
7035
4615
|
return mod.PrivyWalletProvider;
|
|
7036
4616
|
}
|
|
7037
4617
|
async function loadSolanaMobileWalletProvider() {
|
|
7038
|
-
const mod = await import('./solana-mobile-wallet-provider-
|
|
4618
|
+
const mod = await import('./solana-mobile-wallet-provider-DgcGxDoL.mjs');
|
|
7039
4619
|
return mod.SolanaMobileWalletProvider;
|
|
7040
4620
|
}
|
|
4621
|
+
function requireWebPrivyConfig(config) {
|
|
4622
|
+
if (!config.privyConfig || typeof config.privyConfig.appId !== 'string' || config.privyConfig.appId.trim() === '') {
|
|
4623
|
+
throw new Error('Privy auth requires config.privyConfig.appId; no default Privy app is used.');
|
|
4624
|
+
}
|
|
4625
|
+
if (!config.privyConfig.config || typeof config.privyConfig.config !== 'object') {
|
|
4626
|
+
throw new Error('Privy auth requires config.privyConfig.config for the app-scoped Privy provider.');
|
|
4627
|
+
}
|
|
4628
|
+
return config.privyConfig;
|
|
4629
|
+
}
|
|
4630
|
+
function getConfiguredSolanaNetwork(config) {
|
|
4631
|
+
if (typeof config.chain !== 'string')
|
|
4632
|
+
return null;
|
|
4633
|
+
const chain = config.chain.trim();
|
|
4634
|
+
if (chain === '' || chain === 'offchain')
|
|
4635
|
+
return null;
|
|
4636
|
+
return chain;
|
|
4637
|
+
}
|
|
4638
|
+
function mobileWalletClusterFromNetwork(network) {
|
|
4639
|
+
switch (network) {
|
|
4640
|
+
case "solana_devnet":
|
|
4641
|
+
return "devnet";
|
|
4642
|
+
case "solana_mainnet":
|
|
4643
|
+
return "mainnet-beta";
|
|
4644
|
+
case "surfnet":
|
|
4645
|
+
return "localnet";
|
|
4646
|
+
case null:
|
|
4647
|
+
return null;
|
|
4648
|
+
default:
|
|
4649
|
+
resolveSolanaWalletStandardChain(network, "Mobile wallet auth");
|
|
4650
|
+
return null;
|
|
4651
|
+
}
|
|
4652
|
+
}
|
|
4653
|
+
function requireMobileWalletConfig(config) {
|
|
4654
|
+
var _a, _b, _c;
|
|
4655
|
+
const configuredNetwork = getConfiguredSolanaNetwork(config);
|
|
4656
|
+
const cluster = (_b = (_a = config.mobileWalletConfig) === null || _a === void 0 ? void 0 : _a.cluster) !== null && _b !== void 0 ? _b : mobileWalletClusterFromNetwork(configuredNetwork);
|
|
4657
|
+
if (!cluster) {
|
|
4658
|
+
throw new Error("Mobile wallet auth requires an explicit Solana network. " +
|
|
4659
|
+
"Pass config.chain as solana_devnet, solana_mainnet, or surfnet, " +
|
|
4660
|
+
"or pass mobileWalletConfig.cluster.");
|
|
4661
|
+
}
|
|
4662
|
+
return Object.assign(Object.assign({}, ((_c = config.mobileWalletConfig) !== null && _c !== void 0 ? _c : {})), { cluster });
|
|
4663
|
+
}
|
|
4664
|
+
function isLocalOrTestUrl(value) {
|
|
4665
|
+
if (!value)
|
|
4666
|
+
return false;
|
|
4667
|
+
try {
|
|
4668
|
+
const hostname = new URL(value).hostname.toLowerCase();
|
|
4669
|
+
return hostname === 'localhost' ||
|
|
4670
|
+
hostname === '127.0.0.1' ||
|
|
4671
|
+
hostname === '::1' ||
|
|
4672
|
+
hostname.endsWith('.localhost') ||
|
|
4673
|
+
hostname.endsWith('.test');
|
|
4674
|
+
}
|
|
4675
|
+
catch (_a) {
|
|
4676
|
+
return false;
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
function assertMockAuthLocalOnly(config) {
|
|
4680
|
+
const requiredEndpoints = [
|
|
4681
|
+
config.apiUrl,
|
|
4682
|
+
config.wsApiUrl,
|
|
4683
|
+
config.authApiUrl,
|
|
4684
|
+
];
|
|
4685
|
+
const optionalEndpoints = [
|
|
4686
|
+
config.rpcUrl,
|
|
4687
|
+
config.humanAuthApiUrl,
|
|
4688
|
+
config.functionsUrl,
|
|
4689
|
+
].filter((value) => typeof value === 'string' && value.trim() !== '');
|
|
4690
|
+
if (requiredEndpoints.every(isLocalOrTestUrl) && optionalEndpoints.every(isLocalOrTestUrl)) {
|
|
4691
|
+
return;
|
|
4692
|
+
}
|
|
4693
|
+
throw new Error("mockAuth is local/test-only. Pass explicit localhost/.test apiUrl, wsApiUrl, and authApiUrl values; " +
|
|
4694
|
+
"mockAuth cannot be used with Bounded production or staging endpoints.");
|
|
4695
|
+
}
|
|
7041
4696
|
async function hotSwapToMWAProvider(config) {
|
|
7042
|
-
var _a
|
|
7043
|
-
const rpcUrl = (
|
|
4697
|
+
var _a;
|
|
4698
|
+
const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
|
|
4699
|
+
const configuredNetwork = getConfiguredSolanaNetwork(config);
|
|
7044
4700
|
const SolanaMobileWalletProvider = await loadSolanaMobileWalletProvider();
|
|
7045
|
-
const mwaConfig =
|
|
7046
|
-
|
|
7047
|
-
|
|
7048
|
-
|
|
7049
|
-
|
|
7050
|
-
|
|
7051
|
-
|
|
4701
|
+
const mwaConfig = config.mobileWalletConfig
|
|
4702
|
+
? requireMobileWalletConfig(config)
|
|
4703
|
+
: {
|
|
4704
|
+
appIdentity: {
|
|
4705
|
+
name: config.name || undefined,
|
|
4706
|
+
uri: getPlatform().getLocationOrigin(),
|
|
4707
|
+
},
|
|
4708
|
+
cluster: (_a = mobileWalletClusterFromNetwork(configuredNetwork)) !== null && _a !== void 0 ? _a : undefined,
|
|
4709
|
+
};
|
|
4710
|
+
if (!mwaConfig.cluster) {
|
|
4711
|
+
throw new Error("Mobile wallet auth requires config.chain or mobileWalletConfig.cluster before switching providers.");
|
|
4712
|
+
}
|
|
4713
|
+
const mwaProvider = new SolanaMobileWalletProvider(rpcUrl, mwaConfig, configuredNetwork);
|
|
7052
4714
|
let provider = mwaProvider;
|
|
7053
4715
|
if (config.chain === "offchain") {
|
|
7054
4716
|
provider = new OffchainAuthProvider(mwaProvider);
|
|
@@ -7063,11 +4725,8 @@ async function hotSwapToMWAProvider(config) {
|
|
|
7063
4725
|
setAuthProviderInstance(provider);
|
|
7064
4726
|
return provider;
|
|
7065
4727
|
}
|
|
7066
|
-
const SOLANA_DEVNET_RPC_URL = "https://idelle-8nxsep-fast-devnet.helius-rpc.com";
|
|
7067
|
-
const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
7068
|
-
const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
|
|
7069
4728
|
async function getAuthProvider(config) {
|
|
7070
|
-
var _a, _b
|
|
4729
|
+
var _a, _b;
|
|
7071
4730
|
if (currentAuthProvider) {
|
|
7072
4731
|
return currentAuthProvider;
|
|
7073
4732
|
}
|
|
@@ -7077,21 +4736,17 @@ async function getAuthProvider(config) {
|
|
|
7077
4736
|
initConfig = config;
|
|
7078
4737
|
// If mockAuth is enabled, use MockAuthProvider regardless of authMethod
|
|
7079
4738
|
if (config.mockAuth) {
|
|
4739
|
+
assertMockAuthLocalOnly(config);
|
|
7080
4740
|
console.log("[MockAuth] Mock authentication enabled");
|
|
7081
4741
|
currentAuthProvider = new MockAuthProvider();
|
|
7082
4742
|
return currentAuthProvider;
|
|
7083
4743
|
}
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
if (storedMethod && !validAuthMethods.includes(storedMethod)) {
|
|
7091
|
-
// Invalid stored value — clear it
|
|
7092
|
-
setStoredAuthMethod(null);
|
|
7093
|
-
}
|
|
7094
|
-
const rpcUrl = (_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null;
|
|
4744
|
+
const authMethod = config.authMethod;
|
|
4745
|
+
if (!authMethod) {
|
|
4746
|
+
throw new Error("authMethod is required to initialize auth provider; configure the single intended auth method explicitly.");
|
|
4747
|
+
}
|
|
4748
|
+
const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
|
|
4749
|
+
const configuredNetwork = getConfiguredSolanaNetwork(config);
|
|
7095
4750
|
currentAuthMethod = authMethod;
|
|
7096
4751
|
// Clear, actionable error when the BROWSER build (`bounded-sh`) is loaded in a
|
|
7097
4752
|
// non-browser (Node) runtime. The wallet providers below need `window`; without
|
|
@@ -7103,8 +4758,8 @@ async function getAuthProvider(config) {
|
|
|
7103
4758
|
if (typeof window === 'undefined' && browserWalletMethods.includes(authMethod)) {
|
|
7104
4759
|
throw new Error(`bounded-sh: '${authMethod}' auth requires a browser, but no \`window\` was found ` +
|
|
7105
4760
|
`(you're likely running in Node). In server/Node code, import from 'bounded-sh/server' ` +
|
|
7106
|
-
`instead of 'bounded-sh' — it signs with
|
|
7107
|
-
`
|
|
4761
|
+
`instead of 'bounded-sh' — it signs with an explicit keypair passed to createWalletClient({ keypair }) ` +
|
|
4762
|
+
`and needs no browser.`);
|
|
7108
4763
|
}
|
|
7109
4764
|
switch (authMethod) {
|
|
7110
4765
|
case "email":
|
|
@@ -7121,7 +4776,7 @@ async function getAuthProvider(config) {
|
|
|
7121
4776
|
break;
|
|
7122
4777
|
case "phantom": {
|
|
7123
4778
|
const { PhantomWalletProvider } = await loadPhantomWalletProvider();
|
|
7124
|
-
currentAuthProvider = new PhantomWalletProvider(rpcUrl, config.phantomConfig);
|
|
4779
|
+
currentAuthProvider = new PhantomWalletProvider(rpcUrl, config.phantomConfig, configuredNetwork);
|
|
7125
4780
|
// MWA hot-swap is always available (custom modal shows MWA button on Android)
|
|
7126
4781
|
currentAuthProvider.onSwitchToMWA =
|
|
7127
4782
|
() => hotSwapToMWAProvider(config);
|
|
@@ -7131,8 +4786,9 @@ async function getAuthProvider(config) {
|
|
|
7131
4786
|
// Web Privy: a co-equal login route alongside email/phantom/guest. The
|
|
7132
4787
|
// Privy embedded/external Solana wallet signs the SIWS challenge, so the
|
|
7133
4788
|
// session is minted through the same wallet path as Phantom.
|
|
4789
|
+
const privyConfig = requireWebPrivyConfig(config);
|
|
7134
4790
|
const PrivyWalletProvider = await loadPrivyWalletProvider();
|
|
7135
|
-
currentAuthProvider = new PrivyWalletProvider((
|
|
4791
|
+
currentAuthProvider = new PrivyWalletProvider((_a = config.name) !== null && _a !== void 0 ? _a : null, (_b = config.logoUrl) !== null && _b !== void 0 ? _b : null, privyConfig, rpcUrl, configuredNetwork);
|
|
7136
4792
|
break;
|
|
7137
4793
|
}
|
|
7138
4794
|
case "privy-expo":
|
|
@@ -7147,7 +4803,7 @@ async function getAuthProvider(config) {
|
|
|
7147
4803
|
break;
|
|
7148
4804
|
case "mobile-wallet-adapter": {
|
|
7149
4805
|
const SolanaMobileWalletProvider = await loadSolanaMobileWalletProvider();
|
|
7150
|
-
currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, config
|
|
4806
|
+
currentAuthProvider = new SolanaMobileWalletProvider(rpcUrl, requireMobileWalletConfig(config), configuredNetwork);
|
|
7151
4807
|
break;
|
|
7152
4808
|
}
|
|
7153
4809
|
case "onboard":
|
|
@@ -7180,7 +4836,7 @@ function assertBrowserAuthEnv(method) {
|
|
|
7180
4836
|
throw new Error(`bounded-sh: '${method}' is a browser/React-Native auth flow — it needs \`window\`/\`localStorage\` ` +
|
|
7181
4837
|
`to persist the session, which Node doesn't have (the session would be silently dropped, then every ` +
|
|
7182
4838
|
`request 403s). In Node/server code import from 'bounded-sh/server' and sign with a keypair ` +
|
|
7183
|
-
`
|
|
4839
|
+
`by using createWalletClient({ keypair }).`);
|
|
7184
4840
|
}
|
|
7185
4841
|
}
|
|
7186
4842
|
/**
|
|
@@ -7217,13 +4873,14 @@ async function signInAnonymously() {
|
|
|
7217
4873
|
* (web localStorage / RN storage) and identity model. `init()` must have run first.
|
|
7218
4874
|
*/
|
|
7219
4875
|
async function loginWithPrivy(options) {
|
|
7220
|
-
var _a, _b
|
|
4876
|
+
var _a, _b;
|
|
7221
4877
|
assertBrowserAuthEnv('loginWithPrivy');
|
|
7222
4878
|
const coreConfig = await getConfig();
|
|
7223
4879
|
let provider;
|
|
7224
4880
|
if (getPlatform().hasDOM) {
|
|
4881
|
+
const privyConfig = requireWebPrivyConfig(coreConfig);
|
|
7225
4882
|
const PrivyWalletProvider = await loadPrivyWalletProvider();
|
|
7226
|
-
provider = new PrivyWalletProvider((_a = coreConfig.name) !== null && _a !== void 0 ? _a : null, (_b = coreConfig.logoUrl) !== null && _b !== void 0 ? _b : null,
|
|
4883
|
+
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));
|
|
7227
4884
|
currentAuthMethod = 'privy';
|
|
7228
4885
|
}
|
|
7229
4886
|
else {
|
|
@@ -7369,15 +5026,13 @@ async function logout$1() {
|
|
|
7369
5026
|
throw new Error("Auth provider not initialized. Please call init() first.");
|
|
7370
5027
|
}
|
|
7371
5028
|
// Revoke the refresh-token family server-side BEFORE the provider clears the
|
|
7372
|
-
// local session (so we still have the token + issuer to revoke).
|
|
7373
|
-
//
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7377
|
-
|
|
7378
|
-
|
|
7379
|
-
}
|
|
7380
|
-
catch ( /* proceed with local logout regardless */_b) { /* proceed with local logout regardless */ }
|
|
5029
|
+
// local session (so we still have the token + issuer to revoke). If revoke
|
|
5030
|
+
// fails, surface the error and leave local state intact so callers do not
|
|
5031
|
+
// mistake a local-only logout for server revocation.
|
|
5032
|
+
const sm = getActiveSessionManager();
|
|
5033
|
+
const refreshToken = sm.getRefreshToken();
|
|
5034
|
+
if (refreshToken)
|
|
5035
|
+
await revokeSession(refreshToken, (_a = sm.getIssuer()) !== null && _a !== void 0 ? _a : undefined);
|
|
7381
5036
|
await currentAuthProvider.logout();
|
|
7382
5037
|
setStoredAuthMethod(null);
|
|
7383
5038
|
currentAuthProvider = null;
|
|
@@ -7708,7 +5363,6 @@ async function confirmAndCheckTransaction(connection, signature) {
|
|
|
7708
5363
|
* to host Privy's React context, this provider expects the RN app itself
|
|
7709
5364
|
* to render <PrivyProvider> and then bridge the hooks via setPrivyMethods().
|
|
7710
5365
|
*/
|
|
7711
|
-
const SURFNET_RPC_URL = 'https://surfpool.fly.dev';
|
|
7712
5366
|
// -----------------------------------------------------------------------
|
|
7713
5367
|
// Provider implementation
|
|
7714
5368
|
// -----------------------------------------------------------------------
|
|
@@ -7716,7 +5370,7 @@ class PrivyExpoProvider {
|
|
|
7716
5370
|
constructor(appId, networkUrl = null) {
|
|
7717
5371
|
this.privyMethods = null;
|
|
7718
5372
|
this.appId = appId;
|
|
7719
|
-
this.networkUrl = networkUrl;
|
|
5373
|
+
this.networkUrl = normalizeSolanaRpcUrl(networkUrl);
|
|
7720
5374
|
}
|
|
7721
5375
|
/**
|
|
7722
5376
|
* Bridge Privy hooks from the app's React tree into this provider.
|
|
@@ -8001,15 +5655,7 @@ class PrivyExpoProvider {
|
|
|
8001
5655
|
return { signature, txInfo };
|
|
8002
5656
|
}
|
|
8003
5657
|
getRpcUrl(network) {
|
|
8004
|
-
|
|
8005
|
-
return this.networkUrl;
|
|
8006
|
-
if (network === 'solana_devnet')
|
|
8007
|
-
return SOLANA_DEVNET_RPC_URL;
|
|
8008
|
-
if (network === 'solana_mainnet')
|
|
8009
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
8010
|
-
if (network === 'surfnet')
|
|
8011
|
-
return SURFNET_RPC_URL;
|
|
8012
|
-
return SOLANA_MAINNET_RPC_URL;
|
|
5658
|
+
return resolveSolanaRpcUrl(this.networkUrl, network, "Privy Expo Solana transaction");
|
|
8013
5659
|
}
|
|
8014
5660
|
async ensureReady(timeoutMs = 15000) {
|
|
8015
5661
|
if (!this.privyMethods) {
|
|
@@ -8037,5 +5683,5 @@ class PrivyExpoProvider {
|
|
|
8037
5683
|
}
|
|
8038
5684
|
}
|
|
8039
5685
|
|
|
8040
|
-
export {
|
|
8041
|
-
//# sourceMappingURL=index.native-
|
|
5686
|
+
export { loginWithRedirect as A, linkWithRedirect as B, completeLoginFromRedirect as C, loginWithPopup as D, completeLoginInPopup as E, useAuth as F, deserializeTransaction as G, getIdToken as H, setPlatform as I, DEFAULT_TEST_ADDRESS as J, index as K, MockAuthProvider as M, OffchainAuthProvider as O, PrivyExpoProvider as P, SURFNET_RPC_URL as S, detectAndroid as a, bufferExports as b, confirmAndCheckTransaction as c, detectMobile as d, setAuthLoading as e, resolveSolanaWalletStandardChain as f, getPlatform as g, bs58 as h, init as i, getCurrentUser as j, onAuthLoadingChanged as k, getAuthLoading as l, login as m, normalizeSolanaRpcUrl as n, onAuthStateChanged as o, logout as p, getAuthProvider as q, resolveSolanaRpcUrl as r, setCurrentUser as s, signInAnonymously as t, sendEmailOtp as u, sendTextOtp as v, verifyEmailOtp as w, verifyTextOtp as x, linkEmail as y, loginWithPrivy as z };
|
|
5687
|
+
//# sourceMappingURL=index.native-DWI_i6-6.mjs.map
|