Skip to content

Commit 36654cb

Browse files
authored
upgradability: fixes to allow more easily to extend an existing driver #1154 (#1155)
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent e8b9e0a commit 36654cb

File tree

57 files changed

+338
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+338
-260
lines changed

cmd/tokengen/README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Usage:
4343
tokengen certifier-keygen [flags]
4444
4545
Flags:
46-
-d, --driver string driver (dlog) (default "dlog")
46+
-d, --driver string driver (zkatdlognogh.v1) (default "zkatdlognogh.v1")
4747
-h, --help help for certifier-keygen
4848
-o, --output string output folder (default ".")
4949
-p, --pppath string path to the public parameters file
@@ -53,56 +53,56 @@ Flags:
5353

5454
The `tokengen gen` command has two subcommands, as follows:
5555

56-
- fatoken: generates the public parameters for the fabtoken driver
57-
- dlog: generates the public parameters for the dlog driver
56+
- fabtoken.v1: generates the public parameters for the fabtoken driver
57+
- zkatdlog.v1: generates the public parameters for the zkatdlog.v1 driver
5858

59-
## tokengen gen fabtoken
59+
## tokengen gen fabtoken.v1
6060

6161
```
6262
Usage:
63-
tokengen gen fabtoken [flags]
63+
tokengen gen fabtoken.v1 [flags]
6464
6565
Flags:
6666
-a, --auditors strings list of auditor MSP directories containing the corresponding auditor certificate
6767
--cc generate chaincode package
68-
-h, --help help for fabtoken
68+
-h, --help help for fabtoken.v1
6969
-s, --issuers strings list of issuer MSP directories containing the corresponding issuer certificate
7070
-o, --output string output folder (default ".")
7171
7272
```
7373

7474
The public parameters are stored in the output folder with name `fabtoken_pp.json`.
7575

76-
### tokengen gen dlog
76+
### tokengen gen zkatdlog.v1
7777

7878
```
7979
Usage:
80-
tokengen gen dlog [flags]
80+
tokengen gen zkatdlog.v1 [flags]
8181
8282
Flags:
8383
-a, --auditors strings list of auditor MSP directories containing the corresponding auditor certificate
8484
-b, --base int base is used to define the maximum quantity a token can contain as Base^Exponent (default 100)
8585
--cc generate chaincode package
8686
-e, --exponent int exponent is used to define the maximum quantity a token can contain as Base^Exponent (default 2)
87-
-h, --help help for dlog
87+
-h, --help help for zkatdlog.v1
8888
-i, --idemix string idemix msp dir
8989
-s, --issuers strings list of issuer MSP directories containing the corresponding issuer certificate
9090
-o, --output string output folder (default ".")
9191
```
9292

93-
The public parameters are stored in the output folder with name `zkatdlog_pp.json`.
93+
The public parameters are stored in the output folder with name `zkatdlognoghv1_pp.json`.
9494

95-
### tokengen update dlog
95+
### tokengen update zkatdlog.v1
9696

97-
This command takes an existing `zkatdlog_pp.json` and allows you to update the issuer and/or auditor certificates, while keeping the public parameters intact.
97+
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.
9898

9999
```
100100
Usage:
101-
tokengen update dlog [flags]
101+
tokengen update zkatdlog.v1 [flags]
102102
103103
Flags:
104104
-a, --auditors strings list of auditor MSP directories containing the corresponding auditor certificate
105-
-h, --help help for dlog
105+
-h, --help help for zkatdlog.v1
106106
-i, --input string path of the public param file
107107
-s, --issuers strings list of issuer MSP directories containing the corresponding issuer certificate
108108
-o, --output string output folder (default ".")

cmd/tokengen/cobra/certfier/keypairgen.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"os"
1212
"path/filepath"
1313

14+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/zkatdlognoghv1"
1415
driver2 "github.com/hyperledger-labs/fabric-token-sdk/token/core"
1516
fabtoken "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/driver"
16-
dlog "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/driver"
17+
dlogdriver "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/driver"
1718
"github.com/pkg/errors"
1819
"github.com/spf13/cobra"
1920
)
@@ -26,7 +27,7 @@ var output string
2627
func KeyPairGenCmd() *cobra.Command {
2728
// Set the flags on the node start command.
2829
flags := cobraCommand.Flags()
29-
flags.StringVarP(&driver, "driver", "d", "dlog", "driver (dlog)")
30+
flags.StringVarP(&driver, "driver", "d", zkatdlognoghv1.DriverIdentifier, "driver (dlog)")
3031
flags.StringVarP(&ppPath, "pppath", "p", "", "path to the public parameters file")
3132
flags.StringVarP(&output, "output", "o", ".", "output folder")
3233

@@ -56,7 +57,7 @@ func keyPairGen(args []string) error {
5657
if err != nil {
5758
return errors.Wrapf(err, "failed reading public parameters from [%s]", ppPath)
5859
}
59-
s := driver2.NewPPManagerFactoryService(fabtoken.NewPPMFactory(), dlog.NewPPMFactory())
60+
s := driver2.NewPPManagerFactoryService(fabtoken.NewPPMFactory(), dlogdriver.NewPPMFactory())
6061
pp, err := s.PublicParametersFromBytes(ppRaw)
6162
if err != nil {
6263
return errors.Wrapf(err, "failed unmarshalling public parameters loaded from [%s], len [%d]", ppPath, len(ppRaw))
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package fabtoken
7+
package fabtokenv1
88

99
import (
1010
"fmt"
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/cc"
1515
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/common"
16+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/fabtokenv1"
1617
v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/setup"
1718

1819
"github.com/pkg/errors"
@@ -44,7 +45,7 @@ func Cmd() *cobra.Command {
4445
}
4546

4647
var cobraCommand = &cobra.Command{
47-
Use: "fabtoken",
48+
Use: fabtokenv1.DriverIdentifier,
4849
Short: "Gen FabToken public parameters.",
4950
Long: `Generates FabToken public parameters.`,
5051
RunE: func(cmd *cobra.Command, args []string) error {

cmd/tokengen/cobra/pp/gen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ SPDX-License-Identifier: Apache-2.0
77
package pp
88

99
import (
10-
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/dlog"
11-
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/fabtoken"
10+
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/fabtokenv1"
11+
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/zkatdlognoghv1"
1212
"github.com/spf13/cobra"
1313
)
1414

1515
// GenCmd returns the Cobra Command for Public Params Generation
1616
func GenCmd() *cobra.Command {
17-
genCobraCommand.AddCommand(fabtoken.Cmd())
18-
genCobraCommand.AddCommand(dlog.Cmd())
17+
genCobraCommand.AddCommand(fabtokenv1.Cmd())
18+
genCobraCommand.AddCommand(zkatdlognoghv1.Cmd())
1919

2020
return genCobraCommand
2121
}

cmd/tokengen/cobra/pp/update.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ SPDX-License-Identifier: Apache-2.0
77
package pp
88

99
import (
10-
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/dlog"
10+
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/zkatdlognoghv1"
1111
"github.com/spf13/cobra"
1212
)
1313

1414
// UpdateCmd returns the Cobra Command for updating the config file
1515
func UpdateCmd() *cobra.Command {
1616
// not implemented for fabtoken
17-
updateCobraCommand.AddCommand(dlog.UpdateCmd())
17+
updateCobraCommand.AddCommand(zkatdlognoghv1.UpdateCmd())
1818

1919
return updateCobraCommand
2020
}

cmd/tokengen/cobra/pp/dlog/gen.go renamed to cmd/tokengen/cobra/pp/zkatdlognoghv1/gen.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package dlog
7+
package zkatdlognoghv1
88

99
import (
1010
"fmt"
@@ -15,6 +15,7 @@ import (
1515
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/cc"
1616
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/common"
1717
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/idemix"
18+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/zkatdlognoghv1"
1819
v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
1920
"github.com/pkg/errors"
2021
"github.com/spf13/cobra"
@@ -77,7 +78,7 @@ func Cmd() *cobra.Command {
7778
}
7879

7980
var cobraCommand = &cobra.Command{
80-
Use: "dlog",
81+
Use: zkatdlognoghv1.DriverIdentifier,
8182
Short: "Gen ZKAT DLog public parameters.",
8283
Long: `Generates ZKAT DLog public parameters.`,
8384
RunE: func(cmd *cobra.Command, args []string) error {
@@ -142,7 +143,7 @@ func Gen(args *GeneratorArgs) ([]byte, error) {
142143
if err != nil {
143144
return nil, errors.Wrap(err, "failed serializing public parameters")
144145
}
145-
path := filepath.Join(args.OutputDir, "zkatdlog_pp.json")
146+
path := filepath.Join(args.OutputDir, "zkatdlognoghv1_pp.json")
146147
if err := os.WriteFile(path, raw, 0755); err != nil {
147148
return nil, errors.Wrap(err, "failed writing public parameters to file")
148149
}

cmd/tokengen/cobra/pp/dlog/update.go renamed to cmd/tokengen/cobra/pp/zkatdlognoghv1/update.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Copyright IBM Corp. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
package dlog
7+
package zkatdlognoghv1
88

99
import (
1010
"fmt"
1111
"os"
1212
"path/filepath"
1313

1414
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/common"
15+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/zkatdlognoghv1"
1516
v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
1617
"github.com/pkg/errors"
1718
"github.com/spf13/cobra"
@@ -44,7 +45,7 @@ func UpdateCmd() *cobra.Command {
4445
}
4546

4647
var cmd = &cobra.Command{
47-
Use: "dlog",
48+
Use: zkatdlognoghv1.DriverIdentifier,
4849
Short: "Update certs in the public parameters file.",
4950
Long: "Update certs in the public parameters file without changing the parameters themselves.",
5051
RunE: func(cmd *cobra.Command, args []string) error {
@@ -78,7 +79,7 @@ func Update(args *UpdateArgs) error {
7879
return errors.Wrapf(err, "failed to read input file at [%s]", args.InputFile)
7980
}
8081

81-
pp, err := v1.NewPublicParamsFromBytes(oldraw, v1.DLogIdentifier, v1.ProtocolV1)
82+
pp, err := v1.NewPublicParamsFromBytes(oldraw, v1.DLogNoGHDriverName, v1.ProtocolV1)
8283
if err != nil {
8384
return errors.Wrapf(err, "failed to unmarshal pp from [%s]", args.InputFile)
8485
}
@@ -103,9 +104,9 @@ func Update(args *UpdateArgs) error {
103104
if err != nil {
104105
return errors.Wrap(err, "failed serializing public parameters")
105106
}
106-
path := filepath.Join(args.OutputDir, "zkatdlog_pp.json")
107+
path := filepath.Join(args.OutputDir, "zkatdlognoghv1_pp.json")
107108
if _, err := os.Stat(path); err == nil {
108-
return errors.New("zkatdlog_pp.json exists in current directory. Specify another output folder with -o")
109+
return errors.New("zkatdlognoghv1_pp.json exists in current directory. Specify another output folder with -o")
109110
}
110111
if err := os.WriteFile(path, raw, 0755); err != nil {
111112
return errors.Wrap(err, "failed writing public parameters to file")

cmd/tokengen/main_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"testing"
1515

1616
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/common"
17+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/fabtokenv1"
18+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/zkatdlognoghv1"
1719
v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
1820
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
1921
"github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/slices"
@@ -22,7 +24,7 @@ import (
2224
)
2325

2426
// To run this command, first make sure to install the tokengen tool. To do that run `make tokengen`.
25-
//go:generate tokengen gen dlog --idemix "./testdata/idemix" --issuers "./testdata/issuers/msp" --auditors "./testdata/auditors/msp" --output "./testdata"
27+
//go:generate tokengen gen zkatdlognogh.v1 --idemix "./testdata/idemix" --issuers "./testdata/issuers/msp" --auditors "./testdata/auditors/msp" --output "./testdata"
2628

2729
func TestCompile(t *testing.T) {
2830
gt := NewGomegaWithT(t)
@@ -45,7 +47,7 @@ func TestGenFullSuccess(t *testing.T) {
4547
tokengen,
4648
[]string{
4749
"gen",
48-
"dlog",
50+
zkatdlognoghv1.DriverIdentifier,
4951
"--idemix",
5052
"./testdata/idemix",
5153
"--issuers",
@@ -81,13 +83,13 @@ func TestFullUpdate(t *testing.T) {
8183
tokengen,
8284
[]string{
8385
"update",
84-
"dlog",
86+
zkatdlognoghv1.DriverIdentifier,
8587
"--issuers",
8688
"./testdata/auditors/msp",
8789
"--auditors",
8890
"./testdata/issuers/msp",
8991
"--input",
90-
"./testdata/zkatdlog_pp.json",
92+
"./testdata/zkatdlognoghv1_pp.json",
9193
"--output",
9294
tempOutput,
9395
},
@@ -118,11 +120,11 @@ func TestPartialUpdate(t *testing.T) {
118120
tokengen,
119121
[]string{
120122
"update",
121-
"dlog",
123+
zkatdlognoghv1.DriverIdentifier,
122124
"--issuers",
123125
"./testdata/auditors/msp",
124126
"--input",
125-
"./testdata/zkatdlog_pp.json",
127+
"./testdata/zkatdlognoghv1_pp.json",
126128
"--output",
127129
tempOutput,
128130
},
@@ -148,7 +150,7 @@ func TestGenFailure(t *testing.T) {
148150
ErrMsg string
149151
}
150152
var tests []T
151-
for _, driver := range []string{"fabtoken"} {
153+
for _, driver := range []string{fabtokenv1.DriverIdentifier} {
152154
tests = append(tests, []T{
153155
{
154156
Args: []string{
@@ -188,15 +190,15 @@ func TestGenFailure(t *testing.T) {
188190
{
189191
Args: []string{
190192
"gen",
191-
"dlog",
193+
zkatdlognoghv1.DriverIdentifier,
192194
"--issuers", "aOrg1MSP,b",
193195
},
194196
ErrMsg: "failed to generate public parameters: failed to load issuer public key: failed reading idemix issuer public key [msp/IssuerPublicKey]: open msp/IssuerPublicKey: no such file or directory",
195197
},
196198
{
197199
Args: []string{
198200
"gen",
199-
"dlog",
201+
zkatdlognoghv1.DriverIdentifier,
200202
"--idemix", "./testdata/idemix",
201203
"--issuers", "Error: failed to generate public parameters: failed to get issuer identity [aOrg1MSP]: invalid input [aOrg1MSP]",
202204
},
@@ -213,10 +215,10 @@ func TestGenFailure(t *testing.T) {
213215
}
214216

215217
func validateOutputEquivalent(gt *WithT, tempOutput, auditorsMSPdir, issuersMSPdir, idemixMSPdir string) {
216-
ppRaw, err := os.ReadFile(filepath.Join(tempOutput, "zkatdlog_pp.json"))
218+
ppRaw, err := os.ReadFile(filepath.Join(tempOutput, "zkatdlognoghv1_pp.json"))
217219
gt.Expect(err).NotTo(HaveOccurred())
218220

219-
pp, err := v1.NewPublicParamsFromBytes(ppRaw, v1.DLogIdentifier, v1.ProtocolV1)
221+
pp, err := v1.NewPublicParamsFromBytes(ppRaw, v1.DLogNoGHDriverName, v1.ProtocolV1)
220222
gt.Expect(err).NotTo(HaveOccurred())
221223
gt.Expect(pp.Validate()).NotTo(HaveOccurred())
222224

cmd/tokengen/samples/topology/fungible.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/artifactgen"
1515
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token"
1616
fabric2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric"
17+
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/zkatdlognoghv1"
1718
"github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
1819
tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
1920
)
@@ -116,7 +117,7 @@ func Topology(tokenSDKDriver string, sdks ...node.SDK) []api.Topology {
116117
}
117118

118119
func main() {
119-
if err := artifactgen.WriteTopologies("fungible.yaml", Topology("dlog", &tokensdk.SDK{}), 0766); err != nil {
120+
if err := artifactgen.WriteTopologies("fungible.yaml", Topology(zkatdlognoghv1.DriverIdentifier, &tokensdk.SDK{}), 0766); err != nil {
120121
panic(err)
121122
}
122123
}

cmd/tokengen/testdata/zkatdlog_pp.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)