From 62073e562527676b34de9074e2caa5599fd3dbce Mon Sep 17 00:00:00 2001 From: Andrew Gillis Date: Fri, 29 Mar 2024 11:13:50 -0700 Subject: [PATCH] Dhash api (#177) * Remove unused error return form dhash API --- dhash/dhash.go | 6 ++++-- dhash/dhash_test.go | 3 +-- find/client/dhash_client.go | 7 +------ go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/dhash/dhash.go b/dhash/dhash.go index b2c64b6..63f67fa 100644 --- a/dhash/dhash.go +++ b/dhash/dhash.go @@ -41,9 +41,11 @@ func sha256Multiple(dest []byte, payloads ...[]byte) []byte { // SecondMultihash calculates SHA256 over the multihash and wraps it into // another multihash with DBL_SHA256 codec. -func SecondMultihash(mh multihash.Multihash) (multihash.Multihash, error) { +func SecondMultihash(mh multihash.Multihash) multihash.Multihash { digest := SHA256(append(secondHashPrefix, mh...), nil) - return multihash.Encode(digest, multihash.DBL_SHA2_256) + // The error return from multihash.Encode is legacy; it is always nil. + mh2, _ := multihash.Encode(digest, multihash.DBL_SHA2_256) + return mh2 } // deriveKey derives encryptioin key from the passphrase using SHA256 diff --git a/dhash/dhash_test.go b/dhash/dhash_test.go index 4448fac..4b894be 100644 --- a/dhash/dhash_test.go +++ b/dhash/dhash_test.go @@ -61,8 +61,7 @@ func TestCanDecryptEncryptedValue(t *testing.T) { func TestSecondMultihash(t *testing.T) { mh := test.RandomMultihashes(1)[0] - smh, err := SecondMultihash(mh) - require.NoError(t, err) + smh := SecondMultihash(mh) h := sha256.New() h.Write(append(secondHashPrefix, mh...)) diff --git a/find/client/dhash_client.go b/find/client/dhash_client.go index 16012da..acd1e1b 100644 --- a/find/client/dhash_client.go +++ b/find/client/dhash_client.go @@ -143,12 +143,7 @@ func (c *DHashClient) Find(ctx context.Context, mh multihash.Multihash) (*model. func (c *DHashClient) FindAsync(ctx context.Context, mh multihash.Multihash, resChan chan<- model.ProviderResult) error { defer close(resChan) - dhmh, err := dhash.SecondMultihash(mh) - if err != nil { - return err - } - - encryptedMultihashResults, err := c.dhstoreAPI.FindMultihash(ctx, dhmh) + encryptedMultihashResults, err := c.dhstoreAPI.FindMultihash(ctx, dhash.SecondMultihash(mh)) if err != nil { return err } diff --git a/go.mod b/go.mod index 7e0933b..f294ab6 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/ipfs/go-ipld-format v0.6.0 github.com/ipfs/go-log/v2 v2.5.1 github.com/ipld/go-ipld-prime v0.21.0 - github.com/libp2p/go-libp2p v0.33.1 + github.com/libp2p/go-libp2p v0.33.2 github.com/libp2p/go-libp2p-pubsub v0.10.0 github.com/libp2p/go-msgio v0.3.0 github.com/mr-tron/base58 v1.2.0 diff --git a/go.sum b/go.sum index c4ccbee..0a27c1c 100644 --- a/go.sum +++ b/go.sum @@ -174,8 +174,8 @@ github.com/libp2p/go-buffer-pool v0.1.0 h1:oK4mSFcQz7cTQIfqbe4MIj9gLW+mnanjyFtc6 github.com/libp2p/go-buffer-pool v0.1.0/go.mod h1:N+vh8gMqimBzdKkSMVuydVDq+UV5QTWy5HSiZacSbPg= github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM= github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro= -github.com/libp2p/go-libp2p v0.33.1 h1:tvJl9b9M6nSLBtZSXSguq+/lRhRj2oLRkyhBmQNMFLA= -github.com/libp2p/go-libp2p v0.33.1/go.mod h1:zOUTMjG4I7TXwMndNyOBn/CNtVBLlvBlnxfi+8xzx+E= +github.com/libp2p/go-libp2p v0.33.2 h1:vCdwnFxoGOXMKmaGHlDSnL4bM3fQeW8pgIa9DECnb40= +github.com/libp2p/go-libp2p v0.33.2/go.mod h1:zTeppLuCvUIkT118pFVzA8xzP/p2dJYOMApCkFh0Yww= github.com/libp2p/go-libp2p-asn-util v0.4.1 h1:xqL7++IKD9TBFMgnLPZR6/6iYhawHKHl950SO9L6n94= github.com/libp2p/go-libp2p-asn-util v0.4.1/go.mod h1:d/NI6XZ9qxw67b4e+NgpQexCIiFYJjErASrYW4PFDN8= github.com/libp2p/go-libp2p-pubsub v0.10.0 h1:wS0S5FlISavMaAbxyQn3dxMOe2eegMfswM471RuHJwA=