Giter Club home page Giter Club logo

mydid's Introduction

MyDID

This provides a basic implementation of the W3C DID specification which was approved as a recommendation in late June 2022 Specification can be found on https://www.w3.org/TR/did-core/

DID format

MyDID implementation adopts the following format when generating DIDs

"did:ttd:"(namespace):identifier
namespace: idchar*
identifier: base58char+
idchar: ALPHA / DIGIT
base58char: 123456789ABCDEFGH JKLMN PQRSTUVWXYZabcdefghijk mnopqrstuvwxyz

e.g.

did:ttd:zkjhdj365dqbbtc28hic
did:ttd:sg:zkjhdj365dqbbtc28hic

#How to use

Generate a DID

First you need to generate a key pair. General EC curves and edward curves are supported at the moment.

KeyPairGenerator generator = KeyPairGenerator.getInstance("EC");
//or
KeyPairGenerator generator = KeyPairGenerator.getInstance("EC", "BC");
//or
KeyPairGenerator generator = KeyPairGenerator.getInstance("Ed25519");
...
KeyPair keyPair = generator.generateKeyPair();

Then use the generated keypair to call the createDid method in the DidUtil class This will generate the DID and return its corresponding DIDDocument

DIDDocument didDoc = DidUtil.createDid(keyPair);
System.out.println(didDoc.getId().getFullQualifiedIdentifier());

Store DIDDcoument on Algorand Blockchain

Generated DID document can be stored in Algorand blockchain. For local testing Algorand sandbox, which is available on https://github.com/algorand/sandbox can be used for this. Clone the Algorand sandbox repo and start the sandbox using ./sandbox up command. This will start the Algorand private node on the local machine. Then create client to connect to the Algorand

AlgodClient algodClient = AlgorandUtil.createAlgodClient();

We need an Algorand account to store the DID document on the chain. By default, the sandbox comes with 3 accounts. I will get the first account.

KmdApi kmdApi = AlgorandUtil.createKmdApi();
String defaultWalletHandle = AlgorandUtil.AlgorandSandboxPrivateNode.getDefaultWalletHandle(kmdApi);
List<Address> walletAddresses = AlgorandUtil.getWalletAddresses(kmdApi, defaultWalletHandle);
byte[] sk = AlgorandUtil.getPrivateKeyFromWallet(kmdApi, walletAddresses.get(0), defaultWalletHandle, "");
Account steward = new Account(sk);

Then I use that account to store the document on the chain. JSON representation of the DIDDocument will be stored in the blockchain as

AlgorandUtil.storeDID(algodClient, steward, didDoc);

Retrieve a DIDDocument from the Blockchain

We can use the Algorand indexer client to retrieve any DIDDocument from the chain, if we know the DID To do that, first we need to create an Algorand Indexer client

IndexerClient indexerClient = AlgorandUtil.createIndexerClient();

Then we can use the AlgorandClient to retrieve the document as follows. You can use either a DID object or a string representation of (full qualified) DID

JSONObject documentSender = AlgorandUtil.getDIDDocument(indexerClient, didDoc.getId());

mydid's People

Contributors

thusithathilina avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.