Skip to content

Commit

Permalink
fix: return correct signature
Browse files Browse the repository at this point in the history
  • Loading branch information
billyjacoby committed Oct 31, 2024
1 parent 132d0aa commit 63a4d18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 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: 4 additions & 3 deletions packages/wallets/wallet-private-key/src/strategy/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DirectSignResponse,
PrivateKey as PrivateKeySigner,
getInjectiveSignerAddress,
} from '@injectivelabs/sdk-ts'
} from '@injectivelabs/sdk-ts/src/index'
import {
ErrorType,
WalletException,
Expand Down Expand Up @@ -202,9 +202,10 @@ 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 = await pk.signHashed(bufferUTF)

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

0 comments on commit 63a4d18

Please sign in to comment.