Skip to content

Commit

Permalink
fix: solana generic issue
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>
  • Loading branch information
sprohaszka-ledger committed May 3, 2024
1 parent eec3be5 commit 2bfd9e1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 36 deletions.
6 changes: 3 additions & 3 deletions libs/coin-modules/coin-solana/src/bridge/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import type { SolanaAccount, SolanaPreloadDataV1, Transaction } from "../types";
import { endpointByCurrencyId } from "../utils";
import { SignerContext } from "@ledgerhq/coin-framework/signer";
import { SolanaAddress, SolanaSignature, SolanaSigner } from "../signer";
import { SolanaSigner } from "../signer";
import resolver from "../hw-getAddress";
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";

Expand Down Expand Up @@ -118,7 +118,7 @@ function makeBroadcast(getChainAPI: (config: Config) => Promise<ChainAPI>): Broa

function makeSign(
getChainAPI: (config: Config) => Promise<ChainAPI>,
signerContext: SignerContext<SolanaSigner, SolanaAddress | SolanaSignature>,
signerContext: SignerContext<SolanaSigner>,
): SignOperationFnSignature<Transaction> {
return info => {
const config: Config = {
Expand Down Expand Up @@ -157,7 +157,7 @@ export function makeBridges({
getAPI: (config: Config) => Promise<ChainAPI>;
getQueuedAPI: (config: Config) => Promise<ChainAPI>;
getQueuedAndCachedAPI: (config: Config) => Promise<ChainAPI>;
signerContext: SignerContext<SolanaSigner, SolanaAddress | SolanaSignature>;
signerContext: SignerContext<SolanaSigner>;
}): {
currencyBridge: CurrencyBridge;
accountBridge: AccountBridge<Transaction>;
Expand Down
6 changes: 2 additions & 4 deletions libs/coin-modules/coin-solana/src/bridge/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { cached, Config, getChainAPI, queued } from "../api";
import { traced } from "../api/traced";
import { makeBridges } from "./bridge";
import { SignerContext } from "@ledgerhq/coin-framework/signer";
import { SolanaAddress, SolanaSignature, SolanaSigner } from "../signer";
import { SolanaSigner } from "../signer";

const httpRequestLogger = (url: string, options: any) => {
log("network", url, {
Expand Down Expand Up @@ -32,9 +32,7 @@ const getQueuedAndCachedAPI = makeLRUCache(
minutes(1000),
);

export function createBridges(
signerContext: SignerContext<SolanaSigner, SolanaAddress | SolanaSignature>,
) {
export function createBridges(signerContext: SignerContext<SolanaSigner>) {
return makeBridges({
getAPI,
getQueuedAPI,
Expand Down
6 changes: 2 additions & 4 deletions libs/coin-modules/coin-solana/src/hw-getAddress.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
import { SignerContext } from "@ledgerhq/coin-framework/signer";
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
import { SolanaAddress, SolanaSignature, SolanaSigner } from "./signer";
import { SolanaAddress, SolanaSigner } from "./signer";

import bs58 from "bs58";

const resolver = (
signerContext: SignerContext<SolanaSigner, SolanaAddress | SolanaSignature>,
): GetAddressFn => {
const resolver = (signerContext: SignerContext<SolanaSigner>): GetAddressFn => {
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
const { address } = (await signerContext(deviceId, signer =>
signer.getAddress(path, verify),
Expand Down
4 changes: 2 additions & 2 deletions libs/coin-modules/coin-solana/src/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
TransferCommand,
} from "./types";
import { buildTransactionWithAPI } from "./js-buildTransaction";
import type { SolanaAddress, SolanaSignature, SolanaSigner } from "./signer";
import type { SolanaSignature, SolanaSigner } from "./signer";
import BigNumber from "bignumber.js";
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
import { assertUnreachable } from "./utils";
Expand Down Expand Up @@ -53,7 +53,7 @@ const buildOptimisticOperation = (account: Account, transaction: Transaction): S

export const buildSignOperation =
(
signerContext: SignerContext<SolanaSigner, SolanaAddress | SolanaSignature>,
signerContext: SignerContext<SolanaSigner>,
api: () => Promise<ChainAPI>,
): SignOperationFnSignature<Transaction> =>
({
Expand Down
11 changes: 0 additions & 11 deletions libs/coin-modules/coin-solana/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@ export type SolanaAddress = {
export type SolanaSignature = {
signature: Buffer;
};
// enum PubKeyDisplayMode {
// LONG,
// SHORT,
// }
// type AppConfig = {
// blindSigningEnabled: boolean;
// pubKeyDisplayMode: PubKeyDisplayMode;
// version: string;
// };
export interface SolanaSigner {
getAddress(path: string, display?: boolean): Promise<SolanaAddress>;
signTransaction(path: string, txBuffer: Buffer): Promise<SolanaSignature>;
// signOffchainMessage(path: string, msgBuffer: Buffer): Promise<SolanaSignature>;
// getAppConfiguration(): Promise<AppConfig>;
}
8 changes: 1 addition & 7 deletions libs/coin-modules/coin-tezos/src/bridge/signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import type {
import { getEnv } from "@ledgerhq/live-env";
import { FeeNotLoaded } from "@ledgerhq/errors";
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
import type {
LedgerSigner,
TezosAccount,
TezosOperation,
TezosSigner,
Transaction,
} from "../types";
import type { TezosAccount, TezosOperation, TezosSigner, Transaction } from "../types";
import { SignerContext } from "@ledgerhq/coin-framework/signer";

export async function getOperationContents({
Expand Down
10 changes: 5 additions & 5 deletions libs/ledger-live-common/src/families/solana/bridge/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@ledgerhq/coin-solana/api/index";
import { Functions } from "@ledgerhq/coin-solana/utils";
import { makeBridges } from "@ledgerhq/coin-solana/bridge/bridge";
import { SolanaAddress, SolanaSignature, SolanaSigner } from "@ledgerhq/coin-solana/signer";
import { SolanaSigner } from "@ledgerhq/coin-solana/signer";
import { getMockedMethods } from "./mock-data";

function mockChainAPI(config: Config): ChainAPI {
Expand Down Expand Up @@ -91,10 +91,10 @@ function getMockedAPIs() {
signTransaction: (_path: string, _txBuffer: Buffer) =>
Promise.resolve({ signature: Buffer.from("") }),
};
const signerContext = (
deviceId: string,
fn: (signer: SolanaSigner) => Promise<SolanaAddress | SolanaSignature>,
): Promise<SolanaAddress | SolanaSignature> => {
const signerContext = <T>(
_deviceId: string,
fn: (signer: SolanaSigner) => Promise<T>,
): Promise<T> => {
return fn(signer);
};
const mockedAPI = mockChainAPI({ cluster: "mock" } as any);
Expand Down

0 comments on commit 2bfd9e1

Please sign in to comment.