@wishknish/knishio-client-ts 0.9.5 → 0.9.6
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 +312 -231
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -28
- package/dist/index.d.ts +32 -28
- package/dist/index.iife.js +831 -469
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +312 -231
- package/dist/index.js.map +1 -1
- package/package.json +18 -21
- package/src/KnishIOClient.ts +37 -8
- package/src/core/AtomMeta.ts +12 -4
- package/src/core/Molecule.ts +61 -0
- package/src/core/Wallet.ts +7 -5
- package/src/index.ts +1 -1
- package/src/libraries/GraphQLClient.ts +21 -7
- package/src/libraries/UrqlClientWrapper.ts +8 -3
- package/src/libraries/crypto.ts +4 -6
- package/src/mutation/MutationReplenishToken.ts +28 -0
- package/src/schemas/index.ts +1 -1
- package/src/types/assertions.ts +2 -2
- package/src/validation/schemas.ts +6 -6
package/dist/index.iife.js
CHANGED
|
@@ -57,8 +57,8 @@ var KnishIO = (function (exports) {
|
|
|
57
57
|
var __esm = (fn, res) => function __init() {
|
|
58
58
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
59
59
|
};
|
|
60
|
-
var __commonJS = (cb,
|
|
61
|
-
return
|
|
60
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
61
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
62
62
|
};
|
|
63
63
|
var __export = (target, all) => {
|
|
64
64
|
for (var name2 in all)
|
|
@@ -72,15 +72,15 @@ var KnishIO = (function (exports) {
|
|
|
72
72
|
}
|
|
73
73
|
return to;
|
|
74
74
|
};
|
|
75
|
-
var __toESM = (
|
|
75
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
76
76
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
77
77
|
// file that has been converted to a CommonJS file using a Babel-
|
|
78
78
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
79
79
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
80
|
-
__defProp(target, "default", { value:
|
|
81
|
-
|
|
80
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
81
|
+
mod
|
|
82
82
|
));
|
|
83
|
-
var __toCommonJS = (
|
|
83
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
84
84
|
|
|
85
85
|
// src/exception/BaseException.ts
|
|
86
86
|
exports.BaseException = void 0;
|
|
@@ -39975,11 +39975,9 @@ ${operationTypes.join("\n")}
|
|
|
39975
39975
|
const base17Hash = convertToBase17(molecularHash);
|
|
39976
39976
|
const enumerated = enumerateMolecularHash(base17Hash);
|
|
39977
39977
|
const normalized = normalizeMolecularHash(enumerated);
|
|
39978
|
-
|
|
39978
|
+
const ots = otsFragments;
|
|
39979
39979
|
if (ots.length !== 2048) {
|
|
39980
|
-
|
|
39981
|
-
return false;
|
|
39982
|
-
}
|
|
39980
|
+
return false;
|
|
39983
39981
|
}
|
|
39984
39982
|
const otsChunks = [];
|
|
39985
39983
|
for (let i4 = 0; i4 < ots.length; i4 += CRYPTO_CONSTANTS.KEY_FRAGMENT_SIZE) {
|
|
@@ -40482,6 +40480,123 @@ ${operationTypes.join("\n")}
|
|
|
40482
40480
|
});
|
|
40483
40481
|
}
|
|
40484
40482
|
};
|
|
40483
|
+
|
|
40484
|
+
// src/libraries/array.ts
|
|
40485
|
+
function deepCloning(o3, h3) {
|
|
40486
|
+
let i4;
|
|
40487
|
+
let r3;
|
|
40488
|
+
let x2;
|
|
40489
|
+
const t3 = [Array, Date, Number, String, Boolean];
|
|
40490
|
+
const s2 = Object.prototype.toString;
|
|
40491
|
+
h3 = h3 || [];
|
|
40492
|
+
for (i4 = 0; i4 < h3.length; i4 += 2) {
|
|
40493
|
+
if (o3 === h3[i4]) {
|
|
40494
|
+
return h3[i4 + 1];
|
|
40495
|
+
}
|
|
40496
|
+
}
|
|
40497
|
+
if (!r3 && o3 && typeof o3 === "object") {
|
|
40498
|
+
r3 = {};
|
|
40499
|
+
for (i4 = 0; i4 < t3.length; i4++) {
|
|
40500
|
+
if (s2.call(o3) === s2.call(x2 = new t3[i4](o3))) {
|
|
40501
|
+
r3 = i4 ? x2 : [];
|
|
40502
|
+
}
|
|
40503
|
+
}
|
|
40504
|
+
h3.push(o3, r3);
|
|
40505
|
+
for (i4 in o3) {
|
|
40506
|
+
if (Object.prototype.hasOwnProperty.call(o3, i4)) {
|
|
40507
|
+
r3[i4] = deepCloning(o3[i4], h3);
|
|
40508
|
+
}
|
|
40509
|
+
}
|
|
40510
|
+
}
|
|
40511
|
+
return r3 || o3;
|
|
40512
|
+
}
|
|
40513
|
+
function chunkArray(arr, size) {
|
|
40514
|
+
const chunks = [];
|
|
40515
|
+
for (let i4 = 0; i4 < arr.length; i4 += size) {
|
|
40516
|
+
chunks.push(arr.slice(i4, i4 + size));
|
|
40517
|
+
}
|
|
40518
|
+
return chunks;
|
|
40519
|
+
}
|
|
40520
|
+
function diff(...arrays) {
|
|
40521
|
+
return [].concat(...arrays.map((arr, i4) => {
|
|
40522
|
+
const others = arrays.slice(0);
|
|
40523
|
+
others.splice(i4, 1);
|
|
40524
|
+
const unique = [...new Set([].concat(...others))];
|
|
40525
|
+
return arr.filter((item) => !unique.includes(item));
|
|
40526
|
+
}));
|
|
40527
|
+
}
|
|
40528
|
+
function intersect(...arrays) {
|
|
40529
|
+
if (arrays.length === 0) return [];
|
|
40530
|
+
if (arrays.length === 1) return arrays[0];
|
|
40531
|
+
return arrays.reduce(
|
|
40532
|
+
(first, second) => first.filter((item) => second.includes(item))
|
|
40533
|
+
);
|
|
40534
|
+
}
|
|
40535
|
+
|
|
40536
|
+
// src/core/PolicyMeta.ts
|
|
40537
|
+
var PolicyMeta = class _PolicyMeta {
|
|
40538
|
+
policy;
|
|
40539
|
+
/**
|
|
40540
|
+
* Create new PolicyMeta instance
|
|
40541
|
+
* Matches JavaScript SDK constructor signature exactly
|
|
40542
|
+
*/
|
|
40543
|
+
constructor(policy = {}, metaKeys = []) {
|
|
40544
|
+
this.policy = _PolicyMeta.normalizePolicy(policy);
|
|
40545
|
+
this.fillDefault(metaKeys);
|
|
40546
|
+
}
|
|
40547
|
+
/**
|
|
40548
|
+
* Normalize policy object structure
|
|
40549
|
+
* Matches JavaScript SDK normalizePolicy method exactly
|
|
40550
|
+
*/
|
|
40551
|
+
static normalizePolicy(policy = {}) {
|
|
40552
|
+
const policyMeta = {};
|
|
40553
|
+
for (const [policyKey, value2] of Object.entries(policy)) {
|
|
40554
|
+
if (value2 !== null && ["read", "write"].includes(policyKey)) {
|
|
40555
|
+
policyMeta[policyKey] = {};
|
|
40556
|
+
for (const [key, content] of Object.entries(value2)) {
|
|
40557
|
+
policyMeta[policyKey][key] = content;
|
|
40558
|
+
}
|
|
40559
|
+
}
|
|
40560
|
+
}
|
|
40561
|
+
return policyMeta;
|
|
40562
|
+
}
|
|
40563
|
+
/**
|
|
40564
|
+
* Fill default policy values for metadata keys
|
|
40565
|
+
* Matches JavaScript SDK fillDefault method exactly
|
|
40566
|
+
*/
|
|
40567
|
+
fillDefault(metaKeys = []) {
|
|
40568
|
+
const readPolicy = Array.from(this.policy).filter((item) => item.action === "read");
|
|
40569
|
+
const writePolicy = Array.from(this.policy).filter((item) => item.action === "write");
|
|
40570
|
+
for (const [type2, value2] of Object.entries({
|
|
40571
|
+
read: readPolicy,
|
|
40572
|
+
write: writePolicy
|
|
40573
|
+
})) {
|
|
40574
|
+
const policyKey = value2.map((item) => item.key);
|
|
40575
|
+
if (!this.policy[type2]) {
|
|
40576
|
+
this.policy[type2] = {};
|
|
40577
|
+
}
|
|
40578
|
+
for (const key of diff(metaKeys, policyKey)) {
|
|
40579
|
+
if (!this.policy[type2][key]) {
|
|
40580
|
+
this.policy[type2][key] = type2 === "write" && !["characters", "pubkey"].includes(key) ? ["self"] : ["all"];
|
|
40581
|
+
}
|
|
40582
|
+
}
|
|
40583
|
+
}
|
|
40584
|
+
}
|
|
40585
|
+
/**
|
|
40586
|
+
* Get the policy object
|
|
40587
|
+
* Matches JavaScript SDK get method exactly
|
|
40588
|
+
*/
|
|
40589
|
+
get() {
|
|
40590
|
+
return this.policy;
|
|
40591
|
+
}
|
|
40592
|
+
/**
|
|
40593
|
+
* Convert policy to JSON string
|
|
40594
|
+
* Matches JavaScript SDK toJson method exactly
|
|
40595
|
+
*/
|
|
40596
|
+
toJson() {
|
|
40597
|
+
return JSON.stringify(this.get());
|
|
40598
|
+
}
|
|
40599
|
+
};
|
|
40485
40600
|
var AtomMeta = class _AtomMeta {
|
|
40486
40601
|
meta;
|
|
40487
40602
|
/**
|
|
@@ -40577,8 +40692,9 @@ ${operationTypes.join("\n")}
|
|
|
40577
40692
|
* @return This instance for chaining
|
|
40578
40693
|
*/
|
|
40579
40694
|
addPolicy(policy) {
|
|
40695
|
+
const policyMeta = new PolicyMeta(policy, Object.keys(this.meta));
|
|
40580
40696
|
this.merge({
|
|
40581
|
-
policy:
|
|
40697
|
+
policy: policyMeta.toJson()
|
|
40582
40698
|
});
|
|
40583
40699
|
return this;
|
|
40584
40700
|
}
|
|
@@ -41214,8 +41330,89 @@ ${operationTypes.join("\n")}
|
|
|
41214
41330
|
return value2;
|
|
41215
41331
|
}
|
|
41216
41332
|
|
|
41333
|
+
// src/core/TokenUnit.ts
|
|
41334
|
+
var TokenUnit = class _TokenUnit {
|
|
41335
|
+
id;
|
|
41336
|
+
name;
|
|
41337
|
+
metas;
|
|
41338
|
+
/**
|
|
41339
|
+
* Create new TokenUnit instance
|
|
41340
|
+
* Matches JavaScript SDK constructor signature exactly
|
|
41341
|
+
*/
|
|
41342
|
+
constructor(id, name2, metas) {
|
|
41343
|
+
this.id = id;
|
|
41344
|
+
this.name = name2;
|
|
41345
|
+
this.metas = metas || {};
|
|
41346
|
+
}
|
|
41347
|
+
/**
|
|
41348
|
+
* Create TokenUnit from GraphQL response data
|
|
41349
|
+
* Matches JavaScript SDK createFromGraphQL method exactly
|
|
41350
|
+
*/
|
|
41351
|
+
static createFromGraphQL(data) {
|
|
41352
|
+
let metas = data.metas || {};
|
|
41353
|
+
if (Array.isArray(metas) && metas.length) {
|
|
41354
|
+
try {
|
|
41355
|
+
metas = JSON.parse(metas);
|
|
41356
|
+
if (!metas) {
|
|
41357
|
+
metas = {};
|
|
41358
|
+
}
|
|
41359
|
+
} catch (error62) {
|
|
41360
|
+
metas = {};
|
|
41361
|
+
}
|
|
41362
|
+
}
|
|
41363
|
+
return new _TokenUnit(
|
|
41364
|
+
data.id,
|
|
41365
|
+
data.name,
|
|
41366
|
+
metas
|
|
41367
|
+
);
|
|
41368
|
+
}
|
|
41369
|
+
/**
|
|
41370
|
+
* Create TokenUnit from database array data
|
|
41371
|
+
* Matches JavaScript SDK createFromDB method exactly
|
|
41372
|
+
*/
|
|
41373
|
+
static createFromDB(data) {
|
|
41374
|
+
return new _TokenUnit(
|
|
41375
|
+
data[0],
|
|
41376
|
+
data[1],
|
|
41377
|
+
data.length > 2 ? data[2] : {}
|
|
41378
|
+
);
|
|
41379
|
+
}
|
|
41380
|
+
/**
|
|
41381
|
+
* Get fragment zone from metadata
|
|
41382
|
+
* Matches JavaScript SDK getFragmentZone method exactly
|
|
41383
|
+
*/
|
|
41384
|
+
getFragmentZone() {
|
|
41385
|
+
return this.metas.fragmentZone || null;
|
|
41386
|
+
}
|
|
41387
|
+
/**
|
|
41388
|
+
* Get fused token units from metadata
|
|
41389
|
+
* Matches JavaScript SDK getFusedTokenUnits method exactly
|
|
41390
|
+
*/
|
|
41391
|
+
getFusedTokenUnits() {
|
|
41392
|
+
return this.metas.fusedTokenUnits || null;
|
|
41393
|
+
}
|
|
41394
|
+
/**
|
|
41395
|
+
* Convert to data array format
|
|
41396
|
+
* Matches JavaScript SDK toData method exactly
|
|
41397
|
+
*/
|
|
41398
|
+
toData() {
|
|
41399
|
+
return [this.id, this.name, this.metas];
|
|
41400
|
+
}
|
|
41401
|
+
/**
|
|
41402
|
+
* Convert to GraphQL response format
|
|
41403
|
+
* Matches JavaScript SDK toGraphQLResponse method exactly
|
|
41404
|
+
*/
|
|
41405
|
+
toGraphQLResponse() {
|
|
41406
|
+
return {
|
|
41407
|
+
id: this.id,
|
|
41408
|
+
name: this.name,
|
|
41409
|
+
metas: JSON.stringify(this.metas)
|
|
41410
|
+
};
|
|
41411
|
+
}
|
|
41412
|
+
};
|
|
41413
|
+
|
|
41217
41414
|
// node_modules/@noble/hashes/_u64.js
|
|
41218
|
-
var U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
41415
|
+
var U32_MASK64 = /* @__PURE__ */ (() => BigInt(2 ** 32 - 1))();
|
|
41219
41416
|
var _32n = /* @__PURE__ */ BigInt(32);
|
|
41220
41417
|
function fromBig(n3, le = false) {
|
|
41221
41418
|
if (le)
|
|
@@ -41232,44 +41429,60 @@ ${operationTypes.join("\n")}
|
|
|
41232
41429
|
}
|
|
41233
41430
|
return [Ah, Al];
|
|
41234
41431
|
}
|
|
41235
|
-
var rotlSH = (h3, l3, s2) => h3 << s2 | l3 >>> 32 - s2;
|
|
41236
|
-
var rotlSL = (h3, l3, s2) => l3 << s2 | h3 >>> 32 - s2;
|
|
41237
|
-
var rotlBH = (h3, l3, s2) => l3 << s2 - 32 | h3 >>> 64 - s2;
|
|
41238
|
-
var rotlBL = (h3, l3, s2) => h3 << s2 - 32 | l3 >>> 64 - s2;
|
|
41239
41432
|
|
|
41240
41433
|
// node_modules/@noble/hashes/utils.js
|
|
41241
41434
|
function isBytes(a3) {
|
|
41242
|
-
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array";
|
|
41435
|
+
return a3 instanceof Uint8Array || ArrayBuffer.isView(a3) && a3.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a3 && a3.BYTES_PER_ELEMENT === 1;
|
|
41243
41436
|
}
|
|
41437
|
+
var atitle = (title) => title ? `"${title}" ` : "";
|
|
41244
41438
|
function anumber(n3, title = "") {
|
|
41245
|
-
if (
|
|
41246
|
-
|
|
41247
|
-
|
|
41248
|
-
|
|
41439
|
+
if (typeof n3 !== "number")
|
|
41440
|
+
throw new TypeError(atitle(title) + "expected number, got " + typeof n3);
|
|
41441
|
+
if (!Number.isSafeInteger(n3) || n3 < 0)
|
|
41442
|
+
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n3);
|
|
41443
|
+
return n3;
|
|
41249
41444
|
}
|
|
41250
|
-
function
|
|
41251
|
-
|
|
41252
|
-
|
|
41253
|
-
const needsLen = length !== void 0;
|
|
41254
|
-
if (!bytes || needsLen && len !== length) {
|
|
41255
|
-
const prefix = title && `"${title}" `;
|
|
41256
|
-
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
41257
|
-
const got = bytes ? `length=${len}` : `type=${typeof value2}`;
|
|
41258
|
-
throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
|
|
41259
|
-
}
|
|
41445
|
+
function abool(value2, title = "") {
|
|
41446
|
+
if (typeof value2 !== "boolean")
|
|
41447
|
+
throw new TypeError(atitle(title) + "expected boolean, got type=" + typeof value2);
|
|
41260
41448
|
return value2;
|
|
41261
41449
|
}
|
|
41450
|
+
function abytes(value2, length, title = "") {
|
|
41451
|
+
if (isBytes(value2) && (length === void 0 || value2.length === length))
|
|
41452
|
+
return value2;
|
|
41453
|
+
if (length !== void 0)
|
|
41454
|
+
anumber(length, "length");
|
|
41455
|
+
const bytes = isBytes(value2);
|
|
41456
|
+
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
41457
|
+
const got = bytes ? `length=${value2.length}` : `type=${typeof value2}`;
|
|
41458
|
+
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
41459
|
+
if (!bytes)
|
|
41460
|
+
throw new TypeError(message);
|
|
41461
|
+
throw new RangeError(message);
|
|
41462
|
+
}
|
|
41463
|
+
var aobject = (value2, label) => {
|
|
41464
|
+
if (value2 === null || typeof value2 !== "object" || Array.isArray(value2))
|
|
41465
|
+
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value2);
|
|
41466
|
+
};
|
|
41467
|
+
var aopts = (value2, label) => {
|
|
41468
|
+
aobject(value2, label);
|
|
41469
|
+
const proto = Object.getPrototypeOf(value2);
|
|
41470
|
+
if (proto !== Object.prototype && proto !== null)
|
|
41471
|
+
throw new TypeError(`"${label}" expected plain object`);
|
|
41472
|
+
if (Object.hasOwn(value2, "__proto__"))
|
|
41473
|
+
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
41474
|
+
};
|
|
41262
41475
|
function aexists(instance, checkFinished = true) {
|
|
41263
41476
|
if (instance.destroyed)
|
|
41264
|
-
throw new Error("
|
|
41477
|
+
throw new Error("hash was destroyed");
|
|
41265
41478
|
if (checkFinished && instance.finished)
|
|
41266
|
-
throw new Error("
|
|
41479
|
+
throw new Error("digest() was already called");
|
|
41267
41480
|
}
|
|
41268
41481
|
function aoutput(out, instance) {
|
|
41269
|
-
abytes(out, void 0, "
|
|
41482
|
+
abytes(out, void 0, "output");
|
|
41270
41483
|
const min = instance.outputLen;
|
|
41271
|
-
if (out.length
|
|
41272
|
-
throw new
|
|
41484
|
+
if (!(out.length >= min)) {
|
|
41485
|
+
throw new RangeError('"output" expected length >= ' + min);
|
|
41273
41486
|
}
|
|
41274
41487
|
}
|
|
41275
41488
|
function u32(arr) {
|
|
@@ -41291,22 +41504,38 @@ ${operationTypes.join("\n")}
|
|
|
41291
41504
|
return arr;
|
|
41292
41505
|
}
|
|
41293
41506
|
var swap32IfBE = isLE ? (u4) => u4 : byteSwap32;
|
|
41507
|
+
function checkOpts(defaults, opts2, title = "opts") {
|
|
41508
|
+
aopts(defaults, "defaults");
|
|
41509
|
+
if (opts2 !== void 0)
|
|
41510
|
+
aopts(opts2, title);
|
|
41511
|
+
const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts2);
|
|
41512
|
+
return merged;
|
|
41513
|
+
}
|
|
41294
41514
|
function createHasher(hashCons, info = {}) {
|
|
41515
|
+
if (typeof hashCons !== "function")
|
|
41516
|
+
throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
|
|
41517
|
+
info = checkOpts({}, info, "info");
|
|
41295
41518
|
const hashC = (msg, opts2) => hashCons(opts2).update(msg).digest();
|
|
41296
41519
|
const tmp = hashCons(void 0);
|
|
41297
41520
|
hashC.outputLen = tmp.outputLen;
|
|
41298
41521
|
hashC.blockLen = tmp.blockLen;
|
|
41522
|
+
hashC.canXOF = tmp.canXOF;
|
|
41299
41523
|
hashC.create = (opts2) => hashCons(opts2);
|
|
41300
41524
|
Object.assign(hashC, info);
|
|
41301
41525
|
return Object.freeze(hashC);
|
|
41302
41526
|
}
|
|
41303
41527
|
function randomBytes(bytesLength = 32) {
|
|
41528
|
+
anumber(bytesLength, "bytesLength");
|
|
41304
41529
|
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
|
|
41305
41530
|
if (typeof cr?.getRandomValues !== "function")
|
|
41306
41531
|
throw new Error("crypto.getRandomValues must be defined");
|
|
41532
|
+
if (bytesLength > 65536)
|
|
41533
|
+
throw new RangeError(`"bytesLength" expected <= 65536, got ${bytesLength}`);
|
|
41307
41534
|
return cr.getRandomValues(new Uint8Array(bytesLength));
|
|
41308
41535
|
}
|
|
41309
41536
|
var oidNist = (suffix) => ({
|
|
41537
|
+
// Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
|
|
41538
|
+
// Larger suffix values would need base-128 OID encoding and a different length byte.
|
|
41310
41539
|
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
41311
41540
|
});
|
|
41312
41541
|
|
|
@@ -41335,10 +41564,21 @@ ${operationTypes.join("\n")}
|
|
|
41335
41564
|
var IOTAS = split(_SHA3_IOTA, true);
|
|
41336
41565
|
var SHA3_IOTA_H = IOTAS[0];
|
|
41337
41566
|
var SHA3_IOTA_L = IOTAS[1];
|
|
41567
|
+
var rotlSH = (h3, l3, s2) => h3 << s2 | l3 >>> 32 - s2;
|
|
41568
|
+
var rotlSL = (h3, l3, s2) => l3 << s2 | h3 >>> 32 - s2;
|
|
41569
|
+
var rotlBH = (h3, l3, s2) => l3 << s2 - 32 | h3 >>> 64 - s2;
|
|
41570
|
+
var rotlBL = (h3, l3, s2) => h3 << s2 - 32 | l3 >>> 64 - s2;
|
|
41338
41571
|
var rotlH = (h3, l3, s2) => s2 > 32 ? rotlBH(h3, l3, s2) : rotlSH(h3, l3, s2);
|
|
41339
41572
|
var rotlL = (h3, l3, s2) => s2 > 32 ? rotlBL(h3, l3, s2) : rotlSL(h3, l3, s2);
|
|
41573
|
+
var B2 = new Uint32Array(5 * 2);
|
|
41340
41574
|
function keccakP(s2, rounds = 24) {
|
|
41341
|
-
|
|
41575
|
+
if (!(s2 instanceof Uint32Array))
|
|
41576
|
+
throw new TypeError('"s" expected Uint32Array(50), got type=' + typeof s2);
|
|
41577
|
+
if (s2.length !== 50)
|
|
41578
|
+
throw new RangeError('"s" expected Uint32Array(50), got length=' + s2.length);
|
|
41579
|
+
anumber(rounds, "rounds");
|
|
41580
|
+
if (rounds < 1 || rounds > 24)
|
|
41581
|
+
throw new Error('"rounds" expected integer 1..24');
|
|
41342
41582
|
for (let round = 24 - rounds; round < 24; round++) {
|
|
41343
41583
|
for (let x2 = 0; x2 < 10; x2++)
|
|
41344
41584
|
B2[x2] = s2[x2] ^ s2[x2 + 10] ^ s2[x2 + 20] ^ s2[x2 + 30] ^ s2[x2 + 40];
|
|
@@ -41367,10 +41607,17 @@ ${operationTypes.join("\n")}
|
|
|
41367
41607
|
s2[PI + 1] = Tl;
|
|
41368
41608
|
}
|
|
41369
41609
|
for (let y3 = 0; y3 < 50; y3 += 10) {
|
|
41370
|
-
|
|
41371
|
-
|
|
41372
|
-
|
|
41373
|
-
|
|
41610
|
+
const b0 = s2[y3], b1 = s2[y3 + 1], b2 = s2[y3 + 2], b3 = s2[y3 + 3];
|
|
41611
|
+
s2[y3] ^= ~s2[y3 + 2] & s2[y3 + 4];
|
|
41612
|
+
s2[y3 + 1] ^= ~s2[y3 + 3] & s2[y3 + 5];
|
|
41613
|
+
s2[y3 + 2] ^= ~s2[y3 + 4] & s2[y3 + 6];
|
|
41614
|
+
s2[y3 + 3] ^= ~s2[y3 + 5] & s2[y3 + 7];
|
|
41615
|
+
s2[y3 + 4] ^= ~s2[y3 + 6] & s2[y3 + 8];
|
|
41616
|
+
s2[y3 + 5] ^= ~s2[y3 + 7] & s2[y3 + 9];
|
|
41617
|
+
s2[y3 + 6] ^= ~s2[y3 + 8] & b0;
|
|
41618
|
+
s2[y3 + 7] ^= ~s2[y3 + 9] & b1;
|
|
41619
|
+
s2[y3 + 8] ^= ~b0 & b2;
|
|
41620
|
+
s2[y3 + 9] ^= ~b1 & b3;
|
|
41374
41621
|
}
|
|
41375
41622
|
s2[0] ^= SHA3_IOTA_H[round];
|
|
41376
41623
|
s2[1] ^= SHA3_IOTA_L[round];
|
|
@@ -41387,18 +41634,24 @@ ${operationTypes.join("\n")}
|
|
|
41387
41634
|
blockLen;
|
|
41388
41635
|
suffix;
|
|
41389
41636
|
outputLen;
|
|
41637
|
+
canXOF;
|
|
41390
41638
|
enableXOF = false;
|
|
41391
41639
|
rounds;
|
|
41392
41640
|
// NOTE: we accept arguments in bytes instead of bits here.
|
|
41393
41641
|
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
41642
|
+
anumber(blockLen, "blockLen");
|
|
41643
|
+
anumber(suffix, "suffix");
|
|
41644
|
+
anumber(rounds, "rounds");
|
|
41645
|
+
abool(enableXOF, "enableXOF");
|
|
41394
41646
|
this.blockLen = blockLen;
|
|
41395
41647
|
this.suffix = suffix;
|
|
41396
41648
|
this.outputLen = outputLen;
|
|
41397
41649
|
this.enableXOF = enableXOF;
|
|
41650
|
+
this.canXOF = enableXOF;
|
|
41398
41651
|
this.rounds = rounds;
|
|
41399
41652
|
anumber(outputLen, "outputLen");
|
|
41400
41653
|
if (!(0 < blockLen && blockLen < 200))
|
|
41401
|
-
throw new Error("
|
|
41654
|
+
throw new Error('"blockLen" must be 1..199');
|
|
41402
41655
|
this.state = new Uint8Array(200);
|
|
41403
41656
|
this.state32 = u32(this.state);
|
|
41404
41657
|
}
|
|
@@ -41415,9 +41668,20 @@ ${operationTypes.join("\n")}
|
|
|
41415
41668
|
update(data) {
|
|
41416
41669
|
aexists(this);
|
|
41417
41670
|
abytes(data);
|
|
41418
|
-
const { blockLen, state } = this;
|
|
41671
|
+
const { blockLen, state, state32 } = this;
|
|
41419
41672
|
const len = data.length;
|
|
41673
|
+
const canUseU32 = blockLen % 4 === 0 && data.byteOffset % 4 === 0;
|
|
41674
|
+
const blockLen32 = blockLen / 4;
|
|
41675
|
+
const data32 = canUseU32 && len >= blockLen ? u32(data) : void 0;
|
|
41420
41676
|
for (let pos = 0; pos < len; ) {
|
|
41677
|
+
if (data32 !== void 0 && this.pos === 0 && pos % 4 === 0 && len - pos >= blockLen) {
|
|
41678
|
+
for (let i4 = 0, o3 = pos / 4; i4 < blockLen32; i4++)
|
|
41679
|
+
state32[i4] ^= data32[o3 + i4];
|
|
41680
|
+
pos += blockLen;
|
|
41681
|
+
this.pos = blockLen;
|
|
41682
|
+
this.keccak();
|
|
41683
|
+
continue;
|
|
41684
|
+
}
|
|
41421
41685
|
const take2 = Math.min(blockLen - this.pos, len - pos);
|
|
41422
41686
|
for (let i4 = 0; i4 < take2; i4++)
|
|
41423
41687
|
state[this.pos++] ^= data[pos++];
|
|
@@ -41455,7 +41719,7 @@ ${operationTypes.join("\n")}
|
|
|
41455
41719
|
}
|
|
41456
41720
|
xofInto(out) {
|
|
41457
41721
|
if (!this.enableXOF)
|
|
41458
|
-
throw new Error("XOF is not
|
|
41722
|
+
throw new Error("XOF is not enabled");
|
|
41459
41723
|
return this.writeInto(out);
|
|
41460
41724
|
}
|
|
41461
41725
|
xof(bytes) {
|
|
@@ -41466,12 +41730,13 @@ ${operationTypes.join("\n")}
|
|
|
41466
41730
|
aoutput(out, this);
|
|
41467
41731
|
if (this.finished)
|
|
41468
41732
|
throw new Error("digest() was already called");
|
|
41469
|
-
this.writeInto(out);
|
|
41733
|
+
this.writeInto(out.length === this.outputLen ? out : out.subarray(0, this.outputLen));
|
|
41470
41734
|
this.destroy();
|
|
41471
|
-
return out;
|
|
41472
41735
|
}
|
|
41473
41736
|
digest() {
|
|
41474
|
-
|
|
41737
|
+
const out = new Uint8Array(this.outputLen);
|
|
41738
|
+
this.digestInto(out);
|
|
41739
|
+
return out;
|
|
41475
41740
|
}
|
|
41476
41741
|
destroy() {
|
|
41477
41742
|
this.destroyed = true;
|
|
@@ -41480,6 +41745,7 @@ ${operationTypes.join("\n")}
|
|
|
41480
41745
|
_cloneInto(to) {
|
|
41481
41746
|
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
|
41482
41747
|
to ||= new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds);
|
|
41748
|
+
to.blockLen = blockLen;
|
|
41483
41749
|
to.state32.set(this.state32);
|
|
41484
41750
|
to.pos = this.pos;
|
|
41485
41751
|
to.posOut = this.posOut;
|
|
@@ -41488,6 +41754,7 @@ ${operationTypes.join("\n")}
|
|
|
41488
41754
|
to.suffix = suffix;
|
|
41489
41755
|
to.outputLen = outputLen;
|
|
41490
41756
|
to.enableXOF = enableXOF;
|
|
41757
|
+
to.canXOF = this.canXOF;
|
|
41491
41758
|
to.destroyed = this.destroyed;
|
|
41492
41759
|
return to;
|
|
41493
41760
|
}
|
|
@@ -41505,35 +41772,73 @@ ${operationTypes.join("\n")}
|
|
|
41505
41772
|
64,
|
|
41506
41773
|
/* @__PURE__ */ oidNist(10)
|
|
41507
41774
|
);
|
|
41508
|
-
var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 = {}) =>
|
|
41775
|
+
var genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts2 = {}) => {
|
|
41776
|
+
opts2 = checkOpts({}, opts2);
|
|
41777
|
+
return new Keccak(blockLen, suffix, opts2.dkLen === void 0 ? outputLen : opts2.dkLen, true);
|
|
41778
|
+
}, info);
|
|
41509
41779
|
var shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
|
|
41510
41780
|
var shake2562 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
|
|
41511
41781
|
|
|
41782
|
+
// node_modules/@noble/curves/utils.js
|
|
41783
|
+
function aobject2(value2, title = "object") {
|
|
41784
|
+
if (value2 === null || typeof value2 !== "object" || Array.isArray(value2))
|
|
41785
|
+
throw new TypeError(title === "object" ? "expected valid options object" : `"${title}" expected object, got type=${typeof value2}`);
|
|
41786
|
+
return value2;
|
|
41787
|
+
}
|
|
41788
|
+
function validateObject(object2, fields = {}, optFields = {}, title = "object") {
|
|
41789
|
+
aobject2(object2, title);
|
|
41790
|
+
aobject2(fields, "fields");
|
|
41791
|
+
aobject2(optFields, "optFields");
|
|
41792
|
+
function checkField(fieldName, expectedType, isOpt) {
|
|
41793
|
+
const label = title === "object" ? `param "${String(fieldName)}"` : `"${title}.${String(fieldName)}"`;
|
|
41794
|
+
const val = object2[fieldName];
|
|
41795
|
+
if (!Object.hasOwn(object2, fieldName) && (isOpt ? val !== void 0 : expectedType !== "function")) {
|
|
41796
|
+
throw new TypeError(`${label} is invalid: expected own property`);
|
|
41797
|
+
}
|
|
41798
|
+
if (isOpt && val === void 0)
|
|
41799
|
+
return;
|
|
41800
|
+
const current = typeof val;
|
|
41801
|
+
if (current !== expectedType || val === null)
|
|
41802
|
+
throw new TypeError(`${label} is invalid: expected ${expectedType}, got ${current}`);
|
|
41803
|
+
}
|
|
41804
|
+
const iter = (f3, isOpt) => Object.entries(f3).forEach(([k2, v3]) => checkField(k2, v3, isOpt));
|
|
41805
|
+
iter(fields, false);
|
|
41806
|
+
iter(optFields, true);
|
|
41807
|
+
}
|
|
41808
|
+
|
|
41512
41809
|
// node_modules/@noble/curves/abstract/fft.js
|
|
41513
|
-
function checkU32(n3) {
|
|
41810
|
+
function checkU32(n3, title = "n") {
|
|
41811
|
+
if (typeof n3 !== "number")
|
|
41812
|
+
throw new TypeError(`wrong u32 integer "${title}": expected number, got type=${typeof n3}`);
|
|
41514
41813
|
if (!Number.isSafeInteger(n3) || n3 < 0 || n3 > 4294967295)
|
|
41515
|
-
throw new
|
|
41814
|
+
throw new RangeError(`wrong u32 integer "${title}": expected 0..4294967295, got ${n3}`);
|
|
41516
41815
|
return n3;
|
|
41517
41816
|
}
|
|
41518
41817
|
function isPowerOfTwo(x2) {
|
|
41519
|
-
checkU32(x2);
|
|
41818
|
+
checkU32(x2, "x");
|
|
41520
41819
|
return (x2 & x2 - 1) === 0 && x2 !== 0;
|
|
41521
41820
|
}
|
|
41522
41821
|
function reverseBits(n3, bits) {
|
|
41523
41822
|
checkU32(n3);
|
|
41823
|
+
if (typeof bits !== "number")
|
|
41824
|
+
throw new TypeError('"bits" expected number, got type=' + typeof bits);
|
|
41825
|
+
if (!Number.isSafeInteger(bits) || bits < 0 || bits > 32)
|
|
41826
|
+
throw new Error(`expected integer 0 <= bits <= 32, got ${bits}`);
|
|
41524
41827
|
let reversed = 0;
|
|
41525
41828
|
for (let i4 = 0; i4 < bits; i4++, n3 >>>= 1)
|
|
41526
41829
|
reversed = reversed << 1 | n3 & 1;
|
|
41527
|
-
return reversed;
|
|
41830
|
+
return reversed >>> 0;
|
|
41528
41831
|
}
|
|
41529
41832
|
function log2(n3) {
|
|
41530
41833
|
checkU32(n3);
|
|
41531
41834
|
return 31 - Math.clz32(n3);
|
|
41532
41835
|
}
|
|
41533
41836
|
function bitReversalInplace(values) {
|
|
41837
|
+
if (!values || typeof values !== "object" || typeof values.length !== "number")
|
|
41838
|
+
throw new TypeError('"values" expected array-like, got type=' + typeof values);
|
|
41534
41839
|
const n3 = values.length;
|
|
41535
|
-
if (
|
|
41536
|
-
throw new Error("
|
|
41840
|
+
if (!isPowerOfTwo(n3))
|
|
41841
|
+
throw new Error("expected positive power-of-two length, got " + n3);
|
|
41537
41842
|
const bits = log2(n3);
|
|
41538
41843
|
for (let i4 = 0; i4 < n3; i4++) {
|
|
41539
41844
|
const j2 = reverseBits(i4, bits);
|
|
@@ -41546,10 +41851,18 @@ ${operationTypes.join("\n")}
|
|
|
41546
41851
|
return values;
|
|
41547
41852
|
}
|
|
41548
41853
|
var FFTCore = (F3, coreOpts) => {
|
|
41854
|
+
validateObject(coreOpts, { N: "number", roots: "object", dit: "boolean" }, { invertButterflies: "boolean", skipStages: "number", brp: "boolean" }, "coreOpts");
|
|
41549
41855
|
const { N: N3, roots, dit, invertButterflies = false, skipStages = 0, brp = true } = coreOpts;
|
|
41856
|
+
checkU32(N3, "coreOpts.N");
|
|
41550
41857
|
const bits = log2(N3);
|
|
41551
41858
|
if (!isPowerOfTwo(N3))
|
|
41552
41859
|
throw new Error("FFT: Polynomial size should be power of two");
|
|
41860
|
+
checkU32(skipStages, "coreOpts.skipStages");
|
|
41861
|
+
const maxSkipStages = bits === 0 ? 0 : bits - 1;
|
|
41862
|
+
if (skipStages > maxSkipStages)
|
|
41863
|
+
throw new Error(`FFT: wrong skipStages: expected 0 <= skipStages <= ${maxSkipStages}`);
|
|
41864
|
+
if (roots.length !== N3)
|
|
41865
|
+
throw new Error(`FFT: wrong roots length: expected ${N3}, got ${roots.length}`);
|
|
41553
41866
|
const isDit = dit !== invertButterflies;
|
|
41554
41867
|
return (values) => {
|
|
41555
41868
|
if (values.length !== N3)
|
|
@@ -41590,8 +41903,19 @@ ${operationTypes.join("\n")}
|
|
|
41590
41903
|
};
|
|
41591
41904
|
|
|
41592
41905
|
// node_modules/@noble/post-quantum/utils.js
|
|
41906
|
+
var abytesDoc = abytes;
|
|
41593
41907
|
var randomBytes2 = randomBytes;
|
|
41908
|
+
function aarray2(item, title, inner = () => {
|
|
41909
|
+
}) {
|
|
41910
|
+
if (!Array.isArray(item))
|
|
41911
|
+
throw new TypeError(`"${title}" expected array, got type=${typeof item}`);
|
|
41912
|
+
for (let i4 = 0; i4 < item.length; i4++)
|
|
41913
|
+
inner(item[i4], `${title}[${i4}]`);
|
|
41914
|
+
return item;
|
|
41915
|
+
}
|
|
41594
41916
|
function equalBytes(a3, b2) {
|
|
41917
|
+
a3 = abytes(a3);
|
|
41918
|
+
b2 = abytes(b2);
|
|
41595
41919
|
if (a3.length !== b2.length)
|
|
41596
41920
|
return false;
|
|
41597
41921
|
let diff3 = 0;
|
|
@@ -41600,7 +41924,7 @@ ${operationTypes.join("\n")}
|
|
|
41600
41924
|
return diff3 === 0;
|
|
41601
41925
|
}
|
|
41602
41926
|
function copyBytes(bytes) {
|
|
41603
|
-
return Uint8Array
|
|
41927
|
+
return new Uint8Array(abytes(bytes));
|
|
41604
41928
|
}
|
|
41605
41929
|
function splitCoder(label, ...lengths) {
|
|
41606
41930
|
const getLength = (c3) => typeof c3 === "number" ? c3 : c3.bytesLen;
|
|
@@ -41635,15 +41959,17 @@ ${operationTypes.join("\n")}
|
|
|
41635
41959
|
};
|
|
41636
41960
|
}
|
|
41637
41961
|
function vecCoder(c3, vecLen) {
|
|
41638
|
-
const
|
|
41962
|
+
const coder = c3;
|
|
41963
|
+
const bytesLen = vecLen * coder.bytesLen;
|
|
41639
41964
|
return {
|
|
41640
41965
|
bytesLen,
|
|
41641
41966
|
encode: (u4) => {
|
|
41642
|
-
|
|
41643
|
-
|
|
41967
|
+
const uArr = aarray2(u4, "u");
|
|
41968
|
+
if (uArr.length !== vecLen)
|
|
41969
|
+
throw new RangeError(`vecCoder.encode: wrong length=${uArr.length}. Expected: ${vecLen}`);
|
|
41644
41970
|
const res = new Uint8Array(bytesLen);
|
|
41645
|
-
for (let i4 = 0, pos = 0; i4 <
|
|
41646
|
-
const b2 =
|
|
41971
|
+
for (let i4 = 0, pos = 0; i4 < uArr.length; i4++) {
|
|
41972
|
+
const b2 = coder.encode(uArr[i4]);
|
|
41647
41973
|
res.set(b2, pos);
|
|
41648
41974
|
b2.fill(0);
|
|
41649
41975
|
pos += b2.length;
|
|
@@ -41653,8 +41979,8 @@ ${operationTypes.join("\n")}
|
|
|
41653
41979
|
decode: (a3) => {
|
|
41654
41980
|
abytes(a3, bytesLen);
|
|
41655
41981
|
const r3 = [];
|
|
41656
|
-
for (let i4 = 0; i4 < a3.length; i4 +=
|
|
41657
|
-
r3.push(
|
|
41982
|
+
for (let i4 = 0; i4 < a3.length; i4 += coder.bytesLen)
|
|
41983
|
+
r3.push(coder.decode(a3.subarray(i4, i4 + coder.bytesLen)));
|
|
41658
41984
|
return r3;
|
|
41659
41985
|
}
|
|
41660
41986
|
};
|
|
@@ -41669,18 +41995,21 @@ ${operationTypes.join("\n")}
|
|
|
41669
41995
|
}
|
|
41670
41996
|
}
|
|
41671
41997
|
function getMask(bits) {
|
|
41672
|
-
|
|
41998
|
+
anumber(bits, "bits");
|
|
41999
|
+
if (bits > 32)
|
|
42000
|
+
throw new RangeError('"bits" expected <= 32, got ' + bits);
|
|
42001
|
+
return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
|
|
41673
42002
|
}
|
|
41674
42003
|
|
|
41675
42004
|
// node_modules/@noble/post-quantum/_crystals.js
|
|
41676
42005
|
var genCrystals = (opts2) => {
|
|
41677
42006
|
const { newPoly, N: N3, Q: Q4, F: F3, ROOT_OF_UNITY: ROOT_OF_UNITY2, brvBits} = opts2;
|
|
41678
|
-
const
|
|
42007
|
+
const mod = (a3, modulo = Q4) => {
|
|
41679
42008
|
const result = a3 % modulo | 0;
|
|
41680
42009
|
return (result >= 0 ? result | 0 : modulo + result | 0) | 0;
|
|
41681
42010
|
};
|
|
41682
42011
|
const smod = (a3, modulo = Q4) => {
|
|
41683
|
-
const r3 =
|
|
42012
|
+
const r3 = mod(a3, modulo) | 0;
|
|
41684
42013
|
return (r3 > modulo >> 1 ? r3 - modulo | 0 : r3) | 0;
|
|
41685
42014
|
};
|
|
41686
42015
|
function getZettas() {
|
|
@@ -41692,47 +42021,61 @@ ${operationTypes.join("\n")}
|
|
|
41692
42021
|
}
|
|
41693
42022
|
return out;
|
|
41694
42023
|
}
|
|
41695
|
-
const
|
|
41696
|
-
const
|
|
41697
|
-
|
|
41698
|
-
sub: (a3, b2) => mod2((a3 | 0) - (b2 | 0)) | 0,
|
|
41699
|
-
mul: (a3, b2) => mod2((a3 | 0) * (b2 | 0)) | 0,
|
|
41700
|
-
inv: (_a3) => {
|
|
41701
|
-
throw new Error("not implemented");
|
|
41702
|
-
}
|
|
42024
|
+
const nttZetas = getZettas();
|
|
42025
|
+
const inv = (_a3) => {
|
|
42026
|
+
throw new Error("not implemented");
|
|
41703
42027
|
};
|
|
42028
|
+
const field = {
|
|
42029
|
+
add: (a3, b2) => {
|
|
42030
|
+
const r3 = a3 + b2 | 0;
|
|
42031
|
+
return r3 >= Q4 ? r3 - Q4 | 0 : r3;
|
|
42032
|
+
},
|
|
42033
|
+
sub: (a3, b2) => {
|
|
42034
|
+
const r3 = a3 - b2 | 0;
|
|
42035
|
+
return r3 < 0 ? r3 + Q4 | 0 : r3;
|
|
42036
|
+
},
|
|
42037
|
+
mul: (a3, b2) => mod((a3 | 0) * (b2 | 0)) | 0,
|
|
42038
|
+
inv
|
|
42039
|
+
} ;
|
|
41704
42040
|
const nttOpts = {
|
|
41705
42041
|
N: N3,
|
|
41706
|
-
roots:
|
|
42042
|
+
roots: nttZetas,
|
|
41707
42043
|
invertButterflies: true,
|
|
41708
42044
|
skipStages: 1 ,
|
|
41709
42045
|
brp: false
|
|
41710
42046
|
};
|
|
41711
42047
|
const dif = FFTCore(field, { dit: false, ...nttOpts });
|
|
41712
42048
|
const dit = FFTCore(field, { dit: true, ...nttOpts });
|
|
41713
|
-
const
|
|
42049
|
+
const NTT = {
|
|
41714
42050
|
encode: (r3) => {
|
|
41715
42051
|
return dif(r3);
|
|
41716
42052
|
},
|
|
41717
42053
|
decode: (r3) => {
|
|
41718
42054
|
dit(r3);
|
|
41719
42055
|
for (let i4 = 0; i4 < r3.length; i4++)
|
|
41720
|
-
r3[i4] =
|
|
42056
|
+
r3[i4] = mod(F3 * r3[i4]);
|
|
41721
42057
|
return r3;
|
|
41722
42058
|
}
|
|
41723
42059
|
};
|
|
41724
|
-
const
|
|
42060
|
+
const bitsCoder = (d4, c3) => {
|
|
42061
|
+
for (let i4 = 0, bufLen = 0; i4 < N3; i4++) {
|
|
42062
|
+
bufLen += d4;
|
|
42063
|
+
if (bufLen > 32)
|
|
42064
|
+
getMask(bufLen);
|
|
42065
|
+
bufLen %= 8;
|
|
42066
|
+
}
|
|
41725
42067
|
const mask = getMask(d4);
|
|
41726
42068
|
const bytesLen = d4 * (N3 / 8);
|
|
41727
42069
|
return {
|
|
41728
42070
|
bytesLen,
|
|
41729
|
-
encode: (
|
|
42071
|
+
encode: (poly_) => {
|
|
42072
|
+
const poly = poly_;
|
|
41730
42073
|
const r3 = new Uint8Array(bytesLen);
|
|
41731
42074
|
for (let i4 = 0, buf = 0, bufLen = 0, pos = 0; i4 < poly.length; i4++) {
|
|
41732
42075
|
buf |= (c3.encode(poly[i4]) & mask) << bufLen;
|
|
41733
42076
|
bufLen += d4;
|
|
41734
42077
|
for (; bufLen >= 8; bufLen -= 8, buf >>= 8)
|
|
41735
|
-
r3[pos++] = buf &
|
|
42078
|
+
r3[pos++] = buf & 255;
|
|
41736
42079
|
}
|
|
41737
42080
|
return r3;
|
|
41738
42081
|
},
|
|
@@ -41748,7 +42091,16 @@ ${operationTypes.join("\n")}
|
|
|
41748
42091
|
}
|
|
41749
42092
|
};
|
|
41750
42093
|
};
|
|
41751
|
-
return {
|
|
42094
|
+
return {
|
|
42095
|
+
mod,
|
|
42096
|
+
smod,
|
|
42097
|
+
nttZetas,
|
|
42098
|
+
NTT: {
|
|
42099
|
+
encode: (r3) => NTT.encode(r3),
|
|
42100
|
+
decode: (r3) => NTT.decode(r3)
|
|
42101
|
+
},
|
|
42102
|
+
bitsCoder
|
|
42103
|
+
};
|
|
41752
42104
|
};
|
|
41753
42105
|
var createXofShake = (shake) => (seed, blockLen) => {
|
|
41754
42106
|
if (!blockLen)
|
|
@@ -41786,43 +42138,57 @@ ${operationTypes.join("\n")}
|
|
|
41786
42138
|
var Q2 = 3329;
|
|
41787
42139
|
var F2 = 3303;
|
|
41788
42140
|
var ROOT_OF_UNITY = 17;
|
|
41789
|
-
var
|
|
42141
|
+
var crystals = /* @__PURE__ */ genCrystals({
|
|
41790
42142
|
N: N2,
|
|
41791
42143
|
Q: Q2,
|
|
41792
42144
|
F: F2,
|
|
41793
42145
|
ROOT_OF_UNITY,
|
|
41794
42146
|
newPoly: (n3) => new Uint16Array(n3),
|
|
41795
42147
|
brvBits: 7});
|
|
41796
|
-
var PARAMS = {
|
|
41797
|
-
|
|
42148
|
+
var PARAMS = /* @__PURE__ */ (() => Object.freeze({
|
|
42149
|
+
512: Object.freeze({ N: N2, Q: Q2, K: 2, ETA1: 3, ETA2: 2, du: 10, dv: 4, RBGstrength: 128 }),
|
|
42150
|
+
768: Object.freeze({ N: N2, Q: Q2, K: 3, ETA1: 2, ETA2: 2, du: 10, dv: 4, RBGstrength: 192 }),
|
|
42151
|
+
1024: Object.freeze({ N: N2, Q: Q2, K: 4, ETA1: 2, ETA2: 2, du: 11, dv: 5, RBGstrength: 256 })
|
|
42152
|
+
}))();
|
|
41798
42153
|
var compress = (d4) => {
|
|
41799
42154
|
if (d4 >= 12)
|
|
41800
|
-
return { encode: (i4) => i4, decode: (i4) => i4 };
|
|
42155
|
+
return { encode: (i4) => i4, decode: (i4) => i4 >= Q2 ? i4 - Q2 : i4 };
|
|
41801
42156
|
const a3 = 2 ** (d4 - 1);
|
|
41802
42157
|
return {
|
|
41803
|
-
//
|
|
42158
|
+
// This only matches standalone Compress_d after bitsCoder masks the result into Z_(2^d).
|
|
41804
42159
|
encode: (i4) => ((i4 << d4) + Q2 / 2) / Q2,
|
|
41805
42160
|
// const decompress = (i: number) => round((Q / 2 ** d) * i);
|
|
41806
42161
|
decode: (i4) => i4 * Q2 + a3 >>> d4
|
|
41807
42162
|
};
|
|
41808
42163
|
};
|
|
41809
|
-
var
|
|
41810
|
-
|
|
41811
|
-
|
|
41812
|
-
|
|
42164
|
+
var byteCoder = (d4) => crystals.bitsCoder(d4, { encode: (i4) => i4, decode: (i4) => i4 >= Q2 ? i4 - Q2 : i4 } );
|
|
42165
|
+
var polyCoder = (d4) => d4 === 12 ? byteCoder(12) : crystals.bitsCoder(d4, compress(d4));
|
|
42166
|
+
function polyAdd(a_, b_) {
|
|
42167
|
+
const a3 = a_;
|
|
42168
|
+
const b2 = b_;
|
|
42169
|
+
for (let i4 = 0; i4 < N2; i4++) {
|
|
42170
|
+
const r3 = a3[i4] + b2[i4];
|
|
42171
|
+
a3[i4] = r3 >= Q2 ? r3 - Q2 : r3;
|
|
42172
|
+
}
|
|
41813
42173
|
}
|
|
41814
|
-
function polySub(
|
|
41815
|
-
|
|
41816
|
-
|
|
42174
|
+
function polySub(a_, b_) {
|
|
42175
|
+
const a3 = a_;
|
|
42176
|
+
const b2 = b_;
|
|
42177
|
+
for (let i4 = 0; i4 < N2; i4++) {
|
|
42178
|
+
const r3 = a3[i4] - b2[i4];
|
|
42179
|
+
a3[i4] = r3 < 0 ? r3 + Q2 : r3;
|
|
42180
|
+
}
|
|
41817
42181
|
}
|
|
41818
42182
|
function BaseCaseMultiply(a0, a1, b0, b1, zeta) {
|
|
41819
|
-
const c0 = mod(a1 * b1 * zeta + a0 * b0);
|
|
41820
|
-
const c1 = mod(a0 * b1 + a1 * b0);
|
|
42183
|
+
const c0 = crystals.mod(crystals.mod(a1 * b1) * zeta + a0 * b0);
|
|
42184
|
+
const c1 = crystals.mod(a0 * b1 + a1 * b0);
|
|
41821
42185
|
return { c0, c1 };
|
|
41822
42186
|
}
|
|
41823
|
-
function MultiplyNTTs(
|
|
42187
|
+
function MultiplyNTTs(f_, g_) {
|
|
42188
|
+
const f3 = f_;
|
|
42189
|
+
const g2 = g_;
|
|
41824
42190
|
for (let i4 = 0; i4 < N2 / 2; i4++) {
|
|
41825
|
-
let z3 = nttZetas[64 + (i4 >> 1)];
|
|
42191
|
+
let z3 = crystals.nttZetas[64 + (i4 >> 1)];
|
|
41826
42192
|
if (i4 & 1)
|
|
41827
42193
|
z3 = -z3;
|
|
41828
42194
|
const { c0, c1 } = BaseCaseMultiply(f3[2 * i4 + 0], f3[2 * i4 + 1], g2[2 * i4 + 0], g2[2 * i4 + 1], z3);
|
|
@@ -41831,7 +42197,8 @@ ${operationTypes.join("\n")}
|
|
|
41831
42197
|
}
|
|
41832
42198
|
return f3;
|
|
41833
42199
|
}
|
|
41834
|
-
function SampleNTT(
|
|
42200
|
+
function SampleNTT(xof_) {
|
|
42201
|
+
const xof = xof_;
|
|
41835
42202
|
const r3 = new Uint16Array(N2);
|
|
41836
42203
|
for (let j2 = 0; j2 < N2; ) {
|
|
41837
42204
|
const b2 = xof();
|
|
@@ -41848,10 +42215,10 @@ ${operationTypes.join("\n")}
|
|
|
41848
42215
|
}
|
|
41849
42216
|
return r3;
|
|
41850
42217
|
}
|
|
41851
|
-
|
|
41852
|
-
const buf = PRF(eta * N2 / 4, seed, nonce);
|
|
42218
|
+
var sampleCBDBytes = (buf, eta) => {
|
|
41853
42219
|
const r3 = new Uint16Array(N2);
|
|
41854
42220
|
const b32 = u32(buf);
|
|
42221
|
+
swap32IfBE(b32);
|
|
41855
42222
|
let len = 0;
|
|
41856
42223
|
for (let i4 = 0, p3 = 0, bb = 0, t0 = 0; i4 < b32.length; i4++) {
|
|
41857
42224
|
let b2 = b32[i4];
|
|
@@ -41863,17 +42230,23 @@ ${operationTypes.join("\n")}
|
|
|
41863
42230
|
t0 = bb;
|
|
41864
42231
|
bb = 0;
|
|
41865
42232
|
} else if (len === 2 * eta) {
|
|
41866
|
-
r3[p3++] = mod(t0 - bb);
|
|
42233
|
+
r3[p3++] = crystals.mod(t0 - bb);
|
|
41867
42234
|
bb = 0;
|
|
41868
42235
|
len = 0;
|
|
41869
42236
|
}
|
|
41870
42237
|
}
|
|
41871
42238
|
}
|
|
42239
|
+
swap32IfBE(b32);
|
|
41872
42240
|
if (len)
|
|
41873
42241
|
throw new Error(`sampleCBD: leftover bits: ${len}`);
|
|
41874
42242
|
return r3;
|
|
42243
|
+
};
|
|
42244
|
+
function sampleCBD(PRF_, seed, nonce, eta) {
|
|
42245
|
+
const PRF = PRF_;
|
|
42246
|
+
return sampleCBDBytes(PRF(eta * N2 / 4, seed, nonce), eta);
|
|
41875
42247
|
}
|
|
41876
|
-
var genKPKE = (
|
|
42248
|
+
var genKPKE = (opts_) => {
|
|
42249
|
+
const opts2 = opts_;
|
|
41877
42250
|
const { K: K2, PRF, XOF, HASH512, ETA1, ETA2, du, dv } = opts2;
|
|
41878
42251
|
const poly1 = polyCoder(1);
|
|
41879
42252
|
const polyV = polyCoder(dv);
|
|
@@ -41882,6 +42255,31 @@ ${operationTypes.join("\n")}
|
|
|
41882
42255
|
const secretCoder = vecCoder(polyCoder(12), K2);
|
|
41883
42256
|
const cipherCoder = splitCoder("ciphertext", vecCoder(polyU, K2), polyV);
|
|
41884
42257
|
const seedCoder = splitCoder("seed", 32, 32);
|
|
42258
|
+
const encryptCore = (tHat, getA, msg, seed) => {
|
|
42259
|
+
const rHat = [];
|
|
42260
|
+
for (let i4 = 0; i4 < K2; i4++)
|
|
42261
|
+
rHat.push(crystals.NTT.encode(sampleCBD(PRF, seed, i4, ETA1)));
|
|
42262
|
+
const tmp2 = new Uint16Array(N2);
|
|
42263
|
+
const u4 = [];
|
|
42264
|
+
for (let i4 = 0; i4 < K2; i4++) {
|
|
42265
|
+
const e1 = sampleCBD(PRF, seed, K2 + i4, ETA2);
|
|
42266
|
+
const tmp = new Uint16Array(N2);
|
|
42267
|
+
for (let j2 = 0; j2 < K2; j2++) {
|
|
42268
|
+
const aij = getA(i4, j2);
|
|
42269
|
+
polyAdd(tmp, MultiplyNTTs(aij, rHat[j2]));
|
|
42270
|
+
}
|
|
42271
|
+
polyAdd(e1, crystals.NTT.decode(tmp));
|
|
42272
|
+
u4.push(e1);
|
|
42273
|
+
polyAdd(tmp2, MultiplyNTTs(tHat[i4], rHat[i4]));
|
|
42274
|
+
cleanBytes(tmp);
|
|
42275
|
+
}
|
|
42276
|
+
const e22 = sampleCBD(PRF, seed, 2 * K2, ETA2);
|
|
42277
|
+
polyAdd(e22, crystals.NTT.decode(tmp2));
|
|
42278
|
+
const v3 = poly1.decode(msg);
|
|
42279
|
+
polyAdd(v3, e22);
|
|
42280
|
+
cleanBytes(tHat, rHat, tmp2, e22);
|
|
42281
|
+
return cipherCoder.encode([u4, v3]);
|
|
42282
|
+
};
|
|
41885
42283
|
return {
|
|
41886
42284
|
secretCoder,
|
|
41887
42285
|
lengths: {
|
|
@@ -41890,7 +42288,7 @@ ${operationTypes.join("\n")}
|
|
|
41890
42288
|
cipherText: cipherCoder.bytesLen
|
|
41891
42289
|
},
|
|
41892
42290
|
keygen: (seed) => {
|
|
41893
|
-
|
|
42291
|
+
abytesDoc(seed, 32, "seed");
|
|
41894
42292
|
const seedDst = new Uint8Array(33);
|
|
41895
42293
|
seedDst.set(seed);
|
|
41896
42294
|
seedDst[32] = K2;
|
|
@@ -41899,10 +42297,10 @@ ${operationTypes.join("\n")}
|
|
|
41899
42297
|
const sHat = [];
|
|
41900
42298
|
const tHat = [];
|
|
41901
42299
|
for (let i4 = 0; i4 < K2; i4++)
|
|
41902
|
-
sHat.push(NTT.encode(sampleCBD(PRF, sigma, i4, ETA1)));
|
|
42300
|
+
sHat.push(crystals.NTT.encode(sampleCBD(PRF, sigma, i4, ETA1)));
|
|
41903
42301
|
const x2 = XOF(rho);
|
|
41904
42302
|
for (let i4 = 0; i4 < K2; i4++) {
|
|
41905
|
-
const e4 = NTT.encode(sampleCBD(PRF, sigma, K2 + i4, ETA1));
|
|
42303
|
+
const e4 = crystals.NTT.encode(sampleCBD(PRF, sigma, K2 + i4, ETA1));
|
|
41906
42304
|
for (let j2 = 0; j2 < K2; j2++) {
|
|
41907
42305
|
const aji = SampleNTT(x2.get(j2, i4));
|
|
41908
42306
|
polyAdd(e4, MultiplyNTTs(aji, sHat[j2]));
|
|
@@ -41919,90 +42317,119 @@ ${operationTypes.join("\n")}
|
|
|
41919
42317
|
},
|
|
41920
42318
|
encrypt: (publicKey, msg, seed) => {
|
|
41921
42319
|
const [tHat, rho] = publicCoder.decode(publicKey);
|
|
41922
|
-
const rHat = [];
|
|
41923
|
-
for (let i4 = 0; i4 < K2; i4++)
|
|
41924
|
-
rHat.push(NTT.encode(sampleCBD(PRF, seed, i4, ETA1)));
|
|
41925
42320
|
const x2 = XOF(rho);
|
|
41926
|
-
const
|
|
41927
|
-
|
|
41928
|
-
|
|
41929
|
-
|
|
41930
|
-
|
|
41931
|
-
|
|
41932
|
-
|
|
41933
|
-
|
|
41934
|
-
|
|
41935
|
-
|
|
41936
|
-
|
|
41937
|
-
|
|
41938
|
-
|
|
41939
|
-
|
|
42321
|
+
const res = encryptCore(tHat, (i4, j2) => SampleNTT(x2.get(i4, j2)), msg, seed);
|
|
42322
|
+
x2.clean();
|
|
42323
|
+
return res;
|
|
42324
|
+
},
|
|
42325
|
+
// Expands the full  matrix (public data derived from rho) once, so repeated encryptions
|
|
42326
|
+
// against the same ek skip the K² SampleNTT XOF expansions. Cached polys are copied per
|
|
42327
|
+
// call because encryptCore mutates its inputs in place.
|
|
42328
|
+
prepare: (publicKey) => {
|
|
42329
|
+
const [tHat, rho] = publicCoder.decode(publicKey);
|
|
42330
|
+
const x2 = XOF(rho);
|
|
42331
|
+
const A2 = [];
|
|
42332
|
+
for (let i4 = 0; i4 < K2; i4++)
|
|
42333
|
+
for (let j2 = 0; j2 < K2; j2++)
|
|
42334
|
+
A2.push(SampleNTT(x2.get(i4, j2)));
|
|
41940
42335
|
x2.clean();
|
|
41941
|
-
|
|
41942
|
-
|
|
41943
|
-
|
|
41944
|
-
|
|
41945
|
-
cleanBytes(tHat, rHat, tmp2, e22);
|
|
41946
|
-
return cipherCoder.encode([u4, v3]);
|
|
42336
|
+
return {
|
|
42337
|
+
encrypt: (msg, seed) => encryptCore(tHat.map((p3) => p3.slice()), (i4, j2) => A2[i4 * K2 + j2].slice(), msg, seed),
|
|
42338
|
+
clean: () => cleanBytes(tHat, A2)
|
|
42339
|
+
};
|
|
41947
42340
|
},
|
|
41948
42341
|
decrypt: (cipherText, privateKey) => {
|
|
41949
42342
|
const [u4, v3] = cipherCoder.decode(cipherText);
|
|
41950
42343
|
const sk = secretCoder.decode(privateKey);
|
|
41951
42344
|
const tmp = new Uint16Array(N2);
|
|
41952
42345
|
for (let i4 = 0; i4 < K2; i4++)
|
|
41953
|
-
polyAdd(tmp, MultiplyNTTs(sk[i4], NTT.encode(u4[i4])));
|
|
41954
|
-
polySub(v3, NTT.decode(tmp));
|
|
41955
|
-
|
|
41956
|
-
|
|
42346
|
+
polyAdd(tmp, MultiplyNTTs(sk[i4], crystals.NTT.encode(u4[i4])));
|
|
42347
|
+
polySub(v3, crystals.NTT.decode(tmp));
|
|
42348
|
+
const res = poly1.encode(v3);
|
|
42349
|
+
cleanBytes(tmp, sk, u4, v3);
|
|
42350
|
+
return res;
|
|
41957
42351
|
}
|
|
41958
42352
|
};
|
|
41959
42353
|
};
|
|
41960
42354
|
function createKyber(opts2) {
|
|
41961
|
-
const
|
|
41962
|
-
const
|
|
42355
|
+
const rawOpts = opts2;
|
|
42356
|
+
const KPKE = genKPKE(rawOpts);
|
|
42357
|
+
const { HASH256, HASH512, KDF } = rawOpts;
|
|
41963
42358
|
const { secretCoder: KPKESecretCoder, lengths } = KPKE;
|
|
41964
42359
|
const secretCoder = splitCoder("secretKey", lengths.secretKey, lengths.publicKey, 32, 32);
|
|
41965
42360
|
const msgLen = 32;
|
|
41966
42361
|
const seedLen = 64;
|
|
41967
|
-
|
|
41968
|
-
|
|
41969
|
-
|
|
41970
|
-
|
|
41971
|
-
|
|
41972
|
-
|
|
41973
|
-
|
|
41974
|
-
|
|
41975
|
-
|
|
41976
|
-
|
|
41977
|
-
|
|
41978
|
-
|
|
41979
|
-
|
|
41980
|
-
|
|
41981
|
-
|
|
41982
|
-
|
|
42362
|
+
const validateModulus = (publicKey, fn) => {
|
|
42363
|
+
const eke = publicKey.subarray(0, 384 * rawOpts.K);
|
|
42364
|
+
const ek = KPKESecretCoder.encode(KPKESecretCoder.decode(copyBytes(eke)));
|
|
42365
|
+
const ok = equalBytes(ek, eke);
|
|
42366
|
+
cleanBytes(ek);
|
|
42367
|
+
if (!ok)
|
|
42368
|
+
throw new Error(`ML-KEM.${fn}: wrong publicKey modulus`);
|
|
42369
|
+
};
|
|
42370
|
+
const kemLengths = Object.freeze({
|
|
42371
|
+
...lengths,
|
|
42372
|
+
seed: 64,
|
|
42373
|
+
msg: msgLen,
|
|
42374
|
+
msgRand: msgLen,
|
|
42375
|
+
secretKey: secretCoder.bytesLen
|
|
42376
|
+
});
|
|
42377
|
+
return Object.freeze({
|
|
42378
|
+
info: Object.freeze({ type: "ml-kem" }),
|
|
42379
|
+
lengths: kemLengths,
|
|
42380
|
+
keygen: (seed) => {
|
|
42381
|
+
const ownSeed = seed === void 0;
|
|
42382
|
+
const s2 = ownSeed ? randomBytes2(seedLen) : seed;
|
|
42383
|
+
let sk;
|
|
42384
|
+
let publicKeyHash;
|
|
42385
|
+
try {
|
|
42386
|
+
abytesDoc(s2, seedLen, "seed");
|
|
42387
|
+
const keys = KPKE.keygen(s2.subarray(0, 32));
|
|
42388
|
+
const publicKey = keys.publicKey;
|
|
42389
|
+
sk = keys.secretKey;
|
|
42390
|
+
publicKeyHash = HASH256(publicKey);
|
|
42391
|
+
const secretKey = secretCoder.encode([sk, publicKey, publicKeyHash, s2.subarray(32)]);
|
|
42392
|
+
return {
|
|
42393
|
+
publicKey,
|
|
42394
|
+
secretKey
|
|
42395
|
+
};
|
|
42396
|
+
} finally {
|
|
42397
|
+
if (sk !== void 0)
|
|
42398
|
+
cleanBytes(sk);
|
|
42399
|
+
if (publicKeyHash !== void 0)
|
|
42400
|
+
cleanBytes(publicKeyHash);
|
|
42401
|
+
if (ownSeed)
|
|
42402
|
+
cleanBytes(s2);
|
|
42403
|
+
}
|
|
41983
42404
|
},
|
|
41984
42405
|
getPublicKey: (secretKey) => {
|
|
41985
42406
|
const [_sk, publicKey, _publicKeyHash, _z] = secretCoder.decode(secretKey);
|
|
41986
42407
|
return Uint8Array.from(publicKey);
|
|
41987
42408
|
},
|
|
41988
|
-
encapsulate: (publicKey, msg
|
|
41989
|
-
|
|
41990
|
-
|
|
41991
|
-
|
|
41992
|
-
|
|
41993
|
-
|
|
41994
|
-
|
|
41995
|
-
|
|
41996
|
-
|
|
41997
|
-
|
|
41998
|
-
|
|
41999
|
-
|
|
42000
|
-
|
|
42001
|
-
|
|
42409
|
+
encapsulate: (publicKey, msg) => {
|
|
42410
|
+
const ownMsg = msg === void 0;
|
|
42411
|
+
const m2 = ownMsg ? randomBytes2(msgLen) : msg;
|
|
42412
|
+
let kr;
|
|
42413
|
+
try {
|
|
42414
|
+
abytesDoc(publicKey, lengths.publicKey, "publicKey");
|
|
42415
|
+
abytesDoc(m2, msgLen, "message");
|
|
42416
|
+
validateModulus(publicKey, "encapsulate");
|
|
42417
|
+
kr = HASH512.create().update(m2).update(HASH256(publicKey)).digest();
|
|
42418
|
+
const cipherText = KPKE.encrypt(publicKey, m2, kr.subarray(32, 64));
|
|
42419
|
+
return {
|
|
42420
|
+
cipherText,
|
|
42421
|
+
sharedSecret: kr.subarray(0, 32)
|
|
42422
|
+
};
|
|
42423
|
+
} finally {
|
|
42424
|
+
if (kr !== void 0)
|
|
42425
|
+
cleanBytes(kr.subarray(32));
|
|
42426
|
+
if (ownMsg)
|
|
42427
|
+
cleanBytes(m2);
|
|
42428
|
+
}
|
|
42002
42429
|
},
|
|
42003
42430
|
decapsulate: (cipherText, secretKey) => {
|
|
42004
|
-
|
|
42005
|
-
|
|
42431
|
+
abytesDoc(secretKey, secretCoder.bytesLen, "secretKey");
|
|
42432
|
+
abytesDoc(cipherText, lengths.cipherText, "cipherText");
|
|
42006
42433
|
const k768 = secretCoder.bytesLen - 96;
|
|
42007
42434
|
const start2 = k768 + 32;
|
|
42008
42435
|
const test = HASH256(secretKey.subarray(k768 / 2, start2));
|
|
@@ -42015,25 +42442,76 @@ ${operationTypes.join("\n")}
|
|
|
42015
42442
|
const cipherText2 = KPKE.encrypt(publicKey, msg, kr.subarray(32, 64));
|
|
42016
42443
|
const isValid = equalBytes(cipherText, cipherText2);
|
|
42017
42444
|
const Kbar = KDF.create({ dkLen: 32 }).update(z3).update(cipherText).digest();
|
|
42018
|
-
cleanBytes(msg, cipherText2, !isValid ? Khat : Kbar);
|
|
42445
|
+
cleanBytes(msg, cipherText2, kr.subarray(32), !isValid ? Khat : Kbar);
|
|
42019
42446
|
return isValid ? Khat : Kbar;
|
|
42447
|
+
},
|
|
42448
|
+
/**
|
|
42449
|
+
* Experimental prototype: pre-expand a public key so repeated encapsulate/decapsulate
|
|
42450
|
+
* against the same key skip re-validation, H(ek), t̂ decoding and the K² SampleNTT
|
|
42451
|
+
* XOF expansions of Â. Only public data is cached; see {@link KEMPrepared}.
|
|
42452
|
+
*/
|
|
42453
|
+
prepare: (publicKey) => {
|
|
42454
|
+
abytesDoc(publicKey, lengths.publicKey, "publicKey");
|
|
42455
|
+
validateModulus(publicKey, "prepare");
|
|
42456
|
+
const ek = copyBytes(publicKey);
|
|
42457
|
+
const publicKeyHash = HASH256(ek);
|
|
42458
|
+
const cached2 = KPKE.prepare(ek);
|
|
42459
|
+
return Object.freeze({
|
|
42460
|
+
publicKey: ek,
|
|
42461
|
+
encapsulate: (msg) => {
|
|
42462
|
+
const ownMsg = msg === void 0;
|
|
42463
|
+
const m2 = ownMsg ? randomBytes2(msgLen) : msg;
|
|
42464
|
+
let kr;
|
|
42465
|
+
try {
|
|
42466
|
+
abytesDoc(m2, msgLen, "message");
|
|
42467
|
+
kr = HASH512.create().update(m2).update(publicKeyHash).digest();
|
|
42468
|
+
const cipherText = cached2.encrypt(m2, kr.subarray(32, 64));
|
|
42469
|
+
return {
|
|
42470
|
+
cipherText,
|
|
42471
|
+
sharedSecret: kr.subarray(0, 32)
|
|
42472
|
+
};
|
|
42473
|
+
} finally {
|
|
42474
|
+
if (kr !== void 0)
|
|
42475
|
+
cleanBytes(kr.subarray(32));
|
|
42476
|
+
if (ownMsg)
|
|
42477
|
+
cleanBytes(m2);
|
|
42478
|
+
}
|
|
42479
|
+
},
|
|
42480
|
+
decapsulate: (cipherText, secretKey) => {
|
|
42481
|
+
abytesDoc(secretKey, secretCoder.bytesLen, "secretKey");
|
|
42482
|
+
abytesDoc(cipherText, lengths.cipherText, "cipherText");
|
|
42483
|
+
const [sk, ekEmbedded, storedHash, z3] = secretCoder.decode(secretKey);
|
|
42484
|
+
if (!equalBytes(ekEmbedded, ek) || !equalBytes(storedHash, publicKeyHash))
|
|
42485
|
+
throw new Error("ML-KEM.decapsulate: secretKey does not match prepared publicKey");
|
|
42486
|
+
const msg = KPKE.decrypt(cipherText, sk);
|
|
42487
|
+
const kr = HASH512.create().update(msg).update(publicKeyHash).digest();
|
|
42488
|
+
const Khat = kr.subarray(0, 32);
|
|
42489
|
+
const cipherText2 = cached2.encrypt(msg, kr.subarray(32, 64));
|
|
42490
|
+
const isValid = equalBytes(cipherText, cipherText2);
|
|
42491
|
+
const Kbar = KDF.create({ dkLen: 32 }).update(z3).update(cipherText).digest();
|
|
42492
|
+
cleanBytes(msg, cipherText2, kr.subarray(32), !isValid ? Khat : Kbar);
|
|
42493
|
+
return isValid ? Khat : Kbar;
|
|
42494
|
+
},
|
|
42495
|
+
clean: cached2.clean
|
|
42496
|
+
});
|
|
42020
42497
|
}
|
|
42021
|
-
};
|
|
42498
|
+
});
|
|
42022
42499
|
}
|
|
42023
42500
|
function shakePRF(dkLen, key, nonce) {
|
|
42024
42501
|
return shake2562.create({ dkLen }).update(key).update(new Uint8Array([nonce])).digest();
|
|
42025
42502
|
}
|
|
42026
|
-
var opts = {
|
|
42503
|
+
var opts = /* @__PURE__ */ (() => ({
|
|
42027
42504
|
HASH256: sha3_256,
|
|
42028
42505
|
HASH512: sha3_512,
|
|
42029
42506
|
KDF: shake2562,
|
|
42030
42507
|
XOF: XOF128,
|
|
42031
42508
|
PRF: shakePRF
|
|
42032
|
-
};
|
|
42033
|
-
var
|
|
42509
|
+
}))();
|
|
42510
|
+
var mk = (params) => createKyber({
|
|
42034
42511
|
...opts,
|
|
42035
|
-
...
|
|
42512
|
+
...params
|
|
42036
42513
|
});
|
|
42514
|
+
var ml_kem768 = /* @__PURE__ */ (() => mk(PARAMS[768]))();
|
|
42037
42515
|
|
|
42038
42516
|
// src/core/Wallet.ts
|
|
42039
42517
|
var Wallet = class _Wallet {
|
|
@@ -42176,11 +42654,13 @@ ${operationTypes.join("\n")}
|
|
|
42176
42654
|
return typeof maybeBundleHash === "string" && isBundleHash(maybeBundleHash);
|
|
42177
42655
|
}
|
|
42178
42656
|
/**
|
|
42179
|
-
*
|
|
42180
|
-
*
|
|
42657
|
+
* Map raw token-unit tuples to TokenUnit instances.
|
|
42658
|
+
* Matches JS SDK Wallet.getTokenUnits (Wallet.js:190-196). The serialised shape reaches hashed
|
|
42659
|
+
* atom meta via AtomMeta.setAtomWallet -> JSON.stringify(getTokenUnitsData()), so returning raw
|
|
42660
|
+
* tuples here would diverge from every other SDK.
|
|
42181
42661
|
*/
|
|
42182
42662
|
static getTokenUnits(unitsData) {
|
|
42183
|
-
return unitsData;
|
|
42663
|
+
return unitsData.map((unitData) => TokenUnit.createFromDB(unitData));
|
|
42184
42664
|
}
|
|
42185
42665
|
/**
|
|
42186
42666
|
* Create a remainder wallet for transactions
|
|
@@ -42480,7 +42960,7 @@ ${operationTypes.join("\n")}
|
|
|
42480
42960
|
var TokenSlugSchema = external_exports.string().min(1, "Token slug cannot be empty").max(64, "Token slug cannot exceed 64 characters").transform((val) => val.toUpperCase()).brand();
|
|
42481
42961
|
var MetaTypeSchema = external_exports.string().min(1, "Meta type cannot be empty").max(256, "Meta type cannot exceed 256 characters").brand();
|
|
42482
42962
|
var MetaIdSchema = external_exports.string().min(1, "Meta ID cannot be empty").brand();
|
|
42483
|
-
var BatchIdSchema = external_exports.string().
|
|
42963
|
+
var BatchIdSchema = external_exports.string().regex(/^[0-9a-fA-F]{64}$/, "Batch ID must be 64 hexadecimal characters").brand();
|
|
42484
42964
|
var CellSlugSchema = external_exports.string().min(1, "Cell slug cannot be empty").max(64, "Cell slug cannot exceed 64 characters").brand();
|
|
42485
42965
|
var AtomIsotopeSchema = external_exports.enum(["C", "V", "U", "T", "M", "I", "R", "B", "F"], {
|
|
42486
42966
|
error: "Invalid atom isotope. Must be one of: C, V, U, T, M, I, R, B, F"
|
|
@@ -42804,58 +43284,6 @@ ${operationTypes.join("\n")}
|
|
|
42804
43284
|
};
|
|
42805
43285
|
var RuleArgumentException_default = RuleArgumentException;
|
|
42806
43286
|
|
|
42807
|
-
// src/libraries/array.ts
|
|
42808
|
-
function deepCloning(o3, h3) {
|
|
42809
|
-
let i4;
|
|
42810
|
-
let r3;
|
|
42811
|
-
let x2;
|
|
42812
|
-
const t3 = [Array, Date, Number, String, Boolean];
|
|
42813
|
-
const s2 = Object.prototype.toString;
|
|
42814
|
-
h3 = h3 || [];
|
|
42815
|
-
for (i4 = 0; i4 < h3.length; i4 += 2) {
|
|
42816
|
-
if (o3 === h3[i4]) {
|
|
42817
|
-
return h3[i4 + 1];
|
|
42818
|
-
}
|
|
42819
|
-
}
|
|
42820
|
-
if (!r3 && o3 && typeof o3 === "object") {
|
|
42821
|
-
r3 = {};
|
|
42822
|
-
for (i4 = 0; i4 < t3.length; i4++) {
|
|
42823
|
-
if (s2.call(o3) === s2.call(x2 = new t3[i4](o3))) {
|
|
42824
|
-
r3 = i4 ? x2 : [];
|
|
42825
|
-
}
|
|
42826
|
-
}
|
|
42827
|
-
h3.push(o3, r3);
|
|
42828
|
-
for (i4 in o3) {
|
|
42829
|
-
if (Object.prototype.hasOwnProperty.call(o3, i4)) {
|
|
42830
|
-
r3[i4] = deepCloning(o3[i4], h3);
|
|
42831
|
-
}
|
|
42832
|
-
}
|
|
42833
|
-
}
|
|
42834
|
-
return r3 || o3;
|
|
42835
|
-
}
|
|
42836
|
-
function chunkArray(arr, size) {
|
|
42837
|
-
const chunks = [];
|
|
42838
|
-
for (let i4 = 0; i4 < arr.length; i4 += size) {
|
|
42839
|
-
chunks.push(arr.slice(i4, i4 + size));
|
|
42840
|
-
}
|
|
42841
|
-
return chunks;
|
|
42842
|
-
}
|
|
42843
|
-
function diff(...arrays) {
|
|
42844
|
-
return [].concat(...arrays.map((arr, i4) => {
|
|
42845
|
-
const others = arrays.slice(0);
|
|
42846
|
-
others.splice(i4, 1);
|
|
42847
|
-
const unique = [...new Set([].concat(...others))];
|
|
42848
|
-
return arr.filter((item) => !unique.includes(item));
|
|
42849
|
-
}));
|
|
42850
|
-
}
|
|
42851
|
-
function intersect(...arrays) {
|
|
42852
|
-
if (arrays.length === 0) return [];
|
|
42853
|
-
if (arrays.length === 1) return arrays[0];
|
|
42854
|
-
return arrays.reduce(
|
|
42855
|
-
(first, second) => first.filter((item) => second.includes(item))
|
|
42856
|
-
);
|
|
42857
|
-
}
|
|
42858
|
-
|
|
42859
43287
|
// src/instance/rules/Callback.ts
|
|
42860
43288
|
init_exception();
|
|
42861
43289
|
init_zod();
|
|
@@ -44187,6 +44615,51 @@ ${operationTypes.join("\n")}
|
|
|
44187
44615
|
}));
|
|
44188
44616
|
return this;
|
|
44189
44617
|
}
|
|
44618
|
+
/**
|
|
44619
|
+
* Replenishes non-finite token supplies.
|
|
44620
|
+
* Matches JS SDK Molecule.replenishToken (Molecule.js:521-566) exactly.
|
|
44621
|
+
*
|
|
44622
|
+
* Two orderings here are load-bearing for the molecular hash and must not be reordered:
|
|
44623
|
+
* the remainder balance is computed BEFORE the source balance is overwritten, and the
|
|
44624
|
+
* source V-atom is added BEFORE the remainder V-atom.
|
|
44625
|
+
*/
|
|
44626
|
+
replenishToken({
|
|
44627
|
+
amount,
|
|
44628
|
+
units = []
|
|
44629
|
+
}) {
|
|
44630
|
+
if (amount < 0) {
|
|
44631
|
+
throw new NegativeAmountException("Molecule::replenishToken() - Amount to replenish must be positive!");
|
|
44632
|
+
}
|
|
44633
|
+
if (!this.sourceWallet || !this.remainderWallet) {
|
|
44634
|
+
throw new Error("Source and remainder wallets required for token replenishment");
|
|
44635
|
+
}
|
|
44636
|
+
if (units.length) {
|
|
44637
|
+
const formatted = Wallet.getTokenUnits(units);
|
|
44638
|
+
this.remainderWallet.tokenUnits = this.sourceWallet.tokenUnits;
|
|
44639
|
+
for (const unit of formatted) {
|
|
44640
|
+
this.remainderWallet.tokenUnits.push(unit);
|
|
44641
|
+
}
|
|
44642
|
+
this.remainderWallet.balance = String(this.remainderWallet.tokenUnits.length);
|
|
44643
|
+
this.sourceWallet.tokenUnits = formatted;
|
|
44644
|
+
this.sourceWallet.balance = String(this.sourceWallet.tokenUnits.length);
|
|
44645
|
+
} else {
|
|
44646
|
+
this.remainderWallet.balance = String(Number(this.sourceWallet.balance) + amount);
|
|
44647
|
+
this.sourceWallet.balance = String(amount);
|
|
44648
|
+
}
|
|
44649
|
+
this.addAtom(Atom.create({
|
|
44650
|
+
isotope: "V",
|
|
44651
|
+
wallet: this.sourceWallet,
|
|
44652
|
+
value: Number(this.sourceWallet.balance)
|
|
44653
|
+
}));
|
|
44654
|
+
this.addAtom(Atom.create({
|
|
44655
|
+
isotope: "V",
|
|
44656
|
+
wallet: this.remainderWallet,
|
|
44657
|
+
value: Number(this.remainderWallet.balance),
|
|
44658
|
+
metaType: "walletBundle",
|
|
44659
|
+
metaId: this.remainderWallet.bundle
|
|
44660
|
+
}));
|
|
44661
|
+
return this;
|
|
44662
|
+
}
|
|
44190
44663
|
/**
|
|
44191
44664
|
* Initialize authorization request
|
|
44192
44665
|
* Creates U-isotope (authorization) atom for requesting auth token
|
|
@@ -46130,21 +46603,22 @@ ${operationTypes.join("\n")}
|
|
|
46130
46603
|
}
|
|
46131
46604
|
};
|
|
46132
46605
|
var makeResult = (e4, r3, t3) => {
|
|
46133
|
-
|
|
46606
|
+
var a3 = r3.payload || r3;
|
|
46607
|
+
if (!("data" in a3 || "errors" in a3 && Array.isArray(a3.errors))) {
|
|
46134
46608
|
throw new Error("No Content");
|
|
46135
46609
|
}
|
|
46136
|
-
var
|
|
46610
|
+
var n3 = "subscription" === e4.kind;
|
|
46137
46611
|
return {
|
|
46138
46612
|
operation: e4,
|
|
46139
|
-
data:
|
|
46140
|
-
error: Array.isArray(
|
|
46141
|
-
graphQLErrors:
|
|
46613
|
+
data: a3.data,
|
|
46614
|
+
error: Array.isArray(a3.errors) ? new CombinedError({
|
|
46615
|
+
graphQLErrors: a3.errors,
|
|
46142
46616
|
response: t3
|
|
46143
46617
|
}) : void 0,
|
|
46144
|
-
extensions:
|
|
46145
|
-
...
|
|
46618
|
+
extensions: a3.extensions ? {
|
|
46619
|
+
...a3.extensions
|
|
46146
46620
|
} : void 0,
|
|
46147
|
-
hasNext: null == r3.hasNext ?
|
|
46621
|
+
hasNext: null == r3.hasNext ? n3 : r3.hasNext,
|
|
46148
46622
|
stale: false
|
|
46149
46623
|
};
|
|
46150
46624
|
};
|
|
@@ -46537,14 +47011,14 @@ ${operationTypes.join("\n")}
|
|
|
46537
47011
|
var o3 = [];
|
|
46538
47012
|
var s2 = {};
|
|
46539
47013
|
for (var c3 = 0, u4 = r3.directives.length; c3 < u4; c3++) {
|
|
46540
|
-
var
|
|
46541
|
-
var
|
|
46542
|
-
if ("_" !==
|
|
46543
|
-
o3.push(
|
|
47014
|
+
var d4 = r3.directives[c3];
|
|
47015
|
+
var p3 = d4.name.value;
|
|
47016
|
+
if ("_" !== p3[0]) {
|
|
47017
|
+
o3.push(d4);
|
|
46544
47018
|
} else {
|
|
46545
|
-
|
|
47019
|
+
p3 = p3.slice(1);
|
|
46546
47020
|
}
|
|
46547
|
-
s2[
|
|
47021
|
+
s2[p3] = d4;
|
|
46548
47022
|
}
|
|
46549
47023
|
r3 = {
|
|
46550
47024
|
...r3,
|
|
@@ -46553,17 +47027,17 @@ ${operationTypes.join("\n")}
|
|
|
46553
47027
|
};
|
|
46554
47028
|
}
|
|
46555
47029
|
if ("selectionSet" in r3) {
|
|
46556
|
-
var
|
|
46557
|
-
var
|
|
47030
|
+
var l3 = [];
|
|
47031
|
+
var v3 = r3.kind === e2.OPERATION_DEFINITION;
|
|
46558
47032
|
if (r3.selectionSet) {
|
|
46559
47033
|
for (var f3 = 0, h3 = r3.selectionSet.selections.length; f3 < h3; f3++) {
|
|
46560
47034
|
var k2 = r3.selectionSet.selections[f3];
|
|
46561
|
-
|
|
47035
|
+
v3 = v3 || k2.kind === e2.FIELD && "__typename" === k2.name.value && !k2.alias;
|
|
46562
47036
|
var y3 = formatNode(k2);
|
|
46563
|
-
|
|
47037
|
+
l3.push(y3);
|
|
46564
47038
|
}
|
|
46565
|
-
if (!
|
|
46566
|
-
|
|
47039
|
+
if (!v3) {
|
|
47040
|
+
l3.push({
|
|
46567
47041
|
kind: e2.FIELD,
|
|
46568
47042
|
name: {
|
|
46569
47043
|
kind: e2.NAME,
|
|
@@ -46576,7 +47050,7 @@ ${operationTypes.join("\n")}
|
|
|
46576
47050
|
...r3,
|
|
46577
47051
|
selectionSet: {
|
|
46578
47052
|
...r3.selectionSet,
|
|
46579
|
-
selections:
|
|
47053
|
+
selections: l3
|
|
46580
47054
|
}
|
|
46581
47055
|
};
|
|
46582
47056
|
}
|
|
@@ -46636,20 +47110,20 @@ ${operationTypes.join("\n")}
|
|
|
46636
47110
|
s2 += arguments[0][c3];
|
|
46637
47111
|
}
|
|
46638
47112
|
o3.unshift(keyDocument(s2));
|
|
46639
|
-
for (var
|
|
46640
|
-
for (var
|
|
46641
|
-
var
|
|
46642
|
-
if (
|
|
46643
|
-
var
|
|
46644
|
-
var f3 = stringifyDocument(
|
|
46645
|
-
if (!a3.has(
|
|
46646
|
-
a3.set(
|
|
46647
|
-
i4.push(
|
|
46648
|
-
} else if (a3.get(
|
|
46649
|
-
console.warn("[WARNING: Duplicate Fragment] A fragment with name `" +
|
|
47113
|
+
for (var d4 = 0; d4 < o3.length; d4++) {
|
|
47114
|
+
for (var p3 = 0; p3 < o3[d4].definitions.length; p3++) {
|
|
47115
|
+
var l3 = o3[d4].definitions[p3];
|
|
47116
|
+
if (l3.kind === e2.FRAGMENT_DEFINITION) {
|
|
47117
|
+
var v3 = l3.name.value;
|
|
47118
|
+
var f3 = stringifyDocument(l3);
|
|
47119
|
+
if (!a3.has(v3)) {
|
|
47120
|
+
a3.set(v3, f3);
|
|
47121
|
+
i4.push(l3);
|
|
47122
|
+
} else if (a3.get(v3) !== f3) {
|
|
47123
|
+
console.warn("[WARNING: Duplicate Fragment] A fragment with name `" + v3 + "` already exists in this document.\nWhile fragment names may not be unique across your source, each name must be unique per document.");
|
|
46650
47124
|
}
|
|
46651
47125
|
} else {
|
|
46652
|
-
i4.push(
|
|
47126
|
+
i4.push(l3);
|
|
46653
47127
|
}
|
|
46654
47128
|
}
|
|
46655
47129
|
}
|
|
@@ -46725,26 +47199,26 @@ ${operationTypes.join("\n")}
|
|
|
46725
47199
|
});
|
|
46726
47200
|
for (var c4 = 0; c4 < o4.length; c4++) {
|
|
46727
47201
|
var u4 = o4[c4];
|
|
46728
|
-
var
|
|
46729
|
-
if (!
|
|
46730
|
-
i4.set(u4,
|
|
47202
|
+
var d4 = i4.get(u4);
|
|
47203
|
+
if (!d4) {
|
|
47204
|
+
i4.set(u4, d4 = /* @__PURE__ */ new Set());
|
|
46731
47205
|
}
|
|
46732
|
-
for (var
|
|
46733
|
-
s3.add(
|
|
47206
|
+
for (var p3 of d4.values()) {
|
|
47207
|
+
s3.add(p3);
|
|
46734
47208
|
}
|
|
46735
|
-
|
|
47209
|
+
d4.clear();
|
|
46736
47210
|
}
|
|
46737
|
-
for (var
|
|
46738
|
-
if (a3.has(
|
|
46739
|
-
n3 = a3.get(
|
|
46740
|
-
a3.delete(
|
|
47211
|
+
for (var l3 of s3.values()) {
|
|
47212
|
+
if (a3.has(l3)) {
|
|
47213
|
+
n3 = a3.get(l3).operation;
|
|
47214
|
+
a3.delete(l3);
|
|
46741
47215
|
reexecuteOperation(r3, n3);
|
|
46742
47216
|
}
|
|
46743
47217
|
}
|
|
46744
47218
|
} else if ("query" === n3.kind && e5.data) {
|
|
46745
47219
|
a3.set(n3.key, e5);
|
|
46746
|
-
for (var
|
|
46747
|
-
var f3 = o4[
|
|
47220
|
+
for (var v3 = 0; v3 < o4.length; v3++) {
|
|
47221
|
+
var f3 = o4[v3];
|
|
46748
47222
|
var h3 = i4.get(f3);
|
|
46749
47223
|
if (!h3) {
|
|
46750
47224
|
i4.set(f3, h3 = /* @__PURE__ */ new Set());
|
|
@@ -46795,13 +47269,12 @@ ${operationTypes.join("\n")}
|
|
|
46795
47269
|
complete() {
|
|
46796
47270
|
if (!i6) {
|
|
46797
47271
|
i6 = true;
|
|
46798
|
-
if ("subscription" === r5.kind) {
|
|
46799
|
-
a3.reexecuteOperation(makeOperation("teardown", r5, r5.context));
|
|
46800
|
-
}
|
|
46801
47272
|
if (u6 && u6.hasNext) {
|
|
46802
47273
|
nextResult({
|
|
46803
47274
|
hasNext: false
|
|
46804
47275
|
});
|
|
47276
|
+
} else if ("subscription" === r5.kind) {
|
|
47277
|
+
a3.reexecuteOperation(makeOperation("teardown", r5, r5.context));
|
|
46805
47278
|
}
|
|
46806
47279
|
e5.complete();
|
|
46807
47280
|
}
|
|
@@ -46817,8 +47290,8 @@ ${operationTypes.join("\n")}
|
|
|
46817
47290
|
}));
|
|
46818
47291
|
})(t5));
|
|
46819
47292
|
}))(filter(((e5) => "teardown" !== e5.kind && u4(e5)))(r4));
|
|
46820
|
-
var
|
|
46821
|
-
return merge2([t4,
|
|
47293
|
+
var d4 = i4(filter(((e5) => "teardown" === e5.kind || !u4(e5)))(r4));
|
|
47294
|
+
return merge2([t4, d4]);
|
|
46822
47295
|
};
|
|
46823
47296
|
};
|
|
46824
47297
|
var fetchExchange = ({ forward: e4, dispatchDebug: r3 }) => (t3) => {
|
|
@@ -46910,7 +47383,7 @@ ${operationTypes.join("\n")}
|
|
|
46910
47383
|
fetchSubscriptions: e4.fetchSubscriptions,
|
|
46911
47384
|
fetchOptions: e4.fetchOptions,
|
|
46912
47385
|
fetch: e4.fetch,
|
|
46913
|
-
preferGetMethod: e4.preferGetMethod,
|
|
47386
|
+
preferGetMethod: null != e4.preferGetMethod ? e4.preferGetMethod : "within-url-limit",
|
|
46914
47387
|
requestPolicy: e4.requestPolicy || "cache-first"
|
|
46915
47388
|
};
|
|
46916
47389
|
var s2 = makeSubject();
|
|
@@ -46988,7 +47461,7 @@ ${operationTypes.join("\n")}
|
|
|
46988
47461
|
return share(r4);
|
|
46989
47462
|
};
|
|
46990
47463
|
var u4 = this instanceof Client ? this : Object.create(Client.prototype);
|
|
46991
|
-
var
|
|
47464
|
+
var d4 = Object.assign(u4, {
|
|
46992
47465
|
suspense: !!e4.suspense,
|
|
46993
47466
|
operations$: s2.source,
|
|
46994
47467
|
reexecuteOperation(e5) {
|
|
@@ -47027,7 +47500,7 @@ ${operationTypes.join("\n")}
|
|
|
47027
47500
|
...o3,
|
|
47028
47501
|
...n4,
|
|
47029
47502
|
requestPolicy: n4.requestPolicy || o3.requestPolicy,
|
|
47030
|
-
suspense: n4.suspense || false !== n4.suspense &&
|
|
47503
|
+
suspense: n4.suspense || false !== n4.suspense && d4.suspense
|
|
47031
47504
|
});
|
|
47032
47505
|
},
|
|
47033
47506
|
executeRequestOperation(e5) {
|
|
@@ -47051,44 +47524,44 @@ ${operationTypes.join("\n")}
|
|
|
47051
47524
|
})));
|
|
47052
47525
|
},
|
|
47053
47526
|
executeQuery(e5, r4) {
|
|
47054
|
-
var t4 =
|
|
47055
|
-
return
|
|
47527
|
+
var t4 = d4.createRequestOperation("query", e5, r4);
|
|
47528
|
+
return d4.executeRequestOperation(t4);
|
|
47056
47529
|
},
|
|
47057
47530
|
executeSubscription(e5, r4) {
|
|
47058
|
-
var t4 =
|
|
47059
|
-
return
|
|
47531
|
+
var t4 = d4.createRequestOperation("subscription", e5, r4);
|
|
47532
|
+
return d4.executeRequestOperation(t4);
|
|
47060
47533
|
},
|
|
47061
47534
|
executeMutation(e5, r4) {
|
|
47062
|
-
var t4 =
|
|
47063
|
-
return
|
|
47535
|
+
var t4 = d4.createRequestOperation("mutation", e5, r4);
|
|
47536
|
+
return d4.executeRequestOperation(t4);
|
|
47064
47537
|
},
|
|
47065
47538
|
readQuery(e5, r4, t4) {
|
|
47066
47539
|
var n4 = null;
|
|
47067
47540
|
subscribe(((e6) => {
|
|
47068
47541
|
n4 = e6;
|
|
47069
|
-
}))(
|
|
47542
|
+
}))(d4.query(e5, r4, t4)).unsubscribe();
|
|
47070
47543
|
return n4;
|
|
47071
47544
|
},
|
|
47072
|
-
query: (e5, r4, t4) =>
|
|
47073
|
-
subscription: (e5, r4, t4) =>
|
|
47074
|
-
mutation: (e5, r4, t4) =>
|
|
47545
|
+
query: (e5, r4, t4) => d4.executeQuery(createRequest(e5, r4), t4),
|
|
47546
|
+
subscription: (e5, r4, t4) => d4.executeSubscription(createRequest(e5, r4), t4),
|
|
47547
|
+
mutation: (e5, r4, t4) => d4.executeMutation(createRequest(e5, r4), t4)
|
|
47075
47548
|
});
|
|
47076
|
-
var
|
|
47549
|
+
var p3 = noop;
|
|
47077
47550
|
{
|
|
47078
47551
|
var { next: f3, source: x2 } = makeSubject();
|
|
47079
|
-
|
|
47080
|
-
|
|
47552
|
+
d4.subscribeToDebugTarget = (e5) => subscribe(e5)(x2);
|
|
47553
|
+
p3 = f3;
|
|
47081
47554
|
}
|
|
47082
47555
|
var w2 = composeExchanges(e4.exchanges);
|
|
47083
47556
|
var E2 = share(w2({
|
|
47084
|
-
client:
|
|
47085
|
-
dispatchDebug:
|
|
47557
|
+
client: d4,
|
|
47558
|
+
dispatchDebug: p3,
|
|
47086
47559
|
forward: fallbackExchange({
|
|
47087
|
-
dispatchDebug:
|
|
47560
|
+
dispatchDebug: p3
|
|
47088
47561
|
})
|
|
47089
47562
|
})(s2.source));
|
|
47090
47563
|
publish(E2);
|
|
47091
|
-
return
|
|
47564
|
+
return d4;
|
|
47092
47565
|
};
|
|
47093
47566
|
var Q3 = C2;
|
|
47094
47567
|
|
|
@@ -47147,16 +47620,27 @@ ${operationTypes.join("\n")}
|
|
|
47147
47620
|
return Q3({
|
|
47148
47621
|
url: serverUri,
|
|
47149
47622
|
exchanges,
|
|
47150
|
-
//
|
|
47151
|
-
//
|
|
47152
|
-
//
|
|
47153
|
-
|
|
47623
|
+
// urql 5 had no default and always POSTed; urql 6 defaults to 'within-url-limit', which
|
|
47624
|
+
// URL-encodes short queries and sends NO body. That would silently disable the CipherHash
|
|
47625
|
+
// envelope below — cipherFetch's `typeof init.body === 'string'` guard fails on a GET, so
|
|
47626
|
+
// the query would leave as plaintext URL parameters with no error. Pin POST explicitly.
|
|
47627
|
+
preferGetMethod: false,
|
|
47628
|
+
// Always route through our own fetch. Two reasons: (1) PQ-transport Phase E — when
|
|
47629
|
+
// encryption is on, cipherFetch wraps the request body in the CipherHash envelope and
|
|
47630
|
+
// decrypts the response; (2) the 60s timeout. urql's makeFetchSource unconditionally
|
|
47631
|
+
// overwrites init.signal with its own AbortController, so a signal returned from
|
|
47632
|
+
// fetchOptions() is discarded and never fired. Combining it here is the only place it
|
|
47633
|
+
// survives.
|
|
47634
|
+
fetch: ((input2, init) => {
|
|
47635
|
+
const timeoutSignal = AbortSignal.timeout(6e4);
|
|
47636
|
+
const signal = init?.signal && typeof AbortSignal.any === "function" ? AbortSignal.any([init.signal, timeoutSignal]) : init?.signal ?? timeoutSignal;
|
|
47637
|
+
const timedInit = { ...init, signal };
|
|
47638
|
+
return this.cipherLink ? this.cipherFetch(input2, timedInit) : fetch(input2, timedInit);
|
|
47639
|
+
}),
|
|
47154
47640
|
fetchOptions: () => ({
|
|
47155
47641
|
headers: {
|
|
47156
47642
|
"X-Auth-Token": this.$__authToken
|
|
47157
|
-
}
|
|
47158
|
-
// Add 60 second timeout
|
|
47159
|
-
signal: AbortSignal.timeout(6e4)
|
|
47643
|
+
}
|
|
47160
47644
|
})
|
|
47161
47645
|
});
|
|
47162
47646
|
}
|
|
@@ -47672,12 +48156,12 @@ ${operationTypes.join("\n")}
|
|
|
47672
48156
|
);
|
|
47673
48157
|
var BatchIdSchema2 = createBrandedSchema(
|
|
47674
48158
|
"BatchId",
|
|
47675
|
-
//
|
|
47676
|
-
//
|
|
47677
|
-
|
|
47678
|
-
|
|
47679
|
-
|
|
47680
|
-
)
|
|
48159
|
+
// 64 hex characters. generateBatchId (src/libraries/crypto.ts) returns either
|
|
48160
|
+
// shake256(molecularHash + index, 256) — 256 bits, 64 hex chars — or randomString(64) over the
|
|
48161
|
+
// alphabet 'abcdef0123456789'. A UUID shape matches nothing this SDK can produce, so the
|
|
48162
|
+
// previous 8-4-4-4-12 regex rejected every real batch ID. Agrees with isBatchId in
|
|
48163
|
+
// src/types/guards.ts.
|
|
48164
|
+
external_exports.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid batch ID format")
|
|
47681
48165
|
);
|
|
47682
48166
|
var CellSlugSchema2 = createBrandedSchema(
|
|
47683
48167
|
"CellSlug",
|
|
@@ -48580,89 +49064,6 @@ ${operationTypes.join("\n")}
|
|
|
48580
49064
|
|
|
48581
49065
|
// src/response/ResponseBalance.ts
|
|
48582
49066
|
init_Response();
|
|
48583
|
-
|
|
48584
|
-
// src/core/TokenUnit.ts
|
|
48585
|
-
var TokenUnit = class _TokenUnit {
|
|
48586
|
-
id;
|
|
48587
|
-
name;
|
|
48588
|
-
metas;
|
|
48589
|
-
/**
|
|
48590
|
-
* Create new TokenUnit instance
|
|
48591
|
-
* Matches JavaScript SDK constructor signature exactly
|
|
48592
|
-
*/
|
|
48593
|
-
constructor(id, name2, metas) {
|
|
48594
|
-
this.id = id;
|
|
48595
|
-
this.name = name2;
|
|
48596
|
-
this.metas = metas || {};
|
|
48597
|
-
}
|
|
48598
|
-
/**
|
|
48599
|
-
* Create TokenUnit from GraphQL response data
|
|
48600
|
-
* Matches JavaScript SDK createFromGraphQL method exactly
|
|
48601
|
-
*/
|
|
48602
|
-
static createFromGraphQL(data) {
|
|
48603
|
-
let metas = data.metas || {};
|
|
48604
|
-
if (Array.isArray(metas) && metas.length) {
|
|
48605
|
-
try {
|
|
48606
|
-
metas = JSON.parse(metas);
|
|
48607
|
-
if (!metas) {
|
|
48608
|
-
metas = {};
|
|
48609
|
-
}
|
|
48610
|
-
} catch (error62) {
|
|
48611
|
-
metas = {};
|
|
48612
|
-
}
|
|
48613
|
-
}
|
|
48614
|
-
return new _TokenUnit(
|
|
48615
|
-
data.id,
|
|
48616
|
-
data.name,
|
|
48617
|
-
metas
|
|
48618
|
-
);
|
|
48619
|
-
}
|
|
48620
|
-
/**
|
|
48621
|
-
* Create TokenUnit from database array data
|
|
48622
|
-
* Matches JavaScript SDK createFromDB method exactly
|
|
48623
|
-
*/
|
|
48624
|
-
static createFromDB(data) {
|
|
48625
|
-
return new _TokenUnit(
|
|
48626
|
-
data[0],
|
|
48627
|
-
data[1],
|
|
48628
|
-
data.length > 2 ? data[2] : {}
|
|
48629
|
-
);
|
|
48630
|
-
}
|
|
48631
|
-
/**
|
|
48632
|
-
* Get fragment zone from metadata
|
|
48633
|
-
* Matches JavaScript SDK getFragmentZone method exactly
|
|
48634
|
-
*/
|
|
48635
|
-
getFragmentZone() {
|
|
48636
|
-
return this.metas.fragmentZone || null;
|
|
48637
|
-
}
|
|
48638
|
-
/**
|
|
48639
|
-
* Get fused token units from metadata
|
|
48640
|
-
* Matches JavaScript SDK getFusedTokenUnits method exactly
|
|
48641
|
-
*/
|
|
48642
|
-
getFusedTokenUnits() {
|
|
48643
|
-
return this.metas.fusedTokenUnits || null;
|
|
48644
|
-
}
|
|
48645
|
-
/**
|
|
48646
|
-
* Convert to data array format
|
|
48647
|
-
* Matches JavaScript SDK toData method exactly
|
|
48648
|
-
*/
|
|
48649
|
-
toData() {
|
|
48650
|
-
return [this.id, this.name, this.metas];
|
|
48651
|
-
}
|
|
48652
|
-
/**
|
|
48653
|
-
* Convert to GraphQL response format
|
|
48654
|
-
* Matches JavaScript SDK toGraphQLResponse method exactly
|
|
48655
|
-
*/
|
|
48656
|
-
toGraphQLResponse() {
|
|
48657
|
-
return {
|
|
48658
|
-
id: this.id,
|
|
48659
|
-
name: this.name,
|
|
48660
|
-
metas: JSON.stringify(this.metas)
|
|
48661
|
-
};
|
|
48662
|
-
}
|
|
48663
|
-
};
|
|
48664
|
-
|
|
48665
|
-
// src/response/ResponseBalance.ts
|
|
48666
49067
|
var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
48667
49068
|
/**
|
|
48668
49069
|
* Class constructor
|
|
@@ -51201,6 +51602,12 @@ ${operationTypes.join("\n")}
|
|
|
51201
51602
|
}
|
|
51202
51603
|
};
|
|
51203
51604
|
|
|
51605
|
+
// src/mutation/MutationReplenishToken.ts
|
|
51606
|
+
var MutationReplenishToken = class extends MutationProposeMolecule {
|
|
51607
|
+
fillMolecule() {
|
|
51608
|
+
}
|
|
51609
|
+
};
|
|
51610
|
+
|
|
51204
51611
|
// src/subscribe/Subscribe.ts
|
|
51205
51612
|
init_exception();
|
|
51206
51613
|
var Subscribe = class {
|
|
@@ -52642,20 +53049,42 @@ ${operationTypes.join("\n")}
|
|
|
52642
53049
|
return response;
|
|
52643
53050
|
}
|
|
52644
53051
|
/**
|
|
52645
|
-
* Replenish
|
|
53052
|
+
* Replenish a non-finite token supply.
|
|
53053
|
+
* Matches JS SDK KnishIOClient.replenishToken (KnishIOClient.js:2195-2231).
|
|
52646
53054
|
*/
|
|
52647
53055
|
async replenishToken({
|
|
52648
53056
|
token,
|
|
52649
53057
|
amount = null,
|
|
52650
53058
|
units = null,
|
|
52651
|
-
sourceWallet
|
|
53059
|
+
sourceWallet = null
|
|
52652
53060
|
}) {
|
|
52653
53061
|
this.log("info", `KnishIOClient::replenishToken() - Replenishing ${amount || "units"} of ${token}...`);
|
|
52654
|
-
|
|
52655
|
-
token
|
|
52656
|
-
|
|
52657
|
-
|
|
53062
|
+
if (!sourceWallet) {
|
|
53063
|
+
sourceWallet = (await this.queryBalance({ token }))?.payload();
|
|
53064
|
+
}
|
|
53065
|
+
if (!sourceWallet) {
|
|
53066
|
+
throw new exports.TransferBalanceException("Source wallet is missing or invalid.");
|
|
53067
|
+
}
|
|
53068
|
+
const remainderWallet = sourceWallet.createRemainder(this.getSecret());
|
|
53069
|
+
const molecule = await this.createMolecule({
|
|
53070
|
+
sourceWallet,
|
|
53071
|
+
remainderWallet
|
|
52658
53072
|
});
|
|
53073
|
+
molecule.replenishToken({
|
|
53074
|
+
amount: Number(amount ?? 0),
|
|
53075
|
+
units: units ?? []
|
|
53076
|
+
});
|
|
53077
|
+
molecule.sign({ bundle: this.getBundle() });
|
|
53078
|
+
molecule.check();
|
|
53079
|
+
const mutation = await this.createMoleculeMutation({
|
|
53080
|
+
mutationClass: MutationReplenishToken,
|
|
53081
|
+
molecule
|
|
53082
|
+
});
|
|
53083
|
+
const response = await this.executeQuery(mutation);
|
|
53084
|
+
if (!response) {
|
|
53085
|
+
throw new CodeException("Token replenishment failed");
|
|
53086
|
+
}
|
|
53087
|
+
return response;
|
|
52659
53088
|
}
|
|
52660
53089
|
/**
|
|
52661
53090
|
* Fuse token units
|
|
@@ -53106,75 +53535,8 @@ ${operationTypes.join("\n")}
|
|
|
53106
53535
|
|
|
53107
53536
|
// src/index.ts
|
|
53108
53537
|
init_Response();
|
|
53109
|
-
|
|
53110
|
-
// src/core/PolicyMeta.ts
|
|
53111
|
-
var PolicyMeta = class _PolicyMeta {
|
|
53112
|
-
policy;
|
|
53113
|
-
/**
|
|
53114
|
-
* Create new PolicyMeta instance
|
|
53115
|
-
* Matches JavaScript SDK constructor signature exactly
|
|
53116
|
-
*/
|
|
53117
|
-
constructor(policy = {}, metaKeys = []) {
|
|
53118
|
-
this.policy = _PolicyMeta.normalizePolicy(policy);
|
|
53119
|
-
this.fillDefault(metaKeys);
|
|
53120
|
-
}
|
|
53121
|
-
/**
|
|
53122
|
-
* Normalize policy object structure
|
|
53123
|
-
* Matches JavaScript SDK normalizePolicy method exactly
|
|
53124
|
-
*/
|
|
53125
|
-
static normalizePolicy(policy = {}) {
|
|
53126
|
-
const policyMeta = {};
|
|
53127
|
-
for (const [policyKey, value2] of Object.entries(policy)) {
|
|
53128
|
-
if (value2 !== null && ["read", "write"].includes(policyKey)) {
|
|
53129
|
-
policyMeta[policyKey] = {};
|
|
53130
|
-
for (const [key, content] of Object.entries(value2)) {
|
|
53131
|
-
policyMeta[policyKey][key] = content;
|
|
53132
|
-
}
|
|
53133
|
-
}
|
|
53134
|
-
}
|
|
53135
|
-
return policyMeta;
|
|
53136
|
-
}
|
|
53137
|
-
/**
|
|
53138
|
-
* Fill default policy values for metadata keys
|
|
53139
|
-
* Matches JavaScript SDK fillDefault method exactly
|
|
53140
|
-
*/
|
|
53141
|
-
fillDefault(metaKeys = []) {
|
|
53142
|
-
const readPolicy = Array.from(this.policy).filter((item) => item.action === "read");
|
|
53143
|
-
const writePolicy = Array.from(this.policy).filter((item) => item.action === "write");
|
|
53144
|
-
for (const [type2, value2] of Object.entries({
|
|
53145
|
-
read: readPolicy,
|
|
53146
|
-
write: writePolicy
|
|
53147
|
-
})) {
|
|
53148
|
-
const policyKey = value2.map((item) => item.key);
|
|
53149
|
-
if (!this.policy[type2]) {
|
|
53150
|
-
this.policy[type2] = {};
|
|
53151
|
-
}
|
|
53152
|
-
for (const key of diff(metaKeys, policyKey)) {
|
|
53153
|
-
if (!this.policy[type2][key]) {
|
|
53154
|
-
this.policy[type2][key] = type2 === "write" && !["characters", "pubkey"].includes(key) ? ["self"] : ["all"];
|
|
53155
|
-
}
|
|
53156
|
-
}
|
|
53157
|
-
}
|
|
53158
|
-
}
|
|
53159
|
-
/**
|
|
53160
|
-
* Get the policy object
|
|
53161
|
-
* Matches JavaScript SDK get method exactly
|
|
53162
|
-
*/
|
|
53163
|
-
get() {
|
|
53164
|
-
return this.policy;
|
|
53165
|
-
}
|
|
53166
|
-
/**
|
|
53167
|
-
* Convert policy to JSON string
|
|
53168
|
-
* Matches JavaScript SDK toJson method exactly
|
|
53169
|
-
*/
|
|
53170
|
-
toJson() {
|
|
53171
|
-
return JSON.stringify(this.get());
|
|
53172
|
-
}
|
|
53173
|
-
};
|
|
53174
|
-
|
|
53175
|
-
// src/index.ts
|
|
53176
53538
|
init_exception();
|
|
53177
|
-
var SDK_VERSION = "0.9.
|
|
53539
|
+
var SDK_VERSION = "0.9.6";
|
|
53178
53540
|
var SDK_NAME = "KnishIO-Client-TS";
|
|
53179
53541
|
var COMPATIBLE_SERVER_VERSIONS = [4, 5];
|
|
53180
53542
|
var SDK_INFO = {
|
|
@@ -53265,8 +53627,8 @@ ${operationTypes.join("\n")}
|
|
|
53265
53627
|
};
|
|
53266
53628
|
/*! Bundled license information:
|
|
53267
53629
|
|
|
53268
|
-
@noble/
|
|
53269
|
-
(*! noble-
|
|
53630
|
+
@noble/curves/utils.js:
|
|
53631
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
53270
53632
|
|
|
53271
53633
|
@noble/post-quantum/utils.js:
|
|
53272
53634
|
@noble/post-quantum/_crystals.js:
|