add function to receive cashu into new token
This commit is contained in:
parent
3bbeb113a7
commit
03163e9f4a
1 changed files with 13 additions and 1 deletions
14
src/cashu.ts
14
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<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 {
|
||||
|
|
Loading…
Reference in a new issue