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

cli: add serialize-transfer and execute-signed-tx commands #5345

Merged
merged 2 commits into from
Oct 20, 2022
Merged

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Oct 17, 2022

Add two cli command (serialize-transfer-sui at Step 1 and execute-signed-tx at Step 3). This is useful if the user just want to serialize the data with CLI and take the signing offline somewhere else (wallet of your choice, or tools in other languages). And come back with a signed transaction just to execute it.

This is useful for us to ensure serialization consistency btw ts-sdk and rust.

Step 1: Serialize the Data

target/debug/sui client serialize-transfer-sui --to 0x581a119a6576d3b502b5dc47c5de497b774e68ca --sui-coin-object-id 0x0599b794da39169f7c75d34eba06ae105fedc61b --gas-budget 1000
VHJhbnNhY3Rpb25EYXRhOjoAA1gaEZpldtO1ArXcR8XeSXt3TmjKAFgaEZpldtO1ArXcR8XeSXt3TmjKBZm3lNo5Fp98ddNOugauEF/txhsCAAAAAAAAACC0knjIoZEdbQBQuqg3feG/GA0L2v9gLDfH2uX8iGf5SwEAAAAAAAAA6AMAAAAAAAA=

Step 2: Sign the data

This can be done elsewhere in your signing device of your choice, here uses the keytool command as a PoC.

target/debug/sui keytool sign --address 0x581a119a6576d3b502b5dc47c5de497b774e68ca --data VHJhbnNhY3Rpb25EYXRhOjoAA1gaEZpldtO1ArXcR8XeSXt3TmjKAFgaEZpldtO1ArXcR8XeSXt3TmjKBZm3lNo5Fp98ddNOugauEF/txhsCAAAAAAAAACC0knjIoZEdbQBQuqg3feG/GA0L2v9gLDfH2uX8iGf5SwEAAAAAAAAA6AMAAAAAAAA=
2022-10-18T03:30:39.510775Z  INFO sui::keytool: Data to sign : VHJhbnNhY3Rpb25EYXRhOjoAA1gaEZpldtO1ArXcR8XeSXt3TmjKAFgaEZpldtO1ArXcR8XeSXt3TmjKBZm3lNo5Fp98ddNOugauEF/txhsCAAAAAAAAACC0knjIoZEdbQBQuqg3feG/GA0L2v9gLDfH2uX8iGf5SwEAAAAAAAAA6AMAAAAAAAA=
2022-10-18T03:30:39.510838Z  INFO sui::keytool: Address : 0x581a119a6576d3b502b5dc47c5de497b774e68ca
2022-10-18T03:30:39.511304Z  INFO sui::keytool: Flag Base64: AA==
2022-10-18T03:30:39.511318Z  INFO sui::keytool: Public Key Base64: rJzjxQ+FCK9m8YDU8Dq1Yx931HkIArhcw33kUPL9P8c=
2022-10-18T03:30:39.511326Z  INFO sui::keytool: Signature : epIttAjg4OBOzVBQQuMflR9sJwh12XiBFwDV9gmiBxomKJ0YyjcbhLONdvA1xs2NXy8xdagwHR/uRVdI6z+LAg==

Step 3: Execute the tx with its data and signature that it committed to

target/debug/sui client execute-signed-tx --tx-data VHJhbnNhY3Rpb25EYXRhOjoAA1gaEZpldtO1ArXcR8XeSXt3TmjKAFgaEZpldtO1ArXcR8XeSXt3TmjKBZm3lNo5Fp98ddNOugauEF/txhsCAAAAAAAAACC0knjIoZEdbQBQuqg3feG/GA0L2v9gLDfH2uX8iGf5SwEAAAAAAAAA6AMAAAAAAAA= --scheme ed25519 --pubkey rJzjxQ+FCK9m8YDU8Dq1Yx931HkIArhcw33kUPL9P8c= --signature epIttAjg4OBOzVBQQuMflR9sJwh12XiBFwDV9gmiBxomKJ0YyjcbhLONdvA1xs2NXy8xdagwHR/uRVdI6z+LAg==
----- Certificate ----
Transaction Hash: wnk9u71q8mhPgEOrDZJacVyqAzNBAmsMOPM4rNoS0LE=
Transaction Signature: AA==@epIttAjg4OBOzVBQQuMflR9sJwh12XiBFwDV9gmiBxomKJ0YyjcbhLONdvA1xs2NXy8xdagwHR/uRVdI6z+LAg==@rJzjxQ+FCK9m8YDU8Dq1Yx931HkIArhcw33kUPL9P8c=
Signed Authorities Bitmap: RoaringBitmap<[0, 1, 3]>
Transaction Kind : Transfer SUI
Recipient : 0x581a119a6576d3b502b5dc47c5de497b774e68ca
Amount: Full Balance

----- Transaction Effects ----
Status : Success
Mutated Objects:
  - ID: 0x0599b794da39169f7c75d34eba06ae105fedc61b , Owner: Account Address ( 0x581a119a6576d3b502b5dc47c5de497b774e68ca )

@joyqvq joyqvq force-pushed the util-cli branch 2 times, most recently from ae3ab72 to 3998342 Compare October 18, 2022 03:16
@joyqvq joyqvq changed the title cli: add print-serialize-data option to transfer and transfer-sui cli: add serialize-transfer and execute-signed-tx commands Oct 18, 2022
@joyqvq joyqvq marked this pull request as ready for review October 18, 2022 03:38
Copy link
Contributor

@huitseeker huitseeker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM! regarding maintenability, I was wondering if we had an integration test covering the CLI, in the style of https://docs.rs/assert_cli/latest/assert_cli/index.html

Indeed, I'm afraid of us breaking this tool inadvertently by changing the transaction format. assert_cli is really easy to use and would offer some protection against this I expect. I'd highly encourage adding a basic test of those 2 commands.

@joyqvq joyqvq enabled auto-merge (squash) October 20, 2022 00:59
@joyqvq joyqvq disabled auto-merge October 20, 2022 14:19
@joyqvq joyqvq enabled auto-merge (squash) October 20, 2022 14:20
@joyqvq joyqvq merged commit 84b6f1e into main Oct 20, 2022
@joyqvq joyqvq deleted the util-cli branch October 20, 2022 14:57
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.

2 participants