@cardananium/cquisitor-lib 0.1.0-beta.46 → 0.1.0-beta.47

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
@@ -24,7 +24,7 @@ Functions:
24
24
 
25
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. 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).
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). Never throws on malformed input — returns a `{ok, value}` / `{ok: false, error, partial?}` union where `error` is a structured `CborDecodeError` (kind / byte offset / byte span / semantic `path`) and `partial` is the sub-tree decoded before the failure, with every unfinished container flagged `incomplete: true`.
28
28
  - `validate_cddl(cddl)` - Parses a CDDL schema and reports structural errors.
29
29
  - `validate_cbor_against_cddl(cbor_hex, cddl, rule_name)` - Validates CBOR payload against a CDDL rule with detailed mismatch info.
30
30
 
@@ -308,21 +308,34 @@ const possibleTypes = get_possible_types_for_input("e1a...");
308
308
 
309
309
  ### CBOR Decoder
310
310
 
311
- #### `cbor_to_json(cbor_hex: string): CborValue`
311
+ #### `cbor_to_json(cbor_hex: string): CborDecodeResult`
312
312
 
313
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.
314
314
 
315
+ The function **never throws** on malformed input. On success it returns `{ ok: true, value }`; on failure `{ ok: false, error, partial? }` where `error` is a structured `CborDecodeError` and `partial` is the sub-tree decoded up to the failure point:
316
+
315
317
  ```typescript
316
- const cbor = cbor_to_json("a26461646472...");
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" }
318
+ const r = cbor_to_json("a26461646472...");
319
+ if (r.ok) {
320
+ // r.value the full positional tree; each node may carry oddities like:
321
+ // { kind: "IntNotShortest", detail: "value 15 uses 2-byte header, shortest is 1" }
322
+ // { kind: "IndefiniteLength", detail: "indefinite-length map" }
323
+ // { kind: "MapKeysNotSorted", detail: "key at offset 3 sorts after key at offset 5" }
324
+ // { kind: "DuplicateMapKeys", detail: "duplicate key at offsets 3 and 6" }
325
+ // { kind: "BignumForSmallInt", detail: "unsigned bignum fits in a native CBOR integer" }
326
+ } else {
327
+ // r.error: { kind, offset?, byte_span?, path, message }
328
+ // kind — machine-readable tag ("invalid_syntax", "unexpected_eof", ...).
329
+ // offset — byte where decoding stopped.
330
+ // byte_span — { offset, length } when the failure pins a range.
331
+ // path — structural location, e.g. "$.entries[1].value[0]".
332
+ // r.partial (optional) — same shape as a CborValue, but every unfinished
333
+ // container carries `incomplete: true`, and partial map entries carry
334
+ // `incomplete_at: "key" | "value"` on the half that didn't parse.
335
+ }
323
336
  ```
324
337
 
325
- See `CborOddityKind` in the type definitions for the full list.
338
+ See `CborOddityKind` and `CborDecodeErrorKind` in the type definitions for the full lists.
326
339
 
327
340
  #### `validate_cddl(cddl: string): { valid: boolean, error?: object }`
328
341
 
@@ -102,7 +102,48 @@ export function get_possible_types_for_input(input: string): (string)[];
102
102
  * @param {string} cbor_hex
103
103
  * @returns {any}
104
104
  */
105
- export function cbor_to_json(cbor_hex: string): CborValue;
105
+ /**
106
+ * Decodes a CBOR hex string into a positional JSON tree.
107
+ *
108
+ * Never throws on malformed input — on failure returns
109
+ * `{ ok: false, error: CborDecodeError, partial? }`. Structured errors
110
+ * carry `kind`, `offset`, a `byte_span`, a semantic `path` into the
111
+ * failing position, and a human `message`.
112
+ *
113
+ * When anything was successfully decoded before the failure, `partial`
114
+ * contains the prefix tree with every un-finished container flagged
115
+ * `incomplete: true`. Node shape otherwise matches the success value, so
116
+ * renderers can display it the same way.
117
+ */
118
+ export function cbor_to_json(cbor_hex: string): CborDecodeResult;
119
+
120
+ export type CborDecodeResult =
121
+ | { ok: true; value: CborValue }
122
+ | { ok: false; error: CborDecodeError; partial?: CborPartialValue };
123
+
124
+ export type CborDecodeErrorKind =
125
+ | "invalid_hex"
126
+ | "invalid_syntax"
127
+ | "unexpected_eof"
128
+ | "unexpected_break"
129
+ | "trailing_data"
130
+ | "invalid_utf8"
131
+ | "invalid_chunk"
132
+ | "int_not_representable"
133
+ | "non_finite_float"
134
+ | "io_error";
135
+
136
+ export interface CborDecodeError {
137
+ kind: CborDecodeErrorKind;
138
+ /** Human-readable message. Not stable — use `kind` for branching. */
139
+ message: string;
140
+ /** Semantic path into the decoded tree (e.g. `$.entries[1].value[0]`). */
141
+ path: string;
142
+ /** Byte offset where decoding failed. Absent only for rare IO fallbacks. */
143
+ offset?: number;
144
+ /** Byte range pinned by the failure, when wider than a single byte. */
145
+ byte_span?: CborPosition;
146
+ }
106
147
 
107
148
  /**
108
149
  * Validates a CDDL schema by parsing it into the intermediate validation tree.
@@ -279,6 +320,63 @@ export type CborValue =
279
320
  | CborIndefiniteString
280
321
  | CborIndefiniteBytes;
281
322
 
323
+ /**
324
+ * Sub-tree returned alongside a decode error. Structurally identical to
325
+ * `CborValue`, with two additional flags present **only** on nodes that
326
+ * couldn't be finished:
327
+ *
328
+ * - `incomplete: true` — on containers (Array / Map / Tag /
329
+ * IndefiniteLengthBytes / IndefiniteLengthString) whose body was cut
330
+ * short by the failure. For definite-length Array/Map the `items` field
331
+ * retains the wire-declared count; `values.length` shows how many slots
332
+ * actually decoded.
333
+ * - `incomplete_at: "key" | "value"` — on the single map entry where
334
+ * decoding stopped; at most one of `key` / `value` on that entry is
335
+ * populated, indicating which half had been parsed before the failure.
336
+ */
337
+ export type CborPartialValue =
338
+ | CborSimple
339
+ | CborPartialArray
340
+ | CborPartialMap
341
+ | CborPartialTag
342
+ | CborPartialIndefiniteString
343
+ | CborPartialIndefiniteBytes;
344
+
345
+ export interface CborPartialArray extends Omit<CborArray, "values"> {
346
+ values: CborPartialValue[];
347
+ incomplete?: true;
348
+ }
349
+
350
+ export interface CborPartialMap extends Omit<CborMap, "values"> {
351
+ values: Array<CborPartialMapEntry | { key: CborValue; value: CborValue }>;
352
+ incomplete?: true;
353
+ }
354
+
355
+ export interface CborPartialMapEntry {
356
+ key?: CborPartialValue;
357
+ value?: CborPartialValue;
358
+ incomplete: true;
359
+ incomplete_at: "key" | "value";
360
+ }
361
+
362
+ export interface CborPartialTag extends Omit<CborTag, "value"> {
363
+ /** Absent when the inner item could not be parsed at all. */
364
+ value?: CborPartialValue;
365
+ incomplete?: true;
366
+ }
367
+
368
+ export interface CborPartialIndefiniteString
369
+ extends Omit<CborIndefiniteString, "chunks"> {
370
+ chunks: CborValue[];
371
+ incomplete?: true;
372
+ }
373
+
374
+ export interface CborPartialIndefiniteBytes
375
+ extends Omit<CborIndefiniteBytes, "chunks"> {
376
+ chunks: CborValue[];
377
+ incomplete?: true;
378
+ }
379
+
282
380
  export type CddlValidationResult =
283
381
  | { valid: true }
284
382
  | { valid: false; error: CddlErrorInfo };
@@ -28437,6 +28437,12 @@ export function calculate_ex_units_ceil_cost(ex_units, ex_unit_prices) {
28437
28437
  }
28438
28438
 
28439
28439
  /**
28440
+ * Decode CBOR hex into a positional JSON tree.
28441
+ *
28442
+ * Never throws on malformed input — returns a `{ok: false, error: {...}}`
28443
+ * object with a structured decode error: `kind`, `offset`, `byte_span`,
28444
+ * structural `path`, and a human `message`. Successful decodes come back
28445
+ * as `{ok: true, value: <tree>}`.
28440
28446
  * @param {string} cbor_hex
28441
28447
  * @returns {any}
28442
28448
  */
Binary file
@@ -4,7 +4,6 @@ export const memory: WebAssembly.Memory;
4
4
  export const decode_specific_type: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
5
5
  export const get_decodable_types: () => [number, number];
6
6
  export const get_possible_types_for_input: (a: number, b: number) => [number, number];
7
- export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
8
7
  export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
9
8
  export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
9
  export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
@@ -16,6 +15,7 @@ export const get_ref_script_bytes: (a: number, b: number, c: number) => [number,
16
15
  export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
17
16
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
18
17
  export const validate_cddl: (a: number, b: number) => [number, number, number];
18
+ export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
19
19
  export const __wbg_bigint_free: (a: number, b: number) => void;
20
20
  export const __wbg_certificatesbuilder_free: (a: number, b: number) => void;
21
21
  export const __wbg_changeconfig_free: (a: number, b: number) => void;
@@ -102,7 +102,48 @@ export function get_possible_types_for_input(input: string): (string)[];
102
102
  * @param {string} cbor_hex
103
103
  * @returns {any}
104
104
  */
105
- export function cbor_to_json(cbor_hex: string): CborValue;
105
+ /**
106
+ * Decodes a CBOR hex string into a positional JSON tree.
107
+ *
108
+ * Never throws on malformed input — on failure returns
109
+ * `{ ok: false, error: CborDecodeError, partial? }`. Structured errors
110
+ * carry `kind`, `offset`, a `byte_span`, a semantic `path` into the
111
+ * failing position, and a human `message`.
112
+ *
113
+ * When anything was successfully decoded before the failure, `partial`
114
+ * contains the prefix tree with every un-finished container flagged
115
+ * `incomplete: true`. Node shape otherwise matches the success value, so
116
+ * renderers can display it the same way.
117
+ */
118
+ export function cbor_to_json(cbor_hex: string): CborDecodeResult;
119
+
120
+ export type CborDecodeResult =
121
+ | { ok: true; value: CborValue }
122
+ | { ok: false; error: CborDecodeError; partial?: CborPartialValue };
123
+
124
+ export type CborDecodeErrorKind =
125
+ | "invalid_hex"
126
+ | "invalid_syntax"
127
+ | "unexpected_eof"
128
+ | "unexpected_break"
129
+ | "trailing_data"
130
+ | "invalid_utf8"
131
+ | "invalid_chunk"
132
+ | "int_not_representable"
133
+ | "non_finite_float"
134
+ | "io_error";
135
+
136
+ export interface CborDecodeError {
137
+ kind: CborDecodeErrorKind;
138
+ /** Human-readable message. Not stable — use `kind` for branching. */
139
+ message: string;
140
+ /** Semantic path into the decoded tree (e.g. `$.entries[1].value[0]`). */
141
+ path: string;
142
+ /** Byte offset where decoding failed. Absent only for rare IO fallbacks. */
143
+ offset?: number;
144
+ /** Byte range pinned by the failure, when wider than a single byte. */
145
+ byte_span?: CborPosition;
146
+ }
106
147
 
107
148
  /**
108
149
  * Validates a CDDL schema by parsing it into the intermediate validation tree.
@@ -279,6 +320,63 @@ export type CborValue =
279
320
  | CborIndefiniteString
280
321
  | CborIndefiniteBytes;
281
322
 
323
+ /**
324
+ * Sub-tree returned alongside a decode error. Structurally identical to
325
+ * `CborValue`, with two additional flags present **only** on nodes that
326
+ * couldn't be finished:
327
+ *
328
+ * - `incomplete: true` — on containers (Array / Map / Tag /
329
+ * IndefiniteLengthBytes / IndefiniteLengthString) whose body was cut
330
+ * short by the failure. For definite-length Array/Map the `items` field
331
+ * retains the wire-declared count; `values.length` shows how many slots
332
+ * actually decoded.
333
+ * - `incomplete_at: "key" | "value"` — on the single map entry where
334
+ * decoding stopped; at most one of `key` / `value` on that entry is
335
+ * populated, indicating which half had been parsed before the failure.
336
+ */
337
+ export type CborPartialValue =
338
+ | CborSimple
339
+ | CborPartialArray
340
+ | CborPartialMap
341
+ | CborPartialTag
342
+ | CborPartialIndefiniteString
343
+ | CborPartialIndefiniteBytes;
344
+
345
+ export interface CborPartialArray extends Omit<CborArray, "values"> {
346
+ values: CborPartialValue[];
347
+ incomplete?: true;
348
+ }
349
+
350
+ export interface CborPartialMap extends Omit<CborMap, "values"> {
351
+ values: Array<CborPartialMapEntry | { key: CborValue; value: CborValue }>;
352
+ incomplete?: true;
353
+ }
354
+
355
+ export interface CborPartialMapEntry {
356
+ key?: CborPartialValue;
357
+ value?: CborPartialValue;
358
+ incomplete: true;
359
+ incomplete_at: "key" | "value";
360
+ }
361
+
362
+ export interface CborPartialTag extends Omit<CborTag, "value"> {
363
+ /** Absent when the inner item could not be parsed at all. */
364
+ value?: CborPartialValue;
365
+ incomplete?: true;
366
+ }
367
+
368
+ export interface CborPartialIndefiniteString
369
+ extends Omit<CborIndefiniteString, "chunks"> {
370
+ chunks: CborValue[];
371
+ incomplete?: true;
372
+ }
373
+
374
+ export interface CborPartialIndefiniteBytes
375
+ extends Omit<CborIndefiniteBytes, "chunks"> {
376
+ chunks: CborValue[];
377
+ incomplete?: true;
378
+ }
379
+
282
380
  export type CddlValidationResult =
283
381
  | { valid: true }
284
382
  | { valid: false; error: CddlErrorInfo };
@@ -28663,6 +28663,12 @@ function calculate_ex_units_ceil_cost(ex_units, ex_unit_prices) {
28663
28663
  exports.calculate_ex_units_ceil_cost = calculate_ex_units_ceil_cost;
28664
28664
 
28665
28665
  /**
28666
+ * Decode CBOR hex into a positional JSON tree.
28667
+ *
28668
+ * Never throws on malformed input — returns a `{ok: false, error: {...}}`
28669
+ * object with a structured decode error: `kind`, `offset`, `byte_span`,
28670
+ * structural `path`, and a human `message`. Successful decodes come back
28671
+ * as `{ok: true, value: <tree>}`.
28666
28672
  * @param {string} cbor_hex
28667
28673
  * @returns {any}
28668
28674
  */
Binary file
@@ -4,7 +4,6 @@ export const memory: WebAssembly.Memory;
4
4
  export const decode_specific_type: (a: number, b: number, c: number, d: number, e: any) => [number, number, number];
5
5
  export const get_decodable_types: () => [number, number];
6
6
  export const get_possible_types_for_input: (a: number, b: number) => [number, number];
7
- export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
8
7
  export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
9
8
  export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
9
  export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
@@ -16,6 +15,7 @@ export const get_ref_script_bytes: (a: number, b: number, c: number) => [number,
16
15
  export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
17
16
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
18
17
  export const validate_cddl: (a: number, b: number) => [number, number, number];
18
+ export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
19
19
  export const __wbg_bigint_free: (a: number, b: number) => void;
20
20
  export const __wbg_certificatesbuilder_free: (a: number, b: number) => void;
21
21
  export const __wbg_changeconfig_free: (a: number, b: number) => void;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "Evgenii Lisitskii <evgeniilisitskii@gmail.com>"
5
5
  ],
6
6
  "description": "Cardano transaction validation library",
7
- "version": "0.1.0-beta.46",
7
+ "version": "0.1.0-beta.47",
8
8
  "license": "Apache-2.0",
9
9
  "files": [
10
10
  "node/cquisitor_lib_bg.wasm",