@bounded-sh/client 0.0.7 → 0.0.8
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/dist/auth/index.d.ts +15 -0
- package/dist/auth/oidc-auth.d.ts +25 -11
- package/dist/auth/providers/email-auth-provider.d.ts +10 -0
- package/dist/auth/providers/mock-auth-provider.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +483 -2615
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +484 -2614
- package/dist/index.js.map +1 -1
- package/dist/{index.native-CCc03Zxr.js → index.native-C-duG1XV.js} +488 -2618
- package/dist/index.native-C-duG1XV.js.map +1 -0
- package/dist/{index.native-BxNuEqgy.esm.js → index.native-DnVLH-7o.esm.js} +487 -2619
- package/dist/index.native-DnVLH-7o.esm.js.map +1 -0
- package/dist/index.native.d.ts +2 -1
- package/dist/index.native.esm.js +1 -1
- package/dist/index.native.js +3 -1
- package/dist/index.native.js.map +1 -1
- package/dist/{phantom-wallet-provider-yMlFdfKn.js → phantom-wallet-provider-DKScS8m6.js} +2 -2
- package/dist/{phantom-wallet-provider-yMlFdfKn.js.map → phantom-wallet-provider-DKScS8m6.js.map} +1 -1
- package/dist/{phantom-wallet-provider-CxnVOBTM.esm.js → phantom-wallet-provider-DfTqdjx7.esm.js} +2 -2
- package/dist/{phantom-wallet-provider-CxnVOBTM.esm.js.map → phantom-wallet-provider-DfTqdjx7.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-BbjUoSdY.esm.js → privy-wallet-provider-BpPAZyUD.esm.js} +3 -3
- package/dist/{privy-wallet-provider-BbjUoSdY.esm.js.map → privy-wallet-provider-BpPAZyUD.esm.js.map} +1 -1
- package/dist/{privy-wallet-provider-BcbjdOfk.js → privy-wallet-provider-wCTdqpRq.js} +3 -3
- package/dist/{privy-wallet-provider-BcbjdOfk.js.map → privy-wallet-provider-wCTdqpRq.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-BCoTvY5g.js → solana-mobile-wallet-provider-DZx3xVit.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-BCoTvY5g.js.map → solana-mobile-wallet-provider-DZx3xVit.js.map} +1 -1
- package/dist/{solana-mobile-wallet-provider-wl_xDwIC.esm.js → solana-mobile-wallet-provider-xmASWrPf.esm.js} +2 -2
- package/dist/{solana-mobile-wallet-provider-wl_xDwIC.esm.js.map → solana-mobile-wallet-provider-xmASWrPf.esm.js.map} +1 -1
- package/package.json +2 -2
- package/dist/index.native-BxNuEqgy.esm.js.map +0 -1
- package/dist/index.native-CCc03Zxr.js.map +0 -1
|
@@ -37,7 +37,7 @@ function commonjsRequire(path) {
|
|
|
37
37
|
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.');
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
var naclFast
|
|
40
|
+
var naclFast = {exports: {}};
|
|
41
41
|
|
|
42
42
|
var _nodeResolve_empty = {};
|
|
43
43
|
|
|
@@ -48,11 +48,11 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
|
|
|
48
48
|
|
|
49
49
|
var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
|
|
50
50
|
|
|
51
|
-
var hasRequiredNaclFast
|
|
51
|
+
var hasRequiredNaclFast;
|
|
52
52
|
|
|
53
|
-
function requireNaclFast
|
|
54
|
-
if (hasRequiredNaclFast
|
|
55
|
-
hasRequiredNaclFast
|
|
53
|
+
function requireNaclFast () {
|
|
54
|
+
if (hasRequiredNaclFast) return naclFast.exports;
|
|
55
|
+
hasRequiredNaclFast = 1;
|
|
56
56
|
(function (module) {
|
|
57
57
|
(function(nacl) {
|
|
58
58
|
|
|
@@ -2444,12 +2444,12 @@ function requireNaclFast$1 () {
|
|
|
2444
2444
|
})();
|
|
2445
2445
|
|
|
2446
2446
|
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
2447
|
-
} (naclFast
|
|
2448
|
-
return naclFast
|
|
2447
|
+
} (naclFast));
|
|
2448
|
+
return naclFast.exports;
|
|
2449
2449
|
}
|
|
2450
2450
|
|
|
2451
|
-
var naclFastExports
|
|
2452
|
-
var nacl
|
|
2451
|
+
var naclFastExports = requireNaclFast();
|
|
2452
|
+
var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
|
|
2453
2453
|
|
|
2454
2454
|
var bn$1 = {exports: {}};
|
|
2455
2455
|
|
|
@@ -6414,10 +6414,13 @@ let clientConfig = {
|
|
|
6414
6414
|
humanAuthApiUrl: 'https://auth.bounded.sh',
|
|
6415
6415
|
functionsUrl: 'https://functions.bounded.sh',
|
|
6416
6416
|
appId: '',
|
|
6417
|
-
// 'email' = Bounded
|
|
6418
|
-
// for
|
|
6419
|
-
//
|
|
6420
|
-
//
|
|
6417
|
+
// 'email' = Bounded Auth human login (inline email OTP) — the out-of-box default
|
|
6418
|
+
// for normal apps. Hosted OAuth/social uses loginWithRedirect/loginWithPopup.
|
|
6419
|
+
// Text OTP is off by default and uses hosted/headless text helpers only when
|
|
6420
|
+
// Bounded explicitly enables it for the issuer. For
|
|
6421
|
+
// crypto/onchain wallet login use authMethod:'phantom' (Solana / Phantom), or
|
|
6422
|
+
// signInAnonymously() for zero-friction 'guest' accounts. ('wallet' is an
|
|
6423
|
+
// unimplemented stub; don't use.)
|
|
6421
6424
|
authMethod: 'email',
|
|
6422
6425
|
chain: '',
|
|
6423
6426
|
rpcUrl: '',
|
|
@@ -10232,7 +10235,7 @@ class ServerSessionManager {
|
|
|
10232
10235
|
const nonce = await genAuthNonce();
|
|
10233
10236
|
const message = await genSolanaMessage(address, nonce);
|
|
10234
10237
|
/* sign the message */
|
|
10235
|
-
const sigBytes = nacl
|
|
10238
|
+
const sigBytes = nacl.sign.detached(new TextEncoder().encode(message), kp.secretKey);
|
|
10236
10239
|
const signature = bufferExports$1.Buffer.from(sigBytes).toString("base64");
|
|
10237
10240
|
/* call auth API */
|
|
10238
10241
|
const { accessToken, idToken, refreshToken, } = await createSessionWithSignature(address, message, signature);
|
|
@@ -10617,7 +10620,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
10617
10620
|
}
|
|
10618
10621
|
}
|
|
10619
10622
|
|
|
10620
|
-
var __rest = function (s, e) {
|
|
10623
|
+
var __rest$1 = function (s, e) {
|
|
10621
10624
|
var t = {};
|
|
10622
10625
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
10623
10626
|
t[p] = s[p];
|
|
@@ -11092,7 +11095,7 @@ async function search(path, query, opts = {}) {
|
|
|
11092
11095
|
normalizedPath = normalizedPath.slice(0, -1);
|
|
11093
11096
|
}
|
|
11094
11097
|
if (!normalizedPath || normalizedPath.length === 0) {
|
|
11095
|
-
|
|
11098
|
+
throw new Error("Invalid path provided.");
|
|
11096
11099
|
}
|
|
11097
11100
|
if (typeof query !== "string" || query.trim().length === 0) {
|
|
11098
11101
|
throw new Error("search query must be a non-empty string");
|
|
@@ -11119,7 +11122,7 @@ async function get(path, opts = {}) {
|
|
|
11119
11122
|
normalizedPath = normalizedPath.slice(0, -1);
|
|
11120
11123
|
}
|
|
11121
11124
|
if (!normalizedPath || normalizedPath.length === 0) {
|
|
11122
|
-
|
|
11125
|
+
throw new Error("Invalid path provided.");
|
|
11123
11126
|
}
|
|
11124
11127
|
// Create cache key combining path, prompt, filter, sort, includeSubPaths,
|
|
11125
11128
|
// shape, limit, cursor — and (H1) the caller's appId + principal fingerprint,
|
|
@@ -11247,6 +11250,23 @@ function cleanupExpiredCache() {
|
|
|
11247
11250
|
});
|
|
11248
11251
|
lastCacheCleanup = now;
|
|
11249
11252
|
}
|
|
11253
|
+
function classifyGetManyBatchError(error) {
|
|
11254
|
+
var _a, _b, _c;
|
|
11255
|
+
const err = error;
|
|
11256
|
+
const status = (_b = (_a = err === null || err === void 0 ? void 0 : err.status) !== null && _a !== void 0 ? _a : err === null || err === void 0 ? void 0 : err.statusCode) !== null && _b !== void 0 ? _b : (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.status;
|
|
11257
|
+
const message = error instanceof Error
|
|
11258
|
+
? error.message
|
|
11259
|
+
: typeof (err === null || err === void 0 ? void 0 : err.message) === 'string'
|
|
11260
|
+
? err.message
|
|
11261
|
+
: 'Unknown error';
|
|
11262
|
+
if (status === 401 || status === 403) {
|
|
11263
|
+
return { code: 'UNAUTHORIZED', message };
|
|
11264
|
+
}
|
|
11265
|
+
if (status === 400) {
|
|
11266
|
+
return { code: 'INVALID_PATH', message };
|
|
11267
|
+
}
|
|
11268
|
+
return { code: 'REQUEST_FAILED', message };
|
|
11269
|
+
}
|
|
11250
11270
|
async function getMany(paths, opts = {}) {
|
|
11251
11271
|
var _a, _b, _c, _d, _e;
|
|
11252
11272
|
if (paths.length === 0) {
|
|
@@ -11291,6 +11311,11 @@ async function getMany(paths, opts = {}) {
|
|
|
11291
11311
|
if (uncachedPaths.length > 0) {
|
|
11292
11312
|
try {
|
|
11293
11313
|
const response = await makeApiRequest('POST', 'items/batch', { paths: uncachedPaths }, opts._overrides);
|
|
11314
|
+
if (response.status === 404 && response.data == null) {
|
|
11315
|
+
const endpointError = new Error('Batch read endpoint returned 404');
|
|
11316
|
+
endpointError.status = 404;
|
|
11317
|
+
throw endpointError;
|
|
11318
|
+
}
|
|
11294
11319
|
// makeApiRequest returns `{ data: <httpBody> }`, and the worker's items/batch
|
|
11295
11320
|
// httpBody is `{ data: { results: [...] }, status }` — so the results are
|
|
11296
11321
|
// double-nested at response.data.data.results. (Reading response.data.results
|
|
@@ -11333,11 +11358,12 @@ async function getMany(paths, opts = {}) {
|
|
|
11333
11358
|
}
|
|
11334
11359
|
}
|
|
11335
11360
|
catch (error) {
|
|
11361
|
+
const batchError = classifyGetManyBatchError(error);
|
|
11336
11362
|
for (const originalIndex of uncachedIndices) {
|
|
11337
11363
|
results[originalIndex] = {
|
|
11338
11364
|
path: normalizedPaths[originalIndex],
|
|
11339
11365
|
data: null,
|
|
11340
|
-
error:
|
|
11366
|
+
error: batchError,
|
|
11341
11367
|
};
|
|
11342
11368
|
}
|
|
11343
11369
|
}
|
|
@@ -11499,26 +11525,23 @@ async function setMany(many, options) {
|
|
|
11499
11525
|
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: transactionResult.signature, signedTransaction: transactionResult.signedTransaction });
|
|
11500
11526
|
}
|
|
11501
11527
|
// Handle Solana on-chain transaction flow
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
}
|
|
11513
|
-
lastTxSignature = transactionResult.transactionSignature;
|
|
11514
|
-
signedTransaction = transactionResult.signedTransaction;
|
|
11528
|
+
if (!Array.isArray(transactions) || transactions.length !== 1) {
|
|
11529
|
+
throw new Error(`Expected exactly one on-chain transaction, received ${Array.isArray(transactions) ? transactions.length : 0}`);
|
|
11530
|
+
}
|
|
11531
|
+
const curTx = transactions[0];
|
|
11532
|
+
let transactionResult;
|
|
11533
|
+
if (curTx.serializedTransaction) {
|
|
11534
|
+
transactionResult = await handlePreBuiltTransaction(curTx, authProvider, options);
|
|
11535
|
+
}
|
|
11536
|
+
else {
|
|
11537
|
+
transactionResult = await handleSolanaTransaction(curTx, authProvider, options);
|
|
11515
11538
|
}
|
|
11516
11539
|
// Sync items after all transactions are confirmed
|
|
11517
11540
|
// Wait for 1.5 seconds to ensure all transactions are confirmed
|
|
11518
11541
|
await new Promise(resolve => setTimeout(resolve, 1500));
|
|
11519
11542
|
await syncItems(many.map(m => m.path), options);
|
|
11520
11543
|
// TODO: Should we wait here or do the optimistic subscription updates like below?
|
|
11521
|
-
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId:
|
|
11544
|
+
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: transactionResult.transactionSignature, signedTransaction: transactionResult.signedTransaction });
|
|
11522
11545
|
}
|
|
11523
11546
|
else if (setResponse.status === 200) {
|
|
11524
11547
|
// This means that the document was set successfully.
|
|
@@ -11531,7 +11554,7 @@ async function setMany(many, options) {
|
|
|
11531
11554
|
else if (setResponse.data &&
|
|
11532
11555
|
typeof setResponse.data === 'object' &&
|
|
11533
11556
|
setResponse.data.success === true) {
|
|
11534
|
-
const _k = setResponse.data, { success: _success } = _k, rest = __rest(_k, ["success"]);
|
|
11557
|
+
const _k = setResponse.data, { success: _success } = _k, rest = __rest$1(_k, ["success"]);
|
|
11535
11558
|
return Object.assign(Object.assign(Object.assign({}, documents.map(d => d.document)), rest), { transactionId: null });
|
|
11536
11559
|
}
|
|
11537
11560
|
else {
|
|
@@ -11767,7 +11790,7 @@ async function getFiles(path, options) {
|
|
|
11767
11790
|
try {
|
|
11768
11791
|
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
11769
11792
|
if (!normalizedPath || normalizedPath.length === 0) {
|
|
11770
|
-
|
|
11793
|
+
throw new Error("Invalid path provided.");
|
|
11771
11794
|
}
|
|
11772
11795
|
const apiPath = `storage?path=${normalizedPath}`;
|
|
11773
11796
|
const response = await makeApiRequest('GET', apiPath, null, options === null || options === void 0 ? void 0 : options._overrides);
|
|
@@ -12187,6 +12210,12 @@ function roomKeyFromRoutePath(routePath) {
|
|
|
12187
12210
|
return null;
|
|
12188
12211
|
return `${segs[0]}/${segs[1]}`;
|
|
12189
12212
|
}
|
|
12213
|
+
function replaySubscriptions(connection) {
|
|
12214
|
+
for (const sub of connection.subscriptions.values()) {
|
|
12215
|
+
sub.lastData = undefined;
|
|
12216
|
+
sendSubscribe(connection, sub);
|
|
12217
|
+
}
|
|
12218
|
+
}
|
|
12190
12219
|
async function getOrCreateConnection(appId, isServer, routePath, authTokenProvider, principalKey) {
|
|
12191
12220
|
attachBrowserReconnectHooksOnce();
|
|
12192
12221
|
// A per-room subscription gets its OWN connection routed to the room DO; all
|
|
@@ -12212,10 +12241,12 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
|
|
|
12212
12241
|
pendingRequests: new Map(),
|
|
12213
12242
|
isConnecting: false,
|
|
12214
12243
|
isConnected: false,
|
|
12244
|
+
isAuthenticating: false,
|
|
12215
12245
|
appId,
|
|
12216
12246
|
key: connKey,
|
|
12217
12247
|
routePath: roomKey ? routePath : undefined,
|
|
12218
12248
|
authTokenProvider,
|
|
12249
|
+
pendingAuthToken: null,
|
|
12219
12250
|
tokenRefreshTimer: null,
|
|
12220
12251
|
consecutiveAuthFailures: 0,
|
|
12221
12252
|
};
|
|
@@ -12240,16 +12271,17 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
|
|
|
12240
12271
|
// Per-room connection: carry the room path so the worker routes this WS
|
|
12241
12272
|
// to the room DO (appId#room#roomId) where the live view fan-out lives.
|
|
12242
12273
|
if (connection.routePath) {
|
|
12243
|
-
wsUrl.searchParams.append('
|
|
12274
|
+
wsUrl.searchParams.append('routePath', connection.routePath);
|
|
12244
12275
|
}
|
|
12245
|
-
//
|
|
12246
|
-
// token from the wallet's own session (self-refreshing); all others
|
|
12247
|
-
// the ambient env/web session.
|
|
12276
|
+
// Resolve auth token if available. A wallet-scoped connection resolves
|
|
12277
|
+
// its token from the wallet's own session (self-refreshing); all others
|
|
12278
|
+
// use the ambient env/web session. The token is sent as the first WS
|
|
12279
|
+
// frame after open, never as a URL query parameter.
|
|
12248
12280
|
const authToken = connection.authTokenProvider
|
|
12249
12281
|
? await connection.authTokenProvider().catch(() => null)
|
|
12250
12282
|
: await getFreshAuthToken(isServer);
|
|
12283
|
+
connection.pendingAuthToken = authToken || null;
|
|
12251
12284
|
if (authToken) {
|
|
12252
|
-
wsUrl.searchParams.append('authorization', authToken);
|
|
12253
12285
|
// Successful token acquisition — reset failure counter
|
|
12254
12286
|
connection.consecutiveAuthFailures = 0;
|
|
12255
12287
|
}
|
|
@@ -12275,6 +12307,7 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
|
|
|
12275
12307
|
connection.ws = ws;
|
|
12276
12308
|
// Handle connection open
|
|
12277
12309
|
ws.addEventListener('open', () => {
|
|
12310
|
+
var _a, _b;
|
|
12278
12311
|
connection.isConnecting = false;
|
|
12279
12312
|
connection.isConnected = true;
|
|
12280
12313
|
// NOTE: Do NOT reset consecutiveAuthFailures here. It is reset when a
|
|
@@ -12289,10 +12322,26 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
|
|
|
12289
12322
|
// urlProvider skips straight to unauthenticated connection.
|
|
12290
12323
|
// Schedule periodic token freshness checks
|
|
12291
12324
|
scheduleTokenRefresh(connection, isServer);
|
|
12292
|
-
|
|
12293
|
-
|
|
12294
|
-
|
|
12295
|
-
|
|
12325
|
+
if (connection.pendingAuthToken) {
|
|
12326
|
+
connection.isAuthenticating = true;
|
|
12327
|
+
try {
|
|
12328
|
+
(_a = connection.ws) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({ type: 'auth', token: connection.pendingAuthToken }));
|
|
12329
|
+
}
|
|
12330
|
+
catch (error) {
|
|
12331
|
+
connection.isAuthenticating = false;
|
|
12332
|
+
connection.isConnected = false;
|
|
12333
|
+
console.error('[WS v2] Error sending auth message:', error);
|
|
12334
|
+
try {
|
|
12335
|
+
(_b = connection.ws) === null || _b === void 0 ? void 0 : _b.close(1008, 'Authentication send failed');
|
|
12336
|
+
}
|
|
12337
|
+
catch (_c) {
|
|
12338
|
+
// Already closed.
|
|
12339
|
+
}
|
|
12340
|
+
}
|
|
12341
|
+
}
|
|
12342
|
+
else {
|
|
12343
|
+
connection.isAuthenticating = false;
|
|
12344
|
+
replaySubscriptions(connection);
|
|
12296
12345
|
}
|
|
12297
12346
|
});
|
|
12298
12347
|
// Handle incoming messages
|
|
@@ -12316,6 +12365,7 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
|
|
|
12316
12365
|
// Handle close
|
|
12317
12366
|
ws.addEventListener('close', () => {
|
|
12318
12367
|
connection.isConnected = false;
|
|
12368
|
+
connection.isAuthenticating = false;
|
|
12319
12369
|
if (connection.tokenRefreshTimer) {
|
|
12320
12370
|
clearInterval(connection.tokenRefreshTimer);
|
|
12321
12371
|
connection.tokenRefreshTimer = null;
|
|
@@ -12332,6 +12382,11 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
|
|
|
12332
12382
|
function handleServerMessage(connection, message) {
|
|
12333
12383
|
var _a, _b;
|
|
12334
12384
|
switch (message.type) {
|
|
12385
|
+
case 'authenticated': {
|
|
12386
|
+
connection.isAuthenticating = false;
|
|
12387
|
+
replaySubscriptions(connection);
|
|
12388
|
+
break;
|
|
12389
|
+
}
|
|
12335
12390
|
case 'subscribed': {
|
|
12336
12391
|
const subscription = connection.subscriptions.get(message.subscriptionId);
|
|
12337
12392
|
if (subscription) {
|
|
@@ -12632,7 +12687,7 @@ async function subscribeV2(path, subscriptionOptions, roomRoutePath) {
|
|
|
12632
12687
|
};
|
|
12633
12688
|
connection.subscriptions.set(subscriptionId, subscription);
|
|
12634
12689
|
// Send subscribe message if connected
|
|
12635
|
-
if (connection.isConnected) {
|
|
12690
|
+
if (connection.isConnected && !connection.isAuthenticating) {
|
|
12636
12691
|
// Create a promise to wait for subscription confirmation
|
|
12637
12692
|
const subscriptionPromise = new Promise((resolve, reject) => {
|
|
12638
12693
|
connection.pendingSubscriptions.set(subscriptionId, { resolve, reject });
|
|
@@ -12670,7 +12725,7 @@ async function removeCallbackFromSubscription(connection, subscriptionId, callba
|
|
|
12670
12725
|
}
|
|
12671
12726
|
// No more callbacks, unsubscribe from server
|
|
12672
12727
|
connection.subscriptions.delete(subscriptionId);
|
|
12673
|
-
if (connection.isConnected) {
|
|
12728
|
+
if (connection.isConnected && !connection.isAuthenticating) {
|
|
12674
12729
|
// Create a promise to wait for unsubscription confirmation
|
|
12675
12730
|
const unsubscribePromise = new Promise((resolve, reject) => {
|
|
12676
12731
|
connection.pendingUnsubscriptions.set(subscriptionId, { resolve, reject });
|
|
@@ -12846,12 +12901,59 @@ function generateRequestId() {
|
|
|
12846
12901
|
*/
|
|
12847
12902
|
function hasActiveConnection() {
|
|
12848
12903
|
for (const connection of connections.values()) {
|
|
12849
|
-
if (connection.ws && connection.isConnected) {
|
|
12904
|
+
if (connection.ws && connection.isConnected && !connection.isAuthenticating) {
|
|
12850
12905
|
return true;
|
|
12851
12906
|
}
|
|
12852
12907
|
}
|
|
12853
12908
|
return false;
|
|
12854
12909
|
}
|
|
12910
|
+
async function waitForConnectionAuthenticated(connection) {
|
|
12911
|
+
if (!connection.isAuthenticating || !connection.ws)
|
|
12912
|
+
return;
|
|
12913
|
+
const ws = connection.ws;
|
|
12914
|
+
await new Promise((resolve, reject) => {
|
|
12915
|
+
let timeout;
|
|
12916
|
+
let cleanup = () => { };
|
|
12917
|
+
const onMessage = (event) => {
|
|
12918
|
+
try {
|
|
12919
|
+
const message = JSON.parse(event.data);
|
|
12920
|
+
if ((message === null || message === void 0 ? void 0 : message.type) === 'authenticated') {
|
|
12921
|
+
cleanup();
|
|
12922
|
+
resolve();
|
|
12923
|
+
}
|
|
12924
|
+
}
|
|
12925
|
+
catch (_a) {
|
|
12926
|
+
// Other frames are handled by the main listener.
|
|
12927
|
+
}
|
|
12928
|
+
};
|
|
12929
|
+
const onClose = () => {
|
|
12930
|
+
cleanup();
|
|
12931
|
+
reject(new Error('WebSocket disconnected during authentication'));
|
|
12932
|
+
};
|
|
12933
|
+
const onError = () => {
|
|
12934
|
+
cleanup();
|
|
12935
|
+
reject(new Error('WebSocket authentication failed'));
|
|
12936
|
+
};
|
|
12937
|
+
cleanup = () => {
|
|
12938
|
+
clearTimeout(timeout);
|
|
12939
|
+
ws.removeEventListener('message', onMessage);
|
|
12940
|
+
ws.removeEventListener('close', onClose);
|
|
12941
|
+
ws.removeEventListener('error', onError);
|
|
12942
|
+
};
|
|
12943
|
+
timeout = setTimeout(() => {
|
|
12944
|
+
cleanup();
|
|
12945
|
+
reject(new Error('WebSocket authentication timeout'));
|
|
12946
|
+
}, 10000);
|
|
12947
|
+
if (!connection.isAuthenticating) {
|
|
12948
|
+
cleanup();
|
|
12949
|
+
resolve();
|
|
12950
|
+
return;
|
|
12951
|
+
}
|
|
12952
|
+
ws.addEventListener('message', onMessage);
|
|
12953
|
+
ws.addEventListener('close', onClose);
|
|
12954
|
+
ws.addEventListener('error', onError);
|
|
12955
|
+
});
|
|
12956
|
+
}
|
|
12855
12957
|
async function sendRequest(msgBuilder) {
|
|
12856
12958
|
const config = await getConfig();
|
|
12857
12959
|
const appId = config.appId;
|
|
@@ -12877,6 +12979,7 @@ async function sendRequest(msgBuilder) {
|
|
|
12877
12979
|
if (!connection.ws || !connection.isConnected) {
|
|
12878
12980
|
throw new Error('WebSocket connection not available');
|
|
12879
12981
|
}
|
|
12982
|
+
await waitForConnectionAuthenticated(connection);
|
|
12880
12983
|
const requestId = generateRequestId();
|
|
12881
12984
|
const message = msgBuilder(requestId);
|
|
12882
12985
|
return new Promise((resolve, reject) => {
|
|
@@ -12913,7 +13016,7 @@ function wsIntent(appId, roomRoutePath, intent) {
|
|
|
12913
13016
|
const roomKey = roomKeyFromRoutePath(roomRoutePath);
|
|
12914
13017
|
const connKey = roomKey ? `${appId}#room#${roomKey}` : appId;
|
|
12915
13018
|
const connection = connections.get(connKey);
|
|
12916
|
-
if (!connection || !connection.ws || connection.ws.readyState !== WS_READY_STATE_OPEN) {
|
|
13019
|
+
if (!connection || !connection.ws || connection.ws.readyState !== WS_READY_STATE_OPEN || connection.isAuthenticating) {
|
|
12917
13020
|
return false;
|
|
12918
13021
|
}
|
|
12919
13022
|
try {
|
|
@@ -12936,7 +13039,7 @@ function wsIntentReliable(appId, roomRoutePath, intent) {
|
|
|
12936
13039
|
const roomKey = roomKeyFromRoutePath(roomRoutePath);
|
|
12937
13040
|
const connKey = roomKey ? `${appId}#room#${roomKey}` : appId;
|
|
12938
13041
|
const connection = connections.get(connKey);
|
|
12939
|
-
if (!connection || !connection.ws || connection.ws.readyState !== WS_READY_STATE_OPEN) {
|
|
13042
|
+
if (!connection || !connection.ws || connection.ws.readyState !== WS_READY_STATE_OPEN || connection.isAuthenticating) {
|
|
12940
13043
|
return undefined;
|
|
12941
13044
|
}
|
|
12942
13045
|
const requestId = generateRequestId();
|
|
@@ -13263,6 +13366,7 @@ class RealtimeStore {
|
|
|
13263
13366
|
this.idbDirtyKeys = new Set();
|
|
13264
13367
|
this.closed = false;
|
|
13265
13368
|
this.authToken = null;
|
|
13369
|
+
this.authenticating = false;
|
|
13266
13370
|
this.isServer = false;
|
|
13267
13371
|
this.tokenRefreshTimer = null;
|
|
13268
13372
|
// -----------------------------------------------------------------------
|
|
@@ -13310,7 +13414,7 @@ class RealtimeStore {
|
|
|
13310
13414
|
this.initPromise = this.init();
|
|
13311
13415
|
await this.initPromise;
|
|
13312
13416
|
}
|
|
13313
|
-
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN)
|
|
13417
|
+
if (((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN && !this.authenticating)
|
|
13314
13418
|
return;
|
|
13315
13419
|
if (this.connectPromise)
|
|
13316
13420
|
return this.connectPromise;
|
|
@@ -13325,21 +13429,52 @@ class RealtimeStore {
|
|
|
13325
13429
|
}
|
|
13326
13430
|
const params = new URLSearchParams();
|
|
13327
13431
|
params.set('apiKey', this.appId);
|
|
13328
|
-
if (this.authToken)
|
|
13329
|
-
params.set('authorization', this.authToken);
|
|
13330
|
-
// Note: token in URL is required until DO server supports subprotocol auth.
|
|
13331
|
-
// WSS encrypts the full URL including query params on the wire.
|
|
13332
13432
|
const url = `${this.wsUrl}?${params.toString()}`;
|
|
13333
13433
|
const ws = new WebSocket(url);
|
|
13334
13434
|
this.ws = ws;
|
|
13335
|
-
|
|
13435
|
+
let authTimer = null;
|
|
13436
|
+
const finishConnected = () => {
|
|
13437
|
+
if (authTimer) {
|
|
13438
|
+
clearTimeout(authTimer);
|
|
13439
|
+
authTimer = null;
|
|
13440
|
+
}
|
|
13441
|
+
this.authenticating = false;
|
|
13336
13442
|
ws.removeEventListener('error', onError);
|
|
13337
13443
|
this.reconnectDelay = 1000;
|
|
13338
13444
|
this.connectPromise = null;
|
|
13339
13445
|
this.resubscribeAll();
|
|
13340
13446
|
resolve();
|
|
13341
13447
|
};
|
|
13448
|
+
const onOpen = () => {
|
|
13449
|
+
if (!this.authToken) {
|
|
13450
|
+
finishConnected();
|
|
13451
|
+
return;
|
|
13452
|
+
}
|
|
13453
|
+
this.authenticating = true;
|
|
13454
|
+
authTimer = setTimeout(() => {
|
|
13455
|
+
this.authenticating = false;
|
|
13456
|
+
this.connectPromise = null;
|
|
13457
|
+
try {
|
|
13458
|
+
ws.close(1008, 'Authentication timeout');
|
|
13459
|
+
}
|
|
13460
|
+
catch ( /* ignore */_a) { /* ignore */ }
|
|
13461
|
+
reject(new Error('WebSocket authentication timeout'));
|
|
13462
|
+
}, 10000);
|
|
13463
|
+
try {
|
|
13464
|
+
ws.send(JSON.stringify({ type: 'auth', token: this.authToken }));
|
|
13465
|
+
}
|
|
13466
|
+
catch (e) {
|
|
13467
|
+
if (authTimer)
|
|
13468
|
+
clearTimeout(authTimer);
|
|
13469
|
+
this.authenticating = false;
|
|
13470
|
+
this.connectPromise = null;
|
|
13471
|
+
reject(e);
|
|
13472
|
+
}
|
|
13473
|
+
};
|
|
13342
13474
|
const onError = (e) => {
|
|
13475
|
+
if (authTimer)
|
|
13476
|
+
clearTimeout(authTimer);
|
|
13477
|
+
this.authenticating = false;
|
|
13343
13478
|
ws.removeEventListener('open', onOpen);
|
|
13344
13479
|
this.connectPromise = null;
|
|
13345
13480
|
reject(new Error('WebSocket connection failed'));
|
|
@@ -13347,9 +13482,22 @@ class RealtimeStore {
|
|
|
13347
13482
|
ws.addEventListener('open', onOpen, { once: true });
|
|
13348
13483
|
ws.addEventListener('error', onError, { once: true });
|
|
13349
13484
|
ws.addEventListener('message', (event) => {
|
|
13485
|
+
if (this.authenticating) {
|
|
13486
|
+
try {
|
|
13487
|
+
const msg = JSON.parse(typeof event.data === 'string' ? event.data : new TextDecoder().decode(event.data));
|
|
13488
|
+
if ((msg === null || msg === void 0 ? void 0 : msg.type) === 'authenticated') {
|
|
13489
|
+
finishConnected();
|
|
13490
|
+
return;
|
|
13491
|
+
}
|
|
13492
|
+
}
|
|
13493
|
+
catch ( /* fall through to normal handling */_a) { /* fall through to normal handling */ }
|
|
13494
|
+
}
|
|
13350
13495
|
this.handleMessage(event.data);
|
|
13351
13496
|
});
|
|
13352
13497
|
ws.addEventListener('close', () => {
|
|
13498
|
+
if (authTimer)
|
|
13499
|
+
clearTimeout(authTimer);
|
|
13500
|
+
this.authenticating = false;
|
|
13353
13501
|
this.ws = null;
|
|
13354
13502
|
this.connectPromise = null;
|
|
13355
13503
|
this.rejectAllPending('WebSocket closed');
|
|
@@ -13402,6 +13550,8 @@ class RealtimeStore {
|
|
|
13402
13550
|
break;
|
|
13403
13551
|
case 'pong':
|
|
13404
13552
|
break;
|
|
13553
|
+
case 'authenticated':
|
|
13554
|
+
break;
|
|
13405
13555
|
// v1 compat: handle legacy message types during transition
|
|
13406
13556
|
case 'subscribed':
|
|
13407
13557
|
this.handleSnapshot(Object.assign(Object.assign({}, msg), { type: 'snapshot', docs: msg.data }));
|
|
@@ -14003,6 +14153,17 @@ function resetRealtimeStore() {
|
|
|
14003
14153
|
// rule, and dispatches to the function — returning its JSON, or throwing on
|
|
14004
14154
|
// 403 / error.
|
|
14005
14155
|
// ---------------------------------------------------------------------------
|
|
14156
|
+
var __rest = function (s, e) {
|
|
14157
|
+
var t = {};
|
|
14158
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14159
|
+
t[p] = s[p];
|
|
14160
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
14161
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
14162
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
14163
|
+
t[p[i]] = s[p[i]];
|
|
14164
|
+
}
|
|
14165
|
+
return t;
|
|
14166
|
+
};
|
|
14006
14167
|
/** Prod functions dispatcher; overridable via init({ functionsUrl }) or network preset. */
|
|
14007
14168
|
const DEFAULT_FUNCTIONS_URL = 'https://functions.bounded.sh';
|
|
14008
14169
|
class FunctionInvokeError extends Error {
|
|
@@ -14013,6 +14174,12 @@ class FunctionInvokeError extends Error {
|
|
|
14013
14174
|
this.name = 'FunctionInvokeError';
|
|
14014
14175
|
}
|
|
14015
14176
|
}
|
|
14177
|
+
function stripAuthHeaders(headers) {
|
|
14178
|
+
if (!headers)
|
|
14179
|
+
return undefined;
|
|
14180
|
+
const { Authorization, authorization } = headers, rest = __rest(headers, ["Authorization", "authorization"]);
|
|
14181
|
+
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
14182
|
+
}
|
|
14016
14183
|
/**
|
|
14017
14184
|
* Invoke a deployed Bounded Function by name. Returns the function's JSON.
|
|
14018
14185
|
*
|
|
@@ -14035,7 +14202,7 @@ async function invoke(name, args = {}, opts = {}) {
|
|
|
14035
14202
|
const authHeader = ((_a = opts._overrides) === null || _a === void 0 ? void 0 : _a._getAuthHeaders)
|
|
14036
14203
|
? await opts._overrides._getAuthHeaders()
|
|
14037
14204
|
: await createAuthHeader(config.isServer);
|
|
14038
|
-
const headers = Object.assign(Object.assign({ 'Content-Type': 'application/json', 'X-App-Id': config.appId, 'X-Public-App-Id': config.appId }, (
|
|
14205
|
+
const headers = Object.assign(Object.assign({ 'Content-Type': 'application/json', 'X-App-Id': config.appId, 'X-Public-App-Id': config.appId }, ((_b = stripAuthHeaders(opts.headers)) !== null && _b !== void 0 ? _b : {})), (authHeader !== null && authHeader !== void 0 ? authHeader : {}));
|
|
14039
14206
|
const controller = new AbortController();
|
|
14040
14207
|
const timeoutMs = (_c = opts.timeoutMs) !== null && _c !== void 0 ? _c : 60000;
|
|
14041
14208
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -14586,14 +14753,22 @@ class MockAuthProvider {
|
|
|
14586
14753
|
}
|
|
14587
14754
|
async signMessageMock(message) {
|
|
14588
14755
|
const address = getPlatform().sessionStorage.getItem('test-user-address') || DEFAULT_TEST_ADDRESS;
|
|
14589
|
-
//
|
|
14590
|
-
|
|
14756
|
+
// Offchain transactions are verified by hashing the exact message. Keep the
|
|
14757
|
+
// mock provider deterministic so mockAuth exercises the same integrity check.
|
|
14758
|
+
const signature = await this.generateOffchainSignature(message);
|
|
14591
14759
|
console.log('[MockAuth] Mock message signed:', {
|
|
14592
14760
|
address,
|
|
14593
14761
|
message,
|
|
14594
|
-
signature
|
|
14762
|
+
signature
|
|
14595
14763
|
});
|
|
14596
|
-
return
|
|
14764
|
+
return signature;
|
|
14765
|
+
}
|
|
14766
|
+
async generateOffchainSignature(message) {
|
|
14767
|
+
const platform = getPlatform();
|
|
14768
|
+
const data = platform.textEncode(message);
|
|
14769
|
+
const hashBuffer = await platform.sha256(data);
|
|
14770
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
14771
|
+
return platform.btoa(String.fromCharCode(...hashArray));
|
|
14597
14772
|
}
|
|
14598
14773
|
/**
|
|
14599
14774
|
* Mock transaction signing - returns the transaction as-is (no actual signing)
|
|
@@ -17964,2549 +18139,144 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
17964
18139
|
default: bs58
|
|
17965
18140
|
});
|
|
17966
18141
|
|
|
17967
|
-
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
|
|
17971
|
-
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
|
|
17976
|
-
|
|
17977
|
-
|
|
17978
|
-
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
|
|
17983
|
-
|
|
17984
|
-
|
|
17985
|
-
|
|
17986
|
-
|
|
17987
|
-
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
|
|
17993
|
-
|
|
17994
|
-
|
|
17995
|
-
|
|
17996
|
-
|
|
17997
|
-
|
|
17998
|
-
|
|
17999
|
-
|
|
18000
|
-
|
|
18001
|
-
|
|
18002
|
-
|
|
18003
|
-
|
|
18004
|
-
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
|
|
18010
|
-
|
|
18011
|
-
|
|
18012
|
-
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
|
|
18035
|
-
|
|
18036
|
-
|
|
18037
|
-
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
|
|
18044
|
-
|
|
18045
|
-
|
|
18046
|
-
|
|
18047
|
-
|
|
18048
|
-
|
|
18049
|
-
|
|
18050
|
-
|
|
18051
|
-
|
|
18052
|
-
|
|
18053
|
-
|
|
18054
|
-
|
|
18055
|
-
|
|
18056
|
-
|
|
18057
|
-
|
|
18058
|
-
|
|
18059
|
-
|
|
18060
|
-
|
|
18061
|
-
|
|
18062
|
-
|
|
18063
|
-
|
|
18064
|
-
|
|
18065
|
-
|
|
18066
|
-
|
|
18067
|
-
|
|
18068
|
-
|
|
18069
|
-
|
|
18070
|
-
|
|
18071
|
-
|
|
18072
|
-
|
|
18073
|
-
|
|
18074
|
-
|
|
18075
|
-
|
|
18076
|
-
|
|
18077
|
-
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18081
|
-
|
|
18082
|
-
|
|
18083
|
-
|
|
18084
|
-
|
|
18085
|
-
|
|
18086
|
-
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
|
|
18092
|
-
|
|
18093
|
-
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18097
|
-
|
|
18098
|
-
|
|
18099
|
-
|
|
18100
|
-
|
|
18101
|
-
|
|
18102
|
-
|
|
18103
|
-
|
|
18104
|
-
|
|
18105
|
-
|
|
18106
|
-
u = x10 + x9 | 0;
|
|
18107
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
18108
|
-
u = x11 + x10 | 0;
|
|
18109
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
18110
|
-
u = x8 + x11 | 0;
|
|
18111
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
18112
|
-
u = x9 + x8 | 0;
|
|
18113
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
18114
|
-
|
|
18115
|
-
u = x15 + x14 | 0;
|
|
18116
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
18117
|
-
u = x12 + x15 | 0;
|
|
18118
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
18119
|
-
u = x13 + x12 | 0;
|
|
18120
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
18121
|
-
u = x14 + x13 | 0;
|
|
18122
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
18123
|
-
}
|
|
18124
|
-
x0 = x0 + j0 | 0;
|
|
18125
|
-
x1 = x1 + j1 | 0;
|
|
18126
|
-
x2 = x2 + j2 | 0;
|
|
18127
|
-
x3 = x3 + j3 | 0;
|
|
18128
|
-
x4 = x4 + j4 | 0;
|
|
18129
|
-
x5 = x5 + j5 | 0;
|
|
18130
|
-
x6 = x6 + j6 | 0;
|
|
18131
|
-
x7 = x7 + j7 | 0;
|
|
18132
|
-
x8 = x8 + j8 | 0;
|
|
18133
|
-
x9 = x9 + j9 | 0;
|
|
18134
|
-
x10 = x10 + j10 | 0;
|
|
18135
|
-
x11 = x11 + j11 | 0;
|
|
18136
|
-
x12 = x12 + j12 | 0;
|
|
18137
|
-
x13 = x13 + j13 | 0;
|
|
18138
|
-
x14 = x14 + j14 | 0;
|
|
18139
|
-
x15 = x15 + j15 | 0;
|
|
18140
|
-
|
|
18141
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
18142
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
18143
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
18144
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
18145
|
-
|
|
18146
|
-
o[ 4] = x1 >>> 0 & 0xff;
|
|
18147
|
-
o[ 5] = x1 >>> 8 & 0xff;
|
|
18148
|
-
o[ 6] = x1 >>> 16 & 0xff;
|
|
18149
|
-
o[ 7] = x1 >>> 24 & 0xff;
|
|
18150
|
-
|
|
18151
|
-
o[ 8] = x2 >>> 0 & 0xff;
|
|
18152
|
-
o[ 9] = x2 >>> 8 & 0xff;
|
|
18153
|
-
o[10] = x2 >>> 16 & 0xff;
|
|
18154
|
-
o[11] = x2 >>> 24 & 0xff;
|
|
18155
|
-
|
|
18156
|
-
o[12] = x3 >>> 0 & 0xff;
|
|
18157
|
-
o[13] = x3 >>> 8 & 0xff;
|
|
18158
|
-
o[14] = x3 >>> 16 & 0xff;
|
|
18159
|
-
o[15] = x3 >>> 24 & 0xff;
|
|
18160
|
-
|
|
18161
|
-
o[16] = x4 >>> 0 & 0xff;
|
|
18162
|
-
o[17] = x4 >>> 8 & 0xff;
|
|
18163
|
-
o[18] = x4 >>> 16 & 0xff;
|
|
18164
|
-
o[19] = x4 >>> 24 & 0xff;
|
|
18165
|
-
|
|
18166
|
-
o[20] = x5 >>> 0 & 0xff;
|
|
18167
|
-
o[21] = x5 >>> 8 & 0xff;
|
|
18168
|
-
o[22] = x5 >>> 16 & 0xff;
|
|
18169
|
-
o[23] = x5 >>> 24 & 0xff;
|
|
18170
|
-
|
|
18171
|
-
o[24] = x6 >>> 0 & 0xff;
|
|
18172
|
-
o[25] = x6 >>> 8 & 0xff;
|
|
18173
|
-
o[26] = x6 >>> 16 & 0xff;
|
|
18174
|
-
o[27] = x6 >>> 24 & 0xff;
|
|
18175
|
-
|
|
18176
|
-
o[28] = x7 >>> 0 & 0xff;
|
|
18177
|
-
o[29] = x7 >>> 8 & 0xff;
|
|
18178
|
-
o[30] = x7 >>> 16 & 0xff;
|
|
18179
|
-
o[31] = x7 >>> 24 & 0xff;
|
|
18180
|
-
|
|
18181
|
-
o[32] = x8 >>> 0 & 0xff;
|
|
18182
|
-
o[33] = x8 >>> 8 & 0xff;
|
|
18183
|
-
o[34] = x8 >>> 16 & 0xff;
|
|
18184
|
-
o[35] = x8 >>> 24 & 0xff;
|
|
18185
|
-
|
|
18186
|
-
o[36] = x9 >>> 0 & 0xff;
|
|
18187
|
-
o[37] = x9 >>> 8 & 0xff;
|
|
18188
|
-
o[38] = x9 >>> 16 & 0xff;
|
|
18189
|
-
o[39] = x9 >>> 24 & 0xff;
|
|
18190
|
-
|
|
18191
|
-
o[40] = x10 >>> 0 & 0xff;
|
|
18192
|
-
o[41] = x10 >>> 8 & 0xff;
|
|
18193
|
-
o[42] = x10 >>> 16 & 0xff;
|
|
18194
|
-
o[43] = x10 >>> 24 & 0xff;
|
|
18195
|
-
|
|
18196
|
-
o[44] = x11 >>> 0 & 0xff;
|
|
18197
|
-
o[45] = x11 >>> 8 & 0xff;
|
|
18198
|
-
o[46] = x11 >>> 16 & 0xff;
|
|
18199
|
-
o[47] = x11 >>> 24 & 0xff;
|
|
18200
|
-
|
|
18201
|
-
o[48] = x12 >>> 0 & 0xff;
|
|
18202
|
-
o[49] = x12 >>> 8 & 0xff;
|
|
18203
|
-
o[50] = x12 >>> 16 & 0xff;
|
|
18204
|
-
o[51] = x12 >>> 24 & 0xff;
|
|
18205
|
-
|
|
18206
|
-
o[52] = x13 >>> 0 & 0xff;
|
|
18207
|
-
o[53] = x13 >>> 8 & 0xff;
|
|
18208
|
-
o[54] = x13 >>> 16 & 0xff;
|
|
18209
|
-
o[55] = x13 >>> 24 & 0xff;
|
|
18210
|
-
|
|
18211
|
-
o[56] = x14 >>> 0 & 0xff;
|
|
18212
|
-
o[57] = x14 >>> 8 & 0xff;
|
|
18213
|
-
o[58] = x14 >>> 16 & 0xff;
|
|
18214
|
-
o[59] = x14 >>> 24 & 0xff;
|
|
18215
|
-
|
|
18216
|
-
o[60] = x15 >>> 0 & 0xff;
|
|
18217
|
-
o[61] = x15 >>> 8 & 0xff;
|
|
18218
|
-
o[62] = x15 >>> 16 & 0xff;
|
|
18219
|
-
o[63] = x15 >>> 24 & 0xff;
|
|
18220
|
-
}
|
|
18221
|
-
|
|
18222
|
-
function core_hsalsa20(o,p,k,c) {
|
|
18223
|
-
var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
|
|
18224
|
-
j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
|
|
18225
|
-
j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
|
|
18226
|
-
j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
|
|
18227
|
-
j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
|
|
18228
|
-
j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
|
|
18229
|
-
j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
|
|
18230
|
-
j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
|
|
18231
|
-
j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
|
|
18232
|
-
j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
|
|
18233
|
-
j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
|
|
18234
|
-
j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
|
|
18235
|
-
j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
|
|
18236
|
-
j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
|
|
18237
|
-
j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
|
|
18238
|
-
j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
|
|
18239
|
-
|
|
18240
|
-
var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
|
|
18241
|
-
x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
|
|
18242
|
-
x15 = j15, u;
|
|
18243
|
-
|
|
18244
|
-
for (var i = 0; i < 20; i += 2) {
|
|
18245
|
-
u = x0 + x12 | 0;
|
|
18246
|
-
x4 ^= u<<7 | u>>>(32-7);
|
|
18247
|
-
u = x4 + x0 | 0;
|
|
18248
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
18249
|
-
u = x8 + x4 | 0;
|
|
18250
|
-
x12 ^= u<<13 | u>>>(32-13);
|
|
18251
|
-
u = x12 + x8 | 0;
|
|
18252
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
18253
|
-
|
|
18254
|
-
u = x5 + x1 | 0;
|
|
18255
|
-
x9 ^= u<<7 | u>>>(32-7);
|
|
18256
|
-
u = x9 + x5 | 0;
|
|
18257
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
18258
|
-
u = x13 + x9 | 0;
|
|
18259
|
-
x1 ^= u<<13 | u>>>(32-13);
|
|
18260
|
-
u = x1 + x13 | 0;
|
|
18261
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
18262
|
-
|
|
18263
|
-
u = x10 + x6 | 0;
|
|
18264
|
-
x14 ^= u<<7 | u>>>(32-7);
|
|
18265
|
-
u = x14 + x10 | 0;
|
|
18266
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
18267
|
-
u = x2 + x14 | 0;
|
|
18268
|
-
x6 ^= u<<13 | u>>>(32-13);
|
|
18269
|
-
u = x6 + x2 | 0;
|
|
18270
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
18271
|
-
|
|
18272
|
-
u = x15 + x11 | 0;
|
|
18273
|
-
x3 ^= u<<7 | u>>>(32-7);
|
|
18274
|
-
u = x3 + x15 | 0;
|
|
18275
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
18276
|
-
u = x7 + x3 | 0;
|
|
18277
|
-
x11 ^= u<<13 | u>>>(32-13);
|
|
18278
|
-
u = x11 + x7 | 0;
|
|
18279
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
18280
|
-
|
|
18281
|
-
u = x0 + x3 | 0;
|
|
18282
|
-
x1 ^= u<<7 | u>>>(32-7);
|
|
18283
|
-
u = x1 + x0 | 0;
|
|
18284
|
-
x2 ^= u<<9 | u>>>(32-9);
|
|
18285
|
-
u = x2 + x1 | 0;
|
|
18286
|
-
x3 ^= u<<13 | u>>>(32-13);
|
|
18287
|
-
u = x3 + x2 | 0;
|
|
18288
|
-
x0 ^= u<<18 | u>>>(32-18);
|
|
18289
|
-
|
|
18290
|
-
u = x5 + x4 | 0;
|
|
18291
|
-
x6 ^= u<<7 | u>>>(32-7);
|
|
18292
|
-
u = x6 + x5 | 0;
|
|
18293
|
-
x7 ^= u<<9 | u>>>(32-9);
|
|
18294
|
-
u = x7 + x6 | 0;
|
|
18295
|
-
x4 ^= u<<13 | u>>>(32-13);
|
|
18296
|
-
u = x4 + x7 | 0;
|
|
18297
|
-
x5 ^= u<<18 | u>>>(32-18);
|
|
18298
|
-
|
|
18299
|
-
u = x10 + x9 | 0;
|
|
18300
|
-
x11 ^= u<<7 | u>>>(32-7);
|
|
18301
|
-
u = x11 + x10 | 0;
|
|
18302
|
-
x8 ^= u<<9 | u>>>(32-9);
|
|
18303
|
-
u = x8 + x11 | 0;
|
|
18304
|
-
x9 ^= u<<13 | u>>>(32-13);
|
|
18305
|
-
u = x9 + x8 | 0;
|
|
18306
|
-
x10 ^= u<<18 | u>>>(32-18);
|
|
18307
|
-
|
|
18308
|
-
u = x15 + x14 | 0;
|
|
18309
|
-
x12 ^= u<<7 | u>>>(32-7);
|
|
18310
|
-
u = x12 + x15 | 0;
|
|
18311
|
-
x13 ^= u<<9 | u>>>(32-9);
|
|
18312
|
-
u = x13 + x12 | 0;
|
|
18313
|
-
x14 ^= u<<13 | u>>>(32-13);
|
|
18314
|
-
u = x14 + x13 | 0;
|
|
18315
|
-
x15 ^= u<<18 | u>>>(32-18);
|
|
18316
|
-
}
|
|
18317
|
-
|
|
18318
|
-
o[ 0] = x0 >>> 0 & 0xff;
|
|
18319
|
-
o[ 1] = x0 >>> 8 & 0xff;
|
|
18320
|
-
o[ 2] = x0 >>> 16 & 0xff;
|
|
18321
|
-
o[ 3] = x0 >>> 24 & 0xff;
|
|
18322
|
-
|
|
18323
|
-
o[ 4] = x5 >>> 0 & 0xff;
|
|
18324
|
-
o[ 5] = x5 >>> 8 & 0xff;
|
|
18325
|
-
o[ 6] = x5 >>> 16 & 0xff;
|
|
18326
|
-
o[ 7] = x5 >>> 24 & 0xff;
|
|
18327
|
-
|
|
18328
|
-
o[ 8] = x10 >>> 0 & 0xff;
|
|
18329
|
-
o[ 9] = x10 >>> 8 & 0xff;
|
|
18330
|
-
o[10] = x10 >>> 16 & 0xff;
|
|
18331
|
-
o[11] = x10 >>> 24 & 0xff;
|
|
18332
|
-
|
|
18333
|
-
o[12] = x15 >>> 0 & 0xff;
|
|
18334
|
-
o[13] = x15 >>> 8 & 0xff;
|
|
18335
|
-
o[14] = x15 >>> 16 & 0xff;
|
|
18336
|
-
o[15] = x15 >>> 24 & 0xff;
|
|
18337
|
-
|
|
18338
|
-
o[16] = x6 >>> 0 & 0xff;
|
|
18339
|
-
o[17] = x6 >>> 8 & 0xff;
|
|
18340
|
-
o[18] = x6 >>> 16 & 0xff;
|
|
18341
|
-
o[19] = x6 >>> 24 & 0xff;
|
|
18342
|
-
|
|
18343
|
-
o[20] = x7 >>> 0 & 0xff;
|
|
18344
|
-
o[21] = x7 >>> 8 & 0xff;
|
|
18345
|
-
o[22] = x7 >>> 16 & 0xff;
|
|
18346
|
-
o[23] = x7 >>> 24 & 0xff;
|
|
18347
|
-
|
|
18348
|
-
o[24] = x8 >>> 0 & 0xff;
|
|
18349
|
-
o[25] = x8 >>> 8 & 0xff;
|
|
18350
|
-
o[26] = x8 >>> 16 & 0xff;
|
|
18351
|
-
o[27] = x8 >>> 24 & 0xff;
|
|
18352
|
-
|
|
18353
|
-
o[28] = x9 >>> 0 & 0xff;
|
|
18354
|
-
o[29] = x9 >>> 8 & 0xff;
|
|
18355
|
-
o[30] = x9 >>> 16 & 0xff;
|
|
18356
|
-
o[31] = x9 >>> 24 & 0xff;
|
|
18357
|
-
}
|
|
18358
|
-
|
|
18359
|
-
function crypto_core_salsa20(out,inp,k,c) {
|
|
18360
|
-
core_salsa20(out,inp,k,c);
|
|
18361
|
-
}
|
|
18362
|
-
|
|
18363
|
-
function crypto_core_hsalsa20(out,inp,k,c) {
|
|
18364
|
-
core_hsalsa20(out,inp,k,c);
|
|
18365
|
-
}
|
|
18366
|
-
|
|
18367
|
-
var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
|
|
18368
|
-
// "expand 32-byte k"
|
|
18369
|
-
|
|
18370
|
-
function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
|
|
18371
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
18372
|
-
var u, i;
|
|
18373
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
18374
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
18375
|
-
while (b >= 64) {
|
|
18376
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18377
|
-
for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
18378
|
-
u = 1;
|
|
18379
|
-
for (i = 8; i < 16; i++) {
|
|
18380
|
-
u = u + (z[i] & 0xff) | 0;
|
|
18381
|
-
z[i] = u & 0xff;
|
|
18382
|
-
u >>>= 8;
|
|
18383
|
-
}
|
|
18384
|
-
b -= 64;
|
|
18385
|
-
cpos += 64;
|
|
18386
|
-
mpos += 64;
|
|
18387
|
-
}
|
|
18388
|
-
if (b > 0) {
|
|
18389
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18390
|
-
for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
|
|
18391
|
-
}
|
|
18392
|
-
return 0;
|
|
18393
|
-
}
|
|
18394
|
-
|
|
18395
|
-
function crypto_stream_salsa20(c,cpos,b,n,k) {
|
|
18396
|
-
var z = new Uint8Array(16), x = new Uint8Array(64);
|
|
18397
|
-
var u, i;
|
|
18398
|
-
for (i = 0; i < 16; i++) z[i] = 0;
|
|
18399
|
-
for (i = 0; i < 8; i++) z[i] = n[i];
|
|
18400
|
-
while (b >= 64) {
|
|
18401
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18402
|
-
for (i = 0; i < 64; i++) c[cpos+i] = x[i];
|
|
18403
|
-
u = 1;
|
|
18404
|
-
for (i = 8; i < 16; i++) {
|
|
18405
|
-
u = u + (z[i] & 0xff) | 0;
|
|
18406
|
-
z[i] = u & 0xff;
|
|
18407
|
-
u >>>= 8;
|
|
18408
|
-
}
|
|
18409
|
-
b -= 64;
|
|
18410
|
-
cpos += 64;
|
|
18411
|
-
}
|
|
18412
|
-
if (b > 0) {
|
|
18413
|
-
crypto_core_salsa20(x,z,k,sigma);
|
|
18414
|
-
for (i = 0; i < b; i++) c[cpos+i] = x[i];
|
|
18415
|
-
}
|
|
18416
|
-
return 0;
|
|
18417
|
-
}
|
|
18418
|
-
|
|
18419
|
-
function crypto_stream(c,cpos,d,n,k) {
|
|
18420
|
-
var s = new Uint8Array(32);
|
|
18421
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
18422
|
-
var sn = new Uint8Array(8);
|
|
18423
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
18424
|
-
return crypto_stream_salsa20(c,cpos,d,sn,s);
|
|
18425
|
-
}
|
|
18426
|
-
|
|
18427
|
-
function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
|
|
18428
|
-
var s = new Uint8Array(32);
|
|
18429
|
-
crypto_core_hsalsa20(s,n,k,sigma);
|
|
18430
|
-
var sn = new Uint8Array(8);
|
|
18431
|
-
for (var i = 0; i < 8; i++) sn[i] = n[i+16];
|
|
18432
|
-
return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
|
|
18433
|
-
}
|
|
18434
|
-
|
|
18435
|
-
/*
|
|
18436
|
-
* Port of Andrew Moon's Poly1305-donna-16. Public domain.
|
|
18437
|
-
* https://github.com/floodyberry/poly1305-donna
|
|
18438
|
-
*/
|
|
18439
|
-
|
|
18440
|
-
var poly1305 = function(key) {
|
|
18441
|
-
this.buffer = new Uint8Array(16);
|
|
18442
|
-
this.r = new Uint16Array(10);
|
|
18443
|
-
this.h = new Uint16Array(10);
|
|
18444
|
-
this.pad = new Uint16Array(8);
|
|
18445
|
-
this.leftover = 0;
|
|
18446
|
-
this.fin = 0;
|
|
18447
|
-
|
|
18448
|
-
var t0, t1, t2, t3, t4, t5, t6, t7;
|
|
18449
|
-
|
|
18450
|
-
t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
|
|
18451
|
-
t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
18452
|
-
t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
|
|
18453
|
-
t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
18454
|
-
t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
|
|
18455
|
-
this.r[5] = ((t4 >>> 1)) & 0x1ffe;
|
|
18456
|
-
t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
18457
|
-
t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
|
|
18458
|
-
t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
18459
|
-
this.r[9] = ((t7 >>> 5)) & 0x007f;
|
|
18460
|
-
|
|
18461
|
-
this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
|
|
18462
|
-
this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
|
|
18463
|
-
this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
|
|
18464
|
-
this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
|
|
18465
|
-
this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
|
|
18466
|
-
this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
|
|
18467
|
-
this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
|
|
18468
|
-
this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
|
|
18469
|
-
};
|
|
18470
|
-
|
|
18471
|
-
poly1305.prototype.blocks = function(m, mpos, bytes) {
|
|
18472
|
-
var hibit = this.fin ? 0 : (1 << 11);
|
|
18473
|
-
var t0, t1, t2, t3, t4, t5, t6, t7, c;
|
|
18474
|
-
var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
|
|
18475
|
-
|
|
18476
|
-
var h0 = this.h[0],
|
|
18477
|
-
h1 = this.h[1],
|
|
18478
|
-
h2 = this.h[2],
|
|
18479
|
-
h3 = this.h[3],
|
|
18480
|
-
h4 = this.h[4],
|
|
18481
|
-
h5 = this.h[5],
|
|
18482
|
-
h6 = this.h[6],
|
|
18483
|
-
h7 = this.h[7],
|
|
18484
|
-
h8 = this.h[8],
|
|
18485
|
-
h9 = this.h[9];
|
|
18486
|
-
|
|
18487
|
-
var r0 = this.r[0],
|
|
18488
|
-
r1 = this.r[1],
|
|
18489
|
-
r2 = this.r[2],
|
|
18490
|
-
r3 = this.r[3],
|
|
18491
|
-
r4 = this.r[4],
|
|
18492
|
-
r5 = this.r[5],
|
|
18493
|
-
r6 = this.r[6],
|
|
18494
|
-
r7 = this.r[7],
|
|
18495
|
-
r8 = this.r[8],
|
|
18496
|
-
r9 = this.r[9];
|
|
18497
|
-
|
|
18498
|
-
while (bytes >= 16) {
|
|
18499
|
-
t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
|
|
18500
|
-
t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
|
|
18501
|
-
t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
|
|
18502
|
-
t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
|
|
18503
|
-
t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
|
|
18504
|
-
h5 += ((t4 >>> 1)) & 0x1fff;
|
|
18505
|
-
t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
|
|
18506
|
-
t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
|
|
18507
|
-
t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
|
|
18508
|
-
h9 += ((t7 >>> 5)) | hibit;
|
|
18509
|
-
|
|
18510
|
-
c = 0;
|
|
18511
|
-
|
|
18512
|
-
d0 = c;
|
|
18513
|
-
d0 += h0 * r0;
|
|
18514
|
-
d0 += h1 * (5 * r9);
|
|
18515
|
-
d0 += h2 * (5 * r8);
|
|
18516
|
-
d0 += h3 * (5 * r7);
|
|
18517
|
-
d0 += h4 * (5 * r6);
|
|
18518
|
-
c = (d0 >>> 13); d0 &= 0x1fff;
|
|
18519
|
-
d0 += h5 * (5 * r5);
|
|
18520
|
-
d0 += h6 * (5 * r4);
|
|
18521
|
-
d0 += h7 * (5 * r3);
|
|
18522
|
-
d0 += h8 * (5 * r2);
|
|
18523
|
-
d0 += h9 * (5 * r1);
|
|
18524
|
-
c += (d0 >>> 13); d0 &= 0x1fff;
|
|
18525
|
-
|
|
18526
|
-
d1 = c;
|
|
18527
|
-
d1 += h0 * r1;
|
|
18528
|
-
d1 += h1 * r0;
|
|
18529
|
-
d1 += h2 * (5 * r9);
|
|
18530
|
-
d1 += h3 * (5 * r8);
|
|
18531
|
-
d1 += h4 * (5 * r7);
|
|
18532
|
-
c = (d1 >>> 13); d1 &= 0x1fff;
|
|
18533
|
-
d1 += h5 * (5 * r6);
|
|
18534
|
-
d1 += h6 * (5 * r5);
|
|
18535
|
-
d1 += h7 * (5 * r4);
|
|
18536
|
-
d1 += h8 * (5 * r3);
|
|
18537
|
-
d1 += h9 * (5 * r2);
|
|
18538
|
-
c += (d1 >>> 13); d1 &= 0x1fff;
|
|
18539
|
-
|
|
18540
|
-
d2 = c;
|
|
18541
|
-
d2 += h0 * r2;
|
|
18542
|
-
d2 += h1 * r1;
|
|
18543
|
-
d2 += h2 * r0;
|
|
18544
|
-
d2 += h3 * (5 * r9);
|
|
18545
|
-
d2 += h4 * (5 * r8);
|
|
18546
|
-
c = (d2 >>> 13); d2 &= 0x1fff;
|
|
18547
|
-
d2 += h5 * (5 * r7);
|
|
18548
|
-
d2 += h6 * (5 * r6);
|
|
18549
|
-
d2 += h7 * (5 * r5);
|
|
18550
|
-
d2 += h8 * (5 * r4);
|
|
18551
|
-
d2 += h9 * (5 * r3);
|
|
18552
|
-
c += (d2 >>> 13); d2 &= 0x1fff;
|
|
18553
|
-
|
|
18554
|
-
d3 = c;
|
|
18555
|
-
d3 += h0 * r3;
|
|
18556
|
-
d3 += h1 * r2;
|
|
18557
|
-
d3 += h2 * r1;
|
|
18558
|
-
d3 += h3 * r0;
|
|
18559
|
-
d3 += h4 * (5 * r9);
|
|
18560
|
-
c = (d3 >>> 13); d3 &= 0x1fff;
|
|
18561
|
-
d3 += h5 * (5 * r8);
|
|
18562
|
-
d3 += h6 * (5 * r7);
|
|
18563
|
-
d3 += h7 * (5 * r6);
|
|
18564
|
-
d3 += h8 * (5 * r5);
|
|
18565
|
-
d3 += h9 * (5 * r4);
|
|
18566
|
-
c += (d3 >>> 13); d3 &= 0x1fff;
|
|
18567
|
-
|
|
18568
|
-
d4 = c;
|
|
18569
|
-
d4 += h0 * r4;
|
|
18570
|
-
d4 += h1 * r3;
|
|
18571
|
-
d4 += h2 * r2;
|
|
18572
|
-
d4 += h3 * r1;
|
|
18573
|
-
d4 += h4 * r0;
|
|
18574
|
-
c = (d4 >>> 13); d4 &= 0x1fff;
|
|
18575
|
-
d4 += h5 * (5 * r9);
|
|
18576
|
-
d4 += h6 * (5 * r8);
|
|
18577
|
-
d4 += h7 * (5 * r7);
|
|
18578
|
-
d4 += h8 * (5 * r6);
|
|
18579
|
-
d4 += h9 * (5 * r5);
|
|
18580
|
-
c += (d4 >>> 13); d4 &= 0x1fff;
|
|
18581
|
-
|
|
18582
|
-
d5 = c;
|
|
18583
|
-
d5 += h0 * r5;
|
|
18584
|
-
d5 += h1 * r4;
|
|
18585
|
-
d5 += h2 * r3;
|
|
18586
|
-
d5 += h3 * r2;
|
|
18587
|
-
d5 += h4 * r1;
|
|
18588
|
-
c = (d5 >>> 13); d5 &= 0x1fff;
|
|
18589
|
-
d5 += h5 * r0;
|
|
18590
|
-
d5 += h6 * (5 * r9);
|
|
18591
|
-
d5 += h7 * (5 * r8);
|
|
18592
|
-
d5 += h8 * (5 * r7);
|
|
18593
|
-
d5 += h9 * (5 * r6);
|
|
18594
|
-
c += (d5 >>> 13); d5 &= 0x1fff;
|
|
18595
|
-
|
|
18596
|
-
d6 = c;
|
|
18597
|
-
d6 += h0 * r6;
|
|
18598
|
-
d6 += h1 * r5;
|
|
18599
|
-
d6 += h2 * r4;
|
|
18600
|
-
d6 += h3 * r3;
|
|
18601
|
-
d6 += h4 * r2;
|
|
18602
|
-
c = (d6 >>> 13); d6 &= 0x1fff;
|
|
18603
|
-
d6 += h5 * r1;
|
|
18604
|
-
d6 += h6 * r0;
|
|
18605
|
-
d6 += h7 * (5 * r9);
|
|
18606
|
-
d6 += h8 * (5 * r8);
|
|
18607
|
-
d6 += h9 * (5 * r7);
|
|
18608
|
-
c += (d6 >>> 13); d6 &= 0x1fff;
|
|
18609
|
-
|
|
18610
|
-
d7 = c;
|
|
18611
|
-
d7 += h0 * r7;
|
|
18612
|
-
d7 += h1 * r6;
|
|
18613
|
-
d7 += h2 * r5;
|
|
18614
|
-
d7 += h3 * r4;
|
|
18615
|
-
d7 += h4 * r3;
|
|
18616
|
-
c = (d7 >>> 13); d7 &= 0x1fff;
|
|
18617
|
-
d7 += h5 * r2;
|
|
18618
|
-
d7 += h6 * r1;
|
|
18619
|
-
d7 += h7 * r0;
|
|
18620
|
-
d7 += h8 * (5 * r9);
|
|
18621
|
-
d7 += h9 * (5 * r8);
|
|
18622
|
-
c += (d7 >>> 13); d7 &= 0x1fff;
|
|
18623
|
-
|
|
18624
|
-
d8 = c;
|
|
18625
|
-
d8 += h0 * r8;
|
|
18626
|
-
d8 += h1 * r7;
|
|
18627
|
-
d8 += h2 * r6;
|
|
18628
|
-
d8 += h3 * r5;
|
|
18629
|
-
d8 += h4 * r4;
|
|
18630
|
-
c = (d8 >>> 13); d8 &= 0x1fff;
|
|
18631
|
-
d8 += h5 * r3;
|
|
18632
|
-
d8 += h6 * r2;
|
|
18633
|
-
d8 += h7 * r1;
|
|
18634
|
-
d8 += h8 * r0;
|
|
18635
|
-
d8 += h9 * (5 * r9);
|
|
18636
|
-
c += (d8 >>> 13); d8 &= 0x1fff;
|
|
18637
|
-
|
|
18638
|
-
d9 = c;
|
|
18639
|
-
d9 += h0 * r9;
|
|
18640
|
-
d9 += h1 * r8;
|
|
18641
|
-
d9 += h2 * r7;
|
|
18642
|
-
d9 += h3 * r6;
|
|
18643
|
-
d9 += h4 * r5;
|
|
18644
|
-
c = (d9 >>> 13); d9 &= 0x1fff;
|
|
18645
|
-
d9 += h5 * r4;
|
|
18646
|
-
d9 += h6 * r3;
|
|
18647
|
-
d9 += h7 * r2;
|
|
18648
|
-
d9 += h8 * r1;
|
|
18649
|
-
d9 += h9 * r0;
|
|
18650
|
-
c += (d9 >>> 13); d9 &= 0x1fff;
|
|
18651
|
-
|
|
18652
|
-
c = (((c << 2) + c)) | 0;
|
|
18653
|
-
c = (c + d0) | 0;
|
|
18654
|
-
d0 = c & 0x1fff;
|
|
18655
|
-
c = (c >>> 13);
|
|
18656
|
-
d1 += c;
|
|
18657
|
-
|
|
18658
|
-
h0 = d0;
|
|
18659
|
-
h1 = d1;
|
|
18660
|
-
h2 = d2;
|
|
18661
|
-
h3 = d3;
|
|
18662
|
-
h4 = d4;
|
|
18663
|
-
h5 = d5;
|
|
18664
|
-
h6 = d6;
|
|
18665
|
-
h7 = d7;
|
|
18666
|
-
h8 = d8;
|
|
18667
|
-
h9 = d9;
|
|
18668
|
-
|
|
18669
|
-
mpos += 16;
|
|
18670
|
-
bytes -= 16;
|
|
18671
|
-
}
|
|
18672
|
-
this.h[0] = h0;
|
|
18673
|
-
this.h[1] = h1;
|
|
18674
|
-
this.h[2] = h2;
|
|
18675
|
-
this.h[3] = h3;
|
|
18676
|
-
this.h[4] = h4;
|
|
18677
|
-
this.h[5] = h5;
|
|
18678
|
-
this.h[6] = h6;
|
|
18679
|
-
this.h[7] = h7;
|
|
18680
|
-
this.h[8] = h8;
|
|
18681
|
-
this.h[9] = h9;
|
|
18682
|
-
};
|
|
18683
|
-
|
|
18684
|
-
poly1305.prototype.finish = function(mac, macpos) {
|
|
18685
|
-
var g = new Uint16Array(10);
|
|
18686
|
-
var c, mask, f, i;
|
|
18687
|
-
|
|
18688
|
-
if (this.leftover) {
|
|
18689
|
-
i = this.leftover;
|
|
18690
|
-
this.buffer[i++] = 1;
|
|
18691
|
-
for (; i < 16; i++) this.buffer[i] = 0;
|
|
18692
|
-
this.fin = 1;
|
|
18693
|
-
this.blocks(this.buffer, 0, 16);
|
|
18694
|
-
}
|
|
18695
|
-
|
|
18696
|
-
c = this.h[1] >>> 13;
|
|
18697
|
-
this.h[1] &= 0x1fff;
|
|
18698
|
-
for (i = 2; i < 10; i++) {
|
|
18699
|
-
this.h[i] += c;
|
|
18700
|
-
c = this.h[i] >>> 13;
|
|
18701
|
-
this.h[i] &= 0x1fff;
|
|
18702
|
-
}
|
|
18703
|
-
this.h[0] += (c * 5);
|
|
18704
|
-
c = this.h[0] >>> 13;
|
|
18705
|
-
this.h[0] &= 0x1fff;
|
|
18706
|
-
this.h[1] += c;
|
|
18707
|
-
c = this.h[1] >>> 13;
|
|
18708
|
-
this.h[1] &= 0x1fff;
|
|
18709
|
-
this.h[2] += c;
|
|
18710
|
-
|
|
18711
|
-
g[0] = this.h[0] + 5;
|
|
18712
|
-
c = g[0] >>> 13;
|
|
18713
|
-
g[0] &= 0x1fff;
|
|
18714
|
-
for (i = 1; i < 10; i++) {
|
|
18715
|
-
g[i] = this.h[i] + c;
|
|
18716
|
-
c = g[i] >>> 13;
|
|
18717
|
-
g[i] &= 0x1fff;
|
|
18718
|
-
}
|
|
18719
|
-
g[9] -= (1 << 13);
|
|
18720
|
-
|
|
18721
|
-
mask = (c ^ 1) - 1;
|
|
18722
|
-
for (i = 0; i < 10; i++) g[i] &= mask;
|
|
18723
|
-
mask = ~mask;
|
|
18724
|
-
for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
|
|
18725
|
-
|
|
18726
|
-
this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
|
|
18727
|
-
this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
|
|
18728
|
-
this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
|
|
18729
|
-
this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
|
|
18730
|
-
this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
|
|
18731
|
-
this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
|
|
18732
|
-
this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
|
|
18733
|
-
this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
|
|
18734
|
-
|
|
18735
|
-
f = this.h[0] + this.pad[0];
|
|
18736
|
-
this.h[0] = f & 0xffff;
|
|
18737
|
-
for (i = 1; i < 8; i++) {
|
|
18738
|
-
f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
|
|
18739
|
-
this.h[i] = f & 0xffff;
|
|
18740
|
-
}
|
|
18741
|
-
|
|
18742
|
-
mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
|
|
18743
|
-
mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
|
|
18744
|
-
mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
|
|
18745
|
-
mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
|
|
18746
|
-
mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
|
|
18747
|
-
mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
|
|
18748
|
-
mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
|
|
18749
|
-
mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
|
|
18750
|
-
mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
|
|
18751
|
-
mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
|
|
18752
|
-
mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
|
|
18753
|
-
mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
|
|
18754
|
-
mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
|
|
18755
|
-
mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
|
|
18756
|
-
mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
|
|
18757
|
-
mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
|
|
18758
|
-
};
|
|
18759
|
-
|
|
18760
|
-
poly1305.prototype.update = function(m, mpos, bytes) {
|
|
18761
|
-
var i, want;
|
|
18762
|
-
|
|
18763
|
-
if (this.leftover) {
|
|
18764
|
-
want = (16 - this.leftover);
|
|
18765
|
-
if (want > bytes)
|
|
18766
|
-
want = bytes;
|
|
18767
|
-
for (i = 0; i < want; i++)
|
|
18768
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
18769
|
-
bytes -= want;
|
|
18770
|
-
mpos += want;
|
|
18771
|
-
this.leftover += want;
|
|
18772
|
-
if (this.leftover < 16)
|
|
18773
|
-
return;
|
|
18774
|
-
this.blocks(this.buffer, 0, 16);
|
|
18775
|
-
this.leftover = 0;
|
|
18776
|
-
}
|
|
18777
|
-
|
|
18778
|
-
if (bytes >= 16) {
|
|
18779
|
-
want = bytes - (bytes % 16);
|
|
18780
|
-
this.blocks(m, mpos, want);
|
|
18781
|
-
mpos += want;
|
|
18782
|
-
bytes -= want;
|
|
18783
|
-
}
|
|
18784
|
-
|
|
18785
|
-
if (bytes) {
|
|
18786
|
-
for (i = 0; i < bytes; i++)
|
|
18787
|
-
this.buffer[this.leftover + i] = m[mpos+i];
|
|
18788
|
-
this.leftover += bytes;
|
|
18789
|
-
}
|
|
18790
|
-
};
|
|
18791
|
-
|
|
18792
|
-
function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
|
|
18793
|
-
var s = new poly1305(k);
|
|
18794
|
-
s.update(m, mpos, n);
|
|
18795
|
-
s.finish(out, outpos);
|
|
18796
|
-
return 0;
|
|
18797
|
-
}
|
|
18798
|
-
|
|
18799
|
-
function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
|
|
18800
|
-
var x = new Uint8Array(16);
|
|
18801
|
-
crypto_onetimeauth(x,0,m,mpos,n,k);
|
|
18802
|
-
return crypto_verify_16(h,hpos,x,0);
|
|
18803
|
-
}
|
|
18804
|
-
|
|
18805
|
-
function crypto_secretbox(c,m,d,n,k) {
|
|
18806
|
-
var i;
|
|
18807
|
-
if (d < 32) return -1;
|
|
18808
|
-
crypto_stream_xor(c,0,m,0,d,n,k);
|
|
18809
|
-
crypto_onetimeauth(c, 16, c, 32, d - 32, c);
|
|
18810
|
-
for (i = 0; i < 16; i++) c[i] = 0;
|
|
18811
|
-
return 0;
|
|
18812
|
-
}
|
|
18813
|
-
|
|
18814
|
-
function crypto_secretbox_open(m,c,d,n,k) {
|
|
18815
|
-
var i;
|
|
18816
|
-
var x = new Uint8Array(32);
|
|
18817
|
-
if (d < 32) return -1;
|
|
18818
|
-
crypto_stream(x,0,32,n,k);
|
|
18819
|
-
if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
|
|
18820
|
-
crypto_stream_xor(m,0,c,0,d,n,k);
|
|
18821
|
-
for (i = 0; i < 32; i++) m[i] = 0;
|
|
18822
|
-
return 0;
|
|
18823
|
-
}
|
|
18824
|
-
|
|
18825
|
-
function set25519(r, a) {
|
|
18826
|
-
var i;
|
|
18827
|
-
for (i = 0; i < 16; i++) r[i] = a[i]|0;
|
|
18828
|
-
}
|
|
18829
|
-
|
|
18830
|
-
function car25519(o) {
|
|
18831
|
-
var i, v, c = 1;
|
|
18832
|
-
for (i = 0; i < 16; i++) {
|
|
18833
|
-
v = o[i] + c + 65535;
|
|
18834
|
-
c = Math.floor(v / 65536);
|
|
18835
|
-
o[i] = v - c * 65536;
|
|
18836
|
-
}
|
|
18837
|
-
o[0] += c-1 + 37 * (c-1);
|
|
18838
|
-
}
|
|
18839
|
-
|
|
18840
|
-
function sel25519(p, q, b) {
|
|
18841
|
-
var t, c = ~(b-1);
|
|
18842
|
-
for (var i = 0; i < 16; i++) {
|
|
18843
|
-
t = c & (p[i] ^ q[i]);
|
|
18844
|
-
p[i] ^= t;
|
|
18845
|
-
q[i] ^= t;
|
|
18846
|
-
}
|
|
18847
|
-
}
|
|
18848
|
-
|
|
18849
|
-
function pack25519(o, n) {
|
|
18850
|
-
var i, j, b;
|
|
18851
|
-
var m = gf(), t = gf();
|
|
18852
|
-
for (i = 0; i < 16; i++) t[i] = n[i];
|
|
18853
|
-
car25519(t);
|
|
18854
|
-
car25519(t);
|
|
18855
|
-
car25519(t);
|
|
18856
|
-
for (j = 0; j < 2; j++) {
|
|
18857
|
-
m[0] = t[0] - 0xffed;
|
|
18858
|
-
for (i = 1; i < 15; i++) {
|
|
18859
|
-
m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
|
|
18860
|
-
m[i-1] &= 0xffff;
|
|
18861
|
-
}
|
|
18862
|
-
m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
|
|
18863
|
-
b = (m[15]>>16) & 1;
|
|
18864
|
-
m[14] &= 0xffff;
|
|
18865
|
-
sel25519(t, m, 1-b);
|
|
18866
|
-
}
|
|
18867
|
-
for (i = 0; i < 16; i++) {
|
|
18868
|
-
o[2*i] = t[i] & 0xff;
|
|
18869
|
-
o[2*i+1] = t[i]>>8;
|
|
18870
|
-
}
|
|
18871
|
-
}
|
|
18872
|
-
|
|
18873
|
-
function neq25519(a, b) {
|
|
18874
|
-
var c = new Uint8Array(32), d = new Uint8Array(32);
|
|
18875
|
-
pack25519(c, a);
|
|
18876
|
-
pack25519(d, b);
|
|
18877
|
-
return crypto_verify_32(c, 0, d, 0);
|
|
18878
|
-
}
|
|
18879
|
-
|
|
18880
|
-
function par25519(a) {
|
|
18881
|
-
var d = new Uint8Array(32);
|
|
18882
|
-
pack25519(d, a);
|
|
18883
|
-
return d[0] & 1;
|
|
18884
|
-
}
|
|
18885
|
-
|
|
18886
|
-
function unpack25519(o, n) {
|
|
18887
|
-
var i;
|
|
18888
|
-
for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
|
|
18889
|
-
o[15] &= 0x7fff;
|
|
18890
|
-
}
|
|
18891
|
-
|
|
18892
|
-
function A(o, a, b) {
|
|
18893
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
|
|
18894
|
-
}
|
|
18895
|
-
|
|
18896
|
-
function Z(o, a, b) {
|
|
18897
|
-
for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
|
|
18898
|
-
}
|
|
18899
|
-
|
|
18900
|
-
function M(o, a, b) {
|
|
18901
|
-
var v, c,
|
|
18902
|
-
t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
|
|
18903
|
-
t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
|
|
18904
|
-
t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
|
|
18905
|
-
t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
|
|
18906
|
-
b0 = b[0],
|
|
18907
|
-
b1 = b[1],
|
|
18908
|
-
b2 = b[2],
|
|
18909
|
-
b3 = b[3],
|
|
18910
|
-
b4 = b[4],
|
|
18911
|
-
b5 = b[5],
|
|
18912
|
-
b6 = b[6],
|
|
18913
|
-
b7 = b[7],
|
|
18914
|
-
b8 = b[8],
|
|
18915
|
-
b9 = b[9],
|
|
18916
|
-
b10 = b[10],
|
|
18917
|
-
b11 = b[11],
|
|
18918
|
-
b12 = b[12],
|
|
18919
|
-
b13 = b[13],
|
|
18920
|
-
b14 = b[14],
|
|
18921
|
-
b15 = b[15];
|
|
18922
|
-
|
|
18923
|
-
v = a[0];
|
|
18924
|
-
t0 += v * b0;
|
|
18925
|
-
t1 += v * b1;
|
|
18926
|
-
t2 += v * b2;
|
|
18927
|
-
t3 += v * b3;
|
|
18928
|
-
t4 += v * b4;
|
|
18929
|
-
t5 += v * b5;
|
|
18930
|
-
t6 += v * b6;
|
|
18931
|
-
t7 += v * b7;
|
|
18932
|
-
t8 += v * b8;
|
|
18933
|
-
t9 += v * b9;
|
|
18934
|
-
t10 += v * b10;
|
|
18935
|
-
t11 += v * b11;
|
|
18936
|
-
t12 += v * b12;
|
|
18937
|
-
t13 += v * b13;
|
|
18938
|
-
t14 += v * b14;
|
|
18939
|
-
t15 += v * b15;
|
|
18940
|
-
v = a[1];
|
|
18941
|
-
t1 += v * b0;
|
|
18942
|
-
t2 += v * b1;
|
|
18943
|
-
t3 += v * b2;
|
|
18944
|
-
t4 += v * b3;
|
|
18945
|
-
t5 += v * b4;
|
|
18946
|
-
t6 += v * b5;
|
|
18947
|
-
t7 += v * b6;
|
|
18948
|
-
t8 += v * b7;
|
|
18949
|
-
t9 += v * b8;
|
|
18950
|
-
t10 += v * b9;
|
|
18951
|
-
t11 += v * b10;
|
|
18952
|
-
t12 += v * b11;
|
|
18953
|
-
t13 += v * b12;
|
|
18954
|
-
t14 += v * b13;
|
|
18955
|
-
t15 += v * b14;
|
|
18956
|
-
t16 += v * b15;
|
|
18957
|
-
v = a[2];
|
|
18958
|
-
t2 += v * b0;
|
|
18959
|
-
t3 += v * b1;
|
|
18960
|
-
t4 += v * b2;
|
|
18961
|
-
t5 += v * b3;
|
|
18962
|
-
t6 += v * b4;
|
|
18963
|
-
t7 += v * b5;
|
|
18964
|
-
t8 += v * b6;
|
|
18965
|
-
t9 += v * b7;
|
|
18966
|
-
t10 += v * b8;
|
|
18967
|
-
t11 += v * b9;
|
|
18968
|
-
t12 += v * b10;
|
|
18969
|
-
t13 += v * b11;
|
|
18970
|
-
t14 += v * b12;
|
|
18971
|
-
t15 += v * b13;
|
|
18972
|
-
t16 += v * b14;
|
|
18973
|
-
t17 += v * b15;
|
|
18974
|
-
v = a[3];
|
|
18975
|
-
t3 += v * b0;
|
|
18976
|
-
t4 += v * b1;
|
|
18977
|
-
t5 += v * b2;
|
|
18978
|
-
t6 += v * b3;
|
|
18979
|
-
t7 += v * b4;
|
|
18980
|
-
t8 += v * b5;
|
|
18981
|
-
t9 += v * b6;
|
|
18982
|
-
t10 += v * b7;
|
|
18983
|
-
t11 += v * b8;
|
|
18984
|
-
t12 += v * b9;
|
|
18985
|
-
t13 += v * b10;
|
|
18986
|
-
t14 += v * b11;
|
|
18987
|
-
t15 += v * b12;
|
|
18988
|
-
t16 += v * b13;
|
|
18989
|
-
t17 += v * b14;
|
|
18990
|
-
t18 += v * b15;
|
|
18991
|
-
v = a[4];
|
|
18992
|
-
t4 += v * b0;
|
|
18993
|
-
t5 += v * b1;
|
|
18994
|
-
t6 += v * b2;
|
|
18995
|
-
t7 += v * b3;
|
|
18996
|
-
t8 += v * b4;
|
|
18997
|
-
t9 += v * b5;
|
|
18998
|
-
t10 += v * b6;
|
|
18999
|
-
t11 += v * b7;
|
|
19000
|
-
t12 += v * b8;
|
|
19001
|
-
t13 += v * b9;
|
|
19002
|
-
t14 += v * b10;
|
|
19003
|
-
t15 += v * b11;
|
|
19004
|
-
t16 += v * b12;
|
|
19005
|
-
t17 += v * b13;
|
|
19006
|
-
t18 += v * b14;
|
|
19007
|
-
t19 += v * b15;
|
|
19008
|
-
v = a[5];
|
|
19009
|
-
t5 += v * b0;
|
|
19010
|
-
t6 += v * b1;
|
|
19011
|
-
t7 += v * b2;
|
|
19012
|
-
t8 += v * b3;
|
|
19013
|
-
t9 += v * b4;
|
|
19014
|
-
t10 += v * b5;
|
|
19015
|
-
t11 += v * b6;
|
|
19016
|
-
t12 += v * b7;
|
|
19017
|
-
t13 += v * b8;
|
|
19018
|
-
t14 += v * b9;
|
|
19019
|
-
t15 += v * b10;
|
|
19020
|
-
t16 += v * b11;
|
|
19021
|
-
t17 += v * b12;
|
|
19022
|
-
t18 += v * b13;
|
|
19023
|
-
t19 += v * b14;
|
|
19024
|
-
t20 += v * b15;
|
|
19025
|
-
v = a[6];
|
|
19026
|
-
t6 += v * b0;
|
|
19027
|
-
t7 += v * b1;
|
|
19028
|
-
t8 += v * b2;
|
|
19029
|
-
t9 += v * b3;
|
|
19030
|
-
t10 += v * b4;
|
|
19031
|
-
t11 += v * b5;
|
|
19032
|
-
t12 += v * b6;
|
|
19033
|
-
t13 += v * b7;
|
|
19034
|
-
t14 += v * b8;
|
|
19035
|
-
t15 += v * b9;
|
|
19036
|
-
t16 += v * b10;
|
|
19037
|
-
t17 += v * b11;
|
|
19038
|
-
t18 += v * b12;
|
|
19039
|
-
t19 += v * b13;
|
|
19040
|
-
t20 += v * b14;
|
|
19041
|
-
t21 += v * b15;
|
|
19042
|
-
v = a[7];
|
|
19043
|
-
t7 += v * b0;
|
|
19044
|
-
t8 += v * b1;
|
|
19045
|
-
t9 += v * b2;
|
|
19046
|
-
t10 += v * b3;
|
|
19047
|
-
t11 += v * b4;
|
|
19048
|
-
t12 += v * b5;
|
|
19049
|
-
t13 += v * b6;
|
|
19050
|
-
t14 += v * b7;
|
|
19051
|
-
t15 += v * b8;
|
|
19052
|
-
t16 += v * b9;
|
|
19053
|
-
t17 += v * b10;
|
|
19054
|
-
t18 += v * b11;
|
|
19055
|
-
t19 += v * b12;
|
|
19056
|
-
t20 += v * b13;
|
|
19057
|
-
t21 += v * b14;
|
|
19058
|
-
t22 += v * b15;
|
|
19059
|
-
v = a[8];
|
|
19060
|
-
t8 += v * b0;
|
|
19061
|
-
t9 += v * b1;
|
|
19062
|
-
t10 += v * b2;
|
|
19063
|
-
t11 += v * b3;
|
|
19064
|
-
t12 += v * b4;
|
|
19065
|
-
t13 += v * b5;
|
|
19066
|
-
t14 += v * b6;
|
|
19067
|
-
t15 += v * b7;
|
|
19068
|
-
t16 += v * b8;
|
|
19069
|
-
t17 += v * b9;
|
|
19070
|
-
t18 += v * b10;
|
|
19071
|
-
t19 += v * b11;
|
|
19072
|
-
t20 += v * b12;
|
|
19073
|
-
t21 += v * b13;
|
|
19074
|
-
t22 += v * b14;
|
|
19075
|
-
t23 += v * b15;
|
|
19076
|
-
v = a[9];
|
|
19077
|
-
t9 += v * b0;
|
|
19078
|
-
t10 += v * b1;
|
|
19079
|
-
t11 += v * b2;
|
|
19080
|
-
t12 += v * b3;
|
|
19081
|
-
t13 += v * b4;
|
|
19082
|
-
t14 += v * b5;
|
|
19083
|
-
t15 += v * b6;
|
|
19084
|
-
t16 += v * b7;
|
|
19085
|
-
t17 += v * b8;
|
|
19086
|
-
t18 += v * b9;
|
|
19087
|
-
t19 += v * b10;
|
|
19088
|
-
t20 += v * b11;
|
|
19089
|
-
t21 += v * b12;
|
|
19090
|
-
t22 += v * b13;
|
|
19091
|
-
t23 += v * b14;
|
|
19092
|
-
t24 += v * b15;
|
|
19093
|
-
v = a[10];
|
|
19094
|
-
t10 += v * b0;
|
|
19095
|
-
t11 += v * b1;
|
|
19096
|
-
t12 += v * b2;
|
|
19097
|
-
t13 += v * b3;
|
|
19098
|
-
t14 += v * b4;
|
|
19099
|
-
t15 += v * b5;
|
|
19100
|
-
t16 += v * b6;
|
|
19101
|
-
t17 += v * b7;
|
|
19102
|
-
t18 += v * b8;
|
|
19103
|
-
t19 += v * b9;
|
|
19104
|
-
t20 += v * b10;
|
|
19105
|
-
t21 += v * b11;
|
|
19106
|
-
t22 += v * b12;
|
|
19107
|
-
t23 += v * b13;
|
|
19108
|
-
t24 += v * b14;
|
|
19109
|
-
t25 += v * b15;
|
|
19110
|
-
v = a[11];
|
|
19111
|
-
t11 += v * b0;
|
|
19112
|
-
t12 += v * b1;
|
|
19113
|
-
t13 += v * b2;
|
|
19114
|
-
t14 += v * b3;
|
|
19115
|
-
t15 += v * b4;
|
|
19116
|
-
t16 += v * b5;
|
|
19117
|
-
t17 += v * b6;
|
|
19118
|
-
t18 += v * b7;
|
|
19119
|
-
t19 += v * b8;
|
|
19120
|
-
t20 += v * b9;
|
|
19121
|
-
t21 += v * b10;
|
|
19122
|
-
t22 += v * b11;
|
|
19123
|
-
t23 += v * b12;
|
|
19124
|
-
t24 += v * b13;
|
|
19125
|
-
t25 += v * b14;
|
|
19126
|
-
t26 += v * b15;
|
|
19127
|
-
v = a[12];
|
|
19128
|
-
t12 += v * b0;
|
|
19129
|
-
t13 += v * b1;
|
|
19130
|
-
t14 += v * b2;
|
|
19131
|
-
t15 += v * b3;
|
|
19132
|
-
t16 += v * b4;
|
|
19133
|
-
t17 += v * b5;
|
|
19134
|
-
t18 += v * b6;
|
|
19135
|
-
t19 += v * b7;
|
|
19136
|
-
t20 += v * b8;
|
|
19137
|
-
t21 += v * b9;
|
|
19138
|
-
t22 += v * b10;
|
|
19139
|
-
t23 += v * b11;
|
|
19140
|
-
t24 += v * b12;
|
|
19141
|
-
t25 += v * b13;
|
|
19142
|
-
t26 += v * b14;
|
|
19143
|
-
t27 += v * b15;
|
|
19144
|
-
v = a[13];
|
|
19145
|
-
t13 += v * b0;
|
|
19146
|
-
t14 += v * b1;
|
|
19147
|
-
t15 += v * b2;
|
|
19148
|
-
t16 += v * b3;
|
|
19149
|
-
t17 += v * b4;
|
|
19150
|
-
t18 += v * b5;
|
|
19151
|
-
t19 += v * b6;
|
|
19152
|
-
t20 += v * b7;
|
|
19153
|
-
t21 += v * b8;
|
|
19154
|
-
t22 += v * b9;
|
|
19155
|
-
t23 += v * b10;
|
|
19156
|
-
t24 += v * b11;
|
|
19157
|
-
t25 += v * b12;
|
|
19158
|
-
t26 += v * b13;
|
|
19159
|
-
t27 += v * b14;
|
|
19160
|
-
t28 += v * b15;
|
|
19161
|
-
v = a[14];
|
|
19162
|
-
t14 += v * b0;
|
|
19163
|
-
t15 += v * b1;
|
|
19164
|
-
t16 += v * b2;
|
|
19165
|
-
t17 += v * b3;
|
|
19166
|
-
t18 += v * b4;
|
|
19167
|
-
t19 += v * b5;
|
|
19168
|
-
t20 += v * b6;
|
|
19169
|
-
t21 += v * b7;
|
|
19170
|
-
t22 += v * b8;
|
|
19171
|
-
t23 += v * b9;
|
|
19172
|
-
t24 += v * b10;
|
|
19173
|
-
t25 += v * b11;
|
|
19174
|
-
t26 += v * b12;
|
|
19175
|
-
t27 += v * b13;
|
|
19176
|
-
t28 += v * b14;
|
|
19177
|
-
t29 += v * b15;
|
|
19178
|
-
v = a[15];
|
|
19179
|
-
t15 += v * b0;
|
|
19180
|
-
t16 += v * b1;
|
|
19181
|
-
t17 += v * b2;
|
|
19182
|
-
t18 += v * b3;
|
|
19183
|
-
t19 += v * b4;
|
|
19184
|
-
t20 += v * b5;
|
|
19185
|
-
t21 += v * b6;
|
|
19186
|
-
t22 += v * b7;
|
|
19187
|
-
t23 += v * b8;
|
|
19188
|
-
t24 += v * b9;
|
|
19189
|
-
t25 += v * b10;
|
|
19190
|
-
t26 += v * b11;
|
|
19191
|
-
t27 += v * b12;
|
|
19192
|
-
t28 += v * b13;
|
|
19193
|
-
t29 += v * b14;
|
|
19194
|
-
t30 += v * b15;
|
|
19195
|
-
|
|
19196
|
-
t0 += 38 * t16;
|
|
19197
|
-
t1 += 38 * t17;
|
|
19198
|
-
t2 += 38 * t18;
|
|
19199
|
-
t3 += 38 * t19;
|
|
19200
|
-
t4 += 38 * t20;
|
|
19201
|
-
t5 += 38 * t21;
|
|
19202
|
-
t6 += 38 * t22;
|
|
19203
|
-
t7 += 38 * t23;
|
|
19204
|
-
t8 += 38 * t24;
|
|
19205
|
-
t9 += 38 * t25;
|
|
19206
|
-
t10 += 38 * t26;
|
|
19207
|
-
t11 += 38 * t27;
|
|
19208
|
-
t12 += 38 * t28;
|
|
19209
|
-
t13 += 38 * t29;
|
|
19210
|
-
t14 += 38 * t30;
|
|
19211
|
-
// t15 left as is
|
|
19212
|
-
|
|
19213
|
-
// first car
|
|
19214
|
-
c = 1;
|
|
19215
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
19216
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
19217
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
19218
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
19219
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
19220
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
19221
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
19222
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
19223
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
19224
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
19225
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
19226
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
19227
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
19228
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
19229
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
19230
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
19231
|
-
t0 += c-1 + 37 * (c-1);
|
|
19232
|
-
|
|
19233
|
-
// second car
|
|
19234
|
-
c = 1;
|
|
19235
|
-
v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
|
|
19236
|
-
v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
|
|
19237
|
-
v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
|
|
19238
|
-
v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
|
|
19239
|
-
v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
|
|
19240
|
-
v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
|
|
19241
|
-
v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
|
|
19242
|
-
v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
|
|
19243
|
-
v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
|
|
19244
|
-
v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
|
|
19245
|
-
v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
|
|
19246
|
-
v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
|
|
19247
|
-
v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
|
|
19248
|
-
v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
|
|
19249
|
-
v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
|
|
19250
|
-
v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
|
|
19251
|
-
t0 += c-1 + 37 * (c-1);
|
|
19252
|
-
|
|
19253
|
-
o[ 0] = t0;
|
|
19254
|
-
o[ 1] = t1;
|
|
19255
|
-
o[ 2] = t2;
|
|
19256
|
-
o[ 3] = t3;
|
|
19257
|
-
o[ 4] = t4;
|
|
19258
|
-
o[ 5] = t5;
|
|
19259
|
-
o[ 6] = t6;
|
|
19260
|
-
o[ 7] = t7;
|
|
19261
|
-
o[ 8] = t8;
|
|
19262
|
-
o[ 9] = t9;
|
|
19263
|
-
o[10] = t10;
|
|
19264
|
-
o[11] = t11;
|
|
19265
|
-
o[12] = t12;
|
|
19266
|
-
o[13] = t13;
|
|
19267
|
-
o[14] = t14;
|
|
19268
|
-
o[15] = t15;
|
|
19269
|
-
}
|
|
19270
|
-
|
|
19271
|
-
function S(o, a) {
|
|
19272
|
-
M(o, a, a);
|
|
19273
|
-
}
|
|
19274
|
-
|
|
19275
|
-
function inv25519(o, i) {
|
|
19276
|
-
var c = gf();
|
|
19277
|
-
var a;
|
|
19278
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
19279
|
-
for (a = 253; a >= 0; a--) {
|
|
19280
|
-
S(c, c);
|
|
19281
|
-
if(a !== 2 && a !== 4) M(c, c, i);
|
|
19282
|
-
}
|
|
19283
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
19284
|
-
}
|
|
19285
|
-
|
|
19286
|
-
function pow2523(o, i) {
|
|
19287
|
-
var c = gf();
|
|
19288
|
-
var a;
|
|
19289
|
-
for (a = 0; a < 16; a++) c[a] = i[a];
|
|
19290
|
-
for (a = 250; a >= 0; a--) {
|
|
19291
|
-
S(c, c);
|
|
19292
|
-
if(a !== 1) M(c, c, i);
|
|
19293
|
-
}
|
|
19294
|
-
for (a = 0; a < 16; a++) o[a] = c[a];
|
|
19295
|
-
}
|
|
19296
|
-
|
|
19297
|
-
function crypto_scalarmult(q, n, p) {
|
|
19298
|
-
var z = new Uint8Array(32);
|
|
19299
|
-
var x = new Float64Array(80), r, i;
|
|
19300
|
-
var a = gf(), b = gf(), c = gf(),
|
|
19301
|
-
d = gf(), e = gf(), f = gf();
|
|
19302
|
-
for (i = 0; i < 31; i++) z[i] = n[i];
|
|
19303
|
-
z[31]=(n[31]&127)|64;
|
|
19304
|
-
z[0]&=248;
|
|
19305
|
-
unpack25519(x,p);
|
|
19306
|
-
for (i = 0; i < 16; i++) {
|
|
19307
|
-
b[i]=x[i];
|
|
19308
|
-
d[i]=a[i]=c[i]=0;
|
|
19309
|
-
}
|
|
19310
|
-
a[0]=d[0]=1;
|
|
19311
|
-
for (i=254; i>=0; --i) {
|
|
19312
|
-
r=(z[i>>>3]>>>(i&7))&1;
|
|
19313
|
-
sel25519(a,b,r);
|
|
19314
|
-
sel25519(c,d,r);
|
|
19315
|
-
A(e,a,c);
|
|
19316
|
-
Z(a,a,c);
|
|
19317
|
-
A(c,b,d);
|
|
19318
|
-
Z(b,b,d);
|
|
19319
|
-
S(d,e);
|
|
19320
|
-
S(f,a);
|
|
19321
|
-
M(a,c,a);
|
|
19322
|
-
M(c,b,e);
|
|
19323
|
-
A(e,a,c);
|
|
19324
|
-
Z(a,a,c);
|
|
19325
|
-
S(b,a);
|
|
19326
|
-
Z(c,d,f);
|
|
19327
|
-
M(a,c,_121665);
|
|
19328
|
-
A(a,a,d);
|
|
19329
|
-
M(c,c,a);
|
|
19330
|
-
M(a,d,f);
|
|
19331
|
-
M(d,b,x);
|
|
19332
|
-
S(b,e);
|
|
19333
|
-
sel25519(a,b,r);
|
|
19334
|
-
sel25519(c,d,r);
|
|
19335
|
-
}
|
|
19336
|
-
for (i = 0; i < 16; i++) {
|
|
19337
|
-
x[i+16]=a[i];
|
|
19338
|
-
x[i+32]=c[i];
|
|
19339
|
-
x[i+48]=b[i];
|
|
19340
|
-
x[i+64]=d[i];
|
|
19341
|
-
}
|
|
19342
|
-
var x32 = x.subarray(32);
|
|
19343
|
-
var x16 = x.subarray(16);
|
|
19344
|
-
inv25519(x32,x32);
|
|
19345
|
-
M(x16,x16,x32);
|
|
19346
|
-
pack25519(q,x16);
|
|
19347
|
-
return 0;
|
|
19348
|
-
}
|
|
19349
|
-
|
|
19350
|
-
function crypto_scalarmult_base(q, n) {
|
|
19351
|
-
return crypto_scalarmult(q, n, _9);
|
|
19352
|
-
}
|
|
19353
|
-
|
|
19354
|
-
function crypto_box_keypair(y, x) {
|
|
19355
|
-
randombytes(x, 32);
|
|
19356
|
-
return crypto_scalarmult_base(y, x);
|
|
19357
|
-
}
|
|
19358
|
-
|
|
19359
|
-
function crypto_box_beforenm(k, y, x) {
|
|
19360
|
-
var s = new Uint8Array(32);
|
|
19361
|
-
crypto_scalarmult(s, x, y);
|
|
19362
|
-
return crypto_core_hsalsa20(k, _0, s, sigma);
|
|
19363
|
-
}
|
|
19364
|
-
|
|
19365
|
-
var crypto_box_afternm = crypto_secretbox;
|
|
19366
|
-
var crypto_box_open_afternm = crypto_secretbox_open;
|
|
19367
|
-
|
|
19368
|
-
function crypto_box(c, m, d, n, y, x) {
|
|
19369
|
-
var k = new Uint8Array(32);
|
|
19370
|
-
crypto_box_beforenm(k, y, x);
|
|
19371
|
-
return crypto_box_afternm(c, m, d, n, k);
|
|
19372
|
-
}
|
|
19373
|
-
|
|
19374
|
-
function crypto_box_open(m, c, d, n, y, x) {
|
|
19375
|
-
var k = new Uint8Array(32);
|
|
19376
|
-
crypto_box_beforenm(k, y, x);
|
|
19377
|
-
return crypto_box_open_afternm(m, c, d, n, k);
|
|
19378
|
-
}
|
|
19379
|
-
|
|
19380
|
-
var K = [
|
|
19381
|
-
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
|
|
19382
|
-
0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
|
|
19383
|
-
0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
|
19384
|
-
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
|
|
19385
|
-
0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
|
|
19386
|
-
0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
|
19387
|
-
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
|
|
19388
|
-
0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
|
|
19389
|
-
0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
|
19390
|
-
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
|
|
19391
|
-
0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
|
|
19392
|
-
0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
|
19393
|
-
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
|
|
19394
|
-
0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
|
|
19395
|
-
0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
|
19396
|
-
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
|
|
19397
|
-
0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
|
|
19398
|
-
0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
|
19399
|
-
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
|
|
19400
|
-
0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
|
|
19401
|
-
0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
|
19402
|
-
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
|
|
19403
|
-
0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
|
|
19404
|
-
0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
|
19405
|
-
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
|
|
19406
|
-
0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
|
|
19407
|
-
0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
|
19408
|
-
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
|
|
19409
|
-
0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
|
|
19410
|
-
0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
|
19411
|
-
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
|
|
19412
|
-
0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
|
|
19413
|
-
0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
|
19414
|
-
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
|
|
19415
|
-
0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
|
|
19416
|
-
0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
|
19417
|
-
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
|
|
19418
|
-
0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
|
|
19419
|
-
0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
|
19420
|
-
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
|
19421
|
-
];
|
|
19422
|
-
|
|
19423
|
-
function crypto_hashblocks_hl(hh, hl, m, n) {
|
|
19424
|
-
var wh = new Int32Array(16), wl = new Int32Array(16),
|
|
19425
|
-
bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
|
|
19426
|
-
bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
|
|
19427
|
-
th, tl, i, j, h, l, a, b, c, d;
|
|
19428
|
-
|
|
19429
|
-
var ah0 = hh[0],
|
|
19430
|
-
ah1 = hh[1],
|
|
19431
|
-
ah2 = hh[2],
|
|
19432
|
-
ah3 = hh[3],
|
|
19433
|
-
ah4 = hh[4],
|
|
19434
|
-
ah5 = hh[5],
|
|
19435
|
-
ah6 = hh[6],
|
|
19436
|
-
ah7 = hh[7],
|
|
19437
|
-
|
|
19438
|
-
al0 = hl[0],
|
|
19439
|
-
al1 = hl[1],
|
|
19440
|
-
al2 = hl[2],
|
|
19441
|
-
al3 = hl[3],
|
|
19442
|
-
al4 = hl[4],
|
|
19443
|
-
al5 = hl[5],
|
|
19444
|
-
al6 = hl[6],
|
|
19445
|
-
al7 = hl[7];
|
|
19446
|
-
|
|
19447
|
-
var pos = 0;
|
|
19448
|
-
while (n >= 128) {
|
|
19449
|
-
for (i = 0; i < 16; i++) {
|
|
19450
|
-
j = 8 * i + pos;
|
|
19451
|
-
wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
|
|
19452
|
-
wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
|
|
19453
|
-
}
|
|
19454
|
-
for (i = 0; i < 80; i++) {
|
|
19455
|
-
bh0 = ah0;
|
|
19456
|
-
bh1 = ah1;
|
|
19457
|
-
bh2 = ah2;
|
|
19458
|
-
bh3 = ah3;
|
|
19459
|
-
bh4 = ah4;
|
|
19460
|
-
bh5 = ah5;
|
|
19461
|
-
bh6 = ah6;
|
|
19462
|
-
bh7 = ah7;
|
|
19463
|
-
|
|
19464
|
-
bl0 = al0;
|
|
19465
|
-
bl1 = al1;
|
|
19466
|
-
bl2 = al2;
|
|
19467
|
-
bl3 = al3;
|
|
19468
|
-
bl4 = al4;
|
|
19469
|
-
bl5 = al5;
|
|
19470
|
-
bl6 = al6;
|
|
19471
|
-
bl7 = al7;
|
|
19472
|
-
|
|
19473
|
-
// add
|
|
19474
|
-
h = ah7;
|
|
19475
|
-
l = al7;
|
|
19476
|
-
|
|
19477
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19478
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19479
|
-
|
|
19480
|
-
// Sigma1
|
|
19481
|
-
h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
|
|
19482
|
-
l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
|
|
19483
|
-
|
|
19484
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19485
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19486
|
-
|
|
19487
|
-
// Ch
|
|
19488
|
-
h = (ah4 & ah5) ^ (~ah4 & ah6);
|
|
19489
|
-
l = (al4 & al5) ^ (~al4 & al6);
|
|
19490
|
-
|
|
19491
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19492
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19493
|
-
|
|
19494
|
-
// K
|
|
19495
|
-
h = K[i*2];
|
|
19496
|
-
l = K[i*2+1];
|
|
19497
|
-
|
|
19498
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19499
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19500
|
-
|
|
19501
|
-
// w
|
|
19502
|
-
h = wh[i%16];
|
|
19503
|
-
l = wl[i%16];
|
|
19504
|
-
|
|
19505
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19506
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19507
|
-
|
|
19508
|
-
b += a >>> 16;
|
|
19509
|
-
c += b >>> 16;
|
|
19510
|
-
d += c >>> 16;
|
|
19511
|
-
|
|
19512
|
-
th = c & 0xffff | d << 16;
|
|
19513
|
-
tl = a & 0xffff | b << 16;
|
|
19514
|
-
|
|
19515
|
-
// add
|
|
19516
|
-
h = th;
|
|
19517
|
-
l = tl;
|
|
19518
|
-
|
|
19519
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19520
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19521
|
-
|
|
19522
|
-
// Sigma0
|
|
19523
|
-
h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
|
|
19524
|
-
l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
|
|
19525
|
-
|
|
19526
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19527
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19528
|
-
|
|
19529
|
-
// Maj
|
|
19530
|
-
h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
|
|
19531
|
-
l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
|
|
19532
|
-
|
|
19533
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19534
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19535
|
-
|
|
19536
|
-
b += a >>> 16;
|
|
19537
|
-
c += b >>> 16;
|
|
19538
|
-
d += c >>> 16;
|
|
19539
|
-
|
|
19540
|
-
bh7 = (c & 0xffff) | (d << 16);
|
|
19541
|
-
bl7 = (a & 0xffff) | (b << 16);
|
|
19542
|
-
|
|
19543
|
-
// add
|
|
19544
|
-
h = bh3;
|
|
19545
|
-
l = bl3;
|
|
19546
|
-
|
|
19547
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19548
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19549
|
-
|
|
19550
|
-
h = th;
|
|
19551
|
-
l = tl;
|
|
19552
|
-
|
|
19553
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19554
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19555
|
-
|
|
19556
|
-
b += a >>> 16;
|
|
19557
|
-
c += b >>> 16;
|
|
19558
|
-
d += c >>> 16;
|
|
19559
|
-
|
|
19560
|
-
bh3 = (c & 0xffff) | (d << 16);
|
|
19561
|
-
bl3 = (a & 0xffff) | (b << 16);
|
|
19562
|
-
|
|
19563
|
-
ah1 = bh0;
|
|
19564
|
-
ah2 = bh1;
|
|
19565
|
-
ah3 = bh2;
|
|
19566
|
-
ah4 = bh3;
|
|
19567
|
-
ah5 = bh4;
|
|
19568
|
-
ah6 = bh5;
|
|
19569
|
-
ah7 = bh6;
|
|
19570
|
-
ah0 = bh7;
|
|
19571
|
-
|
|
19572
|
-
al1 = bl0;
|
|
19573
|
-
al2 = bl1;
|
|
19574
|
-
al3 = bl2;
|
|
19575
|
-
al4 = bl3;
|
|
19576
|
-
al5 = bl4;
|
|
19577
|
-
al6 = bl5;
|
|
19578
|
-
al7 = bl6;
|
|
19579
|
-
al0 = bl7;
|
|
19580
|
-
|
|
19581
|
-
if (i%16 === 15) {
|
|
19582
|
-
for (j = 0; j < 16; j++) {
|
|
19583
|
-
// add
|
|
19584
|
-
h = wh[j];
|
|
19585
|
-
l = wl[j];
|
|
19586
|
-
|
|
19587
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19588
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19589
|
-
|
|
19590
|
-
h = wh[(j+9)%16];
|
|
19591
|
-
l = wl[(j+9)%16];
|
|
19592
|
-
|
|
19593
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19594
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19595
|
-
|
|
19596
|
-
// sigma0
|
|
19597
|
-
th = wh[(j+1)%16];
|
|
19598
|
-
tl = wl[(j+1)%16];
|
|
19599
|
-
h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
|
|
19600
|
-
l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
|
|
19601
|
-
|
|
19602
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19603
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19604
|
-
|
|
19605
|
-
// sigma1
|
|
19606
|
-
th = wh[(j+14)%16];
|
|
19607
|
-
tl = wl[(j+14)%16];
|
|
19608
|
-
h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
|
|
19609
|
-
l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
|
|
19610
|
-
|
|
19611
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19612
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19613
|
-
|
|
19614
|
-
b += a >>> 16;
|
|
19615
|
-
c += b >>> 16;
|
|
19616
|
-
d += c >>> 16;
|
|
19617
|
-
|
|
19618
|
-
wh[j] = (c & 0xffff) | (d << 16);
|
|
19619
|
-
wl[j] = (a & 0xffff) | (b << 16);
|
|
19620
|
-
}
|
|
19621
|
-
}
|
|
19622
|
-
}
|
|
19623
|
-
|
|
19624
|
-
// add
|
|
19625
|
-
h = ah0;
|
|
19626
|
-
l = al0;
|
|
19627
|
-
|
|
19628
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19629
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19630
|
-
|
|
19631
|
-
h = hh[0];
|
|
19632
|
-
l = hl[0];
|
|
19633
|
-
|
|
19634
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19635
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19636
|
-
|
|
19637
|
-
b += a >>> 16;
|
|
19638
|
-
c += b >>> 16;
|
|
19639
|
-
d += c >>> 16;
|
|
19640
|
-
|
|
19641
|
-
hh[0] = ah0 = (c & 0xffff) | (d << 16);
|
|
19642
|
-
hl[0] = al0 = (a & 0xffff) | (b << 16);
|
|
19643
|
-
|
|
19644
|
-
h = ah1;
|
|
19645
|
-
l = al1;
|
|
19646
|
-
|
|
19647
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19648
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19649
|
-
|
|
19650
|
-
h = hh[1];
|
|
19651
|
-
l = hl[1];
|
|
19652
|
-
|
|
19653
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19654
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19655
|
-
|
|
19656
|
-
b += a >>> 16;
|
|
19657
|
-
c += b >>> 16;
|
|
19658
|
-
d += c >>> 16;
|
|
19659
|
-
|
|
19660
|
-
hh[1] = ah1 = (c & 0xffff) | (d << 16);
|
|
19661
|
-
hl[1] = al1 = (a & 0xffff) | (b << 16);
|
|
19662
|
-
|
|
19663
|
-
h = ah2;
|
|
19664
|
-
l = al2;
|
|
19665
|
-
|
|
19666
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19667
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19668
|
-
|
|
19669
|
-
h = hh[2];
|
|
19670
|
-
l = hl[2];
|
|
19671
|
-
|
|
19672
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19673
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19674
|
-
|
|
19675
|
-
b += a >>> 16;
|
|
19676
|
-
c += b >>> 16;
|
|
19677
|
-
d += c >>> 16;
|
|
19678
|
-
|
|
19679
|
-
hh[2] = ah2 = (c & 0xffff) | (d << 16);
|
|
19680
|
-
hl[2] = al2 = (a & 0xffff) | (b << 16);
|
|
19681
|
-
|
|
19682
|
-
h = ah3;
|
|
19683
|
-
l = al3;
|
|
19684
|
-
|
|
19685
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19686
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19687
|
-
|
|
19688
|
-
h = hh[3];
|
|
19689
|
-
l = hl[3];
|
|
19690
|
-
|
|
19691
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19692
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19693
|
-
|
|
19694
|
-
b += a >>> 16;
|
|
19695
|
-
c += b >>> 16;
|
|
19696
|
-
d += c >>> 16;
|
|
19697
|
-
|
|
19698
|
-
hh[3] = ah3 = (c & 0xffff) | (d << 16);
|
|
19699
|
-
hl[3] = al3 = (a & 0xffff) | (b << 16);
|
|
19700
|
-
|
|
19701
|
-
h = ah4;
|
|
19702
|
-
l = al4;
|
|
19703
|
-
|
|
19704
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19705
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19706
|
-
|
|
19707
|
-
h = hh[4];
|
|
19708
|
-
l = hl[4];
|
|
19709
|
-
|
|
19710
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19711
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19712
|
-
|
|
19713
|
-
b += a >>> 16;
|
|
19714
|
-
c += b >>> 16;
|
|
19715
|
-
d += c >>> 16;
|
|
19716
|
-
|
|
19717
|
-
hh[4] = ah4 = (c & 0xffff) | (d << 16);
|
|
19718
|
-
hl[4] = al4 = (a & 0xffff) | (b << 16);
|
|
19719
|
-
|
|
19720
|
-
h = ah5;
|
|
19721
|
-
l = al5;
|
|
19722
|
-
|
|
19723
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19724
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19725
|
-
|
|
19726
|
-
h = hh[5];
|
|
19727
|
-
l = hl[5];
|
|
19728
|
-
|
|
19729
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19730
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19731
|
-
|
|
19732
|
-
b += a >>> 16;
|
|
19733
|
-
c += b >>> 16;
|
|
19734
|
-
d += c >>> 16;
|
|
19735
|
-
|
|
19736
|
-
hh[5] = ah5 = (c & 0xffff) | (d << 16);
|
|
19737
|
-
hl[5] = al5 = (a & 0xffff) | (b << 16);
|
|
19738
|
-
|
|
19739
|
-
h = ah6;
|
|
19740
|
-
l = al6;
|
|
19741
|
-
|
|
19742
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19743
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19744
|
-
|
|
19745
|
-
h = hh[6];
|
|
19746
|
-
l = hl[6];
|
|
19747
|
-
|
|
19748
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19749
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19750
|
-
|
|
19751
|
-
b += a >>> 16;
|
|
19752
|
-
c += b >>> 16;
|
|
19753
|
-
d += c >>> 16;
|
|
19754
|
-
|
|
19755
|
-
hh[6] = ah6 = (c & 0xffff) | (d << 16);
|
|
19756
|
-
hl[6] = al6 = (a & 0xffff) | (b << 16);
|
|
19757
|
-
|
|
19758
|
-
h = ah7;
|
|
19759
|
-
l = al7;
|
|
19760
|
-
|
|
19761
|
-
a = l & 0xffff; b = l >>> 16;
|
|
19762
|
-
c = h & 0xffff; d = h >>> 16;
|
|
19763
|
-
|
|
19764
|
-
h = hh[7];
|
|
19765
|
-
l = hl[7];
|
|
19766
|
-
|
|
19767
|
-
a += l & 0xffff; b += l >>> 16;
|
|
19768
|
-
c += h & 0xffff; d += h >>> 16;
|
|
19769
|
-
|
|
19770
|
-
b += a >>> 16;
|
|
19771
|
-
c += b >>> 16;
|
|
19772
|
-
d += c >>> 16;
|
|
19773
|
-
|
|
19774
|
-
hh[7] = ah7 = (c & 0xffff) | (d << 16);
|
|
19775
|
-
hl[7] = al7 = (a & 0xffff) | (b << 16);
|
|
19776
|
-
|
|
19777
|
-
pos += 128;
|
|
19778
|
-
n -= 128;
|
|
19779
|
-
}
|
|
19780
|
-
|
|
19781
|
-
return n;
|
|
19782
|
-
}
|
|
19783
|
-
|
|
19784
|
-
function crypto_hash(out, m, n) {
|
|
19785
|
-
var hh = new Int32Array(8),
|
|
19786
|
-
hl = new Int32Array(8),
|
|
19787
|
-
x = new Uint8Array(256),
|
|
19788
|
-
i, b = n;
|
|
19789
|
-
|
|
19790
|
-
hh[0] = 0x6a09e667;
|
|
19791
|
-
hh[1] = 0xbb67ae85;
|
|
19792
|
-
hh[2] = 0x3c6ef372;
|
|
19793
|
-
hh[3] = 0xa54ff53a;
|
|
19794
|
-
hh[4] = 0x510e527f;
|
|
19795
|
-
hh[5] = 0x9b05688c;
|
|
19796
|
-
hh[6] = 0x1f83d9ab;
|
|
19797
|
-
hh[7] = 0x5be0cd19;
|
|
19798
|
-
|
|
19799
|
-
hl[0] = 0xf3bcc908;
|
|
19800
|
-
hl[1] = 0x84caa73b;
|
|
19801
|
-
hl[2] = 0xfe94f82b;
|
|
19802
|
-
hl[3] = 0x5f1d36f1;
|
|
19803
|
-
hl[4] = 0xade682d1;
|
|
19804
|
-
hl[5] = 0x2b3e6c1f;
|
|
19805
|
-
hl[6] = 0xfb41bd6b;
|
|
19806
|
-
hl[7] = 0x137e2179;
|
|
19807
|
-
|
|
19808
|
-
crypto_hashblocks_hl(hh, hl, m, n);
|
|
19809
|
-
n %= 128;
|
|
19810
|
-
|
|
19811
|
-
for (i = 0; i < n; i++) x[i] = m[b-n+i];
|
|
19812
|
-
x[n] = 128;
|
|
19813
|
-
|
|
19814
|
-
n = 256-128*(n<112?1:0);
|
|
19815
|
-
x[n-9] = 0;
|
|
19816
|
-
ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
|
|
19817
|
-
crypto_hashblocks_hl(hh, hl, x, n);
|
|
19818
|
-
|
|
19819
|
-
for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
|
|
19820
|
-
|
|
19821
|
-
return 0;
|
|
19822
|
-
}
|
|
19823
|
-
|
|
19824
|
-
function add(p, q) {
|
|
19825
|
-
var a = gf(), b = gf(), c = gf(),
|
|
19826
|
-
d = gf(), e = gf(), f = gf(),
|
|
19827
|
-
g = gf(), h = gf(), t = gf();
|
|
19828
|
-
|
|
19829
|
-
Z(a, p[1], p[0]);
|
|
19830
|
-
Z(t, q[1], q[0]);
|
|
19831
|
-
M(a, a, t);
|
|
19832
|
-
A(b, p[0], p[1]);
|
|
19833
|
-
A(t, q[0], q[1]);
|
|
19834
|
-
M(b, b, t);
|
|
19835
|
-
M(c, p[3], q[3]);
|
|
19836
|
-
M(c, c, D2);
|
|
19837
|
-
M(d, p[2], q[2]);
|
|
19838
|
-
A(d, d, d);
|
|
19839
|
-
Z(e, b, a);
|
|
19840
|
-
Z(f, d, c);
|
|
19841
|
-
A(g, d, c);
|
|
19842
|
-
A(h, b, a);
|
|
19843
|
-
|
|
19844
|
-
M(p[0], e, f);
|
|
19845
|
-
M(p[1], h, g);
|
|
19846
|
-
M(p[2], g, f);
|
|
19847
|
-
M(p[3], e, h);
|
|
19848
|
-
}
|
|
19849
|
-
|
|
19850
|
-
function cswap(p, q, b) {
|
|
19851
|
-
var i;
|
|
19852
|
-
for (i = 0; i < 4; i++) {
|
|
19853
|
-
sel25519(p[i], q[i], b);
|
|
19854
|
-
}
|
|
19855
|
-
}
|
|
19856
|
-
|
|
19857
|
-
function pack(r, p) {
|
|
19858
|
-
var tx = gf(), ty = gf(), zi = gf();
|
|
19859
|
-
inv25519(zi, p[2]);
|
|
19860
|
-
M(tx, p[0], zi);
|
|
19861
|
-
M(ty, p[1], zi);
|
|
19862
|
-
pack25519(r, ty);
|
|
19863
|
-
r[31] ^= par25519(tx) << 7;
|
|
19864
|
-
}
|
|
19865
|
-
|
|
19866
|
-
function scalarmult(p, q, s) {
|
|
19867
|
-
var b, i;
|
|
19868
|
-
set25519(p[0], gf0);
|
|
19869
|
-
set25519(p[1], gf1);
|
|
19870
|
-
set25519(p[2], gf1);
|
|
19871
|
-
set25519(p[3], gf0);
|
|
19872
|
-
for (i = 255; i >= 0; --i) {
|
|
19873
|
-
b = (s[(i/8)|0] >> (i&7)) & 1;
|
|
19874
|
-
cswap(p, q, b);
|
|
19875
|
-
add(q, p);
|
|
19876
|
-
add(p, p);
|
|
19877
|
-
cswap(p, q, b);
|
|
19878
|
-
}
|
|
19879
|
-
}
|
|
19880
|
-
|
|
19881
|
-
function scalarbase(p, s) {
|
|
19882
|
-
var q = [gf(), gf(), gf(), gf()];
|
|
19883
|
-
set25519(q[0], X);
|
|
19884
|
-
set25519(q[1], Y);
|
|
19885
|
-
set25519(q[2], gf1);
|
|
19886
|
-
M(q[3], X, Y);
|
|
19887
|
-
scalarmult(p, q, s);
|
|
19888
|
-
}
|
|
19889
|
-
|
|
19890
|
-
function crypto_sign_keypair(pk, sk, seeded) {
|
|
19891
|
-
var d = new Uint8Array(64);
|
|
19892
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
19893
|
-
var i;
|
|
19894
|
-
|
|
19895
|
-
if (!seeded) randombytes(sk, 32);
|
|
19896
|
-
crypto_hash(d, sk, 32);
|
|
19897
|
-
d[0] &= 248;
|
|
19898
|
-
d[31] &= 127;
|
|
19899
|
-
d[31] |= 64;
|
|
19900
|
-
|
|
19901
|
-
scalarbase(p, d);
|
|
19902
|
-
pack(pk, p);
|
|
19903
|
-
|
|
19904
|
-
for (i = 0; i < 32; i++) sk[i+32] = pk[i];
|
|
19905
|
-
return 0;
|
|
19906
|
-
}
|
|
19907
|
-
|
|
19908
|
-
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]);
|
|
19909
|
-
|
|
19910
|
-
function modL(r, x) {
|
|
19911
|
-
var carry, i, j, k;
|
|
19912
|
-
for (i = 63; i >= 32; --i) {
|
|
19913
|
-
carry = 0;
|
|
19914
|
-
for (j = i - 32, k = i - 12; j < k; ++j) {
|
|
19915
|
-
x[j] += carry - 16 * x[i] * L[j - (i - 32)];
|
|
19916
|
-
carry = Math.floor((x[j] + 128) / 256);
|
|
19917
|
-
x[j] -= carry * 256;
|
|
19918
|
-
}
|
|
19919
|
-
x[j] += carry;
|
|
19920
|
-
x[i] = 0;
|
|
19921
|
-
}
|
|
19922
|
-
carry = 0;
|
|
19923
|
-
for (j = 0; j < 32; j++) {
|
|
19924
|
-
x[j] += carry - (x[31] >> 4) * L[j];
|
|
19925
|
-
carry = x[j] >> 8;
|
|
19926
|
-
x[j] &= 255;
|
|
19927
|
-
}
|
|
19928
|
-
for (j = 0; j < 32; j++) x[j] -= carry * L[j];
|
|
19929
|
-
for (i = 0; i < 32; i++) {
|
|
19930
|
-
x[i+1] += x[i] >> 8;
|
|
19931
|
-
r[i] = x[i] & 255;
|
|
19932
|
-
}
|
|
19933
|
-
}
|
|
19934
|
-
|
|
19935
|
-
function reduce(r) {
|
|
19936
|
-
var x = new Float64Array(64), i;
|
|
19937
|
-
for (i = 0; i < 64; i++) x[i] = r[i];
|
|
19938
|
-
for (i = 0; i < 64; i++) r[i] = 0;
|
|
19939
|
-
modL(r, x);
|
|
19940
|
-
}
|
|
19941
|
-
|
|
19942
|
-
// Note: difference from C - smlen returned, not passed as argument.
|
|
19943
|
-
function crypto_sign(sm, m, n, sk) {
|
|
19944
|
-
var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
|
|
19945
|
-
var i, j, x = new Float64Array(64);
|
|
19946
|
-
var p = [gf(), gf(), gf(), gf()];
|
|
19947
|
-
|
|
19948
|
-
crypto_hash(d, sk, 32);
|
|
19949
|
-
d[0] &= 248;
|
|
19950
|
-
d[31] &= 127;
|
|
19951
|
-
d[31] |= 64;
|
|
19952
|
-
|
|
19953
|
-
var smlen = n + 64;
|
|
19954
|
-
for (i = 0; i < n; i++) sm[64 + i] = m[i];
|
|
19955
|
-
for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
|
|
19956
|
-
|
|
19957
|
-
crypto_hash(r, sm.subarray(32), n+32);
|
|
19958
|
-
reduce(r);
|
|
19959
|
-
scalarbase(p, r);
|
|
19960
|
-
pack(sm, p);
|
|
19961
|
-
|
|
19962
|
-
for (i = 32; i < 64; i++) sm[i] = sk[i];
|
|
19963
|
-
crypto_hash(h, sm, n + 64);
|
|
19964
|
-
reduce(h);
|
|
19965
|
-
|
|
19966
|
-
for (i = 0; i < 64; i++) x[i] = 0;
|
|
19967
|
-
for (i = 0; i < 32; i++) x[i] = r[i];
|
|
19968
|
-
for (i = 0; i < 32; i++) {
|
|
19969
|
-
for (j = 0; j < 32; j++) {
|
|
19970
|
-
x[i+j] += h[i] * d[j];
|
|
19971
|
-
}
|
|
19972
|
-
}
|
|
19973
|
-
|
|
19974
|
-
modL(sm.subarray(32), x);
|
|
19975
|
-
return smlen;
|
|
19976
|
-
}
|
|
19977
|
-
|
|
19978
|
-
function unpackneg(r, p) {
|
|
19979
|
-
var t = gf(), chk = gf(), num = gf(),
|
|
19980
|
-
den = gf(), den2 = gf(), den4 = gf(),
|
|
19981
|
-
den6 = gf();
|
|
19982
|
-
|
|
19983
|
-
set25519(r[2], gf1);
|
|
19984
|
-
unpack25519(r[1], p);
|
|
19985
|
-
S(num, r[1]);
|
|
19986
|
-
M(den, num, D);
|
|
19987
|
-
Z(num, num, r[2]);
|
|
19988
|
-
A(den, r[2], den);
|
|
19989
|
-
|
|
19990
|
-
S(den2, den);
|
|
19991
|
-
S(den4, den2);
|
|
19992
|
-
M(den6, den4, den2);
|
|
19993
|
-
M(t, den6, num);
|
|
19994
|
-
M(t, t, den);
|
|
19995
|
-
|
|
19996
|
-
pow2523(t, t);
|
|
19997
|
-
M(t, t, num);
|
|
19998
|
-
M(t, t, den);
|
|
19999
|
-
M(t, t, den);
|
|
20000
|
-
M(r[0], t, den);
|
|
20001
|
-
|
|
20002
|
-
S(chk, r[0]);
|
|
20003
|
-
M(chk, chk, den);
|
|
20004
|
-
if (neq25519(chk, num)) M(r[0], r[0], I);
|
|
20005
|
-
|
|
20006
|
-
S(chk, r[0]);
|
|
20007
|
-
M(chk, chk, den);
|
|
20008
|
-
if (neq25519(chk, num)) return -1;
|
|
20009
|
-
|
|
20010
|
-
if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
|
|
20011
|
-
|
|
20012
|
-
M(r[3], r[0], r[1]);
|
|
20013
|
-
return 0;
|
|
20014
|
-
}
|
|
20015
|
-
|
|
20016
|
-
function crypto_sign_open(m, sm, n, pk) {
|
|
20017
|
-
var i;
|
|
20018
|
-
var t = new Uint8Array(32), h = new Uint8Array(64);
|
|
20019
|
-
var p = [gf(), gf(), gf(), gf()],
|
|
20020
|
-
q = [gf(), gf(), gf(), gf()];
|
|
20021
|
-
|
|
20022
|
-
if (n < 64) return -1;
|
|
20023
|
-
|
|
20024
|
-
if (unpackneg(q, pk)) return -1;
|
|
20025
|
-
|
|
20026
|
-
for (i = 0; i < n; i++) m[i] = sm[i];
|
|
20027
|
-
for (i = 0; i < 32; i++) m[i+32] = pk[i];
|
|
20028
|
-
crypto_hash(h, m, n);
|
|
20029
|
-
reduce(h);
|
|
20030
|
-
scalarmult(p, q, h);
|
|
20031
|
-
|
|
20032
|
-
scalarbase(q, sm.subarray(32));
|
|
20033
|
-
add(p, q);
|
|
20034
|
-
pack(t, p);
|
|
20035
|
-
|
|
20036
|
-
n -= 64;
|
|
20037
|
-
if (crypto_verify_32(sm, 0, t, 0)) {
|
|
20038
|
-
for (i = 0; i < n; i++) m[i] = 0;
|
|
20039
|
-
return -1;
|
|
20040
|
-
}
|
|
20041
|
-
|
|
20042
|
-
for (i = 0; i < n; i++) m[i] = sm[i + 64];
|
|
20043
|
-
return n;
|
|
20044
|
-
}
|
|
20045
|
-
|
|
20046
|
-
var crypto_secretbox_KEYBYTES = 32,
|
|
20047
|
-
crypto_secretbox_NONCEBYTES = 24,
|
|
20048
|
-
crypto_secretbox_ZEROBYTES = 32,
|
|
20049
|
-
crypto_secretbox_BOXZEROBYTES = 16,
|
|
20050
|
-
crypto_scalarmult_BYTES = 32,
|
|
20051
|
-
crypto_scalarmult_SCALARBYTES = 32,
|
|
20052
|
-
crypto_box_PUBLICKEYBYTES = 32,
|
|
20053
|
-
crypto_box_SECRETKEYBYTES = 32,
|
|
20054
|
-
crypto_box_BEFORENMBYTES = 32,
|
|
20055
|
-
crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
|
|
20056
|
-
crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
|
|
20057
|
-
crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
|
|
20058
|
-
crypto_sign_BYTES = 64,
|
|
20059
|
-
crypto_sign_PUBLICKEYBYTES = 32,
|
|
20060
|
-
crypto_sign_SECRETKEYBYTES = 64,
|
|
20061
|
-
crypto_sign_SEEDBYTES = 32,
|
|
20062
|
-
crypto_hash_BYTES = 64;
|
|
20063
|
-
|
|
20064
|
-
nacl.lowlevel = {
|
|
20065
|
-
crypto_core_hsalsa20: crypto_core_hsalsa20,
|
|
20066
|
-
crypto_stream_xor: crypto_stream_xor,
|
|
20067
|
-
crypto_stream: crypto_stream,
|
|
20068
|
-
crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
|
|
20069
|
-
crypto_stream_salsa20: crypto_stream_salsa20,
|
|
20070
|
-
crypto_onetimeauth: crypto_onetimeauth,
|
|
20071
|
-
crypto_onetimeauth_verify: crypto_onetimeauth_verify,
|
|
20072
|
-
crypto_verify_16: crypto_verify_16,
|
|
20073
|
-
crypto_verify_32: crypto_verify_32,
|
|
20074
|
-
crypto_secretbox: crypto_secretbox,
|
|
20075
|
-
crypto_secretbox_open: crypto_secretbox_open,
|
|
20076
|
-
crypto_scalarmult: crypto_scalarmult,
|
|
20077
|
-
crypto_scalarmult_base: crypto_scalarmult_base,
|
|
20078
|
-
crypto_box_beforenm: crypto_box_beforenm,
|
|
20079
|
-
crypto_box_afternm: crypto_box_afternm,
|
|
20080
|
-
crypto_box: crypto_box,
|
|
20081
|
-
crypto_box_open: crypto_box_open,
|
|
20082
|
-
crypto_box_keypair: crypto_box_keypair,
|
|
20083
|
-
crypto_hash: crypto_hash,
|
|
20084
|
-
crypto_sign: crypto_sign,
|
|
20085
|
-
crypto_sign_keypair: crypto_sign_keypair,
|
|
20086
|
-
crypto_sign_open: crypto_sign_open,
|
|
20087
|
-
|
|
20088
|
-
crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
|
|
20089
|
-
crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
|
|
20090
|
-
crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
|
|
20091
|
-
crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
|
|
20092
|
-
crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
|
|
20093
|
-
crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
|
|
20094
|
-
crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
|
|
20095
|
-
crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
|
|
20096
|
-
crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
|
|
20097
|
-
crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
|
|
20098
|
-
crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
|
|
20099
|
-
crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
|
|
20100
|
-
crypto_sign_BYTES: crypto_sign_BYTES,
|
|
20101
|
-
crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
|
|
20102
|
-
crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
|
|
20103
|
-
crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
|
|
20104
|
-
crypto_hash_BYTES: crypto_hash_BYTES,
|
|
20105
|
-
|
|
20106
|
-
gf: gf,
|
|
20107
|
-
D: D,
|
|
20108
|
-
L: L,
|
|
20109
|
-
pack25519: pack25519,
|
|
20110
|
-
unpack25519: unpack25519,
|
|
20111
|
-
M: M,
|
|
20112
|
-
A: A,
|
|
20113
|
-
S: S,
|
|
20114
|
-
Z: Z,
|
|
20115
|
-
pow2523: pow2523,
|
|
20116
|
-
add: add,
|
|
20117
|
-
set25519: set25519,
|
|
20118
|
-
modL: modL,
|
|
20119
|
-
scalarmult: scalarmult,
|
|
20120
|
-
scalarbase: scalarbase,
|
|
20121
|
-
};
|
|
20122
|
-
|
|
20123
|
-
/* High-level API */
|
|
20124
|
-
|
|
20125
|
-
function checkLengths(k, n) {
|
|
20126
|
-
if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
|
|
20127
|
-
if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
|
|
20128
|
-
}
|
|
20129
|
-
|
|
20130
|
-
function checkBoxLengths(pk, sk) {
|
|
20131
|
-
if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
|
|
20132
|
-
if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
|
|
20133
|
-
}
|
|
20134
|
-
|
|
20135
|
-
function checkArrayTypes() {
|
|
20136
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
20137
|
-
if (!(arguments[i] instanceof Uint8Array))
|
|
20138
|
-
throw new TypeError('unexpected type, use Uint8Array');
|
|
20139
|
-
}
|
|
20140
|
-
}
|
|
20141
|
-
|
|
20142
|
-
function cleanup(arr) {
|
|
20143
|
-
for (var i = 0; i < arr.length; i++) arr[i] = 0;
|
|
20144
|
-
}
|
|
20145
|
-
|
|
20146
|
-
nacl.randomBytes = function(n) {
|
|
20147
|
-
var b = new Uint8Array(n);
|
|
20148
|
-
randombytes(b, n);
|
|
20149
|
-
return b;
|
|
20150
|
-
};
|
|
20151
|
-
|
|
20152
|
-
nacl.secretbox = function(msg, nonce, key) {
|
|
20153
|
-
checkArrayTypes(msg, nonce, key);
|
|
20154
|
-
checkLengths(key, nonce);
|
|
20155
|
-
var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
|
|
20156
|
-
var c = new Uint8Array(m.length);
|
|
20157
|
-
for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
|
|
20158
|
-
crypto_secretbox(c, m, m.length, nonce, key);
|
|
20159
|
-
return c.subarray(crypto_secretbox_BOXZEROBYTES);
|
|
20160
|
-
};
|
|
20161
|
-
|
|
20162
|
-
nacl.secretbox.open = function(box, nonce, key) {
|
|
20163
|
-
checkArrayTypes(box, nonce, key);
|
|
20164
|
-
checkLengths(key, nonce);
|
|
20165
|
-
var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
|
|
20166
|
-
var m = new Uint8Array(c.length);
|
|
20167
|
-
for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
|
|
20168
|
-
if (c.length < 32) return null;
|
|
20169
|
-
if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
|
|
20170
|
-
return m.subarray(crypto_secretbox_ZEROBYTES);
|
|
20171
|
-
};
|
|
20172
|
-
|
|
20173
|
-
nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
|
|
20174
|
-
nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
|
|
20175
|
-
nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
|
|
20176
|
-
|
|
20177
|
-
nacl.scalarMult = function(n, p) {
|
|
20178
|
-
checkArrayTypes(n, p);
|
|
20179
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
20180
|
-
if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
|
|
20181
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
20182
|
-
crypto_scalarmult(q, n, p);
|
|
20183
|
-
return q;
|
|
20184
|
-
};
|
|
20185
|
-
|
|
20186
|
-
nacl.scalarMult.base = function(n) {
|
|
20187
|
-
checkArrayTypes(n);
|
|
20188
|
-
if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
|
|
20189
|
-
var q = new Uint8Array(crypto_scalarmult_BYTES);
|
|
20190
|
-
crypto_scalarmult_base(q, n);
|
|
20191
|
-
return q;
|
|
20192
|
-
};
|
|
20193
|
-
|
|
20194
|
-
nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
|
|
20195
|
-
nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
|
|
20196
|
-
|
|
20197
|
-
nacl.box = function(msg, nonce, publicKey, secretKey) {
|
|
20198
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
20199
|
-
return nacl.secretbox(msg, nonce, k);
|
|
20200
|
-
};
|
|
20201
|
-
|
|
20202
|
-
nacl.box.before = function(publicKey, secretKey) {
|
|
20203
|
-
checkArrayTypes(publicKey, secretKey);
|
|
20204
|
-
checkBoxLengths(publicKey, secretKey);
|
|
20205
|
-
var k = new Uint8Array(crypto_box_BEFORENMBYTES);
|
|
20206
|
-
crypto_box_beforenm(k, publicKey, secretKey);
|
|
20207
|
-
return k;
|
|
20208
|
-
};
|
|
20209
|
-
|
|
20210
|
-
nacl.box.after = nacl.secretbox;
|
|
20211
|
-
|
|
20212
|
-
nacl.box.open = function(msg, nonce, publicKey, secretKey) {
|
|
20213
|
-
var k = nacl.box.before(publicKey, secretKey);
|
|
20214
|
-
return nacl.secretbox.open(msg, nonce, k);
|
|
20215
|
-
};
|
|
20216
|
-
|
|
20217
|
-
nacl.box.open.after = nacl.secretbox.open;
|
|
20218
|
-
|
|
20219
|
-
nacl.box.keyPair = function() {
|
|
20220
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
20221
|
-
var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
|
|
20222
|
-
crypto_box_keypair(pk, sk);
|
|
20223
|
-
return {publicKey: pk, secretKey: sk};
|
|
20224
|
-
};
|
|
20225
|
-
|
|
20226
|
-
nacl.box.keyPair.fromSecretKey = function(secretKey) {
|
|
20227
|
-
checkArrayTypes(secretKey);
|
|
20228
|
-
if (secretKey.length !== crypto_box_SECRETKEYBYTES)
|
|
20229
|
-
throw new Error('bad secret key size');
|
|
20230
|
-
var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
|
|
20231
|
-
crypto_scalarmult_base(pk, secretKey);
|
|
20232
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
20233
|
-
};
|
|
20234
|
-
|
|
20235
|
-
nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
|
|
20236
|
-
nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
|
|
20237
|
-
nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
|
|
20238
|
-
nacl.box.nonceLength = crypto_box_NONCEBYTES;
|
|
20239
|
-
nacl.box.overheadLength = nacl.secretbox.overheadLength;
|
|
20240
|
-
|
|
20241
|
-
nacl.sign = function(msg, secretKey) {
|
|
20242
|
-
checkArrayTypes(msg, secretKey);
|
|
20243
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
20244
|
-
throw new Error('bad secret key size');
|
|
20245
|
-
var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
|
|
20246
|
-
crypto_sign(signedMsg, msg, msg.length, secretKey);
|
|
20247
|
-
return signedMsg;
|
|
20248
|
-
};
|
|
20249
|
-
|
|
20250
|
-
nacl.sign.open = function(signedMsg, publicKey) {
|
|
20251
|
-
checkArrayTypes(signedMsg, publicKey);
|
|
20252
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
20253
|
-
throw new Error('bad public key size');
|
|
20254
|
-
var tmp = new Uint8Array(signedMsg.length);
|
|
20255
|
-
var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
|
|
20256
|
-
if (mlen < 0) return null;
|
|
20257
|
-
var m = new Uint8Array(mlen);
|
|
20258
|
-
for (var i = 0; i < m.length; i++) m[i] = tmp[i];
|
|
20259
|
-
return m;
|
|
20260
|
-
};
|
|
20261
|
-
|
|
20262
|
-
nacl.sign.detached = function(msg, secretKey) {
|
|
20263
|
-
var signedMsg = nacl.sign(msg, secretKey);
|
|
20264
|
-
var sig = new Uint8Array(crypto_sign_BYTES);
|
|
20265
|
-
for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
|
|
20266
|
-
return sig;
|
|
20267
|
-
};
|
|
20268
|
-
|
|
20269
|
-
nacl.sign.detached.verify = function(msg, sig, publicKey) {
|
|
20270
|
-
checkArrayTypes(msg, sig, publicKey);
|
|
20271
|
-
if (sig.length !== crypto_sign_BYTES)
|
|
20272
|
-
throw new Error('bad signature size');
|
|
20273
|
-
if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
|
|
20274
|
-
throw new Error('bad public key size');
|
|
20275
|
-
var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
20276
|
-
var m = new Uint8Array(crypto_sign_BYTES + msg.length);
|
|
20277
|
-
var i;
|
|
20278
|
-
for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
|
|
20279
|
-
for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
|
|
20280
|
-
return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
|
|
20281
|
-
};
|
|
20282
|
-
|
|
20283
|
-
nacl.sign.keyPair = function() {
|
|
20284
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20285
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
20286
|
-
crypto_sign_keypair(pk, sk);
|
|
20287
|
-
return {publicKey: pk, secretKey: sk};
|
|
20288
|
-
};
|
|
20289
|
-
|
|
20290
|
-
nacl.sign.keyPair.fromSecretKey = function(secretKey) {
|
|
20291
|
-
checkArrayTypes(secretKey);
|
|
20292
|
-
if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
|
|
20293
|
-
throw new Error('bad secret key size');
|
|
20294
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20295
|
-
for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
|
|
20296
|
-
return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
|
|
20297
|
-
};
|
|
20298
|
-
|
|
20299
|
-
nacl.sign.keyPair.fromSeed = function(seed) {
|
|
20300
|
-
checkArrayTypes(seed);
|
|
20301
|
-
if (seed.length !== crypto_sign_SEEDBYTES)
|
|
20302
|
-
throw new Error('bad seed size');
|
|
20303
|
-
var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
|
|
20304
|
-
var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
|
|
20305
|
-
for (var i = 0; i < 32; i++) sk[i] = seed[i];
|
|
20306
|
-
crypto_sign_keypair(pk, sk, true);
|
|
20307
|
-
return {publicKey: pk, secretKey: sk};
|
|
20308
|
-
};
|
|
20309
|
-
|
|
20310
|
-
nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
|
|
20311
|
-
nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
|
|
20312
|
-
nacl.sign.seedLength = crypto_sign_SEEDBYTES;
|
|
20313
|
-
nacl.sign.signatureLength = crypto_sign_BYTES;
|
|
20314
|
-
|
|
20315
|
-
nacl.hash = function(msg) {
|
|
20316
|
-
checkArrayTypes(msg);
|
|
20317
|
-
var h = new Uint8Array(crypto_hash_BYTES);
|
|
20318
|
-
crypto_hash(h, msg, msg.length);
|
|
20319
|
-
return h;
|
|
20320
|
-
};
|
|
20321
|
-
|
|
20322
|
-
nacl.hash.hashLength = crypto_hash_BYTES;
|
|
20323
|
-
|
|
20324
|
-
nacl.verify = function(x, y) {
|
|
20325
|
-
checkArrayTypes(x, y);
|
|
20326
|
-
// Zero length arguments are considered not equal.
|
|
20327
|
-
if (x.length === 0 || y.length === 0) return false;
|
|
20328
|
-
if (x.length !== y.length) return false;
|
|
20329
|
-
return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
|
|
20330
|
-
};
|
|
20331
|
-
|
|
20332
|
-
nacl.setPRNG = function(fn) {
|
|
20333
|
-
randombytes = fn;
|
|
20334
|
-
};
|
|
20335
|
-
|
|
20336
|
-
(function() {
|
|
20337
|
-
// Initialize PRNG if environment provides CSPRNG.
|
|
20338
|
-
// If not, methods calling randombytes will throw.
|
|
20339
|
-
var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
|
|
20340
|
-
if (crypto && crypto.getRandomValues) {
|
|
20341
|
-
// Browsers.
|
|
20342
|
-
var QUOTA = 65536;
|
|
20343
|
-
nacl.setPRNG(function(x, n) {
|
|
20344
|
-
var i, v = new Uint8Array(n);
|
|
20345
|
-
for (i = 0; i < n; i += QUOTA) {
|
|
20346
|
-
crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
|
|
20347
|
-
}
|
|
20348
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
20349
|
-
cleanup(v);
|
|
20350
|
-
});
|
|
20351
|
-
} else if (typeof commonjsRequire !== 'undefined') {
|
|
20352
|
-
// Node.js.
|
|
20353
|
-
crypto = require$$0;
|
|
20354
|
-
if (crypto && crypto.randomBytes) {
|
|
20355
|
-
nacl.setPRNG(function(x, n) {
|
|
20356
|
-
var i, v = crypto.randomBytes(n);
|
|
20357
|
-
for (i = 0; i < n; i++) x[i] = v[i];
|
|
20358
|
-
cleanup(v);
|
|
20359
|
-
});
|
|
20360
|
-
}
|
|
20361
|
-
}
|
|
20362
|
-
})();
|
|
20363
|
-
|
|
20364
|
-
})(module.exports ? module.exports : (self.nacl = self.nacl || {}));
|
|
20365
|
-
} (naclFast));
|
|
20366
|
-
return naclFast.exports;
|
|
20367
|
-
}
|
|
20368
|
-
|
|
20369
|
-
var naclFastExports = requireNaclFast();
|
|
20370
|
-
var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
|
|
20371
|
-
|
|
20372
|
-
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
20373
|
-
//
|
|
20374
|
-
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
20375
|
-
// Bounded account address; it signs the auth challenge exactly like a wallet.
|
|
20376
|
-
//
|
|
20377
|
-
// Two backends, chosen automatically:
|
|
20378
|
-
// 1. WebCrypto Ed25519 + IndexedDB (browsers that support it) — the key is
|
|
20379
|
-
// NON-EXTRACTABLE: an XSS can ask it to *sign* but can never read the
|
|
20380
|
-
// private bytes. This is the secure default.
|
|
20381
|
-
// 2. tweetnacl keypair in platform storage (React Native / older browsers) —
|
|
20382
|
-
// the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
|
|
20383
|
-
// treat it as a low-stakes guest identity and tell users to upgrade
|
|
20384
|
-
// (link an email) before they care about not losing it.
|
|
20385
|
-
//
|
|
20386
|
-
// Either way the public output is identical: a base58 address + a base64
|
|
20387
|
-
// detached signature, which is the format the session endpoint already accepts.
|
|
20388
|
-
const FALLBACK_STORE_KEY = 'bounded_guest_key_v1';
|
|
20389
|
-
const IDB_NAME = 'bounded-guest';
|
|
20390
|
-
const IDB_STORE = 'keys';
|
|
20391
|
-
const IDB_KEY = 'ed25519';
|
|
20392
|
-
function toBase64(bytes) {
|
|
20393
|
-
let bin = '';
|
|
20394
|
-
for (let i = 0; i < bytes.length; i++)
|
|
20395
|
-
bin += String.fromCharCode(bytes[i]);
|
|
20396
|
-
// btoa exists in browsers + RN (Hermes) ; Buffer is the Node/SSR fallback.
|
|
20397
|
-
return typeof btoa !== 'undefined' ? btoa(bin) : Buffer.from(bytes).toString('base64');
|
|
20398
|
-
}
|
|
20399
|
-
// ----- WebCrypto (non-extractable) backend -----------------------------------
|
|
20400
|
-
function subtle() {
|
|
20401
|
-
const c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto;
|
|
20402
|
-
return c && c.subtle ? c.subtle : null;
|
|
20403
|
-
}
|
|
20404
|
-
function idb() {
|
|
20405
|
-
return new Promise((resolve, reject) => {
|
|
20406
|
-
const req = globalThis.indexedDB.open(IDB_NAME, 1);
|
|
20407
|
-
req.onupgradeneeded = () => req.result.createObjectStore(IDB_STORE);
|
|
20408
|
-
req.onsuccess = () => resolve(req.result);
|
|
20409
|
-
req.onerror = () => reject(req.error);
|
|
20410
|
-
});
|
|
20411
|
-
}
|
|
20412
|
-
function idbGet(db, key) {
|
|
20413
|
-
return new Promise((resolve, reject) => {
|
|
20414
|
-
const r = db.transaction(IDB_STORE, 'readonly').objectStore(IDB_STORE).get(key);
|
|
20415
|
-
r.onsuccess = () => resolve(r.result);
|
|
20416
|
-
r.onerror = () => reject(r.error);
|
|
20417
|
-
});
|
|
20418
|
-
}
|
|
20419
|
-
function idbPut(db, key, val) {
|
|
20420
|
-
return new Promise((resolve, reject) => {
|
|
20421
|
-
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).put(val, key);
|
|
20422
|
-
r.onsuccess = () => resolve();
|
|
20423
|
-
r.onerror = () => reject(r.error);
|
|
20424
|
-
});
|
|
20425
|
-
}
|
|
20426
|
-
async function tryWebCrypto() {
|
|
20427
|
-
const s = subtle();
|
|
20428
|
-
if (!s || typeof globalThis.indexedDB === 'undefined')
|
|
20429
|
-
return null;
|
|
20430
|
-
try {
|
|
20431
|
-
const db = await idb();
|
|
20432
|
-
let pair = (await idbGet(db, IDB_KEY));
|
|
20433
|
-
if (!pair) {
|
|
20434
|
-
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
20435
|
-
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
20436
|
-
'sign',
|
|
20437
|
-
'verify',
|
|
20438
|
-
]));
|
|
20439
|
-
await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed
|
|
20440
|
-
}
|
|
20441
|
-
const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable
|
|
20442
|
-
const address = bs58.encode(raw);
|
|
20443
|
-
return {
|
|
20444
|
-
address,
|
|
20445
|
-
nonExtractable: true,
|
|
20446
|
-
async sign(message) {
|
|
20447
|
-
const data = new TextEncoder().encode(message);
|
|
20448
|
-
const sig = new Uint8Array(await s.sign({ name: 'Ed25519' }, pair.privateKey, data));
|
|
20449
|
-
return toBase64(sig);
|
|
20450
|
-
},
|
|
20451
|
-
};
|
|
20452
|
-
}
|
|
20453
|
-
catch (_a) {
|
|
20454
|
-
return null; // engine lacks Ed25519 / IndexedDB blocked → fall back
|
|
20455
|
-
}
|
|
20456
|
-
}
|
|
20457
|
-
// ----- tweetnacl (stored-secret) fallback ------------------------------------
|
|
20458
|
-
function fallbackKey() {
|
|
20459
|
-
const store = getPlatform().storage;
|
|
20460
|
-
let secret;
|
|
20461
|
-
const saved = store.getItem(FALLBACK_STORE_KEY);
|
|
20462
|
-
if (saved) {
|
|
20463
|
-
secret = bs58.decode(saved);
|
|
20464
|
-
}
|
|
20465
|
-
else {
|
|
20466
|
-
const kp = web3_js.Keypair.generate();
|
|
20467
|
-
secret = kp.secretKey; // 64 bytes
|
|
20468
|
-
store.setItem(FALLBACK_STORE_KEY, bs58.encode(secret));
|
|
20469
|
-
}
|
|
20470
|
-
const kp = web3_js.Keypair.fromSecretKey(secret);
|
|
20471
|
-
const address = kp.publicKey.toBase58();
|
|
20472
|
-
return {
|
|
20473
|
-
address,
|
|
20474
|
-
nonExtractable: false,
|
|
20475
|
-
async sign(message) {
|
|
20476
|
-
const data = new TextEncoder().encode(message);
|
|
20477
|
-
const sig = nacl.sign.detached(data, secret);
|
|
20478
|
-
return toBase64(sig);
|
|
20479
|
-
},
|
|
20480
|
-
};
|
|
20481
|
-
}
|
|
20482
|
-
let cached = null;
|
|
20483
|
-
/** Get (or create) this device's durable guest key. */
|
|
20484
|
-
async function getGuestKey() {
|
|
20485
|
-
var _a;
|
|
20486
|
-
if (cached)
|
|
20487
|
-
return cached;
|
|
20488
|
-
cached = (_a = (await tryWebCrypto())) !== null && _a !== void 0 ? _a : fallbackKey();
|
|
20489
|
-
return cached;
|
|
20490
|
-
}
|
|
20491
|
-
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
20492
|
-
async function clearGuestKey() {
|
|
20493
|
-
cached = null;
|
|
20494
|
-
try {
|
|
20495
|
-
getPlatform().storage.removeItem(FALLBACK_STORE_KEY);
|
|
20496
|
-
}
|
|
20497
|
-
catch (_a) { }
|
|
20498
|
-
try {
|
|
20499
|
-
if (typeof globalThis.indexedDB !== 'undefined') {
|
|
20500
|
-
const db = await idb();
|
|
20501
|
-
await new Promise((res) => {
|
|
20502
|
-
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).delete(IDB_KEY);
|
|
20503
|
-
r.onsuccess = () => res();
|
|
20504
|
-
r.onerror = () => res();
|
|
20505
|
-
});
|
|
20506
|
-
}
|
|
20507
|
-
}
|
|
20508
|
-
catch (_b) { }
|
|
20509
|
-
}
|
|
18142
|
+
// guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
|
|
18143
|
+
//
|
|
18144
|
+
// A guest is an ed25519 keypair generated on the device. Its public key is the
|
|
18145
|
+
// Bounded account address; it signs the auth challenge exactly like a wallet.
|
|
18146
|
+
//
|
|
18147
|
+
// Two backends, chosen automatically:
|
|
18148
|
+
// 1. WebCrypto Ed25519 + IndexedDB (browsers that support it) — the key is
|
|
18149
|
+
// NON-EXTRACTABLE: an XSS can ask it to *sign* but can never read the
|
|
18150
|
+
// private bytes. This is the secure default.
|
|
18151
|
+
// 2. tweetnacl keypair in platform storage (React Native / older browsers) —
|
|
18152
|
+
// the secret is stored as bytes. Simpler, but exfiltratable by XSS, so
|
|
18153
|
+
// treat it as a low-stakes guest identity and tell users to upgrade
|
|
18154
|
+
// (link an email) before they care about not losing it.
|
|
18155
|
+
//
|
|
18156
|
+
// Either way the public output is identical: a base58 address + a base64
|
|
18157
|
+
// detached signature, which is the format the session endpoint already accepts.
|
|
18158
|
+
const FALLBACK_STORE_KEY = 'bounded_guest_key_v1';
|
|
18159
|
+
const IDB_NAME = 'bounded-guest';
|
|
18160
|
+
const IDB_STORE = 'keys';
|
|
18161
|
+
const IDB_KEY = 'ed25519';
|
|
18162
|
+
function toBase64(bytes) {
|
|
18163
|
+
let bin = '';
|
|
18164
|
+
for (let i = 0; i < bytes.length; i++)
|
|
18165
|
+
bin += String.fromCharCode(bytes[i]);
|
|
18166
|
+
// btoa exists in browsers + RN (Hermes) ; Buffer is the Node/SSR fallback.
|
|
18167
|
+
return typeof btoa !== 'undefined' ? btoa(bin) : Buffer.from(bytes).toString('base64');
|
|
18168
|
+
}
|
|
18169
|
+
// ----- WebCrypto (non-extractable) backend -----------------------------------
|
|
18170
|
+
function subtle() {
|
|
18171
|
+
const c = globalThis === null || globalThis === void 0 ? void 0 : globalThis.crypto;
|
|
18172
|
+
return c && c.subtle ? c.subtle : null;
|
|
18173
|
+
}
|
|
18174
|
+
function idb() {
|
|
18175
|
+
return new Promise((resolve, reject) => {
|
|
18176
|
+
const req = globalThis.indexedDB.open(IDB_NAME, 1);
|
|
18177
|
+
req.onupgradeneeded = () => req.result.createObjectStore(IDB_STORE);
|
|
18178
|
+
req.onsuccess = () => resolve(req.result);
|
|
18179
|
+
req.onerror = () => reject(req.error);
|
|
18180
|
+
});
|
|
18181
|
+
}
|
|
18182
|
+
function idbGet(db, key) {
|
|
18183
|
+
return new Promise((resolve, reject) => {
|
|
18184
|
+
const r = db.transaction(IDB_STORE, 'readonly').objectStore(IDB_STORE).get(key);
|
|
18185
|
+
r.onsuccess = () => resolve(r.result);
|
|
18186
|
+
r.onerror = () => reject(r.error);
|
|
18187
|
+
});
|
|
18188
|
+
}
|
|
18189
|
+
function idbPut(db, key, val) {
|
|
18190
|
+
return new Promise((resolve, reject) => {
|
|
18191
|
+
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).put(val, key);
|
|
18192
|
+
r.onsuccess = () => resolve();
|
|
18193
|
+
r.onerror = () => reject(r.error);
|
|
18194
|
+
});
|
|
18195
|
+
}
|
|
18196
|
+
async function tryWebCrypto() {
|
|
18197
|
+
const s = subtle();
|
|
18198
|
+
if (!s || typeof globalThis.indexedDB === 'undefined')
|
|
18199
|
+
return null;
|
|
18200
|
+
try {
|
|
18201
|
+
const db = await idb();
|
|
18202
|
+
let pair = (await idbGet(db, IDB_KEY));
|
|
18203
|
+
if (!pair) {
|
|
18204
|
+
// Probe Ed25519 support by generating (throws on unsupported engines).
|
|
18205
|
+
pair = (await s.generateKey({ name: 'Ed25519' }, /* extractable */ false, [
|
|
18206
|
+
'sign',
|
|
18207
|
+
'verify',
|
|
18208
|
+
]));
|
|
18209
|
+
await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed
|
|
18210
|
+
}
|
|
18211
|
+
const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable
|
|
18212
|
+
const address = bs58.encode(raw);
|
|
18213
|
+
return {
|
|
18214
|
+
address,
|
|
18215
|
+
nonExtractable: true,
|
|
18216
|
+
async sign(message) {
|
|
18217
|
+
const data = new TextEncoder().encode(message);
|
|
18218
|
+
const sig = new Uint8Array(await s.sign({ name: 'Ed25519' }, pair.privateKey, data));
|
|
18219
|
+
return toBase64(sig);
|
|
18220
|
+
},
|
|
18221
|
+
};
|
|
18222
|
+
}
|
|
18223
|
+
catch (_a) {
|
|
18224
|
+
return null; // engine lacks Ed25519 / IndexedDB blocked → fall back
|
|
18225
|
+
}
|
|
18226
|
+
}
|
|
18227
|
+
// ----- tweetnacl (stored-secret) fallback ------------------------------------
|
|
18228
|
+
function fallbackKey() {
|
|
18229
|
+
const store = getPlatform().storage;
|
|
18230
|
+
let secret;
|
|
18231
|
+
const saved = store.getItem(FALLBACK_STORE_KEY);
|
|
18232
|
+
if (saved) {
|
|
18233
|
+
secret = bs58.decode(saved);
|
|
18234
|
+
}
|
|
18235
|
+
else {
|
|
18236
|
+
const kp = web3_js.Keypair.generate();
|
|
18237
|
+
secret = kp.secretKey; // 64 bytes
|
|
18238
|
+
store.setItem(FALLBACK_STORE_KEY, bs58.encode(secret));
|
|
18239
|
+
}
|
|
18240
|
+
const kp = web3_js.Keypair.fromSecretKey(secret);
|
|
18241
|
+
const address = kp.publicKey.toBase58();
|
|
18242
|
+
return {
|
|
18243
|
+
address,
|
|
18244
|
+
nonExtractable: false,
|
|
18245
|
+
async sign(message) {
|
|
18246
|
+
const data = new TextEncoder().encode(message);
|
|
18247
|
+
const sig = nacl.sign.detached(data, secret);
|
|
18248
|
+
return toBase64(sig);
|
|
18249
|
+
},
|
|
18250
|
+
};
|
|
18251
|
+
}
|
|
18252
|
+
let cached = null;
|
|
18253
|
+
/** Get (or create) this device's durable guest key. */
|
|
18254
|
+
async function getGuestKey() {
|
|
18255
|
+
var _a;
|
|
18256
|
+
if (cached)
|
|
18257
|
+
return cached;
|
|
18258
|
+
cached = (_a = (await tryWebCrypto())) !== null && _a !== void 0 ? _a : fallbackKey();
|
|
18259
|
+
return cached;
|
|
18260
|
+
}
|
|
18261
|
+
/** Forget the guest key on this device (a fresh signInAnonymously mints a new one). */
|
|
18262
|
+
async function clearGuestKey() {
|
|
18263
|
+
cached = null;
|
|
18264
|
+
try {
|
|
18265
|
+
getPlatform().storage.removeItem(FALLBACK_STORE_KEY);
|
|
18266
|
+
}
|
|
18267
|
+
catch (_a) { }
|
|
18268
|
+
try {
|
|
18269
|
+
if (typeof globalThis.indexedDB !== 'undefined') {
|
|
18270
|
+
const db = await idb();
|
|
18271
|
+
await new Promise((res) => {
|
|
18272
|
+
const r = db.transaction(IDB_STORE, 'readwrite').objectStore(IDB_STORE).delete(IDB_KEY);
|
|
18273
|
+
r.onsuccess = () => res();
|
|
18274
|
+
r.onerror = () => res();
|
|
18275
|
+
});
|
|
18276
|
+
}
|
|
18277
|
+
}
|
|
18278
|
+
catch (_b) { }
|
|
18279
|
+
}
|
|
20510
18280
|
|
|
20511
18281
|
const GUEST_TX_UNSUPPORTED = 'Guest (anonymous) auth is offchain-only — it cannot sign or submit Solana transactions. ' +
|
|
20512
18282
|
'Use a wallet provider for onchain actions.';
|
|
@@ -20645,6 +18415,17 @@ async function post(path, body) {
|
|
|
20645
18415
|
// ---------------------------------------------------------------------------
|
|
20646
18416
|
// headless primitives (used by the modal AND exported for custom UIs)
|
|
20647
18417
|
// ---------------------------------------------------------------------------
|
|
18418
|
+
function normalizePhoneNumber(value) {
|
|
18419
|
+
const compact = String(value || '').trim().replace(/[()\s.-]/g, '');
|
|
18420
|
+
return compact.startsWith('00') ? `+${compact.slice(2)}` : compact;
|
|
18421
|
+
}
|
|
18422
|
+
function assertPhoneNumber(value) {
|
|
18423
|
+
const phoneNumber = normalizePhoneNumber(value);
|
|
18424
|
+
if (!/^\+[1-9]\d{7,14}$/.test(phoneNumber)) {
|
|
18425
|
+
throw new Error('phoneNumber must be in E.164 format, e.g. +14155550132');
|
|
18426
|
+
}
|
|
18427
|
+
return phoneNumber;
|
|
18428
|
+
}
|
|
20648
18429
|
/** Send a login code to `email`. Step 1 of the inline email-OTP flow. */
|
|
20649
18430
|
async function sendEmailOtp$1(email) {
|
|
20650
18431
|
const cfg = await getConfig();
|
|
@@ -20654,6 +18435,13 @@ async function sendEmailOtp$1(email) {
|
|
|
20654
18435
|
const data = await post('/email', { email: e, appId: cfg.appId });
|
|
20655
18436
|
return { ok: true, expiresInSeconds: data === null || data === void 0 ? void 0 : data.expiresInSeconds };
|
|
20656
18437
|
}
|
|
18438
|
+
/** Send a login code by text message. Requires the Bounded issuer to have text OTP explicitly enabled and SMS configured. */
|
|
18439
|
+
async function sendTextOtp$1(phoneNumber) {
|
|
18440
|
+
const cfg = await getConfig();
|
|
18441
|
+
const phone = assertPhoneNumber(phoneNumber);
|
|
18442
|
+
const data = await post('/text', { phoneNumber: phone, appId: cfg.appId });
|
|
18443
|
+
return { ok: true, expiresInSeconds: data === null || data === void 0 ? void 0 : data.expiresInSeconds };
|
|
18444
|
+
}
|
|
20657
18445
|
/**
|
|
20658
18446
|
* Verify the code for `email` and establish the session. Step 2 of the flow.
|
|
20659
18447
|
* Stores the Bounded id token (the realtime bearer) and sets the current user.
|
|
@@ -20687,6 +18475,33 @@ async function verifyEmailOtp$1(email, otp) {
|
|
|
20687
18475
|
setAuthLoading(false);
|
|
20688
18476
|
}
|
|
20689
18477
|
}
|
|
18478
|
+
/**
|
|
18479
|
+
* Verify the text-message code for `phoneNumber` and establish the session.
|
|
18480
|
+
* Phone-only users have `user.email === null`; use `user.id` for ownership.
|
|
18481
|
+
*/
|
|
18482
|
+
async function verifyTextOtp$1(phoneNumber, otp) {
|
|
18483
|
+
setAuthLoading(true);
|
|
18484
|
+
try {
|
|
18485
|
+
const cfg = await getConfig();
|
|
18486
|
+
const phone = assertPhoneNumber(phoneNumber);
|
|
18487
|
+
const code = (otp || '').trim();
|
|
18488
|
+
if (!code)
|
|
18489
|
+
throw new Error('code is required');
|
|
18490
|
+
const data = await post('/text/verify', { phoneNumber: phone, appId: cfg.appId, otp: code });
|
|
18491
|
+
const idToken = data === null || data === void 0 ? void 0 : data.idToken;
|
|
18492
|
+
if (!idToken)
|
|
18493
|
+
throw new Error('No token returned from verification.');
|
|
18494
|
+
const user = userFromIdToken$1(idToken);
|
|
18495
|
+
const refreshToken = typeof (data === null || data === void 0 ? void 0 : data.refreshToken) === 'string' ? data.refreshToken : '';
|
|
18496
|
+
const issuer = (cfg.humanAuthApiUrl || '').replace(/\/$/, '');
|
|
18497
|
+
await sessionManager$1().storeSession(String(user.address || ''), idToken, idToken, refreshToken, issuer);
|
|
18498
|
+
setCurrentUser(user);
|
|
18499
|
+
return user;
|
|
18500
|
+
}
|
|
18501
|
+
finally {
|
|
18502
|
+
setAuthLoading(false);
|
|
18503
|
+
}
|
|
18504
|
+
}
|
|
20690
18505
|
/**
|
|
20691
18506
|
* UPGRADE an anonymous (guest) session by LINKING an email credential — Firebase
|
|
20692
18507
|
* `linkWithCredential` parity. The guest's `guestToken` is sent to the auth issuer
|
|
@@ -20744,8 +18559,8 @@ class EmailAuthProvider {
|
|
|
20744
18559
|
async login() {
|
|
20745
18560
|
if (!getPlatform().hasDOM) {
|
|
20746
18561
|
throw new Error('Email login on this platform (e.g. React Native) is headless: call ' +
|
|
20747
|
-
"sendEmailOtp(email) then verifyEmailOtp(email, code)
|
|
20748
|
-
|
|
18562
|
+
"sendEmailOtp(email) then verifyEmailOtp(email, code), or, when text OTP is enabled, " +
|
|
18563
|
+
"sendTextOtp(phone) then verifyTextOtp(phone, code). Render your own OTP inputs. The built-in modal is web-only.");
|
|
20749
18564
|
}
|
|
20750
18565
|
return openEmailModal();
|
|
20751
18566
|
}
|
|
@@ -20962,6 +18777,11 @@ function userFromIdToken(idToken) {
|
|
|
20962
18777
|
email: (c.email || null), provider: oidcProviderSingleton,
|
|
20963
18778
|
};
|
|
20964
18779
|
}
|
|
18780
|
+
function tokenField(data, snake, camel) {
|
|
18781
|
+
var _a;
|
|
18782
|
+
const value = (_a = data === null || data === void 0 ? void 0 : data[snake]) !== null && _a !== void 0 ? _a : data === null || data === void 0 ? void 0 : data[camel];
|
|
18783
|
+
return typeof value === 'string' ? value : '';
|
|
18784
|
+
}
|
|
20965
18785
|
async function issuerBase() {
|
|
20966
18786
|
const cfg = await getConfig();
|
|
20967
18787
|
return (cfg.humanAuthApiUrl || 'https://auth.bounded.sh').replace(/\/$/, '');
|
|
@@ -20985,10 +18805,26 @@ function randomState() {
|
|
|
20985
18805
|
crypto.getRandomValues(rnd);
|
|
20986
18806
|
return b64url(rnd.buffer);
|
|
20987
18807
|
}
|
|
20988
|
-
|
|
18808
|
+
function normalizeMethod(value) {
|
|
18809
|
+
const normalized = String(value || '').trim().toLowerCase();
|
|
18810
|
+
return /^[a-z0-9_-]{1,40}$/.test(normalized) ? normalized : null;
|
|
18811
|
+
}
|
|
18812
|
+
function appendHostedLoginHints(params, opts) {
|
|
18813
|
+
const methods = (opts.methods || [])
|
|
18814
|
+
.map((method) => normalizeMethod(method))
|
|
18815
|
+
.filter((method) => !!method);
|
|
18816
|
+
if (methods.length > 0) {
|
|
18817
|
+
params.set('bounded_methods', Array.from(new Set(methods)).join(','));
|
|
18818
|
+
}
|
|
18819
|
+
const provider = normalizeMethod(opts.provider);
|
|
18820
|
+
if (provider)
|
|
18821
|
+
params.set('bounded_provider', provider);
|
|
18822
|
+
}
|
|
18823
|
+
async function buildAuthorizeUrl(opts) {
|
|
20989
18824
|
const cfg = await getConfig();
|
|
20990
18825
|
if (!cfg.appId)
|
|
20991
18826
|
throw new Error('appId is not configured (init the SDK with your appId)');
|
|
18827
|
+
const redirectUri = opts.redirectUri;
|
|
20992
18828
|
const { verifier, challenge } = await makePkce();
|
|
20993
18829
|
const state = randomState();
|
|
20994
18830
|
// Stash the verifier + state so the redirect_uri page can finish the exchange. sessionStorage
|
|
@@ -20999,6 +18835,7 @@ async function buildAuthorizeUrl(redirectUri) {
|
|
|
20999
18835
|
client_id: cfg.appId, redirect_uri: redirectUri, response_type: 'code', scope: 'openid profile email',
|
|
21000
18836
|
code_challenge: challenge, code_challenge_method: 'S256', state,
|
|
21001
18837
|
});
|
|
18838
|
+
appendHostedLoginHints(params, opts);
|
|
21002
18839
|
return `${base}/api/auth/oauth2/authorize?${params.toString()}`;
|
|
21003
18840
|
}
|
|
21004
18841
|
/** Start login: navigate the whole page to the hosted Bounded login. Returns after redirect
|
|
@@ -21006,7 +18843,7 @@ async function buildAuthorizeUrl(redirectUri) {
|
|
|
21006
18843
|
async function loginWithRedirect(opts) {
|
|
21007
18844
|
if (!hasDOM())
|
|
21008
18845
|
throw new Error('loginWithRedirect is web-only');
|
|
21009
|
-
const url = await buildAuthorizeUrl(opts
|
|
18846
|
+
const url = await buildAuthorizeUrl(opts);
|
|
21010
18847
|
window.location.href = url;
|
|
21011
18848
|
}
|
|
21012
18849
|
const LINK_GUEST_KEY = 'bounded.link.guest';
|
|
@@ -21022,7 +18859,7 @@ async function linkWithRedirect(opts) {
|
|
|
21022
18859
|
if (!guestToken)
|
|
21023
18860
|
throw new Error('linkWithRedirect requires an active anonymous session — call signInAnonymously() first.');
|
|
21024
18861
|
sessionStorage.setItem(LINK_GUEST_KEY, guestToken);
|
|
21025
|
-
const url = await buildAuthorizeUrl(opts
|
|
18862
|
+
const url = await buildAuthorizeUrl(opts);
|
|
21026
18863
|
window.location.href = url;
|
|
21027
18864
|
}
|
|
21028
18865
|
// If a guest-link is pending (linkWithRedirect stashed a guest token before this
|
|
@@ -21044,10 +18881,13 @@ async function finishGuestLinkIfPending(socialIdToken) {
|
|
|
21044
18881
|
body: JSON.stringify({ appId: cfg.appId, guestToken, socialToken: socialIdToken }),
|
|
21045
18882
|
});
|
|
21046
18883
|
const data = await res.json().catch(() => null);
|
|
21047
|
-
|
|
18884
|
+
const idToken = tokenField(data, 'id_token', 'idToken');
|
|
18885
|
+
if (!res.ok || !idToken)
|
|
21048
18886
|
return null; // link failed -> keep the plain social session
|
|
21049
|
-
const upgraded = userFromIdToken(
|
|
21050
|
-
|
|
18887
|
+
const upgraded = userFromIdToken(idToken);
|
|
18888
|
+
const accessToken = tokenField(data, 'access_token', 'accessToken') || idToken;
|
|
18889
|
+
const refreshToken = tokenField(data, 'refresh_token', 'refreshToken');
|
|
18890
|
+
await sessionManager().storeSession(String(upgraded.address || ''), accessToken, idToken, refreshToken, base);
|
|
21051
18891
|
setCurrentUser(upgraded);
|
|
21052
18892
|
return upgraded;
|
|
21053
18893
|
}
|
|
@@ -21094,7 +18934,7 @@ async function completeLoginFromRedirect() {
|
|
|
21094
18934
|
async function loginWithPopup(opts) {
|
|
21095
18935
|
if (!hasDOM())
|
|
21096
18936
|
throw new Error('loginWithPopup is web-only');
|
|
21097
|
-
const url = await buildAuthorizeUrl(opts
|
|
18937
|
+
const url = await buildAuthorizeUrl(opts);
|
|
21098
18938
|
const w = opts.width || 480, h = opts.height || 720;
|
|
21099
18939
|
const left = window.screenX + (window.outerWidth - w) / 2;
|
|
21100
18940
|
const top = window.screenY + (window.outerHeight - h) / 2;
|
|
@@ -21186,8 +19026,10 @@ async function exchangeCode(code, verifier, redirectUri) {
|
|
|
21186
19026
|
const idToken = (data === null || data === void 0 ? void 0 : data.id_token) || (data === null || data === void 0 ? void 0 : data.idToken);
|
|
21187
19027
|
if (!idToken)
|
|
21188
19028
|
throw new Error('No id_token returned from the token endpoint');
|
|
19029
|
+
const accessToken = tokenField(data, 'access_token', 'accessToken') || idToken;
|
|
19030
|
+
const refreshToken = tokenField(data, 'refresh_token', 'refreshToken');
|
|
21189
19031
|
const user = userFromIdToken(idToken);
|
|
21190
|
-
await sessionManager().storeSession(String(user.address || ''),
|
|
19032
|
+
await sessionManager().storeSession(String(user.address || ''), accessToken, idToken, refreshToken, base);
|
|
21191
19033
|
setCurrentUser(user);
|
|
21192
19034
|
setAuthProviderInstance(oidcProviderSingleton);
|
|
21193
19035
|
return user;
|
|
@@ -21248,17 +19090,17 @@ function clearIncompatibleSession() {
|
|
|
21248
19090
|
// Lazy loaders for web-only providers.
|
|
21249
19091
|
// Using dynamic import() ensures Metro (RN) never resolves these modules.
|
|
21250
19092
|
async function loadPhantomWalletProvider() {
|
|
21251
|
-
const mod = await Promise.resolve().then(function () { return require('./phantom-wallet-provider-
|
|
19093
|
+
const mod = await Promise.resolve().then(function () { return require('./phantom-wallet-provider-DKScS8m6.js'); });
|
|
21252
19094
|
return { PhantomWalletProvider: mod.PhantomWalletProvider };
|
|
21253
19095
|
}
|
|
21254
19096
|
// Web Privy provider (depends on react-dom + @privy-io/react-auth). Lazy so Metro
|
|
21255
19097
|
// never bundles it into the RN build — RN uses the @privy-io/expo provider instead.
|
|
21256
19098
|
async function loadPrivyWalletProvider() {
|
|
21257
|
-
const mod = await Promise.resolve().then(function () { return require('./privy-wallet-provider-
|
|
19099
|
+
const mod = await Promise.resolve().then(function () { return require('./privy-wallet-provider-wCTdqpRq.js'); });
|
|
21258
19100
|
return mod.PrivyWalletProvider;
|
|
21259
19101
|
}
|
|
21260
19102
|
async function loadSolanaMobileWalletProvider() {
|
|
21261
|
-
const mod = await Promise.resolve().then(function () { return require('./solana-mobile-wallet-provider-
|
|
19103
|
+
const mod = await Promise.resolve().then(function () { return require('./solana-mobile-wallet-provider-DZx3xVit.js'); });
|
|
21262
19104
|
return mod.SolanaMobileWalletProvider;
|
|
21263
19105
|
}
|
|
21264
19106
|
async function hotSwapToMWAProvider(config) {
|
|
@@ -21493,6 +19335,15 @@ async function sendEmailOtp(email) {
|
|
|
21493
19335
|
assertBrowserAuthEnv('sendEmailOtp');
|
|
21494
19336
|
return sendEmailOtp$1(email);
|
|
21495
19337
|
}
|
|
19338
|
+
/**
|
|
19339
|
+
* Send a 6-digit login code by text message. Requires the configured Bounded
|
|
19340
|
+
* auth issuer to have text OTP explicitly enabled and SMS delivery configured.
|
|
19341
|
+
* Works on web AND React Native.
|
|
19342
|
+
*/
|
|
19343
|
+
async function sendTextOtp(phoneNumber) {
|
|
19344
|
+
assertBrowserAuthEnv('sendTextOtp');
|
|
19345
|
+
return sendTextOtp$1(phoneNumber);
|
|
19346
|
+
}
|
|
21496
19347
|
/**
|
|
21497
19348
|
* Verify the `code` for `email`, establish the session, and return the user.
|
|
21498
19349
|
* Step 2 of the inline email flow. Coexists with signInAnonymously()/wallets.
|
|
@@ -21502,6 +19353,15 @@ async function verifyEmailOtp(email, code) {
|
|
|
21502
19353
|
await activateEmailProvider();
|
|
21503
19354
|
return verifyEmailOtp$1(email, code);
|
|
21504
19355
|
}
|
|
19356
|
+
/**
|
|
19357
|
+
* Verify the text-message `code`, establish the session, and return the user.
|
|
19358
|
+
* Phone-only users have no `user.email`; use `user.id` for app identity.
|
|
19359
|
+
*/
|
|
19360
|
+
async function verifyTextOtp(phoneNumber, code) {
|
|
19361
|
+
assertBrowserAuthEnv('verifyTextOtp');
|
|
19362
|
+
await activateEmailProvider();
|
|
19363
|
+
return verifyTextOtp$1(phoneNumber, code);
|
|
19364
|
+
}
|
|
21505
19365
|
/**
|
|
21506
19366
|
* UPGRADE the current anonymous (guest) session by linking an email — Firebase
|
|
21507
19367
|
* `linkWithCredential` parity. Send the code first with `sendEmailOtp(email)`,
|
|
@@ -21719,6 +19579,12 @@ async function logout() {
|
|
|
21719
19579
|
setCurrentUser(null);
|
|
21720
19580
|
}
|
|
21721
19581
|
var hasRunFirstTime = false;
|
|
19582
|
+
function userPrincipalKey(user) {
|
|
19583
|
+
var _a, _b, _c;
|
|
19584
|
+
if (!user)
|
|
19585
|
+
return null;
|
|
19586
|
+
return (_c = (_b = (_a = user.id) !== null && _a !== void 0 ? _a : user.address) !== null && _b !== void 0 ? _b : user.email) !== null && _c !== void 0 ? _c : null;
|
|
19587
|
+
}
|
|
21722
19588
|
// Update the currentUser and notify listeners
|
|
21723
19589
|
function setCurrentUser(user) {
|
|
21724
19590
|
// Enrich with the universal identity fields (id/email) derived from the
|
|
@@ -21728,7 +19594,9 @@ function setCurrentUser(user) {
|
|
|
21728
19594
|
user = withUserIdentity(user);
|
|
21729
19595
|
const lastUser = currentUser;
|
|
21730
19596
|
const wasInitializedBefore = hasRunFirstTime;
|
|
21731
|
-
const
|
|
19597
|
+
const lastPrincipal = userPrincipalKey(currentUser);
|
|
19598
|
+
const nextPrincipal = userPrincipalKey(user);
|
|
19599
|
+
const shouldRunListeners = !hasRunFirstTime || lastPrincipal !== nextPrincipal;
|
|
21732
19600
|
hasRunFirstTime = true;
|
|
21733
19601
|
currentUser = user;
|
|
21734
19602
|
if (shouldRunListeners) {
|
|
@@ -21736,7 +19604,7 @@ function setCurrentUser(user) {
|
|
|
21736
19604
|
// Reconnect WebSocket connections with new auth when user changes.
|
|
21737
19605
|
// Skip on the first setCurrentUser call during init() — there are no
|
|
21738
19606
|
// existing connections to reconnect at that point.
|
|
21739
|
-
if (wasInitializedBefore && (lastUser
|
|
19607
|
+
if (wasInitializedBefore && userPrincipalKey(lastUser) !== nextPrincipal) {
|
|
21740
19608
|
reconnectWithNewAuth().catch((error) => {
|
|
21741
19609
|
console.error('Error reconnecting WebSocket after auth change:', error);
|
|
21742
19610
|
});
|
|
@@ -22315,6 +20183,7 @@ exports.runQuery = runQuery;
|
|
|
22315
20183
|
exports.runQueryMany = runQueryMany;
|
|
22316
20184
|
exports.search = search;
|
|
22317
20185
|
exports.sendEmailOtp = sendEmailOtp;
|
|
20186
|
+
exports.sendTextOtp = sendTextOtp;
|
|
22318
20187
|
exports.serverTimestamp = serverTimestamp;
|
|
22319
20188
|
exports.set = set;
|
|
22320
20189
|
exports.setAuthLoading = setAuthLoading;
|
|
@@ -22334,10 +20203,11 @@ exports.toMillis = toMillis;
|
|
|
22334
20203
|
exports.toSeconds = toSeconds;
|
|
22335
20204
|
exports.useAuth = useAuth;
|
|
22336
20205
|
exports.verifyEmailOtp = verifyEmailOtp;
|
|
20206
|
+
exports.verifyTextOtp = verifyTextOtp;
|
|
22337
20207
|
exports.withEffects = withEffects;
|
|
22338
20208
|
exports.wsDelete = wsDelete;
|
|
22339
20209
|
exports.wsGet = wsGet;
|
|
22340
20210
|
exports.wsGetMany = wsGetMany;
|
|
22341
20211
|
exports.wsQuery = wsQuery;
|
|
22342
20212
|
exports.wsSet = wsSet;
|
|
22343
|
-
//# sourceMappingURL=index.native-
|
|
20213
|
+
//# sourceMappingURL=index.native-C-duG1XV.js.map
|