Skip to content

Commit e0ab5e7

Browse files
committed
documentation
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 00258b3 commit e0ab5e7

File tree

30 files changed

+130
-173
lines changed

30 files changed

+130
-173
lines changed

cmd/tokengen/README.md

Lines changed: 30 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,53 @@
11
# Tokengen
22

3-
`tokengen` is an utility for generating Fabric Token-SDK material.
4-
It is provided as a means of preconfiguring public parameters, token chaincode, and so.
5-
It would normally not be used in the operation of a production network.
3+
`tokengen` is a utility for generating Fabric Token-SDK material, such as public parameters, token chaincode packages, and other cryptographic artifacts.
64

7-
## Syntax
5+
It is primarily used for pre-configuring development and testing environments.
86

9-
The `tokengen` command has five subcommands, as follows:
7+
## Build
108

11-
- artifacts
12-
- certifier-keygen
13-
- gen
14-
- help
15-
- version
16-
17-
## tokengen artifacts
18-
19-
This command is used to centrally generate key material and configuration files.
20-
It takes in input a `topology` file, in `yaml` format, that describes the topologies of the networks involved.
21-
An example can be found [`here`](./samples/topology/fungible.yaml).
22-
Topology files can be edited directly or they can be generated programmatically as shown [`here`](./samples/topology/fungible.go).
23-
24-
```
25-
Read topology from file and generates artifacts.
26-
27-
Usage:
28-
tokengen artifacts [flags]
29-
30-
Flags:
31-
-h, --help help for artifacts
32-
-o, --output string output folder (default "./testdata")
33-
-p, --port int host starting port (default 20000)
34-
-t, --topology string topology file in yaml format
35-
```
36-
37-
## tokengen certifier-keygen
38-
39-
```
40-
Gen Token Certifier Key Pair.
41-
42-
Usage:
43-
tokengen certifier-keygen [flags]
44-
45-
Flags:
46-
-d, --driver string driver (zkatdlognogh.v1) (default "zkatdlognogh.v1")
47-
-h, --help help for certifier-keygen
48-
-o, --output string output folder (default ".")
49-
-p, --pppath string path to the public parameters file
50-
```
51-
52-
## tokengen gen
53-
54-
The `tokengen gen` command has two subcommands, as follows:
55-
56-
- fabtoken.v1: generates the public parameters for the fabtoken driver
57-
- zkatdlognogh.v1: generates the public parameters for the zkatdlognogh.v1 driver
58-
59-
## tokengen gen fabtoken.v1
60-
61-
```
62-
Usage:
63-
tokengen gen fabtoken.v1 [flags]
64-
65-
Flags:
66-
-a, --auditors strings list of auditor MSP directories containing the corresponding auditor certificate
67-
--cc generate chaincode package
68-
-h, --help help for fabtoken.v1
69-
-s, --issuers strings list of issuer MSP directories containing the corresponding issuer certificate
70-
-o, --output string output folder (default ".")
71-
-v, --version uint allows the caller of tokengen to override the version number put in the public params
72-
```
73-
74-
The public parameters are stored in the output folder with name `fabtokenv1_pp.json`.
75-
If version is overridden, then file name will be `("fabtokenv%d_pp.json", version)`.
76-
77-
### tokengen gen zkatdlognogh.v1
9+
To build `tokengen`, run the following command from the root of the repository:
7810

11+
```bash
12+
make tokengen
7913
```
80-
Usage:
81-
tokengen gen zkatdlognogh.v1 [flags]
8214

83-
Flags:
84-
-r, --aries flag to indicate that aries should be used as backend for idemix
85-
-a, --auditors strings list of auditor MSP directories containing the corresponding auditor certificate
86-
-b, --bits uint bits is used to define the maximum quantity a token can contain (default 64)
87-
--cc generate chaincode package
88-
-x, --extra stringArray extra data in key=value format, where value is the path to a file containing the data to load and store in the key
89-
-h, --help help for zkatdlognogh.v1
90-
-i, --idemix string idemix msp dir
91-
-s, --issuers strings list of issuer MSP directories containing the corresponding issuer certificate
92-
-o, --output string output folder (default ".")
93-
-v, --version uint allows the caller of tokengen to override the version number put in the public params
94-
```
15+
The binary will be generated in the `$GOROOT/bin` directory.
9516

96-
The public parameters are stored in the output folder with name `zkatdlognoghv1_pp.json`.
97-
If version is overridden, then file name will be `("zkatdlognogh%d_pp.json", version)`.
17+
## Usage
9818

99-
### tokengen update zkatdlognogh.v1
19+
The `tokengen` tool uses a command-line interface with several subcommands. You can always use the `--help` flag to see available options for any command.
10020

101-
This command takes an existing `zkatdlognoghv1_pp.json` and allows you to update the issuer and/or auditor certificates, while keeping the public parameters intact.
102-
103-
```
104-
Usage:
105-
tokengen update zkatdlognogh.v1 [flags]
106-
107-
Flags:
108-
-a, --auditors strings list of auditor MSP directories containing the corresponding auditor certificate
109-
-x, --extra stringArray extra data in key=value format, where is the path to a file containing the data to load and store in the key
110-
-h, --help help for zkatdlognogh.v1
111-
-i, --input string path of the public param file
112-
-s, --issuers strings list of issuer MSP directories containing the corresponding issuer certificate
113-
-o, --output string output folder (default ".")
114-
-v, --version uint allows the caller of tokengen to override the version number put in the public params
21+
```bash
22+
tokengen [command] --help
11523
```
11624

117-
## tokengen pp
25+
### Core Commands
11826

119-
The `tokengen pp` command has the following subcommands:
27+
- **`artifacts`**: Generates key material and configuration files from a topology description (YAML).
28+
- **`gen`**: Generates public parameters for specific drivers (e.g., `fabtoken.v1`, `zkatdlognogh.v1`).
29+
- **`update`**: Updates certificates within existing public parameters.
30+
- **`pp print`**: Inspects and prints human-readable details of a public parameters file.
31+
- **`certifier-keygen`**: Generates key pairs for token certifiers.
32+
- **`version`**: Displays the build version information.
12033

121-
- print: Inspect public parameters
122-
123-
### tokengen pp print
124-
125-
```
126-
Usage:
127-
tokengen pp print [flags]
128-
129-
Flags:
130-
-h, --help help for print
131-
-i, --input string path of the public param file
132-
```
133-
134-
## tokengen help
34+
### Examples
13535

36+
#### Generate Public Parameters for FabToken
37+
```bash
38+
tokengen gen fabtoken.v1 --auditors ./msp/auditor --issuers ./msp/issuer --output ./params
13639
```
137-
Help provides help for any command in the application.
138-
Simply type tokengen help [path to command] for full details.
13940

140-
Usage:
141-
tokengen help [command] [flags]
142-
143-
Flags:
144-
-h, --help help for help
41+
#### Inspect Public Parameters
42+
```bash
43+
tokengen pp print --input ./params/fabtokenv1_pp.json
14544
```
14645

147-
## tokengen version
148-
46+
#### Generate Artifacts from Topology
47+
```bash
48+
tokengen artifacts --topology ./topology.yaml --output ./artifacts
14949
```
150-
Print current version of tokengen.
15150

152-
Usage:
153-
tokengen version [flags]
51+
## Configuration
15452

155-
Flags:
156-
-h, --help help for version
157-
```
53+
`tokengen` can also be configured via environment variables prefixed with `CORE_`. For example, `CORE_LOGGING_LEVEL=debug` will set the logging level to debug.

cmd/tokengen/cobra/artifactgen/artifactgen_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/stretchr/testify/require"
1919
)
2020

21+
// TestWriteTopologies tests the WriteTopologies function.
2122
func TestWriteTopologies(t *testing.T) {
2223
tempDir := t.TempDir()
2324
fileName := filepath.Join(tempDir, "topologies.yaml")

cmd/tokengen/cobra/artifactgen/gen/gen.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ import (
1919
"gopkg.in/yaml.v2"
2020
)
2121

22+
// Topology represents a topology.
2223
type Topology struct {
2324
Type string `yaml:"type,omitempty"`
2425
}
2526

27+
// Topologies represents a list of topologies.
2628
type Topologies struct {
2729
Topologies []Topology `yaml:"topologies,omitempty"`
2830
}
2931

32+
// T represents a list of topologies.
3033
type T struct {
3134
Topologies []interface{} `yaml:"topologies,omitempty"`
3235
}
@@ -35,7 +38,7 @@ var topologyFile string
3538
var output string
3639
var port int
3740

38-
// Cmd returns the Cobra Command for Version
41+
// Cmd returns the Cobra Command for generating artifacts.
3942
func Cmd() *cobra.Command {
4043
// Set the flags on the node start command.
4144
flags := cobraCommand.Flags()
@@ -85,6 +88,7 @@ func gen(args []string) error {
8588
return nil
8689
}
8790

91+
// LoadTopologies loads topologies from the given raw byte slice.
8892
func LoadTopologies(raw []byte) ([]api.Topology, error) {
8993
names := &Topologies{}
9094
if err := yaml.Unmarshal(raw, names); err != nil {

cmd/tokengen/cobra/artifactgen/gen/gen_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18+
// TestCmd tests the Cmd function.
1819
func TestCmd(t *testing.T) {
1920
cmd := Cmd()
2021
assert.NotNil(t, cmd)
@@ -28,6 +29,7 @@ func TestCmd(t *testing.T) {
2829
})
2930
}
3031

32+
// TestGen tests the gen function and LoadTopologies.
3133
func TestGen(t *testing.T) {
3234
tempDir := t.TempDir()
3335

cmd/tokengen/cobra/artifactgen/testdata/topology.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
1717
)
1818

19+
// Topology returns a list of topologies for testing.
1920
func Topology(tokenSDKDriver string, sdks ...node.SDK) []api.Topology {
2021
// Fabric
2122
fabricTopology := fabric.NewDefaultTopology()

cmd/tokengen/cobra/artifactgen/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import (
1515
"gopkg.in/yaml.v2"
1616
)
1717

18+
// Topologies represents a list of topologies.
1819
type Topologies struct {
1920
Topologies []api.Topology `yaml:"topologies,omitempty"`
2021
}
2122

23+
// WriteTopologies writes the given topologies to the specified file.
2224
func WriteTopologies(fileName string, topologies []api.Topology, perm fs.FileMode) error {
2325
raw, err := yaml.Marshal(&Topologies{Topologies: topologies})
2426
if err != nil {

cmd/tokengen/cobra/certfier/keypairgen.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var driver string
2323
var ppPath string
2424
var output string
2525

26-
// KeyPairGenCmd returns the Cobra Command for the Certifier KeyGen
26+
// KeyPairGenCmd returns the Cobra Command for generating a Token Certifier Key Pair.
2727
func KeyPairGenCmd() *cobra.Command {
2828
var cobraCommand = &cobra.Command{
2929
Use: "certifier-keygen",
@@ -48,7 +48,7 @@ func KeyPairGenCmd() *cobra.Command {
4848
return cobraCommand
4949
}
5050

51-
// keyPairGen
51+
// keyPairGen generates a certifier key-pair.
5252
func keyPairGen() error {
5353
// TODO:
5454
// 1. load public parameters from ppPath

cmd/tokengen/cobra/certfier/keypairgen_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18+
// TestKeyPairGenCmd tests the KeyPairGenCmd function.
1819
func TestKeyPairGenCmd(t *testing.T) {
1920
cmd := KeyPairGenCmd()
2021
assert.NotNil(t, cmd)
2122
assert.Equal(t, "certifier-keygen", cmd.Use)
2223
}
2324

25+
// TestKeyPairGen tests the keyPairGen function.
2426
func TestKeyPairGen(t *testing.T) {
2527
wd, _ := os.Getwd()
2628
testdataPath := filepath.Join(wd, "..", "..", "testdata", "zkatdlognoghv1_pp.json")
@@ -53,6 +55,7 @@ func TestKeyPairGen(t *testing.T) {
5355
})
5456
}
5557

58+
// TestCobraCommand tests the Cobra command for generating certifier key pairs.
5659
func TestCobraCommand(t *testing.T) {
5760
wd, _ := os.Getwd()
5861
testdataPath := filepath.Join(wd, "..", "..", "testdata", "zkatdlognoghv1_pp.json")

cmd/tokengen/cobra/pp/cc/cc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1919
)
2020

21-
// GeneratePackage generates the chaincode package for the given raw public parameters
21+
// GeneratePackage generates the chaincode package for the given raw public parameters.
2222
func GeneratePackage(raw []byte, outputDir string) error {
2323
t, err := template.New("node").Funcs(template.FuncMap{
2424
"Params": func() string { return base64.StdEncoding.EncodeToString(raw) },

cmd/tokengen/cobra/pp/cc/cc_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ SPDX-License-Identifier: Apache-2.0
77
package cc
88

99
import (
10-
"testing"
1110
"github.com/stretchr/testify/assert"
11+
"testing"
1212
)
1313

14+
// TestGeneratePackage tests the GeneratePackage function.
1415
func TestGeneratePackage(t *testing.T) {
1516
t.Run("fail_package", func(t *testing.T) {
1617
// Providing an invalid path should make PackageChaincode fail.

0 commit comments

Comments
 (0)