包含发布模板(schema),创建凭证和验证凭证等流程。
@PostMapping(value = "/intercation2")
public void testCreateMyDidWorksForEmptyJson2() throws Exception {
String name = "company_name";
String p_type = ">=";
int p_value = 0;
log.info("------生成proof,查询条件:[{}]:[{}]:[{}]-------",name,p_type,p_value);
Wallet wallet_stuent = null;
Wallet wallet_school = null;
Pool pool = null;
String poolName = "default_pool";
try {
InitHelper.init();
StorageUtils.cleanupStorage();
Pool.setProtocolVersion(PROTOCOL_VERSION).get();
try {
poolName = PoolUtils.createPoolLedgerConfig();
}catch (Exception e){
log.error("----------------------创建pool失败 -----------------------------");
}
pool = Pool.openPoolLedger(poolName, null).get();
try {
Wallet.createWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
}catch (Exception e){
log.error("----------------------创建wallet失败 -----------------------------"+WALLET_CONFIG);
}
try {
Wallet.createWallet(wallet_stuentConfig, WALLET_CREDENTIALS).get();
}catch (Exception e){
log.error("----------------------创建wallet失败 -----------------------------"+wallet_stuentConfig);
}
wallet_school = Wallet.openWallet(WALLET_CONFIG, WALLET_CREDENTIALS).get();
wallet_stuent = Wallet.openWallet(wallet_stuentConfig, WALLET_CREDENTIALS).get();
// Issuer create DID
//请求方 创建did
/**
* did=V4SGRU86Z58d6TV7PBUe6f,verkey=GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL
*/
DidResults.CreateAndStoreMyDidResult trusteeDidInfo = Did.createAndStoreMyDid(wallet_school, new JSONObject().put("seed", TRUSTEE_SEED).toString()).get();
log.info("----------------------------trusteeDidInfo-------------------[{}]",trusteeDidInfo);
// 创建新的did,仅用于安全交互
/**
* did=ToY8X3Q6PHcbQc4sFF974v,verkey=FcGyGsd951uD351CVW3tsae5vFenw7SucAXdCJjHc2Sx
*/
DidResults.CreateAndStoreMyDidResult issuerDidInfo = Did.createAndStoreMyDid(wallet_school, "{}").get();
log.info("----------------------------issuerDidInfo-------------------[{}]",issuerDidInfo);
String nymRequest = Ledger.buildNymRequest(trusteeDidInfo.getDid(), issuerDidInfo.getDid(),
issuerDidInfo.getVerkey(), null, "TRUSTEE").get();
log.info("----------------------------nymRequest-------------------[{}]",nymRequest);
//创建连接 将相应的交易发送到 Ledger(分布式账本)
Ledger.signAndSubmitRequest(pool, wallet_school, trusteeDidInfo.getDid(), nymRequest).get();
String issuerDid = issuerDidInfo.getDid();
// Prover create DID
// Prover方创建新的DID,仅用于安全交互
DidResults.CreateAndStoreMyDidResult proverDidInfo = Did.createAndStoreMyDid(wallet_stuent,"{}").get();
/**
* did=G4CimvjB2S7FJ8UXS5Kkju,verkey=9Cve4SydbrFKG2LB1H4rZLJowkdnKcidEZdr8ntQTBtE
*/
log.info("----------------------------proverDidInfo-------------------[{}]",proverDidInfo);
String proverDid = proverDidInfo.getDid();
String proverVerkey = proverDidInfo.getVerkey();
// Issuer publish Prover DID
//创建连接 将相应的交易发送到 Ledger(分布式账本)
nymRequest = Ledger.buildNymRequest(issuerDid, proverDid, proverVerkey, null, null).get();
Ledger.signAndSubmitRequest(pool, wallet_school, issuerDid, nymRequest).get();
// ISSUER post to Ledger Schema, CredentialDefinition, RevocationRegistry
// Issuer creates Schema
/**
* 凭据架构设置
*/
/**
* schemaJson={
* "ver":"1.0",
* "id":"ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0",
* "name":"gvt","version":"1.0",
* "attrNames":["name","age","sex","height"],
* "seqNo":null
* }
*/
AnoncredsResults.IssuerCreateSchemaResult schemaInfo =
Anoncreds.issuerCreateSchema(issuerDidInfo.getDid(), "gksw", "2.0", GVT_SCHEMA_ATTRIBUTES2).get();
log.info("----------------------------schemaInfo-------------------[{}]",schemaInfo);
String schemaJson = schemaInfo.getSchemaJson();
/**
* ledger.build_schema_request通过持续调用构建 Schema 请求并
* ledger.sign_and_submit_request发送创建的请求,将相应的 Schema 事务发送到 Ledger 。
*/
// Issuer posts Schema to Ledger
String schemaRequest = Ledger.buildSchemaRequest(issuerDid, schemaJson).get();
/**
* 将颁发的可用信息 发布 分布式账本。
*/
Ledger.signAndSubmitRequest(pool, wallet_school, issuerDid, schemaRequest).get();
/**
* 通过持续调用构建请求、发送创建的请求以及从响应中获取Anoncreds API 所需格式来从分类帐中获取特定的凭证模式。
*/
// Issuer get Schema from Ledger
/**
* {
* "reqId": 1655714390813315391,
* "identifier": "ToY8X3Q6PHcbQc4sFF974v",
* "operation": {
* "type": "107",
* "dest": "ToY8X3Q6PHcbQc4sFF974v",
* "data": {
* "name": "gvt",
* "version": "1.0"
* }
* },
* "protocolVersion": 2
* }
*/
String getSchemaRequest = Ledger.buildGetSchemaRequest(issuerDid, schemaInfo.getSchemaId()).get();
log.info("----------------------------getSchemaRequest-------------------[{}]",getSchemaRequest);
/**
* {
* "op": "REPLY",
* "result": {
* "type": "107",
* "seqNo": 176,
* "reqId": 1655714390813315391,
* "identifier": "ToY8X3Q6PHcbQc4sFF974v",
* "dest": "ToY8X3Q6PHcbQc4sFF974v",
* "state_proof": {
* "proof_nodes": "+QOg+HagIG9ZOFgzUTZQSGNiUWM0c0ZGOTc0djoyOmd2dDoxLjC4U/hRuE97ImxzbiI6MTc2LCJsdXQiOjE2NTU3MTQzOTAsInZhbCI6eyJhdHRyX25hbWVzIjpbInNleCIsImFnZSIsIm5hbWUiLCJoZWlnaHQiXX19+QERoIBPRVBym0VMqKUPRb4BR2IfQI9oHsZplBrgQiWRTN2RoEqrNL0SnxW8bZvFG5ZEBag39mJuHZ8mD7rFQE2G4ohagICgAp8B0LP5DPDRA1bU9M0R7vfDt2ieiUNn+xD8KFqxlz+gI0mUUx8NGlamvRtqQSxcDc0c7ObYKSp+jIlT3YniB4+gcXGNyQTTyR2+ktcc5z8GxyOiuIbGCG/63qAj2R/HbvOAgKDgHyyBaf6beq30wRoq8ApB66vLElkAsPXRvPaoVicKIKAtgZkuibjMnPY8uOMuJ3vYG0K02yms2RsE4i5M4iQU1ICAgICg9SLAPJ7gWodAxHMnGo1lZdsx9G329AQDHi2Va5FlEdyA+QIRoIHXGAgPHEw80DxSWZyUUH6lwZAgyE+SPqefavbv+NXRoHVoLWh/mtko6PXQfXHiJmj4HHpM0SKBEX6KfEyp1hcfoB2cAf4dex7KHdFAYJ7WeopPeByp8L+gzgRYOwlkGshRoG/Z7UWjvay97nIjN9a9BCJ2XnGRdy8Zjgh9HzZ+h1szoKWuuTo39gwwBcaiZFO1dOlUTJBl8e0g6FOs/YB6fonmoH8K+7C7sUVhoT99sbTdK8gCiVzCZ4AKVj/IF0B3vjs4oPMfGWX08kIU7jLrU8uKvpxjrihL+hf6WCpdlN3PDemYoDO49ZFE5wQLghKJ1lLL3S+3HhMeFh3aLtwAw2sXjRkXoN97+YmtuuEFGEzVW0Sgm3yfl/ueXKVFy5jpVKrfNWbRoPsHiHwb5k8wY2/V6TgrfACDi5rzVyucq3RdNjXC3dFGoLnDYDyQXq9qSEYkgkt+88ijENf5Urn753936BPv/sA3oPQnqsDT+/XL3pjveDtVVjETk/337a/CCGEpF+KRXGe3oLpQEQ6vKsvZU+BDV3xX9pOexeGCyT/oIFWYuWbhUWZjoLD23HcAytr5Ja/vdwdOq3KcQwSyJcx0JewV0nIuAMmSoC53D2XU+6d3B99NXLxasgcOmcfbBGBRE/hIqDm3iowFoAUfA+xqTeaLrR7v8/vxdn1RKHsJ6C7l3KbOk7gEozmjgA==",
* "root_hash": "FBwrQrAacWSZZ7KkhGGcXJGjSbzJYZ2eJ2T79rUo6CX4",
* "multi_signature": {
* "signature": "QwPzLnAnxVE7ysVpap7crfcCawS36yUP73jfFWyeKYM1JLdVUwDMAek48QwG9nDi2xSgr7dQJe2yqMfDxRBLFvu1o3pvEUBo2r1X9vt51Q4xF28sCtk4Bc3xYEjbK4uYUYuu5ub75A7PGpXSvEtArmrZhs92CsjDoPAgJtofwotFc3",
* "participants": [
* "Node1",
* "Node4",
* "Node3"
* ],
* "value": {
* "ledger_id": 1,
* "state_root_hash": "FBwrQrAacWSZZ7KkhGGcXJGjSbzJYZ2eJ2T79rUo6CX4",
* "timestamp": 1655714390,
* "pool_state_root_hash": "NCGqbfRWDWtLB2bDuL6TC5BhrRdQMc5MyKdXQqXii44",
* "txn_root_hash": "58PCsj7QfzfQ3tWfiUSAUfLr2XGoTqFiNsocfM1DvPU1"
* }* }
* },
* "txnTime": 1655714390,
* "data": {
* "attr_names": [
* "sex",
* "age",
* "name",
* "height"
* ],
* "name": "gvt",
* "version": "1.0"
* }
* }
* }
*/
String getSchemaResponse = PoolUtils.ensurePreviousRequestApplied(pool, getSchemaRequest, response -> {
JSONObject getSchemaResponseObject = new JSONObject(response);
return ! getSchemaResponseObject.getJSONObject("result").isNull("seqNo");
});
log.info("----------------------------getSchemaResponse-------------------[{}]",getSchemaResponse);
// !!IMPORTANT!!
// It is important to get Schema from Ledger and parse it to get the correct schema JSON and correspondent id in Ledger
// After that we can create CredentialDefinition for received Schema(not for result of indy_issuer_create_schema)
/**
* id=ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0,
* objectJson={
* "ver":"1.0",
* "id":"ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0",
* "name":"gvt",
* "version":"1.0",
* "attrNames":["height","sex","name","age"],
* "seqNo":176}
*/
LedgerResults.ParseResponseResult schemaInfo1 = Ledger.parseGetSchemaResponse(getSchemaResponse).get();
log.info("----------------------------schemaInfo1-------------------[{}]",schemaInfo1);
schemaJson = schemaInfo1.getObjectJson();
// Issuer creates CredentialDefinition
AnoncredsResults.IssuerCreateAndStoreCredentialDefResult credDefInfo =
Anoncreds.issuerCreateAndStoreCredentialDef(wallet_school, issuerDid, schemaJson,
TAG, null, new JSONObject().put("support_revocation", true).toString()).get();
/**
* credDefId=ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1,
* credDefJson={
* "ver":"1.0",
* "id":"ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1",
* "schemaId":"176",
* "type":"CL",
* "tag":"tag1",
* "value":
*
* {
* "primary": {
* "n": "94033702084171458854963922120782197615265308689826122768567250504410676357499028786540501263208594076927525398220264000938312505416118327968723681721683728651164202136503352795096926170914026076055539617375871896375048339370513076273855330283840560664959472980808197377909862786243645840471443050735691330672022360330087089190348773744873333353290292227531789764027789607825559187299963552569891636361659109425724570174334772372382623765507701636191417625067261509941704915790958074902736051398594705952492876727565018777190004847683021268467545465810559396988265934823942188791481879311922014692828163896625132389369",
* "s": "72842095105063349597742725590098231345191353200810048366989296771880729364842319616142462875471953090238688375421505141554681907559377272143663060654703969464721901109195849517122578201015913187748777054829037289715488627953450091072098879525176613197020950847961209083847165569325157522541224834527019928102294274271906831790192577472298046828779494642043324531028828131558121941389025234471951853731729440020904833779948845250346796279774579698728917941147848224479994666123212783841051558711430186753869714266776998936894610053611207135456601310230957046798633818821568041009290402592049572581763787068724857324175",
* "r": {
* "master_secret": "82610044194032168817774758066656783724306686905861850274243257560458118208378151355878289333688849051116342812162683086380167893273750929198524789522424687128699213606884169371003124291424395665788688167435995701470021777353735167106882524317320231328161158610552059797345970523031534164172122685460791351488023788725093021343941901556678918475826513877779985314541805353693991810459030944167242512690482763421673857599993094115612965727659482911416468008274561319460858792911540403445137667809383581818185941348381629912423902771325653924788510810528561276166830387742840491057171205265423180171250442368767643353982",
* "age": "25691982714341161984095519241592342826109689199091956805855460842045175556235926566513338258641515258066476085812345449459890160978018537562732299549447960033593174507276614184158394517764545258042053885812588429060379151892548930185367826002938879548516721587078086891683998237620783229352761103482912577628670690730426500659687626379747083636784022226195795574387747138658302605498718784114842024745093225526976266133484269941559137586295083301338590542592304991048524686521750781383278702507345158434404242090664077109691031908681699722631940471479670755198990230245584525578146866410412416432435057332886389773723",
* "name": "72347852769657879640550367027550565641867537081915289205554710162294207659436141008679960952869760028887272797984660391790880086964501885074026779169023096792491611325177531899532566428973729836115408403571000484325582787211314908553294467753986397014236156329063174677442191139359488708353382728487715019362805753512883125798857943567702762725349600155595242347971060997590868202117958414584435735982705478305187429133492839454613804943548173994098316068108481954393221770019219341593519448407047709624083090246172777451156834004934958938360525170489610269208111701508792243000318561156211602061213130396017465401125",
* "sex": "45040593670849707072088078392077270602907094507025975806988466939415099136124430397341796940798249989651207081752706447202261023593640074877979933240454045381235968243676296733752408158155741309994250984189168423213757902293583933057987063074671562634801510135019948661422490325413368058623533175993558342500920543324791510236666076322665779800006230351327526531081123019903576403075240466848966230515247733705503027530190868016305170349405574882051279227625522212682629530961603797735820012370597146065515734775961876846105553044156051482966801358501617157012409086987954524424114985145718851820435373083833610349023",
* "height": "29516369426175635327014130901004231124359714616110483510242485362881282574336998218708009979732012570067502523864262313267525083326372653839374935812093086338615038790250562040762499277381859716387394379046110321343451676208190693828469178815493233098020461641365702381734926886039765267621543184409468003030982455802409024748605179896786368651392944935025462441679316934946160069560309793333498916380935336798256612571132293447232293764032092665640825114035985825250699602563157648876550602307705185348128260747395341090133454794270249835558745356422176603542346615160328315701057697086978537872197488945414010769503"
* },
* "rctxt": "51526020257216399293574532845273600698316337041681887765376449144472804070767277724974836060809318267382080907403187451880264437114123837505460388419406171556016649803887232019348775175151567892821153217098489406890685285123628941025668420221098686383524663584203118966650612344585740013348741462817385140660879503584970108889590397324357092446408673168673116512010650721439707252019591836756066242402862587386272469576512353380565922129757374191416664258521525294129616448505026970468637244799949448597160993304870128402131901794972525164775936979936482134069543808095504902484613830201538644496323879181224052625338",
* "z": "44929073527567998873495509976143809287564534846285096470231360978408780616126266326000528951366868506542280053256388002814553883509765358627566746811470362160849794082048629253730899300802123547241942625103229753027664592506818618899323245563147488892747684397276269702111764458018771619282619553960309186081512408013258200067339206709587535625183498097376878254611766185504675402304879594099706880358044867018144985033783524479940304297265806780447569842391940219036071300636054463364922754560676960770870756340444447969637684438489899742111333201140275702182943167854111861079653025958547711423589833257955468110516"* },
* "revocation": {
* "g": "1 0280CD89D176028D4D870E58910A101A6457C1FC6EBD3B7FC949EAF7754FDF18 1 1666BCCDB7D3B89AAB6B8194CBD4464F15B6B62FCCAB5113F8BA664A83EA5521 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "g_dash": "1 1AEFF2C1579D2432641767A767475DF3C7ABDFB997B1C5035383B9412ABE486C 1 1FE87A2217BB2CAE5FAB45892B8D26108E3DCC4812B276AF59B565BDC5073D5D 1 1C901F4F384BD829528E06BC2F8DA26BCAF57802B04E088F4DD95281F108580C 1 0BF1C0EE1530069264CD0739741FDBAC2B726C51A127A32629734398CDFE1FB1 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000",
* "h": "1 09D2E0080D1CFB1EBBFC5EAA307DC640EAF47D3B11D6896A174B5A000BA394C2 1 1C547DAC1DB6161200A639B1360332C47CE88A45C2C7CD53DFFD01FC36A81FB9 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "h0": "1 1F1FEA1540DBDBDD0D22E1C72B8670C13F006AA5863296CB93C665AFDBA00070 1 13852DB4F00239FF7FCED8FCF882F254C7C378700E4216734E4D4236AEE2CAC7 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "h1": "1 0D346CF0F62275D944106E11316D660866B998C760EE1787545BC527F2832258 1 0D5DB7D8E53894BE03EFA74BA118ED0F5FAAF1FC3344A67141B5B05687797114 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "h2": "1 2381EB02EC3D0B3C8E3E8982A4A830CBC801206613E44E29A49153D7DBAF2998 1 1A5D550D6D9A5A0F18BA2A22F2677A8B8A25B686D564E2EDABDB53A2EE5A5045 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "htilde": "1 155017B35808A426A134B82B9BDDF3C896FB328D1DA5166C36AB31818EDEAEE1 1 221F0AEEE688B2BA436C656ABC378B407538A2DEF49634400E35B1BC6A2B9115 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "h_cap": "1 03BE30DB69691C8ECAC67780194B2C48462CACE8FC92B55D5F2915D3073387F8 1 06C4F2AFD7EF1DCAE88FCFF68F0D54469CE8F6EEAED35117E1B77EA034F17997 1 1BF0FA1D19F1CB1A4F9F28721010E6CD7874CD8294FEF7D94472BA8D0A7E363E 1 00AF72471428837F8F7BAAC5AFF4019BB85F0FE979FE46799085AC4F1EA85F80 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000",
* "u": "1 0F429AD07EEE1AE003E5014105AA91ACD7AB8CE0902AC59F543A80E6D4989497 1 12124A4AD48571EF1339828318A1C3BC9F9AD0FBE927D899B0F3BC88476D6DB7 1 1E17377F354EB10FA860212C06318A28F0C5D65861D680FDE3988DC522CFAD73 1 0C843B443EFBB5525001540021143FBEB96C9C3BA4B2C0CD1B41C5CF4F84016A 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000",
* "pk": "1 15845F462BFB02E392578EF84C58191BA56E957E1CA0F376CC5438BA642D878A 1 192604D2CE783B49753F91848AC84C229E0A7C8283311CBFAAA111BFC80EFACE 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8",
* "y": "1 17E950DE2179BD2D0270B19BA6C34BAEC795DCD0E8CEBE54849B936F79728E40 1 1E50ABFCC55AE252BD48E49D4E21B1EDAC70CFB3441680A6FBABDB6C8DB61C5E 1 05ACF4E22391F7DA6A93E47E9317DA5A38A14745DC687EB59FB0DE0FF1A4EDAF 1 10D05122213E0C25CD54E7D7437764920B6930C4EABB75277589C222A51F61DA 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000"
* }
* }
*/
log.info("----------------------------credDefInfo-------------------[{}]",credDefInfo);
String credDefId = credDefInfo.getCredDefId();
String credDefJson = credDefInfo.getCredDefJson();
// Issuer post CredentialDefinition to Ledger
String credDefRequest = Ledger.buildCredDefRequest(issuerDid, credDefJson).get();
log.info("----------------------------credDefRequest-------------------[{}]",credDefRequest);
Ledger.signAndSubmitRequest(pool, wallet_school, issuerDid, credDefRequest).get();
// Issuer creates RevocationRegistry
/* FIXME: getIndyHomePath hard coded forward slash "/". It will not work for Windows. */
String tailsWriterConfig = new JSONObject(String.format("{\"base_dir\":\"%s\", \"uri_pattern\":\"\"}",
getIndyHomePath("tails")).replace('\\', '/')).toString();
// 创建一个撤销注册表
BlobStorageWriter tailsWriterHandle = BlobStorageWriter.openWriter("default", tailsWriterConfig).get();
/**
* 可以为给定的凭证定义创建一个新的撤销注册表。
*/
AnoncredsResults.IssuerCreateAndStoreRevocRegResult revRegInfo =
Anoncreds.issuerCreateAndStoreRevocReg(wallet_school, issuerDid, null, TAG,
credDefId,
new JSONObject().put("max_cred_num", 5).put("issuance_type", "ISSUANCE_ON_DEMAND").toString(),
tailsWriterHandle).get();
/**
* revRegDefJson={
* "ver":"1.0",
* "id":"ToY8X3Q6PHcbQc4sFF974v:4:ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1:CL_ACCUM:tag1",
* "revocDefType":"CL_ACCUM",
* "tag":"tag1",
* "credDefId":"ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1",***
*/
log.info("----------------------------revRegInfo-------------------[{}]",revRegInfo);
String revRegId = revRegInfo.getRevRegId();
String revRegDefJson = revRegInfo.getRevRegDefJson();
String revRegEntryJson = revRegInfo.getRevRegEntryJson();
// Issuer posts RevocationRegistryDefinition to Ledger
String revRegDefRequest = Ledger.buildRevocRegDefRequest(issuerDid, revRegDefJson).get();
Ledger.signAndSubmitRequest(pool, wallet_school, issuerDid, revRegDefRequest).get();
// Issuer posts RevocationRegistryEntry to Ledger
String revRegEntryRequest = Ledger.buildRevocRegEntryRequest(issuerDid, revRegId,
REVOC_REG_TYPE, revRegEntryJson).get();
Ledger.signAndSubmitRequest(pool, wallet_school, issuerDid, revRegEntryRequest).get();
// Issuance Credential for Prover
/**
* 主密钥是证明者用来保证证书唯一适用于他们的私有数据项。
* Master Secret 是一个输入,它结合了来自多个 Credentials 的数据以证明 Credentials 具有一个共同的主题(证明者)。
* Master Secret 应该只有 Prover 知道。
*/
// Prover creates Master Secret
Anoncreds.proverCreateMasterSecret(wallet_stuent, COMMON_MASTER_SECRET).get();
/**
* 创建了一份关于颁发成绩单证书的证书要约。
* 这个成绩单证书的价值在于它是由费伯学院颁发的可证明的。
*/
// Issuer creates Credential Offer
String credOfferJson = Anoncreds.issuerCreateCredentialOffer(wallet_school, credDefId).get();
/**
* {
* "schema_id": "ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0",
* "cred_def_id": "ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1",
* "key_correctness_proof": {
* "c": "40443925940474528802526344037401660872783414707178500708572951101754097079007",
* "xz_cap": "588460112496568956636311067224153545860708771413590139215871404260174007103797573248897672154949092768871718240353902356638767512185690284628895355329555634813966580643049808819366681968567875149837186494649119763168950178436950661956758627185408695551612458369298801101510004599952067790302556373797845291281279242680496915733179150030113076718944202743771156044144999488643323580534016473132378896604025721599160294132315977023396521035427890911184977003607781477304110437640148247798197543187047441629201416513863282653611513107024360412307225639290819806026175839652608024093585468079301500063195629243680772899565599471140626820276742261905359769398618561895402440011856755985392858898085",
* "xr_cap": [
* [
* "master_secret",
* "346450852033359049939700175397477425278971466274712942819972058877952789476370503280497595659580873140327071366500907848922856332470066099933455483390910182669707573888481262429958497794939405157422390030183309902538143748862559913981734421071335455313878202229195442824919962326087626815092207626197411120990248659597892325252106562762619500066431622288255378136216083641938992514199250231189121882980991753228846905869271591277068651294572278500123546317174798949839216821736293489849899953521142667459297067444089049699945818996004559644004512006038238485449026219560725786551211466761089058378392433479319617149161551037567918330972377180439555445285590345641089502060868858299693010491577"
* ],
* [
* "age",
* "429942276548096506783515412100383052241218748300867451388223570977148461737723989857915014132275256841042873713266338459412607448196934624238913668853238615899692778431687277368809304688326709217594386889396905620228928727909145010268073358157566123468665962123908582617398589230831378019201047630739911175795577283783833914337474041404726854772507613530887038916713085666003494767831264425463140694704825162549923429904479579954337145065701009811279350657581708037366099276866189978563817923039424939964632534305151457256816856922008638491953307144799297572959230365847451356810489989436777958404922514942749720928972129838958608877828029999360310799275442655174218457511266380804767709459185"
* ],
* [
* "height",
* "484896640446727054791113830648069089428528102148954217511009743519825356015387581153101323831273434215653513816524190514516028416091292899295850638347952005457830519851915427717696342187097359869173224146546447288995273864806535018762191617044784446280935888656326614383331643612061373201914497203024463306626160908293778243559256881169445440085199952416597034523327191042521443730832865665240149489797965459483060577526248267030437095573386791567379330847434175652121310299071280888320168685685627689195127750946616478715995400947176368313544789125594703132180533856388865384292424730415048017325915550154689878903159130781996385067559576314609676071764927537121211118405570098634268528584212"
* ],
* [
* "name",
* "852100571143286199964542404228383834917200163561340936590047732759849153464145314062821670464343627913162944651610326227223181018112049964681593257039817928465162261554056717163455185836239700050722591467200836751176440475186610470858924533354404203178797691298187969195186445915618099387700277906471076451506648135742970391507268479908233030756728774292906382802333539018619144554926327386042866714403244881730657312556218544671735452018013192906666176304571098112023627646449344728729320151521856062479533665232206972350992029031130101562616188105003299089383937474928470587431922814845536612259243422013479767610873906164223695485612980187368418032513069628276597766484026189902662800467627"
* ],
* [
* "sex",
* "271612781741748687665631163781784222206986514919240510659600898968029891445471151340374711481358667080933602799465151302152730310941328163824139855273459669212454563496981737906428620709831548372960217382220735228294241139157912721406675788543368628640706883773505430341605507178302192478448403420429844258369780113256936326800300618260364727492596873395176617721423154793478355071876961603875133904077141347301216761853623832434363197681195408760576362459324272835870130171792194224358816706549727197034997151802079175002886327657912761140166088787418843410014259949206667591099405750162890671401313490922011115170898989631758033420729599135647363505910141148338618849922275418467656443189550"
* ]
* ]
* },
* "nonce": "478750980376935836730653"
* }
*/
log.info("----------------------------credOfferJson-------------------[{}]",credOfferJson);
// Prover gets CredentialDefinition from Ledger
JSONObject credOffer = new JSONObject(credOfferJson);
/**
* Alice 还需要获取Transcript Credential Offercred_def_id中对应的 Credential Definition 。
*/
String getCredDefRequest = Ledger.buildGetCredDefRequest(proverDid, credOffer.getString("cred_def_id")).get();
String getCredDefResponse = PoolUtils.ensurePreviousRequestApplied(pool, getCredDefRequest, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseResponseResult credDefIdInfo = Ledger.parseGetCredDefResponse(getCredDefResponse).get();
log.info("----------------------------credDefIdInfo-------------------[{}]",JSON.toJSONString(credDefIdInfo));
credDefId = credDefIdInfo.getId();
credDefJson = credDefIdInfo.getObjectJson();
// Prover creates Credential Request
/**
* Alice 拥有了创建颁发Faber Transcript Credential 的凭证请求的一切。
*/
AnoncredsResults.ProverCreateCredentialRequestResult credReqInfo =
Anoncreds.proverCreateCredentialReq(wallet_stuent, proverDid, credOfferJson,
credDefJson, COMMON_MASTER_SECRET).get();
log.info("----------------------------credReqInfo-------------------[{}]",credReqInfo);
String credReqJson = credReqInfo.getCredentialRequestJson();
String credReqMetadataJson = credReqInfo.getCredentialRequestMetadataJson();
// Issuer creates TailsReader
BlobStorageReader blobStorageReaderHandle = BlobStorageReader.openReader(TYPE, tailsWriterConfig).get();
// Issuer creates Credential
AnoncredsResults.IssuerCreateCredentialResult credRegInfo =
Anoncreds.issuerCreateCredential(wallet_school, credOfferJson, credReqJson,
GVT_CRED_VALUES2, revRegId,
blobStorageReaderHandle.getBlobStorageReaderHandle()).get();
/**
* {
* "schema_id": "ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0",
* "cred_def_id": "ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1",
* "rev_reg_id": "ToY8X3Q6PHcbQc4sFF974v:4:ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1:CL_ACCUM:tag1",
* "values": {
* "age": {
* "raw": "28",
* "encoded": "28"
* },
* "height": {
* "raw": "175",
* "encoded": "175"
* },
* "name": {
* "raw": "Alex",
* "encoded": "1139481716457488690172217916278103335"
* },
* "sex": {
* "raw": "male",
* "encoded": "5944657099558967239210949258394887428692050081607692519917050"
* }* }
* "signature":{
* "p_credential":{"m_2":"75901566995036267216218625262479869056220009330158995470292750728417866315510",
* "a":"1312453883722259963498379617919825170930130258141331020146963109550499858458204643851501330692578387765189670872687953203750734295210108837317842865973310648732488985431815320572083351805887728180518722030444869623798898308933922158513510727251849827879768797341094049867157542099271728974797472159431768318224035974864140874532510450763353806417273391106803419615919605902039577311754376210777442452609679112204027492374327507556518801226547036310090024522405405436690617258487914171666401521805694076564783656939283378450760736996932764650619106300064401613821443755370044453791059459839623226044146159106810944268","e":"259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742930316365758435296162413497750681908343","v":"6047829871196726845656441227848859089464628851589326022798420062215205190418012649073799907061612096614143081278918401044406031012161380761335232017839510594387066282377829582637762630799115153154274521012446843523427366824750842391332857277874332914140601418607227554772082047518950649957730539942341599699987844102215772219487321008807006441577335278841902003153428185542252290133141739580332246398597364277958882521491442979245281034883086484481563576933803331640553937714597709191781091233343824498071117960229723648985639873574944263724879600728620956105743220156393834441308325128971311380788286030543935558822335293252520514113507870697065726211844202647062484483635696462591332511104804083760726855179438159240386848706071378735563879911902895445511017496589200466602019972320028336676696165373160010539174341216"},"r_credential":{"sigma":"1 099540E071E77AFC6F8C44445D25E59E89B285E0770FFAFE83FE3E42BEB4080F 1 23A30458BA9E3C0C35757A0EA56BED500946C56B3AA45B36D712C69AD34E3A88 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8","c":"15583F861D911FF11492E8FD0503DC5C27DBE2CFED11E629B5BBD594356CEE25","vr_prime_prime":"0CFE6B8306FE258E95CF6807C0AAF0F7E3CA17146F90AA9A83CFE799094BB00E","witness_signature":{"sigma_i":"1 06AD2B6B3B2AE0D5911F459C9825D1D6277C6AF7BB81F377803CF38F276F14F9 1 0BF5CC082A0A197117BF8F152BEB8E756DBCA7AEEBA6F7B119A8759353F3AEDE 1 18FA70BBDF31E108F8CEB161A5C7DC7BB2D9E40C2D2298EFB91C503F1B4B3793 1 03CA4F76602CDB62BC8599442CC2988DEEFFA8F5B63E13EF9CB42DBF5FC967D4 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000","u_i":"1 0B331779BCAC6C8E3DFDF0C22CFF742FAF432234B484428D8F2B262CD9D3A2B0 1 1CA4BD74D4436CE296287B2686F82DE5C59AA01B1A0187F4C5B76229AC3EBB18 1 164F108C0D8ACF21809C29C7F3DE797D5BB4CB6D10CF37255A9DC7D35BFDB2BE 1 01EA2A10DA1DD580E7DD3EA62ACC5D97C08B4E303DAE467148FC0139175647B8 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000","g_i":"1 01360CAF520ECEA4E034ADAC5A90181FAD3649CFB1D1714732CD76D422C68AFF 1 077F325B46484778969383329B58C2B9548AE434ABDC18AF6525EBFC3E3226C6 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8"},"g_i":"1 01360CAF520ECEA4E034ADAC5A90181FAD3649CFB1D1714732CD76D422C68AFF 1 077F325B46484778969383329B58C2B9548AE434ABDC18AF6525EBFC3E3226C6 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8","i":1,"m2":"A7CEC3B772B15FE73C0882C5BECA93A5D6868C165DE3B9BC85FF07F6D88676F6"}},"signature_correctness_proof":{"se":"19794137728338194735576950298937268072832173636010843529813196562879651021848651278049986301119199794555022372662100489133820543587918941894855394974165244808644649249816044300979501816489913931120702471401974887140046490068032898174966710036897228205820362002369117311731597955778819968578784683294181651555604308427609236368705170497854100805397066880365420906844101053017644894529844615647458447990316513355344633543277989124708025422328575307865828791509874649106543076054353909349539269291634635604645027575508246245400733681160538279597220537170246215816570724500349066170073365116333206008363975790974600933927","c":"89951911482033840343685731445299090894688051041962761571169487222990754114295"},"rev_reg":{"accum":"21 1140EDD421D373B5C0CFB9C77A2645692DEC47515FE78F2143713D75CFA0024F5 21 121BD4C953E3A5A44B8123A0499888D0673AE9DDF2584B2E7EBB71E8D0376358C 6 85F112491FD8E66FE6C97431ADB29CE4E5E896A15E07BDF497A14B299B317311 4 37FA08CF4CE9CCAB2890CC93F3030624A904A1B4677F3C317DBE7EE6ED6D53A2 6 8F2012741E3906DB4854E969D21D061F66961624953CF72094B0EC5A8703F360 4 3F51CE8175F0E016ADD755186919D9531D1DC3AD72D9DB1F6897E87295E80022"},"witness":{"omega":"1 0000000000000000000000000000000000000000000000000000000000000000 1 0000000000000000000000000000000000000000000000000000000000000000 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000 1 0000000000000000000000000000000000000000000000000000000000000000 1 0000000000000000000000000000000000000000000000000000000000000000"}},revocId=1,revocRegDeltaJson={"ver":"1.0","value":{"prevAccum":"1 0000000000000000000000000000000000000000000000000000000000000000 1 0000000000000000000000000000000000000000000000000000000000000000 2 095E45DDF417D05FB10933FFC63D474548B7FFFF7888802F07FFFFFF7D07A8A8 1 0000000000000000000000000000000000000000000000000000000000000000 1 0000000000000000000000000000000000000000000000000000000000000000 1 0000000000000000000000000000000000000000000000000000000000000000","accum":"21 1140EDD421D373B5C0CFB9C77A2645692DEC47515FE78F2143713D75CFA0024F5 21 121BD4C953E3A5A44B8123A0499888D0673AE9DDF2584B2E7EBB71E8D0376358C 6 85F112491FD8E66FE6C97431ADB29CE4E5E896A15E07BDF497A14B299B317311 4 37FA08CF4CE9CCAB2890CC93F3030624A904A1B4677F3C317DBE7EE6ED6D53A2 6 8F2012741E3906DB4854E969D21D061F66961624953CF72094B0EC5A8703F360 4 3F51CE8175F0E016ADD755186919D9531D1DC3AD72D9DB1F6897E87295E80022","issued":[1]}}
*/
log.info("----------------------------credRegInfo-------------------[{}]",credRegInfo);
String credJson = credRegInfo.getCredentialJson();
String credRevId = credRegInfo.getRevocId();
String revocRegDeltaJson = credRegInfo.getRevocRegDeltaJson();
// Issuer posts RevocationRegistryDelta to Ledger
revRegEntryRequest = Ledger.buildRevocRegEntryRequest(issuerDid, revRegId, REVOC_REG_TYPE, revocRegDeltaJson).get();
Ledger.signAndSubmitRequest(pool, wallet_school, issuerDid, revRegEntryRequest).get();
// Prover gets RevocationRegistryDefinition
JSONObject credential = new JSONObject(credJson);
String getRevRegDefRequest = Ledger.buildGetRevocRegDefRequest(proverDid, credential.getString("rev_reg_id")).get();
String getRevRegDefResponse = PoolUtils.ensurePreviousRequestApplied(pool, getRevRegDefRequest, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseResponseResult revRegInfo1 = Ledger.parseGetRevocRegDefResponse(getRevRegDefResponse).get();
String revocRegDefJson = revRegInfo1.getObjectJson();
log.info("----------------------------revRegInfo1-------------------[{}]",revRegInfo1);
// Prover store received Credential
String credential1_id = Anoncreds.proverStoreCredential(wallet_stuent, "credential1_id",
credReqMetadataJson, credJson, credDefJson, revocRegDefJson).get();
/**
* id=ToY8X3Q6PHcbQc4sFF974v:4:ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1:CL_ACCUM:tag1,
*
* objectJson=
* {
* "ver": "1.0",
* "id": "ToY8X3Q6PHcbQc4sFF974v:4:ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1:CL_ACCUM:tag1",
* "revocDefType": "CL_ACCUM",
* "tag": "tag1",
* "credDefId": "ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1",
* "value": {
* "issuanceType": "ISSUANCE_ON_DEMAND",
* "maxCredNum": 5,
* "publicKeys": {
* "accumKey": {
* "z": "1 023DD2BF7399C0396943D5231DA7E2FCDDAECB7B6F6F7774DF4C8C3385B9CA75 1 062A9898E5DC67AF760377CD702EA95C0B60C799F53E2AAC27FE2EEAFA853BF1 1 1667EE5A78BF2A3C611C4F389A1CC20674509227C65FD981A73B171F35AF2109 1 1931F03BEFB4E38F3C77431E9D3A3584727EB03DCACD4645C0978C17155667C2 1 11A9D01DB80FE7AE05537C2DEC58F97D67C28E46E4544B83A552C4693BC1909A 1 22A5E585EF66D3D6DC06CA5549F137CDAA95CE7E22B29670176BE0A2825EBA6D 1 0CE38534523DAC4BA2540654A50E0205C7C74EA9587F56883A79EB16C53E4C21 1 10168D755EFE4132A59756215E93B6A21C05A29AF6FF740C7786A78367766687 1 0EA21589A63BBDB119410A6D9AC91DCB30368605193E5004C015C7C9F41736C5 1 1CF0499B025632DFB9CA0C17F3EC24F093473B064383FFFEF086BB34C0A5FD93 1 07BC8D30AE43217B6BA5E0D452C791E6841D94AE0285FB9B8E891FB5D2BB8588 1 114F58481F15A2439627AD01599086988ED13314515DC516557C551B3BAE95D0"
* }* },
* "tailsHash": "sxctqDLjmVvg7CXmbaA4dXrmz6UyhKXfxGfcZ7J577c",
* "tailsLocation": "/root/.indy_client/tails/sxctqDLjmVvg7CXmbaA4dXrmz6UyhKXfxGfcZ7J577c"
* }
* }
*/
log.info("--------------------------credential1_id-----------------[{}]",JSON.toJSONString(credential1_id));
log.info("--------------------------写入成功-----------------[{}]",true);
long to = System.currentTimeMillis() / 1000;
String proofRequest = new JSONObject().
put("nonce", "123432421212").
put("name", "proof_req_1").
put("version", "0.1").
put("requested_attributes", new JSONObject().
put("attr1_referent", new JSONObject().
put("name", "account").put("name","tel_no")
)).
put("requested_predicates", new JSONObject().
put("predicate1_referent", new JSONObject().put("name", name).put("p_type", p_type).put("p_value", p_value))).
put("non_revoked", new JSONObject().
put("to", to)).toString();
// Prover gets Claims for Proof Request
String credsJson = Anoncreds.proverGetCredentialsForProofReq(wallet_stuent, proofRequest).get();
/**
* {
* 'attrs': {
* 'attr1_referent': [{
* 'cred_info': {
* 'referent': 'credential1_id',
* 'attrs': {
* 'height': '175',
* 'name': 'Alex',
* 'age': '28',
* 'sex': 'male'
* },
* 'schema_id': 'ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0',
* 'cred_def_id': 'ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1',
* 'rev_reg_id': 'ToY8X3Q6PHcbQc4sFF974v:4:ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1:CL_ACCUM:tag1',
* 'cred_rev_id': '1'* },
* 'interval': {
* 'from': null,
* 'to': 1655714402
* }
* }]
* },
* 'predicates': {
* 'predicate1_referent': [{
* 'cred_info': {
* 'referent': 'credential1_id',
* 'attrs': {
* 'sex': 'male',
* 'height': '175',
* 'age': '28',
* 'name': 'Alex'
* },
* 'schema_id': 'ToY8X3Q6PHcbQc4sFF974v:2:gvt:1.0',
* 'cred_def_id': 'ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1',
* 'rev_reg_id': 'ToY8X3Q6PHcbQc4sFF974v:4:ToY8X3Q6PHcbQc4sFF974v:3:CL:176:tag1:CL_ACCUM:tag1',
* 'cred_rev_id': '1'
* },
* 'interval': {
* 'from': null,
* 'to': 1655714402
* }
* }]
* }
* }
*/
log.info("--------------------------credsJson-----------------[{}]",JSON.toJSONString(credsJson));
JSONObject credentials = new JSONObject(credsJson);
JSONArray credsForReferent = credentials.getJSONObject("attrs").getJSONArray("attr1_referent");
JSONObject cred_info = credsForReferent.getJSONObject(0).getJSONObject("cred_info");
// Prover gets RevocationRegistryDelta from Ledger
String getRevRegDeltaRequest = Ledger.buildGetRevocRegDeltaRequest(proverDid, cred_info.getString("rev_reg_id"), - 1, (int) to).get();
String getRevRegDeltaResponse = PoolUtils.ensurePreviousRequestApplied(pool, getRevRegDeltaRequest, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseRegistryResponseResult revRegInfo2 = Ledger.parseGetRevocRegDeltaResponse(getRevRegDeltaResponse).get();
log.info("--------------------------revRegInfo2-----------------[{}]",JSON.toJSONString(revRegInfo2));
revRegId = revRegInfo2.getId();
revocRegDeltaJson = revRegInfo2.getObjectJson();
long timestamp = revRegInfo2.getTimestamp();
// Prover creates RevocationState
String revStateJson = Anoncreds.createRevocationState(blobStorageReaderHandle.getBlobStorageReaderHandle(),
revocRegDefJson, revocRegDeltaJson, timestamp, credRevId).get();
log.info("--------------------------revStateJson-----------------[{}]",JSON.toJSONString(revStateJson));
// Prover gets Schema from Ledger
getSchemaRequest = Ledger.buildGetSchemaRequest(proverDid, cred_info.getString("schema_id")).get();
getSchemaResponse = PoolUtils.ensurePreviousRequestApplied(pool, getSchemaRequest, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseResponseResult schemaInfo2 = Ledger.parseGetSchemaResponse(getSchemaResponse).get();
log.info("--------------------------schemaInfo2-----------------[{}]",JSON.toJSONString(schemaInfo2));
String schemaId = schemaInfo2.getId();
schemaJson = schemaInfo2.getObjectJson();
// Prover creates Proof
String requestedCredentialsJson = new JSONObject().
put("self_attested_attributes", new JSONObject()).
put("requested_attributes", new JSONObject().
put("attr1_referent", new JSONObject().
put("cred_id", cred_info.get("referent")).
put("timestamp", timestamp).
put("revealed", true))).
put("requested_predicates", new JSONObject().
put("predicate1_referent", new JSONObject().
put("cred_id", cred_info.get("referent")).
put("timestamp", timestamp))).toString();
String schemasJson = new JSONObject().put(schemaId, new JSONObject(schemaJson)).toString();
String credDefsJson = new JSONObject().put(credDefId, new JSONObject(credDefJson)).toString();
String revStatesJson = new JSONObject().put(revRegId, new JSONObject().
put(String.valueOf(timestamp), new JSONObject(revStateJson))).toString();
log.info("--------------------------requestedCredentialsJson-----------------[{}]",JSON.toJSONString(requestedCredentialsJson));
String proofJson = Anoncreds.proverCreateProof(wallet_stuent, proofRequest,
requestedCredentialsJson, COMMON_MASTER_SECRET,
schemasJson, credDefsJson, revStatesJson).get();
log.info("--------------------------proofJson-----------------[{}]",JSON.toJSONString(proofJson));
JSONObject proof = new JSONObject(proofJson);
JSONObject identifier = proof.getJSONArray("identifiers").getJSONObject(0);
// Verifier gets Schema from Ledger
String getSchemaReq = Ledger.buildGetSchemaRequest(DID_MY1, identifier.getString("schema_id")).get();
String getSchemaResp = PoolUtils.ensurePreviousRequestApplied(pool, getSchemaReq, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseResponseResult schemaInfo3 = Ledger.parseGetSchemaResponse(getSchemaResp).get();
log.info("--------------------------schemaInfo3-----------------[{}]",JSON.toJSONString(schemaInfo3));
schemaId = schemaInfo3.getId();
schemaJson = schemaInfo3.getObjectJson();
// Verifier gets CredDef from Ledger
String getCredDefReq = Ledger.buildGetCredDefRequest(DID_MY1, identifier.getString("cred_def_id")).get();
String getCredDefResp = PoolUtils.ensurePreviousRequestApplied(pool, getCredDefReq, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseResponseResult credDefInfo3 = Ledger.parseGetCredDefResponse(getCredDefResp).get();
log.info("--------------------------credDefInfo3-----------------[{}]",JSON.toJSONString(credDefInfo3));
credDefId = credDefInfo3.getId();
credDefJson = credDefInfo3.getObjectJson();
// Verifier gets RevocationRegistryDefinition from Ledger
String getRevRegDefReq = Ledger.buildGetRevocRegDefRequest(DID_MY1, identifier.getString("rev_reg_id")).get();
String getRevRegDefResp = PoolUtils.ensurePreviousRequestApplied(pool, getRevRegDefReq, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseResponseResult revRegDefInfo3 = Ledger.parseGetRevocRegDefResponse(getRevRegDefResp).get();
log.info("--------------------------revRegDefInfo3-----------------[{}]",JSON.toJSONString(revRegDefInfo3));
String revRegDefId = revRegDefInfo3.getId();
revRegDefJson = revRegDefInfo3.getObjectJson();
// Verifier gets RevocationRegistry from Ledger
String getRevRegReq = Ledger.buildGetRevocRegRequest(DID_MY1, identifier.getString("rev_reg_id"), identifier.getInt("timestamp")).get();
String getRevRegResp = PoolUtils.ensurePreviousRequestApplied(pool, getRevRegReq, innerResponse -> {
JSONObject innerResponseObject = new JSONObject(innerResponse);
return !innerResponseObject.getJSONObject("result").isNull("seqNo");
});
LedgerResults.ParseRegistryResponseResult revRegInfo3 = Ledger.parseGetRevocRegResponse(getRevRegResp).get();
log.info("--------------------------revRegInfo3-----------------[{}]",JSON.toJSONString(revRegInfo3));
revRegId = revRegInfo3.getId();
String revRegJson = revRegInfo3.getObjectJson();
timestamp = revRegInfo3.getTimestamp();
schemasJson = new JSONObject().put(schemaId, new JSONObject(schemaJson)).toString();
credDefsJson = new JSONObject().put(credDefId, new JSONObject(credDefJson)).toString();
String revRegDefsJson = new JSONObject().put(revRegDefId, new JSONObject(revRegDefJson)).toString();
String revRegsJson = new JSONObject().put(revRegId, new JSONObject().
put(String.valueOf(timestamp), new JSONObject(revRegJson))).toString();
Boolean valid = Anoncreds.verifierVerifyProof(proofRequest,
proofJson,
schemasJson,
credDefsJson,
revRegDefsJson,
revRegsJson).get();
log.info("-----------------valid:[{}]-----proverDidInfo-:[{}]--------------------------",valid,JSON.toJSONString(proverDidInfo));
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (IndyException e) {
e.printStackTrace();
} finally {
closeWallet(wallet_school);
closeWallet(wallet_stuent);
closePool(pool);
}
}
public void closePool(Pool pool){
Optional.ofNullable(pool).ifPresent(t->{
try {
t.closePoolLedger().get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException|IndyException e) {
e.printStackTrace();
}
});
}
public void closeWallet(Wallet wallet){
Optional.ofNullable(wallet).ifPresent(t->{
try {
t.closeWallet().get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
} catch (ExecutionException|IndyException e) {
e.printStackTrace();
}
});
}