feat(deps): remove the multicodec dependency, as varsig constants are not multicodec

This commit is contained in:
Michael Muré
2025-07-10 11:24:14 +02:00
parent eb70826a70
commit 5fb3516d15
5 changed files with 33 additions and 45 deletions

View File

@@ -3,26 +3,23 @@ package varsig
import (
"encoding/binary"
"fmt"
"github.com/multiformats/go-multicodec"
)
// Prefix is the multicodec.Code for the varsig's varuint prefix byte.
const Prefix = uint64(multicodec.Varsig)
// Prefix is the value for the varsig's varuint prefix byte.
const Prefix = uint64(0x34)
// HashAlgorithm is the multicodec.Code that specifies the hash algorithm
// HashAlgorithm is the value that specifies the hash algorithm
// that's used to reduce the signed content
type HashAlgorithm uint64
// Constant multicodec.Code values that allow Varsig implementations to
// specify how the payload content is hashed before the signature is
// generated.
// Constant values that allow Varsig implementations to specify how
// the payload content is hashed before the signature is generated.
const (
HashAlgorithmUnspecified HashAlgorithm = 0x00
HashAlgorithmSHA256 = HashAlgorithm(multicodec.Sha2_256)
HashAlgorithmSHA384 = HashAlgorithm(multicodec.Sha2_384)
HashAlgorithmSHA512 = HashAlgorithm(multicodec.Sha2_512)
HashAlgorithmShake256 = HashAlgorithm(multicodec.Shake256)
HashAlgorithmSHA256 = HashAlgorithm(0x12)
HashAlgorithmSHA384 = HashAlgorithm(0x20)
HashAlgorithmSHA512 = HashAlgorithm(0x13)
HashAlgorithmShake256 = HashAlgorithm(0x19)
)
// DecodeHashAlgorithm reads and validates the expected hash algorithm
@@ -51,16 +48,16 @@ func DecodeHashAlgorithm(r BytesReader) (HashAlgorithm, error) {
// consistent hashes and signatures.
type PayloadEncoding uint64
// Constant multicodec.Code values that allow Varsig implementations to
// specify how the payload content is encoded before being hashed. In
// varsig >= v1, only canonical encoding is allowed.
// Constant values that allow Varsig implementations to specify how the
// payload content is encoded before being hashed.
// In varsig >= v1, only canonical encoding is allowed.
const (
PayloadEncodingUnspecified PayloadEncoding = 0x00
PayloadEncodingVerbatim PayloadEncoding = 0x5f
PayloadEncodingDAGPB = PayloadEncoding(multicodec.DagPb)
PayloadEncodingDAGCBOR = PayloadEncoding(multicodec.DagCbor)
PayloadEncodingDAGJSON = PayloadEncoding(multicodec.DagJson)
PayloadEncodingEIP191 = PayloadEncoding(multicodec.Eip191)
PayloadEncodingDAGPB = PayloadEncoding(0x70)
PayloadEncodingDAGCBOR = PayloadEncoding(0x71)
PayloadEncodingDAGJSON = PayloadEncoding(0x0129)
PayloadEncodingEIP191 = PayloadEncoding(0xd191)
PayloadEncodingJWT PayloadEncoding = 0x6a77
)
@@ -112,8 +109,8 @@ func decodeEncodingInfoV1(payEnc PayloadEncoding) (PayloadEncoding, error) {
}
}
// Discriminator is (usually) the multicodec.Code representing the public
// key type of the algorithm used to create the signature.
// Discriminator is (usually) the value representing the public key type of
// the algorithm used to create the signature.
//
// There is not set list of constants here, nor is there a decode function
// as the author of an implementation should include the constant with the

View File

@@ -4,26 +4,24 @@ import (
"crypto/ed25519"
"encoding/binary"
"fmt"
"github.com/multiformats/go-multicodec"
)
// Constants containing multicodec.Code values that specify EdDSA signatures.
// Constants containing values that specify EdDSA signatures.
const (
DiscriminatorEdDSA = Discriminator(multicodec.Ed25519Pub)
DiscriminatorEd25519 = Discriminator(multicodec.Ed25519Pub)
DiscriminatorEd448 = Discriminator(multicodec.Ed448Pub)
DiscriminatorEdDSA = Discriminator(0xed)
DiscriminatorEd25519 = Discriminator(0xed)
DiscriminatorEd448 = Discriminator(0x1203)
)
// EdDSACurve are multicodec.Code values that specify which Edwards curve
// is used when generating the signature.
// EdDSACurve are values that specify which Edwards curve is used when
// generating the signature.
type EdDSACurve uint64
// Constants describing the multicodec.Code for each specific Edwards
// curve that can be encoded into a Varsig.
// Constants describing the values for each specific Edwards curve that can
// be encoded into a Varsig.
const (
CurveEd25519 = EdDSACurve(multicodec.Ed25519Pub)
CurveEd448 = EdDSACurve(multicodec.Ed448Pub)
CurveEd25519 = EdDSACurve(0xed)
CurveEd448 = EdDSACurve(0x1203)
)
func decodeEdDSACurve(r BytesReader) (EdDSACurve, error) {
@@ -87,8 +85,8 @@ func (v EdDSAVarsig) Curve() EdDSACurve {
return v.curve
}
// HashAlgorithm returns the multicodec.Code describing the hash algorithm
// used to hash the payload content before the signature is generated.
// HashAlgorithm returns the value describing the hash algorithm used to hash
// the payload content before the signature is generated.
func (v EdDSAVarsig) HashAlgorithm() HashAlgorithm {
return v.hashAlg
}

5
go.mod
View File

@@ -2,10 +2,7 @@ module github.com/ucan-wg/go-varsig
go 1.24.4
require (
github.com/multiformats/go-multicodec v0.9.2
github.com/stretchr/testify v1.10.0
)
require github.com/stretchr/testify v1.10.0
require (
github.com/davecgh/go-spew v1.1.1 // indirect

2
go.sum
View File

@@ -6,8 +6,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/multiformats/go-multicodec v0.9.2 h1:YrlXCuqxjqm3bXl+vBq5LKz5pz4mvAsugdqy78k0pXQ=
github.com/multiformats/go-multicodec v0.9.2/go.mod h1:LLWNMtyV5ithSBUo3vFIMaeDy+h3EbkMTek1m+Fybbo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=

6
rsa.go
View File

@@ -2,12 +2,10 @@ package varsig
import (
"encoding/binary"
"github.com/multiformats/go-multicodec"
)
// DiscriminatorRSA is the multicodec.Code specifying an RSA signature.
const DiscriminatorRSA = Discriminator(multicodec.RsaPub)
// DiscriminatorRSA is the value specifying an RSA signature.
const DiscriminatorRSA = Discriminator(0x1205)
var _ Varsig = RSAVarsig{}