refactor(core): compute crypto primitives with SharedCoreKit - #718
Merged
Conversation
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>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Moves Base58, SHA-256/512, HMAC, PBKDF2, and Ed25519 in
FlipcashCoreonto the shared Kotlin implementations published inSharedCoreKit0.4.0, and deletesCodeCurves— the vendored orlp ed25519 C this app no longer needs.What moved
Vendor/Base58.swift): the ~120-line vendored NeoSwift/Solana.Swift implementation is now a thin wrapper overSharedCoreKit.Base58.Hashes/):SHA256,SHA512,HMAC,PBKDFnow buffer intoSharedHash's one-shot Kotlin hashes instead of calling CommonCrypto directly.HashType.AlgorithmandHMAC.Algorithmare narrowed to the variants actually used (.sha256/.sha512) — greps turned up zero callers of.sha1/.sha224/.sha384, and PBKDF2's only.sha256caller was a test asserting digest length, which is deleted with it.Solana/Keys/KeyPair.swift): key generation, signing, verification, and on-curve checks callSharedEd25519instead of linkingCodeCurves.Key+Generate.swiftswaps the C library'sed25519_create_seedforSecRandomCopyBytesdirectly.CrossPlatformVectors: repointed fromCodeCurvestoSharedCoreKiton the same fixtures. The XCFramework ships no macOS slice, so this suite now runs on an iOS Simulator destination in CI rather than viaswift teston the runner —vectors.ymlupdated to pick a simulator and run bothCrossPlatformVectorsandFlipcashCoreVectorsagainst it.CodeCurvesdeleted 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):FlipcashCoreCrossPlatformVectorsFlipcashCoreVectorsThe
FlipcashCorecount is 850, not 851: the one test removed is the PBKDF2.sha256digest-length assertion mentioned above.xcodebuild -scheme Flipcash buildcurrently fails, but on something this branch doesn't touch:FlipcashUI/Sources/FlipcashUI/Views/Bill/CodeView.swiftcallsKikCode.figure(...), a geometry API that doesn't exist inSharedCoreKitat either0.3.1or0.4.0— pre-existing onmainbefore this branch, unrelated to the crypto-primitive swap.Known issue carried over, not fixed here
SharedCore.xcframeworkdeclares.iOS(.v15)but its object files are built for a newer simulator floor than that — linking against it printsld: 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 theflipcash-shared-core-spmside.