JavaScript 65.5%
Python 17.8%
CSS 13%
HTML 3.7%
1"use strict";23Object.defineProperty(exports, "__esModule", {4 value: true5});6exports.DHCipher = void 0;7var _bigint = require("./bigint.js");8function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }9function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }10function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }11function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }12function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }13function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }14var DHPublicKey = /*#__PURE__*/function () {15 function DHPublicKey(key) {16 _classCallCheck(this, DHPublicKey);17 this._key = key;18 }19 return _createClass(DHPublicKey, [{20 key: "algorithm",21 get: function get() {22 return {23 name: "DH"24 };25 }26 }, {27 key: "exportKey",28 value: function exportKey() {29 return this._key;30 }31 }]);32}();33var DHCipher = exports.DHCipher = /*#__PURE__*/function () {34 function DHCipher() {35 _classCallCheck(this, DHCipher);36 this._g = null;37 this._p = null;38 this._gBigInt = null;39 this._pBigInt = null;40 this._privateKey = null;41 }42 return _createClass(DHCipher, [{43 key: "algorithm",44 get: function get() {45 return {46 name: "DH"47 };48 }49 }, {50 key: "_generateKey",51 value: function _generateKey(algorithm) {52 var g = algorithm.g;53 var p = algorithm.p;54 this._keyBytes = p.length;55 this._gBigInt = (0, _bigint.u8ArrayToBigInt)(g);56 this._pBigInt = (0, _bigint.u8ArrayToBigInt)(p);57 this._privateKey = window.crypto.getRandomValues(new Uint8Array(this._keyBytes));58 this._privateKeyBigInt = (0, _bigint.u8ArrayToBigInt)(this._privateKey);59 this._publicKey = (0, _bigint.bigIntToU8Array)((0, _bigint.modPow)(this._gBigInt, this._privateKeyBigInt, this._pBigInt), this._keyBytes);60 }61 }, {62 key: "deriveBits",63 value: function deriveBits(algorithm, length) {64 var bytes = Math.ceil(length / 8);65 var pkey = new Uint8Array(algorithm["public"]);66 var len = bytes > this._keyBytes ? bytes : this._keyBytes;67 var secret = (0, _bigint.modPow)((0, _bigint.u8ArrayToBigInt)(pkey), this._privateKeyBigInt, this._pBigInt);68 return (0, _bigint.bigIntToU8Array)(secret, len).slice(0, len);69 }70 }], [{71 key: "generateKey",72 value: function generateKey(algorithm, _extractable) {73 var cipher = new DHCipher();74 cipher._generateKey(algorithm);75 return {76 privateKey: cipher,77 publicKey: new DHPublicKey(cipher._publicKey)78 };79 }80 }]);81}();