Skip to content

Commit

Permalink
Merge pull request #138 from CityOfZion/CU-86a64561q
Browse files Browse the repository at this point in the history
CU-86a64561q - BSEthereum - Ledger - EthersLedgerSigner's signTransac…
  • Loading branch information
thiagocbalducci authored Jan 6, 2025
2 parents 0f10dba + 824438b commit b49b664
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Fix bug where EthersLedgerSigner's signTransaction method did not sign some transaction fields",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class EthersLedgerSigner extends Signer implements TypedDataSigner {
}

async getAddress(): Promise<string> {
const { address } = await this.#ledgerApp.getAddress(this.#bip44Path)
const { address } = await BSEthereumHelper.retry(() => this.#ledgerApp.getAddress(this.#bip44Path))
return address
}

Expand Down Expand Up @@ -73,17 +73,10 @@ export class EthersLedgerSigner extends Signer implements TypedDataSigner {
async signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string> {
try {
const tx = await ethers.utils.resolveProperties(transaction)
const unsignedTransaction: ethers.utils.UnsignedTransaction = {
chainId: tx.chainId ?? undefined,
data: tx.data ?? undefined,
gasLimit: tx.gasLimit ?? undefined,
gasPrice: tx.gasPrice ?? undefined,
nonce: tx.nonce ? ethers.BigNumber.from(tx.nonce).toNumber() : undefined,
to: tx.to ?? undefined,
value: tx.value ?? undefined,
}

const serializedUnsignedTransaction = ethers.utils.serializeTransaction(unsignedTransaction).substring(2)
const serializedUnsignedTransaction = ethers.utils
.serializeTransaction(<ethers.utils.UnsignedTransaction>tx)
.substring(2)

const resolution = await LedgerEthereumAppService.resolveTransaction(serializedUnsignedTransaction, {}, {})

Expand All @@ -95,7 +88,7 @@ export class EthersLedgerSigner extends Signer implements TypedDataSigner {

this.#emitter?.emit('getSignatureEnd')

return ethers.utils.serializeTransaction(unsignedTransaction, {
return ethers.utils.serializeTransaction(<ethers.utils.UnsignedTransaction>tx, {
v: ethers.BigNumber.from('0x' + signature.v).toNumber(),
r: '0x' + signature.r,
s: '0x' + signature.s,
Expand Down

0 comments on commit b49b664

Please sign in to comment.