@blockcerts/blockcerts-verifier 1.72.0 → 1.72.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.husky/commit-msg +0 -3
- package/.husky/pre-commit +0 -3
- package/.husky/pre-push +0 -3
- package/bundle-stats.html +33 -32
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov.info +7030 -0
- package/dist/{DataIntegrityProof-CsicZNrL-BkSRjzkI.js → DataIntegrityProof-BhL7Kkhm-affsdujn.js} +2 -2
- package/dist/EcdsaSd2023-CUjrjGzC-Cx7ejHu-.js +30 -0
- package/dist/EcdsaSecp256k1Signature2019-D90cAynb-Bf5kILPF.js +1 -0
- package/dist/{Ed25519Signature2020-CglkQLKN-CQ6lMzyG.js → Ed25519Signature2020-fJGvlbIp-B6XhFwr4.js} +4 -4
- package/dist/EddsaRdfc2022-XufziFi3-D5IoKiRE.js +14 -0
- package/dist/HashlinkVerifier-udsj5z09-BTqOkVoD.js +8 -0
- package/dist/MerkleProof2017-C0RhRNNx-zjQMRSQY.js +1 -0
- package/dist/MerkleProof2017-C499XBV8-l50m9izr.js +74 -0
- package/dist/MerkleProof2019-B7f1hhem-CjLDyx6Q.js +5 -0
- package/dist/Suite-Bu3gszvt-Dmvbh142.js +33 -0
- package/dist/_polyfill-node.crypto-DGISCHrB-C5-OOGc0.js +1 -0
- package/dist/checkCredentialSchemaConformity-CgpOS3eC-AjSPoJub.js +1 -0
- package/dist/{checkRevocationStatusList2021-BDBFhnz6-BEBD8TO8.js → checkRevocationStatusList2021-D4VNDRlW-DgNfOAoI.js} +2 -2
- package/dist/controlVerificationMethod-CSwPoUL8-CvUADmjg.js +1 -0
- package/dist/downloadPDF-UAsY-nU_.js +297 -0
- package/dist/ed25519-key-pair.esm-DxoBwwVJ-D8j8wFfG.js +1 -0
- package/dist/ensureNotRevoked-ByWaYoog-BheL-ZKZ.js +1 -0
- package/dist/ensureNotRevoked-C1kT3A6R-oFUZltl3.js +1 -0
- package/dist/{ensureValidIssuingKey-wTUvNuDH-BdV46XBb.js → ensureValidIssuingKey-DEV9E0Ph-DY8BTObG.js} +1 -1
- package/dist/index-DZ7aUhT_-D0G2DVsh.js +29 -0
- package/dist/index-DjD0A6uJ-BdFUkPCF.js +33 -0
- package/dist/index-RfFwckcH.js +1 -0
- package/dist/index-tlZQQ_rg-CYTlxhyY.js +1 -0
- package/dist/index.es-CnYWLNZV.js +56 -0
- package/dist/jsonld-signatures-D4X_Irzi-D_wBqxSl.js +56 -0
- package/dist/main.js +142 -133
- package/dist/pako.esm-BGRKTPxS-Bodm4Eha.js +2 -0
- package/dist/purify.es-Om653OSQ.js +2 -0
- package/dist/retrieveVerificationMethodPublicKey-D_autuwE-DGbK-RPm.js +1 -0
- package/dist/sha2-JcCWfgvE-By1_saxP.js +2 -0
- package/dist/verifyIssuerProfile-2PhdMtQZ-CfqcAkBL.js +1 -0
- package/dist/webcrypto.es-BOyMRPOj-CAxP3jJR.js +40 -0
- package/package.json +15 -16
- package/vitest.config.ts +4 -1
- package/dist/EcdsaSd2023-DN9HBdgh-Bc0hVwTd.js +0 -30
- package/dist/EcdsaSecp256k1Signature2019-C3F03t_M-DAJeMTpu.js +0 -1
- package/dist/EddsaRdfc2022-CfoLi-PP-l7ITLQQT.js +0 -14
- package/dist/HashlinkVerifier-CTG-OS14-B4Niv2-b.js +0 -8
- package/dist/MerkleProof2017-B_EJmYja-CYd4dJc1.js +0 -1
- package/dist/MerkleProof2017-MZJbBTpc-Cwfnte6F.js +0 -75
- package/dist/MerkleProof2019-B7t13hOo-D8n9YrUw.js +0 -13
- package/dist/Suite-BmP2Qu19-D1ucdMDB.js +0 -1
- package/dist/_commonjs-dynamic-modules-COweQ1RR-BHR_E30J.js +0 -1
- package/dist/base64url-Cy03LJLt-vkTPfQOh.js +0 -4
- package/dist/checkCredentialSchemaConformity-BiggGGMP-Dx992E4t.js +0 -1
- package/dist/controlVerificationMethod-Bh_-e0Fd-BUCC8ctY.js +0 -1
- package/dist/did-key-common.esm-BELyYVSE-Cqrpf7cy.js +0 -9
- package/dist/did-key-ed25519.esm-C3GUddDp-BJdBgNDg.js +0 -1
- package/dist/did-key-secp256k1.esm-D-R266jM-BTxlD5VW.js +0 -1
- package/dist/downloadPDF-D2qwT_DJ.js +0 -297
- package/dist/ed25519-key-pair.esm-DQF2kkXh-XX5BXBcl.js +0 -25
- package/dist/elliptic-6I21PEnR-CsYseRX1.js +0 -1
- package/dist/elliptic-mDX7fQQx-BpaNaVm0.js +0 -1
- package/dist/ensureNotRevoked-Dc6VA2bO-DvMIgM4L.js +0 -1
- package/dist/ensureNotRevoked-gui-UMnE-o08xNOvL.js +0 -1
- package/dist/index-BrurC4Vt-C0eXpZGn.js +0 -1
- package/dist/index-CEj3k9G6.js +0 -2
- package/dist/index-DXh-XAic-B2gT500V.js +0 -22
- package/dist/index-DZLKRa_V-D_IQzjvG.js +0 -5
- package/dist/index-fQcSLZgh-DpptYyN8.js +0 -1
- package/dist/index.es-BIiEi3w5.js +0 -56
- package/dist/jsonld-BAMY2WqE-BJ5uVeOU.js +0 -36
- package/dist/jsonld-signatures-BbHr1fSN-BSospRuX.js +0 -74
- package/dist/keyUtils-ue8EY3Op-DoHdKWgN.js +0 -1
- package/dist/pako.esm-BGRKTPxS-UdHShO7y.js +0 -2
- package/dist/purify.es-CkKsfeyH.js +0 -2
- package/dist/retrieveVerificationMethodPublicKey-CLBY4G8P-CagFGnNt.js +0 -1
- package/dist/sha256-Bwge_vjI-C1PUWFZm.js +0 -1
- package/dist/verifyIssuerProfile-BaiZaU2c-Zcu1X0PY.js +0 -1
- package/dist/webcrypto.es-DptGOl2T-BnVhHKeM.js +0 -40
- package/dist/x25519-hG3WOzPe-Dh8L0KYb.js +0 -1
- /package/dist/{index-Gr4i_Ned-Dgus2xdV.js → index-CyNtT_1q-Dgus2xdV.js} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import{d as e,r as t,V as n,g as o,i,a as r,b as a,p as s,c as l}from"./index-RfFwckcH.js";import{Buffer as c}from"buffer";var d={},u=class e{constructor(e,t=new Map,n=0){this.prefix=e,this._existing=t,this.counter=n}clone(){const{prefix:t,_existing:n,counter:o}=this;return new e(t,new Map(n),o)}getId(e){const t=e&&this._existing.get(e);if(t)return t;const n=this.prefix+this.counter;return this.counter++,e&&this._existing.set(e,n),n}hasId(e){return this._existing.has(e)}getOldIds(){return[...this._existing.keys()]}},p={},h="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function f(){throw new Error("setTimeout has not been defined")}function v(){throw new Error("clearTimeout has not been defined")}var g=f,y=v;function m(e){if(g===setTimeout)return setTimeout(e,0);if((g===f||!g)&&setTimeout)return g=setTimeout,setTimeout(e,0);try{return g(e,0)}catch(t){try{return g.call(null,e,0)}catch(t){return g.call(this,e,0)}}}"function"==typeof h.setTimeout&&(g=setTimeout),"function"==typeof h.clearTimeout&&(y=clearTimeout);var x,w=[],b=!1,I=-1;function j(){b&&x&&(b=!1,x.length?w=x.concat(w):I=-1,w.length&&S())}function S(){if(!b){var e=m(j);b=!0;for(var t=w.length;t;){for(x=w,w=[];++I<t;)x&&x[I].run();I=-1,t=w.length}x=null,b=!1,function(e){if(y===clearTimeout)return clearTimeout(e);if((y===v||!y)&&clearTimeout)return y=clearTimeout,clearTimeout(e);try{return y(e)}catch(t){try{return y.call(null,e)}catch(t){return y.call(this,e)}}}(e)}}function k(e,t){this.fun=e,this.array=t}k.prototype.run=function(){this.fun.apply(null,this.array)};var E=h.performance||{};E.now||E.mozNow||E.msNow||E.oNow||E.webkitNow,function(e){if(!e.setImmediate){var t,n,o,i,r,a=1,s={},l=!1,c=e.document,d=Object.getPrototypeOf&&Object.getPrototypeOf(e);d=d&&d.setTimeout?d:e,"[object process]"==={}.toString.call(e.process)?t=function(e){!function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];w.push(new k(e,t)),1!==w.length||b||m(S)}(function(){p(e)})}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t}}()?e.MessageChannel?((o=new MessageChannel).port1.onmessage=function(e){p(e.data)},t=function(e){o.port2.postMessage(e)}):c&&"onreadystatechange"in c.createElement("script")?(n=c.documentElement,t=function(e){var t=c.createElement("script");t.onreadystatechange=function(){p(e),t.onreadystatechange=null,n.removeChild(t),t=null},n.appendChild(t)}):t=function(e){setTimeout(p,0,e)}:(i="setImmediate$"+Math.random()+"$",r=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(i)&&p(+t.data.slice(i.length))},e.addEventListener?e.addEventListener("message",r,!1):e.attachEvent("onmessage",r),t=function(t){e.postMessage(i+t,"*")}),d.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var n=new Array(arguments.length-1),o=0;o<n.length;o++)n[o]=arguments[o+1];var i={callback:e,args:n};return s[a]=i,t(a),a++},d.clearImmediate=u}function u(e){delete s[e]}function p(e){if(l)setTimeout(p,0,e);else{var t=s[e];if(t){l=!0;try{!function(e){var t=e.callback,n=e.args;switch(n.length){case 0:t();break;case 1:t(n[0]);break;case 2:t(n[0],n[1]);break;case 3:t(n[0],n[1],n[2]);break;default:t.apply(void 0,n)}}(t)}finally{u(e),l=!1}}}}}("undefined"==typeof self?l:self),
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
p.setImmediate=setImmediate,p.crypto=globalThis.crypto;const D=[];for(let e=0;e<=255;++e)D.push(e.toString(16).padStart(2,"0"));p.bufferToHex=function(e){let t="";const n=new Uint8Array(e);for(let e=0;e<n.length;++e)t+=D[n[e]];return t};
|
|
6
|
+
/*!
|
|
7
|
+
* Copyright (c) 2016-2023 Digital Bazaar, Inc. All rights reserved.
|
|
8
|
+
*/
|
|
9
|
+
const{bufferToHex:O,crypto:N}=p,C=new Map([["sha256","SHA-256"],["SHA256","SHA-256"],["SHA-256","SHA-256"],["sha384","SHA-384"],["SHA384","SHA-384"],["SHA-384","SHA-384"],["sha512","SHA-512"],["SHA512","SHA-512"],["SHA-512","SHA-512"]]);var A=class{constructor(e){if(!N||!N.subtle)throw new Error("crypto.subtle not found.");if(!C.has(e))throw new Error(`Unsupported algorithm "${e}".`);this.algorithm=C.get(e),this._content=""}update(e){this._content+=e}async digest(){const e=(new TextEncoder).encode(this._content),t=await N.subtle.digest(this.algorithm,e);return O(t)}},L=class{constructor(e){this.current=e.sort(),this.done=!1,this.dir=new Map;for(let t=0;t<e.length;++t)this.dir.set(e[t],!0)}hasNext(){return!this.done}next(){const{current:e,dir:t}=this,n=e.slice();let o=null,i=0;const r=e.length;for(let n=0;n<r;++n){const a=e[n],s=t.get(a);(null===o||a>o)&&(s&&n>0&&a>e[n-1]||!s&&n<r-1&&a>e[n+1])&&(o=a,i=n)}if(null===o)this.done=!0;else{const n=t.get(o)?i-1:i+1;e[i]=e[n],e[n]=o;for(const n of e)n>o&&t.set(n,!t.get(n))}return n}};
|
|
10
|
+
/*!
|
|
11
|
+
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.
|
|
12
|
+
*/
|
|
13
|
+
/*!
|
|
14
|
+
* Copyright (c) 2016-2022 Digital Bazaar, Inc. All rights reserved.
|
|
15
|
+
*/
|
|
16
|
+
const R="http://www.w3.org/1999/02/22-rdf-syntax-ns#langString",T="http://www.w3.org/2001/XMLSchema#string",_="NamedNode",P="BlankNode",M="Literal",H={};(()=>{const e="A-Za-zÀ-ÖØ-öø-˿Ͱ-ͽͿ--⁰-Ⰰ-、-豈-﷏ﷰ-�_",t=e+"0-9-·̀-ͯ‿-⁀",n="_:((?:["+e+"0-9])(?:(?:["+t+".])*(?:["+t+"]))?)",o='(?:<((?:[^\0- <>"{}|^`\\\\]|\\\\u[0-9A-Fa-f]{4}|\\\\U[0-9A-Fa-f]{8})*)>)',i="[ \\t]+",r="[ \\t]*",a="(?:"+o+"|"+n+")"+i,s=o+i,l="(?:"+o+"|"+n+"|"+('(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"(?:'+("(?:\\^\\^"+o+")")+"|(?:@([a-zA-Z]+(?:-[a-zA-Z0-9]+)*)))?)")+")"+r,c="(?:\\.|(?:(?:"+o+"|"+n+")"+r+"\\.))";H.eoln=/(?:\r\n)|(?:\n)|(?:\r)/g,H.empty=new RegExp("^"+r+"$"),H.quad=new RegExp("^"+r+a+s+l+c+r+"$")})();var J=class e{static parse(e){const t=[],n={},o=e.split(H.eoln);let i=0;for(const e of o){if(i++,H.empty.test(e))continue;const o=e.match(H.quad);if(null===o)throw new Error("N-Quads parse error on line "+i+".");const r={subject:null,predicate:null,object:null,graph:null};if(void 0!==o[1]?r.subject={termType:_,value:Q(o[1])}:r.subject={termType:P,value:o[2]},r.predicate={termType:_,value:Q(o[3])},void 0!==o[4]?r.object={termType:_,value:Q(o[4])}:void 0!==o[5]?r.object={termType:P,value:o[5]}:(r.object={termType:M,value:void 0,datatype:{termType:_}},void 0!==o[7]?r.object.datatype.value=Q(o[7]):void 0!==o[8]?(r.object.datatype.value=R,r.object.language=o[8]):r.object.datatype.value=T,r.object.value=V(o[6])),void 0!==o[9]?r.graph={termType:_,value:Q(o[9])}:void 0!==o[10]?r.graph={termType:P,value:o[10]}:r.graph={termType:"DefaultGraph",value:""},r.graph.value in n){let e=!0;const o=n[r.graph.value];for(const t of o)if(F(t,r)){e=!1;break}e&&(o.push(r),t.push(r))}else n[r.graph.value]=[r],t.push(r)}return t}static serialize(t){const n=[];for(const o of t)n.push(e.serializeQuad(o));return n.sort().join("")}static serializeQuadComponents(e,t,n,o){let i="";return e.termType===_?i+=`<${z(e.value)}>`:i+=`_:${e.value}`,t.termType===_?i+=` <${z(t.value)}> `:i+=` _:${t.value} `,n.termType===_?i+=`<${z(n.value)}>`:n.termType===P?i+=`_:${n.value}`:(i+=`"${function(e){if(!U.test(e))return e;return e.replace(U,function(e){return B[e.codePointAt(0)]})}(n.value)}"`,n.datatype.value===R?n.language&&(i+=`@${n.language}`):n.datatype.value!==T&&(i+=`^^<${z(n.datatype.value)}>`)),o.termType===_?i+=` <${z(o.value)}>`:o.termType===P&&(i+=` _:${o.value}`),i+=" .\n",i}static serializeQuad(t){return e.serializeQuadComponents(t.subject,t.predicate,t.object,t.graph)}};function F(e,t){return e.subject.termType===t.subject.termType&&e.object.termType===t.object.termType&&(e.subject.value===t.subject.value&&e.predicate.value===t.predicate.value&&e.object.value===t.object.value&&(e.object.termType!==M||e.object.datatype.termType===t.object.datatype.termType&&e.object.language===t.object.language&&e.object.datatype.value===t.object.datatype.value))}const U=/[\u0000-\u001F\u007F"\\]/g,B=[];for(let e=0;e<=127;++e)U.test(String.fromCharCode(e))&&(B[e]="\\u"+e.toString(16).toUpperCase().padStart(4,"0"),U.lastIndex=0);B["\b".codePointAt(0)]="\\b",B["\t".codePointAt(0)]="\\t",B["\n".codePointAt(0)]="\\n",B["\f".codePointAt(0)]="\\f",B["\r".codePointAt(0)]="\\r",B['"'.codePointAt(0)]='\\"',B["\\".codePointAt(0)]="\\\\";const q=/(?:\\([btnfr"'\\]))|(?:\\u([0-9A-Fa-f]{4}))|(?:\\U([0-9A-Fa-f]{8}))/g;function V(e){return q.test(e)?e.replace(q,function(e,t,n,o){if(t)switch(t){case"b":return"\b";case"t":return"\t";case"n":return"\n";case"f":return"\f";case"r":return"\r";case'"':return'"';case"'":return"'";case"\\":return"\\"}return n?String.fromCharCode(parseInt(n,16)):o?String.fromCodePoint(parseInt(o,16)):void 0}):e}const $=/[\u0000-\u0020<>"{}|^`\\]/g,G=[];for(let e=0;e<=127;++e)$.test(String.fromCharCode(e))&&(G[e]="\\u"+e.toString(16).toUpperCase().padStart(4,"0"),$.lastIndex=0);function z(e){return $.test(e)?e.replace($,function(e){return G[e.codePointAt(0)]}):e}const K=/(?:\\u([0-9A-Fa-f]{4}))|(?:\\U([0-9A-Fa-f]{8}))/g;function Q(e){return K.test(e)?e.replace(K,function(e,t,n){return t?String.fromCharCode(parseInt(t,16)):n?String.fromCodePoint(parseInt(n,16)):void 0}):e}
|
|
17
|
+
/*!
|
|
18
|
+
* Copyright (c) 2016-2023 Digital Bazaar, Inc. All rights reserved.
|
|
19
|
+
*/const W=u,X=A,Z=L,Y=J,{setImmediate:ee}=p;var te=class{constructor({createMessageDigest:e=null,messageDigestAlgorithm:t="sha256",canonicalIdMap:n=new Map,maxWorkFactor:o=1,maxDeepIterations:i=-1,signal:r=null}={}){this.name="RDFC-1.0",this.blankNodeInfo=new Map,this.canonicalIssuer=new W("c14n",n),this.createMessageDigest=e||(()=>new X(t)),this.maxWorkFactor=o,this.maxDeepIterations=i,this.remainingDeepIterations=0,this.signal=r,this.quads=null}async main(e){this.quads=e;for(const t of e)this._addBlankNodeQuadInfo({quad:t,component:t.subject}),this._addBlankNodeQuadInfo({quad:t,component:t.object}),this._addBlankNodeQuadInfo({quad:t,component:t.graph});const t=new Map,n=[...this.blankNodeInfo.keys()];let o=0;for(const e of n)++o%100==0&&await this._yield(),await this._hashAndTrackBlankNode({id:e,hashToBlankNodes:t});const i=[...t.keys()].sort(),r=[];for(const e of i){const n=t.get(e);if(n.length>1){r.push(n);continue}const o=n[0];this.canonicalIssuer.getId(o)}if(this.maxDeepIterations<0)if(0===this.maxWorkFactor)this.maxDeepIterations=0;else if(this.maxWorkFactor===1/0)this.maxDeepIterations=1/0;else{const e=r.reduce((e,t)=>e+t.length,0);this.maxDeepIterations=e**this.maxWorkFactor}this.maxDeepIterations>Number.MAX_SAFE_INTEGER&&(this.maxDeepIterations=1/0),this.remainingDeepIterations=this.maxDeepIterations;for(const e of r){const t=[];for(const n of e){if(this.canonicalIssuer.hasId(n))continue;const e=new W("b");e.getId(n);const o=await this.hashNDegreeQuads(n,e);t.push(o)}t.sort(ne);for(const e of t){const t=e.issuer.getOldIds();for(const e of t)this.canonicalIssuer.getId(e)}}const a=[];for(const e of this.quads){const t=Y.serializeQuadComponents(this._componentWithCanonicalId(e.subject),e.predicate,this._componentWithCanonicalId(e.object),this._componentWithCanonicalId(e.graph));a.push(t)}return a.sort(),a.join("")}async hashFirstDegreeQuads(e){const t=[],n=this.blankNodeInfo.get(e),o=n.quads;for(const n of o)t.push(Y.serializeQuadComponents(this.modifyFirstDegreeComponent(e,n.subject,"subject"),n.predicate,this.modifyFirstDegreeComponent(e,n.object,"object"),this.modifyFirstDegreeComponent(e,n.graph,"graph")));t.sort();const i=this.createMessageDigest();for(const e of t)i.update(e);return n.hash=await i.digest(),n.hash}async hashRelatedBlankNode(e,t,n,o){const i=this.createMessageDigest();let r;return i.update(o),"g"!==o&&i.update(this.getRelatedPredicate(t)),r=this.canonicalIssuer.hasId(e)?"_:"+this.canonicalIssuer.getId(e):n.hasId(e)?"_:"+n.getId(e):this.blankNodeInfo.get(e).hash,i.update(r),i.digest()}async hashNDegreeQuads(e,t){if(0===this.remainingDeepIterations)throw new Error(`Maximum deep iterations exceeded (${this.maxDeepIterations}).`);this.remainingDeepIterations--;const n=this.createMessageDigest(),o=await this.createHashToRelated(e,t),i=[...o.keys()].sort();for(const e of i){n.update(e);let i,r="";const a=new Z(o.get(e));let s=0;for(;a.hasNext();){const e=a.next();if(++s%3==0){if(this.signal&&this.signal.aborted)throw new Error(`Abort signal received: "${this.signal.reason}".`);await this._yield()}let n=t.clone(),o="";const l=[];let c=!1;for(const t of e)if(this.canonicalIssuer.hasId(t)?o+="_:"+this.canonicalIssuer.getId(t):(n.hasId(t)||l.push(t),o+="_:"+n.getId(t)),0!==r.length&&o>r){c=!0;break}if(!c){for(const e of l){const t=await this.hashNDegreeQuads(e,n);if(o+="_:"+n.getId(e),o+=`<${t.hash}>`,n=t.issuer,0!==r.length&&o>r){c=!0;break}}c||(0===r.length||o<r)&&(r=o,i=n)}}n.update(r),t=i}return{hash:await n.digest(),issuer:t}}modifyFirstDegreeComponent(e,t){return"BlankNode"!==t.termType?t:{termType:"BlankNode",value:t.value===e?"a":"z"}}getRelatedPredicate(e){return`<${e.predicate.value}>`}async createHashToRelated(e,t){const n=new Map,o=this.blankNodeInfo.get(e).quads;let i=0;for(const r of o)++i%100==0&&await this._yield(),await Promise.all([this._addRelatedBlankNodeHash({quad:r,component:r.subject,position:"s",id:e,issuer:t,hashToRelated:n}),this._addRelatedBlankNodeHash({quad:r,component:r.object,position:"o",id:e,issuer:t,hashToRelated:n}),this._addRelatedBlankNodeHash({quad:r,component:r.graph,position:"g",id:e,issuer:t,hashToRelated:n})]);return n}async _hashAndTrackBlankNode({id:e,hashToBlankNodes:t}){const n=await this.hashFirstDegreeQuads(e),o=t.get(n);o?o.push(e):t.set(n,[e])}_addBlankNodeQuadInfo({quad:e,component:t}){if("BlankNode"!==t.termType)return;const n=t.value,o=this.blankNodeInfo.get(n);o?o.quads.add(e):this.blankNodeInfo.set(n,{quads:new Set([e]),hash:null})}async _addRelatedBlankNodeHash({quad:e,component:t,position:n,id:o,issuer:i,hashToRelated:r}){if("BlankNode"!==t.termType||t.value===o)return;const a=t.value,s=await this.hashRelatedBlankNode(a,e,i,n),l=r.get(s);l?l.push(a):r.set(s,[a])}_componentWithCanonicalId(e){return"BlankNode"!==e.termType||e.value.startsWith(this.canonicalIssuer.prefix)?e:{termType:"BlankNode",value:this.canonicalIssuer.getId(e.value)}}async _yield(){return new Promise(e=>ee(e))}};function ne(e,t){return e.hash<t.hash?-1:e.hash>t.hash?1:0}
|
|
20
|
+
/*!
|
|
21
|
+
* Copyright (c) 2016-2023 Digital Bazaar, Inc. All rights reserved.
|
|
22
|
+
*/const oe=u,ie=A,re=L,ae=J;var se=class{constructor({createMessageDigest:e=null,messageDigestAlgorithm:t="sha256",canonicalIdMap:n=new Map,maxWorkFactor:o=1,maxDeepIterations:i=-1,timeout:r=0}={}){this.name="RDFC-1.0",this.blankNodeInfo=new Map,this.canonicalIssuer=new oe("c14n",n),this.createMessageDigest=e||(()=>new ie(t)),this.maxWorkFactor=o,this.maxDeepIterations=i,this.remainingDeepIterations=0,this.timeout=r,r>0&&(this.startTime=Date.now()),this.quads=null}main(e){this.quads=e;for(const t of e)this._addBlankNodeQuadInfo({quad:t,component:t.subject}),this._addBlankNodeQuadInfo({quad:t,component:t.object}),this._addBlankNodeQuadInfo({quad:t,component:t.graph});const t=new Map,n=[...this.blankNodeInfo.keys()];for(const e of n)this._hashAndTrackBlankNode({id:e,hashToBlankNodes:t});const o=[...t.keys()].sort(),i=[];for(const e of o){const n=t.get(e);if(n.length>1){i.push(n);continue}const o=n[0];this.canonicalIssuer.getId(o)}if(this.maxDeepIterations<0)if(0===this.maxWorkFactor)this.maxDeepIterations=0;else if(this.maxWorkFactor===1/0)this.maxDeepIterations=1/0;else{const e=i.reduce((e,t)=>e+t.length,0);this.maxDeepIterations=e**this.maxWorkFactor}this.maxDeepIterations>Number.MAX_SAFE_INTEGER&&(this.maxDeepIterations=1/0),this.remainingDeepIterations=this.maxDeepIterations;for(const e of i){const t=[];for(const n of e){if(this.canonicalIssuer.hasId(n))continue;const e=new oe("b");e.getId(n);const o=this.hashNDegreeQuads(n,e);t.push(o)}t.sort(le);for(const e of t){const t=e.issuer.getOldIds();for(const e of t)this.canonicalIssuer.getId(e)}}const r=[];for(const e of this.quads){const t=ae.serializeQuadComponents(this._componentWithCanonicalId(e.subject),e.predicate,this._componentWithCanonicalId(e.object),this._componentWithCanonicalId(e.graph));r.push(t)}return r.sort(),r.join("")}hashFirstDegreeQuads(e){const t=[],n=this.blankNodeInfo.get(e),o=n.quads;for(const n of o)t.push(ae.serializeQuadComponents(this.modifyFirstDegreeComponent(e,n.subject,"subject"),n.predicate,this.modifyFirstDegreeComponent(e,n.object,"object"),this.modifyFirstDegreeComponent(e,n.graph,"graph")));t.sort();const i=this.createMessageDigest();for(const e of t)i.update(e);return n.hash=i.digest(),n.hash}hashRelatedBlankNode(e,t,n,o){const i=this.createMessageDigest();let r;return i.update(o),"g"!==o&&i.update(this.getRelatedPredicate(t)),r=this.canonicalIssuer.hasId(e)?"_:"+this.canonicalIssuer.getId(e):n.hasId(e)?"_:"+n.getId(e):this.blankNodeInfo.get(e).hash,i.update(r),i.digest()}hashNDegreeQuads(e,t){if(0===this.remainingDeepIterations)throw new Error(`Maximum deep iterations exceeded (${this.maxDeepIterations}).`);this.remainingDeepIterations--;const n=this.createMessageDigest(),o=this.createHashToRelated(e,t),i=[...o.keys()].sort();for(const e of i){n.update(e);let i,r="";const a=new re(o.get(e));let s=0;for(;a.hasNext();){const e=a.next();if(++s%3==0&&this.timeout>0&&Date.now()-this.startTime>this.timeout)throw new Error("Canonize timeout.");let n=t.clone(),o="";const l=[];let c=!1;for(const t of e)if(this.canonicalIssuer.hasId(t)?o+="_:"+this.canonicalIssuer.getId(t):(n.hasId(t)||l.push(t),o+="_:"+n.getId(t)),0!==r.length&&o>r){c=!0;break}if(!c){for(const e of l){const t=this.hashNDegreeQuads(e,n);if(o+="_:"+n.getId(e),o+=`<${t.hash}>`,n=t.issuer,0!==r.length&&o>r){c=!0;break}}c||(0===r.length||o<r)&&(r=o,i=n)}}n.update(r),t=i}return{hash:n.digest(),issuer:t}}modifyFirstDegreeComponent(e,t){return"BlankNode"!==t.termType?t:{termType:"BlankNode",value:t.value===e?"a":"z"}}getRelatedPredicate(e){return`<${e.predicate.value}>`}createHashToRelated(e,t){const n=new Map,o=this.blankNodeInfo.get(e).quads;for(const i of o)this._addRelatedBlankNodeHash({quad:i,component:i.subject,position:"s",id:e,issuer:t,hashToRelated:n}),this._addRelatedBlankNodeHash({quad:i,component:i.object,position:"o",id:e,issuer:t,hashToRelated:n}),this._addRelatedBlankNodeHash({quad:i,component:i.graph,position:"g",id:e,issuer:t,hashToRelated:n});return n}_hashAndTrackBlankNode({id:e,hashToBlankNodes:t}){const n=this.hashFirstDegreeQuads(e),o=t.get(n);o?o.push(e):t.set(n,[e])}_addBlankNodeQuadInfo({quad:e,component:t}){if("BlankNode"!==t.termType)return;const n=t.value,o=this.blankNodeInfo.get(n);o?o.quads.add(e):this.blankNodeInfo.set(n,{quads:new Set([e]),hash:null})}_addRelatedBlankNodeHash({quad:e,component:t,position:n,id:o,issuer:i,hashToRelated:r}){if("BlankNode"!==t.termType||t.value===o)return;const a=t.value,s=this.hashRelatedBlankNode(a,e,i,n),l=r.get(s);l?l.push(a):r.set(s,[a])}_componentWithCanonicalId(e){return"BlankNode"!==e.termType||e.value.startsWith(this.canonicalIssuer.prefix)?e:{termType:"BlankNode",value:this.canonicalIssuer.getId(e.value)}}};function le(e,t){return e.hash<t.hash?-1:e.hash>t.hash?1:0}!function(e){const t=te,n=se;function o(t,n){if(n.inputFormat){if("application/n-quads"===n.inputFormat){if("string"!=typeof t)throw new Error("N-Quads input must be a string.");return e.NQuads.parse(t)}throw new Error(`Unknown canonicalization input format: "${n.inputFormat}".`)}return t}function i(e){if(e.format&&"application/n-quads"!==e.format)throw new Error(`Unknown canonicalization output format: "${e.format}".`)}function r(){globalThis.RDF_CANONIZE_TRACE_URDNA2015&&console.trace("[rdf-canonize] URDNA2015 is deprecated, use RDFC-1.0")}e.NQuads=J,e.IdentifierIssuer=u,e.canonize=async function(e,n={}){const a=o(e,n);if(i(n),!("algorithm"in n))throw new Error("No RDF Dataset Canonicalization algorithm specified.");if("RDFC-1.0"===n.algorithm)return new t(n).main(a);if("URDNA2015"===n.algorithm&&!n.rejectURDNA2015)return r(),new t(n).main(a);throw new Error("Invalid RDF Dataset Canonicalization algorithm: "+n.algorithm)},e._canonizeSync=function(e,t={}){const a=o(e,t);if(i(t),!("algorithm"in t))throw new Error("No RDF Dataset Canonicalization algorithm specified.");if("RDFC-1.0"===t.algorithm)return new n(t).main(a);if("URDNA2015"===t.algorithm&&!t.rejectURDNA2015)return r(),new n(t).main(a);throw new Error("Invalid RDF Dataset Canonicalization algorithm: "+t.algorithm)}}(d);var ce=d;const de={};var ue=de;de.isArray=Array.isArray,de.isBoolean=e=>"boolean"==typeof e||"[object Boolean]"===Object.prototype.toString.call(e),de.isDouble=e=>de.isNumber(e)&&(-1!==String(e).indexOf(".")||Math.abs(e)>=1e21),de.isEmptyObject=e=>de.isObject(e)&&0===Object.keys(e).length,de.isNumber=e=>"number"==typeof e||"[object Number]"===Object.prototype.toString.call(e),de.isNumeric=e=>!isNaN(parseFloat(e))&&isFinite(e),de.isObject=e=>"[object Object]"===Object.prototype.toString.call(e),de.isString=e=>"string"==typeof e||"[object String]"===Object.prototype.toString.call(e),de.isUndefined=e=>void 0===e;const pe=ue,he={};var fe=he;he.isSubject=e=>{if(pe.isObject(e)&&!("@value"in e||"@set"in e||"@list"in e)){return Object.keys(e).length>1||!("@id"in e)}return!1},he.isSubjectReference=e=>pe.isObject(e)&&1===Object.keys(e).length&&"@id"in e,he.isValue=e=>pe.isObject(e)&&"@value"in e,he.isList=e=>pe.isObject(e)&&"@list"in e,he.isGraph=e=>pe.isObject(e)&&"@graph"in e&&1===Object.keys(e).filter(e=>"@id"!==e&&"@index"!==e).length,he.isSimpleGraph=e=>he.isGraph(e)&&!("@id"in e),he.isBlankNode=e=>{if(pe.isObject(e)){if("@id"in e){const t=e["@id"];return!pe.isString(t)||0===t.indexOf("_:")}return 0===Object.keys(e).length||!("@value"in e||"@set"in e||"@list"in e)}return!1};var ve=class extends Error{constructor(e="An unspecified JSON-LD error occurred.",t="jsonld.Error",n={}){super(e),this.name=t,this.message=e,this.details=n}};const ge=fe,ye=ue,me=ce.IdentifierIssuer,xe=ve,we=/(?:<[^>]*?>|"[^"]*?"|[^,])+/g,be=/\s*<([^>]*?)>\s*(?:;\s*(.*))?/,Ie=/(.*?)=(?:(?:"([^"]*?)")|([^"]*?))\s*(?:(?:;\s*)|$)/g,je={accept:"application/ld+json, application/json"},Se={};var ke=Se;function Ee(e,t){if(ye.isArray(t))for(let n=0;n<t.length;++n)t[n]=Ee(e,t[n]);else if(ge.isList(t))t["@list"]=Ee(e,t["@list"]);else if(ye.isObject(t)){ge.isBlankNode(t)&&(t["@id"]=e.getId(t["@id"]));const n=Object.keys(t).sort();for(let o=0;o<n.length;++o){const i=n[o];"@id"!==i&&(t[i]=Ee(e,t[i]))}}return t}Se.IdentifierIssuer=me,Se.REGEX_BCP47=/^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$/,Se.REGEX_KEYWORD=/^@[a-zA-Z]+$/,Se.clone=function(e){if(e&&"object"==typeof e){let t;if(ye.isArray(e)){t=[];for(let n=0;n<e.length;++n)t[n]=Se.clone(e[n])}else if(e instanceof Map){t=new Map;for(const[n,o]of e)t.set(n,Se.clone(o))}else if(e instanceof Set){t=new Set;for(const n of e)t.add(Se.clone(n))}else if(ye.isObject(e)){t={};for(const n in e)t[n]=Se.clone(e[n])}else t=e.toString();return t}return e},Se.asArray=function(e){return Array.isArray(e)?e:[e]},Se.buildHeaders=(e={})=>{if(Object.keys(e).some(e=>"accept"===e.toLowerCase()))throw new RangeError('Accept header may not be specified; only "'+je.accept+'" is supported.');return Object.assign({Accept:je.accept},e)},Se.parseLinkHeader=e=>{const t={},n=e.match(we);for(let e=0;e<n.length;++e){let o=n[e].match(be);if(!o)continue;const i={target:o[1]},r=o[2];for(;o=Ie.exec(r);)i[o[1]]=void 0===o[2]?o[3]:o[2];const a=i.rel||"";Array.isArray(t[a])?t[a].push(i):t.hasOwnProperty(a)?t[a]=[t[a],i]:t[a]=i}return t},Se.validateTypeValue=(e,t)=>{if(!(ye.isString(e)||ye.isArray(e)&&e.every(e=>ye.isString(e)))){if(t&&ye.isObject(e))switch(Object.keys(e).length){case 0:return;case 1:if("@default"in e&&Se.asArray(e["@default"]).every(e=>ye.isString(e)))return}throw new xe('Invalid JSON-LD syntax; "@type" value must a string, an array of strings, an empty object, or a default object.',"jsonld.SyntaxError",{code:"invalid type value",value:e})}},Se.hasProperty=(e,t)=>{if(e.hasOwnProperty(t)){const n=e[t];return!ye.isArray(n)||n.length>0}return!1},Se.hasValue=(e,t,n)=>{if(Se.hasProperty(e,t)){let o=e[t];const i=ge.isList(o);if(ye.isArray(o)||i){i&&(o=o["@list"]);for(let e=0;e<o.length;++e)if(Se.compareValues(n,o[e]))return!0}else if(!ye.isArray(n))return Se.compareValues(n,o)}return!1},Se.addValue=(e,t,n,o)=>{if("propertyIsArray"in(o=o||{})||(o.propertyIsArray=!1),"valueIsArray"in o||(o.valueIsArray=!1),"allowDuplicate"in o||(o.allowDuplicate=!0),"prependValue"in o||(o.prependValue=!1),o.valueIsArray)e[t]=n;else if(ye.isArray(n)){0===n.length&&o.propertyIsArray&&!e.hasOwnProperty(t)&&(e[t]=[]),o.prependValue&&(n=n.concat(e[t]),e[t]=[]);for(let i=0;i<n.length;++i)Se.addValue(e,t,n[i],o)}else if(e.hasOwnProperty(t)){const i=!o.allowDuplicate&&Se.hasValue(e,t,n);ye.isArray(e[t])||i&&!o.propertyIsArray||(e[t]=[e[t]]),i||(o.prependValue?e[t].unshift(n):e[t].push(n))}else e[t]=o.propertyIsArray?[n]:n},Se.getValues=(e,t)=>[].concat(e[t]||[]),Se.removeProperty=(e,t)=>{delete e[t]},Se.removeValue=(e,t,n,o)=>{"propertyIsArray"in(o=o||{})||(o.propertyIsArray=!1);const i=Se.getValues(e,t).filter(e=>!Se.compareValues(e,n));0===i.length?Se.removeProperty(e,t):1!==i.length||o.propertyIsArray?e[t]=i:e[t]=i[0]},Se.relabelBlankNodes=(e,t)=>Ee((t=t||{}).issuer||new me("_:b"),e),Se.compareValues=(e,t)=>e===t||(!(!ge.isValue(e)||!ge.isValue(t)||e["@value"]!==t["@value"]||e["@type"]!==t["@type"]||e["@language"]!==t["@language"]||e["@index"]!==t["@index"])||!!(ye.isObject(e)&&"@id"in e&&ye.isObject(t)&&"@id"in t)&&e["@id"]===t["@id"]),Se.compareShortestLeast=(e,t)=>e.length<t.length?-1:t.length<e.length?1:e===t?0:e<t?-1:1;const De="http://www.w3.org/1999/02/22-rdf-syntax-ns#",Oe="http://www.w3.org/2001/XMLSchema#";var Ne,Ce,Ae,Le,Re={LINK_HEADER_CONTEXT:"http://www.w3.org/ns/json-ld#context",RDF_LIST:De+"List",RDF_FIRST:De+"first",RDF_REST:De+"rest",RDF_NIL:De+"nil",RDF_TYPE:De+"type",RDF_JSON_LITERAL:De+"JSON",RDF_LANGSTRING:De+"langString",XSD_BOOLEAN:Oe+"boolean",XSD_DOUBLE:Oe+"double",XSD_INTEGER:Oe+"integer",XSD_STRING:Oe+"string"};function Te(){return Ce||(Ce=1,Ne=class{constructor(){this._requests={}}wrapLoader(e){const t=this;return t._loader=e,function(){return t.add.apply(t,arguments)}}async add(e){let t=this._requests[e];if(t)return Promise.resolve(t);t=this._requests[e]=this._loader(e);try{return await t}finally{delete this._requests[e]}}}),Ne}function _e(){if(Le)return Ae;Le=1;const e=ue,t={};Ae=t,t.parsers={simple:{keys:["href","scheme","authority","path","query","fragment"],regex:/^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/},full:{keys:["href","protocol","scheme","authority","auth","user","password","hostname","port","path","directory","file","query","fragment"],regex:/^(([a-zA-Z][a-zA-Z0-9+-.]*):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(?:(((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/}},t.parse=(e,n)=>{const o={},i=t.parsers[n||"full"],r=i.regex.exec(e);let a=i.keys.length;for(;a--;)o[i.keys[a]]=void 0===r[a]?null:r[a];return("https"===o.scheme&&"443"===o.port||"http"===o.scheme&&"80"===o.port)&&(o.href=o.href.replace(":"+o.port,""),o.authority=o.authority.replace(":"+o.port,""),o.port=null),o.normalizedPath=t.removeDotSegments(o.path),o},t.prependBase=(n,o)=>{if(null===n)return o;if(t.isAbsolute(o))return o;n&&!e.isString(n)||(n=t.parse(n||""));const i=t.parse(o),r={protocol:n.protocol||""};if(null!==i.authority)r.authority=i.authority,r.path=i.path,r.query=i.query;else if(r.authority=n.authority,""===i.path)r.path=n.path,null!==i.query?r.query=i.query:r.query=n.query;else{if(0===i.path.indexOf("/"))r.path=i.path;else{let e=n.path;e=e.substr(0,e.lastIndexOf("/")+1),(e.length>0||n.authority)&&"/"!==e.substr(-1)&&(e+="/"),e+=i.path,r.path=e}r.query=i.query}""!==i.path&&(r.path=t.removeDotSegments(r.path));let a=r.protocol;return null!==r.authority&&(a+="//"+r.authority),a+=r.path,null!==r.query&&(a+="?"+r.query),null!==i.fragment&&(a+="#"+i.fragment),""===a&&(a="./"),a},t.removeBase=(n,o)=>{if(null===n)return o;n&&!e.isString(n)||(n=t.parse(n||""));let i="";if(""!==n.href?i+=(n.protocol||"")+"//"+(n.authority||""):o.indexOf("//")&&(i+="//"),0!==o.indexOf(i))return o;const r=t.parse(o.substr(i.length)),a=n.normalizedPath.split("/"),s=r.normalizedPath.split("/"),l=r.fragment||r.query?0:1;for(;a.length>0&&s.length>l&&a[0]===s[0];)a.shift(),s.shift();let c="";if(a.length>0){a.pop();for(let e=0;e<a.length;++e)c+="../"}return c+=s.join("/"),null!==r.query&&(c+="?"+r.query),null!==r.fragment&&(c+="#"+r.fragment),""===c&&(c="./"),c},t.removeDotSegments=e=>{if(0===e.length)return"";const t=e.split("/"),n=[];for(;t.length>0;){const e=t.shift(),o=0===t.length;"."!==e?".."!==e?n.push(e):(n.pop(),o&&n.push("")):o&&n.push("")}return"/"===e[0]&&n.length>0&&""!==n[0]&&n.unshift(""),1===n.length&&""===n[0]?"/":n.join("/")};const n=/^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/;return t.isAbsolute=t=>e.isString(t)&&n.test(t),t.isRelative=t=>e.isString(t),Ae}const{parseLinkHeader:Pe,buildHeaders:Me}=ke,{LINK_HEADER_CONTEXT:He}=Re,Je=ve,Fe=Te(),{prependBase:Ue}=_e(),Be=/(^|(\r\n))link:/i;const qe=({secure:e,headers:t={},xhr:n}={headers:{}})=>{t=Me(t);return(new Fe).wrapLoader(async function o(i){if(0!==i.indexOf("http:")&&0!==i.indexOf("https:"))throw new Je('URL could not be dereferenced; only "http" and "https" URLs are supported.',"jsonld.InvalidUrl",{code:"loading document failed",url:i});if(e&&0!==i.indexOf("https"))throw new Je('URL could not be dereferenced; secure mode is enabled and the URL\'s scheme is not "https".',"jsonld.InvalidUrl",{code:"loading document failed",url:i});let r;try{r=await function(e,t,n){e=e||XMLHttpRequest;const o=new e;return new Promise((e,i)=>{o.onload=()=>e(o),o.onerror=e=>i(e),o.open("GET",t,!0);for(const e in n)o.setRequestHeader(e,n[e]);o.send()})}(n,i,t)}catch(e){throw new Je("URL could not be dereferenced, an error occurred.","jsonld.LoadDocumentError",{code:"loading document failed",url:i,cause:e})}if(r.status>=400)throw new Je("URL could not be dereferenced: "+r.statusText,"jsonld.LoadDocumentError",{code:"loading document failed",url:i,httpStatusCode:r.status});let a={contextUrl:null,documentUrl:i,document:r.response},s=null;const l=r.getResponseHeader("Content-Type");let c;Be.test(r.getAllResponseHeaders())&&(c=r.getResponseHeader("Link"));if(c&&"application/ld+json"!==l){const e=Pe(c),t=e[He];if(Array.isArray(t))throw new Je("URL could not be dereferenced, it has more than one associated HTTP Link Header.","jsonld.InvalidUrl",{code:"multiple context link headers",url:i});t&&(a.contextUrl=t.target),s=e.alternate,s&&"application/ld+json"==s.type&&!(l||"").match(/^application\/(\w*\+)?json$/)&&(a=await o(Ue(i,s.target)))}return a})},Ve={};var $e,Ge,ze=Ve;Ve.setupDocumentLoaders=function(e){"undefined"!=typeof XMLHttpRequest&&(e.documentLoaders.xhr=qe,e.useDocumentLoader("xhr"))},Ve.setupGlobals=function(e){void 0===globalThis.JsonLdProcessor&&Object.defineProperty(globalThis,"JsonLdProcessor",{writable:!0,enumerable:!1,configurable:!0,value:e.JsonLdProcessor})};var Ke=Qe;function Qe(e){var t=this;if(t instanceof Qe||(t=new Qe),t.tail=null,t.head=null,t.length=0,e&&"function"==typeof e.forEach)e.forEach(function(e){t.push(e)});else if(arguments.length>0)for(var n=0,o=arguments.length;n<o;n++)t.push(arguments[n]);return t}function We(e,t,n){var o=t===e.head?new Ye(n,null,t,e):new Ye(n,t,t.next,e);return null===o.next&&(e.tail=o),null===o.prev&&(e.head=o),e.length++,o}function Xe(e,t){e.tail=new Ye(t,e.tail,null,e),e.head||(e.head=e.tail),e.length++}function Ze(e,t){e.head=new Ye(t,null,e.head,e),e.tail||(e.tail=e.head),e.length++}function Ye(e,t,n,o){if(!(this instanceof Ye))return new Ye(e,t,n,o);this.list=o,this.value=e,t?(t.next=this,this.prev=t):this.prev=null,n?(n.prev=this,this.next=n):this.next=null}Qe.Node=Ye,Qe.create=Qe,Qe.prototype.removeNode=function(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");var t=e.next,n=e.prev;return t&&(t.prev=n),n&&(n.next=t),e===this.head&&(this.head=t),e===this.tail&&(this.tail=n),e.list.length--,e.next=null,e.prev=null,e.list=null,t},Qe.prototype.unshiftNode=function(e){if(e!==this.head){e.list&&e.list.removeNode(e);var t=this.head;e.list=this,e.next=t,t&&(t.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}},Qe.prototype.pushNode=function(e){if(e!==this.tail){e.list&&e.list.removeNode(e);var t=this.tail;e.list=this,e.prev=t,t&&(t.next=e),this.tail=e,this.head||(this.head=e),this.length++}},Qe.prototype.push=function(){for(var e=0,t=arguments.length;e<t;e++)Xe(this,arguments[e]);return this.length},Qe.prototype.unshift=function(){for(var e=0,t=arguments.length;e<t;e++)Ze(this,arguments[e]);return this.length},Qe.prototype.pop=function(){if(this.tail){var e=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,e}},Qe.prototype.shift=function(){if(this.head){var e=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,e}},Qe.prototype.forEach=function(e,t){t=t||this;for(var n=this.head,o=0;null!==n;o++)e.call(t,n.value,o,this),n=n.next},Qe.prototype.forEachReverse=function(e,t){t=t||this;for(var n=this.tail,o=this.length-1;null!==n;o--)e.call(t,n.value,o,this),n=n.prev},Qe.prototype.get=function(e){for(var t=0,n=this.head;null!==n&&t<e;t++)n=n.next;if(t===e&&null!==n)return n.value},Qe.prototype.getReverse=function(e){for(var t=0,n=this.tail;null!==n&&t<e;t++)n=n.prev;if(t===e&&null!==n)return n.value},Qe.prototype.map=function(e,t){t=t||this;for(var n=new Qe,o=this.head;null!==o;)n.push(e.call(t,o.value,this)),o=o.next;return n},Qe.prototype.mapReverse=function(e,t){t=t||this;for(var n=new Qe,o=this.tail;null!==o;)n.push(e.call(t,o.value,this)),o=o.prev;return n},Qe.prototype.reduce=function(e,t){var n,o=this.head;if(arguments.length>1)n=t;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");o=this.head.next,n=this.head.value}for(var i=0;null!==o;i++)n=e(n,o.value,i),o=o.next;return n},Qe.prototype.reduceReverse=function(e,t){var n,o=this.tail;if(arguments.length>1)n=t;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");o=this.tail.prev,n=this.tail.value}for(var i=this.length-1;null!==o;i--)n=e(n,o.value,i),o=o.prev;return n},Qe.prototype.toArray=function(){for(var e=new Array(this.length),t=0,n=this.head;null!==n;t++)e[t]=n.value,n=n.next;return e},Qe.prototype.toArrayReverse=function(){for(var e=new Array(this.length),t=0,n=this.tail;null!==n;t++)e[t]=n.value,n=n.prev;return e},Qe.prototype.slice=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new Qe;if(t<e||t<0)return n;e<0&&(e=0),t>this.length&&(t=this.length);for(var o=0,i=this.head;null!==i&&o<e;o++)i=i.next;for(;null!==i&&o<t;o++,i=i.next)n.push(i.value);return n},Qe.prototype.sliceReverse=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new Qe;if(t<e||t<0)return n;e<0&&(e=0),t>this.length&&(t=this.length);for(var o=this.length,i=this.tail;null!==i&&o>t;o--)i=i.prev;for(;null!==i&&o>e;o--,i=i.prev)n.push(i.value);return n},Qe.prototype.splice=function(e,t,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(var o=0,i=this.head;null!==i&&o<e;o++)i=i.next;var r=[];for(o=0;i&&o<t;o++)r.push(i.value),i=this.removeNode(i);null===i&&(i=this.tail),i!==this.head&&i!==this.tail&&(i=i.prev);for(o=0;o<n.length;o++)i=We(this,i,n[o]);return r},Qe.prototype.reverse=function(){for(var e=this.head,t=this.tail,n=e;null!==n;n=n.prev){var o=n.prev;n.prev=n.next,n.next=o}return this.head=t,this.tail=e,this};try{(Ge||(Ge=1,$e=function(e){e.prototype[Symbol.iterator]=function*(){for(let e=this.head;e;e=e.next)yield e.value}}),$e)(Qe)}catch(e){}const et=Ke,tt=Symbol("max"),nt=Symbol("length"),ot=Symbol("lengthCalculator"),it=Symbol("allowStale"),rt=Symbol("maxAge"),at=Symbol("dispose"),st=Symbol("noDisposeOnSet"),lt=Symbol("lruList"),ct=Symbol("cache"),dt=Symbol("updateAgeOnGet"),ut=()=>1;const pt=(e,t,n)=>{const o=e[ct].get(t);if(o){const t=o.value;if(ht(e,t)){if(vt(e,o),!e[it])return}else n&&(e[dt]&&(o.value.now=Date.now()),e[lt].unshiftNode(o));return t.value}},ht=(e,t)=>{if(!t||!t.maxAge&&!e[rt])return!1;const n=Date.now()-t.now;return t.maxAge?n>t.maxAge:e[rt]&&n>e[rt]},ft=e=>{if(e[nt]>e[tt])for(let t=e[lt].tail;e[nt]>e[tt]&&null!==t;){const n=t.prev;vt(e,t),t=n}},vt=(e,t)=>{if(t){const n=t.value;e[at]&&e[at](n.key,n.value),e[nt]-=n.length,e[ct].delete(n.key),e[lt].removeNode(t)}};class gt{constructor(e,t,n,o,i){this.key=e,this.value=t,this.length=n,this.now=o,this.maxAge=i||0}}const yt=(e,t,n,o)=>{let i=n.value;ht(e,i)&&(vt(e,n),e[it]||(i=void 0)),i&&t.call(o,i.value,i.key,e)};var mt=class{constructor(e){if("number"==typeof e&&(e={max:e}),e||(e={}),e.max&&("number"!=typeof e.max||e.max<0))throw new TypeError("max must be a non-negative number");this[tt]=e.max||1/0;const t=e.length||ut;if(this[ot]="function"!=typeof t?ut:t,this[it]=e.stale||!1,e.maxAge&&"number"!=typeof e.maxAge)throw new TypeError("maxAge must be a number");this[rt]=e.maxAge||0,this[at]=e.dispose,this[st]=e.noDisposeOnSet||!1,this[dt]=e.updateAgeOnGet||!1,this.reset()}set max(e){if("number"!=typeof e||e<0)throw new TypeError("max must be a non-negative number");this[tt]=e||1/0,ft(this)}get max(){return this[tt]}set allowStale(e){this[it]=!!e}get allowStale(){return this[it]}set maxAge(e){if("number"!=typeof e)throw new TypeError("maxAge must be a non-negative number");this[rt]=e,ft(this)}get maxAge(){return this[rt]}set lengthCalculator(e){"function"!=typeof e&&(e=ut),e!==this[ot]&&(this[ot]=e,this[nt]=0,this[lt].forEach(e=>{e.length=this[ot](e.value,e.key),this[nt]+=e.length})),ft(this)}get lengthCalculator(){return this[ot]}get length(){return this[nt]}get itemCount(){return this[lt].length}rforEach(e,t){t=t||this;for(let n=this[lt].tail;null!==n;){const o=n.prev;yt(this,e,n,t),n=o}}forEach(e,t){t=t||this;for(let n=this[lt].head;null!==n;){const o=n.next;yt(this,e,n,t),n=o}}keys(){return this[lt].toArray().map(e=>e.key)}values(){return this[lt].toArray().map(e=>e.value)}reset(){this[at]&&this[lt]&&this[lt].length&&this[lt].forEach(e=>this[at](e.key,e.value)),this[ct]=new Map,this[lt]=new et,this[nt]=0}dump(){return this[lt].map(e=>!ht(this,e)&&{k:e.key,v:e.value,e:e.now+(e.maxAge||0)}).toArray().filter(e=>e)}dumpLru(){return this[lt]}set(e,t,n){if((n=n||this[rt])&&"number"!=typeof n)throw new TypeError("maxAge must be a number");const o=n?Date.now():0,i=this[ot](t,e);if(this[ct].has(e)){if(i>this[tt])return vt(this,this[ct].get(e)),!1;const r=this[ct].get(e).value;return this[at]&&(this[st]||this[at](e,r.value)),r.now=o,r.maxAge=n,r.value=t,this[nt]+=i-r.length,r.length=i,this.get(e),ft(this),!0}const r=new gt(e,t,i,o,n);return r.length>this[tt]?(this[at]&&this[at](e,t),!1):(this[nt]+=r.length,this[lt].unshift(r),this[ct].set(e,this[lt].head),ft(this),!0)}has(e){if(!this[ct].has(e))return!1;const t=this[ct].get(e).value;return!ht(this,t)}get(e){return pt(this,e,!0)}peek(e){return pt(this,e,!1)}pop(){const e=this[lt].tail;return e?(vt(this,e),e.value):null}del(e){vt(this,this[ct].get(e))}load(e){this.reset();const t=Date.now();for(let n=e.length-1;n>=0;n--){const o=e[n],i=o.e||0;if(0===i)this.set(o.k,o.v);else{const e=i-t;e>0&&this.set(o.k,o.v,e)}}}prune(){this[ct].forEach((e,t)=>pt(this,t,!1))}};const xt=mt;const{isArray:wt,isObject:bt,isString:It}=ue,{asArray:jt}=ke,{prependBase:St}=_e(),kt=ve,Et=class{constructor({document:e}){this.document=e,this.cache=new xt({max:10})}getProcessed(e){return this.cache.get(e)}setProcessed(e,t){this.cache.set(e,t)}};function Dt(e){throw new kt("Invalid JSON-LD syntax; @context must be an object.","jsonld.SyntaxError",{code:"invalid local context",context:e})}function Ot({context:e,base:t}){if(!e)return;const n=e["@context"];if(It(n))e["@context"]=St(t,n);else if(wt(n))for(let e=0;e<n.length;++e){const o=n[e];It(o)?n[e]=St(t,o):bt(o)&&Ot({context:{"@context":o},base:t})}else if(bt(n))for(const e in n)Ot({context:n[e],base:t})}var Nt=ce.NQuads;const Ct=ve,{isArray:At}=ue,{asArray:Lt}=ke,Rt={};var Tt=Rt;function _t({event:e,handlers:t}){let n=!0;for(let o=0;n&&o<t.length;++o){n=!1;const i=t[o];if(At(i))n=_t({event:e,handlers:i});else if("function"==typeof i)i({event:e,next:()=>{n=!0}});else{if("object"!=typeof i)throw new Ct("Invalid event handler.","jsonld.InvalidEventHandler",{event:e});e.code in i?i[e.code]({event:e,next:()=>{n=!0}}):n=!0}}return n}Rt.defaultEventHandler=null,Rt.setupEventHandler=({options:e={}})=>{const t=[].concat(e.safe?Rt.safeEventHandler:[],e.eventHandler?Lt(e.eventHandler):[],Rt.defaultEventHandler?Rt.defaultEventHandler:[]);return 0===t.length?null:t},Rt.handleEvent=({event:e,options:t})=>{_t({event:e,handlers:t.eventHandler})};const Pt=new Set(["empty object","free-floating scalar","invalid @language value","invalid property","null @id value","null @value value","object with only @id","object with only @language","object with only @list","object with only @value","relative @id reference","relative @type reference","relative @vocab reference","reserved @id value","reserved @reverse value","reserved term","blank node predicate","relative graph reference","relative object reference","relative predicate reference","relative subject reference","rdfDirection not set"]);Rt.safeEventHandler=function({event:e,next:t}){if("warning"===e.level&&Pt.has(e.code))throw new Ct("Safe mode validation error.","jsonld.ValidationError",{event:e});t()},Rt.logEventHandler=function({event:e,next:t}){console.log(`EVENT: ${e.message}`,{event:e}),t()},Rt.logWarningEventHandler=function({event:e,next:t}){"warning"===e.level&&console.warn(`WARNING: ${e.message}`,{event:e}),t()},Rt.unhandledEventHandler=function({event:e}){throw new Ct("No handler for event.","jsonld.UnhandledEvent",{event:e})},Rt.setDefaultEventHandler=function({eventHandler:e}={}){Rt.defaultEventHandler=e?Lt(e):null};const Mt=ke,Ht=ve,{isArray:Jt,isObject:Ft,isString:Ut,isUndefined:Bt}=ue,{isAbsolute:qt,isRelative:Vt,prependBase:$t}=_e(),{handleEvent:Gt}=Tt,{REGEX_BCP47:zt,REGEX_KEYWORD:Kt,asArray:Qt,compareShortestLeast:Wt}=ke,Xt=new Map,Zt={};var Yt=Zt;function en(e,t,n,o,i,r){if(null===t||!Ut(t)||Zt.isKeyword(t))return t;if(t.match(Kt))return null;if(o&&o.hasOwnProperty(t)&&!0!==i.get(t)&&Zt.createTermDefinition({activeCtx:e,localCtx:o,term:t,defined:i,options:r}),(n=n||{}).vocab){const n=e.mappings.get(t);if(null===n)return null;if(Ft(n)&&"@id"in n)return n["@id"]}const a=t.indexOf(":");if(a>0){const n=t.substr(0,a),s=t.substr(a+1);if("_"===n||0===s.indexOf("//"))return t;o&&o.hasOwnProperty(n)&&Zt.createTermDefinition({activeCtx:e,localCtx:o,term:n,defined:i,options:r});const l=e.mappings.get(n);if(l&&l._prefix)return l["@id"]+s;if(qt(t))return t}if(n.vocab&&"@vocab"in e){t=e["@vocab"]+t}else if(n.base){let n,o;"@base"in e?e["@base"]?(o=$t(r.base,e["@base"]),n=$t(o,t)):(o=e["@base"],n=t):(o=r.base,n=$t(r.base,t)),t=n}return t}function tn(e,t){if(!e||"object"!=typeof e||!t||"object"!=typeof t)return e===t;const n=Array.isArray(e);if(n!==Array.isArray(t))return!1;if(n){if(e.length!==t.length)return!1;for(let n=0;n<e.length;++n)if(!tn(e[n],t[n]))return!1;return!0}const o=Object.keys(e),i=Object.keys(t);if(o.length!==i.length)return!1;for(const n in e){let o=e[n],i=t[n];if("@container"===n&&Array.isArray(o)&&Array.isArray(i)&&(o=o.slice().sort(),i=i.slice().sort()),!tn(o,i))return!1}return!0}Zt.process=async({activeCtx:e,localCtx:t,options:n,propagate:o=!0,overrideProtected:i=!1,cycles:r=new Set})=>{Ft(t)&&"@context"in t&&Jt(t["@context"])&&(t=t["@context"]);if(0===Qt(t).length)return e;const a=[],s=[({event:e,next:t})=>{a.push(e),t()}];n.eventHandler&&s.push(n.eventHandler);const l=n;n={...n,eventHandler:s};const c=await n.contextResolver.resolve({activeCtx:e,context:t,documentLoader:n.documentLoader,base:n.base});Ft(c[0].document)&&"boolean"==typeof c[0].document["@propagate"]&&(o=c[0].document["@propagate"]);let d=e;o||d.previousContext||(d=d.clone(),d.previousContext=e);for(const o of c){let{document:s}=o;if(e=d,null===s){if(!i&&0!==Object.keys(e.protected).length)throw new Ht("Tried to nullify a context with protected terms outside of a term definition.","jsonld.SyntaxError",{code:"invalid context nullification"});d=e=Zt.getInitialContext(n).clone();continue}const c=o.getProcessed(e);if(c){if(l.eventHandler)for(const e of c.events)Gt({event:e,options:l});d=e=c.context;continue}if(Ft(s)&&"@context"in s&&(s=s["@context"]),!Ft(s))throw new Ht("Invalid JSON-LD syntax; @context must be an object.","jsonld.SyntaxError",{code:"invalid local context",context:s});d=d.clone();const u=new Map;if("@version"in s){if(1.1!==s["@version"])throw new Ht("Unsupported JSON-LD version: "+s["@version"],"jsonld.UnsupportedVersion",{code:"invalid @version value",context:s});if(e.processingMode&&"json-ld-1.0"===e.processingMode)throw new Ht("@version: "+s["@version"]+" not compatible with "+e.processingMode,"jsonld.ProcessingModeConflict",{code:"processing mode conflict",context:s});d.processingMode="json-ld-1.1",d["@version"]=s["@version"],u.set("@version",!0)}if(d.processingMode=d.processingMode||e.processingMode,"@base"in s){let e=s["@base"];if(null===e||qt(e));else{if(!Vt(e))throw new Ht('Invalid JSON-LD syntax; the value of "@base" in a @context must be an absolute IRI, a relative IRI, or null.',"jsonld.SyntaxError",{code:"invalid base IRI",context:s});e=$t(d["@base"],e)}d["@base"]=e,u.set("@base",!0)}if("@vocab"in s){const e=s["@vocab"];if(null===e)delete d["@vocab"];else{if(!Ut(e))throw new Ht('Invalid JSON-LD syntax; the value of "@vocab" in a @context must be a string or null.',"jsonld.SyntaxError",{code:"invalid vocab mapping",context:s});if(!qt(e)&&Zt.processingMode(d,1))throw new Ht('Invalid JSON-LD syntax; the value of "@vocab" in a @context must be an absolute IRI.',"jsonld.SyntaxError",{code:"invalid vocab mapping",context:s});{const t=en(d,e,{vocab:!0,base:!0},void 0,void 0,n);qt(t)||n.eventHandler&&Gt({event:{type:["JsonLdEvent"],code:"relative @vocab reference",level:"warning",message:"Relative @vocab reference found.",details:{vocab:t}},options:n}),d["@vocab"]=t}}u.set("@vocab",!0)}if("@language"in s){const e=s["@language"];if(null===e)delete d["@language"];else{if(!Ut(e))throw new Ht('Invalid JSON-LD syntax; the value of "@language" in a @context must be a string or null.',"jsonld.SyntaxError",{code:"invalid default language",context:s});e.match(zt)||n.eventHandler&&Gt({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:e}},options:n}),d["@language"]=e.toLowerCase()}u.set("@language",!0)}if("@direction"in s){const t=s["@direction"];if("json-ld-1.0"===e.processingMode)throw new Ht("Invalid JSON-LD syntax; @direction not compatible with "+e.processingMode,"jsonld.SyntaxError",{code:"invalid context member",context:s});if(null===t)delete d["@direction"];else{if("ltr"!==t&&"rtl"!==t)throw new Ht('Invalid JSON-LD syntax; the value of "@direction" in a @context must be null, "ltr", or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",context:s});d["@direction"]=t}u.set("@direction",!0)}if("@propagate"in s){const n=s["@propagate"];if("json-ld-1.0"===e.processingMode)throw new Ht("Invalid JSON-LD syntax; @propagate not compatible with "+e.processingMode,"jsonld.SyntaxError",{code:"invalid context entry",context:s});if("boolean"!=typeof n)throw new Ht("Invalid JSON-LD syntax; @propagate value must be a boolean.","jsonld.SyntaxError",{code:"invalid @propagate value",context:t});u.set("@propagate",!0)}if("@import"in s){const o=s["@import"];if("json-ld-1.0"===e.processingMode)throw new Ht("Invalid JSON-LD syntax; @import not compatible with "+e.processingMode,"jsonld.SyntaxError",{code:"invalid context entry",context:s});if(!Ut(o))throw new Ht("Invalid JSON-LD syntax; @import must be a string.","jsonld.SyntaxError",{code:"invalid @import value",context:t});const i=await n.contextResolver.resolve({activeCtx:e,context:o,documentLoader:n.documentLoader,base:n.base});if(1!==i.length)throw new Ht("Invalid JSON-LD syntax; @import must reference a single context.","jsonld.SyntaxError",{code:"invalid remote context",context:t});const r=i[0].getProcessed(e);if(r)s=r;else{const n=i[0].document;if("@import"in n)throw new Ht("Invalid JSON-LD syntax: imported context must not include @import.","jsonld.SyntaxError",{code:"invalid context entry",context:t});for(const e in n)s.hasOwnProperty(e)||(s[e]=n[e]);i[0].setProcessed(e,s)}u.set("@import",!0)}u.set("@protected",s["@protected"]||!1);for(const e in s)if(Zt.createTermDefinition({activeCtx:d,localCtx:s,term:e,defined:u,options:n,overrideProtected:i}),Ft(s[e])&&"@context"in s[e]){const t=s[e]["@context"];let o=!0;if(Ut(t)){const e=$t(n.base,t);r.has(e)?o=!1:r.add(e)}if(o)try{await Zt.process({activeCtx:d.clone(),localCtx:s[e]["@context"],overrideProtected:!0,options:n,cycles:r})}catch(t){throw new Ht("Invalid JSON-LD syntax; invalid scoped context.","jsonld.SyntaxError",{code:"invalid scoped context",context:s[e]["@context"],term:e})}}o.setProcessed(e,{context:d,events:a})}return d},Zt.createTermDefinition=({activeCtx:e,localCtx:t,term:n,defined:o,options:i,overrideProtected:r=!1})=>{if(o.has(n)){if(o.get(n))return;throw new Ht("Cyclical context definition detected.","jsonld.CyclicalContext",{code:"cyclic IRI mapping",context:t,term:n})}let a;if(o.set(n,!1),t.hasOwnProperty(n)&&(a=t[n]),"@type"===n&&Ft(a)&&"@set"===(a["@container"]||"@set")&&Zt.processingMode(e,1.1)){const e=["@container","@id","@protected"],o=Object.keys(a);if(0===o.length||o.some(t=>!e.includes(t)))throw new Ht("Invalid JSON-LD syntax; keywords cannot be overridden.","jsonld.SyntaxError",{code:"keyword redefinition",context:t,term:n})}else{if(Zt.isKeyword(n))throw new Ht("Invalid JSON-LD syntax; keywords cannot be overridden.","jsonld.SyntaxError",{code:"keyword redefinition",context:t,term:n});if(n.match(Kt))return void(i.eventHandler&&Gt({event:{type:["JsonLdEvent"],code:"reserved term",level:"warning",message:'Terms beginning with "@" are reserved for future use and dropped.',details:{term:n}},options:i}));if(""===n)throw new Ht("Invalid JSON-LD syntax; a term cannot be an empty string.","jsonld.SyntaxError",{code:"invalid term definition",context:t})}const s=e.mappings.get(n);e.mappings.has(n)&&e.mappings.delete(n);let l=!1;if((Ut(a)||null===a)&&(l=!0,a={"@id":a}),!Ft(a))throw new Ht("Invalid JSON-LD syntax; @context term values must be strings or objects.","jsonld.SyntaxError",{code:"invalid term definition",context:t});const c={};e.mappings.set(n,c),c.reverse=!1;const d=["@container","@id","@language","@reverse","@type"];Zt.processingMode(e,1.1)&&d.push("@context","@direction","@index","@nest","@prefix","@protected");for(const e in a)if(!d.includes(e))throw new Ht("Invalid JSON-LD syntax; a term definition must not contain "+e,"jsonld.SyntaxError",{code:"invalid term definition",context:t});const u=n.indexOf(":");if(c._termHasColon=u>0,"@reverse"in a){if("@id"in a)throw new Ht("Invalid JSON-LD syntax; a @reverse term definition must not contain @id.","jsonld.SyntaxError",{code:"invalid reverse property",context:t});if("@nest"in a)throw new Ht("Invalid JSON-LD syntax; a @reverse term definition must not contain @nest.","jsonld.SyntaxError",{code:"invalid reverse property",context:t});const r=a["@reverse"];if(!Ut(r))throw new Ht("Invalid JSON-LD syntax; a @context @reverse value must be a string.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:t});if(r.match(Kt))return i.eventHandler&&Gt({event:{type:["JsonLdEvent"],code:"reserved @reverse value",level:"warning",message:'@reverse values beginning with "@" are reserved for future use and dropped.',details:{reverse:r}},options:i}),void(s?e.mappings.set(n,s):e.mappings.delete(n));const l=en(e,r,{vocab:!0,base:!1},t,o,i);if(!qt(l))throw new Ht("Invalid JSON-LD syntax; a @context @reverse value must be an absolute IRI or a blank node identifier.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:t});c["@id"]=l,c.reverse=!0}else if("@id"in a){let r=a["@id"];if(r&&!Ut(r))throw new Ht("Invalid JSON-LD syntax; a @context @id value must be an array of strings or a string.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:t});if(null===r)c["@id"]=null;else{if(!Zt.isKeyword(r)&&r.match(Kt))return i.eventHandler&&Gt({event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:'@id values beginning with "@" are reserved for future use and dropped.',details:{id:r}},options:i}),void(s?e.mappings.set(n,s):e.mappings.delete(n));if(r!==n){if(r=en(e,r,{vocab:!0,base:!1},t,o,i),!qt(r)&&!Zt.isKeyword(r))throw new Ht("Invalid JSON-LD syntax; a @context @id value must be an absolute IRI, a blank node identifier, or a keyword.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:t});if(n.match(/(?::[^:])|\//)){if(en(e,n,{vocab:!0,base:!1},t,new Map(o).set(n,!0),i)!==r)throw new Ht("Invalid JSON-LD syntax; term in form of IRI must expand to definition.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:t})}c["@id"]=r,c._prefix=l&&!c._termHasColon&&null!==r.match(/[:\/\?#\[\]@]$/)}}}if(!("@id"in c))if(c._termHasColon){const r=n.substr(0,u);if(t.hasOwnProperty(r)&&Zt.createTermDefinition({activeCtx:e,localCtx:t,term:r,defined:o,options:i}),e.mappings.has(r)){const t=n.substr(u+1);c["@id"]=e.mappings.get(r)["@id"]+t}else c["@id"]=n}else if("@type"===n)c["@id"]=n;else{if(!("@vocab"in e))throw new Ht("Invalid JSON-LD syntax; @context terms must define an @id.","jsonld.SyntaxError",{code:"invalid IRI mapping",context:t,term:n});c["@id"]=e["@vocab"]+n}if((!0===a["@protected"]||!0===o.get("@protected")&&!1!==a["@protected"])&&(e.protected[n]=!0,c.protected=!0),o.set(n,!0),"@type"in a){let n=a["@type"];if(!Ut(n))throw new Ht("Invalid JSON-LD syntax; an @context @type value must be a string.","jsonld.SyntaxError",{code:"invalid type mapping",context:t});if("@json"===n||"@none"===n){if(Zt.processingMode(e,1))throw new Ht(`Invalid JSON-LD syntax; an @context @type value must not be "${n}" in JSON-LD 1.0 mode.`,"jsonld.SyntaxError",{code:"invalid type mapping",context:t})}else if("@id"!==n&&"@vocab"!==n){if(n=en(e,n,{vocab:!0,base:!1},t,o,i),!qt(n))throw new Ht("Invalid JSON-LD syntax; an @context @type value must be an absolute IRI.","jsonld.SyntaxError",{code:"invalid type mapping",context:t});if(0===n.indexOf("_:"))throw new Ht("Invalid JSON-LD syntax; an @context @type value must be an IRI, not a blank node identifier.","jsonld.SyntaxError",{code:"invalid type mapping",context:t})}c["@type"]=n}if("@container"in a){const n=Ut(a["@container"])?[a["@container"]]:a["@container"]||[],o=["@list","@set","@index","@language"];let i=!0;const r=n.includes("@set");if(Zt.processingMode(e,1.1)){if(o.push("@graph","@id","@type"),n.includes("@list")){if(1!==n.length)throw new Ht("Invalid JSON-LD syntax; @context @container with @list must have no other values","jsonld.SyntaxError",{code:"invalid container mapping",context:t})}else if(n.includes("@graph")){if(n.some(e=>"@graph"!==e&&"@id"!==e&&"@index"!==e&&"@set"!==e))throw new Ht("Invalid JSON-LD syntax; @context @container with @graph must have no other values other than @id, @index, and @set","jsonld.SyntaxError",{code:"invalid container mapping",context:t})}else i&=n.length<=(r?2:1);if(n.includes("@type")&&(c["@type"]=c["@type"]||"@id",!["@id","@vocab"].includes(c["@type"])))throw new Ht("Invalid JSON-LD syntax; container: @type requires @type to be @id or @vocab.","jsonld.SyntaxError",{code:"invalid type mapping",context:t})}else i&=!Jt(a["@container"]),i&=n.length<=1;if(i&=n.every(e=>o.includes(e)),i&=!(r&&n.includes("@list")),!i)throw new Ht("Invalid JSON-LD syntax; @context @container value must be one of the following: "+o.join(", "),"jsonld.SyntaxError",{code:"invalid container mapping",context:t});if(c.reverse&&!n.every(e=>["@index","@set"].includes(e)))throw new Ht("Invalid JSON-LD syntax; @context @container value for a @reverse type definition must be @index or @set.","jsonld.SyntaxError",{code:"invalid reverse property",context:t});c["@container"]=n}if("@index"in a){if(!("@container"in a)||!c["@container"].includes("@index"))throw new Ht(`Invalid JSON-LD syntax; @index without @index in @container: "${a["@index"]}" on term "${n}".`,"jsonld.SyntaxError",{code:"invalid term definition",context:t});if(!Ut(a["@index"])||0===a["@index"].indexOf("@"))throw new Ht(`Invalid JSON-LD syntax; @index must expand to an IRI: "${a["@index"]}" on term "${n}".`,"jsonld.SyntaxError",{code:"invalid term definition",context:t});c["@index"]=a["@index"]}if("@context"in a&&(c["@context"]=a["@context"]),"@language"in a&&!("@type"in a)){let e=a["@language"];if(null!==e&&!Ut(e))throw new Ht("Invalid JSON-LD syntax; @context @language value must be a string or null.","jsonld.SyntaxError",{code:"invalid language mapping",context:t});null!==e&&(e=e.toLowerCase()),c["@language"]=e}if("@prefix"in a){if(n.match(/:|\//))throw new Ht("Invalid JSON-LD syntax; @context @prefix used on a compact IRI term","jsonld.SyntaxError",{code:"invalid term definition",context:t});if(Zt.isKeyword(c["@id"]))throw new Ht("Invalid JSON-LD syntax; keywords may not be used as prefixes","jsonld.SyntaxError",{code:"invalid term definition",context:t});if("boolean"!=typeof a["@prefix"])throw new Ht("Invalid JSON-LD syntax; @context value for @prefix must be boolean","jsonld.SyntaxError",{code:"invalid @prefix value",context:t});c._prefix=!0===a["@prefix"]}if("@direction"in a){const e=a["@direction"];if(null!==e&&"ltr"!==e&&"rtl"!==e)throw new Ht('Invalid JSON-LD syntax; @direction value must be null, "ltr", or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",context:t});c["@direction"]=e}if("@nest"in a){const e=a["@nest"];if(!Ut(e)||"@nest"!==e&&0===e.indexOf("@"))throw new Ht("Invalid JSON-LD syntax; @context @nest value must be a string which is not a keyword other than @nest.","jsonld.SyntaxError",{code:"invalid @nest value",context:t});c["@nest"]=e}
|
|
23
|
+
// disallow aliasing @context and @preserve
|
|
24
|
+
const p=c["@id"];if("@context"===p||"@preserve"===p)throw new Ht("Invalid JSON-LD syntax; @context and @preserve cannot be aliased.","jsonld.SyntaxError",{code:"invalid keyword alias",context:t});if(s&&s.protected&&!r&&(e.protected[n]=!0,c.protected=!0,!tn(s,c)))throw new Ht("Invalid JSON-LD syntax; tried to redefine a protected term.","jsonld.SyntaxError",{code:"protected term redefinition",context:t,term:n})},Zt.expandIri=(e,t,n,o)=>en(e,t,n,void 0,void 0,o),Zt.getInitialContext=e=>{const t=JSON.stringify({processingMode:e.processingMode}),n=Xt.get(t);if(n)return n;const o={processingMode:e.processingMode,mappings:new Map,inverse:null,getInverse:function(){const e=this;if(e.inverse)return e.inverse;const t=e.inverse={},n=e.fastCurieMap={},o={},a=(e["@language"]||"@none").toLowerCase(),s=e["@direction"],l=e.mappings,c=[...l.keys()].sort(Wt);for(const e of c){const i=l.get(e);if(null===i)continue;let c=i["@container"]||"@none";if(c=[].concat(c).sort().join(""),null===i["@id"])continue;const d=Qt(i["@id"]);for(const l of d){let d=t[l];const u=Zt.isKeyword(l);if(d)u||i._termHasColon||o[l].push(e);else if(t[l]=d={},!u&&!i._termHasColon){o[l]=[e];const t={iri:l,terms:o[l]};l[0]in n?n[l[0]].push(t):n[l[0]]=[t]}if(d[c]||(d[c]={"@language":{},"@type":{},"@any":{}}),d=d[c],r(e,d["@any"],"@none"),i.reverse)r(e,d["@type"],"@reverse");else if("@none"===i["@type"])r(e,d["@any"],"@none"),r(e,d["@language"],"@none"),r(e,d["@type"],"@none");else if("@type"in i)r(e,d["@type"],i["@type"]);else if("@language"in i&&"@direction"in i){const t=i["@language"],n=i["@direction"];r(e,d["@language"],t&&n?`${t}_${n}`.toLowerCase():t?t.toLowerCase():n?`_${n}`:"@null")}else"@language"in i?r(e,d["@language"],(i["@language"]||"@null").toLowerCase()):"@direction"in i?i["@direction"]?r(e,d["@language"],`_${i["@direction"]}`):r(e,d["@language"],"@none"):s?(r(e,d["@language"],`_${s}`),r(e,d["@language"],"@none"),r(e,d["@type"],"@none")):(r(e,d["@language"],a),r(e,d["@language"],"@none"),r(e,d["@type"],"@none"))}}for(const e in n)i(n,e,1);return t},clone:function(){const e={};e.mappings=Mt.clone(this.mappings),e.clone=this.clone,e.inverse=null,e.getInverse=this.getInverse,e.protected=Mt.clone(this.protected),this.previousContext&&(e.previousContext=this.previousContext.clone());e.revertToPreviousContext=this.revertToPreviousContext,"@base"in this&&(e["@base"]=this["@base"]);"@language"in this&&(e["@language"]=this["@language"]);"@vocab"in this&&(e["@vocab"]=this["@vocab"]);return e},revertToPreviousContext:function(){if(!this.previousContext)return this;return this.previousContext.clone()},protected:{}};return 1e4===Xt.size&&Xt.clear(),Xt.set(t,o),o;function i(e,t,n){const o=e[t],r=e[t]={};let a,s;for(const e of o)a=e.iri,s=n>=a.length?"":a[n],s in r?r[s].push(e):r[s]=[e];for(const e in r)""!==e&&i(r,e,n+1)}function r(e,t,n){t.hasOwnProperty(n)||(t[n]=e)}},Zt.getContextValue=(e,t,n)=>{if(null===t){if("@context"===n)return;return null}if(e.mappings.has(t)){const o=e.mappings.get(t);if(Bt(n))return o;if(o.hasOwnProperty(n))return o[n]}return"@language"===n&&n in e||"@direction"===n&&n in e?e[n]:"@context"!==n?null:void 0},Zt.processingMode=(e,t)=>t.toString()>="1.1"?!e.processingMode||e.processingMode>="json-ld-"+t.toString():"json-ld-1.0"===e.processingMode,Zt.isKeyword=e=>{if(!Ut(e)||"@"!==e[0])return!1;switch(e){case"@base":case"@container":case"@context":case"@default":case"@direction":case"@embed":case"@explicit":case"@graph":case"@id":case"@included":case"@index":case"@json":case"@language":case"@list":case"@nest":case"@none":case"@omitDefault":case"@prefix":case"@preserve":case"@protected":case"@requireAll":case"@reverse":case"@set":case"@type":case"@value":case"@version":case"@vocab":return!0}return!1};const nn=ve,{isArray:on,isObject:rn,isEmptyObject:an,isString:sn,isUndefined:ln}=ue,{isList:cn,isValue:dn,isGraph:un,isSubject:pn}=fe,{expandIri:hn,getContextValue:fn,isKeyword:vn,process:gn,processingMode:yn}=Yt,{isAbsolute:mn}=_e(),{REGEX_BCP47:xn,REGEX_KEYWORD:wn,addValue:bn,asArray:In,getValues:jn,validateTypeValue:Sn}=ke,{handleEvent:kn}=Tt,En={};var Dn=En;function On({value:e,count:t,options:n}){if(0===t||"@value"in e||"@list"in e||1===t&&"@id"in e){if(n.eventHandler){let o,i;0===t?(o="empty object",i="Dropping empty object."):"@value"in e?(o="object with only @value",i="Dropping object with only @value."):"@list"in e?(o="object with only @list",i="Dropping object with only @list."):1===t&&"@id"in e&&(o="object with only @id",i="Dropping object with only @id."),kn({event:{type:["JsonLdEvent"],code:o,level:"warning",message:i,details:{value:e}},options:n})}return null}return e}async function Nn({activeCtx:e,activeProperty:t,expandedActiveProperty:n,element:o,expandedParent:i,options:r={},insideList:a,typeKey:s,typeScopedContext:l}){const c=Object.keys(o).sort(),d=[];let u;const p=o[s]&&"@json"===hn(e,on(o[s])?o[s][0]:o[s],{vocab:!0},{...r,typeExpansion:!0});for(const a of c){let s,c=o[a];if("@context"===a)continue;const h=hn(e,a,{vocab:!0},r);if(null===h||!mn(h)&&!vn(h)){r.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"invalid property",level:"warning",message:"Dropping property that did not expand into an absolute IRI or keyword.",details:{property:a,expandedProperty:h}},options:r});continue}if(vn(h)){if("@reverse"===n)throw new nn("Invalid JSON-LD syntax; a keyword cannot be used as a @reverse property.","jsonld.SyntaxError",{code:"invalid reverse property map",value:c});if(h in i&&"@included"!==h&&"@type"!==h)throw new nn("Invalid JSON-LD syntax; colliding keywords detected.","jsonld.SyntaxError",{code:"colliding keywords",keyword:h})}if("@id"===h){if(!sn(c)){if(!r.isFrame)throw new nn('Invalid JSON-LD syntax; "@id" value must a string.',"jsonld.SyntaxError",{code:"invalid @id value",value:c});if(rn(c)){if(!an(c))throw new nn('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:c})}else{if(!on(c))throw new nn('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:c});if(!c.every(e=>sn(e)))throw new nn('Invalid JSON-LD syntax; "@id" value an empty object or array of strings, if framing',"jsonld.SyntaxError",{code:"invalid @id value",value:c})}}bn(i,"@id",In(c).map(t=>{if(sn(t)){const n=hn(e,t,{base:!0},r);return r.eventHandler&&(null===n?kn(null===t?{event:{type:["JsonLdEvent"],code:"null @id value",level:"warning",message:"Null @id found.",details:{id:t}},options:r}:{event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:"Reserved @id found.",details:{id:t}},options:r}):mn(n)||kn({event:{type:["JsonLdEvent"],code:"relative @id reference",level:"warning",message:"Relative @id reference found.",details:{id:t,expandedId:n}},options:r})),n}return t}),{propertyIsArray:r.isFrame});continue}if("@type"===h){rn(c)&&(c=Object.fromEntries(Object.entries(c).map(([e,t])=>[hn(l,e,{vocab:!0}),In(t).map(e=>hn(l,e,{base:!0,vocab:!0},{...r,typeExpansion:!0}))]))),Sn(c,r.isFrame),bn(i,"@type",In(c).map(e=>{if(sn(e)){const t=hn(l,e,{base:!0,vocab:!0},{...r,typeExpansion:!0});return"@json"===t||mn(t)||r.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"relative @type reference",level:"warning",message:"Relative @type reference found.",details:{type:e}},options:r}),t}return e}),{propertyIsArray:!!r.isFrame});continue}if("@included"===h&&yn(e,1.1)){const n=In(await En.expand({activeCtx:e,activeProperty:t,element:c,options:r}));if(!n.every(e=>pn(e)))throw new nn("Invalid JSON-LD syntax; values of @included must expand to node objects.","jsonld.SyntaxError",{code:"invalid @included value",value:c});bn(i,"@included",n,{propertyIsArray:!0});continue}if("@graph"===h&&!rn(c)&&!on(c))throw new nn('Invalid JSON-LD syntax; "@graph" value must not be an object or an array.',"jsonld.SyntaxError",{code:"invalid @graph value",value:c});if("@value"===h){u=c,p&&yn(e,1.1)?i["@value"]=c:bn(i,"@value",c,{propertyIsArray:r.isFrame});continue}if("@language"===h){if(null===c)continue;if(!sn(c)&&!r.isFrame)throw new nn('Invalid JSON-LD syntax; "@language" value must be a string.',"jsonld.SyntaxError",{code:"invalid language-tagged string",value:c});c=In(c).map(e=>sn(e)?e.toLowerCase():e);for(const e of c)sn(e)&&!e.match(xn)&&r.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:e}},options:r});bn(i,"@language",c,{propertyIsArray:r.isFrame});continue}if("@direction"===h){if(!sn(c)&&!r.isFrame)throw new nn('Invalid JSON-LD syntax; "@direction" value must be a string.',"jsonld.SyntaxError",{code:"invalid base direction",value:c});c=In(c);for(const e of c)if(sn(e)&&"ltr"!==e&&"rtl"!==e)throw new nn('Invalid JSON-LD syntax; "@direction" must be "ltr" or "rtl".',"jsonld.SyntaxError",{code:"invalid base direction",value:c});bn(i,"@direction",c,{propertyIsArray:r.isFrame});continue}if("@index"===h){if(!sn(c))throw new nn('Invalid JSON-LD syntax; "@index" value must be a string.',"jsonld.SyntaxError",{code:"invalid @index value",value:c});bn(i,"@index",c);continue}if("@reverse"===h){if(!rn(c))throw new nn('Invalid JSON-LD syntax; "@reverse" value must be an object.',"jsonld.SyntaxError",{code:"invalid @reverse value",value:c});if(s=await En.expand({activeCtx:e,activeProperty:"@reverse",element:c,options:r}),"@reverse"in s)for(const e in s["@reverse"])bn(i,e,s["@reverse"][e],{propertyIsArray:!0});let t=i["@reverse"]||null;for(const e in s){if("@reverse"===e)continue;null===t&&(t=i["@reverse"]={}),bn(t,e,[],{propertyIsArray:!0});const n=s[e];for(let o=0;o<n.length;++o){const i=n[o];if(dn(i)||cn(i))throw new nn('Invalid JSON-LD syntax; "@reverse" value must not be a @value or an @list.',"jsonld.SyntaxError",{code:"invalid reverse property value",value:s});bn(t,e,i,{propertyIsArray:!0})}}continue}if("@nest"===h){d.push(a);continue}let f=e;const v=fn(e,a,"@context");ln(v)||(f=await gn({activeCtx:e,localCtx:v,propagate:!0,overrideProtected:!0,options:r}));const g=fn(e,a,"@container")||[];if(g.includes("@language")&&rn(c)){s=An(f,c,fn(f,a,"@direction"),r)}else if(g.includes("@index")&&rn(c)){const t=g.includes("@graph"),n=fn(f,a,"@index")||"@index",o="@index"!==n&&hn(e,n,{vocab:!0},r);s=await Ln({activeCtx:f,options:r,activeProperty:a,value:c,asGraph:t,indexKey:n,propertyIndex:o})}else if(g.includes("@id")&&rn(c)){const e=g.includes("@graph");s=await Ln({activeCtx:f,options:r,activeProperty:a,value:c,asGraph:e,indexKey:"@id"})}else if(g.includes("@type")&&rn(c))s=await Ln({activeCtx:f.revertToPreviousContext(),options:r,activeProperty:a,value:c,asGraph:!1,indexKey:"@type"});else{const o="@list"===h;if(o||"@set"===h){let e=t;o&&"@graph"===n&&(e=null),s=await En.expand({activeCtx:f,activeProperty:e,element:c,options:r,insideList:o})}else s="@json"===fn(e,a,"@type")?{"@type":"@json","@value":c}:await En.expand({activeCtx:f,activeProperty:a,element:c,options:r,insideList:!1})}if(null!==s||"@value"===h){if("@list"!==h&&!cn(s)&&g.includes("@list")&&(s={"@list":In(s)}),g.includes("@graph")&&!g.some(e=>"@id"===e||"@index"===e)){if(s=In(s),r.isFrame||(s=s.filter(e=>null!==On({value:e,count:Object.keys(e).length,options:r}))),0===s.length)continue;s=s.map(e=>({"@graph":In(e)}))}if(f.mappings.has(a)&&f.mappings.get(a).reverse){const e=i["@reverse"]=i["@reverse"]||{};s=In(s);for(let t=0;t<s.length;++t){const n=s[t];if(dn(n)||cn(n))throw new nn('Invalid JSON-LD syntax; "@reverse" value must not be a @value or an @list.',"jsonld.SyntaxError",{code:"invalid reverse property value",value:s});bn(e,h,n,{propertyIsArray:!0})}continue}bn(i,h,s,{propertyIsArray:!0})}}if("@value"in i)if("@json"===i["@type"]&&yn(e,1.1));else if((rn(u)||on(u))&&!r.isFrame)throw new nn('Invalid JSON-LD syntax; "@value" value must not be an object or an array.',"jsonld.SyntaxError",{code:"invalid value object value",value:u});for(const c of d){const d=on(o[c])?o[c]:[o[c]];for(const o of d){if(!rn(o)||Object.keys(o).some(t=>"@value"===hn(e,t,{vocab:!0},r)))throw new nn("Invalid JSON-LD syntax; nested value must be a node object.","jsonld.SyntaxError",{code:"invalid @nest value",value:o});await Nn({activeCtx:e,activeProperty:t,expandedActiveProperty:n,element:o,expandedParent:i,options:r,insideList:a,typeScopedContext:l,typeKey:s})}}}function Cn({activeCtx:e,activeProperty:t,value:n,options:o}){if(null==n)return null;const i=hn(e,t,{vocab:!0},o);if("@id"===i)return hn(e,n,{base:!0},o);if("@type"===i)return hn(e,n,{vocab:!0,base:!0},{...o,typeExpansion:!0});const r=fn(e,t,"@type");if(("@id"===r||"@graph"===i)&&sn(n)){const i=hn(e,n,{base:!0},o);return null===i&&n.match(wn)&&o.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"reserved @id value",level:"warning",message:"Reserved @id found.",details:{id:t}},options:o}),{"@id":i}}if("@vocab"===r&&sn(n))return{"@id":hn(e,n,{vocab:!0,base:!0},o)};if(vn(i))return n;const a={};if(r&&!["@id","@vocab","@none"].includes(r))a["@type"]=r;else if(sn(n)){const n=fn(e,t,"@language");null!==n&&(a["@language"]=n);const o=fn(e,t,"@direction");null!==o&&(a["@direction"]=o)}return["boolean","number","string"].includes(typeof n)||(n=n.toString()),a["@value"]=n,a}function An(e,t,n,o){const i=[],r=Object.keys(t).sort();for(const a of r){const r=hn(e,a,{vocab:!0},o);let s=t[a];on(s)||(s=[s]);for(const e of s){if(null===e)continue;if(!sn(e))throw new nn("Invalid JSON-LD syntax; language map values must be strings.","jsonld.SyntaxError",{code:"invalid language map value",languageMap:t});const s={"@value":e};"@none"!==r&&(a.match(xn)||o.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:a}},options:o}),s["@language"]=a.toLowerCase()),n&&(s["@direction"]=n),i.push(s)}}return i}async function Ln({activeCtx:e,options:t,activeProperty:n,value:o,asGraph:i,indexKey:r,propertyIndex:a}){const s=[],l=Object.keys(o).sort(),c="@type"===r;for(let d of l){if(c){const n=fn(e,d,"@context");ln(n)||(e=await gn({activeCtx:e,localCtx:n,propagate:!1,options:t}))}let l,u=o[d];on(u)||(u=[u]),u=await En.expand({activeCtx:e,activeProperty:n,element:u,options:t,insideList:!1,insideIndex:!0}),l=a?"@none"===d?"@none":Cn({activeCtx:e,activeProperty:r,value:d,options:t}):hn(e,d,{vocab:!0},t),"@id"===r?d=hn(e,d,{base:!0},t):c&&(d=l);for(let e of u){if(i&&!un(e)&&(e={"@graph":[e]}),"@type"===r)"@none"===l||(e["@type"]?e["@type"]=[d].concat(e["@type"]):e["@type"]=[d]);else{if(dn(e)&&!["@language","@type","@index"].includes(r))throw new nn(`Invalid JSON-LD syntax; Attempt to add illegal key to value object: "${r}".`,"jsonld.SyntaxError",{code:"invalid value object",value:e});a?"@none"!==l&&bn(e,a,l,{propertyIsArray:!0,prependValue:!0}):"@none"===l||r in e||(e[r]=d)}s.push(e)}}return s}En.expand=async({activeCtx:e,activeProperty:t=null,element:n,options:o={},insideList:i=!1,insideIndex:r=!1,typeScopedContext:a=null})=>{if(null==n)return null;if("@default"===t&&(o=Object.assign({},o,{isFrame:!1})),!on(n)&&!rn(n))return i||null!==t&&"@graph"!==hn(e,t,{vocab:!0},o)?Cn({activeCtx:e,activeProperty:t,value:n,options:o}):(o.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"free-floating scalar",level:"warning",message:"Dropping free-floating scalar not in a list.",details:{value:n}},options:o}),null);if(on(n)){let s=[];const l=fn(e,t,"@container")||[];i=i||l.includes("@list");for(let l=0;l<n.length;++l){let c=await En.expand({activeCtx:e,activeProperty:t,element:n[l],options:o,insideIndex:r,typeScopedContext:a});i&&on(c)&&(c={"@list":c}),null!==c&&(on(c)?s=s.concat(c):s.push(c))}return s}const s=hn(e,t,{vocab:!0},o),l=fn(e,t,"@context");a=a||(e.previousContext?e:null);let c=Object.keys(n).sort(),d=!r;if(d&&a&&c.length<=2&&!c.includes("@context"))for(const t of c){const n=hn(a,t,{vocab:!0},o);if("@value"===n){d=!1,e=a;break}if("@id"===n&&1===c.length){d=!1;break}}d&&(e=e.revertToPreviousContext()),ln(l)||(e=await gn({activeCtx:e,localCtx:l,propagate:!0,overrideProtected:!0,options:o})),"@context"in n&&(e=await gn({activeCtx:e,localCtx:n["@context"],options:o})),a=e;let u=null;for(const t of c){if("@type"===hn(e,t,{vocab:!0},o)){u=u||t;const i=n[t],r=Array.isArray(i)?i.length>1?i.slice().sort():i:[i];for(const t of r){const n=fn(a,t,"@context");ln(n)||(e=await gn({activeCtx:e,localCtx:n,options:o,propagate:!1}))}}}let p={};await Nn({activeCtx:e,activeProperty:t,expandedActiveProperty:s,element:n,expandedParent:p,options:o,insideList:i,typeKey:u,typeScopedContext:a}),c=Object.keys(p);let h=c.length;if("@value"in p){if("@type"in p&&("@language"in p||"@direction"in p))throw new nn('Invalid JSON-LD syntax; an element containing "@value" may not contain both "@type" and either "@language" or "@direction".',"jsonld.SyntaxError",{code:"invalid value object",element:p});let t=h-1;if("@type"in p&&(t-=1),"@index"in p&&(t-=1),"@language"in p&&(t-=1),"@direction"in p&&(t-=1),0!==t)throw new nn('Invalid JSON-LD syntax; an element containing "@value" may only have an "@index" property and either "@type" or either or both "@language" or "@direction".',"jsonld.SyntaxError",{code:"invalid value object",element:p});const n=null===p["@value"]?[]:In(p["@value"]),i=jn(p,"@type");if(yn(e,1.1)&&i.includes("@json")&&1===i.length);else if(0===n.length)o.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"null @value value",level:"warning",message:"Dropping null @value value.",details:{value:p}},options:o}),p=null;else{if(!n.every(e=>sn(e)||an(e))&&"@language"in p)throw new nn("Invalid JSON-LD syntax; only strings may be language-tagged.","jsonld.SyntaxError",{code:"invalid language-tagged value",element:p});if(!i.every(e=>mn(e)&&!(sn(e)&&0===e.indexOf("_:"))||an(e)))throw new nn('Invalid JSON-LD syntax; an element containing "@value" and "@type" must have an absolute IRI for the value of "@type".',"jsonld.SyntaxError",{code:"invalid typed value",element:p})}}else if("@type"in p&&!on(p["@type"]))p["@type"]=[p["@type"]];else if("@set"in p||"@list"in p){if(h>1&&(2!==h||!("@index"in p)))throw new nn('Invalid JSON-LD syntax; if an element has the property "@set" or "@list", then it can have at most one other property that is "@index".',"jsonld.SyntaxError",{code:"invalid set or list object",element:p});"@set"in p&&(p=p["@set"],c=Object.keys(p),h=c.length)}else 1===h&&"@language"in p&&(o.eventHandler&&kn({event:{type:["JsonLdEvent"],code:"object with only @language",level:"warning",message:"Dropping object with only @language.",details:{value:p}},options:o}),p=null);return!rn(p)||o.keepFreeFloatingNodes||i||null!==t&&"@graph"!==s&&!(fn(e,t,"@container")||[]).includes("@graph")||(p=On({value:p,count:h,options:o})),p};const{isKeyword:Rn}=Yt,Tn=fe,_n=ue,Pn=ke,Mn=ve,Hn={};var Jn=Hn;Hn.createMergedNodeMap=(e,t)=>{const n=(t=t||{}).issuer||new Pn.IdentifierIssuer("_:b"),o={"@default":{}};return Hn.createNodeMap(e,o,"@default",n),Hn.mergeNodeMaps(o)},Hn.createNodeMap=(e,t,n,o,i,r)=>{if(_n.isArray(e)){for(const i of e)Hn.createNodeMap(i,t,n,o,void 0,r);return}if(!_n.isObject(e))return void(r&&r.push(e));if(Tn.isValue(e)){if("@type"in e){let t=e["@type"];0===t.indexOf("_:")&&(e["@type"]=t=o.getId(t))}return void(r&&r.push(e))}if(r&&Tn.isList(e)){const a=[];return Hn.createNodeMap(e["@list"],t,n,o,i,a),void r.push({"@list":a})}if("@type"in e){const t=e["@type"];for(const e of t)0===e.indexOf("_:")&&o.getId(e)}_n.isUndefined(i)&&(i=Tn.isBlankNode(e)?o.getId(e["@id"]):e["@id"]),r&&r.push({"@id":i});const a=t[n],s=a[i]=a[i]||{};s["@id"]=i;const l=Object.keys(e).sort();for(let r of l){if("@id"===r)continue;if("@reverse"===r){const r={"@id":i},s=e["@reverse"];for(const e in s){const i=s[e];for(const s of i){let i=s["@id"];Tn.isBlankNode(s)&&(i=o.getId(i)),Hn.createNodeMap(s,t,n,o,i),Pn.addValue(a[i],e,r,{propertyIsArray:!0,allowDuplicate:!1})}}continue}if("@graph"===r){i in t||(t[i]={}),Hn.createNodeMap(e[r],t,i,o);continue}if("@included"===r){Hn.createNodeMap(e[r],t,n,o);continue}if("@type"!==r&&Rn(r)){if("@index"===r&&r in s&&(e[r]!==s[r]||e[r]["@id"]!==s[r]["@id"]))throw new Mn("Invalid JSON-LD syntax; conflicting @index property detected.","jsonld.SyntaxError",{code:"conflicting indexes",subject:s});s[r]=e[r];continue}const l=e[r];if(0===r.indexOf("_:")&&(r=o.getId(r)),0!==l.length)for(let e of l)if("@type"===r&&(e=0===e.indexOf("_:")?o.getId(e):e),Tn.isSubject(e)||Tn.isSubjectReference(e)){if("@id"in e&&!e["@id"])continue;const i=Tn.isBlankNode(e)?o.getId(e["@id"]):e["@id"];Pn.addValue(s,r,{"@id":i},{propertyIsArray:!0,allowDuplicate:!1}),Hn.createNodeMap(e,t,n,o,i)}else if(Tn.isValue(e))Pn.addValue(s,r,e,{propertyIsArray:!0,allowDuplicate:!1});else if(Tn.isList(e)){const a=[];Hn.createNodeMap(e["@list"],t,n,o,i,a),e={"@list":a},Pn.addValue(s,r,e,{propertyIsArray:!0,allowDuplicate:!1})}else Hn.createNodeMap(e,t,n,o,i),Pn.addValue(s,r,e,{propertyIsArray:!0,allowDuplicate:!1});else Pn.addValue(s,r,[],{propertyIsArray:!0})}},Hn.mergeNodeMapGraphs=e=>{const t={};for(const n of Object.keys(e).sort())for(const o of Object.keys(e[n]).sort()){const i=e[n][o];o in t||(t[o]={"@id":o});const r=t[o];for(const e of Object.keys(i).sort())if(Rn(e)&&"@type"!==e)r[e]=Pn.clone(i[e]);else for(const t of i[e])Pn.addValue(r,e,Pn.clone(t),{propertyIsArray:!0,allowDuplicate:!1})}return t},Hn.mergeNodeMaps=e=>{const t=e["@default"],n=Object.keys(e).sort();for(const o of n){if("@default"===o)continue;const n=e[o];let i=t[o];i?"@graph"in i||(i["@graph"]=[]):t[o]=i={"@id":o,"@graph":[]};const r=i["@graph"];for(const e of Object.keys(n).sort()){const t=n[e];Tn.isSubjectReference(t)||r.push(t)}}return t};const{isSubjectReference:Fn}=fe,{createMergedNodeMap:Un}=Jn,Bn={};var qn=Bn;Bn.flatten=e=>{const t=Un(e),n=[],o=Object.keys(t).sort();for(let e=0;e<o.length;++e){const i=t[o[e]];Fn(i)||n.push(i)}return n};const Vn=ve,$n=fe,Gn=ue,{REGEX_BCP47:zn,addValue:Kn}=ke,{handleEvent:Qn}=Tt,{RDF_LIST:Wn,RDF_FIRST:Xn,RDF_REST:Zn,RDF_NIL:Yn,RDF_TYPE:eo,RDF_JSON_LITERAL:to,XSD_BOOLEAN:no,XSD_DOUBLE:oo,XSD_INTEGER:io,XSD_STRING:ro}=Re,ao={};var so=ao;function lo(e,t,n,o){const i=co(e);if(i)return{"@id":i};const r={"@value":e.value};if(e.language)e.language.match(zn)||o.eventHandler&&Qn({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:e.language}},options:o}),r["@language"]=e.language;else{let i=e.datatype.value;if(i||(i=ro),i===to){i="@json";try{r["@value"]=JSON.parse(r["@value"])}catch(e){throw new Vn("JSON literal could not be parsed.","jsonld.InvalidJsonLiteral",{code:"invalid JSON literal",value:r["@value"],cause:e})}}if(t)if(i===no)"true"===r["@value"]||"1"===r["@value"]?r["@value"]=!0:"false"===r["@value"]||"0"===r["@value"]?r["@value"]=!1:r["@type"]=i;else if(i===io)if(Gn.isNumeric(r["@value"])){const e=parseInt(r["@value"],10);e.toFixed(0)===r["@value"]&&(r["@value"]=e)}else r["@type"]=i;else i===oo&&Gn.isNumeric(r["@value"])?r["@value"]=parseFloat(r["@value"]):r["@type"]=i;else if("i18n-datatype"===n&&i.startsWith("https://www.w3.org/ns/i18n#")){const[,e,t]=i.split(/[#_]/);e.length>0&&(r["@language"]=e,e.match(zn)||o.eventHandler&&Qn({event:{type:["JsonLdEvent"],code:"invalid @language value",level:"warning",message:"@language value must be valid BCP47.",details:{language:e}},options:o})),r["@direction"]=t}else i!==ro&&(r["@type"]=i)}return r}function co(e){return"NamedNode"===e.termType?e.value:"BlankNode"===e.termType?"_:"+e.value:null}ao.fromRDF=async(e,t)=>{const{useRdfType:n=!1,useNativeTypes:o=!1,rdfDirection:i=null}=t,r={},a={"@default":r},s={};if(i){if("compound-literal"===i)throw new Vn("Unsupported rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});if("i18n-datatype"!==i)throw new Vn("Unknown rdfDirection value.","jsonld.InvalidRdfDirection",{value:i})}for(const l of e){const e="DefaultGraph"===l.graph.termType?"@default":l.graph.value;e in a||(a[e]={}),"@default"===e||e in r||(r[e]={"@id":e});const c=a[e],d=co(l.subject),u=l.predicate.value,p=l.object;d in c||(c[d]={"@id":d});const h=c[d],f=co(p),v=!!f;if(v&&!(f in c)&&(c[f]={"@id":f}),u===eo&&!n&&v){Kn(h,"@type",f,{propertyIsArray:!0});continue}const g=lo(p,o,i,t);if(Kn(h,u,g,{propertyIsArray:!0}),v)if(f===Yn){const e=c[f];"usages"in e||(e.usages=[]),e.usages.push({node:h,property:u,value:g})}else s[f]=!(f in s)&&{node:h,property:u,value:g}}for(const e in a){const t=a[e];if(!(Yn in t))continue;const n=t[Yn];if(n.usages){for(let e of n.usages){let n=e.node,o=e.property,i=e.value;const r=[],a=[];let l=Object.keys(n).length;for(;o===Zn&&Gn.isObject(s[n["@id"]])&&Gn.isArray(n[Xn])&&1===n[Xn].length&&Gn.isArray(n[Zn])&&1===n[Zn].length&&(3===l||4===l&&Gn.isArray(n["@type"])&&1===n["@type"].length&&n["@type"][0]===Wn)&&(r.push(n[Xn][0]),a.push(n["@id"]),e=s[n["@id"]],n=e.node,o=e.property,i=e.value,l=Object.keys(n).length,$n.isBlankNode(n)););delete i["@id"],i["@list"]=r.reverse();for(const e of a)delete t[e]}delete n.usages}}const l=[],c=Object.keys(r).sort();for(const e of c){const t=r[e];if(e in a){const n=t["@graph"]=[],o=a[e],i=Object.keys(o).sort();for(const e of i){const t=o[e];$n.isSubjectReference(t)||n.push(t)}}$n.isSubjectReference(t)||l.push(t)}return l};const{createNodeMap:uo}=Jn,{isKeyword:po}=Yt,ho=fe,fo=function e(t){if("number"==typeof t&&isNaN(t))throw new Error("NaN is not allowed");if("number"==typeof t&&!isFinite(t))throw new Error("Infinity is not allowed");if(null===t||"object"!=typeof t)return JSON.stringify(t);if(t.toJSON instanceof Function)return e(t.toJSON());if(Array.isArray(t)){return`[${t.reduce((t,n,o)=>`${t}${0===o?"":","}${e(void 0===n||"symbol"==typeof n?null:n)}`,"")}]`}return`{${Object.keys(t).sort().reduce((n,o)=>{if(void 0===t[o]||"symbol"==typeof t[o])return n;return`${n}${0===n.length?"":","}${e(o)}:${e(t[o])}`},"")}}`},vo=ve,go=ue,yo=ke,{handleEvent:mo}=Tt,{RDF_FIRST:xo,RDF_REST:wo,RDF_NIL:bo,RDF_TYPE:Io,RDF_JSON_LITERAL:jo,RDF_LANGSTRING:So,XSD_BOOLEAN:ko,XSD_DOUBLE:Eo,XSD_INTEGER:Do,XSD_STRING:Oo}=Re,{isAbsolute:No}=_e(),Co={};var Ao=Co;function Lo(e,t,n,o,i){const r=Object.keys(t).sort();for(const a of r){const r=t[a],s=Object.keys(r).sort();for(let t of s){const s=r[t];if("@type"===t)t=Io;else if(po(t))continue;for(const r of s){const s=To(a);if(!No(a)){i.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"relative subject reference",level:"warning",message:"Relative subject reference found.",details:{subject:a}},options:i});continue}const l=To(t);if(!No(t)){i.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"relative predicate reference",level:"warning",message:"Relative predicate reference found.",details:{predicate:t}},options:i});continue}if("BlankNode"===l.termType&&!i.produceGeneralizedRdf){i.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"blank node predicate",level:"warning",message:"Dropping blank node predicate.",details:{property:o.getOldIds().find(e=>o.getId(e)===t)}},options:i});continue}const c=Ro(r,o,e,n,i.rdfDirection,i);c&&e.push({subject:s,predicate:l,object:c,graph:n})}}}}function Ro(e,t,n,o,i,r){let a;if(ho.isValue(e)){a={termType:"Literal",value:void 0,datatype:{termType:"NamedNode"}};let t=e["@value"];const n=e["@type"]||null;if("@json"===n)a.value=fo(t),a.datatype.value=jo;else if(go.isBoolean(t))a.value=t.toString(),a.datatype.value=n||ko;else if(go.isDouble(t)||n===Eo)go.isDouble(t)||(t=parseFloat(t)),a.value=t.toExponential(15).replace(/(\d)0*e\+?/,"$1E"),a.datatype.value=n||Eo;else if(go.isNumber(t))a.value=t.toFixed(0),a.datatype.value=n||Do;else if("@direction"in e&&"i18n-datatype"===i){const n=`https://www.w3.org/ns/i18n#${(e["@language"]||"").toLowerCase()}_${e["@direction"]}`;a.datatype.value=n,a.value=t}else{if("@direction"in e&&"compound-literal"===i)throw new vo("Unsupported rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});if("@direction"in e&&i)throw new vo("Unknown rdfDirection value.","jsonld.InvalidRdfDirection",{value:i});"@language"in e?("@direction"in e&&!i&&r.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"rdfDirection not set",level:"warning",message:"rdfDirection not set for @direction.",details:{object:a.value}},options:r}),a.value=t,a.datatype.value=n||So,a.language=e["@language"]):("@direction"in e&&!i&&r.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"rdfDirection not set",level:"warning",message:"rdfDirection not set for @direction.",details:{object:a.value}},options:r}),a.value=t,a.datatype.value=n||Oo)}}else if(ho.isList(e)){const s=function(e,t,n,o,i,r){const a={termType:"NamedNode",value:xo},s={termType:"NamedNode",value:wo},l={termType:"NamedNode",value:bo},c=e.pop(),d=c?{termType:"BlankNode",value:t.getId().slice(2)}:l;let u=d;for(const l of e){const e=Ro(l,t,n,o,i,r),c={termType:"BlankNode",value:t.getId().slice(2)};n.push({subject:u,predicate:a,object:e,graph:o}),n.push({subject:u,predicate:s,object:c,graph:o}),u=c}if(c){const e=Ro(c,t,n,o,i,r);n.push({subject:u,predicate:a,object:e,graph:o}),n.push({subject:u,predicate:s,object:l,graph:o})}return d}(e["@list"],t,n,o,i,r);a={termType:s.termType,value:s.value}}else{a=To(go.isObject(e)?e["@id"]:e)}return"NamedNode"!==a.termType||No(a.value)?a:(r.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"relative object reference",level:"warning",message:"Relative object reference found.",details:{object:a.value}},options:r}),null)}function To(e){return e.startsWith("_:")?{termType:"BlankNode",value:e.slice(2)}:{termType:"NamedNode",value:e}}Co.toRDF=(e,t)=>{const n=new yo.IdentifierIssuer("_:b"),o={"@default":{}};uo(e,o,"@default",n);const i=[],r=Object.keys(o).sort();for(const e of r){let r;if("@default"===e)r={termType:"DefaultGraph",value:""};else{if(!No(e)){t.eventHandler&&mo({event:{type:["JsonLdEvent"],code:"relative graph reference",level:"warning",message:"Relative graph reference found.",details:{graph:e}},options:t});continue}r=To(e)}Lo(i,o[e],r,n,t)}return i};const{isKeyword:_o}=Yt,Po=fe,Mo=ue,Ho=ke,Jo=_e(),Fo=ve,{createNodeMap:Uo,mergeNodeMapGraphs:Bo}=Jn,qo={};var Vo=qo;function $o(e){const t={};for(const n in e)void 0!==e[n]&&(t["@"+n]=[e[n]]);return[t]}function Go(e,t,n){for(let o=n.length-1;o>=0;--o){const i=n[o];if(i.graph===t&&i.subject["@id"]===e["@id"])return!0}return!1}function zo(e,t,n){const o="@"+n;let i=o in e?e[o][0]:t[n];if("embed"===n)if(!0===i)i="@once";else if(!1===i)i="@never";else if("@always"!==i&&"@never"!==i&&"@link"!==i&&"@first"!==i&&"@last"!==i&&"@once"!==i)throw new Fo("Invalid JSON-LD syntax; invalid value of @embed.","jsonld.SyntaxError",{code:"invalid @embed value",frame:e});return i}function Ko(e){if(!Mo.isArray(e)||1!==e.length||!Mo.isObject(e[0]))throw new Fo("Invalid JSON-LD syntax; a JSON-LD frame must be a single object.","jsonld.SyntaxError",{frame:e});if("@id"in e[0])for(const t of Ho.asArray(e[0]["@id"]))if(!Mo.isObject(t)&&!Jo.isAbsolute(t)||Mo.isString(t)&&0===t.indexOf("_:"))throw new Fo("Invalid JSON-LD syntax; invalid @id in frame.","jsonld.SyntaxError",{code:"invalid frame",frame:e});if("@type"in e[0])for(const t of Ho.asArray(e[0]["@type"]))if(!Mo.isObject(t)&&!Jo.isAbsolute(t)&&"@json"!==t||Mo.isString(t)&&0===t.indexOf("_:"))throw new Fo("Invalid JSON-LD syntax; invalid @type in frame.","jsonld.SyntaxError",{code:"invalid frame",frame:e})}function Qo(e,t,n,o){let i=!0,r=!1;for(const a in n){let s=!1;const l=Ho.getValues(t,a),c=0===Ho.getValues(n,a).length;if("@id"===a){if(Mo.isEmptyObject(n["@id"][0]||{})?s=!0:n["@id"].length>=0&&(s=n["@id"].includes(l[0])),!o.requireAll)return s}else if("@type"===a){if(i=!1,c){if(l.length>0)return!1;s=!0}else if(1===n["@type"].length&&Mo.isEmptyObject(n["@type"][0]))s=l.length>0;else for(const e of n["@type"])s=!(!Mo.isObject(e)||!("@default"in e))||(s||l.some(t=>t===e));if(!o.requireAll)return s}else{if(_o(a))continue;{const t=Ho.getValues(n,a)[0];let r=!1;if(t&&(Ko([t]),r="@default"in t),i=!1,0===l.length&&r)continue;if(l.length>0&&c)return!1;if(void 0===t){if(l.length>0)return!1;s=!0}else if(Po.isList(t)){const n=t["@list"][0];if(Po.isList(l[0])){const t=l[0]["@list"];Po.isValue(n)?s=t.some(e=>ei(n,e)):(Po.isSubject(n)||Po.isSubjectReference(n))&&(s=t.some(t=>Yo(e,n,t,o)))}}else s=Po.isValue(t)?l.some(e=>ei(t,e)):Po.isSubjectReference(t)?l.some(n=>Yo(e,t,n,o)):!!Mo.isObject(t)&&l.length>0}}if(!s&&o.requireAll)return!1;r=r||s}return i||r}function Wo(e,t){const n=e.uniqueEmbeds[e.graph],o=n[t],i=o.parent,r=o.property,a={"@id":t};if(Mo.isArray(i)){for(let e=0;e<i.length;++e)if(Ho.compareValues(i[e],a)){i[e]=a;break}}else{const e=Mo.isArray(i[r]);Ho.removeValue(i,r,a,{propertyIsArray:e}),Ho.addValue(i,r,a,{propertyIsArray:e})}const s=e=>{const t=Object.keys(n);for(const o of t)o in n&&Mo.isObject(n[o].parent)&&n[o].parent["@id"]===e&&(delete n[o],s(o))};s(t)}
|
|
25
|
+
/**
|
|
26
|
+
* Removes the @preserve keywords from expanded result of framing.
|
|
27
|
+
*
|
|
28
|
+
* @param input the framed, framed output.
|
|
29
|
+
* @param options the framing options used.
|
|
30
|
+
*
|
|
31
|
+
* @return the resulting output.
|
|
32
|
+
*/function Xo(e,t){if(Mo.isArray(e))return e.map(e=>Xo(e,t));if(Mo.isObject(e)){
|
|
33
|
+
// remove @preserve
|
|
34
|
+
if("@preserve"in e)return e["@preserve"][0];if(Po.isValue(e))return e;if(Po.isList(e))return e["@list"]=Xo(e["@list"],t),e;if("@id"in e){const n=e["@id"];if(t.link.hasOwnProperty(n)){const o=t.link[n].indexOf(e);if(-1!==o)return t.link[n][o];t.link[n].push(e)}else t.link[n]=[e]}for(const n in e)"@id"===n&&t.bnodesToClear.includes(e[n])?delete e["@id"]:e[n]=Xo(e[n],t)}return e}function Zo(e,t,n){Mo.isObject(e)?Ho.addValue(e,t,n,{propertyIsArray:!0}):e.push(n)}function Yo(e,t,n,o){if(!("@id"in n))return!1;const i=e.subjects[n["@id"]];return i&&Qo(e,i,t,o)}function ei(e,t){const n=t["@value"],o=t["@type"],i=t["@language"],r=e["@value"]?Mo.isArray(e["@value"])?e["@value"]:[e["@value"]]:[],a=e["@type"]?Mo.isArray(e["@type"])?e["@type"]:[e["@type"]]:[],s=e["@language"]?Mo.isArray(e["@language"])?e["@language"]:[e["@language"]]:[];return 0===r.length&&0===a.length&&0===s.length||!(!r.includes(n)&&!Mo.isEmptyObject(r[0]))&&(!!(!o&&0===a.length||a.includes(o)||o&&Mo.isEmptyObject(a[0]))&&!!(!i&&0===s.length||s.includes(i)||i&&Mo.isEmptyObject(s[0])))}qo.frameMergedOrDefault=(e,t,n)=>{const o={options:n,embedded:!1,graph:"@default",graphMap:{"@default":{}},subjectStack:[],link:{},bnodeMap:{}},i=new Ho.IdentifierIssuer("_:b");Uo(e,o.graphMap,"@default",i),n.merged&&(o.graphMap["@merged"]=Bo(o.graphMap),o.graph="@merged"),o.subjects=o.graphMap[o.graph];const r=[];return qo.frame(o,Object.keys(o.subjects).sort(),t,r),n.pruneBlankNodeIdentifiers&&(n.bnodesToClear=Object.keys(o.bnodeMap).filter(e=>1===o.bnodeMap[e].length)),
|
|
35
|
+
// remove @preserve from results
|
|
36
|
+
n.link={},Xo(r,n)},qo.frame=(e,t,n,o,i=null)=>{Ko(n),n=n[0];const r=e.options,a={embed:zo(n,r,"embed"),explicit:zo(n,r,"explicit"),requireAll:zo(n,r,"requireAll")};e.link.hasOwnProperty(e.graph)||(e.link[e.graph]={});const s=e.link[e.graph],l=function(e,t,n,o){const i={};for(const r of t){const t=e.graphMap[e.graph][r];Qo(e,t,n,o)&&(i[r]=t)}return i}(e,t,n,a),c=Object.keys(l).sort();for(const d of c){const c=l[d];if(null===i?e.uniqueEmbeds={[e.graph]:{}}:e.uniqueEmbeds[e.graph]=e.uniqueEmbeds[e.graph]||{},"@link"===a.embed&&d in s){Zo(o,i,s[d]);continue}const u={"@id":d};if(0===d.indexOf("_:")&&Ho.addValue(e.bnodeMap,d,u,{propertyIsArray:!0}),s[d]=u,("@first"===a.embed||"@last"===a.embed)&&e.is11)throw new Fo("Invalid JSON-LD syntax; invalid value of @embed.","jsonld.SyntaxError",{code:"invalid @embed value",frame:n});if(e.embedded||!e.uniqueEmbeds[e.graph].hasOwnProperty(d))if(!e.embedded||"@never"!==a.embed&&!Go(c,e.graph,e.subjectStack))if(!e.embedded||"@first"!=a.embed&&"@once"!=a.embed||!e.uniqueEmbeds[e.graph].hasOwnProperty(d)){if("@last"===a.embed&&d in e.uniqueEmbeds[e.graph]&&Wo(e,d),e.uniqueEmbeds[e.graph][d]={parent:o,property:i},e.subjectStack.push({subject:c,graph:e.graph}),d in e.graphMap){let t=!1,o=null;"@graph"in n?(o=n["@graph"][0],t=!("@merged"===d||"@default"===d),Mo.isObject(o)||(o={})):(t="@merged"!==e.graph,o={}),t&&qo.frame({...e,graph:d,embedded:!1},Object.keys(e.graphMap[d]).sort(),[o],u,"@graph")}"@included"in n&&qo.frame({...e,embedded:!1},t,n["@included"],u,"@included");for(const t of Object.keys(c).sort())if(_o(t)){if(u[t]=Ho.clone(c[t]),"@type"===t)for(const t of c["@type"])0===t.indexOf("_:")&&Ho.addValue(e.bnodeMap,t,u,{propertyIsArray:!0})}else if(!a.explicit||t in n)for(const o of c[t]){const i=t in n?n[t]:$o(a);if(Po.isList(o)){const i=n[t]&&n[t][0]&&n[t][0]["@list"]?n[t][0]["@list"]:$o(a),r={"@list":[]};Zo(u,t,r);const s=o["@list"];for(const t of s)Po.isSubjectReference(t)?qo.frame({...e,embedded:!0},[t["@id"]],i,r,"@list"):Zo(r,"@list",Ho.clone(t))}else Po.isSubjectReference(o)?qo.frame({...e,embedded:!0},[o["@id"]],i,u,t):ei(i[0],o)&&Zo(u,t,Ho.clone(o))}for(const e of Object.keys(n).sort()){if("@type"===e){if(!Mo.isObject(n[e][0])||!("@default"in n[e][0]))continue}else if(_o(e))continue;const t=n[e][0]||{};if(!zo(t,r,"omitDefault")&&!(e in u)){let n="@null";"@default"in t&&(n=Ho.clone(t["@default"])),Mo.isArray(n)||(n=[n]),u[e]=[{"@preserve":n}]}}for(const t of Object.keys(n["@reverse"]||{}).sort()){const o=n["@reverse"][t];for(const n of Object.keys(e.subjects)){Ho.getValues(e.subjects[n],t).some(e=>e["@id"]===d)&&(u["@reverse"]=u["@reverse"]||{},Ho.addValue(u["@reverse"],t,[],{propertyIsArray:!0}),qo.frame({...e,embedded:!0},[n],o,u["@reverse"][t],i))}}Zo(o,i,u),e.subjectStack.pop()}else Zo(o,i,u);else Zo(o,i,u)}},qo.cleanupNull=(e,t)=>{if(Mo.isArray(e)){return e.map(e=>qo.cleanupNull(e,t)).filter(e=>e)}if("@null"===e)return null;if(Mo.isObject(e)){if("@id"in e){const n=e["@id"];if(t.link.hasOwnProperty(n)){const o=t.link[n].indexOf(e);if(-1!==o)return t.link[n][o];t.link[n].push(e)}else t.link[n]=[e]}for(const n in e)e[n]=qo.cleanupNull(e[n],t)}return e};const ti=ve,{isArray:ni,isObject:oi,isString:ii,isUndefined:ri}=ue,{isList:ai,isValue:si,isGraph:li,isSimpleGraph:ci,isSubjectReference:di}=fe,{expandIri:ui,getContextValue:pi,isKeyword:hi,process:fi,processingMode:vi}=Yt,{removeBase:gi,prependBase:yi}=_e(),{REGEX_KEYWORD:mi,addValue:xi,asArray:wi,compareShortestLeast:bi}=ke,Ii={};var ji,Si,ki=Ii;function Ei(e,t,n){if("@nest"!==ui(e,t,{vocab:!0},n))throw new ti("JSON-LD compact error; nested property must have an @nest value resolving to @nest.","jsonld.SyntaxError",{code:"invalid @nest value"})}Ii.compact=async({activeCtx:e,activeProperty:t=null,element:n,options:o={}})=>{if(ni(n)){let i=[];for(let r=0;r<n.length;++r){const a=await Ii.compact({activeCtx:e,activeProperty:t,element:n[r],options:o});null!==a&&i.push(a)}if(o.compactArrays&&1===i.length){0===(pi(e,t,"@container")||[]).length&&(i=i[0])}return i}const i=pi(e,t,"@context");if(ri(i)||(e=await fi({activeCtx:e,localCtx:i,propagate:!0,overrideProtected:!0,options:o})),oi(n)){if(o.link&&"@id"in n&&o.link.hasOwnProperty(n["@id"])){const e=o.link[n["@id"]];for(let t=0;t<e.length;++t)if(e[t].expanded===n)return e[t].compacted}if(si(n)||di(n)){const i=Ii.compactValue({activeCtx:e,activeProperty:t,value:n,options:o});return o.link&&di(n)&&(o.link.hasOwnProperty(n["@id"])||(o.link[n["@id"]]=[]),o.link[n["@id"]].push({expanded:n,compacted:i})),i}if(ai(n)){if((pi(e,t,"@container")||[]).includes("@list"))return Ii.compact({activeCtx:e,activeProperty:t,element:n["@list"],options:o})}const i="@reverse"===t,r={},a=e;si(n)||di(n)||(e=e.revertToPreviousContext());const s=pi(a,t,"@context");ri(s)||(e=await fi({activeCtx:e,localCtx:s,propagate:!0,overrideProtected:!0,options:o})),o.link&&"@id"in n&&(o.link.hasOwnProperty(n["@id"])||(o.link[n["@id"]]=[]),o.link[n["@id"]].push({expanded:n,compacted:r}));let l=n["@type"]||[];l.length>1&&(l=Array.from(l).sort());const c=e;for(const t of l){const n=Ii.compactIri({activeCtx:c,iri:t,relativeTo:{vocab:!0}}),i=pi(a,n,"@context");ri(i)||(e=await fi({activeCtx:e,localCtx:i,options:o,propagate:!1}))}const d=Object.keys(n).sort();for(const s of d){const l=n[s];if("@id"===s){let t=wi(l).map(t=>Ii.compactIri({activeCtx:e,iri:t,relativeTo:{vocab:!1},base:o.base}));1===t.length&&(t=t[0]);r[Ii.compactIri({activeCtx:e,iri:"@id",relativeTo:{vocab:!0}})]=t;continue}if("@type"===s){let t=wi(l).map(e=>Ii.compactIri({activeCtx:a,iri:e,relativeTo:{vocab:!0}}));1===t.length&&(t=t[0]);const n=Ii.compactIri({activeCtx:e,iri:"@type",relativeTo:{vocab:!0}}),o=(pi(e,n,"@container")||[]).includes("@set")&&vi(e,1.1)||ni(t)&&0===l.length;xi(r,n,t,{propertyIsArray:o});continue}if("@reverse"===s){const t=await Ii.compact({activeCtx:e,activeProperty:"@reverse",element:l,options:o});for(const n in t)if(e.mappings.has(n)&&e.mappings.get(n).reverse){const i=t[n],a=(pi(e,n,"@container")||[]).includes("@set")||!o.compactArrays;xi(r,n,i,{propertyIsArray:a}),delete t[n]}if(Object.keys(t).length>0){const n=Ii.compactIri({activeCtx:e,iri:s,relativeTo:{vocab:!0}});xi(r,n,t)}continue}if("@preserve"===s){const n=await Ii.compact({activeCtx:e,activeProperty:t,element:l,options:o});ni(n)&&0===n.length||xi(r,s,n);continue}if("@index"===s){if((pi(e,t,"@container")||[]).includes("@index"))continue;const n=Ii.compactIri({activeCtx:e,iri:s,relativeTo:{vocab:!0}});xi(r,n,l);continue}if("@graph"!==s&&"@list"!==s&&"@included"!==s&&hi(s)){const t=Ii.compactIri({activeCtx:e,iri:s,relativeTo:{vocab:!0}});xi(r,t,l);continue}if(!ni(l))throw new ti("JSON-LD expansion error; expanded value must be an array.","jsonld.SyntaxError");if(0===l.length){const t=Ii.compactIri({activeCtx:e,iri:s,value:l,relativeTo:{vocab:!0},reverse:i}),n=e.mappings.has(t)?e.mappings.get(t)["@nest"]:null;let a=r;n&&(Ei(e,n,o),oi(r[n])||(r[n]={}),a=r[n]),xi(a,t,l,{propertyIsArray:!0})}for(const t of l){const n=Ii.compactIri({activeCtx:e,iri:s,value:t,relativeTo:{vocab:!0},reverse:i}),a=e.mappings.has(n)?e.mappings.get(n)["@nest"]:null;let l=r;a&&(Ei(e,a,o),oi(r[a])||(r[a]={}),l=r[a]);const c=pi(e,n,"@container")||[],d=li(t),u=ai(t);let p;u?p=t["@list"]:d&&(p=t["@graph"]);let h=await Ii.compact({activeCtx:e,activeProperty:n,element:u||d?p:t,options:o});if(u){if(ni(h)||(h=[h]),c.includes("@list")){xi(l,n,h,{valueIsArray:!0,allowDuplicate:!0});continue}h={[Ii.compactIri({activeCtx:e,iri:"@list",relativeTo:{vocab:!0}})]:h},"@index"in t&&(h[Ii.compactIri({activeCtx:e,iri:"@index",relativeTo:{vocab:!0}})]=t["@index"])}if(d)if(c.includes("@graph")&&(c.includes("@id")||c.includes("@index")&&ci(t))){let i;l.hasOwnProperty(n)?i=l[n]:l[n]=i={};const r=(c.includes("@id")?t["@id"]:t["@index"])||Ii.compactIri({activeCtx:e,iri:"@none",relativeTo:{vocab:!0}});xi(i,r,h,{propertyIsArray:!o.compactArrays||c.includes("@set")})}else c.includes("@graph")&&ci(t)?(ni(h)&&h.length>1&&(h={"@included":h}),xi(l,n,h,{propertyIsArray:!o.compactArrays||c.includes("@set")})):(ni(h)&&1===h.length&&o.compactArrays&&(h=h[0]),h={[Ii.compactIri({activeCtx:e,iri:"@graph",relativeTo:{vocab:!0}})]:h},"@id"in t&&(h[Ii.compactIri({activeCtx:e,iri:"@id",relativeTo:{vocab:!0}})]=t["@id"]),"@index"in t&&(h[Ii.compactIri({activeCtx:e,iri:"@index",relativeTo:{vocab:!0}})]=t["@index"]),xi(l,n,h,{propertyIsArray:!o.compactArrays||c.includes("@set")}));else if(c.includes("@language")||c.includes("@index")||c.includes("@id")||c.includes("@type")){let i,r;if(l.hasOwnProperty(n)?i=l[n]:l[n]=i={},c.includes("@language"))si(h)&&(h=h["@value"]),r=t["@language"];else if(c.includes("@index")){const o=pi(e,n,"@index")||"@index",i=Ii.compactIri({activeCtx:e,iri:o,relativeTo:{vocab:!0}});if("@index"===o)r=t["@index"],delete h[i];else{let e;if([r,...e]=wi(h[o]||[]),ii(r))switch(e.length){case 0:delete h[o];break;case 1:h[o]=e[0];break;default:h[o]=e}else r=null}}else if(c.includes("@id")){const t=Ii.compactIri({activeCtx:e,iri:"@id",relativeTo:{vocab:!0}});r=h[t],delete h[t]}else if(c.includes("@type")){const i=Ii.compactIri({activeCtx:e,iri:"@type",relativeTo:{vocab:!0}});let a;switch([r,...a]=wi(h[i]||[]),a.length){case 0:delete h[i];break;case 1:h[i]=a[0];break;default:h[i]=a}1===Object.keys(h).length&&"@id"in t&&(h=await Ii.compact({activeCtx:e,activeProperty:n,element:{"@id":t["@id"]},options:o}))}r||(r=Ii.compactIri({activeCtx:e,iri:"@none",relativeTo:{vocab:!0}})),xi(i,r,h,{propertyIsArray:c.includes("@set")})}else{const e=!o.compactArrays||c.includes("@set")||c.includes("@list")||ni(h)&&0===h.length||"@list"===s||"@graph"===s;xi(l,n,h,{propertyIsArray:e})}}}return r}return n},Ii.compactIri=({activeCtx:e,iri:t,value:n=null,relativeTo:o={vocab:!1},reverse:i=!1,base:r=null})=>{if(null===t)return t;e.isPropertyTermScoped&&e.previousContext&&(e=e.previousContext);const a=e.getInverse();if(hi(t)&&t in a&&"@none"in a[t]&&"@type"in a[t]["@none"]&&"@none"in a[t]["@none"]["@type"])return a[t]["@none"]["@type"]["@none"];if(o.vocab&&t in a){const o=e["@language"]||"@none",r=[];oi(n)&&"@index"in n&&!("@graph"in n)&&r.push("@index","@index@set"),oi(n)&&"@preserve"in n&&(n=n["@preserve"][0]),li(n)?("@index"in n&&r.push("@graph@index","@graph@index@set","@index","@index@set"),"@id"in n&&r.push("@graph@id","@graph@id@set"),r.push("@graph","@graph@set","@set"),"@index"in n||r.push("@graph@index","@graph@index@set","@index","@index@set"),"@id"in n||r.push("@graph@id","@graph@id@set")):oi(n)&&!si(n)&&r.push("@id","@id@set","@type","@set@type");let a="@language",s="@null";if(i)a="@type",s="@reverse",r.push("@set");else if(ai(n)){"@index"in n||r.push("@list");const e=n["@list"];if(0===e.length)a="@any",s="@none";else{let t=0===e.length?o:null,n=null;for(let o=0;o<e.length;++o){const i=e[o];let r="@none",a="@none";if(si(i))if("@direction"in i){r=`${(i["@language"]||"").toLowerCase()}_${i["@direction"]}`}else"@language"in i?r=i["@language"].toLowerCase():"@type"in i?a=i["@type"]:r="@null";else a="@id";if(null===t?t=r:r!==t&&si(i)&&(t="@none"),null===n?n=a:a!==n&&(n="@none"),"@none"===t&&"@none"===n)break}t=t||"@none",n=n||"@none","@none"!==n?(a="@type",s=n):s=t}}else{if(si(n))if("@language"in n&&!("@index"in n)){r.push("@language","@language@set"),s=n["@language"];const e=n["@direction"];e&&(s=`${s}_${e}`)}else"@direction"in n&&!("@index"in n)?s=`_${n["@direction"]}`:"@type"in n&&(a="@type",s=n["@type"]);else a="@type",s="@id";r.push("@set")}r.push("@none"),oi(n)&&!("@index"in n)&&r.push("@index","@index@set"),si(n)&&1===Object.keys(n).length&&r.push("@language","@language@set");const l=function(e,t,n,o,i,r){null===r&&(r="@null");const a=[];if(("@id"===r||"@reverse"===r)&&oi(n)&&"@id"in n){"@reverse"===r&&a.push("@reverse");const t=Ii.compactIri({activeCtx:e,iri:n["@id"],relativeTo:{vocab:!0}});e.mappings.has(t)&&e.mappings.get(t)&&e.mappings.get(t)["@id"]===n["@id"]?a.push.apply(a,["@vocab","@id"]):a.push.apply(a,["@id","@vocab"])}else{a.push(r);const e=a.find(e=>e.includes("_"));e&&a.push(e.replace(/^[^_]+_/,"_"))}a.push("@none");const s=e.inverse[t];for(const e of o){if(!(e in s))continue;const t=s[e][i];for(const e of a)if(e in t)return t[e]}return null}(e,t,n,r,a,s);if(null!==l)return l}if(o.vocab&&"@vocab"in e){const n=e["@vocab"];if(0===t.indexOf(n)&&t!==n){const o=t.substr(n.length);if(!e.mappings.has(o))return o}}let s=null;const l=[];let c=e.fastCurieMap;const d=t.length-1;for(let e=0;e<d&&t[e]in c;++e)c=c[t[e]],""in c&&l.push(c[""][0]);for(let o=l.length-1;o>=0;--o){const i=l[o],r=i.terms;for(const o of r){const r=o+":"+t.substr(i.iri.length);e.mappings.get(o)._prefix&&(!e.mappings.has(r)||null===n&&e.mappings.get(r)["@id"]===t)&&(null===s||bi(r,s)<0)&&(s=r)}}if(null!==s)return s;for(const[n,o]of e.mappings)if(o&&o._prefix&&t.startsWith(n+":"))throw new ti(`Absolute IRI "${t}" confused with prefix "${n}".`,"jsonld.SyntaxError",{code:"IRI confused with prefix",context:e});if(!o.vocab){if("@base"in e){if(e["@base"]){const n=gi(yi(r,e["@base"]),t);return mi.test(n)?`./${n}`:n}return t}return gi(r,t)}return t},Ii.compactValue=({activeCtx:e,activeProperty:t,value:n,options:o})=>{if(si(n)){const o=pi(e,t,"@type"),i=pi(e,t,"@language"),r=pi(e,t,"@direction"),a=pi(e,t,"@container")||[],s="@index"in n&&!a.includes("@index");if(!s&&"@none"!==o){if(n["@type"]===o)return n["@value"];if("@language"in n&&n["@language"]===i&&"@direction"in n&&n["@direction"]===r)return n["@value"];if("@language"in n&&n["@language"]===i)return n["@value"];if("@direction"in n&&n["@direction"]===r)return n["@value"]}const l=Object.keys(n).length,c=1===l||2===l&&"@index"in n&&!s,d="@language"in e,u=ii(n["@value"]),p=e.mappings.has(t)&&null===e.mappings.get(t)["@language"];if(c&&"@none"!==o&&(!d||!u||p))return n["@value"];const h={};return s&&(h[Ii.compactIri({activeCtx:e,iri:"@index",relativeTo:{vocab:!0}})]=n["@index"]),"@type"in n?h[Ii.compactIri({activeCtx:e,iri:"@type",relativeTo:{vocab:!0}})]=Ii.compactIri({activeCtx:e,iri:n["@type"],relativeTo:{vocab:!0}}):"@language"in n&&(h[Ii.compactIri({activeCtx:e,iri:"@language",relativeTo:{vocab:!0}})]=n["@language"]),"@direction"in n&&(h[Ii.compactIri({activeCtx:e,iri:"@direction",relativeTo:{vocab:!0}})]=n["@direction"]),h[Ii.compactIri({activeCtx:e,iri:"@value",relativeTo:{vocab:!0}})]=n["@value"],h}const i=ui(e,t,{vocab:!0},o),r=pi(e,t,"@type"),a=Ii.compactIri({activeCtx:e,iri:n["@id"],relativeTo:{vocab:"@vocab"===r},base:o.base});return"@id"===r||"@vocab"===r||"@graph"===i?a:{[Ii.compactIri({activeCtx:e,iri:"@id",relativeTo:{vocab:!0}})]:a}};
|
|
37
|
+
/**
|
|
38
|
+
* A JavaScript implementation of the JSON-LD API.
|
|
39
|
+
*
|
|
40
|
+
* @author Dave Longley
|
|
41
|
+
*
|
|
42
|
+
* @license BSD 3-Clause License
|
|
43
|
+
* Copyright (c) 2011-2022 Digital Bazaar, Inc.
|
|
44
|
+
* All rights reserved.
|
|
45
|
+
*
|
|
46
|
+
* Redistribution and use in source and binary forms, with or without
|
|
47
|
+
* modification, are permitted provided that the following conditions are met:
|
|
48
|
+
*
|
|
49
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
50
|
+
* this list of conditions and the following disclaimer.
|
|
51
|
+
*
|
|
52
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
53
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
54
|
+
* documentation and/or other materials provided with the distribution.
|
|
55
|
+
*
|
|
56
|
+
* Neither the name of the Digital Bazaar, Inc. nor the names of its
|
|
57
|
+
* contributors may be used to endorse or promote products derived from
|
|
58
|
+
* this software without specific prior written permission.
|
|
59
|
+
*
|
|
60
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
61
|
+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
62
|
+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
63
|
+
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
64
|
+
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
65
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
66
|
+
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
67
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
68
|
+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
69
|
+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
70
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
71
|
+
*/
|
|
72
|
+
const Di=ce,Oi=ze,Ni=ke,Ci=class{constructor({sharedCache:e}){this.perOpCache=new Map,this.sharedCache=e}async resolve({activeCtx:e,context:t,documentLoader:n,base:o,cycles:i=new Set}){t&&bt(t)&&t["@context"]&&(t=t["@context"]),t=jt(t);const r=[];for(const a of t){if(It(a)){let t=this._get(a);t||(t=await this._resolveRemoteContext({activeCtx:e,url:a,documentLoader:n,base:o,cycles:i})),wt(t)?r.push(...t):r.push(t);continue}if(null===a){r.push(new Et({document:null}));continue}bt(a)||Dt(t);const s=JSON.stringify(a);let l=this._get(s);l||(l=new Et({document:a}),this._cacheResolvedContext({key:s,resolved:l,tag:"static"})),r.push(l)}return r}_get(e){let t=this.perOpCache.get(e);if(!t){const n=this.sharedCache.get(e);n&&(t=n.get("static"),t&&this.perOpCache.set(e,t))}return t}_cacheResolvedContext({key:e,resolved:t,tag:n}){if(this.perOpCache.set(e,t),void 0!==n){let o=this.sharedCache.get(e);o||(o=new Map,this.sharedCache.set(e,o)),o.set(n,t)}return t}async _resolveRemoteContext({activeCtx:e,url:t,documentLoader:n,base:o,cycles:i}){t=St(o,t);const{context:r,remoteDoc:a}=await this._fetchContext({activeCtx:e,url:t,documentLoader:n,cycles:i});Ot({context:r,base:o=a.documentUrl||t});const s=await this.resolve({activeCtx:e,context:r,documentLoader:n,base:o,cycles:i});return this._cacheResolvedContext({key:t,resolved:s,tag:a.tag}),s}async _fetchContext({activeCtx:e,url:t,documentLoader:n,cycles:o}){if(o.size>10)throw new kt("Maximum number of @context URLs exceeded.","jsonld.ContextUrlError",{code:"json-ld-1.0"===e.processingMode?"loading remote context failed":"context overflow",max:10});if(o.has(t))throw new kt("Cyclical @context URLs detected.","jsonld.ContextUrlError",{code:"json-ld-1.0"===e.processingMode?"recursive context inclusion":"context overflow",url:t});let i,r;o.add(t);try{r=await n(t),i=r.document||null,It(i)&&(i=JSON.parse(i))}catch(e){throw new kt(`Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context. URL: "${t}".`,"jsonld.InvalidUrl",{code:"loading remote context failed",url:t,cause:e})}if(!bt(i))throw new kt(`Dereferencing a URL did not result in a JSON object. The response was valid JSON, but it was not a JSON object. URL: "${t}".`,"jsonld.InvalidUrl",{code:"invalid remote context",url:t});return i="@context"in i?{"@context":i["@context"]}:{"@context":{}},r.contextUrl&&(wt(i["@context"])||(i["@context"]=[i["@context"]]),i["@context"].push(r.contextUrl)),{context:i,remoteDoc:r}}},Ai=Ni.IdentifierIssuer,Li=ve,Ri=mt,Ti=Nt,{expand:_i}=Dn,{flatten:Pi}=qn,{fromRDF:Mi}=so,{toRDF:Hi}=Ao,{frameMergedOrDefault:Ji,cleanupNull:Fi}=Vo,{isArray:Ui,isObject:Bi,isString:qi}=ue,{isSubjectReference:Vi}=fe,{expandIri:$i,getInitialContext:Gi,process:zi,processingMode:Ki}=Yt,{compact:Qi,compactIri:Wi}=ki,{createNodeMap:Xi,createMergedNodeMap:Zi,mergeNodeMaps:Yi}=Jn,{logEventHandler:er,logWarningEventHandler:tr,safeEventHandler:nr,setDefaultEventHandler:or,setupEventHandler:ir,strictEventHandler:rr,unhandledEventHandler:ar}=Tt,sr=function(e){const t={},n=new Ri({max:100});function o(t,{documentLoader:n=e.documentLoader,...o}){if(t&&"compactionMap"in t)throw new Li('"compactionMap" not supported.',"jsonld.OptionsError");if(t&&"expansionMap"in t)throw new Li('"expansionMap" not supported.',"jsonld.OptionsError");return Object.assign({},{documentLoader:n},o,t,{eventHandler:ir({options:t})})}return e.compact=async function(t,i,r){if(arguments.length<2)throw new TypeError("Could not compact, too few arguments.");if(null===i)throw new Li("The compaction context must not be null.","jsonld.CompactError",{code:"invalid local context"});if(null===t)return null;let a;(r=o(r,{base:qi(t)?t:"",compactArrays:!0,compactToRelative:!0,graph:!1,skipExpansion:!1,link:!1,issuer:new Ai("_:b"),contextResolver:new Ci({sharedCache:n})})).link&&(r.skipExpansion=!0),r.compactToRelative||delete r.base,a=r.skipExpansion?t:await e.expand(t,r);const s=await e.processContext(Gi(r),i,r);let l=await Qi({activeCtx:s,element:a,options:r});r.compactArrays&&!r.graph&&Ui(l)?1===l.length?l=l[0]:0===l.length&&(l={}):r.graph&&Bi(l)&&(l=[l]),Bi(i)&&"@context"in i&&(i=i["@context"]),i=Ni.clone(i),Ui(i)||(i=[i]);const c=i;i=[];for(let e=0;e<c.length;++e)(!Bi(c[e])||Object.keys(c[e]).length>0)&&i.push(c[e]);const d=i.length>0;if(1===i.length&&(i=i[0]),Ui(l)){const e=Wi({activeCtx:s,iri:"@graph",relativeTo:{vocab:!0}}),t=l;l={},d&&(l["@context"]=i),l[e]=t}else if(Bi(l)&&d){const e=l;l={"@context":i};for(const t in e)l[t]=e[t]}return l},e.expand=async function(t,i){if(arguments.length<1)throw new TypeError("Could not expand, too few arguments.");const r={},a=[];if("expandContext"in(i=o(i,{keepFreeFloatingNodes:!1,contextResolver:new Ci({sharedCache:n})}))){const e=Ni.clone(i.expandContext);Bi(e)&&"@context"in e?r.expandContext=e:r.expandContext={"@context":e},a.push(r.expandContext)}let s;if(qi(t)){const n=await e.get(t,i);s=n.documentUrl,r.input=n.document,n.contextUrl&&(r.remoteContext={"@context":n.contextUrl},a.push(r.remoteContext))}else r.input=Ni.clone(t);"base"in i||(i.base=s||"");let l=Gi(i);for(const e of a)l=await zi({activeCtx:l,localCtx:e,options:i});let c=await _i({activeCtx:l,element:r.input,options:i});return Bi(c)&&"@graph"in c&&1===Object.keys(c).length?c=c["@graph"]:null===c&&(c=[]),Ui(c)||(c=[c]),c},e.flatten=async function(t,i,r){if(arguments.length<1)return new TypeError("Could not flatten, too few arguments.");i="function"==typeof i?null:i||null,r=o(r,{base:qi(t)?t:"",contextResolver:new Ci({sharedCache:n})});const a=await e.expand(t,r),s=Pi(a);if(null===i)return s;r.graph=!0,r.skipExpansion=!0;return await e.compact(s,i,r)},e.frame=async function(t,i,r){if(arguments.length<2)throw new TypeError("Could not frame, too few arguments.");if(r=o(r,{base:qi(t)?t:"",embed:"@once",explicit:!1,requireAll:!1,omitDefault:!1,bnodesToClear:[],contextResolver:new Ci({sharedCache:n})}),qi(i)){const t=await e.get(i,r);if(i=t.document,t.contextUrl){let e=i["@context"];e?Ui(e)?e.push(t.contextUrl):e=[e,t.contextUrl]:e=t.contextUrl,i["@context"]=e}}const a=i&&i["@context"]||{},s=await e.processContext(Gi(r),a,r);r.hasOwnProperty("omitGraph")||(r.omitGraph=Ki(s,1.1)),r.hasOwnProperty("pruneBlankNodeIdentifiers")||(r.pruneBlankNodeIdentifiers=Ki(s,1.1));const l=await e.expand(t,r),c={...r};c.isFrame=!0,c.keepFreeFloatingNodes=!0;const d=await e.expand(i,c),u=Object.keys(i).map(e=>$i(s,e,{vocab:!0}));c.merged=!u.includes("@graph"),c.is11=Ki(s,1.1);const p=Ji(l,d,c);c.graph=!r.omitGraph,c.skipExpansion=!0,c.link={},c.framing=!0;let h=await e.compact(p,a,c);return c.link={},h=Fi(h,c),h},e.link=async function(t,n,o){const i={};return n&&(i["@context"]=n),i["@embed"]="@link",e.frame(t,i,o)},e.normalize=e.canonize=async function(t,i){if(arguments.length<1)throw new TypeError("Could not canonize, too few arguments.");i=o(i,{skipExpansion:!1,safe:!0,contextResolver:new Ci({sharedCache:n})});const r=Object.assign({},{algorithm:"RDFC-1.0"},i.canonizeOptions||null);if("inputFormat"in i){if("application/n-quads"!==i.inputFormat)throw new Li("Unknown canonicalization input format.","jsonld.CanonizeError");const e=Ti.parse(t);return Di.canonize(e,r)}const a={...i};delete a.format,delete a.canonizeOptions,a.produceGeneralizedRdf=!1;const s=await e.toRDF(t,a);return Di.canonize(s,r)},e.fromRDF=async function(e,n){if(arguments.length<1)throw new TypeError("Could not convert from RDF, too few arguments.");n=o(n,{format:qi(e)?"application/n-quads":void 0});const{format:i}=n;let{rdfParser:r}=n;if(i){if(r=r||t[i],!r)throw new Li("Unknown input format.","jsonld.UnknownFormat",{format:i})}else r=()=>e;const a=await r(e);return Mi(a,n)},e.toRDF=async function(t,i){if(arguments.length<1)throw new TypeError("Could not convert to RDF, too few arguments.");let r;r=(i=o(i,{skipExpansion:!1,contextResolver:new Ci({sharedCache:n})})).skipExpansion?t:await e.expand(t,i);const a=Hi(r,i);if(i.format){if("application/n-quads"===i.format)return Ti.serialize(a);throw new Li("Unknown output format.","jsonld.UnknownFormat",{format:i.format})}return a},e.createNodeMap=async function(t,i){if(arguments.length<1)throw new TypeError("Could not create node map, too few arguments.");i=o(i,{base:qi(t)?t:"",contextResolver:new Ci({sharedCache:n})});const r=await e.expand(t,i);return Zi(r,i)},e.merge=async function(t,i,r){if(arguments.length<1)throw new TypeError("Could not merge, too few arguments.");if(!Ui(t))throw new TypeError('Could not merge, "docs" must be an array.');i="function"==typeof i?null:i||null,r=o(r,{contextResolver:new Ci({sharedCache:n})});const a=await Promise.all(t.map(t=>{const n={...r};return e.expand(t,n)}));let s=!0;"mergeNodes"in r&&(s=r.mergeNodes);const l=r.issuer||new Ai("_:b"),c={"@default":{}};for(let e=0;e<a.length;++e){const t=Ni.relabelBlankNodes(a[e],{issuer:new Ai("_:b"+e+"-")}),n=s||0===e?c:{"@default":{}};if(Xi(t,n,"@default",l),n!==c)for(const e in n){const t=n[e];if(!(e in c)){c[e]=t;continue}const o=c[e];for(const e in t)e in o||(o[e]=t[e])}}const d=Yi(c),u=[],p=Object.keys(d).sort();for(let e=0;e<p.length;++e){const t=d[p[e]];Vi(t)||u.push(t)}if(null===i)return u;r.graph=!0,r.skipExpansion=!0;return await e.compact(u,i,r)},Object.defineProperty(e,"documentLoader",{get:()=>e._documentLoader,set:t=>e._documentLoader=t}),e.documentLoader=async e=>{throw new Li("Could not retrieve a JSON-LD document from the URL. URL dereferencing not implemented.","jsonld.LoadDocumentError",{code:"loading document failed",url:e})},e.get=async function(t,n){let o;o="function"==typeof n.documentLoader?n.documentLoader:e.documentLoader;const i=await o(t);try{if(!i.document)throw new Li("No remote document found at the given URL.","jsonld.NullRemoteDocument");qi(i.document)&&(i.document=JSON.parse(i.document))}catch(e){throw new Li("Could not retrieve a JSON-LD document from the URL.","jsonld.LoadDocumentError",{code:"loading document failed",cause:e,remoteDoc:i})}return i},e.processContext=async function(e,t,i){return i=o(i,{base:"",contextResolver:new Ci({sharedCache:n})}),null===t?Gi(i):(t=Ni.clone(t),Bi(t)&&"@context"in t||(t={"@context":t}),zi({activeCtx:e,localCtx:t,options:i}))},e.getContextValue=Yt.getContextValue,e.documentLoaders={},e.useDocumentLoader=function(t){if(!(t in e.documentLoaders))throw new Li('Unknown document loader type: "'+t+'"',"jsonld.UnknownDocumentLoader",{type:t});e.documentLoader=e.documentLoaders[t].apply(e,Array.prototype.slice.call(arguments,1))},e.registerRDFParser=function(e,n){t[e]=n},e.unregisterRDFParser=function(e){delete t[e]},e.registerRDFParser("application/n-quads",Ti.parse),e.url=_e(),e.logEventHandler=er,e.logWarningEventHandler=tr,e.safeEventHandler=nr,e.setDefaultEventHandler=or,e.strictEventHandler=rr,e.unhandledEventHandler=ar,e.util=Ni,Object.assign(e,Ni),e.promises=e,e.RequestQueue=Te(),e.JsonLdProcessor=(Si||(Si=1,ji=e=>{class t{toString(){return"[object JsonLdProcessor]"}}return Object.defineProperty(t,"prototype",{writable:!1,enumerable:!1}),Object.defineProperty(t.prototype,"constructor",{writable:!0,enumerable:!1,configurable:!0,value:t}),t.compact=function(t,n){return arguments.length<2?Promise.reject(new TypeError("Could not compact, too few arguments.")):e.compact(t,n)},t.expand=function(t){return arguments.length<1?Promise.reject(new TypeError("Could not expand, too few arguments.")):e.expand(t)},t.flatten=function(t){return arguments.length<1?Promise.reject(new TypeError("Could not flatten, too few arguments.")):e.flatten(t)},t}),ji)(e),Oi.setupGlobals(e),Oi.setupDocumentLoaders(e),e},lr=function(){return sr(function(){return lr()})};sr(lr);var cr=a(lr);function dr(e,t,n=""){const o=(i=e)instanceof Uint8Array||ArrayBuffer.isView(i)&&"Uint8Array"===i.constructor.name;
|
|
73
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
74
|
+
var i;const r=e?.length;if(!o||void 0!==t){throw new Error((n&&`"${n}" `)+"expected Uint8Array"+""+", got "+(o?`length=${r}`:"type="+typeof e))}return e}function ur(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function pr(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function hr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function fr(e,t){return e<<32-t|e>>>t}function vr(e,t={}){const n=(t,n)=>e(n).update(t).digest(),o=e(void 0);return n.outputLen=o.outputLen,n.blockLen=o.blockLen,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}const gr=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function yr(e,t,n){return e&t^~e&n}function mr(e,t,n){return e&t^e&n^t&n}class xr{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,o){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=hr(this.buffer)}update(e){ur(this),dr(e);const{view:t,buffer:n,blockLen:o}=this,i=e.length;for(let r=0;r<i;){const a=Math.min(o-this.pos,i-r);if(a===o){const t=hr(e);for(;o<=i-r;r+=o)this.process(t,r);continue}n.set(e.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===o&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ur(this),function(e,t){dr(e,void 0,"digestInto() output");const n=t.outputLen;if(e.length<n)throw new Error('"digestInto() output" expected to be of length >='+n)}(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:o,isLE:i}=this;let{pos:r}=this;t[r++]=128,pr(this.buffer.subarray(r)),this.padOffset>o-r&&(this.process(n,0),r=0);for(let e=r;e<o;e++)t[e]=0;n.setBigUint64(o-8,BigInt(8*this.length),i),this.process(n,0);const a=hr(e),s=this.outputLen;if(s%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const l=s/4,c=this.get();if(l>c.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)a.setUint32(4*e,c[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());const{blockLen:t,buffer:n,length:o,finished:i,destroyed:r,pos:a}=this;return e.destroyed=r,e.finished=i,e.length=o,e.pos=a,o%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const wr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),br=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Ir=new Uint32Array(64);class jr extends xr{constructor(e){super(64,e,8,!1)}get(){const{A:e,B:t,C:n,D:o,E:i,F:r,G:a,H:s}=this;return[e,t,n,o,i,r,a,s]}set(e,t,n,o,i,r,a,s){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|o,this.E=0|i,this.F=0|r,this.G=0|a,this.H=0|s}process(e,t){for(let n=0;n<16;n++,t+=4)Ir[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Ir[e-15],n=Ir[e-2],o=fr(t,7)^fr(t,18)^t>>>3,i=fr(n,17)^fr(n,19)^n>>>10;Ir[e]=i+Ir[e-7]+o+Ir[e-16]|0}let{A:n,B:o,C:i,D:r,E:a,F:s,G:l,H:c}=this;for(let e=0;e<64;e++){const t=c+(fr(a,6)^fr(a,11)^fr(a,25))+yr(a,s,l)+br[e]+Ir[e]|0,d=(fr(n,2)^fr(n,13)^fr(n,22))+mr(n,o,i)|0;c=l,l=s,s=a,a=r+t|0,r=i,i=o,o=n,n=t+d|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,r=r+this.D|0,a=a+this.E|0,s=s+this.F|0,l=l+this.G|0,c=c+this.H|0,this.set(n,o,i,r,a,s,l,c)}roundClean(){pr(Ir)}destroy(){this.set(0,0,0,0,0,0,0,0),pr(this.buffer)}}class Sr extends jr{A=0|wr[0];B=0|wr[1];C=0|wr[2];D=0|wr[3];E=0|wr[4];F=0|wr[5];G=0|wr[6];H=0|wr[7];constructor(){super(32)}}const kr=vr(()=>new Sr,gr(1));function Er(e){e=e.trim();const t=[];for(let n=0;n<e.length;n+=2)t.push(parseInt(e.substring(n,n+2),16));return t}const Dr="__IMAGE__SIGNATURE__";function Or(e){if(!Array.isArray(e["@context"])||Array.isArray(e["@context"])&&null==e["@context"][0]["image:signature"])return e;const t=JSON.parse(JSON.stringify(e));return t["@context"][0][Dr]=e["@context"][0]["image:signature"],delete t["@context"][0]["image:signature"],t}async function Nr(e){Array.isArray(e["@context"])&&!e["@context"].find(e=>i(e)&&"@vocab"in e)&&e["@context"].push({"@vocab":"http://fallback.org/"});const t=(r=e,null!=r.document?.assertion?.["image:signature"]&&(r.document.assertion[Dr]=r.document.assertion["image:signature"],delete r.document.assertion["image:signature"]),r);var r;const a={algorithm:"URDNA2015",format:"application/nquads",documentLoader:function(e){return e in s?{contextUrl:null,document:Or(s[e]),documentUrl:e}:cr.documentLoader(e)},safe:!1};let l;try{l=await cr.normalize(t.document,a)}catch(e){throw console.error(e),new n("computeLocalHash",o("errors","failedJsonLdNormalization"))}const d=function(e){const t=e.split("\n"),n=/<http:\/\/fallback\.org\/(.*)>/,o=t.map(e=>n.exec(e)).filter(e=>null!=e);if(o.length>0){const e=o.map(e=>e[1]).sort();return Array.from(new Set(e))}return null}(l);if(d)throw new n("computeLocalHash",`${o("errors","foundUnmappedFields")}: ${d.join(", ")}`);return c.from(kr(Uint8Array.from(function(e){const t=[];for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t.push(o):o<2048?t.push(192|o>>6,128|63&o):o<55296||o>=57344?t.push(224|o>>12,128|o>>6&63,128|63&o):(n++,o=65536+((1023&o)<<10|1023&e.charCodeAt(n)),t.push(240|o>>18,128|o>>12&63,128|o>>6&63,128|63&o))}return t}(l)))).toString("hex")}function Cr(e,t,i){let a="";const s=function(e,t){let n=null;for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&o.toLowerCase()===t.toLowerCase()&&(n=o);return e[n]}(e,t),l=r(i);if(s?(s.created&&l<=s.created&&(a="invalidIssuingAddressCreationTime"),s.revoked&&l>=s.revoked&&(a="invalidIssuingAddressRevoked"),s.expires&&l>=s.expires&&(a="invalidIssuingAddressExpired")):a="invalidIssuingAddressUnknown",a)throw new n("checkAuthenticity",o("errors",a))}class Ar{constructor(e){}}var Lr;!function(e){e.getTransactionId="getTransactionId",e.computeLocalHash="computeLocalHash",e.fetchRemoteHash="fetchRemoteHash",e.parseIssuerKeys="parseIssuerKeys",e.compareHashes="compareHashes",e.checkMerkleRoot="checkMerkleRoot",e.checkReceipt="checkReceipt",e.checkAuthenticity="checkAuthenticity"}(Lr||(Lr={}));class Rr extends Ar{verificationProcess=[Lr.getTransactionId,Lr.computeLocalHash,Lr.fetchRemoteHash,Lr.compareHashes,Lr.checkMerkleRoot,Lr.checkReceipt,Lr.parseIssuerKeys,Lr.checkAuthenticity];transactionId;localHash;documentToVerify;txData;chain;explorerAPIs;receipt;issuerPublicKeyList;issuer;proof;type="MerkleProof2017";constructor(t){super(t),t.executeStep&&(this.executeStep=t.executeStep),this.documentToVerify=t.document,this.explorerAPIs=t.explorerAPIs,this.issuer=t.issuer,this.proof=t.proof,this.validateProofType(),this.receipt=this.documentToVerify.signature??this.documentToVerify.receipt,this.chain=e.certificates.getChain("",this.receipt),this.transactionId=e.certificates.getTransactionId(this.receipt),this.adaptVerificationProcessToChain()}async init(){}async verifyProof(){for(const e of this.verificationProcess){if(!this[e])return void console.error("verification logic for",e,"not implemented");await this[e]()}}async verifyIdentity(){}getProofVerificationSteps(t){return this.verificationProcess.map(n=>e.verifier.convertToVerificationSubsteps(t,n))}getIdentityVerificationSteps(){return[]}getIssuerPublicKey(){return e.chains.isMockChain(this.chain)?"This mock chain does not support issuing addresses":this.txData?this.txData.issuingAddress:void console.error("Trying to access issuing address when txData not available yet. Did you run the `verify` method yet?")}getIssuerName(){return this.issuer.name}getIssuerProfileDomain(){const e=new URL(this.getIssuerProfileUrl());return e?.hostname}getIssuerProfileUrl(){return this.issuer.id}getSigningDate(){return this.txData.time.toString()}getProofType(){return Array.isArray(this.proof.type)?this.proof.type[0]:this.proof.type}getChain(){return this.chain}getReceipt(){return this.receipt}getTransactionIdString(){return e.certificates.getTransactionId(this.getReceipt())}getTransactionLink(){return e.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).transactionLink}getRawTransactionLink(){return e.certificates.getTransactionLink(this.getTransactionIdString(),this.getChain()).rawTransactionLink}validateProofType(){const e=[this.type,"ChainpointSHA256v2"],t=this.getProofType();if(!e.includes(t))throw new Error(`Incompatible proof type passed. Expected: ${this.type}, Got: ${this.proof.type[0]}`)}adaptVerificationProcessToChain(){e.chains.isMockChain(this.chain)&&(t(this.verificationProcess,Lr.getTransactionId),t(this.verificationProcess,Lr.fetchRemoteHash),t(this.verificationProcess,Lr.parseIssuerKeys),t(this.verificationProcess,Lr.checkMerkleRoot),t(this.verificationProcess,Lr.checkAuthenticity))}async executeStep(e,t,n){throw new Error("doAction method needs to be overwritten by injecting from CVJS")}async getTransactionId(){await this.executeStep(Lr.getTransactionId,()=>function(e){if("string"==typeof e&&e.length>0)return e;throw new n("getTransactionId",o("errors","isTransactionIdValid"))}(this.transactionId),this.type)}async computeLocalHash(){this.localHash=await this.executeStep(Lr.computeLocalHash,async()=>await Nr(this.documentToVerify),this.type)}async fetchRemoteHash(){this.txData=await this.executeStep(Lr.fetchRemoteHash,async()=>await e.verifier.lookForTx({transactionId:this.transactionId,chain:this.chain.code,explorerAPIs:this.explorerAPIs}),this.type)}async compareHashes(){await this.executeStep(Lr.compareHashes,()=>function(e,t){if(e!==t)throw new n("compareHashes",o("errors","ensureHashesEqual"));return!0}(this.localHash,this.receipt.targetHash),this.type)}async checkMerkleRoot(){await this.executeStep(Lr.checkMerkleRoot,()=>function(e,t){if(e!==t)throw new n("checkMerkleRoot",o("errors","ensureMerkleRootEqual"));return!0}(this.receipt.merkleRoot,this.txData.remoteHash),this.type)}async checkReceipt(){await this.executeStep(Lr.checkReceipt,()=>{!function(e){let t=e.targetHash;const i=e.merkleRoot;try{const o=e.proof??e.path;if(o)for(const e in o){const i=o[e];let r;if(void 0!==i.left)r=Er(`${i.left}${t}`),t=c.from(kr(Uint8Array.from(r))).toString("hex");else{if(void 0===i.right)throw new n("checkReceipt","Trigger catch error.");r=Er(`${t}${i.right}`),t=c.from(kr(Uint8Array.from(r))).toString("hex")}}}catch(e){throw new n("checkReceipt",o("errors","ensureValidReceipt"))}if(t!==i)throw new n("checkReceipt",o("errors","invalidMerkleReceipt"))}(this.receipt)},this.type)}async parseIssuerKeys(){this.issuerPublicKeyList=await this.executeStep(Lr.parseIssuerKeys,()=>e.verifier.parseIssuerKeys(this.issuer),this.type)}async checkAuthenticity(){await this.executeStep(Lr.checkAuthenticity,()=>{Cr(this.issuerPublicKeyList,this.txData.issuingAddress,this.txData.time)},this.type)}}export{Rr as default};
|