Skip to content

Commit

Permalink
Added functionality to sign message
Browse files Browse the repository at this point in the history
  • Loading branch information
SDargarh committed Jul 22, 2024
1 parent bef5bb0 commit c511e05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- Implemented Keyring functionality to enable account generation and export keys
- Added getAccounts() method to fetch list of generated accounts
- Added importWallet() to import account using privateKey
- Added initial test
- Added initial test
- Added functionality to sign message
3 changes: 2 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"ed25519-hd-key": "^1.3.0",
"mocha": "^10.7.0",
"nyc": "^17.0.0",
"obs-store": "^4.0.3"
"obs-store": "^4.0.3",
"tweetnacl": "^1.0.3"
}
}
14 changes: 14 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const ObservableStore = require("obs-store");
const bs58 = require("bs58");
const helper = require("./helper");
const nacl = require('tweetnacl');


const { solana: { HD_PATH }, solana_connection: { MAINNET }} = require('./config')
Expand Down Expand Up @@ -55,6 +56,19 @@ class KeyringController {
}
}

async signMessage(message, _address) {
const { mnemonic, address } = this.store.getState()
const idx = address.indexOf(_address);

if (idx < 0)
throw "Invalid address, the address is not available in the wallet"

const accountDetails = helper.setupAccount(mnemonic, helper.getHDPath(idx))
const msg = Buffer.from(message)

return { signedMessage: bs58.encode(nacl.sign.detached(msg, accountDetails.secretKey)) };
}

persistAllAddress(_address) {
const { address } = this.store.getState();
let newAdd = address;
Expand Down

0 comments on commit c511e05

Please sign in to comment.