@bounded-sh/client 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/auth/providers/phantom-wallet-provider.d.ts +1 -1
  2. package/dist/auth/providers/privy-expo-provider.d.ts +1 -1
  3. package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +3 -3
  4. package/dist/{index-VGx-869x.js → index-2UpSvA7V.js} +2586 -124
  5. package/dist/index-2UpSvA7V.js.map +1 -0
  6. package/dist/{index-C1VOdmRN.js → index-C2JpxGAC.js} +1202 -450
  7. package/dist/index-C2JpxGAC.js.map +1 -0
  8. package/dist/{index-CT2j1oic.esm.js → index-C2yvle9S.esm.js} +1202 -450
  9. package/dist/index-C2yvle9S.esm.js.map +1 -0
  10. package/dist/{index-sKqrgk0t.js → index-CYVVTWs4.js} +1202 -450
  11. package/dist/index-CYVVTWs4.js.map +1 -0
  12. package/dist/{index-BHTfW8CV.esm.js → index-DJg-Dduo.esm.js} +1202 -450
  13. package/dist/index-DJg-Dduo.esm.js.map +1 -0
  14. package/dist/{index-o5Hv9pfS.esm.js → index-DyfiK3_X.esm.js} +2585 -124
  15. package/dist/index-DyfiK3_X.esm.js.map +1 -0
  16. package/dist/{index.browser-BJZ7fYwv.js → index.browser-BTJZmhY1.js} +766 -773
  17. package/dist/index.browser-BTJZmhY1.js.map +1 -0
  18. package/dist/{index.browser-DaNhOhkQ.esm.js → index.browser-C_TToxuO.esm.js} +230 -242
  19. package/dist/index.browser-C_TToxuO.esm.js.map +1 -0
  20. package/dist/{index.browser-utVKQsEC.js → index.browser-DcHalmEf.js} +230 -242
  21. package/dist/index.browser-DcHalmEf.js.map +1 -0
  22. package/dist/{index.browser-DhAcjdpV.esm.js → index.browser-pymH6o1X.esm.js} +766 -773
  23. package/dist/index.browser-pymH6o1X.esm.js.map +1 -0
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.esm.js +1 -1
  26. package/dist/index.js +2 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/{index.native-JPUkdHJj.esm.js → index.native-BTjBgNiE.esm.js} +2556 -95
  29. package/dist/index.native-BTjBgNiE.esm.js.map +1 -0
  30. package/dist/{index.native-B5IBOdv_.js → index.native-BvsmNFXn.js} +2557 -95
  31. package/dist/index.native-BvsmNFXn.js.map +1 -0
  32. package/dist/index.native.d.ts +1 -1
  33. package/dist/index.native.esm.js +1 -1
  34. package/dist/index.native.js +2 -1
  35. package/dist/index.native.js.map +1 -1
  36. package/dist/{phantom-wallet-provider-CDLyxrih.js → phantom-wallet-provider-BXMvoOrI.js} +10 -10
  37. package/dist/phantom-wallet-provider-BXMvoOrI.js.map +1 -0
  38. package/dist/{phantom-wallet-provider-DMlaSrAl.esm.js → phantom-wallet-provider-CTossIFB.esm.js} +10 -10
  39. package/dist/phantom-wallet-provider-CTossIFB.esm.js.map +1 -0
  40. package/dist/{privy-wallet-provider-nR52lXzI.esm.js → privy-wallet-provider-1qE_f-DF.esm.js} +6 -6
  41. package/dist/privy-wallet-provider-1qE_f-DF.esm.js.map +1 -0
  42. package/dist/{privy-wallet-provider-DiHHTDbZ.js → privy-wallet-provider-D64DJ3u4.js} +6 -6
  43. package/dist/privy-wallet-provider-D64DJ3u4.js.map +1 -0
  44. package/dist/{solana-mobile-wallet-provider-B4CeMMQd.esm.js → solana-mobile-wallet-provider-9M8U6AA7.esm.js} +22 -22
  45. package/dist/solana-mobile-wallet-provider-9M8U6AA7.esm.js.map +1 -0
  46. package/dist/{solana-mobile-wallet-provider-BYMfFjZb.js → solana-mobile-wallet-provider-C1wQ1DRK.js} +22 -22
  47. package/dist/solana-mobile-wallet-provider-C1wQ1DRK.js.map +1 -0
  48. package/package.json +2 -2
  49. package/dist/index-BHTfW8CV.esm.js.map +0 -1
  50. package/dist/index-C1VOdmRN.js.map +0 -1
  51. package/dist/index-CT2j1oic.esm.js.map +0 -1
  52. package/dist/index-VGx-869x.js.map +0 -1
  53. package/dist/index-o5Hv9pfS.esm.js.map +0 -1
  54. package/dist/index-sKqrgk0t.js.map +0 -1
  55. package/dist/index.browser-BJZ7fYwv.js.map +0 -1
  56. package/dist/index.browser-DaNhOhkQ.esm.js.map +0 -1
  57. package/dist/index.browser-DhAcjdpV.esm.js.map +0 -1
  58. package/dist/index.browser-utVKQsEC.js.map +0 -1
  59. package/dist/index.native-B5IBOdv_.js.map +0 -1
  60. package/dist/index.native-JPUkdHJj.esm.js.map +0 -1
  61. package/dist/phantom-wallet-provider-CDLyxrih.js.map +0 -1
  62. package/dist/phantom-wallet-provider-DMlaSrAl.esm.js.map +0 -1
  63. package/dist/privy-wallet-provider-DiHHTDbZ.js.map +0 -1
  64. package/dist/privy-wallet-provider-nR52lXzI.esm.js.map +0 -1
  65. package/dist/solana-mobile-wallet-provider-B4CeMMQd.esm.js.map +0 -1
  66. package/dist/solana-mobile-wallet-provider-BYMfFjZb.js.map +0 -1
@@ -16,7 +16,7 @@ function commonjsRequire(path) {
16
16
  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.');
17
17
  }
18
18
 
19
- var naclFast = {exports: {}};
19
+ var naclFast$1 = {exports: {}};
20
20
 
21
21
  var _nodeResolve_empty = {};
22
22
 
@@ -27,11 +27,11 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
27
27
 
28
28
  var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
29
29
 
30
- var hasRequiredNaclFast;
30
+ var hasRequiredNaclFast$1;
31
31
 
32
- function requireNaclFast () {
33
- if (hasRequiredNaclFast) return naclFast.exports;
34
- hasRequiredNaclFast = 1;
32
+ function requireNaclFast$1 () {
33
+ if (hasRequiredNaclFast$1) return naclFast$1.exports;
34
+ hasRequiredNaclFast$1 = 1;
35
35
  (function (module) {
36
36
  (function(nacl) {
37
37
 
@@ -2423,12 +2423,12 @@ function requireNaclFast () {
2423
2423
  })();
2424
2424
 
2425
2425
  })(module.exports ? module.exports : (self.nacl = self.nacl || {}));
2426
- } (naclFast));
2427
- return naclFast.exports;
2426
+ } (naclFast$1));
2427
+ return naclFast$1.exports;
2428
2428
  }
2429
2429
 
2430
- var naclFastExports = requireNaclFast();
2431
- var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
2430
+ var naclFastExports$1 = requireNaclFast$1();
2431
+ var nacl$1 = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports$1);
2432
2432
 
2433
2433
  var bn$1 = {exports: {}};
2434
2434
 
@@ -6448,7 +6448,7 @@ function getWebhookKeysUrl() {
6448
6448
  /**
6449
6449
  * True when init() configured a Bounded network (the Cloudflare-native stack).
6450
6450
  * Synchronous + non-blocking. Used to route reads/writes that behave differently
6451
- * on Bounded vs the legacy Tarobase backend (e.g. `count`/`aggregate`, which on
6451
+ * on Bounded vs the legacy backend (e.g. `count`/`aggregate`, which on
6452
6452
  * Bounded must use the deterministic server aggregation, not the legacy AI query).
6453
6453
  */
6454
6454
  function isBoundedNetwork() {
@@ -9303,7 +9303,7 @@ class WebSessionManager {
9303
9303
  // the RIGHT /session/refresh. Email overrides with humanAuthApiUrl; all
9304
9304
  // wallet/guest/signature flows default to authApiUrl (the bounded-auth issuer).
9305
9305
  const sessionIssuer = (issuer || config.authApiUrl || "").replace(/\/$/, "");
9306
- localStorage.setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9306
+ localStorage.setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9307
9307
  accessToken,
9308
9308
  idToken,
9309
9309
  refreshToken, appId: currentAppId }, (sessionIssuer ? { issuer: sessionIssuer } : {}))));
@@ -9314,7 +9314,7 @@ class WebSessionManager {
9314
9314
  static async getSession() {
9315
9315
  if (typeof window === "undefined")
9316
9316
  return null;
9317
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9317
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9318
9318
  if (!session)
9319
9319
  return null;
9320
9320
  const sessionObj = JSON.parse(session);
@@ -9338,7 +9338,7 @@ class WebSessionManager {
9338
9338
  // Persist the ROTATED refresh token — the old one is now
9339
9339
  // single-use spent; reusing it would revoke the family.
9340
9340
  refreshed.refreshToken);
9341
- const newSession = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9341
+ const newSession = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9342
9342
  if (!newSession)
9343
9343
  return null;
9344
9344
  const newObj = JSON.parse(newSession);
@@ -9362,14 +9362,14 @@ class WebSessionManager {
9362
9362
  static clearSession() {
9363
9363
  if (typeof window === "undefined")
9364
9364
  return;
9365
- localStorage.removeItem(this.TAROBASE_SESSION_STORAGE_KEY);
9365
+ localStorage.removeItem(this.BOUNDED_SESSION_STORAGE_KEY);
9366
9366
  }
9367
9367
  /* ------------------------------------------------------------------ */
9368
9368
  /* IS-AUTH */
9369
9369
  /* ------------------------------------------------------------------ */
9370
9370
  static isAuthenticated() {
9371
9371
  // NOTE: this remains synchronous to stay backward compatible
9372
- return !!localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9372
+ return !!localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9373
9373
  }
9374
9374
  /* ------------------------------------------------------------------ */
9375
9375
  /* TOKEN HELPERS */
@@ -9377,13 +9377,13 @@ class WebSessionManager {
9377
9377
  static getIdToken() {
9378
9378
  if (typeof window === "undefined")
9379
9379
  return null;
9380
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9380
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9381
9381
  return session ? JSON.parse(session).idToken : null;
9382
9382
  }
9383
9383
  static getRefreshToken() {
9384
9384
  if (typeof window === "undefined")
9385
9385
  return null;
9386
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9386
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9387
9387
  return session ? JSON.parse(session).refreshToken : null;
9388
9388
  }
9389
9389
  /** The issuer base that minted this session (for routing silent refresh). */
@@ -9391,7 +9391,7 @@ class WebSessionManager {
9391
9391
  var _a;
9392
9392
  if (typeof window === "undefined")
9393
9393
  return null;
9394
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9394
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9395
9395
  return session ? ((_a = JSON.parse(session).issuer) !== null && _a !== void 0 ? _a : null) : null;
9396
9396
  }
9397
9397
  /* ------------------------------------------------------------------ */
@@ -9401,7 +9401,7 @@ class WebSessionManager {
9401
9401
  var _a;
9402
9402
  if (typeof window === "undefined")
9403
9403
  return;
9404
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9404
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9405
9405
  if (!session)
9406
9406
  return;
9407
9407
  const sessionObj = JSON.parse(session);
@@ -9418,10 +9418,10 @@ class WebSessionManager {
9418
9418
  sessionObj.refreshToken = refreshToken;
9419
9419
  }
9420
9420
  (_a = sessionObj.appId) !== null && _a !== void 0 ? _a : (sessionObj.appId = config.appId);
9421
- localStorage.setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9421
+ localStorage.setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9422
9422
  }
9423
9423
  }
9424
- WebSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
9424
+ WebSessionManager.BOUNDED_SESSION_STORAGE_KEY = "bounded_session_storage";
9425
9425
 
9426
9426
  let _config = null;
9427
9427
  class ReactNativeSessionManager {
@@ -9514,7 +9514,7 @@ class ReactNativeSessionManager {
9514
9514
  // Issuer base for silent refresh (email overrides w/ humanAuthApiUrl; wallet/
9515
9515
  // guest default to authApiUrl). See WebSessionManager for the rationale.
9516
9516
  const sessionIssuer = (issuer || config.authApiUrl || "").replace(/\/$/, "");
9517
- this.getStorage().setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9517
+ this.getStorage().setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9518
9518
  accessToken,
9519
9519
  idToken,
9520
9520
  refreshToken, appId: currentAppId }, (sessionIssuer ? { issuer: sessionIssuer } : {}))));
@@ -9523,7 +9523,7 @@ class ReactNativeSessionManager {
9523
9523
  /* GET */
9524
9524
  /* ------------------------------------------------------------------ */
9525
9525
  static async getSession() {
9526
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9526
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9527
9527
  if (!session)
9528
9528
  return null;
9529
9529
  const sessionObj = JSON.parse(session);
@@ -9544,7 +9544,7 @@ class ReactNativeSessionManager {
9544
9544
  const refreshed = await refreshSession(refreshToken, sessionObj.issuer);
9545
9545
  if ((refreshed === null || refreshed === void 0 ? void 0 : refreshed.idToken) && (refreshed === null || refreshed === void 0 ? void 0 : refreshed.accessToken)) {
9546
9546
  await this.updateIdTokenAndAccessToken(refreshed.idToken, refreshed.accessToken, refreshed.refreshToken);
9547
- const newSession = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9547
+ const newSession = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9548
9548
  if (!newSession)
9549
9549
  return null;
9550
9550
  const newObj = JSON.parse(newSession);
@@ -9566,20 +9566,20 @@ class ReactNativeSessionManager {
9566
9566
  /* CLEAR */
9567
9567
  /* ------------------------------------------------------------------ */
9568
9568
  static clearSession() {
9569
- this.getStorage().removeItem(this.TAROBASE_SESSION_STORAGE_KEY);
9569
+ this.getStorage().removeItem(this.BOUNDED_SESSION_STORAGE_KEY);
9570
9570
  }
9571
9571
  /* ------------------------------------------------------------------ */
9572
9572
  /* IS-AUTH */
9573
9573
  /* ------------------------------------------------------------------ */
9574
9574
  static isAuthenticated() {
9575
- return !!this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9575
+ return !!this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9576
9576
  }
9577
9577
  /* ------------------------------------------------------------------ */
9578
9578
  /* TOKEN HELPERS */
9579
9579
  /* ------------------------------------------------------------------ */
9580
9580
  static getIdToken() {
9581
9581
  try {
9582
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9582
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9583
9583
  return session ? JSON.parse(session).idToken : null;
9584
9584
  }
9585
9585
  catch (_a) {
@@ -9590,7 +9590,7 @@ class ReactNativeSessionManager {
9590
9590
  static getIssuer() {
9591
9591
  var _a;
9592
9592
  try {
9593
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9593
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9594
9594
  return session ? ((_a = JSON.parse(session).issuer) !== null && _a !== void 0 ? _a : null) : null;
9595
9595
  }
9596
9596
  catch (_b) {
@@ -9599,7 +9599,7 @@ class ReactNativeSessionManager {
9599
9599
  }
9600
9600
  static getRefreshToken() {
9601
9601
  try {
9602
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9602
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9603
9603
  return session ? JSON.parse(session).refreshToken : null;
9604
9604
  }
9605
9605
  catch (_a) {
@@ -9611,7 +9611,7 @@ class ReactNativeSessionManager {
9611
9611
  /* ------------------------------------------------------------------ */
9612
9612
  static async updateIdTokenAndAccessToken(idToken, accessToken, refreshToken) {
9613
9613
  var _a;
9614
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9614
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9615
9615
  if (!session)
9616
9616
  return;
9617
9617
  const sessionObj = JSON.parse(session);
@@ -9627,10 +9627,10 @@ class ReactNativeSessionManager {
9627
9627
  sessionObj.refreshToken = refreshToken;
9628
9628
  }
9629
9629
  (_a = sessionObj.appId) !== null && _a !== void 0 ? _a : (sessionObj.appId = config.appId);
9630
- this.getStorage().setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9630
+ this.getStorage().setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9631
9631
  }
9632
9632
  }
9633
- ReactNativeSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
9633
+ ReactNativeSessionManager.BOUNDED_SESSION_STORAGE_KEY = "bounded_session_storage";
9634
9634
 
9635
9635
  /**
9636
9636
  * Return the active CLIENT session manager for the current runtime.
@@ -10151,9 +10151,9 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
10151
10151
  /* ENV helpers */
10152
10152
  /* ------------------------------------------------------------------ */
10153
10153
  // Canonical `BOUNDED_PRIVATE_KEY` (matches the CLI); legacy
10154
- // `TAROBASE_SOLANA_KEYPAIR` still honored. Only consulted when no explicit
10154
+ // `BOUNDED_SOLANA_KEYPAIR` still honored. Only consulted when no explicit
10155
10155
  // keypair was provided (createWalletClient passes one).
10156
- const ENV_KEYPAIRS = ["BOUNDED_PRIVATE_KEY", "TAROBASE_SOLANA_KEYPAIR"];
10156
+ const ENV_KEYPAIRS = ["BOUNDED_PRIVATE_KEY", "BOUNDED_SOLANA_KEYPAIR"];
10157
10157
  function loadKeypairFromEnv() {
10158
10158
  let secret;
10159
10159
  let found;
@@ -10211,7 +10211,7 @@ class ServerSessionManager {
10211
10211
  const nonce = await genAuthNonce();
10212
10212
  const message = await genSolanaMessage(address, nonce);
10213
10213
  /* sign the message */
10214
- const sigBytes = nacl.sign.detached(new TextEncoder().encode(message), kp.secretKey);
10214
+ const sigBytes = nacl$1.sign.detached(new TextEncoder().encode(message), kp.secretKey);
10215
10215
  const signature = bufferExports$1.Buffer.from(sigBytes).toString("base64");
10216
10216
  /* call auth API */
10217
10217
  const { accessToken, idToken, refreshToken, } = await createSessionWithSignature(address, message, signature);
@@ -10276,7 +10276,7 @@ var serverSessionManager = /*#__PURE__*/Object.freeze({
10276
10276
  });
10277
10277
 
10278
10278
  /**
10279
- * Safe base64 helpers for tarobase-core.
10279
+ * Safe base64 helpers for bounded-core.
10280
10280
  *
10281
10281
  * Uses the global atob/btoa when available (browser, RN with polyfill),
10282
10282
  * falls back to the 'buffer' package (Node.js / SSR / RN without polyfill).
@@ -10456,7 +10456,7 @@ axiosRetry(apiClient, {
10456
10456
  shouldResetTimeout: true,
10457
10457
  onRetry: (retryCount, error, requestConfig) => {
10458
10458
  var _a;
10459
- console.warn(`[tarobase-sdk] retry ${retryCount} for ${(_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${requestConfig.url} — ${error.code || error.message}`);
10459
+ console.warn(`[bounded-sdk] retry ${retryCount} for ${(_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${requestConfig.url} — ${error.code || error.message}`);
10460
10460
  },
10461
10461
  });
10462
10462
  const refreshInFlight = new Map();
@@ -10515,8 +10515,8 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
10515
10515
  : await createAuthHeader(config.isServer);
10516
10516
  const headers = Object.assign({ "Content-Type": "application/json", "X-Public-App-Id": config.appId, "X-App-Id": config.appId }, authHeader);
10517
10517
  if (typeof window !== "undefined" &&
10518
- window.CUSTOM_TAROBASE_APP_ID_HEADER) {
10519
- const customAppId = window.CUSTOM_TAROBASE_APP_ID_HEADER;
10518
+ window.CUSTOM_BOUNDED_APP_ID_HEADER) {
10519
+ const customAppId = window.CUSTOM_BOUNDED_APP_ID_HEADER;
10520
10520
  if (customAppId) {
10521
10521
  headers["X-App-Id"] = customAppId;
10522
10522
  }
@@ -10775,7 +10775,7 @@ function parseAggregateValue(result) {
10775
10775
  * Count items in a collection path. Returns a numeric result.
10776
10776
  *
10777
10777
  * This uses the AI query engine with a count-specific prompt prefix,
10778
- * so TaroBase will generate a $count aggregation pipeline and return
10778
+ * so Bounded will generate a $count aggregation pipeline and return
10779
10779
  * just the count rather than full documents.
10780
10780
  *
10781
10781
  * IMPORTANT: This only works for collections where the read policy is "true".
@@ -11282,6 +11282,13 @@ async function runExpressionMany(many) {
11282
11282
  throw error;
11283
11283
  }
11284
11284
  }
11285
+ /**
11286
+ * Write a document at `path`. Sugar for a one-element {@link setMany}.
11287
+ *
11288
+ * **Delete:** pass `null` as the document to delete it — `set(path, null)` is
11289
+ * the delete (there is no separate `del`/`remove`). It is routed through the
11290
+ * collection's policy `delete` rule and broadcasts a delete to subscribers.
11291
+ */
11285
11292
  async function set(path, document, options) {
11286
11293
  const result = await setMany([{ path, document }], options);
11287
11294
  // Clear cache entries that might be affected by this update
@@ -11300,10 +11307,10 @@ async function setMany(many, options) {
11300
11307
  let documents = [];
11301
11308
  const pathsToInvalidate = new Set();
11302
11309
  for (const { path, document: documentWithReservedFields } of many) {
11303
- // for setting, we should remove any pieces of the document that start with 'tarobase_' as they are internal and shouldn't be updated. The API would block it if it is one of the reserved ones
11310
+ // for setting, we should remove any pieces of the document that start with '_' as they are internal and shouldn't be updated. The API would block it if it is one of the reserved ones
11304
11311
  let document = documentWithReservedFields;
11305
11312
  if (documentWithReservedFields) {
11306
- document = Object.fromEntries(Object.entries(documentWithReservedFields).filter(([key]) => !key.startsWith('tarobase_')));
11313
+ document = Object.fromEntries(Object.entries(documentWithReservedFields).filter(([key]) => !key.startsWith('_')));
11307
11314
  }
11308
11315
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
11309
11316
  pathsToInvalidate.add(normalizedPath);
@@ -11427,7 +11434,7 @@ async function setMany(many, options) {
11427
11434
  var _a, _b, _c, _d, _e;
11428
11435
  // NOTE (backwards-compat revert): a program-allowlist on server-supplied
11429
11436
  // `preInstructions` was tried here for the audit-8 SOL-drain concern, but it
11430
- // broke legitimate onchain DeFi flows — tarobase routes Phoenix, Jupiter/swap,
11437
+ // broke legitimate onchain DeFi flows — bounded routes Phoenix, Jupiter/swap,
11431
11438
  // SPL-Token and ATA-creation instructions through standard-path preInstructions
11432
11439
  // (see sol-helper remaining-accounts-extractor). A correct audit-8 fix must be
11433
11440
  // DeFi-aware (e.g. block ONLY a raw System Transfer/TransferWithSeed, never a
@@ -11511,10 +11518,10 @@ async function setMany(many, options) {
11511
11518
  const transaction = VersionedTransaction.deserialize(txBytes);
11512
11519
  // Validate the transaction before signing: ensure only allowed programs
11513
11520
  // and no unauthorized System program instructions (e.g., SOL transfers)
11514
- const TAROBASE_PROGRAM = 'poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp';
11521
+ const BOUNDED_PROGRAM = 'poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp';
11515
11522
  const COMPUTE_BUDGET = 'ComputeBudget111111111111111111111111111111';
11516
11523
  const SYSTEM_PROGRAM = '11111111111111111111111111111111';
11517
- const ALLOWED_PROGRAMS = new Set([TAROBASE_PROGRAM, COMPUTE_BUDGET, SYSTEM_PROGRAM]);
11524
+ const ALLOWED_PROGRAMS = new Set([BOUNDED_PROGRAM, COMPUTE_BUDGET, SYSTEM_PROGRAM]);
11518
11525
  // System program instruction discriminators (first 4 bytes, little-endian u32)
11519
11526
  const SYSTEM_TRANSFER = 2; // Transfer instruction index
11520
11527
  const SYSTEM_TRANSFER_WITH_SEED = 11;
@@ -12108,8 +12115,8 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
12108
12115
  if (appId && appId !== config.appId) {
12109
12116
  wsUrl.searchParams.append('appId', appId);
12110
12117
  }
12111
- else if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
12112
- wsUrl.searchParams.append('appId', window.CUSTOM_TAROBASE_APP_ID_HEADER);
12118
+ else if (typeof window !== 'undefined' && window.CUSTOM_BOUNDED_APP_ID_HEADER) {
12119
+ wsUrl.searchParams.append('appId', window.CUSTOM_BOUNDED_APP_ID_HEADER);
12113
12120
  }
12114
12121
  else {
12115
12122
  wsUrl.searchParams.append('appId', config.appId);
@@ -12969,7 +12976,7 @@ function serverTimestamp() {
12969
12976
  // ---------------------------------------------------------------------------
12970
12977
  // IDB helpers (lazy-loaded, non-blocking)
12971
12978
  // ---------------------------------------------------------------------------
12972
- const IDB_NAME$1 = 'tarobase-realtime';
12979
+ const IDB_NAME$1 = 'bounded-realtime';
12973
12980
  const IDB_STORE$1 = 'subscriptions';
12974
12981
  const IDB_VERSION = 1;
12975
12982
  let idbPromise = null;
@@ -13407,10 +13414,10 @@ class RealtimeStore {
13407
13414
  const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
13408
13415
  const collectionPath = this.getCollectionPath(normalizedPath);
13409
13416
  const optimisticDoc = Object.assign(Object.assign({ _id: normalizedPath, pathId: normalizedPath }, resolvedDoc), {
13410
- // System timestamp field name differs by stack: the Bounded worker stamps
13411
- // the neutral `_updatedAt`; legacy Tarobase stamps `tarobase_updated_at`.
13417
+ // System timestamp field name: the Bounded worker stamps the neutral
13418
+ // `_updatedAt`; the underscore-prefixed `_updated_at` metadata mirror.
13412
13419
  // Match it so the optimistic doc lines up with the server's confirmation.
13413
- [isBoundedNetwork() ? '_updatedAt' : 'tarobase_updated_at']: Date.now() });
13420
+ [isBoundedNetwork() ? '_updatedAt' : '_updated_at']: Date.now() });
13414
13421
  const sub = this.findSubscriptionByPath(collectionPath);
13415
13422
  let prevDoc = null;
13416
13423
  if (sub) {
@@ -13863,6 +13870,7 @@ const functions = { invoke };
13863
13870
  // collection. This file is the consumer surface around that runtime:
13864
13871
  //
13865
13872
  // bounded.live.intent(roomPath, intent) -> POST {realtime}/live/intent
13873
+ // bounded.live.status(roomPath) -> GET {realtime}/live/status
13866
13874
  //
13867
13875
  // It mirrors `functions.invoke` exactly: it attaches the caller's session token
13868
13876
  // AUTOMATICALLY (the same token the SDK uses for data reads/writes), and throws
@@ -13875,18 +13883,14 @@ const functions = { invoke };
13875
13883
  // Addressing: clients address rooms BY PATH (the `path` field in the body). The
13876
13884
  // worker derives the roomId from `body.path` and sets X-Room-Id internally;
13877
13885
  // clients NEVER set X-Room-Id. The caller's address is taken server-side from
13878
- // the Authorization header (auth.userAddress) — it is NOT sent in the body.
13886
+ // the Authorization header (auth.userId/userAddress) — it is NOT sent in the
13887
+ // body.
13879
13888
  //
13880
13889
  // Subscribing to your view: a per-player view doc lives at
13881
- // `<roomPath>/view/<myAddress>` (the policy declares
13882
- // `rooms/$roomId/view/$addr` ephemeral with `read: $addr == @user.address`).
13883
- // That path has an EVEN segment count, so it is an ordinary document path —
13884
- // plain `subscribe('<roomPath>/view/<myAddress>', { onData })` already works.
13885
- // `subscribeView()` below is thin sugar over that (path construction + address
13886
- // defaulting); it adds zero new transport.
13887
- //
13888
- // Status polling (GET /live/status?path=<sessionCollection>/<roomId>) is out of
13889
- // scope for this piece — see follow-up.
13890
+ // `<roomPath>/view/<myUserId>` (the policy declares
13891
+ // `rooms/$roomId/view/$userId` ephemeral with `read: $userId == @user.id`).
13892
+ // Wallet-address keyed view paths remain supported through opts.address for
13893
+ // older policies, but new live rooms should key views by @user.id.
13890
13894
  // ---------------------------------------------------------------------------
13891
13895
  class LiveIntentError extends Error {
13892
13896
  constructor(message, statusCode, details) {
@@ -13967,7 +13971,7 @@ async function intent(roomPath, intent, opts = {}) {
13967
13971
  res = await fetch(`${base}/live/intent`, {
13968
13972
  method: 'POST',
13969
13973
  headers,
13970
- body: JSON.stringify({ path: roomPath, intent }),
13974
+ body: JSON.stringify({ path: normalizedRoomPath, intent }),
13971
13975
  signal: controller.signal,
13972
13976
  });
13973
13977
  }
@@ -13995,43 +13999,95 @@ async function intent(roomPath, intent, opts = {}) {
13995
13999
  }
13996
14000
  return (body !== null && body !== void 0 ? body : { ok: true });
13997
14001
  }
14002
+ /**
14003
+ * Fetch the runtime status for a live room.
14004
+ *
14005
+ * const s = await bounded.live.status('rooms/abc');
14006
+ * console.log(s.running, s.stopReason, s.generation, s.etag);
14007
+ *
14008
+ * This is diagnostic/ops surface. It reports whether the room facet exists,
14009
+ * whether it is currently ticking, why it last stopped, which module etag is
14010
+ * loaded, and the current generation used after terminal restarts.
14011
+ */
14012
+ async function status(roomPath, opts = {}) {
14013
+ var _a, _b, _c, _d, _e;
14014
+ if (!roomPath || typeof roomPath !== 'string') {
14015
+ throw new LiveIntentError('A room path is required');
14016
+ }
14017
+ const normalizedRoomPath = roomPath.replace(/\/$/, '');
14018
+ const config = await getConfig();
14019
+ const base = realtimeHttpBase(config.wsApiUrl);
14020
+ const headers = Object.assign({ 'X-App-Id': config.appId, 'X-Public-App-Id': config.appId }, ((_a = opts.headers) !== null && _a !== void 0 ? _a : {}));
14021
+ const controller = new AbortController();
14022
+ const timeoutMs = (_b = opts.timeoutMs) !== null && _b !== void 0 ? _b : 15000;
14023
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
14024
+ let res;
14025
+ try {
14026
+ res = await fetch(`${base}/live/status?path=${encodeURIComponent(normalizedRoomPath)}`, {
14027
+ method: 'GET',
14028
+ headers,
14029
+ signal: controller.signal,
14030
+ });
14031
+ }
14032
+ catch (err) {
14033
+ clearTimeout(timer);
14034
+ if ((err === null || err === void 0 ? void 0 : err.name) === 'AbortError') {
14035
+ throw new LiveIntentError(`Live status for "${normalizedRoomPath}" timed out after ${timeoutMs}ms`);
14036
+ }
14037
+ throw new LiveIntentError(`Failed to reach the realtime worker: ${(_c = err === null || err === void 0 ? void 0 : err.message) !== null && _c !== void 0 ? _c : String(err)}`);
14038
+ }
14039
+ clearTimeout(timer);
14040
+ let body = null;
14041
+ const text = await res.text();
14042
+ if (text) {
14043
+ try {
14044
+ body = JSON.parse(text);
14045
+ }
14046
+ catch (_f) {
14047
+ body = { raw: text };
14048
+ }
14049
+ }
14050
+ if (!res.ok) {
14051
+ const message = (_e = (_d = body === null || body === void 0 ? void 0 : body.error) !== null && _d !== void 0 ? _d : body === null || body === void 0 ? void 0 : body.message) !== null && _e !== void 0 ? _e : `Live status failed with HTTP ${res.status}`;
14052
+ throw new LiveIntentError(message, res.status, body);
14053
+ }
14054
+ return body;
14055
+ }
13998
14056
  /**
13999
14057
  * Subscribe to YOUR per-player view of a room. Thin sugar over:
14000
14058
  *
14001
- * subscribe('<roomPath>/view/<myAddress>', { onData, onError })
14059
+ * subscribe('<roomPath>/view/<myUserId>', { onData, onError })
14002
14060
  *
14003
- * The address defaults to the logged-in user's address (from the session
14004
- * token's claims); pass `opts.address` to override. Returns the unsubscribe
14061
+ * The view id defaults to the logged-in user's @user.id (from the session token
14062
+ * claims); pass `opts.userId` to override. `opts.address` is kept as a legacy
14063
+ * alias for older wallet-address keyed policies. Returns the unsubscribe
14005
14064
  * function (a Promise<() => Promise<void>>, same as `subscribe`).
14006
14065
  *
14007
14066
  * Note: this is a browser-first helper (the WS subscription manager is
14008
14067
  * browser-oriented). Server consumers should use `live.intent`.
14009
14068
  */
14010
14069
  async function subscribeView(roomPath, opts) {
14011
- var _a;
14070
+ var _a, _b, _c;
14012
14071
  if (!roomPath || typeof roomPath !== 'string') {
14013
14072
  throw new LiveIntentError('A room path is required');
14014
14073
  }
14015
14074
  if (!opts || typeof opts.onData !== 'function') {
14016
14075
  throw new LiveIntentError('subscribeView requires an onData callback');
14017
14076
  }
14018
- let address = opts.address;
14019
- if (!address) {
14077
+ let viewUserId = (_a = opts.userId) !== null && _a !== void 0 ? _a : opts.address;
14078
+ if (!viewUserId) {
14020
14079
  const config = await getConfig();
14021
14080
  const info = await getUserInfo(config.isServer);
14022
- // getUserInfo returns the RAW idToken payload — the wallet address lives in
14023
- // the `custom:walletAddress` claim, NOT a flat `address` field. Reading only
14024
- // `.address` meant auto-resolution NEVER worked, forcing every caller (browser
14025
- // AND server) to pass opts.address — the client having to hand the backend an
14026
- // identity it already authenticated. Resolve it from the actual claim so a
14027
- // logged-in caller never needs to pass its own address.
14028
- address = (_a = info === null || info === void 0 ? void 0 : info.address) !== null && _a !== void 0 ? _a : info === null || info === void 0 ? void 0 : info['custom:walletAddress'];
14081
+ // getUserInfo returns the RAW idToken payload. The universal live view key
14082
+ // is @user.id (`custom:userId`); wallet-address keyed views are still
14083
+ // resolved as a compatibility fallback for older policies.
14084
+ viewUserId = (_c = (_b = info === null || info === void 0 ? void 0 : info['custom:userId']) !== null && _b !== void 0 ? _b : info === null || info === void 0 ? void 0 : info['custom:walletAddress']) !== null && _c !== void 0 ? _c : info === null || info === void 0 ? void 0 : info.address;
14029
14085
  }
14030
- if (!address || typeof address !== 'string') {
14031
- throw new LiveIntentError('Could not resolve a player address for subscribeView; pass opts.address or log in first');
14086
+ if (!viewUserId || typeof viewUserId !== 'string') {
14087
+ throw new LiveIntentError('Could not resolve a player view id for subscribeView; pass opts.userId or log in first');
14032
14088
  }
14033
14089
  const normalizedRoomPath = roomPath.replace(/\/$/, '');
14034
- const viewPath = `${normalizedRoomPath}/view/${address}`;
14090
+ const viewPath = `${normalizedRoomPath}/view/${viewUserId}`;
14035
14091
  // This is a LIVE/room subscription by construction (the caller hands us the
14036
14092
  // room path), so we route its connection to the per-room DO where the live
14037
14093
  // view fan-out runs. App code passes NO routing — the room path is the helper's
@@ -14042,7 +14098,7 @@ async function subscribeView(roomPath, opts) {
14042
14098
  return subscribeV2(viewPath, { onData: opts.onData, onError: opts.onError }, normalizedRoomPath);
14043
14099
  }
14044
14100
  /** The `bounded.live` namespace surface. */
14045
- const live = { intent, subscribeView };
14101
+ const live = { intent, status, subscribeView };
14046
14102
 
14047
14103
  // ---------------------------------------------------------------------------
14048
14104
  // live-effects.ts -- AUTHOR-facing types + helpers for writing a Bounded live
@@ -17686,13 +17742,2418 @@ var srcExports = requireSrc();
17686
17742
  var basex = /*@__PURE__*/getDefaultExportFromCjs$1(srcExports);
17687
17743
 
17688
17744
  var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
17689
- var base58 = basex(ALPHABET);
17745
+ var bs582 = basex(ALPHABET);
17690
17746
 
17691
17747
  var index = /*#__PURE__*/Object.freeze({
17692
17748
  __proto__: null,
17693
- default: base58
17749
+ default: bs582
17694
17750
  });
17695
17751
 
17752
+ var naclFast = {exports: {}};
17753
+
17754
+ var hasRequiredNaclFast;
17755
+
17756
+ function requireNaclFast () {
17757
+ if (hasRequiredNaclFast) return naclFast.exports;
17758
+ hasRequiredNaclFast = 1;
17759
+ (function (module) {
17760
+ (function(nacl) {
17761
+
17762
+ // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
17763
+ // Public domain.
17764
+ //
17765
+ // Implementation derived from TweetNaCl version 20140427.
17766
+ // See for details: http://tweetnacl.cr.yp.to/
17767
+
17768
+ var gf = function(init) {
17769
+ var i, r = new Float64Array(16);
17770
+ if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
17771
+ return r;
17772
+ };
17773
+
17774
+ // Pluggable, initialized in high-level API below.
17775
+ var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
17776
+
17777
+ var _0 = new Uint8Array(16);
17778
+ var _9 = new Uint8Array(32); _9[0] = 9;
17779
+
17780
+ var gf0 = gf(),
17781
+ gf1 = gf([1]),
17782
+ _121665 = gf([0xdb41, 1]),
17783
+ D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
17784
+ D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
17785
+ X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
17786
+ Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
17787
+ I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
17788
+
17789
+ function ts64(x, i, h, l) {
17790
+ x[i] = (h >> 24) & 0xff;
17791
+ x[i+1] = (h >> 16) & 0xff;
17792
+ x[i+2] = (h >> 8) & 0xff;
17793
+ x[i+3] = h & 0xff;
17794
+ x[i+4] = (l >> 24) & 0xff;
17795
+ x[i+5] = (l >> 16) & 0xff;
17796
+ x[i+6] = (l >> 8) & 0xff;
17797
+ x[i+7] = l & 0xff;
17798
+ }
17799
+
17800
+ function vn(x, xi, y, yi, n) {
17801
+ var i,d = 0;
17802
+ for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
17803
+ return (1 & ((d - 1) >>> 8)) - 1;
17804
+ }
17805
+
17806
+ function crypto_verify_16(x, xi, y, yi) {
17807
+ return vn(x,xi,y,yi,16);
17808
+ }
17809
+
17810
+ function crypto_verify_32(x, xi, y, yi) {
17811
+ return vn(x,xi,y,yi,32);
17812
+ }
17813
+
17814
+ function core_salsa20(o, p, k, c) {
17815
+ var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
17816
+ j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
17817
+ j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
17818
+ j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
17819
+ j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
17820
+ j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
17821
+ j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
17822
+ j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
17823
+ j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
17824
+ j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
17825
+ j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
17826
+ j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
17827
+ j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
17828
+ j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
17829
+ j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
17830
+ j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
17831
+
17832
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
17833
+ x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
17834
+ x15 = j15, u;
17835
+
17836
+ for (var i = 0; i < 20; i += 2) {
17837
+ u = x0 + x12 | 0;
17838
+ x4 ^= u<<7 | u>>>(32-7);
17839
+ u = x4 + x0 | 0;
17840
+ x8 ^= u<<9 | u>>>(32-9);
17841
+ u = x8 + x4 | 0;
17842
+ x12 ^= u<<13 | u>>>(32-13);
17843
+ u = x12 + x8 | 0;
17844
+ x0 ^= u<<18 | u>>>(32-18);
17845
+
17846
+ u = x5 + x1 | 0;
17847
+ x9 ^= u<<7 | u>>>(32-7);
17848
+ u = x9 + x5 | 0;
17849
+ x13 ^= u<<9 | u>>>(32-9);
17850
+ u = x13 + x9 | 0;
17851
+ x1 ^= u<<13 | u>>>(32-13);
17852
+ u = x1 + x13 | 0;
17853
+ x5 ^= u<<18 | u>>>(32-18);
17854
+
17855
+ u = x10 + x6 | 0;
17856
+ x14 ^= u<<7 | u>>>(32-7);
17857
+ u = x14 + x10 | 0;
17858
+ x2 ^= u<<9 | u>>>(32-9);
17859
+ u = x2 + x14 | 0;
17860
+ x6 ^= u<<13 | u>>>(32-13);
17861
+ u = x6 + x2 | 0;
17862
+ x10 ^= u<<18 | u>>>(32-18);
17863
+
17864
+ u = x15 + x11 | 0;
17865
+ x3 ^= u<<7 | u>>>(32-7);
17866
+ u = x3 + x15 | 0;
17867
+ x7 ^= u<<9 | u>>>(32-9);
17868
+ u = x7 + x3 | 0;
17869
+ x11 ^= u<<13 | u>>>(32-13);
17870
+ u = x11 + x7 | 0;
17871
+ x15 ^= u<<18 | u>>>(32-18);
17872
+
17873
+ u = x0 + x3 | 0;
17874
+ x1 ^= u<<7 | u>>>(32-7);
17875
+ u = x1 + x0 | 0;
17876
+ x2 ^= u<<9 | u>>>(32-9);
17877
+ u = x2 + x1 | 0;
17878
+ x3 ^= u<<13 | u>>>(32-13);
17879
+ u = x3 + x2 | 0;
17880
+ x0 ^= u<<18 | u>>>(32-18);
17881
+
17882
+ u = x5 + x4 | 0;
17883
+ x6 ^= u<<7 | u>>>(32-7);
17884
+ u = x6 + x5 | 0;
17885
+ x7 ^= u<<9 | u>>>(32-9);
17886
+ u = x7 + x6 | 0;
17887
+ x4 ^= u<<13 | u>>>(32-13);
17888
+ u = x4 + x7 | 0;
17889
+ x5 ^= u<<18 | u>>>(32-18);
17890
+
17891
+ u = x10 + x9 | 0;
17892
+ x11 ^= u<<7 | u>>>(32-7);
17893
+ u = x11 + x10 | 0;
17894
+ x8 ^= u<<9 | u>>>(32-9);
17895
+ u = x8 + x11 | 0;
17896
+ x9 ^= u<<13 | u>>>(32-13);
17897
+ u = x9 + x8 | 0;
17898
+ x10 ^= u<<18 | u>>>(32-18);
17899
+
17900
+ u = x15 + x14 | 0;
17901
+ x12 ^= u<<7 | u>>>(32-7);
17902
+ u = x12 + x15 | 0;
17903
+ x13 ^= u<<9 | u>>>(32-9);
17904
+ u = x13 + x12 | 0;
17905
+ x14 ^= u<<13 | u>>>(32-13);
17906
+ u = x14 + x13 | 0;
17907
+ x15 ^= u<<18 | u>>>(32-18);
17908
+ }
17909
+ x0 = x0 + j0 | 0;
17910
+ x1 = x1 + j1 | 0;
17911
+ x2 = x2 + j2 | 0;
17912
+ x3 = x3 + j3 | 0;
17913
+ x4 = x4 + j4 | 0;
17914
+ x5 = x5 + j5 | 0;
17915
+ x6 = x6 + j6 | 0;
17916
+ x7 = x7 + j7 | 0;
17917
+ x8 = x8 + j8 | 0;
17918
+ x9 = x9 + j9 | 0;
17919
+ x10 = x10 + j10 | 0;
17920
+ x11 = x11 + j11 | 0;
17921
+ x12 = x12 + j12 | 0;
17922
+ x13 = x13 + j13 | 0;
17923
+ x14 = x14 + j14 | 0;
17924
+ x15 = x15 + j15 | 0;
17925
+
17926
+ o[ 0] = x0 >>> 0 & 0xff;
17927
+ o[ 1] = x0 >>> 8 & 0xff;
17928
+ o[ 2] = x0 >>> 16 & 0xff;
17929
+ o[ 3] = x0 >>> 24 & 0xff;
17930
+
17931
+ o[ 4] = x1 >>> 0 & 0xff;
17932
+ o[ 5] = x1 >>> 8 & 0xff;
17933
+ o[ 6] = x1 >>> 16 & 0xff;
17934
+ o[ 7] = x1 >>> 24 & 0xff;
17935
+
17936
+ o[ 8] = x2 >>> 0 & 0xff;
17937
+ o[ 9] = x2 >>> 8 & 0xff;
17938
+ o[10] = x2 >>> 16 & 0xff;
17939
+ o[11] = x2 >>> 24 & 0xff;
17940
+
17941
+ o[12] = x3 >>> 0 & 0xff;
17942
+ o[13] = x3 >>> 8 & 0xff;
17943
+ o[14] = x3 >>> 16 & 0xff;
17944
+ o[15] = x3 >>> 24 & 0xff;
17945
+
17946
+ o[16] = x4 >>> 0 & 0xff;
17947
+ o[17] = x4 >>> 8 & 0xff;
17948
+ o[18] = x4 >>> 16 & 0xff;
17949
+ o[19] = x4 >>> 24 & 0xff;
17950
+
17951
+ o[20] = x5 >>> 0 & 0xff;
17952
+ o[21] = x5 >>> 8 & 0xff;
17953
+ o[22] = x5 >>> 16 & 0xff;
17954
+ o[23] = x5 >>> 24 & 0xff;
17955
+
17956
+ o[24] = x6 >>> 0 & 0xff;
17957
+ o[25] = x6 >>> 8 & 0xff;
17958
+ o[26] = x6 >>> 16 & 0xff;
17959
+ o[27] = x6 >>> 24 & 0xff;
17960
+
17961
+ o[28] = x7 >>> 0 & 0xff;
17962
+ o[29] = x7 >>> 8 & 0xff;
17963
+ o[30] = x7 >>> 16 & 0xff;
17964
+ o[31] = x7 >>> 24 & 0xff;
17965
+
17966
+ o[32] = x8 >>> 0 & 0xff;
17967
+ o[33] = x8 >>> 8 & 0xff;
17968
+ o[34] = x8 >>> 16 & 0xff;
17969
+ o[35] = x8 >>> 24 & 0xff;
17970
+
17971
+ o[36] = x9 >>> 0 & 0xff;
17972
+ o[37] = x9 >>> 8 & 0xff;
17973
+ o[38] = x9 >>> 16 & 0xff;
17974
+ o[39] = x9 >>> 24 & 0xff;
17975
+
17976
+ o[40] = x10 >>> 0 & 0xff;
17977
+ o[41] = x10 >>> 8 & 0xff;
17978
+ o[42] = x10 >>> 16 & 0xff;
17979
+ o[43] = x10 >>> 24 & 0xff;
17980
+
17981
+ o[44] = x11 >>> 0 & 0xff;
17982
+ o[45] = x11 >>> 8 & 0xff;
17983
+ o[46] = x11 >>> 16 & 0xff;
17984
+ o[47] = x11 >>> 24 & 0xff;
17985
+
17986
+ o[48] = x12 >>> 0 & 0xff;
17987
+ o[49] = x12 >>> 8 & 0xff;
17988
+ o[50] = x12 >>> 16 & 0xff;
17989
+ o[51] = x12 >>> 24 & 0xff;
17990
+
17991
+ o[52] = x13 >>> 0 & 0xff;
17992
+ o[53] = x13 >>> 8 & 0xff;
17993
+ o[54] = x13 >>> 16 & 0xff;
17994
+ o[55] = x13 >>> 24 & 0xff;
17995
+
17996
+ o[56] = x14 >>> 0 & 0xff;
17997
+ o[57] = x14 >>> 8 & 0xff;
17998
+ o[58] = x14 >>> 16 & 0xff;
17999
+ o[59] = x14 >>> 24 & 0xff;
18000
+
18001
+ o[60] = x15 >>> 0 & 0xff;
18002
+ o[61] = x15 >>> 8 & 0xff;
18003
+ o[62] = x15 >>> 16 & 0xff;
18004
+ o[63] = x15 >>> 24 & 0xff;
18005
+ }
18006
+
18007
+ function core_hsalsa20(o,p,k,c) {
18008
+ var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
18009
+ j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
18010
+ j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
18011
+ j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
18012
+ j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
18013
+ j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
18014
+ j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
18015
+ j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
18016
+ j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
18017
+ j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
18018
+ j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
18019
+ j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
18020
+ j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
18021
+ j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
18022
+ j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
18023
+ j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
18024
+
18025
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
18026
+ x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
18027
+ x15 = j15, u;
18028
+
18029
+ for (var i = 0; i < 20; i += 2) {
18030
+ u = x0 + x12 | 0;
18031
+ x4 ^= u<<7 | u>>>(32-7);
18032
+ u = x4 + x0 | 0;
18033
+ x8 ^= u<<9 | u>>>(32-9);
18034
+ u = x8 + x4 | 0;
18035
+ x12 ^= u<<13 | u>>>(32-13);
18036
+ u = x12 + x8 | 0;
18037
+ x0 ^= u<<18 | u>>>(32-18);
18038
+
18039
+ u = x5 + x1 | 0;
18040
+ x9 ^= u<<7 | u>>>(32-7);
18041
+ u = x9 + x5 | 0;
18042
+ x13 ^= u<<9 | u>>>(32-9);
18043
+ u = x13 + x9 | 0;
18044
+ x1 ^= u<<13 | u>>>(32-13);
18045
+ u = x1 + x13 | 0;
18046
+ x5 ^= u<<18 | u>>>(32-18);
18047
+
18048
+ u = x10 + x6 | 0;
18049
+ x14 ^= u<<7 | u>>>(32-7);
18050
+ u = x14 + x10 | 0;
18051
+ x2 ^= u<<9 | u>>>(32-9);
18052
+ u = x2 + x14 | 0;
18053
+ x6 ^= u<<13 | u>>>(32-13);
18054
+ u = x6 + x2 | 0;
18055
+ x10 ^= u<<18 | u>>>(32-18);
18056
+
18057
+ u = x15 + x11 | 0;
18058
+ x3 ^= u<<7 | u>>>(32-7);
18059
+ u = x3 + x15 | 0;
18060
+ x7 ^= u<<9 | u>>>(32-9);
18061
+ u = x7 + x3 | 0;
18062
+ x11 ^= u<<13 | u>>>(32-13);
18063
+ u = x11 + x7 | 0;
18064
+ x15 ^= u<<18 | u>>>(32-18);
18065
+
18066
+ u = x0 + x3 | 0;
18067
+ x1 ^= u<<7 | u>>>(32-7);
18068
+ u = x1 + x0 | 0;
18069
+ x2 ^= u<<9 | u>>>(32-9);
18070
+ u = x2 + x1 | 0;
18071
+ x3 ^= u<<13 | u>>>(32-13);
18072
+ u = x3 + x2 | 0;
18073
+ x0 ^= u<<18 | u>>>(32-18);
18074
+
18075
+ u = x5 + x4 | 0;
18076
+ x6 ^= u<<7 | u>>>(32-7);
18077
+ u = x6 + x5 | 0;
18078
+ x7 ^= u<<9 | u>>>(32-9);
18079
+ u = x7 + x6 | 0;
18080
+ x4 ^= u<<13 | u>>>(32-13);
18081
+ u = x4 + x7 | 0;
18082
+ x5 ^= u<<18 | u>>>(32-18);
18083
+
18084
+ u = x10 + x9 | 0;
18085
+ x11 ^= u<<7 | u>>>(32-7);
18086
+ u = x11 + x10 | 0;
18087
+ x8 ^= u<<9 | u>>>(32-9);
18088
+ u = x8 + x11 | 0;
18089
+ x9 ^= u<<13 | u>>>(32-13);
18090
+ u = x9 + x8 | 0;
18091
+ x10 ^= u<<18 | u>>>(32-18);
18092
+
18093
+ u = x15 + x14 | 0;
18094
+ x12 ^= u<<7 | u>>>(32-7);
18095
+ u = x12 + x15 | 0;
18096
+ x13 ^= u<<9 | u>>>(32-9);
18097
+ u = x13 + x12 | 0;
18098
+ x14 ^= u<<13 | u>>>(32-13);
18099
+ u = x14 + x13 | 0;
18100
+ x15 ^= u<<18 | u>>>(32-18);
18101
+ }
18102
+
18103
+ o[ 0] = x0 >>> 0 & 0xff;
18104
+ o[ 1] = x0 >>> 8 & 0xff;
18105
+ o[ 2] = x0 >>> 16 & 0xff;
18106
+ o[ 3] = x0 >>> 24 & 0xff;
18107
+
18108
+ o[ 4] = x5 >>> 0 & 0xff;
18109
+ o[ 5] = x5 >>> 8 & 0xff;
18110
+ o[ 6] = x5 >>> 16 & 0xff;
18111
+ o[ 7] = x5 >>> 24 & 0xff;
18112
+
18113
+ o[ 8] = x10 >>> 0 & 0xff;
18114
+ o[ 9] = x10 >>> 8 & 0xff;
18115
+ o[10] = x10 >>> 16 & 0xff;
18116
+ o[11] = x10 >>> 24 & 0xff;
18117
+
18118
+ o[12] = x15 >>> 0 & 0xff;
18119
+ o[13] = x15 >>> 8 & 0xff;
18120
+ o[14] = x15 >>> 16 & 0xff;
18121
+ o[15] = x15 >>> 24 & 0xff;
18122
+
18123
+ o[16] = x6 >>> 0 & 0xff;
18124
+ o[17] = x6 >>> 8 & 0xff;
18125
+ o[18] = x6 >>> 16 & 0xff;
18126
+ o[19] = x6 >>> 24 & 0xff;
18127
+
18128
+ o[20] = x7 >>> 0 & 0xff;
18129
+ o[21] = x7 >>> 8 & 0xff;
18130
+ o[22] = x7 >>> 16 & 0xff;
18131
+ o[23] = x7 >>> 24 & 0xff;
18132
+
18133
+ o[24] = x8 >>> 0 & 0xff;
18134
+ o[25] = x8 >>> 8 & 0xff;
18135
+ o[26] = x8 >>> 16 & 0xff;
18136
+ o[27] = x8 >>> 24 & 0xff;
18137
+
18138
+ o[28] = x9 >>> 0 & 0xff;
18139
+ o[29] = x9 >>> 8 & 0xff;
18140
+ o[30] = x9 >>> 16 & 0xff;
18141
+ o[31] = x9 >>> 24 & 0xff;
18142
+ }
18143
+
18144
+ function crypto_core_salsa20(out,inp,k,c) {
18145
+ core_salsa20(out,inp,k,c);
18146
+ }
18147
+
18148
+ function crypto_core_hsalsa20(out,inp,k,c) {
18149
+ core_hsalsa20(out,inp,k,c);
18150
+ }
18151
+
18152
+ var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
18153
+ // "expand 32-byte k"
18154
+
18155
+ function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
18156
+ var z = new Uint8Array(16), x = new Uint8Array(64);
18157
+ var u, i;
18158
+ for (i = 0; i < 16; i++) z[i] = 0;
18159
+ for (i = 0; i < 8; i++) z[i] = n[i];
18160
+ while (b >= 64) {
18161
+ crypto_core_salsa20(x,z,k,sigma);
18162
+ for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
18163
+ u = 1;
18164
+ for (i = 8; i < 16; i++) {
18165
+ u = u + (z[i] & 0xff) | 0;
18166
+ z[i] = u & 0xff;
18167
+ u >>>= 8;
18168
+ }
18169
+ b -= 64;
18170
+ cpos += 64;
18171
+ mpos += 64;
18172
+ }
18173
+ if (b > 0) {
18174
+ crypto_core_salsa20(x,z,k,sigma);
18175
+ for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
18176
+ }
18177
+ return 0;
18178
+ }
18179
+
18180
+ function crypto_stream_salsa20(c,cpos,b,n,k) {
18181
+ var z = new Uint8Array(16), x = new Uint8Array(64);
18182
+ var u, i;
18183
+ for (i = 0; i < 16; i++) z[i] = 0;
18184
+ for (i = 0; i < 8; i++) z[i] = n[i];
18185
+ while (b >= 64) {
18186
+ crypto_core_salsa20(x,z,k,sigma);
18187
+ for (i = 0; i < 64; i++) c[cpos+i] = x[i];
18188
+ u = 1;
18189
+ for (i = 8; i < 16; i++) {
18190
+ u = u + (z[i] & 0xff) | 0;
18191
+ z[i] = u & 0xff;
18192
+ u >>>= 8;
18193
+ }
18194
+ b -= 64;
18195
+ cpos += 64;
18196
+ }
18197
+ if (b > 0) {
18198
+ crypto_core_salsa20(x,z,k,sigma);
18199
+ for (i = 0; i < b; i++) c[cpos+i] = x[i];
18200
+ }
18201
+ return 0;
18202
+ }
18203
+
18204
+ function crypto_stream(c,cpos,d,n,k) {
18205
+ var s = new Uint8Array(32);
18206
+ crypto_core_hsalsa20(s,n,k,sigma);
18207
+ var sn = new Uint8Array(8);
18208
+ for (var i = 0; i < 8; i++) sn[i] = n[i+16];
18209
+ return crypto_stream_salsa20(c,cpos,d,sn,s);
18210
+ }
18211
+
18212
+ function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
18213
+ var s = new Uint8Array(32);
18214
+ crypto_core_hsalsa20(s,n,k,sigma);
18215
+ var sn = new Uint8Array(8);
18216
+ for (var i = 0; i < 8; i++) sn[i] = n[i+16];
18217
+ return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
18218
+ }
18219
+
18220
+ /*
18221
+ * Port of Andrew Moon's Poly1305-donna-16. Public domain.
18222
+ * https://github.com/floodyberry/poly1305-donna
18223
+ */
18224
+
18225
+ var poly1305 = function(key) {
18226
+ this.buffer = new Uint8Array(16);
18227
+ this.r = new Uint16Array(10);
18228
+ this.h = new Uint16Array(10);
18229
+ this.pad = new Uint16Array(8);
18230
+ this.leftover = 0;
18231
+ this.fin = 0;
18232
+
18233
+ var t0, t1, t2, t3, t4, t5, t6, t7;
18234
+
18235
+ t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
18236
+ t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
18237
+ t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
18238
+ t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
18239
+ t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
18240
+ this.r[5] = ((t4 >>> 1)) & 0x1ffe;
18241
+ t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
18242
+ t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
18243
+ t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
18244
+ this.r[9] = ((t7 >>> 5)) & 0x007f;
18245
+
18246
+ this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
18247
+ this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
18248
+ this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
18249
+ this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
18250
+ this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
18251
+ this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
18252
+ this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
18253
+ this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
18254
+ };
18255
+
18256
+ poly1305.prototype.blocks = function(m, mpos, bytes) {
18257
+ var hibit = this.fin ? 0 : (1 << 11);
18258
+ var t0, t1, t2, t3, t4, t5, t6, t7, c;
18259
+ var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
18260
+
18261
+ var h0 = this.h[0],
18262
+ h1 = this.h[1],
18263
+ h2 = this.h[2],
18264
+ h3 = this.h[3],
18265
+ h4 = this.h[4],
18266
+ h5 = this.h[5],
18267
+ h6 = this.h[6],
18268
+ h7 = this.h[7],
18269
+ h8 = this.h[8],
18270
+ h9 = this.h[9];
18271
+
18272
+ var r0 = this.r[0],
18273
+ r1 = this.r[1],
18274
+ r2 = this.r[2],
18275
+ r3 = this.r[3],
18276
+ r4 = this.r[4],
18277
+ r5 = this.r[5],
18278
+ r6 = this.r[6],
18279
+ r7 = this.r[7],
18280
+ r8 = this.r[8],
18281
+ r9 = this.r[9];
18282
+
18283
+ while (bytes >= 16) {
18284
+ t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
18285
+ t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
18286
+ t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
18287
+ t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
18288
+ t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
18289
+ h5 += ((t4 >>> 1)) & 0x1fff;
18290
+ t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
18291
+ t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
18292
+ t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
18293
+ h9 += ((t7 >>> 5)) | hibit;
18294
+
18295
+ c = 0;
18296
+
18297
+ d0 = c;
18298
+ d0 += h0 * r0;
18299
+ d0 += h1 * (5 * r9);
18300
+ d0 += h2 * (5 * r8);
18301
+ d0 += h3 * (5 * r7);
18302
+ d0 += h4 * (5 * r6);
18303
+ c = (d0 >>> 13); d0 &= 0x1fff;
18304
+ d0 += h5 * (5 * r5);
18305
+ d0 += h6 * (5 * r4);
18306
+ d0 += h7 * (5 * r3);
18307
+ d0 += h8 * (5 * r2);
18308
+ d0 += h9 * (5 * r1);
18309
+ c += (d0 >>> 13); d0 &= 0x1fff;
18310
+
18311
+ d1 = c;
18312
+ d1 += h0 * r1;
18313
+ d1 += h1 * r0;
18314
+ d1 += h2 * (5 * r9);
18315
+ d1 += h3 * (5 * r8);
18316
+ d1 += h4 * (5 * r7);
18317
+ c = (d1 >>> 13); d1 &= 0x1fff;
18318
+ d1 += h5 * (5 * r6);
18319
+ d1 += h6 * (5 * r5);
18320
+ d1 += h7 * (5 * r4);
18321
+ d1 += h8 * (5 * r3);
18322
+ d1 += h9 * (5 * r2);
18323
+ c += (d1 >>> 13); d1 &= 0x1fff;
18324
+
18325
+ d2 = c;
18326
+ d2 += h0 * r2;
18327
+ d2 += h1 * r1;
18328
+ d2 += h2 * r0;
18329
+ d2 += h3 * (5 * r9);
18330
+ d2 += h4 * (5 * r8);
18331
+ c = (d2 >>> 13); d2 &= 0x1fff;
18332
+ d2 += h5 * (5 * r7);
18333
+ d2 += h6 * (5 * r6);
18334
+ d2 += h7 * (5 * r5);
18335
+ d2 += h8 * (5 * r4);
18336
+ d2 += h9 * (5 * r3);
18337
+ c += (d2 >>> 13); d2 &= 0x1fff;
18338
+
18339
+ d3 = c;
18340
+ d3 += h0 * r3;
18341
+ d3 += h1 * r2;
18342
+ d3 += h2 * r1;
18343
+ d3 += h3 * r0;
18344
+ d3 += h4 * (5 * r9);
18345
+ c = (d3 >>> 13); d3 &= 0x1fff;
18346
+ d3 += h5 * (5 * r8);
18347
+ d3 += h6 * (5 * r7);
18348
+ d3 += h7 * (5 * r6);
18349
+ d3 += h8 * (5 * r5);
18350
+ d3 += h9 * (5 * r4);
18351
+ c += (d3 >>> 13); d3 &= 0x1fff;
18352
+
18353
+ d4 = c;
18354
+ d4 += h0 * r4;
18355
+ d4 += h1 * r3;
18356
+ d4 += h2 * r2;
18357
+ d4 += h3 * r1;
18358
+ d4 += h4 * r0;
18359
+ c = (d4 >>> 13); d4 &= 0x1fff;
18360
+ d4 += h5 * (5 * r9);
18361
+ d4 += h6 * (5 * r8);
18362
+ d4 += h7 * (5 * r7);
18363
+ d4 += h8 * (5 * r6);
18364
+ d4 += h9 * (5 * r5);
18365
+ c += (d4 >>> 13); d4 &= 0x1fff;
18366
+
18367
+ d5 = c;
18368
+ d5 += h0 * r5;
18369
+ d5 += h1 * r4;
18370
+ d5 += h2 * r3;
18371
+ d5 += h3 * r2;
18372
+ d5 += h4 * r1;
18373
+ c = (d5 >>> 13); d5 &= 0x1fff;
18374
+ d5 += h5 * r0;
18375
+ d5 += h6 * (5 * r9);
18376
+ d5 += h7 * (5 * r8);
18377
+ d5 += h8 * (5 * r7);
18378
+ d5 += h9 * (5 * r6);
18379
+ c += (d5 >>> 13); d5 &= 0x1fff;
18380
+
18381
+ d6 = c;
18382
+ d6 += h0 * r6;
18383
+ d6 += h1 * r5;
18384
+ d6 += h2 * r4;
18385
+ d6 += h3 * r3;
18386
+ d6 += h4 * r2;
18387
+ c = (d6 >>> 13); d6 &= 0x1fff;
18388
+ d6 += h5 * r1;
18389
+ d6 += h6 * r0;
18390
+ d6 += h7 * (5 * r9);
18391
+ d6 += h8 * (5 * r8);
18392
+ d6 += h9 * (5 * r7);
18393
+ c += (d6 >>> 13); d6 &= 0x1fff;
18394
+
18395
+ d7 = c;
18396
+ d7 += h0 * r7;
18397
+ d7 += h1 * r6;
18398
+ d7 += h2 * r5;
18399
+ d7 += h3 * r4;
18400
+ d7 += h4 * r3;
18401
+ c = (d7 >>> 13); d7 &= 0x1fff;
18402
+ d7 += h5 * r2;
18403
+ d7 += h6 * r1;
18404
+ d7 += h7 * r0;
18405
+ d7 += h8 * (5 * r9);
18406
+ d7 += h9 * (5 * r8);
18407
+ c += (d7 >>> 13); d7 &= 0x1fff;
18408
+
18409
+ d8 = c;
18410
+ d8 += h0 * r8;
18411
+ d8 += h1 * r7;
18412
+ d8 += h2 * r6;
18413
+ d8 += h3 * r5;
18414
+ d8 += h4 * r4;
18415
+ c = (d8 >>> 13); d8 &= 0x1fff;
18416
+ d8 += h5 * r3;
18417
+ d8 += h6 * r2;
18418
+ d8 += h7 * r1;
18419
+ d8 += h8 * r0;
18420
+ d8 += h9 * (5 * r9);
18421
+ c += (d8 >>> 13); d8 &= 0x1fff;
18422
+
18423
+ d9 = c;
18424
+ d9 += h0 * r9;
18425
+ d9 += h1 * r8;
18426
+ d9 += h2 * r7;
18427
+ d9 += h3 * r6;
18428
+ d9 += h4 * r5;
18429
+ c = (d9 >>> 13); d9 &= 0x1fff;
18430
+ d9 += h5 * r4;
18431
+ d9 += h6 * r3;
18432
+ d9 += h7 * r2;
18433
+ d9 += h8 * r1;
18434
+ d9 += h9 * r0;
18435
+ c += (d9 >>> 13); d9 &= 0x1fff;
18436
+
18437
+ c = (((c << 2) + c)) | 0;
18438
+ c = (c + d0) | 0;
18439
+ d0 = c & 0x1fff;
18440
+ c = (c >>> 13);
18441
+ d1 += c;
18442
+
18443
+ h0 = d0;
18444
+ h1 = d1;
18445
+ h2 = d2;
18446
+ h3 = d3;
18447
+ h4 = d4;
18448
+ h5 = d5;
18449
+ h6 = d6;
18450
+ h7 = d7;
18451
+ h8 = d8;
18452
+ h9 = d9;
18453
+
18454
+ mpos += 16;
18455
+ bytes -= 16;
18456
+ }
18457
+ this.h[0] = h0;
18458
+ this.h[1] = h1;
18459
+ this.h[2] = h2;
18460
+ this.h[3] = h3;
18461
+ this.h[4] = h4;
18462
+ this.h[5] = h5;
18463
+ this.h[6] = h6;
18464
+ this.h[7] = h7;
18465
+ this.h[8] = h8;
18466
+ this.h[9] = h9;
18467
+ };
18468
+
18469
+ poly1305.prototype.finish = function(mac, macpos) {
18470
+ var g = new Uint16Array(10);
18471
+ var c, mask, f, i;
18472
+
18473
+ if (this.leftover) {
18474
+ i = this.leftover;
18475
+ this.buffer[i++] = 1;
18476
+ for (; i < 16; i++) this.buffer[i] = 0;
18477
+ this.fin = 1;
18478
+ this.blocks(this.buffer, 0, 16);
18479
+ }
18480
+
18481
+ c = this.h[1] >>> 13;
18482
+ this.h[1] &= 0x1fff;
18483
+ for (i = 2; i < 10; i++) {
18484
+ this.h[i] += c;
18485
+ c = this.h[i] >>> 13;
18486
+ this.h[i] &= 0x1fff;
18487
+ }
18488
+ this.h[0] += (c * 5);
18489
+ c = this.h[0] >>> 13;
18490
+ this.h[0] &= 0x1fff;
18491
+ this.h[1] += c;
18492
+ c = this.h[1] >>> 13;
18493
+ this.h[1] &= 0x1fff;
18494
+ this.h[2] += c;
18495
+
18496
+ g[0] = this.h[0] + 5;
18497
+ c = g[0] >>> 13;
18498
+ g[0] &= 0x1fff;
18499
+ for (i = 1; i < 10; i++) {
18500
+ g[i] = this.h[i] + c;
18501
+ c = g[i] >>> 13;
18502
+ g[i] &= 0x1fff;
18503
+ }
18504
+ g[9] -= (1 << 13);
18505
+
18506
+ mask = (c ^ 1) - 1;
18507
+ for (i = 0; i < 10; i++) g[i] &= mask;
18508
+ mask = ~mask;
18509
+ for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
18510
+
18511
+ this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
18512
+ this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
18513
+ this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
18514
+ this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
18515
+ this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
18516
+ this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
18517
+ this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
18518
+ this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
18519
+
18520
+ f = this.h[0] + this.pad[0];
18521
+ this.h[0] = f & 0xffff;
18522
+ for (i = 1; i < 8; i++) {
18523
+ f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
18524
+ this.h[i] = f & 0xffff;
18525
+ }
18526
+
18527
+ mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
18528
+ mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
18529
+ mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
18530
+ mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
18531
+ mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
18532
+ mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
18533
+ mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
18534
+ mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
18535
+ mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
18536
+ mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
18537
+ mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
18538
+ mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
18539
+ mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
18540
+ mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
18541
+ mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
18542
+ mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
18543
+ };
18544
+
18545
+ poly1305.prototype.update = function(m, mpos, bytes) {
18546
+ var i, want;
18547
+
18548
+ if (this.leftover) {
18549
+ want = (16 - this.leftover);
18550
+ if (want > bytes)
18551
+ want = bytes;
18552
+ for (i = 0; i < want; i++)
18553
+ this.buffer[this.leftover + i] = m[mpos+i];
18554
+ bytes -= want;
18555
+ mpos += want;
18556
+ this.leftover += want;
18557
+ if (this.leftover < 16)
18558
+ return;
18559
+ this.blocks(this.buffer, 0, 16);
18560
+ this.leftover = 0;
18561
+ }
18562
+
18563
+ if (bytes >= 16) {
18564
+ want = bytes - (bytes % 16);
18565
+ this.blocks(m, mpos, want);
18566
+ mpos += want;
18567
+ bytes -= want;
18568
+ }
18569
+
18570
+ if (bytes) {
18571
+ for (i = 0; i < bytes; i++)
18572
+ this.buffer[this.leftover + i] = m[mpos+i];
18573
+ this.leftover += bytes;
18574
+ }
18575
+ };
18576
+
18577
+ function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
18578
+ var s = new poly1305(k);
18579
+ s.update(m, mpos, n);
18580
+ s.finish(out, outpos);
18581
+ return 0;
18582
+ }
18583
+
18584
+ function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
18585
+ var x = new Uint8Array(16);
18586
+ crypto_onetimeauth(x,0,m,mpos,n,k);
18587
+ return crypto_verify_16(h,hpos,x,0);
18588
+ }
18589
+
18590
+ function crypto_secretbox(c,m,d,n,k) {
18591
+ var i;
18592
+ if (d < 32) return -1;
18593
+ crypto_stream_xor(c,0,m,0,d,n,k);
18594
+ crypto_onetimeauth(c, 16, c, 32, d - 32, c);
18595
+ for (i = 0; i < 16; i++) c[i] = 0;
18596
+ return 0;
18597
+ }
18598
+
18599
+ function crypto_secretbox_open(m,c,d,n,k) {
18600
+ var i;
18601
+ var x = new Uint8Array(32);
18602
+ if (d < 32) return -1;
18603
+ crypto_stream(x,0,32,n,k);
18604
+ if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
18605
+ crypto_stream_xor(m,0,c,0,d,n,k);
18606
+ for (i = 0; i < 32; i++) m[i] = 0;
18607
+ return 0;
18608
+ }
18609
+
18610
+ function set25519(r, a) {
18611
+ var i;
18612
+ for (i = 0; i < 16; i++) r[i] = a[i]|0;
18613
+ }
18614
+
18615
+ function car25519(o) {
18616
+ var i, v, c = 1;
18617
+ for (i = 0; i < 16; i++) {
18618
+ v = o[i] + c + 65535;
18619
+ c = Math.floor(v / 65536);
18620
+ o[i] = v - c * 65536;
18621
+ }
18622
+ o[0] += c-1 + 37 * (c-1);
18623
+ }
18624
+
18625
+ function sel25519(p, q, b) {
18626
+ var t, c = ~(b-1);
18627
+ for (var i = 0; i < 16; i++) {
18628
+ t = c & (p[i] ^ q[i]);
18629
+ p[i] ^= t;
18630
+ q[i] ^= t;
18631
+ }
18632
+ }
18633
+
18634
+ function pack25519(o, n) {
18635
+ var i, j, b;
18636
+ var m = gf(), t = gf();
18637
+ for (i = 0; i < 16; i++) t[i] = n[i];
18638
+ car25519(t);
18639
+ car25519(t);
18640
+ car25519(t);
18641
+ for (j = 0; j < 2; j++) {
18642
+ m[0] = t[0] - 0xffed;
18643
+ for (i = 1; i < 15; i++) {
18644
+ m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
18645
+ m[i-1] &= 0xffff;
18646
+ }
18647
+ m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
18648
+ b = (m[15]>>16) & 1;
18649
+ m[14] &= 0xffff;
18650
+ sel25519(t, m, 1-b);
18651
+ }
18652
+ for (i = 0; i < 16; i++) {
18653
+ o[2*i] = t[i] & 0xff;
18654
+ o[2*i+1] = t[i]>>8;
18655
+ }
18656
+ }
18657
+
18658
+ function neq25519(a, b) {
18659
+ var c = new Uint8Array(32), d = new Uint8Array(32);
18660
+ pack25519(c, a);
18661
+ pack25519(d, b);
18662
+ return crypto_verify_32(c, 0, d, 0);
18663
+ }
18664
+
18665
+ function par25519(a) {
18666
+ var d = new Uint8Array(32);
18667
+ pack25519(d, a);
18668
+ return d[0] & 1;
18669
+ }
18670
+
18671
+ function unpack25519(o, n) {
18672
+ var i;
18673
+ for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
18674
+ o[15] &= 0x7fff;
18675
+ }
18676
+
18677
+ function A(o, a, b) {
18678
+ for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
18679
+ }
18680
+
18681
+ function Z(o, a, b) {
18682
+ for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
18683
+ }
18684
+
18685
+ function M(o, a, b) {
18686
+ var v, c,
18687
+ t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
18688
+ t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
18689
+ t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
18690
+ t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
18691
+ b0 = b[0],
18692
+ b1 = b[1],
18693
+ b2 = b[2],
18694
+ b3 = b[3],
18695
+ b4 = b[4],
18696
+ b5 = b[5],
18697
+ b6 = b[6],
18698
+ b7 = b[7],
18699
+ b8 = b[8],
18700
+ b9 = b[9],
18701
+ b10 = b[10],
18702
+ b11 = b[11],
18703
+ b12 = b[12],
18704
+ b13 = b[13],
18705
+ b14 = b[14],
18706
+ b15 = b[15];
18707
+
18708
+ v = a[0];
18709
+ t0 += v * b0;
18710
+ t1 += v * b1;
18711
+ t2 += v * b2;
18712
+ t3 += v * b3;
18713
+ t4 += v * b4;
18714
+ t5 += v * b5;
18715
+ t6 += v * b6;
18716
+ t7 += v * b7;
18717
+ t8 += v * b8;
18718
+ t9 += v * b9;
18719
+ t10 += v * b10;
18720
+ t11 += v * b11;
18721
+ t12 += v * b12;
18722
+ t13 += v * b13;
18723
+ t14 += v * b14;
18724
+ t15 += v * b15;
18725
+ v = a[1];
18726
+ t1 += v * b0;
18727
+ t2 += v * b1;
18728
+ t3 += v * b2;
18729
+ t4 += v * b3;
18730
+ t5 += v * b4;
18731
+ t6 += v * b5;
18732
+ t7 += v * b6;
18733
+ t8 += v * b7;
18734
+ t9 += v * b8;
18735
+ t10 += v * b9;
18736
+ t11 += v * b10;
18737
+ t12 += v * b11;
18738
+ t13 += v * b12;
18739
+ t14 += v * b13;
18740
+ t15 += v * b14;
18741
+ t16 += v * b15;
18742
+ v = a[2];
18743
+ t2 += v * b0;
18744
+ t3 += v * b1;
18745
+ t4 += v * b2;
18746
+ t5 += v * b3;
18747
+ t6 += v * b4;
18748
+ t7 += v * b5;
18749
+ t8 += v * b6;
18750
+ t9 += v * b7;
18751
+ t10 += v * b8;
18752
+ t11 += v * b9;
18753
+ t12 += v * b10;
18754
+ t13 += v * b11;
18755
+ t14 += v * b12;
18756
+ t15 += v * b13;
18757
+ t16 += v * b14;
18758
+ t17 += v * b15;
18759
+ v = a[3];
18760
+ t3 += v * b0;
18761
+ t4 += v * b1;
18762
+ t5 += v * b2;
18763
+ t6 += v * b3;
18764
+ t7 += v * b4;
18765
+ t8 += v * b5;
18766
+ t9 += v * b6;
18767
+ t10 += v * b7;
18768
+ t11 += v * b8;
18769
+ t12 += v * b9;
18770
+ t13 += v * b10;
18771
+ t14 += v * b11;
18772
+ t15 += v * b12;
18773
+ t16 += v * b13;
18774
+ t17 += v * b14;
18775
+ t18 += v * b15;
18776
+ v = a[4];
18777
+ t4 += v * b0;
18778
+ t5 += v * b1;
18779
+ t6 += v * b2;
18780
+ t7 += v * b3;
18781
+ t8 += v * b4;
18782
+ t9 += v * b5;
18783
+ t10 += v * b6;
18784
+ t11 += v * b7;
18785
+ t12 += v * b8;
18786
+ t13 += v * b9;
18787
+ t14 += v * b10;
18788
+ t15 += v * b11;
18789
+ t16 += v * b12;
18790
+ t17 += v * b13;
18791
+ t18 += v * b14;
18792
+ t19 += v * b15;
18793
+ v = a[5];
18794
+ t5 += v * b0;
18795
+ t6 += v * b1;
18796
+ t7 += v * b2;
18797
+ t8 += v * b3;
18798
+ t9 += v * b4;
18799
+ t10 += v * b5;
18800
+ t11 += v * b6;
18801
+ t12 += v * b7;
18802
+ t13 += v * b8;
18803
+ t14 += v * b9;
18804
+ t15 += v * b10;
18805
+ t16 += v * b11;
18806
+ t17 += v * b12;
18807
+ t18 += v * b13;
18808
+ t19 += v * b14;
18809
+ t20 += v * b15;
18810
+ v = a[6];
18811
+ t6 += v * b0;
18812
+ t7 += v * b1;
18813
+ t8 += v * b2;
18814
+ t9 += v * b3;
18815
+ t10 += v * b4;
18816
+ t11 += v * b5;
18817
+ t12 += v * b6;
18818
+ t13 += v * b7;
18819
+ t14 += v * b8;
18820
+ t15 += v * b9;
18821
+ t16 += v * b10;
18822
+ t17 += v * b11;
18823
+ t18 += v * b12;
18824
+ t19 += v * b13;
18825
+ t20 += v * b14;
18826
+ t21 += v * b15;
18827
+ v = a[7];
18828
+ t7 += v * b0;
18829
+ t8 += v * b1;
18830
+ t9 += v * b2;
18831
+ t10 += v * b3;
18832
+ t11 += v * b4;
18833
+ t12 += v * b5;
18834
+ t13 += v * b6;
18835
+ t14 += v * b7;
18836
+ t15 += v * b8;
18837
+ t16 += v * b9;
18838
+ t17 += v * b10;
18839
+ t18 += v * b11;
18840
+ t19 += v * b12;
18841
+ t20 += v * b13;
18842
+ t21 += v * b14;
18843
+ t22 += v * b15;
18844
+ v = a[8];
18845
+ t8 += v * b0;
18846
+ t9 += v * b1;
18847
+ t10 += v * b2;
18848
+ t11 += v * b3;
18849
+ t12 += v * b4;
18850
+ t13 += v * b5;
18851
+ t14 += v * b6;
18852
+ t15 += v * b7;
18853
+ t16 += v * b8;
18854
+ t17 += v * b9;
18855
+ t18 += v * b10;
18856
+ t19 += v * b11;
18857
+ t20 += v * b12;
18858
+ t21 += v * b13;
18859
+ t22 += v * b14;
18860
+ t23 += v * b15;
18861
+ v = a[9];
18862
+ t9 += v * b0;
18863
+ t10 += v * b1;
18864
+ t11 += v * b2;
18865
+ t12 += v * b3;
18866
+ t13 += v * b4;
18867
+ t14 += v * b5;
18868
+ t15 += v * b6;
18869
+ t16 += v * b7;
18870
+ t17 += v * b8;
18871
+ t18 += v * b9;
18872
+ t19 += v * b10;
18873
+ t20 += v * b11;
18874
+ t21 += v * b12;
18875
+ t22 += v * b13;
18876
+ t23 += v * b14;
18877
+ t24 += v * b15;
18878
+ v = a[10];
18879
+ t10 += v * b0;
18880
+ t11 += v * b1;
18881
+ t12 += v * b2;
18882
+ t13 += v * b3;
18883
+ t14 += v * b4;
18884
+ t15 += v * b5;
18885
+ t16 += v * b6;
18886
+ t17 += v * b7;
18887
+ t18 += v * b8;
18888
+ t19 += v * b9;
18889
+ t20 += v * b10;
18890
+ t21 += v * b11;
18891
+ t22 += v * b12;
18892
+ t23 += v * b13;
18893
+ t24 += v * b14;
18894
+ t25 += v * b15;
18895
+ v = a[11];
18896
+ t11 += v * b0;
18897
+ t12 += v * b1;
18898
+ t13 += v * b2;
18899
+ t14 += v * b3;
18900
+ t15 += v * b4;
18901
+ t16 += v * b5;
18902
+ t17 += v * b6;
18903
+ t18 += v * b7;
18904
+ t19 += v * b8;
18905
+ t20 += v * b9;
18906
+ t21 += v * b10;
18907
+ t22 += v * b11;
18908
+ t23 += v * b12;
18909
+ t24 += v * b13;
18910
+ t25 += v * b14;
18911
+ t26 += v * b15;
18912
+ v = a[12];
18913
+ t12 += v * b0;
18914
+ t13 += v * b1;
18915
+ t14 += v * b2;
18916
+ t15 += v * b3;
18917
+ t16 += v * b4;
18918
+ t17 += v * b5;
18919
+ t18 += v * b6;
18920
+ t19 += v * b7;
18921
+ t20 += v * b8;
18922
+ t21 += v * b9;
18923
+ t22 += v * b10;
18924
+ t23 += v * b11;
18925
+ t24 += v * b12;
18926
+ t25 += v * b13;
18927
+ t26 += v * b14;
18928
+ t27 += v * b15;
18929
+ v = a[13];
18930
+ t13 += v * b0;
18931
+ t14 += v * b1;
18932
+ t15 += v * b2;
18933
+ t16 += v * b3;
18934
+ t17 += v * b4;
18935
+ t18 += v * b5;
18936
+ t19 += v * b6;
18937
+ t20 += v * b7;
18938
+ t21 += v * b8;
18939
+ t22 += v * b9;
18940
+ t23 += v * b10;
18941
+ t24 += v * b11;
18942
+ t25 += v * b12;
18943
+ t26 += v * b13;
18944
+ t27 += v * b14;
18945
+ t28 += v * b15;
18946
+ v = a[14];
18947
+ t14 += v * b0;
18948
+ t15 += v * b1;
18949
+ t16 += v * b2;
18950
+ t17 += v * b3;
18951
+ t18 += v * b4;
18952
+ t19 += v * b5;
18953
+ t20 += v * b6;
18954
+ t21 += v * b7;
18955
+ t22 += v * b8;
18956
+ t23 += v * b9;
18957
+ t24 += v * b10;
18958
+ t25 += v * b11;
18959
+ t26 += v * b12;
18960
+ t27 += v * b13;
18961
+ t28 += v * b14;
18962
+ t29 += v * b15;
18963
+ v = a[15];
18964
+ t15 += v * b0;
18965
+ t16 += v * b1;
18966
+ t17 += v * b2;
18967
+ t18 += v * b3;
18968
+ t19 += v * b4;
18969
+ t20 += v * b5;
18970
+ t21 += v * b6;
18971
+ t22 += v * b7;
18972
+ t23 += v * b8;
18973
+ t24 += v * b9;
18974
+ t25 += v * b10;
18975
+ t26 += v * b11;
18976
+ t27 += v * b12;
18977
+ t28 += v * b13;
18978
+ t29 += v * b14;
18979
+ t30 += v * b15;
18980
+
18981
+ t0 += 38 * t16;
18982
+ t1 += 38 * t17;
18983
+ t2 += 38 * t18;
18984
+ t3 += 38 * t19;
18985
+ t4 += 38 * t20;
18986
+ t5 += 38 * t21;
18987
+ t6 += 38 * t22;
18988
+ t7 += 38 * t23;
18989
+ t8 += 38 * t24;
18990
+ t9 += 38 * t25;
18991
+ t10 += 38 * t26;
18992
+ t11 += 38 * t27;
18993
+ t12 += 38 * t28;
18994
+ t13 += 38 * t29;
18995
+ t14 += 38 * t30;
18996
+ // t15 left as is
18997
+
18998
+ // first car
18999
+ c = 1;
19000
+ v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
19001
+ v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
19002
+ v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
19003
+ v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
19004
+ v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
19005
+ v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
19006
+ v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
19007
+ v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
19008
+ v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
19009
+ v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
19010
+ v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
19011
+ v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
19012
+ v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
19013
+ v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
19014
+ v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
19015
+ v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
19016
+ t0 += c-1 + 37 * (c-1);
19017
+
19018
+ // second car
19019
+ c = 1;
19020
+ v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
19021
+ v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
19022
+ v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
19023
+ v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
19024
+ v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
19025
+ v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
19026
+ v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
19027
+ v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
19028
+ v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
19029
+ v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
19030
+ v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
19031
+ v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
19032
+ v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
19033
+ v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
19034
+ v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
19035
+ v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
19036
+ t0 += c-1 + 37 * (c-1);
19037
+
19038
+ o[ 0] = t0;
19039
+ o[ 1] = t1;
19040
+ o[ 2] = t2;
19041
+ o[ 3] = t3;
19042
+ o[ 4] = t4;
19043
+ o[ 5] = t5;
19044
+ o[ 6] = t6;
19045
+ o[ 7] = t7;
19046
+ o[ 8] = t8;
19047
+ o[ 9] = t9;
19048
+ o[10] = t10;
19049
+ o[11] = t11;
19050
+ o[12] = t12;
19051
+ o[13] = t13;
19052
+ o[14] = t14;
19053
+ o[15] = t15;
19054
+ }
19055
+
19056
+ function S(o, a) {
19057
+ M(o, a, a);
19058
+ }
19059
+
19060
+ function inv25519(o, i) {
19061
+ var c = gf();
19062
+ var a;
19063
+ for (a = 0; a < 16; a++) c[a] = i[a];
19064
+ for (a = 253; a >= 0; a--) {
19065
+ S(c, c);
19066
+ if(a !== 2 && a !== 4) M(c, c, i);
19067
+ }
19068
+ for (a = 0; a < 16; a++) o[a] = c[a];
19069
+ }
19070
+
19071
+ function pow2523(o, i) {
19072
+ var c = gf();
19073
+ var a;
19074
+ for (a = 0; a < 16; a++) c[a] = i[a];
19075
+ for (a = 250; a >= 0; a--) {
19076
+ S(c, c);
19077
+ if(a !== 1) M(c, c, i);
19078
+ }
19079
+ for (a = 0; a < 16; a++) o[a] = c[a];
19080
+ }
19081
+
19082
+ function crypto_scalarmult(q, n, p) {
19083
+ var z = new Uint8Array(32);
19084
+ var x = new Float64Array(80), r, i;
19085
+ var a = gf(), b = gf(), c = gf(),
19086
+ d = gf(), e = gf(), f = gf();
19087
+ for (i = 0; i < 31; i++) z[i] = n[i];
19088
+ z[31]=(n[31]&127)|64;
19089
+ z[0]&=248;
19090
+ unpack25519(x,p);
19091
+ for (i = 0; i < 16; i++) {
19092
+ b[i]=x[i];
19093
+ d[i]=a[i]=c[i]=0;
19094
+ }
19095
+ a[0]=d[0]=1;
19096
+ for (i=254; i>=0; --i) {
19097
+ r=(z[i>>>3]>>>(i&7))&1;
19098
+ sel25519(a,b,r);
19099
+ sel25519(c,d,r);
19100
+ A(e,a,c);
19101
+ Z(a,a,c);
19102
+ A(c,b,d);
19103
+ Z(b,b,d);
19104
+ S(d,e);
19105
+ S(f,a);
19106
+ M(a,c,a);
19107
+ M(c,b,e);
19108
+ A(e,a,c);
19109
+ Z(a,a,c);
19110
+ S(b,a);
19111
+ Z(c,d,f);
19112
+ M(a,c,_121665);
19113
+ A(a,a,d);
19114
+ M(c,c,a);
19115
+ M(a,d,f);
19116
+ M(d,b,x);
19117
+ S(b,e);
19118
+ sel25519(a,b,r);
19119
+ sel25519(c,d,r);
19120
+ }
19121
+ for (i = 0; i < 16; i++) {
19122
+ x[i+16]=a[i];
19123
+ x[i+32]=c[i];
19124
+ x[i+48]=b[i];
19125
+ x[i+64]=d[i];
19126
+ }
19127
+ var x32 = x.subarray(32);
19128
+ var x16 = x.subarray(16);
19129
+ inv25519(x32,x32);
19130
+ M(x16,x16,x32);
19131
+ pack25519(q,x16);
19132
+ return 0;
19133
+ }
19134
+
19135
+ function crypto_scalarmult_base(q, n) {
19136
+ return crypto_scalarmult(q, n, _9);
19137
+ }
19138
+
19139
+ function crypto_box_keypair(y, x) {
19140
+ randombytes(x, 32);
19141
+ return crypto_scalarmult_base(y, x);
19142
+ }
19143
+
19144
+ function crypto_box_beforenm(k, y, x) {
19145
+ var s = new Uint8Array(32);
19146
+ crypto_scalarmult(s, x, y);
19147
+ return crypto_core_hsalsa20(k, _0, s, sigma);
19148
+ }
19149
+
19150
+ var crypto_box_afternm = crypto_secretbox;
19151
+ var crypto_box_open_afternm = crypto_secretbox_open;
19152
+
19153
+ function crypto_box(c, m, d, n, y, x) {
19154
+ var k = new Uint8Array(32);
19155
+ crypto_box_beforenm(k, y, x);
19156
+ return crypto_box_afternm(c, m, d, n, k);
19157
+ }
19158
+
19159
+ function crypto_box_open(m, c, d, n, y, x) {
19160
+ var k = new Uint8Array(32);
19161
+ crypto_box_beforenm(k, y, x);
19162
+ return crypto_box_open_afternm(m, c, d, n, k);
19163
+ }
19164
+
19165
+ var K = [
19166
+ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
19167
+ 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
19168
+ 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
19169
+ 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
19170
+ 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
19171
+ 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
19172
+ 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
19173
+ 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
19174
+ 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
19175
+ 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
19176
+ 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
19177
+ 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
19178
+ 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
19179
+ 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
19180
+ 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
19181
+ 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
19182
+ 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
19183
+ 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
19184
+ 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
19185
+ 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
19186
+ 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
19187
+ 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
19188
+ 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
19189
+ 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
19190
+ 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
19191
+ 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
19192
+ 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
19193
+ 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
19194
+ 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
19195
+ 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
19196
+ 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
19197
+ 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
19198
+ 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
19199
+ 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
19200
+ 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
19201
+ 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
19202
+ 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
19203
+ 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
19204
+ 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
19205
+ 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
19206
+ ];
19207
+
19208
+ function crypto_hashblocks_hl(hh, hl, m, n) {
19209
+ var wh = new Int32Array(16), wl = new Int32Array(16),
19210
+ bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
19211
+ bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
19212
+ th, tl, i, j, h, l, a, b, c, d;
19213
+
19214
+ var ah0 = hh[0],
19215
+ ah1 = hh[1],
19216
+ ah2 = hh[2],
19217
+ ah3 = hh[3],
19218
+ ah4 = hh[4],
19219
+ ah5 = hh[5],
19220
+ ah6 = hh[6],
19221
+ ah7 = hh[7],
19222
+
19223
+ al0 = hl[0],
19224
+ al1 = hl[1],
19225
+ al2 = hl[2],
19226
+ al3 = hl[3],
19227
+ al4 = hl[4],
19228
+ al5 = hl[5],
19229
+ al6 = hl[6],
19230
+ al7 = hl[7];
19231
+
19232
+ var pos = 0;
19233
+ while (n >= 128) {
19234
+ for (i = 0; i < 16; i++) {
19235
+ j = 8 * i + pos;
19236
+ wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
19237
+ wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
19238
+ }
19239
+ for (i = 0; i < 80; i++) {
19240
+ bh0 = ah0;
19241
+ bh1 = ah1;
19242
+ bh2 = ah2;
19243
+ bh3 = ah3;
19244
+ bh4 = ah4;
19245
+ bh5 = ah5;
19246
+ bh6 = ah6;
19247
+ bh7 = ah7;
19248
+
19249
+ bl0 = al0;
19250
+ bl1 = al1;
19251
+ bl2 = al2;
19252
+ bl3 = al3;
19253
+ bl4 = al4;
19254
+ bl5 = al5;
19255
+ bl6 = al6;
19256
+ bl7 = al7;
19257
+
19258
+ // add
19259
+ h = ah7;
19260
+ l = al7;
19261
+
19262
+ a = l & 0xffff; b = l >>> 16;
19263
+ c = h & 0xffff; d = h >>> 16;
19264
+
19265
+ // Sigma1
19266
+ h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
19267
+ l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
19268
+
19269
+ a += l & 0xffff; b += l >>> 16;
19270
+ c += h & 0xffff; d += h >>> 16;
19271
+
19272
+ // Ch
19273
+ h = (ah4 & ah5) ^ (~ah4 & ah6);
19274
+ l = (al4 & al5) ^ (~al4 & al6);
19275
+
19276
+ a += l & 0xffff; b += l >>> 16;
19277
+ c += h & 0xffff; d += h >>> 16;
19278
+
19279
+ // K
19280
+ h = K[i*2];
19281
+ l = K[i*2+1];
19282
+
19283
+ a += l & 0xffff; b += l >>> 16;
19284
+ c += h & 0xffff; d += h >>> 16;
19285
+
19286
+ // w
19287
+ h = wh[i%16];
19288
+ l = wl[i%16];
19289
+
19290
+ a += l & 0xffff; b += l >>> 16;
19291
+ c += h & 0xffff; d += h >>> 16;
19292
+
19293
+ b += a >>> 16;
19294
+ c += b >>> 16;
19295
+ d += c >>> 16;
19296
+
19297
+ th = c & 0xffff | d << 16;
19298
+ tl = a & 0xffff | b << 16;
19299
+
19300
+ // add
19301
+ h = th;
19302
+ l = tl;
19303
+
19304
+ a = l & 0xffff; b = l >>> 16;
19305
+ c = h & 0xffff; d = h >>> 16;
19306
+
19307
+ // Sigma0
19308
+ h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
19309
+ l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
19310
+
19311
+ a += l & 0xffff; b += l >>> 16;
19312
+ c += h & 0xffff; d += h >>> 16;
19313
+
19314
+ // Maj
19315
+ h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
19316
+ l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
19317
+
19318
+ a += l & 0xffff; b += l >>> 16;
19319
+ c += h & 0xffff; d += h >>> 16;
19320
+
19321
+ b += a >>> 16;
19322
+ c += b >>> 16;
19323
+ d += c >>> 16;
19324
+
19325
+ bh7 = (c & 0xffff) | (d << 16);
19326
+ bl7 = (a & 0xffff) | (b << 16);
19327
+
19328
+ // add
19329
+ h = bh3;
19330
+ l = bl3;
19331
+
19332
+ a = l & 0xffff; b = l >>> 16;
19333
+ c = h & 0xffff; d = h >>> 16;
19334
+
19335
+ h = th;
19336
+ l = tl;
19337
+
19338
+ a += l & 0xffff; b += l >>> 16;
19339
+ c += h & 0xffff; d += h >>> 16;
19340
+
19341
+ b += a >>> 16;
19342
+ c += b >>> 16;
19343
+ d += c >>> 16;
19344
+
19345
+ bh3 = (c & 0xffff) | (d << 16);
19346
+ bl3 = (a & 0xffff) | (b << 16);
19347
+
19348
+ ah1 = bh0;
19349
+ ah2 = bh1;
19350
+ ah3 = bh2;
19351
+ ah4 = bh3;
19352
+ ah5 = bh4;
19353
+ ah6 = bh5;
19354
+ ah7 = bh6;
19355
+ ah0 = bh7;
19356
+
19357
+ al1 = bl0;
19358
+ al2 = bl1;
19359
+ al3 = bl2;
19360
+ al4 = bl3;
19361
+ al5 = bl4;
19362
+ al6 = bl5;
19363
+ al7 = bl6;
19364
+ al0 = bl7;
19365
+
19366
+ if (i%16 === 15) {
19367
+ for (j = 0; j < 16; j++) {
19368
+ // add
19369
+ h = wh[j];
19370
+ l = wl[j];
19371
+
19372
+ a = l & 0xffff; b = l >>> 16;
19373
+ c = h & 0xffff; d = h >>> 16;
19374
+
19375
+ h = wh[(j+9)%16];
19376
+ l = wl[(j+9)%16];
19377
+
19378
+ a += l & 0xffff; b += l >>> 16;
19379
+ c += h & 0xffff; d += h >>> 16;
19380
+
19381
+ // sigma0
19382
+ th = wh[(j+1)%16];
19383
+ tl = wl[(j+1)%16];
19384
+ h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
19385
+ l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
19386
+
19387
+ a += l & 0xffff; b += l >>> 16;
19388
+ c += h & 0xffff; d += h >>> 16;
19389
+
19390
+ // sigma1
19391
+ th = wh[(j+14)%16];
19392
+ tl = wl[(j+14)%16];
19393
+ h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
19394
+ l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
19395
+
19396
+ a += l & 0xffff; b += l >>> 16;
19397
+ c += h & 0xffff; d += h >>> 16;
19398
+
19399
+ b += a >>> 16;
19400
+ c += b >>> 16;
19401
+ d += c >>> 16;
19402
+
19403
+ wh[j] = (c & 0xffff) | (d << 16);
19404
+ wl[j] = (a & 0xffff) | (b << 16);
19405
+ }
19406
+ }
19407
+ }
19408
+
19409
+ // add
19410
+ h = ah0;
19411
+ l = al0;
19412
+
19413
+ a = l & 0xffff; b = l >>> 16;
19414
+ c = h & 0xffff; d = h >>> 16;
19415
+
19416
+ h = hh[0];
19417
+ l = hl[0];
19418
+
19419
+ a += l & 0xffff; b += l >>> 16;
19420
+ c += h & 0xffff; d += h >>> 16;
19421
+
19422
+ b += a >>> 16;
19423
+ c += b >>> 16;
19424
+ d += c >>> 16;
19425
+
19426
+ hh[0] = ah0 = (c & 0xffff) | (d << 16);
19427
+ hl[0] = al0 = (a & 0xffff) | (b << 16);
19428
+
19429
+ h = ah1;
19430
+ l = al1;
19431
+
19432
+ a = l & 0xffff; b = l >>> 16;
19433
+ c = h & 0xffff; d = h >>> 16;
19434
+
19435
+ h = hh[1];
19436
+ l = hl[1];
19437
+
19438
+ a += l & 0xffff; b += l >>> 16;
19439
+ c += h & 0xffff; d += h >>> 16;
19440
+
19441
+ b += a >>> 16;
19442
+ c += b >>> 16;
19443
+ d += c >>> 16;
19444
+
19445
+ hh[1] = ah1 = (c & 0xffff) | (d << 16);
19446
+ hl[1] = al1 = (a & 0xffff) | (b << 16);
19447
+
19448
+ h = ah2;
19449
+ l = al2;
19450
+
19451
+ a = l & 0xffff; b = l >>> 16;
19452
+ c = h & 0xffff; d = h >>> 16;
19453
+
19454
+ h = hh[2];
19455
+ l = hl[2];
19456
+
19457
+ a += l & 0xffff; b += l >>> 16;
19458
+ c += h & 0xffff; d += h >>> 16;
19459
+
19460
+ b += a >>> 16;
19461
+ c += b >>> 16;
19462
+ d += c >>> 16;
19463
+
19464
+ hh[2] = ah2 = (c & 0xffff) | (d << 16);
19465
+ hl[2] = al2 = (a & 0xffff) | (b << 16);
19466
+
19467
+ h = ah3;
19468
+ l = al3;
19469
+
19470
+ a = l & 0xffff; b = l >>> 16;
19471
+ c = h & 0xffff; d = h >>> 16;
19472
+
19473
+ h = hh[3];
19474
+ l = hl[3];
19475
+
19476
+ a += l & 0xffff; b += l >>> 16;
19477
+ c += h & 0xffff; d += h >>> 16;
19478
+
19479
+ b += a >>> 16;
19480
+ c += b >>> 16;
19481
+ d += c >>> 16;
19482
+
19483
+ hh[3] = ah3 = (c & 0xffff) | (d << 16);
19484
+ hl[3] = al3 = (a & 0xffff) | (b << 16);
19485
+
19486
+ h = ah4;
19487
+ l = al4;
19488
+
19489
+ a = l & 0xffff; b = l >>> 16;
19490
+ c = h & 0xffff; d = h >>> 16;
19491
+
19492
+ h = hh[4];
19493
+ l = hl[4];
19494
+
19495
+ a += l & 0xffff; b += l >>> 16;
19496
+ c += h & 0xffff; d += h >>> 16;
19497
+
19498
+ b += a >>> 16;
19499
+ c += b >>> 16;
19500
+ d += c >>> 16;
19501
+
19502
+ hh[4] = ah4 = (c & 0xffff) | (d << 16);
19503
+ hl[4] = al4 = (a & 0xffff) | (b << 16);
19504
+
19505
+ h = ah5;
19506
+ l = al5;
19507
+
19508
+ a = l & 0xffff; b = l >>> 16;
19509
+ c = h & 0xffff; d = h >>> 16;
19510
+
19511
+ h = hh[5];
19512
+ l = hl[5];
19513
+
19514
+ a += l & 0xffff; b += l >>> 16;
19515
+ c += h & 0xffff; d += h >>> 16;
19516
+
19517
+ b += a >>> 16;
19518
+ c += b >>> 16;
19519
+ d += c >>> 16;
19520
+
19521
+ hh[5] = ah5 = (c & 0xffff) | (d << 16);
19522
+ hl[5] = al5 = (a & 0xffff) | (b << 16);
19523
+
19524
+ h = ah6;
19525
+ l = al6;
19526
+
19527
+ a = l & 0xffff; b = l >>> 16;
19528
+ c = h & 0xffff; d = h >>> 16;
19529
+
19530
+ h = hh[6];
19531
+ l = hl[6];
19532
+
19533
+ a += l & 0xffff; b += l >>> 16;
19534
+ c += h & 0xffff; d += h >>> 16;
19535
+
19536
+ b += a >>> 16;
19537
+ c += b >>> 16;
19538
+ d += c >>> 16;
19539
+
19540
+ hh[6] = ah6 = (c & 0xffff) | (d << 16);
19541
+ hl[6] = al6 = (a & 0xffff) | (b << 16);
19542
+
19543
+ h = ah7;
19544
+ l = al7;
19545
+
19546
+ a = l & 0xffff; b = l >>> 16;
19547
+ c = h & 0xffff; d = h >>> 16;
19548
+
19549
+ h = hh[7];
19550
+ l = hl[7];
19551
+
19552
+ a += l & 0xffff; b += l >>> 16;
19553
+ c += h & 0xffff; d += h >>> 16;
19554
+
19555
+ b += a >>> 16;
19556
+ c += b >>> 16;
19557
+ d += c >>> 16;
19558
+
19559
+ hh[7] = ah7 = (c & 0xffff) | (d << 16);
19560
+ hl[7] = al7 = (a & 0xffff) | (b << 16);
19561
+
19562
+ pos += 128;
19563
+ n -= 128;
19564
+ }
19565
+
19566
+ return n;
19567
+ }
19568
+
19569
+ function crypto_hash(out, m, n) {
19570
+ var hh = new Int32Array(8),
19571
+ hl = new Int32Array(8),
19572
+ x = new Uint8Array(256),
19573
+ i, b = n;
19574
+
19575
+ hh[0] = 0x6a09e667;
19576
+ hh[1] = 0xbb67ae85;
19577
+ hh[2] = 0x3c6ef372;
19578
+ hh[3] = 0xa54ff53a;
19579
+ hh[4] = 0x510e527f;
19580
+ hh[5] = 0x9b05688c;
19581
+ hh[6] = 0x1f83d9ab;
19582
+ hh[7] = 0x5be0cd19;
19583
+
19584
+ hl[0] = 0xf3bcc908;
19585
+ hl[1] = 0x84caa73b;
19586
+ hl[2] = 0xfe94f82b;
19587
+ hl[3] = 0x5f1d36f1;
19588
+ hl[4] = 0xade682d1;
19589
+ hl[5] = 0x2b3e6c1f;
19590
+ hl[6] = 0xfb41bd6b;
19591
+ hl[7] = 0x137e2179;
19592
+
19593
+ crypto_hashblocks_hl(hh, hl, m, n);
19594
+ n %= 128;
19595
+
19596
+ for (i = 0; i < n; i++) x[i] = m[b-n+i];
19597
+ x[n] = 128;
19598
+
19599
+ n = 256-128*(n<112?1:0);
19600
+ x[n-9] = 0;
19601
+ ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
19602
+ crypto_hashblocks_hl(hh, hl, x, n);
19603
+
19604
+ for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
19605
+
19606
+ return 0;
19607
+ }
19608
+
19609
+ function add(p, q) {
19610
+ var a = gf(), b = gf(), c = gf(),
19611
+ d = gf(), e = gf(), f = gf(),
19612
+ g = gf(), h = gf(), t = gf();
19613
+
19614
+ Z(a, p[1], p[0]);
19615
+ Z(t, q[1], q[0]);
19616
+ M(a, a, t);
19617
+ A(b, p[0], p[1]);
19618
+ A(t, q[0], q[1]);
19619
+ M(b, b, t);
19620
+ M(c, p[3], q[3]);
19621
+ M(c, c, D2);
19622
+ M(d, p[2], q[2]);
19623
+ A(d, d, d);
19624
+ Z(e, b, a);
19625
+ Z(f, d, c);
19626
+ A(g, d, c);
19627
+ A(h, b, a);
19628
+
19629
+ M(p[0], e, f);
19630
+ M(p[1], h, g);
19631
+ M(p[2], g, f);
19632
+ M(p[3], e, h);
19633
+ }
19634
+
19635
+ function cswap(p, q, b) {
19636
+ var i;
19637
+ for (i = 0; i < 4; i++) {
19638
+ sel25519(p[i], q[i], b);
19639
+ }
19640
+ }
19641
+
19642
+ function pack(r, p) {
19643
+ var tx = gf(), ty = gf(), zi = gf();
19644
+ inv25519(zi, p[2]);
19645
+ M(tx, p[0], zi);
19646
+ M(ty, p[1], zi);
19647
+ pack25519(r, ty);
19648
+ r[31] ^= par25519(tx) << 7;
19649
+ }
19650
+
19651
+ function scalarmult(p, q, s) {
19652
+ var b, i;
19653
+ set25519(p[0], gf0);
19654
+ set25519(p[1], gf1);
19655
+ set25519(p[2], gf1);
19656
+ set25519(p[3], gf0);
19657
+ for (i = 255; i >= 0; --i) {
19658
+ b = (s[(i/8)|0] >> (i&7)) & 1;
19659
+ cswap(p, q, b);
19660
+ add(q, p);
19661
+ add(p, p);
19662
+ cswap(p, q, b);
19663
+ }
19664
+ }
19665
+
19666
+ function scalarbase(p, s) {
19667
+ var q = [gf(), gf(), gf(), gf()];
19668
+ set25519(q[0], X);
19669
+ set25519(q[1], Y);
19670
+ set25519(q[2], gf1);
19671
+ M(q[3], X, Y);
19672
+ scalarmult(p, q, s);
19673
+ }
19674
+
19675
+ function crypto_sign_keypair(pk, sk, seeded) {
19676
+ var d = new Uint8Array(64);
19677
+ var p = [gf(), gf(), gf(), gf()];
19678
+ var i;
19679
+
19680
+ if (!seeded) randombytes(sk, 32);
19681
+ crypto_hash(d, sk, 32);
19682
+ d[0] &= 248;
19683
+ d[31] &= 127;
19684
+ d[31] |= 64;
19685
+
19686
+ scalarbase(p, d);
19687
+ pack(pk, p);
19688
+
19689
+ for (i = 0; i < 32; i++) sk[i+32] = pk[i];
19690
+ return 0;
19691
+ }
19692
+
19693
+ 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]);
19694
+
19695
+ function modL(r, x) {
19696
+ var carry, i, j, k;
19697
+ for (i = 63; i >= 32; --i) {
19698
+ carry = 0;
19699
+ for (j = i - 32, k = i - 12; j < k; ++j) {
19700
+ x[j] += carry - 16 * x[i] * L[j - (i - 32)];
19701
+ carry = Math.floor((x[j] + 128) / 256);
19702
+ x[j] -= carry * 256;
19703
+ }
19704
+ x[j] += carry;
19705
+ x[i] = 0;
19706
+ }
19707
+ carry = 0;
19708
+ for (j = 0; j < 32; j++) {
19709
+ x[j] += carry - (x[31] >> 4) * L[j];
19710
+ carry = x[j] >> 8;
19711
+ x[j] &= 255;
19712
+ }
19713
+ for (j = 0; j < 32; j++) x[j] -= carry * L[j];
19714
+ for (i = 0; i < 32; i++) {
19715
+ x[i+1] += x[i] >> 8;
19716
+ r[i] = x[i] & 255;
19717
+ }
19718
+ }
19719
+
19720
+ function reduce(r) {
19721
+ var x = new Float64Array(64), i;
19722
+ for (i = 0; i < 64; i++) x[i] = r[i];
19723
+ for (i = 0; i < 64; i++) r[i] = 0;
19724
+ modL(r, x);
19725
+ }
19726
+
19727
+ // Note: difference from C - smlen returned, not passed as argument.
19728
+ function crypto_sign(sm, m, n, sk) {
19729
+ var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
19730
+ var i, j, x = new Float64Array(64);
19731
+ var p = [gf(), gf(), gf(), gf()];
19732
+
19733
+ crypto_hash(d, sk, 32);
19734
+ d[0] &= 248;
19735
+ d[31] &= 127;
19736
+ d[31] |= 64;
19737
+
19738
+ var smlen = n + 64;
19739
+ for (i = 0; i < n; i++) sm[64 + i] = m[i];
19740
+ for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
19741
+
19742
+ crypto_hash(r, sm.subarray(32), n+32);
19743
+ reduce(r);
19744
+ scalarbase(p, r);
19745
+ pack(sm, p);
19746
+
19747
+ for (i = 32; i < 64; i++) sm[i] = sk[i];
19748
+ crypto_hash(h, sm, n + 64);
19749
+ reduce(h);
19750
+
19751
+ for (i = 0; i < 64; i++) x[i] = 0;
19752
+ for (i = 0; i < 32; i++) x[i] = r[i];
19753
+ for (i = 0; i < 32; i++) {
19754
+ for (j = 0; j < 32; j++) {
19755
+ x[i+j] += h[i] * d[j];
19756
+ }
19757
+ }
19758
+
19759
+ modL(sm.subarray(32), x);
19760
+ return smlen;
19761
+ }
19762
+
19763
+ function unpackneg(r, p) {
19764
+ var t = gf(), chk = gf(), num = gf(),
19765
+ den = gf(), den2 = gf(), den4 = gf(),
19766
+ den6 = gf();
19767
+
19768
+ set25519(r[2], gf1);
19769
+ unpack25519(r[1], p);
19770
+ S(num, r[1]);
19771
+ M(den, num, D);
19772
+ Z(num, num, r[2]);
19773
+ A(den, r[2], den);
19774
+
19775
+ S(den2, den);
19776
+ S(den4, den2);
19777
+ M(den6, den4, den2);
19778
+ M(t, den6, num);
19779
+ M(t, t, den);
19780
+
19781
+ pow2523(t, t);
19782
+ M(t, t, num);
19783
+ M(t, t, den);
19784
+ M(t, t, den);
19785
+ M(r[0], t, den);
19786
+
19787
+ S(chk, r[0]);
19788
+ M(chk, chk, den);
19789
+ if (neq25519(chk, num)) M(r[0], r[0], I);
19790
+
19791
+ S(chk, r[0]);
19792
+ M(chk, chk, den);
19793
+ if (neq25519(chk, num)) return -1;
19794
+
19795
+ if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
19796
+
19797
+ M(r[3], r[0], r[1]);
19798
+ return 0;
19799
+ }
19800
+
19801
+ function crypto_sign_open(m, sm, n, pk) {
19802
+ var i;
19803
+ var t = new Uint8Array(32), h = new Uint8Array(64);
19804
+ var p = [gf(), gf(), gf(), gf()],
19805
+ q = [gf(), gf(), gf(), gf()];
19806
+
19807
+ if (n < 64) return -1;
19808
+
19809
+ if (unpackneg(q, pk)) return -1;
19810
+
19811
+ for (i = 0; i < n; i++) m[i] = sm[i];
19812
+ for (i = 0; i < 32; i++) m[i+32] = pk[i];
19813
+ crypto_hash(h, m, n);
19814
+ reduce(h);
19815
+ scalarmult(p, q, h);
19816
+
19817
+ scalarbase(q, sm.subarray(32));
19818
+ add(p, q);
19819
+ pack(t, p);
19820
+
19821
+ n -= 64;
19822
+ if (crypto_verify_32(sm, 0, t, 0)) {
19823
+ for (i = 0; i < n; i++) m[i] = 0;
19824
+ return -1;
19825
+ }
19826
+
19827
+ for (i = 0; i < n; i++) m[i] = sm[i + 64];
19828
+ return n;
19829
+ }
19830
+
19831
+ var crypto_secretbox_KEYBYTES = 32,
19832
+ crypto_secretbox_NONCEBYTES = 24,
19833
+ crypto_secretbox_ZEROBYTES = 32,
19834
+ crypto_secretbox_BOXZEROBYTES = 16,
19835
+ crypto_scalarmult_BYTES = 32,
19836
+ crypto_scalarmult_SCALARBYTES = 32,
19837
+ crypto_box_PUBLICKEYBYTES = 32,
19838
+ crypto_box_SECRETKEYBYTES = 32,
19839
+ crypto_box_BEFORENMBYTES = 32,
19840
+ crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
19841
+ crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
19842
+ crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
19843
+ crypto_sign_BYTES = 64,
19844
+ crypto_sign_PUBLICKEYBYTES = 32,
19845
+ crypto_sign_SECRETKEYBYTES = 64,
19846
+ crypto_sign_SEEDBYTES = 32,
19847
+ crypto_hash_BYTES = 64;
19848
+
19849
+ nacl.lowlevel = {
19850
+ crypto_core_hsalsa20: crypto_core_hsalsa20,
19851
+ crypto_stream_xor: crypto_stream_xor,
19852
+ crypto_stream: crypto_stream,
19853
+ crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
19854
+ crypto_stream_salsa20: crypto_stream_salsa20,
19855
+ crypto_onetimeauth: crypto_onetimeauth,
19856
+ crypto_onetimeauth_verify: crypto_onetimeauth_verify,
19857
+ crypto_verify_16: crypto_verify_16,
19858
+ crypto_verify_32: crypto_verify_32,
19859
+ crypto_secretbox: crypto_secretbox,
19860
+ crypto_secretbox_open: crypto_secretbox_open,
19861
+ crypto_scalarmult: crypto_scalarmult,
19862
+ crypto_scalarmult_base: crypto_scalarmult_base,
19863
+ crypto_box_beforenm: crypto_box_beforenm,
19864
+ crypto_box_afternm: crypto_box_afternm,
19865
+ crypto_box: crypto_box,
19866
+ crypto_box_open: crypto_box_open,
19867
+ crypto_box_keypair: crypto_box_keypair,
19868
+ crypto_hash: crypto_hash,
19869
+ crypto_sign: crypto_sign,
19870
+ crypto_sign_keypair: crypto_sign_keypair,
19871
+ crypto_sign_open: crypto_sign_open,
19872
+
19873
+ crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
19874
+ crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
19875
+ crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
19876
+ crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
19877
+ crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
19878
+ crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
19879
+ crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
19880
+ crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
19881
+ crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
19882
+ crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
19883
+ crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
19884
+ crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
19885
+ crypto_sign_BYTES: crypto_sign_BYTES,
19886
+ crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
19887
+ crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
19888
+ crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
19889
+ crypto_hash_BYTES: crypto_hash_BYTES,
19890
+
19891
+ gf: gf,
19892
+ D: D,
19893
+ L: L,
19894
+ pack25519: pack25519,
19895
+ unpack25519: unpack25519,
19896
+ M: M,
19897
+ A: A,
19898
+ S: S,
19899
+ Z: Z,
19900
+ pow2523: pow2523,
19901
+ add: add,
19902
+ set25519: set25519,
19903
+ modL: modL,
19904
+ scalarmult: scalarmult,
19905
+ scalarbase: scalarbase,
19906
+ };
19907
+
19908
+ /* High-level API */
19909
+
19910
+ function checkLengths(k, n) {
19911
+ if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
19912
+ if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
19913
+ }
19914
+
19915
+ function checkBoxLengths(pk, sk) {
19916
+ if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
19917
+ if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
19918
+ }
19919
+
19920
+ function checkArrayTypes() {
19921
+ for (var i = 0; i < arguments.length; i++) {
19922
+ if (!(arguments[i] instanceof Uint8Array))
19923
+ throw new TypeError('unexpected type, use Uint8Array');
19924
+ }
19925
+ }
19926
+
19927
+ function cleanup(arr) {
19928
+ for (var i = 0; i < arr.length; i++) arr[i] = 0;
19929
+ }
19930
+
19931
+ nacl.randomBytes = function(n) {
19932
+ var b = new Uint8Array(n);
19933
+ randombytes(b, n);
19934
+ return b;
19935
+ };
19936
+
19937
+ nacl.secretbox = function(msg, nonce, key) {
19938
+ checkArrayTypes(msg, nonce, key);
19939
+ checkLengths(key, nonce);
19940
+ var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
19941
+ var c = new Uint8Array(m.length);
19942
+ for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
19943
+ crypto_secretbox(c, m, m.length, nonce, key);
19944
+ return c.subarray(crypto_secretbox_BOXZEROBYTES);
19945
+ };
19946
+
19947
+ nacl.secretbox.open = function(box, nonce, key) {
19948
+ checkArrayTypes(box, nonce, key);
19949
+ checkLengths(key, nonce);
19950
+ var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
19951
+ var m = new Uint8Array(c.length);
19952
+ for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
19953
+ if (c.length < 32) return null;
19954
+ if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
19955
+ return m.subarray(crypto_secretbox_ZEROBYTES);
19956
+ };
19957
+
19958
+ nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
19959
+ nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
19960
+ nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
19961
+
19962
+ nacl.scalarMult = function(n, p) {
19963
+ checkArrayTypes(n, p);
19964
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
19965
+ if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
19966
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
19967
+ crypto_scalarmult(q, n, p);
19968
+ return q;
19969
+ };
19970
+
19971
+ nacl.scalarMult.base = function(n) {
19972
+ checkArrayTypes(n);
19973
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
19974
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
19975
+ crypto_scalarmult_base(q, n);
19976
+ return q;
19977
+ };
19978
+
19979
+ nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
19980
+ nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
19981
+
19982
+ nacl.box = function(msg, nonce, publicKey, secretKey) {
19983
+ var k = nacl.box.before(publicKey, secretKey);
19984
+ return nacl.secretbox(msg, nonce, k);
19985
+ };
19986
+
19987
+ nacl.box.before = function(publicKey, secretKey) {
19988
+ checkArrayTypes(publicKey, secretKey);
19989
+ checkBoxLengths(publicKey, secretKey);
19990
+ var k = new Uint8Array(crypto_box_BEFORENMBYTES);
19991
+ crypto_box_beforenm(k, publicKey, secretKey);
19992
+ return k;
19993
+ };
19994
+
19995
+ nacl.box.after = nacl.secretbox;
19996
+
19997
+ nacl.box.open = function(msg, nonce, publicKey, secretKey) {
19998
+ var k = nacl.box.before(publicKey, secretKey);
19999
+ return nacl.secretbox.open(msg, nonce, k);
20000
+ };
20001
+
20002
+ nacl.box.open.after = nacl.secretbox.open;
20003
+
20004
+ nacl.box.keyPair = function() {
20005
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
20006
+ var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
20007
+ crypto_box_keypair(pk, sk);
20008
+ return {publicKey: pk, secretKey: sk};
20009
+ };
20010
+
20011
+ nacl.box.keyPair.fromSecretKey = function(secretKey) {
20012
+ checkArrayTypes(secretKey);
20013
+ if (secretKey.length !== crypto_box_SECRETKEYBYTES)
20014
+ throw new Error('bad secret key size');
20015
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
20016
+ crypto_scalarmult_base(pk, secretKey);
20017
+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
20018
+ };
20019
+
20020
+ nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
20021
+ nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
20022
+ nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
20023
+ nacl.box.nonceLength = crypto_box_NONCEBYTES;
20024
+ nacl.box.overheadLength = nacl.secretbox.overheadLength;
20025
+
20026
+ nacl.sign = function(msg, secretKey) {
20027
+ checkArrayTypes(msg, secretKey);
20028
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
20029
+ throw new Error('bad secret key size');
20030
+ var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
20031
+ crypto_sign(signedMsg, msg, msg.length, secretKey);
20032
+ return signedMsg;
20033
+ };
20034
+
20035
+ nacl.sign.open = function(signedMsg, publicKey) {
20036
+ checkArrayTypes(signedMsg, publicKey);
20037
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
20038
+ throw new Error('bad public key size');
20039
+ var tmp = new Uint8Array(signedMsg.length);
20040
+ var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
20041
+ if (mlen < 0) return null;
20042
+ var m = new Uint8Array(mlen);
20043
+ for (var i = 0; i < m.length; i++) m[i] = tmp[i];
20044
+ return m;
20045
+ };
20046
+
20047
+ nacl.sign.detached = function(msg, secretKey) {
20048
+ var signedMsg = nacl.sign(msg, secretKey);
20049
+ var sig = new Uint8Array(crypto_sign_BYTES);
20050
+ for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
20051
+ return sig;
20052
+ };
20053
+
20054
+ nacl.sign.detached.verify = function(msg, sig, publicKey) {
20055
+ checkArrayTypes(msg, sig, publicKey);
20056
+ if (sig.length !== crypto_sign_BYTES)
20057
+ throw new Error('bad signature size');
20058
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
20059
+ throw new Error('bad public key size');
20060
+ var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
20061
+ var m = new Uint8Array(crypto_sign_BYTES + msg.length);
20062
+ var i;
20063
+ for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
20064
+ for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
20065
+ return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
20066
+ };
20067
+
20068
+ nacl.sign.keyPair = function() {
20069
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
20070
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
20071
+ crypto_sign_keypair(pk, sk);
20072
+ return {publicKey: pk, secretKey: sk};
20073
+ };
20074
+
20075
+ nacl.sign.keyPair.fromSecretKey = function(secretKey) {
20076
+ checkArrayTypes(secretKey);
20077
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
20078
+ throw new Error('bad secret key size');
20079
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
20080
+ for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
20081
+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
20082
+ };
20083
+
20084
+ nacl.sign.keyPair.fromSeed = function(seed) {
20085
+ checkArrayTypes(seed);
20086
+ if (seed.length !== crypto_sign_SEEDBYTES)
20087
+ throw new Error('bad seed size');
20088
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
20089
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
20090
+ for (var i = 0; i < 32; i++) sk[i] = seed[i];
20091
+ crypto_sign_keypair(pk, sk, true);
20092
+ return {publicKey: pk, secretKey: sk};
20093
+ };
20094
+
20095
+ nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
20096
+ nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
20097
+ nacl.sign.seedLength = crypto_sign_SEEDBYTES;
20098
+ nacl.sign.signatureLength = crypto_sign_BYTES;
20099
+
20100
+ nacl.hash = function(msg) {
20101
+ checkArrayTypes(msg);
20102
+ var h = new Uint8Array(crypto_hash_BYTES);
20103
+ crypto_hash(h, msg, msg.length);
20104
+ return h;
20105
+ };
20106
+
20107
+ nacl.hash.hashLength = crypto_hash_BYTES;
20108
+
20109
+ nacl.verify = function(x, y) {
20110
+ checkArrayTypes(x, y);
20111
+ // Zero length arguments are considered not equal.
20112
+ if (x.length === 0 || y.length === 0) return false;
20113
+ if (x.length !== y.length) return false;
20114
+ return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
20115
+ };
20116
+
20117
+ nacl.setPRNG = function(fn) {
20118
+ randombytes = fn;
20119
+ };
20120
+
20121
+ (function() {
20122
+ // Initialize PRNG if environment provides CSPRNG.
20123
+ // If not, methods calling randombytes will throw.
20124
+ var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
20125
+ if (crypto && crypto.getRandomValues) {
20126
+ // Browsers.
20127
+ var QUOTA = 65536;
20128
+ nacl.setPRNG(function(x, n) {
20129
+ var i, v = new Uint8Array(n);
20130
+ for (i = 0; i < n; i += QUOTA) {
20131
+ crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
20132
+ }
20133
+ for (i = 0; i < n; i++) x[i] = v[i];
20134
+ cleanup(v);
20135
+ });
20136
+ } else if (typeof commonjsRequire !== 'undefined') {
20137
+ // Node.js.
20138
+ crypto = require$$0;
20139
+ if (crypto && crypto.randomBytes) {
20140
+ nacl.setPRNG(function(x, n) {
20141
+ var i, v = crypto.randomBytes(n);
20142
+ for (i = 0; i < n; i++) x[i] = v[i];
20143
+ cleanup(v);
20144
+ });
20145
+ }
20146
+ }
20147
+ })();
20148
+
20149
+ })(module.exports ? module.exports : (self.nacl = self.nacl || {}));
20150
+ } (naclFast));
20151
+ return naclFast.exports;
20152
+ }
20153
+
20154
+ var naclFastExports = requireNaclFast();
20155
+ var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
20156
+
17696
20157
  // guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
17697
20158
  //
17698
20159
  // A guest is an ed25519 keypair generated on the device. Its public key is the
@@ -17763,7 +20224,7 @@ async function tryWebCrypto() {
17763
20224
  await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed
17764
20225
  }
17765
20226
  const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable
17766
- const address = base58.encode(raw);
20227
+ const address = bs582.encode(raw);
17767
20228
  return {
17768
20229
  address,
17769
20230
  nonExtractable: true,
@@ -17784,12 +20245,12 @@ function fallbackKey() {
17784
20245
  let secret;
17785
20246
  const saved = store.getItem(FALLBACK_STORE_KEY);
17786
20247
  if (saved) {
17787
- secret = base58.decode(saved);
20248
+ secret = bs582.decode(saved);
17788
20249
  }
17789
20250
  else {
17790
20251
  const kp = Keypair.generate();
17791
20252
  secret = kp.secretKey; // 64 bytes
17792
- store.setItem(FALLBACK_STORE_KEY, base58.encode(secret));
20253
+ store.setItem(FALLBACK_STORE_KEY, bs582.encode(secret));
17793
20254
  }
17794
20255
  const kp = Keypair.fromSecretKey(secret);
17795
20256
  const address = kp.publicKey.toBase58();
@@ -18524,7 +20985,7 @@ let currentAuthProvider = null;
18524
20985
  let currentAuthMethod = null;
18525
20986
  let initConfig = null;
18526
20987
  // --- localStorage helpers: track which auth method the user last logged in with ---
18527
- const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
20988
+ const STORED_AUTH_METHOD_KEY = 'bounded_last_auth_method';
18528
20989
  function getStoredAuthMethod() {
18529
20990
  try {
18530
20991
  return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY);
@@ -18572,17 +21033,17 @@ function clearIncompatibleSession() {
18572
21033
  // Lazy loaders for web-only providers.
18573
21034
  // Using dynamic import() ensures Metro (RN) never resolves these modules.
18574
21035
  async function loadPhantomWalletProvider() {
18575
- const mod = await import('./phantom-wallet-provider-DMlaSrAl.esm.js');
21036
+ const mod = await import('./phantom-wallet-provider-CTossIFB.esm.js');
18576
21037
  return { PhantomWalletProvider: mod.PhantomWalletProvider };
18577
21038
  }
18578
21039
  // Web Privy provider (depends on react-dom + @privy-io/react-auth). Lazy so Metro
18579
21040
  // never bundles it into the RN build — RN uses the @privy-io/expo provider instead.
18580
21041
  async function loadPrivyWalletProvider() {
18581
- const mod = await import('./privy-wallet-provider-nR52lXzI.esm.js');
21042
+ const mod = await import('./privy-wallet-provider-1qE_f-DF.esm.js');
18582
21043
  return mod.PrivyWalletProvider;
18583
21044
  }
18584
21045
  async function loadSolanaMobileWalletProvider() {
18585
- const mod = await import('./solana-mobile-wallet-provider-B4CeMMQd.esm.js');
21046
+ const mod = await import('./solana-mobile-wallet-provider-9M8U6AA7.esm.js');
18586
21047
  return mod.SolanaMobileWalletProvider;
18587
21048
  }
18588
21049
  async function hotSwapToMWAProvider(config) {
@@ -19302,7 +21763,7 @@ class PrivyExpoProvider {
19302
21763
  if (!wallet) {
19303
21764
  throw new Error('No embedded Solana wallet found after login. Ensure embeddedWallets.solana.createOnLogin is configured.');
19304
21765
  }
19305
- // Mint a Tarobase session by having the Privy Solana wallet sign the
21766
+ // Mint a Bounded session by having the Privy Solana wallet sign the
19306
21767
  // standard SIWS challenge — identical to Phantom/MWA, so the backend mints
19307
21768
  // the session via the proven wallet-signature path (no Privy-specific
19308
21769
  // token verification needed).
@@ -19322,8 +21783,8 @@ class PrivyExpoProvider {
19322
21783
  const connection = new Connection(rpcUrl, 'confirmed');
19323
21784
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
19324
21785
  let app_id = solTransactionData.appId;
19325
- if (typeof globalThis !== 'undefined' && globalThis.CUSTOM_TAROBASE_APP_ID_HEADER) {
19326
- app_id = globalThis.CUSTOM_TAROBASE_APP_ID_HEADER;
21786
+ if (typeof globalThis !== 'undefined' && globalThis.CUSTOM_BOUNDED_APP_ID_HEADER) {
21787
+ app_id = globalThis.CUSTOM_BOUNDED_APP_ID_HEADER;
19327
21788
  }
19328
21789
  if (!app_id) {
19329
21790
  throw new Error('App ID is required');
@@ -19393,7 +21854,7 @@ class PrivyExpoProvider {
19393
21854
  const wallet = await this.getWalletOrThrow();
19394
21855
  const messageBytes = getPlatform().textEncode(message);
19395
21856
  const result = await wallet.signMessage(messageBytes);
19396
- return base58.encode(result.signature);
21857
+ return bs582.encode(result.signature);
19397
21858
  }
19398
21859
  async signTransaction(transaction) {
19399
21860
  await this.ensureReady();
@@ -19477,7 +21938,7 @@ class PrivyExpoProvider {
19477
21938
  // Private helpers
19478
21939
  // -------------------------------------------------------------------
19479
21940
  /**
19480
- * Mint a Tarobase session from a Privy Solana wallet by signing the canonical
21941
+ * Mint a Bounded session from a Privy Solana wallet by signing the canonical
19481
21942
  * SIWS challenge (nonce -> genSolanaMessage -> wallet.signMessage). This reuses
19482
21943
  * createSessionWithSignature — the exact path Phantom, the mobile wallet
19483
21944
  * adapter, and the guest device-key use — so the bounded /session issuer mints
@@ -19561,5 +22022,5 @@ class PrivyExpoProvider {
19561
22022
  }
19562
22023
  }
19563
22024
 
19564
- export { aggregate as $, signInAnonymously as A, sendEmailOtp as B, verifyEmailOtp as C, linkEmail as D, loginWithPrivy as E, loginWithRedirect as F, linkWithRedirect as G, completeLoginFromRedirect as H, loginWithPopup as I, completeLoginInPopup as J, get as K, set as L, setMany as M, setFile as N, getFiles as O, search as P, queryAggregate as Q, runQuery as R, SOLANA_DEVNET_RPC_URL as S, runQueryMany as T, runExpression as U, runExpressionMany as V, WebSessionManager as W, signMessage as X, signTransaction as Y, signAndSubmitTransaction as Z, count as _, buildSetDocumentsTransaction as a, subscribe as a0, useAuth as a1, deserializeTransaction as a2, getIdToken as a3, setPlatform as a4, MockAuthProvider as a5, DEFAULT_TEST_ADDRESS as a6, OffchainAuthProvider as a7, PrivyExpoProvider as a8, EFFECT_INTENT_ADDRESS as a9, signSessionCreateMessage as aA, subscribeView as aB, withEffects as aC, wsDelete as aD, wsGet as aE, wsGetMany as aF, wsQuery as aG, wsSet as aH, index as aI, FunctionInvokeError as aa, InsufficientBalanceError as ab, LiveIntentError as ac, ReactNativeSessionManager as ad, RealtimeStore as ae, ServerSessionManager as af, clearCache as ag, closeAllSubscriptions as ah, defineLiveModule as ai, deriveUserIdentityFromIdToken as aj, functions as ak, getCachedData as al, getMany as am, getRealtimeStore as an, getWebhookKeysUrl as ao, hasActiveConnection as ap, increment as aq, invoke as ar, isEffectResult as as, live as at, intent as au, reconnectWithNewAuth as av, refreshSession as aw, resetRealtimeStore as ax, revokeSession as ay, serverTimestamp as az, bufferExports as b, convertRemainingAccounts as c, confirmAndCheckTransaction as d, SOLANA_MAINNET_RPC_URL as e, SURFNET_RPC_URL$1 as f, detectMobile as g, detectAndroid as h, getPlatform as i, setAuthLoading as j, genAuthNonce as k, genSolanaMessage as l, createSessionWithSignature as m, getActiveSessionManager as n, base58 as o, getDefaultExportFromCjs$1 as p, init as q, getCurrentUser as r, setCurrentUser as s, onAuthStateChanged as t, onAuthLoadingChanged as u, getAuthLoading as v, login as w, logout as x, getConfig as y, getAuthProvider as z };
19565
- //# sourceMappingURL=index.native-JPUkdHJj.esm.js.map
22025
+ export { aggregate as $, signInAnonymously as A, sendEmailOtp as B, verifyEmailOtp as C, linkEmail as D, loginWithPrivy as E, loginWithRedirect as F, linkWithRedirect as G, completeLoginFromRedirect as H, loginWithPopup as I, completeLoginInPopup as J, get as K, set as L, setMany as M, setFile as N, getFiles as O, search as P, queryAggregate as Q, runQuery as R, SOLANA_DEVNET_RPC_URL as S, runQueryMany as T, runExpression as U, runExpressionMany as V, WebSessionManager as W, signMessage as X, signTransaction as Y, signAndSubmitTransaction as Z, count as _, buildSetDocumentsTransaction as a, subscribe as a0, useAuth as a1, deserializeTransaction as a2, getIdToken as a3, setPlatform as a4, MockAuthProvider as a5, DEFAULT_TEST_ADDRESS as a6, OffchainAuthProvider as a7, PrivyExpoProvider as a8, EFFECT_INTENT_ADDRESS as a9, serverTimestamp as aA, signSessionCreateMessage as aB, subscribeView as aC, withEffects as aD, wsDelete as aE, wsGet as aF, wsGetMany as aG, wsQuery as aH, wsSet as aI, index as aJ, FunctionInvokeError as aa, InsufficientBalanceError as ab, LiveIntentError as ac, ReactNativeSessionManager as ad, RealtimeStore as ae, ServerSessionManager as af, clearCache as ag, closeAllSubscriptions as ah, defineLiveModule as ai, deriveUserIdentityFromIdToken as aj, functions as ak, getCachedData as al, getMany as am, getRealtimeStore as an, getWebhookKeysUrl as ao, hasActiveConnection as ap, increment as aq, invoke as ar, isEffectResult as as, live as at, intent as au, status as av, reconnectWithNewAuth as aw, refreshSession as ax, resetRealtimeStore as ay, revokeSession as az, bufferExports as b, convertRemainingAccounts as c, confirmAndCheckTransaction as d, SOLANA_MAINNET_RPC_URL as e, SURFNET_RPC_URL$1 as f, detectMobile as g, detectAndroid as h, getPlatform as i, setAuthLoading as j, genAuthNonce as k, genSolanaMessage as l, createSessionWithSignature as m, getActiveSessionManager as n, bs582 as o, getDefaultExportFromCjs$1 as p, init as q, getCurrentUser as r, setCurrentUser as s, onAuthStateChanged as t, onAuthLoadingChanged as u, getAuthLoading as v, login as w, logout as x, getConfig as y, getAuthProvider as z };
22026
+ //# sourceMappingURL=index.native-BTjBgNiE.esm.js.map