diff --git a/src/cashu.ts b/src/cashu.ts index fa303f7..77dc4fd 100644 --- a/src/cashu.ts +++ b/src/cashu.ts @@ -1,6 +1,6 @@ -import {CashuMint, CashuWallet, getDecodedToken, getEncodedToken, type Proof} from "@cashu/cashu-ts"; -import type {TokenEntry} from "@cashu/cashu-ts"; -import {getMailSubscriptionDurationForSats} from "./general.ts"; +import { CashuMint, CashuWallet, getDecodedToken, getEncodedToken, type Proof } from "@cashu/cashu-ts"; +import type { TokenEntry } from "@cashu/cashu-ts"; +import { getMailSubscriptionDurationForSats } from "./general.ts"; class InvalidTokenException extends Error { constructor(message: string) { @@ -27,10 +27,10 @@ export class TokenInfo { constructor(protected readonly tokenString: string) { const decodedTokenData = getDecodedToken(tokenString); - const tokens = decodedTokenData.token; + const tokens = Array.isArray(decodedTokenData.token) ? decodedTokenData.token : [decodedTokenData.token]; const amount = tokens.flatMap(t => t.proofs).reduce((c, x) => c + x.amount, 0); - if(decodedTokenData.token.length === 0) + if (tokens.length === 0) throw new InvalidTokenException('Invalid token format. We only accept tokens with at least one proof'); if (tokens.slice(1).some(t => t.mint !== tokens[0].mint)) throw new InvalidTokenException('Invalid token format. We only accept tokens with the same mint');