Skip to content

Commit

Permalink
Merge pull request #11 from getsafle/feature-sign-tx-vrs
Browse files Browse the repository at this point in the history
Feature sign tx vrs
  • Loading branch information
apoorvq committed Mar 9, 2022
2 parents 9550f43 + b3bfac3 commit 65033f0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -27,3 +27,9 @@
##### Implement get balance functionality

- Added getBalance() to fetch the balance in native currency.

### 1.2.0 (2022-03-05)

##### Implement sign functionality

- Added sign() to sign a message or transaction and get signature along with v,r,s.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -61,6 +61,12 @@ const signedTx = await ethController.signTransaction(ethTx, _fromAddress);
const signedMsg = await ethController.signMessage(msgParams);
```

### Sign a message

```
const signedObj = await ethController.sign(msgParams, pvtKey, web3Obj);
```

### Sign Typed Data (EIP-712)

```
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@getsafle/vault-eth-controller",
"version": "1.1.0",
"version": "1.2.0",
"description": "Ethereum controller for safle vault.",
"main": "src/index.js",
"scripts": {
Expand Down
19 changes: 19 additions & 0 deletions src/index.js
Expand Up @@ -423,6 +423,25 @@ 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 65033f0

Please sign in to comment.