From 61c3208941372bddab3c47be15bf219e1f4b46f1 Mon Sep 17 00:00:00 2001 From: Roman <51091564+jeanpierreroma@users.noreply.github.com> Date: Sun, 20 Sep 2026 15:59:11 +0300 Subject: [PATCH] fix(dashpay): refuse a contract-group-bound key registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ManagedPlatformWallet.ContractBounds` grew a third case in the Swift SDK (dashpay/platform#4800), and the DPP-layer `ContractBounds` that `PlatformDashConnectDataSource.parse()` maps it into still has two, so the file stopped compiling against current `v4.2-dev`: PlatformDashConnectDataSource.swift:246:33: error: switch must be exhaustive note: add missing case: '.contractGroup(id: let id)' There is no correct arm to add. Dropping the bound would be wrong twice over: the value decides which approved app a scanned key registration belongs to, so a key whose bound is erased names no single app; and the same value is rebuilt into the `IdentityPubkey` handed back to `updateIdentity(...)`, so a silently weakened bound would mean signing a transition the dApp never asked for. A key bound to a contract group is never one of the login keys this flow derives, so refuse the transition instead — the same conclusion the SDK's own persistence seam reaches, and the reason dashpay/platform#4853 asks for the DPP-layer enum to model the bound end to end. The identity-key fixtures gain the protocol-14 limit fields (dashpay/platform#4798) so the test target builds against the same SDK. Co-Authored-By: Claude Opus 5 (1M context) --- .../PlatformDashConnectDataSource.swift | 16 ++++++++++++++-- .../PlatformDashConnectDataSourceTests.swift | 6 +++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift b/DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift index fd3b07fb95..54b48d4883 100644 --- a/DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift +++ b/DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift @@ -235,14 +235,14 @@ struct PlatformWalletDashConnectStateTransitionParser: DashConnectStateTransitio return .keyRegistration( DashConnectKeyRegistrationTransition( identityId: parsed.identityId, - addPublicKeys: parsed.addPublicKeys.map { key in + addPublicKeys: try parsed.addPublicKeys.map { key in DashConnectKeyRegistrationKey( keyId: key.keyId, keyType: key.keyType, purpose: key.purpose, securityLevel: key.securityLevel, publicKeyData: key.pubkeyBytes, - contractBounds: key.contractBounds.map { + contractBounds: try key.contractBounds.map { switch $0 { case .singleContract(let id): return .singleContract(id: id) @@ -251,6 +251,18 @@ struct PlatformWalletDashConnectStateTransitionParser: DashConnectStateTransitio id: id, documentTypeName: documentTypeName ) + case .contractGroup: + // The wallet layer reports a contract-group bound since the + // SDK's #4800, and the DPP-layer `ContractBounds` this maps + // into has no case for it (dashpay/platform#4853). Dropping + // the bound is not an option here: the value decides which + // approved app a key registration belongs to, and it is also + // rebuilt into the `IdentityPubkey` handed back to + // `updateIdentity(...)`, so a silently weakened bound would + // mean signing a transition the dApp did not ask for. A key + // bound to a contract group is never one of the login keys + // this flow derives, so refuse the transition instead. + throw DashConnectPlatformError.keyRegistrationUnexpectedMutation } } ) diff --git a/DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift b/DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift index b866fb9171..fa2a35a1ce 100644 --- a/DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift +++ b/DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift @@ -1102,7 +1102,11 @@ final class PlatformDashConnectDataSourceTests: XCTestCase { keyType: keyType, readOnly: false, disabledAt: disabledAt.map { Int64(bitPattern: $0) }, - data: data + data: data, + // Protocol 14 key limits (platform#4798). These fixtures describe + // the keys the QR login flow derives, which carry neither. + totalBudget: nil, + expiresAt: nil ) }