solid-ui 3.0.1-1f7a1f3 → 3.0.1-2c1067d
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/README.md +1 -1
- package/dist/chat/keys.js +4 -4
- package/dist/chat/keys.js.map +1 -1
- package/dist/chat/signature.js +5 -5
- package/dist/chat/signature.js.map +1 -1
- package/dist/solid-ui.esm.js +11331 -11804
- package/dist/solid-ui.esm.js.map +1 -1
- package/dist/solid-ui.esm.min.js +14 -14
- package/dist/solid-ui.esm.min.js.map +1 -1
- package/dist/solid-ui.js +610 -1029
- package/dist/solid-ui.js.map +1 -1
- package/dist/solid-ui.min.js +7 -9
- package/dist/solid-ui.min.js.map +1 -1
- package/dist/versionInfo.js +2 -2
- package/package.json +3 -3
package/dist/solid-ui.js
CHANGED
|
@@ -14126,44 +14126,42 @@ var DateFolder = /*#__PURE__*/function () {
|
|
|
14126
14126
|
}() // firstleafObject
|
|
14127
14127
|
}]);
|
|
14128
14128
|
}(); // class
|
|
14129
|
-
;// ./node_modules/@noble/hashes/
|
|
14130
|
-
const crypto_crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
14131
|
-
//# sourceMappingURL=crypto.js.map
|
|
14132
|
-
;// ./node_modules/@noble/hashes/esm/utils.js
|
|
14129
|
+
;// ./node_modules/@noble/hashes/utils.js
|
|
14133
14130
|
/**
|
|
14134
14131
|
* Utilities for hex, bytes, CSPRNG.
|
|
14135
14132
|
* @module
|
|
14136
14133
|
*/
|
|
14137
14134
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
14138
|
-
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
14139
|
-
// node.js versions earlier than v19 don't declare it in global scope.
|
|
14140
|
-
// For node.js, package.json#exports field mapping rewrites import
|
|
14141
|
-
// from `crypto` to `cryptoNode`, which imports native module.
|
|
14142
|
-
// Makes the utils un-importable in browsers without a bundler.
|
|
14143
|
-
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
|
14144
|
-
|
|
14145
14135
|
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
14146
|
-
function
|
|
14136
|
+
function utils_isBytes(a) {
|
|
14147
14137
|
return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
|
|
14148
14138
|
}
|
|
14149
14139
|
/** Asserts something is positive integer. */
|
|
14150
|
-
function
|
|
14151
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
14152
|
-
|
|
14140
|
+
function utils_anumber(n, title = '') {
|
|
14141
|
+
if (!Number.isSafeInteger(n) || n < 0) {
|
|
14142
|
+
const prefix = title && `"${title}" `;
|
|
14143
|
+
throw new Error(`${prefix}expected integer >= 0, got ${n}`);
|
|
14144
|
+
}
|
|
14153
14145
|
}
|
|
14154
14146
|
/** Asserts something is Uint8Array. */
|
|
14155
|
-
function
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14147
|
+
function utils_abytes(value, length, title = '') {
|
|
14148
|
+
const bytes = utils_isBytes(value);
|
|
14149
|
+
const len = value?.length;
|
|
14150
|
+
const needsLen = length !== undefined;
|
|
14151
|
+
if (!bytes || (needsLen && len !== length)) {
|
|
14152
|
+
const prefix = title && `"${title}" `;
|
|
14153
|
+
const ofLen = needsLen ? ` of length ${length}` : '';
|
|
14154
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
14155
|
+
throw new Error(prefix + 'expected Uint8Array' + ofLen + ', got ' + got);
|
|
14156
|
+
}
|
|
14157
|
+
return value;
|
|
14160
14158
|
}
|
|
14161
14159
|
/** Asserts something is hash */
|
|
14162
|
-
function
|
|
14160
|
+
function utils_ahash(h) {
|
|
14163
14161
|
if (typeof h !== 'function' || typeof h.create !== 'function')
|
|
14164
|
-
throw new Error('Hash
|
|
14165
|
-
|
|
14166
|
-
|
|
14162
|
+
throw new Error('Hash must wrapped by utils.createHasher');
|
|
14163
|
+
utils_anumber(h.outputLen);
|
|
14164
|
+
utils_anumber(h.blockLen);
|
|
14167
14165
|
}
|
|
14168
14166
|
/** Asserts a hash instance has not been destroyed / finished */
|
|
14169
14167
|
function aexists(instance, checkFinished = true) {
|
|
@@ -14174,10 +14172,10 @@ function aexists(instance, checkFinished = true) {
|
|
|
14174
14172
|
}
|
|
14175
14173
|
/** Asserts output is properly-sized byte array */
|
|
14176
14174
|
function aoutput(out, instance) {
|
|
14177
|
-
|
|
14175
|
+
utils_abytes(out, undefined, 'digestInto() output');
|
|
14178
14176
|
const min = instance.outputLen;
|
|
14179
14177
|
if (out.length < min) {
|
|
14180
|
-
throw new Error('digestInto()
|
|
14178
|
+
throw new Error('"digestInto() output" expected to be of length >=' + min);
|
|
14181
14179
|
}
|
|
14182
14180
|
}
|
|
14183
14181
|
/** Cast u8 / u16 / u32 to u8. */
|
|
@@ -14219,8 +14217,6 @@ function byteSwap(word) {
|
|
|
14219
14217
|
const swap8IfBE = (/* unused pure expression or super */ null && (isLE
|
|
14220
14218
|
? (n) => n
|
|
14221
14219
|
: (n) => byteSwap(n)));
|
|
14222
|
-
/** @deprecated */
|
|
14223
|
-
const byteSwapIfBE = (/* unused pure expression or super */ null && (swap8IfBE));
|
|
14224
14220
|
/** In place byte swap for Uint32Array */
|
|
14225
14221
|
function byteSwap32(arr) {
|
|
14226
14222
|
for (let i = 0; i < arr.length; i++) {
|
|
@@ -14241,8 +14237,8 @@ const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(1
|
|
|
14241
14237
|
* Convert byte array to hex string. Uses built-in function, when available.
|
|
14242
14238
|
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
14243
14239
|
*/
|
|
14244
|
-
function
|
|
14245
|
-
|
|
14240
|
+
function utils_bytesToHex(bytes) {
|
|
14241
|
+
utils_abytes(bytes);
|
|
14246
14242
|
// @ts-ignore
|
|
14247
14243
|
if (hasHexBuiltin)
|
|
14248
14244
|
return bytes.toHex();
|
|
@@ -14268,7 +14264,7 @@ function asciiToBase16(ch) {
|
|
|
14268
14264
|
* Convert hex string to byte array. Uses built-in function, when available.
|
|
14269
14265
|
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
14270
14266
|
*/
|
|
14271
|
-
function
|
|
14267
|
+
function utils_hexToBytes(hex) {
|
|
14272
14268
|
if (typeof hex !== 'string')
|
|
14273
14269
|
throw new Error('hex string expected, got ' + typeof hex);
|
|
14274
14270
|
// @ts-ignore
|
|
@@ -14311,6 +14307,7 @@ async function asyncLoop(iters, tick, cb) {
|
|
|
14311
14307
|
}
|
|
14312
14308
|
/**
|
|
14313
14309
|
* Converts string to bytes using UTF8 encoding.
|
|
14310
|
+
* Built-in doesn't validate input to be string: we do the check.
|
|
14314
14311
|
* @example utf8ToBytes('abc') // Uint8Array.from([97, 98, 99])
|
|
14315
14312
|
*/
|
|
14316
14313
|
function utf8ToBytes(str) {
|
|
@@ -14318,40 +14315,21 @@ function utf8ToBytes(str) {
|
|
|
14318
14315
|
throw new Error('string expected');
|
|
14319
14316
|
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
14320
14317
|
}
|
|
14321
|
-
/**
|
|
14322
|
-
* Converts bytes to string using UTF8 encoding.
|
|
14323
|
-
* @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
|
|
14324
|
-
*/
|
|
14325
|
-
function bytesToUtf8(bytes) {
|
|
14326
|
-
return new TextDecoder().decode(bytes);
|
|
14327
|
-
}
|
|
14328
|
-
/**
|
|
14329
|
-
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
14330
|
-
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
14331
|
-
* Keep in mind for future mutable operations.
|
|
14332
|
-
*/
|
|
14333
|
-
function toBytes(data) {
|
|
14334
|
-
if (typeof data === 'string')
|
|
14335
|
-
data = utf8ToBytes(data);
|
|
14336
|
-
abytes(data);
|
|
14337
|
-
return data;
|
|
14338
|
-
}
|
|
14339
14318
|
/**
|
|
14340
14319
|
* Helper for KDFs: consumes uint8array or string.
|
|
14341
14320
|
* When string is passed, does utf8 decoding, using TextDecoder.
|
|
14342
14321
|
*/
|
|
14343
|
-
function kdfInputToBytes(data) {
|
|
14322
|
+
function kdfInputToBytes(data, errorTitle = '') {
|
|
14344
14323
|
if (typeof data === 'string')
|
|
14345
|
-
|
|
14346
|
-
|
|
14347
|
-
return data;
|
|
14324
|
+
return utf8ToBytes(data);
|
|
14325
|
+
return utils_abytes(data, undefined, errorTitle);
|
|
14348
14326
|
}
|
|
14349
14327
|
/** Copies several Uint8Arrays into one. */
|
|
14350
|
-
function
|
|
14328
|
+
function utils_concatBytes(...arrays) {
|
|
14351
14329
|
let sum = 0;
|
|
14352
14330
|
for (let i = 0; i < arrays.length; i++) {
|
|
14353
14331
|
const a = arrays[i];
|
|
14354
|
-
|
|
14332
|
+
utils_abytes(a);
|
|
14355
14333
|
sum += a.length;
|
|
14356
14334
|
}
|
|
14357
14335
|
const res = new Uint8Array(sum);
|
|
@@ -14362,74 +14340,41 @@ function concatBytes(...arrays) {
|
|
|
14362
14340
|
}
|
|
14363
14341
|
return res;
|
|
14364
14342
|
}
|
|
14343
|
+
/** Merges default options and passed options. */
|
|
14365
14344
|
function checkOpts(defaults, opts) {
|
|
14366
14345
|
if (opts !== undefined && {}.toString.call(opts) !== '[object Object]')
|
|
14367
|
-
throw new Error('options
|
|
14346
|
+
throw new Error('options must be object or undefined');
|
|
14368
14347
|
const merged = Object.assign(defaults, opts);
|
|
14369
14348
|
return merged;
|
|
14370
14349
|
}
|
|
14371
|
-
/**
|
|
14372
|
-
|
|
14373
|
-
|
|
14374
|
-
|
|
14375
|
-
function utils_createHasher(hashCons) {
|
|
14376
|
-
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
14377
|
-
const tmp = hashCons();
|
|
14378
|
-
hashC.outputLen = tmp.outputLen;
|
|
14379
|
-
hashC.blockLen = tmp.blockLen;
|
|
14380
|
-
hashC.create = () => hashCons();
|
|
14381
|
-
return hashC;
|
|
14382
|
-
}
|
|
14383
|
-
function createOptHasher(hashCons) {
|
|
14384
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
14385
|
-
const tmp = hashCons({});
|
|
14350
|
+
/** Creates function with outputLen, blockLen, create properties from a class constructor. */
|
|
14351
|
+
function utils_createHasher(hashCons, info = {}) {
|
|
14352
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
14353
|
+
const tmp = hashCons(undefined);
|
|
14386
14354
|
hashC.outputLen = tmp.outputLen;
|
|
14387
14355
|
hashC.blockLen = tmp.blockLen;
|
|
14388
14356
|
hashC.create = (opts) => hashCons(opts);
|
|
14389
|
-
|
|
14357
|
+
Object.assign(hashC, info);
|
|
14358
|
+
return Object.freeze(hashC);
|
|
14390
14359
|
}
|
|
14391
|
-
function createXOFer(hashCons) {
|
|
14392
|
-
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
14393
|
-
const tmp = hashCons({});
|
|
14394
|
-
hashC.outputLen = tmp.outputLen;
|
|
14395
|
-
hashC.blockLen = tmp.blockLen;
|
|
14396
|
-
hashC.create = (opts) => hashCons(opts);
|
|
14397
|
-
return hashC;
|
|
14398
|
-
}
|
|
14399
|
-
const wrapConstructor = (/* unused pure expression or super */ null && (utils_createHasher));
|
|
14400
|
-
const wrapConstructorWithOpts = (/* unused pure expression or super */ null && (createOptHasher));
|
|
14401
|
-
const wrapXOFConstructorWithOpts = (/* unused pure expression or super */ null && (createXOFer));
|
|
14402
14360
|
/** Cryptographically secure PRNG. Uses internal OS-level `crypto.getRandomValues`. */
|
|
14403
|
-
function
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
|
|
14412
|
-
}
|
|
14361
|
+
function randomBytes(bytesLength = 32) {
|
|
14362
|
+
const cr = typeof globalThis === 'object' ? globalThis.crypto : null;
|
|
14363
|
+
if (typeof cr?.getRandomValues !== 'function')
|
|
14364
|
+
throw new Error('crypto.getRandomValues must be defined');
|
|
14365
|
+
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
14366
|
+
}
|
|
14367
|
+
/** Creates OID opts for NIST hashes, with prefix 06 09 60 86 48 01 65 03 04 02. */
|
|
14368
|
+
const utils_oidNist = (suffix) => ({
|
|
14369
|
+
oid: Uint8Array.from([0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, suffix]),
|
|
14370
|
+
});
|
|
14413
14371
|
//# sourceMappingURL=utils.js.map
|
|
14414
|
-
;// ./node_modules/@noble/hashes/
|
|
14372
|
+
;// ./node_modules/@noble/hashes/_md.js
|
|
14415
14373
|
/**
|
|
14416
14374
|
* Internal Merkle-Damgard hash utils.
|
|
14417
14375
|
* @module
|
|
14418
14376
|
*/
|
|
14419
14377
|
|
|
14420
|
-
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
|
14421
|
-
function setBigUint64(view, byteOffset, value, isLE) {
|
|
14422
|
-
if (typeof view.setBigUint64 === 'function')
|
|
14423
|
-
return view.setBigUint64(byteOffset, value, isLE);
|
|
14424
|
-
const _32n = BigInt(32);
|
|
14425
|
-
const _u32_max = BigInt(0xffffffff);
|
|
14426
|
-
const wh = Number((value >> _32n) & _u32_max);
|
|
14427
|
-
const wl = Number(value & _u32_max);
|
|
14428
|
-
const h = isLE ? 4 : 0;
|
|
14429
|
-
const l = isLE ? 0 : 4;
|
|
14430
|
-
view.setUint32(byteOffset + h, wh, isLE);
|
|
14431
|
-
view.setUint32(byteOffset + l, wl, isLE);
|
|
14432
|
-
}
|
|
14433
14378
|
/** Choice: a ? b : c */
|
|
14434
14379
|
function Chi(a, b, c) {
|
|
14435
14380
|
return (a & b) ^ (~a & c);
|
|
@@ -14442,13 +14387,19 @@ function Maj(a, b, c) {
|
|
|
14442
14387
|
* Merkle-Damgard hash construction base class.
|
|
14443
14388
|
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
|
14444
14389
|
*/
|
|
14445
|
-
class HashMD
|
|
14390
|
+
class HashMD {
|
|
14391
|
+
blockLen;
|
|
14392
|
+
outputLen;
|
|
14393
|
+
padOffset;
|
|
14394
|
+
isLE;
|
|
14395
|
+
// For partial updates less than block size
|
|
14396
|
+
buffer;
|
|
14397
|
+
view;
|
|
14398
|
+
finished = false;
|
|
14399
|
+
length = 0;
|
|
14400
|
+
pos = 0;
|
|
14401
|
+
destroyed = false;
|
|
14446
14402
|
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
14447
|
-
super();
|
|
14448
|
-
this.finished = false;
|
|
14449
|
-
this.length = 0;
|
|
14450
|
-
this.pos = 0;
|
|
14451
|
-
this.destroyed = false;
|
|
14452
14403
|
this.blockLen = blockLen;
|
|
14453
14404
|
this.outputLen = outputLen;
|
|
14454
14405
|
this.padOffset = padOffset;
|
|
@@ -14458,8 +14409,7 @@ class HashMD extends Hash {
|
|
|
14458
14409
|
}
|
|
14459
14410
|
update(data) {
|
|
14460
14411
|
aexists(this);
|
|
14461
|
-
|
|
14462
|
-
abytes(data);
|
|
14412
|
+
utils_abytes(data);
|
|
14463
14413
|
const { view, buffer, blockLen } = this;
|
|
14464
14414
|
const len = data.length;
|
|
14465
14415
|
for (let pos = 0; pos < len;) {
|
|
@@ -14507,13 +14457,13 @@ class HashMD extends Hash {
|
|
|
14507
14457
|
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
14508
14458
|
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
14509
14459
|
// So we just write lowest 64 bits of that value.
|
|
14510
|
-
setBigUint64(
|
|
14460
|
+
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE);
|
|
14511
14461
|
this.process(view, 0);
|
|
14512
14462
|
const oview = createView(out);
|
|
14513
14463
|
const len = this.outputLen;
|
|
14514
|
-
// NOTE: we do division by 4 later, which
|
|
14464
|
+
// NOTE: we do division by 4 later, which must be fused in single op with modulo by JIT
|
|
14515
14465
|
if (len % 4)
|
|
14516
|
-
throw new Error('_sha2: outputLen
|
|
14466
|
+
throw new Error('_sha2: outputLen must be aligned to 32bit');
|
|
14517
14467
|
const outLen = len / 4;
|
|
14518
14468
|
const state = this.get();
|
|
14519
14469
|
if (outLen > state.length)
|
|
@@ -14529,7 +14479,7 @@ class HashMD extends Hash {
|
|
|
14529
14479
|
return res;
|
|
14530
14480
|
}
|
|
14531
14481
|
_cloneInto(to) {
|
|
14532
|
-
to
|
|
14482
|
+
to ||= new this.constructor();
|
|
14533
14483
|
to.set(...this.get());
|
|
14534
14484
|
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
14535
14485
|
to.destroyed = destroyed;
|
|
@@ -14567,7 +14517,7 @@ const SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
|
14567
14517
|
0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179,
|
|
14568
14518
|
]);
|
|
14569
14519
|
//# sourceMappingURL=_md.js.map
|
|
14570
|
-
;// ./node_modules/@noble/hashes/
|
|
14520
|
+
;// ./node_modules/@noble/hashes/_u64.js
|
|
14571
14521
|
/**
|
|
14572
14522
|
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
14573
14523
|
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
@@ -14635,11 +14585,11 @@ const u64 = {
|
|
|
14635
14585
|
};
|
|
14636
14586
|
/* harmony default export */ const _u64 = ((/* unused pure expression or super */ null && (u64)));
|
|
14637
14587
|
//# sourceMappingURL=_u64.js.map
|
|
14638
|
-
;// ./node_modules/@noble/hashes/
|
|
14588
|
+
;// ./node_modules/@noble/hashes/sha2.js
|
|
14639
14589
|
/**
|
|
14640
14590
|
* SHA2 hash function. A.k.a. sha256, sha384, sha512, sha512_224, sha512_256.
|
|
14641
14591
|
* SHA256 is the fastest hash implementable in JS, even faster than Blake3.
|
|
14642
|
-
* Check out [RFC 4634](https://
|
|
14592
|
+
* Check out [RFC 4634](https://www.rfc-editor.org/rfc/rfc4634) and
|
|
14643
14593
|
* [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
14644
14594
|
* @module
|
|
14645
14595
|
*/
|
|
@@ -14663,19 +14613,10 @@ const SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
|
14663
14613
|
]);
|
|
14664
14614
|
/** Reusable temporary buffer. "W" comes straight from spec. */
|
|
14665
14615
|
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
14666
|
-
|
|
14667
|
-
|
|
14616
|
+
/** Internal 32-byte base SHA2 hash class. */
|
|
14617
|
+
class SHA2_32B extends HashMD {
|
|
14618
|
+
constructor(outputLen) {
|
|
14668
14619
|
super(64, outputLen, 8, false);
|
|
14669
|
-
// We cannot use array here since array allows indexing by variable
|
|
14670
|
-
// which means optimizer/compiler cannot use registers.
|
|
14671
|
-
this.A = SHA256_IV[0] | 0;
|
|
14672
|
-
this.B = SHA256_IV[1] | 0;
|
|
14673
|
-
this.C = SHA256_IV[2] | 0;
|
|
14674
|
-
this.D = SHA256_IV[3] | 0;
|
|
14675
|
-
this.E = SHA256_IV[4] | 0;
|
|
14676
|
-
this.F = SHA256_IV[5] | 0;
|
|
14677
|
-
this.G = SHA256_IV[6] | 0;
|
|
14678
|
-
this.H = SHA256_IV[7] | 0;
|
|
14679
14620
|
}
|
|
14680
14621
|
get() {
|
|
14681
14622
|
const { A, B, C, D, E, F, G, H } = this;
|
|
@@ -14738,17 +14679,34 @@ class SHA256 extends HashMD {
|
|
|
14738
14679
|
clean(this.buffer);
|
|
14739
14680
|
}
|
|
14740
14681
|
}
|
|
14741
|
-
|
|
14682
|
+
/** Internal SHA2-256 hash class. */
|
|
14683
|
+
class _SHA256 extends SHA2_32B {
|
|
14684
|
+
// We cannot use array here since array allows indexing by variable
|
|
14685
|
+
// which means optimizer/compiler cannot use registers.
|
|
14686
|
+
A = SHA256_IV[0] | 0;
|
|
14687
|
+
B = SHA256_IV[1] | 0;
|
|
14688
|
+
C = SHA256_IV[2] | 0;
|
|
14689
|
+
D = SHA256_IV[3] | 0;
|
|
14690
|
+
E = SHA256_IV[4] | 0;
|
|
14691
|
+
F = SHA256_IV[5] | 0;
|
|
14692
|
+
G = SHA256_IV[6] | 0;
|
|
14693
|
+
H = SHA256_IV[7] | 0;
|
|
14694
|
+
constructor() {
|
|
14695
|
+
super(32);
|
|
14696
|
+
}
|
|
14697
|
+
}
|
|
14698
|
+
/** Internal SHA2-224 hash class. */
|
|
14699
|
+
class _SHA224 extends SHA2_32B {
|
|
14700
|
+
A = SHA224_IV[0] | 0;
|
|
14701
|
+
B = SHA224_IV[1] | 0;
|
|
14702
|
+
C = SHA224_IV[2] | 0;
|
|
14703
|
+
D = SHA224_IV[3] | 0;
|
|
14704
|
+
E = SHA224_IV[4] | 0;
|
|
14705
|
+
F = SHA224_IV[5] | 0;
|
|
14706
|
+
G = SHA224_IV[6] | 0;
|
|
14707
|
+
H = SHA224_IV[7] | 0;
|
|
14742
14708
|
constructor() {
|
|
14743
14709
|
super(28);
|
|
14744
|
-
this.A = SHA224_IV[0] | 0;
|
|
14745
|
-
this.B = SHA224_IV[1] | 0;
|
|
14746
|
-
this.C = SHA224_IV[2] | 0;
|
|
14747
|
-
this.D = SHA224_IV[3] | 0;
|
|
14748
|
-
this.E = SHA224_IV[4] | 0;
|
|
14749
|
-
this.F = SHA224_IV[5] | 0;
|
|
14750
|
-
this.G = SHA224_IV[6] | 0;
|
|
14751
|
-
this.H = SHA224_IV[7] | 0;
|
|
14752
14710
|
}
|
|
14753
14711
|
}
|
|
14754
14712
|
// SHA2-512 is slower than sha256 in js because u64 operations are slow.
|
|
@@ -14782,28 +14740,10 @@ const SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
|
14782
14740
|
// Reusable temporary buffers
|
|
14783
14741
|
const SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
14784
14742
|
const SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
14785
|
-
|
|
14786
|
-
|
|
14743
|
+
/** Internal 64-byte base SHA2 hash class. */
|
|
14744
|
+
class SHA2_64B extends HashMD {
|
|
14745
|
+
constructor(outputLen) {
|
|
14787
14746
|
super(128, outputLen, 16, false);
|
|
14788
|
-
// We cannot use array here since array allows indexing by variable
|
|
14789
|
-
// which means optimizer/compiler cannot use registers.
|
|
14790
|
-
// h -- high 32 bits, l -- low 32 bits
|
|
14791
|
-
this.Ah = SHA512_IV[0] | 0;
|
|
14792
|
-
this.Al = SHA512_IV[1] | 0;
|
|
14793
|
-
this.Bh = SHA512_IV[2] | 0;
|
|
14794
|
-
this.Bl = SHA512_IV[3] | 0;
|
|
14795
|
-
this.Ch = SHA512_IV[4] | 0;
|
|
14796
|
-
this.Cl = SHA512_IV[5] | 0;
|
|
14797
|
-
this.Dh = SHA512_IV[6] | 0;
|
|
14798
|
-
this.Dl = SHA512_IV[7] | 0;
|
|
14799
|
-
this.Eh = SHA512_IV[8] | 0;
|
|
14800
|
-
this.El = SHA512_IV[9] | 0;
|
|
14801
|
-
this.Fh = SHA512_IV[10] | 0;
|
|
14802
|
-
this.Fl = SHA512_IV[11] | 0;
|
|
14803
|
-
this.Gh = SHA512_IV[12] | 0;
|
|
14804
|
-
this.Gl = SHA512_IV[13] | 0;
|
|
14805
|
-
this.Hh = SHA512_IV[14] | 0;
|
|
14806
|
-
this.Hl = SHA512_IV[15] | 0;
|
|
14807
14747
|
}
|
|
14808
14748
|
// prettier-ignore
|
|
14809
14749
|
get() {
|
|
@@ -14907,25 +14847,48 @@ class SHA512 extends HashMD {
|
|
|
14907
14847
|
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
14908
14848
|
}
|
|
14909
14849
|
}
|
|
14910
|
-
|
|
14850
|
+
/** Internal SHA2-512 hash class. */
|
|
14851
|
+
class _SHA512 extends SHA2_64B {
|
|
14852
|
+
Ah = SHA512_IV[0] | 0;
|
|
14853
|
+
Al = SHA512_IV[1] | 0;
|
|
14854
|
+
Bh = SHA512_IV[2] | 0;
|
|
14855
|
+
Bl = SHA512_IV[3] | 0;
|
|
14856
|
+
Ch = SHA512_IV[4] | 0;
|
|
14857
|
+
Cl = SHA512_IV[5] | 0;
|
|
14858
|
+
Dh = SHA512_IV[6] | 0;
|
|
14859
|
+
Dl = SHA512_IV[7] | 0;
|
|
14860
|
+
Eh = SHA512_IV[8] | 0;
|
|
14861
|
+
El = SHA512_IV[9] | 0;
|
|
14862
|
+
Fh = SHA512_IV[10] | 0;
|
|
14863
|
+
Fl = SHA512_IV[11] | 0;
|
|
14864
|
+
Gh = SHA512_IV[12] | 0;
|
|
14865
|
+
Gl = SHA512_IV[13] | 0;
|
|
14866
|
+
Hh = SHA512_IV[14] | 0;
|
|
14867
|
+
Hl = SHA512_IV[15] | 0;
|
|
14868
|
+
constructor() {
|
|
14869
|
+
super(64);
|
|
14870
|
+
}
|
|
14871
|
+
}
|
|
14872
|
+
/** Internal SHA2-384 hash class. */
|
|
14873
|
+
class _SHA384 extends SHA2_64B {
|
|
14874
|
+
Ah = SHA384_IV[0] | 0;
|
|
14875
|
+
Al = SHA384_IV[1] | 0;
|
|
14876
|
+
Bh = SHA384_IV[2] | 0;
|
|
14877
|
+
Bl = SHA384_IV[3] | 0;
|
|
14878
|
+
Ch = SHA384_IV[4] | 0;
|
|
14879
|
+
Cl = SHA384_IV[5] | 0;
|
|
14880
|
+
Dh = SHA384_IV[6] | 0;
|
|
14881
|
+
Dl = SHA384_IV[7] | 0;
|
|
14882
|
+
Eh = SHA384_IV[8] | 0;
|
|
14883
|
+
El = SHA384_IV[9] | 0;
|
|
14884
|
+
Fh = SHA384_IV[10] | 0;
|
|
14885
|
+
Fl = SHA384_IV[11] | 0;
|
|
14886
|
+
Gh = SHA384_IV[12] | 0;
|
|
14887
|
+
Gl = SHA384_IV[13] | 0;
|
|
14888
|
+
Hh = SHA384_IV[14] | 0;
|
|
14889
|
+
Hl = SHA384_IV[15] | 0;
|
|
14911
14890
|
constructor() {
|
|
14912
14891
|
super(48);
|
|
14913
|
-
this.Ah = SHA384_IV[0] | 0;
|
|
14914
|
-
this.Al = SHA384_IV[1] | 0;
|
|
14915
|
-
this.Bh = SHA384_IV[2] | 0;
|
|
14916
|
-
this.Bl = SHA384_IV[3] | 0;
|
|
14917
|
-
this.Ch = SHA384_IV[4] | 0;
|
|
14918
|
-
this.Cl = SHA384_IV[5] | 0;
|
|
14919
|
-
this.Dh = SHA384_IV[6] | 0;
|
|
14920
|
-
this.Dl = SHA384_IV[7] | 0;
|
|
14921
|
-
this.Eh = SHA384_IV[8] | 0;
|
|
14922
|
-
this.El = SHA384_IV[9] | 0;
|
|
14923
|
-
this.Fh = SHA384_IV[10] | 0;
|
|
14924
|
-
this.Fl = SHA384_IV[11] | 0;
|
|
14925
|
-
this.Gh = SHA384_IV[12] | 0;
|
|
14926
|
-
this.Gl = SHA384_IV[13] | 0;
|
|
14927
|
-
this.Hh = SHA384_IV[14] | 0;
|
|
14928
|
-
this.Hl = SHA384_IV[15] | 0;
|
|
14929
14892
|
}
|
|
14930
14893
|
}
|
|
14931
14894
|
/**
|
|
@@ -14944,161 +14907,83 @@ const T256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
|
14944
14907
|
0x22312194, 0xfc2bf72c, 0x9f555fa3, 0xc84c64c2, 0x2393b86b, 0x6f53b151, 0x96387719, 0x5940eabd,
|
|
14945
14908
|
0x96283ee2, 0xa88effe3, 0xbe5e1e25, 0x53863992, 0x2b0199fc, 0x2c85b8aa, 0x0eb72ddc, 0x81c52ca2,
|
|
14946
14909
|
]);
|
|
14947
|
-
|
|
14910
|
+
/** Internal SHA2-512/224 hash class. */
|
|
14911
|
+
class _SHA512_224 extends SHA2_64B {
|
|
14912
|
+
Ah = T224_IV[0] | 0;
|
|
14913
|
+
Al = T224_IV[1] | 0;
|
|
14914
|
+
Bh = T224_IV[2] | 0;
|
|
14915
|
+
Bl = T224_IV[3] | 0;
|
|
14916
|
+
Ch = T224_IV[4] | 0;
|
|
14917
|
+
Cl = T224_IV[5] | 0;
|
|
14918
|
+
Dh = T224_IV[6] | 0;
|
|
14919
|
+
Dl = T224_IV[7] | 0;
|
|
14920
|
+
Eh = T224_IV[8] | 0;
|
|
14921
|
+
El = T224_IV[9] | 0;
|
|
14922
|
+
Fh = T224_IV[10] | 0;
|
|
14923
|
+
Fl = T224_IV[11] | 0;
|
|
14924
|
+
Gh = T224_IV[12] | 0;
|
|
14925
|
+
Gl = T224_IV[13] | 0;
|
|
14926
|
+
Hh = T224_IV[14] | 0;
|
|
14927
|
+
Hl = T224_IV[15] | 0;
|
|
14948
14928
|
constructor() {
|
|
14949
14929
|
super(28);
|
|
14950
|
-
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
|
|
14954
|
-
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14930
|
+
}
|
|
14931
|
+
}
|
|
14932
|
+
/** Internal SHA2-512/256 hash class. */
|
|
14933
|
+
class _SHA512_256 extends SHA2_64B {
|
|
14934
|
+
Ah = T256_IV[0] | 0;
|
|
14935
|
+
Al = T256_IV[1] | 0;
|
|
14936
|
+
Bh = T256_IV[2] | 0;
|
|
14937
|
+
Bl = T256_IV[3] | 0;
|
|
14938
|
+
Ch = T256_IV[4] | 0;
|
|
14939
|
+
Cl = T256_IV[5] | 0;
|
|
14940
|
+
Dh = T256_IV[6] | 0;
|
|
14941
|
+
Dl = T256_IV[7] | 0;
|
|
14942
|
+
Eh = T256_IV[8] | 0;
|
|
14943
|
+
El = T256_IV[9] | 0;
|
|
14944
|
+
Fh = T256_IV[10] | 0;
|
|
14945
|
+
Fl = T256_IV[11] | 0;
|
|
14946
|
+
Gh = T256_IV[12] | 0;
|
|
14947
|
+
Gl = T256_IV[13] | 0;
|
|
14948
|
+
Hh = T256_IV[14] | 0;
|
|
14949
|
+
Hl = T256_IV[15] | 0;
|
|
14969
14950
|
constructor() {
|
|
14970
14951
|
super(32);
|
|
14971
|
-
this.Ah = T256_IV[0] | 0;
|
|
14972
|
-
this.Al = T256_IV[1] | 0;
|
|
14973
|
-
this.Bh = T256_IV[2] | 0;
|
|
14974
|
-
this.Bl = T256_IV[3] | 0;
|
|
14975
|
-
this.Ch = T256_IV[4] | 0;
|
|
14976
|
-
this.Cl = T256_IV[5] | 0;
|
|
14977
|
-
this.Dh = T256_IV[6] | 0;
|
|
14978
|
-
this.Dl = T256_IV[7] | 0;
|
|
14979
|
-
this.Eh = T256_IV[8] | 0;
|
|
14980
|
-
this.El = T256_IV[9] | 0;
|
|
14981
|
-
this.Fh = T256_IV[10] | 0;
|
|
14982
|
-
this.Fl = T256_IV[11] | 0;
|
|
14983
|
-
this.Gh = T256_IV[12] | 0;
|
|
14984
|
-
this.Gl = T256_IV[13] | 0;
|
|
14985
|
-
this.Hh = T256_IV[14] | 0;
|
|
14986
|
-
this.Hl = T256_IV[15] | 0;
|
|
14987
14952
|
}
|
|
14988
14953
|
}
|
|
14989
14954
|
/**
|
|
14990
|
-
* SHA2-256 hash function from RFC 4634.
|
|
14955
|
+
* SHA2-256 hash function from RFC 4634. In JS it's the fastest: even faster than Blake3. Some info:
|
|
14991
14956
|
*
|
|
14992
|
-
*
|
|
14993
|
-
*
|
|
14994
|
-
*
|
|
14957
|
+
* - Trying 2^128 hashes would get 50% chance of collision, using birthday attack.
|
|
14958
|
+
* - BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
14959
|
+
* - Each sha256 hash is executing 2^18 bit operations.
|
|
14960
|
+
* - Good 2024 ASICs can do 200Th/sec with 3500 watts of power, corresponding to 2^36 hashes/joule.
|
|
14995
14961
|
*/
|
|
14996
|
-
const sha2_sha256 = /* @__PURE__ */ utils_createHasher(() => new
|
|
14962
|
+
const sha2_sha256 = /* @__PURE__ */ utils_createHasher(() => new _SHA256(),
|
|
14963
|
+
/* @__PURE__ */ utils_oidNist(0x01));
|
|
14997
14964
|
/** SHA2-224 hash function from RFC 4634 */
|
|
14998
|
-
const sha224 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new
|
|
14965
|
+
const sha224 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new _SHA224(),
|
|
14966
|
+
/* @__PURE__ */ oidNist(0x04))));
|
|
14999
14967
|
/** SHA2-512 hash function from RFC 4634. */
|
|
15000
|
-
const sha512 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new
|
|
14968
|
+
const sha512 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new _SHA512(),
|
|
14969
|
+
/* @__PURE__ */ oidNist(0x03))));
|
|
15001
14970
|
/** SHA2-384 hash function from RFC 4634. */
|
|
15002
|
-
const sha384 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new
|
|
14971
|
+
const sha384 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new _SHA384(),
|
|
14972
|
+
/* @__PURE__ */ oidNist(0x02))));
|
|
15003
14973
|
/**
|
|
15004
14974
|
* SHA2-512/256 "truncated" hash function, with improved resistance to length extension attacks.
|
|
15005
14975
|
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
|
15006
14976
|
*/
|
|
15007
|
-
const sha512_256 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new
|
|
14977
|
+
const sha512_256 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new _SHA512_256(),
|
|
14978
|
+
/* @__PURE__ */ oidNist(0x06))));
|
|
15008
14979
|
/**
|
|
15009
14980
|
* SHA2-512/224 "truncated" hash function, with improved resistance to length extension attacks.
|
|
15010
14981
|
* See the paper on [truncated SHA512](https://eprint.iacr.org/2010/548.pdf).
|
|
15011
14982
|
*/
|
|
15012
|
-
const sha512_224 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new
|
|
14983
|
+
const sha512_224 = /* @__PURE__ */ (/* unused pure expression or super */ null && (createHasher(() => new _SHA512_224(),
|
|
14984
|
+
/* @__PURE__ */ oidNist(0x05))));
|
|
15013
14985
|
//# sourceMappingURL=sha2.js.map
|
|
15014
|
-
;// ./node_modules/@noble/
|
|
15015
|
-
/**
|
|
15016
|
-
* HMAC: RFC2104 message authentication code.
|
|
15017
|
-
* @module
|
|
15018
|
-
*/
|
|
15019
|
-
|
|
15020
|
-
class HMAC extends Hash {
|
|
15021
|
-
constructor(hash, _key) {
|
|
15022
|
-
super();
|
|
15023
|
-
this.finished = false;
|
|
15024
|
-
this.destroyed = false;
|
|
15025
|
-
ahash(hash);
|
|
15026
|
-
const key = toBytes(_key);
|
|
15027
|
-
this.iHash = hash.create();
|
|
15028
|
-
if (typeof this.iHash.update !== 'function')
|
|
15029
|
-
throw new Error('Expected instance of class which extends utils.Hash');
|
|
15030
|
-
this.blockLen = this.iHash.blockLen;
|
|
15031
|
-
this.outputLen = this.iHash.outputLen;
|
|
15032
|
-
const blockLen = this.blockLen;
|
|
15033
|
-
const pad = new Uint8Array(blockLen);
|
|
15034
|
-
// blockLen can be bigger than outputLen
|
|
15035
|
-
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
15036
|
-
for (let i = 0; i < pad.length; i++)
|
|
15037
|
-
pad[i] ^= 0x36;
|
|
15038
|
-
this.iHash.update(pad);
|
|
15039
|
-
// By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
|
|
15040
|
-
this.oHash = hash.create();
|
|
15041
|
-
// Undo internal XOR && apply outer XOR
|
|
15042
|
-
for (let i = 0; i < pad.length; i++)
|
|
15043
|
-
pad[i] ^= 0x36 ^ 0x5c;
|
|
15044
|
-
this.oHash.update(pad);
|
|
15045
|
-
clean(pad);
|
|
15046
|
-
}
|
|
15047
|
-
update(buf) {
|
|
15048
|
-
aexists(this);
|
|
15049
|
-
this.iHash.update(buf);
|
|
15050
|
-
return this;
|
|
15051
|
-
}
|
|
15052
|
-
digestInto(out) {
|
|
15053
|
-
aexists(this);
|
|
15054
|
-
abytes(out, this.outputLen);
|
|
15055
|
-
this.finished = true;
|
|
15056
|
-
this.iHash.digestInto(out);
|
|
15057
|
-
this.oHash.update(out);
|
|
15058
|
-
this.oHash.digestInto(out);
|
|
15059
|
-
this.destroy();
|
|
15060
|
-
}
|
|
15061
|
-
digest() {
|
|
15062
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
15063
|
-
this.digestInto(out);
|
|
15064
|
-
return out;
|
|
15065
|
-
}
|
|
15066
|
-
_cloneInto(to) {
|
|
15067
|
-
// Create new instance without calling constructor since key already in state and we don't know it.
|
|
15068
|
-
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
15069
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
15070
|
-
to = to;
|
|
15071
|
-
to.finished = finished;
|
|
15072
|
-
to.destroyed = destroyed;
|
|
15073
|
-
to.blockLen = blockLen;
|
|
15074
|
-
to.outputLen = outputLen;
|
|
15075
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
15076
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
15077
|
-
return to;
|
|
15078
|
-
}
|
|
15079
|
-
clone() {
|
|
15080
|
-
return this._cloneInto();
|
|
15081
|
-
}
|
|
15082
|
-
destroy() {
|
|
15083
|
-
this.destroyed = true;
|
|
15084
|
-
this.oHash.destroy();
|
|
15085
|
-
this.iHash.destroy();
|
|
15086
|
-
}
|
|
15087
|
-
}
|
|
15088
|
-
/**
|
|
15089
|
-
* HMAC: RFC2104 message authentication code.
|
|
15090
|
-
* @param hash - function that would be used e.g. sha256
|
|
15091
|
-
* @param key - message key
|
|
15092
|
-
* @param message - message data
|
|
15093
|
-
* @example
|
|
15094
|
-
* import { hmac } from '@noble/hashes/hmac';
|
|
15095
|
-
* import { sha256 } from '@noble/hashes/sha2';
|
|
15096
|
-
* const mac1 = hmac(sha256, 'key', 'message');
|
|
15097
|
-
*/
|
|
15098
|
-
const hmac_hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
15099
|
-
hmac_hmac.create = (hash, key) => new HMAC(hash, key);
|
|
15100
|
-
//# sourceMappingURL=hmac.js.map
|
|
15101
|
-
;// ./node_modules/@noble/curves/esm/utils.js
|
|
14986
|
+
;// ./node_modules/@noble/curves/utils.js
|
|
15102
14987
|
/**
|
|
15103
14988
|
* Hex, bytes and number utilities.
|
|
15104
14989
|
* @module
|
|
@@ -15108,35 +14993,31 @@ hmac_hmac.create = (hash, key) => new HMAC(hash, key);
|
|
|
15108
14993
|
|
|
15109
14994
|
const _0n = /* @__PURE__ */ BigInt(0);
|
|
15110
14995
|
const _1n = /* @__PURE__ */ BigInt(1);
|
|
15111
|
-
function
|
|
15112
|
-
if (typeof value !== 'boolean')
|
|
15113
|
-
throw new Error(title + ' boolean expected, got ' + value);
|
|
15114
|
-
}
|
|
15115
|
-
// tmp name until v2
|
|
15116
|
-
function _abool2(value, title = '') {
|
|
14996
|
+
function utils_abool(value, title = '') {
|
|
15117
14997
|
if (typeof value !== 'boolean') {
|
|
15118
|
-
const prefix = title && `"${title}"`;
|
|
14998
|
+
const prefix = title && `"${title}" `;
|
|
15119
14999
|
throw new Error(prefix + 'expected boolean, got type=' + typeof value);
|
|
15120
15000
|
}
|
|
15121
15001
|
return value;
|
|
15122
15002
|
}
|
|
15123
|
-
//
|
|
15124
|
-
|
|
15125
|
-
|
|
15126
|
-
|
|
15127
|
-
|
|
15128
|
-
|
|
15129
|
-
|
|
15003
|
+
// Used in weierstrass, der
|
|
15004
|
+
function abignumber(n) {
|
|
15005
|
+
if (typeof n === 'bigint') {
|
|
15006
|
+
if (!isPosBig(n))
|
|
15007
|
+
throw new Error('positive bigint expected, got ' + n);
|
|
15008
|
+
}
|
|
15009
|
+
else
|
|
15010
|
+
utils_anumber(n);
|
|
15011
|
+
return n;
|
|
15012
|
+
}
|
|
15013
|
+
function asafenumber(value, title = '') {
|
|
15014
|
+
if (!Number.isSafeInteger(value)) {
|
|
15130
15015
|
const prefix = title && `"${title}" `;
|
|
15131
|
-
|
|
15132
|
-
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
15133
|
-
throw new Error(prefix + 'expected Uint8Array' + ofLen + ', got ' + got);
|
|
15016
|
+
throw new Error(prefix + 'expected safe integer, got type=' + typeof value);
|
|
15134
15017
|
}
|
|
15135
|
-
return value;
|
|
15136
15018
|
}
|
|
15137
|
-
// Used in weierstrass, der
|
|
15138
15019
|
function numberToHexUnpadded(num) {
|
|
15139
|
-
const hex = num.toString(16);
|
|
15020
|
+
const hex = abignumber(num).toString(16);
|
|
15140
15021
|
return hex.length & 1 ? '0' + hex : hex;
|
|
15141
15022
|
}
|
|
15142
15023
|
function hexToNumber(hex) {
|
|
@@ -15146,53 +15027,25 @@ function hexToNumber(hex) {
|
|
|
15146
15027
|
}
|
|
15147
15028
|
// BE: Big Endian, LE: Little Endian
|
|
15148
15029
|
function utils_bytesToNumberBE(bytes) {
|
|
15149
|
-
return hexToNumber(
|
|
15030
|
+
return hexToNumber(utils_bytesToHex(bytes));
|
|
15150
15031
|
}
|
|
15151
|
-
function
|
|
15152
|
-
|
|
15153
|
-
return hexToNumber(bytesToHex(Uint8Array.from(bytes).reverse()));
|
|
15032
|
+
function bytesToNumberLE(bytes) {
|
|
15033
|
+
return hexToNumber(utils_bytesToHex(copyBytes(utils_abytes(bytes)).reverse()));
|
|
15154
15034
|
}
|
|
15155
15035
|
function numberToBytesBE(n, len) {
|
|
15156
|
-
|
|
15036
|
+
utils_anumber(len);
|
|
15037
|
+
n = abignumber(n);
|
|
15038
|
+
const res = utils_hexToBytes(n.toString(16).padStart(len * 2, '0'));
|
|
15039
|
+
if (res.length !== len)
|
|
15040
|
+
throw new Error('number too large');
|
|
15041
|
+
return res;
|
|
15157
15042
|
}
|
|
15158
15043
|
function numberToBytesLE(n, len) {
|
|
15159
15044
|
return numberToBytesBE(n, len).reverse();
|
|
15160
15045
|
}
|
|
15161
15046
|
// Unpadded, rarely used
|
|
15162
15047
|
function numberToVarBytesBE(n) {
|
|
15163
|
-
return hexToBytes_(numberToHexUnpadded(n));
|
|
15164
|
-
}
|
|
15165
|
-
/**
|
|
15166
|
-
* Takes hex string or Uint8Array, converts to Uint8Array.
|
|
15167
|
-
* Validates output length.
|
|
15168
|
-
* Will throw error for other types.
|
|
15169
|
-
* @param title descriptive title for an error e.g. 'secret key'
|
|
15170
|
-
* @param hex hex string or Uint8Array
|
|
15171
|
-
* @param expectedLength optional, will compare to result array's length
|
|
15172
|
-
* @returns
|
|
15173
|
-
*/
|
|
15174
|
-
function utils_ensureBytes(title, hex, expectedLength) {
|
|
15175
|
-
let res;
|
|
15176
|
-
if (typeof hex === 'string') {
|
|
15177
|
-
try {
|
|
15178
|
-
res = hexToBytes(hex);
|
|
15179
|
-
}
|
|
15180
|
-
catch (e) {
|
|
15181
|
-
throw new Error(title + ' must be hex string or Uint8Array, cause: ' + e);
|
|
15182
|
-
}
|
|
15183
|
-
}
|
|
15184
|
-
else if (isBytes(hex)) {
|
|
15185
|
-
// Uint8Array.from() instead of hash.slice() because node.js Buffer
|
|
15186
|
-
// is instance of Uint8Array, and its slice() creates **mutable** copy
|
|
15187
|
-
res = Uint8Array.from(hex);
|
|
15188
|
-
}
|
|
15189
|
-
else {
|
|
15190
|
-
throw new Error(title + ' must be hex string or Uint8Array');
|
|
15191
|
-
}
|
|
15192
|
-
const len = res.length;
|
|
15193
|
-
if (typeof expectedLength === 'number' && len !== expectedLength)
|
|
15194
|
-
throw new Error(title + ' of length ' + expectedLength + ' expected, got ' + len);
|
|
15195
|
-
return res;
|
|
15048
|
+
return hexToBytes_(numberToHexUnpadded(abignumber(n)));
|
|
15196
15049
|
}
|
|
15197
15050
|
// Compares 2 u8a-s in kinda constant time
|
|
15198
15051
|
function equalBytes(a, b) {
|
|
@@ -15213,7 +15066,7 @@ function copyBytes(bytes) {
|
|
|
15213
15066
|
/**
|
|
15214
15067
|
* Decodes 7-bit ASCII string to Uint8Array, throws on non-ascii symbols
|
|
15215
15068
|
* Should be safe to use for things expected to be ASCII.
|
|
15216
|
-
* Returns exact same result as
|
|
15069
|
+
* Returns exact same result as `TextEncoder` for ASCII or throws.
|
|
15217
15070
|
*/
|
|
15218
15071
|
function asciiToBytes(ascii) {
|
|
15219
15072
|
return Uint8Array.from(ascii, (c, i) => {
|
|
@@ -15224,18 +15077,9 @@ function asciiToBytes(ascii) {
|
|
|
15224
15077
|
return charCode;
|
|
15225
15078
|
});
|
|
15226
15079
|
}
|
|
15227
|
-
/**
|
|
15228
|
-
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
15229
|
-
*/
|
|
15230
|
-
// export const utf8ToBytes: typeof utf8ToBytes_ = utf8ToBytes_;
|
|
15231
|
-
/**
|
|
15232
|
-
* Converts bytes to string using UTF8 encoding.
|
|
15233
|
-
* @example bytesToUtf8(Uint8Array.from([97, 98, 99])) // 'abc'
|
|
15234
|
-
*/
|
|
15235
|
-
// export const bytesToUtf8: typeof bytesToUtf8_ = bytesToUtf8_;
|
|
15236
15080
|
// Is positive bigint
|
|
15237
15081
|
const isPosBig = (n) => typeof n === 'bigint' && _0n <= n;
|
|
15238
|
-
function
|
|
15082
|
+
function inRange(n, min, max) {
|
|
15239
15083
|
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
15240
15084
|
}
|
|
15241
15085
|
/**
|
|
@@ -15243,13 +15087,13 @@ function utils_inRange(n, min, max) {
|
|
|
15243
15087
|
* @example
|
|
15244
15088
|
* aInRange('x', x, 1n, 256n); // would assume x is in (1n..255n)
|
|
15245
15089
|
*/
|
|
15246
|
-
function
|
|
15090
|
+
function utils_aInRange(title, n, min, max) {
|
|
15247
15091
|
// Why min <= n < max and not a (min < n < max) OR b (min <= n <= max)?
|
|
15248
15092
|
// consider P=256n, min=0n, max=P
|
|
15249
15093
|
// - a for min=0 would require -1: `inRange('x', x, -1n, P)`
|
|
15250
15094
|
// - b would commonly require subtraction: `inRange('x', x, 0n, P - 1n)`
|
|
15251
15095
|
// - our way is the cleanest: `inRange('x', x, 0n, P)
|
|
15252
|
-
if (!
|
|
15096
|
+
if (!inRange(n, min, max))
|
|
15253
15097
|
throw new Error('expected valid ' + title + ': ' + min + ' <= n < ' + max + ', got ' + n);
|
|
15254
15098
|
}
|
|
15255
15099
|
// Bit operations
|
|
@@ -15258,7 +15102,7 @@ function aInRange(title, n, min, max) {
|
|
|
15258
15102
|
* Same as `n.toString(2).length`
|
|
15259
15103
|
* TODO: merge with nLength in modular
|
|
15260
15104
|
*/
|
|
15261
|
-
function
|
|
15105
|
+
function utils_bitLen(n) {
|
|
15262
15106
|
let len;
|
|
15263
15107
|
for (len = 0; n > _0n; n >>= _1n, len += 1)
|
|
15264
15108
|
;
|
|
@@ -15290,16 +15134,17 @@ const utils_bitMask = (n) => (_1n << BigInt(n)) - _1n;
|
|
|
15290
15134
|
* const drbg = createHmacDRBG<Key>(32, 32, hmac);
|
|
15291
15135
|
* drbg(seed, bytesToKey); // bytesToKey must return Key or undefined
|
|
15292
15136
|
*/
|
|
15293
|
-
function
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
if (typeof qByteLen !== 'number' || qByteLen < 2)
|
|
15297
|
-
throw new Error('qByteLen must be a number');
|
|
15137
|
+
function utils_createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
15138
|
+
anumber(hashLen, 'hashLen');
|
|
15139
|
+
anumber(qByteLen, 'qByteLen');
|
|
15298
15140
|
if (typeof hmacFn !== 'function')
|
|
15299
15141
|
throw new Error('hmacFn must be a function');
|
|
15300
|
-
// Step B, Step C: set hashLen to 8*ceil(hlen/8)
|
|
15301
15142
|
const u8n = (len) => new Uint8Array(len); // creates Uint8Array
|
|
15302
|
-
const
|
|
15143
|
+
const NULL = Uint8Array.of();
|
|
15144
|
+
const byte0 = Uint8Array.of(0x00);
|
|
15145
|
+
const byte1 = Uint8Array.of(0x01);
|
|
15146
|
+
const _maxDrbgIters = 1000;
|
|
15147
|
+
// Step B, Step C: set hashLen to 8*ceil(hlen/8)
|
|
15303
15148
|
let v = u8n(hashLen); // Minimal non-full-spec HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
|
|
15304
15149
|
let k = u8n(hashLen); // Steps B and C of RFC6979 3.2: set hashLen, in our case always same
|
|
15305
15150
|
let i = 0; // Iterations counter, will throw when over 1000
|
|
@@ -15308,20 +15153,20 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
15308
15153
|
k.fill(0);
|
|
15309
15154
|
i = 0;
|
|
15310
15155
|
};
|
|
15311
|
-
const h = (...
|
|
15312
|
-
const reseed = (seed =
|
|
15156
|
+
const h = (...msgs) => hmacFn(k, concatBytes_(v, ...msgs)); // hmac(k)(v, ...values)
|
|
15157
|
+
const reseed = (seed = NULL) => {
|
|
15313
15158
|
// HMAC-DRBG reseed() function. Steps D-G
|
|
15314
|
-
k = h(
|
|
15159
|
+
k = h(byte0, seed); // k = hmac(k || v || 0x00 || seed)
|
|
15315
15160
|
v = h(); // v = hmac(k || v)
|
|
15316
15161
|
if (seed.length === 0)
|
|
15317
15162
|
return;
|
|
15318
|
-
k = h(
|
|
15163
|
+
k = h(byte1, seed); // k = hmac(k || v || 0x01 || seed)
|
|
15319
15164
|
v = h(); // v = hmac(k || v)
|
|
15320
15165
|
};
|
|
15321
15166
|
const gen = () => {
|
|
15322
15167
|
// HMAC-DRBG generate() function
|
|
15323
|
-
if (i++ >=
|
|
15324
|
-
throw new Error('drbg: tried
|
|
15168
|
+
if (i++ >= _maxDrbgIters)
|
|
15169
|
+
throw new Error('drbg: tried max amount of iterations');
|
|
15325
15170
|
let len = 0;
|
|
15326
15171
|
const out = [];
|
|
15327
15172
|
while (len < qByteLen) {
|
|
@@ -15330,7 +15175,7 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
15330
15175
|
out.push(sl);
|
|
15331
15176
|
len += v.length;
|
|
15332
15177
|
}
|
|
15333
|
-
return
|
|
15178
|
+
return concatBytes_(...out);
|
|
15334
15179
|
};
|
|
15335
15180
|
const genUntil = (seed, pred) => {
|
|
15336
15181
|
reset();
|
|
@@ -15343,49 +15188,7 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
15343
15188
|
};
|
|
15344
15189
|
return genUntil;
|
|
15345
15190
|
}
|
|
15346
|
-
|
|
15347
|
-
const validatorFns = {
|
|
15348
|
-
bigint: (val) => typeof val === 'bigint',
|
|
15349
|
-
function: (val) => typeof val === 'function',
|
|
15350
|
-
boolean: (val) => typeof val === 'boolean',
|
|
15351
|
-
string: (val) => typeof val === 'string',
|
|
15352
|
-
stringOrUint8Array: (val) => typeof val === 'string' || isBytes(val),
|
|
15353
|
-
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
15354
|
-
array: (val) => Array.isArray(val),
|
|
15355
|
-
field: (val, object) => object.Fp.isValid(val),
|
|
15356
|
-
hash: (val) => typeof val === 'function' && Number.isSafeInteger(val.outputLen),
|
|
15357
|
-
};
|
|
15358
|
-
// type Record<K extends string | number | symbol, T> = { [P in K]: T; }
|
|
15359
|
-
function utils_validateObject(object, validators, optValidators = {}) {
|
|
15360
|
-
const checkField = (fieldName, type, isOptional) => {
|
|
15361
|
-
const checkVal = validatorFns[type];
|
|
15362
|
-
if (typeof checkVal !== 'function')
|
|
15363
|
-
throw new Error('invalid validator function');
|
|
15364
|
-
const val = object[fieldName];
|
|
15365
|
-
if (isOptional && val === undefined)
|
|
15366
|
-
return;
|
|
15367
|
-
if (!checkVal(val, object)) {
|
|
15368
|
-
throw new Error('param ' + String(fieldName) + ' is invalid. Expected ' + type + ', got ' + val);
|
|
15369
|
-
}
|
|
15370
|
-
};
|
|
15371
|
-
for (const [fieldName, type] of Object.entries(validators))
|
|
15372
|
-
checkField(fieldName, type, false);
|
|
15373
|
-
for (const [fieldName, type] of Object.entries(optValidators))
|
|
15374
|
-
checkField(fieldName, type, true);
|
|
15375
|
-
return object;
|
|
15376
|
-
}
|
|
15377
|
-
// validate type tests
|
|
15378
|
-
// const o: { a: number; b: number; c: number } = { a: 1, b: 5, c: 6 };
|
|
15379
|
-
// const z0 = validateObject(o, { a: 'isSafeInteger' }, { c: 'bigint' }); // Ok!
|
|
15380
|
-
// // Should fail type-check
|
|
15381
|
-
// const z1 = validateObject(o, { a: 'tmp' }, { c: 'zz' });
|
|
15382
|
-
// const z2 = validateObject(o, { a: 'isSafeInteger' }, { c: 'zz' });
|
|
15383
|
-
// const z3 = validateObject(o, { test: 'boolean', z: 'bug' });
|
|
15384
|
-
// const z4 = validateObject(o, { a: 'boolean', z: 'bug' });
|
|
15385
|
-
function isHash(val) {
|
|
15386
|
-
return typeof val === 'function' && Number.isSafeInteger(val.outputLen);
|
|
15387
|
-
}
|
|
15388
|
-
function _validateObject(object, fields, optFields = {}) {
|
|
15191
|
+
function utils_validateObject(object, fields = {}, optFields = {}) {
|
|
15389
15192
|
if (!object || typeof object !== 'object')
|
|
15390
15193
|
throw new Error('expected valid options object');
|
|
15391
15194
|
function checkField(fieldName, expectedType, isOpt) {
|
|
@@ -15396,8 +15199,9 @@ function _validateObject(object, fields, optFields = {}) {
|
|
|
15396
15199
|
if (current !== expectedType || val === null)
|
|
15397
15200
|
throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
15398
15201
|
}
|
|
15399
|
-
Object.entries(
|
|
15400
|
-
|
|
15202
|
+
const iter = (f, isOpt) => Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
|
|
15203
|
+
iter(fields, false);
|
|
15204
|
+
iter(optFields, true);
|
|
15401
15205
|
}
|
|
15402
15206
|
/**
|
|
15403
15207
|
* throws not implemented error
|
|
@@ -15421,7 +15225,7 @@ function memoized(fn) {
|
|
|
15421
15225
|
};
|
|
15422
15226
|
}
|
|
15423
15227
|
//# sourceMappingURL=utils.js.map
|
|
15424
|
-
;// ./node_modules/@noble/curves/
|
|
15228
|
+
;// ./node_modules/@noble/curves/abstract/modular.js
|
|
15425
15229
|
/**
|
|
15426
15230
|
* Utils for modular division and fields.
|
|
15427
15231
|
* Field over 11 is a finite (Galois) field is integer number operations `mod 11`.
|
|
@@ -15430,12 +15234,14 @@ function memoized(fn) {
|
|
|
15430
15234
|
*/
|
|
15431
15235
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15432
15236
|
|
|
15237
|
+
// Numbers aren't used in x25519 / x448 builds
|
|
15433
15238
|
// prettier-ignore
|
|
15434
|
-
const modular_0n =
|
|
15239
|
+
const modular_0n = /* @__PURE__ */ BigInt(0), modular_1n = /* @__PURE__ */ BigInt(1), _2n = /* @__PURE__ */ BigInt(2);
|
|
15435
15240
|
// prettier-ignore
|
|
15436
|
-
const
|
|
15241
|
+
const _3n = /* @__PURE__ */ BigInt(3), _4n = /* @__PURE__ */ BigInt(4), _5n = /* @__PURE__ */ BigInt(5);
|
|
15437
15242
|
// prettier-ignore
|
|
15438
|
-
const
|
|
15243
|
+
const _7n = /* @__PURE__ */ BigInt(7), _8n = /* @__PURE__ */ BigInt(8), _9n = /* @__PURE__ */ BigInt(9);
|
|
15244
|
+
const _16n = /* @__PURE__ */ BigInt(16);
|
|
15439
15245
|
// Calculates a modulo b
|
|
15440
15246
|
function mod(a, b) {
|
|
15441
15247
|
const result = a % b;
|
|
@@ -15642,7 +15448,6 @@ const FIELD_FIELDS = [
|
|
|
15642
15448
|
function modular_validateField(field) {
|
|
15643
15449
|
const initial = {
|
|
15644
15450
|
ORDER: 'bigint',
|
|
15645
|
-
MASK: 'bigint',
|
|
15646
15451
|
BYTES: 'number',
|
|
15647
15452
|
BITS: 'number',
|
|
15648
15453
|
};
|
|
@@ -15650,7 +15455,7 @@ function modular_validateField(field) {
|
|
|
15650
15455
|
map[val] = 'function';
|
|
15651
15456
|
return map;
|
|
15652
15457
|
}, initial);
|
|
15653
|
-
|
|
15458
|
+
utils_validateObject(field, opts);
|
|
15654
15459
|
// const max = 16384;
|
|
15655
15460
|
// if (field.BYTES < 1 || field.BYTES > max) throw new Error('invalid field');
|
|
15656
15461
|
// if (field.BITS < 1 || field.BITS > 8 * max) throw new Error('invalid field');
|
|
@@ -15734,14 +15539,151 @@ function FpIsSquare(Fp, n) {
|
|
|
15734
15539
|
return l === 1;
|
|
15735
15540
|
}
|
|
15736
15541
|
// CURVE.n lengths
|
|
15737
|
-
function
|
|
15542
|
+
function nLength(n, nBitLength) {
|
|
15738
15543
|
// Bit size, byte size of CURVE.n
|
|
15739
15544
|
if (nBitLength !== undefined)
|
|
15740
|
-
|
|
15545
|
+
utils_anumber(nBitLength);
|
|
15741
15546
|
const _nBitLength = nBitLength !== undefined ? nBitLength : n.toString(2).length;
|
|
15742
15547
|
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
15743
15548
|
return { nBitLength: _nBitLength, nByteLength };
|
|
15744
15549
|
}
|
|
15550
|
+
class _Field {
|
|
15551
|
+
ORDER;
|
|
15552
|
+
BITS;
|
|
15553
|
+
BYTES;
|
|
15554
|
+
isLE;
|
|
15555
|
+
ZERO = modular_0n;
|
|
15556
|
+
ONE = modular_1n;
|
|
15557
|
+
_lengths;
|
|
15558
|
+
_sqrt; // cached sqrt
|
|
15559
|
+
_mod;
|
|
15560
|
+
constructor(ORDER, opts = {}) {
|
|
15561
|
+
if (ORDER <= modular_0n)
|
|
15562
|
+
throw new Error('invalid field: expected ORDER > 0, got ' + ORDER);
|
|
15563
|
+
let _nbitLength = undefined;
|
|
15564
|
+
this.isLE = false;
|
|
15565
|
+
if (opts != null && typeof opts === 'object') {
|
|
15566
|
+
if (typeof opts.BITS === 'number')
|
|
15567
|
+
_nbitLength = opts.BITS;
|
|
15568
|
+
if (typeof opts.sqrt === 'function')
|
|
15569
|
+
this.sqrt = opts.sqrt;
|
|
15570
|
+
if (typeof opts.isLE === 'boolean')
|
|
15571
|
+
this.isLE = opts.isLE;
|
|
15572
|
+
if (opts.allowedLengths)
|
|
15573
|
+
this._lengths = opts.allowedLengths?.slice();
|
|
15574
|
+
if (typeof opts.modFromBytes === 'boolean')
|
|
15575
|
+
this._mod = opts.modFromBytes;
|
|
15576
|
+
}
|
|
15577
|
+
const { nBitLength, nByteLength } = nLength(ORDER, _nbitLength);
|
|
15578
|
+
if (nByteLength > 2048)
|
|
15579
|
+
throw new Error('invalid field: expected ORDER of <= 2048 bytes');
|
|
15580
|
+
this.ORDER = ORDER;
|
|
15581
|
+
this.BITS = nBitLength;
|
|
15582
|
+
this.BYTES = nByteLength;
|
|
15583
|
+
this._sqrt = undefined;
|
|
15584
|
+
Object.preventExtensions(this);
|
|
15585
|
+
}
|
|
15586
|
+
create(num) {
|
|
15587
|
+
return mod(num, this.ORDER);
|
|
15588
|
+
}
|
|
15589
|
+
isValid(num) {
|
|
15590
|
+
if (typeof num !== 'bigint')
|
|
15591
|
+
throw new Error('invalid field element: expected bigint, got ' + typeof num);
|
|
15592
|
+
return modular_0n <= num && num < this.ORDER; // 0 is valid element, but it's not invertible
|
|
15593
|
+
}
|
|
15594
|
+
is0(num) {
|
|
15595
|
+
return num === modular_0n;
|
|
15596
|
+
}
|
|
15597
|
+
// is valid and invertible
|
|
15598
|
+
isValidNot0(num) {
|
|
15599
|
+
return !this.is0(num) && this.isValid(num);
|
|
15600
|
+
}
|
|
15601
|
+
isOdd(num) {
|
|
15602
|
+
return (num & modular_1n) === modular_1n;
|
|
15603
|
+
}
|
|
15604
|
+
neg(num) {
|
|
15605
|
+
return mod(-num, this.ORDER);
|
|
15606
|
+
}
|
|
15607
|
+
eql(lhs, rhs) {
|
|
15608
|
+
return lhs === rhs;
|
|
15609
|
+
}
|
|
15610
|
+
sqr(num) {
|
|
15611
|
+
return mod(num * num, this.ORDER);
|
|
15612
|
+
}
|
|
15613
|
+
add(lhs, rhs) {
|
|
15614
|
+
return mod(lhs + rhs, this.ORDER);
|
|
15615
|
+
}
|
|
15616
|
+
sub(lhs, rhs) {
|
|
15617
|
+
return mod(lhs - rhs, this.ORDER);
|
|
15618
|
+
}
|
|
15619
|
+
mul(lhs, rhs) {
|
|
15620
|
+
return mod(lhs * rhs, this.ORDER);
|
|
15621
|
+
}
|
|
15622
|
+
pow(num, power) {
|
|
15623
|
+
return FpPow(this, num, power);
|
|
15624
|
+
}
|
|
15625
|
+
div(lhs, rhs) {
|
|
15626
|
+
return mod(lhs * invert(rhs, this.ORDER), this.ORDER);
|
|
15627
|
+
}
|
|
15628
|
+
// Same as above, but doesn't normalize
|
|
15629
|
+
sqrN(num) {
|
|
15630
|
+
return num * num;
|
|
15631
|
+
}
|
|
15632
|
+
addN(lhs, rhs) {
|
|
15633
|
+
return lhs + rhs;
|
|
15634
|
+
}
|
|
15635
|
+
subN(lhs, rhs) {
|
|
15636
|
+
return lhs - rhs;
|
|
15637
|
+
}
|
|
15638
|
+
mulN(lhs, rhs) {
|
|
15639
|
+
return lhs * rhs;
|
|
15640
|
+
}
|
|
15641
|
+
inv(num) {
|
|
15642
|
+
return invert(num, this.ORDER);
|
|
15643
|
+
}
|
|
15644
|
+
sqrt(num) {
|
|
15645
|
+
// Caching _sqrt speeds up sqrt9mod16 by 5x and tonneli-shanks by 10%
|
|
15646
|
+
if (!this._sqrt)
|
|
15647
|
+
this._sqrt = FpSqrt(this.ORDER);
|
|
15648
|
+
return this._sqrt(this, num);
|
|
15649
|
+
}
|
|
15650
|
+
toBytes(num) {
|
|
15651
|
+
return this.isLE ? numberToBytesLE(num, this.BYTES) : numberToBytesBE(num, this.BYTES);
|
|
15652
|
+
}
|
|
15653
|
+
fromBytes(bytes, skipValidation = false) {
|
|
15654
|
+
utils_abytes(bytes);
|
|
15655
|
+
const { _lengths: allowedLengths, BYTES, isLE, ORDER, _mod: modFromBytes } = this;
|
|
15656
|
+
if (allowedLengths) {
|
|
15657
|
+
if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
|
|
15658
|
+
throw new Error('Field.fromBytes: expected ' + allowedLengths + ' bytes, got ' + bytes.length);
|
|
15659
|
+
}
|
|
15660
|
+
const padded = new Uint8Array(BYTES);
|
|
15661
|
+
// isLE add 0 to right, !isLE to the left.
|
|
15662
|
+
padded.set(bytes, isLE ? 0 : padded.length - bytes.length);
|
|
15663
|
+
bytes = padded;
|
|
15664
|
+
}
|
|
15665
|
+
if (bytes.length !== BYTES)
|
|
15666
|
+
throw new Error('Field.fromBytes: expected ' + BYTES + ' bytes, got ' + bytes.length);
|
|
15667
|
+
let scalar = isLE ? bytesToNumberLE(bytes) : utils_bytesToNumberBE(bytes);
|
|
15668
|
+
if (modFromBytes)
|
|
15669
|
+
scalar = mod(scalar, ORDER);
|
|
15670
|
+
if (!skipValidation)
|
|
15671
|
+
if (!this.isValid(scalar))
|
|
15672
|
+
throw new Error('invalid field element: outside of range 0..ORDER');
|
|
15673
|
+
// NOTE: we don't validate scalar here, please use isValid. This done such way because some
|
|
15674
|
+
// protocol may allow non-reduced scalar that reduced later or changed some other way.
|
|
15675
|
+
return scalar;
|
|
15676
|
+
}
|
|
15677
|
+
// TODO: we don't need it here, move out to separate fn
|
|
15678
|
+
invertBatch(lst) {
|
|
15679
|
+
return modular_FpInvertBatch(this, lst);
|
|
15680
|
+
}
|
|
15681
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
15682
|
+
// and it's unclear what to return in there.
|
|
15683
|
+
cmov(a, b, condition) {
|
|
15684
|
+
return condition ? b : a;
|
|
15685
|
+
}
|
|
15686
|
+
}
|
|
15745
15687
|
/**
|
|
15746
15688
|
* Creates a finite field. Major performance optimizations:
|
|
15747
15689
|
* * 1. Denormalized operations like mulN instead of mul.
|
|
@@ -15761,107 +15703,8 @@ function modular_nLength(n, nBitLength) {
|
|
|
15761
15703
|
* @param isLE (default: false) if encoding / decoding should be in little-endian
|
|
15762
15704
|
* @param redef optional faster redefinitions of sqrt and other methods
|
|
15763
15705
|
*/
|
|
15764
|
-
function Field(ORDER,
|
|
15765
|
-
|
|
15766
|
-
if (ORDER <= modular_0n)
|
|
15767
|
-
throw new Error('invalid field: expected ORDER > 0, got ' + ORDER);
|
|
15768
|
-
let _nbitLength = undefined;
|
|
15769
|
-
let _sqrt = undefined;
|
|
15770
|
-
let modFromBytes = false;
|
|
15771
|
-
let allowedLengths = undefined;
|
|
15772
|
-
if (typeof bitLenOrOpts === 'object' && bitLenOrOpts != null) {
|
|
15773
|
-
if (opts.sqrt || isLE)
|
|
15774
|
-
throw new Error('cannot specify opts in two arguments');
|
|
15775
|
-
const _opts = bitLenOrOpts;
|
|
15776
|
-
if (_opts.BITS)
|
|
15777
|
-
_nbitLength = _opts.BITS;
|
|
15778
|
-
if (_opts.sqrt)
|
|
15779
|
-
_sqrt = _opts.sqrt;
|
|
15780
|
-
if (typeof _opts.isLE === 'boolean')
|
|
15781
|
-
isLE = _opts.isLE;
|
|
15782
|
-
if (typeof _opts.modFromBytes === 'boolean')
|
|
15783
|
-
modFromBytes = _opts.modFromBytes;
|
|
15784
|
-
allowedLengths = _opts.allowedLengths;
|
|
15785
|
-
}
|
|
15786
|
-
else {
|
|
15787
|
-
if (typeof bitLenOrOpts === 'number')
|
|
15788
|
-
_nbitLength = bitLenOrOpts;
|
|
15789
|
-
if (opts.sqrt)
|
|
15790
|
-
_sqrt = opts.sqrt;
|
|
15791
|
-
}
|
|
15792
|
-
const { nBitLength: BITS, nByteLength: BYTES } = modular_nLength(ORDER, _nbitLength);
|
|
15793
|
-
if (BYTES > 2048)
|
|
15794
|
-
throw new Error('invalid field: expected ORDER of <= 2048 bytes');
|
|
15795
|
-
let sqrtP; // cached sqrtP
|
|
15796
|
-
const f = Object.freeze({
|
|
15797
|
-
ORDER,
|
|
15798
|
-
isLE,
|
|
15799
|
-
BITS,
|
|
15800
|
-
BYTES,
|
|
15801
|
-
MASK: utils_bitMask(BITS),
|
|
15802
|
-
ZERO: modular_0n,
|
|
15803
|
-
ONE: modular_1n,
|
|
15804
|
-
allowedLengths: allowedLengths,
|
|
15805
|
-
create: (num) => mod(num, ORDER),
|
|
15806
|
-
isValid: (num) => {
|
|
15807
|
-
if (typeof num !== 'bigint')
|
|
15808
|
-
throw new Error('invalid field element: expected bigint, got ' + typeof num);
|
|
15809
|
-
return modular_0n <= num && num < ORDER; // 0 is valid element, but it's not invertible
|
|
15810
|
-
},
|
|
15811
|
-
is0: (num) => num === modular_0n,
|
|
15812
|
-
// is valid and invertible
|
|
15813
|
-
isValidNot0: (num) => !f.is0(num) && f.isValid(num),
|
|
15814
|
-
isOdd: (num) => (num & modular_1n) === modular_1n,
|
|
15815
|
-
neg: (num) => mod(-num, ORDER),
|
|
15816
|
-
eql: (lhs, rhs) => lhs === rhs,
|
|
15817
|
-
sqr: (num) => mod(num * num, ORDER),
|
|
15818
|
-
add: (lhs, rhs) => mod(lhs + rhs, ORDER),
|
|
15819
|
-
sub: (lhs, rhs) => mod(lhs - rhs, ORDER),
|
|
15820
|
-
mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
|
|
15821
|
-
pow: (num, power) => FpPow(f, num, power),
|
|
15822
|
-
div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
|
|
15823
|
-
// Same as above, but doesn't normalize
|
|
15824
|
-
sqrN: (num) => num * num,
|
|
15825
|
-
addN: (lhs, rhs) => lhs + rhs,
|
|
15826
|
-
subN: (lhs, rhs) => lhs - rhs,
|
|
15827
|
-
mulN: (lhs, rhs) => lhs * rhs,
|
|
15828
|
-
inv: (num) => invert(num, ORDER),
|
|
15829
|
-
sqrt: _sqrt ||
|
|
15830
|
-
((n) => {
|
|
15831
|
-
if (!sqrtP)
|
|
15832
|
-
sqrtP = FpSqrt(ORDER);
|
|
15833
|
-
return sqrtP(f, n);
|
|
15834
|
-
}),
|
|
15835
|
-
toBytes: (num) => (isLE ? numberToBytesLE(num, BYTES) : numberToBytesBE(num, BYTES)),
|
|
15836
|
-
fromBytes: (bytes, skipValidation = true) => {
|
|
15837
|
-
if (allowedLengths) {
|
|
15838
|
-
if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
|
|
15839
|
-
throw new Error('Field.fromBytes: expected ' + allowedLengths + ' bytes, got ' + bytes.length);
|
|
15840
|
-
}
|
|
15841
|
-
const padded = new Uint8Array(BYTES);
|
|
15842
|
-
// isLE add 0 to right, !isLE to the left.
|
|
15843
|
-
padded.set(bytes, isLE ? 0 : padded.length - bytes.length);
|
|
15844
|
-
bytes = padded;
|
|
15845
|
-
}
|
|
15846
|
-
if (bytes.length !== BYTES)
|
|
15847
|
-
throw new Error('Field.fromBytes: expected ' + BYTES + ' bytes, got ' + bytes.length);
|
|
15848
|
-
let scalar = isLE ? utils_bytesToNumberLE(bytes) : utils_bytesToNumberBE(bytes);
|
|
15849
|
-
if (modFromBytes)
|
|
15850
|
-
scalar = mod(scalar, ORDER);
|
|
15851
|
-
if (!skipValidation)
|
|
15852
|
-
if (!f.isValid(scalar))
|
|
15853
|
-
throw new Error('invalid field element: outside of range 0..ORDER');
|
|
15854
|
-
// NOTE: we don't validate scalar here, please use isValid. This done such way because some
|
|
15855
|
-
// protocol may allow non-reduced scalar that reduced later or changed some other way.
|
|
15856
|
-
return scalar;
|
|
15857
|
-
},
|
|
15858
|
-
// TODO: we don't need it here, move out to separate fn
|
|
15859
|
-
invertBatch: (lst) => modular_FpInvertBatch(f, lst),
|
|
15860
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
15861
|
-
// and it's unclear what to return in there.
|
|
15862
|
-
cmov: (a, b, c) => (c ? b : a),
|
|
15863
|
-
});
|
|
15864
|
-
return Object.freeze(f);
|
|
15706
|
+
function Field(ORDER, opts = {}) {
|
|
15707
|
+
return new _Field(ORDER, opts);
|
|
15865
15708
|
}
|
|
15866
15709
|
// Generic random scalar, we can do same for other fields if via Fp2.mul(Fp2.ONE, Fp2.random)?
|
|
15867
15710
|
// This allows unsafe methods like ignore bias or zero. These unsafe, but often used in different protocols (if deterministic RNG).
|
|
@@ -15888,21 +15731,6 @@ function FpSqrtEven(Fp, elm) {
|
|
|
15888
15731
|
const root = Fp.sqrt(elm);
|
|
15889
15732
|
return Fp.isOdd(root) ? Fp.neg(root) : root;
|
|
15890
15733
|
}
|
|
15891
|
-
/**
|
|
15892
|
-
* "Constant-time" private key generation utility.
|
|
15893
|
-
* Same as mapKeyToField, but accepts less bytes (40 instead of 48 for 32-byte field).
|
|
15894
|
-
* Which makes it slightly more biased, less secure.
|
|
15895
|
-
* @deprecated use `mapKeyToField` instead
|
|
15896
|
-
*/
|
|
15897
|
-
function hashToPrivateScalar(hash, groupOrder, isLE = false) {
|
|
15898
|
-
hash = ensureBytes('privateHash', hash);
|
|
15899
|
-
const hashLen = hash.length;
|
|
15900
|
-
const minLen = modular_nLength(groupOrder).nByteLength + 8;
|
|
15901
|
-
if (minLen < 24 || hashLen < minLen || hashLen > 1024)
|
|
15902
|
-
throw new Error('hashToPrivateScalar: expected ' + minLen + '-1024 bytes of input, got ' + hashLen);
|
|
15903
|
-
const num = isLE ? bytesToNumberLE(hash) : bytesToNumberBE(hash);
|
|
15904
|
-
return mod(num, groupOrder - modular_1n) + modular_1n;
|
|
15905
|
-
}
|
|
15906
15734
|
/**
|
|
15907
15735
|
* Returns total number of bytes consumed by the field element.
|
|
15908
15736
|
* For example, 32 bytes for usual 256-bit weierstrass curve.
|
|
@@ -15922,7 +15750,7 @@ function getFieldBytesLength(fieldOrder) {
|
|
|
15922
15750
|
* @param fieldOrder number of field elements, usually CURVE.n
|
|
15923
15751
|
* @returns byte length of target hash
|
|
15924
15752
|
*/
|
|
15925
|
-
function
|
|
15753
|
+
function modular_getMinHashLength(fieldOrder) {
|
|
15926
15754
|
const length = getFieldBytesLength(fieldOrder);
|
|
15927
15755
|
return length + Math.ceil(length / 2);
|
|
15928
15756
|
}
|
|
@@ -15935,24 +15763,25 @@ function getMinHashLength(fieldOrder) {
|
|
|
15935
15763
|
* FIPS 186-5, A.2 https://csrc.nist.gov/publications/detail/fips/186/5/final
|
|
15936
15764
|
* RFC 9380, https://www.rfc-editor.org/rfc/rfc9380#section-5
|
|
15937
15765
|
* @param hash hash output from SHA3 or a similar function
|
|
15938
|
-
* @param groupOrder size of subgroup - (e.g. secp256k1.
|
|
15766
|
+
* @param groupOrder size of subgroup - (e.g. secp256k1.Point.Fn.ORDER)
|
|
15939
15767
|
* @param isLE interpret hash bytes as LE num
|
|
15940
15768
|
* @returns valid private scalar
|
|
15941
15769
|
*/
|
|
15942
|
-
function
|
|
15770
|
+
function modular_mapHashToField(key, fieldOrder, isLE = false) {
|
|
15771
|
+
utils_abytes(key);
|
|
15943
15772
|
const len = key.length;
|
|
15944
15773
|
const fieldLen = getFieldBytesLength(fieldOrder);
|
|
15945
|
-
const minLen =
|
|
15774
|
+
const minLen = modular_getMinHashLength(fieldOrder);
|
|
15946
15775
|
// No small numbers: need to understand bias story. No huge numbers: easier to detect JS timings.
|
|
15947
15776
|
if (len < 16 || len < minLen || len > 1024)
|
|
15948
15777
|
throw new Error('expected ' + minLen + '-1024 bytes of input, got ' + len);
|
|
15949
|
-
const num = isLE ?
|
|
15778
|
+
const num = isLE ? bytesToNumberLE(key) : utils_bytesToNumberBE(key);
|
|
15950
15779
|
// `mod(x, 11)` can sometimes produce 0. `mod(x, 10) + 1` is the same, but no 0
|
|
15951
15780
|
const reduced = mod(num, fieldOrder - modular_1n) + modular_1n;
|
|
15952
15781
|
return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
15953
15782
|
}
|
|
15954
15783
|
//# sourceMappingURL=modular.js.map
|
|
15955
|
-
;// ./node_modules/@noble/curves/
|
|
15784
|
+
;// ./node_modules/@noble/curves/abstract/curve.js
|
|
15956
15785
|
/**
|
|
15957
15786
|
* Methods for elliptic curve multiplication by scalars.
|
|
15958
15787
|
* Contains wNAF, pippenger.
|
|
@@ -15961,8 +15790,8 @@ function mapHashToField(key, fieldOrder, isLE = false) {
|
|
|
15961
15790
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
15962
15791
|
|
|
15963
15792
|
|
|
15964
|
-
const curve_0n = BigInt(0);
|
|
15965
|
-
const curve_1n = BigInt(1);
|
|
15793
|
+
const curve_0n = /* @__PURE__ */ BigInt(0);
|
|
15794
|
+
const curve_1n = /* @__PURE__ */ BigInt(1);
|
|
15966
15795
|
function negateCt(condition, item) {
|
|
15967
15796
|
const neg = item.negate();
|
|
15968
15797
|
return condition ? neg : item;
|
|
@@ -16061,6 +15890,10 @@ function assert0(n) {
|
|
|
16061
15890
|
* This would allow windows to be in different memory locations
|
|
16062
15891
|
*/
|
|
16063
15892
|
class wNAF {
|
|
15893
|
+
BASE;
|
|
15894
|
+
ZERO;
|
|
15895
|
+
Fn;
|
|
15896
|
+
bits;
|
|
16064
15897
|
// Parametrized with a given Point class (not individual point)
|
|
16065
15898
|
constructor(Point, bits) {
|
|
16066
15899
|
this.BASE = Point.BASE;
|
|
@@ -16237,13 +16070,14 @@ function mulEndoUnsafe(Point, point, k1, k2) {
|
|
|
16237
16070
|
* @param points array of L curve points
|
|
16238
16071
|
* @param scalars array of L scalars (aka secret keys / bigints)
|
|
16239
16072
|
*/
|
|
16240
|
-
function pippenger(c,
|
|
16073
|
+
function pippenger(c, points, scalars) {
|
|
16241
16074
|
// If we split scalars by some window (let's say 8 bits), every chunk will only
|
|
16242
16075
|
// take 256 buckets even if there are 4096 scalars, also re-uses double.
|
|
16243
16076
|
// TODO:
|
|
16244
16077
|
// - https://eprint.iacr.org/2024/750.pdf
|
|
16245
16078
|
// - https://tches.iacr.org/index.php/TCHES/article/view/10287
|
|
16246
16079
|
// 0 is accepted in scalars
|
|
16080
|
+
const fieldN = c.Fn;
|
|
16247
16081
|
validateMSMPoints(points, c);
|
|
16248
16082
|
validateMSMScalars(scalars, fieldN);
|
|
16249
16083
|
const plength = points.length;
|
|
@@ -16260,7 +16094,7 @@ function pippenger(c, fieldN, points, scalars) {
|
|
|
16260
16094
|
windowSize = wbits - 2;
|
|
16261
16095
|
else if (wbits > 0)
|
|
16262
16096
|
windowSize = 2;
|
|
16263
|
-
const MASK =
|
|
16097
|
+
const MASK = bitMask(windowSize);
|
|
16264
16098
|
const buckets = new Array(Number(MASK) + 1).fill(zero); // +1 for zero array
|
|
16265
16099
|
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
16266
16100
|
let sum = zero;
|
|
@@ -16291,7 +16125,7 @@ function pippenger(c, fieldN, points, scalars) {
|
|
|
16291
16125
|
* @param points array of L curve points
|
|
16292
16126
|
* @returns function which multiplies points with scaars
|
|
16293
16127
|
*/
|
|
16294
|
-
function precomputeMSMUnsafe(c,
|
|
16128
|
+
function precomputeMSMUnsafe(c, points, windowSize) {
|
|
16295
16129
|
/**
|
|
16296
16130
|
* Performance Analysis of Window-based Precomputation
|
|
16297
16131
|
*
|
|
@@ -16327,6 +16161,7 @@ function precomputeMSMUnsafe(c, fieldN, points, windowSize) {
|
|
|
16327
16161
|
* - Optimal for ~256 scalars
|
|
16328
16162
|
* - Less efficient for 4096+ scalars (Pippenger preferred)
|
|
16329
16163
|
*/
|
|
16164
|
+
const fieldN = c.Fn;
|
|
16330
16165
|
validateW(windowSize, fieldN.BITS);
|
|
16331
16166
|
validateMSMPoints(points, c);
|
|
16332
16167
|
const zero = c.ZERO;
|
|
@@ -16363,26 +16198,6 @@ function precomputeMSMUnsafe(c, fieldN, points, windowSize) {
|
|
|
16363
16198
|
return res;
|
|
16364
16199
|
};
|
|
16365
16200
|
}
|
|
16366
|
-
// TODO: remove
|
|
16367
|
-
/** @deprecated */
|
|
16368
|
-
function validateBasic(curve) {
|
|
16369
|
-
validateField(curve.Fp);
|
|
16370
|
-
validateObject(curve, {
|
|
16371
|
-
n: 'bigint',
|
|
16372
|
-
h: 'bigint',
|
|
16373
|
-
Gx: 'field',
|
|
16374
|
-
Gy: 'field',
|
|
16375
|
-
}, {
|
|
16376
|
-
nBitLength: 'isSafeInteger',
|
|
16377
|
-
nByteLength: 'isSafeInteger',
|
|
16378
|
-
});
|
|
16379
|
-
// Set defaults
|
|
16380
|
-
return Object.freeze({
|
|
16381
|
-
...nLength(curve.n, curve.nBitLength),
|
|
16382
|
-
...curve,
|
|
16383
|
-
...{ p: curve.Fp.ORDER },
|
|
16384
|
-
});
|
|
16385
|
-
}
|
|
16386
16201
|
function createField(order, field, isLE) {
|
|
16387
16202
|
if (field) {
|
|
16388
16203
|
if (field.ORDER !== order)
|
|
@@ -16395,7 +16210,7 @@ function createField(order, field, isLE) {
|
|
|
16395
16210
|
}
|
|
16396
16211
|
}
|
|
16397
16212
|
/** Validates CURVE opts and creates fields */
|
|
16398
|
-
function
|
|
16213
|
+
function createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
|
|
16399
16214
|
if (FpFnLE === undefined)
|
|
16400
16215
|
FpFnLE = type === 'edwards';
|
|
16401
16216
|
if (!CURVE || typeof CURVE !== 'object')
|
|
@@ -16417,8 +16232,14 @@ function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
|
|
|
16417
16232
|
CURVE = Object.freeze(Object.assign({}, CURVE));
|
|
16418
16233
|
return { CURVE, Fp, Fn };
|
|
16419
16234
|
}
|
|
16235
|
+
function curve_createKeygen(randomSecretKey, getPublicKey) {
|
|
16236
|
+
return function keygen(seed) {
|
|
16237
|
+
const secretKey = randomSecretKey(seed);
|
|
16238
|
+
return { secretKey, publicKey: getPublicKey(secretKey) };
|
|
16239
|
+
};
|
|
16240
|
+
}
|
|
16420
16241
|
//# sourceMappingURL=curve.js.map
|
|
16421
|
-
;// ./node_modules/@noble/curves/
|
|
16242
|
+
;// ./node_modules/@noble/curves/abstract/weierstrass.js
|
|
16422
16243
|
/**
|
|
16423
16244
|
* Short Weierstrass curve methods. The formula is: y² = x³ + ax + b.
|
|
16424
16245
|
*
|
|
@@ -16475,7 +16296,7 @@ function _splitEndoScalar(k, basis, n) {
|
|
|
16475
16296
|
k2 = -k2;
|
|
16476
16297
|
// Double check that resulting scalar less than half bits of N: otherwise wNAF will fail.
|
|
16477
16298
|
// This should only happen on wrong basises. Also, math inside is too complex and I don't trust it.
|
|
16478
|
-
const MAX_NUM = utils_bitMask(Math.ceil(
|
|
16299
|
+
const MAX_NUM = utils_bitMask(Math.ceil(utils_bitLen(n) / 2)) + weierstrass_1n; // Half bits of N
|
|
16479
16300
|
if (k1 < weierstrass_0n || k1 >= MAX_NUM || k2 < weierstrass_0n || k2 >= MAX_NUM) {
|
|
16480
16301
|
throw new Error('splitScalar (endomorphism): failed, k=' + k);
|
|
16481
16302
|
}
|
|
@@ -16492,8 +16313,8 @@ function validateSigOpts(opts, def) {
|
|
|
16492
16313
|
// @ts-ignore
|
|
16493
16314
|
optsn[optName] = opts[optName] === undefined ? def[optName] : opts[optName];
|
|
16494
16315
|
}
|
|
16495
|
-
|
|
16496
|
-
|
|
16316
|
+
abool(optsn.lowS, 'lowS');
|
|
16317
|
+
abool(optsn.prehash, 'prehash');
|
|
16497
16318
|
if (optsn.format !== undefined)
|
|
16498
16319
|
validateSigFormat(optsn.format);
|
|
16499
16320
|
return optsn;
|
|
@@ -16523,10 +16344,10 @@ const DER = {
|
|
|
16523
16344
|
throw new E('tlv.encode: unpadded data');
|
|
16524
16345
|
const dataLen = data.length / 2;
|
|
16525
16346
|
const len = numberToHexUnpadded(dataLen);
|
|
16526
|
-
if ((len.length / 2) &
|
|
16347
|
+
if ((len.length / 2) & 0b1000_0000)
|
|
16527
16348
|
throw new E('tlv.encode: long form length too big');
|
|
16528
16349
|
// length of length with long form flag
|
|
16529
|
-
const lenLen = dataLen > 127 ? numberToHexUnpadded((len.length / 2) |
|
|
16350
|
+
const lenLen = dataLen > 127 ? numberToHexUnpadded((len.length / 2) | 0b1000_0000) : '';
|
|
16530
16351
|
const t = numberToHexUnpadded(tag);
|
|
16531
16352
|
return t + lenLen + len + data;
|
|
16532
16353
|
},
|
|
@@ -16539,13 +16360,13 @@ const DER = {
|
|
|
16539
16360
|
if (data.length < 2 || data[pos++] !== tag)
|
|
16540
16361
|
throw new E('tlv.decode: wrong tlv');
|
|
16541
16362
|
const first = data[pos++];
|
|
16542
|
-
const isLong = !!(first &
|
|
16363
|
+
const isLong = !!(first & 0b1000_0000); // First bit of first length byte is flag for short/long form
|
|
16543
16364
|
let length = 0;
|
|
16544
16365
|
if (!isLong)
|
|
16545
16366
|
length = first;
|
|
16546
16367
|
else {
|
|
16547
16368
|
// Long form: [longFlag(1bit), lengthLength(7bit), length (BE)]
|
|
16548
|
-
const lenLen = first &
|
|
16369
|
+
const lenLen = first & 0b0111_1111;
|
|
16549
16370
|
if (!lenLen)
|
|
16550
16371
|
throw new E('tlv.decode(long): indefinite length not supported');
|
|
16551
16372
|
if (lenLen > 4)
|
|
@@ -16586,17 +16407,17 @@ const DER = {
|
|
|
16586
16407
|
},
|
|
16587
16408
|
decode(data) {
|
|
16588
16409
|
const { Err: E } = DER;
|
|
16589
|
-
if (data[0] &
|
|
16410
|
+
if (data[0] & 0b1000_0000)
|
|
16590
16411
|
throw new E('invalid signature integer: negative');
|
|
16591
|
-
if (data[0] === 0x00 && !(data[1] &
|
|
16412
|
+
if (data[0] === 0x00 && !(data[1] & 0b1000_0000))
|
|
16592
16413
|
throw new E('invalid signature integer: unnecessary leading zero');
|
|
16593
16414
|
return utils_bytesToNumberBE(data);
|
|
16594
16415
|
},
|
|
16595
16416
|
},
|
|
16596
|
-
toSig(
|
|
16417
|
+
toSig(bytes) {
|
|
16597
16418
|
// parse DER signature
|
|
16598
16419
|
const { Err: E, _int: int, _tlv: tlv } = DER;
|
|
16599
|
-
const data =
|
|
16420
|
+
const data = utils_abytes(bytes, undefined, 'signature');
|
|
16600
16421
|
const { v: seqBytes, l: seqLeftBytes } = tlv.decode(0x30, data);
|
|
16601
16422
|
if (seqLeftBytes.length)
|
|
16602
16423
|
throw new E('invalid signature: left bytes after parsing');
|
|
@@ -16617,55 +16438,37 @@ const DER = {
|
|
|
16617
16438
|
// Be friendly to bad ECMAScript parsers by not using bigint literals
|
|
16618
16439
|
// prettier-ignore
|
|
16619
16440
|
const weierstrass_0n = BigInt(0), weierstrass_1n = BigInt(1), weierstrass_2n = BigInt(2), weierstrass_3n = BigInt(3), weierstrass_4n = BigInt(4);
|
|
16620
|
-
function _normFnElement(Fn, key) {
|
|
16621
|
-
const { BYTES: expected } = Fn;
|
|
16622
|
-
let num;
|
|
16623
|
-
if (typeof key === 'bigint') {
|
|
16624
|
-
num = key;
|
|
16625
|
-
}
|
|
16626
|
-
else {
|
|
16627
|
-
let bytes = utils_ensureBytes('private key', key);
|
|
16628
|
-
try {
|
|
16629
|
-
num = Fn.fromBytes(bytes);
|
|
16630
|
-
}
|
|
16631
|
-
catch (error) {
|
|
16632
|
-
throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key}`);
|
|
16633
|
-
}
|
|
16634
|
-
}
|
|
16635
|
-
if (!Fn.isValidNot0(num))
|
|
16636
|
-
throw new Error('invalid private key: out of range [1..N-1]');
|
|
16637
|
-
return num;
|
|
16638
|
-
}
|
|
16639
16441
|
/**
|
|
16640
16442
|
* Creates weierstrass Point constructor, based on specified curve options.
|
|
16641
16443
|
*
|
|
16444
|
+
* See {@link WeierstrassOpts}.
|
|
16445
|
+
*
|
|
16642
16446
|
* @example
|
|
16643
16447
|
```js
|
|
16644
16448
|
const opts = {
|
|
16645
|
-
p:
|
|
16646
|
-
n:
|
|
16647
|
-
h:
|
|
16648
|
-
a:
|
|
16649
|
-
b:
|
|
16650
|
-
Gx:
|
|
16651
|
-
Gy:
|
|
16449
|
+
p: 0xfffffffffffffffffffffffffffffffeffffac73n,
|
|
16450
|
+
n: 0x100000000000000000001b8fa16dfab9aca16b6b3n,
|
|
16451
|
+
h: 1n,
|
|
16452
|
+
a: 0n,
|
|
16453
|
+
b: 7n,
|
|
16454
|
+
Gx: 0x3b4c382ce37aa192a4019e763036f4f5dd4d7ebbn,
|
|
16455
|
+
Gy: 0x938cf935318fdced6bc28286531733c3f03c4feen,
|
|
16652
16456
|
};
|
|
16653
|
-
const
|
|
16457
|
+
const secp160k1_Point = weierstrass(opts);
|
|
16654
16458
|
```
|
|
16655
16459
|
*/
|
|
16656
|
-
function
|
|
16657
|
-
const validated =
|
|
16460
|
+
function weierstrass(params, extraOpts = {}) {
|
|
16461
|
+
const validated = createCurveFields('weierstrass', params, extraOpts);
|
|
16658
16462
|
const { Fp, Fn } = validated;
|
|
16659
16463
|
let CURVE = validated.CURVE;
|
|
16660
16464
|
const { h: cofactor, n: CURVE_ORDER } = CURVE;
|
|
16661
|
-
|
|
16465
|
+
utils_validateObject(extraOpts, {}, {
|
|
16662
16466
|
allowInfinityPoint: 'boolean',
|
|
16663
16467
|
clearCofactor: 'function',
|
|
16664
16468
|
isTorsionFree: 'function',
|
|
16665
16469
|
fromBytes: 'function',
|
|
16666
16470
|
toBytes: 'function',
|
|
16667
16471
|
endo: 'object',
|
|
16668
|
-
wrapPrivateKey: 'boolean',
|
|
16669
16472
|
});
|
|
16670
16473
|
const { endo } = extraOpts;
|
|
16671
16474
|
if (endo) {
|
|
@@ -16683,18 +16486,18 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
16683
16486
|
function pointToBytes(_c, point, isCompressed) {
|
|
16684
16487
|
const { x, y } = point.toAffine();
|
|
16685
16488
|
const bx = Fp.toBytes(x);
|
|
16686
|
-
|
|
16489
|
+
utils_abool(isCompressed, 'isCompressed');
|
|
16687
16490
|
if (isCompressed) {
|
|
16688
16491
|
assertCompressionIsSupported();
|
|
16689
16492
|
const hasEvenY = !Fp.isOdd(y);
|
|
16690
|
-
return
|
|
16493
|
+
return utils_concatBytes(pprefix(hasEvenY), bx);
|
|
16691
16494
|
}
|
|
16692
16495
|
else {
|
|
16693
|
-
return
|
|
16496
|
+
return utils_concatBytes(Uint8Array.of(0x04), bx, Fp.toBytes(y));
|
|
16694
16497
|
}
|
|
16695
16498
|
}
|
|
16696
16499
|
function pointFromBytes(bytes) {
|
|
16697
|
-
|
|
16500
|
+
utils_abytes(bytes, undefined, 'Point');
|
|
16698
16501
|
const { publicKey: comp, publicKeyUncompressed: uncomp } = lengths; // e.g. for 32-byte: 33, 65
|
|
16699
16502
|
const length = bytes.length;
|
|
16700
16503
|
const head = bytes[0];
|
|
@@ -16714,9 +16517,9 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
16714
16517
|
throw new Error('bad point: is not on curve, sqrt error' + err);
|
|
16715
16518
|
}
|
|
16716
16519
|
assertCompressionIsSupported();
|
|
16717
|
-
const
|
|
16718
|
-
const
|
|
16719
|
-
if (
|
|
16520
|
+
const evenY = Fp.isOdd(y);
|
|
16521
|
+
const evenH = (head & 1) === 1; // ECDSA-specific
|
|
16522
|
+
if (evenH !== evenY)
|
|
16720
16523
|
y = Fp.neg(y);
|
|
16721
16524
|
return { x, y };
|
|
16722
16525
|
}
|
|
@@ -16765,7 +16568,7 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
16765
16568
|
}
|
|
16766
16569
|
function aprjpoint(other) {
|
|
16767
16570
|
if (!(other instanceof Point))
|
|
16768
|
-
throw new Error('
|
|
16571
|
+
throw new Error('Weierstrass Point expected');
|
|
16769
16572
|
}
|
|
16770
16573
|
function splitEndoScalarN(k) {
|
|
16771
16574
|
if (!endo || !endo.basises)
|
|
@@ -16828,6 +16631,17 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
16828
16631
|
* We're doing calculations in projective, because its operations don't require costly inversion.
|
|
16829
16632
|
*/
|
|
16830
16633
|
class Point {
|
|
16634
|
+
// base / generator point
|
|
16635
|
+
static BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
16636
|
+
// zero / infinity / identity point
|
|
16637
|
+
static ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO); // 0, 1, 0
|
|
16638
|
+
// math field
|
|
16639
|
+
static Fp = Fp;
|
|
16640
|
+
// scalar field
|
|
16641
|
+
static Fn = Fn;
|
|
16642
|
+
X;
|
|
16643
|
+
Y;
|
|
16644
|
+
Z;
|
|
16831
16645
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
16832
16646
|
constructor(X, Y, Z) {
|
|
16833
16647
|
this.X = acoord('x', X);
|
|
@@ -16851,12 +16665,12 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
16851
16665
|
return new Point(x, y, Fp.ONE);
|
|
16852
16666
|
}
|
|
16853
16667
|
static fromBytes(bytes) {
|
|
16854
|
-
const P = Point.fromAffine(decodePoint(
|
|
16668
|
+
const P = Point.fromAffine(decodePoint(utils_abytes(bytes, undefined, 'point')));
|
|
16855
16669
|
P.assertValidity();
|
|
16856
16670
|
return P;
|
|
16857
16671
|
}
|
|
16858
16672
|
static fromHex(hex) {
|
|
16859
|
-
return Point.fromBytes(
|
|
16673
|
+
return Point.fromBytes(utils_hexToBytes(hex));
|
|
16860
16674
|
}
|
|
16861
16675
|
get x() {
|
|
16862
16676
|
return this.toAffine().x;
|
|
@@ -17043,11 +16857,13 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
17043
16857
|
if (!Fn.isValid(sc))
|
|
17044
16858
|
throw new Error('invalid scalar: out of range'); // 0 is valid
|
|
17045
16859
|
if (sc === weierstrass_0n || p.is0())
|
|
17046
|
-
return Point.ZERO;
|
|
16860
|
+
return Point.ZERO; // 0
|
|
17047
16861
|
if (sc === weierstrass_1n)
|
|
17048
|
-
return p; //
|
|
16862
|
+
return p; // 1
|
|
17049
16863
|
if (wnaf.hasCache(this))
|
|
17050
|
-
return this.multiply(sc);
|
|
16864
|
+
return this.multiply(sc); // precomputes
|
|
16865
|
+
// We don't have method for double scalar multiplication (aP + bQ):
|
|
16866
|
+
// Even with using Strauss-Shamir trick, it's 35% slower than naïve mul+add.
|
|
17051
16867
|
if (endo) {
|
|
17052
16868
|
const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(sc);
|
|
17053
16869
|
const { p1, p2 } = mulEndoUnsafe(Point, p, k1, k2); // 30% faster vs wnaf.unsafe
|
|
@@ -17057,10 +16873,6 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
17057
16873
|
return wnaf.unsafe(p, sc);
|
|
17058
16874
|
}
|
|
17059
16875
|
}
|
|
17060
|
-
multiplyAndAddUnsafe(Q, a, b) {
|
|
17061
|
-
const sum = this.multiplyUnsafe(a).add(Q.multiplyUnsafe(b));
|
|
17062
|
-
return sum.is0() ? undefined : sum;
|
|
17063
|
-
}
|
|
17064
16876
|
/**
|
|
17065
16877
|
* Converts Projective point to affine (x, y) coordinates.
|
|
17066
16878
|
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
@@ -17093,50 +16905,17 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
17093
16905
|
return this.multiplyUnsafe(cofactor).is0();
|
|
17094
16906
|
}
|
|
17095
16907
|
toBytes(isCompressed = true) {
|
|
17096
|
-
|
|
16908
|
+
utils_abool(isCompressed, 'isCompressed');
|
|
17097
16909
|
this.assertValidity();
|
|
17098
16910
|
return encodePoint(Point, this, isCompressed);
|
|
17099
16911
|
}
|
|
17100
16912
|
toHex(isCompressed = true) {
|
|
17101
|
-
return
|
|
16913
|
+
return utils_bytesToHex(this.toBytes(isCompressed));
|
|
17102
16914
|
}
|
|
17103
16915
|
toString() {
|
|
17104
16916
|
return `<Point ${this.is0() ? 'ZERO' : this.toHex()}>`;
|
|
17105
16917
|
}
|
|
17106
|
-
// TODO: remove
|
|
17107
|
-
get px() {
|
|
17108
|
-
return this.X;
|
|
17109
|
-
}
|
|
17110
|
-
get py() {
|
|
17111
|
-
return this.X;
|
|
17112
|
-
}
|
|
17113
|
-
get pz() {
|
|
17114
|
-
return this.Z;
|
|
17115
|
-
}
|
|
17116
|
-
toRawBytes(isCompressed = true) {
|
|
17117
|
-
return this.toBytes(isCompressed);
|
|
17118
|
-
}
|
|
17119
|
-
_setWindowSize(windowSize) {
|
|
17120
|
-
this.precompute(windowSize);
|
|
17121
|
-
}
|
|
17122
|
-
static normalizeZ(points) {
|
|
17123
|
-
return normalizeZ(Point, points);
|
|
17124
|
-
}
|
|
17125
|
-
static msm(points, scalars) {
|
|
17126
|
-
return pippenger(Point, Fn, points, scalars);
|
|
17127
|
-
}
|
|
17128
|
-
static fromPrivateKey(privateKey) {
|
|
17129
|
-
return Point.BASE.multiply(_normFnElement(Fn, privateKey));
|
|
17130
|
-
}
|
|
17131
16918
|
}
|
|
17132
|
-
// base / generator point
|
|
17133
|
-
Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp.ONE);
|
|
17134
|
-
// zero / infinity / identity point
|
|
17135
|
-
Point.ZERO = new Point(Fp.ZERO, Fp.ONE, Fp.ZERO); // 0, 1, 0
|
|
17136
|
-
// math field
|
|
17137
|
-
Point.Fp = Fp;
|
|
17138
|
-
// scalar field
|
|
17139
|
-
Point.Fn = Fn;
|
|
17140
16919
|
const bits = Fn.BITS;
|
|
17141
16920
|
const wnaf = new wNAF(Point, extraOpts.endo ? Math.ceil(bits / 2) : bits);
|
|
17142
16921
|
Point.BASE.precompute(8); // Enable precomputes. Slows down first publicKey computation by 20ms.
|
|
@@ -17285,11 +17064,12 @@ function getWLengths(Fp, Fn) {
|
|
|
17285
17064
|
*/
|
|
17286
17065
|
function ecdh(Point, ecdhOpts = {}) {
|
|
17287
17066
|
const { Fn } = Point;
|
|
17288
|
-
const randomBytes_ = ecdhOpts.randomBytes ||
|
|
17067
|
+
const randomBytes_ = ecdhOpts.randomBytes || wcRandomBytes;
|
|
17289
17068
|
const lengths = Object.assign(getWLengths(Point.Fp, Fn), { seed: getMinHashLength(Fn.ORDER) });
|
|
17290
17069
|
function isValidSecretKey(secretKey) {
|
|
17291
17070
|
try {
|
|
17292
|
-
|
|
17071
|
+
const num = Fn.fromBytes(secretKey);
|
|
17072
|
+
return Fn.isValidNot0(num);
|
|
17293
17073
|
}
|
|
17294
17074
|
catch (error) {
|
|
17295
17075
|
return false;
|
|
@@ -17314,7 +17094,7 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
17314
17094
|
* (groupLen + ceil(groupLen / 2)) with modulo bias being negligible.
|
|
17315
17095
|
*/
|
|
17316
17096
|
function randomSecretKey(seed = randomBytes_(lengths.seed)) {
|
|
17317
|
-
return mapHashToField(
|
|
17097
|
+
return mapHashToField(abytes(seed, lengths.seed, 'seed'), Fn.ORDER);
|
|
17318
17098
|
}
|
|
17319
17099
|
/**
|
|
17320
17100
|
* Computes public key for a secret key. Checks for validity of the secret key.
|
|
@@ -17322,24 +17102,18 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
17322
17102
|
* @returns Public key, full when isCompressed=false; short when isCompressed=true
|
|
17323
17103
|
*/
|
|
17324
17104
|
function getPublicKey(secretKey, isCompressed = true) {
|
|
17325
|
-
return Point.BASE.multiply(
|
|
17326
|
-
}
|
|
17327
|
-
function keygen(seed) {
|
|
17328
|
-
const secretKey = randomSecretKey(seed);
|
|
17329
|
-
return { secretKey, publicKey: getPublicKey(secretKey) };
|
|
17105
|
+
return Point.BASE.multiply(Fn.fromBytes(secretKey)).toBytes(isCompressed);
|
|
17330
17106
|
}
|
|
17331
17107
|
/**
|
|
17332
17108
|
* Quick and dirty check for item being public key. Does not validate hex, or being on-curve.
|
|
17333
17109
|
*/
|
|
17334
17110
|
function isProbPub(item) {
|
|
17335
|
-
if (typeof item === 'bigint')
|
|
17336
|
-
return false;
|
|
17337
|
-
if (item instanceof Point)
|
|
17338
|
-
return true;
|
|
17339
17111
|
const { secretKey, publicKey, publicKeyUncompressed } = lengths;
|
|
17340
|
-
if (
|
|
17112
|
+
if (!isBytes(item))
|
|
17113
|
+
return undefined;
|
|
17114
|
+
if (('_lengths' in Fn && Fn._lengths) || secretKey === publicKey)
|
|
17341
17115
|
return undefined;
|
|
17342
|
-
const l =
|
|
17116
|
+
const l = abytes(item, undefined, 'key').length;
|
|
17343
17117
|
return l === publicKey || l === publicKeyUncompressed;
|
|
17344
17118
|
}
|
|
17345
17119
|
/**
|
|
@@ -17355,31 +17129,24 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
17355
17129
|
throw new Error('first arg must be private key');
|
|
17356
17130
|
if (isProbPub(publicKeyB) === false)
|
|
17357
17131
|
throw new Error('second arg must be public key');
|
|
17358
|
-
const s =
|
|
17359
|
-
const b = Point.
|
|
17132
|
+
const s = Fn.fromBytes(secretKeyA);
|
|
17133
|
+
const b = Point.fromBytes(publicKeyB); // checks for being on-curve
|
|
17360
17134
|
return b.multiply(s).toBytes(isCompressed);
|
|
17361
17135
|
}
|
|
17362
17136
|
const utils = {
|
|
17363
17137
|
isValidSecretKey,
|
|
17364
17138
|
isValidPublicKey,
|
|
17365
17139
|
randomSecretKey,
|
|
17366
|
-
// TODO: remove
|
|
17367
|
-
isValidPrivateKey: isValidSecretKey,
|
|
17368
|
-
randomPrivateKey: randomSecretKey,
|
|
17369
|
-
normPrivateKeyToScalar: (key) => _normFnElement(Fn, key),
|
|
17370
|
-
precompute(windowSize = 8, point = Point.BASE) {
|
|
17371
|
-
return point.precompute(windowSize, false);
|
|
17372
|
-
},
|
|
17373
17140
|
};
|
|
17141
|
+
const keygen = createKeygen(randomSecretKey, getPublicKey);
|
|
17374
17142
|
return Object.freeze({ getPublicKey, getSharedSecret, keygen, Point, utils, lengths });
|
|
17375
17143
|
}
|
|
17376
17144
|
/**
|
|
17377
17145
|
* Creates ECDSA signing interface for given elliptic curve `Point` and `hash` function.
|
|
17378
|
-
* We need `hash` for 2 features:
|
|
17379
|
-
* 1. Message prehash-ing. NOT used if `sign` / `verify` are called with `prehash: false`
|
|
17380
|
-
* 2. k generation in `sign`, using HMAC-drbg(hash)
|
|
17381
17146
|
*
|
|
17382
|
-
*
|
|
17147
|
+
* @param Point created using {@link weierstrass} function
|
|
17148
|
+
* @param hash used for 1) message prehash-ing 2) k generation in `sign`, using hmac_drbg(hash)
|
|
17149
|
+
* @param ecdsaOpts rarely needed, see {@link ECDSAOpts}
|
|
17383
17150
|
*
|
|
17384
17151
|
* @example
|
|
17385
17152
|
* ```js
|
|
@@ -17389,28 +17156,28 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
17389
17156
|
* const p256_sha224_r = ecdsa(p256_Point, sha224, { randomBytes: (length) => { ... } });
|
|
17390
17157
|
* ```
|
|
17391
17158
|
*/
|
|
17392
|
-
function
|
|
17159
|
+
function weierstrass_ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
17393
17160
|
ahash(hash);
|
|
17394
|
-
|
|
17161
|
+
validateObject(ecdsaOpts, {}, {
|
|
17395
17162
|
hmac: 'function',
|
|
17396
17163
|
lowS: 'boolean',
|
|
17397
17164
|
randomBytes: 'function',
|
|
17398
17165
|
bits2int: 'function',
|
|
17399
17166
|
bits2int_modN: 'function',
|
|
17400
17167
|
});
|
|
17401
|
-
|
|
17402
|
-
const
|
|
17403
|
-
|
|
17168
|
+
ecdsaOpts = Object.assign({}, ecdsaOpts);
|
|
17169
|
+
const randomBytes = ecdsaOpts.randomBytes || wcRandomBytes;
|
|
17170
|
+
const hmac = ecdsaOpts.hmac || ((key, msg) => nobleHmac(hash, key, msg));
|
|
17404
17171
|
const { Fp, Fn } = Point;
|
|
17405
17172
|
const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
|
|
17406
17173
|
const { keygen, getPublicKey, getSharedSecret, utils, lengths } = ecdh(Point, ecdsaOpts);
|
|
17407
17174
|
const defaultSigOpts = {
|
|
17408
|
-
prehash:
|
|
17409
|
-
lowS: typeof ecdsaOpts.lowS === 'boolean' ? ecdsaOpts.lowS :
|
|
17410
|
-
format:
|
|
17175
|
+
prehash: true,
|
|
17176
|
+
lowS: typeof ecdsaOpts.lowS === 'boolean' ? ecdsaOpts.lowS : true,
|
|
17177
|
+
format: 'compact',
|
|
17411
17178
|
extraEntropy: false,
|
|
17412
17179
|
};
|
|
17413
|
-
const
|
|
17180
|
+
const hasLargeCofactor = CURVE_ORDER * weierstrass_2n < Fp.ORDER; // Won't CURVE().h > 2n be more effective?
|
|
17414
17181
|
function isBiggerThanHalfOrder(number) {
|
|
17415
17182
|
const HALF = CURVE_ORDER >> weierstrass_1n;
|
|
17416
17183
|
return number > HALF;
|
|
@@ -17420,28 +17187,47 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17420
17187
|
throw new Error(`invalid signature ${title}: out of range 1..Point.Fn.ORDER`);
|
|
17421
17188
|
return num;
|
|
17422
17189
|
}
|
|
17190
|
+
function assertSmallCofactor() {
|
|
17191
|
+
// ECDSA recovery is hard for cofactor > 1 curves.
|
|
17192
|
+
// In sign, `r = q.x mod n`, and here we recover q.x from r.
|
|
17193
|
+
// While recovering q.x >= n, we need to add r+n for cofactor=1 curves.
|
|
17194
|
+
// However, for cofactor>1, r+n may not get q.x:
|
|
17195
|
+
// r+n*i would need to be done instead where i is unknown.
|
|
17196
|
+
// To easily get i, we either need to:
|
|
17197
|
+
// a. increase amount of valid recid values (4, 5...); OR
|
|
17198
|
+
// b. prohibit non-prime-order signatures (recid > 1).
|
|
17199
|
+
if (hasLargeCofactor)
|
|
17200
|
+
throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
|
|
17201
|
+
}
|
|
17423
17202
|
function validateSigLength(bytes, format) {
|
|
17424
17203
|
validateSigFormat(format);
|
|
17425
17204
|
const size = lengths.signature;
|
|
17426
17205
|
const sizer = format === 'compact' ? size : format === 'recovered' ? size + 1 : undefined;
|
|
17427
|
-
return
|
|
17206
|
+
return abytes(bytes, sizer);
|
|
17428
17207
|
}
|
|
17429
17208
|
/**
|
|
17430
17209
|
* ECDSA signature with its (r, s) properties. Supports compact, recovered & DER representations.
|
|
17431
17210
|
*/
|
|
17432
17211
|
class Signature {
|
|
17212
|
+
r;
|
|
17213
|
+
s;
|
|
17214
|
+
recovery;
|
|
17433
17215
|
constructor(r, s, recovery) {
|
|
17434
17216
|
this.r = validateRS('r', r); // r in [1..N-1];
|
|
17435
17217
|
this.s = validateRS('s', s); // s in [1..N-1];
|
|
17436
|
-
if (recovery != null)
|
|
17218
|
+
if (recovery != null) {
|
|
17219
|
+
assertSmallCofactor();
|
|
17220
|
+
if (![0, 1, 2, 3].includes(recovery))
|
|
17221
|
+
throw new Error('invalid recovery id');
|
|
17437
17222
|
this.recovery = recovery;
|
|
17223
|
+
}
|
|
17438
17224
|
Object.freeze(this);
|
|
17439
17225
|
}
|
|
17440
|
-
static fromBytes(bytes, format =
|
|
17226
|
+
static fromBytes(bytes, format = defaultSigOpts.format) {
|
|
17441
17227
|
validateSigLength(bytes, format);
|
|
17442
17228
|
let recid;
|
|
17443
17229
|
if (format === 'der') {
|
|
17444
|
-
const { r, s } = DER.toSig(
|
|
17230
|
+
const { r, s } = DER.toSig(abytes(bytes));
|
|
17445
17231
|
return new Signature(r, s);
|
|
17446
17232
|
}
|
|
17447
17233
|
if (format === 'recovered') {
|
|
@@ -17449,7 +17235,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17449
17235
|
format = 'compact';
|
|
17450
17236
|
bytes = bytes.subarray(1);
|
|
17451
17237
|
}
|
|
17452
|
-
const L =
|
|
17238
|
+
const L = lengths.signature / 2;
|
|
17453
17239
|
const r = bytes.subarray(0, L);
|
|
17454
17240
|
const s = bytes.subarray(L, L * 2);
|
|
17455
17241
|
return new Signature(Fn.fromBytes(r), Fn.fromBytes(s), recid);
|
|
@@ -17457,38 +17243,31 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17457
17243
|
static fromHex(hex, format) {
|
|
17458
17244
|
return this.fromBytes(hexToBytes(hex), format);
|
|
17459
17245
|
}
|
|
17246
|
+
assertRecovery() {
|
|
17247
|
+
const { recovery } = this;
|
|
17248
|
+
if (recovery == null)
|
|
17249
|
+
throw new Error('invalid recovery id: must be present');
|
|
17250
|
+
return recovery;
|
|
17251
|
+
}
|
|
17460
17252
|
addRecoveryBit(recovery) {
|
|
17461
17253
|
return new Signature(this.r, this.s, recovery);
|
|
17462
17254
|
}
|
|
17463
17255
|
recoverPublicKey(messageHash) {
|
|
17464
|
-
const
|
|
17465
|
-
const
|
|
17466
|
-
|
|
17467
|
-
throw new Error('recovery id invalid');
|
|
17468
|
-
// ECDSA recovery is hard for cofactor > 1 curves.
|
|
17469
|
-
// In sign, `r = q.x mod n`, and here we recover q.x from r.
|
|
17470
|
-
// While recovering q.x >= n, we need to add r+n for cofactor=1 curves.
|
|
17471
|
-
// However, for cofactor>1, r+n may not get q.x:
|
|
17472
|
-
// r+n*i would need to be done instead where i is unknown.
|
|
17473
|
-
// To easily get i, we either need to:
|
|
17474
|
-
// a. increase amount of valid recid values (4, 5...); OR
|
|
17475
|
-
// b. prohibit non-prime-order signatures (recid > 1).
|
|
17476
|
-
const hasCofactor = CURVE_ORDER * weierstrass_2n < FIELD_ORDER;
|
|
17477
|
-
if (hasCofactor && rec > 1)
|
|
17478
|
-
throw new Error('recovery id is ambiguous for h>1 curve');
|
|
17479
|
-
const radj = rec === 2 || rec === 3 ? r + CURVE_ORDER : r;
|
|
17256
|
+
const { r, s } = this;
|
|
17257
|
+
const recovery = this.assertRecovery();
|
|
17258
|
+
const radj = recovery === 2 || recovery === 3 ? r + CURVE_ORDER : r;
|
|
17480
17259
|
if (!Fp.isValid(radj))
|
|
17481
|
-
throw new Error('recovery id
|
|
17260
|
+
throw new Error('invalid recovery id: sig.r+curve.n != R.x');
|
|
17482
17261
|
const x = Fp.toBytes(radj);
|
|
17483
|
-
const R = Point.fromBytes(concatBytes(pprefix((
|
|
17262
|
+
const R = Point.fromBytes(concatBytes(pprefix((recovery & 1) === 0), x));
|
|
17484
17263
|
const ir = Fn.inv(radj); // r^-1
|
|
17485
|
-
const h = bits2int_modN(
|
|
17264
|
+
const h = bits2int_modN(abytes(messageHash, undefined, 'msgHash')); // Truncate hash
|
|
17486
17265
|
const u1 = Fn.create(-h * ir); // -hr^-1
|
|
17487
17266
|
const u2 = Fn.create(s * ir); // sr^-1
|
|
17488
17267
|
// (sr^-1)R-(hr^-1)G = -(hr^-1)G + (sr^-1). unsafe is fine: there is no private data.
|
|
17489
17268
|
const Q = Point.BASE.multiplyUnsafe(u1).add(R.multiplyUnsafe(u2));
|
|
17490
17269
|
if (Q.is0())
|
|
17491
|
-
throw new Error('point at infinify');
|
|
17270
|
+
throw new Error('invalid recovery: point at infinify');
|
|
17492
17271
|
Q.assertValidity();
|
|
17493
17272
|
return Q;
|
|
17494
17273
|
}
|
|
@@ -17496,45 +17275,22 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17496
17275
|
hasHighS() {
|
|
17497
17276
|
return isBiggerThanHalfOrder(this.s);
|
|
17498
17277
|
}
|
|
17499
|
-
toBytes(format =
|
|
17278
|
+
toBytes(format = defaultSigOpts.format) {
|
|
17500
17279
|
validateSigFormat(format);
|
|
17501
17280
|
if (format === 'der')
|
|
17502
17281
|
return hexToBytes(DER.hexFromSig(this));
|
|
17503
|
-
const r =
|
|
17504
|
-
const
|
|
17282
|
+
const { r, s } = this;
|
|
17283
|
+
const rb = Fn.toBytes(r);
|
|
17284
|
+
const sb = Fn.toBytes(s);
|
|
17505
17285
|
if (format === 'recovered') {
|
|
17506
|
-
|
|
17507
|
-
|
|
17508
|
-
return concatBytes(Uint8Array.of(this.recovery), r, s);
|
|
17286
|
+
assertSmallCofactor();
|
|
17287
|
+
return concatBytes(Uint8Array.of(this.assertRecovery()), rb, sb);
|
|
17509
17288
|
}
|
|
17510
|
-
return concatBytes(
|
|
17289
|
+
return concatBytes(rb, sb);
|
|
17511
17290
|
}
|
|
17512
17291
|
toHex(format) {
|
|
17513
17292
|
return bytesToHex(this.toBytes(format));
|
|
17514
17293
|
}
|
|
17515
|
-
// TODO: remove
|
|
17516
|
-
assertValidity() { }
|
|
17517
|
-
static fromCompact(hex) {
|
|
17518
|
-
return Signature.fromBytes(utils_ensureBytes('sig', hex), 'compact');
|
|
17519
|
-
}
|
|
17520
|
-
static fromDER(hex) {
|
|
17521
|
-
return Signature.fromBytes(utils_ensureBytes('sig', hex), 'der');
|
|
17522
|
-
}
|
|
17523
|
-
normalizeS() {
|
|
17524
|
-
return this.hasHighS() ? new Signature(this.r, Fn.neg(this.s), this.recovery) : this;
|
|
17525
|
-
}
|
|
17526
|
-
toDERRawBytes() {
|
|
17527
|
-
return this.toBytes('der');
|
|
17528
|
-
}
|
|
17529
|
-
toDERHex() {
|
|
17530
|
-
return bytesToHex(this.toBytes('der'));
|
|
17531
|
-
}
|
|
17532
|
-
toCompactRawBytes() {
|
|
17533
|
-
return this.toBytes('compact');
|
|
17534
|
-
}
|
|
17535
|
-
toCompactHex() {
|
|
17536
|
-
return bytesToHex(this.toBytes('compact'));
|
|
17537
|
-
}
|
|
17538
17294
|
}
|
|
17539
17295
|
// RFC6979: ensure ECDSA msg is X bytes and < N. RFC suggests optional truncating via bits2octets.
|
|
17540
17296
|
// FIPS 186-4 4.6 suggests the leftmost min(nBitLen, outLen) bits, which matches bits2int.
|
|
@@ -17547,7 +17303,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17547
17303
|
throw new Error('input is too large');
|
|
17548
17304
|
// For curves with nBitLength % 8 !== 0: bits2octets(bits2octets(m)) !== bits2octets(m)
|
|
17549
17305
|
// for some cases, since bytes.length * 8 is not actual bitLength.
|
|
17550
|
-
const num =
|
|
17306
|
+
const num = bytesToNumberBE(bytes); // check for == u8 done here
|
|
17551
17307
|
const delta = bytes.length * 8 - fnBits; // truncate to nBitLength leftmost bits
|
|
17552
17308
|
return delta > 0 ? num >> BigInt(delta) : num;
|
|
17553
17309
|
};
|
|
@@ -17556,7 +17312,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17556
17312
|
return Fn.create(bits2int(bytes)); // can't use bytesToNumberBE here
|
|
17557
17313
|
};
|
|
17558
17314
|
// Pads output with zero as per spec
|
|
17559
|
-
const ORDER_MASK =
|
|
17315
|
+
const ORDER_MASK = bitMask(fnBits);
|
|
17560
17316
|
/** Converts to bytes. Checks if num in `[0..ORDER_MASK-1]` e.g.: `[0..2^256-1]`. */
|
|
17561
17317
|
function int2octets(num) {
|
|
17562
17318
|
// IMPORTANT: the check ensures working for case `Fn.BYTES != Fn.BITS * 8`
|
|
@@ -17564,8 +17320,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17564
17320
|
return Fn.toBytes(num);
|
|
17565
17321
|
}
|
|
17566
17322
|
function validateMsgAndHash(message, prehash) {
|
|
17567
|
-
|
|
17568
|
-
return prehash ?
|
|
17323
|
+
abytes(message, undefined, 'message');
|
|
17324
|
+
return prehash ? abytes(hash(message), undefined, 'prehashed message') : message;
|
|
17569
17325
|
}
|
|
17570
17326
|
/**
|
|
17571
17327
|
* Steps A, D of RFC6979 3.2.
|
|
@@ -17575,26 +17331,26 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17575
17331
|
* Warning: we cannot assume here that message has same amount of bytes as curve order,
|
|
17576
17332
|
* this will be invalid at least for P521. Also it can be bigger for P224 + SHA256.
|
|
17577
17333
|
*/
|
|
17578
|
-
function prepSig(message,
|
|
17579
|
-
if (['recovered', 'canonical'].some((k) => k in opts))
|
|
17580
|
-
throw new Error('sign() legacy options not supported');
|
|
17334
|
+
function prepSig(message, secretKey, opts) {
|
|
17581
17335
|
const { lowS, prehash, extraEntropy } = validateSigOpts(opts, defaultSigOpts);
|
|
17582
17336
|
message = validateMsgAndHash(message, prehash); // RFC6979 3.2 A: h1 = H(m)
|
|
17583
17337
|
// We can't later call bits2octets, since nested bits2int is broken for curves
|
|
17584
17338
|
// with fnBits % 8 !== 0. Because of that, we unwrap it here as int2octets call.
|
|
17585
17339
|
// const bits2octets = (bits) => int2octets(bits2int_modN(bits))
|
|
17586
17340
|
const h1int = bits2int_modN(message);
|
|
17587
|
-
const d =
|
|
17341
|
+
const d = Fn.fromBytes(secretKey); // validate secret key, convert to bigint
|
|
17342
|
+
if (!Fn.isValidNot0(d))
|
|
17343
|
+
throw new Error('invalid private key');
|
|
17588
17344
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
17589
17345
|
// extraEntropy. RFC6979 3.6: additional k' (optional).
|
|
17590
17346
|
if (extraEntropy != null && extraEntropy !== false) {
|
|
17591
17347
|
// K = HMAC_K(V || 0x00 || int2octets(x) || bits2octets(h1) || k')
|
|
17592
17348
|
// gen random bytes OR pass as-is
|
|
17593
17349
|
const e = extraEntropy === true ? randomBytes(lengths.secretKey) : extraEntropy;
|
|
17594
|
-
seedArgs.push(
|
|
17350
|
+
seedArgs.push(abytes(e, undefined, 'extraEntropy')); // check for being bytes
|
|
17595
17351
|
}
|
|
17596
17352
|
const seed = concatBytes(...seedArgs); // Step D of RFC6979 3.2
|
|
17597
|
-
const m = h1int; //
|
|
17353
|
+
const m = h1int; // no need to call bits2int second time here, it is inside truncateHash!
|
|
17598
17354
|
// Converts signature params into point w r/s, checks result for validity.
|
|
17599
17355
|
// To transform k => Signature:
|
|
17600
17356
|
// q = k⋅G
|
|
@@ -17606,7 +17362,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17606
17362
|
function k2sig(kBytes) {
|
|
17607
17363
|
// RFC 6979 Section 3.2, step 3: k = bits2int(T)
|
|
17608
17364
|
// Important: all mod() calls here must be done over N
|
|
17609
|
-
const k = bits2int(kBytes); //
|
|
17365
|
+
const k = bits2int(kBytes); // Cannot use fields methods, since it is group element
|
|
17610
17366
|
if (!Fn.isValidNot0(k))
|
|
17611
17367
|
return; // Valid scalars (including k) must be in 1..N-1
|
|
17612
17368
|
const ik = Fn.inv(k); // k^-1 mod n
|
|
@@ -17614,16 +17370,16 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17614
17370
|
const r = Fn.create(q.x); // r = q.x mod n
|
|
17615
17371
|
if (r === weierstrass_0n)
|
|
17616
17372
|
return;
|
|
17617
|
-
const s = Fn.create(ik * Fn.create(m + r * d)); //
|
|
17373
|
+
const s = Fn.create(ik * Fn.create(m + r * d)); // s = k^-1(m + rd) mod n
|
|
17618
17374
|
if (s === weierstrass_0n)
|
|
17619
17375
|
return;
|
|
17620
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y & weierstrass_1n); // recovery bit (2 or 3
|
|
17376
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & weierstrass_1n); // recovery bit (2 or 3 when q.x>n)
|
|
17621
17377
|
let normS = s;
|
|
17622
17378
|
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
17623
|
-
normS = Fn.neg(s); // if lowS was passed, ensure s is always
|
|
17624
|
-
recovery ^= 1;
|
|
17379
|
+
normS = Fn.neg(s); // if lowS was passed, ensure s is always in the bottom half of N
|
|
17380
|
+
recovery ^= 1;
|
|
17625
17381
|
}
|
|
17626
|
-
return new Signature(r, normS,
|
|
17382
|
+
return new Signature(r, normS, hasLargeCofactor ? undefined : recovery);
|
|
17627
17383
|
}
|
|
17628
17384
|
return { seed, k2sig };
|
|
17629
17385
|
}
|
|
@@ -17639,46 +17395,10 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17639
17395
|
* ```
|
|
17640
17396
|
*/
|
|
17641
17397
|
function sign(message, secretKey, opts = {}) {
|
|
17642
|
-
message = utils_ensureBytes('message', message);
|
|
17643
17398
|
const { seed, k2sig } = prepSig(message, secretKey, opts); // Steps A, D of RFC6979 3.2.
|
|
17644
17399
|
const drbg = createHmacDrbg(hash.outputLen, Fn.BYTES, hmac);
|
|
17645
17400
|
const sig = drbg(seed, k2sig); // Steps B, C, D, E, F, G
|
|
17646
|
-
return sig;
|
|
17647
|
-
}
|
|
17648
|
-
function tryParsingSig(sg) {
|
|
17649
|
-
// Try to deduce format
|
|
17650
|
-
let sig = undefined;
|
|
17651
|
-
const isHex = typeof sg === 'string' || isBytes(sg);
|
|
17652
|
-
const isObj = !isHex &&
|
|
17653
|
-
sg !== null &&
|
|
17654
|
-
typeof sg === 'object' &&
|
|
17655
|
-
typeof sg.r === 'bigint' &&
|
|
17656
|
-
typeof sg.s === 'bigint';
|
|
17657
|
-
if (!isHex && !isObj)
|
|
17658
|
-
throw new Error('invalid signature, expected Uint8Array, hex string or Signature instance');
|
|
17659
|
-
if (isObj) {
|
|
17660
|
-
sig = new Signature(sg.r, sg.s);
|
|
17661
|
-
}
|
|
17662
|
-
else if (isHex) {
|
|
17663
|
-
try {
|
|
17664
|
-
sig = Signature.fromBytes(utils_ensureBytes('sig', sg), 'der');
|
|
17665
|
-
}
|
|
17666
|
-
catch (derError) {
|
|
17667
|
-
if (!(derError instanceof DER.Err))
|
|
17668
|
-
throw derError;
|
|
17669
|
-
}
|
|
17670
|
-
if (!sig) {
|
|
17671
|
-
try {
|
|
17672
|
-
sig = Signature.fromBytes(utils_ensureBytes('sig', sg), 'compact');
|
|
17673
|
-
}
|
|
17674
|
-
catch (error) {
|
|
17675
|
-
return false;
|
|
17676
|
-
}
|
|
17677
|
-
}
|
|
17678
|
-
}
|
|
17679
|
-
if (!sig)
|
|
17680
|
-
return false;
|
|
17681
|
-
return sig;
|
|
17401
|
+
return sig.toBytes(opts.format);
|
|
17682
17402
|
}
|
|
17683
17403
|
/**
|
|
17684
17404
|
* Verifies a signature against message and public key.
|
|
@@ -17695,16 +17415,15 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17695
17415
|
*/
|
|
17696
17416
|
function verify(signature, message, publicKey, opts = {}) {
|
|
17697
17417
|
const { lowS, prehash, format } = validateSigOpts(opts, defaultSigOpts);
|
|
17698
|
-
publicKey =
|
|
17699
|
-
message = validateMsgAndHash(
|
|
17700
|
-
if (
|
|
17701
|
-
|
|
17702
|
-
|
|
17703
|
-
|
|
17704
|
-
|
|
17705
|
-
if (sig === false)
|
|
17706
|
-
return false;
|
|
17418
|
+
publicKey = abytes(publicKey, undefined, 'publicKey');
|
|
17419
|
+
message = validateMsgAndHash(message, prehash);
|
|
17420
|
+
if (!isBytes(signature)) {
|
|
17421
|
+
const end = signature instanceof Signature ? ', use sig.toBytes()' : '';
|
|
17422
|
+
throw new Error('verify expects Uint8Array signature' + end);
|
|
17423
|
+
}
|
|
17424
|
+
validateSigLength(signature, format); // execute this twice because we want loud error
|
|
17707
17425
|
try {
|
|
17426
|
+
const sig = Signature.fromBytes(signature, format);
|
|
17708
17427
|
const P = Point.fromBytes(publicKey);
|
|
17709
17428
|
if (lowS && sig.hasHighS())
|
|
17710
17429
|
return false;
|
|
@@ -17742,114 +17461,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
17742
17461
|
hash,
|
|
17743
17462
|
});
|
|
17744
17463
|
}
|
|
17745
|
-
/** @deprecated use `weierstrass` in newer releases */
|
|
17746
|
-
function weierstrassPoints(c) {
|
|
17747
|
-
const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c);
|
|
17748
|
-
const Point = weierstrassN(CURVE, curveOpts);
|
|
17749
|
-
return _weierstrass_new_output_to_legacy(c, Point);
|
|
17750
|
-
}
|
|
17751
|
-
function _weierstrass_legacy_opts_to_new(c) {
|
|
17752
|
-
const CURVE = {
|
|
17753
|
-
a: c.a,
|
|
17754
|
-
b: c.b,
|
|
17755
|
-
p: c.Fp.ORDER,
|
|
17756
|
-
n: c.n,
|
|
17757
|
-
h: c.h,
|
|
17758
|
-
Gx: c.Gx,
|
|
17759
|
-
Gy: c.Gy,
|
|
17760
|
-
};
|
|
17761
|
-
const Fp = c.Fp;
|
|
17762
|
-
let allowedLengths = c.allowedPrivateKeyLengths
|
|
17763
|
-
? Array.from(new Set(c.allowedPrivateKeyLengths.map((l) => Math.ceil(l / 2))))
|
|
17764
|
-
: undefined;
|
|
17765
|
-
const Fn = Field(CURVE.n, {
|
|
17766
|
-
BITS: c.nBitLength,
|
|
17767
|
-
allowedLengths: allowedLengths,
|
|
17768
|
-
modFromBytes: c.wrapPrivateKey,
|
|
17769
|
-
});
|
|
17770
|
-
const curveOpts = {
|
|
17771
|
-
Fp,
|
|
17772
|
-
Fn,
|
|
17773
|
-
allowInfinityPoint: c.allowInfinityPoint,
|
|
17774
|
-
endo: c.endo,
|
|
17775
|
-
isTorsionFree: c.isTorsionFree,
|
|
17776
|
-
clearCofactor: c.clearCofactor,
|
|
17777
|
-
fromBytes: c.fromBytes,
|
|
17778
|
-
toBytes: c.toBytes,
|
|
17779
|
-
};
|
|
17780
|
-
return { CURVE, curveOpts };
|
|
17781
|
-
}
|
|
17782
|
-
function _ecdsa_legacy_opts_to_new(c) {
|
|
17783
|
-
const { CURVE, curveOpts } = _weierstrass_legacy_opts_to_new(c);
|
|
17784
|
-
const ecdsaOpts = {
|
|
17785
|
-
hmac: c.hmac,
|
|
17786
|
-
randomBytes: c.randomBytes,
|
|
17787
|
-
lowS: c.lowS,
|
|
17788
|
-
bits2int: c.bits2int,
|
|
17789
|
-
bits2int_modN: c.bits2int_modN,
|
|
17790
|
-
};
|
|
17791
|
-
return { CURVE, curveOpts, hash: c.hash, ecdsaOpts };
|
|
17792
|
-
}
|
|
17793
|
-
function _legacyHelperEquat(Fp, a, b) {
|
|
17794
|
-
/**
|
|
17795
|
-
* y² = x³ + ax + b: Short weierstrass curve formula. Takes x, returns y².
|
|
17796
|
-
* @returns y²
|
|
17797
|
-
*/
|
|
17798
|
-
function weierstrassEquation(x) {
|
|
17799
|
-
const x2 = Fp.sqr(x); // x * x
|
|
17800
|
-
const x3 = Fp.mul(x2, x); // x² * x
|
|
17801
|
-
return Fp.add(Fp.add(x3, Fp.mul(x, a)), b); // x³ + a * x + b
|
|
17802
|
-
}
|
|
17803
|
-
return weierstrassEquation;
|
|
17804
|
-
}
|
|
17805
|
-
function _weierstrass_new_output_to_legacy(c, Point) {
|
|
17806
|
-
const { Fp, Fn } = Point;
|
|
17807
|
-
function isWithinCurveOrder(num) {
|
|
17808
|
-
return inRange(num, weierstrass_1n, Fn.ORDER);
|
|
17809
|
-
}
|
|
17810
|
-
const weierstrassEquation = _legacyHelperEquat(Fp, c.a, c.b);
|
|
17811
|
-
return Object.assign({}, {
|
|
17812
|
-
CURVE: c,
|
|
17813
|
-
Point: Point,
|
|
17814
|
-
ProjectivePoint: Point,
|
|
17815
|
-
normPrivateKeyToScalar: (key) => _normFnElement(Fn, key),
|
|
17816
|
-
weierstrassEquation,
|
|
17817
|
-
isWithinCurveOrder,
|
|
17818
|
-
});
|
|
17819
|
-
}
|
|
17820
|
-
function _ecdsa_new_output_to_legacy(c, _ecdsa) {
|
|
17821
|
-
const Point = _ecdsa.Point;
|
|
17822
|
-
return Object.assign({}, _ecdsa, {
|
|
17823
|
-
ProjectivePoint: Point,
|
|
17824
|
-
CURVE: Object.assign({}, c, modular_nLength(Point.Fn.ORDER, Point.Fn.BITS)),
|
|
17825
|
-
});
|
|
17826
|
-
}
|
|
17827
|
-
// _ecdsa_legacy
|
|
17828
|
-
function weierstrass(c) {
|
|
17829
|
-
const { CURVE, curveOpts, hash, ecdsaOpts } = _ecdsa_legacy_opts_to_new(c);
|
|
17830
|
-
const Point = weierstrassN(CURVE, curveOpts);
|
|
17831
|
-
const signs = ecdsa(Point, hash, ecdsaOpts);
|
|
17832
|
-
return _ecdsa_new_output_to_legacy(c, signs);
|
|
17833
|
-
}
|
|
17834
17464
|
//# sourceMappingURL=weierstrass.js.map
|
|
17835
|
-
;// ./node_modules/@noble/curves/
|
|
17836
|
-
/**
|
|
17837
|
-
* Utilities for short weierstrass curves, combined with noble-hashes.
|
|
17838
|
-
* @module
|
|
17839
|
-
*/
|
|
17840
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
17841
|
-
|
|
17842
|
-
/** connects noble-curves to noble-hashes */
|
|
17843
|
-
function getHash(hash) {
|
|
17844
|
-
return { hash };
|
|
17845
|
-
}
|
|
17846
|
-
/** @deprecated use new `weierstrass()` and `ecdsa()` methods */
|
|
17847
|
-
function createCurve(curveDef, defHash) {
|
|
17848
|
-
const create = (hash) => weierstrass({ ...curveDef, hash: hash });
|
|
17849
|
-
return { ...create(defHash), create };
|
|
17850
|
-
}
|
|
17851
|
-
//# sourceMappingURL=_shortw_utils.js.map
|
|
17852
|
-
;// ./node_modules/@noble/curves/esm/secp256k1.js
|
|
17465
|
+
;// ./node_modules/@noble/curves/secp256k1.js
|
|
17853
17466
|
/**
|
|
17854
17467
|
* SECG secp256k1. See [pdf](https://www.secg.org/sec2-v2.pdf).
|
|
17855
17468
|
*
|
|
@@ -17866,7 +17479,7 @@ function createCurve(curveDef, defHash) {
|
|
|
17866
17479
|
|
|
17867
17480
|
|
|
17868
17481
|
// Seems like generator was produced from some seed:
|
|
17869
|
-
// `
|
|
17482
|
+
// `Pointk1.BASE.multiply(Pointk1.Fn.inv(2n, N)).toAffine().x`
|
|
17870
17483
|
// // gives short x 0x3b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63n
|
|
17871
17484
|
const secp256k1_CURVE = {
|
|
17872
17485
|
p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'),
|
|
@@ -17885,7 +17498,6 @@ const secp256k1_ENDO = {
|
|
|
17885
17498
|
],
|
|
17886
17499
|
};
|
|
17887
17500
|
const secp256k1_0n = /* @__PURE__ */ BigInt(0);
|
|
17888
|
-
const secp256k1_1n = /* @__PURE__ */ BigInt(1);
|
|
17889
17501
|
const secp256k1_2n = /* @__PURE__ */ BigInt(2);
|
|
17890
17502
|
/**
|
|
17891
17503
|
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
|
|
@@ -17916,21 +17528,28 @@ function sqrtMod(y) {
|
|
|
17916
17528
|
return root;
|
|
17917
17529
|
}
|
|
17918
17530
|
const Fpk1 = Field(secp256k1_CURVE.p, { sqrt: sqrtMod });
|
|
17531
|
+
const Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
|
|
17532
|
+
Fp: Fpk1,
|
|
17533
|
+
endo: secp256k1_ENDO,
|
|
17534
|
+
});
|
|
17919
17535
|
/**
|
|
17920
|
-
* secp256k1 curve
|
|
17536
|
+
* secp256k1 curve: ECDSA and ECDH methods.
|
|
17921
17537
|
*
|
|
17922
|
-
*
|
|
17538
|
+
* Uses sha256 to hash messages. To use a different hash,
|
|
17539
|
+
* pass `{ prehash: false }` to sign / verify.
|
|
17923
17540
|
*
|
|
17924
17541
|
* @example
|
|
17925
17542
|
* ```js
|
|
17926
|
-
* import { secp256k1 } from '@noble/curves/secp256k1';
|
|
17543
|
+
* import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
17927
17544
|
* const { secretKey, publicKey } = secp256k1.keygen();
|
|
17928
|
-
* const
|
|
17545
|
+
* // const publicKey = secp256k1.getPublicKey(secretKey);
|
|
17546
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
17929
17547
|
* const sig = secp256k1.sign(msg, secretKey);
|
|
17930
|
-
* const isValid = secp256k1.verify(sig, msg, publicKey)
|
|
17548
|
+
* const isValid = secp256k1.verify(sig, msg, publicKey);
|
|
17549
|
+
* // const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
|
|
17931
17550
|
* ```
|
|
17932
17551
|
*/
|
|
17933
|
-
const secp256k1 =
|
|
17552
|
+
const secp256k1 = /* @__PURE__ */ (/* unused pure expression or super */ null && (ecdsa(Pointk1, sha256)));
|
|
17934
17553
|
// Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
|
|
17935
17554
|
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
17936
17555
|
/** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
|
|
@@ -17938,20 +17557,19 @@ const TAGGED_HASH_PREFIXES = {};
|
|
|
17938
17557
|
function taggedHash(tag, ...messages) {
|
|
17939
17558
|
let tagP = TAGGED_HASH_PREFIXES[tag];
|
|
17940
17559
|
if (tagP === undefined) {
|
|
17941
|
-
const tagH = sha2_sha256(
|
|
17942
|
-
tagP =
|
|
17560
|
+
const tagH = sha2_sha256(asciiToBytes(tag));
|
|
17561
|
+
tagP = utils_concatBytes(tagH, tagH);
|
|
17943
17562
|
TAGGED_HASH_PREFIXES[tag] = tagP;
|
|
17944
17563
|
}
|
|
17945
|
-
return sha2_sha256(
|
|
17564
|
+
return sha2_sha256(utils_concatBytes(tagP, ...messages));
|
|
17946
17565
|
}
|
|
17947
17566
|
// ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03
|
|
17948
17567
|
const pointToBytes = (point) => point.toBytes(true).slice(1);
|
|
17949
|
-
const Pointk1 = /* @__PURE__ */ (() => secp256k1.Point)();
|
|
17950
17568
|
const hasEven = (y) => y % secp256k1_2n === secp256k1_0n;
|
|
17951
17569
|
// Calculate point, scalar and bytes
|
|
17952
17570
|
function schnorrGetExtPubKey(priv) {
|
|
17953
17571
|
const { Fn, BASE } = Pointk1;
|
|
17954
|
-
const d_ =
|
|
17572
|
+
const d_ = Fn.fromBytes(priv);
|
|
17955
17573
|
const p = BASE.multiply(d_); // P = d'⋅G; 0 < d' < n check is done inside
|
|
17956
17574
|
const scalar = hasEven(p.y) ? d_ : Fn.neg(d_);
|
|
17957
17575
|
return { scalar, bytes: pointToBytes(p) };
|
|
@@ -17992,11 +17610,11 @@ function schnorrGetPublicKey(secretKey) {
|
|
|
17992
17610
|
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
|
|
17993
17611
|
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
|
|
17994
17612
|
*/
|
|
17995
|
-
function schnorrSign(message, secretKey, auxRand =
|
|
17613
|
+
function schnorrSign(message, secretKey, auxRand = randomBytes(32)) {
|
|
17996
17614
|
const { Fn } = Pointk1;
|
|
17997
|
-
const m =
|
|
17615
|
+
const m = utils_abytes(message, undefined, 'message');
|
|
17998
17616
|
const { bytes: px, scalar: d } = schnorrGetExtPubKey(secretKey); // checks for isWithinCurveOrder
|
|
17999
|
-
const a =
|
|
17617
|
+
const a = utils_abytes(auxRand, 32, 'auxRand'); // Auxiliary random data a: a 32-byte array
|
|
18000
17618
|
const t = Fn.toBytes(d ^ num(taggedHash('BIP0340/aux', a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
|
|
18001
17619
|
const rand = taggedHash('BIP0340/nonce', t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
|
|
18002
17620
|
// Let k' = int(rand) mod n. Fail if k' = 0. Let R = k'⋅G
|
|
@@ -18015,20 +17633,19 @@ function schnorrSign(message, secretKey, auxRand = utils_randomBytes(32)) {
|
|
|
18015
17633
|
* Will swallow errors & return false except for initial type validation of arguments.
|
|
18016
17634
|
*/
|
|
18017
17635
|
function schnorrVerify(signature, message, publicKey) {
|
|
18018
|
-
const { Fn, BASE } = Pointk1;
|
|
18019
|
-
const sig =
|
|
18020
|
-
const m =
|
|
18021
|
-
const pub =
|
|
17636
|
+
const { Fp, Fn, BASE } = Pointk1;
|
|
17637
|
+
const sig = utils_abytes(signature, 64, 'signature');
|
|
17638
|
+
const m = utils_abytes(message, undefined, 'message');
|
|
17639
|
+
const pub = utils_abytes(publicKey, 32, 'publicKey');
|
|
18022
17640
|
try {
|
|
18023
17641
|
const P = lift_x(num(pub)); // P = lift_x(int(pk)); fail if that fails
|
|
18024
17642
|
const r = num(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
18025
|
-
if (!
|
|
17643
|
+
if (!Fp.isValidNot0(r))
|
|
18026
17644
|
return false;
|
|
18027
17645
|
const s = num(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
18028
|
-
if (!
|
|
17646
|
+
if (!Fn.isValidNot0(s))
|
|
18029
17647
|
return false;
|
|
18030
|
-
// int(challenge(bytes(r)||bytes(P)||m))%n
|
|
18031
|
-
const e = challenge(Fn.toBytes(r), pointToBytes(P), m);
|
|
17648
|
+
const e = challenge(Fn.toBytes(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
|
|
18032
17649
|
// R = s⋅G - e⋅P, where -eP == (n-e)P
|
|
18033
17650
|
const R = BASE.multiplyUnsafe(s).add(P.multiplyUnsafe(Fn.neg(e)));
|
|
18034
17651
|
const { x, y } = R.toAffine();
|
|
@@ -18046,7 +17663,7 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
18046
17663
|
* https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
18047
17664
|
* @example
|
|
18048
17665
|
* ```js
|
|
18049
|
-
* import { schnorr } from '@noble/curves/secp256k1';
|
|
17666
|
+
* import { schnorr } from '@noble/curves/secp256k1.js';
|
|
18050
17667
|
* const { secretKey, publicKey } = schnorr.keygen();
|
|
18051
17668
|
* // const publicKey = schnorr.getPublicKey(secretKey);
|
|
18052
17669
|
* const msg = new TextEncoder().encode('hello');
|
|
@@ -18057,31 +17674,20 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
18057
17674
|
const schnorr = /* @__PURE__ */ (() => {
|
|
18058
17675
|
const size = 32;
|
|
18059
17676
|
const seedLength = 48;
|
|
18060
|
-
const randomSecretKey = (seed =
|
|
18061
|
-
return
|
|
17677
|
+
const randomSecretKey = (seed = randomBytes(seedLength)) => {
|
|
17678
|
+
return modular_mapHashToField(seed, secp256k1_CURVE.n);
|
|
18062
17679
|
};
|
|
18063
|
-
// TODO: remove
|
|
18064
|
-
secp256k1.utils.randomSecretKey;
|
|
18065
|
-
function keygen(seed) {
|
|
18066
|
-
const secretKey = randomSecretKey(seed);
|
|
18067
|
-
return { secretKey, publicKey: schnorrGetPublicKey(secretKey) };
|
|
18068
|
-
}
|
|
18069
17680
|
return {
|
|
18070
|
-
keygen,
|
|
17681
|
+
keygen: curve_createKeygen(randomSecretKey, schnorrGetPublicKey),
|
|
18071
17682
|
getPublicKey: schnorrGetPublicKey,
|
|
18072
17683
|
sign: schnorrSign,
|
|
18073
17684
|
verify: schnorrVerify,
|
|
18074
17685
|
Point: Pointk1,
|
|
18075
17686
|
utils: {
|
|
18076
|
-
randomSecretKey
|
|
18077
|
-
randomPrivateKey: randomSecretKey,
|
|
17687
|
+
randomSecretKey,
|
|
18078
17688
|
taggedHash,
|
|
18079
|
-
// TODO: remove
|
|
18080
17689
|
lift_x,
|
|
18081
17690
|
pointToBytes,
|
|
18082
|
-
numberToBytesBE: numberToBytesBE,
|
|
18083
|
-
bytesToNumberBE: utils_bytesToNumberBE,
|
|
18084
|
-
mod: mod,
|
|
18085
17691
|
},
|
|
18086
17692
|
lengths: {
|
|
18087
17693
|
secretKey: size,
|
|
@@ -18127,7 +17733,7 @@ const mapSWU = /* @__PURE__ */ (/* unused pure expression or super */ null && ((
|
|
|
18127
17733
|
Z: Fpk1.create(BigInt('-11')),
|
|
18128
17734
|
}))()));
|
|
18129
17735
|
/** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
|
|
18130
|
-
const secp256k1_hasher = /* @__PURE__ */ (/* unused pure expression or super */ null && ((() => createHasher(
|
|
17736
|
+
const secp256k1_hasher = /* @__PURE__ */ (/* unused pure expression or super */ null && ((() => createHasher(Pointk1, (scalars) => {
|
|
18131
17737
|
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
18132
17738
|
return isoMap(x, y);
|
|
18133
17739
|
}, {
|
|
@@ -18139,32 +17745,7 @@ const secp256k1_hasher = /* @__PURE__ */ (/* unused pure expression or super */
|
|
|
18139
17745
|
expand: 'xmd',
|
|
18140
17746
|
hash: sha256,
|
|
18141
17747
|
}))()));
|
|
18142
|
-
/** @deprecated use `import { secp256k1_hasher } from '@noble/curves/secp256k1.js';` */
|
|
18143
|
-
const hashToCurve = /* @__PURE__ */ (/* unused pure expression or super */ null && ((() => secp256k1_hasher.hashToCurve)()));
|
|
18144
|
-
/** @deprecated use `import { secp256k1_hasher } from '@noble/curves/secp256k1.js';` */
|
|
18145
|
-
const encodeToCurve = /* @__PURE__ */ (/* unused pure expression or super */ null && ((() => secp256k1_hasher.encodeToCurve)()));
|
|
18146
17748
|
//# sourceMappingURL=secp256k1.js.map
|
|
18147
|
-
;// ./node_modules/@noble/hashes/esm/sha256.js
|
|
18148
|
-
/**
|
|
18149
|
-
* SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
|
|
18150
|
-
*
|
|
18151
|
-
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
|
18152
|
-
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
|
18153
|
-
*
|
|
18154
|
-
* Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
|
18155
|
-
* @module
|
|
18156
|
-
* @deprecated
|
|
18157
|
-
*/
|
|
18158
|
-
|
|
18159
|
-
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
18160
|
-
const sha256_SHA256 = (/* unused pure expression or super */ null && (SHA256n));
|
|
18161
|
-
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
18162
|
-
const sha256_sha256 = sha2_sha256;
|
|
18163
|
-
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
18164
|
-
const sha256_SHA224 = (/* unused pure expression or super */ null && (SHA224n));
|
|
18165
|
-
/** @deprecated Use import from `noble/hashes/sha2` module */
|
|
18166
|
-
const sha256_sha224 = (/* unused pure expression or super */ null && (sha224n));
|
|
18167
|
-
//# sourceMappingURL=sha256.js.map
|
|
18168
17749
|
;// ./src/chat/signature.ts
|
|
18169
17750
|
|
|
18170
17751
|
|
|
@@ -18231,8 +17812,8 @@ function serializeMsg(msg) {
|
|
|
18231
17812
|
return JSON.stringify(msg);
|
|
18232
17813
|
}
|
|
18233
17814
|
function getMsgHash(message) {
|
|
18234
|
-
var msgHash =
|
|
18235
|
-
return
|
|
17815
|
+
var msgHash = sha2_sha256(utf8Encoder.encode(serializeMsg(message)));
|
|
17816
|
+
return utils_bytesToHex(msgHash);
|
|
18236
17817
|
}
|
|
18237
17818
|
|
|
18238
17819
|
// const isRecord = (obj: unknown): obj is Record<string, unknown> => obj instanceof Object
|
|
@@ -18258,10 +17839,10 @@ function getMsgHash(message) {
|
|
|
18258
17839
|
} */
|
|
18259
17840
|
|
|
18260
17841
|
function verifySignature(sig, message, pubKey) {
|
|
18261
|
-
return schnorr.verify(sig, getMsgHash(message), pubKey);
|
|
17842
|
+
return schnorr.verify(utils_hexToBytes(sig), utils_hexToBytes(getMsgHash(message)), utils_hexToBytes(pubKey));
|
|
18262
17843
|
}
|
|
18263
17844
|
function signMsg(message, key) {
|
|
18264
|
-
return
|
|
17845
|
+
return utils_bytesToHex(schnorr.sign(utils_hexToBytes(getMsgHash(message)), utils_hexToBytes(key)));
|
|
18265
17846
|
}
|
|
18266
17847
|
;// ./src/utils/keyHelpers/otherHelpers.ts
|
|
18267
17848
|
|
|
@@ -18489,10 +18070,10 @@ var keyAclBody = function keyAclBody(keyDoc, me) {
|
|
|
18489
18070
|
|
|
18490
18071
|
|
|
18491
18072
|
function generatePrivateKey() {
|
|
18492
|
-
return
|
|
18073
|
+
return utils_bytesToHex(schnorr.utils.randomSecretKey());
|
|
18493
18074
|
}
|
|
18494
18075
|
function generatePublicKey(privateKey) {
|
|
18495
|
-
return
|
|
18076
|
+
return utils_bytesToHex(schnorr.getPublicKey(utils_hexToBytes(privateKey)));
|
|
18496
18077
|
}
|
|
18497
18078
|
|
|
18498
18079
|
/**
|