-
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.
Implements the signature verification inside a Mina smart contract.
- Loading branch information
Showing
10 changed files
with
6,352 additions
and
188 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,33 @@ | ||
import { | ||
Field, | ||
Provable, | ||
Struct, | ||
} from 'o1js'; | ||
|
||
export class SessionHeader extends Struct ({ | ||
encoderSeed: Provable.Array(Field, 32), | ||
merkleRoot: Provable.Array(Field, 32), | ||
sentLen: Provable.Array(Field, 8), | ||
recvLen: Provable.Array(Field, 8), | ||
handshakeSummary: Struct({ | ||
time: Provable.Array(Field, 8), | ||
serverPublicKey: Struct({ | ||
group: Provable.Array(Field, 2), | ||
key: Provable.Array(Field, 65), | ||
}), | ||
handshakeCommitment: Provable.Array(Field, 32), | ||
}), | ||
}) { | ||
toFields(): Field[] { | ||
return [ | ||
...this.encoderSeed, | ||
...this.merkleRoot, | ||
...this.sentLen, | ||
...this.recvLen, | ||
...this.handshakeSummary.time, | ||
...this.handshakeSummary.serverPublicKey.group, | ||
...this.handshakeSummary.serverPublicKey.key, | ||
...this.handshakeSummary.handshakeCommitment, | ||
]; | ||
} | ||
} |
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,25 +1,26 @@ | ||
import { | ||
Field, | ||
SmartContract, | ||
state, | ||
State, | ||
method, | ||
Signature, | ||
PublicKey | ||
PublicKey, | ||
} from 'o1js'; | ||
|
||
import { SessionHeader } from './SessionHeader.js'; | ||
|
||
export class TlsnVerifier extends SmartContract { | ||
@state(PublicKey) notaryPublicKey = State<PublicKey>(); | ||
|
||
@method verify( | ||
sessionHeader: Field[], | ||
sessionHeader: SessionHeader, | ||
signature: Signature | ||
) { | ||
// Get the notary public key from the contract state | ||
const notaryPublicKey = this.notaryPublicKey.getAndRequireEquals(); | ||
|
||
// Evaluate whether the signature is valid for the provided data | ||
const validSignature = signature.verify(notaryPublicKey, sessionHeader); | ||
const validSignature = signature.verify(notaryPublicKey, sessionHeader.toFields()); | ||
validSignature.assertTrue(); | ||
} | ||
} |
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
Oops, something went wrong.