Chore/merge upstream - #22
Merged
Merged
Conversation
Keep the existing Cardano scheme structure while defining the Masumi V2 request commitment, seller authorization, escrow datum, settlement policies, Hydra path, and replay rules.
- order client submission before paid retry - bind registered agents to the global V2 registry - validate Hydra nonces in the selected head ledger
docs(cardano): define Masumi V2 x402 flow
# Conflicts: # examples/typescript/facilitator/advanced/all_networks.ts # examples/typescript/servers/advanced/README.md # examples/typescript/servers/advanced/all_networks.ts
# Conflicts: # e2e/clients/axios/test.config.json # e2e/clients/fetch/test.config.json # e2e/facilitators/typescript/test.config.json # e2e/src/networks/networks.ts # e2e/src/types.ts # e2e/test.ts # examples/typescript/clients/advanced/README.md # examples/typescript/clients/advanced/all_networks.ts # examples/typescript/facilitator/advanced/README.md # examples/typescript/facilitator/advanced/all_networks.ts # examples/typescript/pnpm-lock.yaml # examples/typescript/servers/advanced/README.md # examples/typescript/servers/advanced/all_networks.ts # typescript/package.json
Restrict Masumi datum addresses to the forms the escrow lifecycle can carry end to end: enterprise key addresses and base addresses whose payment and stake credentials are both key hashes. Masumi's own getPubKeyAddressDatum accepts nothing else, and every later transition rebuilds the continuation datum through it while vested_pay demands `new_datum.buyer == buyer` exactly, so a script stake credential or a pointer address strands the escrow with no recovery path. Enforce the deadline and payment-window rules at issue time. payByTime, the deadline gaps, Masumi's 15-minute submitResultTime lead and maxTimeoutSeconds are all covered by termsDigest, so a 402 that a buyer refuses cannot be repaired afterwards - only re-issued. Deadline strings are guarded before conversion so an unparseable value is a named rejection rather than a raw SyntaxError from BigInt. The interval rule now lives in one place and is shared by the issuer, the client and the facilitator instead of being copied three times. Make the facilitator capability check coherently fail-closed: a facilitator that publishes no extra is not describing itself and passes, but one that publishes a half-filled block is a rejection rather than silent permission to serve a 402 nobody can settle. Read settlementPolicy through the schema instead of an unchecked cast. Drop the dead maxTimeoutSeconds re-check before submission - the ceiling grows with the clock and cannot newly fail - keeping only the expiry check, which can. Document the relationship to masumi-payment-service: the escrow address, datum, collateral floor, min-UTxO headroom and blockchainIdentifier all match the deployed V2 contract, but reference_signature covers this scheme's termsDigest rather than Masumi's signed payload, so a lock built here cannot be driven through a Masumi node.
Two seller-controlled values had no ceiling, and together they let a hostile or compromised resource server freeze a buyer's wallet while passing every existing check. Cap the deadline horizon. vested_pay gates the buyer's WithdrawRefund on `must_start_after(validity_range, submit_result_time)`, so until that deadline the buyer can recover neither the payment nor its collateral. Only minimum gaps were enforced, so a 402 naming external_dispute_unlock_ time years out froze the funds for that long. The issuer, the client and the facilitator now reject a last deadline more than 30 days out, and the client can raise the horizon for a counterparty whose settlement window it accepts. Checking against the verifier's own clock is monotonic: a facilitator sees a later `now` than the client did, so it can only accept what the client already accepted, never newly reject it. Cap the collateral. collateral_return_lovelace is derived from the datum size, and the datum carries reference_key and reference_signature verbatim - each allowed up to MAX_MASUMI_COSE_BYTES. A real lock is a ~450-byte datum needing at most ~3.7 ADA; padding the COSE fields toward the ledger's transaction limit pushes the buyer's own locked collateral past 50 ADA. The client now refuses a collateral above a configurable ceiling before it signs, rather than locking the funds away until submit_result_time.
Reject Masumi `auto` settlement against a facilitator that advertises only Hydra. This scheme authenticates L1 exclusively - verifyMasumiLock refuses a Hydra payload outright - so treating a Hydra-only advertisement as satisfying `auto` served a 402 whose every payment fails at verification. An explicit `hydra` policy still defers to the advertisement, so a subclass that does implement Hydra is unaffected. Re-check the clock-relative issue policy after `signTerms` resolves. Signing is asynchronous and unbounded - a hardware wallet, a remote signer or a human approval can take minutes - so a 402 could be served with a `payByTime` that expired while it was being signed. The second pass reads this function's own `terms` and `requirements` rather than `input`, so a caller mutating its argument mid-flight cannot steer it. The `maxTimeoutSeconds` ceiling is deliberately not the trigger: it moves forward with the clock and cannot newly fail. Skip the issue policy only for the literal boolean `true`, so a truthy non-boolean arriving from untyped configuration cannot silently disable a security check. Let the issuer configure its deadline horizon instead of always using the constant, mirroring the buyer-side option. Compute the test fixture's deadlines when each case runs rather than at module load. `payByTime` has only a minute of slack inside `maxTimeoutSeconds`, so a slow suite would have started failing on timing alone.
…rule The horizon check ran on every path through verifyMasumiAuthorization, but only the client could configure it - the facilitator never sets maxDeadlineHorizonMs, so it was pinned to the 30-day default. A client whose operator raised the horizon to accept a long-settlement counterparty would sign and broadcast a lock the facilitator then rejected, stranding the funds the check exists to protect. The horizon is a judgement about how long the payer will accept its own funds being immobilised, so the payer is the side that makes it. It now applies only when a caller supplies one: the client always does, defaulting to the constant, and a verifier does not. Once the funds are locked, rejecting the payment for a distant deadline unfreezes nothing anyway - it only adds a failed settlement to a lock the buyer already chose to make. The interval rule is a protocol rule and still applies everywhere. Also correct the assertMasumiIssueWindow doc: it claimed the post-signing pass guards against drifting outside maxTimeoutSeconds, which it cannot. That ceiling is `now + maxTimeoutSeconds` and moves forward with the clock, so a payByTime once inside it stays inside it. Only the floors can trip late, which is what the second pass is for.
…mplementation fix(cardano): harden Masumi payment validation
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.
Description
Tests
Checklist