Code Monkey home page Code Monkey logo

findy-wrapper-go's Introduction

findy-wrapper-go

test codecov

Findy Agency is an open-source project for a decentralized identity agency. OP Lab developed it from 2019 to 2024. The project is no longer maintained, but the work will continue with new goals and a new mission. Follow the blog for updates.

This is a Go wrapper for indy-sdk. It wraps most of the libindy's functions and data types, but it doesn't try to be complete. We have written it incrementally and wrapped only those functions that we need at the moment.

We haven't extended this wrapper with helper classes. It only tries to offer Go programming interface above the existing libindy API. findy-agent extends this wrapper with SSI/DID abstractions and offers more high-level API for SSI/DID development. For the most applications findy-agent is the one to start playing with.

This wrapper offers one key feature addition to that it's written in Go: it's not dependent on running indy ledger. The wrapper abstracts ledger with the plug-in interface which allows to implement any storage technology to handle needed persistence. Currently implemented ledger add-ons are:

  • indy pool: data is saved into the indy ledger
  • memory ledger: especially good for unit testing and caching
  • file: data is saved into simple JSON file
  • immudb: data is written to immutable database

Get Started

Ubuntu 20.04< is preferred development environment but macOS is also an option. Please make sure that Go and git are both installed and working properly.

Linux and Ubuntu

This is the preferred way to build and use Findy Go wrapper.

  1. Install libindy-dev: make indy_to_debian

    Check indy-sdk installation instructions for more details.

  2. Clone the repo: git clone https://github.com/findy-network/findy-wrapper-go

  3. Run the tests to see everything is working properly : make test

macOS

Because indy SDK won't offer proper distribution for OSX, we have written a helper Bash script to perform installation. Follow these steps:

  1. Install Homebrew if it insn't already on your machine.
  2. Clone the repo: git clone https://github.com/findy-network/findy-wrapper-go
  3. Go to directory ./scripts/mac-libindy:
    $ cd scripts/mac-libindy
    
  4. Execute the installation script.
    $ ./install.sh
    
    Or, if you want to change the default installation location, enter it as a first argument for the script.
    $ ./install.sh /my/own/location
    
  5. Follow the instructions of the install.sh i.e. source the env.sh which is generated to installation directory and is in your clipboard after successful installation.
    $ source /usr/local/opt/libindy/env.sh
    
  6. Run the tests to see everything is OK: make test

The problem solving tip: source env.sh in your dev session.

Development Without The Ledger

The findy-go package includes memory implementation of the ledger transaction interface. If pool names are FINDY_MEM_LEDGER or FINDY_ECHO_LEGDER the package uses its internal implementation of the ledger pool and lets you perform all of its functions.

	r := <-pool.OpenLedger("FINDY_MEM_LEDGER")
	if r.Err() != nil {
		return r.Err()
	}
	pool := r.Handle()

Run Tests With Indy Ledger

  1. Install and start ledger

  2. Create a ledger pool with indy CLI on VON Network or if findy-agent is installed

    findy-agent ledger pool create --name <pool_name> --genesis-txn-file genesis.txt

    To test ledger connection you can give the following command:

    findy-agent ledger pool ping --name <pool_name>

  3. Set environment variable: export FINDY_POOL="FINDY_LEDGER,<pool_name>"

    This will tell anoncreds tests to use FINDY_LEDGER plugin that's the add-on for real Indy ledger. You give the pool name for the ledger after the comma.

  4. Run tests: make test.

    This will run all the pool tests towards the real ledger.

Documentation

The wrapper includes minimal Go documentation. If you need more information about indy SDK, we suggest that you would read the original indy SDK documentation.

Naming Conventions

It follows the same sub-package structure as libindy. Also, function names are the same, but it respects Go idioms.

Original indy SDK function calls in C:

indy_key_for_did(...)
...
indy_key_for_local_did(..)

Same functions but with Go wrapper:

r := <-did.Key(pool, wallet, didStr)
...
r = <-did.LocalKey(wallet, didStr)

As you can see, the subjects that would exist in the function names aren't repeated if they are in the package names already.

Return Types

The return type is Channel, which transfers dto.Result Go structures. These structures work similarly to C unions, which means that we can use one type for all of the wrapper functions. To access the actual data, you have to know the actual type. pool.OpenLedger() returns Handle type.

	r = <-pool.OpenLedger("FINDY_MEM_LEDGER")
	assert.NoError(r.Err())
	h2 := r.Handle()
	assert.Equal(h2, -1)

did.CreateAndStore() returns two strings: did and verkey. Please note the use of did.Did struct instead of the JSON string.

	r := <-did.CreateAndStore(w, did.Did{Seed: ""})
	assert.NoError(r.Err())
	did := r.Str1()
	vk := r.Str2()

When a null string is needed for an argument, the predefined type must be used.

	r = <-annoncreds.IssuerCreateAndStoreCredentialDef(w1, w1DID, scJSON,
		"MY_FIRMS_CRED_DEF", findy.NullString, findy.NullString)

Error Values

The Go error value can be retrieved with dto.Result.Err() which returns Go error.

findy-wrapper-go's People

Contributors

agency-releaser[bot] avatar dependabot[bot] avatar github-actions[bot] avatar heikkohoo avatar lainio avatar lauravuo avatar lauravuo-techlab avatar pekkakaipio-op avatar techlab-lainio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

d1l3t4ntt1

findy-wrapper-go's Issues

Create pool handle during test run

When unit testing with indy ledger, pool handle needs to be created before the test run with indy-cli or findy-agent. To avoid this:

  1. add pool handle creation to test initialisation so that based on active ledger type, handle is created when necessary
  2. remove indy-cli installation step from CI unit test startup sequence

RevRegId is defined as int but should be string

When I confirm a present-proof request, which requests attributes that are part of a revocable credential, I get the following error in findy:

findy-core  | E0120 15:47:00.127938       8 dto.go:28] json: cannot unmarshal string into Go struct field CredentialInfo.cred_info.rev_reg_id of type int: from JSON:
findy-core  | [{"cred_info":{"referent":"dd6ddbb9-035d-409c-9093-3a937ed202e8","attrs":{"lastName":"t","title":"","firstName":"t"},"schema_id":"FnhYpbRquQe6TaECgdYxY5:2:guest:1.0","cred_def_id":"FnhYpbRquQe6TaECgdYxY5:3:CL:17:guest-local-abc001","rev_reg_id":"FnhYpbRquQe6TaECgdYxY5:4:FnhYpbRquQe6TaECgdYxY5:3:CL:17:guest-local-abc001:CL_ACCUM:7efa9955-20ec-477c-a8e8-8b81f0f4c437","cred_rev_id":"1"},"interval":{"from":0,"to":1674229540}}]
findy-core  | E0120 15:47:00.127979       8 handlers.go:70] continue PSM: proof user action handler: create proof: json: cannot unmarshal string into Go struct field CredentialInfo.cred_info.rev_reg_id of type int

Since it complains about rev_reg_id - which looks to be a correct String - I search the findy code and found the following:

RevRegID int `json:"rev_reg_id,omitempty"`

It says, rev_reg_id is an optional Int. At line 129 of the same file however, it is a String. Same with CredRevId.

RevRegID string `json:"rev_reg_id,omitempty"`

Due to my lack of Go experience, I can't provide you a PR. Sorry for that.

Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.