Skip to content

Commit

Permalink
fix: cose vp presentation set (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 authored Jul 23, 2024
1 parent ee4b1e7 commit 8cb417a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cwt/cwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func createTestProof() (string, error) {
data := map[int]interface{}{
1: "test-client",
3: "http://127.0.0.1:60413",
6: "1706706927",
6: 1706706927,
10: "kYcbCxvele1pn94YpKjD",
}

Expand Down
12 changes: 6 additions & 6 deletions verifiable/cose.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func marshalCOSE(
signatureAlg cose.Algorithm,
signer cwt.ProofCreator,
keyID string,
) ([]byte, error) {
) ([]byte, *cose.Sign1Message, error) {
payload, err := cbor.Marshal(claims)
if err != nil {
return nil, err
return nil, nil, err
}

msg := &cose.Sign1Message{
Expand All @@ -44,23 +44,23 @@ func marshalCOSE(

signData, err := cwt2.GetProofValue(msg)
if err != nil {
return nil, err
return nil, nil, err
}

signed, err := signer.SignCWT(cwt.SignParameters{
KeyID: keyID,
CWTAlg: signatureAlg,
}, signData)
if err != nil {
return nil, err
return nil, nil, err
}

msg.Signature = signed

final, err := cbor.Marshal(msg)
if err != nil {
return nil, err
return nil, nil, err
}

return final, nil
return final, msg, nil
}
5 changes: 3 additions & 2 deletions verifiable/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -1756,7 +1756,7 @@ func (vc *Credential) CreateSignedCOSEVC(
return nil, err
}

msg, err := claims.MarshaCOSE(signatureAlg, proofCreator, keyID)
msgRaw, msg, err := claims.MarshaCOSE(signatureAlg, proofCreator, keyID)
if err != nil {
return nil, err
}
Expand All @@ -1766,7 +1766,8 @@ func (vc *Credential) CreateSignedCOSEVC(
credentialContents: vc.Contents(),
ldProofs: vc.ldProofs,
CWTEnvelope: &CWTEnvelope{
Sign1MessageRaw: msg,
Sign1MessageRaw: msgRaw,
Sign1MessageParsed: msg,
},
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion verifiable/credential_cwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ func (jcc *CWTCredClaims) MarshaCOSE(
signatureAlg cose.Algorithm,
signer cwt.ProofCreator,
keyID string,
) ([]byte, error) {
) ([]byte, *cose.Sign1Message, error) {
return marshalCOSE(jcc, signatureAlg, signer, keyID)
}
2 changes: 1 addition & 1 deletion verifiable/presentation_cwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ func (c *CWTPresClaims) MarshalCWT(
signatureAlg cose.Algorithm,
signer cwt.ProofCreator,
keyID string,
) ([]byte, error) {
) ([]byte, *cose.Sign1Message, error) {
return marshalCOSE(c, signatureAlg, signer, keyID)
}
4 changes: 3 additions & 1 deletion verifiable/presentation_cwt_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/trustbloc/kms-go/spi/kms"
"github.com/veraison/go-cose"
Expand All @@ -32,8 +33,9 @@ func TestParsePresentationFromCWS_EdDSA(t *testing.T) {
cwtClaims, err := vp.CWTClaims([]string{}, false)
require.NoError(t, err)

cwtBytes, err := cwtClaims.MarshalCWT(cose.AlgorithmEdDSA, proofCreator, holderKeyID)
cwtBytes, msg, err := cwtClaims.MarshalCWT(cose.AlgorithmEdDSA, proofCreator, holderKeyID)
require.NoError(t, err)
assert.NotNil(t, msg)

hexStr := hex.EncodeToString(cwtBytes)
fmt.Println(hexStr)
Expand Down

0 comments on commit 8cb417a

Please sign in to comment.