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

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
@@ -25,9 +25,13 @@ Functions:
25
25
  ### CBOR Decoder & CDDL Validation
26
26
 
27
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
- - `validate_cddl(cddl)` - Parses a CDDL schema; reports parse errors and unresolved rule references (e.g. `thing = [unknown_rule, int]` → `kind: "unresolved_references"`).
29
- - `validate_cbor_against_cddl(cbor_hex, cddl, rule_name)` - Validates a CBOR payload against a named rule. Errors carry `kind`, `expected`, semantic `path`, byte/anchor spans, and an `additional` array when multiple violations fire.
28
+ - `validate_cddl(cddl)` - Parses a CDDL schema; reports parse errors (with a `byte_span` for editor squiggles) and unresolved rule references (e.g. `thing = [unknown_rule, int]` → `kind: "unresolved_references"`).
29
+ - `validate_cbor_against_cddl(cbor_hex, cddl, rule_name)` - Validates a CBOR payload against a named rule. Errors carry `kind`, `expected`, semantic `path`, byte/anchor spans, a `cddl_byte_span` pointing at the failing CDDL type, and an `additional` array when multiple violations fire.
30
30
  - `decode_cbor_against_cddl(cbor_hex, cddl, rule_name)` - Maps decoded CBOR onto a CDDL schema and returns labelled JSON (e.g. Cardano `[body, witness_set, bool, aux]` becomes `{transaction_body, transaction_witness_set, ...}`). Handles generics (`set<a>`), tagged sets, type rules used as field labels, and a few well-known tags (bignum → string number, datetime → ISO string). Sub-structures the schema doesn't cover surface under `@extra` / `@positional` so partial matches don't lose data.
31
+ - `cddl_outline(cddl)` - Returns one `{name, kind, span, name_span}` entry per top-level rule. Editor outline view, breadcrumbs, fuzzy "go to rule".
32
+ - `cddl_references(cddl, name)` - Returns `{definition, uses[]}` byte ranges for a rule name. Powers find-references and same-name highlighting on cursor.
33
+ - `cddl_symbol_at(cddl, offset)` - Returns the symbol under the cursor (or `null`), with `role: "definition" | "use"` and a `definition_span` pointing at its rule. Powers hover and Cmd-click go-to-definition.
34
+ - `cddl_format(cddl)` - Pretty-prints CDDL by round-tripping through the AST. Useful for format-on-save.
31
35
 
32
36
  ### Plutus Script Decoder
33
37
 
@@ -366,11 +370,14 @@ validate_cbor_against_cddl("01", "thing = tstr", "thing");
366
370
  // expected: "tstr",
367
371
  // path: "$",
368
372
  // byte_spans: [{ offset: 0, length: 1 }],
373
+ // cddl_byte_span: { offset: 8, length: 4, line: 1 }, // points at `tstr`
369
374
  // message: "expected type tstr, got Integer(Integer(1))"
370
375
  // }
371
376
  // }
372
377
  ```
373
378
 
379
+ `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
+
374
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`.
375
382
 
376
383
  #### `decode_cbor_against_cddl(cbor_hex: string, cddl: string, rule_name: string): unknown`
@@ -395,6 +402,48 @@ decode_cbor_against_cddl(txHex, conwayCddl, "transaction");
395
402
 
396
403
  Recognised features: type choices (first match wins), generics (`set<a>`), tagged data (well-known tags 0/2/3 specialised to ISO date / bignum string), rule references, optionals/repetitions, prelude scalars. Sub-structures the schema doesn't cover or that don't match any choice fall back to a raw form under `@extra` (maps) or `@positional` (arrays) so data is never silently dropped.
397
404
 
405
+ #### CDDL editor primitives
406
+
407
+ For embedding a CDDL editor / inspector. All four functions parse the document with the same checked parser as `validate_cddl` and throw on parse errors.
408
+
409
+ ```typescript
410
+ // Document outline — list every rule with its byte range.
411
+ cddl_outline("alpha = uint\nbeta = (a: int)");
412
+ // [
413
+ // {name: "alpha", kind: "type", span: {offset: 0, length: 12, line: 1},
414
+ // name_span: {offset: 0, length: 5, line: 1}},
415
+ // {name: "beta", kind: "group", span: {offset: 13, length: 14, line: 2},
416
+ // name_span: {offset: 13, length: 4, line: 2}}
417
+ // ]
418
+
419
+ // Find every use of a rule — the IDE "Find references" affordance.
420
+ cddl_references("coin = uint\noutput = [bstr, coin]\nfee = coin", "coin");
421
+ // {definition: {offset: 0, length: 4, line: 1},
422
+ // uses: [
423
+ // {offset: 26, length: 4, line: 2},
424
+ // {offset: 38, length: 4, line: 3}
425
+ // ]}
426
+
427
+ // Symbol at cursor — hover info and Cmd-click target.
428
+ cddl_symbol_at("coin = uint\nfee = coin", /* offset = */ 18);
429
+ // {name: "coin", kind: "rule_reference", role: "use",
430
+ // span: {offset: 18, length: 4, line: 2},
431
+ // definition_span: {offset: 0, length: 4, line: 1},
432
+ // rule_span: {offset: 0, length: 11, line: 1}}
433
+
434
+ // Re-format — round-trip via Display.
435
+ cddl_format("alpha = uint");
436
+ // "alpha = uint"
437
+ ```
438
+
439
+ `validate_cddl` itself returns a `byte_span` on parser errors so editor-side squiggles can underline the offending position directly:
440
+
441
+ ```typescript
442
+ validate_cddl("alpha = ");
443
+ // {valid: false,
444
+ // error: {kind: "parse_error", message: "...", byte_span: {offset: 8, length: 0, line: 1}}}
445
+ ```
446
+
398
447
  ### Plutus Script Decoder
399
448
 
400
449
  #### `decode_plutus_program_uplc_json(hex: string): ProgramJson`
@@ -171,6 +171,67 @@ export function validate_cbor_against_cddl(
171
171
  rule_name: string
172
172
  ): CborValidationResult;
173
173
 
174
+ /** Outline entry — one rule from `cddl_outline`. */
175
+ export interface CddlOutlineEntry {
176
+ /** Rule name (`transaction_body`, `set`, …). */
177
+ name: string;
178
+ /** `"type"` for `=`, `"group"` for `( … )`. */
179
+ kind: "type" | "group";
180
+ /** Byte range covering the whole `name = …` rule definition. */
181
+ span: { offset: number; length: number; line: number };
182
+ /** Byte range of just the rule's name identifier. */
183
+ name_span: { offset: number; length: number; line: number };
184
+ }
185
+
186
+ /** Result of `cddl_symbol_at`. `null` when the cursor isn't on an identifier. */
187
+ export type CddlSymbolAtResult =
188
+ | null
189
+ | {
190
+ name: string;
191
+ kind: "type" | "group" | "rule_reference" | "prelude_or_unknown";
192
+ 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;
196
+ };
197
+
198
+ /** Result of `cddl_references`. */
199
+ export interface CddlReferencesResult {
200
+ definition: { offset: number; length: number; line: number } | null;
201
+ uses: { offset: number; length: number; line: number }[];
202
+ }
203
+
204
+ /**
205
+ * Returns one entry per top-level rule (`{name, kind, span, name_span}`).
206
+ * Used for editor outline view, breadcrumbs, fuzzy "go to rule".
207
+ * @param cddl
208
+ */
209
+ export function cddl_outline(cddl: string): CddlOutlineEntry[];
210
+
211
+ /**
212
+ * Returns `{definition, uses[]}` byte ranges for the rule named `name`.
213
+ * Powers find-references and rename-aware highlighting.
214
+ * @param cddl
215
+ * @param name
216
+ */
217
+ export function cddl_references(cddl: string, name: string): CddlReferencesResult;
218
+
219
+ /**
220
+ * Returns the symbol under `offset` (or `null` if none). For uses,
221
+ * `definition_span` points at the rule's name — the "go to definition"
222
+ * target.
223
+ * @param cddl
224
+ * @param offset
225
+ */
226
+ export function cddl_symbol_at(cddl: string, offset: number): CddlSymbolAtResult;
227
+
228
+ /**
229
+ * Pretty-prints the CDDL by parsing it and serialising via `Display`.
230
+ * Useful for "format on save". Throws on invalid input.
231
+ * @param cddl
232
+ */
233
+ export function cddl_format(cddl: string): string;
234
+
174
235
  /**
175
236
  * Maps decoded CBOR onto a CDDL schema and returns labelled JSON. Where
176
237
  * `cbor_to_json` returns positional CBOR (numeric map keys, raw arrays),
@@ -408,6 +469,11 @@ export type CddlValidationResult =
408
469
  export interface CddlErrorInfo {
409
470
  kind: string;
410
471
  message: string;
472
+ /**
473
+ * Byte range in the CDDL source the parser tripped over, when the
474
+ * error has positional info. Useful for IDE squiggly underlines.
475
+ */
476
+ byte_span?: { offset: number; length: number; line: number };
411
477
  }
412
478
 
413
479
  export type CborValidationResult =
@@ -418,6 +484,7 @@ export type CborValidationResult =
418
484
  * `kind` categorises the failure:
419
485
  * - "parse_error" — the CDDL itself failed to parse
420
486
  * - "unresolved_references" — the CDDL references a rule name that isn't defined
487
+ * - "no_rules" — the CDDL parsed but defined no rules (empty / comment-only document)
421
488
  * - "missing_rule" — the rule name passed to `validate_cbor_against_cddl` is not in the CDDL
422
489
  * - "input_parse" — the CBOR bytes themselves are malformed
423
490
  * - "mismatch" / "map_cut" — a data mismatch; inspect `expected`, `path`,
@@ -428,9 +495,21 @@ export interface CborValidationErrorInfo {
428
495
  kind: string;
429
496
  message: string;
430
497
  expected?: string;
498
+ /** Semantic path into the CBOR (e.g. `$.b[0]`). */
431
499
  path?: string;
500
+ /** Byte range in the CBOR input that triggered the error. */
432
501
  byte_spans?: CborPosition[];
502
+ /** Byte range covering the whole containing CBOR structure. */
433
503
  anchor_spans?: CborPosition[];
504
+ /**
505
+ * Byte range in the CDDL **source** pointing at the type the
506
+ * validator tried to apply when it failed (synthesised by walking
507
+ * the AST in parallel with `path`). Useful for highlighting the
508
+ * offending CDDL rule in editors.
509
+ */
510
+ cddl_byte_span?: { offset: number; length: number; line: number };
511
+ /** Other validation errors reported in the same run. */
512
+ additional?: CborValidationErrorInfo[];
434
513
  }
435
514
 
436
515
  export interface DecodingParams {
@@ -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_from_str, 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, 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";
@@ -28456,6 +28456,34 @@ export function cbor_to_json(cbor_hex) {
28456
28456
  return takeFromExternrefTable0(ret[0]);
28457
28457
  }
28458
28458
 
28459
+ /**
28460
+ * Re-format the CDDL document by parsing and serialising via `Display`.
28461
+ * Useful for "format on save". Returns the parse error message on
28462
+ * invalid input.
28463
+ * @param {string} cddl
28464
+ * @returns {string}
28465
+ */
28466
+ export function cddl_format(cddl) {
28467
+ let deferred3_0;
28468
+ let deferred3_1;
28469
+ try {
28470
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28471
+ const len0 = WASM_VECTOR_LEN;
28472
+ const ret = wasm.cddl_format(ptr0, len0);
28473
+ var ptr2 = ret[0];
28474
+ var len2 = ret[1];
28475
+ if (ret[3]) {
28476
+ ptr2 = 0; len2 = 0;
28477
+ throw takeFromExternrefTable0(ret[2]);
28478
+ }
28479
+ deferred3_0 = ptr2;
28480
+ deferred3_1 = len2;
28481
+ return getStringFromWasm0(ptr2, len2);
28482
+ } finally {
28483
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
28484
+ }
28485
+ }
28486
+
28459
28487
  /**
28460
28488
  * Returns a `ast::CDDL` wrapped in `JsValue` from a `&str`
28461
28489
  *
@@ -28488,6 +28516,61 @@ export function cddl_from_str(input) {
28488
28516
  return takeFromExternrefTable0(ret[0]);
28489
28517
  }
28490
28518
 
28519
+ /**
28520
+ * Returns `[{name, kind, span, name_span}]` for every top-level rule
28521
+ * in the CDDL document. Use it for editor outline / breadcrumbs /
28522
+ * fuzzy-pick-rule navigation.
28523
+ * @param {string} cddl
28524
+ * @returns {any}
28525
+ */
28526
+ export function cddl_outline(cddl) {
28527
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28528
+ const len0 = WASM_VECTOR_LEN;
28529
+ const ret = wasm.cddl_outline(ptr0, len0);
28530
+ if (ret[2]) {
28531
+ throw takeFromExternrefTable0(ret[1]);
28532
+ }
28533
+ return takeFromExternrefTable0(ret[0]);
28534
+ }
28535
+
28536
+ /**
28537
+ * Returns `{definition: span | null, uses: span[]}` for the rule
28538
+ * `name`. Powers find-references and rename-aware highlighting.
28539
+ * @param {string} cddl
28540
+ * @param {string} name
28541
+ * @returns {any}
28542
+ */
28543
+ export function cddl_references(cddl, name) {
28544
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28545
+ const len0 = WASM_VECTOR_LEN;
28546
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28547
+ const len1 = WASM_VECTOR_LEN;
28548
+ const ret = wasm.cddl_references(ptr0, len0, ptr1, len1);
28549
+ if (ret[2]) {
28550
+ throw takeFromExternrefTable0(ret[1]);
28551
+ }
28552
+ return takeFromExternrefTable0(ret[0]);
28553
+ }
28554
+
28555
+ /**
28556
+ * Returns the symbol under `offset` (`null` if the cursor isn't on an
28557
+ * identifier), with `role: "definition" | "use"`, `kind`, `span`, and
28558
+ * `definition_span` (the rule's name span — the go-to-definition
28559
+ * target).
28560
+ * @param {string} cddl
28561
+ * @param {number} offset
28562
+ * @returns {any}
28563
+ */
28564
+ export function cddl_symbol_at(cddl, offset) {
28565
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28566
+ const len0 = WASM_VECTOR_LEN;
28567
+ const ret = wasm.cddl_symbol_at(ptr0, len0, offset);
28568
+ if (ret[2]) {
28569
+ throw takeFromExternrefTable0(ret[1]);
28570
+ }
28571
+ return takeFromExternrefTable0(ret[0]);
28572
+ }
28573
+
28491
28574
  /**
28492
28575
  * @param {string} hex_str
28493
28576
  * @returns {any}
@@ -29389,6 +29472,17 @@ export function __wbg_entries_e0b73aa8571ddb56(arg0) {
29389
29472
  const ret = Object.entries(arg0);
29390
29473
  return ret;
29391
29474
  }
29475
+ export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
29476
+ let deferred0_0;
29477
+ let deferred0_1;
29478
+ try {
29479
+ deferred0_0 = arg0;
29480
+ deferred0_1 = arg1;
29481
+ console.error(getStringFromWasm0(arg0, arg1));
29482
+ } finally {
29483
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
29484
+ }
29485
+ }
29392
29486
  export function __wbg_getRandomValues_112147a6595454ff(arg0) {
29393
29487
  const ret = arg0.getRandomValues;
29394
29488
  return ret;
@@ -29463,6 +29557,10 @@ export function __wbg_new_0c7403db6e782f19(arg0) {
29463
29557
  const ret = new Uint8Array(arg0);
29464
29558
  return ret;
29465
29559
  }
29560
+ export function __wbg_new_227d7c05414eb861() {
29561
+ const ret = new Error();
29562
+ return ret;
29563
+ }
29466
29564
  export function __wbg_new_34d45cc8e36aaead() {
29467
29565
  const ret = new Map();
29468
29566
  return ret;
@@ -29533,6 +29631,13 @@ export function __wbg_set_fde2cec06c23692b(arg0, arg1, arg2) {
29533
29631
  const ret = arg0.set(arg1, arg2);
29534
29632
  return ret;
29535
29633
  }
29634
+ export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
29635
+ const ret = arg1.stack;
29636
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29637
+ const len1 = WASM_VECTOR_LEN;
29638
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
29639
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
29640
+ }
29536
29641
  export function __wbg_static_accessor_GLOBAL_8cfadc87a297ca02() {
29537
29642
  const ret = typeof global === 'undefined' ? null : global;
29538
29643
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
Binary file
@@ -4,13 +4,17 @@ 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
+ export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
7
10
  export const cbor_to_json: (a: number, b: number) => [number, number, number];
11
+ export const cddl_format: (a: number, b: number) => [number, number, number, number];
12
+ export const cddl_outline: (a: number, b: number) => [number, number, number];
13
+ export const cddl_references: (a: number, b: number, c: number, d: number) => [number, number, number];
14
+ export const cddl_symbol_at: (a: number, b: number, c: number) => [number, number, number];
8
15
  export const decode_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
9
16
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
10
17
  export const validate_cddl: (a: number, b: number) => [number, number, number];
11
- export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
12
- export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
13
- export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
14
18
  export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
15
19
  export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
16
20
  export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
@@ -2446,7 +2450,7 @@ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) =>
2446
2450
  export const __wbindgen_exn_store: (a: number) => void;
2447
2451
  export const __externref_table_alloc: () => number;
2448
2452
  export const __wbindgen_externrefs: WebAssembly.Table;
2449
- export const __externref_table_dealloc: (a: number) => void;
2450
2453
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
2454
+ export const __externref_table_dealloc: (a: number) => void;
2451
2455
  export const __externref_drop_slice: (a: number, b: number) => void;
2452
2456
  export const __wbindgen_start: () => void;
@@ -171,6 +171,67 @@ export function validate_cbor_against_cddl(
171
171
  rule_name: string
172
172
  ): CborValidationResult;
173
173
 
174
+ /** Outline entry — one rule from `cddl_outline`. */
175
+ export interface CddlOutlineEntry {
176
+ /** Rule name (`transaction_body`, `set`, …). */
177
+ name: string;
178
+ /** `"type"` for `=`, `"group"` for `( … )`. */
179
+ kind: "type" | "group";
180
+ /** Byte range covering the whole `name = …` rule definition. */
181
+ span: { offset: number; length: number; line: number };
182
+ /** Byte range of just the rule's name identifier. */
183
+ name_span: { offset: number; length: number; line: number };
184
+ }
185
+
186
+ /** Result of `cddl_symbol_at`. `null` when the cursor isn't on an identifier. */
187
+ export type CddlSymbolAtResult =
188
+ | null
189
+ | {
190
+ name: string;
191
+ kind: "type" | "group" | "rule_reference" | "prelude_or_unknown";
192
+ 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;
196
+ };
197
+
198
+ /** Result of `cddl_references`. */
199
+ export interface CddlReferencesResult {
200
+ definition: { offset: number; length: number; line: number } | null;
201
+ uses: { offset: number; length: number; line: number }[];
202
+ }
203
+
204
+ /**
205
+ * Returns one entry per top-level rule (`{name, kind, span, name_span}`).
206
+ * Used for editor outline view, breadcrumbs, fuzzy "go to rule".
207
+ * @param cddl
208
+ */
209
+ export function cddl_outline(cddl: string): CddlOutlineEntry[];
210
+
211
+ /**
212
+ * Returns `{definition, uses[]}` byte ranges for the rule named `name`.
213
+ * Powers find-references and rename-aware highlighting.
214
+ * @param cddl
215
+ * @param name
216
+ */
217
+ export function cddl_references(cddl: string, name: string): CddlReferencesResult;
218
+
219
+ /**
220
+ * Returns the symbol under `offset` (or `null` if none). For uses,
221
+ * `definition_span` points at the rule's name — the "go to definition"
222
+ * target.
223
+ * @param cddl
224
+ * @param offset
225
+ */
226
+ export function cddl_symbol_at(cddl: string, offset: number): CddlSymbolAtResult;
227
+
228
+ /**
229
+ * Pretty-prints the CDDL by parsing it and serialising via `Display`.
230
+ * Useful for "format on save". Throws on invalid input.
231
+ * @param cddl
232
+ */
233
+ export function cddl_format(cddl: string): string;
234
+
174
235
  /**
175
236
  * Maps decoded CBOR onto a CDDL schema and returns labelled JSON. Where
176
237
  * `cbor_to_json` returns positional CBOR (numeric map keys, raw arrays),
@@ -408,6 +469,11 @@ export type CddlValidationResult =
408
469
  export interface CddlErrorInfo {
409
470
  kind: string;
410
471
  message: string;
472
+ /**
473
+ * Byte range in the CDDL source the parser tripped over, when the
474
+ * error has positional info. Useful for IDE squiggly underlines.
475
+ */
476
+ byte_span?: { offset: number; length: number; line: number };
411
477
  }
412
478
 
413
479
  export type CborValidationResult =
@@ -418,6 +484,7 @@ export type CborValidationResult =
418
484
  * `kind` categorises the failure:
419
485
  * - "parse_error" — the CDDL itself failed to parse
420
486
  * - "unresolved_references" — the CDDL references a rule name that isn't defined
487
+ * - "no_rules" — the CDDL parsed but defined no rules (empty / comment-only document)
421
488
  * - "missing_rule" — the rule name passed to `validate_cbor_against_cddl` is not in the CDDL
422
489
  * - "input_parse" — the CBOR bytes themselves are malformed
423
490
  * - "mismatch" / "map_cut" — a data mismatch; inspect `expected`, `path`,
@@ -428,9 +495,21 @@ export interface CborValidationErrorInfo {
428
495
  kind: string;
429
496
  message: string;
430
497
  expected?: string;
498
+ /** Semantic path into the CBOR (e.g. `$.b[0]`). */
431
499
  path?: string;
500
+ /** Byte range in the CBOR input that triggered the error. */
432
501
  byte_spans?: CborPosition[];
502
+ /** Byte range covering the whole containing CBOR structure. */
433
503
  anchor_spans?: CborPosition[];
504
+ /**
505
+ * Byte range in the CDDL **source** pointing at the type the
506
+ * validator tried to apply when it failed (synthesised by walking
507
+ * the AST in parallel with `path`). Useful for highlighting the
508
+ * offending CDDL rule in editors.
509
+ */
510
+ cddl_byte_span?: { offset: number; length: number; line: number };
511
+ /** Other validation errors reported in the same run. */
512
+ additional?: CborValidationErrorInfo[];
434
513
  }
435
514
 
436
515
  export interface DecodingParams {
@@ -28683,6 +28683,35 @@ function cbor_to_json(cbor_hex) {
28683
28683
  }
28684
28684
  exports.cbor_to_json = cbor_to_json;
28685
28685
 
28686
+ /**
28687
+ * Re-format the CDDL document by parsing and serialising via `Display`.
28688
+ * Useful for "format on save". Returns the parse error message on
28689
+ * invalid input.
28690
+ * @param {string} cddl
28691
+ * @returns {string}
28692
+ */
28693
+ function cddl_format(cddl) {
28694
+ let deferred3_0;
28695
+ let deferred3_1;
28696
+ try {
28697
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28698
+ const len0 = WASM_VECTOR_LEN;
28699
+ const ret = wasm.cddl_format(ptr0, len0);
28700
+ var ptr2 = ret[0];
28701
+ var len2 = ret[1];
28702
+ if (ret[3]) {
28703
+ ptr2 = 0; len2 = 0;
28704
+ throw takeFromExternrefTable0(ret[2]);
28705
+ }
28706
+ deferred3_0 = ptr2;
28707
+ deferred3_1 = len2;
28708
+ return getStringFromWasm0(ptr2, len2);
28709
+ } finally {
28710
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
28711
+ }
28712
+ }
28713
+ exports.cddl_format = cddl_format;
28714
+
28686
28715
  /**
28687
28716
  * Returns a `ast::CDDL` wrapped in `JsValue` from a `&str`
28688
28717
  *
@@ -28716,6 +28745,64 @@ function cddl_from_str(input) {
28716
28745
  }
28717
28746
  exports.cddl_from_str = cddl_from_str;
28718
28747
 
28748
+ /**
28749
+ * Returns `[{name, kind, span, name_span}]` for every top-level rule
28750
+ * in the CDDL document. Use it for editor outline / breadcrumbs /
28751
+ * fuzzy-pick-rule navigation.
28752
+ * @param {string} cddl
28753
+ * @returns {any}
28754
+ */
28755
+ function cddl_outline(cddl) {
28756
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28757
+ const len0 = WASM_VECTOR_LEN;
28758
+ const ret = wasm.cddl_outline(ptr0, len0);
28759
+ if (ret[2]) {
28760
+ throw takeFromExternrefTable0(ret[1]);
28761
+ }
28762
+ return takeFromExternrefTable0(ret[0]);
28763
+ }
28764
+ exports.cddl_outline = cddl_outline;
28765
+
28766
+ /**
28767
+ * Returns `{definition: span | null, uses: span[]}` for the rule
28768
+ * `name`. Powers find-references and rename-aware highlighting.
28769
+ * @param {string} cddl
28770
+ * @param {string} name
28771
+ * @returns {any}
28772
+ */
28773
+ function cddl_references(cddl, name) {
28774
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28775
+ const len0 = WASM_VECTOR_LEN;
28776
+ const ptr1 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28777
+ const len1 = WASM_VECTOR_LEN;
28778
+ const ret = wasm.cddl_references(ptr0, len0, ptr1, len1);
28779
+ if (ret[2]) {
28780
+ throw takeFromExternrefTable0(ret[1]);
28781
+ }
28782
+ return takeFromExternrefTable0(ret[0]);
28783
+ }
28784
+ exports.cddl_references = cddl_references;
28785
+
28786
+ /**
28787
+ * Returns the symbol under `offset` (`null` if the cursor isn't on an
28788
+ * identifier), with `role: "definition" | "use"`, `kind`, `span`, and
28789
+ * `definition_span` (the rule's name span — the go-to-definition
28790
+ * target).
28791
+ * @param {string} cddl
28792
+ * @param {number} offset
28793
+ * @returns {any}
28794
+ */
28795
+ function cddl_symbol_at(cddl, offset) {
28796
+ const ptr0 = passStringToWasm0(cddl, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28797
+ const len0 = WASM_VECTOR_LEN;
28798
+ const ret = wasm.cddl_symbol_at(ptr0, len0, offset);
28799
+ if (ret[2]) {
28800
+ throw takeFromExternrefTable0(ret[1]);
28801
+ }
28802
+ return takeFromExternrefTable0(ret[0]);
28803
+ }
28804
+ exports.cddl_symbol_at = cddl_symbol_at;
28805
+
28719
28806
  /**
28720
28807
  * @param {string} hex_str
28721
28808
  * @returns {any}
@@ -29661,6 +29748,17 @@ function __wbg_get_imports() {
29661
29748
  const ret = Object.entries(arg0);
29662
29749
  return ret;
29663
29750
  },
29751
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
29752
+ let deferred0_0;
29753
+ let deferred0_1;
29754
+ try {
29755
+ deferred0_0 = arg0;
29756
+ deferred0_1 = arg1;
29757
+ console.error(getStringFromWasm0(arg0, arg1));
29758
+ } finally {
29759
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
29760
+ }
29761
+ },
29664
29762
  __wbg_getRandomValues_112147a6595454ff: function(arg0) {
29665
29763
  const ret = arg0.getRandomValues;
29666
29764
  return ret;
@@ -29735,6 +29833,10 @@ function __wbg_get_imports() {
29735
29833
  const ret = new Uint8Array(arg0);
29736
29834
  return ret;
29737
29835
  },
29836
+ __wbg_new_227d7c05414eb861: function() {
29837
+ const ret = new Error();
29838
+ return ret;
29839
+ },
29738
29840
  __wbg_new_34d45cc8e36aaead: function() {
29739
29841
  const ret = new Map();
29740
29842
  return ret;
@@ -29805,6 +29907,13 @@ function __wbg_get_imports() {
29805
29907
  const ret = arg0.set(arg1, arg2);
29806
29908
  return ret;
29807
29909
  },
29910
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
29911
+ const ret = arg1.stack;
29912
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29913
+ const len1 = WASM_VECTOR_LEN;
29914
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
29915
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
29916
+ },
29808
29917
  __wbg_static_accessor_GLOBAL_8cfadc87a297ca02: function() {
29809
29918
  const ret = typeof global === 'undefined' ? null : global;
29810
29919
  return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
Binary file
@@ -4,13 +4,17 @@ 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
+ export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
9
+ export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
7
10
  export const cbor_to_json: (a: number, b: number) => [number, number, number];
11
+ export const cddl_format: (a: number, b: number) => [number, number, number, number];
12
+ export const cddl_outline: (a: number, b: number) => [number, number, number];
13
+ export const cddl_references: (a: number, b: number, c: number, d: number) => [number, number, number];
14
+ export const cddl_symbol_at: (a: number, b: number, c: number) => [number, number, number];
8
15
  export const decode_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
9
16
  export const validate_cbor_against_cddl: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
10
17
  export const validate_cddl: (a: number, b: number) => [number, number, number];
11
- export const check_block_or_tx_signatures: (a: number, b: number) => [number, number, number];
12
- export const get_necessary_data_list_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
13
- export const validate_transaction_js: (a: number, b: number, c: number, d: number) => [number, number, number, number];
14
18
  export const decode_plutus_program_pretty_uplc: (a: number, b: number) => [number, number, number, number];
15
19
  export const decode_plutus_program_uplc_json: (a: number, b: number) => [number, number, number];
16
20
  export const execute_tx_scripts: (a: number, b: number, c: any, d: any) => [number, number, number];
@@ -2446,7 +2450,7 @@ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) =>
2446
2450
  export const __wbindgen_exn_store: (a: number) => void;
2447
2451
  export const __externref_table_alloc: () => number;
2448
2452
  export const __wbindgen_externrefs: WebAssembly.Table;
2449
- export const __externref_table_dealloc: (a: number) => void;
2450
2453
  export const __wbindgen_free: (a: number, b: number, c: number) => void;
2454
+ export const __externref_table_dealloc: (a: number) => void;
2451
2455
  export const __externref_drop_slice: (a: number, b: number) => void;
2452
2456
  export const __wbindgen_start: () => 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.50",
7
+ "version": "0.1.0-beta.51",
8
8
  "license": "Apache-2.0",
9
9
  "files": [
10
10
  "node/cquisitor_lib_bg.wasm",