Skip to content

fix(sdk): match ACP store accounts case-insensitively - #401

Merged
architect-dev merged 1 commit into
FhenixProtocol:masterfrom
erkancamli:fix/acp-store-account-case
Oct 14, 2026
Merged

architect-dev merged 1 commit into
FhenixProtocol:masterfrom
erkancamli:fix/acp-store-account-case

Conversation

@erkancamli

@erkancamli erkancamli commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

ACPs are written under the wallet client's address (storeACP / storeActiveACP in core/acps.ts use walletClient.account.address, which viem returns checksummed), but reads use the account the caller passes: getOrCreateSelfACP(chainId, account), getActiveACP(chainId, account), and decryptForView(...).setAccount(account) / decryptForTx(...).setAccount(account). The store in acps/store.ts keys by the raw string, so the same address in a different case does not match.

In practice an address that comes lowercased from an indexer, a URL or user input:

  • makes decryptForView(...).setAccount(addr) fail with ACPNotFound although an active ACP exists for that account;
  • makes getOrCreateSelfACP(chainId, lowercaseAddr) miss the active ACP every time, so it creates a new one and asks the wallet for another signature on each call.

The issuer checks in core/acps.ts already compare addresses with toLowerCase().

This adds a small resolveAccountKey that maps an account to the key it is already stored under (case-insensitive match), used by every read and write in the store. It does not rewrite keys: a new account keeps the spelling it is first written with, which is the connected wallet's address in practice, so existing persisted data and the @cofhe/react hooks that read the raw snapshot (state.acps[chainId][account]) keep working.

Tests: core/test/acpStoreAccountCase.test.ts covers the lowercase lookup of the active ACP, getOrCreateSelfACP with a lowercase account (no second signature), and one bucket per account across cases. It uses a local signing wallet and a stubbed EIP-712 domain, so it needs no RPC. All 3 fail on master and pass with the fix. The acps/test suites still pass, and in the node test project the only failures are the existing network-dependent ones, identical with and without this change. eslint and prettier are clean on the changed files. A changeset is included.


Note

Low Risk
Scoped to client-side ACP localStorage key resolution; no auth or on-chain behavior changes, and existing stored key spellings are preserved.

Overview
ACP persisted store lookups now treat account addresses as case-insensitive, fixing misses when callers pass a lowercased address (indexer, URL, user input) while data was saved under the wallet’s checksummed key.

A new resolveAccountKey maps any account string to the existing bucket key (or keeps the incoming spelling on first write) and is wired through all store getters/setters for ACPs and active ACP hashes, so getOrCreateSelfACP, decryptForView/setAccount, and related paths reuse the same ACP instead of raising ACPNotFound or triggering repeat wallet signatures. Persisted localStorage keys are not migrated—only lookup/write resolution changes.

Adds offline Vitest coverage for lowercase reads, single-signature reuse, and one bucket per account across cases, plus a patch changeset for @cofhe/sdk.

Reviewed by Cursor Bugbot for commit 2bbd6ba. Bugbot is set up for automated code reviews on this repo. Configure here.

ACPs are written under the wallet client's checksummed address, but
reads use whatever account the caller passes. A lowercased address (from
an indexer, a URL or user input) did not match the stored key, so
decryptForView(...).setAccount(addr) failed with ACPNotFound and
getOrCreateSelfACP never found the active ACP, creating a new one and
asking the wallet for another signature on every call.

Resolve the account to the key it is already stored under before reading
or writing. A new account keeps the spelling it is first written with, so
existing persisted data and the React hooks, which read the raw snapshot,
are unaffected.
@changeset-bot

changeset-bot Bot commented Oct 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2bbd6ba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@cofhe/sdk Patch
@cofhe/abi Patch
@cofhe/hardhat-3-plugin Patch
@cofhe/hardhat-plugin Patch
@cofhe/mock-contracts Patch
@cofhe/react Patch
@cofhe/site Patch
@cofhe/example-react Patch
@cofhe/foundry-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@architect-dev architect-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good fix. Will probably remove this changeset after it merges. I don't think its necessary to document this as a change since its a small bugfix.

@architect-dev
architect-dev merged commit 621e4c3 into FhenixProtocol:master Oct 14, 2026
13 checks passed
architect-dev added a commit that referenced this pull request Oct 16, 2026
- Bump @cofhe/sdk to major so the fixed group releases 1.0.0
- Merge the six mock-parity changesets into mocks-match-production
- Drop changesets for small internal fixes (#300, #329, #399, #401, #405)
- Shorten the CofheProvider breaking-change note
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