@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.cjs
CHANGED
|
@@ -2178,11 +2178,9 @@ function verifyOTSSignature(otsFragments, molecularHash, signingAddress) {
|
|
|
2178
2178
|
const base17Hash = convertToBase17(molecularHash);
|
|
2179
2179
|
const enumerated = enumerateMolecularHash(base17Hash);
|
|
2180
2180
|
const normalized = normalizeMolecularHash(enumerated);
|
|
2181
|
-
|
|
2181
|
+
const ots = otsFragments;
|
|
2182
2182
|
if (ots.length !== 2048) {
|
|
2183
|
-
|
|
2184
|
-
return false;
|
|
2185
|
-
}
|
|
2183
|
+
return false;
|
|
2186
2184
|
}
|
|
2187
2185
|
const otsChunks = [];
|
|
2188
2186
|
for (let i = 0; i < ots.length; i += CRYPTO_CONSTANTS.KEY_FRAGMENT_SIZE) {
|
|
@@ -2685,6 +2683,123 @@ var Meta = class {
|
|
|
2685
2683
|
});
|
|
2686
2684
|
}
|
|
2687
2685
|
};
|
|
2686
|
+
|
|
2687
|
+
// src/libraries/array.ts
|
|
2688
|
+
function deepCloning(o, h) {
|
|
2689
|
+
let i;
|
|
2690
|
+
let r;
|
|
2691
|
+
let x;
|
|
2692
|
+
const t = [Array, Date, Number, String, Boolean];
|
|
2693
|
+
const s = Object.prototype.toString;
|
|
2694
|
+
h = h || [];
|
|
2695
|
+
for (i = 0; i < h.length; i += 2) {
|
|
2696
|
+
if (o === h[i]) {
|
|
2697
|
+
return h[i + 1];
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
if (!r && o && typeof o === "object") {
|
|
2701
|
+
r = {};
|
|
2702
|
+
for (i = 0; i < t.length; i++) {
|
|
2703
|
+
if (s.call(o) === s.call(x = new t[i](o))) {
|
|
2704
|
+
r = i ? x : [];
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
h.push(o, r);
|
|
2708
|
+
for (i in o) {
|
|
2709
|
+
if (Object.prototype.hasOwnProperty.call(o, i)) {
|
|
2710
|
+
r[i] = deepCloning(o[i], h);
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
return r || o;
|
|
2715
|
+
}
|
|
2716
|
+
function chunkArray(arr, size) {
|
|
2717
|
+
const chunks = [];
|
|
2718
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
2719
|
+
chunks.push(arr.slice(i, i + size));
|
|
2720
|
+
}
|
|
2721
|
+
return chunks;
|
|
2722
|
+
}
|
|
2723
|
+
function diff(...arrays) {
|
|
2724
|
+
return [].concat(...arrays.map((arr, i) => {
|
|
2725
|
+
const others = arrays.slice(0);
|
|
2726
|
+
others.splice(i, 1);
|
|
2727
|
+
const unique = [...new Set([].concat(...others))];
|
|
2728
|
+
return arr.filter((item) => !unique.includes(item));
|
|
2729
|
+
}));
|
|
2730
|
+
}
|
|
2731
|
+
function intersect(...arrays) {
|
|
2732
|
+
if (arrays.length === 0) return [];
|
|
2733
|
+
if (arrays.length === 1) return arrays[0];
|
|
2734
|
+
return arrays.reduce(
|
|
2735
|
+
(first, second) => first.filter((item) => second.includes(item))
|
|
2736
|
+
);
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2739
|
+
// src/core/PolicyMeta.ts
|
|
2740
|
+
var PolicyMeta = class _PolicyMeta {
|
|
2741
|
+
policy;
|
|
2742
|
+
/**
|
|
2743
|
+
* Create new PolicyMeta instance
|
|
2744
|
+
* Matches JavaScript SDK constructor signature exactly
|
|
2745
|
+
*/
|
|
2746
|
+
constructor(policy = {}, metaKeys = []) {
|
|
2747
|
+
this.policy = _PolicyMeta.normalizePolicy(policy);
|
|
2748
|
+
this.fillDefault(metaKeys);
|
|
2749
|
+
}
|
|
2750
|
+
/**
|
|
2751
|
+
* Normalize policy object structure
|
|
2752
|
+
* Matches JavaScript SDK normalizePolicy method exactly
|
|
2753
|
+
*/
|
|
2754
|
+
static normalizePolicy(policy = {}) {
|
|
2755
|
+
const policyMeta = {};
|
|
2756
|
+
for (const [policyKey, value] of Object.entries(policy)) {
|
|
2757
|
+
if (value !== null && ["read", "write"].includes(policyKey)) {
|
|
2758
|
+
policyMeta[policyKey] = {};
|
|
2759
|
+
for (const [key, content] of Object.entries(value)) {
|
|
2760
|
+
policyMeta[policyKey][key] = content;
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
return policyMeta;
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* Fill default policy values for metadata keys
|
|
2768
|
+
* Matches JavaScript SDK fillDefault method exactly
|
|
2769
|
+
*/
|
|
2770
|
+
fillDefault(metaKeys = []) {
|
|
2771
|
+
const readPolicy = Array.from(this.policy).filter((item) => item.action === "read");
|
|
2772
|
+
const writePolicy = Array.from(this.policy).filter((item) => item.action === "write");
|
|
2773
|
+
for (const [type, value] of Object.entries({
|
|
2774
|
+
read: readPolicy,
|
|
2775
|
+
write: writePolicy
|
|
2776
|
+
})) {
|
|
2777
|
+
const policyKey = value.map((item) => item.key);
|
|
2778
|
+
if (!this.policy[type]) {
|
|
2779
|
+
this.policy[type] = {};
|
|
2780
|
+
}
|
|
2781
|
+
for (const key of diff(metaKeys, policyKey)) {
|
|
2782
|
+
if (!this.policy[type][key]) {
|
|
2783
|
+
this.policy[type][key] = type === "write" && !["characters", "pubkey"].includes(key) ? ["self"] : ["all"];
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
/**
|
|
2789
|
+
* Get the policy object
|
|
2790
|
+
* Matches JavaScript SDK get method exactly
|
|
2791
|
+
*/
|
|
2792
|
+
get() {
|
|
2793
|
+
return this.policy;
|
|
2794
|
+
}
|
|
2795
|
+
/**
|
|
2796
|
+
* Convert policy to JSON string
|
|
2797
|
+
* Matches JavaScript SDK toJson method exactly
|
|
2798
|
+
*/
|
|
2799
|
+
toJson() {
|
|
2800
|
+
return JSON.stringify(this.get());
|
|
2801
|
+
}
|
|
2802
|
+
};
|
|
2688
2803
|
var AtomMeta = class _AtomMeta {
|
|
2689
2804
|
meta;
|
|
2690
2805
|
/**
|
|
@@ -2780,8 +2895,9 @@ var AtomMeta = class _AtomMeta {
|
|
|
2780
2895
|
* @return This instance for chaining
|
|
2781
2896
|
*/
|
|
2782
2897
|
addPolicy(policy) {
|
|
2898
|
+
const policyMeta = new PolicyMeta(policy, Object.keys(this.meta));
|
|
2783
2899
|
this.merge({
|
|
2784
|
-
policy:
|
|
2900
|
+
policy: policyMeta.toJson()
|
|
2785
2901
|
});
|
|
2786
2902
|
return this;
|
|
2787
2903
|
}
|
|
@@ -3414,6 +3530,87 @@ function createMolecularHash(value) {
|
|
|
3414
3530
|
}
|
|
3415
3531
|
return value;
|
|
3416
3532
|
}
|
|
3533
|
+
|
|
3534
|
+
// src/core/TokenUnit.ts
|
|
3535
|
+
var TokenUnit = class _TokenUnit {
|
|
3536
|
+
id;
|
|
3537
|
+
name;
|
|
3538
|
+
metas;
|
|
3539
|
+
/**
|
|
3540
|
+
* Create new TokenUnit instance
|
|
3541
|
+
* Matches JavaScript SDK constructor signature exactly
|
|
3542
|
+
*/
|
|
3543
|
+
constructor(id, name, metas) {
|
|
3544
|
+
this.id = id;
|
|
3545
|
+
this.name = name;
|
|
3546
|
+
this.metas = metas || {};
|
|
3547
|
+
}
|
|
3548
|
+
/**
|
|
3549
|
+
* Create TokenUnit from GraphQL response data
|
|
3550
|
+
* Matches JavaScript SDK createFromGraphQL method exactly
|
|
3551
|
+
*/
|
|
3552
|
+
static createFromGraphQL(data) {
|
|
3553
|
+
let metas = data.metas || {};
|
|
3554
|
+
if (Array.isArray(metas) && metas.length) {
|
|
3555
|
+
try {
|
|
3556
|
+
metas = JSON.parse(metas);
|
|
3557
|
+
if (!metas) {
|
|
3558
|
+
metas = {};
|
|
3559
|
+
}
|
|
3560
|
+
} catch (error) {
|
|
3561
|
+
metas = {};
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
return new _TokenUnit(
|
|
3565
|
+
data.id,
|
|
3566
|
+
data.name,
|
|
3567
|
+
metas
|
|
3568
|
+
);
|
|
3569
|
+
}
|
|
3570
|
+
/**
|
|
3571
|
+
* Create TokenUnit from database array data
|
|
3572
|
+
* Matches JavaScript SDK createFromDB method exactly
|
|
3573
|
+
*/
|
|
3574
|
+
static createFromDB(data) {
|
|
3575
|
+
return new _TokenUnit(
|
|
3576
|
+
data[0],
|
|
3577
|
+
data[1],
|
|
3578
|
+
data.length > 2 ? data[2] : {}
|
|
3579
|
+
);
|
|
3580
|
+
}
|
|
3581
|
+
/**
|
|
3582
|
+
* Get fragment zone from metadata
|
|
3583
|
+
* Matches JavaScript SDK getFragmentZone method exactly
|
|
3584
|
+
*/
|
|
3585
|
+
getFragmentZone() {
|
|
3586
|
+
return this.metas.fragmentZone || null;
|
|
3587
|
+
}
|
|
3588
|
+
/**
|
|
3589
|
+
* Get fused token units from metadata
|
|
3590
|
+
* Matches JavaScript SDK getFusedTokenUnits method exactly
|
|
3591
|
+
*/
|
|
3592
|
+
getFusedTokenUnits() {
|
|
3593
|
+
return this.metas.fusedTokenUnits || null;
|
|
3594
|
+
}
|
|
3595
|
+
/**
|
|
3596
|
+
* Convert to data array format
|
|
3597
|
+
* Matches JavaScript SDK toData method exactly
|
|
3598
|
+
*/
|
|
3599
|
+
toData() {
|
|
3600
|
+
return [this.id, this.name, this.metas];
|
|
3601
|
+
}
|
|
3602
|
+
/**
|
|
3603
|
+
* Convert to GraphQL response format
|
|
3604
|
+
* Matches JavaScript SDK toGraphQLResponse method exactly
|
|
3605
|
+
*/
|
|
3606
|
+
toGraphQLResponse() {
|
|
3607
|
+
return {
|
|
3608
|
+
id: this.id,
|
|
3609
|
+
name: this.name,
|
|
3610
|
+
metas: JSON.stringify(this.metas)
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
};
|
|
3417
3614
|
var Wallet = class _Wallet {
|
|
3418
3615
|
token;
|
|
3419
3616
|
balance;
|
|
@@ -3554,11 +3751,13 @@ var Wallet = class _Wallet {
|
|
|
3554
3751
|
return typeof maybeBundleHash === "string" && isBundleHash(maybeBundleHash);
|
|
3555
3752
|
}
|
|
3556
3753
|
/**
|
|
3557
|
-
*
|
|
3558
|
-
*
|
|
3754
|
+
* Map raw token-unit tuples to TokenUnit instances.
|
|
3755
|
+
* Matches JS SDK Wallet.getTokenUnits (Wallet.js:190-196). The serialised shape reaches hashed
|
|
3756
|
+
* atom meta via AtomMeta.setAtomWallet -> JSON.stringify(getTokenUnitsData()), so returning raw
|
|
3757
|
+
* tuples here would diverge from every other SDK.
|
|
3559
3758
|
*/
|
|
3560
3759
|
static getTokenUnits(unitsData) {
|
|
3561
|
-
return unitsData;
|
|
3760
|
+
return unitsData.map((unitData) => TokenUnit.createFromDB(unitData));
|
|
3562
3761
|
}
|
|
3563
3762
|
/**
|
|
3564
3763
|
* Create a remainder wallet for transactions
|
|
@@ -3855,7 +4054,7 @@ zod.z.string().regex(base17HashRegex, "Molecular hash must be base17 format (0-9
|
|
|
3855
4054
|
var TokenSlugSchema = zod.z.string().min(1, "Token slug cannot be empty").max(64, "Token slug cannot exceed 64 characters").transform((val) => val.toUpperCase()).brand();
|
|
3856
4055
|
var MetaTypeSchema = zod.z.string().min(1, "Meta type cannot be empty").max(256, "Meta type cannot exceed 256 characters").brand();
|
|
3857
4056
|
var MetaIdSchema = zod.z.string().min(1, "Meta ID cannot be empty").brand();
|
|
3858
|
-
var BatchIdSchema = zod.z.string().
|
|
4057
|
+
var BatchIdSchema = zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Batch ID must be 64 hexadecimal characters").brand();
|
|
3859
4058
|
var CellSlugSchema = zod.z.string().min(1, "Cell slug cannot be empty").max(64, "Cell slug cannot exceed 64 characters").brand();
|
|
3860
4059
|
var AtomIsotopeSchema = zod.z.enum(["C", "V", "U", "T", "M", "I", "R", "B", "F"], {
|
|
3861
4060
|
error: "Invalid atom isotope. Must be one of: C, V, U, T, M, I, R, B, F"
|
|
@@ -4179,58 +4378,6 @@ var RuleArgumentException = class extends exports.BaseException {
|
|
|
4179
4378
|
};
|
|
4180
4379
|
var RuleArgumentException_default = RuleArgumentException;
|
|
4181
4380
|
|
|
4182
|
-
// src/libraries/array.ts
|
|
4183
|
-
function deepCloning(o, h) {
|
|
4184
|
-
let i;
|
|
4185
|
-
let r;
|
|
4186
|
-
let x;
|
|
4187
|
-
const t = [Array, Date, Number, String, Boolean];
|
|
4188
|
-
const s = Object.prototype.toString;
|
|
4189
|
-
h = h || [];
|
|
4190
|
-
for (i = 0; i < h.length; i += 2) {
|
|
4191
|
-
if (o === h[i]) {
|
|
4192
|
-
return h[i + 1];
|
|
4193
|
-
}
|
|
4194
|
-
}
|
|
4195
|
-
if (!r && o && typeof o === "object") {
|
|
4196
|
-
r = {};
|
|
4197
|
-
for (i = 0; i < t.length; i++) {
|
|
4198
|
-
if (s.call(o) === s.call(x = new t[i](o))) {
|
|
4199
|
-
r = i ? x : [];
|
|
4200
|
-
}
|
|
4201
|
-
}
|
|
4202
|
-
h.push(o, r);
|
|
4203
|
-
for (i in o) {
|
|
4204
|
-
if (Object.prototype.hasOwnProperty.call(o, i)) {
|
|
4205
|
-
r[i] = deepCloning(o[i], h);
|
|
4206
|
-
}
|
|
4207
|
-
}
|
|
4208
|
-
}
|
|
4209
|
-
return r || o;
|
|
4210
|
-
}
|
|
4211
|
-
function chunkArray(arr, size) {
|
|
4212
|
-
const chunks = [];
|
|
4213
|
-
for (let i = 0; i < arr.length; i += size) {
|
|
4214
|
-
chunks.push(arr.slice(i, i + size));
|
|
4215
|
-
}
|
|
4216
|
-
return chunks;
|
|
4217
|
-
}
|
|
4218
|
-
function diff(...arrays) {
|
|
4219
|
-
return [].concat(...arrays.map((arr, i) => {
|
|
4220
|
-
const others = arrays.slice(0);
|
|
4221
|
-
others.splice(i, 1);
|
|
4222
|
-
const unique = [...new Set([].concat(...others))];
|
|
4223
|
-
return arr.filter((item) => !unique.includes(item));
|
|
4224
|
-
}));
|
|
4225
|
-
}
|
|
4226
|
-
function intersect(...arrays) {
|
|
4227
|
-
if (arrays.length === 0) return [];
|
|
4228
|
-
if (arrays.length === 1) return arrays[0];
|
|
4229
|
-
return arrays.reduce(
|
|
4230
|
-
(first, second) => first.filter((item) => second.includes(item))
|
|
4231
|
-
);
|
|
4232
|
-
}
|
|
4233
|
-
|
|
4234
4381
|
// src/instance/rules/Callback.ts
|
|
4235
4382
|
init_exception();
|
|
4236
4383
|
var CallbackParamsSchema = zod.z.object({
|
|
@@ -5561,6 +5708,51 @@ var Molecule = class _Molecule {
|
|
|
5561
5708
|
}));
|
|
5562
5709
|
return this;
|
|
5563
5710
|
}
|
|
5711
|
+
/**
|
|
5712
|
+
* Replenishes non-finite token supplies.
|
|
5713
|
+
* Matches JS SDK Molecule.replenishToken (Molecule.js:521-566) exactly.
|
|
5714
|
+
*
|
|
5715
|
+
* Two orderings here are load-bearing for the molecular hash and must not be reordered:
|
|
5716
|
+
* the remainder balance is computed BEFORE the source balance is overwritten, and the
|
|
5717
|
+
* source V-atom is added BEFORE the remainder V-atom.
|
|
5718
|
+
*/
|
|
5719
|
+
replenishToken({
|
|
5720
|
+
amount,
|
|
5721
|
+
units = []
|
|
5722
|
+
}) {
|
|
5723
|
+
if (amount < 0) {
|
|
5724
|
+
throw new NegativeAmountException("Molecule::replenishToken() - Amount to replenish must be positive!");
|
|
5725
|
+
}
|
|
5726
|
+
if (!this.sourceWallet || !this.remainderWallet) {
|
|
5727
|
+
throw new Error("Source and remainder wallets required for token replenishment");
|
|
5728
|
+
}
|
|
5729
|
+
if (units.length) {
|
|
5730
|
+
const formatted = Wallet.getTokenUnits(units);
|
|
5731
|
+
this.remainderWallet.tokenUnits = this.sourceWallet.tokenUnits;
|
|
5732
|
+
for (const unit of formatted) {
|
|
5733
|
+
this.remainderWallet.tokenUnits.push(unit);
|
|
5734
|
+
}
|
|
5735
|
+
this.remainderWallet.balance = String(this.remainderWallet.tokenUnits.length);
|
|
5736
|
+
this.sourceWallet.tokenUnits = formatted;
|
|
5737
|
+
this.sourceWallet.balance = String(this.sourceWallet.tokenUnits.length);
|
|
5738
|
+
} else {
|
|
5739
|
+
this.remainderWallet.balance = String(Number(this.sourceWallet.balance) + amount);
|
|
5740
|
+
this.sourceWallet.balance = String(amount);
|
|
5741
|
+
}
|
|
5742
|
+
this.addAtom(Atom.create({
|
|
5743
|
+
isotope: "V",
|
|
5744
|
+
wallet: this.sourceWallet,
|
|
5745
|
+
value: Number(this.sourceWallet.balance)
|
|
5746
|
+
}));
|
|
5747
|
+
this.addAtom(Atom.create({
|
|
5748
|
+
isotope: "V",
|
|
5749
|
+
wallet: this.remainderWallet,
|
|
5750
|
+
value: Number(this.remainderWallet.balance),
|
|
5751
|
+
metaType: "walletBundle",
|
|
5752
|
+
metaId: this.remainderWallet.bundle
|
|
5753
|
+
}));
|
|
5754
|
+
return this;
|
|
5755
|
+
}
|
|
5564
5756
|
/**
|
|
5565
5757
|
* Initialize authorization request
|
|
5566
5758
|
* Creates U-isotope (authorization) atom for requesting auth token
|
|
@@ -6095,16 +6287,27 @@ var GraphQLClient = class {
|
|
|
6095
6287
|
return core.createClient({
|
|
6096
6288
|
url: serverUri,
|
|
6097
6289
|
exchanges,
|
|
6098
|
-
//
|
|
6099
|
-
//
|
|
6100
|
-
//
|
|
6101
|
-
|
|
6290
|
+
// urql 5 had no default and always POSTed; urql 6 defaults to 'within-url-limit', which
|
|
6291
|
+
// URL-encodes short queries and sends NO body. That would silently disable the CipherHash
|
|
6292
|
+
// envelope below — cipherFetch's `typeof init.body === 'string'` guard fails on a GET, so
|
|
6293
|
+
// the query would leave as plaintext URL parameters with no error. Pin POST explicitly.
|
|
6294
|
+
preferGetMethod: false,
|
|
6295
|
+
// Always route through our own fetch. Two reasons: (1) PQ-transport Phase E — when
|
|
6296
|
+
// encryption is on, cipherFetch wraps the request body in the CipherHash envelope and
|
|
6297
|
+
// decrypts the response; (2) the 60s timeout. urql's makeFetchSource unconditionally
|
|
6298
|
+
// overwrites init.signal with its own AbortController, so a signal returned from
|
|
6299
|
+
// fetchOptions() is discarded and never fired. Combining it here is the only place it
|
|
6300
|
+
// survives.
|
|
6301
|
+
fetch: ((input, init) => {
|
|
6302
|
+
const timeoutSignal = AbortSignal.timeout(6e4);
|
|
6303
|
+
const signal = init?.signal && typeof AbortSignal.any === "function" ? AbortSignal.any([init.signal, timeoutSignal]) : init?.signal ?? timeoutSignal;
|
|
6304
|
+
const timedInit = { ...init, signal };
|
|
6305
|
+
return this.cipherLink ? this.cipherFetch(input, timedInit) : fetch(input, timedInit);
|
|
6306
|
+
}),
|
|
6102
6307
|
fetchOptions: () => ({
|
|
6103
6308
|
headers: {
|
|
6104
6309
|
"X-Auth-Token": this.$__authToken
|
|
6105
|
-
}
|
|
6106
|
-
// Add 60 second timeout
|
|
6107
|
-
signal: AbortSignal.timeout(6e4)
|
|
6310
|
+
}
|
|
6108
6311
|
})
|
|
6109
6312
|
});
|
|
6110
6313
|
}
|
|
@@ -6617,12 +6820,12 @@ var TokenSlugSchema2 = createBrandedSchema(
|
|
|
6617
6820
|
);
|
|
6618
6821
|
var BatchIdSchema2 = createBrandedSchema(
|
|
6619
6822
|
"BatchId",
|
|
6620
|
-
//
|
|
6621
|
-
//
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
)
|
|
6823
|
+
// 64 hex characters. generateBatchId (src/libraries/crypto.ts) returns either
|
|
6824
|
+
// shake256(molecularHash + index, 256) — 256 bits, 64 hex chars — or randomString(64) over the
|
|
6825
|
+
// alphabet 'abcdef0123456789'. A UUID shape matches nothing this SDK can produce, so the
|
|
6826
|
+
// previous 8-4-4-4-12 regex rejected every real batch ID. Agrees with isBatchId in
|
|
6827
|
+
// src/types/guards.ts.
|
|
6828
|
+
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid batch ID format")
|
|
6626
6829
|
);
|
|
6627
6830
|
var CellSlugSchema2 = createBrandedSchema(
|
|
6628
6831
|
"CellSlug",
|
|
@@ -7525,89 +7728,6 @@ var ConfigValidator = class _ConfigValidator {
|
|
|
7525
7728
|
|
|
7526
7729
|
// src/response/ResponseBalance.ts
|
|
7527
7730
|
init_Response();
|
|
7528
|
-
|
|
7529
|
-
// src/core/TokenUnit.ts
|
|
7530
|
-
var TokenUnit = class _TokenUnit {
|
|
7531
|
-
id;
|
|
7532
|
-
name;
|
|
7533
|
-
metas;
|
|
7534
|
-
/**
|
|
7535
|
-
* Create new TokenUnit instance
|
|
7536
|
-
* Matches JavaScript SDK constructor signature exactly
|
|
7537
|
-
*/
|
|
7538
|
-
constructor(id, name, metas) {
|
|
7539
|
-
this.id = id;
|
|
7540
|
-
this.name = name;
|
|
7541
|
-
this.metas = metas || {};
|
|
7542
|
-
}
|
|
7543
|
-
/**
|
|
7544
|
-
* Create TokenUnit from GraphQL response data
|
|
7545
|
-
* Matches JavaScript SDK createFromGraphQL method exactly
|
|
7546
|
-
*/
|
|
7547
|
-
static createFromGraphQL(data) {
|
|
7548
|
-
let metas = data.metas || {};
|
|
7549
|
-
if (Array.isArray(metas) && metas.length) {
|
|
7550
|
-
try {
|
|
7551
|
-
metas = JSON.parse(metas);
|
|
7552
|
-
if (!metas) {
|
|
7553
|
-
metas = {};
|
|
7554
|
-
}
|
|
7555
|
-
} catch (error) {
|
|
7556
|
-
metas = {};
|
|
7557
|
-
}
|
|
7558
|
-
}
|
|
7559
|
-
return new _TokenUnit(
|
|
7560
|
-
data.id,
|
|
7561
|
-
data.name,
|
|
7562
|
-
metas
|
|
7563
|
-
);
|
|
7564
|
-
}
|
|
7565
|
-
/**
|
|
7566
|
-
* Create TokenUnit from database array data
|
|
7567
|
-
* Matches JavaScript SDK createFromDB method exactly
|
|
7568
|
-
*/
|
|
7569
|
-
static createFromDB(data) {
|
|
7570
|
-
return new _TokenUnit(
|
|
7571
|
-
data[0],
|
|
7572
|
-
data[1],
|
|
7573
|
-
data.length > 2 ? data[2] : {}
|
|
7574
|
-
);
|
|
7575
|
-
}
|
|
7576
|
-
/**
|
|
7577
|
-
* Get fragment zone from metadata
|
|
7578
|
-
* Matches JavaScript SDK getFragmentZone method exactly
|
|
7579
|
-
*/
|
|
7580
|
-
getFragmentZone() {
|
|
7581
|
-
return this.metas.fragmentZone || null;
|
|
7582
|
-
}
|
|
7583
|
-
/**
|
|
7584
|
-
* Get fused token units from metadata
|
|
7585
|
-
* Matches JavaScript SDK getFusedTokenUnits method exactly
|
|
7586
|
-
*/
|
|
7587
|
-
getFusedTokenUnits() {
|
|
7588
|
-
return this.metas.fusedTokenUnits || null;
|
|
7589
|
-
}
|
|
7590
|
-
/**
|
|
7591
|
-
* Convert to data array format
|
|
7592
|
-
* Matches JavaScript SDK toData method exactly
|
|
7593
|
-
*/
|
|
7594
|
-
toData() {
|
|
7595
|
-
return [this.id, this.name, this.metas];
|
|
7596
|
-
}
|
|
7597
|
-
/**
|
|
7598
|
-
* Convert to GraphQL response format
|
|
7599
|
-
* Matches JavaScript SDK toGraphQLResponse method exactly
|
|
7600
|
-
*/
|
|
7601
|
-
toGraphQLResponse() {
|
|
7602
|
-
return {
|
|
7603
|
-
id: this.id,
|
|
7604
|
-
name: this.name,
|
|
7605
|
-
metas: JSON.stringify(this.metas)
|
|
7606
|
-
};
|
|
7607
|
-
}
|
|
7608
|
-
};
|
|
7609
|
-
|
|
7610
|
-
// src/response/ResponseBalance.ts
|
|
7611
7731
|
var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
7612
7732
|
/**
|
|
7613
7733
|
* Class constructor
|
|
@@ -10116,6 +10236,12 @@ var MutationAppendRequest = class extends MutationProposeMolecule {
|
|
|
10116
10236
|
}
|
|
10117
10237
|
};
|
|
10118
10238
|
|
|
10239
|
+
// src/mutation/MutationReplenishToken.ts
|
|
10240
|
+
var MutationReplenishToken = class extends MutationProposeMolecule {
|
|
10241
|
+
fillMolecule() {
|
|
10242
|
+
}
|
|
10243
|
+
};
|
|
10244
|
+
|
|
10119
10245
|
// src/subscribe/Subscribe.ts
|
|
10120
10246
|
init_exception();
|
|
10121
10247
|
var Subscribe = class {
|
|
@@ -11549,20 +11675,42 @@ var KnishIOClient = class {
|
|
|
11549
11675
|
return response;
|
|
11550
11676
|
}
|
|
11551
11677
|
/**
|
|
11552
|
-
* Replenish
|
|
11678
|
+
* Replenish a non-finite token supply.
|
|
11679
|
+
* Matches JS SDK KnishIOClient.replenishToken (KnishIOClient.js:2195-2231).
|
|
11553
11680
|
*/
|
|
11554
11681
|
async replenishToken({
|
|
11555
11682
|
token,
|
|
11556
11683
|
amount = null,
|
|
11557
11684
|
units = null,
|
|
11558
|
-
sourceWallet
|
|
11685
|
+
sourceWallet = null
|
|
11559
11686
|
}) {
|
|
11560
11687
|
this.log("info", `KnishIOClient::replenishToken() - Replenishing ${amount || "units"} of ${token}...`);
|
|
11561
|
-
|
|
11562
|
-
token
|
|
11563
|
-
|
|
11564
|
-
|
|
11688
|
+
if (!sourceWallet) {
|
|
11689
|
+
sourceWallet = (await this.queryBalance({ token }))?.payload();
|
|
11690
|
+
}
|
|
11691
|
+
if (!sourceWallet) {
|
|
11692
|
+
throw new exports.TransferBalanceException("Source wallet is missing or invalid.");
|
|
11693
|
+
}
|
|
11694
|
+
const remainderWallet = sourceWallet.createRemainder(this.getSecret());
|
|
11695
|
+
const molecule = await this.createMolecule({
|
|
11696
|
+
sourceWallet,
|
|
11697
|
+
remainderWallet
|
|
11565
11698
|
});
|
|
11699
|
+
molecule.replenishToken({
|
|
11700
|
+
amount: Number(amount ?? 0),
|
|
11701
|
+
units: units ?? []
|
|
11702
|
+
});
|
|
11703
|
+
molecule.sign({ bundle: this.getBundle() });
|
|
11704
|
+
molecule.check();
|
|
11705
|
+
const mutation = await this.createMoleculeMutation({
|
|
11706
|
+
mutationClass: MutationReplenishToken,
|
|
11707
|
+
molecule
|
|
11708
|
+
});
|
|
11709
|
+
const response = await this.executeQuery(mutation);
|
|
11710
|
+
if (!response) {
|
|
11711
|
+
throw new CodeException("Token replenishment failed");
|
|
11712
|
+
}
|
|
11713
|
+
return response;
|
|
11566
11714
|
}
|
|
11567
11715
|
/**
|
|
11568
11716
|
* Fuse token units
|
|
@@ -12013,75 +12161,8 @@ var KnishIOClient = class {
|
|
|
12013
12161
|
|
|
12014
12162
|
// src/index.ts
|
|
12015
12163
|
init_Response();
|
|
12016
|
-
|
|
12017
|
-
// src/core/PolicyMeta.ts
|
|
12018
|
-
var PolicyMeta = class _PolicyMeta {
|
|
12019
|
-
policy;
|
|
12020
|
-
/**
|
|
12021
|
-
* Create new PolicyMeta instance
|
|
12022
|
-
* Matches JavaScript SDK constructor signature exactly
|
|
12023
|
-
*/
|
|
12024
|
-
constructor(policy = {}, metaKeys = []) {
|
|
12025
|
-
this.policy = _PolicyMeta.normalizePolicy(policy);
|
|
12026
|
-
this.fillDefault(metaKeys);
|
|
12027
|
-
}
|
|
12028
|
-
/**
|
|
12029
|
-
* Normalize policy object structure
|
|
12030
|
-
* Matches JavaScript SDK normalizePolicy method exactly
|
|
12031
|
-
*/
|
|
12032
|
-
static normalizePolicy(policy = {}) {
|
|
12033
|
-
const policyMeta = {};
|
|
12034
|
-
for (const [policyKey, value] of Object.entries(policy)) {
|
|
12035
|
-
if (value !== null && ["read", "write"].includes(policyKey)) {
|
|
12036
|
-
policyMeta[policyKey] = {};
|
|
12037
|
-
for (const [key, content] of Object.entries(value)) {
|
|
12038
|
-
policyMeta[policyKey][key] = content;
|
|
12039
|
-
}
|
|
12040
|
-
}
|
|
12041
|
-
}
|
|
12042
|
-
return policyMeta;
|
|
12043
|
-
}
|
|
12044
|
-
/**
|
|
12045
|
-
* Fill default policy values for metadata keys
|
|
12046
|
-
* Matches JavaScript SDK fillDefault method exactly
|
|
12047
|
-
*/
|
|
12048
|
-
fillDefault(metaKeys = []) {
|
|
12049
|
-
const readPolicy = Array.from(this.policy).filter((item) => item.action === "read");
|
|
12050
|
-
const writePolicy = Array.from(this.policy).filter((item) => item.action === "write");
|
|
12051
|
-
for (const [type, value] of Object.entries({
|
|
12052
|
-
read: readPolicy,
|
|
12053
|
-
write: writePolicy
|
|
12054
|
-
})) {
|
|
12055
|
-
const policyKey = value.map((item) => item.key);
|
|
12056
|
-
if (!this.policy[type]) {
|
|
12057
|
-
this.policy[type] = {};
|
|
12058
|
-
}
|
|
12059
|
-
for (const key of diff(metaKeys, policyKey)) {
|
|
12060
|
-
if (!this.policy[type][key]) {
|
|
12061
|
-
this.policy[type][key] = type === "write" && !["characters", "pubkey"].includes(key) ? ["self"] : ["all"];
|
|
12062
|
-
}
|
|
12063
|
-
}
|
|
12064
|
-
}
|
|
12065
|
-
}
|
|
12066
|
-
/**
|
|
12067
|
-
* Get the policy object
|
|
12068
|
-
* Matches JavaScript SDK get method exactly
|
|
12069
|
-
*/
|
|
12070
|
-
get() {
|
|
12071
|
-
return this.policy;
|
|
12072
|
-
}
|
|
12073
|
-
/**
|
|
12074
|
-
* Convert policy to JSON string
|
|
12075
|
-
* Matches JavaScript SDK toJson method exactly
|
|
12076
|
-
*/
|
|
12077
|
-
toJson() {
|
|
12078
|
-
return JSON.stringify(this.get());
|
|
12079
|
-
}
|
|
12080
|
-
};
|
|
12081
|
-
|
|
12082
|
-
// src/index.ts
|
|
12083
12164
|
init_exception();
|
|
12084
|
-
var SDK_VERSION = "0.9.
|
|
12165
|
+
var SDK_VERSION = "0.9.6";
|
|
12085
12166
|
var SDK_NAME = "KnishIO-Client-TS";
|
|
12086
12167
|
var COMPATIBLE_SERVER_VERSIONS = [4, 5];
|
|
12087
12168
|
var SDK_INFO = {
|