@secondlayer/stacks 3.1.0 → 3.3.0
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-0j16z8ev.js → stacks-08y0y0t7.js} +17 -13
- package/dist/shared/stacks-08y0y0t7.js.map +12 -0
- package/dist/shared/{stacks-bq0weg6n.js → stacks-1mpmzzyp.js} +5 -5
- package/dist/shared/{stacks-18jv9aen.js → stacks-4z72akdf.js} +11 -32
- package/dist/shared/stacks-4z72akdf.js.map +12 -0
- package/dist/shared/{stacks-r2yw4xzb.js → stacks-6bgh2c9h.js} +3 -3
- package/dist/shared/{stacks-mbnfwekf.js → stacks-9d2d0qjc.js} +3 -3
- package/dist/shared/{stacks-6xt8py97.cjs → stacks-agk106zs.cjs} +7 -27
- package/dist/shared/stacks-agk106zs.cjs.map +12 -0
- package/dist/shared/{stacks-gfm3r397.cjs → stacks-bfan7ex7.js} +27 -2
- package/dist/shared/stacks-bfan7ex7.js.map +11 -0
- package/dist/shared/{stacks-x94a1d6s.js → stacks-bm49tsh0.js} +2 -2
- package/dist/shared/{stacks-qchg7s2m.js → stacks-gkf9tsws.js} +3 -3
- package/dist/shared/{stacks-cyeajysa.js → stacks-jknrzd6v.js} +2 -2
- package/dist/shared/{stacks-sd9sc71n.js → stacks-jx146qf1.js} +3 -3
- package/dist/shared/{stacks-xh87kdz8.cjs → stacks-q34k4vnc.cjs} +15 -11
- package/dist/shared/stacks-q34k4vnc.cjs.map +12 -0
- package/dist/shared/{stacks-1x9b2k5y.js → stacks-r1m1r72q.js} +6 -6
- package/dist/shared/{stacks-m77szbay.js → stacks-rw2xbtdv.js} +2 -2
- package/dist/shared/{stacks-2mm20wqf.js → stacks-ttdk2g2f.js} +2 -2
- package/dist/shared/{stacks-ch5vshcd.js → stacks-v1hzk599.js} +7 -7
- package/dist/shared/{stacks-p2c0w0sq.js → stacks-w8tt1fmt.js} +3 -3
- package/dist/shared/{stacks-azp00pve.js → stacks-x5386y2y.cjs} +16 -13
- package/dist/shared/stacks-x5386y2y.cjs.map +11 -0
- package/dist/src/actions/index.js +12 -12
- package/dist/src/bitcoin/index.js +5 -5
- package/dist/src/bns/index.js +10 -10
- package/dist/src/clarity/index.d.cts +3 -0
- package/dist/src/clarity/index.d.ts +3 -0
- package/dist/src/clarity/index.js +7 -6
- package/dist/src/clarity/index.js.map +1 -1
- package/dist/src/connect/index.cjs +1 -2
- package/dist/src/connect/index.cjs.map +2 -2
- package/dist/src/connect/index.js +1 -2
- package/dist/src/connect/index.js.map +2 -2
- package/dist/src/filters/index.d.cts +18 -4
- package/dist/src/filters/index.d.ts +18 -4
- package/dist/src/filters/index.js +2 -2
- package/dist/src/index.d.cts +27 -15
- package/dist/src/index.d.ts +27 -15
- package/dist/src/index.js +11 -11
- package/dist/src/postconditions/index.js +2 -2
- package/dist/src/pox/index.js +9 -9
- package/dist/src/pox5/index.js +9 -9
- package/dist/src/sbtc/index.js +8 -8
- package/dist/src/stackingdao/index.js +9 -9
- package/dist/src/tools/index.cjs +1 -2
- package/dist/src/tools/index.cjs.map +4 -4
- package/dist/src/tools/index.js +1 -2
- package/dist/src/tools/index.js.map +4 -4
- package/dist/src/transactions/index.js +4 -4
- package/dist/src/utils/index.cjs +3 -1
- package/dist/src/utils/index.cjs.map +2 -2
- package/dist/src/utils/index.d.cts +13 -1
- package/dist/src/utils/index.d.ts +13 -1
- package/dist/src/utils/index.js +6 -2
- package/dist/src/utils/index.js.map +2 -2
- package/dist/src/x402/index.js +7 -7
- package/package.json +1 -1
- package/dist/shared/stacks-0j16z8ev.js.map +0 -12
- package/dist/shared/stacks-18jv9aen.js.map +0 -13
- package/dist/shared/stacks-6xt8py97.cjs.map +0 -13
- package/dist/shared/stacks-azp00pve.js.map +0 -11
- package/dist/shared/stacks-gfm3r397.cjs.map +0 -11
- package/dist/shared/stacks-xh87kdz8.cjs.map +0 -12
- /package/dist/shared/{stacks-bq0weg6n.js.map → stacks-1mpmzzyp.js.map} +0 -0
- /package/dist/shared/{stacks-r2yw4xzb.js.map → stacks-6bgh2c9h.js.map} +0 -0
- /package/dist/shared/{stacks-mbnfwekf.js.map → stacks-9d2d0qjc.js.map} +0 -0
- /package/dist/shared/{stacks-x94a1d6s.js.map → stacks-bm49tsh0.js.map} +0 -0
- /package/dist/shared/{stacks-qchg7s2m.js.map → stacks-gkf9tsws.js.map} +0 -0
- /package/dist/shared/{stacks-cyeajysa.js.map → stacks-jknrzd6v.js.map} +0 -0
- /package/dist/shared/{stacks-sd9sc71n.js.map → stacks-jx146qf1.js.map} +0 -0
- /package/dist/shared/{stacks-1x9b2k5y.js.map → stacks-r1m1r72q.js.map} +0 -0
- /package/dist/shared/{stacks-m77szbay.js.map → stacks-rw2xbtdv.js.map} +0 -0
- /package/dist/shared/{stacks-2mm20wqf.js.map → stacks-ttdk2g2f.js.map} +0 -0
- /package/dist/shared/{stacks-ch5vshcd.js.map → stacks-v1hzk599.js.map} +0 -0
- /package/dist/shared/{stacks-p2c0w0sq.js.map → stacks-w8tt1fmt.js.map} +0 -0
package/dist/src/utils/index.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(exports_utils, {
|
|
|
28
28
|
parseUnits: () => parseUnits,
|
|
29
29
|
parseStx: () => parseStx,
|
|
30
30
|
parseSignature: () => parseSignature,
|
|
31
|
+
parsePrincipal: () => parsePrincipal,
|
|
31
32
|
parseContractId: () => parseContractId,
|
|
32
33
|
isValidAddress: () => isValidAddress,
|
|
33
34
|
isCompressedPublicKey: () => isCompressedPublicKey,
|
|
@@ -60,6 +61,7 @@ __export(exports_utils, {
|
|
|
60
61
|
MICROSTX_PER_STX: () => MICROSTX_PER_STX,
|
|
61
62
|
MAX_U128: () => MAX_U128,
|
|
62
63
|
MAX_I128: () => MAX_I128,
|
|
64
|
+
CONTRACT_NAME_REGEX: () => CONTRACT_NAME_REGEX,
|
|
63
65
|
AddressVersion: () => AddressVersion
|
|
64
66
|
});
|
|
65
67
|
module.exports = __toCommonJS(exports_utils);
|
|
@@ -165,5 +167,5 @@ function randomBytes(length) {
|
|
|
165
167
|
return import_secp256k12.etc.randomBytes(length ?? 32);
|
|
166
168
|
}
|
|
167
169
|
|
|
168
|
-
//# debugId=
|
|
170
|
+
//# debugId=6B87ECBAC9286DEB64756E2164756E21
|
|
169
171
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Signature as NobleSignature, verify } from \"@noble/secp256k1\";\nimport { c32address } from \"./address.ts\";\nimport { AddressVersion } from \"./constants.ts\";\nimport { concatBytes, hexToBytes, utf8ToBytes } from \"./encoding.ts\";\nimport { hashP2PKH } from \"./hash.ts\";\n\nexport interface RecoverableSignature {\n\t/** Recovery id (0–3) */\n\trecovery: number;\n\t/** 32-byte r value as hex */\n\tr: string;\n\t/** 32-byte s value as hex */\n\ts: string;\n}\n\n// --- Format conversion ---\n\n/**\n * Parse a 65-byte VRS hex signature into components.\n * VRS format: recovery (1 byte) + r (32 bytes) + s (32 bytes)\n */\nexport function parseSignature(hex: string): RecoverableSignature {\n\tconst clean = hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n\tif (clean.length !== 130) {\n\t\tthrow new Error(\n\t\t\t`Invalid signature length: expected 130 hex chars, got ${clean.length}`,\n\t\t);\n\t}\n\treturn {\n\t\trecovery: Number.parseInt(clean.slice(0, 2), 16),\n\t\tr: clean.slice(2, 66),\n\t\ts: clean.slice(66, 130),\n\t};\n}\n\n/**\n * Serialize a recoverable signature to 65-byte VRS hex (130 chars).\n */\nexport function serializeSignature(sig: RecoverableSignature): string {\n\tconst v = sig.recovery.toString(16).padStart(2, \"0\");\n\treturn v + sig.r + sig.s;\n}\n\n/** Convert VRS hex to RSV hex: r+s (128 chars) + recovery (2 chars). */\nexport function signatureVrsToRsv(vrs: string): string {\n\tconst clean = vrs.startsWith(\"0x\") ? vrs.slice(2) : vrs;\n\treturn clean.slice(2) + clean.slice(0, 2);\n}\n\n/** Convert RSV hex to VRS hex: recovery (2 chars) + r+s (128 chars). */\nexport function signatureRsvToVrs(rsv: string): string {\n\tconst clean = rsv.startsWith(\"0x\") ? rsv.slice(2) : rsv;\n\treturn clean.slice(-2) + clean.slice(0, -2);\n}\n\n// --- Recovery ---\n\n/**\n * Recover a public key from a message hash and VRS signature.\n * @returns hex-encoded public key (33 bytes compressed, or 65 bytes uncompressed)\n */\nexport function recoverPublicKey(\n\thash: Uint8Array | string,\n\tsignature: string,\n\tcompressed = true,\n): string {\n\tconst parsed = parseSignature(signature);\n\tconst rs = parsed.r + parsed.s;\n\tconst sig = NobleSignature.fromCompact(rs).addRecoveryBit(parsed.recovery);\n\tconst msgHash = typeof hash === \"string\" ? hexToBytes(hash) : hash;\n\tconst point = sig.recoverPublicKey(msgHash);\n\treturn point.toHex(compressed);\n}\n\n/**\n * Recover a Stacks address from a message hash and VRS signature.\n * @param addressVersion defaults to MainnetSingleSig (22)\n */\nexport function recoverAddress(\n\thash: Uint8Array | string,\n\tsignature: string,\n\taddressVersion: number = AddressVersion.MainnetSingleSig,\n): string {\n\tconst pubkey = recoverPublicKey(hash, signature, true);\n\tconst pubkeyHash = hashP2PKH(hexToBytes(pubkey));\n\treturn c32address(addressVersion, pubkeyHash);\n}\n\n// --- Verification ---\n\n/**\n * Verify an ECDSA signature against a message hash and public key.\n * Accepts compact (64-byte) signature as hex or Uint8Array.\n */\nexport function verifySignature(\n\thash: Uint8Array | string,\n\tsignature: string | Uint8Array,\n\tpublicKey: string | Uint8Array,\n): boolean {\n\treturn verify(signature, hash, publicKey, { lowS: false });\n}\n\n/** Bitcoin-style varint encoding for message length prefix. */\nfunction encodeVarint(n: number): Uint8Array {\n\tif (n < 0xfd) return new Uint8Array([n]);\n\tif (n <= 0xffff) {\n\t\tconst buf = new Uint8Array(3);\n\t\tbuf[0] = 0xfd;\n\t\tbuf[1] = n & 0xff;\n\t\tbuf[2] = (n >> 8) & 0xff;\n\t\treturn buf;\n\t}\n\tconst buf = new Uint8Array(5);\n\tbuf[0] = 0xfe;\n\tbuf[1] = n & 0xff;\n\tbuf[2] = (n >> 8) & 0xff;\n\tbuf[3] = (n >> 16) & 0xff;\n\tbuf[4] = (n >> 24) & 0xff;\n\treturn buf;\n}\n\nconst STACKS_MESSAGE_PREFIX = \"\\x17Stacks Signed Message:\\n\";\nconst LEGACY_MESSAGE_PREFIX = \"\\x18Stacks Message Signing:\\n\";\n\n/** Hash a message with the Stacks structured message prefix. */\nfunction hashMessage(message: string | Uint8Array, prefix: string): Uint8Array {\n\tconst messageBytes =\n\t\ttypeof message === \"string\" ? utf8ToBytes(message) : message;\n\tconst prefixBytes = utf8ToBytes(prefix);\n\tconst lengthBytes = encodeVarint(messageBytes.length);\n\treturn sha256(concatBytes(prefixBytes, lengthBytes, messageBytes));\n}\n\n/**\n * Verify a signed Stacks message.\n * Parses a VRS signature, extracts r+s for verification.\n * Falls back to legacy prefix if standard prefix fails.\n */\nexport function verifyMessageSignature(\n\tmessage: string | Uint8Array,\n\tsignature: string,\n\tpublicKey: string,\n): boolean {\n\tconst parsed = parseSignature(signature);\n\tconst compactSig = parsed.r + parsed.s;\n\n\tconst msgHash = hashMessage(message, STACKS_MESSAGE_PREFIX);\n\tif (verify(compactSig, msgHash, publicKey, { lowS: false })) return true;\n\n\t// Fallback to legacy prefix\n\tif (typeof message === \"string\") {\n\t\tconst legacyHash = hashMessage(message, LEGACY_MESSAGE_PREFIX);\n\t\tif (verify(compactSig, legacyHash, publicKey, { lowS: false })) return true;\n\t}\n\n\treturn false;\n}\n",
|
|
6
6
|
"import { Point, etc } from \"@noble/secp256k1\";\nimport { bytesToHex, hexToBytes } from \"./encoding.ts\";\n\n/** Compress a public key to 33 bytes (hex). */\nexport function compressPublicKey(publicKey: string | Uint8Array): string {\n\tconst hex = typeof publicKey === \"string\" ? publicKey : bytesToHex(publicKey);\n\treturn Point.fromHex(hex).toHex(true);\n}\n\n/** Uncompress a public key to 65 bytes (hex). */\nexport function uncompressPublicKey(publicKey: string | Uint8Array): string {\n\tconst hex = typeof publicKey === \"string\" ? publicKey : bytesToHex(publicKey);\n\treturn Point.fromHex(hex).toHex(false);\n}\n\n/** Check if a public key is in compressed format (starts with 0x02 or 0x03). */\nexport function isCompressedPublicKey(publicKey: string | Uint8Array): boolean {\n\tconst bytes =\n\t\ttypeof publicKey === \"string\" ? hexToBytes(publicKey) : publicKey;\n\treturn bytes.length === 33 && (bytes[0] === 0x02 || bytes[0] === 0x03);\n}\n\n/** Generate cryptographically secure random bytes. Defaults to 32 bytes. */\nexport function randomBytes(length?: number): Uint8Array {\n\treturn etc.randomBytes(length ?? 32);\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAuB,IAAvB;AACoD,IAApD;AAqBO,SAAS,cAAc,CAAC,KAAmC;AAAA,EACjE,MAAM,QAAQ,IAAI,WAAW,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI;AAAA,EACpD,IAAI,MAAM,WAAW,KAAK;AAAA,IACzB,MAAM,IAAI,MACT,yDAAyD,MAAM,QAChE;AAAA,EACD;AAAA,EACA,OAAO;AAAA,IACN,UAAU,OAAO,SAAS,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,IAC/C,GAAG,MAAM,MAAM,GAAG,EAAE;AAAA,IACpB,GAAG,MAAM,MAAM,IAAI,GAAG;AAAA,EACvB;AAAA;AAMM,SAAS,kBAAkB,CAAC,KAAmC;AAAA,EACrE,MAAM,IAAI,IAAI,SAAS,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAAA,EACnD,OAAO,IAAI,IAAI,IAAI,IAAI;AAAA;AAIjB,SAAS,iBAAiB,CAAC,KAAqB;AAAA,EACtD,MAAM,QAAQ,IAAI,WAAW,IAAI,IAAI,IAAI,MAAM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SAAS;AAAA,EAC5E,OAAO,wBAAM,QAAQ,GAAG,EAAE,MAAM,KAAK;AAAA;AAI/B,SAAS,qBAAqB,CAAC,WAAyC;AAAA,EAC9E,MAAM,QACL,OAAO,cAAc,WAAW,WAAW,SAAS,IAAI;AAAA,EACzD,OAAO,MAAM,WAAW,OAAO,MAAM,OAAO,KAAQ,MAAM,OAAO;AAAA;AAI3D,SAAS,WAAW,CAAC,QAA6B;AAAA,EACxD,OAAO,sBAAI,YAAY,UAAU,EAAE;AAAA;",
|
|
9
|
+
"debugId": "6B87ECBAC9286DEB64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -35,9 +35,21 @@ declare function c32addressDecode(c32addr: string): [number, string];
|
|
|
35
35
|
* Derive the single-sig Stacks address for a compressed public key.
|
|
36
36
|
*/
|
|
37
37
|
declare function publicKeyToAddress(publicKey: string | Uint8Array, network?: "mainnet" | "testnet"): string;
|
|
38
|
+
/** Clarity contract-name grammar: leading letter, then letters/digits/`-`/`_`.
|
|
39
|
+
* Underscore is legal (SIP-002) and deployed contracts use it — matches the
|
|
40
|
+
* pattern the Index API already accepts for contract ids. */
|
|
41
|
+
declare const CONTRACT_NAME_REGEX: RegExp;
|
|
38
42
|
declare function validateStacksAddress(address: string): boolean;
|
|
39
43
|
/** Alias for validateStacksAddress — matches future.md naming. */
|
|
40
44
|
declare const isValidAddress: (address: string) => boolean;
|
|
45
|
+
/** Parse a principal into its parts, or null when malformed. The single
|
|
46
|
+
* definition of "valid principal" for this package: exactly one optional
|
|
47
|
+
* `.name` segment (never two), a c32-decodable address, and a contract name
|
|
48
|
+
* matching the Clarity grammar. */
|
|
49
|
+
declare function parsePrincipal(value: string): {
|
|
50
|
+
address: string
|
|
51
|
+
contractName?: string
|
|
52
|
+
} | null;
|
|
41
53
|
declare function parseContractId(contractId: string): [string, string];
|
|
42
54
|
declare function isClarityName(name: string): boolean;
|
|
43
55
|
/**
|
|
@@ -141,4 +153,4 @@ declare function uncompressPublicKey(publicKey: string | Uint8Array): string;
|
|
|
141
153
|
declare function isCompressedPublicKey(publicKey: string | Uint8Array): boolean;
|
|
142
154
|
/** Generate cryptographically secure random bytes. Defaults to 32 bytes. */
|
|
143
155
|
declare function randomBytes(length?: number): Uint8Array;
|
|
144
|
-
export { writeUInt8, writeUInt32BE, writeUInt16BE, without0x, with0x, verifySignature, verifyMessageSignature, validateStacksAddress, utf8ToBytes, uncompressPublicKey, txidFromBytes, toTwos, signatureVrsToRsv, signatureRsvToVrs, sha512_256, sha256, serializeSignature, ripemd160, recoverPublicKey, recoverAddress, readUInt32BE, readUInt16BE, randomBytes, publicKeyToAddress, parseUnits, parseStx, parseSignature, parseContractId, isValidAddress, isCompressedPublicKey, isClarityName, isAddressEqual, intToHex, intToBytes, intToBigInt, hexToBytes, hashP2PKH, hash160, getContractAddress, fromTwos, formatUnits, formatStx, concatBytes, compressPublicKey, c32addressDecode, c32address, bytesToUtf8, bytesToTwosBigInt, bytesToHex, bytesToAscii, bigIntToBytes, asciiToBytes, addressToVersion, ZERO_ADDRESS, TESTNET_ZERO_ADDRESS, RecoverableSignature, MIN_I128, MICROSTX_PER_STX, MAX_U128, MAX_I128, IntegerType, AddressVersion };
|
|
156
|
+
export { writeUInt8, writeUInt32BE, writeUInt16BE, without0x, with0x, verifySignature, verifyMessageSignature, validateStacksAddress, utf8ToBytes, uncompressPublicKey, txidFromBytes, toTwos, signatureVrsToRsv, signatureRsvToVrs, sha512_256, sha256, serializeSignature, ripemd160, recoverPublicKey, recoverAddress, readUInt32BE, readUInt16BE, randomBytes, publicKeyToAddress, parseUnits, parseStx, parseSignature, parsePrincipal, parseContractId, isValidAddress, isCompressedPublicKey, isClarityName, isAddressEqual, intToHex, intToBytes, intToBigInt, hexToBytes, hashP2PKH, hash160, getContractAddress, fromTwos, formatUnits, formatStx, concatBytes, compressPublicKey, c32addressDecode, c32address, bytesToUtf8, bytesToTwosBigInt, bytesToHex, bytesToAscii, bigIntToBytes, asciiToBytes, addressToVersion, ZERO_ADDRESS, TESTNET_ZERO_ADDRESS, RecoverableSignature, MIN_I128, MICROSTX_PER_STX, MAX_U128, MAX_I128, IntegerType, CONTRACT_NAME_REGEX, AddressVersion };
|
|
@@ -35,9 +35,21 @@ declare function c32addressDecode(c32addr: string): [number, string];
|
|
|
35
35
|
* Derive the single-sig Stacks address for a compressed public key.
|
|
36
36
|
*/
|
|
37
37
|
declare function publicKeyToAddress(publicKey: string | Uint8Array, network?: "mainnet" | "testnet"): string;
|
|
38
|
+
/** Clarity contract-name grammar: leading letter, then letters/digits/`-`/`_`.
|
|
39
|
+
* Underscore is legal (SIP-002) and deployed contracts use it — matches the
|
|
40
|
+
* pattern the Index API already accepts for contract ids. */
|
|
41
|
+
declare const CONTRACT_NAME_REGEX: RegExp;
|
|
38
42
|
declare function validateStacksAddress(address: string): boolean;
|
|
39
43
|
/** Alias for validateStacksAddress — matches future.md naming. */
|
|
40
44
|
declare const isValidAddress: (address: string) => boolean;
|
|
45
|
+
/** Parse a principal into its parts, or null when malformed. The single
|
|
46
|
+
* definition of "valid principal" for this package: exactly one optional
|
|
47
|
+
* `.name` segment (never two), a c32-decodable address, and a contract name
|
|
48
|
+
* matching the Clarity grammar. */
|
|
49
|
+
declare function parsePrincipal(value: string): {
|
|
50
|
+
address: string
|
|
51
|
+
contractName?: string
|
|
52
|
+
} | null;
|
|
41
53
|
declare function parseContractId(contractId: string): [string, string];
|
|
42
54
|
declare function isClarityName(name: string): boolean;
|
|
43
55
|
/**
|
|
@@ -141,4 +153,4 @@ declare function uncompressPublicKey(publicKey: string | Uint8Array): string;
|
|
|
141
153
|
declare function isCompressedPublicKey(publicKey: string | Uint8Array): boolean;
|
|
142
154
|
/** Generate cryptographically secure random bytes. Defaults to 32 bytes. */
|
|
143
155
|
declare function randomBytes(length?: number): Uint8Array;
|
|
144
|
-
export { writeUInt8, writeUInt32BE, writeUInt16BE, without0x, with0x, verifySignature, verifyMessageSignature, validateStacksAddress, utf8ToBytes, uncompressPublicKey, txidFromBytes, toTwos, signatureVrsToRsv, signatureRsvToVrs, sha512_256, sha256, serializeSignature, ripemd160, recoverPublicKey, recoverAddress, readUInt32BE, readUInt16BE, randomBytes, publicKeyToAddress, parseUnits, parseStx, parseSignature, parseContractId, isValidAddress, isCompressedPublicKey, isClarityName, isAddressEqual, intToHex, intToBytes, intToBigInt, hexToBytes, hashP2PKH, hash160, getContractAddress, fromTwos, formatUnits, formatStx, concatBytes, compressPublicKey, c32addressDecode, c32address, bytesToUtf8, bytesToTwosBigInt, bytesToHex, bytesToAscii, bigIntToBytes, asciiToBytes, addressToVersion, ZERO_ADDRESS, TESTNET_ZERO_ADDRESS, RecoverableSignature, MIN_I128, MICROSTX_PER_STX, MAX_U128, MAX_I128, IntegerType, AddressVersion };
|
|
156
|
+
export { writeUInt8, writeUInt32BE, writeUInt16BE, without0x, with0x, verifySignature, verifyMessageSignature, validateStacksAddress, utf8ToBytes, uncompressPublicKey, txidFromBytes, toTwos, signatureVrsToRsv, signatureRsvToVrs, sha512_256, sha256, serializeSignature, ripemd160, recoverPublicKey, recoverAddress, readUInt32BE, readUInt16BE, randomBytes, publicKeyToAddress, parseUnits, parseStx, parseSignature, parsePrincipal, parseContractId, isValidAddress, isCompressedPublicKey, isClarityName, isAddressEqual, intToHex, intToBytes, intToBigInt, hexToBytes, hashP2PKH, hash160, getContractAddress, fromTwos, formatUnits, formatStx, concatBytes, compressPublicKey, c32addressDecode, c32address, bytesToUtf8, bytesToTwosBigInt, bytesToHex, bytesToAscii, bigIntToBytes, asciiToBytes, addressToVersion, ZERO_ADDRESS, TESTNET_ZERO_ADDRESS, RecoverableSignature, MIN_I128, MICROSTX_PER_STX, MAX_U128, MAX_I128, IntegerType, CONTRACT_NAME_REGEX, AddressVersion };
|
package/dist/src/utils/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "../../shared/stacks-913a2rx7.js";
|
|
7
7
|
import {
|
|
8
8
|
AddressVersion,
|
|
9
|
+
CONTRACT_NAME_REGEX,
|
|
9
10
|
MAX_I128,
|
|
10
11
|
MAX_U128,
|
|
11
12
|
MICROSTX_PER_STX,
|
|
@@ -18,9 +19,10 @@ import {
|
|
|
18
19
|
isClarityName,
|
|
19
20
|
isValidAddress,
|
|
20
21
|
parseContractId,
|
|
22
|
+
parsePrincipal,
|
|
21
23
|
publicKeyToAddress,
|
|
22
24
|
validateStacksAddress
|
|
23
|
-
} from "../../shared/stacks-
|
|
25
|
+
} from "../../shared/stacks-bfan7ex7.js";
|
|
24
26
|
import {
|
|
25
27
|
asciiToBytes,
|
|
26
28
|
bigIntToBytes,
|
|
@@ -180,6 +182,7 @@ export {
|
|
|
180
182
|
parseUnits,
|
|
181
183
|
parseStx,
|
|
182
184
|
parseSignature,
|
|
185
|
+
parsePrincipal,
|
|
183
186
|
parseContractId,
|
|
184
187
|
isValidAddress,
|
|
185
188
|
isCompressedPublicKey,
|
|
@@ -212,8 +215,9 @@ export {
|
|
|
212
215
|
MICROSTX_PER_STX,
|
|
213
216
|
MAX_U128,
|
|
214
217
|
MAX_I128,
|
|
218
|
+
CONTRACT_NAME_REGEX,
|
|
215
219
|
AddressVersion
|
|
216
220
|
};
|
|
217
221
|
|
|
218
|
-
//# debugId=
|
|
222
|
+
//# debugId=195579D5E6B81F9C64756E2164756E21
|
|
219
223
|
//# sourceMappingURL=index.js.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { Signature as NobleSignature, verify } from \"@noble/secp256k1\";\nimport { c32address } from \"./address.ts\";\nimport { AddressVersion } from \"./constants.ts\";\nimport { concatBytes, hexToBytes, utf8ToBytes } from \"./encoding.ts\";\nimport { hashP2PKH } from \"./hash.ts\";\n\nexport interface RecoverableSignature {\n\t/** Recovery id (0–3) */\n\trecovery: number;\n\t/** 32-byte r value as hex */\n\tr: string;\n\t/** 32-byte s value as hex */\n\ts: string;\n}\n\n// --- Format conversion ---\n\n/**\n * Parse a 65-byte VRS hex signature into components.\n * VRS format: recovery (1 byte) + r (32 bytes) + s (32 bytes)\n */\nexport function parseSignature(hex: string): RecoverableSignature {\n\tconst clean = hex.startsWith(\"0x\") ? hex.slice(2) : hex;\n\tif (clean.length !== 130) {\n\t\tthrow new Error(\n\t\t\t`Invalid signature length: expected 130 hex chars, got ${clean.length}`,\n\t\t);\n\t}\n\treturn {\n\t\trecovery: Number.parseInt(clean.slice(0, 2), 16),\n\t\tr: clean.slice(2, 66),\n\t\ts: clean.slice(66, 130),\n\t};\n}\n\n/**\n * Serialize a recoverable signature to 65-byte VRS hex (130 chars).\n */\nexport function serializeSignature(sig: RecoverableSignature): string {\n\tconst v = sig.recovery.toString(16).padStart(2, \"0\");\n\treturn v + sig.r + sig.s;\n}\n\n/** Convert VRS hex to RSV hex: r+s (128 chars) + recovery (2 chars). */\nexport function signatureVrsToRsv(vrs: string): string {\n\tconst clean = vrs.startsWith(\"0x\") ? vrs.slice(2) : vrs;\n\treturn clean.slice(2) + clean.slice(0, 2);\n}\n\n/** Convert RSV hex to VRS hex: recovery (2 chars) + r+s (128 chars). */\nexport function signatureRsvToVrs(rsv: string): string {\n\tconst clean = rsv.startsWith(\"0x\") ? rsv.slice(2) : rsv;\n\treturn clean.slice(-2) + clean.slice(0, -2);\n}\n\n// --- Recovery ---\n\n/**\n * Recover a public key from a message hash and VRS signature.\n * @returns hex-encoded public key (33 bytes compressed, or 65 bytes uncompressed)\n */\nexport function recoverPublicKey(\n\thash: Uint8Array | string,\n\tsignature: string,\n\tcompressed = true,\n): string {\n\tconst parsed = parseSignature(signature);\n\tconst rs = parsed.r + parsed.s;\n\tconst sig = NobleSignature.fromCompact(rs).addRecoveryBit(parsed.recovery);\n\tconst msgHash = typeof hash === \"string\" ? hexToBytes(hash) : hash;\n\tconst point = sig.recoverPublicKey(msgHash);\n\treturn point.toHex(compressed);\n}\n\n/**\n * Recover a Stacks address from a message hash and VRS signature.\n * @param addressVersion defaults to MainnetSingleSig (22)\n */\nexport function recoverAddress(\n\thash: Uint8Array | string,\n\tsignature: string,\n\taddressVersion: number = AddressVersion.MainnetSingleSig,\n): string {\n\tconst pubkey = recoverPublicKey(hash, signature, true);\n\tconst pubkeyHash = hashP2PKH(hexToBytes(pubkey));\n\treturn c32address(addressVersion, pubkeyHash);\n}\n\n// --- Verification ---\n\n/**\n * Verify an ECDSA signature against a message hash and public key.\n * Accepts compact (64-byte) signature as hex or Uint8Array.\n */\nexport function verifySignature(\n\thash: Uint8Array | string,\n\tsignature: string | Uint8Array,\n\tpublicKey: string | Uint8Array,\n): boolean {\n\treturn verify(signature, hash, publicKey, { lowS: false });\n}\n\n/** Bitcoin-style varint encoding for message length prefix. */\nfunction encodeVarint(n: number): Uint8Array {\n\tif (n < 0xfd) return new Uint8Array([n]);\n\tif (n <= 0xffff) {\n\t\tconst buf = new Uint8Array(3);\n\t\tbuf[0] = 0xfd;\n\t\tbuf[1] = n & 0xff;\n\t\tbuf[2] = (n >> 8) & 0xff;\n\t\treturn buf;\n\t}\n\tconst buf = new Uint8Array(5);\n\tbuf[0] = 0xfe;\n\tbuf[1] = n & 0xff;\n\tbuf[2] = (n >> 8) & 0xff;\n\tbuf[3] = (n >> 16) & 0xff;\n\tbuf[4] = (n >> 24) & 0xff;\n\treturn buf;\n}\n\nconst STACKS_MESSAGE_PREFIX = \"\\x17Stacks Signed Message:\\n\";\nconst LEGACY_MESSAGE_PREFIX = \"\\x18Stacks Message Signing:\\n\";\n\n/** Hash a message with the Stacks structured message prefix. */\nfunction hashMessage(message: string | Uint8Array, prefix: string): Uint8Array {\n\tconst messageBytes =\n\t\ttypeof message === \"string\" ? utf8ToBytes(message) : message;\n\tconst prefixBytes = utf8ToBytes(prefix);\n\tconst lengthBytes = encodeVarint(messageBytes.length);\n\treturn sha256(concatBytes(prefixBytes, lengthBytes, messageBytes));\n}\n\n/**\n * Verify a signed Stacks message.\n * Parses a VRS signature, extracts r+s for verification.\n * Falls back to legacy prefix if standard prefix fails.\n */\nexport function verifyMessageSignature(\n\tmessage: string | Uint8Array,\n\tsignature: string,\n\tpublicKey: string,\n): boolean {\n\tconst parsed = parseSignature(signature);\n\tconst compactSig = parsed.r + parsed.s;\n\n\tconst msgHash = hashMessage(message, STACKS_MESSAGE_PREFIX);\n\tif (verify(compactSig, msgHash, publicKey, { lowS: false })) return true;\n\n\t// Fallback to legacy prefix\n\tif (typeof message === \"string\") {\n\t\tconst legacyHash = hashMessage(message, LEGACY_MESSAGE_PREFIX);\n\t\tif (verify(compactSig, legacyHash, publicKey, { lowS: false })) return true;\n\t}\n\n\treturn false;\n}\n",
|
|
6
6
|
"import { Point, etc } from \"@noble/secp256k1\";\nimport { bytesToHex, hexToBytes } from \"./encoding.ts\";\n\n/** Compress a public key to 33 bytes (hex). */\nexport function compressPublicKey(publicKey: string | Uint8Array): string {\n\tconst hex = typeof publicKey === \"string\" ? publicKey : bytesToHex(publicKey);\n\treturn Point.fromHex(hex).toHex(true);\n}\n\n/** Uncompress a public key to 65 bytes (hex). */\nexport function uncompressPublicKey(publicKey: string | Uint8Array): string {\n\tconst hex = typeof publicKey === \"string\" ? publicKey : bytesToHex(publicKey);\n\treturn Point.fromHex(hex).toHex(false);\n}\n\n/** Check if a public key is in compressed format (starts with 0x02 or 0x03). */\nexport function isCompressedPublicKey(publicKey: string | Uint8Array): boolean {\n\tconst bytes =\n\t\ttypeof publicKey === \"string\" ? hexToBytes(publicKey) : publicKey;\n\treturn bytes.length === 33 && (bytes[0] === 0x02 || bytes[0] === 0x03);\n}\n\n/** Generate cryptographically secure random bytes. Defaults to 32 bytes. */\nexport function randomBytes(length?: number): Uint8Array {\n\treturn etc.randomBytes(length ?? 32);\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "
|
|
9
|
-
"debugId": "
|
|
8
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mBAAS;AACT,sBAAS;AAqBF,SAAS,cAAc,CA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AAI,OAAO;AAAA,EAErC,MAAM,UAAU,YAAY,SAAS,qBAAqB;AAAA,EAC1D,IAAI,OAAO,YAAY,SAAS,WAAW,EAAE,MAAM,MAAM,CAAC;AAAA,IAAG,OAAO;AAAA,EAGpE,IAAI,OAAO,YAAY,UAAU;AAAA,IAChC,MAAM,aAAa,YAAY,SAAS,qBAAqB;AAAA,IAC7D,IAAI,OAAO,YAAY,YAAY,WAAW,EAAE,MAAM,MAAM,CAAC;AAAA,MAAG,OAAO;AAAA,EACxE;AAAA,EAEA,OAAO;AAAA;;AC5JR;AAIO,SAAS,iBAAiB,CAAC,WAAwC;AAAA,EACzE,MAAM,MAAM,OAAO,cAAc,WAAW,YAAY,WAAW,SAAS;AAAA,EAC5E,OAAO,MAAM,QAAQ,GAAG,EAAE,MAAM,IAAI;AAAA;AAI9B,SAAS,mBAAmB,CAAC,WAAwC;AAAA,EAC3E,MAAM,MAAM,OAAO,cAAc,WAAW,YAAY,WAAW,SAAS;AAAA,EAC5E,OAAO,MAAM,QAAQ,GAAG,EAAE,MAAM,KAAK;AAAA;AAI/B,SAAS,qBAAqB,CAAC,WAAyC;AAAA,EAC9E,MAAM,QACL,OAAO,cAAc,WAAW,WAAW,SAAS,IAAI;AAAA,EACzD,OAAO,MAAM,WAAW,OAAO,MAAM,OAAO,KAAQ,MAAM,OAAO;AAAA;AAI3D,SAAS,WAAW,CAAC,QAA6B;AAAA,EACxD,OAAO,IAAI,YAAY,UAAU,EAAE;AAAA;",
|
|
9
|
+
"debugId": "195579D5E6B81F9C64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/src/x402/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sponsorTransaction
|
|
3
|
-
} from "../../shared/stacks-
|
|
3
|
+
} from "../../shared/stacks-w8tt1fmt.js";
|
|
4
4
|
import {
|
|
5
5
|
sendTransaction
|
|
6
|
-
} from "../../shared/stacks-
|
|
6
|
+
} from "../../shared/stacks-9d2d0qjc.js";
|
|
7
7
|
import"../../shared/stacks-fh48neva.js";
|
|
8
8
|
import"../../shared/stacks-709tra19.js";
|
|
9
9
|
import {
|
|
10
10
|
Pc
|
|
11
|
-
} from "../../shared/stacks-
|
|
11
|
+
} from "../../shared/stacks-bm49tsh0.js";
|
|
12
12
|
import {
|
|
13
13
|
deserializeTransaction
|
|
14
|
-
} from "../../shared/stacks-
|
|
14
|
+
} from "../../shared/stacks-gkf9tsws.js";
|
|
15
15
|
import {
|
|
16
16
|
MEMO_MAX_LENGTH_BYTES,
|
|
17
17
|
buildContractCall,
|
|
18
18
|
buildTokenTransfer
|
|
19
|
-
} from "../../shared/stacks-
|
|
19
|
+
} from "../../shared/stacks-jx146qf1.js";
|
|
20
20
|
import {
|
|
21
21
|
Cl
|
|
22
|
-
} from "../../shared/stacks-
|
|
22
|
+
} from "../../shared/stacks-ttdk2g2f.js";
|
|
23
23
|
import {
|
|
24
24
|
parseContractId
|
|
25
|
-
} from "../../shared/stacks-
|
|
25
|
+
} from "../../shared/stacks-bfan7ex7.js";
|
|
26
26
|
import {
|
|
27
27
|
utf8ToBytes
|
|
28
28
|
} from "../../shared/stacks-qs5fzts5.js";
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/filters/event-types.ts", "../src/filters/validate.ts", "../src/filters/factories.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"// The decoded event-type vocabulary — canonical home. Index (decoded layer)\n// and Streams (canonical firehose) expose the SAME set. This lives in\n// @secondlayer/stacks because it is the leaf of the dependency graph\n// (shared → stacks), so no package can drift a private copy upward:\n// @secondlayer/shared re-exports it for back-compat.\nexport const DECODED_EVENT_TYPES = [\n\t\"stx_transfer\",\n\t\"stx_mint\",\n\t\"stx_burn\",\n\t\"stx_lock\",\n\t\"ft_transfer\",\n\t\"ft_mint\",\n\t\"ft_burn\",\n\t\"nft_transfer\",\n\t\"nft_mint\",\n\t\"nft_burn\",\n\t\"print\",\n] as const;\n\nexport type DecodedEventType = (typeof DECODED_EVENT_TYPES)[number];\n\n/** Every chain-event filter member across all four surfaces: the 10 decoded\n * token/STX types, the three contract-shaped types (spelled as subgraphs and\n * triggers spell them — Index/Streams project `print_event` → `print`), and\n * the five sBTC lifecycle types (Subscriptions-only). */\nexport const CHAIN_EVENT_FILTER_TYPES = [\n\t\"stx_transfer\",\n\t\"stx_mint\",\n\t\"stx_burn\",\n\t\"stx_lock\",\n\t\"ft_transfer\",\n\t\"ft_mint\",\n\t\"ft_burn\",\n\t\"nft_transfer\",\n\t\"nft_mint\",\n\t\"nft_burn\",\n\t\"contract_call\",\n\t\"contract_deploy\",\n\t\"print_event\",\n\t\"sbtc_deposit\",\n\t\"sbtc_withdrawal_create\",\n\t\"sbtc_withdrawal_accept\",\n\t\"sbtc_withdrawal_reject\",\n\t\"sbtc_withdrawal_swept_confirmed\",\n] as const;\n\nexport type ChainEventFilterType = (typeof CHAIN_EVENT_FILTER_TYPES)[number];\n",
|
|
6
|
-
"import { isValidAddress } from \"../utils/address.ts\";\n\n/** A validated Stacks principal (standard or contract). Branded so downstream\n * code can require \"already validated\" without re-checking. */\nexport type Principal = string & { readonly __principal: unique symbol };\n\n/**\n * `<contract>::<asset-name>` — the shape a fungible/non-fungible asset filter\n * takes, expressed so the compiler can check it.\n *\n * The most common mistake in this API is passing a CONTRACT ID\n * (`SP….sbtc-token`) where an asset identifier (`SP….sbtc-token::sbtc-token`)\n * belongs, and the failure mode is a query that quietly returns zero rows. The\n * two differ structurally by `::`, so a template-literal type catches it at the\n * call site — no brand, no cast, literals just work.\n *\n * A value that is only known at runtime (config, env) is not narrow enough on\n * purpose; run it through {@link assetId} once, which validates and narrows.\n *\n * Wildcard patterns (Subscriptions/Subgraphs-only) are admitted by the second arm — they\n * are legitimately not full identifiers (`SPB.*`), and the runtime validator\n * short-circuits on them for the same reason.\n */\nexport type AssetIdentifier = `${string}::${string}` | `${string}*${string}`;\n\n/**\n * Narrow a runtime string to an {@link AssetIdentifier}, validating it.\n *\n * The escape hatch for config-driven values: `assetId(process.env.ASSET!)`\n * throws on a contract id instead of letting it through to a zero-row query.\n */\nexport function assetId(value: string): AssetIdentifier {\n\tassertAssetIdentifier(\"assetIdentifier\", value);\n\treturn value as AssetIdentifier;\n}\n\n/** `true` for a standard (`SP…`/`ST…`) or contract (`SP….name`) principal. */\nexport function isPrincipal(value: string): value is Principal {\n\tconst parts = value.split(\".\");\n\tif (parts.length > 2) return false;\n\tconst [addr, contractName] = parts;\n\tif (!addr || !isValidAddress(addr)) return false;\n\tif (parts.length === 2 && !contractName) return false;\n\treturn true;\n}\n\n/** Subscriptions and Subgraph sources match `*` wildcards in\n * principal/identifier patterns; every\n * other surface treats the value literally. */\nexport function hasWildcard(value: string): boolean {\n\treturn value.includes(\"*\");\n}\n\n/** Throw unless `value` is a principal or a wildcard pattern. The factories\n * call this so a swapped argument (asset id where a sender belongs, typo'd\n * address) fails at construction — not as a silent zero-row query. */\nexport function assertPrincipalish(field: string, value: string): void {\n\tif (hasWildcard(value)) return;\n\tif (!isPrincipal(value)) {\n\t\tthrow new Error(\n\t\t\t`${field} \"${value}\" is not a valid Stacks principal (SP…/ST…, optionally .contract-name).`,\n\t\t);\n\t}\n}\n\n/** Throw unless `value` looks like `SP….contract::asset` (or a wildcard). */\nexport function assertAssetIdentifier(field: string, value: string): void {\n\tif (hasWildcard(value)) return;\n\tconst [contractId, assetName, ...rest] = value.split(\"::\");\n\tif (\n\t\t!contractId ||\n\t\t!assetName ||\n\t\trest.length > 0 ||\n\t\t!contractId.includes(\".\") ||\n\t\t!isPrincipal(contractId)\n\t) {\n\t\tthrow new Error(\n\t\t\t`${field} \"${value}\" is not a valid asset identifier (SP….contract-name::asset-name). Passing a bare contract id here matches zero rows — use contractId for that.`,\n\t\t);\n\t}\n}\n\n/** Throw unless `value` is a contract id `SP….name` (or a wildcard). */\nexport function assertContractId(field: string, value: string): void {\n\tif (hasWildcard(value)) return;\n\tif (value.includes(\"::\")) {\n\t\tthrow new Error(\n\t\t\t`${field} \"${value}\" is an asset identifier, not a contract id — use assetIdentifier for that.`,\n\t\t);\n\t}\n\tif (!value.includes(\".\") || !isPrincipal(value)) {\n\t\tthrow new Error(\n\t\t\t`${field} \"${value}\" is not a valid contract id (SP….contract-name).`,\n\t\t);\n\t}\n}\n",
|
|
7
|
-
"import type { AbiContract } from \"../clarity/abi/contract.ts\";\nimport type { ChainEventFilterType } from \"./event-types.ts\";\nimport type { SubgraphMemberType, SubgraphSourceSpec } from \"./types.ts\";\nimport type {\n\tChainEventFilter,\n\tChainEventFilterSpec,\n\tChainTriggerShape,\n\tContractCallsParamsShape,\n\tIndexEventsParamsShape,\n\tPrintFieldType,\n\tSpecFor,\n\tStreamsParamsShape,\n} from \"./types.ts\";\nimport {\n\tassertAssetIdentifier,\n\tassertContractId,\n\tassertPrincipalish,\n\thasWildcard,\n} from \"./validate.ts\";\n\n// ── Field metadata driving validation and projections ────────────────────\n\nconst PRINCIPAL_FIELDS = new Set([\n\t\"sender\",\n\t\"recipient\",\n\t\"caller\",\n\t\"deployer\",\n\t\"lockedAddress\",\n]);\nconst AMOUNT_FIELDS = new Set([\"minAmount\", \"maxAmount\"]);\n/** Fields with no filtering semantics — safe to drop in a projection. */\nconst DECORATIVE_FIELDS = new Set([\"abi\", \"prints\"]);\n\nfunction specEntries(spec: ChainEventFilterSpec): Array<[string, unknown]> {\n\treturn Object.entries(spec).filter(\n\t\t([key, value]) => key !== \"type\" && value !== undefined,\n\t);\n}\n\nfunction validateSpec(spec: ChainEventFilterSpec): void {\n\tfor (const [key, value] of specEntries(spec)) {\n\t\tif (PRINCIPAL_FIELDS.has(key)) {\n\t\t\tassertPrincipalish(key, value as string);\n\t\t} else if (key === \"assetIdentifier\") {\n\t\t\tassertAssetIdentifier(key, value as string);\n\t\t} else if (key === \"contractId\") {\n\t\t\t// A contract SET validates member-wise — one bad id in a router+pools\n\t\t\t// list must fail as loudly as a bad single id.\n\t\t\tfor (const id of Array.isArray(value) ? value : [value]) {\n\t\t\t\tassertContractId(key, id as string);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** Throw for a field the target surface cannot express — dropping it would\n * silently widen the match, which is the exact bug this module exists to\n * kill. Names the surface that CAN express it. */\nfunction unsupported(surface: string, field: string, hint: string): never {\n\tthrow new Error(\n\t\t`${field} cannot be expressed on ${surface} — ${hint}. Drop the field from the filter or use the surface that supports it.`,\n\t);\n}\n\nfunction assertNoWildcards(surface: string, spec: ChainEventFilterSpec): void {\n\tfor (const [key, value] of specEntries(spec)) {\n\t\t// Arrays too: a wildcard inside a contractId set would otherwise reach\n\t\t// the wire as a literal `IN ('SP….pool-*')` — the silent zero-row match\n\t\t// this module exists to kill.\n\t\tconst candidates = Array.isArray(value) ? value : [value];\n\t\tfor (const candidate of candidates) {\n\t\t\tif (typeof candidate === \"string\" && hasWildcard(candidate)) {\n\t\t\t\tunsupported(\n\t\t\t\t\tsurface,\n\t\t\t\t\t`${key} wildcard \"${candidate}\"`,\n\t\t\t\t\t\"wildcard patterns are Subscriptions/Subgraphs-only\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/** The Index API treats `trait` and `contractId` as mutually exclusive (a\n * trait already resolves to a contract set). Throw here, naming the fix,\n * instead of letting the pair reach the server as a 400. Subgraphs AND them\n * — that surface accepts both. */\nfunction assertNotTraitAndContract(\n\tsurface: string,\n\tspec: ChainEventFilterSpec,\n): void {\n\tconst trait = \"trait\" in spec ? spec.trait : undefined;\n\tconst contract = \"contractId\" in spec ? spec.contractId : undefined;\n\tif (trait !== undefined && contract !== undefined) {\n\t\tunsupported(\n\t\t\tsurface,\n\t\t\t\"trait with contractId\",\n\t\t\t\"the Index treats them as mutually exclusive — drop one, or use a subgraph source, which ANDs the pair\",\n\t\t);\n\t}\n}\n\n// ── Projections ──────────────────────────────────────────────────────────\n\nfunction toChainTrigger(spec: ChainEventFilterSpec): ChainTriggerShape {\n\tconst out: Record<string, string | number> = {};\n\tfor (const [key, value] of specEntries(spec)) {\n\t\tif (DECORATIVE_FIELDS.has(key)) continue;\n\t\tif (Array.isArray(value)) {\n\t\t\t// One trigger, one contract: silently taking the first would watch\n\t\t\t// a fraction of what the filter says. Create one subscription per\n\t\t\t// contract instead.\n\t\t\tunsupported(\n\t\t\t\t\"Subscriptions\",\n\t\t\t\t`${key} set`,\n\t\t\t\t\"a chain trigger targets ONE contract — create one subscription per contract, or use Index/Subgraphs which accept the set\",\n\t\t\t);\n\t\t}\n\t\t// The one sanctioned bigint→string boundary.\n\t\tout[key] =\n\t\t\ttypeof value === \"bigint\" ? value.toString() : (value as string | number);\n\t}\n\treturn { type: spec.type, ...out };\n}\n\nfunction toIndexParams(\n\tspec: ChainEventFilterSpec,\n\textra: Record<string, unknown> = {},\n): IndexEventsParamsShape {\n\tassertNoWildcards(\"Index events\", spec);\n\tassertNotTraitAndContract(\"Index events\", spec);\n\tconst out: Record<string, unknown> = {\n\t\teventType: spec.type === \"print_event\" ? \"print\" : spec.type,\n\t};\n\tfor (const [key, value] of specEntries(spec)) {\n\t\tif (DECORATIVE_FIELDS.has(key)) continue;\n\t\tif (AMOUNT_FIELDS.has(key)) {\n\t\t\tunsupported(\n\t\t\t\t\"Index events\",\n\t\t\t\tkey,\n\t\t\t\t\"amount predicates are Subscriptions/Subgraphs-only; filter client-side on the decoded rows\",\n\t\t\t);\n\t\t}\n\t\tif (key === \"topic\") {\n\t\t\tunsupported(\n\t\t\t\t\"Index events\",\n\t\t\t\t\"topic\",\n\t\t\t\t\"per-topic reads are Subgraphs/Subscriptions-only (or read the contract's print feed and switch on topic)\",\n\t\t\t);\n\t\t}\n\t\tif (key === \"lockedAddress\") {\n\t\t\t// Index normalizes stx_lock's locked_address INTO the `sender` column\n\t\t\t// (the row's sender IS the locked address) — a rename, not a gap.\n\t\t\tout.sender = value;\n\t\t\tcontinue;\n\t\t}\n\t\tif (key === \"caller\") {\n\t\t\tunsupported(\n\t\t\t\t\"Index events\",\n\t\t\t\t\"caller\",\n\t\t\t\t\"contract-call fields live on index.contractCalls\",\n\t\t\t);\n\t\t}\n\t\tout[key] = value;\n\t}\n\treturn { ...out, ...extra } as IndexEventsParamsShape;\n}\n\nfunction toStreamsParams(\n\tspec: ChainEventFilterSpec,\n\textra: Record<string, unknown> = {},\n): StreamsParamsShape {\n\tassertNoWildcards(\"Streams\", spec);\n\tconst out: Record<string, unknown> = {\n\t\ttypes: [spec.type === \"print_event\" ? \"print\" : spec.type],\n\t};\n\tfor (const [key, value] of specEntries(spec)) {\n\t\tif (DECORATIVE_FIELDS.has(key)) continue;\n\t\tif (AMOUNT_FIELDS.has(key)) {\n\t\t\tunsupported(\n\t\t\t\t\"Streams\",\n\t\t\t\tkey,\n\t\t\t\t\"amount predicates are Subscriptions/Subgraphs-only\",\n\t\t\t);\n\t\t}\n\t\tif (key === \"trait\") {\n\t\t\tunsupported(\n\t\t\t\t\"Streams\",\n\t\t\t\t\"trait\",\n\t\t\t\t\"Streams has no trait resolution — Index and Subgraphs do\",\n\t\t\t);\n\t\t}\n\t\tif (key === \"topic\") {\n\t\t\tunsupported(\n\t\t\t\t\"Streams\",\n\t\t\t\t\"topic\",\n\t\t\t\t\"per-topic filtering is Subgraphs/Subscriptions-only\",\n\t\t\t);\n\t\t}\n\t\tif (key === \"lockedAddress\") {\n\t\t\tunsupported(\n\t\t\t\t\"Streams\",\n\t\t\t\t\"lockedAddress\",\n\t\t\t\t\"stx_lock address filtering is Subscriptions/Subgraphs-only\",\n\t\t\t);\n\t\t}\n\t\tout[key] = value;\n\t}\n\treturn { ...out, ...extra } as StreamsParamsShape;\n}\n\nfunction toContractCallsParams(\n\tspec: ChainEventFilterSpec,\n\textra: Record<string, unknown> = {},\n): ContractCallsParamsShape {\n\tassertNoWildcards(\"Index contract-calls\", spec);\n\tassertNotTraitAndContract(\"Index contract-calls\", spec);\n\tconst out: Record<string, unknown> = {};\n\tfor (const [key, value] of specEntries(spec)) {\n\t\tif (DECORATIVE_FIELDS.has(key)) continue;\n\t\tif (key === \"caller\") {\n\t\t\t// The endpoint filters by tx sender, which IS the caller — a rename,\n\t\t\t// not a gap.\n\t\t\tout.sender = value;\n\t\t\tcontinue;\n\t\t}\n\t\tout[key] = value;\n\t}\n\treturn { ...out, ...extra } as ContractCallsParamsShape;\n}\n\nfunction toSubgraphSource(spec: ChainEventFilterSpec): ChainEventFilterSpec {\n\t// The spec IS the subgraph source shape (camelCase, bigint amounts,\n\t// literal prints/abi preserved). Strip the projection methods by copying\n\t// data fields only.\n\treturn Object.fromEntries([\n\t\t[\"type\", spec.type],\n\t\t...specEntries(spec),\n\t]) as unknown as ChainEventFilterSpec;\n}\n\n// ── Factory ──────────────────────────────────────────────────────────────\n\nconst DECODED_MEMBERS = new Set<ChainEventFilterType>([\n\t\"stx_transfer\",\n\t\"stx_mint\",\n\t\"stx_burn\",\n\t\"stx_lock\",\n\t\"ft_transfer\",\n\t\"ft_mint\",\n\t\"ft_burn\",\n\t\"nft_transfer\",\n\t\"nft_mint\",\n\t\"nft_burn\",\n\t\"print_event\",\n]);\n\n/** Build a canonical filter: validated spec + the projections its member\n * supports (methods are attached per member at runtime, matching the\n * type-level gating exactly). `const F` preserves field literals — a\n * `prints`/`abi` declaration keeps its exact type through\n * `toSubgraphSource()`, which is what feeds `defineSubgraph` narrowing. */\nexport function makeChainEventFilter<\n\tT extends ChainEventFilterType,\n\tconst F extends Omit<SpecFor<T>, \"type\">,\n>(type: T, fields: F): ChainEventFilter<T, { type: T } & F> {\n\tconst spec = { type, ...fields } as unknown as SpecFor<T>;\n\tvalidateSpec(spec);\n\n\tconst filter = { ...spec } as unknown as Record<string, unknown>;\n\tfilter.toChainTrigger = () => toChainTrigger(spec);\n\tif (DECODED_MEMBERS.has(type)) {\n\t\tfilter.toIndexParams = (extra?: Record<string, unknown>) =>\n\t\t\ttoIndexParams(spec, extra);\n\t\tfilter.toStreamsParams = (extra?: Record<string, unknown>) =>\n\t\t\ttoStreamsParams(spec, extra);\n\t}\n\tif (type === \"contract_call\") {\n\t\tfilter.toContractCallsParams = (extra?: Record<string, unknown>) =>\n\t\t\ttoContractCallsParams(spec, extra);\n\t}\n\tif (!type.startsWith(\"sbtc_\")) {\n\t\tfilter.toSubgraphSource = () => toSubgraphSource(spec);\n\t}\n\treturn filter as unknown as ChainEventFilter<T, { type: T } & F>;\n}\n\n/**\n * Rehydrate a canonical filter from a subgraph-source-shaped object (the\n * inverse of `toSubgraphSource`). Powers migration and the round-trip\n * property gate: `toSubgraphSource(fromSubgraphSource(f))` must deep-equal\n * `f` for every production subgraph source.\n */\nexport function fromSubgraphSource(\n\tsource: SubgraphSourceSpec,\n): ChainEventFilter<SubgraphMemberType> {\n\tconst { type, ...fields } = source;\n\treturn makeChainEventFilter(\n\t\ttype,\n\t\tfields as Omit<SpecFor<typeof type>, \"type\">,\n\t) as unknown as ChainEventFilter<SubgraphMemberType>;\n}\n\ntype Fields<T extends ChainEventFilterType> = Omit<SpecFor<T>, \"type\">;\n\n/** The `on.*` namespace, annotated explicitly — bunup's dts emitter needs an\n * annotation on exported values (an inferred object of generic factories\n * collapses to `{}` in the emitted declarations). */\nexport interface OnNamespace {\n\tstxTransfer(\n\t\tfields?: Fields<\"stx_transfer\">,\n\t): ChainEventFilter<\"stx_transfer\">;\n\tstxMint(fields?: Fields<\"stx_mint\">): ChainEventFilter<\"stx_mint\">;\n\tstxBurn(fields?: Fields<\"stx_burn\">): ChainEventFilter<\"stx_burn\">;\n\tstxLock(fields?: Fields<\"stx_lock\">): ChainEventFilter<\"stx_lock\">;\n\tftTransfer(fields?: Fields<\"ft_transfer\">): ChainEventFilter<\"ft_transfer\">;\n\tftMint(fields?: Fields<\"ft_mint\">): ChainEventFilter<\"ft_mint\">;\n\tftBurn(fields?: Fields<\"ft_burn\">): ChainEventFilter<\"ft_burn\">;\n\tnftTransfer(\n\t\tfields?: Fields<\"nft_transfer\">,\n\t): ChainEventFilter<\"nft_transfer\">;\n\tnftMint(fields?: Fields<\"nft_mint\">): ChainEventFilter<\"nft_mint\">;\n\tnftBurn(fields?: Fields<\"nft_burn\">): ChainEventFilter<\"nft_burn\">;\n\t/** `abi` literals are preserved (`const A`) so `toSubgraphSource()` keeps\n\t * typing `event.input` inside `defineSubgraph`. */\n\tcontractCall<const A extends AbiContract | undefined = undefined>(\n\t\tfields?: Omit<SpecFor<\"contract_call\">, \"type\" | \"abi\"> & { abi?: A },\n\t): ChainEventFilter<\n\t\t\"contract_call\",\n\t\t{ type: \"contract_call\" } & Omit<\n\t\t\tSpecFor<\"contract_call\">,\n\t\t\t\"type\" | \"abi\"\n\t\t> & {\n\t\t\t\tabi?: A;\n\t\t\t}\n\t>;\n\tcontractDeploy(\n\t\tfields?: Fields<\"contract_deploy\">,\n\t): ChainEventFilter<\"contract_deploy\">;\n\t/** Canonical member is `print_event` (as Subgraphs and Subscriptions spell\n\t * it); `toIndexParams`/`toStreamsParams` project to `print`. `prints`\n\t * literals are preserved (`const P`) for per-topic `event.data` narrowing. */\n\tprint<\n\t\tconst P extends\n\t\t\t| Record<string, Record<string, PrintFieldType>>\n\t\t\t| undefined = undefined,\n\t>(\n\t\tfields?: Omit<SpecFor<\"print_event\">, \"type\" | \"prints\"> & { prints?: P },\n\t): ChainEventFilter<\n\t\t\"print_event\",\n\t\t{ type: \"print_event\" } & Omit<\n\t\t\tSpecFor<\"print_event\">,\n\t\t\t\"type\" | \"prints\"\n\t\t> & {\n\t\t\t\tprints?: P;\n\t\t\t}\n\t>;\n\tsbtcDeposit(\n\t\tfields?: Fields<\"sbtc_deposit\">,\n\t): ChainEventFilter<\"sbtc_deposit\">;\n\tsbtcWithdrawalCreate(\n\t\tfields?: Fields<\"sbtc_withdrawal_create\">,\n\t): ChainEventFilter<\"sbtc_withdrawal_create\">;\n\tsbtcWithdrawalAccept(\n\t\tfields?: Fields<\"sbtc_withdrawal_accept\">,\n\t): ChainEventFilter<\"sbtc_withdrawal_accept\">;\n\tsbtcWithdrawalReject(\n\t\tfields?: Fields<\"sbtc_withdrawal_reject\">,\n\t): ChainEventFilter<\"sbtc_withdrawal_reject\">;\n\tsbtcWithdrawalSweptConfirmed(\n\t\tfields?: Fields<\"sbtc_withdrawal_swept_confirmed\">,\n\t): ChainEventFilter<\"sbtc_withdrawal_swept_confirmed\">;\n}\n\n/**\n * `on.*` — one filter vocabulary for every surface.\n *\n * ```ts\n * import { on } from \"@secondlayer/stacks/filters\";\n *\n * const usdc = on.ftTransfer({ assetIdentifier: USDC, minAmount: 1_000_000n });\n *\n * sl.index.events.list(usdc.toIndexParams({ limit: 100 })); // pull\n * sl.streams.events.consume({ ...usdc.toStreamsParams(), onBatch });\n * sl.subscriptions.create({ name, url, triggers: [usdc.toChainTrigger()] });\n * defineSubgraph({ sources: { usdc: usdc.toSubgraphSource() }, schema, handlers });\n * ```\n *\n * A surface a member can't reach is a missing method (compile error), and a\n * field a surface can't express throws at projection time — never a silent\n * zero-row or over-wide match.\n */\nexport const on: OnNamespace = {\n\tstxTransfer: (fields: Fields<\"stx_transfer\"> = {}) =>\n\t\tmakeChainEventFilter(\"stx_transfer\", fields),\n\tstxMint: (fields: Fields<\"stx_mint\"> = {}) =>\n\t\tmakeChainEventFilter(\"stx_mint\", fields),\n\tstxBurn: (fields: Fields<\"stx_burn\"> = {}) =>\n\t\tmakeChainEventFilter(\"stx_burn\", fields),\n\tstxLock: (fields: Fields<\"stx_lock\"> = {}) =>\n\t\tmakeChainEventFilter(\"stx_lock\", fields),\n\tftTransfer: (fields: Fields<\"ft_transfer\"> = {}) =>\n\t\tmakeChainEventFilter(\"ft_transfer\", fields),\n\tftMint: (fields: Fields<\"ft_mint\"> = {}) =>\n\t\tmakeChainEventFilter(\"ft_mint\", fields),\n\tftBurn: (fields: Fields<\"ft_burn\"> = {}) =>\n\t\tmakeChainEventFilter(\"ft_burn\", fields),\n\tnftTransfer: (fields: Fields<\"nft_transfer\"> = {}) =>\n\t\tmakeChainEventFilter(\"nft_transfer\", fields),\n\tnftMint: (fields: Fields<\"nft_mint\"> = {}) =>\n\t\tmakeChainEventFilter(\"nft_mint\", fields),\n\tnftBurn: (fields: Fields<\"nft_burn\"> = {}) =>\n\t\tmakeChainEventFilter(\"nft_burn\", fields),\n\tcontractCall: <const A extends AbiContract | undefined = undefined>(\n\t\tfields: Omit<SpecFor<\"contract_call\">, \"type\" | \"abi\"> & { abi?: A } = {},\n\t) => makeChainEventFilter(\"contract_call\", fields),\n\tcontractDeploy: (fields: Fields<\"contract_deploy\"> = {}) =>\n\t\tmakeChainEventFilter(\"contract_deploy\", fields),\n\t/** Canonical member is `print_event` (as Subgraphs and Subscriptions spell\n\t * it); `toIndexParams`/`toStreamsParams` project to `print`. */\n\tprint: <\n\t\tconst P extends\n\t\t\t| Record<string, Record<string, PrintFieldType>>\n\t\t\t| undefined = undefined,\n\t>(\n\t\tfields: Omit<SpecFor<\"print_event\">, \"type\" | \"prints\"> & {\n\t\t\tprints?: P;\n\t\t} = {},\n\t) => makeChainEventFilter(\"print_event\", fields),\n\tsbtcDeposit: (fields: Fields<\"sbtc_deposit\"> = {}) =>\n\t\tmakeChainEventFilter(\"sbtc_deposit\", fields),\n\tsbtcWithdrawalCreate: (fields: Fields<\"sbtc_withdrawal_create\"> = {}) =>\n\t\tmakeChainEventFilter(\"sbtc_withdrawal_create\", fields),\n\tsbtcWithdrawalAccept: (fields: Fields<\"sbtc_withdrawal_accept\"> = {}) =>\n\t\tmakeChainEventFilter(\"sbtc_withdrawal_accept\", fields),\n\tsbtcWithdrawalReject: (fields: Fields<\"sbtc_withdrawal_reject\"> = {}) =>\n\t\tmakeChainEventFilter(\"sbtc_withdrawal_reject\", fields),\n\tsbtcWithdrawalSweptConfirmed: (\n\t\tfields: Fields<\"sbtc_withdrawal_swept_confirmed\"> = {},\n\t) => makeChainEventFilter(\"sbtc_withdrawal_swept_confirmed\", fields),\n};\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": ";;;;;AAKO,IAAM,sBAAsB;AAAA,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B,MAAM;AAAA,EACtD,8BAA8B,CAC7B,SAAoD,CAAC,MACjD,qBAAqB,mCAAmC,MAAM;AACpE;",
|
|
10
|
-
"debugId": "EBF984B8438B171C64756E2164756E21",
|
|
11
|
-
"names": []
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/clarity/abi/types.ts", "../src/clarity/abi/guards.ts", "../src/clarity/abi/utils.ts", "../src/clarity/bridge.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { MAX_I128, MAX_U128, MIN_I128 } from \"../../utils/constants.ts\";\n\nexport { MAX_U128, MAX_I128, MIN_I128 };\n\nexport const CONTRACT_NAME_REGEX: RegExp = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;\n\n// Primitive types\n\nexport type AbiUInt128 = \"uint128\";\nexport type AbiInt128 = \"int128\";\nexport type AbiBool = \"bool\";\nexport type AbiPrincipal = \"principal\";\nexport type AbiTraitReference = \"trait_reference\";\nexport type AbiNone = \"none\";\n\nexport type AbiStringAscii<L extends number = number> = {\n\t\"string-ascii\": { length: L };\n};\n\nexport type AbiStringUtf8<L extends number = number> = {\n\t\"string-utf8\": { length: L };\n};\n\nexport type AbiBuffer<L extends number = number> = {\n\tbuff: { length: L };\n};\n\nexport type AbiPrimitiveType =\n\t| AbiUInt128\n\t| AbiInt128\n\t| AbiBool\n\t| AbiPrincipal\n\t| AbiTraitReference\n\t| AbiNone\n\t| AbiStringAscii\n\t| AbiStringUtf8\n\t| AbiBuffer;\n\n// Composite types (interfaces for recursion)\n\nexport interface AbiListType {\n\tlist: { type: AbiType; length: number };\n}\n\nexport interface AbiTupleType {\n\ttuple: ReadonlyArray<{ name: string; type: AbiType }>;\n}\n\nexport interface AbiOptionalType {\n\toptional: AbiType;\n}\n\nexport interface AbiResponseType {\n\tresponse: { ok: AbiType; error: AbiType };\n}\n\n/** Discriminated union of all Clarity value types (primitives, buffers, lists, tuples, optionals, responses). */\nexport type AbiType =\n\t| AbiPrimitiveType\n\t| AbiListType\n\t| AbiTupleType\n\t| AbiOptionalType\n\t| AbiResponseType;\n\n// Generic versions for better type inference\n\nexport type AbiList<T extends AbiType = AbiType, L extends number = number> = {\n\tlist: { type: T; length: L };\n};\n\nexport type AbiTuple<T extends ReadonlyArray<{ name: string; type: AbiType }>> =\n\t{\n\t\ttuple: T;\n\t};\n\nexport type AbiOptional<T extends AbiType = AbiType> = {\n\toptional: T;\n};\n\nexport type AbiResponse<\n\tO extends AbiType = AbiType,\n\tE extends AbiType = AbiType,\n> = {\n\tresponse: { ok: O; error: E };\n};\n",
|
|
6
|
-
"import { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { ResponseErr, ResponseOk } from \"./mappings.ts\";\nimport { CONTRACT_NAME_REGEX, MAX_I128, MAX_U128, MIN_I128 } from \"./types.ts\";\nimport type {\n\tAbiBuffer,\n\tAbiListType,\n\tAbiOptionalType,\n\tAbiResponseType,\n\tAbiStringAscii,\n\tAbiStringUtf8,\n\tAbiTraitReference,\n\tAbiTupleType,\n\tAbiType,\n} from \"./types.ts\";\n\n// Value guards\n\nexport function isUint128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= 0n && value <= MAX_U128;\n}\n\nexport function isInt128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= MIN_I128 && value <= MAX_I128;\n}\n\nexport function isBool(value: unknown): value is boolean {\n\treturn typeof value === \"boolean\";\n}\n\nexport function isPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parts = value.split(\".\");\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst address = parts[0]!;\n\tconst contractName = parts[1];\n\tif (!validateStacksAddress(address)) return false;\n\tif (contractName !== undefined) {\n\t\treturn CONTRACT_NAME_REGEX.test(contractName);\n\t}\n\treturn true;\n}\n\nexport function isStandardPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (value.includes(\".\")) return false;\n\treturn validateStacksAddress(value);\n}\n\nexport function isContractPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (!value.includes(\".\")) return false;\n\tconst parts = value.split(\".\");\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst address = parts[0]!;\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst contractName = parts[1]!;\n\tif (!validateStacksAddress(address)) return false;\n\treturn CONTRACT_NAME_REGEX.test(contractName);\n}\n\nexport function isTraitReference(value: unknown): value is string {\n\treturn isContractPrincipal(value);\n}\n\nexport function isString(value: unknown): value is string {\n\treturn typeof value === \"string\";\n}\n\nexport function isUint8Array(value: unknown): value is Uint8Array {\n\treturn value instanceof Uint8Array;\n}\n\nexport function isArray<T>(\n\tvalue: unknown,\n\titemGuard: (item: unknown) => item is T,\n): value is T[] {\n\treturn Array.isArray(value) && value.every(itemGuard);\n}\n\nexport function isOptional<T>(\n\tvalue: unknown,\n\tguard: (val: unknown) => val is T,\n): value is T | null {\n\treturn value === null || guard(value);\n}\n\nexport function isOkResponse<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tresponse: { ok: T } | { err: any },\n): response is ResponseOk<T> {\n\treturn \"ok\" in response && !(\"err\" in response);\n}\n\nexport function isErrResponse<E>(\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tresponse: { ok: any } | { err: E },\n): response is ResponseErr<E> {\n\treturn \"err\" in response && !(\"ok\" in response);\n}\n\nexport function isResponse<T, E>(\n\tvalue: unknown,\n\tokGuard: (val: unknown) => val is T,\n\terrGuard: (val: unknown) => val is E,\n): value is ResponseOk<T> | ResponseErr<E> {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst obj = value as Record<string, unknown>;\n\tif (\"ok\" in value && !(\"err\" in value)) return okGuard(obj.ok);\n\tif (\"err\" in value && !(\"ok\" in value)) return errGuard(obj.err);\n\treturn false;\n}\n\n// ABI type definition guards\n\nexport function isAbiList(type: AbiType): type is AbiListType {\n\treturn typeof type === \"object\" && type !== null && \"list\" in type;\n}\n\nexport function isAbiTuple(type: AbiType): type is AbiTupleType {\n\treturn typeof type === \"object\" && type !== null && \"tuple\" in type;\n}\n\nexport function isAbiOptional(type: AbiType): type is AbiOptionalType {\n\treturn typeof type === \"object\" && type !== null && \"optional\" in type;\n}\n\nexport function isAbiResponse(type: AbiType): type is AbiResponseType {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nexport function isAbiBuffer(type: AbiType): type is AbiBuffer {\n\treturn typeof type === \"object\" && type !== null && \"buff\" in type;\n}\n\nexport function isAbiStringAscii(type: AbiType): type is AbiStringAscii {\n\treturn typeof type === \"object\" && type !== null && \"string-ascii\" in type;\n}\n\nexport function isAbiStringUtf8(type: AbiType): type is AbiStringUtf8 {\n\treturn typeof type === \"object\" && type !== null && \"string-utf8\" in type;\n}\n\nexport function isAbiTraitReference(type: AbiType): type is AbiTraitReference {\n\treturn type === \"trait_reference\";\n}\n",
|
|
7
|
-
"type CamelCaseInner<S extends string> =\n\tS extends `${infer P1}-${infer P2}${infer P3}`\n\t\t? `${P1}${Capitalize<CamelCaseInner<`${P2}${P3}`>>}`\n\t\t: S;\n\nexport type ToCamelCase<S extends string> =\n\tCamelCaseInner<S> extends `${number}${string}`\n\t\t? `_${CamelCaseInner<S>}`\n\t\t: CamelCaseInner<S>;\n\nexport function toCamelCase(str: string): string {\n\treturn str\n\t\t.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())\n\t\t.replace(/-([A-Z])/g, (_, letter) => letter)\n\t\t.replace(/-(\\d)/g, (_, digit) => digit)\n\t\t.replace(/-/g, \"\")\n\t\t.replace(/^\\d/, \"_$&\");\n}\n",
|
|
8
|
-
"import {\n\tisAbiBuffer,\n\tisAbiList,\n\tisAbiOptional,\n\tisAbiResponse,\n\tisAbiStringAscii,\n\tisAbiStringUtf8,\n\tisAbiTuple,\n} from \"./abi/guards.ts\";\nimport type { AbiToTS } from \"./abi/mappings.ts\";\nimport type { AbiType } from \"./abi/types.ts\";\nimport { toCamelCase } from \"./abi/utils.ts\";\nimport type { ClarityValue } from \"./types.ts\";\nimport {\n\tboolCV,\n\tbufferCV,\n\tintCV,\n\tlistCV,\n\tnoneCV,\n\tresponseErrorCV,\n\tresponseOkCV,\n\tsomeCV,\n\tstringAsciiCV,\n\tstringUtf8CV,\n\ttupleCV,\n\tuintCV,\n} from \"./values.ts\";\nimport { Cl } from \"./values.ts\";\n\n/** CV type tags — mirrors the discriminants of `ClarityValue`. */\nconst CV_TYPE_TAGS = new Set([\n\t\"int\",\n\t\"uint\",\n\t\"true\",\n\t\"false\",\n\t\"address\",\n\t\"contract\",\n\t\"ascii\",\n\t\"utf8\",\n\t\"buffer\",\n\t\"list\",\n\t\"tuple\",\n\t\"none\",\n\t\"some\",\n\t\"ok\",\n\t\"err\",\n]);\n\n/**\n * Duck-type check: is `value` already a built ClarityValue? Tag-only CVs\n * (`true`/`false`/`none`) have no payload; every other tag carries `value`.\n */\nexport function isClarityValue(value: unknown): value is ClarityValue {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst type = (value as { type?: unknown }).type;\n\tif (typeof type !== \"string\" || !CV_TYPE_TAGS.has(type)) return false;\n\tif (type === \"true\" || type === \"false\" || type === \"none\") return true;\n\treturn \"value\" in value;\n}\n\nconst HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;\n\n/**\n * Coerce a flexible buffer input to a BufferCV. Accepts `Uint8Array`, a\n * pre-built `BufferCV`, a tagged `{ type: 'ascii' | 'utf8' | 'hex', value }`\n * object, or a bare string (even-length hex — optionally 0x-prefixed — is\n * decoded as hex; anything else is UTF-8 encoded).\n */\nfunction coerceBuffer(value: unknown): ClarityValue {\n\tif (value instanceof Uint8Array) return bufferCV(value);\n\tif (typeof value === \"object\" && value !== null && \"type\" in value) {\n\t\tconst tagged = value as { type: string; value?: unknown };\n\t\tif (tagged.type === \"buffer\" && isClarityValue(value)) return value;\n\t\tif (typeof tagged.value === \"string\") {\n\t\t\tif (tagged.type === \"ascii\") return Cl.bufferFromAscii(tagged.value);\n\t\t\tif (tagged.type === \"utf8\") return Cl.bufferFromUtf8(tagged.value);\n\t\t\tif (tagged.type === \"hex\") return Cl.bufferFromHex(tagged.value);\n\t\t}\n\t\tthrow new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);\n\t}\n\tif (typeof value === \"string\") {\n\t\tconst hex = value.startsWith(\"0x\") ? value.slice(2) : value;\n\t\tif (HEX_PAIRS_REGEX.test(hex)) return Cl.bufferFromHex(hex);\n\t\treturn Cl.bufferFromUtf8(value);\n\t}\n\tthrow new Error(\n\t\t\"buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV\",\n\t);\n}\n\n/**\n * Convert a JS value to a ClarityValue using ABI type information.\n *\n * Pre-built ClarityValues pass through unchanged (escape hatch for callers\n * that already hold a CV). Buffer args additionally accept hex strings and\n * tagged `{ type, value }` objects — matching the generated-client input\n * contract.\n */\nexport function jsToClarityValue(\n\tabiType: AbiType,\n\tvalue: unknown,\n): ClarityValue {\n\t// Buffers first: the tagged `{ type: 'ascii', value }` input form is\n\t// shape-identical to StringAsciiCV, so buffer coercion wins for buff args.\n\tif (isAbiBuffer(abiType)) return coerceBuffer(value);\n\n\tif (isClarityValue(value)) return value;\n\n\tif (abiType === \"uint128\") return uintCV(value as bigint | number);\n\tif (abiType === \"int128\") return intCV(value as bigint | number);\n\tif (abiType === \"bool\") return boolCV(value as boolean);\n\tif (abiType === \"principal\" || abiType === \"trait_reference\")\n\t\treturn Cl.principal(value as string);\n\n\tif (isAbiStringAscii(abiType)) return stringAsciiCV(value as string);\n\tif (isAbiStringUtf8(abiType)) return stringUtf8CV(value as string);\n\n\tif (isAbiList(abiType)) {\n\t\tconst arr = value as unknown[];\n\t\treturn listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tconst data: Record<string, ClarityValue> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tconst hasOriginal = field.name in obj;\n\t\t\tconst hasCamel = camelKey in obj;\n\t\t\tconst fieldValue = hasOriginal\n\t\t\t\t? obj[field.name]\n\t\t\t\t: hasCamel\n\t\t\t\t\t? obj[camelKey]\n\t\t\t\t\t: undefined;\n\t\t\tif (fieldValue === undefined && !isAbiOptional(field.type)) {\n\t\t\t\tthrow new Error(`Missing tuple field: ${field.name}`);\n\t\t\t}\n\t\t\tdata[field.name] = jsToClarityValue(field.type, fieldValue);\n\t\t}\n\t\treturn tupleCV(data);\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (value === null || value === undefined) return noneCV();\n\t\treturn someCV(jsToClarityValue(abiType.optional, value));\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tif (\"ok\" in obj && !(\"err\" in obj))\n\t\t\treturn responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));\n\t\tif (\"err\" in obj && !(\"ok\" in obj))\n\t\t\treturn responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));\n\t\tthrow new Error(\"Response must have exactly 'ok' or 'err' property\");\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n\n/**\n * Convert a ClarityValue back to a typed JS value using ABI type information.\n */\nexport function clarityValueToJS<T extends AbiType>(\n\tabiType: T,\n\tcv: ClarityValue,\n): AbiToTS<T> {\n\treturn clarityValueToJSInner(abiType, cv) as AbiToTS<T>;\n}\n\n/** Non-generic version for internal use — avoids deep type instantiation. */\nexport function clarityValueToJSUntyped(\n\tabiType: AbiType,\n\tcv: ClarityValue,\n): unknown {\n\treturn clarityValueToJSInner(abiType, cv);\n}\n\nfunction clarityValueToJSInner(abiType: AbiType, cv: ClarityValue): unknown {\n\tif (abiType === \"uint128\" || abiType === \"int128\") {\n\t\tif (cv.type !== \"int\" && cv.type !== \"uint\")\n\t\t\tthrow new Error(`Expected int/uint CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (abiType === \"bool\") {\n\t\tif (cv.type === \"true\") return true;\n\t\tif (cv.type === \"false\") return false;\n\t\tthrow new Error(`Expected bool CV, got ${cv.type}`);\n\t}\n\n\tif (abiType === \"principal\" || abiType === \"trait_reference\") {\n\t\tif (cv.type !== \"address\" && cv.type !== \"contract\")\n\t\t\tthrow new Error(`Expected principal CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {\n\t\tif (cv.type !== \"ascii\" && cv.type !== \"utf8\")\n\t\t\tthrow new Error(`Expected string CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiBuffer(abiType)) {\n\t\tif (cv.type !== \"buffer\")\n\t\t\tthrow new Error(`Expected buffer CV, got ${cv.type}`);\n\t\t// BufferCV stores hex string; convert back to Uint8Array\n\t\tconst hex = cv.value;\n\t\tconst bytes = new Uint8Array(hex.length / 2);\n\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\tbytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tif (isAbiList(abiType)) {\n\t\tif (cv.type !== \"list\") throw new Error(`Expected list CV, got ${cv.type}`);\n\t\treturn cv.value.map((item) =>\n\t\t\tclarityValueToJSInner(abiType.list.type, item),\n\t\t);\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tif (cv.type !== \"tuple\")\n\t\t\tthrow new Error(`Expected tuple CV, got ${cv.type}`);\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst fieldCV = cv.value[field.name];\n\t\t\tif (!fieldCV) throw new Error(`Missing tuple field in CV: ${field.name}`);\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tresult[camelKey] = clarityValueToJSInner(field.type, fieldCV);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (cv.type === \"none\") return null;\n\t\tif (cv.type === \"some\")\n\t\t\treturn clarityValueToJSInner(abiType.optional, cv.value);\n\t\tthrow new Error(`Expected optional CV, got ${cv.type}`);\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tif (cv.type === \"ok\")\n\t\t\treturn { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };\n\t\tif (cv.type === \"err\")\n\t\t\treturn { err: clarityValueToJSInner(abiType.response.error, cv.value) };\n\t\tthrow new Error(`Expected response CV, got ${cv.type}`);\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIO,IAAM,sBAA8B;;;ACapC,SAAS,SAAS,CAAC,OAAiC;AAAA,EAC1D,OAAO,OAAO,UAAU,YAAY,SAAS,MAAM,SAAS;AAAA;AAGtD,SAAS,QAAQ,CAAC,OAAiC;AAAA,EACzD,OAAO,OAAO,UAAU,YAAY,SAAS,YAAY,SAAS;AAAA;AAG5D,SAAS,MAAM,CAAC,OAAkC;AAAA,EACxD,OAAO,OAAO,UAAU;AAAA;AAGlB,SAAS,WAAW,CAAC,OAAiC;AAAA,EAC5D,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,MAAM,QAAQ,MAAM,MAAM,GAAG;AAAA,EAE7B,MAAM,UAAU,MAAM;AAAA,EACtB,MAAM,eAAe,MAAM;AAAA,EAC3B,IAAI,CAAC,sBAAsB,OAAO;AAAA,IAAG,OAAO;AAAA,EAC5C,IAAI,iBAAiB,WAAW;AAAA,IAC/B,O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AA,MAClC,MAAM,UAAU,GAAG,MAAM,MAAM;AAAA,MAC/B,IAAI,CAAC;AAAA,QAAS,MAAM,IAAI,MAAM,8BAA8B,MAAM,MAAM;AAAA,MACxE,MAAM,WAAW,YAAY,MAAM,IAAI;AAAA,MACvC,OAAO,YAAY,sBAAsB,MAAM,MAAM,OAAO;AAAA,IAC7D;AAAA,IACA,OAAO;AAAA,EACR;AAAA,EAEA,IAAI,cAAc,OAAO,GAAG;AAAA,IAC3B,IAAI,GAAG,SAAS;AAAA,MAAQ,OAAO;AAAA,IAC/B,IAAI,GAAG,SAAS;AAAA,MACf,OAAO,sBAAsB,QAAQ,UAAU,GAAG,KAAK;AAAA,IACxD,MAAM,IAAI,MAAM,6BAA6B,GAAG,MAAM;AAAA,EACvD;AAAA,EAEA,IAAI,cAAc,OAAO,GAAG;AAAA,IAC3B,IAAI,GAAG,SAAS;AAAA,MACf,OAAO,EAAE,IAAI,sBAAsB,QAAQ,SAAS,IAAI,GAAG,KAAK,EAAE;AAAA,IACnE,IAAI,GAAG,SAAS;AAAA,MACf,OAAO,EAAE,KAAK,sBAAsB,QAAQ,SAAS,OAAO,GAAG,KAAK,EAAE;AAAA,IACvE,MAAM,IAAI,MAAM,6BAA6B,GAAG,MAAM;AAAA,EACvD;AAAA,EAEA,MAAM,IAAI,MAAM,qBAAqB,KAAK,UAAU,OAAO,GAAG;AAAA;",
|
|
11
|
-
"debugId": "61393ECAC463249664756E2164756E21",
|
|
12
|
-
"names": []
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/clarity/abi/types.ts", "../src/clarity/abi/guards.ts", "../src/clarity/abi/utils.ts", "../src/clarity/bridge.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { MAX_I128, MAX_U128, MIN_I128 } from \"../../utils/constants.ts\";\n\nexport { MAX_U128, MAX_I128, MIN_I128 };\n\nexport const CONTRACT_NAME_REGEX: RegExp = /^[a-zA-Z][a-zA-Z0-9\\-]{0,127}$/;\n\n// Primitive types\n\nexport type AbiUInt128 = \"uint128\";\nexport type AbiInt128 = \"int128\";\nexport type AbiBool = \"bool\";\nexport type AbiPrincipal = \"principal\";\nexport type AbiTraitReference = \"trait_reference\";\nexport type AbiNone = \"none\";\n\nexport type AbiStringAscii<L extends number = number> = {\n\t\"string-ascii\": { length: L };\n};\n\nexport type AbiStringUtf8<L extends number = number> = {\n\t\"string-utf8\": { length: L };\n};\n\nexport type AbiBuffer<L extends number = number> = {\n\tbuff: { length: L };\n};\n\nexport type AbiPrimitiveType =\n\t| AbiUInt128\n\t| AbiInt128\n\t| AbiBool\n\t| AbiPrincipal\n\t| AbiTraitReference\n\t| AbiNone\n\t| AbiStringAscii\n\t| AbiStringUtf8\n\t| AbiBuffer;\n\n// Composite types (interfaces for recursion)\n\nexport interface AbiListType {\n\tlist: { type: AbiType; length: number };\n}\n\nexport interface AbiTupleType {\n\ttuple: ReadonlyArray<{ name: string; type: AbiType }>;\n}\n\nexport interface AbiOptionalType {\n\toptional: AbiType;\n}\n\nexport interface AbiResponseType {\n\tresponse: { ok: AbiType; error: AbiType };\n}\n\n/** Discriminated union of all Clarity value types (primitives, buffers, lists, tuples, optionals, responses). */\nexport type AbiType =\n\t| AbiPrimitiveType\n\t| AbiListType\n\t| AbiTupleType\n\t| AbiOptionalType\n\t| AbiResponseType;\n\n// Generic versions for better type inference\n\nexport type AbiList<T extends AbiType = AbiType, L extends number = number> = {\n\tlist: { type: T; length: L };\n};\n\nexport type AbiTuple<T extends ReadonlyArray<{ name: string; type: AbiType }>> =\n\t{\n\t\ttuple: T;\n\t};\n\nexport type AbiOptional<T extends AbiType = AbiType> = {\n\toptional: T;\n};\n\nexport type AbiResponse<\n\tO extends AbiType = AbiType,\n\tE extends AbiType = AbiType,\n> = {\n\tresponse: { ok: O; error: E };\n};\n",
|
|
6
|
-
"import { validateStacksAddress } from \"../../utils/address.ts\";\nimport type { ResponseErr, ResponseOk } from \"./mappings.ts\";\nimport { CONTRACT_NAME_REGEX, MAX_I128, MAX_U128, MIN_I128 } from \"./types.ts\";\nimport type {\n\tAbiBuffer,\n\tAbiListType,\n\tAbiOptionalType,\n\tAbiResponseType,\n\tAbiStringAscii,\n\tAbiStringUtf8,\n\tAbiTraitReference,\n\tAbiTupleType,\n\tAbiType,\n} from \"./types.ts\";\n\n// Value guards\n\nexport function isUint128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= 0n && value <= MAX_U128;\n}\n\nexport function isInt128(value: unknown): value is bigint {\n\treturn typeof value === \"bigint\" && value >= MIN_I128 && value <= MAX_I128;\n}\n\nexport function isBool(value: unknown): value is boolean {\n\treturn typeof value === \"boolean\";\n}\n\nexport function isPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parts = value.split(\".\");\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst address = parts[0]!;\n\tconst contractName = parts[1];\n\tif (!validateStacksAddress(address)) return false;\n\tif (contractName !== undefined) {\n\t\treturn CONTRACT_NAME_REGEX.test(contractName);\n\t}\n\treturn true;\n}\n\nexport function isStandardPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (value.includes(\".\")) return false;\n\treturn validateStacksAddress(value);\n}\n\nexport function isContractPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tif (!value.includes(\".\")) return false;\n\tconst parts = value.split(\".\");\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst address = parts[0]!;\n\t// biome-ignore lint/style/noNonNullAssertion: value is non-null after preceding check or by construction; TS narrowing limitation\n\tconst contractName = parts[1]!;\n\tif (!validateStacksAddress(address)) return false;\n\treturn CONTRACT_NAME_REGEX.test(contractName);\n}\n\nexport function isTraitReference(value: unknown): value is string {\n\treturn isContractPrincipal(value);\n}\n\nexport function isString(value: unknown): value is string {\n\treturn typeof value === \"string\";\n}\n\nexport function isUint8Array(value: unknown): value is Uint8Array {\n\treturn value instanceof Uint8Array;\n}\n\nexport function isArray<T>(\n\tvalue: unknown,\n\titemGuard: (item: unknown) => item is T,\n): value is T[] {\n\treturn Array.isArray(value) && value.every(itemGuard);\n}\n\nexport function isOptional<T>(\n\tvalue: unknown,\n\tguard: (val: unknown) => val is T,\n): value is T | null {\n\treturn value === null || guard(value);\n}\n\nexport function isOkResponse<T>(\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tresponse: { ok: T } | { err: any },\n): response is ResponseOk<T> {\n\treturn \"ok\" in response && !(\"err\" in response);\n}\n\nexport function isErrResponse<E>(\n\t// biome-ignore lint/suspicious/noExplicitAny: interop boundary or dynamic-shape value where typing adds friction without runtime safety\n\tresponse: { ok: any } | { err: E },\n): response is ResponseErr<E> {\n\treturn \"err\" in response && !(\"ok\" in response);\n}\n\nexport function isResponse<T, E>(\n\tvalue: unknown,\n\tokGuard: (val: unknown) => val is T,\n\terrGuard: (val: unknown) => val is E,\n): value is ResponseOk<T> | ResponseErr<E> {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst obj = value as Record<string, unknown>;\n\tif (\"ok\" in value && !(\"err\" in value)) return okGuard(obj.ok);\n\tif (\"err\" in value && !(\"ok\" in value)) return errGuard(obj.err);\n\treturn false;\n}\n\n// ABI type definition guards\n\nexport function isAbiList(type: AbiType): type is AbiListType {\n\treturn typeof type === \"object\" && type !== null && \"list\" in type;\n}\n\nexport function isAbiTuple(type: AbiType): type is AbiTupleType {\n\treturn typeof type === \"object\" && type !== null && \"tuple\" in type;\n}\n\nexport function isAbiOptional(type: AbiType): type is AbiOptionalType {\n\treturn typeof type === \"object\" && type !== null && \"optional\" in type;\n}\n\nexport function isAbiResponse(type: AbiType): type is AbiResponseType {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nexport function isAbiBuffer(type: AbiType): type is AbiBuffer {\n\treturn typeof type === \"object\" && type !== null && \"buff\" in type;\n}\n\nexport function isAbiStringAscii(type: AbiType): type is AbiStringAscii {\n\treturn typeof type === \"object\" && type !== null && \"string-ascii\" in type;\n}\n\nexport function isAbiStringUtf8(type: AbiType): type is AbiStringUtf8 {\n\treturn typeof type === \"object\" && type !== null && \"string-utf8\" in type;\n}\n\nexport function isAbiTraitReference(type: AbiType): type is AbiTraitReference {\n\treturn type === \"trait_reference\";\n}\n",
|
|
7
|
-
"type CamelCaseInner<S extends string> =\n\tS extends `${infer P1}-${infer P2}${infer P3}`\n\t\t? `${P1}${Capitalize<CamelCaseInner<`${P2}${P3}`>>}`\n\t\t: S;\n\nexport type ToCamelCase<S extends string> =\n\tCamelCaseInner<S> extends `${number}${string}`\n\t\t? `_${CamelCaseInner<S>}`\n\t\t: CamelCaseInner<S>;\n\nexport function toCamelCase(str: string): string {\n\treturn str\n\t\t.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())\n\t\t.replace(/-([A-Z])/g, (_, letter) => letter)\n\t\t.replace(/-(\\d)/g, (_, digit) => digit)\n\t\t.replace(/-/g, \"\")\n\t\t.replace(/^\\d/, \"_$&\");\n}\n",
|
|
8
|
-
"import {\n\tisAbiBuffer,\n\tisAbiList,\n\tisAbiOptional,\n\tisAbiResponse,\n\tisAbiStringAscii,\n\tisAbiStringUtf8,\n\tisAbiTuple,\n} from \"./abi/guards.ts\";\nimport type { AbiToTS } from \"./abi/mappings.ts\";\nimport type { AbiType } from \"./abi/types.ts\";\nimport { toCamelCase } from \"./abi/utils.ts\";\nimport type { ClarityValue } from \"./types.ts\";\nimport {\n\tboolCV,\n\tbufferCV,\n\tintCV,\n\tlistCV,\n\tnoneCV,\n\tresponseErrorCV,\n\tresponseOkCV,\n\tsomeCV,\n\tstringAsciiCV,\n\tstringUtf8CV,\n\ttupleCV,\n\tuintCV,\n} from \"./values.ts\";\nimport { Cl } from \"./values.ts\";\n\n/** CV type tags — mirrors the discriminants of `ClarityValue`. */\nconst CV_TYPE_TAGS = new Set([\n\t\"int\",\n\t\"uint\",\n\t\"true\",\n\t\"false\",\n\t\"address\",\n\t\"contract\",\n\t\"ascii\",\n\t\"utf8\",\n\t\"buffer\",\n\t\"list\",\n\t\"tuple\",\n\t\"none\",\n\t\"some\",\n\t\"ok\",\n\t\"err\",\n]);\n\n/**\n * Duck-type check: is `value` already a built ClarityValue? Tag-only CVs\n * (`true`/`false`/`none`) have no payload; every other tag carries `value`.\n */\nexport function isClarityValue(value: unknown): value is ClarityValue {\n\tif (typeof value !== \"object\" || value === null) return false;\n\tconst type = (value as { type?: unknown }).type;\n\tif (typeof type !== \"string\" || !CV_TYPE_TAGS.has(type)) return false;\n\tif (type === \"true\" || type === \"false\" || type === \"none\") return true;\n\treturn \"value\" in value;\n}\n\nconst HEX_PAIRS_REGEX = /^(?:[0-9a-fA-F]{2})+$/;\n\n/**\n * Coerce a flexible buffer input to a BufferCV. Accepts `Uint8Array`, a\n * pre-built `BufferCV`, a tagged `{ type: 'ascii' | 'utf8' | 'hex', value }`\n * object, or a bare string (even-length hex — optionally 0x-prefixed — is\n * decoded as hex; anything else is UTF-8 encoded).\n */\nfunction coerceBuffer(value: unknown): ClarityValue {\n\tif (value instanceof Uint8Array) return bufferCV(value);\n\tif (typeof value === \"object\" && value !== null && \"type\" in value) {\n\t\tconst tagged = value as { type: string; value?: unknown };\n\t\tif (tagged.type === \"buffer\" && isClarityValue(value)) return value;\n\t\tif (typeof tagged.value === \"string\") {\n\t\t\tif (tagged.type === \"ascii\") return Cl.bufferFromAscii(tagged.value);\n\t\t\tif (tagged.type === \"utf8\") return Cl.bufferFromUtf8(tagged.value);\n\t\t\tif (tagged.type === \"hex\") return Cl.bufferFromHex(tagged.value);\n\t\t}\n\t\tthrow new Error(`Unsupported buffer input: ${JSON.stringify(value)}`);\n\t}\n\tif (typeof value === \"string\") {\n\t\tconst hex = value.startsWith(\"0x\") ? value.slice(2) : value;\n\t\tif (HEX_PAIRS_REGEX.test(hex)) return Cl.bufferFromHex(hex);\n\t\treturn Cl.bufferFromUtf8(value);\n\t}\n\tthrow new Error(\n\t\t\"buffer arg expects Uint8Array, hex string, { type, value }, or BufferCV\",\n\t);\n}\n\n/**\n * Convert a JS value to a ClarityValue using ABI type information.\n *\n * Pre-built ClarityValues pass through unchanged (escape hatch for callers\n * that already hold a CV). Buffer args additionally accept hex strings and\n * tagged `{ type, value }` objects — matching the generated-client input\n * contract.\n */\nexport function jsToClarityValue(\n\tabiType: AbiType,\n\tvalue: unknown,\n): ClarityValue {\n\t// Buffers first: the tagged `{ type: 'ascii', value }` input form is\n\t// shape-identical to StringAsciiCV, so buffer coercion wins for buff args.\n\tif (isAbiBuffer(abiType)) return coerceBuffer(value);\n\n\tif (isClarityValue(value)) return value;\n\n\tif (abiType === \"uint128\") return uintCV(value as bigint | number);\n\tif (abiType === \"int128\") return intCV(value as bigint | number);\n\tif (abiType === \"bool\") return boolCV(value as boolean);\n\tif (abiType === \"principal\" || abiType === \"trait_reference\")\n\t\treturn Cl.principal(value as string);\n\n\tif (isAbiStringAscii(abiType)) return stringAsciiCV(value as string);\n\tif (isAbiStringUtf8(abiType)) return stringUtf8CV(value as string);\n\n\tif (isAbiList(abiType)) {\n\t\tconst arr = value as unknown[];\n\t\treturn listCV(arr.map((item) => jsToClarityValue(abiType.list.type, item)));\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tconst data: Record<string, ClarityValue> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tconst hasOriginal = field.name in obj;\n\t\t\tconst hasCamel = camelKey in obj;\n\t\t\tconst fieldValue = hasOriginal\n\t\t\t\t? obj[field.name]\n\t\t\t\t: hasCamel\n\t\t\t\t\t? obj[camelKey]\n\t\t\t\t\t: undefined;\n\t\t\tif (fieldValue === undefined && !isAbiOptional(field.type)) {\n\t\t\t\tthrow new Error(`Missing tuple field: ${field.name}`);\n\t\t\t}\n\t\t\tdata[field.name] = jsToClarityValue(field.type, fieldValue);\n\t\t}\n\t\treturn tupleCV(data);\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (value === null || value === undefined) return noneCV();\n\t\treturn someCV(jsToClarityValue(abiType.optional, value));\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tconst obj = value as Record<string, unknown>;\n\t\tif (\"ok\" in obj && !(\"err\" in obj))\n\t\t\treturn responseOkCV(jsToClarityValue(abiType.response.ok, obj.ok));\n\t\tif (\"err\" in obj && !(\"ok\" in obj))\n\t\t\treturn responseErrorCV(jsToClarityValue(abiType.response.error, obj.err));\n\t\tthrow new Error(\"Response must have exactly 'ok' or 'err' property\");\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n\n/**\n * Convert a ClarityValue back to a typed JS value using ABI type information.\n */\nexport function clarityValueToJS<T extends AbiType>(\n\tabiType: T,\n\tcv: ClarityValue,\n): AbiToTS<T> {\n\treturn clarityValueToJSInner(abiType, cv) as AbiToTS<T>;\n}\n\n/** Non-generic version for internal use — avoids deep type instantiation. */\nexport function clarityValueToJSUntyped(\n\tabiType: AbiType,\n\tcv: ClarityValue,\n): unknown {\n\treturn clarityValueToJSInner(abiType, cv);\n}\n\nfunction clarityValueToJSInner(abiType: AbiType, cv: ClarityValue): unknown {\n\tif (abiType === \"uint128\" || abiType === \"int128\") {\n\t\tif (cv.type !== \"int\" && cv.type !== \"uint\")\n\t\t\tthrow new Error(`Expected int/uint CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (abiType === \"bool\") {\n\t\tif (cv.type === \"true\") return true;\n\t\tif (cv.type === \"false\") return false;\n\t\tthrow new Error(`Expected bool CV, got ${cv.type}`);\n\t}\n\n\tif (abiType === \"principal\" || abiType === \"trait_reference\") {\n\t\tif (cv.type !== \"address\" && cv.type !== \"contract\")\n\t\t\tthrow new Error(`Expected principal CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiStringAscii(abiType) || isAbiStringUtf8(abiType)) {\n\t\tif (cv.type !== \"ascii\" && cv.type !== \"utf8\")\n\t\t\tthrow new Error(`Expected string CV, got ${cv.type}`);\n\t\treturn cv.value;\n\t}\n\n\tif (isAbiBuffer(abiType)) {\n\t\tif (cv.type !== \"buffer\")\n\t\t\tthrow new Error(`Expected buffer CV, got ${cv.type}`);\n\t\t// BufferCV stores hex string; convert back to Uint8Array\n\t\tconst hex = cv.value;\n\t\tconst bytes = new Uint8Array(hex.length / 2);\n\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\tbytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);\n\t\t}\n\t\treturn bytes;\n\t}\n\n\tif (isAbiList(abiType)) {\n\t\tif (cv.type !== \"list\") throw new Error(`Expected list CV, got ${cv.type}`);\n\t\treturn cv.value.map((item) =>\n\t\t\tclarityValueToJSInner(abiType.list.type, item),\n\t\t);\n\t}\n\n\tif (isAbiTuple(abiType)) {\n\t\tif (cv.type !== \"tuple\")\n\t\t\tthrow new Error(`Expected tuple CV, got ${cv.type}`);\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const field of abiType.tuple) {\n\t\t\tconst fieldCV = cv.value[field.name];\n\t\t\tif (!fieldCV) throw new Error(`Missing tuple field in CV: ${field.name}`);\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tresult[camelKey] = clarityValueToJSInner(field.type, fieldCV);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (isAbiOptional(abiType)) {\n\t\tif (cv.type === \"none\") return null;\n\t\tif (cv.type === \"some\")\n\t\t\treturn clarityValueToJSInner(abiType.optional, cv.value);\n\t\tthrow new Error(`Expected optional CV, got ${cv.type}`);\n\t}\n\n\tif (isAbiResponse(abiType)) {\n\t\tif (cv.type === \"ok\")\n\t\t\treturn { ok: clarityValueToJSInner(abiType.response.ok, cv.value) };\n\t\tif (cv.type === \"err\")\n\t\t\treturn { err: clarityValueToJSInner(abiType.response.error, cv.value) };\n\t\tthrow new Error(`Expected response CV, got ${cv.type}`);\n\t}\n\n\tthrow new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);\n}\n"
|
|
9
|
-
],
|
|
10
|
-
"mappings": ";AAIO,IAAM,sBAA8B;;;ACapC,SAAS,SAAS,CAAC,OAAiC;AAAA,EAC1D,OAAO,OAAO,UAAU,YAAY,SAAS,MAAM,SAAS;AAAA;AAGtD,SAAS,QAAQ,CAAC,OAAiC;AAAA,EACzD,OAAO,OAAO,UAAU,YAAY,SAAS,YAAY,SAAS;AAAA;AAG5D,SAAS,MAAM,CAAC,OAAkC;AAAA,EACxD,OAAO,OAAO,UAAU;AAAA;AAGlB,SAAS,WAAW,CAAC,OAAiC;AAAA,EAC5D,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,MAAM,QAAQ,MAAM,MAAM,GAAG;AAAA,EAE7B,MAAM,UAAU,MAAM;AAAA,EACtB,MAAM,eAAe,MAAM;AAAA,EAC3B,IAAI,CAAC,sBAAsB,OAAO;AAAA,IAAG,OAAO;AAAA,EAC5C,IAAI,iBAAiB,WAAW;AAAA,IAC/B,OAAO,oBAAoB,KAAK,YAAY;AAAA,EAC7C;AAAA,EACA,OAAO;AAAA;AAGD,SAAS,mBAAmB,CAAC,OAAiC;AAAA,EACpE,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,IAAI,MAAM,SAAS,GAAG;AAAA,IAAG,OAAO;AAAA,EAChC,OAAO,sBAAsB,KAAK;AAAA;AAG5B,SAAS,mBAAmB,CAAC,OAAiC;AAAA,EACpE,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,IAAI,CAAC,MAAM,SAAS,GAAG;AAAA,IAAG,OAAO;AAAA,EACjC,MAAM,QAAQ,MAAM,MAAM,GAAG;AAAA,EAE7B,MAAM,UAAU,MAAM;AAAA,EAEtB,MAAM,eAAe,MAAM;AA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AEA,IAAI,cAAc,OAAO,GAAG;AAAA,IAC3B,IAAI,GAAG,SAAS;AAAA,MACf,OAAO,EAAE,IAAI,sBAAsB,QAAQ,SAAS,IAAI,GAAG,KAAK,EAAE;AAAA,IACnE,IAAI,GAAG,SAAS;AAAA,MACf,OAAO,EAAE,KAAK,sBAAsB,QAAQ,SAAS,OAAO,GAAG,KAAK,EAAE;AAAA,IACvE,MAAM,IAAI,MAAM,6BAA6B,GAAG,MAAM;AAAA,EACvD;AAAA,EAEA,MAAM,IAAI,MAAM,qBAAqB,KAAK,UAAU,OAAO,GAAG;AAAA;",
|
|
11
|
-
"debugId": "234B58D453D798AA64756E2164756E21",
|
|
12
|
-
"names": []
|
|
13
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/utils/constants.ts", "../src/utils/address.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"// Clarity integer bounds\nexport const MAX_U128: bigint = (1n << 128n) - 1n;\nexport const MAX_I128: bigint = (1n << 127n) - 1n;\nexport const MIN_I128: bigint = -(1n << 127n);\n\n/** C32-encoded address version bytes for single-sig and multi-sig on each network. */\nexport const AddressVersion = {\n\tMainnetSingleSig: 22,\n\tMainnetMultiSig: 20,\n\tTestnetSingleSig: 26,\n\tTestnetMultiSig: 21,\n} as const;\nexport type AddressVersion =\n\t(typeof AddressVersion)[keyof typeof AddressVersion];\n\n/** Mainnet burn address (all-zero hash160). */\nexport const ZERO_ADDRESS = \"SP000000000000000000002Q6VF78\";\n/** Testnet burn address (all-zero hash160). */\nexport const TESTNET_ZERO_ADDRESS = \"ST000000000000000000002AMW42H\";\n\n/** Number of microSTX per 1 STX (10^6). */\nexport const MICROSTX_PER_STX = 1_000_000n;\n",
|
|
6
|
-
"import { c32address, c32addressDecode } from \"./c32.ts\";\nimport { AddressVersion } from \"./constants.ts\";\nimport { bytesToHex, hexToBytes, without0x } from \"./encoding.ts\";\nimport { hash160 } from \"./hash.ts\";\n\nexport { c32address, c32addressDecode };\n\n/**\n * Derive the single-sig Stacks address for a compressed public key.\n */\nexport function publicKeyToAddress(\n\tpublicKey: string | Uint8Array,\n\tnetwork: \"mainnet\" | \"testnet\" = \"mainnet\",\n): string {\n\tconst bytes =\n\t\ttypeof publicKey === \"string\"\n\t\t\t? hexToBytes(without0x(publicKey))\n\t\t\t: publicKey;\n\tconst version =\n\t\tnetwork === \"mainnet\"\n\t\t\t? AddressVersion.MainnetSingleSig\n\t\t\t: AddressVersion.TestnetSingleSig;\n\treturn c32address(version, bytesToHex(hash160(bytes)));\n}\n\nexport function validateStacksAddress(address: string): boolean {\n\ttry {\n\t\tc32addressDecode(address);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** Alias for validateStacksAddress — matches future.md naming. */\nexport const isValidAddress: (address: string) => boolean =\n\tvalidateStacksAddress;\n\nexport function parseContractId(contractId: string): [string, string] {\n\tconst [address, name] = contractId.split(\".\");\n\tif (!address || !name)\n\t\tthrow new Error(`Invalid contract identifier: ${contractId}`);\n\treturn [address, name];\n}\n\nexport function isClarityName(name: string): boolean {\n\tconst regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;\n\treturn regex.test(name) && name.length < 128;\n}\n\n/**\n * Compare two Stacks addresses for equality (case-insensitive, version-aware).\n * Throws if either address is invalid.\n */\nexport function isAddressEqual(a: string, b: string): boolean {\n\tconst [versionA, hashA] = c32addressDecode(a);\n\tconst [versionB, hashB] = c32addressDecode(b);\n\treturn versionA === versionB && hashA.toLowerCase() === hashB.toLowerCase();\n}\n\n/** Extract the version byte from a Stacks address (22, 20, 26, or 21). */\nexport function addressToVersion(address: string): number {\n\treturn c32addressDecode(address)[0];\n}\n\n/**\n * Build a contract address from deployer + contract name.\n * Validates both parts; returns `deployer.contractName`.\n */\nexport function getContractAddress(\n\tdeployer: string,\n\tcontractName: string,\n): string {\n\tif (!validateStacksAddress(deployer)) {\n\t\tthrow new Error(`Invalid deployer address: ${deployer}`);\n\t}\n\tif (!isClarityName(contractName)) {\n\t\tthrow new Error(`Invalid contract name: ${contractName}`);\n\t}\n\treturn `${deployer}.${contractName}`;\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";;;;;;;;;;AACO,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,WAAmB,EAAE,MAAM;AAGjC,IAAM,iBAAiB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,iBAAiB;AAClB;AAKO,IAAM,eAAe;AAErB,IAAM,uBAAuB;AAG7B,IAAM,mBAAmB;;;ACXzB,SAAS,kBAAkB,CACjC,WACA,UAAiC,WACxB;AAAA,EACT,MAAM,QACL,OAAO,cAAc,WAClB,WAAW,UAAU,SAAS,CAAC,IAC/B;AAAA,EACJ,MAAM,UACL,YAAY,YACT,eAAe,mBACf,eAAe;AAAA,EACnB,OAAO,WAAW,SAAS,WAAW,QAAQ,KAAK,CAAC,CAAC;AAAA;AAG/C,SAAS,qBAAqB,CAAC,SAA0B;AAAA,EAC/D,IAAI;AAAA,IACH,iBAAiB,OAAO;AAAA,IACxB,OAAO;AAAA,IACN,MAAM;AAAA,IACP,OAAO;AAAA;AAAA;AAKF,IAAM,iBACZ;AAEM,SAAS,eAAe,CAAC,YAAsC;AAAA,EACrE,OAAO,SAAS,QAAQ,WAAW,MAAM,GAAG;AAAA,EAC5C,IAAI,CAAC,WAAW,CAAC;AAAA,IAChB,MAAM,IAAI,MAAM,gCAAgC,YAAY;AAAA,EAC7D,OAAO,CAAC,SAAS,IAAI;AAAA;AAGf,SAAS,aAAa,CAAC,MAAuB;AAAA,EACpD,MAAM,QAAQ;AAAA,EACd,OAAO,MAAM,KAAK,IAAI,KAAK,KAAK,SAAS;AAAA;AAOnC,SAAS,cAAc,CAAC,GAAW,GAAoB;AAAA,EAC7D,OAAO,UAAU,SAAS,iBAAiB,CAAC;AAAA,EAC5C,OAAO,UAAU,SAAS,iBAAiB,CAAC;AAAA,EAC5C,OAAO,aAAa,YAAY,MAAM,YAAY,MAAM,MAAM,YAAY;AAAA;AAIpE,SAAS,gBAAgB,CAAC,SAAyB;AAAA,EACzD,OAAO,iBAAiB,OAAO,EAAE;AAAA;AAO3B,SAAS,kBAAkB,CACjC,UACA,cACS;AAAA,EACT,IAAI,CAAC,sBAAsB,QAAQ,GAAG;AAAA,IACrC,MAAM,IAAI,MAAM,6BAA6B,UAAU;AAAA,EACxD;AAAA,EACA,IAAI,CAAC,cAAc,YAAY,GAAG;AAAA,IACjC,MAAM,IAAI,MAAM,0BAA0B,cAAc;AAAA,EACzD;AAAA,EACA,OAAO,GAAG,YAAY;AAAA;",
|
|
9
|
-
"debugId": "63F221153EEDD88D64756E2164756E21",
|
|
10
|
-
"names": []
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/utils/constants.ts", "../src/utils/address.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"// Clarity integer bounds\nexport const MAX_U128: bigint = (1n << 128n) - 1n;\nexport const MAX_I128: bigint = (1n << 127n) - 1n;\nexport const MIN_I128: bigint = -(1n << 127n);\n\n/** C32-encoded address version bytes for single-sig and multi-sig on each network. */\nexport const AddressVersion = {\n\tMainnetSingleSig: 22,\n\tMainnetMultiSig: 20,\n\tTestnetSingleSig: 26,\n\tTestnetMultiSig: 21,\n} as const;\nexport type AddressVersion =\n\t(typeof AddressVersion)[keyof typeof AddressVersion];\n\n/** Mainnet burn address (all-zero hash160). */\nexport const ZERO_ADDRESS = \"SP000000000000000000002Q6VF78\";\n/** Testnet burn address (all-zero hash160). */\nexport const TESTNET_ZERO_ADDRESS = \"ST000000000000000000002AMW42H\";\n\n/** Number of microSTX per 1 STX (10^6). */\nexport const MICROSTX_PER_STX = 1_000_000n;\n",
|
|
6
|
-
"import { c32address, c32addressDecode } from \"./c32.ts\";\nimport { AddressVersion } from \"./constants.ts\";\nimport { bytesToHex, hexToBytes, without0x } from \"./encoding.ts\";\nimport { hash160 } from \"./hash.ts\";\n\nexport { c32address, c32addressDecode };\n\n/**\n * Derive the single-sig Stacks address for a compressed public key.\n */\nexport function publicKeyToAddress(\n\tpublicKey: string | Uint8Array,\n\tnetwork: \"mainnet\" | \"testnet\" = \"mainnet\",\n): string {\n\tconst bytes =\n\t\ttypeof publicKey === \"string\"\n\t\t\t? hexToBytes(without0x(publicKey))\n\t\t\t: publicKey;\n\tconst version =\n\t\tnetwork === \"mainnet\"\n\t\t\t? AddressVersion.MainnetSingleSig\n\t\t\t: AddressVersion.TestnetSingleSig;\n\treturn c32address(version, bytesToHex(hash160(bytes)));\n}\n\nexport function validateStacksAddress(address: string): boolean {\n\ttry {\n\t\tc32addressDecode(address);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** Alias for validateStacksAddress — matches future.md naming. */\nexport const isValidAddress: (address: string) => boolean =\n\tvalidateStacksAddress;\n\nexport function parseContractId(contractId: string): [string, string] {\n\tconst [address, name] = contractId.split(\".\");\n\tif (!address || !name)\n\t\tthrow new Error(`Invalid contract identifier: ${contractId}`);\n\treturn [address, name];\n}\n\nexport function isClarityName(name: string): boolean {\n\tconst regex = /^[a-zA-Z]([a-zA-Z0-9]|[-_!?+<>=/*])*$|^[-+=/*]$|^[<>]=?$/;\n\treturn regex.test(name) && name.length < 128;\n}\n\n/**\n * Compare two Stacks addresses for equality (case-insensitive, version-aware).\n * Throws if either address is invalid.\n */\nexport function isAddressEqual(a: string, b: string): boolean {\n\tconst [versionA, hashA] = c32addressDecode(a);\n\tconst [versionB, hashB] = c32addressDecode(b);\n\treturn versionA === versionB && hashA.toLowerCase() === hashB.toLowerCase();\n}\n\n/** Extract the version byte from a Stacks address (22, 20, 26, or 21). */\nexport function addressToVersion(address: string): number {\n\treturn c32addressDecode(address)[0];\n}\n\n/**\n * Build a contract address from deployer + contract name.\n * Validates both parts; returns `deployer.contractName`.\n */\nexport function getContractAddress(\n\tdeployer: string,\n\tcontractName: string,\n): string {\n\tif (!validateStacksAddress(deployer)) {\n\t\tthrow new Error(`Invalid deployer address: ${deployer}`);\n\t}\n\tif (!isClarityName(contractName)) {\n\t\tthrow new Error(`Invalid contract name: ${contractName}`);\n\t}\n\treturn `${deployer}.${contractName}`;\n}\n"
|
|
7
|
-
],
|
|
8
|
-
"mappings": ";AACO,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,WAAmB,EAAE,MAAM;AAGjC,IAAM,iBAAiB;AAAA,EAC7B,kBAAkB;AAAA,EAClB,iBAAiB;AAAA,EACjB,kBAAkB;AAAA,EAClB,iBAAiB;AAClB;AAKO,IAAM,eAAe;AAErB,IAAM,uBAAuB;AAG7B,IAAM,mBAAmB;;;ACXzB,SAAS,kBAAkB,CACjC,WACA,UAAiC,WACxB;AAAA,EACT,MAAM,QACL,OAAO,cAAc,WAClB,WAAW,UAAU,SAAS,CAAC,IAC/B;AAAA,EACJ,MAAM,UACL,YAAY,YACT,eAAe,mBACf,eAAe;AAAA,EACnB,OAAO,WAAW,SAAS,WAAW,QAAQ,KAAK,CAAC,CAAC;AAAA;AAG/C,SAAS,qBAAqB,CAAC,SAA0B;AAAA,EAC/D,IAAI;AAAA,IACH,iBAAiB,OAAO;AAAA,IACxB,OAAO;AAAA,IACN,MAAM;AAAA,IACP,OAAO;AAAA;AAAA;AAKF,IAAM,iBACZ;AAEM,SAAS,eAAe,CAAC,YAAsC;AAAA,EACrE,OAAO,SAAS,QAAQ,WAAW,MAAM,GAAG;AAAA,EAC5C,IAAI,CAAC,WAAW,CAAC;AAAA,IAChB,MAAM,IAAI,MAAM,gCAAgC,YAAY;AAAA,EAC7D,OAAO,CAAC,SAAS,IAAI;AAAA;AAGf,SAAS,aAAa,CAAC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