Lay2 - pw-sdk - Build DApps on CKB and Run Them Everywhere

UPDATE: Checkpoint 3 Completed

First let’s recall the goals of Checkpoint 3

The original version is:

And we submitted a proposal to change that into:

The detailed consideration of changing the objective is explained in the above post, and so far this proposal has not received any opposition, so we’ll proceed with the new objectives.

pw-lib

To support EOS, we need SHA-256 hash algorithm on CKB, which has already been achieved in checkpoint 2 as a bonus.

pw-lock

Things are different now, because we have 3 address formats instead of 1. To identify them, we add a 1-byte mark in front of the 65-byte witness:

Witnesses[0].lock: [FLAG | Witness]
/* 
FLAG BYTE:
0x01 - ETH
0x02 - EOS
0x03 - Tron
*/

In the actual code:

if(lock_bytes_seg.size == SIGNATURE_SIZE){
    // backward compatible with old witness format
    *chain_id = 1;
    memcpy(lock_bytes, lock_bytes_seg.ptr, SIGNATURE_SIZE);
  }else{
    // get the flag byte in new format
    memcpy(chain_id, lock_bytes_seg.ptr, 1);
    memcpy(lock_bytes, (lock_bytes_seg.ptr + 1), SIGNATURE_SIZE);
  }

More changes for adapting the 2 new blockchains will be addressed in our review call.

As we already put pw-lock on main-net and it affects a lot of assets now, we won’t change the master branch unless the code is solid enough. So we put the new features in a new branch feature_eostron, which can be found here:

https://github.com/lay2dev/pw-lock/tree/feature_eostron

pw-core

Thanks to the flexible design of pw-core, it’s simple to add support for EOS and Tron. What we need to do is:

  • Add 2 new Providers: EosProvider and TronProvider, which will use scatterjs and tronWeb to retrive addresses from the outside providers.
  • Add 2 new Signers: EosSigner and TronSigner.
  • Add 2 new Address types, and adjust the logic of methods for new formats.
  • Adjust witness format to add flag byte in front of original witness

Also we add a new branch instead of directly update the master branch of pw-core, even all changes are backward compatible. You can find the code here:

https://github.com/lay2dev/pw-core/tree/feature_eostron

bonus

Yes, we have a demo for you to try out :stuck_out_tongue:

https://pw-eostron-demo.vercel.app/

Open it with EOS and Tron env then you can see your CKB address mapped from new blockchains.

You can aquire testnet CKB from the facuet of Aggron testnet, and the link is in the Demo page.

Souce code of the demo:

4 Likes