From 5fb3516d155c8ed0253f23e00f041a6bf94da0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 10 Jul 2025 11:24:14 +0200 Subject: [PATCH] feat(deps): remove the multicodec dependency, as varsig constants are not multicodec --- constant.go | 39 ++++++++++++++++++--------------------- eddsa.go | 26 ++++++++++++-------------- go.mod | 5 +---- go.sum | 2 -- rsa.go | 6 ++---- 5 files changed, 33 insertions(+), 45 deletions(-) diff --git a/constant.go b/constant.go index fea10f6..22e9bb5 100644 --- a/constant.go +++ b/constant.go @@ -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 diff --git a/eddsa.go b/eddsa.go index 37816d4..ca60d08 100644 --- a/eddsa.go +++ b/eddsa.go @@ -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 } diff --git a/go.mod b/go.mod index ac82baf..0faf208 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index db62f16..b37bff5 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/rsa.go b/rsa.go index 0fe7713..b445314 100644 --- a/rsa.go +++ b/rsa.go @@ -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{}