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

addition of c# wrapper with libs for windows and macos #66

Merged
merged 42 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3427272
added files to build library for windows and macos
Feb 4, 2024
79b7066
added c# wrapper
Feb 4, 2024
6f62f08
removed visual studio generated config
Feb 4, 2024
bb7d580
added vs and vscode ignores
Feb 4, 2024
9caca00
fixed npe and added content to readme
Feb 5, 2024
cf9c860
Changed to support UTF8
Feb 7, 2024
6d63737
Updated README.md
smartrics Feb 8, 2024
4b95b9a
fix makefile arch selection
conbon Feb 8, 2024
9a259ef
Merge branch 'csharp-ffi' of https://github.com/Iotic-Labs/iotics-ide…
Feb 8, 2024
70daffc
.dylib for native mac extension vs .so for linux
conbon Feb 8, 2024
6458134
Merge branch 'csharp-ffi' of https://github.com/Iotic-Labs/iotics-ide…
Feb 8, 2024
1c2da8b
macos_arm native libraries
conbon Feb 9, 2024
34d7812
Merge branch 'csharp-ffi' of https://github.com/Iotic-Labs/iotics-ide…
Feb 9, 2024
e0cac19
moved windows libs
Feb 9, 2024
8b5a475
reorganised libraties
Feb 9, 2024
f868041
added files to build library for windows and macos
Feb 4, 2024
035a1bd
added c# wrapper
Feb 4, 2024
d334580
removed visual studio generated config
Feb 4, 2024
784aa2e
added vs and vscode ignores
Feb 4, 2024
d093756
fixed npe and added content to readme
Feb 5, 2024
e0c5c8b
Changed to support UTF8
Feb 7, 2024
0a161b2
Updated README.md
smartrics Feb 8, 2024
58b2c98
macos_arm native libraries
conbon Feb 9, 2024
3a7deb2
moved windows libs
Feb 9, 2024
b2b8aaa
reorganised libraties
Feb 9, 2024
bacf057
Merge branch 'csharp-ffi' of https://github.com/Iotic-Labs/iotics-ide…
Feb 12, 2024
a9d8d35
sanitised gitignore
Feb 12, 2024
fa17d16
fixed script comment and env variable as per reviewer's request
Feb 12, 2024
9347f06
fixed comment and env var name as per review
Feb 12, 2024
73b813e
fixed as per review
Feb 12, 2024
ed76ec3
further removed random data from the readme example for clarity
Feb 12, 2024
0f3615e
removed hardcoded resolver address
Feb 12, 2024
916bd57
added error messages to test output
Feb 12, 2024
a3ee3cc
removed hardcoded resolver name
Feb 12, 2024
66a042a
explaining what's going on as per instructions from reviewer
Feb 12, 2024
550cc02
cleaned up code as per review
Feb 12, 2024
2b0ea9c
fixed typo as per review
Feb 12, 2024
0127302
renamed to a more appropriate name the return value of the c# wrapper
Feb 12, 2024
9d35824
fixed code to comply to reviewers' comments
Feb 12, 2024
2b383b1
fixed typo
Feb 12, 2024
89f11c4
removed unnecessary tabs and comments and added Recreate for twins
smartrics Feb 14, 2024
1b672ea
removed tab
smartrics Feb 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ ffi/java-idsdk/.idea
ffi/java-idsdk/target
ffi/java-idsdk/**/*.class
dist/
.idea/
.idea/
smartrics marked this conversation as resolved.
Show resolved Hide resolved
ffi/dotnet-idsdk/.vscode
ffi/dotnet-idsdk/**/.vs
ffi/dotnet-idsdk/**/obj
smartrics marked this conversation as resolved.
Show resolved Hide resolved
ffi/dotnet-idsdk/**/bin
18 changes: 10 additions & 8 deletions ffi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ ifeq ($(OS),Windows_NT)
endif
OS_EXT=dll
else
UNAME_OS := $(shell uname -s)
ifeq ($(UNAME_OS),Darwin)
OS_FLAG=darwin
OS_EXT=dylib
endif
ifeq ($(UNAME_OS),Linux)
OS_FLAG=linux
OS_EXT=so
ifeq ($(strip $(OS_FLAG)),)
UNAME_OS := $(shell uname -s)
ifeq ($(UNAME_OS),Darwin)
OS_FLAG=darwin
OS_EXT=dylib
endif
ifeq ($(UNAME_OS),Linux)
OS_FLAG=linux
OS_EXT=so
endif
endif

UNAME_ARCH := $(shell uname -m)
Expand Down
16 changes: 12 additions & 4 deletions ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@ FFI wrapper for iotics-identity-go

## Build

`make compile`
With `make` installed you can compile for the current platform with
`make compile`. The script will detect the OS and ARCH and build for your system.

The target should determine the platform and architecture of the current OS and build the binary library accordingly.
If you want to override the target os (the `GOOS` variable), define `$OS_FLAG` to the desired value.
smartrics marked this conversation as resolved.
Show resolved Hide resolved
For example if you want to compile for an iOS target run
`env OS_FLAG=ios make compile`
smartrics marked this conversation as resolved.
Show resolved Hide resolved

Alternatively you can build your version using:

`env GOOS=<os> GOARCH=<arch> go build -buildmode=c-shared -o lib/lib-iotics-id-sdk.so ./ffi_wrapper.go`
On Windows, if you don't have `make` you can run the powershell script `build.ps1` like:
smartrics marked this conversation as resolved.
Show resolved Hide resolved

`powershell -ExecutionPolicy Bypass -File build.ps1`

Alternatively you can build your version manually using:

`env GOOS=<$OS_FLAG> GOARCH=<$OS_ARCH> go build -buildmode=c-shared -o lib/lib-iotics-id-sdk.so ./ffi_wrapper.go`
smartrics marked this conversation as resolved.
Show resolved Hide resolved

## Verifying goreleaser locally

Expand Down
23 changes: 23 additions & 0 deletions ffi/build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Set the name of your Go program
smartrics marked this conversation as resolved.
Show resolved Hide resolved
$programName = "lib-iotics-id-sdk"

# Set the source file name (assuming it's in the same directory as the script)
$sourceFile = "."

# Set the output directory for compiled binaries
$outputDirectory = ".\lib"

$env:GOARCH="amd64"
$env:CGO_ENABLED=1

# Compile for Windows
Write-Host "Compiling for Windows..."
$env:GOOS="windows"
go build -x -v -buildmode=c-shared -o "$outputDirectory\$programName.dll" $sourceFile

if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Compilation for Windows failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}

Write-Host "Compilation completed successfully."
9 changes: 9 additions & 0 deletions ffi/dotnet-idsdk/IoticsIdLib/IoticsIdLib.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>
29 changes: 29 additions & 0 deletions ffi/dotnet-idsdk/IoticsIdLib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Build & run

1. go to the ffi directory and run the Makefile or the build.ps1 as per README.
StephanieBracaloni marked this conversation as resolved.
Show resolved Hide resolved
2. once the build of the ffi wrapper works, copy the libraries in this top directory `copy .\lib\*.* .\dotnet-idsdk\IoticsIdLib\`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs an update

- the libraries need to be made available to the project. there should be a way to configure the path in the csproj but I haven't found a way yet
smartrics marked this conversation as resolved.
Show resolved Hide resolved
3. run
- `dotnet clean` to clean the project (sometimes it seems you need to delete the directories `bin` and `obj` manually)
- `dotnet build` to build it
- `dotnet run` to run the Main method in `src\Main.cs`

In order to distribute the project to 3rd parties you should zip the two files `lib-iotics-id-sdk.[dll|h]` and the content of the bin directory.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Depending on how much time there is) we should instead try to release an artefact via GH actions for all of this bundled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should automate the build once we have at least 2 users

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in a way. Though we can see that the releases currently contain a single x86_64 Linux FFI binary.
I would think that it'll be easier for people to use this without having to clone & build themselves. It's not like they'd want to (or we'd want them to) hack around with it. We'd want them to just use it.



## Run output

a working output for the run is
vtermanis marked this conversation as resolved.
Show resolved Hide resolved

A new seed: b7778a197751d2370662c03ba7b17a38224748729158437be98a185eeae69561
Use these mnemonics instead of remembering the seed: resist rough main upgrade brush breeze book fix desert diesel future icon caught picnic ski climb drop tent glad cost upgrade infant few diagram
Recovered seed: b7778a197751d2370662c03ba7b17a38224748729158437be98a185eeae69561
Agent identity: Key=agentKeyName, Id=#agentName, Did=did:iotics:iotU1NapzbKmJC7b18UbohQe1HRpkGSYtnF6, Seed=...69561 Resolver=https://did.dev.iotics.com
User identity: Key=userKeyName, Id=#userName, Did=did:iotics:iotDRfBoB4H1o7XRySDNQjppBP1YcDkwgEUN, Seed=...69561 Resolver=https://did.dev.iotics.com
Twin identity: Key=userKeyName, Id=#userName, Did=did:iotics:iotWTs39Ce4cT85eXMGKsmS6rR8F73VGGxpu, Seed=...69561 Resolver=https://did.dev.iotics.com
Twin identity with CD: Key=twinKeyName, Id=#twinName, Did=did:iotics:iotB8Jq3V1MyejYJercDmiXXZzZ1ZStVgi2o, Seed=...69561 Resolver=https://did.dev.iotics.com
User delegating to agent 1: OK
Agent2 identity: Key=agentKeyName2, Id=#agentName2, Did=did:iotics:iotGbUUVGm2kFBEhV49ZBzjk8vCb5MYLBGwK, Seed=...a2772 Resolver=https://did.dev.iotics.com
Twin delegating to agent2: OK
Token 1: eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJmb28iLCJleHAiOjE3MDcxMzIxNjcsImlhdCI6MTcwNzEzMjEyNywiaXNzIjoiZGlkOmlvdGljczppb3RVMU5hcHpiS21KQzdiMThVYm9oUWUxSFJwa0dTWXRuRjYjYWdlbnROYW1lIiwic3ViIjoiZGlkOmlvdGljczppb3REUmZCb0I0SDFvN1hSeVNETlFqcHBCUDFZY0Rrd2dFVU4ifQ.VxOhfy6a7cR8RzeEwMrPC9hqoyKLhRDxTMWAybN35SWhPDHzPDnjvORSFEpeovelD1XFRn9ikyLncygipZ9SVw
Token 2: eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJmb28iLCJleHAiOjE3MDcxMzIxNjcsImlhdCI6MTcwNzEzMjEyNywiaXNzIjoiZGlkOmlvdGljczppb3RVMU5hcHpiS21KQzdiMThVYm9oUWUxSFJwa0dTWXRuRjYjYWdlbnROYW1lIiwic3ViIjoiZGlkOmlvdGljczppb3REUmZCb0I0SDFvN1hSeVNETlFqcHBCUDFZY0Rrd2dFVU4ifQ.0qNDZRJEvExnGEphi6RuZj3t_MnL7HXs0PgrR-rsWHL3Px8MXGxDo75WSlwbaABaLrCErvKgmk-cV_AX-oGJgQ
smartrics marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
177 changes: 177 additions & 0 deletions ffi/dotnet-idsdk/IoticsIdLib/lib/arm64/macos/lib-iotics-id-sdk.h
vtermanis marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
/* Code generated by cmd/cgo; DO NOT EDIT. */

/* package command-line-arguments */


#line 1 "cgo-builtin-export-prolog"

#include <stddef.h>

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef struct { const char *p; ptrdiff_t n; } _GoString_;
#endif

#endif

/* Start of preamble from import "C" comments. */


#line 3 "ffi_wrapper.go"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>

#line 1 "cgo-generated-wrapper"


/* End of preamble from import "C" comments. */


/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"

#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H

typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef size_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif

/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];

#ifndef GO_CGO_GOSTRING_TYPEDEF
typedef _GoString_ GoString;
#endif
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;

#endif

/* End of boilerplate cgo prologue. */

#ifdef __cplusplus
extern "C" {
#endif


/* Return type for CreateDefaultSeed */
struct CreateDefaultSeed_return {
char* r0;
char* r1;
};
extern struct CreateDefaultSeed_return CreateDefaultSeed();

/* Return type for MnemonicBip39ToSeed */
struct MnemonicBip39ToSeed_return {
char* r0;
char* r1;
};
extern struct MnemonicBip39ToSeed_return MnemonicBip39ToSeed(char* cMnemonic);

/* Return type for SeedBip39ToMnemonic */
struct SeedBip39ToMnemonic_return {
char* r0;
char* r1;
};
extern struct SeedBip39ToMnemonic_return SeedBip39ToMnemonic(char* cSeed);

/* Return type for CreateAgentIdentity */
struct CreateAgentIdentity_return {
char* r0;
char* r1;
};
extern struct CreateAgentIdentity_return CreateAgentIdentity(char* cResolverAddress, char* cKeyName, char* cName, char* cSeed);

/* Return type for RecreateAgentIdentity */
struct RecreateAgentIdentity_return {
char* r0;
char* r1;
};
extern struct RecreateAgentIdentity_return RecreateAgentIdentity(char* cResolverAddress, char* cKeyName, char* cName, char* cSeed);

/* Return type for CreateUserIdentity */
struct CreateUserIdentity_return {
char* r0;
char* r1;
};
extern struct CreateUserIdentity_return CreateUserIdentity(char* cResolverAddress, char* cKeyName, char* cName, char* cSeed);

/* Return type for RecreateUserIdentity */
struct RecreateUserIdentity_return {
char* r0;
char* r1;
};
extern struct RecreateUserIdentity_return RecreateUserIdentity(char* cResolverAddress, char* cKeyName, char* cName, char* cSeed);

/* Return type for CreateTwinIdentity */
struct CreateTwinIdentity_return {
char* r0;
char* r1;
};
extern struct CreateTwinIdentity_return CreateTwinIdentity(char* cResolverAddress, char* cKeyName, char* cName, char* cSeed);

/* Return type for RecreateTwinIdentity */
struct RecreateTwinIdentity_return {
char* r0;
char* r1;
};
extern struct RecreateTwinIdentity_return RecreateTwinIdentity(char* cResolverAddress, char* cKeyName, char* cName, char* cSeed);
extern char* UserDelegatesAuthenticationToAgent(char* cResolverAddress, char* cAgentDid, char* cAgentKeyName, char* cAgentName, char* cAgentSeed, char* cUserDid, char* cUserKeyName, char* cUserName, char* cUserSeed, char* cDelegationName);
extern char* TwinDelegatesControlToAgent(char* cResolverAddress, char* cAgentDid, char* cAgentKeyName, char* cAgentName, char* cAgentSeed, char* cTwinDid, char* cTwinKeyName, char* cTwinName, char* cTwinSeed, char* cDelegationName);

/* Return type for IsAllowedFor */
struct IsAllowedFor_return {
char* r0;
char* r1;
};
extern struct IsAllowedFor_return IsAllowedFor(char* cResolverAddress, char* cToken);

/* Return type for CreateAgentAuthToken */
struct CreateAgentAuthToken_return {
char* r0;
char* r1;
};

// CreateAgentAuthToken creates an Agent Authentication token given the secrets
// It returns the token string or error string
//
extern struct CreateAgentAuthToken_return CreateAgentAuthToken(char* cAgentDid, char* cAgentKeyName, char* cAgentName, char* cAgentSeed, char* cUserDid, char* cAudience, GoInt64 durationInSeconds);

/* Return type for CreateTwinDidWithControlDelegation */
struct CreateTwinDidWithControlDelegation_return {
char* r0;
char* r1;
};
extern struct CreateTwinDidWithControlDelegation_return CreateTwinDidWithControlDelegation(char* cResolverAddress, char* cAgentDid, char* cAgentKeyName, char* cAgentName, char* cAgentSeed, char* cTwinKeyName, char* cTwinName);
extern void FreeUpCString(char* pointer);

#ifdef __cplusplus
}
#endif
vtermanis marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Loading
Loading