This project supports to generate ethereum keypair, sign message, and restore public key with hashed-message and its signature.
This project is developed with,
- node v16.10.0
- npm v7.24.0
and using,
- elliptic v6.5.4
- ethers v5.4.7
- keccak256 v1.0.3
- web3 v1.5.3
>>> ~$ git clone https://github.com/wyuinche/ether-restorejs.git
>>> ~$ cd ether-restorejs
>>> ~/ether-restorejs$ npm install -g
added 1 package, and audited 3 packages in 852msThen use 'npm link ether-restorejs' command in your project folder.
>>> ~/{your project}$ npm link ether-restorejs
added 1 package, and audited 386 packages in 2s'ether-restorejs' supports to generate new ethereum keypair containing a private/public key set.
>>> const etherRestorejs = require('ether-restorejs');
>>> const keypair = etherRestorejs.newKeypair();
>>> keypair.getPrivateKey();
369ba45936f36fdcae428f67ff89a9f82816d4828c36cdb7d34f5904a3bbf941
>>. keypair.getPublicKey();
04804ef73721632e7e65e5f53136137dc6406a792fef07eba1d18715f280ed9bb3a3549ed7ce32332be7225c06c0beea104023b009407c3418f895113fd79abfc7'ether-restorejs' supports to hash string message for ethereum.
>>> const etherRestorejs = require('ether-restorejs');
>>> const msg = 'sample text';
>>> const hashedMsg = etherRestorejs.hashMessage(msg); // <Buffer 65 c9 aa 04 1b fe 8b 21 b4 d5 63 57 74 14 c3 64 50 29 fa 30 bd 40 a7 80 1f 49 05 be c5 72 14 69>
>>> hashedMsg.toString('hex');
65c9aa041bfe8b21b4d563577414c3645029fa30bd40a7801f4905bec5721469You can sign message for ethereum with you keypairs.
/* keypair: keypair generated in 'Generate New Ethereum Keypair'
*/
>>> const signature = keypair.sign('sample text'); 'ether-restorejs' supports to restore ethereum public key by a pair of hashed message and its signature.
>>> const etherRestorejs = require('ether-restorejs');
>>> const keypair = etherRestorejs.newKeypair();
>>> const msg = "sample text";
>>> const hashedMsg = etherRestorejs.hashMessage(msg);
>>> const signature = keypair.sign(msg);
>>> const publicKey = etherRestorejs.restorePublicKey(hashedMsg, signature);
>>> keypair.getPublicKey() == publicKey;
true