Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
refactor: VC, VP, and supporting models moved into components. (#3581)
Browse files Browse the repository at this point in the history
- Verifiable Credentials and Presentation models are now in
  component/models/verifiable
- SD-JWT package is now in component/models/sdjwt
- move jsonld validator to component/models/ld
- Key fingerprint helpers and JOSE extensions moved to
  component/kmscrypto

All APIs in original afgo pkg/ folders can continue to be used,
these now transparently refer/call the moved APIs.

Signed-off-by: Filip Burlacu <Filip.Burlacu@gendigital.com>
  • Loading branch information
Moopli authored May 16, 2023
1 parent 0284074 commit 20c4d4b
Show file tree
Hide file tree
Showing 172 changed files with 6,834 additions and 4,885 deletions.
2 changes: 2 additions & 0 deletions cmd/aries-agent-mobile/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ require (

replace (
github.com/hyperledger/aries-framework-go => ../../
github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto
github.com/hyperledger/aries-framework-go/component/models => ../../component/models
// github.com/hyperledger/aries-framework-go/component/storage/edv => ../../component/storage/edv // TODO (#2815) remove this once the wallet package doesn't import edv
github.com/hyperledger/aries-framework-go/component/storageutil => ../../component/storageutil
github.com/hyperledger/aries-framework-go/spi => ../../spi
Expand Down
4 changes: 0 additions & 4 deletions cmd/aries-agent-mobile/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3 h1:PCbDSujjQ6oTEnAHgtThNmbS7SPAYEDBlKOnZFE+Ujw=
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3/go.mod h1:aEk0vHBmZsAdDfXaI12Kg5ipZGiB3qNqgbPt/e/Hm2s=
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 h1:x5qFQraTX86z9GCwF28IxfnPm6QH5YgHaX+4x97Jwvw=
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM=
github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230501135648-a9a7ad029347 h1:oPGUCpmnm7yxsVllcMQnHF3uc3hy4jfrSCh7nvzXA00=
github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230501135648-a9a7ad029347/go.mod h1:nF8fHsYY+GZl74AFAQaKAhYWOOSaLVzW/TZ0Sq/6axI=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e h1:/hrQfwJvHJrwV2FSmfnRp5L6yKY9DqDFqwYyb+oVuDU=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e/go.mod h1:ACGP1L+WeecDtyA0Mi2E1kqtPLIGrCWPSJ43q2elwX8=
github.com/hyperledger/aries-framework-go/test/component v0.0.0-20220428211718-66cc046674a1 h1:vxZ0DlFNLjgxMdBESLZu895AsI1JWL2SJerphwIn8Po=
Expand Down
1 change: 1 addition & 0 deletions cmd/aries-agent-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ require (

replace (
github.com/hyperledger/aries-framework-go => ../..
github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto
github.com/hyperledger/aries-framework-go/component/models => ../../component/models
// github.com/hyperledger/aries-framework-go/component/storage/edv => ../../component/storage/edv // TODO (#2815) remove this once the wallet package doesn't import edv
github.com/hyperledger/aries-framework-go/component/storage/leveldb => ../../component/storage/leveldb
Expand Down
2 changes: 0 additions & 2 deletions cmd/aries-agent-rest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ github.com/hyperledger/aries-framework-go-ext/component/storage/mysql v0.0.0-202
github.com/hyperledger/aries-framework-go-ext/component/storage/mysql v0.0.0-20220629202442-ce8776c10037/go.mod h1:0VNWYQ937z51P4usiHUPz0MImh8tsKEVsHVmAx2z5zA=
github.com/hyperledger/aries-framework-go-ext/component/storage/postgresql v0.0.0-20220629202442-ce8776c10037 h1:fQJPZ8kXsCSfCUHyK6zsR1RYwYP2Xz+jSaOlj+Lm1MY=
github.com/hyperledger/aries-framework-go-ext/component/storage/postgresql v0.0.0-20220629202442-ce8776c10037/go.mod h1:35iXtsPH1PImVDq8xFHETtrcvyHhJXKcvf82YJ6/z4k=
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3 h1:PCbDSujjQ6oTEnAHgtThNmbS7SPAYEDBlKOnZFE+Ujw=
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3/go.mod h1:aEk0vHBmZsAdDfXaI12Kg5ipZGiB3qNqgbPt/e/Hm2s=
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 h1:x5qFQraTX86z9GCwF28IxfnPm6QH5YgHaX+4x97Jwvw=
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM=
github.com/hyperledger/aries-framework-go/component/storage/edv v0.0.0-20221025204933-b807371b6f1e h1:/hrQfwJvHJrwV2FSmfnRp5L6yKY9DqDFqwYyb+oVuDU=
Expand Down
2 changes: 2 additions & 0 deletions cmd/aries-js-worker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ require (

replace (
github.com/hyperledger/aries-framework-go => ../..
github.com/hyperledger/aries-framework-go/component/kmscrypto => ../../component/kmscrypto
github.com/hyperledger/aries-framework-go/component/models => ../../component/models
github.com/hyperledger/aries-framework-go/component/storage/edv => ../../component/storage/edv // TODO (#2815) remove this once the wallet package doesn't import edv
github.com/hyperledger/aries-framework-go/component/storage/indexeddb => ../../component/storage/indexeddb
github.com/hyperledger/aries-framework-go/component/storageutil => ../../component/storageutil
Expand Down
4 changes: 0 additions & 4 deletions cmd/aries-js-worker/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3 h1:PCbDSujjQ6oTEnAHgtThNmbS7SPAYEDBlKOnZFE+Ujw=
github.com/hyperledger/aries-framework-go/component/kmscrypto v0.0.0-20230427134832-0c9969493bd3/go.mod h1:aEk0vHBmZsAdDfXaI12Kg5ipZGiB3qNqgbPt/e/Hm2s=
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3 h1:x5qFQraTX86z9GCwF28IxfnPm6QH5YgHaX+4x97Jwvw=
github.com/hyperledger/aries-framework-go/component/log v0.0.0-20230427134832-0c9969493bd3/go.mod h1:CvYs4l8X2NrrF93weLOu5RTOIJeVdoZITtjEflyuTyM=
github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230501135648-a9a7ad029347 h1:oPGUCpmnm7yxsVllcMQnHF3uc3hy4jfrSCh7nvzXA00=
github.com/hyperledger/aries-framework-go/component/models v0.0.0-20230501135648-a9a7ad029347/go.mod h1:nF8fHsYY+GZl74AFAQaKAhYWOOSaLVzW/TZ0Sq/6axI=
github.com/hyperledger/aries-framework-go/test/component v0.0.0-20220428211718-66cc046674a1 h1:vxZ0DlFNLjgxMdBESLZu895AsI1JWL2SJerphwIn8Po=
github.com/hyperledger/ursa-wrapper-go v0.3.1 h1:Do+QrVNniY77YK2jTIcyWqj9rm/Yb5SScN0bqCjiibA=
github.com/hyperledger/ursa-wrapper-go v0.3.1/go.mod h1:nPSAuMasIzSVciQo22PedBk4Opph6bJ6ia3ms7BH/mk=
Expand Down
2 changes: 1 addition & 1 deletion component/kmscrypto/crypto/tinkcrypto/key_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/curve25519"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

cryptoapi "github.com/hyperledger/aries-framework-go/spi/crypto"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/google/tink/go/testutil"
"github.com/stretchr/testify/require"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/composite"
ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
tinkpb "github.com/google/tink/go/proto/tink_go_proto"
"google.golang.org/protobuf/proto"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/composite"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/composite/ecdh/subtle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

cbcaead "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/aead"
ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
tinkpb "github.com/google/tink/go/proto/tink_go_proto"
"github.com/stretchr/testify/require"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

cbcaead "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/aead"
ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/google/tink/go/testutil"
"github.com/stretchr/testify/require"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

ecdhpb "github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/proto/ecdh_aead_go_proto"
)
Expand Down
2 changes: 1 addition & 1 deletion component/kmscrypto/crypto/tinkcrypto/wrap_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
hybrid "github.com/google/tink/go/hybrid/subtle"
"golang.org/x/crypto/chacha20poly1305"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/aead/subtle"
)
Expand Down
2 changes: 1 addition & 1 deletion component/kmscrypto/crypto/tinkcrypto/wrap_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/curve25519"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/internal/cryptoutil"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/util/cryptoutil"
)

func Test_ecKWSupportFailures(t *testing.T) {
Expand Down
173 changes: 173 additions & 0 deletions component/kmscrypto/doc/jose/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package jose

import (
"github.com/hyperledger/aries-framework-go/component/kmscrypto/crypto/tinkcrypto/primitive/composite/ecdh"
"github.com/hyperledger/aries-framework-go/component/kmscrypto/doc/jose/jwk"
)

// IANA registered JOSE headers (https://tools.ietf.org/html/rfc7515#section-4.1)
const (
// HeaderAlgorithm identifies:
// For JWS: the cryptographic algorithm used to secure the JWS.
// For JWE: the cryptographic algorithm used to encrypt or determine the value of the CEK.
HeaderAlgorithm = "alg" // string

// HeaderEncryption identifies the JWE content encryption algorithm.
HeaderEncryption = "enc" // string

// HeaderJWKSetURL is a URI that refers to a resource for a set of JSON-encoded public keys, one of which:
// For JWS: corresponds to the key used to digitally sign the JWS.
// For JWE: corresponds to the public key to which the JWE was encrypted.
HeaderJWKSetURL = "jku" // string

// HeaderJSONWebKey is:
// For JWS: the public key that corresponds to the key used to digitally sign the JWS.
// For JWE: the public key to which the JWE was encrypted.
HeaderJSONWebKey = "jwk" // JSON

// HeaderKeyID is a hint:
// For JWS: indicating which key was used to secure the JWS.
// For JWE: which references the public key to which the JWE was encrypted.
HeaderKeyID = "kid" // string

// HeaderSenderKeyID is a hint:
// For JWS: not used.
// For JWE: which references the (sender) public key used in the JWE key derivation/wrapping to encrypt the CEK.
HeaderSenderKeyID = "skid" // string

// HeaderX509URL is a URI that refers to a resource for the X.509 public key certificate or certificate chain:
// For JWS: corresponding to the key used to digitally sign the JWS.
// For JWE: corresponding to the public key to which the JWE was encrypted.
HeaderX509URL = "x5u"

// HeaderX509CertificateChain contains the X.509 public key certificate or certificate chain:
// For JWS: corresponding to the key used to digitally sign the JWS.
// For JWE: corresponding to the public key to which the JWE was encrypted.
HeaderX509CertificateChain = "x5c"

// HeaderX509CertificateDigest (X.509 certificate SHA-1 thumbprint) is a base64url-encoded
// SHA-1 thumbprint (a.k.a. digest) of the DER encoding of the X.509 certificate:
// For JWS: corresponding to the key used to digitally sign the JWS.
// For JWE: corresponding to the public key to which the JWE was encrypted.
HeaderX509CertificateDigestSha1 = "x5t"

// HeaderX509CertificateDigestSha256 (X.509 certificate SHA-256 thumbprint) is a base64url-encoded SHA-256
// thumbprint (a.k.a. digest) of the DER encoding of the X.509 certificate:
// For JWS: corresponding to the key used to digitally sign the JWS.
// For JWE: corresponding to the public key to which the JWE was encrypted.
HeaderX509CertificateDigestSha256 = "x5t#S256" // string

// HeaderType is:
// For JWS: used by JWS applications to declare the media type of this complete JWS.
// For JWE: used by JWE applications to declare the media type of this complete JWE.
HeaderType = "typ" // string

// HeaderContentType is used by JWS applications to declare the media type of:
// For JWS: the secured content (the payload).
// For JWE: the secured content (the plaintext).
HeaderContentType = "cty" // string

// HeaderCritical indicates that extensions to:
// For JWS: this JWS header specification and/or JWA are being used that MUST be understood and processed.
// For JWE: this JWE header specification and/or JWA are being used that MUST be understood and processed.
HeaderCritical = "crit" // array

// HeaderEPK is used by JWE applications to wrap/unwrap the CEK for a recipient.
HeaderEPK = "epk" // JSON
)

// Header defined in https://tools.ietf.org/html/rfc7797
const (
// HeaderB64 determines whether the payload is represented in the JWS and the JWS Signing
// Input as ASCII(BASE64URL(JWS Payload)) or as the JWS Payload value itself with no encoding performed.
HeaderB64Payload = "b64" // bool
// A256GCMALG is the default content encryption algorithm value as per
// the JWA specification: https://tools.ietf.org/html/rfc7518#section-5.1
A256GCMALG = "A256GCM"
// XC20PALG represents XChacha20Poly1305 content encryption algorithm value.
XC20PALG = "XC20P"
// A128CBCHS256ALG represents AES_128_CBC_HMAC_SHA_256 encryption algorithm value.
A128CBCHS256ALG = "A128CBC-HS256"
// A192CBCHS384ALG represents AES_192_CBC_HMAC_SHA_384 encryption algorithm value.
A192CBCHS384ALG = "A192CBC-HS384"
// A256CBCHS384ALG represents AES_256_CBC_HMAC_SHA_384 encryption algorithm value (not defined in JWA spec above).
A256CBCHS384ALG = "A256CBC-HS384"
// A256CBCHS512ALG represents AES_256_CBC_HMAC_SHA_512 encryption algorithm value.
A256CBCHS512ALG = "A256CBC-HS512"
)

var aeadAlg = map[EncAlg]ecdh.AEADAlg{ //nolint:gochecknoglobals
A256GCM: ecdh.AES256GCM,
XC20P: ecdh.XC20P,
A128CBCHS256: ecdh.AES128CBCHMACSHA256,
A192CBCHS384: ecdh.AES192CBCHMACSHA384,
A256CBCHS384: ecdh.AES256CBCHMACSHA384,
A256CBCHS512: ecdh.AES256CBCHMACSHA512,
}

// Headers represents JOSE headers.
type Headers map[string]interface{}

// KeyID gets Key ID from JOSE headers.
func (h Headers) KeyID() (string, bool) {
return h.stringValue(HeaderKeyID)
}

// SenderKeyID gets the sender Key ID from Jose headers.
func (h Headers) SenderKeyID() (string, bool) {
return h.stringValue(HeaderSenderKeyID)
}

// Algorithm gets Algorithm from JOSE headers.
func (h Headers) Algorithm() (string, bool) {
return h.stringValue(HeaderAlgorithm)
}

// Encryption gets content encryption algorithm from JOSE headers.
func (h Headers) Encryption() (string, bool) {
return h.stringValue(HeaderEncryption)
}

// Type gets content encryption type from JOSE headers.
func (h Headers) Type() (string, bool) {
return h.stringValue(HeaderType)
}

// ContentType gets the payload content type from JOSE headers.
func (h Headers) ContentType() (string, bool) {
return h.stringValue(HeaderContentType)
}

func (h Headers) stringValue(key string) (string, bool) {
raw, ok := h[key]
if !ok {
return "", false
}

str, ok := raw.(string)

return str, ok
}

// JWK gets JWK from JOSE headers.
func (h Headers) JWK() (*jwk.JWK, bool) {
jwkRaw, ok := h[HeaderJSONWebKey]
if !ok {
return nil, false
}

var jwkKey jwk.JWK

err := convertMapToValue(jwkRaw, &jwkKey)
if err != nil {
return nil, false
}

return &jwkKey, true
}
File renamed without changes.
Loading

0 comments on commit 20c4d4b

Please sign in to comment.