@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.
Files changed (77) hide show
  1. package/dist/shared/{stacks-0j16z8ev.js → stacks-08y0y0t7.js} +17 -13
  2. package/dist/shared/stacks-08y0y0t7.js.map +12 -0
  3. package/dist/shared/{stacks-bq0weg6n.js → stacks-1mpmzzyp.js} +5 -5
  4. package/dist/shared/{stacks-18jv9aen.js → stacks-4z72akdf.js} +11 -32
  5. package/dist/shared/stacks-4z72akdf.js.map +12 -0
  6. package/dist/shared/{stacks-r2yw4xzb.js → stacks-6bgh2c9h.js} +3 -3
  7. package/dist/shared/{stacks-mbnfwekf.js → stacks-9d2d0qjc.js} +3 -3
  8. package/dist/shared/{stacks-6xt8py97.cjs → stacks-agk106zs.cjs} +7 -27
  9. package/dist/shared/stacks-agk106zs.cjs.map +12 -0
  10. package/dist/shared/{stacks-gfm3r397.cjs → stacks-bfan7ex7.js} +27 -2
  11. package/dist/shared/stacks-bfan7ex7.js.map +11 -0
  12. package/dist/shared/{stacks-x94a1d6s.js → stacks-bm49tsh0.js} +2 -2
  13. package/dist/shared/{stacks-qchg7s2m.js → stacks-gkf9tsws.js} +3 -3
  14. package/dist/shared/{stacks-cyeajysa.js → stacks-jknrzd6v.js} +2 -2
  15. package/dist/shared/{stacks-sd9sc71n.js → stacks-jx146qf1.js} +3 -3
  16. package/dist/shared/{stacks-xh87kdz8.cjs → stacks-q34k4vnc.cjs} +15 -11
  17. package/dist/shared/stacks-q34k4vnc.cjs.map +12 -0
  18. package/dist/shared/{stacks-1x9b2k5y.js → stacks-r1m1r72q.js} +6 -6
  19. package/dist/shared/{stacks-m77szbay.js → stacks-rw2xbtdv.js} +2 -2
  20. package/dist/shared/{stacks-2mm20wqf.js → stacks-ttdk2g2f.js} +2 -2
  21. package/dist/shared/{stacks-ch5vshcd.js → stacks-v1hzk599.js} +7 -7
  22. package/dist/shared/{stacks-p2c0w0sq.js → stacks-w8tt1fmt.js} +3 -3
  23. package/dist/shared/{stacks-azp00pve.js → stacks-x5386y2y.cjs} +16 -13
  24. package/dist/shared/stacks-x5386y2y.cjs.map +11 -0
  25. package/dist/src/actions/index.js +12 -12
  26. package/dist/src/bitcoin/index.js +5 -5
  27. package/dist/src/bns/index.js +10 -10
  28. package/dist/src/clarity/index.d.cts +3 -0
  29. package/dist/src/clarity/index.d.ts +3 -0
  30. package/dist/src/clarity/index.js +7 -6
  31. package/dist/src/clarity/index.js.map +1 -1
  32. package/dist/src/connect/index.cjs +1 -2
  33. package/dist/src/connect/index.cjs.map +2 -2
  34. package/dist/src/connect/index.js +1 -2
  35. package/dist/src/connect/index.js.map +2 -2
  36. package/dist/src/filters/index.d.cts +18 -4
  37. package/dist/src/filters/index.d.ts +18 -4
  38. package/dist/src/filters/index.js +2 -2
  39. package/dist/src/index.d.cts +27 -15
  40. package/dist/src/index.d.ts +27 -15
  41. package/dist/src/index.js +11 -11
  42. package/dist/src/postconditions/index.js +2 -2
  43. package/dist/src/pox/index.js +9 -9
  44. package/dist/src/pox5/index.js +9 -9
  45. package/dist/src/sbtc/index.js +8 -8
  46. package/dist/src/stackingdao/index.js +9 -9
  47. package/dist/src/tools/index.cjs +1 -2
  48. package/dist/src/tools/index.cjs.map +4 -4
  49. package/dist/src/tools/index.js +1 -2
  50. package/dist/src/tools/index.js.map +4 -4
  51. package/dist/src/transactions/index.js +4 -4
  52. package/dist/src/utils/index.cjs +3 -1
  53. package/dist/src/utils/index.cjs.map +2 -2
  54. package/dist/src/utils/index.d.cts +13 -1
  55. package/dist/src/utils/index.d.ts +13 -1
  56. package/dist/src/utils/index.js +6 -2
  57. package/dist/src/utils/index.js.map +2 -2
  58. package/dist/src/x402/index.js +7 -7
  59. package/package.json +1 -1
  60. package/dist/shared/stacks-0j16z8ev.js.map +0 -12
  61. package/dist/shared/stacks-18jv9aen.js.map +0 -13
  62. package/dist/shared/stacks-6xt8py97.cjs.map +0 -13
  63. package/dist/shared/stacks-azp00pve.js.map +0 -11
  64. package/dist/shared/stacks-gfm3r397.cjs.map +0 -11
  65. package/dist/shared/stacks-xh87kdz8.cjs.map +0 -12
  66. /package/dist/shared/{stacks-bq0weg6n.js.map → stacks-1mpmzzyp.js.map} +0 -0
  67. /package/dist/shared/{stacks-r2yw4xzb.js.map → stacks-6bgh2c9h.js.map} +0 -0
  68. /package/dist/shared/{stacks-mbnfwekf.js.map → stacks-9d2d0qjc.js.map} +0 -0
  69. /package/dist/shared/{stacks-x94a1d6s.js.map → stacks-bm49tsh0.js.map} +0 -0
  70. /package/dist/shared/{stacks-qchg7s2m.js.map → stacks-gkf9tsws.js.map} +0 -0
  71. /package/dist/shared/{stacks-cyeajysa.js.map → stacks-jknrzd6v.js.map} +0 -0
  72. /package/dist/shared/{stacks-sd9sc71n.js.map → stacks-jx146qf1.js.map} +0 -0
  73. /package/dist/shared/{stacks-1x9b2k5y.js.map → stacks-r1m1r72q.js.map} +0 -0
  74. /package/dist/shared/{stacks-m77szbay.js.map → stacks-rw2xbtdv.js.map} +0 -0
  75. /package/dist/shared/{stacks-2mm20wqf.js.map → stacks-ttdk2g2f.js.map} +0 -0
  76. /package/dist/shared/{stacks-ch5vshcd.js.map → stacks-v1hzk599.js.map} +0 -0
  77. /package/dist/shared/{stacks-p2c0w0sq.js.map → stacks-w8tt1fmt.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
- isValidAddress
3
- } from "./stacks-azp00pve.js";
2
+ parsePrincipal
3
+ } from "./stacks-bfan7ex7.js";
4
4
 
5
5
  // src/filters/event-types.ts
6
6
  var DECODED_EVENT_TYPES = [
@@ -42,15 +42,7 @@ function assetId(value) {
42
42
  return value;
43
43
  }
44
44
  function isPrincipal(value) {
45
- const parts = value.split(".");
46
- if (parts.length > 2)
47
- return false;
48
- const [addr, contractName] = parts;
49
- if (!addr || !isValidAddress(addr))
50
- return false;
51
- if (parts.length === 2 && !contractName)
52
- return false;
53
- return true;
45
+ return parsePrincipal(value) !== null;
54
46
  }
55
47
  function hasWildcard(value) {
56
48
  return value.includes("*");
@@ -132,6 +124,9 @@ function toChainTrigger(spec) {
132
124
  for (const [key, value] of specEntries(spec)) {
133
125
  if (DECORATIVE_FIELDS.has(key))
134
126
  continue;
127
+ if (key === "factory") {
128
+ unsupported("Subscriptions", "factory", "dynamic factory discovery is a Subgraphs-only concept — a trigger targets addresses known when it is created");
129
+ }
135
130
  if (Array.isArray(value)) {
136
131
  unsupported("Subscriptions", `${key} set`, "a chain trigger targets ONE contract — create one subscription per contract, or use Index/Subgraphs which accept the set");
137
132
  }
@@ -148,6 +143,9 @@ function toIndexParams(spec, extra = {}) {
148
143
  for (const [key, value] of specEntries(spec)) {
149
144
  if (DECORATIVE_FIELDS.has(key))
150
145
  continue;
146
+ if (key === "factory") {
147
+ unsupported("Index events", "factory", "dynamic factory discovery is a Subgraphs-only concept");
148
+ }
151
149
  if (AMOUNT_FIELDS.has(key)) {
152
150
  unsupported("Index events", key, "amount predicates are Subscriptions/Subgraphs-only; filter client-side on the decoded rows");
153
151
  }
@@ -173,6 +171,9 @@ function toStreamsParams(spec, extra = {}) {
173
171
  for (const [key, value] of specEntries(spec)) {
174
172
  if (DECORATIVE_FIELDS.has(key))
175
173
  continue;
174
+ if (key === "factory") {
175
+ unsupported("Streams", "factory", "dynamic factory discovery is a Subgraphs-only concept");
176
+ }
176
177
  if (AMOUNT_FIELDS.has(key)) {
177
178
  unsupported("Streams", key, "amount predicates are Subscriptions/Subgraphs-only");
178
179
  }
@@ -196,6 +197,9 @@ function toContractCallsParams(spec, extra = {}) {
196
197
  for (const [key, value] of specEntries(spec)) {
197
198
  if (DECORATIVE_FIELDS.has(key))
198
199
  continue;
200
+ if (key === "factory") {
201
+ unsupported("Index contract-calls", "factory", "dynamic factory discovery is a Subgraphs-only concept");
202
+ }
199
203
  if (key === "caller") {
200
204
  out.sender = value;
201
205
  continue;
@@ -266,5 +270,5 @@ var on = {
266
270
  };
267
271
  export { DECODED_EVENT_TYPES, CHAIN_EVENT_FILTER_TYPES, assetId, isPrincipal, hasWildcard, assertPrincipalish, assertAssetIdentifier, assertContractId, makeChainEventFilter, fromSubgraphSource, on };
268
272
 
269
- //# debugId=EBF984B8438B171C64756E2164756E21
270
- //# sourceMappingURL=stacks-0j16z8ev.js.map
273
+ //# debugId=860B00F53A9C2F7064756E2164756E21
274
+ //# sourceMappingURL=stacks-08y0y0t7.js.map
@@ -0,0 +1,12 @@
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 { parsePrincipal } 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.\n * Shares {@link parsePrincipal} with the ABI guards so the two surfaces can't\n * disagree about what a principal is. */\nexport function isPrincipal(value: string): value is Principal {\n\treturn parsePrincipal(value) !== null;\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 (key === \"factory\") {\n\t\t\tunsupported(\n\t\t\t\t\"Subscriptions\",\n\t\t\t\t\"factory\",\n\t\t\t\t\"dynamic factory discovery is a Subgraphs-only concept — a trigger targets addresses known when it is created\",\n\t\t\t);\n\t\t}\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 (key === \"factory\") {\n\t\t\tunsupported(\n\t\t\t\t\"Index events\",\n\t\t\t\t\"factory\",\n\t\t\t\t\"dynamic factory discovery is a Subgraphs-only concept\",\n\t\t\t);\n\t\t}\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 (key === \"factory\") {\n\t\t\tunsupported(\n\t\t\t\t\"Streams\",\n\t\t\t\t\"factory\",\n\t\t\t\t\"dynamic factory discovery is a Subgraphs-only concept\",\n\t\t\t);\n\t\t}\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 === \"factory\") {\n\t\t\tunsupported(\n\t\t\t\t\"Index contract-calls\",\n\t\t\t\t\"factory\",\n\t\t\t\t\"dynamic factory discovery is a Subgraphs-only concept\",\n\t\t\t);\n\t\t}\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,EAClC;AAAA,EACA;AAAA,EACA;AAAA,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,CAAC,MAClE,qBAAqB,0BAA0B,MAAM;AAAA,EACtD,8BAA8B,CAC7B,SAAoD,CAAC,MACjD,qBAAqB,mCAAmC,MAAM;AACpE;",
10
+ "debugId": "860B00F53A9C2F7064756E2164756E21",
11
+ "names": []
12
+ }
@@ -6,21 +6,21 @@ import {
6
6
  resolveFee,
7
7
  resolveNonce,
8
8
  setUnsignedFee
9
- } from "./stacks-mbnfwekf.js";
9
+ } from "./stacks-9d2d0qjc.js";
10
10
  import {
11
11
  MalformedResponseError
12
12
  } from "./stacks-fh48neva.js";
13
13
  import {
14
14
  buildContractCall,
15
15
  signTransactionWithAccount
16
- } from "./stacks-sd9sc71n.js";
16
+ } from "./stacks-jx146qf1.js";
17
17
  import {
18
18
  deserializeCVBytes,
19
19
  serializeCVBytes
20
- } from "./stacks-2mm20wqf.js";
20
+ } from "./stacks-ttdk2g2f.js";
21
21
  import {
22
22
  parseContractId
23
- } from "./stacks-azp00pve.js";
23
+ } from "./stacks-bfan7ex7.js";
24
24
  import {
25
25
  bytesToHex,
26
26
  with0x
@@ -82,4 +82,4 @@ async function callContract(client, params) {
82
82
  export { getMapEntry, callContract };
83
83
 
84
84
  //# debugId=FF3F274BBCF0781464756E2164756E21
85
- //# sourceMappingURL=stacks-bq0weg6n.js.map
85
+ //# sourceMappingURL=stacks-1mpmzzyp.js.map
@@ -12,17 +12,13 @@ import {
12
12
  stringUtf8CV,
13
13
  tupleCV,
14
14
  uintCV
15
- } from "./stacks-2mm20wqf.js";
15
+ } from "./stacks-ttdk2g2f.js";
16
16
  import {
17
17
  MAX_I128,
18
18
  MAX_U128,
19
19
  MIN_I128,
20
- validateStacksAddress
21
- } from "./stacks-azp00pve.js";
22
-
23
- // src/clarity/abi/types.ts
24
- var CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\-]{0,127}$/;
25
-
20
+ parsePrincipal
21
+ } from "./stacks-bfan7ex7.js";
26
22
  // src/clarity/abi/guards.ts
27
23
  function isUint128(value) {
28
24
  return typeof value === "bigint" && value >= 0n && value <= MAX_U128;
@@ -34,36 +30,19 @@ function isBool(value) {
34
30
  return typeof value === "boolean";
35
31
  }
36
32
  function isPrincipal(value) {
37
- if (typeof value !== "string")
38
- return false;
39
- const parts = value.split(".");
40
- const address = parts[0];
41
- const contractName = parts[1];
42
- if (!validateStacksAddress(address))
43
- return false;
44
- if (contractName !== undefined) {
45
- return CONTRACT_NAME_REGEX.test(contractName);
46
- }
47
- return true;
33
+ return typeof value === "string" && parsePrincipal(value) !== null;
48
34
  }
49
35
  function isStandardPrincipal(value) {
50
36
  if (typeof value !== "string")
51
37
  return false;
52
- if (value.includes("."))
53
- return false;
54
- return validateStacksAddress(value);
38
+ const parsed = parsePrincipal(value);
39
+ return parsed !== null && parsed.contractName === undefined;
55
40
  }
56
41
  function isContractPrincipal(value) {
57
42
  if (typeof value !== "string")
58
43
  return false;
59
- if (!value.includes("."))
60
- return false;
61
- const parts = value.split(".");
62
- const address = parts[0];
63
- const contractName = parts[1];
64
- if (!validateStacksAddress(address))
65
- return false;
66
- return CONTRACT_NAME_REGEX.test(contractName);
44
+ const parsed = parsePrincipal(value);
45
+ return parsed !== null && parsed.contractName !== undefined;
67
46
  }
68
47
  function isTraitReference(value) {
69
48
  return isContractPrincipal(value);
@@ -305,7 +284,7 @@ function clarityValueToJSInner(abiType, cv) {
305
284
  throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
306
285
  }
307
286
 
308
- export { CONTRACT_NAME_REGEX, isUint128, isInt128, isBool, isPrincipal, isStandardPrincipal, isContractPrincipal, isTraitReference, isString, isUint8Array, isArray, isOptional, isOkResponse, isErrResponse, isResponse, isAbiList, isAbiTuple, isAbiOptional, isAbiResponse, isAbiBuffer, isAbiStringAscii, isAbiStringUtf8, isAbiTraitReference, toCamelCase, isClarityValue, jsToClarityValue, clarityValueToJS, clarityValueToJSUntyped };
287
+ export { isUint128, isInt128, isBool, isPrincipal, isStandardPrincipal, isContractPrincipal, isTraitReference, isString, isUint8Array, isArray, isOptional, isOkResponse, isErrResponse, isResponse, isAbiList, isAbiTuple, isAbiOptional, isAbiResponse, isAbiBuffer, isAbiStringAscii, isAbiStringUtf8, isAbiTraitReference, toCamelCase, isClarityValue, jsToClarityValue, clarityValueToJS, clarityValueToJSUntyped };
309
288
 
310
- //# debugId=61393ECAC463249664756E2164756E21
311
- //# sourceMappingURL=stacks-18jv9aen.js.map
289
+ //# debugId=F11F31DC77EDD23C64756E2164756E21
290
+ //# sourceMappingURL=stacks-4z72akdf.js.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/clarity/abi/guards.ts", "../src/clarity/abi/utils.ts", "../src/clarity/bridge.ts"],
4
+ "sourcesContent": [
5
+ "import { parsePrincipal } from \"../../utils/address.ts\";\nimport type { ResponseErr, ResponseOk } from \"./mappings.ts\";\nimport { 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\treturn typeof value === \"string\" && parsePrincipal(value) !== null;\n}\n\nexport function isStandardPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parsed = parsePrincipal(value);\n\t// Explicit null check: `null?.contractName === undefined` is also true.\n\treturn parsed !== null && parsed.contractName === undefined;\n}\n\nexport function isContractPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parsed = parsePrincipal(value);\n\treturn parsed !== null && parsed.contractName !== undefined;\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",
6
+ "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",
7
+ "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"
8
+ ],
9
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAiBO,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,OAAO,OAAO,UAAU,YAAY,eAAe,KAAK,MAAM;AAAA;AAGxD,SAAS,mBAAmB,CAAC,OAAiC;AAAA,EACpE,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,MAAM,SAAS,eAAe,KAAK;AAAA,EAEnC,OAAO,WAAW,QAAQ,OAAO,iBAAiB;AAAA;AAG5C,SAAS,mBAAmB,CAAC,OAAiC;AAAA,EACpE,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO;AAAA,EACtC,MAAM,SAAS,eAAe,KAAK;AAAA,EACnC,OAAO,WAAW,QAAQ,OAAO,iBAAiB;AAAA;AAG5C,SAAS,gBAAgB,CAAC,OAAiC;AAAA,EACjE,OAAO,oBAAoB,KAAK;AAAA;AAG1B,SAAS,QAAQ,CAAC,OAAiC;AAAA,EACzD,OAAO,OAAO,UAAU;AAAA;AAGlB,SAAS,YAAY,CAAC,OAAqC;AAAA,EACjE,OAAO,iBAAiB;AAAA;AAGlB,SAAS,OAAU,CACzB,OACA,WACe;AAAA,E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,OAAO,GAAG;AAAA;",
10
+ "debugId": "F11F31DC77EDD23C64756E2164756E21",
11
+ "names": []
12
+ }
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  deserializeCVBytes,
3
3
  serializeCVBytes
4
- } from "./stacks-2mm20wqf.js";
4
+ } from "./stacks-ttdk2g2f.js";
5
5
  import {
6
6
  parseContractId
7
- } from "./stacks-azp00pve.js";
7
+ } from "./stacks-bfan7ex7.js";
8
8
  import {
9
9
  bytesToHex,
10
10
  with0x
@@ -32,4 +32,4 @@ async function readContract(client, params) {
32
32
  export { readContract };
33
33
 
34
34
  //# debugId=0C52945E9698380964756E2164756E21
35
- //# sourceMappingURL=stacks-r2yw4xzb.js.map
35
+ //# sourceMappingURL=stacks-6bgh2c9h.js.map
@@ -9,10 +9,10 @@ import {
9
9
  getTransactionId,
10
10
  serializePayload,
11
11
  serializeTransaction
12
- } from "./stacks-sd9sc71n.js";
12
+ } from "./stacks-jx146qf1.js";
13
13
  import {
14
14
  deserializeCVBytes
15
- } from "./stacks-2mm20wqf.js";
15
+ } from "./stacks-ttdk2g2f.js";
16
16
  import {
17
17
  bytesToHex,
18
18
  intToBigInt
@@ -493,4 +493,4 @@ function assertNoFeeTierForProvider(fee) {
493
493
  export { estimateFee, getBlockHeight, HttpRequestError, getNonce, extendedApiSource, indexTxSource, TransactionError, BroadcastError, TransactionAbortedError, TransactionDroppedError, WaitForTransactionTimeoutError, SerializationError, SigningError, waitForTransactionReceipt, sendTransaction, jsonRpcSource, memoryStore, createNonceManager, resolveNonce, reconcileNonce, startNonceReconciler, isNonceConflictError, broadcastWithNonceReset, isProviderAccount, isFeeTier, minimumFee, resolveFee, setUnsignedFee, assertNoFeeTierForProvider };
494
494
 
495
495
  //# debugId=9367C23DC56A284164756E2164756E21
496
- //# sourceMappingURL=stacks-mbnfwekf.js.map
496
+ //# sourceMappingURL=stacks-9d2d0qjc.js.map
@@ -1,6 +1,3 @@
1
- // src/clarity/abi/types.ts
2
- var CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9\-]{0,127}$/;
3
-
4
1
  // src/clarity/abi/guards.ts
5
2
  function isUint128(value) {
6
3
  return typeof value === "bigint" && value >= 0n && value <= MAX_U128;
@@ -12,36 +9,19 @@ function isBool(value) {
12
9
  return typeof value === "boolean";
13
10
  }
14
11
  function isPrincipal(value) {
15
- if (typeof value !== "string")
16
- return false;
17
- const parts = value.split(".");
18
- const address = parts[0];
19
- const contractName = parts[1];
20
- if (!validateStacksAddress(address))
21
- return false;
22
- if (contractName !== undefined) {
23
- return CONTRACT_NAME_REGEX.test(contractName);
24
- }
25
- return true;
12
+ return typeof value === "string" && parsePrincipal(value) !== null;
26
13
  }
27
14
  function isStandardPrincipal(value) {
28
15
  if (typeof value !== "string")
29
16
  return false;
30
- if (value.includes("."))
31
- return false;
32
- return validateStacksAddress(value);
17
+ const parsed = parsePrincipal(value);
18
+ return parsed !== null && parsed.contractName === undefined;
33
19
  }
34
20
  function isContractPrincipal(value) {
35
21
  if (typeof value !== "string")
36
22
  return false;
37
- if (!value.includes("."))
38
- return false;
39
- const parts = value.split(".");
40
- const address = parts[0];
41
- const contractName = parts[1];
42
- if (!validateStacksAddress(address))
43
- return false;
44
- return CONTRACT_NAME_REGEX.test(contractName);
23
+ const parsed = parsePrincipal(value);
24
+ return parsed !== null && parsed.contractName !== undefined;
45
25
  }
46
26
  function isTraitReference(value) {
47
27
  return isContractPrincipal(value);
@@ -283,5 +263,5 @@ function clarityValueToJSInner(abiType, cv) {
283
263
  throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
284
264
  }
285
265
 
286
- //# debugId=234B58D453D798AA64756E2164756E21
287
- //# sourceMappingURL=stacks-6xt8py97.cjs.map
266
+ //# debugId=C0E0912050C4217A64756E2164756E21
267
+ //# sourceMappingURL=stacks-agk106zs.cjs.map
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/clarity/abi/guards.ts", "../src/clarity/abi/utils.ts", "../src/clarity/bridge.ts"],
4
+ "sourcesContent": [
5
+ "import { parsePrincipal } from \"../../utils/address.ts\";\nimport type { ResponseErr, ResponseOk } from \"./mappings.ts\";\nimport { 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\treturn typeof value === \"string\" && parsePrincipal(value) !== null;\n}\n\nexport function isStandardPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parsed = parsePrincipal(value);\n\t// Explicit null check: `null?.contractName === undefined` is also true.\n\treturn parsed !== null && parsed.contractName === undefined;\n}\n\nexport function isContractPrincipal(value: unknown): value is string {\n\tif (typeof value !== \"string\") return false;\n\tconst parsed = parsePrincipal(value);\n\treturn parsed !== null && parsed.contractName !== undefined;\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",
6
+ "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",
7
+ "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"
8
+ ],
9
+ "mappings": ";AAiBO,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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,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;",
10
+ "debugId": "C0E0912050C4217A64756E2164756E21",
11
+ "names": []
12
+ }
@@ -1,3 +1,12 @@
1
+ import {
2
+ bytesToHex,
3
+ c32address,
4
+ c32addressDecode,
5
+ hash160,
6
+ hexToBytes,
7
+ without0x
8
+ } from "./stacks-qs5fzts5.js";
9
+
1
10
  // src/utils/constants.ts
2
11
  var MAX_U128 = (1n << 128n) - 1n;
3
12
  var MAX_I128 = (1n << 127n) - 1n;
@@ -18,6 +27,7 @@ function publicKeyToAddress(publicKey, network = "mainnet") {
18
27
  const version = network === "mainnet" ? AddressVersion.MainnetSingleSig : AddressVersion.TestnetSingleSig;
19
28
  return c32address(version, bytesToHex(hash160(bytes)));
20
29
  }
30
+ var CONTRACT_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/;
21
31
  function validateStacksAddress(address) {
22
32
  try {
23
33
  c32addressDecode(address);
@@ -27,6 +37,19 @@ function validateStacksAddress(address) {
27
37
  }
28
38
  }
29
39
  var isValidAddress = validateStacksAddress;
40
+ function parsePrincipal(value) {
41
+ const parts = value.split(".");
42
+ if (parts.length > 2)
43
+ return null;
44
+ const [address, contractName] = parts;
45
+ if (!validateStacksAddress(address))
46
+ return null;
47
+ if (contractName === undefined)
48
+ return { address };
49
+ if (!CONTRACT_NAME_REGEX.test(contractName))
50
+ return null;
51
+ return { address, contractName };
52
+ }
30
53
  function parseContractId(contractId) {
31
54
  const [address, name] = contractId.split(".");
32
55
  if (!address || !name)
@@ -55,5 +78,7 @@ function getContractAddress(deployer, contractName) {
55
78
  return `${deployer}.${contractName}`;
56
79
  }
57
80
 
58
- //# debugId=81ECA8886FD9FECC64756E2164756E21
59
- //# sourceMappingURL=stacks-gfm3r397.cjs.map
81
+ export { MAX_U128, MAX_I128, MIN_I128, AddressVersion, ZERO_ADDRESS, TESTNET_ZERO_ADDRESS, MICROSTX_PER_STX, publicKeyToAddress, CONTRACT_NAME_REGEX, validateStacksAddress, isValidAddress, parsePrincipal, parseContractId, isClarityName, isAddressEqual, addressToVersion, getContractAddress };
82
+
83
+ //# debugId=ED927A54625FE2DC64756E2164756E21
84
+ //# sourceMappingURL=stacks-bfan7ex7.js.map
@@ -0,0 +1,11 @@
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\n/** Clarity contract-name grammar: leading letter, then letters/digits/`-`/`_`.\n * Underscore is legal (SIP-002) and deployed contracts use it — matches the\n * pattern the Index API already accepts for contract ids. */\nexport const CONTRACT_NAME_REGEX: RegExp = /^[a-zA-Z][a-zA-Z0-9_-]{0,127}$/;\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\n/** Parse a principal into its parts, or null when malformed. The single\n * definition of \"valid principal\" for this package: exactly one optional\n * `.name` segment (never two), a c32-decodable address, and a contract name\n * matching the Clarity grammar. */\nexport function parsePrincipal(\n\tvalue: string,\n): { address: string; contractName?: string } | null {\n\tconst parts = value.split(\".\");\n\tif (parts.length > 2) return null;\n\tconst [address, contractName] = parts as [string, string | undefined];\n\tif (!validateStacksAddress(address)) return null;\n\tif (contractName === undefined) return { address };\n\tif (!CONTRACT_NAME_REGEX.test(contractName)) return null;\n\treturn { address, contractName };\n}\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,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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": "ED927A54625FE2DC64756E2164756E21",
10
+ "names": []
11
+ }
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parseContractId,
3
3
  validateStacksAddress
4
- } from "./stacks-azp00pve.js";
4
+ } from "./stacks-bfan7ex7.js";
5
5
  import {
6
6
  intToBigInt
7
7
  } from "./stacks-qs5fzts5.js";
@@ -119,4 +119,4 @@ var Pc = {
119
119
  export { Pc };
120
120
 
121
121
  //# debugId=596DCED919FAD1C264756E2164756E21
122
- //# sourceMappingURL=stacks-x94a1d6s.js.map
122
+ //# sourceMappingURL=stacks-bm49tsh0.js.map
@@ -9,13 +9,13 @@ import {
9
9
  PostConditionPrincipalId,
10
10
  RECOVERABLE_ECDSA_SIG_LENGTH_BYTES,
11
11
  VRF_PROOF_BYTES_LENGTH
12
- } from "./stacks-sd9sc71n.js";
12
+ } from "./stacks-jx146qf1.js";
13
13
  import {
14
14
  BytesReader,
15
15
  readAddress,
16
16
  readCV,
17
17
  readLPString
18
- } from "./stacks-2mm20wqf.js";
18
+ } from "./stacks-ttdk2g2f.js";
19
19
  import {
20
20
  bytesToAscii,
21
21
  bytesToHex,
@@ -282,4 +282,4 @@ function deserializeTransaction(input, meta) {
282
282
  export { deserializeTransaction };
283
283
 
284
284
  //# debugId=D060D493BBB8A86F64756E2164756E21
285
- //# sourceMappingURL=stacks-qchg7s2m.js.map
285
+ //# sourceMappingURL=stacks-gkf9tsws.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readContract
3
- } from "./stacks-r2yw4xzb.js";
3
+ } from "./stacks-6bgh2c9h.js";
4
4
 
5
5
  // src/actions/public/multicall.ts
6
6
  async function multicall(client, params) {
@@ -19,4 +19,4 @@ async function multicall(client, params) {
19
19
  export { multicall };
20
20
 
21
21
  //# debugId=7B700090E4A219F464756E2164756E21
22
- //# sourceMappingURL=stacks-cyeajysa.js.map
22
+ //# sourceMappingURL=stacks-jknrzd6v.js.map