forked from LedgerHQ/app-hedera
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhedera.c
More file actions
54 lines (44 loc) · 1.62 KB
/
Copy pathhedera.c
File metadata and controls
54 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "hedera.h"
#include <cx.h>
#include <os.h>
#include <string.h>
#include "crypto_helpers.h"
#include "utils.h"
#include <stddef.h>
#include <stdbool.h>
// Constructs the fixed Hedera derivation path: m/44'/3030'/0'/0'/index'
// Used for transaction signing and public key operations
// Only the index parameter varies; all other path components are hardcoded
static void hedera_set_path(uint32_t index, uint32_t path[static 5]) {
path[0] = PATH_ZERO; // 44'
path[1] = PATH_ONE; // 3030'
path[2] = PATH_TWO; // 0'
path[3] = PATH_THREE; // 0'
path[4] = PATH_FOUR; // index'
}
bool hedera_get_pubkey(uint32_t index, uint8_t raw_pubkey[static RAW_PUBKEY_SIZE]) {
uint32_t path[5];
hedera_set_path(index, path);
if (CX_OK != bip32_derive_with_seed_get_pubkey_256(
HDW_ED25519_SLIP10, CX_CURVE_Ed25519, path, 5, raw_pubkey,
NULL, CX_SHA512, NULL, 0)) {
return false;
}
return true;
}
bool hedera_sign(uint32_t index, const uint8_t* tx, uint8_t tx_len,
/* out */ uint8_t* result, /* out */ size_t* sig_len_out) {
uint32_t path[5];
size_t sig_len = 64;
hedera_set_path(index, path);
if (CX_OK != bip32_derive_with_seed_eddsa_sign_hash_256(
HDW_ED25519_SLIP10, CX_CURVE_Ed25519, path, 5, CX_SHA512,
tx, // hash (really message)
tx_len, // hash length (really message length)
result, // signature
&sig_len, NULL, 0)) {
return false;
}
if (sig_len_out) *sig_len_out = sig_len;
return true;
}