add function to receive cashu into new token

This commit is contained in:
Danny Morabito 2024-11-28 17:05:07 +01:00
parent 3bbeb113a7
commit 03163e9f4a
Signed by: dannym
GPG key ID: 7CC8056A5A04557E

View file

@ -1,4 +1,4 @@
import {getDecodedToken, type Proof} from "@cashu/cashu-ts"; import {CashuMint, CashuWallet, getDecodedToken, getEncodedToken, type Proof} from "@cashu/cashu-ts";
import type {TokenEntry} from "@cashu/cashu-ts"; import type {TokenEntry} from "@cashu/cashu-ts";
import {getMailSubscriptionDurationForSats} from "./general.ts"; import {getMailSubscriptionDurationForSats} from "./general.ts";
@ -44,6 +44,18 @@ export class TokenInfo {
this.mint = tokens[0].mint; this.mint = tokens[0].mint;
this.proofs = tokens.flatMap(t => t.proofs); this.proofs = tokens.flatMap(t => t.proofs);
} }
async receive(): Promise<string> {
const mint = new CashuMint(this.mint);
const wallet = new CashuWallet(mint);
const newToken = await wallet.receive(this.tokenString);
return getEncodedToken({
token: [{
mint: this.mint,
proofs: newToken
}]
});
}
} }
export class TokenInfoWithMailSubscriptionDuration extends TokenInfo { export class TokenInfoWithMailSubscriptionDuration extends TokenInfo {