diff --git a/libindy_vdr/include/README.md b/libindy_vdr/include/README.md index ae9e59dc..b271f0a8 100644 --- a/libindy_vdr/include/README.md +++ b/libindy_vdr/include/README.md @@ -1,15 +1,33 @@ _Generating the C header:_ -Install [cbindgen](https://github.com/eqrion/cbindgen/): + +1. use `nightly` instead of `stable` + +```sh +rustup default nightly +``` +> **Note**: If you run into _'unknown feature'_ issues by using latest nightly, force it to 1.72.0 by executing: `rustup default nightly-2023-06-15` + +2. Install [cbindgen](https://github.com/eqrion/cbindgen/) ```sh cargo install cbindgen ``` -From the `libindy_vdr` directory, generate the header file: +3. Install [cargo expand](https://github.com/dtolnay/cargo-expand) + +```sh +cargo install cargo-expand +``` + +4. Generate the header file: ```sh -cbindgen --config include/cbindgen.toml --crate indy-vdr --output include/libindy_vdr.h +cbindgen --config libindy_vdr/include/cbindgen.toml --crate indy-vdr --lockfile Cargo.lock --output libindy_vdr/include/libindy_vdr.h ``` -Note that a few types are currently defined manually, such as `ByteBuffer`, because of limitations in the binding generator. +5. Copy to React Native: + +```sh +cp libindy_vdr/include/libindy_vdr.h wrappers/javascript/indy-vdr-react-native/cpp/include/ +``` diff --git a/libindy_vdr/include/cbindgen.toml b/libindy_vdr/include/cbindgen.toml index 99ab80c5..8ec622ba 100644 --- a/libindy_vdr/include/cbindgen.toml +++ b/libindy_vdr/include/cbindgen.toml @@ -1,151 +1,15 @@ -# This is a template cbindgen.toml file with all of the default values. -# Some values are commented out because their absence is the real default. -# -# See https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml -# for detailed documentation of every option here. - - - language = "C" cpp_compat = true - -############## Options for Wrapping the Contents of the Header ################# - -# header = "/* Text to put at the beginning of the generated file. Probably a license. */" -# trailer = "/* Text to put at the end of the generated file */" -# include_guard = "my_bindings_h" -# pragma_once = true -# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" -include_version = false -# namespace = "my_namespace" -namespaces = [] -using_namespaces = [] -sys_includes = [] -includes = [] -no_includes = false -after_includes = "" - - - - -############################ Code Style Options ################################ - -braces = "SameLine" -line_length = 100 -tab_width = 2 -documentation = true -documentation_style = "auto" -# documentation_length = "full" -line_endings = "LF" # also "CR", "CRLF", "Native" - - - - -############################# Codegen Options ################################## - -style = "both" -sort_by = "Name" # default for `fn.sort_by` and `const.sort_by` +pragma_once = true +autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" +include_version = true usize_is_size_t = true - - - -[defines] -# "target_os = freebsd" = "DEFINE_FREEBSD" -# "feature = serde" = "DEFINE_SERDE" -"feature = rich_schema" = "DEFINE_RICH_SCHEMA" -"test" = "DEFINE_TEST" - -[export] -include = [] -exclude = [] -# prefix = "CAPI_" -item_types = [] -renaming_overrides_prefixing = false - - - -[export.rename] - - -[export.body] - - -[export.mangle] - - -[fn] -rename_args = "None" -# must_use = "MUST_USE_FUNC" -# no_return = "NO_RETURN" -# prefix = "START_FUNC" -# postfix = "END_FUNC" -args = "auto" -sort_by = "Name" - - - - -[struct] -rename_fields = "None" -# must_use = "MUST_USE_STRUCT" -derive_constructor = false -derive_eq = false -derive_neq = false -derive_lt = false -derive_lte = false -derive_gt = false -derive_gte = false - - - - -[enum] -rename_variants = "None" -# must_use = "MUST_USE_ENUM" -add_sentinel = false -prefix_with_name = false -derive_helper_methods = false -derive_const_casts = false -derive_mut_casts = false -# cast_assert_name = "ASSERT" -derive_tagged_enum_destructor = false -derive_tagged_enum_copy_constructor = false -enum_class = true -private_default_tagged_enum_constructor = false - - - - -[const] -allow_static_const = true -allow_constexpr = false sort_by = "Name" - - - -[macro_expansion] -bitflags = false - - - - - - -############## Options for How Your Rust library Should Be Parsed ############## - [parse] parse_deps = true -include = ["ffi-support"] -exclude = [] -clean = false -extra_bindings = [] - - +include = ["ffi-support", "ffi"] [parse.expand] -crates = [] -all_features = false -default_features = true -features = [] +crates = ["indy-vdr"] \ No newline at end of file diff --git a/libindy_vdr/include/libindy_vdr.h b/libindy_vdr/include/libindy_vdr.h index 86b131a5..902ffb8f 100644 --- a/libindy_vdr/include/libindy_vdr.h +++ b/libindy_vdr/include/libindy_vdr.h @@ -1,11 +1,29 @@ +#pragma once + +/* Generated with cbindgen:0.24.5 */ + +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ + #include #include #include #include #include +/** + * No (enforced) self-certification + */ +#define CERT_DEFAULT 0 -#define DEFAULT 0 +/** + * Self-certification based on did:indy method spec + */ +#define CERT_DID_INDY 2 + +/** + * Legacy self-certification + */ +#define CERT_DID_SOV 1 #define DEFAULT_ACK_TIMEOUT 20 @@ -19,9 +37,13 @@ #define DEFAULT_REQUEST_READ_NODES 2 -#define DID_INDY 2 +#define ROLE_ENDORSER 101 + +#define ROLE_NETWORK_MONITOR 201 -#define DID_SOV 1 +#define ROLE_STEWARD 2 + +#define ROLE_TRUSTEE 0 enum ErrorCode #ifdef __cplusplus @@ -290,20 +312,6 @@ ErrorCode indy_vdr_build_get_revoc_reg_request(FfiStr submitter_did, int64_t timestamp, RequestHandle *handle_p); -#if (defined(DEFINE_RICH_SCHEMA) || defined(DEFINE_TEST)) -ErrorCode indy_vdr_build_get_rich_schema_object_by_id_request(FfiStr submitter_did, - FfiStr rs_id, - RequestHandle *handle_p); -#endif - -#if (defined(DEFINE_RICH_SCHEMA) || defined(DEFINE_TEST)) -ErrorCode indy_vdr_build_get_rich_schema_object_by_metadata_request(FfiStr submitter_did, - FfiStr rs_type, - FfiStr rs_name, - FfiStr rs_version, - RequestHandle *handle_p); -#endif - ErrorCode indy_vdr_build_get_schema_request(FfiStr submitter_did, FfiStr schema_id, RequestHandle *handle_p); @@ -370,17 +378,6 @@ ErrorCode indy_vdr_build_revoc_reg_entry_request(FfiStr submitter_did, FfiStr revoc_reg_entry, RequestHandle *handle_p); -#if (defined(DEFINE_RICH_SCHEMA) || defined(DEFINE_TEST)) -ErrorCode indy_vdr_build_rich_schema_request(FfiStr submitter_did, - FfiStr rs_id, - FfiStr rs_content, - FfiStr rs_name, - FfiStr rs_version, - FfiStr rs_type, - FfiStr ver, - RequestHandle *handle_p); -#endif - ErrorCode indy_vdr_build_schema_request(FfiStr submitter_did, FfiStr schema, RequestHandle *handle_p); @@ -408,11 +405,15 @@ ErrorCode indy_vdr_pool_get_status(PoolHandle pool_handle, CallbackId cb_id); ErrorCode indy_vdr_pool_get_transactions(PoolHandle pool_handle, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); ErrorCode indy_vdr_pool_get_verifiers(PoolHandle pool_handle, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); ErrorCode indy_vdr_pool_refresh(PoolHandle pool_handle, @@ -423,12 +424,16 @@ ErrorCode indy_vdr_pool_submit_action(PoolHandle pool_handle, RequestHandle request_handle, FfiStr nodes, int32_t timeout, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); ErrorCode indy_vdr_pool_submit_request(PoolHandle pool_handle, RequestHandle request_handle, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); /** @@ -482,6 +487,19 @@ ErrorCode indy_vdr_set_protocol_version(int64_t version); ErrorCode indy_vdr_set_socks_proxy(FfiStr socks_proxy); +/** + * Public destructor for strings managed by the other side of the FFI. + * + * # Safety + * + * This will free the string pointer it gets passed in as an argument, + * and thus can be wildly unsafe if misused. + * + * See the documentation of `ffi_support::destroy_c_string` and + * `ffi_support::define_string_destructor!` for further info. + */ +void indy_vdr_string_free(char *s); + char *indy_vdr_version(void); #ifdef __cplusplus diff --git a/wrappers/javascript/.gitignore b/wrappers/javascript/.gitignore index 4e03ba3c..852b83eb 100644 --- a/wrappers/javascript/.gitignore +++ b/wrappers/javascript/.gitignore @@ -48,3 +48,4 @@ react-native/android/gradle* **/build **/native/mobile +genesis.txn diff --git a/wrappers/javascript/indy-vdr-react-native/cpp/include/libindy_vdr.h b/wrappers/javascript/indy-vdr-react-native/cpp/include/libindy_vdr.h index 7bdc47e1..902ffb8f 100644 --- a/wrappers/javascript/indy-vdr-react-native/cpp/include/libindy_vdr.h +++ b/wrappers/javascript/indy-vdr-react-native/cpp/include/libindy_vdr.h @@ -1,11 +1,29 @@ #pragma once +/* Generated with cbindgen:0.24.5 */ + +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ + #include #include #include #include #include +/** + * No (enforced) self-certification + */ +#define CERT_DEFAULT 0 + +/** + * Self-certification based on did:indy method spec + */ +#define CERT_DID_INDY 2 + +/** + * Legacy self-certification + */ +#define CERT_DID_SOV 1 #define DEFAULT_ACK_TIMEOUT 20 @@ -19,6 +37,14 @@ #define DEFAULT_REQUEST_READ_NODES 2 +#define ROLE_ENDORSER 101 + +#define ROLE_NETWORK_MONITOR 201 + +#define ROLE_STEWARD 2 + +#define ROLE_TRUSTEE 0 + enum ErrorCode #ifdef __cplusplus : int64_t @@ -36,11 +62,27 @@ enum ErrorCode PoolNoConsensus = 30, PoolRequestFailed = 31, PoolTimeout = 32, + Resolver = 9, }; #ifndef __cplusplus typedef int64_t ErrorCode; #endif // __cplusplus +/** + * The Indy Node communication protocol version + */ +enum ProtocolVersion +#ifdef __cplusplus + : int64_t +#endif // __cplusplus + { + Node1_3 = 1, + Node1_4 = 2, +}; +#ifndef __cplusplus +typedef int64_t ProtocolVersion; +#endif // __cplusplus + /** * `FfiStr<'a>` is a safe (`#[repr(transparent)]`) wrapper around a * nul-terminated `*const c_char` (e.g. a C string). Conceptually, it is @@ -180,6 +222,8 @@ typedef struct ByteBuffer { uint8_t *data; } ByteBuffer; + + #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -197,6 +241,19 @@ ErrorCode indy_vdr_build_attrib_request(FfiStr submitter_did, FfiStr enc, RequestHandle *handle_p); +ErrorCode indy_vdr_build_auth_rule_request(FfiStr submitter_did, + FfiStr txn_type, + FfiStr action, + FfiStr field, + FfiStr old_value, + FfiStr new_value, + FfiStr constraint, + RequestHandle *handle_p); + +ErrorCode indy_vdr_build_auth_rules_request(FfiStr submitter_did, + FfiStr rules, + RequestHandle *handle_p); + ErrorCode indy_vdr_build_cred_def_request(FfiStr submitter_did, FfiStr cred_def, RequestHandle *handle_p); @@ -216,14 +273,28 @@ ErrorCode indy_vdr_build_get_attrib_request(FfiStr submitter_did, FfiStr raw, FfiStr hash, FfiStr enc, + int32_t seq_no, + int64_t timestamp, RequestHandle *handle_p); +ErrorCode indy_vdr_build_get_auth_rule_request(FfiStr submitter_did, + FfiStr auth_type, + FfiStr auth_action, + FfiStr field, + FfiStr old_value, + FfiStr new_value, + RequestHandle *handle_p); + ErrorCode indy_vdr_build_get_cred_def_request(FfiStr submitter_did, FfiStr cred_def_id, RequestHandle *handle_p); +ErrorCode indy_vdr_build_get_frozen_ledgers_request(FfiStr identifier, RequestHandle *handle_p); + ErrorCode indy_vdr_build_get_nym_request(FfiStr submitter_did, FfiStr dest, + int32_t seq_no, + int64_t timestamp, RequestHandle *handle_p); ErrorCode indy_vdr_build_get_revoc_reg_def_request(FfiStr submitter_did, @@ -241,20 +312,6 @@ ErrorCode indy_vdr_build_get_revoc_reg_request(FfiStr submitter_did, int64_t timestamp, RequestHandle *handle_p); -#if (defined(DEFINE_RICH_SCHEMA) || defined(DEFINE_TEST)) -ErrorCode indy_vdr_build_get_rich_schema_object_by_id_request(FfiStr submitter_did, - FfiStr rs_id, - RequestHandle *handle_p); -#endif - -#if (defined(DEFINE_RICH_SCHEMA) || defined(DEFINE_TEST)) -ErrorCode indy_vdr_build_get_rich_schema_object_by_metadata_request(FfiStr submitter_did, - FfiStr rs_type, - FfiStr rs_name, - FfiStr rs_version, - RequestHandle *handle_p); -#endif - ErrorCode indy_vdr_build_get_schema_request(FfiStr submitter_did, FfiStr schema_id, RequestHandle *handle_p); @@ -270,6 +327,15 @@ ErrorCode indy_vdr_build_get_txn_request(FfiStr submitter_did, ErrorCode indy_vdr_build_get_validator_info_request(FfiStr submitter_did, RequestHandle *handle_p); +ErrorCode indy_vdr_build_ledgers_freeze_request(FfiStr identifier, + FfiStr ledgers_ids, + RequestHandle *handle_p); + +ErrorCode indy_vdr_build_node_request(FfiStr identifier, + FfiStr dest, + FfiStr data, + RequestHandle *handle_p); + ErrorCode indy_vdr_build_nym_request(FfiStr submitter_did, FfiStr dest, FfiStr verkey, @@ -279,6 +345,29 @@ ErrorCode indy_vdr_build_nym_request(FfiStr submitter_did, int32_t version, RequestHandle *handle_p); +ErrorCode indy_vdr_build_pool_config_request(FfiStr identifier, + int8_t writes, + int8_t force, + RequestHandle *handle_p); + +ErrorCode indy_vdr_build_pool_restart_request(FfiStr identifier, + FfiStr action, + FfiStr datetime, + RequestHandle *handle_p); + +ErrorCode indy_vdr_build_pool_upgrade_request(FfiStr identifier, + FfiStr name, + FfiStr version, + FfiStr action, + FfiStr sha256, + int32_t timeout, + FfiStr schedule, + FfiStr justification, + int8_t reinstall, + int8_t force, + FfiStr package, + RequestHandle *handle_p); + ErrorCode indy_vdr_build_revoc_reg_def_request(FfiStr submitter_did, FfiStr revoc_reg_def, RequestHandle *handle_p); @@ -289,17 +378,6 @@ ErrorCode indy_vdr_build_revoc_reg_entry_request(FfiStr submitter_did, FfiStr revoc_reg_entry, RequestHandle *handle_p); -#if (defined(DEFINE_RICH_SCHEMA) || defined(DEFINE_TEST)) -ErrorCode indy_vdr_build_rich_schema_request(FfiStr submitter_did, - FfiStr rs_id, - FfiStr rs_content, - FfiStr rs_name, - FfiStr rs_version, - FfiStr rs_type, - FfiStr ver, - RequestHandle *handle_p); -#endif - ErrorCode indy_vdr_build_schema_request(FfiStr submitter_did, FfiStr schema, RequestHandle *handle_p); @@ -311,6 +389,11 @@ ErrorCode indy_vdr_build_txn_author_agreement_request(FfiStr submitter_did, int64_t retirement_ts, RequestHandle *handle_p); +ErrorCode indy_vdr_dereference(PoolHandle pool_handle, + FfiStr did_url, + void (*cb)(int64_t cb_id, ErrorCode err, const char *response), + int64_t cb_id); + ErrorCode indy_vdr_get_current_error(const char **error_json_p); ErrorCode indy_vdr_pool_close(PoolHandle pool_handle); @@ -322,11 +405,15 @@ ErrorCode indy_vdr_pool_get_status(PoolHandle pool_handle, CallbackId cb_id); ErrorCode indy_vdr_pool_get_transactions(PoolHandle pool_handle, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); ErrorCode indy_vdr_pool_get_verifiers(PoolHandle pool_handle, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); ErrorCode indy_vdr_pool_refresh(PoolHandle pool_handle, @@ -337,12 +424,16 @@ ErrorCode indy_vdr_pool_submit_action(PoolHandle pool_handle, RequestHandle request_handle, FfiStr nodes, int32_t timeout, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); ErrorCode indy_vdr_pool_submit_request(PoolHandle pool_handle, RequestHandle request_handle, - void (*cb)(CallbackId cb_id, ErrorCode err, const char *response), + void (*cb)(CallbackId cb_id, + ErrorCode err, + const char *response), CallbackId cb_id); /** @@ -383,6 +474,11 @@ ErrorCode indy_vdr_request_set_signature(RequestHandle request_handle, struct By ErrorCode indy_vdr_request_set_txn_author_agreement_acceptance(RequestHandle request_handle, FfiStr acceptance); +ErrorCode indy_vdr_resolve(PoolHandle pool_handle, + FfiStr did, + void (*cb)(int64_t cb_id, ErrorCode err, const char *response), + int64_t cb_id); + ErrorCode indy_vdr_set_config(FfiStr config); ErrorCode indy_vdr_set_default_logger(void); @@ -391,6 +487,19 @@ ErrorCode indy_vdr_set_protocol_version(int64_t version); ErrorCode indy_vdr_set_socks_proxy(FfiStr socks_proxy); +/** + * Public destructor for strings managed by the other side of the FFI. + * + * # Safety + * + * This will free the string pointer it gets passed in as an argument, + * and thus can be wildly unsafe if misused. + * + * See the documentation of `ffi_support::destroy_c_string` and + * `ffi_support::define_string_destructor!` for further info. + */ +void indy_vdr_string_free(char *s); + char *indy_vdr_version(void); #ifdef __cplusplus diff --git a/wrappers/javascript/indy-vdr-react-native/cpp/indyVdr.cpp b/wrappers/javascript/indy-vdr-react-native/cpp/indyVdr.cpp index a9d15852..aa2f68f6 100644 --- a/wrappers/javascript/indy-vdr-react-native/cpp/indyVdr.cpp +++ b/wrappers/javascript/indy-vdr-react-native/cpp/indyVdr.cpp @@ -102,6 +102,8 @@ jsi::Value buildGetAttribRequest(jsi::Runtime &rt, jsi::Object options) { auto hash = jsiToValue(rt, options, "hash", true); auto raw = jsiToValue(rt, options, "raw", true); auto enc = jsiToValue(rt, options, "enc", true); + auto seqNo = jsiToValue(rt, options, "seqNo", true); + auto timestamp = jsiToValue(rt, options, "timestamp", true); RequestHandle out; @@ -110,7 +112,8 @@ jsi::Value buildGetAttribRequest(jsi::Runtime &rt, jsi::Object options) { targetDid.c_str(), raw.length() > 0 ? raw.c_str() : nullptr, hash.length() > 0 ? hash.c_str() : nullptr, - enc.length() > 0 ? enc.c_str() : nullptr, &out); + enc.length() > 0 ? enc.c_str() : nullptr, + seqNo, timestamp, &out); return createReturnValue(rt, code, &out); }; @@ -226,12 +229,14 @@ jsi::Value buildGetNymRequest(jsi::Runtime &rt, jsi::Object options) { auto submitterDid = jsiToValue(rt, options, "submitterDid", true); auto dest = jsiToValue(rt, options, "dest"); + auto seqNo = jsiToValue(rt, options, "seqNo", true); + auto timestamp = jsiToValue(rt, options, "timestamp", true); RequestHandle out; ErrorCode code = indy_vdr_build_get_nym_request( submitterDid.length() > 0 ? submitterDid.c_str() : nullptr, dest.c_str(), - &out); + seqNo, timestamp, &out); return createReturnValue(rt, code, &out); }; @@ -297,6 +302,8 @@ jsi::Value buildNymRequest(jsi::Runtime &rt, jsi::Object options) { auto verkey = jsiToValue(rt, options, "verkey", true); auto alias = jsiToValue(rt, options, "alias", true); auto role = jsiToValue(rt, options, "role", true); + auto diddocContent = jsiToValue(rt, options, "diddocContent", true); + auto version = jsiToValue(rt, options, "version"); RequestHandle out; @@ -304,7 +311,9 @@ jsi::Value buildNymRequest(jsi::Runtime &rt, jsi::Object options) { submitterDid.c_str(), dest.c_str(), verkey.length() > 0 ? verkey.c_str() : nullptr, alias.length() > 0 ? alias.c_str() : nullptr, - role.length() > 0 ? role.c_str() : nullptr, &out); + role.length() > 0 ? role.c_str() : nullptr, + diddocContent.length() > 0 ? diddocContent.c_str() : nullptr, + version, &out); return createReturnValue(rt, code, &out); };