@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
@@ -40,7 +40,7 @@ function commonjsRequire(path) {
40
40
  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.');
41
41
  }
42
42
 
43
- var naclFast = {exports: {}};
43
+ var naclFast$1 = {exports: {}};
44
44
 
45
45
  var _nodeResolve_empty = {};
46
46
 
@@ -51,11 +51,11 @@ var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
51
51
 
52
52
  var require$$0 = /*@__PURE__*/getDefaultExportFromNamespaceIfNotNamed(_nodeResolve_empty$1);
53
53
 
54
- var hasRequiredNaclFast;
54
+ var hasRequiredNaclFast$1;
55
55
 
56
- function requireNaclFast () {
57
- if (hasRequiredNaclFast) return naclFast.exports;
58
- hasRequiredNaclFast = 1;
56
+ function requireNaclFast$1 () {
57
+ if (hasRequiredNaclFast$1) return naclFast$1.exports;
58
+ hasRequiredNaclFast$1 = 1;
59
59
  (function (module) {
60
60
  (function(nacl) {
61
61
 
@@ -2447,12 +2447,12 @@ function requireNaclFast () {
2447
2447
  })();
2448
2448
 
2449
2449
  })(module.exports ? module.exports : (self.nacl = self.nacl || {}));
2450
- } (naclFast));
2451
- return naclFast.exports;
2450
+ } (naclFast$1));
2451
+ return naclFast$1.exports;
2452
2452
  }
2453
2453
 
2454
- var naclFastExports = requireNaclFast();
2455
- var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
2454
+ var naclFastExports$1 = requireNaclFast$1();
2455
+ var nacl$1 = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports$1);
2456
2456
 
2457
2457
  var bn$1 = {exports: {}};
2458
2458
 
@@ -6472,7 +6472,7 @@ function getWebhookKeysUrl() {
6472
6472
  /**
6473
6473
  * True when init() configured a Bounded network (the Cloudflare-native stack).
6474
6474
  * Synchronous + non-blocking. Used to route reads/writes that behave differently
6475
- * on Bounded vs the legacy Tarobase backend (e.g. `count`/`aggregate`, which on
6475
+ * on Bounded vs the legacy backend (e.g. `count`/`aggregate`, which on
6476
6476
  * Bounded must use the deterministic server aggregation, not the legacy AI query).
6477
6477
  */
6478
6478
  function isBoundedNetwork() {
@@ -9327,7 +9327,7 @@ class WebSessionManager {
9327
9327
  // the RIGHT /session/refresh. Email overrides with humanAuthApiUrl; all
9328
9328
  // wallet/guest/signature flows default to authApiUrl (the bounded-auth issuer).
9329
9329
  const sessionIssuer = (issuer || config.authApiUrl || "").replace(/\/$/, "");
9330
- localStorage.setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9330
+ localStorage.setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9331
9331
  accessToken,
9332
9332
  idToken,
9333
9333
  refreshToken, appId: currentAppId }, (sessionIssuer ? { issuer: sessionIssuer } : {}))));
@@ -9338,7 +9338,7 @@ class WebSessionManager {
9338
9338
  static async getSession() {
9339
9339
  if (typeof window === "undefined")
9340
9340
  return null;
9341
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9341
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9342
9342
  if (!session)
9343
9343
  return null;
9344
9344
  const sessionObj = JSON.parse(session);
@@ -9362,7 +9362,7 @@ class WebSessionManager {
9362
9362
  // Persist the ROTATED refresh token — the old one is now
9363
9363
  // single-use spent; reusing it would revoke the family.
9364
9364
  refreshed.refreshToken);
9365
- const newSession = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9365
+ const newSession = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9366
9366
  if (!newSession)
9367
9367
  return null;
9368
9368
  const newObj = JSON.parse(newSession);
@@ -9386,14 +9386,14 @@ class WebSessionManager {
9386
9386
  static clearSession() {
9387
9387
  if (typeof window === "undefined")
9388
9388
  return;
9389
- localStorage.removeItem(this.TAROBASE_SESSION_STORAGE_KEY);
9389
+ localStorage.removeItem(this.BOUNDED_SESSION_STORAGE_KEY);
9390
9390
  }
9391
9391
  /* ------------------------------------------------------------------ */
9392
9392
  /* IS-AUTH */
9393
9393
  /* ------------------------------------------------------------------ */
9394
9394
  static isAuthenticated() {
9395
9395
  // NOTE: this remains synchronous to stay backward compatible
9396
- return !!localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9396
+ return !!localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9397
9397
  }
9398
9398
  /* ------------------------------------------------------------------ */
9399
9399
  /* TOKEN HELPERS */
@@ -9401,13 +9401,13 @@ class WebSessionManager {
9401
9401
  static getIdToken() {
9402
9402
  if (typeof window === "undefined")
9403
9403
  return null;
9404
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9404
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9405
9405
  return session ? JSON.parse(session).idToken : null;
9406
9406
  }
9407
9407
  static getRefreshToken() {
9408
9408
  if (typeof window === "undefined")
9409
9409
  return null;
9410
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9410
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9411
9411
  return session ? JSON.parse(session).refreshToken : null;
9412
9412
  }
9413
9413
  /** The issuer base that minted this session (for routing silent refresh). */
@@ -9415,7 +9415,7 @@ class WebSessionManager {
9415
9415
  var _a;
9416
9416
  if (typeof window === "undefined")
9417
9417
  return null;
9418
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9418
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9419
9419
  return session ? ((_a = JSON.parse(session).issuer) !== null && _a !== void 0 ? _a : null) : null;
9420
9420
  }
9421
9421
  /* ------------------------------------------------------------------ */
@@ -9425,7 +9425,7 @@ class WebSessionManager {
9425
9425
  var _a;
9426
9426
  if (typeof window === "undefined")
9427
9427
  return;
9428
- const session = localStorage.getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9428
+ const session = localStorage.getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9429
9429
  if (!session)
9430
9430
  return;
9431
9431
  const sessionObj = JSON.parse(session);
@@ -9442,10 +9442,10 @@ class WebSessionManager {
9442
9442
  sessionObj.refreshToken = refreshToken;
9443
9443
  }
9444
9444
  (_a = sessionObj.appId) !== null && _a !== void 0 ? _a : (sessionObj.appId = config.appId);
9445
- localStorage.setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9445
+ localStorage.setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9446
9446
  }
9447
9447
  }
9448
- WebSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
9448
+ WebSessionManager.BOUNDED_SESSION_STORAGE_KEY = "bounded_session_storage";
9449
9449
 
9450
9450
  let _config = null;
9451
9451
  class ReactNativeSessionManager {
@@ -9538,7 +9538,7 @@ class ReactNativeSessionManager {
9538
9538
  // Issuer base for silent refresh (email overrides w/ humanAuthApiUrl; wallet/
9539
9539
  // guest default to authApiUrl). See WebSessionManager for the rationale.
9540
9540
  const sessionIssuer = (issuer || config.authApiUrl || "").replace(/\/$/, "");
9541
- this.getStorage().setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9541
+ this.getStorage().setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(Object.assign({ address,
9542
9542
  accessToken,
9543
9543
  idToken,
9544
9544
  refreshToken, appId: currentAppId }, (sessionIssuer ? { issuer: sessionIssuer } : {}))));
@@ -9547,7 +9547,7 @@ class ReactNativeSessionManager {
9547
9547
  /* GET */
9548
9548
  /* ------------------------------------------------------------------ */
9549
9549
  static async getSession() {
9550
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9550
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9551
9551
  if (!session)
9552
9552
  return null;
9553
9553
  const sessionObj = JSON.parse(session);
@@ -9568,7 +9568,7 @@ class ReactNativeSessionManager {
9568
9568
  const refreshed = await refreshSession(refreshToken, sessionObj.issuer);
9569
9569
  if ((refreshed === null || refreshed === void 0 ? void 0 : refreshed.idToken) && (refreshed === null || refreshed === void 0 ? void 0 : refreshed.accessToken)) {
9570
9570
  await this.updateIdTokenAndAccessToken(refreshed.idToken, refreshed.accessToken, refreshed.refreshToken);
9571
- const newSession = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9571
+ const newSession = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9572
9572
  if (!newSession)
9573
9573
  return null;
9574
9574
  const newObj = JSON.parse(newSession);
@@ -9590,20 +9590,20 @@ class ReactNativeSessionManager {
9590
9590
  /* CLEAR */
9591
9591
  /* ------------------------------------------------------------------ */
9592
9592
  static clearSession() {
9593
- this.getStorage().removeItem(this.TAROBASE_SESSION_STORAGE_KEY);
9593
+ this.getStorage().removeItem(this.BOUNDED_SESSION_STORAGE_KEY);
9594
9594
  }
9595
9595
  /* ------------------------------------------------------------------ */
9596
9596
  /* IS-AUTH */
9597
9597
  /* ------------------------------------------------------------------ */
9598
9598
  static isAuthenticated() {
9599
- return !!this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9599
+ return !!this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9600
9600
  }
9601
9601
  /* ------------------------------------------------------------------ */
9602
9602
  /* TOKEN HELPERS */
9603
9603
  /* ------------------------------------------------------------------ */
9604
9604
  static getIdToken() {
9605
9605
  try {
9606
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9606
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9607
9607
  return session ? JSON.parse(session).idToken : null;
9608
9608
  }
9609
9609
  catch (_a) {
@@ -9614,7 +9614,7 @@ class ReactNativeSessionManager {
9614
9614
  static getIssuer() {
9615
9615
  var _a;
9616
9616
  try {
9617
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9617
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9618
9618
  return session ? ((_a = JSON.parse(session).issuer) !== null && _a !== void 0 ? _a : null) : null;
9619
9619
  }
9620
9620
  catch (_b) {
@@ -9623,7 +9623,7 @@ class ReactNativeSessionManager {
9623
9623
  }
9624
9624
  static getRefreshToken() {
9625
9625
  try {
9626
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9626
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9627
9627
  return session ? JSON.parse(session).refreshToken : null;
9628
9628
  }
9629
9629
  catch (_a) {
@@ -9635,7 +9635,7 @@ class ReactNativeSessionManager {
9635
9635
  /* ------------------------------------------------------------------ */
9636
9636
  static async updateIdTokenAndAccessToken(idToken, accessToken, refreshToken) {
9637
9637
  var _a;
9638
- const session = this.getStorage().getItem(this.TAROBASE_SESSION_STORAGE_KEY);
9638
+ const session = this.getStorage().getItem(this.BOUNDED_SESSION_STORAGE_KEY);
9639
9639
  if (!session)
9640
9640
  return;
9641
9641
  const sessionObj = JSON.parse(session);
@@ -9651,10 +9651,10 @@ class ReactNativeSessionManager {
9651
9651
  sessionObj.refreshToken = refreshToken;
9652
9652
  }
9653
9653
  (_a = sessionObj.appId) !== null && _a !== void 0 ? _a : (sessionObj.appId = config.appId);
9654
- this.getStorage().setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9654
+ this.getStorage().setItem(this.BOUNDED_SESSION_STORAGE_KEY, JSON.stringify(sessionObj));
9655
9655
  }
9656
9656
  }
9657
- ReactNativeSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
9657
+ ReactNativeSessionManager.BOUNDED_SESSION_STORAGE_KEY = "bounded_session_storage";
9658
9658
 
9659
9659
  /**
9660
9660
  * Return the active CLIENT session manager for the current runtime.
@@ -10175,9 +10175,9 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
10175
10175
  /* ENV helpers */
10176
10176
  /* ------------------------------------------------------------------ */
10177
10177
  // Canonical `BOUNDED_PRIVATE_KEY` (matches the CLI); legacy
10178
- // `TAROBASE_SOLANA_KEYPAIR` still honored. Only consulted when no explicit
10178
+ // `BOUNDED_SOLANA_KEYPAIR` still honored. Only consulted when no explicit
10179
10179
  // keypair was provided (createWalletClient passes one).
10180
- const ENV_KEYPAIRS = ["BOUNDED_PRIVATE_KEY", "TAROBASE_SOLANA_KEYPAIR"];
10180
+ const ENV_KEYPAIRS = ["BOUNDED_PRIVATE_KEY", "BOUNDED_SOLANA_KEYPAIR"];
10181
10181
  function loadKeypairFromEnv() {
10182
10182
  let secret;
10183
10183
  let found;
@@ -10235,7 +10235,7 @@ class ServerSessionManager {
10235
10235
  const nonce = await genAuthNonce();
10236
10236
  const message = await genSolanaMessage(address, nonce);
10237
10237
  /* sign the message */
10238
- const sigBytes = nacl.sign.detached(new TextEncoder().encode(message), kp.secretKey);
10238
+ const sigBytes = nacl$1.sign.detached(new TextEncoder().encode(message), kp.secretKey);
10239
10239
  const signature = bufferExports$1.Buffer.from(sigBytes).toString("base64");
10240
10240
  /* call auth API */
10241
10241
  const { accessToken, idToken, refreshToken, } = await createSessionWithSignature(address, message, signature);
@@ -10300,7 +10300,7 @@ var serverSessionManager = /*#__PURE__*/Object.freeze({
10300
10300
  });
10301
10301
 
10302
10302
  /**
10303
- * Safe base64 helpers for tarobase-core.
10303
+ * Safe base64 helpers for bounded-core.
10304
10304
  *
10305
10305
  * Uses the global atob/btoa when available (browser, RN with polyfill),
10306
10306
  * falls back to the 'buffer' package (Node.js / SSR / RN without polyfill).
@@ -10480,7 +10480,7 @@ axiosRetry(apiClient, {
10480
10480
  shouldResetTimeout: true,
10481
10481
  onRetry: (retryCount, error, requestConfig) => {
10482
10482
  var _a;
10483
- console.warn(`[tarobase-sdk] retry ${retryCount} for ${(_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${requestConfig.url} — ${error.code || error.message}`);
10483
+ console.warn(`[bounded-sdk] retry ${retryCount} for ${(_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${requestConfig.url} — ${error.code || error.message}`);
10484
10484
  },
10485
10485
  });
10486
10486
  const refreshInFlight = new Map();
@@ -10539,8 +10539,8 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
10539
10539
  : await createAuthHeader(config.isServer);
10540
10540
  const headers = Object.assign({ "Content-Type": "application/json", "X-Public-App-Id": config.appId, "X-App-Id": config.appId }, authHeader);
10541
10541
  if (typeof window !== "undefined" &&
10542
- window.CUSTOM_TAROBASE_APP_ID_HEADER) {
10543
- const customAppId = window.CUSTOM_TAROBASE_APP_ID_HEADER;
10542
+ window.CUSTOM_BOUNDED_APP_ID_HEADER) {
10543
+ const customAppId = window.CUSTOM_BOUNDED_APP_ID_HEADER;
10544
10544
  if (customAppId) {
10545
10545
  headers["X-App-Id"] = customAppId;
10546
10546
  }
@@ -10799,7 +10799,7 @@ function parseAggregateValue(result) {
10799
10799
  * Count items in a collection path. Returns a numeric result.
10800
10800
  *
10801
10801
  * This uses the AI query engine with a count-specific prompt prefix,
10802
- * so TaroBase will generate a $count aggregation pipeline and return
10802
+ * so Bounded will generate a $count aggregation pipeline and return
10803
10803
  * just the count rather than full documents.
10804
10804
  *
10805
10805
  * IMPORTANT: This only works for collections where the read policy is "true".
@@ -11306,6 +11306,13 @@ async function runExpressionMany(many) {
11306
11306
  throw error;
11307
11307
  }
11308
11308
  }
11309
+ /**
11310
+ * Write a document at `path`. Sugar for a one-element {@link setMany}.
11311
+ *
11312
+ * **Delete:** pass `null` as the document to delete it — `set(path, null)` is
11313
+ * the delete (there is no separate `del`/`remove`). It is routed through the
11314
+ * collection's policy `delete` rule and broadcasts a delete to subscribers.
11315
+ */
11309
11316
  async function set(path, document, options) {
11310
11317
  const result = await setMany([{ path, document }], options);
11311
11318
  // Clear cache entries that might be affected by this update
@@ -11324,10 +11331,10 @@ async function setMany(many, options) {
11324
11331
  let documents = [];
11325
11332
  const pathsToInvalidate = new Set();
11326
11333
  for (const { path, document: documentWithReservedFields } of many) {
11327
- // 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
11334
+ // 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
11328
11335
  let document = documentWithReservedFields;
11329
11336
  if (documentWithReservedFields) {
11330
- document = Object.fromEntries(Object.entries(documentWithReservedFields).filter(([key]) => !key.startsWith('tarobase_')));
11337
+ document = Object.fromEntries(Object.entries(documentWithReservedFields).filter(([key]) => !key.startsWith('_')));
11331
11338
  }
11332
11339
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
11333
11340
  pathsToInvalidate.add(normalizedPath);
@@ -11451,7 +11458,7 @@ async function setMany(many, options) {
11451
11458
  var _a, _b, _c, _d, _e;
11452
11459
  // NOTE (backwards-compat revert): a program-allowlist on server-supplied
11453
11460
  // `preInstructions` was tried here for the audit-8 SOL-drain concern, but it
11454
- // broke legitimate onchain DeFi flows — tarobase routes Phoenix, Jupiter/swap,
11461
+ // broke legitimate onchain DeFi flows — bounded routes Phoenix, Jupiter/swap,
11455
11462
  // SPL-Token and ATA-creation instructions through standard-path preInstructions
11456
11463
  // (see sol-helper remaining-accounts-extractor). A correct audit-8 fix must be
11457
11464
  // DeFi-aware (e.g. block ONLY a raw System Transfer/TransferWithSeed, never a
@@ -11535,10 +11542,10 @@ async function setMany(many, options) {
11535
11542
  const transaction = web3_js.VersionedTransaction.deserialize(txBytes);
11536
11543
  // Validate the transaction before signing: ensure only allowed programs
11537
11544
  // and no unauthorized System program instructions (e.g., SOL transfers)
11538
- const TAROBASE_PROGRAM = 'poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp';
11545
+ const BOUNDED_PROGRAM = 'poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp';
11539
11546
  const COMPUTE_BUDGET = 'ComputeBudget111111111111111111111111111111';
11540
11547
  const SYSTEM_PROGRAM = '11111111111111111111111111111111';
11541
- const ALLOWED_PROGRAMS = new Set([TAROBASE_PROGRAM, COMPUTE_BUDGET, SYSTEM_PROGRAM]);
11548
+ const ALLOWED_PROGRAMS = new Set([BOUNDED_PROGRAM, COMPUTE_BUDGET, SYSTEM_PROGRAM]);
11542
11549
  // System program instruction discriminators (first 4 bytes, little-endian u32)
11543
11550
  const SYSTEM_TRANSFER = 2; // Transfer instruction index
11544
11551
  const SYSTEM_TRANSFER_WITH_SEED = 11;
@@ -12132,8 +12139,8 @@ async function getOrCreateConnection(appId, isServer, routePath, authTokenProvid
12132
12139
  if (appId && appId !== config.appId) {
12133
12140
  wsUrl.searchParams.append('appId', appId);
12134
12141
  }
12135
- else if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
12136
- wsUrl.searchParams.append('appId', window.CUSTOM_TAROBASE_APP_ID_HEADER);
12142
+ else if (typeof window !== 'undefined' && window.CUSTOM_BOUNDED_APP_ID_HEADER) {
12143
+ wsUrl.searchParams.append('appId', window.CUSTOM_BOUNDED_APP_ID_HEADER);
12137
12144
  }
12138
12145
  else {
12139
12146
  wsUrl.searchParams.append('appId', config.appId);
@@ -12993,7 +13000,7 @@ function serverTimestamp() {
12993
13000
  // ---------------------------------------------------------------------------
12994
13001
  // IDB helpers (lazy-loaded, non-blocking)
12995
13002
  // ---------------------------------------------------------------------------
12996
- const IDB_NAME$1 = 'tarobase-realtime';
13003
+ const IDB_NAME$1 = 'bounded-realtime';
12997
13004
  const IDB_STORE$1 = 'subscriptions';
12998
13005
  const IDB_VERSION = 1;
12999
13006
  let idbPromise = null;
@@ -13431,10 +13438,10 @@ class RealtimeStore {
13431
13438
  const normalizedPath = path.startsWith('/') ? path.slice(1) : path;
13432
13439
  const collectionPath = this.getCollectionPath(normalizedPath);
13433
13440
  const optimisticDoc = Object.assign(Object.assign({ _id: normalizedPath, pathId: normalizedPath }, resolvedDoc), {
13434
- // System timestamp field name differs by stack: the Bounded worker stamps
13435
- // the neutral `_updatedAt`; legacy Tarobase stamps `tarobase_updated_at`.
13441
+ // System timestamp field name: the Bounded worker stamps the neutral
13442
+ // `_updatedAt`; the underscore-prefixed `_updated_at` metadata mirror.
13436
13443
  // Match it so the optimistic doc lines up with the server's confirmation.
13437
- [isBoundedNetwork() ? '_updatedAt' : 'tarobase_updated_at']: Date.now() });
13444
+ [isBoundedNetwork() ? '_updatedAt' : '_updated_at']: Date.now() });
13438
13445
  const sub = this.findSubscriptionByPath(collectionPath);
13439
13446
  let prevDoc = null;
13440
13447
  if (sub) {
@@ -13887,6 +13894,7 @@ const functions = { invoke };
13887
13894
  // collection. This file is the consumer surface around that runtime:
13888
13895
  //
13889
13896
  // bounded.live.intent(roomPath, intent) -> POST {realtime}/live/intent
13897
+ // bounded.live.status(roomPath) -> GET {realtime}/live/status
13890
13898
  //
13891
13899
  // It mirrors `functions.invoke` exactly: it attaches the caller's session token
13892
13900
  // AUTOMATICALLY (the same token the SDK uses for data reads/writes), and throws
@@ -13899,18 +13907,14 @@ const functions = { invoke };
13899
13907
  // Addressing: clients address rooms BY PATH (the `path` field in the body). The
13900
13908
  // worker derives the roomId from `body.path` and sets X-Room-Id internally;
13901
13909
  // clients NEVER set X-Room-Id. The caller's address is taken server-side from
13902
- // the Authorization header (auth.userAddress) — it is NOT sent in the body.
13910
+ // the Authorization header (auth.userId/userAddress) — it is NOT sent in the
13911
+ // body.
13903
13912
  //
13904
13913
  // Subscribing to your view: a per-player view doc lives at
13905
- // `<roomPath>/view/<myAddress>` (the policy declares
13906
- // `rooms/$roomId/view/$addr` ephemeral with `read: $addr == @user.address`).
13907
- // That path has an EVEN segment count, so it is an ordinary document path —
13908
- // plain `subscribe('<roomPath>/view/<myAddress>', { onData })` already works.
13909
- // `subscribeView()` below is thin sugar over that (path construction + address
13910
- // defaulting); it adds zero new transport.
13911
- //
13912
- // Status polling (GET /live/status?path=<sessionCollection>/<roomId>) is out of
13913
- // scope for this piece — see follow-up.
13914
+ // `<roomPath>/view/<myUserId>` (the policy declares
13915
+ // `rooms/$roomId/view/$userId` ephemeral with `read: $userId == @user.id`).
13916
+ // Wallet-address keyed view paths remain supported through opts.address for
13917
+ // older policies, but new live rooms should key views by @user.id.
13914
13918
  // ---------------------------------------------------------------------------
13915
13919
  class LiveIntentError extends Error {
13916
13920
  constructor(message, statusCode, details) {
@@ -13991,7 +13995,7 @@ async function intent(roomPath, intent, opts = {}) {
13991
13995
  res = await fetch(`${base}/live/intent`, {
13992
13996
  method: 'POST',
13993
13997
  headers,
13994
- body: JSON.stringify({ path: roomPath, intent }),
13998
+ body: JSON.stringify({ path: normalizedRoomPath, intent }),
13995
13999
  signal: controller.signal,
13996
14000
  });
13997
14001
  }
@@ -14019,43 +14023,95 @@ async function intent(roomPath, intent, opts = {}) {
14019
14023
  }
14020
14024
  return (body !== null && body !== void 0 ? body : { ok: true });
14021
14025
  }
14026
+ /**
14027
+ * Fetch the runtime status for a live room.
14028
+ *
14029
+ * const s = await bounded.live.status('rooms/abc');
14030
+ * console.log(s.running, s.stopReason, s.generation, s.etag);
14031
+ *
14032
+ * This is diagnostic/ops surface. It reports whether the room facet exists,
14033
+ * whether it is currently ticking, why it last stopped, which module etag is
14034
+ * loaded, and the current generation used after terminal restarts.
14035
+ */
14036
+ async function status(roomPath, opts = {}) {
14037
+ var _a, _b, _c, _d, _e;
14038
+ if (!roomPath || typeof roomPath !== 'string') {
14039
+ throw new LiveIntentError('A room path is required');
14040
+ }
14041
+ const normalizedRoomPath = roomPath.replace(/\/$/, '');
14042
+ const config = await getConfig();
14043
+ const base = realtimeHttpBase(config.wsApiUrl);
14044
+ const headers = Object.assign({ 'X-App-Id': config.appId, 'X-Public-App-Id': config.appId }, ((_a = opts.headers) !== null && _a !== void 0 ? _a : {}));
14045
+ const controller = new AbortController();
14046
+ const timeoutMs = (_b = opts.timeoutMs) !== null && _b !== void 0 ? _b : 15000;
14047
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
14048
+ let res;
14049
+ try {
14050
+ res = await fetch(`${base}/live/status?path=${encodeURIComponent(normalizedRoomPath)}`, {
14051
+ method: 'GET',
14052
+ headers,
14053
+ signal: controller.signal,
14054
+ });
14055
+ }
14056
+ catch (err) {
14057
+ clearTimeout(timer);
14058
+ if ((err === null || err === void 0 ? void 0 : err.name) === 'AbortError') {
14059
+ throw new LiveIntentError(`Live status for "${normalizedRoomPath}" timed out after ${timeoutMs}ms`);
14060
+ }
14061
+ 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)}`);
14062
+ }
14063
+ clearTimeout(timer);
14064
+ let body = null;
14065
+ const text = await res.text();
14066
+ if (text) {
14067
+ try {
14068
+ body = JSON.parse(text);
14069
+ }
14070
+ catch (_f) {
14071
+ body = { raw: text };
14072
+ }
14073
+ }
14074
+ if (!res.ok) {
14075
+ 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}`;
14076
+ throw new LiveIntentError(message, res.status, body);
14077
+ }
14078
+ return body;
14079
+ }
14022
14080
  /**
14023
14081
  * Subscribe to YOUR per-player view of a room. Thin sugar over:
14024
14082
  *
14025
- * subscribe('<roomPath>/view/<myAddress>', { onData, onError })
14083
+ * subscribe('<roomPath>/view/<myUserId>', { onData, onError })
14026
14084
  *
14027
- * The address defaults to the logged-in user's address (from the session
14028
- * token's claims); pass `opts.address` to override. Returns the unsubscribe
14085
+ * The view id defaults to the logged-in user's @user.id (from the session token
14086
+ * claims); pass `opts.userId` to override. `opts.address` is kept as a legacy
14087
+ * alias for older wallet-address keyed policies. Returns the unsubscribe
14029
14088
  * function (a Promise<() => Promise<void>>, same as `subscribe`).
14030
14089
  *
14031
14090
  * Note: this is a browser-first helper (the WS subscription manager is
14032
14091
  * browser-oriented). Server consumers should use `live.intent`.
14033
14092
  */
14034
14093
  async function subscribeView(roomPath, opts) {
14035
- var _a;
14094
+ var _a, _b, _c;
14036
14095
  if (!roomPath || typeof roomPath !== 'string') {
14037
14096
  throw new LiveIntentError('A room path is required');
14038
14097
  }
14039
14098
  if (!opts || typeof opts.onData !== 'function') {
14040
14099
  throw new LiveIntentError('subscribeView requires an onData callback');
14041
14100
  }
14042
- let address = opts.address;
14043
- if (!address) {
14101
+ let viewUserId = (_a = opts.userId) !== null && _a !== void 0 ? _a : opts.address;
14102
+ if (!viewUserId) {
14044
14103
  const config = await getConfig();
14045
14104
  const info = await getUserInfo(config.isServer);
14046
- // getUserInfo returns the RAW idToken payload — the wallet address lives in
14047
- // the `custom:walletAddress` claim, NOT a flat `address` field. Reading only
14048
- // `.address` meant auto-resolution NEVER worked, forcing every caller (browser
14049
- // AND server) to pass opts.address — the client having to hand the backend an
14050
- // identity it already authenticated. Resolve it from the actual claim so a
14051
- // logged-in caller never needs to pass its own address.
14052
- 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'];
14105
+ // getUserInfo returns the RAW idToken payload. The universal live view key
14106
+ // is @user.id (`custom:userId`); wallet-address keyed views are still
14107
+ // resolved as a compatibility fallback for older policies.
14108
+ 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;
14053
14109
  }
14054
- if (!address || typeof address !== 'string') {
14055
- throw new LiveIntentError('Could not resolve a player address for subscribeView; pass opts.address or log in first');
14110
+ if (!viewUserId || typeof viewUserId !== 'string') {
14111
+ throw new LiveIntentError('Could not resolve a player view id for subscribeView; pass opts.userId or log in first');
14056
14112
  }
14057
14113
  const normalizedRoomPath = roomPath.replace(/\/$/, '');
14058
- const viewPath = `${normalizedRoomPath}/view/${address}`;
14114
+ const viewPath = `${normalizedRoomPath}/view/${viewUserId}`;
14059
14115
  // This is a LIVE/room subscription by construction (the caller hands us the
14060
14116
  // room path), so we route its connection to the per-room DO where the live
14061
14117
  // view fan-out runs. App code passes NO routing — the room path is the helper's
@@ -14066,7 +14122,7 @@ async function subscribeView(roomPath, opts) {
14066
14122
  return subscribeV2(viewPath, { onData: opts.onData, onError: opts.onError }, normalizedRoomPath);
14067
14123
  }
14068
14124
  /** The `bounded.live` namespace surface. */
14069
- const live = { intent, subscribeView };
14125
+ const live = { intent, status, subscribeView };
14070
14126
 
14071
14127
  // ---------------------------------------------------------------------------
14072
14128
  // live-effects.ts -- AUTHOR-facing types + helpers for writing a Bounded live
@@ -17710,13 +17766,2418 @@ var srcExports = requireSrc();
17710
17766
  var basex = /*@__PURE__*/getDefaultExportFromCjs$1(srcExports);
17711
17767
 
17712
17768
  var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
17713
- var base58 = basex(ALPHABET);
17769
+ var bs582 = basex(ALPHABET);
17714
17770
 
17715
17771
  var index = /*#__PURE__*/Object.freeze({
17716
17772
  __proto__: null,
17717
- default: base58
17773
+ default: bs582
17718
17774
  });
17719
17775
 
17776
+ var naclFast = {exports: {}};
17777
+
17778
+ var hasRequiredNaclFast;
17779
+
17780
+ function requireNaclFast () {
17781
+ if (hasRequiredNaclFast) return naclFast.exports;
17782
+ hasRequiredNaclFast = 1;
17783
+ (function (module) {
17784
+ (function(nacl) {
17785
+
17786
+ // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.
17787
+ // Public domain.
17788
+ //
17789
+ // Implementation derived from TweetNaCl version 20140427.
17790
+ // See for details: http://tweetnacl.cr.yp.to/
17791
+
17792
+ var gf = function(init) {
17793
+ var i, r = new Float64Array(16);
17794
+ if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
17795
+ return r;
17796
+ };
17797
+
17798
+ // Pluggable, initialized in high-level API below.
17799
+ var randombytes = function(/* x, n */) { throw new Error('no PRNG'); };
17800
+
17801
+ var _0 = new Uint8Array(16);
17802
+ var _9 = new Uint8Array(32); _9[0] = 9;
17803
+
17804
+ var gf0 = gf(),
17805
+ gf1 = gf([1]),
17806
+ _121665 = gf([0xdb41, 1]),
17807
+ D = gf([0x78a3, 0x1359, 0x4dca, 0x75eb, 0xd8ab, 0x4141, 0x0a4d, 0x0070, 0xe898, 0x7779, 0x4079, 0x8cc7, 0xfe73, 0x2b6f, 0x6cee, 0x5203]),
17808
+ D2 = gf([0xf159, 0x26b2, 0x9b94, 0xebd6, 0xb156, 0x8283, 0x149a, 0x00e0, 0xd130, 0xeef3, 0x80f2, 0x198e, 0xfce7, 0x56df, 0xd9dc, 0x2406]),
17809
+ X = gf([0xd51a, 0x8f25, 0x2d60, 0xc956, 0xa7b2, 0x9525, 0xc760, 0x692c, 0xdc5c, 0xfdd6, 0xe231, 0xc0a4, 0x53fe, 0xcd6e, 0x36d3, 0x2169]),
17810
+ Y = gf([0x6658, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666, 0x6666]),
17811
+ I = gf([0xa0b0, 0x4a0e, 0x1b27, 0xc4ee, 0xe478, 0xad2f, 0x1806, 0x2f43, 0xd7a7, 0x3dfb, 0x0099, 0x2b4d, 0xdf0b, 0x4fc1, 0x2480, 0x2b83]);
17812
+
17813
+ function ts64(x, i, h, l) {
17814
+ x[i] = (h >> 24) & 0xff;
17815
+ x[i+1] = (h >> 16) & 0xff;
17816
+ x[i+2] = (h >> 8) & 0xff;
17817
+ x[i+3] = h & 0xff;
17818
+ x[i+4] = (l >> 24) & 0xff;
17819
+ x[i+5] = (l >> 16) & 0xff;
17820
+ x[i+6] = (l >> 8) & 0xff;
17821
+ x[i+7] = l & 0xff;
17822
+ }
17823
+
17824
+ function vn(x, xi, y, yi, n) {
17825
+ var i,d = 0;
17826
+ for (i = 0; i < n; i++) d |= x[xi+i]^y[yi+i];
17827
+ return (1 & ((d - 1) >>> 8)) - 1;
17828
+ }
17829
+
17830
+ function crypto_verify_16(x, xi, y, yi) {
17831
+ return vn(x,xi,y,yi,16);
17832
+ }
17833
+
17834
+ function crypto_verify_32(x, xi, y, yi) {
17835
+ return vn(x,xi,y,yi,32);
17836
+ }
17837
+
17838
+ function core_salsa20(o, p, k, c) {
17839
+ var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
17840
+ j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
17841
+ j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
17842
+ j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
17843
+ j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
17844
+ j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
17845
+ j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
17846
+ j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
17847
+ j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
17848
+ j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
17849
+ j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
17850
+ j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
17851
+ j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
17852
+ j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
17853
+ j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
17854
+ j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
17855
+
17856
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
17857
+ x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
17858
+ x15 = j15, u;
17859
+
17860
+ for (var i = 0; i < 20; i += 2) {
17861
+ u = x0 + x12 | 0;
17862
+ x4 ^= u<<7 | u>>>(32-7);
17863
+ u = x4 + x0 | 0;
17864
+ x8 ^= u<<9 | u>>>(32-9);
17865
+ u = x8 + x4 | 0;
17866
+ x12 ^= u<<13 | u>>>(32-13);
17867
+ u = x12 + x8 | 0;
17868
+ x0 ^= u<<18 | u>>>(32-18);
17869
+
17870
+ u = x5 + x1 | 0;
17871
+ x9 ^= u<<7 | u>>>(32-7);
17872
+ u = x9 + x5 | 0;
17873
+ x13 ^= u<<9 | u>>>(32-9);
17874
+ u = x13 + x9 | 0;
17875
+ x1 ^= u<<13 | u>>>(32-13);
17876
+ u = x1 + x13 | 0;
17877
+ x5 ^= u<<18 | u>>>(32-18);
17878
+
17879
+ u = x10 + x6 | 0;
17880
+ x14 ^= u<<7 | u>>>(32-7);
17881
+ u = x14 + x10 | 0;
17882
+ x2 ^= u<<9 | u>>>(32-9);
17883
+ u = x2 + x14 | 0;
17884
+ x6 ^= u<<13 | u>>>(32-13);
17885
+ u = x6 + x2 | 0;
17886
+ x10 ^= u<<18 | u>>>(32-18);
17887
+
17888
+ u = x15 + x11 | 0;
17889
+ x3 ^= u<<7 | u>>>(32-7);
17890
+ u = x3 + x15 | 0;
17891
+ x7 ^= u<<9 | u>>>(32-9);
17892
+ u = x7 + x3 | 0;
17893
+ x11 ^= u<<13 | u>>>(32-13);
17894
+ u = x11 + x7 | 0;
17895
+ x15 ^= u<<18 | u>>>(32-18);
17896
+
17897
+ u = x0 + x3 | 0;
17898
+ x1 ^= u<<7 | u>>>(32-7);
17899
+ u = x1 + x0 | 0;
17900
+ x2 ^= u<<9 | u>>>(32-9);
17901
+ u = x2 + x1 | 0;
17902
+ x3 ^= u<<13 | u>>>(32-13);
17903
+ u = x3 + x2 | 0;
17904
+ x0 ^= u<<18 | u>>>(32-18);
17905
+
17906
+ u = x5 + x4 | 0;
17907
+ x6 ^= u<<7 | u>>>(32-7);
17908
+ u = x6 + x5 | 0;
17909
+ x7 ^= u<<9 | u>>>(32-9);
17910
+ u = x7 + x6 | 0;
17911
+ x4 ^= u<<13 | u>>>(32-13);
17912
+ u = x4 + x7 | 0;
17913
+ x5 ^= u<<18 | u>>>(32-18);
17914
+
17915
+ u = x10 + x9 | 0;
17916
+ x11 ^= u<<7 | u>>>(32-7);
17917
+ u = x11 + x10 | 0;
17918
+ x8 ^= u<<9 | u>>>(32-9);
17919
+ u = x8 + x11 | 0;
17920
+ x9 ^= u<<13 | u>>>(32-13);
17921
+ u = x9 + x8 | 0;
17922
+ x10 ^= u<<18 | u>>>(32-18);
17923
+
17924
+ u = x15 + x14 | 0;
17925
+ x12 ^= u<<7 | u>>>(32-7);
17926
+ u = x12 + x15 | 0;
17927
+ x13 ^= u<<9 | u>>>(32-9);
17928
+ u = x13 + x12 | 0;
17929
+ x14 ^= u<<13 | u>>>(32-13);
17930
+ u = x14 + x13 | 0;
17931
+ x15 ^= u<<18 | u>>>(32-18);
17932
+ }
17933
+ x0 = x0 + j0 | 0;
17934
+ x1 = x1 + j1 | 0;
17935
+ x2 = x2 + j2 | 0;
17936
+ x3 = x3 + j3 | 0;
17937
+ x4 = x4 + j4 | 0;
17938
+ x5 = x5 + j5 | 0;
17939
+ x6 = x6 + j6 | 0;
17940
+ x7 = x7 + j7 | 0;
17941
+ x8 = x8 + j8 | 0;
17942
+ x9 = x9 + j9 | 0;
17943
+ x10 = x10 + j10 | 0;
17944
+ x11 = x11 + j11 | 0;
17945
+ x12 = x12 + j12 | 0;
17946
+ x13 = x13 + j13 | 0;
17947
+ x14 = x14 + j14 | 0;
17948
+ x15 = x15 + j15 | 0;
17949
+
17950
+ o[ 0] = x0 >>> 0 & 0xff;
17951
+ o[ 1] = x0 >>> 8 & 0xff;
17952
+ o[ 2] = x0 >>> 16 & 0xff;
17953
+ o[ 3] = x0 >>> 24 & 0xff;
17954
+
17955
+ o[ 4] = x1 >>> 0 & 0xff;
17956
+ o[ 5] = x1 >>> 8 & 0xff;
17957
+ o[ 6] = x1 >>> 16 & 0xff;
17958
+ o[ 7] = x1 >>> 24 & 0xff;
17959
+
17960
+ o[ 8] = x2 >>> 0 & 0xff;
17961
+ o[ 9] = x2 >>> 8 & 0xff;
17962
+ o[10] = x2 >>> 16 & 0xff;
17963
+ o[11] = x2 >>> 24 & 0xff;
17964
+
17965
+ o[12] = x3 >>> 0 & 0xff;
17966
+ o[13] = x3 >>> 8 & 0xff;
17967
+ o[14] = x3 >>> 16 & 0xff;
17968
+ o[15] = x3 >>> 24 & 0xff;
17969
+
17970
+ o[16] = x4 >>> 0 & 0xff;
17971
+ o[17] = x4 >>> 8 & 0xff;
17972
+ o[18] = x4 >>> 16 & 0xff;
17973
+ o[19] = x4 >>> 24 & 0xff;
17974
+
17975
+ o[20] = x5 >>> 0 & 0xff;
17976
+ o[21] = x5 >>> 8 & 0xff;
17977
+ o[22] = x5 >>> 16 & 0xff;
17978
+ o[23] = x5 >>> 24 & 0xff;
17979
+
17980
+ o[24] = x6 >>> 0 & 0xff;
17981
+ o[25] = x6 >>> 8 & 0xff;
17982
+ o[26] = x6 >>> 16 & 0xff;
17983
+ o[27] = x6 >>> 24 & 0xff;
17984
+
17985
+ o[28] = x7 >>> 0 & 0xff;
17986
+ o[29] = x7 >>> 8 & 0xff;
17987
+ o[30] = x7 >>> 16 & 0xff;
17988
+ o[31] = x7 >>> 24 & 0xff;
17989
+
17990
+ o[32] = x8 >>> 0 & 0xff;
17991
+ o[33] = x8 >>> 8 & 0xff;
17992
+ o[34] = x8 >>> 16 & 0xff;
17993
+ o[35] = x8 >>> 24 & 0xff;
17994
+
17995
+ o[36] = x9 >>> 0 & 0xff;
17996
+ o[37] = x9 >>> 8 & 0xff;
17997
+ o[38] = x9 >>> 16 & 0xff;
17998
+ o[39] = x9 >>> 24 & 0xff;
17999
+
18000
+ o[40] = x10 >>> 0 & 0xff;
18001
+ o[41] = x10 >>> 8 & 0xff;
18002
+ o[42] = x10 >>> 16 & 0xff;
18003
+ o[43] = x10 >>> 24 & 0xff;
18004
+
18005
+ o[44] = x11 >>> 0 & 0xff;
18006
+ o[45] = x11 >>> 8 & 0xff;
18007
+ o[46] = x11 >>> 16 & 0xff;
18008
+ o[47] = x11 >>> 24 & 0xff;
18009
+
18010
+ o[48] = x12 >>> 0 & 0xff;
18011
+ o[49] = x12 >>> 8 & 0xff;
18012
+ o[50] = x12 >>> 16 & 0xff;
18013
+ o[51] = x12 >>> 24 & 0xff;
18014
+
18015
+ o[52] = x13 >>> 0 & 0xff;
18016
+ o[53] = x13 >>> 8 & 0xff;
18017
+ o[54] = x13 >>> 16 & 0xff;
18018
+ o[55] = x13 >>> 24 & 0xff;
18019
+
18020
+ o[56] = x14 >>> 0 & 0xff;
18021
+ o[57] = x14 >>> 8 & 0xff;
18022
+ o[58] = x14 >>> 16 & 0xff;
18023
+ o[59] = x14 >>> 24 & 0xff;
18024
+
18025
+ o[60] = x15 >>> 0 & 0xff;
18026
+ o[61] = x15 >>> 8 & 0xff;
18027
+ o[62] = x15 >>> 16 & 0xff;
18028
+ o[63] = x15 >>> 24 & 0xff;
18029
+ }
18030
+
18031
+ function core_hsalsa20(o,p,k,c) {
18032
+ var j0 = c[ 0] & 0xff | (c[ 1] & 0xff)<<8 | (c[ 2] & 0xff)<<16 | (c[ 3] & 0xff)<<24,
18033
+ j1 = k[ 0] & 0xff | (k[ 1] & 0xff)<<8 | (k[ 2] & 0xff)<<16 | (k[ 3] & 0xff)<<24,
18034
+ j2 = k[ 4] & 0xff | (k[ 5] & 0xff)<<8 | (k[ 6] & 0xff)<<16 | (k[ 7] & 0xff)<<24,
18035
+ j3 = k[ 8] & 0xff | (k[ 9] & 0xff)<<8 | (k[10] & 0xff)<<16 | (k[11] & 0xff)<<24,
18036
+ j4 = k[12] & 0xff | (k[13] & 0xff)<<8 | (k[14] & 0xff)<<16 | (k[15] & 0xff)<<24,
18037
+ j5 = c[ 4] & 0xff | (c[ 5] & 0xff)<<8 | (c[ 6] & 0xff)<<16 | (c[ 7] & 0xff)<<24,
18038
+ j6 = p[ 0] & 0xff | (p[ 1] & 0xff)<<8 | (p[ 2] & 0xff)<<16 | (p[ 3] & 0xff)<<24,
18039
+ j7 = p[ 4] & 0xff | (p[ 5] & 0xff)<<8 | (p[ 6] & 0xff)<<16 | (p[ 7] & 0xff)<<24,
18040
+ j8 = p[ 8] & 0xff | (p[ 9] & 0xff)<<8 | (p[10] & 0xff)<<16 | (p[11] & 0xff)<<24,
18041
+ j9 = p[12] & 0xff | (p[13] & 0xff)<<8 | (p[14] & 0xff)<<16 | (p[15] & 0xff)<<24,
18042
+ j10 = c[ 8] & 0xff | (c[ 9] & 0xff)<<8 | (c[10] & 0xff)<<16 | (c[11] & 0xff)<<24,
18043
+ j11 = k[16] & 0xff | (k[17] & 0xff)<<8 | (k[18] & 0xff)<<16 | (k[19] & 0xff)<<24,
18044
+ j12 = k[20] & 0xff | (k[21] & 0xff)<<8 | (k[22] & 0xff)<<16 | (k[23] & 0xff)<<24,
18045
+ j13 = k[24] & 0xff | (k[25] & 0xff)<<8 | (k[26] & 0xff)<<16 | (k[27] & 0xff)<<24,
18046
+ j14 = k[28] & 0xff | (k[29] & 0xff)<<8 | (k[30] & 0xff)<<16 | (k[31] & 0xff)<<24,
18047
+ j15 = c[12] & 0xff | (c[13] & 0xff)<<8 | (c[14] & 0xff)<<16 | (c[15] & 0xff)<<24;
18048
+
18049
+ var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7,
18050
+ x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14,
18051
+ x15 = j15, u;
18052
+
18053
+ for (var i = 0; i < 20; i += 2) {
18054
+ u = x0 + x12 | 0;
18055
+ x4 ^= u<<7 | u>>>(32-7);
18056
+ u = x4 + x0 | 0;
18057
+ x8 ^= u<<9 | u>>>(32-9);
18058
+ u = x8 + x4 | 0;
18059
+ x12 ^= u<<13 | u>>>(32-13);
18060
+ u = x12 + x8 | 0;
18061
+ x0 ^= u<<18 | u>>>(32-18);
18062
+
18063
+ u = x5 + x1 | 0;
18064
+ x9 ^= u<<7 | u>>>(32-7);
18065
+ u = x9 + x5 | 0;
18066
+ x13 ^= u<<9 | u>>>(32-9);
18067
+ u = x13 + x9 | 0;
18068
+ x1 ^= u<<13 | u>>>(32-13);
18069
+ u = x1 + x13 | 0;
18070
+ x5 ^= u<<18 | u>>>(32-18);
18071
+
18072
+ u = x10 + x6 | 0;
18073
+ x14 ^= u<<7 | u>>>(32-7);
18074
+ u = x14 + x10 | 0;
18075
+ x2 ^= u<<9 | u>>>(32-9);
18076
+ u = x2 + x14 | 0;
18077
+ x6 ^= u<<13 | u>>>(32-13);
18078
+ u = x6 + x2 | 0;
18079
+ x10 ^= u<<18 | u>>>(32-18);
18080
+
18081
+ u = x15 + x11 | 0;
18082
+ x3 ^= u<<7 | u>>>(32-7);
18083
+ u = x3 + x15 | 0;
18084
+ x7 ^= u<<9 | u>>>(32-9);
18085
+ u = x7 + x3 | 0;
18086
+ x11 ^= u<<13 | u>>>(32-13);
18087
+ u = x11 + x7 | 0;
18088
+ x15 ^= u<<18 | u>>>(32-18);
18089
+
18090
+ u = x0 + x3 | 0;
18091
+ x1 ^= u<<7 | u>>>(32-7);
18092
+ u = x1 + x0 | 0;
18093
+ x2 ^= u<<9 | u>>>(32-9);
18094
+ u = x2 + x1 | 0;
18095
+ x3 ^= u<<13 | u>>>(32-13);
18096
+ u = x3 + x2 | 0;
18097
+ x0 ^= u<<18 | u>>>(32-18);
18098
+
18099
+ u = x5 + x4 | 0;
18100
+ x6 ^= u<<7 | u>>>(32-7);
18101
+ u = x6 + x5 | 0;
18102
+ x7 ^= u<<9 | u>>>(32-9);
18103
+ u = x7 + x6 | 0;
18104
+ x4 ^= u<<13 | u>>>(32-13);
18105
+ u = x4 + x7 | 0;
18106
+ x5 ^= u<<18 | u>>>(32-18);
18107
+
18108
+ u = x10 + x9 | 0;
18109
+ x11 ^= u<<7 | u>>>(32-7);
18110
+ u = x11 + x10 | 0;
18111
+ x8 ^= u<<9 | u>>>(32-9);
18112
+ u = x8 + x11 | 0;
18113
+ x9 ^= u<<13 | u>>>(32-13);
18114
+ u = x9 + x8 | 0;
18115
+ x10 ^= u<<18 | u>>>(32-18);
18116
+
18117
+ u = x15 + x14 | 0;
18118
+ x12 ^= u<<7 | u>>>(32-7);
18119
+ u = x12 + x15 | 0;
18120
+ x13 ^= u<<9 | u>>>(32-9);
18121
+ u = x13 + x12 | 0;
18122
+ x14 ^= u<<13 | u>>>(32-13);
18123
+ u = x14 + x13 | 0;
18124
+ x15 ^= u<<18 | u>>>(32-18);
18125
+ }
18126
+
18127
+ o[ 0] = x0 >>> 0 & 0xff;
18128
+ o[ 1] = x0 >>> 8 & 0xff;
18129
+ o[ 2] = x0 >>> 16 & 0xff;
18130
+ o[ 3] = x0 >>> 24 & 0xff;
18131
+
18132
+ o[ 4] = x5 >>> 0 & 0xff;
18133
+ o[ 5] = x5 >>> 8 & 0xff;
18134
+ o[ 6] = x5 >>> 16 & 0xff;
18135
+ o[ 7] = x5 >>> 24 & 0xff;
18136
+
18137
+ o[ 8] = x10 >>> 0 & 0xff;
18138
+ o[ 9] = x10 >>> 8 & 0xff;
18139
+ o[10] = x10 >>> 16 & 0xff;
18140
+ o[11] = x10 >>> 24 & 0xff;
18141
+
18142
+ o[12] = x15 >>> 0 & 0xff;
18143
+ o[13] = x15 >>> 8 & 0xff;
18144
+ o[14] = x15 >>> 16 & 0xff;
18145
+ o[15] = x15 >>> 24 & 0xff;
18146
+
18147
+ o[16] = x6 >>> 0 & 0xff;
18148
+ o[17] = x6 >>> 8 & 0xff;
18149
+ o[18] = x6 >>> 16 & 0xff;
18150
+ o[19] = x6 >>> 24 & 0xff;
18151
+
18152
+ o[20] = x7 >>> 0 & 0xff;
18153
+ o[21] = x7 >>> 8 & 0xff;
18154
+ o[22] = x7 >>> 16 & 0xff;
18155
+ o[23] = x7 >>> 24 & 0xff;
18156
+
18157
+ o[24] = x8 >>> 0 & 0xff;
18158
+ o[25] = x8 >>> 8 & 0xff;
18159
+ o[26] = x8 >>> 16 & 0xff;
18160
+ o[27] = x8 >>> 24 & 0xff;
18161
+
18162
+ o[28] = x9 >>> 0 & 0xff;
18163
+ o[29] = x9 >>> 8 & 0xff;
18164
+ o[30] = x9 >>> 16 & 0xff;
18165
+ o[31] = x9 >>> 24 & 0xff;
18166
+ }
18167
+
18168
+ function crypto_core_salsa20(out,inp,k,c) {
18169
+ core_salsa20(out,inp,k,c);
18170
+ }
18171
+
18172
+ function crypto_core_hsalsa20(out,inp,k,c) {
18173
+ core_hsalsa20(out,inp,k,c);
18174
+ }
18175
+
18176
+ var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
18177
+ // "expand 32-byte k"
18178
+
18179
+ function crypto_stream_salsa20_xor(c,cpos,m,mpos,b,n,k) {
18180
+ var z = new Uint8Array(16), x = new Uint8Array(64);
18181
+ var u, i;
18182
+ for (i = 0; i < 16; i++) z[i] = 0;
18183
+ for (i = 0; i < 8; i++) z[i] = n[i];
18184
+ while (b >= 64) {
18185
+ crypto_core_salsa20(x,z,k,sigma);
18186
+ for (i = 0; i < 64; i++) c[cpos+i] = m[mpos+i] ^ x[i];
18187
+ u = 1;
18188
+ for (i = 8; i < 16; i++) {
18189
+ u = u + (z[i] & 0xff) | 0;
18190
+ z[i] = u & 0xff;
18191
+ u >>>= 8;
18192
+ }
18193
+ b -= 64;
18194
+ cpos += 64;
18195
+ mpos += 64;
18196
+ }
18197
+ if (b > 0) {
18198
+ crypto_core_salsa20(x,z,k,sigma);
18199
+ for (i = 0; i < b; i++) c[cpos+i] = m[mpos+i] ^ x[i];
18200
+ }
18201
+ return 0;
18202
+ }
18203
+
18204
+ function crypto_stream_salsa20(c,cpos,b,n,k) {
18205
+ var z = new Uint8Array(16), x = new Uint8Array(64);
18206
+ var u, i;
18207
+ for (i = 0; i < 16; i++) z[i] = 0;
18208
+ for (i = 0; i < 8; i++) z[i] = n[i];
18209
+ while (b >= 64) {
18210
+ crypto_core_salsa20(x,z,k,sigma);
18211
+ for (i = 0; i < 64; i++) c[cpos+i] = x[i];
18212
+ u = 1;
18213
+ for (i = 8; i < 16; i++) {
18214
+ u = u + (z[i] & 0xff) | 0;
18215
+ z[i] = u & 0xff;
18216
+ u >>>= 8;
18217
+ }
18218
+ b -= 64;
18219
+ cpos += 64;
18220
+ }
18221
+ if (b > 0) {
18222
+ crypto_core_salsa20(x,z,k,sigma);
18223
+ for (i = 0; i < b; i++) c[cpos+i] = x[i];
18224
+ }
18225
+ return 0;
18226
+ }
18227
+
18228
+ function crypto_stream(c,cpos,d,n,k) {
18229
+ var s = new Uint8Array(32);
18230
+ crypto_core_hsalsa20(s,n,k,sigma);
18231
+ var sn = new Uint8Array(8);
18232
+ for (var i = 0; i < 8; i++) sn[i] = n[i+16];
18233
+ return crypto_stream_salsa20(c,cpos,d,sn,s);
18234
+ }
18235
+
18236
+ function crypto_stream_xor(c,cpos,m,mpos,d,n,k) {
18237
+ var s = new Uint8Array(32);
18238
+ crypto_core_hsalsa20(s,n,k,sigma);
18239
+ var sn = new Uint8Array(8);
18240
+ for (var i = 0; i < 8; i++) sn[i] = n[i+16];
18241
+ return crypto_stream_salsa20_xor(c,cpos,m,mpos,d,sn,s);
18242
+ }
18243
+
18244
+ /*
18245
+ * Port of Andrew Moon's Poly1305-donna-16. Public domain.
18246
+ * https://github.com/floodyberry/poly1305-donna
18247
+ */
18248
+
18249
+ var poly1305 = function(key) {
18250
+ this.buffer = new Uint8Array(16);
18251
+ this.r = new Uint16Array(10);
18252
+ this.h = new Uint16Array(10);
18253
+ this.pad = new Uint16Array(8);
18254
+ this.leftover = 0;
18255
+ this.fin = 0;
18256
+
18257
+ var t0, t1, t2, t3, t4, t5, t6, t7;
18258
+
18259
+ t0 = key[ 0] & 0xff | (key[ 1] & 0xff) << 8; this.r[0] = ( t0 ) & 0x1fff;
18260
+ t1 = key[ 2] & 0xff | (key[ 3] & 0xff) << 8; this.r[1] = ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
18261
+ t2 = key[ 4] & 0xff | (key[ 5] & 0xff) << 8; this.r[2] = ((t1 >>> 10) | (t2 << 6)) & 0x1f03;
18262
+ t3 = key[ 6] & 0xff | (key[ 7] & 0xff) << 8; this.r[3] = ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
18263
+ t4 = key[ 8] & 0xff | (key[ 9] & 0xff) << 8; this.r[4] = ((t3 >>> 4) | (t4 << 12)) & 0x00ff;
18264
+ this.r[5] = ((t4 >>> 1)) & 0x1ffe;
18265
+ t5 = key[10] & 0xff | (key[11] & 0xff) << 8; this.r[6] = ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
18266
+ t6 = key[12] & 0xff | (key[13] & 0xff) << 8; this.r[7] = ((t5 >>> 11) | (t6 << 5)) & 0x1f81;
18267
+ t7 = key[14] & 0xff | (key[15] & 0xff) << 8; this.r[8] = ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
18268
+ this.r[9] = ((t7 >>> 5)) & 0x007f;
18269
+
18270
+ this.pad[0] = key[16] & 0xff | (key[17] & 0xff) << 8;
18271
+ this.pad[1] = key[18] & 0xff | (key[19] & 0xff) << 8;
18272
+ this.pad[2] = key[20] & 0xff | (key[21] & 0xff) << 8;
18273
+ this.pad[3] = key[22] & 0xff | (key[23] & 0xff) << 8;
18274
+ this.pad[4] = key[24] & 0xff | (key[25] & 0xff) << 8;
18275
+ this.pad[5] = key[26] & 0xff | (key[27] & 0xff) << 8;
18276
+ this.pad[6] = key[28] & 0xff | (key[29] & 0xff) << 8;
18277
+ this.pad[7] = key[30] & 0xff | (key[31] & 0xff) << 8;
18278
+ };
18279
+
18280
+ poly1305.prototype.blocks = function(m, mpos, bytes) {
18281
+ var hibit = this.fin ? 0 : (1 << 11);
18282
+ var t0, t1, t2, t3, t4, t5, t6, t7, c;
18283
+ var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
18284
+
18285
+ var h0 = this.h[0],
18286
+ h1 = this.h[1],
18287
+ h2 = this.h[2],
18288
+ h3 = this.h[3],
18289
+ h4 = this.h[4],
18290
+ h5 = this.h[5],
18291
+ h6 = this.h[6],
18292
+ h7 = this.h[7],
18293
+ h8 = this.h[8],
18294
+ h9 = this.h[9];
18295
+
18296
+ var r0 = this.r[0],
18297
+ r1 = this.r[1],
18298
+ r2 = this.r[2],
18299
+ r3 = this.r[3],
18300
+ r4 = this.r[4],
18301
+ r5 = this.r[5],
18302
+ r6 = this.r[6],
18303
+ r7 = this.r[7],
18304
+ r8 = this.r[8],
18305
+ r9 = this.r[9];
18306
+
18307
+ while (bytes >= 16) {
18308
+ t0 = m[mpos+ 0] & 0xff | (m[mpos+ 1] & 0xff) << 8; h0 += ( t0 ) & 0x1fff;
18309
+ t1 = m[mpos+ 2] & 0xff | (m[mpos+ 3] & 0xff) << 8; h1 += ((t0 >>> 13) | (t1 << 3)) & 0x1fff;
18310
+ t2 = m[mpos+ 4] & 0xff | (m[mpos+ 5] & 0xff) << 8; h2 += ((t1 >>> 10) | (t2 << 6)) & 0x1fff;
18311
+ t3 = m[mpos+ 6] & 0xff | (m[mpos+ 7] & 0xff) << 8; h3 += ((t2 >>> 7) | (t3 << 9)) & 0x1fff;
18312
+ t4 = m[mpos+ 8] & 0xff | (m[mpos+ 9] & 0xff) << 8; h4 += ((t3 >>> 4) | (t4 << 12)) & 0x1fff;
18313
+ h5 += ((t4 >>> 1)) & 0x1fff;
18314
+ t5 = m[mpos+10] & 0xff | (m[mpos+11] & 0xff) << 8; h6 += ((t4 >>> 14) | (t5 << 2)) & 0x1fff;
18315
+ t6 = m[mpos+12] & 0xff | (m[mpos+13] & 0xff) << 8; h7 += ((t5 >>> 11) | (t6 << 5)) & 0x1fff;
18316
+ t7 = m[mpos+14] & 0xff | (m[mpos+15] & 0xff) << 8; h8 += ((t6 >>> 8) | (t7 << 8)) & 0x1fff;
18317
+ h9 += ((t7 >>> 5)) | hibit;
18318
+
18319
+ c = 0;
18320
+
18321
+ d0 = c;
18322
+ d0 += h0 * r0;
18323
+ d0 += h1 * (5 * r9);
18324
+ d0 += h2 * (5 * r8);
18325
+ d0 += h3 * (5 * r7);
18326
+ d0 += h4 * (5 * r6);
18327
+ c = (d0 >>> 13); d0 &= 0x1fff;
18328
+ d0 += h5 * (5 * r5);
18329
+ d0 += h6 * (5 * r4);
18330
+ d0 += h7 * (5 * r3);
18331
+ d0 += h8 * (5 * r2);
18332
+ d0 += h9 * (5 * r1);
18333
+ c += (d0 >>> 13); d0 &= 0x1fff;
18334
+
18335
+ d1 = c;
18336
+ d1 += h0 * r1;
18337
+ d1 += h1 * r0;
18338
+ d1 += h2 * (5 * r9);
18339
+ d1 += h3 * (5 * r8);
18340
+ d1 += h4 * (5 * r7);
18341
+ c = (d1 >>> 13); d1 &= 0x1fff;
18342
+ d1 += h5 * (5 * r6);
18343
+ d1 += h6 * (5 * r5);
18344
+ d1 += h7 * (5 * r4);
18345
+ d1 += h8 * (5 * r3);
18346
+ d1 += h9 * (5 * r2);
18347
+ c += (d1 >>> 13); d1 &= 0x1fff;
18348
+
18349
+ d2 = c;
18350
+ d2 += h0 * r2;
18351
+ d2 += h1 * r1;
18352
+ d2 += h2 * r0;
18353
+ d2 += h3 * (5 * r9);
18354
+ d2 += h4 * (5 * r8);
18355
+ c = (d2 >>> 13); d2 &= 0x1fff;
18356
+ d2 += h5 * (5 * r7);
18357
+ d2 += h6 * (5 * r6);
18358
+ d2 += h7 * (5 * r5);
18359
+ d2 += h8 * (5 * r4);
18360
+ d2 += h9 * (5 * r3);
18361
+ c += (d2 >>> 13); d2 &= 0x1fff;
18362
+
18363
+ d3 = c;
18364
+ d3 += h0 * r3;
18365
+ d3 += h1 * r2;
18366
+ d3 += h2 * r1;
18367
+ d3 += h3 * r0;
18368
+ d3 += h4 * (5 * r9);
18369
+ c = (d3 >>> 13); d3 &= 0x1fff;
18370
+ d3 += h5 * (5 * r8);
18371
+ d3 += h6 * (5 * r7);
18372
+ d3 += h7 * (5 * r6);
18373
+ d3 += h8 * (5 * r5);
18374
+ d3 += h9 * (5 * r4);
18375
+ c += (d3 >>> 13); d3 &= 0x1fff;
18376
+
18377
+ d4 = c;
18378
+ d4 += h0 * r4;
18379
+ d4 += h1 * r3;
18380
+ d4 += h2 * r2;
18381
+ d4 += h3 * r1;
18382
+ d4 += h4 * r0;
18383
+ c = (d4 >>> 13); d4 &= 0x1fff;
18384
+ d4 += h5 * (5 * r9);
18385
+ d4 += h6 * (5 * r8);
18386
+ d4 += h7 * (5 * r7);
18387
+ d4 += h8 * (5 * r6);
18388
+ d4 += h9 * (5 * r5);
18389
+ c += (d4 >>> 13); d4 &= 0x1fff;
18390
+
18391
+ d5 = c;
18392
+ d5 += h0 * r5;
18393
+ d5 += h1 * r4;
18394
+ d5 += h2 * r3;
18395
+ d5 += h3 * r2;
18396
+ d5 += h4 * r1;
18397
+ c = (d5 >>> 13); d5 &= 0x1fff;
18398
+ d5 += h5 * r0;
18399
+ d5 += h6 * (5 * r9);
18400
+ d5 += h7 * (5 * r8);
18401
+ d5 += h8 * (5 * r7);
18402
+ d5 += h9 * (5 * r6);
18403
+ c += (d5 >>> 13); d5 &= 0x1fff;
18404
+
18405
+ d6 = c;
18406
+ d6 += h0 * r6;
18407
+ d6 += h1 * r5;
18408
+ d6 += h2 * r4;
18409
+ d6 += h3 * r3;
18410
+ d6 += h4 * r2;
18411
+ c = (d6 >>> 13); d6 &= 0x1fff;
18412
+ d6 += h5 * r1;
18413
+ d6 += h6 * r0;
18414
+ d6 += h7 * (5 * r9);
18415
+ d6 += h8 * (5 * r8);
18416
+ d6 += h9 * (5 * r7);
18417
+ c += (d6 >>> 13); d6 &= 0x1fff;
18418
+
18419
+ d7 = c;
18420
+ d7 += h0 * r7;
18421
+ d7 += h1 * r6;
18422
+ d7 += h2 * r5;
18423
+ d7 += h3 * r4;
18424
+ d7 += h4 * r3;
18425
+ c = (d7 >>> 13); d7 &= 0x1fff;
18426
+ d7 += h5 * r2;
18427
+ d7 += h6 * r1;
18428
+ d7 += h7 * r0;
18429
+ d7 += h8 * (5 * r9);
18430
+ d7 += h9 * (5 * r8);
18431
+ c += (d7 >>> 13); d7 &= 0x1fff;
18432
+
18433
+ d8 = c;
18434
+ d8 += h0 * r8;
18435
+ d8 += h1 * r7;
18436
+ d8 += h2 * r6;
18437
+ d8 += h3 * r5;
18438
+ d8 += h4 * r4;
18439
+ c = (d8 >>> 13); d8 &= 0x1fff;
18440
+ d8 += h5 * r3;
18441
+ d8 += h6 * r2;
18442
+ d8 += h7 * r1;
18443
+ d8 += h8 * r0;
18444
+ d8 += h9 * (5 * r9);
18445
+ c += (d8 >>> 13); d8 &= 0x1fff;
18446
+
18447
+ d9 = c;
18448
+ d9 += h0 * r9;
18449
+ d9 += h1 * r8;
18450
+ d9 += h2 * r7;
18451
+ d9 += h3 * r6;
18452
+ d9 += h4 * r5;
18453
+ c = (d9 >>> 13); d9 &= 0x1fff;
18454
+ d9 += h5 * r4;
18455
+ d9 += h6 * r3;
18456
+ d9 += h7 * r2;
18457
+ d9 += h8 * r1;
18458
+ d9 += h9 * r0;
18459
+ c += (d9 >>> 13); d9 &= 0x1fff;
18460
+
18461
+ c = (((c << 2) + c)) | 0;
18462
+ c = (c + d0) | 0;
18463
+ d0 = c & 0x1fff;
18464
+ c = (c >>> 13);
18465
+ d1 += c;
18466
+
18467
+ h0 = d0;
18468
+ h1 = d1;
18469
+ h2 = d2;
18470
+ h3 = d3;
18471
+ h4 = d4;
18472
+ h5 = d5;
18473
+ h6 = d6;
18474
+ h7 = d7;
18475
+ h8 = d8;
18476
+ h9 = d9;
18477
+
18478
+ mpos += 16;
18479
+ bytes -= 16;
18480
+ }
18481
+ this.h[0] = h0;
18482
+ this.h[1] = h1;
18483
+ this.h[2] = h2;
18484
+ this.h[3] = h3;
18485
+ this.h[4] = h4;
18486
+ this.h[5] = h5;
18487
+ this.h[6] = h6;
18488
+ this.h[7] = h7;
18489
+ this.h[8] = h8;
18490
+ this.h[9] = h9;
18491
+ };
18492
+
18493
+ poly1305.prototype.finish = function(mac, macpos) {
18494
+ var g = new Uint16Array(10);
18495
+ var c, mask, f, i;
18496
+
18497
+ if (this.leftover) {
18498
+ i = this.leftover;
18499
+ this.buffer[i++] = 1;
18500
+ for (; i < 16; i++) this.buffer[i] = 0;
18501
+ this.fin = 1;
18502
+ this.blocks(this.buffer, 0, 16);
18503
+ }
18504
+
18505
+ c = this.h[1] >>> 13;
18506
+ this.h[1] &= 0x1fff;
18507
+ for (i = 2; i < 10; i++) {
18508
+ this.h[i] += c;
18509
+ c = this.h[i] >>> 13;
18510
+ this.h[i] &= 0x1fff;
18511
+ }
18512
+ this.h[0] += (c * 5);
18513
+ c = this.h[0] >>> 13;
18514
+ this.h[0] &= 0x1fff;
18515
+ this.h[1] += c;
18516
+ c = this.h[1] >>> 13;
18517
+ this.h[1] &= 0x1fff;
18518
+ this.h[2] += c;
18519
+
18520
+ g[0] = this.h[0] + 5;
18521
+ c = g[0] >>> 13;
18522
+ g[0] &= 0x1fff;
18523
+ for (i = 1; i < 10; i++) {
18524
+ g[i] = this.h[i] + c;
18525
+ c = g[i] >>> 13;
18526
+ g[i] &= 0x1fff;
18527
+ }
18528
+ g[9] -= (1 << 13);
18529
+
18530
+ mask = (c ^ 1) - 1;
18531
+ for (i = 0; i < 10; i++) g[i] &= mask;
18532
+ mask = ~mask;
18533
+ for (i = 0; i < 10; i++) this.h[i] = (this.h[i] & mask) | g[i];
18534
+
18535
+ this.h[0] = ((this.h[0] ) | (this.h[1] << 13) ) & 0xffff;
18536
+ this.h[1] = ((this.h[1] >>> 3) | (this.h[2] << 10) ) & 0xffff;
18537
+ this.h[2] = ((this.h[2] >>> 6) | (this.h[3] << 7) ) & 0xffff;
18538
+ this.h[3] = ((this.h[3] >>> 9) | (this.h[4] << 4) ) & 0xffff;
18539
+ this.h[4] = ((this.h[4] >>> 12) | (this.h[5] << 1) | (this.h[6] << 14)) & 0xffff;
18540
+ this.h[5] = ((this.h[6] >>> 2) | (this.h[7] << 11) ) & 0xffff;
18541
+ this.h[6] = ((this.h[7] >>> 5) | (this.h[8] << 8) ) & 0xffff;
18542
+ this.h[7] = ((this.h[8] >>> 8) | (this.h[9] << 5) ) & 0xffff;
18543
+
18544
+ f = this.h[0] + this.pad[0];
18545
+ this.h[0] = f & 0xffff;
18546
+ for (i = 1; i < 8; i++) {
18547
+ f = (((this.h[i] + this.pad[i]) | 0) + (f >>> 16)) | 0;
18548
+ this.h[i] = f & 0xffff;
18549
+ }
18550
+
18551
+ mac[macpos+ 0] = (this.h[0] >>> 0) & 0xff;
18552
+ mac[macpos+ 1] = (this.h[0] >>> 8) & 0xff;
18553
+ mac[macpos+ 2] = (this.h[1] >>> 0) & 0xff;
18554
+ mac[macpos+ 3] = (this.h[1] >>> 8) & 0xff;
18555
+ mac[macpos+ 4] = (this.h[2] >>> 0) & 0xff;
18556
+ mac[macpos+ 5] = (this.h[2] >>> 8) & 0xff;
18557
+ mac[macpos+ 6] = (this.h[3] >>> 0) & 0xff;
18558
+ mac[macpos+ 7] = (this.h[3] >>> 8) & 0xff;
18559
+ mac[macpos+ 8] = (this.h[4] >>> 0) & 0xff;
18560
+ mac[macpos+ 9] = (this.h[4] >>> 8) & 0xff;
18561
+ mac[macpos+10] = (this.h[5] >>> 0) & 0xff;
18562
+ mac[macpos+11] = (this.h[5] >>> 8) & 0xff;
18563
+ mac[macpos+12] = (this.h[6] >>> 0) & 0xff;
18564
+ mac[macpos+13] = (this.h[6] >>> 8) & 0xff;
18565
+ mac[macpos+14] = (this.h[7] >>> 0) & 0xff;
18566
+ mac[macpos+15] = (this.h[7] >>> 8) & 0xff;
18567
+ };
18568
+
18569
+ poly1305.prototype.update = function(m, mpos, bytes) {
18570
+ var i, want;
18571
+
18572
+ if (this.leftover) {
18573
+ want = (16 - this.leftover);
18574
+ if (want > bytes)
18575
+ want = bytes;
18576
+ for (i = 0; i < want; i++)
18577
+ this.buffer[this.leftover + i] = m[mpos+i];
18578
+ bytes -= want;
18579
+ mpos += want;
18580
+ this.leftover += want;
18581
+ if (this.leftover < 16)
18582
+ return;
18583
+ this.blocks(this.buffer, 0, 16);
18584
+ this.leftover = 0;
18585
+ }
18586
+
18587
+ if (bytes >= 16) {
18588
+ want = bytes - (bytes % 16);
18589
+ this.blocks(m, mpos, want);
18590
+ mpos += want;
18591
+ bytes -= want;
18592
+ }
18593
+
18594
+ if (bytes) {
18595
+ for (i = 0; i < bytes; i++)
18596
+ this.buffer[this.leftover + i] = m[mpos+i];
18597
+ this.leftover += bytes;
18598
+ }
18599
+ };
18600
+
18601
+ function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
18602
+ var s = new poly1305(k);
18603
+ s.update(m, mpos, n);
18604
+ s.finish(out, outpos);
18605
+ return 0;
18606
+ }
18607
+
18608
+ function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
18609
+ var x = new Uint8Array(16);
18610
+ crypto_onetimeauth(x,0,m,mpos,n,k);
18611
+ return crypto_verify_16(h,hpos,x,0);
18612
+ }
18613
+
18614
+ function crypto_secretbox(c,m,d,n,k) {
18615
+ var i;
18616
+ if (d < 32) return -1;
18617
+ crypto_stream_xor(c,0,m,0,d,n,k);
18618
+ crypto_onetimeauth(c, 16, c, 32, d - 32, c);
18619
+ for (i = 0; i < 16; i++) c[i] = 0;
18620
+ return 0;
18621
+ }
18622
+
18623
+ function crypto_secretbox_open(m,c,d,n,k) {
18624
+ var i;
18625
+ var x = new Uint8Array(32);
18626
+ if (d < 32) return -1;
18627
+ crypto_stream(x,0,32,n,k);
18628
+ if (crypto_onetimeauth_verify(c, 16,c, 32,d - 32,x) !== 0) return -1;
18629
+ crypto_stream_xor(m,0,c,0,d,n,k);
18630
+ for (i = 0; i < 32; i++) m[i] = 0;
18631
+ return 0;
18632
+ }
18633
+
18634
+ function set25519(r, a) {
18635
+ var i;
18636
+ for (i = 0; i < 16; i++) r[i] = a[i]|0;
18637
+ }
18638
+
18639
+ function car25519(o) {
18640
+ var i, v, c = 1;
18641
+ for (i = 0; i < 16; i++) {
18642
+ v = o[i] + c + 65535;
18643
+ c = Math.floor(v / 65536);
18644
+ o[i] = v - c * 65536;
18645
+ }
18646
+ o[0] += c-1 + 37 * (c-1);
18647
+ }
18648
+
18649
+ function sel25519(p, q, b) {
18650
+ var t, c = ~(b-1);
18651
+ for (var i = 0; i < 16; i++) {
18652
+ t = c & (p[i] ^ q[i]);
18653
+ p[i] ^= t;
18654
+ q[i] ^= t;
18655
+ }
18656
+ }
18657
+
18658
+ function pack25519(o, n) {
18659
+ var i, j, b;
18660
+ var m = gf(), t = gf();
18661
+ for (i = 0; i < 16; i++) t[i] = n[i];
18662
+ car25519(t);
18663
+ car25519(t);
18664
+ car25519(t);
18665
+ for (j = 0; j < 2; j++) {
18666
+ m[0] = t[0] - 0xffed;
18667
+ for (i = 1; i < 15; i++) {
18668
+ m[i] = t[i] - 0xffff - ((m[i-1]>>16) & 1);
18669
+ m[i-1] &= 0xffff;
18670
+ }
18671
+ m[15] = t[15] - 0x7fff - ((m[14]>>16) & 1);
18672
+ b = (m[15]>>16) & 1;
18673
+ m[14] &= 0xffff;
18674
+ sel25519(t, m, 1-b);
18675
+ }
18676
+ for (i = 0; i < 16; i++) {
18677
+ o[2*i] = t[i] & 0xff;
18678
+ o[2*i+1] = t[i]>>8;
18679
+ }
18680
+ }
18681
+
18682
+ function neq25519(a, b) {
18683
+ var c = new Uint8Array(32), d = new Uint8Array(32);
18684
+ pack25519(c, a);
18685
+ pack25519(d, b);
18686
+ return crypto_verify_32(c, 0, d, 0);
18687
+ }
18688
+
18689
+ function par25519(a) {
18690
+ var d = new Uint8Array(32);
18691
+ pack25519(d, a);
18692
+ return d[0] & 1;
18693
+ }
18694
+
18695
+ function unpack25519(o, n) {
18696
+ var i;
18697
+ for (i = 0; i < 16; i++) o[i] = n[2*i] + (n[2*i+1] << 8);
18698
+ o[15] &= 0x7fff;
18699
+ }
18700
+
18701
+ function A(o, a, b) {
18702
+ for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
18703
+ }
18704
+
18705
+ function Z(o, a, b) {
18706
+ for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
18707
+ }
18708
+
18709
+ function M(o, a, b) {
18710
+ var v, c,
18711
+ t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0,
18712
+ t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0,
18713
+ t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0,
18714
+ t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0,
18715
+ b0 = b[0],
18716
+ b1 = b[1],
18717
+ b2 = b[2],
18718
+ b3 = b[3],
18719
+ b4 = b[4],
18720
+ b5 = b[5],
18721
+ b6 = b[6],
18722
+ b7 = b[7],
18723
+ b8 = b[8],
18724
+ b9 = b[9],
18725
+ b10 = b[10],
18726
+ b11 = b[11],
18727
+ b12 = b[12],
18728
+ b13 = b[13],
18729
+ b14 = b[14],
18730
+ b15 = b[15];
18731
+
18732
+ v = a[0];
18733
+ t0 += v * b0;
18734
+ t1 += v * b1;
18735
+ t2 += v * b2;
18736
+ t3 += v * b3;
18737
+ t4 += v * b4;
18738
+ t5 += v * b5;
18739
+ t6 += v * b6;
18740
+ t7 += v * b7;
18741
+ t8 += v * b8;
18742
+ t9 += v * b9;
18743
+ t10 += v * b10;
18744
+ t11 += v * b11;
18745
+ t12 += v * b12;
18746
+ t13 += v * b13;
18747
+ t14 += v * b14;
18748
+ t15 += v * b15;
18749
+ v = a[1];
18750
+ t1 += v * b0;
18751
+ t2 += v * b1;
18752
+ t3 += v * b2;
18753
+ t4 += v * b3;
18754
+ t5 += v * b4;
18755
+ t6 += v * b5;
18756
+ t7 += v * b6;
18757
+ t8 += v * b7;
18758
+ t9 += v * b8;
18759
+ t10 += v * b9;
18760
+ t11 += v * b10;
18761
+ t12 += v * b11;
18762
+ t13 += v * b12;
18763
+ t14 += v * b13;
18764
+ t15 += v * b14;
18765
+ t16 += v * b15;
18766
+ v = a[2];
18767
+ t2 += v * b0;
18768
+ t3 += v * b1;
18769
+ t4 += v * b2;
18770
+ t5 += v * b3;
18771
+ t6 += v * b4;
18772
+ t7 += v * b5;
18773
+ t8 += v * b6;
18774
+ t9 += v * b7;
18775
+ t10 += v * b8;
18776
+ t11 += v * b9;
18777
+ t12 += v * b10;
18778
+ t13 += v * b11;
18779
+ t14 += v * b12;
18780
+ t15 += v * b13;
18781
+ t16 += v * b14;
18782
+ t17 += v * b15;
18783
+ v = a[3];
18784
+ t3 += v * b0;
18785
+ t4 += v * b1;
18786
+ t5 += v * b2;
18787
+ t6 += v * b3;
18788
+ t7 += v * b4;
18789
+ t8 += v * b5;
18790
+ t9 += v * b6;
18791
+ t10 += v * b7;
18792
+ t11 += v * b8;
18793
+ t12 += v * b9;
18794
+ t13 += v * b10;
18795
+ t14 += v * b11;
18796
+ t15 += v * b12;
18797
+ t16 += v * b13;
18798
+ t17 += v * b14;
18799
+ t18 += v * b15;
18800
+ v = a[4];
18801
+ t4 += v * b0;
18802
+ t5 += v * b1;
18803
+ t6 += v * b2;
18804
+ t7 += v * b3;
18805
+ t8 += v * b4;
18806
+ t9 += v * b5;
18807
+ t10 += v * b6;
18808
+ t11 += v * b7;
18809
+ t12 += v * b8;
18810
+ t13 += v * b9;
18811
+ t14 += v * b10;
18812
+ t15 += v * b11;
18813
+ t16 += v * b12;
18814
+ t17 += v * b13;
18815
+ t18 += v * b14;
18816
+ t19 += v * b15;
18817
+ v = a[5];
18818
+ t5 += v * b0;
18819
+ t6 += v * b1;
18820
+ t7 += v * b2;
18821
+ t8 += v * b3;
18822
+ t9 += v * b4;
18823
+ t10 += v * b5;
18824
+ t11 += v * b6;
18825
+ t12 += v * b7;
18826
+ t13 += v * b8;
18827
+ t14 += v * b9;
18828
+ t15 += v * b10;
18829
+ t16 += v * b11;
18830
+ t17 += v * b12;
18831
+ t18 += v * b13;
18832
+ t19 += v * b14;
18833
+ t20 += v * b15;
18834
+ v = a[6];
18835
+ t6 += v * b0;
18836
+ t7 += v * b1;
18837
+ t8 += v * b2;
18838
+ t9 += v * b3;
18839
+ t10 += v * b4;
18840
+ t11 += v * b5;
18841
+ t12 += v * b6;
18842
+ t13 += v * b7;
18843
+ t14 += v * b8;
18844
+ t15 += v * b9;
18845
+ t16 += v * b10;
18846
+ t17 += v * b11;
18847
+ t18 += v * b12;
18848
+ t19 += v * b13;
18849
+ t20 += v * b14;
18850
+ t21 += v * b15;
18851
+ v = a[7];
18852
+ t7 += v * b0;
18853
+ t8 += v * b1;
18854
+ t9 += v * b2;
18855
+ t10 += v * b3;
18856
+ t11 += v * b4;
18857
+ t12 += v * b5;
18858
+ t13 += v * b6;
18859
+ t14 += v * b7;
18860
+ t15 += v * b8;
18861
+ t16 += v * b9;
18862
+ t17 += v * b10;
18863
+ t18 += v * b11;
18864
+ t19 += v * b12;
18865
+ t20 += v * b13;
18866
+ t21 += v * b14;
18867
+ t22 += v * b15;
18868
+ v = a[8];
18869
+ t8 += v * b0;
18870
+ t9 += v * b1;
18871
+ t10 += v * b2;
18872
+ t11 += v * b3;
18873
+ t12 += v * b4;
18874
+ t13 += v * b5;
18875
+ t14 += v * b6;
18876
+ t15 += v * b7;
18877
+ t16 += v * b8;
18878
+ t17 += v * b9;
18879
+ t18 += v * b10;
18880
+ t19 += v * b11;
18881
+ t20 += v * b12;
18882
+ t21 += v * b13;
18883
+ t22 += v * b14;
18884
+ t23 += v * b15;
18885
+ v = a[9];
18886
+ t9 += v * b0;
18887
+ t10 += v * b1;
18888
+ t11 += v * b2;
18889
+ t12 += v * b3;
18890
+ t13 += v * b4;
18891
+ t14 += v * b5;
18892
+ t15 += v * b6;
18893
+ t16 += v * b7;
18894
+ t17 += v * b8;
18895
+ t18 += v * b9;
18896
+ t19 += v * b10;
18897
+ t20 += v * b11;
18898
+ t21 += v * b12;
18899
+ t22 += v * b13;
18900
+ t23 += v * b14;
18901
+ t24 += v * b15;
18902
+ v = a[10];
18903
+ t10 += v * b0;
18904
+ t11 += v * b1;
18905
+ t12 += v * b2;
18906
+ t13 += v * b3;
18907
+ t14 += v * b4;
18908
+ t15 += v * b5;
18909
+ t16 += v * b6;
18910
+ t17 += v * b7;
18911
+ t18 += v * b8;
18912
+ t19 += v * b9;
18913
+ t20 += v * b10;
18914
+ t21 += v * b11;
18915
+ t22 += v * b12;
18916
+ t23 += v * b13;
18917
+ t24 += v * b14;
18918
+ t25 += v * b15;
18919
+ v = a[11];
18920
+ t11 += v * b0;
18921
+ t12 += v * b1;
18922
+ t13 += v * b2;
18923
+ t14 += v * b3;
18924
+ t15 += v * b4;
18925
+ t16 += v * b5;
18926
+ t17 += v * b6;
18927
+ t18 += v * b7;
18928
+ t19 += v * b8;
18929
+ t20 += v * b9;
18930
+ t21 += v * b10;
18931
+ t22 += v * b11;
18932
+ t23 += v * b12;
18933
+ t24 += v * b13;
18934
+ t25 += v * b14;
18935
+ t26 += v * b15;
18936
+ v = a[12];
18937
+ t12 += v * b0;
18938
+ t13 += v * b1;
18939
+ t14 += v * b2;
18940
+ t15 += v * b3;
18941
+ t16 += v * b4;
18942
+ t17 += v * b5;
18943
+ t18 += v * b6;
18944
+ t19 += v * b7;
18945
+ t20 += v * b8;
18946
+ t21 += v * b9;
18947
+ t22 += v * b10;
18948
+ t23 += v * b11;
18949
+ t24 += v * b12;
18950
+ t25 += v * b13;
18951
+ t26 += v * b14;
18952
+ t27 += v * b15;
18953
+ v = a[13];
18954
+ t13 += v * b0;
18955
+ t14 += v * b1;
18956
+ t15 += v * b2;
18957
+ t16 += v * b3;
18958
+ t17 += v * b4;
18959
+ t18 += v * b5;
18960
+ t19 += v * b6;
18961
+ t20 += v * b7;
18962
+ t21 += v * b8;
18963
+ t22 += v * b9;
18964
+ t23 += v * b10;
18965
+ t24 += v * b11;
18966
+ t25 += v * b12;
18967
+ t26 += v * b13;
18968
+ t27 += v * b14;
18969
+ t28 += v * b15;
18970
+ v = a[14];
18971
+ t14 += v * b0;
18972
+ t15 += v * b1;
18973
+ t16 += v * b2;
18974
+ t17 += v * b3;
18975
+ t18 += v * b4;
18976
+ t19 += v * b5;
18977
+ t20 += v * b6;
18978
+ t21 += v * b7;
18979
+ t22 += v * b8;
18980
+ t23 += v * b9;
18981
+ t24 += v * b10;
18982
+ t25 += v * b11;
18983
+ t26 += v * b12;
18984
+ t27 += v * b13;
18985
+ t28 += v * b14;
18986
+ t29 += v * b15;
18987
+ v = a[15];
18988
+ t15 += v * b0;
18989
+ t16 += v * b1;
18990
+ t17 += v * b2;
18991
+ t18 += v * b3;
18992
+ t19 += v * b4;
18993
+ t20 += v * b5;
18994
+ t21 += v * b6;
18995
+ t22 += v * b7;
18996
+ t23 += v * b8;
18997
+ t24 += v * b9;
18998
+ t25 += v * b10;
18999
+ t26 += v * b11;
19000
+ t27 += v * b12;
19001
+ t28 += v * b13;
19002
+ t29 += v * b14;
19003
+ t30 += v * b15;
19004
+
19005
+ t0 += 38 * t16;
19006
+ t1 += 38 * t17;
19007
+ t2 += 38 * t18;
19008
+ t3 += 38 * t19;
19009
+ t4 += 38 * t20;
19010
+ t5 += 38 * t21;
19011
+ t6 += 38 * t22;
19012
+ t7 += 38 * t23;
19013
+ t8 += 38 * t24;
19014
+ t9 += 38 * t25;
19015
+ t10 += 38 * t26;
19016
+ t11 += 38 * t27;
19017
+ t12 += 38 * t28;
19018
+ t13 += 38 * t29;
19019
+ t14 += 38 * t30;
19020
+ // t15 left as is
19021
+
19022
+ // first car
19023
+ c = 1;
19024
+ v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
19025
+ v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
19026
+ v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
19027
+ v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
19028
+ v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
19029
+ v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
19030
+ v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
19031
+ v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
19032
+ v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
19033
+ v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
19034
+ v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
19035
+ v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
19036
+ v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
19037
+ v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
19038
+ v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
19039
+ v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
19040
+ t0 += c-1 + 37 * (c-1);
19041
+
19042
+ // second car
19043
+ c = 1;
19044
+ v = t0 + c + 65535; c = Math.floor(v / 65536); t0 = v - c * 65536;
19045
+ v = t1 + c + 65535; c = Math.floor(v / 65536); t1 = v - c * 65536;
19046
+ v = t2 + c + 65535; c = Math.floor(v / 65536); t2 = v - c * 65536;
19047
+ v = t3 + c + 65535; c = Math.floor(v / 65536); t3 = v - c * 65536;
19048
+ v = t4 + c + 65535; c = Math.floor(v / 65536); t4 = v - c * 65536;
19049
+ v = t5 + c + 65535; c = Math.floor(v / 65536); t5 = v - c * 65536;
19050
+ v = t6 + c + 65535; c = Math.floor(v / 65536); t6 = v - c * 65536;
19051
+ v = t7 + c + 65535; c = Math.floor(v / 65536); t7 = v - c * 65536;
19052
+ v = t8 + c + 65535; c = Math.floor(v / 65536); t8 = v - c * 65536;
19053
+ v = t9 + c + 65535; c = Math.floor(v / 65536); t9 = v - c * 65536;
19054
+ v = t10 + c + 65535; c = Math.floor(v / 65536); t10 = v - c * 65536;
19055
+ v = t11 + c + 65535; c = Math.floor(v / 65536); t11 = v - c * 65536;
19056
+ v = t12 + c + 65535; c = Math.floor(v / 65536); t12 = v - c * 65536;
19057
+ v = t13 + c + 65535; c = Math.floor(v / 65536); t13 = v - c * 65536;
19058
+ v = t14 + c + 65535; c = Math.floor(v / 65536); t14 = v - c * 65536;
19059
+ v = t15 + c + 65535; c = Math.floor(v / 65536); t15 = v - c * 65536;
19060
+ t0 += c-1 + 37 * (c-1);
19061
+
19062
+ o[ 0] = t0;
19063
+ o[ 1] = t1;
19064
+ o[ 2] = t2;
19065
+ o[ 3] = t3;
19066
+ o[ 4] = t4;
19067
+ o[ 5] = t5;
19068
+ o[ 6] = t6;
19069
+ o[ 7] = t7;
19070
+ o[ 8] = t8;
19071
+ o[ 9] = t9;
19072
+ o[10] = t10;
19073
+ o[11] = t11;
19074
+ o[12] = t12;
19075
+ o[13] = t13;
19076
+ o[14] = t14;
19077
+ o[15] = t15;
19078
+ }
19079
+
19080
+ function S(o, a) {
19081
+ M(o, a, a);
19082
+ }
19083
+
19084
+ function inv25519(o, i) {
19085
+ var c = gf();
19086
+ var a;
19087
+ for (a = 0; a < 16; a++) c[a] = i[a];
19088
+ for (a = 253; a >= 0; a--) {
19089
+ S(c, c);
19090
+ if(a !== 2 && a !== 4) M(c, c, i);
19091
+ }
19092
+ for (a = 0; a < 16; a++) o[a] = c[a];
19093
+ }
19094
+
19095
+ function pow2523(o, i) {
19096
+ var c = gf();
19097
+ var a;
19098
+ for (a = 0; a < 16; a++) c[a] = i[a];
19099
+ for (a = 250; a >= 0; a--) {
19100
+ S(c, c);
19101
+ if(a !== 1) M(c, c, i);
19102
+ }
19103
+ for (a = 0; a < 16; a++) o[a] = c[a];
19104
+ }
19105
+
19106
+ function crypto_scalarmult(q, n, p) {
19107
+ var z = new Uint8Array(32);
19108
+ var x = new Float64Array(80), r, i;
19109
+ var a = gf(), b = gf(), c = gf(),
19110
+ d = gf(), e = gf(), f = gf();
19111
+ for (i = 0; i < 31; i++) z[i] = n[i];
19112
+ z[31]=(n[31]&127)|64;
19113
+ z[0]&=248;
19114
+ unpack25519(x,p);
19115
+ for (i = 0; i < 16; i++) {
19116
+ b[i]=x[i];
19117
+ d[i]=a[i]=c[i]=0;
19118
+ }
19119
+ a[0]=d[0]=1;
19120
+ for (i=254; i>=0; --i) {
19121
+ r=(z[i>>>3]>>>(i&7))&1;
19122
+ sel25519(a,b,r);
19123
+ sel25519(c,d,r);
19124
+ A(e,a,c);
19125
+ Z(a,a,c);
19126
+ A(c,b,d);
19127
+ Z(b,b,d);
19128
+ S(d,e);
19129
+ S(f,a);
19130
+ M(a,c,a);
19131
+ M(c,b,e);
19132
+ A(e,a,c);
19133
+ Z(a,a,c);
19134
+ S(b,a);
19135
+ Z(c,d,f);
19136
+ M(a,c,_121665);
19137
+ A(a,a,d);
19138
+ M(c,c,a);
19139
+ M(a,d,f);
19140
+ M(d,b,x);
19141
+ S(b,e);
19142
+ sel25519(a,b,r);
19143
+ sel25519(c,d,r);
19144
+ }
19145
+ for (i = 0; i < 16; i++) {
19146
+ x[i+16]=a[i];
19147
+ x[i+32]=c[i];
19148
+ x[i+48]=b[i];
19149
+ x[i+64]=d[i];
19150
+ }
19151
+ var x32 = x.subarray(32);
19152
+ var x16 = x.subarray(16);
19153
+ inv25519(x32,x32);
19154
+ M(x16,x16,x32);
19155
+ pack25519(q,x16);
19156
+ return 0;
19157
+ }
19158
+
19159
+ function crypto_scalarmult_base(q, n) {
19160
+ return crypto_scalarmult(q, n, _9);
19161
+ }
19162
+
19163
+ function crypto_box_keypair(y, x) {
19164
+ randombytes(x, 32);
19165
+ return crypto_scalarmult_base(y, x);
19166
+ }
19167
+
19168
+ function crypto_box_beforenm(k, y, x) {
19169
+ var s = new Uint8Array(32);
19170
+ crypto_scalarmult(s, x, y);
19171
+ return crypto_core_hsalsa20(k, _0, s, sigma);
19172
+ }
19173
+
19174
+ var crypto_box_afternm = crypto_secretbox;
19175
+ var crypto_box_open_afternm = crypto_secretbox_open;
19176
+
19177
+ function crypto_box(c, m, d, n, y, x) {
19178
+ var k = new Uint8Array(32);
19179
+ crypto_box_beforenm(k, y, x);
19180
+ return crypto_box_afternm(c, m, d, n, k);
19181
+ }
19182
+
19183
+ function crypto_box_open(m, c, d, n, y, x) {
19184
+ var k = new Uint8Array(32);
19185
+ crypto_box_beforenm(k, y, x);
19186
+ return crypto_box_open_afternm(m, c, d, n, k);
19187
+ }
19188
+
19189
+ var K = [
19190
+ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
19191
+ 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
19192
+ 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
19193
+ 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
19194
+ 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
19195
+ 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
19196
+ 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
19197
+ 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
19198
+ 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
19199
+ 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
19200
+ 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
19201
+ 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
19202
+ 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
19203
+ 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
19204
+ 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
19205
+ 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
19206
+ 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
19207
+ 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
19208
+ 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
19209
+ 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
19210
+ 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
19211
+ 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
19212
+ 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
19213
+ 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
19214
+ 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
19215
+ 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
19216
+ 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
19217
+ 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
19218
+ 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
19219
+ 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
19220
+ 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
19221
+ 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
19222
+ 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
19223
+ 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
19224
+ 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
19225
+ 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
19226
+ 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
19227
+ 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
19228
+ 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
19229
+ 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
19230
+ ];
19231
+
19232
+ function crypto_hashblocks_hl(hh, hl, m, n) {
19233
+ var wh = new Int32Array(16), wl = new Int32Array(16),
19234
+ bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7,
19235
+ bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7,
19236
+ th, tl, i, j, h, l, a, b, c, d;
19237
+
19238
+ var ah0 = hh[0],
19239
+ ah1 = hh[1],
19240
+ ah2 = hh[2],
19241
+ ah3 = hh[3],
19242
+ ah4 = hh[4],
19243
+ ah5 = hh[5],
19244
+ ah6 = hh[6],
19245
+ ah7 = hh[7],
19246
+
19247
+ al0 = hl[0],
19248
+ al1 = hl[1],
19249
+ al2 = hl[2],
19250
+ al3 = hl[3],
19251
+ al4 = hl[4],
19252
+ al5 = hl[5],
19253
+ al6 = hl[6],
19254
+ al7 = hl[7];
19255
+
19256
+ var pos = 0;
19257
+ while (n >= 128) {
19258
+ for (i = 0; i < 16; i++) {
19259
+ j = 8 * i + pos;
19260
+ wh[i] = (m[j+0] << 24) | (m[j+1] << 16) | (m[j+2] << 8) | m[j+3];
19261
+ wl[i] = (m[j+4] << 24) | (m[j+5] << 16) | (m[j+6] << 8) | m[j+7];
19262
+ }
19263
+ for (i = 0; i < 80; i++) {
19264
+ bh0 = ah0;
19265
+ bh1 = ah1;
19266
+ bh2 = ah2;
19267
+ bh3 = ah3;
19268
+ bh4 = ah4;
19269
+ bh5 = ah5;
19270
+ bh6 = ah6;
19271
+ bh7 = ah7;
19272
+
19273
+ bl0 = al0;
19274
+ bl1 = al1;
19275
+ bl2 = al2;
19276
+ bl3 = al3;
19277
+ bl4 = al4;
19278
+ bl5 = al5;
19279
+ bl6 = al6;
19280
+ bl7 = al7;
19281
+
19282
+ // add
19283
+ h = ah7;
19284
+ l = al7;
19285
+
19286
+ a = l & 0xffff; b = l >>> 16;
19287
+ c = h & 0xffff; d = h >>> 16;
19288
+
19289
+ // Sigma1
19290
+ h = ((ah4 >>> 14) | (al4 << (32-14))) ^ ((ah4 >>> 18) | (al4 << (32-18))) ^ ((al4 >>> (41-32)) | (ah4 << (32-(41-32))));
19291
+ l = ((al4 >>> 14) | (ah4 << (32-14))) ^ ((al4 >>> 18) | (ah4 << (32-18))) ^ ((ah4 >>> (41-32)) | (al4 << (32-(41-32))));
19292
+
19293
+ a += l & 0xffff; b += l >>> 16;
19294
+ c += h & 0xffff; d += h >>> 16;
19295
+
19296
+ // Ch
19297
+ h = (ah4 & ah5) ^ (~ah4 & ah6);
19298
+ l = (al4 & al5) ^ (~al4 & al6);
19299
+
19300
+ a += l & 0xffff; b += l >>> 16;
19301
+ c += h & 0xffff; d += h >>> 16;
19302
+
19303
+ // K
19304
+ h = K[i*2];
19305
+ l = K[i*2+1];
19306
+
19307
+ a += l & 0xffff; b += l >>> 16;
19308
+ c += h & 0xffff; d += h >>> 16;
19309
+
19310
+ // w
19311
+ h = wh[i%16];
19312
+ l = wl[i%16];
19313
+
19314
+ a += l & 0xffff; b += l >>> 16;
19315
+ c += h & 0xffff; d += h >>> 16;
19316
+
19317
+ b += a >>> 16;
19318
+ c += b >>> 16;
19319
+ d += c >>> 16;
19320
+
19321
+ th = c & 0xffff | d << 16;
19322
+ tl = a & 0xffff | b << 16;
19323
+
19324
+ // add
19325
+ h = th;
19326
+ l = tl;
19327
+
19328
+ a = l & 0xffff; b = l >>> 16;
19329
+ c = h & 0xffff; d = h >>> 16;
19330
+
19331
+ // Sigma0
19332
+ h = ((ah0 >>> 28) | (al0 << (32-28))) ^ ((al0 >>> (34-32)) | (ah0 << (32-(34-32)))) ^ ((al0 >>> (39-32)) | (ah0 << (32-(39-32))));
19333
+ l = ((al0 >>> 28) | (ah0 << (32-28))) ^ ((ah0 >>> (34-32)) | (al0 << (32-(34-32)))) ^ ((ah0 >>> (39-32)) | (al0 << (32-(39-32))));
19334
+
19335
+ a += l & 0xffff; b += l >>> 16;
19336
+ c += h & 0xffff; d += h >>> 16;
19337
+
19338
+ // Maj
19339
+ h = (ah0 & ah1) ^ (ah0 & ah2) ^ (ah1 & ah2);
19340
+ l = (al0 & al1) ^ (al0 & al2) ^ (al1 & al2);
19341
+
19342
+ a += l & 0xffff; b += l >>> 16;
19343
+ c += h & 0xffff; d += h >>> 16;
19344
+
19345
+ b += a >>> 16;
19346
+ c += b >>> 16;
19347
+ d += c >>> 16;
19348
+
19349
+ bh7 = (c & 0xffff) | (d << 16);
19350
+ bl7 = (a & 0xffff) | (b << 16);
19351
+
19352
+ // add
19353
+ h = bh3;
19354
+ l = bl3;
19355
+
19356
+ a = l & 0xffff; b = l >>> 16;
19357
+ c = h & 0xffff; d = h >>> 16;
19358
+
19359
+ h = th;
19360
+ l = tl;
19361
+
19362
+ a += l & 0xffff; b += l >>> 16;
19363
+ c += h & 0xffff; d += h >>> 16;
19364
+
19365
+ b += a >>> 16;
19366
+ c += b >>> 16;
19367
+ d += c >>> 16;
19368
+
19369
+ bh3 = (c & 0xffff) | (d << 16);
19370
+ bl3 = (a & 0xffff) | (b << 16);
19371
+
19372
+ ah1 = bh0;
19373
+ ah2 = bh1;
19374
+ ah3 = bh2;
19375
+ ah4 = bh3;
19376
+ ah5 = bh4;
19377
+ ah6 = bh5;
19378
+ ah7 = bh6;
19379
+ ah0 = bh7;
19380
+
19381
+ al1 = bl0;
19382
+ al2 = bl1;
19383
+ al3 = bl2;
19384
+ al4 = bl3;
19385
+ al5 = bl4;
19386
+ al6 = bl5;
19387
+ al7 = bl6;
19388
+ al0 = bl7;
19389
+
19390
+ if (i%16 === 15) {
19391
+ for (j = 0; j < 16; j++) {
19392
+ // add
19393
+ h = wh[j];
19394
+ l = wl[j];
19395
+
19396
+ a = l & 0xffff; b = l >>> 16;
19397
+ c = h & 0xffff; d = h >>> 16;
19398
+
19399
+ h = wh[(j+9)%16];
19400
+ l = wl[(j+9)%16];
19401
+
19402
+ a += l & 0xffff; b += l >>> 16;
19403
+ c += h & 0xffff; d += h >>> 16;
19404
+
19405
+ // sigma0
19406
+ th = wh[(j+1)%16];
19407
+ tl = wl[(j+1)%16];
19408
+ h = ((th >>> 1) | (tl << (32-1))) ^ ((th >>> 8) | (tl << (32-8))) ^ (th >>> 7);
19409
+ l = ((tl >>> 1) | (th << (32-1))) ^ ((tl >>> 8) | (th << (32-8))) ^ ((tl >>> 7) | (th << (32-7)));
19410
+
19411
+ a += l & 0xffff; b += l >>> 16;
19412
+ c += h & 0xffff; d += h >>> 16;
19413
+
19414
+ // sigma1
19415
+ th = wh[(j+14)%16];
19416
+ tl = wl[(j+14)%16];
19417
+ h = ((th >>> 19) | (tl << (32-19))) ^ ((tl >>> (61-32)) | (th << (32-(61-32)))) ^ (th >>> 6);
19418
+ l = ((tl >>> 19) | (th << (32-19))) ^ ((th >>> (61-32)) | (tl << (32-(61-32)))) ^ ((tl >>> 6) | (th << (32-6)));
19419
+
19420
+ a += l & 0xffff; b += l >>> 16;
19421
+ c += h & 0xffff; d += h >>> 16;
19422
+
19423
+ b += a >>> 16;
19424
+ c += b >>> 16;
19425
+ d += c >>> 16;
19426
+
19427
+ wh[j] = (c & 0xffff) | (d << 16);
19428
+ wl[j] = (a & 0xffff) | (b << 16);
19429
+ }
19430
+ }
19431
+ }
19432
+
19433
+ // add
19434
+ h = ah0;
19435
+ l = al0;
19436
+
19437
+ a = l & 0xffff; b = l >>> 16;
19438
+ c = h & 0xffff; d = h >>> 16;
19439
+
19440
+ h = hh[0];
19441
+ l = hl[0];
19442
+
19443
+ a += l & 0xffff; b += l >>> 16;
19444
+ c += h & 0xffff; d += h >>> 16;
19445
+
19446
+ b += a >>> 16;
19447
+ c += b >>> 16;
19448
+ d += c >>> 16;
19449
+
19450
+ hh[0] = ah0 = (c & 0xffff) | (d << 16);
19451
+ hl[0] = al0 = (a & 0xffff) | (b << 16);
19452
+
19453
+ h = ah1;
19454
+ l = al1;
19455
+
19456
+ a = l & 0xffff; b = l >>> 16;
19457
+ c = h & 0xffff; d = h >>> 16;
19458
+
19459
+ h = hh[1];
19460
+ l = hl[1];
19461
+
19462
+ a += l & 0xffff; b += l >>> 16;
19463
+ c += h & 0xffff; d += h >>> 16;
19464
+
19465
+ b += a >>> 16;
19466
+ c += b >>> 16;
19467
+ d += c >>> 16;
19468
+
19469
+ hh[1] = ah1 = (c & 0xffff) | (d << 16);
19470
+ hl[1] = al1 = (a & 0xffff) | (b << 16);
19471
+
19472
+ h = ah2;
19473
+ l = al2;
19474
+
19475
+ a = l & 0xffff; b = l >>> 16;
19476
+ c = h & 0xffff; d = h >>> 16;
19477
+
19478
+ h = hh[2];
19479
+ l = hl[2];
19480
+
19481
+ a += l & 0xffff; b += l >>> 16;
19482
+ c += h & 0xffff; d += h >>> 16;
19483
+
19484
+ b += a >>> 16;
19485
+ c += b >>> 16;
19486
+ d += c >>> 16;
19487
+
19488
+ hh[2] = ah2 = (c & 0xffff) | (d << 16);
19489
+ hl[2] = al2 = (a & 0xffff) | (b << 16);
19490
+
19491
+ h = ah3;
19492
+ l = al3;
19493
+
19494
+ a = l & 0xffff; b = l >>> 16;
19495
+ c = h & 0xffff; d = h >>> 16;
19496
+
19497
+ h = hh[3];
19498
+ l = hl[3];
19499
+
19500
+ a += l & 0xffff; b += l >>> 16;
19501
+ c += h & 0xffff; d += h >>> 16;
19502
+
19503
+ b += a >>> 16;
19504
+ c += b >>> 16;
19505
+ d += c >>> 16;
19506
+
19507
+ hh[3] = ah3 = (c & 0xffff) | (d << 16);
19508
+ hl[3] = al3 = (a & 0xffff) | (b << 16);
19509
+
19510
+ h = ah4;
19511
+ l = al4;
19512
+
19513
+ a = l & 0xffff; b = l >>> 16;
19514
+ c = h & 0xffff; d = h >>> 16;
19515
+
19516
+ h = hh[4];
19517
+ l = hl[4];
19518
+
19519
+ a += l & 0xffff; b += l >>> 16;
19520
+ c += h & 0xffff; d += h >>> 16;
19521
+
19522
+ b += a >>> 16;
19523
+ c += b >>> 16;
19524
+ d += c >>> 16;
19525
+
19526
+ hh[4] = ah4 = (c & 0xffff) | (d << 16);
19527
+ hl[4] = al4 = (a & 0xffff) | (b << 16);
19528
+
19529
+ h = ah5;
19530
+ l = al5;
19531
+
19532
+ a = l & 0xffff; b = l >>> 16;
19533
+ c = h & 0xffff; d = h >>> 16;
19534
+
19535
+ h = hh[5];
19536
+ l = hl[5];
19537
+
19538
+ a += l & 0xffff; b += l >>> 16;
19539
+ c += h & 0xffff; d += h >>> 16;
19540
+
19541
+ b += a >>> 16;
19542
+ c += b >>> 16;
19543
+ d += c >>> 16;
19544
+
19545
+ hh[5] = ah5 = (c & 0xffff) | (d << 16);
19546
+ hl[5] = al5 = (a & 0xffff) | (b << 16);
19547
+
19548
+ h = ah6;
19549
+ l = al6;
19550
+
19551
+ a = l & 0xffff; b = l >>> 16;
19552
+ c = h & 0xffff; d = h >>> 16;
19553
+
19554
+ h = hh[6];
19555
+ l = hl[6];
19556
+
19557
+ a += l & 0xffff; b += l >>> 16;
19558
+ c += h & 0xffff; d += h >>> 16;
19559
+
19560
+ b += a >>> 16;
19561
+ c += b >>> 16;
19562
+ d += c >>> 16;
19563
+
19564
+ hh[6] = ah6 = (c & 0xffff) | (d << 16);
19565
+ hl[6] = al6 = (a & 0xffff) | (b << 16);
19566
+
19567
+ h = ah7;
19568
+ l = al7;
19569
+
19570
+ a = l & 0xffff; b = l >>> 16;
19571
+ c = h & 0xffff; d = h >>> 16;
19572
+
19573
+ h = hh[7];
19574
+ l = hl[7];
19575
+
19576
+ a += l & 0xffff; b += l >>> 16;
19577
+ c += h & 0xffff; d += h >>> 16;
19578
+
19579
+ b += a >>> 16;
19580
+ c += b >>> 16;
19581
+ d += c >>> 16;
19582
+
19583
+ hh[7] = ah7 = (c & 0xffff) | (d << 16);
19584
+ hl[7] = al7 = (a & 0xffff) | (b << 16);
19585
+
19586
+ pos += 128;
19587
+ n -= 128;
19588
+ }
19589
+
19590
+ return n;
19591
+ }
19592
+
19593
+ function crypto_hash(out, m, n) {
19594
+ var hh = new Int32Array(8),
19595
+ hl = new Int32Array(8),
19596
+ x = new Uint8Array(256),
19597
+ i, b = n;
19598
+
19599
+ hh[0] = 0x6a09e667;
19600
+ hh[1] = 0xbb67ae85;
19601
+ hh[2] = 0x3c6ef372;
19602
+ hh[3] = 0xa54ff53a;
19603
+ hh[4] = 0x510e527f;
19604
+ hh[5] = 0x9b05688c;
19605
+ hh[6] = 0x1f83d9ab;
19606
+ hh[7] = 0x5be0cd19;
19607
+
19608
+ hl[0] = 0xf3bcc908;
19609
+ hl[1] = 0x84caa73b;
19610
+ hl[2] = 0xfe94f82b;
19611
+ hl[3] = 0x5f1d36f1;
19612
+ hl[4] = 0xade682d1;
19613
+ hl[5] = 0x2b3e6c1f;
19614
+ hl[6] = 0xfb41bd6b;
19615
+ hl[7] = 0x137e2179;
19616
+
19617
+ crypto_hashblocks_hl(hh, hl, m, n);
19618
+ n %= 128;
19619
+
19620
+ for (i = 0; i < n; i++) x[i] = m[b-n+i];
19621
+ x[n] = 128;
19622
+
19623
+ n = 256-128*(n<112?1:0);
19624
+ x[n-9] = 0;
19625
+ ts64(x, n-8, (b / 0x20000000) | 0, b << 3);
19626
+ crypto_hashblocks_hl(hh, hl, x, n);
19627
+
19628
+ for (i = 0; i < 8; i++) ts64(out, 8*i, hh[i], hl[i]);
19629
+
19630
+ return 0;
19631
+ }
19632
+
19633
+ function add(p, q) {
19634
+ var a = gf(), b = gf(), c = gf(),
19635
+ d = gf(), e = gf(), f = gf(),
19636
+ g = gf(), h = gf(), t = gf();
19637
+
19638
+ Z(a, p[1], p[0]);
19639
+ Z(t, q[1], q[0]);
19640
+ M(a, a, t);
19641
+ A(b, p[0], p[1]);
19642
+ A(t, q[0], q[1]);
19643
+ M(b, b, t);
19644
+ M(c, p[3], q[3]);
19645
+ M(c, c, D2);
19646
+ M(d, p[2], q[2]);
19647
+ A(d, d, d);
19648
+ Z(e, b, a);
19649
+ Z(f, d, c);
19650
+ A(g, d, c);
19651
+ A(h, b, a);
19652
+
19653
+ M(p[0], e, f);
19654
+ M(p[1], h, g);
19655
+ M(p[2], g, f);
19656
+ M(p[3], e, h);
19657
+ }
19658
+
19659
+ function cswap(p, q, b) {
19660
+ var i;
19661
+ for (i = 0; i < 4; i++) {
19662
+ sel25519(p[i], q[i], b);
19663
+ }
19664
+ }
19665
+
19666
+ function pack(r, p) {
19667
+ var tx = gf(), ty = gf(), zi = gf();
19668
+ inv25519(zi, p[2]);
19669
+ M(tx, p[0], zi);
19670
+ M(ty, p[1], zi);
19671
+ pack25519(r, ty);
19672
+ r[31] ^= par25519(tx) << 7;
19673
+ }
19674
+
19675
+ function scalarmult(p, q, s) {
19676
+ var b, i;
19677
+ set25519(p[0], gf0);
19678
+ set25519(p[1], gf1);
19679
+ set25519(p[2], gf1);
19680
+ set25519(p[3], gf0);
19681
+ for (i = 255; i >= 0; --i) {
19682
+ b = (s[(i/8)|0] >> (i&7)) & 1;
19683
+ cswap(p, q, b);
19684
+ add(q, p);
19685
+ add(p, p);
19686
+ cswap(p, q, b);
19687
+ }
19688
+ }
19689
+
19690
+ function scalarbase(p, s) {
19691
+ var q = [gf(), gf(), gf(), gf()];
19692
+ set25519(q[0], X);
19693
+ set25519(q[1], Y);
19694
+ set25519(q[2], gf1);
19695
+ M(q[3], X, Y);
19696
+ scalarmult(p, q, s);
19697
+ }
19698
+
19699
+ function crypto_sign_keypair(pk, sk, seeded) {
19700
+ var d = new Uint8Array(64);
19701
+ var p = [gf(), gf(), gf(), gf()];
19702
+ var i;
19703
+
19704
+ if (!seeded) randombytes(sk, 32);
19705
+ crypto_hash(d, sk, 32);
19706
+ d[0] &= 248;
19707
+ d[31] &= 127;
19708
+ d[31] |= 64;
19709
+
19710
+ scalarbase(p, d);
19711
+ pack(pk, p);
19712
+
19713
+ for (i = 0; i < 32; i++) sk[i+32] = pk[i];
19714
+ return 0;
19715
+ }
19716
+
19717
+ 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]);
19718
+
19719
+ function modL(r, x) {
19720
+ var carry, i, j, k;
19721
+ for (i = 63; i >= 32; --i) {
19722
+ carry = 0;
19723
+ for (j = i - 32, k = i - 12; j < k; ++j) {
19724
+ x[j] += carry - 16 * x[i] * L[j - (i - 32)];
19725
+ carry = Math.floor((x[j] + 128) / 256);
19726
+ x[j] -= carry * 256;
19727
+ }
19728
+ x[j] += carry;
19729
+ x[i] = 0;
19730
+ }
19731
+ carry = 0;
19732
+ for (j = 0; j < 32; j++) {
19733
+ x[j] += carry - (x[31] >> 4) * L[j];
19734
+ carry = x[j] >> 8;
19735
+ x[j] &= 255;
19736
+ }
19737
+ for (j = 0; j < 32; j++) x[j] -= carry * L[j];
19738
+ for (i = 0; i < 32; i++) {
19739
+ x[i+1] += x[i] >> 8;
19740
+ r[i] = x[i] & 255;
19741
+ }
19742
+ }
19743
+
19744
+ function reduce(r) {
19745
+ var x = new Float64Array(64), i;
19746
+ for (i = 0; i < 64; i++) x[i] = r[i];
19747
+ for (i = 0; i < 64; i++) r[i] = 0;
19748
+ modL(r, x);
19749
+ }
19750
+
19751
+ // Note: difference from C - smlen returned, not passed as argument.
19752
+ function crypto_sign(sm, m, n, sk) {
19753
+ var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
19754
+ var i, j, x = new Float64Array(64);
19755
+ var p = [gf(), gf(), gf(), gf()];
19756
+
19757
+ crypto_hash(d, sk, 32);
19758
+ d[0] &= 248;
19759
+ d[31] &= 127;
19760
+ d[31] |= 64;
19761
+
19762
+ var smlen = n + 64;
19763
+ for (i = 0; i < n; i++) sm[64 + i] = m[i];
19764
+ for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
19765
+
19766
+ crypto_hash(r, sm.subarray(32), n+32);
19767
+ reduce(r);
19768
+ scalarbase(p, r);
19769
+ pack(sm, p);
19770
+
19771
+ for (i = 32; i < 64; i++) sm[i] = sk[i];
19772
+ crypto_hash(h, sm, n + 64);
19773
+ reduce(h);
19774
+
19775
+ for (i = 0; i < 64; i++) x[i] = 0;
19776
+ for (i = 0; i < 32; i++) x[i] = r[i];
19777
+ for (i = 0; i < 32; i++) {
19778
+ for (j = 0; j < 32; j++) {
19779
+ x[i+j] += h[i] * d[j];
19780
+ }
19781
+ }
19782
+
19783
+ modL(sm.subarray(32), x);
19784
+ return smlen;
19785
+ }
19786
+
19787
+ function unpackneg(r, p) {
19788
+ var t = gf(), chk = gf(), num = gf(),
19789
+ den = gf(), den2 = gf(), den4 = gf(),
19790
+ den6 = gf();
19791
+
19792
+ set25519(r[2], gf1);
19793
+ unpack25519(r[1], p);
19794
+ S(num, r[1]);
19795
+ M(den, num, D);
19796
+ Z(num, num, r[2]);
19797
+ A(den, r[2], den);
19798
+
19799
+ S(den2, den);
19800
+ S(den4, den2);
19801
+ M(den6, den4, den2);
19802
+ M(t, den6, num);
19803
+ M(t, t, den);
19804
+
19805
+ pow2523(t, t);
19806
+ M(t, t, num);
19807
+ M(t, t, den);
19808
+ M(t, t, den);
19809
+ M(r[0], t, den);
19810
+
19811
+ S(chk, r[0]);
19812
+ M(chk, chk, den);
19813
+ if (neq25519(chk, num)) M(r[0], r[0], I);
19814
+
19815
+ S(chk, r[0]);
19816
+ M(chk, chk, den);
19817
+ if (neq25519(chk, num)) return -1;
19818
+
19819
+ if (par25519(r[0]) === (p[31]>>7)) Z(r[0], gf0, r[0]);
19820
+
19821
+ M(r[3], r[0], r[1]);
19822
+ return 0;
19823
+ }
19824
+
19825
+ function crypto_sign_open(m, sm, n, pk) {
19826
+ var i;
19827
+ var t = new Uint8Array(32), h = new Uint8Array(64);
19828
+ var p = [gf(), gf(), gf(), gf()],
19829
+ q = [gf(), gf(), gf(), gf()];
19830
+
19831
+ if (n < 64) return -1;
19832
+
19833
+ if (unpackneg(q, pk)) return -1;
19834
+
19835
+ for (i = 0; i < n; i++) m[i] = sm[i];
19836
+ for (i = 0; i < 32; i++) m[i+32] = pk[i];
19837
+ crypto_hash(h, m, n);
19838
+ reduce(h);
19839
+ scalarmult(p, q, h);
19840
+
19841
+ scalarbase(q, sm.subarray(32));
19842
+ add(p, q);
19843
+ pack(t, p);
19844
+
19845
+ n -= 64;
19846
+ if (crypto_verify_32(sm, 0, t, 0)) {
19847
+ for (i = 0; i < n; i++) m[i] = 0;
19848
+ return -1;
19849
+ }
19850
+
19851
+ for (i = 0; i < n; i++) m[i] = sm[i + 64];
19852
+ return n;
19853
+ }
19854
+
19855
+ var crypto_secretbox_KEYBYTES = 32,
19856
+ crypto_secretbox_NONCEBYTES = 24,
19857
+ crypto_secretbox_ZEROBYTES = 32,
19858
+ crypto_secretbox_BOXZEROBYTES = 16,
19859
+ crypto_scalarmult_BYTES = 32,
19860
+ crypto_scalarmult_SCALARBYTES = 32,
19861
+ crypto_box_PUBLICKEYBYTES = 32,
19862
+ crypto_box_SECRETKEYBYTES = 32,
19863
+ crypto_box_BEFORENMBYTES = 32,
19864
+ crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES,
19865
+ crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES,
19866
+ crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES,
19867
+ crypto_sign_BYTES = 64,
19868
+ crypto_sign_PUBLICKEYBYTES = 32,
19869
+ crypto_sign_SECRETKEYBYTES = 64,
19870
+ crypto_sign_SEEDBYTES = 32,
19871
+ crypto_hash_BYTES = 64;
19872
+
19873
+ nacl.lowlevel = {
19874
+ crypto_core_hsalsa20: crypto_core_hsalsa20,
19875
+ crypto_stream_xor: crypto_stream_xor,
19876
+ crypto_stream: crypto_stream,
19877
+ crypto_stream_salsa20_xor: crypto_stream_salsa20_xor,
19878
+ crypto_stream_salsa20: crypto_stream_salsa20,
19879
+ crypto_onetimeauth: crypto_onetimeauth,
19880
+ crypto_onetimeauth_verify: crypto_onetimeauth_verify,
19881
+ crypto_verify_16: crypto_verify_16,
19882
+ crypto_verify_32: crypto_verify_32,
19883
+ crypto_secretbox: crypto_secretbox,
19884
+ crypto_secretbox_open: crypto_secretbox_open,
19885
+ crypto_scalarmult: crypto_scalarmult,
19886
+ crypto_scalarmult_base: crypto_scalarmult_base,
19887
+ crypto_box_beforenm: crypto_box_beforenm,
19888
+ crypto_box_afternm: crypto_box_afternm,
19889
+ crypto_box: crypto_box,
19890
+ crypto_box_open: crypto_box_open,
19891
+ crypto_box_keypair: crypto_box_keypair,
19892
+ crypto_hash: crypto_hash,
19893
+ crypto_sign: crypto_sign,
19894
+ crypto_sign_keypair: crypto_sign_keypair,
19895
+ crypto_sign_open: crypto_sign_open,
19896
+
19897
+ crypto_secretbox_KEYBYTES: crypto_secretbox_KEYBYTES,
19898
+ crypto_secretbox_NONCEBYTES: crypto_secretbox_NONCEBYTES,
19899
+ crypto_secretbox_ZEROBYTES: crypto_secretbox_ZEROBYTES,
19900
+ crypto_secretbox_BOXZEROBYTES: crypto_secretbox_BOXZEROBYTES,
19901
+ crypto_scalarmult_BYTES: crypto_scalarmult_BYTES,
19902
+ crypto_scalarmult_SCALARBYTES: crypto_scalarmult_SCALARBYTES,
19903
+ crypto_box_PUBLICKEYBYTES: crypto_box_PUBLICKEYBYTES,
19904
+ crypto_box_SECRETKEYBYTES: crypto_box_SECRETKEYBYTES,
19905
+ crypto_box_BEFORENMBYTES: crypto_box_BEFORENMBYTES,
19906
+ crypto_box_NONCEBYTES: crypto_box_NONCEBYTES,
19907
+ crypto_box_ZEROBYTES: crypto_box_ZEROBYTES,
19908
+ crypto_box_BOXZEROBYTES: crypto_box_BOXZEROBYTES,
19909
+ crypto_sign_BYTES: crypto_sign_BYTES,
19910
+ crypto_sign_PUBLICKEYBYTES: crypto_sign_PUBLICKEYBYTES,
19911
+ crypto_sign_SECRETKEYBYTES: crypto_sign_SECRETKEYBYTES,
19912
+ crypto_sign_SEEDBYTES: crypto_sign_SEEDBYTES,
19913
+ crypto_hash_BYTES: crypto_hash_BYTES,
19914
+
19915
+ gf: gf,
19916
+ D: D,
19917
+ L: L,
19918
+ pack25519: pack25519,
19919
+ unpack25519: unpack25519,
19920
+ M: M,
19921
+ A: A,
19922
+ S: S,
19923
+ Z: Z,
19924
+ pow2523: pow2523,
19925
+ add: add,
19926
+ set25519: set25519,
19927
+ modL: modL,
19928
+ scalarmult: scalarmult,
19929
+ scalarbase: scalarbase,
19930
+ };
19931
+
19932
+ /* High-level API */
19933
+
19934
+ function checkLengths(k, n) {
19935
+ if (k.length !== crypto_secretbox_KEYBYTES) throw new Error('bad key size');
19936
+ if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error('bad nonce size');
19937
+ }
19938
+
19939
+ function checkBoxLengths(pk, sk) {
19940
+ if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error('bad public key size');
19941
+ if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error('bad secret key size');
19942
+ }
19943
+
19944
+ function checkArrayTypes() {
19945
+ for (var i = 0; i < arguments.length; i++) {
19946
+ if (!(arguments[i] instanceof Uint8Array))
19947
+ throw new TypeError('unexpected type, use Uint8Array');
19948
+ }
19949
+ }
19950
+
19951
+ function cleanup(arr) {
19952
+ for (var i = 0; i < arr.length; i++) arr[i] = 0;
19953
+ }
19954
+
19955
+ nacl.randomBytes = function(n) {
19956
+ var b = new Uint8Array(n);
19957
+ randombytes(b, n);
19958
+ return b;
19959
+ };
19960
+
19961
+ nacl.secretbox = function(msg, nonce, key) {
19962
+ checkArrayTypes(msg, nonce, key);
19963
+ checkLengths(key, nonce);
19964
+ var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
19965
+ var c = new Uint8Array(m.length);
19966
+ for (var i = 0; i < msg.length; i++) m[i+crypto_secretbox_ZEROBYTES] = msg[i];
19967
+ crypto_secretbox(c, m, m.length, nonce, key);
19968
+ return c.subarray(crypto_secretbox_BOXZEROBYTES);
19969
+ };
19970
+
19971
+ nacl.secretbox.open = function(box, nonce, key) {
19972
+ checkArrayTypes(box, nonce, key);
19973
+ checkLengths(key, nonce);
19974
+ var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
19975
+ var m = new Uint8Array(c.length);
19976
+ for (var i = 0; i < box.length; i++) c[i+crypto_secretbox_BOXZEROBYTES] = box[i];
19977
+ if (c.length < 32) return null;
19978
+ if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
19979
+ return m.subarray(crypto_secretbox_ZEROBYTES);
19980
+ };
19981
+
19982
+ nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
19983
+ nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
19984
+ nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
19985
+
19986
+ nacl.scalarMult = function(n, p) {
19987
+ checkArrayTypes(n, p);
19988
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
19989
+ if (p.length !== crypto_scalarmult_BYTES) throw new Error('bad p size');
19990
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
19991
+ crypto_scalarmult(q, n, p);
19992
+ return q;
19993
+ };
19994
+
19995
+ nacl.scalarMult.base = function(n) {
19996
+ checkArrayTypes(n);
19997
+ if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error('bad n size');
19998
+ var q = new Uint8Array(crypto_scalarmult_BYTES);
19999
+ crypto_scalarmult_base(q, n);
20000
+ return q;
20001
+ };
20002
+
20003
+ nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
20004
+ nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
20005
+
20006
+ nacl.box = function(msg, nonce, publicKey, secretKey) {
20007
+ var k = nacl.box.before(publicKey, secretKey);
20008
+ return nacl.secretbox(msg, nonce, k);
20009
+ };
20010
+
20011
+ nacl.box.before = function(publicKey, secretKey) {
20012
+ checkArrayTypes(publicKey, secretKey);
20013
+ checkBoxLengths(publicKey, secretKey);
20014
+ var k = new Uint8Array(crypto_box_BEFORENMBYTES);
20015
+ crypto_box_beforenm(k, publicKey, secretKey);
20016
+ return k;
20017
+ };
20018
+
20019
+ nacl.box.after = nacl.secretbox;
20020
+
20021
+ nacl.box.open = function(msg, nonce, publicKey, secretKey) {
20022
+ var k = nacl.box.before(publicKey, secretKey);
20023
+ return nacl.secretbox.open(msg, nonce, k);
20024
+ };
20025
+
20026
+ nacl.box.open.after = nacl.secretbox.open;
20027
+
20028
+ nacl.box.keyPair = function() {
20029
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
20030
+ var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
20031
+ crypto_box_keypair(pk, sk);
20032
+ return {publicKey: pk, secretKey: sk};
20033
+ };
20034
+
20035
+ nacl.box.keyPair.fromSecretKey = function(secretKey) {
20036
+ checkArrayTypes(secretKey);
20037
+ if (secretKey.length !== crypto_box_SECRETKEYBYTES)
20038
+ throw new Error('bad secret key size');
20039
+ var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
20040
+ crypto_scalarmult_base(pk, secretKey);
20041
+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
20042
+ };
20043
+
20044
+ nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
20045
+ nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
20046
+ nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
20047
+ nacl.box.nonceLength = crypto_box_NONCEBYTES;
20048
+ nacl.box.overheadLength = nacl.secretbox.overheadLength;
20049
+
20050
+ nacl.sign = function(msg, secretKey) {
20051
+ checkArrayTypes(msg, secretKey);
20052
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
20053
+ throw new Error('bad secret key size');
20054
+ var signedMsg = new Uint8Array(crypto_sign_BYTES+msg.length);
20055
+ crypto_sign(signedMsg, msg, msg.length, secretKey);
20056
+ return signedMsg;
20057
+ };
20058
+
20059
+ nacl.sign.open = function(signedMsg, publicKey) {
20060
+ checkArrayTypes(signedMsg, publicKey);
20061
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
20062
+ throw new Error('bad public key size');
20063
+ var tmp = new Uint8Array(signedMsg.length);
20064
+ var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
20065
+ if (mlen < 0) return null;
20066
+ var m = new Uint8Array(mlen);
20067
+ for (var i = 0; i < m.length; i++) m[i] = tmp[i];
20068
+ return m;
20069
+ };
20070
+
20071
+ nacl.sign.detached = function(msg, secretKey) {
20072
+ var signedMsg = nacl.sign(msg, secretKey);
20073
+ var sig = new Uint8Array(crypto_sign_BYTES);
20074
+ for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
20075
+ return sig;
20076
+ };
20077
+
20078
+ nacl.sign.detached.verify = function(msg, sig, publicKey) {
20079
+ checkArrayTypes(msg, sig, publicKey);
20080
+ if (sig.length !== crypto_sign_BYTES)
20081
+ throw new Error('bad signature size');
20082
+ if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
20083
+ throw new Error('bad public key size');
20084
+ var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
20085
+ var m = new Uint8Array(crypto_sign_BYTES + msg.length);
20086
+ var i;
20087
+ for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
20088
+ for (i = 0; i < msg.length; i++) sm[i+crypto_sign_BYTES] = msg[i];
20089
+ return (crypto_sign_open(m, sm, sm.length, publicKey) >= 0);
20090
+ };
20091
+
20092
+ nacl.sign.keyPair = function() {
20093
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
20094
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
20095
+ crypto_sign_keypair(pk, sk);
20096
+ return {publicKey: pk, secretKey: sk};
20097
+ };
20098
+
20099
+ nacl.sign.keyPair.fromSecretKey = function(secretKey) {
20100
+ checkArrayTypes(secretKey);
20101
+ if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
20102
+ throw new Error('bad secret key size');
20103
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
20104
+ for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32+i];
20105
+ return {publicKey: pk, secretKey: new Uint8Array(secretKey)};
20106
+ };
20107
+
20108
+ nacl.sign.keyPair.fromSeed = function(seed) {
20109
+ checkArrayTypes(seed);
20110
+ if (seed.length !== crypto_sign_SEEDBYTES)
20111
+ throw new Error('bad seed size');
20112
+ var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
20113
+ var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
20114
+ for (var i = 0; i < 32; i++) sk[i] = seed[i];
20115
+ crypto_sign_keypair(pk, sk, true);
20116
+ return {publicKey: pk, secretKey: sk};
20117
+ };
20118
+
20119
+ nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
20120
+ nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
20121
+ nacl.sign.seedLength = crypto_sign_SEEDBYTES;
20122
+ nacl.sign.signatureLength = crypto_sign_BYTES;
20123
+
20124
+ nacl.hash = function(msg) {
20125
+ checkArrayTypes(msg);
20126
+ var h = new Uint8Array(crypto_hash_BYTES);
20127
+ crypto_hash(h, msg, msg.length);
20128
+ return h;
20129
+ };
20130
+
20131
+ nacl.hash.hashLength = crypto_hash_BYTES;
20132
+
20133
+ nacl.verify = function(x, y) {
20134
+ checkArrayTypes(x, y);
20135
+ // Zero length arguments are considered not equal.
20136
+ if (x.length === 0 || y.length === 0) return false;
20137
+ if (x.length !== y.length) return false;
20138
+ return (vn(x, 0, y, 0, x.length) === 0) ? true : false;
20139
+ };
20140
+
20141
+ nacl.setPRNG = function(fn) {
20142
+ randombytes = fn;
20143
+ };
20144
+
20145
+ (function() {
20146
+ // Initialize PRNG if environment provides CSPRNG.
20147
+ // If not, methods calling randombytes will throw.
20148
+ var crypto = typeof self !== 'undefined' ? (self.crypto || self.msCrypto) : null;
20149
+ if (crypto && crypto.getRandomValues) {
20150
+ // Browsers.
20151
+ var QUOTA = 65536;
20152
+ nacl.setPRNG(function(x, n) {
20153
+ var i, v = new Uint8Array(n);
20154
+ for (i = 0; i < n; i += QUOTA) {
20155
+ crypto.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
20156
+ }
20157
+ for (i = 0; i < n; i++) x[i] = v[i];
20158
+ cleanup(v);
20159
+ });
20160
+ } else if (typeof commonjsRequire !== 'undefined') {
20161
+ // Node.js.
20162
+ crypto = require$$0;
20163
+ if (crypto && crypto.randomBytes) {
20164
+ nacl.setPRNG(function(x, n) {
20165
+ var i, v = crypto.randomBytes(n);
20166
+ for (i = 0; i < n; i++) x[i] = v[i];
20167
+ cleanup(v);
20168
+ });
20169
+ }
20170
+ }
20171
+ })();
20172
+
20173
+ })(module.exports ? module.exports : (self.nacl = self.nacl || {}));
20174
+ } (naclFast));
20175
+ return naclFast.exports;
20176
+ }
20177
+
20178
+ var naclFastExports = requireNaclFast();
20179
+ var nacl = /*@__PURE__*/getDefaultExportFromCjs$1(naclFastExports);
20180
+
17720
20181
  // guest-keystore.ts — durable per-device keypair for anonymous ("guest") auth.
17721
20182
  //
17722
20183
  // A guest is an ed25519 keypair generated on the device. Its public key is the
@@ -17787,7 +20248,7 @@ async function tryWebCrypto() {
17787
20248
  await idbPut(db, IDB_KEY, pair); // CryptoKey is structured-cloneable; bytes never exposed
17788
20249
  }
17789
20250
  const raw = new Uint8Array(await s.exportKey('raw', pair.publicKey)); // public is exportable
17790
- const address = base58.encode(raw);
20251
+ const address = bs582.encode(raw);
17791
20252
  return {
17792
20253
  address,
17793
20254
  nonExtractable: true,
@@ -17808,12 +20269,12 @@ function fallbackKey() {
17808
20269
  let secret;
17809
20270
  const saved = store.getItem(FALLBACK_STORE_KEY);
17810
20271
  if (saved) {
17811
- secret = base58.decode(saved);
20272
+ secret = bs582.decode(saved);
17812
20273
  }
17813
20274
  else {
17814
20275
  const kp = web3_js.Keypair.generate();
17815
20276
  secret = kp.secretKey; // 64 bytes
17816
- store.setItem(FALLBACK_STORE_KEY, base58.encode(secret));
20277
+ store.setItem(FALLBACK_STORE_KEY, bs582.encode(secret));
17817
20278
  }
17818
20279
  const kp = web3_js.Keypair.fromSecretKey(secret);
17819
20280
  const address = kp.publicKey.toBase58();
@@ -18548,7 +21009,7 @@ let currentAuthProvider = null;
18548
21009
  let currentAuthMethod = null;
18549
21010
  let initConfig = null;
18550
21011
  // --- localStorage helpers: track which auth method the user last logged in with ---
18551
- const STORED_AUTH_METHOD_KEY$1 = 'tarobase_last_auth_method';
21012
+ const STORED_AUTH_METHOD_KEY$1 = 'bounded_last_auth_method';
18552
21013
  function getStoredAuthMethod() {
18553
21014
  try {
18554
21015
  return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY$1);
@@ -19301,7 +21762,7 @@ async function loadDependencies() {
19301
21762
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
19302
21763
  import('react'),
19303
21764
  import('react-dom/client'),
19304
- Promise.resolve().then(function () { return require('./index-sKqrgk0t.js'); })
21765
+ Promise.resolve().then(function () { return require('./index-CYVVTWs4.js'); })
19305
21766
  ]);
19306
21767
  // Extract default export from ESM module namespace
19307
21768
  // Dynamic import() returns { default: Module, ...exports }, not the module directly
@@ -19491,7 +21952,7 @@ class PhantomWalletProvider {
19491
21952
  };
19492
21953
  }
19493
21954
  }, [phantom, phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, connect, disconnect, isDisconnecting, modal, modal.isOpened, solana, solana === null || solana === void 0 ? void 0 : solana.connected, solanaHook.isAvailable, connectError]);
19494
- // Auto-login: If connected but no Tarobase session, try to create one.
21955
+ // Auto-login: If connected but no Bounded session, try to create one.
19495
21956
  // This handles social login callbacks where user returns from OAuth already connected.
19496
21957
  React.useEffect(() => {
19497
21958
  const autoCreateSession = async () => {
@@ -19505,7 +21966,7 @@ class PhantomWalletProvider {
19505
21966
  // and clears it on logout, so this guard is correct in both
19506
21967
  // steady-state and post-logout cases.
19507
21968
  try {
19508
- if (getPlatform().storage.getItem('tarobase_last_auth_method') === 'mobile-wallet-adapter') {
21969
+ if (getPlatform().storage.getItem('bounded_last_auth_method') === 'mobile-wallet-adapter') {
19509
21970
  return;
19510
21971
  }
19511
21972
  }
@@ -19543,7 +22004,7 @@ class PhantomWalletProvider {
19543
22004
  // in flight. If MWA owns the auth method now, abort before we
19544
22005
  // overwrite its session (or its in-flight session).
19545
22006
  try {
19546
- if (getPlatform().storage.getItem('tarobase_last_auth_method') === 'mobile-wallet-adapter') {
22007
+ if (getPlatform().storage.getItem('bounded_last_auth_method') === 'mobile-wallet-adapter') {
19547
22008
  return;
19548
22009
  }
19549
22010
  }
@@ -19551,7 +22012,7 @@ class PhantomWalletProvider {
19551
22012
  await WebSessionManager.storeSession(publicKey, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
19552
22013
  // Mark auth method so clearIncompatibleSession() doesn't wipe this session
19553
22014
  try {
19554
- getPlatform().storage.setItem('tarobase_last_auth_method', 'phantom');
22015
+ getPlatform().storage.setItem('bounded_last_auth_method', 'phantom');
19555
22016
  }
19556
22017
  catch (_d) { }
19557
22018
  setCurrentUser({ provider: that, address: publicKey });
@@ -19649,7 +22110,7 @@ class PhantomWalletProvider {
19649
22110
  await WebSessionManager.storeSession(publicKey, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
19650
22111
  // Mark auth method so clearIncompatibleSession() doesn't wipe this session
19651
22112
  try {
19652
- getPlatform().storage.setItem('tarobase_last_auth_method', 'phantom');
22113
+ getPlatform().storage.setItem('bounded_last_auth_method', 'phantom');
19653
22114
  }
19654
22115
  catch (_b) { }
19655
22116
  const user = { provider: that, address: publicKey };
@@ -20264,8 +22725,8 @@ class PhantomWalletProvider {
20264
22725
  try {
20265
22726
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
20266
22727
  let app_id = solTransactionData.appId;
20267
- if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
20268
- app_id = window.CUSTOM_TAROBASE_APP_ID_HEADER;
22728
+ if (typeof window !== 'undefined' && window.CUSTOM_BOUNDED_APP_ID_HEADER) {
22729
+ app_id = window.CUSTOM_BOUNDED_APP_ID_HEADER;
20269
22730
  }
20270
22731
  if (!app_id) {
20271
22732
  throw new Error("App ID is required");
@@ -20682,7 +23143,7 @@ var phantomWalletProvider = /*#__PURE__*/Object.freeze({
20682
23143
  * doesn't force the user back into Phantom's approval flow when the
20683
23144
  * underlying wallet authorization is still valid.
20684
23145
  */
20685
- const MWA_AUTH_TOKEN_STORAGE_KEY = 'tarobase_mwa_auth_token';
23146
+ const MWA_AUTH_TOKEN_STORAGE_KEY = 'bounded_mwa_auth_token';
20686
23147
  /**
20687
23148
  * Detects whether the current environment is a mobile browser capable of
20688
23149
  * Mobile Wallet Adapter (MWA) communication.
@@ -20696,7 +23157,7 @@ function isMobileWalletAvailable() {
20696
23157
  return detectAndroid();
20697
23158
  }
20698
23159
  const ED25519_SIGNATURE_LENGTH = 64;
20699
- const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
23160
+ const STORED_AUTH_METHOD_KEY = 'bounded_last_auth_method';
20700
23161
  const MWA_AUTH_METHOD = 'mobile-wallet-adapter';
20701
23162
  function findMwaError(e, maxDepth = 5) {
20702
23163
  var _a;
@@ -20799,7 +23260,7 @@ async function withMwaAssociationRetry(fn) {
20799
23260
  * no `blur` event fires, the protocol's `getDetectionPromise` (3000ms
20800
23261
  * timeout, line 433) rejects, and we get `ERROR_WALLET_NOT_FOUND`.
20801
23262
  *
20802
- * Fix: show a Tarobase-controlled modal between the two transacts. When the
23263
+ * Fix: show a Bounded-controlled modal between the two transacts. When the
20803
23264
  * user taps the modal's "Sign in" button, that tap IS a fresh user
20804
23265
  * activation. We invoke the sign function directly inside the click handler
20805
23266
  * — no `await` between the tap and the call — so the activation propagates
@@ -20837,7 +23298,7 @@ async function awaitSignInGestureAndSign(theme, signFn, noResultError = 'MWA ret
20837
23298
  const closeColor = isDark ? '#71717a' : '#a1a1aa';
20838
23299
  const fontStack = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
20839
23300
  const overlay = document.createElement('div');
20840
- overlay.setAttribute('data-tarobase-mwa-gesture', 'true');
23301
+ overlay.setAttribute('data-bounded-mwa-gesture', 'true');
20841
23302
  overlay.style.cssText = [
20842
23303
  'position: fixed',
20843
23304
  'inset: 0',
@@ -21202,7 +23663,7 @@ async function registerMobileWalletAdapter(config) {
21202
23663
  if (typeof window === 'undefined')
21203
23664
  return;
21204
23665
  try {
21205
- const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-BJZ7fYwv.js'); });
23666
+ const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-BTJZmhY1.js'); });
21206
23667
  const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
21207
23668
  if (!registerMwa) {
21208
23669
  console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
@@ -21260,7 +23721,7 @@ async function registerMobileWalletAdapter(config) {
21260
23721
  * does.
21261
23722
  *
21262
23723
  * Notes on UX: login uses two wallet popups in succession — `standard:connect`
21263
- * (authorize) and `solana:signMessage` (sign the Tarobase nonce). The
23724
+ * (authorize) and `solana:signMessage` (sign the Bounded nonce). The
21264
23725
  * previous implementation combined both inside a single `transact` callback;
21265
23726
  * splitting them is the cost of going through wallet-standard, and is
21266
23727
  * acceptable given the alternative was broken on Seeker.
@@ -21303,9 +23764,9 @@ class SolanaMobileWalletProvider {
21303
23764
  // entirely via `config.appIdentity.uri`.
21304
23765
  const fallbackUri = hasDOM
21305
23766
  ? getPlatform().getLocationOrigin()
21306
- : 'tarobase://app';
23767
+ : 'bounded://app';
21307
23768
  this.appIdentity = config.appIdentity || {
21308
- name: 'TaroBase App',
23769
+ name: 'Bounded App',
21309
23770
  uri: fallbackUri,
21310
23771
  };
21311
23772
  this.cluster = config.cluster || 'mainnet-beta';
@@ -21341,7 +23802,7 @@ class SolanaMobileWalletProvider {
21341
23802
  async ensureWallet() {
21342
23803
  if (this.wallet)
21343
23804
  return this.wallet;
21344
- const mod = await Promise.resolve().then(function () { return require('./index.browser-BJZ7fYwv.js'); });
23805
+ const mod = await Promise.resolve().then(function () { return require('./index.browser-BTJZmhY1.js'); });
21345
23806
  const chain = mapChainToWalletStandard(this.cluster);
21346
23807
  this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
21347
23808
  appIdentity: this.appIdentity,
@@ -21361,7 +23822,7 @@ class SolanaMobileWalletProvider {
21361
23822
  return this.wallet;
21362
23823
  }
21363
23824
  /**
21364
- * Ensure the wallet has an active authorization. After a Tarobase session
23825
+ * Ensure the wallet has an active authorization. After a Bounded session
21365
23826
  * is restored from storage on cold-start, `wallet.accounts` is empty until
21366
23827
  * we silently reconnect from the AuthorizationCache. If the cache is also
21367
23828
  * empty, fall back to interactive `login()` (which surfaces the three-stage
@@ -21472,7 +23933,7 @@ class SolanaMobileWalletProvider {
21472
23933
  }
21473
23934
  const account = auth.accounts[0];
21474
23935
  // account.address is base64-encoded per MWA spec; convert to
21475
- // the base58 form Tarobase + the rest of the SDK use.
23936
+ // the base58 form Bounded + the rest of the SDK use.
21476
23937
  const base58Addr = new web3_js.PublicKey(bufferExports.Buffer.from(account.address, 'base64')).toBase58();
21477
23938
  // Reuse session if already valid for this address — skip the
21478
23939
  // signMessages roundtrip entirely.
@@ -21509,7 +23970,7 @@ class SolanaMobileWalletProvider {
21509
23970
  setCurrentUser(user);
21510
23971
  return user;
21511
23972
  }
21512
- // Create Tarobase session on the server.
23973
+ // Create Bounded session on the server.
21513
23974
  if (!result.signatureBase64 || !result.messageText) {
21514
23975
  throw new Error('MWA login completed without signature');
21515
23976
  }
@@ -21538,7 +23999,7 @@ class SolanaMobileWalletProvider {
21538
23999
  }
21539
24000
  const wallet = await this.ensureWallet();
21540
24001
  // Quick-check: wallet may already have authorization (e.g. from a
21541
- // previous in-page login) and a matching Tarobase session — skip
24002
+ // previous in-page login) and a matching Bounded session — skip
21542
24003
  // popups in that case.
21543
24004
  if (wallet.accounts.length > 0) {
21544
24005
  const accountPubkey = new web3_js.PublicKey(wallet.accounts[0].publicKey);
@@ -21569,14 +24030,14 @@ class SolanaMobileWalletProvider {
21569
24030
  const account = accounts[0];
21570
24031
  const accountPubkey = new web3_js.PublicKey(account.publicKey);
21571
24032
  const base58Addr = accountPubkey.toBase58();
21572
- // If we happen to already have a matching Tarobase session, reuse it.
24033
+ // If we happen to already have a matching Bounded session, reuse it.
21573
24034
  const existingSession = await getActiveSessionManager().getSession();
21574
24035
  if (existingSession && existingSession.address === base58Addr) {
21575
24036
  const user = { provider: this, address: base58Addr };
21576
24037
  setCurrentUser(user);
21577
24038
  return user;
21578
24039
  }
21579
- // Wallet popup #2: sign the Tarobase nonce message.
24040
+ // Wallet popup #2: sign the Bounded nonce message.
21580
24041
  //
21581
24042
  // We cannot call signMessageFeat.signMessage() directly here:
21582
24043
  // it would run as a JS continuation from the connect() resolve,
@@ -21589,7 +24050,7 @@ class SolanaMobileWalletProvider {
21589
24050
  // protocol's 3-second getDetectionPromise rejects with
21590
24051
  // ERROR_WALLET_NOT_FOUND.
21591
24052
  //
21592
- // Insert a Tarobase modal: the user's tap on "Sign in" provides a
24053
+ // Insert a Bounded modal: the user's tap on "Sign in" provides a
21593
24054
  // fresh activation, and signMessage is invoked synchronously
21594
24055
  // inside the click handler so the activation propagates.
21595
24056
  // C1: fetch the nonce HERE (after connect), not before — a pre-connect
@@ -21606,7 +24067,7 @@ class SolanaMobileWalletProvider {
21606
24067
  }
21607
24068
  const { signature: sigBytes } = signResult;
21608
24069
  const signatureBase64 = bufferExports.Buffer.from(sigBytes).toString('base64');
21609
- // Create Tarobase session on the server.
24070
+ // Create Bounded session on the server.
21610
24071
  const createSessionResult = await createSessionWithSignature(base58Addr, messageText, signatureBase64);
21611
24072
  await getActiveSessionManager().storeSession(base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
21612
24073
  // Auth-method marker is already 'mobile-wallet-adapter' from above.
@@ -21959,7 +24420,7 @@ class SolanaMobileWalletProvider {
21959
24420
  options: { commitment: 'confirmed' },
21960
24421
  }));
21961
24422
  const { signature: sigBytes } = sendResult;
21962
- const signature = base58.encode(sigBytes);
24423
+ const signature = bs582.encode(sigBytes);
21963
24424
  await confirmAndCheckTransaction(connection, signature);
21964
24425
  return signature;
21965
24426
  }
@@ -21995,8 +24456,8 @@ class SolanaMobileWalletProvider {
21995
24456
  try {
21996
24457
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
21997
24458
  let app_id = solTransactionData.appId;
21998
- if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
21999
- app_id = window.CUSTOM_TAROBASE_APP_ID_HEADER;
24459
+ if (typeof window !== 'undefined' && window.CUSTOM_BOUNDED_APP_ID_HEADER) {
24460
+ app_id = window.CUSTOM_BOUNDED_APP_ID_HEADER;
22000
24461
  }
22001
24462
  if (!app_id) {
22002
24463
  throw new Error('App ID is required');
@@ -22107,7 +24568,7 @@ class SolanaMobileWalletProvider {
22107
24568
  throw new Error('MWA returned no signature');
22108
24569
  }
22109
24570
  const { signature: sigBytes } = sendResult;
22110
- const signature = base58.encode(sigBytes);
24571
+ const signature = bs582.encode(sigBytes);
22111
24572
  const txInfo = await confirmAndCheckTransaction(connection, signature);
22112
24573
  return {
22113
24574
  transactionSignature: signature,
@@ -22603,8 +25064,8 @@ class PrivyWalletProvider {
22603
25064
  const connection = new web3_js.Connection(rpcUrl, "confirmed");
22604
25065
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
22605
25066
  let app_id = solTransactionData.appId;
22606
- if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
22607
- const customAppId = window.CUSTOM_TAROBASE_APP_ID_HEADER;
25067
+ if (typeof window !== 'undefined' && window.CUSTOM_BOUNDED_APP_ID_HEADER) {
25068
+ const customAppId = window.CUSTOM_BOUNDED_APP_ID_HEADER;
22608
25069
  if (customAppId) {
22609
25070
  app_id = customAppId;
22610
25071
  }
@@ -22944,7 +25405,7 @@ class PrivyWalletProvider {
22944
25405
  // Handle case where signature might be bytes instead of string
22945
25406
  const rawSig = result.signature;
22946
25407
  if (rawSig instanceof Uint8Array || Array.isArray(rawSig)) {
22947
- signature = base58.encode(rawSig instanceof Uint8Array ? rawSig : new Uint8Array(rawSig));
25408
+ signature = bs582.encode(rawSig instanceof Uint8Array ? rawSig : new Uint8Array(rawSig));
22948
25409
  }
22949
25410
  else {
22950
25411
  signature = rawSig;
@@ -23215,7 +25676,7 @@ class PrivyExpoProvider {
23215
25676
  if (!wallet) {
23216
25677
  throw new Error('No embedded Solana wallet found after login. Ensure embeddedWallets.solana.createOnLogin is configured.');
23217
25678
  }
23218
- // Mint a Tarobase session by having the Privy Solana wallet sign the
25679
+ // Mint a Bounded session by having the Privy Solana wallet sign the
23219
25680
  // standard SIWS challenge — identical to Phantom/MWA, so the backend mints
23220
25681
  // the session via the proven wallet-signature path (no Privy-specific
23221
25682
  // token verification needed).
@@ -23235,8 +25696,8 @@ class PrivyExpoProvider {
23235
25696
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
23236
25697
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
23237
25698
  let app_id = solTransactionData.appId;
23238
- if (typeof globalThis !== 'undefined' && globalThis.CUSTOM_TAROBASE_APP_ID_HEADER) {
23239
- app_id = globalThis.CUSTOM_TAROBASE_APP_ID_HEADER;
25699
+ if (typeof globalThis !== 'undefined' && globalThis.CUSTOM_BOUNDED_APP_ID_HEADER) {
25700
+ app_id = globalThis.CUSTOM_BOUNDED_APP_ID_HEADER;
23240
25701
  }
23241
25702
  if (!app_id) {
23242
25703
  throw new Error('App ID is required');
@@ -23306,7 +25767,7 @@ class PrivyExpoProvider {
23306
25767
  const wallet = await this.getWalletOrThrow();
23307
25768
  const messageBytes = getPlatform().textEncode(message);
23308
25769
  const result = await wallet.signMessage(messageBytes);
23309
- return base58.encode(result.signature);
25770
+ return bs582.encode(result.signature);
23310
25771
  }
23311
25772
  async signTransaction(transaction) {
23312
25773
  await this.ensureReady();
@@ -23390,7 +25851,7 @@ class PrivyExpoProvider {
23390
25851
  // Private helpers
23391
25852
  // -------------------------------------------------------------------
23392
25853
  /**
23393
- * Mint a Tarobase session from a Privy Solana wallet by signing the canonical
25854
+ * Mint a Bounded session from a Privy Solana wallet by signing the canonical
23394
25855
  * SIWS challenge (nonce -> genSolanaMessage -> wallet.signMessage). This reuses
23395
25856
  * createSessionWithSignature — the exact path Phantom, the mobile wallet
23396
25857
  * adapter, and the guest device-key use — so the bounded /session issuer mints
@@ -23490,7 +25951,7 @@ exports.ServerSessionManager = ServerSessionManager;
23490
25951
  exports.SolanaMobileWalletProvider = SolanaMobileWalletProvider;
23491
25952
  exports.WebSessionManager = WebSessionManager;
23492
25953
  exports.aggregate = aggregate;
23493
- exports.base58 = base58;
25954
+ exports.bs582 = bs582;
23494
25955
  exports.bufferExports = bufferExports;
23495
25956
  exports.buildSetDocumentsTransaction = buildSetDocumentsTransaction;
23496
25957
  exports.clearCache = clearCache;
@@ -23559,6 +26020,7 @@ exports.signInAnonymously = signInAnonymously;
23559
26020
  exports.signMessage = signMessage;
23560
26021
  exports.signSessionCreateMessage = signSessionCreateMessage;
23561
26022
  exports.signTransaction = signTransaction;
26023
+ exports.status = status;
23562
26024
  exports.subscribe = subscribe;
23563
26025
  exports.subscribeView = subscribeView;
23564
26026
  exports.useAuth = useAuth;
@@ -23569,4 +26031,4 @@ exports.wsGet = wsGet;
23569
26031
  exports.wsGetMany = wsGetMany;
23570
26032
  exports.wsQuery = wsQuery;
23571
26033
  exports.wsSet = wsSet;
23572
- //# sourceMappingURL=index-VGx-869x.js.map
26034
+ //# sourceMappingURL=index-2UpSvA7V.js.map