Skip to content

Commit

Permalink
fix(credential-ld): remove fs dependency for JSON LD default contexts (
Browse files Browse the repository at this point in the history
…#868)

* remove fs dependency for JSON LD default contexts
* add contexts/*.json files in the build output

fixes #837
  • Loading branch information
italobb committed May 23, 2022
1 parent 5150b0e commit 2f75935
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 18 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/credential-ld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"files": [
"build/**/*",
"src/**/*",
"contexts/**/*.jsonld",
"contexts/**/*.json",
"plugin.schema.json",
"README.md",
"LICENSE"
Expand Down
27 changes: 11 additions & 16 deletions packages/credential-ld/src/ld-default-contexts.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import * as fs from 'fs'
import * as path from 'path'
import { ContextDoc } from './types'

async function _read(_path: string): Promise<ContextDoc> {
const contextDefinition = await fs.promises.readFile(path.join(__dirname, '../contexts', _path), {
encoding: 'utf8',
})
return JSON.parse(contextDefinition)
return await import('../contexts/' + _path);
}

/**
* Provides a hardcoded map of common context definitions
*/
export const LdDefaultContexts = new Map([
['https://www.w3.org/2018/credentials/v1', _read('w3_2018_credentials_v1.jsonld')],
['https://www.w3.org/ns/did/v1', _read('security_context_v1.jsonld')],
['https://w3id.org/did/v0.11', _read('did_v0.11.jsonld')],
['https://www.w3.org/2018/credentials/v1', _read('w3_2018_credentials_v1.json')],
['https://www.w3.org/ns/did/v1', _read('security_context_v1.json')],
['https://w3id.org/did/v0.11', _read('did_v0.11.json')],

['https://veramo.io/contexts/socialmedia/v1', _read('socialmedia-v1.jsonld')],
['https://veramo.io/contexts/kyc/v1', _read('kyc-v1.jsonld')],
['https://veramo.io/contexts/profile/v1', _read('profile-v1.jsonld')],
['https://ns.did.ai/transmute/v1', _read('transmute_v1.jsonld')],
['https://veramo.io/contexts/socialmedia/v1', _read('socialmedia-v1.json')],
['https://veramo.io/contexts/kyc/v1', _read('kyc-v1.json')],
['https://veramo.io/contexts/profile/v1', _read('profile-v1.json')],
['https://ns.did.ai/transmute/v1', _read('transmute_v1.json')],
[
'https://identity.foundation/EcdsaSecp256k1RecoverySignature2020/lds-ecdsa-secp256k1-recovery2020-0.0.jsonld',
_read('lds-ecdsa-secp256k1-recovery2020-0.0.jsonld'),
_read('lds-ecdsa-secp256k1-recovery2020-0.0.json'),
],
['https://w3id.org/security/suites/ed25519-2018/v1', _read('ed25519-signature-2018-v1.jsonld')],
['https://w3id.org/security/suites/x25519-2019/v1', _read('X25519KeyAgreementKey2019.jsonld')],
['https://w3id.org/security/suites/ed25519-2018/v1', _read('ed25519-signature-2018-v1.json')],
['https://w3id.org/security/suites/x25519-2019/v1', _read('X25519KeyAgreementKey2019.json')],
])
3 changes: 2 additions & 1 deletion packages/credential-ld/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"outDir": "build",
"declarationDir": "build",
// https://github.com/transmute-industries/vc.js/issues/60
"skipLibCheck": true
"skipLibCheck": true,
"resolveJsonModule": true
},
"references": [
{ "path": "../core" },
Expand Down

0 comments on commit 2f75935

Please sign in to comment.