Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: fix ecdsa module name in example #5140

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions sui_programmability/examples/math/sources/ecdsa.move
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// 2) Recover a Secp256k1 signature to its public key, output an object with the public key.
// 3) Verify a Secp256k1 signature, produce an event for whether it is verified.
module math::ecdsa {
use sui::crypto;
use sui::ecdsa;
use sui::event;
use sui::object::{Self, UID};
use sui::tx_context::TxContext;
Expand All @@ -26,7 +26,7 @@ module math::ecdsa {
public entry fun keccak256(data: vector<u8>, recipient: address, ctx: &mut TxContext) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irrelevant to this PR, but why this keccak function lives here under ECDSA?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we want to put it in something like hash.move

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let hashed = Output {
id: object::new(ctx),
value: crypto::keccak256(data),
value: ecdsa::keccak256(&data),
};
// Transfer an output data object holding the hashed data to the recipient.
transfer::transfer(hashed, recipient)
Expand All @@ -35,7 +35,7 @@ module math::ecdsa {
public entry fun ecrecover(signature: vector<u8>, hashed_msg: vector<u8>, recipient: address, ctx: &mut TxContext) {
let pubkey = Output {
id: object::new(ctx),
value: crypto::ecrecover(signature, hashed_msg),
value: ecdsa::ecrecover(&signature, &hashed_msg),
};
// Transfer an output data object holding the pubkey to the recipient.
transfer::transfer(pubkey, recipient)
Expand All @@ -52,8 +52,8 @@ module math::ecdsa {
*v = (*v - 1) % 2;
};

let pubkey = crypto::ecrecover(signature, hashed_msg);
let uncompressed = crypto::decompress_pubkey(pubkey);
let pubkey = ecdsa::ecrecover(&signature, &hashed_msg);
let uncompressed = ecdsa::decompress_pubkey(&pubkey);

// Take the last 64 bytes of the uncompressed pubkey.
let uncompressed_64 = vector::empty<u8>();
Expand All @@ -65,7 +65,7 @@ module math::ecdsa {
};

// Take the last 20 bytes of the hash of the 64-bytes uncompressed pubkey.
let hashed = crypto::keccak256(uncompressed_64);
let hashed = ecdsa::keccak256(&uncompressed_64);
let addr = vector::empty<u8>();
let i = 12;
while (i < 32) {
Expand All @@ -84,6 +84,6 @@ module math::ecdsa {
}

public entry fun secp256k1_verify(signature: vector<u8>, public_key: vector<u8>, hashed_msg: vector<u8>) {
event::emit(VerifiedEvent {is_verified: crypto::secp256k1_verify(signature, public_key, hashed_msg)});
event::emit(VerifiedEvent {is_verified: ecdsa::secp256k1_verify(&signature, &public_key, &hashed_msg)});
}
}