Skip to content

Added Off Chain message signing#30

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

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

Conversation

@AntekWozniakBlocky
Copy link
Collaborator

@AntekWozniakBlocky AntekWozniakBlocky commented Mar 24, 2025

Checklist

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

#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
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

"\xff" \
"solana offchain"

static int check_buffer_length(Parser *parser, size_t num) {
Copy link
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
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

#define MAX_OFFCHAIN_MESSAGE_LENGTH PACKET_DATA_SIZE

// Assuming that only one signer
#define OFFCHAIN_MESSAGE_HEADER_LENGTH 85
Copy link
Collaborator Author

@AntekWozniakBlocky AntekWozniakBlocky Mar 27, 2025

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

#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
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

return get_pubkey_index(&signer_pubkey,
header->pubkeys,
header->pubkeys_header.num_required_signatures,
signer_index);
Copy link
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
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

}
return -1;
}

Copy link
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
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
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
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