Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update types for payload and signature #87

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions lib/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import BigNumber from "bignumber.js";
import {
Account,
Currency,
Transaction,
Transport,
WalletAPIClient,
WindowMessageTransport,
defaultLogger,
} from "@ledgerhq/wallet-api-client";
import { ExchangeModule } from "@ledgerhq/wallet-api-exchange-module";
import { ExchangeCompleteParams, ExchangeModule } from "@ledgerhq/wallet-api-exchange-module";

import {
cancelSwap,
Expand Down Expand Up @@ -99,6 +100,18 @@ export type SellInfo = {
type?: string;
};

// extented type to include paramas as string for binaryPayload and signature
export type ExtendedExchangeModule = ExchangeModule & {
completeSell: (params: {
provider: string;
fromAccountId: string;
transaction: Transaction;
binaryPayload: Buffer | string;
signature: Buffer | string; // Custom update to accept Buffer or string
feeStrategy: ExchangeCompleteParams["feeStrategy"];
}) => Promise<string>;
};

/**
* ExchangeSDK allows you to send a swap request to a Ledger Device through a Ledger Live request.
* Under the hood, it relies on {@link https://github.com/LedgerHQ/wallet-api WalletAPI}.
Expand All @@ -114,8 +127,8 @@ export class ExchangeSDK {
return this.walletAPIDecorator.walletClient;
}

private get exchangeModule(): ExchangeModule {
return (this.walletAPI.custom as any).exchange as ExchangeModule;
private get exchangeModule(): ExtendedExchangeModule {
return (this.walletAPI.custom as any).exchange as ExtendedExchangeModule;
}

/**
Expand Down Expand Up @@ -389,7 +402,7 @@ export class ExchangeSDK {
provider: this.providerId,
fromAccountId,
transaction,
binaryPayload: Buffer.from(binaryPayload),
binaryPayload,
signature,
feeStrategy,
})
Expand Down Expand Up @@ -521,8 +534,8 @@ export class ExchangeSDK {
type: string;
}) {
let recipientAddress: string;
let binaryPayload: string;
let signature: Buffer;
let binaryPayload: Buffer | string;
let signature: Buffer | string;
let beData: BEData | undefined;
let newAmount = amount;

Expand All @@ -540,7 +553,7 @@ export class ExchangeSDK {
recipientAddress = data.recipientAddress;
newAmount = data.amount;
binaryPayload = data.binaryPayload;
signature = data.signature;
signature = Buffer.from(data.signature);
beData = data.beData;
} else {
const data = await retrieveSellPayload({
Expand All @@ -561,7 +574,7 @@ export class ExchangeSDK {

recipientAddress = data.payinAddress;
binaryPayload = data.providerSig.payload;
signature = Buffer.from(data.providerSig.signature);
signature = data.providerSig.signature;
}

return {
Expand Down
Loading