Skip to content

Commit

Permalink
fix: return correct signautre
Browse files Browse the repository at this point in the history
  • Loading branch information
billyjacoby committed Oct 31, 2024
1 parent 132d0aa commit 32aefe8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 6 additions & 7 deletions packages/sdk-ts/src/core/accounts/PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,12 @@ export class PrivateKey {
* @param {string} messageHashedBytes: the message that will be signed, a Buffer made of bytes
* @returns {Uint8Array} a signature of this private key over the given message
*/
signHashed(messageHashedBytes: Buffer): Uint8Array {
async signHashed(messageHashedBytes: Buffer): Promise<string> {
const { wallet } = this

const signature = wallet.signingKey.sign(messageHashedBytes)
const splitSignature = BytesUtils.splitSignature(signature)
const signature = await wallet.signMessage(messageHashedBytes)

return BytesUtils.arrayify(
BytesUtils.concat([splitSignature.r, splitSignature.s]),
)
return signature
}

/**
Expand Down Expand Up @@ -360,7 +357,9 @@ export class PrivateKey {
}

const decodedExtension =
InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.decode(extension.value)
InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.decode(
extension.value,
)

const ethereumChainId = Number(
decodedExtension.typedDataChainID,
Expand Down
7 changes: 5 additions & 2 deletions packages/wallets/wallet-private-key/src/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,12 @@ export class PrivateKeyWallet
}

try {
const signature = await pk.signHashed(Buffer.from(toUtf8(data), 'utf-8'))
const bufferUTF = Buffer.from(toUtf8(data), 'utf-8')
const signature = pk.signHashed(bufferUTF)

return `0x${Buffer.from(signature).toString('base64')}`
return signature

// return `0x${Buffer.from(signature).toString('base64')}`
} catch (e: unknown) {
throw new MetamaskException(new Error((e as any).message), {
code: UnspecifiedErrorCode,
Expand Down

0 comments on commit 32aefe8

Please sign in to comment.