Skip to content

fix: correct attestation example flow and documentation#139

Merged
MicBun merged 1 commit intomainfrom
fixattestationdoc
Nov 9, 2025
Merged

fix: correct attestation example flow and documentation#139
MicBun merged 1 commit intomainfrom
fixattestationdoc

Conversation

@MicBun
Copy link
Copy Markdown
Member

@MicBun MicBun commented Nov 9, 2025

resolves: #136

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated attestation example README with clarified prerequisites, improved setup instructions, and expanded workflow details including signature verification guidance.
  • New Features

    • Enhanced attestation example with capability to list recent attestations and retrieve signed attestation payloads with payload details and validation.
    • Improved error handling for attestation requests including edge cases like insufficient balance.
  • Chores

    • Added package configuration for attestation example.

@MicBun MicBun requested a review from outerlook November 9, 2025 01:19
@MicBun MicBun self-assigned this Nov 9, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 9, 2025

Walkthrough

This PR updates the attestation example to fix non-functional execution methods by adding a package manifest, refactoring the control flow with proper error handling and attestation retrieval, and updating documentation with clarified prerequisites, running instructions, and signature verification code.

Changes

Cohort / File(s) Summary
Documentation
examples/attestation/README.md
Prerequisites rewritten to mark wallet and private key as optional; running instructions shifted to start from sdk-js root; Quick Start and wallet sections updated for local PRIVATE_KEY usage; attestation flow expanded with granular steps; code snippet updated to use SHA256 hash and recoverAddress for signature verification; RequestAttestationInput.maxFee type widened from number to number | string | bigint; documentation links updated.
Example Implementation
examples/attestation/index.ts
Added ethers imports (sha256, recoverAddress); instantiated wallet object for address display; renamed "Request Attestation" to "Request Attestation Metadata"; replaced one-shot attestation request with multi-step flow including listing recent attestations, retrieval and parsing of signed attestation payload with validator address recovery, and optional new attestation request with polling and error handling for insufficient balance.
Package Configuration
examples/attestation/package.json
New file: package manifest for attestation example with name "attestation", version "1.0.0", start script using tsx to run index.ts, and ISC license.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Script as index.ts
    participant SDK as Attestation SDK
    participant Blockchain

    User->>Script: Run with PRIVATE_KEY

    rect rgb(200, 220, 240)
    Note over Script: Setup Phase
    Script->>Script: Initialize wallet from PRIVATE_KEY
    Script->>Script: Display wallet address (if no key, use default)
    end

    rect rgb(240, 220, 200)
    Note over Script: List Attestations Phase
    Script->>SDK: List recent attestations (limit: 3)
    SDK-->>Script: Return attestation list
    Script->>Script: Display TX ID, blocks, hashes
    end

    rect rgb(220, 240, 200)
    Note over Script: Retrieve Signed Attestation Phase
    alt Attestations exist
        Script->>SDK: Fetch signed attestation
        SDK-->>Script: Return payload & signature
        Script->>Script: Compute SHA256(canonical payload)
        Script->>Script: Recover validator address via recoverAddress(hash, R, S, V)
        Script->>Script: Display extraction guidance
    else No attestations
        Script->>Script: Skip retrieval phase
    end
    end

    rect rgb(240, 200, 220)
    Note over Script: Request New Attestation Phase
    alt Key provided
        Script->>SDK: Request new attestation with data provider, stream, args
        SDK->>Blockchain: Submit attestation request
        Script->>Script: Wait for TX confirmation
        Script->>SDK: Poll for signed attestation (multiple attempts)
        alt Success
            SDK-->>Script: Return signed attestation
            Script->>Script: Extract & verify validator address
            Script->>Script: Display payload details
        else Timeout
            Script->>Script: Log timeout, continue
        end
    else Insufficient balance
        Script->>Script: Log insufficient balance, continue
    end
    end

    Script->>User: Summarize completed operations
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Areas requiring attention:

  • Cryptographic operations in index.ts: SHA256 hashing and recoverAddress signature recovery logic
  • Polling mechanism for attestation retrieval with multiple retry attempts
  • Error handling path for insufficient balance edge case
  • Type change for RequestAttestationInput.maxFee and impact on SDK API contract
  • Package.json tsx script execution as alternative to ts-node-esm

Possibly related PRs

Suggested labels

documentation

Suggested reviewers

  • outerlook
  • williamrusdyputra

Poem

🐰 A rabbit hops through attestation flows,
With tsx scripts and signatures that rose,
SHA256 hashes dance in the chain,
Error handling smooths every lane—
The example now works, no more pain! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'fix: correct attestation example flow and documentation' directly summarizes the main changes: fixing the attestation example's execution flow and updating its documentation.
Linked Issues check ✅ Passed The PR addresses issue #136 which reported non-functional attestation examples. The changes add a package.json with proper run scripts using tsx, update documentation with correct execution instructions, and fix the example code flow to be functional.
Out of Scope Changes check ✅ Passed All changes are scoped to the attestation example directory: documentation updates, example code improvements, and adding package.json. No unrelated modifications to other parts of the codebase were introduced.
✨ 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 fixattestationdoc

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.

@holdex
Copy link
Copy Markdown

holdex bot commented Nov 9, 2025

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 1h Update time Nov 9, 2025, 1:25 AM

@holdex
Copy link
Copy Markdown

holdex bot commented Nov 9, 2025

Bug Report Checklist

Status Commit Link Bug Author
✅ Submitted commit link @MicBun

@MicBun
Copy link
Copy Markdown
Member Author

MicBun commented Nov 9, 2025

@pr-time-tracker bug commit 93e7768 && bug author @MicBun

@MicBun MicBun merged commit 35754f3 into main Nov 9, 2025
4 of 6 checks passed
@MicBun MicBun deleted the fixattestationdoc branch November 9, 2025 01:22
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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e06cc91 and 128b76e.

📒 Files selected for processing (3)
  • examples/attestation/README.md (6 hunks)
  • examples/attestation/index.ts (5 hunks)
  • examples/attestation/package.json (1 hunks)
🧰 Additional context used
🪛 Gitleaks (8.28.0)
examples/attestation/README.md

[high] 61-61: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ 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

Comment on lines +6 to +8
"scripts": {
"start": "tsx index.ts"
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Ensure tsx is installed for this package’s start script

Following the new Quick Start (clean clone → npm install at repo root → cd examples/attestationnpm start) still fails with sh: tsx: command not found. Because this package doesn’t declare tsx, the local npm start has no binary unless someone happens to have it installed globally. Please declare tsx (and install it before running) so the example works out of the box.

Suggested fix:

   "scripts": {
-    "start": "tsx index.ts"
-  },
+    "start": "tsx index.ts"
+  },
+  "devDependencies": {
+    "tsx": "^4.19.0"
+  }

After adding the dependency, remember to document running npm install inside this directory (see README).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"scripts": {
"start": "tsx index.ts"
},
"scripts": {
"start": "tsx index.ts"
},
"devDependencies": {
"tsx": "^4.19.0"
}
🤖 Prompt for AI Agents
In examples/attestation/package.json around lines 6 to 8, the "start" script
uses the tsx binary which is not declared in this package, causing "tsx: command
not found"; add "tsx" (preferably as a devDependency) to this package.json and
run npm install in the examples/attestation directory so the binary is available
locally, and update the example README to instruct users to run npm install
inside examples/attestation before npm start.

Comment on lines +45 to 65
# From the sdk-js root directory, navigate to the example
cd examples/attestation

Or directly:
```bash
npx tsx examples/attestation/index.ts
# Run with default test key
npm start
```

### With Your Own Wallet

If you want to use your own private key instead of the test key:

```bash
# Set your private key
export PRIVATE_KEY="0x..."
# From the sdk-js root directory, navigate to the example
cd examples/attestation

# Set your private key (replace with your actual private key)
export PRIVATE_KEY="0x1234567890abcdef..."

# Run the example
npm run example:attestation
npm start
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Document installing the example dependencies before npm start

Results from README’s Quick Start (root npm install, cd examples/attestation, npm start) still error out because this package needs its own npm install to fetch tsx. Please add that step—otherwise the new manifest doesn’t actually fix the reproduction path from issue #136.

For example:

# From the sdk-js root directory, navigate to the example
cd examples/attestation

# Install example dependencies
npm install

# Run with default test key
npm start

That keeps the instructions runnable for anyone starting from a clean clone.

🧰 Tools
🪛 Gitleaks (8.28.0)

[high] 61-61: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
examples/attestation/README.md around lines 45 to 65: the Quick Start omits
installing the example-specific dependencies so running npm start after
installing at the repo root fails (missing tsx); update the instructions to
include an npm install step inside examples/attestation before npm start (show
commands: cd examples/attestation, npm install, then npm start) so the example
dependencies are fetched and the example runs from a clean clone.

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

1 participant