Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

feat: add Stellar signatures support#558

Closed
jobotics wants to merge 12 commits intobetafrom
feat/stellar-signatures-support
Closed

feat: add Stellar signatures support#558
jobotics wants to merge 12 commits intobetafrom
feat/stellar-signatures-support

Conversation

@jobotics
Copy link
Collaborator

@jobotics jobotics commented Jul 28, 2025

Depends on defuse-protocol/sdk-monorepo#60

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for Stellar authentication and wallet signatures throughout the app.
    • Enabled deposit route availability and message signing for Stellar wallets.
    • Stellar messages and signatures now follow the same format and verification logic as Solana.
  • Chores

    • Centralized authentication and wallet message utilities by migrating many local types and functions to the external @defuse-protocol/internal-utils package.
    • Updated imports and type references across the codebase to use the external package for authentication methods, wallet messages, signature handling, and message factories.
    • Removed several local utility files and test suites related to message creation, signature preparation, and authentication identity conversion.
    • Refactored type annotations and function signatures to align with the centralized external utilities.
  • Tests

    • Expanded test coverage to include Stellar authentication, message creation, signature handling, and broadcast preparation.

@jobotics jobotics requested a review from cawabunga-bytes July 28, 2025 14:31
@coderabbitai
Copy link

coderabbitai bot commented Jul 28, 2025

Walkthrough

The codebase was refactored to remove local definitions and implementations related to authentication methods, wallet messages, and message factories, replacing them with centralized imports from the external package @defuse-protocol/internal-utils. This includes removal of local types, utilities, and test suites for authentication identity conversion, message creation, signature preparation, and wallet message types. Additionally, support for the Stellar blockchain was integrated by grouping it with Solana in deposit routing and signature verification logic. Numerous imports and type annotations across features, machines, utilities, and components were updated to use the centralized external package instead of local modules. No changes to core logic or exported entity signatures were introduced beyond these import and type source consolidations.

Changes

Cohort / File(s) Change Summary
Removal of Local Auth Handle Types and Utilities
src/types/authHandle.ts, src/utils/authIdentity.ts, src/utils/authIdentity.test.ts
Deleted local AuthMethod, AuthHandle types and authHandleToIntentsUserId utility with its tests. Replaced all usage with imports from @defuse-protocol/internal-utils under authIdentity and AuthMethod.
Removal of Local Wallet Message Types and Utilities
src/types/walletMessage.ts, src/utils/messageFactory.ts, src/utils/messageFactory.test.ts, src/utils/prepareBroadcastRequest.ts, src/utils/prepareBroadcastRequest.test.ts
Deleted wallet message type definitions, message factory functions, and signature preparation utilities with tests. Replaced all usage with imports from @defuse-protocol/internal-utils under walletMessage and messageFactory.
Signature Verification Update
src/utils/verifyWalletSignature.ts
Updated signature verification to import walletMessage types from external package and added Stellar support grouped with Solana for Ed25519 signature verification.
Deposit Service Update
src/services/depositService.ts
Updated imports to use external AuthMethod and authIdentity. Added Stellar support grouped with Solana in deposit route logic.
Core and Feature Files Import Refactoring
Multiple files including src/core/*, src/features/*, src/types/*
Replaced local imports of AuthMethod, WalletMessage, WalletSignatureResult, authHandleToIntentsUserId, and message factory functions with imports from @defuse-protocol/internal-utils. Updated all type annotations and usage accordingly.
Test Files Import Updates
src/features/otcDesk/utils/schemaMultipayload.test.ts, src/features/otcDesk/utils/schemaPrimitives.test.ts, src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/validation.test.ts
Updated test imports to use @defuse-protocol/internal-utils for signature transformation and auth identity utilities.
Deleted Exports and Types
src/types.ts, src/types/deposit.ts, src/types/swap.ts, src/types/withdraw.ts
Removed export of AuthMethod from local types. Updated type references for auth handles and wallet messages to use external package namespaces.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

Gone the locals, centralized the code,
Rabbit hops on a streamlined road.
Auth and messages now in one place,
Cleaner imports, a neater space.
Stellar joins Solana's flight,
Together they leap, swift and bright!
🐇🚀✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/stellar-signatures-support

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 1

🔭 Outside diff range comments (1)
src/utils/prepareBroadcastRequest.ts (1)

36-48: Fix assertion logic for Stellar signatures.

The assertion currently requires userInfo.userChainType === "solana" for both SOLANA and STELLAR signature types, but it should accept "stellar" for STELLAR signatures.

     case "SOLANA":
     case "STELLAR":
       assert(
-        userInfo.userChainType === "solana",
+        (signatureType === "SOLANA" && userInfo.userChainType === "solana") ||
+        (signatureType === "STELLAR" && userInfo.userChainType === "stellar"),
         "User chain and signature chain must match"
       )
🧹 Nitpick comments (1)
src/utils/authIdentity.ts (1)

23-25: Update documentation to include Stellar.

The comment should be updated to reflect that both Solana and Stellar addresses use the same base58 to hex conversion.

-// 3. Solana addresses: Converted from base58 to hex
+// 3. Solana/Stellar addresses: Converted from base58 to hex
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c5c6f8 and 41a6df4.

⛔ Files ignored due to path filters (1)
  • src/utils/__snapshots__/prepareBroadcastRequest.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (10)
  • src/services/depositService.ts (1 hunks)
  • src/types/authHandle.ts (1 hunks)
  • src/types/walletMessage.ts (2 hunks)
  • src/utils/authIdentity.test.ts (1 hunks)
  • src/utils/authIdentity.ts (1 hunks)
  • src/utils/messageFactory.test.ts (2 hunks)
  • src/utils/messageFactory.ts (1 hunks)
  • src/utils/prepareBroadcastRequest.test.ts (3 hunks)
  • src/utils/prepareBroadcastRequest.ts (3 hunks)
  • src/utils/verifyWalletSignature.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/utils/prepareBroadcastRequest.test.ts (2)
src/types/walletMessage.ts (1)
  • StellarSignatureData (106-110)
src/utils/prepareBroadcastRequest.ts (1)
  • prepareSwapSignedData (8-70)
src/services/depositService.ts (1)
src/types/authHandle.ts (2)
  • AuthMethod (1-7)
  • AuthMethod (9-16)
src/utils/messageFactory.test.ts (2)
src/utils/messageFactory.ts (2)
  • makeInnerSwapMessage (24-68)
  • makeSwapMessage (246-291)
src/utils/authIdentity.ts (1)
  • authHandleToIntentsUserId (40-83)
src/utils/authIdentity.test.ts (1)
src/utils/authIdentity.ts (1)
  • authHandleToIntentsUserId (40-83)
🔇 Additional comments (14)
src/types/authHandle.ts (1)

7-7: LGTM: Clean addition of Stellar auth method.

The addition follows the established pattern and maintains type safety. The constant object correctly mirrors the type definition.

Also applies to: 15-15

src/utils/authIdentity.test.ts (1)

28-36: LGTM: Comprehensive test coverage for Stellar authentication.

The test correctly verifies that Stellar identifiers are processed through base58 decode and hex encode, consistent with the Solana implementation. The test structure follows established patterns.

src/services/depositService.ts (1)

895-895: LGTM: Consistent deposit route handling for Stellar.

Adding Stellar to the same case as Solana is appropriate since both blockchains use Ed25519 signatures and should have equivalent deposit capabilities. The fallthrough logic maintains consistency.

src/utils/messageFactory.ts (1)

276-278: LGTM: Appropriate message format for Stellar.

Using the same payloadBytes format as Solana is correct since both blockchains use Ed25519 signatures and require identical message structures for signature verification.

src/utils/verifyWalletSignature.ts (1)

29-30: LGTM: Correct signature verification for Stellar.

Grouping Stellar with Solana for signature verification is appropriate since both use Ed25519 signatures. The shared verification logic using sign.detached.verify is correct for both blockchain types.

src/utils/authIdentity.ts (1)

64-64: LGTM: Stellar support added correctly.

Adding Stellar to fall through to the same case as Solana is appropriate since both use Ed25519 public keys encoded in base58.

src/utils/prepareBroadcastRequest.test.ts (2)

6-6: LGTM: Import added correctly.


42-46: LGTM: Stellar message format matches Solana.

The Stellar message format correctly mirrors the Solana format since both use Ed25519 signatures.

src/utils/prepareBroadcastRequest.ts (2)

47-47: LGTM: Function rename improves clarity.

Renaming transformSolanaSignature to transformED25519Signature better reflects that it handles Ed25519 signatures from both Solana and Stellar.


109-111: LGTM: Function rename is consistent.

The function rename from transformSolanaSignature to transformED25519Signature makes it more generic and appropriate for both Solana and Stellar.

src/utils/messageFactory.test.ts (2)

59-72: LGTM: Stellar message format correctly mirrors Solana.

The expected Stellar message format appropriately matches the Solana format since both use Ed25519 signatures and the same message structure.


220-247: LGTM: Comprehensive test for Stellar message format.

The test properly verifies that Stellar messages match Solana messages and includes good documentation explaining the rationale. The test also validates the decoded message content structure.

src/types/walletMessage.ts (2)

101-110: LGTM: Stellar types follow established patterns.

The StellarMessage and StellarSignatureData types are well-structured and consistent with the existing type patterns. The message format appropriately matches SolanaMessage since both use Ed25519 signatures.


118-127: LGTM: Union types properly extended.

The WalletMessage and WalletSignatureResult union types are correctly extended to include the new Stellar types.

Comment on lines +100 to +113
it("should return the correct signed data for a Stellar signature", () => {
const signature: StellarSignatureData = {
type: "STELLAR",
signatureData: Buffer.from("deadbeef1c", "hex"),
signedData: walletMessage.STELLAR,
}

expect(
prepareSwapSignedData(signature, {
userAddress: "DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy",
userChainType: "stellar",
})
).toMatchSnapshot()
})
Copy link

@coderabbitai coderabbitai bot Jul 28, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix user chain type assertion mismatch.

The test uses userChainType: "stellar" but the prepareSwapSignedData function asserts that userInfo.userChainType === "solana" for both SOLANA and STELLAR cases. This will cause the test to fail.

     expect(
       prepareSwapSignedData(signature, {
         userAddress: "DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy",
-        userChainType: "stellar",
+        userChainType: "solana",
       })
     ).toMatchSnapshot()
📝 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
it("should return the correct signed data for a Stellar signature", () => {
const signature: StellarSignatureData = {
type: "STELLAR",
signatureData: Buffer.from("deadbeef1c", "hex"),
signedData: walletMessage.STELLAR,
}
expect(
prepareSwapSignedData(signature, {
userAddress: "DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy",
userChainType: "stellar",
})
).toMatchSnapshot()
})
it("should return the correct signed data for a Stellar signature", () => {
const signature: StellarSignatureData = {
type: "STELLAR",
signatureData: Buffer.from("deadbeef1c", "hex"),
signedData: walletMessage.STELLAR,
}
expect(
prepareSwapSignedData(signature, {
userAddress: "DRpbCBMxVnDK7maPM5tGv6MvB3v1sRMC86PZ8okm21hy",
userChainType: "solana",
})
).toMatchSnapshot()
})
🤖 Prompt for AI Agents
In src/utils/prepareBroadcastRequest.test.ts around lines 100 to 113, the test
sets userChainType to "stellar" but the prepareSwapSignedData function expects
userChainType to be "solana" for both SOLANA and STELLAR cases. To fix this,
change the userChainType value in the test from "stellar" to "solana" to match
the assertion in the function and ensure the test passes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you double-check? prepareSwapSignedData does expect case "STELLAR": as well.

Copy link

Choose a reason for hiding this comment

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

🧩 Analysis chain

@jobotics You're absolutely right to question this. Let me examine the actual implementation of prepareSwapSignedData to verify the correct behavior.


🏁 Script executed:

#!/bin/bash
# Let's look at the prepareSwapSignedData function implementation
cat src/utils/prepareBroadcastRequest.ts

Length of output: 3759


@jobotics You're right to ask me to double-check! I've examined the actual implementation, and I can confirm my original analysis was correct.

Looking at the prepareSwapSignedData function, both "SOLANA" and "STELLAR" cases fall through to the same code block:

case "SOLANA":
case "STELLAR":
  assert(
    userInfo.userChainType === "solana",
    "User chain and signature chain must match"
  )

The assertion explicitly requires userInfo.userChainType === "solana" for both SOLANA and STELLAR signature types. So the test with userChainType: "stellar" would indeed fail this assertion.

However, this reveals what might be a design issue: if STELLAR signatures are now supported, shouldn't the assertion also accept "stellar" as a valid userChainType? The current implementation treats both signature types identically but only accepts Solana as the user chain type.

Would you like me to suggest updating either:

  1. The test (as originally suggested) to use "solana"
  2. The assertion in prepareSwapSignedData to accept both "solana" and "stellar"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ohh, you are right!

Copy link

Choose a reason for hiding this comment

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

@jobotics Thanks for taking the time to double-check with me! I'm glad we could work through this together and confirm the mismatch. The test will indeed fail with userChainType: "stellar" due to that assertion requiring "solana".

Should I help you decide whether to:

  1. Update the test to use userChainType: "solana" (quick fix)

  2. Update the assertion in prepareSwapSignedData to accept both "solana" and "stellar" (more comprehensive but requires understanding the intended design)

    (\ /)
    ( .. )
    o
    (")(") happy rabbit - glad we figured it out together!

Copy link

@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: 5

♻️ Duplicate comments (2)
src/features/1Click/components/SwapUIMachineFormSyncProvider.tsx (1)

1-1: Duplicate: AuthMethod export issue.

Same issue as in SwapSubmitter.tsx - AuthMethod is not exported from the external package.

src/features/swap/components/SwapUIMachineProvider.tsx (1)

1-1: Same critical issue: walletMessage export not found.

This file has the same compilation issue as src/features/1Click/components/SwapUIMachineProvider.tsx - the walletMessage import from @defuse-protocol/internal-utils is causing a compilation error.

The resolution for this issue should be the same as the other affected file - ensure the external package properly exports the walletMessage namespace.

Also applies to: 55-57

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 41a6df4 and a17722b.

📒 Files selected for processing (69)
  • src/core/formatters.ts (3 hunks)
  • src/core/messages.test.ts (2 hunks)
  • src/core/messages.ts (6 hunks)
  • src/features/1Click/components/SwapSubmitter.tsx (1 hunks)
  • src/features/1Click/components/SwapUIMachineFormSyncProvider.tsx (1 hunks)
  • src/features/1Click/components/SwapUIMachineProvider.tsx (2 hunks)
  • src/features/account/components/AccountWidget.tsx (2 hunks)
  • src/features/deposit/components/DepositForm/index.tsx (1 hunks)
  • src/features/deposit/components/DepositUIMachineFormSyncProvider.tsx (1 hunks)
  • src/features/deposit/components/DepositUIMachineProvider.tsx (2 hunks)
  • src/features/gift/actors/giftMakerRootMachine.ts (2 hunks)
  • src/features/gift/actors/giftMakerSignActor.ts (4 hunks)
  • src/features/gift/components/GiftHistoryWidget.tsx (2 hunks)
  • src/features/gift/components/GiftMakerForm.tsx (1 hunks)
  • src/features/gift/components/GiftTakerWidget.tsx (1 hunks)
  • src/features/gift/hooks/useBalanceUpdaterSyncWithHistory.ts (2 hunks)
  • src/features/gift/stores/storageOperations.ts (2 hunks)
  • src/features/gift/types/sharedTypes.ts (2 hunks)
  • src/features/gift/utils/determineGiftToken.ts (2 hunks)
  • src/features/gift/utils/signGiftTakerMessage.ts (3 hunks)
  • src/features/machines/depositGenerateAddressMachine.ts (1 hunks)
  • src/features/machines/depositUIMachine.ts (1 hunks)
  • src/features/machines/depositedBalanceMachine.ts (2 hunks)
  • src/features/machines/signIntentMachine.ts (4 hunks)
  • src/features/machines/swapIntentMachine.ts (7 hunks)
  • src/features/machines/swapUIMachine.ts (2 hunks)
  • src/features/machines/swapUIMachine1Click.ts (2 hunks)
  • src/features/machines/withdrawUIMachine.ts (2 hunks)
  • src/features/otcDesk/actors/otcMakerOrderCancellationActor.ts (2 hunks)
  • src/features/otcDesk/actors/otcMakerRootMachine.ts (2 hunks)
  • src/features/otcDesk/actors/otcMakerSignActor.ts (4 hunks)
  • src/features/otcDesk/components/OtcMakerForm.tsx (1 hunks)
  • src/features/otcDesk/components/OtcMakerTrades.tsx (2 hunks)
  • src/features/otcDesk/components/OtcTakerForm.tsx (2 hunks)
  • src/features/otcDesk/components/OtcTakerWidget.tsx (1 hunks)
  • src/features/otcDesk/hooks/useOtcTakerConfirmTrade.ts (2 hunks)
  • src/features/otcDesk/providers/SignIntentActorProvider.tsx (3 hunks)
  • src/features/otcDesk/stores/otcMakerTrades.ts (3 hunks)
  • src/features/otcDesk/types/sharedTypes.ts (1 hunks)
  • src/features/otcDesk/utils/parseTradeTerms.test.ts (2 hunks)
  • src/features/otcDesk/utils/schemaMultipayload.test.ts (3 hunks)
  • src/features/otcDesk/utils/schemaPrimitives.test.ts (2 hunks)
  • src/features/otcDesk/utils/schemaPrimitives.ts (2 hunks)
  • src/features/swap/components/SwapSubmitter.tsx (1 hunks)
  • src/features/swap/components/SwapUIMachineFormSyncProvider.tsx (1 hunks)
  • src/features/swap/components/SwapUIMachineProvider.tsx (2 hunks)
  • src/features/tokenMigration/components/TokenMigration.tsx (1 hunks)
  • src/features/tokenMigration/components/TokenMigrationDialog.tsx (2 hunks)
  • src/features/tokenMigration/machines/tokenMigrationMachine.ts (3 hunks)
  • src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/RecipientSubForm.tsx (1 hunks)
  • src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/validation.test.ts (6 hunks)
  • src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/validation.ts (2 hunks)
  • src/features/withdraw/components/WithdrawForm/utils.ts (1 hunks)
  • src/features/withdraw/components/WithdrawWidget.tsx (3 hunks)
  • src/services/depositService.ts (3 hunks)
  • src/types.ts (0 hunks)
  • src/types/authHandle.ts (0 hunks)
  • src/types/deposit.ts (1 hunks)
  • src/types/swap.ts (2 hunks)
  • src/types/walletMessage.ts (0 hunks)
  • src/types/withdraw.ts (1 hunks)
  • src/utils/authIdentity.test.ts (0 hunks)
  • src/utils/authIdentity.ts (0 hunks)
  • src/utils/messageFactory.test.ts (0 hunks)
  • src/utils/messageFactory.ts (0 hunks)
  • src/utils/multiPayload/webauthn.ts (1 hunks)
  • src/utils/prepareBroadcastRequest.test.ts (0 hunks)
  • src/utils/prepareBroadcastRequest.ts (0 hunks)
  • src/utils/verifyWalletSignature.ts (2 hunks)
💤 Files with no reviewable changes (9)
  • src/types.ts
  • src/utils/prepareBroadcastRequest.test.ts
  • src/types/authHandle.ts
  • src/utils/authIdentity.test.ts
  • src/utils/authIdentity.ts
  • src/utils/messageFactory.test.ts
  • src/utils/messageFactory.ts
  • src/types/walletMessage.ts
  • src/utils/prepareBroadcastRequest.ts
✅ Files skipped from review due to trivial changes (37)
  • src/features/tokenMigration/components/TokenMigration.tsx
  • src/features/swap/components/SwapSubmitter.tsx
  • src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/RecipientSubForm.tsx
  • src/features/machines/depositGenerateAddressMachine.ts
  • src/features/machines/depositUIMachine.ts
  • src/features/gift/components/GiftMakerForm.tsx
  • src/features/deposit/components/DepositUIMachineFormSyncProvider.tsx
  • src/features/otcDesk/components/OtcTakerWidget.tsx
  • src/features/swap/components/SwapUIMachineFormSyncProvider.tsx
  • src/features/deposit/components/DepositUIMachineProvider.tsx
  • src/features/gift/components/GiftTakerWidget.tsx
  • src/features/withdraw/components/WithdrawForm/utils.ts
  • src/features/otcDesk/components/OtcMakerForm.tsx
  • src/features/otcDesk/components/OtcTakerForm.tsx
  • src/features/account/components/AccountWidget.tsx
  • src/features/otcDesk/hooks/useOtcTakerConfirmTrade.ts
  • src/features/gift/stores/storageOperations.ts
  • src/features/gift/hooks/useBalanceUpdaterSyncWithHistory.ts
  • src/features/deposit/components/DepositForm/index.tsx
  • src/features/machines/swapUIMachine1Click.ts
  • src/features/withdraw/components/WithdrawWidget.tsx
  • src/features/otcDesk/utils/schemaPrimitives.test.ts
  • src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/validation.ts
  • src/types/deposit.ts
  • src/features/withdraw/components/WithdrawForm/components/RecipientSubForm/validation.test.ts
  • src/features/otcDesk/stores/otcMakerTrades.ts
  • src/features/tokenMigration/components/TokenMigrationDialog.tsx
  • src/features/otcDesk/actors/otcMakerSignActor.ts
  • src/features/otcDesk/actors/otcMakerOrderCancellationActor.ts
  • src/features/otcDesk/providers/SignIntentActorProvider.tsx
  • src/features/otcDesk/types/sharedTypes.ts
  • src/features/gift/actors/giftMakerRootMachine.ts
  • src/features/otcDesk/actors/otcMakerRootMachine.ts
  • src/features/machines/signIntentMachine.ts
  • src/features/machines/swapIntentMachine.ts
  • src/features/gift/utils/signGiftTakerMessage.ts
  • src/utils/multiPayload/webauthn.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/utils/verifyWalletSignature.ts
  • src/services/depositService.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/features/gift/types/sharedTypes.ts (1)
src/features/otcDesk/types/sharedTypes.ts (1)
  • SignMessage (6-8)
src/features/otcDesk/utils/schemaMultipayload.test.ts (2)
src/core/formatters.ts (1)
  • SignerCredentials (10-15)
src/index.ts (1)
  • SignerCredentials (28-28)
🪛 GitHub Check: test / test
src/features/1Click/components/SwapUIMachineProvider.tsx

[failure] 1-1:
Module '"@defuse-protocol/internal-utils"' has no exported member 'walletMessage'.

src/core/messages.ts

[failure] 3-3:
Module '"@defuse-protocol/internal-utils"' has no exported member 'walletMessage'.


[failure] 2-2:
Module '"@defuse-protocol/internal-utils"' has no exported member 'messageFactory'.

src/core/formatters.ts

[failure] 5-5:
Module '"@defuse-protocol/internal-utils"' has no exported member 'walletMessage'.


[failure] 5-5:
Module '"@defuse-protocol/internal-utils"' declares 'AuthMethod' locally, but it is not exported.


[failure] 3-3:
Module '"@defuse-protocol/internal-utils"' has no exported member 'prepareBroadcastRequest'.


[failure] 2-2:
Module '"@defuse-protocol/internal-utils"' has no exported member 'authIdentity'.

src/core/messages.test.ts

[failure] 1-1:
Module '"@defuse-protocol/internal-utils"' has no exported member 'authIdentity'.

src/features/1Click/components/SwapSubmitter.tsx

[failure] 1-1:
Module '"@defuse-protocol/internal-utils"' declares 'AuthMethod' locally, but it is not exported.

src/features/1Click/components/SwapUIMachineFormSyncProvider.tsx

[failure] 1-1:
Module '"@defuse-protocol/internal-utils"' declares 'AuthMethod' locally, but it is not exported.

🪛 GitHub Actions: CI
src/core/formatters.ts

[error] 2-2: TypeScript error TS2305: Module '@defuse-protocol/internal-utils' has no exported member 'authIdentity'.

⏰ 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). (2)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (27)
src/types/withdraw.ts (3)

7-8: LGTM! Type references correctly updated to use namespaced imports.

The type references have been properly updated to use the namespaced authHandle.AuthHandle type from the external package, maintaining the same semantic meaning with indexed access types.


15-17: LGTM! Function signature properly updated with namespaced types.

The signMessage function signature has been correctly updated to use the namespaced wallet message types from the external package, maintaining the same function contract.


1-1: Ensure @defuse-protocol/internal-utils exports required types

I wasn’t able to locate the package in node_modules, so please double-check that the dependency is installed and that its TypeScript definitions include the following exports:

  • Confirm @defuse-protocol/internal-utils is listed under your project’s dependencies (package.json).
  • Verify its .d.ts files export authHandle and walletMessage (e.g. via export namespace authHandle { … } or export type authHandle = …).

Location to review:

  • src/types/withdraw.ts (line 1)
src/features/1Click/components/SwapSubmitter.tsx (1)

1-1: Critical: AuthMethod import missing – build will fail

The attempt to import AuthMethod from @defuse-protocol/internal-utils currently errors out because the module can’t be found. To resolve this:

  • Add @defuse-protocol/internal-utils to your project’s package.json dependencies and run npm install (or yarn).
  • Confirm that the published package exports a type named AuthMethod.
  • If the export’s name or location has changed, update the import in src/features/1Click/components/SwapSubmitter.tsx accordingly.

fix_required

src/core/messages.test.ts (1)

11-11: Consistent refactoring to namespaced access.

The usage correctly updates to access the method through the authIdentity namespace, assuming the export issue is resolved.

src/features/otcDesk/utils/schemaPrimitives.ts (2)

1-1: Import refactoring follows consistent pattern.

The change from direct function import to namespaced import is consistent with the overall refactoring approach.


55-56: Correct usage of namespaced function access.

The function call correctly accesses normalizeERC191Signature through the prepareBroadcastRequest namespace.

Please ensure the external package properly exports prepareBroadcastRequest.normalizeERC191Signature to avoid runtime errors.

src/features/otcDesk/utils/parseTradeTerms.test.ts (2)

1-1: Consistent import refactoring pattern.

The change follows the same pattern as other files, moving from local import to external package import.

Based on similar issues in other files, please verify that authIdentity is properly exported from the external package.


24-27: Correct namespaced function usage.

The function call correctly uses the namespaced access pattern authIdentity.authHandleToIntentsUserId.

src/features/gift/utils/determineGiftToken.ts (1)

1-1: LGTM! Clean refactor to centralized authentication utilities.

The import change from local authHandleToIntentsUserId to the namespaced authIdentity.authHandleToIntentsUserId from the external package is consistent with the broader refactoring effort. The function call is properly updated to use the new namespace.

Also applies to: 30-33

src/features/otcDesk/components/OtcMakerTrades.tsx (1)

1-1: LGTM! Consistent refactoring pattern.

The import and usage changes follow the same pattern as other files in this refactor, replacing local authentication utilities with the centralized external package. The function call is correctly updated to use the namespaced method.

Also applies to: 72-76

src/features/gift/components/GiftHistoryWidget.tsx (1)

1-2: LGTM! Complete refactor of authentication imports.

Both the authIdentity namespace and AuthMethod type are properly imported from the external package, and the function call is correctly updated to use the namespaced method. This maintains the existing functionality while centralizing authentication utilities.

Also applies to: 38-42

src/features/machines/withdrawUIMachine.ts (1)

1-2: LGTM! Proper refactoring of authentication utilities in state machine.

The imports and function call are correctly updated to use the centralized authentication utilities. The logic for converting user credentials to defuseUserId remains unchanged while using the new namespaced approach.

Also applies to: 601-604

src/features/machines/depositedBalanceMachine.ts (1)

1-2: LGTM! Consistent authentication refactoring in balance machine.

The imports and function usage are properly updated to use the centralized authentication utilities from the external package. The LOGIN event handler correctly uses the namespaced function to convert user credentials to the intents user ID.

Also applies to: 267-270

src/features/tokenMigration/machines/tokenMigrationMachine.ts (1)

1-2: LGTM! Clean refactoring to external package.

The import changes correctly replace local modules with the centralized @defuse-protocol/internal-utils package. The usage of namespaced imports (messageFactory.makeSwapMessage, walletMessage.WalletSignatureResult) maintains good type safety and code clarity.

Also applies to: 30-30, 143-143

src/types/swap.ts (1)

1-1: LGTM! Consistent type refactoring.

The import changes properly centralize the AuthMethod and walletMessage types, and the function signature correctly uses the namespaced types for better type safety.

Also applies to: 28-30

src/features/machines/swapUIMachine.ts (1)

1-2: LGTM! Proper centralization of auth utilities.

The refactoring correctly replaces the local authHandleToIntentsUserId function with authIdentity.authHandleToIntentsUserId from the external package. The namespaced import pattern maintains good code organization and type safety.

Also applies to: 420-423

src/features/gift/actors/giftMakerSignActor.ts (2)

61-61: LGTM! Type annotations updated correctly.

The type annotations have been properly updated to use the namespaced types from the external package.

Also applies to: 70-70


186-186: LGTM! Function call updated to use external utility.

The nonce generation has been correctly updated to use messageFactory.randomDefuseNonce() from the external package.

src/features/gift/types/sharedTypes.ts (2)

1-1: Import change aligns with centralization effort.

The import has been correctly updated to use the external package, consistent with the broader refactoring across the codebase.


7-8: Type annotations updated correctly.

The type annotations for SignMessage parameters and GiftSignedResult.signatureResult have been properly updated to use the namespaced types from the external package, matching the pattern used in src/features/otcDesk/types/sharedTypes.ts.

Also applies to: 18-18

src/features/otcDesk/utils/schemaMultipayload.test.ts (3)

1-2: Import changes align with centralization effort.

The imports have been correctly updated to use the external package for both utility functions and types.


135-137: Type annotation updated correctly.

The FakeSign type has been properly updated to use the namespaced walletMessage.WalletMessage type.


152-154: Function call updated to use external utility.

The call to normalizeERC191Signature has been correctly updated to use the namespaced function from the external package.

src/core/messages.ts (2)

35-35: Return type annotations updated correctly.

All function return types have been properly updated to use walletMessage.WalletMessage from the external package, assuming the export issue is resolved.

Also applies to: 52-52, 76-76, 98-98, 119-119


53-53: Function calls updated to use external utilities.

All message factory function calls have been correctly updated to use the namespaced methods from the external package.

Also applies to: 61-61, 77-77, 85-85, 99-99, 120-120, 128-128

src/core/formatters.ts (1)

27-27: Function signatures and calls updated correctly.

The function parameter types and calls to external utilities have been properly updated to use the namespaced imports, assuming the export issues are resolved.

Also applies to: 30-30, 44-44

Comment on lines +1 to +5
import {
authIdentity,
prepareBroadcastRequest,
} from "@defuse-protocol/internal-utils"
import type { AuthMethod, walletMessage } from "@defuse-protocol/internal-utils"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: External package missing required exports.

The pipeline failure and static analysis clearly indicate that multiple required exports are missing from @defuse-protocol/internal-utils:

  • authIdentity (pipeline failure)
  • prepareBroadcastRequest (static analysis)
  • walletMessage (static analysis)
  • AuthMethod (not exported)

This confirms a dependency issue where this PR requires the related changes from defuse-protocol/sdk-monorepo#60 to be merged first.

🧰 Tools
🪛 GitHub Check: test / test

[failure] 5-5:
Module '"@defuse-protocol/internal-utils"' has no exported member 'walletMessage'.


[failure] 5-5:
Module '"@defuse-protocol/internal-utils"' declares 'AuthMethod' locally, but it is not exported.


[failure] 3-3:
Module '"@defuse-protocol/internal-utils"' has no exported member 'prepareBroadcastRequest'.


[failure] 2-2:
Module '"@defuse-protocol/internal-utils"' has no exported member 'authIdentity'.

🪛 GitHub Actions: CI

[error] 2-2: TypeScript error TS2305: Module '@defuse-protocol/internal-utils' has no exported member 'authIdentity'.

🤖 Prompt for AI Agents
In src/core/formatters.ts lines 1 to 5, the imports from
@defuse-protocol/internal-utils include symbols that are not yet exported,
causing pipeline failures and static analysis errors. To fix this, remove or
comment out the imports of authIdentity, prepareBroadcastRequest, walletMessage,
and AuthMethod until the related PR
https://github.com/defuse-protocol/sdk-monorepo/pull/60 is merged and these
exports become available.

@@ -1,5 +1,5 @@
import { authIdentity } from "@defuse-protocol/internal-utils"
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Critical: authIdentity not exported from external package.

The static analysis indicates that authIdentity is not exported from @defuse-protocol/internal-utils. This will cause the test to fail.

Please verify the external package exports the authIdentity object with the authHandleToIntentsUserId method.


🏁 Script executed:

#!/usr/bin/env bash
set -e

# Download the package tarball
PKG=$(npm pack @defuse-protocol/internal-utils)
echo "Packed as $PKG"

# List all JavaScript and TypeScript declaration files in the tarball
FILES=$(tar -tzf "$PKG" | grep -E '\.js$|\.d\.ts$')
echo "Relevant files:"
echo "$FILES"

# Search each file for the authIdentity export
echo "Searching for 'authIdentity' occurrences..."
for f in $FILES; do
  echo "=== $f ==="
  tar -xzOf "$PKG" "$f" | grep -H "authIdentity" || true
done

Length of output: 1674


Critical: authIdentity isn’t exported from @defuse-protocol/internal-utils

The package’s declaration file (dist/index.d.ts) contains no authIdentity export, so importing it will break the build.

• File: src/core/messages.test.ts
Line 1:

import { authIdentity } from "@defuse-protocol/internal-utils"

• Evidence: dist/index.d.ts has no mention of authIdentity

Please either:

  • Revert to the original local import (authHandleToIntentsUserId) or
  • Update @defuse-protocol/internal-utils to export authIdentity.authHandleToIntentsUserId
🧰 Tools
🪛 GitHub Check: test / test

[failure] 1-1:
Module '"@defuse-protocol/internal-utils"' has no exported member 'authIdentity'.

🤖 Prompt for AI Agents
In src/core/messages.test.ts at line 1, the import statement tries to import
`authIdentity` from `@defuse-protocol/internal-utils`, but this export does not
exist and breaks the build. To fix this, revert the import to use the original
local import `authHandleToIntentsUserId` instead of `authIdentity`, or update
the `@defuse-protocol/internal-utils` package to export
`authIdentity.authHandleToIntentsUserId` if that is preferred.

Comment on lines 1 to +4
import {
type WithdrawParams,
makeEmptyMessage,
makeInnerSwapAndWithdrawMessage,
makeInnerSwapMessage,
makeInnerTransferMessage,
makeSwapMessage,
} from "../utils/messageFactory"
messageFactory,
type walletMessage,
} from "@defuse-protocol/internal-utils"
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: External package missing required exports.

The import changes are structurally correct, but static analysis indicates that messageFactory and walletMessage are not exported from @defuse-protocol/internal-utils. This will cause compilation failures.

This appears to be a dependency issue where the changes in this repository depend on the related PR mentioned in the objectives: defuse-protocol/sdk-monorepo#60

Ensure that the dependency PR is merged and the package is updated before merging these changes.

🧰 Tools
🪛 GitHub Check: test / test

[failure] 3-3:
Module '"@defuse-protocol/internal-utils"' has no exported member 'walletMessage'.


[failure] 2-2:
Module '"@defuse-protocol/internal-utils"' has no exported member 'messageFactory'.

🤖 Prompt for AI Agents
In src/core/messages.ts at lines 1 to 4, the imports of messageFactory and
walletMessage from @defuse-protocol/internal-utils are causing compilation
errors because these exports do not exist in the current package version. To fix
this, ensure that the related dependency PR
(https://github.com/defuse-protocol/sdk-monorepo/pull/60) is merged and the
package is updated to include these exports before merging this code.

@@ -1,3 +1,4 @@
import type { walletMessage } from "@defuse-protocol/internal-utils"
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Critical: Module export mismatch causing compilation failure.

The static analysis reports that Module '@defuse-protocol/internal-utils' has no exported member 'walletMessage', which will cause compilation to fail. This suggests the external package may not be exporting walletMessage as expected.

Please verify the export structure of the @defuse-protocol/internal-utils package:

Since this PR depends on defuse-protocol/sdk-monorepo#60, ensure that dependency is merged and the package version is updated accordingly.

Also applies to: 53-55


🏁 Script executed:

#!/bin/bash
# Description: Check the exported members of the external package
# Expected: Should show walletMessage export

# Check if the package is installed and its exports
cat package.json | jq '.dependencies["@defuse-protocol/internal-utils"]'

# If package is available, check its TypeScript definitions
fd -e d.ts -x cat {} \; --search-path node_modules/@defuse-protocol/internal-utils | head -50

Length of output: 313


🏁 Script executed:

#!/bin/bash
# Fetch package manifest fields for types and main entry
npm view @defuse-protocol/internal-utils@0.1.2 types main --json

# Attempt to download the TypeScript definitions from unpkg, if a types field exists
types=$(npm view @defuse-protocol/internal-utils@0.1.2 types)
if [ -n "$types" ]; then
  echo "==> Downloading definitions for $types from unpkg"
  curl -s "https://unpkg.com/@defuse-protocol/internal-utils@0.1.2/$types" | head -200
else
  echo "No 'types' entry in package manifest; trying to inspect index.d.ts"
  curl -s "https://unpkg.com/@defuse-protocol/internal-utils@0.1.2/index.d.ts" | head -200
fi

Length of output: 6684


Critical: walletMessage import missing in @defuse-protocol/internal-utils

The TypeScript definitions for version 0.1.2 of @defuse-protocol/internal-utils (see ./dist/index.d.ts) do not include any export named walletMessage. This will cause a compilation error in your PR.

Please address this by either:

Affected locations:

  • src/features/1Click/components/SwapUIMachineProvider.tsx
    • Line 1: import type { walletMessage } from "@defuse-protocol/internal-utils"
    • Lines 53–55: usage in function signature
🧰 Tools
🪛 GitHub Check: test / test

[failure] 1-1:
Module '"@defuse-protocol/internal-utils"' has no exported member 'walletMessage'.

🤖 Prompt for AI Agents
In src/features/1Click/components/SwapUIMachineProvider.tsx at line 1 and lines
53-55, the import of walletMessage from @defuse-protocol/internal-utils is
invalid because the current version 0.1.2 does not export walletMessage. Fix
this by either updating the @defuse-protocol/internal-utils dependency to a
version that includes walletMessage or by replacing walletMessage in the import
and usage with the correct exported type or name from the existing version of
the package.

Comment on lines +1 to +4
import {
messageFactory,
type walletMessage,
} from "@defuse-protocol/internal-utils"
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify external package exports for messageFactory and walletMessage.

The import changes look correct, but static analysis failures in other files indicate that messageFactory and walletMessage may not be properly exported from @defuse-protocol/internal-utils.

Verify that the external package properly exports these members:


🏁 Script executed:

#!/bin/bash
# Description: Check if the external package exports the required members
# Expected: Package should export messageFactory and walletMessage namespaces

# Check if the package is installed and what it exports
npm list @defuse-protocol/internal-utils || echo "Package not found"

# Check the package.json and main entry point
if [ -d "node_modules/@defuse-protocol/internal-utils" ]; then
  echo "=== Package.json ==="
  cat node_modules/@defuse-protocol/internal-utils/package.json | jq '.main, .types, .exports'
  
  echo "=== Main entry exports ==="
  if [ -f "node_modules/@defuse-protocol/internal-utils/dist/index.d.ts" ]; then
    head -50 node_modules/@defuse-protocol/internal-utils/dist/index.d.ts
  elif [ -f "node_modules/@defuse-protocol/internal-utils/index.d.ts" ]; then
    head -50 node_modules/@defuse-protocol/internal-utils/index.d.ts
  fi
fi

Length of output: 220


Missing dependency and export verification for @defuse-protocol/internal-utils

It appears @defuse-protocol/internal-utils is not installed in this project, so the following imports will fail at build time:

import {
  messageFactory,
  type walletMessage,
} from "@defuse-protocol/internal-utils"

Please address this as follows:

  • Add and install the package:
    npm install @defuse-protocol/internal-utils
    
  • After installation, confirm that messageFactory and the walletMessage namespace are indeed exported. For example, inspect:
    node_modules/@defuse-protocol/internal-utils/dist/index.d.ts
    
    and verify it contains:
    export const messageFactory: { randomDefuseNonce(): /* … */; /* … */ };
    export namespace walletMessage {
      type WalletMessage = /* … */;
      type WalletSignatureResult = /* … */;
    }
  • If those exports differ or are missing, update the package or adjust your imports accordingly.

Affected file:

  • src/features/gift/actors/giftMakerSignActor.ts — imports of messageFactory & walletMessage
🤖 Prompt for AI Agents
In src/features/gift/actors/giftMakerSignActor.ts lines 1 to 4, the imports from
@defuse-protocol/internal-utils will fail because the package is not installed.
Fix this by running npm install @defuse-protocol/internal-utils to add the
dependency. Then verify that messageFactory and walletMessage are correctly
exported by inspecting
node_modules/@defuse-protocol/internal-utils/dist/index.d.ts. If the exports
differ or are missing, update the package or adjust the imports accordingly.

@jobotics jobotics marked this pull request as draft July 29, 2025 10:06
@jobotics
Copy link
Collaborator Author

Not applicable any more.

@jobotics jobotics closed this Jul 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants