ethers.js/dist/ethers.min.js

1 line
399 KiB
JavaScript
Raw Normal View History

2022-10-01 08:34:06 +03:00
const version="6.0.0-beta-exports.4";async function resolveProperties(value){const keys=Object.keys(value);const results=await Promise.all(keys.map(k=>Promise.resolve(value[k])));return results.reduce((accum,v,index)=>{accum[keys[index]]=v;return accum},{})}function defineReadOnly(object,name,value){Object.defineProperty(object,name,{enumerable:true,value:value,writable:false})}function checkType(value,type){const types=type.split("|").map(t=>t.trim());for(let i=0;i<types.length;i++){switch(type){case"any":return;case"boolean":case"number":case"string":if(typeof value===type){return}}}throw new Error("invalid value for type")}function defineProperties(target,values,types,defaults){for(let key in values){let value=values[key];const fallback=defaults?defaults[key]:undefined;if(fallback!==undefined){value=fallback}else{const type=types?types[key]:null;if(type){checkType(value,type)}}Object.defineProperty(target,key,{enumerable:true,value:value,writable:false})}}const ErrorConstructors={};ErrorConstructors.INVALID_ARGUMENT=TypeError;ErrorConstructors.NUMERIC_FAULT=RangeError;ErrorConstructors.BUFFER_OVERRUN=RangeError;function isError(error,code){return error&&error.code===code}function isCallException(error){return isError(error,"CALL_EXCEPTION")}function makeError(message,code,info){{const details=[];if(info){if("message"in info||"code"in info||"name"in info){throw new Error(`value will overwrite populated values: ${JSON.stringify(info)}`)}for(const key in info){const value=info[key];try{details.push(key+"="+JSON.stringify(value))}catch(error){details.push(key+"=[could not serialize object]")}}}details.push(`code=${code}`);details.push(`version=${version}`);if(details.length){message+=" ("+details.join(", ")+")"}}const create=ErrorConstructors[code]||Error;const error=new create(message);defineReadOnly(error,"code",code);if(info){for(const key in info){defineReadOnly(error,key,info[key])}}return error}function throwError(message,code,info){throw makeError(message,code,info)}function throwArgumentError(message,name,value){return throwError(message,"INVALID_ARGUMENT",{argument:name,value:value})}function assertArgument(check,message,name,value){if(!check){throwArgumentError(message,name,value)}}function assertArgumentCount(count,expectedCount,message=""){if(message){message=": "+message}if(count<expectedCount){throwError("missing arguemnt"+message,"MISSING_ARGUMENT",{count:count,expectedCount:expectedCount})}if(count>expectedCount){throwError("too many arguemnts"+message,"UNEXPECTED_ARGUMENT",{count:count,expectedCount:expectedCount})}}const _normalizeForms=["NFD","NFC","NFKD","NFKC"].reduce((accum,form)=>{try{if("test".normalize(form)!=="test"){throw new Error("bad")}if(form==="NFD"){const check=String.fromCharCode(233).normalize("NFD");const expected=String.fromCharCode(101,769);if(check!==expected){throw new Error("broken")}}accum.push(form)}catch(error){}return accum},[]);function assertNormalize(form){if(_normalizeForms.indexOf(form)===-1){throwError("platform missing String.prototype.normalize","UNSUPPORTED_OPERATION",{operation:"String.prototype.normalize",info:{form:form}})}}function assertPrivate(givenGuard,guard,className=""){if(givenGuard!==guard){let method=className,operation="new";if(className){method+=".";operation+=" "+className}throwError(`private constructor; use ${method}from* methods`,"UNSUPPORTED_OPERATION",{operation:operation})}}function _getBytes(value,name,copy){if(value instanceof Uint8Array){if(copy){return new Uint8Array(value)}return value}if(typeof value==="string"&&value.match(/^0x([0-9a-f][0-9a-f])*$/i)){const result=new Uint8Array((value.length-2)/2);let offset=2;for(let i=0;i<result.length;i++){result[i]=parseInt(value.substring(offset,offset+2),16);offset+=2}return result}return throwArgumentError("invalid BytesLike value",name||"value",value)}function getBytes(value,name){return _getBytes(value,name,false)}function getBytesCopy(value,name){return _getBytes(value,name,true)}function isHexString(value,length){if(typeof value!=="string"||!value.match(/^0x[0-9A-Fa-f]*$/)){return false}if(type