Skip to content

Commit 125d10a

Browse files
committed
make generators versioned, add input interface for validator context
Signed-off-by: Arne Rutjes <arne123@gmail.com>
1 parent 0330979 commit 125d10a

File tree

12 files changed

+50
-27
lines changed

12 files changed

+50
-27
lines changed

integration/nwo/token/generators/pp/fabtokenv1/gen.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@ import (
1313
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1414
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
1515
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology"
16+
"github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/setup"
1617
fabtokenv1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/setup"
18+
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
1719
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity"
1820
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs"
1921
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/x509"
2022
)
2123

22-
type FabTokenPublicParamsGenerator struct{}
24+
type FabTokenPublicParamsGenerator struct {
25+
DriverVersion driver.TokenDriverVersion
26+
}
2327

24-
func NewFabTokenPublicParamsGenerator() *FabTokenPublicParamsGenerator {
25-
return &FabTokenPublicParamsGenerator{}
28+
func NewFabTokenPublicParamsGenerator(version driver.TokenDriverVersion) *FabTokenPublicParamsGenerator {
29+
gen := &FabTokenPublicParamsGenerator{
30+
DriverVersion: setup.ProtocolV1,
31+
}
32+
if version > 0 {
33+
gen.DriverVersion = version
34+
}
35+
return gen
2636
}
2737

2838
func (f *FabTokenPublicParamsGenerator) Generate(tms *topology.TMS, wallets *topology.Wallets, args ...interface{}) ([]byte, error) {
@@ -41,7 +51,7 @@ func (f *FabTokenPublicParamsGenerator) Generate(tms *topology.TMS, wallets *top
4151
return nil, errors.Wrapf(err, "failed to parse max token value [%s] to uint64", precisionStr)
4252
}
4353
}
44-
pp, err := fabtokenv1.Setup(precision)
54+
pp, err := fabtokenv1.WithVersion(precision, f.DriverVersion)
4555
if err != nil {
4656
return nil, err
4757
}

integration/nwo/token/generators/pp/zkatdlognoghv1/gen.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,24 @@ import (
1919
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/generators/crypto/zkatdlognoghv1"
2020
"github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology"
2121
dlognoghv1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
22+
"github.com/hyperledger-labs/fabric-token-sdk/token/driver"
2223
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity"
2324
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs"
2425
"github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/x509"
2526
)
2627

2728
type DLogPublicParamsGenerator struct {
2829
DefaultCurveID math3.CurveID
30+
DriverVersion driver.TokenDriverVersion
2931
}
3032

31-
func NewDLogPublicParamsGenerator(defaultCurveID math3.CurveID) *DLogPublicParamsGenerator {
32-
return &DLogPublicParamsGenerator{DefaultCurveID: defaultCurveID}
33+
// NewDLogPublicParamsGenerator creates a new generator. The version is optional and defaults to v1.
34+
func NewDLogPublicParamsGenerator(defaultCurveID math3.CurveID, version driver.TokenDriverVersion) *DLogPublicParamsGenerator {
35+
gen := &DLogPublicParamsGenerator{DefaultCurveID: defaultCurveID, DriverVersion: dlognoghv1.ProtocolV1}
36+
if version > 0 {
37+
gen.DriverVersion = version
38+
}
39+
return gen
3340
}
3441

3542
func (d *DLogPublicParamsGenerator) Generate(tms *topology.TMS, wallets *topology.Wallets, args ...interface{}) ([]byte, error) {
@@ -63,7 +70,7 @@ func (d *DLogPublicParamsGenerator) Generate(tms *topology.TMS, wallets *topolog
6370
return nil, err
6471
}
6572
}
66-
pp, err := dlognoghv1.Setup(bits, ipkBytes, curveID)
73+
pp, err := dlognoghv1.WithVersion(bits, ipkBytes, curveID, d.DriverVersion)
6774
if err != nil {
6875
return nil, err
6976
}

integration/nwo/token/platform.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func NewPlatform(ctx api2.Context, t api2.Topology, builder api2.Builder) *Platf
8484
TokenGenPath: DefaultTokenGenPath,
8585
NetworkHandlers: map[string]NetworkHandler{},
8686
}
87-
p.PublicParamsGenerators[fabtokenv1.DriverIdentifier] = fabtokenv2.NewFabTokenPublicParamsGenerator()
88-
p.PublicParamsGenerators[zkatdlognoghv1.DriverIdentifier] = common2.NewDLogPublicParamsGenerator(math3.BN254)
87+
p.PublicParamsGenerators[fabtokenv1.DriverIdentifier] = fabtokenv2.NewFabTokenPublicParamsGenerator(0)
88+
p.PublicParamsGenerators[zkatdlognoghv1.DriverIdentifier] = common2.NewDLogPublicParamsGenerator(math3.BN254, 0)
8989

9090
return p
9191
}

token/core/common/validator.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
TokenRequestSignatures driver.ValidationAttributeID = "sigs"
2323
)
2424

25-
type Context[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] struct {
25+
type Context[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] struct {
2626
Logger logging.Logger
2727
PP P
2828
Anchor driver.TokenRequestAnchor
@@ -42,17 +42,17 @@ func (c *Context[P, T, TA, IA, DS]) CountMetadataKey(key string) {
4242
c.MetadataCounter[key] = c.MetadataCounter[key] + 1
4343
}
4444

45-
type ValidateTransferFunc[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(c context.Context, ctx *Context[P, T, TA, IA, DS]) error
45+
type ValidateTransferFunc[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(c context.Context, ctx *Context[P, T, TA, IA, DS]) error
4646

47-
type ValidateIssueFunc[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(c context.Context, ctx *Context[P, T, TA, IA, DS]) error
47+
type ValidateIssueFunc[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(c context.Context, ctx *Context[P, T, TA, IA, DS]) error
4848

49-
type ValidateAuditingFunc[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(c context.Context, ctx *Context[P, T, TA, IA, DS]) error
49+
type ValidateAuditingFunc[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] func(c context.Context, ctx *Context[P, T, TA, IA, DS]) error
5050

5151
type ActionDeserializer[TA driver.TransferAction, IA driver.IssueAction] interface {
5252
DeserializeActions(tr *driver.TokenRequest) ([]IA, []TA, error)
5353
}
5454

55-
type Validator[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] struct {
55+
type Validator[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer] struct {
5656
Logger logging.Logger
5757
PublicParams P
5858
Deserializer DS
@@ -63,7 +63,7 @@ type Validator[P driver.PublicParameters, T any, TA driver.TransferAction, IA dr
6363
IssueValidators []ValidateIssueFunc[P, T, TA, IA, DS]
6464
}
6565

66-
func NewValidator[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](
66+
func NewValidator[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](
6767
Logger logging.Logger,
6868
publicParams P,
6969
deserializer DS,

token/core/common/validator_auditing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
ErrAuditorSignaturesPresent = errors.New("auditor signatures present")
2020
)
2121

22-
func AuditingSignaturesValidate[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
22+
func AuditingSignaturesValidate[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
2323
if len(ctx.PP.Auditors()) == 0 {
2424
// enforce no auditor signatures are attached
2525
if len(ctx.TokenRequest.AuditorSignatures) != 0 {

token/core/common/validator_auditing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
type (
20-
TestContext = Context[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]
20+
TestContext = Context[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]
2121
TestCheck = func() bool
2222
)
2323

token/core/common/validator_issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
// IssueApplicationDataValidate accepts any metadata in the "pub" namespace.
1818
// This gives the user of the Token SDK the option to attach public data to the token transaction.
19-
func IssueApplicationDataValidate[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
19+
func IssueApplicationDataValidate[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
2020
for key := range ctx.IssueAction.GetMetadata() {
2121
if strings.HasPrefix(key, meta.PublicMetadataPrefix) {
2222
ctx.CountMetadataKey(key)

token/core/common/validator_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ import (
2121
func TestAnchorInContext(t *testing.T) {
2222
anchor := driver.TokenRequestAnchor("hello world")
2323
anotherAnchor := driver.TokenRequestAnchor("another anchor")
24-
v := NewValidator[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer](
24+
v := NewValidator[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer](
2525
nil,
2626
nil,
2727
nil,
2828
nil,
29-
[]ValidateTransferFunc[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]{
30-
func(c context.Context, ctx *Context[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]) error {
29+
[]ValidateTransferFunc[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]{
30+
func(c context.Context, ctx *Context[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]) error {
3131
if anchor != ctx.Anchor {
3232
return fmt.Errorf("transfer, anchor does not match, expected %s, got %s", anchor, ctx.Anchor)
3333
}
3434
return nil
3535
},
3636
},
37-
[]ValidateIssueFunc[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]{
38-
func(c context.Context, ctx *Context[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]) error {
37+
[]ValidateIssueFunc[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]{
38+
func(c context.Context, ctx *Context[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]) error {
3939
if anchor != ctx.Anchor {
4040
return fmt.Errorf("issue, anchor does not match, expected %s, got %s", anchor, ctx.Anchor)
4141
}
4242
return nil
4343
},
4444
},
45-
[]ValidateAuditingFunc[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]{
46-
func(c context.Context, ctx *Context[driver.PublicParameters, any, driver.TransferAction, driver.IssueAction, driver.Deserializer]) error {
45+
[]ValidateAuditingFunc[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]{
46+
func(c context.Context, ctx *Context[driver.PublicParameters, driver.Input, driver.TransferAction, driver.IssueAction, driver.Deserializer]) error {
4747
if anchor != ctx.Anchor {
4848
return fmt.Errorf("audit, anchor does not match, expected %s, got %s", anchor, ctx.Anchor)
4949
}

token/core/common/validator_transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
// TransferApplicationDataValidate accepts any metadata in the "pub" namespace.
1818
// This gives the user of the Token SDK the option to attach public data to the token transaction.
19-
func TransferApplicationDataValidate[P driver.PublicParameters, T any, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
19+
func TransferApplicationDataValidate[P driver.PublicParameters, T driver.Input, TA driver.TransferAction, IA driver.IssueAction, DS driver.Deserializer](c context.Context, ctx *Context[P, T, TA, IA, DS]) error {
2020
for key := range ctx.TransferAction.GetMetadata() {
2121
if strings.HasPrefix(key, meta.PublicMetadataPrefix) {
2222
ctx.CountMetadataKey(key)

0 commit comments

Comments
 (0)