cryptape / omnilock

2 stars 4 forks source link

Solana (phantom wallet) support #6

Open XuJiandong opened 7 months ago

XuJiandong commented 7 months ago

This PR aims to add support for the Solana blockchain within Omnilock, with a specific focus on integrating with the Phantom wallet.

Overall procedure:

  1. After receiving the transaction (tx), the dApp calculates the signing message hash (32 bytes). It is sighash_all in omnilock.
  2. The dApp calls the API described at https://docs.phantom.app/solana/signing-a-message. The format of the signed string is as follows:
    CKB transaction: 0x<signing message hash, in hexadecimal format>

    For example:

    CKB transaction: 0xd3f012c170b17dc3af2287800a36326c115a82106ded34a05c925345007a988c
  3. The dApp combines the signature and pubkey together and fills in the signature field of OmniLockWitnessLock. The signature is 64 bytes, and the pubkey is 32 bytes, totaling 96 bytes. They have a specific order: the signature comes first, followed by the pubkey. Then, the dApp sends the tx to the p2p network.
  4. During omnilock verification, the signature field of OmniLockWitnessLock is first obtained and parsed into two parts: signature(64 bytes) and pubkey(32 bytes).
  5. The blake160 hash of the pubkey is verified to match the 20-byte auth content. In solana, the 32 bytes pubkey can be decoded from address via base58. Unlike other blockchains, it's not an pubkey hash and can't be fit into 20 bytes auth content. So there is an blake160 hash on pubkey. Solana auth id is 19(0x13).
  6. The omnilock calculates the signing message hash, converts it to hexadecimal format, and adds the prefix "CKB transaction: 0x ". This becomes the ed25519 message. Note that this message can be of any length and does not require hashing.
  7. For the ed25519 message, signature, and pubkey, the ed25519 verify function is used. If the verification passes, the signature is successfully verified.

Other notes:

XuJiandong commented 7 months ago
Pudge testnet deployment information: parameter value
code_hash 0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb
hash_type type
tx_hash 0xec18bf0d857c981c3d1f4e17999b9b90c484b303378e94de1a57b0872f5d4602
index 0x0
dep_type code