commands

package
v0.0.0-...-8770fa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2023 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2023 The Go SSI Framework Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

View Source
var CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Step 1: Create an ebsi decentralized identifier.",
	Run: func(_ *cobra.Command, _ []string) {
		did := ebsi.NewDecentralizedIdentifier()
		did.GenerateMethodSpecificId()

		jwkIssuanceKey, _ := generateSecp256r1AsJwk(did.String())
		jwkPublicKey, _ := jwkIssuanceKey.PublicKey()
		didDocument := map[string]interface{}{
			"@context": []string{"https://www.w3.org/ns/did/v1"},
			"id":       did.String(),
			"verificationMethod": []map[string]interface{}{
				{
					"id":           jwkPublicKey.KeyID(),
					"type":         "JsonWebKey2020",
					"controller":   did.String(),
					"publicKeyJwk": jwkPublicKey,
				},
			},
			"authentication":  []string{jwkPublicKey.KeyID()},
			"assertionMethod": []string{jwkPublicKey.KeyID()},
		}
		jwkPresentationKey, _ := generateSecp256r1AsJwk(did.String())
		didBucket := wallet.DidBucket{
			Did:             did.String(),
			Document:        didDocument,
			IssuanceKey:     jwkIssuanceKey,
			PresentationKey: jwkPresentationKey,
		}
		if err := wallet.StoreBucket(didBucket); err != nil {
			fmt.Printf("Failed to save the results\n'%s'\n", err)
			return
		}
		fmt.Printf("Creating of did %s succeeded\n", did.String())
	},
}
View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "List the decentralized identifiers stored in the wallet).",
	Args:  cobra.ExactArgs(0),
	Run: func(_ *cobra.Command, _ []string) {
		identifiers, err := wallet.GetAllKeys()
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error while reading the wallet\n'%s'\n", err)
			return
		}
		for _, did := range identifiers {
			fmt.Println(did)
		}
	},
}
View Source
var OnboardCmd = &cobra.Command{
	Use:   "onboard",
	Short: "Step 2: Onboard the controller of the did.",
	Args:  cobra.ExactArgs(0),
	Run: func(cmd *cobra.Command, _ []string) {
		didString, _ := cmd.Flags().GetString("did")
		did := ebsi.NewDecentralizedIdentifier()
		if err := did.ParseIdentifier(didString); err != nil {
			fmt.Printf("Identifier is not valid\n'%s'\n", err)
			return
		}
		accessToken := promptGetAccessToken()
		didBucket, err := wallet.GetBucketByDid(did.String())
		if err != nil {
			fmt.Printf("Failed to load the did bucket\n'%s'\n", err)
			return
		}
		didBucket.AdminSigningKey, _ = generateSecp256k1AsJwk(didBucket.Did)
		ebsiTrustList := ebsi.NewEBSITrustList(
			ebsi.WithBaseUrl("https://api-pilot.ebsi.eu"),
			ebsi.WithVerbose(true),
			ebsi.WithAuthToken(accessToken),
		)

		token, err := ebsiTrustList.Onboard(did.String(), didBucket.AdminSigningKey)
		if err != nil {
			fmt.Printf("failed to onboard the user\n'%s'\n", err)
			return
		}
		switch token := token.(type) {
		case string:
			didBucket.Token = token
			if err = wallet.StoreBucket(didBucket); err != nil {
				fmt.Printf("failed to save the results\n'%s'\n", err)
				return
			}
		default:
			fmt.Printf("invalid response type\n'%s'\n", err)
		}

		fmt.Printf("Onboarding of %s succeeded\n", didString)
	},
}
View Source
var RegisterCmd = &cobra.Command{
	Use:   "register",
	Short: "Step 3: Register the did document (ebsi only).",
	Args:  cobra.ExactArgs(0),
	Run: func(cmd *cobra.Command, _ []string) {
		didString, _ := cmd.Flags().GetString("did")
		did := ebsi.NewDecentralizedIdentifier()
		if err := did.ParseIdentifier(didString); err != nil {
			fmt.Printf("Identifier is not valid\n'%s'\n", err)
			return
		}
		didBucket, err := wallet.GetBucketByDid(did.String())
		if err != nil {
			fmt.Printf("Failed to load the did bucket\n'%s'\n", err)
			return
		}
		didBucket.AdminEncryptionKey, _ = generateSecp256k1AsJwk(didBucket.Did)
		didBucket.AdminTransactionKey, _ = generateSecp256k1AsJwk(didBucket.Did)
		ebsiTrustList := ebsi.NewEBSITrustList(
			ebsi.WithBaseUrl("https://api-pilot.ebsi.eu"),
			ebsi.WithVerbose(true),
		)
		if _, err := ebsiTrustList.RegisterDid(
			ebsi.WithController(didBucket.Did),
			ebsi.WithDocument(didBucket.Document),
			ebsi.WithDocumentMetadata(map[string]interface{}{"deactivated": false}),
			ebsi.WithToken(didBucket.Token),
			ebsi.WithEncryptionKey(didBucket.AdminEncryptionKey),
			ebsi.WithSigningKey(didBucket.AdminSigningKey),
			ebsi.WithTransactionKey(didBucket.AdminTransactionKey),
		); err != nil {
			fmt.Printf("Failed to register the did document\n'%s'\n", err)
			return
		}
		if err = wallet.StoreBucket(didBucket); err != nil {
			fmt.Printf("Failed to save the results\n'%s'\n", err)
			return
		}
		fmt.Printf("Registering of the did document for %s succeeded", didString)
	},
}
View Source
var ResolveCmd = &cobra.Command{
	Use:   "resolve",
	Short: "Step 4: Resolve a did document.",
	Args:  cobra.ExactArgs(0),
	Run: func(cmd *cobra.Command, _ []string) {
		didString, _ := cmd.Flags().GetString("did")
		did := ebsi.NewDecentralizedIdentifier()
		if err := did.ParseIdentifier(didString); err != nil {
			fmt.Printf("Identifier is not valid\n'%s'\n", err)
			return
		}
		ebsiTrustList := ebsi.NewEBSITrustList(
			ebsi.WithBaseUrl("https://api-pilot.ebsi.eu"),
		)
		rawdoc, err := ebsiTrustList.ResolveDid(did.String())
		if err != nil {
			fmt.Printf("Failed to resolve the did document.\n%s\n", err)
			return
		}
		jsonDiddoc, _ := json.MarshalIndent(rawdoc, "", "    ")
		fmt.Printf("Resolving the did document succeeded.\n%s\n", string(jsonDiddoc))
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL