Skip to content
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

Dev #2

Open
wants to merge 10 commits into
base: development
Choose a base branch
from
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# ioConnect
# ioID-SDK

An embedded SDK for connecting smart devices to Web3

![SDK_Design_Overall](./doc/image/SDK_Design_Overall.png)

ioConnect SDK is based on the previously developed PSACrypto SDK and adds implementations of protocols such as DID, DIDDoc, JOSE, and DIDComm on top of ARM PSA functionality. It is implemented in C language and enhances the cross-platform compatibility of the SDK.
ioID-SDK is based on the previously developed PSACrypto SDK and adds implementations of protocols such as DID, DIDDoc, JOSE, and DIDComm on top of ARM PSA functionality. It is implemented in C language and enhances the cross-platform compatibility of the SDK.

The ioConnect SDK is primarily divided into two parts: the Core Layer and the Platform Adaptation Layer (PAL). The Core Layer provides functionality independent of the hardware platform, including implementations of PSA, DID, JOSE, and other protocols. The PAL layer optimizes the code according to the specific characteristics of different hardware platforms. For example, for the ESP platform, the SDK relies on its event messaging mechanism for code optimization, while for the Arduino platform, it implements communication functionality by inheriting the base class.

![ioConnect_repo](./doc/image/ioConnect_repo.png)
The ioID-SDK is primarily divided into two parts: the Core Layer and the Platform Adaptation Layer (PAL). The Core Layer provides functionality independent of the hardware platform, including implementations of PSA, DID, JOSE, and other protocols. The PAL layer optimizes the code according to the specific characteristics of different hardware platforms. For example, for the ESP platform, the SDK relies on its event messaging mechanism for code optimization, while for the Arduino platform, it implements communication functionality by inheriting the base class.

In the file structure of the Core Layer:

Expand All @@ -18,11 +16,11 @@ The `dids` folder mainly implements the functionality of the DID, DIDComm, and V

The `jose` folder mainly implements the JOSE protocol suite, including JWK, JWS, JWE, and others.

![ioConnect_repo_2](./doc/image/ioConnect_repo_2.png)
![ioID-SDK_repo_2](./doc/image/ioConnect_repo_2.png)

In the file structure of the Platform Adaptation Layer (PAL), the SDK mainly implements methods for connecting to IoTeX decentralized network nodes. For example, the `DeviceRegister` component provides a method for terminal devices to register with the IoTeX Wallet, and the `Sprout` component allows easy communication with Sprout.

![ioConnect_repo_3](./doc/image/ioConnect_repo_3.png)
![ioID-SDK_repo_3](./doc/image/ioConnect_repo_3.png)



Expand All @@ -45,32 +43,32 @@ In the file structure of the Platform Adaptation Layer (PAL), the SDK mainly imp

### How to Generate a DID for a device

Please view the documentation : **[How to Generate a DID for a device Using ioConnect SDK](./doc/How_to_Generate_a_DID_for_a_device_Using_ioConnectSDK.md)**
Please view the documentation : **[How to Generate a DID for a device Using ioID SDK](./doc/How_to_Generate_a_DID_for_a_device_Using_ioID-SDK.md)**


### How to Generate a DIDDoc

Please view the documentation : **[How to Generate a DID Document Using ioConnect SDK](./doc/How_to_Generate_a_DID_Document_Using_ioConnectSDK.md)**
Please view the documentation : **[How to Generate a DID Document Using ioID SDK](./doc/How_to_Generate_a_DID_Document_Using_ioID-SDK.md)**

### How to Generate a Verifiable Credentials

Please view the documentation : **[How to Generate a Verifiable Credentials Using ioConnect SDK](./doc/How_to_Generate_a_Verifiable_Credentials_Using_ioConnectSDK.md)**
Please view the documentation : **[How to Generate a Verifiable Credentials Using ioID SDK](./doc/How_to_Generate_a_Verifiable_Credentials_Using_ioID-SDK.md)**

### How to Generate a JWS

Please view the documentation : **[How_to generate_a_JWS](./doc/How_to_use_the_ioConnectSDK_to_generate_a_JWS_Serialization.md)**
Please view the documentation : **[How_to generate_a_JWS](./doc/How_to_use_the_ioID-SDK_to_generate_a_JWS_Serialization.md)**

### How to Generate a JWE

Please view the documentation : **[How_to generate_a_JWE](./doc/How_to_use_the_ioConnectSDK_to_generate_a_JWE_Serialization.md)**
Please view the documentation : **[How_to generate_a_JWE](./doc/How_to_use_the_ioID-SDK_to_generate_a_JWE_Serialization.md)**

### How to Generate a JWT

Please view the documentation : **[How_to generate_a_JWT](./doc/How_to_use_the_ioConnectSDK_to_generate_a_JWT_Serialization.md)**
Please view the documentation : **[How_to generate_a_JWT](./doc/How_to_use_the_ioID-SDK_to_generate_a_JWT_Serialization.md)**

### How to Generate a DIDComm

Please view the documentation : **[How_to generate_a_DIDComm](./doc/How_to_use_the_ioConnectSDK_to_generate_a_DIDComm.md)**
Please view the documentation : **[How_to generate_a_DIDComm](./doc/How_to_use_the_ioID-SDK_to_generate_a_DIDComm.md)**



Expand Down
2 changes: 1 addition & 1 deletion core/src/psa/psa_crypto_ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ psa_status_t iotex_psa_ecdsa_verify_hash(

return( iotex_to_psa_error( ret ) );
#else
return iotex_ecdsa_verify( PSA_KEY_TYPE_ECC_GET_FAMILY(attributes->core.type),
return iotex_ecdsa_verify( attributes->core.type,
key_buffer, key_buffer_size,
hash, hash_length, (uint8_t *)signature, signature_length);
#endif
Expand Down
15 changes: 12 additions & 3 deletions core/src/psa/psa_crypto_porting.c
Original file line number Diff line number Diff line change
Expand Up @@ -2570,7 +2570,10 @@ int iotex_ecdsa_verify( psa_key_type_t type,
uint8_t public_key[2 * NUM_ECC_BYTES] = {0};
int ret;

switch( type )
if ( (key_buffer_size != 64) && (key_buffer_size != 65))
return PSA_ERROR_INVALID_ARGUMENT;

switch( PSA_KEY_TYPE_ECC_GET_FAMILY(type) )
{
case PSA_ECC_FAMILY_SECP_R1:

Expand All @@ -2586,11 +2589,17 @@ int iotex_ecdsa_verify( psa_key_type_t type,
return PSA_ERROR_GENERIC_ERROR;
}

uECC_compute_public_key(key_buffer, public_key, curve);
int offset = key_buffer_size == 64 ? 0 : 1;

if (PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type)) {
memcpy(public_key, key_buffer + offset, 64);
} else {
uECC_compute_public_key(key_buffer, public_key, curve);
}

ret = uECC_verify(public_key, hash, hash_length, signature, curve);
if ( 0 == ret )
return PSA_ERROR_GENERIC_ERROR;
return PSA_ERROR_INVALID_SIGNATURE;

return PSA_SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# How to Generate a DID Document Using ioConnectSDK
# How to Generate a DID Document Using ioID-SDK

​ A DIDDoc is a set of data describing the [DID subject](https://www.w3.org/TR/did-core/#dfn-did-subjects), including mechanisms, such as cryptographic public keys, that the [DID subject](https://www.w3.org/TR/did-core/#dfn-did-subjects) or a [DID delegate](https://www.w3.org/TR/did-core/#dfn-did-delegate) can use to [authenticate](https://www.w3.org/TR/did-core/#dfn-authenticated) itself and prove its association with the [DID](https://www.w3.org/TR/did-core/#dfn-decentralized-identifiers). A DID document might have one or more different [representations](https://www.w3.org/TR/did-core/#dfn-representations)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# How to Generate a DID for a device Using ioConnectSDK
# How to Generate a DID for a device Using ioID-SDK



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# How to Generate a Verifiable Credentials Using ioConnectSDK
# How to Generate a Verifiable Credentials Using ioID-SDK



Expand Down
17 changes: 11 additions & 6 deletions pal/ESP32/DeviceRegister/deviceregister.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ static char signature_str[64 * 2 + 1] = {0};
static TaskHandle_t pxCreatedTask;
static esp_log_level_t log_level = 0;

#if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS)
static httpd_handle_t server = NULL;
#endif

#if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS)
static esp_err_t did_get_handler(httpd_req_t *req)
Expand Down Expand Up @@ -349,18 +351,18 @@ void iotex_pal_sprout_device_register_start(char *did, char *diddoc)
printf("Failed to _pal_device_register_init() ret %d\n", ret);
}

upload_did = iotex_utils_device_register_did_upload_prepare(did, 1, signature_str, true);
upload_did = iotex_utils_device_register_did_upload_prepare(did, 1, NULL, true);
if (upload_did)
printf("Upload DID : %s\n", upload_did);

upload_diddoc = iotex_utils_device_register_diddoc_upload_prepare(diddoc, 1, signature_str, true);
upload_diddoc = iotex_utils_device_register_diddoc_upload_prepare(diddoc, 1, NULL, true);
if (upload_diddoc)
printf("Upload DIDDoc : %s\n", upload_diddoc);

#if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_SERIAL)
xTaskCreate(_sprout_device_register_serial_task, "device_register_task", 1024 * 5, NULL, 10, &pxCreatedTask);
#elif (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS)
_pal_sprout_webserver_secure_start();
xTaskCreate(_sprout_device_register_serial_task, "device_register_task", 1024 * 5, NULL, 10, &pxCreatedTask);
#elif (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS)
_pal_sprout_webserver_secure_start();
#endif

}
Expand All @@ -379,9 +381,12 @@ void iotex_pal_sprout_device_register_stop(void)
pxCreatedTask = NULL;

mode_https:

#if (IOTEX_PAL_DEVICE_REGISTER_MODE == IOTEX_PAL_DEVICE_REGISTER_MODE_HTTPS)
if (server)
httpd_ssl_stop(server);
#endif

return;
}


Expand Down