Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Named export 'SECURITY_CONTEXT_URL' not found. #387

Open
dcolley opened this issue Feb 2, 2024 · 0 comments
Open

SyntaxError: Named export 'SECURITY_CONTEXT_URL' not found. #387

dcolley opened this issue Feb 2, 2024 · 0 comments

Comments

@dcolley
Copy link

dcolley commented Feb 2, 2024

Steps to produce:

launch the app with

node server.js

Produces the following error:

% node server.js 
file:///.../subledgr.com/graphql/node_modules/@docknetwork/sdk/utils/vc/crypto/common/DockCryptoSignature.js:1
import{initializeWasm as e,CredentialSchema as t,DefaultSchemaParsingOpts as r}from"@docknetwork/crypto-wasm-ts";import o from"jsonld";import{SECURITY_CONTEXT_URL as i}from"jsonld-signatures";import{u8aToU8a as a}from"@polkadot/util";import n from"json-stringify-deterministic";import{withExtendedStaticProperties as c}from"../../../inheritance.js";import s from"./CustomLinkedDataSignature.js";import"bs58";import"base64url";import"../../jws.js";const d={useDefaults:!1};var l=c(["KeyPair","CredentialBuilder","Credential","proofType"],class extends s{constructor(e={},t,r,o){const{verificationMethod:i,signer:a,keypair:n,verifier:c}=e;super({type:t,LDKeyClass:r,contextUrl:"https://www.w3.org/2018/credentials/v1",alg:t,signer:a,verifier:c,useProofValue:!0}),this.proof={"@context":[{sec:"https://w3id.org/security#",proof:{"@id":"sec:proof","@type":"@id","@container":"@graph"}},o],type:t},this.requireCredentialSchema=!0,this.verificationMethod=i,n&&(void 0===i&&(this.verificationMethod=n.id),this.key=n)}async createVerifyData(t){await e();let r,o;t.proof&&t.proof.proofValue?t.document.cryptoVersion?[r,o]=this.constructor.convertCredentialForVerification(t):[r,o]=this.constructor.convertCredential(t):[r,o]=await this.constructor.convertCredentialToSerializedForSigning(t);return o.encoder.encodeMessageObject(r,!1)[1]}static convertCredential({document:e,proof:t,signingOptions:r={requireAllFieldsFromSchema:!1}}){const[o]=this.getTrimmedProofAndValue(e,t),[i]=this.extractSchema(e),a=new this.CredentialBuilder;a.version="0.2.0",a.schema=i;const{cryptoVersion:n,credentialSchema:c,credentialSubject:s,credentialStatus:d,...l}={...e,proof:o};a.subject=s,a.credStatus=d,Object.keys(l).sort().forEach((e=>{a.setTopLevelField(e,l[e])})),a.setTopLevelField("@context",JSON.stringify(e["@context"])),a.setTopLevelField("type",JSON.stringify(e.type));const h=a.updateSchemaIfNeeded(r);if(e.credentialSchema){const t=h.credentialSchema;Object.assign(e.credentialSchema,"string"==typeof t?JSON.parse(t):t)}return[h,a.schema]}static convertCredentialForPresBuilding({document:e,proof:r}){const[o,i]=this.getTrimmedProofAndValue(e,r),[a,n]=this.extractSchema(e),c={...e,proof:o};this.revealMandatoryFields(c,e);const d=this.Credential.fromJSON(c,s.fromJsigProofValue(i));return n||(d.schema=t.generateAppropriateSchema(c,a)),d}static convertCredentialForVerification({document:e,proof:r}){const[o]=this.getTrimmedProofAndValue(e,r),i=this.extractSchema(e);let a=i[0];const c=i[1],s={...e,proof:o};this.revealMandatoryFields(s,e),c||(s.cryptoVersion="0.2.0",void 0===s.credentialSchema&&(s.credentialSchema=JSON.stringify(a.toJSON())),a=t.generateAppropriateSchema(s,a));const d=a.toJSON();return s.credentialSchema=c?n(d):JSON.stringify(d),e.credentialSchema&&Object.assign(e.credentialSchema,d),[s,a]}static async convertCredentialToSerializedForSigning({document:e,proof:r,documentLoader:o}){const[i]=this.getTrimmedProofAndValue(e,r),[a]=await this.extractSchemaForSigning(e,o),c=new this.CredentialBuilder;c.schema=a;const{credentialSchema:s,credentialSubject:d,credentialStatus:l,...h}={...e,proof:i};c.subject=d,c.credStatus=l,Object.keys(h).sort().forEach((e=>{c.setTopLevelField(e,h[e])})),c.setTopLevelField("@context",JSON.stringify(e["@context"])),c.setTopLevelField("type",JSON.stringify(e.type));const m=c.serializeForSigning();c.schema=t.generateAppropriateSchema(m,a);const f=c.schema.toJSON();return m.credentialSchema=n(f),Object.assign(e.credentialSchema,f),e.cryptoVersion=m.cryptoVersion,[m,c.schema]}static revealMandatoryFields(e,t){e["@context"]=JSON.stringify(t["@context"]),e.type=JSON.stringify(t.type)}static getTrimmedProofAndValue(e,t){const r=t||e.proof;if(r.type!==this.proofType[0])throw new Error(`Invalid \`proof.type\`, expected ${this.proofType[0]}, received ${r.type}`);const o={"@context":e["@context"]||i,...r},a=o.proofValue;return delete o.jws,delete o.signatureValue,delete o.proofValue,[o,a]}static async extractSchemaForSigning(e,o){let i,a=!0;if(e.credentialSchema&&e.credentialSchema.id){async function n(e){if(!e.startsWith("blob:dock:"))throw new Error(`Can only fetch schemas stored on Dock for now. Got schema id ${e}`);const{document:t}=await o(e);return t[1]}i=await t.fromJSONWithPotentiallyExternalSchema({parsingOptions:r,...e.credentialSchema},n)}else i=this.extractSchemaWhenIdNotSet(e),a=!1;return[i,a]}static extractSchema(e){let o,i=!0;return e.credentialSchema&&e.credentialSchema.id?o=t.fromJSON({parsingOptions:r,...e.credentialSchema}):(o=this.extractSchemaWhenIdNotSet(e),i=!1),[o,i]}static extractSchemaWhenIdNotSet(e){let r;return r=e.credentialSchema?new t(t.essential()):new t(t.essential(),{useDefaults:!1,defaultMinimumInteger:-(2**32-1),defaultDecimalPlaces:0},!1,{version:"0.0.1"}),r}static async getVerificationMethod({proof:e,documentLoader:t}){let{verificationMethod:r}=e;if("object"==typeof r&&(r=r.id),!r)throw new Error('No "verificationMethod" found in proof.');const a=await o.frame(r,{"@context":i,"@embed":"@always",id:r},{documentLoader:t,compactToRelative:!1,expandContext:i});if(!a)throw new Error(`Verification method ${r} not found.`);if(void 0!==a.revoked)throw new Error("The verification method has been revoked.");return a}async getVerificationMethod({proof:e,documentLoader:t}){return this.constructor.getVerificationMethod({proof:e,documentLoader:t})}static signerFactory(e,t){const{KeyPair:r}=this;return{id:t,async sign({data:t}){if(!e||!e.privateKeyBuffer)throw new Error("No private key to sign with.");const o=t.length,i=r.SignatureParams.getSigParamsOfRequiredSize(o,r.defaultLabelBytes),n=r.adaptKey(new r.SecretKey(a(e.privateKeyBuffer)),t.length);return r.Signature.generate(t,n,i).value}}}ensureSuiteContext(){}});export{d as DEFAULT_PARSING_OPTS,l as default};
                                                                                                                                              ^^^^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'SECURITY_CONTEXT_URL' not found. The requested module 'jsonld-signatures' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'jsonld-signatures';
const {initializeWasm: e,CredentialSchema: t,DefaultSchemaParsingOpts: r}from"@docknetwork/crypto-wasm-ts";import o from"jsonld";import{SECURITY_CONTEXT_URL: i}from"jsonld-signatures";import{u8aToU8a: a}from"@polkadot/util";import n from"json-stringify-deterministic";import{withExtendedStaticProperties: c}from"../../../inheritance.js";import s from"./CustomLinkedDataSignature.js";import"bs58";import"base64url";import"../../jws.js";const d={useDefaults:!1};var l=c(["KeyPair","CredentialBuilder","Credential","proofType"],class extends s{constructor(e={},t,r,o){const{verificationMethod:i,signer:a,keypair:n,verifier:c}=e;super({type:t,LDKeyClass:r,contextUrl:"https://www.w3.org/2018/credentials/v1",alg:t,signer:a,verifier:c,useProofValue:!0}),this.proof={"@context":[{sec:"https://w3id.org/security#",proof:{"@id":"sec:proof","@type":"@id","@container":"@graph"}},o],type:t},this.requireCredentialSchema=!0,this.verificationMethod=i,n&&(void 0===i&&(this.verificationMethod=n.id),this.key=n)}async createVerifyData(t){await e();let r,o;t.proof&&t.proof.proofValue?t.document.cryptoVersion?[r,o]=this.constructor.convertCredentialForVerification(t):[r,o]=this.constructor.convertCredential(t):[r,o]=await this.constructor.convertCredentialToSerializedForSigning(t);return o.encoder.encodeMessageObject(r,!1)[1]}static convertCredential({document:e,proof:t,signingOptions:r={requireAllFieldsFromSchema:!1}}){const[o]=this.getTrimmedProofAndValue(e,t),[i]=this.extractSchema(e),a=new this.CredentialBuilder;a.version="0.2.0",a.schema=i;const{cryptoVersion:n,credentialSchema:c,credentialSubject:s,credentialStatus:d,...l}={...e,proof:o};a.subject=s,a.credStatus=d,Object.keys(l).sort().forEach((e=>{a.setTopLevelField(e,l[e])})),a.setTopLevelField("@context",JSON.stringify(e["@context"])),a.setTopLevelField("type",JSON.stringify(e.type));const h=a.updateSchemaIfNeeded(r);if(e.credentialSchema){const t=h.credentialSchema;Object.assign(e.credentialSchema,"string"==typeof t?JSON.parse(t):t)}return[h,a.schema]}static convertCredentialForPresBuilding({document:e,proof:r}){const[o,i]=this.getTrimmedProofAndValue(e,r),[a,n]=this.extractSchema(e),c={...e,proof:o};this.revealMandatoryFields(c,e);const d=this.Credential.fromJSON(c,s.fromJsigProofValue(i));return n||(d.schema=t.generateAppropriateSchema(c,a)),d}static convertCredentialForVerification({document:e,proof:r}){const[o]=this.getTrimmedProofAndValue(e,r),i=this.extractSchema(e);let a=i[0];const c=i[1],s={...e,proof:o};this.revealMandatoryFields(s,e),c||(s.cryptoVersion="0.2.0",void 0===s.credentialSchema&&(s.credentialSchema=JSON.stringify(a.toJSON())),a=t.generateAppropriateSchema(s,a));const d=a.toJSON();return s.credentialSchema=c?n(d):JSON.stringify(d),e.credentialSchema&&Object.assign(e.credentialSchema,d),[s,a]}static async convertCredentialToSerializedForSigning({document:e,proof:r,documentLoader:o}){const[i]=this.getTrimmedProofAndValue(e,r),[a]=await this.extractSchemaForSigning(e,o),c=new this.CredentialBuilder;c.schema=a;const{credentialSchema:s,credentialSubject:d,credentialStatus:l,...h}={...e,proof:i};c.subject=d,c.credStatus=l,Object.keys(h).sort().forEach((e=>{c.setTopLevelField(e,h[e])})),c.setTopLevelField("@context",JSON.stringify(e["@context"])),c.setTopLevelField("type",JSON.stringify(e.type));const m=c.serializeForSigning();c.schema=t.generateAppropriateSchema(m,a);const f=c.schema.toJSON();return m.credentialSchema=n(f),Object.assign(e.credentialSchema,f),e.cryptoVersion=m.cryptoVersion,[m,c.schema]}static revealMandatoryFields(e,t){e["@context"]=JSON.stringify(t["@context"]),e.type=JSON.stringify(t.type)}static getTrimmedProofAndValue(e,t){const r=t||e.proof;if(r.type!==this.proofType[0])throw new Error(`Invalid \`proof.type\`, expected ${this.proofType[0]}, received ${r.type}`);const o={"@context":e["@context"]||i,...r},a=o.proofValue;return delete o.jws,delete o.signatureValue,delete o.proofValue,[o,a]}static async extractSchemaForSigning(e,o){let i,a=!0;if(e.credentialSchema&&e.credentialSchema.id){async function n(e){if(!e.startsWith("blob:dock:"))throw new Error(`Can only fetch schemas stored on Dock for now. Got schema id ${e}`);const{document:t}=await o(e);return t[1]}i=await t.fromJSONWithPotentiallyExternalSchema({parsingOptions:r,...e.credentialSchema},n)}else i=this.extractSchemaWhenIdNotSet(e),a=!1;return[i,a]}static extractSchema(e){let o,i=!0;return e.credentialSchema&&e.credentialSchema.id?o=t.fromJSON({parsingOptions:r,...e.credentialSchema}):(o=this.extractSchemaWhenIdNotSet(e),i=!1),[o,i]}static extractSchemaWhenIdNotSet(e){let r;return r=e.credentialSchema?new t(t.essential()):new t(t.essential(),{useDefaults:!1,defaultMinimumInteger:-(2**32-1),defaultDecimalPlaces:0},!1,{version:"0.0.1"}),r}static async getVerificationMethod({proof:e,documentLoader:t}){let{verificationMethod:r}=e;if("object"==typeof r&&(r=r.id),!r)throw new Error('No "verificationMethod" found in proof.');const a=await o.frame(r,{"@context":i,"@embed":"@always",id:r},{documentLoader:t,compactToRelative:!1,expandContext:i});if(!a)throw new Error(`Verification method ${r} not found.`);if(void 0!==a.revoked)throw new Error("The verification method has been revoked.");return a}async getVerificationMethod({proof:e,documentLoader:t}){return this.constructor.getVerificationMethod({proof:e,documentLoader:t})}static signerFactory(e,t){const{KeyPair:r}=this;return{id:t,async sign({data:t}){if(!e||!e.privateKeyBuffer)throw new Error("No private key to sign with.");const o=t.length,i=r.SignatureParams.getSigParamsOfRequiredSize(o,r.defaultLabelBytes),n=r.adaptKey(new r.SecretKey(a(e.privateKeyBuffer)),t.length);return r.Signature.generate(t,n,i).value}}}ensureSuiteContext(){}});export{d: DEFAULT_PARSING_OPTS,l: default} = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Node.js v18.17.0

Possible solution

https://github.com/docknetwork/sdk/blob/ebb8e86a43f2622bf769883b72ff85a326e68cbd/src/utils/vc/crypto/common/DockCryptoSignature.js

As per upstream docs, the recommended import should be:

// after: npm install @sphereon/rn-jsonld-signatures
import * as jsigs from '@sphereon/rn-jsonld-signatures';

// then you can access as follows
const myVal = jsigs.SECURITY_CONTEXT_URL || 'some other value'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant