-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added new verify command to verify signatures - updated result of sign command to be stringified json making it easier to utilize verify command immediately after signing - added tests
- Loading branch information
Showing
13 changed files
with
161 additions
and
122 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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
export interface SignResult { | ||
signature: string | ||
verifyingKey: string | ||
} | ||
|
||
export interface RawSignPayload { | ||
sigRequestHash: string | ||
hash: any | ||
auxiliaryData: any | ||
signatureVerifyingKey?: string | ||
} | ||
|
||
// TODO: export type from sdk | ||
export interface SignatureData { | ||
signature: string | ||
verifyingKey: string | ||
hashType: string | ||
message: string // hex string as bytes? | ||
} |
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
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,23 @@ | ||
import { Command, /* Option */ } from 'commander' | ||
|
||
import { EntropyVerify } from './main' | ||
import { accountOption, configOption, endpointOption, cliWrite } from '../common/utils-cli' | ||
import { loadEntropyCli } from '../common/load-entropy' | ||
|
||
export function entropyVerifyCommand () { | ||
const verifyCommand = new Command('verify') | ||
.description('Verify a signture. Output is a boolean') | ||
.argument('<signatureData>', 'Signature data returned from signing method') | ||
.addOption(accountOption()) | ||
.addOption(configOption()) | ||
.addOption(endpointOption()) | ||
.action(async (signatureData, opts) => { | ||
const entropy = await loadEntropyCli(opts) | ||
const VerifyService = new EntropyVerify(entropy, opts.endpoint) | ||
|
||
const isVerified = await VerifyService.verify(JSON.parse(signatureData)) | ||
cliWrite({ isSignatureVerified: isVerified }) | ||
process.exit(0) | ||
}) | ||
return verifyCommand | ||
} |
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,15 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { EntropyBase } from "src/common/entropy-base"; | ||
import { SignatureData } from "src/sign/types"; | ||
|
||
const FLOW_CONTEXT = 'ENTROPY_VERIFY' | ||
|
||
export class EntropyVerify extends EntropyBase { | ||
constructor (entropy: Entropy, endpoint: string) { | ||
super({ entropy, endpoint, flowContext: FLOW_CONTEXT }) | ||
} | ||
|
||
async verify (signatureData: SignatureData): Promise<boolean> { | ||
return this.entropy.verify(signatureData) | ||
} | ||
} |
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,30 @@ | ||
import test from 'tape' | ||
|
||
import { EntropySign } from '../src/sign/main' | ||
import { EntropyVerify } from '../src/verify/main' | ||
import { setupTest, eveSeed } from './testing-utils' | ||
|
||
const endpoint = 'ws://127.0.0.1:9944' | ||
|
||
test('Verify Signature', async (t) => { | ||
const { run, entropy } = await setupTest(t, { seed: eveSeed }) | ||
const signService = new EntropySign(entropy, endpoint) | ||
const verifyService = new EntropyVerify(entropy, endpoint) | ||
|
||
await run('register', entropy.register()) | ||
const result = await run( | ||
'sign', | ||
signService.signMessageWithAdapters({ msg: "heyo!" }) | ||
) | ||
|
||
t.true(result?.signature?.length > 32, 'signature has some body!') | ||
|
||
const isVerified = await run( | ||
'verify signature', | ||
verifyService.verify(result) | ||
) | ||
|
||
t.true(isVerified, 'signature is verified') | ||
|
||
t.end() | ||
}) |
Oops, something went wrong.