keep-starknet-strange / joyboy

Decentralized social built with Nostr and powered by Starknet account abstraction.
https://joyboy.community
MIT License
62 stars 41 forks source link

Implementation of snip-6 for SocialPay account contract #111

Closed mubarak23 closed 4 weeks ago

mubarak23 commented 1 month ago

This is a draft PR for snip-6 for SocialPay account contract implementation,

bip340::verify(public_key, *social_event.sig.r, *social_event.sig.s, ba)

from what am seeing here, i need to collect event message in order to achieve these function argument.

does this make sense to push this into the constructor,

  #[storage]
    struct Storage {
        #[key]
        public_key: u256,
        request_event: SocialRequest
    }

am not sure if this will work since SocialRequest will keep changing base on the event that was send.

vercel[bot] commented 1 month ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
joyboy ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2024 11:06am
joyboy-webapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 6, 2024 11:06am
mubarak23 commented 1 month ago

am getting the following error Unexpected argument type. Expected: "core::array::Array::<core::felt252>", found: "core::array::Span::<core::felt252>".

on this line

return self.is_valid_signature(tx_hash, signature); for signature field

mubarak23 commented 1 month ago

warning: Plugin diagnostic: Failed to generate ABI: __execute__ is a reserved entry point names for account contracts only.

 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:77:5
    #[external(v0)]
    ^*************^

error: Method is_zero not found on type core::starknet::contract_address::ContractAddress. Did you import the correct trait and impl?

 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:81:27
            assert(sender.is_zero(), 'Account: invalid caller');
                          ^*****^

error: Item core::starknet::call_contract_syscall is not visible in this context.


 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:95:46
                        let _res = starknet::call_contract_syscall(to, selector, calldata.span())
                                             ^*******************^

error: Method span could not be called on type core::array::Span::<core::felt252>. Candidate ArrayTrait::span inference failed with: Type mismatch: core::array::Span::<core::felt252> and @core::array::Array::<?7>


 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:95:91
                        let _res = starknet::call_contract_syscall(to, selector, calldata.span())
                                                                                          ^**^

error: Unexpected argument type. Expected: "core::array::Array::", found:

"core::array::Span::<core::felt252>".
 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:109:53
            return self.is_valid_signature(tx_hash, signature);
                                                    ^*******^

error: Function not found.

 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:119:30
            let byte_array = format_as_byte_array(hash, 16);
                             ^******************^

error: Identifier not found.

 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:121:36
            let verify_signature = bip340::verify(
                                   ^****^

warning: Unused variable. Consider ignoring by prefixing with _.

 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:117:17
            let public_key = self.public_key.read();
                ^********^

warning: Unused variable. Consider ignoring by prefixing with _.

 --> /home/runner/work/joyboy/joyboy/onchain/src/social/account.cairo:119:17
            let byte_array = format_as_byte_array(hash, 16);
                ^********^
maciejka commented 1 month ago

Did you manage to fix compilation errors?

mubarak23 commented 1 month ago

Did you manage to fix compilation errors?

no,

mubarak23 commented 1 month ago

call to this function,

return self.is_valid_signature(tx_hash, signature);

signature throw this error

core::array::Span:: ``

Unexpected argument type. Expected: "core::array::Array::", found: "core::array::Span::".

mubarak23 commented 1 month ago
Screenshot 2024-05-29 at 12 11 36
maciejka commented 1 month ago
Screenshot 2024-05-29 at 12 11 36

Please check if this will help: https://github.com/OpenZeppelin/cairo-contracts/blob/978b4e75209da355667d8954d2450e32bd71fe49/src/account/account.cairo#L282

mubarak23 commented 1 month ago
Screenshot 2024-05-29 at 12 11 36

Please check if this will help: https://github.com/OpenZeppelin/cairo-contracts/blob/978b4e75209da355667d8954d2450e32bd71fe49/src/account/account.cairo#L282

i understand their implementation,

it a bit different from my own,

from __validate__

am passing signature of type

core::array::Span::<core::felt252>

into

is_valid_signature

 fn is_valid_signature(
            self: @ContractState, hash: felt252, signature: Array<felt252>
        ) -> felt252 {}

is_valid_signature expect a type

core::array::Array::<core::felt252>

how do i convert signature of type
core::array::Span::<core::felt252>

to core::array::Array::<core::felt252>

before passing it into is_valid_signature function

mubarak23 commented 1 month ago

from this warning error

warn: Plugin diagnostic: Failed to generate ABI:executeis a reserved entry point names for account contracts only.

Does this mean we cannot use execute as function name

maciejka commented 1 month ago

Please let me know what is the status of this pr. Do you intend to complete it?

mubarak23 commented 1 month ago

Please let me know what is the status of this pr. Do you intend to complete it?

Yes,

maciejka commented 4 weeks ago

We will restart the work in another pr.