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

View File

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

5
go.mod
View File

@@ -2,10 +2,7 @@ module github.com/ucan-wg/go-varsig
go 1.24.4 go 1.24.4
require ( require github.com/stretchr/testify v1.10.0
github.com/multiformats/go-multicodec v0.9.2
github.com/stretchr/testify v1.10.0
)
require ( require (
github.com/davecgh/go-spew v1.1.1 // indirect 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/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 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=

6
rsa.go
View File

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