From c8986835efd347ce84c6d52836429c6b9b34644a Mon Sep 17 00:00:00 2001 From: Egge Date: Wed, 4 Dec 2024 13:47:50 +0100 Subject: [PATCH] use interface isntead of concrete class --- src/CashuWallet.ts | 26 +++++++++++++------------- src/model/BlindingData.ts | 11 +++++++++-- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/CashuWallet.ts b/src/CashuWallet.ts index 66cc8578..2939fa15 100644 --- a/src/CashuWallet.ts +++ b/src/CashuWallet.ts @@ -32,7 +32,7 @@ import { serializeProof } from '@cashu/crypto/modules/client'; import { getSignedProofs } from '@cashu/crypto/modules/client/NUT11'; import { type Proof as NUT11Proof } from '@cashu/crypto/modules/common/index'; import { SubscriptionCanceller } from './model/types/wallet/websocket.js'; -import { BlindingData } from './model/BlindingData.js'; +import { BlindingData, BlindingDataLike } from './model/BlindingData.js'; /** * The default number of proofs per denomination to keep in a wallet. */ @@ -251,7 +251,7 @@ class CashuWallet { pubkey?: string; privkey?: string; requireDleq?: boolean; - blindingData?: Array; + blindingData?: Array; } ): Promise> { if (typeof token === 'string') { @@ -307,8 +307,8 @@ class CashuWallet { includeFees?: boolean; includeDleq?: boolean; customBlindingData?: { - keep?: Array; - send?: Array; + keep?: Array; + send?: Array; }; } ): Promise { @@ -489,8 +489,8 @@ class CashuWallet { keysetId?: string; includeFees?: boolean; customBlindingData?: { - keep?: Array; - send?: Array; + keep?: Array; + send?: Array; }; } ): Promise { @@ -788,8 +788,8 @@ class CashuWallet { pubkey?: string, privkey?: string, customBlindingData?: { - keep?: Array; - send?: Array; + keep?: Array; + send?: Array; } ): SwapTransaction { const totalAmount = proofsToSend.reduce((total: number, curr: Proof) => total + curr.amount, 0); @@ -800,8 +800,8 @@ class CashuWallet { ); } const keepAmount = totalAmount - amount - this.getFeesForProofs(proofsToSend); - let keepBlindingData: Array; - let sendBlindingData: Array; + let keepBlindingData: Array; + let sendBlindingData: Array; if (customBlindingData?.keep) { keepBlindingData = customBlindingData.keep; @@ -1046,8 +1046,8 @@ class CashuWallet { counter?: number, pubkey?: string, outputAmounts?: Array - ): Array { - let blindingData: Array; + ): Array { + let blindingData: Array; if (pubkey) { blindingData = BlindingData.createP2PKData(pubkey, amount, keyset, outputAmounts); } else if (counter || counter === 0) { @@ -1079,7 +1079,7 @@ class CashuWallet { amount: number, keyset: MintKeys, counter?: number - ): Array { + ): Array { let count = Math.ceil(Math.log2(amount)) || 1; //Prevent count from being -Infinity if (count < 0) { diff --git a/src/model/BlindingData.ts b/src/model/BlindingData.ts index 6ea90555..b8415641 100644 --- a/src/model/BlindingData.ts +++ b/src/model/BlindingData.ts @@ -1,6 +1,5 @@ import { createP2PKsecret } from '@cashu/crypto/modules/client/NUT11'; import { - Keys, MintKeys, Proof, SerializedBlindedMessage, @@ -19,7 +18,15 @@ import { verifyDLEQProof_reblind } from '@cashu/crypto/modules/client/NUT12'; import { bytesToNumber, numberToHexPadded64, splitAmount } from '../utils'; import { deriveBlindingFactor, deriveSecret } from '@cashu/crypto/modules/client/NUT09'; -export class BlindingData { +export interface BlindingDataLike { + blindedMessage: SerializedBlindedMessage; + blindingFactor: bigint; + secret: Uint8Array; + + toProof: (signature: SerializedBlindedSignature, keyset: MintKeys) => Proof; +} + +export class BlindingData implements BlindingDataLike { blindedMessage: SerializedBlindedMessage; blindingFactor: bigint; secret: Uint8Array;