diff --git a/package.json b/package.json index 575c084..47c2e01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tweetnacl-sealedbox-js", - "version": "1.1.0", + "version": "1.2.0", "description": "", "main": "sealedbox.node.js", "module": "entrypoint.js", @@ -12,13 +12,14 @@ "author": "", "license": "MIT", "devDependencies": { - "mocha": "^4.0.1", - "sodium": "^2.0.3", - "webpack": "^3.10.0", - "webpack-node-externals": "^1.6.0" + "libsodium-wrappers": "^0.7.5", + "mocha": "^6.2.0", + "webpack": "^4.39.2", + "webpack-cli": "^3.3.7", + "webpack-node-externals": "^1.7.2" }, "dependencies": { "blakejs": "^1.1.0", - "tweetnacl": "^1.0.0" + "tweetnacl": "^1.0.1" } } diff --git a/sealedbox.node.js b/sealedbox.node.js index cbb7220..030613c 100644 --- a/sealedbox.node.js +++ b/sealedbox.node.js @@ -1,211 +1 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else { - var a = factory(); - for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; - } -})(typeof self !== 'undefined' ? self : this, function() { -return /******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 3); -/******/ }) -/************************************************************************/ -/******/ ([ -/* 0 */ -/***/ (function(module, exports) { - -module.exports = require("tweetnacl"); - -/***/ }), -/* 1 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl__ = __webpack_require__(0); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_tweetnacl__); - - -const overheadLength = __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.publicKeyLength + __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.overheadLength; -/* harmony export (immutable) */ __webpack_exports__["a"] = overheadLength; - - - -/***/ }), -/* 2 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (immutable) */ __webpack_exports__["a"] = nonce; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl__ = __webpack_require__(0); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_tweetnacl__); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b__ = __webpack_require__(5); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b__); - - - -function nonce(pk1, pk2){ - var state = __WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b___default.a.blake2bInit(__WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.nonceLength, null); - __WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b___default.a.blake2bUpdate(state, pk1); - __WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b___default.a.blake2bUpdate(state, pk2); - return __WEBPACK_IMPORTED_MODULE_1_blakejs_blake2b___default.a.blake2bFinal(state); -}; - - -/***/ }), -/* 3 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -Object.defineProperty(__webpack_exports__, "__esModule", { value: true }); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__src_consts__ = __webpack_require__(1); -/* harmony namespace reexport (by provided) */ __webpack_require__.d(__webpack_exports__, "overheadLength", function() { return __WEBPACK_IMPORTED_MODULE_0__src_consts__["a"]; }); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__src_seal__ = __webpack_require__(4); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__src_open__ = __webpack_require__(7); -/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "seal", function() { return __WEBPACK_IMPORTED_MODULE_1__src_seal__["a"]; }); -/* harmony reexport (binding) */ __webpack_require__.d(__webpack_exports__, "open", function() { return __WEBPACK_IMPORTED_MODULE_2__src_open__["a"]; }); - - - - - - - - -/***/ }), -/* 4 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (immutable) */ __webpack_exports__["a"] = seal; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl__ = __webpack_require__(0); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_tweetnacl__); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__nonce__ = __webpack_require__(2); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__consts__ = __webpack_require__(1); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__utils__ = __webpack_require__(6); - - - - - -function seal(m, pk){ - var c = new Uint8Array(__WEBPACK_IMPORTED_MODULE_2__consts__["a" /* overheadLength */] + m.length); - - var ek = __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.keyPair(); - c.set(ek.publicKey); - - var nonce = Object(__WEBPACK_IMPORTED_MODULE_1__nonce__["a" /* default */])(ek.publicKey, pk); - var boxed = __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box(m, nonce, pk, ek.secretKey); - c.set(boxed, ek.publicKey.length); - - Object(__WEBPACK_IMPORTED_MODULE_3__utils__["a" /* zero */])(ek.secretKey); - - return c; -}; - - -/***/ }), -/* 5 */ -/***/ (function(module, exports) { - -module.exports = require("blakejs/blake2b"); - -/***/ }), -/* 6 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (immutable) */ __webpack_exports__["a"] = zero; -function zero(buf){ - for(var i = 0; i < buf.length; i++){ - buf[i] = 0; - } -}; - - -/***/ }), -/* 7 */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -/* harmony export (immutable) */ __webpack_exports__["a"] = open; -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl__ = __webpack_require__(0); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_tweetnacl__); -/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__nonce__ = __webpack_require__(2); - - - -function open(c, pk, sk){ - var epk = c.subarray(0, __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.publicKeyLength); - var nonce = Object(__WEBPACK_IMPORTED_MODULE_1__nonce__["a" /* default */])(epk, pk); - - var boxData = c.subarray(__WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.publicKeyLength); - return __WEBPACK_IMPORTED_MODULE_0_tweetnacl___default.a.box.open(boxData, nonce, epk, sk); -}; - - -/***/ }) -/******/ ]); -}); \ No newline at end of file +!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(global,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){e.exports=require("tweetnacl")},function(e,t){e.exports=require("blakejs/blake2b")},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r);const u=o.a.box.publicKeyLength+o.a.box.overheadLength;var a=n(1),i=n.n(a);function l(e,t){var n=i.a.blake2bInit(o.a.box.nonceLength,null);return i.a.blake2bUpdate(n,e),i.a.blake2bUpdate(n,t),i.a.blake2bFinal(n)}function f(e,t){var n=new Uint8Array(u+e.length),r=o.a.box.keyPair();n.set(r.publicKey);var a=l(r.publicKey,t),i=o.a.box(e,a,t,r.secretKey);return n.set(i,r.publicKey.length),function(e){for(var t=0;t=4294967296&&o++,e[n]=r,e[n+1]=o}function o(e,n,t,r){var o=e[n]+t;t<0&&(o+=4294967296);var a=e[n+1]+r;o>=4294967296&&a++,e[n]=o,e[n+1]=a}function a(e,n){return e[n]^e[n+1]<<8^e[n+2]<<16^e[n+3]<<24}function u(e,n,t,a,u,c){var i=x[u],f=x[u+1],l=x[c],b=x[c+1];r(d,e,n),o(d,e,i,f);var s=d[a]^d[e],p=d[a+1]^d[e+1];d[a]=p,d[a+1]=s,r(d,t,a),s=d[n]^d[t],p=d[n+1]^d[t+1],d[n]=s>>>24^p<<8,d[n+1]=p>>>24^s<<8,r(d,e,n),o(d,e,l,b),s=d[a]^d[e],p=d[a+1]^d[e+1],d[a]=s>>>16^p<<16,d[a+1]=p>>>16^s<<16,r(d,t,a),s=d[n]^d[t],p=d[n+1]^d[t+1],d[n]=p>>>31^s<<1,d[n+1]=s>>>31^p<<1}function c(e,n){var t=0;for(t=0;t<16;t++)d[t]=e.h[t],d[t+16]=v[t];for(d[24]=d[24]^e.t,d[25]=d[25]^e.t/4294967296,n&&(d[28]=~d[28],d[29]=~d[29]),t=0;t<32;t++)x[t]=a(e.b,4*t);for(t=0;t<12;t++)u(0,8,16,24,h[16*t+0],h[16*t+1]),u(2,10,18,26,h[16*t+2],h[16*t+3]),u(4,12,20,28,h[16*t+4],h[16*t+5]),u(6,14,22,30,h[16*t+6],h[16*t+7]),u(0,10,20,30,h[16*t+8],h[16*t+9]),u(2,12,22,24,h[16*t+10],h[16*t+11]),u(4,14,16,26,h[16*t+12],h[16*t+13]),u(6,8,18,28,h[16*t+14],h[16*t+15]);for(t=0;t<16;t++)e.h[t]=e.h[t]^d[t]^d[t+16]}function i(e,n){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(n&&n.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");for(var t={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:e},r=0;r<16;r++)t.h[r]=v[r];var o=n?n.length:0;return t.h[0]^=16842752^o<<8^e,n&&(f(t,n),t.c=128),t}function f(e,n){for(var t=0;t>2]>>8*(3&t);return n}function b(e,n,t){t=t||64,e=p.normalizeInput(e);var r=i(t,n);return f(r,e),l(r)}function s(e,n,t){var r=b(e,n,t);return p.toHex(r)}var p=t(6),v=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),y=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],h=new Uint8Array(y.map(function(e){return 2*e})),d=new Uint32Array(32),x=new Uint32Array(32);e.exports={blake2b:b,blake2bHex:s,blake2bInit:i,blake2bUpdate:f,blake2bFinal:l}},function(e,t){e.exports=n},function(e,n,t){"use strict";function r(e){for(var n=0;n=4294967296&&o++,e[n]=r,e[n+1]=o}function a(e,n,t,r){var o=e[n]+t;t<0&&(o+=4294967296);var a=e[n+1]+r;o>=4294967296&&a++,e[n]=o,e[n+1]=a}function u(e,n){return e[n]^e[n+1]<<8^e[n+2]<<16^e[n+3]<<24}function i(e,n,t,r,u,i){var c=b[u],l=b[u+1],p=b[i],y=b[i+1];o(f,e,n),a(f,e,c,l);var d=f[r]^f[e],s=f[r+1]^f[e+1];f[r]=s,f[r+1]=d,o(f,t,r),d=f[n]^f[t],s=f[n+1]^f[t+1],f[n]=d>>>24^s<<8,f[n+1]=s>>>24^d<<8,o(f,e,n),a(f,e,p,y),d=f[r]^f[e],s=f[r+1]^f[e+1],f[r]=d>>>16^s<<16,f[r+1]=s>>>16^d<<16,o(f,t,r),d=f[n]^f[t],s=f[n+1]^f[t+1],f[n]=s>>>31^d<<1,f[n+1]=d>>>31^s<<1}var c=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),l=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map(function(e){return 2*e})),f=new Uint32Array(32),b=new Uint32Array(32);function p(e,n){var t=0;for(t=0;t<16;t++)f[t]=e.h[t],f[t+16]=c[t];for(f[24]=f[24]^e.t,f[25]=f[25]^e.t/4294967296,n&&(f[28]=~f[28],f[29]=~f[29]),t=0;t<32;t++)b[t]=u(e.b,4*t);for(t=0;t<12;t++)i(0,8,16,24,l[16*t+0],l[16*t+1]),i(2,10,18,26,l[16*t+2],l[16*t+3]),i(4,12,20,28,l[16*t+4],l[16*t+5]),i(6,14,22,30,l[16*t+6],l[16*t+7]),i(0,10,20,30,l[16*t+8],l[16*t+9]),i(2,12,22,24,l[16*t+10],l[16*t+11]),i(4,14,16,26,l[16*t+12],l[16*t+13]),i(6,8,18,28,l[16*t+14],l[16*t+15]);for(t=0;t<16;t++)e.h[t]=e.h[t]^f[t]^f[t+16]}function y(e,n){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(n&&n.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");for(var t={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:e},r=0;r<16;r++)t.h[r]=c[r];var o=n?n.length:0;return t.h[0]^=16842752^o<<8^e,n&&(d(t,n),t.c=128),t}function d(e,n){for(var t=0;t>2]>>8*(3&t);return n}function v(e,n,t){t=t||64,e=r.normalizeInput(e);var o=y(t,n);return d(o,e),s(o)}e.exports={blake2b:v,blake2bHex:function(e,n,t){var o=v(e,n,t);return r.toHex(o)},blake2bInit:y,blake2bUpdate:d,blake2bFinal:s}},function(e,t){e.exports=n},function(e,n,t){"use strict";t.r(n);var r=t(0),o=t.n(r);const a=o.a.box.publicKeyLength+o.a.box.overheadLength;var u=t(1),i=t.n(u);function c(e,n){var t=i.a.blake2bInit(o.a.box.nonceLength,null);return i.a.blake2bUpdate(t,e),i.a.blake2bUpdate(t,n),i.a.blake2bFinal(t)}function l(e,n){var t=new Uint8Array(a+e.length),r=o.a.box.keyPair();t.set(r.publicKey);var u=c(r.publicKey,n),i=o.a.box(e,u,n,r.secretKey);return t.set(i,r.publicKey.length),function(e){for(var n=0;n