@imtbl/toolkit 2.1.16-alpha.4 → 2.1.17-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
- import i from 'bn.js';
2
- import * as n from 'enc-utils';
1
+ import G from 'bn.js';
2
+ import * as H from 'enc-utils';
3
+ import { toUtf8Bytes } from 'ethers';
4
+ import { track } from '@imtbl/metrics';
3
5
 
4
- function g(e){return n.addHexPrefix(n.padLeft(e.r.toString(16),64)+n.padLeft(e.s.toString(16),64)+n.padLeft(e.recoveryParam?.toString(16)||"",2))}function d(e){let t=new i(e,16).cmp(new i(27))!==-1?new i(e,16).sub(new i(27)).toNumber():new i(e,16).toNumber();return e.trim()?t:void 0}function c(e,t=64){let r=n.removeHexPrefix(e);return {r:new i(r.substring(0,t),"hex"),s:new i(r.substring(t,t*2),"hex"),recoveryParam:d(r.substring(t*2,t*2+2))}}async function a(e,t){let r=c(await t.signMessage(e));return g(r)}async function p(e){let t=Math.floor(Date.now()/1e3).toString(),r=await a(t,e);return {timestamp:t,signature:r}}async function f(e,t){let r=await t.getAddress(),u=await a(e,t);return {message:e,ethAddress:r,ethSignature:u}}function x(e){switch(e.type){case"ERC721":return {type:"ERC721",data:{token_id:e.tokenId,token_address:e.tokenAddress}};case"ERC20":return {type:"ERC20",data:{token_address:e.tokenAddress}};case"ETH":default:return {type:"ETH",data:{decimals:18}}}}
6
+ var j={},lr=!1;function kr(){if(lr)return j;lr=!0,j.byteLength=A,j.toByteArray=L,j.fromByteArray=k;for(var s=[],c=[],w=typeof Uint8Array<"u"?Uint8Array:Array,x="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",m=0,f=x.length;m<f;++m)s[m]=x[m],c[x.charCodeAt(m)]=m;c[45]=62,c[95]=63;function o(a){var l=a.length;if(l%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var g=a.indexOf("=");g===-1&&(g=l);var S=g===l?0:4-g%4;return [g,S]}function A(a){var l=o(a),g=l[0],S=l[1];return (g+S)*3/4-S}function _(a,l,g){return (l+g)*3/4-g}function L(a){var l,g=o(a),S=g[0],P=g[1],U=new w(_(a,S,P)),M=0,b=P>0?S-4:S,C;for(C=0;C<b;C+=4)l=c[a.charCodeAt(C)]<<18|c[a.charCodeAt(C+1)]<<12|c[a.charCodeAt(C+2)]<<6|c[a.charCodeAt(C+3)],U[M++]=l>>16&255,U[M++]=l>>8&255,U[M++]=l&255;return P===2&&(l=c[a.charCodeAt(C)]<<2|c[a.charCodeAt(C+1)]>>4,U[M++]=l&255),P===1&&(l=c[a.charCodeAt(C)]<<10|c[a.charCodeAt(C+1)]<<4|c[a.charCodeAt(C+2)]>>2,U[M++]=l>>8&255,U[M++]=l&255),U}function I(a){return s[a>>18&63]+s[a>>12&63]+s[a>>6&63]+s[a&63]}function R(a,l,g){for(var S,P=[],U=l;U<g;U+=3)S=(a[U]<<16&16711680)+(a[U+1]<<8&65280)+(a[U+2]&255),P.push(I(S));return P.join("")}function k(a){for(var l,g=a.length,S=g%3,P=[],U=16383,M=0,b=g-S;M<b;M+=U)P.push(R(a,M,M+U>b?b:M+U));return S===1?(l=a[g-1],P.push(s[l>>2]+s[l<<4&63]+"==")):S===2&&(l=(a[g-2]<<8)+a[g-1],P.push(s[l>>10]+s[l>>4&63]+s[l<<2&63]+"=")),P.join("")}return j}var K={},fr=!1;function Lr(){if(fr)return K;fr=!0;return K.read=function(s,c,w,x,m){var f,o,A=m*8-x-1,_=(1<<A)-1,L=_>>1,I=-7,R=w?m-1:0,k=w?-1:1,a=s[c+R];for(R+=k,f=a&(1<<-I)-1,a>>=-I,I+=A;I>0;f=f*256+s[c+R],R+=k,I-=8);for(o=f&(1<<-I)-1,f>>=-I,I+=x;I>0;o=o*256+s[c+R],R+=k,I-=8);if(f===0)f=1-L;else {if(f===_)return o?NaN:(a?-1:1)*(1/0);o=o+Math.pow(2,x),f=f-L;}return (a?-1:1)*o*Math.pow(2,f-x)},K.write=function(s,c,w,x,m,f){var o,A,_,L=f*8-m-1,I=(1<<L)-1,R=I>>1,k=m===23?Math.pow(2,-24)-Math.pow(2,-77):0,a=x?0:f-1,l=x?1:-1,g=c<0||c===0&&1/c<0?1:0;for(c=Math.abs(c),isNaN(c)||c===1/0?(A=isNaN(c)?1:0,o=I):(o=Math.floor(Math.log(c)/Math.LN2),c*(_=Math.pow(2,-o))<1&&(o--,_*=2),o+R>=1?c+=k/_:c+=k*Math.pow(2,1-R),c*_>=2&&(o++,_/=2),o+R>=I?(A=0,o=I):o+R>=1?(A=(c*_-1)*Math.pow(2,m),o=o+R):(A=c*Math.pow(2,R-1)*Math.pow(2,m),o=0));m>=8;s[w+a]=A&255,a+=l,A/=256,m-=8);for(o=o<<m|A,L+=m;L>0;s[w+a]=o&255,a+=l,o/=256,L-=8);s[w+a-l]|=g*128;},K}var Y={},wr=!1;function $r(){if(wr)return Y;wr=!0;let s=kr(),c=Lr(),w=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Y.Buffer=o,Y.SlowBuffer=P,Y.INSPECT_MAX_BYTES=50;let x=2147483647;Y.kMaxLength=x,o.TYPED_ARRAY_SUPPORT=m(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function m(){try{let e=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(e,r),e.foo()===42}catch{return !1}}Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function f(e){if(e>x)throw new RangeError('The value "'+e+'" is invalid for option "size"');let r=new Uint8Array(e);return Object.setPrototypeOf(r,o.prototype),r}function o(e,r,t){if(typeof e=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return I(e)}return A(e,r,t)}o.poolSize=8192;function A(e,r,t){if(typeof e=="string")return R(e,r);if(ArrayBuffer.isView(e))return a(e);if(e==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if($(e,ArrayBuffer)||e&&$(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&($(e,SharedArrayBuffer)||e&&$(e.buffer,SharedArrayBuffer)))return l(e,r,t);if(typeof e=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=e.valueOf&&e.valueOf();if(n!=null&&n!==e)return o.from(n,r,t);let i=g(e);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]=="function")return o.from(e[Symbol.toPrimitive]("string"),r,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}o.from=function(e,r,t){return A(e,r,t)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function _(e){if(typeof e!="number")throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function L(e,r,t){return _(e),e<=0?f(e):r!==void 0?typeof t=="string"?f(e).fill(r,t):f(e).fill(r):f(e)}o.alloc=function(e,r,t){return L(e,r,t)};function I(e){return _(e),f(e<0?0:S(e)|0)}o.allocUnsafe=function(e){return I(e)},o.allocUnsafeSlow=function(e){return I(e)};function R(e,r){if((typeof r!="string"||r==="")&&(r="utf8"),!o.isEncoding(r))throw new TypeError("Unknown encoding: "+r);let t=U(e,r)|0,n=f(t),i=n.write(e,r);return i!==t&&(n=n.slice(0,i)),n}function k(e){let r=e.length<0?0:S(e.length)|0,t=f(r);for(let n=0;n<r;n+=1)t[n]=e[n]&255;return t}function a(e){if($(e,Uint8Array)){let r=new Uint8Array(e);return l(r.buffer,r.byteOffset,r.byteLength)}return k(e)}function l(e,r,t){if(r<0||e.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<r+(t||0))throw new RangeError('"length" is outside of buffer bounds');let n;return r===void 0&&t===void 0?n=new Uint8Array(e):t===void 0?n=new Uint8Array(e,r):n=new Uint8Array(e,r,t),Object.setPrototypeOf(n,o.prototype),n}function g(e){if(o.isBuffer(e)){let r=S(e.length)|0,t=f(r);return t.length===0||e.copy(t,0,0,r),t}if(e.length!==void 0)return typeof e.length!="number"||v(e.length)?f(0):k(e);if(e.type==="Buffer"&&Array.isArray(e.data))return k(e.data)}function S(e){if(e>=x)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+x.toString(16)+" bytes");return e|0}function P(e){return +e!=e&&(e=0),o.alloc(+e)}o.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==o.prototype},o.compare=function(r,t){if($(r,Uint8Array)&&(r=o.from(r,r.offset,r.byteLength)),$(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(r)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(r===t)return 0;let n=r.length,i=t.length;for(let u=0,h=Math.min(n,i);u<h;++u)if(r[u]!==t[u]){n=r[u],i=t[u];break}return n<i?-1:i<n?1:0},o.isEncoding=function(r){switch(String(r).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return !0;default:return !1}},o.concat=function(r,t){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return o.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<r.length;++n)t+=r[n].length;let i=o.allocUnsafe(t),u=0;for(n=0;n<r.length;++n){let h=r[n];if($(h,Uint8Array))u+h.length>i.length?(o.isBuffer(h)||(h=o.from(h)),h.copy(i,u)):Uint8Array.prototype.set.call(i,h,u);else if(o.isBuffer(h))h.copy(i,u);else throw new TypeError('"list" argument must be an Array of Buffers');u+=h.length;}return i};function U(e,r){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||$(e,ArrayBuffer))return e.byteLength;if(typeof e!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let t=e.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(r){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Q(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return pr(e).length;default:if(i)return n?-1:Q(e).length;r=(""+r).toLowerCase(),i=!0;}}o.byteLength=U;function M(e,r,t){let n=!1;if((r===void 0||r<0)&&(r=0),r>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,r>>>=0,t<=r))return "";for(e||(e="utf8");;)switch(e){case"hex":return Sr(this,r,t);case"utf8":case"utf-8":return er(this,r,t);case"ascii":return Ur(this,r,t);case"latin1":case"binary":return xr(this,r,t);case"base64":return Ir(this,r,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Tr(this,r,t);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0;}}o.prototype._isBuffer=!0;function b(e,r,t){let n=e[r];e[r]=e[t],e[t]=n;}o.prototype.swap16=function(){let r=this.length;if(r%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<r;t+=2)b(this,t,t+1);return this},o.prototype.swap32=function(){let r=this.length;if(r%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<r;t+=4)b(this,t,t+3),b(this,t+1,t+2);return this},o.prototype.swap64=function(){let r=this.length;if(r%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<r;t+=8)b(this,t,t+7),b(this,t+1,t+6),b(this,t+2,t+5),b(this,t+3,t+4);return this},o.prototype.toString=function(){let r=this.length;return r===0?"":arguments.length===0?er(this,0,r):M.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(r){if(!o.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:o.compare(this,r)===0},o.prototype.inspect=function(){let r="",t=Y.INSPECT_MAX_BYTES;return r=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(r+=" ... "),"<Buffer "+r+">"},w&&(o.prototype[w]=o.prototype.inspect),o.prototype.compare=function(r,t,n,i,u){if($(r,Uint8Array)&&(r=o.from(r,r.offset,r.byteLength)),!o.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(t===void 0&&(t=0),n===void 0&&(n=r?r.length:0),i===void 0&&(i=0),u===void 0&&(u=this.length),t<0||n>r.length||i<0||u>this.length)throw new RangeError("out of range index");if(i>=u&&t>=n)return 0;if(i>=u)return -1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,u>>>=0,this===r)return 0;let h=u-i,p=n-t,B=Math.min(h,p),d=this.slice(i,u),E=r.slice(t,n);for(let y=0;y<B;++y)if(d[y]!==E[y]){h=d[y],p=E[y];break}return h<p?-1:p<h?1:0};function C(e,r,t,n,i){if(e.length===0)return -1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,v(t)&&(t=i?0:e.length-1),t<0&&(t=e.length+t),t>=e.length){if(i)return -1;t=e.length-1;}else if(t<0)if(i)t=0;else return -1;if(typeof r=="string"&&(r=o.from(r,n)),o.isBuffer(r))return r.length===0?-1:tr(e,r,t,n,i);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(e,r,t):Uint8Array.prototype.lastIndexOf.call(e,r,t):tr(e,[r],t,n,i);throw new TypeError("val must be string, number or Buffer")}function tr(e,r,t,n,i){let u=1,h=e.length,p=r.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(e.length<2||r.length<2)return -1;u=2,h/=2,p/=2,t/=2;}function B(E,y){return u===1?E[y]:E.readUInt16BE(y*u)}let d;if(i){let E=-1;for(d=t;d<h;d++)if(B(e,d)===B(r,E===-1?0:d-E)){if(E===-1&&(E=d),d-E+1===p)return E*u}else E!==-1&&(d-=d-E),E=-1;}else for(t+p>h&&(t=h-p),d=t;d>=0;d--){let E=!0;for(let y=0;y<p;y++)if(B(e,d+y)!==B(r,y)){E=!1;break}if(E)return d}return -1}o.prototype.includes=function(r,t,n){return this.indexOf(r,t,n)!==-1},o.prototype.indexOf=function(r,t,n){return C(this,r,t,n,!0)},o.prototype.lastIndexOf=function(r,t,n){return C(this,r,t,n,!1)};function gr(e,r,t,n){t=Number(t)||0;let i=e.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;let u=r.length;n>u/2&&(n=u/2);let h;for(h=0;h<n;++h){let p=parseInt(r.substr(h*2,2),16);if(v(p))return h;e[t+h]=p;}return h}function dr(e,r,t,n){return J(Q(r,e.length-t),e,t,n)}function mr(e,r,t,n){return J(Pr(r),e,t,n)}function Br(e,r,t,n){return J(pr(r),e,t,n)}function Er(e,r,t,n){return J(Mr(r,e.length-t),e,t,n)}o.prototype.write=function(r,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let u=this.length-t;if((n===void 0||n>u)&&(n=u),r.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let h=!1;for(;;)switch(i){case"hex":return gr(this,r,t,n);case"utf8":case"utf-8":return dr(this,r,t,n);case"ascii":case"latin1":case"binary":return mr(this,r,t,n);case"base64":return Br(this,r,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Er(this,r,t,n);default:if(h)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),h=!0;}},o.prototype.toJSON=function(){return {type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Ir(e,r,t){return r===0&&t===e.length?s.fromByteArray(e):s.fromByteArray(e.slice(r,t))}function er(e,r,t){t=Math.min(e.length,t);let n=[],i=r;for(;i<t;){let u=e[i],h=null,p=u>239?4:u>223?3:u>191?2:1;if(i+p<=t){let B,d,E,y;switch(p){case 1:u<128&&(h=u);break;case 2:B=e[i+1],(B&192)===128&&(y=(u&31)<<6|B&63,y>127&&(h=y));break;case 3:B=e[i+1],d=e[i+2],(B&192)===128&&(d&192)===128&&(y=(u&15)<<12|(B&63)<<6|d&63,y>2047&&(y<55296||y>57343)&&(h=y));break;case 4:B=e[i+1],d=e[i+2],E=e[i+3],(B&192)===128&&(d&192)===128&&(E&192)===128&&(y=(u&15)<<18|(B&63)<<12|(d&63)<<6|E&63,y>65535&&y<1114112&&(h=y));}}h===null?(h=65533,p=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|h&1023),n.push(h),i+=p;}return Ar(n)}let nr=4096;function Ar(e){let r=e.length;if(r<=nr)return String.fromCharCode.apply(String,e);let t="",n=0;for(;n<r;)t+=String.fromCharCode.apply(String,e.slice(n,n+=nr));return t}function Ur(e,r,t){let n="";t=Math.min(e.length,t);for(let i=r;i<t;++i)n+=String.fromCharCode(e[i]&127);return n}function xr(e,r,t){let n="";t=Math.min(e.length,t);for(let i=r;i<t;++i)n+=String.fromCharCode(e[i]);return n}function Sr(e,r,t){let n=e.length;(!r||r<0)&&(r=0),(!t||t<0||t>n)&&(t=n);let i="";for(let u=r;u<t;++u)i+=Nr[e[u]];return i}function Tr(e,r,t){let n=e.slice(r,t),i="";for(let u=0;u<n.length-1;u+=2)i+=String.fromCharCode(n[u]+n[u+1]*256);return i}o.prototype.slice=function(r,t){let n=this.length;r=~~r,t=t===void 0?n:~~t,r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<r&&(t=r);let i=this.subarray(r,t);return Object.setPrototypeOf(i,o.prototype),i};function T(e,r,t){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+r>t)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(r,t,n){r=r>>>0,t=t>>>0,n||T(r,t,this.length);let i=this[r],u=1,h=0;for(;++h<t&&(u*=256);)i+=this[r+h]*u;return i},o.prototype.readUintBE=o.prototype.readUIntBE=function(r,t,n){r=r>>>0,t=t>>>0,n||T(r,t,this.length);let i=this[r+--t],u=1;for(;t>0&&(u*=256);)i+=this[r+--t]*u;return i},o.prototype.readUint8=o.prototype.readUInt8=function(r,t){return r=r>>>0,t||T(r,1,this.length),this[r]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(r,t){return r=r>>>0,t||T(r,2,this.length),this[r]|this[r+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(r,t){return r=r>>>0,t||T(r,2,this.length),this[r]<<8|this[r+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(r,t){return r=r>>>0,t||T(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(r,t){return r=r>>>0,t||T(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])},o.prototype.readBigUInt64LE=D(function(r){r=r>>>0,W(r,"offset");let t=this[r],n=this[r+7];(t===void 0||n===void 0)&&z(r,this.length-8);let i=t+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24,u=this[++r]+this[++r]*2**8+this[++r]*2**16+n*2**24;return BigInt(i)+(BigInt(u)<<BigInt(32))}),o.prototype.readBigUInt64BE=D(function(r){r=r>>>0,W(r,"offset");let t=this[r],n=this[r+7];(t===void 0||n===void 0)&&z(r,this.length-8);let i=t*2**24+this[++r]*2**16+this[++r]*2**8+this[++r],u=this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+n;return (BigInt(i)<<BigInt(32))+BigInt(u)}),o.prototype.readIntLE=function(r,t,n){r=r>>>0,t=t>>>0,n||T(r,t,this.length);let i=this[r],u=1,h=0;for(;++h<t&&(u*=256);)i+=this[r+h]*u;return u*=128,i>=u&&(i-=Math.pow(2,8*t)),i},o.prototype.readIntBE=function(r,t,n){r=r>>>0,t=t>>>0,n||T(r,t,this.length);let i=t,u=1,h=this[r+--i];for(;i>0&&(u*=256);)h+=this[r+--i]*u;return u*=128,h>=u&&(h-=Math.pow(2,8*t)),h},o.prototype.readInt8=function(r,t){return r=r>>>0,t||T(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]},o.prototype.readInt16LE=function(r,t){r=r>>>0,t||T(r,2,this.length);let n=this[r]|this[r+1]<<8;return n&32768?n|4294901760:n},o.prototype.readInt16BE=function(r,t){r=r>>>0,t||T(r,2,this.length);let n=this[r+1]|this[r]<<8;return n&32768?n|4294901760:n},o.prototype.readInt32LE=function(r,t){return r=r>>>0,t||T(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24},o.prototype.readInt32BE=function(r,t){return r=r>>>0,t||T(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]},o.prototype.readBigInt64LE=D(function(r){r=r>>>0,W(r,"offset");let t=this[r],n=this[r+7];(t===void 0||n===void 0)&&z(r,this.length-8);let i=this[r+4]+this[r+5]*2**8+this[r+6]*2**16+(n<<24);return (BigInt(i)<<BigInt(32))+BigInt(t+this[++r]*2**8+this[++r]*2**16+this[++r]*2**24)}),o.prototype.readBigInt64BE=D(function(r){r=r>>>0,W(r,"offset");let t=this[r],n=this[r+7];(t===void 0||n===void 0)&&z(r,this.length-8);let i=(t<<24)+this[++r]*2**16+this[++r]*2**8+this[++r];return (BigInt(i)<<BigInt(32))+BigInt(this[++r]*2**24+this[++r]*2**16+this[++r]*2**8+n)}),o.prototype.readFloatLE=function(r,t){return r=r>>>0,t||T(r,4,this.length),c.read(this,r,!0,23,4)},o.prototype.readFloatBE=function(r,t){return r=r>>>0,t||T(r,4,this.length),c.read(this,r,!1,23,4)},o.prototype.readDoubleLE=function(r,t){return r=r>>>0,t||T(r,8,this.length),c.read(this,r,!0,52,8)},o.prototype.readDoubleBE=function(r,t){return r=r>>>0,t||T(r,8,this.length),c.read(this,r,!1,52,8)};function N(e,r,t,n,i,u){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<u)throw new RangeError('"value" argument is out of bounds');if(t+n>e.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(r,t,n,i){if(r=+r,t=t>>>0,n=n>>>0,!i){let p=Math.pow(2,8*n)-1;N(this,r,t,n,p,0);}let u=1,h=0;for(this[t]=r&255;++h<n&&(u*=256);)this[t+h]=r/u&255;return t+n},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(r,t,n,i){if(r=+r,t=t>>>0,n=n>>>0,!i){let p=Math.pow(2,8*n)-1;N(this,r,t,n,p,0);}let u=n-1,h=1;for(this[t+u]=r&255;--u>=0&&(h*=256);)this[t+u]=r/h&255;return t+n},o.prototype.writeUint8=o.prototype.writeUInt8=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,1,255,0),this[t]=r&255,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,2,65535,0),this[t]=r&255,this[t+1]=r>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,2,65535,0),this[t]=r>>>8,this[t+1]=r&255,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,4,4294967295,0),this[t+3]=r>>>24,this[t+2]=r>>>16,this[t+1]=r>>>8,this[t]=r&255,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,4,4294967295,0),this[t]=r>>>24,this[t+1]=r>>>16,this[t+2]=r>>>8,this[t+3]=r&255,t+4};function ir(e,r,t,n,i){ar(r,n,i,e,t,7);let u=Number(r&BigInt(4294967295));e[t++]=u,u=u>>8,e[t++]=u,u=u>>8,e[t++]=u,u=u>>8,e[t++]=u;let h=Number(r>>BigInt(32)&BigInt(4294967295));return e[t++]=h,h=h>>8,e[t++]=h,h=h>>8,e[t++]=h,h=h>>8,e[t++]=h,t}function or(e,r,t,n,i){ar(r,n,i,e,t,7);let u=Number(r&BigInt(4294967295));e[t+7]=u,u=u>>8,e[t+6]=u,u=u>>8,e[t+5]=u,u=u>>8,e[t+4]=u;let h=Number(r>>BigInt(32)&BigInt(4294967295));return e[t+3]=h,h=h>>8,e[t+2]=h,h=h>>8,e[t+1]=h,h=h>>8,e[t]=h,t+8}o.prototype.writeBigUInt64LE=D(function(r,t=0){return ir(this,r,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=D(function(r,t=0){return or(this,r,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(r,t,n,i){if(r=+r,t=t>>>0,!i){let B=Math.pow(2,8*n-1);N(this,r,t,n,B-1,-B);}let u=0,h=1,p=0;for(this[t]=r&255;++u<n&&(h*=256);)r<0&&p===0&&this[t+u-1]!==0&&(p=1),this[t+u]=(r/h>>0)-p&255;return t+n},o.prototype.writeIntBE=function(r,t,n,i){if(r=+r,t=t>>>0,!i){let B=Math.pow(2,8*n-1);N(this,r,t,n,B-1,-B);}let u=n-1,h=1,p=0;for(this[t+u]=r&255;--u>=0&&(h*=256);)r<0&&p===0&&this[t+u+1]!==0&&(p=1),this[t+u]=(r/h>>0)-p&255;return t+n},o.prototype.writeInt8=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,1,127,-128),r<0&&(r=255+r+1),this[t]=r&255,t+1},o.prototype.writeInt16LE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,2,32767,-32768),this[t]=r&255,this[t+1]=r>>>8,t+2},o.prototype.writeInt16BE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,2,32767,-32768),this[t]=r>>>8,this[t+1]=r&255,t+2},o.prototype.writeInt32LE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,4,2147483647,-2147483648),this[t]=r&255,this[t+1]=r>>>8,this[t+2]=r>>>16,this[t+3]=r>>>24,t+4},o.prototype.writeInt32BE=function(r,t,n){return r=+r,t=t>>>0,n||N(this,r,t,4,2147483647,-2147483648),r<0&&(r=4294967295+r+1),this[t]=r>>>24,this[t+1]=r>>>16,this[t+2]=r>>>8,this[t+3]=r&255,t+4},o.prototype.writeBigInt64LE=D(function(r,t=0){return ir(this,r,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=D(function(r,t=0){return or(this,r,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function ur(e,r,t,n,i,u){if(t+n>e.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function hr(e,r,t,n,i){return r=+r,t=t>>>0,i||ur(e,r,t,4),c.write(e,r,t,n,23,4),t+4}o.prototype.writeFloatLE=function(r,t,n){return hr(this,r,t,!0,n)},o.prototype.writeFloatBE=function(r,t,n){return hr(this,r,t,!1,n)};function cr(e,r,t,n,i){return r=+r,t=t>>>0,i||ur(e,r,t,8),c.write(e,r,t,n,52,8),t+8}o.prototype.writeDoubleLE=function(r,t,n){return cr(this,r,t,!0,n)},o.prototype.writeDoubleBE=function(r,t,n){return cr(this,r,t,!1,n)},o.prototype.copy=function(r,t,n,i){if(!o.isBuffer(r))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=r.length&&(t=r.length),t||(t=0),i>0&&i<n&&(i=n),i===n||r.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),r.length-t<i-n&&(i=r.length-t+n);let u=i-n;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(r,this.subarray(n,i),t),u},o.prototype.fill=function(r,t,n,i){if(typeof r=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!o.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(r.length===1){let h=r.charCodeAt(0);(i==="utf8"&&h<128||i==="latin1")&&(r=h);}}else typeof r=="number"?r=r&255:typeof r=="boolean"&&(r=Number(r));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,r||(r=0);let u;if(typeof r=="number")for(u=t;u<n;++u)this[u]=r;else {let h=o.isBuffer(r)?r:o.from(r,i),p=h.length;if(p===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(u=0;u<n-t;++u)this[u+t]=h[u%p];}return this};let V={};function Z(e,r,t){V[e]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:r.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name;}get code(){return e}set code(i){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:i,writable:!0});}toString(){return `${this.name} [${e}]: ${this.message}`}};}Z("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Z("ERR_INVALID_ARG_TYPE",function(e,r){return `The "${e}" argument must be of type number. Received type ${typeof r}`},TypeError),Z("ERR_OUT_OF_RANGE",function(e,r,t){let n=`The value of "${e}" is out of range.`,i=t;return Number.isInteger(t)&&Math.abs(t)>2**32?i=sr(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=sr(i)),i+="n"),n+=` It must be ${r}. Received ${i}`,n},RangeError);function sr(e){let r="",t=e.length,n=e[0]==="-"?1:0;for(;t>=n+4;t-=3)r=`_${e.slice(t-3,t)}${r}`;return `${e.slice(0,t)}${r}`}function Rr(e,r,t){W(r,"offset"),(e[r]===void 0||e[r+t]===void 0)&&z(r,e.length-(t+1));}function ar(e,r,t,n,i,u){if(e>t||e<r){let h=typeof r=="bigint"?"n":"",p;throw r===0||r===BigInt(0)?p=`>= 0${h} and < 2${h} ** ${(u+1)*8}${h}`:p=`>= -(2${h} ** ${(u+1)*8-1}${h}) and < 2 ** ${(u+1)*8-1}${h}`,new V.ERR_OUT_OF_RANGE("value",p,e)}Rr(n,i,u);}function W(e,r){if(typeof e!="number")throw new V.ERR_INVALID_ARG_TYPE(r,"number",e)}function z(e,r,t){throw Math.floor(e)!==e?(W(e,t),new V.ERR_OUT_OF_RANGE("offset","an integer",e)):r<0?new V.ERR_BUFFER_OUT_OF_BOUNDS:new V.ERR_OUT_OF_RANGE("offset",`>= ${0} and <= ${r}`,e)}let _r=/[^+/0-9A-Za-z-_]/g;function Cr(e){if(e=e.split("=")[0],e=e.trim().replace(_r,""),e.length<2)return "";for(;e.length%4!==0;)e=e+"=";return e}function Q(e,r){r=r||1/0;let t,n=e.length,i=null,u=[];for(let h=0;h<n;++h){if(t=e.charCodeAt(h),t>55295&&t<57344){if(!i){if(t>56319){(r-=3)>-1&&u.push(239,191,189);continue}else if(h+1===n){(r-=3)>-1&&u.push(239,191,189);continue}i=t;continue}if(t<56320){(r-=3)>-1&&u.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536;}else i&&(r-=3)>-1&&u.push(239,191,189);if(i=null,t<128){if((r-=1)<0)break;u.push(t);}else if(t<2048){if((r-=2)<0)break;u.push(t>>6|192,t&63|128);}else if(t<65536){if((r-=3)<0)break;u.push(t>>12|224,t>>6&63|128,t&63|128);}else if(t<1114112){if((r-=4)<0)break;u.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128);}else throw new Error("Invalid code point")}return u}function Pr(e){let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t)&255);return r}function Mr(e,r){let t,n,i,u=[];for(let h=0;h<e.length&&!((r-=2)<0);++h)t=e.charCodeAt(h),n=t>>8,i=t%256,u.push(i),u.push(n);return u}function pr(e){return s.toByteArray(Cr(e))}function J(e,r,t,n){let i;for(i=0;i<n&&!(i+t>=r.length||i>=e.length);++i)r[i+t]=e[i];return i}function $(e,r){return e instanceof r||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===r.name}function v(e){return e!==e}let Nr=function(){let e="0123456789abcdef",r=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)r[n+i]=e[t]+e[i];}return r}();function D(e){return typeof BigInt>"u"?br:e}function br(){throw new Error("BigInt not supported")}return Y}var X=$r();X.Buffer;X.SlowBuffer;X.INSPECT_MAX_BYTES;X.kMaxLength;var q=X.Buffer;X.INSPECT_MAX_BYTES;X.kMaxLength;function Fr(s){return H.addHexPrefix(H.padLeft(s.r.toString(16),64)+H.padLeft(s.s.toString(16),64)+H.padLeft(s.recoveryParam?.toString(16)||"",2))}function Dr(s){let c=new G(s,16).cmp(new G(27))!==-1?new G(s,16).sub(new G(27)).toNumber():new G(s,16).toNumber();return s.trim()?c:void 0}function Or(s,c=64){let w=H.removeHexPrefix(s);return {r:new G(w.substring(0,c),"hex"),s:new G(w.substring(c,c*2),"hex"),recoveryParam:Dr(w.substring(c*2,c*2+2))}}async function yr(s,c){let w=await c.getAddress();track("xProvider","log",{address:w,param:"signRaw.payload",val:s}),track("xProvider","log",{address:w,param:"signRaw.toUtf8Bytes",val:toUtf8Bytes(s).toString()}),track("xProvider","log",{address:w,param:"signRaw.payload.normalize() === payload",val:s===s.normalize()});let m=new TextEncoder().encode(s),f=new TextDecoder("utf-8").decode(m),o=q.from(s,"utf8"),A=new TextDecoder("utf-8").decode(o);track("xProvider","log",{address:w,param:"signRaw.message === payload.normalize()",val:f===s.normalize()}),track("xProvider","log",{address:w,param:"signRaw.message2 === payload.normalize()",val:A===s.normalize()}),track("xProvider","log",{address:w,param:"signRaw.message",val:f,bytes:toUtf8Bytes(f).toString()}),track("xProvider","log",{address:w,param:"signRaw.message2",val:A,bytes:toUtf8Bytes(A).toString()}),track("xProvider","log",{address:w,param:"signRaw.toUtf8Bytes === toUtf8Bytes(message)",val:toUtf8Bytes(s).toString()===toUtf8Bytes(f).toString()}),track("xProvider","log",{address:w,param:"signRaw.toUtf8Bytes === toUtf8Bytes(message2)",val:toUtf8Bytes(s).toString()===toUtf8Bytes(A).toString()});let _=Or(await c.signMessage(toUtf8Bytes(f)));return Fr(_)}async function Qr(s){let c=Math.floor(Date.now()/1e3).toString(),w=await yr(c,s);return {timestamp:c,signature:w}}async function vr(s,c){let w=await c.getAddress(),x=await yr(s,c);return {message:s,ethAddress:w,ethSignature:x}}function nt(s){switch(s.type){case"ERC721":return {type:"ERC721",data:{token_id:s.tokenId,token_address:s.tokenAddress}};case"ERC20":return {type:"ERC20",data:{token_address:s.tokenAddress}};case"ETH":default:return {type:"ETH",data:{decimals:18}}}}/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
5
7
 
6
- export { x as convertToSignableToken, p as generateIMXAuthorisationHeaders, f as signMessage, a as signRaw };
8
+ export { nt as convertToSignableToken, Qr as generateIMXAuthorisationHeaders, vr as signMessage, yr as signRaw };
@@ -1,7 +1,9 @@
1
1
  'use strict';
2
2
 
3
- var i = require('bn.js');
4
- var n = require('enc-utils');
3
+ var o = require('bn.js');
4
+ var i = require('enc-utils');
5
+ var ethers = require('ethers');
6
+ var metrics = require('@imtbl/metrics');
5
7
 
6
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
9
 
@@ -23,12 +25,12 @@ function _interopNamespace(e) {
23
25
  return Object.freeze(n);
24
26
  }
25
27
 
26
- var i__default = /*#__PURE__*/_interopDefault(i);
27
- var n__namespace = /*#__PURE__*/_interopNamespace(n);
28
+ var o__default = /*#__PURE__*/_interopDefault(o);
29
+ var i__namespace = /*#__PURE__*/_interopNamespace(i);
28
30
 
29
- function a(e){return n__namespace.addHexPrefix(n__namespace.padLeft(e.r.toString(16),64)+n__namespace.padLeft(e.s.toString(16),64)+n__namespace.padLeft(e.recoveryParam?.toString(16)||"",2))}function u(e){let t=new i__default.default(e,16).cmp(new i__default.default(27))!==-1?new i__default.default(e,16).sub(new i__default.default(27)).toNumber():new i__default.default(e,16).toNumber();return e.trim()?t:void 0}function g(e,t=64){let r=n__namespace.removeHexPrefix(e);return {r:new i__default.default(r.substring(0,t),"hex"),s:new i__default.default(r.substring(t,t*2),"hex"),recoveryParam:u(r.substring(t*2,t*2+2))}}async function s(e,t){let r=g(await t.signMessage(e));return a(r)}async function c(e){let t=Math.floor(Date.now()/1e3).toString(),r=await s(t,e);return {timestamp:t,signature:r}}async function m(e,t){let r=await t.getAddress(),o=await s(e,t);return {message:e,ethAddress:r,ethSignature:o}}function f(e){switch(e.type){case"ERC721":return {type:"ERC721",data:{token_id:e.tokenId,token_address:e.tokenAddress}};case"ERC20":return {type:"ERC20",data:{token_address:e.tokenAddress}};case"ETH":default:return {type:"ETH",data:{decimals:18}}}}
31
+ function l(e){return i__namespace.addHexPrefix(i__namespace.padLeft(e.r.toString(16),64)+i__namespace.padLeft(e.s.toString(16),64)+i__namespace.padLeft(e.recoveryParam?.toString(16)||"",2))}function p(e){let t=new o__default.default(e,16).cmp(new o__default.default(27))!==-1?new o__default.default(e,16).sub(new o__default.default(27)).toNumber():new o__default.default(e,16).toNumber();return e.trim()?t:void 0}function S(e,t=64){let r=i__namespace.removeHexPrefix(e);return {r:new o__default.default(r.substring(0,t),"hex"),s:new o__default.default(r.substring(t,t*2),"hex"),recoveryParam:p(r.substring(t*2,t*2+2))}}async function d(e,t){let r=await t.getAddress();metrics.track("xProvider","log",{address:r,param:"signRaw.payload",val:e}),metrics.track("xProvider","log",{address:r,param:"signRaw.toUtf8Bytes",val:ethers.toUtf8Bytes(e).toString()}),metrics.track("xProvider","log",{address:r,param:"signRaw.payload.normalize() === payload",val:e===e.normalize()});let u=new TextEncoder().encode(e),a=new TextDecoder("utf-8").decode(u),c=Buffer.from(e,"utf8"),g=new TextDecoder("utf-8").decode(c);metrics.track("xProvider","log",{address:r,param:"signRaw.message === payload.normalize()",val:a===e.normalize()}),metrics.track("xProvider","log",{address:r,param:"signRaw.message2 === payload.normalize()",val:g===e.normalize()}),metrics.track("xProvider","log",{address:r,param:"signRaw.message",val:a,bytes:ethers.toUtf8Bytes(a).toString()}),metrics.track("xProvider","log",{address:r,param:"signRaw.message2",val:g,bytes:ethers.toUtf8Bytes(g).toString()}),metrics.track("xProvider","log",{address:r,param:"signRaw.toUtf8Bytes === toUtf8Bytes(message)",val:ethers.toUtf8Bytes(e).toString()===ethers.toUtf8Bytes(a).toString()}),metrics.track("xProvider","log",{address:r,param:"signRaw.toUtf8Bytes === toUtf8Bytes(message2)",val:ethers.toUtf8Bytes(e).toString()===ethers.toUtf8Bytes(g).toString()});let f=S(await t.signMessage(ethers.toUtf8Bytes(a)));return l(f)}async function y(e){let t=Math.floor(Date.now()/1e3).toString(),r=await d(t,e);return {timestamp:t,signature:r}}async function b(e,t){let r=await t.getAddress(),m=await d(e,t);return {message:e,ethAddress:r,ethSignature:m}}function R(e){switch(e.type){case"ERC721":return {type:"ERC721",data:{token_id:e.tokenId,token_address:e.tokenAddress}};case"ERC20":return {type:"ERC20",data:{token_address:e.tokenAddress}};case"ETH":default:return {type:"ETH",data:{decimals:18}}}}
30
32
 
31
- exports.convertToSignableToken = f;
32
- exports.generateIMXAuthorisationHeaders = c;
33
- exports.signMessage = m;
34
- exports.signRaw = s;
33
+ exports.convertToSignableToken = R;
34
+ exports.generateIMXAuthorisationHeaders = y;
35
+ exports.signMessage = b;
36
+ exports.signRaw = d;
@@ -1,6 +1,8 @@
1
- import i from 'bn.js';
2
- import * as n from 'enc-utils';
1
+ import o from 'bn.js';
2
+ import * as i from 'enc-utils';
3
+ import { toUtf8Bytes } from 'ethers';
4
+ import { track } from '@imtbl/metrics';
3
5
 
4
- function a(e){return n.addHexPrefix(n.padLeft(e.r.toString(16),64)+n.padLeft(e.s.toString(16),64)+n.padLeft(e.recoveryParam?.toString(16)||"",2))}function u(e){let t=new i(e,16).cmp(new i(27))!==-1?new i(e,16).sub(new i(27)).toNumber():new i(e,16).toNumber();return e.trim()?t:void 0}function g(e,t=64){let r=n.removeHexPrefix(e);return {r:new i(r.substring(0,t),"hex"),s:new i(r.substring(t,t*2),"hex"),recoveryParam:u(r.substring(t*2,t*2+2))}}async function s(e,t){let r=g(await t.signMessage(e));return a(r)}async function c(e){let t=Math.floor(Date.now()/1e3).toString(),r=await s(t,e);return {timestamp:t,signature:r}}async function m(e,t){let r=await t.getAddress(),o=await s(e,t);return {message:e,ethAddress:r,ethSignature:o}}function f(e){switch(e.type){case"ERC721":return {type:"ERC721",data:{token_id:e.tokenId,token_address:e.tokenAddress}};case"ERC20":return {type:"ERC20",data:{token_address:e.tokenAddress}};case"ETH":default:return {type:"ETH",data:{decimals:18}}}}
6
+ function l(e){return i.addHexPrefix(i.padLeft(e.r.toString(16),64)+i.padLeft(e.s.toString(16),64)+i.padLeft(e.recoveryParam?.toString(16)||"",2))}function p(e){let t=new o(e,16).cmp(new o(27))!==-1?new o(e,16).sub(new o(27)).toNumber():new o(e,16).toNumber();return e.trim()?t:void 0}function S(e,t=64){let r=i.removeHexPrefix(e);return {r:new o(r.substring(0,t),"hex"),s:new o(r.substring(t,t*2),"hex"),recoveryParam:p(r.substring(t*2,t*2+2))}}async function d(e,t){let r=await t.getAddress();track("xProvider","log",{address:r,param:"signRaw.payload",val:e}),track("xProvider","log",{address:r,param:"signRaw.toUtf8Bytes",val:toUtf8Bytes(e).toString()}),track("xProvider","log",{address:r,param:"signRaw.payload.normalize() === payload",val:e===e.normalize()});let u=new TextEncoder().encode(e),a=new TextDecoder("utf-8").decode(u),c=Buffer.from(e,"utf8"),g=new TextDecoder("utf-8").decode(c);track("xProvider","log",{address:r,param:"signRaw.message === payload.normalize()",val:a===e.normalize()}),track("xProvider","log",{address:r,param:"signRaw.message2 === payload.normalize()",val:g===e.normalize()}),track("xProvider","log",{address:r,param:"signRaw.message",val:a,bytes:toUtf8Bytes(a).toString()}),track("xProvider","log",{address:r,param:"signRaw.message2",val:g,bytes:toUtf8Bytes(g).toString()}),track("xProvider","log",{address:r,param:"signRaw.toUtf8Bytes === toUtf8Bytes(message)",val:toUtf8Bytes(e).toString()===toUtf8Bytes(a).toString()}),track("xProvider","log",{address:r,param:"signRaw.toUtf8Bytes === toUtf8Bytes(message2)",val:toUtf8Bytes(e).toString()===toUtf8Bytes(g).toString()});let f=S(await t.signMessage(toUtf8Bytes(a)));return l(f)}async function y(e){let t=Math.floor(Date.now()/1e3).toString(),r=await d(t,e);return {timestamp:t,signature:r}}async function b(e,t){let r=await t.getAddress(),m=await d(e,t);return {message:e,ethAddress:r,ethSignature:m}}function R(e){switch(e.type){case"ERC721":return {type:"ERC721",data:{token_id:e.tokenId,token_address:e.tokenAddress}};case"ERC20":return {type:"ERC20",data:{token_address:e.tokenAddress}};case"ETH":default:return {type:"ETH",data:{decimals:18}}}}
5
7
 
6
- export { f as convertToSignableToken, c as generateIMXAuthorisationHeaders, m as signMessage, s as signRaw };
8
+ export { R as convertToSignableToken, y as generateIMXAuthorisationHeaders, b as signMessage, d as signRaw };
@@ -1,11 +1,12 @@
1
1
  import { Signer } from 'ethers';
2
- export declare function signRaw(payload: string, signer: Signer): Promise<string>;
2
+ import { Signer as EthersV5Signer } from 'ethers-v5';
3
+ export declare function signRaw(payload: string, signer: Signer | EthersV5Signer): Promise<string>;
3
4
  type IMXAuthorisationHeaders = {
4
5
  timestamp: string;
5
6
  signature: string;
6
7
  };
7
- export declare function generateIMXAuthorisationHeaders(ethSigner: Signer): Promise<IMXAuthorisationHeaders>;
8
- export declare function signMessage(message: string, signer: Signer): Promise<{
8
+ export declare function generateIMXAuthorisationHeaders(ethSigner: Signer | EthersV5Signer): Promise<IMXAuthorisationHeaders>;
9
+ export declare function signMessage(message: string, signer: Signer | EthersV5Signer): Promise<{
9
10
  message: string;
10
11
  ethAddress: string;
11
12
  ethSignature: string;
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@imtbl/toolkit",
3
3
  "description": "Provider package for Immutable SDK",
4
- "version": "2.1.16-alpha.4",
4
+ "version": "2.1.17-alpha.0",
5
5
  "author": "Immutable",
6
6
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
7
7
  "dependencies": {
8
- "@imtbl/x-client": "2.1.16-alpha.4",
8
+ "@imtbl/x-client": "2.1.17-alpha.0",
9
9
  "@magic-ext/oidc": "12.0.5",
10
+ "@imtbl/metrics": "2.1.17-alpha.0",
10
11
  "@metamask/detect-provider": "^2.0.0",
11
12
  "axios": "^1.6.5",
12
13
  "bn.js": "^5.2.1",
13
14
  "enc-utils": "^3.0.0",
14
15
  "ethers": "^6.13.4",
15
16
  "magic-sdk": "^29.0.5",
17
+ "ethers-v5": "npm:ethers@5.7.2",
16
18
  "oidc-client-ts": "2.4.0"
17
19
  },
18
20
  "devDependencies": {