Upgrade TweetNaCl and split nacl.util

This commit is contained in:
yflory 2025-03-31 16:16:29 +02:00
parent 70084672b5
commit ad56510180
59 changed files with 278 additions and 250 deletions

View File

@ -53,8 +53,8 @@ define([
var keys = Nacl.sign.keyPair();
var inviteToken = window.location.hash.slice(1);
localStorage.CP_sso_auth = JSON.stringify({
s: Nacl.util.encodeBase64(keys.secretKey),
p: Nacl.util.encodeBase64(keys.publicKey),
s: Util.encodeBase64(keys.secretKey),
p: Util.encodeBase64(keys.publicKey),
token: inviteToken
});
ServerCommand(keys, {

View File

@ -12,6 +12,7 @@ const Fse = require("fs-extra");
const Path = require("path");
const Nacl = require("tweetnacl/nacl-fast");
const Hash = require('./common-hash');
const Util = require('./common-util');
module.exports.create = function (Env) {
var log = Env.Log;
@ -92,7 +93,7 @@ nThen(function (w) {
if (typeof(Env.bearerSecret) === 'string') { return; }
// if one does not exist, then create one and remember it
// 256 bits
var bearerSecret = Nacl.util.encodeBase64(Nacl.randomBytes(32));
var bearerSecret = Util.encodeBase64(Nacl.randomBytes(32));
Env.Log.info("GENERATING_BEARER_SECRET", {});
Decrees.write(Env, [
'SET_BEARER_SECRET',

View File

@ -44,14 +44,14 @@ Block.validateLoginBlock = function (Env, publicKey, signature, block, _cb) {
var u8_public_key;
try {
u8_public_key = Nacl.util.decodeBase64(publicKey);
u8_public_key = Util.decodeBase64(publicKey);
} catch (e) {
return void cb('E_INVALID_KEY');
}
var u8_signature;
try {
u8_signature = Nacl.util.decodeBase64(signature);
u8_signature = Util.decodeBase64(signature);
} catch (e) {
Env.Log.error('INVALID_BLOCK_SIGNATURE', e);
return void cb('E_INVALID_SIGNATURE');
@ -60,7 +60,7 @@ Block.validateLoginBlock = function (Env, publicKey, signature, block, _cb) {
// convert the block to a Uint8Array
var u8_block;
try {
u8_block = Nacl.util.decodeBase64(block);
u8_block = Util.decodeBase64(block);
} catch (e) {
return void cb('E_INVALID_BLOCK');
}
@ -85,9 +85,9 @@ Block.validateAncestorProof = function (Env, proof, _cb) {
try {
var parsed = JSON.parse(proof);
var pub = parsed[0];
var u8_pub = Nacl.util.decodeBase64(pub);
var u8_pub = Util.decodeBase64(pub);
var sig = parsed[1];
var u8_sig = Nacl.util.decodeBase64(sig);
var u8_sig = Util.decodeBase64(sig);
var valid = false;
nThen(function (w) {
valid = Nacl.sign.detached.verify(u8_pub, u8_sig, u8_pub);
@ -159,7 +159,7 @@ Block.writeLoginBlock = function (Env, msg, _cb) {
}).nThen(function () {
var buffer;
try {
buffer = Buffer.from(Nacl.util.decodeBase64(validatedBlock));
buffer = Buffer.from(Util.decodeBase64(validatedBlock));
} catch (err) {
return void cb('E_BLOCK_DESERIALIZATION');
}

View File

@ -225,8 +225,8 @@ Channel.deleteMailboxMessage = function (Env, data, cb) {
const proof = data.proof;
let nonce, proofBytes;
try {
nonce = Nacl.util.decodeBase64(proof.split('|')[0]);
proofBytes = Nacl.util.decodeBase64(proof.split('|')[1]);
nonce = Util.decodeBase64(proof.split('|')[0]);
proofBytes = Util.decodeBase64(proof.split('|')[1]);
} catch (e) {
return void cb('EINVAL');
}
@ -234,10 +234,10 @@ Channel.deleteMailboxMessage = function (Env, data, cb) {
// Check if you're allowed to delete this hash
try {
const mySecret = Env.curvePrivate;
const msgBytes = Nacl.util.decodeBase64(msg).subarray(64); // Remove signature
const msgBytes = Util.decodeBase64(msg).subarray(64); // Remove signature
const theirPublic = msgBytes.subarray(24,56); // 0-24 = nonce; 24-56=publickey (32 bytes)
const hashBytes = Nacl.box.open(proofBytes, nonce, theirPublic, mySecret);
return Nacl.util.encodeUTF8(hashBytes) === hash;
return Util.encodeUTF8(hashBytes) === hash;
} catch (e) {
return false;
}

View File

@ -254,7 +254,7 @@ module.exports.create = function (config) {
// initialized as undefined
bearerSecret: void 0,
curvePrivate: curve.secretKey,
curvePublic: Nacl.util.encodeBase64(curve.publicKey),
curvePublic: Util.encodeBase64(curve.publicKey),
selfDestructTo: {},
};

View File

@ -116,7 +116,7 @@ HK.closeNetfluxSession = function (Env, netfluxId) {
const isValidValidateKeyString = function (key) {
try {
return typeof(key) === 'string' &&
Nacl.util.decodeBase64(key).length === Nacl.sign.publicKeyLength;
Util.decodeBase64(key).length === Nacl.sign.publicKeyLength;
} catch (e) {
return false;
}

View File

@ -99,7 +99,7 @@ COMMANDS.SSO_UPDATE_BLOCK = SSO.SSO_UPDATE_BLOCK; // Password change
COMMANDS.SSO_VALIDATE = SSO.SSO_VALIDATE;
*/
var randomToken = () => Nacl.util.encodeBase64(Nacl.randomBytes(24)).replace(/\//g, '-');
var randomToken = () => Util.encodeBase64(Nacl.randomBytes(24)).replace(/\//g, '-');
// this function handles the first stage of the protocol
// (the server's validation of the client's request and the generation of its challenge)
@ -278,9 +278,9 @@ var handleResponse = function (Env, req, res) {
u8_publicKey;
try {
u8_toVerify = Nacl.util.decodeUTF8(text);
u8_sig = Nacl.util.decodeBase64(sig);
u8_publicKey = Nacl.util.decodeBase64(publicKey);
u8_toVerify = Util.decodeUTF8(text);
u8_sig = Util.decodeBase64(sig);
u8_publicKey = Util.decodeBase64(publicKey);
} catch (err3) {
Env.Log.error('CHALLENGE_RESPONSE_DECODING_ERROR', {
text: text,

View File

@ -29,7 +29,7 @@ var pathFromId = function (Env, id, ref) {
return Path.join(Env.paths.base, "sessions", id.slice(0, 2), id, ref);
};
Sessions.randomId = () => Nacl.util.encodeBase64(Nacl.randomBytes(24)).replace(/\//g, '-');
Sessions.randomId = () => Util.encodeBase64(Nacl.randomBytes(24)).replace(/\//g, '-');
Sessions.read = function (Env, id, ref, cb) {
var path = pathFromId(Env, id, ref);

View File

@ -7,6 +7,7 @@ var Fse = require("fs-extra");
var Path = require("path");
var nacl = require("tweetnacl/nacl-fast");
var nThen = require("nthen");
var Util = require('../common-util');
var Tasks = module.exports;
@ -49,7 +50,7 @@ var makeDirectoryId = function (d) {
var write = function (env, task, cb) {
var str = JSON.stringify(task) + '\n';
var id = nacl.util.encodeBase64(nacl.hash(nacl.util.decodeUTF8(str))).replace(/\//g, '-');
var id = Util.encodeBase64(nacl.hash(Util.decodeUTF8(str))).replace(/\//g, '-');
var dir = makeDirectoryId(task[0]);
var path = Path.join(env.root, dir);

View File

@ -772,14 +772,14 @@ COMMANDS.INLINE = function (data, cb) {
monitoringIncrement('inlineValidation');
var signedMsg;
try {
signedMsg = Nacl.util.decodeBase64(data.msg);
signedMsg = Util.decodeBase64(data.msg);
} catch (e) {
return void cb('E_BAD_MESSAGE');
}
var validateKey;
try {
validateKey = Nacl.util.decodeBase64(data.key);
validateKey = Util.decodeBase64(data.key);
} catch (e) {
return void cb("E_BADKEY");
}
@ -801,19 +801,19 @@ const checkDetachedSignature = function (signedMsg, signature, publicKey) {
var signatureBuffer;
try {
signedBuffer = Nacl.util.decodeUTF8(signedMsg);
signedBuffer = Util.decodeUTF8(signedMsg);
} catch (e) {
throw new Error("INVALID_SIGNED_BUFFER");
}
try {
pubBuffer = Nacl.util.decodeBase64(publicKey);
pubBuffer = Util.decodeBase64(publicKey);
} catch (e) {
throw new Error("INVALID_PUBLIC_KEY");
}
try {
signatureBuffer = Nacl.util.decodeBase64(signature);
signatureBuffer = Util.decodeBase64(signature);
} catch (e) {
throw new Error("INVALID_SIGNATURE");
}
@ -851,8 +851,7 @@ COMMANDS.HASH_CHANNEL_LIST = function (data, cb) {
});
uniques.sort();
var hash = Nacl.util.encodeBase64(Nacl.hash(Nacl
.util.decodeUTF8(JSON.stringify(uniques))));
var hash = Util.encodeBase64(Nacl.hash(Util.decodeUTF8(JSON.stringify(uniques))));
cb(void 0, hash);
};

View File

@ -7,7 +7,7 @@
// merge code more easily.
// Set REVERSE to true to copy from "www" to "src" once the changes have been merged.
const REVERSE = true;
const REVERSE = false;
const Fs = require('node:fs');
const map = {
'./src/worker/components/roster.js': './www/common/outer/roster.js',

31
package-lock.json generated
View File

@ -16,7 +16,7 @@
"bootstrap": "^4.0.0",
"bootstrap-tokenfield": "^0.12.0",
"chainpad": "^5.2.6",
"chainpad-crypto": "^0.2.5",
"chainpad-crypto": "^0.3.0",
"chainpad-listmap": "^1.1.1",
"chainpad-netflux": "^1.2.3",
"chainpad-server": "^5.2.4",
@ -58,7 +58,8 @@
"sortify": "^1.0.4",
"stream-to-pull-stream": "^1.7.2",
"thirty-two": "^1.0.2",
"tweetnacl": "file:./src/tweetnacl",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"ulimit": "0.0.2",
"ws": "^8.17.1",
"x2js": "^3.4.4"
@ -1902,11 +1903,13 @@
}
},
"node_modules/chainpad-crypto": {
"version": "0.2.8",
"resolved": "https://registry.npmjs.org/chainpad-crypto/-/chainpad-crypto-0.2.8.tgz",
"integrity": "sha512-B0/aW0TUcRQUF8Aaz7bBFfIPs/ybdr92Rl0ezVrSxEQuxaRHBNGJrUvVxdKreLuh+XYdbQeeRKDXbgvEcLDcEg==",
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/chainpad-crypto/-/chainpad-crypto-0.3.0.tgz",
"integrity": "sha512-L6gUiE8m/ZrUE3eVMju6qzG92Mis3M4T1xCuxVF3eqwa9+46fl9OFwt/TiSmi+oVHSIBmgDTcnOEF/JSxnxYxw==",
"license": "AGPL-3.0+",
"dependencies": {
"tweetnacl": "~0.12.2"
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1"
}
},
"node_modules/chainpad-listmap": {
@ -6149,8 +6152,16 @@
"dev": true
},
"node_modules/tweetnacl": {
"resolved": "src/tweetnacl",
"link": true
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==",
"license": "Unlicense"
},
"node_modules/tweetnacl-util": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz",
"integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==",
"license": "Unlicense"
},
"node_modules/type-check": {
"version": "0.4.0",
@ -6497,10 +6508,6 @@
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"src/tweetnacl": {
"version": "0.12.2",
"license": "Public domain"
}
}
}

View File

@ -19,7 +19,7 @@
"bootstrap": "^4.0.0",
"bootstrap-tokenfield": "^0.12.0",
"chainpad": "^5.2.6",
"chainpad-crypto": "^0.2.5",
"chainpad-crypto": "^0.3.0",
"chainpad-listmap": "^1.1.1",
"chainpad-netflux": "^1.2.3",
"chainpad-server": "^5.2.4",
@ -61,7 +61,8 @@
"sortify": "^1.0.4",
"stream-to-pull-stream": "^1.7.2",
"thirty-two": "^1.0.2",
"tweetnacl": "file:./src/tweetnacl",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"ulimit": "0.0.2",
"ws": "^8.17.1",
"x2js": "^3.4.4"

View File

@ -7,6 +7,7 @@ const nThen = require('nthen');
const Nacl = require('tweetnacl/nacl-fast');
const Path = require('path');
const Pins = require('../lib/pins');
const Util = require('../lib/common-util');
const Config = require('../lib/load-config');
var escapeKeyCharacters = function (key) {
@ -24,9 +25,9 @@ if (dataIdx === -1) {
const deleteData = JSON.parse(process.argv[dataIdx+1]);
if (!deleteData.toSign || !deleteData.proof) { return void console.error("Invalid arguments"); }
// Check sig
const ed = Nacl.util.decodeBase64(deleteData.toSign.edPublic);
const signed = Nacl.util.decodeUTF8(JSON.stringify(deleteData.toSign));
const proof = Nacl.util.decodeBase64(deleteData.proof);
const ed = Util.decodeBase64(deleteData.toSign.edPublic);
const signed = Util.decodeUTF8(JSON.stringify(deleteData.toSign));
const proof = Util.decodeBase64(deleteData.proof);
if (!Nacl.sign.detached.verify(signed, proof, ed)) { return void console.error("Invalid signature"); }
edPublic = escapeKeyCharacters(deleteData.toSign.edPublic);
}

View File

@ -34,6 +34,7 @@ Fse.rmSync(oldComponentsPath, { recursive: true, force: true });
"mathjax",
"open-sans-fontface",
"tweetnacl",
"tweetnacl-util",
"require-css",
"requirejs",
"requirejs-plugins",

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
const Nacl = require('tweetnacl/nacl-fast');
const Util = require('../lib/common-util');
const keyPair = Nacl.box.keyPair();
console.log("You've just generated a new key pair for your support mailbox.");
@ -19,9 +20,9 @@ console.log("NOTE: You can change the key pair at any time if you want to revoke
console.log();
console.log();
console.log("Your public key (add it to config.js):");
console.log(Nacl.util.encodeBase64(keyPair.publicKey));
console.log(Util.encodeBase64(keyPair.publicKey));
console.log();
console.log();
console.log("Your private key (store it in a safe place and send it to your instance's admins):");
console.log(Nacl.util.encodeBase64(keyPair.secretKey));
console.log(Util.encodeBase64(keyPair.secretKey));

View File

@ -5,13 +5,14 @@
let SodiumNative = require('sodium-native');
let Nacl = require('tweetnacl/nacl-fast');
let LibSodium = require('libsodium-wrappers');
let Util = require('../lib/common-util');
let msgStr = "This is a test";
let keys = Nacl.sign.keyPair();
let pub = keys.publicKey;
let msg = Nacl.util.decodeUTF8(msgStr);
let msg = Util.decodeUTF8(msgStr);
let signedMsg = Nacl.sign(msg, keys.secretKey);
let sig = signedMsg.subarray(0, 64);

View File

@ -7,6 +7,7 @@ var Nacl = require("tweetnacl/nacl-fast");
var nThen = require("nthen");
var CPNetflux = require("../../www/components/chainpad-netflux/chainpad-netflux");
var Hash = require("../../www/common/common-hash");
var Util = require("../../lib/common-util");
var Rpc = require("../../www/common/rpc");
var HK = require("../../lib/hk-util");
@ -69,7 +70,7 @@ nThen(function (w) {
//console.log(i);
if (i-- <= 0) { return void done(); }
var ciphertext = Nacl.util.encodeBase64(Nacl.randomBytes(256));
var ciphertext = Util.encodeBase64(Nacl.randomBytes(256));
client.anonRpc.send('WRITE_PRIVATE_MESSAGE', [
client.channel,

View File

@ -55,16 +55,16 @@ var state = {};
var makeCurveKeys = function () {
var pair = Nacl.box.keyPair();
return {
curvePrivate: Nacl.util.encodeBase64(pair.secretKey),
curvePublic: Nacl.util.encodeBase64(pair.publicKey),
curvePrivate: Util.encodeBase64(pair.secretKey),
curvePublic: Util.encodeBase64(pair.publicKey),
};
};
var makeEdKeys = function () {
var keys = Nacl.sign.keyPair.fromSeed(Nacl.randomBytes(Nacl.sign.seedLength));
return {
edPrivate: Nacl.util.encodeBase64(keys.secretKey),
edPublic: Nacl.util.encodeBase64(keys.publicKey),
edPrivate: Util.encodeBase64(keys.secretKey),
edPublic: Util.encodeBase64(keys.publicKey),
};
};
@ -198,7 +198,7 @@ nThen(function (w) {
alice.anonRpc.send('WRITE_PRIVATE_MESSAGE', [
alice.mailboxChannel,
msg
//Nacl.util.encodeBase64(Nacl.randomBytes(128))
//Util.encodeBase64(Nacl.randomBytes(128))
], w(function (err) {
if (err) { throw new Error(err); }
console.log('message %s written successfully', i);

View File

@ -43,16 +43,16 @@ process.on('unhandledRejection', function (err) {
var makeCurveKeys = function () {
var pair = Nacl.box.keyPair();
return {
curvePrivate: Nacl.util.encodeBase64(pair.secretKey),
curvePublic: Nacl.util.encodeBase64(pair.publicKey),
curvePrivate: Util.encodeBase64(pair.secretKey),
curvePublic: Util.encodeBase64(pair.publicKey),
};
};
var makeEdKeys = function () {
var keys = Nacl.sign.keyPair.fromSeed(Nacl.randomBytes(Nacl.sign.seedLength));
return {
edPrivate: Nacl.util.encodeBase64(keys.secretKey),
edPublic: Nacl.util.encodeBase64(keys.publicKey),
edPrivate: Util.encodeBase64(keys.secretKey),
edPublic: Util.encodeBase64(keys.publicKey),
};
};

View File

@ -9,13 +9,13 @@ var factory = function (Util, Crypto, Keys, Nacl) {
var uint8ArrayToHex = Util.uint8ArrayToHex;
var hexToBase64 = Util.hexToBase64;
var base64ToHex = Util.base64ToHex;
Hash.encodeBase64 = Nacl.util.encodeBase64;
Hash.decodeBase64 = Nacl.util.decodeBase64;
Hash.encodeBase64 = Util.encodeBase64;
Hash.decodeBase64 = Util.decodeBase64;
// This implementation must match that on the server
// it's used for a checksum
Hash.hashChannelList = function (list) {
return Nacl.util.encodeBase64(Nacl.hash(Nacl.util
return Util.encodeBase64(Nacl.hash(Util
.decodeUTF8(JSON.stringify(list))));
};
@ -34,15 +34,15 @@ var factory = function (Util, Crypto, Keys, Nacl) {
Hash.getSignPublicFromPrivate = function (edPrivateSafeStr) {
var edPrivateStr = Crypto.b64AddSlashes(edPrivateSafeStr);
var privateKey = Nacl.util.decodeBase64(edPrivateStr);
var privateKey = Util.decodeBase64(edPrivateStr);
var keyPair = Nacl.sign.keyPair.fromSecretKey(privateKey);
return Nacl.util.encodeBase64(keyPair.publicKey);
return Util.encodeBase64(keyPair.publicKey);
};
Hash.getCurvePublicFromPrivate = function (curvePrivateSafeStr) {
var curvePrivateStr = Crypto.b64AddSlashes(curvePrivateSafeStr);
var privateKey = Nacl.util.decodeBase64(curvePrivateStr);
var privateKey = Util.decodeBase64(curvePrivateStr);
var keyPair = Nacl.box.keyPair.fromSecretKey(privateKey);
return Nacl.util.encodeBase64(keyPair.publicKey);
return Util.encodeBase64(keyPair.publicKey);
};
var getEditHashFromKeys = Hash.getEditHashFromKeys = function (secret) {
@ -585,7 +585,7 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app)
secret.channel = base64ToHex(parsed.channel);
secret.keys = {
fileKeyStr: parsed.key,
cryptKey: Nacl.util.decodeBase64(parsed.key)
cryptKey: Util.decodeBase64(parsed.key)
};
} else if (parsed.type === "user") {
throw new Error("User hashes can't be opened (yet)");
@ -653,15 +653,15 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app)
var keys = secret && secret.keys;
var secondary = keys && keys.secondaryKey;
if (!secondary) { return; }
var curvePair = Nacl.box.keyPair.fromSecretKey(Nacl.util.decodeUTF8(secondary).slice(0,32));
var curvePair = Nacl.box.keyPair.fromSecretKey(Util.decodeUTF8(secondary).slice(0,32));
var ret = {};
ret.form_public = Nacl.util.encodeBase64(curvePair.publicKey);
var privateKey = ret.form_private = Nacl.util.encodeBase64(curvePair.secretKey);
ret.form_public = Util.encodeBase64(curvePair.publicKey);
var privateKey = ret.form_private = Util.encodeBase64(curvePair.secretKey);
var auditorHash = Hash.getViewHashFromKeys({
version: 1,
channel: secret.channel,
keys: { viewKeyStr: Nacl.util.encodeBase64(keys.cryptKey) }
keys: { viewKeyStr: Util.encodeBase64(keys.cryptKey) }
});
var _parsed = Hash.parseTypeHash('pad', auditorHash);
ret.form_auditorHash = _parsed.getHash({auditorKey: privateKey});
@ -720,12 +720,12 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app)
Hash.decodeDataOptions = function (opts) {
var b64 = decodeURIComponent(opts);
var str = Nacl.util.encodeUTF8(Nacl.util.decodeBase64(b64));
var str = Util.encodeUTF8(Util.decodeBase64(b64));
return Util.tryParse(str) || {};
};
Hash.encodeDataOptions = function (opts) {
var str = JSON.stringify(opts);
var b64 = Nacl.util.encodeBase64(Nacl.util.decodeUTF8(str));
var b64 = Util.encodeBase64(Util.decodeUTF8(str));
return encodeURIComponent(b64);
};
Hash.getNewPadURL = function (href, opts) {

View File

@ -3,12 +3,22 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
(function (window) {
const factory = (NaclUtil) => {
var Util = {};
// polyfill for atob in case you're using this from node...
window.atob = window.atob || function (str) { return Buffer.from(str, 'base64').toString('binary'); };
window.btoa = window.btoa || function (str) { return Buffer.from(str, 'binary').toString('base64'); };
Util.encodeBase64 = NaclUtil.encodeBase64;
Util.decodeBase64 = str => {
let i;
if (i = str.length % 4) { str += '='.repeat(4-i); }
return NaclUtil.decodeBase64(str);
};
Util.encodeUTF8 = NaclUtil.encodeUTF8;
Util.decodeUTF8 = NaclUtil.decodeUTF8;
Util.slice = function (A, start, end) {
return Array.prototype.slice.call(A, start, end);
};
@ -857,12 +867,14 @@
};
/* End of code copied from saferphore */
return Util;
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = Util;
module.exports = factory(require('tweetnacl-util'));
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([], function () {
window.CryptPad_Util = Util;
return Util;
define(['/components/tweetnacl-util/nacl-util.min.js'], function () {
return factory(globalThis?.nacl?.util);
});
} else {
window.CryptPad_Util = Util;

View File

@ -26,7 +26,7 @@ const factory = (nThen, Util, ApiConfig = {}, Nacl) => {
};
var clone = o => JSON.parse(JSON.stringify(o));
var randomToken = () => Nacl.util.encodeBase64(Nacl.randomBytes(24));
var randomToken = () => Util.encodeBase64(Nacl.randomBytes(24));
var postData = function (url, data, cb) {
var CB = Util.once(Util.mkAsync(cb));
fetch(url, {
@ -53,7 +53,7 @@ const factory = (nThen, Util, ApiConfig = {}, Nacl) => {
var serverCommand = function (keypair, my_data, cb) {
var obj = clone(my_data);
obj.publicKey = Nacl.util.encodeBase64(keypair.publicKey);
obj.publicKey = Util.encodeBase64(keypair.publicKey);
obj.nonce = randomToken();
var href = new URL('/api/auth/', API_ORIGIN);
var txid, date;
@ -82,9 +82,9 @@ const factory = (nThen, Util, ApiConfig = {}, Nacl) => {
var copy = clone(obj);
copy.txid = txid;
copy.date = date;
var toSign = Nacl.util.decodeUTF8(JSON.stringify(copy));
var toSign = Util.decodeUTF8(JSON.stringify(copy));
var sig = Nacl.sign.detached(toSign, keypair.secretKey);
var encoded = Nacl.util.encodeBase64(sig);
var encoded = Util.encodeBase64(sig);
var obj2 = {
sig: encoded,
txid: txid,

View File

@ -23,7 +23,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// [b64_public, b64_sig, b64_block [version, nonce, content]]
Block.seed = function () {
return Nacl.hash(Nacl.util.decodeUTF8('pewpewpew'));
return Nacl.hash(Util.decodeUTF8('pewpewpew'));
};
// should be deterministic from a seed...
@ -49,8 +49,8 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
try {
var sign = keys.sign;
return {
edPrivate: Nacl.util.encodeBase64(sign.secretKey),
edPublic: Nacl.util.encodeBase64(sign.publicKey),
edPrivate: Util.encodeBase64(sign.secretKey),
edPublic: Util.encodeBase64(sign.publicKey),
};
} catch (err) {
console.error(err);
@ -60,7 +60,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// (UTF8 content, keys object) => Uint8Array block
Block.encrypt = function (version, content, keys) {
var u8 = Nacl.util.decodeUTF8(content);
var u8 = Util.decodeUTF8(content);
var nonce = Nacl.randomBytes(Nacl.secretbox.nonceLength);
return Block.join([
[0],
@ -77,7 +77,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
var plaintext = Nacl.secretbox.open(box, nonce, keys.symmetric);
try {
return JSON.parse(Nacl.util.encodeUTF8(plaintext));
return JSON.parse(Util.encodeUTF8(plaintext));
} catch (e) {
console.error(e);
return;
@ -98,9 +98,9 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// serialize {publickey, sig, ciphertext}
return {
publicKey: Nacl.util.encodeBase64(keys.sign.publicKey),
signature: Nacl.util.encodeBase64(sig),
ciphertext: Nacl.util.encodeBase64(ciphertext),
publicKey: Util.encodeBase64(keys.sign.publicKey),
signature: Util.encodeBase64(sig),
ciphertext: Util.encodeBase64(ciphertext),
};
};
@ -111,14 +111,14 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// sign your old publicKey with your old privateKey
var u8_sig = Nacl.sign.detached(u8_pub, u8_secret);
// return an array with the sig and the pubkey
return JSON.stringify([u8_pub, u8_sig].map(Nacl.util.encodeBase64));
return JSON.stringify([u8_pub, u8_sig].map(Util.encodeBase64));
} catch (err) {
return void console.error(err);
}
};
var urlSafeB64 = function (u8) {
return Nacl.util.encodeBase64(u8).replace(/\//g, '-');
return Util.encodeBase64(u8).replace(/\//g, '-');
};
Block.getBlockUrl = function (keys) {
@ -138,7 +138,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
var decodeSafeB64 = function (b64) {
try {
return Nacl.util.decodeBase64(b64.replace(/\-/g, '/'));
return Util.decodeBase64(b64.replace(/\-/g, '/'));
} catch (e) {
console.error(e);
return;

View File

@ -14,8 +14,8 @@ var factory = function (Util, Nacl) {
// we will sign various message with our edPrivate keys
// this handles that in a generic way
var signMsg = function (data, signKey) {
var buffer = Nacl.util.decodeUTF8(JSON.stringify(data));
return Nacl.util.encodeBase64(Nacl.sign.detached(buffer, signKey));
var buffer = Util.decodeUTF8(JSON.stringify(data));
return Util.encodeBase64(Nacl.sign.detached(buffer, signKey));
};
// sendMsg takes a pre-formed message, does a little validation
@ -299,7 +299,7 @@ var factory = function (Util, Nacl) {
var signKey;
try {
signKey = Nacl.util.decodeBase64(edPrivateKey);
signKey = Util.decodeBase64(edPrivateKey);
if (signKey.length !== 64) {
throw new Error('private key did not match expected length of 64');
}
@ -308,7 +308,7 @@ var factory = function (Util, Nacl) {
}
try {
if (Nacl.util.decodeBase64(edPublicKey).length !== 32) {
if (Util.decodeBase64(edPublicKey).length !== 32) {
return void cb('expected public key to be 32 uint');
}
} catch (err) { return void cb(err); }

View File

@ -497,8 +497,8 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
if (store.rpc) { return void cb(store.rpc); }
var kp = Crypto.Nacl.sign.keyPair();
var keys = {
edPublic: Crypto.Nacl.util.encodeBase64(kp.publicKey),
edPrivate: Crypto.Nacl.util.encodeBase64(kp.secretKey)
edPublic: Util.encodeBase64(kp.publicKey),
edPrivate: Util.encodeBase64(kp.secretKey)
};
Pinpad.create(store.network, keys, function (e, call) {
if (e) { return void cb({error: e}); }
@ -945,16 +945,16 @@ const factory = (ApiConfig = {}, Sortify, UserObject, ProxyManager,
};
toSign.drive = store.driveChannel;
toSign.edPublic = edPublic;
var signKey = Crypto.Nacl.util.decodeBase64(store.proxy.edPrivate);
var proof = Crypto.Nacl.sign.detached(Crypto.Nacl.util.decodeUTF8(Sortify(toSign)), signKey);
var signKey = Util.decodeBase64(store.proxy.edPrivate);
var proof = Crypto.Nacl.sign.detached(Util.decodeUTF8(Sortify(toSign)), signKey);
var check = Crypto.Nacl.sign.detached.verify(Crypto.Nacl.util.decodeUTF8(Sortify(toSign)),
var check = Crypto.Nacl.sign.detached.verify(Util.decodeUTF8(Sortify(toSign)),
proof,
Crypto.Nacl.util.decodeBase64(edPublic));
Util.decodeBase64(edPublic));
if (!check) { console.error('signed message failed verification'); }
var proofTxt = Crypto.Nacl.util.encodeBase64(proof);
var proofTxt = Util.encodeBase64(proof);
cb({
proof: proofTxt,
toSign: JSON.parse(Sortify(toSign))

View File

@ -6,8 +6,8 @@
var factory = function (Util, Cred, Nacl, Crypto) {
var Invite = {};
var encode64 = Nacl.util.encodeBase64;
var decode64 = Nacl.util.decodeBase64;
var encode64 = Util.encodeBase64;
var decode64 = Util.decodeBase64;
// ed and curve keys can be random...
Invite.generateKeys = function () {
@ -56,7 +56,7 @@ var factory = function (Util, Cred, Nacl, Crypto) {
// Invite links should only be visible to members or above, so
// we store them in the roster encrypted with a string only available
// to users with edit rights
var decodeUTF8 = Nacl.util.decodeUTF8;
var decodeUTF8 = Util.decodeUTF8;
Invite.encryptHash = function (data, seedStr) {
var array = decodeUTF8(seedStr);
var bytes = Nacl.hash(array);

View File

@ -161,8 +161,8 @@ proxy.mailboxes = {
var Nacl = Crypto.Nacl;
var curveSeed = Nacl.randomBytes(32);
var curvePair = Nacl.box.keyPair.fromSecretKey(new Uint8Array(curveSeed));
var curvePrivate = Nacl.util.encodeBase64(curvePair.secretKey);
var curvePublic = Nacl.util.encodeBase64(curvePair.publicKey);
var curvePrivate = Util.encodeBase64(curvePair.secretKey);
var curvePublic = Util.encodeBase64(curvePair.publicKey);
sendTo({
store: {
anon_rpc: anonRpc,

View File

@ -302,9 +302,9 @@ const factory = (ApiConfig = {}, Util, Hash, Realtime, Pinpad, Crypt,
if (!curvePrivate) { return void cb('EFORBIDDEN'); }
let edPrivate, edPublic;
try {
let pair = Nacl.sign.keyPair.fromSeed(Nacl.util.decodeBase64(curvePrivate));
edPrivate = Nacl.util.encodeBase64(pair.secretKey);
edPublic = Nacl.util.encodeBase64(pair.publicKey);
let pair = Nacl.sign.keyPair.fromSeed(Util.decodeBase64(curvePrivate));
edPrivate = Util.encodeBase64(pair.secretKey);
edPublic = Util.encodeBase64(pair.publicKey);
} catch (e) {
return void cb(e);
}
@ -999,8 +999,8 @@ const factory = (ApiConfig = {}, Util, Hash, Realtime, Pinpad, Crypt,
let updateServerKey = (ctx, curvePublic, curvePrivate, cb) => {
let edPublic;
try {
let pair = Nacl.sign.keyPair.fromSeed(Nacl.util.decodeBase64(curvePrivate));
edPublic = Nacl.util.encodeBase64(pair.publicKey);
let pair = Nacl.sign.keyPair.fromSeed(Util.decodeBase64(curvePrivate));
edPublic = Util.encodeBase64(pair.publicKey);
} catch (e) {
return void cb(e);
}
@ -1022,8 +1022,8 @@ const factory = (ApiConfig = {}, Util, Hash, Realtime, Pinpad, Crypt,
let edPublic = proxy.edPublic;
const keyPair = Nacl.box.keyPair();
const newKeyPub = Nacl.util.encodeBase64(keyPair.publicKey);
const newKey = Nacl.util.encodeBase64(keyPair.secretKey);
const newKeyPub = Util.encodeBase64(keyPair.publicKey);
const newKey = Util.encodeBase64(keyPair.secretKey);
const oldKey = Util.find(proxy, ['mailboxes', 'supportteam', 'keys', 'curvePrivate']);
const oldKeyPub = Util.find(proxy, ['mailboxes', 'supportteam', 'keys', 'curvePublic']);

View File

@ -758,13 +758,13 @@ const factory = (Util, Hash, Constants, Realtime, ProxyManager,
channel: Hash.createChannelId(),
viewed: [],
keys: {
curvePrivate: Nacl.util.encodeBase64(curvePair.secretKey),
curvePublic: Nacl.util.encodeBase64(curvePair.publicKey)
curvePrivate: Util.encodeBase64(curvePair.secretKey),
curvePublic: Util.encodeBase64(curvePair.publicKey)
}
},
drive: {
edPrivate: Nacl.util.encodeBase64(keyPair.secretKey),
edPublic: Nacl.util.encodeBase64(keyPair.publicKey)
edPrivate: Util.encodeBase64(keyPair.secretKey),
edPublic: Util.encodeBase64(keyPair.publicKey)
},
chat: {
edit: chatHashes.editHash,
@ -1868,7 +1868,7 @@ const factory = (Util, Hash, Constants, Realtime, ProxyManager,
if (team.keys && team.keys.mailbox) { return team.keys.mailbox; }
var strSeed = Util.find(team, ['keys', 'roster', 'edit']);
if (!strSeed) { return; }
var hash = Nacl.hash(Nacl.util.decodeUTF8(strSeed));
var hash = Nacl.hash(Util.decodeUTF8(strSeed));
var seed = hash.slice(0,32);
var mailboxChannel = Util.uint8ArrayToHex(hash.slice(32,48));
var curvePair = Nacl.box.keyPair.fromSecretKey(seed);
@ -1876,8 +1876,8 @@ const factory = (Util, Hash, Constants, Realtime, ProxyManager,
channel: mailboxChannel,
viewed: [],
keys: {
curvePrivate: Nacl.util.encodeBase64(curvePair.secretKey),
curvePublic: Nacl.util.encodeBase64(curvePair.publicKey)
curvePrivate: Util.encodeBase64(curvePair.secretKey),
curvePublic: Util.encodeBase64(curvePair.publicKey)
}
};
};
@ -1919,9 +1919,9 @@ const factory = (Util, Hash, Constants, Realtime, ProxyManager,
var checkKeyPair = function (edPrivate, edPublic) {
if (!edPrivate || !edPublic) { return true; }
try {
var secretKey = Nacl.util.decodeBase64(edPrivate);
var secretKey = Util.decodeBase64(edPrivate);
var pair = Nacl.sign.keyPair.fromSecretKey(secretKey);
return Nacl.util.encodeBase64(pair.publicKey) === edPublic;
return Util.encodeBase64(pair.publicKey) === edPublic;
} catch (e) {
return false;
}

View File

@ -2,7 +2,8 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
import nacl from 'tweetnacl/nacl-fast';
//import nacl from 'tweetnacl/nacl-fast';
import * as Util from '../../common/common-util.js';
import { Module, ModuleObject } from '../types'
export interface TestModuleObject extends ModuleObject {
@ -25,7 +26,7 @@ const TestModule: Module<TestModuleObject> = {
cb();
},
toBase64: (str) => {
return nacl.util.encodeBase64(nacl.util.decodeUTF8(str));
return Util.encodeBase64(Util.decodeUTF8(str));
}
}
}

View File

@ -2767,9 +2767,9 @@ define([
var clone = Util.clone(json);
delete clone.proof;
var msg = Nacl.util.decodeUTF8(Sortify(clone));
var sig = Nacl.util.decodeBase64(json.proof);
var pub = Nacl.util.decodeBase64(json.blockId);
var msg = Util.decodeUTF8(Sortify(clone));
var sig = Util.decodeBase64(json.proof);
var pub = Util.decodeBase64(json.blockId);
return Nacl.sign.detached.verify(msg, sig, pub);
};

View File

@ -240,7 +240,7 @@ define([
parsed.hashData.type === "pad" &&
parsed.hashData.key === "oRE0oLCtEXusRDyin7GyLGcS" &&
secret.channel === "d8d51b4aea863f3f050f47f8ad261753" &&
window.nacl.util.encodeBase64(secret.keys.cryptKey) === "0Ts1M6VVEozErV2Nx/LTv6Im5SCD7io2LlhasyyBPQo=" &&
Util.encodeBase64(secret.keys.cryptKey) === "0Ts1M6VVEozErV2Nx/LTv6Im5SCD7io2LlhasyyBPQo=" &&
secret.keys.validateKey === "f5A1FM9Gp55tnOcM75RyHD1oxBG9ZPh9WDA7qe2Fvps=" &&
parsed.hashData.ownerKey === "uPmJDtDJ9okhdIyQ-8zphYlpaAonJDOC6MAcYY6iBwWBQr+XmrQ9uGY9WkApJTfEfAu5QcqaDCw1Ul+JXKcYkA" &&
parsed.hashData.embed &&
@ -278,7 +278,7 @@ define([
parsed.hashData.type === "pad" &&
parsed.hashData.key === "oRE0oLCtEXusRDyin7GyLGcS" &&
secret.channel === "d8d51b4aea863f3f050f47f8ad261753" &&
window.nacl.util.encodeBase64(secret.keys.cryptKey) === "0Ts1M6VVEozErV2Nx/LTv6Im5SCD7io2LlhasyyBPQo=" &&
Util.encodeBase64(secret.keys.cryptKey) === "0Ts1M6VVEozErV2Nx/LTv6Im5SCD7io2LlhasyyBPQo=" &&
secret.keys.validateKey === "f5A1FM9Gp55tnOcM75RyHD1oxBG9ZPh9WDA7qe2Fvps=" &&
!parsed.hashData.present);
}, "test support for version 2 hash failed to parse");
@ -290,7 +290,7 @@ define([
parsed.hashData.type === "pad" &&
parsed.hashData.key === "HGu0tK2od-2BBnwAz2ZNS-t4" &&
secret.channel === "3fb6dc93807d903aff390b5f798c92c9" &&
window.nacl.util.encodeBase64(secret.keys.cryptKey) === "EeCkGJra8eJgVu7v4Yl2Hc3yUjrgpKpxr0Lcc3bSWVs=" &&
Util.encodeBase64(secret.keys.cryptKey) === "EeCkGJra8eJgVu7v4Yl2Hc3yUjrgpKpxr0Lcc3bSWVs=" &&
secret.keys.validateKey === "WGkBczJf2V6vQZfAScz8V1KY6jKdoxUCckrD+E75gGE=" &&
parsed.hashData.embed &&
parsed.hashData.password);

View File

@ -9,13 +9,13 @@ var factory = function (Util, Crypto, Keys, Nacl) {
var uint8ArrayToHex = Util.uint8ArrayToHex;
var hexToBase64 = Util.hexToBase64;
var base64ToHex = Util.base64ToHex;
Hash.encodeBase64 = Nacl.util.encodeBase64;
Hash.decodeBase64 = Nacl.util.decodeBase64;
Hash.encodeBase64 = Util.encodeBase64;
Hash.decodeBase64 = Util.decodeBase64;
// This implementation must match that on the server
// it's used for a checksum
Hash.hashChannelList = function (list) {
return Nacl.util.encodeBase64(Nacl.hash(Nacl.util
return Util.encodeBase64(Nacl.hash(Util
.decodeUTF8(JSON.stringify(list))));
};
@ -34,15 +34,15 @@ var factory = function (Util, Crypto, Keys, Nacl) {
Hash.getSignPublicFromPrivate = function (edPrivateSafeStr) {
var edPrivateStr = Crypto.b64AddSlashes(edPrivateSafeStr);
var privateKey = Nacl.util.decodeBase64(edPrivateStr);
var privateKey = Util.decodeBase64(edPrivateStr);
var keyPair = Nacl.sign.keyPair.fromSecretKey(privateKey);
return Nacl.util.encodeBase64(keyPair.publicKey);
return Util.encodeBase64(keyPair.publicKey);
};
Hash.getCurvePublicFromPrivate = function (curvePrivateSafeStr) {
var curvePrivateStr = Crypto.b64AddSlashes(curvePrivateSafeStr);
var privateKey = Nacl.util.decodeBase64(curvePrivateStr);
var privateKey = Util.decodeBase64(curvePrivateStr);
var keyPair = Nacl.box.keyPair.fromSecretKey(privateKey);
return Nacl.util.encodeBase64(keyPair.publicKey);
return Util.encodeBase64(keyPair.publicKey);
};
var getEditHashFromKeys = Hash.getEditHashFromKeys = function (secret) {
@ -585,7 +585,7 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app)
secret.channel = base64ToHex(parsed.channel);
secret.keys = {
fileKeyStr: parsed.key,
cryptKey: Nacl.util.decodeBase64(parsed.key)
cryptKey: Util.decodeBase64(parsed.key)
};
} else if (parsed.type === "user") {
throw new Error("User hashes can't be opened (yet)");
@ -653,15 +653,15 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app)
var keys = secret && secret.keys;
var secondary = keys && keys.secondaryKey;
if (!secondary) { return; }
var curvePair = Nacl.box.keyPair.fromSecretKey(Nacl.util.decodeUTF8(secondary).slice(0,32));
var curvePair = Nacl.box.keyPair.fromSecretKey(Util.decodeUTF8(secondary).slice(0,32));
var ret = {};
ret.form_public = Nacl.util.encodeBase64(curvePair.publicKey);
var privateKey = ret.form_private = Nacl.util.encodeBase64(curvePair.secretKey);
ret.form_public = Util.encodeBase64(curvePair.publicKey);
var privateKey = ret.form_private = Util.encodeBase64(curvePair.secretKey);
var auditorHash = Hash.getViewHashFromKeys({
version: 1,
channel: secret.channel,
keys: { viewKeyStr: Nacl.util.encodeBase64(keys.cryptKey) }
keys: { viewKeyStr: Util.encodeBase64(keys.cryptKey) }
});
var _parsed = Hash.parseTypeHash('pad', auditorHash);
ret.form_auditorHash = _parsed.getHash({auditorKey: privateKey});
@ -720,12 +720,12 @@ Version 4: Data URL when not a realtime link yet (new pad or "static" app)
Hash.decodeDataOptions = function (opts) {
var b64 = decodeURIComponent(opts);
var str = Nacl.util.encodeUTF8(Nacl.util.decodeBase64(b64));
var str = Util.encodeUTF8(Util.decodeBase64(b64));
return Util.tryParse(str) || {};
};
Hash.encodeDataOptions = function (opts) {
var str = JSON.stringify(opts);
var b64 = Nacl.util.encodeBase64(Nacl.util.decodeUTF8(str));
var b64 = Util.encodeBase64(Util.decodeUTF8(str));
return encodeURIComponent(b64);
};
Hash.getNewPadURL = function (href, opts) {

View File

@ -43,8 +43,8 @@ define([
var curveSeed = dispense(32);
var curvePair = Nacl.box.keyPair.fromSecretKey(new Uint8Array(curveSeed));
opt.curvePrivate = Nacl.util.encodeBase64(curvePair.secretKey);
opt.curvePublic = Nacl.util.encodeBase64(curvePair.publicKey);
opt.curvePrivate = Util.encodeBase64(curvePair.secretKey);
opt.curvePublic = Util.encodeBase64(curvePair.publicKey);
// 32 more for a signing key
var edSeed = opt.edSeed = dispense(32);
@ -56,8 +56,8 @@ define([
// derive a private key from the ed seed
var signingKeypair = Nacl.sign.keyPair.fromSeed(new Uint8Array(edSeed));
opt.edPrivate = Nacl.util.encodeBase64(signingKeypair.secretKey);
opt.edPublic = Nacl.util.encodeBase64(signingKeypair.publicKey);
opt.edPrivate = Util.encodeBase64(signingKeypair.secretKey);
opt.edPublic = Util.encodeBase64(signingKeypair.publicKey);
var keys = opt.keys = Crypto.createEditCryptor(null, encryptionSeed);

View File

@ -8,9 +8,7 @@ define([
'/common/visible.js',
'/common/common-hash.js',
'/common/media-tag.js',
'/components/tweetnacl/nacl-fast.min.js',
], function ($, Util, Visible, Hash, MediaTag) {
var Nacl = window.nacl;
var Thumb = {
dimension: 100,
padDimension: 200,
@ -45,7 +43,7 @@ define([
Thumb.fromMetadata = function (metadata) {
if (!metadata || typeof(metadata) !== 'object' || !metadata.thumbnail) { return; }
try {
var u8 = Nacl.util.decodeBase64(metadata.thumbnail);
var u8 = Util.decodeBase64(metadata.thumbnail);
var blob = new Blob([u8], {
type: 'image/png'
});
@ -285,7 +283,7 @@ define([
var addThumbnail = function (err, thumb, $span, cb) {
var split = thumb.split(',');
var u8 = Nacl.util.decodeBase64(split[1] || split[0]);
var u8 = Util.decodeBase64(split[1] || split[0]);
var blob = new Blob([u8], {
type: 'image/png'
});

View File

@ -3,12 +3,22 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
(function (window) {
const factory = (NaclUtil) => {
var Util = {};
// polyfill for atob in case you're using this from node...
window.atob = window.atob || function (str) { return Buffer.from(str, 'base64').toString('binary'); };
window.btoa = window.btoa || function (str) { return Buffer.from(str, 'binary').toString('base64'); };
Util.encodeBase64 = NaclUtil.encodeBase64;
Util.decodeBase64 = str => {
let i;
if (i = str.length % 4) { str += '='.repeat(4-i); }
return NaclUtil.decodeBase64(str);
};
Util.encodeUTF8 = NaclUtil.encodeUTF8;
Util.decodeUTF8 = NaclUtil.decodeUTF8;
Util.slice = function (A, start, end) {
return Array.prototype.slice.call(A, start, end);
};
@ -857,12 +867,14 @@
};
/* End of code copied from saferphore */
return Util;
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = Util;
module.exports = factory(require('tweetnacl-util'));
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([], function () {
window.CryptPad_Util = Util;
return Util;
define(['/components/tweetnacl-util/nacl-util.min.js'], function () {
return factory(globalThis?.nacl?.util);
});
} else {
window.CryptPad_Util = Util;

View File

@ -230,7 +230,7 @@ define([
'/api/broadcast?'+ (+new Date()),
], waitFor(function (Broadcast) {
nacl = window.nacl;
theirs = nacl.util.decodeBase64(Broadcast.curvePublic);
theirs = Util.decodeBase64(Broadcast.curvePublic);
}));
}).nThen;
var toDelete = [];
@ -238,14 +238,14 @@ define([
if (answer.uid !== data.uid) { return; }
n = n(function (waitFor) {
var hash = answer.hash;
var h = nacl.util.decodeUTF8(hash);
var h = Util.decodeUTF8(hash);
// Make proof
var curve = answer.curvePrivate;
var mySecret = nacl.util.decodeBase64(curve);
var mySecret = Util.decodeBase64(curve);
var nonce = nacl.randomBytes(24);
var proofBytes = nacl.box(h, nonce, theirs, mySecret);
var proof = nacl.util.encodeBase64(nonce) +'|'+ nacl.util.encodeBase64(proofBytes);
var proof = Util.encodeBase64(nonce) +'|'+ Util.encodeBase64(proofBytes);
var lineData = {
channel: data.channel,
hash: hash,
@ -1606,7 +1606,7 @@ define([
oldChannel = oldSecret.channel;
var src = fileHost + Hash.getBlobPathFromHex(oldChannel);
var key = oldSecret.keys && oldSecret.keys.cryptKey;
var cryptKey = window.nacl.util.encodeBase64(key);
var cryptKey = window.Util.encodeBase64(key);
var mt = document.createElement('media-tag');
mt.setAttribute('src', src);
@ -2468,9 +2468,9 @@ define([
};
common.getAnonymousKeys = function (formSeed, channel) {
var array = window.nacl.util.decodeBase64(formSeed + channel);
var array = window.Util.decodeBase64(formSeed + channel);
var hash = window.nacl.hash(array);
var secretKey = window.nacl.util.encodeBase64(hash.subarray(32));
var secretKey = window.Util.encodeBase64(hash.subarray(32));
var publicKey = Hash.getCurvePublicFromPrivate(secretKey);
return {
curvePrivate: secretKey,

View File

@ -13,15 +13,12 @@ define([
'/customize/messages.js',
'/customize/application_config.js',
'/components/tweetnacl/nacl-fast.min.js',
'/components/croppie/croppie.min.js',
'/components/file-saver/FileSaver.min.js',
'css!/components/croppie/croppie.css',
], function ($, ApiConfig, Util, Hash, UI, h, MediaTag, Messages, AppConfig) {
var MT = {};
var Nacl = window.nacl;
// Configure MediaTags to use our local viewer
// This file is loaded by sframe-common so the following config is used in all the inner apps
if (MediaTag) {
@ -384,7 +381,7 @@ define([
var host = priv.fileHost || priv.origin || '';
src = host + Hash.getBlobPathFromHex(secret.channel);
var _key = secret.keys && secret.keys.cryptKey;
if (_key) { key = 'cryptpad:' + Nacl.util.encodeBase64(_key); }
if (_key) { key = 'cryptpad:' + Util.encodeBase64(_key); }
}
if (!src || !key) {
$spinner.hide();

View File

@ -9,7 +9,7 @@ var factory = function (Util, Nacl, Scrypt) {
Invite.deriveSeeds = function (safeSeed) {
// take the hash of the provided seed
var seed = safeSeed.replace(/\-/g, '/');
var u8_seed = Nacl.hash(Nacl.util.decodeBase64(seed));
var u8_seed = Nacl.hash(Util.decodeBase64(seed));
// hash the first half again for scrypt's input
var subseed1 = Nacl.hash(u8_seed.subarray(0, 32));
@ -17,8 +17,8 @@ var factory = function (Util, Nacl, Scrypt) {
var subseed2 = Nacl.hash(u8_seed.subarray(32));
return {
scrypt: Nacl.util.encodeBase64(subseed1),
preview: Nacl.util.encodeBase64(subseed2),
scrypt: Util.encodeBase64(subseed1),
preview: Util.encodeBase64(subseed2),
};
};

View File

@ -212,7 +212,7 @@ define([
}).nThen(function (waitFor) {
$content.empty();
var next = waitFor();
recoverySecret = Nacl.util.encodeBase64(Nacl.randomBytes(24));
recoverySecret = Util.encodeBase64(Nacl.randomBytes(24));
var button = h('button.btn.btn-primary', [
h('i.fa.fa-check'),
h('span', Messages.done)

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
(function (window) {
var factory = function () {
var factory = function (Util) {
var Promise = window.Promise;
var cache;
var cypherChunkLength = 131088;
@ -373,7 +373,7 @@ var factory = function () {
// Gets the key from the key string.
getKeyFromStr: function (str) {
return window.nacl.util.decodeBase64(str);
return Util.decodeBase64(str);
}
};
@ -448,7 +448,7 @@ var factory = function () {
var metaChunk = window.nacl.secretbox.open(metaBox, Decrypt.createNonce(), key);
try {
return JSON.parse(window.nacl.util.encodeUTF8(metaChunk));
return JSON.parse(Util.encodeUTF8(metaChunk));
}
catch (e) { return null; }
};
@ -487,7 +487,7 @@ var factory = function () {
Decrypt.increment(nonce);
try { res.metadata = JSON.parse(Nacl.util.encodeUTF8(metaChunk)); }
try { res.metadata = JSON.parse(Util.encodeUTF8(metaChunk)); }
catch (e) { return void done('E_METADATA_DECRYPTION'); }
if (!res.metadata) { return void done('NO_METADATA'); }
@ -822,8 +822,8 @@ var factory = function () {
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = factory();
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
define([], function () {
return factory();
define(['/common/common-util.js'], function (Util) {
return factory(Util);
});
} else {
// unsupported initialization

View File

@ -56,7 +56,6 @@ define([
X2T)
{
var saveAs = window.saveAs;
var Nacl = window.nacl;
var APP = window.APP = {
$: $,
urlArgs: Util.find(ApiConfig, ['requireConf', 'urlArgs'])
@ -2126,7 +2125,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
}
try {
debug("Decrypt with key " + data.key);
FileCrypto.decrypt(u8, Nacl.util.decodeBase64(data.key), function (err, res) {
FileCrypto.decrypt(u8, Util.decodeBase64(data.key), function (err, res) {
APP.loadingImage--;
if (err || !res.content) {
debug("Decrypting failed");

View File

@ -26,7 +26,7 @@ const factory = (nThen, Util, ApiConfig = {}, Nacl) => {
};
var clone = o => JSON.parse(JSON.stringify(o));
var randomToken = () => Nacl.util.encodeBase64(Nacl.randomBytes(24));
var randomToken = () => Util.encodeBase64(Nacl.randomBytes(24));
var postData = function (url, data, cb) {
var CB = Util.once(Util.mkAsync(cb));
fetch(url, {
@ -53,7 +53,7 @@ const factory = (nThen, Util, ApiConfig = {}, Nacl) => {
var serverCommand = function (keypair, my_data, cb) {
var obj = clone(my_data);
obj.publicKey = Nacl.util.encodeBase64(keypair.publicKey);
obj.publicKey = Util.encodeBase64(keypair.publicKey);
obj.nonce = randomToken();
var href = new URL('/api/auth/', API_ORIGIN);
var txid, date;
@ -82,9 +82,9 @@ const factory = (nThen, Util, ApiConfig = {}, Nacl) => {
var copy = clone(obj);
copy.txid = txid;
copy.date = date;
var toSign = Nacl.util.decodeUTF8(JSON.stringify(copy));
var toSign = Util.decodeUTF8(JSON.stringify(copy));
var sig = Nacl.sign.detached(toSign, keypair.secretKey);
var encoded = Nacl.util.encodeBase64(sig);
var encoded = Util.encodeBase64(sig);
var obj2 = {
sig: encoded,
txid: txid,

View File

@ -23,7 +23,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// [b64_public, b64_sig, b64_block [version, nonce, content]]
Block.seed = function () {
return Nacl.hash(Nacl.util.decodeUTF8('pewpewpew'));
return Nacl.hash(Util.decodeUTF8('pewpewpew'));
};
// should be deterministic from a seed...
@ -49,8 +49,8 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
try {
var sign = keys.sign;
return {
edPrivate: Nacl.util.encodeBase64(sign.secretKey),
edPublic: Nacl.util.encodeBase64(sign.publicKey),
edPrivate: Util.encodeBase64(sign.secretKey),
edPublic: Util.encodeBase64(sign.publicKey),
};
} catch (err) {
console.error(err);
@ -60,7 +60,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// (UTF8 content, keys object) => Uint8Array block
Block.encrypt = function (version, content, keys) {
var u8 = Nacl.util.decodeUTF8(content);
var u8 = Util.decodeUTF8(content);
var nonce = Nacl.randomBytes(Nacl.secretbox.nonceLength);
return Block.join([
[0],
@ -77,7 +77,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
var plaintext = Nacl.secretbox.open(box, nonce, keys.symmetric);
try {
return JSON.parse(Nacl.util.encodeUTF8(plaintext));
return JSON.parse(Util.encodeUTF8(plaintext));
} catch (e) {
console.error(e);
return;
@ -98,9 +98,9 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// serialize {publickey, sig, ciphertext}
return {
publicKey: Nacl.util.encodeBase64(keys.sign.publicKey),
signature: Nacl.util.encodeBase64(sig),
ciphertext: Nacl.util.encodeBase64(ciphertext),
publicKey: Util.encodeBase64(keys.sign.publicKey),
signature: Util.encodeBase64(sig),
ciphertext: Util.encodeBase64(ciphertext),
};
};
@ -111,14 +111,14 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
// sign your old publicKey with your old privateKey
var u8_sig = Nacl.sign.detached(u8_pub, u8_secret);
// return an array with the sig and the pubkey
return JSON.stringify([u8_pub, u8_sig].map(Nacl.util.encodeBase64));
return JSON.stringify([u8_pub, u8_sig].map(Util.encodeBase64));
} catch (err) {
return void console.error(err);
}
};
var urlSafeB64 = function (u8) {
return Nacl.util.encodeBase64(u8).replace(/\//g, '-');
return Util.encodeBase64(u8).replace(/\//g, '-');
};
Block.getBlockUrl = function (keys) {
@ -138,7 +138,7 @@ const factory = (Util, ApiConfig = {}, ServerCommand, Nacl) => {
var decodeSafeB64 = function (b64) {
try {
return Nacl.util.decodeBase64(b64.replace(/\-/g, '/'));
return Util.decodeBase64(b64.replace(/\-/g, '/'));
} catch (e) {
console.error(e);
return;

View File

@ -8,9 +8,7 @@ define([
'/common/common-util.js',
'/common/outer/cache-store.js',
'/components/nthen/index.js',
'/components/tweetnacl/nacl-fast.min.js',
], function (FileCrypto, Hash, Util, Cache, nThen) {
var Nacl = window.nacl;
var module = {};
module.uploadU8 =function (common, data, cb) {
@ -30,7 +28,7 @@ define([
var estimate = FileCrypto.computeEncryptedSize(u8.length, metadata);
var sendChunk = function (box, cb) {
var enc = Nacl.util.encodeBase64(box);
var enc = Util.encodeBase64(box);
common.uploadChunk(teamId, enc, function (e, msg) {
cb(e, msg);
});

View File

@ -14,8 +14,8 @@ var factory = function (Util, Nacl) {
// we will sign various message with our edPrivate keys
// this handles that in a generic way
var signMsg = function (data, signKey) {
var buffer = Nacl.util.decodeUTF8(JSON.stringify(data));
return Nacl.util.encodeBase64(Nacl.sign.detached(buffer, signKey));
var buffer = Util.decodeUTF8(JSON.stringify(data));
return Util.encodeBase64(Nacl.sign.detached(buffer, signKey));
};
// sendMsg takes a pre-formed message, does a little validation
@ -299,7 +299,7 @@ var factory = function (Util, Nacl) {
var signKey;
try {
signKey = Nacl.util.decodeBase64(edPrivateKey);
signKey = Util.decodeBase64(edPrivateKey);
if (signKey.length !== 64) {
throw new Error('private key did not match expected length of 64');
}
@ -308,7 +308,7 @@ var factory = function (Util, Nacl) {
}
try {
if (Nacl.util.decodeBase64(edPublicKey).length !== 32) {
if (Util.decodeBase64(edPublicKey).length !== 32) {
return void cb('expected public key to be 32 uint');
}
} catch (err) { return void cb(err); }

View File

@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
define([], function () {
define(['/common/common-util.js'], function (Util) {
var verbose = function (x) { console.log(x); };
verbose = function () {}; // comment out to enable verbose logging
@ -57,8 +57,8 @@ define([], function () {
if (msg.indexOf('[4') === 0) {
var id = '';
if (window.nacl) {
var hash = window.nacl.hash(window.nacl.util.decodeUTF8(msg));
id = window.nacl.util.encodeBase64(hash.subarray(0, 8)) + '|';
var hash = window.nacl.hash(Util.decodeUTF8(msg));
id = Util.encodeBase64(hash.subarray(0, 8)) + '|';
} else {
console.log("Checkpoint sent without an ID. Nacl is missing.");
}

View File

@ -1682,7 +1682,7 @@ define([
}
});
};
data.blob = Crypto.Nacl.util.decodeBase64(data.blob);
data.blob = Utils.Util.decodeBase64(data.blob);
Files.upload(data, data.noStore, Cryptpad, updateProgress, onComplete, onError, onPending);
cb();
});

View File

@ -4,7 +4,7 @@
(() => {
const factory = function () {
let USE_MIN = true;
let USE_MIN = false;
let path = '/common/worker.bundle.js?';
if (USE_MIN) { path = '/common/worker.bundle.min.js?'; }

File diff suppressed because one or more lines are too long

View File

@ -5,11 +5,10 @@
define([
'/diagram/util.js',
'/common/common-util.js'
], function (
DiagramUtil,
DiagramUtil, Util
) {
const Nacl = window.nacl;
const splitAt = function (str, char) {
const pos = str.indexOf(char);
if (pos <= 0) {
@ -23,7 +22,7 @@ define([
const [, metadata] = splitAt(prefix, ':');
const [mimeType, ] = splitAt(metadata, ';');
const u8 = Nacl.util.decodeBase64(data);
const u8 = Util.decodeBase64(data);
return new Blob([u8], { type: mimeType });
};

View File

@ -19,7 +19,6 @@ define([
Hash,
ApiConfig,
) {
const Nacl = window.nacl;
const x2js = new X2JS();
const parseCryptPadUrl = function(href) {
@ -102,7 +101,7 @@ define([
diagrams.forEach(function(diagram) {
if (diagram.childNodes.length === 1 && diagram.firstChild && diagram.firstChild.nodeType === TEXT_NODE) {
const innerText = diagram.firstChild.nodeValue;
const bin = Nacl.util.decodeBase64(innerText);
const bin = Util.decodeBase64(innerText);
const xmlUrlStr = pako.inflateRaw(bin, {to: 'string'});
const xmlStr = decodeURIComponent(xmlUrlStr);
const diagramDoc = parser.parseFromString(xmlStr, "application/xml");
@ -151,7 +150,7 @@ define([
const hexFileName = secret.channel;
const src = fileHost + Hash.getBlobPathFromHex(hexFileName);
const key = secret.keys && secret.keys.cryptKey;
const cryptKey = Nacl.util.encodeBase64(key);
const cryptKey = Util.encodeBase64(key);
return getCryptPadUrl(src, cryptKey, data.fileType);
};
@ -199,7 +198,7 @@ define([
return void reject(err);
}
try {
FileCrypto.decrypt(u8, Nacl.util.decodeBase64(key), (err, res) => {
FileCrypto.decrypt(u8, Util.decodeBase64(key), (err, res) => {
if (err || !res.content) {
console.error("Decrypting failed");
return void reject(err);

View File

@ -3,8 +3,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
define([
'/common/common-util.js',
'/components/tweetnacl/nacl-fast.min.js',
], function () {
], function (Util) {
var Nacl = window.nacl;
//var PARANOIA = true;
@ -12,7 +13,7 @@ define([
var cypherChunkLength = 131088;
var computeEncryptedSize = function (bytes, meta) {
var metasize = Nacl.util.decodeUTF8(JSON.stringify(meta)).length;
var metasize = Util.decodeUTF8(JSON.stringify(meta)).length;
var chunks = Math.ceil(bytes / plainChunkLength);
return metasize + 18 + (chunks * 16) + bytes;
};
@ -80,7 +81,7 @@ define([
increment(nonce);
try {
res.metadata = JSON.parse(Nacl.util.encodeUTF8(metaChunk));
res.metadata = JSON.parse(Util.encodeUTF8(metaChunk));
} catch (e) {
return window.setTimeout(function () {
done('E_METADATA_DECRYPTION');
@ -147,13 +148,13 @@ define([
var nonce = createNonce();
// encode metadata
var plaintext = Nacl.util.decodeUTF8(JSON.stringify(metadata));
var plaintext = Util.decodeUTF8(JSON.stringify(metadata));
// if metadata is too large, drop the thumbnail.
if (plaintext.length > 65535) {
var temp = JSON.parse(JSON.stringify(metadata));
delete temp.thumbnail;
plaintext = Nacl.util.decodeUTF8(JSON.stringify(temp));
plaintext = Util.decodeUTF8(JSON.stringify(temp));
}
var i = 0;

View File

@ -8,6 +8,7 @@ define([
'/components/nthen/index.js',
'/common/sframe-common.js',
'/common/common-hash.js',
'/common/common-util.js',
'/common/common-interface.js',
'/common/common-ui-elements.js',
'/customize/messages.js',
@ -26,13 +27,13 @@ define([
nThen,
SFCommon,
Hash,
Util,
UI,
UIElements,
Messages,
MediaTag)
{
var saveAs = window.saveAs;
var Nacl = window.nacl;
var APP = window.APP = {};
@ -81,7 +82,7 @@ define([
var hexFileName = secret.channel;
var src = fileHost + Hash.getBlobPathFromHex(hexFileName);
var key = secret.keys && secret.keys.cryptKey;
var cryptKey = Nacl.util.encodeBase64(key);
var cryptKey = Util.encodeBase64(key);
var $mt = $dlview.find('media-tag');
$mt.attr('src', src);

View File

@ -3,8 +3,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
define([
'/common/common-util.js',
'/components/tweetnacl/nacl-fast.min.js'
], function () {
], function (Util) {
var Handler = {};
@ -31,13 +32,13 @@ define([
return total;
};
var anonProof = function (channel, theirPub, anonKeys) {
var u8_plain = Nacl.util.decodeUTF8(channel);
var u8_plain = Util.decodeUTF8(channel);
var u8_nonce = Nacl.randomBytes(Nacl.box.nonceLength);
var u8_cipher = Nacl.box(
u8_plain,
u8_nonce,
Nacl.util.decodeBase64(theirPub),
Nacl.util.decodeBase64(anonKeys.curvePrivate)
Util.decodeBase64(theirPub),
Util.decodeBase64(anonKeys.curvePrivate)
);
var u8_bundle = u8_concat([
u8_nonce, // 24 uint8s
@ -45,7 +46,7 @@ define([
]);
return {
key: anonKeys.curvePublic,
proof: Nacl.util.encodeBase64(u8_bundle)
proof: Util.encodeBase64(u8_bundle)
};
};
var deleteLines = false; // "false" to support old forms
@ -111,9 +112,9 @@ define([
try {
var res = Utils.Crypto.Mailbox.openOwnSecretLetter(messages[0].msg, {
validateKey: data.validateKey,
ephemeral_private: Nacl.util.decodeBase64(answer.curvePrivate),
my_private: Nacl.util.decodeBase64(finalKeys.curvePrivate),
their_public: Nacl.util.decodeBase64(data.publicKey)
ephemeral_private: Util.decodeBase64(answer.curvePrivate),
my_private: Util.decodeBase64(finalKeys.curvePrivate),
their_public: Util.decodeBase64(data.publicKey)
});
var parsed = JSON.parse(res.content);
parsed._isAnon = answer.anonymous;
@ -141,16 +142,16 @@ define([
var pub = proofObj.key;
var proofTxt = proofObj.proof;
try {
var u8_bundle = Nacl.util.decodeBase64(proofTxt);
var u8_bundle = Util.decodeBase64(proofTxt);
var u8_nonce = u8_slice(u8_bundle, 0, Nacl.box.nonceLength);
var u8_cipher = u8_slice(u8_bundle, Nacl.box.nonceLength);
var u8_plain = Nacl.box.open(
u8_cipher,
u8_nonce,
Nacl.util.decodeBase64(pub),
Nacl.util.decodeBase64(curvePrivate)
Util.decodeBase64(pub),
Util.decodeBase64(curvePrivate)
);
return channel === Nacl.util.encodeUTF8(u8_plain);
return channel === Util.encodeUTF8(u8_plain);
} catch (e) {
console.error(e);
return false;
@ -327,7 +328,7 @@ define([
myKeys.signingKey = keys.secondarySignKey;
var ephemeral_keypair = Nacl.box.keyPair();
var ephemeral_private = Nacl.util.encodeBase64(ephemeral_keypair.secretKey);
var ephemeral_private = Util.encodeBase64(ephemeral_keypair.secretKey);
myKeys.ephemeral_keypair = ephemeral_keypair;
if (myAnonymousKeys) {

View File

@ -6,10 +6,10 @@ define([
'/api/config',
'/common/sframe-common-outer.js',
'/common/common-hash.js',
'/common/common-util.js',
'/components/tweetnacl/nacl-fast.min.js'
], function (Config, SCO, Hash) {
], function (Config, SCO, Hash, Util) {
let Nacl = window.nacl;
var getTxid = function () {
return Math.random().toString(16).replace('0.', '');
};
@ -100,10 +100,10 @@ define([
};
let sanitizeKey = key => {
try {
Nacl.util.decodeBase64(key);
Util.decodeBase64(key);
return key;
} catch (e) {
return Nacl.util.encodeBase64(Nacl.util.decodeUTF8(key)).replaceAll('=', '');
return Util.encodeBase64(Util.decodeUTF8(key)).replaceAll('=', '');
}
};
chan.on('GET_SESSION', function (data, cb) {

View File

@ -76,10 +76,10 @@ define([
var toSign = {
intent: 'Disable TOTP',
date: new Date().toISOString(),
blockId: Nacl.util.encodeBase64(pub),
blockId: Util.encodeBase64(pub),
};
var proof = Nacl.sign.detached(Nacl.util.decodeUTF8(Sortify(toSign)), sec);
toSign.proof = Nacl.util.encodeBase64(proof);
var proof = Nacl.sign.detached(Util.decodeUTF8(Sortify(toSign)), sec);
toSign.proof = Util.encodeBase64(proof);
proofStr = JSON.stringify(toSign, 0, 2);
$mfaProof.html(proofStr);
};

View File

@ -15,14 +15,10 @@ define([
'/common/outer/local-store.js',
'/common/outer/login-block.js',
'/customize/messages.js',
'/components/tweetnacl/nacl-fast.min.js',
], function (ApiConfig, $, h, Util, Cred, UI, Login, Constants,
ServerCommand, LocalStore, Block, Messages) {
if (window.top !== window) { return; }
let Nacl = window.nacl;
let ssoAuthCb = function (cb) {
var b64Keys = Util.tryParse(localStorage.CP_sso_auth);
if (!b64Keys) {
@ -30,8 +26,8 @@ define([
return;
}
var keys = {
secretKey: Nacl.util.decodeBase64(b64Keys.s),
publicKey: Nacl.util.decodeBase64(b64Keys.p)
secretKey: Util.decodeBase64(b64Keys.s),
publicKey: Util.decodeBase64(b64Keys.p)
};
var inviteToken = b64Keys.token;
ServerCommand(keys, {