Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GINKGO_TEST_OPTS ?=
#GINKGO_TEST_OPTS += --keep-going
GINKGO_TEST_OPTS += --vv
#GINKGO_TEST_OPTS += --until-it-fails
GINKGO_TEST_OPTS += --poll-progress-after 60s
GINKGO_TEST_OPTS += --fail-fast
#GINKGO_TEST_OPTS += --focus "generate artifacts & successful pingpong"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
driver3 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/chaincode"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/committer"
Expand Down Expand Up @@ -41,7 +40,6 @@ type provider struct {
metadataKVS driver.MetadataStore
endorseTxKVS driver.EndorseTxStore
publisher events.Publisher
hasher hash.Hasher
newVault generic.VaultConstructor
tracerProvider tracing.Provider
metricsProvider metrics.Provider
Expand All @@ -58,7 +56,6 @@ func NewChannelProvider(
metadataKVS driver.MetadataStore,
endorseTxKVS driver.EndorseTxStore,
publisher events.Publisher,
hasher hash.Hasher,
tracerProvider tracing.Provider,
metricsProvider metrics.Provider,
drivers multiplexed.Driver,
Expand All @@ -74,7 +71,6 @@ func NewChannelProvider(
metadataKVS: metadataKVS,
endorseTxKVS: endorseTxKVS,
publisher: publisher,
hasher: hasher,
newVault: newVault,
tracerProvider: tracerProvider,
metricsProvider: metricsProvider,
Expand Down Expand Up @@ -120,7 +116,6 @@ func (p *provider) NewChannel(nw driver.FabricNetworkService, channelName string
nw.ConfigService(),
peerService,
nw.LocalMembership().DefaultSigningIdentity(),
p.hasher,
channelConfig.FinalityWaitTimeout(),
true,
)
Expand Down Expand Up @@ -180,7 +175,6 @@ func (p *provider) NewChannel(nw driver.FabricNetworkService, channelName string
deliveryService, err := delivery.NewService(
channelName,
channelConfig,
p.hasher,
nw.Name(),
nw.LocalMembership(),
nw.ConfigService(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
committer2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/core/generic/committer"
cdriver "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/committer"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/driver/config"
Expand Down Expand Up @@ -62,7 +61,6 @@ func NewProvider(
idProvider identity.ViewIdentityProvider,
kvss *kvs.KVS,
publisher events.Publisher,
hasher hash.Hasher,
tracerProvider tracing.Provider,
Drivers multiplexed.Driver,
) *Provider {
Expand All @@ -74,7 +72,6 @@ func NewProvider(
metadataKVS,
endorseTxKVS,
publisher,
hasher,
tracerProvider,
metricsProvider,
Drivers,
Expand Down
3 changes: 0 additions & 3 deletions docs/platform/fabric/fabricdev/sdk/fabricdev/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package fabricdev

import (
fdevdriver "github.com/hyperledger-labs/fabric-smart-client/docs/platform/fabric/fabricdev/core/fabricdev/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/driver/config"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/driver/identity"
Expand Down Expand Up @@ -37,7 +36,6 @@ func NewDriver(in struct {
IdProvider identity.ViewIdentityProvider
KVS *kvs.KVS
Publisher events.Publisher
Hasher hash.Hasher
TracerProvider tracing.Provider
Drivers multiplexed.Driver
}) core.NamedDriver {
Expand All @@ -55,7 +53,6 @@ func NewDriver(in struct {
in.IdProvider,
in.KVS,
in.Publisher,
in.Hasher,
in.TracerProvider,
in.Drivers,
),
Expand Down
6 changes: 2 additions & 4 deletions integration/fabric/atsa/states/states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ func TestJson(t *testing.T) {
o, err := json.MarshalIndent(asset, "", " ")
assert.NoError(err)
fmt.Println(string(o))
hash := sha256.New()
hash.Write([]byte("Hello World!!!"))
rawHashed := hash.Sum(nil)
asset.PrivateProperties = []byte(base64.StdEncoding.EncodeToString(rawHashed))
rawHashed := sha256.Sum256([]byte("Hello World!!!"))
asset.PrivateProperties = []byte(base64.StdEncoding.EncodeToString(rawHashed[:]))
o, err = json.MarshalIndent(asset, "", " ")
assert.NoError(err)
fmt.Println(string(o))
Expand Down
5 changes: 2 additions & 3 deletions integration/fabric/atsachaincode/chaincode/asset_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,8 @@ func (s *SmartContract) VerifyAssetProperties(ctx contractapi.TransactionContext
return false, fmt.Errorf("asset private properties hash does not exist: %s", assetID)
}

hash := sha256.New()
hash.Write(immutablePropertiesJSON)
calculatedPropertiesHash := hash.Sum(nil)
h := sha256.Sum256(immutablePropertiesJSON)
calculatedPropertiesHash := h[:]

// verify that the hash of the passed immutable properties matches the on-chain hash
if !bytes.Equal(immutablePropertiesOnChainHash, calculatedPropertiesHash) {
Expand Down
4 changes: 2 additions & 2 deletions integration/fabricx/iou/iou_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (

"github.com/hyperledger-labs/fabric-smart-client/integration"
"github.com/hyperledger-labs/fabric-smart-client/integration/fabricx/iou"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
nwofabricx "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabricx"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabricx/fxconfig"
nwofsc "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc"
"github.com/hyperledger/fabric/integration/nwo"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -76,7 +76,7 @@ func updateEP(s *TestSuite) {
Version: 0,
}

cmd := nwo.NewCommand(fxconfig.CMDPath(), command)
cmd := common.NewCommand(fxconfig.CMDPath(), command)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
err := cmd.Run()
Expand Down
4 changes: 2 additions & 2 deletions integration/nwo/common/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"encoding/base32"
"strings"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils"
)

// UniqueName generates base-32 enocded UUIDs for container names.
func UniqueName() string {
name := base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(util.GenerateBytesUUID())
name := base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(utils.GenerateBytesUUID())
return strings.ToLower(name)
}
4 changes: 2 additions & 2 deletions integration/nwo/fabric/topology/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ SPDX-License-Identifier: Apache-2.0
package topology

import (
"crypto/sha256"
"fmt"
"os"

"github.com/hyperledger/fabric/common/util"
"github.com/onsi/gomega"
)

Expand All @@ -37,7 +37,7 @@ type Chaincode struct {
func (c *Chaincode) SetPackageIDFromPackageFile() {
fileBytes, err := os.ReadFile(c.PackageFile)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
hashStr := fmt.Sprintf("%x", util.ComputeSHA256(fileBytes))
hashStr := fmt.Sprintf("%x", sha256.Sum256(fileBytes))
c.PackageID = c.Label + ":" + hashStr
}

Expand Down
8 changes: 4 additions & 4 deletions integration/nwo/fabricx/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"time"

"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/commands"
fabric_network "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/network"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabricx/fxconfig"
"github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
"github.com/hyperledger/fabric/integration/nwo"
"github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -168,7 +168,7 @@ func (n *Network) PostRun(load bool) {
gomega.Eventually(func(g gomega.Gomega) {
// TODO: set the correct query service endpoint
cmd := &fxconfig.ListNamespaces{QueryServiceEndpoint: "127.0.0.1:7001"}
sess, err := n.StartSession(nwo.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
sess, err := n.StartSession(common.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
g.Expect(err).NotTo(gomega.HaveOccurred())
g.Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))

Expand Down Expand Up @@ -211,7 +211,7 @@ func (n *Network) DeployNamespace(chaincode *topology.ChannelChaincode) {
},
},
}
sess, err := n.StartSession(nwo.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
sess, err := n.StartSession(common.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
}
Expand All @@ -223,7 +223,7 @@ func (n *Network) UpdateNamespace(chaincodeID, version, path, packageFile string

func (n *Network) ListInstalledNames() {
cmd := &fxconfig.ListNamespaces{QueryServiceEndpoint: "127.0.0.1:7001"}
sess, err := n.StartSession(nwo.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
sess, err := n.StartSession(common.NewCommand(fxconfig.CMDPath(), cmd), cmd.SessionName())
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Eventually(sess, n.EventuallyTimeout).Should(gexec.Exit(0))
}
2 changes: 0 additions & 2 deletions integration/nwo/fsc/fsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/grpc"
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/storage/driver"
common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/storage/driver/common"
Expand Down Expand Up @@ -264,7 +263,6 @@ func (p *Platform) PostRun(bool) {
ConnectionConfig: p.Context.ConnectionConfig(node.UniqueName),
},
p.Context.ClientSigningIdentity(node.Name),
hash.NewSHA256Provider(),
tracerProvider,
)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions platform/common/core/generic/vault/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
)

type VersionedQueryExecutor interface {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (i *Interceptor[V]) SetState(namespace string, key string, value []byte) er
if i.IsClosed() {
return errors.New("this instance was closed")
}
i.logger.Debugf("SetState [%s,%s,%s]", namespace, key, hash.Hashable(value).String())
i.logger.Debugf("SetState [%s,%s,%s]", namespace, key, logging.SHA256Base64(value))

return i.rws.WriteSet.Add(namespace, key, value)
}
Expand Down
9 changes: 5 additions & 4 deletions platform/common/services/identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ package identity

import (
"bytes"
"crypto/sha256"
"encoding/base64"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
)

// Identity wraps the byte representation of a lower level identity.
Expand All @@ -26,15 +25,17 @@ func (id Identity) UniqueID() string {
if len(id) == 0 {
return "<empty>"
}
return base64.StdEncoding.EncodeToString(utils.MustGet(utils.SHA256(id)))
h := sha256.Sum256(id)
return base64.StdEncoding.EncodeToString(h[:])
}

// Hash returns the hash of this identity
func (id Identity) Hash() string {
if len(id) == 0 {
return "<empty>"
}
return string(utils.MustGet(utils.SHA256(id)))
h := sha256.Sum256(id)
return string(h[:])
}

// String returns a string representation of this identity
Expand Down
16 changes: 14 additions & 2 deletions platform/common/services/logging/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package logging

import (
"crypto/sha256"
"encoding/base64"
"fmt"
"reflect"
Expand All @@ -15,7 +16,6 @@ import (
"unicode"

"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/collections"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/utils/hash"
)

const (
Expand All @@ -33,6 +33,18 @@ func (k keys[K, V]) String() string {
return fmt.Sprintf(strings.Join(collections.Repeat("%v", len(k)), ", "), collections.Keys(k))
}

// SHA256Base64 logs lazily a byte slice as sha265 hash in base64 format
func SHA256Base64(b []byte) sha256Base64Enc {
h := sha256.Sum256(b)
return h[:]
}

type sha256Base64Enc []byte

func (b sha256Base64Enc) String() string {
return Base64(b).String()
}

// Base64 logs lazily a byte array in base64 format
func Base64(b []byte) base64Enc {
return b
Expand Down Expand Up @@ -87,7 +99,7 @@ func (w prefix) String() string {
if len(res) <= 20 {
return res
}
return fmt.Sprintf("%s~%s", res[:20], hash.Hashable(res).String())
return fmt.Sprintf("%s~%s", res[:20], SHA256Base64([]byte(res)))
}

type printable string
Expand Down
52 changes: 0 additions & 52 deletions platform/common/utils/hash.go

This file was deleted.

Loading