@secondlayer/stacks 0.2.2 → 0.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-02actsrx.cjs.map +2 -2
- package/dist/shared/{stacks-xp9n3r0t.js → stacks-09wa7ewe.js} +108 -108
- package/dist/shared/stacks-09wa7ewe.js.map +15 -0
- package/dist/shared/{stacks-ky14tdf6.cjs → stacks-0nfexv24.cjs} +20 -8
- package/dist/shared/stacks-0nfexv24.cjs.map +14 -0
- package/dist/shared/{stacks-an5k8n4t.cjs → stacks-14pgpkrr.cjs} +82 -73
- package/dist/shared/stacks-14pgpkrr.cjs.map +23 -0
- package/dist/shared/{stacks-v6ja2eh7.cjs → stacks-17sdtaxg.cjs} +106 -102
- package/dist/shared/stacks-17sdtaxg.cjs.map +15 -0
- package/dist/shared/{stacks-96gaxfcf.js → stacks-1s5w4ncf.js} +44 -32
- package/dist/shared/stacks-1s5w4ncf.js.map +17 -0
- package/dist/shared/stacks-24h5k94q.cjs.map +3 -3
- package/dist/shared/{stacks-evnzth1q.cjs → stacks-4vzmhw3q.cjs} +3 -3
- package/dist/shared/stacks-4vzmhw3q.cjs.map +10 -0
- package/dist/shared/{stacks-k9p8m3wf.js → stacks-4x2bcc2k.js} +87 -78
- package/dist/shared/stacks-4x2bcc2k.js.map +23 -0
- package/dist/shared/stacks-5tprhns9.cjs.map +3 -3
- package/dist/shared/stacks-709tra19.js.map +2 -2
- package/dist/shared/{stacks-q79dx28x.js → stacks-70p84bgg.js} +3 -3
- package/dist/shared/stacks-70p84bgg.js.map +10 -0
- package/dist/shared/{stacks-k2p5tv6x.js → stacks-913a2rx7.js} +3 -3
- package/dist/shared/stacks-913a2rx7.js.map +10 -0
- package/dist/shared/{stacks-jrnmh4kc.js → stacks-96d6m1zy.js} +15 -6
- package/dist/shared/stacks-96d6m1zy.js.map +11 -0
- package/dist/shared/stacks-9g0jhab3.cjs.map +2 -2
- package/dist/shared/stacks-dr5en54r.cjs.map +2 -2
- package/dist/shared/stacks-fcaefc5b.cjs.map +2 -2
- package/dist/shared/stacks-gck1sq7h.cjs.map +2 -2
- package/dist/shared/stacks-je937aas.js.map +2 -2
- package/dist/shared/{stacks-k58k970n.js → stacks-kg1npstf.js} +5 -3
- package/dist/shared/stacks-kg1npstf.js.map +10 -0
- package/dist/shared/{stacks-qvg7c24g.cjs → stacks-n98w7g57.cjs} +5 -3
- package/dist/shared/stacks-n98w7g57.cjs.map +10 -0
- package/dist/shared/{stacks-6m1z4j07.js → stacks-nqae5amn.cjs} +74 -160
- package/dist/shared/stacks-nqae5amn.cjs.map +10 -0
- package/dist/shared/stacks-qcae5852.js.map +2 -2
- package/dist/shared/stacks-qt8ehebn.js.map +3 -3
- package/dist/shared/stacks-ra02bpny.cjs.map +3 -3
- package/dist/shared/stacks-rwfgts3s.js.map +2 -2
- package/dist/shared/stacks-s10yb9gz.js.map +2 -2
- package/dist/shared/{stacks-etf219gs.cjs → stacks-s30kkvm8.js} +101 -118
- package/dist/shared/stacks-s30kkvm8.js.map +10 -0
- package/dist/shared/stacks-s7z5q8be.js.map +3 -3
- package/dist/shared/stacks-v9jqcpd4.js.map +2 -2
- package/dist/shared/stacks-vdfag81a.cjs.map +2 -2
- package/dist/shared/{stacks-rg1g0fja.js → stacks-wjem3xw9.js} +21 -9
- package/dist/shared/stacks-wjem3xw9.js.map +14 -0
- package/dist/shared/{stacks-k08tgzyp.cjs → stacks-wyxj879g.cjs} +3 -3
- package/dist/shared/stacks-wyxj879g.cjs.map +13 -0
- package/dist/shared/stacks-y3dh7hv1.js.map +3 -3
- package/dist/shared/{stacks-2ar4prfz.cjs → stacks-y5262j0z.cjs} +14 -5
- package/dist/shared/stacks-y5262j0z.cjs.map +11 -0
- package/dist/shared/stacks-ya3x01yd.cjs.map +2 -2
- package/dist/shared/{stacks-p93g814f.js → stacks-zf7rbpzp.js} +4 -4
- package/dist/shared/stacks-zf7rbpzp.js.map +13 -0
- package/dist/shared/{stacks-61rvzkz1.cjs → stacks-znrb59ce.cjs} +41 -29
- package/dist/shared/stacks-znrb59ce.cjs.map +17 -0
- package/dist/src/accounts/index.cjs +2 -2
- package/dist/src/accounts/index.cjs.map +5 -5
- package/dist/src/accounts/index.js +2 -6
- package/dist/src/accounts/index.js.map +5 -5
- package/dist/src/actions/index.d.cts +29 -29
- package/dist/src/actions/index.d.ts +29 -29
- package/dist/src/actions/index.js +7 -7
- package/dist/src/bns/index.cjs +55 -43
- package/dist/src/bns/index.cjs.map +9 -9
- package/dist/src/bns/index.d.cts +29 -29
- package/dist/src/bns/index.d.ts +29 -29
- package/dist/src/bns/index.js +62 -50
- package/dist/src/bns/index.js.map +9 -9
- package/dist/src/clarity/index.js +4 -4
- package/dist/src/connect/index.cjs +114 -112
- package/dist/src/connect/index.cjs.map +13 -13
- package/dist/src/connect/index.js +114 -112
- package/dist/src/connect/index.js.map +13 -13
- package/dist/src/connect/walletconnect/index.cjs +3 -3
- package/dist/src/connect/walletconnect/index.cjs.map +10 -10
- package/dist/src/connect/walletconnect/index.js +3 -3
- package/dist/src/connect/walletconnect/index.js.map +10 -10
- package/dist/src/index.cjs +108 -2
- package/dist/src/index.cjs.map +19 -15
- package/dist/src/index.d.cts +291 -112
- package/dist/src/index.d.ts +291 -112
- package/dist/src/index.js +122 -9
- package/dist/src/index.js.map +19 -15
- package/dist/src/pox/index.cjs.map +6 -6
- package/dist/src/pox/index.d.cts +29 -29
- package/dist/src/pox/index.d.ts +29 -29
- package/dist/src/pox/index.js +5 -5
- package/dist/src/pox/index.js.map +6 -6
- package/dist/src/stackingdao/index.cjs +31 -6
- package/dist/src/stackingdao/index.cjs.map +6 -6
- package/dist/src/stackingdao/index.d.cts +29 -29
- package/dist/src/stackingdao/index.d.ts +29 -29
- package/dist/src/stackingdao/index.js +37 -12
- package/dist/src/stackingdao/index.js.map +6 -6
- package/dist/src/subscriptions/index.d.cts +29 -29
- package/dist/src/subscriptions/index.d.ts +29 -29
- package/dist/src/tools/btc/index.cjs +130 -0
- package/dist/src/tools/btc/index.cjs.map +10 -0
- package/dist/src/tools/btc/index.d.cts +8 -0
- package/dist/src/tools/btc/index.d.ts +8 -0
- package/dist/src/tools/btc/index.js +89 -0
- package/dist/src/tools/btc/index.js.map +10 -0
- package/dist/src/tools/index.cjs +2470 -0
- package/dist/src/tools/index.cjs.map +61 -0
- package/dist/src/tools/index.d.cts +144 -0
- package/dist/src/tools/index.d.ts +144 -0
- package/dist/src/tools/index.js +2435 -0
- package/dist/src/tools/index.js.map +61 -0
- package/dist/src/transactions/index.js +3 -3
- package/dist/src/triggers/index.cjs +66 -0
- package/dist/src/triggers/index.cjs.map +10 -0
- package/dist/src/triggers/index.d.cts +116 -0
- package/dist/src/triggers/index.d.ts +116 -0
- package/dist/src/triggers/index.js +25 -0
- package/dist/src/triggers/index.js.map +10 -0
- package/dist/src/tx/index.cjs +65 -0
- package/dist/src/tx/index.cjs.map +10 -0
- package/dist/src/tx/index.d.cts +42 -0
- package/dist/src/tx/index.d.ts +42 -0
- package/dist/src/tx/index.js +22 -0
- package/dist/src/tx/index.js.map +10 -0
- package/dist/src/ui/index.cjs +431 -0
- package/dist/src/ui/index.cjs.map +27 -0
- package/dist/src/ui/index.d.cts +107 -0
- package/dist/src/ui/index.d.ts +107 -0
- package/dist/src/ui/index.js +391 -0
- package/dist/src/ui/index.js.map +27 -0
- package/dist/src/ui/schemas.cjs +134 -0
- package/dist/src/ui/schemas.cjs.map +18 -0
- package/dist/src/ui/schemas.d.cts +83 -0
- package/dist/src/ui/schemas.d.ts +83 -0
- package/dist/src/ui/schemas.js +91 -0
- package/dist/src/ui/schemas.js.map +18 -0
- package/dist/src/utils/index.cjs +3 -3
- package/dist/src/utils/index.cjs.map +4 -4
- package/dist/src/utils/index.js +4 -4
- package/dist/src/utils/index.js.map +4 -4
- package/package.json +157 -105
- package/dist/shared/stacks-2ar4prfz.cjs.map +0 -11
- package/dist/shared/stacks-61rvzkz1.cjs.map +0 -17
- package/dist/shared/stacks-6m1z4j07.js.map +0 -10
- package/dist/shared/stacks-96gaxfcf.js.map +0 -17
- package/dist/shared/stacks-an5k8n4t.cjs.map +0 -23
- package/dist/shared/stacks-etf219gs.cjs.map +0 -10
- package/dist/shared/stacks-evnzth1q.cjs.map +0 -10
- package/dist/shared/stacks-jrnmh4kc.js.map +0 -11
- package/dist/shared/stacks-k08tgzyp.cjs.map +0 -13
- package/dist/shared/stacks-k2p5tv6x.js.map +0 -10
- package/dist/shared/stacks-k58k970n.js.map +0 -10
- package/dist/shared/stacks-k9p8m3wf.js.map +0 -23
- package/dist/shared/stacks-ky14tdf6.cjs.map +0 -13
- package/dist/shared/stacks-p93g814f.js.map +0 -13
- package/dist/shared/stacks-q79dx28x.js.map +0 -10
- package/dist/shared/stacks-qvg7c24g.cjs.map +0 -10
- package/dist/shared/stacks-rg1g0fja.js.map +0 -13
- package/dist/shared/stacks-v6ja2eh7.cjs.map +0 -15
- package/dist/shared/stacks-xp9n3r0t.js.map +0 -15
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils/constants.ts"],
|
|
4
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
|
|
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
6
|
],
|
|
7
|
-
"mappings": ";AACO,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,WAAmB,EAAE,MAAM;AAGjC,IAAM,iBAAiB;AAAA,
|
|
7
|
+
"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;",
|
|
8
8
|
"debugId": "536701B14D19412164756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/actions/getContract.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type {
|
|
5
|
+
"import type {\n\tAbiContract,\n\tAbiFunction,\n\tAbiMap,\n\tAbiType,\n\tExtractFunctionArgs,\n\tExtractFunctionOutput,\n\tExtractMapKey,\n\tExtractMapNames,\n\tExtractMapValue,\n\tExtractPublicFunctions,\n\tExtractReadOnlyFunctions,\n} from \"../clarity/abi/index.ts\";\nimport { type ToCamelCase, toCamelCase } from \"../clarity/abi/utils.ts\";\nimport {\n\tclarityValueToJSUntyped,\n\tjsToClarityValue,\n} from \"../clarity/bridge.ts\";\nimport type { ClarityValue } from \"../clarity/types.ts\";\nimport type { Client } from \"../clients/types.ts\";\nimport type { PostCondition } from \"../postconditions/types.ts\";\nimport type { IntegerType } from \"../utils/encoding.ts\";\nimport { getMapEntry } from \"./public/getMapEntry.ts\";\nimport { readContract } from \"./public/readContract.ts\";\nimport { callContract } from \"./wallet/callContract.ts\";\n\n// --- Type helpers for unwrapping response types ---\n\n/** Unwrap `(response ok err)` → just the `ok` branch type */\ntype UnwrapResponse<T> = T extends { ok: infer O } | { err: any } ? O : T;\n\ntype ReadMethodReturn<\n\tC extends AbiContract,\n\tN extends ExtractReadOnlyFunctions<C>,\n> = UnwrapResponse<ExtractFunctionOutput<C, N>>;\n\n// --- Public type for the contract instance ---\n\ntype ReadMethods<C extends AbiContract> = {\n\t[N in ExtractReadOnlyFunctions<C> as ToCamelCase<N>]: (\n\t\targs: ExtractFunctionArgs<C, N>,\n\t) => Promise<ReadMethodReturn<C, N>>;\n};\n\ntype CallMethods<C extends AbiContract> = {\n\t[N in ExtractPublicFunctions<C> as ToCamelCase<N>]: (\n\t\targs: ExtractFunctionArgs<C, N>,\n\t\toptions?: ContractCallOptions,\n\t) => Promise<string>;\n};\n\ntype MapMethods<C extends AbiContract> = {\n\t[N in ExtractMapNames<C> as ToCamelCase<N>]: (\n\t\tkey: ExtractMapKey<C, N>,\n\t) => Promise<ExtractMapValue<C, N> | null>;\n};\n\nexport type ContractCallOptions = {\n\tfee?: IntegerType;\n\tnonce?: IntegerType;\n\tpostConditionMode?: \"allow\" | \"deny\";\n\tpostConditions?: PostCondition[];\n};\n\nexport type ContractInstance<C extends AbiContract> = {\n\tread: ReadMethods<C>;\n\tcall: CallMethods<C>;\n\tmaps: MapMethods<C>;\n};\n\nexport type GetContractParams<C extends AbiContract> = {\n\tclient: Client;\n\taddress: string;\n\tname: string;\n\tabi: C;\n};\n\nexport function getContract<const TAbi extends AbiContract>(\n\tparams: GetContractParams<TAbi>,\n): ContractInstance<TAbi> {\n\tconst { client, address, name: contractName, abi } = params;\n\tconst contractId = `${address}.${contractName}`;\n\n\t// Index functions/maps by name for fast lookup\n\tconst fnByName = new Map<string, AbiFunction>();\n\tfor (const fn of abi.functions) {\n\t\tfnByName.set(fn.name, fn as AbiFunction);\n\t}\n\n\tconst mapByName = new Map<string, AbiMap>();\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tmapByName.set(m.name, m as AbiMap);\n\t\t}\n\t}\n\n\t// Build kebab→camel reverse map for function/map names\n\tconst camelToKebab = new Map<string, string>();\n\tfor (const fn of abi.functions) {\n\t\tcamelToKebab.set(toCamelCase(fn.name), fn.name);\n\t}\n\tif (abi.maps) {\n\t\tfor (const m of abi.maps) {\n\t\t\tcamelToKebab.set(toCamelCase(m.name), m.name);\n\t\t}\n\t}\n\n\tconst read = new Proxy({} as ReadMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"read-only\") return undefined;\n\n\t\t\treturn async (args: Record<string, unknown>) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\tconst result = await readContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\targs: clarityArgs,\n\t\t\t\t});\n\n\t\t\t\tconst jsValue = clarityValueToJSUntyped(fn.outputs as AbiType, result);\n\n\t\t\t\t// Auto-unwrap: if output is response type, unwrap ok / throw on err\n\t\t\t\tif (isResponseOutput(fn.outputs as AbiType)) {\n\t\t\t\t\tconst resp = jsValue as { ok?: unknown; err?: unknown };\n\t\t\t\t\tif (\"ok\" in resp) return resp.ok;\n\t\t\t\t\tthrow new ContractResponseError(\n\t\t\t\t\t\t`${contractId}::${fn.name} returned (err ${formatErrValue(resp.err)})`,\n\t\t\t\t\t\tresp.err,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn jsValue;\n\t\t\t};\n\t\t},\n\t});\n\n\tconst call = new Proxy({} as CallMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst fnName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst fn = fnByName.get(fnName);\n\t\t\tif (!fn || fn.access !== \"public\") return undefined;\n\n\t\t\treturn async (\n\t\t\t\targs: Record<string, unknown>,\n\t\t\t\toptions?: ContractCallOptions,\n\t\t\t) => {\n\t\t\t\tconst clarityArgs = buildFunctionArgs(fn, args);\n\t\t\t\treturn callContract(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tfunctionName: fn.name,\n\t\t\t\t\tfunctionArgs: clarityArgs,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t};\n\t\t},\n\t});\n\n\tconst maps = new Proxy({} as MapMethods<TAbi>, {\n\t\tget(_target, prop: string) {\n\t\t\tconst mapName = camelToKebab.get(prop) ?? prop;\n\t\t\tconst map = mapByName.get(mapName);\n\t\t\tif (!map) return undefined;\n\n\t\t\treturn async (key: unknown) => {\n\t\t\t\tconst clarityKey = jsToClarityValue(map.key as AbiType, key);\n\t\t\t\tconst result = await getMapEntry(client, {\n\t\t\t\t\tcontract: contractId,\n\t\t\t\t\tmapName: map.name,\n\t\t\t\t\tkey: clarityKey,\n\t\t\t\t});\n\n\t\t\t\t// Map entries come back as (optional ...). If none, return null.\n\t\t\t\tif (result.type === \"none\") return null;\n\t\t\t\tif (result.type === \"some\") {\n\t\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result.value);\n\t\t\t\t}\n\t\t\t\t// Direct value (shouldn't normally happen, but handle gracefully)\n\t\t\t\treturn clarityValueToJSUntyped(map.value as AbiType, result);\n\t\t\t};\n\t\t},\n\t});\n\n\treturn { read, call, maps };\n}\n\n// --- Helpers ---\n\nfunction buildFunctionArgs(\n\tfn: AbiFunction,\n\targs: Record<string, unknown>,\n): ClarityValue[] {\n\treturn fn.args.map((arg) => {\n\t\tconst camelKey = toCamelCase(arg.name);\n\t\tconst hasOriginal = arg.name in args;\n\t\tconst hasCamel = camelKey in args;\n\t\tconst value = hasOriginal\n\t\t\t? args[arg.name]\n\t\t\t: hasCamel\n\t\t\t\t? args[camelKey]\n\t\t\t\t: undefined;\n\t\tif (value === undefined) throw new Error(`Missing argument: ${arg.name}`);\n\t\treturn jsToClarityValue(arg.type as AbiType, value);\n\t});\n}\n\nfunction isResponseOutput(type: AbiType): boolean {\n\treturn typeof type === \"object\" && type !== null && \"response\" in type;\n}\n\nfunction formatErrValue(value: unknown): string {\n\tif (typeof value === \"bigint\") return value.toString();\n\tif (typeof value === \"string\") return `\"${value}\"`;\n\treturn String(value);\n}\n\nexport class ContractResponseError extends Error {\n\toverride name = \"ContractResponseError\";\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly errorValue: unknown,\n\t) {\n\t\tsuper(message);\n\t}\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
7
|
+
"mappings": ";AA6EO,SAAS,WAA2C,CAC1D,QACyB;AAAA,EACzB,QAAQ,QAAQ,SAAS,MAAM,cAAc,QAAQ;AAAA,EACrD,MAAM,aAAa,GAAG,WAAW;AAAA,EAGjC,MAAM,WAAW,IAAI;AAAA,EACrB,WAAW,MAAM,IAAI,WAAW;AAAA,IAC/B,SAAS,IAAI,GAAG,MAAM,EAAiB;AAAA,EACxC;AAAA,EAEA,MAAM,YAAY,IAAI;AAAA,EACtB,IAAI,IAAI,MAAM;AAAA,IACb,WAAW,KAAK,IAAI,MAAM;AAAA,MACzB,UAAU,IAAI,EAAE,MAAM,CAAW;AAAA,IAClC;AAAA,EACD;AAAA,EAGA,MAAM,eAAe,IAAI;AAAA,EACzB,WAAW,MAAM,IAAI,WAAW;AAAA,IAC/B,aAAa,IAAI,YAAY,GAAG,IAAI,GAAG,GAAG,IAAI;AAAA,EAC/C;AAAA,EACA,IAAI,IAAI,MAAM;AAAA,IACb,WAAW,KAAK,IAAI,MAAM;AAAA,MACzB,aAAa,IAAI,YAAY,EAAE,IAAI,GAAG,EAAE,IAAI;AAAA,IAC7C;AAA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,OAAO,UAAU;AAAA,IAAU,OAAO,MAAM,SAAS;AAAA,EACrD,IAAI,OAAO,UAAU;AAAA,IAAU,OAAO,IAAI;AAAA,EAC1C,OAAO,OAAO,KAAK;AAAA;AAAA;AAGb,MAAM,8BAA8B,MAAM;AAAA,EAI/B;AAAA,EAHR,OAAO;AAAA,EAChB,WAAW,CACV,SACgB,YACf;AAAA,IACD,MAAM,OAAO;AAAA,IAFG;AAAA;AAIlB;",
|
|
8
8
|
"debugId": "044399D0C01FC46B64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -128,7 +128,7 @@ function serializeCV(value) {
|
|
|
128
128
|
return bytesToHex(serializeCVBytes(value));
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
// src/
|
|
131
|
+
// src/utils/bytes-reader.ts
|
|
132
132
|
class BytesReader {
|
|
133
133
|
data;
|
|
134
134
|
offset = 0;
|
|
@@ -136,21 +136,33 @@ class BytesReader {
|
|
|
136
136
|
this.data = data;
|
|
137
137
|
}
|
|
138
138
|
readUInt8() {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
return this.data[this.offset++];
|
|
140
|
+
}
|
|
141
|
+
readUInt16BE() {
|
|
142
|
+
const val = (this.data[this.offset] << 8 | this.data[this.offset + 1]) >>> 0;
|
|
143
|
+
this.offset += 2;
|
|
144
|
+
return val;
|
|
142
145
|
}
|
|
143
146
|
readUInt32BE() {
|
|
144
|
-
const
|
|
147
|
+
const val = (this.data[this.offset] << 24 | this.data[this.offset + 1] << 16 | this.data[this.offset + 2] << 8 | this.data[this.offset + 3]) >>> 0;
|
|
145
148
|
this.offset += 4;
|
|
146
|
-
return
|
|
149
|
+
return val;
|
|
147
150
|
}
|
|
148
151
|
readBytes(length) {
|
|
152
|
+
if (this.offset + length > this.data.length) {
|
|
153
|
+
throw new Error(`Buffer underflow: need ${length} bytes at offset ${this.offset}, have ${this.data.length}`);
|
|
154
|
+
}
|
|
149
155
|
const slice = this.data.slice(this.offset, this.offset + length);
|
|
150
156
|
this.offset += length;
|
|
151
157
|
return slice;
|
|
152
158
|
}
|
|
159
|
+
readBigUInt64BE() {
|
|
160
|
+
const hex = bytesToHex(this.readBytes(8));
|
|
161
|
+
return hex.length > 0 ? BigInt(`0x${hex}`) : 0n;
|
|
162
|
+
}
|
|
153
163
|
}
|
|
164
|
+
|
|
165
|
+
// src/clarity/deserialize.ts
|
|
154
166
|
function readAddress(reader) {
|
|
155
167
|
const version = reader.readUInt8();
|
|
156
168
|
const hash160 = bytesToHex(reader.readBytes(20));
|
|
@@ -340,7 +352,7 @@ var Cl = {
|
|
|
340
352
|
deserialize: deserializeCVBytes
|
|
341
353
|
};
|
|
342
354
|
|
|
343
|
-
export { ClarityWireType, clarityTypeFromByte, serializeCVBytes, serializeCV, intCV, uintCV, trueCV, falseCV, boolCV, bufferCV, standardPrincipalCV, contractPrincipalCV, noneCV, someCV, responseOkCV, responseErrorCV, listCV, tupleCV, stringAsciiCV, stringUtf8CV, Cl, deserializeCVBytes, deserializeCV };
|
|
355
|
+
export { ClarityWireType, clarityTypeFromByte, serializeCVBytes, serializeCV, BytesReader, intCV, uintCV, trueCV, falseCV, boolCV, bufferCV, standardPrincipalCV, contractPrincipalCV, noneCV, someCV, responseOkCV, responseErrorCV, listCV, tupleCV, stringAsciiCV, stringUtf8CV, Cl, readAddress, readLPString, readCV, deserializeCVBytes, deserializeCV };
|
|
344
356
|
|
|
345
|
-
//# debugId=
|
|
346
|
-
//# sourceMappingURL=stacks-
|
|
357
|
+
//# debugId=D00820D9453409D864756E2164756E21
|
|
358
|
+
//# sourceMappingURL=stacks-wjem3xw9.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/clarity/types.ts", "../src/clarity/serialize.ts", "../src/utils/bytes-reader.ts", "../src/clarity/deserialize.ts", "../src/clarity/values.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"export type ClarityType =\n\t| \"int\"\n\t| \"uint\"\n\t| \"buffer\"\n\t| \"true\"\n\t| \"false\"\n\t| \"address\"\n\t| \"contract\"\n\t| \"ok\"\n\t| \"err\"\n\t| \"none\"\n\t| \"some\"\n\t| \"list\"\n\t| \"tuple\"\n\t| \"ascii\"\n\t| \"utf8\";\n\n/** Wire type IDs matching the Stacks binary format (SIP-005) */\nexport const ClarityWireType = {\n\tint: 0x00,\n\tuint: 0x01,\n\tbuffer: 0x02,\n\ttrue: 0x03,\n\tfalse: 0x04,\n\taddress: 0x05,\n\tcontract: 0x06,\n\tok: 0x07,\n\terr: 0x08,\n\tnone: 0x09,\n\tsome: 0x0a,\n\tlist: 0x0b,\n\ttuple: 0x0c,\n\tascii: 0x0d,\n\tutf8: 0x0e,\n} as const satisfies Record<ClarityType, number>;\n\n/** Reverse lookup: wire byte → ClarityType string */\nconst wireTypeToClarity = Object.fromEntries(\n\tObject.entries(ClarityWireType).map(([k, v]) => [v, k]),\n) as Record<number, ClarityType>;\n\nexport function clarityTypeFromByte(byte: number): ClarityType {\n\tconst type = wireTypeToClarity[byte];\n\tif (!type) throw new Error(`Unknown clarity wire type: ${byte}`);\n\treturn type;\n}\n\n// CV types\n\nexport type IntCV = { readonly type: \"int\"; readonly value: bigint };\nexport type UIntCV = { readonly type: \"uint\"; readonly value: bigint };\nexport type BooleanCV = TrueCV | FalseCV;\nexport type TrueCV = { readonly type: \"true\" };\nexport type FalseCV = { readonly type: \"false\" };\nexport type BufferCV = { readonly type: \"buffer\"; readonly value: string }; // hex\nexport type NoneCV = { readonly type: \"none\" };\nexport type SomeCV = {\n\treadonly type: \"some\";\n\treadonly value: ClarityValue;\n};\nexport type OptionalCV = NoneCV | SomeCV;\nexport type ResponseOkCV = {\n\treadonly type: \"ok\";\n\treadonly value: ClarityValue;\n};\nexport type ResponseErrorCV = {\n\treadonly type: \"err\";\n\treadonly value: ClarityValue;\n};\nexport type ResponseCV = ResponseOkCV | ResponseErrorCV;\nexport type StandardPrincipalCV = {\n\treadonly type: \"address\";\n\treadonly value: string;\n};\nexport type ContractPrincipalCV = {\n\treadonly type: \"contract\";\n\treadonly value: string; // \"address.name\"\n};\nexport type PrincipalCV = StandardPrincipalCV | ContractPrincipalCV;\nexport type ListCV = {\n\ttype: \"list\";\n\tvalue: ClarityValue[];\n};\nexport type TupleData = {\n\t[key: string]: ClarityValue;\n};\nexport type TupleCV = {\n\ttype: \"tuple\";\n\tvalue: TupleData;\n};\nexport type StringAsciiCV = {\n\treadonly type: \"ascii\";\n\treadonly value: string;\n};\nexport type StringUtf8CV = {\n\treadonly type: \"utf8\";\n\treadonly value: string;\n};\n\nexport type ClarityValue =\n\t| IntCV\n\t| UIntCV\n\t| BooleanCV\n\t| BufferCV\n\t| NoneCV\n\t| SomeCV\n\t| ResponseOkCV\n\t| ResponseErrorCV\n\t| StandardPrincipalCV\n\t| ContractPrincipalCV\n\t| ListCV\n\t| TupleCV\n\t| StringAsciiCV\n\t| StringUtf8CV;\n",
|
|
6
|
+
"import { c32addressDecode } from \"../utils/c32.ts\";\nimport {\n\tasciiToBytes,\n\tbigIntToBytes,\n\tbytesToHex,\n\tconcatBytes,\n\thexToBytes,\n\tintToHex,\n\ttoTwos,\n\tutf8ToBytes,\n\twriteUInt32BE,\n} from \"../utils/encoding.ts\";\nimport {\n\ttype ClarityType,\n\ttype ClarityValue,\n\tClarityWireType,\n} from \"./types.ts\";\n\nconst CLARITY_INT_SIZE = 128n;\nconst CLARITY_INT_BYTE_SIZE = 16;\n\nfunction typeIdByte(type: ClarityType): number {\n\treturn ClarityWireType[type];\n}\n\nfunction withTypeId(type: ClarityType, bytes: Uint8Array): Uint8Array {\n\treturn concatBytes(new Uint8Array([typeIdByte(type)]), bytes);\n}\n\nfunction serializeAddress(c32Address: string): Uint8Array {\n\tconst [version, hash160] = c32addressDecode(c32Address);\n\treturn concatBytes(new Uint8Array([version]), hexToBytes(hash160));\n}\n\nfunction serializeLPString(str: string, prefixBytes = 1): Uint8Array {\n\tconst content = utf8ToBytes(str);\n\tconst lengthPrefix = hexToBytes(intToHex(content.byteLength, prefixBytes));\n\treturn concatBytes(lengthPrefix, content);\n}\n\nexport function serializeCVBytes(value: ClarityValue): Uint8Array {\n\tswitch (value.type) {\n\t\tcase \"true\":\n\t\tcase \"false\":\n\t\t\treturn new Uint8Array([typeIdByte(value.type)]);\n\n\t\tcase \"int\": {\n\t\t\tconst bytes = bigIntToBytes(\n\t\t\t\ttoTwos(BigInt(value.value), CLARITY_INT_SIZE),\n\t\t\t\tCLARITY_INT_BYTE_SIZE,\n\t\t\t);\n\t\t\treturn withTypeId(value.type, bytes);\n\t\t}\n\n\t\tcase \"uint\": {\n\t\t\tconst bytes = bigIntToBytes(BigInt(value.value), CLARITY_INT_BYTE_SIZE);\n\t\t\treturn withTypeId(value.type, bytes);\n\t\t}\n\n\t\tcase \"buffer\": {\n\t\t\tconst bufBytes = hexToBytes(value.value);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(writeUInt32BE(bufBytes.length), bufBytes),\n\t\t\t);\n\t\t}\n\n\t\tcase \"none\":\n\t\t\treturn new Uint8Array([typeIdByte(value.type)]);\n\n\t\tcase \"some\":\n\t\t\treturn withTypeId(value.type, serializeCVBytes(value.value));\n\n\t\tcase \"ok\":\n\t\tcase \"err\":\n\t\t\treturn withTypeId(value.type, serializeCVBytes(value.value));\n\n\t\tcase \"address\":\n\t\t\treturn withTypeId(value.type, serializeAddress(value.value));\n\n\t\tcase \"contract\": {\n\t\t\tconst [addr, name] = value.value.split(\".\");\n\t\t\tif (!addr || !name)\n\t\t\t\tthrow new Error(`Invalid contract principal: ${value.value}`);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(serializeAddress(addr), serializeLPString(name)),\n\t\t\t);\n\t\t}\n\n\t\tcase \"list\": {\n\t\t\tconst parts: Uint8Array[] = [writeUInt32BE(value.value.length)];\n\t\t\tfor (const item of value.value) {\n\t\t\t\tparts.push(serializeCVBytes(item));\n\t\t\t}\n\t\t\treturn withTypeId(value.type, concatBytes(...parts));\n\t\t}\n\n\t\tcase \"tuple\": {\n\t\t\tconst keys = Object.keys(value.value).sort((a, b) => a.localeCompare(b));\n\t\t\tconst parts: Uint8Array[] = [writeUInt32BE(keys.length)];\n\t\t\tfor (const key of keys) {\n\t\t\t\tparts.push(serializeLPString(key));\n\t\t\t\tparts.push(serializeCVBytes(value.value[key]!));\n\t\t\t}\n\t\t\treturn withTypeId(value.type, concatBytes(...parts));\n\t\t}\n\n\t\tcase \"ascii\": {\n\t\t\tconst strBytes = asciiToBytes(value.value);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(writeUInt32BE(strBytes.length), strBytes),\n\t\t\t);\n\t\t}\n\n\t\tcase \"utf8\": {\n\t\t\tconst strBytes = utf8ToBytes(value.value);\n\t\t\treturn withTypeId(\n\t\t\t\tvalue.type,\n\t\t\t\tconcatBytes(writeUInt32BE(strBytes.length), strBytes),\n\t\t\t);\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot serialize unknown clarity type`);\n\t}\n}\n\nexport function serializeCV(value: ClarityValue): string {\n\treturn bytesToHex(serializeCVBytes(value));\n}\n",
|
|
7
|
+
"import { bytesToHex } from \"./encoding.ts\";\n\nexport class BytesReader {\n\tprivate data: Uint8Array;\n\tpublic offset = 0;\n\n\tconstructor(data: Uint8Array) {\n\t\tthis.data = data;\n\t}\n\n\treadUInt8(): number {\n\t\treturn this.data[this.offset++]!;\n\t}\n\n\treadUInt16BE(): number {\n\t\tconst val =\n\t\t\t((this.data[this.offset]! << 8) | this.data[this.offset + 1]!) >>> 0;\n\t\tthis.offset += 2;\n\t\treturn val;\n\t}\n\n\treadUInt32BE(): number {\n\t\tconst val =\n\t\t\t((this.data[this.offset]! << 24) |\n\t\t\t\t(this.data[this.offset + 1]! << 16) |\n\t\t\t\t(this.data[this.offset + 2]! << 8) |\n\t\t\t\tthis.data[this.offset + 3]!) >>>\n\t\t\t0;\n\t\tthis.offset += 4;\n\t\treturn val;\n\t}\n\n\treadBytes(length: number): Uint8Array {\n\t\tif (this.offset + length > this.data.length) {\n\t\t\tthrow new Error(\n\t\t\t\t`Buffer underflow: need ${length} bytes at offset ${this.offset}, have ${this.data.length}`,\n\t\t\t);\n\t\t}\n\t\tconst slice = this.data.slice(this.offset, this.offset + length);\n\t\tthis.offset += length;\n\t\treturn slice;\n\t}\n\n\treadBigUInt64BE(): bigint {\n\t\tconst hex = bytesToHex(this.readBytes(8));\n\t\treturn hex.length > 0 ? BigInt(`0x${hex}`) : 0n;\n\t}\n}\n",
|
|
8
|
+
"import { BytesReader } from \"../utils/bytes-reader.ts\";\nimport { c32address } from \"../utils/c32.ts\";\nimport {\n\tbytesToAscii,\n\tbytesToHex,\n\tbytesToTwosBigInt,\n\tbytesToUtf8,\n\thexToBytes,\n\twithout0x,\n} from \"../utils/encoding.ts\";\nimport { type ClarityValue, clarityTypeFromByte } from \"./types.ts\";\nimport {\n\tbufferCV,\n\tcontractPrincipalCV,\n\tfalseCV,\n\tintCV,\n\tlistCV,\n\tnoneCV,\n\tresponseErrorCV,\n\tresponseOkCV,\n\tsomeCV,\n\tstandardPrincipalCV,\n\tstringAsciiCV,\n\tstringUtf8CV,\n\ttrueCV,\n\ttupleCV,\n\tuintCV,\n} from \"./values.ts\";\n\nexport function readAddress(reader: BytesReader): string {\n\tconst version = reader.readUInt8();\n\tconst hash160 = bytesToHex(reader.readBytes(20));\n\treturn c32address(version, hash160);\n}\n\nexport function readLPString(reader: BytesReader, prefixBytes = 1): string {\n\tlet length = 0;\n\tfor (let i = 0; i < prefixBytes; i++) {\n\t\tlength = (length << 8) | reader.readUInt8();\n\t}\n\treturn bytesToUtf8(reader.readBytes(length));\n}\n\nexport function readCV(reader: BytesReader): ClarityValue {\n\tconst typeByte = reader.readUInt8();\n\tconst type = clarityTypeFromByte(typeByte);\n\n\tswitch (type) {\n\t\tcase \"int\":\n\t\t\treturn intCV(bytesToTwosBigInt(reader.readBytes(16)));\n\n\t\tcase \"uint\":\n\t\t\treturn uintCV(reader.readBytes(16));\n\n\t\tcase \"true\":\n\t\t\treturn trueCV();\n\n\t\tcase \"false\":\n\t\t\treturn falseCV();\n\n\t\tcase \"buffer\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\treturn bufferCV(reader.readBytes(len));\n\t\t}\n\n\t\tcase \"none\":\n\t\t\treturn noneCV();\n\n\t\tcase \"some\":\n\t\t\treturn someCV(readCV(reader));\n\n\t\tcase \"ok\":\n\t\t\treturn responseOkCV(readCV(reader));\n\n\t\tcase \"err\":\n\t\t\treturn responseErrorCV(readCV(reader));\n\n\t\tcase \"address\":\n\t\t\treturn standardPrincipalCV(readAddress(reader));\n\n\t\tcase \"contract\": {\n\t\t\tconst addr = readAddress(reader);\n\t\t\tconst name = readLPString(reader);\n\t\t\treturn contractPrincipalCV(addr, name);\n\t\t}\n\n\t\tcase \"list\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\tconst items: ClarityValue[] = [];\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\titems.push(readCV(reader));\n\t\t\t}\n\t\t\treturn listCV(items);\n\t\t}\n\n\t\tcase \"tuple\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\tconst data: Record<string, ClarityValue> = {};\n\t\t\tfor (let i = 0; i < len; i++) {\n\t\t\t\tconst key = readLPString(reader);\n\t\t\t\tdata[key] = readCV(reader);\n\t\t\t}\n\t\t\treturn tupleCV(data);\n\t\t}\n\n\t\tcase \"ascii\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\treturn stringAsciiCV(bytesToAscii(reader.readBytes(len)));\n\t\t}\n\n\t\tcase \"utf8\": {\n\t\t\tconst len = reader.readUInt32BE();\n\t\t\treturn stringUtf8CV(bytesToUtf8(reader.readBytes(len)));\n\t\t}\n\n\t\tdefault:\n\t\t\tthrow new Error(`Cannot deserialize unknown clarity type: ${type}`);\n\t}\n}\n\nexport function deserializeCVBytes<T extends ClarityValue = ClarityValue>(\n\tinput: Uint8Array | string,\n): T {\n\tconst bytes =\n\t\ttypeof input === \"string\" ? hexToBytes(without0x(input)) : input;\n\treturn readCV(new BytesReader(bytes)) as T;\n}\n\nexport function deserializeCV<T extends ClarityValue = ClarityValue>(\n\tinput: Uint8Array | string,\n): T {\n\treturn deserializeCVBytes(input);\n}\n",
|
|
9
|
+
"import { isClarityName } from \"../utils/address.ts\";\nimport { c32address, c32addressDecode } from \"../utils/c32.ts\";\nimport {\n\ttype IntegerType,\n\tasciiToBytes,\n\tbytesToHex,\n\tbytesToTwosBigInt,\n\thexToBytes,\n\tintToBigInt,\n\tutf8ToBytes,\n} from \"../utils/encoding.ts\";\nimport { deserializeCVBytes } from \"./deserialize.ts\";\nimport { serializeCVBytes } from \"./serialize.ts\";\nimport type {\n\tBooleanCV,\n\tBufferCV,\n\tClarityValue,\n\tContractPrincipalCV,\n\tFalseCV,\n\tIntCV,\n\tListCV,\n\tNoneCV,\n\tResponseErrorCV,\n\tResponseOkCV,\n\tSomeCV,\n\tStandardPrincipalCV,\n\tStringAsciiCV,\n\tStringUtf8CV,\n\tTrueCV,\n\tTupleCV,\n\tTupleData,\n\tUIntCV,\n} from \"./types.ts\";\n\nconst MAX_U128 = BigInt(\"0xffffffffffffffffffffffffffffffff\");\nconst MIN_I128 = BigInt(\"-170141183460469231731687303715884105728\");\nconst MAX_I128 = BigInt(\"0x7fffffffffffffffffffffffffffffff\");\n\n// Primitives\n\nexport function intCV(value: IntegerType): IntCV {\n\tif (typeof value === \"string\" && value.toLowerCase().startsWith(\"0x\")) {\n\t\tvalue = bytesToTwosBigInt(hexToBytes(value));\n\t}\n\tif (value instanceof Uint8Array) value = bytesToTwosBigInt(value);\n\tconst n = intToBigInt(value);\n\tif (n > MAX_I128) throw new RangeError(`Int exceeds max i128: ${MAX_I128}`);\n\tif (n < MIN_I128) throw new RangeError(`Int below min i128: ${MIN_I128}`);\n\treturn { type: \"int\", value: n };\n}\n\nexport function uintCV(value: IntegerType): UIntCV {\n\tconst n = intToBigInt(value);\n\tif (n < 0n)\n\t\tthrow new RangeError(\"Cannot construct unsigned int from negative value\");\n\tif (n > MAX_U128) throw new RangeError(`UInt exceeds max u128: ${MAX_U128}`);\n\treturn { type: \"uint\", value: n };\n}\n\nexport const trueCV = (): TrueCV => ({ type: \"true\" });\nexport const falseCV = (): FalseCV => ({ type: \"false\" });\nexport const boolCV = (v: boolean): BooleanCV => (v ? trueCV() : falseCV());\n\nexport function bufferCV(buffer: Uint8Array): BufferCV {\n\tif (buffer.byteLength > 1_048_576) {\n\t\tthrow new Error(\"Buffer exceeds max size of 1MB\");\n\t}\n\treturn { type: \"buffer\", value: bytesToHex(buffer) };\n}\n\nexport function standardPrincipalCV(address: string): StandardPrincipalCV {\n\t// Validate by decoding\n\tconst [version, hash160] = c32addressDecode(address);\n\tconst normalized = c32address(version, hash160);\n\treturn { type: \"address\", value: normalized };\n}\n\nexport function contractPrincipalCV(\n\taddress: string,\n\tcontractName: string,\n): ContractPrincipalCV {\n\tconst [version, hash160] = c32addressDecode(address);\n\tconst normalized = c32address(version, hash160);\n\tif (utf8ToBytes(contractName).byteLength >= 128) {\n\t\tthrow new Error(\"Contract name must be less than 128 bytes\");\n\t}\n\treturn { type: \"contract\", value: `${normalized}.${contractName}` };\n}\n\nexport function noneCV(): NoneCV {\n\treturn { type: \"none\" };\n}\n\nexport function someCV(value: ClarityValue): SomeCV {\n\treturn { type: \"some\", value };\n}\n\nexport function responseOkCV(value: ClarityValue): ResponseOkCV {\n\treturn { type: \"ok\", value };\n}\n\nexport function responseErrorCV(value: ClarityValue): ResponseErrorCV {\n\treturn { type: \"err\", value };\n}\n\nexport function listCV(values: ClarityValue[]): ListCV {\n\treturn { type: \"list\", value: values };\n}\n\nexport function tupleCV(data: TupleData): TupleCV {\n\tfor (const key in data) {\n\t\tif (!isClarityName(key)) {\n\t\t\tthrow new Error(`\"${key}\" is not a valid Clarity name`);\n\t\t}\n\t}\n\treturn { type: \"tuple\", value: data };\n}\n\nexport function stringAsciiCV(value: string): StringAsciiCV {\n\treturn { type: \"ascii\", value };\n}\n\nexport function stringUtf8CV(value: string): StringUtf8CV {\n\treturn { type: \"utf8\", value };\n}\n\n// Cl namespace — clean API\n\nexport const Cl: {\n\treadonly int: (value: IntegerType) => IntCV;\n\treadonly uint: (value: IntegerType) => UIntCV;\n\treadonly bool: (v: boolean) => BooleanCV;\n\tprincipal(address: string): StandardPrincipalCV | ContractPrincipalCV;\n\taddress(address: string): StandardPrincipalCV | ContractPrincipalCV;\n\treadonly contractPrincipal: (\n\t\taddress: string,\n\t\tcontractName: string,\n\t) => ContractPrincipalCV;\n\treadonly standardPrincipal: (address: string) => StandardPrincipalCV;\n\treadonly buffer: (buffer: Uint8Array) => BufferCV;\n\treadonly bufferFromHex: (hex: string) => BufferCV;\n\treadonly bufferFromAscii: (ascii: string) => BufferCV;\n\treadonly bufferFromUtf8: (utf8: string) => BufferCV;\n\treadonly none: () => NoneCV;\n\treadonly some: (value: ClarityValue) => SomeCV;\n\treadonly ok: (value: ClarityValue) => ResponseOkCV;\n\treadonly error: (value: ClarityValue) => ResponseErrorCV;\n\treadonly list: (values: ClarityValue[]) => ListCV;\n\treadonly tuple: (data: TupleData) => TupleCV;\n\treadonly stringAscii: (value: string) => StringAsciiCV;\n\treadonly stringUtf8: (value: string) => StringUtf8CV;\n\tserialize(value: ClarityValue): string;\n\treadonly deserialize: (bytes: Uint8Array) => ClarityValue;\n} = {\n\tint: intCV,\n\tuint: uintCV,\n\tbool: boolCV,\n\tprincipal(address: string): StandardPrincipalCV | ContractPrincipalCV {\n\t\tconst [addr, name] = address.split(\".\");\n\t\tif (!addr) throw new Error(\"Invalid principal address\");\n\t\treturn name ? contractPrincipalCV(addr, name) : standardPrincipalCV(addr);\n\t},\n\taddress(address: string): StandardPrincipalCV | ContractPrincipalCV {\n\t\treturn Cl.principal(address);\n\t},\n\tcontractPrincipal: contractPrincipalCV,\n\tstandardPrincipal: standardPrincipalCV,\n\tbuffer: bufferCV,\n\tbufferFromHex: (hex: string): BufferCV => bufferCV(hexToBytes(hex)),\n\tbufferFromAscii: (ascii: string): BufferCV => bufferCV(asciiToBytes(ascii)),\n\tbufferFromUtf8: (utf8: string): BufferCV => bufferCV(utf8ToBytes(utf8)),\n\tnone: noneCV,\n\tsome: someCV,\n\tok: responseOkCV,\n\terror: responseErrorCV,\n\tlist: listCV,\n\ttuple: tupleCV,\n\tstringAscii: stringAsciiCV,\n\tstringUtf8: stringUtf8CV,\n\tserialize(value: ClarityValue): string {\n\t\treturn bytesToHex(serializeCVBytes(value));\n\t},\n\tdeserialize: deserializeCVBytes,\n} as const;\n"
|
|
10
|
+
],
|
|
11
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAM,kBAAkB;AAAA,EAC9B,KAAK;AAAA,EACL,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AAAA,EACT,UAAU;AAAA,EACV,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,MAAM;AACP;AAGA,IAAM,oBAAoB,OAAO,YAChC,OAAO,QAAQ,eAAe,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CACvD;AAEO,SAAS,mBAAmB,CAAC,MAA2B;AAAA,EAC9D,MAAM,OAAO,kBAAkB;AAAA,EAC/B,IAAI,CAAC;AAAA,IAAM,MAAM,IAAI,MAAM,8BAA8B,MAAM;AAAA,EAC/D,OAAO;AAAA;;;AC1BR,IAAM,mBAAmB;AACzB,IAAM,wBAAwB;AAE9B,SAAS,UAAU,CAAC,MAA2B;AAAA,EAC9C,OAAO,gBAAgB;AAAA;AAGxB,SAAS,UAAU,CAAC,MAAmB,OAA+B;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I,IAAI,oBAAoB,IAAI;AAAA;AAAA,EAEzE,OAAO,CAAC,SAA4D;AAAA,IACnE,OAAO,GAAG,UAAU,OAAO;AAAA;AAAA,EAE5B,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,QAAQ;AAAA,EACR,eAAe,CAAC,QAA0B,SAAS,WAAW,GAAG,CAAC;AAAA,EAClE,iBAAiB,CAAC,UAA4B,SAAS,aAAa,KAAK,CAAC;AAAA,EAC1E,gBAAgB,CAAC,SAA2B,SAAS,YAAY,IAAI,CAAC;AAAA,EACtE,MAAM;AAAA,EACN,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,SAAS,CAAC,OAA6B;AAAA,IACtC,OAAO,WAAW,iBAAiB,KAAK,CAAC;AAAA;AAAA,EAE1C,aAAa;AACd;",
|
|
12
|
+
"debugId": "D00820D9453409D864756E2164756E21",
|
|
13
|
+
"names": []
|
|
14
|
+
}
|
|
@@ -189,7 +189,7 @@ function clarityValueToJSInner(abiType, cv) {
|
|
|
189
189
|
const hex = cv.value;
|
|
190
190
|
const bytes = new Uint8Array(hex.length / 2);
|
|
191
191
|
for (let i = 0;i < bytes.length; i++) {
|
|
192
|
-
bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
192
|
+
bytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
193
193
|
}
|
|
194
194
|
return bytes;
|
|
195
195
|
}
|
|
@@ -228,5 +228,5 @@ function clarityValueToJSInner(abiType, cv) {
|
|
|
228
228
|
throw new Error(`Unknown ABI type: ${JSON.stringify(abiType)}`);
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
-
//# debugId=
|
|
232
|
-
//# sourceMappingURL=stacks-
|
|
231
|
+
//# debugId=758D772BF3E061A664756E2164756E21
|
|
232
|
+
//# sourceMappingURL=stacks-wyxj879g.cjs.map
|
|
@@ -0,0 +1,13 @@
|
|
|
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\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\tconst address = parts[0]!;\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\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\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/**\n * Convert a JS value to a ClarityValue using ABI type information.\n */\nexport function jsToClarityValue(\n\tabiType: AbiType,\n\tvalue: unknown,\n): ClarityValue {\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\tif (isAbiBuffer(abiType)) return bufferCV(value as Uint8Array);\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;AA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GAAG;AAAA,IACxB,IAAI,GAAG,SAAS;AAAA,MACf,MAAM,IAAI,MAAM,0BAA0B,GAAG,MAAM;AAAA,IACpD,MAAM,SAAkC,CAAC;AAAA,IACzC,WAAW,SAAS,QAAQ,OAAO;AAAA,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": "758D772BF3E061A664756E2164756E21",
|
|
12
|
+
"names": []
|
|
13
|
+
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/errors/websocket.ts", "../src/subscriptions/actions.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { BaseError } from \"./base.ts\";\n\nexport class WebSocketError extends BaseError {\n
|
|
6
|
-
"import type { Client } from \"../clients/types.ts\";\nimport type { WebSocketTransport } from \"../transports/webSocket.ts\";\nimport type {\n
|
|
5
|
+
"import { BaseError } from \"./base.ts\";\n\nexport class WebSocketError extends BaseError {\n\toverride name = \"WebSocketError\";\n\n\tconstructor(message: string, options?: { cause?: Error; details?: string }) {\n\t\tsuper(message, options);\n\t}\n}\n",
|
|
6
|
+
"import type { Client } from \"../clients/types.ts\";\nimport { WebSocketError } from \"../errors/websocket.ts\";\nimport type { WebSocketTransport } from \"../transports/webSocket.ts\";\nimport type {\n\tAddressBalanceNotification,\n\tAddressTxNotification,\n\tBlockNotification,\n\tMempoolNotification,\n\tNftEventNotification,\n\tSubscription,\n\tTxUpdateNotification,\n} from \"./types.ts\";\n\nfunction getWsTransport(client: Client): WebSocketTransport {\n\tif (client.transport.type !== \"webSocket\") {\n\t\tthrow new WebSocketError(\n\t\t\t\"Watch actions require a webSocket transport. Use `webSocket()` when creating your client.\",\n\t\t);\n\t}\n\treturn client.transport as WebSocketTransport;\n}\n\nexport type WatchBlocksParams = {\n\tonBlock: (block: BlockNotification) => void;\n};\n\nexport async function watchBlocks(\n\tclient: Client,\n\tparams: WatchBlocksParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe({ event: \"block\" }, params.onBlock);\n}\n\nexport type WatchMempoolParams = {\n\tonTransaction: (tx: MempoolNotification) => void;\n};\n\nexport async function watchMempool(\n\tclient: Client,\n\tparams: WatchMempoolParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe({ event: \"mempool\" }, params.onTransaction);\n}\n\nexport type WatchTransactionParams = {\n\ttxId: string;\n\tonUpdate: (update: TxUpdateNotification) => void;\n};\n\nexport async function watchTransaction(\n\tclient: Client,\n\tparams: WatchTransactionParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"tx_update\", tx_id: params.txId },\n\t\tparams.onUpdate,\n\t);\n}\n\nexport type WatchAddressParams = {\n\taddress: string;\n\tonTransaction: (tx: AddressTxNotification) => void;\n};\n\nexport async function watchAddress(\n\tclient: Client,\n\tparams: WatchAddressParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"address_tx_update\", address: params.address },\n\t\tparams.onTransaction,\n\t);\n}\n\nexport type WatchAddressBalanceParams = {\n\taddress: string;\n\tonBalance: (balance: AddressBalanceNotification) => void;\n};\n\nexport async function watchAddressBalance(\n\tclient: Client,\n\tparams: WatchAddressBalanceParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\treturn transport.subscribe(\n\t\t{ event: \"address_balance_update\", address: params.address },\n\t\tparams.onBalance,\n\t);\n}\n\nexport type WatchNftEventParams = {\n\tonEvent: (event: NftEventNotification) => void;\n\tassetIdentifier?: string;\n\tvalue?: string;\n};\n\nexport async function watchNftEvent(\n\tclient: Client,\n\tparams: WatchNftEventParams,\n): Promise<Subscription> {\n\tconst transport = getWsTransport(client);\n\n\tlet event: \"nft_event\" | \"nft_asset_event\" | \"nft_collection_event\";\n\tif (params.assetIdentifier && params.value) {\n\t\tevent = \"nft_event\";\n\t} else if (params.assetIdentifier) {\n\t\tevent = \"nft_collection_event\";\n\t} else {\n\t\tevent = \"nft_event\";\n\t}\n\n\treturn transport.subscribe(\n\t\t{\n\t\t\tevent,\n\t\t\tasset_identifier: params.assetIdentifier,\n\t\t\tvalue: params.value,\n\t\t},\n\t\tparams.onEvent,\n\t);\n}\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": ";;;;;AAEO,MAAM,uBAAuB,UAAU;AAAA,
|
|
8
|
+
"mappings": ";;;;;AAEO,MAAM,uBAAuB,UAAU;AAAA,EACpC,OAAO;AAAA,EAEhB,WAAW,CAAC,SAAiB,SAA+C;AAAA,IAC3E,MAAM,SAAS,OAAO;AAAA;AAExB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IACC;AAAA,IACA,kBAAkB,OAAO;AAAA,IACzB,OAAO,OAAO;AAAA,EACf,GACA,OAAO,OACR;AAAA;",
|
|
9
9
|
"debugId": "1EA8C0F2045E5C9564756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -117,7 +117,10 @@ function cvToJSON(val) {
|
|
|
117
117
|
case "uint":
|
|
118
118
|
return { type: "uint", value: val.value.toString() };
|
|
119
119
|
case "buffer":
|
|
120
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
type: `(buff ${Math.ceil(val.value.length / 2)})`,
|
|
122
|
+
value: `0x${val.value}`
|
|
123
|
+
};
|
|
121
124
|
case "none":
|
|
122
125
|
return { type: "(optional none)", value: null };
|
|
123
126
|
case "some":
|
|
@@ -139,9 +142,15 @@ function cvToJSON(val) {
|
|
|
139
142
|
return { type: "(tuple)", value: result };
|
|
140
143
|
}
|
|
141
144
|
case "ascii":
|
|
142
|
-
return {
|
|
145
|
+
return {
|
|
146
|
+
type: `(string-ascii ${asciiToBytes(val.value).length})`,
|
|
147
|
+
value: val.value
|
|
148
|
+
};
|
|
143
149
|
case "utf8":
|
|
144
|
-
return {
|
|
150
|
+
return {
|
|
151
|
+
type: `(string-utf8 ${utf8ToBytes(val.value).length})`,
|
|
152
|
+
value: val.value
|
|
153
|
+
};
|
|
145
154
|
}
|
|
146
155
|
}
|
|
147
156
|
function cvToValue(val) {
|
|
@@ -324,5 +333,5 @@ function validateArgsArray(func, args) {
|
|
|
324
333
|
});
|
|
325
334
|
}
|
|
326
335
|
|
|
327
|
-
//# debugId=
|
|
328
|
-
//# sourceMappingURL=stacks-
|
|
336
|
+
//# debugId=E549A79634B2E0BE64756E2164756E21
|
|
337
|
+
//# sourceMappingURL=stacks-y5262j0z.cjs.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/clarity/prettyPrint.ts", "../src/clarity/abi/converters.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import {\n\tasciiToBytes,\n\tbytesToAscii,\n\thexToBytes,\n\tutf8ToBytes,\n} from \"../utils/encoding.ts\";\nimport type { ClarityValue } from \"./types.ts\";\n\nexport function prettyPrint(\n\tval: ClarityValue,\n\tencoding: \"tryAscii\" | \"hex\" = \"hex\",\n): string | undefined {\n\tswitch (val.type) {\n\t\tcase \"true\":\n\t\t\treturn \"true\";\n\t\tcase \"false\":\n\t\t\treturn \"false\";\n\t\tcase \"int\":\n\t\t\treturn val.value.toString();\n\t\tcase \"uint\":\n\t\t\treturn `u${val.value.toString()}`;\n\t\tcase \"buffer\":\n\t\t\tif (encoding === \"tryAscii\") {\n\t\t\t\tconst str = bytesToAscii(hexToBytes(val.value));\n\t\t\t\tif (/^[ -~]*$/.test(str)) return JSON.stringify(str);\n\t\t\t}\n\t\t\treturn `0x${val.value}`;\n\t\tcase \"none\":\n\t\t\treturn \"none\";\n\t\tcase \"some\":\n\t\t\treturn `(some ${prettyPrint(val.value, encoding)})`;\n\t\tcase \"ok\":\n\t\t\treturn `(ok ${prettyPrint(val.value, encoding)})`;\n\t\tcase \"err\":\n\t\t\treturn `(err ${prettyPrint(val.value, encoding)})`;\n\t\tcase \"address\":\n\t\tcase \"contract\":\n\t\t\treturn val.value;\n\t\tcase \"list\":\n\t\t\treturn `(list ${val.value.map((v) => prettyPrint(v, encoding)).join(\" \")})`;\n\t\tcase \"tuple\":\n\t\t\treturn `(tuple ${Object.keys(val.value)\n\t\t\t\t.map((key) => `(${key} ${prettyPrint(val.value[key]!, encoding)})`)\n\t\t\t\t.join(\" \")})`;\n\t\tcase \"ascii\":\n\t\t\treturn `\"${val.value}\"`;\n\t\tcase \"utf8\":\n\t\t\treturn `u\"${val.value}\"`;\n\t}\n}\n\nexport function cvToJSON(val: ClarityValue): any {\n\tswitch (val.type) {\n\t\tcase \"true\":\n\t\t\treturn { type: \"bool\", value: true };\n\t\tcase \"false\":\n\t\t\treturn { type: \"bool\", value: false };\n\t\tcase \"int\":\n\t\t\treturn { type: \"int\", value: val.value.toString() };\n\t\tcase \"uint\":\n\t\t\treturn { type: \"uint\", value: val.value.toString() };\n\t\tcase \"buffer\":\n\t\t\treturn {\n\t\t\t\ttype: `(buff ${Math.ceil(val.value.length / 2)})`,\n\t\t\t\tvalue: `0x${val.value}`,\n\t\t\t};\n\t\tcase \"none\":\n\t\t\treturn { type: \"(optional none)\", value: null };\n\t\tcase \"some\":\n\t\t\treturn { type: `(optional)`, value: cvToJSON(val.value) };\n\t\tcase \"ok\":\n\t\t\treturn { type: \"(response)\", value: cvToJSON(val.value), success: true };\n\t\tcase \"err\":\n\t\t\treturn { type: \"(response)\", value: cvToJSON(val.value), success: false };\n\t\tcase \"address\":\n\t\tcase \"contract\":\n\t\t\treturn { type: \"principal\", value: val.value };\n\t\tcase \"list\":\n\t\t\treturn { type: \"(list)\", value: val.value.map(cvToJSON) };\n\t\tcase \"tuple\": {\n\t\t\tconst result: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(val.value)) {\n\t\t\t\tresult[key] = cvToJSON(val.value[key]!);\n\t\t\t}\n\t\t\treturn { type: \"(tuple)\", value: result };\n\t\t}\n\t\tcase \"ascii\":\n\t\t\treturn {\n\t\t\t\ttype: `(string-ascii ${asciiToBytes(val.value).length})`,\n\t\t\t\tvalue: val.value,\n\t\t\t};\n\t\tcase \"utf8\":\n\t\t\treturn {\n\t\t\t\ttype: `(string-utf8 ${utf8ToBytes(val.value).length})`,\n\t\t\t\tvalue: val.value,\n\t\t\t};\n\t}\n}\n\nexport function cvToValue(val: ClarityValue): any {\n\tswitch (val.type) {\n\t\tcase \"true\":\n\t\t\treturn true;\n\t\tcase \"false\":\n\t\t\treturn false;\n\t\tcase \"int\":\n\t\tcase \"uint\":\n\t\t\treturn val.value;\n\t\tcase \"buffer\":\n\t\t\treturn `0x${val.value}`;\n\t\tcase \"none\":\n\t\t\treturn null;\n\t\tcase \"some\":\n\t\t\treturn cvToValue(val.value);\n\t\tcase \"ok\":\n\t\tcase \"err\":\n\t\t\treturn cvToValue(val.value);\n\t\tcase \"address\":\n\t\tcase \"contract\":\n\t\t\treturn val.value;\n\t\tcase \"list\":\n\t\t\treturn val.value.map(cvToValue);\n\t\tcase \"tuple\": {\n\t\t\tconst result: Record<string, any> = {};\n\t\t\tfor (const key of Object.keys(val.value)) {\n\t\t\t\tresult[key] = cvToValue(val.value[key]!);\n\t\t\t}\n\t\t\treturn result;\n\t\t}\n\t\tcase \"ascii\":\n\t\tcase \"utf8\":\n\t\t\treturn val.value;\n\t}\n}\n",
|
|
6
|
+
"import type { AbiFunction } from \"./contract.ts\";\nimport {\n\tisAbiBuffer,\n\tisAbiList,\n\tisAbiOptional,\n\tisAbiResponse,\n\tisAbiStringAscii,\n\tisAbiStringUtf8,\n\tisAbiTuple,\n\tisBool,\n\tisInt128,\n\tisPrincipal,\n\tisString,\n\tisUint8Array,\n\tisUint128,\n} from \"./guards.ts\";\nimport type { AbiType } from \"./types.ts\";\nimport { toCamelCase } from \"./utils.ts\";\n\nexport class ClarityConversionError extends Error {\n\tconstructor(\n\t\tmessage: string,\n\t\tpublic readonly type: AbiType,\n\t\tpublic readonly value: unknown,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"ClarityConversionError\";\n\t}\n}\n\nexport function jsToClarity(type: AbiType, value: unknown): unknown {\n\tif (type === \"none\") return null;\n\n\tif (type === \"uint128\") {\n\t\tif (!isUint128(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid uint128 value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"int128\") {\n\t\tif (!isInt128(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid int128 value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"bool\") {\n\t\tif (!isBool(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid bool value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"principal\") {\n\t\tif (!isPrincipal(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid principal value\", type, value);\n\t\treturn value;\n\t}\n\n\tif (type === \"trait_reference\") {\n\t\tif (!isPrincipal(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Invalid trait_reference value\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\treturn value;\n\t}\n\n\tif (isAbiStringAscii(type)) {\n\t\tif (!isString(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Invalid string-ascii value\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst str = value as string;\n\t\tfor (let i = 0; i < str.length; i++) {\n\t\t\tif (str.charCodeAt(i) > 127) {\n\t\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\t`Non-ASCII character at position ${i}: '${str[i]}' (code ${str.charCodeAt(i)})`,\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (str.length > type[\"string-ascii\"].length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`String length ${str.length} exceeds max ${type[\"string-ascii\"].length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (isAbiStringUtf8(type)) {\n\t\tif (!isString(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Invalid string-utf8 value\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst str = value as string;\n\t\tconst byteLength = new TextEncoder().encode(str).length;\n\t\tif (byteLength > type[\"string-utf8\"].length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`String byte length ${byteLength} exceeds max ${type[\"string-utf8\"].length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (isAbiBuffer(type)) {\n\t\tif (!isUint8Array(value))\n\t\t\tthrow new ClarityConversionError(\"Invalid buffer value\", type, value);\n\t\tconst buff = value as Uint8Array;\n\t\tif (buff.length > type.buff.length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`Buffer length ${buff.length} exceeds max ${type.buff.length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (isAbiList(type)) {\n\t\tif (!Array.isArray(value))\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Expected array for list type\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tif (value.length > type.list.length) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`List length ${value.length} exceeds max ${type.list.length}`,\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t}\n\t\treturn value.map((item) => jsToClarity(type.list.type, item));\n\t}\n\n\tif (isAbiTuple(type)) {\n\t\tif (typeof value !== \"object\" || value === null)\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Expected object for tuple type\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst result: Record<string, unknown> = {};\n\t\tfor (const field of type.tuple) {\n\t\t\tconst camelKey = toCamelCase(field.name);\n\t\t\tconst hasOriginal = field.name in (value as object);\n\t\t\tconst hasCamel = camelKey in (value as object);\n\t\t\tif (!hasOriginal && !hasCamel) {\n\t\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\t`Missing tuple field: ${field.name}`,\n\t\t\t\t\ttype,\n\t\t\t\t\tvalue,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fieldValue = hasOriginal\n\t\t\t\t? (value as Record<string, unknown>)[field.name]\n\t\t\t\t: (value as Record<string, unknown>)[camelKey];\n\t\t\tresult[field.name] = jsToClarity(field.type, fieldValue);\n\t\t}\n\t\treturn result;\n\t}\n\n\tif (isAbiOptional(type)) {\n\t\tif (value === null || value === undefined) return null;\n\t\treturn jsToClarity(type.optional, value);\n\t}\n\n\tif (isAbiResponse(type)) {\n\t\tif (typeof value !== \"object\" || value === null)\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t\"Expected object for response type\",\n\t\t\t\ttype,\n\t\t\t\tvalue,\n\t\t\t);\n\t\tconst hasOk = \"ok\" in value;\n\t\tconst hasErr = \"err\" in value;\n\t\tif (hasOk && !hasErr) {\n\t\t\treturn {\n\t\t\t\tok: jsToClarity(type.response.ok, (value as { ok: unknown }).ok),\n\t\t\t};\n\t\t}\n\t\tif (hasErr && !hasOk) {\n\t\t\treturn {\n\t\t\t\terr: jsToClarity(type.response.error, (value as { err: unknown }).err),\n\t\t\t};\n\t\t}\n\t\tthrow new ClarityConversionError(\n\t\t\t\"Response must have exactly 'ok' or 'err' property\",\n\t\t\ttype,\n\t\t\tvalue,\n\t\t);\n\t}\n\n\tthrow new ClarityConversionError(`Unknown Clarity type`, type, value);\n}\n\nexport function prepareArgs<F extends AbiFunction>(\n\tfunc: F,\n\targs: Record<string, unknown>,\n): unknown[] {\n\treturn func.args.map((arg) => {\n\t\tif (!(arg.name in args)) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`Missing argument: ${arg.name}`,\n\t\t\t\targ.type,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t}\n\t\treturn jsToClarity(arg.type, args[arg.name]);\n\t});\n}\n\nexport function validateArgs<F extends AbiFunction>(\n\tfunc: F,\n\targs: Record<string, unknown>,\n): void {\n\tfor (const arg of func.args) {\n\t\tif (!(arg.name in args)) {\n\t\t\tthrow new ClarityConversionError(\n\t\t\t\t`Missing argument: ${arg.name}`,\n\t\t\t\targ.type,\n\t\t\t\tundefined,\n\t\t\t);\n\t\t}\n\t\tjsToClarity(arg.type, args[arg.name]);\n\t}\n}\n\nexport function validateArgsArray<F extends AbiFunction>(\n\tfunc: F,\n\targs: unknown[],\n): void {\n\tif (args.length !== func.args.length) {\n\t\tthrow new ClarityConversionError(\n\t\t\t`Expected ${func.args.length} arguments, got ${args.length}`,\n\t\t\tfunc.args[0]?.type ?? \"bool\",\n\t\t\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J,SACD;AAAA,IACD;AAAA,IACA,OAAO,YAAY,IAAI,MAAM,KAAK,IAAI,KAAK;AAAA,GAC3C;AAAA;AAGK,SAAS,YAAmC,CAClD,MACA,MACO;AAAA,EACP,WAAW,OAAO,KAAK,MAAM;AAAA,IAC5B,IAAI,EAAE,IAAI,QAAQ,OAAO;AAAA,MACxB,MAAM,IAAI,uBACT,qBAAqB,IAAI,QACzB,IAAI,MACJ,SACD;AAAA,IACD;AAAA,IACA,YAAY,IAAI,MAAM,KAAK,IAAI,KAAK;AAAA,EACrC;AAAA;AAGM,SAAS,iBAAwC,CACvD,MACA,MACO;AAAA,EACP,IAAI,KAAK,WAAW,KAAK,KAAK,QAAQ;AAAA,IACrC,MAAM,IAAI,uBACT,YAAY,KAAK,KAAK,yBAAyB,KAAK,UACpD,KAAK,KAAK,IAAI,QAAQ,QACtB,IACD;AAAA,EACD;AAAA,EACA,KAAK,KAAK,QAAQ,CAAC,KAAK,MAAM;AAAA,IAC7B,YAAY,IAAI,MAAM,KAAK,EAAE;AAAA,GAC7B;AAAA;",
|
|
9
|
+
"debugId": "E549A79634B2E0BE64756E2164756E21",
|
|
10
|
+
"names": []
|
|
11
|
+
}
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils/constants.ts"],
|
|
4
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
|
|
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
6
|
],
|
|
7
|
-
"mappings": ";AACO,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,YAAoB,MAAM,QAAQ;AACxC,IAAM,WAAmB,EAAE,MAAM;AAGjC,IAAM,iBAAiB;AAAA,
|
|
7
|
+
"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;",
|
|
8
8
|
"debugId": "B42A43BFB28E5FFC64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
stringUtf8CV,
|
|
13
13
|
tupleCV,
|
|
14
14
|
uintCV
|
|
15
|
-
} from "./stacks-
|
|
15
|
+
} from "./stacks-wjem3xw9.js";
|
|
16
16
|
import {
|
|
17
17
|
MAX_I128,
|
|
18
18
|
MAX_U128,
|
|
@@ -213,7 +213,7 @@ function clarityValueToJSInner(abiType, cv) {
|
|
|
213
213
|
const hex = cv.value;
|
|
214
214
|
const bytes = new Uint8Array(hex.length / 2);
|
|
215
215
|
for (let i = 0;i < bytes.length; i++) {
|
|
216
|
-
bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
216
|
+
bytes[i] = Number.parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
217
217
|
}
|
|
218
218
|
return bytes;
|
|
219
219
|
}
|
|
@@ -254,5 +254,5 @@ function clarityValueToJSInner(abiType, cv) {
|
|
|
254
254
|
|
|
255
255
|
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, jsToClarityValue, clarityValueToJS, clarityValueToJSUntyped };
|
|
256
256
|
|
|
257
|
-
//# debugId=
|
|
258
|
-
//# sourceMappingURL=stacks-
|
|
257
|
+
//# debugId=295B2BA1DC85445964756E2164756E21
|
|
258
|
+
//# sourceMappingURL=stacks-zf7rbpzp.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
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\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\tconst address = parts[0]!;\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\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\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/**\n * Convert a JS value to a ClarityValue using ABI type information.\n */\nexport function jsToClarityValue(\n\tabiType: AbiType,\n\tvalue: unknown,\n): ClarityValue {\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\tif (isAbiBuffer(abiType)) return bufferCV(value as Uint8Array);\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,EAC7B,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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