← Cashu Fee Desk

Source & license

Open a file to read the implementation or copy it for offline use. Run node test.cjs to verify the reference scenarios.

index.html
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>Cashu Fee Desk · First Walk Atlas</title><link rel="stylesheet" href="style.css"><script defer src="fees.js"></script><script defer src="cases.js"></script><script defer src="desk.js"></script></head><body>
<header><a href="#main">Cashu Fee Desk</a><a href="source.html">Source &amp; license ↗</a></header>
<main id="main"><h1>Will the recipient get enough sats?</h1><p class="intro">Try a Cashu payment request with sample proofs. See how keyset fees, mint restrictions and melt methods change what the recipient can redeem.</p>
<div class="layout"><section class="controls"><h2>Set up a payment</h2><label>Worked example<select id="preset"></select></label>
<div class="twocol"><label>Requested sats<input type="number" id="amount" min="0" max="1000000000" step="1"></label><label>Sending mint<select id="policy"><option value="listed">On the request’s list</option><option value="strict-other">Outside a strict list</option><option value="preferred-other">Outside a preferred list</option><option value="any">No mint list</option></select></label></div>
<fieldset><legend>Proof groups</legend><div class="grouphead" aria-hidden="true"><span>Count</span><span>Sats each</span><span>Fee, ppk</span><span></span></div><div id="groups"></div><button id="add" type="button">+ Add group</button></fieldset>
<fieldset><legend>Melt methods</legend><label class="row"><input type="checkbox" id="constrained">Request specifies melt methods</label>
<div id="methods"></div></fieldset></section>
<section class="ticket" aria-labelledby="receipt"><h2 id="receipt">Payment check</h2><div aria-live="polite" aria-atomic="true"><p id="status"></p><p id="why"></p></div><dl id="math"></dl>
<p class="formula">Input fee = sum of per-proof ppk fees ÷ 1,000, rounded up once.</p><button id="export">Download this test case</button><button id="vectors">Download all 10 vectors</button></section></div>
<footer>Sat-denominated examples use whole sats and a 1-sat minimum denomination. All calculations run on this device. <a href="https://github.com/cashubtc/nuts/blob/main/02.md">NUT-02</a> · <a href="https://github.com/cashubtc/nuts/blob/main/18.md">NUT-18</a></footer></main></body></html>
style.css
:root{font-family:"Atkinson Hyperlegible Next","Helvetica Neue",Arial,sans-serif;color:#232925;background:#f4f1e9;color-scheme:light}*{box-sizing:border-box}body{max-width:1090px;margin:auto;padding:0 32px 38px}header{display:flex;justify-content:space-between;align-items:center;gap:16px;border-bottom:1px solid #a3a99a;padding:22px 0}header a:first-child{font-weight:bold;color:#284b3f;text-decoration:none}a{color:#14533d;text-underline-offset:3px}h1{font-family:"Hedvig Letters Serif",Georgia,serif;font-weight:normal;font-size:clamp(38px,6.5vw,74px);line-height:1.03;letter-spacing:-.045em;max-width:740px;margin:44px 0 12px}.intro{font-size:18px;line-height:1.45;max-width:690px;margin:0 0 32px}.layout{display:grid;grid-template-columns:minmax(0,1.3fr) minmax(260px,.9fr);gap:24px;align-items:start}.controls,.ticket{padding:22px;border:1px solid #b3b8a9;border-radius:6px;background:#fcfbf7}.ticket{background:#e2eade;border-color:#97aa96;border-top:5px solid #2f5b47}.ticket h2,.controls h2{font-size:21px;margin:0 0 20px}label,legend{font-size:14px;font-weight:650}label{display:block}input,select,button{font:inherit;font-size:15px;color:inherit}select,input[type=number]{height:42px;width:100%;min-width:0;border:1px solid #9ca396;background:white;border-radius:4px;padding:7px;margin-top:6px}.twocol{display:grid;grid-template-columns:1fr 1.6fr;gap:12px;margin-top:16px}fieldset{padding:12px 0 0;margin:20px 0 0;border:0;border-top:1px solid #c9ccbf}legend{padding:0 7px 0 0}.groups,.grouphead{display:grid;grid-template-columns:1fr 1fr 1fr 35px;gap:6px;align-items:center}.grouphead{font-size:12px}.groups button{padding:6px;margin:6px 0 0}.row{display:flex;align-items:center;gap:6px;margin:4px 0}.method{display:grid;grid-template-columns:1fr 1fr;align-items:center;gap:12px;margin-top:10px}input[type=checkbox]{width:17px;height:17px;accent-color:#24583f}button{border:1px solid #667669;border-radius:5px;background:transparent;padding:9px 12px;cursor:pointer;margin:9px 4px 0 0}button:hover{background:#d9e4d6}button:disabled{opacity:.5;cursor:default}:focus-visible{outline:3px solid #0078a2;outline-offset:2px}#status{font:normal 40px/1.12 Georgia,serif;letter-spacing:-.03em;margin:0}#why{line-height:1.5;min-height:1.5em}dl{margin:20px 0 10px}dl div{display:flex;justify-content:space-between;gap:8px;border-top:1px solid #b6c3b1;padding:10px 0;font-size:15px}dd{font-variant-numeric:tabular-nums;font-weight:bold;margin:0;overflow-wrap:anywhere}.formula,footer{font-size:13px;line-height:1.5}.formula{border-top:1px dashed #99a595;padding-top:14px}footer{margin-top:28px;padding-top:15px;border-top:1px solid #afb5a7}pre{white-space:pre;overflow:auto;background:#fff;padding:12px}summary{padding:10px 0;cursor:pointer}@media(max-width:680px){body{padding:0 16px 24px}.layout{grid-template-columns:1fr}.controls,.ticket{padding:17px}h1{margin-top:28px}.intro{font-size:16px}}
desk.js
/* SPDX-License-Identifier: MIT */
"use strict";
const $ = id => document.getElementById(id);
const make = (tag, text) => { const e=document.createElement(tag); if(text!==undefined)e.textContent=text; return e; };
function numeric(value,label,min=0) {
  const n=make("input"); n.type="number"; n.min=min; n.max=1000000000; n.step=1; n.value=value;
  n.setAttribute("aria-label",label); return n;
}
function addGroup(g) {
  const row=make("div");row.className="groups";
  row.append(numeric(g.count,"Number of proofs",1),numeric(g.value,"Face value per proof in sats",1),numeric(g.ppk,"Fee in parts per thousand"));
  const del=make("button","×");del.type="button";del.setAttribute("aria-label","Remove proof group");
  del.addEventListener("click",()=>{row.remove();refresh()});row.append(del);$("groups").append(row);
}
function addMethod(name,fee,supported) {
  const row=make("div");row.className="method";row.dataset.name=name;
  const check=make("input");check.type="checkbox";check.checked=supported;
  const label=make("label");label.className="row";label.append(check,"Mint supports "+name);
  const price=make("label","Fee in sats");price.append(numeric(fee??0,name+" melt fee"));
  row.append(label,price);$("methods").append(row);
}
function loadExample(index) {
  const s=cashuCases[index].scenario;$("amount").value=s.amount;$("policy").value=s.mint;
  $("groups").replaceChildren();s.groups.forEach(addGroup);$("methods").replaceChildren();
  $("constrained").checked=!!s.methods.length;
  (s.methods.length?s.methods:[{name:"bolt11",fee:0,supported:true},{name:"onchain",fee:5,supported:false}]).forEach(m=>addMethod(m.name,m.fee,m.supported));
  refresh();
}
function state() {
  const methods=$("constrained").checked?Array.from($("methods").children,row=>({name:row.dataset.name,fee:row.querySelector("input[type=number]").valueAsNumber,supported:row.querySelector("input[type=checkbox]").checked})):[];
  const groups=Array.from($("groups").children,row=>{
    const [count,value,ppk]=Array.from(row.querySelectorAll("input"),i=>i.valueAsNumber);
    return {count,value,ppk};
  });
  return {amount:$("amount").valueAsNumber,mint:$("policy").value,groups,methods};
}
function refresh() {
  $("math").replaceChildren();$("methods").hidden=!$("constrained").checked;
  try {
    const s=state();const r=evaluateCashuFees(s);
    const delta=r.difference===null?null:BigInt(r.difference);
    $("status").textContent=r.status==="incompatible"?"Mint incompatible":r.status==="short"?String(-delta)+(delta===-1n?" sat short":" sats short"):delta===0n?"Exact amount":"Covered";
    $("why").textContent=r.reason||(r.status==="short"?"The redeemable value falls below the amount due.":delta>0n?delta+" surplus sats after fees.":"The proofs cover the request and applicable fees exactly.");
    const rows=[["Requested",s.amount],["Proof face value",r.face],["Input fee",r.inputFee],["After input fee",r.net],["Melt method fee",r.methodFee]];
    for(const [name,n] of rows){const row=make("div");row.append(make("dt",name),make("dd",n===null?"Inapplicable":n+" sat"));$("math").append(row);}
    $("export").disabled=false;
  } catch(e) {$("status").textContent="Check inputs";$("why").textContent=e.message;$("export").disabled=true;}
}
function download(name,object) {
  const url=URL.createObjectURL(new Blob([JSON.stringify(object,null,2)+"\n"],{type:"application/json"}));
  const a=make("a");a.href=url;a.download=name;a.click();setTimeout(()=>URL.revokeObjectURL(url),1500);
}
cashuCases.forEach((c,i)=>{const o=make("option",c.name);o.value=i;$("preset").append(o)});
$("preset").addEventListener("change",e=>loadExample(Number(e.target.value)));
document.querySelector(".controls").addEventListener("input",e=>{if(e.target.id!=="preset")refresh()});
$("add").addEventListener("click",()=>{addGroup({count:1,value:1,ppk:0});refresh()});
$("export").addEventListener("click",()=>{const scenario=state();download("cashu-fee-case.json",{unit:"sat",scenario,result:evaluateCashuFees(scenario)});});
$("vectors").addEventListener("click",()=>download("cashu-fee-vectors.json",cashuCases.map(c=>({name:c.name,unit:"sat",scenario:c.scenario,expectedColumns:["status","inputFee","methodFee","difference"],expected:c.expected}))));
loadExample(0);
fees.js
/* SPDX-License-Identifier: MIT */
(function (root) {
  "use strict";
  function integer(value, label, min = 0) {
    if (!Number.isSafeInteger(value) || value < min || value > 1000000000) {
      throw new Error(label + " must be a whole number between " + min + " and 1,000,000,000.");
    }
    return BigInt(value);
  }
  function evaluate(s) {
    const target = integer(s.amount, "Requested amount");
    if (!["listed", "strict-other", "preferred-other", "any"].includes(s.mint)) throw new Error("Select a mint policy.");
    if (!Array.isArray(s.groups) || !s.groups.length) throw new Error("Add at least one proof group.");
    let gross = 0n, parts = 0n;
    for (const g of s.groups) {
      const count = integer(g.count, "Proof count", 1);
      gross += count * integer(g.value, "Proof face value", 1);
      parts += count * integer(g.ppk, "Keyset fee");
    }
    const inputFee = (parts + 999n) / 1000n;
    const net = gross - inputFee;
    if (!Array.isArray(s.methods)) throw new Error("Supply a list of melt methods.");
    for (const m of s.methods) {
      if (!m || typeof m.name !== "string" || !m.name || typeof m.supported !== "boolean") throw new Error("Supply a method name and mint support flag.");
      if (m.fee !== undefined) integer(m.fee, "Method fee");
    }
    const matching = s.methods.filter(m => m.supported);
    const fees = matching.map(m => m.fee === undefined ? 0n : integer(m.fee, "Method fee"));
    let reason = "";
    if (s.mint === "strict-other") reason = "The request requires a different mint.";
    else if (s.methods.length && !matching.length) reason = "This mint supports none of the requested melt methods.";
    let methodFee = 0n;
    if (s.mint !== "listed" && fees.length) methodFee = fees.reduce((a,b) => a < b ? a : b);
    const delta = net - target - methodFee;
    return {status:reason ? "incompatible" : delta < 0n ? "short" : "covered",reason,
      face:gross.toString(),inputFee:inputFee.toString(),net:net.toString(),
      methodFee:reason ? null : methodFee.toString(),difference:reason ? null : delta.toString()};
  }
  if (typeof module === "object" && module.exports) module.exports = evaluate;
  else root.evaluateCashuFees = evaluate;
})(globalThis);
cases.js
/* SPDX-License-Identifier: MIT */
(function (root) {
  const group = (count,value,ppk) => ({count,value,ppk});
  const methods = (bolt,chain) => [{name:"bolt11",fee:0,supported:bolt},{name:"onchain",fee:5,supported:chain}];
  const cases = [
    ["One sat short", 4, "listed", [group(1,4,250)], [], ["short","1","0","-1"]],
    ["Round once across keysets", 5, "listed", [group(1,4,500),group(1,2,500)], [], ["covered","1","0","0"]],
    ["Mixed keysets over the boundary", 4, "listed", [group(1,4,500),group(1,2,501)], [], ["covered","2","0","0"]],
    ["Dust costs 250 sats", 1000, "any", [group(1000,1,250)], [], ["short","250","0","-250"]],
    ["Preferred mint unavailable", 10, "preferred-other", [group(1,16,250)], methods(false,true), ["covered","1","5","0"]],
    ["Use the cheapest supported method", 15, "any", [group(1,16,250)], methods(true,true), ["covered","1","0","0"]],
    ["Listed mint waives the method fee", 15, "listed", [group(1,16,250)], methods(false,true), ["covered","1","0","0"]],
    ["Strict mint mismatch", 1, "strict-other", [group(1,2,0)], [], ["incompatible","0",null,null]],
    ["No shared melt method", 1, "listed", [group(1,2,0)], methods(false,false), ["incompatible","0",null,null]],
    ["An omitted method fee is zero", 2, "any", [group(1,2,0)], [{name:"bolt11",supported:true}], ["covered","0","0","0"]]
  ].map(([name,amount,mint,groups,methods,expected])=>({name,scenario:{amount,mint,groups,methods},expected}));
  if (typeof module === "object" && module.exports) module.exports = cases;
  else root.cashuCases = cases;
})(globalThis);
test.cjs
const assert = require("node:assert/strict");
const evaluate = require("./fees.js");
const cases = require("./cases.js");
for (const example of cases) {
  const actual = evaluate(example.scenario);
  assert.deepEqual([actual.status, actual.inputFee, actual.methodFee, actual.difference],example.expected,example.name);
}
const large = evaluate({amount:1,mint:"any",groups:[{count:1e9,value:1e9,ppk:1e9}],methods:[]});
assert.equal(large.face,"1000000000000000000");
assert.equal(large.inputFee,"1000000000000000");
assert.throws(()=>evaluate({amount:4,mint:"any",groups:[{count:1.5,value:1,ppk:0}],methods:[]}));
console.log(cases.length + " reference scenarios passed, plus exact-integer and invalid-input checks.");
README.md
# Cashu Fee Desk

An offline sat-denominated Cashu payment-request calculator and interoperability fixture set, built in November 2026 by First Walk Atlas, an AI studio with a human operator. Open index.html in a browser or run node test.cjs from this directory. Both work offline with no dependencies. The website's Source & license page contains the source and license.

A wallet can hand over proofs whose face value equals the request and still leave the recipient short. The desk models the receiver's net proceeds, the sending mint's relationship to the request and the cheapest supported melt method when its fee applies. Change the counts and rates to compare results. Download the current case and expected result, or all ten reference cases, from the payment check.

## Model

The calculator handles a fixed amount in sat, one sending mint, integer denominations with a 1-sat minimum, and any number of user-specified keyset groups. It sums per-proof fee rates across groups before rounding up. A strict mint-list mismatch or lack of a required common method makes a payment incompatible. A listed mint waives a per-method surcharge. A preferred but unlisted mint, or a request with no list, incurs the lowest fee among matching methods. Example method fees are illustrative.

The UI uses sample amounts only. It does not read tokens, keys, addresses or wallet balances. It does not check proof validity, advertised mint capabilities, lock conditions, exchange rates or current fee schedules. Enter the known fee for each keyset and the relevant method support. These synthetic cases exercise arithmetic and mint policy, not transaction serialization.

The core returns amounts as decimal strings for exact results. A null methodFee or difference denotes an incompatible mint. On a valid path, negative difference is a shortfall and positive difference is a surplus. Fixture expected columns are status, inputFee, methodFee and difference.

## Protocol references

https://github.com/cashubtc/nuts/blob/main/02.md
https://github.com/cashubtc/nuts/blob/main/18.md
LICENSE
MIT License

Copyright (c) 2026 First Walk Atlas

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.