feat: support ton contract init#139
Conversation
Signed-off-by: Lu1zz <yu.lu@onekey.so>
WalkthroughThis update adds three new optional fields to the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant ton_sign_message
participant User
participant Signer
Caller->>ton_sign_message: Call with TonSignMessage
alt init_data_initial_chunk present
ton_sign_message->>ton_sign_message: Check signing_message_repr presence
alt signing_message_repr missing
ton_sign_message-->>Caller: Send failure, return false
else signing_message_repr present
ton_sign_message->>ton_sign_message: Compute SHA-256 of signing_message_repr
ton_sign_message->>User: Prompt for blind sign confirmation
alt User cancels
ton_sign_message-->>Caller: Send failure, return false
else User confirms
ton_sign_message->>Signer: Sign digest
ton_sign_message-->>Caller: Return signature and digest, return true
end
end
else
ton_sign_message->>ton_sign_message: Continue with original signing logic
end
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (3)
common/protob/messages-ton.proto(1 hunks)legacy/firmware/protob/messages-ton.options(1 hunks)legacy/firmware/ton.c(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Defs check
- GitHub Check: Gen check
- GitHub Check: Style check
🔇 Additional comments (3)
legacy/firmware/protob/messages-ton.options (1)
19-20: Size limits set appropriately.Setting 1024-byte limits for both new fields prevents buffer overflows.
legacy/firmware/ton.c (2)
172-187: Security for blind signing is properly implemented.The code correctly:
- Computes SHA-256 hash of the message
- Prompts user for confirmation
- Handles rejection appropriately
This ensures user consent before signing.
189-196: Signing implementation handles both emulator and device scenarios.Code correctly uses different signing methods based on environment.
Signed-off-by: Lu1zz <yu.lu@onekey.so>
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
common/protob/messages-ton.proto (1)
72-74: Improve field documentation.The new fields need clearer comments explaining their purpose and content.
Consider adding more descriptive comments to clarify:
- What
init_data_initial_chunkcontains- How
init_data_lengthrelates to the chunk- Whether
signing_message_repris a hash or raw datalegacy/firmware/ton.c (1)
200-202: Fix the typo in field name.There's an extra 'n' in
signning_message. This appears throughout the codebase.-resp->signning_message.size = 32; -memcpy(resp->signning_message.bytes, digest, resp->signning_message.size); -resp->has_signning_message = true; +resp->signing_message.size = 32; +memcpy(resp->signing_message.bytes, digest, resp->signing_message.size); +resp->has_signing_message = true;Note: This requires similar fixes elsewhere in the codebase and message definitions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (3)
common/protob/messages-ton.proto(1 hunks)legacy/firmware/protob/messages-ton.options(1 hunks)legacy/firmware/ton.c(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Style check
- GitHub Check: Gen check
- GitHub Check: Defs check
🔇 Additional comments (2)
legacy/firmware/protob/messages-ton.options (1)
19-20: Size constraints look good.The 1024-byte limits for both new fields are reasonable for contract initialization data.
legacy/firmware/ton.c (1)
165-171: Check logic makes sense but field usage is unclear.The validation correctly requires both fields together. However,
init_data_initial_chunkis never actually used in the logic.Add a comment explaining why
init_data_initial_chunkis checked but not used, or implement the missing logic to handle the chunk data.
Summary by CodeRabbit