Skip to content

Commit

Permalink
Fix suffix message
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Jul 29, 2024
1 parent 6d13d3c commit 14e239e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion contracts/ccc-sol-lock/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn message_wrap(msg: &str) -> String {
assert_eq!(msg.len(), 64);
// Text used to signify that a signed message follows and to prevent inadvertently signing a transaction.
const CKB_PREFIX: &str = "Signing a CKB transaction: 0x";
const CKB_SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected SOL wallet before signing this message\n";
const CKB_SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected Solana wallet before signing this message\n";
[CKB_PREFIX, msg, CKB_SUFFIX].join("")
}

Expand Down
2 changes: 1 addition & 1 deletion docs/sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The corresponding witness must be a proper `WitnessArgs` data structure in molec

The following bytes are verified:

"Signing a CKB transaction: 0x{sigh_hash}\n\nIMPORTANT: Please verify the integrity and authenticity of connected SOL wallet before signing this message\n"
"Signing a CKB transaction: 0x{sigh_hash}\n\nIMPORTANT: Please verify the integrity and authenticity of connected Solana wallet before signing this message\n"

The `{sighasl_all}` is replaced by `sighash_all` in hexadecimal string, with length 64. The string in the last part can be displayed in wallet UIs.

Expand Down
8 changes: 4 additions & 4 deletions tests/src/test_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn message_wrap(msg: &str) -> String {
assert_eq!(msg.len(), 64);
// Text used to signify that a signed message follows and to prevent inadvertently signing a transaction.
const CKB_PREFIX: &str = "Signing a CKB transaction: 0x";
const CKB_SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected SOL wallet before signing this message\n";
const CKB_SUFFIX: &str = "\n\nIMPORTANT: Please verify the integrity and authenticity of connected Solana wallet before signing this message\n";
[CKB_PREFIX, msg, CKB_SUFFIX].join("")
}

Expand Down Expand Up @@ -154,15 +154,15 @@ fn test_success_e2e() {
// 2. Import account with private key AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFMtav2rXn79au8yvzCadhc0mUe1LiFtYafJBrt8KW6KQ==
// 3. Open F12
// 4. Run msg = new TextEncoder().encode('Signing a CKB transaction: 0x62b23cebc0c020f433f97cb6f018883b793f5e9777db4
// d34736a0c5df004ead5\n\nIMPORTANT: Please verify the integrity and authenticity of connected SOL wallet bef
// ore signing this message\n');
// d34736a0c5df004ead5\n\nIMPORTANT: Please verify the integrity and authenticity of connected Solana wallet
// before signing this message\n');
// 5. Run sig = await phantom.solana.signMessage(msg, 'utf8');
// 6. Run sig.signature.toString('hex')

let wa = ckb_types::packed::WitnessArgs::new_unchecked(tx.witnesses().get_unchecked(0).raw_data());
let mut wa_lock = wa.lock().to_opt().unwrap().raw_data().to_vec();
wa_lock.copy_from_slice(
&hex::decode("7e4beceaef78790a33e783d2411bf4f86f7cee767aefdc6f33ec9c275b8370077f53cfd11ea1a76329318c10abf0de86989f8d07efc9ccc8aa8b50fc13758103").unwrap()
&hex::decode("df1fc2d71c4a5d4a74ea3673a0b85fc0e683e48bc8b4cc343f7656c404a5aa315c19df47fc8a414b2be8a41c315d0424a3e0f56554fd5030de3a1ed6706b7509").unwrap()
);
let wa = wa.as_builder().lock(Some(ckb_types::bytes::Bytes::from(wa_lock)).pack()).build();
let tx = tx.as_advanced_builder().set_witnesses(vec![wa.as_bytes().pack()]).build();
Expand Down

0 comments on commit 14e239e

Please sign in to comment.