Skip to content

chore: fix attestation readme and support numeric typing#137

Merged
williamrusdyputra merged 1 commit into
mainfrom
adaptNewMigration
Nov 7, 2025
Merged

chore: fix attestation readme and support numeric typing#137
williamrusdyputra merged 1 commit into
mainfrom
adaptNewMigration

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented Nov 7, 2025

resolves: #136

Summary by CodeRabbit

  • Documentation

    • Simplified attestation setup with Quick Start guide
    • Clearer fee information and configuration guidance
    • Improved error messaging for common issues
  • Improvements

    • Enhanced fee parameter flexibility (supports multiple numeric formats)
    • Better attestation request parameter handling

@MicBun MicBun requested a review from outerlook November 7, 2025 08:50
@MicBun MicBun self-assigned this Nov 7, 2025
@holdex
Copy link
Copy Markdown

holdex Bot commented Nov 7, 2025

Time Submission Status

Member Status Time Action Last Update
@MicBun ❌ Missing - ⚠️ Submit time -
williamrusdyputra ✅ Submitted 10min Update time Nov 7, 2025, 9:18 AM

@MicBun MicBun changed the title chore: fix readme commands and support numeric typings for attestation chore: fix attestation readme and support numeric typing Nov 7, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 7, 2025

Walkthrough

Updates attestation example documentation with Quick Start approach using tsx instead of ts-node, adds default test private key support, updates kwil-js dependency to ^0.9.10, and implements proper type encoding for maxFee (wei) and BYTEA parameter handling in attestation operations.

Changes

Cohort / File(s) Summary
Attestation Example Updates
examples/attestation/README.md, examples/attestation/index.ts
Restructured documentation from multiple execution options to simplified Quick Start approach; replaced ts-node with tsx; added default test private key (0x000...001) with warnings; updated maxFee from numeric literal (1000000) to string representation in wei ("40000000000000000000")
Dependency and Configuration
package.json
Updated @trufnetwork/kwil-js from ^0.9.9 to ^0.9.10
API Contract Extensions
src/contracts-api/action.ts
Added optional types parameter to executeWithNamedParams method; forwards types to underlying kwilClient.execute call
Attestation Action Implementation
src/contracts-api/attestationAction.ts
Imported Utils from kwil-js; updated requestAttestation to coerce maxFee to string and pass type annotations for $max_fee (numeric(78,0)); updated listAttestations to encode requester parameter as base64 string or empty Uint8Array; added handling for getter functions in result.value
Type Definitions
src/types/attestation.ts
Widened RequestAttestationInput.maxFee from number to number | string | bigint; updated validation logic to convert all maxFee formats to BigInt with non-negativity check

Sequence Diagram

sequenceDiagram
    actor User as User
    participant SDK as SDK
    participant KwilJS as kwil-js
    participant Contract as Contract

    User->>SDK: requestAttestation(maxFee: number)
    activate SDK
    
    rect rgb(220, 240, 250)
    Note over SDK: Type Conversion Phase
    SDK->>SDK: Convert maxFee to string (wei)
    SDK->>SDK: Create types mapping:<br/>{ $max_fee: 'numeric(78,0)' }
    end
    
    rect rgb(240, 250, 220)
    Note over SDK: Execution Phase
    SDK->>SDK: executeWithNamedParams(method,<br/>inputs, types)
    end
    
    SDK->>KwilJS: execute(request with types)
    activate KwilJS
    KwilJS->>Contract: Submit attestation<br/>(proper type encoding)
    activate Contract
    Contract-->>KwilJS: Receipt
    deactivate Contract
    KwilJS-->>SDK: TxReceipt
    deactivate KwilJS
    
    SDK-->>User: Success
    deactivate SDK
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas requiring extra attention:
    • Type conversion logic in src/types/attestation.ts validateAttestationRequest function (BigInt handling for multiple input types)
    • BYTEA parameter encoding in src/contracts-api/attestationAction.ts listAttestations (null handling and base64 encoding)
    • Getter function handling for result.value in listAttestations (robustness of normalization)

Possibly related PRs

Suggested labels

enhancement, documentation

Suggested reviewers

  • outerlook
  • williamrusdyputra

Poem

🐰 With tsx now swift and types encoded tight,
Our attestations fly through the night,
Wei-measured fees in strings so grand,
The kwil-js upgrade across the land,
hops with glee — our examples work at last! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: README documentation fixes and support for numeric typing in attestation, aligning with the PR objectives.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #136: updated README with working example instructions, replaced ts-node with tsx, added default test key, and updated kwil-js dependency to support numeric types.
Out of Scope Changes check ✅ Passed All changes directly support fixing the attestation example functionality: README improvements, index.ts enhancements, types expansion, and dependency updates are all within scope of resolving issue #136.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch adaptNewMigration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/contracts-api/action.ts (1)

94-111: LGTM! Optional types parameter enables proper numeric encoding.

The new parameter allows specifying types like NUMERIC(78,0) for large wei amounts, which is essential for attestation fees. The optional parameter maintains backward compatibility.

Consider tightening the type signature to leverage kwil-js types:

-    types?: Record<string, any>,
+    types?: Record<string, Types.ValueType>,

This would provide better type safety if kwil-js exports the appropriate type.

examples/attestation/README.md (1)

38-38: Fix grammar for improved readability.

Add a comma before "but" since it connects two independent clauses.

Apply this diff:

-   **Note**: If `PRIVATE_KEY` is not set, the example will use a default test private key (`0x000...001`). This is useful for testing but the wallet may not have sufficient balance on mainnet.
+   **Note**: If `PRIVATE_KEY` is not set, the example will use a default test private key (`0x000...001`). This is useful for testing, but the wallet may not have sufficient balance on mainnet.
src/types/attestation.ts (1)

194-203: LGTM! Validation correctly handles multiple numeric types.

The conversion logic properly handles all three input types and performs BigInt comparison for accuracy.

Note: Math.floor on line 199 could theoretically lose precision for numbers exceeding Number.MAX_SAFE_INTEGER. Since the type already accepts bigint, users should prefer passing large values as bigint or string for precision. Consider documenting this in the JSDoc for maxFee.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 05730ab and a278701.

📒 Files selected for processing (6)
  • examples/attestation/README.md (2 hunks)
  • examples/attestation/index.ts (2 hunks)
  • package.json (1 hunks)
  • src/contracts-api/action.ts (1 hunks)
  • src/contracts-api/attestationAction.ts (4 hunks)
  • src/types/attestation.ts (2 hunks)
🧰 Additional context used
🪛 LanguageTool
examples/attestation/README.md

[uncategorized] ~38-~38: Use a comma before ‘but’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...x000...001`). This is useful for testing but the wallet may not have sufficient bala...

(COMMA_COMPOUND_SENTENCE_2)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (10)
package.json (1)

54-54: LGTM! Dependency update aligns with new kwil-js features.

The bump to ^0.9.10 supports the new Utils.DataType API and enhanced parameter typing used in attestation operations.

examples/attestation/README.md (2)

42-62: LGTM! Documentation aligns with Quick Start flow.

The updated instructions using tsx and the default test key make the example more accessible for initial testing.


206-209: LGTM! Helpful guidance on attestation fees.

The updated error section clearly mentions the 40 TRUF fee requirement and advises setting appropriate maxFee values.

examples/attestation/index.ts (2)

22-28: LGTM! Helpful default for initial testing.

The default test private key with clear warnings improves the developer experience while guiding users to set their own key for production use.


73-73: Verify the attestation fee amount is correct.

The maxFee is set to "40000000000000000000" wei (40 TRUF). Ensure this aligns with the actual attestation fee structure.

The string representation correctly handles the large wei amount and aligns with the updated type signature that accepts number | string | bigint.

src/types/attestation.ts (1)

44-48: LGTM! Type widening supports large wei amounts.

Accepting number | string | bigint enables proper handling of attestation fees up to 40 TRUF (40e18 wei), which exceeds JavaScript's safe integer range.

src/contracts-api/attestationAction.ts (4)

9-9: LGTM! Utils import enables numeric type specification.

The Utils import provides access to DataType.Numeric() for properly encoding large wei amounts.


95-111: LGTM! Proper numeric encoding for large wei amounts.

The implementation correctly:

  • Converts maxFee to string for safe handling
  • Specifies NUMERIC(78,0) type for up to 78-digit wei values
  • Passes types to executeWithNamedParams

This ensures attestation fees are accurately encoded without precision loss.


272-274: LGTM! Defensive normalization for result value.

The code safely handles cases where result.value might be a getter function, ensuring consistent array processing.


253-259: The referenced version kwil-js 0.9.10+ does not exist.

The latest published version of the official kwil-js package is 0.9.4, not 0.9.10. The review comment's claim about kwil-js 0.9.10+ handling empty Uint8Array as BYTEA NULL cannot be verified against a non-existent version. The actual behavior of empty Uint8Array for BYTEA parameters in the current version (0.9.4) should be verified separately against official documentation or tested directly, rather than relying on the unsubstantiated version reference in the code comment.

Likely an incorrect or invalid review comment.

@williamrusdyputra
Copy link
Copy Markdown
Contributor

@MicBun CI failed due to max fee config on tests

@MicBun
Copy link
Copy Markdown
Contributor Author

MicBun commented Nov 7, 2025

Yes, currently no whitelist, i am creating it now
Whitelist system is needed for ci/cd pipeline

@williamrusdyputra
Copy link
Copy Markdown
Contributor

Yes, currently no whitelist, i am creating it now
Whitelist system is needed for ci/cd pipeline

got it

@williamrusdyputra williamrusdyputra merged commit a81c255 into main Nov 7, 2025
4 of 7 checks passed
@williamrusdyputra williamrusdyputra deleted the adaptNewMigration branch November 7, 2025 09:18
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.

Bug: Attestation example methods all non-functional

2 participants