Skip to content

Commit df44cab

Browse files
authored
various enhancements (#428)
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent 039211e commit df44cab

File tree

49 files changed

+541
-238
lines changed

Some content is hidden

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

49 files changed

+541
-238
lines changed

docs/core-token.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Example core.yaml section
2+
3+
The following example provides descriptions for the various keys required for a Fabric Smart Client node that uses the Token SDK.
4+
5+
```yaml
6+
# ------------------- Token SDK Configuration -------------------------
7+
token:
8+
# Is the token-sdk enabled
9+
enabled: true
10+
tms:
11+
mytms: # unique name of this token management system
12+
network: default # the name of the network this TMS refers to (Fabric, Orion, etc)
13+
channel: testchannel # the name of the network's channel this TMS refers to, if applicable
14+
namespace: tns # the name of the channel's namespace this TMS refers to, if applicable
15+
# sections dedicated to the definition of the wallets
16+
wallets:
17+
# owner wallets
18+
owners:
19+
- id: alice # the unique identifier of this wallet. Here is an example of use: `ttx.GetWallet(context, "alice")`
20+
default: true # is this the default owner wallet
21+
# path to the folder containing the cryptographic material associated to wallet.
22+
# The content of the folder is driver dependent
23+
path: /path/to/alice-wallet
24+
- id: alice.id1
25+
path: /path/to/alice.id1-wallet
26+
# issuer wallets
27+
issuers:
28+
- id: issuer # the unique identifier of this wallet. Here is an example of use: `ttx.GetIssuerWallet(context, "issuer)`
29+
default: true # is this the default issuer wallet
30+
# path to the folder containing the cryptographic material associated to wallet.
31+
# The content of the folder is driver dependent
32+
path: /path/to/issuer-wallet
33+
# additional options that can be used to instantiated the wallet.
34+
# options are driver dependent. With `fabtoken` and `dlog` drivers,
35+
# the following options apply
36+
opts:
37+
BCCSP:
38+
Default: SW
39+
PKCS11:
40+
Hash: SHA2
41+
Label: null
42+
Library: null
43+
Pin: null
44+
Security: 256
45+
SW:
46+
Hash: SHA2
47+
Security: 256
48+
# auditor wallets
49+
auditors:
50+
- id: auditor # the unique identifier of this wallet. Here is an example of use: `ttx.GetAuditorWallet(context, "auditor)`
51+
default: true # is this the default auditor wallet
52+
# path to the folder containing the cryptographic material associated to wallet.
53+
# The content of the folder is driver dependent
54+
path: /path/to/auditor-wallet
55+
# additional options that can be used to instantiated the wallet.
56+
# options are driver dependent. With `fabtoken` and `dlog` drivers,
57+
# the following options apply
58+
opts:
59+
BCCSP:
60+
Default: SW
61+
PKCS11:
62+
Hash: SHA2
63+
Label: null
64+
Library: null
65+
Pin: null
66+
Security: 256
67+
SW:
68+
Hash: SHA2
69+
Security: 256
70+
# Internal database to keep track of token transactions.
71+
# It is used by auditors and token owners to track history
72+
ttxdb:
73+
persistence:
74+
# type can be badger (disk) or memory
75+
type: badger
76+
opts:
77+
# persistence location
78+
path: /some/path
79+
```

docs/design.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ The `Smart Client` allows the `Token SDK` to:
3636
- Orchestrate very complex token-dependent business processes via [`views`](https://github.com/hyperledger-labs/fabric-smart-client/blob/main/docs/view/api.md);
3737
- Store the tokens inside the Vault for easy lookup and manipulation;
3838
- To listen to events from the backends related to token transaction, and more.
39+
40+
## Configuration
41+
42+
You can find an example of the configuration required for the Token SDK in [Example Core File Section](./core-token.md)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/dgraph-io/ristretto v0.1.0
1010
github.com/golang/protobuf v1.5.2
1111
github.com/hashicorp/go-uuid v1.0.2
12-
github.com/hyperledger-labs/fabric-smart-client v0.1.0
12+
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221130141649-2080c0c69de1
1313
github.com/hyperledger-labs/orion-sdk-go v0.2.5
1414
github.com/hyperledger-labs/orion-server v0.2.5
1515
github.com/hyperledger/fabric v1.4.0-rc1.0.20220808214918-83596078d0c3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,8 @@ github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmK
805805
github.com/huin/goupnp v1.0.0 h1:wg75sLpL6DZqwHQN6E1Cfk6mtfzS45z8OV+ic+DtHRo=
806806
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
807807
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
808-
github.com/hyperledger-labs/fabric-smart-client v0.1.0 h1:Co7vzD037WscPxQrjv2TGiONX+FAocXxBwwcTg414dA=
809-
github.com/hyperledger-labs/fabric-smart-client v0.1.0/go.mod h1:WtNWdKVbF9R1/2hIBVQUlR9Zl3T0TdkzUcCQTc2Eqk4=
808+
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221130141649-2080c0c69de1 h1:F5/QSzgJsQS0rFsO8YK2mAQ0VU8ZclQrprzt82Z0PeU=
809+
github.com/hyperledger-labs/fabric-smart-client v0.1.1-0.20221130141649-2080c0c69de1/go.mod h1:WtNWdKVbF9R1/2hIBVQUlR9Zl3T0TdkzUcCQTc2Eqk4=
810810
github.com/hyperledger-labs/orion-sdk-go v0.2.5 h1:HFGRTuMZgzo9EtyJeFAhVSlbrj6x3jtY0aDcghdjzRE=
811811
github.com/hyperledger-labs/orion-sdk-go v0.2.5/go.mod h1:At8hiFATfkDXQ4AFLVbaTiC9GDhVDo8aN/supb1KBb4=
812812
github.com/hyperledger-labs/orion-server v0.2.5 h1:aFudmB9SAnsT5v8jhazkuszEu0pdJNFqaYZF2GpvAuI=

integration/nwo/token/fabric/fabric.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (p *NetworkHandler) GenerateArtifacts(tms *topology2.TMS) {
157157

158158
func (p *NetworkHandler) GenerateExtension(tms *topology2.TMS, node *sfcnode.Node) string {
159159
t, err := template.New("peer").Funcs(template.FuncMap{
160+
"TMSID": func() string { return tms.ID() },
160161
"TMS": func() *topology2.TMS { return tms },
161162
"Wallets": func() *generators.Wallets { return p.GetEntry(tms).Wallets[node.Name] },
162163
}).Parse(Extension)

integration/nwo/token/fabric/template.go

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,82 @@ token:
1212
# namespace identifiers. The network identifier should refer to a configure network (Fabric, Orion, and so on).
1313
# The meaning of channel and namespace are network dependant. For Fabric, the meaning is clear.
1414
# For Orion, channel is empty and namespace is the DB name to use.
15-
tms:
16-
- # Network identifier this TMS refers to
17-
network: {{ TMS.Network }}
18-
# Channel identifier within the specified network
19-
channel: {{ TMS.Channel }}
20-
# Namespace identifier within the specified channel
21-
namespace: {{ TMS.Namespace }}
22-
certification:
23-
{{ if TMS.Certifiers }} interactive:
24-
ids: {{ range TMS.Certifiers }}
25-
- {{ . }}{{ end }}{{ end }}
26-
{{ if Wallets }}
27-
# Wallets associated with this TMS
28-
wallets:{{ if Wallets.Certifiers }}
29-
# Certifiers wallets are used to certify tokens
30-
certifiers: {{ range Wallets.Certifiers }}
31-
- id: {{ .ID }}
32-
default: {{ .Default }}
33-
path: {{ .Path }}
15+
tms:
16+
{{ TMSID }}:
17+
# Network identifier this TMS refers to
18+
network: {{ TMS.Network }}
19+
# Channel identifier within the specified network
20+
channel: {{ TMS.Channel }}
21+
# Namespace identifier within the specified channel
22+
namespace: {{ TMS.Namespace }}
23+
certification:
24+
{{ if TMS.Certifiers }} interactive:
25+
ids: {{ range TMS.Certifiers }}
26+
- {{ . }}{{ end }}{{ end }}
27+
{{ if Wallets }}
28+
# Wallets associated with this TMS
29+
wallets:{{ if Wallets.Certifiers }}
30+
# Certifiers wallets are used to certify tokens
31+
certifiers: {{ range Wallets.Certifiers }}
32+
- id: {{ .ID }}
33+
default: {{ .Default }}
34+
path: {{ .Path }}
35+
{{ end }}
36+
{{ end }}{{ if Wallets.Issuers }}
37+
# Issuers wallets are used to issue tokens
38+
issuers: {{ range Wallets.Issuers }}
39+
- id: {{ .ID }}
40+
default: {{ .Default }}
41+
path: {{ .Path }}
42+
opts:
43+
BCCSP:
44+
Default: {{ .Opts.Default }}
45+
# Settings for the SW crypto provider (i.e. when DEFAULT: SW)
46+
SW:
47+
Hash: {{ .Opts.SW.Hash }}
48+
Security: {{ .Opts.SW.Security }}
49+
# Settings for the PKCS#11 crypto provider (i.e. when DEFAULT: PKCS11)
50+
PKCS11:
51+
# Location of the PKCS11 module library
52+
Library: {{ .Opts.PKCS11.Library }}
53+
# Token Label
54+
Label: {{ .Opts.PKCS11.Label }}
55+
# User PIN
56+
Pin: {{ .Opts.PKCS11.Pin }}
57+
Hash: {{ .Opts.PKCS11.Hash }}
58+
Security: {{ .Opts.PKCS11.Security }}
59+
{{ end }}
60+
{{ end }}{{ if Wallets.Owners }}
61+
# Owners wallets are used to own tokens
62+
owners: {{ range Wallets.Owners }}
63+
- id: {{ .ID }}
64+
default: {{ .Default }}
65+
path: {{ .Path }}
66+
{{ end }}
67+
{{ end }}{{ if Wallets.Auditors }}
68+
# Auditors wallets are used to audit tokens
69+
auditors: {{ range Wallets.Auditors }}
70+
- id: {{ .ID }}
71+
default: {{ .Default }}
72+
path: {{ .Path }}
73+
opts:
74+
BCCSP:
75+
Default: {{ .Opts.Default }}
76+
# Settings for the SW crypto provider (i.e. when DEFAULT: SW)
77+
SW:
78+
Hash: {{ .Opts.SW.Hash }}
79+
Security: {{ .Opts.SW.Security }}
80+
# Settings for the PKCS#11 crypto provider (i.e. when DEFAULT: PKCS11)
81+
PKCS11:
82+
# Location of the PKCS11 module library
83+
Library: {{ .Opts.PKCS11.Library }}
84+
# Token Label
85+
Label: {{ .Opts.PKCS11.Label }}
86+
# User PIN
87+
Pin: {{ .Opts.PKCS11.Pin }}
88+
Hash: {{ .Opts.PKCS11.Hash }}
89+
Security: {{ .Opts.PKCS11.Security }}
90+
{{ end }}
3491
{{ end }}
35-
{{ end }}{{ if Wallets.Issuers }}
36-
# Issuers wallets are used to issue tokens
37-
issuers: {{ range Wallets.Issuers }}
38-
- id: {{ .ID }}
39-
default: {{ .Default }}
40-
path: {{ .Path }}
41-
opts:
42-
BCCSP:
43-
Default: {{ .Opts.Default }}
44-
# Settings for the SW crypto provider (i.e. when DEFAULT: SW)
45-
SW:
46-
Hash: {{ .Opts.SW.Hash }}
47-
Security: {{ .Opts.SW.Security }}
48-
# Settings for the PKCS#11 crypto provider (i.e. when DEFAULT: PKCS11)
49-
PKCS11:
50-
# Location of the PKCS11 module library
51-
Library: {{ .Opts.PKCS11.Library }}
52-
# Token Label
53-
Label: {{ .Opts.PKCS11.Label }}
54-
# User PIN
55-
Pin: {{ .Opts.PKCS11.Pin }}
56-
Hash: {{ .Opts.PKCS11.Hash }}
57-
Security: {{ .Opts.PKCS11.Security }}
5892
{{ end }}
59-
{{ end }}{{ if Wallets.Owners }}
60-
# Owners wallets are used to own tokens
61-
owners: {{ range Wallets.Owners }}
62-
- id: {{ .ID }}
63-
default: {{ .Default }}
64-
path: {{ .Path }}
65-
{{ end }}
66-
{{ end }}{{ if Wallets.Auditors }}
67-
# Auditors wallets are used to audit tokens
68-
auditors: {{ range Wallets.Auditors }}
69-
- id: {{ .ID }}
70-
default: {{ .Default }}
71-
path: {{ .Path }}
72-
opts:
73-
BCCSP:
74-
Default: {{ .Opts.Default }}
75-
# Settings for the SW crypto provider (i.e. when DEFAULT: SW)
76-
SW:
77-
Hash: {{ .Opts.SW.Hash }}
78-
Security: {{ .Opts.SW.Security }}
79-
# Settings for the PKCS#11 crypto provider (i.e. when DEFAULT: PKCS11)
80-
PKCS11:
81-
# Location of the PKCS11 module library
82-
Library: {{ .Opts.PKCS11.Library }}
83-
# Token Label
84-
Label: {{ .Opts.PKCS11.Label }}
85-
# User PIN
86-
Pin: {{ .Opts.PKCS11.Pin }}
87-
Hash: {{ .Opts.PKCS11.Hash }}
88-
Security: {{ .Opts.PKCS11.Security }}
89-
{{ end }}
90-
{{ end }}
91-
{{ end }}
92-
`
93+
`

integration/nwo/token/orion/orion.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func (p *NetworkHandler) GenerateArtifacts(tms *topology2.TMS) {
117117

118118
func (p *NetworkHandler) GenerateExtension(tms *topology2.TMS, node *sfcnode.Node) string {
119119
t, err := template.New("peer").Funcs(template.FuncMap{
120+
"TMSID": func() string { return tms.ID() },
120121
"TMS": func() *topology2.TMS { return tms },
121122
"Wallets": func() *generators.Wallets { return p.GetEntry(tms).Wallets[node.Name] },
122123
"IsCustodian": func() bool {

integration/nwo/token/orion/template.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,42 @@ package orion
99
const Extension = `
1010
token:
1111
tms:
12-
- network: {{ TMS.Network }}
13-
channel: {{ TMS.Channel }}
14-
namespace: {{ TMS.Namespace }}
15-
orion:
16-
custodian:
17-
id: {{ CustodianID }}
18-
enabled: {{ IsCustodian }}
19-
certification:
20-
interactive:
21-
ids: {{ range TMS.Certifiers }}
22-
- {{ . }}{{ end }}
23-
{{ if Wallets }}wallets:{{ if Wallets.Certifiers }}
24-
certifiers: {{ range Wallets.Certifiers }}
25-
- id: {{ .ID }}
26-
default: {{ .Default }}
27-
path: {{ .Path }}
12+
{{ TMSID }}:
13+
network: {{ TMS.Network }}
14+
channel: {{ TMS.Channel }}
15+
namespace: {{ TMS.Namespace }}
16+
orion:
17+
custodian:
18+
id: {{ CustodianID }}
19+
enabled: {{ IsCustodian }}
20+
certification:
21+
interactive:
22+
ids: {{ range TMS.Certifiers }}
23+
- {{ . }}{{ end }}
24+
{{ if Wallets }}wallets:{{ if Wallets.Certifiers }}
25+
certifiers: {{ range Wallets.Certifiers }}
26+
- id: {{ .ID }}
27+
default: {{ .Default }}
28+
path: {{ .Path }}
29+
{{ end }}
30+
{{ end }}{{ if Wallets.Issuers }}
31+
issuers: {{ range Wallets.Issuers }}
32+
- id: {{ .ID }}
33+
default: {{ .Default }}
34+
path: {{ .Path }}
35+
{{ end }}
36+
{{ end }}{{ if Wallets.Owners }}
37+
owners: {{ range Wallets.Owners }}
38+
- id: {{ .ID }}
39+
default: {{ .Default }}
40+
path: {{ .Path }}
41+
{{ end }}
42+
{{ end }}{{ if Wallets.Auditors }}
43+
auditors: {{ range Wallets.Auditors }}
44+
- id: {{ .ID }}
45+
default: {{ .Default }}
46+
path: {{ .Path }}
47+
{{ end }}
2848
{{ end }}
29-
{{ end }}{{ if Wallets.Issuers }}
30-
issuers: {{ range Wallets.Issuers }}
31-
- id: {{ .ID }}
32-
default: {{ .Default }}
33-
path: {{ .Path }}
3449
{{ end }}
35-
{{ end }}{{ if Wallets.Owners }}
36-
owners: {{ range Wallets.Owners }}
37-
- id: {{ .ID }}
38-
default: {{ .Default }}
39-
path: {{ .Path }}
40-
{{ end }}
41-
{{ end }}{{ if Wallets.Auditors }}
42-
auditors: {{ range Wallets.Auditors }}
43-
- id: {{ .ID }}
44-
default: {{ .Default }}
45-
path: {{ .Path }}
46-
{{ end }}
47-
{{ end }}
48-
{{ end }}
4950
`

integration/nwo/token/platform.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const (
3535
DefaultTokenGenPath = "github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen"
3636
)
3737

38+
type PF interface {
39+
GetTopology() *Topology
40+
GenIssuerCryptoMaterial(tmsNetwork string, fscNode string, walletID string) string
41+
GenOwnerCryptoMaterial(tmsNetwork string, fscNode string, walletID string) string
42+
}
43+
3844
type NetworkHandler interface {
3945
GenerateArtifacts(tms *topology2.TMS)
4046
GenerateExtension(tms *topology2.TMS, node *sfcnode.Node) string
@@ -75,12 +81,12 @@ func NewPlatform(ctx api2.Context, t api2.Topology, builder api2.Builder) *Platf
7581

7682
// GetPlatform returns the token platform from the passed context bound to the passed id.
7783
// It returns nil, if nothing is found
78-
func GetPlatform(ctx *context.Context, id string) *Platform {
84+
func GetPlatform(ctx *context.Context, id string) PF {
7985
p := ctx.PlatformByName(id)
8086
if p == nil {
8187
return nil
8288
}
83-
fp, ok := p.(*Platform)
89+
fp, ok := p.(PF)
8490
if ok {
8591
return fp
8692
}
@@ -270,6 +276,10 @@ func (p *Platform) FSCNodeKVSDir(peer *sfcnode.Node) string {
270276
return filepath.Join(p.Context.RootDir(), "fsc", "nodes", peer.ID(), "kvs")
271277
}
272278

279+
func (p *Platform) GetTopology() *Topology {
280+
return p.Topology
281+
}
282+
273283
func (p *Platform) nextColor() string {
274284
color := p.ColorIndex%14 + 31
275285
if color > 37 {

0 commit comments

Comments
 (0)