Skip to content

Added Off Chain message signing - #30

Open
AntekWozniakBlocky wants to merge 31 commits into
developfrom
off-chain-signing-v4
Open

Added Off Chain message signing#30
AntekWozniakBlocky wants to merge 31 commits into
developfrom
off-chain-signing-v4

Conversation

@AntekWozniakBlocky

@AntekWozniakBlocky AntekWozniakBlocky commented Mar 24, 2025

Copy link
Copy Markdown
Collaborator

Checklist

  • App update process has been followed
  • Target branch is develop
  • Application version has been bumped

Comment thread libsol/parser.c Outdated
Comment thread libsol/include/sol/transaction_summary.h Outdated
Comment thread src/ui/sign_message_nbgl.c Outdated
#include <stdbool.h>

bool is_data_utf8(const uint8_t *data, size_t length);
bool is_data_ascii(const uint8_t *data, size_t length); No newline at end of file

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That util functions are required for parsing off chain payload

Comment thread libsol/parser.c
"\xff" \
"solana offchain"

static int check_buffer_length(Parser *parser, size_t num) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved out to common_byte_strings.h

item->title = title;
item->application_domain = value;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

New item required for showing app domain

Comment thread src/globals.h
#define MAX_OFFCHAIN_MESSAGE_LENGTH PACKET_DATA_SIZE

// Assuming that only one signer
#define OFFCHAIN_MESSAGE_HEADER_LENGTH 85

@AntekWozniakBlocky AntekWozniakBlocky Mar 27, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is 85 (16+1+32+1+1+32*1+2)
sign domain + version + app domain + format + signer count + signer pub keys + length

Comment thread src/globals.h
#define CASSERT(predicate, file) _impl_CASSERT_LINE(predicate, __LINE__, file)
#define _impl_PASTE(a, b) a##b
#define _impl_CASSERT_LINE(predicate, line, file) \
typedef char _impl_PASTE(assertion_failed_##file##_, line)[2 * !!(predicate) -1];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Macros required for off chain message signing logic

Comment thread src/handle_sign_message.c
return get_pubkey_index(&signer_pubkey,
header->pubkeys,
header->pubkeys_header.num_required_signatures,
signer_index);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Refactored version of the same function

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Core of Off Chain Message Signing

Comment thread src/utils.c
}
return -1;
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Helper function, moved out from other parts of code for readability

else:
raise ValueError()

if len(message) <= MAX_LEN:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed the length check because the Ledger should handle that, instead of comparing it in the tests.

data += self.version.to_bytes(1, byteorder='little')
# Include padded app_domain
data += self.app_domain
# Serialize message

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added missing fields

OFFCHAIN_MESSAGE_APPLICATION_DOMAIN_LENGTH,
G_transaction_summary_text,
TEXT_BUFFER_LENGTH));
break;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Handling new item type

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