-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from rolsonquadras/longform-vdr
chore: move sidetreelongform vdr from did-go
- Loading branch information
Showing
33 changed files
with
4,793 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Long Form VDR | ||
Long form VDR is used to resolve long form DID and to create long-form DID. | ||
Update, recover and deactivate operations are currently not supported. | ||
|
||
## New VDR | ||
``` | ||
import ( | ||
"crypto" | ||
"github.com/trustbloc/did-go/method/sidetreelongform" | ||
) | ||
vdr, err := sidetreelongform.New() | ||
if err != nil { | ||
return err | ||
} | ||
``` | ||
|
||
## Create DID | ||
For creating DID use vdr create and pass DID document. | ||
|
||
``` | ||
import ( | ||
"crypto" | ||
"crypto/ed25519" | ||
"crypto/rand" | ||
"fmt" | ||
ariesdid "github.com/hyperledger/aries-framework-go/pkg/doc/did" | ||
"github.com/hyperledger/aries-framework-go/pkg/doc/jose" | ||
vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr" | ||
"github.com/trustbloc/did-go/method/sidetreelongform" | ||
) | ||
recoveryKey, recoveryKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader) | ||
if err != nil { | ||
return err | ||
} | ||
updateKey, updateKeyPrivateKey, err := ed25519.GenerateKey(rand.Reader) | ||
if err != nil { | ||
return err | ||
} | ||
didPublicKey, _, err := ed25519.GenerateKey(rand.Reader) | ||
if err != nil { | ||
return err | ||
} | ||
jwk, err := jose.JWKFromKey(didPublicKey) | ||
if err != nil { | ||
return err | ||
} | ||
vm,err:=ariesdid.NewVerificationMethodFromJWK("key1", "Ed25519VerificationKey2018", "", jwk) | ||
if err != nil { | ||
return err | ||
} | ||
didDoc := &ariesdid.Doc{} | ||
// add did keys | ||
didDoc.Authentication = append(didDoc.Authentication, *ariesdid.NewReferencedVerification(vm, | ||
ariesdid.Authentication)) | ||
// add did services | ||
didDoc.Service = []ariesdid.Service{{ID: "svc1", Type: "type", ServiceEndpoint: "http://www.example.com/"}} | ||
// create did | ||
createdDocResolution, err := vdr.Create(didDoc, | ||
vdrapi.WithOption(sidetreelongform.RecoveryPublicKeyOpt, recoveryKey), | ||
vdrapi.WithOption(sidetreelongform.UpdatePublicKeyOpt, updateKey), | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(createdDocResolution.DIDDocument.ID) | ||
// recovery private key should be saved for future use. | ||
keyRetrieverImpl.recoverKey = recoveryKeyPrivateKey | ||
// update private key should be saved for future use. | ||
keyRetrieverImpl.updateKey = updateKeyPrivateKey | ||
sidetreelongformDID := createdDocResolution.DIDDocument.ID | ||
``` | ||
|
||
## Resolve DID | ||
For resolving DID use vdr read and pass long form DID. | ||
|
||
``` | ||
docResolution, err := vdr.Read(sidetreelongformDID) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(docResolution.DIDDocument.ID) | ||
``` | ||
|
||
## Update DID | ||
Not supported. | ||
|
||
## Recover DID | ||
Not supported. | ||
|
||
## Deactivate DID | ||
Not supported. |
Oops, something went wrong.