chore(envelope): clean up TODOs
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/libp2p/go-libp2p/core/crypto"
|
|
||||||
"github.com/multiformats/go-multibase"
|
"github.com/multiformats/go-multibase"
|
||||||
"github.com/multiformats/go-multicodec"
|
"github.com/multiformats/go-multicodec"
|
||||||
"github.com/multiformats/go-multihash"
|
"github.com/multiformats/go-multihash"
|
||||||
@@ -20,17 +19,6 @@ func CIDToBase58BTC(id cid.Cid) string {
|
|||||||
return id.Encode(b58BTCEnc)
|
return id.Encode(b58BTCEnc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CID returns the UCAN content identifier a Tokener.
|
|
||||||
// TODO: remove?
|
|
||||||
func CID(privKey crypto.PrivKey, token Tokener) (cid.Cid, error) {
|
|
||||||
data, err := ToDagCbor(privKey, token)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Undef, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return CIDFromBytes(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CIDFromBytes returns the UCAN content identifier for an arbitrary slice
|
// CIDFromBytes returns the UCAN content identifier for an arbitrary slice
|
||||||
// of bytes.
|
// of bytes.
|
||||||
func CIDFromBytes(b []byte) (cid.Cid, error) {
|
func CIDFromBytes(b []byte) (cid.Cid, error) {
|
||||||
|
|||||||
@@ -14,14 +14,17 @@ import (
|
|||||||
"github.com/ucan-wg/go-ucan/internal/envelope"
|
"github.com/ucan-wg/go-ucan/internal/envelope"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCid(t *testing.T) {
|
func TestCidFromBytes(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
expData := golden.Get(t, "example.dagcbor")
|
expData := golden.Get(t, "example.dagcbor")
|
||||||
expHash, err := multihash.Sum(expData, uint64(multicodec.Sha2_256), -1)
|
expHash, err := multihash.Sum(expData, uint64(multicodec.Sha2_256), -1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
id, err := envelope.CID(examplePrivKey(t), newExample(t))
|
data, err := envelope.ToDagCbor(examplePrivKey(t), newExample(t))
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
id, err := envelope.CIDFromBytes(data)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, exampleCID, envelope.CIDToBase58BTC(id))
|
assert.Equal(t, exampleCID, envelope.CIDToBase58BTC(id))
|
||||||
assert.Equal(t, expHash, id.Hash())
|
assert.Equal(t, expHash, id.Hash())
|
||||||
|
|||||||
Reference in New Issue
Block a user