目錄
- WeIdentity
- 1. 主要模塊介紹
- 分布式身份標識 (WeIdentity DID)
- 可驗證數字憑證 (WeIdentity Credential)
- 2. WeIdentity 參考場景
- 術語
- 使用場景
- 1 [選擇性披露](https://weidentity.readthedocs.io/zh_CN/latest/docs/use-cases.html#id4)
- 如何為Credential生成簽名
- 如何驗證選擇性披露的Credential
- 2 [資料共享](https://weidentity.readthedocs.io/zh_CN/latest/docs/use-cases.html#id7)
- 總體流程
- WeIdentity Sample開發樣例代碼
- 結合代碼
- DemoIssuerController
- DemoMemberController
- DemoOtherCredentialController
- DemoOtherCredentialPoJoController
- DemoOtherEvidenceController
- DemoOtherTransportationController
- DemoOtherWeIdController
- DemoUserAgentController
- DemoVerifierController
- ToolController
- ToolController
WeIdentity
分布式多中心的技術解決方案,可承載物體物件(人或者物)的現實身份與鏈上身份的可信映射、以及實作物體物件之間安全的訪問授權與資料交換,
1. 主要模塊介紹
WeIdentity DID以及WeIdentity Credential,
分布式身份標識 (WeIdentity DID)
簡稱WeID,WeIdentity的分布式多中心的ID注冊機制下生成的物體的ID,
WeIdentity DID模塊實作了一套符合W3C DID規范的分布式多中心的身份標識協議,使物體(人或物)的現實身份實作了鏈上的身份標識;同時,WeIdentity DID給與Entity(人或者物)直接擁有和控制自己身份ID的能力,
可驗證數字憑證 (WeIdentity Credential)
WeIdentity Credential提供了一整套基于W3C VC規范的解決方案,旨在對身份證、行駛證、存款證明、處方、畢業證、房產證、信用報告等這一類資料進行標準化、電子化,生成可驗證、可交換的「憑證」(Credential),支持對憑證的屬性進行選擇性披露,及生成鏈上存證(Evidence)
2. WeIdentity 參考場景
在WeIdentity生態中,存在著上圖所示的幾類角色,不同角色的權責和角色之間的關系如下表所示:

| 角色 | 說明 |
|---|---|
| User (Entity) | 用戶(物體),會在鏈上注冊屬于自己的WeIdentity DID,從Issuer處申請Credential,并授權轉發或直接出示給Verifier來使用之, |
| Issuer | Credential的發行者,會驗證物體對WeIdentity DID的所有權,其次發行物體相關的Credential, |
| Verifier | Credential的使用者,會驗證物體對WeIdentity DID的所有權,其次在鏈上驗證Credential的真實性,以便處理相關業務, |
| User Agent / Credential Repository | 用戶(物體)在此生成WeIdentity DID,為了便于使用,物體也可將自己的私鑰、持有的Credential托管于此, |
在實際業務里,WeIdentity可以被廣泛運用在「物體身份標識」及「可信資料交換」場景中,首先,通過User Agent為不同的物體生成獨立唯一的DID;其次,Issuer驗證物體身份及DID所有權,為物體發行各種各樣的電子化Credential,當物體需要辦理業務的時候,可以直接將Credential出示給Verifier,也可以通過在鏈上進行主動授權 + 授權存證上鏈的方式,由之前授權的憑證存盤機構轉發給Verifier,
以上流程,保證了資料以物體用戶為中心,同時物體身份、確權、授權等操作在鏈上完成,可追溯,可驗證,不可篡改,
術語
| Claim | 宣告 | 對物體的一個宣告或者主張,用于裝載憑證(Credential)業務資料的欄位,例如電子駕照的各項資訊就是存在一個Claim結構中 |
|---|---|---|
| WeIdentity Credential | 可驗證數字憑證 | 簡稱“憑證”,遵循W3C Verifiable Credential規范的電子憑證,可用來抽象現實世界憑證類的物件,一個Credential可以包含一個或者多個Claim,例如電子駕照,電子學歷等 |
| CPT | 憑證的宣告型別 | Claim Protocol Type,不同的Issuer按業務場景需要,各自定義不同型別資料結構的Claim,各種各樣的Claim用不同的CPT來定義 |
| issue | 發行 | 一個Issuer(包括Authority Issuer)按照某種CPT定義的格式,發行Credential,這個動作叫issue |
| publish | 發布 | 一個Issuer(包括Authority Issuer)發行一種新的CPT,這個動作稱為publish |
| Issuer | 憑證發行者 | 任意擁有WeIdentity DID的Entity都可以作為Issuer來發行Credential |
| Entity | 物體 | WeIdentity Document或Credential描述的物體,即擁有WeIdentity DID的人或者物 |
| User Agent | 用戶代理 | 用戶私鑰托管機構,例如某個用戶身份管理APP,依據業務場景需求,可以是云端保存機制的,也可以是客服端本地保存機制的 |
使用場景
通過WeIdentity對物體進行DID、憑證(Credential)的生成及系結,可以更加準確完善地描述物體身份、物體間關系,并有效提高物體間資訊流轉的真實性和效率,
1 選擇性披露
如何為Credential生成簽名
Issuer生成Credential簽名的程序:
- Claim中的每個欄位計算生成一個對應的hash值,
- 將Claim中的每個欄位的hash值以某種形式拼接起來形成一個字串Claim_Hash,然后跟Credential原有的其他欄位組成一個新的用于計算hash的Credential結構,
- 對這個包含Claim_Hash的Credential結構計算hash,得到Credential Hash,
- 使用Private Key對這個Credential Hash進行簽名,得到簽名的值Signature,

如何驗證選擇性披露的Credential
用戶選擇需要披露的欄位集合(可以是一個或者幾個欄位,這個例子中是Field_1),需要披露的欄位提供原文,其他欄位提供hash值,將包含這個Claim結構的Credential披露給Verifier,下面是Verifier驗證的程序:
- Verifier從Credential提取用戶披露的Claim欄位,
- Verifier對用戶披露的欄位分別計算hash(這個例子中是Field_1,計算出Field_1_hash),然后得到一個包含所有欄位hash值的Claim結構,
- 對這個Claim結構中的每個欄位的hash值以某種形式拼接起來形成一個字串Claim_Hash,然后跟Credential原有的其他欄位組成一個新的用于計算hash的Credential結構,
- 對這個包含Claim_Hash的Credential結構計算hash,得到Credential Hash,
- 使用Credential的Signature和Issuer的public key進行decrypt,得到一個簽名的計算值,
- 比較Credential的Signature與簽名的計算值,看是否相等,確認這個Credential的合法性,

2 資料共享
總體流程
一般來說,WeIdentity解決方案的基本流程如下:
- 用戶根據業務需求,選擇是否需要進行KYC認證,
- 用戶生成WeIdentity DID,
- 用戶向相關業務方申請Credential,
- 相關業務方扮演Issuer的角色,發行Credential交給用戶,
- 用戶成為了Credential的Holder,
- 用戶出示Credential,以完成業務需求,
- 相關業務方扮演Verifier的角色,驗證Credential有效性,

其中CPT為模板類,定義了Claim包含的資料欄位及各欄位屬性要求,Claim為CPT的實體,Issuer將Claim進行簽名,即可生成Credential,
WeIdentity Sample開發樣例代碼
###Claim Protocol Type(CPT)注冊機制
不同的Issuer按業務場景需要,各自定義不同型別資料結構的Claim,所有的Claim結構都需要到CPT合約注冊,以保證全網唯一,所有的CPT定義檔案(JSON-LD格式)可以從CPT合約下載,
結合代碼
DemoIssuerController
Issuer: Credential的發行者,會驗證物體對WeIdentity DID的所有權,其次發行物體相關的Credential,
| 介面 | 含義 | 備注 |
|---|---|---|
| /step2/registCpt | 注冊CPT | 需要獲得publisher,privateKey和claim才可以注冊CPT |
| /step3/createCredential | 創建電子憑證 | 需要提供cptId,issuer,privateKey,claimDataMap才可以創建電子憑證 |
DemoMemberController
Committee Member: 委員會機構成員,管理Authority Issuer的委員會機構的成員,
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/member/createWeId | 創建WeId | 直接就可以創建一個唯一id |
| /step2/registerAuthorityIssuer | 注冊成為權威機構 | 需要issuer和orgId即authorityName才可以 |
DemoOtherCredentialController
其他相關介面-Credential
電子憑證其他相關介面,
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/credential/getCredentialPoJoHash | 傳入Credential資訊生成Credential整體的Hash值,一般在生成Evidence時呼叫, |
DemoOtherCredentialPoJoController
電子憑證其他相關介面,
其他相關介面-CredentialPoJo
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/createCredentialPoJo | 傳入Credential資訊生成Credential整體的Hash值,一般在生成Evidence時呼叫, | 直接呼叫 |
| /step2/createSelectiveCredential | 通過原始憑證和披漏策略,創建選擇性披露的Credential, | 直接呼叫 |
| /step3/verifyEvidence | 驗證電子憑證, | 直接呼叫 |
| /step4/createPresentationPolicyE | 創建PresentationPolicyE, | 直接呼叫 |
| /step5/createPresentation | 創建Presentation, | 直接呼叫 |
| /step6/getCredentialPoJoHash | 傳入CredentialPojo資訊生成CredentialPojo整體的Hash值,一般在生成Evidence時呼叫, | 直接呼叫 |
| /step7/addSignatureCredentialPojo | 多簽,在原憑證串列的基礎上,創建包裹成一個新的多簽憑證,由傳入的私鑰所簽名,此憑證的CPT為一個固定值,在驗證一個多簽憑證時,會迭代驗證其包裹的所有子憑證,本介面不支持創建選擇性披露的多簽憑證, | 直接呼叫 |
DemoOtherEvidenceController
其他相關介面-Evidence
存證其他相關介面,
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/createEvidence | 將傳入Object計算Hash值生成存證上鏈,回傳存證地址,傳入的私鑰將會成為鏈上存證的簽名方,此簽名方和憑證的Issuer可以不是同一方,當傳入的object為null時,則會創建一個空的存證并回傳其地址,空存證中僅包含簽名方,不含Hash值,可以隨后呼叫SetHashValue()方法,為空存證添加Hash值和簽名, | 直接呼叫 |
| /step2/getEvidence | 根據傳入的憑證存證Hash,在鏈上查找憑證存證資訊, | 直接呼叫 |
DemoOtherTransportationController
傳輸其他相關介面,
其他相關介面-Transportation
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/jsonTransportationSpecify | 指定transportation的認證者,用于權限控制, | |
| /step2/jsonTransportationSerialize | 用于序列化物件,要求物件實作JsonSerializer介面, |
DemoOtherWeIdController
其他相關介面-WeId
WeId其他相關介面,
| /step1/createWeId | 通過公私鑰對創建WeId, | create weId without parameters and call the settings property method. returns weId and public key |
DemoUserAgentController
UserAgent相關介面 ,
User Agent / Credential Repository:
用戶(物體)在此生成WeIdentity DID,為了便于使用,物體也可將自己的私鑰、持有的Credential托管于此,
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/userAgent/createWeId | 創建weid | create weId without parameters. returns weId and public key |
DemoVerifierController
會驗證物體對WeIdentity DID的所有權,其次在鏈上驗證Credential的真實性,以便處理相關業務,
Verifier相關介面
Verifier: Credential的使用者,
| 介面 | 含義 | 備注 |
|---|---|---|
| /step1/verifyCredential | 驗證憑證是否正確 | 回傳true或者false |
ToolController
小工具
| 含義 | 備注 |
|---|---|
| /step1/verifyCredential | 驗證憑證是否正確 |
ToolController
小工具
| 含義 | 備注 |
|---|---|
| /step1/getPublicKey | 通過私鑰生成公鑰 |
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/145529.html
標籤:其他
