8. addSignature
基本信息
- 接口名称:com.webank.weid.rpc.CredentialPojoService.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 | 参数为空 |
调用示例
- CredentialPojoService credentialPojoService = new CredentialPojoServiceImpl();
- HashMap<String, Object> claim = new HashMap<String, Object>(3);
- claim.put("name", "zhang san");
- claim.put("gender", "F");
- claim.put("age", 18);
- CreateCredentialPojoArgs createCredentialPojoArgs = new CreateCredentialPojoArgs();
- createCredentialPojoArgs.setClaim(claim);
- createCredentialPojoArgs.setCptId(1017);
- createCredentialPojoArgs.setExpirationDate(1551448312461L);
- createCredentialPojoArgs.setIssuer("did:weid:101:0x39e5e6f663ef77409144014ceb063713b65600e7");
- WeIdPrivateKey weIdPrivateKey = new WeIdPrivateKey();
- weIdPrivateKey.setPrivateKey("60866441986950167911324536025850958917764441489874006048340539971987791929772");
- createCredentialPojoArgs.setWeIdPrivateKey(weIdPrivateKey);
- ResponseData<CredentialWrapper> response = credentialPojoService.createCredentialPojo(createCredentialArgs);
- List<CredentialPojo> credList = new ArrayList<>();
- credList.add(response.getResult().getCredentialPojo());
- Long expirationDate = DateUtils.convertToNoMillisecondTimeStamp(
- createCredentialPojoArgs.getExpirationDate() + 24 * 60 * 60);
- createCredentialPojoArgs.setExpirationDate(expirationDate);
- CredentialPojo tempCredential =
- credentialPojoService.createCredentialPojo(createCredentialPojoArgs).getResult().getCredentialPojo();
- credentialList.add(tempCredential);
- ResponseData<CredentialPojo> multiSignedResp = credentialService.addSignature(credList, weIdPrivateKey);
- System.out.println(multiSignedResp);
- 返回结果如:
- result:(com.webank.weid.protocol.base.CredentialPojo)
- credentialPojo:(com.webank.weid.protocol.base.CredentialPojo) {
- {
- "claim": {
- "credentialList": [
- {
- "claim": {
- "age": 1,
- "gender": "F",
- "id": "did:weid:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
- "name": "1"
- },
- "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
- "cptId": 2000087,
- "expirationDate": 1567491752,
- "id": "6ea6e209-10e9-4a93-b6be-12af1a32655b",
- "issuanceDate": 1567405352,
- "issuer": "did:weid:1:0xa4c2666560499868baf1906941f806b6d1c26e33",
- "proof": {
- "created": 1567405352,
- "creator": "did:weid:1:0xa4c2666560499868baf1906941f806b6d1c26e33#keys-0",
- "salt": {
- "age": "yOwN7",
- "gender": "jjB85",
- "id": "BmRYI",
- "name": "BjYqF"
- },
- "signatureValue": "G+SNG3rBZNDvRNgRtJugPtX1FmE8XJIkV4CGPK\/nt\/breIPMJ5wYxImTp2QAxBUe5HMwCe9PPGhhMJJAazM5u9k=",
- "type": "Secp256k1"
- },
- "type": [
- "VerifiableCredential"
- ]
- },
- {
- "claim": {
- "age": 1,
- "gender": "F",
- "id": "did:weid:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
- "name": "1"
- },
- "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
- "cptId": 2000087,
- "expirationDate": 1567491842,
- "id": "a3544a9c-6cb6-4688-9622-bb935fb0d93f",
- "issuanceDate": 1567405355,
- "issuer": "did:weid:1:0x309320a01f215a380c6950e80a89181ad8a8cd53",
- "proof": {
- "created": 1567405355,
- "creator": "did:weid:1:0x309320a01f215a380c6950e80a89181ad8a8cd53#keys-0",
- "salt": {
- "age": "5nImi",
- "gender": "Me224",
- "id": "5pYs2",
- "name": "z6VmW"
- },
- "signatureValue": "HC8OAG\/dRmteGSIGWIDekp8fC1KJI8EEDZBb29HiTLXvVj350l9yTOHeGSBCr2VRY\/DSHT5ONjlvcrO4Mqa3Auo=",
- "type": "Secp256k1"
- },
- "type": [
- "VerifiableCredential"
- ]
- }
- ]
- },
- "context": "https:\/\/github.com\/WeBankFinTech\/WeIdentity\/blob\/master\/context\/v1",
- "cptId": 107,
- "expirationDate": 1567491842,
- "id": "ad5d5a54-4574-4b3b-b1df-9d0687b6a0ac",
- "issuanceDate": 1567405359,
- "issuer": "did:weid:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6",
- "proof": {
- "created": 1567405359,
- "creator": "did:weid:1:0x4e9a111867ed6370e1e23f7a79426f6649eb78c6#keys-0",
- "salt": {
- "credentialList": "UuJHx"
- },
- "signatureValue": "HC1y3rfyb\/2sg+E2Uulczm8VDtmQ6VrU\/9ow4e4nP3lVUOv4Gz41pfBrJHnV4wQoUbQsCYpezFx5sdaUwUILV1I=",
- "type": "Secp256k1"
- },
- "type": [
- "VerifiableCredential"
- ]
- }
- errorCode: 0
- errorMessage: success
- transactionInfo:null
时序图
sequenceDiagramparticipant 调用者participant CredentialPojoService调用者->>CredentialPojoService: 调用addSignature()CredentialPojoService->>CredentialPojoService: 入参非空、格式及合法性检查opt 入参校验失败CredentialPojoService—>>调用者: 报错,提示参数不合法并退出endCredentialPojoService->>CredentialPojoService: 生成签发日期、以原凭证列表为Claim生成数字签名CredentialPojoService—>>调用者: 返回凭证