Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2927d17
feat: Added boilerpate code for constellation app
muzaffarbhat07 Mar 6, 2025
b9e9fe8
fix: Corrected constellation boilerplate code
muzaffarbhat07 Mar 6, 2025
5b0f6a7
fix: Constellation proto options
muzaffarbhat07 Mar 6, 2025
3e36ebc
fix: Code formatting
muzaffarbhat07 Mar 6, 2025
642d273
feat: Constellation generate pubkey and address
muzaffarbhat07 Mar 6, 2025
bb1679e
fix: Return uncompressed pubkey in constellation app
muzaffarbhat07 Mar 6, 2025
1a04b50
fix: Corrected constellatio generate address pseudo code
muzaffarbhat07 Mar 6, 2025
5ecaf1d
Merge pull request #628 from Cypherock/feat/constellation/pubkey-address
TejasvOnly Mar 8, 2025
32d223f
feat: Added sign txn functionality to constellation app
muzaffarbhat07 Mar 8, 2025
140c089
fix: Generalized constellation sign txn
muzaffarbhat07 Mar 17, 2025
2950811
fix: Removed unit from amount and fee
muzaffarbhat07 Mar 18, 2025
c472a6e
fix: Code formatting
muzaffarbhat07 Mar 18, 2025
dcdb3b3
fix: Resolve review comments
muzaffarbhat07 Mar 19, 2025
4cde2ed
feat: Added constellation blind signing
muzaffarbhat07 Mar 12, 2025
7c3074a
feat: Added constellation sign msg and data
muzaffarbhat07 Mar 15, 2025
248874e
fix: Resolved review comments
muzaffarbhat07 Mar 19, 2025
346843c
fix: Ci tests
muzaffarbhat07 Mar 19, 2025
26e3fe6
fix: Code formatting
muzaffarbhat07 Mar 19, 2025
5a29ae9
feat: Added constellation blind signing
muzaffarbhat07 Mar 12, 2025
1fc5b4a
feat: Added constellation sign msg and data
muzaffarbhat07 Mar 15, 2025
26be9b9
feat: Modified ending text of constellation
muzaffarbhat07 Mar 18, 2025
e7681a1
fix: Code formatting
muzaffarbhat07 Mar 18, 2025
8076fb5
fix: Code formatting
muzaffarbhat07 Mar 19, 2025
48e3f69
Merge pull request #631 from Cypherock/feat/constellation/sign-txn
muzaffarbhat07 Mar 20, 2025
49422a3
Merge pull request #632 from Cypherock/feat/constellation/sign-msg
muzaffarbhat07 Mar 22, 2025
bafea33
Merge pull request #633 from Cypherock/feat/constellation/ui-text-ending
muzaffarbhat07 Mar 22, 2025
99d6ebc
chore: Updated cypherock common submodule
muzaffarbhat07 May 22, 2025
be6784e
Merge branch 'release/0.6.2304+' into feat/constellation/base
muzaffarbhat07 May 22, 2025
9a42b4a
feat: Added swap functionality to constellation app
muzaffarbhat07 May 22, 2025
8f632d4
fix: Updated app versions count to allow more apps
muzaffarbhat07 May 22, 2025
8603b46
fix: Code formatting
muzaffarbhat07 May 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions apps/constellation_app/constellation_api.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/**
* @file constellation_api.c
* @author Cypherock X1 Team
* @brief Defines helpers apis for CONSTELLATION app.
* @copyright Copyright (c) 2025 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
*target=_blank>https://mitcc.org/</a>
*
******************************************************************************
* @attention
*
* (c) Copyright 2025 by HODL TECH PTE LTD
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
* to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*
* "Commons Clause" License Condition v1.0
*
* The Software is provided to you by the Licensor under the License,
* as defined below, subject to the following condition.
*
* Without limiting other conditions in the License, the grant of
* rights under the License will not include, and the License does not
* grant to you, the right to Sell the Software.
*
* For purposes of the foregoing, "Sell" means practicing any or all
* of the rights granted to you under the License to provide to third
* parties, for a fee or other consideration (including without
* limitation fees for hosting or consulting/ support services related
* to the Software), a product or service whose value derives, entirely
* or substantially, from the functionality of the Software. Any license
* notice or attribution required by the License must also include
* this Commons Clause License Condition notice.
*
* Software: All X1Wallet associated files.
* License: MIT
* Licensor: HODL TECH PTE LTD
*
******************************************************************************
*/

/*****************************************************************************
* INCLUDES
*****************************************************************************/

#include "constellation_api.h"

#include <pb_decode.h>
#include <pb_encode.h>

#include "common_error.h"
#include "core_api.h"
#include "events.h"

/*****************************************************************************
* EXTERN VARIABLES
*****************************************************************************/

/*****************************************************************************
* PRIVATE MACROS AND DEFINES
*****************************************************************************/

/*****************************************************************************
* PRIVATE TYPEDEFS
*****************************************************************************/

/*****************************************************************************
* STATIC VARIABLES
*****************************************************************************/

/*****************************************************************************
* GLOBAL VARIABLES
*****************************************************************************/

/*****************************************************************************
* STATIC FUNCTION PROTOTYPES
*****************************************************************************/

/*****************************************************************************
* STATIC FUNCTIONS
*****************************************************************************/

/*****************************************************************************
* GLOBAL FUNCTIONS
*****************************************************************************/
bool decode_constellation_query(const uint8_t *data,
uint16_t data_size,
constellation_query_t *query_out) {
if (NULL == data || NULL == query_out || 0 == data_size) {
constellation_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
ERROR_DATA_FLOW_DECODING_FAILED);
return false;
}

// zeroise for safety from garbage in the query reference
memzero(query_out, sizeof(constellation_query_t));

/* Create a stream that reads from the buffer. */
pb_istream_t stream = pb_istream_from_buffer(data, data_size);

/* Now we are ready to decode the message. */
bool status = pb_decode(&stream, CONSTELLATION_QUERY_FIELDS, query_out);

/* Send error to host if status is false*/
if (false == status) {
constellation_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
ERROR_DATA_FLOW_DECODING_FAILED);
}

return status;
}

bool encode_constellation_result(const constellation_result_t *result,
uint8_t *buffer,
uint16_t max_buffer_len,
size_t *bytes_written_out) {
if (NULL == result || NULL == buffer || NULL == bytes_written_out)
return false;

/* Create a stream that will write to our buffer. */
pb_ostream_t stream = pb_ostream_from_buffer(buffer, max_buffer_len);

/* Now we are ready to encode the message! */
bool status = pb_encode(&stream, CONSTELLATION_RESULT_FIELDS, result);

if (true == status) {
*bytes_written_out = stream.bytes_written;
}

return status;
}

bool check_constellation_query(const constellation_query_t *query,
pb_size_t exp_query_tag) {
if ((NULL == query) || (exp_query_tag != query->which_request)) {
constellation_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
ERROR_DATA_FLOW_INVALID_QUERY);
return false;
}
return true;
}

constellation_result_t init_constellation_result(pb_size_t result_tag) {
constellation_result_t result = CONSTELLATION_RESULT_INIT_ZERO;
result.which_response = result_tag;
return result;
}

void constellation_send_error(pb_size_t which_error, uint32_t error_code) {
constellation_result_t result =
init_constellation_result(CONSTELLATION_RESULT_COMMON_ERROR_TAG);
result.common_error = init_common_error(which_error, error_code);
constellation_send_result(&result);
}

void constellation_send_result(const constellation_result_t *result) {
// TODO: Set all option files
uint8_t buffer[1700] = {0};
size_t bytes_encoded = 0;
ASSERT(encode_constellation_result(
result, buffer, sizeof(buffer), &bytes_encoded));
send_response_to_host(&buffer[0], bytes_encoded);
}

bool constellation_get_query(constellation_query_t *query,
pb_size_t exp_query_tag) {
evt_status_t event = get_events(EVENT_CONFIG_USB, MAX_INACTIVITY_TIMEOUT);

if (true == event.p0_event.flag) {
return false;
}

if (!decode_constellation_query(
event.usb_event.p_msg, event.usb_event.msg_size, query)) {
return false;
}

if (!check_constellation_query(query, exp_query_tag)) {
return false;
}

return true;
}
119 changes: 119 additions & 0 deletions apps/constellation_app/constellation_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* @file constellation_api.h
* @author Cypherock X1 Team
* @brief Header file to export some helper functions for the CONSTELLATION
* app
* @copyright Copyright (c) 2025 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
* target=_blank>https://mitcc.org/</a>
*/
#ifndef CONSTELLATION_API_H
#define CONSTELLATION_API_H

/*****************************************************************************
* INCLUDES
*****************************************************************************/

#include <constellation/core.pb.h>
#include <stdint.h>

/*****************************************************************************
* MACROS AND DEFINES
*****************************************************************************/

/*****************************************************************************
* TYPEDEFS
*****************************************************************************/

/*****************************************************************************
* EXPORTED VARIABLES
*****************************************************************************/

/*****************************************************************************
* GLOBAL FUNCTION PROTOTYPES
*****************************************************************************/

/**
* @brief API to decode query from host with `CONSTELLATION_QUERY_FIELDS`
*
* @param[in] data: PB encoded bytestream received from host
* @param[in] data_size: size of pb encoded bytestream
* @param[out] query_out: @ref constellation_query_t obj to copy the decoded
* result to
* @return bool True if decoding was successful, else false
*/
bool decode_constellation_query(const uint8_t *data,
uint16_t data_size,
constellation_query_t *query_out);

/**
* @brief Encodes the CONSTELLATION result with `CONSTELLATION_RESULT_FIELDS` to
* byte-stream
*
* @param[in] result: object of populated @ref constellation_result_t to be
* encoded
* @param[out] buffer: buffer to fill byte-stream into
* @param[in] max_buffer_len: Max length allowed for writing bytestream to
* buffer
* @param[out] bytes_written_out: bytes written to bytestream
* @return bool True if decoding was successful, else false
*/
bool encode_constellation_result(const constellation_result_t *result,
uint8_t *buffer,
uint16_t max_buffer_len,
size_t *bytes_written_out);

/**
* @brief This API checks if the `which_request` field of the query of type
* `constellation_query_t` matches against the expected tag.
*
* @param query The query of type `constellation_query_t` to be checked
* @param exp_query_tag The expected tag of the query
* @return true If the query tag matches the expected tag
* @return false If the query tag does not match the expected tag
*/
bool check_constellation_query(const constellation_query_t *query,
pb_size_t exp_query_tag);

/**
* @brief Returns zero initialized object of type
* constellation_result_t result_tag set in result.which_response field
*
* @param result_tag Result tag to be set in the constellation_result_t result
* @return constellation_result_t Result object of type constellation_result_t
*/
constellation_result_t init_constellation_result(pb_size_t result_tag);

/**
* @brief Send the error to the host.
*
* @param which_error The error type to be sent
* @param error_code The error code to sent to the host
*/
void constellation_send_error(pb_size_t which_error, uint32_t error_code);

/**
* @brief This API encodes constellation_result_t in protobuf structure.
* @details If the encoding is successful, then it sends the corresponding
* result to the host.
*
* The function ASSERTs the result of encode_constellation_result internally.
*
* @param result The result which needs to be sent to the host.
*/
void constellation_send_result(const constellation_result_t *result);

/**
* @brief This API receives request of type constellation_query_t of type
* exp_query_tag from the host.
*
* @param query The reference to which the query needs to be populated
* @param exp_query_tag The expected tag of the query
* @return true If the query was recieved from the host matching the tag
* @return false If the request timed out or the recieved request did not match
* the tag
*/
bool constellation_get_query(constellation_query_t *query,
pb_size_t exp_query_tag);

#endif
63 changes: 63 additions & 0 deletions apps/constellation_app/constellation_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* @file constellation_context.h
* @author Cypherock X1 Team
* @brief Header file defining typedefs and MACROS for the CONSTELLATION app
* @copyright Copyright (c) 2025 HODL TECH PTE LTD
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
* target=_blank>https://mitcc.org/</a>
*/
#ifndef CONSTELLATION_CONTEXT_H
#define CONSTELLATION_CONTEXT_H

/*****************************************************************************
* INCLUDES
*****************************************************************************/
#include <stdbool.h>
#include <stdint.h>

/*****************************************************************************
* MACROS AND DEFINES
*****************************************************************************/
#define CONSTELLATION_NAME "CONSTELLATION"
#define CONSTELLATION_LUNIT "DAG"

#define CONSTELLATION_IMPLICIT_ACCOUNT_DEPTH 5

#define CONSTELLATION_PURPOSE_INDEX 0x8000002C // 44'
#define CONSTELLATION_COIN_INDEX 0x80000000 + 1137 // 1137'
#define CONSTELLATION_ACCOUNT_INDEX 0x80000000 // 0'
#define CONSTELLATION_CHANGE_INDEX 0x00000000 // 0

#define CONSTELLATION_PUB_KEY_SIZE 65
#define CONSTELLATION_ACCOUNT_ADDRESS_SIZE 40
#define PKCS_PREFIX_SIZE 23
#define PKCS_PREFIXED_PUBKEY_SIZE PKCS_PREFIX_SIZE + CONSTELLATION_PUB_KEY_SIZE
#define SHA256_DIGEST_SIZE 32
#define BS58_ENCODED_SIZE 45
#define CONSTELLATION_TXN_HASH_LENGTH 64
#define CONSTELLATION_SIGN_MSG_PREFIX_LENGTH 31
#define CONSTELLATION_SIGN_DATA_PREFIX_LENGTH 28

#define MAX_ALLOWED_SIZE 20480

/**
* TODO: update the size of msg data same as MAX_ALLOWED_SIZE.
* Constraints : The LVGL buffer cannot handle more than 3Kb data size which
* puts a limit on how much data can be displayed on the device. Possible fix is
* to show the long messages in chunks in line with max LVGL buffer size.
*/
#define MAX_MSG_DATA_SIZE 3072

/*****************************************************************************
* TYPEDEFS
*****************************************************************************/

/*****************************************************************************
* EXPORTED VARIABLES
*****************************************************************************/

/*****************************************************************************
* GLOBAL FUNCTION PROTOTYPES
*****************************************************************************/

#endif /* CONSTELLATION_CONTEXT_H */
Loading