OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / deobfuscated / lib / migrations / 3 / room.js

136 lines · javascript ref:
const _0x5221af=(function(){let _0x468cb4=!![];return function(_0x17d400,_0x233696){const _0x2d439c=_0x468cb4?function(){if(_0x233696){const _0x11bfa8=_0x233696.apply(_0x17d400,arguments);return _0x233696=null,_0x11bfa8;}}:function(){};return _0x468cb4=![],_0x2d439c;};}());
const _0x42ecd3=_0x5221af(this,function(){_0x47a220={_0x4eaa05:0x77},_0x181188={_0x2b0ba1:0x360};return _0x42ecd3.toString().search("(((.+)+)+)+$").toString().constructor(_0x42ecd3).search("(((.+)+)+)+$");});
_0x42ecd3();
const b4a=require('b4a'),IdentityKey=require('keet-identity-key'),{
  mnemonicToEntropy}
=require('bip39-mnemonic'),c=require('compact-encoding'),{
  ConfigSchema}
=require('@holepunchto/legacy-keet-core-schemas'),{
  CONFIG}
=require('@holepunchto/keet-core-api'),IDENTITIES_RELEASE_TIMESTAMP=-0x3b20cefac48,MNEMONIC_USERDATA_KEY="keet-seed-phrase";
module.exports=async function migrateRoom(_0x173c07,_0x3deee8,{capabilities:_0x2098b2,encryptionKey:_0xeb09f6,privateProfile:_0x413e4b},{migratingRooms:_0x4396c0}){
  _0x2ce41a={
    _0xae19fe:0x146,_0x31705f:0x3f6},_0x556ff8={
    _0x57a613:0x69,_0x10c201:0x86,_0xaf8f6:0x4ba}
  ;
  const _0x704a8b=await _0x173c07.local.find("@local/drive-files-by-room",{'gte':{'roomKey':_0x3deee8},'lte':{'roomKey':_0x3deee8}}).toArray();
  for(const _0x43b881 of _0x704a8b){
    _0x43b881.encryptionKey=_0xeb09f6;
  }
const _0x3b731d=await _0x173c07.internalEnterLocalTransaction();
try{
  for(const _0x103490 of _0x704a8b){
    await _0x3b731d.insert("@local/drive-files",_0x103490);
  }
await _0x3b731d.flush();
}finally{
await _0x173c07.internalExitLocalTransaction();
}
const _0x5adf42=_0x173c07.internalOpenRoom(_0x3deee8,_0xeb09f6,{'mailbox':_0x2098b2.mailboxKeyPair.publicKey,'isPrivateProfile':!!_0x413e4b});
try{
  await runRoomMigration(_0x173c07,_0x5adf42,_0x2098b2,_0x4396c0,_0x413e4b),await _0x173c07.blindPeering.addAutobase(_0x5adf42.base,null,{'all':!![]});
}finally{
_0x173c07.internalReleaseRoom(_0x5adf42);
}
}
;
function peerIsAhead(_0x56d707){
  _0x1b5e84={
    _0xc2dca4:0x5d,_0x458be9:0xeb},_0x457035={
    _0x13d9b6:0xc5,_0x304209:0x505}
  ;
  for(const _0x42855d of _0x56d707.peers){
    if(_0x42855d.remoteLength<=_0x56d707.signedLength)continue;
    return!![];
  }
return![];
}
async function waitForUpdate(_0x2362b7,_0x2346f1){
  _0x2c91cd={
    _0x38d7c2:0x143,_0x56a384:0x15c,_0x2f40ed:0x443},_0x2bf19b={
    _0xd15376:0x6a,_0x143543:0x5df}
  ;
  await _0x2346f1.core.ready();
  const _0x31d4cb=_0x2346f1.core.findingPeers();
  const _0x30d826=setTimeout(_0x31d4cb,_0x2362b7.isTesting?0x4b:0x1d4c);
  try{
    await _0x2346f1.core.update();
    for(let _0x4e4e4b=--0x1eb0;_0x4e4e4b<0x5&&peerIsAhead(_0x2346f1.core);_0x4e4e4b++){
      if(_0x4e4e4b>0x0)await new Promise(_0x1c26c6=>setTimeout(_0x1c26c6,_0x2362b7.isTesting?--0x272c:0x3e8));
      await _0x2346f1.update();
    }
}finally{
clearTimeout(_0x30d826),_0x31d4cb();
}
}
async function runRoomMigration(_0x4574fd,_0xef1660,_0x543d68,_0x4058c7,_0x5aa631){
  _0x3224c8={
    _0x34cc58:0x63,_0x4d2daa:0xf7},_0x50fd5d={
    _0x343426:0x177,_0x186fda:0x130,_0x2bc76f:0x243}
  ;
  if(_0x4574fd.debugForceMigrationFailure&&b4a.equals(_0x4574fd.debugForceMigrationFailure,_0xef1660.key))throw new Error("Migration failed");
  await waitForUpdate(_0x4574fd,_0xef1660.base);
  const _0x5305d0=await _0xef1660.db.get("@keet/system-digest");
  if(!_0x5305d0){
    let _0x3005e6=null;
    if(_0x5aa631){
      const _0x475079=[];
      for(const _0x4f4815 of _0x5aa631.blockedMembers){
        _0x475079.push(_0x4f4815);
      }
    const _0x9099fc=[];
    for(const {roomKey:_0x250306,v3:_0xe6c4fb}of _0x4058c7){
      const {
        seed:_0x4b1fc2,encryptionKey:_0x32ac44,initiator:_0x536ea1,fastForwardTo:_0x4cb6c2}
      =_0xe6c4fb,_0xa9986d={
        'roomKey':_0x250306,'encryptionKey':_0x32ac44,'seed':_0x4b1fc2,'initiator':_0x536ea1,'fastForwardTo':_0x4cb6c2}
      ;
      _0x9099fc.push(_0xa9986d);
    }
  _0x3005e6={
    'sharedRooms':_0x9099fc,'blockedContacts':_0x475079}
  ;
}
await _0xef1660.dispatch("@keet/upgrade",{'version':0x9},{'dryRun':![],'optimistic':!![]});
if(_0x3005e6)await _0xef1660.dispatch("@keet-private-id/run-v3-migration",_0x3005e6,{'dryRun':![]});
}
const _0x33de8a=await _0x4574fd.local.get("@local/rooms",{'roomKey':_0xef1660.key});
_0x33de8a.digest&&_0x33de8a.dm&&_0x33de8a.dm.length&&(!_0x33de8a.config.title&&await _0x4574fd.privateProfile.dispatch("@keet-private-id/remove-contact",{'memberKey':_0x33de8a.dm[-0x1134]}));
if(!_0x5aa631){
  await _0xef1660.internalEnsureProfileUpdated();
  return;
}
const [_0x323c3b,_0x2bd4f6,_0x3b5096]=await Promise.all([_0xef1660.db.findOne("@keet/members"),_0xef1660.base.view.legacy.bee.get(CONFIG.ID_RECOVERY_PHRASE,ConfigSchema.Encoding),_0xef1660.base.getUserData(MNEMONIC_USERDATA_KEY)]);
const _0x25f464=_0x2bd4f6?c.decode(c.string,_0x2bd4f6.value):_0x3b5096&&b4a.toString(_0x3b5096,"utf-8");
if(_0x323c3b){
  const _0x33e856={
    ..._0x323c3b.profile,'mailbox':_0x543d68.mailboxKeyPair.publicKey}
  ;
  await _0x4574fd.internalUpdateProfile({'profile':_0x33e856});
}
if(_0x25f464){
  const _0x4c11d1=await _0x4574fd.internalEnterLocalTransaction();
  try{
    const _0x1b060c=await _0x4c11d1.get("@local/identity");
    _0x1b060c.entropy=mnemonicToEntropy(_0x25f464),await _0x4c11d1.insert("@local/identity",_0x1b060c),await _0x4c11d1.flush();
  }finally{
  await _0x4574fd.internalExitLocalTransaction();
}
await migrateDiscoveryCore(_0x4574fd,_0xef1660,_0x25f464,_0x543d68);
}
}
async function migrateDiscoveryCore(_0x4a0786,_0x6c99fb,_0x28e4b4,_0x328b90){
  _0x48d34a={
    _0x1dd6a5:0xa2,_0x134097:0x15e},_0x52b50c={
    _0x599942:0xf3,_0x5702b8:0x69,_0x52a47a:0x458}
  ;
  const _0x3e3809=await IdentityKey.from({'mnemonic':_0x28e4b4});
  await _0x4a0786.internalCreateDiscoveryCore(_0x3e3809);
  if(_0x4a0786.discoveryCore.length>-0x4660){
    const _0x21d9b9=Math.floor((Date.now()-IDENTITIES_RELEASE_TIMESTAMP)/(0x3e8));
    await _0x4a0786.discoveryCore.truncate(_0x4a0786.discoveryCore.length,_0x21d9b9);
  }
const _0x770512=_0x328b90.mailboxKeyPair.publicKey;
await _0x4a0786.discoveryCore.append({'version':0x1,'timestamp':Date.now(),'key':_0x6c99fb.key,'mailbox':_0x770512}),await _0x6c99fb.dispatch("@keet-private-id/update-identity",{'identity':{'publicKey':_0x3e3809.identityPublicKey,'discoveryCoreKey':_0x4a0786.discoveryCore.key}});
}