Skip to content

Commit

Permalink
Merge pull request #14 from getsafle/sign-message
Browse files Browse the repository at this point in the history
Sign message
  • Loading branch information
sshubhamagg authored Aug 19, 2024
2 parents c4389f1 + 9137a38 commit f9644ed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

- Implemented Keyring functionality to manage accounts
- Implemented functionality to sign a raw transaction
- Implemented functionality to sign a message
22 changes: 22 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,28 @@ class KeyringController extends EventEmitter {
return signedTx;
}

/**
* Sign Transaction or Message to get v,r,s
*
* Signs a transaction object.
*
* @param {Object} rawTx - The transaction or message to sign.
* @param {Object} privateKey - The private key of the account.
* @param {Object} web3 - web3 object.
* @returns {Object} The signed transaction object.
*/
async sign(rawTx, privateKey, web3) {
let signedTx;
if (typeof rawTx === "string")
signedTx = await web3.eth.accounts.sign(rawTx, privateKey);
else
signedTx = await web3.eth.accounts.signTransaction(
{ ...rawTx, gas: await web3.eth.estimateGas(rawTx) },
privateKey
);
return signedTx;
}

/**
* Get Keyring For Account
*
Expand Down

0 comments on commit f9644ed

Please sign in to comment.