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