@wishknish/knishio-client-ts 0.7.4 → 0.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2702 -1033
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +339 -106
- package/dist/index.d.ts +339 -106
- package/dist/index.iife.js +22052 -19964
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +2699 -1034
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/AuthToken.ts +8 -2
- package/src/KnishIOClient.ts +346 -51
- package/src/constants.ts +5 -3
- package/src/core/Atom.ts +167 -100
- package/src/core/AtomMeta.ts +11 -28
- package/src/core/Meta.ts +18 -15
- package/src/core/Molecule.ts +607 -141
- package/src/core/Wallet.ts +19 -24
- package/src/index.ts +8 -0
- package/src/instance/rules/Rule.ts +128 -19
- package/src/libraries/CheckMolecule.ts +88 -1
- package/src/libraries/crypto.ts +14 -30
- package/src/libraries/strings.ts +26 -25
- package/src/mutation/MutationAppendRequest.ts +52 -0
- package/src/mutation/MutationCreateRule.ts +2 -2
- package/src/mutation/MutationPeering.ts +37 -0
- package/src/mutation/MutationRequestAuthorization.ts +3 -3
- package/src/query/QueryActiveSession.ts +0 -1
- package/src/query/QueryContinuId.ts +8 -0
- package/src/query/QueryMetaTypeViaMolecule.ts +221 -0
- package/src/query/QueryWalletList.ts +2 -2
- package/src/response/ResponseAppendRequest.ts +17 -0
- package/src/response/ResponseBalance.ts +8 -3
- package/src/response/ResponseContinuId.ts +1 -1
- package/src/response/ResponseMetaType.ts +32 -19
- package/src/response/ResponseMetaTypeViaMolecule.ts +224 -0
- package/src/response/ResponsePeering.ts +17 -0
- package/src/response/ResponsePolicy.ts +2 -3
- package/src/response/ResponseProposeMolecule.ts +0 -1
- package/src/response/ResponseRequestAuthorization.ts +32 -2
- package/src/response/ResponseRequestAuthorizationGuest.ts +25 -1
- package/src/response/ResponseWalletList.ts +1 -1
- package/src/types/guards.ts +18 -5
- package/src/types/index.ts +3 -3
package/dist/index.cjs
CHANGED
|
@@ -904,9 +904,19 @@ var init_UnauthenticatedException = __esm({
|
|
|
904
904
|
});
|
|
905
905
|
|
|
906
906
|
// src/exception/AuthorizationRejectedException.ts
|
|
907
|
+
var AuthorizationRejectedException, AuthorizationRejectedException_default;
|
|
907
908
|
var init_AuthorizationRejectedException = __esm({
|
|
908
909
|
"src/exception/AuthorizationRejectedException.ts"() {
|
|
909
910
|
init_BaseException();
|
|
911
|
+
AuthorizationRejectedException = class extends exports.BaseException {
|
|
912
|
+
/**
|
|
913
|
+
* Constructor
|
|
914
|
+
*/
|
|
915
|
+
constructor(message = "Authorization attempt rejected by ledger.") {
|
|
916
|
+
super("AUTHORIZATION_REJECTED_ERROR", message);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
AuthorizationRejectedException_default = AuthorizationRejectedException;
|
|
910
920
|
}
|
|
911
921
|
});
|
|
912
922
|
|
|
@@ -1301,7 +1311,7 @@ var init_Dot = __esm({
|
|
|
1301
1311
|
};
|
|
1302
1312
|
}
|
|
1303
1313
|
});
|
|
1304
|
-
var ResponseErrorSchema,
|
|
1314
|
+
var ResponseErrorSchema, ValidationResultSchema2;
|
|
1305
1315
|
var init_response = __esm({
|
|
1306
1316
|
"src/types/response.ts"() {
|
|
1307
1317
|
ResponseErrorSchema = zod.z.object({
|
|
@@ -1312,7 +1322,7 @@ var init_response = __esm({
|
|
|
1312
1322
|
timestamp: zod.z.string().optional(),
|
|
1313
1323
|
operation: zod.z.string().optional()
|
|
1314
1324
|
});
|
|
1315
|
-
|
|
1325
|
+
ValidationResultSchema2 = zod.z.object({
|
|
1316
1326
|
success: zod.z.boolean(),
|
|
1317
1327
|
data: zod.z.any().optional(),
|
|
1318
1328
|
error: ResponseErrorSchema.optional(),
|
|
@@ -1502,7 +1512,7 @@ var init_EnhancedResponse = __esm({
|
|
|
1502
1512
|
// Enhanced response validation
|
|
1503
1513
|
validate() {
|
|
1504
1514
|
try {
|
|
1505
|
-
|
|
1515
|
+
ValidationResultSchema2.parse(this.toValidationResult());
|
|
1506
1516
|
return {
|
|
1507
1517
|
success: true,
|
|
1508
1518
|
data: this._payload,
|
|
@@ -1753,7 +1763,7 @@ function chunkSubstr(str, size) {
|
|
|
1753
1763
|
}
|
|
1754
1764
|
return chunks;
|
|
1755
1765
|
}
|
|
1756
|
-
function randomString(length = 32, alphabet = "
|
|
1766
|
+
function randomString(length = 32, alphabet = "abcdef0123456789") {
|
|
1757
1767
|
if (length <= 0) return "";
|
|
1758
1768
|
let result = "";
|
|
1759
1769
|
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
@@ -1774,26 +1784,26 @@ function charsetBaseConvert(src, fromBase, toBase, srcSymbolTable = "0123456789a
|
|
|
1774
1784
|
return false;
|
|
1775
1785
|
}
|
|
1776
1786
|
try {
|
|
1777
|
-
let
|
|
1778
|
-
const
|
|
1779
|
-
for (let
|
|
1780
|
-
const
|
|
1781
|
-
|
|
1782
|
-
if (charIndex === -1) {
|
|
1787
|
+
let val = BigInt(0);
|
|
1788
|
+
const bigFromBase = BigInt(fromBase);
|
|
1789
|
+
for (let charIndex = 0; charIndex < src.length; charIndex++) {
|
|
1790
|
+
const symbolIndex = srcSymbolTable.indexOf(src.charAt(charIndex));
|
|
1791
|
+
if (symbolIndex === -1) {
|
|
1783
1792
|
return false;
|
|
1784
1793
|
}
|
|
1785
|
-
|
|
1794
|
+
val = val * bigFromBase + BigInt(symbolIndex);
|
|
1786
1795
|
}
|
|
1787
|
-
if (
|
|
1796
|
+
if (val === BigInt(0)) {
|
|
1788
1797
|
return destSymbolTable.charAt(0);
|
|
1789
1798
|
}
|
|
1799
|
+
const bigToBase = BigInt(toBase);
|
|
1790
1800
|
let result = "";
|
|
1791
|
-
while (
|
|
1792
|
-
const remainder =
|
|
1793
|
-
result = destSymbolTable.charAt(remainder) + result;
|
|
1794
|
-
|
|
1801
|
+
while (val > BigInt(0)) {
|
|
1802
|
+
const remainder = val % bigToBase;
|
|
1803
|
+
result = destSymbolTable.charAt(Number(remainder)) + result;
|
|
1804
|
+
val = val / bigToBase;
|
|
1795
1805
|
}
|
|
1796
|
-
return result;
|
|
1806
|
+
return result || "0";
|
|
1797
1807
|
} catch (error) {
|
|
1798
1808
|
return false;
|
|
1799
1809
|
}
|
|
@@ -1918,15 +1928,11 @@ function generateSecret(seed = null, length = CRYPTO_CONSTANTS.SECRET_LENGTH) {
|
|
|
1918
1928
|
return randomString(length);
|
|
1919
1929
|
}
|
|
1920
1930
|
}
|
|
1921
|
-
function generateBundleHash(secret,
|
|
1931
|
+
function generateBundleHash(secret, _source = null) {
|
|
1922
1932
|
if (!secret || secret.length === 0) {
|
|
1923
1933
|
throw new Error("Secret is required for bundle hash generation");
|
|
1924
1934
|
}
|
|
1925
|
-
|
|
1926
|
-
if (source) {
|
|
1927
|
-
input = secret + source;
|
|
1928
|
-
}
|
|
1929
|
-
const hash = shake256(input, CRYPTO_CONSTANTS.BUNDLE_HASH_LENGTH * 4);
|
|
1935
|
+
const hash = shake256(secret, CRYPTO_CONSTANTS.BUNDLE_HASH_LENGTH * 4);
|
|
1930
1936
|
return hash;
|
|
1931
1937
|
}
|
|
1932
1938
|
function generatePosition() {
|
|
@@ -1937,17 +1943,10 @@ function generateBatchId({
|
|
|
1937
1943
|
molecularHash = null,
|
|
1938
1944
|
index = null
|
|
1939
1945
|
} = {}) {
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
input += molecularHash;
|
|
1943
|
-
}
|
|
1944
|
-
if (index !== null) {
|
|
1945
|
-
input += index.toString();
|
|
1946
|
-
}
|
|
1947
|
-
if (input === "") {
|
|
1948
|
-
input = randomString(32);
|
|
1946
|
+
if (molecularHash && index !== null) {
|
|
1947
|
+
return shake256(molecularHash + index, 256);
|
|
1949
1948
|
}
|
|
1950
|
-
return
|
|
1949
|
+
return randomString(64);
|
|
1951
1950
|
}
|
|
1952
1951
|
function generateWalletKey({
|
|
1953
1952
|
secret,
|
|
@@ -2255,63 +2254,134 @@ function runExtendedCompatibilityTests() {
|
|
|
2255
2254
|
return { passed: allPassed, results };
|
|
2256
2255
|
}
|
|
2257
2256
|
|
|
2258
|
-
// src/
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
"ATOM_INDEX_ERROR",
|
|
2262
|
-
"ATOMS_MISSING_ERROR",
|
|
2263
|
-
"AUTHORIZATION_REJECTED_ERROR",
|
|
2264
|
-
"BALANCE_INSUFFICIENT_ERROR",
|
|
2265
|
-
"BATCH_ID_ERROR",
|
|
2266
|
-
"CODE_ERROR",
|
|
2267
|
-
"DECRYPTION_KEY_ERROR",
|
|
2268
|
-
"INVALID_RESPONSE_ERROR",
|
|
2269
|
-
"META_MISSING_ERROR",
|
|
2270
|
-
"MOLECULAR_HASH_MISMATCH_ERROR",
|
|
2271
|
-
"MOLECULAR_HASH_MISSING_ERROR",
|
|
2272
|
-
"NEGATIVE_AMOUNT_ERROR",
|
|
2273
|
-
"POLICY_INVALID_ERROR",
|
|
2274
|
-
"RULE_ARGUMENT_ERROR",
|
|
2275
|
-
"SIGNATURE_MALFORMED_ERROR",
|
|
2276
|
-
"SIGNATURE_MISMATCH_ERROR",
|
|
2277
|
-
"STACKABLE_UNIT_AMOUNT_ERROR",
|
|
2278
|
-
"STACKABLE_UNIT_DECIMALS_ERROR",
|
|
2279
|
-
"TRANSFER_BALANCE_ERROR",
|
|
2280
|
-
"TRANSFER_MALFORMED_ERROR",
|
|
2281
|
-
"TRANSFER_MISMATCHED_ERROR",
|
|
2282
|
-
"TRANSFER_REMAINDER_ERROR",
|
|
2283
|
-
"TRANSFER_TO_SELF_ERROR",
|
|
2284
|
-
"TRANSFER_UNBALANCED_ERROR",
|
|
2285
|
-
"UNAUTHENTICATED_ERROR",
|
|
2286
|
-
"WALLET_CREDENTIAL_ERROR",
|
|
2287
|
-
"WALLET_SHADOW_ERROR",
|
|
2288
|
-
"WRONG_TOKEN_TYPE_ERROR"
|
|
2289
|
-
];
|
|
2290
|
-
var PROTOCOL_CONFIG = {
|
|
2291
|
-
DEFAULT_SDK_VERSION: 4};
|
|
2292
|
-
var QUERY_TYPES = [
|
|
2293
|
-
"Balance",
|
|
2294
|
-
"WalletBundle",
|
|
2295
|
-
"WalletList",
|
|
2296
|
-
"Atom",
|
|
2297
|
-
"MetaType",
|
|
2298
|
-
"MetaTypeViaAtom",
|
|
2299
|
-
"ContinuId",
|
|
2300
|
-
"Batch",
|
|
2301
|
-
"ActiveSession",
|
|
2302
|
-
"Policy",
|
|
2303
|
-
"Token",
|
|
2304
|
-
"UserActivity"
|
|
2305
|
-
];
|
|
2306
|
-
function createLookup(values) {
|
|
2307
|
-
return values.reduce((acc, value) => {
|
|
2308
|
-
acc[value] = value;
|
|
2309
|
-
return acc;
|
|
2310
|
-
}, {});
|
|
2257
|
+
// src/versions/HashAtom.ts
|
|
2258
|
+
function isObject(value) {
|
|
2259
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2311
2260
|
}
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2261
|
+
function isArray(value) {
|
|
2262
|
+
return Array.isArray(value);
|
|
2263
|
+
}
|
|
2264
|
+
function isPrimitive(value) {
|
|
2265
|
+
return value === null || value === void 0 || ["string", "number", "boolean"].includes(typeof value);
|
|
2266
|
+
}
|
|
2267
|
+
var HashAtom = class _HashAtom {
|
|
2268
|
+
/**
|
|
2269
|
+
* Creates a HashAtom instance from an Atom with proper typing
|
|
2270
|
+
*/
|
|
2271
|
+
static create(atom) {
|
|
2272
|
+
const parameters = {};
|
|
2273
|
+
for (const key of Object.keys(atom)) {
|
|
2274
|
+
if (Object.prototype.hasOwnProperty.call(atom, key)) {
|
|
2275
|
+
parameters[key] = atom[key];
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
return new this(parameters);
|
|
2279
|
+
}
|
|
2280
|
+
/**
|
|
2281
|
+
* Recursively structures an object or array for hashing consistency
|
|
2282
|
+
* Eliminates any types with proper generic constraints
|
|
2283
|
+
*/
|
|
2284
|
+
static structure(object) {
|
|
2285
|
+
if (isPrimitive(object)) {
|
|
2286
|
+
return object;
|
|
2287
|
+
}
|
|
2288
|
+
if (isArray(object)) {
|
|
2289
|
+
const result = [];
|
|
2290
|
+
for (const value of object) {
|
|
2291
|
+
result.push(_HashAtom.isStructure(value) ? _HashAtom.structure(value) : value);
|
|
2292
|
+
}
|
|
2293
|
+
return result;
|
|
2294
|
+
}
|
|
2295
|
+
if (isObject(object)) {
|
|
2296
|
+
const result = [];
|
|
2297
|
+
const keys = Object.keys(object).sort((first, second) => {
|
|
2298
|
+
if (first === second) {
|
|
2299
|
+
return 0;
|
|
2300
|
+
}
|
|
2301
|
+
return first < second ? -1 : 1;
|
|
2302
|
+
});
|
|
2303
|
+
for (const key of keys) {
|
|
2304
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
2305
|
+
const item = {};
|
|
2306
|
+
const value = object[key];
|
|
2307
|
+
item[key] = _HashAtom.isStructure(value) ? _HashAtom.structure(value) : value;
|
|
2308
|
+
result.push(item);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
if (result.length > 0) {
|
|
2312
|
+
return result;
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
return object;
|
|
2316
|
+
}
|
|
2317
|
+
/**
|
|
2318
|
+
* Type guard to determine if a value needs recursive structure processing
|
|
2319
|
+
*/
|
|
2320
|
+
static isStructure(structure) {
|
|
2321
|
+
return isObject(structure) || isArray(structure);
|
|
2322
|
+
}
|
|
2323
|
+
/**
|
|
2324
|
+
* Returns the structured view of this HashAtom instance
|
|
2325
|
+
*/
|
|
2326
|
+
view() {
|
|
2327
|
+
return _HashAtom.structure(this);
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Protected constructor to support subclass instantiation
|
|
2331
|
+
*/
|
|
2332
|
+
constructor(params = {}) {
|
|
2333
|
+
Object.assign(this, params);
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
|
|
2337
|
+
// src/versions/Version4.ts
|
|
2338
|
+
var Version4 = class extends HashAtom {
|
|
2339
|
+
position;
|
|
2340
|
+
walletAddress;
|
|
2341
|
+
isotope;
|
|
2342
|
+
token;
|
|
2343
|
+
value;
|
|
2344
|
+
batchId;
|
|
2345
|
+
metaType;
|
|
2346
|
+
metaId;
|
|
2347
|
+
meta;
|
|
2348
|
+
index;
|
|
2349
|
+
createdAt;
|
|
2350
|
+
version;
|
|
2351
|
+
constructor({
|
|
2352
|
+
position = null,
|
|
2353
|
+
walletAddress = null,
|
|
2354
|
+
isotope = null,
|
|
2355
|
+
token = null,
|
|
2356
|
+
value = null,
|
|
2357
|
+
batchId = null,
|
|
2358
|
+
metaType = null,
|
|
2359
|
+
metaId = null,
|
|
2360
|
+
meta = null,
|
|
2361
|
+
index = null,
|
|
2362
|
+
createdAt = null,
|
|
2363
|
+
version = null
|
|
2364
|
+
} = {}) {
|
|
2365
|
+
super();
|
|
2366
|
+
this.position = position;
|
|
2367
|
+
this.walletAddress = walletAddress;
|
|
2368
|
+
this.isotope = isotope;
|
|
2369
|
+
this.token = token;
|
|
2370
|
+
this.value = value;
|
|
2371
|
+
this.batchId = batchId;
|
|
2372
|
+
this.metaType = metaType;
|
|
2373
|
+
this.metaId = metaId;
|
|
2374
|
+
this.meta = meta;
|
|
2375
|
+
this.index = index;
|
|
2376
|
+
this.createdAt = createdAt;
|
|
2377
|
+
this.version = version;
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
|
|
2381
|
+
// src/versions/index.ts
|
|
2382
|
+
var versions_default = {
|
|
2383
|
+
4: Version4
|
|
2384
|
+
};
|
|
2315
2385
|
|
|
2316
2386
|
// src/types/guards.ts
|
|
2317
2387
|
function assertNever(value) {
|
|
@@ -2337,6 +2407,10 @@ function handleIsotope(isotope, handlers) {
|
|
|
2337
2407
|
return handlers.B();
|
|
2338
2408
|
case "F":
|
|
2339
2409
|
return handlers.F();
|
|
2410
|
+
case "P":
|
|
2411
|
+
return handlers.P();
|
|
2412
|
+
case "A":
|
|
2413
|
+
return handlers.A();
|
|
2340
2414
|
default:
|
|
2341
2415
|
return assertNever(isotope);
|
|
2342
2416
|
}
|
|
@@ -2348,126 +2422,537 @@ function isPosition(value) {
|
|
|
2348
2422
|
return typeof value === "string" && value.length === 64 && /^[0-9a-fA-F]{64}$/.test(value);
|
|
2349
2423
|
}
|
|
2350
2424
|
|
|
2351
|
-
// src/core/
|
|
2352
|
-
var
|
|
2353
|
-
|
|
2354
|
-
WALLET_ADDRESS: "",
|
|
2355
|
-
ISOTOPE: "C",
|
|
2356
|
-
TOKEN: "USER",
|
|
2357
|
-
VALUE: null,
|
|
2358
|
-
BATCH_ID: null,
|
|
2359
|
-
META_TYPE: null,
|
|
2360
|
-
META_ID: null,
|
|
2361
|
-
META: [],
|
|
2362
|
-
OTS_FRAGMENT: null,
|
|
2363
|
-
INDEX: null,
|
|
2364
|
-
VERSION: PROTOCOL_CONFIG.DEFAULT_SDK_VERSION
|
|
2365
|
-
};
|
|
2366
|
-
var Atom = class _Atom {
|
|
2367
|
-
// Core properties matching JS SDK exactly
|
|
2368
|
-
position;
|
|
2369
|
-
walletAddress;
|
|
2370
|
-
isotope;
|
|
2371
|
-
token;
|
|
2372
|
-
value;
|
|
2373
|
-
batchId;
|
|
2374
|
-
metaType;
|
|
2375
|
-
metaId;
|
|
2376
|
-
meta;
|
|
2377
|
-
otsFragment;
|
|
2378
|
-
index;
|
|
2379
|
-
createdAt;
|
|
2380
|
-
version;
|
|
2425
|
+
// src/core/Meta.ts
|
|
2426
|
+
var Meta = class {
|
|
2427
|
+
// No instance properties - this class only provides static methods
|
|
2381
2428
|
/**
|
|
2382
|
-
*
|
|
2383
|
-
*
|
|
2429
|
+
* Normalize metadata to consistent format
|
|
2430
|
+
* Matches JavaScript SDK Meta.normalizeMeta exactly
|
|
2384
2431
|
*/
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2432
|
+
static normalizeMeta(meta) {
|
|
2433
|
+
if (!meta) {
|
|
2434
|
+
return [];
|
|
2435
|
+
}
|
|
2436
|
+
if (Array.isArray(meta)) {
|
|
2437
|
+
return meta.map((item) => {
|
|
2438
|
+
if (typeof item === "object" && item !== null && "key" in item) {
|
|
2439
|
+
return {
|
|
2440
|
+
key: String(item.key),
|
|
2441
|
+
value: item.value == null ? null : String(item.value)
|
|
2442
|
+
};
|
|
2443
|
+
}
|
|
2444
|
+
return {
|
|
2445
|
+
key: "unknown",
|
|
2446
|
+
value: String(item)
|
|
2447
|
+
};
|
|
2448
|
+
});
|
|
2449
|
+
}
|
|
2450
|
+
if (typeof meta === "object" && meta !== null) {
|
|
2451
|
+
const target = [];
|
|
2452
|
+
for (const property in meta) {
|
|
2453
|
+
if (Object.prototype.hasOwnProperty.call(meta, property)) {
|
|
2454
|
+
const raw = meta[property];
|
|
2455
|
+
target.push({ key: property, value: raw == null ? null : String(raw) });
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
return target;
|
|
2459
|
+
}
|
|
2460
|
+
return [{
|
|
2461
|
+
key: "value",
|
|
2462
|
+
value: String(meta)
|
|
2463
|
+
}];
|
|
2413
2464
|
}
|
|
2414
|
-
// =============================================================================
|
|
2415
|
-
// INSTANCE METHODS - MATCH JAVASCRIPT SDK
|
|
2416
|
-
// =============================================================================
|
|
2417
2465
|
/**
|
|
2418
|
-
*
|
|
2419
|
-
* Matches JavaScript SDK Meta.aggregateMeta
|
|
2466
|
+
* Aggregate metadata into single object
|
|
2467
|
+
* Matches JavaScript SDK Meta.aggregateMeta exactly
|
|
2420
2468
|
*/
|
|
2421
|
-
|
|
2469
|
+
static aggregateMeta(metaItems) {
|
|
2470
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2471
|
+
return {};
|
|
2472
|
+
}
|
|
2422
2473
|
const aggregated = {};
|
|
2423
|
-
for (const
|
|
2424
|
-
if (
|
|
2425
|
-
|
|
2474
|
+
for (const item of metaItems) {
|
|
2475
|
+
if (item && typeof item === "object" && "key" in item) {
|
|
2476
|
+
const key = String(item.key);
|
|
2477
|
+
if ("value" in item) {
|
|
2478
|
+
aggregated[key] = item.value;
|
|
2479
|
+
} else {
|
|
2480
|
+
const { key: itemKey, ...restOfItem } = item;
|
|
2481
|
+
aggregated[key] = Object.keys(restOfItem).length === 1 && "value" in restOfItem ? restOfItem.value : restOfItem;
|
|
2482
|
+
}
|
|
2426
2483
|
}
|
|
2427
2484
|
}
|
|
2428
2485
|
return aggregated;
|
|
2429
2486
|
}
|
|
2430
2487
|
/**
|
|
2431
|
-
*
|
|
2432
|
-
*
|
|
2488
|
+
* Merge multiple metadata arrays
|
|
2489
|
+
* Combines arrays while preserving order and handling duplicates
|
|
2433
2490
|
*/
|
|
2434
|
-
|
|
2435
|
-
const
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
if (
|
|
2491
|
+
static mergeMeta(...metaArrays) {
|
|
2492
|
+
const merged = [];
|
|
2493
|
+
const keysSeen = /* @__PURE__ */ new Set();
|
|
2494
|
+
for (const metaArray of metaArrays) {
|
|
2495
|
+
if (!metaArray || !Array.isArray(metaArray)) {
|
|
2439
2496
|
continue;
|
|
2440
2497
|
}
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
}
|
|
2498
|
+
const normalized = this.normalizeMeta(metaArray);
|
|
2499
|
+
for (const item of normalized) {
|
|
2500
|
+
let finalKey = item.key;
|
|
2501
|
+
let counter = 1;
|
|
2502
|
+
while (keysSeen.has(finalKey)) {
|
|
2503
|
+
finalKey = `${item.key}_${counter}`;
|
|
2504
|
+
counter++;
|
|
2447
2505
|
}
|
|
2448
|
-
|
|
2449
|
-
|
|
2506
|
+
keysSeen.add(finalKey);
|
|
2507
|
+
merged.push({
|
|
2508
|
+
...item,
|
|
2509
|
+
key: finalKey
|
|
2510
|
+
});
|
|
2450
2511
|
}
|
|
2451
2512
|
}
|
|
2452
|
-
return
|
|
2513
|
+
return merged;
|
|
2453
2514
|
}
|
|
2454
2515
|
/**
|
|
2455
|
-
*
|
|
2456
|
-
* Separate from hashable values to maintain proper typing
|
|
2516
|
+
* Filter metadata by key pattern or predicate
|
|
2457
2517
|
*/
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2518
|
+
static filterMeta(metaItems, filter) {
|
|
2519
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2520
|
+
return [];
|
|
2521
|
+
}
|
|
2522
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2523
|
+
if (typeof filter === "string") {
|
|
2524
|
+
return normalized.filter((item) => item.key.includes(filter));
|
|
2525
|
+
}
|
|
2526
|
+
if (filter instanceof RegExp) {
|
|
2527
|
+
return normalized.filter((item) => filter.test(item.key));
|
|
2528
|
+
}
|
|
2529
|
+
if (typeof filter === "function") {
|
|
2530
|
+
return normalized.filter(filter);
|
|
2531
|
+
}
|
|
2532
|
+
return normalized;
|
|
2533
|
+
}
|
|
2534
|
+
/**
|
|
2535
|
+
* Find metadata item by key
|
|
2536
|
+
*/
|
|
2537
|
+
static findMeta(metaItems, key) {
|
|
2538
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2539
|
+
return null;
|
|
2540
|
+
}
|
|
2541
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2542
|
+
return normalized.find((item) => item.key === key) || null;
|
|
2543
|
+
}
|
|
2544
|
+
/**
|
|
2545
|
+
* Get metadata value by key
|
|
2546
|
+
*/
|
|
2547
|
+
static getMetaValue(metaItems, key, defaultValue = null) {
|
|
2548
|
+
const item = this.findMeta(metaItems, key);
|
|
2549
|
+
return item ? item.value : defaultValue;
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Set or update metadata item by key
|
|
2553
|
+
*/
|
|
2554
|
+
static setMeta(metaItems, key, value) {
|
|
2555
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2556
|
+
const existingIndex = normalized.findIndex((item) => item.key === key);
|
|
2557
|
+
const newItem = {
|
|
2558
|
+
key,
|
|
2559
|
+
value: value == null ? null : String(value)
|
|
2560
|
+
};
|
|
2561
|
+
if (existingIndex >= 0) {
|
|
2562
|
+
normalized[existingIndex] = newItem;
|
|
2563
|
+
} else {
|
|
2564
|
+
normalized.push(newItem);
|
|
2565
|
+
}
|
|
2566
|
+
return normalized;
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Remove metadata item by key
|
|
2570
|
+
*/
|
|
2571
|
+
static removeMeta(metaItems, key) {
|
|
2572
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2573
|
+
return [];
|
|
2574
|
+
}
|
|
2575
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2576
|
+
return normalized.filter((item) => item.key !== key);
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Convert metadata to JSON-serializable format
|
|
2580
|
+
*/
|
|
2581
|
+
static toJSON(metaItems) {
|
|
2582
|
+
return this.aggregateMeta(this.normalizeMeta(metaItems));
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* Create metadata from JSON object
|
|
2586
|
+
*/
|
|
2587
|
+
static fromJSON(jsonData) {
|
|
2588
|
+
if (!jsonData || typeof jsonData !== "object") {
|
|
2589
|
+
return [];
|
|
2590
|
+
}
|
|
2591
|
+
return Object.entries(jsonData).map(([key, value]) => ({
|
|
2592
|
+
key,
|
|
2593
|
+
value: value == null ? null : String(value)
|
|
2594
|
+
}));
|
|
2595
|
+
}
|
|
2596
|
+
/**
|
|
2597
|
+
* Validate metadata structure
|
|
2598
|
+
*/
|
|
2599
|
+
static validateMeta(metaItems) {
|
|
2600
|
+
if (!Array.isArray(metaItems)) {
|
|
2601
|
+
return false;
|
|
2602
|
+
}
|
|
2603
|
+
return metaItems.every(
|
|
2604
|
+
(item) => item && typeof item === "object" && "key" in item && typeof item.key === "string"
|
|
2605
|
+
);
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* Get all unique keys from metadata
|
|
2609
|
+
*/
|
|
2610
|
+
static getKeys(metaItems) {
|
|
2611
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2612
|
+
return [];
|
|
2613
|
+
}
|
|
2614
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2615
|
+
const keys = /* @__PURE__ */ new Set();
|
|
2616
|
+
for (const item of normalized) {
|
|
2617
|
+
keys.add(item.key);
|
|
2618
|
+
}
|
|
2619
|
+
return Array.from(keys);
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Check if metadata contains specific key
|
|
2623
|
+
*/
|
|
2624
|
+
static hasKey(metaItems, key) {
|
|
2625
|
+
return this.getKeys(metaItems).includes(key);
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* Get metadata statistics
|
|
2629
|
+
*/
|
|
2630
|
+
static getStats(metaItems) {
|
|
2631
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2632
|
+
return {
|
|
2633
|
+
totalItems: 0,
|
|
2634
|
+
uniqueKeys: 0,
|
|
2635
|
+
keys: [],
|
|
2636
|
+
valueTypes: {}
|
|
2637
|
+
};
|
|
2638
|
+
}
|
|
2639
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2640
|
+
const keys = this.getKeys(normalized);
|
|
2641
|
+
const valueTypes = {};
|
|
2642
|
+
for (const item of normalized) {
|
|
2643
|
+
const type = item.value === null ? "null" : typeof item.value;
|
|
2644
|
+
valueTypes[type] = (valueTypes[type] || 0) + 1;
|
|
2645
|
+
}
|
|
2646
|
+
return {
|
|
2647
|
+
totalItems: normalized.length,
|
|
2648
|
+
uniqueKeys: keys.length,
|
|
2649
|
+
keys,
|
|
2650
|
+
valueTypes
|
|
2651
|
+
};
|
|
2652
|
+
}
|
|
2653
|
+
/**
|
|
2654
|
+
* Deep clone metadata array
|
|
2655
|
+
*/
|
|
2656
|
+
static clone(metaItems) {
|
|
2657
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2658
|
+
return [];
|
|
2659
|
+
}
|
|
2660
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2661
|
+
return normalized.map((item) => ({ ...item }));
|
|
2662
|
+
}
|
|
2663
|
+
/**
|
|
2664
|
+
* Sort metadata by key
|
|
2665
|
+
*/
|
|
2666
|
+
static sort(metaItems, descending = false) {
|
|
2667
|
+
if (!metaItems || !Array.isArray(metaItems)) {
|
|
2668
|
+
return [];
|
|
2669
|
+
}
|
|
2670
|
+
const normalized = this.normalizeMeta(metaItems);
|
|
2671
|
+
return normalized.sort((a, b) => {
|
|
2672
|
+
const comparison = a.key.localeCompare(b.key);
|
|
2673
|
+
return descending ? -comparison : comparison;
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
};
|
|
2677
|
+
var AtomMeta = class _AtomMeta {
|
|
2678
|
+
meta;
|
|
2679
|
+
/**
|
|
2680
|
+
* Create new AtomMeta instance
|
|
2681
|
+
* @param meta - Initial metadata (object or array)
|
|
2682
|
+
*/
|
|
2683
|
+
constructor(meta = null) {
|
|
2684
|
+
this.meta = Meta.normalizeMeta(meta);
|
|
2685
|
+
}
|
|
2686
|
+
/**
|
|
2687
|
+
* Merge additional metadata
|
|
2688
|
+
* @param meta - Metadata to merge
|
|
2689
|
+
* @return This instance for chaining
|
|
2690
|
+
*/
|
|
2691
|
+
merge(meta) {
|
|
2692
|
+
this.meta = [...this.meta, ...Meta.normalizeMeta(meta)];
|
|
2693
|
+
return this;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Add context metadata if enabled
|
|
2697
|
+
* @param context - Context URL or null for default
|
|
2698
|
+
* @return This instance for chaining
|
|
2699
|
+
*/
|
|
2700
|
+
addContext(context = null) {
|
|
2701
|
+
return this;
|
|
2702
|
+
}
|
|
2703
|
+
/**
|
|
2704
|
+
* Set atom wallet metadata
|
|
2705
|
+
* @param wallet - Wallet to extract metadata from
|
|
2706
|
+
* @return This instance for chaining
|
|
2707
|
+
*/
|
|
2708
|
+
setAtomWallet(wallet) {
|
|
2709
|
+
const walletMeta = {};
|
|
2710
|
+
if (wallet.tokenUnits && wallet.tokenUnits.length) {
|
|
2711
|
+
walletMeta.tokenUnits = JSON.stringify(wallet.getTokenUnitsData ? wallet.getTokenUnitsData() : wallet.tokenUnits);
|
|
2712
|
+
}
|
|
2713
|
+
if (wallet.tradeRates && wallet.tradeRates.length) {
|
|
2714
|
+
walletMeta.tradeRates = JSON.stringify(wallet.tradeRates);
|
|
2715
|
+
}
|
|
2716
|
+
if (Object.keys(walletMeta).length > 0) {
|
|
2717
|
+
this.merge(walletMeta);
|
|
2718
|
+
}
|
|
2719
|
+
return this;
|
|
2720
|
+
}
|
|
2721
|
+
/**
|
|
2722
|
+
* Set full NEW wallet metadata
|
|
2723
|
+
* Used for shadow wallet claim & wallet creation & token creation
|
|
2724
|
+
* @param wallet - Wallet with full metadata
|
|
2725
|
+
* @return This instance for chaining
|
|
2726
|
+
*/
|
|
2727
|
+
setMetaWallet(wallet) {
|
|
2728
|
+
this.merge({
|
|
2729
|
+
walletTokenSlug: wallet.token,
|
|
2730
|
+
walletBundleHash: wallet.bundle,
|
|
2731
|
+
walletAddress: wallet.address,
|
|
2732
|
+
walletPosition: wallet.position,
|
|
2733
|
+
walletBatchId: wallet.batchId,
|
|
2734
|
+
walletPubkey: wallet.pubkey,
|
|
2735
|
+
walletCharacters: wallet.characters
|
|
2736
|
+
});
|
|
2737
|
+
return this;
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Set shadow wallet claim flag
|
|
2741
|
+
* @param shadowWalletClaim - Claim flag (converted to number)
|
|
2742
|
+
* @return This instance for chaining
|
|
2743
|
+
*/
|
|
2744
|
+
setShadowWalletClaim(shadowWalletClaim) {
|
|
2745
|
+
this.merge({ shadowWalletClaim: Number(shadowWalletClaim) });
|
|
2746
|
+
return this;
|
|
2747
|
+
}
|
|
2748
|
+
/**
|
|
2749
|
+
* Set signing wallet metadata
|
|
2750
|
+
* @param signingWallet - Wallet used for signing
|
|
2751
|
+
* @return This instance for chaining
|
|
2752
|
+
*/
|
|
2753
|
+
setSigningWallet(signingWallet) {
|
|
2754
|
+
this.merge({
|
|
2755
|
+
signingWallet: JSON.stringify({
|
|
2756
|
+
tokenSlug: signingWallet.token,
|
|
2757
|
+
bundleHash: signingWallet.bundle,
|
|
2758
|
+
address: signingWallet.address,
|
|
2759
|
+
position: signingWallet.position,
|
|
2760
|
+
pubkey: signingWallet.pubkey,
|
|
2761
|
+
characters: signingWallet.characters
|
|
2762
|
+
})
|
|
2763
|
+
});
|
|
2764
|
+
return this;
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* Add policy metadata
|
|
2768
|
+
* @param policy - Policy object to add
|
|
2769
|
+
* @return This instance for chaining
|
|
2770
|
+
*/
|
|
2771
|
+
addPolicy(policy) {
|
|
2772
|
+
this.merge({
|
|
2773
|
+
policy: JSON.stringify(policy)
|
|
2774
|
+
});
|
|
2775
|
+
return this;
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* Get the normalized metadata array
|
|
2779
|
+
* @return Array of normalized metadata items
|
|
2780
|
+
*/
|
|
2781
|
+
get() {
|
|
2782
|
+
return this.meta;
|
|
2783
|
+
}
|
|
2784
|
+
/**
|
|
2785
|
+
* Convert metadata to plain object
|
|
2786
|
+
* @return Aggregated metadata object
|
|
2787
|
+
*/
|
|
2788
|
+
toObject() {
|
|
2789
|
+
return Meta.aggregateMeta(this.meta);
|
|
2790
|
+
}
|
|
2791
|
+
/**
|
|
2792
|
+
* Convert metadata to JSON string
|
|
2793
|
+
* @return JSON string representation
|
|
2794
|
+
*/
|
|
2795
|
+
toJSON() {
|
|
2796
|
+
return JSON.stringify(this.toObject());
|
|
2797
|
+
}
|
|
2798
|
+
/**
|
|
2799
|
+
* Get metadata value by key
|
|
2800
|
+
* @param key - Key to lookup
|
|
2801
|
+
* @param defaultValue - Default if not found
|
|
2802
|
+
* @return Value or default
|
|
2803
|
+
*/
|
|
2804
|
+
getValue(key, defaultValue = null) {
|
|
2805
|
+
return Meta.getMetaValue(this.meta, key, defaultValue);
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Check if metadata has a key
|
|
2809
|
+
* @param key - Key to check
|
|
2810
|
+
* @return True if key exists
|
|
2811
|
+
*/
|
|
2812
|
+
hasKey(key) {
|
|
2813
|
+
return Meta.hasKey(this.meta, key);
|
|
2814
|
+
}
|
|
2815
|
+
/**
|
|
2816
|
+
* Remove metadata by key
|
|
2817
|
+
* @param key - Key to remove
|
|
2818
|
+
* @return This instance for chaining
|
|
2819
|
+
*/
|
|
2820
|
+
remove(key) {
|
|
2821
|
+
this.meta = Meta.removeMeta(this.meta, key);
|
|
2822
|
+
return this;
|
|
2823
|
+
}
|
|
2824
|
+
/**
|
|
2825
|
+
* Clear all metadata
|
|
2826
|
+
* @return This instance for chaining
|
|
2827
|
+
*/
|
|
2828
|
+
clear() {
|
|
2829
|
+
this.meta = [];
|
|
2830
|
+
return this;
|
|
2831
|
+
}
|
|
2832
|
+
/**
|
|
2833
|
+
* Get count of metadata items
|
|
2834
|
+
* @return Number of items
|
|
2835
|
+
*/
|
|
2836
|
+
count() {
|
|
2837
|
+
return this.meta.length;
|
|
2838
|
+
}
|
|
2839
|
+
/**
|
|
2840
|
+
* Clone this AtomMeta instance
|
|
2841
|
+
* @return New AtomMeta with same data
|
|
2842
|
+
*/
|
|
2843
|
+
clone() {
|
|
2844
|
+
return new _AtomMeta(Meta.clone(this.meta));
|
|
2845
|
+
}
|
|
2846
|
+
};
|
|
2847
|
+
var Atom = class _Atom {
|
|
2848
|
+
// Core properties matching JS SDK exactly (all default to null)
|
|
2849
|
+
position;
|
|
2850
|
+
walletAddress;
|
|
2851
|
+
isotope;
|
|
2852
|
+
token;
|
|
2853
|
+
value;
|
|
2854
|
+
batchId;
|
|
2855
|
+
metaType;
|
|
2856
|
+
metaId;
|
|
2857
|
+
meta;
|
|
2858
|
+
otsFragment;
|
|
2859
|
+
index;
|
|
2860
|
+
createdAt;
|
|
2861
|
+
version;
|
|
2862
|
+
/**
|
|
2863
|
+
* Create a new Atom instance
|
|
2864
|
+
* Constructor signature matches JavaScript SDK exactly
|
|
2865
|
+
*/
|
|
2866
|
+
constructor({
|
|
2867
|
+
position = null,
|
|
2868
|
+
walletAddress = null,
|
|
2869
|
+
isotope = null,
|
|
2870
|
+
token = null,
|
|
2871
|
+
value = null,
|
|
2872
|
+
batchId = null,
|
|
2873
|
+
metaType = null,
|
|
2874
|
+
metaId = null,
|
|
2875
|
+
meta = null,
|
|
2876
|
+
otsFragment = null,
|
|
2877
|
+
index = null,
|
|
2878
|
+
createdAt = null,
|
|
2879
|
+
version = null
|
|
2880
|
+
} = {}) {
|
|
2881
|
+
this.position = position;
|
|
2882
|
+
this.walletAddress = walletAddress;
|
|
2883
|
+
this.isotope = isotope;
|
|
2884
|
+
this.token = token;
|
|
2885
|
+
this.value = value !== null && value !== void 0 ? String(value) : null;
|
|
2886
|
+
this.batchId = batchId;
|
|
2887
|
+
this.metaType = metaType;
|
|
2888
|
+
this.metaId = metaId;
|
|
2889
|
+
this.meta = meta ? Meta.normalizeMeta(meta) : [];
|
|
2890
|
+
this.otsFragment = otsFragment;
|
|
2891
|
+
this.index = index;
|
|
2892
|
+
if (version !== null && version !== void 0 && Object.prototype.hasOwnProperty.call(versions_default, version)) {
|
|
2893
|
+
this.version = String(version);
|
|
2894
|
+
}
|
|
2895
|
+
this.createdAt = createdAt || String(+/* @__PURE__ */ new Date());
|
|
2896
|
+
}
|
|
2897
|
+
// =============================================================================
|
|
2898
|
+
// INSTANCE METHODS - MATCH JAVASCRIPT SDK
|
|
2899
|
+
// =============================================================================
|
|
2900
|
+
/**
|
|
2901
|
+
* Get aggregated metadata for this atom
|
|
2902
|
+
* Matches JavaScript SDK Meta.aggregateMeta functionality
|
|
2903
|
+
*/
|
|
2904
|
+
aggregatedMeta() {
|
|
2905
|
+
const aggregated = {};
|
|
2906
|
+
for (const metaItem of this.meta) {
|
|
2907
|
+
if (metaItem && typeof metaItem === "object" && "key" in metaItem) {
|
|
2908
|
+
aggregated[metaItem.key] = metaItem.value;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
return aggregated;
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Get values that will be used for hashing
|
|
2915
|
+
* Must match JavaScript SDK getHashableValues exactly - returns array of strings!
|
|
2916
|
+
*/
|
|
2917
|
+
getHashableValues() {
|
|
2918
|
+
const hashableValues = [];
|
|
2919
|
+
for (const property of _Atom.getHashableProps()) {
|
|
2920
|
+
const value = this[property];
|
|
2921
|
+
if (value === null && !["position", "walletAddress"].includes(property)) {
|
|
2922
|
+
continue;
|
|
2923
|
+
}
|
|
2924
|
+
if (property === "meta") {
|
|
2925
|
+
for (const meta of value) {
|
|
2926
|
+
if (typeof meta.value !== "undefined" && meta.value !== null) {
|
|
2927
|
+
hashableValues.push(String(meta.key));
|
|
2928
|
+
hashableValues.push(String(meta.value));
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
} else {
|
|
2932
|
+
hashableValues.push(value === null ? "" : String(value));
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
return hashableValues;
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* Get structured data for JSON serialization
|
|
2939
|
+
* Separate from hashable values to maintain proper typing
|
|
2940
|
+
*/
|
|
2941
|
+
getStructuredData() {
|
|
2942
|
+
return {
|
|
2943
|
+
position: this.position || "",
|
|
2944
|
+
walletAddress: this.walletAddress?.toString() || "",
|
|
2945
|
+
isotope: this.isotope || "C",
|
|
2946
|
+
token: this.token?.toString() || "",
|
|
2947
|
+
value: this.value !== null ? this.value.toString() : null,
|
|
2465
2948
|
batchId: this.batchId?.toString() || null,
|
|
2466
2949
|
metaType: this.metaType?.toString() || null,
|
|
2467
2950
|
metaId: this.metaId?.toString() || null,
|
|
2468
|
-
|
|
2951
|
+
// Always return array for meta (server expects Vec<MetaItemInput>, not null)
|
|
2952
|
+
meta: this.meta.length > 0 ? [...this.meta] : [],
|
|
2469
2953
|
createdAt: this.createdAt,
|
|
2470
|
-
index: this.index !== null ? this.index : 0
|
|
2954
|
+
index: this.index !== null ? this.index : 0,
|
|
2955
|
+
version: this.version ?? null
|
|
2471
2956
|
};
|
|
2472
2957
|
}
|
|
2473
2958
|
/**
|
|
@@ -2496,9 +2981,19 @@ var Atom = class _Atom {
|
|
|
2496
2981
|
}
|
|
2497
2982
|
}
|
|
2498
2983
|
}
|
|
2499
|
-
const structuredData = this.getStructuredData();
|
|
2500
2984
|
const serialized = {
|
|
2501
|
-
|
|
2985
|
+
position: this.position ?? "",
|
|
2986
|
+
walletAddress: this.walletAddress ?? "",
|
|
2987
|
+
isotope: this.isotope,
|
|
2988
|
+
token: this.token ?? "",
|
|
2989
|
+
value: this.value,
|
|
2990
|
+
batchId: this.batchId,
|
|
2991
|
+
metaType: this.metaType,
|
|
2992
|
+
metaId: this.metaId,
|
|
2993
|
+
meta: this.meta || [],
|
|
2994
|
+
index: this.index,
|
|
2995
|
+
createdAt: this.createdAt,
|
|
2996
|
+
version: this.version
|
|
2502
2997
|
};
|
|
2503
2998
|
if (includeOtsFragments && this.otsFragment) {
|
|
2504
2999
|
serialized.otsFragment = this.otsFragment;
|
|
@@ -2535,6 +3030,7 @@ var Atom = class _Atom {
|
|
|
2535
3030
|
if (!isPosition(this.position) || !isWalletAddress(this.walletAddress)) {
|
|
2536
3031
|
return false;
|
|
2537
3032
|
}
|
|
3033
|
+
if (!this.isotope) return false;
|
|
2538
3034
|
return handleIsotope(this.isotope, {
|
|
2539
3035
|
V: () => this.value !== null && !isNaN(Number(this.value)),
|
|
2540
3036
|
// Value atoms must have numeric value
|
|
@@ -2552,8 +3048,12 @@ var Atom = class _Atom {
|
|
|
2552
3048
|
// Rule atoms
|
|
2553
3049
|
B: () => true,
|
|
2554
3050
|
// Buffer atoms
|
|
2555
|
-
F: () => true
|
|
3051
|
+
F: () => true,
|
|
2556
3052
|
// Fuse atoms
|
|
3053
|
+
P: () => true,
|
|
3054
|
+
// Peer atoms
|
|
3055
|
+
A: () => Boolean(this.metaType && this.metaId)
|
|
3056
|
+
// Append atoms must have metaType and metaId
|
|
2557
3057
|
});
|
|
2558
3058
|
}
|
|
2559
3059
|
// =============================================================================
|
|
@@ -2583,24 +3083,48 @@ var Atom = class _Atom {
|
|
|
2583
3083
|
*/
|
|
2584
3084
|
static getUnclaimedProps() {
|
|
2585
3085
|
return [
|
|
2586
|
-
"
|
|
2587
|
-
"walletAddress",
|
|
2588
|
-
"isotope",
|
|
2589
|
-
"token",
|
|
2590
|
-
"value",
|
|
2591
|
-
"batchId",
|
|
2592
|
-
"metaType",
|
|
2593
|
-
"metaId",
|
|
2594
|
-
"meta",
|
|
2595
|
-
"createdAt"
|
|
3086
|
+
"otsFragment"
|
|
2596
3087
|
];
|
|
2597
3088
|
}
|
|
2598
3089
|
/**
|
|
2599
3090
|
* Create atom from parameters - factory method
|
|
2600
|
-
* Matches JavaScript SDK Atom.create static method
|
|
3091
|
+
* Matches JavaScript SDK Atom.create static method exactly
|
|
3092
|
+
* Processes wallet meta, extracts wallet fields, normalizes meta
|
|
2601
3093
|
*/
|
|
2602
|
-
static create(
|
|
2603
|
-
|
|
3094
|
+
static create({
|
|
3095
|
+
isotope,
|
|
3096
|
+
wallet = null,
|
|
3097
|
+
value = null,
|
|
3098
|
+
metaType = null,
|
|
3099
|
+
metaId = null,
|
|
3100
|
+
meta = null,
|
|
3101
|
+
batchId = null
|
|
3102
|
+
}) {
|
|
3103
|
+
let atomMeta;
|
|
3104
|
+
if (!meta) {
|
|
3105
|
+
atomMeta = new AtomMeta();
|
|
3106
|
+
} else if (meta instanceof AtomMeta) {
|
|
3107
|
+
atomMeta = meta;
|
|
3108
|
+
} else {
|
|
3109
|
+
atomMeta = new AtomMeta(meta);
|
|
3110
|
+
}
|
|
3111
|
+
if (wallet) {
|
|
3112
|
+
atomMeta.setAtomWallet(wallet);
|
|
3113
|
+
if (!batchId) {
|
|
3114
|
+
batchId = wallet.batchId;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
return new _Atom({
|
|
3118
|
+
position: wallet ? wallet.position : null,
|
|
3119
|
+
walletAddress: wallet ? wallet.address : null,
|
|
3120
|
+
isotope,
|
|
3121
|
+
token: wallet ? wallet.token : null,
|
|
3122
|
+
value,
|
|
3123
|
+
batchId,
|
|
3124
|
+
metaType,
|
|
3125
|
+
metaId,
|
|
3126
|
+
meta: atomMeta.get()
|
|
3127
|
+
});
|
|
2604
3128
|
}
|
|
2605
3129
|
/**
|
|
2606
3130
|
* Creates an Atom instance from JSON data (2025 TS best practices)
|
|
@@ -2676,15 +3200,22 @@ var Atom = class _Atom {
|
|
|
2676
3200
|
return "";
|
|
2677
3201
|
}
|
|
2678
3202
|
const atomList = _Atom.sortAtoms(atoms);
|
|
2679
|
-
const numberOfAtoms = String(atoms.length);
|
|
2680
|
-
let hashableValues = [];
|
|
2681
|
-
for (const atom of atomList) {
|
|
2682
|
-
hashableValues.push(numberOfAtoms);
|
|
2683
|
-
hashableValues = hashableValues.concat(atom.getHashableValues());
|
|
2684
|
-
}
|
|
2685
3203
|
const molecularSponge = new JsSHA__default.default("SHAKE256", "TEXT");
|
|
2686
|
-
|
|
2687
|
-
|
|
3204
|
+
const versionRegistry = versions_default;
|
|
3205
|
+
if (atomList.every((atom) => atom.version && Object.prototype.hasOwnProperty.call(versionRegistry, atom.version))) {
|
|
3206
|
+
molecularSponge.update(JSON.stringify(
|
|
3207
|
+
atomList.map((atom) => versionRegistry[atom.version].create(atom).view())
|
|
3208
|
+
));
|
|
3209
|
+
} else {
|
|
3210
|
+
const numberOfAtoms = String(atoms.length);
|
|
3211
|
+
let hashableValues = [];
|
|
3212
|
+
for (const atom of atomList) {
|
|
3213
|
+
hashableValues.push(numberOfAtoms);
|
|
3214
|
+
hashableValues = hashableValues.concat(atom.getHashableValues());
|
|
3215
|
+
}
|
|
3216
|
+
for (const hashableValue of hashableValues) {
|
|
3217
|
+
molecularSponge.update(hashableValue);
|
|
3218
|
+
}
|
|
2688
3219
|
}
|
|
2689
3220
|
const hexHash = molecularSponge.getHash("HEX", { outputLen: 256 });
|
|
2690
3221
|
return convertToBase17(hexHash.toLowerCase());
|
|
@@ -2694,10 +3225,8 @@ var Atom = class _Atom {
|
|
|
2694
3225
|
* Matches JavaScript SDK sortAtoms method
|
|
2695
3226
|
*/
|
|
2696
3227
|
static sortAtoms(atoms) {
|
|
2697
|
-
return [...atoms].sort((
|
|
2698
|
-
|
|
2699
|
-
const indexB = b.index !== null ? b.index : 0;
|
|
2700
|
-
return indexA - indexB;
|
|
3228
|
+
return [...atoms].sort((first, second) => {
|
|
3229
|
+
return first.index < second.index ? -1 : 1;
|
|
2701
3230
|
});
|
|
2702
3231
|
}
|
|
2703
3232
|
/**
|
|
@@ -2705,11 +3234,7 @@ var Atom = class _Atom {
|
|
|
2705
3234
|
* Matches JavaScript SDK generateNextAtomIndex method
|
|
2706
3235
|
*/
|
|
2707
3236
|
static generateNextAtomIndex(atoms) {
|
|
2708
|
-
|
|
2709
|
-
return 0;
|
|
2710
|
-
}
|
|
2711
|
-
const indices = atoms.map((atom) => atom.index !== null ? atom.index : 0).filter((index) => typeof index === "number");
|
|
2712
|
-
return indices.length > 0 ? Math.max(...indices) + 1 : 0;
|
|
3237
|
+
return atoms.length;
|
|
2713
3238
|
}
|
|
2714
3239
|
/**
|
|
2715
3240
|
* Filter atoms by isotope(s)
|
|
@@ -2717,7 +3242,7 @@ var Atom = class _Atom {
|
|
|
2717
3242
|
*/
|
|
2718
3243
|
static isotopeFilter(isotopes, atoms) {
|
|
2719
3244
|
const targetIsotopes = Array.isArray(isotopes) ? isotopes : [isotopes];
|
|
2720
|
-
return atoms.filter((atom) => targetIsotopes.includes(atom.isotope));
|
|
3245
|
+
return atoms.filter((atom) => atom.isotope !== null && targetIsotopes.includes(atom.isotope));
|
|
2721
3246
|
}
|
|
2722
3247
|
// =============================================================================
|
|
2723
3248
|
// VALIDATION AND UTILITY METHODS
|
|
@@ -2744,7 +3269,9 @@ var Atom = class _Atom {
|
|
|
2744
3269
|
static getUniqueIsotopes(atoms) {
|
|
2745
3270
|
const isotopes = /* @__PURE__ */ new Set();
|
|
2746
3271
|
for (const atom of atoms) {
|
|
2747
|
-
|
|
3272
|
+
if (atom.isotope !== null) {
|
|
3273
|
+
isotopes.add(atom.isotope);
|
|
3274
|
+
}
|
|
2748
3275
|
}
|
|
2749
3276
|
return Array.from(isotopes);
|
|
2750
3277
|
}
|
|
@@ -2760,16 +3287,74 @@ var Atom = class _Atom {
|
|
|
2760
3287
|
static groupByIsotope(atoms) {
|
|
2761
3288
|
const groups = {};
|
|
2762
3289
|
for (const atom of atoms) {
|
|
2763
|
-
|
|
2764
|
-
|
|
3290
|
+
const iso = atom.isotope;
|
|
3291
|
+
if (iso === null) continue;
|
|
3292
|
+
if (!groups[iso]) {
|
|
3293
|
+
groups[iso] = [];
|
|
2765
3294
|
}
|
|
2766
|
-
groups[
|
|
3295
|
+
groups[iso].push(atom);
|
|
2767
3296
|
}
|
|
2768
3297
|
return groups;
|
|
2769
3298
|
}
|
|
2770
3299
|
};
|
|
2771
3300
|
init_WalletCredentialException();
|
|
2772
3301
|
|
|
3302
|
+
// src/constants.ts
|
|
3303
|
+
var ISOTOPES = ["C", "V", "U", "T", "M", "I", "R", "B", "F", "P", "A"];
|
|
3304
|
+
var ERROR_TYPES = [
|
|
3305
|
+
"ATOM_INDEX_ERROR",
|
|
3306
|
+
"ATOMS_MISSING_ERROR",
|
|
3307
|
+
"AUTHORIZATION_REJECTED_ERROR",
|
|
3308
|
+
"BALANCE_INSUFFICIENT_ERROR",
|
|
3309
|
+
"BATCH_ID_ERROR",
|
|
3310
|
+
"CODE_ERROR",
|
|
3311
|
+
"DECRYPTION_KEY_ERROR",
|
|
3312
|
+
"INVALID_RESPONSE_ERROR",
|
|
3313
|
+
"META_MISSING_ERROR",
|
|
3314
|
+
"MOLECULAR_HASH_MISMATCH_ERROR",
|
|
3315
|
+
"MOLECULAR_HASH_MISSING_ERROR",
|
|
3316
|
+
"NEGATIVE_AMOUNT_ERROR",
|
|
3317
|
+
"POLICY_INVALID_ERROR",
|
|
3318
|
+
"RULE_ARGUMENT_ERROR",
|
|
3319
|
+
"SIGNATURE_MALFORMED_ERROR",
|
|
3320
|
+
"SIGNATURE_MISMATCH_ERROR",
|
|
3321
|
+
"STACKABLE_UNIT_AMOUNT_ERROR",
|
|
3322
|
+
"STACKABLE_UNIT_DECIMALS_ERROR",
|
|
3323
|
+
"TRANSFER_BALANCE_ERROR",
|
|
3324
|
+
"TRANSFER_MALFORMED_ERROR",
|
|
3325
|
+
"TRANSFER_MISMATCHED_ERROR",
|
|
3326
|
+
"TRANSFER_REMAINDER_ERROR",
|
|
3327
|
+
"TRANSFER_TO_SELF_ERROR",
|
|
3328
|
+
"TRANSFER_UNBALANCED_ERROR",
|
|
3329
|
+
"UNAUTHENTICATED_ERROR",
|
|
3330
|
+
"WALLET_CREDENTIAL_ERROR",
|
|
3331
|
+
"WALLET_SHADOW_ERROR",
|
|
3332
|
+
"WRONG_TOKEN_TYPE_ERROR"
|
|
3333
|
+
];
|
|
3334
|
+
var QUERY_TYPES = [
|
|
3335
|
+
"Balance",
|
|
3336
|
+
"WalletBundle",
|
|
3337
|
+
"WalletList",
|
|
3338
|
+
"Atom",
|
|
3339
|
+
"MetaType",
|
|
3340
|
+
"MetaTypeViaAtom",
|
|
3341
|
+
"ContinuId",
|
|
3342
|
+
"Batch",
|
|
3343
|
+
"ActiveSession",
|
|
3344
|
+
"Policy",
|
|
3345
|
+
"Token",
|
|
3346
|
+
"UserActivity"
|
|
3347
|
+
];
|
|
3348
|
+
function createLookup(values) {
|
|
3349
|
+
return values.reduce((acc, value) => {
|
|
3350
|
+
acc[value] = value;
|
|
3351
|
+
return acc;
|
|
3352
|
+
}, {});
|
|
3353
|
+
}
|
|
3354
|
+
var ISOTOPE_LOOKUP = createLookup(ISOTOPES);
|
|
3355
|
+
createLookup(ERROR_TYPES);
|
|
3356
|
+
createLookup(QUERY_TYPES);
|
|
3357
|
+
|
|
2773
3358
|
// src/types/index.ts
|
|
2774
3359
|
function isHexString(value) {
|
|
2775
3360
|
return /^[0-9a-fA-F]+$/.test(value);
|
|
@@ -2848,17 +3433,8 @@ var Wallet = class _Wallet {
|
|
|
2848
3433
|
batchId = null,
|
|
2849
3434
|
characters = null
|
|
2850
3435
|
} = {}) {
|
|
2851
|
-
if (address !== null && !isWalletAddress2(address)) {
|
|
2852
|
-
throw new exports.WalletCredentialException("Invalid wallet address format");
|
|
2853
|
-
}
|
|
2854
|
-
if (bundle !== null && !isBundleHash(bundle)) {
|
|
2855
|
-
throw new exports.WalletCredentialException("Invalid bundle hash format");
|
|
2856
|
-
}
|
|
2857
|
-
if (position !== null && !isPosition2(position)) {
|
|
2858
|
-
throw new exports.WalletCredentialException("Invalid position format");
|
|
2859
|
-
}
|
|
2860
3436
|
this.token = token;
|
|
2861
|
-
this.balance = 0;
|
|
3437
|
+
this.balance = "0";
|
|
2862
3438
|
this.molecules = {};
|
|
2863
3439
|
this.key = null;
|
|
2864
3440
|
this.privkey = null;
|
|
@@ -2920,8 +3496,10 @@ var Wallet = class _Wallet {
|
|
|
2920
3496
|
token,
|
|
2921
3497
|
position
|
|
2922
3498
|
}) {
|
|
2923
|
-
const
|
|
2924
|
-
const
|
|
3499
|
+
const secretHex = isHex(secret) ? secret : shake256(secret, 1024);
|
|
3500
|
+
const positionHex = isHex(position) ? position : shake256(position, 256);
|
|
3501
|
+
const bigIntSecret = BigInt(`0x${secretHex}`);
|
|
3502
|
+
const indexedKey = bigIntSecret + BigInt(`0x${positionHex}`);
|
|
2925
3503
|
const intermediateKeySponge = new JsSHA__default.default("SHAKE256", "TEXT");
|
|
2926
3504
|
intermediateKeySponge.update(indexedKey.toString(16));
|
|
2927
3505
|
if (token) {
|
|
@@ -3046,7 +3624,7 @@ var Wallet = class _Wallet {
|
|
|
3046
3624
|
* Initializes the ML-KEM key pair (matches JavaScript SDK exactly)
|
|
3047
3625
|
*/
|
|
3048
3626
|
initializeMLKEM() {
|
|
3049
|
-
const seedHex = generateSecret(this.key,
|
|
3627
|
+
const seedHex = generateSecret(this.key, 128);
|
|
3050
3628
|
const seed = new Uint8Array(64);
|
|
3051
3629
|
for (let i = 0; i < 64; i++) {
|
|
3052
3630
|
seed[i] = parseInt(seedHex.substr(i * 2, 2), 16);
|
|
@@ -3164,287 +3742,632 @@ var Wallet = class _Wallet {
|
|
|
3164
3742
|
return new Uint8Array([...binaryString].map((char) => char.charCodeAt(0)));
|
|
3165
3743
|
}
|
|
3166
3744
|
};
|
|
3745
|
+
var hexStringRegex = /^[0-9a-fA-F]+$/;
|
|
3746
|
+
var base17HashRegex = /^[0-9a-g]+$/;
|
|
3747
|
+
zod.z.string().regex(hexStringRegex, "Must be a valid hexadecimal string").brand();
|
|
3748
|
+
var WalletAddressSchema = zod.z.string().regex(hexStringRegex, "Wallet address must be hexadecimal").length(64, "Wallet address must be exactly 64 characters").brand();
|
|
3749
|
+
var BundleHashSchema = zod.z.string().regex(hexStringRegex, "Bundle hash must be hexadecimal").length(64, "Bundle hash must be exactly 64 characters").brand();
|
|
3750
|
+
var PositionSchema = zod.z.string().regex(hexStringRegex, "Position must be hexadecimal").length(64, "Position must be exactly 64 characters").brand();
|
|
3751
|
+
zod.z.string().regex(base17HashRegex, "Molecular hash must be base17 format (0-9,a-g)").min(1, "Molecular hash cannot be empty").brand();
|
|
3752
|
+
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();
|
|
3753
|
+
var MetaTypeSchema = zod.z.string().min(1, "Meta type cannot be empty").max(256, "Meta type cannot exceed 256 characters").brand();
|
|
3754
|
+
var MetaIdSchema = zod.z.string().min(1, "Meta ID cannot be empty").brand();
|
|
3755
|
+
var BatchIdSchema = zod.z.string().min(1, "Batch ID cannot be empty").brand();
|
|
3756
|
+
var CellSlugSchema = zod.z.string().min(1, "Cell slug cannot be empty").max(64, "Cell slug cannot exceed 64 characters").brand();
|
|
3757
|
+
var AtomIsotopeSchema = zod.z.enum(["C", "V", "U", "T", "M", "I", "R", "B", "F"], {
|
|
3758
|
+
errorMap: () => ({ message: "Invalid atom isotope. Must be one of: C, V, U, T, M, I, R, B, F" })
|
|
3759
|
+
});
|
|
3760
|
+
var MetaDataValueSchema = zod.z.union([
|
|
3761
|
+
zod.z.string(),
|
|
3762
|
+
zod.z.number(),
|
|
3763
|
+
zod.z.boolean(),
|
|
3764
|
+
zod.z.null()
|
|
3765
|
+
]);
|
|
3766
|
+
var AtomMetaDataSchema = zod.z.object({
|
|
3767
|
+
key: zod.z.string().min(1, "Meta key cannot be empty"),
|
|
3768
|
+
value: MetaDataValueSchema
|
|
3769
|
+
}).strict();
|
|
3770
|
+
var MetaDataSchema = zod.z.lazy(
|
|
3771
|
+
() => zod.z.record(zod.z.union([
|
|
3772
|
+
MetaDataValueSchema,
|
|
3773
|
+
MetaDataSchema,
|
|
3774
|
+
zod.z.array(MetaDataSchema)
|
|
3775
|
+
]))
|
|
3776
|
+
);
|
|
3777
|
+
zod.z.object({
|
|
3778
|
+
position: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3779
|
+
walletAddress: zod.z.union([WalletAddressSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3780
|
+
isotope: AtomIsotopeSchema.optional(),
|
|
3781
|
+
token: zod.z.union([TokenSlugSchema, zod.z.string()]).optional(),
|
|
3782
|
+
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.null()]).optional(),
|
|
3783
|
+
batchId: zod.z.union([BatchIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3784
|
+
metaType: zod.z.union([MetaTypeSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3785
|
+
metaId: zod.z.union([MetaIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3786
|
+
meta: zod.z.union([zod.z.array(AtomMetaDataSchema), zod.z.null()]).optional(),
|
|
3787
|
+
otsFragment: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3788
|
+
index: zod.z.union([zod.z.number().int().min(0), zod.z.null()]).optional(),
|
|
3789
|
+
createdAt: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3790
|
+
version: zod.z.union([zod.z.number().int().min(1), zod.z.null()]).optional()
|
|
3791
|
+
}).strict();
|
|
3792
|
+
var WalletParamsSchema = zod.z.object({
|
|
3793
|
+
secret: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3794
|
+
bundle: zod.z.union([BundleHashSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3795
|
+
token: zod.z.union([TokenSlugSchema, zod.z.string()]).optional(),
|
|
3796
|
+
address: zod.z.union([WalletAddressSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3797
|
+
position: zod.z.union([PositionSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3798
|
+
batchId: zod.z.union([BatchIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3799
|
+
characters: zod.z.union([zod.z.string(), zod.z.null()]).optional()
|
|
3800
|
+
}).strict();
|
|
3801
|
+
zod.z.object({
|
|
3802
|
+
secret: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3803
|
+
bundle: zod.z.union([BundleHashSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3804
|
+
sourceWallet: zod.z.union([WalletParamsSchema, zod.z.null()]).optional(),
|
|
3805
|
+
remainderWallet: zod.z.union([WalletParamsSchema, zod.z.null()]).optional(),
|
|
3806
|
+
cellSlug: zod.z.union([CellSlugSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3807
|
+
version: zod.z.number().int().min(1).optional()
|
|
3808
|
+
}).strict();
|
|
3809
|
+
zod.z.object({
|
|
3810
|
+
uri: zod.z.union([zod.z.string().url(), zod.z.array(zod.z.string().url())]).optional(),
|
|
3811
|
+
cellSlug: zod.z.union([CellSlugSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3812
|
+
client: zod.z.unknown().optional(),
|
|
3813
|
+
socket: zod.z.unknown().optional(),
|
|
3814
|
+
serverSdkVersion: zod.z.number().int().min(1).optional(),
|
|
3815
|
+
logging: zod.z.boolean().optional()
|
|
3816
|
+
}).strict();
|
|
3817
|
+
zod.z.object({
|
|
3818
|
+
token: zod.z.string().min(1, "Auth token cannot be empty"),
|
|
3819
|
+
expiresAt: zod.z.number().int().min(0, "Expiration time must be positive"),
|
|
3820
|
+
encrypt: zod.z.boolean(),
|
|
3821
|
+
pubkey: zod.z.string().min(1, "Public key cannot be empty")
|
|
3822
|
+
}).strict();
|
|
3823
|
+
zod.z.object({
|
|
3824
|
+
cellSlug: zod.z.union([CellSlugSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3825
|
+
encrypt: zod.z.boolean().optional(),
|
|
3826
|
+
callback: zod.z.function().args(zod.z.unknown()).returns(zod.z.void()).optional()
|
|
3827
|
+
}).strict();
|
|
3828
|
+
zod.z.object({
|
|
3829
|
+
cellSlug: zod.z.union([CellSlugSchema, zod.z.string(), zod.z.null()]).optional()
|
|
3830
|
+
}).strict();
|
|
3831
|
+
zod.z.object({
|
|
3832
|
+
recipient: zod.z.union([WalletAddressSchema, zod.z.string()]),
|
|
3833
|
+
amount: zod.z.union([zod.z.number().positive(), zod.z.string().min(1)]),
|
|
3834
|
+
token: zod.z.union([TokenSlugSchema, zod.z.string()]).optional(),
|
|
3835
|
+
callbackUrl: zod.z.union([zod.z.string().url(), zod.z.null()]).optional(),
|
|
3836
|
+
metaType: zod.z.union([MetaTypeSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3837
|
+
metaId: zod.z.union([MetaIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3838
|
+
meta: zod.z.union([MetaDataSchema, zod.z.null()]).optional()
|
|
3839
|
+
}).strict();
|
|
3840
|
+
zod.z.object({
|
|
3841
|
+
token: zod.z.union([TokenSlugSchema, zod.z.string()]),
|
|
3842
|
+
amount: zod.z.union([zod.z.number().positive(), zod.z.string().min(1)]),
|
|
3843
|
+
metaType: zod.z.union([MetaTypeSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3844
|
+
metaId: zod.z.union([MetaIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3845
|
+
meta: zod.z.union([MetaDataSchema, zod.z.null()]).optional(),
|
|
3846
|
+
fungible: zod.z.boolean().optional(),
|
|
3847
|
+
splittable: zod.z.number().int().min(0).optional(),
|
|
3848
|
+
supplyToken: zod.z.union([TokenSlugSchema, zod.z.string(), zod.z.null()]).optional()
|
|
3849
|
+
}).strict();
|
|
3850
|
+
zod.z.object({
|
|
3851
|
+
amount: zod.z.union([zod.z.number().positive(), zod.z.string().min(1)]),
|
|
3852
|
+
token: zod.z.union([TokenSlugSchema, zod.z.string()]).optional(),
|
|
3853
|
+
metaType: zod.z.union([MetaTypeSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3854
|
+
metaId: zod.z.union([MetaIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3855
|
+
meta: zod.z.union([MetaDataSchema, zod.z.null()]).optional()
|
|
3856
|
+
}).strict();
|
|
3857
|
+
var MetaFilterSchema = zod.z.object({
|
|
3858
|
+
key: zod.z.string(),
|
|
3859
|
+
value: zod.z.string(),
|
|
3860
|
+
comparison: zod.z.string().optional(),
|
|
3861
|
+
criterion: zod.z.string().optional()
|
|
3862
|
+
}).strict();
|
|
3863
|
+
zod.z.object({
|
|
3864
|
+
address: zod.z.union([WalletAddressSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3865
|
+
bundleHash: zod.z.union([BundleHashSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3866
|
+
token: zod.z.union([TokenSlugSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3867
|
+
type: zod.z.enum(["token", "user"]).nullable().optional()
|
|
3868
|
+
}).strict();
|
|
3869
|
+
zod.z.object({
|
|
3870
|
+
metaType: zod.z.union([MetaTypeSchema, zod.z.string()]),
|
|
3871
|
+
metaId: zod.z.union([MetaIdSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3872
|
+
key: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3873
|
+
value: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3874
|
+
latest: zod.z.union([zod.z.boolean(), zod.z.null()]).optional(),
|
|
3875
|
+
filter: zod.z.union([zod.z.array(MetaFilterSchema), zod.z.null()]).optional(),
|
|
3876
|
+
queryArgs: zod.z.union([zod.z.record(zod.z.unknown()), zod.z.null()]).optional(),
|
|
3877
|
+
count: zod.z.union([zod.z.number().int().min(1), zod.z.null()]).optional(),
|
|
3878
|
+
countBy: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3879
|
+
cellSlug: zod.z.union([CellSlugSchema, zod.z.string(), zod.z.null()]).optional()
|
|
3880
|
+
}).strict();
|
|
3881
|
+
zod.z.object({
|
|
3882
|
+
bundleHash: zod.z.union([BundleHashSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3883
|
+
tokenSlug: zod.z.union([TokenSlugSchema, zod.z.string(), zod.z.null()]).optional(),
|
|
3884
|
+
unspent: zod.z.union([zod.z.boolean(), zod.z.null()]).optional()
|
|
3885
|
+
}).strict();
|
|
3886
|
+
zod.z.object({
|
|
3887
|
+
seed: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3888
|
+
length: zod.z.number().int().min(1).optional(),
|
|
3889
|
+
outputLength: zod.z.number().int().min(1).optional()
|
|
3890
|
+
}).strict();
|
|
3891
|
+
zod.z.object({
|
|
3892
|
+
privateKey: zod.z.string().min(1, "Private key cannot be empty"),
|
|
3893
|
+
publicKey: zod.z.string().min(1, "Public key cannot be empty")
|
|
3894
|
+
}).strict();
|
|
3895
|
+
zod.z.object({
|
|
3896
|
+
signature: zod.z.string().min(1, "Signature cannot be empty"),
|
|
3897
|
+
otsFragments: zod.z.array(zod.z.string()).optional()
|
|
3898
|
+
}).strict();
|
|
3899
|
+
zod.z.object({
|
|
3900
|
+
query: zod.z.string().min(1, "GraphQL query cannot be empty"),
|
|
3901
|
+
variables: zod.z.record(zod.z.unknown()).optional(),
|
|
3902
|
+
operationName: zod.z.union([zod.z.string(), zod.z.null()]).optional()
|
|
3903
|
+
}).strict();
|
|
3904
|
+
var GraphQLErrorSchema = zod.z.object({
|
|
3905
|
+
message: zod.z.string(),
|
|
3906
|
+
locations: zod.z.array(zod.z.object({
|
|
3907
|
+
line: zod.z.number().int().min(1),
|
|
3908
|
+
column: zod.z.number().int().min(1)
|
|
3909
|
+
})).optional(),
|
|
3910
|
+
path: zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).optional(),
|
|
3911
|
+
extensions: zod.z.record(zod.z.unknown()).optional()
|
|
3912
|
+
}).strict();
|
|
3913
|
+
zod.z.object({
|
|
3914
|
+
data: zod.z.unknown().optional(),
|
|
3915
|
+
errors: zod.z.array(GraphQLErrorSchema).nullable().optional(),
|
|
3916
|
+
extensions: zod.z.record(zod.z.unknown()).optional()
|
|
3917
|
+
}).strict();
|
|
3918
|
+
zod.z.object({
|
|
3919
|
+
operationName: zod.z.string().optional(),
|
|
3920
|
+
query: zod.z.string().optional(),
|
|
3921
|
+
variables: zod.z.record(zod.z.unknown()).optional(),
|
|
3922
|
+
callback: zod.z.function().args(zod.z.unknown()).returns(zod.z.void()).optional()
|
|
3923
|
+
}).strict();
|
|
3924
|
+
zod.z.object({
|
|
3925
|
+
valid: zod.z.boolean(),
|
|
3926
|
+
error: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
3927
|
+
expected: zod.z.string().optional(),
|
|
3928
|
+
actual: zod.z.unknown().optional()
|
|
3929
|
+
}).strict();
|
|
3930
|
+
zod.z.object({
|
|
3931
|
+
operation: zod.z.string().optional(),
|
|
3932
|
+
parameters: zod.z.record(zod.z.unknown()).optional(),
|
|
3933
|
+
timestamp: zod.z.number().int().min(0).optional(),
|
|
3934
|
+
stack: zod.z.string().optional()
|
|
3935
|
+
}).strict();
|
|
3936
|
+
zod.z.enum([
|
|
3937
|
+
"ATOM_INDEX_ERROR",
|
|
3938
|
+
"ATOMS_MISSING_ERROR",
|
|
3939
|
+
"AUTHORIZATION_REJECTED_ERROR",
|
|
3940
|
+
"BALANCE_INSUFFICIENT_ERROR",
|
|
3941
|
+
"BATCH_ID_ERROR",
|
|
3942
|
+
"CODE_ERROR",
|
|
3943
|
+
"DECRYPTION_KEY_ERROR",
|
|
3944
|
+
"INVALID_RESPONSE_ERROR",
|
|
3945
|
+
"META_MISSING_ERROR",
|
|
3946
|
+
"MOLECULAR_HASH_MISMATCH_ERROR",
|
|
3947
|
+
"MOLECULAR_HASH_MISSING_ERROR",
|
|
3948
|
+
"NEGATIVE_AMOUNT_ERROR",
|
|
3949
|
+
"POLICY_INVALID_ERROR",
|
|
3950
|
+
"SIGNATURE_MALFORMED_ERROR",
|
|
3951
|
+
"SIGNATURE_MISMATCH_ERROR",
|
|
3952
|
+
"STACKABLE_UNIT_AMOUNT_ERROR",
|
|
3953
|
+
"STACKABLE_UNIT_DECIMALS_ERROR",
|
|
3954
|
+
"TRANSFER_BALANCE_ERROR",
|
|
3955
|
+
"TRANSFER_MALFORMED_ERROR",
|
|
3956
|
+
"TRANSFER_MISMATCHED_ERROR",
|
|
3957
|
+
"TRANSFER_REMAINDER_ERROR",
|
|
3958
|
+
"TRANSFER_TO_SELF_ERROR",
|
|
3959
|
+
"TRANSFER_UNBALANCED_ERROR",
|
|
3960
|
+
"UNAUTHENTICATED_ERROR",
|
|
3961
|
+
"WALLET_CREDENTIAL_ERROR",
|
|
3962
|
+
"WALLET_SHADOW_ERROR",
|
|
3963
|
+
"WRONG_TOKEN_TYPE_ERROR"
|
|
3964
|
+
]);
|
|
3965
|
+
function parseWithSchema(schema, data, context) {
|
|
3966
|
+
const result = schema.safeParse(data);
|
|
3967
|
+
if (!result.success) {
|
|
3968
|
+
const errorMessage = context ? `${context}: ${result.error.message}` : result.error.message;
|
|
3969
|
+
throw new Error(errorMessage);
|
|
3970
|
+
}
|
|
3971
|
+
return result.data;
|
|
3972
|
+
}
|
|
3167
3973
|
|
|
3168
|
-
// src/
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3974
|
+
// src/instance/rules/Meta.ts
|
|
3975
|
+
var Meta2 = class _Meta {
|
|
3976
|
+
__data = /* @__PURE__ */ new Map();
|
|
3977
|
+
constructor(args = {}) {
|
|
3978
|
+
const validatedArgs = parseWithSchema(MetaDataSchema, args, "Meta constructor");
|
|
3979
|
+
for (const [key, value] of Object.entries(validatedArgs)) {
|
|
3980
|
+
this.__data.set(`__${key}`, value);
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3174
3983
|
/**
|
|
3175
|
-
*
|
|
3176
|
-
* Matches JavaScript SDK Meta.normalizeMeta exactly
|
|
3984
|
+
* Creates a Meta object from a plain object with runtime validation
|
|
3177
3985
|
*/
|
|
3178
|
-
static
|
|
3179
|
-
|
|
3180
|
-
return [];
|
|
3181
|
-
}
|
|
3182
|
-
if (Array.isArray(meta)) {
|
|
3183
|
-
return meta.map((item) => {
|
|
3184
|
-
if (typeof item === "object" && item !== null && "key" in item) {
|
|
3185
|
-
return {
|
|
3186
|
-
...item,
|
|
3187
|
-
key: String(item.key),
|
|
3188
|
-
value: item.value
|
|
3189
|
-
};
|
|
3190
|
-
}
|
|
3191
|
-
return {
|
|
3192
|
-
key: "unknown",
|
|
3193
|
-
value: String(item)
|
|
3194
|
-
};
|
|
3195
|
-
});
|
|
3196
|
-
}
|
|
3197
|
-
if (typeof meta === "object" && meta !== null) {
|
|
3198
|
-
return Object.entries(meta).map(([key, value]) => ({
|
|
3199
|
-
key,
|
|
3200
|
-
value
|
|
3201
|
-
}));
|
|
3202
|
-
}
|
|
3203
|
-
return [{
|
|
3204
|
-
key: "value",
|
|
3205
|
-
value: meta
|
|
3206
|
-
}];
|
|
3986
|
+
static toObject(object) {
|
|
3987
|
+
return new _Meta(object);
|
|
3207
3988
|
}
|
|
3208
3989
|
/**
|
|
3209
|
-
*
|
|
3210
|
-
* Matches JavaScript SDK Meta.aggregateMeta exactly
|
|
3990
|
+
* Gets a metadata value by key
|
|
3211
3991
|
*/
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
return {};
|
|
3215
|
-
}
|
|
3216
|
-
const aggregated = {};
|
|
3217
|
-
for (const item of metaItems) {
|
|
3218
|
-
if (item && typeof item === "object" && "key" in item) {
|
|
3219
|
-
const key = String(item.key);
|
|
3220
|
-
if ("value" in item) {
|
|
3221
|
-
aggregated[key] = item.value;
|
|
3222
|
-
} else {
|
|
3223
|
-
const { key: itemKey, ...restOfItem } = item;
|
|
3224
|
-
aggregated[key] = Object.keys(restOfItem).length === 1 && "value" in restOfItem ? restOfItem.value : restOfItem;
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
}
|
|
3228
|
-
return aggregated;
|
|
3992
|
+
get(key) {
|
|
3993
|
+
return this.__data.get(`__${String(key)}`);
|
|
3229
3994
|
}
|
|
3230
3995
|
/**
|
|
3231
|
-
*
|
|
3232
|
-
* Combines arrays while preserving order and handling duplicates
|
|
3996
|
+
* Sets a metadata value by key
|
|
3233
3997
|
*/
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
const keysSeen = /* @__PURE__ */ new Set();
|
|
3237
|
-
for (const metaArray of metaArrays) {
|
|
3238
|
-
if (!metaArray || !Array.isArray(metaArray)) {
|
|
3239
|
-
continue;
|
|
3240
|
-
}
|
|
3241
|
-
const normalized = this.normalizeMeta(metaArray);
|
|
3242
|
-
for (const item of normalized) {
|
|
3243
|
-
let finalKey = item.key;
|
|
3244
|
-
let counter = 1;
|
|
3245
|
-
while (keysSeen.has(finalKey)) {
|
|
3246
|
-
finalKey = `${item.key}_${counter}`;
|
|
3247
|
-
counter++;
|
|
3248
|
-
}
|
|
3249
|
-
keysSeen.add(finalKey);
|
|
3250
|
-
merged.push({
|
|
3251
|
-
...item,
|
|
3252
|
-
key: finalKey
|
|
3253
|
-
});
|
|
3254
|
-
}
|
|
3255
|
-
}
|
|
3256
|
-
return merged;
|
|
3998
|
+
set(key, value) {
|
|
3999
|
+
this.__data.set(`__${String(key)}`, value);
|
|
3257
4000
|
}
|
|
3258
4001
|
/**
|
|
3259
|
-
*
|
|
4002
|
+
* Checks if a key exists
|
|
3260
4003
|
*/
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
}
|
|
3272
|
-
if (typeof filter === "function") {
|
|
3273
|
-
return normalized.filter(filter);
|
|
3274
|
-
}
|
|
3275
|
-
return normalized;
|
|
4004
|
+
has(key) {
|
|
4005
|
+
return this.__data.has(`__${String(key)}`);
|
|
4006
|
+
}
|
|
4007
|
+
/**
|
|
4008
|
+
* Gets all keys
|
|
4009
|
+
*/
|
|
4010
|
+
keys() {
|
|
4011
|
+
return Array.from(this.__data.keys()).map(
|
|
4012
|
+
(key) => key.startsWith("__") ? key.substring(2) : key
|
|
4013
|
+
);
|
|
3276
4014
|
}
|
|
3277
4015
|
/**
|
|
3278
|
-
*
|
|
4016
|
+
* Converts Meta object back to plain object
|
|
3279
4017
|
*/
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
4018
|
+
toJSON() {
|
|
4019
|
+
const object = {};
|
|
4020
|
+
for (const [key, value] of this.__data.entries()) {
|
|
4021
|
+
if (key.startsWith("__")) {
|
|
4022
|
+
const plainKey = key.substring(2);
|
|
4023
|
+
object[plainKey] = value;
|
|
4024
|
+
}
|
|
3283
4025
|
}
|
|
3284
|
-
|
|
3285
|
-
return normalized.find((item) => item.key === key) || null;
|
|
4026
|
+
return object;
|
|
3286
4027
|
}
|
|
3287
4028
|
/**
|
|
3288
|
-
*
|
|
4029
|
+
* Creates a typed copy of this Meta object
|
|
3289
4030
|
*/
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
return item ? item.value : defaultValue;
|
|
4031
|
+
clone() {
|
|
4032
|
+
return new _Meta(this.toJSON());
|
|
3293
4033
|
}
|
|
3294
4034
|
/**
|
|
3295
|
-
*
|
|
4035
|
+
* Merges another Meta object into this one
|
|
3296
4036
|
*/
|
|
3297
|
-
|
|
3298
|
-
const
|
|
3299
|
-
|
|
3300
|
-
const newItem = {
|
|
3301
|
-
key,
|
|
3302
|
-
value
|
|
3303
|
-
};
|
|
3304
|
-
if (existingIndex >= 0) {
|
|
3305
|
-
normalized[existingIndex] = newItem;
|
|
3306
|
-
} else {
|
|
3307
|
-
normalized.push(newItem);
|
|
3308
|
-
}
|
|
3309
|
-
return normalized;
|
|
4037
|
+
merge(other) {
|
|
4038
|
+
const combined = { ...this.toJSON(), ...other.toJSON() };
|
|
4039
|
+
return new _Meta(combined);
|
|
3310
4040
|
}
|
|
3311
4041
|
/**
|
|
3312
|
-
*
|
|
4042
|
+
* Type-safe iteration over metadata entries
|
|
3313
4043
|
*/
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
4044
|
+
forEach(callback) {
|
|
4045
|
+
for (const [key, value] of this.__data.entries()) {
|
|
4046
|
+
if (key.startsWith("__")) {
|
|
4047
|
+
const plainKey = key.substring(2);
|
|
4048
|
+
callback(value, plainKey);
|
|
4049
|
+
}
|
|
3317
4050
|
}
|
|
3318
|
-
const normalized = this.normalizeMeta(metaItems);
|
|
3319
|
-
return normalized.filter((item) => item.key !== key);
|
|
3320
4051
|
}
|
|
3321
4052
|
/**
|
|
3322
|
-
*
|
|
4053
|
+
* Returns the size of the metadata object
|
|
3323
4054
|
*/
|
|
3324
|
-
|
|
3325
|
-
return this.
|
|
4055
|
+
get size() {
|
|
4056
|
+
return this.__data.size;
|
|
3326
4057
|
}
|
|
3327
4058
|
/**
|
|
3328
|
-
*
|
|
4059
|
+
* Clears all metadata
|
|
3329
4060
|
*/
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
return [];
|
|
3333
|
-
}
|
|
3334
|
-
return Object.entries(jsonData).map(([key, value]) => ({
|
|
3335
|
-
key,
|
|
3336
|
-
value
|
|
3337
|
-
}));
|
|
4061
|
+
clear() {
|
|
4062
|
+
this.__data.clear();
|
|
3338
4063
|
}
|
|
4064
|
+
};
|
|
4065
|
+
|
|
4066
|
+
// src/instance/rules/exception/RuleArgumentException.ts
|
|
4067
|
+
init_BaseException();
|
|
4068
|
+
var RuleArgumentException = class extends exports.BaseException {
|
|
3339
4069
|
/**
|
|
3340
|
-
*
|
|
4070
|
+
* Constructor
|
|
3341
4071
|
*/
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
4072
|
+
constructor(message = "An incorrect argument!") {
|
|
4073
|
+
super("RULE_ARGUMENT_ERROR", message);
|
|
4074
|
+
}
|
|
4075
|
+
};
|
|
4076
|
+
var RuleArgumentException_default = RuleArgumentException;
|
|
4077
|
+
|
|
4078
|
+
// src/libraries/array.ts
|
|
4079
|
+
function deepCloning(o, h) {
|
|
4080
|
+
let i;
|
|
4081
|
+
let r;
|
|
4082
|
+
let x;
|
|
4083
|
+
const t = [Array, Date, Number, String, Boolean];
|
|
4084
|
+
const s = Object.prototype.toString;
|
|
4085
|
+
h = h || [];
|
|
4086
|
+
for (i = 0; i < h.length; i += 2) {
|
|
4087
|
+
if (o === h[i]) {
|
|
4088
|
+
return h[i + 1];
|
|
3345
4089
|
}
|
|
3346
|
-
return metaItems.every(
|
|
3347
|
-
(item) => item && typeof item === "object" && "key" in item && typeof item.key === "string"
|
|
3348
|
-
);
|
|
3349
4090
|
}
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
4091
|
+
if (!r && o && typeof o === "object") {
|
|
4092
|
+
r = {};
|
|
4093
|
+
for (i = 0; i < t.length; i++) {
|
|
4094
|
+
if (s.call(o) === s.call(x = new t[i](o))) {
|
|
4095
|
+
r = i ? x : [];
|
|
4096
|
+
}
|
|
3356
4097
|
}
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
4098
|
+
h.push(o, r);
|
|
4099
|
+
for (i in o) {
|
|
4100
|
+
if (Object.prototype.hasOwnProperty.call(o, i)) {
|
|
4101
|
+
r[i] = deepCloning(o[i], h);
|
|
4102
|
+
}
|
|
3361
4103
|
}
|
|
3362
|
-
|
|
4104
|
+
}
|
|
4105
|
+
return r || o;
|
|
4106
|
+
}
|
|
4107
|
+
function chunkArray(arr, size) {
|
|
4108
|
+
if (!arr.length) {
|
|
4109
|
+
return [];
|
|
4110
|
+
}
|
|
4111
|
+
return [arr.slice(0, size)].concat(chunkArray(arr.slice(size), size));
|
|
4112
|
+
}
|
|
4113
|
+
function diff(...arrays) {
|
|
4114
|
+
return [].concat(...arrays.map((arr, i) => {
|
|
4115
|
+
const others = arrays.slice(0);
|
|
4116
|
+
others.splice(i, 1);
|
|
4117
|
+
const unique = [...new Set([].concat(...others))];
|
|
4118
|
+
return arr.filter((item) => !unique.includes(item));
|
|
4119
|
+
}));
|
|
4120
|
+
}
|
|
4121
|
+
function intersect(...arrays) {
|
|
4122
|
+
if (arrays.length === 0) return [];
|
|
4123
|
+
if (arrays.length === 1) return arrays[0];
|
|
4124
|
+
return arrays.reduce(
|
|
4125
|
+
(first, second) => first.filter((item) => second.includes(item))
|
|
4126
|
+
);
|
|
4127
|
+
}
|
|
4128
|
+
|
|
4129
|
+
// src/instance/rules/Callback.ts
|
|
4130
|
+
init_exception();
|
|
4131
|
+
var CallbackParamsSchema = zod.z.object({
|
|
4132
|
+
action: zod.z.string().min(1, "Action cannot be empty"),
|
|
4133
|
+
metaType: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
4134
|
+
metaId: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
4135
|
+
meta: zod.z.union([zod.z.instanceof(Meta2), zod.z.record(zod.z.unknown()), zod.z.null()]).optional(),
|
|
4136
|
+
address: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
4137
|
+
token: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
4138
|
+
amount: zod.z.union([zod.z.string(), zod.z.null()]).optional(),
|
|
4139
|
+
comparison: zod.z.union([zod.z.string(), zod.z.null()]).optional()
|
|
4140
|
+
}).strict();
|
|
4141
|
+
var Callback = class _Callback {
|
|
4142
|
+
__action;
|
|
4143
|
+
__metaType;
|
|
4144
|
+
__metaId;
|
|
4145
|
+
__meta;
|
|
4146
|
+
__address;
|
|
4147
|
+
__token;
|
|
4148
|
+
__amount;
|
|
4149
|
+
__comparison;
|
|
4150
|
+
constructor(params) {
|
|
4151
|
+
const validatedParams = parseWithSchema(CallbackParamsSchema, params, "Callback constructor");
|
|
4152
|
+
if (!validatedParams.action) {
|
|
4153
|
+
throw new RuleArgumentException_default('Callback structure violated, missing mandatory "action" parameter.');
|
|
4154
|
+
}
|
|
4155
|
+
this.__action = validatedParams.action;
|
|
4156
|
+
this.__metaType = validatedParams.metaType ?? null;
|
|
4157
|
+
this.__metaId = validatedParams.metaId ?? null;
|
|
4158
|
+
this.__address = validatedParams.address ?? null;
|
|
4159
|
+
this.__token = validatedParams.token ?? null;
|
|
4160
|
+
this.__amount = validatedParams.amount ?? null;
|
|
4161
|
+
this.__comparison = validatedParams.comparison ?? null;
|
|
4162
|
+
if (validatedParams.meta) {
|
|
4163
|
+
this.__meta = validatedParams.meta instanceof Meta2 ? validatedParams.meta : Meta2.toObject(validatedParams.meta);
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
// Setters
|
|
4167
|
+
set comparison(comparison) {
|
|
4168
|
+
this.__comparison = comparison;
|
|
4169
|
+
}
|
|
4170
|
+
set amount(amount) {
|
|
4171
|
+
if (!isNumeric(amount)) {
|
|
4172
|
+
throw new CodeException("Parameter amount should be a string containing numbers");
|
|
4173
|
+
}
|
|
4174
|
+
this.__amount = amount;
|
|
4175
|
+
}
|
|
4176
|
+
set token(token) {
|
|
4177
|
+
this.__token = token;
|
|
4178
|
+
}
|
|
4179
|
+
set address(address) {
|
|
4180
|
+
this.__address = address;
|
|
4181
|
+
}
|
|
4182
|
+
set meta(meta) {
|
|
4183
|
+
this.__meta = meta instanceof Meta2 ? meta : Meta2.toObject(meta);
|
|
4184
|
+
}
|
|
4185
|
+
set metaType(metaType) {
|
|
4186
|
+
this.__metaType = metaType;
|
|
4187
|
+
}
|
|
4188
|
+
set metaId(metaId) {
|
|
4189
|
+
this.__metaId = metaId;
|
|
3363
4190
|
}
|
|
3364
4191
|
/**
|
|
3365
|
-
*
|
|
4192
|
+
* Creates a Callback from a plain object with validation
|
|
3366
4193
|
*/
|
|
3367
|
-
static
|
|
3368
|
-
return
|
|
4194
|
+
static toObject(object) {
|
|
4195
|
+
return new _Callback(object);
|
|
3369
4196
|
}
|
|
3370
4197
|
/**
|
|
3371
|
-
*
|
|
4198
|
+
* Converts to JSON representation
|
|
3372
4199
|
*/
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
valueTypes: {}
|
|
3380
|
-
};
|
|
4200
|
+
toJSON() {
|
|
4201
|
+
const meta = {
|
|
4202
|
+
action: this.__action
|
|
4203
|
+
};
|
|
4204
|
+
if (this.__metaType) {
|
|
4205
|
+
meta.metaType = this.__metaType;
|
|
3381
4206
|
}
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
const valueTypes = {};
|
|
3385
|
-
for (const item of normalized) {
|
|
3386
|
-
const type = item.value === null ? "null" : typeof item.value;
|
|
3387
|
-
valueTypes[type] = (valueTypes[type] || 0) + 1;
|
|
4207
|
+
if (this.__metaId) {
|
|
4208
|
+
meta.metaId = this.__metaId;
|
|
3388
4209
|
}
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
}
|
|
4210
|
+
if (this.__meta) {
|
|
4211
|
+
meta.meta = this.__meta.toJSON();
|
|
4212
|
+
}
|
|
4213
|
+
if (this.__address) {
|
|
4214
|
+
meta.address = this.__address;
|
|
4215
|
+
}
|
|
4216
|
+
if (this.__token) {
|
|
4217
|
+
meta.token = this.__token;
|
|
4218
|
+
}
|
|
4219
|
+
if (this.__amount) {
|
|
4220
|
+
meta.amount = this.__amount;
|
|
4221
|
+
}
|
|
4222
|
+
if (this.__comparison) {
|
|
4223
|
+
meta.comparison = this.__comparison;
|
|
4224
|
+
}
|
|
4225
|
+
return meta;
|
|
4226
|
+
}
|
|
4227
|
+
// Action type checkers using discriminated unions
|
|
4228
|
+
isReject() {
|
|
4229
|
+
return this._is("reject");
|
|
4230
|
+
}
|
|
4231
|
+
isMeta() {
|
|
4232
|
+
const prop = intersect(Object.keys(this.toJSON()), ["action", "metaId", "metaType", "meta"]);
|
|
4233
|
+
return prop.length === 4 && this._is("meta");
|
|
4234
|
+
}
|
|
4235
|
+
isCollect() {
|
|
4236
|
+
const prop = intersect(Object.keys(this.toJSON()), ["action", "address", "token", "amount", "comparison"]);
|
|
4237
|
+
return prop.length === 5 && this._is("collect");
|
|
4238
|
+
}
|
|
4239
|
+
isBuffer() {
|
|
4240
|
+
const prop = intersect(Object.keys(this.toJSON()), ["action", "address", "token", "amount", "comparison"]);
|
|
4241
|
+
return prop.length === 5 && this._is("buffer");
|
|
4242
|
+
}
|
|
4243
|
+
isRemit() {
|
|
4244
|
+
const prop = intersect(Object.keys(this.toJSON()), ["action", "token", "amount"]);
|
|
4245
|
+
return prop.length === 3 && this._is("remit");
|
|
4246
|
+
}
|
|
4247
|
+
isBurn() {
|
|
4248
|
+
const prop = intersect(Object.keys(this.toJSON()), ["action", "token", "amount", "comparison"]);
|
|
4249
|
+
return prop.length === 4 && this._is("burn");
|
|
3395
4250
|
}
|
|
3396
4251
|
/**
|
|
3397
|
-
*
|
|
4252
|
+
* Private helper to check action type with type narrowing
|
|
3398
4253
|
*/
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
return [];
|
|
3402
|
-
}
|
|
3403
|
-
const normalized = this.normalizeMeta(metaItems);
|
|
3404
|
-
return normalized.map((item) => ({ ...item }));
|
|
4254
|
+
_is(type) {
|
|
4255
|
+
return this.__action.toLowerCase() === type.toLowerCase();
|
|
3405
4256
|
}
|
|
3406
4257
|
/**
|
|
3407
|
-
*
|
|
4258
|
+
* Type-safe getter for action
|
|
3408
4259
|
*/
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
4260
|
+
get action() {
|
|
4261
|
+
return this.__action;
|
|
4262
|
+
}
|
|
4263
|
+
};
|
|
4264
|
+
|
|
4265
|
+
// src/instance/rules/Condition.ts
|
|
4266
|
+
var Condition = class {
|
|
4267
|
+
__key;
|
|
4268
|
+
__value;
|
|
4269
|
+
__comparison;
|
|
4270
|
+
constructor({ key, value, comparison }) {
|
|
4271
|
+
if ([key, value, comparison].some((item) => !item)) {
|
|
4272
|
+
throw new RuleArgumentException_default("Condition::constructor( { key, value, comparison } ) - not all class parameters are initialised!");
|
|
4273
|
+
}
|
|
4274
|
+
this.__key = key;
|
|
4275
|
+
this.__value = value;
|
|
4276
|
+
this.__comparison = comparison;
|
|
4277
|
+
}
|
|
4278
|
+
/**
|
|
4279
|
+
* Creates a Condition from a plain object
|
|
4280
|
+
*/
|
|
4281
|
+
static toObject(object) {
|
|
4282
|
+
return new this({
|
|
4283
|
+
key: object.key,
|
|
4284
|
+
value: object.value,
|
|
4285
|
+
comparison: object.comparison
|
|
3417
4286
|
});
|
|
3418
4287
|
}
|
|
4288
|
+
/**
|
|
4289
|
+
* Converts to JSON representation
|
|
4290
|
+
*/
|
|
4291
|
+
toJSON() {
|
|
4292
|
+
return {
|
|
4293
|
+
key: this.__key,
|
|
4294
|
+
value: this.__value,
|
|
4295
|
+
comparison: this.__comparison
|
|
4296
|
+
};
|
|
4297
|
+
}
|
|
3419
4298
|
};
|
|
3420
4299
|
|
|
3421
4300
|
// src/instance/rules/Rule.ts
|
|
4301
|
+
init_exception();
|
|
3422
4302
|
var Rule = class _Rule {
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
4303
|
+
__condition;
|
|
4304
|
+
__callback;
|
|
4305
|
+
constructor({ condition = [], callback = [] }) {
|
|
4306
|
+
for (const element of condition) {
|
|
4307
|
+
if (!(element instanceof Condition)) {
|
|
4308
|
+
throw new RuleArgumentException_default();
|
|
4309
|
+
}
|
|
4310
|
+
}
|
|
4311
|
+
for (const element of callback) {
|
|
4312
|
+
if (!(element instanceof Callback)) {
|
|
4313
|
+
throw new RuleArgumentException_default();
|
|
4314
|
+
}
|
|
4315
|
+
}
|
|
4316
|
+
this.__condition = condition;
|
|
4317
|
+
this.__callback = callback;
|
|
4318
|
+
}
|
|
4319
|
+
/**
|
|
4320
|
+
* Adds a condition to this rule
|
|
4321
|
+
*/
|
|
4322
|
+
set comparison(condition) {
|
|
4323
|
+
this.__condition.push(
|
|
4324
|
+
condition instanceof Condition ? condition : Condition.toObject(condition)
|
|
4325
|
+
);
|
|
4326
|
+
}
|
|
4327
|
+
/**
|
|
4328
|
+
* Adds a callback to this rule
|
|
4329
|
+
*/
|
|
4330
|
+
set callback(callback) {
|
|
4331
|
+
this.__callback.push(
|
|
4332
|
+
callback instanceof Callback ? callback : Callback.toObject(callback)
|
|
4333
|
+
);
|
|
3430
4334
|
}
|
|
3431
4335
|
/**
|
|
3432
4336
|
* Convert rule data to Rule object
|
|
3433
|
-
* @param
|
|
4337
|
+
* @param object - Rule data to convert
|
|
3434
4338
|
* @return Rule instance
|
|
3435
4339
|
*/
|
|
3436
|
-
static toObject(
|
|
3437
|
-
if (
|
|
3438
|
-
|
|
4340
|
+
static toObject(object) {
|
|
4341
|
+
if (!object.condition) {
|
|
4342
|
+
throw new MetaMissingException("Rule::toObject() - Incorrect rule format! There is no condition field.");
|
|
3439
4343
|
}
|
|
3440
|
-
|
|
4344
|
+
if (!object.callback) {
|
|
4345
|
+
throw new MetaMissingException("Rule::toObject() - Incorrect rule format! There is no callback field.");
|
|
4346
|
+
}
|
|
4347
|
+
const rule = new _Rule({});
|
|
4348
|
+
for (const condition of object.condition) {
|
|
4349
|
+
rule.comparison = condition;
|
|
4350
|
+
}
|
|
4351
|
+
for (const callback of object.callback) {
|
|
4352
|
+
rule.callback = callback;
|
|
4353
|
+
}
|
|
4354
|
+
return rule;
|
|
4355
|
+
}
|
|
4356
|
+
/**
|
|
4357
|
+
* Converts to JSON representation
|
|
4358
|
+
*/
|
|
4359
|
+
toJSON() {
|
|
4360
|
+
return {
|
|
4361
|
+
condition: this.__condition,
|
|
4362
|
+
callback: this.__callback
|
|
4363
|
+
};
|
|
3441
4364
|
}
|
|
3442
|
-
// TODO: Implement remaining Rule methods
|
|
3443
4365
|
};
|
|
3444
4366
|
|
|
3445
4367
|
// src/libraries/CheckMolecule.ts
|
|
4368
|
+
init_exception();
|
|
3446
4369
|
init_Dot();
|
|
3447
|
-
var CheckMolecule = class {
|
|
4370
|
+
var CheckMolecule = class _CheckMolecule {
|
|
3448
4371
|
molecule;
|
|
3449
4372
|
/**
|
|
3450
4373
|
* Initialize CheckMolecule with a molecule to validate
|
|
@@ -3724,7 +4647,7 @@ var CheckMolecule = class {
|
|
|
3724
4647
|
if (Number.isNaN(firstValue)) {
|
|
3725
4648
|
throw new TypeError('Invalid isotope "V" values');
|
|
3726
4649
|
}
|
|
3727
|
-
const remainder = senderWallet.balance + firstValue;
|
|
4650
|
+
const remainder = Number(senderWallet.balance) + firstValue;
|
|
3728
4651
|
if (remainder < 0) {
|
|
3729
4652
|
throw new exports.TransferBalanceException();
|
|
3730
4653
|
}
|
|
@@ -3799,6 +4722,77 @@ var CheckMolecule = class {
|
|
|
3799
4722
|
}
|
|
3800
4723
|
return true;
|
|
3801
4724
|
}
|
|
4725
|
+
/**
|
|
4726
|
+
* Reconstructs a Molecule instance from server-side GraphQL data.
|
|
4727
|
+
* Maps server atom field names to SDK-expected format and parses metasJson.
|
|
4728
|
+
*/
|
|
4729
|
+
static fromServerData({
|
|
4730
|
+
molecularHash,
|
|
4731
|
+
bundleHash,
|
|
4732
|
+
cellSlug = null,
|
|
4733
|
+
status = null,
|
|
4734
|
+
createdAt = null,
|
|
4735
|
+
atoms = []
|
|
4736
|
+
}) {
|
|
4737
|
+
const mappedAtoms = atoms.map((serverAtom) => {
|
|
4738
|
+
let meta = [];
|
|
4739
|
+
if (serverAtom.metasJson) {
|
|
4740
|
+
try {
|
|
4741
|
+
const parsed = JSON.parse(serverAtom.metasJson);
|
|
4742
|
+
if (Array.isArray(parsed)) {
|
|
4743
|
+
meta = parsed;
|
|
4744
|
+
} else if (parsed && typeof parsed === "object") {
|
|
4745
|
+
meta = Object.entries(parsed).map(([key, value]) => ({ key, value: String(value) }));
|
|
4746
|
+
}
|
|
4747
|
+
} catch (e) {
|
|
4748
|
+
meta = [];
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
return {
|
|
4752
|
+
position: serverAtom.position || null,
|
|
4753
|
+
walletAddress: serverAtom.walletAddress || null,
|
|
4754
|
+
isotope: serverAtom.isotope || null,
|
|
4755
|
+
token: serverAtom.tokenSlug || serverAtom.token || null,
|
|
4756
|
+
value: serverAtom.value != null ? String(serverAtom.value) : null,
|
|
4757
|
+
batchId: serverAtom.batchId || null,
|
|
4758
|
+
metaType: serverAtom.metaType || null,
|
|
4759
|
+
metaId: serverAtom.metaId || null,
|
|
4760
|
+
meta,
|
|
4761
|
+
index: serverAtom.index != null ? serverAtom.index : null,
|
|
4762
|
+
otsFragment: serverAtom.otsFragment || null,
|
|
4763
|
+
createdAt: serverAtom.createdAt || null
|
|
4764
|
+
};
|
|
4765
|
+
});
|
|
4766
|
+
return Molecule.fromJSON({
|
|
4767
|
+
molecularHash,
|
|
4768
|
+
bundle: bundleHash,
|
|
4769
|
+
cellSlug,
|
|
4770
|
+
status,
|
|
4771
|
+
createdAt,
|
|
4772
|
+
atoms: mappedAtoms
|
|
4773
|
+
});
|
|
4774
|
+
}
|
|
4775
|
+
/**
|
|
4776
|
+
* Verifies a molecule reconstructed from server-side GraphQL data.
|
|
4777
|
+
* Returns an object with verification result and any error details.
|
|
4778
|
+
*/
|
|
4779
|
+
static verifyFromServerData(moleculeData) {
|
|
4780
|
+
try {
|
|
4781
|
+
const molecule = _CheckMolecule.fromServerData(moleculeData);
|
|
4782
|
+
new _CheckMolecule(molecule).verify();
|
|
4783
|
+
return {
|
|
4784
|
+
molecularHash: moleculeData.molecularHash,
|
|
4785
|
+
verified: true,
|
|
4786
|
+
error: null
|
|
4787
|
+
};
|
|
4788
|
+
} catch (error) {
|
|
4789
|
+
return {
|
|
4790
|
+
molecularHash: moleculeData.molecularHash || null,
|
|
4791
|
+
verified: false,
|
|
4792
|
+
error: error.message || String(error)
|
|
4793
|
+
};
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
3802
4796
|
};
|
|
3803
4797
|
|
|
3804
4798
|
// src/core/Molecule.ts
|
|
@@ -3815,6 +4809,8 @@ var Molecule = class _Molecule {
|
|
|
3815
4809
|
remainderWallet;
|
|
3816
4810
|
atoms;
|
|
3817
4811
|
version;
|
|
4812
|
+
continuIdPosition;
|
|
4813
|
+
parentHashes;
|
|
3818
4814
|
local;
|
|
3819
4815
|
/**
|
|
3820
4816
|
* Create new Molecule instance
|
|
@@ -3826,7 +4822,8 @@ var Molecule = class _Molecule {
|
|
|
3826
4822
|
sourceWallet = null,
|
|
3827
4823
|
remainderWallet = null,
|
|
3828
4824
|
cellSlug = null,
|
|
3829
|
-
version = null
|
|
4825
|
+
version = null,
|
|
4826
|
+
continuIdPosition = null
|
|
3830
4827
|
} = {}) {
|
|
3831
4828
|
this.status = null;
|
|
3832
4829
|
this.molecularHash = null;
|
|
@@ -3835,11 +4832,12 @@ var Molecule = class _Molecule {
|
|
|
3835
4832
|
this.secret = secret;
|
|
3836
4833
|
this.bundle = bundle;
|
|
3837
4834
|
this.sourceWallet = sourceWallet;
|
|
4835
|
+
this.continuIdPosition = continuIdPosition;
|
|
3838
4836
|
this.atoms = [];
|
|
3839
|
-
|
|
4837
|
+
this.parentHashes = [];
|
|
4838
|
+
const versionRegistry = versions_default;
|
|
4839
|
+
if (version !== null && Object.prototype.hasOwnProperty.call(versionRegistry, version)) {
|
|
3840
4840
|
this.version = String(version);
|
|
3841
|
-
} else {
|
|
3842
|
-
this.version = null;
|
|
3843
4841
|
}
|
|
3844
4842
|
if (remainderWallet || sourceWallet) {
|
|
3845
4843
|
this.remainderWallet = remainderWallet || Wallet.create({
|
|
@@ -3874,7 +4872,7 @@ var Molecule = class _Molecule {
|
|
|
3874
4872
|
if (!Array.isArray(isotopes)) {
|
|
3875
4873
|
isotopes = [isotopes];
|
|
3876
4874
|
}
|
|
3877
|
-
return atoms.filter((atom) => isotopes.includes(atom.isotope));
|
|
4875
|
+
return atoms.filter((atom) => atom.isotope !== null && isotopes.includes(atom.isotope));
|
|
3878
4876
|
}
|
|
3879
4877
|
/**
|
|
3880
4878
|
* Generates the next atomic index
|
|
@@ -3895,25 +4893,65 @@ var Molecule = class _Molecule {
|
|
|
3895
4893
|
addAtom(atom) {
|
|
3896
4894
|
this.molecularHash = null;
|
|
3897
4895
|
atom.index = this.generateIndex();
|
|
3898
|
-
atom.version = this.version
|
|
4896
|
+
atom.version = this.version ?? void 0;
|
|
3899
4897
|
this.atoms.push(atom);
|
|
3900
4898
|
this.atoms = Atom.sortAtoms(this.atoms);
|
|
3901
4899
|
return this;
|
|
3902
4900
|
}
|
|
3903
4901
|
/**
|
|
3904
|
-
* Add user remainder atom for ContinuID
|
|
4902
|
+
* Add user remainder atom for ContinuID
|
|
4903
|
+
* Matches JavaScript SDK addContinuIdAtom exactly
|
|
4904
|
+
*/
|
|
4905
|
+
addContinuIdAtom() {
|
|
4906
|
+
if (!this.remainderWallet || this.remainderWallet.token !== "USER") {
|
|
4907
|
+
this.remainderWallet = Wallet.create({
|
|
4908
|
+
secret: this.secret,
|
|
4909
|
+
bundle: this.bundle
|
|
4910
|
+
});
|
|
4911
|
+
}
|
|
4912
|
+
const continuIdMeta = {};
|
|
4913
|
+
if (this.continuIdPosition) {
|
|
4914
|
+
continuIdMeta.previousPosition = this.continuIdPosition;
|
|
4915
|
+
} else if (this.sourceWallet && this.sourceWallet.position) {
|
|
4916
|
+
continuIdMeta.previousPosition = this.sourceWallet.position;
|
|
4917
|
+
}
|
|
4918
|
+
if (this.remainderWallet.pubkey) {
|
|
4919
|
+
continuIdMeta.pubkey = this.remainderWallet.pubkey;
|
|
4920
|
+
}
|
|
4921
|
+
if (this.remainderWallet.characters) {
|
|
4922
|
+
continuIdMeta.characters = this.remainderWallet.characters;
|
|
4923
|
+
}
|
|
4924
|
+
this.addAtom(Atom.create({
|
|
4925
|
+
isotope: "I",
|
|
4926
|
+
wallet: this.remainderWallet,
|
|
4927
|
+
metaType: "walletBundle",
|
|
4928
|
+
metaId: this.remainderWallet.bundle,
|
|
4929
|
+
meta: new AtomMeta(continuIdMeta)
|
|
4930
|
+
}));
|
|
4931
|
+
return this;
|
|
4932
|
+
}
|
|
4933
|
+
/**
|
|
4934
|
+
* Add a policy R-isotope atom (matching JS SDK)
|
|
3905
4935
|
*/
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
}
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
4936
|
+
addPolicyAtom({
|
|
4937
|
+
metaType,
|
|
4938
|
+
metaId,
|
|
4939
|
+
meta = {},
|
|
4940
|
+
policy = {}
|
|
4941
|
+
}) {
|
|
4942
|
+
const atomMeta = new AtomMeta(meta);
|
|
4943
|
+
atomMeta.addPolicy(policy);
|
|
4944
|
+
const wallet = Wallet.create({
|
|
4945
|
+
secret: this.secret,
|
|
4946
|
+
bundle: this.sourceWallet.bundle,
|
|
4947
|
+
token: "USER"
|
|
4948
|
+
});
|
|
4949
|
+
this.addAtom(Atom.create({
|
|
4950
|
+
wallet,
|
|
4951
|
+
isotope: "R",
|
|
4952
|
+
metaType,
|
|
4953
|
+
metaId,
|
|
4954
|
+
meta: atomMeta
|
|
3917
4955
|
}));
|
|
3918
4956
|
return this;
|
|
3919
4957
|
}
|
|
@@ -3928,34 +4966,25 @@ var Molecule = class _Molecule {
|
|
|
3928
4966
|
if (!this.sourceWallet) {
|
|
3929
4967
|
throw new Error("Source wallet required for value transfer");
|
|
3930
4968
|
}
|
|
3931
|
-
if (this.sourceWallet.balance - amount < 0) {
|
|
4969
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
3932
4970
|
throw new BalanceInsufficientException();
|
|
3933
4971
|
}
|
|
3934
|
-
this.addAtom(
|
|
4972
|
+
this.addAtom(Atom.create({
|
|
3935
4973
|
isotope: "V",
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
token: this.sourceWallet.token,
|
|
3939
|
-
value: -this.sourceWallet.balance
|
|
4974
|
+
wallet: this.sourceWallet,
|
|
4975
|
+
value: -Number(this.sourceWallet.balance)
|
|
3940
4976
|
}));
|
|
3941
|
-
this.addAtom(
|
|
4977
|
+
this.addAtom(Atom.create({
|
|
3942
4978
|
isotope: "V",
|
|
3943
|
-
|
|
3944
|
-
walletAddress: recipientWallet.address,
|
|
3945
|
-
token: recipientWallet.token,
|
|
4979
|
+
wallet: recipientWallet,
|
|
3946
4980
|
value: amount,
|
|
3947
4981
|
metaType: "walletBundle",
|
|
3948
4982
|
metaId: recipientWallet.bundle
|
|
3949
4983
|
}));
|
|
3950
|
-
|
|
3951
|
-
throw new Error("Remainder wallet required for value transfer");
|
|
3952
|
-
}
|
|
3953
|
-
this.addAtom(new Atom({
|
|
4984
|
+
this.addAtom(Atom.create({
|
|
3954
4985
|
isotope: "V",
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
token: this.remainderWallet.token,
|
|
3958
|
-
value: this.sourceWallet.balance - amount,
|
|
4986
|
+
wallet: this.remainderWallet,
|
|
4987
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
3959
4988
|
metaType: "walletBundle",
|
|
3960
4989
|
metaId: this.remainderWallet.bundle
|
|
3961
4990
|
}));
|
|
@@ -3984,6 +5013,17 @@ var Molecule = class _Molecule {
|
|
|
3984
5013
|
throw new SignatureMalformedException("No atoms available for signing!");
|
|
3985
5014
|
}
|
|
3986
5015
|
let signingPosition = signingAtom.position;
|
|
5016
|
+
const signingWalletMeta = signingAtom.aggregatedMeta ? signingAtom.aggregatedMeta() : null;
|
|
5017
|
+
const signingWalletJson = signingWalletMeta?.signingWallet;
|
|
5018
|
+
if (signingWalletJson) {
|
|
5019
|
+
try {
|
|
5020
|
+
const parsedSigningWallet = JSON.parse(signingWalletJson);
|
|
5021
|
+
if (parsedSigningWallet.position) {
|
|
5022
|
+
signingPosition = parsedSigningWallet.position;
|
|
5023
|
+
}
|
|
5024
|
+
} catch {
|
|
5025
|
+
}
|
|
5026
|
+
}
|
|
3987
5027
|
if (!signingPosition) {
|
|
3988
5028
|
throw new SignatureMalformedException("Signing wallet must have a position!");
|
|
3989
5029
|
}
|
|
@@ -4102,7 +5142,7 @@ var Molecule = class _Molecule {
|
|
|
4102
5142
|
*/
|
|
4103
5143
|
toJSON(options = {}) {
|
|
4104
5144
|
const {
|
|
4105
|
-
includeValidationContext =
|
|
5145
|
+
includeValidationContext = false,
|
|
4106
5146
|
includeOtsFragments = true,
|
|
4107
5147
|
secureMode = false
|
|
4108
5148
|
} = options;
|
|
@@ -4115,21 +5155,24 @@ var Molecule = class _Molecule {
|
|
|
4115
5155
|
molecularHash: this.molecularHash,
|
|
4116
5156
|
createdAt: this.createdAt,
|
|
4117
5157
|
cellSlug: this.cellSlug,
|
|
4118
|
-
cellSlugOrigin: this.cellSlugOrigin,
|
|
4119
|
-
version: this.version,
|
|
4120
5158
|
bundle: this.bundle,
|
|
4121
5159
|
// Serialized atoms array with optional OTS fragments
|
|
4122
5160
|
atoms: this.atoms.map((atom) => atom.toJSON({
|
|
4123
5161
|
includeOtsFragments
|
|
4124
5162
|
}))
|
|
4125
5163
|
};
|
|
5164
|
+
if (this.parentHashes && this.parentHashes.length > 0) {
|
|
5165
|
+
serialized.parentHashes = this.parentHashes;
|
|
5166
|
+
}
|
|
4126
5167
|
if (includeValidationContext) {
|
|
5168
|
+
serialized.cellSlugOrigin = this.cellSlugOrigin;
|
|
5169
|
+
serialized.version = this.version;
|
|
4127
5170
|
if (this.sourceWallet) {
|
|
4128
5171
|
serialized.sourceWallet = {
|
|
4129
5172
|
address: this.sourceWallet.address,
|
|
4130
5173
|
position: this.sourceWallet.position,
|
|
4131
5174
|
token: this.sourceWallet.token,
|
|
4132
|
-
balance: this.sourceWallet.balance || 0,
|
|
5175
|
+
balance: this.sourceWallet.balance || "0",
|
|
4133
5176
|
bundle: this.sourceWallet.bundle,
|
|
4134
5177
|
batchId: this.sourceWallet.batchId || null,
|
|
4135
5178
|
characters: this.sourceWallet.characters || "BASE64",
|
|
@@ -4145,7 +5188,7 @@ var Molecule = class _Molecule {
|
|
|
4145
5188
|
address: this.remainderWallet.address,
|
|
4146
5189
|
position: this.remainderWallet.position,
|
|
4147
5190
|
token: this.remainderWallet.token,
|
|
4148
|
-
balance: this.remainderWallet.balance || 0,
|
|
5191
|
+
balance: this.remainderWallet.balance || "0",
|
|
4149
5192
|
bundle: this.remainderWallet.bundle,
|
|
4150
5193
|
batchId: this.remainderWallet.batchId || null,
|
|
4151
5194
|
characters: this.remainderWallet.characters || "BASE64",
|
|
@@ -4173,30 +5216,26 @@ var Molecule = class _Molecule {
|
|
|
4173
5216
|
// =============================================================================
|
|
4174
5217
|
/**
|
|
4175
5218
|
* Initialize token creation
|
|
5219
|
+
* Matches JavaScript SDK initTokenCreation implementation
|
|
4176
5220
|
*/
|
|
4177
5221
|
initTokenCreation({
|
|
4178
5222
|
recipientWallet,
|
|
4179
5223
|
amount,
|
|
4180
5224
|
meta
|
|
4181
5225
|
}) {
|
|
4182
|
-
this.
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
5226
|
+
if (!this.sourceWallet) {
|
|
5227
|
+
throw new Error("Source wallet required for token creation");
|
|
5228
|
+
}
|
|
5229
|
+
const atomMeta = new AtomMeta(meta);
|
|
5230
|
+
atomMeta.setMetaWallet(recipientWallet);
|
|
5231
|
+
this.addAtom(Atom.create({
|
|
5232
|
+
isotope: "C",
|
|
5233
|
+
wallet: this.sourceWallet,
|
|
4187
5234
|
value: amount,
|
|
4188
5235
|
metaType: "token",
|
|
4189
5236
|
metaId: recipientWallet.token,
|
|
4190
|
-
meta:
|
|
4191
|
-
|
|
4192
|
-
this.addAtom(new Atom({
|
|
4193
|
-
isotope: "M",
|
|
4194
|
-
position: recipientWallet.position,
|
|
4195
|
-
walletAddress: recipientWallet.address,
|
|
4196
|
-
token: recipientWallet.token,
|
|
4197
|
-
metaType: "walletBundle",
|
|
4198
|
-
metaId: recipientWallet.bundle,
|
|
4199
|
-
meta: meta ? [{ key: "tokenMeta", value: JSON.stringify(meta) }] : []
|
|
5237
|
+
meta: atomMeta,
|
|
5238
|
+
batchId: recipientWallet.batchId
|
|
4200
5239
|
}));
|
|
4201
5240
|
this.addContinuIdAtom();
|
|
4202
5241
|
return this;
|
|
@@ -4206,26 +5245,57 @@ var Molecule = class _Molecule {
|
|
|
4206
5245
|
*/
|
|
4207
5246
|
burnToken({
|
|
4208
5247
|
amount,
|
|
4209
|
-
walletBundle = null
|
|
5248
|
+
walletBundle: _walletBundle = null
|
|
4210
5249
|
}) {
|
|
4211
5250
|
if (!this.sourceWallet) {
|
|
4212
5251
|
throw new Error("Source wallet required for token burning");
|
|
4213
5252
|
}
|
|
4214
|
-
if (amount
|
|
4215
|
-
throw new NegativeAmountException();
|
|
5253
|
+
if (amount < 0) {
|
|
5254
|
+
throw new NegativeAmountException("Molecule::burnToken() - Amount to burn must be positive!");
|
|
4216
5255
|
}
|
|
4217
|
-
if (this.sourceWallet.balance - amount < 0) {
|
|
5256
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
4218
5257
|
throw new BalanceInsufficientException();
|
|
4219
5258
|
}
|
|
4220
|
-
|
|
5259
|
+
const burnWallet = new Wallet({
|
|
5260
|
+
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
5261
|
+
token: this.sourceWallet.token
|
|
5262
|
+
});
|
|
5263
|
+
this.addAtom(Atom.create({
|
|
4221
5264
|
isotope: "V",
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
5265
|
+
wallet: this.sourceWallet,
|
|
5266
|
+
value: -Number(this.sourceWallet.balance)
|
|
5267
|
+
}));
|
|
5268
|
+
this.addAtom(Atom.create({
|
|
5269
|
+
isotope: "V",
|
|
5270
|
+
wallet: burnWallet,
|
|
5271
|
+
value: amount,
|
|
5272
|
+
metaType: "walletBundle",
|
|
5273
|
+
metaId: burnWallet.bundle
|
|
5274
|
+
}));
|
|
5275
|
+
this.addAtom(Atom.create({
|
|
5276
|
+
isotope: "V",
|
|
5277
|
+
wallet: this.remainderWallet,
|
|
5278
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
5279
|
+
metaType: "walletBundle",
|
|
5280
|
+
metaId: this.remainderWallet.bundle
|
|
5281
|
+
}));
|
|
5282
|
+
return this;
|
|
5283
|
+
}
|
|
5284
|
+
/**
|
|
5285
|
+
* Initialize authorization request
|
|
5286
|
+
* Creates U-isotope (authorization) atom for requesting auth token
|
|
5287
|
+
* Matches JavaScript SDK Molecule.initAuthorization
|
|
5288
|
+
*/
|
|
5289
|
+
initAuthorization({ meta }) {
|
|
5290
|
+
if (!this.sourceWallet) {
|
|
5291
|
+
throw new Error("Source wallet required for authorization");
|
|
5292
|
+
}
|
|
5293
|
+
this.addAtom(Atom.create({
|
|
5294
|
+
isotope: "U",
|
|
5295
|
+
wallet: this.sourceWallet,
|
|
5296
|
+
meta: new AtomMeta(meta)
|
|
4228
5297
|
}));
|
|
5298
|
+
this.addContinuIdAtom();
|
|
4229
5299
|
return this;
|
|
4230
5300
|
}
|
|
4231
5301
|
/**
|
|
@@ -4240,59 +5310,123 @@ var Molecule = class _Molecule {
|
|
|
4240
5310
|
if (!this.sourceWallet) {
|
|
4241
5311
|
throw new Error("Source wallet required for meta creation");
|
|
4242
5312
|
}
|
|
4243
|
-
|
|
4244
|
-
if (meta) {
|
|
4245
|
-
if (Array.isArray(meta)) {
|
|
4246
|
-
metaArray.push(...meta);
|
|
4247
|
-
} else if (typeof meta === "object") {
|
|
4248
|
-
for (const [key, value] of Object.entries(meta)) {
|
|
4249
|
-
metaArray.push({ key, value });
|
|
4250
|
-
}
|
|
4251
|
-
} else {
|
|
4252
|
-
metaArray.push({ key: "value", value: meta });
|
|
4253
|
-
}
|
|
4254
|
-
}
|
|
4255
|
-
if (policy) {
|
|
4256
|
-
metaArray.push({ key: "policy", value: JSON.stringify(policy) });
|
|
4257
|
-
}
|
|
4258
|
-
this.addAtom(new Atom({
|
|
5313
|
+
this.addAtom(Atom.create({
|
|
4259
5314
|
isotope: "M",
|
|
4260
|
-
|
|
4261
|
-
walletAddress: this.sourceWallet.address,
|
|
4262
|
-
token: this.sourceWallet.token,
|
|
5315
|
+
wallet: this.sourceWallet,
|
|
4263
5316
|
metaType,
|
|
4264
5317
|
metaId,
|
|
4265
|
-
meta:
|
|
5318
|
+
meta: new AtomMeta(meta)
|
|
4266
5319
|
}));
|
|
5320
|
+
if (policy && Object.keys(policy).length > 0) {
|
|
5321
|
+
this.addPolicyAtom({
|
|
5322
|
+
metaType,
|
|
5323
|
+
metaId,
|
|
5324
|
+
meta,
|
|
5325
|
+
policy
|
|
5326
|
+
});
|
|
5327
|
+
}
|
|
4267
5328
|
this.addContinuIdAtom();
|
|
4268
5329
|
return this;
|
|
4269
5330
|
}
|
|
4270
5331
|
/**
|
|
4271
5332
|
* Initialize wallet creation
|
|
5333
|
+
* Uses source wallet for atom properties (matching JavaScript SDK)
|
|
5334
|
+
* The wallet being created is stored in metadata
|
|
4272
5335
|
*/
|
|
4273
5336
|
initWalletCreation(wallet, atomMeta = null) {
|
|
4274
|
-
|
|
5337
|
+
if (!this.sourceWallet) {
|
|
5338
|
+
throw new Error("Source wallet required for wallet creation");
|
|
5339
|
+
}
|
|
5340
|
+
if (!atomMeta) {
|
|
5341
|
+
atomMeta = new AtomMeta();
|
|
5342
|
+
}
|
|
5343
|
+
atomMeta.setMetaWallet(wallet);
|
|
5344
|
+
const creationAtom = Atom.create({
|
|
4275
5345
|
isotope: "C",
|
|
4276
|
-
|
|
4277
|
-
walletAddress: wallet.address,
|
|
4278
|
-
token: wallet.token,
|
|
5346
|
+
wallet: this.sourceWallet,
|
|
4279
5347
|
metaType: "wallet",
|
|
4280
5348
|
metaId: wallet.address,
|
|
4281
|
-
meta: atomMeta
|
|
5349
|
+
meta: atomMeta,
|
|
5350
|
+
batchId: wallet.batchId
|
|
4282
5351
|
});
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
5352
|
+
this.addAtom(creationAtom);
|
|
5353
|
+
this.addContinuIdAtom();
|
|
5354
|
+
return this;
|
|
5355
|
+
}
|
|
5356
|
+
/**
|
|
5357
|
+
* Creates atoms for rule definition
|
|
5358
|
+
* Matches JavaScript SDK Molecule.createRule method
|
|
5359
|
+
*
|
|
5360
|
+
* @param metaType - The meta type for the rule
|
|
5361
|
+
* @param metaId - The meta ID for the rule
|
|
5362
|
+
* @param rule - Array of Rule objects or rule data
|
|
5363
|
+
* @param policy - Optional policy object
|
|
5364
|
+
* @return This molecule instance for chaining
|
|
5365
|
+
*/
|
|
5366
|
+
createRule({
|
|
5367
|
+
metaType,
|
|
5368
|
+
metaId,
|
|
5369
|
+
rule,
|
|
5370
|
+
policy = {}
|
|
5371
|
+
}) {
|
|
5372
|
+
if (!this.sourceWallet) {
|
|
5373
|
+
throw new Error("Source wallet required for createRule");
|
|
5374
|
+
}
|
|
5375
|
+
const ruleArray = Array.isArray(rule) ? rule : [rule];
|
|
5376
|
+
const rules = [];
|
|
5377
|
+
for (const r of ruleArray) {
|
|
5378
|
+
rules.push(r instanceof Rule ? r : Rule.toObject(r));
|
|
5379
|
+
}
|
|
5380
|
+
const atomMeta = new AtomMeta({
|
|
5381
|
+
rule: JSON.stringify(rules)
|
|
5382
|
+
});
|
|
5383
|
+
if (policy && Object.keys(policy).length > 0) {
|
|
5384
|
+
atomMeta.addPolicy(policy);
|
|
5385
|
+
}
|
|
5386
|
+
this.addAtom(Atom.create({
|
|
5387
|
+
isotope: "R",
|
|
5388
|
+
wallet: this.sourceWallet,
|
|
5389
|
+
metaType,
|
|
5390
|
+
metaId,
|
|
5391
|
+
meta: atomMeta
|
|
5392
|
+
}));
|
|
5393
|
+
this.addContinuIdAtom();
|
|
5394
|
+
return this;
|
|
5395
|
+
}
|
|
5396
|
+
/**
|
|
5397
|
+
* Initializes a token request molecule
|
|
5398
|
+
* Matches JavaScript SDK Molecule.initTokenRequest method
|
|
5399
|
+
*
|
|
5400
|
+
* @param token - Token slug to request
|
|
5401
|
+
* @param amount - Amount of tokens to request
|
|
5402
|
+
* @param metaType - Meta type (typically 'walletBundle')
|
|
5403
|
+
* @param metaId - Meta ID (typically recipient bundle hash)
|
|
5404
|
+
* @param meta - Optional additional metadata
|
|
5405
|
+
* @param batchId - Optional batch ID
|
|
5406
|
+
* @return This molecule instance for chaining
|
|
5407
|
+
*/
|
|
5408
|
+
initTokenRequest({
|
|
5409
|
+
token,
|
|
5410
|
+
amount,
|
|
5411
|
+
metaType,
|
|
5412
|
+
metaId,
|
|
5413
|
+
meta = {},
|
|
5414
|
+
batchId = null
|
|
5415
|
+
}) {
|
|
5416
|
+
if (!this.sourceWallet) {
|
|
5417
|
+
throw new Error("Source wallet required for initTokenRequest");
|
|
4294
5418
|
}
|
|
4295
|
-
|
|
5419
|
+
const metaWithToken = { ...meta, token, amount: String(amount) };
|
|
5420
|
+
this.local = 1;
|
|
5421
|
+
this.addAtom(Atom.create({
|
|
5422
|
+
isotope: "T",
|
|
5423
|
+
wallet: this.sourceWallet,
|
|
5424
|
+
value: amount,
|
|
5425
|
+
metaType,
|
|
5426
|
+
metaId,
|
|
5427
|
+
meta: new AtomMeta(metaWithToken),
|
|
5428
|
+
batchId
|
|
5429
|
+
}));
|
|
4296
5430
|
this.addContinuIdAtom();
|
|
4297
5431
|
return this;
|
|
4298
5432
|
}
|
|
@@ -4342,6 +5476,7 @@ var Molecule = class _Molecule {
|
|
|
4342
5476
|
}
|
|
4343
5477
|
});
|
|
4344
5478
|
}
|
|
5479
|
+
molecule.parentHashes = Array.isArray(data.parentHashes) ? [...data.parentHashes] : [];
|
|
4345
5480
|
if (includeValidationContext) {
|
|
4346
5481
|
if (data.sourceWallet) {
|
|
4347
5482
|
molecule.sourceWallet = new Wallet({
|
|
@@ -4352,7 +5487,7 @@ var Molecule = class _Molecule {
|
|
|
4352
5487
|
batchId: data.sourceWallet.batchId,
|
|
4353
5488
|
characters: data.sourceWallet.characters
|
|
4354
5489
|
});
|
|
4355
|
-
molecule.sourceWallet.balance = data.sourceWallet.balance
|
|
5490
|
+
molecule.sourceWallet.balance = String(data.sourceWallet.balance != null ? data.sourceWallet.balance : 0);
|
|
4356
5491
|
molecule.sourceWallet.address = data.sourceWallet.address;
|
|
4357
5492
|
if (data.sourceWallet.pubkey) {
|
|
4358
5493
|
molecule.sourceWallet.pubkey = data.sourceWallet.pubkey;
|
|
@@ -4370,7 +5505,7 @@ var Molecule = class _Molecule {
|
|
|
4370
5505
|
batchId: data.remainderWallet.batchId,
|
|
4371
5506
|
characters: data.remainderWallet.characters
|
|
4372
5507
|
});
|
|
4373
|
-
molecule.remainderWallet.balance = data.remainderWallet.balance
|
|
5508
|
+
molecule.remainderWallet.balance = String(data.remainderWallet.balance != null ? data.remainderWallet.balance : 0);
|
|
4374
5509
|
molecule.remainderWallet.address = data.remainderWallet.address;
|
|
4375
5510
|
if (data.remainderWallet.pubkey) {
|
|
4376
5511
|
molecule.remainderWallet.pubkey = data.remainderWallet.pubkey;
|
|
@@ -4391,245 +5526,208 @@ var Molecule = class _Molecule {
|
|
|
4391
5526
|
static jsonToObject(json) {
|
|
4392
5527
|
return _Molecule.fromJSON(json);
|
|
4393
5528
|
}
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
/**
|
|
4398
|
-
* Create new AtomMeta instance
|
|
4399
|
-
* @param meta - Initial metadata (object or array)
|
|
4400
|
-
*/
|
|
4401
|
-
constructor(meta = null) {
|
|
4402
|
-
this.meta = Meta.normalizeMeta(meta);
|
|
4403
|
-
}
|
|
5529
|
+
// =============================================================================
|
|
5530
|
+
// ISOTOPE INIT METHODS - MATCHING JAVASCRIPT SDK PARITY
|
|
5531
|
+
// =============================================================================
|
|
4404
5532
|
/**
|
|
4405
|
-
*
|
|
4406
|
-
*
|
|
4407
|
-
*
|
|
5533
|
+
* Initialize a P-type molecule for peer registration
|
|
5534
|
+
* Matches JavaScript SDK Molecule.initPeering implementation exactly
|
|
5535
|
+
*
|
|
5536
|
+
* @param host - The peer host URL to register
|
|
5537
|
+
* @return This molecule instance for chaining
|
|
4408
5538
|
*/
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
for (const item of normalized) {
|
|
4413
|
-
if (existingKeys.has(item.key)) {
|
|
4414
|
-
const index = this.meta.findIndex((m) => m.key === item.key);
|
|
4415
|
-
if (index !== -1) {
|
|
4416
|
-
this.meta[index] = item;
|
|
4417
|
-
}
|
|
4418
|
-
} else {
|
|
4419
|
-
this.meta.push(item);
|
|
4420
|
-
existingKeys.add(item.key);
|
|
4421
|
-
}
|
|
5539
|
+
initPeering({ host }) {
|
|
5540
|
+
if (!this.sourceWallet) {
|
|
5541
|
+
throw new Error("Source wallet required for peer registration");
|
|
4422
5542
|
}
|
|
5543
|
+
this.addAtom(Atom.create({
|
|
5544
|
+
isotope: "P",
|
|
5545
|
+
wallet: this.sourceWallet,
|
|
5546
|
+
metaType: "walletBundle",
|
|
5547
|
+
metaId: this.bundle,
|
|
5548
|
+
meta: new AtomMeta({ peerHost: host })
|
|
5549
|
+
}));
|
|
5550
|
+
this.addContinuIdAtom();
|
|
4423
5551
|
return this;
|
|
4424
5552
|
}
|
|
4425
5553
|
/**
|
|
4426
|
-
*
|
|
4427
|
-
*
|
|
4428
|
-
*
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
* Set atom wallet metadata
|
|
4435
|
-
* @param wallet - Wallet to extract metadata from
|
|
4436
|
-
* @return This instance for chaining
|
|
5554
|
+
* Initialize an A-type molecule for an append request
|
|
5555
|
+
* Matches JavaScript SDK Molecule.initAppendRequest implementation exactly
|
|
5556
|
+
*
|
|
5557
|
+
* @param metaType - The target MetaType to append to
|
|
5558
|
+
* @param metaId - The target MetaId to append to
|
|
5559
|
+
* @param action - The action to perform
|
|
5560
|
+
* @param meta - Additional metadata
|
|
5561
|
+
* @return This molecule instance for chaining
|
|
4437
5562
|
*/
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
}
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
if (wallet.tradeRates && Object.keys(wallet.tradeRates).length) {
|
|
4447
|
-
walletMeta.tradeRates = JSON.stringify(wallet.tradeRates);
|
|
5563
|
+
initAppendRequest({
|
|
5564
|
+
metaType,
|
|
5565
|
+
metaId,
|
|
5566
|
+
action,
|
|
5567
|
+
meta = {}
|
|
5568
|
+
}) {
|
|
5569
|
+
if (!this.sourceWallet) {
|
|
5570
|
+
throw new Error("Source wallet required for append request");
|
|
4448
5571
|
}
|
|
4449
|
-
this.
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
4457
|
-
*/
|
|
4458
|
-
setMetaWallet(wallet) {
|
|
4459
|
-
this.merge({
|
|
4460
|
-
walletTokenSlug: wallet.token,
|
|
4461
|
-
walletBundleHash: wallet.bundle,
|
|
4462
|
-
walletAddress: wallet.address,
|
|
4463
|
-
walletPosition: wallet.position,
|
|
4464
|
-
walletBatchId: wallet.batchId,
|
|
4465
|
-
walletPubkey: wallet.pubkey,
|
|
4466
|
-
walletCharacters: wallet.characters
|
|
4467
|
-
});
|
|
4468
|
-
return this;
|
|
4469
|
-
}
|
|
4470
|
-
/**
|
|
4471
|
-
* Set shadow wallet claim flag
|
|
4472
|
-
* @param shadowWalletClaim - Claim flag (converted to number)
|
|
4473
|
-
* @return This instance for chaining
|
|
4474
|
-
*/
|
|
4475
|
-
setShadowWalletClaim(shadowWalletClaim) {
|
|
4476
|
-
this.merge({ shadowWalletClaim: Number(shadowWalletClaim) });
|
|
4477
|
-
return this;
|
|
4478
|
-
}
|
|
4479
|
-
/**
|
|
4480
|
-
* Set signing wallet metadata
|
|
4481
|
-
* @param signingWallet - Wallet used for signing
|
|
4482
|
-
* @return This instance for chaining
|
|
4483
|
-
*/
|
|
4484
|
-
setSigningWallet(signingWallet) {
|
|
4485
|
-
this.merge({
|
|
4486
|
-
signingWallet: JSON.stringify({
|
|
4487
|
-
tokenSlug: signingWallet.token,
|
|
4488
|
-
bundleHash: signingWallet.bundle,
|
|
4489
|
-
address: signingWallet.address,
|
|
4490
|
-
position: signingWallet.position,
|
|
4491
|
-
pubkey: signingWallet.pubkey,
|
|
4492
|
-
characters: signingWallet.characters
|
|
4493
|
-
})
|
|
4494
|
-
});
|
|
4495
|
-
return this;
|
|
4496
|
-
}
|
|
4497
|
-
/**
|
|
4498
|
-
* Add policy metadata
|
|
4499
|
-
* @param policy - Policy object to add
|
|
4500
|
-
* @return This instance for chaining
|
|
4501
|
-
*/
|
|
4502
|
-
addPolicy(policy) {
|
|
4503
|
-
this.merge({
|
|
4504
|
-
policy: JSON.stringify(policy)
|
|
4505
|
-
});
|
|
5572
|
+
this.addAtom(Atom.create({
|
|
5573
|
+
isotope: "A",
|
|
5574
|
+
wallet: this.sourceWallet,
|
|
5575
|
+
metaType,
|
|
5576
|
+
metaId,
|
|
5577
|
+
meta: new AtomMeta({ action, ...meta })
|
|
5578
|
+
}));
|
|
5579
|
+
this.addContinuIdAtom();
|
|
4506
5580
|
return this;
|
|
4507
5581
|
}
|
|
4508
5582
|
/**
|
|
4509
|
-
*
|
|
4510
|
-
*
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
/**
|
|
4516
|
-
* Convert metadata to plain object
|
|
4517
|
-
* @return Aggregated metadata object
|
|
4518
|
-
*/
|
|
4519
|
-
toObject() {
|
|
4520
|
-
return Meta.aggregateMeta(this.meta);
|
|
4521
|
-
}
|
|
4522
|
-
/**
|
|
4523
|
-
* Convert metadata to JSON string
|
|
4524
|
-
* @return JSON string representation
|
|
4525
|
-
*/
|
|
4526
|
-
toJSON() {
|
|
4527
|
-
return JSON.stringify(this.toObject());
|
|
4528
|
-
}
|
|
4529
|
-
/**
|
|
4530
|
-
* Get metadata value by key
|
|
4531
|
-
* @param key - Key to lookup
|
|
4532
|
-
* @param defaultValue - Default if not found
|
|
4533
|
-
* @return Value or default
|
|
4534
|
-
*/
|
|
4535
|
-
getValue(key, defaultValue = null) {
|
|
4536
|
-
return Meta.getMetaValue(this.meta, key, defaultValue);
|
|
4537
|
-
}
|
|
4538
|
-
/**
|
|
4539
|
-
* Check if metadata has a key
|
|
4540
|
-
* @param key - Key to check
|
|
4541
|
-
* @return True if key exists
|
|
4542
|
-
*/
|
|
4543
|
-
hasKey(key) {
|
|
4544
|
-
return Meta.hasKey(this.meta, key);
|
|
4545
|
-
}
|
|
4546
|
-
/**
|
|
4547
|
-
* Remove metadata by key
|
|
4548
|
-
* @param key - Key to remove
|
|
4549
|
-
* @return This instance for chaining
|
|
5583
|
+
* Initialize a deposit buffer operation (B-isotope)
|
|
5584
|
+
* Matches JavaScript SDK Molecule.initDepositBuffer implementation exactly
|
|
5585
|
+
*
|
|
5586
|
+
* @param amount - Amount to deposit into buffer
|
|
5587
|
+
* @param tradeRates - Trade rates for the buffer wallet
|
|
5588
|
+
* @return This molecule instance for chaining
|
|
4550
5589
|
*/
|
|
4551
|
-
|
|
4552
|
-
|
|
5590
|
+
initDepositBuffer({
|
|
5591
|
+
amount,
|
|
5592
|
+
tradeRates
|
|
5593
|
+
}) {
|
|
5594
|
+
if (!this.sourceWallet) {
|
|
5595
|
+
throw new Error("Source wallet required for buffer deposit");
|
|
5596
|
+
}
|
|
5597
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
5598
|
+
throw new BalanceInsufficientException();
|
|
5599
|
+
}
|
|
5600
|
+
const bufferWallet = Wallet.create({
|
|
5601
|
+
secret: this.secret,
|
|
5602
|
+
bundle: this.bundle,
|
|
5603
|
+
token: this.sourceWallet.token,
|
|
5604
|
+
batchId: this.sourceWallet.batchId
|
|
5605
|
+
});
|
|
5606
|
+
if (tradeRates) {
|
|
5607
|
+
bufferWallet.tradeRates = tradeRates;
|
|
5608
|
+
}
|
|
5609
|
+
this.addAtom(Atom.create({
|
|
5610
|
+
isotope: "V",
|
|
5611
|
+
wallet: this.sourceWallet,
|
|
5612
|
+
value: -Number(this.sourceWallet.balance)
|
|
5613
|
+
}));
|
|
5614
|
+
this.addAtom(Atom.create({
|
|
5615
|
+
isotope: "B",
|
|
5616
|
+
wallet: bufferWallet,
|
|
5617
|
+
value: amount,
|
|
5618
|
+
metaType: "walletBundle",
|
|
5619
|
+
metaId: this.sourceWallet.bundle
|
|
5620
|
+
}));
|
|
5621
|
+
this.addAtom(Atom.create({
|
|
5622
|
+
isotope: "V",
|
|
5623
|
+
wallet: this.remainderWallet,
|
|
5624
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
5625
|
+
metaType: "walletBundle",
|
|
5626
|
+
metaId: this.sourceWallet.bundle
|
|
5627
|
+
}));
|
|
4553
5628
|
return this;
|
|
4554
5629
|
}
|
|
4555
5630
|
/**
|
|
4556
|
-
*
|
|
4557
|
-
*
|
|
5631
|
+
* Initialize a withdraw buffer operation (B-isotope)
|
|
5632
|
+
* Matches JavaScript SDK Molecule.initWithdrawBuffer implementation exactly
|
|
5633
|
+
*
|
|
5634
|
+
* @param recipients - Map of recipientBundle → amount
|
|
5635
|
+
* @param signingWallet - Optional signing wallet for reconciliation
|
|
5636
|
+
* @return This molecule instance for chaining
|
|
4558
5637
|
*/
|
|
4559
|
-
|
|
4560
|
-
|
|
5638
|
+
initWithdrawBuffer({
|
|
5639
|
+
recipients,
|
|
5640
|
+
signingWallet = null
|
|
5641
|
+
}) {
|
|
5642
|
+
if (!this.sourceWallet) {
|
|
5643
|
+
throw new Error("Source wallet required for buffer withdrawal");
|
|
5644
|
+
}
|
|
5645
|
+
let amount = 0;
|
|
5646
|
+
for (const recipientAmount of Object.values(recipients || {})) {
|
|
5647
|
+
amount += recipientAmount;
|
|
5648
|
+
}
|
|
5649
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
5650
|
+
throw new BalanceInsufficientException();
|
|
5651
|
+
}
|
|
5652
|
+
const firstAtomMeta = new AtomMeta();
|
|
5653
|
+
if (signingWallet) {
|
|
5654
|
+
firstAtomMeta.setSigningWallet(signingWallet);
|
|
5655
|
+
}
|
|
5656
|
+
this.addAtom(Atom.create({
|
|
5657
|
+
isotope: "B",
|
|
5658
|
+
wallet: this.sourceWallet,
|
|
5659
|
+
value: -Number(this.sourceWallet.balance),
|
|
5660
|
+
meta: firstAtomMeta,
|
|
5661
|
+
metaType: "walletBundle",
|
|
5662
|
+
metaId: this.sourceWallet.bundle
|
|
5663
|
+
}));
|
|
5664
|
+
for (const [recipientBundle, recipientAmount] of Object.entries(recipients || {})) {
|
|
5665
|
+
this.addAtom(new Atom({
|
|
5666
|
+
isotope: "V",
|
|
5667
|
+
token: this.sourceWallet.token,
|
|
5668
|
+
value: recipientAmount,
|
|
5669
|
+
batchId: this.sourceWallet.batchId ? generateBatchId({}) : null,
|
|
5670
|
+
metaType: "walletBundle",
|
|
5671
|
+
metaId: recipientBundle
|
|
5672
|
+
}));
|
|
5673
|
+
}
|
|
5674
|
+
this.addAtom(Atom.create({
|
|
5675
|
+
isotope: "B",
|
|
5676
|
+
wallet: this.remainderWallet,
|
|
5677
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
5678
|
+
metaType: "walletBundle",
|
|
5679
|
+
metaId: this.remainderWallet.bundle
|
|
5680
|
+
}));
|
|
4561
5681
|
return this;
|
|
4562
5682
|
}
|
|
4563
5683
|
/**
|
|
4564
|
-
*
|
|
4565
|
-
*
|
|
5684
|
+
* Initialize shadow wallet claim
|
|
5685
|
+
* Matches JavaScript SDK Molecule.initShadowWalletClaim implementation exactly
|
|
5686
|
+
*
|
|
5687
|
+
* @param wallet - The shadow wallet to claim
|
|
5688
|
+
* @return This molecule instance for chaining
|
|
4566
5689
|
*/
|
|
4567
|
-
|
|
4568
|
-
|
|
5690
|
+
initShadowWalletClaim(wallet) {
|
|
5691
|
+
const atomMeta = new AtomMeta();
|
|
5692
|
+
atomMeta.setShadowWalletClaim(true);
|
|
5693
|
+
return this.initWalletCreation(wallet, atomMeta);
|
|
4569
5694
|
}
|
|
4570
5695
|
/**
|
|
4571
|
-
*
|
|
4572
|
-
*
|
|
5696
|
+
* Initialize identifier creation
|
|
5697
|
+
* Matches JavaScript SDK Molecule.initIdentifierCreation implementation exactly
|
|
5698
|
+
*
|
|
5699
|
+
* @param type - Identifier type (phone or email)
|
|
5700
|
+
* @param contact - Phone number or email string
|
|
5701
|
+
* @param code - Verification code
|
|
5702
|
+
* @return This molecule instance for chaining
|
|
4573
5703
|
*/
|
|
4574
|
-
|
|
4575
|
-
|
|
5704
|
+
initIdentifierCreation({
|
|
5705
|
+
type,
|
|
5706
|
+
contact,
|
|
5707
|
+
code
|
|
5708
|
+
}) {
|
|
5709
|
+
if (!this.sourceWallet) {
|
|
5710
|
+
throw new Error("Source wallet required for identifier creation");
|
|
5711
|
+
}
|
|
5712
|
+
const meta = {
|
|
5713
|
+
code,
|
|
5714
|
+
hash: generateBundleHash(contact.trim(), "Molecule::initIdentifierCreation")
|
|
5715
|
+
};
|
|
5716
|
+
this.addAtom(Atom.create({
|
|
5717
|
+
isotope: "C",
|
|
5718
|
+
wallet: this.sourceWallet,
|
|
5719
|
+
metaType: "identifier",
|
|
5720
|
+
metaId: type,
|
|
5721
|
+
meta: new AtomMeta(meta)
|
|
5722
|
+
}));
|
|
5723
|
+
this.addContinuIdAtom();
|
|
5724
|
+
return this;
|
|
4576
5725
|
}
|
|
4577
5726
|
};
|
|
4578
5727
|
|
|
4579
5728
|
// src/index.ts
|
|
4580
5729
|
init_Dot();
|
|
4581
5730
|
|
|
4582
|
-
// src/libraries/array.ts
|
|
4583
|
-
function deepCloning(o, h) {
|
|
4584
|
-
let i;
|
|
4585
|
-
let r;
|
|
4586
|
-
let x;
|
|
4587
|
-
const t = [Array, Date, Number, String, Boolean];
|
|
4588
|
-
const s = Object.prototype.toString;
|
|
4589
|
-
h = h || [];
|
|
4590
|
-
for (i = 0; i < h.length; i += 2) {
|
|
4591
|
-
if (o === h[i]) {
|
|
4592
|
-
return h[i + 1];
|
|
4593
|
-
}
|
|
4594
|
-
}
|
|
4595
|
-
if (!r && o && typeof o === "object") {
|
|
4596
|
-
r = {};
|
|
4597
|
-
for (i = 0; i < t.length; i++) {
|
|
4598
|
-
if (s.call(o) === s.call(x = new t[i](o))) {
|
|
4599
|
-
r = i ? x : [];
|
|
4600
|
-
}
|
|
4601
|
-
}
|
|
4602
|
-
h.push(o, r);
|
|
4603
|
-
for (i in o) {
|
|
4604
|
-
if (Object.prototype.hasOwnProperty.call(o, i)) {
|
|
4605
|
-
r[i] = deepCloning(o[i], h);
|
|
4606
|
-
}
|
|
4607
|
-
}
|
|
4608
|
-
}
|
|
4609
|
-
return r || o;
|
|
4610
|
-
}
|
|
4611
|
-
function chunkArray(arr, size) {
|
|
4612
|
-
if (!arr.length) {
|
|
4613
|
-
return [];
|
|
4614
|
-
}
|
|
4615
|
-
return [arr.slice(0, size)].concat(chunkArray(arr.slice(size), size));
|
|
4616
|
-
}
|
|
4617
|
-
function diff(...arrays) {
|
|
4618
|
-
return [].concat(...arrays.map((arr, i) => {
|
|
4619
|
-
const others = arrays.slice(0);
|
|
4620
|
-
others.splice(i, 1);
|
|
4621
|
-
const unique = [...new Set([].concat(...others))];
|
|
4622
|
-
return arr.filter((item) => !unique.includes(item));
|
|
4623
|
-
}));
|
|
4624
|
-
}
|
|
4625
|
-
function intersect(...arrays) {
|
|
4626
|
-
if (arrays.length === 0) return [];
|
|
4627
|
-
if (arrays.length === 1) return arrays[0];
|
|
4628
|
-
return arrays.reduce(
|
|
4629
|
-
(first, second) => first.filter((item) => second.includes(item))
|
|
4630
|
-
);
|
|
4631
|
-
}
|
|
4632
|
-
|
|
4633
5731
|
// src/libraries/Decimal.ts
|
|
4634
5732
|
var MULTIPLIER = 10 ** 18;
|
|
4635
5733
|
var Decimal = class _Decimal {
|
|
@@ -4841,6 +5939,129 @@ var GraphQLClient = class {
|
|
|
4841
5939
|
}
|
|
4842
5940
|
};
|
|
4843
5941
|
|
|
5942
|
+
// src/AuthToken.ts
|
|
5943
|
+
var AuthToken = class _AuthToken {
|
|
5944
|
+
$__token;
|
|
5945
|
+
$__expiresAt;
|
|
5946
|
+
$__pubkey;
|
|
5947
|
+
$__encrypt;
|
|
5948
|
+
$__wallet;
|
|
5949
|
+
/**
|
|
5950
|
+
* Create new AuthToken instance
|
|
5951
|
+
*/
|
|
5952
|
+
constructor({
|
|
5953
|
+
token,
|
|
5954
|
+
expiresAt,
|
|
5955
|
+
encrypt,
|
|
5956
|
+
pubkey
|
|
5957
|
+
}) {
|
|
5958
|
+
this.$__token = token;
|
|
5959
|
+
this.$__expiresAt = expiresAt;
|
|
5960
|
+
this.$__pubkey = pubkey;
|
|
5961
|
+
this.$__encrypt = encrypt;
|
|
5962
|
+
}
|
|
5963
|
+
/**
|
|
5964
|
+
* Static factory method to create AuthToken with wallet
|
|
5965
|
+
*/
|
|
5966
|
+
static create(data, wallet) {
|
|
5967
|
+
const authToken = new _AuthToken(data);
|
|
5968
|
+
authToken.setWallet(wallet);
|
|
5969
|
+
return authToken;
|
|
5970
|
+
}
|
|
5971
|
+
/**
|
|
5972
|
+
* Restore AuthToken from snapshot
|
|
5973
|
+
*/
|
|
5974
|
+
static restore(snapshot, secret) {
|
|
5975
|
+
const wallet = new Wallet({
|
|
5976
|
+
secret,
|
|
5977
|
+
token: "AUTH",
|
|
5978
|
+
position: snapshot.wallet.position,
|
|
5979
|
+
characters: snapshot.wallet.characters
|
|
5980
|
+
});
|
|
5981
|
+
return _AuthToken.create({
|
|
5982
|
+
token: snapshot.token,
|
|
5983
|
+
expiresAt: snapshot.expiresAt,
|
|
5984
|
+
pubkey: snapshot.pubkey,
|
|
5985
|
+
encrypt: snapshot.encrypt
|
|
5986
|
+
}, wallet);
|
|
5987
|
+
}
|
|
5988
|
+
/**
|
|
5989
|
+
* Set wallet for this auth token
|
|
5990
|
+
*/
|
|
5991
|
+
setWallet(wallet) {
|
|
5992
|
+
this.$__wallet = wallet;
|
|
5993
|
+
}
|
|
5994
|
+
/**
|
|
5995
|
+
* Get wallet
|
|
5996
|
+
*/
|
|
5997
|
+
getWallet() {
|
|
5998
|
+
return this.$__wallet;
|
|
5999
|
+
}
|
|
6000
|
+
/**
|
|
6001
|
+
* Get auth token
|
|
6002
|
+
*/
|
|
6003
|
+
getToken() {
|
|
6004
|
+
return this.$__token;
|
|
6005
|
+
}
|
|
6006
|
+
/**
|
|
6007
|
+
* Get expiration timestamp
|
|
6008
|
+
*/
|
|
6009
|
+
getExpiresAt() {
|
|
6010
|
+
return this.$__expiresAt;
|
|
6011
|
+
}
|
|
6012
|
+
/**
|
|
6013
|
+
* Get public key
|
|
6014
|
+
*/
|
|
6015
|
+
getPubkey() {
|
|
6016
|
+
return this.$__pubkey;
|
|
6017
|
+
}
|
|
6018
|
+
/**
|
|
6019
|
+
* Check if encryption is enabled
|
|
6020
|
+
*/
|
|
6021
|
+
isEncrypted() {
|
|
6022
|
+
return this.$__encrypt;
|
|
6023
|
+
}
|
|
6024
|
+
/**
|
|
6025
|
+
* Get expire interval in milliseconds (matching JS SDK pattern)
|
|
6026
|
+
*/
|
|
6027
|
+
getExpireInterval() {
|
|
6028
|
+
return this.$__expiresAt * 1e3 - Date.now();
|
|
6029
|
+
}
|
|
6030
|
+
/**
|
|
6031
|
+
* Check if token is expired
|
|
6032
|
+
*/
|
|
6033
|
+
isExpired() {
|
|
6034
|
+
return !this.$__expiresAt || this.getExpireInterval() < 0;
|
|
6035
|
+
}
|
|
6036
|
+
/**
|
|
6037
|
+
* Get auth data for GraphQL client
|
|
6038
|
+
*/
|
|
6039
|
+
getAuthData() {
|
|
6040
|
+
return {
|
|
6041
|
+
token: this.$__token,
|
|
6042
|
+
pubkey: this.$__pubkey,
|
|
6043
|
+
wallet: this.$__wallet
|
|
6044
|
+
};
|
|
6045
|
+
}
|
|
6046
|
+
/**
|
|
6047
|
+
* Create snapshot for persistence
|
|
6048
|
+
*/
|
|
6049
|
+
toSnapshot() {
|
|
6050
|
+
return {
|
|
6051
|
+
token: this.$__token,
|
|
6052
|
+
expiresAt: this.$__expiresAt,
|
|
6053
|
+
pubkey: this.$__pubkey,
|
|
6054
|
+
encrypt: this.$__encrypt,
|
|
6055
|
+
...this.$__wallet ? {
|
|
6056
|
+
wallet: {
|
|
6057
|
+
position: this.$__wallet.position,
|
|
6058
|
+
characters: this.$__wallet.characters
|
|
6059
|
+
}
|
|
6060
|
+
} : {}
|
|
6061
|
+
};
|
|
6062
|
+
}
|
|
6063
|
+
};
|
|
6064
|
+
|
|
4844
6065
|
// src/query/Query.ts
|
|
4845
6066
|
init_exception();
|
|
4846
6067
|
var Query = class {
|
|
@@ -5004,36 +6225,36 @@ var Mutation = class extends Query {
|
|
|
5004
6225
|
function createBrandedSchema(name, baseSchema = zod.z.string()) {
|
|
5005
6226
|
return baseSchema.brand(name);
|
|
5006
6227
|
}
|
|
5007
|
-
var
|
|
6228
|
+
var WalletAddressSchema2 = createBrandedSchema(
|
|
5008
6229
|
"WalletAddress",
|
|
5009
6230
|
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid wallet address format")
|
|
5010
6231
|
);
|
|
5011
|
-
var
|
|
6232
|
+
var BundleHashSchema2 = createBrandedSchema(
|
|
5012
6233
|
"BundleHash",
|
|
5013
6234
|
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid bundle hash format")
|
|
5014
6235
|
);
|
|
5015
|
-
var
|
|
6236
|
+
var PositionSchema2 = createBrandedSchema(
|
|
5016
6237
|
"Position",
|
|
5017
6238
|
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid position format")
|
|
5018
6239
|
);
|
|
5019
|
-
var
|
|
6240
|
+
var MolecularHashSchema2 = createBrandedSchema(
|
|
5020
6241
|
"MolecularHash",
|
|
5021
6242
|
zod.z.string().regex(/^[0-9a-g]+$/, "Invalid molecular hash format (base17)")
|
|
5022
6243
|
);
|
|
5023
|
-
var
|
|
6244
|
+
var TokenSlugSchema2 = createBrandedSchema(
|
|
5024
6245
|
"TokenSlug",
|
|
5025
6246
|
zod.z.string().min(1).max(32).regex(/^[A-Z0-9_]+$/, "Token slug must be uppercase alphanumeric")
|
|
5026
6247
|
);
|
|
5027
|
-
var
|
|
6248
|
+
var BatchIdSchema2 = createBrandedSchema(
|
|
5028
6249
|
"BatchId",
|
|
5029
6250
|
zod.z.string().uuid("Invalid batch ID format")
|
|
5030
6251
|
);
|
|
5031
|
-
var
|
|
6252
|
+
var CellSlugSchema2 = createBrandedSchema(
|
|
5032
6253
|
"CellSlug",
|
|
5033
6254
|
zod.z.string().min(1).max(64).regex(/^[a-zA-Z0-9\-_.]+$/, "Invalid cell slug format")
|
|
5034
6255
|
);
|
|
5035
6256
|
var ISOTOPES2 = ["C", "V", "U", "T", "M", "I", "R", "B", "F"];
|
|
5036
|
-
var
|
|
6257
|
+
var AtomIsotopeSchema2 = zod.z.enum(ISOTOPES2);
|
|
5037
6258
|
zod.z.object({
|
|
5038
6259
|
isotope: zod.z.literal("V"),
|
|
5039
6260
|
value: zod.z.union([zod.z.string(), zod.z.number()]).refine(
|
|
@@ -5053,17 +6274,17 @@ zod.z.object({
|
|
|
5053
6274
|
zod.z.object({
|
|
5054
6275
|
isotope: zod.z.literal("C")
|
|
5055
6276
|
}).strict();
|
|
5056
|
-
var
|
|
6277
|
+
var MetaDataSchema2 = zod.z.lazy(
|
|
5057
6278
|
() => zod.z.union([
|
|
5058
6279
|
zod.z.string(),
|
|
5059
6280
|
zod.z.number(),
|
|
5060
6281
|
zod.z.boolean(),
|
|
5061
6282
|
zod.z.null(),
|
|
5062
|
-
zod.z.record(zod.z.string(),
|
|
5063
|
-
zod.z.array(
|
|
6283
|
+
zod.z.record(zod.z.string(), MetaDataSchema2),
|
|
6284
|
+
zod.z.array(MetaDataSchema2)
|
|
5064
6285
|
])
|
|
5065
6286
|
);
|
|
5066
|
-
var
|
|
6287
|
+
var AtomMetaDataSchema2 = zod.z.object({
|
|
5067
6288
|
key: zod.z.string().min(1),
|
|
5068
6289
|
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()])
|
|
5069
6290
|
}).strict();
|
|
@@ -5071,44 +6292,44 @@ zod.z.object({
|
|
|
5071
6292
|
key: zod.z.string(),
|
|
5072
6293
|
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()])
|
|
5073
6294
|
}).passthrough();
|
|
5074
|
-
var
|
|
6295
|
+
var AtomParamsSchema2 = zod.z.object({
|
|
5075
6296
|
position: zod.z.string().optional(),
|
|
5076
|
-
walletAddress: zod.z.union([
|
|
5077
|
-
isotope:
|
|
5078
|
-
token: zod.z.union([
|
|
6297
|
+
walletAddress: zod.z.union([WalletAddressSchema2, zod.z.string()]).optional(),
|
|
6298
|
+
isotope: AtomIsotopeSchema2.default("C"),
|
|
6299
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).default("USER"),
|
|
5079
6300
|
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.null()]).optional(),
|
|
5080
|
-
batchId: zod.z.union([
|
|
6301
|
+
batchId: zod.z.union([BatchIdSchema2, zod.z.string(), zod.z.null()]).optional(),
|
|
5081
6302
|
metaType: zod.z.string().optional(),
|
|
5082
6303
|
metaId: zod.z.string().optional(),
|
|
5083
|
-
meta: zod.z.array(
|
|
6304
|
+
meta: zod.z.array(AtomMetaDataSchema2).optional(),
|
|
5084
6305
|
otsFragment: zod.z.string().optional(),
|
|
5085
6306
|
index: zod.z.number().int().min(0).optional(),
|
|
5086
6307
|
createdAt: zod.z.string().optional(),
|
|
5087
6308
|
version: zod.z.number().int().min(1).optional()
|
|
5088
6309
|
}).strict();
|
|
5089
|
-
var
|
|
6310
|
+
var WalletParamsSchema2 = zod.z.object({
|
|
5090
6311
|
secret: zod.z.string().optional(),
|
|
5091
|
-
bundle: zod.z.union([
|
|
5092
|
-
token: zod.z.union([
|
|
5093
|
-
address: zod.z.union([
|
|
5094
|
-
position: zod.z.union([
|
|
5095
|
-
batchId: zod.z.union([
|
|
6312
|
+
bundle: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6313
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).default("USER"),
|
|
6314
|
+
address: zod.z.union([WalletAddressSchema2, zod.z.string()]).optional(),
|
|
6315
|
+
position: zod.z.union([PositionSchema2, zod.z.string()]).optional(),
|
|
6316
|
+
batchId: zod.z.union([BatchIdSchema2, zod.z.string()]).optional(),
|
|
5096
6317
|
characters: zod.z.string().optional()
|
|
5097
6318
|
}).strict();
|
|
5098
|
-
var
|
|
6319
|
+
var MoleculeParamsSchema2 = zod.z.object({
|
|
5099
6320
|
secret: zod.z.string().optional(),
|
|
5100
|
-
bundle: zod.z.union([
|
|
5101
|
-
sourceWallet:
|
|
5102
|
-
remainderWallet:
|
|
5103
|
-
cellSlug: zod.z.union([
|
|
6321
|
+
bundle: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6322
|
+
sourceWallet: WalletParamsSchema2.optional(),
|
|
6323
|
+
remainderWallet: WalletParamsSchema2.optional(),
|
|
6324
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional(),
|
|
5104
6325
|
version: zod.z.number().int().min(1).optional()
|
|
5105
6326
|
}).strict();
|
|
5106
|
-
var
|
|
6327
|
+
var KnishIOClientConfigSchema2 = zod.z.object({
|
|
5107
6328
|
uri: zod.z.union([
|
|
5108
6329
|
zod.z.string().url("Invalid URI format"),
|
|
5109
6330
|
zod.z.array(zod.z.string().url("Invalid URI format")).min(1)
|
|
5110
6331
|
]).optional(),
|
|
5111
|
-
cellSlug: zod.z.union([
|
|
6332
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional(),
|
|
5112
6333
|
client: zod.z.unknown().optional(),
|
|
5113
6334
|
socket: zod.z.unknown().optional(),
|
|
5114
6335
|
serverSdkVersion: zod.z.number().int().min(1).max(10).default(4),
|
|
@@ -5121,48 +6342,48 @@ var EnvironmentConfigSchema = zod.z.object({
|
|
|
5121
6342
|
KNISHIO_LOGGING: zod.z.string().transform((val) => val === "true").default("false"),
|
|
5122
6343
|
KNISHIO_SERVER_SDK_VERSION: zod.z.string().transform((val) => parseInt(val, 10)).default("4")
|
|
5123
6344
|
}).partial();
|
|
5124
|
-
var
|
|
5125
|
-
recipient: zod.z.union([
|
|
6345
|
+
var TransferParamsSchema2 = zod.z.object({
|
|
6346
|
+
recipient: zod.z.union([WalletAddressSchema2, zod.z.string()]),
|
|
5126
6347
|
amount: zod.z.union([zod.z.number(), zod.z.string()]).refine(
|
|
5127
6348
|
(val) => Number(val) > 0,
|
|
5128
6349
|
"Amount must be positive"
|
|
5129
6350
|
),
|
|
5130
|
-
token: zod.z.union([
|
|
6351
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5131
6352
|
callbackUrl: zod.z.string().url().optional(),
|
|
5132
6353
|
metaType: zod.z.string().optional(),
|
|
5133
6354
|
metaId: zod.z.string().optional(),
|
|
5134
|
-
meta:
|
|
6355
|
+
meta: MetaDataSchema2.optional()
|
|
5135
6356
|
}).strict();
|
|
5136
|
-
var
|
|
5137
|
-
token: zod.z.union([
|
|
6357
|
+
var CreateTokenParamsSchema2 = zod.z.object({
|
|
6358
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]),
|
|
5138
6359
|
amount: zod.z.union([zod.z.number(), zod.z.string()]).refine(
|
|
5139
6360
|
(val) => Number(val) > 0,
|
|
5140
6361
|
"Amount must be positive"
|
|
5141
6362
|
),
|
|
5142
6363
|
metaType: zod.z.string().optional(),
|
|
5143
6364
|
metaId: zod.z.string().optional(),
|
|
5144
|
-
meta:
|
|
6365
|
+
meta: MetaDataSchema2.optional(),
|
|
5145
6366
|
fungible: zod.z.boolean().default(true),
|
|
5146
6367
|
splittable: zod.z.number().int().min(0).optional(),
|
|
5147
|
-
supplyToken: zod.z.union([
|
|
6368
|
+
supplyToken: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional()
|
|
5148
6369
|
}).strict();
|
|
5149
|
-
var
|
|
6370
|
+
var RequestTokensParamsSchema2 = zod.z.object({
|
|
5150
6371
|
amount: zod.z.union([zod.z.number(), zod.z.string()]).refine(
|
|
5151
6372
|
(val) => Number(val) > 0,
|
|
5152
6373
|
"Amount must be positive"
|
|
5153
6374
|
),
|
|
5154
|
-
token: zod.z.union([
|
|
6375
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5155
6376
|
metaType: zod.z.string().optional(),
|
|
5156
6377
|
metaId: zod.z.string().optional(),
|
|
5157
|
-
meta:
|
|
6378
|
+
meta: MetaDataSchema2.optional()
|
|
5158
6379
|
}).strict();
|
|
5159
|
-
var
|
|
5160
|
-
address: zod.z.union([
|
|
5161
|
-
bundleHash: zod.z.union([
|
|
5162
|
-
token: zod.z.union([
|
|
6380
|
+
var BalanceQueryParamsSchema2 = zod.z.object({
|
|
6381
|
+
address: zod.z.union([WalletAddressSchema2, zod.z.string()]).optional(),
|
|
6382
|
+
bundleHash: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6383
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5163
6384
|
type: zod.z.enum(["token", "user"]).optional()
|
|
5164
6385
|
}).strict();
|
|
5165
|
-
var
|
|
6386
|
+
var MetaQueryParamsSchema2 = zod.z.object({
|
|
5166
6387
|
metaType: zod.z.string().min(1),
|
|
5167
6388
|
metaId: zod.z.string().optional(),
|
|
5168
6389
|
key: zod.z.string().optional(),
|
|
@@ -5172,33 +6393,33 @@ var MetaQueryParamsSchema = zod.z.object({
|
|
|
5172
6393
|
queryArgs: zod.z.record(zod.z.unknown()).optional(),
|
|
5173
6394
|
count: zod.z.number().int().min(0).optional(),
|
|
5174
6395
|
countBy: zod.z.string().optional(),
|
|
5175
|
-
cellSlug: zod.z.union([
|
|
6396
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional()
|
|
5176
6397
|
}).strict();
|
|
5177
|
-
var
|
|
5178
|
-
bundleHash: zod.z.union([
|
|
5179
|
-
tokenSlug: zod.z.union([
|
|
6398
|
+
var WalletQueryParamsSchema2 = zod.z.object({
|
|
6399
|
+
bundleHash: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6400
|
+
tokenSlug: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5180
6401
|
unspent: zod.z.boolean().optional()
|
|
5181
6402
|
}).strict();
|
|
5182
|
-
var
|
|
6403
|
+
var AuthTokenParamsSchema2 = zod.z.object({
|
|
5183
6404
|
token: zod.z.string().min(1),
|
|
5184
6405
|
expiresAt: zod.z.number().int().min(0),
|
|
5185
6406
|
encrypt: zod.z.boolean(),
|
|
5186
6407
|
pubkey: zod.z.string().min(1)
|
|
5187
6408
|
}).strict();
|
|
5188
|
-
var
|
|
5189
|
-
cellSlug: zod.z.union([
|
|
6409
|
+
var AuthParamsSchema2 = zod.z.object({
|
|
6410
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional(),
|
|
5190
6411
|
encrypt: zod.z.boolean().optional(),
|
|
5191
6412
|
callback: zod.z.function().optional()
|
|
5192
6413
|
}).strict();
|
|
5193
|
-
var
|
|
5194
|
-
cellSlug: zod.z.union([
|
|
6414
|
+
var GuestAuthParamsSchema2 = zod.z.object({
|
|
6415
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional()
|
|
5195
6416
|
}).strict();
|
|
5196
|
-
var
|
|
6417
|
+
var GraphQLRequestSchema2 = zod.z.object({
|
|
5197
6418
|
query: zod.z.string().min(1),
|
|
5198
6419
|
variables: zod.z.record(zod.z.unknown()).optional(),
|
|
5199
6420
|
operationName: zod.z.string().optional()
|
|
5200
6421
|
}).strict();
|
|
5201
|
-
var
|
|
6422
|
+
var GraphQLErrorSchema2 = zod.z.object({
|
|
5202
6423
|
message: zod.z.string(),
|
|
5203
6424
|
locations: zod.z.array(zod.z.object({
|
|
5204
6425
|
line: zod.z.number().int(),
|
|
@@ -5207,9 +6428,9 @@ var GraphQLErrorSchema = zod.z.object({
|
|
|
5207
6428
|
path: zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).optional(),
|
|
5208
6429
|
extensions: zod.z.record(zod.z.unknown()).optional()
|
|
5209
6430
|
}).strict();
|
|
5210
|
-
var
|
|
6431
|
+
var GraphQLResponseSchema2 = zod.z.object({
|
|
5211
6432
|
data: zod.z.unknown().optional(),
|
|
5212
|
-
errors: zod.z.array(
|
|
6433
|
+
errors: zod.z.array(GraphQLErrorSchema2).optional(),
|
|
5213
6434
|
extensions: zod.z.record(zod.z.unknown()).optional()
|
|
5214
6435
|
}).strict();
|
|
5215
6436
|
function safeParse(schema, data) {
|
|
@@ -5236,35 +6457,35 @@ function createTypeGuard(schema) {
|
|
|
5236
6457
|
}
|
|
5237
6458
|
var Schemas = {
|
|
5238
6459
|
// Core types
|
|
5239
|
-
WalletAddress:
|
|
5240
|
-
BundleHash:
|
|
5241
|
-
Position:
|
|
5242
|
-
MolecularHash:
|
|
5243
|
-
TokenSlug:
|
|
5244
|
-
BatchId:
|
|
5245
|
-
CellSlug:
|
|
6460
|
+
WalletAddress: WalletAddressSchema2,
|
|
6461
|
+
BundleHash: BundleHashSchema2,
|
|
6462
|
+
Position: PositionSchema2,
|
|
6463
|
+
MolecularHash: MolecularHashSchema2,
|
|
6464
|
+
TokenSlug: TokenSlugSchema2,
|
|
6465
|
+
BatchId: BatchIdSchema2,
|
|
6466
|
+
CellSlug: CellSlugSchema2,
|
|
5246
6467
|
// Entities
|
|
5247
|
-
AtomParams:
|
|
5248
|
-
WalletParams:
|
|
5249
|
-
MoleculeParams:
|
|
6468
|
+
AtomParams: AtomParamsSchema2,
|
|
6469
|
+
WalletParams: WalletParamsSchema2,
|
|
6470
|
+
MoleculeParams: MoleculeParamsSchema2,
|
|
5250
6471
|
// Configuration
|
|
5251
|
-
ClientConfig:
|
|
6472
|
+
ClientConfig: KnishIOClientConfigSchema2,
|
|
5252
6473
|
EnvironmentConfig: EnvironmentConfigSchema,
|
|
5253
6474
|
// Operations
|
|
5254
|
-
TransferParams:
|
|
5255
|
-
CreateTokenParams:
|
|
5256
|
-
RequestTokensParams:
|
|
6475
|
+
TransferParams: TransferParamsSchema2,
|
|
6476
|
+
CreateTokenParams: CreateTokenParamsSchema2,
|
|
6477
|
+
RequestTokensParams: RequestTokensParamsSchema2,
|
|
5257
6478
|
// Queries
|
|
5258
|
-
BalanceQueryParams:
|
|
5259
|
-
MetaQueryParams:
|
|
5260
|
-
WalletQueryParams:
|
|
6479
|
+
BalanceQueryParams: BalanceQueryParamsSchema2,
|
|
6480
|
+
MetaQueryParams: MetaQueryParamsSchema2,
|
|
6481
|
+
WalletQueryParams: WalletQueryParamsSchema2,
|
|
5261
6482
|
// Auth
|
|
5262
|
-
AuthTokenParams:
|
|
5263
|
-
AuthParams:
|
|
5264
|
-
GuestAuthParams:
|
|
6483
|
+
AuthTokenParams: AuthTokenParamsSchema2,
|
|
6484
|
+
AuthParams: AuthParamsSchema2,
|
|
6485
|
+
GuestAuthParams: GuestAuthParamsSchema2,
|
|
5265
6486
|
// GraphQL
|
|
5266
|
-
GraphQLRequest:
|
|
5267
|
-
GraphQLResponse:
|
|
6487
|
+
GraphQLRequest: GraphQLRequestSchema2,
|
|
6488
|
+
GraphQLResponse: GraphQLResponseSchema2
|
|
5268
6489
|
};
|
|
5269
6490
|
|
|
5270
6491
|
// src/validation/ValidationService.ts
|
|
@@ -5943,7 +7164,8 @@ var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
|
5943
7164
|
* Matches JavaScript SDK payload() method exactly
|
|
5944
7165
|
*/
|
|
5945
7166
|
payload() {
|
|
5946
|
-
const
|
|
7167
|
+
const balanceData = this.data();
|
|
7168
|
+
const walletData = Array.isArray(balanceData) ? balanceData[0] : balanceData;
|
|
5947
7169
|
if (!walletData || !walletData.bundleHash || !walletData.tokenSlug) {
|
|
5948
7170
|
return null;
|
|
5949
7171
|
}
|
|
@@ -5961,7 +7183,7 @@ var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
|
5961
7183
|
secret = null
|
|
5962
7184
|
}) {
|
|
5963
7185
|
let wallet;
|
|
5964
|
-
if (data.position
|
|
7186
|
+
if (!data.position) {
|
|
5965
7187
|
wallet = Wallet.create({
|
|
5966
7188
|
bundle: data.bundleHash,
|
|
5967
7189
|
token: data.tokenSlug,
|
|
@@ -5990,7 +7212,7 @@ var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
|
5990
7212
|
wallet.tradeRates[tradeRate.tokenSlug] = tradeRate.amount;
|
|
5991
7213
|
}
|
|
5992
7214
|
}
|
|
5993
|
-
wallet.balance =
|
|
7215
|
+
wallet.balance = String(data.amount != null ? data.amount : 0);
|
|
5994
7216
|
wallet.pubkey = data.pubkey;
|
|
5995
7217
|
wallet.createdAt = data.createdAt;
|
|
5996
7218
|
return wallet;
|
|
@@ -6183,7 +7405,7 @@ var ResponseWalletList = class _ResponseWalletList extends exports.Response {
|
|
|
6183
7405
|
wallet.tradeRates[tradeRate.tokenSlug] = tradeRate.amount;
|
|
6184
7406
|
}
|
|
6185
7407
|
}
|
|
6186
|
-
wallet.balance =
|
|
7408
|
+
wallet.balance = String(data.amount != null ? data.amount : 0);
|
|
6187
7409
|
wallet.pubkey = data.pubkey;
|
|
6188
7410
|
wallet.createdAt = data.createdAt;
|
|
6189
7411
|
return wallet;
|
|
@@ -6221,8 +7443,8 @@ var QueryWalletList = class extends Query {
|
|
|
6221
7443
|
*/
|
|
6222
7444
|
constructor(graphQLClient, knishIOClient) {
|
|
6223
7445
|
super(graphQLClient, knishIOClient);
|
|
6224
|
-
this.$__query = core.gql`query( $bundleHash: String, $
|
|
6225
|
-
Wallet( bundleHash: $bundleHash,
|
|
7446
|
+
this.$__query = core.gql`query( $bundleHash: String, $token: String ) {
|
|
7447
|
+
Wallet( bundleHash: $bundleHash, token: $token ) {
|
|
6226
7448
|
address,
|
|
6227
7449
|
bundleHash,
|
|
6228
7450
|
token {
|
|
@@ -6364,7 +7586,7 @@ var ResponseContinuId = class extends exports.Response {
|
|
|
6364
7586
|
wallet.batchId = continuId.batchId;
|
|
6365
7587
|
wallet.characters = continuId.characters;
|
|
6366
7588
|
wallet.pubkey = continuId.pubkey;
|
|
6367
|
-
wallet.balance = continuId.amount
|
|
7589
|
+
wallet.balance = String(continuId.amount != null ? continuId.amount : 0);
|
|
6368
7590
|
}
|
|
6369
7591
|
return wallet;
|
|
6370
7592
|
}
|
|
@@ -6390,6 +7612,13 @@ var QueryContinuId = class extends Query {
|
|
|
6390
7612
|
}
|
|
6391
7613
|
}`;
|
|
6392
7614
|
}
|
|
7615
|
+
/**
|
|
7616
|
+
* Force network-only for ContinuID queries to prevent URQL cache from
|
|
7617
|
+
* returning stale wallet positions after mutations advance the ContinuID chain
|
|
7618
|
+
*/
|
|
7619
|
+
createQueryContext() {
|
|
7620
|
+
return { requestPolicy: "network-only" };
|
|
7621
|
+
}
|
|
6393
7622
|
/**
|
|
6394
7623
|
* Returns a Response object
|
|
6395
7624
|
* Matches JavaScript SDK createResponse method exactly
|
|
@@ -6419,31 +7648,40 @@ var ResponseMetaType = class extends exports.Response {
|
|
|
6419
7648
|
dataKey: "data.MetaType"
|
|
6420
7649
|
});
|
|
6421
7650
|
}
|
|
7651
|
+
/**
|
|
7652
|
+
* Extracts payload from metaData object
|
|
7653
|
+
*/
|
|
7654
|
+
extractPayload(metaData) {
|
|
7655
|
+
return {
|
|
7656
|
+
instances: metaData?.instances || [],
|
|
7657
|
+
instanceCount: metaData?.instanceCount || [],
|
|
7658
|
+
paginatorInfo: metaData?.paginatorInfo || {}
|
|
7659
|
+
};
|
|
7660
|
+
}
|
|
6422
7661
|
/**
|
|
6423
7662
|
* Returns meta type instance results
|
|
6424
|
-
*
|
|
7663
|
+
* Handles various response formats from server:
|
|
7664
|
+
* - Array of results (normal case)
|
|
7665
|
+
* - Single object (filtered queries)
|
|
7666
|
+
* - null/undefined (no results)
|
|
7667
|
+
* - Empty array (no matching data)
|
|
6425
7668
|
*/
|
|
6426
7669
|
payload() {
|
|
6427
7670
|
const metaTypeData = this.data();
|
|
6428
|
-
if (
|
|
7671
|
+
if (metaTypeData === null || metaTypeData === void 0) {
|
|
6429
7672
|
return null;
|
|
6430
7673
|
}
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
if (metaData.instances) {
|
|
6438
|
-
response.instances = metaData.instances;
|
|
6439
|
-
}
|
|
6440
|
-
if (metaData.instanceCount) {
|
|
6441
|
-
response.instanceCount = metaData.instanceCount;
|
|
7674
|
+
if (Array.isArray(metaTypeData)) {
|
|
7675
|
+
if (metaTypeData.length === 0) {
|
|
7676
|
+
return this.extractPayload(null);
|
|
7677
|
+
}
|
|
7678
|
+
const metaData = metaTypeData[metaTypeData.length - 1];
|
|
7679
|
+
return this.extractPayload(metaData);
|
|
6442
7680
|
}
|
|
6443
|
-
if (
|
|
6444
|
-
|
|
7681
|
+
if (typeof metaTypeData === "object") {
|
|
7682
|
+
return this.extractPayload(metaTypeData);
|
|
6445
7683
|
}
|
|
6446
|
-
return
|
|
7684
|
+
return null;
|
|
6447
7685
|
}
|
|
6448
7686
|
};
|
|
6449
7687
|
var QueryMetaType = class extends Query {
|
|
@@ -6911,10 +8149,9 @@ var ResponsePolicy = class extends exports.Response {
|
|
|
6911
8149
|
}) {
|
|
6912
8150
|
super({
|
|
6913
8151
|
query,
|
|
6914
|
-
json
|
|
8152
|
+
json,
|
|
8153
|
+
dataKey: "data.Policy"
|
|
6915
8154
|
});
|
|
6916
|
-
this.dataKey = "data.Policy";
|
|
6917
|
-
this.init();
|
|
6918
8155
|
}
|
|
6919
8156
|
/**
|
|
6920
8157
|
* Returns the policy payload
|
|
@@ -7017,7 +8254,6 @@ var QueryActiveSession = class extends Query {
|
|
|
7017
8254
|
metaId
|
|
7018
8255
|
jsonData
|
|
7019
8256
|
createdAt
|
|
7020
|
-
updatedAt
|
|
7021
8257
|
}
|
|
7022
8258
|
}
|
|
7023
8259
|
`;
|
|
@@ -7350,6 +8586,252 @@ var QueryMetaTypeViaAtom = class extends Query {
|
|
|
7350
8586
|
}
|
|
7351
8587
|
};
|
|
7352
8588
|
|
|
8589
|
+
// src/response/ResponseMetaTypeViaMolecule.ts
|
|
8590
|
+
init_Response();
|
|
8591
|
+
var ResponseMetaTypeViaMolecule = class _ResponseMetaTypeViaMolecule extends exports.Response {
|
|
8592
|
+
/**
|
|
8593
|
+
* Class constructor
|
|
8594
|
+
*/
|
|
8595
|
+
constructor({
|
|
8596
|
+
query,
|
|
8597
|
+
json
|
|
8598
|
+
}) {
|
|
8599
|
+
super({
|
|
8600
|
+
query,
|
|
8601
|
+
json,
|
|
8602
|
+
dataKey: "data.MetaTypeViaAtom"
|
|
8603
|
+
});
|
|
8604
|
+
}
|
|
8605
|
+
/**
|
|
8606
|
+
* Extracts metas from a molecule's atoms' metasJson for a specific instance.
|
|
8607
|
+
* Filters atoms by matching metaType and metaId, then parses metasJson.
|
|
8608
|
+
*/
|
|
8609
|
+
static extractMetasFromMolecule(molecule, metaType, metaId) {
|
|
8610
|
+
if (!molecule || !molecule.atoms) {
|
|
8611
|
+
return [];
|
|
8612
|
+
}
|
|
8613
|
+
const metas = [];
|
|
8614
|
+
for (const atom of molecule.atoms) {
|
|
8615
|
+
if (atom.metaType !== metaType || atom.metaId !== metaId) {
|
|
8616
|
+
continue;
|
|
8617
|
+
}
|
|
8618
|
+
if (!atom.metasJson) {
|
|
8619
|
+
continue;
|
|
8620
|
+
}
|
|
8621
|
+
let parsed;
|
|
8622
|
+
try {
|
|
8623
|
+
parsed = JSON.parse(atom.metasJson);
|
|
8624
|
+
if (!Array.isArray(parsed)) {
|
|
8625
|
+
continue;
|
|
8626
|
+
}
|
|
8627
|
+
} catch (e) {
|
|
8628
|
+
continue;
|
|
8629
|
+
}
|
|
8630
|
+
for (const entry of parsed) {
|
|
8631
|
+
metas.push({
|
|
8632
|
+
molecularHash: molecule.molecularHash,
|
|
8633
|
+
position: atom.position,
|
|
8634
|
+
key: entry.key,
|
|
8635
|
+
value: entry.value,
|
|
8636
|
+
createdAt: atom.createdAt
|
|
8637
|
+
});
|
|
8638
|
+
}
|
|
8639
|
+
}
|
|
8640
|
+
return metas;
|
|
8641
|
+
}
|
|
8642
|
+
/**
|
|
8643
|
+
* Returns meta type instance results with metas synthesized from molecule data.
|
|
8644
|
+
* Produces the same payload format as ResponseMetaType and ResponseMetaTypeViaAtom:
|
|
8645
|
+
* { instances, instanceCount, paginatorInfo }
|
|
8646
|
+
*/
|
|
8647
|
+
payload() {
|
|
8648
|
+
const metaTypeData = this.data();
|
|
8649
|
+
if (!metaTypeData || metaTypeData.length === 0) {
|
|
8650
|
+
return null;
|
|
8651
|
+
}
|
|
8652
|
+
const response = {
|
|
8653
|
+
instances: {},
|
|
8654
|
+
instanceCount: {},
|
|
8655
|
+
paginatorInfo: {}
|
|
8656
|
+
};
|
|
8657
|
+
const metaData = metaTypeData.pop();
|
|
8658
|
+
if (metaData.instances) {
|
|
8659
|
+
response.instances = metaData.instances.map((instance) => {
|
|
8660
|
+
let metas = instance.metas;
|
|
8661
|
+
if (!metas || metas.length === 0) {
|
|
8662
|
+
metas = _ResponseMetaTypeViaMolecule.extractMetasFromMolecule(
|
|
8663
|
+
instance.molecule,
|
|
8664
|
+
instance.metaType,
|
|
8665
|
+
instance.metaId
|
|
8666
|
+
);
|
|
8667
|
+
}
|
|
8668
|
+
return {
|
|
8669
|
+
...instance,
|
|
8670
|
+
metas
|
|
8671
|
+
};
|
|
8672
|
+
});
|
|
8673
|
+
}
|
|
8674
|
+
if (metaData.instanceCount) {
|
|
8675
|
+
response.instanceCount = metaData.instanceCount;
|
|
8676
|
+
}
|
|
8677
|
+
if (metaData.paginatorInfo) {
|
|
8678
|
+
response.paginatorInfo = metaData.paginatorInfo;
|
|
8679
|
+
}
|
|
8680
|
+
return response;
|
|
8681
|
+
}
|
|
8682
|
+
/**
|
|
8683
|
+
* Verifies the cryptographic integrity of all molecules associated
|
|
8684
|
+
* with meta instances in this response.
|
|
8685
|
+
*/
|
|
8686
|
+
verifyIntegrity() {
|
|
8687
|
+
const results = [];
|
|
8688
|
+
const metaTypeData = this.data();
|
|
8689
|
+
if (!metaTypeData || metaTypeData.length === 0) {
|
|
8690
|
+
return { verified: true, molecules: results };
|
|
8691
|
+
}
|
|
8692
|
+
const instances = metaTypeData[metaTypeData.length - 1]?.instances || [];
|
|
8693
|
+
for (const instance of instances) {
|
|
8694
|
+
if (!instance.molecule) continue;
|
|
8695
|
+
results.push(CheckMolecule.verifyFromServerData(instance.molecule));
|
|
8696
|
+
}
|
|
8697
|
+
return {
|
|
8698
|
+
verified: results.length === 0 || results.every((r) => r.verified),
|
|
8699
|
+
molecules: results
|
|
8700
|
+
};
|
|
8701
|
+
}
|
|
8702
|
+
};
|
|
8703
|
+
var QueryMetaTypeViaMolecule = class extends Query {
|
|
8704
|
+
/**
|
|
8705
|
+
* Create new QueryMetaTypeViaMolecule instance
|
|
8706
|
+
*/
|
|
8707
|
+
constructor(graphQLClient, knishIOClient) {
|
|
8708
|
+
super(graphQLClient, knishIOClient);
|
|
8709
|
+
this.$__query = core.gql`query ($metaTypes: [String!], $metaIds: [String!], $values: [String!], $keys: [String!], $latest: Boolean, $filter: [MetaFilter!], $queryArgs: QueryArgs, $countBy: String, $atomValues: [String!], $cellSlugs: [String!] ) {
|
|
8710
|
+
MetaTypeViaAtom(
|
|
8711
|
+
metaTypes: $metaTypes
|
|
8712
|
+
metaIds: $metaIds
|
|
8713
|
+
atomValues: $atomValues
|
|
8714
|
+
cellSlugs: $cellSlugs
|
|
8715
|
+
filter: $filter,
|
|
8716
|
+
latest: $latest,
|
|
8717
|
+
queryArgs: $queryArgs
|
|
8718
|
+
countBy: $countBy
|
|
8719
|
+
) {
|
|
8720
|
+
metaType,
|
|
8721
|
+
instanceCount {
|
|
8722
|
+
key,
|
|
8723
|
+
value
|
|
8724
|
+
},
|
|
8725
|
+
instances {
|
|
8726
|
+
metaType,
|
|
8727
|
+
metaId,
|
|
8728
|
+
createdAt,
|
|
8729
|
+
metas( values: $values, keys: $keys ) {
|
|
8730
|
+
molecularHash,
|
|
8731
|
+
position,
|
|
8732
|
+
key,
|
|
8733
|
+
value,
|
|
8734
|
+
createdAt
|
|
8735
|
+
},
|
|
8736
|
+
molecule {
|
|
8737
|
+
molecularHash,
|
|
8738
|
+
bundleHash,
|
|
8739
|
+
cellSlug,
|
|
8740
|
+
status,
|
|
8741
|
+
createdAt,
|
|
8742
|
+
atoms {
|
|
8743
|
+
position,
|
|
8744
|
+
walletAddress,
|
|
8745
|
+
isotope,
|
|
8746
|
+
tokenSlug,
|
|
8747
|
+
value,
|
|
8748
|
+
batchId,
|
|
8749
|
+
metaType,
|
|
8750
|
+
metaId,
|
|
8751
|
+
index,
|
|
8752
|
+
createdAt,
|
|
8753
|
+
otsFragment,
|
|
8754
|
+
metasJson
|
|
8755
|
+
}
|
|
8756
|
+
}
|
|
8757
|
+
},
|
|
8758
|
+
paginatorInfo {
|
|
8759
|
+
currentPage,
|
|
8760
|
+
total
|
|
8761
|
+
}
|
|
8762
|
+
}
|
|
8763
|
+
}`;
|
|
8764
|
+
}
|
|
8765
|
+
/**
|
|
8766
|
+
* Builds a GraphQL-friendly variables object based on input fields
|
|
8767
|
+
*/
|
|
8768
|
+
static createVariables({
|
|
8769
|
+
metaType = null,
|
|
8770
|
+
metaId = null,
|
|
8771
|
+
key = null,
|
|
8772
|
+
value = null,
|
|
8773
|
+
keys = null,
|
|
8774
|
+
values = null,
|
|
8775
|
+
atomValues = null,
|
|
8776
|
+
latest = null,
|
|
8777
|
+
filter = null,
|
|
8778
|
+
queryArgs = null,
|
|
8779
|
+
countBy = null,
|
|
8780
|
+
cellSlug = null
|
|
8781
|
+
} = {}) {
|
|
8782
|
+
const variables = {};
|
|
8783
|
+
if (atomValues) {
|
|
8784
|
+
variables.atomValues = atomValues;
|
|
8785
|
+
}
|
|
8786
|
+
if (keys) {
|
|
8787
|
+
variables.keys = keys;
|
|
8788
|
+
}
|
|
8789
|
+
if (values) {
|
|
8790
|
+
variables.values = values;
|
|
8791
|
+
}
|
|
8792
|
+
if (metaType) {
|
|
8793
|
+
variables.metaTypes = typeof metaType === "string" ? [metaType] : metaType;
|
|
8794
|
+
}
|
|
8795
|
+
if (metaId) {
|
|
8796
|
+
variables.metaIds = typeof metaId === "string" ? [metaId] : metaId;
|
|
8797
|
+
}
|
|
8798
|
+
if (cellSlug) {
|
|
8799
|
+
variables.cellSlugs = typeof cellSlug === "string" ? [cellSlug] : cellSlug;
|
|
8800
|
+
}
|
|
8801
|
+
if (countBy) {
|
|
8802
|
+
variables.countBy = countBy;
|
|
8803
|
+
}
|
|
8804
|
+
if (filter) {
|
|
8805
|
+
variables.filter = filter;
|
|
8806
|
+
}
|
|
8807
|
+
if (key && value) {
|
|
8808
|
+
variables.filter = variables.filter || [];
|
|
8809
|
+
variables.filter.push({
|
|
8810
|
+
key,
|
|
8811
|
+
value,
|
|
8812
|
+
comparison: "="
|
|
8813
|
+
});
|
|
8814
|
+
}
|
|
8815
|
+
variables.latest = latest === true;
|
|
8816
|
+
if (queryArgs) {
|
|
8817
|
+
if (typeof queryArgs.limit === "undefined" || queryArgs.limit === 0) {
|
|
8818
|
+
queryArgs.limit = "*";
|
|
8819
|
+
}
|
|
8820
|
+
variables.queryArgs = queryArgs;
|
|
8821
|
+
}
|
|
8822
|
+
return variables;
|
|
8823
|
+
}
|
|
8824
|
+
/**
|
|
8825
|
+
* Returns a Response object
|
|
8826
|
+
*/
|
|
8827
|
+
createResponse(json) {
|
|
8828
|
+
return new ResponseMetaTypeViaMolecule({
|
|
8829
|
+
query: this,
|
|
8830
|
+
json
|
|
8831
|
+
});
|
|
8832
|
+
}
|
|
8833
|
+
};
|
|
8834
|
+
|
|
7353
8835
|
// src/response/ResponseProposeMolecule.ts
|
|
7354
8836
|
init_Response();
|
|
7355
8837
|
init_Dot();
|
|
@@ -7368,7 +8850,6 @@ var ResponseProposeMolecule = class extends exports.Response {
|
|
|
7368
8850
|
dataKey: "data.ProposeMolecule"
|
|
7369
8851
|
});
|
|
7370
8852
|
this.$__clientMolecule = query.molecule();
|
|
7371
|
-
this.init();
|
|
7372
8853
|
}
|
|
7373
8854
|
/**
|
|
7374
8855
|
* Initialize response object with payload data
|
|
@@ -7932,12 +9413,31 @@ var ResponseRequestAuthorization = class extends ResponseProposeMolecule {
|
|
|
7932
9413
|
return this.payloadKey("token");
|
|
7933
9414
|
}
|
|
7934
9415
|
/**
|
|
7935
|
-
* Returns
|
|
7936
|
-
* Matches JavaScript SDK time method exactly
|
|
9416
|
+
* Returns raw time value from payload
|
|
7937
9417
|
*/
|
|
7938
9418
|
time() {
|
|
7939
9419
|
return this.payloadKey("time");
|
|
7940
9420
|
}
|
|
9421
|
+
/**
|
|
9422
|
+
* Returns the expiration timestamp as Unix seconds.
|
|
9423
|
+
* Handles both server formats:
|
|
9424
|
+
* - PHP server: time = lifetime in ms, expiresAt = Unix timestamp in payload
|
|
9425
|
+
* - Rust server: time = Unix timestamp in seconds
|
|
9426
|
+
*/
|
|
9427
|
+
expiresAt() {
|
|
9428
|
+
try {
|
|
9429
|
+
const ea = this.payloadKey("expiresAt");
|
|
9430
|
+
if (ea) {
|
|
9431
|
+
return Number(ea);
|
|
9432
|
+
}
|
|
9433
|
+
} catch (_e) {
|
|
9434
|
+
}
|
|
9435
|
+
const timeValue = Number(this.time());
|
|
9436
|
+
if (timeValue >= 1577836800) {
|
|
9437
|
+
return timeValue;
|
|
9438
|
+
}
|
|
9439
|
+
return Math.floor(Date.now() / 1e3) + Math.floor(timeValue / 1e3);
|
|
9440
|
+
}
|
|
7941
9441
|
/**
|
|
7942
9442
|
* Returns encryption info
|
|
7943
9443
|
* Matches JavaScript SDK encrypt method exactly
|
|
@@ -8029,11 +9529,31 @@ var ResponseRequestAuthorizationGuest = class extends exports.Response {
|
|
|
8029
9529
|
return this.payloadKey("token");
|
|
8030
9530
|
}
|
|
8031
9531
|
/**
|
|
8032
|
-
* Returns
|
|
9532
|
+
* Returns raw time value from payload
|
|
8033
9533
|
*/
|
|
8034
9534
|
time() {
|
|
8035
9535
|
return this.payloadKey("time");
|
|
8036
9536
|
}
|
|
9537
|
+
/**
|
|
9538
|
+
* Returns the expiration timestamp as Unix seconds.
|
|
9539
|
+
* Handles both server formats:
|
|
9540
|
+
* - PHP server: time = lifetime in ms, expiresAt = Unix timestamp in payload
|
|
9541
|
+
* - Rust server: time = Unix timestamp in seconds
|
|
9542
|
+
*/
|
|
9543
|
+
expiresAt() {
|
|
9544
|
+
try {
|
|
9545
|
+
const ea = this.payloadKey("expiresAt");
|
|
9546
|
+
if (ea) {
|
|
9547
|
+
return Number(ea);
|
|
9548
|
+
}
|
|
9549
|
+
} catch (_e) {
|
|
9550
|
+
}
|
|
9551
|
+
const timeValue = Number(this.time());
|
|
9552
|
+
if (timeValue >= 1577836800) {
|
|
9553
|
+
return timeValue;
|
|
9554
|
+
}
|
|
9555
|
+
return Math.floor(Date.now() / 1e3) + Math.floor(timeValue / 1e3);
|
|
9556
|
+
}
|
|
8037
9557
|
/**
|
|
8038
9558
|
* Returns public key
|
|
8039
9559
|
*/
|
|
@@ -8123,10 +9643,74 @@ var MutationLinkIdentifier = class extends Mutation {
|
|
|
8123
9643
|
`;
|
|
8124
9644
|
}
|
|
8125
9645
|
/**
|
|
8126
|
-
* Returns a Response object
|
|
9646
|
+
* Returns a Response object
|
|
9647
|
+
*/
|
|
9648
|
+
createResponse(json) {
|
|
9649
|
+
return new ResponseLinkIdentifier({
|
|
9650
|
+
query: this,
|
|
9651
|
+
json
|
|
9652
|
+
});
|
|
9653
|
+
}
|
|
9654
|
+
};
|
|
9655
|
+
|
|
9656
|
+
// src/response/ResponsePeering.ts
|
|
9657
|
+
var ResponsePeering = class extends ResponseProposeMolecule {
|
|
9658
|
+
};
|
|
9659
|
+
|
|
9660
|
+
// src/mutation/MutationPeering.ts
|
|
9661
|
+
var MutationPeering = class extends MutationProposeMolecule {
|
|
9662
|
+
/**
|
|
9663
|
+
* Fills a molecule with a P-isotope peering atom
|
|
9664
|
+
* Matches JavaScript SDK fillMolecule method exactly
|
|
9665
|
+
*/
|
|
9666
|
+
fillMolecule({ host }) {
|
|
9667
|
+
this.$__molecule.initPeering({ host });
|
|
9668
|
+
this.$__molecule.sign({});
|
|
9669
|
+
this.$__molecule.check();
|
|
9670
|
+
}
|
|
9671
|
+
/**
|
|
9672
|
+
* Builds a Response object out of a JSON object
|
|
9673
|
+
* Matches JavaScript SDK createResponse method exactly
|
|
9674
|
+
*/
|
|
9675
|
+
createResponse(json) {
|
|
9676
|
+
return new ResponsePeering({
|
|
9677
|
+
query: this,
|
|
9678
|
+
json
|
|
9679
|
+
});
|
|
9680
|
+
}
|
|
9681
|
+
};
|
|
9682
|
+
|
|
9683
|
+
// src/response/ResponseAppendRequest.ts
|
|
9684
|
+
var ResponseAppendRequest = class extends ResponseProposeMolecule {
|
|
9685
|
+
};
|
|
9686
|
+
|
|
9687
|
+
// src/mutation/MutationAppendRequest.ts
|
|
9688
|
+
var MutationAppendRequest = class extends MutationProposeMolecule {
|
|
9689
|
+
/**
|
|
9690
|
+
* Fills a molecule with an A-isotope append request atom
|
|
9691
|
+
* Matches JavaScript SDK fillMolecule method exactly
|
|
9692
|
+
*/
|
|
9693
|
+
fillMolecule({
|
|
9694
|
+
metaType,
|
|
9695
|
+
metaId,
|
|
9696
|
+
action,
|
|
9697
|
+
meta = {}
|
|
9698
|
+
}) {
|
|
9699
|
+
this.$__molecule.initAppendRequest({
|
|
9700
|
+
metaType,
|
|
9701
|
+
metaId,
|
|
9702
|
+
action,
|
|
9703
|
+
meta
|
|
9704
|
+
});
|
|
9705
|
+
this.$__molecule.sign({});
|
|
9706
|
+
this.$__molecule.check();
|
|
9707
|
+
}
|
|
9708
|
+
/**
|
|
9709
|
+
* Builds a Response object out of a JSON object
|
|
9710
|
+
* Matches JavaScript SDK createResponse method exactly
|
|
8127
9711
|
*/
|
|
8128
9712
|
createResponse(json) {
|
|
8129
|
-
return new
|
|
9713
|
+
return new ResponseAppendRequest({
|
|
8130
9714
|
query: this,
|
|
8131
9715
|
json
|
|
8132
9716
|
});
|
|
@@ -8355,6 +9939,7 @@ var KnishIOClient = class {
|
|
|
8355
9939
|
$__logging = false;
|
|
8356
9940
|
$__authTokenObjects = {};
|
|
8357
9941
|
$__authToken = null;
|
|
9942
|
+
$__authInProcess = false;
|
|
8358
9943
|
$__remainderWallet = null;
|
|
8359
9944
|
lastMoleculeQuery = null;
|
|
8360
9945
|
abortControllers = /* @__PURE__ */ new Map();
|
|
@@ -8498,6 +10083,9 @@ var KnishIOClient = class {
|
|
|
8498
10083
|
} else {
|
|
8499
10084
|
this.$__uris = uri;
|
|
8500
10085
|
}
|
|
10086
|
+
if (this.$__client && "setUri" in this.$__client) {
|
|
10087
|
+
this.$__client.setUri(this.getRandomUri());
|
|
10088
|
+
}
|
|
8501
10089
|
}
|
|
8502
10090
|
/**
|
|
8503
10091
|
* Gets the Knish.IO server URIs
|
|
@@ -8560,7 +10148,8 @@ var KnishIOClient = class {
|
|
|
8560
10148
|
return this.$__remainderWallet;
|
|
8561
10149
|
}
|
|
8562
10150
|
/**
|
|
8563
|
-
*
|
|
10151
|
+
* Instantiates a new Molecule and prepares this client session to operate on it
|
|
10152
|
+
* Matches JavaScript SDK createMolecule implementation
|
|
8564
10153
|
*/
|
|
8565
10154
|
async createMolecule({
|
|
8566
10155
|
secret = null,
|
|
@@ -8571,17 +10160,38 @@ var KnishIOClient = class {
|
|
|
8571
10160
|
this.log("info", "KnishIOClient::createMolecule() - Creating a new molecule...");
|
|
8572
10161
|
secret = secret || this.getSecret();
|
|
8573
10162
|
bundle = bundle || this.getBundle();
|
|
10163
|
+
let continuIdPosition = null;
|
|
10164
|
+
if (sourceWallet && sourceWallet.token !== "USER") {
|
|
10165
|
+
if (this.lastMoleculeQuery && this.getRemainderWallet() && this.getRemainderWallet()?.token === "USER" && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response()?.success()) {
|
|
10166
|
+
continuIdPosition = this.getRemainderWallet()?.position || null;
|
|
10167
|
+
this.log("info", `KnishIOClient::createMolecule() - Captured USER ContinuID position ${continuIdPosition?.substring(0, 16)}... for non-USER source wallet`);
|
|
10168
|
+
} else {
|
|
10169
|
+
const userWallet = await this.getSourceWallet();
|
|
10170
|
+
continuIdPosition = userWallet?.position || null;
|
|
10171
|
+
this.log("info", `KnishIOClient::createMolecule() - Queried USER ContinuID position ${continuIdPosition?.substring(0, 16)}... for non-USER source wallet`);
|
|
10172
|
+
}
|
|
10173
|
+
}
|
|
8574
10174
|
if (!sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet()?.token === "USER" && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response()?.success()) {
|
|
8575
10175
|
sourceWallet = this.getRemainderWallet();
|
|
10176
|
+
this.log("info", `KnishIOClient::createMolecule() - Using carry-forward remainder wallet at position ${sourceWallet?.position?.substring(0, 16)}...`);
|
|
8576
10177
|
}
|
|
8577
10178
|
if (!sourceWallet) {
|
|
8578
10179
|
sourceWallet = await this.getSourceWallet();
|
|
8579
10180
|
}
|
|
8580
|
-
|
|
10181
|
+
this.setRemainderWallet(remainderWallet || Wallet.create({
|
|
8581
10182
|
secret,
|
|
8582
10183
|
bundle,
|
|
10184
|
+
token: "USER",
|
|
10185
|
+
batchId: sourceWallet.batchId,
|
|
10186
|
+
characters: sourceWallet.characters
|
|
10187
|
+
}));
|
|
10188
|
+
return new Molecule({
|
|
10189
|
+
secret,
|
|
8583
10190
|
sourceWallet,
|
|
8584
|
-
remainderWallet
|
|
10191
|
+
remainderWallet: this.getRemainderWallet(),
|
|
10192
|
+
cellSlug: this.getCellSlug(),
|
|
10193
|
+
version: this.getServerSdkVersion(),
|
|
10194
|
+
continuIdPosition
|
|
8585
10195
|
});
|
|
8586
10196
|
}
|
|
8587
10197
|
/**
|
|
@@ -8604,7 +10214,7 @@ var KnishIOClient = class {
|
|
|
8604
10214
|
* Executes a query or mutation
|
|
8605
10215
|
*/
|
|
8606
10216
|
async executeQuery(query, variables = null) {
|
|
8607
|
-
if (this.$__authToken && this.$__authToken.isExpired()) {
|
|
10217
|
+
if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
|
|
8608
10218
|
this.log("info", "KnishIOClient::executeQuery() - Access token is expired. Getting new one...");
|
|
8609
10219
|
await this.requestAuthToken({
|
|
8610
10220
|
secret: this.$__secret,
|
|
@@ -8631,14 +10241,26 @@ var KnishIOClient = class {
|
|
|
8631
10241
|
}
|
|
8632
10242
|
}
|
|
8633
10243
|
/**
|
|
8634
|
-
*
|
|
10244
|
+
* Retrieves this session's wallet used for signing the next Molecule
|
|
10245
|
+
* Queries ContinuID from the server to get the authoritative position
|
|
10246
|
+
* Matches JavaScript SDK getSourceWallet implementation
|
|
8635
10247
|
*/
|
|
8636
10248
|
async getSourceWallet() {
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
10249
|
+
let sourceWallet = (await this.queryContinuId({
|
|
10250
|
+
bundle: this.getBundle()
|
|
10251
|
+
}))?.payload();
|
|
10252
|
+
if (!sourceWallet) {
|
|
10253
|
+
sourceWallet = new Wallet({
|
|
10254
|
+
secret: this.getSecret()
|
|
10255
|
+
});
|
|
10256
|
+
} else {
|
|
10257
|
+
sourceWallet.key = Wallet.generateKey({
|
|
10258
|
+
secret: this.getSecret(),
|
|
10259
|
+
token: sourceWallet.token,
|
|
10260
|
+
position: sourceWallet.position
|
|
10261
|
+
});
|
|
10262
|
+
}
|
|
10263
|
+
return sourceWallet;
|
|
8642
10264
|
}
|
|
8643
10265
|
/**
|
|
8644
10266
|
* Transfer tokens between wallets
|
|
@@ -8667,7 +10289,7 @@ var KnishIOClient = class {
|
|
|
8667
10289
|
amount
|
|
8668
10290
|
});
|
|
8669
10291
|
}
|
|
8670
|
-
if (sourceWallet === null || Decimal.cmp(sourceWallet.balance, amount) < 0) {
|
|
10292
|
+
if (sourceWallet === null || Decimal.cmp(Number(sourceWallet.balance), amount) < 0) {
|
|
8671
10293
|
throw new exports.TransferBalanceException();
|
|
8672
10294
|
}
|
|
8673
10295
|
const recipientWallet = Wallet.create({
|
|
@@ -8702,19 +10324,48 @@ var KnishIOClient = class {
|
|
|
8702
10324
|
return await this.executeQuery(query);
|
|
8703
10325
|
}
|
|
8704
10326
|
/**
|
|
8705
|
-
* Request authorization token
|
|
10327
|
+
* Request authorization token (guest or profile)
|
|
10328
|
+
*
|
|
10329
|
+
* @param secret - User secret for profile auth (null for guest)
|
|
10330
|
+
* @param seed - Seed to generate secret (alternative to secret)
|
|
10331
|
+
* @param cellSlug - Cell slug for scoped access
|
|
10332
|
+
* @param encrypt - Whether to use encryption
|
|
8706
10333
|
*/
|
|
8707
10334
|
async requestAuthToken({
|
|
8708
|
-
secret
|
|
8709
|
-
seed
|
|
8710
|
-
cellSlug
|
|
8711
|
-
encrypt
|
|
10335
|
+
secret = null,
|
|
10336
|
+
seed = null,
|
|
10337
|
+
cellSlug = null,
|
|
10338
|
+
encrypt = false
|
|
8712
10339
|
} = {}) {
|
|
8713
10340
|
if (this.$__serverSdkVersion < 3) {
|
|
8714
|
-
this.log("warn", "KnishIOClient::
|
|
10341
|
+
this.log("warn", "KnishIOClient::requestAuthToken() - Server SDK version does not require authorization...");
|
|
8715
10342
|
return null;
|
|
8716
10343
|
}
|
|
8717
|
-
|
|
10344
|
+
if (secret === null && seed) {
|
|
10345
|
+
secret = generateSecret(seed);
|
|
10346
|
+
}
|
|
10347
|
+
if (cellSlug) {
|
|
10348
|
+
this.setCellSlug(cellSlug);
|
|
10349
|
+
}
|
|
10350
|
+
this.$__authInProcess = true;
|
|
10351
|
+
let response;
|
|
10352
|
+
if (secret) {
|
|
10353
|
+
response = await this.requestProfileAuthToken({
|
|
10354
|
+
secret,
|
|
10355
|
+
encrypt
|
|
10356
|
+
});
|
|
10357
|
+
} else {
|
|
10358
|
+
response = await this.requestGuestAuthToken({
|
|
10359
|
+
cellSlug: cellSlug || this.getCellSlug(),
|
|
10360
|
+
encrypt
|
|
10361
|
+
});
|
|
10362
|
+
}
|
|
10363
|
+
if (this.$__authToken) {
|
|
10364
|
+
this.log("info", `KnishIOClient::requestAuthToken() - Successfully retrieved auth token...`);
|
|
10365
|
+
}
|
|
10366
|
+
this.switchEncryption(encrypt);
|
|
10367
|
+
this.$__authInProcess = false;
|
|
10368
|
+
return response;
|
|
8718
10369
|
}
|
|
8719
10370
|
/**
|
|
8720
10371
|
* Logging utility
|
|
@@ -8812,7 +10463,7 @@ var KnishIOClient = class {
|
|
|
8812
10463
|
});
|
|
8813
10464
|
const sourceWallet = response.payload();
|
|
8814
10465
|
const amountNum = typeof amount === "string" ? Number(amount) : amount;
|
|
8815
|
-
if (sourceWallet === null || Decimal.cmp(sourceWallet.balance || 0, amountNum) < 0) {
|
|
10466
|
+
if (sourceWallet === null || Decimal.cmp(Number(sourceWallet.balance || 0), amountNum) < 0) {
|
|
8816
10467
|
throw new exports.TransferBalanceException();
|
|
8817
10468
|
}
|
|
8818
10469
|
if (!sourceWallet.position || !sourceWallet.address) {
|
|
@@ -8832,7 +10483,7 @@ var KnishIOClient = class {
|
|
|
8832
10483
|
const walletQuery = this.createQuery(QueryWalletList);
|
|
8833
10484
|
const response = await this.executeQuery(walletQuery, {
|
|
8834
10485
|
bundleHash: bundle || this.getBundle(),
|
|
8835
|
-
|
|
10486
|
+
token,
|
|
8836
10487
|
unspent
|
|
8837
10488
|
});
|
|
8838
10489
|
return response?.payload() || [];
|
|
@@ -8882,6 +10533,7 @@ var KnishIOClient = class {
|
|
|
8882
10533
|
count = null,
|
|
8883
10534
|
countBy = null,
|
|
8884
10535
|
throughAtom = true,
|
|
10536
|
+
throughMolecule = false,
|
|
8885
10537
|
values = null,
|
|
8886
10538
|
keys = null,
|
|
8887
10539
|
atomValues = null
|
|
@@ -8889,7 +10541,23 @@ var KnishIOClient = class {
|
|
|
8889
10541
|
this.log("info", `KnishIOClient::queryMeta() - Querying metaType: ${metaType}, metaId: ${metaId}...`);
|
|
8890
10542
|
let query;
|
|
8891
10543
|
let variables;
|
|
8892
|
-
if (
|
|
10544
|
+
if (throughMolecule) {
|
|
10545
|
+
query = this.createQuery(QueryMetaTypeViaMolecule);
|
|
10546
|
+
variables = QueryMetaTypeViaMolecule.createVariables({
|
|
10547
|
+
metaType,
|
|
10548
|
+
metaId,
|
|
10549
|
+
key,
|
|
10550
|
+
value,
|
|
10551
|
+
latest,
|
|
10552
|
+
filter,
|
|
10553
|
+
queryArgs,
|
|
10554
|
+
countBy,
|
|
10555
|
+
values,
|
|
10556
|
+
keys,
|
|
10557
|
+
atomValues,
|
|
10558
|
+
cellSlug: this.getCellSlug()
|
|
10559
|
+
});
|
|
10560
|
+
} else if (throughAtom) {
|
|
8893
10561
|
query = this.createQuery(QueryMetaTypeViaAtom);
|
|
8894
10562
|
variables = QueryMetaTypeViaAtom.createVariables({
|
|
8895
10563
|
metaType,
|
|
@@ -8922,6 +10590,19 @@ var KnishIOClient = class {
|
|
|
8922
10590
|
}
|
|
8923
10591
|
return this.executeQuery(query, variables);
|
|
8924
10592
|
}
|
|
10593
|
+
/**
|
|
10594
|
+
* Queries meta assets and verifies cryptographic integrity of associated molecules.
|
|
10595
|
+
* Forces throughMolecule=true to ensure molecule data is available for verification.
|
|
10596
|
+
* Returns the same response as queryMeta(), with an additional `integrity` field on the payload.
|
|
10597
|
+
*/
|
|
10598
|
+
async queryMetaVerified(params) {
|
|
10599
|
+
const response = await this.queryMeta({ ...params, throughMolecule: true });
|
|
10600
|
+
const payload = response.payload();
|
|
10601
|
+
if (payload && typeof response.verifyIntegrity === "function") {
|
|
10602
|
+
payload.integrity = response.verifyIntegrity();
|
|
10603
|
+
}
|
|
10604
|
+
return response;
|
|
10605
|
+
}
|
|
8925
10606
|
/**
|
|
8926
10607
|
* Query cascading meta instances for batchId
|
|
8927
10608
|
*/
|
|
@@ -9184,7 +10865,7 @@ var KnishIOClient = class {
|
|
|
9184
10865
|
const recipientWallet = new Wallet({
|
|
9185
10866
|
secret: this.getSecret(),
|
|
9186
10867
|
bundle: this.getBundle(),
|
|
9187
|
-
token
|
|
10868
|
+
token,
|
|
9188
10869
|
batchId
|
|
9189
10870
|
});
|
|
9190
10871
|
await mutation.fillMolecule({
|
|
@@ -9212,7 +10893,7 @@ var KnishIOClient = class {
|
|
|
9212
10893
|
this.log("info", `KnishIOClient::requestTokens() - Requesting ${amount || "units"} of ${token}...`);
|
|
9213
10894
|
const mutation = await this.createMoleculeMutation({ mutationClass: MutationRequestTokens });
|
|
9214
10895
|
await mutation.fillMolecule({
|
|
9215
|
-
token
|
|
10896
|
+
token,
|
|
9216
10897
|
amount: amount ?? 0,
|
|
9217
10898
|
metaType: to || "",
|
|
9218
10899
|
metaId: to || "",
|
|
@@ -9241,11 +10922,19 @@ var KnishIOClient = class {
|
|
|
9241
10922
|
amount: amount || 0
|
|
9242
10923
|
});
|
|
9243
10924
|
}
|
|
9244
|
-
const
|
|
10925
|
+
const remainderWallet = sourceWallet.createRemainder(this.getSecret());
|
|
10926
|
+
const molecule = await this.createMolecule({
|
|
10927
|
+
sourceWallet,
|
|
10928
|
+
remainderWallet
|
|
10929
|
+
});
|
|
10930
|
+
const mutation = await this.createMoleculeMutation({
|
|
10931
|
+
mutationClass: MutationTransferTokens,
|
|
10932
|
+
molecule
|
|
10933
|
+
});
|
|
9245
10934
|
const recipientWallet = new Wallet({
|
|
9246
10935
|
secret: this.getSecret(),
|
|
9247
10936
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
9248
|
-
token
|
|
10937
|
+
token
|
|
9249
10938
|
});
|
|
9250
10939
|
await mutation.fillMolecule({
|
|
9251
10940
|
recipientWallet,
|
|
@@ -9300,7 +10989,7 @@ var KnishIOClient = class {
|
|
|
9300
10989
|
const newWallet = new Wallet({
|
|
9301
10990
|
secret: this.getSecret(),
|
|
9302
10991
|
bundle: this.getBundle(),
|
|
9303
|
-
token
|
|
10992
|
+
token
|
|
9304
10993
|
});
|
|
9305
10994
|
await mutation.fillMolecule(newWallet);
|
|
9306
10995
|
const response = await this.executeQuery(mutation);
|
|
@@ -9331,7 +11020,7 @@ var KnishIOClient = class {
|
|
|
9331
11020
|
}
|
|
9332
11021
|
const mutation = await this.createMoleculeMutation({ mutationClass: MutationClaimShadowWallet });
|
|
9333
11022
|
await mutation.fillMolecule({
|
|
9334
|
-
token
|
|
11023
|
+
token,
|
|
9335
11024
|
batchId: shadowWallet.batchId
|
|
9336
11025
|
});
|
|
9337
11026
|
const response = await this.executeQuery(mutation);
|
|
@@ -9379,11 +11068,16 @@ var KnishIOClient = class {
|
|
|
9379
11068
|
policy = null
|
|
9380
11069
|
}) {
|
|
9381
11070
|
this.log("info", `KnishIOClient::createMeta() - Creating metadata for ${metaType}:${metaId}...`);
|
|
9382
|
-
const mutation = await this.createMoleculeMutation({
|
|
11071
|
+
const mutation = await this.createMoleculeMutation({
|
|
11072
|
+
mutationClass: MutationCreateMeta,
|
|
11073
|
+
molecule: await this.createMolecule({
|
|
11074
|
+
secret: this.getSecret()
|
|
11075
|
+
})
|
|
11076
|
+
});
|
|
9383
11077
|
await mutation.fillMolecule({
|
|
9384
|
-
metaType
|
|
11078
|
+
metaType,
|
|
9385
11079
|
metaId,
|
|
9386
|
-
meta,
|
|
11080
|
+
meta: meta || {},
|
|
9387
11081
|
policy
|
|
9388
11082
|
});
|
|
9389
11083
|
const response = await this.executeQuery(mutation);
|
|
@@ -9402,9 +11096,14 @@ var KnishIOClient = class {
|
|
|
9402
11096
|
policy = null
|
|
9403
11097
|
}) {
|
|
9404
11098
|
this.log("info", `KnishIOClient::createRule() - Creating rule for ${metaType}:${metaId}...`);
|
|
9405
|
-
const mutation = await this.createMoleculeMutation({
|
|
11099
|
+
const mutation = await this.createMoleculeMutation({
|
|
11100
|
+
mutationClass: MutationCreateRule,
|
|
11101
|
+
molecule: await this.createMolecule({
|
|
11102
|
+
secret: this.getSecret()
|
|
11103
|
+
})
|
|
11104
|
+
});
|
|
9406
11105
|
await mutation.fillMolecule({
|
|
9407
|
-
metaType
|
|
11106
|
+
metaType,
|
|
9408
11107
|
metaId,
|
|
9409
11108
|
rule,
|
|
9410
11109
|
policy
|
|
@@ -9491,8 +11190,8 @@ var KnishIOClient = class {
|
|
|
9491
11190
|
this.log("info", `KnishIOClient::activeSession() - Declaring active session for ${metaType}:${metaId}...`);
|
|
9492
11191
|
const mutation = this.createQuery(MutationActiveSession);
|
|
9493
11192
|
const response = await this.executeQuery(mutation, {
|
|
9494
|
-
|
|
9495
|
-
metaType
|
|
11193
|
+
bundleHash: bundle || this.getBundle(),
|
|
11194
|
+
metaType,
|
|
9496
11195
|
metaId,
|
|
9497
11196
|
ipAddress,
|
|
9498
11197
|
browser,
|
|
@@ -9522,7 +11221,15 @@ var KnishIOClient = class {
|
|
|
9522
11221
|
amount
|
|
9523
11222
|
});
|
|
9524
11223
|
}
|
|
9525
|
-
const
|
|
11224
|
+
const remainderWallet = sourceWallet.createRemainder(this.getSecret());
|
|
11225
|
+
const molecule = await this.createMolecule({
|
|
11226
|
+
sourceWallet,
|
|
11227
|
+
remainderWallet
|
|
11228
|
+
});
|
|
11229
|
+
const mutation = await this.createMoleculeMutation({
|
|
11230
|
+
mutationClass: MutationDepositBufferToken,
|
|
11231
|
+
molecule
|
|
11232
|
+
});
|
|
9526
11233
|
await mutation.fillMolecule({
|
|
9527
11234
|
amount: typeof amount === "string" ? Number(amount) : amount,
|
|
9528
11235
|
tradeRates
|
|
@@ -9585,6 +11292,7 @@ var KnishIOClient = class {
|
|
|
9585
11292
|
}
|
|
9586
11293
|
/**
|
|
9587
11294
|
* Request profile authentication token
|
|
11295
|
+
* Matches JavaScript SDK requestProfileAuthToken implementation
|
|
9588
11296
|
*/
|
|
9589
11297
|
async requestProfileAuthToken({
|
|
9590
11298
|
secret,
|
|
@@ -9592,151 +11300,108 @@ var KnishIOClient = class {
|
|
|
9592
11300
|
}) {
|
|
9593
11301
|
this.log("info", "KnishIOClient::requestProfileAuthToken() - Requesting profile auth token...");
|
|
9594
11302
|
this.setSecret(secret);
|
|
9595
|
-
const
|
|
9596
|
-
|
|
11303
|
+
const wallet = new Wallet({
|
|
11304
|
+
secret,
|
|
11305
|
+
token: "AUTH"
|
|
11306
|
+
});
|
|
11307
|
+
const molecule = await this.createMolecule({
|
|
11308
|
+
secret,
|
|
11309
|
+
sourceWallet: wallet
|
|
11310
|
+
});
|
|
11311
|
+
const mutation = await this.createMoleculeMutation({
|
|
11312
|
+
mutationClass: MutationRequestAuthorization,
|
|
11313
|
+
molecule
|
|
11314
|
+
});
|
|
11315
|
+
mutation.fillMolecule({
|
|
9597
11316
|
meta: { encrypt: encrypt ? "true" : "false" }
|
|
9598
11317
|
});
|
|
9599
11318
|
const response = await this.executeQuery(mutation);
|
|
9600
11319
|
if (!response) {
|
|
9601
11320
|
throw new CodeException("Profile auth token request failed");
|
|
9602
11321
|
}
|
|
11322
|
+
if (response.success()) {
|
|
11323
|
+
const authToken = AuthToken.create({
|
|
11324
|
+
token: response.token(),
|
|
11325
|
+
expiresAt: response.expiresAt(),
|
|
11326
|
+
encrypt: String(response.encrypt()) === "true",
|
|
11327
|
+
pubkey: response.pubKey()
|
|
11328
|
+
}, wallet);
|
|
11329
|
+
this.setAuthToken(authToken);
|
|
11330
|
+
} else {
|
|
11331
|
+
throw new AuthorizationRejectedException_default(
|
|
11332
|
+
`KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${response.reason()}`
|
|
11333
|
+
);
|
|
11334
|
+
}
|
|
9603
11335
|
if (encrypt) {
|
|
9604
11336
|
this.switchEncryption(true);
|
|
9605
11337
|
}
|
|
9606
11338
|
return response;
|
|
9607
11339
|
}
|
|
9608
11340
|
// =============================================================================
|
|
9609
|
-
//
|
|
11341
|
+
// MUTATION METHODS - PEERING & APPEND REQUEST
|
|
9610
11342
|
// =============================================================================
|
|
9611
11343
|
/**
|
|
9612
|
-
*
|
|
9613
|
-
|
|
9614
|
-
cellSlug() {
|
|
9615
|
-
return this.getCellSlug();
|
|
9616
|
-
}
|
|
9617
|
-
/**
|
|
9618
|
-
* @deprecated Use getUri() instead
|
|
11344
|
+
* Register a peer node via P-isotope
|
|
11345
|
+
* Matches JavaScript SDK registerPeer implementation exactly
|
|
9619
11346
|
*/
|
|
9620
|
-
|
|
9621
|
-
|
|
11347
|
+
async registerPeer({ host }) {
|
|
11348
|
+
this.log("info", `KnishIOClient::registerPeer() - Registering peer at ${host}...`);
|
|
11349
|
+
const mutation = await this.createMoleculeMutation({
|
|
11350
|
+
mutationClass: MutationPeering,
|
|
11351
|
+
molecule: await this.createMolecule({
|
|
11352
|
+
secret: this.getSecret()
|
|
11353
|
+
})
|
|
11354
|
+
});
|
|
11355
|
+
mutation.fillMolecule({ host });
|
|
11356
|
+
const response = await this.executeQuery(mutation);
|
|
11357
|
+
if (!response) {
|
|
11358
|
+
throw new CodeException("Peer registration failed");
|
|
11359
|
+
}
|
|
11360
|
+
return response;
|
|
9622
11361
|
}
|
|
9623
|
-
};
|
|
9624
|
-
|
|
9625
|
-
// src/AuthToken.ts
|
|
9626
|
-
var AuthToken = class _AuthToken {
|
|
9627
|
-
$__token;
|
|
9628
|
-
$__expiresAt;
|
|
9629
|
-
$__pubkey;
|
|
9630
|
-
$__encrypt;
|
|
9631
|
-
$__wallet;
|
|
9632
11362
|
/**
|
|
9633
|
-
*
|
|
11363
|
+
* Submit an append request via A-isotope
|
|
11364
|
+
* Matches JavaScript SDK appendRequest implementation exactly
|
|
9634
11365
|
*/
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
11366
|
+
async appendRequest({
|
|
11367
|
+
metaType,
|
|
11368
|
+
metaId,
|
|
11369
|
+
action,
|
|
11370
|
+
meta = {}
|
|
9640
11371
|
}) {
|
|
9641
|
-
this
|
|
9642
|
-
|
|
9643
|
-
|
|
9644
|
-
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
* Static factory method to create AuthToken with wallet
|
|
9648
|
-
*/
|
|
9649
|
-
static create(data, wallet) {
|
|
9650
|
-
const authToken = new _AuthToken(data);
|
|
9651
|
-
authToken.setWallet(wallet);
|
|
9652
|
-
return authToken;
|
|
9653
|
-
}
|
|
9654
|
-
/**
|
|
9655
|
-
* Restore AuthToken from snapshot
|
|
9656
|
-
*/
|
|
9657
|
-
static restore(snapshot, secret) {
|
|
9658
|
-
const wallet = new Wallet({
|
|
9659
|
-
secret,
|
|
9660
|
-
token: "AUTH",
|
|
9661
|
-
position: snapshot.wallet.position,
|
|
9662
|
-
characters: snapshot.wallet.characters
|
|
11372
|
+
this.log("info", `KnishIOClient::appendRequest() - Submitting append request for ${metaType}:${metaId}...`);
|
|
11373
|
+
const mutation = await this.createMoleculeMutation({
|
|
11374
|
+
mutationClass: MutationAppendRequest,
|
|
11375
|
+
molecule: await this.createMolecule({
|
|
11376
|
+
secret: this.getSecret()
|
|
11377
|
+
})
|
|
9663
11378
|
});
|
|
9664
|
-
|
|
9665
|
-
|
|
9666
|
-
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
}
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
this.$__wallet = wallet;
|
|
9676
|
-
}
|
|
9677
|
-
/**
|
|
9678
|
-
* Get wallet
|
|
9679
|
-
*/
|
|
9680
|
-
getWallet() {
|
|
9681
|
-
return this.$__wallet;
|
|
9682
|
-
}
|
|
9683
|
-
/**
|
|
9684
|
-
* Get auth token
|
|
9685
|
-
*/
|
|
9686
|
-
getToken() {
|
|
9687
|
-
return this.$__token;
|
|
9688
|
-
}
|
|
9689
|
-
/**
|
|
9690
|
-
* Get expiration timestamp
|
|
9691
|
-
*/
|
|
9692
|
-
getExpiresAt() {
|
|
9693
|
-
return this.$__expiresAt;
|
|
9694
|
-
}
|
|
9695
|
-
/**
|
|
9696
|
-
* Get public key
|
|
9697
|
-
*/
|
|
9698
|
-
getPubkey() {
|
|
9699
|
-
return this.$__pubkey;
|
|
9700
|
-
}
|
|
9701
|
-
/**
|
|
9702
|
-
* Check if encryption is enabled
|
|
9703
|
-
*/
|
|
9704
|
-
isEncrypted() {
|
|
9705
|
-
return this.$__encrypt;
|
|
9706
|
-
}
|
|
9707
|
-
/**
|
|
9708
|
-
* Check if token is expired
|
|
9709
|
-
*/
|
|
9710
|
-
isExpired() {
|
|
9711
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
9712
|
-
return now >= this.$__expiresAt;
|
|
11379
|
+
mutation.fillMolecule({
|
|
11380
|
+
metaType,
|
|
11381
|
+
metaId,
|
|
11382
|
+
action,
|
|
11383
|
+
meta
|
|
11384
|
+
});
|
|
11385
|
+
const response = await this.executeQuery(mutation);
|
|
11386
|
+
if (!response) {
|
|
11387
|
+
throw new CodeException("Append request failed");
|
|
11388
|
+
}
|
|
11389
|
+
return response;
|
|
9713
11390
|
}
|
|
11391
|
+
// =============================================================================
|
|
11392
|
+
// LEGACY/DEPRECATED METHODS
|
|
11393
|
+
// =============================================================================
|
|
9714
11394
|
/**
|
|
9715
|
-
*
|
|
11395
|
+
* @deprecated Use getCellSlug() instead
|
|
9716
11396
|
*/
|
|
9717
|
-
|
|
9718
|
-
return
|
|
9719
|
-
token: this.$__token,
|
|
9720
|
-
pubkey: this.$__pubkey,
|
|
9721
|
-
wallet: this.$__wallet
|
|
9722
|
-
};
|
|
11397
|
+
cellSlug() {
|
|
11398
|
+
return this.getCellSlug();
|
|
9723
11399
|
}
|
|
9724
11400
|
/**
|
|
9725
|
-
*
|
|
11401
|
+
* @deprecated Use getUri() instead
|
|
9726
11402
|
*/
|
|
9727
|
-
|
|
9728
|
-
return
|
|
9729
|
-
token: this.$__token,
|
|
9730
|
-
expiresAt: this.$__expiresAt,
|
|
9731
|
-
pubkey: this.$__pubkey,
|
|
9732
|
-
encrypt: this.$__encrypt,
|
|
9733
|
-
...this.$__wallet ? {
|
|
9734
|
-
wallet: {
|
|
9735
|
-
position: this.$__wallet.position,
|
|
9736
|
-
characters: this.$__wallet.characters
|
|
9737
|
-
}
|
|
9738
|
-
} : {}
|
|
9739
|
-
};
|
|
11403
|
+
uri() {
|
|
11404
|
+
return this.getUri();
|
|
9740
11405
|
}
|
|
9741
11406
|
};
|
|
9742
11407
|
|
|
@@ -9914,9 +11579,11 @@ exports.KnishIOClient = KnishIOClient;
|
|
|
9914
11579
|
exports.Meta = Meta;
|
|
9915
11580
|
exports.Molecule = Molecule;
|
|
9916
11581
|
exports.Mutation = Mutation;
|
|
11582
|
+
exports.MutationAppendRequest = MutationAppendRequest;
|
|
9917
11583
|
exports.MutationCreateMeta = MutationCreateMeta;
|
|
9918
11584
|
exports.MutationCreateToken = MutationCreateToken;
|
|
9919
11585
|
exports.MutationCreateWallet = MutationCreateWallet;
|
|
11586
|
+
exports.MutationPeering = MutationPeering;
|
|
9920
11587
|
exports.MutationProposeMolecule = MutationProposeMolecule;
|
|
9921
11588
|
exports.MutationRequestAuthorization = MutationRequestAuthorization;
|
|
9922
11589
|
exports.MutationRequestTokens = MutationRequestTokens;
|
|
@@ -9931,6 +11598,7 @@ exports.QueryMetaType = QueryMetaType;
|
|
|
9931
11598
|
exports.QueryMetaTypeViaAtom = QueryMetaTypeViaAtom;
|
|
9932
11599
|
exports.QueryWalletBundle = QueryWalletBundle;
|
|
9933
11600
|
exports.QueryWalletList = QueryWalletList;
|
|
11601
|
+
exports.ResponseAppendRequest = ResponseAppendRequest;
|
|
9934
11602
|
exports.ResponseAtom = ResponseAtom;
|
|
9935
11603
|
exports.ResponseBalance = ResponseBalance;
|
|
9936
11604
|
exports.ResponseContinuId = ResponseContinuId;
|
|
@@ -9939,6 +11607,7 @@ exports.ResponseCreateToken = ResponseCreateToken;
|
|
|
9939
11607
|
exports.ResponseCreateWallet = ResponseCreateWallet;
|
|
9940
11608
|
exports.ResponseMetaType = ResponseMetaType;
|
|
9941
11609
|
exports.ResponseMetaTypeViaAtom = ResponseMetaTypeViaAtom;
|
|
11610
|
+
exports.ResponsePeering = ResponsePeering;
|
|
9942
11611
|
exports.ResponseProposeMolecule = ResponseProposeMolecule;
|
|
9943
11612
|
exports.ResponseRequestAuthorization = ResponseRequestAuthorization;
|
|
9944
11613
|
exports.ResponseRequestTokens = ResponseRequestTokens;
|