Skip to content

chore: assert amulet.admin is present before building commands that need it - #2326

Merged
rukmini-basu-da merged 5 commits into
canton-network:mainfrom
ayushsingh82:ayush/assert-amulet-admin-1797
Aug 25, 2026
Merged

chore: assert amulet.admin is present before building commands that need it#2326
rukmini-basu-da merged 5 commits into
canton-network:mainfrom
ayushsingh82:ayush/assert-amulet-admin-1797

Conversation

@ayushsingh82

Copy link
Copy Markdown
Contributor

Summary

fetchAmulet() (sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts) returns AssetBody with admin: PartyId typed as always-present, but parseAssets (sdk/wallet-sdk/src/wallet/namespace/utils/url.ts) does no runtime validation of the raw registry response it's built from -- admin can actually be undefined at runtime despite what the type claims.

Three call sites currently pass amulet.admin straight into ledger commands with no guard:

  • preapproval.ts's create command (expectedDso: amulet.admin)
  • traffic.ts's buyMemberTraffic
  • namespace.ts's tap

If a registry response omits admin, this silently builds a command (e.g. a transfer preapproval with an undefined expectedDso) that can even be submitted but won't work correctly, instead of failing loudly at the point where the bad data enters the SDK.

Added one guard inside fetchAmulet(), using the SDK's existing ctx.error.throw(...) convention, which protects all three call sites at once.

Fixes #1797

Test plan

  • tsc --noEmit in sdk/wallet-sdk: 115 errors before and after (exact match, confirmed via git stash comparison) -- all pre-existing from unbuilt workspace deps, zero new errors from this change
  • Could not run the existing amulet.test.ts/preapproval.test.ts/traffic.test.ts suite -- it transitively needs core-token-standard, whose build requires Daml-generated codegen artifacts (damljs/token-standard-models) not available in the environment I worked in

fetchAmulet() returns AssetBody with admin: PartyId typed as always
present, but parseAssets does no runtime validation of the registry
response it comes from. Three call sites (preapproval create command,
traffic buyMemberTraffic, namespace tap) pass amulet.admin straight
into ledger commands unchecked -- if a registry response is missing
it, this silently builds a command (e.g. transfer preapproval) with
an undefined expectedDso instead of failing loudly.

Add one guard in fetchAmulet() that protects all three call sites.

Fixes canton-network#1797

Signed-off-by: ayushsingh82 <ayushsinghmi711@gmail.com>
@ayushsingh82

Copy link
Copy Markdown
Contributor Author

@alexmatson-da whenever you have a chance, would appreciate a look at this one.

@mjuchli-da mjuchli-da changed the title Assert amulet.admin is present before building commands that need it chore: assert amulet.admin is present before building commands that need it Aug 20, 2026
@mjuchli-da

Copy link
Copy Markdown
Contributor

@rukmini-basu-da to review

Comment thread sdk/wallet-sdk/src/wallet/namespace/amulet/namespace.ts Outdated
Validating the registry response's admin field in fetchAmulet() only
covered the amulet call site. parseAssets is the shared function that
converts raw registry data into AssetBody for all callers (amulet,
token transfer, token utxos), so the guard belongs there instead.

Adds a unit test covering the missing-admin case.

Signed-off-by: ayushsingh82 <ayushsinghmi711@gmail.com>
Comment thread sdk/wallet-sdk/src/wallet/namespace/utils/url.ts Outdated
ayushsingh82 and others added 3 commits August 21, 2026 17:37
Address review feedback: annotate the return type as AssetBody[]
instead of relying on inference.

Signed-off-by: ayushsingh82 <ayushsinghmi711@gmail.com>
@rukmini-basu-da
rukmini-basu-da merged commit 346463a into canton-network:main Aug 25, 2026
26 checks passed
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.

Wallet SDK V1 asserting registry data

3 participants