OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / deobfuscated / lib / tasks / pairing / invitation.js

153 lines · javascript ref:
const _0x54bfc7=(function(){let _0x614ef9=!![];return function(_0x2d3c20,_0x4782b5){const _0x58d29b=_0x614ef9?function(){if(_0x4782b5){const _0x6fbd62=_0x4782b5.apply(_0x2d3c20,arguments);return _0x4782b5=null,_0x6fbd62;}}:function(){};return _0x614ef9=![],_0x58d29b;};}()),_0x3e553e=_0x54bfc7(this,function(){_0x52fdc1={_0x42f3ca:0x265},_0x5955bd={_0x8931b5:0x29};return _0x3e553e.toString().search("(((.+)+)+)+$").toString().constructor(_0x3e553e).search("(((.+)+)+)+$");});
_0x3e553e();
const b4a=require('b4a'),safetyCatch=require('safety-catch');
const SignalPromise=require('signal-promise'),{
  Task}
=require('../task'),{
  getInvitationId,generatePairingCapabilities,generateRoomPairingName,createInvitationJoinOperation}
=require('../../invitations');
module.exports=class JoinRoomInvitationTask extends Task{
  constructor(_0x3d6e1d){
    _0xa73e16={
      _0x1887c4:0x5d,_0x37f828:0x9c},_0x447cb5={
      _0x4b358b:0x607,_0x49bbc7:0x7f}
    ;
    super(_0x3d6e1d);
    const _0x27dcaa=this.description.joinRoomInvitation;
    this._invitation=_0x27dcaa.invitation,this._initiator=_0x27dcaa.invitation.initiator,this._inviter=_0x27dcaa.invitation.inviter,this._identity=_0x27dcaa.invitation.identity,this._mailboxPublicKey=_0x27dcaa.invitation.mailbox,this._responseKeyPair=_0x27dcaa.invitation.responseKeyPair,this._invitationSeed=this._invitation.invitationSeed;
    this._capabilities=generatePairingCapabilities(this._mailboxPublicKey),this._invitationId=getInvitationId(this._invitationSeed),this._roomInfo=null,this._sharedRoomInfo=null,this._writerInfo=null,this._identityInfo=null,this._privateProfileInfo=null,this._room=null,this._core=null,this._responseCore=null,this._wakeupSession=null,this._privateProfile=null,this._signal=null,this._watcher=null;
  }
async._close(){
  _0x202707={
    _0x532a61:0x731,_0x4af036:0x150},_0x5026f7={
    _0x2e8897:0x17b,_0x25d32f:0x4af,_0x129b2c:0x8d}
  ;
  if(this._signal)this._signal.notify(new Error("Invitation join task closed before resolving"));
  if(this._watcher)this._privateProfile.db.unwatch(this._watcher);
  this._wakeupSession&&(this.swarmWorker.stopActiveSwarming(this._capabilities.swarmTopic),this._wakeupSession.destroy());
  if(this._core)await this._core.close();
  if(this._responseCore)await this._responseCore.close();
  if(this._room)this.keet.internalReleaseRoom(this._room);
  if(this._privateProfile)this.keet.internalReleaseRoom(this._privateProfile);
}
._samePendingInvitation(_0x2bb289){
  _0x4e909e={
    _0x106dbd:0x1ad,_0x5f1b8c:0x164,_0x459bf6:0x109},_0x174def={
    _0x387af0:0x8e,_0x3a489a:0x730}
  ;
  return b4a.equals(_0x2bb289.id,this._invitationId)&&b4a.equals(_0x2bb289.responseKeyPair.publicKey,this._responseKeyPair.publicKey);
}
async._appendJoinRequest(){
  _0x977eca={
    _0x4025ed:0xb,_0x2214c5:0x14b,_0x3f6f02:0xf},_0x860a22={
    _0x134cf1:0x7f}
  ;
  const _0x54e71c={
    'key':this._core.key,'responsePublicKey':this._responseKeyPair.publicKey},_0x187557=await this.local.get("@local/writer-appends",_0x54e71c);
  if(_0x187557)return;
  const _0x1ff0c3={
    'identity':this._identityInfo,'privateProfile':this._privateProfileInfo},_0x3ae787=this.keet.internalCreateDeviceUpdate(_0x1ff0c3,this._core.key,{'isPrivateProfile':!!this._identity}),_0xa7b705=this.keet.internalGetMemberUpdate(_0x1ff0c3),_0x282ec4={
    'device':_0x3ae787,'member':_0xa7b705}
  ;
  let _0x10f4d8=null;
  this._identity&&(_0x10f4d8={'devicePublicKey':this._identity.devicePublicKey});
  const _0x26e7b5=this.keet.internalGetHeads(this._inviter,this._room),_0xb50c87=createInvitationJoinOperation(this._core.key,this._mailboxPublicKey,this._responseKeyPair,this._invitationSeed,_0x282ec4,{'identity':_0x10f4d8,'heads':_0x26e7b5});
  await this.keet.internalAppendOptimisticOperation(this._core.key,_0xb50c87);
  if(this.closing)return;
  const _0x1d9896=await this.keet.internalEnterLocalTransaction();
  try{
    await _0x1d9896.insert("@local/writer-appends",_0x54e71c),await _0x1d9896.flush();
  }finally{
  await this.keet.internalExitLocalTransaction();
}
}
async._waitForResponse(){
  _0xea6fd3={
    _0x40075f:0x12e,_0xe7a831:0x8c,_0x2a6c3c:0x3a},_0x29bf08={
    _0x32823a:0x400,_0xa67728:0x3c5,_0x51dea5:0x3bc,_0x5c47ae:0x35e,_0x526c26:0x34f,_0x44ae25:0x310,_0x127ab8:0x38d,_0x3457e5:0x3fc,_0x561b74:0x3ca,_0x3bb415:0x2e1,_0x4c1925:0x2da,_0x5657ed:0x2fc,_0x1a6ae1:0x328,_0x1099c5:0x2d3,_0x2926ef:0x2f0,_0x256ea3:0x2ec,_0x5736c1:0x3fe,_0x5312a1:0x3c9,_0x8bdc97:0x3be,_0x50e0bc:0x3fa},_0x5e916e={
    _0x5bbcc9:0x83,_0x3ec20c:0x323},_0x2b178a={
    _0x268981:0x199,_0x1c1e77:0x11d}
  ;
  this._responseCore=this.store.get({'keyPair':this._responseKeyPair,'writable':![]}),await this._responseCore.ready();
  const _0x580eb4=this._privateProfileInfo.capabilities.mailboxKeyPair.publicKey;
  this.keet.blindPeering.addCoreBackground(this._responseCore,_0x580eb4,{'referrer':_0x580eb4,'priority':0x1});
  if(this.closing)return;
  const _0x4d8ddf=_0x342179=>{
    this._wakeupSession.announce(_0x342179,[{'key':this._core.key,'length':this._core.length}]);
  }
;
this._wakeupSession=this.keet.protomuxWakeup.session(this._mailboxPublicKey,{'discoveryKey':this._capabilities.wakeupTopic,'onpeeractive':_0x4d8ddf});
for(const _0x2b0920 of this._wakeupSession.peers){
  if(!_0x2b0920.active)continue;
  _0x4d8ddf(_0x2b0920);
}
this.swarmWorker.startActiveSwarming(this._capabilities.swarmTopic);
this.keet.discovery&&this.keet.discovery.announce(this._capabilities.discoveryKeyPair);
try{
  await this._responseCore.get(0x0);
}catch(_0xebe8d1){
if(this.closing)return;
throw _0xebe8d1;
}
if(this.closing)return;
this.swarmWorker.stopActiveSwarming(this._capabilities.swarmTopic);
this.keet.discovery&&this.keet.discovery.subscribe(this._capabilities.discoveryKeyPair.publicKey,{'since':Date.now()});
await this._responseCore.close();
if(this.closing)return;
this._privateProfile.base.hintWakeup([{'key':this._responseCore.key,'length':0x1}]);
}
async._append(){
  _0x105d90={
    _0x172573:0xa6,_0x136fef:0x11a},_0x2a6087={
    _0x5f386b:0x265,_0x1de583:0x154},_0x3ce72f=await this.keet.store.createKeyPair(generateRoomPairingName(this._responseKeyPair.publicKey));
  const _0x1a29a1=await this.keet.internalEnterLocalTransaction();
  try{
    this._writerInfo={
      'keyPair':_0x3ce72f,'key':this._core.key,'mailbox':this._mailboxPublicKey,'responseKeyPair':this._responseKeyPair},await _0x1a29a1.insert("@local/writers",this._writerInfo),await _0x1a29a1.flush();
  }finally{
  await this.keet.internalExitLocalTransaction();
}
await this._appendJoinRequest();
}
async._run(){
  _0xca84b7={
    _0x21c5d8:0x9b,_0x5798e6:0xd7,_0x3c03af:0xcc,_0x2fcdc0:0x100,_0x41f54a:0x5,_0x50ebb3:0x15,_0x2f5073:0xf,_0x125682:0x34,_0x392f57:0x11,_0x4575a4:0x67,_0x110bd9:0x1f,_0x5dd5b8:0x47,_0x327564:0x97,_0x80d045:0x102,_0x4542b0:0xbc,_0x506861:0x7f,_0x4cfdd0:0x44,_0x1783c3:0x85,_0x5b1927:0x87,_0xeca058:0x6b,_0x13fe63:0xbe,_0x393281:0xcb,_0x3d90e7:0xc0,_0xa9df3e:0x101,_0x1e0d3b:0xb9,_0x56a1b4:0xf9,_0x4d9342:0xf6,_0x205890:0x8f,_0x1a03e1:0xb8,_0x4d33f7:0x10,_0x101eeb:0x18},_0x59f869={
    _0x443410:0x1d8,_0x279abe:0xd3,_0x171d9a:0x18f},_0x1ed27b={
    _0x36c750:0x79},_0x30ac5a={
    _0x1a86f4:0xe5,_0x5c1e1b:0x13},_0x57f460={
    _0x7ea250:0x4a,_0xc38123:0x4c1}
  ;
  if(this.closing)return;
  const [_0x4e1730,_0x2964a4]=await Promise.all([this.local.get("@local/writers",{'mailbox':this._mailboxPublicKey}),this.local.get("@local/identity")]),[_0x116c9c,_0x2e39fa]=await Promise.all([this.local.get("@local/rooms",{'roomKey':_0x2964a4.privateProfileKey}),this.local.get("@local/rooms-by-mailbox",{'capabilities':{'mailboxKeyPair':{'publicKey':this._mailboxPublicKey}}})]);
  if(this.closing)return;
  this._roomInfo=_0x2e39fa,this._writerInfo=_0x4e1730;
  this._identityInfo=_0x2964a4,this._privateProfileInfo=_0x116c9c,this._privateProfile=this.keet.internalOpenExistingRoom(this._identityInfo.privateProfileKey),await this._privateProfile.ready();
  if(this.closing)return;
  this._room=this._roomInfo?this.keet.internalOpenExistingRoom(this._roomInfo.roomKey):null;
  if(this._room){
    await this._room.ready();
    if(this.closing)return;
  }
const _0x5a733b=await this._privateProfile.db.get("@keet-private-id/pending-invitations",{'id':this._invitationId});
if(this.closing||!_0x5a733b||!this._samePendingInvitation(_0x5a733b))return;
this._core=this.store.get({'key':this._initiator.key}),await this._core.ready();
if(this.closing)return;
if(this._core.writable){
  await this._append();
  if(this._room){
    await this._room.base.setLocal(this._core.key);
    if(this.closing)return;
  }
}
this.keet.emit("pending-rooms-changed"),this.keet.blindPeering.addCoreBackground(this._core,this._mailboxPublicKey,{'referrer':this._mailboxPublicKey,'priority':0x1}),this._waitForResponse().catch(this.keet.onerror),this._signal=new SignalPromise(),this._watcher=async()=>{
  try{
    const _0x2033dd=await this._privateProfile.db.get("@keet-private-id/pending-invitations",{'id':this._invitationId});
    (!_0x2033dd||!this._samePendingInvitation(_0x2033dd))&&this._signal.notify();
  }catch(_0x14afef){
  safetyCatch(_0x14afef);
}
},this._privateProfile.db.watch(this._watcher),this._watcher(),await this._signal.wait();
}
}
;