Skip to content

Commit

Permalink
add more platforms and update sigma-rust dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Alesfatalis committed May 3, 2024
1 parent 3214e9a commit 8d3a161
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
os: [ubuntu-latest, macos-13, macos-14, windows-latest]

steps:
- uses: actions/checkout@v3
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ This library makes heavy use of cgo. A set of precompiled shared library objects
<tr>
<td><code>aarch64</code></td>
<td><code>aarch64-apple-darwin</code></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Windows</td>
<td><code>amd64</code></td>
<td><code>x86_64-pc-windows-gnu</code></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Expand All @@ -75,7 +75,8 @@ This library makes heavy use of cgo. A set of precompiled shared library objects
### Library
The libraries under `lib` were compiled from `sigma-rust` with the following commands:
```
cross build -p ergo-lib-c --release --target x86_64-apple-darwin
cargo build -p ergo-lib-c --release --target x86_64-apple-darwin
cargo build -p ergo-lib-c --release --target x86_64-apple-darwin
cross build -p ergo-lib-c --release --target x86_64-unknown-linux-gnu
cross build -p ergo-lib-c --release --target aarch64-unknown-linux-gnu
cross build -p ergo-lib-c --release --target x86_64-pc-windows-gnu
Expand Down
2 changes: 1 addition & 1 deletion cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package ergo
// #cgo linux,arm64 LDFLAGS: -Wl,-rpath,${SRCDIR}/packaged/lib/linux-aarch64 -L${SRCDIR}/packaged/lib/linux-aarch64 -lm
// #cgo windows,amd64 LDFLAGS: -Wl,-rpath,${SRCDIR}/packaged/lib/windows-amd64 -L${SRCDIR}/packaged/lib/windows-amd64 -lbcrypt
// #cgo darwin,amd64 LDFLAGS: -Wl,-rpath,${SRCDIR}/packaged/lib/darwin-amd64 -L${SRCDIR}/packaged/lib/darwin-amd64
// //#cgo darwin,arm64 LDFLAGS: -Wl,-rpath,${SRCDIR}/packaged/lib/darwin-aarch64 -L${SRCDIR}/packaged/lib/darwin-aarch64
// #cgo darwin,arm64 LDFLAGS: -Wl,-rpath,${SRCDIR}/packaged/lib/darwin-aarch64 -L${SRCDIR}/packaged/lib/darwin-aarch64
//
// #include <ergo.h>
import "C"
Expand Down
115 changes: 111 additions & 4 deletions packaged/include/ergo.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ typedef struct Contract Contract;
*/
typedef struct DataInput DataInput;

typedef struct DerivationPath DerivationPath;

/**
* Ergo box, that is taking part in some transaction on the chain Differs with [`ErgoBoxCandidate`]
* by added transaction id and an index in the input of that transaction
Expand Down Expand Up @@ -175,6 +177,8 @@ typedef struct ErgoTree ErgoTree;

typedef struct Error Error;

typedef struct ExtPubKey ExtPubKey;

typedef struct ExtSecretKey ExtSecretKey;

/**
Expand Down Expand Up @@ -466,6 +470,10 @@ typedef const struct Collection_DataInput *ConstCollectionPtr_DataInput;

typedef ConstCollectionPtr_DataInput ConstDataInputsPtr;

typedef struct DerivationPath *DerivationPathPtr;

typedef const struct DerivationPath *ConstDerivationPathPtr;

typedef struct ErgoBoxAssetsData *ErgoBoxAssetsDataPtr;

typedef const struct ErgoBoxAssetsData *ConstErgoBoxAssetsDataPtr;
Expand Down Expand Up @@ -512,10 +520,16 @@ typedef const struct ErgoStateContext *ConstErgoStateContextPtr;

typedef const struct PreHeader *ConstPreHeaderPtr;

typedef const struct ExtPubKey *ConstExtPubKeyPtr;

typedef struct ExtPubKey *ExtPubKeyPtr;

typedef const struct ExtSecretKey *ConstExtSecretKeyPtr;

typedef struct ExtSecretKey *ExtSecretKeyPtr;

typedef struct SecretKey *SecretKeyPtr;

typedef struct HintsBag *HintsBagPtr;

typedef const struct CommitmentHint *ConstCommitmentHintPtr;
Expand Down Expand Up @@ -622,8 +636,6 @@ typedef struct CompletionCallback {
typedef struct RequestHandle *RequestHandlePtr;
#endif

typedef struct SecretKey *SecretKeyPtr;

typedef const struct SecretKey *ConstSecretKeyPtr;

typedef struct Collection_SecretKey *CollectionPtr_SecretKey;
Expand Down Expand Up @@ -1128,6 +1140,43 @@ void ergo_lib_delete_error(ErrorPtr error);

void ergo_lib_delete_string(char *ptr);

/**
* Drop `DerivationPath`
*/
void ergo_lib_derivation_path_delete(DerivationPathPtr ptr);

/**
* Returns the length of the derivation path
*/
uintptr_t ergo_lib_derivation_path_depth(ConstDerivationPathPtr derivation_path_ptr);

/**
* Create derivation path from string
* String should be in the form of: m/44/429/acc'/0/addr
*/
ErrorPtr ergo_lib_derivation_path_from_str(const char *derivation_path_str,
DerivationPathPtr *derivation_path_out);

/**
* Create DerivationPath from account index and address indices
*/
ErrorPtr ergo_lib_derivation_path_new(uint32_t account,
const uint32_t *address_indices,
uintptr_t len,
DerivationPathPtr *derivation_path_out);

/**
* Returns a new derivation path with the last element of the derivation path being increased, e.g. m/1/2 -> m/1/3
*/
ErrorPtr ergo_lib_derivation_path_next(ConstDerivationPathPtr derivation_path_ptr,
DerivationPathPtr *derivation_path_out);

/**
* Get derivation path as string in the m/44/429/acc'/0/addr format
*/
void ergo_lib_derivation_path_to_str(ConstDerivationPathPtr derivation_path_ptr,
const char **_derivation_path_str);

/**
* Drop `ErgoBoxAssetsData`
*/
Expand Down Expand Up @@ -1536,6 +1585,40 @@ ErrorPtr ergo_lib_ergo_tree_with_constant(ConstErgoTreePtr ergo_tree_ptr,

char *ergo_lib_error_to_string(ErrorPtr error);

/**
* Get address for extended public key
*/
void ergo_lib_ext_pub_key_address(ConstExtPubKeyPtr ext_pub_key_ptr, AddressPtr *address_out);

/**
* Derive a new extended public key from the provided index
* The index is in the form of soft or hardened indices
* For example: 4 or 4' respectively
*/
ErrorPtr ergo_lib_ext_pub_key_child(ConstExtPubKeyPtr derive_from_key_ptr,
uint32_t child_index,
ExtPubKeyPtr *ext_pub_key_out);

/**
* Drop `ExtPubKey`
*/
void ergo_lib_ext_pub_key_delete(ExtPubKeyPtr ptr);

/**
* Derive a new extended public key from the derivation path
*/
ErrorPtr ergo_lib_ext_pub_key_derive(ConstExtPubKeyPtr ext_pub_key_ptr,
ConstDerivationPathPtr derivation_path_ptr,
ExtPubKeyPtr *ext_pub_key_out);

/**
* Create ExtPubKey from public key bytes, chain code and derivation path
*/
ErrorPtr ergo_lib_ext_pub_key_new(const uint8_t *public_key_bytes,
const uint8_t *chain_code_ptr,
ConstDerivationPathPtr derivation_path_ptr,
ExtPubKeyPtr *ext_pub_key_out);

/**
* Derive a new extended secret key from the provided index
* The index is in the form of soft or hardened indices
Expand All @@ -1550,21 +1633,45 @@ ErrorPtr ergo_lib_ext_secret_key_child(ConstExtSecretKeyPtr secret_key_bytes_ptr
*/
void ergo_lib_ext_secret_key_delete(ExtSecretKeyPtr ptr);

/**
* Derive a new extended secret key from the derivation path
*/
ErrorPtr ergo_lib_ext_secret_key_derive(ConstExtSecretKeyPtr ext_secret_key_ptr,
ConstDerivationPathPtr derivation_path_ptr,
ExtSecretKeyPtr *ext_secret_key_out);

/**
* Derive root extended secret key from seed bytes
*/
ErrorPtr ergo_lib_ext_secret_key_derive_master(const uint8_t *seed,
ExtSecretKeyPtr *ext_secret_key_out);

/**
* Get secret key for extended secret key
*/
void ergo_lib_ext_secret_key_get_secret_key(ConstExtSecretKeyPtr ext_secret_key_ptr,
SecretKeyPtr *secret_key_out);

/**
* Create ExtSecretKey from secret key bytes, chain code and derivation path
* Derivation path should be a string in the form of: m/44/429/acc'/0/addr
*/
ErrorPtr ergo_lib_ext_secret_key_new(const uint8_t *secret_key_bytes_ptr,
const uint8_t *chain_code_ptr,
const char *derivation_path_str,
ConstDerivationPathPtr derivation_path_ptr,
ExtSecretKeyPtr *ext_secret_key_out);

/**
* Get derivation path for extended secret key
*/
void ergo_lib_ext_secret_key_path(ConstExtSecretKeyPtr ext_secret_key_ptr,
DerivationPathPtr *derivation_path_out);

/**
* The extended public key associated with this secret key
*/
void ergo_lib_ext_secret_key_public_key(ConstExtSecretKeyPtr ext_secret_key_ptr,
ExtPubKeyPtr *ext_pub_key_out);

/**
* Add commitment hint to the bag
*/
Expand Down
2 changes: 2 additions & 0 deletions packaged/lib/darwin-aarch64/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://github.com/golang/go/issues/26366.
package darwin_aarch64
Binary file added packaged/lib/darwin-aarch64/libergo.a
Binary file not shown.
Binary file modified packaged/lib/darwin-amd64/libergo.a
Binary file not shown.
1 change: 1 addition & 0 deletions packaged/lib/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package lib

import (
_ "github.com/sigmaspace-io/ergo-lib-go/packaged/lib/darwin-aarch64"
_ "github.com/sigmaspace-io/ergo-lib-go/packaged/lib/darwin-amd64"
_ "github.com/sigmaspace-io/ergo-lib-go/packaged/lib/linux-aarch64"
_ "github.com/sigmaspace-io/ergo-lib-go/packaged/lib/linux-amd64"
Expand Down
Binary file modified packaged/lib/linux-aarch64/libergo.a
Binary file not shown.
Binary file modified packaged/lib/linux-amd64/libergo.a
Binary file not shown.
Binary file modified packaged/lib/windows-amd64/libergo.a
Binary file not shown.

0 comments on commit 8d3a161

Please sign in to comment.