-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
599ca95
commit ef3c37f
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const output = require('common/src/output') | ||
const storage = require('../internal/storage') | ||
const { getWallet } = require('../internal/signers') | ||
|
||
require('../scopes/sig') | ||
.task('sign', 'Signs a message with a wallet') | ||
.addOptionalPositionalParam('message', 'The message to sign') | ||
.setAction(async ({ message }) => { | ||
try { | ||
const signers = storage.readSigners() | ||
const signer = signers[signers.activeSigner] | ||
|
||
const wallet = getWallet(signer.pk) | ||
|
||
output.resultBox(wallet.signMessageSync(message)) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { Terminal } = require('common/src/terminal') | ||
const storage = require('../../src/internal/storage') | ||
const { getWallet } = require('../../src/internal/signers') | ||
|
||
describe('info', function () { | ||
const terminal = new Terminal() | ||
|
||
const demoSig = { | ||
address: '0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f', | ||
pk: '0xdbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97', | ||
} | ||
|
||
describe('when queryig info about a signer', function () { | ||
before('add test signers', async function () { | ||
const signers = storage.readSigners() | ||
if (!('test__3' in signers)) signers.test__3 = demoSig | ||
signers.activeSigner = 'test__3' | ||
storage.storeSigners(signers) | ||
}) | ||
|
||
after('remove test signers', async function () { | ||
const signers = storage.readSigners() | ||
if ('test__3' in signers) delete signers.test__3 | ||
storage.storeSigners(signers) | ||
}) | ||
|
||
describe('when signing a message', function () { | ||
before('sign', async function () { | ||
await terminal.run('npx hardhat sig sign "hello"') | ||
}) | ||
|
||
it('prints the expected signature', async function () { | ||
terminal.has('Result') | ||
|
||
const wallet = getWallet(demoSig.pk) | ||
const sig = wallet.signMessageSync('hello') | ||
terminal.has(sig.slice(0, 15)) | ||
}) | ||
}) | ||
}) | ||
}) |