Skip to content

feat(docs): improve CBOR decoder tool UI and add data decoder option#65

Merged
solidsnakedev merged 1 commit into
mainfrom
feat/add-more-decoders
Nov 21, 2025
Merged

feat(docs): improve CBOR decoder tool UI and add data decoder option#65
solidsnakedev merged 1 commit into
mainfrom
feat/add-more-decoders

Conversation

@solidsnakedev
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings November 21, 2025 17:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the CBOR decoder tool UI and extends its functionality to support decoding multiple types of Cardano data structures.

  • Improved CBOR decoder UI with modern card-based layout and better error display
  • Added support for decoding Transaction Witness Sets and Plutus Data in addition to Transactions
  • Updated API documentation to reflect schema changes and new codec options

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
packages/evolution/src/core/index.ts Exports TransactionWitnessSet module to enable witness set decoding functionality
packages/evolution/docs/modules/core/TSchema.ts.md Updates function signatures for Variant and Struct with improved type definitions
docs/next-env.d.ts Adjusts Next.js type reference path from .next/types to out/dev/types
docs/content/docs/modules/core/TSchema.mdx Adds constructor documentation (TaggedStruct, Variant) and expands StructOptions interface with new fields
docs/content/docs/modules/core/Data.mdx Updates method signatures and adds DataSchema interface documentation
docs/content/docs/modules/core/CBOR.mdx Introduces AIKEN_DEFAULT_OPTIONS constant and extends CodecOptions with encodeMapAsPairs field
docs/app/tools/tx-decoder/transaction-decoder.tsx Implements multi-type decoder (transaction/witnessSet/data) with redesigned card-based UI

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

</svg>
<div className="flex-1 min-w-0 space-y-2">
<p className="text-sm font-medium text-destructive">Error decoding {decodeType === 'transaction' ? 'transaction' : decodeType === 'witnessSet' ? 'witness set' : 'data'}</p>
<pre className="text-xs text-muted-foreground whitespace-pre-wrap break-words overflow-wrap-anywhere font-mono">{error}</pre>
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The CSS class overflow-wrap-anywhere may not be a valid Tailwind CSS utility class. The standard Tailwind utilities for overflow-wrap are break-normal, break-words, and break-all. The property overflow-wrap: anywhere is valid CSS, but you need to verify this is configured in your Tailwind setup or use break-words which is the standard Tailwind utility with similar behavior.

Suggested change
<pre className="text-xs text-muted-foreground whitespace-pre-wrap break-words overflow-wrap-anywhere font-mono">{error}</pre>
<pre className="text-xs text-muted-foreground whitespace-pre-wrap break-words font-mono">{error}</pre>

Copilot uses AI. Check for mistakes.
const [error, setError] = useState<string | null>(null)
const [decodeType, setDecodeType] = useState<DecodeType>('transaction')

const decodeTx = async () => {
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decodeTx function is declared as async but doesn't use await anywhere in its body. The function performs only synchronous operations (decoding CBOR, encoding to JSON, and setting state). Remove the async keyword to accurately reflect the function's behavior.

Suggested change
const decodeTx = async () => {
const decodeTx = () => {

Copilot uses AI. Check for mistakes.
toData: (a: A, overrideOptions?: ParseOptions) => I
fromData: (i: I, overrideOptions?: ParseOptions) => A
toCBORHex: (a: A, overrideOptions?: ParseOptions) => string
toCBORBytes: (a: A, overrideOptions?: ParseOptions) => any
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type of toCBORBytes has been changed from Uint8Array to any, which removes type safety. This is a regression that allows any type to be returned without compile-time checks. Unless there's a specific reason for this change, the return type should remain Uint8Array to maintain type safety.

Suggested change
toCBORBytes: (a: A, overrideOptions?: ParseOptions) => any
toCBORBytes: (a: A, overrideOptions?: ParseOptions) => Uint8Array

Copilot uses AI. Check for mistakes.
@@ -289,7 +334,31 @@ export interface StructOptions {
*
* Default: true when index is specified, false otherwise
*/
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistency in property naming: flat was renamed to flatInUnion, but the documentation doesn't indicate this is a breaking change. If this is part of the StructOptions interface, existing code using flat will break. Consider documenting this as a breaking change or supporting both property names with deprecation warnings.

Suggested change
*/
*/
/**
* @deprecated Use `flatInUnion` instead. The `flat` property has been renamed to `flatInUnion` for clarity.
* Both `flat` and `flatInUnion` are currently supported, but `flat` will be removed in a future release.
*/

Copilot uses AI. Check for mistakes.
fields: Fields,
options?: StructOptions
) => Struct<Fields>
options: StructOptions = {}
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation shows a default parameter value in a declare signature (options: StructOptions = {}). TypeScript declaration files (.d.ts) and declare statements should not include default parameter values - these are implementation details. The signature should use options?: StructOptions instead, with the default value documented separately or shown only in implementation files.

Suggested change
options: StructOptions = {}
options?: StructOptions

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +41
setError(`Please enter a ${decodeType === 'transaction' ? 'transaction' : decodeType === 'witnessSet' ? 'transaction witness set' : 'plutus data'} CBOR hex string`)
return
}

const tx = Core.Transaction.fromCBORHex(cleanHex)
const json = JSON.stringify(tx.toJSON(), (key, value) =>
typeof value === 'bigint' ? value.toString() : value
, 2)
setDecodedJson(json)
if (decodeType === 'transaction') {
const tx = Core.Transaction.fromCBORHex(cleanHex)
const json = Schema.encodeSync(Schema.parseJson(Core.Transaction.Transaction, {space: 2}))(tx)
setDecodedJson(json)
} else if (decodeType === 'witnessSet') {
const witnessSet = Core.TransactionWitnessSet.fromCBORHex(cleanHex)
const json = Schema.encodeSync(Schema.parseJson(Core.TransactionWitnessSet.TransactionWitnessSet, {space: 2}))(witnessSet)
setDecodedJson(json)
} else {
const data = Core.Data.fromCBORHex(cleanHex)
const json = Schema.encodeSync(Schema.parseJson(Core.Data.DataSchema, {space: 2}))(data)
setDecodedJson(json)
}
} catch (err) {
console.error('Decode error:', err)
setError(err instanceof Error ? err.message : "Failed to decode transaction")
setError(err instanceof Error ? err.message : `Failed to decode ${decodeType === 'transaction' ? 'transaction' : decodeType === 'witnessSet' ? 'witness set' : 'data'}`)
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeated ternary expressions for message formatting create code duplication and reduce maintainability. Consider extracting this logic into a helper function or using a lookup object:

const getDecodeTypeLabel = (type: DecodeType, variant: 'short' | 'full' = 'short'): string => {
  const labels = {
    transaction: { short: 'transaction', full: 'transaction' },
    witnessSet: { short: 'witness set', full: 'transaction witness set' },
    data: { short: 'data', full: 'plutus data' }
  }
  return labels[type][variant]
}

This pattern is repeated on lines 22, 41, 83, 92, and 106.

Copilot uses AI. Check for mistakes.
Comment on lines +62 to +71
<select
id="decode-type"
value={decodeType}
onChange={(e) => setDecodeType(e.target.value as DecodeType)}
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"
>
<option value="transaction">Transaction</option>
<option value="witnessSet">Transaction Witness Set</option>
<option value="data">Plutus Data</option>
</select>
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The <select> element lacks proper accessibility attributes. Add an aria-label or ensure the associated <label> is properly connected for screen reader users. While the htmlFor attribute on the label connects to the select via id, consider adding aria-describedby if there's additional help text needed.

Copilot uses AI. Check for mistakes.
toCBORHex: (a: A, overrideOptions?: ParseOptions) => string
toCBORBytes: (a: A, overrideOptions?: ParseOptions) => any
fromCBORHex: (i: string, overrideOptions?: ParseOptions) => A
fromCBORBytes: (i: any, overrideOptions?: ParseOptions) => A
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter type for fromCBORBytes has been changed from Uint8Array to any, which removes input type safety. This allows any type to be passed without compile-time validation, potentially leading to runtime errors. The parameter should be typed as Uint8Array to maintain API safety and catch errors at compile time.

Suggested change
fromCBORBytes: (i: any, overrideOptions?: ParseOptions) => A
fromCBORBytes: (i: Uint8Array, overrideOptions?: ParseOptions) => A

Copilot uses AI. Check for mistakes.

```ts
export declare const toCBORBytes: (input: Data, options?: CBOR.CodecOptions) => Uint8Array
export declare const toCBORBytes: (data: Data, options?: CBOR.CodecOptions) => any
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type of toCBORBytes has been changed from Uint8Array to any, which removes type safety. This is inconsistent with the function's purpose of encoding data to CBOR bytes. The return type should be Uint8Array to provide proper type guarantees to API consumers.

Suggested change
export declare const toCBORBytes: (data: Data, options?: CBOR.CodecOptions) => any
export declare const toCBORBytes: (data: Data, options?: CBOR.CodecOptions) => Uint8Array

Copilot uses AI. Check for mistakes.
**Signature**

```ts
export declare const Variant: <Variants extends Record<string, Schema.Struct.Fields>>(
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Variant signature in the documentation shows Record<string, Schema.Struct.Fields> as the constraint, but the actual implementation in TSchema.ts.md uses Record<PropertyKey, Schema.Struct.Fields>. These should be consistent. Using PropertyKey (which includes string | number | symbol) is more flexible, but if the implementation only supports string keys, the documentation should match.

Suggested change
export declare const Variant: <Variants extends Record<string, Schema.Struct.Fields>>(
export declare const Variant: <Variants extends Record<PropertyKey, Schema.Struct.Fields>>(

Copilot uses AI. Check for mistakes.
@solidsnakedev solidsnakedev merged commit ac83d0f into main Nov 21, 2025
11 checks passed
@solidsnakedev solidsnakedev deleted the feat/add-more-decoders branch November 21, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants