@cardananium/cquisitor-lib 0.1.0-beta.44 → 0.1.0-beta.45

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/README.md CHANGED
@@ -22,9 +22,11 @@ Functions:
22
22
  - `decode_specific_type(hex, type_name, params)` - Decode specific Cardano type
23
23
  - `get_possible_types_for_input(hex)` - Suggests types that can decode given input
24
24
 
25
- ### CBOR Decoder
25
+ ### CBOR Decoder & CDDL Validation
26
26
 
27
- `cbor_to_json(cbor_hex)` - Converts raw CBOR to JSON with positional information, supporting indefinite arrays/maps and all CBOR types.
27
+ - `cbor_to_json(cbor_hex)` - Converts raw CBOR to JSON with positional information, supporting indefinite arrays/maps and all CBOR types. Each node carries an optional `oddities` array flagging deviations from RFC 8949 deterministic encoding (overlong integers/floats, indefinite length, unsorted/duplicate map keys, non-canonical bignums).
28
+ - `validate_cddl(cddl)` - Parses a CDDL schema and reports structural errors.
29
+ - `validate_cbor_against_cddl(cbor_hex, cddl, rule_name)` - Validates CBOR payload against a CDDL rule with detailed mismatch info.
28
30
 
29
31
  ### Plutus Script Decoder
30
32
 
@@ -104,7 +106,8 @@ import {
104
106
 
105
107
  // Step 1: Parse transaction and identify required data
106
108
  const txHex = "84a400..."; // Your transaction in hex format
107
- const necessaryDataJson = get_necessary_data_list_js(txHex);
109
+ const networkType = "mainnet"; // or "preview" | "preprod"
110
+ const necessaryDataJson = get_necessary_data_list_js(txHex, networkType);
108
111
  const necessaryData = JSON.parse(necessaryDataJson);
109
112
 
110
113
  console.log('Required UTXOs:', necessaryData.utxos);
@@ -177,7 +180,7 @@ import {
177
180
  async function validateTransaction(txHex: string): Promise<boolean> {
178
181
  try {
179
182
  // Parse transaction
180
- const necessaryDataJson = get_necessary_data_list_js(txHex);
183
+ const necessaryDataJson = get_necessary_data_list_js(txHex, "mainnet");
181
184
  const necessaryData = JSON.parse(necessaryDataJson);
182
185
 
183
186
  // Fetch required blockchain data
@@ -226,12 +229,12 @@ async function validateTransaction(txHex: string): Promise<boolean> {
226
229
 
227
230
  ### Transaction Validation
228
231
 
229
- #### `get_necessary_data_list_js(tx_hex: string): string`
232
+ #### `get_necessary_data_list_js(tx_hex: string, network_type: "mainnet" | "preview" | "preprod"): string`
230
233
 
231
- Extracts required blockchain data for validation.
234
+ Extracts required blockchain data for validation. `network_type` determines the bech32 prefix used when deriving stake/reward addresses for `accounts`, `pools`, and `dReps`.
232
235
 
233
236
  ```typescript
234
- const necessaryData = JSON.parse(get_necessary_data_list_js(txHex));
237
+ const necessaryData = JSON.parse(get_necessary_data_list_js(txHex, "mainnet"));
235
238
  // Returns: { utxos, accounts, pools, dReps, govActions, ... }
236
239
  ```
237
240
 
@@ -248,6 +251,23 @@ const result = JSON.parse(validate_transaction_js(txHex, JSON.stringify(context)
248
251
 
249
252
  Extracts all UTxO references (inputs + collateral + reference inputs) from transaction.
250
253
 
254
+ #### `get_ref_script_bytes(tx_hex: string, output_index: number): string`
255
+
256
+ Returns the hex-encoded CBOR bytes of the reference script embedded in `outputs[output_index]`. Returns an empty string if the output has no reference script or the index is out of range.
257
+
258
+ ```typescript
259
+ const scriptHex = get_ref_script_bytes(txHex, 0);
260
+ ```
261
+
262
+ #### `extract_hashes_from_transaction_js(tx_hex: string): string`
263
+
264
+ Returns a JSON-serialized `ExtractedHashes` with every script / datum / redeemer / metadata / auxiliary-data hash referenced by the transaction (witness set, outputs with inline scripts/datums, auxiliary data). Useful for building indexers or caches.
265
+
266
+ ```typescript
267
+ const hashes = JSON.parse(extract_hashes_from_transaction_js(txHex));
268
+ // { witness_native_script_hashes, witness_plutus_scripts, witness_datum_hashes, ... }
269
+ ```
270
+
251
271
  ### Universal Decoder
252
272
 
253
273
  #### `get_decodable_types(): string[]`
@@ -290,11 +310,36 @@ const possibleTypes = get_possible_types_for_input("e1a...");
290
310
 
291
311
  #### `cbor_to_json(cbor_hex: string): CborValue`
292
312
 
293
- Converts CBOR to JSON with positional metadata.
313
+ Converts CBOR to JSON with positional metadata. Each node has `position_info` (byte span of its header) and, for containers/tags, `struct_position_info` (span of the whole subtree). Non-canonical encoding deviations (per RFC 8949 §4.1/§4.2) are flagged locally on the offending node via an optional `oddities: CborOddity[]` field — canonical inputs omit the field entirely.
294
314
 
295
315
  ```typescript
296
316
  const cbor = cbor_to_json("a26461646472...");
297
- // Returns structured JSON with position info for each element
317
+ // Returns structured JSON; each node may carry oddities like:
318
+ // { kind: "IntNotShortest", detail: "value 15 uses 2-byte header, shortest is 1" }
319
+ // { kind: "IndefiniteLength", detail: "indefinite-length map" }
320
+ // { kind: "MapKeysNotSorted", detail: "key at offset 3 sorts after key at offset 5" }
321
+ // { kind: "DuplicateMapKeys", detail: "duplicate key at offsets 3 and 6" }
322
+ // { kind: "BignumForSmallInt", detail: "unsigned bignum fits in a native CBOR integer" }
323
+ ```
324
+
325
+ See `CborOddityKind` in the type definitions for the full list.
326
+
327
+ #### `validate_cddl(cddl: string): { valid: boolean, error?: object }`
328
+
329
+ Parses a CDDL schema and reports whether it is well-formed. Returns `{ valid: true }` on success or `{ valid: false, error: { kind, ... } }` with a structured error on failure.
330
+
331
+ ```typescript
332
+ const result = validate_cddl("thing = {n: uint}");
333
+ // { valid: true }
334
+ ```
335
+
336
+ #### `validate_cbor_against_cddl(cbor_hex: string, cddl: string, rule_name: string): { valid: boolean, error?: object }`
337
+
338
+ Validates a CBOR payload against a specific rule in a CDDL schema. On mismatch the error carries `kind`, `expected`, and location info.
339
+
340
+ ```typescript
341
+ const result = validate_cbor_against_cddl("01", "thing = tstr", "thing");
342
+ // { valid: false, error: { kind: "mismatch", expected: "tstr", ... } }
298
343
  ```
299
344
 
300
345
  ### Plutus Script Decoder