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

Need documentation for message signing/verifying #1941

Open
nikita-fuchs opened this issue Feb 7, 2024 · 1 comment
Open

Need documentation for message signing/verifying #1941

nikita-fuchs opened this issue Feb 7, 2024 · 1 comment
Labels
docs Documentation
Milestone

Comments

@nikita-fuchs
Copy link
Contributor

As partners want to implement SH wallet as a login mechanism, they need documentation for signing messages using the wallet and verifying the signatures. I guess the only thing necessary here are the proper sdk functions, whereas the wallet part should handle itself?

@davidyuk
Copy link
Member

davidyuk commented Feb 9, 2024

would be good to have a guide about message signing/verifying

I guess the only thing necessary here are the proper sdk functions, whereas the wallet part should handle itself?

yep, except for deep links, sdk doesn't define anything there yet

related issue superhero-com/superhero-wallet#2688

Things should be mentioned there:

https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/classes/AccountBase.html#signMessage
https://docs.aeternity.com/aepp-sdk-js/v13.2.2/api/functions/verifyMessage.html

it('Verify message in Sophia', async () => {
const signContract = await aeSdk.initializeContract<{
message_to_hash: (message: string) => Uint8Array;
verify: (message: string, pub: Encoded.AccountAddress, sig: Uint8Array) => boolean;
}>({
sourceCode:
'include "String.aes"'
+ '\n'
+ '\ncontract Sign ='
+ '\n entrypoint int_to_binary (i: int): string ='
+ '\n switch(Char.from_int(i))'
+ '\n None => abort("Int is too big")'
+ '\n Some(c) => String.from_list([c])'
+ '\n'
+ '\n entrypoint includes (str: string, pat: string): bool ='
+ '\n switch(String.contains(str, pat))'
+ '\n None => false'
+ '\n Some(_) => true'
+ '\n'
+ '\n entrypoint message_to_hash (message: string): hash ='
+ '\n let prefix = "aeternity Signed Message:\\n"'
+ '\n let prefixBinary = String.concat(int_to_binary(String.length(prefix)), prefix)'
+ '\n let messageBinary = String.concat(int_to_binary(String.length(message)), message)'
+ '\n Crypto.blake2b(String.concat(prefixBinary, messageBinary))'
+ '\n'
+ '\n entrypoint verify (message: string, pub: address, sig: signature): bool ='
+ '\n require(includes(message, "H"), "Invalid message")'
+ '\n Crypto.verify_sig(message_to_hash(message), pub, sig)',
});
await signContract.$deploy([]);
await Promise.all(['Hello', 'H'.repeat(127)].map(async (message) => {
expect((await signContract.message_to_hash(message)).decodedResult)
.to.be.eql(messageToHash(message));
const signature = await aeSdk.signMessage(message);
expect((await signContract.verify(message, aeSdk.address, signature)).decodedResult)
.to.be.equal(true);
}));
});

@davidyuk davidyuk added this to the next milestone Feb 9, 2024
@davidyuk davidyuk added docs Documentation and removed feature labels Feb 9, 2024
@davidyuk davidyuk changed the title need documentation for signing/verifying Need documentation for message signing/verifying Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation
Projects
None yet
Development

No branches or pull requests

2 participants