Skip to content

Commit 65033f0

Browse files
authored
Merge pull request #11 from getsafle/feature-sign-tx-vrs
Feature sign tx vrs
2 parents 9550f43 + b3bfac3 commit 65033f0

5 files changed

Lines changed: 33 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@
2727
##### Implement get balance functionality
2828

2929
- Added getBalance() to fetch the balance in native currency.
30+
31+
### 1.2.0 (2022-03-05)
32+
33+
##### Implement sign functionality
34+
35+
- Added sign() to sign a message or transaction and get signature along with v,r,s.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ const signedTx = await ethController.signTransaction(ethTx, _fromAddress);
6161
const signedMsg = await ethController.signMessage(msgParams);
6262
```
6363

64+
### Sign a message
65+
66+
```
67+
const signedObj = await ethController.sign(msgParams, pvtKey, web3Obj);
68+
```
69+
6470
### Sign Typed Data (EIP-712)
6571

6672
```

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@getsafle/vault-eth-controller",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Ethereum controller for safle vault.",
55
"main": "src/index.js",
66
"scripts": {

src/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,25 @@ class KeyringController extends EventEmitter {
423423
return signedTx
424424
}
425425

426+
/**
427+
* Sign Transaction or Message to get v,r,s
428+
*
429+
* Signs a transaction object.
430+
*
431+
* @param {Object} rawTx - The transaction or message to sign.
432+
* @param {Object} privateKey - The private key of the account.
433+
* @param {Object} web3 - web3 object.
434+
* @returns {Object} The signed transaction object.
435+
*/
436+
async sign(rawTx, privateKey, web3) {
437+
let signedTx;
438+
if (typeof rawTx === 'string')
439+
signedTx = await web3.eth.accounts.sign(rawTx, privateKey);
440+
else
441+
signedTx = await web3.eth.accounts.signTransaction({ ...rawTx, gas: await web3.eth.estimateGas(rawTx) }, privateKey)
442+
return signedTx
443+
}
444+
426445
/**
427446
* Get Keyring For Account
428447
*

0 commit comments

Comments
 (0)