@secondlayer/stacks 6.1.0 → 6.1.1
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/shared/stacks-esm-0pc6tmf0.js +50 -0
- package/dist/shared/{stacks-esm-743jfh10.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
- package/dist/shared/{stacks-esm-0rdxcta7.js → stacks-esm-16d82wyc.js} +10 -10
- package/dist/shared/{stacks-esm-0rdxcta7.js.map → stacks-esm-16d82wyc.js.map} +2 -2
- package/dist/shared/{stacks-esm-cvhazvhd.js → stacks-esm-7a0ehykf.js} +43 -43
- package/dist/shared/{stacks-esm-cvhazvhd.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
- package/dist/shared/{stacks-esm-1jae0a3r.js → stacks-esm-7v18h5dk.js} +4 -4
- package/dist/shared/{stacks-esm-1jae0a3r.js.map → stacks-esm-7v18h5dk.js.map} +2 -2
- package/dist/shared/{stacks-esm-9rnx0zxr.js → stacks-esm-8f5catbf.js} +126 -126
- package/dist/shared/{stacks-esm-9rnx0zxr.js.map → stacks-esm-8f5catbf.js.map} +2 -2
- package/dist/shared/{stacks-esm-7fpqgtyx.js → stacks-esm-8jt6k8p3.js} +13 -13
- package/dist/shared/{stacks-esm-7fpqgtyx.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
- package/dist/shared/{stacks-esm-hr7fpxtj.js → stacks-esm-a20wyky3.js} +92 -92
- package/dist/shared/{stacks-esm-hr7fpxtj.js.map → stacks-esm-a20wyky3.js.map} +2 -2
- package/dist/shared/{stacks-esm-3pv5avgr.js → stacks-esm-b54n1jdx.js} +54 -54
- package/dist/shared/{stacks-esm-3pv5avgr.js.map → stacks-esm-b54n1jdx.js.map} +2 -2
- package/dist/shared/{stacks-esm-r9q4wnyw.js → stacks-esm-cmtj5vky.js} +162 -162
- package/dist/shared/{stacks-esm-r9q4wnyw.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
- package/dist/shared/{stacks-esm-wv67m4g6.js → stacks-esm-e2qhfgke.js} +36 -36
- package/dist/shared/{stacks-esm-wv67m4g6.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
- package/dist/shared/{stacks-esm-qk0p9fr6.js → stacks-esm-ea4m4bk7.js} +117 -117
- package/dist/shared/{stacks-esm-qk0p9fr6.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
- package/dist/shared/{stacks-esm-fcfdn2zx.js → stacks-esm-hkw1kvd4.js} +140 -140
- package/dist/shared/{stacks-esm-fcfdn2zx.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
- package/dist/shared/{stacks-esm-qkj67g80.js → stacks-esm-k108pemv.js} +4 -4
- package/dist/shared/{stacks-esm-qkj67g80.js.map → stacks-esm-k108pemv.js.map} +2 -2
- package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
- package/dist/shared/{stacks-esm-2mc7ebrm.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
- package/dist/shared/{stacks-esm-n53kvwmt.js → stacks-esm-mt1thm7k.js} +9 -9
- package/dist/shared/{stacks-esm-n53kvwmt.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
- package/dist/shared/{stacks-esm-v45990hx.js → stacks-esm-n1mekwnb.js} +9 -9
- package/dist/shared/{stacks-esm-v45990hx.js.map → stacks-esm-n1mekwnb.js.map} +2 -2
- package/dist/shared/{stacks-esm-r6dejrgr.js → stacks-esm-nt5hf8ht.js} +34 -34
- package/dist/shared/{stacks-esm-r6dejrgr.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
- package/dist/shared/{stacks-esm-skmcf5n2.js → stacks-esm-phgy8yqf.js} +210 -210
- package/dist/shared/{stacks-esm-skmcf5n2.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
- package/dist/shared/{stacks-esm-kds4n82p.js → stacks-esm-pxv6ny92.js} +116 -116
- package/dist/shared/{stacks-esm-kds4n82p.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
- package/dist/shared/{stacks-esm-3g33bqsm.js → stacks-esm-qfzxhdqz.js} +19 -19
- package/dist/shared/{stacks-esm-3g33bqsm.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
- package/dist/shared/{stacks-esm-aw2mj3sj.js → stacks-esm-snj9s2q8.js} +43 -43
- package/dist/shared/{stacks-esm-aw2mj3sj.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
- package/dist/shared/{stacks-esm-q19a17fd.js → stacks-esm-ss9ap75h.js} +28 -28
- package/dist/shared/{stacks-esm-q19a17fd.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
- package/dist/shared/{stacks-esm-x1r01353.js → stacks-esm-t88hc019.js} +18 -18
- package/dist/shared/{stacks-esm-x1r01353.js.map → stacks-esm-t88hc019.js.map} +2 -2
- package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
- package/dist/shared/{stacks-esm-pxhfqfff.js.map → stacks-esm-tdrdye4y.js.map} +2 -2
- package/dist/src/accounts/index.cjs +15 -13
- package/dist/src/accounts/index.cjs.map +2 -2
- package/dist/src/accounts/index.d.cts +1 -1
- package/dist/src/accounts/index.d.ts +1 -1
- package/dist/src/accounts/index.js +26 -26
- package/dist/src/accounts/index.js.map +2 -2
- package/dist/src/actions/index.cjs +83 -81
- package/dist/src/actions/index.cjs.map +2 -2
- package/dist/src/actions/index.d.cts +1 -1
- package/dist/src/actions/index.d.ts +1 -1
- package/dist/src/actions/index.js +102 -103
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/bitcoin/index.cjs +2035 -2036
- package/dist/src/bitcoin/index.cjs.map +8 -8
- package/dist/src/bitcoin/index.d.cts +92 -92
- package/dist/src/bitcoin/index.d.ts +92 -92
- package/dist/src/bitcoin/index.js +88 -90
- package/dist/src/bitcoin/index.js.map +2 -2
- package/dist/src/bns/index.cjs +3313 -3310
- package/dist/src/bns/index.cjs.map +13 -13
- package/dist/src/bns/index.d.cts +1 -1
- package/dist/src/bns/index.d.ts +1 -1
- package/dist/src/bns/index.js +39 -41
- package/dist/src/bns/index.js.map +2 -2
- package/dist/src/chains/index.cjs +14 -12
- package/dist/src/chains/index.cjs.map +2 -2
- package/dist/src/chains/index.d.cts +1 -1
- package/dist/src/chains/index.d.ts +1 -1
- package/dist/src/chains/index.js +12 -12
- package/dist/src/chains/index.js.map +1 -1
- package/dist/src/clarity/index.cjs +98 -96
- package/dist/src/clarity/index.cjs.map +2 -2
- package/dist/src/clarity/index.d.cts +1 -1
- package/dist/src/clarity/index.d.ts +1 -1
- package/dist/src/clarity/index.js +170 -171
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/connect/index.cjs +19 -19
- package/dist/src/connect/index.cjs.map +2 -2
- package/dist/src/connect/index.d.cts +1 -1
- package/dist/src/connect/index.d.ts +1 -1
- package/dist/src/connect/index.js +19 -19
- package/dist/src/connect/index.js.map +2 -2
- package/dist/src/connect/walletconnect/index.cjs +6 -46
- package/dist/src/connect/walletconnect/index.cjs.map +3 -4
- package/dist/src/connect/walletconnect/index.d.cts +1 -1
- package/dist/src/connect/walletconnect/index.d.ts +1 -1
- package/dist/src/connect/walletconnect/index.js +6 -46
- package/dist/src/connect/walletconnect/index.js.map +3 -4
- package/dist/src/filters/index.cjs +22 -20
- package/dist/src/filters/index.cjs.map +2 -2
- package/dist/src/filters/index.d.cts +1 -1
- package/dist/src/filters/index.d.ts +1 -1
- package/dist/src/filters/index.js +30 -30
- package/dist/src/filters/index.js.map +1 -1
- package/dist/src/index.cjs +1411 -1410
- package/dist/src/index.cjs.map +11 -11
- package/dist/src/index.d.cts +724 -724
- package/dist/src/index.d.ts +724 -724
- package/dist/src/index.js +219 -219
- package/dist/src/index.js.map +2 -2
- package/dist/src/postconditions/index.cjs +26 -24
- package/dist/src/postconditions/index.cjs.map +2 -2
- package/dist/src/postconditions/index.d.cts +1 -1
- package/dist/src/postconditions/index.d.ts +1 -1
- package/dist/src/postconditions/index.js +16 -17
- package/dist/src/postconditions/index.js.map +1 -1
- package/dist/src/pox/index.cjs +722 -721
- package/dist/src/pox/index.cjs.map +9 -9
- package/dist/src/pox/index.d.cts +1 -1
- package/dist/src/pox/index.d.ts +1 -1
- package/dist/src/pox/index.js +40 -41
- package/dist/src/pox/index.js.map +2 -2
- package/dist/src/pox5/index.cjs +141 -137
- package/dist/src/pox5/index.cjs.map +3 -3
- package/dist/src/pox5/index.d.cts +9 -1
- package/dist/src/pox5/index.d.ts +9 -1
- package/dist/src/pox5/index.js +210 -209
- package/dist/src/pox5/index.js.map +3 -3
- package/dist/src/sbtc/index.cjs +71 -69
- package/dist/src/sbtc/index.cjs.map +2 -2
- package/dist/src/sbtc/index.d.cts +1 -1
- package/dist/src/sbtc/index.d.ts +1 -1
- package/dist/src/sbtc/index.js +39 -40
- package/dist/src/sbtc/index.js.map +2 -2
- package/dist/src/simnet/index.cjs +16 -16
- package/dist/src/simnet/index.cjs.map +2 -2
- package/dist/src/simnet/index.d.cts +1 -1
- package/dist/src/simnet/index.d.ts +1 -1
- package/dist/src/simnet/index.js +16 -16
- package/dist/src/simnet/index.js.map +2 -2
- package/dist/src/stackingdao/index.cjs +716 -715
- package/dist/src/stackingdao/index.cjs.map +9 -9
- package/dist/src/stackingdao/index.d.cts +1 -1
- package/dist/src/stackingdao/index.d.ts +1 -1
- package/dist/src/stackingdao/index.js +26 -27
- package/dist/src/stackingdao/index.js.map +2 -2
- package/dist/src/subscriptions/index.cjs +15 -13
- package/dist/src/subscriptions/index.cjs.map +2 -2
- package/dist/src/subscriptions/index.d.cts +1 -1
- package/dist/src/subscriptions/index.d.ts +1 -1
- package/dist/src/subscriptions/index.js +14 -15
- package/dist/src/subscriptions/index.js.map +1 -1
- package/dist/src/transactions/index.cjs +79 -77
- package/dist/src/transactions/index.cjs.map +2 -2
- package/dist/src/transactions/index.d.cts +1 -1
- package/dist/src/transactions/index.d.ts +1 -1
- package/dist/src/transactions/index.js +104 -105
- package/dist/src/transactions/index.js.map +1 -1
- package/dist/src/utils/index.cjs +76 -74
- package/dist/src/utils/index.cjs.map +2 -2
- package/dist/src/utils/index.d.cts +1 -1
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.js +131 -131
- package/dist/src/utils/index.js.map +2 -2
- package/package.json +1 -1
- package/dist/shared/stacks-esm-2mc7ebrm.js +0 -84
- package/dist/shared/stacks-esm-743jfh10.js +0 -50
- package/dist/shared/stacks-esm-pxhfqfff.js +0 -48
|
@@ -19,13 +19,15 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
19
19
|
return cached;
|
|
20
20
|
}
|
|
21
21
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
if (mod && typeof mod === "object" || typeof mod === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(mod))
|
|
25
|
+
if (!__hasOwnProp.call(to, key))
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: __accessProp.bind(mod, key),
|
|
28
|
+
enumerable: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
29
31
|
if (canCache)
|
|
30
32
|
cache.set(mod, to);
|
|
31
33
|
return to;
|
|
@@ -61,16 +63,19 @@ var __export = (target, all) => {
|
|
|
61
63
|
});
|
|
62
64
|
};
|
|
63
65
|
|
|
64
|
-
// src/
|
|
65
|
-
var
|
|
66
|
-
__export(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fromHex: () => fromHex,
|
|
71
|
-
Pc: () => Pc
|
|
66
|
+
// src/stackingdao/index.ts
|
|
67
|
+
var exports_stackingdao = {};
|
|
68
|
+
__export(exports_stackingdao, {
|
|
69
|
+
STACKINGDAO_CONTRACTS: () => STACKINGDAO_CONTRACTS,
|
|
70
|
+
TRAIT_CONTRACTS: () => TRAIT_CONTRACTS,
|
|
71
|
+
stackingDao: () => stackingDao
|
|
72
72
|
});
|
|
73
|
-
module.exports = __toCommonJS(
|
|
73
|
+
module.exports = __toCommonJS(exports_stackingdao);
|
|
74
|
+
|
|
75
|
+
// src/clarity/abi/utils.ts
|
|
76
|
+
function toCamelCase(str) {
|
|
77
|
+
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/-([A-Z])/g, (_, letter) => letter).replace(/-(\d)/g, (_, digit) => digit).replace(/-/g, "").replace(/^\d/, "_$&");
|
|
78
|
+
}
|
|
74
79
|
|
|
75
80
|
// src/utils/c32.ts
|
|
76
81
|
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
@@ -403,103 +408,86 @@ function getContractAddress(deployer, contractName) {
|
|
|
403
408
|
}
|
|
404
409
|
return `${deployer}.${contractName}`;
|
|
405
410
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
SignatureUncompressed: 3
|
|
487
|
-
};
|
|
488
|
-
var RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;
|
|
489
|
-
var MEMO_MAX_LENGTH_BYTES = 34;
|
|
490
|
-
var MAX_STRING_LENGTH_BYTES = 128;
|
|
491
|
-
var COINBASE_BYTES_LENGTH = 32;
|
|
492
|
-
var VRF_PROOF_BYTES_LENGTH = 80;
|
|
493
|
-
var MICROBLOCK_HEADER_BYTES_LENGTH = 132;
|
|
494
|
-
var TenureChangeCause = {
|
|
495
|
-
BlockFound: 0,
|
|
496
|
-
Extended: 1,
|
|
497
|
-
ExtendedRuntime: 2,
|
|
498
|
-
ExtendedReadCount: 3,
|
|
499
|
-
ExtendedReadLength: 4,
|
|
500
|
-
ExtendedWriteCount: 5,
|
|
501
|
-
ExtendedWriteLength: 6
|
|
502
|
-
};
|
|
411
|
+
// src/clarity/abi/guards.ts
|
|
412
|
+
function isUint128(value) {
|
|
413
|
+
return typeof value === "bigint" && value >= 0n && value <= MAX_U128;
|
|
414
|
+
}
|
|
415
|
+
function isInt128(value) {
|
|
416
|
+
return typeof value === "bigint" && value >= MIN_I128 && value <= MAX_I128;
|
|
417
|
+
}
|
|
418
|
+
function isBool(value) {
|
|
419
|
+
return typeof value === "boolean";
|
|
420
|
+
}
|
|
421
|
+
function isPrincipal(value) {
|
|
422
|
+
return typeof value === "string" && parsePrincipal(value) !== null;
|
|
423
|
+
}
|
|
424
|
+
function isStandardPrincipal(value) {
|
|
425
|
+
if (typeof value !== "string")
|
|
426
|
+
return false;
|
|
427
|
+
const parsed = parsePrincipal(value);
|
|
428
|
+
return parsed !== null && parsed.contractName === undefined;
|
|
429
|
+
}
|
|
430
|
+
function isContractPrincipal(value) {
|
|
431
|
+
if (typeof value !== "string")
|
|
432
|
+
return false;
|
|
433
|
+
const parsed = parsePrincipal(value);
|
|
434
|
+
return parsed !== null && parsed.contractName !== undefined;
|
|
435
|
+
}
|
|
436
|
+
function isTraitReference(value) {
|
|
437
|
+
return isContractPrincipal(value);
|
|
438
|
+
}
|
|
439
|
+
function isString(value) {
|
|
440
|
+
return typeof value === "string";
|
|
441
|
+
}
|
|
442
|
+
function isUint8Array(value) {
|
|
443
|
+
return value instanceof Uint8Array;
|
|
444
|
+
}
|
|
445
|
+
function isArray(value, itemGuard) {
|
|
446
|
+
return Array.isArray(value) && value.every(itemGuard);
|
|
447
|
+
}
|
|
448
|
+
function isOptional(value, guard) {
|
|
449
|
+
return value === null || guard(value);
|
|
450
|
+
}
|
|
451
|
+
function isOkResponse(response) {
|
|
452
|
+
return "ok" in response && !("err" in response);
|
|
453
|
+
}
|
|
454
|
+
function isErrResponse(response) {
|
|
455
|
+
return "err" in response && !("ok" in response);
|
|
456
|
+
}
|
|
457
|
+
function isResponse(value, okGuard, errGuard) {
|
|
458
|
+
if (typeof value !== "object" || value === null)
|
|
459
|
+
return false;
|
|
460
|
+
const obj = value;
|
|
461
|
+
if ("ok" in value && !("err" in value))
|
|
462
|
+
return okGuard(obj.ok);
|
|
463
|
+
if ("err" in value && !("ok" in value))
|
|
464
|
+
return errGuard(obj.err);
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
function isAbiList(type) {
|
|
468
|
+
return typeof type === "object" && type !== null && "list" in type;
|
|
469
|
+
}
|
|
470
|
+
function isAbiTuple(type) {
|
|
471
|
+
return typeof type === "object" && type !== null && "tuple" in type;
|
|
472
|
+
}
|
|
473
|
+
function isAbiOptional(type) {
|
|
474
|
+
return typeof type === "object" && type !== null && "optional" in type;
|
|
475
|
+
}
|
|
476
|
+
function isAbiResponse(type) {
|
|
477
|
+
return typeof type === "object" && type !== null && "response" in type;
|
|
478
|
+
}
|
|
479
|
+
function isAbiBuffer(type) {
|
|
480
|
+
return typeof type === "object" && type !== null && "buff" in type;
|
|
481
|
+
}
|
|
482
|
+
function isAbiStringAscii(type) {
|
|
483
|
+
return typeof type === "object" && type !== null && "string-ascii" in type;
|
|
484
|
+
}
|
|
485
|
+
function isAbiStringUtf8(type) {
|
|
486
|
+
return typeof type === "object" && type !== null && "string-utf8" in type;
|
|
487
|
+
}
|
|
488
|
+
function isAbiTraitReference(type) {
|
|
489
|
+
return type === "trait_reference";
|
|
490
|
+
}
|
|
503
491
|
|
|
504
492
|
// src/errors/base.ts
|
|
505
493
|
function codeFromName(name) {
|
|
@@ -663,45 +651,139 @@ function clarityTypeFromByte(byte) {
|
|
|
663
651
|
return type;
|
|
664
652
|
}
|
|
665
653
|
|
|
666
|
-
// src/clarity/
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
return
|
|
671
|
-
}
|
|
672
|
-
function withTypeId(type, bytes) {
|
|
673
|
-
return concatBytes(new Uint8Array([typeIdByte(type)]), bytes);
|
|
654
|
+
// src/clarity/deserialize.ts
|
|
655
|
+
function readAddress(reader) {
|
|
656
|
+
const version = reader.readUInt8();
|
|
657
|
+
const hash160 = bytesToHex(reader.readBytes(20));
|
|
658
|
+
return c32address(version, hash160);
|
|
674
659
|
}
|
|
675
|
-
function
|
|
676
|
-
|
|
677
|
-
|
|
660
|
+
function readLPString(reader, prefixBytes = 1) {
|
|
661
|
+
let length = 0;
|
|
662
|
+
for (let i = 0;i < prefixBytes; i++) {
|
|
663
|
+
length = length << 8 | reader.readUInt8();
|
|
664
|
+
}
|
|
665
|
+
return bytesToUtf8(reader.readBytes(length));
|
|
678
666
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
667
|
+
var MAX_CV_DEPTH = 64;
|
|
668
|
+
var MIN_LIST_ITEM_BYTES = 1;
|
|
669
|
+
var MIN_TUPLE_ENTRY_BYTES = 2;
|
|
670
|
+
function checkCount(reader, count, minBytes) {
|
|
671
|
+
if (count * minBytes > reader.remaining()) {
|
|
672
|
+
throw new SerializationError(`Clarity value declares ${count} elements but only ${reader.remaining()} bytes remain`);
|
|
673
|
+
}
|
|
683
674
|
}
|
|
684
|
-
function
|
|
685
|
-
|
|
675
|
+
function readCV(reader, depth = 0) {
|
|
676
|
+
if (depth > MAX_CV_DEPTH) {
|
|
677
|
+
throw new SerializationError(`Clarity value nests deeper than ${MAX_CV_DEPTH} levels`);
|
|
678
|
+
}
|
|
679
|
+
const typeByte = reader.readUInt8();
|
|
680
|
+
const type = clarityTypeFromByte(typeByte);
|
|
681
|
+
switch (type) {
|
|
682
|
+
case "int":
|
|
683
|
+
return intCV(bytesToTwosBigInt(reader.readBytes(16)));
|
|
684
|
+
case "uint":
|
|
685
|
+
return uintCV(reader.readBytes(16));
|
|
686
686
|
case "true":
|
|
687
|
+
return trueCV();
|
|
687
688
|
case "false":
|
|
688
|
-
return
|
|
689
|
-
case "int": {
|
|
690
|
-
const bytes = bigIntToBytes(toTwos(BigInt(value.value), CLARITY_INT_SIZE), CLARITY_INT_BYTE_SIZE);
|
|
691
|
-
return withTypeId(value.type, bytes);
|
|
692
|
-
}
|
|
693
|
-
case "uint": {
|
|
694
|
-
const bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);
|
|
695
|
-
return withTypeId(value.type, bytes);
|
|
696
|
-
}
|
|
689
|
+
return falseCV();
|
|
697
690
|
case "buffer": {
|
|
698
|
-
const
|
|
699
|
-
return
|
|
691
|
+
const len = reader.readUInt32BE();
|
|
692
|
+
return bufferCV(reader.readBytes(len));
|
|
700
693
|
}
|
|
701
694
|
case "none":
|
|
702
|
-
return
|
|
695
|
+
return noneCV();
|
|
703
696
|
case "some":
|
|
704
|
-
return
|
|
697
|
+
return someCV(readCV(reader, depth + 1));
|
|
698
|
+
case "ok":
|
|
699
|
+
return responseOkCV(readCV(reader, depth + 1));
|
|
700
|
+
case "err":
|
|
701
|
+
return responseErrorCV(readCV(reader, depth + 1));
|
|
702
|
+
case "address":
|
|
703
|
+
return standardPrincipalCV(readAddress(reader));
|
|
704
|
+
case "contract": {
|
|
705
|
+
const addr = readAddress(reader);
|
|
706
|
+
const name = readLPString(reader);
|
|
707
|
+
return contractPrincipalCV(addr, name);
|
|
708
|
+
}
|
|
709
|
+
case "list": {
|
|
710
|
+
const len = reader.readUInt32BE();
|
|
711
|
+
checkCount(reader, len, MIN_LIST_ITEM_BYTES);
|
|
712
|
+
const items = [];
|
|
713
|
+
for (let i = 0;i < len; i++) {
|
|
714
|
+
items.push(readCV(reader, depth + 1));
|
|
715
|
+
}
|
|
716
|
+
return listCV(items);
|
|
717
|
+
}
|
|
718
|
+
case "tuple": {
|
|
719
|
+
const len = reader.readUInt32BE();
|
|
720
|
+
checkCount(reader, len, MIN_TUPLE_ENTRY_BYTES);
|
|
721
|
+
const data = {};
|
|
722
|
+
for (let i = 0;i < len; i++) {
|
|
723
|
+
const key = readLPString(reader);
|
|
724
|
+
data[key] = readCV(reader, depth + 1);
|
|
725
|
+
}
|
|
726
|
+
return tupleCV(data);
|
|
727
|
+
}
|
|
728
|
+
case "ascii": {
|
|
729
|
+
const len = reader.readUInt32BE();
|
|
730
|
+
return stringAsciiCV(bytesToAscii(reader.readBytes(len)));
|
|
731
|
+
}
|
|
732
|
+
case "utf8": {
|
|
733
|
+
const len = reader.readUInt32BE();
|
|
734
|
+
return stringUtf8CV(bytesToUtf8(reader.readBytes(len)));
|
|
735
|
+
}
|
|
736
|
+
default:
|
|
737
|
+
throw new SerializationError(`Cannot deserialize unknown clarity type: ${type}`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
function deserializeCVBytes(input) {
|
|
741
|
+
const bytes = typeof input === "string" ? hexToBytes(without0x(input)) : input;
|
|
742
|
+
return readCV(new BytesReader(bytes));
|
|
743
|
+
}
|
|
744
|
+
function deserializeCV(input) {
|
|
745
|
+
return deserializeCVBytes(input);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// src/clarity/serialize.ts
|
|
749
|
+
var CLARITY_INT_SIZE = 128n;
|
|
750
|
+
var CLARITY_INT_BYTE_SIZE = 16;
|
|
751
|
+
function typeIdByte(type) {
|
|
752
|
+
return ClarityWireType[type];
|
|
753
|
+
}
|
|
754
|
+
function withTypeId(type, bytes) {
|
|
755
|
+
return concatBytes(new Uint8Array([typeIdByte(type)]), bytes);
|
|
756
|
+
}
|
|
757
|
+
function serializeAddress(c32Address) {
|
|
758
|
+
const [version, hash160] = c32addressDecode(c32Address);
|
|
759
|
+
return concatBytes(new Uint8Array([version]), hexToBytes(hash160));
|
|
760
|
+
}
|
|
761
|
+
function serializeLPString(str, prefixBytes = 1) {
|
|
762
|
+
const content = utf8ToBytes(str);
|
|
763
|
+
const lengthPrefix = hexToBytes(intToHex(content.byteLength, prefixBytes));
|
|
764
|
+
return concatBytes(lengthPrefix, content);
|
|
765
|
+
}
|
|
766
|
+
function serializeCVBytes(value) {
|
|
767
|
+
switch (value.type) {
|
|
768
|
+
case "true":
|
|
769
|
+
case "false":
|
|
770
|
+
return new Uint8Array([typeIdByte(value.type)]);
|
|
771
|
+
case "int": {
|
|
772
|
+
const bytes = bigIntToBytes(toTwos(BigInt(value.value), CLARITY_INT_SIZE), CLARITY_INT_BYTE_SIZE);
|
|
773
|
+
return withTypeId(value.type, bytes);
|
|
774
|
+
}
|
|
775
|
+
case "uint": {
|
|
776
|
+
const bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);
|
|
777
|
+
return withTypeId(value.type, bytes);
|
|
778
|
+
}
|
|
779
|
+
case "buffer": {
|
|
780
|
+
const bufBytes = hexToBytes(value.value);
|
|
781
|
+
return withTypeId(value.type, concatBytes(writeUInt32BE(bufBytes.length), bufBytes));
|
|
782
|
+
}
|
|
783
|
+
case "none":
|
|
784
|
+
return new Uint8Array([typeIdByte(value.type)]);
|
|
785
|
+
case "some":
|
|
786
|
+
return withTypeId(value.type, serializeCVBytes(value.value));
|
|
705
787
|
case "ok":
|
|
706
788
|
case "err":
|
|
707
789
|
return withTypeId(value.type, serializeCVBytes(value.value));
|
|
@@ -781,13 +863,13 @@ function bufferCV(buffer) {
|
|
|
781
863
|
return { type: "buffer", value: bytesToHex(buffer) };
|
|
782
864
|
}
|
|
783
865
|
function standardPrincipalCV(address) {
|
|
784
|
-
const [version,
|
|
785
|
-
const normalized = c32address(version,
|
|
866
|
+
const [version, hash160] = c32addressDecode(address);
|
|
867
|
+
const normalized = c32address(version, hash160);
|
|
786
868
|
return { type: "address", value: normalized };
|
|
787
869
|
}
|
|
788
870
|
function contractPrincipalCV(address, contractName) {
|
|
789
|
-
const [version,
|
|
790
|
-
const normalized = c32address(version,
|
|
871
|
+
const [version, hash160] = c32addressDecode(address);
|
|
872
|
+
const normalized = c32address(version, hash160);
|
|
791
873
|
if (utf8ToBytes(contractName).byteLength >= 128) {
|
|
792
874
|
throw new Error("Contract name must be less than 128 bytes");
|
|
793
875
|
}
|
|
@@ -855,102 +937,284 @@ var Cl = {
|
|
|
855
937
|
deserialize: deserializeCVBytes
|
|
856
938
|
};
|
|
857
939
|
|
|
858
|
-
// src/clarity/
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
940
|
+
// src/clarity/bridge.ts
|
|
941
|
+
var CV_TYPE_TAGS = new Set([
|
|
942
|
+
"int",
|
|
943
|
+
"uint",
|
|
944
|
+
"true",
|
|
945
|
+
"false",
|
|
946
|
+
"address",
|
|
947
|
+
"contract",
|
|
948
|
+
"ascii",
|
|
949
|
+
"utf8",
|
|
950
|
+
"buffer",
|
|
951
|
+
"list",
|
|
952
|
+
"tuple",
|
|
953
|
+
"none",
|
|
954
|
+
"some",
|
|
955
|
+
"ok",
|
|
956
|
+
"err"
|
|
957
|
+
]);
|
|
958
|
+
function isClarityValue(value) {
|
|
959
|
+
if (typeof value !== "object" || value === null)
|
|
960
|
+
return false;
|
|
961
|
+
const type = value.type;
|
|
962
|
+
if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
|
|
963
|
+
return false;
|
|
964
|
+
if (type === "true" || type === "false" || type === "none")
|
|
965
|
+
return true;
|
|
966
|
+
return "value" in value;
|
|
863
967
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
968
|
+
var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
|
|
969
|
+
function coerceBuffer(value) {
|
|
970
|
+
if (value instanceof Uint8Array)
|
|
971
|
+
return bufferCV(value);
|
|
972
|
+
if (typeof value === "object" && value !== null && "type" in value) {
|
|
973
|
+
const tagged = value;
|
|
974
|
+
if (tagged.type === "buffer" && isClarityValue(value))
|
|
975
|
+
return value;
|
|
976
|
+
if (typeof tagged.value === "string") {
|
|
977
|
+
if (tagged.type === "ascii")
|
|
978
|
+
return Cl.bufferFromAscii(tagged.value);
|
|
979
|
+
if (tagged.type === "utf8")
|
|
980
|
+
return Cl.bufferFromUtf8(tagged.value);
|
|
981
|
+
if (tagged.type === "hex")
|
|
982
|
+
return Cl.bufferFromHex(tagged.value);
|
|
983
|
+
}
|
|
984
|
+
throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
|
|
868
985
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
function checkCount(reader, count, minBytes) {
|
|
875
|
-
if (count * minBytes > reader.remaining()) {
|
|
876
|
-
throw new SerializationError(`Clarity value declares ${count} elements but only ${reader.remaining()} bytes remain`);
|
|
986
|
+
if (typeof value === "string") {
|
|
987
|
+
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
988
|
+
if (HEX_PAIRS_REGEX.test(hex))
|
|
989
|
+
return Cl.bufferFromHex(hex);
|
|
990
|
+
return Cl.bufferFromUtf8(value);
|
|
877
991
|
}
|
|
992
|
+
throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
|
|
878
993
|
}
|
|
879
|
-
function
|
|
880
|
-
if (
|
|
881
|
-
|
|
994
|
+
function jsToClarityValue(abiType, value) {
|
|
995
|
+
if (isAbiBuffer(abiType))
|
|
996
|
+
return coerceBuffer(value);
|
|
997
|
+
if (isClarityValue(value))
|
|
998
|
+
return value;
|
|
999
|
+
if (abiType === "uint128")
|
|
1000
|
+
return uintCV(value);
|
|
1001
|
+
if (abiType === "int128")
|
|
1002
|
+
return intCV(value);
|
|
1003
|
+
if (abiType === "bool")
|
|
1004
|
+
return boolCV(value);
|
|
1005
|
+
if (abiType === "principal" || abiType === "trait_reference")
|
|
1006
|
+
return Cl.principal(value);
|
|
1007
|
+
if (isAbiStringAscii(abiType))
|
|
1008
|
+
return stringAsciiCV(value);
|
|
1009
|
+
if (isAbiStringUtf8(abiType))
|
|
1010
|
+
return stringUtf8CV(value);
|
|
1011
|
+
if (isAbiList(abiType)) {
|
|
1012
|
+
const arr = value;
|
|
1013
|
+
return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
|
|
882
1014
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
return falseCV();
|
|
894
|
-
case "buffer": {
|
|
895
|
-
const len = reader.readUInt32BE();
|
|
896
|
-
return bufferCV(reader.readBytes(len));
|
|
897
|
-
}
|
|
898
|
-
case "none":
|
|
899
|
-
return noneCV();
|
|
900
|
-
case "some":
|
|
901
|
-
return someCV(readCV(reader, depth + 1));
|
|
902
|
-
case "ok":
|
|
903
|
-
return responseOkCV(readCV(reader, depth + 1));
|
|
904
|
-
case "err":
|
|
905
|
-
return responseErrorCV(readCV(reader, depth + 1));
|
|
906
|
-
case "address":
|
|
907
|
-
return standardPrincipalCV(readAddress(reader));
|
|
908
|
-
case "contract": {
|
|
909
|
-
const addr = readAddress(reader);
|
|
910
|
-
const name = readLPString(reader);
|
|
911
|
-
return contractPrincipalCV(addr, name);
|
|
912
|
-
}
|
|
913
|
-
case "list": {
|
|
914
|
-
const len = reader.readUInt32BE();
|
|
915
|
-
checkCount(reader, len, MIN_LIST_ITEM_BYTES);
|
|
916
|
-
const items = [];
|
|
917
|
-
for (let i = 0;i < len; i++) {
|
|
918
|
-
items.push(readCV(reader, depth + 1));
|
|
919
|
-
}
|
|
920
|
-
return listCV(items);
|
|
921
|
-
}
|
|
922
|
-
case "tuple": {
|
|
923
|
-
const len = reader.readUInt32BE();
|
|
924
|
-
checkCount(reader, len, MIN_TUPLE_ENTRY_BYTES);
|
|
925
|
-
const data = {};
|
|
926
|
-
for (let i = 0;i < len; i++) {
|
|
927
|
-
const key = readLPString(reader);
|
|
928
|
-
data[key] = readCV(reader, depth + 1);
|
|
1015
|
+
if (isAbiTuple(abiType)) {
|
|
1016
|
+
const obj = value;
|
|
1017
|
+
const data = {};
|
|
1018
|
+
for (const field of abiType.tuple) {
|
|
1019
|
+
const camelKey = toCamelCase(field.name);
|
|
1020
|
+
const hasOriginal = field.name in obj;
|
|
1021
|
+
const hasCamel = camelKey in obj;
|
|
1022
|
+
const fieldValue = hasOriginal ? obj[field.name] : hasCamel ? obj[camelKey] : undefined;
|
|
1023
|
+
if (fieldValue === undefined && !isAbiOptional(field.type)) {
|
|
1024
|
+
throw new Error(`Missing tuple field: ${field.name}`);
|
|
929
1025
|
}
|
|
930
|
-
|
|
931
|
-
}
|
|
932
|
-
case "ascii": {
|
|
933
|
-
const len = reader.readUInt32BE();
|
|
934
|
-
return stringAsciiCV(bytesToAscii(reader.readBytes(len)));
|
|
935
|
-
}
|
|
936
|
-
case "utf8": {
|
|
937
|
-
const len = reader.readUInt32BE();
|
|
938
|
-
return stringUtf8CV(bytesToUtf8(reader.readBytes(len)));
|
|
1026
|
+
data[field.name] = jsToClarityValue(field.type, fieldValue);
|
|
939
1027
|
}
|
|
940
|
-
|
|
941
|
-
throw new SerializationError(`Cannot deserialize unknown clarity type: ${type}`);
|
|
1028
|
+
return tupleCV(data);
|
|
942
1029
|
}
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1030
|
+
if (isAbiOptional(abiType)) {
|
|
1031
|
+
if (value === null || value === undefined)
|
|
1032
|
+
return noneCV();
|
|
1033
|
+
return someCV(jsToClarityValue(abiType.optional, value));
|
|
1034
|
+
}
|
|
1035
|
+
if (isAbiResponse(abiType)) {
|
|
1036
|
+
const obj = value;
|
|
1037
|
+
if ("ok" in obj && !("err" in obj))
|
|
1038
|
+
return responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));
|
|
1039
|
+
if ("err" in obj && !("ok" in obj))
|
|
1040
|
+
return responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));
|
|
1041
|
+
throw new Error("Response must have exactly 'ok' or 'err' property");
|
|
1042
|
+
}
|
|
1043
|
+
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
1044
|
+
}
|
|
1045
|
+
function clarityValueToJS(abiType, cv) {
|
|
1046
|
+
return clarityValueToJSInner(abiType, cv);
|
|
1047
|
+
}
|
|
1048
|
+
function clarityValueToJSUntyped(abiType, cv) {
|
|
1049
|
+
return clarityValueToJSInner(abiType, cv);
|
|
1050
|
+
}
|
|
1051
|
+
function clarityValueToJSInner(abiType, cv) {
|
|
1052
|
+
if (abiType === "uint128" || abiType === "int128") {
|
|
1053
|
+
if (cv.type !== "int" && cv.type !== "uint")
|
|
1054
|
+
throw new Error(`Expected int/uint CV, got ${cv.type}`);
|
|
1055
|
+
return cv.value;
|
|
1056
|
+
}
|
|
1057
|
+
if (abiType === "bool") {
|
|
1058
|
+
if (cv.type === "true")
|
|
1059
|
+
return true;
|
|
1060
|
+
if (cv.type === "false")
|
|
1061
|
+
return false;
|
|
1062
|
+
throw new Error(`Expected bool CV, got ${cv.type}`);
|
|
1063
|
+
}
|
|
1064
|
+
if (abiType === "principal" || abiType === "trait_reference") {
|
|
1065
|
+
if (cv.type !== "address" && cv.type !== "contract")
|
|
1066
|
+
throw new Error(`Expected principal CV, got ${cv.type}`);
|
|
1067
|
+
return cv.value;
|
|
1068
|
+
}
|
|
1069
|
+
if (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {
|
|
1070
|
+
if (cv.type !== "ascii" && cv.type !== "utf8")
|
|
1071
|
+
throw new Error(`Expected string CV, got ${cv.type}`);
|
|
1072
|
+
return cv.value;
|
|
1073
|
+
}
|
|
1074
|
+
if (isAbiBuffer(abiType)) {
|
|
1075
|
+
if (cv.type !== "buffer")
|
|
1076
|
+
throw new Error(`Expected buffer CV, got ${cv.type}`);
|
|
1077
|
+
const hex = cv.value;
|
|
1078
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
1079
|
+
for (let i = 0;i < bytes.length; i++) {
|
|
1080
|
+
bytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
1081
|
+
}
|
|
1082
|
+
return bytes;
|
|
1083
|
+
}
|
|
1084
|
+
if (isAbiList(abiType)) {
|
|
1085
|
+
if (cv.type !== "list")
|
|
1086
|
+
throw new Error(`Expected list CV, got ${cv.type}`);
|
|
1087
|
+
return cv.value.map((item) => clarityValueToJSInner(abiType.list.type, item));
|
|
1088
|
+
}
|
|
1089
|
+
if (isAbiTuple(abiType)) {
|
|
1090
|
+
if (cv.type !== "tuple")
|
|
1091
|
+
throw new Error(`Expected tuple CV, got ${cv.type}`);
|
|
1092
|
+
const result = {};
|
|
1093
|
+
for (const field of abiType.tuple) {
|
|
1094
|
+
const fieldCV = cv.value[field.name];
|
|
1095
|
+
if (!fieldCV)
|
|
1096
|
+
throw new Error(`Missing tuple field in CV: ${field.name}`);
|
|
1097
|
+
const camelKey = toCamelCase(field.name);
|
|
1098
|
+
result[camelKey] = clarityValueToJSInner(field.type, fieldCV);
|
|
1099
|
+
}
|
|
1100
|
+
return result;
|
|
1101
|
+
}
|
|
1102
|
+
if (isAbiOptional(abiType)) {
|
|
1103
|
+
if (cv.type === "none")
|
|
1104
|
+
return null;
|
|
1105
|
+
if (cv.type === "some")
|
|
1106
|
+
return clarityValueToJSInner(abiType.optional, cv.value);
|
|
1107
|
+
throw new Error(`Expected optional CV, got ${cv.type}`);
|
|
1108
|
+
}
|
|
1109
|
+
if (isAbiResponse(abiType)) {
|
|
1110
|
+
if (cv.type === "ok")
|
|
1111
|
+
return { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };
|
|
1112
|
+
if (cv.type === "err")
|
|
1113
|
+
return { err: clarityValueToJSInner(abiType.response.error, cv.value) };
|
|
1114
|
+
throw new Error(`Expected response CV, got ${cv.type}`);
|
|
1115
|
+
}
|
|
1116
|
+
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// src/transactions/types.ts
|
|
1120
|
+
var AuthType = {
|
|
1121
|
+
Standard: 4,
|
|
1122
|
+
Sponsored: 5
|
|
1123
|
+
};
|
|
1124
|
+
var PayloadType = {
|
|
1125
|
+
TokenTransfer: 0,
|
|
1126
|
+
SmartContract: 1,
|
|
1127
|
+
ContractCall: 2,
|
|
1128
|
+
PoisonMicroblock: 3,
|
|
1129
|
+
Coinbase: 4,
|
|
1130
|
+
CoinbaseToAltRecipient: 5,
|
|
1131
|
+
VersionedSmartContract: 6,
|
|
1132
|
+
TenureChange: 7,
|
|
1133
|
+
NakamotoCoinbase: 8
|
|
1134
|
+
};
|
|
1135
|
+
var ClarityVersion = {
|
|
1136
|
+
Clarity1: 1,
|
|
1137
|
+
Clarity2: 2,
|
|
1138
|
+
Clarity3: 3,
|
|
1139
|
+
Clarity4: 4,
|
|
1140
|
+
Clarity5: 5,
|
|
1141
|
+
Clarity6: 6
|
|
1142
|
+
};
|
|
1143
|
+
var AnchorMode = {
|
|
1144
|
+
OnChainOnly: 1,
|
|
1145
|
+
OffChainOnly: 2,
|
|
1146
|
+
Any: 3
|
|
1147
|
+
};
|
|
1148
|
+
var PostConditionModeWire = {
|
|
1149
|
+
Allow: 1,
|
|
1150
|
+
Deny: 2,
|
|
1151
|
+
Originator: 3
|
|
1152
|
+
};
|
|
1153
|
+
var AddressHashMode = {
|
|
1154
|
+
P2PKH: 0,
|
|
1155
|
+
P2SH: 1,
|
|
1156
|
+
P2WPKH: 2,
|
|
1157
|
+
P2WSH: 3,
|
|
1158
|
+
P2SH_NonSequential: 5,
|
|
1159
|
+
P2WSH_P2SH_NonSequential: 7
|
|
1160
|
+
};
|
|
1161
|
+
var PubKeyEncoding = {
|
|
1162
|
+
Compressed: 0,
|
|
1163
|
+
Uncompressed: 1
|
|
1164
|
+
};
|
|
1165
|
+
var FungibleConditionCode = {
|
|
1166
|
+
Equal: 1,
|
|
1167
|
+
Greater: 2,
|
|
1168
|
+
GreaterEqual: 3,
|
|
1169
|
+
Less: 4,
|
|
1170
|
+
LessEqual: 5
|
|
1171
|
+
};
|
|
1172
|
+
var NonFungibleConditionCode = {
|
|
1173
|
+
Sends: 16,
|
|
1174
|
+
DoesNotSend: 17,
|
|
1175
|
+
MaybeSent: 18
|
|
1176
|
+
};
|
|
1177
|
+
var PoxConditionCode = {
|
|
1178
|
+
WillNotPerform: 48,
|
|
1179
|
+
MayPerform: 49,
|
|
1180
|
+
WillPerform: 50
|
|
1181
|
+
};
|
|
1182
|
+
var PostConditionPrincipalId = {
|
|
1183
|
+
Origin: 1,
|
|
1184
|
+
Standard: 2,
|
|
1185
|
+
Contract: 3
|
|
1186
|
+
};
|
|
1187
|
+
var AssetType = {
|
|
1188
|
+
STX: 0,
|
|
1189
|
+
Fungible: 1,
|
|
1190
|
+
NonFungible: 2,
|
|
1191
|
+
Staking: 3,
|
|
1192
|
+
Pox: 4
|
|
1193
|
+
};
|
|
1194
|
+
var AuthFieldType = {
|
|
1195
|
+
PublicKeyCompressed: 0,
|
|
1196
|
+
PublicKeyUncompressed: 1,
|
|
1197
|
+
SignatureCompressed: 2,
|
|
1198
|
+
SignatureUncompressed: 3
|
|
1199
|
+
};
|
|
1200
|
+
var RECOVERABLE_ECDSA_SIG_LENGTH_BYTES = 65;
|
|
1201
|
+
var MEMO_MAX_LENGTH_BYTES = 34;
|
|
1202
|
+
var MAX_STRING_LENGTH_BYTES = 128;
|
|
1203
|
+
var COINBASE_BYTES_LENGTH = 32;
|
|
1204
|
+
var VRF_PROOF_BYTES_LENGTH = 80;
|
|
1205
|
+
var MICROBLOCK_HEADER_BYTES_LENGTH = 132;
|
|
1206
|
+
var TenureChangeCause = {
|
|
1207
|
+
BlockFound: 0,
|
|
1208
|
+
Extended: 1,
|
|
1209
|
+
ExtendedRuntime: 2,
|
|
1210
|
+
ExtendedReadCount: 3,
|
|
1211
|
+
ExtendedReadLength: 4,
|
|
1212
|
+
ExtendedWriteCount: 5,
|
|
1213
|
+
ExtendedWriteLength: 6
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
// src/transactions/wire/deserialize.ts
|
|
1217
|
+
function readSpendingCondition(r) {
|
|
954
1218
|
const hashMode = r.readUInt8();
|
|
955
1219
|
const signer = bytesToHex(r.readBytes(20));
|
|
956
1220
|
const nonce = r.readBigUInt64BE();
|
|
@@ -1216,8 +1480,8 @@ function deserializeTransaction(input, meta) {
|
|
|
1216
1480
|
|
|
1217
1481
|
// src/transactions/wire/serialize.ts
|
|
1218
1482
|
function serializeAddress2(c32Address) {
|
|
1219
|
-
const [version,
|
|
1220
|
-
return concatBytes(new Uint8Array([version]), hexToBytes(
|
|
1483
|
+
const [version, hash160] = c32addressDecode(c32Address);
|
|
1484
|
+
return concatBytes(new Uint8Array([version]), hexToBytes(hash160));
|
|
1221
1485
|
}
|
|
1222
1486
|
function serializeLPString2(str, prefixBytes = 1) {
|
|
1223
1487
|
const content = utf8ToBytes(str);
|
|
@@ -1256,8 +1520,8 @@ function serializeSpendingCondition(condition) {
|
|
|
1256
1520
|
}
|
|
1257
1521
|
function serializeAuthField(field) {
|
|
1258
1522
|
if (field.type === "publicKey") {
|
|
1259
|
-
const
|
|
1260
|
-
return concatBytes(writeUInt8(
|
|
1523
|
+
const typeId = field.pubKeyEncoding === 0 ? 0 : 1;
|
|
1524
|
+
return concatBytes(writeUInt8(typeId), hexToBytes(field.data));
|
|
1261
1525
|
}
|
|
1262
1526
|
const typeId = field.pubKeyEncoding === 0 ? 2 : 3;
|
|
1263
1527
|
return concatBytes(writeUInt8(typeId), hexToBytes(field.data));
|
|
@@ -1544,456 +1808,41 @@ function wireToPostCondition(wire) {
|
|
|
1544
1808
|
case "staking":
|
|
1545
1809
|
return {
|
|
1546
1810
|
type: "staking-postcondition",
|
|
1547
|
-
address: principalToString(wire.principal),
|
|
1548
|
-
condition: fungibleName(wire.conditionCode),
|
|
1549
|
-
amount: wire.amount.toString()
|
|
1550
|
-
};
|
|
1551
|
-
case "pox":
|
|
1552
|
-
return {
|
|
1553
|
-
type: "pox-postcondition",
|
|
1554
|
-
address: principalToString(wire.principal),
|
|
1555
|
-
condition: poxName(wire.conditionCode)
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
function fungibleName(code) {
|
|
1560
|
-
const name = FUNGIBLE_CODE_REVERSE[code];
|
|
1561
|
-
if (!name)
|
|
1562
|
-
throw new Error(`Unknown fungible post-condition code: ${code}`);
|
|
1563
|
-
return name;
|
|
1564
|
-
}
|
|
1565
|
-
function nftName(code) {
|
|
1566
|
-
const name = NFT_CODE_REVERSE[code];
|
|
1567
|
-
if (!name)
|
|
1568
|
-
throw new Error(`Unknown nft post-condition code: ${code}`);
|
|
1569
|
-
return name;
|
|
1570
|
-
}
|
|
1571
|
-
function poxName(code) {
|
|
1572
|
-
const name = POX_CODE_REVERSE[code];
|
|
1573
|
-
if (!name)
|
|
1574
|
-
throw new Error(`Unknown pox post-condition code: ${code}`);
|
|
1575
|
-
return name;
|
|
1576
|
-
}
|
|
1577
|
-
function fromHex(hex) {
|
|
1578
|
-
return wireToPostCondition(deserializePostConditionWire(hex));
|
|
1579
|
-
}
|
|
1580
|
-
function postConditionToHex(pc) {
|
|
1581
|
-
return bytesToHex(serializePostConditionWire(convertPostCondition(pc)));
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
// src/postconditions/builder.ts
|
|
1585
|
-
class PartialPcWithPrincipal {
|
|
1586
|
-
address;
|
|
1587
|
-
constructor(address) {
|
|
1588
|
-
this.address = address;
|
|
1589
|
-
}
|
|
1590
|
-
willSendEq(amount) {
|
|
1591
|
-
return new PartialPcFtWithCode(this.address, amount, "eq");
|
|
1592
|
-
}
|
|
1593
|
-
willSendGte(amount) {
|
|
1594
|
-
return new PartialPcFtWithCode(this.address, amount, "gte");
|
|
1595
|
-
}
|
|
1596
|
-
willSendGt(amount) {
|
|
1597
|
-
return new PartialPcFtWithCode(this.address, amount, "gt");
|
|
1598
|
-
}
|
|
1599
|
-
willSendLte(amount) {
|
|
1600
|
-
return new PartialPcFtWithCode(this.address, amount, "lte");
|
|
1601
|
-
}
|
|
1602
|
-
willSendLt(amount) {
|
|
1603
|
-
return new PartialPcFtWithCode(this.address, amount, "lt");
|
|
1604
|
-
}
|
|
1605
|
-
willSendAsset() {
|
|
1606
|
-
return new PartialPcNftWithCode(this.address, "sent");
|
|
1607
|
-
}
|
|
1608
|
-
willNotSendAsset() {
|
|
1609
|
-
return new PartialPcNftWithCode(this.address, "not-sent");
|
|
1610
|
-
}
|
|
1611
|
-
willMaybeSendAsset() {
|
|
1612
|
-
return new PartialPcNftWithCode(this.address, "maybe-sent");
|
|
1613
|
-
}
|
|
1614
|
-
willPerformPox() {
|
|
1615
|
-
return {
|
|
1616
|
-
type: "pox-postcondition",
|
|
1617
|
-
address: this.address,
|
|
1618
|
-
condition: "will-perform"
|
|
1619
|
-
};
|
|
1620
|
-
}
|
|
1621
|
-
willNotPerformPox() {
|
|
1622
|
-
return {
|
|
1623
|
-
type: "pox-postcondition",
|
|
1624
|
-
address: this.address,
|
|
1625
|
-
condition: "will-not-perform"
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
|
-
mayPerformPox() {
|
|
1629
|
-
return {
|
|
1630
|
-
type: "pox-postcondition",
|
|
1631
|
-
address: this.address,
|
|
1632
|
-
condition: "may-perform"
|
|
1633
|
-
};
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1637
|
-
class PartialPcFtWithCode {
|
|
1638
|
-
address;
|
|
1639
|
-
amount;
|
|
1640
|
-
code;
|
|
1641
|
-
constructor(address, amount, code) {
|
|
1642
|
-
this.address = address;
|
|
1643
|
-
this.amount = amount;
|
|
1644
|
-
this.code = code;
|
|
1645
|
-
}
|
|
1646
|
-
ustx() {
|
|
1647
|
-
return {
|
|
1648
|
-
type: "stx-postcondition",
|
|
1649
|
-
address: this.address,
|
|
1650
|
-
condition: this.code,
|
|
1651
|
-
amount: parsePostConditionAmount(this.amount).toString()
|
|
1652
|
-
};
|
|
1653
|
-
}
|
|
1654
|
-
ustxToLock() {
|
|
1655
|
-
return {
|
|
1656
|
-
type: "staking-postcondition",
|
|
1657
|
-
address: this.address,
|
|
1658
|
-
condition: this.code,
|
|
1659
|
-
amount: parsePostConditionAmount(this.amount).toString()
|
|
1660
|
-
};
|
|
1661
|
-
}
|
|
1662
|
-
ft(contractId, tokenName) {
|
|
1663
|
-
const [address, name] = contractId.split(".");
|
|
1664
|
-
if (!address || !validateStacksAddress(address) || !name) {
|
|
1665
|
-
throw new Error(`Invalid contract id: ${contractId}`);
|
|
1666
|
-
}
|
|
1667
|
-
return {
|
|
1668
|
-
type: "ft-postcondition",
|
|
1669
|
-
address: this.address,
|
|
1670
|
-
condition: this.code,
|
|
1671
|
-
amount: parsePostConditionAmount(this.amount).toString(),
|
|
1672
|
-
asset: `${contractId}::${tokenName}`
|
|
1673
|
-
};
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
class PartialPcNftWithCode {
|
|
1678
|
-
address;
|
|
1679
|
-
code;
|
|
1680
|
-
constructor(address, code) {
|
|
1681
|
-
this.address = address;
|
|
1682
|
-
this.code = code;
|
|
1683
|
-
}
|
|
1684
|
-
nft(assetOrContractId, tokenNameOrAssetId, assetId) {
|
|
1685
|
-
let contractAddress;
|
|
1686
|
-
let contractName;
|
|
1687
|
-
let tokenName;
|
|
1688
|
-
let id;
|
|
1689
|
-
if (assetId !== undefined) {
|
|
1690
|
-
[contractAddress, contractName] = parseContractId(assetOrContractId);
|
|
1691
|
-
tokenName = tokenNameOrAssetId;
|
|
1692
|
-
id = assetId;
|
|
1693
|
-
} else {
|
|
1694
|
-
const [principal, tName] = assetOrContractId.split("::");
|
|
1695
|
-
if (!principal || !tName)
|
|
1696
|
-
throw new Error(`Invalid asset name: ${assetOrContractId}`);
|
|
1697
|
-
[contractAddress, contractName] = parseContractId(principal);
|
|
1698
|
-
tokenName = tName;
|
|
1699
|
-
id = tokenNameOrAssetId;
|
|
1700
|
-
}
|
|
1701
|
-
if (!validateStacksAddress(contractAddress)) {
|
|
1702
|
-
throw new Error(`Invalid contract address: ${contractAddress}`);
|
|
1703
|
-
}
|
|
1704
|
-
return {
|
|
1705
|
-
type: "nft-postcondition",
|
|
1706
|
-
address: this.address,
|
|
1707
|
-
condition: this.code,
|
|
1708
|
-
asset: `${contractAddress}.${contractName}::${tokenName}`,
|
|
1709
|
-
assetId: id
|
|
1710
|
-
};
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
var Pc = {
|
|
1714
|
-
principal(address) {
|
|
1715
|
-
const [addr, name] = address.split(".");
|
|
1716
|
-
if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
|
|
1717
|
-
throw new Error(`Invalid principal: ${address}`);
|
|
1718
|
-
}
|
|
1719
|
-
return new PartialPcWithPrincipal(address);
|
|
1720
|
-
},
|
|
1721
|
-
origin() {
|
|
1722
|
-
return new PartialPcWithPrincipal("origin");
|
|
1723
|
-
},
|
|
1724
|
-
fromHex: (hex) => fromHex(hex)
|
|
1725
|
-
};
|
|
1726
|
-
// src/stackingdao/index.ts
|
|
1727
|
-
var exports_stackingdao = {};
|
|
1728
|
-
__export(exports_stackingdao, {
|
|
1729
|
-
stackingDao: () => stackingDao,
|
|
1730
|
-
TRAIT_CONTRACTS: () => TRAIT_CONTRACTS,
|
|
1731
|
-
STACKINGDAO_CONTRACTS: () => STACKINGDAO_CONTRACTS
|
|
1732
|
-
});
|
|
1733
|
-
module.exports = __toCommonJS(exports_stackingdao);
|
|
1734
|
-
|
|
1735
|
-
// src/clarity/abi/utils.ts
|
|
1736
|
-
function toCamelCase(str) {
|
|
1737
|
-
return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/-([A-Z])/g, (_, letter) => letter).replace(/-(\d)/g, (_, digit) => digit).replace(/-/g, "").replace(/^\d/, "_$&");
|
|
1738
|
-
}
|
|
1739
|
-
// src/clarity/abi/guards.ts
|
|
1740
|
-
function isUint128(value) {
|
|
1741
|
-
return typeof value === "bigint" && value >= 0n && value <= MAX_U128;
|
|
1742
|
-
}
|
|
1743
|
-
function isInt128(value) {
|
|
1744
|
-
return typeof value === "bigint" && value >= MIN_I128 && value <= MAX_I128;
|
|
1745
|
-
}
|
|
1746
|
-
function isBool(value) {
|
|
1747
|
-
return typeof value === "boolean";
|
|
1748
|
-
}
|
|
1749
|
-
function isPrincipal(value) {
|
|
1750
|
-
return typeof value === "string" && parsePrincipal(value) !== null;
|
|
1751
|
-
}
|
|
1752
|
-
function isStandardPrincipal(value) {
|
|
1753
|
-
if (typeof value !== "string")
|
|
1754
|
-
return false;
|
|
1755
|
-
const parsed = parsePrincipal(value);
|
|
1756
|
-
return parsed !== null && parsed.contractName === undefined;
|
|
1757
|
-
}
|
|
1758
|
-
function isContractPrincipal(value) {
|
|
1759
|
-
if (typeof value !== "string")
|
|
1760
|
-
return false;
|
|
1761
|
-
const parsed = parsePrincipal(value);
|
|
1762
|
-
return parsed !== null && parsed.contractName !== undefined;
|
|
1763
|
-
}
|
|
1764
|
-
function isTraitReference(value) {
|
|
1765
|
-
return isContractPrincipal(value);
|
|
1766
|
-
}
|
|
1767
|
-
function isString(value) {
|
|
1768
|
-
return typeof value === "string";
|
|
1769
|
-
}
|
|
1770
|
-
function isUint8Array(value) {
|
|
1771
|
-
return value instanceof Uint8Array;
|
|
1772
|
-
}
|
|
1773
|
-
function isArray(value, itemGuard) {
|
|
1774
|
-
return Array.isArray(value) && value.every(itemGuard);
|
|
1775
|
-
}
|
|
1776
|
-
function isOptional(value, guard) {
|
|
1777
|
-
return value === null || guard(value);
|
|
1778
|
-
}
|
|
1779
|
-
function isOkResponse(response) {
|
|
1780
|
-
return "ok" in response && !("err" in response);
|
|
1781
|
-
}
|
|
1782
|
-
function isErrResponse(response) {
|
|
1783
|
-
return "err" in response && !("ok" in response);
|
|
1784
|
-
}
|
|
1785
|
-
function isResponse(value, okGuard, errGuard) {
|
|
1786
|
-
if (typeof value !== "object" || value === null)
|
|
1787
|
-
return false;
|
|
1788
|
-
const obj = value;
|
|
1789
|
-
if ("ok" in value && !("err" in value))
|
|
1790
|
-
return okGuard(obj.ok);
|
|
1791
|
-
if ("err" in value && !("ok" in value))
|
|
1792
|
-
return errGuard(obj.err);
|
|
1793
|
-
return false;
|
|
1794
|
-
}
|
|
1795
|
-
function isAbiList(type) {
|
|
1796
|
-
return typeof type === "object" && type !== null && "list" in type;
|
|
1797
|
-
}
|
|
1798
|
-
function isAbiTuple(type) {
|
|
1799
|
-
return typeof type === "object" && type !== null && "tuple" in type;
|
|
1800
|
-
}
|
|
1801
|
-
function isAbiOptional(type) {
|
|
1802
|
-
return typeof type === "object" && type !== null && "optional" in type;
|
|
1803
|
-
}
|
|
1804
|
-
function isAbiResponse(type) {
|
|
1805
|
-
return typeof type === "object" && type !== null && "response" in type;
|
|
1806
|
-
}
|
|
1807
|
-
function isAbiBuffer(type) {
|
|
1808
|
-
return typeof type === "object" && type !== null && "buff" in type;
|
|
1809
|
-
}
|
|
1810
|
-
function isAbiStringAscii(type) {
|
|
1811
|
-
return typeof type === "object" && type !== null && "string-ascii" in type;
|
|
1812
|
-
}
|
|
1813
|
-
function isAbiStringUtf8(type) {
|
|
1814
|
-
return typeof type === "object" && type !== null && "string-utf8" in type;
|
|
1815
|
-
}
|
|
1816
|
-
function isAbiTraitReference(type) {
|
|
1817
|
-
return type === "trait_reference";
|
|
1818
|
-
}
|
|
1819
|
-
|
|
1820
|
-
// src/clarity/bridge.ts
|
|
1821
|
-
var CV_TYPE_TAGS = new Set([
|
|
1822
|
-
"int",
|
|
1823
|
-
"uint",
|
|
1824
|
-
"true",
|
|
1825
|
-
"false",
|
|
1826
|
-
"address",
|
|
1827
|
-
"contract",
|
|
1828
|
-
"ascii",
|
|
1829
|
-
"utf8",
|
|
1830
|
-
"buffer",
|
|
1831
|
-
"list",
|
|
1832
|
-
"tuple",
|
|
1833
|
-
"none",
|
|
1834
|
-
"some",
|
|
1835
|
-
"ok",
|
|
1836
|
-
"err"
|
|
1837
|
-
]);
|
|
1838
|
-
function isClarityValue(value) {
|
|
1839
|
-
if (typeof value !== "object" || value === null)
|
|
1840
|
-
return false;
|
|
1841
|
-
const type = value.type;
|
|
1842
|
-
if (typeof type !== "string" || !CV_TYPE_TAGS.has(type))
|
|
1843
|
-
return false;
|
|
1844
|
-
if (type === "true" || type === "false" || type === "none")
|
|
1845
|
-
return true;
|
|
1846
|
-
return "value" in value;
|
|
1847
|
-
}
|
|
1848
|
-
var HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;
|
|
1849
|
-
function coerceBuffer(value) {
|
|
1850
|
-
if (value instanceof Uint8Array)
|
|
1851
|
-
return bufferCV(value);
|
|
1852
|
-
if (typeof value === "object" && value !== null && "type" in value) {
|
|
1853
|
-
const tagged = value;
|
|
1854
|
-
if (tagged.type === "buffer" && isClarityValue(value))
|
|
1855
|
-
return value;
|
|
1856
|
-
if (typeof tagged.value === "string") {
|
|
1857
|
-
if (tagged.type === "ascii")
|
|
1858
|
-
return Cl.bufferFromAscii(tagged.value);
|
|
1859
|
-
if (tagged.type === "utf8")
|
|
1860
|
-
return Cl.bufferFromUtf8(tagged.value);
|
|
1861
|
-
if (tagged.type === "hex")
|
|
1862
|
-
return Cl.bufferFromHex(tagged.value);
|
|
1863
|
-
}
|
|
1864
|
-
throw new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);
|
|
1865
|
-
}
|
|
1866
|
-
if (typeof value === "string") {
|
|
1867
|
-
const hex = value.startsWith("0x") ? value.slice(2) : value;
|
|
1868
|
-
if (HEX_PAIRS_REGEX.test(hex))
|
|
1869
|
-
return Cl.bufferFromHex(hex);
|
|
1870
|
-
return Cl.bufferFromUtf8(value);
|
|
1871
|
-
}
|
|
1872
|
-
throw new Error("buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV");
|
|
1873
|
-
}
|
|
1874
|
-
function jsToClarityValue(abiType, value) {
|
|
1875
|
-
if (isAbiBuffer(abiType))
|
|
1876
|
-
return coerceBuffer(value);
|
|
1877
|
-
if (isClarityValue(value))
|
|
1878
|
-
return value;
|
|
1879
|
-
if (abiType === "uint128")
|
|
1880
|
-
return uintCV(value);
|
|
1881
|
-
if (abiType === "int128")
|
|
1882
|
-
return intCV(value);
|
|
1883
|
-
if (abiType === "bool")
|
|
1884
|
-
return boolCV(value);
|
|
1885
|
-
if (abiType === "principal" || abiType === "trait_reference")
|
|
1886
|
-
return Cl.principal(value);
|
|
1887
|
-
if (isAbiStringAscii(abiType))
|
|
1888
|
-
return stringAsciiCV(value);
|
|
1889
|
-
if (isAbiStringUtf8(abiType))
|
|
1890
|
-
return stringUtf8CV(value);
|
|
1891
|
-
if (isAbiList(abiType)) {
|
|
1892
|
-
const arr = value;
|
|
1893
|
-
return listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));
|
|
1894
|
-
}
|
|
1895
|
-
if (isAbiTuple(abiType)) {
|
|
1896
|
-
const obj = value;
|
|
1897
|
-
const data = {};
|
|
1898
|
-
for (const field of abiType.tuple) {
|
|
1899
|
-
const camelKey = toCamelCase(field.name);
|
|
1900
|
-
const hasOriginal = field.name in obj;
|
|
1901
|
-
const hasCamel = camelKey in obj;
|
|
1902
|
-
const fieldValue = hasOriginal ? obj[field.name] : hasCamel ? obj[camelKey] : undefined;
|
|
1903
|
-
if (fieldValue === undefined && !isAbiOptional(field.type)) {
|
|
1904
|
-
throw new Error(`Missing tuple field: ${field.name}`);
|
|
1905
|
-
}
|
|
1906
|
-
data[field.name] = jsToClarityValue(field.type, fieldValue);
|
|
1907
|
-
}
|
|
1908
|
-
return tupleCV(data);
|
|
1909
|
-
}
|
|
1910
|
-
if (isAbiOptional(abiType)) {
|
|
1911
|
-
if (value === null || value === undefined)
|
|
1912
|
-
return noneCV();
|
|
1913
|
-
return someCV(jsToClarityValue(abiType.optional, value));
|
|
1914
|
-
}
|
|
1915
|
-
if (isAbiResponse(abiType)) {
|
|
1916
|
-
const obj = value;
|
|
1917
|
-
if ("ok" in obj && !("err" in obj))
|
|
1918
|
-
return responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));
|
|
1919
|
-
if ("err" in obj && !("ok" in obj))
|
|
1920
|
-
return responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));
|
|
1921
|
-
throw new Error("Response must have exactly 'ok' or 'err' property");
|
|
1811
|
+
address: principalToString(wire.principal),
|
|
1812
|
+
condition: fungibleName(wire.conditionCode),
|
|
1813
|
+
amount: wire.amount.toString()
|
|
1814
|
+
};
|
|
1815
|
+
case "pox":
|
|
1816
|
+
return {
|
|
1817
|
+
type: "pox-postcondition",
|
|
1818
|
+
address: principalToString(wire.principal),
|
|
1819
|
+
condition: poxName(wire.conditionCode)
|
|
1820
|
+
};
|
|
1922
1821
|
}
|
|
1923
|
-
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
1924
1822
|
}
|
|
1925
|
-
function
|
|
1926
|
-
|
|
1823
|
+
function fungibleName(code) {
|
|
1824
|
+
const name = FUNGIBLE_CODE_REVERSE[code];
|
|
1825
|
+
if (!name)
|
|
1826
|
+
throw new Error(`Unknown fungible post-condition code: ${code}`);
|
|
1827
|
+
return name;
|
|
1927
1828
|
}
|
|
1928
|
-
function
|
|
1929
|
-
|
|
1829
|
+
function nftName(code) {
|
|
1830
|
+
const name = NFT_CODE_REVERSE[code];
|
|
1831
|
+
if (!name)
|
|
1832
|
+
throw new Error(`Unknown nft post-condition code: ${code}`);
|
|
1833
|
+
return name;
|
|
1930
1834
|
}
|
|
1931
|
-
function
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
throw new Error(`Expected bool CV, got ${cv.type}`);
|
|
1943
|
-
}
|
|
1944
|
-
if (abiType === "principal" || abiType === "trait_reference") {
|
|
1945
|
-
if (cv.type !== "address" && cv.type !== "contract")
|
|
1946
|
-
throw new Error(`Expected principal CV, got ${cv.type}`);
|
|
1947
|
-
return cv.value;
|
|
1948
|
-
}
|
|
1949
|
-
if (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {
|
|
1950
|
-
if (cv.type !== "ascii" && cv.type !== "utf8")
|
|
1951
|
-
throw new Error(`Expected string CV, got ${cv.type}`);
|
|
1952
|
-
return cv.value;
|
|
1953
|
-
}
|
|
1954
|
-
if (isAbiBuffer(abiType)) {
|
|
1955
|
-
if (cv.type !== "buffer")
|
|
1956
|
-
throw new Error(`Expected buffer CV, got ${cv.type}`);
|
|
1957
|
-
const hex = cv.value;
|
|
1958
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
1959
|
-
for (let i = 0;i < bytes.length; i++) {
|
|
1960
|
-
bytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
1961
|
-
}
|
|
1962
|
-
return bytes;
|
|
1963
|
-
}
|
|
1964
|
-
if (isAbiList(abiType)) {
|
|
1965
|
-
if (cv.type !== "list")
|
|
1966
|
-
throw new Error(`Expected list CV, got ${cv.type}`);
|
|
1967
|
-
return cv.value.map((item) => clarityValueToJSInner(abiType.list.type, item));
|
|
1968
|
-
}
|
|
1969
|
-
if (isAbiTuple(abiType)) {
|
|
1970
|
-
if (cv.type !== "tuple")
|
|
1971
|
-
throw new Error(`Expected tuple CV, got ${cv.type}`);
|
|
1972
|
-
const result = {};
|
|
1973
|
-
for (const field of abiType.tuple) {
|
|
1974
|
-
const fieldCV = cv.value[field.name];
|
|
1975
|
-
if (!fieldCV)
|
|
1976
|
-
throw new Error(`Missing tuple field in CV: ${field.name}`);
|
|
1977
|
-
const camelKey = toCamelCase(field.name);
|
|
1978
|
-
result[camelKey] = clarityValueToJSInner(field.type, fieldCV);
|
|
1979
|
-
}
|
|
1980
|
-
return result;
|
|
1981
|
-
}
|
|
1982
|
-
if (isAbiOptional(abiType)) {
|
|
1983
|
-
if (cv.type === "none")
|
|
1984
|
-
return null;
|
|
1985
|
-
if (cv.type === "some")
|
|
1986
|
-
return clarityValueToJSInner(abiType.optional, cv.value);
|
|
1987
|
-
throw new Error(`Expected optional CV, got ${cv.type}`);
|
|
1988
|
-
}
|
|
1989
|
-
if (isAbiResponse(abiType)) {
|
|
1990
|
-
if (cv.type === "ok")
|
|
1991
|
-
return { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };
|
|
1992
|
-
if (cv.type === "err")
|
|
1993
|
-
return { err: clarityValueToJSInner(abiType.response.error, cv.value) };
|
|
1994
|
-
throw new Error(`Expected response CV, got ${cv.type}`);
|
|
1995
|
-
}
|
|
1996
|
-
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
1835
|
+
function poxName(code) {
|
|
1836
|
+
const name = POX_CODE_REVERSE[code];
|
|
1837
|
+
if (!name)
|
|
1838
|
+
throw new Error(`Unknown pox post-condition code: ${code}`);
|
|
1839
|
+
return name;
|
|
1840
|
+
}
|
|
1841
|
+
function fromHex(hex) {
|
|
1842
|
+
return wireToPostCondition(deserializePostConditionWire(hex));
|
|
1843
|
+
}
|
|
1844
|
+
function postConditionToHex(pc) {
|
|
1845
|
+
return bytesToHex(serializePostConditionWire(convertPostCondition(pc)));
|
|
1997
1846
|
}
|
|
1998
1847
|
|
|
1999
1848
|
// src/transactions/authorization.ts
|
|
@@ -2142,11 +1991,11 @@ function replayMultiSigSigHash(tx) {
|
|
|
2142
1991
|
const condition = tx.auth.spendingCondition;
|
|
2143
1992
|
if (isNonSequential(condition.hashMode)) {
|
|
2144
1993
|
const preSign = nonSequentialPreSignHash(tx);
|
|
2145
|
-
let
|
|
1994
|
+
let curSigHash = preSign;
|
|
2146
1995
|
for (const field of condition.fields) {
|
|
2147
|
-
|
|
1996
|
+
curSigHash = sigHashPostSign(curSigHash, field.pubKeyEncoding, field.data);
|
|
2148
1997
|
}
|
|
2149
|
-
return
|
|
1998
|
+
return curSigHash;
|
|
2150
1999
|
}
|
|
2151
2000
|
let curSigHash = initialSigHash(tx);
|
|
2152
2001
|
for (const field of condition.fields) {
|
|
@@ -2267,8 +2116,8 @@ async function signSequentialWithAccount(tx, condition, account, publicKeys, sig
|
|
|
2267
2116
|
const fields = [...condition.fields];
|
|
2268
2117
|
let curSigHash = initialSigHash(tx);
|
|
2269
2118
|
for (const field of fields) {
|
|
2270
|
-
const
|
|
2271
|
-
curSigHash = sigHashPostSign(
|
|
2119
|
+
const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
|
|
2120
|
+
curSigHash = sigHashPostSign(preSign, field.pubKeyEncoding, field.data);
|
|
2272
2121
|
}
|
|
2273
2122
|
for (let i = fields.length;i < signerIndex; i++) {
|
|
2274
2123
|
const pubKeyField = {
|
|
@@ -2277,8 +2126,8 @@ async function signSequentialWithAccount(tx, condition, account, publicKeys, sig
|
|
|
2277
2126
|
data: publicKeys[i]
|
|
2278
2127
|
};
|
|
2279
2128
|
fields.push(pubKeyField);
|
|
2280
|
-
const
|
|
2281
|
-
curSigHash = sigHashPostSign(
|
|
2129
|
+
const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
|
|
2130
|
+
curSigHash = sigHashPostSign(preSign, pubKeyField.pubKeyEncoding, pubKeyField.data);
|
|
2282
2131
|
}
|
|
2283
2132
|
const preSign = sigHashPreSign(curSigHash, AuthType.Standard, condition.fee, condition.nonce);
|
|
2284
2133
|
const sigBytes = await account.sign(hexToBytes(preSign));
|
|
@@ -2572,9 +2421,9 @@ function getOriginSigHash(tx) {
|
|
|
2572
2421
|
if ("fields" in condition) {
|
|
2573
2422
|
return replayMultiSigSigHash(tx);
|
|
2574
2423
|
}
|
|
2575
|
-
const
|
|
2424
|
+
const initialSigHash = signBegin(tx);
|
|
2576
2425
|
const sc = condition;
|
|
2577
|
-
const preSign = sigHashPreSign(
|
|
2426
|
+
const preSign = sigHashPreSign(initialSigHash, AuthType.Standard, sc.fee, sc.nonce);
|
|
2578
2427
|
return sigHashPostSign(preSign, sc.keyEncoding, sc.signature);
|
|
2579
2428
|
}
|
|
2580
2429
|
function signSponsor(tx, privateKey) {
|
|
@@ -2878,8 +2727,8 @@ function indexNotFound(error, sourceName) {
|
|
|
2878
2727
|
}
|
|
2879
2728
|
return true;
|
|
2880
2729
|
}
|
|
2881
|
-
function normalizeTxid(
|
|
2882
|
-
return
|
|
2730
|
+
function normalizeTxid(txid) {
|
|
2731
|
+
return txid.startsWith("0x") ? txid : `0x${txid}`;
|
|
2883
2732
|
}
|
|
2884
2733
|
function decodeResultHex(hex) {
|
|
2885
2734
|
if (!hex)
|
|
@@ -2903,10 +2752,10 @@ function normalizeStatus(txStatus) {
|
|
|
2903
2752
|
}
|
|
2904
2753
|
function extendedApiSource() {
|
|
2905
2754
|
return {
|
|
2906
|
-
async get({ client, txid
|
|
2755
|
+
async get({ client, txid }) {
|
|
2907
2756
|
let data;
|
|
2908
2757
|
try {
|
|
2909
|
-
data = await client.request(`/extended/v1/tx/${encodeURIComponent(normalizeTxid(
|
|
2758
|
+
data = await client.request(`/extended/v1/tx/${encodeURIComponent(normalizeTxid(txid))}`, { method: "GET" });
|
|
2910
2759
|
} catch (error) {
|
|
2911
2760
|
if (error instanceof HttpRequestError && error.status === 404) {
|
|
2912
2761
|
return { receipt: null };
|
|
@@ -2921,7 +2770,7 @@ function extendedApiSource() {
|
|
|
2921
2770
|
return { receipt: null };
|
|
2922
2771
|
return {
|
|
2923
2772
|
receipt: {
|
|
2924
|
-
txid: normalizeTxid(
|
|
2773
|
+
txid: normalizeTxid(txid),
|
|
2925
2774
|
status,
|
|
2926
2775
|
blockHeight: typeof data.block_height === "number" && data.block_height > 0 ? data.block_height : undefined,
|
|
2927
2776
|
blockHash: data.block_hash ?? undefined,
|
|
@@ -2937,11 +2786,11 @@ function indexTxSource(params = {}) {
|
|
|
2937
2786
|
const headers = params.apiKey ? { authorization: `Bearer ${params.apiKey}` } : undefined;
|
|
2938
2787
|
return {
|
|
2939
2788
|
canonicalOnly: true,
|
|
2940
|
-
async get({ client, txid
|
|
2789
|
+
async get({ client, txid }) {
|
|
2941
2790
|
const request = indexRequestFn(client, params.baseUrl, "indexTxSource");
|
|
2942
2791
|
let data;
|
|
2943
2792
|
try {
|
|
2944
|
-
data = await request(`/v1/index/transactions/${normalizeTxid(
|
|
2793
|
+
data = await request(`/v1/index/transactions/${normalizeTxid(txid)}`, {
|
|
2945
2794
|
method: "GET",
|
|
2946
2795
|
headers
|
|
2947
2796
|
});
|
|
@@ -2990,7 +2839,7 @@ async function getBlockHeight(client) {
|
|
|
2990
2839
|
var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2991
2840
|
async function waitForTransactionReceipt(client, params) {
|
|
2992
2841
|
const {
|
|
2993
|
-
txid
|
|
2842
|
+
txid,
|
|
2994
2843
|
confirmations = 1,
|
|
2995
2844
|
timeout = 180000,
|
|
2996
2845
|
pollingInterval = 3000
|
|
@@ -3001,21 +2850,21 @@ async function waitForTransactionReceipt(client, params) {
|
|
|
3001
2850
|
let unknownSince = null;
|
|
3002
2851
|
let everPending = false;
|
|
3003
2852
|
while (true) {
|
|
3004
|
-
const snapshot = await source.get({ client, txid
|
|
2853
|
+
const snapshot = await source.get({ client, txid });
|
|
3005
2854
|
const receipt = snapshot.receipt;
|
|
3006
2855
|
if (receipt === null) {
|
|
3007
2856
|
unknownSince ??= Date.now();
|
|
3008
2857
|
if (Date.now() - unknownSince >= droppedGracePeriod) {
|
|
3009
|
-
throw new TransactionDroppedError(everPending ? `Transaction ${
|
|
2858
|
+
throw new TransactionDroppedError(everPending ? `Transaction ${txid} left the mempool without being mined` : `Transaction ${txid} was never observed by the status source`, { txid });
|
|
3010
2859
|
}
|
|
3011
2860
|
} else {
|
|
3012
2861
|
unknownSince = null;
|
|
3013
2862
|
switch (receipt.status) {
|
|
3014
2863
|
case "dropped":
|
|
3015
|
-
throw new TransactionDroppedError(`Transaction ${
|
|
2864
|
+
throw new TransactionDroppedError(`Transaction ${txid} was dropped from the mempool`, { txid });
|
|
3016
2865
|
case "abort_by_response":
|
|
3017
2866
|
case "abort_by_post_condition":
|
|
3018
|
-
throw new TransactionAbortedError(`Transaction ${
|
|
2867
|
+
throw new TransactionAbortedError(`Transaction ${txid} aborted (${receipt.status})`, { receipt });
|
|
3019
2868
|
case "pending":
|
|
3020
2869
|
everPending = true;
|
|
3021
2870
|
break;
|
|
@@ -3032,7 +2881,7 @@ async function waitForTransactionReceipt(client, params) {
|
|
|
3032
2881
|
}
|
|
3033
2882
|
}
|
|
3034
2883
|
if (Date.now() - startedAt >= timeout) {
|
|
3035
|
-
throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${
|
|
2884
|
+
throw new WaitForTransactionTimeoutError(`Timed out after ${timeout}ms waiting for transaction ${txid}`, { txid });
|
|
3036
2885
|
}
|
|
3037
2886
|
await sleep2(pollingInterval);
|
|
3038
2887
|
}
|
|
@@ -3060,11 +2909,11 @@ async function sendTransaction(client, params) {
|
|
|
3060
2909
|
throw error;
|
|
3061
2910
|
}
|
|
3062
2911
|
} else if (error instanceof TimeoutError) {
|
|
3063
|
-
const
|
|
3064
|
-
const receipt = await getTransaction(client, { txid
|
|
2912
|
+
const txid = getTransactionId(params.transaction);
|
|
2913
|
+
const receipt = await getTransaction(client, { txid }).catch(() => null);
|
|
3065
2914
|
if (receipt === null)
|
|
3066
2915
|
throw error;
|
|
3067
|
-
data = { txid
|
|
2916
|
+
data = { txid };
|
|
3068
2917
|
} else {
|
|
3069
2918
|
throw error;
|
|
3070
2919
|
}
|
|
@@ -3076,16 +2925,16 @@ async function sendTransaction(client, params) {
|
|
|
3076
2925
|
txid: data.txid ?? getTransactionId(params.transaction)
|
|
3077
2926
|
});
|
|
3078
2927
|
}
|
|
3079
|
-
const
|
|
2928
|
+
const txid = typeof data === "string" ? data.replace(/"/g, "") : data.txid ?? getTransactionId(params.transaction);
|
|
3080
2929
|
if (params.wait) {
|
|
3081
2930
|
const confirmations = params.wait === true ? 1 : params.wait;
|
|
3082
2931
|
const receipt = await waitForTransactionReceipt(client, {
|
|
3083
|
-
txid
|
|
2932
|
+
txid,
|
|
3084
2933
|
confirmations
|
|
3085
2934
|
});
|
|
3086
|
-
return { txid
|
|
2935
|
+
return { txid, receipt };
|
|
3087
2936
|
}
|
|
3088
|
-
return { txid
|
|
2937
|
+
return { txid };
|
|
3089
2938
|
}
|
|
3090
2939
|
|
|
3091
2940
|
// src/actions/wallet/nonceManager.ts
|
|
@@ -3750,6 +3599,158 @@ var sip010Abi = SIP010_ABI;
|
|
|
3750
3599
|
var sip009Abi = SIP009_ABI;
|
|
3751
3600
|
var sip013Abi = SIP013_ABI;
|
|
3752
3601
|
|
|
3602
|
+
// src/postconditions/index.ts
|
|
3603
|
+
var exports_postconditions = {};
|
|
3604
|
+
__export(exports_postconditions, {
|
|
3605
|
+
Pc: () => Pc,
|
|
3606
|
+
fromHex: () => fromHex,
|
|
3607
|
+
parsePostConditionAmount: () => parsePostConditionAmount,
|
|
3608
|
+
postConditionToHex: () => postConditionToHex,
|
|
3609
|
+
wireToPostCondition: () => wireToPostCondition
|
|
3610
|
+
});
|
|
3611
|
+
|
|
3612
|
+
// src/postconditions/builder.ts
|
|
3613
|
+
class PartialPcWithPrincipal {
|
|
3614
|
+
address;
|
|
3615
|
+
constructor(address) {
|
|
3616
|
+
this.address = address;
|
|
3617
|
+
}
|
|
3618
|
+
willSendEq(amount) {
|
|
3619
|
+
return new PartialPcFtWithCode(this.address, amount, "eq");
|
|
3620
|
+
}
|
|
3621
|
+
willSendGte(amount) {
|
|
3622
|
+
return new PartialPcFtWithCode(this.address, amount, "gte");
|
|
3623
|
+
}
|
|
3624
|
+
willSendGt(amount) {
|
|
3625
|
+
return new PartialPcFtWithCode(this.address, amount, "gt");
|
|
3626
|
+
}
|
|
3627
|
+
willSendLte(amount) {
|
|
3628
|
+
return new PartialPcFtWithCode(this.address, amount, "lte");
|
|
3629
|
+
}
|
|
3630
|
+
willSendLt(amount) {
|
|
3631
|
+
return new PartialPcFtWithCode(this.address, amount, "lt");
|
|
3632
|
+
}
|
|
3633
|
+
willSendAsset() {
|
|
3634
|
+
return new PartialPcNftWithCode(this.address, "sent");
|
|
3635
|
+
}
|
|
3636
|
+
willNotSendAsset() {
|
|
3637
|
+
return new PartialPcNftWithCode(this.address, "not-sent");
|
|
3638
|
+
}
|
|
3639
|
+
willMaybeSendAsset() {
|
|
3640
|
+
return new PartialPcNftWithCode(this.address, "maybe-sent");
|
|
3641
|
+
}
|
|
3642
|
+
willPerformPox() {
|
|
3643
|
+
return {
|
|
3644
|
+
type: "pox-postcondition",
|
|
3645
|
+
address: this.address,
|
|
3646
|
+
condition: "will-perform"
|
|
3647
|
+
};
|
|
3648
|
+
}
|
|
3649
|
+
willNotPerformPox() {
|
|
3650
|
+
return {
|
|
3651
|
+
type: "pox-postcondition",
|
|
3652
|
+
address: this.address,
|
|
3653
|
+
condition: "will-not-perform"
|
|
3654
|
+
};
|
|
3655
|
+
}
|
|
3656
|
+
mayPerformPox() {
|
|
3657
|
+
return {
|
|
3658
|
+
type: "pox-postcondition",
|
|
3659
|
+
address: this.address,
|
|
3660
|
+
condition: "may-perform"
|
|
3661
|
+
};
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
|
|
3665
|
+
class PartialPcFtWithCode {
|
|
3666
|
+
address;
|
|
3667
|
+
amount;
|
|
3668
|
+
code;
|
|
3669
|
+
constructor(address, amount, code) {
|
|
3670
|
+
this.address = address;
|
|
3671
|
+
this.amount = amount;
|
|
3672
|
+
this.code = code;
|
|
3673
|
+
}
|
|
3674
|
+
ustx() {
|
|
3675
|
+
return {
|
|
3676
|
+
type: "stx-postcondition",
|
|
3677
|
+
address: this.address,
|
|
3678
|
+
condition: this.code,
|
|
3679
|
+
amount: parsePostConditionAmount(this.amount).toString()
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3682
|
+
ustxToLock() {
|
|
3683
|
+
return {
|
|
3684
|
+
type: "staking-postcondition",
|
|
3685
|
+
address: this.address,
|
|
3686
|
+
condition: this.code,
|
|
3687
|
+
amount: parsePostConditionAmount(this.amount).toString()
|
|
3688
|
+
};
|
|
3689
|
+
}
|
|
3690
|
+
ft(contractId, tokenName) {
|
|
3691
|
+
const [address, name] = contractId.split(".");
|
|
3692
|
+
if (!address || !validateStacksAddress(address) || !name) {
|
|
3693
|
+
throw new Error(`Invalid contract id: ${contractId}`);
|
|
3694
|
+
}
|
|
3695
|
+
return {
|
|
3696
|
+
type: "ft-postcondition",
|
|
3697
|
+
address: this.address,
|
|
3698
|
+
condition: this.code,
|
|
3699
|
+
amount: parsePostConditionAmount(this.amount).toString(),
|
|
3700
|
+
asset: `${contractId}::${tokenName}`
|
|
3701
|
+
};
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
|
|
3705
|
+
class PartialPcNftWithCode {
|
|
3706
|
+
address;
|
|
3707
|
+
code;
|
|
3708
|
+
constructor(address, code) {
|
|
3709
|
+
this.address = address;
|
|
3710
|
+
this.code = code;
|
|
3711
|
+
}
|
|
3712
|
+
nft(assetOrContractId, tokenNameOrAssetId, assetId) {
|
|
3713
|
+
let contractAddress;
|
|
3714
|
+
let contractName;
|
|
3715
|
+
let tokenName;
|
|
3716
|
+
let id;
|
|
3717
|
+
if (assetId !== undefined) {
|
|
3718
|
+
[contractAddress, contractName] = parseContractId(assetOrContractId);
|
|
3719
|
+
tokenName = tokenNameOrAssetId;
|
|
3720
|
+
id = assetId;
|
|
3721
|
+
} else {
|
|
3722
|
+
const [principal, tName] = assetOrContractId.split("::");
|
|
3723
|
+
if (!principal || !tName)
|
|
3724
|
+
throw new Error(`Invalid asset name: ${assetOrContractId}`);
|
|
3725
|
+
[contractAddress, contractName] = parseContractId(principal);
|
|
3726
|
+
tokenName = tName;
|
|
3727
|
+
id = tokenNameOrAssetId;
|
|
3728
|
+
}
|
|
3729
|
+
if (!validateStacksAddress(contractAddress)) {
|
|
3730
|
+
throw new Error(`Invalid contract address: ${contractAddress}`);
|
|
3731
|
+
}
|
|
3732
|
+
return {
|
|
3733
|
+
type: "nft-postcondition",
|
|
3734
|
+
address: this.address,
|
|
3735
|
+
condition: this.code,
|
|
3736
|
+
asset: `${contractAddress}.${contractName}::${tokenName}`,
|
|
3737
|
+
assetId: id
|
|
3738
|
+
};
|
|
3739
|
+
}
|
|
3740
|
+
}
|
|
3741
|
+
var Pc = {
|
|
3742
|
+
principal(address) {
|
|
3743
|
+
const [addr, name] = address.split(".");
|
|
3744
|
+
if (!addr || !validateStacksAddress(addr) || typeof name === "string" && !name) {
|
|
3745
|
+
throw new Error(`Invalid principal: ${address}`);
|
|
3746
|
+
}
|
|
3747
|
+
return new PartialPcWithPrincipal(address);
|
|
3748
|
+
},
|
|
3749
|
+
origin() {
|
|
3750
|
+
return new PartialPcWithPrincipal("origin");
|
|
3751
|
+
},
|
|
3752
|
+
fromHex: (hex) => fromHex(hex)
|
|
3753
|
+
};
|
|
3753
3754
|
// src/stackingdao/abi.ts
|
|
3754
3755
|
var withdrawTuple = {
|
|
3755
3756
|
tuple: [
|
|
@@ -4064,5 +4065,5 @@ function stackingDao() {
|
|
|
4064
4065
|
});
|
|
4065
4066
|
}
|
|
4066
4067
|
|
|
4067
|
-
//# debugId=
|
|
4068
|
+
//# debugId=9C8528EDF2AF4E0964756E2164756E21
|
|
4068
4069
|
//# sourceMappingURL=index.cjs.map
|