@wishknish/knishio-client-ts 0.7.4 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2670 -1039
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +336 -105
- package/dist/index.d.ts +336 -105
- package/dist/index.iife.js +22097 -20047
- package/dist/index.iife.js.map +1 -1
- package/dist/index.js +2667 -1040
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/src/AuthToken.ts +8 -2
- package/src/KnishIOClient.ts +306 -50
- 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 +582 -140
- 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
|
-
return [];
|
|
3264
|
-
}
|
|
3265
|
-
const normalized = this.normalizeMeta(metaItems);
|
|
3266
|
-
if (typeof filter === "string") {
|
|
3267
|
-
return normalized.filter((item) => item.key.includes(filter));
|
|
3268
|
-
}
|
|
3269
|
-
if (filter instanceof RegExp) {
|
|
3270
|
-
return normalized.filter((item) => filter.test(item.key));
|
|
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)}`);
|
|
3276
4006
|
}
|
|
3277
4007
|
/**
|
|
3278
|
-
*
|
|
4008
|
+
* Gets all keys
|
|
3279
4009
|
*/
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
4010
|
+
keys() {
|
|
4011
|
+
return Array.from(this.__data.keys()).map(
|
|
4012
|
+
(key) => key.startsWith("__") ? key.substring(2) : key
|
|
4013
|
+
);
|
|
4014
|
+
}
|
|
4015
|
+
/**
|
|
4016
|
+
* Converts Meta object back to plain object
|
|
4017
|
+
*/
|
|
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,7 @@ var Molecule = class _Molecule {
|
|
|
3815
4809
|
remainderWallet;
|
|
3816
4810
|
atoms;
|
|
3817
4811
|
version;
|
|
4812
|
+
parentHashes;
|
|
3818
4813
|
local;
|
|
3819
4814
|
/**
|
|
3820
4815
|
* Create new Molecule instance
|
|
@@ -3836,10 +4831,10 @@ var Molecule = class _Molecule {
|
|
|
3836
4831
|
this.bundle = bundle;
|
|
3837
4832
|
this.sourceWallet = sourceWallet;
|
|
3838
4833
|
this.atoms = [];
|
|
3839
|
-
|
|
4834
|
+
this.parentHashes = [];
|
|
4835
|
+
const versionRegistry = versions_default;
|
|
4836
|
+
if (version !== null && Object.prototype.hasOwnProperty.call(versionRegistry, version)) {
|
|
3840
4837
|
this.version = String(version);
|
|
3841
|
-
} else {
|
|
3842
|
-
this.version = null;
|
|
3843
4838
|
}
|
|
3844
4839
|
if (remainderWallet || sourceWallet) {
|
|
3845
4840
|
this.remainderWallet = remainderWallet || Wallet.create({
|
|
@@ -3874,7 +4869,7 @@ var Molecule = class _Molecule {
|
|
|
3874
4869
|
if (!Array.isArray(isotopes)) {
|
|
3875
4870
|
isotopes = [isotopes];
|
|
3876
4871
|
}
|
|
3877
|
-
return atoms.filter((atom) => isotopes.includes(atom.isotope));
|
|
4872
|
+
return atoms.filter((atom) => atom.isotope !== null && isotopes.includes(atom.isotope));
|
|
3878
4873
|
}
|
|
3879
4874
|
/**
|
|
3880
4875
|
* Generates the next atomic index
|
|
@@ -3895,25 +4890,63 @@ var Molecule = class _Molecule {
|
|
|
3895
4890
|
addAtom(atom) {
|
|
3896
4891
|
this.molecularHash = null;
|
|
3897
4892
|
atom.index = this.generateIndex();
|
|
3898
|
-
atom.version = this.version
|
|
4893
|
+
atom.version = this.version ?? void 0;
|
|
3899
4894
|
this.atoms.push(atom);
|
|
3900
4895
|
this.atoms = Atom.sortAtoms(this.atoms);
|
|
3901
4896
|
return this;
|
|
3902
4897
|
}
|
|
3903
4898
|
/**
|
|
3904
4899
|
* Add user remainder atom for ContinuID
|
|
4900
|
+
* Matches JavaScript SDK addContinuIdAtom exactly
|
|
3905
4901
|
*/
|
|
3906
4902
|
addContinuIdAtom() {
|
|
3907
|
-
if (!this.remainderWallet) {
|
|
3908
|
-
|
|
4903
|
+
if (!this.remainderWallet || this.remainderWallet.token !== "USER") {
|
|
4904
|
+
this.remainderWallet = Wallet.create({
|
|
4905
|
+
secret: this.secret,
|
|
4906
|
+
bundle: this.bundle
|
|
4907
|
+
});
|
|
4908
|
+
}
|
|
4909
|
+
const continuIdMeta = {};
|
|
4910
|
+
if (this.sourceWallet && this.sourceWallet.position) {
|
|
4911
|
+
continuIdMeta.previousPosition = this.sourceWallet.position;
|
|
4912
|
+
}
|
|
4913
|
+
if (this.remainderWallet.pubkey) {
|
|
4914
|
+
continuIdMeta.pubkey = this.remainderWallet.pubkey;
|
|
4915
|
+
}
|
|
4916
|
+
if (this.remainderWallet.characters) {
|
|
4917
|
+
continuIdMeta.characters = this.remainderWallet.characters;
|
|
3909
4918
|
}
|
|
3910
|
-
this.addAtom(
|
|
4919
|
+
this.addAtom(Atom.create({
|
|
3911
4920
|
isotope: "I",
|
|
3912
|
-
|
|
3913
|
-
walletAddress: this.remainderWallet.address,
|
|
3914
|
-
token: "USER",
|
|
4921
|
+
wallet: this.remainderWallet,
|
|
3915
4922
|
metaType: "walletBundle",
|
|
3916
|
-
metaId: this.remainderWallet.bundle
|
|
4923
|
+
metaId: this.remainderWallet.bundle,
|
|
4924
|
+
meta: new AtomMeta(continuIdMeta)
|
|
4925
|
+
}));
|
|
4926
|
+
return this;
|
|
4927
|
+
}
|
|
4928
|
+
/**
|
|
4929
|
+
* Add a policy R-isotope atom (matching JS SDK)
|
|
4930
|
+
*/
|
|
4931
|
+
addPolicyAtom({
|
|
4932
|
+
metaType,
|
|
4933
|
+
metaId,
|
|
4934
|
+
meta = {},
|
|
4935
|
+
policy = {}
|
|
4936
|
+
}) {
|
|
4937
|
+
const atomMeta = new AtomMeta(meta);
|
|
4938
|
+
atomMeta.addPolicy(policy);
|
|
4939
|
+
const wallet = Wallet.create({
|
|
4940
|
+
secret: this.secret,
|
|
4941
|
+
bundle: this.sourceWallet.bundle,
|
|
4942
|
+
token: "USER"
|
|
4943
|
+
});
|
|
4944
|
+
this.addAtom(Atom.create({
|
|
4945
|
+
wallet,
|
|
4946
|
+
isotope: "R",
|
|
4947
|
+
metaType,
|
|
4948
|
+
metaId,
|
|
4949
|
+
meta: atomMeta
|
|
3917
4950
|
}));
|
|
3918
4951
|
return this;
|
|
3919
4952
|
}
|
|
@@ -3928,34 +4961,25 @@ var Molecule = class _Molecule {
|
|
|
3928
4961
|
if (!this.sourceWallet) {
|
|
3929
4962
|
throw new Error("Source wallet required for value transfer");
|
|
3930
4963
|
}
|
|
3931
|
-
if (this.sourceWallet.balance - amount < 0) {
|
|
4964
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
3932
4965
|
throw new BalanceInsufficientException();
|
|
3933
4966
|
}
|
|
3934
|
-
this.addAtom(
|
|
4967
|
+
this.addAtom(Atom.create({
|
|
3935
4968
|
isotope: "V",
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
token: this.sourceWallet.token,
|
|
3939
|
-
value: -this.sourceWallet.balance
|
|
4969
|
+
wallet: this.sourceWallet,
|
|
4970
|
+
value: -Number(this.sourceWallet.balance)
|
|
3940
4971
|
}));
|
|
3941
|
-
this.addAtom(
|
|
4972
|
+
this.addAtom(Atom.create({
|
|
3942
4973
|
isotope: "V",
|
|
3943
|
-
|
|
3944
|
-
walletAddress: recipientWallet.address,
|
|
3945
|
-
token: recipientWallet.token,
|
|
4974
|
+
wallet: recipientWallet,
|
|
3946
4975
|
value: amount,
|
|
3947
4976
|
metaType: "walletBundle",
|
|
3948
4977
|
metaId: recipientWallet.bundle
|
|
3949
4978
|
}));
|
|
3950
|
-
|
|
3951
|
-
throw new Error("Remainder wallet required for value transfer");
|
|
3952
|
-
}
|
|
3953
|
-
this.addAtom(new Atom({
|
|
4979
|
+
this.addAtom(Atom.create({
|
|
3954
4980
|
isotope: "V",
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
token: this.remainderWallet.token,
|
|
3958
|
-
value: this.sourceWallet.balance - amount,
|
|
4981
|
+
wallet: this.remainderWallet,
|
|
4982
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
3959
4983
|
metaType: "walletBundle",
|
|
3960
4984
|
metaId: this.remainderWallet.bundle
|
|
3961
4985
|
}));
|
|
@@ -3984,6 +5008,17 @@ var Molecule = class _Molecule {
|
|
|
3984
5008
|
throw new SignatureMalformedException("No atoms available for signing!");
|
|
3985
5009
|
}
|
|
3986
5010
|
let signingPosition = signingAtom.position;
|
|
5011
|
+
const signingWalletMeta = signingAtom.aggregatedMeta ? signingAtom.aggregatedMeta() : null;
|
|
5012
|
+
const signingWalletJson = signingWalletMeta?.signingWallet;
|
|
5013
|
+
if (signingWalletJson) {
|
|
5014
|
+
try {
|
|
5015
|
+
const parsedSigningWallet = JSON.parse(signingWalletJson);
|
|
5016
|
+
if (parsedSigningWallet.position) {
|
|
5017
|
+
signingPosition = parsedSigningWallet.position;
|
|
5018
|
+
}
|
|
5019
|
+
} catch {
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
3987
5022
|
if (!signingPosition) {
|
|
3988
5023
|
throw new SignatureMalformedException("Signing wallet must have a position!");
|
|
3989
5024
|
}
|
|
@@ -4102,7 +5137,7 @@ var Molecule = class _Molecule {
|
|
|
4102
5137
|
*/
|
|
4103
5138
|
toJSON(options = {}) {
|
|
4104
5139
|
const {
|
|
4105
|
-
includeValidationContext =
|
|
5140
|
+
includeValidationContext = false,
|
|
4106
5141
|
includeOtsFragments = true,
|
|
4107
5142
|
secureMode = false
|
|
4108
5143
|
} = options;
|
|
@@ -4115,21 +5150,24 @@ var Molecule = class _Molecule {
|
|
|
4115
5150
|
molecularHash: this.molecularHash,
|
|
4116
5151
|
createdAt: this.createdAt,
|
|
4117
5152
|
cellSlug: this.cellSlug,
|
|
4118
|
-
cellSlugOrigin: this.cellSlugOrigin,
|
|
4119
|
-
version: this.version,
|
|
4120
5153
|
bundle: this.bundle,
|
|
4121
5154
|
// Serialized atoms array with optional OTS fragments
|
|
4122
5155
|
atoms: this.atoms.map((atom) => atom.toJSON({
|
|
4123
5156
|
includeOtsFragments
|
|
4124
5157
|
}))
|
|
4125
5158
|
};
|
|
5159
|
+
if (this.parentHashes && this.parentHashes.length > 0) {
|
|
5160
|
+
serialized.parentHashes = this.parentHashes;
|
|
5161
|
+
}
|
|
4126
5162
|
if (includeValidationContext) {
|
|
5163
|
+
serialized.cellSlugOrigin = this.cellSlugOrigin;
|
|
5164
|
+
serialized.version = this.version;
|
|
4127
5165
|
if (this.sourceWallet) {
|
|
4128
5166
|
serialized.sourceWallet = {
|
|
4129
5167
|
address: this.sourceWallet.address,
|
|
4130
5168
|
position: this.sourceWallet.position,
|
|
4131
5169
|
token: this.sourceWallet.token,
|
|
4132
|
-
balance: this.sourceWallet.balance || 0,
|
|
5170
|
+
balance: this.sourceWallet.balance || "0",
|
|
4133
5171
|
bundle: this.sourceWallet.bundle,
|
|
4134
5172
|
batchId: this.sourceWallet.batchId || null,
|
|
4135
5173
|
characters: this.sourceWallet.characters || "BASE64",
|
|
@@ -4145,7 +5183,7 @@ var Molecule = class _Molecule {
|
|
|
4145
5183
|
address: this.remainderWallet.address,
|
|
4146
5184
|
position: this.remainderWallet.position,
|
|
4147
5185
|
token: this.remainderWallet.token,
|
|
4148
|
-
balance: this.remainderWallet.balance || 0,
|
|
5186
|
+
balance: this.remainderWallet.balance || "0",
|
|
4149
5187
|
bundle: this.remainderWallet.bundle,
|
|
4150
5188
|
batchId: this.remainderWallet.batchId || null,
|
|
4151
5189
|
characters: this.remainderWallet.characters || "BASE64",
|
|
@@ -4173,30 +5211,26 @@ var Molecule = class _Molecule {
|
|
|
4173
5211
|
// =============================================================================
|
|
4174
5212
|
/**
|
|
4175
5213
|
* Initialize token creation
|
|
5214
|
+
* Matches JavaScript SDK initTokenCreation implementation
|
|
4176
5215
|
*/
|
|
4177
5216
|
initTokenCreation({
|
|
4178
5217
|
recipientWallet,
|
|
4179
5218
|
amount,
|
|
4180
5219
|
meta
|
|
4181
5220
|
}) {
|
|
4182
|
-
this.
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
5221
|
+
if (!this.sourceWallet) {
|
|
5222
|
+
throw new Error("Source wallet required for token creation");
|
|
5223
|
+
}
|
|
5224
|
+
const atomMeta = new AtomMeta(meta);
|
|
5225
|
+
atomMeta.setMetaWallet(recipientWallet);
|
|
5226
|
+
this.addAtom(Atom.create({
|
|
5227
|
+
isotope: "C",
|
|
5228
|
+
wallet: this.sourceWallet,
|
|
4187
5229
|
value: amount,
|
|
4188
5230
|
metaType: "token",
|
|
4189
5231
|
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) }] : []
|
|
5232
|
+
meta: atomMeta,
|
|
5233
|
+
batchId: recipientWallet.batchId
|
|
4200
5234
|
}));
|
|
4201
5235
|
this.addContinuIdAtom();
|
|
4202
5236
|
return this;
|
|
@@ -4206,28 +5240,48 @@ var Molecule = class _Molecule {
|
|
|
4206
5240
|
*/
|
|
4207
5241
|
burnToken({
|
|
4208
5242
|
amount,
|
|
4209
|
-
walletBundle = null
|
|
5243
|
+
walletBundle: _walletBundle = null
|
|
4210
5244
|
}) {
|
|
4211
5245
|
if (!this.sourceWallet) {
|
|
4212
5246
|
throw new Error("Source wallet required for token burning");
|
|
4213
5247
|
}
|
|
4214
|
-
if (amount
|
|
4215
|
-
throw new NegativeAmountException();
|
|
5248
|
+
if (amount < 0) {
|
|
5249
|
+
throw new NegativeAmountException("Molecule::burnToken() - Amount to burn must be positive!");
|
|
4216
5250
|
}
|
|
4217
|
-
if (this.sourceWallet.balance - amount < 0) {
|
|
5251
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
4218
5252
|
throw new BalanceInsufficientException();
|
|
4219
5253
|
}
|
|
4220
|
-
this.addAtom(
|
|
5254
|
+
this.addAtom(Atom.create({
|
|
4221
5255
|
isotope: "V",
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
5256
|
+
wallet: this.sourceWallet,
|
|
5257
|
+
value: -amount
|
|
5258
|
+
}));
|
|
5259
|
+
this.addAtom(Atom.create({
|
|
5260
|
+
isotope: "V",
|
|
5261
|
+
wallet: this.remainderWallet,
|
|
5262
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
5263
|
+
metaType: "walletBundle",
|
|
5264
|
+
metaId: this.remainderWallet.bundle
|
|
4228
5265
|
}));
|
|
4229
5266
|
return this;
|
|
4230
5267
|
}
|
|
5268
|
+
/**
|
|
5269
|
+
* Initialize authorization request
|
|
5270
|
+
* Creates U-isotope (authorization) atom for requesting auth token
|
|
5271
|
+
* Matches JavaScript SDK Molecule.initAuthorization
|
|
5272
|
+
*/
|
|
5273
|
+
initAuthorization({ meta }) {
|
|
5274
|
+
if (!this.sourceWallet) {
|
|
5275
|
+
throw new Error("Source wallet required for authorization");
|
|
5276
|
+
}
|
|
5277
|
+
this.addAtom(Atom.create({
|
|
5278
|
+
isotope: "U",
|
|
5279
|
+
wallet: this.sourceWallet,
|
|
5280
|
+
meta: new AtomMeta(meta)
|
|
5281
|
+
}));
|
|
5282
|
+
this.addContinuIdAtom();
|
|
5283
|
+
return this;
|
|
5284
|
+
}
|
|
4231
5285
|
/**
|
|
4232
5286
|
* Initialize meta
|
|
4233
5287
|
*/
|
|
@@ -4240,59 +5294,123 @@ var Molecule = class _Molecule {
|
|
|
4240
5294
|
if (!this.sourceWallet) {
|
|
4241
5295
|
throw new Error("Source wallet required for meta creation");
|
|
4242
5296
|
}
|
|
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({
|
|
5297
|
+
this.addAtom(Atom.create({
|
|
4259
5298
|
isotope: "M",
|
|
4260
|
-
|
|
4261
|
-
walletAddress: this.sourceWallet.address,
|
|
4262
|
-
token: this.sourceWallet.token,
|
|
5299
|
+
wallet: this.sourceWallet,
|
|
4263
5300
|
metaType,
|
|
4264
5301
|
metaId,
|
|
4265
|
-
meta:
|
|
5302
|
+
meta: new AtomMeta(meta)
|
|
4266
5303
|
}));
|
|
5304
|
+
if (policy && Object.keys(policy).length > 0) {
|
|
5305
|
+
this.addPolicyAtom({
|
|
5306
|
+
metaType,
|
|
5307
|
+
metaId,
|
|
5308
|
+
meta,
|
|
5309
|
+
policy
|
|
5310
|
+
});
|
|
5311
|
+
}
|
|
4267
5312
|
this.addContinuIdAtom();
|
|
4268
5313
|
return this;
|
|
4269
5314
|
}
|
|
4270
5315
|
/**
|
|
4271
5316
|
* Initialize wallet creation
|
|
5317
|
+
* Uses source wallet for atom properties (matching JavaScript SDK)
|
|
5318
|
+
* The wallet being created is stored in metadata
|
|
4272
5319
|
*/
|
|
4273
5320
|
initWalletCreation(wallet, atomMeta = null) {
|
|
4274
|
-
|
|
5321
|
+
if (!this.sourceWallet) {
|
|
5322
|
+
throw new Error("Source wallet required for wallet creation");
|
|
5323
|
+
}
|
|
5324
|
+
if (!atomMeta) {
|
|
5325
|
+
atomMeta = new AtomMeta();
|
|
5326
|
+
}
|
|
5327
|
+
atomMeta.setMetaWallet(wallet);
|
|
5328
|
+
const creationAtom = Atom.create({
|
|
4275
5329
|
isotope: "C",
|
|
4276
|
-
|
|
4277
|
-
walletAddress: wallet.address,
|
|
4278
|
-
token: wallet.token,
|
|
5330
|
+
wallet: this.sourceWallet,
|
|
4279
5331
|
metaType: "wallet",
|
|
4280
5332
|
metaId: wallet.address,
|
|
4281
|
-
meta: atomMeta
|
|
5333
|
+
meta: atomMeta,
|
|
5334
|
+
batchId: wallet.batchId
|
|
4282
5335
|
});
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
5336
|
+
this.addAtom(creationAtom);
|
|
5337
|
+
this.addContinuIdAtom();
|
|
5338
|
+
return this;
|
|
5339
|
+
}
|
|
5340
|
+
/**
|
|
5341
|
+
* Creates atoms for rule definition
|
|
5342
|
+
* Matches JavaScript SDK Molecule.createRule method
|
|
5343
|
+
*
|
|
5344
|
+
* @param metaType - The meta type for the rule
|
|
5345
|
+
* @param metaId - The meta ID for the rule
|
|
5346
|
+
* @param rule - Array of Rule objects or rule data
|
|
5347
|
+
* @param policy - Optional policy object
|
|
5348
|
+
* @return This molecule instance for chaining
|
|
5349
|
+
*/
|
|
5350
|
+
createRule({
|
|
5351
|
+
metaType,
|
|
5352
|
+
metaId,
|
|
5353
|
+
rule,
|
|
5354
|
+
policy = {}
|
|
5355
|
+
}) {
|
|
5356
|
+
if (!this.sourceWallet) {
|
|
5357
|
+
throw new Error("Source wallet required for createRule");
|
|
5358
|
+
}
|
|
5359
|
+
const ruleArray = Array.isArray(rule) ? rule : [rule];
|
|
5360
|
+
const rules = [];
|
|
5361
|
+
for (const r of ruleArray) {
|
|
5362
|
+
rules.push(r instanceof Rule ? r : Rule.toObject(r));
|
|
5363
|
+
}
|
|
5364
|
+
const atomMeta = new AtomMeta({
|
|
5365
|
+
rule: JSON.stringify(rules)
|
|
5366
|
+
});
|
|
5367
|
+
if (policy && Object.keys(policy).length > 0) {
|
|
5368
|
+
atomMeta.addPolicy(policy);
|
|
5369
|
+
}
|
|
5370
|
+
this.addAtom(Atom.create({
|
|
5371
|
+
isotope: "R",
|
|
5372
|
+
wallet: this.sourceWallet,
|
|
5373
|
+
metaType,
|
|
5374
|
+
metaId,
|
|
5375
|
+
meta: atomMeta
|
|
5376
|
+
}));
|
|
5377
|
+
this.addContinuIdAtom();
|
|
5378
|
+
return this;
|
|
5379
|
+
}
|
|
5380
|
+
/**
|
|
5381
|
+
* Initializes a token request molecule
|
|
5382
|
+
* Matches JavaScript SDK Molecule.initTokenRequest method
|
|
5383
|
+
*
|
|
5384
|
+
* @param token - Token slug to request
|
|
5385
|
+
* @param amount - Amount of tokens to request
|
|
5386
|
+
* @param metaType - Meta type (typically 'walletBundle')
|
|
5387
|
+
* @param metaId - Meta ID (typically recipient bundle hash)
|
|
5388
|
+
* @param meta - Optional additional metadata
|
|
5389
|
+
* @param batchId - Optional batch ID
|
|
5390
|
+
* @return This molecule instance for chaining
|
|
5391
|
+
*/
|
|
5392
|
+
initTokenRequest({
|
|
5393
|
+
token,
|
|
5394
|
+
amount,
|
|
5395
|
+
metaType,
|
|
5396
|
+
metaId,
|
|
5397
|
+
meta = {},
|
|
5398
|
+
batchId = null
|
|
5399
|
+
}) {
|
|
5400
|
+
if (!this.sourceWallet) {
|
|
5401
|
+
throw new Error("Source wallet required for initTokenRequest");
|
|
4294
5402
|
}
|
|
4295
|
-
|
|
5403
|
+
const metaWithToken = { ...meta, token, amount: String(amount) };
|
|
5404
|
+
this.local = 1;
|
|
5405
|
+
this.addAtom(Atom.create({
|
|
5406
|
+
isotope: "T",
|
|
5407
|
+
wallet: this.sourceWallet,
|
|
5408
|
+
value: amount,
|
|
5409
|
+
metaType,
|
|
5410
|
+
metaId,
|
|
5411
|
+
meta: new AtomMeta(metaWithToken),
|
|
5412
|
+
batchId
|
|
5413
|
+
}));
|
|
4296
5414
|
this.addContinuIdAtom();
|
|
4297
5415
|
return this;
|
|
4298
5416
|
}
|
|
@@ -4342,6 +5460,7 @@ var Molecule = class _Molecule {
|
|
|
4342
5460
|
}
|
|
4343
5461
|
});
|
|
4344
5462
|
}
|
|
5463
|
+
molecule.parentHashes = Array.isArray(data.parentHashes) ? [...data.parentHashes] : [];
|
|
4345
5464
|
if (includeValidationContext) {
|
|
4346
5465
|
if (data.sourceWallet) {
|
|
4347
5466
|
molecule.sourceWallet = new Wallet({
|
|
@@ -4352,7 +5471,7 @@ var Molecule = class _Molecule {
|
|
|
4352
5471
|
batchId: data.sourceWallet.batchId,
|
|
4353
5472
|
characters: data.sourceWallet.characters
|
|
4354
5473
|
});
|
|
4355
|
-
molecule.sourceWallet.balance = data.sourceWallet.balance
|
|
5474
|
+
molecule.sourceWallet.balance = String(data.sourceWallet.balance != null ? data.sourceWallet.balance : 0);
|
|
4356
5475
|
molecule.sourceWallet.address = data.sourceWallet.address;
|
|
4357
5476
|
if (data.sourceWallet.pubkey) {
|
|
4358
5477
|
molecule.sourceWallet.pubkey = data.sourceWallet.pubkey;
|
|
@@ -4370,7 +5489,7 @@ var Molecule = class _Molecule {
|
|
|
4370
5489
|
batchId: data.remainderWallet.batchId,
|
|
4371
5490
|
characters: data.remainderWallet.characters
|
|
4372
5491
|
});
|
|
4373
|
-
molecule.remainderWallet.balance = data.remainderWallet.balance
|
|
5492
|
+
molecule.remainderWallet.balance = String(data.remainderWallet.balance != null ? data.remainderWallet.balance : 0);
|
|
4374
5493
|
molecule.remainderWallet.address = data.remainderWallet.address;
|
|
4375
5494
|
if (data.remainderWallet.pubkey) {
|
|
4376
5495
|
molecule.remainderWallet.pubkey = data.remainderWallet.pubkey;
|
|
@@ -4391,245 +5510,208 @@ var Molecule = class _Molecule {
|
|
|
4391
5510
|
static jsonToObject(json) {
|
|
4392
5511
|
return _Molecule.fromJSON(json);
|
|
4393
5512
|
}
|
|
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
|
-
}
|
|
5513
|
+
// =============================================================================
|
|
5514
|
+
// ISOTOPE INIT METHODS - MATCHING JAVASCRIPT SDK PARITY
|
|
5515
|
+
// =============================================================================
|
|
4404
5516
|
/**
|
|
4405
|
-
*
|
|
4406
|
-
*
|
|
4407
|
-
*
|
|
5517
|
+
* Initialize a P-type molecule for peer registration
|
|
5518
|
+
* Matches JavaScript SDK Molecule.initPeering implementation exactly
|
|
5519
|
+
*
|
|
5520
|
+
* @param host - The peer host URL to register
|
|
5521
|
+
* @return This molecule instance for chaining
|
|
4408
5522
|
*/
|
|
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
|
-
}
|
|
5523
|
+
initPeering({ host }) {
|
|
5524
|
+
if (!this.sourceWallet) {
|
|
5525
|
+
throw new Error("Source wallet required for peer registration");
|
|
4422
5526
|
}
|
|
5527
|
+
this.addAtom(Atom.create({
|
|
5528
|
+
isotope: "P",
|
|
5529
|
+
wallet: this.sourceWallet,
|
|
5530
|
+
metaType: "walletBundle",
|
|
5531
|
+
metaId: this.bundle,
|
|
5532
|
+
meta: new AtomMeta({ peerHost: host })
|
|
5533
|
+
}));
|
|
5534
|
+
this.addContinuIdAtom();
|
|
4423
5535
|
return this;
|
|
4424
5536
|
}
|
|
4425
5537
|
/**
|
|
4426
|
-
*
|
|
4427
|
-
*
|
|
4428
|
-
*
|
|
5538
|
+
* Initialize an A-type molecule for an append request
|
|
5539
|
+
* Matches JavaScript SDK Molecule.initAppendRequest implementation exactly
|
|
5540
|
+
*
|
|
5541
|
+
* @param metaType - The target MetaType to append to
|
|
5542
|
+
* @param metaId - The target MetaId to append to
|
|
5543
|
+
* @param action - The action to perform
|
|
5544
|
+
* @param meta - Additional metadata
|
|
5545
|
+
* @return This molecule instance for chaining
|
|
4429
5546
|
*/
|
|
4430
|
-
|
|
5547
|
+
initAppendRequest({
|
|
5548
|
+
metaType,
|
|
5549
|
+
metaId,
|
|
5550
|
+
action,
|
|
5551
|
+
meta = {}
|
|
5552
|
+
}) {
|
|
5553
|
+
if (!this.sourceWallet) {
|
|
5554
|
+
throw new Error("Source wallet required for append request");
|
|
5555
|
+
}
|
|
5556
|
+
this.addAtom(Atom.create({
|
|
5557
|
+
isotope: "A",
|
|
5558
|
+
wallet: this.sourceWallet,
|
|
5559
|
+
metaType,
|
|
5560
|
+
metaId,
|
|
5561
|
+
meta: new AtomMeta({ action, ...meta })
|
|
5562
|
+
}));
|
|
5563
|
+
this.addContinuIdAtom();
|
|
4431
5564
|
return this;
|
|
4432
5565
|
}
|
|
4433
5566
|
/**
|
|
4434
|
-
*
|
|
4435
|
-
*
|
|
4436
|
-
*
|
|
5567
|
+
* Initialize a deposit buffer operation (B-isotope)
|
|
5568
|
+
* Matches JavaScript SDK Molecule.initDepositBuffer implementation exactly
|
|
5569
|
+
*
|
|
5570
|
+
* @param amount - Amount to deposit into buffer
|
|
5571
|
+
* @param tradeRates - Trade rates for the buffer wallet
|
|
5572
|
+
* @return This molecule instance for chaining
|
|
4437
5573
|
*/
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
walletMeta.tokenUnits = JSON.stringify(wallet.getTokenUnitsData ? wallet.getTokenUnitsData() : wallet.tokenUnits);
|
|
5574
|
+
initDepositBuffer({
|
|
5575
|
+
amount,
|
|
5576
|
+
tradeRates
|
|
5577
|
+
}) {
|
|
5578
|
+
if (!this.sourceWallet) {
|
|
5579
|
+
throw new Error("Source wallet required for buffer deposit");
|
|
4445
5580
|
}
|
|
4446
|
-
if (
|
|
4447
|
-
|
|
5581
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
5582
|
+
throw new BalanceInsufficientException();
|
|
4448
5583
|
}
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
* Used for shadow wallet claim & wallet creation & token creation
|
|
4455
|
-
* @param wallet - Wallet with full metadata
|
|
4456
|
-
* @return This instance for chaining
|
|
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)
|
|
5584
|
+
const bufferWallet = Wallet.create({
|
|
5585
|
+
secret: this.secret,
|
|
5586
|
+
bundle: this.bundle,
|
|
5587
|
+
token: this.sourceWallet.token,
|
|
5588
|
+
batchId: this.sourceWallet.batchId
|
|
4505
5589
|
});
|
|
5590
|
+
if (tradeRates) {
|
|
5591
|
+
bufferWallet.tradeRates = tradeRates;
|
|
5592
|
+
}
|
|
5593
|
+
this.addAtom(Atom.create({
|
|
5594
|
+
isotope: "V",
|
|
5595
|
+
wallet: this.sourceWallet,
|
|
5596
|
+
value: -Number(this.sourceWallet.balance)
|
|
5597
|
+
}));
|
|
5598
|
+
this.addAtom(Atom.create({
|
|
5599
|
+
isotope: "B",
|
|
5600
|
+
wallet: bufferWallet,
|
|
5601
|
+
value: amount,
|
|
5602
|
+
metaType: "walletBundle",
|
|
5603
|
+
metaId: this.sourceWallet.bundle
|
|
5604
|
+
}));
|
|
5605
|
+
this.addAtom(Atom.create({
|
|
5606
|
+
isotope: "V",
|
|
5607
|
+
wallet: this.remainderWallet,
|
|
5608
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
5609
|
+
metaType: "walletBundle",
|
|
5610
|
+
metaId: this.sourceWallet.bundle
|
|
5611
|
+
}));
|
|
4506
5612
|
return this;
|
|
4507
5613
|
}
|
|
4508
5614
|
/**
|
|
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
|
|
4550
|
-
*/
|
|
4551
|
-
remove(key) {
|
|
4552
|
-
this.meta = Meta.removeMeta(this.meta, key);
|
|
4553
|
-
return this;
|
|
4554
|
-
}
|
|
4555
|
-
/**
|
|
4556
|
-
* Clear all metadata
|
|
4557
|
-
* @return This instance for chaining
|
|
5615
|
+
* Initialize a withdraw buffer operation (B-isotope)
|
|
5616
|
+
* Matches JavaScript SDK Molecule.initWithdrawBuffer implementation exactly
|
|
5617
|
+
*
|
|
5618
|
+
* @param recipients - Map of recipientBundle → amount
|
|
5619
|
+
* @param signingWallet - Optional signing wallet for reconciliation
|
|
5620
|
+
* @return This molecule instance for chaining
|
|
4558
5621
|
*/
|
|
4559
|
-
|
|
4560
|
-
|
|
5622
|
+
initWithdrawBuffer({
|
|
5623
|
+
recipients,
|
|
5624
|
+
signingWallet = null
|
|
5625
|
+
}) {
|
|
5626
|
+
if (!this.sourceWallet) {
|
|
5627
|
+
throw new Error("Source wallet required for buffer withdrawal");
|
|
5628
|
+
}
|
|
5629
|
+
let amount = 0;
|
|
5630
|
+
for (const recipientAmount of Object.values(recipients || {})) {
|
|
5631
|
+
amount += recipientAmount;
|
|
5632
|
+
}
|
|
5633
|
+
if (Number(this.sourceWallet.balance) - amount < 0) {
|
|
5634
|
+
throw new BalanceInsufficientException();
|
|
5635
|
+
}
|
|
5636
|
+
const firstAtomMeta = new AtomMeta();
|
|
5637
|
+
if (signingWallet) {
|
|
5638
|
+
firstAtomMeta.setSigningWallet(signingWallet);
|
|
5639
|
+
}
|
|
5640
|
+
this.addAtom(Atom.create({
|
|
5641
|
+
isotope: "B",
|
|
5642
|
+
wallet: this.sourceWallet,
|
|
5643
|
+
value: -Number(this.sourceWallet.balance),
|
|
5644
|
+
meta: firstAtomMeta,
|
|
5645
|
+
metaType: "walletBundle",
|
|
5646
|
+
metaId: this.sourceWallet.bundle
|
|
5647
|
+
}));
|
|
5648
|
+
for (const [recipientBundle, recipientAmount] of Object.entries(recipients || {})) {
|
|
5649
|
+
this.addAtom(new Atom({
|
|
5650
|
+
isotope: "V",
|
|
5651
|
+
token: this.sourceWallet.token,
|
|
5652
|
+
value: recipientAmount,
|
|
5653
|
+
batchId: this.sourceWallet.batchId ? generateBatchId({}) : null,
|
|
5654
|
+
metaType: "walletBundle",
|
|
5655
|
+
metaId: recipientBundle
|
|
5656
|
+
}));
|
|
5657
|
+
}
|
|
5658
|
+
this.addAtom(Atom.create({
|
|
5659
|
+
isotope: "B",
|
|
5660
|
+
wallet: this.remainderWallet,
|
|
5661
|
+
value: Number(this.sourceWallet.balance) - amount,
|
|
5662
|
+
metaType: "walletBundle",
|
|
5663
|
+
metaId: this.remainderWallet.bundle
|
|
5664
|
+
}));
|
|
4561
5665
|
return this;
|
|
4562
5666
|
}
|
|
4563
5667
|
/**
|
|
4564
|
-
*
|
|
4565
|
-
*
|
|
5668
|
+
* Initialize shadow wallet claim
|
|
5669
|
+
* Matches JavaScript SDK Molecule.initShadowWalletClaim implementation exactly
|
|
5670
|
+
*
|
|
5671
|
+
* @param wallet - The shadow wallet to claim
|
|
5672
|
+
* @return This molecule instance for chaining
|
|
4566
5673
|
*/
|
|
4567
|
-
|
|
4568
|
-
|
|
5674
|
+
initShadowWalletClaim(wallet) {
|
|
5675
|
+
const atomMeta = new AtomMeta();
|
|
5676
|
+
atomMeta.setShadowWalletClaim(true);
|
|
5677
|
+
return this.initWalletCreation(wallet, atomMeta);
|
|
4569
5678
|
}
|
|
4570
5679
|
/**
|
|
4571
|
-
*
|
|
4572
|
-
*
|
|
5680
|
+
* Initialize identifier creation
|
|
5681
|
+
* Matches JavaScript SDK Molecule.initIdentifierCreation implementation exactly
|
|
5682
|
+
*
|
|
5683
|
+
* @param type - Identifier type (phone or email)
|
|
5684
|
+
* @param contact - Phone number or email string
|
|
5685
|
+
* @param code - Verification code
|
|
5686
|
+
* @return This molecule instance for chaining
|
|
4573
5687
|
*/
|
|
4574
|
-
|
|
4575
|
-
|
|
5688
|
+
initIdentifierCreation({
|
|
5689
|
+
type,
|
|
5690
|
+
contact,
|
|
5691
|
+
code
|
|
5692
|
+
}) {
|
|
5693
|
+
if (!this.sourceWallet) {
|
|
5694
|
+
throw new Error("Source wallet required for identifier creation");
|
|
5695
|
+
}
|
|
5696
|
+
const meta = {
|
|
5697
|
+
code,
|
|
5698
|
+
hash: generateBundleHash(contact.trim(), "Molecule::initIdentifierCreation")
|
|
5699
|
+
};
|
|
5700
|
+
this.addAtom(Atom.create({
|
|
5701
|
+
isotope: "C",
|
|
5702
|
+
wallet: this.sourceWallet,
|
|
5703
|
+
metaType: "identifier",
|
|
5704
|
+
metaId: type,
|
|
5705
|
+
meta: new AtomMeta(meta)
|
|
5706
|
+
}));
|
|
5707
|
+
this.addContinuIdAtom();
|
|
5708
|
+
return this;
|
|
4576
5709
|
}
|
|
4577
5710
|
};
|
|
4578
5711
|
|
|
4579
5712
|
// src/index.ts
|
|
4580
5713
|
init_Dot();
|
|
4581
5714
|
|
|
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
5715
|
// src/libraries/Decimal.ts
|
|
4634
5716
|
var MULTIPLIER = 10 ** 18;
|
|
4635
5717
|
var Decimal = class _Decimal {
|
|
@@ -4841,6 +5923,129 @@ var GraphQLClient = class {
|
|
|
4841
5923
|
}
|
|
4842
5924
|
};
|
|
4843
5925
|
|
|
5926
|
+
// src/AuthToken.ts
|
|
5927
|
+
var AuthToken = class _AuthToken {
|
|
5928
|
+
$__token;
|
|
5929
|
+
$__expiresAt;
|
|
5930
|
+
$__pubkey;
|
|
5931
|
+
$__encrypt;
|
|
5932
|
+
$__wallet;
|
|
5933
|
+
/**
|
|
5934
|
+
* Create new AuthToken instance
|
|
5935
|
+
*/
|
|
5936
|
+
constructor({
|
|
5937
|
+
token,
|
|
5938
|
+
expiresAt,
|
|
5939
|
+
encrypt,
|
|
5940
|
+
pubkey
|
|
5941
|
+
}) {
|
|
5942
|
+
this.$__token = token;
|
|
5943
|
+
this.$__expiresAt = expiresAt;
|
|
5944
|
+
this.$__pubkey = pubkey;
|
|
5945
|
+
this.$__encrypt = encrypt;
|
|
5946
|
+
}
|
|
5947
|
+
/**
|
|
5948
|
+
* Static factory method to create AuthToken with wallet
|
|
5949
|
+
*/
|
|
5950
|
+
static create(data, wallet) {
|
|
5951
|
+
const authToken = new _AuthToken(data);
|
|
5952
|
+
authToken.setWallet(wallet);
|
|
5953
|
+
return authToken;
|
|
5954
|
+
}
|
|
5955
|
+
/**
|
|
5956
|
+
* Restore AuthToken from snapshot
|
|
5957
|
+
*/
|
|
5958
|
+
static restore(snapshot, secret) {
|
|
5959
|
+
const wallet = new Wallet({
|
|
5960
|
+
secret,
|
|
5961
|
+
token: "AUTH",
|
|
5962
|
+
position: snapshot.wallet.position,
|
|
5963
|
+
characters: snapshot.wallet.characters
|
|
5964
|
+
});
|
|
5965
|
+
return _AuthToken.create({
|
|
5966
|
+
token: snapshot.token,
|
|
5967
|
+
expiresAt: snapshot.expiresAt,
|
|
5968
|
+
pubkey: snapshot.pubkey,
|
|
5969
|
+
encrypt: snapshot.encrypt
|
|
5970
|
+
}, wallet);
|
|
5971
|
+
}
|
|
5972
|
+
/**
|
|
5973
|
+
* Set wallet for this auth token
|
|
5974
|
+
*/
|
|
5975
|
+
setWallet(wallet) {
|
|
5976
|
+
this.$__wallet = wallet;
|
|
5977
|
+
}
|
|
5978
|
+
/**
|
|
5979
|
+
* Get wallet
|
|
5980
|
+
*/
|
|
5981
|
+
getWallet() {
|
|
5982
|
+
return this.$__wallet;
|
|
5983
|
+
}
|
|
5984
|
+
/**
|
|
5985
|
+
* Get auth token
|
|
5986
|
+
*/
|
|
5987
|
+
getToken() {
|
|
5988
|
+
return this.$__token;
|
|
5989
|
+
}
|
|
5990
|
+
/**
|
|
5991
|
+
* Get expiration timestamp
|
|
5992
|
+
*/
|
|
5993
|
+
getExpiresAt() {
|
|
5994
|
+
return this.$__expiresAt;
|
|
5995
|
+
}
|
|
5996
|
+
/**
|
|
5997
|
+
* Get public key
|
|
5998
|
+
*/
|
|
5999
|
+
getPubkey() {
|
|
6000
|
+
return this.$__pubkey;
|
|
6001
|
+
}
|
|
6002
|
+
/**
|
|
6003
|
+
* Check if encryption is enabled
|
|
6004
|
+
*/
|
|
6005
|
+
isEncrypted() {
|
|
6006
|
+
return this.$__encrypt;
|
|
6007
|
+
}
|
|
6008
|
+
/**
|
|
6009
|
+
* Get expire interval in milliseconds (matching JS SDK pattern)
|
|
6010
|
+
*/
|
|
6011
|
+
getExpireInterval() {
|
|
6012
|
+
return this.$__expiresAt * 1e3 - Date.now();
|
|
6013
|
+
}
|
|
6014
|
+
/**
|
|
6015
|
+
* Check if token is expired
|
|
6016
|
+
*/
|
|
6017
|
+
isExpired() {
|
|
6018
|
+
return !this.$__expiresAt || this.getExpireInterval() < 0;
|
|
6019
|
+
}
|
|
6020
|
+
/**
|
|
6021
|
+
* Get auth data for GraphQL client
|
|
6022
|
+
*/
|
|
6023
|
+
getAuthData() {
|
|
6024
|
+
return {
|
|
6025
|
+
token: this.$__token,
|
|
6026
|
+
pubkey: this.$__pubkey,
|
|
6027
|
+
wallet: this.$__wallet
|
|
6028
|
+
};
|
|
6029
|
+
}
|
|
6030
|
+
/**
|
|
6031
|
+
* Create snapshot for persistence
|
|
6032
|
+
*/
|
|
6033
|
+
toSnapshot() {
|
|
6034
|
+
return {
|
|
6035
|
+
token: this.$__token,
|
|
6036
|
+
expiresAt: this.$__expiresAt,
|
|
6037
|
+
pubkey: this.$__pubkey,
|
|
6038
|
+
encrypt: this.$__encrypt,
|
|
6039
|
+
...this.$__wallet ? {
|
|
6040
|
+
wallet: {
|
|
6041
|
+
position: this.$__wallet.position,
|
|
6042
|
+
characters: this.$__wallet.characters
|
|
6043
|
+
}
|
|
6044
|
+
} : {}
|
|
6045
|
+
};
|
|
6046
|
+
}
|
|
6047
|
+
};
|
|
6048
|
+
|
|
4844
6049
|
// src/query/Query.ts
|
|
4845
6050
|
init_exception();
|
|
4846
6051
|
var Query = class {
|
|
@@ -5004,36 +6209,36 @@ var Mutation = class extends Query {
|
|
|
5004
6209
|
function createBrandedSchema(name, baseSchema = zod.z.string()) {
|
|
5005
6210
|
return baseSchema.brand(name);
|
|
5006
6211
|
}
|
|
5007
|
-
var
|
|
6212
|
+
var WalletAddressSchema2 = createBrandedSchema(
|
|
5008
6213
|
"WalletAddress",
|
|
5009
6214
|
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid wallet address format")
|
|
5010
6215
|
);
|
|
5011
|
-
var
|
|
6216
|
+
var BundleHashSchema2 = createBrandedSchema(
|
|
5012
6217
|
"BundleHash",
|
|
5013
6218
|
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid bundle hash format")
|
|
5014
6219
|
);
|
|
5015
|
-
var
|
|
6220
|
+
var PositionSchema2 = createBrandedSchema(
|
|
5016
6221
|
"Position",
|
|
5017
6222
|
zod.z.string().regex(/^[0-9a-fA-F]{64}$/, "Invalid position format")
|
|
5018
6223
|
);
|
|
5019
|
-
var
|
|
6224
|
+
var MolecularHashSchema2 = createBrandedSchema(
|
|
5020
6225
|
"MolecularHash",
|
|
5021
6226
|
zod.z.string().regex(/^[0-9a-g]+$/, "Invalid molecular hash format (base17)")
|
|
5022
6227
|
);
|
|
5023
|
-
var
|
|
6228
|
+
var TokenSlugSchema2 = createBrandedSchema(
|
|
5024
6229
|
"TokenSlug",
|
|
5025
6230
|
zod.z.string().min(1).max(32).regex(/^[A-Z0-9_]+$/, "Token slug must be uppercase alphanumeric")
|
|
5026
6231
|
);
|
|
5027
|
-
var
|
|
6232
|
+
var BatchIdSchema2 = createBrandedSchema(
|
|
5028
6233
|
"BatchId",
|
|
5029
6234
|
zod.z.string().uuid("Invalid batch ID format")
|
|
5030
6235
|
);
|
|
5031
|
-
var
|
|
6236
|
+
var CellSlugSchema2 = createBrandedSchema(
|
|
5032
6237
|
"CellSlug",
|
|
5033
6238
|
zod.z.string().min(1).max(64).regex(/^[a-zA-Z0-9\-_.]+$/, "Invalid cell slug format")
|
|
5034
6239
|
);
|
|
5035
6240
|
var ISOTOPES2 = ["C", "V", "U", "T", "M", "I", "R", "B", "F"];
|
|
5036
|
-
var
|
|
6241
|
+
var AtomIsotopeSchema2 = zod.z.enum(ISOTOPES2);
|
|
5037
6242
|
zod.z.object({
|
|
5038
6243
|
isotope: zod.z.literal("V"),
|
|
5039
6244
|
value: zod.z.union([zod.z.string(), zod.z.number()]).refine(
|
|
@@ -5053,17 +6258,17 @@ zod.z.object({
|
|
|
5053
6258
|
zod.z.object({
|
|
5054
6259
|
isotope: zod.z.literal("C")
|
|
5055
6260
|
}).strict();
|
|
5056
|
-
var
|
|
6261
|
+
var MetaDataSchema2 = zod.z.lazy(
|
|
5057
6262
|
() => zod.z.union([
|
|
5058
6263
|
zod.z.string(),
|
|
5059
6264
|
zod.z.number(),
|
|
5060
6265
|
zod.z.boolean(),
|
|
5061
6266
|
zod.z.null(),
|
|
5062
|
-
zod.z.record(zod.z.string(),
|
|
5063
|
-
zod.z.array(
|
|
6267
|
+
zod.z.record(zod.z.string(), MetaDataSchema2),
|
|
6268
|
+
zod.z.array(MetaDataSchema2)
|
|
5064
6269
|
])
|
|
5065
6270
|
);
|
|
5066
|
-
var
|
|
6271
|
+
var AtomMetaDataSchema2 = zod.z.object({
|
|
5067
6272
|
key: zod.z.string().min(1),
|
|
5068
6273
|
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()])
|
|
5069
6274
|
}).strict();
|
|
@@ -5071,44 +6276,44 @@ zod.z.object({
|
|
|
5071
6276
|
key: zod.z.string(),
|
|
5072
6277
|
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()])
|
|
5073
6278
|
}).passthrough();
|
|
5074
|
-
var
|
|
6279
|
+
var AtomParamsSchema2 = zod.z.object({
|
|
5075
6280
|
position: zod.z.string().optional(),
|
|
5076
|
-
walletAddress: zod.z.union([
|
|
5077
|
-
isotope:
|
|
5078
|
-
token: zod.z.union([
|
|
6281
|
+
walletAddress: zod.z.union([WalletAddressSchema2, zod.z.string()]).optional(),
|
|
6282
|
+
isotope: AtomIsotopeSchema2.default("C"),
|
|
6283
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).default("USER"),
|
|
5079
6284
|
value: zod.z.union([zod.z.string(), zod.z.number(), zod.z.null()]).optional(),
|
|
5080
|
-
batchId: zod.z.union([
|
|
6285
|
+
batchId: zod.z.union([BatchIdSchema2, zod.z.string(), zod.z.null()]).optional(),
|
|
5081
6286
|
metaType: zod.z.string().optional(),
|
|
5082
6287
|
metaId: zod.z.string().optional(),
|
|
5083
|
-
meta: zod.z.array(
|
|
6288
|
+
meta: zod.z.array(AtomMetaDataSchema2).optional(),
|
|
5084
6289
|
otsFragment: zod.z.string().optional(),
|
|
5085
6290
|
index: zod.z.number().int().min(0).optional(),
|
|
5086
6291
|
createdAt: zod.z.string().optional(),
|
|
5087
6292
|
version: zod.z.number().int().min(1).optional()
|
|
5088
6293
|
}).strict();
|
|
5089
|
-
var
|
|
6294
|
+
var WalletParamsSchema2 = zod.z.object({
|
|
5090
6295
|
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([
|
|
6296
|
+
bundle: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6297
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).default("USER"),
|
|
6298
|
+
address: zod.z.union([WalletAddressSchema2, zod.z.string()]).optional(),
|
|
6299
|
+
position: zod.z.union([PositionSchema2, zod.z.string()]).optional(),
|
|
6300
|
+
batchId: zod.z.union([BatchIdSchema2, zod.z.string()]).optional(),
|
|
5096
6301
|
characters: zod.z.string().optional()
|
|
5097
6302
|
}).strict();
|
|
5098
|
-
var
|
|
6303
|
+
var MoleculeParamsSchema2 = zod.z.object({
|
|
5099
6304
|
secret: zod.z.string().optional(),
|
|
5100
|
-
bundle: zod.z.union([
|
|
5101
|
-
sourceWallet:
|
|
5102
|
-
remainderWallet:
|
|
5103
|
-
cellSlug: zod.z.union([
|
|
6305
|
+
bundle: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6306
|
+
sourceWallet: WalletParamsSchema2.optional(),
|
|
6307
|
+
remainderWallet: WalletParamsSchema2.optional(),
|
|
6308
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional(),
|
|
5104
6309
|
version: zod.z.number().int().min(1).optional()
|
|
5105
6310
|
}).strict();
|
|
5106
|
-
var
|
|
6311
|
+
var KnishIOClientConfigSchema2 = zod.z.object({
|
|
5107
6312
|
uri: zod.z.union([
|
|
5108
6313
|
zod.z.string().url("Invalid URI format"),
|
|
5109
6314
|
zod.z.array(zod.z.string().url("Invalid URI format")).min(1)
|
|
5110
6315
|
]).optional(),
|
|
5111
|
-
cellSlug: zod.z.union([
|
|
6316
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional(),
|
|
5112
6317
|
client: zod.z.unknown().optional(),
|
|
5113
6318
|
socket: zod.z.unknown().optional(),
|
|
5114
6319
|
serverSdkVersion: zod.z.number().int().min(1).max(10).default(4),
|
|
@@ -5121,48 +6326,48 @@ var EnvironmentConfigSchema = zod.z.object({
|
|
|
5121
6326
|
KNISHIO_LOGGING: zod.z.string().transform((val) => val === "true").default("false"),
|
|
5122
6327
|
KNISHIO_SERVER_SDK_VERSION: zod.z.string().transform((val) => parseInt(val, 10)).default("4")
|
|
5123
6328
|
}).partial();
|
|
5124
|
-
var
|
|
5125
|
-
recipient: zod.z.union([
|
|
6329
|
+
var TransferParamsSchema2 = zod.z.object({
|
|
6330
|
+
recipient: zod.z.union([WalletAddressSchema2, zod.z.string()]),
|
|
5126
6331
|
amount: zod.z.union([zod.z.number(), zod.z.string()]).refine(
|
|
5127
6332
|
(val) => Number(val) > 0,
|
|
5128
6333
|
"Amount must be positive"
|
|
5129
6334
|
),
|
|
5130
|
-
token: zod.z.union([
|
|
6335
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5131
6336
|
callbackUrl: zod.z.string().url().optional(),
|
|
5132
6337
|
metaType: zod.z.string().optional(),
|
|
5133
6338
|
metaId: zod.z.string().optional(),
|
|
5134
|
-
meta:
|
|
6339
|
+
meta: MetaDataSchema2.optional()
|
|
5135
6340
|
}).strict();
|
|
5136
|
-
var
|
|
5137
|
-
token: zod.z.union([
|
|
6341
|
+
var CreateTokenParamsSchema2 = zod.z.object({
|
|
6342
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]),
|
|
5138
6343
|
amount: zod.z.union([zod.z.number(), zod.z.string()]).refine(
|
|
5139
6344
|
(val) => Number(val) > 0,
|
|
5140
6345
|
"Amount must be positive"
|
|
5141
6346
|
),
|
|
5142
6347
|
metaType: zod.z.string().optional(),
|
|
5143
6348
|
metaId: zod.z.string().optional(),
|
|
5144
|
-
meta:
|
|
6349
|
+
meta: MetaDataSchema2.optional(),
|
|
5145
6350
|
fungible: zod.z.boolean().default(true),
|
|
5146
6351
|
splittable: zod.z.number().int().min(0).optional(),
|
|
5147
|
-
supplyToken: zod.z.union([
|
|
6352
|
+
supplyToken: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional()
|
|
5148
6353
|
}).strict();
|
|
5149
|
-
var
|
|
6354
|
+
var RequestTokensParamsSchema2 = zod.z.object({
|
|
5150
6355
|
amount: zod.z.union([zod.z.number(), zod.z.string()]).refine(
|
|
5151
6356
|
(val) => Number(val) > 0,
|
|
5152
6357
|
"Amount must be positive"
|
|
5153
6358
|
),
|
|
5154
|
-
token: zod.z.union([
|
|
6359
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5155
6360
|
metaType: zod.z.string().optional(),
|
|
5156
6361
|
metaId: zod.z.string().optional(),
|
|
5157
|
-
meta:
|
|
6362
|
+
meta: MetaDataSchema2.optional()
|
|
5158
6363
|
}).strict();
|
|
5159
|
-
var
|
|
5160
|
-
address: zod.z.union([
|
|
5161
|
-
bundleHash: zod.z.union([
|
|
5162
|
-
token: zod.z.union([
|
|
6364
|
+
var BalanceQueryParamsSchema2 = zod.z.object({
|
|
6365
|
+
address: zod.z.union([WalletAddressSchema2, zod.z.string()]).optional(),
|
|
6366
|
+
bundleHash: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6367
|
+
token: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5163
6368
|
type: zod.z.enum(["token", "user"]).optional()
|
|
5164
6369
|
}).strict();
|
|
5165
|
-
var
|
|
6370
|
+
var MetaQueryParamsSchema2 = zod.z.object({
|
|
5166
6371
|
metaType: zod.z.string().min(1),
|
|
5167
6372
|
metaId: zod.z.string().optional(),
|
|
5168
6373
|
key: zod.z.string().optional(),
|
|
@@ -5172,33 +6377,33 @@ var MetaQueryParamsSchema = zod.z.object({
|
|
|
5172
6377
|
queryArgs: zod.z.record(zod.z.unknown()).optional(),
|
|
5173
6378
|
count: zod.z.number().int().min(0).optional(),
|
|
5174
6379
|
countBy: zod.z.string().optional(),
|
|
5175
|
-
cellSlug: zod.z.union([
|
|
6380
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional()
|
|
5176
6381
|
}).strict();
|
|
5177
|
-
var
|
|
5178
|
-
bundleHash: zod.z.union([
|
|
5179
|
-
tokenSlug: zod.z.union([
|
|
6382
|
+
var WalletQueryParamsSchema2 = zod.z.object({
|
|
6383
|
+
bundleHash: zod.z.union([BundleHashSchema2, zod.z.string()]).optional(),
|
|
6384
|
+
tokenSlug: zod.z.union([TokenSlugSchema2, zod.z.string()]).optional(),
|
|
5180
6385
|
unspent: zod.z.boolean().optional()
|
|
5181
6386
|
}).strict();
|
|
5182
|
-
var
|
|
6387
|
+
var AuthTokenParamsSchema2 = zod.z.object({
|
|
5183
6388
|
token: zod.z.string().min(1),
|
|
5184
6389
|
expiresAt: zod.z.number().int().min(0),
|
|
5185
6390
|
encrypt: zod.z.boolean(),
|
|
5186
6391
|
pubkey: zod.z.string().min(1)
|
|
5187
6392
|
}).strict();
|
|
5188
|
-
var
|
|
5189
|
-
cellSlug: zod.z.union([
|
|
6393
|
+
var AuthParamsSchema2 = zod.z.object({
|
|
6394
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional(),
|
|
5190
6395
|
encrypt: zod.z.boolean().optional(),
|
|
5191
6396
|
callback: zod.z.function().optional()
|
|
5192
6397
|
}).strict();
|
|
5193
|
-
var
|
|
5194
|
-
cellSlug: zod.z.union([
|
|
6398
|
+
var GuestAuthParamsSchema2 = zod.z.object({
|
|
6399
|
+
cellSlug: zod.z.union([CellSlugSchema2, zod.z.string()]).optional()
|
|
5195
6400
|
}).strict();
|
|
5196
|
-
var
|
|
6401
|
+
var GraphQLRequestSchema2 = zod.z.object({
|
|
5197
6402
|
query: zod.z.string().min(1),
|
|
5198
6403
|
variables: zod.z.record(zod.z.unknown()).optional(),
|
|
5199
6404
|
operationName: zod.z.string().optional()
|
|
5200
6405
|
}).strict();
|
|
5201
|
-
var
|
|
6406
|
+
var GraphQLErrorSchema2 = zod.z.object({
|
|
5202
6407
|
message: zod.z.string(),
|
|
5203
6408
|
locations: zod.z.array(zod.z.object({
|
|
5204
6409
|
line: zod.z.number().int(),
|
|
@@ -5207,9 +6412,9 @@ var GraphQLErrorSchema = zod.z.object({
|
|
|
5207
6412
|
path: zod.z.array(zod.z.union([zod.z.string(), zod.z.number()])).optional(),
|
|
5208
6413
|
extensions: zod.z.record(zod.z.unknown()).optional()
|
|
5209
6414
|
}).strict();
|
|
5210
|
-
var
|
|
6415
|
+
var GraphQLResponseSchema2 = zod.z.object({
|
|
5211
6416
|
data: zod.z.unknown().optional(),
|
|
5212
|
-
errors: zod.z.array(
|
|
6417
|
+
errors: zod.z.array(GraphQLErrorSchema2).optional(),
|
|
5213
6418
|
extensions: zod.z.record(zod.z.unknown()).optional()
|
|
5214
6419
|
}).strict();
|
|
5215
6420
|
function safeParse(schema, data) {
|
|
@@ -5236,35 +6441,35 @@ function createTypeGuard(schema) {
|
|
|
5236
6441
|
}
|
|
5237
6442
|
var Schemas = {
|
|
5238
6443
|
// Core types
|
|
5239
|
-
WalletAddress:
|
|
5240
|
-
BundleHash:
|
|
5241
|
-
Position:
|
|
5242
|
-
MolecularHash:
|
|
5243
|
-
TokenSlug:
|
|
5244
|
-
BatchId:
|
|
5245
|
-
CellSlug:
|
|
6444
|
+
WalletAddress: WalletAddressSchema2,
|
|
6445
|
+
BundleHash: BundleHashSchema2,
|
|
6446
|
+
Position: PositionSchema2,
|
|
6447
|
+
MolecularHash: MolecularHashSchema2,
|
|
6448
|
+
TokenSlug: TokenSlugSchema2,
|
|
6449
|
+
BatchId: BatchIdSchema2,
|
|
6450
|
+
CellSlug: CellSlugSchema2,
|
|
5246
6451
|
// Entities
|
|
5247
|
-
AtomParams:
|
|
5248
|
-
WalletParams:
|
|
5249
|
-
MoleculeParams:
|
|
6452
|
+
AtomParams: AtomParamsSchema2,
|
|
6453
|
+
WalletParams: WalletParamsSchema2,
|
|
6454
|
+
MoleculeParams: MoleculeParamsSchema2,
|
|
5250
6455
|
// Configuration
|
|
5251
|
-
ClientConfig:
|
|
6456
|
+
ClientConfig: KnishIOClientConfigSchema2,
|
|
5252
6457
|
EnvironmentConfig: EnvironmentConfigSchema,
|
|
5253
6458
|
// Operations
|
|
5254
|
-
TransferParams:
|
|
5255
|
-
CreateTokenParams:
|
|
5256
|
-
RequestTokensParams:
|
|
6459
|
+
TransferParams: TransferParamsSchema2,
|
|
6460
|
+
CreateTokenParams: CreateTokenParamsSchema2,
|
|
6461
|
+
RequestTokensParams: RequestTokensParamsSchema2,
|
|
5257
6462
|
// Queries
|
|
5258
|
-
BalanceQueryParams:
|
|
5259
|
-
MetaQueryParams:
|
|
5260
|
-
WalletQueryParams:
|
|
6463
|
+
BalanceQueryParams: BalanceQueryParamsSchema2,
|
|
6464
|
+
MetaQueryParams: MetaQueryParamsSchema2,
|
|
6465
|
+
WalletQueryParams: WalletQueryParamsSchema2,
|
|
5261
6466
|
// Auth
|
|
5262
|
-
AuthTokenParams:
|
|
5263
|
-
AuthParams:
|
|
5264
|
-
GuestAuthParams:
|
|
6467
|
+
AuthTokenParams: AuthTokenParamsSchema2,
|
|
6468
|
+
AuthParams: AuthParamsSchema2,
|
|
6469
|
+
GuestAuthParams: GuestAuthParamsSchema2,
|
|
5265
6470
|
// GraphQL
|
|
5266
|
-
GraphQLRequest:
|
|
5267
|
-
GraphQLResponse:
|
|
6471
|
+
GraphQLRequest: GraphQLRequestSchema2,
|
|
6472
|
+
GraphQLResponse: GraphQLResponseSchema2
|
|
5268
6473
|
};
|
|
5269
6474
|
|
|
5270
6475
|
// src/validation/ValidationService.ts
|
|
@@ -5943,7 +7148,8 @@ var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
|
5943
7148
|
* Matches JavaScript SDK payload() method exactly
|
|
5944
7149
|
*/
|
|
5945
7150
|
payload() {
|
|
5946
|
-
const
|
|
7151
|
+
const balanceData = this.data();
|
|
7152
|
+
const walletData = Array.isArray(balanceData) ? balanceData[0] : balanceData;
|
|
5947
7153
|
if (!walletData || !walletData.bundleHash || !walletData.tokenSlug) {
|
|
5948
7154
|
return null;
|
|
5949
7155
|
}
|
|
@@ -5961,7 +7167,7 @@ var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
|
5961
7167
|
secret = null
|
|
5962
7168
|
}) {
|
|
5963
7169
|
let wallet;
|
|
5964
|
-
if (data.position
|
|
7170
|
+
if (!data.position) {
|
|
5965
7171
|
wallet = Wallet.create({
|
|
5966
7172
|
bundle: data.bundleHash,
|
|
5967
7173
|
token: data.tokenSlug,
|
|
@@ -5990,7 +7196,7 @@ var ResponseBalance = class _ResponseBalance extends exports.Response {
|
|
|
5990
7196
|
wallet.tradeRates[tradeRate.tokenSlug] = tradeRate.amount;
|
|
5991
7197
|
}
|
|
5992
7198
|
}
|
|
5993
|
-
wallet.balance =
|
|
7199
|
+
wallet.balance = String(data.amount != null ? data.amount : 0);
|
|
5994
7200
|
wallet.pubkey = data.pubkey;
|
|
5995
7201
|
wallet.createdAt = data.createdAt;
|
|
5996
7202
|
return wallet;
|
|
@@ -6183,7 +7389,7 @@ var ResponseWalletList = class _ResponseWalletList extends exports.Response {
|
|
|
6183
7389
|
wallet.tradeRates[tradeRate.tokenSlug] = tradeRate.amount;
|
|
6184
7390
|
}
|
|
6185
7391
|
}
|
|
6186
|
-
wallet.balance =
|
|
7392
|
+
wallet.balance = String(data.amount != null ? data.amount : 0);
|
|
6187
7393
|
wallet.pubkey = data.pubkey;
|
|
6188
7394
|
wallet.createdAt = data.createdAt;
|
|
6189
7395
|
return wallet;
|
|
@@ -6221,8 +7427,8 @@ var QueryWalletList = class extends Query {
|
|
|
6221
7427
|
*/
|
|
6222
7428
|
constructor(graphQLClient, knishIOClient) {
|
|
6223
7429
|
super(graphQLClient, knishIOClient);
|
|
6224
|
-
this.$__query = core.gql`query( $bundleHash: String, $
|
|
6225
|
-
Wallet( bundleHash: $bundleHash,
|
|
7430
|
+
this.$__query = core.gql`query( $bundleHash: String, $token: String ) {
|
|
7431
|
+
Wallet( bundleHash: $bundleHash, token: $token ) {
|
|
6226
7432
|
address,
|
|
6227
7433
|
bundleHash,
|
|
6228
7434
|
token {
|
|
@@ -6364,7 +7570,7 @@ var ResponseContinuId = class extends exports.Response {
|
|
|
6364
7570
|
wallet.batchId = continuId.batchId;
|
|
6365
7571
|
wallet.characters = continuId.characters;
|
|
6366
7572
|
wallet.pubkey = continuId.pubkey;
|
|
6367
|
-
wallet.balance = continuId.amount
|
|
7573
|
+
wallet.balance = String(continuId.amount != null ? continuId.amount : 0);
|
|
6368
7574
|
}
|
|
6369
7575
|
return wallet;
|
|
6370
7576
|
}
|
|
@@ -6390,6 +7596,13 @@ var QueryContinuId = class extends Query {
|
|
|
6390
7596
|
}
|
|
6391
7597
|
}`;
|
|
6392
7598
|
}
|
|
7599
|
+
/**
|
|
7600
|
+
* Force network-only for ContinuID queries to prevent URQL cache from
|
|
7601
|
+
* returning stale wallet positions after mutations advance the ContinuID chain
|
|
7602
|
+
*/
|
|
7603
|
+
createQueryContext() {
|
|
7604
|
+
return { requestPolicy: "network-only" };
|
|
7605
|
+
}
|
|
6393
7606
|
/**
|
|
6394
7607
|
* Returns a Response object
|
|
6395
7608
|
* Matches JavaScript SDK createResponse method exactly
|
|
@@ -6419,31 +7632,40 @@ var ResponseMetaType = class extends exports.Response {
|
|
|
6419
7632
|
dataKey: "data.MetaType"
|
|
6420
7633
|
});
|
|
6421
7634
|
}
|
|
7635
|
+
/**
|
|
7636
|
+
* Extracts payload from metaData object
|
|
7637
|
+
*/
|
|
7638
|
+
extractPayload(metaData) {
|
|
7639
|
+
return {
|
|
7640
|
+
instances: metaData?.instances || [],
|
|
7641
|
+
instanceCount: metaData?.instanceCount || [],
|
|
7642
|
+
paginatorInfo: metaData?.paginatorInfo || {}
|
|
7643
|
+
};
|
|
7644
|
+
}
|
|
6422
7645
|
/**
|
|
6423
7646
|
* Returns meta type instance results
|
|
6424
|
-
*
|
|
7647
|
+
* Handles various response formats from server:
|
|
7648
|
+
* - Array of results (normal case)
|
|
7649
|
+
* - Single object (filtered queries)
|
|
7650
|
+
* - null/undefined (no results)
|
|
7651
|
+
* - Empty array (no matching data)
|
|
6425
7652
|
*/
|
|
6426
7653
|
payload() {
|
|
6427
7654
|
const metaTypeData = this.data();
|
|
6428
|
-
if (
|
|
7655
|
+
if (metaTypeData === null || metaTypeData === void 0) {
|
|
6429
7656
|
return null;
|
|
6430
7657
|
}
|
|
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;
|
|
6442
|
-
}
|
|
6443
|
-
if (metaData.paginatorInfo) {
|
|
6444
|
-
response.paginatorInfo = metaData.paginatorInfo;
|
|
7658
|
+
if (Array.isArray(metaTypeData)) {
|
|
7659
|
+
if (metaTypeData.length === 0) {
|
|
7660
|
+
return this.extractPayload(null);
|
|
7661
|
+
}
|
|
7662
|
+
const metaData = metaTypeData[metaTypeData.length - 1];
|
|
7663
|
+
return this.extractPayload(metaData);
|
|
6445
7664
|
}
|
|
6446
|
-
|
|
7665
|
+
if (typeof metaTypeData === "object") {
|
|
7666
|
+
return this.extractPayload(metaTypeData);
|
|
7667
|
+
}
|
|
7668
|
+
return null;
|
|
6447
7669
|
}
|
|
6448
7670
|
};
|
|
6449
7671
|
var QueryMetaType = class extends Query {
|
|
@@ -6911,10 +8133,9 @@ var ResponsePolicy = class extends exports.Response {
|
|
|
6911
8133
|
}) {
|
|
6912
8134
|
super({
|
|
6913
8135
|
query,
|
|
6914
|
-
json
|
|
8136
|
+
json,
|
|
8137
|
+
dataKey: "data.Policy"
|
|
6915
8138
|
});
|
|
6916
|
-
this.dataKey = "data.Policy";
|
|
6917
|
-
this.init();
|
|
6918
8139
|
}
|
|
6919
8140
|
/**
|
|
6920
8141
|
* Returns the policy payload
|
|
@@ -7017,7 +8238,6 @@ var QueryActiveSession = class extends Query {
|
|
|
7017
8238
|
metaId
|
|
7018
8239
|
jsonData
|
|
7019
8240
|
createdAt
|
|
7020
|
-
updatedAt
|
|
7021
8241
|
}
|
|
7022
8242
|
}
|
|
7023
8243
|
`;
|
|
@@ -7350,6 +8570,252 @@ var QueryMetaTypeViaAtom = class extends Query {
|
|
|
7350
8570
|
}
|
|
7351
8571
|
};
|
|
7352
8572
|
|
|
8573
|
+
// src/response/ResponseMetaTypeViaMolecule.ts
|
|
8574
|
+
init_Response();
|
|
8575
|
+
var ResponseMetaTypeViaMolecule = class _ResponseMetaTypeViaMolecule extends exports.Response {
|
|
8576
|
+
/**
|
|
8577
|
+
* Class constructor
|
|
8578
|
+
*/
|
|
8579
|
+
constructor({
|
|
8580
|
+
query,
|
|
8581
|
+
json
|
|
8582
|
+
}) {
|
|
8583
|
+
super({
|
|
8584
|
+
query,
|
|
8585
|
+
json,
|
|
8586
|
+
dataKey: "data.MetaTypeViaAtom"
|
|
8587
|
+
});
|
|
8588
|
+
}
|
|
8589
|
+
/**
|
|
8590
|
+
* Extracts metas from a molecule's atoms' metasJson for a specific instance.
|
|
8591
|
+
* Filters atoms by matching metaType and metaId, then parses metasJson.
|
|
8592
|
+
*/
|
|
8593
|
+
static extractMetasFromMolecule(molecule, metaType, metaId) {
|
|
8594
|
+
if (!molecule || !molecule.atoms) {
|
|
8595
|
+
return [];
|
|
8596
|
+
}
|
|
8597
|
+
const metas = [];
|
|
8598
|
+
for (const atom of molecule.atoms) {
|
|
8599
|
+
if (atom.metaType !== metaType || atom.metaId !== metaId) {
|
|
8600
|
+
continue;
|
|
8601
|
+
}
|
|
8602
|
+
if (!atom.metasJson) {
|
|
8603
|
+
continue;
|
|
8604
|
+
}
|
|
8605
|
+
let parsed;
|
|
8606
|
+
try {
|
|
8607
|
+
parsed = JSON.parse(atom.metasJson);
|
|
8608
|
+
if (!Array.isArray(parsed)) {
|
|
8609
|
+
continue;
|
|
8610
|
+
}
|
|
8611
|
+
} catch (e) {
|
|
8612
|
+
continue;
|
|
8613
|
+
}
|
|
8614
|
+
for (const entry of parsed) {
|
|
8615
|
+
metas.push({
|
|
8616
|
+
molecularHash: molecule.molecularHash,
|
|
8617
|
+
position: atom.position,
|
|
8618
|
+
key: entry.key,
|
|
8619
|
+
value: entry.value,
|
|
8620
|
+
createdAt: atom.createdAt
|
|
8621
|
+
});
|
|
8622
|
+
}
|
|
8623
|
+
}
|
|
8624
|
+
return metas;
|
|
8625
|
+
}
|
|
8626
|
+
/**
|
|
8627
|
+
* Returns meta type instance results with metas synthesized from molecule data.
|
|
8628
|
+
* Produces the same payload format as ResponseMetaType and ResponseMetaTypeViaAtom:
|
|
8629
|
+
* { instances, instanceCount, paginatorInfo }
|
|
8630
|
+
*/
|
|
8631
|
+
payload() {
|
|
8632
|
+
const metaTypeData = this.data();
|
|
8633
|
+
if (!metaTypeData || metaTypeData.length === 0) {
|
|
8634
|
+
return null;
|
|
8635
|
+
}
|
|
8636
|
+
const response = {
|
|
8637
|
+
instances: {},
|
|
8638
|
+
instanceCount: {},
|
|
8639
|
+
paginatorInfo: {}
|
|
8640
|
+
};
|
|
8641
|
+
const metaData = metaTypeData.pop();
|
|
8642
|
+
if (metaData.instances) {
|
|
8643
|
+
response.instances = metaData.instances.map((instance) => {
|
|
8644
|
+
let metas = instance.metas;
|
|
8645
|
+
if (!metas || metas.length === 0) {
|
|
8646
|
+
metas = _ResponseMetaTypeViaMolecule.extractMetasFromMolecule(
|
|
8647
|
+
instance.molecule,
|
|
8648
|
+
instance.metaType,
|
|
8649
|
+
instance.metaId
|
|
8650
|
+
);
|
|
8651
|
+
}
|
|
8652
|
+
return {
|
|
8653
|
+
...instance,
|
|
8654
|
+
metas
|
|
8655
|
+
};
|
|
8656
|
+
});
|
|
8657
|
+
}
|
|
8658
|
+
if (metaData.instanceCount) {
|
|
8659
|
+
response.instanceCount = metaData.instanceCount;
|
|
8660
|
+
}
|
|
8661
|
+
if (metaData.paginatorInfo) {
|
|
8662
|
+
response.paginatorInfo = metaData.paginatorInfo;
|
|
8663
|
+
}
|
|
8664
|
+
return response;
|
|
8665
|
+
}
|
|
8666
|
+
/**
|
|
8667
|
+
* Verifies the cryptographic integrity of all molecules associated
|
|
8668
|
+
* with meta instances in this response.
|
|
8669
|
+
*/
|
|
8670
|
+
verifyIntegrity() {
|
|
8671
|
+
const results = [];
|
|
8672
|
+
const metaTypeData = this.data();
|
|
8673
|
+
if (!metaTypeData || metaTypeData.length === 0) {
|
|
8674
|
+
return { verified: true, molecules: results };
|
|
8675
|
+
}
|
|
8676
|
+
const instances = metaTypeData[metaTypeData.length - 1]?.instances || [];
|
|
8677
|
+
for (const instance of instances) {
|
|
8678
|
+
if (!instance.molecule) continue;
|
|
8679
|
+
results.push(CheckMolecule.verifyFromServerData(instance.molecule));
|
|
8680
|
+
}
|
|
8681
|
+
return {
|
|
8682
|
+
verified: results.length === 0 || results.every((r) => r.verified),
|
|
8683
|
+
molecules: results
|
|
8684
|
+
};
|
|
8685
|
+
}
|
|
8686
|
+
};
|
|
8687
|
+
var QueryMetaTypeViaMolecule = class extends Query {
|
|
8688
|
+
/**
|
|
8689
|
+
* Create new QueryMetaTypeViaMolecule instance
|
|
8690
|
+
*/
|
|
8691
|
+
constructor(graphQLClient, knishIOClient) {
|
|
8692
|
+
super(graphQLClient, knishIOClient);
|
|
8693
|
+
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!] ) {
|
|
8694
|
+
MetaTypeViaAtom(
|
|
8695
|
+
metaTypes: $metaTypes
|
|
8696
|
+
metaIds: $metaIds
|
|
8697
|
+
atomValues: $atomValues
|
|
8698
|
+
cellSlugs: $cellSlugs
|
|
8699
|
+
filter: $filter,
|
|
8700
|
+
latest: $latest,
|
|
8701
|
+
queryArgs: $queryArgs
|
|
8702
|
+
countBy: $countBy
|
|
8703
|
+
) {
|
|
8704
|
+
metaType,
|
|
8705
|
+
instanceCount {
|
|
8706
|
+
key,
|
|
8707
|
+
value
|
|
8708
|
+
},
|
|
8709
|
+
instances {
|
|
8710
|
+
metaType,
|
|
8711
|
+
metaId,
|
|
8712
|
+
createdAt,
|
|
8713
|
+
metas( values: $values, keys: $keys ) {
|
|
8714
|
+
molecularHash,
|
|
8715
|
+
position,
|
|
8716
|
+
key,
|
|
8717
|
+
value,
|
|
8718
|
+
createdAt
|
|
8719
|
+
},
|
|
8720
|
+
molecule {
|
|
8721
|
+
molecularHash,
|
|
8722
|
+
bundleHash,
|
|
8723
|
+
cellSlug,
|
|
8724
|
+
status,
|
|
8725
|
+
createdAt,
|
|
8726
|
+
atoms {
|
|
8727
|
+
position,
|
|
8728
|
+
walletAddress,
|
|
8729
|
+
isotope,
|
|
8730
|
+
tokenSlug,
|
|
8731
|
+
value,
|
|
8732
|
+
batchId,
|
|
8733
|
+
metaType,
|
|
8734
|
+
metaId,
|
|
8735
|
+
index,
|
|
8736
|
+
createdAt,
|
|
8737
|
+
otsFragment,
|
|
8738
|
+
metasJson
|
|
8739
|
+
}
|
|
8740
|
+
}
|
|
8741
|
+
},
|
|
8742
|
+
paginatorInfo {
|
|
8743
|
+
currentPage,
|
|
8744
|
+
total
|
|
8745
|
+
}
|
|
8746
|
+
}
|
|
8747
|
+
}`;
|
|
8748
|
+
}
|
|
8749
|
+
/**
|
|
8750
|
+
* Builds a GraphQL-friendly variables object based on input fields
|
|
8751
|
+
*/
|
|
8752
|
+
static createVariables({
|
|
8753
|
+
metaType = null,
|
|
8754
|
+
metaId = null,
|
|
8755
|
+
key = null,
|
|
8756
|
+
value = null,
|
|
8757
|
+
keys = null,
|
|
8758
|
+
values = null,
|
|
8759
|
+
atomValues = null,
|
|
8760
|
+
latest = null,
|
|
8761
|
+
filter = null,
|
|
8762
|
+
queryArgs = null,
|
|
8763
|
+
countBy = null,
|
|
8764
|
+
cellSlug = null
|
|
8765
|
+
} = {}) {
|
|
8766
|
+
const variables = {};
|
|
8767
|
+
if (atomValues) {
|
|
8768
|
+
variables.atomValues = atomValues;
|
|
8769
|
+
}
|
|
8770
|
+
if (keys) {
|
|
8771
|
+
variables.keys = keys;
|
|
8772
|
+
}
|
|
8773
|
+
if (values) {
|
|
8774
|
+
variables.values = values;
|
|
8775
|
+
}
|
|
8776
|
+
if (metaType) {
|
|
8777
|
+
variables.metaTypes = typeof metaType === "string" ? [metaType] : metaType;
|
|
8778
|
+
}
|
|
8779
|
+
if (metaId) {
|
|
8780
|
+
variables.metaIds = typeof metaId === "string" ? [metaId] : metaId;
|
|
8781
|
+
}
|
|
8782
|
+
if (cellSlug) {
|
|
8783
|
+
variables.cellSlugs = typeof cellSlug === "string" ? [cellSlug] : cellSlug;
|
|
8784
|
+
}
|
|
8785
|
+
if (countBy) {
|
|
8786
|
+
variables.countBy = countBy;
|
|
8787
|
+
}
|
|
8788
|
+
if (filter) {
|
|
8789
|
+
variables.filter = filter;
|
|
8790
|
+
}
|
|
8791
|
+
if (key && value) {
|
|
8792
|
+
variables.filter = variables.filter || [];
|
|
8793
|
+
variables.filter.push({
|
|
8794
|
+
key,
|
|
8795
|
+
value,
|
|
8796
|
+
comparison: "="
|
|
8797
|
+
});
|
|
8798
|
+
}
|
|
8799
|
+
variables.latest = latest === true;
|
|
8800
|
+
if (queryArgs) {
|
|
8801
|
+
if (typeof queryArgs.limit === "undefined" || queryArgs.limit === 0) {
|
|
8802
|
+
queryArgs.limit = "*";
|
|
8803
|
+
}
|
|
8804
|
+
variables.queryArgs = queryArgs;
|
|
8805
|
+
}
|
|
8806
|
+
return variables;
|
|
8807
|
+
}
|
|
8808
|
+
/**
|
|
8809
|
+
* Returns a Response object
|
|
8810
|
+
*/
|
|
8811
|
+
createResponse(json) {
|
|
8812
|
+
return new ResponseMetaTypeViaMolecule({
|
|
8813
|
+
query: this,
|
|
8814
|
+
json
|
|
8815
|
+
});
|
|
8816
|
+
}
|
|
8817
|
+
};
|
|
8818
|
+
|
|
7353
8819
|
// src/response/ResponseProposeMolecule.ts
|
|
7354
8820
|
init_Response();
|
|
7355
8821
|
init_Dot();
|
|
@@ -7368,7 +8834,6 @@ var ResponseProposeMolecule = class extends exports.Response {
|
|
|
7368
8834
|
dataKey: "data.ProposeMolecule"
|
|
7369
8835
|
});
|
|
7370
8836
|
this.$__clientMolecule = query.molecule();
|
|
7371
|
-
this.init();
|
|
7372
8837
|
}
|
|
7373
8838
|
/**
|
|
7374
8839
|
* Initialize response object with payload data
|
|
@@ -7932,12 +9397,31 @@ var ResponseRequestAuthorization = class extends ResponseProposeMolecule {
|
|
|
7932
9397
|
return this.payloadKey("token");
|
|
7933
9398
|
}
|
|
7934
9399
|
/**
|
|
7935
|
-
* Returns
|
|
7936
|
-
* Matches JavaScript SDK time method exactly
|
|
9400
|
+
* Returns raw time value from payload
|
|
7937
9401
|
*/
|
|
7938
9402
|
time() {
|
|
7939
9403
|
return this.payloadKey("time");
|
|
7940
9404
|
}
|
|
9405
|
+
/**
|
|
9406
|
+
* Returns the expiration timestamp as Unix seconds.
|
|
9407
|
+
* Handles both server formats:
|
|
9408
|
+
* - PHP server: time = lifetime in ms, expiresAt = Unix timestamp in payload
|
|
9409
|
+
* - Rust server: time = Unix timestamp in seconds
|
|
9410
|
+
*/
|
|
9411
|
+
expiresAt() {
|
|
9412
|
+
try {
|
|
9413
|
+
const ea = this.payloadKey("expiresAt");
|
|
9414
|
+
if (ea) {
|
|
9415
|
+
return Number(ea);
|
|
9416
|
+
}
|
|
9417
|
+
} catch (_e) {
|
|
9418
|
+
}
|
|
9419
|
+
const timeValue = Number(this.time());
|
|
9420
|
+
if (timeValue >= 1577836800) {
|
|
9421
|
+
return timeValue;
|
|
9422
|
+
}
|
|
9423
|
+
return Math.floor(Date.now() / 1e3) + Math.floor(timeValue / 1e3);
|
|
9424
|
+
}
|
|
7941
9425
|
/**
|
|
7942
9426
|
* Returns encryption info
|
|
7943
9427
|
* Matches JavaScript SDK encrypt method exactly
|
|
@@ -8029,11 +9513,31 @@ var ResponseRequestAuthorizationGuest = class extends exports.Response {
|
|
|
8029
9513
|
return this.payloadKey("token");
|
|
8030
9514
|
}
|
|
8031
9515
|
/**
|
|
8032
|
-
* Returns
|
|
9516
|
+
* Returns raw time value from payload
|
|
8033
9517
|
*/
|
|
8034
9518
|
time() {
|
|
8035
9519
|
return this.payloadKey("time");
|
|
8036
9520
|
}
|
|
9521
|
+
/**
|
|
9522
|
+
* Returns the expiration timestamp as Unix seconds.
|
|
9523
|
+
* Handles both server formats:
|
|
9524
|
+
* - PHP server: time = lifetime in ms, expiresAt = Unix timestamp in payload
|
|
9525
|
+
* - Rust server: time = Unix timestamp in seconds
|
|
9526
|
+
*/
|
|
9527
|
+
expiresAt() {
|
|
9528
|
+
try {
|
|
9529
|
+
const ea = this.payloadKey("expiresAt");
|
|
9530
|
+
if (ea) {
|
|
9531
|
+
return Number(ea);
|
|
9532
|
+
}
|
|
9533
|
+
} catch (_e) {
|
|
9534
|
+
}
|
|
9535
|
+
const timeValue = Number(this.time());
|
|
9536
|
+
if (timeValue >= 1577836800) {
|
|
9537
|
+
return timeValue;
|
|
9538
|
+
}
|
|
9539
|
+
return Math.floor(Date.now() / 1e3) + Math.floor(timeValue / 1e3);
|
|
9540
|
+
}
|
|
8037
9541
|
/**
|
|
8038
9542
|
* Returns public key
|
|
8039
9543
|
*/
|
|
@@ -8106,27 +9610,91 @@ var ResponseLinkIdentifier = class extends exports.Response {
|
|
|
8106
9610
|
};
|
|
8107
9611
|
var MutationLinkIdentifier = class extends Mutation {
|
|
8108
9612
|
/**
|
|
8109
|
-
* Constructor
|
|
9613
|
+
* Constructor
|
|
9614
|
+
*/
|
|
9615
|
+
constructor(graphQLClient, knishIOClient) {
|
|
9616
|
+
super(graphQLClient, knishIOClient);
|
|
9617
|
+
this.$__query = core.gql`
|
|
9618
|
+
mutation($bundle: String!, $type: String!, $content: String!) {
|
|
9619
|
+
LinkIdentifier(bundle: $bundle, type: $type, content: $content) {
|
|
9620
|
+
type
|
|
9621
|
+
bundle
|
|
9622
|
+
content
|
|
9623
|
+
set
|
|
9624
|
+
message
|
|
9625
|
+
}
|
|
9626
|
+
}
|
|
9627
|
+
`;
|
|
9628
|
+
}
|
|
9629
|
+
/**
|
|
9630
|
+
* Returns a Response object
|
|
9631
|
+
*/
|
|
9632
|
+
createResponse(json) {
|
|
9633
|
+
return new ResponseLinkIdentifier({
|
|
9634
|
+
query: this,
|
|
9635
|
+
json
|
|
9636
|
+
});
|
|
9637
|
+
}
|
|
9638
|
+
};
|
|
9639
|
+
|
|
9640
|
+
// src/response/ResponsePeering.ts
|
|
9641
|
+
var ResponsePeering = class extends ResponseProposeMolecule {
|
|
9642
|
+
};
|
|
9643
|
+
|
|
9644
|
+
// src/mutation/MutationPeering.ts
|
|
9645
|
+
var MutationPeering = class extends MutationProposeMolecule {
|
|
9646
|
+
/**
|
|
9647
|
+
* Fills a molecule with a P-isotope peering atom
|
|
9648
|
+
* Matches JavaScript SDK fillMolecule method exactly
|
|
9649
|
+
*/
|
|
9650
|
+
fillMolecule({ host }) {
|
|
9651
|
+
this.$__molecule.initPeering({ host });
|
|
9652
|
+
this.$__molecule.sign({});
|
|
9653
|
+
this.$__molecule.check();
|
|
9654
|
+
}
|
|
9655
|
+
/**
|
|
9656
|
+
* Builds a Response object out of a JSON object
|
|
9657
|
+
* Matches JavaScript SDK createResponse method exactly
|
|
9658
|
+
*/
|
|
9659
|
+
createResponse(json) {
|
|
9660
|
+
return new ResponsePeering({
|
|
9661
|
+
query: this,
|
|
9662
|
+
json
|
|
9663
|
+
});
|
|
9664
|
+
}
|
|
9665
|
+
};
|
|
9666
|
+
|
|
9667
|
+
// src/response/ResponseAppendRequest.ts
|
|
9668
|
+
var ResponseAppendRequest = class extends ResponseProposeMolecule {
|
|
9669
|
+
};
|
|
9670
|
+
|
|
9671
|
+
// src/mutation/MutationAppendRequest.ts
|
|
9672
|
+
var MutationAppendRequest = class extends MutationProposeMolecule {
|
|
9673
|
+
/**
|
|
9674
|
+
* Fills a molecule with an A-isotope append request atom
|
|
9675
|
+
* Matches JavaScript SDK fillMolecule method exactly
|
|
8110
9676
|
*/
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
9677
|
+
fillMolecule({
|
|
9678
|
+
metaType,
|
|
9679
|
+
metaId,
|
|
9680
|
+
action,
|
|
9681
|
+
meta = {}
|
|
9682
|
+
}) {
|
|
9683
|
+
this.$__molecule.initAppendRequest({
|
|
9684
|
+
metaType,
|
|
9685
|
+
metaId,
|
|
9686
|
+
action,
|
|
9687
|
+
meta
|
|
9688
|
+
});
|
|
9689
|
+
this.$__molecule.sign({});
|
|
9690
|
+
this.$__molecule.check();
|
|
8124
9691
|
}
|
|
8125
9692
|
/**
|
|
8126
|
-
*
|
|
9693
|
+
* Builds a Response object out of a JSON object
|
|
9694
|
+
* Matches JavaScript SDK createResponse method exactly
|
|
8127
9695
|
*/
|
|
8128
9696
|
createResponse(json) {
|
|
8129
|
-
return new
|
|
9697
|
+
return new ResponseAppendRequest({
|
|
8130
9698
|
query: this,
|
|
8131
9699
|
json
|
|
8132
9700
|
});
|
|
@@ -8355,6 +9923,7 @@ var KnishIOClient = class {
|
|
|
8355
9923
|
$__logging = false;
|
|
8356
9924
|
$__authTokenObjects = {};
|
|
8357
9925
|
$__authToken = null;
|
|
9926
|
+
$__authInProcess = false;
|
|
8358
9927
|
$__remainderWallet = null;
|
|
8359
9928
|
lastMoleculeQuery = null;
|
|
8360
9929
|
abortControllers = /* @__PURE__ */ new Map();
|
|
@@ -8498,6 +10067,9 @@ var KnishIOClient = class {
|
|
|
8498
10067
|
} else {
|
|
8499
10068
|
this.$__uris = uri;
|
|
8500
10069
|
}
|
|
10070
|
+
if (this.$__client && "setUri" in this.$__client) {
|
|
10071
|
+
this.$__client.setUri(this.getRandomUri());
|
|
10072
|
+
}
|
|
8501
10073
|
}
|
|
8502
10074
|
/**
|
|
8503
10075
|
* Gets the Knish.IO server URIs
|
|
@@ -8560,7 +10132,8 @@ var KnishIOClient = class {
|
|
|
8560
10132
|
return this.$__remainderWallet;
|
|
8561
10133
|
}
|
|
8562
10134
|
/**
|
|
8563
|
-
*
|
|
10135
|
+
* Instantiates a new Molecule and prepares this client session to operate on it
|
|
10136
|
+
* Matches JavaScript SDK createMolecule implementation
|
|
8564
10137
|
*/
|
|
8565
10138
|
async createMolecule({
|
|
8566
10139
|
secret = null,
|
|
@@ -8573,15 +10146,24 @@ var KnishIOClient = class {
|
|
|
8573
10146
|
bundle = bundle || this.getBundle();
|
|
8574
10147
|
if (!sourceWallet && this.lastMoleculeQuery && this.getRemainderWallet()?.token === "USER" && this.lastMoleculeQuery.response() && this.lastMoleculeQuery.response()?.success()) {
|
|
8575
10148
|
sourceWallet = this.getRemainderWallet();
|
|
10149
|
+
this.log("info", `KnishIOClient::createMolecule() - Using carry-forward remainder wallet at position ${sourceWallet?.position?.substring(0, 16)}...`);
|
|
8576
10150
|
}
|
|
8577
10151
|
if (!sourceWallet) {
|
|
8578
10152
|
sourceWallet = await this.getSourceWallet();
|
|
8579
10153
|
}
|
|
8580
|
-
|
|
10154
|
+
this.setRemainderWallet(remainderWallet || Wallet.create({
|
|
8581
10155
|
secret,
|
|
8582
10156
|
bundle,
|
|
10157
|
+
token: "USER",
|
|
10158
|
+
batchId: sourceWallet.batchId,
|
|
10159
|
+
characters: sourceWallet.characters
|
|
10160
|
+
}));
|
|
10161
|
+
return new Molecule({
|
|
10162
|
+
secret,
|
|
8583
10163
|
sourceWallet,
|
|
8584
|
-
remainderWallet
|
|
10164
|
+
remainderWallet: this.getRemainderWallet(),
|
|
10165
|
+
cellSlug: this.getCellSlug(),
|
|
10166
|
+
version: this.getServerSdkVersion()
|
|
8585
10167
|
});
|
|
8586
10168
|
}
|
|
8587
10169
|
/**
|
|
@@ -8604,7 +10186,7 @@ var KnishIOClient = class {
|
|
|
8604
10186
|
* Executes a query or mutation
|
|
8605
10187
|
*/
|
|
8606
10188
|
async executeQuery(query, variables = null) {
|
|
8607
|
-
if (this.$__authToken && this.$__authToken.isExpired()) {
|
|
10189
|
+
if (this.$__authToken && this.$__authToken.isExpired() && !this.$__authInProcess) {
|
|
8608
10190
|
this.log("info", "KnishIOClient::executeQuery() - Access token is expired. Getting new one...");
|
|
8609
10191
|
await this.requestAuthToken({
|
|
8610
10192
|
secret: this.$__secret,
|
|
@@ -8631,14 +10213,26 @@ var KnishIOClient = class {
|
|
|
8631
10213
|
}
|
|
8632
10214
|
}
|
|
8633
10215
|
/**
|
|
8634
|
-
*
|
|
10216
|
+
* Retrieves this session's wallet used for signing the next Molecule
|
|
10217
|
+
* Queries ContinuID from the server to get the authoritative position
|
|
10218
|
+
* Matches JavaScript SDK getSourceWallet implementation
|
|
8635
10219
|
*/
|
|
8636
10220
|
async getSourceWallet() {
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
10221
|
+
let sourceWallet = (await this.queryContinuId({
|
|
10222
|
+
bundle: this.getBundle()
|
|
10223
|
+
}))?.payload();
|
|
10224
|
+
if (!sourceWallet) {
|
|
10225
|
+
sourceWallet = new Wallet({
|
|
10226
|
+
secret: this.getSecret()
|
|
10227
|
+
});
|
|
10228
|
+
} else {
|
|
10229
|
+
sourceWallet.key = Wallet.generateKey({
|
|
10230
|
+
secret: this.getSecret(),
|
|
10231
|
+
token: sourceWallet.token,
|
|
10232
|
+
position: sourceWallet.position
|
|
10233
|
+
});
|
|
10234
|
+
}
|
|
10235
|
+
return sourceWallet;
|
|
8642
10236
|
}
|
|
8643
10237
|
/**
|
|
8644
10238
|
* Transfer tokens between wallets
|
|
@@ -8667,7 +10261,7 @@ var KnishIOClient = class {
|
|
|
8667
10261
|
amount
|
|
8668
10262
|
});
|
|
8669
10263
|
}
|
|
8670
|
-
if (sourceWallet === null || Decimal.cmp(sourceWallet.balance, amount) < 0) {
|
|
10264
|
+
if (sourceWallet === null || Decimal.cmp(Number(sourceWallet.balance), amount) < 0) {
|
|
8671
10265
|
throw new exports.TransferBalanceException();
|
|
8672
10266
|
}
|
|
8673
10267
|
const recipientWallet = Wallet.create({
|
|
@@ -8702,19 +10296,48 @@ var KnishIOClient = class {
|
|
|
8702
10296
|
return await this.executeQuery(query);
|
|
8703
10297
|
}
|
|
8704
10298
|
/**
|
|
8705
|
-
* Request authorization token
|
|
10299
|
+
* Request authorization token (guest or profile)
|
|
10300
|
+
*
|
|
10301
|
+
* @param secret - User secret for profile auth (null for guest)
|
|
10302
|
+
* @param seed - Seed to generate secret (alternative to secret)
|
|
10303
|
+
* @param cellSlug - Cell slug for scoped access
|
|
10304
|
+
* @param encrypt - Whether to use encryption
|
|
8706
10305
|
*/
|
|
8707
10306
|
async requestAuthToken({
|
|
8708
|
-
secret
|
|
8709
|
-
seed
|
|
8710
|
-
cellSlug
|
|
8711
|
-
encrypt
|
|
10307
|
+
secret = null,
|
|
10308
|
+
seed = null,
|
|
10309
|
+
cellSlug = null,
|
|
10310
|
+
encrypt = false
|
|
8712
10311
|
} = {}) {
|
|
8713
10312
|
if (this.$__serverSdkVersion < 3) {
|
|
8714
|
-
this.log("warn", "KnishIOClient::
|
|
10313
|
+
this.log("warn", "KnishIOClient::requestAuthToken() - Server SDK version does not require authorization...");
|
|
8715
10314
|
return null;
|
|
8716
10315
|
}
|
|
8717
|
-
|
|
10316
|
+
if (secret === null && seed) {
|
|
10317
|
+
secret = generateSecret(seed);
|
|
10318
|
+
}
|
|
10319
|
+
if (cellSlug) {
|
|
10320
|
+
this.setCellSlug(cellSlug);
|
|
10321
|
+
}
|
|
10322
|
+
this.$__authInProcess = true;
|
|
10323
|
+
let response;
|
|
10324
|
+
if (secret) {
|
|
10325
|
+
response = await this.requestProfileAuthToken({
|
|
10326
|
+
secret,
|
|
10327
|
+
encrypt
|
|
10328
|
+
});
|
|
10329
|
+
} else {
|
|
10330
|
+
response = await this.requestGuestAuthToken({
|
|
10331
|
+
cellSlug: cellSlug || this.getCellSlug(),
|
|
10332
|
+
encrypt
|
|
10333
|
+
});
|
|
10334
|
+
}
|
|
10335
|
+
if (this.$__authToken) {
|
|
10336
|
+
this.log("info", `KnishIOClient::requestAuthToken() - Successfully retrieved auth token...`);
|
|
10337
|
+
}
|
|
10338
|
+
this.switchEncryption(encrypt);
|
|
10339
|
+
this.$__authInProcess = false;
|
|
10340
|
+
return response;
|
|
8718
10341
|
}
|
|
8719
10342
|
/**
|
|
8720
10343
|
* Logging utility
|
|
@@ -8812,7 +10435,7 @@ var KnishIOClient = class {
|
|
|
8812
10435
|
});
|
|
8813
10436
|
const sourceWallet = response.payload();
|
|
8814
10437
|
const amountNum = typeof amount === "string" ? Number(amount) : amount;
|
|
8815
|
-
if (sourceWallet === null || Decimal.cmp(sourceWallet.balance || 0, amountNum) < 0) {
|
|
10438
|
+
if (sourceWallet === null || Decimal.cmp(Number(sourceWallet.balance || 0), amountNum) < 0) {
|
|
8816
10439
|
throw new exports.TransferBalanceException();
|
|
8817
10440
|
}
|
|
8818
10441
|
if (!sourceWallet.position || !sourceWallet.address) {
|
|
@@ -8832,7 +10455,7 @@ var KnishIOClient = class {
|
|
|
8832
10455
|
const walletQuery = this.createQuery(QueryWalletList);
|
|
8833
10456
|
const response = await this.executeQuery(walletQuery, {
|
|
8834
10457
|
bundleHash: bundle || this.getBundle(),
|
|
8835
|
-
|
|
10458
|
+
token,
|
|
8836
10459
|
unspent
|
|
8837
10460
|
});
|
|
8838
10461
|
return response?.payload() || [];
|
|
@@ -8882,6 +10505,7 @@ var KnishIOClient = class {
|
|
|
8882
10505
|
count = null,
|
|
8883
10506
|
countBy = null,
|
|
8884
10507
|
throughAtom = true,
|
|
10508
|
+
throughMolecule = false,
|
|
8885
10509
|
values = null,
|
|
8886
10510
|
keys = null,
|
|
8887
10511
|
atomValues = null
|
|
@@ -8889,7 +10513,23 @@ var KnishIOClient = class {
|
|
|
8889
10513
|
this.log("info", `KnishIOClient::queryMeta() - Querying metaType: ${metaType}, metaId: ${metaId}...`);
|
|
8890
10514
|
let query;
|
|
8891
10515
|
let variables;
|
|
8892
|
-
if (
|
|
10516
|
+
if (throughMolecule) {
|
|
10517
|
+
query = this.createQuery(QueryMetaTypeViaMolecule);
|
|
10518
|
+
variables = QueryMetaTypeViaMolecule.createVariables({
|
|
10519
|
+
metaType,
|
|
10520
|
+
metaId,
|
|
10521
|
+
key,
|
|
10522
|
+
value,
|
|
10523
|
+
latest,
|
|
10524
|
+
filter,
|
|
10525
|
+
queryArgs,
|
|
10526
|
+
countBy,
|
|
10527
|
+
values,
|
|
10528
|
+
keys,
|
|
10529
|
+
atomValues,
|
|
10530
|
+
cellSlug: this.getCellSlug()
|
|
10531
|
+
});
|
|
10532
|
+
} else if (throughAtom) {
|
|
8893
10533
|
query = this.createQuery(QueryMetaTypeViaAtom);
|
|
8894
10534
|
variables = QueryMetaTypeViaAtom.createVariables({
|
|
8895
10535
|
metaType,
|
|
@@ -8922,6 +10562,19 @@ var KnishIOClient = class {
|
|
|
8922
10562
|
}
|
|
8923
10563
|
return this.executeQuery(query, variables);
|
|
8924
10564
|
}
|
|
10565
|
+
/**
|
|
10566
|
+
* Queries meta assets and verifies cryptographic integrity of associated molecules.
|
|
10567
|
+
* Forces throughMolecule=true to ensure molecule data is available for verification.
|
|
10568
|
+
* Returns the same response as queryMeta(), with an additional `integrity` field on the payload.
|
|
10569
|
+
*/
|
|
10570
|
+
async queryMetaVerified(params) {
|
|
10571
|
+
const response = await this.queryMeta({ ...params, throughMolecule: true });
|
|
10572
|
+
const payload = response.payload();
|
|
10573
|
+
if (payload && typeof response.verifyIntegrity === "function") {
|
|
10574
|
+
payload.integrity = response.verifyIntegrity();
|
|
10575
|
+
}
|
|
10576
|
+
return response;
|
|
10577
|
+
}
|
|
8925
10578
|
/**
|
|
8926
10579
|
* Query cascading meta instances for batchId
|
|
8927
10580
|
*/
|
|
@@ -9184,7 +10837,7 @@ var KnishIOClient = class {
|
|
|
9184
10837
|
const recipientWallet = new Wallet({
|
|
9185
10838
|
secret: this.getSecret(),
|
|
9186
10839
|
bundle: this.getBundle(),
|
|
9187
|
-
token
|
|
10840
|
+
token,
|
|
9188
10841
|
batchId
|
|
9189
10842
|
});
|
|
9190
10843
|
await mutation.fillMolecule({
|
|
@@ -9212,7 +10865,7 @@ var KnishIOClient = class {
|
|
|
9212
10865
|
this.log("info", `KnishIOClient::requestTokens() - Requesting ${amount || "units"} of ${token}...`);
|
|
9213
10866
|
const mutation = await this.createMoleculeMutation({ mutationClass: MutationRequestTokens });
|
|
9214
10867
|
await mutation.fillMolecule({
|
|
9215
|
-
token
|
|
10868
|
+
token,
|
|
9216
10869
|
amount: amount ?? 0,
|
|
9217
10870
|
metaType: to || "",
|
|
9218
10871
|
metaId: to || "",
|
|
@@ -9241,11 +10894,17 @@ var KnishIOClient = class {
|
|
|
9241
10894
|
amount: amount || 0
|
|
9242
10895
|
});
|
|
9243
10896
|
}
|
|
9244
|
-
const
|
|
10897
|
+
const molecule = await this.createMolecule({
|
|
10898
|
+
sourceWallet
|
|
10899
|
+
});
|
|
10900
|
+
const mutation = await this.createMoleculeMutation({
|
|
10901
|
+
mutationClass: MutationTransferTokens,
|
|
10902
|
+
molecule
|
|
10903
|
+
});
|
|
9245
10904
|
const recipientWallet = new Wallet({
|
|
9246
10905
|
secret: this.getSecret(),
|
|
9247
10906
|
bundle: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
9248
|
-
token
|
|
10907
|
+
token
|
|
9249
10908
|
});
|
|
9250
10909
|
await mutation.fillMolecule({
|
|
9251
10910
|
recipientWallet,
|
|
@@ -9300,7 +10959,7 @@ var KnishIOClient = class {
|
|
|
9300
10959
|
const newWallet = new Wallet({
|
|
9301
10960
|
secret: this.getSecret(),
|
|
9302
10961
|
bundle: this.getBundle(),
|
|
9303
|
-
token
|
|
10962
|
+
token
|
|
9304
10963
|
});
|
|
9305
10964
|
await mutation.fillMolecule(newWallet);
|
|
9306
10965
|
const response = await this.executeQuery(mutation);
|
|
@@ -9331,7 +10990,7 @@ var KnishIOClient = class {
|
|
|
9331
10990
|
}
|
|
9332
10991
|
const mutation = await this.createMoleculeMutation({ mutationClass: MutationClaimShadowWallet });
|
|
9333
10992
|
await mutation.fillMolecule({
|
|
9334
|
-
token
|
|
10993
|
+
token,
|
|
9335
10994
|
batchId: shadowWallet.batchId
|
|
9336
10995
|
});
|
|
9337
10996
|
const response = await this.executeQuery(mutation);
|
|
@@ -9379,11 +11038,16 @@ var KnishIOClient = class {
|
|
|
9379
11038
|
policy = null
|
|
9380
11039
|
}) {
|
|
9381
11040
|
this.log("info", `KnishIOClient::createMeta() - Creating metadata for ${metaType}:${metaId}...`);
|
|
9382
|
-
const mutation = await this.createMoleculeMutation({
|
|
11041
|
+
const mutation = await this.createMoleculeMutation({
|
|
11042
|
+
mutationClass: MutationCreateMeta,
|
|
11043
|
+
molecule: await this.createMolecule({
|
|
11044
|
+
secret: this.getSecret()
|
|
11045
|
+
})
|
|
11046
|
+
});
|
|
9383
11047
|
await mutation.fillMolecule({
|
|
9384
|
-
metaType
|
|
11048
|
+
metaType,
|
|
9385
11049
|
metaId,
|
|
9386
|
-
meta,
|
|
11050
|
+
meta: meta || {},
|
|
9387
11051
|
policy
|
|
9388
11052
|
});
|
|
9389
11053
|
const response = await this.executeQuery(mutation);
|
|
@@ -9402,9 +11066,14 @@ var KnishIOClient = class {
|
|
|
9402
11066
|
policy = null
|
|
9403
11067
|
}) {
|
|
9404
11068
|
this.log("info", `KnishIOClient::createRule() - Creating rule for ${metaType}:${metaId}...`);
|
|
9405
|
-
const mutation = await this.createMoleculeMutation({
|
|
11069
|
+
const mutation = await this.createMoleculeMutation({
|
|
11070
|
+
mutationClass: MutationCreateRule,
|
|
11071
|
+
molecule: await this.createMolecule({
|
|
11072
|
+
secret: this.getSecret()
|
|
11073
|
+
})
|
|
11074
|
+
});
|
|
9406
11075
|
await mutation.fillMolecule({
|
|
9407
|
-
metaType
|
|
11076
|
+
metaType,
|
|
9408
11077
|
metaId,
|
|
9409
11078
|
rule,
|
|
9410
11079
|
policy
|
|
@@ -9491,8 +11160,8 @@ var KnishIOClient = class {
|
|
|
9491
11160
|
this.log("info", `KnishIOClient::activeSession() - Declaring active session for ${metaType}:${metaId}...`);
|
|
9492
11161
|
const mutation = this.createQuery(MutationActiveSession);
|
|
9493
11162
|
const response = await this.executeQuery(mutation, {
|
|
9494
|
-
|
|
9495
|
-
metaType
|
|
11163
|
+
bundleHash: bundle || this.getBundle(),
|
|
11164
|
+
metaType,
|
|
9496
11165
|
metaId,
|
|
9497
11166
|
ipAddress,
|
|
9498
11167
|
browser,
|
|
@@ -9585,6 +11254,7 @@ var KnishIOClient = class {
|
|
|
9585
11254
|
}
|
|
9586
11255
|
/**
|
|
9587
11256
|
* Request profile authentication token
|
|
11257
|
+
* Matches JavaScript SDK requestProfileAuthToken implementation
|
|
9588
11258
|
*/
|
|
9589
11259
|
async requestProfileAuthToken({
|
|
9590
11260
|
secret,
|
|
@@ -9592,151 +11262,108 @@ var KnishIOClient = class {
|
|
|
9592
11262
|
}) {
|
|
9593
11263
|
this.log("info", "KnishIOClient::requestProfileAuthToken() - Requesting profile auth token...");
|
|
9594
11264
|
this.setSecret(secret);
|
|
9595
|
-
const
|
|
9596
|
-
|
|
11265
|
+
const wallet = new Wallet({
|
|
11266
|
+
secret,
|
|
11267
|
+
token: "AUTH"
|
|
11268
|
+
});
|
|
11269
|
+
const molecule = await this.createMolecule({
|
|
11270
|
+
secret,
|
|
11271
|
+
sourceWallet: wallet
|
|
11272
|
+
});
|
|
11273
|
+
const mutation = await this.createMoleculeMutation({
|
|
11274
|
+
mutationClass: MutationRequestAuthorization,
|
|
11275
|
+
molecule
|
|
11276
|
+
});
|
|
11277
|
+
mutation.fillMolecule({
|
|
9597
11278
|
meta: { encrypt: encrypt ? "true" : "false" }
|
|
9598
11279
|
});
|
|
9599
11280
|
const response = await this.executeQuery(mutation);
|
|
9600
11281
|
if (!response) {
|
|
9601
11282
|
throw new CodeException("Profile auth token request failed");
|
|
9602
11283
|
}
|
|
11284
|
+
if (response.success()) {
|
|
11285
|
+
const authToken = AuthToken.create({
|
|
11286
|
+
token: response.token(),
|
|
11287
|
+
expiresAt: response.expiresAt(),
|
|
11288
|
+
encrypt: String(response.encrypt()) === "true",
|
|
11289
|
+
pubkey: response.pubKey()
|
|
11290
|
+
}, wallet);
|
|
11291
|
+
this.setAuthToken(authToken);
|
|
11292
|
+
} else {
|
|
11293
|
+
throw new AuthorizationRejectedException_default(
|
|
11294
|
+
`KnishIOClient::requestProfileAuthToken() - Authorization attempt rejected by ledger. Reason: ${response.reason()}`
|
|
11295
|
+
);
|
|
11296
|
+
}
|
|
9603
11297
|
if (encrypt) {
|
|
9604
11298
|
this.switchEncryption(true);
|
|
9605
11299
|
}
|
|
9606
11300
|
return response;
|
|
9607
11301
|
}
|
|
9608
11302
|
// =============================================================================
|
|
9609
|
-
//
|
|
11303
|
+
// MUTATION METHODS - PEERING & APPEND REQUEST
|
|
9610
11304
|
// =============================================================================
|
|
9611
11305
|
/**
|
|
9612
|
-
*
|
|
9613
|
-
|
|
9614
|
-
cellSlug() {
|
|
9615
|
-
return this.getCellSlug();
|
|
9616
|
-
}
|
|
9617
|
-
/**
|
|
9618
|
-
* @deprecated Use getUri() instead
|
|
11306
|
+
* Register a peer node via P-isotope
|
|
11307
|
+
* Matches JavaScript SDK registerPeer implementation exactly
|
|
9619
11308
|
*/
|
|
9620
|
-
|
|
9621
|
-
|
|
11309
|
+
async registerPeer({ host }) {
|
|
11310
|
+
this.log("info", `KnishIOClient::registerPeer() - Registering peer at ${host}...`);
|
|
11311
|
+
const mutation = await this.createMoleculeMutation({
|
|
11312
|
+
mutationClass: MutationPeering,
|
|
11313
|
+
molecule: await this.createMolecule({
|
|
11314
|
+
secret: this.getSecret()
|
|
11315
|
+
})
|
|
11316
|
+
});
|
|
11317
|
+
mutation.fillMolecule({ host });
|
|
11318
|
+
const response = await this.executeQuery(mutation);
|
|
11319
|
+
if (!response) {
|
|
11320
|
+
throw new CodeException("Peer registration failed");
|
|
11321
|
+
}
|
|
11322
|
+
return response;
|
|
9622
11323
|
}
|
|
9623
|
-
};
|
|
9624
|
-
|
|
9625
|
-
// src/AuthToken.ts
|
|
9626
|
-
var AuthToken = class _AuthToken {
|
|
9627
|
-
$__token;
|
|
9628
|
-
$__expiresAt;
|
|
9629
|
-
$__pubkey;
|
|
9630
|
-
$__encrypt;
|
|
9631
|
-
$__wallet;
|
|
9632
11324
|
/**
|
|
9633
|
-
*
|
|
11325
|
+
* Submit an append request via A-isotope
|
|
11326
|
+
* Matches JavaScript SDK appendRequest implementation exactly
|
|
9634
11327
|
*/
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
11328
|
+
async appendRequest({
|
|
11329
|
+
metaType,
|
|
11330
|
+
metaId,
|
|
11331
|
+
action,
|
|
11332
|
+
meta = {}
|
|
9640
11333
|
}) {
|
|
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
|
|
11334
|
+
this.log("info", `KnishIOClient::appendRequest() - Submitting append request for ${metaType}:${metaId}...`);
|
|
11335
|
+
const mutation = await this.createMoleculeMutation({
|
|
11336
|
+
mutationClass: MutationAppendRequest,
|
|
11337
|
+
molecule: await this.createMolecule({
|
|
11338
|
+
secret: this.getSecret()
|
|
11339
|
+
})
|
|
9663
11340
|
});
|
|
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;
|
|
11341
|
+
mutation.fillMolecule({
|
|
11342
|
+
metaType,
|
|
11343
|
+
metaId,
|
|
11344
|
+
action,
|
|
11345
|
+
meta
|
|
11346
|
+
});
|
|
11347
|
+
const response = await this.executeQuery(mutation);
|
|
11348
|
+
if (!response) {
|
|
11349
|
+
throw new CodeException("Append request failed");
|
|
11350
|
+
}
|
|
11351
|
+
return response;
|
|
9713
11352
|
}
|
|
11353
|
+
// =============================================================================
|
|
11354
|
+
// LEGACY/DEPRECATED METHODS
|
|
11355
|
+
// =============================================================================
|
|
9714
11356
|
/**
|
|
9715
|
-
*
|
|
11357
|
+
* @deprecated Use getCellSlug() instead
|
|
9716
11358
|
*/
|
|
9717
|
-
|
|
9718
|
-
return
|
|
9719
|
-
token: this.$__token,
|
|
9720
|
-
pubkey: this.$__pubkey,
|
|
9721
|
-
wallet: this.$__wallet
|
|
9722
|
-
};
|
|
11359
|
+
cellSlug() {
|
|
11360
|
+
return this.getCellSlug();
|
|
9723
11361
|
}
|
|
9724
11362
|
/**
|
|
9725
|
-
*
|
|
11363
|
+
* @deprecated Use getUri() instead
|
|
9726
11364
|
*/
|
|
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
|
-
};
|
|
11365
|
+
uri() {
|
|
11366
|
+
return this.getUri();
|
|
9740
11367
|
}
|
|
9741
11368
|
};
|
|
9742
11369
|
|
|
@@ -9914,9 +11541,11 @@ exports.KnishIOClient = KnishIOClient;
|
|
|
9914
11541
|
exports.Meta = Meta;
|
|
9915
11542
|
exports.Molecule = Molecule;
|
|
9916
11543
|
exports.Mutation = Mutation;
|
|
11544
|
+
exports.MutationAppendRequest = MutationAppendRequest;
|
|
9917
11545
|
exports.MutationCreateMeta = MutationCreateMeta;
|
|
9918
11546
|
exports.MutationCreateToken = MutationCreateToken;
|
|
9919
11547
|
exports.MutationCreateWallet = MutationCreateWallet;
|
|
11548
|
+
exports.MutationPeering = MutationPeering;
|
|
9920
11549
|
exports.MutationProposeMolecule = MutationProposeMolecule;
|
|
9921
11550
|
exports.MutationRequestAuthorization = MutationRequestAuthorization;
|
|
9922
11551
|
exports.MutationRequestTokens = MutationRequestTokens;
|
|
@@ -9931,6 +11560,7 @@ exports.QueryMetaType = QueryMetaType;
|
|
|
9931
11560
|
exports.QueryMetaTypeViaAtom = QueryMetaTypeViaAtom;
|
|
9932
11561
|
exports.QueryWalletBundle = QueryWalletBundle;
|
|
9933
11562
|
exports.QueryWalletList = QueryWalletList;
|
|
11563
|
+
exports.ResponseAppendRequest = ResponseAppendRequest;
|
|
9934
11564
|
exports.ResponseAtom = ResponseAtom;
|
|
9935
11565
|
exports.ResponseBalance = ResponseBalance;
|
|
9936
11566
|
exports.ResponseContinuId = ResponseContinuId;
|
|
@@ -9939,6 +11569,7 @@ exports.ResponseCreateToken = ResponseCreateToken;
|
|
|
9939
11569
|
exports.ResponseCreateWallet = ResponseCreateWallet;
|
|
9940
11570
|
exports.ResponseMetaType = ResponseMetaType;
|
|
9941
11571
|
exports.ResponseMetaTypeViaAtom = ResponseMetaTypeViaAtom;
|
|
11572
|
+
exports.ResponsePeering = ResponsePeering;
|
|
9942
11573
|
exports.ResponseProposeMolecule = ResponseProposeMolecule;
|
|
9943
11574
|
exports.ResponseRequestAuthorization = ResponseRequestAuthorization;
|
|
9944
11575
|
exports.ResponseRequestTokens = ResponseRequestTokens;
|