-
Notifications
You must be signed in to change notification settings - Fork 0
Add remote-wallet crate for talking to hardware wallets #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8f7c24c
395fcde
4f83e6c
62668f4
882c732
f7fe013
1f885e2
1a2063e
8a5afbb
7559cee
4c0f635
d100800
7bc0abf
6b3f88d
dc5983f
c3c3288
9d88ad4
5cfec67
0f7e9fd
7be429d
9aa73c2
35844ea
7893c02
607efda
2ca30e9
94812e3
1e56b5c
45cd867
ce404ee
28ca5c2
276bbfc
e704fe4
3527c51
761cc8d
7dab526
bdfedbf
bbb7a1f
acfe2de
aebb77c
1cd4e61
f443041
e529a7f
d003cbc
312d74d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# spacemesh-sdk | ||
Low-level Rust SDK | ||
|
||
This repository contains a low-level Rust SDK for the Spacemesh protocol and associated tooling. Various crates implement utilities such as key derivation and communication with Ledger hardware wallets (see inline Rust documentation for more information). Certain functions are externalized via Wasm bindings and CFFI bindings for use in upstream applications including [Smapp](https://github.com/spacemeshos/smapp/) and [Smcli](https://github.com/spacemeshos/smcli). | ||
|
||
See the Github workflow files for information on how to build on various platforms as a dynamic or static library. | ||
|
||
Portions of the codebase are forked from [Solana](https://github.com/solana-labs/solana/) with gratitude. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
|
||
|
||
language = "C++" | ||
language = "C" | ||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this header file required to be written by hand? I think https://github.com/spacemeshos/post-rs generates the C headers when it builds the library, maybe @poszu can help here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the question. It's not written by hand. There's a makefile recipe for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah my bad. It seems like https://github.com/spacemeshos/post-rs also generates the headers using a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why check it in the repo though? Cbindgen can be used with
The header is later bundled together with the library in release artifacts: https://github.com/spacemeshos/post-rs/blob/fbf1b886253beec659527262499d1392490ea14d/.github/workflows/ci.yml#L155-L162 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no strong opinion. personally I kind of like manually regenerating it, and being alerted when it changes. |
||
|
||
#include <cstdarg> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <ostream> | ||
#include <new> | ||
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
|
||
|
||
extern "C" { | ||
|
||
/// derive_c generates a keypair from a 64-byte BIP39-compatible seed and BIP32 hierarchical | ||
/// derivation path. it returns 64 bytes. the first 32 bytes are the secret key and the second 32 | ||
/// bytes are the public key. | ||
/// this function does the same thing as derive_key, which is bound for wasm rather than CFFI. | ||
/// it adds error handling in order to be friendlier to the FFI caller: in case of an error, it | ||
/// prints the error and returns a null pointer. | ||
/// note that the caller must call derive_free_c() to free the returned memory as ownership is | ||
/// transferred to the caller. | ||
uint8_t *derive_c(const uint8_t *seed, size_t seedlen, const uint8_t *path, size_t pathlen); | ||
|
||
/// free the memory allocated and returned by the derive functions by transferring ownership back to | ||
/// Rust. must be called on each pointer returned by the functions precisely once to ensure safety. | ||
void derive_free_c(uint8_t *ptr); | ||
|
||
} // extern "C" | ||
/** | ||
* derive_c generates a keypair from a 64-byte BIP39-compatible seed and BIP32 hierarchical | ||
* derivation path. It writes the keypair bytes to result, which must be at least 64 bytes long. | ||
* It returns a status code, with a return value of zero indicating success. | ||
* This function does the same thing as derive_key, which is bound for wasm rather than CFFI. | ||
* it adds error handling in order to be friendlier to the FFI caller: in case of an error, it | ||
* prints the error and returns a nonzero value. | ||
*/ | ||
uint16_t derive_c(const uint8_t *seed, | ||
size_t seedlen, | ||
const char *derivation_path_ptr, | ||
uint8_t *result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the rpath issue on macOS this file I think needs the following configuration:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacemeshos/smkeys#6 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to go ahead and merge without this. If it's still causing issues we can open a new PR to fix it (as you did with #5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if related but I created a new issue: #12