-
Notifications
You must be signed in to change notification settings - Fork 28
/
document_loader.go
46 lines (37 loc) · 1.26 KB
/
document_loader.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package ld
import (
_ "embed" //nolint:gci // required for go:embed
"fmt"
jsonld "github.com/piprate/json-gold/ld"
ldcontext "github.com/trustbloc/did-go/doc/ld/context"
lddocloader "github.com/trustbloc/did-go/doc/ld/documentloader"
ldstore "github.com/trustbloc/did-go/doc/ld/store"
)
// nolint:gochecknoglobals //embedded contexts
var (
//go:embed contexts/lds-jws2020-v1.jsonld
jws2020V1Vocab []byte
)
var embedContexts = []ldcontext.Document{ //nolint:gochecknoglobals
{
URL: "https://w3c-ccg.github.io/lds-jws2020/contexts/lds-jws2020-v1.json",
Content: jws2020V1Vocab,
},
}
// provider contains dependencies for the JSON-LD document loader.
type provider interface {
JSONLDContextStore() ldstore.ContextStore
JSONLDRemoteProviderStore() ldstore.RemoteProviderStore
}
// NewDocumentLoader returns a JSON-LD document loader with preloaded contexts.
func NewDocumentLoader(p provider, opts ...lddocloader.Opts) (jsonld.DocumentLoader, error) {
loader, err := lddocloader.NewDocumentLoader(p, append(opts, lddocloader.WithExtraContexts(embedContexts...))...)
if err != nil {
return nil, fmt.Errorf("new document loader: %w", err)
}
return loader, nil
}