7. setAuthentication

基本信息

  1. 接口名称:com.webank.weid.rpc.WeIdService.setAuthentication
  2. 接口定义:ResponseData<Boolean> setAuthentication(SetAuthenticationArgs setAuthenticationArgs)
  3. 接口描述: 根据WeIdentity DID添加认证者。

接口入参: com.webank.weid.protocol.request.SetAuthenticationArgs

名称类型非空说明备注
weIdStringYWeIdentity DID格式字符串如:did:weid:101:0x….
ownerStringN所有者默认为当前WeIdentity DID
publicKeyStringY数字公钥
userWeIdPrivateKeyWeIdPrivateKeyY 交易私钥,后期鉴权使用,见下

com.webank.weid.protocol.base.WeIdPrivateKey

名称类型说明备注
privateKeyString私钥使用十进制数字表示

接口返回: com.webank.weid.protocol.response.ResponseData<Boolean>;

名称类型说明备注
errorCodeInteger返回结果码
errorMessageString返回结果描述
resultBoolean是否set成功
transactionInfoTransactionInfo交易信息

com.webank.weid.protocol.response.TransactionInfo

名称类型说明备注
blockNumberBigInteger交易块高
transactionHashString交易hash
transactionIndexBigInteger交易索引

此方法返回code

enumcodedesc
SUCCESS0成功
WEID_INVALID100101无效的WeIdentity DID
WEID_PRIVATEKEY_INVALID100103私钥格式非法
WEID_PRIVATEKEY_DOES_NOT_MATCH100106私钥不与WeIdentity DID所对应
TRANSACTION_TIMEOUT160001超时
TRANSACTION_EXECUTE_ERROR160002交易错误
UNKNOW_ERROR160003其他错误
ILLEGAL_INPUT160004参数为空

调用示例

  1. WeIdService weIdService = new WeIdServiceImpl();
  2.  
  3. SetAuthenticationArgs setAuthenticationArgs = new SetAuthenticationArgs();
  4. setAuthenticationArgs.setWeId("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
  5. setAuthenticationArgs.setPublicKey(
  6. "13161444623157635919577071263152435729269604287924587017945158373362984739390835280704888860812486081963832887336483721952914804189509503053687001123007342");
  7.  
  8. WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
  9. weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
  10.  
  11. setAuthenticationArgs.setUserWeIdPrivateKey(weIdPrivateKey);
  12.  
  13. ResponseData<Boolean> response = weIdService.setAuthentication(setAuthenticationArgs);
  1. 返回结果如下:
  2. result: true
  3. errorCode: 0
  4. errorMessage: success
  5. transactionInfo:(com.webank.weid.protocol.response.TransactionInfo)
  6. blockNumber: 30013
  7. transactionHash: 0xfbf8338e7df2af0612eca5107c0d2ed75dfd7a795988687f49c010112678f847
  8. transactionIndex: 0

时序图

sequenceDiagramNote over 调用者:传入自己的WeIdentity DID及用作authentication的公私钥调用者->>WeIdentity SDK : 调用setAuthentication来添加认证。WeIdentity SDK->>WeIdentity SDK:拿私钥来重新加载合约对象WeIdentity SDK->>区块链节点: 调用智能合约区块链节点->>区块链节点: 检查调用者的身份是否和WeIdentity DID匹配opt 身份校验不通过区块链节点—>>WeIdentity SDK:报错,提示私钥不匹配并退出WeIdentity SDK—>>调用者:报错退出end区块链节点->>区块链节点:将authentication和WeIdentity DID以及上次记录的块高写到属性事件中区块链节点->>区块链节点:记录最新块高区块链节点—>>WeIdentity SDK:返回WeIdentity SDK—>>调用者:返回调用结果