def __init__(self, remoter, hab, exc, doers=None, **kwa): self.hab = hab self.remoter = remoter self.exc = exc self.parser = parsing.Parser(ims=self.remoter.rxbs, framed=True, kvy=self.hab.kvy) # add tvy # exc=self.exc) doers = doers if doers is not None else [] doers.extend([self.msgDo]) super(Commandant, self).__init__(doers=doers, **kwa)
def test_replay_all(): """ Test conjoint replay all Setup database with events from Deb, Cam, Bev, abd Art Replay all the events in database. """ with basing.openDB(name="deb") as debDB, keeping.openKS(name="deb") as debKS, \ basing.openDB(name="cam") as camDB, keeping.openKS(name="cam") as camKS, \ basing.openDB(name="bev") as bevDB, keeping.openKS(name="bev") as bevKS, \ basing.openDB(name="art") as artDB, keeping.openKS(name="art") as artKS: # setup Deb's habitat using default salt multisig already incepts sith = ["1/2", "1/2", "1/2"] # weighted signing threshold debHab = habbing.Habitat(ks=debKS, db=debDB, isith=sith, icount=3, temp=True) assert debHab.ks == debKS assert debHab.db == debDB assert debHab.kever.prefixer.transferable # setup Cam's habitat using default salt multisig already incepts # Cam's receipts will be vrcs with 3 indexed sigantures attached sith = '2' # hex str of threshold int camHab = habbing.Habitat(ks=camKS, db=camDB, isith=sith, icount=3, temp=True) assert camHab.ks == camKS assert camHab.db == camDB assert camHab.kever.prefixer.transferable # setup Bev's habitat using default salt nonstransferable already incepts # Bev's receipts will be rcts with a receipt couple attached sith = '1' # hex str of threshold int bevHab = habbing.Habitat(ks=bevKS, db=bevDB, isith=sith, icount=1, transferable=False, temp=True) assert bevHab.ks == bevKS assert bevHab.db == bevDB assert not bevHab.kever.prefixer.transferable # setup Art's habitat using custom salt nonstransferable so not match Bev # already incepts # Art's receipts will be rcts with a receipt couple attached salt = coring.Salter(raw=b'abcdef0123456789').qb64 sith = '1' # hex str of threshold int artHab = habbing.Habitat(ks=artKS, db=artDB, isith=sith, icount=1, salt=salt, transferable=False, temp=True) assert artHab.ks == artKS assert artHab.db == artDB assert not artHab.kever.prefixer.transferable # Create series of event for Deb debMsgs = bytearray() debMsgs.extend(debHab.makeOwnInception()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.rotate()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.interact()) # Play debMsgs to Cam # create non-local kevery for Cam to process msgs from Deb camKevery = eventing.Kevery(db=camHab.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(debMsgs), kvy=camKevery) # camKevery.process(ims=bytearray(debMsgs)) # give copy to process assert debHab.pre in camKevery.kevers assert camKevery.kevers[debHab.pre].sn == debHab.kever.sn == 6 assert len(camKevery.cues) == 7 # get disjoints receipts (vrcs) from Cam of Deb's events by processing Cam's cues camMsgs = camHab.processCues(camKevery.cues) # Play camMsgs to Deb # create non-local kevery for Deb to process msgs from Cam debKevery = eventing.Kevery(db=debHab.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(camMsgs), kvy=debKevery) # debKevery.process(ims=bytearray(camMsgs)) # give copy to process assert camHab.pre in debKevery.kevers assert debKevery.kevers[camHab.pre].sn == camHab.kever.sn == 0 assert len(debKevery.cues) == 1 # get disjoints receipts (vrcs) from Deb of Cam's events by processing Deb's cues debCamVrcs = debHab.processCues(debKevery.cues) # Play disjoints debCamVrcs to Cam parsing.Parser().parseOne(ims=bytearray(debCamVrcs), kvy=camKevery) # camKevery.processOne(ims=bytearray(debCamVrcs)) # give copy to process # Play debMsgs to Bev # create non-local kevery for Bev to process msgs from Deb bevKevery = eventing.Kevery(db=bevHab.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(debMsgs), kvy=bevKevery) # bevKevery.process(ims=bytearray(debMsgs)) # give copy to process assert debHab.pre in bevKevery.kevers assert bevKevery.kevers[debHab.pre].sn == debHab.kever.sn == 6 assert len(bevKevery.cues) == 7 # get disjoints receipts (rcts) from Bev of Deb's events by processing Bevs's cues bevMsgs = bevHab.processCues(bevKevery.cues) # Play bevMsgs to Deb parsing.Parser().parse(ims=bytearray(bevMsgs), kvy=debKevery) # debKevery.process(ims=bytearray(bevMsgs)) # give copy to process assert bevHab.pre in debKevery.kevers assert debKevery.kevers[bevHab.pre].sn == bevHab.kever.sn == 0 assert len(debKevery.cues) == 1 # get disjoints receipts (vrcs) from Deb of Bev's events by processing Deb's cues debBevVrcs = debHab.processCues(debKevery.cues) # Play disjoints debBevVrcs to Bev parsing.Parser().parseOne(ims=bytearray(debBevVrcs), kvy=bevKevery) # bevKevery.processOne(ims=bytearray(debBevVrcs)) # give copy to process # now setup replay debAllFelMsgs = debHab.replayAll() assert len(debAllFelMsgs) == 11267 # create non-local kevery for Art to process conjoint replay msgs from Deb artKevery = eventing.Kevery(db=artHab.db, lax=False, local=False) # process Cam's inception so Art will proces Cam's vrcs without escrowing camIcpMsg = camHab.makeOwnInception() parsing.Parser().parse(ims=bytearray(camIcpMsg), kvy=artKevery) assert camHab.pre in artKevery.kevers assert len(artKevery.cues) == 1 # give copy to process in cloned mode artKevery.cloned = True parsing.Parser().parse(ims=bytearray(debAllFelMsgs), kvy=artKevery) assert debHab.pre in artKevery.kevers assert artKevery.kevers[debHab.pre].sn == debHab.kever.sn == 6 assert len(artKevery.cues) == 9 artAllFelMsgs = artHab.replayAll() assert len(artAllFelMsgs) == 11016 assert not os.path.exists(artKS.path) assert not os.path.exists(artDB.path) assert not os.path.exists(bevKS.path) assert not os.path.exists(bevDB.path) assert not os.path.exists(camKS.path) assert not os.path.exists(camDB.path) assert not os.path.exists(debKS.path) assert not os.path.exists(debDB.path) """End Test"""
def test_replay(): """ Test disjoint and conjoint replay Deb creates series of events. Deb replays Deb's events to Cam and collects Cam's receipts Deb replays Deb's events with Cam's recepts to Bev and collects Bev's receipts Deb replays Deb's events with both Cam's and Bev's receipts to Cam Compare replay of Deb's events with receipts by both Deb and Cam to confirm identical """ with basing.openDB(name="deb") as debDB, keeping.openKS(name="deb") as debKS, \ basing.openDB(name="cam") as camDB, keeping.openKS(name="cam") as camKS, \ basing.openDB(name="bev") as bevDB, keeping.openKS(name="bev") as bevKS, \ basing.openDB(name="art") as artDB, keeping.openKS(name="art") as artKS: # setup Deb's habitat using default salt multisig already incepts sith = ["1/2", "1/2", "1/2"] # weighted signing threshold debHab = habbing.Habitat(name='deb', ks=debKS, db=debDB, isith=sith, icount=3, temp=True) assert debHab.ks == debKS assert debHab.db == debDB assert debHab.kever.prefixer.transferable # setup Cam's habitat using default salt multisig already incepts # Cam's receipts will be vrcs with 3 indexed sigantures attached sith = '2' # hex str of threshold int camHab = habbing.Habitat(name='cam', ks=camKS, db=camDB, isith=sith, icount=3, temp=True) assert camHab.ks == camKS assert camHab.db == camDB assert camHab.kever.prefixer.transferable # setup Bev's habitat using default salt nonstransferable already incepts # Bev's receipts will be rcts with a receipt couple attached sith = '1' # hex str of threshold int bevHab = habbing.Habitat(name='bev', ks=bevKS, db=bevDB, isith=sith, icount=1, transferable=False, temp=True) assert bevHab.ks == bevKS assert bevHab.db == bevDB assert not bevHab.kever.prefixer.transferable # setup Art's habitat using custom salt nonstransferable so not match Bev # already incepts # Art's receipts will be rcts with a receipt couple attached salt = coring.Salter(raw=b'abcdef0123456789').qb64 sith = '1' # hex str of threshold int artHab = habbing.Habitat(name='art', ks=artKS, db=artDB, isith=sith, icount=1, salt=salt, transferable=False, temp=True) assert artHab.ks == artKS assert artHab.db == artDB assert not artHab.kever.prefixer.transferable # first setup disjoint replay then conjoint replay # Create series of event for Deb debMsgs = bytearray() debMsgs.extend(debHab.makeOwnInception()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.rotate()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.interact()) debMsgs.extend(debHab.interact()) assert debMsgs == ( b'{"v":"KERI10JSON00015b_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAaf' b'ez-encK314","s":"0","t":"icp","kt":["1/2","1/2","1/2"],"k":["DRx' b'CLERO9eSvG4fluzOsK52GCWCtKOZClVwA38Oa--MA","DCxzT16ikP6LKVJfr6hv' b'1jmhynm6I4-KoGYkJtd9uBro","DsDl5xSHnIlcGo13u5jDRr1jJMkQ34nEc5R6N' b'YsdPS2k"],"n":"Eer5S019j0eEFNFLb0R0UDMoNLavlLiQ73fHGU7MUHXg","bt' b'":"0","b":[],"c":[],"a":[]}-AADAA4HzkCruAhoxet6Vrk_tBCwbwaT78dRw' b'w9RQJb0MR_tmSpEYOYDue-pBQCthsgDJzjyElpSmzNedlY-hVd6rbDwABJnfOgI6' b'teO_3fESnXgiz_9J_F_VfQliLWvLCM8ZnVjrryBuiMYOUmHbfXuNtRC4iZxb-RU0' b'lC55O0r5c5hyrAgACnZEXW7jYpAdrIfmOmH-OEHmhxcwQNu31k-mmzyNTfFvAxmp' b'r7-zLdmzlWKfMBlE6eAbDgCdNr_VL2l8xeJExAA{"v":"KERI10JSON000098_",' b'"i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"1","t":"' b'ixn","p":"E4gF0E1fkpEPBjeq1Sm-RK_Rvg56KOmtBHGfNe_tPxWc","a":[]}-' b'AADAAvo8lxVzu4YS6nG3BXu7PncYdZO57P4gYY-ikaRepVIOeRnZ10iMdJGcyULm' b'mdXLRaVxtuxI956cJljg3joSMBgABgHtCeHi-UZjnI1IWW9ZF8E7ni6UwerFOvPV' b'7z3i1pI7D3HJCoSx8XkhdXPGzUtrNuAvxVptsJtF17_-rP50bBwACguCjTA2taPP' b'EyhVecWjtpoBJCAiYeTdeDv3Hq0pAJXWa7SWjxlDR2-f1TIIXg8PbBD_tgn4Z6zp' b'LZcPLLHH5Cg{"v":"KERI10JSON000190_","i":"EeTLHxy5Npa4SQlFABzhu66' b'FUuSl_iJAafez-encK314","s":"2","t":"rot","p":"EYROVd3Ho83kEgBkrN' b'v6kqTAG4YeCqyPWYBo2jCPteiw","kt":["1/2","1/2","1/2"],"k":["Dj-DU' b'wfCmOrE3ijqucR0I89_fYTFbyotaqeQyDfupkEU","DL-k_8BanjLYaAdm6WWKIp' b'HcHwcbF834vnLPgpW1NL8k","DWG2ZFsWYUsbDI1Kmu8JH22iGaVDGvM7pnuT4y2' b'oR3VI"],"n":"EYd4ha92A2yttnCoLMqFGRzh6nsgduE910LD-scP7C3Q","bt":' b'"0","br":[],"ba":[],"a":[]}-AADAAspTV94LrwMhYVzZD0xu16aKjf1YQ8nT' b'Ta08ik1Fah545jAoe6n1xdnKSgL9Alucp4F-Yl69ksAttb4hTlnikDwABKspYVa4' b'J3r7ox-gDsPbpI5jiFSTcDCjBJGfU6hWhMXx7zpgG1jt4cTeW83oaILMbW85i_U7' b'RT3x6Sm2z5ytCCQACf157-iV13AXKaIddVaXexNx5K9INhJ44tfpb3OBjuPk5JMj' b'VGIU0iz5LkQlc_rV9D79E1pC5Z--YGplzQMv0Ag{"v":"KERI10JSON000098_",' b'"i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"3","t":"' b'ixn","p":"EA4mqdTa4RPrUJ3B_lmEPSxQK50tDkxRRVwVlLzcAdb0","a":[]}-' b'AADAAte_OEI-pzZulc4454QS391RR5bPndHIoLG_vLsC4Qmedqz7o04zuisW-7mr' b'TcfU6ZWs7rlMdSHTBZFErsY-FDQABiHkOIixpSaHGZ80--2JzhmR0TCla09WiEJH' b'5gTd9XXmxDfzDVON9FgDqLKf_Tf1nmgRh_eQFXu42jfvQG4Q1AAACp478kKPjbh1' b'pCxlmqa65PplcTa9zG4zsdYz2raYOiregvotKK30LNXm58886gSuSnEWifJvb-zY' b'wvdK8GsgqBg{"v":"KERI10JSON000098_","i":"EeTLHxy5Npa4SQlFABzhu66' b'FUuSl_iJAafez-encK314","s":"4","t":"ixn","p":"Ecw6XFmjIeMiYp1MTG' b'e4KRk9HnygNpnORox6AaCfC44Y","a":[]}-AADAANlbayWV5QQdCTqmh9dSEb13' b'stiK3srIyL9z4FWMZr_nwejoqK9j9Ic6wBQiUVksayOmGVtknUWrDNOY-PzzgBQA' b'B2FONMatheF144ziEB7uJpGZa3vugxedmLFfOD5CcoX7z6eX6ZZ_fIVkOHRVOxmv' b'nfYyVF7uC8G40PeGgkh5eCAACSwyvmjZcik1VBQCCfh5Mq2SQLUvVfFg9plIanMR' b'Trp7bG_OXE5SSqou6VFNon3Ub8IlBA90-dR7DRRDNPQ5UBw{"v":"KERI10JSON0' b'00098_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"' b'5","t":"ixn","p":"EQW9ROsIuNEdKu_ZIm9zDPKIVallegMHz2PVygiZgttc",' b'"a":[]}-AADAAtjUR1rNouk9T92o22qUbNvptIEjrnqKU3eJTiwdDGoWIwhTLY1T' b'UunYYpqtbk55oaCyc_MXkP-6l57YDiOAsCwAB5Fl7CZj1P1-NsYgrf2caXvWTfkg' b'u15C61JRuRpDnjTtevCjxspLQw6hxeJ6-2mTZHqIHC3hzW01Ed2mFOC_eDAACV87' b'jI4scXXRlNfqXmRrsivc0p3vBIO1OLNC6fex-bFbwV6U8zd_pjWTDZLwCnDm3KJq' b'labzAfGxX32trskGpCQ{"v":"KERI10JSON000098_","i":"EeTLHxy5Npa4SQl' b'FABzhu66FUuSl_iJAafez-encK314","s":"6","t":"ixn","p":"E52dhrHeFM' b'AYWsROU3fPEmD8pCsO_Q2MfvLuZufX43o0","a":[]}-AADAAVe6bfQeaR2X8UIB' b'OS1HMVLWho7FETQ17FQly0USMiSVDIWh8KTEeW-ndMDUlDBBeNEf3UiwDIRE62-k' b'ICoofAwABk4ndaxtTYTLmlxWM2Qb38RYtwSRzr7KRRbhLmL_zLXa7KnoAkmCa9LL' b'ZT5o_6rNjuFruYo7eSL4JfFhCEEn_CwACdPvsbvEV30PaDhbDmdVqI9fzGOSp34e' b'oTChNPt_UGq3uvCAAlwJa66g4WndLiTkN_BmKZP8YCgn40mUj5TFnAQ') # Play debMsgs to Cam # create non-local kevery for Cam to process msgs from Deb camKevery = eventing.Kevery(db=camHab.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(debMsgs), kvy=camKevery) # camKevery.process(ims=bytearray(debMsgs)) # give copy to process assert debHab.pre in camKevery.kevers assert camKevery.kevers[debHab.pre].sn == debHab.kever.sn == 6 assert len(camKevery.cues) == 7 # get disjoints receipts (vrcs) from Cam of Deb's events by processing Cam's cues camMsgs = camHab.processCues(camKevery.cues) assert camMsgs == ( b'{"v":"KERI10JSON00014b_","i":"EnjQHu6cA7Mk4gdlnSbhaKtjOh23I2_1ZZ' b'9KYr-ZdNMg","s":"0","t":"icp","kt":"2","k":["DJBtEHHnzNtE-zxH1xe' b'X4wxs9rEfUQ8d1ancgJJ1BLKk","DMu6yPITjrOBoTPfsY-r1Rc0ead8GKmoCxA_' b'BugKehgY","DfhpvbNyYu1fxTBTXy8eCgghMcOYnxkgoGPBr0ZBZPQA"],"n":"E' b'J85AI0se7UiFBFL1Vl80PnmQ-0dU6q_NXCh6BlSJcKg","bt":"0","b":[],"c"' b':[],"a":[]}-AADAAya98TxjoKqXBaXKBKmu0_98hrOSjoq8YeT5HlKBZsBvGPGU' b'NE3Ex9lkhLTl-U_Gx_1JLqEYJJaVrGLaArb5pDAABiYDraSegcRyxe8Syrd3uYqN' b'HTcalW-_hgVqsUDEZcqdsbje2fBxHO4blsODaSDMm2Crvdj5uvaLch-svOBdEDgA' b'CVGMTILr9hF9NHVscjqi5yCvtkwMhtZHEqh_6v7N_flmXKCkN2AXAi9OEmf-pdXj' b'0UlLdab6MkOfbxSRsmrjTDQ{"v":"KERI10JSON000091_","i":"EeTLHxy5Npa' b'4SQlFABzhu66FUuSl_iJAafez-encK314","s":"0","t":"rct","d":"E4gF0E' b'1fkpEPBjeq1Sm-RK_Rvg56KOmtBHGfNe_tPxWc"}-FABEnjQHu6cA7Mk4gdlnSbh' b'aKtjOh23I2_1ZZ9KYr-ZdNMg0AAAAAAAAAAAAAAAAAAAAAAAEZdlVoasgQzvn7mj' b'ai5hTX7JgLyHrRkeo8Mf5SXL10ro-AADAAY7ru97WNltKYXVBeiqSQ2JhCU6W6Uv' b'wSmYQRNAQ7Vk3_VslqnAkQDApZwVY-I5nonPybqxS4riBoN8O2MvH3BwABNvm83-' b'pYo3WR7BAtg13vvHsaX2PfSZn7ajBCRzUXaQ0ZLNr0wJddMywcVtOrgY0myRmiNq' b'YvetEkb0PJwQG4AwACjit5HUQSAeEMyfC5GeAsPHsGqLwbYMJdqxuZrnzfE2xtXe' b'3dEz9iSKEFUbykO0f1ThpMLpjat3SsNtZUtn07CQ{"v":"KERI10JSON000091_"' b',"i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"1","t":' b'"rct","d":"EYROVd3Ho83kEgBkrNv6kqTAG4YeCqyPWYBo2jCPteiw"}-FABEnj' b'QHu6cA7Mk4gdlnSbhaKtjOh23I2_1ZZ9KYr-ZdNMg0AAAAAAAAAAAAAAAAAAAAAA' b'AEZdlVoasgQzvn7mjai5hTX7JgLyHrRkeo8Mf5SXL10ro-AADAAx2QNu8staqEHq' b'lv3z__tb9wPPuwTqF3uicXv5BAr3npLW541r9RKcDUQ1yMk1TWcs1vO2a_L2rwtC' b'h_pP8kzAgABk1B6jf72NOLhSIbAXTbM5JhxiFatklzqYCkiQw12jGxNOHxmEuKNF' b'0IatvNc3m96hcOb7dc2ZOIQGxX9Ud9nCwAC9LGHfopCtAgtC7OK-aOfYQXN36_Ll' b'RHZu3eeT9E_pFG9I0LYfoRNf0hGVcyPRBpqrIVOTkH1NBWRbVyOMSYhDA{"v":"K' b'ERI10JSON000091_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK' b'314","s":"2","t":"rct","d":"EA4mqdTa4RPrUJ3B_lmEPSxQK50tDkxRRVwV' b'lLzcAdb0"}-FABEnjQHu6cA7Mk4gdlnSbhaKtjOh23I2_1ZZ9KYr-ZdNMg0AAAAA' b'AAAAAAAAAAAAAAAAAAEZdlVoasgQzvn7mjai5hTX7JgLyHrRkeo8Mf5SXL10ro-A' b'ADAAmMLDAvNgoQ_hnYEfx6uzg0LzRuODZmgwhou-EZv83BNJ9JwNabG9oSuLL15Z' b'Zc0blUm8GJ0BJuBcE4rjNW3-CAABlkXt_qnbOaBjqlfNXbLxZ_Rx2SCy8pVSYSz7' b'-UbB2lHpIfGMApVcTamn4pYhyOnaEVVO47tWZ3vDmXkf3WrKBQAC4MZmfqt3B9SY' b'DROZk8shO6vWxzHfZVBzLtNZAJrJLq8FoZ66q3bG4Pgn1pc0ID0fjkpXSiR5aOF2' b'2QhT06erDA{"v":"KERI10JSON000091_","i":"EeTLHxy5Npa4SQlFABzhu66F' b'UuSl_iJAafez-encK314","s":"3","t":"rct","d":"Ecw6XFmjIeMiYp1MTGe' b'4KRk9HnygNpnORox6AaCfC44Y"}-FABEnjQHu6cA7Mk4gdlnSbhaKtjOh23I2_1Z' b'Z9KYr-ZdNMg0AAAAAAAAAAAAAAAAAAAAAAAEZdlVoasgQzvn7mjai5hTX7JgLyHr' b'Rkeo8Mf5SXL10ro-AADAASQpD32fjD-IJuz9w1CFLXYtHE-9rtVRqSvQPqT8yjHO' b'lKMNG2apDa___svlQSw_OmgsCB-LzQn7dyyv73w3KCQABcbrlJRw3GaM5l5NCq_7' b'czfZBAyXPwvpfjwM3BAMnt-tDmTEoJku4MpruiwpgSWcPw_Xp3SE3nmxPIK6-Q08' b'aCAAC58Bw2io7IEt3ZvfEdaHns97Y4QGCnFovmz9VFfp3c2Mjioa1sDgOf9uybHV' b'MKBhpsUy2_BfpgkVOhmcY6GtzCw{"v":"KERI10JSON000091_","i":"EeTLHxy' b'5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"4","t":"rct","d":"EQ' b'W9ROsIuNEdKu_ZIm9zDPKIVallegMHz2PVygiZgttc"}-FABEnjQHu6cA7Mk4gdl' b'nSbhaKtjOh23I2_1ZZ9KYr-ZdNMg0AAAAAAAAAAAAAAAAAAAAAAAEZdlVoasgQzv' b'n7mjai5hTX7JgLyHrRkeo8Mf5SXL10ro-AADAAsW_khBjW_8JTAMqSmfO719vBlr' b'NVpJu-8bpboWZm8hhYfKEEfUWC40GWoYwSN_Xk-2v6oPVp4_oHVVB4hMavAAABuR' b'VEC014QaDOacru4RchNJBZCa5jKhfK10vt-Mb88mQY-HF-kVywqvGnkFyCZowKPz' b'sLEJbTAa8py3hCKJ-5AQACo4tT9i1sv7JM6zhprqwklVnYKsG6Y1DCfGj6c6vIWz' b'StZeO_ICz9iOZkB8IuwJp8r5AYgqJlNl8cl93sgknZDw{"v":"KERI10JSON0000' b'91_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"5",' b'"t":"rct","d":"E52dhrHeFMAYWsROU3fPEmD8pCsO_Q2MfvLuZufX43o0"}-FA' b'BEnjQHu6cA7Mk4gdlnSbhaKtjOh23I2_1ZZ9KYr-ZdNMg0AAAAAAAAAAAAAAAAAA' b'AAAAAEZdlVoasgQzvn7mjai5hTX7JgLyHrRkeo8Mf5SXL10ro-AADAA_06qSZGjm' b'75-wLDLPBK-p32mM1oeDQAQD2wfdQ75jn-JRkYqGztS2tQDBFlxK4uiceok50-ZJ' b'f64An_oB649AQABZpuMeCzUi0oF98kXROI94G3cWLVrDVdbvxDNe60uE7rQ-qwDq' b'tErr65hMaCgbTO3zD9aumRQMU5-1uWZrIxWDQACyukFA_3zKJQyctI3JER5XO8r_' b'iz9Ga5CXxnZFqSuGmQqQEpA9wMDOZ66hRBRNgImMQh-btX4sqbjO_ycaGmjBg{"v' b'":"KERI10JSON000091_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-' b'encK314","s":"6","t":"rct","d":"ENsvgXw3H4VhL3i-eONdu7tgarzrgm9z' b'c2Lj3XlwZ2_4"}-FABEnjQHu6cA7Mk4gdlnSbhaKtjOh23I2_1ZZ9KYr-ZdNMg0A' b'AAAAAAAAAAAAAAAAAAAAAAEZdlVoasgQzvn7mjai5hTX7JgLyHrRkeo8Mf5SXL10' b'ro-AADAAEjRuwX1j8xEYIXjf1cmhLpmF4IwKBGU2fvL0rbbBMN4bA4VTtnAqo6Nh' b'GYK4XKKVL_SKLaL9x9PcFc5ykBqsBwABVwlNGkdx_oScxgYzhLMDmAi-Ro5n85ly' b'LRI6DdtMIRfpgyIa2pPw1BkA2FmmsUkkwdTWxNq77AyfbcQzDKOzDAACSIxniS9R' b'7dsM11Q8uD5qSAxcGyF-CUNYT7NZmQdL52MnszSYy7Mvpwnq9L842jNgL_G8zqif' b'0eizybIVsQj7AQ') # Play camMsgs to Deb # create non-local kevery for Deb to process msgs from Cam debKevery = eventing.Kevery(db=debHab.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(camMsgs), kvy=debKevery) # debKevery.process(ims=bytearray(camMsgs)) # give copy to process assert camHab.pre in debKevery.kevers assert debKevery.kevers[camHab.pre].sn == camHab.kever.sn == 0 assert len(debKevery.cues) == 1 # get disjoints receipts (vrcs) from Deb of Cam's events by processing Deb's cues debCamVrcs = debHab.processCues(debKevery.cues) assert debCamVrcs == ( b'{"v":"KERI10JSON000091_","i":"EnjQHu6cA7Mk4gdlnSbhaKtjOh23I2_1ZZ' b'9KYr-ZdNMg","s":"0","t":"rct","d":"EZdlVoasgQzvn7mjai5hTX7JgLyHr' b'Rkeo8Mf5SXL10ro"}-FABEeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK31' b'40AAAAAAAAAAAAAAAAAAAAAAgEA4mqdTa4RPrUJ3B_lmEPSxQK50tDkxRRVwVlLz' b'cAdb0-AADAARwO4P3VantEgLrBs4K7hvStQ_kpN5EiFjklROGNkV19PBtxO0uUU8' b'0RDbWBjuUgIm59v9oJQKe-hdS8neEI2CgABAptixkGIj7UX1PU9Vlr1kZexUaIie' b'AugElzH99gCfQG2MMtOb3EO5ybgMHkWKKr7PaTpi4H2XrQ-me-PT_fGAgACSUTaW' b'0o0XhD0bQn-Qv2TwDj01L8zRyy7dqlGemZSzl2DBnliA_NqGHBQ2QJKIZfuIc6Mc' b'c3n_HpqI6s7xt-jCQ') # Play disjoints debCamVrcs to Cam parsing.Parser().parseOne(ims=bytearray(debCamVrcs), kvy=camKevery) # camKevery.processOne(ims=bytearray(debCamVrcs)) # give copy to process # Play debMsgs to Bev # create non-local kevery for Bev to process msgs from Deb bevKevery = eventing.Kevery(db=bevHab.db, lax=False, local=False) parsing.Parser().parse(ims=bytearray(debMsgs), kvy=bevKevery) # bevKevery.process(ims=bytearray(debMsgs)) # give copy to process assert debHab.pre in bevKevery.kevers assert bevKevery.kevers[debHab.pre].sn == debHab.kever.sn == 6 assert len(bevKevery.cues) == 7 # get disjoints receipts (rcts) from Bev of Deb's events by processing Bevs's cues bevMsgs = bevHab.processCues(bevKevery.cues) assert bevMsgs == ( b'{"v":"KERI10JSON0000c1_","i":"BCqmHiYBZx_uaQiCTVeum-vt1ZPti8chqb' b'-GpQBPaurA","s":"0","t":"icp","kt":"1","k":["BCqmHiYBZx_uaQiCTVe' b'um-vt1ZPti8chqb-GpQBPaurA"],"n":"","bt":"0","b":[],"c":[],"a":[]' b'}-AABAAgO3RAPPeeFcl5ZvoIR55jsqjQsfKQNenz9EUITRBtu9Q5Js-Umzd_mvSq' b'ZymNJnwLL656s7P-hTZRtG-8-rhBg{"v":"KERI10JSON000091_","i":"EeTLH' b'xy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"0","t":"rct","d":"' b'E4gF0E1fkpEPBjeq1Sm-RK_Rvg56KOmtBHGfNe_tPxWc"}-CABBCqmHiYBZx_uaQ' b'iCTVeum-vt1ZPti8chqb-GpQBPaurA0B0VYuHkBtlKSqsXj_0-2mSNzQ9UOiO-iX' b'jG4V74ivokdt9GUYh5OnZ-lW-SfyzGhQv6QlPRcy7nWTyi_mMzOCAg{"v":"KERI' b'10JSON000091_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314' b'","s":"1","t":"rct","d":"EYROVd3Ho83kEgBkrNv6kqTAG4YeCqyPWYBo2jC' b'Pteiw"}-CABBCqmHiYBZx_uaQiCTVeum-vt1ZPti8chqb-GpQBPaurA0B_gS89Rl' b'Y4y-YTTgBpjdBiA6l8PbGZkd4ODmA3RQyDGVapnpMB_SLvolQuz7WxyE0NsnpJ-D' b'nVFTt-Dv-dKGADA{"v":"KERI10JSON000091_","i":"EeTLHxy5Npa4SQlFABz' b'hu66FUuSl_iJAafez-encK314","s":"2","t":"rct","d":"EA4mqdTa4RPrUJ' b'3B_lmEPSxQK50tDkxRRVwVlLzcAdb0"}-CABBCqmHiYBZx_uaQiCTVeum-vt1ZPt' b'i8chqb-GpQBPaurA0BcbCV4kKek9oab8MDhzvzf0ucYnTIzNiWHLNh65mpxUa2XL' b'jrEfbWlrjpiDXTyYShlLNt8fZxnnwoAW4aelTyBA{"v":"KERI10JSON000091_"' b',"i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"3","t":' b'"rct","d":"Ecw6XFmjIeMiYp1MTGe4KRk9HnygNpnORox6AaCfC44Y"}-CABBCq' b'mHiYBZx_uaQiCTVeum-vt1ZPti8chqb-GpQBPaurA0BZSz6DBrS702RsSJ2qhp5V' b'_4UG3u4v9_PZUxZqkTnBmkxkX-dA9Ml5c_2YaZ0_ETfhrbq30r1elT4gXhKJbRAA' b'A{"v":"KERI10JSON000091_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAa' b'fez-encK314","s":"4","t":"rct","d":"EQW9ROsIuNEdKu_ZIm9zDPKIVall' b'egMHz2PVygiZgttc"}-CABBCqmHiYBZx_uaQiCTVeum-vt1ZPti8chqb-GpQBPau' b'rA0BFvLdsWHk5oGOZQCnDEVww3dMlXZYo9JzNbuJUdK0IqWaJAQBIMEKOqLvZzMx' b'FIi6xNmJCQYKFu5328ovxtddCg{"v":"KERI10JSON000091_","i":"EeTLHxy5' b'Npa4SQlFABzhu66FUuSl_iJAafez-encK314","s":"5","t":"rct","d":"E52' b'dhrHeFMAYWsROU3fPEmD8pCsO_Q2MfvLuZufX43o0"}-CABBCqmHiYBZx_uaQiCT' b'Veum-vt1ZPti8chqb-GpQBPaurA0BDaF78ajVz3FOsApq_1iBTK2i1PT8F0Fgz4q' b'r4HuboYf5XMWR8IvrYcYvthaaRP5168Ge-npP6UgRUd7t8vwCDw{"v":"KERI10J' b'SON000091_","i":"EeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK314","' b's":"6","t":"rct","d":"ENsvgXw3H4VhL3i-eONdu7tgarzrgm9zc2Lj3XlwZ2' b'_4"}-CABBCqmHiYBZx_uaQiCTVeum-vt1ZPti8chqb-GpQBPaurA0B9TkOKxh1bS' b'1gwzpNCx5R-AW0D_xHbbBNlVSdyPW4VUJm4PvRCK9UFsHHk2LGv0KbqRe7ftiY6o' b'V7hSkY4rfGAw') # Play bevMsgs to Deb parsing.Parser().parse(ims=bytearray(bevMsgs), kvy=debKevery) # debKevery.process(ims=bytearray(bevMsgs)) # give copy to process assert bevHab.pre in debKevery.kevers assert debKevery.kevers[bevHab.pre].sn == bevHab.kever.sn == 0 assert len(debKevery.cues) == 1 # get disjoints receipts (vrcs) from Deb of Bev's events by processing Deb's cues debBevVrcs = debHab.processCues(debKevery.cues) assert debBevVrcs == ( b'{"v":"KERI10JSON000091_","i":"BCqmHiYBZx_uaQiCTVeum-vt1ZPti8chqb' b'-GpQBPaurA","s":"0","t":"rct","d":"ERejsDJsBCs9b2j0Cd3pIDxNoGEw8' b'zQd94AXMduyyIF8"}-FABEeTLHxy5Npa4SQlFABzhu66FUuSl_iJAafez-encK31' b'40AAAAAAAAAAAAAAAAAAAAAAgEA4mqdTa4RPrUJ3B_lmEPSxQK50tDkxRRVwVlLz' b'cAdb0-AADAApoGcQmhmFQ2tQmovG0aZNxBN3QMgynKdfVA3pNyJQ-UMBnliFkeaC' b'gioFRXuH9SLm3R1XlFjmIJNvZ7hoJ3bBQABLKipRIasV9TRzcoGF7sQs9vfkcneF' b'7y1YqKMw9oWKEzhJKMuk0QUz6E1fse8mUDazKQsXqY1uKnSFhfjuqAhBQACFrF4i' b'Nt4Cm0srlq1QsXwJe3duzNKOEdf4z-WxWSw49dDpYyfllWEIs8Eu65IADEycjZR3' b'q9BTeO9QARuieV_Dw') # Play disjoints debBevVrcs to Bev parsing.Parser().parseOne(ims=bytearray(debBevVrcs), kvy=bevKevery) # bevKevery.processOne(ims=bytearray(debBevVrcs)) # give copy to process # now setup conjoint replay # Replay Deb's First Seen Events with receipts (vrcs and rcts) from both Cam and Bev # datetime is different in each run in the fse attachment in clone replay # so we either have to force dts in db or we parse in pieces debFelMsgs = bytearray() fn = 0 cloner = debHab.db.clonePreIter(pre=debHab.pre, fn=fn) # create iterator msg = next(cloner) # get zeroth event with attachments assert len(msg) == 1423 debFelMsgs.extend(msg) # parse msg serder = coring.Serder(raw=msg) assert serder.raw == debHab.iserder.raw assert serder.sn == fn # no recovery forks so sn == fn assert serder.ked["t"] == coring.Ilks.icp del msg[:len(serder.raw)] assert len(msg) == 1076 counter = coring.Counter( qb64b=msg) # attachment length quadlets counter assert counter.code == coring.CtrDex.AttachedMaterialQuadlets assert counter.count == (len(msg) - len(counter.qb64b)) // 4 == 268 del msg[:len(counter.qb64b)] assert len(msg) == 1072 == 268 * 4 counter = coring.Counter(qb64b=msg) # indexed signatures counter assert counter.code == coring.CtrDex.ControllerIdxSigs assert counter.count == 3 # multisig deb del msg[:len(counter.qb64b)] assert len(msg) == 1068 for i in range(counter.count): # parse signatures siger = coring.Siger(qb64b=msg) del msg[:len(siger.qb64b)] assert len(msg) == 1068 - 3 * len(siger.qb64b) == 804 counter = coring.Counter(qb64b=msg) # trans receipt (vrc) counter assert counter.code == coring.CtrDex.TransReceiptQuadruples assert counter.count == 3 # multisig cam del msg[:len(counter.qb64b)] assert len(msg) == 800 for i in range(counter.count): # parse receipt quadruples prefixer, seqner, diger, siger = eventing.deTransReceiptQuadruple( msg, strip=True) assert len(msg) == 800 - 3 * (len(prefixer.qb64b) + len( seqner.qb64b) + len(diger.qb64b) + len(siger.qb64b)) == 200 counter = coring.Counter(qb64b=msg) # nontrans receipt (rct) counter assert counter.code == coring.CtrDex.NonTransReceiptCouples assert counter.count == 1 # single sig bev del msg[:len(counter.qb64b)] assert len(msg) == 196 for i in range(counter.count): # parse receipt couples prefixer, cigar = eventing.deReceiptCouple(msg, strip=True) assert len( msg) == 196 - 1 * (len(prefixer.qb64b) + len(cigar.qb64b)) == 64 counter = coring.Counter(qb64b=msg) # first seen replay couple counter assert counter.code == coring.CtrDex.FirstSeenReplayCouples assert counter.count == 1 del msg[:len(counter.qb64b)] assert len(msg) == 60 seqner = coring.Seqner(qb64b=msg) assert seqner.sn == fn == 0 del msg[:len(seqner.qb64b)] assert len(msg) == 36 # 24 less dater = coring.Dater(qb64b=msg) assert (helping.fromIso8601(helping.nowIso8601()) - helping.fromIso8601(dater.dts)) > datetime.timedelta() del msg[:len(dater.qb64b)] assert len(msg) == 0 # 36 less cloner.close() # must close or get lmdb error upon with exit """Exception ignored in: <generator object LMDBer.getAllOrdItemPreIter at 0x106fe1c10> Traceback (most recent call last): File "/Users/Load/Data/Code/public/keripy/src/keri/db/dbing.py", line 512, in getAllOrdItemPreIter yield (cn, bytes(val)) # (on, dig) of event lmdb.Error: Attempt to operate on closed/deleted/dropped object. """ fn += 1 cloner = debHab.db.clonePreIter(pre=debHab.pre, fn=fn) # create iterator not at 0 msg = next(cloner) # next event with attachments assert len(msg) == 1228 serder = coring.Serder(raw=msg) assert serder.sn == fn # no recovery forks so sn == fn assert serder.ked["t"] == coring.Ilks.ixn debFelMsgs.extend(msg) fn += 1 msg = next(cloner) # get zeroth event with attachments serder = coring.Serder(raw=msg) assert serder.sn == fn # no recovery forks so sn == fn assert serder.ked["t"] == coring.Ilks.rot assert len(msg) == 1476 assert ([verfer.qb64 for verfer in serder.verfers ] == [verfer.qb64 for verfer in debHab.kever.verfers]) debFelMsgs.extend(msg) fn += 1 while (fn <= 6): msg = next(cloner) # get zeroth event with attachments serder = coring.Serder(raw=msg) assert serder.sn == fn # no recovery forks so sn == fn assert serder.ked["t"] == coring.Ilks.ixn assert len(msg) == 1228 debFelMsgs.extend(msg) fn += 1 assert len(debFelMsgs) == 9039 cloner.close() # must close or get lmdb error upon with exit msgs = debHab.replay() assert msgs == debFelMsgs # Play Cam's messages to Bev parsing.Parser().parse(ims=bytearray(camMsgs), kvy=bevKevery) # bevKevery.process(ims=bytearray(camMsgs)) # give copy to process assert camHab.pre in bevKevery.kevers assert bevKevery.kevers[camHab.pre].sn == camHab.kever.sn == 0 assert len(bevKevery.cues) == 1 # Play Bev's messages to Cam parsing.Parser().parse(ims=bytearray(bevMsgs), kvy=camKevery) # camKevery.process(ims=bytearray(bevMsgs)) # give copy to process assert bevHab.pre in camKevery.kevers assert camKevery.kevers[bevHab.pre].sn == bevHab.kever.sn == 0 assert len(camKevery.cues) == 1 camDebFelMsgs = camHab.replay(pre=debHab.pre) bevDebFelMsgs = bevHab.replay(pre=debHab.pre) assert len(bevDebFelMsgs) == len(camDebFelMsgs) == len( debFelMsgs) == 9039 # create non-local kevery for Art to process conjoint replay msgs from Deb artKevery = eventing.Kevery(db=artHab.db, lax=False, local=False) # process Cam's inception so Art will proces Cam's vrcs without escrowing camIcpMsg = camHab.makeOwnInception() parsing.Parser().parse(ims=bytearray(camIcpMsg), kvy=artKevery) # artKevery.process(ims=bytearray(camIcpMsg)) assert camHab.pre in artKevery.kevers assert len(artKevery.cues) == 1 # process in cloned mode artKevery.cloned = True parsing.Parser().parse(ims=bytearray(debFelMsgs), kvy=artKevery) assert debHab.pre in artKevery.kevers assert artKevery.kevers[debHab.pre].sn == debHab.kever.sn == 6 assert len(artKevery.cues) == 8 artDebFelMsgs = artHab.replay(pre=debHab.pre) assert len(artDebFelMsgs) == 9039 assert not os.path.exists(artKS.path) assert not os.path.exists(artDB.path) assert not os.path.exists(bevKS.path) assert not os.path.exists(bevDB.path) assert not os.path.exists(camKS.path) assert not os.path.exists(camDB.path) assert not os.path.exists(debKS.path) assert not os.path.exists(debDB.path) """End Test"""
def test_direct_mode_with_manager(): """ Test direct mode with transferable validator event receipts """ # manual process to generate a list of secrets # root = pysodium.randombytes(pysodium.crypto_pwhash_SALTBYTES) # secrets = generateSecrets(root=root, count=8) # Direct Mode initiated by coe is controller, val is validator # but goes both ways once initiated. # set of secrets (seeds for private keys) coeSalt = Salter(raw=b'0123456789abcdea').qb64 # set of secrets (seeds for private keys) valSalt = Salter(raw=b'1123456789abcdea').qb64 with openDB("controller") as coeLogger, openDB("validator") as valLogger, \ openKS(name="controller") as coeKpr, openKS(name="validator") as valKpr: # Init key pair manager coeMgr = Manager(keeper=coeKpr, salt=coeSalt) coeVerfers, coeDigers, cst, nst = coeMgr.incept(icount=1, ncount=1) # init Keverys coeKevery = eventing.Kevery(db=coeLogger) valKevery = eventing.Kevery(db=valLogger) coe_event_digs = [] # list of controller's own event log digs to verify against database val_event_digs = [] # list of validator's own event log digs to verify against database # init sequence numbers for both controller and validator csn = cesn = 0 # sn and last establishment sn = esn vsn = vesn = 0 # sn and last establishment sn = esn # Controller Event 0 Inception Transferable (nxt digest not empty) coeSerder = incept(keys=[coeVerfers[0].qb64], nxt=eventing.Nexter(digs=[coeDigers[0].qb64]).qb64, code=MtrDex.Blake3_256) assert csn == int(coeSerder.ked["s"], 16) == 0 coepre = coeSerder.ked["i"] coe_event_digs.append(coeSerder.dig) # sign serialization sigers = coeMgr.sign(ser=coeSerder.raw, verfers=coeVerfers) # create serialized message cmsg = messagize(coeSerder, sigers=sigers) # create own Controller Kever in Controller's Kevery parsing.Parser().parseOne(ims=bytearray(cmsg), kvy=coeKevery) # coeKevery.processOne(ims=bytearray(cmsg)) # send copy of cmsg coeKever = coeKevery.kevers[coepre] assert coeKever.prefixer.qb64 == coepre # Validator Event 0 Inception Transferable (nxt digest not empty) # Init key pair manager valMgr = Manager(keeper=valKpr, salt=valSalt) valVerfers, valDigers, cst, nst = valMgr.incept(icount=1, ncount=1) valSerder = incept(keys=[valVerfers[0].qb64], nxt=eventing.Nexter(digs=[valDigers[0].qb64]).qb64, code=MtrDex.Blake3_256) assert vsn == int(valSerder.ked["s"], 16) == 0 valpre = valSerder.ked["i"] val_event_digs.append(valSerder.dig) # sign serialization sigers = valMgr.sign(valSerder.raw, verfers=valVerfers) # return Siger if index # create serialized message vmsg = messagize(valSerder, sigers=sigers) # create own Validator Kever in Validator's Kevery parsing.Parser().parseOne(ims=bytearray(vmsg), kvy=valKevery) # valKevery.processOne(ims=bytearray(vmsg)) # send copy of vmsg valKever = valKevery.kevers[valpre] assert valKever.prefixer.qb64 == valpre # simulate sending of controller's inception message to validator parsing.Parser().parse(ims=bytearray(cmsg), kvy=valKevery) # valKevery.process(ims=bytearray(cmsg)) # make copy of msg assert coepre in valKevery.kevers # creates Kever for controller in validator's .kevers # create receipt of controller's inception # create seal of validator's last establishment event seal = SealEvent(i=valpre, s="{:x}".format(valKever.lastEst.s), d=valKever.lastEst.d) coeK = valKevery.kevers[coepre] # lookup coeKever from validator's .kevers # create trans receipt reserder = receipt(pre=coeK.prefixer.qb64, sn=coeK.sn, dig=coeK.serder.diger.qb64) #reserder = chit(pre=coeK.prefixer.qb64, #sn=coeK.sn, #dig=coeK.serder.diger.qb64, #seal=seal) # Validate receipt # sign controller's event not receipt # look up event to sign from validator's kever for coe coeIcpDig = bytes(valKevery.db.getKeLast(key=snKey(pre=coepre, sn=csn))) assert coeIcpDig == coeK.serder.diger.qb64b coeIcpRaw = bytes(valKevery.db.getEvt(key=dgKey(pre=coepre, dig=coeIcpDig))) #counter = Counter(CtrDex.ControllerIdxSigs) #assert counter.qb64 == '-AAB' sigers = valMgr.sign(ser=coeIcpRaw, verfers=valVerfers) # return Siger if index # process own validator receipt in validator's Kevery so have copy in own log rmsg = messagize(reserder, sigers=sigers, seal=seal) assert len(rmsg) == 353 parsing.Parser().parseOne(ims=bytearray(rmsg), kvy=valKevery) # valKevery.processOne(ims=bytearray(rmsg)) # process copy of rmsg # attach receipt message to existing message with validators inception message # simulate streaming. validator first sends it's inception event, then sends a receipt to controller vmsg.extend(rmsg) # Simulate sending validator's inception event and receipt of # controller's inception message to controller parsing.Parser().parse(ims=vmsg, kvy=coeKevery) # coeKevery.process(ims=vmsg) # controller process validator's inception and receipt # check if validator's Kever in controller's .kevers assert valpre in coeKevery.kevers # check if receipt quadruple from validator in receipt database result = coeKevery.db.getVrcs(key=dgKey(pre=coeKever.prefixer.qb64, dig=coeKever.serder.diger.qb64)) assert bytes(result[0]) == (valKever.prefixer.qb64b + Seqner(sn=valKever.sn).qb64b + valKever.serder.diger.qb64b + sigers[0].qb64b) # create receipt to escrow use invalid digest and sequence number so not in controller's db fake = reserder.dig # some other digest reserder = receipt(pre=coeK.prefixer.qb64, sn=10, dig=fake) # sign event not receipt sigers = valMgr.sign(ser=coeIcpRaw, verfers=valVerfers) # return Siger if index # create receipt message vmsg = messagize(reserder, sigers=sigers, seal=seal) parsing.Parser().parse(ims=bytearray(vmsg), kvy=coeKevery) # coeKevery.process(ims=vmsg) # controller process the escrow receipt from validator # check if receipt quadruple in escrow database result = coeKevery.db.getVres(key=snKey(pre=coeKever.prefixer.qb64, sn=10)) assert bytes(result[0]) == (fake.encode("utf-8") + valKever.prefixer.qb64b + Seqner(sn=valKever.sn).qb64b + valKever.serder.diger.qb64b + sigers[0].qb64b) # Send receipt from controller to validator # create receipt of validator's inception # create seal of controller's last establishment event seal = SealEvent(i=coepre, s="{:x}".format(coeKever.lastEst.s), d=coeKever.lastEst.d) valK = coeKevery.kevers[valpre] # lookup valKever from controller's .kevers # create trans receipt reserder = receipt(pre=valK.prefixer.qb64, sn=valK.sn, dig=valK.serder.diger.qb64,) # sign validator's event not receipt # look up event to sign from controller's kever for validator valIcpDig = bytes(coeKevery.db.getKeLast(key=snKey(pre=valpre, sn=vsn))) assert valIcpDig == valK.serder.diger.qb64b valIcpRaw = bytes(coeKevery.db.getEvt(key=dgKey(pre=valpre, dig=valIcpDig))) sigers = coeMgr.sign(ser=valIcpRaw, verfers=coeVerfers) # return Siger if index # create receipt message cmsg = messagize(reserder, sigers=sigers, seal=seal) # controller process own receipt in own Kevery so have copy in own log parsing.Parser().parseOne(ims=bytearray(cmsg), kvy=coeKevery) # coeKevery.processOne(ims=bytearray(cmsg)) # make copy # Simulate sending controller's receipt of validator's inception message to validator parsing.Parser().parse(ims=cmsg, kvy=valKevery) # valKevery.process(ims=cmsg) # controller process validator's inception and receipt # check if receipt quadruple from controller in validator's receipt database result = valKevery.db.getVrcs(key=dgKey(pre=valKever.prefixer.qb64, dig=valKever.serder.diger.qb64)) assert bytes(result[0]) == (coeKever.prefixer.qb64b + Seqner(sn=coeKever.sn).qb64b + coeKever.serder.diger.qb64b + sigers[0].qb64b) # Controller Event 1 Rotation Transferable csn += 1 cesn += 1 assert csn == cesn == 1 coeVerfers, coeDigers, cst, nst = coeMgr.rotate(pre=coeVerfers[0].qb64) coeSerder = rotate(pre=coeKever.prefixer.qb64, keys=[coeVerfers[0].qb64], dig=coeKever.serder.diger.qb64, nxt=eventing.Nexter(digs=[coeDigers[0].qb64]).qb64, sn=csn) coe_event_digs.append(coeSerder.dig) # sign serialization sigers = coeMgr.sign(coeSerder.raw, verfers=coeVerfers) # returns sigers # create serialized message cmsg = messagize(coeSerder, sigers=sigers) # update controller's key event verifier state parsing.Parser().parseOne(ims=bytearray(cmsg), kvy=coeKevery) # coeKevery.processOne(ims=bytearray(cmsg)) # make copy # verify controller's copy of controller's event stream is updated assert coeKever.sn == csn assert coeKever.serder.diger.qb64 == coeSerder.dig # simulate send message from controller to validator parsing.Parser().parse(ims=cmsg, kvy=valKevery) # valKevery.process(ims=cmsg) # verify validator's copy of controller's event stream is updated assert coeK.sn == csn assert coeK.serder.diger.qb64 == coeSerder.dig # create receipt of controller's rotation # create seal of validator's last establishment event seal = SealEvent(i=valpre, s="{:x}".format(valKever.lastEst.s), d=valKever.lastEst.d) # create validator receipt reserder = receipt(pre=coeK.prefixer.qb64, sn=coeK.sn, dig=coeK.serder.diger.qb64) # sign controller's event not receipt # look up event to sign from validator's kever for controller coeRotDig = bytes(valKevery.db.getKeLast(key=snKey(pre=coepre, sn=csn))) assert coeRotDig == coeK.serder.diger.qb64b coeRotRaw = bytes(valKevery.db.getEvt(key=dgKey(pre=coepre, dig=coeRotDig))) sigers = valMgr.sign(ser=coeRotRaw, verfers=valVerfers) # validator create receipt message vmsg = messagize(reserder, sigers=sigers, seal=seal) # validator process own receipt in own kevery so have copy in own log parsing.Parser().parseOne(ims=bytearray(vmsg), kvy=valKevery) # valKevery.processOne(ims=bytearray(vmsg)) # make copy # Simulate send to controller of validator's receipt of controller's rotation message parsing.Parser().parse(ims=vmsg, kvy=coeKevery) # coeKevery.process(ims=vmsg) # controller process validator's incept and receipt # check if receipt quadruple from validator in receipt database result = coeKevery.db.getVrcs(key=dgKey(pre=coeKever.prefixer.qb64, dig=coeKever.serder.diger.qb64)) assert bytes(result[0]) == (valKever.prefixer.qb64b + Seqner(sn=valKever.sn).qb64b + valKever.serder.diger.qb64b + sigers[0].qb64b) # Next Event 2 Controller Interaction csn += 1 # do not increment esn assert csn == 2 assert cesn == 1 coeSerder = interact(pre=coeKever.prefixer.qb64, dig=coeKever.serder.diger.qb64, sn=csn) coe_event_digs.append(coeSerder.dig) # sign serialization sigers = coeMgr.sign(coeSerder.raw, verfers=coeVerfers) # create msg cmsg = messagize(coeSerder, sigers=sigers) # update controller's key event verifier state parsing.Parser().parseOne(ims=bytearray(cmsg), kvy=coeKevery) # coeKevery.processOne(ims=bytearray(cmsg)) # make copy # verify controller's copy of controller's event stream is updated assert coeKever.sn == csn assert coeKever.serder.diger.qb64 == coeSerder.dig # simulate send message from controller to validator parsing.Parser().parse(ims=cmsg, kvy=valKevery) # valKevery.process(ims=cmsg) # verify validator's copy of controller's event stream is updated assert coeK.sn == csn assert coeK.serder.diger.qb64 == coeSerder.dig # create receipt of controller's interaction # create seal of validator's last est event seal = SealEvent(i=valpre, s="{:x}".format(valKever.lastEst.s), d=valKever.lastEst.d) # create validator receipt reserder = receipt(pre=coeK.prefixer.qb64, sn=coeK.sn, dig=coeK.serder.diger.qb64) # sign controller's event not receipt # look up event to sign from validator's kever for controller coeIxnDig = bytes(valKevery.db.getKeLast(key=snKey(pre=coepre, sn=csn))) assert coeIxnDig == coeK.serder.diger.qb64b coeIxnRaw = bytes(valKevery.db.getEvt(key=dgKey(pre=coepre, dig=coeIxnDig))) sigers = valMgr.sign(ser=coeIxnRaw, verfers=valVerfers) # create receipt message vmsg = messagize(reserder, sigers=sigers, seal=seal) # validator process own receipt in own kevery so have copy in own log parsing.Parser().parseOne(ims=bytearray(vmsg), kvy=valKevery) # valKevery.processOne(ims=bytearray(vmsg)) # make copy # Simulate send to controller of validator's receipt of controller's rotation message parsing.Parser().parse(ims=bytearray(vmsg), kvy=coeKevery) # coeKevery.process(ims=vmsg) # controller process validator's incept and receipt # check if receipt quadruple from validator in receipt database result = coeKevery.db.getVrcs(key=dgKey(pre=coeKever.prefixer.qb64, dig=coeKever.serder.diger.qb64)) assert bytes(result[0]) == (valKever.prefixer.qb64b + Seqner(sn=valKever.sn).qb64b + valKever.serder.diger.qb64b + sigers[0].qb64b) # verify final controller event state assert coeKever.sn == coeK.sn == csn db_digs = [bytes(v).decode("utf-8") for v in coeKever.baser.getKelIter(coepre)] assert len(db_digs) == len(coe_event_digs) == csn + 1 assert db_digs == coe_event_digs db_digs = [bytes(v).decode("utf-8") for v in valKever.baser.getKelIter(coepre)] assert len(db_digs) == len(coe_event_digs) == csn + 1 assert db_digs == coe_event_digs # verify final validator event state assert valKever.sn == valK.sn == vsn db_digs = [bytes(v).decode("utf-8") for v in valKever.baser.getKelIter(valpre)] assert len(db_digs) == len(val_event_digs) == vsn + 1 assert db_digs == val_event_digs db_digs = [bytes(v).decode("utf-8") for v in coeKever.baser.getKelIter(valpre)] assert len(db_digs) == len(val_event_digs) == vsn + 1 assert db_digs == val_event_digs assert not os.path.exists(valKevery.db.path) assert not os.path.exists(coeKever.baser.path)
def test_witness(): """ Test event validation logic with witnesses cam is controller van is validator wes is a witness wok is a witness wam is a witness """ salt = coring.Salter(raw=b'abcdef0123456789').qb64 with basing.openDB(name="cam") as camDB, keeping.openKS(name="cam") as camKS, \ basing.openDB(name="van") as vanDB, keeping.openKS(name="van") as vanKS, \ basing.openDB(name="wes") as wesDB, keeping.openKS(name="wes") as wesKS, \ basing.openDB(name="wok") as wokDB, keeping.openKS(name="wok") as wokKS, \ basing.openDB(name="wam") as wamDB, keeping.openKS(name="wam") as wamKS, \ basing.openDB(name="wil") as wilDB, keeping.openKS(name="wil") as wilKS: # witnesses first so can setup inception event for cam wsith = 1 # setup Wes's habitat nontrans # Wes's receipts will be rcts with a receipt couple attached wesHab = habbing.Habitat(name='wes', ks=wesKS, db=wesDB, isith=wsith, icount=1, salt=salt, transferable=False, temp=True) # stem is .name assert wesHab.ks == wesKS assert wesHab.db == wesDB assert not wesHab.kever.prefixer.transferable # create non-local kevery for Wes to process nonlocal msgs wesKvy = eventing.Kevery(db=wesHab.db, lax=False, local=False) # setup Wok's habitat nontrans # Wok's receipts will be rcts with a receipt couple attached wokHab = habbing.Habitat(name='wok', ks=wokKS, db=wokDB, isith=wsith, icount=1, salt=salt, transferable=False, temp=True) # stem is .name assert wokHab.ks == wokKS assert wokHab.db == wokDB assert not wokHab.kever.prefixer.transferable # create non-local kevery for Wok to process nonlocal msgs wokKvy = eventing.Kevery(db=wokHab.db, lax=False, local=False) # setup Wam's habitat nontrans # Wams's receipts will be rcts with a receipt couple attached wamHab = habbing.Habitat(name='wam', ks=wamKS, db=wamDB, isith=wsith, icount=1, salt=salt, transferable=False, temp=True) # stem is .name assert wamHab.ks == wamKS assert wamHab.db == wamDB assert not wamHab.kever.prefixer.transferable # create non-local kevery for Wam to process nonlocal msgs wamKvy = eventing.Kevery(db=wamHab.db, lax=False, local=False) # setup Wil's habitat nontrans # Wil's receipts will be rcts with a receipt couple attached wilHab = habbing.Habitat(name='wil', ks=wilKS, db=wilDB, isith=wsith, icount=1, salt=salt, transferable=False, temp=True) # stem is .name assert wilHab.ks == wilKS assert wilHab.db == wilDB assert not wilHab.kever.prefixer.transferable # create non-local kevery for Wam to process nonlocal msgs wilKvy = eventing.Kevery(db=wilHab.db, lax=False, local=False) # setup Cam's habitat trans multisig wits = [wesHab.pre, wokHab.pre, wamHab.pre] csith = 2 # hex str of threshold int camHab = habbing.Habitat(name='cam', ks=camKS, db=camDB, isith=csith, icount=3, toad=2, wits=wits, salt=salt, temp=True) # stem is .name assert camHab.ks == camKS assert camHab.db == camDB assert camHab.kever.prefixer.transferable for werfer in camHab.iserder.werfers: assert werfer.qb64 in wits assert camHab.kever.wits == wits assert camHab.kever.toad == 2 assert camHab.kever.sn == 0 # create non-local kevery for Cam to process onlocal msgs camKvy = eventing.Kevery(db=camHab.db, lax=False, local=False) # setup Van's habitat trans multisig vsith = 2 # two of three signing threshold vanHab = habbing.Habitat(name='van', ks=vanKS, db=vanDB, isith=vsith, icount=3, salt=salt, temp=True) # stem is .name assert vanHab.ks == vanKS assert vanHab.db == vanDB assert vanHab.kever.prefixer.transferable # create non-local kevery for Van to process nonlocal msgs vanKvy = eventing.Kevery(db=vanHab.db, lax=False, local=False) # make list so easier to batch camWitKvys = [wesKvy, wokKvy, wamKvy] camWitHabs = [wesHab, wokHab, wamHab] # Create Cam inception and send to each of Cam's witnesses camIcpMsg = camHab.makeOwnInception() rctMsgs = [] # list of receipts from each witness for i in range(len(camWitKvys)): kvy = camWitKvys[i] parsing.Parser().parse(ims=bytearray(camIcpMsg), kvy=kvy) # kvy.process(ims=bytearray(camIcpMsg)) # send copy of cam icp msg to witness assert kvy.kevers[camHab.pre].sn == 0 # accepted event assert len(kvy.cues) == 1 # queued receipt cue hab = camWitHabs[i] rctMsg = hab.processCues(kvy.cues) # process cue returns rct msg assert len(rctMsg) == 566 rctMsgs.append(rctMsg) for msg in rctMsgs: # process rct msgs from all witnesses parsing.Parser().parse(ims=bytearray(msg), kvy=camKvy) # camKvy.process(ims=bytearray(msg)) # make copy for hab in camWitHabs: assert hab.pre in camKvy.kevers # get from Cam database copies of witness receipts received by Cam # and send to witnesses so all witnesses have full set of receipts # from all other witnesses # reply one event or receipt one event with all witness attachments dgkey = dbing.dgKey(pre=camHab.pre, dig=camHab.kever.serder.dig) wigs = camHab.db.getWigs(dgkey) assert len(wigs) == 3 wigers = [coring.Siger(qb64b=bytes(wig)) for wig in wigs] rserder = eventing.receipt(pre=camHab.pre, sn=camHab.kever.sn, dig=camHab.kever.serder.dig) camIcpWitRctMsg = eventing.messagize(serder=rserder, wigers=wigers) assert len(camIcpWitRctMsg) == 413 for i in range(len(camWitKvys)): kvy = camWitKvys[i] parsing.Parser().parse(ims=bytearray(camIcpWitRctMsg), kvy=kvy) # kvy.process(ims=bytearray(camIcpWitRctMsg)) # send copy of witness rcts assert len(kvy.db.getWigs(dgkey)) == 3 # fully witnessed assert len(kvy.cues) == 0 # no cues # send Cam icp and witness rcts to Van parsing.Parser().parse(ims=bytearray(camIcpMsg), kvy=vanKvy) # vanKvy.process(ims=bytearray(camIcpMsg)) # should escrow since not witnesses assert camHab.pre not in vanKvy.kevers parsing.Parser().parse(ims=bytearray(camIcpWitRctMsg), kvy=vanKvy) # vanKvy.process(ims=bytearray(camIcpWitRctMsg)) vanKvy.processEscrows() assert camHab.pre in vanKvy.kevers vcKvr = vanKvy.kevers[camHab.pre] assert vcKvr.sn == 0 assert vcKvr.wits == wits # Create Cam ixn and send to each of Cam's witnesses camIxnMsg = camHab.interact() rctMsgs = [] # list of receipts from each witness for i in range(len(camWitKvys)): kvy = camWitKvys[i] parsing.Parser().parse(ims=bytearray(camIxnMsg), kvy=kvy) # kvy.process(ims=bytearray(camIxnMsg)) # send copy of cam icp msg to witness assert kvy.kevers[camHab.pre].sn == 1 # accepted event assert len(kvy.cues) == 1 # queued receipt cue hab = camWitHabs[i] rctMsg = hab.processCues(kvy.cues) # process cue returns rct msg assert len(rctMsg) == 281 rctMsgs.append(rctMsg) for msg in rctMsgs: # process rct msgs from all witnesses parsing.Parser().parse(ims=bytearray(msg), kvy=camKvy) # camKvy.process(ims=bytearray(msg)) # make copy for hab in camWitHabs: assert hab.pre in camKvy.kevers # get from Cam database copies of witness receipts received by Cam # and send to witnesses so all witnesses have full set of receipts # from all other witnesses # reply one event or receipt one event with all witness attachments dgkey = dbing.dgKey(pre=camHab.pre, dig=camHab.kever.serder.dig) wigs = camHab.db.getWigs(dgkey) assert len(wigs) == 3 wigers = [coring.Siger(qb64b=bytes(wig)) for wig in wigs] rserder = eventing.receipt(pre=camHab.pre, sn=camHab.kever.sn, dig=camHab.kever.serder.dig) camIxnWitRctMsg = eventing.messagize(serder=rserder, wigers=wigers) assert len(camIxnWitRctMsg) == 413 for i in range(len(camWitKvys)): kvy = camWitKvys[i] parsing.Parser().parse(ims=bytearray(camIxnWitRctMsg), kvy=kvy) # kvy.process(ims=bytearray(camIxnWitRctMsg)) # send copy of witness rcts assert len(kvy.db.getWigs(dgkey)) == 3 # fully witnessed assert len(kvy.cues) == 0 # no cues # send Cam ixn's witness rcts to Van first then send Cam ixn parsing.Parser().parse(ims=bytearray(camIxnWitRctMsg), kvy=vanKvy) # vanKvy.process(ims=bytearray(camIxnWitRctMsg)) vanKvy.processEscrows() assert vcKvr.sn == 0 parsing.Parser().parse(ims=bytearray(camIxnMsg), kvy=vanKvy) # vanKvy.process(ims=bytearray(camIxnMsg)) # should escrow since not witnesses assert vcKvr.sn == 0 vanKvy.processEscrows() assert vcKvr.sn == 1 # Cam replace Wok with Wil as a witness. # Cam update Wil all event witnessed events for Cam by replay # Cam update itself with Wil receipts including Wils inception camReplayMsg = camHab.replay() assert len(camReplayMsg) == 1831 parsing.Parser().parse(ims=bytearray(camReplayMsg), kvy=wilKvy) # wilKvy.process(ims=bytearray(camReplayMsg)) assert camHab.pre in wilKvy.kevers assert wilKvy.kevers[camHab.pre].sn == 1 # asscepted both events assert len(wilKvy.cues) == 2 wilRctMsg = wilHab.processCues( wilKvy.cues) # process cue returns rct msg assert len(wilKvy.cues) == 0 parsing.Parser().parse(ims=bytearray(wilRctMsg), kvy=camKvy) # camKvy.process(ims=bytearray(wilRctMsg)) # make copy assert wilHab.pre in camKvy.kevers # Cam rotation with witness rotation camRotMsg = camHab.rotate(toad=2, cuts=[wokHab.pre], adds=[wilHab.pre]) assert camHab.kever.wits == [wesHab.pre, wamHab.pre, wilHab.pre] assert camHab.kever.toad == 2 assert camHab.kever.sn == 2 # update lists of witness kvys and habs camWitKvys = [wesKvy, wamKvy, wilKvy] camWitHabs = [wesHab, wamHab, wilHab] rctMsgs = [] # list of receipt msgs from each witness for i in range(len(camWitKvys)): kvy = camWitKvys[i] parsing.Parser().parse(ims=bytearray(camRotMsg), kvy=kvy) # kvy.process(ims=bytearray(camRotMsg)) # send copy of cam msg to witness assert kvy.kevers[camHab.pre].sn == 2 # accepted event assert len(kvy.cues) == 1 # queued receipt cue hab = camWitHabs[i] rctMsg = hab.processCues(kvy.cues) # process cue returns rct msg assert len(rctMsg) == 281 rctMsgs.append(rctMsg) for msg in rctMsgs: # process rct msgs from all witnesses parsing.Parser().parse(ims=bytearray(msg), kvy=camKvy) # camKvy.process(ims=bytearray(msg)) # make copy for hab in camWitHabs: assert hab.pre in camKvy.kevers # get from Cam database copies of witness receipts received by Cam # and send to witnesses so all witnesses have full set of receipts # from all other witnesses # reply one event or receipt one event with all witness attachments dgkey = dbing.dgKey(pre=camHab.pre, dig=camHab.kever.serder.dig) wigs = camHab.db.getWigs(dgkey) assert len(wigs) == 3 wigers = [coring.Siger(qb64b=bytes(wig)) for wig in wigs] rserder = eventing.receipt(pre=camHab.pre, sn=camHab.kever.sn, dig=camHab.kever.serder.dig) camRotWitRctMsg = eventing.messagize(serder=rserder, wigers=wigers) assert len(camRotWitRctMsg) == 413 for i in range(len(camWitKvys)): kvy = camWitKvys[i] parsing.Parser().parse(ims=bytearray(camRotWitRctMsg), kvy=kvy) # kvy.process(ims=bytearray(camRotWitRctMsg)) # send copy of witness rcts assert len(kvy.db.getWigs(dgkey)) == 3 # fully witnessed assert len(kvy.cues) == 0 # no cues # send Cam's rot and wit receipts to Van #vanKvy.process(ims=bytearray(camRotMsg)) # should escrow since not witnesses #vanKvy.process(ims=bytearray(camRotWitRctMsg)) #vanKvy.processEscrows() #assert vcKvr.sn == 2 #assert vcKvr.wits == camHab.kever.wits # send Cam rot's witness rcts to Van first then send Cam rot parsing.Parser().parse(ims=bytearray(camRotWitRctMsg), kvy=vanKvy) # vanKvy.process(ims=bytearray(camRotWitRctMsg)) vanKvy.processEscrows() assert vcKvr.sn == 1 parsing.Parser().parse(ims=bytearray(camRotMsg), kvy=vanKvy) # vanKvy.process(ims=bytearray(camRotMsg)) # should escrow since not witnesses assert vcKvr.sn == 1 vanKvy.processEscrows() assert vcKvr.sn == 2 assert vcKvr.wits == camHab.kever.wits assert not os.path.exists(wokKS.path) assert not os.path.exists(wokDB.path) assert not os.path.exists(wesKS.path) assert not os.path.exists(wesDB.path) assert not os.path.exists(vanKS.path) assert not os.path.exists(vanDB.path) assert not os.path.exists(camKS.path) assert not os.path.exists(camDB.path) """End Test"""
def test_delegation(): """ Test creation and validation of delegated identifer prefixes and events """ # bob is the delegator del is bob's delegate bobSalt = coring.Salter(raw=b'0123456789abcdef').qb64 delSalt = coring.Salter(raw=b'abcdef0123456789').qb64 with basing.openDB(name="bob") as bobDB, \ keeping.openKS(name="bob") as bobKS, \ basing.openDB(name="del") as delDB, \ keeping.openKS(name="del") as delKS: # Init key pair managers bobMgr = keeping.Manager(keeper=bobKS, salt=bobSalt) delMgr = keeping.Manager(keeper=delKS, salt=delSalt) # Init Keverys bobKvy = eventing.Kevery(db=bobDB) delKvy = eventing.Kevery(db=delDB) # Setup Bob by creating inception event verfers, digers, cst, nst = bobMgr.incept( stem='bob', temp=True) # algo default salty and rooted bobSrdr = eventing.incept( keys=[verfer.qb64 for verfer in verfers], nxt=coring.Nexter(digs=[diger.qb64 for diger in digers]).qb64, code=coring.MtrDex.Blake3_256) bob = bobSrdr.ked["i"] assert bob == 'Eta8KLf1zrE5n-HZpgRAnDmxLASZdXEiU9u6aahqR8TI' bobMgr.move(old=verfers[0].qb64, new=bob) # move key pair label to prefix sigers = bobMgr.sign(ser=bobSrdr.raw, verfers=verfers) msg = bytearray(bobSrdr.raw) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == ( b'{"v":"KERI10JSON0000ed_","i":"Eta8KLf1zrE5n-HZpgRAnDmxLASZdXEiU9' b'u6aahqR8TI","s":"0","t":"icp","kt":"1","k":["DqI2cOZ06RwGNwCovYU' b'WExmdKU983IasmUKMmZflvWdQ"],"n":"E7FuL3Z_KBgt_QAwuZi1lUFNC69wvyH' b'SxnMFUsKjZHss","bt":"0","b":[],"c":[],"a":[]}-AABAAp8S6RgfLwdCEi' b'z0jL9cXaDwTJF6MLuKyXp7EfJtrp2myOikOJVUB-w9UGZc1Y8dnURxhXPSca-ZEU' b'AV73XOaAw') # apply msg to bob's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=bobKvy) # bobKvy.process(ims=bytearray(msg)) # process local copy of msg bobK = bobKvy.kevers[bob] assert bobK.prefixer.qb64 == bob assert bobK.serder.diger.qb64 == bobSrdr.dig assert bobK.serder.diger.qb64 == 'E1-QL0TCdsBTRaKoakLjFhjSlELK60Vv8WdRaG6zMnTM' # apply msg to del's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=delKvy) # delKvy.process(ims=bytearray(msg)) # process remote copy of msg assert bob in delKvy.kevers # Setup Del's inception event assuming that Bob's next event will be an ixn delegating event verfers, digers, cst, nst = delMgr.incept( stem='del', temp=True) # algo default salty and rooted delSrdr = eventing.delcept( keys=[verfer.qb64 for verfer in verfers], delpre=bobK.prefixer.qb64, nxt=coring.Nexter(digs=[diger.qb64 for diger in digers]).qb64) delPre = delSrdr.ked["i"] assert delPre == 'E-9tsnVcfUyXVQyBPGfntoL-xexf4Cldt_EPzHis2W4U' delMgr.move(old=verfers[0].qb64, new=delPre) # move key pair label to prefix assert delSrdr.dig == 'E1x1JOub6oEQkxAxTNFu1Pma6y-lrbprNsaILHJHoPmY' # Now create delegating event seal = eventing.SealEvent(i=delPre, s=delSrdr.ked["s"], d=delSrdr.dig) bobSrdr = eventing.interact(pre=bobK.prefixer.qb64, dig=bobK.serder.diger.qb64, sn=bobK.sn + 1, data=[seal._asdict()]) assert bobSrdr.dig == 'E3fUycq1G-P1K1pL2OhvY6ZU-9otSa3hXiCcrxuhjyII' sigers = bobMgr.sign(ser=bobSrdr.raw, verfers=bobK.verfers) msg = bytearray(bobSrdr.raw) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == ( b'{"v":"KERI10JSON000107_","i":"Eta8KLf1zrE5n-HZpgRAnDmxLASZdXEiU9' b'u6aahqR8TI","s":"1","t":"ixn","p":"E1-QL0TCdsBTRaKoakLjFhjSlELK6' b'0Vv8WdRaG6zMnTM","a":[{"i":"E-9tsnVcfUyXVQyBPGfntoL-xexf4Cldt_EP' b'zHis2W4U","s":"0","d":"E1x1JOub6oEQkxAxTNFu1Pma6y-lrbprNsaILHJHo' b'PmY"}]}-AABAAROVSK0qK2gqlr_OUsnHNW_ksCyLVmRaysRne2dI5dweECGIy3_Z' b'uFHyOofiDRt5tRE09PlS0uZdot6byFNr-AA') # apply msg to bob's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=bobKvy) # bobKvy.process(ims=bytearray(msg)) # process local copy of msg assert bobK.serder.diger.qb64 == bobSrdr.dig # key state updated so event was validated # apply msg to del's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=delKvy) # delKvy.process(ims=bytearray(msg)) # process remote copy of msg assert delKvy.kevers[bob].serder.diger.qb64 == bobSrdr.dig # now create msg with Del's delegated inception event sigers = delMgr.sign(ser=delSrdr.raw, verfers=verfers) #seal = eventing.SealSource(s="{:x}".format(bobK.sn+1), #d=bobSrdr.diger.qb64) msg = bytearray(delSrdr.raw) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) counter = coring.Counter(code=coring.CtrDex.SealSourceCouples, count=1) msg.extend(counter.qb64b) seqner = coring.Seqner(sn=bobK.sn) msg.extend(seqner.qb64b) msg.extend(bobSrdr.diger.qb64b) assert msg == ( b'{"v":"KERI10JSON000121_","i":"E-9tsnVcfUyXVQyBPGfntoL-xexf4Cldt_' b'EPzHis2W4U","s":"0","t":"dip","kt":"1","k":["DuK1x8ydpucu3480Jpd' b'1XBfjnCwb3dZ3x5b1CJmuUphA"],"n":"EWWkjZkZDXF74O2bOQ4H5hu4nXDlKg2' b'm4CBEBkUxibiU","bt":"0","b":[],"c":[],"a":[],"di":"Eta8KLf1zrE5n' b'-HZpgRAnDmxLASZdXEiU9u6aahqR8TI"}-AABAA2_8Guj0Gf2JoNTq7hOs4u6eOO' b'WhENALJWDfLxkVcS2uLh753FjtyE80lpeS3to1C9yvENyMnyN4q96ehA4exDA-GA' b'B0AAAAAAAAAAAAAAAAAAAAAAQE3fUycq1G-P1K1pL2OhvY6ZU-9otSa3hXiCcrxu' b'hjyII') # apply Del's delegated inception event message to Del's own Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=delKvy) # delKvy.process(ims=bytearray(msg)) # process remote copy of msg assert delPre in delKvy.kevers delK = delKvy.kevers[delPre] assert delK.delegated assert delK.serder.diger.qb64 == delSrdr.dig couple = delKvy.db.getAes(dbing.dgKey(delPre, delSrdr.dig)) assert couple == seqner.qb64b + bobSrdr.diger.qb64b # apply Del's delegated inception event message to bob's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=bobKvy) # bobKvy.process(ims=bytearray(msg)) # process local copy of msg assert delPre in bobKvy.kevers # successfully validated bobDelK = bobKvy.kevers[delPre] assert bobDelK.delegated assert bobDelK.serder.diger.qb64 == delSrdr.dig # key state updated so event was validated couple = bobKvy.db.getAes(dbing.dgKey(delPre, delSrdr.dig)) assert couple == seqner.qb64b + bobSrdr.diger.qb64b # Setup Del rotation event assuming that Bob's next event will be an ixn delegating event verfers, digers, cst, nst = delMgr.rotate(pre=delPre, temp=True) delSrdr = eventing.deltate( pre=bobDelK.prefixer.qb64, keys=[verfer.qb64 for verfer in verfers], dig=bobDelK.serder.diger.qb64, sn=bobDelK.sn + 1, nxt=coring.Nexter(digs=[diger.qb64 for diger in digers]).qb64) assert delSrdr.dig == 'EPjLBcb4pp-3PGvSi_fTvLvsqUqFoJ0CVCHvIFfu93Xc' # Now create delegating interaction event seal = eventing.SealEvent(i=bobDelK.prefixer.qb64, s=delSrdr.ked["s"], d=delSrdr.dig) bobSrdr = eventing.interact(pre=bobK.prefixer.qb64, dig=bobK.serder.diger.qb64, sn=bobK.sn + 1, data=[seal._asdict()]) sigers = bobMgr.sign(ser=bobSrdr.raw, verfers=bobK.verfers) msg = bytearray(bobSrdr.raw) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == bytearray( b'{"v":"KERI10JSON000107_","i":"Eta8KLf1zrE5n-HZpgRAnDmxLASZdXEiU9' b'u6aahqR8TI","s":"2","t":"ixn","p":"E3fUycq1G-P1K1pL2OhvY6ZU-9otS' b'a3hXiCcrxuhjyII","a":[{"i":"E-9tsnVcfUyXVQyBPGfntoL-xexf4Cldt_EP' b'zHis2W4U","s":"1","d":"EPjLBcb4pp-3PGvSi_fTvLvsqUqFoJ0CVCHvIFfu9' b'3Xc"}]}-AABAAclMVE-bkIn-wPiAqfgR384nWmslQHQvmo2o3xQvd_4Bt6bflc4B' b'AmfBa03KgrDVqmB7qG2VXQbOHevkzOgRdDA') # apply msg to bob's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=bobKvy) # bobKvy.process(ims=bytearray(msg)) # process local copy of msg assert bobK.serder.diger.qb64 == bobSrdr.dig # key state updated so event was validated # apply msg to del's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=delKvy) # delKvy.process(ims=bytearray(msg)) # process remote copy of msg assert delKvy.kevers[bob].serder.diger.qb64 == bobSrdr.dig # now create msg from Del's delegated rotation event sigers = delMgr.sign(ser=delSrdr.raw, verfers=verfers) msg = bytearray(delSrdr.raw) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) counter = coring.Counter(code=coring.CtrDex.SealSourceCouples, count=1) msg.extend(counter.qb64b) seqner = coring.Seqner(sn=bobK.sn) msg.extend(seqner.qb64b) msg.extend(bobSrdr.diger.qb64b) assert msg == ( b'{"v":"KERI10JSON000122_","i":"E-9tsnVcfUyXVQyBPGfntoL-xexf4Cldt_' b'EPzHis2W4U","s":"1","t":"drt","p":"E1x1JOub6oEQkxAxTNFu1Pma6y-lr' b'bprNsaILHJHoPmY","kt":"1","k":["DTf6QZWoet154o9wvzeMuNhLQRr8JaAU' b'eiC6wjB_4_08"],"n":"E8kyiXDfkE7idwWnAZQjHbUZMz-kd_yIMH0miptIFFPo' b'","bt":"0","br":[],"ba":[],"a":[]}-AABAAAVUMNfOl9Fcqx-C3fAYnaxvs' b'iJJO3zG6rP0FQ2WVp__hMEaprrQbJL6-Esnny3U5zvMOqbso17rvecTwmVIwDw-G' b'AB0AAAAAAAAAAAAAAAAAAAAAAgEbOI0OIIFv2VV5bmeSq1pwCn-6b2k6TdWcCbJH' b'E6Ly7o') # apply msg to del's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=delKvy) # delKvy.process(ims=bytearray(msg)) # process remote copy of msg assert bobDelK.delegated assert delK.serder.diger.qb64 == delSrdr.dig couple = delKvy.db.getAes(dbing.dgKey(delPre, delSrdr.dig)) assert couple == seqner.qb64b + bobSrdr.diger.qb64b # apply Del's delegated inception event message to bob's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=bobKvy) # bobKvy.process(ims=bytearray(msg)) # process local copy of msg assert bobDelK.delegated assert bobDelK.serder.diger.qb64 == delSrdr.dig # key state updated so event was validated couple = delKvy.db.getAes(dbing.dgKey(delPre, delSrdr.dig)) assert couple == seqner.qb64b + bobSrdr.diger.qb64b # test replay msgs = bytearray() for msg in delKvy.db.clonePreIter(pre=delPre, fn=0): msgs.extend(msg) assert len(msgs) == 1043 assert couple in msgs assert not os.path.exists(delKS.path) assert not os.path.exists(delDB.path) assert not os.path.exists(bobKS.path) assert not os.path.exists(bobDB.path) """End Test"""
def test_issuing(): sidSalt = coring.Salter(raw=b'0123456789abcdef').qb64 with basing.openDB(name="sid") as sidDB, \ keeping.openKS(name="sid") as sidKS, \ basing.openDB(name="red") as redDB, \ openPocket(name="red") as redPDB: limit = 1.0 tock = 1.0 doist = doing.Doist(limit=limit, tock=tock) sidHab = habbing.Habitat(ks=sidKS, db=sidDB, salt=sidSalt, temp=True) sidPre = sidHab.pre assert sidPre == "E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E" sidIcpMsg = sidHab.makeOwnInception() redKvy = eventing.Kevery(db=redDB) parsing.Parser().parse(ims=bytearray(sidIcpMsg), kvy=redKvy) assert redKvy.kevers[sidPre].sn == 0 # accepted event sed = dict() sed["$id"] = "" sed["$schema"] = "http://json-schema.org/draft-07/schema#" sed.update( dict(type="object", properties=dict(id=dict(type="string"), lei=dict(type="string")))) schemer = scheming.Schemer(sed=sed, code=coring.MtrDex.Blake3_256) assert schemer.said == "EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY" cache = scheming.CacheResolver() cache.add(schemer.said, schemer.raw) jsonSchema = JSONSchema(resolver=cache) # Create Red's wallet and Issue Handler for receiving the credential redWallet = Wallet(hab=sidHab, db=redPDB) redIssueHandler = IssueHandler(wallet=redWallet, typ=jsonSchema) redExc = exchanging.Exchanger(hab=sidHab, tymth=doist.tymen(), handlers=[redIssueHandler]) # Build the credential subject and then the Credentialer for the full credential credSubject = dict( id= "did:keri:Efaavv0oadfghasdfn443fhbyyr4v", # this needs to be generated from a KEL lei="254900OPPU84GM83MG36", issuanceDate="2021-06-27T21:26:21.233257+00:00", ) creder = credential(issuer=sidHab.pre, schema=schemer.said, subject=credSubject, typ=jsonSchema) assert creder.said == "EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM" msg = sidHab.endorse(serder=creder) assert msg == ( b'{"v":"KERI10JSON000136_","i":"EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM",' b'"x":"EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY","ti":"E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E",' b'"d":{"id":"did:keri:Efaavv0oadfghasdfn443fhbyyr4v","lei":"254900OPPU84GM83MG36",' b'"issuanceDate":"2021-06-27T21:26:21.233257+00:00"}}-VA0-FABE4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE' b'-YfcI9E0AAAAAAAAAAAAAAAAAAAAAAAElHzHwX3V6itsD2Ksg_CNBbUNTBYzLYw-AxDNI7_ZmaI' b'-AABAA0pXbQllgzXr88IczAnsPrdhgFKs9wNQvfSfzyrtcvbTwq-U1DmBluAklntCqH1AbBL6TWLZIDGi83BHLWJ82CA' ) # Create the issue credential payload pl = dict(vc=[envelope(msg, typ=jsonSchema)]) # Create the `exn` message for issue credential sidExcSrdr = exchanging.exchange(route="/credential/issue", payload=pl) excMsg = sidHab.sanction(sidExcSrdr) # Parse the exn issue credential message on Red's side parsing.Parser().parse(ims=bytearray(excMsg), kvy=redKvy, exc=redExc) doist.do(doers=[redExc]) assert doist.tyme == limit ser = ( b'{"v":"KERI10JSON000136_","i":"EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM",' b'"x":"EeCCZi1R5xHUlhsyQNm_7NrUQTEKZH5P9vBomnc9AihY","ti":"E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E",' b'"d":{"id":"did:keri:Efaavv0oadfghasdfn443fhbyyr4v","lei":"254900OPPU84GM83MG36",' b'"issuanceDate":"2021-06-27T21:26:21.233257+00:00"}}') sig0 = ( b'AA0pXbQllgzXr88IczAnsPrdhgFKs9wNQvfSfzyrtcvbTwq-U1DmBluAklntCqH1AbBL6TWLZIDGi83BHLWJ82CA' ) # verify we can load serialized VC by SAID key = creder.said.encode("utf-8") assert redPDB.getSers(key) == ser # verify the signature sigs = redPDB.getSigs(key) assert len(sigs) == 1 assert sigs[0] == sig0 # verify we can look up credential by Schema SAID schema = redPDB.getSchms(schemer.saider.qb64b) assert len(schema) == 1 assert schema[0] == key
def test_proving(): sidSalt = coring.Salter(raw=b'0123456789abcdef').qb64 hanSalt = coring.Salter(raw=b'abcdef0123456789').qb64 vicSalt = coring.Salter(raw=b'fedcba9876543210').qb64 with basing.openDB(name="sid") as sidDB, \ keeping.openKS(name="sid") as sidKS, \ basing.openDB(name="vic") as vicDB, \ keeping.openKS(name="vic") as vicKS, \ basing.openDB(name="han") as hanDB, \ keeping.openKS(name="han") as hanKS, \ openPocket(name="han") as hanPDB: limit = 1.0 tock = 1.0 doist = doing.Doist(limit=limit, tock=tock) sidHab = habbing.Habitat(ks=sidKS, db=sidDB, salt=sidSalt, temp=True) assert sidHab.pre == "E4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E" sidIcpMsg = sidHab.makeOwnInception() hanKvy = eventing.Kevery(db=hanDB) parsing.Parser().parse(ims=bytearray(sidIcpMsg), kvy=hanKvy) assert hanKvy.kevers[sidHab.pre].sn == 0 # accepted event hanHab = habbing.Habitat(ks=hanKS, db=hanDB, salt=hanSalt, temp=True) assert hanHab.pre == "EKDWzykRd45o5UQyprm_9e8UcltXGo1tZCrdfGBTA8tc" hanIcpMsg = hanHab.makeOwnInception() vicKvy = eventing.Kevery(db=vicDB) parsing.Parser().parse(ims=bytearray(hanIcpMsg), kvy=vicKvy) assert vicKvy.kevers[hanHab.pre].sn == 0 # accepted event vicHab = habbing.Habitat(ks=vicKS, db=vicDB, salt=vicSalt, temp=True) assert vicHab.pre == "E8HQASAgOnZnQ4T7rv3dcvj0-UydrTTtyCprhEASk__o" vicIcpMsg = vicHab.makeOwnInception() parsing.Parser().parse(ims=bytearray(vicIcpMsg), kvy=hanKvy) assert hanKvy.kevers[vicHab.pre].sn == 0 # accepted event sed = dict() sed["$id"] = "" sed["$schema"] = "http://json-schema.org/draft-07/schema#" sed.update( dict(type="object", properties=dict(id=dict(type="string"), lei=dict(type="string")))) schemer = scheming.Schemer(sed=sed, typ=scheming.JSONSchema(), code=coring.MtrDex.Blake3_256) cache = CacheResolver() cache.add(schemer.said, schemer.raw) jsonSchema = JSONSchema(resolver=cache) credSubject = dict( id= "did:keri:Efaavv0oadfghasdfn443fhbyyr4v", # this needs to be generated from a KEL lei="254900OPPU84GM83MG36", issuanceDate="2021-06-27T21:26:21.233257+00:00", ) creder = credential(issuer=sidHab.pre, schema=schemer.said, subject=credSubject, typ=JSONSchema(resolver=cache)) assert creder.said == "EgaaYOPdG7vootT99cmClvwOoM-hjUIpv5Xl6hFuTcyM" msg = sidHab.endorse(serder=creder) hanWallet = Wallet(hab=hanHab, db=hanPDB) parseCredential(ims=msg, wallet=hanWallet, typ=JSONSchema(resolver=cache)) # verify we can load serialized VC by SAID key = creder.said.encode("utf-8") assert hanPDB.getSers(key) is not None # Create Red's wallet and Issue Handler for receiving the credential hanRequestHandler = RequestHandler(wallet=hanWallet, typ=jsonSchema) hanExc = exchanging.Exchanger(hab=hanHab, tymth=doist.tymen(), handlers=[hanRequestHandler]) # Create the issue credential payload pl = dict(input_descriptors=[dict(x=schemer.said)]) # Create the `exn` message for presentation request vicExcSrdr = exchanging.exchange(route="/presentation/request", payload=pl) excMsg = vicHab.sanction(vicExcSrdr) # Parse the exn presentation request message on Han's side parsing.Parser().parse(ims=bytearray(excMsg), kvy=hanKvy, exc=hanExc) doist.do(doers=[hanExc]) assert doist.tyme == limit resp = hanRequestHandler.cues.popleft() assert resp is not None respSer = coring.Serder(raw=resp.raw) assert respSer.ked['t'] == coring.Ilks.exn assert respSer.ked['r'] == "/presentation/proof" data = respSer.ked['q'] assert "presentation_submission" in data pe = data["presentation_submission"] assert "descriptor_map" in pe dm = pe["descriptor_map"] assert len(dm) == 1 assert dm[0]["id"] == schemer.said assert "verifiableCredential" in data vcs = data["verifiableCredential"] assert len(vcs) == 1 proof = ( "-FABE4YPqsEOaPNaZxVIbY-Gx2bJgP-c7AH_K7pEE-YfcI9E0AAAAAAAAAAAAAAAAAAAAAAAElHzHwX3V6itsD2Ksg_CNBbUNTBYzLYw" "-AxDNI7_ZmaI-AABAA0pXbQllgzXr88IczAnsPrdhgFKs9wNQvfSfzyrtcvbTwq-U1DmBluAklntCqH1AbBL6TWLZIDGi83BHLWJ82CA" ) assert vcs[0]["proof"] == proof
def test_weighted(): """ Test multisig with weighted threshold """ wesSalt = coring.Salter(raw=b'0123456789abcdef').qb64 # init wes Salter # init event DB and keep DB with basing.openDB(name="wes") as wesDB, keeping.openKS( name="wes") as wesKS: # Init key pair manager wesMgr = keeping.Manager(ks=wesKS, salt=wesSalt) # Init Kevery with event DB wesKvy = eventing.Kevery(db=wesDB) # create inception event for Wes with 3 keys each in incept and next sets # defaults are algo salty and rooted sith = ["1/2", "1/2", "1/2"] # 2 of 3 but with weighted threshold nxtsith = ["1/2", "1/2", "1/2"] verfers, digers, cst, nst = wesMgr.incept(icount=3, isith=sith, ncount=3, nsith=nxtsith, stem='wes', temp=True) assert cst == nst == sith wesSrdr = eventing.incept( keys=[verfer.qb64 for verfer in verfers], sith=sith, nxt=coring.Nexter(sith=nxtsith, digs=[diger.qb64 for diger in digers]).qb64, code=coring.MtrDex.Blake3_256) wesPre = wesSrdr.ked["i"] wesMgr.move(old=verfers[0].qb64, new=wesPre) # move key pair label to prefix sigers = wesMgr.sign(ser=wesSrdr.raw, verfers=verfers) msg = bytearray(wesSrdr.raw) counter = coring.Counter(coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == bytearray( b'{"v":"KERI10JSON00015b_","i":"EX0WJtv6vc0IWzOqa92Pv9v9pgs1f0BfIV' b'rSch648Zf0","s":"0","t":"icp","kt":["1/2","1/2","1/2"],"k":["DK4' b'OJI8JOr6oEEUMeSF_X-SbKysfwpKwW-ho5KARvH5c","D1RZLgYke0GmfZm-CH8A' b'sW4HoTU4m-2mFgu8kbwp8jQU","DBVwzum-jPfuUXUcHEWdplB4YcoL3BWGXK0TM' b'oF_NeFU"],"n":"EhJGhyJQTpSlZ9oWfQT-lHNl1woMazLC42O89fRHocTI","bt' b'":"0","b":[],"c":[],"a":[]}-AADAAKWMK8k4Po2A0rBrUBjBom73DfTCNg_b' b'iwR-_LWm6DMHZHGDfCuOmEyR8sEdp7cPxhsavq4istIZ_QQ42yyUcDAABeTClYkN' b'-yjbW3Kz3ot6MvAt5Se-jmcjhu-Cfsv4m_GKYgc_qwel1SbAcqF0TiY0EHFdjNKv' b'Ikg3q19KlhSbuBgACA6QMnsnZuy66xrZVg3c84mTodZCEvOFrAIDQtm8jeXeCTg7' b'yFauoQECZyNIlUnnxVHuk2_Fqi5xK_Lu9Pt76Aw') # apply msg to Wes's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=wesKvy) # wesKvy.process(ims=bytearray(msg)) # process local copy of msg wesK = wesKvy.kevers[wesPre] # kever created so event was validated assert wesK.prefixer.qb64 == wesPre assert wesK.serder.diger.qb64 == wesSrdr.dig # key state updated so event was validated # create interaction event for Wes wesSrdr = eventing.interact(pre=wesK.prefixer.qb64, dig=wesK.serder.diger.qb64, sn=wesK.sn + 1, data=[]) sigers = wesMgr.sign(ser=wesSrdr.raw, verfers=wesK.verfers) msg = bytearray(wesSrdr.raw) counter = coring.Counter(coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == bytearray( b'{"v":"KERI10JSON000098_","i":"EX0WJtv6vc0IWzOqa92Pv9v9pgs1f0BfIV' b'rSch648Zf0","s":"1","t":"ixn","p":"EInuqF20s1O0JhVJaOuKCZZDDyw6D' b'YxATbiuC5Hv3WXs","a":[]}-AADAAmg8UoBCTlnENiySBpn6j7mR1w0gdkfC8Ai' b'aYL5NCFfePp5ZK3CmnP7oQdj_ggiNp9FZNE0Q69A99wNK5FrwzDgABQZZunmJr2X' b'3BYgX34-6SOpzkHZQS99ZL0tDsDyUIL7jZhD1e1203Fh6BnkDjzum2au2dGHJcIP' b'giFGfDsrI5DwACwwYqqYYdEXeLpx_o6LTSKU-Fz_WF2gebP9Z72bZ75atg7_ZM3H' b'g6hhztstGt8TthRQ0TJn6rkvatkbn6yzRjBw') # apply msg to wes's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=wesKvy) # wesKvy.process(ims=bytearray(msg)) # process local copy of msg assert wesK.serder.diger.qb64 == wesSrdr.dig # key state updated so event was validated # Create rotation event for Wes # get current keys as verfers and next digests as digers nxtsith = ["1/2", "1/2", "1/2"] # 2 of 3 but with weighted threshold verfers, digers, cst, nst = wesMgr.rotate(pre=wesPre, count=3, sith=nxtsith, temp=True) assert nst == nxtsith wesSrdr = eventing.rotate( pre=wesK.prefixer.qb64, keys=[verfer.qb64 for verfer in verfers], sith=sith, dig=wesK.serder.diger.qb64, nxt=coring.Nexter(sith=nxtsith, digs=[diger.qb64 for diger in digers]).qb64, sn=wesK.sn + 1, data=[]) sigers = wesMgr.sign(ser=wesSrdr.raw, verfers=verfers) msg = bytearray(wesSrdr.raw) counter = coring.Counter(coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert bytearray( b'{"v":"KERI10JSON000190_","i":"EX0WJtv6vc0IWzOqa92Pv9v9pgs1f0BfIV' b'rSch648Zf0","s":"2","t":"rot","p":"EznUtmH2XJF04dyqpUHLzwkNgwk6D' b'jbDFbjXVI3UJLe0","kt":["1/2","1/2","1/2"],"k":["DeonYM2bKnAwp6VZ' b'cuCXdX72kNFw56czlZ_Tc7XHHVGI","DQghKIy-2do9OkweSgazh3Ql1vCOt5bnc' b'5QF8x50tRoU","DNAUn-5dxm6b8Njo01O0jlStMRCjo9FYQA2mfqFW1_JA"],"n"' b':"EX5fxvjOg5VuDboWbqnTjTPpXa3nNIm99hlsB1EmhTo8","bt":"0","br":[]' b',"ba":[],"a":[]}-AADAAahiASmZJY2KjXKRvVwdRSESmesNsfxUnOQ6buEk6S-' b'4rxRdztde_6_CX2Q4MyUSErHMtmLhesrKjenPBairZAQABbnbZ3lOKcKCMmLYtpT' b'hDEm-tRTsnEh_8loXpA6G3q1oJZNeVJphJjPm2HR0mX2ptC2DEt6p9i4GH1Y56HY' b'TsAgACqF6e_29QkxgXvqDLEUnAIB_XJ7SUhDNpt3cYk6pF1-ULgrhGdZLS1h-c_V' b'KpKITRx3ZTvme7sKbvr_NfR-0ECg') # apply msg to Wes's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=wesKvy) # wesKvy.process(ims=bytearray(msg)) # process local copy of msg assert wesK.serder.diger.qb64 == wesSrdr.dig # key state updated so event was validated # Create rotation event for Wes # get current keys as verfers and next digests as digers sith = nxtsith # rotate so nxtsith is now current sith and need new nextsith # 2 of first 3 and 1 of last 2 nxtsith = [["1/2", "1/2", "1/2"], ["1/1", "1/1"]] verfers, digers, cst, nst = wesMgr.rotate(pre=wesPre, count=5, sith=nxtsith, temp=True) assert cst == sith assert nst == nxtsith wesSrdr = eventing.rotate( pre=wesK.prefixer.qb64, keys=[verfer.qb64 for verfer in verfers], sith=sith, dig=wesK.serder.diger.qb64, nxt=coring.Nexter(sith=nxtsith, digs=[diger.qb64 for diger in digers]).qb64, sn=wesK.sn + 1, data=[]) sigers = wesMgr.sign(ser=wesSrdr.raw, verfers=verfers) msg = bytearray(wesSrdr.raw) counter = coring.Counter(coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == bytearray( b'{"v":"KERI10JSON000190_","i":"EX0WJtv6vc0IWzOqa92Pv9v9pgs1f0BfIV' b'rSch648Zf0","s":"3","t":"rot","p":"EK1BTah7lTyaaol7sLdg9uObplAjP' b'o_JOz1m4WPaLJBw","kt":["1/2","1/2","1/2"],"k":["D7WWKDLVwYxYMLAj' b'DceIEs66xPMY4Afzx-RQw2x0mQzI","Dmg6Aah8qyKKDiQyNXTiO71QJwizjZfGM' b'61BA-s0A5F4","DS3fhKpvPCDL5WmfN4_PkmJMMsSCdRTxG24OQuf_EmHQ"],"n"' b':"EcM4iw7fElXWhad8V-za4Px7nBKjndxoh3XZRkohghKY","bt":"0","br":[]' b',"ba":[],"a":[]}-AADAAl6FtC6Ynm8RAoa2utkIqJX5xW1ZxIkEH7I_MUCXL0p' b'OUT8P0lCgPzn9dvmUagHbzZ4GIwOBqGI-lQJbeESnZBQAB_nJLQJTf9t1NJxNoP5' b'gve9QEQbHFkn2aX6O78_bzOGUf01y8KSl-ugi0_B9-w0dk4J7gjYbv7RhG-TmFPE' b'mEAAACEpJiOTGarwK4jWZ9ZKue05uYPDW5wp4HC8VIt6R93h7WHLqqLVH1m3n5jd' b'AkiM4RFdhUqBwt-jKBfHQmVoBBCA') # apply msg to Wes's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=wesKvy) # wesKvy.process(ims=bytearray(msg)) # process local copy of msg assert wesK.serder.diger.qb64 == wesSrdr.dig # key state updated so event was validated # Create rotation event for Wes # get current keys as verfers and next digests as digers sith = nxtsith # rotate so nxtsith is now current sith and need new nextsith # 2 of first 3 and 1 of last 2 nxtsith = [["1/2", "1/2", "1/2"], ["1/1", "1/1"]] verfers, digers, cst, nst = wesMgr.rotate(pre=wesPre, count=5, sith=nxtsith, temp=True) assert cst == nst == nxtsith wesSrdr = eventing.rotate( pre=wesK.prefixer.qb64, keys=[verfer.qb64 for verfer in verfers], sith=sith, dig=wesK.serder.diger.qb64, nxt=coring.Nexter(sith=nxtsith, digs=[diger.qb64 for diger in digers]).qb64, sn=wesK.sn + 1, data=[]) sigers = wesMgr.sign(ser=wesSrdr.raw, verfers=verfers) msg = bytearray(wesSrdr.raw) counter = coring.Counter(coring.CtrDex.ControllerIdxSigs, count=len(sigers)) msg.extend(counter.qb64b) for siger in sigers: msg.extend(siger.qb64b) assert msg == bytearray( b'{"v":"KERI10JSON0001fe_","i":"EX0WJtv6vc0IWzOqa92Pv9v9pgs1f0BfIV' b'rSch648Zf0","s":"4","t":"rot","p":"EVfMO5GK8tg4KE8XCelX1s_TG_Hqr' b'_kzb3ghIBYvzC6U","kt":[["1/2","1/2","1/2"],["1/1","1/1"]],"k":["' b'DToUWoemnetqJoLFIqDI7lxIJEfF0W7xG5ZlqAseVUQc","Drz-IZjko61q-sPMD' b'IW6n-0NGFubbXiZhzWZrO_BZ0Wc","DiGwL3hjQqiUgQlFPeA6kRR1EBXX0vSLm9' b'b6QhPS8IkQ","Dxj5pcStgZ6CbQ2YktNaj8KLE_g9YAOZF6AL9fyLcWQw","DE5z' b'r5eH8EUVQXyAaxWfQUWkGCId-QDCvvxMT77ibj2Q"],"n":"E3in3Z14va0kk4Wq' b'd3vcCAojKNtQq7ZTrQaavR8x0yu4","bt":"0","br":[],"ba":[],"a":[]}-A' b'AFAAdxx4UfoNYdXckLY9nSYvqYLJzvIRhixshBbqkQ6uwvqaVmwPqmvck0V9xl5x' b'3ssVclasm8Ga3FTkcbmbV2jXDgABBWUhku-qDq8wYn5XMQuKzidAsA6bth8-EsCx' b'9WwTIqWBR-AecW-3X1haAyJshqplDsS9MnZfVgmSHokwdLnRCQACp2tB0pFRv_C7' b'nUXPf9rFKvlWUllrsY6Y1_F4bAOMvyCU-PES4HwyUQv3kQnLxEqnf0fbOYdHJNGo' b'sXi-UqL9BAADW89YpsS5m3IASAtXvXEPez-0y11JRP8bAiUUBdIxGB9ms79jPZnQ' b'tF3045byf3m0Dvi91Y9d4sh-xkzZ15v9DAAE6QR9qNXnHXLisg4Mbadav9AdMjS4' b'uz6jNG1AL6UCa7P90Y53v1V6VRaOPu_RTWXcXYRGqA9BHJ2rLNYWJTJTBA') # apply msg to Wes's Kevery parsing.Parser().parse(ims=bytearray(msg), kvy=wesKvy) # wesKvy.process(ims=bytearray(msg)) # process local copy of msg assert wesK.serder.diger.qb64 == wesSrdr.dig # key state updated so event was validated assert not os.path.exists(wesKS.path) assert not os.path.exists(wesDB.path) """End Test"""
def test_parser(): """ Test the support functionality for Parser stream processor """ logger.setLevel("ERROR") # Test sequence of events given set of secrets secrets = [ 'ArwXoACJgOleVZ2PY7kXn7rA0II0mHYDhc6WrBH8fDAc', 'A6zz7M08-HQSFq92sJ8KJOT2cZ47x7pXFQLPB0pckB3Q', 'AcwFTk-wgk3ZT2buPRIbK-zxgPx-TKbaegQvPEivN90Y', 'Alntkt3u6dDgiQxTATr01dy8M72uuaZEf9eTdM-70Gk8', 'A1-QxDkso9-MR1A8rZz_Naw6fgaAtayda8hrbkRVVu1E', 'AKuYMe09COczwf2nIoD5AE119n7GLFOVFlNLxZcKuswc', 'AxFfJTcSuEE11FINfXMqWttkZGnUZ8KaREhrnyAXTsjw', 'ALq-w1UKkdrppwZzGTtz4PWYEeWm0-sDHzOv5sq96xJY' ] with openDB("controller") as conDB, openDB("validator") as valDB: event_digs = [] # list of event digs in sequence # create event stream msgs = bytearray() # create signers signers = [Signer(qb64=secret) for secret in secrets] # faster assert [signer.qb64 for signer in signers] == secrets # Event 0 Inception Transferable (nxt digest not empty) serder = incept(keys=[signers[0].verfer.qb64], nxt=Nexter(keys=[signers[1].verfer.qb64]).qb64) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[0].sign(serder.raw, index=0) # return siger # create key event verifier state kever = Kever(serder=serder, sigers=[siger], db=conDB) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) assert msgs == bytearray( b'{"v":"KERI10JSON0000ed_","i":"DSuhyBcPZEZLK-fcw5tzHn2N46wRCG_ZOo' b'eKtWTOunRA","s":"0","t":"icp","kt":"1","k":["DSuhyBcPZEZLK-fcw5t' b'zHn2N46wRCG_ZOoeKtWTOunRA"],"n":"EPYuj8mq_PYYsoBKkzX1kxSPGYBWaIy' b'a3slgCOyOtlqU","bt":"0","b":[],"c":[],"a":[]}-AABAAmagesCSY8QhYY' b'HCJXEWpsGD62qoLt2uyT0_Mq5lZPR88JyS5UrwFKFdcjPqyKc_SKaKDJhkGWCk07' b'k_kVkjyCA') # Event 1 Rotation Transferable serder = rotate(pre=kever.prefixer.qb64, keys=[signers[1].verfer.qb64], dig=kever.serder.diger.qb64, nxt=Nexter(keys=[signers[2].verfer.qb64]).qb64, sn=1) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[1].sign(serder.raw, index=0) # returns siger # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 2 Rotation Transferable serder = rotate(pre=kever.prefixer.qb64, keys=[signers[2].verfer.qb64], dig=kever.serder.diger.qb64, nxt=Nexter(keys=[signers[3].verfer.qb64]).qb64, sn=2) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[2].sign(serder.raw, index=0) # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 3 Interaction serder = interact(pre=kever.prefixer.qb64, dig=kever.serder.diger.qb64, sn=3) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[2].sign(serder.raw, index=0) # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 4 Interaction serder = interact(pre=kever.prefixer.qb64, dig=kever.serder.diger.qb64, sn=4) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[2].sign(serder.raw, index=0) # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 5 Rotation Transferable serder = rotate(pre=kever.prefixer.qb64, keys=[signers[3].verfer.qb64], dig=kever.serder.diger.qb64, nxt=Nexter(keys=[signers[4].verfer.qb64]).qb64, sn=5) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[3].sign(serder.raw, index=0) # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 6 Interaction serder = interact(pre=kever.prefixer.qb64, dig=kever.serder.diger.qb64, sn=6) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[3].sign(serder.raw, index=0) # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 7 Rotation to null NonTransferable Abandon # nxt digest is empty serder = rotate(pre=kever.prefixer.qb64, keys=[signers[4].verfer.qb64], dig=kever.serder.diger.qb64, nxt="", sn=7) event_digs.append(serder.dig) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[4].sign(serder.raw, index=0) # update key event verifier state kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 8 Interaction serder = interact(pre=kever.prefixer.qb64, dig=kever.serder.diger.qb64, sn=8) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[4].sign(serder.raw, index=0) # update key event verifier state with pytest.raises( ValidationError): # nulled so reject any more events kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) # Event 8 Rotation serder = rotate(pre=kever.prefixer.qb64, keys=[signers[4].verfer.qb64], dig=kever.serder.diger.qb64, nxt=Nexter(keys=[signers[5].verfer.qb64]).qb64, sn=8) # create sig counter counter = Counter(CtrDex.ControllerIdxSigs) # default is count = 1 # sign serialization siger = signers[4].sign(serder.raw, index=0) # update key event verifier state with pytest.raises( ValidationError): # nontransferable so reject update kever.update(serder=serder, sigers=[siger]) #extend key event stream msgs.extend(serder.raw) msgs.extend(counter.qb64b) msgs.extend(siger.qb64b) assert len(msgs) == 3171 pre = kever.prefixer.qb64 db_digs = [ bytes(val).decode("utf-8") for val in kever.db.getKelIter(pre) ] assert db_digs == event_digs kevery = Kevery(db=valDB) parser = parsing.Parser(kvy=kevery) parser.parse(ims=bytearray(msgs)) # make copy assert parser.ims == bytearray(b'') # emptied assert pre in kevery.kevers vkever = kevery.kevers[pre] assert vkever.sn == kever.sn assert vkever.verfers[0].qb64 == kever.verfers[0].qb64 assert vkever.verfers[0].qb64 == signers[4].verfer.qb64 db_digs = [ bytes(val).decode("utf-8") for val in kevery.db.getKelIter(pre) ] assert db_digs == event_digs parser = parsing.Parser() # no kevery parser.parse(ims=msgs) assert parser.ims == bytearray(b'') assert not os.path.exists(kevery.db.path) assert not os.path.exists(kever.db.path) """ Done Test """
def test_exchanger(): sidSalt = coring.Salter(raw=b'0123456789abcdef').qb64 redSalt = coring.Salter(raw=b'abcdef0123456789').qb64 with basing.openDB(name="sid") as sidDB, \ keeping.openKS(name="sid") as sidKS, \ basing.openDB(name="red") as redDB, \ keeping.openKS(name="red") as redKS: limit = 1.0 tock = 0.03125 doist = doing.Doist(limit=limit, tock=tock) # Init key pair managers sidMgr = keeping.Manager(ks=sidKS, salt=sidSalt) # Init Keverys sidKvy = eventing.Kevery(db=sidDB) redHab = habbing.Habitat(ks=redKS, db=redDB, temp=True) redKvy = eventing.Kevery(db=redDB) # Setup sid by creating inception event verfers, digers, cst, nst = sidMgr.incept( stem='sid', temp=True) # algo default salty and rooted sidSrdr = eventing.incept( keys=[verfer.qb64 for verfer in verfers], nxt=coring.Nexter(digs=[diger.qb64 for diger in digers]).qb64, code=coring.MtrDex.Blake3_256) sidPre = sidSrdr.ked["i"] sidMgr.move(old=verfers[0].qb64, new=sidPre) # move key pair label to prefix sigers = sidMgr.sign(ser=sidSrdr.raw, verfers=verfers) excMsg = bytearray(sidSrdr.raw) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) excMsg.extend(counter.qb64b) for siger in sigers: excMsg.extend(siger.qb64b) sidIcpMsg = excMsg # save for later parsing.Parser().parse(ims=bytearray(sidIcpMsg), kvy=redKvy) assert redKvy.kevers[sidPre].sn == 0 # accepted event echo = EchoDoer(tymth=doist.tymen()) redExc = exchanging.Exchanger(hab=redHab, tymth=doist.tymen(), handlers=[echo]) pl = dict(x="y") sidExcSrdr = exchanging.exchange(route="/test/message", payload=pl) # Create exn message, sign it and attack Signer Seal sigers = sidMgr.sign(ser=sidExcSrdr.raw, verfers=verfers) excMsg = bytearray(sidExcSrdr.raw) excMsg.extend( coring.Counter(coring.CtrDex.SignerSealCouples, count=1).qb64b) excMsg.extend(sidPre.encode("utf-8")) counter = coring.Counter(code=coring.CtrDex.ControllerIdxSigs, count=len(sigers)) excMsg.extend(counter.qb64b) for siger in sigers: excMsg.extend(siger.qb64b) parsing.Parser().parse(ims=bytearray(excMsg), kvy=redKvy, exc=redExc) doist.do(doers=[redExc]) assert doist.tyme == limit resp = echo.cues.popleft() respSer = coring.Serder(raw=resp.raw) assert respSer.ked['t'] == coring.Ilks.exn assert respSer.ked['r'] == "/test/messageResp" assert respSer.ked['q'] == dict(req=pl)