From 9137a387e4d757a16708a766d8f1351199f80143 Mon Sep 17 00:00:00 2001 From: Husien vora Date: Fri, 16 Aug 2024 14:58:40 +0530 Subject: [PATCH] Implemented functionality to sign a message --- CHANGELOG.md | 1 + src/index.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e598a6..53e26e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ - Implemented Keyring functionality to manage accounts - Implemented functionality to sign a raw transaction +- Implemented functionality to sign a message diff --git a/src/index.js b/src/index.js index 22b7e2c..2fecd01 100644 --- a/src/index.js +++ b/src/index.js @@ -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 *