@secondlayer/stacks 6.0.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-qex691bh.js.map → stacks-esm-0pc6tmf0.js.map} +2 -2
- package/dist/shared/{stacks-qt8ehebn.js → stacks-esm-16d82wyc.js} +10 -10
- package/dist/shared/{stacks-qt8ehebn.js.map → stacks-esm-16d82wyc.js.map} +2 -2
- package/dist/shared/{stacks-qs5fzts5.js → stacks-esm-7a0ehykf.js} +43 -43
- package/dist/shared/{stacks-qs5fzts5.js.map → stacks-esm-7a0ehykf.js.map} +2 -2
- package/dist/shared/{stacks-4hs8r4q2.js → stacks-esm-7v18h5dk.js} +4 -4
- package/dist/shared/{stacks-xjkn3en1.cjs.map → stacks-esm-7v18h5dk.js.map} +2 -2
- package/dist/shared/{stacks-71k0vmct.js → stacks-esm-8f5catbf.js} +126 -126
- package/dist/shared/{stacks-71k0vmct.js.map → stacks-esm-8f5catbf.js.map} +2 -2
- package/dist/shared/{stacks-wxfd6r4b.js → stacks-esm-8jt6k8p3.js} +13 -13
- package/dist/shared/{stacks-wxfd6r4b.js.map → stacks-esm-8jt6k8p3.js.map} +2 -2
- package/dist/shared/{stacks-x0qqwrev.js → stacks-esm-a20wyky3.js} +92 -92
- package/dist/shared/{stacks-agk106zs.cjs.map → stacks-esm-a20wyky3.js.map} +2 -2
- package/dist/shared/{stacks-gjz26k6b.js → stacks-esm-b54n1jdx.js} +102 -58
- package/dist/shared/stacks-esm-b54n1jdx.js.map +12 -0
- package/dist/shared/{stacks-9c1yam8b.js → stacks-esm-cmtj5vky.js} +162 -162
- package/dist/shared/{stacks-9c1yam8b.js.map → stacks-esm-cmtj5vky.js.map} +2 -2
- package/dist/shared/{stacks-z90xdr1x.js → stacks-esm-e2qhfgke.js} +36 -36
- package/dist/shared/{stacks-z90xdr1x.js.map → stacks-esm-e2qhfgke.js.map} +2 -2
- package/dist/shared/{stacks-v03zef3g.js → stacks-esm-ea4m4bk7.js} +117 -117
- package/dist/shared/{stacks-v03zef3g.js.map → stacks-esm-ea4m4bk7.js.map} +2 -2
- package/dist/shared/{stacks-69nq48jp.js → stacks-esm-hkw1kvd4.js} +140 -140
- package/dist/shared/{stacks-69nq48jp.js.map → stacks-esm-hkw1kvd4.js.map} +2 -2
- package/dist/shared/{stacks-qcae5852.js → stacks-esm-k108pemv.js} +4 -4
- package/dist/shared/{stacks-qcae5852.js.map → stacks-esm-k108pemv.js.map} +2 -2
- package/dist/shared/stacks-esm-kbz5s6v8.js +84 -0
- package/dist/shared/{stacks-4d7c3x27.js.map → stacks-esm-kbz5s6v8.js.map} +2 -2
- package/dist/shared/{stacks-kg1npstf.js → stacks-esm-mt1thm7k.js} +9 -9
- package/dist/shared/{stacks-kg1npstf.js.map → stacks-esm-mt1thm7k.js.map} +2 -2
- package/dist/shared/{stacks-yvb7rvwk.js → stacks-esm-n1mekwnb.js} +9 -9
- package/dist/shared/{stacks-8vzxax5e.cjs.map → stacks-esm-n1mekwnb.js.map} +2 -2
- package/dist/shared/{stacks-mftyrc60.js → stacks-esm-nt5hf8ht.js} +34 -34
- package/dist/shared/{stacks-mftyrc60.js.map → stacks-esm-nt5hf8ht.js.map} +2 -2
- package/dist/shared/{stacks-51ybf135.js → stacks-esm-phgy8yqf.js} +210 -210
- package/dist/shared/{stacks-51ybf135.js.map → stacks-esm-phgy8yqf.js.map} +2 -2
- package/dist/shared/{stacks-mbt36bzt.js → stacks-esm-pxv6ny92.js} +116 -116
- package/dist/shared/{stacks-mbt36bzt.js.map → stacks-esm-pxv6ny92.js.map} +2 -2
- package/dist/shared/{stacks-8brgfvqx.js → stacks-esm-qfzxhdqz.js} +19 -19
- package/dist/shared/{stacks-8brgfvqx.js.map → stacks-esm-qfzxhdqz.js.map} +2 -2
- package/dist/shared/{stacks-fd4rx56e.js → stacks-esm-snj9s2q8.js} +43 -43
- package/dist/shared/{stacks-fd4rx56e.js.map → stacks-esm-snj9s2q8.js.map} +2 -2
- package/dist/shared/{stacks-yajyej2y.js → stacks-esm-ss9ap75h.js} +28 -28
- package/dist/shared/{stacks-yajyej2y.js.map → stacks-esm-ss9ap75h.js.map} +2 -2
- package/dist/shared/{stacks-1m3m1agc.js → stacks-esm-t88hc019.js} +18 -18
- package/dist/shared/{stacks-1m3m1agc.js.map → stacks-esm-t88hc019.js.map} +2 -2
- package/dist/shared/stacks-esm-tdrdye4y.js +48 -0
- package/dist/shared/{stacks-enpj9krt.cjs.map → stacks-esm-tdrdye4y.js.map} +2 -2
- package/dist/src/accounts/index.cjs +565 -9
- package/dist/src/accounts/index.cjs.map +10 -4
- 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 +3860 -44
- package/dist/src/actions/index.cjs.map +65 -3
- 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 +2506 -31
- package/dist/src/bitcoin/index.cjs.map +31 -3
- 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 +4435 -10
- package/dist/src/bns/index.cjs.map +50 -3
- 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 +141 -5
- package/dist/src/chains/index.cjs.map +5 -3
- 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 +2021 -1
- package/dist/src/clarity/index.cjs.map +24 -3
- 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 +727 -1
- package/dist/src/filters/index.cjs.map +11 -3
- package/dist/src/filters/index.d.cts +76 -13
- package/dist/src/filters/index.d.ts +76 -13
- package/dist/src/filters/index.js +30 -26
- package/dist/src/filters/index.js.map +1 -1
- package/dist/src/index.cjs +4000 -126
- package/dist/src/index.cjs.map +69 -4
- package/dist/src/index.d.cts +658 -607
- package/dist/src/index.d.ts +658 -607
- package/dist/src/index.js +219 -219
- package/dist/src/index.js.map +2 -2
- package/dist/src/postconditions/index.cjs +1728 -1
- package/dist/src/postconditions/index.cjs.map +20 -3
- 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 +3866 -11
- package/dist/src/pox/index.cjs.map +48 -3
- 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 +4124 -95
- package/dist/src/pox5/index.cjs.map +55 -4
- 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 +3719 -16
- package/dist/src/sbtc/index.cjs.map +47 -3
- 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 +3747 -3
- package/dist/src/stackingdao/index.cjs.map +45 -3
- 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 +160 -6
- package/dist/src/subscriptions/index.cjs.map +6 -3
- 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 +2189 -49
- package/dist/src/transactions/index.cjs.map +23 -3
- 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 +503 -69
- package/dist/src/utils/index.cjs.map +9 -3
- 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-02actsrx.cjs +0 -17
- package/dist/shared/stacks-02actsrx.cjs.map +0 -10
- package/dist/shared/stacks-03vfm21t.cjs +0 -222
- package/dist/shared/stacks-03vfm21t.cjs.map +0 -12
- package/dist/shared/stacks-24h5k94q.cjs +0 -74
- package/dist/shared/stacks-24h5k94q.cjs.map +0 -11
- package/dist/shared/stacks-37kz5t9f.cjs +0 -764
- package/dist/shared/stacks-37kz5t9f.cjs.map +0 -23
- package/dist/shared/stacks-3mt2q2na.cjs +0 -65
- package/dist/shared/stacks-3mt2q2na.cjs.map +0 -9
- package/dist/shared/stacks-4d7c3x27.js +0 -84
- package/dist/shared/stacks-4hs8r4q2.js.map +0 -10
- package/dist/shared/stacks-8vzxax5e.cjs +0 -45
- package/dist/shared/stacks-agk106zs.cjs +0 -267
- package/dist/shared/stacks-bdgh9n83.cjs +0 -212
- package/dist/shared/stacks-bdgh9n83.cjs.map +0 -11
- package/dist/shared/stacks-dpxnxhqb.cjs +0 -51
- package/dist/shared/stacks-dpxnxhqb.cjs.map +0 -11
- package/dist/shared/stacks-ee53k9j2.cjs +0 -651
- package/dist/shared/stacks-ee53k9j2.cjs.map +0 -13
- package/dist/shared/stacks-enpj9krt.cjs +0 -38
- package/dist/shared/stacks-f35mnrmg.cjs +0 -164
- package/dist/shared/stacks-f35mnrmg.cjs.map +0 -10
- package/dist/shared/stacks-fhzwsn5d.cjs +0 -261
- package/dist/shared/stacks-fhzwsn5d.cjs.map +0 -12
- package/dist/shared/stacks-gjz26k6b.js.map +0 -12
- package/dist/shared/stacks-gza2n1zs.cjs +0 -73
- package/dist/shared/stacks-gza2n1zs.cjs.map +0 -11
- package/dist/shared/stacks-kem68d80.cjs +0 -156
- package/dist/shared/stacks-kem68d80.cjs.map +0 -10
- package/dist/shared/stacks-n98w7g57.cjs +0 -234
- package/dist/shared/stacks-n98w7g57.cjs.map +0 -10
- package/dist/shared/stacks-p337hp6m.cjs +0 -336
- package/dist/shared/stacks-p337hp6m.cjs.map +0 -25
- package/dist/shared/stacks-q34k4vnc.cjs +0 -286
- package/dist/shared/stacks-q34k4vnc.cjs.map +0 -12
- package/dist/shared/stacks-qex691bh.js +0 -50
- package/dist/shared/stacks-rryme9bv.cjs +0 -569
- package/dist/shared/stacks-rryme9bv.cjs.map +0 -13
- package/dist/shared/stacks-s5vej5z6.cjs +0 -410
- package/dist/shared/stacks-s5vej5z6.cjs.map +0 -15
- package/dist/shared/stacks-sdqkapct.cjs +0 -67
- package/dist/shared/stacks-sdqkapct.cjs.map +0 -12
- package/dist/shared/stacks-v2rfr46a.js +0 -48
- package/dist/shared/stacks-v2rfr46a.js.map +0 -10
- package/dist/shared/stacks-vea7nde7.cjs +0 -731
- package/dist/shared/stacks-vea7nde7.cjs.map +0 -13
- package/dist/shared/stacks-wk8yp13j.cjs +0 -33
- package/dist/shared/stacks-wk8yp13j.cjs.map +0 -11
- package/dist/shared/stacks-x0qqwrev.js.map +0 -12
- package/dist/shared/stacks-xjkn3en1.cjs +0 -42
- package/dist/shared/stacks-xnrywjf1.cjs +0 -131
- package/dist/shared/stacks-xnrywjf1.cjs.map +0 -11
- package/dist/shared/stacks-yvb7rvwk.js.map +0 -10
package/dist/src/utils/index.cjs
CHANGED
|
@@ -1,73 +1,507 @@
|
|
|
1
|
+
var import_node_module = require("node:module");
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
13
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
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
|
+
}
|
|
31
|
+
if (canCache)
|
|
32
|
+
cache.set(mod, to);
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (from) => {
|
|
36
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
37
|
+
if (entry)
|
|
38
|
+
return entry;
|
|
39
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
40
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
41
|
+
for (var key of __getOwnPropNames(from))
|
|
42
|
+
if (!__hasOwnProp.call(entry, key))
|
|
43
|
+
__defProp(entry, key, {
|
|
44
|
+
get: __accessProp.bind(from, key),
|
|
45
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
__moduleCache.set(from, entry);
|
|
49
|
+
return entry;
|
|
50
|
+
};
|
|
51
|
+
var __moduleCache;
|
|
52
|
+
var __returnValue = (v) => v;
|
|
53
|
+
function __exportSetter(name, newValue) {
|
|
54
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
55
|
+
}
|
|
56
|
+
var __export = (target, all) => {
|
|
57
|
+
for (var name in all)
|
|
58
|
+
__defProp(target, name, {
|
|
59
|
+
get: all[name],
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: true,
|
|
62
|
+
set: __exportSetter.bind(all, name)
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
1
66
|
// src/utils/index.ts
|
|
2
67
|
var exports_utils = {};
|
|
3
68
|
__export(exports_utils, {
|
|
4
|
-
|
|
5
|
-
writeUInt32BE: () => writeUInt32BE,
|
|
6
|
-
writeUInt16BE: () => writeUInt16BE,
|
|
7
|
-
without0x: () => without0x,
|
|
8
|
-
with0x: () => with0x,
|
|
9
|
-
verifySignature: () => verifySignature,
|
|
10
|
-
verifyMessageSignature: () => verifyMessageSignature,
|
|
11
|
-
validateStacksAddress: () => validateStacksAddress,
|
|
12
|
-
utf8ToBytes: () => utf8ToBytes,
|
|
13
|
-
uncompressPublicKey: () => uncompressPublicKey,
|
|
14
|
-
txidFromBytes: () => txidFromBytes,
|
|
15
|
-
toTwos: () => toTwos,
|
|
16
|
-
signatureVrsToRsv: () => signatureVrsToRsv,
|
|
17
|
-
signatureRsvToVrs: () => signatureRsvToVrs,
|
|
18
|
-
sha512_256: () => import_sha22.sha512_256,
|
|
19
|
-
sha256: () => import_sha2.sha256,
|
|
20
|
-
serializeSignature: () => serializeSignature,
|
|
21
|
-
ripemd160: () => import_legacy.ripemd160,
|
|
22
|
-
recoverPublicKey: () => recoverPublicKey,
|
|
23
|
-
recoverAddress: () => recoverAddress,
|
|
24
|
-
readUInt32BE: () => readUInt32BE,
|
|
25
|
-
readUInt16BE: () => readUInt16BE,
|
|
26
|
-
randomBytes: () => randomBytes,
|
|
27
|
-
publicKeyToAddress: () => publicKeyToAddress,
|
|
28
|
-
parseUnits: () => parseUnits,
|
|
29
|
-
parseStx: () => parseStx,
|
|
30
|
-
parseSignature: () => parseSignature,
|
|
31
|
-
parsePrincipal: () => parsePrincipal,
|
|
32
|
-
parseContractId: () => parseContractId,
|
|
33
|
-
isValidAddress: () => isValidAddress,
|
|
34
|
-
isCompressedPublicKey: () => isCompressedPublicKey,
|
|
35
|
-
isClarityName: () => isClarityName,
|
|
36
|
-
isAddressEqual: () => isAddressEqual,
|
|
37
|
-
intToHex: () => intToHex,
|
|
38
|
-
intToBytes: () => intToBytes,
|
|
39
|
-
intToBigInt: () => intToBigInt,
|
|
40
|
-
hexToBytes: () => hexToBytes,
|
|
41
|
-
hashP2PKH: () => hashP2PKH,
|
|
42
|
-
hash160: () => hash160,
|
|
43
|
-
getContractAddress: () => getContractAddress,
|
|
44
|
-
fromTwos: () => fromTwos,
|
|
45
|
-
formatUnits: () => formatUnits,
|
|
46
|
-
formatStx: () => formatStx,
|
|
47
|
-
concatBytes: () => concatBytes,
|
|
48
|
-
compressPublicKey: () => compressPublicKey,
|
|
49
|
-
c32addressDecode: () => c32addressDecode,
|
|
50
|
-
c32address: () => c32address,
|
|
51
|
-
bytesToUtf8: () => bytesToUtf8,
|
|
52
|
-
bytesToTwosBigInt: () => bytesToTwosBigInt,
|
|
53
|
-
bytesToHex: () => bytesToHex,
|
|
54
|
-
bytesToAscii: () => bytesToAscii,
|
|
55
|
-
bigIntToBytes: () => bigIntToBytes,
|
|
56
|
-
asciiToBytes: () => asciiToBytes,
|
|
57
|
-
addressToVersion: () => addressToVersion,
|
|
58
|
-
ZERO_ADDRESS: () => ZERO_ADDRESS,
|
|
59
|
-
TESTNET_ZERO_ADDRESS: () => TESTNET_ZERO_ADDRESS,
|
|
60
|
-
MIN_I128: () => MIN_I128,
|
|
61
|
-
MICROSTX_PER_STX: () => MICROSTX_PER_STX,
|
|
62
|
-
MAX_U128: () => MAX_U128,
|
|
63
|
-
MAX_I128: () => MAX_I128,
|
|
69
|
+
AddressVersion: () => AddressVersion,
|
|
64
70
|
CONTRACT_NAME_REGEX: () => CONTRACT_NAME_REGEX,
|
|
65
|
-
|
|
71
|
+
MAX_I128: () => MAX_I128,
|
|
72
|
+
MAX_U128: () => MAX_U128,
|
|
73
|
+
MICROSTX_PER_STX: () => MICROSTX_PER_STX,
|
|
74
|
+
MIN_I128: () => MIN_I128,
|
|
75
|
+
TESTNET_ZERO_ADDRESS: () => TESTNET_ZERO_ADDRESS,
|
|
76
|
+
ZERO_ADDRESS: () => ZERO_ADDRESS,
|
|
77
|
+
addressToVersion: () => addressToVersion,
|
|
78
|
+
asciiToBytes: () => asciiToBytes,
|
|
79
|
+
bigIntToBytes: () => bigIntToBytes,
|
|
80
|
+
bytesToAscii: () => bytesToAscii,
|
|
81
|
+
bytesToHex: () => bytesToHex,
|
|
82
|
+
bytesToTwosBigInt: () => bytesToTwosBigInt,
|
|
83
|
+
bytesToUtf8: () => bytesToUtf8,
|
|
84
|
+
c32address: () => c32address,
|
|
85
|
+
c32addressDecode: () => c32addressDecode,
|
|
86
|
+
compressPublicKey: () => compressPublicKey,
|
|
87
|
+
concatBytes: () => concatBytes,
|
|
88
|
+
formatStx: () => formatStx,
|
|
89
|
+
formatUnits: () => formatUnits,
|
|
90
|
+
fromTwos: () => fromTwos,
|
|
91
|
+
getContractAddress: () => getContractAddress,
|
|
92
|
+
hash160: () => hash160,
|
|
93
|
+
hashP2PKH: () => hashP2PKH,
|
|
94
|
+
hexToBytes: () => hexToBytes,
|
|
95
|
+
intToBigInt: () => intToBigInt,
|
|
96
|
+
intToBytes: () => intToBytes,
|
|
97
|
+
intToHex: () => intToHex,
|
|
98
|
+
isAddressEqual: () => isAddressEqual,
|
|
99
|
+
isClarityName: () => isClarityName,
|
|
100
|
+
isCompressedPublicKey: () => isCompressedPublicKey,
|
|
101
|
+
isValidAddress: () => isValidAddress,
|
|
102
|
+
parseContractId: () => parseContractId,
|
|
103
|
+
parsePrincipal: () => parsePrincipal,
|
|
104
|
+
parseSignature: () => parseSignature,
|
|
105
|
+
parseStx: () => parseStx,
|
|
106
|
+
parseUnits: () => parseUnits,
|
|
107
|
+
publicKeyToAddress: () => publicKeyToAddress,
|
|
108
|
+
randomBytes: () => randomBytes,
|
|
109
|
+
readUInt16BE: () => readUInt16BE,
|
|
110
|
+
readUInt32BE: () => readUInt32BE,
|
|
111
|
+
recoverAddress: () => recoverAddress,
|
|
112
|
+
recoverPublicKey: () => recoverPublicKey,
|
|
113
|
+
ripemd160: () => import_legacy.ripemd160,
|
|
114
|
+
serializeSignature: () => serializeSignature,
|
|
115
|
+
sha256: () => import_sha2.sha256,
|
|
116
|
+
sha512_256: () => import_sha22.sha512_256,
|
|
117
|
+
signatureRsvToVrs: () => signatureRsvToVrs,
|
|
118
|
+
signatureVrsToRsv: () => signatureVrsToRsv,
|
|
119
|
+
toTwos: () => toTwos,
|
|
120
|
+
txidFromBytes: () => txidFromBytes,
|
|
121
|
+
uncompressPublicKey: () => uncompressPublicKey,
|
|
122
|
+
utf8ToBytes: () => utf8ToBytes,
|
|
123
|
+
validateStacksAddress: () => validateStacksAddress,
|
|
124
|
+
verifyMessageSignature: () => verifyMessageSignature,
|
|
125
|
+
verifySignature: () => verifySignature,
|
|
126
|
+
with0x: () => with0x,
|
|
127
|
+
without0x: () => without0x,
|
|
128
|
+
writeUInt16BE: () => writeUInt16BE,
|
|
129
|
+
writeUInt32BE: () => writeUInt32BE,
|
|
130
|
+
writeUInt8: () => writeUInt8
|
|
66
131
|
});
|
|
67
132
|
module.exports = __toCommonJS(exports_utils);
|
|
68
133
|
|
|
69
|
-
// src/utils/
|
|
134
|
+
// src/utils/encoding.ts
|
|
135
|
+
var hexes = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
136
|
+
function bytesToHex(bytes) {
|
|
137
|
+
let hex = "";
|
|
138
|
+
for (const b of bytes) {
|
|
139
|
+
hex += hexes[b];
|
|
140
|
+
}
|
|
141
|
+
return hex;
|
|
142
|
+
}
|
|
143
|
+
function hexToBytes(hex) {
|
|
144
|
+
let h = without0x(hex);
|
|
145
|
+
if (h.length % 2)
|
|
146
|
+
h = `0${h}`;
|
|
147
|
+
const array = new Uint8Array(h.length / 2);
|
|
148
|
+
for (let i = 0;i < array.length; i++) {
|
|
149
|
+
const j = i * 2;
|
|
150
|
+
const byte = Number.parseInt(h.slice(j, j + 2), 16);
|
|
151
|
+
if (Number.isNaN(byte) || byte < 0)
|
|
152
|
+
throw new Error("Invalid byte sequence");
|
|
153
|
+
array[i] = byte;
|
|
154
|
+
}
|
|
155
|
+
return array;
|
|
156
|
+
}
|
|
157
|
+
function with0x(value) {
|
|
158
|
+
return /^0x/i.test(value) ? value : `0x${value}`;
|
|
159
|
+
}
|
|
160
|
+
function without0x(value) {
|
|
161
|
+
return /^0x/i.test(value) ? value.slice(2) : value;
|
|
162
|
+
}
|
|
163
|
+
function utf8ToBytes(str) {
|
|
164
|
+
return new TextEncoder().encode(str);
|
|
165
|
+
}
|
|
166
|
+
function bytesToUtf8(bytes) {
|
|
167
|
+
return new TextDecoder().decode(bytes);
|
|
168
|
+
}
|
|
169
|
+
function asciiToBytes(str) {
|
|
170
|
+
const bytes = new Uint8Array(str.length);
|
|
171
|
+
for (let i = 0;i < str.length; i++) {
|
|
172
|
+
bytes[i] = str.charCodeAt(i) & 255;
|
|
173
|
+
}
|
|
174
|
+
return bytes;
|
|
175
|
+
}
|
|
176
|
+
function bytesToAscii(bytes) {
|
|
177
|
+
return String.fromCharCode(...bytes);
|
|
178
|
+
}
|
|
179
|
+
function concatBytes(...arrays) {
|
|
180
|
+
if (arrays.length === 1)
|
|
181
|
+
return arrays[0];
|
|
182
|
+
const length = arrays.reduce((a, arr) => a + arr.length, 0);
|
|
183
|
+
const result = new Uint8Array(length);
|
|
184
|
+
let pad = 0;
|
|
185
|
+
for (const arr of arrays) {
|
|
186
|
+
result.set(arr, pad);
|
|
187
|
+
pad += arr.length;
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
function intToBigInt(value) {
|
|
192
|
+
if (typeof value === "bigint")
|
|
193
|
+
return value;
|
|
194
|
+
if (typeof value === "string")
|
|
195
|
+
return BigInt(value);
|
|
196
|
+
if (typeof value === "number") {
|
|
197
|
+
if (!Number.isInteger(value))
|
|
198
|
+
throw new RangeError("Values of type 'number' must be an integer.");
|
|
199
|
+
if (value > Number.MAX_SAFE_INTEGER)
|
|
200
|
+
throw new RangeError(`Values of type 'number' must be <= ${Number.MAX_SAFE_INTEGER}. Use BigInt instead.`);
|
|
201
|
+
return BigInt(value);
|
|
202
|
+
}
|
|
203
|
+
if (value instanceof Uint8Array)
|
|
204
|
+
return BigInt(`0x${bytesToHex(value)}`);
|
|
205
|
+
throw new TypeError("Must be a number, bigint, string, or Uint8Array.");
|
|
206
|
+
}
|
|
207
|
+
function intToBytes(value, byteLength) {
|
|
208
|
+
return bigIntToBytes(intToBigInt(value), byteLength);
|
|
209
|
+
}
|
|
210
|
+
function bigIntToBytes(value, length = 16) {
|
|
211
|
+
const hex = value.toString(16).padStart(length * 2, "0");
|
|
212
|
+
return hexToBytes(hex);
|
|
213
|
+
}
|
|
214
|
+
function intToHex(integer, byteLength = 8) {
|
|
215
|
+
const value = typeof integer === "bigint" ? integer : intToBigInt(integer);
|
|
216
|
+
return value.toString(16).padStart(byteLength * 2, "0");
|
|
217
|
+
}
|
|
218
|
+
function toTwos(value, width) {
|
|
219
|
+
const limit = BigInt(1) << width - BigInt(1);
|
|
220
|
+
if (value < -limit || value > limit - BigInt(1)) {
|
|
221
|
+
throw new Error(`Unable to represent integer in width: ${width}`);
|
|
222
|
+
}
|
|
223
|
+
if (value >= BigInt(0))
|
|
224
|
+
return value;
|
|
225
|
+
return value + (BigInt(1) << width);
|
|
226
|
+
}
|
|
227
|
+
function fromTwos(value, width) {
|
|
228
|
+
if (value & BigInt(1) << width - BigInt(1)) {
|
|
229
|
+
return value - (BigInt(1) << width);
|
|
230
|
+
}
|
|
231
|
+
return value;
|
|
232
|
+
}
|
|
233
|
+
function bytesToTwosBigInt(bytes) {
|
|
234
|
+
if (bytes.length === 0)
|
|
235
|
+
return 0n;
|
|
236
|
+
const hex = bytesToHex(bytes);
|
|
237
|
+
if (hex.length === 0)
|
|
238
|
+
return 0n;
|
|
239
|
+
return fromTwos(BigInt(`0x${hex}`), BigInt(bytes.byteLength * 8));
|
|
240
|
+
}
|
|
241
|
+
function writeUInt32BE(value) {
|
|
242
|
+
const buf = new Uint8Array(4);
|
|
243
|
+
buf[0] = value >>> 24 & 255;
|
|
244
|
+
buf[1] = value >>> 16 & 255;
|
|
245
|
+
buf[2] = value >>> 8 & 255;
|
|
246
|
+
buf[3] = value & 255;
|
|
247
|
+
return buf;
|
|
248
|
+
}
|
|
249
|
+
function readUInt32BE(bytes, offset = 0) {
|
|
250
|
+
return (bytes[offset] << 24 | bytes[offset + 1] << 16 | bytes[offset + 2] << 8 | bytes[offset + 3]) >>> 0;
|
|
251
|
+
}
|
|
252
|
+
function writeUInt16BE(value) {
|
|
253
|
+
const buf = new Uint8Array(2);
|
|
254
|
+
buf[0] = value >>> 8 & 255;
|
|
255
|
+
buf[1] = value & 255;
|
|
256
|
+
return buf;
|
|
257
|
+
}
|
|
258
|
+
function readUInt16BE(bytes, offset = 0) {
|
|
259
|
+
return (bytes[offset] << 8 | bytes[offset + 1]) >>> 0;
|
|
260
|
+
}
|
|
261
|
+
function writeUInt8(value) {
|
|
262
|
+
return new Uint8Array([value & 255]);
|
|
263
|
+
}
|
|
264
|
+
// src/utils/hash.ts
|
|
265
|
+
var import_legacy = require("@noble/hashes/legacy.js");
|
|
266
|
+
var import_sha2 = require("@noble/hashes/sha2.js");
|
|
267
|
+
var import_sha22 = require("@noble/hashes/sha2.js");
|
|
268
|
+
function hash160(input) {
|
|
269
|
+
return import_legacy.ripemd160(import_sha2.sha256(input));
|
|
270
|
+
}
|
|
271
|
+
function txidFromBytes(data) {
|
|
272
|
+
return bytesToHex(import_sha22.sha512_256(data));
|
|
273
|
+
}
|
|
274
|
+
function hashP2PKH(input) {
|
|
275
|
+
return bytesToHex(hash160(input));
|
|
276
|
+
}
|
|
277
|
+
// src/utils/c32.ts
|
|
70
278
|
var import_sha23 = require("@noble/hashes/sha2.js");
|
|
279
|
+
var C32 = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
280
|
+
var HEX = "0123456789abcdef";
|
|
281
|
+
function c32normalize(input) {
|
|
282
|
+
return input.toUpperCase().replace(/O/g, "0").replace(/L|I/g, "1");
|
|
283
|
+
}
|
|
284
|
+
function c32encode(inputHex) {
|
|
285
|
+
let hex = inputHex;
|
|
286
|
+
if (hex.length % 2 !== 0)
|
|
287
|
+
hex = `0${hex}`;
|
|
288
|
+
hex = hex.toLowerCase();
|
|
289
|
+
const res = [];
|
|
290
|
+
let carry = 0;
|
|
291
|
+
for (let i = hex.length - 1;i >= 0; i--) {
|
|
292
|
+
if (carry < 4) {
|
|
293
|
+
const currentCode = HEX.indexOf(hex[i]) >> carry;
|
|
294
|
+
const nextCode = i !== 0 ? HEX.indexOf(hex[i - 1]) : 0;
|
|
295
|
+
const nextBits = 1 + carry;
|
|
296
|
+
const nextLowBits = nextCode % (1 << nextBits) << 5 - nextBits;
|
|
297
|
+
res.unshift(C32[currentCode + nextLowBits]);
|
|
298
|
+
carry = nextBits;
|
|
299
|
+
} else {
|
|
300
|
+
carry = 0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
let leadingZeros = 0;
|
|
304
|
+
while (leadingZeros < res.length && res[leadingZeros] === "0")
|
|
305
|
+
leadingZeros++;
|
|
306
|
+
const stripped = res.slice(leadingZeros);
|
|
307
|
+
const bytes = hexToBytes(hex);
|
|
308
|
+
let zeroBytesCount = 0;
|
|
309
|
+
while (zeroBytesCount < bytes.length && bytes[zeroBytesCount] === 0)
|
|
310
|
+
zeroBytesCount++;
|
|
311
|
+
const prefix = Array(zeroBytesCount).fill(C32[0]);
|
|
312
|
+
return [...prefix, ...stripped].join("");
|
|
313
|
+
}
|
|
314
|
+
function c32decode(c32input) {
|
|
315
|
+
const input = c32normalize(c32input);
|
|
316
|
+
if (!input.match(`^[${C32}]*$`))
|
|
317
|
+
throw new Error("Not a c32-encoded string");
|
|
318
|
+
const zeroPrefix = input.match(`^${C32[0]}*`);
|
|
319
|
+
const numLeadingZeroBytes = zeroPrefix ? zeroPrefix[0]?.length : 0;
|
|
320
|
+
const res = [];
|
|
321
|
+
let carry = 0;
|
|
322
|
+
let carryBits = 0;
|
|
323
|
+
for (let i = input.length - 1;i >= 0; i--) {
|
|
324
|
+
if (carryBits === 4) {
|
|
325
|
+
res.unshift(HEX[carry]);
|
|
326
|
+
carryBits = 0;
|
|
327
|
+
carry = 0;
|
|
328
|
+
}
|
|
329
|
+
const currentValue = (C32.indexOf(input[i]) << carryBits) + carry;
|
|
330
|
+
res.unshift(HEX[currentValue % 16]);
|
|
331
|
+
carryBits += 1;
|
|
332
|
+
carry = currentValue >> 4;
|
|
333
|
+
if (carry > 1 << carryBits)
|
|
334
|
+
throw new Error("Panic error in c32 decoding");
|
|
335
|
+
}
|
|
336
|
+
res.unshift(HEX[carry]);
|
|
337
|
+
if (res.length % 2 === 1)
|
|
338
|
+
res.unshift("0");
|
|
339
|
+
let hexLeadingZeros = 0;
|
|
340
|
+
while (hexLeadingZeros < res.length && res[hexLeadingZeros] === "0")
|
|
341
|
+
hexLeadingZeros++;
|
|
342
|
+
let hexStr = res.slice(hexLeadingZeros - hexLeadingZeros % 2).join("");
|
|
343
|
+
for (let i = 0;i < numLeadingZeroBytes; i++)
|
|
344
|
+
hexStr = `00${hexStr}`;
|
|
345
|
+
return hexStr;
|
|
346
|
+
}
|
|
347
|
+
function c32checksum(dataHex) {
|
|
348
|
+
return bytesToHex(import_sha23.sha256(import_sha23.sha256(hexToBytes(dataHex))).slice(0, 4));
|
|
349
|
+
}
|
|
350
|
+
function c32checkEncode(version, data) {
|
|
351
|
+
if (version < 0 || version >= 32)
|
|
352
|
+
throw new Error("Invalid version (must be between 0 and 31)");
|
|
353
|
+
if (!data.match(/^[0-9a-fA-F]*$/))
|
|
354
|
+
throw new Error("Invalid data (not a hex string)");
|
|
355
|
+
let d = data.toLowerCase();
|
|
356
|
+
if (d.length % 2 !== 0)
|
|
357
|
+
d = `0${d}`;
|
|
358
|
+
let versionHex = version.toString(16);
|
|
359
|
+
if (versionHex.length === 1)
|
|
360
|
+
versionHex = `0${versionHex}`;
|
|
361
|
+
const checksumHex = c32checksum(`${versionHex}${d}`);
|
|
362
|
+
return `${C32[version]}${c32encode(`${d}${checksumHex}`)}`;
|
|
363
|
+
}
|
|
364
|
+
function c32checkDecode(c32data) {
|
|
365
|
+
const normalized = c32normalize(c32data);
|
|
366
|
+
const dataHex = c32decode(normalized.slice(1));
|
|
367
|
+
const version = C32.indexOf(normalized[0]);
|
|
368
|
+
const checksum = dataHex.slice(-8);
|
|
369
|
+
let versionHex = version.toString(16);
|
|
370
|
+
if (versionHex.length === 1)
|
|
371
|
+
versionHex = `0${versionHex}`;
|
|
372
|
+
if (c32checksum(`${versionHex}${dataHex.substring(0, dataHex.length - 8)}`) !== checksum) {
|
|
373
|
+
throw new Error("Invalid c32check string: checksum mismatch");
|
|
374
|
+
}
|
|
375
|
+
return [version, dataHex.substring(0, dataHex.length - 8)];
|
|
376
|
+
}
|
|
377
|
+
function c32address(version, hash160hex) {
|
|
378
|
+
if (!hash160hex.match(/^[0-9a-fA-F]{40}$/)) {
|
|
379
|
+
throw new Error("Invalid argument: not a hash160 hex string");
|
|
380
|
+
}
|
|
381
|
+
return `S${c32checkEncode(version, hash160hex)}`;
|
|
382
|
+
}
|
|
383
|
+
function c32addressDecode(c32addr) {
|
|
384
|
+
if (c32addr.length <= 5)
|
|
385
|
+
throw new Error("Invalid c32 address: invalid length");
|
|
386
|
+
if (c32addr[0] !== "S")
|
|
387
|
+
throw new Error('Invalid c32 address: must start with "S"');
|
|
388
|
+
return c32checkDecode(c32addr.slice(1));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/utils/constants.ts
|
|
392
|
+
var MAX_U128 = (1n << 128n) - 1n;
|
|
393
|
+
var MAX_I128 = (1n << 127n) - 1n;
|
|
394
|
+
var MIN_I128 = -(1n << 127n);
|
|
395
|
+
var AddressVersion = {
|
|
396
|
+
MainnetSingleSig: 22,
|
|
397
|
+
MainnetMultiSig: 20,
|
|
398
|
+
TestnetSingleSig: 26,
|
|
399
|
+
TestnetMultiSig: 21
|
|
400
|
+
};
|
|
401
|
+
var ZERO_ADDRESS = "SP000000000000000000002Q6VF78";
|
|
402
|
+
var TESTNET_ZERO_ADDRESS = "ST000000000000000000002AMW42H";
|
|
403
|
+
var MICROSTX_PER_STX = 1000000n;
|
|
404
|
+
|
|
405
|
+
// src/utils/address.ts
|
|
406
|
+
function publicKeyToAddress(publicKey, network = "mainnet") {
|
|
407
|
+
const bytes = typeof publicKey === "string" ? hexToBytes(without0x(publicKey)) : publicKey;
|
|
408
|
+
const version = network === "mainnet" ? AddressVersion.MainnetSingleSig : AddressVersion.TestnetSingleSig;
|
|
409
|
+
return c32address(version, bytesToHex(hash160(bytes)));
|
|
410
|
+
}
|
|
411
|
+
var CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/;
|
|
412
|
+
function validateStacksAddress(address) {
|
|
413
|
+
try {
|
|
414
|
+
c32addressDecode(address);
|
|
415
|
+
return true;
|
|
416
|
+
} catch {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
var isValidAddress = validateStacksAddress;
|
|
421
|
+
function parsePrincipal(value) {
|
|
422
|
+
const parts = value.split(".");
|
|
423
|
+
if (parts.length > 2)
|
|
424
|
+
return null;
|
|
425
|
+
const [address, contractName] = parts;
|
|
426
|
+
if (!validateStacksAddress(address))
|
|
427
|
+
return null;
|
|
428
|
+
if (contractName === undefined)
|
|
429
|
+
return { address };
|
|
430
|
+
if (!CONTRACT_NAME_REGEX.test(contractName))
|
|
431
|
+
return null;
|
|
432
|
+
return { address, contractName };
|
|
433
|
+
}
|
|
434
|
+
function parseContractId(contractId) {
|
|
435
|
+
const parsed = parsePrincipal(contractId);
|
|
436
|
+
if (!parsed?.contractName)
|
|
437
|
+
throw new Error(`Invalid contract identifier: ${contractId}`);
|
|
438
|
+
return [parsed.address, parsed.contractName];
|
|
439
|
+
}
|
|
440
|
+
function isClarityName(name) {
|
|
441
|
+
const regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;
|
|
442
|
+
return regex.test(name) && name.length < 128;
|
|
443
|
+
}
|
|
444
|
+
function isAddressEqual(a, b) {
|
|
445
|
+
const [versionA, hashA] = c32addressDecode(a);
|
|
446
|
+
const [versionB, hashB] = c32addressDecode(b);
|
|
447
|
+
return versionA === versionB && hashA.toLowerCase() === hashB.toLowerCase();
|
|
448
|
+
}
|
|
449
|
+
function addressToVersion(address) {
|
|
450
|
+
return c32addressDecode(address)[0];
|
|
451
|
+
}
|
|
452
|
+
function getContractAddress(deployer, contractName) {
|
|
453
|
+
if (!validateStacksAddress(deployer)) {
|
|
454
|
+
throw new Error(`Invalid deployer address: ${deployer}`);
|
|
455
|
+
}
|
|
456
|
+
if (!isClarityName(contractName)) {
|
|
457
|
+
throw new Error(`Invalid contract name: ${contractName}`);
|
|
458
|
+
}
|
|
459
|
+
return `${deployer}.${contractName}`;
|
|
460
|
+
}
|
|
461
|
+
// src/utils/units.ts
|
|
462
|
+
function formatUnits(value, decimals) {
|
|
463
|
+
let v = BigInt(value);
|
|
464
|
+
const negative = v < 0n;
|
|
465
|
+
if (negative)
|
|
466
|
+
v = -v;
|
|
467
|
+
const divisor = 10n ** BigInt(decimals);
|
|
468
|
+
const integer = (v / divisor).toString();
|
|
469
|
+
let fraction = (v % divisor).toString().padStart(decimals, "0");
|
|
470
|
+
fraction = fraction.replace(/0+$/, "") || "0";
|
|
471
|
+
const result = `${integer}.${fraction}`;
|
|
472
|
+
return negative ? `-${result}` : result;
|
|
473
|
+
}
|
|
474
|
+
var DECIMAL_STRING = /^-?\d+(\.\d+)?$/;
|
|
475
|
+
function parseUnits(value, decimals) {
|
|
476
|
+
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
477
|
+
throw new RangeError(`Cannot parse ${value} as a decimal amount`);
|
|
478
|
+
}
|
|
479
|
+
let str = typeof value === "number" ? value.toFixed(decimals) : value.trim();
|
|
480
|
+
if (!DECIMAL_STRING.test(str)) {
|
|
481
|
+
throw new RangeError(`Cannot parse "${value}" as a decimal amount: expected digits with an optional fraction, like "1.5"`);
|
|
482
|
+
}
|
|
483
|
+
if (typeof value === "number" && Number(str) !== value) {
|
|
484
|
+
throw new RangeError(`Cannot parse ${value} with ${decimals} decimals: pass the amount as a string to keep every digit`);
|
|
485
|
+
}
|
|
486
|
+
const negative = str.startsWith("-");
|
|
487
|
+
if (negative)
|
|
488
|
+
str = str.slice(1);
|
|
489
|
+
const [integer = "", fraction = ""] = str.split(".");
|
|
490
|
+
if (fraction.length > decimals) {
|
|
491
|
+
throw new Error(`Too many decimal places: "${value}" has ${fraction.length} decimals, max is ${decimals}`);
|
|
492
|
+
}
|
|
493
|
+
const padded = fraction.padEnd(decimals, "0");
|
|
494
|
+
const result = BigInt(integer + padded);
|
|
495
|
+
return negative ? -result : result;
|
|
496
|
+
}
|
|
497
|
+
function formatStx(microStx) {
|
|
498
|
+
return formatUnits(microStx, 6);
|
|
499
|
+
}
|
|
500
|
+
function parseStx(stx) {
|
|
501
|
+
return parseUnits(stx, 6);
|
|
502
|
+
}
|
|
503
|
+
// src/utils/signature.ts
|
|
504
|
+
var import_sha24 = require("@noble/hashes/sha2.js");
|
|
71
505
|
var import_secp256k1 = require("@noble/secp256k1");
|
|
72
506
|
function parseSignature(hex) {
|
|
73
507
|
const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
@@ -112,11 +546,11 @@ function encodeVarint(n) {
|
|
|
112
546
|
if (n < 253)
|
|
113
547
|
return new Uint8Array([n]);
|
|
114
548
|
if (n <= 65535) {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
549
|
+
const buf = new Uint8Array(3);
|
|
550
|
+
buf[0] = 253;
|
|
551
|
+
buf[1] = n & 255;
|
|
552
|
+
buf[2] = n >> 8 & 255;
|
|
553
|
+
return buf;
|
|
120
554
|
}
|
|
121
555
|
const buf = new Uint8Array(5);
|
|
122
556
|
buf[0] = 254;
|
|
@@ -134,7 +568,7 @@ function hashMessage(message, prefix) {
|
|
|
134
568
|
const messageBytes = typeof message === "string" ? utf8ToBytes(message) : message;
|
|
135
569
|
const prefixBytes = utf8ToBytes(prefix);
|
|
136
570
|
const lengthBytes = encodeVarint(messageBytes.length);
|
|
137
|
-
return
|
|
571
|
+
return import_sha24.sha256(concatBytes(prefixBytes, lengthBytes, messageBytes));
|
|
138
572
|
}
|
|
139
573
|
function verifyMessageSignature(message, signature, publicKey) {
|
|
140
574
|
const parsed = parseSignature(signature);
|
|
@@ -167,5 +601,5 @@ function randomBytes(length) {
|
|
|
167
601
|
return import_secp256k12.etc.randomBytes(length ?? 32);
|
|
168
602
|
}
|
|
169
603
|
|
|
170
|
-
//# debugId=
|
|
604
|
+
//# debugId=C16DEF43F45A071764756E2164756E21
|
|
171
605
|
//# sourceMappingURL=index.cjs.map
|