jws2020

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OKP KTY = "OKP"
	EC  KTY = "EC"
	RSA KTY = "RSA"

	Ed25519   CRV = "Ed25519"
	X25519    CRV = "X25519"
	SECP256k1 CRV = "secp256k1"
	P256      CRV = "P-256"
	P384      CRV = "P-384"
)
View Source
const (
	JSONWebSignature2020Context                string                    = "https://w3id.org/security/suites/jws-2020/v1"
	JSONWebSignature2020                       cryptosuite.SignatureType = "JsonWebSignature2020"
	JWSSignatureSuiteID                        string                    = "https://w3c-ccg.github.io/security-vocab/#JsonWebSignature2020"
	JWSSignatureSuiteType                                                = cryptosuite.JSONWebKey2020Type
	JWSSignatureSuiteCanonicalizationAlgorithm string                    = "https://w3id.org/security#URDNA2015"
	// JWSSignatureSuiteDigestAlgorithm uses https://www.rfc-editor.org/rfc/rfc4634
	JWSSignatureSuiteDigestAlgorithm gocrypto.Hash = gocrypto.SHA256
	// JWSSignatureSuiteProofAlgorithm  uses https://www.rfc-editor.org/rfc/rfc7797
	JWSSignatureSuiteProofAlgorithm = JSONWebSignature2020
)

Variables

This section is empty.

Functions

func GetJSONWebSignature2020Suite

func GetJSONWebSignature2020Suite() cryptosuite.CryptoSuite

func PubKeyBytesToTypedKey

func PubKeyBytesToTypedKey(keyBytes []byte, kt cryptosuite.LDKeyType) (gocrypto.PublicKey, error)

PubKeyBytesToTypedKey converts a public key byte slice to a crypto.PublicKey based on a given key type, merging both LD key types and JWK key types

Types

type ALG

type ALG string

type CRV

type CRV string

type JSONWebKey2020

type JSONWebKey2020 struct {
	ID                string                `json:"id,omitempty"`
	Type              cryptosuite.LDKeyType `json:"type,omitempty"`
	Controller        string                `json:"controller,omitempty"`
	jwx.PrivateKeyJWK `json:"privateKeyJwk,omitempty"`
	jwx.PublicKeyJWK  `json:"publicKeyJwk,omitempty"`
}

JSONWebKey2020 complies with https://w3c-ccg.github.io/lds-jws2020/#json-web-key-2020

func GenerateEd25519JSONWebKey2020

func GenerateEd25519JSONWebKey2020() (*JSONWebKey2020, error)

GenerateEd25519JSONWebKey2020 returns a JsonWebKey2020 value, containing both public and private keys for an Ed25519 key.

func GenerateJSONWebKey2020

func GenerateJSONWebKey2020(kty KTY, crv CRV) (*JSONWebKey2020, error)

GenerateJSONWebKey2020 The JSONWebKey2020 type specifies a number of key type and curve pairs to enable JOSE conformance these pairs are supported in this library and generated via the function below https://w3c-ccg.github.io/lds-jws2020/#dfn-jsonwebkey2020

func GenerateP256JSONWebKey2020

func GenerateP256JSONWebKey2020() (*JSONWebKey2020, error)

GenerateP256JSONWebKey2020 returns a JsonWebKey2020 value, containing both public and private keys for a P-256 ECDSA key.

func GenerateP384JSONWebKey2020

func GenerateP384JSONWebKey2020() (*JSONWebKey2020, error)

GenerateP384JSONWebKey2020 returns a JsonWebKey2020 value, containing both public and private keys for a P-384 ECDSA key.

func GenerateRSAJSONWebKey2020

func GenerateRSAJSONWebKey2020() (*JSONWebKey2020, error)

GenerateRSAJSONWebKey2020 returns a JsonWebKey2020 value, containing both public and private keys for an RSA-2048 key.

func GenerateSECP256k1JSONWebKey2020

func GenerateSECP256k1JSONWebKey2020() (*JSONWebKey2020, error)

GenerateSECP256k1JSONWebKey2020 returns a JsonWebKey2020 value, containing both public and private keys for a secp256k1 key transformed to an ecdsa key. We use the secp256k1 implementation from Decred https://github.com/decred/dcrd which is utilized in the widely accepted go bitcoin node implementation from the btcsuite project https://github.com/btcsuite/btcd/blob/master/btcec/btcec.go#L23

func GenerateX25519JSONWebKey2020

func GenerateX25519JSONWebKey2020() (*JSONWebKey2020, error)

GenerateX25519JSONWebKey2020 returns a JsonWebKey2020 value, containing both public and private keys for an Ed25519 key transformed to a bi-rationally equivalent X25519 key.

func JSONWebKey2020FromPrivateKey

func JSONWebKey2020FromPrivateKey(key gocrypto.PrivateKey) (*JSONWebKey2020, error)

JSONWebKey2020FromPrivateKey returns a JsonWebKey2020 value from a given private key, containing both JWK public and private key representations of the key.

func (*JSONWebKey2020) IsValid

func (jwk *JSONWebKey2020) IsValid() error

type JSONWebKeySigner

type JSONWebKeySigner struct {
	jwx.Signer
	// contains filtered or unexported fields
}

JSONWebKeySigner constructs a signer for a JSONWebKey2020 object. Given a signature algorithm (e.g. ES256, PS384) and a JSON Web Key (private key), the signer is able to accept a message and provide a valid JSON Web Signature (JWS) value as a result.

func NewJSONWebKeySigner

func NewJSONWebKeySigner(id string, key jwx.PrivateKeyJWK, purpose cryptosuite.ProofPurpose) (*JSONWebKeySigner, error)

func (*JSONWebKeySigner) GetKeyID

func (s *JSONWebKeySigner) GetKeyID() string

func (*JSONWebKeySigner) GetPayloadFormat

func (s *JSONWebKeySigner) GetPayloadFormat() cryptosuite.PayloadFormat

func (*JSONWebKeySigner) GetProofPurpose

func (s *JSONWebKeySigner) GetProofPurpose() cryptosuite.ProofPurpose

func (*JSONWebKeySigner) GetSignatureType

func (*JSONWebKeySigner) GetSignatureType() cryptosuite.SignatureType

func (*JSONWebKeySigner) GetSigningAlgorithm

func (s *JSONWebKeySigner) GetSigningAlgorithm() string

func (*JSONWebKeySigner) SetPayloadFormat

func (s *JSONWebKeySigner) SetPayloadFormat(format cryptosuite.PayloadFormat)

func (*JSONWebKeySigner) SetProofPurpose

func (s *JSONWebKeySigner) SetProofPurpose(purpose cryptosuite.ProofPurpose)

func (*JSONWebKeySigner) Sign

func (s *JSONWebKeySigner) Sign(tbs []byte) ([]byte, error)

Sign returns a byte array signature value for a message `tbs`

type JSONWebKeyVerifier

type JSONWebKeyVerifier struct {
	jwx.Verifier
}

JSONWebKeyVerifier constructs a verifier for a JSONWebKey2020 object. Given a signature algorithm (e.g. ES256, PS384) and a JSON Web Key (pub key), the verifier is able to accept a message and signature, and provide a result to whether the signature is valid.

func NewJSONWebKeyVerifier

func NewJSONWebKeyVerifier(id string, key jwx.PublicKeyJWK) (*JSONWebKeyVerifier, error)

func (JSONWebKeyVerifier) GetKeyID

func (v JSONWebKeyVerifier) GetKeyID() string

func (JSONWebKeyVerifier) Verify

func (v JSONWebKeyVerifier) Verify(message, signature []byte) error

Verify attempts to verify a `signature` against a given `message`, returning nil if the verification is successful and an error should it fail.

type JSONWebSignature2020Proof

type JSONWebSignature2020Proof struct {
	Type               cryptosuite.SignatureType `json:"type,omitempty"`
	Created            string                    `json:"created,omitempty"`
	JWS                string                    `json:"jws,omitempty"`
	ProofPurpose       cryptosuite.ProofPurpose  `json:"proofPurpose,omitempty"`
	Challenge          string                    `json:"challenge,omitempty"`
	VerificationMethod string                    `json:"verificationMethod,omitempty"`
}

func JSONWebSignatureProofFromGenericProof

func JSONWebSignatureProofFromGenericProof(p crypto.Proof) (*JSONWebSignature2020Proof, error)

func (*JSONWebSignature2020Proof) DecodeJWS

func (j *JSONWebSignature2020Proof) DecodeJWS() ([]byte, error)

func (*JSONWebSignature2020Proof) GetDetachedJWS

func (j *JSONWebSignature2020Proof) GetDetachedJWS() string

func (*JSONWebSignature2020Proof) SetDetachedJWS

func (j *JSONWebSignature2020Proof) SetDetachedJWS(jws string)

func (*JSONWebSignature2020Proof) ToGenericProof

func (j *JSONWebSignature2020Proof) ToGenericProof() crypto.Proof

type JWSSignatureSuite

type JWSSignatureSuite struct{}

func (JWSSignatureSuite) CanonicalizationAlgorithm

func (JWSSignatureSuite) CanonicalizationAlgorithm() string

func (JWSSignatureSuite) Canonicalize

func (JWSSignatureSuite) Canonicalize(marshaled []byte) (*string, error)

func (JWSSignatureSuite) CreateVerifyHash

func (j JWSSignatureSuite) CreateVerifyHash(doc map[string]any, proof crypto.Proof, opts *cryptosuite.ProofOptions) ([]byte, error)

func (JWSSignatureSuite) Digest

func (j JWSSignatureSuite) Digest(tbd []byte) ([]byte, error)

func (JWSSignatureSuite) ID

func (JWSSignatureSuite) Marshal

func (JWSSignatureSuite) Marshal(data any) ([]byte, error)

func (JWSSignatureSuite) MessageDigestAlgorithm

func (JWSSignatureSuite) MessageDigestAlgorithm() gocrypto.Hash

func (JWSSignatureSuite) RequiredContexts

func (JWSSignatureSuite) RequiredContexts() []string

func (JWSSignatureSuite) Sign

func (JWSSignatureSuite) SignatureAlgorithm

func (JWSSignatureSuite) SignatureAlgorithm() cryptosuite.SignatureType

func (JWSSignatureSuite) Type

func (JWSSignatureSuite) Verify

type KTY

type KTY string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL