Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
signer
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Wiki
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
signer
Commits
c9425555
Commit
c9425555
authored
1 year ago
by
Lyuben Penkovski
Browse files
Options
Downloads
Patches
Plain Diff
Create VC endpoint implementation
parent
fb1effb2
No related branches found
Branches containing commit
No related tags found
1 merge request
!30
Draft: New endpoint for creating verifiable credentials
Pipeline
#67172
canceled with stages
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/signer/main.go
+1
-2
1 addition, 2 deletions
cmd/signer/main.go
go.sum
+89
-0
89 additions, 0 deletions
go.sum
internal/service/health/service.go
+22
-8
22 additions, 8 deletions
internal/service/health/service.go
internal/service/signer/service.go
+62
-4
62 additions, 4 deletions
internal/service/signer/service.go
with
174 additions
and
14 deletions
cmd/signer/main.go
+
1
−
2
View file @
c9425555
...
...
@@ -65,7 +65,7 @@ func main() {
)
{
signerSvc
=
signer
.
New
(
vault
,
cfg
.
Vault
.
SupportedKeys
,
httpClient
,
logger
)
healthSvc
=
health
.
New
()
healthSvc
=
health
.
New
(
Version
)
}
// create endpoints
...
...
@@ -112,7 +112,6 @@ func main() {
// read and not decoded in some other way.
// Can these definitions be simplified or taken out into a function for better readability?
{
signerServer
.
VerifyCredential
=
goasignersrv
.
NewVerifyCredentialHandler
(
signerEndpoints
.
VerifyCredential
,
mux
,
...
...
This diff is collapsed.
Click to expand it.
go.sum
+
89
−
0
View file @
c9425555
This diff is collapsed.
Click to expand it.
internal/service/health/service.go
+
22
−
8
View file @
c9425555
package
health
import
"context"
import
(
"context"
type
Service
struct
{}
"gitlab.eclipse.org/eclipse/xfsc/tsa/signer/gen/health"
)
func
New
()
*
Service
{
return
&
Service
{}
type
Service
struct
{
ver
string
}
func
(
s
*
Service
)
Liveness
(
_
context
.
Context
)
error
{
return
nil
func
New
(
version
string
)
*
Service
{
return
&
Service
{
ver
:
version
}
}
func
(
s
*
Service
)
Readiness
(
_
context
.
Context
)
error
{
return
nil
func
(
s
*
Service
)
Liveness
(
_
context
.
Context
)
(
*
health
.
HealthResponse
,
error
)
{
return
&
health
.
HealthResponse
{
Service
:
"signer"
,
Status
:
"up"
,
Version
:
s
.
ver
,
},
nil
}
func
(
s
*
Service
)
Readiness
(
_
context
.
Context
)
(
*
health
.
HealthResponse
,
error
)
{
return
&
health
.
HealthResponse
{
Service
:
"signer"
,
Status
:
"up"
,
Version
:
s
.
ver
,
},
nil
}
This diff is collapsed.
Click to expand it.
internal/service/signer/service.go
+
62
−
4
View file @
c9425555
...
...
@@ -128,7 +128,7 @@ func (s *Service) NamespaceKeys(ctx context.Context, req *signer.NamespaceKeysRe
// VerificationMethod returns a single public key formatted as DID verification method.
func
(
s
*
Service
)
VerificationMethod
(
ctx
context
.
Context
,
req
*
signer
.
VerificationMethodRequest
)
(
*
signer
.
DIDVerificationMethod
,
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"
getKey
"
),
zap
.
String
(
"operation"
,
"
verificationMethod
"
),
zap
.
String
(
"namespace"
,
req
.
Namespace
),
zap
.
String
(
"key"
,
req
.
Key
),
zap
.
String
(
"did"
,
req
.
Did
),
...
...
@@ -165,7 +165,7 @@ func (s *Service) VerificationMethod(ctx context.Context, req *signer.Verificati
// VerificationMethods returns all public keys from Vault or OCM.
func
(
s
*
Service
)
VerificationMethods
(
ctx
context
.
Context
,
req
*
signer
.
VerificationMethodsRequest
)
(
res
[]
*
signer
.
DIDVerificationMethod
,
err
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"
getKey
s"
),
zap
.
String
(
"operation"
,
"
verificationMethod
s"
),
zap
.
String
(
"namespace"
,
req
.
Namespace
),
zap
.
String
(
"did"
,
req
.
Did
),
)
...
...
@@ -324,6 +324,64 @@ func (s *Service) PresentationProof(ctx context.Context, req *signer.Presentatio
return
vpWithProof
,
nil
}
// CreateCredential creates Verifiable Credential with proof from raw JSON data.
func
(
s
*
Service
)
CreateCredential
(
ctx
context
.
Context
,
req
*
signer
.
CreateCredentialRequest
)
(
interface
{},
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"createCredential"
),
zap
.
String
(
"namespace"
,
req
.
Namespace
),
zap
.
String
(
"key"
,
req
.
Key
),
zap
.
String
(
"issuer"
,
req
.
Issuer
),
)
if
req
.
CredentialSubject
==
nil
{
logger
.
Error
(
"invalid or missing credential subject"
)
return
nil
,
errors
.
New
(
errors
.
BadRequest
,
"invalid or missing credential subject"
)
}
credSubject
,
ok
:=
req
.
CredentialSubject
.
(
map
[
string
]
interface
{})
if
!
ok
||
len
(
credSubject
)
==
0
{
logger
.
Error
(
"invalid credential subject: non-empty map is expected"
)
return
nil
,
errors
.
New
(
errors
.
BadRequest
,
"invalid credential subject: non-empty map is expected"
)
}
// add additional jsonld contexts only if they are different from the default
jsonldContexts
:=
defaultJSONLDContexts
for
_
,
jsonldContext
:=
range
req
.
Context
{
if
!
containContext
(
defaultJSONLDContexts
,
jsonldContext
)
{
jsonldContexts
=
append
(
jsonldContexts
,
jsonldContext
)
}
}
var
subject
verifiable
.
Subject
if
subjectID
,
ok
:=
credSubject
[
"id"
]
.
(
string
);
ok
&&
len
(
subjectID
)
>
0
{
subject
.
ID
=
subjectID
delete
(
credSubject
,
"id"
)
}
subject
.
CustomFields
=
credSubject
vc
:=
&
verifiable
.
Credential
{
Context
:
jsonldContexts
,
Types
:
[]
string
{
verifiable
.
VCType
},
Issuer
:
verifiable
.
Issuer
{
ID
:
req
.
Issuer
},
Issued
:
&
util
.
TimeWrapper
{
Time
:
time
.
Now
()},
Subject
:
subject
,
}
err
:=
validateCredentialSubject
(
vc
.
Subject
)
if
err
!=
nil
{
logger
.
Error
(
"invalid credential subject"
,
zap
.
Error
(
err
))
return
nil
,
errors
.
New
(
errors
.
BadRequest
,
err
)
}
vcWithProof
,
err
:=
s
.
addCredentialProof
(
ctx
,
req
.
Issuer
,
req
.
Namespace
,
req
.
Key
,
vc
)
if
err
!=
nil
{
logger
.
Error
(
"error making credential proof"
,
zap
.
Error
(
err
))
return
nil
,
err
}
return
vcWithProof
,
nil
}
// CreatePresentation creates VP with proof from raw JSON data.
func
(
s
*
Service
)
CreatePresentation
(
ctx
context
.
Context
,
req
*
signer
.
CreatePresentationRequest
)
(
interface
{},
error
)
{
logger
:=
s
.
logger
.
With
(
...
...
@@ -595,11 +653,11 @@ func validateCredentialSubject(subject interface{}) error {
func
validateSubjectID
(
id
string
)
error
{
s
:=
strings
.
Split
(
id
,
":"
)
if
len
(
s
)
<
2
{
return
fmt
.
Errorf
(
"invalid
format of
subject id"
)
return
fmt
.
Errorf
(
"invalid subject id
: must be URI
"
)
}
if
len
(
s
[
0
])
==
0
||
len
(
s
[
1
])
==
0
{
return
fmt
.
Errorf
(
"invalid
format of
subject id"
)
return
fmt
.
Errorf
(
"invalid subject id
: must be URI
"
)
}
return
nil
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment