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

Solana (phantom wallet) support #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

XuJiandong
Copy link
Contributor

@XuJiandong XuJiandong commented Apr 11, 2024

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
  1. 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.
  2. During omnilock verification, the signature field of OmniLockWitnessLock is first obtained and parsed into two parts: signature(64 bytes) and pubkey(32 bytes).
  3. 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).
  4. 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.
  5. For the ed25519 message, signature, and pubkey, the ed25519 verify function is used. If the verification passes, the signature is successfully verified.

Other notes:

  • The blake160 hash is the leading 20 bytes of blake2b hash with personalization: "ckb-default-hash".
  • A Solana address is a straightforward base58 encoding of a 32-byte ed25519 public key. Unlike Bitcoin and Ethereum, no hashing is involved.
  • Unlike secp256k1, an ed25519 signature cannot independently recover the public key. Therefore, both the signature and an additional public key are required for validation.

@XuJiandong XuJiandong requested review from mohanson and joii2020 April 11, 2024 02:45
@XuJiandong
Copy link
Contributor Author

XuJiandong commented Apr 11, 2024

Pudge testnet deployment information:

parameter value
code_hash 0xf329effd1c475a2978453c8600e1eaf0bc2087ee093c3ee64cc96ec6847752cb
hash_type type
tx_hash 0xec18bf0d857c981c3d1f4e17999b9b90c484b303378e94de1a57b0872f5d4602
index 0x0
dep_type code

test_solana_wrong_auth
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

Successfully merging this pull request may close these issues.

3 participants