Skip to content

WeIdentity_API_Documentation

李大狗 edited this page Mar 7, 2020 · 17 revisions

注:便捷起见,所有接口都是 POST。

Attention: All interface are POST Method for convenience.

1 WeId Operations

1.1 Create WeId

接口描述: 内部创建公私钥,并链上注册WeIdentity DID, 并返回公钥、私钥以及WeIdentity DID。

Description: Create Key pairs and register WeIdentity DID on chain, the response including pubkey, privkey and WeIdentity DID.

Path: /createWeId

Params: None

Successful Response:

{
    "result":{
        "weId":"did:weid:101:0xd613fbc0249f2ce5088ed484fa6b7b51ecb95e24",
        "userWeIdPublicKey":{     "publicKey":"3170902924087212850995053706205512080445198963430287429721846825598988998466716040533782467342119206581749393570668868631792331397183368695050591746049552"
        },
        "userWeIdPrivateKey":{"privateKey":"56535131944142184470585265117809267832190820184147955599118630324301733565588"}
    },
    "errorCode":0,
    "errorMessage":"success",
    "transactionInfo":{
        "blockNumber":60643,
        "transactionHash":"0xc73b7ba6af39614761423dc8fcbbbc7e5f24c82e8187bc467cf0398b4ce4330b",
        "transactionIndex":0
    }
}

Attention: The WeId in the example is "did:weid:101:0xd613fbc0249f2ce5088ed484fa6b7b51ecb95e24".

1.2 Get WeId

接口描述: 根据 WeIdentity DID 查询出 DID 的具体信息。

Description: Get details by DID.

Path: /getWeId

Params:

{
  "weId": [weId]
}

Successful Response:

{
   "result":{
      "id":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b",
      "created":null,
      "updated":1582785477,
      "publicKey":[
         {
            "id":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b#keys-0",
            "type":"Secp256k1",
            "owner":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b",
            "publicKey":"718505172790640333205850120049025443702791120029320034312780536192070120705332890949267038468145117212710796147297688203157489841796439877282289474483922"
         }
      ],
      "authentication":[
         {
            "type":"Secp256k1",
            "publicKey":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b#keys-0"
         }
      ],
      "service":[

      ]
   },
   "errorCode":0,
   "errorMessage":"success",
   "transactionInfo":null
}

2 Issuer Operations

2.1 Register Authority Issuer

接口描述: 注册成为权威机构。

Description: Register as an Authority Issuer.

Path: /registerAuthorityIssuer

Params:

{
   "issuer": [issuer-weId],
   "org-id": [org-name],
   "privkey"(optional): [privkey of Contract Deployer(合约部署者)]
}

Successful Response:

{
   "result":true,
   "errorCode":0,
   "errorMessage":"success",
   "transactionInfo":{
      "blockNumber":190,
      "transactionHash":"0x08be9ebefbf15b6cad0bd657c3401f86317e75750c993c3fcc60b8046bd516cd",
      "transactionIndex":0
   }
}

3 CPT Operations

CPT 定义:

凭证的声明类型 —— 不同的 Issuer 按业务场景需要,各自发行不同类型数据结构的 Claim ,各种各样的 Claim 用不同的 CPT 来定义。例如我们的毕业证书模板,就是一份 CPT。

CPT Definition:

Claim Protocol Type —— According to different business scenarios, Issuers customize Claims with different data structure, the protocol type of claim is CPT. For example, diploma template.

3.1 Register CPT

接口描述: 传入 WeId,Json 和其对应的私钥(可选),链上注册CPT,返回 CPT 编号和版本。

Description: Send WeId, privkey, and Json to register CPT on chain, return the id and the version of CPT.

Path: /registCpt

Params:

{
   "publisher":[weId],
   "claim":{
      "properties":{
         [json]
      }
   }
}

Example:

{
   "publisher":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b",
   "claim":{
      "properties":{
         "id":{
            "type":"string",
            "description":"user weid"
         },
         "name":{
            "type":"string",
            "description":"user name"
         },
         "gender":{
            "type":"string",
            "description":"user gender"
         }
      }
   }
}

Successful Response:

{
   "result":{
      "cptId":1021,
      "cptVersion":1
   },
   "errorCode":0,
   "errorMessage":"success",
   "transactionInfo":{
      "blockNumber":191,
      "transactionHash":"0x93edec4a2811b084bc9f3fdcb13df7b4d11667f9eac2d47f3cba289b57d4df2c",
      "transactionIndex":0
   }
}

4 Credential Operations

Credential —— 简称“凭证”,遵循 W3C Verifiable Credential 规范的电子凭证,可用来抽象现实世界凭证类的对象,一个Credential可以包含一个或者多个Claim。例如电子驾照,电子学历等。

Credential —— an object linked to credential in the real world, following the standards of W3C Verifiable Credential. A Credential could includes one or more Claim. such as digital driver's license, digital diploma.

4.1 Create Credential

接口描述: 创建电子凭证。

Description: Create Credential

Path: /createCredential

Params:

{
   "cptId": [cptId],
   "issuer": [weId],
   "claimData":{
      [json adapting the CPT]
   }
}

Example:

{
   "cptId":"1189",
   "issuer":"did:weid:101:0xd613fbc0249f2ce5088ed484fa6b7b51ecb95e24",
   "claimData":{
      "id":"did:weid:101:0xf36fb2308d36bb94c579f568bdf670743d949deb",
      "name":"zhangsan",
      "gender":"F"
   }
}

Successful Response:

{
   "result":{
      "credential":{
         "context":"https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
         "id":"ba1a2d54-c1c7-4de3-bcc7-e0fe61dce515",
         "cptId":1021,
         "issuer":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b",
         "issuanceDate":1583151051,
         "expirationDate":1614255050,
         "claim":{
            "gender":"F",
            "name":"zhangsan",
            "id":"did:weid:101:0x4ab994b77d4a3bb13b9a2a00ac9bd54040595c09"
         },
         "proof":{
            "creator":"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b",
            "signature":"HFHsuUEDAH3qzeJc3qByLyDrdmfL63KI2Eqc/LoMX74CBbciOayP6dAFWtuMQ9n/U+qk2oip/7Tx0ekkWf1NPZc=",
            "created":"1583151051",
            "type":"Secp256k1"
         },
         "signature":"HFHsuUEDAH3qzeJc3qByLyDrdmfL63KI2Eqc/LoMX74CBbciOayP6dAFWtuMQ9n/U+qk2oip/7Tx0ekkWf1NPZc=",
         "hash":"0xb679ab84c085dce665dc1672ba6874fcc73dc65d09d1b8d200ca29bce5250df3",
         "signatureThumbprint":"{\"claim\":\"gender0xe61d9a3d3848fb2cdd9a2ab61e2f21a10ea431275aed628a0557f9dee697c37aid0xdbbf225ee0327127ca047eaeaebd5366ae147155c2854d75d30e337a4fcc6fc1name0x8929153959cc17e50b39a87e7ecd8b282aaf8735115429d3c6539ae16bdabc6c\",\"context\":\"https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1\",\"cptId\":1021,\"expirationDate\":1614255050,\"id\":\"ba1a2d54-c1c7-4de3-bcc7-e0fe61dce515\",\"issuanceDate\":1583151051,\"issuer\":\"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b\",\"proof\":{\"created\":\"1583151051\",\"creator\":\"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b\",\"signature\":\"HFHsuUEDAH3qzeJc3qByLyDrdmfL63KI2Eqc/LoMX74CBbciOayP6dAFWtuMQ9n/U+qk2oip/7Tx0ekkWf1NPZc=\",\"type\":\"Secp256k1\"}}",
         "proofType":"Secp256k1"
      },
      "disclosure":{
         "name":1,
         "id":1,
         "gender":1
      },
      "signature":"HFHsuUEDAH3qzeJc3qByLyDrdmfL63KI2Eqc/LoMX74CBbciOayP6dAFWtuMQ9n/U+qk2oip/7Tx0ekkWf1NPZc=",
      "hash":"0xb679ab84c085dce665dc1672ba6874fcc73dc65d09d1b8d200ca29bce5250df3",
      "signatureThumbprint":"{\"claim\":\"gender0xe61d9a3d3848fb2cdd9a2ab61e2f21a10ea431275aed628a0557f9dee697c37aid0xdbbf225ee0327127ca047eaeaebd5366ae147155c2854d75d30e337a4fcc6fc1name0x8929153959cc17e50b39a87e7ecd8b282aaf8735115429d3c6539ae16bdabc6c\",\"context\":\"https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1\",\"cptId\":1021,\"expirationDate\":1614255050,\"id\":\"ba1a2d54-c1c7-4de3-bcc7-e0fe61dce515\",\"issuanceDate\":1583151051,\"issuer\":\"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b\",\"proof\":{\"created\":\"1583151051\",\"creator\":\"did:weid:1:0xd068e4d3076c3df7e83920539db7df182ddc5a5b\",\"signature\":\"HFHsuUEDAH3qzeJc3qByLyDrdmfL63KI2Eqc/LoMX74CBbciOayP6dAFWtuMQ9n/U+qk2oip/7Tx0ekkWf1NPZc=\",\"type\":\"Secp256k1\"}}"
   },
   "errorCode":0,
   "errorMessage":"success",
   "transactionInfo":null
}

4.2 Verify Credential(需要优化)

接口描述: 验证电子凭证。

Description: Verify Credential

Path: /verifyCredential

Example:

{
"context":"https://github.com/WeBankFinTech/WeIdentity/blob/master/context/v1",
"id":"e4f4accd-6026-4fd0-9392-1379ddd4f778",
"cptId":1189,
"issuer":"did:weid:101:0xd613fbc0249f2ce5088ed484fa6b7b51ecb95e24",
"issuanceDate":1564371227764,"expirationDate":1595475227763,
"claim":{"gender":"F","name":"zhangsan","id":"did:weid:101:0xf36fb2308d36bb94c579f568bdf670743d949deb"},
"proof":
{
"creator":"did:weid:101:0xd613fbc0249f2ce5088ed484fa6b7b51ecb95e24",
"signature":"G2kD4u4jrnmYbq/oVl9idmTEQzP3a0KEomHGJaVpWzhITIE+dDYSRMyF9TDy+jPANpYRJGg7pGnANM+QeJ9Ba00=",
"created":"1564371227764",
"type":"EcdsaSignature"},
"signature":"G2kD4u4jrnmYbq/oVl9idmTEQzP3a0KEomHGJaVpWzhITIE+dDYSRMyF9TDy+jPANpYRJGg7pGnANM+QeJ9Ba00=",
"proofType":"EcdsaSignature",
"disclosure":{"name":1,"id":1,"gender":1}
}

Successful Response:

{
    "result":true,
    "errorCode":0,
    "errorMessage":"success",
    "transactionInfo":null
}