ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

82 lines
2.7 KiB

  1. import jsonld from 'jsonld'
  2. const STATIC_CACHE = {
  3. 'https://w3id.org/security/v1': {
  4. '@context': {
  5. id: '@id',
  6. type: '@type',
  7. dc: 'http://purl.org/dc/terms/',
  8. sec: 'https://w3id.org/security#',
  9. xsd: 'http://www.w3.org/2001/XMLSchema#',
  10. EcdsaKoblitzSignature2016: 'sec:EcdsaKoblitzSignature2016',
  11. Ed25519Signature2018: 'sec:Ed25519Signature2018',
  12. EncryptedMessage: 'sec:EncryptedMessage',
  13. GraphSignature2012: 'sec:GraphSignature2012',
  14. LinkedDataSignature2015: 'sec:LinkedDataSignature2015',
  15. LinkedDataSignature2016: 'sec:LinkedDataSignature2016',
  16. CryptographicKey: 'sec:Key',
  17. authenticationTag: 'sec:authenticationTag',
  18. canonicalizationAlgorithm: 'sec:canonicalizationAlgorithm',
  19. cipherAlgorithm: 'sec:cipherAlgorithm',
  20. cipherData: 'sec:cipherData',
  21. cipherKey: 'sec:cipherKey',
  22. created: { '@id': 'dc:created', '@type': 'xsd:dateTime' },
  23. creator: { '@id': 'dc:creator', '@type': '@id' },
  24. digestAlgorithm: 'sec:digestAlgorithm',
  25. digestValue: 'sec:digestValue',
  26. domain: 'sec:domain',
  27. encryptionKey: 'sec:encryptionKey',
  28. expiration: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
  29. expires: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
  30. initializationVector: 'sec:initializationVector',
  31. iterationCount: 'sec:iterationCount',
  32. nonce: 'sec:nonce',
  33. normalizationAlgorithm: 'sec:normalizationAlgorithm',
  34. owner: { '@id': 'sec:owner', '@type': '@id' },
  35. password: 'sec:password',
  36. privateKey: { '@id': 'sec:privateKey', '@type': '@id' },
  37. privateKeyPem: 'sec:privateKeyPem',
  38. publicKey: { '@id': 'sec:publicKey', '@type': '@id' },
  39. publicKeyBase58: 'sec:publicKeyBase58',
  40. publicKeyPem: 'sec:publicKeyPem',
  41. publicKeyWif: 'sec:publicKeyWif',
  42. publicKeyService: { '@id': 'sec:publicKeyService', '@type': '@id' },
  43. revoked: { '@id': 'sec:revoked', '@type': 'xsd:dateTime' },
  44. salt: 'sec:salt',
  45. signature: 'sec:signature',
  46. signatureAlgorithm: 'sec:signingAlgorithm',
  47. signatureValue: 'sec:signatureValue'
  48. }
  49. }
  50. }
  51. const localCache = new Map<string, any>()
  52. const nodeDocumentLoader = (jsonld as any).documentLoaders.node();
  53. /* eslint-disable no-import-assign */
  54. (jsonld as any).documentLoader = async (url: string) => {
  55. if (url in STATIC_CACHE) {
  56. return {
  57. contextUrl: null,
  58. document: STATIC_CACHE[url],
  59. documentUrl: url
  60. }
  61. }
  62. if (localCache.has(url)) return localCache.get(url)
  63. const remoteDoc = await nodeDocumentLoader(url)
  64. if (localCache.size < 100) {
  65. localCache.set(url, remoteDoc)
  66. }
  67. return remoteDoc
  68. }
  69. export { jsonld }