Skip to content

Instantly share code, notes, and snippets.

@amark
Created June 15, 2018 21:13
Show Gist options
  • Save amark/f58322572d2ffd84d0c84225c0f7ad88 to your computer and use it in GitHub Desktop.
Save amark/f58322572d2ffd84d0c84225c0f7ad88 to your computer and use it in GitHub Desktop.
function migrateCBCaccount(alias, pass, g, G){
G = G || window.Gun;
g = g || window.gun;
g.get('~@'+alias).map().once(async function(data){
var proof = await G.SEA.work(pass, data.auth.s);
var sea = await G.SEA.decrypt(data.auth.ek, proof, null, {name: "AES-CBC"});
if(!sea){
alert("Error: Could not decrypt old key for one of the accounts. Please try again.");
return;
}
console.log("SAVE YOUR KEYS IN CASE OF EXPLOSION:", sea.priv, sea.epriv);
sea.pub = data.pub;
sea.epub = data.epub;
var auth = await G.SEA.encrypt({priv: sea.priv, epriv: sea.epriv}, proof, null, {name: "AES-GCM"});
auth = await G.SEA.sign({ek: auth, s: data.auth.s}, sea);
console.log('~'+sea.pub, sea, auth);
g.get('~'+sea.pub).put({auth: auth}, function(ack){
if(ack.err){ return alert("Error: " + ack.err) }
alert("You should be good now, try logging in normally!");
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment