{"version":3,"file":"DockCryptoSignature.cjs","sources":["../../../../../src/vc/crypto/common/DockCryptoSignature.js"],"sourcesContent":["import {\n  initializeWasm,\n  CredentialSchema,\n  DefaultSchemaParsingOpts,\n} from '@docknetwork/crypto-wasm-ts';\n\nimport jsigs from 'jsonld-signatures';\n\nimport stringify from 'json-stringify-deterministic';\nimport semver from 'semver/preload.js';\nimport { u8aToU8a } from '../../../utils/types/bytes';\nimport { withExtendedStaticProperties } from '../../../utils/inheritance';\nimport CustomLinkedDataSignature from './CustomLinkedDataSignature';\nimport { deepClone } from '../../../utils';\n\nconst SUITE_CONTEXT_URL = 'https://www.w3.org/2018/credentials/v1';\n\nexport const DEFAULT_PARSING_OPTS = {\n  useDefaults: false,\n};\n\n/**\n * Checks if given credential version is greater than or equal to 0.6.0. This version changed `credentialSchema` property\n * from data-uri to object and started using a deterministic JSON stringify for context and some other properties.\n * @param credVersion\n * @returns {boolean}\n */\nexport function isCredVerGte060(credVersion) {\n  return semver.gte(credVersion, '0.6.0');\n}\n\n/**\n * Defines commons for the `@docknetwork/crypto-wasm-ts` signatures.\n */\nexport default withExtendedStaticProperties(\n  ['KeyPair', 'CredentialBuilder', 'Credential', 'proofType'],\n  class DockCryptoSignature extends CustomLinkedDataSignature {\n    /**\n     * Default constructor\n     * @param options {SignatureSuiteOptions} options for constructing the signature suite\n     * @param type\n     * @param LDKeyClass\n     * @param url\n     */\n    constructor(options = {}, type, LDKeyClass, url) {\n      const {\n        verificationMethod, signer, keypair, verifier,\n      } = options;\n\n      super({\n        type,\n        LDKeyClass,\n        contextUrl: SUITE_CONTEXT_URL,\n        alg: type,\n        signer,\n        verifier,\n        useProofValue: true,\n      });\n\n      this.proof = {\n        '@context': [\n          {\n            sec: 'https://w3id.org/security#',\n            proof: {\n              '@id': 'sec:proof',\n              '@type': '@id',\n              '@container': '@graph',\n            },\n          },\n          url,\n        ],\n        type,\n      };\n\n      this.requireCredentialSchema = true;\n      this.verificationMethod = verificationMethod;\n      if (keypair) {\n        if (verificationMethod === undefined) {\n          this.verificationMethod = keypair.id;\n        }\n        this.key = keypair;\n      }\n    }\n\n    /** Create serialized credential for signing and verification\n     * @param {object} options - The options to use.\n     * @param {object} options.document - The document to be signed/verified.\n     * @param {object} options.proof - The proof to be verified.\n     * @param {function} options.documentLoader - The document loader to use.\n     * @param {function} options.expansionMap - NOT SUPPORTED; do not use.\n     *\n     * @returns {Promise<Uint8Array[]>}.\n     */\n    async createVerifyData(options) {\n      await initializeWasm();\n\n      // If this function is being called for credential verification or not\n      const forVerification = !!(options.proof && options.proof.proofValue);\n\n      let serializedCredential;\n      let credSchema;\n      if (forVerification) {\n        if (options.document.cryptoVersion) {\n          // Newer credentials will have cryptoVersion field set\n          [serializedCredential, credSchema] = this.constructor.convertCredentialForVerification(options);\n        } else {\n          // Legacy. Cannot use `convertCredentialForVerification` because JSON.stringify is not deterministic\n          // and credentialSchema string becomes different. See https://stackoverflow.com/a/43049877\n          [serializedCredential, credSchema] = this.constructor.convertLegacyCredential(options);\n        }\n      } else {\n        // Serialize the data for signing\n        [serializedCredential, credSchema] = await this.constructor.convertCredentialToSerializedForSigning(\n          options,\n        );\n      }\n\n      const useConstantTimeEncoder = semver.gte(credSchema.version, '0.5.0');\n      // Encode messages, retrieve names/values array\n      const nameValues = useConstantTimeEncoder\n        ? credSchema.encoder.encodeMessageObjectConstantTime(\n          serializedCredential,\n          false,\n        )\n        : credSchema.encoder.encodeMessageObject(serializedCredential, false);\n      return nameValues[1];\n    }\n\n    /**\n     * Convert given JSON-LD credential to TS-anoncred's credential. This would not have the signature.\n     * @param document - JSON-LD credential\n     * @param explicitProof\n     * @param signingOptions\n     * @returns {Array} - Returns [serialized cred object, cred schema]\n     */\n    static convertLegacyCredential({\n      document,\n      proof: explicitProof /* documentLoader */,\n      signingOptions = { requireAllFieldsFromSchema: false },\n    }) {\n      const [trimmedProof] = this.getTrimmedProofAndValue(\n        document,\n        explicitProof,\n      );\n\n      const [credSchema] = this.extractSchema(document);\n\n      const credBuilder = new this.CredentialBuilder();\n      // Set legacy version\n      credBuilder.version = '0.2.0';\n      credBuilder.schema = credSchema;\n\n      // Extract top level fields from the document aside from these\n      const {\n        cryptoVersion: _cryptoVersion,\n        credentialSchema: _credentialSchema,\n        credentialSubject,\n        credentialStatus,\n        ...topLevelFields\n      } = {\n        ...document,\n        proof: trimmedProof,\n      };\n      credBuilder.subject = credentialSubject;\n      credBuilder.credStatus = credentialStatus;\n\n      // Add all other top level fields to the credential\n      Object.keys(topLevelFields)\n        .sort()\n        .forEach((k) => {\n          credBuilder.setTopLevelField(k, topLevelFields[k]);\n        });\n\n      // To work with JSON-LD credentials/presentations, we must always reveal the context and type\n      // NOTE: that they are encoded as JSON strings here to reduce message count and so its *always known*\n      credBuilder.setTopLevelField(\n        '@context',\n        JSON.stringify(document['@context']),\n      );\n      credBuilder.setTopLevelField('type', JSON.stringify(document.type));\n\n      // Allow for relaxed schema generation, then embed the generated schema directly into the credential\n      const builtAnoncreds = credBuilder.updateSchemaIfNeededLegacy(signingOptions);\n\n      // Re-assign the embedded schema to the document schema object\n      // this is a bit hacky, but its the only way right now\n      if (document.credentialSchema) {\n        const fullSchema = builtAnoncreds.credentialSchema;\n        Object.assign(\n          document.credentialSchema,\n          typeof fullSchema === 'string' ? JSON.parse(fullSchema) : fullSchema,\n        );\n      }\n\n      // Return the built anoncreds credential and the schema associated\n      return [builtAnoncreds, credBuilder.schema];\n    }\n\n    /**\n     * Convert given JSON-LD credential to TS-anoncred's credential for adding to a presentation. This would have the signature.\n     * @param document - JSON-LD credential\n     * @param explicitProof\n     * @returns {Credential}\n     */\n    static convertCredentialForPresBuilding({\n      document,\n      proof: explicitProof /* documentLoader */,\n    }) {\n      const [trimmedProof, proofVal] = this.getTrimmedProofAndValue(\n        document,\n        explicitProof,\n      );\n\n      const [credSchema, wasExactSchema] = this.extractSchema(document);\n\n      const credJson = {\n        ...document,\n        proof: trimmedProof,\n      };\n\n      // Old credentials don't include the version number but it was set while signing. So add it here if missing.\n      if (credJson.cryptoVersion === undefined) {\n        credJson.cryptoVersion = '0.2.0';\n      }\n\n      this.formatMandatoryFields(credJson, document);\n      const cred = this.Credential.fromJSON(\n        credJson,\n        CustomLinkedDataSignature.fromJsigProofValue(proofVal),\n      );\n      if (!wasExactSchema) {\n        cred.schema = CredentialSchema.generateAppropriateSchema(\n          credJson,\n          credSchema,\n        );\n      }\n\n      return cred;\n    }\n\n    /**\n     * Convert given JSON-LD credential to TS-anoncred's credential. This would have the signature.\n     * @param document - JSON-LD credential\n     * @param explicitProof\n     * @returns {Array}\n     */\n    static convertCredentialForVerification({\n      document,\n      proof: explicitProof /* documentLoader */,\n    }) {\n      const [trimmedProof] = this.getTrimmedProofAndValue(\n        document,\n        explicitProof,\n      );\n\n      const s = this.extractSchema(document);\n      let credSchema = s[0];\n      const wasExactSchema = s[1];\n\n      const credJson = {\n        ...document,\n        proof: trimmedProof,\n      };\n      this.formatMandatoryFields(credJson, document);\n      if (!wasExactSchema) {\n        // Older credentials didn't include the version field in the final credential but they did while signing\n        credJson.cryptoVersion = '0.2.0';\n        if (credJson.credentialSchema === undefined) {\n          credJson.credentialSchema = JSON.stringify(credSchema.toJSON());\n        }\n        credSchema = CredentialSchema.generateAppropriateSchema(\n          credJson,\n          credSchema,\n        );\n      }\n      const schemaJson = semver.gte(credSchema.version, '0.4.0')\n        ? credSchema.toJSON()\n        : credSchema.toJSONOlder();\n      if (credJson.cryptoVersion && isCredVerGte060(credJson.cryptoVersion)) {\n        credJson.credentialSchema = schemaJson;\n      } else {\n        // Older versions used JSON.stringify but newer use deterministic conversion\n        credJson.credentialSchema = wasExactSchema\n          ? stringify(schemaJson)\n          : JSON.stringify(schemaJson);\n      }\n\n      if (document.credentialSchema) {\n        Object.assign(document.credentialSchema, schemaJson);\n      }\n\n      return [credJson, credSchema];\n    }\n\n    /**\n     * Convert given JSON-LD credential to TS-anoncred's credential. This would not have the signature.\n     * @param document - JSON-LD credential\n     * @param explicitProof\n     * @returns {Promise<Array>}\n     */\n    static async convertCredentialToSerializedForSigning({\n      document,\n      proof,\n      documentLoader,\n    }) {\n      const [trimmedProof] = this.getTrimmedProofAndValue(document, proof);\n\n      const [credSchema] = await this.extractSchemaForSigning(\n        document,\n        documentLoader,\n      );\n\n      const credBuilder = new this.CredentialBuilder();\n      credBuilder.schema = credSchema;\n\n      // Extract top level fields from the document aside from these\n      const {\n        credentialSchema: _credentialSchema,\n        credentialSubject,\n        credentialStatus,\n        ...topLevelFields\n      } = {\n        ...document,\n        proof: trimmedProof,\n      };\n      credBuilder.subject = credentialSubject;\n      credBuilder.credStatus = credentialStatus;\n\n      // Add all other top level fields to the credential\n      Object.keys(topLevelFields)\n        .sort()\n        .forEach((k) => {\n          credBuilder.setTopLevelField(k, topLevelFields[k]);\n        });\n\n      // To work with JSON-LD credentials/presentations, we must always reveal the context and type\n      // NOTE: that they are encoded as JSON strings here to reduce message count and so its *always known*\n      credBuilder.setTopLevelField('@context', stringify(document['@context']));\n      credBuilder.setTopLevelField('type', stringify(document.type));\n\n      const serializedCred = credBuilder.serializeForSigning();\n\n      credBuilder.schema = CredentialSchema.generateAppropriateSchema(\n        serializedCred,\n        credSchema,\n      );\n\n      // Update `document` so that generated credential has `credentialSchema` and `cryptoVersion` set\n      const updatedSchemaJson = credBuilder.schema.toJSON();\n      serializedCred.credentialSchema = updatedSchemaJson;\n      Object.assign(document.credentialSchema, updatedSchemaJson);\n      // eslint-disable-next-line no-param-reassign\n      document.cryptoVersion = serializedCred.cryptoVersion;\n\n      return [serializedCred, credBuilder.schema];\n    }\n\n    /**\n     * To work with JSON-LD credentials/presentations, we must always reveal the context, type\n     * @param credJson\n     * @param document\n     */\n    static formatMandatoryFields(credJson, document) {\n      // NOTE: that they are encoded as JSON strings here to reduce message count and so its *always known*\n      const newVersion = credJson.cryptoVersion && isCredVerGte060(credJson.cryptoVersion);\n      // eslint-disable-next-line no-param-reassign\n      credJson['@context'] = newVersion\n        ? stringify(document['@context'])\n        : JSON.stringify(document['@context']);\n      // eslint-disable-next-line no-param-reassign\n      credJson.type = newVersion\n        ? stringify(document.type)\n        : JSON.stringify(document.type);\n    }\n\n    /**\n     * Remove actual value of proof (signature) from the object and return the trimmed object and the proof value\n     * @param document\n     * @param explicitProof\n     * @returns {Array}\n     */\n    static getTrimmedProofAndValue(document, explicitProof) {\n      const proof = explicitProof || document.proof;\n      if (proof.type !== this.proofType[0]) {\n        throw new Error(\n          `Invalid \\`proof.type\\`, expected ${this.proofType[0]}, received ${proof.type}`,\n        );\n      }\n      // `jws`,`signatureValue`,`proofValue` must not be included in the proof\n      const trimmedProof = {\n        '@context': document['@context'] || jsigs.SECURITY_CONTEXT_URL,\n        ...proof,\n      };\n\n      const proofVal = trimmedProof.proofValue;\n\n      delete trimmedProof.jws;\n      delete trimmedProof.signatureValue;\n      delete trimmedProof.proofValue;\n      return [trimmedProof, proofVal];\n    }\n\n    /**\n     * Extract schema from the document and load the schema from its id/reference if needed.\n     * @param document\n     * @param documentLoader\n     * @returns {Promise<Array>}\n     */\n    static async extractSchemaForSigning(document, documentLoader) {\n      let credSchema;\n      // Should be false for legacy cases or when the schema is generated by CredentialBuilder\n      let wasExactSchema = true;\n\n      if (document.credentialSchema && document.credentialSchema.id) {\n        /**\n         * Fetch a schema given a schema id. Currenly only fetching it from Dock blockchain\n         * @param schemaId\n         * @returns {Promise<Object>}\n         */\n        // eslint-disable-next-line no-inner-declarations\n        async function getSchema(schemaId) {\n          const { document: schema } = await documentLoader(schemaId);\n          // schema[0] is the schema/blob id if stored on chain\n          if (schemaId.startsWith('blob:dock:')) {\n            return schema[1];\n          }\n          return schema;\n        }\n\n        const schemaJson = deepClone(document.credentialSchema);\n        // Passing all the default parsing options. Ideally `document.credentialSchema` should contain these\n        if (schemaJson.details === undefined) {\n          schemaJson.details = stringify({\n            parsingOptions: DefaultSchemaParsingOpts,\n          });\n        } else {\n          const details = JSON.parse(schemaJson.details);\n          details.parsingOptions = {\n            ...DefaultSchemaParsingOpts,\n            ...details.parsingOptions,\n          };\n          schemaJson.details = stringify(details);\n        }\n        // If we already have a schema to use, add that first and then generate relaxed values later on\n        credSchema = await CredentialSchema.fromJSONWithPotentiallyExternalSchema(\n          schemaJson,\n          getSchema,\n        );\n      } else {\n        credSchema = this.extractSchemaWhenIdNotSet(document);\n        wasExactSchema = false;\n      }\n      return [credSchema, wasExactSchema];\n    }\n\n    static extractSchema(document) {\n      let credSchema;\n      // Should be false for legacy cases\n      let wasExactSchema = true;\n\n      if (document.credentialSchema && document.credentialSchema.id) {\n        // If we already have a schema to use, add that first and then generate relaxed values later on\n        credSchema = CredentialSchema.fromJSON({\n          // Passing all the default parsing options. Ideally `document.credentialSchema` should contain these\n          parsingOptions: DefaultSchemaParsingOpts,\n          ...document.credentialSchema,\n        });\n      } else {\n        credSchema = this.extractSchemaWhenIdNotSet(document);\n        wasExactSchema = false;\n      }\n      return [credSchema, wasExactSchema];\n    }\n\n    static extractSchemaWhenIdNotSet(document) {\n      let credSchema;\n      if (document.credentialSchema) {\n        // schema object exists but no ID means the SDK is signalling for the suite to generate a schema\n        credSchema = new CredentialSchema(\n          CredentialSchema.essential(),\n          this.getParsingOptions(document),\n        );\n      } else {\n        // Else, no schema was found so just use the essentials and v0.0.1 schema version\n        // NOTE: version is important here and MUST be 0.0.1 otherwise it will invalidate BBS+ credentials\n        // that were issued before a change. This is required because the version value is not known in credentials\n        // where no credentialSchema object is defined\n        credSchema = new CredentialSchema(\n          CredentialSchema.essential(),\n          // Passing old parsing options and version\n          {\n            useDefaults: false,\n            defaultMinimumInteger: -(2 ** 32 - 1),\n            defaultDecimalPlaces: 0,\n          },\n          false,\n          { version: '0.0.1' },\n          undefined,\n          false,\n        );\n      }\n\n      return credSchema;\n    }\n\n    static getParsingOptions(document) {\n      if (\n        document.credentialSchema\n        && document.credentialSchema.details !== undefined\n      ) {\n        const details = JSON.parse(document.credentialSchema.details);\n        return details.parsingOptions;\n      }\n      return DefaultSchemaParsingOpts;\n    }\n\n    static withUpdatedParsingOptions(schemaJson, parsingOptions) {\n      const newSchemaJson = deepClone(schemaJson);\n      if (schemaJson.details === undefined) {\n        newSchemaJson.details = stringify({ parsingOptions });\n      } else {\n        const details = JSON.parse(schemaJson.details);\n        details.parsingOptions = {\n          ...details.parsingOptions,\n          ...parsingOptions,\n        };\n        newSchemaJson.details = stringify(details);\n      }\n      return newSchemaJson;\n    }\n\n    /**\n     * Generate object with `sign` method\n     * @param keypair\n     * @param verificationMethod\n     * @returns {object}\n     */\n    static signerFactory(keypair, verificationMethod) {\n      const { KeyPair } = this;\n      const paramGetter = this.paramGenerator;\n\n      return {\n        id: verificationMethod,\n        async sign({ data }) {\n          if (!keypair || !keypair.privateKeyBuffer) {\n            throw new Error('No private key to sign with.');\n          }\n\n          const msgCount = data.length;\n          const sigParams = paramGetter(msgCount, KeyPair.defaultLabelBytes);\n          const sk = KeyPair.adaptKey(\n            new KeyPair.SecretKey(u8aToU8a(keypair.privateKeyBuffer)),\n            data.length,\n          );\n          const signature = KeyPair.Signature.generate(data, sk, sigParams);\n          return signature.value;\n        },\n      };\n    }\n\n    static get paramGenerator() {\n      return this.KeyPair.SignatureParams.getSigParamsOfRequiredSize;\n    }\n\n    ensureSuiteContext() {\n      // no-op\n    }\n  },\n);\n"],"names":["semver","withExtendedStaticProperties","CustomLinkedDataSignature","initializeWasm","CredentialSchema","stringify","jsigs","deepClone","DefaultSchemaParsingOpts","u8aToU8a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,iBAAiB,GAAG,wCAAwC;;AAEtD,MAAC,oBAAoB,GAAG;AACpC,EAAE,WAAW,EAAE,KAAK;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,eAAe,CAAC,WAAW,EAAE;AAC7C,EAAE,OAAOA,uBAAM,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC;AACzC;;AAEA;AACA;AACA;AACA,0BAAeC,kCAA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