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

Trying to find a Rust Crate/Functionality Demonstration of COSESign1 and COSEKey #643

Closed
JustLeif opened this issue Sep 8, 2023 · 2 comments

Comments

@JustLeif
Copy link

JustLeif commented Sep 8, 2023

Context

I am currently trying to build a form of custom authentication for a web application using Cardano CIP-30 Wallets. I found this article in the official documentation. https://developers.cardano.org/docs/integrate-cardano/user-wallet-authentication/

Issue

My back-end servers are written in Rust, I would prefer not to move over to NodeJS if at all possible.

The following JavaScript code is featured in the documentation using @emurgo/cardano-message-signing-nodejs and @emurgo/cardano-serialization-lib-nodejs

const decoded = COSESign1.from_bytes( Buffer.from(sigData.signature, "hex") );
const headermap = decoded.headers().protected().deserialized_headers();
const addressHex = Buffer.from( headermap.header( Label.new_text("address") ).to_bytes() )
    .toString("hex")
    .substring(4);
const address = Address.from_bytes( Buffer.from(addressHex, "hex") );

const key = COSEKey.from_bytes( Buffer.from(sigData.key, "hex") );
const pubKeyBytes = key.header( Label.new_int( Int.new_negative(BigNum.from_str("2")) ) ).as_bytes();
const publicKey = PublicKey.from_bytes(pubKeyBytes);

const payload = decoded.payload();
const signature = Ed25519Signature.from_bytes(decoded.signature());
const receivedData = decoded.signed_data().to_bytes();

const signerStakeAddrBech32 = RewardAddress.from_address(address).to_address().to_bech32();
const utf8Payload = Buffer.from(payload).toString("utf8");
const expectedPayload = `account: ${signerStakeAddrBech32}`; // reconstructed message

// verify:
const isVerified = publicKey.verify(receivedData, signature);
const payloadAsExpected = utf8Payload == expectedPayload;
const signerIsRegistered = registeredUsers.includes(signerStakeAddrBech32);

Is there anyway anyone knows to easily get these cryptography functions in Rust? My knowledge of Cardano specific cryptography is very limited so I rely very heavily on these helper functions.

Thanks in advance!

@lisicky
Copy link
Contributor

lisicky commented Sep 8, 2023

HI @JustLeif ! Probably you are searching for https://github.com/Emurgo/message-signing

@JustLeif
Copy link
Author

JustLeif commented Sep 8, 2023

HI @JustLeif ! Probably you are searching for https://github.com/Emurgo/message-signing

Thanks for the fast reply I appreciate it 👍

@JustLeif JustLeif closed this as completed Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants