solid-ui 2.4.27-2da93f8e → 2.4.27-2f08a162
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/solid-ui.js +20 -3245
- package/dist/solid-ui.js.map +1 -1
- package/dist/solid-ui.min.js +1 -1
- package/dist/solid-ui.min.js.LICENSE.txt +0 -4
- package/dist/solid-ui.min.js.map +1 -1
- package/lib/chat/chatLogic.js +17 -35
- package/lib/chat/chatLogic.js.map +1 -1
- package/lib/chat/message.js +0 -16
- package/lib/chat/message.js.map +1 -1
- package/lib/versionInfo.js +2 -2
- package/lib/versionInfo.js.map +1 -1
- package/package.json +1 -4
- package/lib/chat/crypto.d.ts +0 -1
- package/lib/chat/crypto.d.ts.map +0 -1
- package/lib/chat/crypto.js +0 -257
- package/lib/chat/crypto.js.map +0 -1
- package/lib/chat/keys.d.ts +0 -5
- package/lib/chat/keys.d.ts.map +0 -1
- package/lib/chat/keys.js +0 -90
- package/lib/chat/keys.js.map +0 -1
- package/lib/chat/signature.d.ts +0 -27
- package/lib/chat/signature.d.ts.map +0 -1
- package/lib/chat/signature.js +0 -110
- package/lib/chat/signature.js.map +0 -1
package/dist/solid-ui.js
CHANGED
|
@@ -2593,8 +2593,6 @@ var _solidLogic = __webpack_require__(/*! solid-logic */ "./node_modules/solid-l
|
|
|
2593
2593
|
var ns = _interopRequireWildcard(__webpack_require__(/*! ../ns */ "./lib/ns.js"));
|
|
2594
2594
|
var $rdf = _interopRequireWildcard(__webpack_require__(/*! rdflib */ "./node_modules/rdflib/esm/index.js"));
|
|
2595
2595
|
var utils = _interopRequireWildcard(__webpack_require__(/*! ../utils */ "./lib/utils/index.js"));
|
|
2596
|
-
var _signature = __webpack_require__(/*! ./signature */ "./lib/chat/signature.js");
|
|
2597
|
-
var _keys = __webpack_require__(/*! ./keys */ "./lib/chat/keys.js");
|
|
2598
2596
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
2599
2597
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
2600
2598
|
/**
|
|
@@ -2655,7 +2653,7 @@ var ChatChannel = /*#__PURE__*/function () {
|
|
|
2655
2653
|
var oldMsg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
2656
2654
|
var deleteIt = arguments.length > 2 ? arguments[2] : undefined;
|
|
2657
2655
|
return /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
2658
|
-
var sts, now, timestamp, dateStamp, chatDocument, message, me, msg
|
|
2656
|
+
var sts, now, timestamp, dateStamp, chatDocument, message, me, msg;
|
|
2659
2657
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
2660
2658
|
while (1) switch (_context2.prev = _context2.next) {
|
|
2661
2659
|
case 0:
|
|
@@ -2666,57 +2664,41 @@ var ChatChannel = /*#__PURE__*/function () {
|
|
|
2666
2664
|
chatDocument = oldMsg ? oldMsg.doc() : _this.dateFolder.leafDocumentFromDate(now);
|
|
2667
2665
|
message = _solidLogic.store.sym(chatDocument.uri + '#' + 'Msg' + timestamp); // const content = store.literal(text)
|
|
2668
2666
|
me = _solidLogic.authn.currentUser(); // If already logged on
|
|
2669
|
-
msg = _signature.getBlankMsg;
|
|
2670
|
-
msg.id = message;
|
|
2671
2667
|
if (oldMsg) {
|
|
2672
2668
|
// edit message replaces old one
|
|
2673
2669
|
sts.push($rdf.st(mostRecentVersion(oldMsg), ns.dct('isReplacedBy'), message, chatDocument));
|
|
2674
|
-
// do we need to rebuild oldMsg signaturen ?
|
|
2675
2670
|
if (deleteIt) {
|
|
2676
2671
|
sts.push($rdf.st(message, ns.schema('dateDeleted'), dateStamp, chatDocument));
|
|
2677
|
-
msg.dateDeleted = dateStamp;
|
|
2678
2672
|
}
|
|
2679
2673
|
} else {
|
|
2680
2674
|
// link new message to channel
|
|
2681
2675
|
sts.push($rdf.st(_this.channel, ns.wf('message'), message, chatDocument));
|
|
2682
2676
|
}
|
|
2683
2677
|
sts.push($rdf.st(message, ns.sioc('content'), _solidLogic.store.literal(text), chatDocument));
|
|
2684
|
-
msg.content = text;
|
|
2685
2678
|
sts.push($rdf.st(message, ns.dct('created'), dateStamp, chatDocument));
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
_context2.next = 21;
|
|
2689
|
-
break;
|
|
2679
|
+
if (me) {
|
|
2680
|
+
sts.push($rdf.st(message, ns.foaf('maker'), me, chatDocument));
|
|
2690
2681
|
}
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
// privateKey the cached private key of me, cache should be deleted after a certain time
|
|
2694
|
-
_context2.next = 19;
|
|
2695
|
-
return (0, _keys.getPrivateKey)(me);
|
|
2696
|
-
case 19:
|
|
2697
|
-
privateKey = _context2.sent;
|
|
2698
|
-
sts.push($rdf.st(message, $rdf.sym("".concat(_signature.SEC, "Proof")), $rdf.sym((0, _signature.signMsg)(msg, privateKey), chatDocument)));
|
|
2699
|
-
case 21:
|
|
2700
|
-
_context2.prev = 21;
|
|
2701
|
-
_context2.next = 24;
|
|
2682
|
+
_context2.prev = 11;
|
|
2683
|
+
_context2.next = 14;
|
|
2702
2684
|
return _solidLogic.store.updater.update([], sts);
|
|
2703
|
-
case
|
|
2704
|
-
_context2.next =
|
|
2685
|
+
case 14:
|
|
2686
|
+
_context2.next = 22;
|
|
2705
2687
|
break;
|
|
2706
|
-
case
|
|
2707
|
-
_context2.prev =
|
|
2708
|
-
_context2.t0 = _context2["catch"](
|
|
2709
|
-
|
|
2710
|
-
debug.warn(
|
|
2711
|
-
alert(
|
|
2712
|
-
throw new Error(
|
|
2713
|
-
case
|
|
2688
|
+
case 16:
|
|
2689
|
+
_context2.prev = 16;
|
|
2690
|
+
_context2.t0 = _context2["catch"](11);
|
|
2691
|
+
msg = 'Error saving chat message: ' + _context2.t0;
|
|
2692
|
+
debug.warn(msg);
|
|
2693
|
+
alert(msg);
|
|
2694
|
+
throw new Error(msg);
|
|
2695
|
+
case 22:
|
|
2714
2696
|
return _context2.abrupt("return", message);
|
|
2715
|
-
case
|
|
2697
|
+
case 23:
|
|
2716
2698
|
case "end":
|
|
2717
2699
|
return _context2.stop();
|
|
2718
2700
|
}
|
|
2719
|
-
}, _callee2, null, [[
|
|
2701
|
+
}, _callee2, null, [[11, 16]]);
|
|
2720
2702
|
})();
|
|
2721
2703
|
});
|
|
2722
2704
|
function updateMessage(_x2) {
|
|
@@ -3991,106 +3973,6 @@ function _infiniteMessageArea() {
|
|
|
3991
3973
|
|
|
3992
3974
|
/***/ }),
|
|
3993
3975
|
|
|
3994
|
-
/***/ "./lib/chat/keys.js":
|
|
3995
|
-
/*!**************************!*\
|
|
3996
|
-
!*** ./lib/chat/keys.js ***!
|
|
3997
|
-
\**************************/
|
|
3998
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
3999
|
-
|
|
4000
|
-
"use strict";
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ "./node_modules/@babel/runtime/helpers/interopRequireDefault.js");
|
|
4004
|
-
var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
|
|
4005
|
-
Object.defineProperty(exports, "__esModule", ({
|
|
4006
|
-
value: true
|
|
4007
|
-
}));
|
|
4008
|
-
exports.generatePrivateKey = generatePrivateKey;
|
|
4009
|
-
exports.generatePublicKey = generatePublicKey;
|
|
4010
|
-
exports.getPrivateKey = getPrivateKey;
|
|
4011
|
-
exports.getPublicKey = getPublicKey;
|
|
4012
|
-
var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ "./node_modules/@babel/runtime/regenerator/index.js"));
|
|
4013
|
-
var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ "./node_modules/@babel/runtime/helpers/asyncToGenerator.js"));
|
|
4014
|
-
var _secp256k = __webpack_require__(/*! @noble/curves/secp256k1 */ "./node_modules/@noble/curves/secp256k1.js");
|
|
4015
|
-
var _utils = __webpack_require__(/*! @noble/hashes/utils */ "./node_modules/@noble/hashes/utils.js");
|
|
4016
|
-
var _signature = __webpack_require__(/*! ./signature */ "./lib/chat/signature.js");
|
|
4017
|
-
var _solidLogic = __webpack_require__(/*! solid-logic */ "./node_modules/solid-logic/lib/index.js");
|
|
4018
|
-
var $rdf = _interopRequireWildcard(__webpack_require__(/*! rdflib */ "./node_modules/rdflib/esm/index.js"));
|
|
4019
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
4020
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
4021
|
-
// should have webcrypto.getRandomValues defined
|
|
4022
|
-
|
|
4023
|
-
function generatePrivateKey() {
|
|
4024
|
-
return (0, _utils.bytesToHex)(_secp256k.schnorr.utils.randomPrivateKey());
|
|
4025
|
-
}
|
|
4026
|
-
function generatePublicKey(privateKey) {
|
|
4027
|
-
return (0, _utils.bytesToHex)(_secp256k.schnorr.getPublicKey(privateKey));
|
|
4028
|
-
}
|
|
4029
|
-
function getPublicKey(webId) {
|
|
4030
|
-
// find publickey
|
|
4031
|
-
/* const url = new URL(webId)
|
|
4032
|
-
url.hash = ''
|
|
4033
|
-
store.fetcher.load(url.href)
|
|
4034
|
-
let publicKey = store.any(store.sym(webId), store.sym(CERT +'publicKey')) */
|
|
4035
|
-
var publicKey = publicKeyExists(webId);
|
|
4036
|
-
return publicKey === null || publicKey === void 0 ? void 0 : publicKey.uri;
|
|
4037
|
-
}
|
|
4038
|
-
function publicKeyExists(webId) {
|
|
4039
|
-
// find publickey
|
|
4040
|
-
var url = new URL(webId);
|
|
4041
|
-
url.hash = '';
|
|
4042
|
-
_solidLogic.store.fetcher.load(url.href);
|
|
4043
|
-
var publicKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'publicKey'));
|
|
4044
|
-
return publicKey;
|
|
4045
|
-
}
|
|
4046
|
-
function privateKeyExists(webId) {
|
|
4047
|
-
var url = new URL(webId);
|
|
4048
|
-
var privateKeyUrl = url.hostname + '/profile/privateKey.ttl';
|
|
4049
|
-
_solidLogic.store.fetcher.load(privateKeyUrl);
|
|
4050
|
-
var privateKey = _solidLogic.store.any(_solidLogic.store.sym(webId), _solidLogic.store.sym(_signature.CERT + 'privateKey'));
|
|
4051
|
-
return privateKey;
|
|
4052
|
-
}
|
|
4053
|
-
function getPrivateKey(_x) {
|
|
4054
|
-
return _getPrivateKey.apply(this, arguments);
|
|
4055
|
-
}
|
|
4056
|
-
function _getPrivateKey() {
|
|
4057
|
-
_getPrivateKey = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(webId) {
|
|
4058
|
-
var url, privateKeyUrl, publicKey, privateKey, del, add;
|
|
4059
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
4060
|
-
while (1) switch (_context.prev = _context.next) {
|
|
4061
|
-
case 0:
|
|
4062
|
-
url = new URL(webId);
|
|
4063
|
-
privateKeyUrl = url.hostname + '/profile/privateKey.ttl'; // find publickey
|
|
4064
|
-
publicKey = publicKeyExists(webId); // find privateKey
|
|
4065
|
-
privateKey = privateKeyExists(webId); // create key pair
|
|
4066
|
-
if (!(!privateKey || !publicKey)) {
|
|
4067
|
-
_context.next = 15;
|
|
4068
|
-
break;
|
|
4069
|
-
}
|
|
4070
|
-
del = [];
|
|
4071
|
-
add = [];
|
|
4072
|
-
if (privateKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), privateKey, $rdf.sym(privateKeyUrl)));
|
|
4073
|
-
if (publicKey) del.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), publicKey, $rdf.sym(url.href)));
|
|
4074
|
-
privateKey = _solidLogic.store.sym(generatePrivateKey());
|
|
4075
|
-
publicKey = _solidLogic.store.sym(generatePublicKey(privateKey.uri));
|
|
4076
|
-
add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'privateKey'), $rdf.literal(privateKey.uri), $rdf.sym(privateKeyUrl)));
|
|
4077
|
-
add.push($rdf.st($rdf.sym(webId), $rdf.sym(_signature.CERT + 'publicKey'), $rdf.literal(publicKey.uri), $rdf.sym(url.href)));
|
|
4078
|
-
_context.next = 15;
|
|
4079
|
-
return _solidLogic.store.updater.updateMany(del, add);
|
|
4080
|
-
case 15:
|
|
4081
|
-
return _context.abrupt("return", privateKey.uri);
|
|
4082
|
-
case 16:
|
|
4083
|
-
case "end":
|
|
4084
|
-
return _context.stop();
|
|
4085
|
-
}
|
|
4086
|
-
}, _callee);
|
|
4087
|
-
}));
|
|
4088
|
-
return _getPrivateKey.apply(this, arguments);
|
|
4089
|
-
}
|
|
4090
|
-
//# sourceMappingURL=keys.js.map
|
|
4091
|
-
|
|
4092
|
-
/***/ }),
|
|
4093
|
-
|
|
4094
3976
|
/***/ "./lib/chat/message.js":
|
|
4095
3977
|
/*!*****************************!*\
|
|
4096
3978
|
!*** ./lib/chat/message.js ***!
|
|
@@ -4127,8 +4009,6 @@ var pad = _interopRequireWildcard(__webpack_require__(/*! ../pad */ "./lib/pad.j
|
|
|
4127
4009
|
var style = _interopRequireWildcard(__webpack_require__(/*! ../style */ "./lib/style.js"));
|
|
4128
4010
|
var utils = _interopRequireWildcard(__webpack_require__(/*! ../utils */ "./lib/utils/index.js"));
|
|
4129
4011
|
var widgets = _interopRequireWildcard(__webpack_require__(/*! ../widgets */ "./lib/widgets/index.js"));
|
|
4130
|
-
var _signature = __webpack_require__(/*! ./signature */ "./lib/chat/signature.js");
|
|
4131
|
-
var _keys = __webpack_require__(/*! ./keys */ "./lib/chat/keys.js");
|
|
4132
4012
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
4133
4013
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
4134
4014
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
@@ -4216,20 +4096,6 @@ function renderMessageRow(channelObject, message, fresh, options, userContext) {
|
|
|
4216
4096
|
var date = _solidLogic.store.any(message, ns.dct('created'));
|
|
4217
4097
|
var latestVersion = (0, _chatLogic.mostRecentVersion)(message);
|
|
4218
4098
|
var content = _solidLogic.store.any(latestVersion, ns.sioc('content'));
|
|
4219
|
-
var signature = _solidLogic.store.any(message, $rdf.sym("".concat(_signature.SEC, "Proof")));
|
|
4220
|
-
|
|
4221
|
-
// verify signature
|
|
4222
|
-
var msg = (0, _signature.getBlankMsg)();
|
|
4223
|
-
msg.id = message;
|
|
4224
|
-
msg.created = date;
|
|
4225
|
-
// this is not correct.
|
|
4226
|
-
// If the message has been edited/deleted we must verify the latest message and may be the intermediate ones
|
|
4227
|
-
msg.content = content;
|
|
4228
|
-
msg.maker = creator;
|
|
4229
|
-
|
|
4230
|
-
// pubKey could be store in a cache for all makers
|
|
4231
|
-
var pubKey = (0, _keys.getPublicKey)(creator); // alain no
|
|
4232
|
-
if (!(0, _signature.verifySignature)(signature, msg, pubKey)) throw new Error();
|
|
4233
4099
|
var originalMessage = (0, _chatLogic.originalVersion)(message);
|
|
4234
4100
|
var edited = !message.sameTerm(originalMessage);
|
|
4235
4101
|
var sortDate = _solidLogic.store.the(originalMessage, ns.dct('created'), null, originalMessage.doc()); // In message
|
|
@@ -5010,126 +4876,6 @@ function messageToolbar(message, messageRow, userContext, channelObject) {
|
|
|
5010
4876
|
|
|
5011
4877
|
/***/ }),
|
|
5012
4878
|
|
|
5013
|
-
/***/ "./lib/chat/signature.js":
|
|
5014
|
-
/*!*******************************!*\
|
|
5015
|
-
!*** ./lib/chat/signature.js ***!
|
|
5016
|
-
\*******************************/
|
|
5017
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
5018
|
-
|
|
5019
|
-
"use strict";
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
Object.defineProperty(exports, "__esModule", ({
|
|
5023
|
-
value: true
|
|
5024
|
-
}));
|
|
5025
|
-
exports.SEC = exports.CERT = void 0;
|
|
5026
|
-
exports.finishMsg = finishMsg;
|
|
5027
|
-
exports.getBlankMsg = getBlankMsg;
|
|
5028
|
-
exports.getMsgHash = getMsgHash;
|
|
5029
|
-
exports.serializeMsg = serializeMsg;
|
|
5030
|
-
exports.signMsg = signMsg;
|
|
5031
|
-
exports.utf8Encoder = exports.utf8Decoder = void 0;
|
|
5032
|
-
exports.validateMsg = validateMsg;
|
|
5033
|
-
exports.verifySignature = verifySignature;
|
|
5034
|
-
var _secp256k = __webpack_require__(/*! @noble/curves/secp256k1 */ "./node_modules/@noble/curves/secp256k1.js");
|
|
5035
|
-
var _sha = __webpack_require__(/*! @noble/hashes/sha256 */ "./node_modules/@noble/hashes/sha256.js");
|
|
5036
|
-
var _utils = __webpack_require__(/*! @noble/hashes/utils */ "./node_modules/@noble/hashes/utils.js");
|
|
5037
|
-
// import {utf8Encoder} from './utils'
|
|
5038
|
-
// import { getPublicKey } from './keys'
|
|
5039
|
-
|
|
5040
|
-
var utf8Decoder = new TextDecoder('utf-8');
|
|
5041
|
-
exports.utf8Decoder = utf8Decoder;
|
|
5042
|
-
var utf8Encoder = new TextEncoder();
|
|
5043
|
-
exports.utf8Encoder = utf8Encoder;
|
|
5044
|
-
var SEC = 'https://w3id.org/security#'; // Proof, VerificationMethod
|
|
5045
|
-
exports.SEC = SEC;
|
|
5046
|
-
var CERT = 'http://www.w3.org/ns/auth/cert#'; // PrivatKey, PublicKey
|
|
5047
|
-
|
|
5048
|
-
/* eslint-disable no-unused-vars */
|
|
5049
|
-
/* export enum Kind {
|
|
5050
|
-
Metadata = 0,
|
|
5051
|
-
Text = 1,
|
|
5052
|
-
RecommendRelay = 2,
|
|
5053
|
-
Contacts = 3,
|
|
5054
|
-
EncryptedDirectMessage = 4,
|
|
5055
|
-
EventDeletion = 5,
|
|
5056
|
-
Reaction = 7,
|
|
5057
|
-
BadgeAward = 8,
|
|
5058
|
-
ChannelCreation = 40,
|
|
5059
|
-
ChannelMetadata = 41,
|
|
5060
|
-
ChannelMessage = 42,
|
|
5061
|
-
ChannelHideMessage = 43,
|
|
5062
|
-
ChannelMuteUser = 44,
|
|
5063
|
-
Report = 1984,
|
|
5064
|
-
ZapRequest = 9734,
|
|
5065
|
-
Zap = 9735,
|
|
5066
|
-
RelayList = 10002,
|
|
5067
|
-
ClientAuth = 22242,
|
|
5068
|
-
BadgeDefinition = 30008,
|
|
5069
|
-
ProfileBadge = 30009,
|
|
5070
|
-
Article = 30023
|
|
5071
|
-
} */
|
|
5072
|
-
exports.CERT = CERT;
|
|
5073
|
-
function getBlankMsg() {
|
|
5074
|
-
return {
|
|
5075
|
-
id: '',
|
|
5076
|
-
created: '',
|
|
5077
|
-
dateDeleted: '',
|
|
5078
|
-
content: '',
|
|
5079
|
-
maker: '',
|
|
5080
|
-
sig: ''
|
|
5081
|
-
};
|
|
5082
|
-
}
|
|
5083
|
-
function finishMsg(t, privateKey) {
|
|
5084
|
-
// to update to chat message triples
|
|
5085
|
-
var message = t;
|
|
5086
|
-
// message.pubkey = getPublicKey(privateKey)
|
|
5087
|
-
message.id = getMsgHash(message);
|
|
5088
|
-
message.sig = signMsg(message, privateKey);
|
|
5089
|
-
return message;
|
|
5090
|
-
}
|
|
5091
|
-
function serializeMsg(msg) {
|
|
5092
|
-
// to update to chat messages triples
|
|
5093
|
-
/* if (!validateMsg(msg))
|
|
5094
|
-
throw new Error("can't serialize message with wrong or missing properties") */
|
|
5095
|
-
|
|
5096
|
-
return JSON.stringify(msg);
|
|
5097
|
-
}
|
|
5098
|
-
function getMsgHash(message) {
|
|
5099
|
-
var msgHash = (0, _sha.sha256)(utf8Encoder.encode(serializeMsg(message)));
|
|
5100
|
-
return (0, _utils.bytesToHex)(msgHash);
|
|
5101
|
-
}
|
|
5102
|
-
var isRecord = function isRecord(obj) {
|
|
5103
|
-
return obj instanceof Object;
|
|
5104
|
-
};
|
|
5105
|
-
function validateMsg(message) {
|
|
5106
|
-
/* if (!isRecord(message)) return false
|
|
5107
|
-
if (typeof message.kind !== 'number') return false
|
|
5108
|
-
if (typeof message.content !== 'string') return false
|
|
5109
|
-
if (typeof message.created_at !== 'number') return false
|
|
5110
|
-
if (typeof message.pubkey !== 'string') return false
|
|
5111
|
-
if (!message.pubkey.match(/^[a-f0-9]{64}$/)) return false
|
|
5112
|
-
if (!Array.isArray(message.tags)) return false
|
|
5113
|
-
for (let i = 0; i < message.tags.length; i++) {
|
|
5114
|
-
let tag = message.tags[i]
|
|
5115
|
-
if (!Array.isArray(tag)) return false
|
|
5116
|
-
for (let j = 0; j < tag.length; j++) {
|
|
5117
|
-
if (typeof tag[j] === 'object') return false
|
|
5118
|
-
}
|
|
5119
|
-
} */
|
|
5120
|
-
|
|
5121
|
-
return true;
|
|
5122
|
-
}
|
|
5123
|
-
function verifySignature(sig, message, pubKey) {
|
|
5124
|
-
return _secp256k.schnorr.verify(sig, getMsgHash(message), pubKey);
|
|
5125
|
-
}
|
|
5126
|
-
function signMsg(message, key) {
|
|
5127
|
-
return (0, _utils.bytesToHex)(_secp256k.schnorr.sign(getMsgHash(message), key));
|
|
5128
|
-
}
|
|
5129
|
-
//# sourceMappingURL=signature.js.map
|
|
5130
|
-
|
|
5131
|
-
/***/ }),
|
|
5132
|
-
|
|
5133
4879
|
/***/ "./lib/create/create.js":
|
|
5134
4880
|
/*!******************************!*\
|
|
5135
4881
|
!*** ./lib/create/create.js ***!
|
|
@@ -13176,8 +12922,8 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
13176
12922
|
}));
|
|
13177
12923
|
exports.versionInfo = void 0;
|
|
13178
12924
|
var versionInfo = {
|
|
13179
|
-
buildTime: '2023-
|
|
13180
|
-
commit: '
|
|
12925
|
+
buildTime: '2023-05-10T10:31:42Z',
|
|
12926
|
+
commit: '2f08a1623c81c49457fe3958898259f1a9dc5a4b',
|
|
13181
12927
|
npmInfo: {
|
|
13182
12928
|
'solid-ui': '2.4.27',
|
|
13183
12929
|
npm: '8.19.4',
|
|
@@ -29586,2962 +29332,6 @@ function validate(uuid) {
|
|
|
29586
29332
|
|
|
29587
29333
|
/***/ }),
|
|
29588
29334
|
|
|
29589
|
-
/***/ "./node_modules/@noble/curves/_shortw_utils.js":
|
|
29590
|
-
/*!*****************************************************!*\
|
|
29591
|
-
!*** ./node_modules/@noble/curves/_shortw_utils.js ***!
|
|
29592
|
-
\*****************************************************/
|
|
29593
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
29594
|
-
|
|
29595
|
-
"use strict";
|
|
29596
|
-
|
|
29597
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
29598
|
-
exports.createCurve = exports.getHash = void 0;
|
|
29599
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
29600
|
-
const hmac_1 = __webpack_require__(/*! @noble/hashes/hmac */ "./node_modules/@noble/hashes/hmac.js");
|
|
29601
|
-
const utils_1 = __webpack_require__(/*! @noble/hashes/utils */ "./node_modules/@noble/hashes/utils.js");
|
|
29602
|
-
const weierstrass_js_1 = __webpack_require__(/*! ./abstract/weierstrass.js */ "./node_modules/@noble/curves/abstract/weierstrass.js");
|
|
29603
|
-
// connects noble-curves to noble-hashes
|
|
29604
|
-
function getHash(hash) {
|
|
29605
|
-
return {
|
|
29606
|
-
hash,
|
|
29607
|
-
hmac: (key, ...msgs) => (0, hmac_1.hmac)(hash, key, (0, utils_1.concatBytes)(...msgs)),
|
|
29608
|
-
randomBytes: utils_1.randomBytes,
|
|
29609
|
-
};
|
|
29610
|
-
}
|
|
29611
|
-
exports.getHash = getHash;
|
|
29612
|
-
function createCurve(curveDef, defHash) {
|
|
29613
|
-
const create = (hash) => (0, weierstrass_js_1.weierstrass)({ ...curveDef, ...getHash(hash) });
|
|
29614
|
-
return Object.freeze({ ...create(defHash), create });
|
|
29615
|
-
}
|
|
29616
|
-
exports.createCurve = createCurve;
|
|
29617
|
-
//# sourceMappingURL=_shortw_utils.js.map
|
|
29618
|
-
|
|
29619
|
-
/***/ }),
|
|
29620
|
-
|
|
29621
|
-
/***/ "./node_modules/@noble/curves/abstract/curve.js":
|
|
29622
|
-
/*!******************************************************!*\
|
|
29623
|
-
!*** ./node_modules/@noble/curves/abstract/curve.js ***!
|
|
29624
|
-
\******************************************************/
|
|
29625
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
29626
|
-
|
|
29627
|
-
"use strict";
|
|
29628
|
-
|
|
29629
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
29630
|
-
exports.validateBasic = exports.wNAF = void 0;
|
|
29631
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
29632
|
-
// Abelian group utilities
|
|
29633
|
-
const modular_js_1 = __webpack_require__(/*! ./modular.js */ "./node_modules/@noble/curves/abstract/modular.js");
|
|
29634
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/curves/abstract/utils.js");
|
|
29635
|
-
const _0n = BigInt(0);
|
|
29636
|
-
const _1n = BigInt(1);
|
|
29637
|
-
// Elliptic curve multiplication of Point by scalar. Fragile.
|
|
29638
|
-
// Scalars should always be less than curve order: this should be checked inside of a curve itself.
|
|
29639
|
-
// Creates precomputation tables for fast multiplication:
|
|
29640
|
-
// - private scalar is split by fixed size windows of W bits
|
|
29641
|
-
// - every window point is collected from window's table & added to accumulator
|
|
29642
|
-
// - since windows are different, same point inside tables won't be accessed more than once per calc
|
|
29643
|
-
// - each multiplication is 'Math.ceil(CURVE_ORDER / 𝑊) + 1' point additions (fixed for any scalar)
|
|
29644
|
-
// - +1 window is neccessary for wNAF
|
|
29645
|
-
// - wNAF reduces table size: 2x less memory + 2x faster generation, but 10% slower multiplication
|
|
29646
|
-
// TODO: Research returning 2d JS array of windows, instead of a single window. This would allow
|
|
29647
|
-
// windows to be in different memory locations
|
|
29648
|
-
function wNAF(c, bits) {
|
|
29649
|
-
const constTimeNegate = (condition, item) => {
|
|
29650
|
-
const neg = item.negate();
|
|
29651
|
-
return condition ? neg : item;
|
|
29652
|
-
};
|
|
29653
|
-
const opts = (W) => {
|
|
29654
|
-
const windows = Math.ceil(bits / W) + 1; // +1, because
|
|
29655
|
-
const windowSize = 2 ** (W - 1); // -1 because we skip zero
|
|
29656
|
-
return { windows, windowSize };
|
|
29657
|
-
};
|
|
29658
|
-
return {
|
|
29659
|
-
constTimeNegate,
|
|
29660
|
-
// non-const time multiplication ladder
|
|
29661
|
-
unsafeLadder(elm, n) {
|
|
29662
|
-
let p = c.ZERO;
|
|
29663
|
-
let d = elm;
|
|
29664
|
-
while (n > _0n) {
|
|
29665
|
-
if (n & _1n)
|
|
29666
|
-
p = p.add(d);
|
|
29667
|
-
d = d.double();
|
|
29668
|
-
n >>= _1n;
|
|
29669
|
-
}
|
|
29670
|
-
return p;
|
|
29671
|
-
},
|
|
29672
|
-
/**
|
|
29673
|
-
* Creates a wNAF precomputation window. Used for caching.
|
|
29674
|
-
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
29675
|
-
* Number of precomputed points depends on the curve size:
|
|
29676
|
-
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
29677
|
-
* - 𝑊 is the window size
|
|
29678
|
-
* - 𝑛 is the bitlength of the curve order.
|
|
29679
|
-
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
29680
|
-
* @returns precomputed point tables flattened to a single array
|
|
29681
|
-
*/
|
|
29682
|
-
precomputeWindow(elm, W) {
|
|
29683
|
-
const { windows, windowSize } = opts(W);
|
|
29684
|
-
const points = [];
|
|
29685
|
-
let p = elm;
|
|
29686
|
-
let base = p;
|
|
29687
|
-
for (let window = 0; window < windows; window++) {
|
|
29688
|
-
base = p;
|
|
29689
|
-
points.push(base);
|
|
29690
|
-
// =1, because we skip zero
|
|
29691
|
-
for (let i = 1; i < windowSize; i++) {
|
|
29692
|
-
base = base.add(p);
|
|
29693
|
-
points.push(base);
|
|
29694
|
-
}
|
|
29695
|
-
p = base.double();
|
|
29696
|
-
}
|
|
29697
|
-
return points;
|
|
29698
|
-
},
|
|
29699
|
-
/**
|
|
29700
|
-
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
29701
|
-
* @param W window size
|
|
29702
|
-
* @param precomputes precomputed tables
|
|
29703
|
-
* @param n scalar (we don't check here, but should be less than curve order)
|
|
29704
|
-
* @returns real and fake (for const-time) points
|
|
29705
|
-
*/
|
|
29706
|
-
wNAF(W, precomputes, n) {
|
|
29707
|
-
// TODO: maybe check that scalar is less than group order? wNAF behavious is undefined otherwise
|
|
29708
|
-
// But need to carefully remove other checks before wNAF. ORDER == bits here
|
|
29709
|
-
const { windows, windowSize } = opts(W);
|
|
29710
|
-
let p = c.ZERO;
|
|
29711
|
-
let f = c.BASE;
|
|
29712
|
-
const mask = BigInt(2 ** W - 1); // Create mask with W ones: 0b1111 for W=4 etc.
|
|
29713
|
-
const maxNumber = 2 ** W;
|
|
29714
|
-
const shiftBy = BigInt(W);
|
|
29715
|
-
for (let window = 0; window < windows; window++) {
|
|
29716
|
-
const offset = window * windowSize;
|
|
29717
|
-
// Extract W bits.
|
|
29718
|
-
let wbits = Number(n & mask);
|
|
29719
|
-
// Shift number by W bits.
|
|
29720
|
-
n >>= shiftBy;
|
|
29721
|
-
// If the bits are bigger than max size, we'll split those.
|
|
29722
|
-
// +224 => 256 - 32
|
|
29723
|
-
if (wbits > windowSize) {
|
|
29724
|
-
wbits -= maxNumber;
|
|
29725
|
-
n += _1n;
|
|
29726
|
-
}
|
|
29727
|
-
// This code was first written with assumption that 'f' and 'p' will never be infinity point:
|
|
29728
|
-
// since each addition is multiplied by 2 ** W, it cannot cancel each other. However,
|
|
29729
|
-
// there is negate now: it is possible that negated element from low value
|
|
29730
|
-
// would be the same as high element, which will create carry into next window.
|
|
29731
|
-
// It's not obvious how this can fail, but still worth investigating later.
|
|
29732
|
-
// Check if we're onto Zero point.
|
|
29733
|
-
// Add random point inside current window to f.
|
|
29734
|
-
const offset1 = offset;
|
|
29735
|
-
const offset2 = offset + Math.abs(wbits) - 1; // -1 because we skip zero
|
|
29736
|
-
const cond1 = window % 2 !== 0;
|
|
29737
|
-
const cond2 = wbits < 0;
|
|
29738
|
-
if (wbits === 0) {
|
|
29739
|
-
// The most important part for const-time getPublicKey
|
|
29740
|
-
f = f.add(constTimeNegate(cond1, precomputes[offset1]));
|
|
29741
|
-
}
|
|
29742
|
-
else {
|
|
29743
|
-
p = p.add(constTimeNegate(cond2, precomputes[offset2]));
|
|
29744
|
-
}
|
|
29745
|
-
}
|
|
29746
|
-
// JIT-compiler should not eliminate f here, since it will later be used in normalizeZ()
|
|
29747
|
-
// Even if the variable is still unused, there are some checks which will
|
|
29748
|
-
// throw an exception, so compiler needs to prove they won't happen, which is hard.
|
|
29749
|
-
// At this point there is a way to F be infinity-point even if p is not,
|
|
29750
|
-
// which makes it less const-time: around 1 bigint multiply.
|
|
29751
|
-
return { p, f };
|
|
29752
|
-
},
|
|
29753
|
-
wNAFCached(P, precomputesMap, n, transform) {
|
|
29754
|
-
// @ts-ignore
|
|
29755
|
-
const W = P._WINDOW_SIZE || 1;
|
|
29756
|
-
// Calculate precomputes on a first run, reuse them after
|
|
29757
|
-
let comp = precomputesMap.get(P);
|
|
29758
|
-
if (!comp) {
|
|
29759
|
-
comp = this.precomputeWindow(P, W);
|
|
29760
|
-
if (W !== 1) {
|
|
29761
|
-
precomputesMap.set(P, transform(comp));
|
|
29762
|
-
}
|
|
29763
|
-
}
|
|
29764
|
-
return this.wNAF(W, comp, n);
|
|
29765
|
-
},
|
|
29766
|
-
};
|
|
29767
|
-
}
|
|
29768
|
-
exports.wNAF = wNAF;
|
|
29769
|
-
function validateBasic(curve) {
|
|
29770
|
-
(0, modular_js_1.validateField)(curve.Fp);
|
|
29771
|
-
(0, utils_js_1.validateObject)(curve, {
|
|
29772
|
-
n: 'bigint',
|
|
29773
|
-
h: 'bigint',
|
|
29774
|
-
Gx: 'field',
|
|
29775
|
-
Gy: 'field',
|
|
29776
|
-
}, {
|
|
29777
|
-
nBitLength: 'isSafeInteger',
|
|
29778
|
-
nByteLength: 'isSafeInteger',
|
|
29779
|
-
});
|
|
29780
|
-
// Set defaults
|
|
29781
|
-
return Object.freeze({
|
|
29782
|
-
...(0, modular_js_1.nLength)(curve.n, curve.nBitLength),
|
|
29783
|
-
...curve,
|
|
29784
|
-
...{ p: curve.Fp.ORDER },
|
|
29785
|
-
});
|
|
29786
|
-
}
|
|
29787
|
-
exports.validateBasic = validateBasic;
|
|
29788
|
-
//# sourceMappingURL=curve.js.map
|
|
29789
|
-
|
|
29790
|
-
/***/ }),
|
|
29791
|
-
|
|
29792
|
-
/***/ "./node_modules/@noble/curves/abstract/hash-to-curve.js":
|
|
29793
|
-
/*!**************************************************************!*\
|
|
29794
|
-
!*** ./node_modules/@noble/curves/abstract/hash-to-curve.js ***!
|
|
29795
|
-
\**************************************************************/
|
|
29796
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
29797
|
-
|
|
29798
|
-
"use strict";
|
|
29799
|
-
|
|
29800
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
29801
|
-
exports.createHasher = exports.isogenyMap = exports.hash_to_field = exports.expand_message_xof = exports.expand_message_xmd = void 0;
|
|
29802
|
-
const modular_js_1 = __webpack_require__(/*! ./modular.js */ "./node_modules/@noble/curves/abstract/modular.js");
|
|
29803
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/curves/abstract/utils.js");
|
|
29804
|
-
function validateDST(dst) {
|
|
29805
|
-
if (dst instanceof Uint8Array)
|
|
29806
|
-
return dst;
|
|
29807
|
-
if (typeof dst === 'string')
|
|
29808
|
-
return (0, utils_js_1.utf8ToBytes)(dst);
|
|
29809
|
-
throw new Error('DST must be Uint8Array or string');
|
|
29810
|
-
}
|
|
29811
|
-
// Octet Stream to Integer. "spec" implementation of os2ip is 2.5x slower vs bytesToNumberBE.
|
|
29812
|
-
const os2ip = utils_js_1.bytesToNumberBE;
|
|
29813
|
-
// Integer to Octet Stream (numberToBytesBE)
|
|
29814
|
-
function i2osp(value, length) {
|
|
29815
|
-
if (value < 0 || value >= 1 << (8 * length)) {
|
|
29816
|
-
throw new Error(`bad I2OSP call: value=${value} length=${length}`);
|
|
29817
|
-
}
|
|
29818
|
-
const res = Array.from({ length }).fill(0);
|
|
29819
|
-
for (let i = length - 1; i >= 0; i--) {
|
|
29820
|
-
res[i] = value & 0xff;
|
|
29821
|
-
value >>>= 8;
|
|
29822
|
-
}
|
|
29823
|
-
return new Uint8Array(res);
|
|
29824
|
-
}
|
|
29825
|
-
function strxor(a, b) {
|
|
29826
|
-
const arr = new Uint8Array(a.length);
|
|
29827
|
-
for (let i = 0; i < a.length; i++) {
|
|
29828
|
-
arr[i] = a[i] ^ b[i];
|
|
29829
|
-
}
|
|
29830
|
-
return arr;
|
|
29831
|
-
}
|
|
29832
|
-
function isBytes(item) {
|
|
29833
|
-
if (!(item instanceof Uint8Array))
|
|
29834
|
-
throw new Error('Uint8Array expected');
|
|
29835
|
-
}
|
|
29836
|
-
function isNum(item) {
|
|
29837
|
-
if (!Number.isSafeInteger(item))
|
|
29838
|
-
throw new Error('number expected');
|
|
29839
|
-
}
|
|
29840
|
-
// Produces a uniformly random byte string using a cryptographic hash function H that outputs b bits
|
|
29841
|
-
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11#section-5.4.1
|
|
29842
|
-
function expand_message_xmd(msg, DST, lenInBytes, H) {
|
|
29843
|
-
isBytes(msg);
|
|
29844
|
-
isBytes(DST);
|
|
29845
|
-
isNum(lenInBytes);
|
|
29846
|
-
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-5.3.3
|
|
29847
|
-
if (DST.length > 255)
|
|
29848
|
-
DST = H((0, utils_js_1.concatBytes)((0, utils_js_1.utf8ToBytes)('H2C-OVERSIZE-DST-'), DST));
|
|
29849
|
-
const { outputLen: b_in_bytes, blockLen: r_in_bytes } = H;
|
|
29850
|
-
const ell = Math.ceil(lenInBytes / b_in_bytes);
|
|
29851
|
-
if (ell > 255)
|
|
29852
|
-
throw new Error('Invalid xmd length');
|
|
29853
|
-
const DST_prime = (0, utils_js_1.concatBytes)(DST, i2osp(DST.length, 1));
|
|
29854
|
-
const Z_pad = i2osp(0, r_in_bytes);
|
|
29855
|
-
const l_i_b_str = i2osp(lenInBytes, 2); // len_in_bytes_str
|
|
29856
|
-
const b = new Array(ell);
|
|
29857
|
-
const b_0 = H((0, utils_js_1.concatBytes)(Z_pad, msg, l_i_b_str, i2osp(0, 1), DST_prime));
|
|
29858
|
-
b[0] = H((0, utils_js_1.concatBytes)(b_0, i2osp(1, 1), DST_prime));
|
|
29859
|
-
for (let i = 1; i <= ell; i++) {
|
|
29860
|
-
const args = [strxor(b_0, b[i - 1]), i2osp(i + 1, 1), DST_prime];
|
|
29861
|
-
b[i] = H((0, utils_js_1.concatBytes)(...args));
|
|
29862
|
-
}
|
|
29863
|
-
const pseudo_random_bytes = (0, utils_js_1.concatBytes)(...b);
|
|
29864
|
-
return pseudo_random_bytes.slice(0, lenInBytes);
|
|
29865
|
-
}
|
|
29866
|
-
exports.expand_message_xmd = expand_message_xmd;
|
|
29867
|
-
function expand_message_xof(msg, DST, lenInBytes, k, H) {
|
|
29868
|
-
isBytes(msg);
|
|
29869
|
-
isBytes(DST);
|
|
29870
|
-
isNum(lenInBytes);
|
|
29871
|
-
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-5.3.3
|
|
29872
|
-
// DST = H('H2C-OVERSIZE-DST-' || a_very_long_DST, Math.ceil((lenInBytes * k) / 8));
|
|
29873
|
-
if (DST.length > 255) {
|
|
29874
|
-
const dkLen = Math.ceil((2 * k) / 8);
|
|
29875
|
-
DST = H.create({ dkLen }).update((0, utils_js_1.utf8ToBytes)('H2C-OVERSIZE-DST-')).update(DST).digest();
|
|
29876
|
-
}
|
|
29877
|
-
if (lenInBytes > 65535 || DST.length > 255)
|
|
29878
|
-
throw new Error('expand_message_xof: invalid lenInBytes');
|
|
29879
|
-
return (H.create({ dkLen: lenInBytes })
|
|
29880
|
-
.update(msg)
|
|
29881
|
-
.update(i2osp(lenInBytes, 2))
|
|
29882
|
-
// 2. DST_prime = DST || I2OSP(len(DST), 1)
|
|
29883
|
-
.update(DST)
|
|
29884
|
-
.update(i2osp(DST.length, 1))
|
|
29885
|
-
.digest());
|
|
29886
|
-
}
|
|
29887
|
-
exports.expand_message_xof = expand_message_xof;
|
|
29888
|
-
/**
|
|
29889
|
-
* Hashes arbitrary-length byte strings to a list of one or more elements of a finite field F
|
|
29890
|
-
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-11#section-5.3
|
|
29891
|
-
* @param msg a byte string containing the message to hash
|
|
29892
|
-
* @param count the number of elements of F to output
|
|
29893
|
-
* @param options `{DST: string, p: bigint, m: number, k: number, expand: 'xmd' | 'xof', hash: H}`, see above
|
|
29894
|
-
* @returns [u_0, ..., u_(count - 1)], a list of field elements.
|
|
29895
|
-
*/
|
|
29896
|
-
function hash_to_field(msg, count, options) {
|
|
29897
|
-
(0, utils_js_1.validateObject)(options, {
|
|
29898
|
-
DST: 'string',
|
|
29899
|
-
p: 'bigint',
|
|
29900
|
-
m: 'isSafeInteger',
|
|
29901
|
-
k: 'isSafeInteger',
|
|
29902
|
-
hash: 'hash',
|
|
29903
|
-
});
|
|
29904
|
-
const { p, k, m, hash, expand, DST: _DST } = options;
|
|
29905
|
-
isBytes(msg);
|
|
29906
|
-
isNum(count);
|
|
29907
|
-
const DST = validateDST(_DST);
|
|
29908
|
-
const log2p = p.toString(2).length;
|
|
29909
|
-
const L = Math.ceil((log2p + k) / 8); // section 5.1 of ietf draft link above
|
|
29910
|
-
const len_in_bytes = count * m * L;
|
|
29911
|
-
let prb; // pseudo_random_bytes
|
|
29912
|
-
if (expand === 'xmd') {
|
|
29913
|
-
prb = expand_message_xmd(msg, DST, len_in_bytes, hash);
|
|
29914
|
-
}
|
|
29915
|
-
else if (expand === 'xof') {
|
|
29916
|
-
prb = expand_message_xof(msg, DST, len_in_bytes, k, hash);
|
|
29917
|
-
}
|
|
29918
|
-
else if (expand === '_internal_pass') {
|
|
29919
|
-
// for internal tests only
|
|
29920
|
-
prb = msg;
|
|
29921
|
-
}
|
|
29922
|
-
else {
|
|
29923
|
-
throw new Error('expand must be "xmd" or "xof"');
|
|
29924
|
-
}
|
|
29925
|
-
const u = new Array(count);
|
|
29926
|
-
for (let i = 0; i < count; i++) {
|
|
29927
|
-
const e = new Array(m);
|
|
29928
|
-
for (let j = 0; j < m; j++) {
|
|
29929
|
-
const elm_offset = L * (j + i * m);
|
|
29930
|
-
const tv = prb.subarray(elm_offset, elm_offset + L);
|
|
29931
|
-
e[j] = (0, modular_js_1.mod)(os2ip(tv), p);
|
|
29932
|
-
}
|
|
29933
|
-
u[i] = e;
|
|
29934
|
-
}
|
|
29935
|
-
return u;
|
|
29936
|
-
}
|
|
29937
|
-
exports.hash_to_field = hash_to_field;
|
|
29938
|
-
function isogenyMap(field, map) {
|
|
29939
|
-
// Make same order as in spec
|
|
29940
|
-
const COEFF = map.map((i) => Array.from(i).reverse());
|
|
29941
|
-
return (x, y) => {
|
|
29942
|
-
const [xNum, xDen, yNum, yDen] = COEFF.map((val) => val.reduce((acc, i) => field.add(field.mul(acc, x), i)));
|
|
29943
|
-
x = field.div(xNum, xDen); // xNum / xDen
|
|
29944
|
-
y = field.mul(y, field.div(yNum, yDen)); // y * (yNum / yDev)
|
|
29945
|
-
return { x, y };
|
|
29946
|
-
};
|
|
29947
|
-
}
|
|
29948
|
-
exports.isogenyMap = isogenyMap;
|
|
29949
|
-
function createHasher(Point, mapToCurve, def) {
|
|
29950
|
-
if (typeof mapToCurve !== 'function')
|
|
29951
|
-
throw new Error('mapToCurve() must be defined');
|
|
29952
|
-
return {
|
|
29953
|
-
// Encodes byte string to elliptic curve
|
|
29954
|
-
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-3
|
|
29955
|
-
hashToCurve(msg, options) {
|
|
29956
|
-
const u = hash_to_field(msg, 2, { ...def, DST: def.DST, ...options });
|
|
29957
|
-
const u0 = Point.fromAffine(mapToCurve(u[0]));
|
|
29958
|
-
const u1 = Point.fromAffine(mapToCurve(u[1]));
|
|
29959
|
-
const P = u0.add(u1).clearCofactor();
|
|
29960
|
-
P.assertValidity();
|
|
29961
|
-
return P;
|
|
29962
|
-
},
|
|
29963
|
-
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-3
|
|
29964
|
-
encodeToCurve(msg, options) {
|
|
29965
|
-
const u = hash_to_field(msg, 1, { ...def, DST: def.encodeDST, ...options });
|
|
29966
|
-
const P = Point.fromAffine(mapToCurve(u[0])).clearCofactor();
|
|
29967
|
-
P.assertValidity();
|
|
29968
|
-
return P;
|
|
29969
|
-
},
|
|
29970
|
-
};
|
|
29971
|
-
}
|
|
29972
|
-
exports.createHasher = createHasher;
|
|
29973
|
-
//# sourceMappingURL=hash-to-curve.js.map
|
|
29974
|
-
|
|
29975
|
-
/***/ }),
|
|
29976
|
-
|
|
29977
|
-
/***/ "./node_modules/@noble/curves/abstract/modular.js":
|
|
29978
|
-
/*!********************************************************!*\
|
|
29979
|
-
!*** ./node_modules/@noble/curves/abstract/modular.js ***!
|
|
29980
|
-
\********************************************************/
|
|
29981
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
29982
|
-
|
|
29983
|
-
"use strict";
|
|
29984
|
-
|
|
29985
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
29986
|
-
exports.hashToPrivateScalar = exports.FpSqrtEven = exports.FpSqrtOdd = exports.Field = exports.nLength = exports.FpIsSquare = exports.FpDiv = exports.FpInvertBatch = exports.FpPow = exports.validateField = exports.isNegativeLE = exports.FpSqrt = exports.tonelliShanks = exports.invert = exports.pow2 = exports.pow = exports.mod = void 0;
|
|
29987
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
29988
|
-
// Utilities for modular arithmetics and finite fields
|
|
29989
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/curves/abstract/utils.js");
|
|
29990
|
-
// prettier-ignore
|
|
29991
|
-
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
|
|
29992
|
-
// prettier-ignore
|
|
29993
|
-
const _4n = BigInt(4), _5n = BigInt(5), _8n = BigInt(8);
|
|
29994
|
-
// prettier-ignore
|
|
29995
|
-
const _9n = BigInt(9), _16n = BigInt(16);
|
|
29996
|
-
// Calculates a modulo b
|
|
29997
|
-
function mod(a, b) {
|
|
29998
|
-
const result = a % b;
|
|
29999
|
-
return result >= _0n ? result : b + result;
|
|
30000
|
-
}
|
|
30001
|
-
exports.mod = mod;
|
|
30002
|
-
/**
|
|
30003
|
-
* Efficiently exponentiate num to power and do modular division.
|
|
30004
|
-
* Unsafe in some contexts: uses ladder, so can expose bigint bits.
|
|
30005
|
-
* @example
|
|
30006
|
-
* powMod(2n, 6n, 11n) // 64n % 11n == 9n
|
|
30007
|
-
*/
|
|
30008
|
-
// TODO: use field version && remove
|
|
30009
|
-
function pow(num, power, modulo) {
|
|
30010
|
-
if (modulo <= _0n || power < _0n)
|
|
30011
|
-
throw new Error('Expected power/modulo > 0');
|
|
30012
|
-
if (modulo === _1n)
|
|
30013
|
-
return _0n;
|
|
30014
|
-
let res = _1n;
|
|
30015
|
-
while (power > _0n) {
|
|
30016
|
-
if (power & _1n)
|
|
30017
|
-
res = (res * num) % modulo;
|
|
30018
|
-
num = (num * num) % modulo;
|
|
30019
|
-
power >>= _1n;
|
|
30020
|
-
}
|
|
30021
|
-
return res;
|
|
30022
|
-
}
|
|
30023
|
-
exports.pow = pow;
|
|
30024
|
-
// Does x ^ (2 ^ power) mod p. pow2(30, 4) == 30 ^ (2 ^ 4)
|
|
30025
|
-
function pow2(x, power, modulo) {
|
|
30026
|
-
let res = x;
|
|
30027
|
-
while (power-- > _0n) {
|
|
30028
|
-
res *= res;
|
|
30029
|
-
res %= modulo;
|
|
30030
|
-
}
|
|
30031
|
-
return res;
|
|
30032
|
-
}
|
|
30033
|
-
exports.pow2 = pow2;
|
|
30034
|
-
// Inverses number over modulo
|
|
30035
|
-
function invert(number, modulo) {
|
|
30036
|
-
if (number === _0n || modulo <= _0n) {
|
|
30037
|
-
throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
|
|
30038
|
-
}
|
|
30039
|
-
// Eucledian GCD https://brilliant.org/wiki/extended-euclidean-algorithm/
|
|
30040
|
-
// Fermat's little theorem "CT-like" version inv(n) = n^(m-2) mod m is 30x slower.
|
|
30041
|
-
let a = mod(number, modulo);
|
|
30042
|
-
let b = modulo;
|
|
30043
|
-
// prettier-ignore
|
|
30044
|
-
let x = _0n, y = _1n, u = _1n, v = _0n;
|
|
30045
|
-
while (a !== _0n) {
|
|
30046
|
-
// JIT applies optimization if those two lines follow each other
|
|
30047
|
-
const q = b / a;
|
|
30048
|
-
const r = b % a;
|
|
30049
|
-
const m = x - u * q;
|
|
30050
|
-
const n = y - v * q;
|
|
30051
|
-
// prettier-ignore
|
|
30052
|
-
b = a, a = r, x = u, y = v, u = m, v = n;
|
|
30053
|
-
}
|
|
30054
|
-
const gcd = b;
|
|
30055
|
-
if (gcd !== _1n)
|
|
30056
|
-
throw new Error('invert: does not exist');
|
|
30057
|
-
return mod(x, modulo);
|
|
30058
|
-
}
|
|
30059
|
-
exports.invert = invert;
|
|
30060
|
-
// Tonelli-Shanks algorithm
|
|
30061
|
-
// Paper 1: https://eprint.iacr.org/2012/685.pdf (page 12)
|
|
30062
|
-
// Paper 2: Square Roots from 1; 24, 51, 10 to Dan Shanks
|
|
30063
|
-
function tonelliShanks(P) {
|
|
30064
|
-
// Legendre constant: used to calculate Legendre symbol (a | p),
|
|
30065
|
-
// which denotes the value of a^((p-1)/2) (mod p).
|
|
30066
|
-
// (a | p) ≡ 1 if a is a square (mod p)
|
|
30067
|
-
// (a | p) ≡ -1 if a is not a square (mod p)
|
|
30068
|
-
// (a | p) ≡ 0 if a ≡ 0 (mod p)
|
|
30069
|
-
const legendreC = (P - _1n) / _2n;
|
|
30070
|
-
let Q, S, Z;
|
|
30071
|
-
// Step 1: By factoring out powers of 2 from p - 1,
|
|
30072
|
-
// find q and s such that p - 1 = q*(2^s) with q odd
|
|
30073
|
-
for (Q = P - _1n, S = 0; Q % _2n === _0n; Q /= _2n, S++)
|
|
30074
|
-
;
|
|
30075
|
-
// Step 2: Select a non-square z such that (z | p) ≡ -1 and set c ≡ zq
|
|
30076
|
-
for (Z = _2n; Z < P && pow(Z, legendreC, P) !== P - _1n; Z++)
|
|
30077
|
-
;
|
|
30078
|
-
// Fast-path
|
|
30079
|
-
if (S === 1) {
|
|
30080
|
-
const p1div4 = (P + _1n) / _4n;
|
|
30081
|
-
return function tonelliFast(Fp, n) {
|
|
30082
|
-
const root = Fp.pow(n, p1div4);
|
|
30083
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
30084
|
-
throw new Error('Cannot find square root');
|
|
30085
|
-
return root;
|
|
30086
|
-
};
|
|
30087
|
-
}
|
|
30088
|
-
// Slow-path
|
|
30089
|
-
const Q1div2 = (Q + _1n) / _2n;
|
|
30090
|
-
return function tonelliSlow(Fp, n) {
|
|
30091
|
-
// Step 0: Check that n is indeed a square: (n | p) should not be ≡ -1
|
|
30092
|
-
if (Fp.pow(n, legendreC) === Fp.neg(Fp.ONE))
|
|
30093
|
-
throw new Error('Cannot find square root');
|
|
30094
|
-
let r = S;
|
|
30095
|
-
// TODO: will fail at Fp2/etc
|
|
30096
|
-
let g = Fp.pow(Fp.mul(Fp.ONE, Z), Q); // will update both x and b
|
|
30097
|
-
let x = Fp.pow(n, Q1div2); // first guess at the square root
|
|
30098
|
-
let b = Fp.pow(n, Q); // first guess at the fudge factor
|
|
30099
|
-
while (!Fp.eql(b, Fp.ONE)) {
|
|
30100
|
-
if (Fp.eql(b, Fp.ZERO))
|
|
30101
|
-
return Fp.ZERO; // https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm (4. If t = 0, return r = 0)
|
|
30102
|
-
// Find m such b^(2^m)==1
|
|
30103
|
-
let m = 1;
|
|
30104
|
-
for (let t2 = Fp.sqr(b); m < r; m++) {
|
|
30105
|
-
if (Fp.eql(t2, Fp.ONE))
|
|
30106
|
-
break;
|
|
30107
|
-
t2 = Fp.sqr(t2); // t2 *= t2
|
|
30108
|
-
}
|
|
30109
|
-
// NOTE: r-m-1 can be bigger than 32, need to convert to bigint before shift, otherwise there will be overflow
|
|
30110
|
-
const ge = Fp.pow(g, _1n << BigInt(r - m - 1)); // ge = 2^(r-m-1)
|
|
30111
|
-
g = Fp.sqr(ge); // g = ge * ge
|
|
30112
|
-
x = Fp.mul(x, ge); // x *= ge
|
|
30113
|
-
b = Fp.mul(b, g); // b *= g
|
|
30114
|
-
r = m;
|
|
30115
|
-
}
|
|
30116
|
-
return x;
|
|
30117
|
-
};
|
|
30118
|
-
}
|
|
30119
|
-
exports.tonelliShanks = tonelliShanks;
|
|
30120
|
-
function FpSqrt(P) {
|
|
30121
|
-
// NOTE: different algorithms can give different roots, it is up to user to decide which one they want.
|
|
30122
|
-
// For example there is FpSqrtOdd/FpSqrtEven to choice root based on oddness (used for hash-to-curve).
|
|
30123
|
-
// P ≡ 3 (mod 4)
|
|
30124
|
-
// √n = n^((P+1)/4)
|
|
30125
|
-
if (P % _4n === _3n) {
|
|
30126
|
-
// Not all roots possible!
|
|
30127
|
-
// const ORDER =
|
|
30128
|
-
// 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn;
|
|
30129
|
-
// const NUM = 72057594037927816n;
|
|
30130
|
-
const p1div4 = (P + _1n) / _4n;
|
|
30131
|
-
return function sqrt3mod4(Fp, n) {
|
|
30132
|
-
const root = Fp.pow(n, p1div4);
|
|
30133
|
-
// Throw if root**2 != n
|
|
30134
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
30135
|
-
throw new Error('Cannot find square root');
|
|
30136
|
-
return root;
|
|
30137
|
-
};
|
|
30138
|
-
}
|
|
30139
|
-
// Atkin algorithm for q ≡ 5 (mod 8), https://eprint.iacr.org/2012/685.pdf (page 10)
|
|
30140
|
-
if (P % _8n === _5n) {
|
|
30141
|
-
const c1 = (P - _5n) / _8n;
|
|
30142
|
-
return function sqrt5mod8(Fp, n) {
|
|
30143
|
-
const n2 = Fp.mul(n, _2n);
|
|
30144
|
-
const v = Fp.pow(n2, c1);
|
|
30145
|
-
const nv = Fp.mul(n, v);
|
|
30146
|
-
const i = Fp.mul(Fp.mul(nv, _2n), v);
|
|
30147
|
-
const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
|
|
30148
|
-
if (!Fp.eql(Fp.sqr(root), n))
|
|
30149
|
-
throw new Error('Cannot find square root');
|
|
30150
|
-
return root;
|
|
30151
|
-
};
|
|
30152
|
-
}
|
|
30153
|
-
// P ≡ 9 (mod 16)
|
|
30154
|
-
if (P % _16n === _9n) {
|
|
30155
|
-
// NOTE: tonelli is too slow for bls-Fp2 calculations even on start
|
|
30156
|
-
// Means we cannot use sqrt for constants at all!
|
|
30157
|
-
//
|
|
30158
|
-
// const c1 = Fp.sqrt(Fp.negate(Fp.ONE)); // 1. c1 = sqrt(-1) in F, i.e., (c1^2) == -1 in F
|
|
30159
|
-
// const c2 = Fp.sqrt(c1); // 2. c2 = sqrt(c1) in F, i.e., (c2^2) == c1 in F
|
|
30160
|
-
// const c3 = Fp.sqrt(Fp.negate(c1)); // 3. c3 = sqrt(-c1) in F, i.e., (c3^2) == -c1 in F
|
|
30161
|
-
// const c4 = (P + _7n) / _16n; // 4. c4 = (q + 7) / 16 # Integer arithmetic
|
|
30162
|
-
// sqrt = (x) => {
|
|
30163
|
-
// let tv1 = Fp.pow(x, c4); // 1. tv1 = x^c4
|
|
30164
|
-
// let tv2 = Fp.mul(c1, tv1); // 2. tv2 = c1 * tv1
|
|
30165
|
-
// const tv3 = Fp.mul(c2, tv1); // 3. tv3 = c2 * tv1
|
|
30166
|
-
// let tv4 = Fp.mul(c3, tv1); // 4. tv4 = c3 * tv1
|
|
30167
|
-
// const e1 = Fp.equals(Fp.square(tv2), x); // 5. e1 = (tv2^2) == x
|
|
30168
|
-
// const e2 = Fp.equals(Fp.square(tv3), x); // 6. e2 = (tv3^2) == x
|
|
30169
|
-
// tv1 = Fp.cmov(tv1, tv2, e1); // 7. tv1 = CMOV(tv1, tv2, e1) # Select tv2 if (tv2^2) == x
|
|
30170
|
-
// tv2 = Fp.cmov(tv4, tv3, e2); // 8. tv2 = CMOV(tv4, tv3, e2) # Select tv3 if (tv3^2) == x
|
|
30171
|
-
// const e3 = Fp.equals(Fp.square(tv2), x); // 9. e3 = (tv2^2) == x
|
|
30172
|
-
// return Fp.cmov(tv1, tv2, e3); // 10. z = CMOV(tv1, tv2, e3) # Select the sqrt from tv1 and tv2
|
|
30173
|
-
// }
|
|
30174
|
-
}
|
|
30175
|
-
// Other cases: Tonelli-Shanks algorithm
|
|
30176
|
-
return tonelliShanks(P);
|
|
30177
|
-
}
|
|
30178
|
-
exports.FpSqrt = FpSqrt;
|
|
30179
|
-
// Little-endian check for first LE bit (last BE bit);
|
|
30180
|
-
const isNegativeLE = (num, modulo) => (mod(num, modulo) & _1n) === _1n;
|
|
30181
|
-
exports.isNegativeLE = isNegativeLE;
|
|
30182
|
-
// prettier-ignore
|
|
30183
|
-
const FIELD_FIELDS = [
|
|
30184
|
-
'create', 'isValid', 'is0', 'neg', 'inv', 'sqrt', 'sqr',
|
|
30185
|
-
'eql', 'add', 'sub', 'mul', 'pow', 'div',
|
|
30186
|
-
'addN', 'subN', 'mulN', 'sqrN'
|
|
30187
|
-
];
|
|
30188
|
-
function validateField(field) {
|
|
30189
|
-
const initial = {
|
|
30190
|
-
ORDER: 'bigint',
|
|
30191
|
-
MASK: 'bigint',
|
|
30192
|
-
BYTES: 'isSafeInteger',
|
|
30193
|
-
BITS: 'isSafeInteger',
|
|
30194
|
-
};
|
|
30195
|
-
const opts = FIELD_FIELDS.reduce((map, val) => {
|
|
30196
|
-
map[val] = 'function';
|
|
30197
|
-
return map;
|
|
30198
|
-
}, initial);
|
|
30199
|
-
return (0, utils_js_1.validateObject)(field, opts);
|
|
30200
|
-
}
|
|
30201
|
-
exports.validateField = validateField;
|
|
30202
|
-
// Generic field functions
|
|
30203
|
-
function FpPow(f, num, power) {
|
|
30204
|
-
// Should have same speed as pow for bigints
|
|
30205
|
-
// TODO: benchmark!
|
|
30206
|
-
if (power < _0n)
|
|
30207
|
-
throw new Error('Expected power > 0');
|
|
30208
|
-
if (power === _0n)
|
|
30209
|
-
return f.ONE;
|
|
30210
|
-
if (power === _1n)
|
|
30211
|
-
return num;
|
|
30212
|
-
let p = f.ONE;
|
|
30213
|
-
let d = num;
|
|
30214
|
-
while (power > _0n) {
|
|
30215
|
-
if (power & _1n)
|
|
30216
|
-
p = f.mul(p, d);
|
|
30217
|
-
d = f.sqr(d);
|
|
30218
|
-
power >>= _1n;
|
|
30219
|
-
}
|
|
30220
|
-
return p;
|
|
30221
|
-
}
|
|
30222
|
-
exports.FpPow = FpPow;
|
|
30223
|
-
// 0 is non-invertible: non-batched version will throw on 0
|
|
30224
|
-
function FpInvertBatch(f, nums) {
|
|
30225
|
-
const tmp = new Array(nums.length);
|
|
30226
|
-
// Walk from first to last, multiply them by each other MOD p
|
|
30227
|
-
const lastMultiplied = nums.reduce((acc, num, i) => {
|
|
30228
|
-
if (f.is0(num))
|
|
30229
|
-
return acc;
|
|
30230
|
-
tmp[i] = acc;
|
|
30231
|
-
return f.mul(acc, num);
|
|
30232
|
-
}, f.ONE);
|
|
30233
|
-
// Invert last element
|
|
30234
|
-
const inverted = f.inv(lastMultiplied);
|
|
30235
|
-
// Walk from last to first, multiply them by inverted each other MOD p
|
|
30236
|
-
nums.reduceRight((acc, num, i) => {
|
|
30237
|
-
if (f.is0(num))
|
|
30238
|
-
return acc;
|
|
30239
|
-
tmp[i] = f.mul(acc, tmp[i]);
|
|
30240
|
-
return f.mul(acc, num);
|
|
30241
|
-
}, inverted);
|
|
30242
|
-
return tmp;
|
|
30243
|
-
}
|
|
30244
|
-
exports.FpInvertBatch = FpInvertBatch;
|
|
30245
|
-
function FpDiv(f, lhs, rhs) {
|
|
30246
|
-
return f.mul(lhs, typeof rhs === 'bigint' ? invert(rhs, f.ORDER) : f.inv(rhs));
|
|
30247
|
-
}
|
|
30248
|
-
exports.FpDiv = FpDiv;
|
|
30249
|
-
// This function returns True whenever the value x is a square in the field F.
|
|
30250
|
-
function FpIsSquare(f) {
|
|
30251
|
-
const legendreConst = (f.ORDER - _1n) / _2n; // Integer arithmetic
|
|
30252
|
-
return (x) => {
|
|
30253
|
-
const p = f.pow(x, legendreConst);
|
|
30254
|
-
return f.eql(p, f.ZERO) || f.eql(p, f.ONE);
|
|
30255
|
-
};
|
|
30256
|
-
}
|
|
30257
|
-
exports.FpIsSquare = FpIsSquare;
|
|
30258
|
-
// CURVE.n lengths
|
|
30259
|
-
function nLength(n, nBitLength) {
|
|
30260
|
-
// Bit size, byte size of CURVE.n
|
|
30261
|
-
const _nBitLength = nBitLength !== undefined ? nBitLength : n.toString(2).length;
|
|
30262
|
-
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
30263
|
-
return { nBitLength: _nBitLength, nByteLength };
|
|
30264
|
-
}
|
|
30265
|
-
exports.nLength = nLength;
|
|
30266
|
-
/**
|
|
30267
|
-
* Initializes a galois field over prime. Non-primes are not supported for now.
|
|
30268
|
-
* Do not init in loop: slow. Very fragile: always run a benchmark on change.
|
|
30269
|
-
* Major performance gains:
|
|
30270
|
-
* a) non-normalized operations like mulN instead of mul
|
|
30271
|
-
* b) `Object.freeze`
|
|
30272
|
-
* c) Same object shape: never add or remove keys
|
|
30273
|
-
* @param ORDER prime positive bigint
|
|
30274
|
-
* @param bitLen how many bits the field consumes
|
|
30275
|
-
* @param isLE (def: false) if encoding / decoding should be in little-endian
|
|
30276
|
-
* @param redef optional faster redefinitions of sqrt and other methods
|
|
30277
|
-
*/
|
|
30278
|
-
function Field(ORDER, bitLen, isLE = false, redef = {}) {
|
|
30279
|
-
if (ORDER <= _0n)
|
|
30280
|
-
throw new Error(`Expected Fp ORDER > 0, got ${ORDER}`);
|
|
30281
|
-
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen);
|
|
30282
|
-
if (BYTES > 2048)
|
|
30283
|
-
throw new Error('Field lengths over 2048 bytes are not supported');
|
|
30284
|
-
const sqrtP = FpSqrt(ORDER);
|
|
30285
|
-
const f = Object.freeze({
|
|
30286
|
-
ORDER,
|
|
30287
|
-
BITS,
|
|
30288
|
-
BYTES,
|
|
30289
|
-
MASK: (0, utils_js_1.bitMask)(BITS),
|
|
30290
|
-
ZERO: _0n,
|
|
30291
|
-
ONE: _1n,
|
|
30292
|
-
create: (num) => mod(num, ORDER),
|
|
30293
|
-
isValid: (num) => {
|
|
30294
|
-
if (typeof num !== 'bigint')
|
|
30295
|
-
throw new Error(`Invalid field element: expected bigint, got ${typeof num}`);
|
|
30296
|
-
return _0n <= num && num < ORDER; // 0 is valid element, but it's not invertible
|
|
30297
|
-
},
|
|
30298
|
-
is0: (num) => num === _0n,
|
|
30299
|
-
isOdd: (num) => (num & _1n) === _1n,
|
|
30300
|
-
neg: (num) => mod(-num, ORDER),
|
|
30301
|
-
eql: (lhs, rhs) => lhs === rhs,
|
|
30302
|
-
sqr: (num) => mod(num * num, ORDER),
|
|
30303
|
-
add: (lhs, rhs) => mod(lhs + rhs, ORDER),
|
|
30304
|
-
sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
|
|
30305
|
-
mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
|
|
30306
|
-
pow: (num, power) => FpPow(f, num, power),
|
|
30307
|
-
div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
|
|
30308
|
-
// Same as above, but doesn't normalize
|
|
30309
|
-
sqrN: (num) => num * num,
|
|
30310
|
-
addN: (lhs, rhs) => lhs + rhs,
|
|
30311
|
-
subN: (lhs, rhs) => lhs - rhs,
|
|
30312
|
-
mulN: (lhs, rhs) => lhs * rhs,
|
|
30313
|
-
inv: (num) => invert(num, ORDER),
|
|
30314
|
-
sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
|
|
30315
|
-
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
30316
|
-
// TODO: do we really need constant cmov?
|
|
30317
|
-
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
30318
|
-
cmov: (a, b, c) => (c ? b : a),
|
|
30319
|
-
toBytes: (num) => (isLE ? (0, utils_js_1.numberToBytesLE)(num, BYTES) : (0, utils_js_1.numberToBytesBE)(num, BYTES)),
|
|
30320
|
-
fromBytes: (bytes) => {
|
|
30321
|
-
if (bytes.length !== BYTES)
|
|
30322
|
-
throw new Error(`Fp.fromBytes: expected ${BYTES}, got ${bytes.length}`);
|
|
30323
|
-
return isLE ? (0, utils_js_1.bytesToNumberLE)(bytes) : (0, utils_js_1.bytesToNumberBE)(bytes);
|
|
30324
|
-
},
|
|
30325
|
-
});
|
|
30326
|
-
return Object.freeze(f);
|
|
30327
|
-
}
|
|
30328
|
-
exports.Field = Field;
|
|
30329
|
-
function FpSqrtOdd(Fp, elm) {
|
|
30330
|
-
if (!Fp.isOdd)
|
|
30331
|
-
throw new Error(`Field doesn't have isOdd`);
|
|
30332
|
-
const root = Fp.sqrt(elm);
|
|
30333
|
-
return Fp.isOdd(root) ? root : Fp.neg(root);
|
|
30334
|
-
}
|
|
30335
|
-
exports.FpSqrtOdd = FpSqrtOdd;
|
|
30336
|
-
function FpSqrtEven(Fp, elm) {
|
|
30337
|
-
if (!Fp.isOdd)
|
|
30338
|
-
throw new Error(`Field doesn't have isOdd`);
|
|
30339
|
-
const root = Fp.sqrt(elm);
|
|
30340
|
-
return Fp.isOdd(root) ? Fp.neg(root) : root;
|
|
30341
|
-
}
|
|
30342
|
-
exports.FpSqrtEven = FpSqrtEven;
|
|
30343
|
-
/**
|
|
30344
|
-
* FIPS 186 B.4.1-compliant "constant-time" private key generation utility.
|
|
30345
|
-
* Can take (n+8) or more bytes of uniform input e.g. from CSPRNG or KDF
|
|
30346
|
-
* and convert them into private scalar, with the modulo bias being neglible.
|
|
30347
|
-
* Needs at least 40 bytes of input for 32-byte private key.
|
|
30348
|
-
* https://research.kudelskisecurity.com/2020/07/28/the-definitive-guide-to-modulo-bias-and-how-to-avoid-it/
|
|
30349
|
-
* @param hash hash output from SHA3 or a similar function
|
|
30350
|
-
* @returns valid private scalar
|
|
30351
|
-
*/
|
|
30352
|
-
function hashToPrivateScalar(hash, groupOrder, isLE = false) {
|
|
30353
|
-
hash = (0, utils_js_1.ensureBytes)('privateHash', hash);
|
|
30354
|
-
const hashLen = hash.length;
|
|
30355
|
-
const minLen = nLength(groupOrder).nByteLength + 8;
|
|
30356
|
-
if (minLen < 24 || hashLen < minLen || hashLen > 1024)
|
|
30357
|
-
throw new Error(`hashToPrivateScalar: expected ${minLen}-1024 bytes of input, got ${hashLen}`);
|
|
30358
|
-
const num = isLE ? (0, utils_js_1.bytesToNumberLE)(hash) : (0, utils_js_1.bytesToNumberBE)(hash);
|
|
30359
|
-
return mod(num, groupOrder - _1n) + _1n;
|
|
30360
|
-
}
|
|
30361
|
-
exports.hashToPrivateScalar = hashToPrivateScalar;
|
|
30362
|
-
//# sourceMappingURL=modular.js.map
|
|
30363
|
-
|
|
30364
|
-
/***/ }),
|
|
30365
|
-
|
|
30366
|
-
/***/ "./node_modules/@noble/curves/abstract/utils.js":
|
|
30367
|
-
/*!******************************************************!*\
|
|
30368
|
-
!*** ./node_modules/@noble/curves/abstract/utils.js ***!
|
|
30369
|
-
\******************************************************/
|
|
30370
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
30371
|
-
|
|
30372
|
-
"use strict";
|
|
30373
|
-
|
|
30374
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
30375
|
-
exports.validateObject = exports.createHmacDrbg = exports.bitMask = exports.bitSet = exports.bitGet = exports.bitLen = exports.utf8ToBytes = exports.equalBytes = exports.concatBytes = exports.ensureBytes = exports.numberToVarBytesBE = exports.numberToBytesLE = exports.numberToBytesBE = exports.bytesToNumberLE = exports.bytesToNumberBE = exports.hexToBytes = exports.hexToNumber = exports.numberToHexUnpadded = exports.bytesToHex = void 0;
|
|
30376
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
30377
|
-
const _0n = BigInt(0);
|
|
30378
|
-
const _1n = BigInt(1);
|
|
30379
|
-
const _2n = BigInt(2);
|
|
30380
|
-
const u8a = (a) => a instanceof Uint8Array;
|
|
30381
|
-
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
|
|
30382
|
-
function bytesToHex(bytes) {
|
|
30383
|
-
if (!u8a(bytes))
|
|
30384
|
-
throw new Error('Uint8Array expected');
|
|
30385
|
-
// pre-caching improves the speed 6x
|
|
30386
|
-
let hex = '';
|
|
30387
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
30388
|
-
hex += hexes[bytes[i]];
|
|
30389
|
-
}
|
|
30390
|
-
return hex;
|
|
30391
|
-
}
|
|
30392
|
-
exports.bytesToHex = bytesToHex;
|
|
30393
|
-
function numberToHexUnpadded(num) {
|
|
30394
|
-
const hex = num.toString(16);
|
|
30395
|
-
return hex.length & 1 ? `0${hex}` : hex;
|
|
30396
|
-
}
|
|
30397
|
-
exports.numberToHexUnpadded = numberToHexUnpadded;
|
|
30398
|
-
function hexToNumber(hex) {
|
|
30399
|
-
if (typeof hex !== 'string')
|
|
30400
|
-
throw new Error('hex string expected, got ' + typeof hex);
|
|
30401
|
-
// Big Endian
|
|
30402
|
-
return BigInt(hex === '' ? '0' : `0x${hex}`);
|
|
30403
|
-
}
|
|
30404
|
-
exports.hexToNumber = hexToNumber;
|
|
30405
|
-
// Caching slows it down 2-3x
|
|
30406
|
-
function hexToBytes(hex) {
|
|
30407
|
-
if (typeof hex !== 'string')
|
|
30408
|
-
throw new Error('hex string expected, got ' + typeof hex);
|
|
30409
|
-
if (hex.length % 2)
|
|
30410
|
-
throw new Error('hex string is invalid: unpadded ' + hex.length);
|
|
30411
|
-
const array = new Uint8Array(hex.length / 2);
|
|
30412
|
-
for (let i = 0; i < array.length; i++) {
|
|
30413
|
-
const j = i * 2;
|
|
30414
|
-
const hexByte = hex.slice(j, j + 2);
|
|
30415
|
-
const byte = Number.parseInt(hexByte, 16);
|
|
30416
|
-
if (Number.isNaN(byte) || byte < 0)
|
|
30417
|
-
throw new Error('invalid byte sequence');
|
|
30418
|
-
array[i] = byte;
|
|
30419
|
-
}
|
|
30420
|
-
return array;
|
|
30421
|
-
}
|
|
30422
|
-
exports.hexToBytes = hexToBytes;
|
|
30423
|
-
// Big Endian
|
|
30424
|
-
function bytesToNumberBE(bytes) {
|
|
30425
|
-
return hexToNumber(bytesToHex(bytes));
|
|
30426
|
-
}
|
|
30427
|
-
exports.bytesToNumberBE = bytesToNumberBE;
|
|
30428
|
-
function bytesToNumberLE(bytes) {
|
|
30429
|
-
if (!u8a(bytes))
|
|
30430
|
-
throw new Error('Uint8Array expected');
|
|
30431
|
-
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
30432
|
-
}
|
|
30433
|
-
exports.bytesToNumberLE = bytesToNumberLE;
|
|
30434
|
-
const numberToBytesBE = (n, len) => hexToBytes(n.toString(16).padStart(len * 2, '0'));
|
|
30435
|
-
exports.numberToBytesBE = numberToBytesBE;
|
|
30436
|
-
const numberToBytesLE = (n, len) => (0, exports.numberToBytesBE)(n, len).reverse();
|
|
30437
|
-
exports.numberToBytesLE = numberToBytesLE;
|
|
30438
|
-
// Returns variable number bytes (minimal bigint encoding?)
|
|
30439
|
-
const numberToVarBytesBE = (n) => hexToBytes(numberToHexUnpadded(n));
|
|
30440
|
-
exports.numberToVarBytesBE = numberToVarBytesBE;
|
|
30441
|
-
function ensureBytes(title, hex, expectedLength) {
|
|
30442
|
-
let res;
|
|
30443
|
-
if (typeof hex === 'string') {
|
|
30444
|
-
try {
|
|
30445
|
-
res = hexToBytes(hex);
|
|
30446
|
-
}
|
|
30447
|
-
catch (e) {
|
|
30448
|
-
throw new Error(`${title} must be valid hex string, got "${hex}". Cause: ${e}`);
|
|
30449
|
-
}
|
|
30450
|
-
}
|
|
30451
|
-
else if (u8a(hex)) {
|
|
30452
|
-
// Uint8Array.from() instead of hash.slice() because node.js Buffer
|
|
30453
|
-
// is instance of Uint8Array, and its slice() creates **mutable** copy
|
|
30454
|
-
res = Uint8Array.from(hex);
|
|
30455
|
-
}
|
|
30456
|
-
else {
|
|
30457
|
-
throw new Error(`${title} must be hex string or Uint8Array`);
|
|
30458
|
-
}
|
|
30459
|
-
const len = res.length;
|
|
30460
|
-
if (typeof expectedLength === 'number' && len !== expectedLength)
|
|
30461
|
-
throw new Error(`${title} expected ${expectedLength} bytes, got ${len}`);
|
|
30462
|
-
return res;
|
|
30463
|
-
}
|
|
30464
|
-
exports.ensureBytes = ensureBytes;
|
|
30465
|
-
// Copies several Uint8Arrays into one.
|
|
30466
|
-
function concatBytes(...arrs) {
|
|
30467
|
-
const r = new Uint8Array(arrs.reduce((sum, a) => sum + a.length, 0));
|
|
30468
|
-
let pad = 0; // walk through each item, ensure they have proper type
|
|
30469
|
-
arrs.forEach((a) => {
|
|
30470
|
-
if (!u8a(a))
|
|
30471
|
-
throw new Error('Uint8Array expected');
|
|
30472
|
-
r.set(a, pad);
|
|
30473
|
-
pad += a.length;
|
|
30474
|
-
});
|
|
30475
|
-
return r;
|
|
30476
|
-
}
|
|
30477
|
-
exports.concatBytes = concatBytes;
|
|
30478
|
-
function equalBytes(b1, b2) {
|
|
30479
|
-
// We don't care about timing attacks here
|
|
30480
|
-
if (b1.length !== b2.length)
|
|
30481
|
-
return false;
|
|
30482
|
-
for (let i = 0; i < b1.length; i++)
|
|
30483
|
-
if (b1[i] !== b2[i])
|
|
30484
|
-
return false;
|
|
30485
|
-
return true;
|
|
30486
|
-
}
|
|
30487
|
-
exports.equalBytes = equalBytes;
|
|
30488
|
-
function utf8ToBytes(str) {
|
|
30489
|
-
if (typeof str !== 'string') {
|
|
30490
|
-
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
30491
|
-
}
|
|
30492
|
-
return new TextEncoder().encode(str);
|
|
30493
|
-
}
|
|
30494
|
-
exports.utf8ToBytes = utf8ToBytes;
|
|
30495
|
-
// Bit operations
|
|
30496
|
-
// Amount of bits inside bigint (Same as n.toString(2).length)
|
|
30497
|
-
function bitLen(n) {
|
|
30498
|
-
let len;
|
|
30499
|
-
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
30500
|
-
;
|
|
30501
|
-
return len;
|
|
30502
|
-
}
|
|
30503
|
-
exports.bitLen = bitLen;
|
|
30504
|
-
// Gets single bit at position. NOTE: first bit position is 0 (same as arrays)
|
|
30505
|
-
// Same as !!+Array.from(n.toString(2)).reverse()[pos]
|
|
30506
|
-
const bitGet = (n, pos) => (n >> BigInt(pos)) & _1n;
|
|
30507
|
-
exports.bitGet = bitGet;
|
|
30508
|
-
// Sets single bit at position
|
|
30509
|
-
const bitSet = (n, pos, value) => n | ((value ? _1n : _0n) << BigInt(pos));
|
|
30510
|
-
exports.bitSet = bitSet;
|
|
30511
|
-
// Return mask for N bits (Same as BigInt(`0b${Array(i).fill('1').join('')}`))
|
|
30512
|
-
// Not using ** operator with bigints for old engines.
|
|
30513
|
-
const bitMask = (n) => (_2n << BigInt(n - 1)) - _1n;
|
|
30514
|
-
exports.bitMask = bitMask;
|
|
30515
|
-
// DRBG
|
|
30516
|
-
const u8n = (data) => new Uint8Array(data); // creates Uint8Array
|
|
30517
|
-
const u8fr = (arr) => Uint8Array.from(arr); // another shortcut
|
|
30518
|
-
/**
|
|
30519
|
-
* Minimal HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
|
|
30520
|
-
* @returns function that will call DRBG until 2nd arg returns something meaningful
|
|
30521
|
-
* @example
|
|
30522
|
-
* const drbg = createHmacDRBG<Key>(32, 32, hmac);
|
|
30523
|
-
* drbg(seed, bytesToKey); // bytesToKey must return Key or undefined
|
|
30524
|
-
*/
|
|
30525
|
-
function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
30526
|
-
if (typeof hashLen !== 'number' || hashLen < 2)
|
|
30527
|
-
throw new Error('hashLen must be a number');
|
|
30528
|
-
if (typeof qByteLen !== 'number' || qByteLen < 2)
|
|
30529
|
-
throw new Error('qByteLen must be a number');
|
|
30530
|
-
if (typeof hmacFn !== 'function')
|
|
30531
|
-
throw new Error('hmacFn must be a function');
|
|
30532
|
-
// Step B, Step C: set hashLen to 8*ceil(hlen/8)
|
|
30533
|
-
let v = u8n(hashLen); // Minimal non-full-spec HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
|
|
30534
|
-
let k = u8n(hashLen); // Steps B and C of RFC6979 3.2: set hashLen, in our case always same
|
|
30535
|
-
let i = 0; // Iterations counter, will throw when over 1000
|
|
30536
|
-
const reset = () => {
|
|
30537
|
-
v.fill(1);
|
|
30538
|
-
k.fill(0);
|
|
30539
|
-
i = 0;
|
|
30540
|
-
};
|
|
30541
|
-
const h = (...b) => hmacFn(k, v, ...b); // hmac(k)(v, ...values)
|
|
30542
|
-
const reseed = (seed = u8n()) => {
|
|
30543
|
-
// HMAC-DRBG reseed() function. Steps D-G
|
|
30544
|
-
k = h(u8fr([0x00]), seed); // k = hmac(k || v || 0x00 || seed)
|
|
30545
|
-
v = h(); // v = hmac(k || v)
|
|
30546
|
-
if (seed.length === 0)
|
|
30547
|
-
return;
|
|
30548
|
-
k = h(u8fr([0x01]), seed); // k = hmac(k || v || 0x01 || seed)
|
|
30549
|
-
v = h(); // v = hmac(k || v)
|
|
30550
|
-
};
|
|
30551
|
-
const gen = () => {
|
|
30552
|
-
// HMAC-DRBG generate() function
|
|
30553
|
-
if (i++ >= 1000)
|
|
30554
|
-
throw new Error('drbg: tried 1000 values');
|
|
30555
|
-
let len = 0;
|
|
30556
|
-
const out = [];
|
|
30557
|
-
while (len < qByteLen) {
|
|
30558
|
-
v = h();
|
|
30559
|
-
const sl = v.slice();
|
|
30560
|
-
out.push(sl);
|
|
30561
|
-
len += v.length;
|
|
30562
|
-
}
|
|
30563
|
-
return concatBytes(...out);
|
|
30564
|
-
};
|
|
30565
|
-
const genUntil = (seed, pred) => {
|
|
30566
|
-
reset();
|
|
30567
|
-
reseed(seed); // Steps D-G
|
|
30568
|
-
let res = undefined; // Step H: grind until k is in [1..n-1]
|
|
30569
|
-
while (!(res = pred(gen())))
|
|
30570
|
-
reseed();
|
|
30571
|
-
reset();
|
|
30572
|
-
return res;
|
|
30573
|
-
};
|
|
30574
|
-
return genUntil;
|
|
30575
|
-
}
|
|
30576
|
-
exports.createHmacDrbg = createHmacDrbg;
|
|
30577
|
-
// Validating curves and fields
|
|
30578
|
-
const validatorFns = {
|
|
30579
|
-
bigint: (val) => typeof val === 'bigint',
|
|
30580
|
-
function: (val) => typeof val === 'function',
|
|
30581
|
-
boolean: (val) => typeof val === 'boolean',
|
|
30582
|
-
string: (val) => typeof val === 'string',
|
|
30583
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
30584
|
-
array: (val) => Array.isArray(val),
|
|
30585
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
30586
|
-
hash: (val) => typeof val === 'function' && Number.isSafeInteger(val.outputLen),
|
|
30587
|
-
};
|
|
30588
|
-
// type Record<K extends string | number | symbol, T> = { [P in K]: T; }
|
|
30589
|
-
function validateObject(object, validators, optValidators = {}) {
|
|
30590
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
30591
|
-
const checkVal = validatorFns[type];
|
|
30592
|
-
if (typeof checkVal !== 'function')
|
|
30593
|
-
throw new Error(`Invalid validator "${type}", expected function`);
|
|
30594
|
-
const val = object[fieldName];
|
|
30595
|
-
if (isOptional && val === undefined)
|
|
30596
|
-
return;
|
|
30597
|
-
if (!checkVal(val, object)) {
|
|
30598
|
-
throw new Error(`Invalid param ${String(fieldName)}=${val} (${typeof val}), expected ${type}`);
|
|
30599
|
-
}
|
|
30600
|
-
};
|
|
30601
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
30602
|
-
checkField(fieldName, type, false);
|
|
30603
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
30604
|
-
checkField(fieldName, type, true);
|
|
30605
|
-
return object;
|
|
30606
|
-
}
|
|
30607
|
-
exports.validateObject = validateObject;
|
|
30608
|
-
// validate type tests
|
|
30609
|
-
// const o: { a: number; b: number; c: number } = { a: 1, b: 5, c: 6 };
|
|
30610
|
-
// const z0 = validateObject(o, { a: 'isSafeInteger' }, { c: 'bigint' }); // Ok!
|
|
30611
|
-
// // Should fail type-check
|
|
30612
|
-
// const z1 = validateObject(o, { a: 'tmp' }, { c: 'zz' });
|
|
30613
|
-
// const z2 = validateObject(o, { a: 'isSafeInteger' }, { c: 'zz' });
|
|
30614
|
-
// const z3 = validateObject(o, { test: 'boolean', z: 'bug' });
|
|
30615
|
-
// const z4 = validateObject(o, { a: 'boolean', z: 'bug' });
|
|
30616
|
-
//# sourceMappingURL=utils.js.map
|
|
30617
|
-
|
|
30618
|
-
/***/ }),
|
|
30619
|
-
|
|
30620
|
-
/***/ "./node_modules/@noble/curves/abstract/weierstrass.js":
|
|
30621
|
-
/*!************************************************************!*\
|
|
30622
|
-
!*** ./node_modules/@noble/curves/abstract/weierstrass.js ***!
|
|
30623
|
-
\************************************************************/
|
|
30624
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
30625
|
-
|
|
30626
|
-
"use strict";
|
|
30627
|
-
|
|
30628
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
30629
|
-
exports.mapToCurveSimpleSWU = exports.SWUFpSqrtRatio = exports.weierstrass = exports.weierstrassPoints = exports.DER = void 0;
|
|
30630
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
30631
|
-
// Short Weierstrass curve. The formula is: y² = x³ + ax + b
|
|
30632
|
-
const mod = __webpack_require__(/*! ./modular.js */ "./node_modules/@noble/curves/abstract/modular.js");
|
|
30633
|
-
const ut = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/curves/abstract/utils.js");
|
|
30634
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/curves/abstract/utils.js");
|
|
30635
|
-
const curve_js_1 = __webpack_require__(/*! ./curve.js */ "./node_modules/@noble/curves/abstract/curve.js");
|
|
30636
|
-
function validatePointOpts(curve) {
|
|
30637
|
-
const opts = (0, curve_js_1.validateBasic)(curve);
|
|
30638
|
-
ut.validateObject(opts, {
|
|
30639
|
-
a: 'field',
|
|
30640
|
-
b: 'field',
|
|
30641
|
-
}, {
|
|
30642
|
-
allowedPrivateKeyLengths: 'array',
|
|
30643
|
-
wrapPrivateKey: 'boolean',
|
|
30644
|
-
isTorsionFree: 'function',
|
|
30645
|
-
clearCofactor: 'function',
|
|
30646
|
-
allowInfinityPoint: 'boolean',
|
|
30647
|
-
fromBytes: 'function',
|
|
30648
|
-
toBytes: 'function',
|
|
30649
|
-
});
|
|
30650
|
-
const { endo, Fp, a } = opts;
|
|
30651
|
-
if (endo) {
|
|
30652
|
-
if (!Fp.eql(a, Fp.ZERO)) {
|
|
30653
|
-
throw new Error('Endomorphism can only be defined for Koblitz curves that have a=0');
|
|
30654
|
-
}
|
|
30655
|
-
if (typeof endo !== 'object' ||
|
|
30656
|
-
typeof endo.beta !== 'bigint' ||
|
|
30657
|
-
typeof endo.splitScalar !== 'function') {
|
|
30658
|
-
throw new Error('Expected endomorphism with beta: bigint and splitScalar: function');
|
|
30659
|
-
}
|
|
30660
|
-
}
|
|
30661
|
-
return Object.freeze({ ...opts });
|
|
30662
|
-
}
|
|
30663
|
-
// ASN.1 DER encoding utilities
|
|
30664
|
-
const { bytesToNumberBE: b2n, hexToBytes: h2b } = ut;
|
|
30665
|
-
exports.DER = {
|
|
30666
|
-
// asn.1 DER encoding utils
|
|
30667
|
-
Err: class DERErr extends Error {
|
|
30668
|
-
constructor(m = '') {
|
|
30669
|
-
super(m);
|
|
30670
|
-
}
|
|
30671
|
-
},
|
|
30672
|
-
_parseInt(data) {
|
|
30673
|
-
const { Err: E } = exports.DER;
|
|
30674
|
-
if (data.length < 2 || data[0] !== 0x02)
|
|
30675
|
-
throw new E('Invalid signature integer tag');
|
|
30676
|
-
const len = data[1];
|
|
30677
|
-
const res = data.subarray(2, len + 2);
|
|
30678
|
-
if (!len || res.length !== len)
|
|
30679
|
-
throw new E('Invalid signature integer: wrong length');
|
|
30680
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
30681
|
-
// since we always use positive integers here. It must always be empty:
|
|
30682
|
-
// - add zero byte if exists
|
|
30683
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
30684
|
-
if (res[0] & 0b10000000)
|
|
30685
|
-
throw new E('Invalid signature integer: negative');
|
|
30686
|
-
if (res[0] === 0x00 && !(res[1] & 0b10000000))
|
|
30687
|
-
throw new E('Invalid signature integer: unnecessary leading zero');
|
|
30688
|
-
return { d: b2n(res), l: data.subarray(len + 2) }; // d is data, l is left
|
|
30689
|
-
},
|
|
30690
|
-
toSig(hex) {
|
|
30691
|
-
// parse DER signature
|
|
30692
|
-
const { Err: E } = exports.DER;
|
|
30693
|
-
const data = typeof hex === 'string' ? h2b(hex) : hex;
|
|
30694
|
-
if (!(data instanceof Uint8Array))
|
|
30695
|
-
throw new Error('ui8a expected');
|
|
30696
|
-
let l = data.length;
|
|
30697
|
-
if (l < 2 || data[0] != 0x30)
|
|
30698
|
-
throw new E('Invalid signature tag');
|
|
30699
|
-
if (data[1] !== l - 2)
|
|
30700
|
-
throw new E('Invalid signature: incorrect length');
|
|
30701
|
-
const { d: r, l: sBytes } = exports.DER._parseInt(data.subarray(2));
|
|
30702
|
-
const { d: s, l: rBytesLeft } = exports.DER._parseInt(sBytes);
|
|
30703
|
-
if (rBytesLeft.length)
|
|
30704
|
-
throw new E('Invalid signature: left bytes after parsing');
|
|
30705
|
-
return { r, s };
|
|
30706
|
-
},
|
|
30707
|
-
hexFromSig(sig) {
|
|
30708
|
-
// Add leading zero if first byte has negative bit enabled. More details in '_parseInt'
|
|
30709
|
-
const slice = (s) => (Number.parseInt(s[0], 16) & 0b1000 ? '00' + s : s);
|
|
30710
|
-
const h = (num) => {
|
|
30711
|
-
const hex = num.toString(16);
|
|
30712
|
-
return hex.length & 1 ? `0${hex}` : hex;
|
|
30713
|
-
};
|
|
30714
|
-
const s = slice(h(sig.s));
|
|
30715
|
-
const r = slice(h(sig.r));
|
|
30716
|
-
const shl = s.length / 2;
|
|
30717
|
-
const rhl = r.length / 2;
|
|
30718
|
-
const sl = h(shl);
|
|
30719
|
-
const rl = h(rhl);
|
|
30720
|
-
return `30${h(rhl + shl + 4)}02${rl}${r}02${sl}${s}`;
|
|
30721
|
-
},
|
|
30722
|
-
};
|
|
30723
|
-
// Be friendly to bad ECMAScript parsers by not using bigint literals
|
|
30724
|
-
// prettier-ignore
|
|
30725
|
-
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4);
|
|
30726
|
-
function weierstrassPoints(opts) {
|
|
30727
|
-
const CURVE = validatePointOpts(opts);
|
|
30728
|
-
const { Fp } = CURVE; // All curves has same field / group length as for now, but they can differ
|
|
30729
|
-
const toBytes = CURVE.toBytes ||
|
|
30730
|
-
((c, point, isCompressed) => {
|
|
30731
|
-
const a = point.toAffine();
|
|
30732
|
-
return ut.concatBytes(Uint8Array.from([0x04]), Fp.toBytes(a.x), Fp.toBytes(a.y));
|
|
30733
|
-
});
|
|
30734
|
-
const fromBytes = CURVE.fromBytes ||
|
|
30735
|
-
((bytes) => {
|
|
30736
|
-
// const head = bytes[0];
|
|
30737
|
-
const tail = bytes.subarray(1);
|
|
30738
|
-
// if (head !== 0x04) throw new Error('Only non-compressed encoding is supported');
|
|
30739
|
-
const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
|
|
30740
|
-
const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
|
|
30741
|
-
return { x, y };
|
|
30742
|
-
});
|
|
30743
|
-
/**
|
|
30744
|
-
* y² = x³ + ax + b: Short weierstrass curve formula
|
|
30745
|
-
* @returns y²
|
|
30746
|
-
*/
|
|
30747
|
-
function weierstrassEquation(x) {
|
|
30748
|
-
const { a, b } = CURVE;
|
|
30749
|
-
const x2 = Fp.sqr(x); // x * x
|
|
30750
|
-
const x3 = Fp.mul(x2, x); // x2 * x
|
|
30751
|
-
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b); // x3 + a * x + b
|
|
30752
|
-
}
|
|
30753
|
-
// Validate whether the passed curve params are valid.
|
|
30754
|
-
// We check if curve equation works for generator point.
|
|
30755
|
-
// `assertValidity()` won't work: `isTorsionFree()` is not available at this point in bls12-381.
|
|
30756
|
-
// ProjectivePoint class has not been initialized yet.
|
|
30757
|
-
if (!Fp.eql(Fp.sqr(CURVE.Gy), weierstrassEquation(CURVE.Gx)))
|
|
30758
|
-
throw new Error('bad generator point: equation left != right');
|
|
30759
|
-
// Valid group elements reside in range 1..n-1
|
|
30760
|
-
function isWithinCurveOrder(num) {
|
|
30761
|
-
return typeof num === 'bigint' && _0n < num && num < CURVE.n;
|
|
30762
|
-
}
|
|
30763
|
-
function assertGE(num) {
|
|
30764
|
-
if (!isWithinCurveOrder(num))
|
|
30765
|
-
throw new Error('Expected valid bigint: 0 < bigint < curve.n');
|
|
30766
|
-
}
|
|
30767
|
-
// Validates if priv key is valid and converts it to bigint.
|
|
30768
|
-
// Supports options allowedPrivateKeyLengths and wrapPrivateKey.
|
|
30769
|
-
function normPrivateKeyToScalar(key) {
|
|
30770
|
-
const { allowedPrivateKeyLengths: lengths, nByteLength, wrapPrivateKey, n } = CURVE;
|
|
30771
|
-
if (lengths && typeof key !== 'bigint') {
|
|
30772
|
-
if (key instanceof Uint8Array)
|
|
30773
|
-
key = ut.bytesToHex(key);
|
|
30774
|
-
// Normalize to hex string, pad. E.g. P521 would norm 130-132 char hex to 132-char bytes
|
|
30775
|
-
if (typeof key !== 'string' || !lengths.includes(key.length))
|
|
30776
|
-
throw new Error('Invalid key');
|
|
30777
|
-
key = key.padStart(nByteLength * 2, '0');
|
|
30778
|
-
}
|
|
30779
|
-
let num;
|
|
30780
|
-
try {
|
|
30781
|
-
num =
|
|
30782
|
-
typeof key === 'bigint'
|
|
30783
|
-
? key
|
|
30784
|
-
: ut.bytesToNumberBE((0, utils_js_1.ensureBytes)('private key', key, nByteLength));
|
|
30785
|
-
}
|
|
30786
|
-
catch (error) {
|
|
30787
|
-
throw new Error(`private key must be ${nByteLength} bytes, hex or bigint, not ${typeof key}`);
|
|
30788
|
-
}
|
|
30789
|
-
if (wrapPrivateKey)
|
|
30790
|
-
num = mod.mod(num, n); // disabled by default, enabled for BLS
|
|
30791
|
-
assertGE(num); // num in range [1..N-1]
|
|
30792
|
-
return num;
|
|
30793
|
-
}
|
|
30794
|
-
const pointPrecomputes = new Map();
|
|
30795
|
-
function assertPrjPoint(other) {
|
|
30796
|
-
if (!(other instanceof Point))
|
|
30797
|
-
throw new Error('ProjectivePoint expected');
|
|
30798
|
-
}
|
|
30799
|
-
/**
|
|
30800
|
-
* Projective Point works in 3d / projective (homogeneous) coordinates: (x, y, z) ∋ (x=x/z, y=y/z)
|
|
30801
|
-
* Default Point works in 2d / affine coordinates: (x, y)
|
|
30802
|
-
* We're doing calculations in projective, because its operations don't require costly inversion.
|
|
30803
|
-
*/
|
|
30804
|
-
class Point {
|
|
30805
|
-
constructor(px, py, pz) {
|
|
30806
|
-
this.px = px;
|
|
30807
|
-
this.py = py;
|
|
30808
|
-
this.pz = pz;
|
|
30809
|
-
if (px == null || !Fp.isValid(px))
|
|
30810
|
-
throw new Error('x required');
|
|
30811
|
-
if (py == null || !Fp.isValid(py))
|
|
30812
|
-
throw new Error('y required');
|
|
30813
|
-
if (pz == null || !Fp.isValid(pz))
|
|
30814
|
-
throw new Error('z required');
|
|
30815
|
-
}
|
|
30816
|
-
// Does not validate if the point is on-curve.
|
|
30817
|
-
// Use fromHex instead, or call assertValidity() later.
|
|
30818
|
-
static fromAffine(p) {
|
|
30819
|
-
const { x, y } = p || {};
|
|
30820
|
-
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
30821
|
-
throw new Error('invalid affine point');
|
|
30822
|
-
if (p instanceof Point)
|
|
30823
|
-
throw new Error('projective point not allowed');
|
|
30824
|
-
const is0 = (i) => Fp.eql(i, Fp.ZERO);
|
|
30825
|
-
// fromAffine(x:0, y:0) would produce (x:0, y:0, z:1), but we need (x:0, y:1, z:0)
|
|
30826
|
-
if (is0(x) && is0(y))
|
|
30827
|
-
return Point.ZERO;
|
|
30828
|
-
return new Point(x, y, Fp.ONE);
|
|
30829
|
-
}
|
|
30830
|
-
get x() {
|
|
30831
|
-
return this.toAffine().x;
|
|
30832
|
-
}
|
|
30833
|
-
get y() {
|
|
30834
|
-
return this.toAffine().y;
|
|
30835
|
-
}
|
|
30836
|
-
/**
|
|
30837
|
-
* Takes a bunch of Projective Points but executes only one
|
|
30838
|
-
* inversion on all of them. Inversion is very slow operation,
|
|
30839
|
-
* so this improves performance massively.
|
|
30840
|
-
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
30841
|
-
*/
|
|
30842
|
-
static normalizeZ(points) {
|
|
30843
|
-
const toInv = Fp.invertBatch(points.map((p) => p.pz));
|
|
30844
|
-
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
30845
|
-
}
|
|
30846
|
-
/**
|
|
30847
|
-
* Converts hash string or Uint8Array to Point.
|
|
30848
|
-
* @param hex short/long ECDSA hex
|
|
30849
|
-
*/
|
|
30850
|
-
static fromHex(hex) {
|
|
30851
|
-
const P = Point.fromAffine(fromBytes((0, utils_js_1.ensureBytes)('pointHex', hex)));
|
|
30852
|
-
P.assertValidity();
|
|
30853
|
-
return P;
|
|
30854
|
-
}
|
|
30855
|
-
// Multiplies generator point by privateKey.
|
|
30856
|
-
static fromPrivateKey(privateKey) {
|
|
30857
|
-
return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
30858
|
-
}
|
|
30859
|
-
// "Private method", don't use it directly
|
|
30860
|
-
_setWindowSize(windowSize) {
|
|
30861
|
-
this._WINDOW_SIZE = windowSize;
|
|
30862
|
-
pointPrecomputes.delete(this);
|
|
30863
|
-
}
|
|
30864
|
-
// A point on curve is valid if it conforms to equation.
|
|
30865
|
-
assertValidity() {
|
|
30866
|
-
// Zero is valid point too!
|
|
30867
|
-
if (this.is0()) {
|
|
30868
|
-
if (CURVE.allowInfinityPoint)
|
|
30869
|
-
return;
|
|
30870
|
-
throw new Error('bad point: ZERO');
|
|
30871
|
-
}
|
|
30872
|
-
// Some 3rd-party test vectors require different wording between here & `fromCompressedHex`
|
|
30873
|
-
const { x, y } = this.toAffine();
|
|
30874
|
-
// Check if x, y are valid field elements
|
|
30875
|
-
if (!Fp.isValid(x) || !Fp.isValid(y))
|
|
30876
|
-
throw new Error('bad point: x or y not FE');
|
|
30877
|
-
const left = Fp.sqr(y); // y²
|
|
30878
|
-
const right = weierstrassEquation(x); // x³ + ax + b
|
|
30879
|
-
if (!Fp.eql(left, right))
|
|
30880
|
-
throw new Error('bad point: equation left != right');
|
|
30881
|
-
if (!this.isTorsionFree())
|
|
30882
|
-
throw new Error('bad point: not in prime-order subgroup');
|
|
30883
|
-
}
|
|
30884
|
-
hasEvenY() {
|
|
30885
|
-
const { y } = this.toAffine();
|
|
30886
|
-
if (Fp.isOdd)
|
|
30887
|
-
return !Fp.isOdd(y);
|
|
30888
|
-
throw new Error("Field doesn't support isOdd");
|
|
30889
|
-
}
|
|
30890
|
-
/**
|
|
30891
|
-
* Compare one point to another.
|
|
30892
|
-
*/
|
|
30893
|
-
equals(other) {
|
|
30894
|
-
assertPrjPoint(other);
|
|
30895
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
30896
|
-
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
30897
|
-
const U1 = Fp.eql(Fp.mul(X1, Z2), Fp.mul(X2, Z1));
|
|
30898
|
-
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
30899
|
-
return U1 && U2;
|
|
30900
|
-
}
|
|
30901
|
-
/**
|
|
30902
|
-
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
30903
|
-
*/
|
|
30904
|
-
negate() {
|
|
30905
|
-
return new Point(this.px, Fp.neg(this.py), this.pz);
|
|
30906
|
-
}
|
|
30907
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
30908
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
30909
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
30910
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
30911
|
-
double() {
|
|
30912
|
-
const { a, b } = CURVE;
|
|
30913
|
-
const b3 = Fp.mul(b, _3n);
|
|
30914
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
30915
|
-
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO; // prettier-ignore
|
|
30916
|
-
let t0 = Fp.mul(X1, X1); // step 1
|
|
30917
|
-
let t1 = Fp.mul(Y1, Y1);
|
|
30918
|
-
let t2 = Fp.mul(Z1, Z1);
|
|
30919
|
-
let t3 = Fp.mul(X1, Y1);
|
|
30920
|
-
t3 = Fp.add(t3, t3); // step 5
|
|
30921
|
-
Z3 = Fp.mul(X1, Z1);
|
|
30922
|
-
Z3 = Fp.add(Z3, Z3);
|
|
30923
|
-
X3 = Fp.mul(a, Z3);
|
|
30924
|
-
Y3 = Fp.mul(b3, t2);
|
|
30925
|
-
Y3 = Fp.add(X3, Y3); // step 10
|
|
30926
|
-
X3 = Fp.sub(t1, Y3);
|
|
30927
|
-
Y3 = Fp.add(t1, Y3);
|
|
30928
|
-
Y3 = Fp.mul(X3, Y3);
|
|
30929
|
-
X3 = Fp.mul(t3, X3);
|
|
30930
|
-
Z3 = Fp.mul(b3, Z3); // step 15
|
|
30931
|
-
t2 = Fp.mul(a, t2);
|
|
30932
|
-
t3 = Fp.sub(t0, t2);
|
|
30933
|
-
t3 = Fp.mul(a, t3);
|
|
30934
|
-
t3 = Fp.add(t3, Z3);
|
|
30935
|
-
Z3 = Fp.add(t0, t0); // step 20
|
|
30936
|
-
t0 = Fp.add(Z3, t0);
|
|
30937
|
-
t0 = Fp.add(t0, t2);
|
|
30938
|
-
t0 = Fp.mul(t0, t3);
|
|
30939
|
-
Y3 = Fp.add(Y3, t0);
|
|
30940
|
-
t2 = Fp.mul(Y1, Z1); // step 25
|
|
30941
|
-
t2 = Fp.add(t2, t2);
|
|
30942
|
-
t0 = Fp.mul(t2, t3);
|
|
30943
|
-
X3 = Fp.sub(X3, t0);
|
|
30944
|
-
Z3 = Fp.mul(t2, t1);
|
|
30945
|
-
Z3 = Fp.add(Z3, Z3); // step 30
|
|
30946
|
-
Z3 = Fp.add(Z3, Z3);
|
|
30947
|
-
return new Point(X3, Y3, Z3);
|
|
30948
|
-
}
|
|
30949
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
30950
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
30951
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
30952
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
30953
|
-
add(other) {
|
|
30954
|
-
assertPrjPoint(other);
|
|
30955
|
-
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
30956
|
-
const { px: X2, py: Y2, pz: Z2 } = other;
|
|
30957
|
-
let X3 = Fp.ZERO, Y3 = Fp.ZERO, Z3 = Fp.ZERO; // prettier-ignore
|
|
30958
|
-
const a = CURVE.a;
|
|
30959
|
-
const b3 = Fp.mul(CURVE.b, _3n);
|
|
30960
|
-
let t0 = Fp.mul(X1, X2); // step 1
|
|
30961
|
-
let t1 = Fp.mul(Y1, Y2);
|
|
30962
|
-
let t2 = Fp.mul(Z1, Z2);
|
|
30963
|
-
let t3 = Fp.add(X1, Y1);
|
|
30964
|
-
let t4 = Fp.add(X2, Y2); // step 5
|
|
30965
|
-
t3 = Fp.mul(t3, t4);
|
|
30966
|
-
t4 = Fp.add(t0, t1);
|
|
30967
|
-
t3 = Fp.sub(t3, t4);
|
|
30968
|
-
t4 = Fp.add(X1, Z1);
|
|
30969
|
-
let t5 = Fp.add(X2, Z2); // step 10
|
|
30970
|
-
t4 = Fp.mul(t4, t5);
|
|
30971
|
-
t5 = Fp.add(t0, t2);
|
|
30972
|
-
t4 = Fp.sub(t4, t5);
|
|
30973
|
-
t5 = Fp.add(Y1, Z1);
|
|
30974
|
-
X3 = Fp.add(Y2, Z2); // step 15
|
|
30975
|
-
t5 = Fp.mul(t5, X3);
|
|
30976
|
-
X3 = Fp.add(t1, t2);
|
|
30977
|
-
t5 = Fp.sub(t5, X3);
|
|
30978
|
-
Z3 = Fp.mul(a, t4);
|
|
30979
|
-
X3 = Fp.mul(b3, t2); // step 20
|
|
30980
|
-
Z3 = Fp.add(X3, Z3);
|
|
30981
|
-
X3 = Fp.sub(t1, Z3);
|
|
30982
|
-
Z3 = Fp.add(t1, Z3);
|
|
30983
|
-
Y3 = Fp.mul(X3, Z3);
|
|
30984
|
-
t1 = Fp.add(t0, t0); // step 25
|
|
30985
|
-
t1 = Fp.add(t1, t0);
|
|
30986
|
-
t2 = Fp.mul(a, t2);
|
|
30987
|
-
t4 = Fp.mul(b3, t4);
|
|
30988
|
-
t1 = Fp.add(t1, t2);
|
|
30989
|
-
t2 = Fp.sub(t0, t2); // step 30
|
|
30990
|
-
t2 = Fp.mul(a, t2);
|
|
30991
|
-
t4 = Fp.add(t4, t2);
|
|
30992
|
-
t0 = Fp.mul(t1, t4);
|
|
30993
|
-
Y3 = Fp.add(Y3, t0);
|
|
30994
|
-
t0 = Fp.mul(t5, t4); // step 35
|
|
30995
|
-
X3 = Fp.mul(t3, X3);
|
|
30996
|
-
X3 = Fp.sub(X3, t0);
|
|
30997
|
-
t0 = Fp.mul(t3, t1);
|
|
30998
|
-
Z3 = Fp.mul(t5, Z3);
|
|
30999
|
-
Z3 = Fp.add(Z3, t0); // step 40
|
|
31000
|
-
return new Point(X3, Y3, Z3);
|
|
31001
|
-
}
|
|
31002
|
-
subtract(other) {
|
|
31003
|
-
return this.add(other.negate());
|
|
31004
|
-
}
|
|
31005
|
-
is0() {
|
|
31006
|
-
return this.equals(Point.ZERO);
|
|
31007
|
-
}
|
|
31008
|
-
wNAF(n) {
|
|
31009
|
-
return wnaf.wNAFCached(this, pointPrecomputes, n, (comp) => {
|
|
31010
|
-
const toInv = Fp.invertBatch(comp.map((p) => p.pz));
|
|
31011
|
-
return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
31012
|
-
});
|
|
31013
|
-
}
|
|
31014
|
-
/**
|
|
31015
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
31016
|
-
* It's faster, but should only be used when you don't care about
|
|
31017
|
-
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
31018
|
-
*/
|
|
31019
|
-
multiplyUnsafe(n) {
|
|
31020
|
-
const I = Point.ZERO;
|
|
31021
|
-
if (n === _0n)
|
|
31022
|
-
return I;
|
|
31023
|
-
assertGE(n); // Will throw on 0
|
|
31024
|
-
if (n === _1n)
|
|
31025
|
-
return this;
|
|
31026
|
-
const { endo } = CURVE;
|
|
31027
|
-
if (!endo)
|
|
31028
|
-
return wnaf.unsafeLadder(this, n);
|
|
31029
|
-
// Apply endomorphism
|
|
31030
|
-
let { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
|
|
31031
|
-
let k1p = I;
|
|
31032
|
-
let k2p = I;
|
|
31033
|
-
let d = this;
|
|
31034
|
-
while (k1 > _0n || k2 > _0n) {
|
|
31035
|
-
if (k1 & _1n)
|
|
31036
|
-
k1p = k1p.add(d);
|
|
31037
|
-
if (k2 & _1n)
|
|
31038
|
-
k2p = k2p.add(d);
|
|
31039
|
-
d = d.double();
|
|
31040
|
-
k1 >>= _1n;
|
|
31041
|
-
k2 >>= _1n;
|
|
31042
|
-
}
|
|
31043
|
-
if (k1neg)
|
|
31044
|
-
k1p = k1p.negate();
|
|
31045
|
-
if (k2neg)
|
|
31046
|
-
k2p = k2p.negate();
|
|
31047
|
-
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
31048
|
-
return k1p.add(k2p);
|
|
31049
|
-
}
|
|
31050
|
-
/**
|
|
31051
|
-
* Constant time multiplication.
|
|
31052
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
31053
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
31054
|
-
* Uses precomputes when available.
|
|
31055
|
-
* Uses endomorphism for Koblitz curves.
|
|
31056
|
-
* @param scalar by which the point would be multiplied
|
|
31057
|
-
* @returns New point
|
|
31058
|
-
*/
|
|
31059
|
-
multiply(scalar) {
|
|
31060
|
-
assertGE(scalar);
|
|
31061
|
-
let n = scalar;
|
|
31062
|
-
let point, fake; // Fake point is used to const-time mult
|
|
31063
|
-
const { endo } = CURVE;
|
|
31064
|
-
if (endo) {
|
|
31065
|
-
const { k1neg, k1, k2neg, k2 } = endo.splitScalar(n);
|
|
31066
|
-
let { p: k1p, f: f1p } = this.wNAF(k1);
|
|
31067
|
-
let { p: k2p, f: f2p } = this.wNAF(k2);
|
|
31068
|
-
k1p = wnaf.constTimeNegate(k1neg, k1p);
|
|
31069
|
-
k2p = wnaf.constTimeNegate(k2neg, k2p);
|
|
31070
|
-
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
31071
|
-
point = k1p.add(k2p);
|
|
31072
|
-
fake = f1p.add(f2p);
|
|
31073
|
-
}
|
|
31074
|
-
else {
|
|
31075
|
-
const { p, f } = this.wNAF(n);
|
|
31076
|
-
point = p;
|
|
31077
|
-
fake = f;
|
|
31078
|
-
}
|
|
31079
|
-
// Normalize `z` for both points, but return only real one
|
|
31080
|
-
return Point.normalizeZ([point, fake])[0];
|
|
31081
|
-
}
|
|
31082
|
-
/**
|
|
31083
|
-
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
31084
|
-
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
31085
|
-
* The trick could be useful if both P and Q are not G (not in our case).
|
|
31086
|
-
* @returns non-zero affine point
|
|
31087
|
-
*/
|
|
31088
|
-
multiplyAndAddUnsafe(Q, a, b) {
|
|
31089
|
-
const G = Point.BASE; // No Strauss-Shamir trick: we have 10% faster G precomputes
|
|
31090
|
-
const mul = (P, a // Select faster multiply() method
|
|
31091
|
-
) => (a === _0n || a === _1n || !P.equals(G) ? P.multiplyUnsafe(a) : P.multiply(a));
|
|
31092
|
-
const sum = mul(this, a).add(mul(Q, b));
|
|
31093
|
-
return sum.is0() ? undefined : sum;
|
|
31094
|
-
}
|
|
31095
|
-
// Converts Projective point to affine (x, y) coordinates.
|
|
31096
|
-
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
31097
|
-
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
31098
|
-
toAffine(iz) {
|
|
31099
|
-
const { px: x, py: y, pz: z } = this;
|
|
31100
|
-
const is0 = this.is0();
|
|
31101
|
-
// If invZ was 0, we return zero point. However we still want to execute
|
|
31102
|
-
// all operations, so we replace invZ with a random number, 1.
|
|
31103
|
-
if (iz == null)
|
|
31104
|
-
iz = is0 ? Fp.ONE : Fp.inv(z);
|
|
31105
|
-
const ax = Fp.mul(x, iz);
|
|
31106
|
-
const ay = Fp.mul(y, iz);
|
|
31107
|
-
const zz = Fp.mul(z, iz);
|
|
31108
|
-
if (is0)
|
|
31109
|
-
return { x: Fp.ZERO, y: Fp.ZERO };
|
|
31110
|
-
if (!Fp.eql(zz, Fp.ONE))
|
|
31111
|
-
throw new Error('invZ was invalid');
|
|
31112
|
-
return { x: ax, y: ay };
|
|
31113
|
-
}
|
|
31114
|
-
isTorsionFree() {
|
|
31115
|
-
const { h: cofactor, isTorsionFree } = CURVE;
|
|
31116
|
-
if (cofactor === _1n)
|
|
31117
|
-
return true; // No subgroups, always torsion-free
|
|
31118
|
-
if (isTorsionFree)
|
|
31119
|
-
return isTorsionFree(Point, this);
|
|
31120
|
-
throw new Error('isTorsionFree() has not been declared for the elliptic curve');
|
|
31121
|
-
}
|
|
31122
|
-
clearCofactor() {
|
|
31123
|
-
const { h: cofactor, clearCofactor } = CURVE;
|
|
31124
|
-
if (cofactor === _1n)
|
|
31125
|
-
return this; // Fast-path
|
|
31126
|
-
if (clearCofactor)
|
|
31127
|
-
return clearCofactor(Point, this);
|
|
31128
|
-
return this.multiplyUnsafe(CURVE.h);
|
|
31129
|
-
}
|
|
31130
|
-
toRawBytes(isCompressed = true) {
|
|
31131
|
-
this.assertValidity();
|
|
31132
|
-
return toBytes(Point, this, isCompressed);
|
|
31133
|
-
}
|
|
31134
|
-
toHex(isCompressed = true) {
|
|
31135
|
-
return ut.bytesToHex(this.toRawBytes(isCompressed));
|
|
31136
|
-
}
|
|
31137
|
-
}
|
|
31138
|
-
Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
31139
|
-
Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO);
|
|
31140
|
-
const _bits = CURVE.nBitLength;
|
|
31141
|
-
const wnaf = (0, curve_js_1.wNAF)(Point, CURVE.endo ? Math.ceil(_bits / 2) : _bits);
|
|
31142
|
-
// Validate if generator point is on curve
|
|
31143
|
-
return {
|
|
31144
|
-
CURVE,
|
|
31145
|
-
ProjectivePoint: Point,
|
|
31146
|
-
normPrivateKeyToScalar,
|
|
31147
|
-
weierstrassEquation,
|
|
31148
|
-
isWithinCurveOrder,
|
|
31149
|
-
};
|
|
31150
|
-
}
|
|
31151
|
-
exports.weierstrassPoints = weierstrassPoints;
|
|
31152
|
-
function validateOpts(curve) {
|
|
31153
|
-
const opts = (0, curve_js_1.validateBasic)(curve);
|
|
31154
|
-
ut.validateObject(opts, {
|
|
31155
|
-
hash: 'hash',
|
|
31156
|
-
hmac: 'function',
|
|
31157
|
-
randomBytes: 'function',
|
|
31158
|
-
}, {
|
|
31159
|
-
bits2int: 'function',
|
|
31160
|
-
bits2int_modN: 'function',
|
|
31161
|
-
lowS: 'boolean',
|
|
31162
|
-
});
|
|
31163
|
-
return Object.freeze({ lowS: true, ...opts });
|
|
31164
|
-
}
|
|
31165
|
-
function weierstrass(curveDef) {
|
|
31166
|
-
const CURVE = validateOpts(curveDef);
|
|
31167
|
-
const { Fp, n: CURVE_ORDER } = CURVE;
|
|
31168
|
-
const compressedLen = Fp.BYTES + 1; // e.g. 33 for 32
|
|
31169
|
-
const uncompressedLen = 2 * Fp.BYTES + 1; // e.g. 65 for 32
|
|
31170
|
-
function isValidFieldElement(num) {
|
|
31171
|
-
return _0n < num && num < Fp.ORDER; // 0 is banned since it's not invertible FE
|
|
31172
|
-
}
|
|
31173
|
-
function modN(a) {
|
|
31174
|
-
return mod.mod(a, CURVE_ORDER);
|
|
31175
|
-
}
|
|
31176
|
-
function invN(a) {
|
|
31177
|
-
return mod.invert(a, CURVE_ORDER);
|
|
31178
|
-
}
|
|
31179
|
-
const { ProjectivePoint: Point, normPrivateKeyToScalar, weierstrassEquation, isWithinCurveOrder, } = weierstrassPoints({
|
|
31180
|
-
...CURVE,
|
|
31181
|
-
toBytes(c, point, isCompressed) {
|
|
31182
|
-
const a = point.toAffine();
|
|
31183
|
-
const x = Fp.toBytes(a.x);
|
|
31184
|
-
const cat = ut.concatBytes;
|
|
31185
|
-
if (isCompressed) {
|
|
31186
|
-
return cat(Uint8Array.from([point.hasEvenY() ? 0x02 : 0x03]), x);
|
|
31187
|
-
}
|
|
31188
|
-
else {
|
|
31189
|
-
return cat(Uint8Array.from([0x04]), x, Fp.toBytes(a.y));
|
|
31190
|
-
}
|
|
31191
|
-
},
|
|
31192
|
-
fromBytes(bytes) {
|
|
31193
|
-
const len = bytes.length;
|
|
31194
|
-
const head = bytes[0];
|
|
31195
|
-
const tail = bytes.subarray(1);
|
|
31196
|
-
// this.assertValidity() is done inside of fromHex
|
|
31197
|
-
if (len === compressedLen && (head === 0x02 || head === 0x03)) {
|
|
31198
|
-
const x = ut.bytesToNumberBE(tail);
|
|
31199
|
-
if (!isValidFieldElement(x))
|
|
31200
|
-
throw new Error('Point is not on curve');
|
|
31201
|
-
const y2 = weierstrassEquation(x); // y² = x³ + ax + b
|
|
31202
|
-
let y = Fp.sqrt(y2); // y = y² ^ (p+1)/4
|
|
31203
|
-
const isYOdd = (y & _1n) === _1n;
|
|
31204
|
-
// ECDSA
|
|
31205
|
-
const isHeadOdd = (head & 1) === 1;
|
|
31206
|
-
if (isHeadOdd !== isYOdd)
|
|
31207
|
-
y = Fp.neg(y);
|
|
31208
|
-
return { x, y };
|
|
31209
|
-
}
|
|
31210
|
-
else if (len === uncompressedLen && head === 0x04) {
|
|
31211
|
-
const x = Fp.fromBytes(tail.subarray(0, Fp.BYTES));
|
|
31212
|
-
const y = Fp.fromBytes(tail.subarray(Fp.BYTES, 2 * Fp.BYTES));
|
|
31213
|
-
return { x, y };
|
|
31214
|
-
}
|
|
31215
|
-
else {
|
|
31216
|
-
throw new Error(`Point of length ${len} was invalid. Expected ${compressedLen} compressed bytes or ${uncompressedLen} uncompressed bytes`);
|
|
31217
|
-
}
|
|
31218
|
-
},
|
|
31219
|
-
});
|
|
31220
|
-
const numToNByteStr = (num) => ut.bytesToHex(ut.numberToBytesBE(num, CURVE.nByteLength));
|
|
31221
|
-
function isBiggerThanHalfOrder(number) {
|
|
31222
|
-
const HALF = CURVE_ORDER >> _1n;
|
|
31223
|
-
return number > HALF;
|
|
31224
|
-
}
|
|
31225
|
-
function normalizeS(s) {
|
|
31226
|
-
return isBiggerThanHalfOrder(s) ? modN(-s) : s;
|
|
31227
|
-
}
|
|
31228
|
-
// slice bytes num
|
|
31229
|
-
const slcNum = (b, from, to) => ut.bytesToNumberBE(b.slice(from, to));
|
|
31230
|
-
/**
|
|
31231
|
-
* ECDSA signature with its (r, s) properties. Supports DER & compact representations.
|
|
31232
|
-
*/
|
|
31233
|
-
class Signature {
|
|
31234
|
-
constructor(r, s, recovery) {
|
|
31235
|
-
this.r = r;
|
|
31236
|
-
this.s = s;
|
|
31237
|
-
this.recovery = recovery;
|
|
31238
|
-
this.assertValidity();
|
|
31239
|
-
}
|
|
31240
|
-
// pair (bytes of r, bytes of s)
|
|
31241
|
-
static fromCompact(hex) {
|
|
31242
|
-
const l = CURVE.nByteLength;
|
|
31243
|
-
hex = (0, utils_js_1.ensureBytes)('compactSignature', hex, l * 2);
|
|
31244
|
-
return new Signature(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
31245
|
-
}
|
|
31246
|
-
// DER encoded ECDSA signature
|
|
31247
|
-
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
31248
|
-
static fromDER(hex) {
|
|
31249
|
-
const { r, s } = exports.DER.toSig((0, utils_js_1.ensureBytes)('DER', hex));
|
|
31250
|
-
return new Signature(r, s);
|
|
31251
|
-
}
|
|
31252
|
-
assertValidity() {
|
|
31253
|
-
// can use assertGE here
|
|
31254
|
-
if (!isWithinCurveOrder(this.r))
|
|
31255
|
-
throw new Error('r must be 0 < r < CURVE.n');
|
|
31256
|
-
if (!isWithinCurveOrder(this.s))
|
|
31257
|
-
throw new Error('s must be 0 < s < CURVE.n');
|
|
31258
|
-
}
|
|
31259
|
-
addRecoveryBit(recovery) {
|
|
31260
|
-
return new Signature(this.r, this.s, recovery);
|
|
31261
|
-
}
|
|
31262
|
-
recoverPublicKey(msgHash) {
|
|
31263
|
-
const { r, s, recovery: rec } = this;
|
|
31264
|
-
const h = bits2int_modN((0, utils_js_1.ensureBytes)('msgHash', msgHash)); // Truncate hash
|
|
31265
|
-
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
31266
|
-
throw new Error('recovery id invalid');
|
|
31267
|
-
const radj = rec === 2 || rec === 3 ? r + CURVE.n : r;
|
|
31268
|
-
if (radj >= Fp.ORDER)
|
|
31269
|
-
throw new Error('recovery id 2 or 3 invalid');
|
|
31270
|
-
const prefix = (rec & 1) === 0 ? '02' : '03';
|
|
31271
|
-
const R = Point.fromHex(prefix + numToNByteStr(radj));
|
|
31272
|
-
const ir = invN(radj); // r^-1
|
|
31273
|
-
const u1 = modN(-h * ir); // -hr^-1
|
|
31274
|
-
const u2 = modN(s * ir); // sr^-1
|
|
31275
|
-
const Q = Point.BASE.multiplyAndAddUnsafe(R, u1, u2); // (sr^-1)R-(hr^-1)G = -(hr^-1)G + (sr^-1)
|
|
31276
|
-
if (!Q)
|
|
31277
|
-
throw new Error('point at infinify'); // unsafe is fine: no priv data leaked
|
|
31278
|
-
Q.assertValidity();
|
|
31279
|
-
return Q;
|
|
31280
|
-
}
|
|
31281
|
-
// Signatures should be low-s, to prevent malleability.
|
|
31282
|
-
hasHighS() {
|
|
31283
|
-
return isBiggerThanHalfOrder(this.s);
|
|
31284
|
-
}
|
|
31285
|
-
normalizeS() {
|
|
31286
|
-
return this.hasHighS() ? new Signature(this.r, modN(-this.s), this.recovery) : this;
|
|
31287
|
-
}
|
|
31288
|
-
// DER-encoded
|
|
31289
|
-
toDERRawBytes() {
|
|
31290
|
-
return ut.hexToBytes(this.toDERHex());
|
|
31291
|
-
}
|
|
31292
|
-
toDERHex() {
|
|
31293
|
-
return exports.DER.hexFromSig({ r: this.r, s: this.s });
|
|
31294
|
-
}
|
|
31295
|
-
// padded bytes of r, then padded bytes of s
|
|
31296
|
-
toCompactRawBytes() {
|
|
31297
|
-
return ut.hexToBytes(this.toCompactHex());
|
|
31298
|
-
}
|
|
31299
|
-
toCompactHex() {
|
|
31300
|
-
return numToNByteStr(this.r) + numToNByteStr(this.s);
|
|
31301
|
-
}
|
|
31302
|
-
}
|
|
31303
|
-
const utils = {
|
|
31304
|
-
isValidPrivateKey(privateKey) {
|
|
31305
|
-
try {
|
|
31306
|
-
normPrivateKeyToScalar(privateKey);
|
|
31307
|
-
return true;
|
|
31308
|
-
}
|
|
31309
|
-
catch (error) {
|
|
31310
|
-
return false;
|
|
31311
|
-
}
|
|
31312
|
-
},
|
|
31313
|
-
normPrivateKeyToScalar: normPrivateKeyToScalar,
|
|
31314
|
-
/**
|
|
31315
|
-
* Produces cryptographically secure private key from random of size (nBitLength+64)
|
|
31316
|
-
* as per FIPS 186 B.4.1 with modulo bias being neglible.
|
|
31317
|
-
*/
|
|
31318
|
-
randomPrivateKey: () => {
|
|
31319
|
-
const rand = CURVE.randomBytes(Fp.BYTES + 8);
|
|
31320
|
-
const num = mod.hashToPrivateScalar(rand, CURVE_ORDER);
|
|
31321
|
-
return ut.numberToBytesBE(num, CURVE.nByteLength);
|
|
31322
|
-
},
|
|
31323
|
-
/**
|
|
31324
|
-
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
31325
|
-
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
31326
|
-
* @returns cached point
|
|
31327
|
-
* @example
|
|
31328
|
-
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
31329
|
-
* fast.multiply(privKey); // much faster ECDH now
|
|
31330
|
-
*/
|
|
31331
|
-
precompute(windowSize = 8, point = Point.BASE) {
|
|
31332
|
-
point._setWindowSize(windowSize);
|
|
31333
|
-
point.multiply(BigInt(3)); // 3 is arbitrary, just need any number here
|
|
31334
|
-
return point;
|
|
31335
|
-
},
|
|
31336
|
-
};
|
|
31337
|
-
/**
|
|
31338
|
-
* Computes public key for a private key. Checks for validity of the private key.
|
|
31339
|
-
* @param privateKey private key
|
|
31340
|
-
* @param isCompressed whether to return compact (default), or full key
|
|
31341
|
-
* @returns Public key, full when isCompressed=false; short when isCompressed=true
|
|
31342
|
-
*/
|
|
31343
|
-
function getPublicKey(privateKey, isCompressed = true) {
|
|
31344
|
-
return Point.fromPrivateKey(privateKey).toRawBytes(isCompressed);
|
|
31345
|
-
}
|
|
31346
|
-
/**
|
|
31347
|
-
* Quick and dirty check for item being public key. Does not validate hex, or being on-curve.
|
|
31348
|
-
*/
|
|
31349
|
-
function isProbPub(item) {
|
|
31350
|
-
const arr = item instanceof Uint8Array;
|
|
31351
|
-
const str = typeof item === 'string';
|
|
31352
|
-
const len = (arr || str) && item.length;
|
|
31353
|
-
if (arr)
|
|
31354
|
-
return len === compressedLen || len === uncompressedLen;
|
|
31355
|
-
if (str)
|
|
31356
|
-
return len === 2 * compressedLen || len === 2 * uncompressedLen;
|
|
31357
|
-
if (item instanceof Point)
|
|
31358
|
-
return true;
|
|
31359
|
-
return false;
|
|
31360
|
-
}
|
|
31361
|
-
/**
|
|
31362
|
-
* ECDH (Elliptic Curve Diffie Hellman).
|
|
31363
|
-
* Computes shared public key from private key and public key.
|
|
31364
|
-
* Checks: 1) private key validity 2) shared key is on-curve.
|
|
31365
|
-
* Does NOT hash the result.
|
|
31366
|
-
* @param privateA private key
|
|
31367
|
-
* @param publicB different public key
|
|
31368
|
-
* @param isCompressed whether to return compact (default), or full key
|
|
31369
|
-
* @returns shared public key
|
|
31370
|
-
*/
|
|
31371
|
-
function getSharedSecret(privateA, publicB, isCompressed = true) {
|
|
31372
|
-
if (isProbPub(privateA))
|
|
31373
|
-
throw new Error('first arg must be private key');
|
|
31374
|
-
if (!isProbPub(publicB))
|
|
31375
|
-
throw new Error('second arg must be public key');
|
|
31376
|
-
const b = Point.fromHex(publicB); // check for being on-curve
|
|
31377
|
-
return b.multiply(normPrivateKeyToScalar(privateA)).toRawBytes(isCompressed);
|
|
31378
|
-
}
|
|
31379
|
-
// RFC6979: ensure ECDSA msg is X bytes and < N. RFC suggests optional truncating via bits2octets.
|
|
31380
|
-
// FIPS 186-4 4.6 suggests the leftmost min(nBitLen, outLen) bits, which matches bits2int.
|
|
31381
|
-
// bits2int can produce res>N, we can do mod(res, N) since the bitLen is the same.
|
|
31382
|
-
// int2octets can't be used; pads small msgs with 0: unacceptatble for trunc as per RFC vectors
|
|
31383
|
-
const bits2int = CURVE.bits2int ||
|
|
31384
|
-
function (bytes) {
|
|
31385
|
-
// For curves with nBitLength % 8 !== 0: bits2octets(bits2octets(m)) !== bits2octets(m)
|
|
31386
|
-
// for some cases, since bytes.length * 8 is not actual bitLength.
|
|
31387
|
-
const num = ut.bytesToNumberBE(bytes); // check for == u8 done here
|
|
31388
|
-
const delta = bytes.length * 8 - CURVE.nBitLength; // truncate to nBitLength leftmost bits
|
|
31389
|
-
return delta > 0 ? num >> BigInt(delta) : num;
|
|
31390
|
-
};
|
|
31391
|
-
const bits2int_modN = CURVE.bits2int_modN ||
|
|
31392
|
-
function (bytes) {
|
|
31393
|
-
return modN(bits2int(bytes)); // can't use bytesToNumberBE here
|
|
31394
|
-
};
|
|
31395
|
-
// NOTE: pads output with zero as per spec
|
|
31396
|
-
const ORDER_MASK = ut.bitMask(CURVE.nBitLength);
|
|
31397
|
-
/**
|
|
31398
|
-
* Converts to bytes. Checks if num in `[0..ORDER_MASK-1]` e.g.: `[0..2^256-1]`.
|
|
31399
|
-
*/
|
|
31400
|
-
function int2octets(num) {
|
|
31401
|
-
if (typeof num !== 'bigint')
|
|
31402
|
-
throw new Error('bigint expected');
|
|
31403
|
-
if (!(_0n <= num && num < ORDER_MASK))
|
|
31404
|
-
throw new Error(`bigint expected < 2^${CURVE.nBitLength}`);
|
|
31405
|
-
// works with order, can have different size than numToField!
|
|
31406
|
-
return ut.numberToBytesBE(num, CURVE.nByteLength);
|
|
31407
|
-
}
|
|
31408
|
-
// Steps A, D of RFC6979 3.2
|
|
31409
|
-
// Creates RFC6979 seed; converts msg/privKey to numbers.
|
|
31410
|
-
// Used only in sign, not in verify.
|
|
31411
|
-
// NOTE: we cannot assume here that msgHash has same amount of bytes as curve order, this will be wrong at least for P521.
|
|
31412
|
-
// Also it can be bigger for P224 + SHA256
|
|
31413
|
-
function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
|
|
31414
|
-
if (['recovered', 'canonical'].some((k) => k in opts))
|
|
31415
|
-
throw new Error('sign() legacy options not supported');
|
|
31416
|
-
const { hash, randomBytes } = CURVE;
|
|
31417
|
-
let { lowS, prehash, extraEntropy: ent } = opts; // generates low-s sigs by default
|
|
31418
|
-
if (lowS == null)
|
|
31419
|
-
lowS = true; // RFC6979 3.2: we skip step A, because we already provide hash
|
|
31420
|
-
msgHash = (0, utils_js_1.ensureBytes)('msgHash', msgHash);
|
|
31421
|
-
if (prehash)
|
|
31422
|
-
msgHash = (0, utils_js_1.ensureBytes)('prehashed msgHash', hash(msgHash));
|
|
31423
|
-
// We can't later call bits2octets, since nested bits2int is broken for curves
|
|
31424
|
-
// with nBitLength % 8 !== 0. Because of that, we unwrap it here as int2octets call.
|
|
31425
|
-
// const bits2octets = (bits) => int2octets(bits2int_modN(bits))
|
|
31426
|
-
const h1int = bits2int_modN(msgHash);
|
|
31427
|
-
const d = normPrivateKeyToScalar(privateKey); // validate private key, convert to bigint
|
|
31428
|
-
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
31429
|
-
// extraEntropy. RFC6979 3.6: additional k' (optional).
|
|
31430
|
-
if (ent != null) {
|
|
31431
|
-
// K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1) || k')
|
|
31432
|
-
const e = ent === true ? randomBytes(Fp.BYTES) : ent; // generate random bytes OR pass as-is
|
|
31433
|
-
seedArgs.push((0, utils_js_1.ensureBytes)('extraEntropy', e, Fp.BYTES)); // check for being of size BYTES
|
|
31434
|
-
}
|
|
31435
|
-
const seed = ut.concatBytes(...seedArgs); // Step D of RFC6979 3.2
|
|
31436
|
-
const m = h1int; // NOTE: no need to call bits2int second time here, it is inside truncateHash!
|
|
31437
|
-
// Converts signature params into point w r/s, checks result for validity.
|
|
31438
|
-
function k2sig(kBytes) {
|
|
31439
|
-
// RFC 6979 Section 3.2, step 3: k = bits2int(T)
|
|
31440
|
-
const k = bits2int(kBytes); // Cannot use fields methods, since it is group element
|
|
31441
|
-
if (!isWithinCurveOrder(k))
|
|
31442
|
-
return; // Important: all mod() calls here must be done over N
|
|
31443
|
-
const ik = invN(k); // k^-1 mod n
|
|
31444
|
-
const q = Point.BASE.multiply(k).toAffine(); // q = Gk
|
|
31445
|
-
const r = modN(q.x); // r = q.x mod n
|
|
31446
|
-
if (r === _0n)
|
|
31447
|
-
return;
|
|
31448
|
-
// Can use scalar blinding b^-1(bm + bdr) where b ∈ [1,q−1] according to
|
|
31449
|
-
// https://tches.iacr.org/index.php/TCHES/article/view/7337/6509. We've decided against it:
|
|
31450
|
-
// a) dependency on CSPRNG b) 15% slowdown c) doesn't really help since bigints are not CT
|
|
31451
|
-
const s = modN(ik * modN(m + r * d)); // Not using blinding here
|
|
31452
|
-
if (s === _0n)
|
|
31453
|
-
return;
|
|
31454
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n); // recovery bit (2 or 3, when q.x > n)
|
|
31455
|
-
let normS = s;
|
|
31456
|
-
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
31457
|
-
normS = normalizeS(s); // if lowS was passed, ensure s is always
|
|
31458
|
-
recovery ^= 1; // // in the bottom half of N
|
|
31459
|
-
}
|
|
31460
|
-
return new Signature(r, normS, recovery); // use normS, not s
|
|
31461
|
-
}
|
|
31462
|
-
return { seed, k2sig };
|
|
31463
|
-
}
|
|
31464
|
-
const defaultSigOpts = { lowS: CURVE.lowS, prehash: false };
|
|
31465
|
-
const defaultVerOpts = { lowS: CURVE.lowS, prehash: false };
|
|
31466
|
-
/**
|
|
31467
|
-
* Signs message hash (not message: you need to hash it by yourself).
|
|
31468
|
-
* ```
|
|
31469
|
-
* sign(m, d, k) where
|
|
31470
|
-
* (x, y) = G × k
|
|
31471
|
-
* r = x mod n
|
|
31472
|
-
* s = (m + dr)/k mod n
|
|
31473
|
-
* ```
|
|
31474
|
-
* @param opts `lowS, extraEntropy, prehash`
|
|
31475
|
-
*/
|
|
31476
|
-
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
|
31477
|
-
const { seed, k2sig } = prepSig(msgHash, privKey, opts); // Steps A, D of RFC6979 3.2.
|
|
31478
|
-
const drbg = ut.createHmacDrbg(CURVE.hash.outputLen, CURVE.nByteLength, CURVE.hmac);
|
|
31479
|
-
return drbg(seed, k2sig); // Steps B, C, D, E, F, G
|
|
31480
|
-
}
|
|
31481
|
-
// Enable precomputes. Slows down first publicKey computation by 20ms.
|
|
31482
|
-
Point.BASE._setWindowSize(8);
|
|
31483
|
-
// utils.precompute(8, ProjectivePoint.BASE)
|
|
31484
|
-
/**
|
|
31485
|
-
* Verifies a signature against message hash and public key.
|
|
31486
|
-
* Rejects lowS signatures by default: to override,
|
|
31487
|
-
* specify option `{lowS: false}`. Implements section 4.1.4 from https://www.secg.org/sec1-v2.pdf:
|
|
31488
|
-
*
|
|
31489
|
-
* ```
|
|
31490
|
-
* verify(r, s, h, P) where
|
|
31491
|
-
* U1 = hs^-1 mod n
|
|
31492
|
-
* U2 = rs^-1 mod n
|
|
31493
|
-
* R = U1⋅G - U2⋅P
|
|
31494
|
-
* mod(R.x, n) == r
|
|
31495
|
-
* ```
|
|
31496
|
-
*/
|
|
31497
|
-
function verify(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
31498
|
-
const sg = signature;
|
|
31499
|
-
msgHash = (0, utils_js_1.ensureBytes)('msgHash', msgHash);
|
|
31500
|
-
publicKey = (0, utils_js_1.ensureBytes)('publicKey', publicKey);
|
|
31501
|
-
if ('strict' in opts)
|
|
31502
|
-
throw new Error('options.strict was renamed to lowS');
|
|
31503
|
-
const { lowS, prehash } = opts;
|
|
31504
|
-
let _sig = undefined;
|
|
31505
|
-
let P;
|
|
31506
|
-
try {
|
|
31507
|
-
if (typeof sg === 'string' || sg instanceof Uint8Array) {
|
|
31508
|
-
// Signature can be represented in 2 ways: compact (2*nByteLength) & DER (variable-length).
|
|
31509
|
-
// Since DER can also be 2*nByteLength bytes, we check for it first.
|
|
31510
|
-
try {
|
|
31511
|
-
_sig = Signature.fromDER(sg);
|
|
31512
|
-
}
|
|
31513
|
-
catch (derError) {
|
|
31514
|
-
if (!(derError instanceof exports.DER.Err))
|
|
31515
|
-
throw derError;
|
|
31516
|
-
_sig = Signature.fromCompact(sg);
|
|
31517
|
-
}
|
|
31518
|
-
}
|
|
31519
|
-
else if (typeof sg === 'object' && typeof sg.r === 'bigint' && typeof sg.s === 'bigint') {
|
|
31520
|
-
const { r, s } = sg;
|
|
31521
|
-
_sig = new Signature(r, s);
|
|
31522
|
-
}
|
|
31523
|
-
else {
|
|
31524
|
-
throw new Error('PARSE');
|
|
31525
|
-
}
|
|
31526
|
-
P = Point.fromHex(publicKey);
|
|
31527
|
-
}
|
|
31528
|
-
catch (error) {
|
|
31529
|
-
if (error.message === 'PARSE')
|
|
31530
|
-
throw new Error(`signature must be Signature instance, Uint8Array or hex string`);
|
|
31531
|
-
return false;
|
|
31532
|
-
}
|
|
31533
|
-
if (lowS && _sig.hasHighS())
|
|
31534
|
-
return false;
|
|
31535
|
-
if (prehash)
|
|
31536
|
-
msgHash = CURVE.hash(msgHash);
|
|
31537
|
-
const { r, s } = _sig;
|
|
31538
|
-
const h = bits2int_modN(msgHash); // Cannot use fields methods, since it is group element
|
|
31539
|
-
const is = invN(s); // s^-1
|
|
31540
|
-
const u1 = modN(h * is); // u1 = hs^-1 mod n
|
|
31541
|
-
const u2 = modN(r * is); // u2 = rs^-1 mod n
|
|
31542
|
-
const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine(); // R = u1⋅G + u2⋅P
|
|
31543
|
-
if (!R)
|
|
31544
|
-
return false;
|
|
31545
|
-
const v = modN(R.x);
|
|
31546
|
-
return v === r;
|
|
31547
|
-
}
|
|
31548
|
-
return {
|
|
31549
|
-
CURVE,
|
|
31550
|
-
getPublicKey,
|
|
31551
|
-
getSharedSecret,
|
|
31552
|
-
sign,
|
|
31553
|
-
verify,
|
|
31554
|
-
ProjectivePoint: Point,
|
|
31555
|
-
Signature,
|
|
31556
|
-
utils,
|
|
31557
|
-
};
|
|
31558
|
-
}
|
|
31559
|
-
exports.weierstrass = weierstrass;
|
|
31560
|
-
// Implementation of the Shallue and van de Woestijne method for any Weierstrass curve
|
|
31561
|
-
// TODO: check if there is a way to merge this with uvRatio in Edwards && move to modular?
|
|
31562
|
-
// b = True and y = sqrt(u / v) if (u / v) is square in F, and
|
|
31563
|
-
// b = False and y = sqrt(Z * (u / v)) otherwise.
|
|
31564
|
-
function SWUFpSqrtRatio(Fp, Z) {
|
|
31565
|
-
// Generic implementation
|
|
31566
|
-
const q = Fp.ORDER;
|
|
31567
|
-
let l = _0n;
|
|
31568
|
-
for (let o = q - _1n; o % _2n === _0n; o /= _2n)
|
|
31569
|
-
l += _1n;
|
|
31570
|
-
const c1 = l; // 1. c1, the largest integer such that 2^c1 divides q - 1.
|
|
31571
|
-
const c2 = (q - _1n) / _2n ** c1; // 2. c2 = (q - 1) / (2^c1) # Integer arithmetic
|
|
31572
|
-
const c3 = (c2 - _1n) / _2n; // 3. c3 = (c2 - 1) / 2 # Integer arithmetic
|
|
31573
|
-
const c4 = _2n ** c1 - _1n; // 4. c4 = 2^c1 - 1 # Integer arithmetic
|
|
31574
|
-
const c5 = _2n ** (c1 - _1n); // 5. c5 = 2^(c1 - 1) # Integer arithmetic
|
|
31575
|
-
const c6 = Fp.pow(Z, c2); // 6. c6 = Z^c2
|
|
31576
|
-
const c7 = Fp.pow(Z, (c2 + _1n) / _2n); // 7. c7 = Z^((c2 + 1) / 2)
|
|
31577
|
-
let sqrtRatio = (u, v) => {
|
|
31578
|
-
let tv1 = c6; // 1. tv1 = c6
|
|
31579
|
-
let tv2 = Fp.pow(v, c4); // 2. tv2 = v^c4
|
|
31580
|
-
let tv3 = Fp.sqr(tv2); // 3. tv3 = tv2^2
|
|
31581
|
-
tv3 = Fp.mul(tv3, v); // 4. tv3 = tv3 * v
|
|
31582
|
-
let tv5 = Fp.mul(u, tv3); // 5. tv5 = u * tv3
|
|
31583
|
-
tv5 = Fp.pow(tv5, c3); // 6. tv5 = tv5^c3
|
|
31584
|
-
tv5 = Fp.mul(tv5, tv2); // 7. tv5 = tv5 * tv2
|
|
31585
|
-
tv2 = Fp.mul(tv5, v); // 8. tv2 = tv5 * v
|
|
31586
|
-
tv3 = Fp.mul(tv5, u); // 9. tv3 = tv5 * u
|
|
31587
|
-
let tv4 = Fp.mul(tv3, tv2); // 10. tv4 = tv3 * tv2
|
|
31588
|
-
tv5 = Fp.pow(tv4, c5); // 11. tv5 = tv4^c5
|
|
31589
|
-
let isQR = Fp.eql(tv5, Fp.ONE); // 12. isQR = tv5 == 1
|
|
31590
|
-
tv2 = Fp.mul(tv3, c7); // 13. tv2 = tv3 * c7
|
|
31591
|
-
tv5 = Fp.mul(tv4, tv1); // 14. tv5 = tv4 * tv1
|
|
31592
|
-
tv3 = Fp.cmov(tv2, tv3, isQR); // 15. tv3 = CMOV(tv2, tv3, isQR)
|
|
31593
|
-
tv4 = Fp.cmov(tv5, tv4, isQR); // 16. tv4 = CMOV(tv5, tv4, isQR)
|
|
31594
|
-
// 17. for i in (c1, c1 - 1, ..., 2):
|
|
31595
|
-
for (let i = c1; i > _1n; i--) {
|
|
31596
|
-
let tv5 = _2n ** (i - _2n); // 18. tv5 = i - 2; 19. tv5 = 2^tv5
|
|
31597
|
-
let tvv5 = Fp.pow(tv4, tv5); // 20. tv5 = tv4^tv5
|
|
31598
|
-
const e1 = Fp.eql(tvv5, Fp.ONE); // 21. e1 = tv5 == 1
|
|
31599
|
-
tv2 = Fp.mul(tv3, tv1); // 22. tv2 = tv3 * tv1
|
|
31600
|
-
tv1 = Fp.mul(tv1, tv1); // 23. tv1 = tv1 * tv1
|
|
31601
|
-
tvv5 = Fp.mul(tv4, tv1); // 24. tv5 = tv4 * tv1
|
|
31602
|
-
tv3 = Fp.cmov(tv2, tv3, e1); // 25. tv3 = CMOV(tv2, tv3, e1)
|
|
31603
|
-
tv4 = Fp.cmov(tvv5, tv4, e1); // 26. tv4 = CMOV(tv5, tv4, e1)
|
|
31604
|
-
}
|
|
31605
|
-
return { isValid: isQR, value: tv3 };
|
|
31606
|
-
};
|
|
31607
|
-
if (Fp.ORDER % _4n === _3n) {
|
|
31608
|
-
// sqrt_ratio_3mod4(u, v)
|
|
31609
|
-
const c1 = (Fp.ORDER - _3n) / _4n; // 1. c1 = (q - 3) / 4 # Integer arithmetic
|
|
31610
|
-
const c2 = Fp.sqrt(Fp.neg(Z)); // 2. c2 = sqrt(-Z)
|
|
31611
|
-
sqrtRatio = (u, v) => {
|
|
31612
|
-
let tv1 = Fp.sqr(v); // 1. tv1 = v^2
|
|
31613
|
-
const tv2 = Fp.mul(u, v); // 2. tv2 = u * v
|
|
31614
|
-
tv1 = Fp.mul(tv1, tv2); // 3. tv1 = tv1 * tv2
|
|
31615
|
-
let y1 = Fp.pow(tv1, c1); // 4. y1 = tv1^c1
|
|
31616
|
-
y1 = Fp.mul(y1, tv2); // 5. y1 = y1 * tv2
|
|
31617
|
-
const y2 = Fp.mul(y1, c2); // 6. y2 = y1 * c2
|
|
31618
|
-
const tv3 = Fp.mul(Fp.sqr(y1), v); // 7. tv3 = y1^2; 8. tv3 = tv3 * v
|
|
31619
|
-
const isQR = Fp.eql(tv3, u); // 9. isQR = tv3 == u
|
|
31620
|
-
let y = Fp.cmov(y2, y1, isQR); // 10. y = CMOV(y2, y1, isQR)
|
|
31621
|
-
return { isValid: isQR, value: y }; // 11. return (isQR, y) isQR ? y : y*c2
|
|
31622
|
-
};
|
|
31623
|
-
}
|
|
31624
|
-
// No curves uses that
|
|
31625
|
-
// if (Fp.ORDER % _8n === _5n) // sqrt_ratio_5mod8
|
|
31626
|
-
return sqrtRatio;
|
|
31627
|
-
}
|
|
31628
|
-
exports.SWUFpSqrtRatio = SWUFpSqrtRatio;
|
|
31629
|
-
// From draft-irtf-cfrg-hash-to-curve-16
|
|
31630
|
-
function mapToCurveSimpleSWU(Fp, opts) {
|
|
31631
|
-
mod.validateField(Fp);
|
|
31632
|
-
if (!Fp.isValid(opts.A) || !Fp.isValid(opts.B) || !Fp.isValid(opts.Z))
|
|
31633
|
-
throw new Error('mapToCurveSimpleSWU: invalid opts');
|
|
31634
|
-
const sqrtRatio = SWUFpSqrtRatio(Fp, opts.Z);
|
|
31635
|
-
if (!Fp.isOdd)
|
|
31636
|
-
throw new Error('Fp.isOdd is not implemented!');
|
|
31637
|
-
// Input: u, an element of F.
|
|
31638
|
-
// Output: (x, y), a point on E.
|
|
31639
|
-
return (u) => {
|
|
31640
|
-
// prettier-ignore
|
|
31641
|
-
let tv1, tv2, tv3, tv4, tv5, tv6, x, y;
|
|
31642
|
-
tv1 = Fp.sqr(u); // 1. tv1 = u^2
|
|
31643
|
-
tv1 = Fp.mul(tv1, opts.Z); // 2. tv1 = Z * tv1
|
|
31644
|
-
tv2 = Fp.sqr(tv1); // 3. tv2 = tv1^2
|
|
31645
|
-
tv2 = Fp.add(tv2, tv1); // 4. tv2 = tv2 + tv1
|
|
31646
|
-
tv3 = Fp.add(tv2, Fp.ONE); // 5. tv3 = tv2 + 1
|
|
31647
|
-
tv3 = Fp.mul(tv3, opts.B); // 6. tv3 = B * tv3
|
|
31648
|
-
tv4 = Fp.cmov(opts.Z, Fp.neg(tv2), !Fp.eql(tv2, Fp.ZERO)); // 7. tv4 = CMOV(Z, -tv2, tv2 != 0)
|
|
31649
|
-
tv4 = Fp.mul(tv4, opts.A); // 8. tv4 = A * tv4
|
|
31650
|
-
tv2 = Fp.sqr(tv3); // 9. tv2 = tv3^2
|
|
31651
|
-
tv6 = Fp.sqr(tv4); // 10. tv6 = tv4^2
|
|
31652
|
-
tv5 = Fp.mul(tv6, opts.A); // 11. tv5 = A * tv6
|
|
31653
|
-
tv2 = Fp.add(tv2, tv5); // 12. tv2 = tv2 + tv5
|
|
31654
|
-
tv2 = Fp.mul(tv2, tv3); // 13. tv2 = tv2 * tv3
|
|
31655
|
-
tv6 = Fp.mul(tv6, tv4); // 14. tv6 = tv6 * tv4
|
|
31656
|
-
tv5 = Fp.mul(tv6, opts.B); // 15. tv5 = B * tv6
|
|
31657
|
-
tv2 = Fp.add(tv2, tv5); // 16. tv2 = tv2 + tv5
|
|
31658
|
-
x = Fp.mul(tv1, tv3); // 17. x = tv1 * tv3
|
|
31659
|
-
const { isValid, value } = sqrtRatio(tv2, tv6); // 18. (is_gx1_square, y1) = sqrt_ratio(tv2, tv6)
|
|
31660
|
-
y = Fp.mul(tv1, u); // 19. y = tv1 * u -> Z * u^3 * y1
|
|
31661
|
-
y = Fp.mul(y, value); // 20. y = y * y1
|
|
31662
|
-
x = Fp.cmov(x, tv3, isValid); // 21. x = CMOV(x, tv3, is_gx1_square)
|
|
31663
|
-
y = Fp.cmov(y, value, isValid); // 22. y = CMOV(y, y1, is_gx1_square)
|
|
31664
|
-
const e1 = Fp.isOdd(u) === Fp.isOdd(y); // 23. e1 = sgn0(u) == sgn0(y)
|
|
31665
|
-
y = Fp.cmov(Fp.neg(y), y, e1); // 24. y = CMOV(-y, y, e1)
|
|
31666
|
-
x = Fp.div(x, tv4); // 25. x = x / tv4
|
|
31667
|
-
return { x, y };
|
|
31668
|
-
};
|
|
31669
|
-
}
|
|
31670
|
-
exports.mapToCurveSimpleSWU = mapToCurveSimpleSWU;
|
|
31671
|
-
//# sourceMappingURL=weierstrass.js.map
|
|
31672
|
-
|
|
31673
|
-
/***/ }),
|
|
31674
|
-
|
|
31675
|
-
/***/ "./node_modules/@noble/curves/secp256k1.js":
|
|
31676
|
-
/*!*************************************************!*\
|
|
31677
|
-
!*** ./node_modules/@noble/curves/secp256k1.js ***!
|
|
31678
|
-
\*************************************************/
|
|
31679
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
31680
|
-
|
|
31681
|
-
"use strict";
|
|
31682
|
-
|
|
31683
|
-
var _a;
|
|
31684
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
31685
|
-
exports.encodeToCurve = exports.hashToCurve = exports.schnorr = exports.secp256k1 = void 0;
|
|
31686
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
31687
|
-
const sha256_1 = __webpack_require__(/*! @noble/hashes/sha256 */ "./node_modules/@noble/hashes/sha256.js");
|
|
31688
|
-
const utils_1 = __webpack_require__(/*! @noble/hashes/utils */ "./node_modules/@noble/hashes/utils.js");
|
|
31689
|
-
const modular_js_1 = __webpack_require__(/*! ./abstract/modular.js */ "./node_modules/@noble/curves/abstract/modular.js");
|
|
31690
|
-
const weierstrass_js_1 = __webpack_require__(/*! ./abstract/weierstrass.js */ "./node_modules/@noble/curves/abstract/weierstrass.js");
|
|
31691
|
-
const utils_js_1 = __webpack_require__(/*! ./abstract/utils.js */ "./node_modules/@noble/curves/abstract/utils.js");
|
|
31692
|
-
const htf = __webpack_require__(/*! ./abstract/hash-to-curve.js */ "./node_modules/@noble/curves/abstract/hash-to-curve.js");
|
|
31693
|
-
const _shortw_utils_js_1 = __webpack_require__(/*! ./_shortw_utils.js */ "./node_modules/@noble/curves/_shortw_utils.js");
|
|
31694
|
-
const secp256k1P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
|
|
31695
|
-
const secp256k1N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
|
|
31696
|
-
const _1n = BigInt(1);
|
|
31697
|
-
const _2n = BigInt(2);
|
|
31698
|
-
const divNearest = (a, b) => (a + b / _2n) / b;
|
|
31699
|
-
/**
|
|
31700
|
-
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
|
|
31701
|
-
* (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
|
|
31702
|
-
*/
|
|
31703
|
-
function sqrtMod(y) {
|
|
31704
|
-
const P = secp256k1P;
|
|
31705
|
-
// prettier-ignore
|
|
31706
|
-
const _3n = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
31707
|
-
// prettier-ignore
|
|
31708
|
-
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
31709
|
-
const b2 = (y * y * y) % P; // x^3, 11
|
|
31710
|
-
const b3 = (b2 * b2 * y) % P; // x^7
|
|
31711
|
-
const b6 = ((0, modular_js_1.pow2)(b3, _3n, P) * b3) % P;
|
|
31712
|
-
const b9 = ((0, modular_js_1.pow2)(b6, _3n, P) * b3) % P;
|
|
31713
|
-
const b11 = ((0, modular_js_1.pow2)(b9, _2n, P) * b2) % P;
|
|
31714
|
-
const b22 = ((0, modular_js_1.pow2)(b11, _11n, P) * b11) % P;
|
|
31715
|
-
const b44 = ((0, modular_js_1.pow2)(b22, _22n, P) * b22) % P;
|
|
31716
|
-
const b88 = ((0, modular_js_1.pow2)(b44, _44n, P) * b44) % P;
|
|
31717
|
-
const b176 = ((0, modular_js_1.pow2)(b88, _88n, P) * b88) % P;
|
|
31718
|
-
const b220 = ((0, modular_js_1.pow2)(b176, _44n, P) * b44) % P;
|
|
31719
|
-
const b223 = ((0, modular_js_1.pow2)(b220, _3n, P) * b3) % P;
|
|
31720
|
-
const t1 = ((0, modular_js_1.pow2)(b223, _23n, P) * b22) % P;
|
|
31721
|
-
const t2 = ((0, modular_js_1.pow2)(t1, _6n, P) * b2) % P;
|
|
31722
|
-
const root = (0, modular_js_1.pow2)(t2, _2n, P);
|
|
31723
|
-
if (!Fp.eql(Fp.sqr(root), y))
|
|
31724
|
-
throw new Error('Cannot find square root');
|
|
31725
|
-
return root;
|
|
31726
|
-
}
|
|
31727
|
-
const Fp = (0, modular_js_1.Field)(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
|
|
31728
|
-
exports.secp256k1 = (0, _shortw_utils_js_1.createCurve)({
|
|
31729
|
-
a: BigInt(0),
|
|
31730
|
-
b: BigInt(7),
|
|
31731
|
-
Fp,
|
|
31732
|
-
n: secp256k1N,
|
|
31733
|
-
// Base point (x, y) aka generator point
|
|
31734
|
-
Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
|
|
31735
|
-
Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'),
|
|
31736
|
-
h: BigInt(1),
|
|
31737
|
-
lowS: true,
|
|
31738
|
-
/**
|
|
31739
|
-
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
|
31740
|
-
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
|
31741
|
-
* For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
31742
|
-
* Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
31743
|
-
*/
|
|
31744
|
-
endo: {
|
|
31745
|
-
beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'),
|
|
31746
|
-
splitScalar: (k) => {
|
|
31747
|
-
const n = secp256k1N;
|
|
31748
|
-
const a1 = BigInt('0x3086d221a7d46bcde86c90e49284eb15');
|
|
31749
|
-
const b1 = -_1n * BigInt('0xe4437ed6010e88286f547fa90abfe4c3');
|
|
31750
|
-
const a2 = BigInt('0x114ca50f7a8e2f3f657c1108d9d44cfd8');
|
|
31751
|
-
const b2 = a1;
|
|
31752
|
-
const POW_2_128 = BigInt('0x100000000000000000000000000000000'); // (2n**128n).toString(16)
|
|
31753
|
-
const c1 = divNearest(b2 * k, n);
|
|
31754
|
-
const c2 = divNearest(-b1 * k, n);
|
|
31755
|
-
let k1 = (0, modular_js_1.mod)(k - c1 * a1 - c2 * a2, n);
|
|
31756
|
-
let k2 = (0, modular_js_1.mod)(-c1 * b1 - c2 * b2, n);
|
|
31757
|
-
const k1neg = k1 > POW_2_128;
|
|
31758
|
-
const k2neg = k2 > POW_2_128;
|
|
31759
|
-
if (k1neg)
|
|
31760
|
-
k1 = n - k1;
|
|
31761
|
-
if (k2neg)
|
|
31762
|
-
k2 = n - k2;
|
|
31763
|
-
if (k1 > POW_2_128 || k2 > POW_2_128) {
|
|
31764
|
-
throw new Error('splitScalar: Endomorphism failed, k=' + k);
|
|
31765
|
-
}
|
|
31766
|
-
return { k1neg, k1, k2neg, k2 };
|
|
31767
|
-
},
|
|
31768
|
-
},
|
|
31769
|
-
}, sha256_1.sha256);
|
|
31770
|
-
// Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
|
|
31771
|
-
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
31772
|
-
const _0n = BigInt(0);
|
|
31773
|
-
const fe = (x) => typeof x === 'bigint' && _0n < x && x < secp256k1P;
|
|
31774
|
-
const ge = (x) => typeof x === 'bigint' && _0n < x && x < secp256k1N;
|
|
31775
|
-
/** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
|
|
31776
|
-
const TAGGED_HASH_PREFIXES = {};
|
|
31777
|
-
function taggedHash(tag, ...messages) {
|
|
31778
|
-
let tagP = TAGGED_HASH_PREFIXES[tag];
|
|
31779
|
-
if (tagP === undefined) {
|
|
31780
|
-
const tagH = (0, sha256_1.sha256)(Uint8Array.from(tag, (c) => c.charCodeAt(0)));
|
|
31781
|
-
tagP = (0, utils_js_1.concatBytes)(tagH, tagH);
|
|
31782
|
-
TAGGED_HASH_PREFIXES[tag] = tagP;
|
|
31783
|
-
}
|
|
31784
|
-
return (0, sha256_1.sha256)((0, utils_js_1.concatBytes)(tagP, ...messages));
|
|
31785
|
-
}
|
|
31786
|
-
// ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03
|
|
31787
|
-
const pointToBytes = (point) => point.toRawBytes(true).slice(1);
|
|
31788
|
-
const numTo32b = (n) => (0, utils_js_1.numberToBytesBE)(n, 32);
|
|
31789
|
-
const modP = (x) => (0, modular_js_1.mod)(x, secp256k1P);
|
|
31790
|
-
const modN = (x) => (0, modular_js_1.mod)(x, secp256k1N);
|
|
31791
|
-
const Point = exports.secp256k1.ProjectivePoint;
|
|
31792
|
-
const GmulAdd = (Q, a, b) => Point.BASE.multiplyAndAddUnsafe(Q, a, b);
|
|
31793
|
-
// Calculate point, scalar and bytes
|
|
31794
|
-
function schnorrGetExtPubKey(priv) {
|
|
31795
|
-
let d_ = exports.secp256k1.utils.normPrivateKeyToScalar(priv); // same method executed in fromPrivateKey
|
|
31796
|
-
let p = Point.fromPrivateKey(d_); // P = d'⋅G; 0 < d' < n check is done inside
|
|
31797
|
-
const scalar = p.hasEvenY() ? d_ : modN(-d_);
|
|
31798
|
-
return { scalar: scalar, bytes: pointToBytes(p) };
|
|
31799
|
-
}
|
|
31800
|
-
/**
|
|
31801
|
-
* lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
|
|
31802
|
-
* @returns valid point checked for being on-curve
|
|
31803
|
-
*/
|
|
31804
|
-
function lift_x(x) {
|
|
31805
|
-
if (!fe(x))
|
|
31806
|
-
throw new Error('bad x: need 0 < x < p'); // Fail if x ≥ p.
|
|
31807
|
-
const xx = modP(x * x);
|
|
31808
|
-
const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
|
|
31809
|
-
let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
|
|
31810
|
-
if (y % _2n !== _0n)
|
|
31811
|
-
y = modP(-y); // Return the unique point P such that x(P) = x and
|
|
31812
|
-
const p = new Point(x, y, _1n); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
|
|
31813
|
-
p.assertValidity();
|
|
31814
|
-
return p;
|
|
31815
|
-
}
|
|
31816
|
-
/**
|
|
31817
|
-
* Create tagged hash, convert it to bigint, reduce modulo-n.
|
|
31818
|
-
*/
|
|
31819
|
-
function challenge(...args) {
|
|
31820
|
-
return modN((0, utils_js_1.bytesToNumberBE)(taggedHash('BIP0340/challenge', ...args)));
|
|
31821
|
-
}
|
|
31822
|
-
/**
|
|
31823
|
-
* Schnorr public key is just `x` coordinate of Point as per BIP340.
|
|
31824
|
-
*/
|
|
31825
|
-
function schnorrGetPublicKey(privateKey) {
|
|
31826
|
-
return schnorrGetExtPubKey(privateKey).bytes; // d'=int(sk). Fail if d'=0 or d'≥n. Ret bytes(d'⋅G)
|
|
31827
|
-
}
|
|
31828
|
-
/**
|
|
31829
|
-
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
|
|
31830
|
-
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
|
|
31831
|
-
*/
|
|
31832
|
-
function schnorrSign(message, privateKey, auxRand = (0, utils_1.randomBytes)(32)) {
|
|
31833
|
-
const m = (0, utils_js_1.ensureBytes)('message', message);
|
|
31834
|
-
const { bytes: px, scalar: d } = schnorrGetExtPubKey(privateKey); // checks for isWithinCurveOrder
|
|
31835
|
-
const a = (0, utils_js_1.ensureBytes)('auxRand', auxRand, 32); // Auxiliary random data a: a 32-byte array
|
|
31836
|
-
const t = numTo32b(d ^ (0, utils_js_1.bytesToNumberBE)(taggedHash('BIP0340/aux', a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
|
|
31837
|
-
const rand = taggedHash('BIP0340/nonce', t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
|
|
31838
|
-
const k_ = modN((0, utils_js_1.bytesToNumberBE)(rand)); // Let k' = int(rand) mod n
|
|
31839
|
-
if (k_ === _0n)
|
|
31840
|
-
throw new Error('sign failed: k is zero'); // Fail if k' = 0.
|
|
31841
|
-
const { bytes: rx, scalar: k } = schnorrGetExtPubKey(k_); // Let R = k'⋅G.
|
|
31842
|
-
const e = challenge(rx, px, m); // Let e = int(hash/challenge(bytes(R) || bytes(P) || m)) mod n.
|
|
31843
|
-
const sig = new Uint8Array(64); // Let sig = bytes(R) || bytes((k + ed) mod n).
|
|
31844
|
-
sig.set(rx, 0);
|
|
31845
|
-
sig.set(numTo32b(modN(k + e * d)), 32);
|
|
31846
|
-
// If Verify(bytes(P), m, sig) (see below) returns failure, abort
|
|
31847
|
-
if (!schnorrVerify(sig, m, px))
|
|
31848
|
-
throw new Error('sign: Invalid signature produced');
|
|
31849
|
-
return sig;
|
|
31850
|
-
}
|
|
31851
|
-
/**
|
|
31852
|
-
* Verifies Schnorr signature.
|
|
31853
|
-
* Will swallow errors & return false except for initial type validation of arguments.
|
|
31854
|
-
*/
|
|
31855
|
-
function schnorrVerify(signature, message, publicKey) {
|
|
31856
|
-
const sig = (0, utils_js_1.ensureBytes)('signature', signature, 64);
|
|
31857
|
-
const m = (0, utils_js_1.ensureBytes)('message', message);
|
|
31858
|
-
const pub = (0, utils_js_1.ensureBytes)('publicKey', publicKey, 32);
|
|
31859
|
-
try {
|
|
31860
|
-
const P = lift_x((0, utils_js_1.bytesToNumberBE)(pub)); // P = lift_x(int(pk)); fail if that fails
|
|
31861
|
-
const r = (0, utils_js_1.bytesToNumberBE)(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
31862
|
-
if (!fe(r))
|
|
31863
|
-
return false;
|
|
31864
|
-
const s = (0, utils_js_1.bytesToNumberBE)(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
31865
|
-
if (!ge(s))
|
|
31866
|
-
return false;
|
|
31867
|
-
const e = challenge(numTo32b(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
|
|
31868
|
-
const R = GmulAdd(P, s, modN(-e)); // R = s⋅G - e⋅P
|
|
31869
|
-
if (!R || !R.hasEvenY() || R.toAffine().x !== r)
|
|
31870
|
-
return false; // -eP == (n-e)P
|
|
31871
|
-
return true; // Fail if is_infinite(R) / not has_even_y(R) / x(R) ≠ r.
|
|
31872
|
-
}
|
|
31873
|
-
catch (error) {
|
|
31874
|
-
return false;
|
|
31875
|
-
}
|
|
31876
|
-
}
|
|
31877
|
-
exports.schnorr = {
|
|
31878
|
-
getPublicKey: schnorrGetPublicKey,
|
|
31879
|
-
sign: schnorrSign,
|
|
31880
|
-
verify: schnorrVerify,
|
|
31881
|
-
utils: {
|
|
31882
|
-
randomPrivateKey: exports.secp256k1.utils.randomPrivateKey,
|
|
31883
|
-
lift_x,
|
|
31884
|
-
pointToBytes,
|
|
31885
|
-
numberToBytesBE: utils_js_1.numberToBytesBE,
|
|
31886
|
-
bytesToNumberBE: utils_js_1.bytesToNumberBE,
|
|
31887
|
-
taggedHash,
|
|
31888
|
-
mod: modular_js_1.mod,
|
|
31889
|
-
},
|
|
31890
|
-
};
|
|
31891
|
-
const isoMap = htf.isogenyMap(Fp, [
|
|
31892
|
-
// xNum
|
|
31893
|
-
[
|
|
31894
|
-
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7',
|
|
31895
|
-
'0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581',
|
|
31896
|
-
'0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262',
|
|
31897
|
-
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c',
|
|
31898
|
-
],
|
|
31899
|
-
// xDen
|
|
31900
|
-
[
|
|
31901
|
-
'0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b',
|
|
31902
|
-
'0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14',
|
|
31903
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
31904
|
-
],
|
|
31905
|
-
// yNum
|
|
31906
|
-
[
|
|
31907
|
-
'0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c',
|
|
31908
|
-
'0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3',
|
|
31909
|
-
'0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931',
|
|
31910
|
-
'0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84',
|
|
31911
|
-
],
|
|
31912
|
-
// yDen
|
|
31913
|
-
[
|
|
31914
|
-
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b',
|
|
31915
|
-
'0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573',
|
|
31916
|
-
'0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f',
|
|
31917
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
31918
|
-
],
|
|
31919
|
-
].map((i) => i.map((j) => BigInt(j))));
|
|
31920
|
-
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
31921
|
-
A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),
|
|
31922
|
-
B: BigInt('1771'),
|
|
31923
|
-
Z: Fp.create(BigInt('-11')),
|
|
31924
|
-
});
|
|
31925
|
-
_a = htf.createHasher(exports.secp256k1.ProjectivePoint, (scalars) => {
|
|
31926
|
-
const { x, y } = mapSWU(Fp.create(scalars[0]));
|
|
31927
|
-
return isoMap(x, y);
|
|
31928
|
-
}, {
|
|
31929
|
-
DST: 'secp256k1_XMD:SHA-256_SSWU_RO_',
|
|
31930
|
-
encodeDST: 'secp256k1_XMD:SHA-256_SSWU_NU_',
|
|
31931
|
-
p: Fp.ORDER,
|
|
31932
|
-
m: 1,
|
|
31933
|
-
k: 128,
|
|
31934
|
-
expand: 'xmd',
|
|
31935
|
-
hash: sha256_1.sha256,
|
|
31936
|
-
}), exports.hashToCurve = _a.hashToCurve, exports.encodeToCurve = _a.encodeToCurve;
|
|
31937
|
-
//# sourceMappingURL=secp256k1.js.map
|
|
31938
|
-
|
|
31939
|
-
/***/ }),
|
|
31940
|
-
|
|
31941
|
-
/***/ "./node_modules/@noble/hashes/_assert.js":
|
|
31942
|
-
/*!***********************************************!*\
|
|
31943
|
-
!*** ./node_modules/@noble/hashes/_assert.js ***!
|
|
31944
|
-
\***********************************************/
|
|
31945
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
31946
|
-
|
|
31947
|
-
"use strict";
|
|
31948
|
-
|
|
31949
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
31950
|
-
exports.output = exports.exists = exports.hash = exports.bytes = exports.bool = exports.number = void 0;
|
|
31951
|
-
function number(n) {
|
|
31952
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
31953
|
-
throw new Error(`Wrong positive integer: ${n}`);
|
|
31954
|
-
}
|
|
31955
|
-
exports.number = number;
|
|
31956
|
-
function bool(b) {
|
|
31957
|
-
if (typeof b !== 'boolean')
|
|
31958
|
-
throw new Error(`Expected boolean, not ${b}`);
|
|
31959
|
-
}
|
|
31960
|
-
exports.bool = bool;
|
|
31961
|
-
function bytes(b, ...lengths) {
|
|
31962
|
-
if (!(b instanceof Uint8Array))
|
|
31963
|
-
throw new TypeError('Expected Uint8Array');
|
|
31964
|
-
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
31965
|
-
throw new TypeError(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
31966
|
-
}
|
|
31967
|
-
exports.bytes = bytes;
|
|
31968
|
-
function hash(hash) {
|
|
31969
|
-
if (typeof hash !== 'function' || typeof hash.create !== 'function')
|
|
31970
|
-
throw new Error('Hash should be wrapped by utils.wrapConstructor');
|
|
31971
|
-
number(hash.outputLen);
|
|
31972
|
-
number(hash.blockLen);
|
|
31973
|
-
}
|
|
31974
|
-
exports.hash = hash;
|
|
31975
|
-
function exists(instance, checkFinished = true) {
|
|
31976
|
-
if (instance.destroyed)
|
|
31977
|
-
throw new Error('Hash instance has been destroyed');
|
|
31978
|
-
if (checkFinished && instance.finished)
|
|
31979
|
-
throw new Error('Hash#digest() has already been called');
|
|
31980
|
-
}
|
|
31981
|
-
exports.exists = exists;
|
|
31982
|
-
function output(out, instance) {
|
|
31983
|
-
bytes(out);
|
|
31984
|
-
const min = instance.outputLen;
|
|
31985
|
-
if (out.length < min) {
|
|
31986
|
-
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
31987
|
-
}
|
|
31988
|
-
}
|
|
31989
|
-
exports.output = output;
|
|
31990
|
-
const assert = {
|
|
31991
|
-
number,
|
|
31992
|
-
bool,
|
|
31993
|
-
bytes,
|
|
31994
|
-
hash,
|
|
31995
|
-
exists,
|
|
31996
|
-
output,
|
|
31997
|
-
};
|
|
31998
|
-
exports["default"] = assert;
|
|
31999
|
-
//# sourceMappingURL=_assert.js.map
|
|
32000
|
-
|
|
32001
|
-
/***/ }),
|
|
32002
|
-
|
|
32003
|
-
/***/ "./node_modules/@noble/hashes/_sha2.js":
|
|
32004
|
-
/*!*********************************************!*\
|
|
32005
|
-
!*** ./node_modules/@noble/hashes/_sha2.js ***!
|
|
32006
|
-
\*********************************************/
|
|
32007
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
32008
|
-
|
|
32009
|
-
"use strict";
|
|
32010
|
-
|
|
32011
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
32012
|
-
exports.SHA2 = void 0;
|
|
32013
|
-
const _assert_js_1 = __webpack_require__(/*! ./_assert.js */ "./node_modules/@noble/hashes/_assert.js");
|
|
32014
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
32015
|
-
// Polyfill for Safari 14
|
|
32016
|
-
function setBigUint64(view, byteOffset, value, isLE) {
|
|
32017
|
-
if (typeof view.setBigUint64 === 'function')
|
|
32018
|
-
return view.setBigUint64(byteOffset, value, isLE);
|
|
32019
|
-
const _32n = BigInt(32);
|
|
32020
|
-
const _u32_max = BigInt(0xffffffff);
|
|
32021
|
-
const wh = Number((value >> _32n) & _u32_max);
|
|
32022
|
-
const wl = Number(value & _u32_max);
|
|
32023
|
-
const h = isLE ? 4 : 0;
|
|
32024
|
-
const l = isLE ? 0 : 4;
|
|
32025
|
-
view.setUint32(byteOffset + h, wh, isLE);
|
|
32026
|
-
view.setUint32(byteOffset + l, wl, isLE);
|
|
32027
|
-
}
|
|
32028
|
-
// Base SHA2 class (RFC 6234)
|
|
32029
|
-
class SHA2 extends utils_js_1.Hash {
|
|
32030
|
-
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
32031
|
-
super();
|
|
32032
|
-
this.blockLen = blockLen;
|
|
32033
|
-
this.outputLen = outputLen;
|
|
32034
|
-
this.padOffset = padOffset;
|
|
32035
|
-
this.isLE = isLE;
|
|
32036
|
-
this.finished = false;
|
|
32037
|
-
this.length = 0;
|
|
32038
|
-
this.pos = 0;
|
|
32039
|
-
this.destroyed = false;
|
|
32040
|
-
this.buffer = new Uint8Array(blockLen);
|
|
32041
|
-
this.view = (0, utils_js_1.createView)(this.buffer);
|
|
32042
|
-
}
|
|
32043
|
-
update(data) {
|
|
32044
|
-
_assert_js_1.default.exists(this);
|
|
32045
|
-
const { view, buffer, blockLen } = this;
|
|
32046
|
-
data = (0, utils_js_1.toBytes)(data);
|
|
32047
|
-
const len = data.length;
|
|
32048
|
-
for (let pos = 0; pos < len;) {
|
|
32049
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
32050
|
-
// Fast path: we have at least one block in input, cast it to view and process
|
|
32051
|
-
if (take === blockLen) {
|
|
32052
|
-
const dataView = (0, utils_js_1.createView)(data);
|
|
32053
|
-
for (; blockLen <= len - pos; pos += blockLen)
|
|
32054
|
-
this.process(dataView, pos);
|
|
32055
|
-
continue;
|
|
32056
|
-
}
|
|
32057
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
32058
|
-
this.pos += take;
|
|
32059
|
-
pos += take;
|
|
32060
|
-
if (this.pos === blockLen) {
|
|
32061
|
-
this.process(view, 0);
|
|
32062
|
-
this.pos = 0;
|
|
32063
|
-
}
|
|
32064
|
-
}
|
|
32065
|
-
this.length += data.length;
|
|
32066
|
-
this.roundClean();
|
|
32067
|
-
return this;
|
|
32068
|
-
}
|
|
32069
|
-
digestInto(out) {
|
|
32070
|
-
_assert_js_1.default.exists(this);
|
|
32071
|
-
_assert_js_1.default.output(out, this);
|
|
32072
|
-
this.finished = true;
|
|
32073
|
-
// Padding
|
|
32074
|
-
// We can avoid allocation of buffer for padding completely if it
|
|
32075
|
-
// was previously not allocated here. But it won't change performance.
|
|
32076
|
-
const { buffer, view, blockLen, isLE } = this;
|
|
32077
|
-
let { pos } = this;
|
|
32078
|
-
// append the bit '1' to the message
|
|
32079
|
-
buffer[pos++] = 0b10000000;
|
|
32080
|
-
this.buffer.subarray(pos).fill(0);
|
|
32081
|
-
// we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
|
|
32082
|
-
if (this.padOffset > blockLen - pos) {
|
|
32083
|
-
this.process(view, 0);
|
|
32084
|
-
pos = 0;
|
|
32085
|
-
}
|
|
32086
|
-
// Pad until full block byte with zeros
|
|
32087
|
-
for (let i = pos; i < blockLen; i++)
|
|
32088
|
-
buffer[i] = 0;
|
|
32089
|
-
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
32090
|
-
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
32091
|
-
// So we just write lowest 64 bits of that value.
|
|
32092
|
-
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
32093
|
-
this.process(view, 0);
|
|
32094
|
-
const oview = (0, utils_js_1.createView)(out);
|
|
32095
|
-
const len = this.outputLen;
|
|
32096
|
-
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
|
32097
|
-
if (len % 4)
|
|
32098
|
-
throw new Error('_sha2: outputLen should be aligned to 32bit');
|
|
32099
|
-
const outLen = len / 4;
|
|
32100
|
-
const state = this.get();
|
|
32101
|
-
if (outLen > state.length)
|
|
32102
|
-
throw new Error('_sha2: outputLen bigger than state');
|
|
32103
|
-
for (let i = 0; i < outLen; i++)
|
|
32104
|
-
oview.setUint32(4 * i, state[i], isLE);
|
|
32105
|
-
}
|
|
32106
|
-
digest() {
|
|
32107
|
-
const { buffer, outputLen } = this;
|
|
32108
|
-
this.digestInto(buffer);
|
|
32109
|
-
const res = buffer.slice(0, outputLen);
|
|
32110
|
-
this.destroy();
|
|
32111
|
-
return res;
|
|
32112
|
-
}
|
|
32113
|
-
_cloneInto(to) {
|
|
32114
|
-
to || (to = new this.constructor());
|
|
32115
|
-
to.set(...this.get());
|
|
32116
|
-
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
32117
|
-
to.length = length;
|
|
32118
|
-
to.pos = pos;
|
|
32119
|
-
to.finished = finished;
|
|
32120
|
-
to.destroyed = destroyed;
|
|
32121
|
-
if (length % blockLen)
|
|
32122
|
-
to.buffer.set(buffer);
|
|
32123
|
-
return to;
|
|
32124
|
-
}
|
|
32125
|
-
}
|
|
32126
|
-
exports.SHA2 = SHA2;
|
|
32127
|
-
//# sourceMappingURL=_sha2.js.map
|
|
32128
|
-
|
|
32129
|
-
/***/ }),
|
|
32130
|
-
|
|
32131
|
-
/***/ "./node_modules/@noble/hashes/crypto.js":
|
|
32132
|
-
/*!**********************************************!*\
|
|
32133
|
-
!*** ./node_modules/@noble/hashes/crypto.js ***!
|
|
32134
|
-
\**********************************************/
|
|
32135
|
-
/***/ ((__unused_webpack_module, exports) => {
|
|
32136
|
-
|
|
32137
|
-
"use strict";
|
|
32138
|
-
|
|
32139
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
32140
|
-
exports.crypto = void 0;
|
|
32141
|
-
exports.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
32142
|
-
//# sourceMappingURL=crypto.js.map
|
|
32143
|
-
|
|
32144
|
-
/***/ }),
|
|
32145
|
-
|
|
32146
|
-
/***/ "./node_modules/@noble/hashes/hmac.js":
|
|
32147
|
-
/*!********************************************!*\
|
|
32148
|
-
!*** ./node_modules/@noble/hashes/hmac.js ***!
|
|
32149
|
-
\********************************************/
|
|
32150
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
32151
|
-
|
|
32152
|
-
"use strict";
|
|
32153
|
-
|
|
32154
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
32155
|
-
exports.hmac = void 0;
|
|
32156
|
-
const _assert_js_1 = __webpack_require__(/*! ./_assert.js */ "./node_modules/@noble/hashes/_assert.js");
|
|
32157
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
32158
|
-
// HMAC (RFC 2104)
|
|
32159
|
-
class HMAC extends utils_js_1.Hash {
|
|
32160
|
-
constructor(hash, _key) {
|
|
32161
|
-
super();
|
|
32162
|
-
this.finished = false;
|
|
32163
|
-
this.destroyed = false;
|
|
32164
|
-
_assert_js_1.default.hash(hash);
|
|
32165
|
-
const key = (0, utils_js_1.toBytes)(_key);
|
|
32166
|
-
this.iHash = hash.create();
|
|
32167
|
-
if (typeof this.iHash.update !== 'function')
|
|
32168
|
-
throw new TypeError('Expected instance of class which extends utils.Hash');
|
|
32169
|
-
this.blockLen = this.iHash.blockLen;
|
|
32170
|
-
this.outputLen = this.iHash.outputLen;
|
|
32171
|
-
const blockLen = this.blockLen;
|
|
32172
|
-
const pad = new Uint8Array(blockLen);
|
|
32173
|
-
// blockLen can be bigger than outputLen
|
|
32174
|
-
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
32175
|
-
for (let i = 0; i < pad.length; i++)
|
|
32176
|
-
pad[i] ^= 0x36;
|
|
32177
|
-
this.iHash.update(pad);
|
|
32178
|
-
// By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
|
|
32179
|
-
this.oHash = hash.create();
|
|
32180
|
-
// Undo internal XOR && apply outer XOR
|
|
32181
|
-
for (let i = 0; i < pad.length; i++)
|
|
32182
|
-
pad[i] ^= 0x36 ^ 0x5c;
|
|
32183
|
-
this.oHash.update(pad);
|
|
32184
|
-
pad.fill(0);
|
|
32185
|
-
}
|
|
32186
|
-
update(buf) {
|
|
32187
|
-
_assert_js_1.default.exists(this);
|
|
32188
|
-
this.iHash.update(buf);
|
|
32189
|
-
return this;
|
|
32190
|
-
}
|
|
32191
|
-
digestInto(out) {
|
|
32192
|
-
_assert_js_1.default.exists(this);
|
|
32193
|
-
_assert_js_1.default.bytes(out, this.outputLen);
|
|
32194
|
-
this.finished = true;
|
|
32195
|
-
this.iHash.digestInto(out);
|
|
32196
|
-
this.oHash.update(out);
|
|
32197
|
-
this.oHash.digestInto(out);
|
|
32198
|
-
this.destroy();
|
|
32199
|
-
}
|
|
32200
|
-
digest() {
|
|
32201
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
32202
|
-
this.digestInto(out);
|
|
32203
|
-
return out;
|
|
32204
|
-
}
|
|
32205
|
-
_cloneInto(to) {
|
|
32206
|
-
// Create new instance without calling constructor since key already in state and we don't know it.
|
|
32207
|
-
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
32208
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
32209
|
-
to = to;
|
|
32210
|
-
to.finished = finished;
|
|
32211
|
-
to.destroyed = destroyed;
|
|
32212
|
-
to.blockLen = blockLen;
|
|
32213
|
-
to.outputLen = outputLen;
|
|
32214
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
32215
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
32216
|
-
return to;
|
|
32217
|
-
}
|
|
32218
|
-
destroy() {
|
|
32219
|
-
this.destroyed = true;
|
|
32220
|
-
this.oHash.destroy();
|
|
32221
|
-
this.iHash.destroy();
|
|
32222
|
-
}
|
|
32223
|
-
}
|
|
32224
|
-
/**
|
|
32225
|
-
* HMAC: RFC2104 message authentication code.
|
|
32226
|
-
* @param hash - function that would be used e.g. sha256
|
|
32227
|
-
* @param key - message key
|
|
32228
|
-
* @param message - message data
|
|
32229
|
-
*/
|
|
32230
|
-
const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
32231
|
-
exports.hmac = hmac;
|
|
32232
|
-
exports.hmac.create = (hash, key) => new HMAC(hash, key);
|
|
32233
|
-
//# sourceMappingURL=hmac.js.map
|
|
32234
|
-
|
|
32235
|
-
/***/ }),
|
|
32236
|
-
|
|
32237
|
-
/***/ "./node_modules/@noble/hashes/sha256.js":
|
|
32238
|
-
/*!**********************************************!*\
|
|
32239
|
-
!*** ./node_modules/@noble/hashes/sha256.js ***!
|
|
32240
|
-
\**********************************************/
|
|
32241
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
32242
|
-
|
|
32243
|
-
"use strict";
|
|
32244
|
-
|
|
32245
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
32246
|
-
exports.sha224 = exports.sha256 = void 0;
|
|
32247
|
-
const _sha2_js_1 = __webpack_require__(/*! ./_sha2.js */ "./node_modules/@noble/hashes/_sha2.js");
|
|
32248
|
-
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
32249
|
-
// Choice: a ? b : c
|
|
32250
|
-
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
32251
|
-
// Majority function, true if any two inpust is true
|
|
32252
|
-
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
32253
|
-
// Round constants:
|
|
32254
|
-
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
32255
|
-
// prettier-ignore
|
|
32256
|
-
const SHA256_K = new Uint32Array([
|
|
32257
|
-
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
32258
|
-
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
32259
|
-
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
32260
|
-
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
32261
|
-
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
32262
|
-
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
32263
|
-
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
32264
|
-
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
32265
|
-
]);
|
|
32266
|
-
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
|
32267
|
-
// prettier-ignore
|
|
32268
|
-
const IV = new Uint32Array([
|
|
32269
|
-
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
32270
|
-
]);
|
|
32271
|
-
// Temporary buffer, not used to store anything between runs
|
|
32272
|
-
// Named this way because it matches specification.
|
|
32273
|
-
const SHA256_W = new Uint32Array(64);
|
|
32274
|
-
class SHA256 extends _sha2_js_1.SHA2 {
|
|
32275
|
-
constructor() {
|
|
32276
|
-
super(64, 32, 8, false);
|
|
32277
|
-
// We cannot use array here since array allows indexing by variable
|
|
32278
|
-
// which means optimizer/compiler cannot use registers.
|
|
32279
|
-
this.A = IV[0] | 0;
|
|
32280
|
-
this.B = IV[1] | 0;
|
|
32281
|
-
this.C = IV[2] | 0;
|
|
32282
|
-
this.D = IV[3] | 0;
|
|
32283
|
-
this.E = IV[4] | 0;
|
|
32284
|
-
this.F = IV[5] | 0;
|
|
32285
|
-
this.G = IV[6] | 0;
|
|
32286
|
-
this.H = IV[7] | 0;
|
|
32287
|
-
}
|
|
32288
|
-
get() {
|
|
32289
|
-
const { A, B, C, D, E, F, G, H } = this;
|
|
32290
|
-
return [A, B, C, D, E, F, G, H];
|
|
32291
|
-
}
|
|
32292
|
-
// prettier-ignore
|
|
32293
|
-
set(A, B, C, D, E, F, G, H) {
|
|
32294
|
-
this.A = A | 0;
|
|
32295
|
-
this.B = B | 0;
|
|
32296
|
-
this.C = C | 0;
|
|
32297
|
-
this.D = D | 0;
|
|
32298
|
-
this.E = E | 0;
|
|
32299
|
-
this.F = F | 0;
|
|
32300
|
-
this.G = G | 0;
|
|
32301
|
-
this.H = H | 0;
|
|
32302
|
-
}
|
|
32303
|
-
process(view, offset) {
|
|
32304
|
-
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
32305
|
-
for (let i = 0; i < 16; i++, offset += 4)
|
|
32306
|
-
SHA256_W[i] = view.getUint32(offset, false);
|
|
32307
|
-
for (let i = 16; i < 64; i++) {
|
|
32308
|
-
const W15 = SHA256_W[i - 15];
|
|
32309
|
-
const W2 = SHA256_W[i - 2];
|
|
32310
|
-
const s0 = (0, utils_js_1.rotr)(W15, 7) ^ (0, utils_js_1.rotr)(W15, 18) ^ (W15 >>> 3);
|
|
32311
|
-
const s1 = (0, utils_js_1.rotr)(W2, 17) ^ (0, utils_js_1.rotr)(W2, 19) ^ (W2 >>> 10);
|
|
32312
|
-
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
|
32313
|
-
}
|
|
32314
|
-
// Compression function main loop, 64 rounds
|
|
32315
|
-
let { A, B, C, D, E, F, G, H } = this;
|
|
32316
|
-
for (let i = 0; i < 64; i++) {
|
|
32317
|
-
const sigma1 = (0, utils_js_1.rotr)(E, 6) ^ (0, utils_js_1.rotr)(E, 11) ^ (0, utils_js_1.rotr)(E, 25);
|
|
32318
|
-
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
32319
|
-
const sigma0 = (0, utils_js_1.rotr)(A, 2) ^ (0, utils_js_1.rotr)(A, 13) ^ (0, utils_js_1.rotr)(A, 22);
|
|
32320
|
-
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
|
32321
|
-
H = G;
|
|
32322
|
-
G = F;
|
|
32323
|
-
F = E;
|
|
32324
|
-
E = (D + T1) | 0;
|
|
32325
|
-
D = C;
|
|
32326
|
-
C = B;
|
|
32327
|
-
B = A;
|
|
32328
|
-
A = (T1 + T2) | 0;
|
|
32329
|
-
}
|
|
32330
|
-
// Add the compressed chunk to the current hash value
|
|
32331
|
-
A = (A + this.A) | 0;
|
|
32332
|
-
B = (B + this.B) | 0;
|
|
32333
|
-
C = (C + this.C) | 0;
|
|
32334
|
-
D = (D + this.D) | 0;
|
|
32335
|
-
E = (E + this.E) | 0;
|
|
32336
|
-
F = (F + this.F) | 0;
|
|
32337
|
-
G = (G + this.G) | 0;
|
|
32338
|
-
H = (H + this.H) | 0;
|
|
32339
|
-
this.set(A, B, C, D, E, F, G, H);
|
|
32340
|
-
}
|
|
32341
|
-
roundClean() {
|
|
32342
|
-
SHA256_W.fill(0);
|
|
32343
|
-
}
|
|
32344
|
-
destroy() {
|
|
32345
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
32346
|
-
this.buffer.fill(0);
|
|
32347
|
-
}
|
|
32348
|
-
}
|
|
32349
|
-
// Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
|
32350
|
-
class SHA224 extends SHA256 {
|
|
32351
|
-
constructor() {
|
|
32352
|
-
super();
|
|
32353
|
-
this.A = 0xc1059ed8 | 0;
|
|
32354
|
-
this.B = 0x367cd507 | 0;
|
|
32355
|
-
this.C = 0x3070dd17 | 0;
|
|
32356
|
-
this.D = 0xf70e5939 | 0;
|
|
32357
|
-
this.E = 0xffc00b31 | 0;
|
|
32358
|
-
this.F = 0x68581511 | 0;
|
|
32359
|
-
this.G = 0x64f98fa7 | 0;
|
|
32360
|
-
this.H = 0xbefa4fa4 | 0;
|
|
32361
|
-
this.outputLen = 28;
|
|
32362
|
-
}
|
|
32363
|
-
}
|
|
32364
|
-
/**
|
|
32365
|
-
* SHA2-256 hash function
|
|
32366
|
-
* @param message - data that would be hashed
|
|
32367
|
-
*/
|
|
32368
|
-
exports.sha256 = (0, utils_js_1.wrapConstructor)(() => new SHA256());
|
|
32369
|
-
exports.sha224 = (0, utils_js_1.wrapConstructor)(() => new SHA224());
|
|
32370
|
-
//# sourceMappingURL=sha256.js.map
|
|
32371
|
-
|
|
32372
|
-
/***/ }),
|
|
32373
|
-
|
|
32374
|
-
/***/ "./node_modules/@noble/hashes/utils.js":
|
|
32375
|
-
/*!*********************************************!*\
|
|
32376
|
-
!*** ./node_modules/@noble/hashes/utils.js ***!
|
|
32377
|
-
\*********************************************/
|
|
32378
|
-
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
32379
|
-
|
|
32380
|
-
"use strict";
|
|
32381
|
-
|
|
32382
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
32383
|
-
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
32384
|
-
exports.randomBytes = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.concatBytes = exports.toBytes = exports.utf8ToBytes = exports.asyncLoop = exports.nextTick = exports.hexToBytes = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
|
|
32385
|
-
// We use `globalThis.crypto`, but node.js versions earlier than v19 don't
|
|
32386
|
-
// declare it in global scope. For node.js, package.json#exports field mapping
|
|
32387
|
-
// rewrites import from `crypto` to `cryptoNode`, which imports native module.
|
|
32388
|
-
// Makes the utils un-importable in browsers without a bundler.
|
|
32389
|
-
// Once node.js 18 is deprecated, we can just drop the import.
|
|
32390
|
-
const crypto_1 = __webpack_require__(/*! @noble/hashes/crypto */ "./node_modules/@noble/hashes/crypto.js");
|
|
32391
|
-
// Cast array to different type
|
|
32392
|
-
const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
32393
|
-
exports.u8 = u8;
|
|
32394
|
-
const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
32395
|
-
exports.u32 = u32;
|
|
32396
|
-
// Cast array to view
|
|
32397
|
-
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
32398
|
-
exports.createView = createView;
|
|
32399
|
-
// The rotate right (circular right shift) operation for uint32
|
|
32400
|
-
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
|
32401
|
-
exports.rotr = rotr;
|
|
32402
|
-
// big-endian hardware is rare. Just in case someone still decides to run hashes:
|
|
32403
|
-
// early-throw an error because we don't support BE yet.
|
|
32404
|
-
exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
32405
|
-
if (!exports.isLE)
|
|
32406
|
-
throw new Error('Non little-endian hardware is not supported');
|
|
32407
|
-
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
|
|
32408
|
-
/**
|
|
32409
|
-
* @example bytesToHex(Uint8Array.from([0xde, 0xad, 0xbe, 0xef])) // 'deadbeef'
|
|
32410
|
-
*/
|
|
32411
|
-
function bytesToHex(uint8a) {
|
|
32412
|
-
// pre-caching improves the speed 6x
|
|
32413
|
-
if (!(uint8a instanceof Uint8Array))
|
|
32414
|
-
throw new Error('Uint8Array expected');
|
|
32415
|
-
let hex = '';
|
|
32416
|
-
for (let i = 0; i < uint8a.length; i++) {
|
|
32417
|
-
hex += hexes[uint8a[i]];
|
|
32418
|
-
}
|
|
32419
|
-
return hex;
|
|
32420
|
-
}
|
|
32421
|
-
exports.bytesToHex = bytesToHex;
|
|
32422
|
-
/**
|
|
32423
|
-
* @example hexToBytes('deadbeef') // Uint8Array.from([0xde, 0xad, 0xbe, 0xef])
|
|
32424
|
-
*/
|
|
32425
|
-
function hexToBytes(hex) {
|
|
32426
|
-
if (typeof hex !== 'string') {
|
|
32427
|
-
throw new TypeError('hexToBytes: expected string, got ' + typeof hex);
|
|
32428
|
-
}
|
|
32429
|
-
if (hex.length % 2)
|
|
32430
|
-
throw new Error('hexToBytes: received invalid unpadded hex');
|
|
32431
|
-
const array = new Uint8Array(hex.length / 2);
|
|
32432
|
-
for (let i = 0; i < array.length; i++) {
|
|
32433
|
-
const j = i * 2;
|
|
32434
|
-
const hexByte = hex.slice(j, j + 2);
|
|
32435
|
-
const byte = Number.parseInt(hexByte, 16);
|
|
32436
|
-
if (Number.isNaN(byte) || byte < 0)
|
|
32437
|
-
throw new Error('Invalid byte sequence');
|
|
32438
|
-
array[i] = byte;
|
|
32439
|
-
}
|
|
32440
|
-
return array;
|
|
32441
|
-
}
|
|
32442
|
-
exports.hexToBytes = hexToBytes;
|
|
32443
|
-
// There is no setImmediate in browser and setTimeout is slow.
|
|
32444
|
-
// call of async fn will return Promise, which will be fullfiled only on
|
|
32445
|
-
// next scheduler queue processing step and this is exactly what we need.
|
|
32446
|
-
const nextTick = async () => { };
|
|
32447
|
-
exports.nextTick = nextTick;
|
|
32448
|
-
// Returns control to thread each 'tick' ms to avoid blocking
|
|
32449
|
-
async function asyncLoop(iters, tick, cb) {
|
|
32450
|
-
let ts = Date.now();
|
|
32451
|
-
for (let i = 0; i < iters; i++) {
|
|
32452
|
-
cb(i);
|
|
32453
|
-
// Date.now() is not monotonic, so in case if clock goes backwards we return return control too
|
|
32454
|
-
const diff = Date.now() - ts;
|
|
32455
|
-
if (diff >= 0 && diff < tick)
|
|
32456
|
-
continue;
|
|
32457
|
-
await (0, exports.nextTick)();
|
|
32458
|
-
ts += diff;
|
|
32459
|
-
}
|
|
32460
|
-
}
|
|
32461
|
-
exports.asyncLoop = asyncLoop;
|
|
32462
|
-
function utf8ToBytes(str) {
|
|
32463
|
-
if (typeof str !== 'string') {
|
|
32464
|
-
throw new TypeError(`utf8ToBytes expected string, got ${typeof str}`);
|
|
32465
|
-
}
|
|
32466
|
-
return new TextEncoder().encode(str);
|
|
32467
|
-
}
|
|
32468
|
-
exports.utf8ToBytes = utf8ToBytes;
|
|
32469
|
-
function toBytes(data) {
|
|
32470
|
-
if (typeof data === 'string')
|
|
32471
|
-
data = utf8ToBytes(data);
|
|
32472
|
-
if (!(data instanceof Uint8Array))
|
|
32473
|
-
throw new TypeError(`Expected input type is Uint8Array (got ${typeof data})`);
|
|
32474
|
-
return data;
|
|
32475
|
-
}
|
|
32476
|
-
exports.toBytes = toBytes;
|
|
32477
|
-
/**
|
|
32478
|
-
* Concats Uint8Array-s into one; like `Buffer.concat([buf1, buf2])`
|
|
32479
|
-
* @example concatBytes(buf1, buf2)
|
|
32480
|
-
*/
|
|
32481
|
-
function concatBytes(...arrays) {
|
|
32482
|
-
if (!arrays.every((a) => a instanceof Uint8Array))
|
|
32483
|
-
throw new Error('Uint8Array list expected');
|
|
32484
|
-
if (arrays.length === 1)
|
|
32485
|
-
return arrays[0];
|
|
32486
|
-
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
32487
|
-
const result = new Uint8Array(length);
|
|
32488
|
-
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
|
32489
|
-
const arr = arrays[i];
|
|
32490
|
-
result.set(arr, pad);
|
|
32491
|
-
pad += arr.length;
|
|
32492
|
-
}
|
|
32493
|
-
return result;
|
|
32494
|
-
}
|
|
32495
|
-
exports.concatBytes = concatBytes;
|
|
32496
|
-
// For runtime check if class implements interface
|
|
32497
|
-
class Hash {
|
|
32498
|
-
// Safe version that clones internal state
|
|
32499
|
-
clone() {
|
|
32500
|
-
return this._cloneInto();
|
|
32501
|
-
}
|
|
32502
|
-
}
|
|
32503
|
-
exports.Hash = Hash;
|
|
32504
|
-
// Check if object doens't have custom constructor (like Uint8Array/Array)
|
|
32505
|
-
const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
|
|
32506
|
-
function checkOpts(defaults, opts) {
|
|
32507
|
-
if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
|
|
32508
|
-
throw new TypeError('Options should be object or undefined');
|
|
32509
|
-
const merged = Object.assign(defaults, opts);
|
|
32510
|
-
return merged;
|
|
32511
|
-
}
|
|
32512
|
-
exports.checkOpts = checkOpts;
|
|
32513
|
-
function wrapConstructor(hashConstructor) {
|
|
32514
|
-
const hashC = (message) => hashConstructor().update(toBytes(message)).digest();
|
|
32515
|
-
const tmp = hashConstructor();
|
|
32516
|
-
hashC.outputLen = tmp.outputLen;
|
|
32517
|
-
hashC.blockLen = tmp.blockLen;
|
|
32518
|
-
hashC.create = () => hashConstructor();
|
|
32519
|
-
return hashC;
|
|
32520
|
-
}
|
|
32521
|
-
exports.wrapConstructor = wrapConstructor;
|
|
32522
|
-
function wrapConstructorWithOpts(hashCons) {
|
|
32523
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
32524
|
-
const tmp = hashCons({});
|
|
32525
|
-
hashC.outputLen = tmp.outputLen;
|
|
32526
|
-
hashC.blockLen = tmp.blockLen;
|
|
32527
|
-
hashC.create = (opts) => hashCons(opts);
|
|
32528
|
-
return hashC;
|
|
32529
|
-
}
|
|
32530
|
-
exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
|
|
32531
|
-
/**
|
|
32532
|
-
* Secure PRNG. Uses `globalThis.crypto` or node.js crypto module.
|
|
32533
|
-
*/
|
|
32534
|
-
function randomBytes(bytesLength = 32) {
|
|
32535
|
-
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === 'function') {
|
|
32536
|
-
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
32537
|
-
}
|
|
32538
|
-
throw new Error('crypto.getRandomValues must be defined');
|
|
32539
|
-
}
|
|
32540
|
-
exports.randomBytes = randomBytes;
|
|
32541
|
-
//# sourceMappingURL=utils.js.map
|
|
32542
|
-
|
|
32543
|
-
/***/ }),
|
|
32544
|
-
|
|
32545
29335
|
/***/ "./node_modules/@xmldom/xmldom/lib/conventions.js":
|
|
32546
29336
|
/*!********************************************************!*\
|
|
32547
29337
|
!*** ./node_modules/@xmldom/xmldom/lib/conventions.js ***!
|
|
@@ -66009,22 +62799,7 @@ module.exports = JSON.parse('{"application/1d-interleaved-parityfec":{"source":"
|
|
|
66009
62799
|
/******/
|
|
66010
62800
|
/******/ /* webpack/runtime/publicPath */
|
|
66011
62801
|
/******/ (() => {
|
|
66012
|
-
/******/
|
|
66013
|
-
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
|
|
66014
|
-
/******/ var document = __webpack_require__.g.document;
|
|
66015
|
-
/******/ if (!scriptUrl && document) {
|
|
66016
|
-
/******/ if (document.currentScript)
|
|
66017
|
-
/******/ scriptUrl = document.currentScript.src;
|
|
66018
|
-
/******/ if (!scriptUrl) {
|
|
66019
|
-
/******/ var scripts = document.getElementsByTagName("script");
|
|
66020
|
-
/******/ if(scripts.length) scriptUrl = scripts[scripts.length - 1].src
|
|
66021
|
-
/******/ }
|
|
66022
|
-
/******/ }
|
|
66023
|
-
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
|
|
66024
|
-
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
|
|
66025
|
-
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
|
|
66026
|
-
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
|
|
66027
|
-
/******/ __webpack_require__.p = scriptUrl;
|
|
62802
|
+
/******/ __webpack_require__.p = "";
|
|
66028
62803
|
/******/ })();
|
|
66029
62804
|
/******/
|
|
66030
62805
|
/******/ /* webpack/runtime/jsonp chunk loading */
|