(function(e){"use strict";varr=require("soop").imports(),t=r.coinUtil||require("../../util"),i=r.Point||require("../Point"),n=r.SecureRandom||require("../SecureRandom"),c=r.Key||require("../Key"),s=function(){};s.encryptObj=function(e,r,t,i){varc=news;c.KB=e,c.message=r,t=c.r=c.rand(t);varo=(c.R,c.S=c.getSfromPubkey()),u=s.kdf(o),p=c.kE=u.slice(0,32),a=c.kM=u.slice(32,64);i=i||n.getRandomBuffer(16);{varf=c.c=s.symmetricEncrypt(p,i,r);c.d=s.mac(a,f)}returnc},s.encrypt=function(r,t,i,n){varo=s.encryptObj(r,t,i,n),u=newc;u.compressed=!1,u.public=o.R.toUncompressedPubKey(),u.compressed=!0;varp=u.public,a=e.concat([p,o.c,o.d]);returna},s.decryptObj=function(e){varr=e.kB,t=e.R,n=e.c,c=e.d,o=i.multiply(t,r),u=o.x.toBuffer({size:32}),p=s.kdf(u),a=e.kE=p.slice(0,32),f=e.kM=p.slice(32,64),y=s.mac(f,n);if(c.toString("hex")!==y.toString("hex"))thrownewError("MAC check incorrect. Data is invalid.");varh=s.symmetricDecrypt(a,n);returnh},s.decrypt=function(e,r){if(r.length<97)thrownewError("invalid length of encrypted data");vart=news;t.kB=e;varn=r.slice(0,33),o=newc;returno.public=n,o.compressed=!1,t.R=i.fromUncompressedPubKey(o.public),t.c=r.slice(33,r.length-64),t.d=r.slice(r.length-64,r.length),s.decryptObj(t)},s.kdf=function(e){varr=t.sha512(e);returnr},s.mac=function(e,r){vari=t.sha512hmac(e,r);returni},s.prototype.rand=function(e){returne?(this.key=newc,this.key.private=e,this.key.regenerateSync()):this.key=c.generateSync(),this.r=this.key.private,this.key.compressed=!1,this.R=i.fromUncompressedPubKey(this.key.public),this.r},s.prototype.getSfromPubkey=function(){vare=newc;e.public=this.KB,e.compressed=!1;varr=i.fromUncompressedPubKey(e.public);returnthis.P=i.multiply(r,this.r),this.S=this.P.x.toBuffer({size:32}),this.S},s.prototype.getSfromPrivkey=function(){vare=this.R,r=this.kB,t=i.multiply(e,r),n=t.x.toBuffer({size:32});returnn},module.exports=require("soop")(s)}).call(this,require("buffer").Buffer);
(function(e){"use strict";varr=require("soop").imports(),t=r.coinUtil||require("../../util"),i=r.Point||require("../Point"),n=r.SecureRandom||require("../SecureRandom"),c=r.Key||require("../Key"),o=function(){};o.encryptObj=function(e,r,t,i){varc=newo;c.KB=e,c.message=r,t=c.getRandomSeed(t);vars=(c.R,c.S=c.getSfromPubkey()),u=o.kdf(s),p=c.kE=u.slice(0,32),a=c.kM=u.slice(32,64);i=i||n.getRandomBuffer(16);{varf=c.c=o.symmetricEncrypt(p,i,r);c.d=o.mac(a,f)}returnc},o.encrypt=function(r,t,i,n){vars=o.encryptObj(r,t,i,n),u=newc;u.compressed=!1,u.public=s.R.toUncompressedPubKey(),u.compressed=!0;varp=u.public,a=e.concat([p,s.c,s.d]);returna},o.decryptObj=function(e){varr=e.kB,t=e.R,n=e.c,c=e.d,s=i.multiply(t,r),u=s.x.toBuffer({size:32}),p=o.kdf(u),a=e.kE=p.slice(0,32),f=e.kM=p.slice(32,64),y=o.mac(f,n);if(c.toString("hex")!==y.toString("hex"))thrownewError("MAC check incorrect. Data is invalid.");varm=o.symmetricDecrypt(a,n);returnm},o.decrypt=function(e,r){if(r.length<97)thrownewError("invalid length of encrypted data");vart=newo;t.kB=e;varn=r.slice(0,33),s=newc;returns.public=n,s.compressed=!1,t.R=i.fromUncompressedPubKey(s.public),t.c=r.slice(33,r.length-64),t.d=r.slice(r.length-64,r.length),o.decryptObj(t)},o.kdf=function(e){varr=t.sha512(e);returnr},o.mac=function(e,r){vari=t.sha512hmac(e,r);returni},o.prototype.getRandomSeed=function(e){returne?(this.key=newc,this.key.private=e,this.key.regenerateSync()):this.key=c.generateSync(),this.r=this.key.private,this.key.compressed=!1,this.R=i.fromUncompressedPubKey(this.key.public),this.r},o.prototype.getSfromPubkey=function(){vare=newc;e.public=this.KB,e.compressed=!1;varr=i.fromUncompressedPubKey(e.public);returnthis.P=i.multiply(r,this.r),this.S=this.P.x.toBuffer({size:32}),this.S},o.prototype.getSfromPrivkey=function(){vare=this.R,r=this.kB,t=i.multiply(e,r),n=t.x.toBuffer({size:32});returnn},module.exports=require("soop")(o)}).call(this,require("buffer").Buffer);