Skip to content

feat: add the DIP-13 rotation level to application encryption keys - #42

Merged
HashEngineering merged 2 commits into
codex/upgrade-platform-4.2from
feat/app-encryption-rotation
Oct 29, 2026
Merged

HashEngineering merged 2 commits into
codex/upgrade-platform-4.2from
feat/app-encryption-rotation

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Problem

The DIP-13 application encryption path ends at purpose', so the key for a given identity, app contract and purpose is fixed forever. Once the first mainnet key is registered at that path it can never be replaced, even if it is compromised or retired. DIP-13 (dashpay/dips#191, used by the App Connect DIP, dashpay/dips#181) now ends the path with a hardened 31-bit rotation' level, with 0' first:

m/9'/coin'/5'/7'/0'/identityId'/contractId'/purpose'/rotation'

kotlin-platform still derives the 8-level path with no rotation, and that is what dash-wallet (Android) uses through this library.

Fix

  • platform-mobile/src/key_wallet.rs: application_encryption_private_key_from_seed takes rotation: u32 and appends ChildNumber::Hardened { index: rotation }. A rotation of 2^31 or more returns an error (same Result<_, String> style as the purpose check).
  • New application_encryption_legacy_private_key_from_seed derives the 8-level path without rotation. It exists only to recognise keys that wallets registered on testnet/devnet before the rotation level existed; its docs say not to use it for new keys.
  • Both share one base-path builder, so the rotation path is by construction the legacy path plus one hardened level (covered by a test).
  • Ferment output for dash-sdk-bindings and dash-sdk-android has the new signature and the legacy function; key_wallet.i gains the SWIG rename and %newobject for applicationEncryptionLegacyPrivateKeyFromSeed.

Stacked on #41

This branch is based on codex/upgrade-platform-4.2 (head 8e1c91b, PR #41, Platform SDK 5.0.1), which is what dash-wallet uses. Merge commit 7a9fe9d brings this branch up to that head without changing the rotation feature files. The base is that branch, not master, so the diff shows only this change. Retarget to master once #41 merges.

Kotlin migration

  • ApplicationKeyDerivation.encryption(seed, identityId, contractId, purpose, rotation, isMainnet): rotation is a required Long (0 until 2^31, checked before the native call). It is required on purpose so callers choose it; new keys use 0. This is source-breaking for existing callers.
  • ApplicationKeyDerivation.legacyEncryptionWithoutRotation(seed, identityId, contractId, purpose, isMainnet) is the explicit pre-rotation path. Use it only to match keys already registered on testnet/devnet.

Tested

Run here:

  • cargo test --lib key_wallet in platform-mobile: 5 tests pass. They pin the DIP vectors (BIP-39 abandon x11 about, empty passphrase, mainnet) for 5 rotation-level keys and 3 legacy keys, check that the rotation path is the legacy path plus a hardened level, that rotation 2^31 - 1 works and 2^31 / u32::MAX fail, and that network, purpose, contract, rotation and legacy/session paths give distinct keys.
  • cargo build in dash-sdk-bindings (with cbindgen 0.29.0 installed, as CI does) regenerated the Ferment bindings and target/include/dash_sdk_bindings.h with both functions. Ferment reorders modules on every run, so the committed fermented.rs files carry only the two changed functions spliced into the existing ordering; the regenerated file and the committed one have the same token multiset.
  • rustfmt --check on key_wallet.rs.

This repo's CI runs only for PRs into main/master/develop, so it doesn't build this stacked PR. The same workflow (build-and-verify-alignment) ran on an earlier feature head (b3ff215) in a fork: https://github.com/PastaPastaPasta/kotlin-platform/actions/runs/40779341353. cbindgen, SWIG generation, CMake, ./gradlew build -x test, the 16 KB alignment check and the AAR check passed there. After merging the final 5.0.1 base, cargo test --locked --offline --manifest-path platform-mobile/Cargo.toml --lib key_wallet passed all five tests, and ./gradlew :dash-sdk-java:cmakeBuild :dpp:test --tests '*AppConnectKeyTest' -PskipSigning passed locally. The dash-sdk-android crate was not regenerated on its own; its fermented.rs got the same two functions as the dash-sdk-bindings one.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 642be841-c689-4108-9508-1dfca813e172

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Comment @coderabbitai help to get the list of available commands.

@PastaPastaPasta
PastaPastaPasta force-pushed the feat/app-encryption-rotation branch from b3ff215 to f010eec Compare October 29, 2026 16:36
The application encryption path ends with a hardened 31-bit rotation level
(dashpay/dips#191, used by the App Connect DIP, dashpay/dips#181):

  m/9'/coin'/5'/7'/0'/identityId'/contractId'/purpose'/rotation'

with rotation 0' first. Without it the path becomes permanent with the first
mainnet key and a compromised or retired key could never be replaced.

platform-mobile: application_encryption_private_key_from_seed takes a
rotation (below 2^31, an error otherwise) and appends it as a hardened level.
The 8-level path without rotation stays available as
application_encryption_legacy_private_key_from_seed, only to recognise keys
that wallets registered on testnet/devnet before the rotation level existed.
Tests pin the DIP vectors for both paths (abandon x11 about, mainnet).

Bindings: Ferment output for dash-sdk-bindings and dash-sdk-android now has
the new signature and the legacy function (regenerated with cargo build of
dash-sdk-bindings; the Android copy carries the same two functions), plus a
SWIG rename for applicationEncryptionLegacyPrivateKeyFromSeed.

Kotlin: ApplicationKeyDerivation.encryption gains a required rotation
parameter, so callers must choose it; new keys use 0. The pre-rotation path
is the explicitly named legacyEncryptionWithoutRotation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PastaPastaPasta
PastaPastaPasta force-pushed the feat/app-encryption-rotation branch from f010eec to ca1082e Compare October 29, 2026 17:00
@HashEngineering
HashEngineering merged commit 68a7dcb into codex/upgrade-platform-4.2 Oct 29, 2026
1 check passed
@HashEngineering
HashEngineering deleted the feat/app-encryption-rotation branch October 29, 2026 18:15
HashEngineering added a commit that referenced this pull request Nov 9, 2026
…on (#41)

* feat: support 4.2-dev

* feat: upgrade to v4.2-dev.8

* feat: expose the network's Platform protocol version

Add get_protocol_version_with_sdk and refresh_protocol_version_with_sdk
exports (fermented bindings regenerated) and DapiClient.getProtocolVersion()
/ refreshProtocolVersion() wrappers. refresh issues a proven getEpochsInfo
query and ratchets dash-sdk up to the version the network runs, so wallets
can pick fees that depend on the activated protocol version (e.g. the
contested username prefunded voting balance, 0.2 -> 0.1 DASH in v14).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ci: skip retired Android SDK tools package

* feat: upgrade to Platform 5.0 and support App Connect

Expose bounded V1 identity keys, DIP-13 application key derivation, remaining budgets, and explicit devnet configuration across Rust, JNI, and Kotlin.

Fix V1 native enum widths and index-only response confirmation using the submitted PV14 nonce-derived document ID. Add regression coverage and build against HashEngineering/platform ferment-5.0.

* feat: expose safe wallet token-purchase requests

Decode one exact unsigned direct-purchase batch, verify token identity and denomination, and rebuild approved values with a fresh nonce and an unbound CRITICAL wallet key. Reject unsupported operations and hidden fee or group changes.

Add native decoder and JNI boundary regression tests. Treat purchase proof results as affected-state snapshots rather than execution confirmation.

* fix: provision wallet signing keys and prove current application key index

* fix: propagate data contract query and conversion failures

* fix: require opt-in critical key migration and use DashJ 24

* fix: guard identity updates and wallet signing with caller authorization

* Expose complete proof-verified contract group scope for Android

Replace the owner-only bridge limitation that forced the wallet to block Yappr's group-bound CRITICAL grants. Verify all member pages at one block, expose admins and each member kind, and retain explicit errors instead of partial scope. Order Android native builds after SWIG generation to prevent stale JNI wrappers. Document the rationale and verified test coverage.

* Pin DashJ 24 to the published timestamped build

Use 24.0.0-20261024.220449-1 instead of the moving SNAPSHOT alias. Record the publicly resolved JAR checksum and snapshot retention caveat; native SDK code is unchanged.

* Preserve purchase operation nonces and expose canonical replay IDs

* Upgrade Platform SDK integration to 5.0.1

* Regenerate Android Ferment bindings for Platform 5.0.1

* Use unsigned local publication in SDK CI

* chore: set dash-sdk-bindings to 5.0.1

* feat: add the DIP-13 rotation level to application encryption keys (#42)

The application encryption path ends with a hardened 31-bit rotation level
(dashpay/dips#191, used by the App Connect DIP, dashpay/dips#181):

  m/9'/coin'/5'/7'/0'/identityId'/contractId'/purpose'/rotation'

with rotation 0' first. Without it the path becomes permanent with the first
mainnet key and a compromised or retired key could never be replaced.

platform-mobile: application_encryption_private_key_from_seed takes a
rotation (below 2^31, an error otherwise) and appends it as a hardened level.
The 8-level path without rotation stays available as
application_encryption_legacy_private_key_from_seed, only to recognise keys
that wallets registered on testnet/devnet before the rotation level existed.
Tests pin the DIP vectors for both paths (abandon x11 about, mainnet).

Bindings: Ferment output for dash-sdk-bindings and dash-sdk-android now has
the new signature and the legacy function (regenerated with cargo build of
dash-sdk-bindings; the Android copy carries the same two functions), plus a
SWIG rename for applicationEncryptionLegacyPrivateKeyFromSeed.

Kotlin: ApplicationKeyDerivation.encryption gains a required rotation
parameter, so callers must choose it; new keys use 0. The pre-rotation path
is the explicitly named legacyEncryptionWithoutRotation.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: HashEngineering <hashengineeringsolutions@gmail.com>

* fix: sync bindings lockfile with 5.0.1

* Forward declare ValueMap independently of generated header order

Declare platform_value_value_map_ValueMap before including Ferment's generated header. This fixes the CI compile failure when Value is emitted before ValueMap without changing ABI or Platform versions.

Add a native header-order regression. Verified the original and reordered generated headers, a clean C++ rebuild, and seven JNI ValueTest tests.

* chore: prepare 5.0.1 Maven Central release

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
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.

2 participants