Skip to content

Commit

Permalink
feat: new improvements after new PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaporossi-ledger committed Mar 11, 2022
1 parent 9f30e20 commit 2e16808
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/signer/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Eth from '@ledgerhq/hw-app-eth';
import Transport from '@ledgerhq/hw-transport';
import TransportWebHID from '@ledgerhq/hw-transport-webhid';

import { Abi, Invocation, InvocationsSignerDetails, Signature } from '../types';
import { Invocation, InvocationsSignerDetails, Signature } from '../types';
import { addHexPrefix } from '../utils/encode';
import { hashMulticall } from '../utils/hash';
import { TypedData, getMessageHash } from '../utils/typedData';
import { SignerInterface } from './interface';
Expand Down Expand Up @@ -43,39 +44,38 @@ export class LedgerBlindSigner implements SignerInterface {

public async signTransaction(
transactions: Invocation[],
transactionsDetail: InvocationsSignerDetails,
abis?: Abi[]
transactionsDetail: InvocationsSignerDetails
): Promise<Signature> {
if (abis && abis.length !== transactions.length) {
throw new Error('ABI must be provided for each transaction or no transaction');
}
const eth = await this.getEthApp();

const msgHash = hashMulticall(
transactionsDetail.walletAddress,
transactions,
transactionsDetail.nonce.toString(),
transactionsDetail.maxFee.toString()
);

const signature = (await eth.starkUnsafeSign(this.derivationPath, hexZeroPad(msgHash, 32))) as {
r: string;
s: string;
};

return [`0x${signature.r}`, `0x${signature.s}`];
return this.sign(msgHash);
}

public async signMessage(typedData: TypedData, accountAddress: string): Promise<Signature> {
const eth = await this.getEthApp();

const msgHash = getMessageHash(typedData, accountAddress);

const signature = (await eth.starkUnsafeSign(this.derivationPath, hexZeroPad(msgHash, 32))) as {
return this.sign(msgHash);
}

protected async sign(msgHash: string): Promise<Signature> {
const eth = await this.getEthApp();

const {
r,
s,
}: {
r: string;
s: string;
} = (await eth.starkUnsafeSign(this.derivationPath, hexZeroPad(msgHash, 32))) as {
r: string;
s: string;
};

return [`0x${signature.r}`, `0x${signature.s}`];
return [addHexPrefix(r), addHexPrefix(s)];
}
}

0 comments on commit 2e16808

Please sign in to comment.