Skip to content

Commit

Permalink
Merge pull request #316 from willmeister/feat/315/SignatureVerification
Browse files Browse the repository at this point in the history
315 Adding signature verification stub
  • Loading branch information
karlfloersch committed Jun 30, 2019
2 parents fe6e30e + 8e39d69 commit 7420899
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
17 changes: 17 additions & 0 deletions packages/core/src/app/utils/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Checks that the message with the provided signature was signed by the private key
* associated with the provided public key.
*
* @param signature the signed message
* @param message the message in question
* @param publicKey the public key to check the signature against
* @returns true if the signature matches the message when decrypted by the publicKey
*/
export const verifySignature = (
signature: any,
message: any,
publicKey: any
): boolean => {
// TODO: Make this do actual signature checking
return signature === publicKey
}
1 change: 1 addition & 0 deletions packages/core/src/app/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export * from './misc'
export * from './range'
export * from './buffer'
export * from './numbers'
export * from './crypto'
10 changes: 8 additions & 2 deletions packages/predicates/src/plugins/ownership-predicate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
StateUpdate,
Transaction,
StateObject,
verifySignature,
} from '@pigi/core'

export class OwnershipPredicatePlugin implements PredicatePlugin {
Expand Down Expand Up @@ -48,8 +49,13 @@ export class OwnershipPredicatePlugin implements PredicatePlugin {
transaction: Transaction,
witness: string
): Promise<void> {
// TODO: Actually check signature stuffs
if (previousStateUpdate.stateObject.data.owner !== witness) {
if (
!verifySignature(
witness,
transaction,
previousStateUpdate.stateObject.data.owner
)
) {
throw new Error(
`Cannot transition from state [${JSON.stringify(
previousStateUpdate
Expand Down

0 comments on commit 7420899

Please sign in to comment.