// TODO: we probably should expose method for replacing the signature, this is too intrusive
s.m=Automerge.change(s.m,'sign',(doc)=>{
doc['signature']=wrappedData.s;
});
s.setSigner(signer);
s.onauthenticate=(v)=>{
console.log('vvv',v);
if(!v){
whohoo(undefined);
return;
}
constopts={
message: pgp.message.fromText(s.toJSON()),
publicKeys: keystore.getEncryptKeys(),
};
pgp.encrypt(opts).then((cipherText)=>{
constsql="INSERT INTO store (owner_fingerprint, hash, content) VALUES ('"+signer.fingerprint()+"', '"+digest+"', '"+cipherText.data+"') ON CONFLICT (hash) DO UPDATE SET content = EXCLUDED.content;";
db.query(sql,(e,rs)=>{
if(e!==null&&e!==undefined){
doh(e);
return;
}
whohoo(true);
});
});
};
s.authenticate(true)
});
}
functionhandleClientMergeGet(db,digest,keystore){
constsql="SELECT content FROM store WHERE hash = '"+digest+"'";
returnnewPromise<string>((whohoo,doh)=>{
db.query(sql,(e,rs)=>{
console.log('rs',e,rs);
if(e!==null&&e!==undefined){
doh(e);
return;
}elseif(rs.rowCount==0){// TODO fix the postgres/sqlite method name issues, this will now break on postgres
constsql="INSERT INTO store (owner_fingerprint, hash, content) VALUES ('"+signer.fingerprint()+"', '"+digest+"', '"+cipherText.data+"') ON CONFLICT (hash) DO UPDATE SET content = EXCLUDED.content;";