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