@cardananium/cquisitor-lib 0.1.0-beta.52 → 0.1.0-beta.54

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.
@@ -171,6 +171,30 @@ export function validate_cbor_against_cddl(
171
171
  rule_name: string
172
172
  ): CborValidationResult;
173
173
 
174
+ /**
175
+ * **CDDL spans carry both byte and char offsets.** `offset`/`length`
176
+ * count UTF-8 bytes (what `pest` reports); `char_offset`/`char_length`
177
+ * count UTF-16 code units — the unit JS strings, `string.slice`,
178
+ * editor APIs, and the LSP protocol use. For ASCII-only sources the
179
+ * two pairs are identical.
180
+ *
181
+ * **CBOR spans are byte offsets only** — into the decoded CBOR buffer.
182
+ * If you have a hex string, multiply by 2 to slice the hex view:
183
+ * `hex.slice(off*2, (off+len)*2)`.
184
+ */
185
+ export interface SourceSpan {
186
+ /** UTF-8 byte offset in the source. */
187
+ offset: number;
188
+ /** UTF-8 byte length. */
189
+ length: number;
190
+ /** UTF-16 code unit offset (= `string.slice`-friendly). */
191
+ char_offset: number;
192
+ /** UTF-16 code unit length. */
193
+ char_length: number;
194
+ /** 1-indexed line. */
195
+ line: number;
196
+ }
197
+
174
198
  /** Outline entry — one rule from `cddl_outline`. */
175
199
  export interface CddlOutlineEntry {
176
200
  /** Rule name (`transaction_body`, `set`, …). */
@@ -178,9 +202,9 @@ export interface CddlOutlineEntry {
178
202
  /** `"type"` for `=`, `"group"` for `( … )`. */
179
203
  kind: "type" | "group";
180
204
  /** Byte range covering the whole `name = …` rule definition. */
181
- span: { offset: number; length: number; line: number };
205
+ span: SourceSpan;
182
206
  /** Byte range of just the rule's name identifier. */
183
- name_span: { offset: number; length: number; line: number };
207
+ name_span: SourceSpan;
184
208
  }
185
209
 
186
210
  /** Result of `cddl_symbol_at`. `null` when the cursor isn't on an identifier. */
@@ -190,15 +214,15 @@ export type CddlSymbolAtResult =
190
214
  name: string;
191
215
  kind: "type" | "group" | "rule_reference" | "prelude_or_unknown";
192
216
  role: "definition" | "use";
193
- span: { offset: number; length: number; line: number };
194
- definition_span: { offset: number; length: number; line: number } | null;
195
- rule_span: { offset: number; length: number; line: number } | null;
217
+ span: SourceSpan;
218
+ definition_span: SourceSpan | null;
219
+ rule_span: SourceSpan | null;
196
220
  };
197
221
 
198
222
  /** Result of `cddl_references`. */
199
223
  export interface CddlReferencesResult {
200
- definition: { offset: number; length: number; line: number } | null;
201
- uses: { offset: number; length: number; line: number }[];
224
+ definition: SourceSpan | null;
225
+ uses: SourceSpan[];
202
226
  }
203
227
 
204
228
  /**
@@ -245,12 +269,19 @@ export interface CborCddlMapEntry {
245
269
  * except 0 / 2 / 3) the inner gets an extra `["@value"]` segment
246
270
  * to match the `{@tag, @value}` wrapper the decoder emits. */
247
271
  decoded_path: string;
272
+ /** Whether this entry describes the value at `cbor_path`, or the
273
+ * *key* of a map entry at that path. Map entries with named keys
274
+ * produce both a `"key"` entry (CBOR span = key bytes, CDDL span
275
+ * = `name:` / `<value>:` declaration) and a `"value"` entry; both
276
+ * carry the same `cbor_path` / `decoded_path`. Array slots, tag
277
+ * payloads, and root nodes are always `"value"`. */
278
+ entry_role: "key" | "value";
248
279
  /** Header byte range of the CBOR node. */
249
280
  cbor_byte_span: { offset: number; length: number };
250
281
  /** Whole-structure byte range (= `cbor_byte_span` for scalars). */
251
282
  cbor_anchor_span: { offset: number; length: number };
252
283
  /** Byte range in the CDDL source describing this position. */
253
- cddl_byte_span: { offset: number; length: number; line: number };
284
+ cddl_byte_span: SourceSpan;
254
285
  /** Name of the CDDL rule that matched, if a rule boundary was crossed. */
255
286
  rule_name?: string;
256
287
  /** CBOR node's wire type (`U8`, `Bytes`, `Map`, `Array`, `Tag`, …). */
@@ -289,6 +320,29 @@ export function map_cbor_to_cddl(
289
320
  * Sub-structures the schema doesn't cover fall back to a raw
290
321
  * representation (under `@extra` for maps / `@positional` for arrays),
291
322
  * so partial matches still yield useful output.
323
+ *
324
+ * **Map output shape**: by default we emit JSON objects (`{a: 1, b: 2}`)
325
+ * for the convenient case. We switch to a wire-order-preserving array
326
+ * form `{ "@entries": [{ key, value, match: { via, label } }, ...] }`
327
+ * when the JSON object form would lose information:
328
+ *
329
+ * * any cbor key is a complex value (Array / Map / Tag / non-standard
330
+ * Simple) — JSON objects can only have string keys.
331
+ * * the cbor map has duplicate keys (RFC 8949 §5.6 — non-canonical
332
+ * but legal). Collapsing into a value-array would drop the
333
+ * interleaving order with surrounding entries.
334
+ *
335
+ * In `@entries` form, each pair carries a `match` field describing how
336
+ * the cbor key was matched against the schema:
337
+ * * `match.via: "literal"` — bareword / literal value match;
338
+ * `match.label` is the literal text.
339
+ * * `match.via: "type"` — `<type1> => …` schema, the key conforms
340
+ * to a type (e.g. `policy_id => …`); `match.label` is `null`.
341
+ * * `match.via: "unmatched"` — no schema entry accepted this key,
342
+ * `key` and `value` are raw decoded forms; `match.label` is `null`.
343
+ *
344
+ * Almost all Cardano maps (txbody, multiasset, witness_set) use object
345
+ * form; the `@entries` form only kicks in for the unusual cases above.
292
346
  * @param {string} cbor_hex
293
347
  * @param {string} cddl
294
348
  * @param {string} rule_name
@@ -519,7 +573,7 @@ export interface CddlErrorInfo {
519
573
  * Byte range in the CDDL source the parser tripped over, when the
520
574
  * error has positional info. Useful for IDE squiggly underlines.
521
575
  */
522
- byte_span?: { offset: number; length: number; line: number };
576
+ byte_span?: SourceSpan;
523
577
  }
524
578
 
525
579
  export type CborValidationResult =
@@ -553,7 +607,7 @@ export interface CborValidationErrorInfo {
553
607
  * the AST in parallel with `path`). Useful for highlighting the
554
608
  * offending CDDL rule in editors.
555
609
  */
556
- cddl_byte_span?: { offset: number; length: number; line: number };
610
+ cddl_byte_span?: SourceSpan;
557
611
  /** Other validation errors reported in the same run. */
558
612
  additional?: CborValidationErrorInfo[];
559
613
  }
Binary file
@@ -4,7 +4,11 @@ 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 extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
7
+ export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
8
+ export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
9
+ export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
10
+ export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
11
+ export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
8
12
  export const cbor_to_json: (a: number, b: number) => [number, number, number];
9
13
  export const cddl_format: (a: number, b: number) => [number, number, number, number];
10
14
  export const cddl_outline: (a: number, b: number) => [number, number, number];
@@ -14,11 +18,7 @@ export const decode_cbor_against_cddl: (a: number, b: number, c: number, d: numb
14
18
  export const map_cbor_to_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
15
19
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
16
20
  export const validate_cddl: (a: number, b: number) => [number, number, number];
17
- export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
18
- export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
19
- export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
20
- export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
21
- export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
21
+ export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
22
22
  export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
23
23
  export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
24
24
  export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
@@ -171,6 +171,30 @@ export function validate_cbor_against_cddl(
171
171
  rule_name: string
172
172
  ): CborValidationResult;
173
173
 
174
+ /**
175
+ * **CDDL spans carry both byte and char offsets.** `offset`/`length`
176
+ * count UTF-8 bytes (what `pest` reports); `char_offset`/`char_length`
177
+ * count UTF-16 code units — the unit JS strings, `string.slice`,
178
+ * editor APIs, and the LSP protocol use. For ASCII-only sources the
179
+ * two pairs are identical.
180
+ *
181
+ * **CBOR spans are byte offsets only** — into the decoded CBOR buffer.
182
+ * If you have a hex string, multiply by 2 to slice the hex view:
183
+ * `hex.slice(off*2, (off+len)*2)`.
184
+ */
185
+ export interface SourceSpan {
186
+ /** UTF-8 byte offset in the source. */
187
+ offset: number;
188
+ /** UTF-8 byte length. */
189
+ length: number;
190
+ /** UTF-16 code unit offset (= `string.slice`-friendly). */
191
+ char_offset: number;
192
+ /** UTF-16 code unit length. */
193
+ char_length: number;
194
+ /** 1-indexed line. */
195
+ line: number;
196
+ }
197
+
174
198
  /** Outline entry — one rule from `cddl_outline`. */
175
199
  export interface CddlOutlineEntry {
176
200
  /** Rule name (`transaction_body`, `set`, …). */
@@ -178,9 +202,9 @@ export interface CddlOutlineEntry {
178
202
  /** `"type"` for `=`, `"group"` for `( … )`. */
179
203
  kind: "type" | "group";
180
204
  /** Byte range covering the whole `name = …` rule definition. */
181
- span: { offset: number; length: number; line: number };
205
+ span: SourceSpan;
182
206
  /** Byte range of just the rule's name identifier. */
183
- name_span: { offset: number; length: number; line: number };
207
+ name_span: SourceSpan;
184
208
  }
185
209
 
186
210
  /** Result of `cddl_symbol_at`. `null` when the cursor isn't on an identifier. */
@@ -190,15 +214,15 @@ export type CddlSymbolAtResult =
190
214
  name: string;
191
215
  kind: "type" | "group" | "rule_reference" | "prelude_or_unknown";
192
216
  role: "definition" | "use";
193
- span: { offset: number; length: number; line: number };
194
- definition_span: { offset: number; length: number; line: number } | null;
195
- rule_span: { offset: number; length: number; line: number } | null;
217
+ span: SourceSpan;
218
+ definition_span: SourceSpan | null;
219
+ rule_span: SourceSpan | null;
196
220
  };
197
221
 
198
222
  /** Result of `cddl_references`. */
199
223
  export interface CddlReferencesResult {
200
- definition: { offset: number; length: number; line: number } | null;
201
- uses: { offset: number; length: number; line: number }[];
224
+ definition: SourceSpan | null;
225
+ uses: SourceSpan[];
202
226
  }
203
227
 
204
228
  /**
@@ -245,12 +269,19 @@ export interface CborCddlMapEntry {
245
269
  * except 0 / 2 / 3) the inner gets an extra `["@value"]` segment
246
270
  * to match the `{@tag, @value}` wrapper the decoder emits. */
247
271
  decoded_path: string;
272
+ /** Whether this entry describes the value at `cbor_path`, or the
273
+ * *key* of a map entry at that path. Map entries with named keys
274
+ * produce both a `"key"` entry (CBOR span = key bytes, CDDL span
275
+ * = `name:` / `<value>:` declaration) and a `"value"` entry; both
276
+ * carry the same `cbor_path` / `decoded_path`. Array slots, tag
277
+ * payloads, and root nodes are always `"value"`. */
278
+ entry_role: "key" | "value";
248
279
  /** Header byte range of the CBOR node. */
249
280
  cbor_byte_span: { offset: number; length: number };
250
281
  /** Whole-structure byte range (= `cbor_byte_span` for scalars). */
251
282
  cbor_anchor_span: { offset: number; length: number };
252
283
  /** Byte range in the CDDL source describing this position. */
253
- cddl_byte_span: { offset: number; length: number; line: number };
284
+ cddl_byte_span: SourceSpan;
254
285
  /** Name of the CDDL rule that matched, if a rule boundary was crossed. */
255
286
  rule_name?: string;
256
287
  /** CBOR node's wire type (`U8`, `Bytes`, `Map`, `Array`, `Tag`, …). */
@@ -289,6 +320,29 @@ export function map_cbor_to_cddl(
289
320
  * Sub-structures the schema doesn't cover fall back to a raw
290
321
  * representation (under `@extra` for maps / `@positional` for arrays),
291
322
  * so partial matches still yield useful output.
323
+ *
324
+ * **Map output shape**: by default we emit JSON objects (`{a: 1, b: 2}`)
325
+ * for the convenient case. We switch to a wire-order-preserving array
326
+ * form `{ "@entries": [{ key, value, match: { via, label } }, ...] }`
327
+ * when the JSON object form would lose information:
328
+ *
329
+ * * any cbor key is a complex value (Array / Map / Tag / non-standard
330
+ * Simple) — JSON objects can only have string keys.
331
+ * * the cbor map has duplicate keys (RFC 8949 §5.6 — non-canonical
332
+ * but legal). Collapsing into a value-array would drop the
333
+ * interleaving order with surrounding entries.
334
+ *
335
+ * In `@entries` form, each pair carries a `match` field describing how
336
+ * the cbor key was matched against the schema:
337
+ * * `match.via: "literal"` — bareword / literal value match;
338
+ * `match.label` is the literal text.
339
+ * * `match.via: "type"` — `<type1> => …` schema, the key conforms
340
+ * to a type (e.g. `policy_id => …`); `match.label` is `null`.
341
+ * * `match.via: "unmatched"` — no schema entry accepted this key,
342
+ * `key` and `value` are raw decoded forms; `match.label` is `null`.
343
+ *
344
+ * Almost all Cardano maps (txbody, multiasset, witness_set) use object
345
+ * form; the `@entries` form only kicks in for the unusual cases above.
292
346
  * @param {string} cbor_hex
293
347
  * @param {string} cddl
294
348
  * @param {string} rule_name
@@ -519,7 +573,7 @@ export interface CddlErrorInfo {
519
573
  * Byte range in the CDDL source the parser tripped over, when the
520
574
  * error has positional info. Useful for IDE squiggly underlines.
521
575
  */
522
- byte_span?: { offset: number; length: number; line: number };
576
+ byte_span?: SourceSpan;
523
577
  }
524
578
 
525
579
  export type CborValidationResult =
@@ -553,7 +607,7 @@ export interface CborValidationErrorInfo {
553
607
  * the AST in parallel with `path`). Useful for highlighting the
554
608
  * offending CDDL rule in editors.
555
609
  */
556
- cddl_byte_span?: { offset: number; length: number; line: number };
610
+ cddl_byte_span?: SourceSpan;
557
611
  /** Other validation errors reported in the same run. */
558
612
  additional?: CborValidationErrorInfo[];
559
613
  }
Binary file
@@ -4,7 +4,11 @@ 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 extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
7
+ export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
8
+ export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
9
+ export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
10
+ export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
11
+ export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
8
12
  export const cbor_to_json: (a: number, b: number) => [number, number, number];
9
13
  export const cddl_format: (a: number, b: number) => [number, number, number, number];
10
14
  export const cddl_outline: (a: number, b: number) => [number, number, number];
@@ -14,11 +18,7 @@ export const decode_cbor_against_cddl: (a: number, b: number, c: number, d: numb
14
18
  export const map_cbor_to_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
15
19
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
16
20
  export const validate_cddl: (a: number, b: number) => [number, number, number];
17
- export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
18
- export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
19
- export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
20
- export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
21
- export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
21
+ export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
22
22
  export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
23
23
  export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
24
24
  export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
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.52",
7
+ "version": "0.1.0-beta.54",
8
8
  "license": "Apache-2.0",
9
9
  "files": [
10
10
  "node/cquisitor_lib_bg.wasm",