@cardananium/cquisitor-lib 0.1.0-beta.51 → 0.1.0-beta.53

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
@@ -353,9 +353,15 @@ validate_cddl("thing = {n: uint}");
353
353
  validate_cddl("thing = [unknown_rule, int]");
354
354
  // { valid: false, error: { kind: "unresolved_references",
355
355
  // message: "missing definition for rule unknown_rule" } }
356
+
357
+ validate_cddl("; only a comment\n");
358
+ // { valid: false, error: { kind: "no_rules",
359
+ // message: "CDDL document defines no rules" } }
356
360
  ```
357
361
 
358
- `error.kind` values: `"parse_error"`, `"unresolved_references"`.
362
+ Parser errors include a `byte_span: {offset, length, line}` so editors can squiggle the exact position pest tripped on.
363
+
364
+ `error.kind` values: `"parse_error"`, `"unresolved_references"`, `"no_rules"`.
359
365
 
360
366
  #### `validate_cbor_against_cddl(cbor_hex: string, cddl: string, rule_name: string): { valid: boolean, error?: object }`
361
367
 
@@ -378,7 +384,9 @@ validate_cbor_against_cddl("01", "thing = tstr", "thing");
378
384
 
379
385
  `error.cddl_byte_span` carries the byte range in the **CDDL source** pointing at the type the validator tried (and failed) to apply — useful for highlighting the offending rule in an editor. It's synthesised by walking the AST in parallel with `path`, so it's available for any error that has a meaningful `path`. When the `rule_name` you passed isn't the first rule of the document, the offsets are still expressed in *your* CDDL coordinates (the wrapper we use internally is invisible to callers).
380
386
 
381
- `error.kind` values: `"parse_error"`, `"unresolved_references"`, `"missing_rule"`, `"input_parse"`, `"mismatch"`, `"map_cut"`, `"generic"`. When multiple violations fire, the headline goes in the top-level fields and the rest land in `error.additional`.
387
+ `error.kind` values: `"parse_error"`, `"unresolved_references"`, `"no_rules"`, `"missing_rule"`, `"input_parse"`, `"mismatch"`, `"map_cut"`, `"generic"`. When multiple violations fire, the headline goes in the top-level fields and the rest land in `error.additional`.
388
+
389
+ `anchor_spans` is always populated — for container values (Map / Array / Tag / indefinite strings) it covers the whole structure; for scalars it falls back to `position_info` so a UI's halo highlight always has something to draw.
382
390
 
383
391
  #### `decode_cbor_against_cddl(cbor_hex: string, cddl: string, rule_name: string): unknown`
384
392
 
@@ -431,9 +439,10 @@ cddl_symbol_at("coin = uint\nfee = coin", /* offset = */ 18);
431
439
  // definition_span: {offset: 0, length: 4, line: 1},
432
440
  // rule_span: {offset: 0, length: 11, line: 1}}
433
441
 
434
- // Re-format — round-trip via Display.
435
- cddl_format("alpha = uint");
436
- // "alpha = uint"
442
+ // Re-format — round-trip via Display. Comments survive
443
+ // (both standalone `; …` and trailing `; …`).
444
+ cddl_format("; header\nalpha = uint ; trailing");
445
+ // "; header\nalpha = uint ; trailing\n"
437
446
  ```
438
447
 
439
448
  `validate_cddl` itself returns a `byte_span` on parser errors so editor-side squiggles can underline the offending position directly:
@@ -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
  /**
@@ -232,6 +256,59 @@ export function cddl_symbol_at(cddl: string, offset: number): CddlSymbolAtResult
232
256
  */
233
257
  export function cddl_format(cddl: string): string;
234
258
 
259
+ /** One entry from `map_cbor_to_cddl`: a single position of a CBOR
260
+ * node, the type that matched it, and the path it ends up at in the
261
+ * output of `decode_cbor_against_cddl`. */
262
+ export interface CborCddlMapEntry {
263
+ /** Path into the *raw* CBOR tree (numeric map keys are bracketed). */
264
+ cbor_path: string;
265
+ /** Path into the labelled JSON returned by `decode_cbor_against_cddl`.
266
+ * Numeric map keys come back as bracket-quoted strings (`["0"]`)
267
+ * because decoded JSON has only string keys; identifier-safe keys
268
+ * use dot notation (`.name`). For unspecialised tags (anything
269
+ * except 0 / 2 / 3) the inner gets an extra `["@value"]` segment
270
+ * to match the `{@tag, @value}` wrapper the decoder emits. */
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";
279
+ /** Header byte range of the CBOR node. */
280
+ cbor_byte_span: { offset: number; length: number };
281
+ /** Whole-structure byte range (= `cbor_byte_span` for scalars). */
282
+ cbor_anchor_span: { offset: number; length: number };
283
+ /** Byte range in the CDDL source describing this position. */
284
+ cddl_byte_span: SourceSpan;
285
+ /** Name of the CDDL rule that matched, if a rule boundary was crossed. */
286
+ rule_name?: string;
287
+ /** CBOR node's wire type (`U8`, `Bytes`, `Map`, `Array`, `Tag`, …). */
288
+ cbor_type?: string;
289
+ }
290
+
291
+ /**
292
+ * Returns a flat list of mapping entries pairing each visited CBOR node
293
+ * with the CDDL position that describes it. Use it to wire
294
+ * bidirectional highlight between a CBOR panel and a CDDL panel without
295
+ * needing a validation error to trigger it.
296
+ *
297
+ * Order is depth-first pre-order, so a parent's entry precedes its
298
+ * children's. Tags in the CBOR are transparent to the path grammar
299
+ * (anweiss-style): `Tag(258, [...])` is walked as if the tag wrapper
300
+ * weren't there when matching against `[* a]`-shaped schemas.
301
+ *
302
+ * @param cbor_hex
303
+ * @param cddl
304
+ * @param rule_name
305
+ */
306
+ export function map_cbor_to_cddl(
307
+ cbor_hex: string,
308
+ cddl: string,
309
+ rule_name: string
310
+ ): CborCddlMapEntry[];
311
+
235
312
  /**
236
313
  * Maps decoded CBOR onto a CDDL schema and returns labelled JSON. Where
237
314
  * `cbor_to_json` returns positional CBOR (numeric map keys, raw arrays),
@@ -473,7 +550,7 @@ export interface CddlErrorInfo {
473
550
  * Byte range in the CDDL source the parser tripped over, when the
474
551
  * error has positional info. Useful for IDE squiggly underlines.
475
552
  */
476
- byte_span?: { offset: number; length: number; line: number };
553
+ byte_span?: SourceSpan;
477
554
  }
478
555
 
479
556
  export type CborValidationResult =
@@ -507,7 +584,7 @@ export interface CborValidationErrorInfo {
507
584
  * the AST in parallel with `path`). Useful for highlighting the
508
585
  * offending CDDL rule in editors.
509
586
  */
510
- cddl_byte_span?: { offset: number; length: number; line: number };
587
+ cddl_byte_span?: SourceSpan;
511
588
  /** Other validation errors reported in the same run. */
512
589
  additional?: CborValidationErrorInfo[];
513
590
  }
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./cquisitor_lib_bg.js";
5
5
  __wbg_set_wasm(wasm);
6
6
  wasm.__wbindgen_start();
7
7
  export {
8
- Address, AddressKind, Anchor, AnchorDataHash, AssetName, AssetNames, Assets, AuxiliaryData, AuxiliaryDataHash, AuxiliaryDataSet, BaseAddress, BigInt, BigNum, Bip32PrivateKey, Bip32PublicKey, Block, BlockEra, BlockHash, BootstrapWitness, BootstrapWitnesses, ByronAddress, ByronAddressType, CborContainerType, CborSetType, Certificate, CertificateKind, Certificates, CertificatesBuilder, ChangeConfig, CoinSelectionStrategyCIP2, Committee, CommitteeColdResign, CommitteeHotAuth, Constitution, ConstrPlutusData, CostModel, Costmdls, CredKind, Credential, Credentials, DNSRecordAorAAAA, DNSRecordSRV, DRep, DRepDeregistration, DRepKind, DRepRegistration, DRepUpdate, DRepVotingThresholds, DataCost, DataHash, DatumSource, Ed25519KeyHash, Ed25519KeyHashes, Ed25519Signature, EnterpriseAddress, ExUnitPrices, ExUnits, FixedBlock, FixedTransaction, FixedTransactionBodies, FixedTransactionBody, FixedTxWitnessesSet, FixedVersionedBlock, GeneralTransactionMetadata, GenesisDelegateHash, GenesisHash, GenesisHashes, GenesisKeyDelegation, GovernanceAction, GovernanceActionId, GovernanceActionIds, GovernanceActionKind, HardForkInitiationAction, Header, HeaderBody, InfoAction, Int, Ipv4, Ipv6, KESSignature, KESVKey, Language, LanguageKind, Languages, LegacyDaedalusPrivateKey, LinearFee, MIRKind, MIRPot, MIRToStakeCredentials, MalformedAddress, MetadataJsonSchema, MetadataList, MetadataMap, Mint, MintAssets, MintBuilder, MintWitness, MintsAssets, MoveInstantaneousReward, MoveInstantaneousRewardsCert, MultiAsset, MultiHostName, NativeScript, NativeScriptKind, NativeScriptSource, NativeScripts, NetworkId, NetworkIdKind, NetworkInfo, NewConstitutionAction, NoConfidenceAction, Nonce, OperationalCert, OutputDatum, ParameterChangeAction, PlutusData, PlutusDataKind, PlutusDatumSchema, PlutusList, PlutusMap, PlutusMapValues, PlutusScript, PlutusScriptSource, PlutusScripts, PlutusWitness, PlutusWitnesses, Pointer, PointerAddress, PoolMetadata, PoolMetadataHash, PoolParams, PoolRegistration, PoolRetirement, PoolVotingThresholds, PrivateKey, ProposedProtocolParameterUpdates, ProtocolParamUpdate, ProtocolVersion, PublicKey, PublicKeys, Redeemer, RedeemerTag, RedeemerTagKind, Redeemers, Relay, RelayKind, Relays, RewardAddress, RewardAddresses, ScriptAll, ScriptAny, ScriptDataHash, ScriptHash, ScriptHashNamespace, ScriptHashes, ScriptNOfK, ScriptPubkey, ScriptRef, ScriptSchema, SingleHostAddr, SingleHostName, StakeAndVoteDelegation, StakeDelegation, StakeDeregistration, StakeRegistration, StakeRegistrationAndDelegation, StakeVoteRegistrationAndDelegation, Strings, TimelockExpiry, TimelockStart, Transaction, TransactionBatch, TransactionBatchList, TransactionBodies, TransactionBody, TransactionBuilder, TransactionBuilderConfig, TransactionBuilderConfigBuilder, TransactionHash, TransactionInput, TransactionInputs, TransactionMetadatum, TransactionMetadatumKind, TransactionMetadatumLabels, TransactionOutput, TransactionOutputAmountBuilder, TransactionOutputBuilder, TransactionOutputs, TransactionSetsState, TransactionUnspentOutput, TransactionUnspentOutputs, TransactionWitnessSet, TransactionWitnessSets, TreasuryWithdrawals, TreasuryWithdrawalsAction, TxInputsBuilder, URL, UnitInterval, Update, UpdateCommitteeAction, VRFCert, VRFKeyHash, VRFVKey, Value, VersionedBlock, Vkey, Vkeys, Vkeywitness, Vkeywitnesses, VoteDelegation, VoteKind, VoteRegistrationAndDelegation, Voter, VoterKind, Voters, VotingBuilder, VotingProcedure, VotingProcedures, VotingProposal, VotingProposalBuilder, VotingProposals, Withdrawals, WithdrawalsBuilder, calculate_ex_units_ceil_cost, cbor_to_json, cddl_format, cddl_from_str, cddl_outline, cddl_references, cddl_symbol_at, check_block_or_tx_signatures, create_send_all, decode_arbitrary_bytes_from_metadatum, decode_cbor_against_cddl, decode_metadatum_to_json_str, decode_plutus_datum_to_json_str, decode_plutus_program_pretty_uplc, decode_plutus_program_uplc_json, decode_specific_type, decrypt_with_password, encode_arbitrary_bytes_as_metadatum, encode_json_str_to_metadatum, encode_json_str_to_native_script, encode_json_str_to_plutus_datum, encrypt_with_password, execute_tx_scripts, extract_hashes_from_transaction_js, get_decodable_types, get_deposit, get_implicit_input, get_necessary_data_list_js, get_possible_types_for_input, get_ref_script_bytes, get_utxo_list_from_tx, has_transaction_set_tag, hash_auxiliary_data, hash_plutus_data, hash_script_data, make_daedalus_bootstrap_witness, make_icarus_bootstrap_witness, make_vkey_witness, min_ada_for_output, min_fee, min_ref_script_fee, min_script_fee, validate_cbor_against_cddl, validate_cbor_from_slice, validate_cddl, validate_cddl_from_str, validate_json_from_str, validate_transaction_js
8
+ Address, AddressKind, Anchor, AnchorDataHash, AssetName, AssetNames, Assets, AuxiliaryData, AuxiliaryDataHash, AuxiliaryDataSet, BaseAddress, BigInt, BigNum, Bip32PrivateKey, Bip32PublicKey, Block, BlockEra, BlockHash, BootstrapWitness, BootstrapWitnesses, ByronAddress, ByronAddressType, CborContainerType, CborSetType, Certificate, CertificateKind, Certificates, CertificatesBuilder, ChangeConfig, CoinSelectionStrategyCIP2, Committee, CommitteeColdResign, CommitteeHotAuth, Constitution, ConstrPlutusData, CostModel, Costmdls, CredKind, Credential, Credentials, DNSRecordAorAAAA, DNSRecordSRV, DRep, DRepDeregistration, DRepKind, DRepRegistration, DRepUpdate, DRepVotingThresholds, DataCost, DataHash, DatumSource, Ed25519KeyHash, Ed25519KeyHashes, Ed25519Signature, EnterpriseAddress, ExUnitPrices, ExUnits, FixedBlock, FixedTransaction, FixedTransactionBodies, FixedTransactionBody, FixedTxWitnessesSet, FixedVersionedBlock, GeneralTransactionMetadata, GenesisDelegateHash, GenesisHash, GenesisHashes, GenesisKeyDelegation, GovernanceAction, GovernanceActionId, GovernanceActionIds, GovernanceActionKind, HardForkInitiationAction, Header, HeaderBody, InfoAction, Int, Ipv4, Ipv6, KESSignature, KESVKey, Language, LanguageKind, Languages, LegacyDaedalusPrivateKey, LinearFee, MIRKind, MIRPot, MIRToStakeCredentials, MalformedAddress, MetadataJsonSchema, MetadataList, MetadataMap, Mint, MintAssets, MintBuilder, MintWitness, MintsAssets, MoveInstantaneousReward, MoveInstantaneousRewardsCert, MultiAsset, MultiHostName, NativeScript, NativeScriptKind, NativeScriptSource, NativeScripts, NetworkId, NetworkIdKind, NetworkInfo, NewConstitutionAction, NoConfidenceAction, Nonce, OperationalCert, OutputDatum, ParameterChangeAction, PlutusData, PlutusDataKind, PlutusDatumSchema, PlutusList, PlutusMap, PlutusMapValues, PlutusScript, PlutusScriptSource, PlutusScripts, PlutusWitness, PlutusWitnesses, Pointer, PointerAddress, PoolMetadata, PoolMetadataHash, PoolParams, PoolRegistration, PoolRetirement, PoolVotingThresholds, PrivateKey, ProposedProtocolParameterUpdates, ProtocolParamUpdate, ProtocolVersion, PublicKey, PublicKeys, Redeemer, RedeemerTag, RedeemerTagKind, Redeemers, Relay, RelayKind, Relays, RewardAddress, RewardAddresses, ScriptAll, ScriptAny, ScriptDataHash, ScriptHash, ScriptHashNamespace, ScriptHashes, ScriptNOfK, ScriptPubkey, ScriptRef, ScriptSchema, SingleHostAddr, SingleHostName, StakeAndVoteDelegation, StakeDelegation, StakeDeregistration, StakeRegistration, StakeRegistrationAndDelegation, StakeVoteRegistrationAndDelegation, Strings, TimelockExpiry, TimelockStart, Transaction, TransactionBatch, TransactionBatchList, TransactionBodies, TransactionBody, TransactionBuilder, TransactionBuilderConfig, TransactionBuilderConfigBuilder, TransactionHash, TransactionInput, TransactionInputs, TransactionMetadatum, TransactionMetadatumKind, TransactionMetadatumLabels, TransactionOutput, TransactionOutputAmountBuilder, TransactionOutputBuilder, TransactionOutputs, TransactionSetsState, TransactionUnspentOutput, TransactionUnspentOutputs, TransactionWitnessSet, TransactionWitnessSets, TreasuryWithdrawals, TreasuryWithdrawalsAction, TxInputsBuilder, URL, UnitInterval, Update, UpdateCommitteeAction, VRFCert, VRFKeyHash, VRFVKey, Value, VersionedBlock, Vkey, Vkeys, Vkeywitness, Vkeywitnesses, VoteDelegation, VoteKind, VoteRegistrationAndDelegation, Voter, VoterKind, Voters, VotingBuilder, VotingProcedure, VotingProcedures, VotingProposal, VotingProposalBuilder, VotingProposals, Withdrawals, WithdrawalsBuilder, calculate_ex_units_ceil_cost, cbor_to_json, cddl_format, cddl_from_str, cddl_outline, cddl_references, cddl_symbol_at, check_block_or_tx_signatures, create_send_all, decode_arbitrary_bytes_from_metadatum, decode_cbor_against_cddl, decode_metadatum_to_json_str, decode_plutus_datum_to_json_str, decode_plutus_program_pretty_uplc, decode_plutus_program_uplc_json, decode_specific_type, decrypt_with_password, encode_arbitrary_bytes_as_metadatum, encode_json_str_to_metadatum, encode_json_str_to_native_script, encode_json_str_to_plutus_datum, encrypt_with_password, execute_tx_scripts, extract_hashes_from_transaction_js, get_decodable_types, get_deposit, get_implicit_input, get_necessary_data_list_js, get_possible_types_for_input, get_ref_script_bytes, get_utxo_list_from_tx, has_transaction_set_tag, hash_auxiliary_data, hash_plutus_data, hash_script_data, make_daedalus_bootstrap_witness, make_icarus_bootstrap_witness, make_vkey_witness, map_cbor_to_cddl, min_ada_for_output, min_fee, min_ref_script_fee, min_script_fee, validate_cbor_against_cddl, validate_cbor_from_slice, validate_cddl, validate_cddl_from_str, validate_json_from_str, validate_transaction_js
9
9
  } from "./cquisitor_lib_bg.js";
@@ -29149,6 +29149,31 @@ export function make_vkey_witness(tx_body_hash, sk) {
29149
29149
  return Vkeywitness.__wrap(ret);
29150
29150
  }
29151
29151
 
29152
+ /**
29153
+ * Returns a flat list of `{cbor_path, cbor_byte_span, cbor_anchor_span,
29154
+ * cddl_byte_span, rule_name?}` entries — one per node visited during a
29155
+ * parallel CBOR ↔ CDDL traversal. Use it to wire bidirectional
29156
+ * highlight between a CBOR panel and a CDDL panel without needing a
29157
+ * validation error to trigger it.
29158
+ * @param {string} cbor_hex
29159
+ * @param {string} cddl
29160
+ * @param {string} rule_name
29161
+ * @returns {any}
29162
+ */
29163
+ export function map_cbor_to_cddl(cbor_hex, cddl, rule_name) {
29164
+ const ptr0 = passStringToWasm0(cbor_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29165
+ const len0 = WASM_VECTOR_LEN;
29166
+ const ptr1 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29167
+ const len1 = WASM_VECTOR_LEN;
29168
+ const ptr2 = passStringToWasm0(rule_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29169
+ const len2 = WASM_VECTOR_LEN;
29170
+ const ret = wasm.map_cbor_to_cddl(ptr0, len0, ptr1, len1, ptr2, len2);
29171
+ if (ret[2]) {
29172
+ throw takeFromExternrefTable0(ret[1]);
29173
+ }
29174
+ return takeFromExternrefTable0(ret[0]);
29175
+ }
29176
+
29152
29177
  /**
29153
29178
  * returns minimal amount of ada for the output for case when the amount is included to the output
29154
29179
  * @param {TransactionOutput} output
Binary file
@@ -7,20 +7,21 @@ export const get_possible_types_for_input: (a: number, b: number) => [number, nu
7
7
  export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
8
8
  export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
9
  export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
+ export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
11
+ export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
12
+ export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
13
+ export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
14
+ export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
15
+ export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
10
16
  export const cbor_to_json: (a: number, b: number) => [number, number, number];
11
17
  export const cddl_format: (a: number, b: number) => [number, number, number, number];
12
18
  export const cddl_outline: (a: number, b: number) => [number, number, number];
13
19
  export const cddl_references: (a: number, b: number, c: number, d: number) => [number, number, number];
14
20
  export const cddl_symbol_at: (a: number, b: number, c: number) => [number, number, number];
15
21
  export const decode_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
22
+ export const map_cbor_to_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
16
23
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
17
24
  export const validate_cddl: (a: number, b: number) => [number, number, number];
18
- export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
19
- export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
20
- export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
21
- export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
22
- export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
23
- export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
24
25
  export const validate_cbor_from_slice: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
25
26
  export const validate_json_from_str: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
26
27
  export const cddl_from_str: (a: number, b: 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
  /**
@@ -232,6 +256,59 @@ export function cddl_symbol_at(cddl: string, offset: number): CddlSymbolAtResult
232
256
  */
233
257
  export function cddl_format(cddl: string): string;
234
258
 
259
+ /** One entry from `map_cbor_to_cddl`: a single position of a CBOR
260
+ * node, the type that matched it, and the path it ends up at in the
261
+ * output of `decode_cbor_against_cddl`. */
262
+ export interface CborCddlMapEntry {
263
+ /** Path into the *raw* CBOR tree (numeric map keys are bracketed). */
264
+ cbor_path: string;
265
+ /** Path into the labelled JSON returned by `decode_cbor_against_cddl`.
266
+ * Numeric map keys come back as bracket-quoted strings (`["0"]`)
267
+ * because decoded JSON has only string keys; identifier-safe keys
268
+ * use dot notation (`.name`). For unspecialised tags (anything
269
+ * except 0 / 2 / 3) the inner gets an extra `["@value"]` segment
270
+ * to match the `{@tag, @value}` wrapper the decoder emits. */
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";
279
+ /** Header byte range of the CBOR node. */
280
+ cbor_byte_span: { offset: number; length: number };
281
+ /** Whole-structure byte range (= `cbor_byte_span` for scalars). */
282
+ cbor_anchor_span: { offset: number; length: number };
283
+ /** Byte range in the CDDL source describing this position. */
284
+ cddl_byte_span: SourceSpan;
285
+ /** Name of the CDDL rule that matched, if a rule boundary was crossed. */
286
+ rule_name?: string;
287
+ /** CBOR node's wire type (`U8`, `Bytes`, `Map`, `Array`, `Tag`, …). */
288
+ cbor_type?: string;
289
+ }
290
+
291
+ /**
292
+ * Returns a flat list of mapping entries pairing each visited CBOR node
293
+ * with the CDDL position that describes it. Use it to wire
294
+ * bidirectional highlight between a CBOR panel and a CDDL panel without
295
+ * needing a validation error to trigger it.
296
+ *
297
+ * Order is depth-first pre-order, so a parent's entry precedes its
298
+ * children's. Tags in the CBOR are transparent to the path grammar
299
+ * (anweiss-style): `Tag(258, [...])` is walked as if the tag wrapper
300
+ * weren't there when matching against `[* a]`-shaped schemas.
301
+ *
302
+ * @param cbor_hex
303
+ * @param cddl
304
+ * @param rule_name
305
+ */
306
+ export function map_cbor_to_cddl(
307
+ cbor_hex: string,
308
+ cddl: string,
309
+ rule_name: string
310
+ ): CborCddlMapEntry[];
311
+
235
312
  /**
236
313
  * Maps decoded CBOR onto a CDDL schema and returns labelled JSON. Where
237
314
  * `cbor_to_json` returns positional CBOR (numeric map keys, raw arrays),
@@ -473,7 +550,7 @@ export interface CddlErrorInfo {
473
550
  * Byte range in the CDDL source the parser tripped over, when the
474
551
  * error has positional info. Useful for IDE squiggly underlines.
475
552
  */
476
- byte_span?: { offset: number; length: number; line: number };
553
+ byte_span?: SourceSpan;
477
554
  }
478
555
 
479
556
  export type CborValidationResult =
@@ -507,7 +584,7 @@ export interface CborValidationErrorInfo {
507
584
  * the AST in parallel with `path`). Useful for highlighting the
508
585
  * offending CDDL rule in editors.
509
586
  */
510
- cddl_byte_span?: { offset: number; length: number; line: number };
587
+ cddl_byte_span?: SourceSpan;
511
588
  /** Other validation errors reported in the same run. */
512
589
  additional?: CborValidationErrorInfo[];
513
590
  }
@@ -29412,6 +29412,32 @@ function make_vkey_witness(tx_body_hash, sk) {
29412
29412
  }
29413
29413
  exports.make_vkey_witness = make_vkey_witness;
29414
29414
 
29415
+ /**
29416
+ * Returns a flat list of `{cbor_path, cbor_byte_span, cbor_anchor_span,
29417
+ * cddl_byte_span, rule_name?}` entries — one per node visited during a
29418
+ * parallel CBOR ↔ CDDL traversal. Use it to wire bidirectional
29419
+ * highlight between a CBOR panel and a CDDL panel without needing a
29420
+ * validation error to trigger it.
29421
+ * @param {string} cbor_hex
29422
+ * @param {string} cddl
29423
+ * @param {string} rule_name
29424
+ * @returns {any}
29425
+ */
29426
+ function map_cbor_to_cddl(cbor_hex, cddl, rule_name) {
29427
+ const ptr0 = passStringToWasm0(cbor_hex, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29428
+ const len0 = WASM_VECTOR_LEN;
29429
+ const ptr1 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29430
+ const len1 = WASM_VECTOR_LEN;
29431
+ const ptr2 = passStringToWasm0(rule_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29432
+ const len2 = WASM_VECTOR_LEN;
29433
+ const ret = wasm.map_cbor_to_cddl(ptr0, len0, ptr1, len1, ptr2, len2);
29434
+ if (ret[2]) {
29435
+ throw takeFromExternrefTable0(ret[1]);
29436
+ }
29437
+ return takeFromExternrefTable0(ret[0]);
29438
+ }
29439
+ exports.map_cbor_to_cddl = map_cbor_to_cddl;
29440
+
29415
29441
  /**
29416
29442
  * returns minimal amount of ada for the output for case when the amount is included to the output
29417
29443
  * @param {TransactionOutput} output
Binary file
@@ -7,20 +7,21 @@ export const get_possible_types_for_input: (a: number, b: number) => [number, nu
7
7
  export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
8
8
  export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
9
  export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
+ export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
11
+ export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
12
+ export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
13
+ export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
14
+ export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
15
+ export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
10
16
  export const cbor_to_json: (a: number, b: number) => [number, number, number];
11
17
  export const cddl_format: (a: number, b: number) => [number, number, number, number];
12
18
  export const cddl_outline: (a: number, b: number) => [number, number, number];
13
19
  export const cddl_references: (a: number, b: number, c: number, d: number) => [number, number, number];
14
20
  export const cddl_symbol_at: (a: number, b: number, c: number) => [number, number, number];
15
21
  export const decode_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
22
+ export const map_cbor_to_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
16
23
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
17
24
  export const validate_cddl: (a: number, b: number) => [number, number, number];
18
- export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
19
- export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
20
- export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
21
- export const get_ref_script_bytes: (a: number, b: number, c: number) => [number, number, number, number];
22
- export const get_utxo_list_from_tx: (a: number, b: number) => [number, number, number, number];
23
- export const extract_hashes_from_transaction_js: (a: number, b: number) => [number, number, number, number];
24
25
  export const validate_cbor_from_slice: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
25
26
  export const validate_json_from_str: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
26
27
  export const cddl_from_str: (a: number, b: 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.51",
7
+ "version": "0.1.0-beta.53",
8
8
  "license": "Apache-2.0",
9
9
  "files": [
10
10
  "node/cquisitor_lib_bg.wasm",