Skip to content

refactor(core): compute crypto primitives with SharedCoreKit - #718

Merged
bmc08gt merged 4 commits into
mainfrom
refactor/core-adopt-sharedcorekit
Sep 3, 2026
Merged

refactor(core): compute crypto primitives with SharedCoreKit#718
bmc08gt merged 4 commits into
mainfrom
refactor/core-adopt-sharedcorekit

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Moves Base58, SHA-256/512, HMAC, PBKDF2, and Ed25519 in FlipcashCore onto the shared Kotlin implementations published in SharedCoreKit 0.4.0, and deletes CodeCurves — the vendored orlp ed25519 C this app no longer needs.

What moved

  • Base58 (Vendor/Base58.swift): the ~120-line vendored NeoSwift/Solana.Swift implementation is now a thin wrapper over SharedCoreKit.Base58.
  • SHA-256/512, HMAC, PBKDF2 (Hashes/): SHA256, SHA512, HMAC, PBKDF now buffer into SharedHash's one-shot Kotlin hashes instead of calling CommonCrypto directly. HashType.Algorithm and HMAC.Algorithm are narrowed to the variants actually used (.sha256/.sha512) — greps turned up zero callers of .sha1/.sha224/.sha384, and PBKDF2's only .sha256 caller was a test asserting digest length, which is deleted with it.
  • Ed25519 (Solana/Keys/KeyPair.swift): key generation, signing, verification, and on-curve checks call SharedEd25519 instead of linking CodeCurves. Key+Generate.swift swaps the C library's ed25519_create_seed for SecRandomCopyBytes directly.
  • CrossPlatformVectors: repointed from CodeCurves to SharedCoreKit on the same fixtures. The XCFramework ships no macOS slice, so this suite now runs on an iOS Simulator destination in CI rather than via swift test on the runner — vectors.yml updated to pick a simulator and run both CrossPlatformVectors and FlipcashCoreVectors against it.
  • CodeCurves deleted outright — nothing in the app links it once Ed25519 has a caller elsewhere.

Verification

Ran against the real published 0.4.0 (not the local-override path used while iterating):

Suite Result
FlipcashCore 850/850
CrossPlatformVectors 1/1
FlipcashCoreVectors 6/6

The FlipcashCore count is 850, not 851: the one test removed is the PBKDF2 .sha256 digest-length assertion mentioned above.

xcodebuild -scheme Flipcash build currently fails, but on something this branch doesn't touch: FlipcashUI/Sources/FlipcashUI/Views/Bill/CodeView.swift calls KikCode.figure(...), a geometry API that doesn't exist in SharedCoreKit at either 0.3.1 or 0.4.0 — pre-existing on main before this branch, unrelated to the crypto-primitive swap.

Known issue carried over, not fixed here

SharedCore.xcframework declares .iOS(.v15) but its object files are built for a newer simulator floor than that — linking against it prints ld: warning: object file (...) was built for newer 'iOS-simulator' version (18.5) than being linked (17.0/18.0). Not a build break, but worth tracking on the flipcash-shared-core-spm side.

bmc08gt and others added 4 commits September 1, 2026 17:36
Drops the vendored NeoSwift/Solana.Swift implementation for SharedCoreKit.Base58.
fromBytes/toBytes keep their signatures, so the nine call sites are untouched, and
toBytes keeps trimming whitespace and returning [] outside the alphabet -- the
Kotlin decode does neither.

851 FlipcashCore tests and the 6 FlipcashCoreVectors fixtures pass unchanged.
Drops CommonCrypto from the hash path. The Swift types keep the HashType shape and
buffer their input, so the streaming call sites in ProgramDerivedAccount and
ConversationID+TipDm are untouched; the shared side hashes once at digestBytes().

The HMAC and PBKDF Algorithm enums narrow to what the shared facade offers -- HMAC
to sha256/sha512, PBKDF to sha512. Nothing outside the enum declarations used
sha1/sha224/sha384, and the only caller of PBKDF .sha256 was a test asserting the
digest length of a path with no production caller, so it goes with the case.

850 FlipcashCore tests pass, and the 6 FlipcashCoreVectors fixtures still match --
Slip10DerivationVectorTests runs BIP39 and SLIP-0010 through the new PBKDF2-SHA512
and HMAC-SHA512.
Both platforms compiled the same orlp C already; now they compile it once, in
:libs:encryption:ed25519, reached through cinterop. KeyPair keeps every public
signature, so the derivation and signing call sites are untouched.

Seed generation moves to SecRandomCopyBytes: the shared module excludes seed.c on
purpose, since it takes a caller-supplied seed rather than reaching for platform
entropy. generate() still returns nil on failure rather than trapping, matching
what the C entry point reported through its status code.

CrossPlatformVectors moves onto SharedCoreKit with it, which means it moves off the
macOS host -- the XCFramework ships iOS slices only. Running it on a simulator is
what the gate is for now: it exercises the framework as FlipcashCore consumes it,
which the Kotlin-side Ed25519VectorTest on the same fixtures does not.

850 FlipcashCore tests, 6 FlipcashCoreVectors fixtures, and the ed25519 vector all
pass.
FlipcashCore, CrossPlatformVectors, and Code.xcodeproj were resolving the
package from a local path to the code-android-app checkout for the crypto
facades this branch adds. Point all four manifests (FlipcashCore, FlipcashUI,
CrossPlatformVectors, Code.xcodeproj) back at the published
flipcash-shared-core-spm 0.4.0, which carries them.

Verified against the real published framework, not the local override:
FlipcashCore (850/850), CrossPlatformVectors (1/1), and FlipcashCoreVectors
(6/6) all pass on an iOS Simulator.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@bmc08gt bmc08gt self-assigned this Sep 3, 2026
@bmc08gt
bmc08gt merged commit c56efd3 into main Sep 3, 2026
1 check passed
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.

1 participant