Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a21fa7f
feat(m4): indexer order list and detail endpoints
erubboli Nov 18, 2026
0509928
feat(m4): order book service with cursor walk and depth rows
erubboli Nov 18, 2026
87da905
feat(m4): price guards for orders and swap entry
erubboli Nov 18, 2026
e488dce
feat(m4): order create, fill and conclude flows over bindings
erubboli Nov 18, 2026
ea82ffb
feat(m4): ml htlc lock, claim and refund flows
erubboli Nov 18, 2026
667ed91
feat(m4): persisted swap sessions with honest transitions
erubboli Nov 18, 2026
1bc09ee
feat(m4): bridge_v2 api provider, mock trade seams, provider wiring
erubboli Nov 18, 2026
740f30e
feat(m4): dex, swap and bridge screens on the provider seams
erubboli Nov 18, 2026
434ad98
docs(m4): swap demo script notes, readme trade status, manual tests
erubboli Nov 18, 2026
ec9650d
chore(m4): activity fixture rides the ethereum bridge scope
erubboli Nov 18, 2026
9671172
fix(m4): reshape the bindings seam to the vendored signatures
erubboli Nov 18, 2026
a83dba0
fix(m4): honest dex ticket, fill preview and deleted fixture seams
erubboli Nov 18, 2026
652bd21
fix(m4): verified broadcasts, guard hardening and nitpick batch
erubboli Nov 18, 2026
568b644
fix(m4): persist swap lock bytes before the broadcast
erubboli Nov 18, 2026
53d5291
fix(m4): pin the witness and order seam signatures
erubboli Nov 18, 2026
797aab6
fix(m4): guard 0-decimal ask legs and pair-filter my orders
erubboli Nov 18, 2026
31c8e8d
fix(m4): honest dex rejection and busy copy
erubboli Nov 18, 2026
2dc2f07
test(m4): refuse lying broadcast answers in the order gate
erubboli Nov 18, 2026
9379c56
fix(m4): scan send modules for console logging
erubboli Nov 18, 2026
1cbe59c
docs(m4): correct the check gate list and timelock claim
erubboli Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 49 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ mobile app, rebuilt in React Native.

---

## ⚠️ Project status · M3 (send and receive)
## ⚠️ Project status · M4 (trade)

**This repository is the send milestone: everything M2 shipped (keys, vault, live chain data) plus the three-step send flow on real builders, BTC signing and broadcast end-to-end on pure-TypeScript scure, the tracked pending to confirmed lifecycle and fresh-address rotation. ML broadcasting still waits on infrastructure, so a mainnet ML send prepares and signs but honestly refuses to broadcast.**
**This repository is the trade milestone: everything M3 shipped (keys, vault, live chain data, the send pipeline) plus the three trade surfaces wired to real infrastructure where it exists - the DEX runs the live on-chain order book with order create/fill/conclude flows, the swap screen drives the ML-side HTLC session machine with persisted sessions, and the bridge reads the bridge_v2 api-server (M2E quotes, fees, status; the treasury deposit address). Signing still rides the device-pending bindings seam and ML broadcasting waits on infrastructure, so every trade action lands in an honest state instead of a fabricated success.**

Real in M4:

- **Order book**: Dex depth rows come from GET /order/pair/{base}_{quote}/book with keyset cursor pagination and an invalid-cursor page-1 restart; stale and error states are explicit, never fixture rows in real mode.
- **Orders**: place (confirm sheet with the exact amounts and a slippage guard against the book mid), fill and conclude run the bindings order encoders with the F11 witness mix (no-signature on the order input, signed payer inputs); the order id derives through the bindings from the create tx inputs, and fill and conclude inputs carry the account nonce and block height per the vendored wallet-bindings v0.1.0 signatures (pinned by src/trade/bindingsParity.test.ts).
- **Atomic swap**: the ML-side HTLC flow (lock, claim, refund, secret extraction) per the docs guide; sessions persist across restarts with the secret hash only (the preimage never persists and never logs; the keep-open warning explains what is at stake), and the lock bytes are stored before the broadcast so a crash cannot strand the refund. The BTC counterparty leg is the scripted demo (see scripts/e2e-testnet.mjs); the timelock guard returns with real offers (plans/mojito-neo/decisions.md).
- **Bridge**: quotes and status ride the bridge_v2 api-server per R5 (per-token fees per direction, the Mintlayer treasury deposit address, m2e deposit confirmations); E2M stays disabled with explanatory copy (no EVM signer, scoped decision open). M2E initiation is honestly gated until the deposit intent encoder and the ML submission route exist. The EVM demo fixtures (Arbitrum, Polygon, BNB) are removed from the bridge chains and pickers in this milestone.

M3 (still accurate): BTC sends are end-to-end real on scure against the configured btc-api base; ML sends prepare and sign over the bindings interface but honestly refuse to broadcast (R3, action item A1); the send lifecycle tracks pending to confirmed with fresh-address rotation.

Real since M1, with vector-backed tests:

Expand Down Expand Up @@ -56,7 +65,7 @@ Do not point this at real funds you cannot afford to lose, and do not treat any
|---|---|
| **Onboarding** | Welcome · Secure (biometric) · PIN set/confirm · Seed reveal · Verify backup · Import phrase · Account discovery · Draw-your-own-entropy |
| **Wallet** | Home (portfolio, balance chart, activity) · DEX (order book + ticket) |
| **Trade** | Atomic Swap (HTLC) · Bridge (Mintlayer ⇄ EVM) · Mojito Card waitlist |
| **Trade** | Atomic Swap (HTLC sessions) · Bridge (Mintlayer ⇄ Ethereum) · Mojito Card waitlist |
| **Flows** | Send (3-step) · Receive (QR) · Settings |
| **App** | Splash · Unlock (biometric + PIN with lockout) |

Expand Down Expand Up @@ -232,7 +241,7 @@ npm run lint # eslint only
npx tsx src/theme.test.ts
```

`npm run check` runs thirty things:
`npm run check` runs thirty-seven things:

1. **`src/theme.test.ts`**: asserts the oklch→sRGB conversion against the known sRGB primaries.
Every colour in the app flows through it, so it's the one piece of non-trivial logic with a
Expand Down Expand Up @@ -266,33 +275,54 @@ npx tsx src/theme.test.ts
the real-mode construction seams.
16. **`src/data/providers/broadcast.test.ts`**: the gap-3 broadcast provider: mock deterministic
ids, 403-to-disabled and transport-to-network mappings, BTC POST tx shape, status reads.
17. **`src/keys/bip39.test.ts`**: published BIP39 seed vectors, checksum/word/length rejection,
17. **`src/data/providers/bridge.test.ts`**: the bridge_v2 api provider: quote and fee parsing
per direction, the treasury deposit address, status mapping and the E2M and initiation
typed gates, all over a scripted transport.
18. **`src/trade/orderBookService.test.ts`**: the live depth aggregation: cursor-paginated
pages, the num/denom price rational, the invalid-cursor page-1 restart and the honest
null last-fill.
19. **`src/trade/orders.test.ts`**: order create/fill/conclude over the bindings double: the
witness mix, order id extraction, nonce and height inputs, the fill guards (frozen,
concluded, overbid, off-band price) and the lying-broadcast refusals.
20. **`src/trade/htlc.test.ts`**: the HTLC flows: lock output parameters, the build/broadcast
split (nothing broadcasts until the prepared lock is confirmed), the claim witness with
the secret, the refund timelock refusal, lying-broadcast refusals and the secret
extraction round-trip.
21. **`src/trade/swapSession.test.ts`**: the swap session machine: transitions (including the
offered -> locked broadcast step), persistence round-trip, corrupt-row dropping,
legacy-column stripping and the no-preimage guarantee.
22. **`src/trade/priceGuards.test.ts`**: the slippage band, minimum fill floor, amount sanity
and the swap timelock rule margin, with typed NaN results.
23. **`src/trade/bindingsParity.test.ts`**: the vendored-signature parity pin: every seam
function (including the privateKey and secret carriers) line-pinned against the vendored
Swift plus the checksum that fails on any vendor upgrade.
24. **`src/keys/bip39.test.ts`**: published BIP39 seed vectors, checksum/word/length rejection,
NFKD normalization, wordlist integrity, supplied-entropy generation.
18. **`src/keys/mlAccounts.test.ts`**: the bindings parity vectors (both networks) for account
25. **`src/keys/mlAccounts.test.ts`**: the bindings parity vectors (both networks) for account
blobs, receiving blobs and addresses, plus the custom-path scan.
19. **`src/keys/BtcKeyring.test.ts`**: BIP84 zpub and address vectors, branch separation, custom
26. **`src/keys/BtcKeyring.test.ts`**: BIP84 zpub and address vectors, branch separation, custom
account paths.
20. **`src/send/validation.test.ts`**: send address validation (mtc1/tmt1/bc1/tb1, wrong-network
27. **`src/send/validation.test.ts`**: send address validation (mtc1/tmt1/bc1/tb1, wrong-network
detection, non-standard HRP rejection) and exact amount parsing against published vectors.
21. **`src/send/mlTxBuilder.test.ts`**: the ML planner and assembler: selection determinism, the
28. **`src/send/mlTxBuilder.test.ts`**: the ML planner and assembler: selection determinism, the
implicit-fee invariant, token-remainder sizing on the real output list, signer loopback.
22. **`src/send/btcTxBuilder.test.ts`**: the BTC builder: plan-fee equals signed-fee on the BIP84
29. **`src/send/btcTxBuilder.test.ts`**: the BTC builder: plan-fee equals signed-fee on the BIP84
vectors, multi-origin signing, confirmed-input policy, typed dust and insufficient funds.
23. **`src/send/TxTracker.test.ts`**: the pending-to-confirmed lifecycle with injected timers:
30. **`src/send/TxTracker.test.ts`**: the pending-to-confirmed lifecycle with injected timers:
poll cadence, attempt caps, terminal stop, flaky-read tolerance.
24. **`src/data/real/realSend.test.ts`**: the real send service over an in-memory manager:
31. **`src/data/real/realSend.test.ts`**: the real send service over an in-memory manager:
funding across every managed address with fresh branch 1 change, typed busy refusal,
broadcast-answer verification, fee pinning, quote purity, post-broadcast warning, the
origin walk over long change histories and the failed-send change release.
25. **`src/data/mock/mockSend.test.ts`**: the R3 demo send path: fixture fee tiers, the same
32. **`src/data/mock/mockSend.test.ts`**: the R3 demo send path: fixture fee tiers, the same
address and amount validation rejections and deterministic demo-labelled ids.
26. **`src/keys/session.test.ts`**: KeySession closure isolation, zeroize of the seed buffer,
33. **`src/keys/session.test.ts`**: KeySession closure isolation, zeroize of the seed buffer,
release semantics, xpub parity.
27. **`scripts/no-console.ts`**: no `console.*` in the native facade or the secret-handling
modules (keys, storage, data, onboarding).
28. **`scripts/no-em-dash.ts`**: no em or en dashes anywhere in code, specs or docs.
29. **`tsc --noEmit`**: strict TypeScript.
30. **`eslint .`**: `eslint-config-expo`, including the `react-hooks` rules.
34. **`scripts/no-console.ts`**: no `console.*` in the native facade or the secret-handling
modules (keys, send, storage, data, onboarding, trade, screens).
35. **`scripts/no-em-dash.ts`**: no em or en dashes anywhere in code, specs or docs.
36. **`tsc --noEmit`**: strict TypeScript.
37. **`eslint .`**: `eslint-config-expo`, including the `react-hooks` rules.

**There is no UI/component test suite yet.** Adding one (React Native Testing Library +
`jest-expo`) is a welcome contribution: start with the onboarding flow, which holds the most
Expand Down
19 changes: 11 additions & 8 deletions modules/mojito-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ export const MojitoCore: MojitoCore = {
encodeOutpointSourceId(id32: Uint8Array, source: 'transaction' | 'block-reward') {
return stub('encodeOutpointSourceId', [id32, source]);
},
encodeLockForSeconds(totalSeconds: number) {
return stub('encodeLockForSeconds', [totalSeconds]);
},
encodeInputForUtxo(outpointSource: Uint8Array, index: number) {
return stub('encodeInputForUtxo', [outpointSource, index]);
},
Expand Down Expand Up @@ -290,17 +293,17 @@ export const MojitoCore: MojitoCore = {
encodeCreateOrderOutput(params: OrderParams) {
return stub('encodeCreateOrderOutput', [params]);
},
encodeInputForFillOrder(orderId: Uint8Array, destination: Uint8Array, amount: string) {
return stub('encodeInputForFillOrder', [orderId, destination, amount]);
encodeInputForFillOrder(orderId: string, fillAmount: string, destination: string, nonce: number, currentBlockHeight: number, network: MlNetwork) {
return stub('encodeInputForFillOrder', [orderId, fillAmount, destination, nonce, currentBlockHeight, network]);
},
encodeInputForConcludeOrder(orderId: Uint8Array, destination: Uint8Array) {
return stub('encodeInputForConcludeOrder', [orderId, destination]);
encodeInputForConcludeOrder(orderId: string, nonce: number, currentBlockHeight: number, network: MlNetwork) {
return stub('encodeInputForConcludeOrder', [orderId, nonce, currentBlockHeight, network]);
},
getOrderId(transaction: Uint8Array, outputIndex: number) {
return stub('getOrderId', [transaction, outputIndex]);
getOrderId(inputs: Uint8Array[], network: MlNetwork) {
return stub('getOrderId', [inputs, network]);
},
getTokenId(transaction: Uint8Array, outputIndex: number) {
return stub('getTokenId', [transaction, outputIndex]);
getTokenId(inputs: Uint8Array[], currentBlockHeight: number, network: MlNetwork) {
return stub('getTokenId', [inputs, currentBlockHeight, network]);
},

// static fee schedule
Expand Down
40 changes: 31 additions & 9 deletions modules/mojito-core/mintlayer/MintlayerBindings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// TS mirror of the UniFFI surface we consume. Names follow the Kotlin/Swift
// spellings from docs/build/sdks/mobile-bindings.md. Amounts are decimal atom
// strings. All fallible calls reject with BindingsError.
// TS mirror of the vendored UniFFI surface (vendor/mintlayer, release
// wallet-bindings-v0.1.0). The signatures below are pinned byte-for-byte
// against the vendored Swift/Kotlin facade by src/trade/bindingsParity.test.ts:
// reshaping this file without the vendored source (or vice versa) fails the
// gate. Swift UInt64/UInt32 arguments ride JS numbers (block heights, nonces
// and indexes fit safely); amounts stay decimal atom strings and ids stay
// bech32 strings, exactly the vendored String forms. All fallible calls
// reject with BindingsError.
export type MlNetwork = 'mainnet' | 'testnet' | 'regtest' | 'signet';

export type BindingsError = {
Expand Down Expand Up @@ -31,6 +36,10 @@ export interface MintlayerBindings {
getTransactionId(transaction: Uint8Array, strictByteSize: boolean): Promise<string>;
decodeTransactionToJson(transaction: Uint8Array, network: MlNetwork): Promise<string>;

// timelock encoders: the HTLC refundTimelock argument is the blob one of
// these produces (the vendored facade exposes no bare-number form)
encodeLockForSeconds(totalSeconds: number): Promise<Uint8Array>;

// signing and witnesses
encodeWitness(params: WitnessParams): Promise<Uint8Array>;
encodeWitnessNoSignature(): Promise<Uint8Array>;
Expand All @@ -41,26 +50,39 @@ export interface MintlayerBindings {

// orders
encodeCreateOrderOutput(params: OrderParams): Promise<Uint8Array>;
encodeInputForFillOrder(orderId: Uint8Array, destination: Uint8Array, amount: string): Promise<Uint8Array>;
encodeInputForConcludeOrder(orderId: Uint8Array, destination: Uint8Array): Promise<Uint8Array>;
getOrderId(transaction: Uint8Array, outputIndex: number): Promise<string>;
getTokenId(transaction: Uint8Array, outputIndex: number): Promise<string>;
encodeInputForFillOrder(orderId: string, fillAmount: string, destination: string, nonce: number, currentBlockHeight: number, network: MlNetwork): Promise<Uint8Array>;
encodeInputForConcludeOrder(orderId: string, nonce: number, currentBlockHeight: number, network: MlNetwork): Promise<Uint8Array>;
/** The bech32 order id derived from the create transaction inputs. */
getOrderId(inputs: Uint8Array[], network: MlNetwork): Promise<string>;
/** The bech32 token id derived from the issuing transaction inputs; the
* id scheme depends on the upgrade active at currentBlockHeight. */
getTokenId(inputs: Uint8Array[], currentBlockHeight: number, network: MlNetwork): Promise<string>;

// static fee schedule
fungibleTokenIssuanceFee(): Promise<string>;
nftIssuanceFee(): Promise<string>;
}

export type HtlcParams = {
atoms: string; tokenId?: string; secretHash: Uint8Array;
spendAddress: string; spendPubkey: Uint8Array; refundAddress: string; refundTimelock: number;
/** Decimal atom amount (the vendored amount string). */
amount: string;
tokenId?: string;
/** Hex-encoded SHA-256 secret hash (the vendored hex string form). */
secretHash: string;
spendAddress: string;
refundAddress: string;
/** Blob from encodeLockForSeconds (the vendored Data form). */
refundTimelock: Uint8Array;
};

export type WitnessParams = {
sighashType: 'all' | 'none' | 'single' | 'anyonecanpay';
privateKey: Uint8Array; address: string; transaction: Uint8Array;
inputUtxos: (Uint8Array | null)[]; inputIndex: number;
additionalInfo?: { tokenId: string }; inclusionHeight: number; network: MlNetwork;
/** F10 reveal field consumed by encodeWitnessHtlcSpend only (M4 atomic
* swap claim): the preimage that satisfies the HTLC hash. */
secret?: Uint8Array;
};

export type OrderParams = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ios:dev": "expo run:ios",
"android:dev": "expo run:android",
"prebuild": "expo prebuild",
"check": "tsx src/theme.test.ts && tsx src/i18n/strings.test.ts && tsx src/money.test.ts && tsx src/data/polling.test.ts && tsx src/data/ml/indexerClient.test.ts && tsx src/data/btc/btcChainService.test.ts && tsx src/data/addresses/addressManager.test.ts && tsx src/storage/addressStore.test.ts && tsx src/data/activity/activityService.test.ts && tsx src/storage/secureStore.test.ts && tsx src/storage/walletVault.test.ts && tsx src/storage/pinStore.test.ts && tsx src/storage/appSettings.test.ts && tsx src/data/real/realWalletData.test.ts && tsx src/data/providers/providers.test.ts && tsx src/data/providers/broadcast.test.ts && tsx src/keys/bip39.test.ts && tsx src/keys/mlAccounts.test.ts && tsx src/keys/BtcKeyring.test.ts && tsx src/send/validation.test.ts && tsx src/send/mlTxBuilder.test.ts && tsx src/send/btcTxBuilder.test.ts && tsx src/send/TxTracker.test.ts && tsx src/data/real/realSend.test.ts && tsx src/data/mock/mockSend.test.ts && tsx src/keys/session.test.ts && tsx scripts/no-console.ts && tsx scripts/no-em-dash.ts && tsc --noEmit && eslint .",
"check": "tsx src/theme.test.ts && tsx src/i18n/strings.test.ts && tsx src/money.test.ts && tsx src/data/polling.test.ts && tsx src/data/ml/indexerClient.test.ts && tsx src/data/btc/btcChainService.test.ts && tsx src/data/addresses/addressManager.test.ts && tsx src/storage/addressStore.test.ts && tsx src/data/activity/activityService.test.ts && tsx src/storage/secureStore.test.ts && tsx src/storage/walletVault.test.ts && tsx src/storage/pinStore.test.ts && tsx src/storage/appSettings.test.ts && tsx src/data/real/realWalletData.test.ts && tsx src/data/providers/providers.test.ts && tsx src/data/providers/broadcast.test.ts && tsx src/data/providers/bridge.test.ts && tsx src/trade/orderBookService.test.ts && tsx src/trade/orders.test.ts && tsx src/trade/htlc.test.ts && tsx src/trade/swapSession.test.ts && tsx src/trade/priceGuards.test.ts && tsx src/trade/bindingsParity.test.ts && tsx src/keys/bip39.test.ts && tsx src/keys/mlAccounts.test.ts && tsx src/keys/BtcKeyring.test.ts && tsx src/send/validation.test.ts && tsx src/send/mlTxBuilder.test.ts && tsx src/send/btcTxBuilder.test.ts && tsx src/send/TxTracker.test.ts && tsx src/data/real/realSend.test.ts && tsx src/data/mock/mockSend.test.ts && tsx src/keys/session.test.ts && tsx scripts/no-console.ts && tsx scripts/no-em-dash.ts && tsc --noEmit && eslint .",
"lint": "eslint ."
},
"dependencies": {
Expand Down
Loading
Loading