From 32aefe8ffe90129512faf199a3ec1c7d10d81059 Mon Sep 17 00:00:00 2001 From: billyjacoby Date: Thu, 31 Oct 2024 12:36:59 -0400 Subject: [PATCH] fix: return correct signautre --- packages/sdk-ts/src/core/accounts/PrivateKey.ts | 13 ++++++------- .../wallet-private-key/src/strategy/strategy.ts | 7 +++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/sdk-ts/src/core/accounts/PrivateKey.ts b/packages/sdk-ts/src/core/accounts/PrivateKey.ts index dee9906d0..3abdd8cb8 100644 --- a/packages/sdk-ts/src/core/accounts/PrivateKey.ts +++ b/packages/sdk-ts/src/core/accounts/PrivateKey.ts @@ -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 { 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 } /** @@ -360,7 +357,9 @@ export class PrivateKey { } const decodedExtension = - InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.decode(extension.value) + InjectiveTypesV1Beta1TxExt.ExtensionOptionsWeb3Tx.decode( + extension.value, + ) const ethereumChainId = Number( decodedExtension.typedDataChainID, diff --git a/packages/wallets/wallet-private-key/src/strategy/strategy.ts b/packages/wallets/wallet-private-key/src/strategy/strategy.ts index bf1b5b79c..c3a20609d 100644 --- a/packages/wallets/wallet-private-key/src/strategy/strategy.ts +++ b/packages/wallets/wallet-private-key/src/strategy/strategy.ts @@ -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,