OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / deobfuscated / lib / tasks / contacts / request.js

226 lines · javascript ref:
const _0x54f3a5=(function(){let _0x49ad45=!![];return function(_0x5b6008,_0x595d49){_0x18c3a3=_0x49ad45?function(){if(_0x595d49){const _0x3af75c=_0x595d49.apply(_0x5b6008,arguments);return _0x595d49=null,_0x3af75c;}}:function(){};return _0x49ad45=![],_0x18c3a3;};}()),_0x1aea3c=_0x54f3a5(this,function(){_0x662bba={_0x337590:0x201};return _0x1aea3c.toString().search("(((.+)+)+)+$").toString().constructor(_0x1aea3c).search("(((.+)+)+)+$");});
_0x1aea3c();
const crypto=require('hypercore-crypto'),SignalPromise=require('signal-promise'),safetyCatch=require('safety-catch'),{
  Task}
=require('../task'),{
  restoreAvatar}
=require('../../contract/avatars'),{
  contract:{
    hyperschema:{
      getEnum:getContractEnum}
  }
}
=require('../../../spec'),{
  getWriterKey,createContactRequestOperation,generateRoomCapabilities,generatePairingCapabilities}
=require('../../invitations');
const RoomType=getContractEnum("@keet/room-type");
module.exports=class SendContactRequestTask extends Task{
  constructor(_0x31cd07){
    _0x210625={
      _0x136547:0x1f3,_0x10651f:0x1b3,_0x55adad:0x4d1}
    ;
    super(_0x31cd07);
    const _0x5a1c18=this.description.sendContactRequest;
    this._roomKey=_0x5a1c18.roomKey,this._memberKey=_0x5a1c18.memberKey,this._message=_0x5a1c18.message,this._contactInfo=_0x5a1c18.contactInfo,this._member=null;
    this._contact=null,this._writerInfo=null,this._contactRoomInfo=null,this._privateContactRoom=null,this._selfMember=null,this._targetMember=null,this._roomMailbox=null;
    this._memberMailbox=null,this._memberMailboxDiscoveryKey=null,this._core=null,this._dmRoom=null,this._memberRoom=null,this._privateProfile=null,this._wakeupSession=null,this._watcher=null,this._privateProfileWatcher=null;
  }
async._close(){
  _0x4ac921={
    _0x472cb3:0x37,_0x4c7dcd:0xb5,_0x4a446e:0x7d},_0x19310a={
    _0x482553:0x65,_0x55b55b:0x1ba}
  ;
  if(this._dmRoom){
    if(this._watcher)this._dmRoom.db.unwatch(this._watcher);
    this.keet.internalReleaseRoom(this._dmRoom);
  }
if(this._memberRoom)this.keet.internalReleaseRoom(this._memberRoom);
if(this._privateProfile){
  if(this._privateProfileWatcher)this._privateProfile.db.unwatch(this._privateProfileWatcher);
  this.keet.internalReleaseRoom(this._privateProfile);
}
if(this._wakeupSession)this._wakeupSession.destroy();
}
async._createRoom(){
  _0x2bac52={
    _0x59fbee:0x13e},_0x545c29={
    _0x549917:0xd8,_0x50172:0x163,_0x96d62e:0x41b},_0x2d900c=crypto.keyPair(),_0x1fc572=crypto.randomBytes(-0x323a),_0x1ff929=getWriterKey(_0x2d900c.publicKey);
  const _0x2b1808=generateRoomCapabilities(_0x1ff929,_0x1fc572),_0x362b25={
    'identity':this._identityInfo,'privateProfile':this._privateProfileInfo},_0x4f64fc=this.keet.internalCreateDeviceUpdate(_0x362b25,_0x1ff929);
  this._roomMailbox=_0x2b1808.mailboxKeyPair.publicKey,this._dmRoom=await this.keet.internalCreateRoom({'settings':{'roomType':RoomType.DirectMessage},'initialMembers':[this._selfMember,this._targetMember],'bootstrapDevice':_0x4f64fc,'keyPair':_0x2d900c,'seed':_0x1fc572});
  this._message&&await this._dmRoom.dispatch("@keet/add-chat-message",{'message':{'text':this._message}});
  return!![];
}
async._appendContactRequest(){
  _0x2c2746={
    _0xee5dee:0x25,_0x23da64:0x100,_0x340694:0x1bd},_0x2b80ef={
    _0x520a18:0x153,_0x14c691:0x143,_0x21e6fb:0x5e5}
  ;
  const _0x202a15=await this.keet.internalVerifyOptimisticCore(this._core);
  if(!_0x202a15||this.closing)return;
  const _0x753afc={
    'message':this._message,'sender':this._selfMember,'mailbox':this._roomMailbox,'keys':{
      'key':this._dmRoom.key,'encryptionKey':this._dmRoom.encryptionKey}
  },_0x35ff56=createContactRequestOperation(this._memberMailbox,this._identityInfo,_0x753afc),_0x1e19be={
  'isBlocked':![]},_0x11b495={
  'memberKey':this._memberKey,'mailbox':this._memberMailbox,'roomKey':this._dmRoom.key,'status':_0x1e19be}
;
return await Promise.all([this._core.append(_0x35ff56),this._privateProfile.dispatch("@keet-private-id/add-contact",{'contact':_0x11b495})]),!![];
}
async._loadRequestWriter(){
  _0x3c41d1={
    _0x45ad9b:0x139,_0xae24c5:0x42a},_0x1a70ec={
    _0x209c48:0x86,_0x1ea0c9:0xa7}
  ;
  this._writerInfo=await this.local.get("@local/writers",{'mailbox':this._memberMailbox});
  if(this._writerInfo)return;
  const _0x2fffa1=crypto.keyPair(),_0x4a72f2=getWriterKey(_0x2fffa1.publicKey);
  this._writerInfo={
    'mailbox':this._memberMailbox,'keyPair':_0x2fffa1,'key':_0x4a72f2}
  ;
  const _0x5ef697=await this.keet.internalEnterLocalTransaction();
  try{
    await _0x5ef697.insert("@local/writers",this._writerInfo),await _0x5ef697.flush();
  }finally{
  await this.keet.internalExitLocalTransaction();
}
}
._getQueryRange(){
  _0x52d70a={
    _0x325cdd:0x8a,_0x16d8be:0x188,_0x48d3da:0x10e},_0x48e38e={
    _0x4f1979:0x1c3,_0x59dabd:0x4da}
  ;
  return{
    'gte':{
      'contact':this._targetMember.attestation.memberKey},'lte':{
      'contact':this._targetMember.attestation.memberKey}
  }
;
}
async._load(){
  _0x3c93b4={
    _0x5b03b9:0xb4,_0x1beb54:0x451},_0xa8de99={
    _0x518aa9:0x1a4,_0x41f91d:0x2}
  ;
  this._identityInfo=await this.local.get("@local/identity");
  if(this.closing)return![];
  const _0x5847da=this._identityInfo.privateProfileKey;
  this._privateProfileInfo=await this.local.get("@local/rooms",{'roomKey':_0x5847da});
  if(this.closing)return![];
  this._privateProfile=this.keet.internalOpenExistingRoom(_0x5847da),await this._privateProfile.ready();
  if(this.closing)return![];
  let _0x2491f3=![];
  this._contactInfo?_0x2491f3=await this._useContactInfo():_0x2491f3=await this._useRoomKey();
  if(!this._targetMember?..profile?..displayName)return![];
  await this._loadRequestWriter();
  if(this.closing)return![];
  this._core=this.store.get({'keyPair':this._writerInfo.keyPair}),await this._core.ready();
  if(this.closing)return![];
  this._privateContactRoom=await this._privateProfile.db.findOne("@keet-private-id/rooms-by-contact",this._getQueryRange());
  if(!_0x2491f3||this._privateContactRoom)return await this._waitForMember(),![];
  return!![];
}
async._useContactInfo(){
  _0x3d4d4b={
    _0x1ec46c:0x1b6,_0x1ee03c:0xbb,_0x3fe4fe:0x509},_0x2217f2=await this._privateProfile.db.get("@keet-private-id/contacts",{'memberKey':this._memberKey});
  this._contact=_0x2217f2,this._memberMailbox=this._contactInfo.profile.mailbox;
  this._member=null,this._memberProofs=null,this._memberPairingCapabilities=generatePairingCapabilities(this._memberMailbox),this._targetMember={
    'profile':this._contactInfo.profile,'attestation':this._contactInfo.attestation}
  ;
  _0x2217f2?..roomKey&&(this._contactRoomInfo=await this._privateProfile.db.get("@keet-private-id/rooms",{'roomKey':this._contact.roomKey}));
  if(this.closing||this._contactRoomInfo?..status.isActive)return![];
  const _0x433c19=this._privateProfileInfo.selfMember;
  this._selfMember={
    'profile':_0x433c19.profile,'attestation':{
      'memberKey':_0x433c19.key,'proof':_0x433c19.proofs.profileAttestation}
  }
;
return!![];
}
async._useRoomKey(){
  _0x89a03={
    _0x441510:0xb1,_0x125239:0x126,_0x2b97df:0x347},_0x26ff9b={
    _0x3ef377:0x197,_0x5013e0:0xa2}
  ;
  this._memberRoom=this.keet.internalOpenExistingRoom(this._roomKey),await this._memberRoom.ready();
  if(this.closing)return![];
  const [_0xd6131b,_0x3a11ec,_0x463491]=await Promise.all([this._privateProfile.db.get("@keet-private-id/contacts",{'memberKey':this._memberKey}),this._memberRoom.db.get("@keet/members",{'key':this._memberKey}),this._memberRoom.db.get("@keet/member-proofs",{'key':this._memberKey})]);
  this._contact=_0xd6131b;
  this._member=_0x3a11ec,this._memberProofs=_0x463491,this._memberMailbox=this._member.profile.mailbox,this._memberPairingCapabilities=generatePairingCapabilities(this._memberMailbox);
  if(this.closing||!_0x3a11ec||!_0x463491)return![];
  this._targetMember={
    'profile':this._member.profile,'attestation':{
      'memberKey':this._member.key,'proof':this._memberProofs.profileAttestation}
  }
;
_0xd6131b?..roomKey&&(this._contactRoomInfo=await this._privateProfile.db.get("@keet-private-id/rooms",{'roomKey':this._contact.roomKey}));
if(this.closing||this._contactRoomInfo?..status.isActive)return![];
const _0x2c88da=this._privateProfileInfo.selfMember;
return this._selfMember={
  'profile':_0x2c88da.profile,'attestation':{
    'memberKey':_0x2c88da.key,'proof':_0x2c88da.proofs.profileAttestation}
},this._targetMember.profile.avatar&&await restoreAvatar(this._memberRoom.blobs,this._targetMember.profile.avatar),!![];
}
async._waitForMember(){
  _0x296b75={
    _0x18dab1:0x19a,_0x4f9d4e:0x35a},_0x572d44={
    _0x16225a:0x9a,_0x34af79:0xa5,_0x4d8b3c:0xc7},_0x332541={
    _0x276f6d:0x1eb,_0x56e038:0x1e5,_0x18cb1a:0x22f,_0x5e6aba:0x1f7,_0x30fa25:0x21f,_0x6a3467:0x214,_0xcca880:0x207,_0x11f0c9:0x203,_0x1beee9:0x22d,_0x34c990:0x20e,_0x38a852:0x243,_0x2ffb5d:0x2c0,_0x1976d7:0x27e,_0x2bac5b:0x29c,_0x3a8ac2:0x2ba,_0x46e6c3:0x283,_0x52df0b:0x2fe,_0xc83030:0x271,_0x38d542:0x239,_0x4de19a:0x1f3,_0x56ec21:0x247},_0x5c6570={
    _0x126300:0x188,_0x40931f:0x263,_0x42fd41:0xfd},_0x34e8c2={
    _0x4d3dcb:0x3a1,_0x19bd37:0x35f,_0x2889f0:0xb9,_0x55a829:0xbb,_0x3b8bdd:0xd8,_0x29e665:0xd8,_0x3b71ee:0x8b,_0x1fee59:0xc5,_0x22174d:0xee,_0x3d0bcd:0x6e,_0x1412f0:0xb5,_0x4af130:0xa2,_0x55780e:0xa0,_0xdf0032:0x60,_0x571c4c:0x98,_0x2c59c6:0x10d,_0x105156:0x13f,_0x5ec2ff:0x118,_0xbc51fb:0xf8,_0x256547:0x119,_0x2377df:0x125},_0x31adb3={
    _0x3eb2bd:0x2eb,_0x1b5a4a:0x302,_0x29a906:0x2d7,_0x2620f2:0x21d,_0x4d1995:0x19d,_0x251b85:0x20e,_0x480edd:0x1c4,_0x5497e4:0x1fa,_0x423a7e:0x349,_0x5e2a8e:0x208,_0x2c8258:0x1e1,_0xd40c6:0x246,_0x31224d:0x212},_0x30f8a2={
    _0x385496:0xb3,_0x53e0f6:0x1ec,_0x3fe108:0x1c5},_0x1acbe6={
    _0x637a0d:0x67,_0x280abb:0x109}
  ;
  if(!this._dmRoom){
    const _0x592726=this._privateContactRoom?..roomKey||this._contact.roomKey;
    this._dmRoom=this.keet.internalOpenExistingRoom(_0x592726);
  }
this.swarmWorker.startActiveSwarming(this._memberPairingCapabilities.swarmTopic);
const _0x5c46ee=_0x1900f8=>{
  this._wakeupSession.announce(_0x1900f8,[{'key':this._core.key,'length':this._core.length}]);
}
;
this._wakeupSession=this.keet.protomuxWakeup.session(this._memberMailbox,{'discoveryKey':this._memberPairingCapabilities.wakeupTopic,'onpeeractive':_0x5c46ee});
for(const _0x5e803a of this._wakeupSession.peers){
  if(!_0x5e803a.active)continue;
  _0x5c46ee(_0x5e803a);
}
this.keet.blindPeering.addCoreBackground(this._core,this._memberMailbox,{'referrer':this._memberMailbox,'priority':0x1}),this._signal=new SignalPromise(),this._watcher=async()=>{
  _0x49bf5b={
    _0x8ca430:0x150,_0x26f318:0x319,_0x3bb105:0x16f}
  ;
  try{
    const _0x564a15=this._targetMember.attestation.memberKey,_0x507eb2=await this._dmRoom.db.findOne("@keet/devices-by-member-key",{'gte':{'memberKey':_0x564a15},'lte':{'memberKey':_0x564a15}});
    if(_0x507eb2)this._signal.notify();
  }catch(_0x5dc358){
  safetyCatch(_0x5dc358);
}
},this._dmRoom.db.watch(this._watcher),this._watcher(),this._privateProfileWatcher=async()=>{
try{
  const _0x1fe4cf=await await this._privateProfile.db.get("@keet-private-id/rooms",{'roomKey':this._dmRoom.key});
  if(_0x1fe4cf&&_0x1fe4cf.status.isActive===![])this._signal.notify();
}catch(_0x1d4436){
safetyCatch(_0x1d4436);
}
}
;
this._privateProfile.db.watch(this._privateProfileWatcher),this._privateProfileWatcher(),await this._signal.wait();
this.swarmWorker.stopActiveSwarming(this._memberPairingCapabilities.swarmTopic);
}
async._run(){
  _0x780ad4={
    _0x2f0a25:0x1c0,_0x91a4ef:0x113},_0x2efa8a={
    _0x168470:0xd8,_0x1eec20:0x17f}
  ;
  const _0x208d4a=await this._load();
  if(this.closing||!_0x208d4a)return;
  const _0x189db3=await this._createRoom();
  if(this.closing||!_0x189db3)return;
  const _0x360f5d=await this._appendContactRequest();
  if(this.closing||!_0x360f5d)return;
  await this._waitForMember();
}
}
;