aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-09-03 14:34:08 -0700
committerAdam Soltys <[email protected]>2024-09-03 14:34:08 -0700
commit581dc3b5b16e3dd1823bbf95357e5e8c49b0c5e0 (patch)
treea8eb0c0b44800acc8b0898cd254de69750783562 /lib
parent48f9e8b0de151edcf49903277d714d939f0b3d8f (diff)
downloadcoinos-server-581dc3b5b16e3dd1823bbf95357e5e8c49b0c5e0.tar.gz
coinos-server-581dc3b5b16e3dd1823bbf95357e5e8c49b0c5e0.zip
support multiple token versions
Diffstat (limited to 'lib')
-rw-r--r--lib/ecash.ts25
1 files changed, 16 insertions, 9 deletions
diff --git a/lib/ecash.ts b/lib/ecash.ts
index 4ce8912a..8f91e70c 100644
--- a/lib/ecash.ts
+++ b/lib/ecash.ts
@@ -4,17 +4,16 @@ import {
CashuWallet,
getDecodedToken,
getEncodedToken,
- MintQuoteState,
+ getEncodedTokenV4,
} from "@cashu/cashu-ts";
import { g, s } from "$lib/db";
-import ln from "$lib/ln";
import { fail } from "$lib/utils";
let m = new CashuMint(config.mintUrl);
let w = new CashuWallet(m);
-let enc = (proofs) =>
- getEncodedToken({
+let enc = (proofs, v = 4) =>
+ (v === 4 ? getEncodedTokenV4 : getEncodedToken)({
token: [{ mint: config.mintUrl, proofs }],
});
@@ -27,6 +26,12 @@ let ext = async (mint) => {
return issuerPk !== ourPk;
};
+export async function get(id, v = 4) {
+ let token = await g(`cash:${id}`);
+ if (v < 4) return enc(dec(token).proofs, 3);
+ return token;
+}
+
export async function claim(token) {
let { proofs: current } = dec(await g(`cash`));
let { mint } = dec(token);
@@ -39,16 +44,18 @@ export async function claim(token) {
return rcvd.reduce((a, b) => a + b.amount, 0);
}
-export async function mint(amount) {
+export async function mint(amount, v = 4) {
let { proofs } = dec(await g(`cash`));
let { send, returnChange } = await w.send(amount, proofs);
- let rcvd = await w.receive(enc(send));
- await s(`cash`, enc(returnChange));
- return enc(rcvd);
+ let rcvd = await w.receive(enc(send, v));
+ let change = enc(returnChange, v);
+ await s(`cash`, change);
+ return enc(rcvd, v);
}
export async function check(token) {
- let { mint, proofs } = dec(token);
+ let o = dec(token);
+ let { mint, proofs } = o;
let total = proofs.reduce((a, b) => a + b.amount, 0);
let external = await ext(mint);