-
Notifications
You must be signed in to change notification settings - Fork 56
feat(swift-sdk): add Swift wrappers for the encrypted-txMetadata FFI exports #4317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bfoss765
wants to merge
2
commits into
v4.2-dev
Choose a base branch
from
followup/v4.1/swift-txmetadata-wrappers
base: v4.2-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+307
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ages/swift-sdk/SwiftTests/SwiftDashSDKTests/EncryptedDocumentVersionValidationTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import XCTest | ||
| @testable import SwiftDashSDK | ||
|
|
||
| /// Version-byte validation for | ||
| /// `ManagedPlatformWallet.createEncryptedDocument` (dashpay/platform#4091). | ||
| /// Only `0` (CBOR) and `1` (protobuf) are wire-meaningful — `seal_tx_metadata` | ||
| /// writes the byte verbatim and the legacy dashj `decryptTxMetadata` switches | ||
| /// on exactly those two values, so an out-of-range byte would silently seal a | ||
| /// document the legacy stack can't decode. | ||
| /// | ||
| /// The `guard` runs before any FFI call (no `platform_wallet_*` symbol is | ||
| /// dereferenced and the wallet `handle` is never used), so the REJECTION paths | ||
| /// are exercised with a dummy handle and no live wallet — the Swift mirror of | ||
| /// the Kotlin `DocumentTransactionsVersionValidationTest` | ||
| /// (`walletHandle = 0L`). The accepted values `0` / `1` would proceed into | ||
| /// native and can't be unit-tested here. | ||
| final class EncryptedDocumentVersionValidationTests: XCTestCase { | ||
|
|
||
| /// A dummy, never-dispatched wallet handle (matches Kotlin's `0L`). The | ||
| /// version guard throws before the handle is read, so no FFI dispatch | ||
| /// occurs on the rejection paths under test. | ||
| private func makeWallet() -> ManagedPlatformWallet { | ||
| ManagedPlatformWallet(handle: 0, walletId: Data(count: 32)) | ||
| } | ||
|
|
||
| private let id32 = Data(count: 32) | ||
| private let payload = Data([0, 1, 2, 3]) | ||
|
|
||
| /// A signer is a required argument, but the version guard throws before it | ||
| /// is ever dereferenced — an in-memory-backed instance is enough to | ||
| /// satisfy the type. Built per-test. | ||
| private func makeSigner() throws -> KeychainSigner { | ||
| let container = try DashModelContainer.createInMemory() | ||
| return KeychainSigner(modelContainer: container, network: .testnet) | ||
| } | ||
|
|
||
| /// Bytes `2...255` (every value the legacy `0..=255` range once accepted | ||
| /// beyond the two wire-meaningful ones) are rejected with a message that | ||
| /// names them. | ||
| func testRejectsVersionBytesTheLegacyStackCannotDecode() async throws { | ||
| let wallet = makeWallet() | ||
| let signer = try makeSigner() | ||
| for version: UInt8 in [2, 3, 127, 255] { | ||
| do { | ||
| _ = try await wallet.createEncryptedDocument( | ||
| ownerIdentityId: id32, | ||
| contractId: id32, | ||
| documentType: "txMetadata", | ||
| version: version, | ||
| payload: payload, | ||
| signer: signer | ||
| ) | ||
| XCTFail("version=\(version) must be rejected") | ||
| } catch let error as PlatformWalletError { | ||
| guard case let .invalidParameter(message) = error else { | ||
| XCTFail("expected .invalidParameter for version=\(version), got \(error)") | ||
| continue | ||
| } | ||
| XCTAssertTrue( | ||
| message.contains("0 (CBOR) or 1 (protobuf)"), | ||
| "message should name the wire-meaningful versions, got: \(message)" | ||
| ) | ||
| } catch { | ||
| XCTFail("expected PlatformWalletError for version=\(version), got \(error)") | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Blocking: Encrypted-document wrappers reference exports absent from this base
This call and the
platform_wallet_fetch_encrypted_documentscall at line 3630 reference functions that do not exist in the exact-head Rust FFI. Commit746b34d93bremoved both exports frompackages/rs-platform-wallet-ffi/src/document.rs, and no later commit in this branch restores them. Regenerating the header withcargo check -p platform-wallet-ffiat0fa7539bf21f8d373e60fc70f28b96ed964bb3a2producesplatform-wallet-ffi.hwith neither declaration, whilebuild_ios.shincludes that generated header in theDashSDKFFImodule. Consequently, a source-built framework cannot type-check these Swift calls; a stale header would instead defer the failure to linking or loading. Restore the encrypted-document Rust implementation and both C exports on this branch, or remove these Swift wrappers until the native API is available.source: ['codex']