Skip to content

fix(identities): assign real nonce to identity txs instead of hardcoded 1#98

Merged
tcsenpai merged 1 commit into
mainfrom
fix/identity-tx-nonce
Jun 24, 2026
Merged

fix(identities): assign real nonce to identity txs instead of hardcoded 1#98
tcsenpai merged 1 commit into
mainfrom
fix/identity-tx-nonce

Conversation

@HaykK-Solicy

@HaykK-Solicy HaykK-Solicy commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

…ed 1

inferIdentity (add/link) and removeIdentity (remove) both hardcoded nonce:1. That only validates for a fresh account (nonce 0): the first identity op succeeds and bumps the on-chain nonce, so the second (e.g. removing an XM wallet right after adding it) is rejected with '[NONCE ERROR] Nonce not assigned'. Both now fetch demos.getAddressNonce(address) and use nonce+1, matching every other native tx in the SDK (DemosTransactions.pay, nativeBridge, ContractDeployer).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed identity actions so they use the correct transaction nonce instead of a fixed value.
    • Improved reliability for adding, assigning, and removing identities after earlier identity operations.
    • Added clearer handling to prevent failures caused by reusing an outdated nonce.

…ed 1

inferIdentity (add/link) and removeIdentity (remove) both hardcoded nonce:1.
That only validates for a fresh account (nonce 0): the first identity op
succeeds and bumps the on-chain nonce, so the second (e.g. removing an XM
wallet right after adding it) is rejected with '[NONCE ERROR] Nonce not
assigned'. Both now fetch demos.getAddressNonce(address) and use nonce+1,
matching every other native tx in the SDK (DemosTransactions.pay,
nativeBridge, ContractDeployer).
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

In src/abstraction/Identities.ts, both inferIdentity and removeIdentity replace the hardcoded nonce: 1 with a live lookup via demos.getAddressNonce(address), setting the transaction nonce to the fetched value plus one.

Changes

Dynamic nonce for identity transactions

Layer / File(s) Summary
Dynamic nonce in inferIdentity and removeIdentity
src/abstraction/Identities.ts
Both functions now call demos.getAddressNonce(address) and set the transaction nonce to nonce + 1 instead of the previously hardcoded nonce: 1, with inline comments explaining the prior failure mode.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • kynesyslabs/sdks#67: Modifies the same inferIdentity/removeIdentity functions in src/abstraction/Identities.ts to add "nomis" context support.
  • kynesyslabs/sdks#75: Also touches inferIdentity/removeIdentity transaction construction in src/abstraction/Identities.ts to wire in TLSN context.

Poem

🐰 A nonce of 1 was stuck in time,
Each second transaction failed to climb.
I hopped to the chain, fetched the count,
Added one more to the right amount.
Now identities flow without a hitch — sublime! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the change: identity transactions now use the real nonce instead of a hardcoded 1.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/identity-tx-nonce

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.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/abstraction/Identities.ts`:
- Line 142: The add/remove flow in Identities.ts is fetching the next nonce too
early because demos.confirm() only validates the tx and does not wait for
on-chain inclusion. Update the logic around the add transaction and the
subsequent getAddressNonce() call to wait until the add tx is actually landed,
using broadcastAndWait() or polling getTransactionStatus() first, so the remove
tx does not reuse the old nonce.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ea42c7a3-2738-42a2-857e-7ed8ff0ac691

📥 Commits

Reviewing files that changed from the base of the PR and between 4e17d6a and d22e29c.

📒 Files selected for processing (1)
  • src/abstraction/Identities.ts

// Use the address' current nonce (+1) like every other native tx in
// this SDK — hardcoding nonce:1 only validated for a fresh account and
// broke the second identity op (e.g. remove after add).
const nonce = await demos.getAddressNonce(address)

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.

🩺 Stability & Availability | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect confirm() and getAddressNonce() to confirm sequencing guarantees.
fd -t f 'demosclass.ts' --exec ast-grep outline {} \;
rg -nP --type=ts -C8 '\b(confirm|getAddressNonce)\s*\(' src/websdk/demosclass.ts

Repository: kynesyslabs/sdks

Length of output: 3584


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the confirm path and nonce lookup behavior around the relevant methods.
ast-grep outline src/websdk/demosclass.ts --view expanded | sed -n '1,220p'
printf '\n--- confirm/getAddressNonce context ---\n'
sed -n '430,520p' src/websdk/demosclass.ts
printf '\n--- getAddressNonce context ---\n'
sed -n '1298,1335p' src/websdk/demosclass.ts
printf '\n--- DemosTransactions references ---\n'
rg -n -C 6 'class DemosTransactions|static confirm|confirm\(transaction|broadcastAndWait|broadcast\(' src/websdk/demosclass.ts

Repository: kynesyslabs/sdks

Length of output: 10224


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the confirm path and nonce lookup behavior around the relevant methods.
ast-grep outline src/websdk/demosclass.ts --view expanded | sed -n '1,220p'
printf '\n--- confirm/getAddressNonce context ---\n'
sed -n '430,520p' src/websdk/demosclass.ts
printf '\n--- getAddressNonce context ---\n'
sed -n '1298,1335p' src/websdk/demosclass.ts
printf '\n--- DemosTransactions references ---\n'
rg -n -C 6 'class DemosTransactions|static confirm|confirm\(transaction|broadcastAndWait|broadcast\(' src/websdk/demosclass.ts

Repository: kynesyslabs/sdks

Length of output: 10224


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the DemosTransactions implementation and inspect confirm/broadcast semantics.
fd -t f . src/websdk | sed -n '1,200p'
printf '\n--- search ---\n'
rg -n -C 8 'class DemosTransactions|confirm\(transaction|broadcastAndWait|getTransactionStatus|getAddressNonce' src/websdk

Repository: kynesyslabs/sdks

Length of output: 25480


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find the DemosTransactions implementation and inspect confirm/broadcast semantics.
fd -t f . src/websdk | sed -n '1,200p'
printf '\n--- search ---\n'
rg -n -C 8 'class DemosTransactions|confirm\(transaction|broadcastAndWait|getTransactionStatus|getAddressNonce' src/websdk

Repository: kynesyslabs/sdks

Length of output: 25480


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the reviewed file and the transaction confirmation implementation.
ast-grep outline src/abstraction/Identities.ts --view expanded | sed -n '1,220p'
printf '\n--- identities excerpt ---\n'
sed -n '120,210p' src/abstraction/Identities.ts
printf '\n--- DemosTransactions.confirm implementation ---\n'
sed -n '1,360p' src/websdk/DemosTransactions.ts | sed -n '300,360p'

Repository: kynesyslabs/sdks

Length of output: 8195


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the reviewed file and the transaction confirmation implementation.
ast-grep outline src/abstraction/Identities.ts --view expanded | sed -n '1,220p'
printf '\n--- identities excerpt ---\n'
sed -n '120,210p' src/abstraction/Identities.ts
printf '\n--- DemosTransactions.confirm implementation ---\n'
sed -n '1,360p' src/websdk/DemosTransactions.ts | sed -n '300,360p'

Repository: kynesyslabs/sdks

Length of output: 8195


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the confirm implementation and nearby transaction flow.
rg -n -C 12 'confirm: async function|confirm\s*\(' src/websdk/DemosTransactions.ts
sed -n '240,340p' src/websdk/DemosTransactions.ts

Repository: kynesyslabs/sdks

Length of output: 4390


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the confirm implementation and nearby transaction flow.
rg -n -C 12 'confirm: async function|confirm\s*\(' src/websdk/DemosTransactions.ts
sed -n '240,340p' src/websdk/DemosTransactions.ts

Repository: kynesyslabs/sdks

Length of output: 4390


Wait for the add tx to land before fetching the next nonce. demos.confirm() only runs confirmTx validation and returns immediately; it does not wait for on-chain inclusion. In the remove-after-add flow, use broadcastAndWait() or poll getTransactionStatus before calling getAddressNonce(), or the second tx can reuse the old nonce and collide.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/abstraction/Identities.ts` at line 142, The add/remove flow in
Identities.ts is fetching the next nonce too early because demos.confirm() only
validates the tx and does not wait for on-chain inclusion. Update the logic
around the add transaction and the subsequent getAddressNonce() call to wait
until the add tx is actually landed, using broadcastAndWait() or polling
getTransactionStatus() first, so the remove tx does not reuse the old nonce.

@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes nonce assignment for identity transactions. The main changes are:

  • Identity add transactions now fetch the current address nonce.
  • Identity remove transactions now fetch the current address nonce.
  • Both identity paths now sign with nonce + 1 instead of hardcoded 1.

Confidence Score: 5/5

Safe to merge based on the scoped identity nonce change.

The change is small and aligns identity transaction nonce handling with the existing native transaction pattern in the SDK.

T-Rex T-Rex Logs

What T-Rex did

  • The identity nonce behavior was inspected by comparing the before and after logs to verify that the code path now uses the real current address nonce plus one for both identity transaction types.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "fix(identities): assign real nonce to id..." | Re-trigger Greptile

@HaykK-Solicy HaykK-Solicy changed the title fix(identities): assign real nonce to identity txs instead of hardcod… fix(identities): assign real nonce to identity txs instead of hardcoded 1 Jun 24, 2026
@tcsenpai tcsenpai merged commit 5b0a31d into main Jun 24, 2026
8 checks passed
@sonarqubecloud

Copy link
Copy Markdown

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