fix(swift-sdk): use platform-wallet-ffi headers instead of hardcoded function signatures#3500
Conversation
📝 WalkthroughWalkthroughThis PR refactors the Platform Wallet FFI architecture by migrating from manual C header definitions to automated generation via cbindgen, reorganizing FFI dependencies, updating network type handling from Changes
Sequence Diagram(s)The changes do not meet the criteria for sequence diagram generation. While they introduce significant refactoring and architectural reorganization, the modifications are primarily build infrastructure updates, dependency restructuring, type system changes, and API signature updates rather than new feature flows or substantial control flow alterations. The contact request refactoring (from parameters to object model) is primarily a structural API change without new multi-component interactions. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
2f85d31 to
5e1b90d
Compare
|
⏳ Review in progress (commit 5e1b90d) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v3.1-dev #3500 +/- ##
==========================================
Coverage 84.83% 84.84%
==========================================
Files 2476 2476
Lines 267733 267915 +182
==========================================
+ Hits 227123 227302 +179
- Misses 40610 40613 +3
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift (1)
94-111:⚠️ Potential issue | 🟠 MajorAdd a public initializer for
PlatformBlockTime.
ManagedIdentity.setLastUpdatedBalanceBlockTime(_:)is public, but this type currently has only internal initializers. SDK consumers can receive aPlatformBlockTimefrom getters, but they cannot construct one to call the setter.Suggested fix
public struct PlatformBlockTime { public let height: UInt64 public let coreHeight: UInt32 public let timestamp: UInt64 + public init(height: UInt64, coreHeight: UInt32, timestamp: UInt64) { + self.height = height + self.coreHeight = coreHeight + self.timestamp = timestamp + } + init(ffi: BlockTime) { self.height = ffi.height self.coreHeight = ffi.core_height self.timestamp = ffi.timestamp }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift` around lines 94 - 111, The PlatformBlockTime struct lacks a public initializer, preventing SDK consumers from constructing instances to call public methods like ManagedIdentity.setLastUpdatedBalanceBlockTime(_:). Add a public initializer such as public init(height: UInt64, coreHeight: UInt32, timestamp: UInt64) to PlatformBlockTime so callers can create instances; also consider making the existing init(ffi: BlockTime) public if external code needs to construct from FFI values (refer to PlatformBlockTime, init(ffi:), and ffiValue).
🧹 Nitpick comments (1)
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift (1)
80-84: Thenetworkargument is only a cache key now.These FFI calls no longer take a network, but this wrapper still exposes
for network:and stores managers in[PlatformNetwork: IdentityManager]. That lets one wallet cache separate Swift managers under arbitrary networks even though the underlying wallet is already bound to a single network.Consider collapsing this to one cached manager, or storing the wallet's creation network and rejecting mismatched requests.
Also applies to: 99-103
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift` around lines 80 - 84, The wrapper currently exposes and caches IdentityManager per PlatformNetwork even though the underlying FFI call platform_wallet_info_get_identity_manager is network-agnostic; update PlatformWallet to either (A) collapse to a single cached IdentityManager (e.g., replace the [PlatformNetwork: IdentityManager] store with a single optional IdentityManager property and remove the network parameter from the getter), or (B) record the wallet's creation network when the wallet is constructed and in the getter validate that the requested network matches that stored network, returning an error on mismatch; make changes around the methods/fields that reference PlatformNetwork and IdentityManager and the call site that invokes platform_wallet_info_get_identity_manager to ensure only one manager is cached or mismatches are rejected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/DashPayService.swift`:
- Around line 137-148: The code currently hardcodes senderKeyIndex and
recipientKeyIndex to 0 when constructing ContactRequest via
ContactRequest.create after calling identity.getId(); instead, derive the
correct key indices: obtain the sender key index from the identity (e.g., via
the identity's key management API or a method on the identity object) and look
up the recipient's key index from the recipient/contact store or contact
metadata before building the request, then pass those derived indices into
ContactRequest.create (replace the literal 0 values for senderKeyIndex and
recipientKeyIndex with the derived values).
In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`:
- Line 18: The wallet factory functions (PlatformWallet.fromSeed and
PlatformWallet.fromMnemonic) must not default the network to .testnet because
the network is fixed at creation; remove the default parameter value so the
signatures become fromSeed(_ seed: Data, network: PlatformNetwork) throws ->
PlatformWallet and fromMnemonic(_ mnemonic: String, network: PlatformNetwork)
throws -> PlatformWallet, update any calls (e.g.,
DashPayService.initializeWallet which calls PlatformWallet.fromMnemonic) to pass
the intended PlatformNetwork explicitly, and run the build to fix any call sites
that relied on the implicit default.
---
Outside diff comments:
In
`@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swift`:
- Around line 94-111: The PlatformBlockTime struct lacks a public initializer,
preventing SDK consumers from constructing instances to call public methods like
ManagedIdentity.setLastUpdatedBalanceBlockTime(_:). Add a public initializer
such as public init(height: UInt64, coreHeight: UInt32, timestamp: UInt64) to
PlatformBlockTime so callers can create instances; also consider making the
existing init(ffi: BlockTime) public if external code needs to construct from
FFI values (refer to PlatformBlockTime, init(ffi:), and ffiValue).
---
Nitpick comments:
In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`:
- Around line 80-84: The wrapper currently exposes and caches IdentityManager
per PlatformNetwork even though the underlying FFI call
platform_wallet_info_get_identity_manager is network-agnostic; update
PlatformWallet to either (A) collapse to a single cached IdentityManager (e.g.,
replace the [PlatformNetwork: IdentityManager] store with a single optional
IdentityManager property and remove the network parameter from the getter), or
(B) record the wallet's creation network when the wallet is constructed and in
the getter validate that the requested network matches that stored network,
returning an error on mismatch; make changes around the methods/fields that
reference PlatformNetwork and IdentityManager and the call site that invokes
platform_wallet_info_get_identity_manager to ensure only one manager is cached
or mismatches are rejected.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 571ae591-ee90-4155-a432-76df2a6ce15b
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (21)
packages/rs-platform-wallet-ffi/Cargo.tomlpackages/rs-platform-wallet-ffi/build.rspackages/rs-platform-wallet-ffi/cbindgen.tomlpackages/rs-platform-wallet-ffi/platform_wallet_ffi.hpackages/rs-platform-wallet-ffi/src/platform_wallet_info.rspackages/rs-platform-wallet-ffi/src/types.rspackages/rs-platform-wallet-ffi/tests/integration_tests.rspackages/rs-sdk-ffi/Cargo.tomlpackages/rs-sdk-ffi/src/lib.rspackages/rs-sdk-ffi/src/platform_wallet_types.rspackages/rs-unified-sdk-ffi/Cargo.tomlpackages/rs-unified-sdk-ffi/src/lib.rspackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ContactRequest.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/DashPayService.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/EstablishedContact.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/IdentityManager.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedIdentity.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swiftpackages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletTypes.swiftpackages/swift-sdk/build_ios.sh
💤 Files with no reviewable changes (5)
- packages/rs-platform-wallet-ffi/src/types.rs
- packages/rs-sdk-ffi/src/platform_wallet_types.rs
- packages/rs-sdk-ffi/src/lib.rs
- packages/rs-platform-wallet-ffi/platform_wallet_ffi.h
- packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletFFI.swift
| // Build the contact request object, then hand it off to the FFI layer. | ||
| // Real callers should derive key indices from the identity/recipient. | ||
| let senderId = try identity.getId() | ||
| let request = try ContactRequest.create( | ||
| senderId: senderId, | ||
| recipientId: recipientId, | ||
| senderKeyIndex: 0, // Should be derived from identity keys | ||
| recipientKeyIndex: 0, // Should be looked up from recipient | ||
| senderKeyIndex: 0, // Should be derived from identity keys | ||
| recipientKeyIndex: 0, // Should be looked up from recipient | ||
| accountReference: 0, | ||
| encryptedPublicKey: encryptedPublicKey | ||
| encryptedPublicKey: encryptedPublicKey, | ||
| coreHeightCreatedAt: coreHeightCreatedAt, | ||
| createdAt: createdAt |
There was a problem hiding this comment.
Derive the real key indices before building the request.
senderKeyIndex and recipientKeyIndex are hardcoded to 0 here. Now that this service constructs the ContactRequest itself, any identity/contact pair that uses non-zero keys will get incorrect request metadata and the downstream send/accept flow can break.
Possible fix
public func sendContactRequest(
from identity: ManagedIdentity,
to recipientId: Identifier,
encryptedPublicKey: Data,
+ senderKeyIndex: UInt32,
+ recipientKeyIndex: UInt32,
coreHeightCreatedAt: UInt32 = 0,
createdAt: UInt64 = UInt64(Date().timeIntervalSince1970 * 1000)
) throws {
// Build the contact request object, then hand it off to the FFI layer.
- // Real callers should derive key indices from the identity/recipient.
let senderId = try identity.getId()
let request = try ContactRequest.create(
senderId: senderId,
recipientId: recipientId,
- senderKeyIndex: 0, // Should be derived from identity keys
- recipientKeyIndex: 0, // Should be looked up from recipient
+ senderKeyIndex: senderKeyIndex,
+ recipientKeyIndex: recipientKeyIndex,
accountReference: 0,
encryptedPublicKey: encryptedPublicKey,
coreHeightCreatedAt: coreHeightCreatedAt,
createdAt: createdAt
)If you want, I can sketch the lookup plumbing for those indices or help turn it into a follow-up issue.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/DashPayService.swift`
around lines 137 - 148, The code currently hardcodes senderKeyIndex and
recipientKeyIndex to 0 when constructing ContactRequest via
ContactRequest.create after calling identity.getId(); instead, derive the
correct key indices: obtain the sender key index from the identity (e.g., via
the identity's key management API or a method on the identity object) and look
up the recipient's key index from the recipient/contact store or contact
metadata before building the request, then pass those derived indices into
ContactRequest.create (replace the literal 0 values for senderKeyIndex and
recipientKeyIndex with the derived values).
|
|
||
| /// Create a new Platform Wallet from a 64-byte seed | ||
| public static func fromSeed(_ seed: Data) throws -> PlatformWallet { | ||
| public static func fromSeed(_ seed: Data, network: PlatformNetwork = .testnet) throws -> PlatformWallet { |
There was a problem hiding this comment.
Don't default the wallet network during creation.
platform_wallet_info_get_identity_manager can no longer correct the network later, so the wallet's network is now fixed at fromSeed / fromMnemonic time. Keeping .testnet as a default lets stale callers keep compiling and silently create the wrong wallet; for example, DashPayService.initializeWallet still calls PlatformWallet.fromMnemonic(mnemonic) on Line 55 of packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/DashPayService.swift.
Suggested fix
-public static func fromSeed(_ seed: Data, network: PlatformNetwork = .testnet) throws -> PlatformWallet {
+public static func fromSeed(_ seed: Data, network: PlatformNetwork) throws -> PlatformWallet { public static func fromMnemonic(
_ mnemonic: String,
passphrase: String? = nil,
- network: PlatformNetwork = .testnet
+ network: PlatformNetwork
) throws -> PlatformWallet {Also applies to: 44-48
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWallet.swift`
at line 18, The wallet factory functions (PlatformWallet.fromSeed and
PlatformWallet.fromMnemonic) must not default the network to .testnet because
the network is fixed at creation; remove the default parameter value so the
signatures become fromSeed(_ seed: Data, network: PlatformNetwork) throws ->
PlatformWallet and fromMnemonic(_ mnemonic: String, network: PlatformNetwork)
throws -> PlatformWallet, update any calls (e.g.,
DashPayService.initializeWallet which calls PlatformWallet.fromMnemonic) to pass
the intended PlatformNetwork explicitly, and run the build to fix any call sites
that relied on the implicit default.
|
✅ DashSDKFFI.xcframework built for this PR.
SwiftPM (host the zip at a stable URL, then use): .binaryTarget(
name: "DashSDKFFI",
url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
checksum: "d6bb6916e6229453ece62fc38d63d3f58bcabcf90b3ce135856b4bb0d7697100"
)Xcode manual integration:
|
Okay, rs-platform-wallet-ffi was exporting symbols and creating a header, but this headers was not being used, we were using hardcoded (and outdated) symbols written directly in the swift code, to be more specific, in the 'PlatformWalletFFI.swift' and 'PlatformWalletTypes.swift', and rs-sdk-ffi was re-exporting the platform-wallet-ffi symbols.
So, this is what I did:
Checklist:
For repository code-owners and collaborators only
Summary by CodeRabbit
Breaking Changes
PlatformWallet.fromSeed()andPlatformWallet.fromMnemonic()methodsBlockTimetype renamed toPlatformBlockTimewith updated field typesContactRequestobjects instead of individual parametersPlatformBlockTimeUpdates