DagX的“KYC认证”实现

认证接入阿里云ocr和公安部数据进行认证。

DagX暂时提供免费的认证功能,并且云端并不会保存用户身份证图片。

具体流程请查看认证操作流程

DagX的“KYC认证”实现_第1张图片

向网络广播消息


let objMessage = {
  app:"attestation",
  payload_location:"inline",
  payload_hash:objectHash.getBase64Hash(attestation),
  payload: attestation
};

payload为认证信息,私有认证信息经过sha256加密,如下:

定义认证字段


var profile = {
  姓名: rows[0].name,
  性别: rows[0].sex,
  民族: rows[0].nationality,
  身份证: rows[0].idnum,
  出生日期:rows[0].birth,
  住址: rows[0].address
};

加密信息


let composer = require('bng-core/composer.js');
let hidden_profile = {};
let src_profile = {};
for (let field in profile) {
  let value = profile[field];
  let blinding =composer.generateBlinding();
  let hidden_value =objectHash.getBase64Hash([value,blinding]);
  hidden_profile[field] =hidden_value;
  src_profile[field] = [value,blinding];
}
let profile_hash =objectHash.getBase64Hash(hidden_profile);
let user_id =getUserId(profile);
let public_profile = {
  profile_hash:profile_hash,
  user_id:user_id
};
let attestation = {
  address: address,
  profile:public_profile
};
return [attestation,src_profile];

将认证信息发送给用户,让用户保存:


let private_profile = {
  unit: unit,
  payload_hash:objectHash.getBase64Hash(attestation),
  src_profile:src_profile
};
let base64PrivateProfile=Buffer.from(JSON.stringify(private_profile)).toString('base64');
text ="点击保存认证信息: [private profile](profile:" +base64PrivateProfile +") ";

byteball attested private profiles

你可能感兴趣的:(DagX的“KYC认证”实现)