cryptpad-server 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/build/core.js CHANGED
@@ -823,60 +823,69 @@ var hasRequiredCrypto;
823
823
  function requireCrypto() {
824
824
  if (hasRequiredCrypto) return crypto;
825
825
  hasRequiredCrypto = 1;
826
- crypto = cryptoLib => {
827
- let exports = {};
828
- exports.decodeBase64 = msg => Buffer.from(msg, "base64");
829
- exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
830
- exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
831
- exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
826
+ const loadSodium = cryptoLib => {
827
+ let sodiumLib = {};
832
828
  let SodiumNative, NaCl;
833
829
  switch (cryptoLib) {
834
830
  case "sodiumnative":
835
- SodiumNative = require("sodium-native");
836
- exports.sigVerify = (signedMessage, validateKey) => {
837
- let msg = signedMessage.subarray(64);
838
- let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
839
- if (!ok) {
840
- return false;
841
- }
842
- return msg;
843
- };
844
- exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
845
- exports.secretbox = (message, nonce, secretKey) => {
846
- let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
847
- SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
848
- return secretBox;
849
- };
850
- exports.secretboxOpen = (secretBox, nonce, secretKey) => {
851
- let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
852
- if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
831
+ try {
832
+ SodiumNative = require("sodium-native");
833
+ sodiumLib.sigVerify = (signedMessage, validateKey) => {
834
+ let msg = signedMessage.subarray(64);
835
+ let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
836
+ if (!ok) {
837
+ return false;
838
+ }
853
839
  return msg;
854
- } else {
855
- return void 0;
856
- }
857
- };
858
- exports.publicKeyFromSecretKey = secretKey => {
859
- let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
860
- SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
861
- return pk;
862
- };
863
- exports.hash = message => {
864
- let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
865
- SodiumNative.crypto_hash_sha512(out, message);
866
- return out;
867
- };
840
+ };
841
+ sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
842
+ sodiumLib.secretbox = (message, nonce, secretKey) => {
843
+ let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
844
+ SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
845
+ return secretBox;
846
+ };
847
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
848
+ let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
849
+ if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
850
+ return msg;
851
+ } else {
852
+ return void 0;
853
+ }
854
+ };
855
+ sodiumLib.publicKeyFromSecretKey = secretKey => {
856
+ let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
857
+ SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
858
+ return pk;
859
+ };
860
+ sodiumLib.hash = message => {
861
+ let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
862
+ SodiumNative.crypto_hash_sha512(out, message);
863
+ return out;
864
+ };
865
+ } catch (err) {
866
+ console.error("Error in loading sodium-native: fallback on tweetnacl");
867
+ return loadSodium("");
868
+ }
868
869
  break;
869
870
 
870
871
  default:
871
872
  NaCl = require$$0$1;
872
- exports.sigVerify = NaCl.sign.open;
873
- exports.detachedVerify = NaCl.sign.detached.verify;
874
- exports.secretbox = NaCl.secretbox;
875
- exports.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
876
- exports.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
877
- exports.hash = msg => Buffer.from(NaCl.hash(msg));
873
+ sodiumLib.sigVerify = NaCl.sign.open;
874
+ sodiumLib.detachedVerify = NaCl.sign.detached.verify;
875
+ sodiumLib.secretbox = NaCl.secretbox;
876
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
877
+ sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
878
+ sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
878
879
  break;
879
880
  }
881
+ return sodiumLib;
882
+ };
883
+ crypto = cryptoLib => {
884
+ const exports = loadSodium(cryptoLib);
885
+ exports.decodeBase64 = msg => Buffer.from(msg, "base64");
886
+ exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
887
+ exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
888
+ exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
880
889
  return exports;
881
890
  };
882
891
  return crypto;
@@ -934,13 +943,13 @@ function require_interface() {
934
943
  return;
935
944
  }
936
945
  const {type: rcvType, idx, challenge: challengeBase64, nonce: nonceBase64} = data;
937
- const challenge = new Uint8Array(Buffer.from(challengeBase64, "base64"));
938
- const nonce = new Uint8Array(Buffer.from(nonceBase64, "base64"));
946
+ const challenge = new Uint8Array(Crypto.decodeBase64(challengeBase64));
947
+ const nonce = new Uint8Array(Crypto.decodeBase64(nonceBase64));
939
948
  if (ctx.ChallengesCache[challengeBase64]) {
940
949
  other.disconnect();
941
950
  return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Reused challenge");
942
951
  }
943
- const msg = Buffer.from(Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key));
952
+ const msg = Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key);
944
953
  if (!msg) {
945
954
  other.disconnect();
946
955
  return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Bad challenge answer");
@@ -1015,13 +1024,13 @@ function require_interface() {
1015
1024
  let uid = Util.guid(ctx.pendingConnections);
1016
1025
  ctx.pendingConnections[uid] = coreId;
1017
1026
  const nonce = NodeCrypto.randomBytes(24);
1018
- const msg = Buffer.from(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`, "utf-8");
1019
- const challenge = Crypto.secretbox(msg, nonce, ctx.nodes_key).toString("base64");
1027
+ const msg = Crypto.decodeUTF8(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`);
1028
+ const challenge = Crypto.encodeBase64(Crypto.secretbox(msg, nonce, ctx.nodes_key));
1020
1029
  createHandlers(ctx, other);
1021
1030
  other.send([ uid, "IDENTITY", {
1022
1031
  type: ctx.myType,
1023
1032
  idx: ctx.myNumber,
1024
- nonce: nonce.toString("base64"),
1033
+ nonce: Crypto.encodeBase64(nonce),
1025
1034
  challenge
1026
1035
  } ]);
1027
1036
  };
@@ -1958,7 +1967,6 @@ function requireCore$1() {
1958
1967
  const Util = requireCommonUtil$1();
1959
1968
  const Constants = requireConstants();
1960
1969
  const escapeKeyCharacters = Util.escapeKeyCharacters;
1961
- __require$3();
1962
1970
  const Crypto = __require$5();
1963
1971
  const Keys = requireKeys();
1964
1972
  Core.DEFAULT_LIMIT = 50 * 1024 * 1024;
@@ -2078,8 +2086,7 @@ function requireCore$1() {
2078
2086
  cb();
2079
2087
  };
2080
2088
  Core.getPaths = (mainConfig, isEnv) => {
2081
- const {index, config} = mainConfig;
2082
- Constants.paths;
2089
+ const {config} = mainConfig;
2083
2090
  const all = {
2084
2091
  basePath: config.basePath || config.base || "./data",
2085
2092
  filePath: config.filePath || "./datastore",
@@ -4436,11 +4443,6 @@ function requireAdmin() {
4436
4443
  const nThen = require$$3;
4437
4444
  const Crypto = __require$5();
4438
4445
  const Admin = {};
4439
- const getWorkerProfiles = function(Env, _publicKey, _data, cb) {
4440
- cb(void 0, {
4441
- "Not Implemented": 1
4442
- });
4443
- };
4444
4446
  const getUid = () => Crypto.randomBytes(18).toString("hex");
4445
4447
  const getInvitations = (Env, _publicKey, _data, cb) => {
4446
4448
  Env.interface.broadcast("storage", "ADMIN_CMD", {
@@ -4509,11 +4511,6 @@ function requireAdmin() {
4509
4511
  }
4510
4512
  Env.flushCache(args, cb);
4511
4513
  };
4512
- const getDiskUsage = (Env, _publicKey, _data, cb) => {
4513
- cb(void 0, {
4514
- DEPRECATED: 0
4515
- });
4516
- };
4517
4514
  const getRegisteredUsers = (Env, _publicKey, _data, cb) => {
4518
4515
  Env.interface.broadcast("storage", "GET_REGISTERED_USERS", {}, (_err, data) => {
4519
4516
  let users = data.reduce((acc, it) => acc + it?.users, 0);
@@ -5157,7 +5154,6 @@ function requireAdmin() {
5157
5154
  ACTIVE_SESSIONS: getActiveSessions,
5158
5155
  ACTIVE_PADS: getActiveChannelCount,
5159
5156
  REGISTERED_USERS: getRegisteredUsers,
5160
- DISK_USAGE: getDiskUsage,
5161
5157
  FLUSH_CACHE: flushCache,
5162
5158
  GET_FILE_DESCRIPTOR_COUNT: getFileDescriptorCount,
5163
5159
  GET_FILE_DESCRIPTOR_LIMIT: getFileDescriptorLimit,
@@ -5194,7 +5190,6 @@ function requireAdmin() {
5194
5190
  ADMIN_DECREE: Admin.sendDecree,
5195
5191
  INSTANCE_STATUS: instanceStatus,
5196
5192
  GET_LIMITS: getLimits,
5197
- GET_WORKER_PROFILES: getWorkerProfiles,
5198
5193
  GET_USER_TOTAL_SIZE: getUserTotalSize,
5199
5194
  GET_ALL_INVITATIONS: getInvitations,
5200
5195
  CREATE_INVITATION: createInvitation,
@@ -7687,7 +7682,7 @@ function requireHttpCommands() {
7687
7682
  return httpCommands;
7688
7683
  }
7689
7684
 
7690
- var version = "0.0.1";
7685
+ var version = "0.0.3";
7691
7686
 
7692
7687
  var require$$2 = {
7693
7688
  version
@@ -813,60 +813,69 @@ var hasRequiredCrypto;
813
813
  function requireCrypto() {
814
814
  if (hasRequiredCrypto) return crypto;
815
815
  hasRequiredCrypto = 1;
816
- crypto = cryptoLib => {
817
- let exports = {};
818
- exports.decodeBase64 = msg => Buffer.from(msg, "base64");
819
- exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
820
- exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
821
- exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
816
+ const loadSodium = cryptoLib => {
817
+ let sodiumLib = {};
822
818
  let SodiumNative, NaCl;
823
819
  switch (cryptoLib) {
824
820
  case "sodiumnative":
825
- SodiumNative = require("sodium-native");
826
- exports.sigVerify = (signedMessage, validateKey) => {
827
- let msg = signedMessage.subarray(64);
828
- let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
829
- if (!ok) {
830
- return false;
831
- }
832
- return msg;
833
- };
834
- exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
835
- exports.secretbox = (message, nonce, secretKey) => {
836
- let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
837
- SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
838
- return secretBox;
839
- };
840
- exports.secretboxOpen = (secretBox, nonce, secretKey) => {
841
- let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
842
- if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
821
+ try {
822
+ SodiumNative = require("sodium-native");
823
+ sodiumLib.sigVerify = (signedMessage, validateKey) => {
824
+ let msg = signedMessage.subarray(64);
825
+ let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
826
+ if (!ok) {
827
+ return false;
828
+ }
843
829
  return msg;
844
- } else {
845
- return void 0;
846
- }
847
- };
848
- exports.publicKeyFromSecretKey = secretKey => {
849
- let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
850
- SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
851
- return pk;
852
- };
853
- exports.hash = message => {
854
- let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
855
- SodiumNative.crypto_hash_sha512(out, message);
856
- return out;
857
- };
830
+ };
831
+ sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
832
+ sodiumLib.secretbox = (message, nonce, secretKey) => {
833
+ let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
834
+ SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
835
+ return secretBox;
836
+ };
837
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
838
+ let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
839
+ if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
840
+ return msg;
841
+ } else {
842
+ return void 0;
843
+ }
844
+ };
845
+ sodiumLib.publicKeyFromSecretKey = secretKey => {
846
+ let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
847
+ SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
848
+ return pk;
849
+ };
850
+ sodiumLib.hash = message => {
851
+ let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
852
+ SodiumNative.crypto_hash_sha512(out, message);
853
+ return out;
854
+ };
855
+ } catch (err) {
856
+ console.error("Error in loading sodium-native: fallback on tweetnacl");
857
+ return loadSodium("");
858
+ }
858
859
  break;
859
860
 
860
861
  default:
861
862
  NaCl = require$$0$1;
862
- exports.sigVerify = NaCl.sign.open;
863
- exports.detachedVerify = NaCl.sign.detached.verify;
864
- exports.secretbox = NaCl.secretbox;
865
- exports.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
866
- exports.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
867
- exports.hash = msg => Buffer.from(NaCl.hash(msg));
863
+ sodiumLib.sigVerify = NaCl.sign.open;
864
+ sodiumLib.detachedVerify = NaCl.sign.detached.verify;
865
+ sodiumLib.secretbox = NaCl.secretbox;
866
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
867
+ sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
868
+ sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
868
869
  break;
869
870
  }
871
+ return sodiumLib;
872
+ };
873
+ crypto = cryptoLib => {
874
+ const exports = loadSodium(cryptoLib);
875
+ exports.decodeBase64 = msg => Buffer.from(msg, "base64");
876
+ exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
877
+ exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
878
+ exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
870
879
  return exports;
871
880
  };
872
881
  return crypto;
package/build/front.js CHANGED
@@ -22,8 +22,6 @@ var require$$1$2 = require("express");
22
22
 
23
23
  var require$$4$1 = require("cookie-parser");
24
24
 
25
- var require$$5 = require("body-parser");
26
-
27
25
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
28
26
 
29
27
  var commonUtil$2 = {
@@ -829,60 +827,69 @@ var hasRequiredCrypto;
829
827
  function requireCrypto() {
830
828
  if (hasRequiredCrypto) return crypto;
831
829
  hasRequiredCrypto = 1;
832
- crypto = cryptoLib => {
833
- let exports = {};
834
- exports.decodeBase64 = msg => Buffer.from(msg, "base64");
835
- exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
836
- exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
837
- exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
830
+ const loadSodium = cryptoLib => {
831
+ let sodiumLib = {};
838
832
  let SodiumNative, NaCl;
839
833
  switch (cryptoLib) {
840
834
  case "sodiumnative":
841
- SodiumNative = require("sodium-native");
842
- exports.sigVerify = (signedMessage, validateKey) => {
843
- let msg = signedMessage.subarray(64);
844
- let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
845
- if (!ok) {
846
- return false;
847
- }
848
- return msg;
849
- };
850
- exports.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
851
- exports.secretbox = (message, nonce, secretKey) => {
852
- let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
853
- SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
854
- return secretBox;
855
- };
856
- exports.secretboxOpen = (secretBox, nonce, secretKey) => {
857
- let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
858
- if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
835
+ try {
836
+ SodiumNative = require("sodium-native");
837
+ sodiumLib.sigVerify = (signedMessage, validateKey) => {
838
+ let msg = signedMessage.subarray(64);
839
+ let ok = SodiumNative.crypto_sign_open(msg, signedMessage, validateKey);
840
+ if (!ok) {
841
+ return false;
842
+ }
859
843
  return msg;
860
- } else {
861
- return void 0;
862
- }
863
- };
864
- exports.publicKeyFromSecretKey = secretKey => {
865
- let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
866
- SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
867
- return pk;
868
- };
869
- exports.hash = message => {
870
- let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
871
- SodiumNative.crypto_hash_sha512(out, message);
872
- return out;
873
- };
844
+ };
845
+ sodiumLib.detachedVerify = (signedBuffer, signatureBuffer, validateKey) => SodiumNative.crypto_sign_verify_detached(signatureBuffer, signedBuffer, validateKey);
846
+ sodiumLib.secretbox = (message, nonce, secretKey) => {
847
+ let secretBox = Buffer.alloc(message.length + SodiumNative.crypto_box_MACBYTES);
848
+ SodiumNative.crypto_secretbox_easy(secretBox, message, nonce, secretKey);
849
+ return secretBox;
850
+ };
851
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => {
852
+ let msg = Buffer.alloc(secretBox.length - SodiumNative.crypto_secretbox_MACBYTES);
853
+ if (SodiumNative.crypto_secretbox_open_easy(msg, secretBox, nonce, secretKey)) {
854
+ return msg;
855
+ } else {
856
+ return void 0;
857
+ }
858
+ };
859
+ sodiumLib.publicKeyFromSecretKey = secretKey => {
860
+ let pk = new Uint8Array(SodiumNative.crypto_sign_PUBLICKEYBYTES);
861
+ SodiumNative.crypto_sign_ed25519_sk_to_pk(pk, secretKey);
862
+ return pk;
863
+ };
864
+ sodiumLib.hash = message => {
865
+ let out = Buffer.alloc(SodiumNative.crypto_hash_sha512_BYTES);
866
+ SodiumNative.crypto_hash_sha512(out, message);
867
+ return out;
868
+ };
869
+ } catch (err) {
870
+ console.error("Error in loading sodium-native: fallback on tweetnacl");
871
+ return loadSodium("");
872
+ }
874
873
  break;
875
874
 
876
875
  default:
877
876
  NaCl = require$$0$1;
878
- exports.sigVerify = NaCl.sign.open;
879
- exports.detachedVerify = NaCl.sign.detached.verify;
880
- exports.secretbox = NaCl.secretbox;
881
- exports.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
882
- exports.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
883
- exports.hash = msg => Buffer.from(NaCl.hash(msg));
877
+ sodiumLib.sigVerify = NaCl.sign.open;
878
+ sodiumLib.detachedVerify = NaCl.sign.detached.verify;
879
+ sodiumLib.secretbox = NaCl.secretbox;
880
+ sodiumLib.secretboxOpen = (secretBox, nonce, secretKey) => Buffer.from(NaCl.secretbox.open(secretBox, nonce, secretKey));
881
+ sodiumLib.publicKeyFromSecretKey = secretKey => NaCl.sign?.keyPair?.fromSecretKey(secretKey)?.publicKey;
882
+ sodiumLib.hash = msg => Buffer.from(NaCl.hash(msg));
884
883
  break;
885
884
  }
885
+ return sodiumLib;
886
+ };
887
+ crypto = cryptoLib => {
888
+ const exports = loadSodium(cryptoLib);
889
+ exports.decodeBase64 = msg => Buffer.from(msg, "base64");
890
+ exports.encodeBase64 = msg => Buffer.from(msg).toString("base64");
891
+ exports.decodeUTF8 = msg => Buffer.from(msg, "utf8");
892
+ exports.encodeUTF8 = msg => Buffer.from(msg).toString("utf8");
886
893
  return exports;
887
894
  };
888
895
  return crypto;
@@ -940,13 +947,13 @@ function require_interface() {
940
947
  return;
941
948
  }
942
949
  const {type: rcvType, idx, challenge: challengeBase64, nonce: nonceBase64} = data;
943
- const challenge = new Uint8Array(Buffer.from(challengeBase64, "base64"));
944
- const nonce = new Uint8Array(Buffer.from(nonceBase64, "base64"));
950
+ const challenge = new Uint8Array(Crypto.decodeBase64(challengeBase64));
951
+ const nonce = new Uint8Array(Crypto.decodeBase64(nonceBase64));
945
952
  if (ctx.ChallengesCache[challengeBase64]) {
946
953
  other.disconnect();
947
954
  return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Reused challenge");
948
955
  }
949
- const msg = Buffer.from(Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key));
956
+ const msg = Crypto.secretboxOpen(challenge, nonce, ctx.nodes_key);
950
957
  if (!msg) {
951
958
  other.disconnect();
952
959
  return ctx.Log.error("INTERFACE_CHALLENGE_ERROR", "Bad challenge answer");
@@ -1021,13 +1028,13 @@ function require_interface() {
1021
1028
  let uid = Util.guid(ctx.pendingConnections);
1022
1029
  ctx.pendingConnections[uid] = coreId;
1023
1030
  const nonce = NodeCrypto.randomBytes(24);
1024
- const msg = Buffer.from(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`, "utf-8");
1025
- const challenge = Crypto.secretbox(msg, nonce, ctx.nodes_key).toString("base64");
1031
+ const msg = Crypto.decodeUTF8(`${ctx.myType}:${ctx.myNumber}:${String(Date.now())}`);
1032
+ const challenge = Crypto.encodeBase64(Crypto.secretbox(msg, nonce, ctx.nodes_key));
1026
1033
  createHandlers(ctx, other);
1027
1034
  other.send([ uid, "IDENTITY", {
1028
1035
  type: ctx.myType,
1029
1036
  idx: ctx.myNumber,
1030
- nonce: nonce.toString("base64"),
1037
+ nonce: Crypto.encodeBase64(nonce),
1031
1038
  challenge
1032
1039
  } ]);
1033
1040
  };
@@ -1561,7 +1568,6 @@ function requireCore() {
1561
1568
  const Util = requireCommonUtil$1();
1562
1569
  const Constants = requireConstants();
1563
1570
  const escapeKeyCharacters = Util.escapeKeyCharacters;
1564
- __require();
1565
1571
  const Crypto = __require$3();
1566
1572
  const Keys = requireKeys();
1567
1573
  Core.DEFAULT_LIMIT = 50 * 1024 * 1024;
@@ -1681,8 +1687,7 @@ function requireCore() {
1681
1687
  cb();
1682
1688
  };
1683
1689
  Core.getPaths = (mainConfig, isEnv) => {
1684
- const {index, config} = mainConfig;
1685
- Constants.paths;
1690
+ const {config} = mainConfig;
1686
1691
  const all = {
1687
1692
  basePath: config.basePath || config.base || "./data",
1688
1693
  filePath: config.filePath || "./datastore",
@@ -4044,7 +4049,7 @@ function requireLogger() {
4044
4049
  return logger;
4045
4050
  }
4046
4051
 
4047
- var version = "0.0.1";
4052
+ var version = "0.0.3";
4048
4053
 
4049
4054
  var require$$2 = {
4050
4055
  version
@@ -5001,7 +5006,6 @@ function requireNetwork() {
5001
5006
  const {setHeaders} = requireHeaders();
5002
5007
  const Crypto = require("crypto");
5003
5008
  const cookieParser = require$$4$1;
5004
- const bodyParser = require$$5;
5005
5009
  const Network = {};
5006
5010
  const app = Express();
5007
5011
  const events = {
@@ -5019,7 +5023,7 @@ function requireNetwork() {
5019
5023
  }
5020
5024
  next();
5021
5025
  });
5022
- app.use(bodyParser.urlencoded({
5026
+ app.use(Express.urlencoded({
5023
5027
  extended: true
5024
5028
  }));
5025
5029
  app.use(cookieParser());