@secondlayer/stacks 6.0.0 → 6.1.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 (153) hide show
  1. package/dist/shared/{stacks-qt8ehebn.js → stacks-esm-0rdxcta7.js} +2 -2
  2. package/dist/shared/{stacks-qt8ehebn.js.map → stacks-esm-0rdxcta7.js.map} +1 -1
  3. package/dist/shared/{stacks-4hs8r4q2.js → stacks-esm-1jae0a3r.js} +2 -2
  4. package/dist/shared/{stacks-xjkn3en1.cjs.map → stacks-esm-1jae0a3r.js.map} +1 -1
  5. package/dist/shared/{stacks-4d7c3x27.js → stacks-esm-2mc7ebrm.js} +3 -3
  6. package/dist/shared/{stacks-4d7c3x27.js.map → stacks-esm-2mc7ebrm.js.map} +1 -1
  7. package/dist/shared/{stacks-8brgfvqx.js → stacks-esm-3g33bqsm.js} +4 -4
  8. package/dist/shared/{stacks-8brgfvqx.js.map → stacks-esm-3g33bqsm.js.map} +1 -1
  9. package/dist/shared/{stacks-gjz26k6b.js → stacks-esm-3pv5avgr.js} +59 -15
  10. package/dist/shared/stacks-esm-3pv5avgr.js.map +12 -0
  11. package/dist/shared/{stacks-qex691bh.js → stacks-esm-743jfh10.js} +6 -6
  12. package/dist/shared/{stacks-qex691bh.js.map → stacks-esm-743jfh10.js.map} +1 -1
  13. package/dist/shared/{stacks-wxfd6r4b.js → stacks-esm-7fpqgtyx.js} +3 -3
  14. package/dist/shared/{stacks-wxfd6r4b.js.map → stacks-esm-7fpqgtyx.js.map} +1 -1
  15. package/dist/shared/{stacks-71k0vmct.js → stacks-esm-9rnx0zxr.js} +5 -5
  16. package/dist/shared/{stacks-71k0vmct.js.map → stacks-esm-9rnx0zxr.js.map} +1 -1
  17. package/dist/shared/{stacks-fd4rx56e.js → stacks-esm-aw2mj3sj.js} +7 -7
  18. package/dist/shared/{stacks-fd4rx56e.js.map → stacks-esm-aw2mj3sj.js.map} +1 -1
  19. package/dist/shared/{stacks-qs5fzts5.js → stacks-esm-cvhazvhd.js} +2 -2
  20. package/dist/shared/{stacks-qs5fzts5.js.map → stacks-esm-cvhazvhd.js.map} +1 -1
  21. package/dist/shared/{stacks-69nq48jp.js → stacks-esm-fcfdn2zx.js} +5 -5
  22. package/dist/shared/{stacks-69nq48jp.js.map → stacks-esm-fcfdn2zx.js.map} +1 -1
  23. package/dist/shared/{stacks-x0qqwrev.js → stacks-esm-hr7fpxtj.js} +4 -4
  24. package/dist/shared/{stacks-x0qqwrev.js.map → stacks-esm-hr7fpxtj.js.map} +1 -1
  25. package/dist/shared/{stacks-mbt36bzt.js → stacks-esm-kds4n82p.js} +11 -11
  26. package/dist/shared/{stacks-mbt36bzt.js.map → stacks-esm-kds4n82p.js.map} +1 -1
  27. package/dist/shared/{stacks-kg1npstf.js → stacks-esm-n53kvwmt.js} +2 -2
  28. package/dist/shared/{stacks-kg1npstf.js.map → stacks-esm-n53kvwmt.js.map} +1 -1
  29. package/dist/shared/{stacks-v2rfr46a.js → stacks-esm-pxhfqfff.js} +4 -4
  30. package/dist/shared/{stacks-v2rfr46a.js.map → stacks-esm-pxhfqfff.js.map} +1 -1
  31. package/dist/shared/{stacks-yajyej2y.js → stacks-esm-q19a17fd.js} +3 -3
  32. package/dist/shared/{stacks-yajyej2y.js.map → stacks-esm-q19a17fd.js.map} +1 -1
  33. package/dist/shared/{stacks-v03zef3g.js → stacks-esm-qk0p9fr6.js} +9 -9
  34. package/dist/shared/{stacks-v03zef3g.js.map → stacks-esm-qk0p9fr6.js.map} +1 -1
  35. package/dist/shared/{stacks-qcae5852.js → stacks-esm-qkj67g80.js} +2 -2
  36. package/dist/shared/{stacks-qcae5852.js.map → stacks-esm-qkj67g80.js.map} +1 -1
  37. package/dist/shared/{stacks-mftyrc60.js → stacks-esm-r6dejrgr.js} +4 -4
  38. package/dist/shared/{stacks-mftyrc60.js.map → stacks-esm-r6dejrgr.js.map} +1 -1
  39. package/dist/shared/{stacks-9c1yam8b.js → stacks-esm-r9q4wnyw.js} +5 -5
  40. package/dist/shared/{stacks-9c1yam8b.js.map → stacks-esm-r9q4wnyw.js.map} +1 -1
  41. package/dist/shared/{stacks-51ybf135.js → stacks-esm-skmcf5n2.js} +5 -5
  42. package/dist/shared/{stacks-51ybf135.js.map → stacks-esm-skmcf5n2.js.map} +1 -1
  43. package/dist/shared/{stacks-yvb7rvwk.js → stacks-esm-v45990hx.js} +2 -2
  44. package/dist/shared/{stacks-8vzxax5e.cjs.map → stacks-esm-v45990hx.js.map} +1 -1
  45. package/dist/shared/{stacks-z90xdr1x.js → stacks-esm-wv67m4g6.js} +3 -3
  46. package/dist/shared/{stacks-z90xdr1x.js.map → stacks-esm-wv67m4g6.js.map} +1 -1
  47. package/dist/shared/{stacks-1m3m1agc.js → stacks-esm-x1r01353.js} +5 -5
  48. package/dist/shared/{stacks-1m3m1agc.js.map → stacks-esm-x1r01353.js.map} +1 -1
  49. package/dist/src/accounts/index.cjs +558 -4
  50. package/dist/src/accounts/index.cjs.map +10 -4
  51. package/dist/src/accounts/index.js +3 -3
  52. package/dist/src/actions/index.cjs +3815 -1
  53. package/dist/src/actions/index.cjs.map +65 -3
  54. package/dist/src/actions/index.js +14 -14
  55. package/dist/src/bitcoin/index.cjs +2477 -1
  56. package/dist/src/bitcoin/index.cjs.map +31 -3
  57. package/dist/src/bitcoin/index.js +11 -11
  58. package/dist/src/bns/index.cjs +4439 -17
  59. package/dist/src/bns/index.cjs.map +50 -3
  60. package/dist/src/bns/index.js +14 -14
  61. package/dist/src/chains/index.cjs +135 -1
  62. package/dist/src/chains/index.cjs.map +5 -3
  63. package/dist/src/chains/index.js +1 -1
  64. package/dist/src/clarity/index.cjs +2019 -1
  65. package/dist/src/clarity/index.cjs.map +24 -3
  66. package/dist/src/clarity/index.js +8 -8
  67. package/dist/src/filters/index.cjs +725 -1
  68. package/dist/src/filters/index.cjs.map +11 -3
  69. package/dist/src/filters/index.d.cts +76 -13
  70. package/dist/src/filters/index.d.ts +76 -13
  71. package/dist/src/filters/index.js +8 -4
  72. package/dist/src/filters/index.js.map +1 -1
  73. package/dist/src/index.cjs +3935 -62
  74. package/dist/src/index.cjs.map +69 -4
  75. package/dist/src/index.d.cts +62 -11
  76. package/dist/src/index.d.ts +62 -11
  77. package/dist/src/index.js +16 -16
  78. package/dist/src/postconditions/index.cjs +1726 -1
  79. package/dist/src/postconditions/index.cjs.map +20 -3
  80. package/dist/src/postconditions/index.js +6 -6
  81. package/dist/src/pox/index.cjs +3855 -1
  82. package/dist/src/pox/index.cjs.map +48 -3
  83. package/dist/src/pox/index.js +13 -13
  84. package/dist/src/pox5/index.cjs +4054 -29
  85. package/dist/src/pox5/index.cjs.map +54 -3
  86. package/dist/src/pox5/index.js +15 -15
  87. package/dist/src/sbtc/index.cjs +3705 -4
  88. package/dist/src/sbtc/index.cjs.map +47 -3
  89. package/dist/src/sbtc/index.js +12 -12
  90. package/dist/src/stackingdao/index.cjs +3751 -8
  91. package/dist/src/stackingdao/index.cjs.map +45 -3
  92. package/dist/src/stackingdao/index.js +12 -12
  93. package/dist/src/subscriptions/index.cjs +153 -1
  94. package/dist/src/subscriptions/index.cjs.map +6 -3
  95. package/dist/src/subscriptions/index.js +2 -2
  96. package/dist/src/transactions/index.cjs +2139 -1
  97. package/dist/src/transactions/index.cjs.map +23 -3
  98. package/dist/src/transactions/index.js +6 -6
  99. package/dist/src/utils/index.cjs +435 -3
  100. package/dist/src/utils/index.cjs.map +9 -3
  101. package/dist/src/utils/index.js +3 -3
  102. package/package.json +1 -1
  103. package/dist/shared/stacks-02actsrx.cjs +0 -17
  104. package/dist/shared/stacks-02actsrx.cjs.map +0 -10
  105. package/dist/shared/stacks-03vfm21t.cjs +0 -222
  106. package/dist/shared/stacks-03vfm21t.cjs.map +0 -12
  107. package/dist/shared/stacks-24h5k94q.cjs +0 -74
  108. package/dist/shared/stacks-24h5k94q.cjs.map +0 -11
  109. package/dist/shared/stacks-37kz5t9f.cjs +0 -764
  110. package/dist/shared/stacks-37kz5t9f.cjs.map +0 -23
  111. package/dist/shared/stacks-3mt2q2na.cjs +0 -65
  112. package/dist/shared/stacks-3mt2q2na.cjs.map +0 -9
  113. package/dist/shared/stacks-4hs8r4q2.js.map +0 -10
  114. package/dist/shared/stacks-8vzxax5e.cjs +0 -45
  115. package/dist/shared/stacks-agk106zs.cjs +0 -267
  116. package/dist/shared/stacks-agk106zs.cjs.map +0 -12
  117. package/dist/shared/stacks-bdgh9n83.cjs +0 -212
  118. package/dist/shared/stacks-bdgh9n83.cjs.map +0 -11
  119. package/dist/shared/stacks-dpxnxhqb.cjs +0 -51
  120. package/dist/shared/stacks-dpxnxhqb.cjs.map +0 -11
  121. package/dist/shared/stacks-ee53k9j2.cjs +0 -651
  122. package/dist/shared/stacks-ee53k9j2.cjs.map +0 -13
  123. package/dist/shared/stacks-enpj9krt.cjs +0 -38
  124. package/dist/shared/stacks-enpj9krt.cjs.map +0 -10
  125. package/dist/shared/stacks-f35mnrmg.cjs +0 -164
  126. package/dist/shared/stacks-f35mnrmg.cjs.map +0 -10
  127. package/dist/shared/stacks-fhzwsn5d.cjs +0 -261
  128. package/dist/shared/stacks-fhzwsn5d.cjs.map +0 -12
  129. package/dist/shared/stacks-gjz26k6b.js.map +0 -12
  130. package/dist/shared/stacks-gza2n1zs.cjs +0 -73
  131. package/dist/shared/stacks-gza2n1zs.cjs.map +0 -11
  132. package/dist/shared/stacks-kem68d80.cjs +0 -156
  133. package/dist/shared/stacks-kem68d80.cjs.map +0 -10
  134. package/dist/shared/stacks-n98w7g57.cjs +0 -234
  135. package/dist/shared/stacks-n98w7g57.cjs.map +0 -10
  136. package/dist/shared/stacks-p337hp6m.cjs +0 -336
  137. package/dist/shared/stacks-p337hp6m.cjs.map +0 -25
  138. package/dist/shared/stacks-q34k4vnc.cjs +0 -286
  139. package/dist/shared/stacks-q34k4vnc.cjs.map +0 -12
  140. package/dist/shared/stacks-rryme9bv.cjs +0 -569
  141. package/dist/shared/stacks-rryme9bv.cjs.map +0 -13
  142. package/dist/shared/stacks-s5vej5z6.cjs +0 -410
  143. package/dist/shared/stacks-s5vej5z6.cjs.map +0 -15
  144. package/dist/shared/stacks-sdqkapct.cjs +0 -67
  145. package/dist/shared/stacks-sdqkapct.cjs.map +0 -12
  146. package/dist/shared/stacks-vea7nde7.cjs +0 -731
  147. package/dist/shared/stacks-vea7nde7.cjs.map +0 -13
  148. package/dist/shared/stacks-wk8yp13j.cjs +0 -33
  149. package/dist/shared/stacks-wk8yp13j.cjs.map +0 -11
  150. package/dist/shared/stacks-xjkn3en1.cjs +0 -42
  151. package/dist/shared/stacks-xnrywjf1.cjs +0 -131
  152. package/dist/shared/stacks-xnrywjf1.cjs.map +0 -11
  153. package/dist/shared/stacks-yvb7rvwk.js.map +0 -10
@@ -1,651 +0,0 @@
1
- // src/clarity/index.ts
2
- var exports_clarity = {};
3
- __export(exports_clarity, {
4
- validateArgsArray: () => validateArgsArray,
5
- validateArgs: () => validateArgs,
6
- uintCV: () => uintCV,
7
- tupleCV: () => tupleCV,
8
- trueCV: () => trueCV,
9
- toCamelCase: () => toCamelCase,
10
- structuredDataHash: () => structuredDataHash,
11
- stringUtf8CV: () => stringUtf8CV,
12
- stringAsciiCV: () => stringAsciiCV,
13
- standardPrincipalCV: () => standardPrincipalCV,
14
- someCV: () => someCV,
15
- sip013Abi: () => sip013Abi,
16
- sip010Abi: () => sip010Abi,
17
- sip009Abi: () => sip009Abi,
18
- signStructuredData: () => signStructuredData,
19
- serializeCVBytes: () => serializeCVBytes,
20
- serializeCV: () => serializeCV,
21
- responseOkCV: () => responseOkCV,
22
- responseErrorCV: () => responseErrorCV,
23
- prettyPrint: () => prettyPrint,
24
- prepareArgs: () => prepareArgs,
25
- parseDeclaredStandards: () => parseDeclaredStandards,
26
- normalizeType: () => normalizeType,
27
- normalizeAccess: () => normalizeAccess,
28
- normalizeAbi: () => normalizeAbi,
29
- noneCV: () => noneCV,
30
- listCV: () => listCV,
31
- jsToClarityValue: () => jsToClarityValue,
32
- jsToClarity: () => jsToClarity,
33
- isUint8Array: () => isUint8Array,
34
- isUint128: () => isUint128,
35
- isTraitReference: () => isTraitReference,
36
- isString: () => isString,
37
- isStandardPrincipal: () => isStandardPrincipal,
38
- isResponse: () => isResponse,
39
- isPrincipal: () => isPrincipal,
40
- isOptional: () => isOptional,
41
- isOkResponse: () => isOkResponse,
42
- isInt128: () => isInt128,
43
- isErrResponse: () => isErrResponse,
44
- isContractPrincipal: () => isContractPrincipal,
45
- isClarityValue: () => isClarityValue,
46
- isBool: () => isBool,
47
- isArray: () => isArray,
48
- isAbiTuple: () => isAbiTuple,
49
- isAbiTraitReference: () => isAbiTraitReference,
50
- isAbiStringUtf8: () => isAbiStringUtf8,
51
- isAbiStringAscii: () => isAbiStringAscii,
52
- isAbiResponse: () => isAbiResponse,
53
- isAbiOptional: () => isAbiOptional,
54
- isAbiList: () => isAbiList,
55
- isAbiBuffer: () => isAbiBuffer,
56
- intCV: () => intCV,
57
- hashStructuredData: () => hashStructuredData,
58
- falseCV: () => falseCV,
59
- encodeStructuredData: () => encodeStructuredData,
60
- deserializeCVBytes: () => deserializeCVBytes,
61
- deserializeCV: () => deserializeCV,
62
- cvToValue: () => cvToValue,
63
- cvToString: () => cvToString,
64
- cvToPrincipal: () => cvToPrincipal,
65
- cvToJSON: () => cvToJSON,
66
- cvToBuffer: () => cvToBuffer,
67
- cvToBoolean: () => cvToBoolean,
68
- cvToBigInt: () => cvToBigInt,
69
- contractPrincipalCV: () => contractPrincipalCV,
70
- classifyContract: () => classifyContract,
71
- clarityValueToJSUntyped: () => clarityValueToJSUntyped,
72
- clarityValueToJS: () => clarityValueToJS,
73
- clarityTypeFromByte: () => clarityTypeFromByte,
74
- bufferCV: () => bufferCV,
75
- boolCV: () => boolCV,
76
- TRAIT_STANDARDS: () => TRAIT_STANDARDS,
77
- SIP018_PREFIX: () => SIP018_PREFIX,
78
- SIP013_ABI: () => SIP013_ABI,
79
- SIP010_ABI: () => SIP010_ABI,
80
- SIP009_ABI: () => SIP009_ABI,
81
- ClarityWireType: () => ClarityWireType,
82
- ClarityConversionError: () => ClarityConversionError,
83
- Cl: () => Cl,
84
- CONTRACT_NAME_REGEX: () => CONTRACT_NAME_REGEX
85
- });
86
- module.exports = __toCommonJS(exports_clarity);
87
-
88
- // src/clarity/prettyPrint.ts
89
- function prettyPrint(val, encoding = "hex") {
90
- switch (val.type) {
91
- case "true":
92
- return "true";
93
- case "false":
94
- return "false";
95
- case "int":
96
- return val.value.toString();
97
- case "uint":
98
- return `u${val.value.toString()}`;
99
- case "buffer":
100
- if (encoding === "tryAscii") {
101
- const str = bytesToAscii(hexToBytes(val.value));
102
- if (/^[ -~]*$/.test(str))
103
- return JSON.stringify(str);
104
- }
105
- return `0x${val.value}`;
106
- case "none":
107
- return "none";
108
- case "some":
109
- return `(some ${prettyPrint(val.value, encoding)})`;
110
- case "ok":
111
- return `(ok ${prettyPrint(val.value, encoding)})`;
112
- case "err":
113
- return `(err ${prettyPrint(val.value, encoding)})`;
114
- case "address":
115
- case "contract":
116
- return val.value;
117
- case "list":
118
- return `(list ${val.value.map((v) => prettyPrint(v, encoding)).join(" ")})`;
119
- case "tuple":
120
- return `(tuple ${Object.keys(val.value).map((key) => `(${key} ${prettyPrint(val.value[key], encoding)})`).join(" ")})`;
121
- case "ascii":
122
- return `"${val.value}"`;
123
- case "utf8":
124
- return `u"${val.value}"`;
125
- }
126
- }
127
- function cvToJSON(val) {
128
- switch (val.type) {
129
- case "true":
130
- return { type: "bool", value: true };
131
- case "false":
132
- return { type: "bool", value: false };
133
- case "int":
134
- return { type: "int", value: val.value.toString() };
135
- case "uint":
136
- return { type: "uint", value: val.value.toString() };
137
- case "buffer": {
138
- const hex = without0x(val.value);
139
- return {
140
- type: `(buff ${Math.ceil(hex.length / 2)})`,
141
- value: `0x${hex}`
142
- };
143
- }
144
- case "none":
145
- return { type: "(optional none)", value: null };
146
- case "some":
147
- return { type: "(optional)", value: cvToJSON(val.value) };
148
- case "ok":
149
- return { type: "(response)", value: cvToJSON(val.value), success: true };
150
- case "err":
151
- return { type: "(response)", value: cvToJSON(val.value), success: false };
152
- case "address":
153
- case "contract":
154
- return { type: "principal", value: val.value };
155
- case "list":
156
- return { type: "(list)", value: val.value.map(cvToJSON) };
157
- case "tuple": {
158
- const result = {};
159
- for (const key of Object.keys(val.value)) {
160
- result[key] = cvToJSON(val.value[key]);
161
- }
162
- return { type: "(tuple)", value: result };
163
- }
164
- case "ascii":
165
- return {
166
- type: `(string-ascii ${asciiToBytes(val.value).length})`,
167
- value: val.value
168
- };
169
- case "utf8":
170
- return {
171
- type: `(string-utf8 ${utf8ToBytes(val.value).length})`,
172
- value: val.value
173
- };
174
- }
175
- }
176
- function cvToValue(val) {
177
- switch (val.type) {
178
- case "true":
179
- return true;
180
- case "false":
181
- return false;
182
- case "int":
183
- case "uint":
184
- return val.value;
185
- case "buffer":
186
- return `0x${val.value}`;
187
- case "none":
188
- return null;
189
- case "some":
190
- return cvToValue(val.value);
191
- case "ok":
192
- case "err":
193
- return cvToValue(val.value);
194
- case "address":
195
- case "contract":
196
- return val.value;
197
- case "list":
198
- return val.value.map(cvToValue);
199
- case "tuple": {
200
- const result = {};
201
- for (const key of Object.keys(val.value)) {
202
- result[key] = cvToValue(val.value[key]);
203
- }
204
- return result;
205
- }
206
- case "ascii":
207
- case "utf8":
208
- return val.value;
209
- }
210
- }
211
- function cvToBigInt(val) {
212
- if (val.type !== "int" && val.type !== "uint") {
213
- throw new Error(`cvToBigInt: expected int or uint, got ${val.type}`);
214
- }
215
- return val.value;
216
- }
217
- function cvToString(val) {
218
- if (val.type !== "ascii" && val.type !== "utf8") {
219
- throw new Error(`cvToString: expected ascii or utf8, got ${val.type}`);
220
- }
221
- return val.value;
222
- }
223
- function cvToBuffer(val) {
224
- if (val.type !== "buffer") {
225
- throw new Error(`cvToBuffer: expected buffer, got ${val.type}`);
226
- }
227
- return val.value;
228
- }
229
- function cvToBoolean(val) {
230
- if (val.type !== "true" && val.type !== "false") {
231
- throw new Error(`cvToBoolean: expected bool, got ${val.type}`);
232
- }
233
- return val.type === "true";
234
- }
235
- function cvToPrincipal(val) {
236
- if (val.type !== "address" && val.type !== "contract") {
237
- throw new Error(`cvToPrincipal: expected principal or contract, got ${val.type}`);
238
- }
239
- return val.value;
240
- }
241
- // src/clarity/abi/converters.ts
242
- class ClarityConversionError extends Error {
243
- type;
244
- value;
245
- constructor(message, type, value) {
246
- super(message);
247
- this.type = type;
248
- this.value = value;
249
- this.name = "ClarityConversionError";
250
- }
251
- }
252
- function jsToClarity(type, value) {
253
- if (type === "none")
254
- return null;
255
- if (type === "uint128") {
256
- if (!isUint128(value))
257
- throw new ClarityConversionError("Invalid uint128 value", type, value);
258
- return value;
259
- }
260
- if (type === "int128") {
261
- if (!isInt128(value))
262
- throw new ClarityConversionError("Invalid int128 value", type, value);
263
- return value;
264
- }
265
- if (type === "bool") {
266
- if (!isBool(value))
267
- throw new ClarityConversionError("Invalid bool value", type, value);
268
- return value;
269
- }
270
- if (type === "principal") {
271
- if (!isPrincipal(value))
272
- throw new ClarityConversionError("Invalid principal value", type, value);
273
- return value;
274
- }
275
- if (type === "trait_reference") {
276
- if (!isPrincipal(value))
277
- throw new ClarityConversionError("Invalid trait_reference value", type, value);
278
- return value;
279
- }
280
- if (isAbiStringAscii(type)) {
281
- if (!isString(value))
282
- throw new ClarityConversionError("Invalid string-ascii value", type, value);
283
- const str = value;
284
- for (let i = 0;i < str.length; i++) {
285
- if (str.charCodeAt(i) > 127) {
286
- throw new ClarityConversionError(`Non-ASCII character at position ${i}: '${str[i]}' (code ${str.charCodeAt(i)})`, type, value);
287
- }
288
- }
289
- if (str.length > type["string-ascii"].length) {
290
- throw new ClarityConversionError(`String length ${str.length} exceeds max ${type["string-ascii"].length}`, type, value);
291
- }
292
- return value;
293
- }
294
- if (isAbiStringUtf8(type)) {
295
- if (!isString(value))
296
- throw new ClarityConversionError("Invalid string-utf8 value", type, value);
297
- const str = value;
298
- const byteLength = new TextEncoder().encode(str).length;
299
- if (byteLength > type["string-utf8"].length) {
300
- throw new ClarityConversionError(`String byte length ${byteLength} exceeds max ${type["string-utf8"].length}`, type, value);
301
- }
302
- return value;
303
- }
304
- if (isAbiBuffer(type)) {
305
- if (!isUint8Array(value))
306
- throw new ClarityConversionError("Invalid buffer value", type, value);
307
- const buff = value;
308
- if (buff.length > type.buff.length) {
309
- throw new ClarityConversionError(`Buffer length ${buff.length} exceeds max ${type.buff.length}`, type, value);
310
- }
311
- return value;
312
- }
313
- if (isAbiList(type)) {
314
- if (!Array.isArray(value))
315
- throw new ClarityConversionError("Expected array for list type", type, value);
316
- if (value.length > type.list.length) {
317
- throw new ClarityConversionError(`List length ${value.length} exceeds max ${type.list.length}`, type, value);
318
- }
319
- return value.map((item) => jsToClarity(type.list.type, item));
320
- }
321
- if (isAbiTuple(type)) {
322
- if (typeof value !== "object" || value === null)
323
- throw new ClarityConversionError("Expected object for tuple type", type, value);
324
- const result = {};
325
- for (const field of type.tuple) {
326
- const camelKey = toCamelCase(field.name);
327
- const hasOriginal = field.name in value;
328
- const hasCamel = camelKey in value;
329
- if (!hasOriginal && !hasCamel) {
330
- throw new ClarityConversionError(`Missing tuple field: ${field.name}`, type, value);
331
- }
332
- const fieldValue = hasOriginal ? value[field.name] : value[camelKey];
333
- result[field.name] = jsToClarity(field.type, fieldValue);
334
- }
335
- return result;
336
- }
337
- if (isAbiOptional(type)) {
338
- if (value === null || value === undefined)
339
- return null;
340
- return jsToClarity(type.optional, value);
341
- }
342
- if (isAbiResponse(type)) {
343
- if (typeof value !== "object" || value === null)
344
- throw new ClarityConversionError("Expected object for response type", type, value);
345
- const hasOk = "ok" in value;
346
- const hasErr = "err" in value;
347
- if (hasOk && !hasErr) {
348
- return {
349
- ok: jsToClarity(type.response.ok, value.ok)
350
- };
351
- }
352
- if (hasErr && !hasOk) {
353
- return {
354
- err: jsToClarity(type.response.error, value.err)
355
- };
356
- }
357
- throw new ClarityConversionError("Response must have exactly 'ok' or 'err' property", type, value);
358
- }
359
- throw new ClarityConversionError("Unknown Clarity type", type, value);
360
- }
361
- function prepareArgs(func, args) {
362
- return func.args.map((arg) => {
363
- if (!(arg.name in args)) {
364
- throw new ClarityConversionError(`Missing argument: ${arg.name}`, arg.type, undefined);
365
- }
366
- return jsToClarity(arg.type, args[arg.name]);
367
- });
368
- }
369
- function validateArgs(func, args) {
370
- for (const arg of func.args) {
371
- if (!(arg.name in args)) {
372
- throw new ClarityConversionError(`Missing argument: ${arg.name}`, arg.type, undefined);
373
- }
374
- jsToClarity(arg.type, args[arg.name]);
375
- }
376
- }
377
- function validateArgsArray(func, args) {
378
- if (args.length !== func.args.length) {
379
- throw new ClarityConversionError(`Expected ${func.args.length} arguments, got ${args.length}`, func.args[0]?.type ?? "bool", args);
380
- }
381
- func.args.forEach((arg, i) => {
382
- jsToClarity(arg.type, args[i]);
383
- });
384
- }
385
- // src/clarity/abi/classify.ts
386
- var TRAIT_STANDARDS = ["sip-009", "sip-010", "sip-013"];
387
- var STANDARDS = [
388
- { id: "sip-010", abi: SIP010_ABI, optional: new Set(["get-token-uri"]) },
389
- { id: "sip-009", abi: SIP009_ABI, optional: new Set(["get-token-uri"]) },
390
- {
391
- id: "sip-013",
392
- abi: SIP013_ABI,
393
- optional: new Set([
394
- "transfer-memo",
395
- "transfer-many",
396
- "transfer-many-memo",
397
- "get-token-uri",
398
- "get-overall-balance",
399
- "get-overall-supply"
400
- ])
401
- }
402
- ];
403
- function indexByName(abi) {
404
- const m = new Map;
405
- for (const f of abi.functions)
406
- m.set(f.name, f);
407
- return m;
408
- }
409
- function conformsTo(candidate, spec) {
410
- const fns = indexByName(candidate);
411
- for (const required of spec.abi.functions) {
412
- if (spec.optional.has(required.name))
413
- continue;
414
- const got = fns.get(required.name);
415
- if (!got)
416
- return false;
417
- if (got.access !== required.access)
418
- return false;
419
- if (got.args.length !== required.args.length)
420
- return false;
421
- }
422
- return true;
423
- }
424
- function classifyContract(abi) {
425
- if (!abi || !Array.isArray(abi.functions))
426
- return [];
427
- return STANDARDS.filter((s) => conformsTo(abi, s)).map((s) => s.id);
428
- }
429
- function parseDeclaredStandards(claritySource) {
430
- const out = new Set;
431
- const matches = claritySource.matchAll(/\(impl-trait\s+[^)]+\)/gi);
432
- for (const m of matches) {
433
- const ref = m[0].toLowerCase();
434
- if (ref.includes("sip-010") || ref.includes(".ft-trait"))
435
- out.add("sip-010");
436
- if (ref.includes("sip-009") || ref.includes("nft-trait"))
437
- out.add("sip-009");
438
- if (ref.includes("sip-013") || ref.includes("semi-fungible"))
439
- out.add("sip-013");
440
- }
441
- return [...out];
442
- }
443
- // src/clarity/abi/normalize.ts
444
- function normalizeAccess(access) {
445
- if (access === "read_only")
446
- return "read-only";
447
- return access;
448
- }
449
- function normalizeType(type) {
450
- if (typeof type === "string") {
451
- switch (type) {
452
- case "uint128":
453
- case "int128":
454
- case "bool":
455
- case "principal":
456
- case "trait_reference":
457
- return type;
458
- default:
459
- return type;
460
- }
461
- }
462
- if (typeof type !== "object" || type === null) {
463
- throw new Error(`Invalid ABI type: expected object, got ${typeof type}`);
464
- }
465
- const typeObj = type;
466
- if ("buffer" in typeObj) {
467
- const buffer = typeObj.buffer;
468
- return {
469
- buff: {
470
- length: buffer?.length ?? 32
471
- }
472
- };
473
- }
474
- if ("buff" in typeObj) {
475
- const buff = typeObj.buff;
476
- return {
477
- buff: {
478
- length: buff?.length ?? 32
479
- }
480
- };
481
- }
482
- if ("string-ascii" in typeObj) {
483
- const strAscii = typeObj["string-ascii"];
484
- return {
485
- "string-ascii": {
486
- length: strAscii?.length ?? 256
487
- }
488
- };
489
- }
490
- if ("string-utf8" in typeObj) {
491
- const strUtf8 = typeObj["string-utf8"];
492
- return {
493
- "string-utf8": {
494
- length: strUtf8?.length ?? 256
495
- }
496
- };
497
- }
498
- if ("response" in typeObj) {
499
- const response = typeObj.response;
500
- return {
501
- response: {
502
- ok: normalizeType(response?.ok ?? "bool"),
503
- error: normalizeType(response?.error ?? "uint128")
504
- }
505
- };
506
- }
507
- if ("optional" in typeObj) {
508
- return {
509
- optional: normalizeType(typeObj.optional)
510
- };
511
- }
512
- if ("list" in typeObj) {
513
- const list = typeObj.list;
514
- return {
515
- list: {
516
- type: normalizeType(list?.type ?? "uint128"),
517
- length: list?.length ?? 100
518
- }
519
- };
520
- }
521
- if ("tuple" in typeObj) {
522
- const tuple = typeObj.tuple;
523
- return {
524
- tuple: tuple.map((field) => ({
525
- name: field.name,
526
- type: normalizeType(field.type)
527
- }))
528
- };
529
- }
530
- throw new Error(`Unknown ABI type structure: ${JSON.stringify(type)}`);
531
- }
532
- function normalizeFunction(func) {
533
- const access = normalizeAccess(func.access);
534
- const args = func.args ?? [];
535
- const outputs = func.outputs;
536
- return {
537
- name: func.name,
538
- access,
539
- args: args.map((arg) => ({
540
- name: arg.name,
541
- type: normalizeType(arg.type)
542
- })),
543
- outputs: normalizeType(typeof outputs === "object" && outputs !== null && "type" in outputs ? outputs.type : outputs)
544
- };
545
- }
546
- function normalizeMap(map) {
547
- return {
548
- name: map.name,
549
- key: normalizeType(map.key),
550
- value: normalizeType(map.value)
551
- };
552
- }
553
- function normalizeVariable(variable) {
554
- return {
555
- name: variable.name,
556
- type: normalizeType(variable.type),
557
- access: variable.access
558
- };
559
- }
560
- function normalizeFungibleToken(token) {
561
- return { name: token.name };
562
- }
563
- function normalizeNonFungibleToken(token) {
564
- return { name: token.name, type: normalizeType(token.type) };
565
- }
566
- function normalizeTraitDefinition(trait) {
567
- const rawFunctions = Array.isArray(trait.functions) ? trait.functions : [];
568
- const functions = [];
569
- for (const func of rawFunctions) {
570
- if (typeof func !== "object" || func === null)
571
- continue;
572
- const normalized = normalizeFunction(func);
573
- if (normalized.access === "private")
574
- continue;
575
- functions.push(normalized);
576
- }
577
- return { name: trait.name, functions };
578
- }
579
- function normalizeAbi(abi) {
580
- if (typeof abi !== "object" || abi === null) {
581
- return { functions: [] };
582
- }
583
- const abiObj = abi;
584
- const functions = [];
585
- const maps = [];
586
- const variables = [];
587
- const fungibleTokens = [];
588
- const nonFungibleTokens = [];
589
- const implementedTraits = [];
590
- const definedTraits = [];
591
- if (Array.isArray(abiObj.functions)) {
592
- for (const func of abiObj.functions) {
593
- if (typeof func === "object" && func !== null) {
594
- functions.push(normalizeFunction(func));
595
- }
596
- }
597
- }
598
- if (Array.isArray(abiObj.maps)) {
599
- for (const map of abiObj.maps) {
600
- if (typeof map === "object" && map !== null) {
601
- maps.push(normalizeMap(map));
602
- }
603
- }
604
- }
605
- if (Array.isArray(abiObj.variables)) {
606
- for (const variable of abiObj.variables) {
607
- if (typeof variable === "object" && variable !== null) {
608
- variables.push(normalizeVariable(variable));
609
- }
610
- }
611
- }
612
- if (Array.isArray(abiObj.fungible_tokens)) {
613
- for (const token of abiObj.fungible_tokens) {
614
- if (typeof token === "object" && token !== null) {
615
- fungibleTokens.push(normalizeFungibleToken(token));
616
- }
617
- }
618
- }
619
- if (Array.isArray(abiObj.non_fungible_tokens)) {
620
- for (const token of abiObj.non_fungible_tokens) {
621
- if (typeof token === "object" && token !== null) {
622
- nonFungibleTokens.push(normalizeNonFungibleToken(token));
623
- }
624
- }
625
- }
626
- if (Array.isArray(abiObj.implemented_traits)) {
627
- for (const trait of abiObj.implemented_traits) {
628
- if (typeof trait === "string")
629
- implementedTraits.push(trait);
630
- }
631
- }
632
- if (Array.isArray(abiObj.defined_traits)) {
633
- for (const trait of abiObj.defined_traits) {
634
- if (typeof trait === "object" && trait !== null) {
635
- definedTraits.push(normalizeTraitDefinition(trait));
636
- }
637
- }
638
- }
639
- return {
640
- functions,
641
- maps: maps.length > 0 ? maps : undefined,
642
- variables: variables.length > 0 ? variables : undefined,
643
- fungible_tokens: fungibleTokens.length > 0 ? fungibleTokens : undefined,
644
- non_fungible_tokens: nonFungibleTokens.length > 0 ? nonFungibleTokens : undefined,
645
- implemented_traits: implementedTraits.length > 0 ? implementedTraits : undefined,
646
- defined_traits: definedTraits.length > 0 ? definedTraits : undefined
647
- };
648
- }
649
-
650
- //# debugId=80FCD2146E22850B64756E2164756E21
651
- //# sourceMappingURL=stacks-ee53k9j2.cjs.map