bitcore-message-zcash/bitcore-message.min.js

1 line
18 KiB
JavaScript
Raw Normal View History

2015-06-03 07:35:07 -07:00
require=function t(r,e,n){function i(s,a){if(!e[s]){if(!r[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var h=new Error("Cannot find module '"+s+"'");throw h.code="MODULE_NOT_FOUND",h}var f=e[s]={exports:{}};r[s][0].call(f.exports,function(t){var e=r[s][1][t];return i(e?e:t)},f,f.exports,t,r,e,n)}return e[s].exports}for(var o="function"==typeof require&&require,s=0;s<n.length;s++)i(n[s]);return i}({1:[function(t,r,e){(function(e){"use strict";var n=t("bitcore"),i=n.deps._,o=n.PrivateKey,s=n.PublicKey,a=n.Address,u=n.encoding.BufferWriter,h=n.crypto.ECDSA,f=n.crypto.Signature,c=n.crypto.Hash.sha256sha256,l=n.util.js,g=n.util.preconditions,p=function y(t){return this instanceof y?(g.checkArgument(i.isString(t),"First argument should be a string"),this.message=t,this):new y(t)};p.MAGIC_BYTES=new e("Bitcoin Signed Message:\n"),p.prototype.magicHash=function(){var t=u.varintBufNum(p.MAGIC_BYTES.length),r=new e(this.message),n=u.varintBufNum(r.length),i=e.concat([t,p.MAGIC_BYTES,n,r]),o=c(i);return o},p.prototype._sign=function(t){g.checkArgument(t instanceof o,"First argument should be an instance of PrivateKey");var r=this.magicHash(),e=new h;return e.hashbuf=r,e.privkey=t,e.pubkey=t.toPublicKey(),e.signRandomK(),e.calci(),e.sig},p.prototype.sign=function(t){var r=this._sign(t);return r.toCompact().toString("base64")},p.prototype._verify=function(t,r){g.checkArgument(t instanceof s,"First argument should be an instance of PublicKey"),g.checkArgument(r instanceof f,"Second argument should be an instance of Signature");var e=this.magicHash(),n=h.verify(e,r,t);return n||(this.error="The signature was invalid"),n},p.prototype.verify=function(t,r){g.checkArgument(t),g.checkArgument(r&&i.isString(r)),i.isString(t)&&(t=a.fromString(t));var n=f.fromCompact(new e(r,"base64")),o=new h;o.hashbuf=this.magicHash(),o.sig=n;var s=o.toPublicKey(),u=a.fromPublicKey(s,t.network);return t.toString()!==u.toString()?(this.error="The signature did not match the message digest",!1):this._verify(s,n)},p.fromString=function(t){return new p(t)},p.fromJSON=function(t){return l.isValidJSON(t)&&(t=JSON.parse(t)),new p(t.message)},p.prototype.toObject=function(){return{message:this.message}},p.prototype.toJSON=function(){return JSON.stringify(this.toObject())},p.prototype.toString=function(){return this.message},p.prototype.inspect=function(){return"<Message: "+this.toString()+">"},r.exports=p}).call(this,t("buffer").Buffer)},{bitcore:"bitcore",buffer:2}],2:[function(t,r,e){function n(t,r,e){if(!(this instanceof n))return new n(t,r,e);var i,o=typeof t;if("number"===o)i=t>0?t>>>0:0;else if("string"===o)"base64"===r&&(t=B(t)),i=n.byteLength(t,r);else{if("object"!==o||null===t)throw new TypeError("must start with number, buffer, array or string");"Buffer"===t.type&&M(t.data)&&(t=t.data),i=+t.length>0?Math.floor(+t.length):0}if(this.length>O)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+O.toString(16)+" bytes");var s;n.TYPED_ARRAY_SUPPORT?s=n._augment(new Uint8Array(i)):(s=this,s.length=i,s._isBuffer=!0);var a;if(n.TYPED_ARRAY_SUPPORT&&"number"==typeof t.byteLength)s._set(t);else if(S(t))if(n.isBuffer(t))for(a=0;i>a;a++)s[a]=t.readUInt8(a);else for(a=0;i>a;a++)s[a]=(t[a]%256+256)%256;else if("string"===o)s.write(t,0,r);else if("number"===o&&!n.TYPED_ARRAY_SUPPORT&&!e)for(a=0;i>a;a++)s[a]=0;return s}function i(t,r,e,n){e=Number(e)||0;var i=t.length-e;n?(n=Number(n),n>i&&(n=i)):n=i;var o=r.length;if(o%2!==0)throw new Error("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;n>s;s++){var a=parseInt(r.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");t[e+s]=a}return s}function o(t,r,e,n){var i=L(U(r),t,e,n);return i}function s(t,r,e,n){var i=L(P(r),t,e,n);return i}function a(t,r,e,n){return s(t,r,e,n)}function u(t,r,e,n){var i=L(R(r),t,e,n);return i}function h(t,r,e,n){var i=L(_(r),t,e,n,2);return i}function f(t,r,e){return D.fromByteArray(0===r&&e===t.length?t:t.slice(r,e))}function c(t,r,e){var n="",i="";e=Math.min(t.length,e);for(var o=r;e>o;o++)t[o]<=127?(n+=Y(i)+Str