6. addSignature
基本信息
- 接口名称:com.webank.weid.rpc.CredentialService.addSignature
- 接口定义:ResponseData<Credential> addSignature(List<Credential> credentialList, WeIdPrivateKey weIdPrivateKey)
- 接口描述:多签,在原凭证列表的基础上,创建包裹成一个新的多签凭证,由传入的私钥所签名。此凭证的CPT为一个固定值。在验证一个多签凭证时,会迭代验证其包裹的所有子凭证。本接口不支持创建选择性披露的多签凭证。
接口入参: java.util.ArrayList
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
com.webank.weid.protocol.base.WeIdPrivateKey
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
privateKey | String | Y | 私钥值 | 使用十进制数字表示 |
接口返回: com.webank.weid.protocol.response.ResponseData<Credential>;
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
errorCode | Integer | 返回结果码 | |
errorMessage | String | 返回结果描述 | |
result | Credential | 见下 | |
transactionInfo | TransactionInfo | 交易信息 |
com.webank.weid.protocol.response.TransactionInfo
名称 | 类型 | 说明 | 备注 |
---|---|---|---|
blockNumber | BigInteger | 交易块高 | |
transactionHash | String | 交易hash | |
transactionIndex | BigInteger | 交易索引 |
com.webank.weid.protocol.base.Credential
名称 | 类型 | 非空 | 说明 | 备注 |
---|---|---|---|---|
context | String | Y | 版本 | 默认为v1 |
id | String | Y | 证书ID | |
cptId | Integer | Y | cptId | 默认为106 |
issuer | String | Y | WeIdentity DID | |
issuanceDate | Long | Y | 创建日期 | |
expirationDate | Long | Y | 到期日期 | |
claim | Map<String, Object> | Y | Claim数据 | |
proof | Map<String, Object> | Y | 签名数据结构体 |
此方法返回code
enum | code | desc |
---|---|---|
SUCCESS | 0 | 成功 |
CPT_JSON_SCHEMA_INVALID | 100301 | JsonSchema无效 |
CPT_ID_ILLEGAL | 100303 | cptId无效 |
CREDENTIAL_ERROR | 100400 | Credential标准错误 |
CREDENTIAL_CREATE_DATE_ILLEGAL | 100408 | 创建日期格式非法 |
CREDENTIAL_EXPIRE_DATE_ILLEGAL | 100409 | 到期日期无效 |
CREDENTIAL_CLAIM_NOT_EXISTS | 100410 | Claim数据不能为空 |
CREDENTIAL_CLAIM_DATA_ILLEGAL | 100411 | Claim数据无效 |
CREDENTIAL_PRIVATE_KEY_NOT_EXISTS | 100415 | 私钥为空 |
CREDENTIAL_ISSUER_INVALID | 100418 | WeIdentity DID无效 |
ILLEGAL_INPUT | 160004 | 参数为空 |
调用示例
- CredentialService credentialService = new CredentialServiceImpl();
- HashMap<String, Object> claim = new HashMap<String, Object>(3);
- claim.put("name", "zhang san");
- claim.put("gender", "F");
- claim.put("age", 18);
- CreateCredentialArgs createCredentialArgs = new CreateCredentialArgs();
- createCredentialArgs.setClaim(claim);
- createCredentialArgs.setCptId(1017);
- createCredentialArgs.setExpirationDate(1551448312461L);
- createCredentialArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- createCredentialArgs.setWeIdPrivateKey(weIdPrivateKey);
- ResponseData<CredentialWrapper> response = credentialService.createCredential(createCredentialArgs);
- List<Credential> credList = new ArrayList<>();
- credList.add(response.getResult().getCredential());
- Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
- createCredentialArgs.getExpirationDate() + 24 * 60 * 60);
- createCredentialArgs.setExpirationDate(expirationDate);
- Credential tempCredential =
- credentialService.createCredential(createCredentialArgs).getResult().getCredential();
- credentialList.add(tempCredential);
- ResponseData<Credential> multiSignedResp = credentialService.addSignature(credList, weIdPrivateKey);
- System.out.println(multiSignedResp);
- 返回结果如:
- result:(com.webank.weid.protocol.base.CredentialWrapper)
- credential:(com.webank.weid.protocol.base.Credential) {
- "claim": {
- "credentialList": [
- {
- "claim": {
- "age": 18,
- "gender": "F",
- "id": "did:weid:101:0xe4bee5a07f282ffd3109699e21663cde0210fb64",
- "name": "zhang san"
- },
- "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
- "cptId": 2000084,
- "expirationDate": 1567488114,
- "id": "a8b1c030-231d-49de-9618-b5ed7f3e6d2e",
- "issuanceDate": 1567401714,
- "issuer": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
- "proof": {
- "created": "1567401714",
- "creator": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
- "signature": "GwKcDoEseYdJxI7M\/R4RAdGcV5SJoFVvg8Z53BVa76LMV8eqbX3F4rb1dWjhqI286AvPECx6uuuo9cTAKuNHRXM=",
- "type": "Secp256k1"
- }
- },
- {
- "claim": {
- "age": 18,
- "gender": "F",
- "id": "did:weid:101:0xe4bee5a07f282ffd3109699e21663cde0210fb64",
- "name": "zhang san"
- },
- "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
- "cptId": 2000084,
- "expirationDate": 1567488201,
- "id": "2130908d-fb2a-4675-8bf1-727f354ca8e4",
- "issuanceDate": 1567401715,
- "issuer": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
- "proof": {
- "created": "1567401715",
- "creator": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
- "signature": "HJXDuvg2l8jRbL5ymmBSAo\/6DMKbCv3P1XoP67S+OVzSbRVDNFXY1CsqpTqT5MAkSY4+UwPLwCfXrLtHsZQ6GOo=",
- "type": "Secp256k1"
- }
- }
- ]
- },
- "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
- "cptId": 106,
- "expirationDate": 1567488201,
- "id": "d8642623-703f-447a-8765-dab1dab4df0a",
- "issuanceDate": 1567401717,
- "issuer": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
- "proof": {
- "created": "1567401717",
- "creator": "did:weid:1:0x92d5472954c38375371f8bdd2bcce2e64aab1f99",
- "signature": "HKXEwzDEwqte4aAUBLvQjiI3C0cw5V\/iWeKWmBs7HIG0IRzgbXnMj8kYw37y5yJE4KdsWCuehBUGuW7WdihL560=",
- "type": "Secp256k1"
- }
- }
- errorCode: 0
- errorMessage: success
- transactionInfo:null
时序图
sequenceDiagramparticipant 调用者participant CredentialService调用者->>CredentialService: 调用addSignature()CredentialService->>CredentialService: 入参非空、格式及合法性检查opt 入参校验失败CredentialService—>>调用者: 报错,提示参数不合法并退出endCredentialService->>CredentialService: 生成签发日期、以原凭证列表为Claim生成数字签名CredentialService—>>调用者: 返回凭证