Skip to content

Commit

Permalink
use interface isntead of concrete class
Browse files Browse the repository at this point in the history
  • Loading branch information
Egge21M committed Dec 4, 2024
1 parent 9275473 commit c898683
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
26 changes: 13 additions & 13 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -251,7 +251,7 @@ class CashuWallet {
pubkey?: string;
privkey?: string;
requireDleq?: boolean;
blindingData?: Array<BlindingData>;
blindingData?: Array<BlindingDataLike>;
}
): Promise<Array<Proof>> {
if (typeof token === 'string') {
Expand Down Expand Up @@ -307,8 +307,8 @@ class CashuWallet {
includeFees?: boolean;
includeDleq?: boolean;
customBlindingData?: {
keep?: Array<BlindingData>;
send?: Array<BlindingData>;
keep?: Array<BlindingDataLike>;
send?: Array<BlindingDataLike>;
};
}
): Promise<SendResponse> {
Expand Down Expand Up @@ -489,8 +489,8 @@ class CashuWallet {
keysetId?: string;
includeFees?: boolean;
customBlindingData?: {
keep?: Array<BlindingData>;
send?: Array<BlindingData>;
keep?: Array<BlindingDataLike>;
send?: Array<BlindingDataLike>;
};
}
): Promise<SendResponse> {
Expand Down Expand Up @@ -788,8 +788,8 @@ class CashuWallet {
pubkey?: string,
privkey?: string,
customBlindingData?: {
keep?: Array<BlindingData>;
send?: Array<BlindingData>;
keep?: Array<BlindingDataLike>;
send?: Array<BlindingDataLike>;
}
): SwapTransaction {
const totalAmount = proofsToSend.reduce((total: number, curr: Proof) => total + curr.amount, 0);
Expand All @@ -800,8 +800,8 @@ class CashuWallet {
);
}
const keepAmount = totalAmount - amount - this.getFeesForProofs(proofsToSend);
let keepBlindingData: Array<BlindingData>;
let sendBlindingData: Array<BlindingData>;
let keepBlindingData: Array<BlindingDataLike>;
let sendBlindingData: Array<BlindingDataLike>;

if (customBlindingData?.keep) {
keepBlindingData = customBlindingData.keep;
Expand Down Expand Up @@ -1046,8 +1046,8 @@ class CashuWallet {
counter?: number,
pubkey?: string,
outputAmounts?: Array<number>
): Array<BlindingData> {
let blindingData: Array<BlindingData>;
): Array<BlindingDataLike> {
let blindingData: Array<BlindingDataLike>;
if (pubkey) {
blindingData = BlindingData.createP2PKData(pubkey, amount, keyset, outputAmounts);
} else if (counter || counter === 0) {
Expand Down Expand Up @@ -1079,7 +1079,7 @@ class CashuWallet {
amount: number,
keyset: MintKeys,
counter?: number
): Array<BlindingData> {
): Array<BlindingDataLike> {
let count = Math.ceil(Math.log2(amount)) || 1;
//Prevent count from being -Infinity
if (count < 0) {
Expand Down
11 changes: 9 additions & 2 deletions src/model/BlindingData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createP2PKsecret } from '@cashu/crypto/modules/client/NUT11';
import {
Keys,
MintKeys,
Proof,
SerializedBlindedMessage,
Expand All @@ -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;
Expand Down

0 comments on commit c898683

Please sign in to comment.