wallet/walletEccKeyPairsGenerate.js
/**
 * Links with the Hyperledger Fabric X509 certificate and writes the OpenPGP wallet to the file system.
 * @param {JSON} certificate Data containing the OpenPGP certificate template
 */
Links with the Hyperledger Fabric X509 certificate and writes the OpenPGP wallet to the file system.
@param {JSON} certificate Data containing the OpenPGP certificate template
Links with the Hyperledger Fabric X509 certificate and writes the OpenPGP wallet to the file system . @param { JSON } certificate Data containing the OpenPGP certificate template
async function writeKeysToFile(certificate) {
  var fileDirPath = undefined;
  try {
    let orgDir = './' + certificate.userId.organization;
    orgDir = orgDir.toLowerCase();
    if (!fs.existsSync(orgDir)) {
      fs.mkdirSync(orgDir);
    }
    let personaDir = orgDir + '/' + certificate.userId.name;
    personaDir = personaDir.toLowerCase();
    if (!fs.existsSync(personaDir)) {
      fs.mkdirSync(personaDir);
    }
    let identity = undefined;
    let identityLabel = undefined;
    let identityMSP = undefined;
    let certPemTemp = undefined;
    let keyStoreDir = undefined;
    if (certificate.userId.MSP == GuaraniMSP) {
      identityMSP = GuaraniMSP;
      if (certificate.userId.type == userType.simple) {
        identityLabel = User2GuaraniIdentityLabel;
        certPemTemp = User2GuaraniMspCertPem.toString();
        keyStoreDir = User2GuaraniMspKeyStoreDir.toString();
      } else if (certificate.userId.type == userType.validator) {
        identityLabel = User1GuaraniIdentityLabel;
        certPemTemp = User1GuaraniMspCertPem.toString();
        keyStoreDir = User1GuaraniMspKeyStoreDir.toString();
      } else {
        identityLabel = AdminGuaraniIdentityLabel;
        certPemTemp = AdminGuaraniMspCertPem.toString();
        keyStoreDir = AdminGuaraniMspKeyStoreDir.toString();
      }
    } else if (certificate.userId.MSP == TiccunaMSP) {
      identityMSP = TiccunaMSP;
      if (certificate.userId.type == userType.simple) {
        identityLabel = User2TiccunaIdentityLabel;
        certPemTemp = User2TiccunaMspCertPem.toString();
        keyStoreDir = User2TiccunaMspKeyStoreDir.toString();
      } else if (certificate.userId.type == userType.validator) {
        identityLabel = User1TiccunaIdentityLabel;
        certPemTemp = User1TiccunaMspCertPem.toString();
        keyStoreDir = User1TiccunaMspKeyStoreDir.toString();
      } else {
        identityLabel = AdminTiccunaIdentityLabel;
        certPemTemp = AdminTiccunaMspCertPem.toString();
        keyStoreDir = AdminTiccunaMspKeyStoreDir.toString();
      }
    } else if (certificate.userId.MSP == XavanteMSP) {
      identityMSP = XavanteMSP;
      if (certificate.userId.type == userType.simple) {
        identityLabel = User2XavanteIdentityLabel;
        certPemTemp = User2XavanteMspCertPem.toString();
        keyStoreDir = User2XavanteMspKeyStoreDir.toString();
      } else if (certificate.userId.type == userType.validator) {
        identityLabel = User1XavanteIdentityLabel;
        certPemTemp = User1XavanteMspCertPem.toString();
        keyStoreDir = User1XavanteMspKeyStoreDir.toString();
      } else {
        identityLabel = AdminXavanteIdentityLabel;
        certPemTemp = AdminXavanteMspCertPem.toString();
        keyStoreDir = AdminXavanteMspKeyStoreDir.toString();
      }
    }
    certificate.userId.type = undefined;
    let cert = fs.readFileSync(certPemTemp).toString();
    let keystore = fs.readFileSync(getMspKeyPath(keyStoreDir)).toString();
    let wallet = new FileSystemWallet(personaDir.toString());
    identity = X509WalletMixin.createIdentity(identityMSP, cert, keystore);
    certificate.userId.X509 = identityLabel;
    await wallet.import(identityLabel, identity);
    fileDirPath = personaDir + '/' + prefixWallet + certificate.userId.email + fileExt;
    fileDirPath = fileDirPath.toLowerCase();
  } catch (error) {
    console.log(error);
    console.log(error.stack);
    throw error.toString();
  }
  await openpgp.generateKey({
    userIds: certificate.userId,
    curve: ECDHTYPE,
    passphrase: certificate.passphrase
  }).then(function (key) {
    certificate.keys.publicArmored = key.publicKeyArmored;
    certificate.keys.privateArmored = key.privateKeyArmored;
    certificate.keys.revocationCertificate = key.revocationCertificate;
  }).then(function () {
    let content = Buffer.from(JSON.stringify(certificate));
    fs.writeFileSync(fileDirPath, content.toString(), utf8);
    return certificate;
  }).catch((e) => {
    console.log(e);
    console.log(e.stack);
    throw e.toString();
  });
}
async function writeKeysToFile ( certificate ) { var fileDirPath = undefined ; try { let orgDir = './' + certificate . userId . organization ; orgDir = orgDir . toLowerCase ( ) ; if ( ! fs . existsSync ( orgDir ) ) { fs . mkdirSync ( orgDir ) ; } let personaDir = orgDir + '/' + certificate . userId . name ; personaDir = personaDir . toLowerCase ( ) ; if ( ! fs . existsSync ( personaDir ) ) { fs . mkdirSync ( personaDir ) ; } let identity = undefined ; let identityLabel = undefined ; let identityMSP = undefined ; let certPemTemp = undefined ; let keyStoreDir = undefined ; if ( certificate . userId . MSP == GuaraniMSP ) { identityMSP = GuaraniMSP ; if ( certificate . userId . type == userType . simple ) { identityLabel = User2GuaraniIdentityLabel ; certPemTemp = User2GuaraniMspCertPem . toString ( ) ; keyStoreDir = User2GuaraniMspKeyStoreDir . toString ( ) ; } else if ( certificate . userId . type == userType . validator ) { identityLabel = User1GuaraniIdentityLabel ; certPemTemp = User1GuaraniMspCertPem . toString ( ) ; keyStoreDir = User1GuaraniMspKeyStoreDir . toString ( ) ; } else { identityLabel = AdminGuaraniIdentityLabel ; certPemTemp = AdminGuaraniMspCertPem . toString ( ) ; keyStoreDir = AdminGuaraniMspKeyStoreDir . toString ( ) ; } } else if ( certificate . userId . MSP == TiccunaMSP ) { identityMSP = TiccunaMSP ; if ( certificate . userId . type == userType . simple ) { identityLabel = User2TiccunaIdentityLabel ; certPemTemp = User2TiccunaMspCertPem . toString ( ) ; keyStoreDir = User2TiccunaMspKeyStoreDir . toString ( ) ; } else if ( certificate . userId . type == userType . validator ) { identityLabel = User1TiccunaIdentityLabel ; certPemTemp = User1TiccunaMspCertPem . toString ( ) ; keyStoreDir = User1TiccunaMspKeyStoreDir . toString ( ) ; } else { identityLabel = AdminTiccunaIdentityLabel ; certPemTemp = AdminTiccunaMspCertPem . toString ( ) ; keyStoreDir = AdminTiccunaMspKeyStoreDir . toString ( ) ; } } else if ( certificate . userId . MSP == XavanteMSP ) { identityMSP = XavanteMSP ; if ( certificate . userId . type == userType . simple ) { identityLabel = User2XavanteIdentityLabel ; certPemTemp = User2XavanteMspCertPem . toString ( ) ; keyStoreDir = User2XavanteMspKeyStoreDir . toString ( ) ; } else if ( certificate . userId . type == userType . validator ) { identityLabel = User1XavanteIdentityLabel ; certPemTemp = User1XavanteMspCertPem . toString ( ) ; keyStoreDir = User1XavanteMspKeyStoreDir . toString ( ) ; } else { identityLabel = AdminXavanteIdentityLabel ; certPemTemp = AdminXavanteMspCertPem . toString ( ) ; keyStoreDir = AdminXavanteMspKeyStoreDir . toString ( ) ; } } certificate . userId . type = undefined ; let cert = fs . readFileSync ( certPemTemp ) . toString ( ) ; let keystore = fs . readFileSync ( getMspKeyPath ( keyStoreDir ) ) . toString ( ) ; let wallet = new FileSystemWallet ( personaDir . toString ( ) ) ; identity = X509WalletMixin . createIdentity ( identityMSP , cert , keystore ) ; certificate . userId . X509 = identityLabel ; await wallet . import ( identityLabel , identity ) ; fileDirPath = personaDir + '/' + prefixWallet + certificate . userId . email + fileExt ; fileDirPath = fileDirPath . toLowerCase ( ) ; } catch ( error ) { console . log ( error ) ; console . log ( error . stack ) ; throw error . toString ( ) ; } await openpgp . generateKey ( { userIds : certificate . userId , curve : ECDHTYPE , passphrase : certificate . passphrase } ) . then ( function ( key ) { certificate . keys . publicArmored = key . publicKeyArmored ; certificate . keys . privateArmored = key . privateKeyArmored ; certificate . keys . revocationCertificate = key . revocationCertificate ; } ) . then ( function ( ) { let content = Buffer . from ( JSON . stringify ( certificate ) ) ; fs . writeFileSync ( fileDirPath , content . toString ( ) , utf8 ) ; return certificate ; } ) . catch ( ( e ) => { console . log ( e ) ; console . log ( e . stack ) ; throw e . toString ( ) ; } ) ; }
Links with the Hyperledger Fabric X509 certificate and writes the OpenPGP wallet to the file system.
Links with the Hyperledger Fabric X509 certificate and writes the OpenPGP wallet to the file system .
// console.log(logPrefix + " [writeKeysToFile]  certificate JSON: " + JSON.stringify(certificate)); // Remove temporary user type configuration // A wallet to store a collection of Fabric identities // Add X.509 designation to the certificate // Load credentials into wallet /**
   * Generates asymmetric encryption keys, based on the elliptical curve algorithm
   */ // certificate.keys.created = key.key.keyPacket.created;