Skip to content

Commit

Permalink
GA-fix: adds functionality to sign different types of transactions wi…
Browse files Browse the repository at this point in the history
…th a private key
  • Loading branch information
ArtemBurakov authored and rileystephens28 committed May 28, 2024
1 parent 7ef4881 commit aee54ad
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions background/services/keyring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,18 +805,28 @@ export default class KeyringService extends BaseService<Events> {
}): Promise<string> {
this.requireUnlocked()
const { domain, types, message } = typedData
// find the keyring using a linear search
const keyring = await this.#findKeyring(account)
// When signing we should not include EIP712Domain type
const { EIP712Domain, ...typesForSigning } = types
try {
const signature = await keyring.signTypedData(
account,
domain,
typesForSigning,
message

const signerWithType = this.#findSigner(account)
if (!signerWithType)
throw new Error(
`Signing transaction failed. Signer for address ${account} was not found.`
)

try {
const signature = isPrivateKey(signerWithType)
? await signerWithType.signer._signTypedData(
domain,
typesForSigning,
message
)
: await signerWithType.signer.signTypedData(
account,
domain,
typesForSigning,
message
)

return signature
} catch (error) {
throw new Error("Signing data failed")
Expand All @@ -840,14 +850,18 @@ export default class KeyringService extends BaseService<Events> {
}): Promise<string> {
this.requireUnlocked()

// find the keyring using a linear search
const keyring = await this.#findKeyring(account)
try {
const signature = await keyring.signMessageBytes(
account,
arrayify(signingData)
const signerWithType = this.#findSigner(account)
if (!signerWithType)
throw new Error(
`Signing transaction failed. Signer for address ${account} was not found.`
)

try {
const messageBytes = arrayify(signingData)
const signature = isPrivateKey(signerWithType)
? await signerWithType.signer.signMessage(messageBytes)
: await signerWithType.signer.signMessageBytes(account, messageBytes)

return signature
} catch (error) {
throw new Error("Signing data failed")
Expand Down

0 comments on commit aee54ad

Please sign in to comment.