Skip to content

Commit

Permalink
feat(account)!: verify message by address instead wallet
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `aecli account verify-message` accepts signer address instead wallet
  • Loading branch information
davidyuk committed Apr 15, 2024
1 parent 4d4adce commit 4128276
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ export async function signMessage(walletPath, data = [], options) {

// ## `Verify` function
// this function allow you to `verify` signed data
export async function verifyMessage(walletPath, hexSignature, dataArray = [], options) {
const { json, filePath, password } = options;
export async function verifyMessage(address, hexSignature, dataArray = [], options) {
const { json, filePath } = options;
const data = filePath ? await fs.readFile(filePath) : dataArray.join(' ');
const account = await AccountCli.read(walletPath, password);
const isCorrect = _verifyMessage(data, Buffer.from(hexSignature, 'hex'), account.address);
const isCorrect = _verifyMessage(data, Buffer.from(hexSignature, 'hex'), address);
if (json) {
print({ data, isCorrect });
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ addCommonOptions(program
//
// You can use this command to sign message
//
// Example: `aecli account verify-message ./wallet.json asd1dasfadfsdasdasdasHexSig... Hello`
// Example: `aecli account verify-message ak_... asd1dasfadfsdasdasdasHexSig... Hello`
addCommonOptions(program
.command('verify-message <wallet_path> <hexSignature> [data...]')
.command('verify-message <address> <hexSignature> [data...]')
.option('--filePath [path]', 'Specify the path to the file(ignore comm and message argument and use file instead)')
.description('Check if message was signed by wallet')
.description('Check if message was signed by account')
.action(Account.verifyMessage));

// ## Initialize `address` command
Expand Down
4 changes: 2 additions & 2 deletions test/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ Secret Key ______________________________ ${keypair.secretKey}

it('verify message', async () => {
const data = 'Hello world';
const verify = await executeAccount(['verify-message', WALLET_NAME, sig, data, '--json', '--password', 'test']);
const verify = await executeAccount(['verify-message', sdk.address, sig, data, '--json']);
verify.isCorrect.should.be.equal(true);
const verifyFromFile = await executeAccount(['verify-message', WALLET_NAME, sigFromFile, '--json', '--password', 'test', '--filePath', fileName]);
const verifyFromFile = await executeAccount(['verify-message', sdk.address, sigFromFile, '--json', '--filePath', fileName]);
verifyFromFile.isCorrect.should.be.equal(true);
});
});

0 comments on commit 4128276

Please sign in to comment.