Created
June 15, 2018 21:13
-
-
Save amark/f58322572d2ffd84d0c84225c0f7ad88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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