Skip to content

Commit a543623

Browse files
Merge pull request #669 from Cypherock/develop
Develop
2 parents daa8393 + 6891fe0 commit a543623

35 files changed

Lines changed: 2789 additions & 66 deletions

.github/workflows/build.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ jobs:
1515
matrix:
1616
firmware: [Main]
1717
target: [Release]
18+
vendor: [Cypherock, Odix]
1819
uses: ./.github/workflows/containerized-build.yml
1920
with:
2021
firmware: ${{ matrix.firmware }}
2122
target: ${{ matrix.target }}
23+
vendor: ${{ matrix.vendor }}
2224
secrets: inherit
2325
create-release:
2426
needs: build-firmwares
@@ -37,16 +39,18 @@ jobs:
3739
auth_token: ${{ secrets.GITHUB_TOKEN }}
3840
REPOSITORY: ${{ github.repository }}
3941
run: |
40-
chkmain=$(sha256sum Main-Release-outputs/Cypherock-Main.bin | cut -f -1 -d ' ')
42+
chkmain=$(sha256sum Main-Release-Cypherock-outputs/Cypherock-Main.bin | cut -f -1 -d ' ')
43+
chkmain_odix=$(sha256sum Main-Release-Odix-outputs/Cypherock-Main-Odix.bin | cut -f -1 -d ' ')
4144
APP_VERSION=$(cat version.txt | grep firmware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
4245
HW_VERSION=$(cat version.txt | grep hardware | cut -f 2-2 -d '=' | awk -F ':' '{ print 0+$1 "." 0+$2 "." $3*2**8 + $4 }')
4346
echo ${APP_VERSION}:${HW_VERSION}
44-
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt
47+
curl -X POST -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/${REPOSITORY}/releases -d '{"tag_name":"'${TAG_NAME}'","target_commitish":"main","name":"'${TAG_NAME}'","body":"Application version: '${APP_VERSION}'\r\nHardware version: '${HW_VERSION}'\r\n## SHA256 of binaries:\r\n**Cypherock-Main.bin** : '${chkmain}' \r\n**Cypherock-Main-Odix.bin** : '${chkmain_odix}'","draft":true,"prerelease":false,"generate_release_notes":true}' > output.txt
4548
echo "upload_url=$(cat output.txt | grep "\"upload_url\":" | cut -f 4-4 -d '"' | cut -f 1-1 -d '{')" >> $GITHUB_ENV
4649
- name: Upload assets
4750
env:
4851
auth_token: ${{ secrets.GITHUB_TOKEN }}
4952
run: |
50-
content_type=$(file -b --mime-type Main-Release-outputs/Cypherock-Main.bin)
51-
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-outputs/Cypherock-Main.bin
53+
content_type=$(file -b --mime-type Main-Release-Cypherock-outputs/Cypherock-Main.bin)
54+
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main.bin --data-binary @Main-Release-Cypherock-outputs/Cypherock-Main.bin
55+
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=Cypherock-Main-Odix.bin --data-binary @Main-Release-Odix-outputs/Cypherock-Main-Odix.bin
5256
curl -X POST -H "Content-Type: ${content_type}" -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${auth_token}" -H "X-GitHub-Api-Version: 2022-11-28" ${upload_url}?name=version.txt --data-binary @version.txt

.github/workflows/containerized-build.yml

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,34 @@ on:
99
target:
1010
required: true
1111
type: string
12+
vendor:
13+
required: true
14+
default: "Cypherock"
15+
type: string
1216

1317
jobs:
1418
build:
1519
runs-on: ubuntu-latest
1620
container:
1721
image: cypherock/x1-firmware-builder:v0.0.0
1822
steps:
19-
- name: Build Firmware (${{ inputs.firmware }} - ${{ inputs.target }})
20-
run: |
21-
if [[ "${{ github.ref_type }}" == "tag" ]]; then
22-
export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')
23-
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
24-
export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')
25-
else
26-
# reftype is repository; use default branch
27-
export VERSION_TAG=main
28-
fi
29-
git clone --branch ${VERSION_TAG} --depth 1 https://github.com/${{ github.repository }}.git --recurse-submodules
30-
mkdir build && cd x1_wallet_firmware && mkdir build && cd build
31-
cmake -DCMAKE_BUILD_TYPE="${{ inputs.target }}" -DFIRMWARE_TYPE="${{ inputs.firmware }}" -DCMAKE_BUILD_PLATFORM="Device" -G "Ninja" ..
32-
ninja && cd ../..
33-
cp x1_wallet_firmware/build/Cypherock-*.* ./build/
34-
- name: Archive Build Artifacts
35-
uses: actions/upload-artifact@v4
36-
with:
37-
name: ${{ inputs.firmware }}-${{ inputs.target }}-outputs
38-
path: build
23+
- name: Build Firmware (${{ inputs.firmware }} - ${{ inputs.target }})
24+
run: |
25+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
26+
export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')
27+
elif [[ "${{ github.ref_type }}" == "branch" ]]; then
28+
export VERSION_TAG=$(echo "${{ github.ref }}" | cut -f 3- -d '/')
29+
else
30+
# reftype is repository; use default branch
31+
export VERSION_TAG=main
32+
fi
33+
git clone --branch ${VERSION_TAG} --depth 1 https://github.com/${{ github.repository }}.git --recurse-submodules
34+
mkdir build && cd x1_wallet_firmware && mkdir build && cd build
35+
cmake -DCMAKE_BUILD_TYPE="${{ inputs.target }}" -DFIRMWARE_TYPE="${{ inputs.firmware }}" -DCMAKE_BUILD_PLATFORM="Device" -DVENDOR="${{ inputs.vendor }}" -G "Ninja" ..
36+
ninja && cd ../..
37+
cp x1_wallet_firmware/build/Cypherock-*.* ./build/
38+
- name: Archive Build Artifacts
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: ${{ inputs.firmware }}-${{ inputs.target }}-${{ inputs.vendor }}-outputs
42+
path: build

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ else()
1313
set(PROJECT Cypherock_Simulator)
1414
endif()
1515

16+
# Replace this with actual vendors
17+
if ("${VENDOR}" STREQUAL "Odix")
18+
add_compile_definitions(VENDOR_NAME="Odix Wallet")
19+
add_compile_definitions(VENDOR_COMPANION_APP="Odix")
20+
add_compile_definitions(VENDOR_DEVICE_NAME="Odix Wallet")
21+
add_compile_definitions(VENDOR_COMPANY_NAME"Odix")
22+
set(PROJECT ${PROJECT}-Odix)
23+
add_compile_definitions(VENDOR_ID=1)
24+
else()
25+
add_compile_definitions(VENDOR_NAME="Cypherock X1 Wallet")
26+
add_compile_definitions(VENDOR_COMPANION_APP="cySync")
27+
add_compile_definitions(VENDOR_DEVICE_NAME="Cypherock X1")
28+
add_compile_definitions(VENDOR_COMPANY_NAME"Cypherock")
29+
add_compile_definitions(VENDOR_ID=0)
30+
endif()
31+
1632
project(${PROJECT})
1733

1834
# python is needed for compiling proto files using nanopb
@@ -56,4 +72,4 @@ target_include_directories( ${EXECUTABLE} PRIVATE vendor/nanopb generated/proto
5672

5773
# Enable support for dynamically allocated fields in nanopb
5874
# Ref: vendor/nanopb/pb.h
59-
add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1)
75+
add_compile_definitions(PB_ENABLE_MALLOC=1 PB_NO_ERRMSG=1)

apps/stellar_app/stellar_api.c

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
/**
2+
* @file stellar_api.c
3+
* @author Cypherock X1 Team
4+
* @brief Defines helpers apis for Stellar app.
5+
* @copyright Copyright (c) 2025 HODL TECH PTE LTD
6+
* <br/> You may obtain a copy of license at <a href="https://mitcc.org/"
7+
*target=_blank>https://mitcc.org/</a>
8+
*
9+
******************************************************************************
10+
* @attention
11+
*
12+
* (c) Copyright 2025 by HODL TECH PTE LTD
13+
*
14+
* Permission is hereby granted, free of charge, to any person obtaining
15+
* a copy of this software and associated documentation files (the
16+
* "Software"), to deal in the Software without restriction, including
17+
* without limitation the rights to use, copy, modify, merge, publish,
18+
* distribute, sublicense, and/or sell copies of the Software, and to
19+
* permit persons to whom the Software is furnished to do so, subject
20+
* to the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be
23+
* included in all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
29+
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
30+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
*
33+
*
34+
* "Commons Clause" License Condition v1.0
35+
*
36+
* The Software is provided to you by the Licensor under the License,
37+
* as defined below, subject to the following condition.
38+
*
39+
* Without limiting other conditions in the License, the grant of
40+
* rights under the License will not include, and the License does not
41+
* grant to you, the right to Sell the Software.
42+
*
43+
* For purposes of the foregoing, "Sell" means practicing any or all
44+
* of the rights granted to you under the License to provide to third
45+
* parties, for a fee or other consideration (including without
46+
* limitation fees for hosting or consulting/ support services related
47+
* to the Software), a product or service whose value derives, entirely
48+
* or substantially, from the functionality of the Software. Any license
49+
* notice or attribution required by the License must also include
50+
* this Commons Clause License Condition notice.
51+
*
52+
* Software: All X1Wallet associated files.
53+
* License: MIT
54+
* Licensor: HODL TECH PTE LTD
55+
*
56+
******************************************************************************
57+
*/
58+
59+
/*****************************************************************************
60+
* INCLUDES
61+
*****************************************************************************/
62+
63+
#include "stellar_api.h"
64+
65+
#include <pb_decode.h>
66+
#include <pb_encode.h>
67+
68+
#include "common_error.h"
69+
#include "core_api.h"
70+
#include "events.h"
71+
72+
/*****************************************************************************
73+
* EXTERN VARIABLES
74+
*****************************************************************************/
75+
76+
/*****************************************************************************
77+
* PRIVATE MACROS AND DEFINES
78+
*****************************************************************************/
79+
80+
/*****************************************************************************
81+
* PRIVATE TYPEDEFS
82+
*****************************************************************************/
83+
84+
/*****************************************************************************
85+
* STATIC VARIABLES
86+
*****************************************************************************/
87+
88+
/*****************************************************************************
89+
* GLOBAL VARIABLES
90+
*****************************************************************************/
91+
92+
/*****************************************************************************
93+
* STATIC FUNCTION PROTOTYPES
94+
*****************************************************************************/
95+
96+
/*****************************************************************************
97+
* STATIC FUNCTIONS
98+
*****************************************************************************/
99+
100+
/*****************************************************************************
101+
* GLOBAL FUNCTIONS
102+
*****************************************************************************/
103+
bool decode_stellar_query(const uint8_t *data,
104+
uint16_t data_size,
105+
stellar_query_t *query_out) {
106+
if (NULL == data || NULL == query_out || 0 == data_size) {
107+
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
108+
ERROR_DATA_FLOW_DECODING_FAILED);
109+
return false;
110+
}
111+
112+
// zeroise for safety from garbage in the query reference
113+
memzero(query_out, sizeof(stellar_query_t));
114+
115+
/* Create a stream that reads from the buffer. */
116+
pb_istream_t stream = pb_istream_from_buffer(data, data_size);
117+
118+
/* Now we are ready to decode the message. */
119+
bool status = pb_decode(&stream, STELLAR_QUERY_FIELDS, query_out);
120+
121+
/* Send error to host if status is false*/
122+
if (false == status) {
123+
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
124+
ERROR_DATA_FLOW_DECODING_FAILED);
125+
}
126+
127+
return status;
128+
}
129+
130+
bool encode_stellar_result(const stellar_result_t *result,
131+
uint8_t *buffer,
132+
uint16_t max_buffer_len,
133+
size_t *bytes_written_out) {
134+
if (NULL == result || NULL == buffer || NULL == bytes_written_out)
135+
return false;
136+
137+
/* Create a stream that will write to our buffer. */
138+
pb_ostream_t stream = pb_ostream_from_buffer(buffer, max_buffer_len);
139+
140+
/* Now we are ready to encode the message! */
141+
bool status = pb_encode(&stream, STELLAR_RESULT_FIELDS, result);
142+
143+
if (true == status) {
144+
*bytes_written_out = stream.bytes_written;
145+
}
146+
147+
return status;
148+
}
149+
150+
bool check_stellar_query(const stellar_query_t *query,
151+
pb_size_t exp_query_tag) {
152+
if ((NULL == query) || (exp_query_tag != query->which_request)) {
153+
stellar_send_error(ERROR_COMMON_ERROR_CORRUPT_DATA_TAG,
154+
ERROR_DATA_FLOW_INVALID_QUERY);
155+
return false;
156+
}
157+
return true;
158+
}
159+
160+
stellar_result_t init_stellar_result(pb_size_t result_tag) {
161+
stellar_result_t result = STELLAR_RESULT_INIT_ZERO;
162+
result.which_response = result_tag;
163+
return result;
164+
}
165+
166+
void stellar_send_error(pb_size_t which_error, uint32_t error_code) {
167+
stellar_result_t result =
168+
init_stellar_result(STELLAR_RESULT_COMMON_ERROR_TAG);
169+
result.common_error = init_common_error(which_error, error_code);
170+
stellar_send_result(&result);
171+
}
172+
173+
void stellar_send_result(const stellar_result_t *result) {
174+
// TODO: Set all option files
175+
uint8_t buffer[1700] = {0};
176+
size_t bytes_encoded = 0;
177+
ASSERT(encode_stellar_result(result, buffer, sizeof(buffer), &bytes_encoded));
178+
send_response_to_host(&buffer[0], bytes_encoded);
179+
}
180+
181+
bool stellar_get_query(stellar_query_t *query, pb_size_t exp_query_tag) {
182+
evt_status_t event = get_events(EVENT_CONFIG_USB, MAX_INACTIVITY_TIMEOUT);
183+
184+
if (true == event.p0_event.flag) {
185+
return false;
186+
}
187+
188+
if (!decode_stellar_query(
189+
event.usb_event.p_msg, event.usb_event.msg_size, query)) {
190+
return false;
191+
}
192+
193+
if (!check_stellar_query(query, exp_query_tag)) {
194+
return false;
195+
}
196+
197+
return true;
198+
}

0 commit comments

Comments
 (0)