From 03163e9f4a07b011a28a8f97c90852ecfc806ddd Mon Sep 17 00:00:00 2001 From: Danny Morabito Date: Thu, 28 Nov 2024 17:05:07 +0100 Subject: [PATCH] add function to receive cashu into new token --- src/cashu.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cashu.ts b/src/cashu.ts index 0a8cbc2..fa303f7 100644 --- a/src/cashu.ts +++ b/src/cashu.ts @@ -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 {getMailSubscriptionDurationForSats} from "./general.ts"; @@ -44,6 +44,18 @@ export class TokenInfo { this.mint = tokens[0].mint; this.proofs = tokens.flatMap(t => t.proofs); } + + async receive(): Promise { + 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 {