Repository navigation
feat(wallet): añadir signAndSendBuilt para los builds de apps/api - #43
Merged
Merged
Conversation
- Con res.soroban: verifica WEB-3, firma solo la entrada del firmante con
expiración min(validUntilLedger, latest + 60) y envía { func, auth } al
relay de la API. Sin soroban: firma externa (signXdr) y send-transaction.
- WalletConfig.relayPath y sendTransactionPath; anchor con rampPath.
- INTERFACES § 8, § 10 y § 11 alineados con la API de P2 (formatos de
respuesta del relay y del ramp).
Refs: #42
RicardoMatosR
requested review from
CarlosJX7,
Diego-Matoss and
jzelada97
as code owners
October 25, 2026 19:40
jzelada97
approved these changes
Oct 25, 2026
jzelada97
left a comment
Owner
There was a problem hiding this comment.
Aprobado por P2 (integrador).
- ✅
signAndSendBuiltencaja conapps/api: consorobanenvía{ func, auth }a/api/fianzas/v1/relay; sin él envía{ signedXdr }a/api/stellar/send-transaction, que devuelve{ txHash, ledger, status, code }(lo que leesendBuilt). - ✅ WEB-3 se comprueba antes de pedir la passkey, y la expiración se limita a
latest + 60aunque la API proponga más. - ✅ INTERFACES § 8, § 10 y § 11 ya reflejan el formato real del relay y del ramp. Lo tendré en cuenta en el cliente de
apps/api. - Nota menor: un build
PENDING(200 contxHash, sin ledger) se da por enviado. Me parece bien para la UI, siempre que P4 haga polling del estado.
5 of 6 tasks
CarlosJX7
pushed a commit
that referenced
this pull request
Oct 25, 2026
) ## Qué cambia La API ya permite **crear, fondear, aprobar y consultar fianzas** contra la factory de testnet, con el bucle build → sign → submit de INTERFACES § 8 y sin cambiar la interfaz. **Builds** (`UnsignedTransactionResponse`): - Firmante **G**: XDR preparado, con el firmante como origen. - Firmante **C** (passkey): además, `soroban { func, auth, validUntilLedger = latest + 60 }` para `signAndSendBuilt` (#43). | Ruta | Contrato | |---|---| | `POST /fianzas/v1/fianzas` | `factory.create_fianza`. Lee `configVersion` si no viene (FAC-6), genera `nonce` si falta y devuelve el `contractId` predicho con `predict_address` | | `POST /fianzas/v1/fianzas/{contractId}/cancel` | `escrow.cancel` | | `POST /escrow/single-release/v2/fund` (TW) | `escrow.fund_escrow`. Los `Terms` se leen de la cadena y se reenvían **sin re-codificar** como `expected_terms`; un `amount` distinto da 422 `ESCROW_PROPERTIES_MISMATCH`; `inviteCode` opcional, nunca se registra | | `POST …/approve-milestones` (TW) | `escrow.approve_release`. Solo `milestoneIndexes: [0]` | | `POST …/approve-and-release-milestones` (TW) | Igual; si la aprobación no liquida, 422 `ESCROW_NOT_COMPLETED` | | `POST …/extend-ttl` (TW) | `escrow.extend_contract_ttl` | **Lecturas** (importes en string decimal y camelCase): - `GET /fianzas/v1/fianzas/by-id/{id}`, `{contractId}/terms` (las 4 comisiones), `{contractId}/view`, `{contractId}/yield` y `{contractId}/preview-settlement?deduction=`. - `GET /fianzas/v1/landlords/{address}/fianzas` y `tenants/{address}/fianzas`: índices de la factory + `get_fianzas` en lotes de 25, con cursor opaco y filtro `status`. **Seguridad:** - Antes de construir nada sobre un `contractId` se comprueba `factory.id_of`: los contratos ajenos dan 404 `ESCROW_NOT_FOUND` y no se construye nada contra ellos. - Los `Error(Contract, #N)` de escrow y factory se traducen a códigos TW/`FZ_*` (p. ej. `ConfigChanged` → 409 `FZ_CONFIG_CHANGED`, `VaultError` → 503 `FZ_VAULT_UNAVAILABLE`, reintentable), siempre con `extensions.contractError`. **Pendiente:** - `stop`, `assign-expert`, `record-report`, `resolve` y los dos `claim-*` siguen en 501 hasta que el escrow los tenga. - Las lecturas en forma TW (`GET /escrows…`) también siguen en 501, con el endpoint que las sustituye. ## Issue Closes #52 ## Cómo probarlo ```bash pnpm install && pnpm --filter @fianzas/api typecheck && pnpm --filter @fianzas/api test # 21 tests (11 nuevos) ``` **e2e en testnet a través de la API**, firmando con la CLI. Casero `fianzas-faucet`, inquilino `fianzas-admin`, `custody`, 1 USDC: 1. `POST /fianzas/v1/fianzas` → `contractId` predicho `CAGKN4…NASA`, `configVersion` 7. 2. Firmada y enviada con `send-transaction` → `SUCCESS`. 3. `terms` (id 1, 1 USDC, bond limitado a 1 USDC) y `by-id/1` coinciden. 4. `fund` → firmada y enviada → `SUCCESS`. 5. Aparece `Active` en la lista del casero y en la del inquilino. Con un firmante **C**, `create_fianza` devuelve una auth entry `sorobanCredentialsAddress` de esa C-address y `func` = `factory.create_fianza` (la raíz que acepta la `RelayPolicy`). ## Notas - #45 y #51 ya están en `main` (los fusionó Ricardo); la rama lleva `main` al día, incluido #43. - `view`, `yield`, `preview-settlement` y `approve_release` funcionan cuando entre #48 y suba su wasm con `scripts/deploy` (`set_escrow_wasm_hash`). Con el escrow actual la simulación falla y la API responde 502 `STELLAR_SIMULATION_FAILED`. - Toca `pnpm-lock.yaml` (`@fianzas/bindings` en la API) con el lock `deps` (#49). - **Para P3 y P4:** el flujo completo es `POST /api/fianzas/v1/fianzas` → `wallet.signAndSendBuilt(res)` → `POST /api/escrow/single-release/v2/fund` → `signAndSendBuilt`. Las listas del panel están en `/api/fianzas/v1/landlords/{address}/fianzas`. ## Checklist - [x] Solo toca mi área (api) + `pnpm-lock.yaml` con lock `deps` - [x] Tests y typecheck del workspace en verde en local - [x] No cambia `docs/INTERFACES.md` (implementa § 8 tal como está) - [x] No toca contratos - [x] Sin secretos: las direcciones salen de `deployments/testnet.json` - [ ] > 300 líneas: ~600 de código y ~250 de tests; es el conjunto mínimo para el camino feliz de la demo
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.
Qué cambia
Tarea de P3 que salió del #15 (API de P2): la wallet ya puede firmar lo que construye
apps/api.wallet.signAndSendBuilt(res, opts)paraUnsignedTransactionResponse:res.soroban(cuenta con passkey): verifica el árbol de auth (WEB-3, igual quesignAndSend), firma solo la entrada del firmante con expiraciónmin(validUntilLedger, latest + 60)(no se fía de la API más allá de AUTH-5) y envía{ func, auth }arelayPath.soroban(cuenta G): firma externa conopts.signXdr(Freighter) y{ signedXdr }a/api/stellar/send-transaction.WalletConfig.relayerUrl→relayPath(/api/fianzas/v1/relay) +sendTransactionPath. Anchor:rampUrl→rampPath(/api/fianzas/v1/ramp). Nadie los usaba todavía.FakeWallet.signAndSendBuiltpara P4.INTERFACES.md: § 10 y § 11 con la API real, y en la tabla de § 8 los formatos de respuesta reales. @jzelada97: el relay responde{ success, data: { transactionId, hash, status } }/{ success: false, code }, no{ hash, status }, porque es lo que exige smart-account-kit para crear cuentas. El ramp responde{ id, status }.Issue
Refs #42 (lock
interfaces)Cómo probarlo
Checklist
packages/wallet,packages/anchor) yINTERFACES.mdcon lock LOCK: interfaces #42docs/INTERFACES.mdcon lockinterfaces