@bcts/components 1.0.0-alpha.5 → 1.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -709
- package/dist/index.cjs.map +1 -1
- package/dist/index.iife.js +3 -711
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +1 -708
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ let __bcts_uniform_resources = require("@bcts/uniform-resources");
|
|
|
33
33
|
let __bcts_rand = require("@bcts/rand");
|
|
34
34
|
let __scure_sr25519 = require("@scure/sr25519");
|
|
35
35
|
__scure_sr25519 = __toESM(__scure_sr25519);
|
|
36
|
+
let __noble_hashes_blake2b = require("@noble/hashes/blake2b");
|
|
36
37
|
let __bcts_sskr = require("@bcts/sskr");
|
|
37
38
|
let __noble_post_quantum_ml_dsa = require("@noble/post-quantum/ml-dsa");
|
|
38
39
|
let __noble_post_quantum_ml_kem = require("@noble/post-quantum/ml-kem");
|
|
@@ -3121,714 +3122,6 @@ var Ed25519PrivateKey = class Ed25519PrivateKey {
|
|
|
3121
3122
|
}
|
|
3122
3123
|
};
|
|
3123
3124
|
|
|
3124
|
-
//#endregion
|
|
3125
|
-
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
|
|
3126
|
-
/**
|
|
3127
|
-
* Utilities for hex, bytes, CSPRNG.
|
|
3128
|
-
* @module
|
|
3129
|
-
*/
|
|
3130
|
-
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3131
|
-
/** Checks if something is Uint8Array. Be careful: nodejs Buffer will return true. */
|
|
3132
|
-
function isBytes(a) {
|
|
3133
|
-
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
3134
|
-
}
|
|
3135
|
-
/** Asserts something is positive integer. */
|
|
3136
|
-
function anumber(n, title = "") {
|
|
3137
|
-
if (!Number.isSafeInteger(n) || n < 0) {
|
|
3138
|
-
const prefix = title && `"${title}" `;
|
|
3139
|
-
throw new Error(`${prefix}expected integer >= 0, got ${n}`);
|
|
3140
|
-
}
|
|
3141
|
-
}
|
|
3142
|
-
/** Asserts something is Uint8Array. */
|
|
3143
|
-
function abytes(value, length, title = "") {
|
|
3144
|
-
const bytes = isBytes(value);
|
|
3145
|
-
const len = value?.length;
|
|
3146
|
-
const needsLen = length !== void 0;
|
|
3147
|
-
if (!bytes || needsLen && len !== length) {
|
|
3148
|
-
const prefix = title && `"${title}" `;
|
|
3149
|
-
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
3150
|
-
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
3151
|
-
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
3152
|
-
}
|
|
3153
|
-
return value;
|
|
3154
|
-
}
|
|
3155
|
-
/** Asserts a hash instance has not been destroyed / finished */
|
|
3156
|
-
function aexists(instance, checkFinished = true) {
|
|
3157
|
-
if (instance.destroyed) throw new Error("Hash instance has been destroyed");
|
|
3158
|
-
if (checkFinished && instance.finished) throw new Error("Hash#digest() has already been called");
|
|
3159
|
-
}
|
|
3160
|
-
/** Asserts output is properly-sized byte array */
|
|
3161
|
-
function aoutput(out, instance) {
|
|
3162
|
-
abytes(out, void 0, "digestInto() output");
|
|
3163
|
-
const min = instance.outputLen;
|
|
3164
|
-
if (out.length < min) throw new Error("\"digestInto() output\" expected to be of length >=" + min);
|
|
3165
|
-
}
|
|
3166
|
-
/** Cast u8 / u16 / u32 to u32. */
|
|
3167
|
-
function u32(arr) {
|
|
3168
|
-
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
3169
|
-
}
|
|
3170
|
-
/** Zeroize a byte array. Warning: JS provides no guarantees. */
|
|
3171
|
-
function clean(...arrays) {
|
|
3172
|
-
for (let i = 0; i < arrays.length; i++) arrays[i].fill(0);
|
|
3173
|
-
}
|
|
3174
|
-
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
|
3175
|
-
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
3176
|
-
/** The byte swap operation for uint32 */
|
|
3177
|
-
function byteSwap(word) {
|
|
3178
|
-
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
3179
|
-
}
|
|
3180
|
-
/** Conditionally byte swap if on a big-endian platform */
|
|
3181
|
-
const swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
|
|
3182
|
-
/** In place byte swap for Uint32Array */
|
|
3183
|
-
function byteSwap32(arr) {
|
|
3184
|
-
for (let i = 0; i < arr.length; i++) arr[i] = byteSwap(arr[i]);
|
|
3185
|
-
return arr;
|
|
3186
|
-
}
|
|
3187
|
-
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
3188
|
-
/** Creates function with outputLen, blockLen, create properties from a class constructor. */
|
|
3189
|
-
function createHasher(hashCons, info = {}) {
|
|
3190
|
-
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
3191
|
-
const tmp = hashCons(void 0);
|
|
3192
|
-
hashC.outputLen = tmp.outputLen;
|
|
3193
|
-
hashC.blockLen = tmp.blockLen;
|
|
3194
|
-
hashC.create = (opts) => hashCons(opts);
|
|
3195
|
-
Object.assign(hashC, info);
|
|
3196
|
-
return Object.freeze(hashC);
|
|
3197
|
-
}
|
|
3198
|
-
|
|
3199
|
-
//#endregion
|
|
3200
|
-
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/_blake.js
|
|
3201
|
-
/**
|
|
3202
|
-
* Internal blake variable.
|
|
3203
|
-
* For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
|
|
3204
|
-
*/
|
|
3205
|
-
const BSIGMA = /* @__PURE__ */ Uint8Array.from([
|
|
3206
|
-
0,
|
|
3207
|
-
1,
|
|
3208
|
-
2,
|
|
3209
|
-
3,
|
|
3210
|
-
4,
|
|
3211
|
-
5,
|
|
3212
|
-
6,
|
|
3213
|
-
7,
|
|
3214
|
-
8,
|
|
3215
|
-
9,
|
|
3216
|
-
10,
|
|
3217
|
-
11,
|
|
3218
|
-
12,
|
|
3219
|
-
13,
|
|
3220
|
-
14,
|
|
3221
|
-
15,
|
|
3222
|
-
14,
|
|
3223
|
-
10,
|
|
3224
|
-
4,
|
|
3225
|
-
8,
|
|
3226
|
-
9,
|
|
3227
|
-
15,
|
|
3228
|
-
13,
|
|
3229
|
-
6,
|
|
3230
|
-
1,
|
|
3231
|
-
12,
|
|
3232
|
-
0,
|
|
3233
|
-
2,
|
|
3234
|
-
11,
|
|
3235
|
-
7,
|
|
3236
|
-
5,
|
|
3237
|
-
3,
|
|
3238
|
-
11,
|
|
3239
|
-
8,
|
|
3240
|
-
12,
|
|
3241
|
-
0,
|
|
3242
|
-
5,
|
|
3243
|
-
2,
|
|
3244
|
-
15,
|
|
3245
|
-
13,
|
|
3246
|
-
10,
|
|
3247
|
-
14,
|
|
3248
|
-
3,
|
|
3249
|
-
6,
|
|
3250
|
-
7,
|
|
3251
|
-
1,
|
|
3252
|
-
9,
|
|
3253
|
-
4,
|
|
3254
|
-
7,
|
|
3255
|
-
9,
|
|
3256
|
-
3,
|
|
3257
|
-
1,
|
|
3258
|
-
13,
|
|
3259
|
-
12,
|
|
3260
|
-
11,
|
|
3261
|
-
14,
|
|
3262
|
-
2,
|
|
3263
|
-
6,
|
|
3264
|
-
5,
|
|
3265
|
-
10,
|
|
3266
|
-
4,
|
|
3267
|
-
0,
|
|
3268
|
-
15,
|
|
3269
|
-
8,
|
|
3270
|
-
9,
|
|
3271
|
-
0,
|
|
3272
|
-
5,
|
|
3273
|
-
7,
|
|
3274
|
-
2,
|
|
3275
|
-
4,
|
|
3276
|
-
10,
|
|
3277
|
-
15,
|
|
3278
|
-
14,
|
|
3279
|
-
1,
|
|
3280
|
-
11,
|
|
3281
|
-
12,
|
|
3282
|
-
6,
|
|
3283
|
-
8,
|
|
3284
|
-
3,
|
|
3285
|
-
13,
|
|
3286
|
-
2,
|
|
3287
|
-
12,
|
|
3288
|
-
6,
|
|
3289
|
-
10,
|
|
3290
|
-
0,
|
|
3291
|
-
11,
|
|
3292
|
-
8,
|
|
3293
|
-
3,
|
|
3294
|
-
4,
|
|
3295
|
-
13,
|
|
3296
|
-
7,
|
|
3297
|
-
5,
|
|
3298
|
-
15,
|
|
3299
|
-
14,
|
|
3300
|
-
1,
|
|
3301
|
-
9,
|
|
3302
|
-
12,
|
|
3303
|
-
5,
|
|
3304
|
-
1,
|
|
3305
|
-
15,
|
|
3306
|
-
14,
|
|
3307
|
-
13,
|
|
3308
|
-
4,
|
|
3309
|
-
10,
|
|
3310
|
-
0,
|
|
3311
|
-
7,
|
|
3312
|
-
6,
|
|
3313
|
-
3,
|
|
3314
|
-
9,
|
|
3315
|
-
2,
|
|
3316
|
-
8,
|
|
3317
|
-
11,
|
|
3318
|
-
13,
|
|
3319
|
-
11,
|
|
3320
|
-
7,
|
|
3321
|
-
14,
|
|
3322
|
-
12,
|
|
3323
|
-
1,
|
|
3324
|
-
3,
|
|
3325
|
-
9,
|
|
3326
|
-
5,
|
|
3327
|
-
0,
|
|
3328
|
-
15,
|
|
3329
|
-
4,
|
|
3330
|
-
8,
|
|
3331
|
-
6,
|
|
3332
|
-
2,
|
|
3333
|
-
10,
|
|
3334
|
-
6,
|
|
3335
|
-
15,
|
|
3336
|
-
14,
|
|
3337
|
-
9,
|
|
3338
|
-
11,
|
|
3339
|
-
3,
|
|
3340
|
-
0,
|
|
3341
|
-
8,
|
|
3342
|
-
12,
|
|
3343
|
-
2,
|
|
3344
|
-
13,
|
|
3345
|
-
7,
|
|
3346
|
-
1,
|
|
3347
|
-
4,
|
|
3348
|
-
10,
|
|
3349
|
-
5,
|
|
3350
|
-
10,
|
|
3351
|
-
2,
|
|
3352
|
-
8,
|
|
3353
|
-
4,
|
|
3354
|
-
7,
|
|
3355
|
-
6,
|
|
3356
|
-
1,
|
|
3357
|
-
5,
|
|
3358
|
-
15,
|
|
3359
|
-
11,
|
|
3360
|
-
9,
|
|
3361
|
-
14,
|
|
3362
|
-
3,
|
|
3363
|
-
12,
|
|
3364
|
-
13,
|
|
3365
|
-
0,
|
|
3366
|
-
0,
|
|
3367
|
-
1,
|
|
3368
|
-
2,
|
|
3369
|
-
3,
|
|
3370
|
-
4,
|
|
3371
|
-
5,
|
|
3372
|
-
6,
|
|
3373
|
-
7,
|
|
3374
|
-
8,
|
|
3375
|
-
9,
|
|
3376
|
-
10,
|
|
3377
|
-
11,
|
|
3378
|
-
12,
|
|
3379
|
-
13,
|
|
3380
|
-
14,
|
|
3381
|
-
15,
|
|
3382
|
-
14,
|
|
3383
|
-
10,
|
|
3384
|
-
4,
|
|
3385
|
-
8,
|
|
3386
|
-
9,
|
|
3387
|
-
15,
|
|
3388
|
-
13,
|
|
3389
|
-
6,
|
|
3390
|
-
1,
|
|
3391
|
-
12,
|
|
3392
|
-
0,
|
|
3393
|
-
2,
|
|
3394
|
-
11,
|
|
3395
|
-
7,
|
|
3396
|
-
5,
|
|
3397
|
-
3,
|
|
3398
|
-
11,
|
|
3399
|
-
8,
|
|
3400
|
-
12,
|
|
3401
|
-
0,
|
|
3402
|
-
5,
|
|
3403
|
-
2,
|
|
3404
|
-
15,
|
|
3405
|
-
13,
|
|
3406
|
-
10,
|
|
3407
|
-
14,
|
|
3408
|
-
3,
|
|
3409
|
-
6,
|
|
3410
|
-
7,
|
|
3411
|
-
1,
|
|
3412
|
-
9,
|
|
3413
|
-
4,
|
|
3414
|
-
7,
|
|
3415
|
-
9,
|
|
3416
|
-
3,
|
|
3417
|
-
1,
|
|
3418
|
-
13,
|
|
3419
|
-
12,
|
|
3420
|
-
11,
|
|
3421
|
-
14,
|
|
3422
|
-
2,
|
|
3423
|
-
6,
|
|
3424
|
-
5,
|
|
3425
|
-
10,
|
|
3426
|
-
4,
|
|
3427
|
-
0,
|
|
3428
|
-
15,
|
|
3429
|
-
8,
|
|
3430
|
-
9,
|
|
3431
|
-
0,
|
|
3432
|
-
5,
|
|
3433
|
-
7,
|
|
3434
|
-
2,
|
|
3435
|
-
4,
|
|
3436
|
-
10,
|
|
3437
|
-
15,
|
|
3438
|
-
14,
|
|
3439
|
-
1,
|
|
3440
|
-
11,
|
|
3441
|
-
12,
|
|
3442
|
-
6,
|
|
3443
|
-
8,
|
|
3444
|
-
3,
|
|
3445
|
-
13,
|
|
3446
|
-
2,
|
|
3447
|
-
12,
|
|
3448
|
-
6,
|
|
3449
|
-
10,
|
|
3450
|
-
0,
|
|
3451
|
-
11,
|
|
3452
|
-
8,
|
|
3453
|
-
3,
|
|
3454
|
-
4,
|
|
3455
|
-
13,
|
|
3456
|
-
7,
|
|
3457
|
-
5,
|
|
3458
|
-
15,
|
|
3459
|
-
14,
|
|
3460
|
-
1,
|
|
3461
|
-
9
|
|
3462
|
-
]);
|
|
3463
|
-
|
|
3464
|
-
//#endregion
|
|
3465
|
-
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
|
|
3466
|
-
/**
|
|
3467
|
-
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
|
3468
|
-
* @todo re-check https://issues.chromium.org/issues/42212588
|
|
3469
|
-
* @module
|
|
3470
|
-
*/
|
|
3471
|
-
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
3472
|
-
const _32n = /* @__PURE__ */ BigInt(32);
|
|
3473
|
-
function fromBig(n, le = false) {
|
|
3474
|
-
if (le) return {
|
|
3475
|
-
h: Number(n & U32_MASK64),
|
|
3476
|
-
l: Number(n >> _32n & U32_MASK64)
|
|
3477
|
-
};
|
|
3478
|
-
return {
|
|
3479
|
-
h: Number(n >> _32n & U32_MASK64) | 0,
|
|
3480
|
-
l: Number(n & U32_MASK64) | 0
|
|
3481
|
-
};
|
|
3482
|
-
}
|
|
3483
|
-
const rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
3484
|
-
const rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
3485
|
-
const rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
3486
|
-
const rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
3487
|
-
const rotr32H = (_h, l) => l;
|
|
3488
|
-
const rotr32L = (h, _l) => h;
|
|
3489
|
-
function add(Ah, Al, Bh, Bl) {
|
|
3490
|
-
const l = (Al >>> 0) + (Bl >>> 0);
|
|
3491
|
-
return {
|
|
3492
|
-
h: Ah + Bh + (l / 2 ** 32 | 0) | 0,
|
|
3493
|
-
l: l | 0
|
|
3494
|
-
};
|
|
3495
|
-
}
|
|
3496
|
-
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
3497
|
-
const add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
3498
|
-
|
|
3499
|
-
//#endregion
|
|
3500
|
-
//#region ../../node_modules/.bun/@noble+hashes@2.0.1/node_modules/@noble/hashes/blake2.js
|
|
3501
|
-
/**
|
|
3502
|
-
* blake2b (64-bit) & blake2s (8 to 32-bit) hash functions.
|
|
3503
|
-
* b could have been faster, but there is no fast u64 in js, so s is 1.5x faster.
|
|
3504
|
-
* @module
|
|
3505
|
-
*/
|
|
3506
|
-
const B2B_IV = /* @__PURE__ */ Uint32Array.from([
|
|
3507
|
-
4089235720,
|
|
3508
|
-
1779033703,
|
|
3509
|
-
2227873595,
|
|
3510
|
-
3144134277,
|
|
3511
|
-
4271175723,
|
|
3512
|
-
1013904242,
|
|
3513
|
-
1595750129,
|
|
3514
|
-
2773480762,
|
|
3515
|
-
2917565137,
|
|
3516
|
-
1359893119,
|
|
3517
|
-
725511199,
|
|
3518
|
-
2600822924,
|
|
3519
|
-
4215389547,
|
|
3520
|
-
528734635,
|
|
3521
|
-
327033209,
|
|
3522
|
-
1541459225
|
|
3523
|
-
]);
|
|
3524
|
-
const BBUF = /* @__PURE__ */ new Uint32Array(32);
|
|
3525
|
-
function G1b(a, b, c, d, msg, x) {
|
|
3526
|
-
const Xl = msg[x], Xh = msg[x + 1];
|
|
3527
|
-
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
3528
|
-
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
3529
|
-
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
3530
|
-
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
3531
|
-
let ll = add3L(Al, Bl, Xl);
|
|
3532
|
-
Ah = add3H(ll, Ah, Bh, Xh);
|
|
3533
|
-
Al = ll | 0;
|
|
3534
|
-
({Dh, Dl} = {
|
|
3535
|
-
Dh: Dh ^ Ah,
|
|
3536
|
-
Dl: Dl ^ Al
|
|
3537
|
-
});
|
|
3538
|
-
({Dh, Dl} = {
|
|
3539
|
-
Dh: rotr32H(Dh, Dl),
|
|
3540
|
-
Dl: rotr32L(Dh, Dl)
|
|
3541
|
-
});
|
|
3542
|
-
({h: Ch, l: Cl} = add(Ch, Cl, Dh, Dl));
|
|
3543
|
-
({Bh, Bl} = {
|
|
3544
|
-
Bh: Bh ^ Ch,
|
|
3545
|
-
Bl: Bl ^ Cl
|
|
3546
|
-
});
|
|
3547
|
-
({Bh, Bl} = {
|
|
3548
|
-
Bh: rotrSH(Bh, Bl, 24),
|
|
3549
|
-
Bl: rotrSL(Bh, Bl, 24)
|
|
3550
|
-
});
|
|
3551
|
-
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
3552
|
-
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
3553
|
-
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
3554
|
-
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
3555
|
-
}
|
|
3556
|
-
function G2b(a, b, c, d, msg, x) {
|
|
3557
|
-
const Xl = msg[x], Xh = msg[x + 1];
|
|
3558
|
-
let Al = BBUF[2 * a], Ah = BBUF[2 * a + 1];
|
|
3559
|
-
let Bl = BBUF[2 * b], Bh = BBUF[2 * b + 1];
|
|
3560
|
-
let Cl = BBUF[2 * c], Ch = BBUF[2 * c + 1];
|
|
3561
|
-
let Dl = BBUF[2 * d], Dh = BBUF[2 * d + 1];
|
|
3562
|
-
let ll = add3L(Al, Bl, Xl);
|
|
3563
|
-
Ah = add3H(ll, Ah, Bh, Xh);
|
|
3564
|
-
Al = ll | 0;
|
|
3565
|
-
({Dh, Dl} = {
|
|
3566
|
-
Dh: Dh ^ Ah,
|
|
3567
|
-
Dl: Dl ^ Al
|
|
3568
|
-
});
|
|
3569
|
-
({Dh, Dl} = {
|
|
3570
|
-
Dh: rotrSH(Dh, Dl, 16),
|
|
3571
|
-
Dl: rotrSL(Dh, Dl, 16)
|
|
3572
|
-
});
|
|
3573
|
-
({h: Ch, l: Cl} = add(Ch, Cl, Dh, Dl));
|
|
3574
|
-
({Bh, Bl} = {
|
|
3575
|
-
Bh: Bh ^ Ch,
|
|
3576
|
-
Bl: Bl ^ Cl
|
|
3577
|
-
});
|
|
3578
|
-
({Bh, Bl} = {
|
|
3579
|
-
Bh: rotrBH(Bh, Bl, 63),
|
|
3580
|
-
Bl: rotrBL(Bh, Bl, 63)
|
|
3581
|
-
});
|
|
3582
|
-
BBUF[2 * a] = Al, BBUF[2 * a + 1] = Ah;
|
|
3583
|
-
BBUF[2 * b] = Bl, BBUF[2 * b + 1] = Bh;
|
|
3584
|
-
BBUF[2 * c] = Cl, BBUF[2 * c + 1] = Ch;
|
|
3585
|
-
BBUF[2 * d] = Dl, BBUF[2 * d + 1] = Dh;
|
|
3586
|
-
}
|
|
3587
|
-
function checkBlake2Opts(outputLen, opts = {}, keyLen, saltLen, persLen) {
|
|
3588
|
-
anumber(keyLen);
|
|
3589
|
-
if (outputLen < 0 || outputLen > keyLen) throw new Error("outputLen bigger than keyLen");
|
|
3590
|
-
const { key, salt, personalization } = opts;
|
|
3591
|
-
if (key !== void 0 && (key.length < 1 || key.length > keyLen)) throw new Error("\"key\" expected to be undefined or of length=1.." + keyLen);
|
|
3592
|
-
if (salt !== void 0) abytes(salt, saltLen, "salt");
|
|
3593
|
-
if (personalization !== void 0) abytes(personalization, persLen, "personalization");
|
|
3594
|
-
}
|
|
3595
|
-
/** Internal base class for BLAKE2. */
|
|
3596
|
-
var _BLAKE2 = class {
|
|
3597
|
-
buffer;
|
|
3598
|
-
buffer32;
|
|
3599
|
-
finished = false;
|
|
3600
|
-
destroyed = false;
|
|
3601
|
-
length = 0;
|
|
3602
|
-
pos = 0;
|
|
3603
|
-
blockLen;
|
|
3604
|
-
outputLen;
|
|
3605
|
-
constructor(blockLen, outputLen) {
|
|
3606
|
-
anumber(blockLen);
|
|
3607
|
-
anumber(outputLen);
|
|
3608
|
-
this.blockLen = blockLen;
|
|
3609
|
-
this.outputLen = outputLen;
|
|
3610
|
-
this.buffer = new Uint8Array(blockLen);
|
|
3611
|
-
this.buffer32 = u32(this.buffer);
|
|
3612
|
-
}
|
|
3613
|
-
update(data) {
|
|
3614
|
-
aexists(this);
|
|
3615
|
-
abytes(data);
|
|
3616
|
-
const { blockLen, buffer, buffer32 } = this;
|
|
3617
|
-
const len = data.length;
|
|
3618
|
-
const offset = data.byteOffset;
|
|
3619
|
-
const buf = data.buffer;
|
|
3620
|
-
for (let pos = 0; pos < len;) {
|
|
3621
|
-
if (this.pos === blockLen) {
|
|
3622
|
-
swap32IfBE(buffer32);
|
|
3623
|
-
this.compress(buffer32, 0, false);
|
|
3624
|
-
swap32IfBE(buffer32);
|
|
3625
|
-
this.pos = 0;
|
|
3626
|
-
}
|
|
3627
|
-
const take = Math.min(blockLen - this.pos, len - pos);
|
|
3628
|
-
const dataOffset = offset + pos;
|
|
3629
|
-
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
3630
|
-
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
3631
|
-
swap32IfBE(data32);
|
|
3632
|
-
for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
|
|
3633
|
-
this.length += blockLen;
|
|
3634
|
-
this.compress(data32, pos32, false);
|
|
3635
|
-
}
|
|
3636
|
-
swap32IfBE(data32);
|
|
3637
|
-
continue;
|
|
3638
|
-
}
|
|
3639
|
-
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
3640
|
-
this.pos += take;
|
|
3641
|
-
this.length += take;
|
|
3642
|
-
pos += take;
|
|
3643
|
-
}
|
|
3644
|
-
return this;
|
|
3645
|
-
}
|
|
3646
|
-
digestInto(out) {
|
|
3647
|
-
aexists(this);
|
|
3648
|
-
aoutput(out, this);
|
|
3649
|
-
const { pos, buffer32 } = this;
|
|
3650
|
-
this.finished = true;
|
|
3651
|
-
clean(this.buffer.subarray(pos));
|
|
3652
|
-
swap32IfBE(buffer32);
|
|
3653
|
-
this.compress(buffer32, 0, true);
|
|
3654
|
-
swap32IfBE(buffer32);
|
|
3655
|
-
const out32 = u32(out);
|
|
3656
|
-
this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
|
|
3657
|
-
}
|
|
3658
|
-
digest() {
|
|
3659
|
-
const { buffer, outputLen } = this;
|
|
3660
|
-
this.digestInto(buffer);
|
|
3661
|
-
const res = buffer.slice(0, outputLen);
|
|
3662
|
-
this.destroy();
|
|
3663
|
-
return res;
|
|
3664
|
-
}
|
|
3665
|
-
_cloneInto(to) {
|
|
3666
|
-
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
|
3667
|
-
to ||= new this.constructor({ dkLen: outputLen });
|
|
3668
|
-
to.set(...this.get());
|
|
3669
|
-
to.buffer.set(buffer);
|
|
3670
|
-
to.destroyed = destroyed;
|
|
3671
|
-
to.finished = finished;
|
|
3672
|
-
to.length = length;
|
|
3673
|
-
to.pos = pos;
|
|
3674
|
-
to.outputLen = outputLen;
|
|
3675
|
-
return to;
|
|
3676
|
-
}
|
|
3677
|
-
clone() {
|
|
3678
|
-
return this._cloneInto();
|
|
3679
|
-
}
|
|
3680
|
-
};
|
|
3681
|
-
/** Internal blake2b hash class. */
|
|
3682
|
-
var _BLAKE2b = class extends _BLAKE2 {
|
|
3683
|
-
v0l = B2B_IV[0] | 0;
|
|
3684
|
-
v0h = B2B_IV[1] | 0;
|
|
3685
|
-
v1l = B2B_IV[2] | 0;
|
|
3686
|
-
v1h = B2B_IV[3] | 0;
|
|
3687
|
-
v2l = B2B_IV[4] | 0;
|
|
3688
|
-
v2h = B2B_IV[5] | 0;
|
|
3689
|
-
v3l = B2B_IV[6] | 0;
|
|
3690
|
-
v3h = B2B_IV[7] | 0;
|
|
3691
|
-
v4l = B2B_IV[8] | 0;
|
|
3692
|
-
v4h = B2B_IV[9] | 0;
|
|
3693
|
-
v5l = B2B_IV[10] | 0;
|
|
3694
|
-
v5h = B2B_IV[11] | 0;
|
|
3695
|
-
v6l = B2B_IV[12] | 0;
|
|
3696
|
-
v6h = B2B_IV[13] | 0;
|
|
3697
|
-
v7l = B2B_IV[14] | 0;
|
|
3698
|
-
v7h = B2B_IV[15] | 0;
|
|
3699
|
-
constructor(opts = {}) {
|
|
3700
|
-
const olen = opts.dkLen === void 0 ? 64 : opts.dkLen;
|
|
3701
|
-
super(128, olen);
|
|
3702
|
-
checkBlake2Opts(olen, opts, 64, 16, 16);
|
|
3703
|
-
let { key, personalization, salt } = opts;
|
|
3704
|
-
let keyLength = 0;
|
|
3705
|
-
if (key !== void 0) {
|
|
3706
|
-
abytes(key, void 0, "key");
|
|
3707
|
-
keyLength = key.length;
|
|
3708
|
-
}
|
|
3709
|
-
this.v0l ^= this.outputLen | keyLength << 8 | 16842752;
|
|
3710
|
-
if (salt !== void 0) {
|
|
3711
|
-
abytes(salt, void 0, "salt");
|
|
3712
|
-
const slt = u32(salt);
|
|
3713
|
-
this.v4l ^= swap8IfBE(slt[0]);
|
|
3714
|
-
this.v4h ^= swap8IfBE(slt[1]);
|
|
3715
|
-
this.v5l ^= swap8IfBE(slt[2]);
|
|
3716
|
-
this.v5h ^= swap8IfBE(slt[3]);
|
|
3717
|
-
}
|
|
3718
|
-
if (personalization !== void 0) {
|
|
3719
|
-
abytes(personalization, void 0, "personalization");
|
|
3720
|
-
const pers = u32(personalization);
|
|
3721
|
-
this.v6l ^= swap8IfBE(pers[0]);
|
|
3722
|
-
this.v6h ^= swap8IfBE(pers[1]);
|
|
3723
|
-
this.v7l ^= swap8IfBE(pers[2]);
|
|
3724
|
-
this.v7h ^= swap8IfBE(pers[3]);
|
|
3725
|
-
}
|
|
3726
|
-
if (key !== void 0) {
|
|
3727
|
-
const tmp = new Uint8Array(this.blockLen);
|
|
3728
|
-
tmp.set(key);
|
|
3729
|
-
this.update(tmp);
|
|
3730
|
-
}
|
|
3731
|
-
}
|
|
3732
|
-
get() {
|
|
3733
|
-
let { v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h } = this;
|
|
3734
|
-
return [
|
|
3735
|
-
v0l,
|
|
3736
|
-
v0h,
|
|
3737
|
-
v1l,
|
|
3738
|
-
v1h,
|
|
3739
|
-
v2l,
|
|
3740
|
-
v2h,
|
|
3741
|
-
v3l,
|
|
3742
|
-
v3h,
|
|
3743
|
-
v4l,
|
|
3744
|
-
v4h,
|
|
3745
|
-
v5l,
|
|
3746
|
-
v5h,
|
|
3747
|
-
v6l,
|
|
3748
|
-
v6h,
|
|
3749
|
-
v7l,
|
|
3750
|
-
v7h
|
|
3751
|
-
];
|
|
3752
|
-
}
|
|
3753
|
-
set(v0l, v0h, v1l, v1h, v2l, v2h, v3l, v3h, v4l, v4h, v5l, v5h, v6l, v6h, v7l, v7h) {
|
|
3754
|
-
this.v0l = v0l | 0;
|
|
3755
|
-
this.v0h = v0h | 0;
|
|
3756
|
-
this.v1l = v1l | 0;
|
|
3757
|
-
this.v1h = v1h | 0;
|
|
3758
|
-
this.v2l = v2l | 0;
|
|
3759
|
-
this.v2h = v2h | 0;
|
|
3760
|
-
this.v3l = v3l | 0;
|
|
3761
|
-
this.v3h = v3h | 0;
|
|
3762
|
-
this.v4l = v4l | 0;
|
|
3763
|
-
this.v4h = v4h | 0;
|
|
3764
|
-
this.v5l = v5l | 0;
|
|
3765
|
-
this.v5h = v5h | 0;
|
|
3766
|
-
this.v6l = v6l | 0;
|
|
3767
|
-
this.v6h = v6h | 0;
|
|
3768
|
-
this.v7l = v7l | 0;
|
|
3769
|
-
this.v7h = v7h | 0;
|
|
3770
|
-
}
|
|
3771
|
-
compress(msg, offset, isLast) {
|
|
3772
|
-
this.get().forEach((v, i) => BBUF[i] = v);
|
|
3773
|
-
BBUF.set(B2B_IV, 16);
|
|
3774
|
-
let { h, l } = fromBig(BigInt(this.length));
|
|
3775
|
-
BBUF[24] = B2B_IV[8] ^ l;
|
|
3776
|
-
BBUF[25] = B2B_IV[9] ^ h;
|
|
3777
|
-
if (isLast) {
|
|
3778
|
-
BBUF[28] = ~BBUF[28];
|
|
3779
|
-
BBUF[29] = ~BBUF[29];
|
|
3780
|
-
}
|
|
3781
|
-
let j = 0;
|
|
3782
|
-
const s = BSIGMA;
|
|
3783
|
-
for (let i = 0; i < 12; i++) {
|
|
3784
|
-
G1b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
3785
|
-
G2b(0, 4, 8, 12, msg, offset + 2 * s[j++]);
|
|
3786
|
-
G1b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
3787
|
-
G2b(1, 5, 9, 13, msg, offset + 2 * s[j++]);
|
|
3788
|
-
G1b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
|
3789
|
-
G2b(2, 6, 10, 14, msg, offset + 2 * s[j++]);
|
|
3790
|
-
G1b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
|
3791
|
-
G2b(3, 7, 11, 15, msg, offset + 2 * s[j++]);
|
|
3792
|
-
G1b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
|
3793
|
-
G2b(0, 5, 10, 15, msg, offset + 2 * s[j++]);
|
|
3794
|
-
G1b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
|
3795
|
-
G2b(1, 6, 11, 12, msg, offset + 2 * s[j++]);
|
|
3796
|
-
G1b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
|
3797
|
-
G2b(2, 7, 8, 13, msg, offset + 2 * s[j++]);
|
|
3798
|
-
G1b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
|
3799
|
-
G2b(3, 4, 9, 14, msg, offset + 2 * s[j++]);
|
|
3800
|
-
}
|
|
3801
|
-
this.v0l ^= BBUF[0] ^ BBUF[16];
|
|
3802
|
-
this.v0h ^= BBUF[1] ^ BBUF[17];
|
|
3803
|
-
this.v1l ^= BBUF[2] ^ BBUF[18];
|
|
3804
|
-
this.v1h ^= BBUF[3] ^ BBUF[19];
|
|
3805
|
-
this.v2l ^= BBUF[4] ^ BBUF[20];
|
|
3806
|
-
this.v2h ^= BBUF[5] ^ BBUF[21];
|
|
3807
|
-
this.v3l ^= BBUF[6] ^ BBUF[22];
|
|
3808
|
-
this.v3h ^= BBUF[7] ^ BBUF[23];
|
|
3809
|
-
this.v4l ^= BBUF[8] ^ BBUF[24];
|
|
3810
|
-
this.v4h ^= BBUF[9] ^ BBUF[25];
|
|
3811
|
-
this.v5l ^= BBUF[10] ^ BBUF[26];
|
|
3812
|
-
this.v5h ^= BBUF[11] ^ BBUF[27];
|
|
3813
|
-
this.v6l ^= BBUF[12] ^ BBUF[28];
|
|
3814
|
-
this.v6h ^= BBUF[13] ^ BBUF[29];
|
|
3815
|
-
this.v7l ^= BBUF[14] ^ BBUF[30];
|
|
3816
|
-
this.v7h ^= BBUF[15] ^ BBUF[31];
|
|
3817
|
-
clean(BBUF);
|
|
3818
|
-
}
|
|
3819
|
-
destroy() {
|
|
3820
|
-
this.destroyed = true;
|
|
3821
|
-
clean(this.buffer32);
|
|
3822
|
-
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
3823
|
-
}
|
|
3824
|
-
};
|
|
3825
|
-
/**
|
|
3826
|
-
* Blake2b hash function. 64-bit. 1.5x slower than blake2s in JS.
|
|
3827
|
-
* @param msg - message that would be hashed
|
|
3828
|
-
* @param opts - dkLen output length, key for MAC mode, salt, personalization
|
|
3829
|
-
*/
|
|
3830
|
-
const blake2b = /* @__PURE__ */ createHasher((opts) => new _BLAKE2b(opts));
|
|
3831
|
-
|
|
3832
3125
|
//#endregion
|
|
3833
3126
|
//#region src/sr25519/sr25519-public-key.ts
|
|
3834
3127
|
/**
|
|
@@ -4009,7 +3302,7 @@ var Sr25519PrivateKey = class Sr25519PrivateKey {
|
|
|
4009
3302
|
* @returns A new Sr25519 private key
|
|
4010
3303
|
*/
|
|
4011
3304
|
static deriveFromKeyMaterial(keyMaterial) {
|
|
4012
|
-
return new Sr25519PrivateKey(blake2b(keyMaterial, { dkLen: SR25519_PRIVATE_KEY_SIZE }));
|
|
3305
|
+
return new Sr25519PrivateKey((0, __noble_hashes_blake2b.blake2b)(keyMaterial, { dkLen: SR25519_PRIVATE_KEY_SIZE }));
|
|
4013
3306
|
}
|
|
4014
3307
|
/**
|
|
4015
3308
|
* Generate a keypair and return both private and public keys.
|