@latticexyz/protocol-parser 2.0.0-next.8 → 2.0.0-skystrife-playtest-3e6ab07b

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.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{isDynamicAbiType as C}from"@latticexyz/schema-type";function xe(e){let t=[],c=[];for(let i of e)C(i)?c.push(i):t.push(i);return{staticFields:t,dynamicFields:c}}import{hexToString as _,sliceHex as q}from"viem";import{assertExhaustive as G}from"@latticexyz/common/utils";import{arrayAbiTypeToStaticAbiType as J,staticAbiTypeToByteLength as Q}from"@latticexyz/schema-type";import{getAddress as z,hexToBigInt as R,hexToBool as U}from"viem";import{assertExhaustive as M}from"@latticexyz/common/utils";import{staticAbiTypeToByteLength as N,staticAbiTypeToDefaultValue as W}from"@latticexyz/schema-type";import{MUDError as d}from"@latticexyz/common/errors";import{staticAbiTypeToByteLength as $}from"@latticexyz/schema-type";var l=class extends d{name="InvalidHexValueError";constructor(t){super(`Hex value "${t}" is an odd length (${t.length-2}). It must be an even length.`)}},b=class extends d{name="InvalidHexLengthForSchemaError";constructor(t){super(`Hex value "${t}" has length of ${t.length-2}, but expected length of 64 for a schema.`)}},S=class extends d{name="InvalidHexLengthForPackedCounterError";constructor(t){super(`Hex value "${t}" has length of ${t.length-2}, but expected length of 64 for a packed counter.`)}},g=class extends d{name="InvalidHexLengthForStaticFieldError";constructor(t,c){super(`Hex value "${c}" has length of ${c.length-2}, but expected length of ${$[t]*2} for ${t} type.`)}},A=class extends d{name="InvalidHexLengthForArrayFieldError";constructor(t,c){super(`Hex value "${c}" has length of ${c.length-2}, but expected a multiple of ${$[t]*2} for ${t}[] type.`)}},v=class extends d{name="SchemaStaticLengthMismatchError";constructor(t,c,i){super(`Schema "${t}" static data length (${c}) did not match the summed length of all static fields (${i}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`)}},H=class extends d{name="PackedCounterLengthMismatchError";constructor(t,c,i){super(`PackedCounter "${t}" total bytes length (${c}) did not match the summed length of all field byte lengths (${i}).`)}};function p(e,t){if(t.length>3&&t.length%2!==0)throw new l(t);if((t.length-2)/2!==N[e])throw new g(e,t);switch(e){case"uint8":case"uint16":case"uint24":case"uint32":case"uint40":case"uint48":case"uint56":case"uint64":case"uint72":case"uint80":case"uint88":case"uint96":case"uint104":case"uint112":case"uint120":case"uint128":case"uint136":case"uint144":case"uint152":case"uint160":case"uint168":case"uint176":case"uint184":case"uint192":case"uint200":case"uint208":case"uint216":case"uint224":case"uint232":case"uint240":case"uint248":case"uint256":case"int8":case"int16":case"int24":case"int32":case"int40":case"int48":case"int56":case"int64":case"int72":case"int80":case"int88":case"int96":case"int104":case"int112":case"int120":case"int128":case"int136":case"int144":case"int152":case"int160":case"int168":case"int176":case"int184":case"int192":case"int200":case"int208":case"int216":case"int224":case"int232":case"int240":case"int248":case"int256":{let i=R(t,{signed:e.startsWith("int")}),a=typeof W[e];if(a==="number")return Number(i);if(a==="bigint")return i;throw new Error(`Unexpected default value type (${a}) for ABI type (${e})`)}case"bytes1":case"bytes2":case"bytes3":case"bytes4":case"bytes5":case"bytes6":case"bytes7":case"bytes8":case"bytes9":case"bytes10":case"bytes11":case"bytes12":case"bytes13":case"bytes14":case"bytes15":case"bytes16":case"bytes17":case"bytes18":case"bytes19":case"bytes20":case"bytes21":case"bytes22":case"bytes23":case"bytes24":case"bytes25":case"bytes26":case"bytes27":case"bytes28":case"bytes29":case"bytes30":case"bytes31":case"bytes32":return t;case"bool":return U(t);case"address":return z(t)}return M(e,`Unsupported static ABI type: ${e}`)}function h(e,t){if(e==="bytes")return t;if(e==="string")return _(t);if(t.length>3&&t.length%2!==0)throw new l(t);let c=(t.length-2)/2;switch(e){case"uint8[]":case"uint16[]":case"uint24[]":case"uint32[]":case"uint40[]":case"uint48[]":case"uint56[]":case"uint64[]":case"uint72[]":case"uint80[]":case"uint88[]":case"uint96[]":case"uint104[]":case"uint112[]":case"uint120[]":case"uint128[]":case"uint136[]":case"uint144[]":case"uint152[]":case"uint160[]":case"uint168[]":case"uint176[]":case"uint184[]":case"uint192[]":case"uint200[]":case"uint208[]":case"uint216[]":case"uint224[]":case"uint232[]":case"uint240[]":case"uint248[]":case"uint256[]":case"int8[]":case"int16[]":case"int24[]":case"int32[]":case"int40[]":case"int48[]":case"int56[]":case"int64[]":case"int72[]":case"int80[]":case"int88[]":case"int96[]":case"int104[]":case"int112[]":case"int120[]":case"int128[]":case"int136[]":case"int144[]":case"int152[]":case"int160[]":case"int168[]":case"int176[]":case"int184[]":case"int192[]":case"int200[]":case"int208[]":case"int216[]":case"int224[]":case"int232[]":case"int240[]":case"int248[]":case"int256[]":case"bytes1[]":case"bytes2[]":case"bytes3[]":case"bytes4[]":case"bytes5[]":case"bytes6[]":case"bytes7[]":case"bytes8[]":case"bytes9[]":case"bytes10[]":case"bytes11[]":case"bytes12[]":case"bytes13[]":case"bytes14[]":case"bytes15[]":case"bytes16[]":case"bytes17[]":case"bytes18[]":case"bytes19[]":case"bytes20[]":case"bytes21[]":case"bytes22[]":case"bytes23[]":case"bytes24[]":case"bytes25[]":case"bytes26[]":case"bytes27[]":case"bytes28[]":case"bytes29[]":case"bytes30[]":case"bytes31[]":case"bytes32[]":case"bool[]":case"address[]":{let i=J(e),a=Q[i];if(c%a!==0)throw new A(i,t);return new Array(c/a).fill(void 0).map((r,s)=>{let o=q(t,s*a,(s+1)*a);return p(i,o)})}}return G(e,`Unsupported dynamic ABI type: ${e}`)}import{isDynamicAbiType as X}from"@latticexyz/schema-type";function _e(e,t){return X(e)?h(e,t):p(e,t)}import{decodeAbiParameters as Y}from"viem";function B(e,t){if(e.staticFields.length!==t.length)throw new Error(`key tuple length ${t.length} does not match key schema length ${e.staticFields.length}`);return t.map((c,i)=>Y([{type:e.staticFields[i]}],c)[0])}function Ye(e,t){let c=B({staticFields:Object.values(e),dynamicFields:[]},t);return Object.fromEntries(Object.keys(e).map((i,a)=>[i,c[a]]))}import{staticAbiTypeToByteLength as ee,dynamicAbiTypeToDefaultValue as te}from"@latticexyz/schema-type";function u(e,t,c){return`0x${e.replace(/^0x/,"").slice(t*2,c!=null?c*2:void 0).padEnd(((c??t)-t)*2,"0")}`}function w(e){if(e.length!==66)throw new S(e);let t=p("uint56",u(e,32-7,32)),c=h("uint40[]",u(e,0,32-7)),i=Object.freeze([...c].reverse()),a=BigInt(i.reduce((n,r)=>n+r,0));if(a!==t)throw new H(e,t,a);return{totalByteLength:t,fieldByteLengths:i}}import{staticAbiTypeToByteLength as Z}from"@latticexyz/schema-type";function F(e){return e.reduce((t,c)=>t+Z[c],0)}function j(e,t){let c=[],i=0;e.staticFields.forEach(r=>{let s=ee[r],o=p(r,u(t,i,i+s));i+=s,c.push(o)});let a=F(e.staticFields),n=i;if(n!==a&&console.warn("Decoded static data length does not match schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?",{expectedLength:a,actualLength:n,bytesOffset:i}),e.dynamicFields.length>0){let r=w(u(t,i,i+32));i+=32,e.dynamicFields.forEach((o,D)=>{let m=r.fieldByteLengths[D];if(m>0){let y=h(o,u(t,i,i+m));i+=m,c.push(y)}else c.push(te[o])});let s=i-32-n;BigInt(s)!==r.totalByteLength&&console.warn("Decoded dynamic data length does not match data layout's expected data length. Data may get corrupted. Did the data layout change?",{expectedLength:r.totalByteLength,actualLength:s,bytesOffset:i})}return c}import{isStaticAbiType as ie,isDynamicAbiType as ce}from"@latticexyz/schema-type";function St(e,t){let c=Object.values(e).filter(ie),i=Object.values(e).filter(ce),a=j({staticFields:c,dynamicFields:i},t);return Object.fromEntries(Object.keys(e).map((n,r)=>[n,a[r]]))}import{arrayAbiTypeToStaticAbiType as ae,isArrayAbiType as se}from"@latticexyz/schema-type";import{encodePacked as E}from"viem";function f(e,t){if(se(e)&&Array.isArray(t)){let c=ae(e);return t.length===0?"0x":E(t.map(()=>c),t)}return E([e],[t])}import{isStaticAbiType as ne}from"@latticexyz/schema-type";import{encodeAbiParameters as re}from"viem";function I(e,t){return t.map((c,i)=>re([{type:e.staticFields[i]}],[c]))}function jt(e,t){let c=Object.values(e).filter(ne);return I({staticFields:c,dynamicFields:[]},Object.values(t))}function O(e,t){let c=t.slice(0,e.staticFields.length),i=t.slice(e.staticFields.length),a=c.map((m,y)=>f(e.staticFields[y],m).replace(/^0x/,"")).join("");if(e.dynamicFields.length===0)return`0x${a}`;let n=i.map((m,y)=>f(e.dynamicFields[y],m).replace(/^0x/,"")),r=n.map(m=>m.length/2).reverse(),s=r.reduce((m,y)=>m+BigInt(y),0n),o=n.join(""),D=`${r.map(m=>f("uint40",m).replace(/^0x/,"")).join("")}${f("uint56",s).replace(/^0x/,"")}`.padStart(64,"0");return`0x${a}${D}${o}`}import{isStaticAbiType as oe,isDynamicAbiType as me}from"@latticexyz/schema-type";function kt(e,t){let c=Object.values(e).filter(oe),i=Object.values(e).filter(me);return O({staticFields:c,dynamicFields:i},Object.values(t))}import{schemaAbiTypes as V,staticAbiTypeToByteLength as pe}from"@latticexyz/schema-type";import{hexToNumber as T,sliceHex as x}from"viem";function L(e){if(e.length!==66)throw new b(e);let t=T(x(e,0,2)),c=T(x(e,2,3)),i=T(x(e,3,4)),a=[],n=[];for(let s=4;s<4+c;s++){let o=T(x(e,s,s+1));a.push(V[o])}for(let s=4+c;s<4+c+i;s++){let o=T(x(e,s,s+1));n.push(V[o])}let r=a.reduce((s,o)=>s+pe[o],0);if(r!==t)throw console.warn(`Schema "${e}" static data length (${t}) did not match the summed length of all static fields (${r}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`),new v(e,t,r);return{staticFields:a,dynamicFields:n}}import{sliceHex as K}from"viem";function Qt(e){let t=L(K(e,0,32));return{keySchema:L(K(e,32,64)),valueSchema:t}}import{isStaticAbiType as ye}from"@latticexyz/schema-type";import{schemaAbiTypes as k}from"@latticexyz/schema-type";function P(e){let t=e.staticFields.map(i=>k.indexOf(i)),c=e.dynamicFields.map(i=>k.indexOf(i));return`0x${[F(e.staticFields).toString(16).padStart(4,"0"),e.staticFields.length.toString(16).padStart(2,"0"),e.dynamicFields.length.toString(16).padStart(2,"0"),...t.map(i=>i.toString(16).padStart(2,"0")),...c.map(i=>i.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}function ci(e){return P({staticFields:Object.values(e).filter(ye),dynamicFields:[]})}function si(e,t){return t<e.staticFields.length?e.staticFields[t]:e.dynamicFields[t-e.staticFields.length]}import{isDynamicAbiType as de,isStaticAbiType as ue}from"@latticexyz/schema-type";function mi(e){return P({staticFields:Object.values(e).filter(ue),dynamicFields:Object.values(e).filter(de)})}export{l as InvalidHexLengthError,A as InvalidHexLengthForArrayFieldError,S as InvalidHexLengthForPackedCounterError,b as InvalidHexLengthForSchemaError,g as InvalidHexLengthForStaticFieldError,H as PackedCounterLengthMismatchError,v as SchemaStaticLengthMismatchError,xe as abiTypesToSchema,h as decodeDynamicField,_e as decodeField,Ye as decodeKey,B as decodeKeyTuple,j as decodeRecord,p as decodeStaticField,St as decodeValue,f as encodeField,jt as encodeKey,I as encodeKeyTuple,O as encodeRecord,kt as encodeValue,w as hexToPackedCounter,L as hexToSchema,Qt as hexToTableSchema,ci as keySchemaToHex,u as readHex,si as schemaIndexToAbiType,P as schemaToHex,F as staticDataLength,mi as valueSchemaToHex};
1
+ import{isDynamicAbiType as C}from"@latticexyz/schema-type";function ge(e){let t=[],i=[];for(let c of e)C(c)?i.push(c):t.push(c);return{staticFields:t,dynamicFields:i}}import{hexToString as _,sliceHex as q}from"viem";import{assertExhaustive as G}from"@latticexyz/common/utils";import{arrayAbiTypeToStaticAbiType as J,staticAbiTypeToByteLength as Q}from"@latticexyz/schema-type";import{getAddress as z,hexToBigInt as R,hexToBool as U}from"viem";import{assertExhaustive as M}from"@latticexyz/common/utils";import{staticAbiTypeToByteLength as N,staticAbiTypeToDefaultValue as W}from"@latticexyz/schema-type";import{MUDError as d}from"@latticexyz/common/errors";import{staticAbiTypeToByteLength as $}from"@latticexyz/schema-type";var l=class extends d{name="InvalidHexValueError";constructor(t){super(`Hex value "${t}" is an odd length (${t.length-2}). It must be an even length.`)}},b=class extends d{name="InvalidHexLengthForSchemaError";constructor(t){super(`Hex value "${t}" has length of ${t.length-2}, but expected length of 64 for a schema.`)}},S=class extends d{name="InvalidHexLengthForPackedCounterError";constructor(t){super(`Hex value "${t}" has length of ${t.length-2}, but expected length of 64 for a packed counter.`)}},g=class extends d{name="InvalidHexLengthForStaticFieldError";constructor(t,i){super(`Hex value "${i}" has length of ${i.length-2}, but expected length of ${$[t]*2} for ${t} type.`)}},A=class extends d{name="InvalidHexLengthForArrayFieldError";constructor(t,i){super(`Hex value "${i}" has length of ${i.length-2}, but expected a multiple of ${$[t]*2} for ${t}[] type.`)}},v=class extends d{name="SchemaStaticLengthMismatchError";constructor(t,i,c){super(`Schema "${t}" static data length (${i}) did not match the summed length of all static fields (${c}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`)}},H=class extends d{name="PackedCounterLengthMismatchError";constructor(t,i,c){super(`PackedCounter "${t}" total bytes length (${i}) did not match the summed length of all field byte lengths (${c}).`)}};function p(e,t){if(t.length>3&&t.length%2!==0)throw new l(t);if((t.length-2)/2!==N[e])throw new g(e,t);switch(e){case"uint8":case"uint16":case"uint24":case"uint32":case"uint40":case"uint48":case"uint56":case"uint64":case"uint72":case"uint80":case"uint88":case"uint96":case"uint104":case"uint112":case"uint120":case"uint128":case"uint136":case"uint144":case"uint152":case"uint160":case"uint168":case"uint176":case"uint184":case"uint192":case"uint200":case"uint208":case"uint216":case"uint224":case"uint232":case"uint240":case"uint248":case"uint256":case"int8":case"int16":case"int24":case"int32":case"int40":case"int48":case"int56":case"int64":case"int72":case"int80":case"int88":case"int96":case"int104":case"int112":case"int120":case"int128":case"int136":case"int144":case"int152":case"int160":case"int168":case"int176":case"int184":case"int192":case"int200":case"int208":case"int216":case"int224":case"int232":case"int240":case"int248":case"int256":{let c=R(t,{signed:e.startsWith("int")}),a=typeof W[e];if(a==="number")return Number(c);if(a==="bigint")return c;throw new Error(`Unexpected default value type (${a}) for ABI type (${e})`)}case"bytes1":case"bytes2":case"bytes3":case"bytes4":case"bytes5":case"bytes6":case"bytes7":case"bytes8":case"bytes9":case"bytes10":case"bytes11":case"bytes12":case"bytes13":case"bytes14":case"bytes15":case"bytes16":case"bytes17":case"bytes18":case"bytes19":case"bytes20":case"bytes21":case"bytes22":case"bytes23":case"bytes24":case"bytes25":case"bytes26":case"bytes27":case"bytes28":case"bytes29":case"bytes30":case"bytes31":case"bytes32":return t;case"bool":return U(t);case"address":return z(t)}return M(e,`Unsupported static ABI type: ${e}`)}function h(e,t){if(e==="bytes")return t;if(e==="string")return _(t);if(t.length>3&&t.length%2!==0)throw new l(t);let i=(t.length-2)/2;switch(e){case"uint8[]":case"uint16[]":case"uint24[]":case"uint32[]":case"uint40[]":case"uint48[]":case"uint56[]":case"uint64[]":case"uint72[]":case"uint80[]":case"uint88[]":case"uint96[]":case"uint104[]":case"uint112[]":case"uint120[]":case"uint128[]":case"uint136[]":case"uint144[]":case"uint152[]":case"uint160[]":case"uint168[]":case"uint176[]":case"uint184[]":case"uint192[]":case"uint200[]":case"uint208[]":case"uint216[]":case"uint224[]":case"uint232[]":case"uint240[]":case"uint248[]":case"uint256[]":case"int8[]":case"int16[]":case"int24[]":case"int32[]":case"int40[]":case"int48[]":case"int56[]":case"int64[]":case"int72[]":case"int80[]":case"int88[]":case"int96[]":case"int104[]":case"int112[]":case"int120[]":case"int128[]":case"int136[]":case"int144[]":case"int152[]":case"int160[]":case"int168[]":case"int176[]":case"int184[]":case"int192[]":case"int200[]":case"int208[]":case"int216[]":case"int224[]":case"int232[]":case"int240[]":case"int248[]":case"int256[]":case"bytes1[]":case"bytes2[]":case"bytes3[]":case"bytes4[]":case"bytes5[]":case"bytes6[]":case"bytes7[]":case"bytes8[]":case"bytes9[]":case"bytes10[]":case"bytes11[]":case"bytes12[]":case"bytes13[]":case"bytes14[]":case"bytes15[]":case"bytes16[]":case"bytes17[]":case"bytes18[]":case"bytes19[]":case"bytes20[]":case"bytes21[]":case"bytes22[]":case"bytes23[]":case"bytes24[]":case"bytes25[]":case"bytes26[]":case"bytes27[]":case"bytes28[]":case"bytes29[]":case"bytes30[]":case"bytes31[]":case"bytes32[]":case"bool[]":case"address[]":{let c=J(e),a=Q[c];if(i%a!==0)throw new A(c,t);return new Array(i/a).fill(void 0).map((n,s)=>{let o=q(t,s*a,(s+1)*a);return p(c,o)})}}return G(e,`Unsupported dynamic ABI type: ${e}`)}import{isDynamicAbiType as X}from"@latticexyz/schema-type";function Je(e,t){return X(e)?h(e,t):p(e,t)}import{decodeAbiParameters as Y}from"viem";function B(e,t){if(e.staticFields.length!==t.length)throw new Error(`key tuple length ${t.length} does not match key schema length ${e.staticFields.length}`);return t.map((i,c)=>Y([{type:e.staticFields[c]}],i)[0])}function tt(e,t){let i=B({staticFields:Object.values(e),dynamicFields:[]},t);return Object.fromEntries(Object.keys(e).map((c,a)=>[c,i[a]]))}import{staticAbiTypeToByteLength as ee,dynamicAbiTypeToDefaultValue as te}from"@latticexyz/schema-type";function u(e,t,i){return`0x${e.replace(/^0x/,"").slice(t*2,i!=null?i*2:void 0).padEnd(((i??t)-t)*2,"0")}`}function w(e){if(e.length!==66)throw new S(e);let t=p("uint56",u(e,32-7,32)),i=h("uint40[]",u(e,0,32-7)),c=Object.freeze([...i].reverse()),a=BigInt(c.reduce((r,n)=>r+n,0));if(a!==t)throw new H(e,t,a);return{totalByteLength:t,fieldByteLengths:c}}import{staticAbiTypeToByteLength as Z}from"@latticexyz/schema-type";function F(e){return e.reduce((t,i)=>t+Z[i],0)}function j(e,t){let i=[],c=0;e.staticFields.forEach(n=>{let s=ee[n],o=p(n,u(t,c,c+s));c+=s,i.push(o)});let a=F(e.staticFields),r=c;if(r!==a&&console.warn("Decoded static data length does not match schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?",{expectedLength:a,actualLength:r,bytesOffset:c}),e.dynamicFields.length>0){let n=w(u(t,c,c+32));c+=32,e.dynamicFields.forEach((o,L)=>{let m=n.fieldByteLengths[L];if(m>0){let y=h(o,u(t,c,c+m));c+=m,i.push(y)}else i.push(te[o])});let s=c-32-r;BigInt(s)!==n.totalByteLength&&console.warn("Decoded dynamic data length does not match data layout's expected data length. Data may get corrupted. Did the data layout change?",{expectedLength:n.totalByteLength,actualLength:s,bytesOffset:c})}return i}import{isStaticAbiType as ie,isDynamicAbiType as ce}from"@latticexyz/schema-type";function vt(e,t){let i=Object.values(e).filter(ie),c=Object.values(e).filter(ce),a=j({staticFields:i,dynamicFields:c},t);return Object.fromEntries(Object.keys(e).map((r,n)=>[r,a[n]]))}import{arrayAbiTypeToStaticAbiType as ae,isArrayAbiType as se}from"@latticexyz/schema-type";import{encodePacked as E}from"viem";function f(e,t){if(se(e)&&Array.isArray(t)){let i=ae(e);return t.length===0?"0x":E(t.map(()=>i),t)}return E([e],[t])}import{isStaticAbiType as ne}from"@latticexyz/schema-type";import{encodeAbiParameters as re}from"viem";function O(e,t){return t.map((i,c)=>re([{type:e.staticFields[c]}],[i]))}function It(e,t){let i=Object.values(e).filter(ne);return O({staticFields:i,dynamicFields:[]},Object.values(t))}function I(e,t){let i=t.slice(0,e.staticFields.length),c=t.slice(e.staticFields.length),a=i.map((m,y)=>f(e.staticFields[y],m).replace(/^0x/,"")).join("");if(e.dynamicFields.length===0)return`0x${a}`;let r=c.map((m,y)=>f(e.dynamicFields[y],m).replace(/^0x/,"")),n=r.map(m=>m.length/2).reverse(),s=n.reduce((m,y)=>m+BigInt(y),0n),o=r.join(""),L=`${n.map(m=>f("uint40",m).replace(/^0x/,"")).join("")}${f("uint56",s).replace(/^0x/,"")}`.padStart(64,"0");return`0x${a}${L}${o}`}import{isStaticAbiType as oe,isDynamicAbiType as me}from"@latticexyz/schema-type";function Rt(e,t){let i=Object.values(e).filter(oe),c=Object.values(e).filter(me);return I({staticFields:i,dynamicFields:c},Object.values(t))}function Mt(e){return`0x${[e.staticFieldLengths.reduce((i,c)=>i+c,0).toString(16).padStart(4,"0"),e.staticFieldLengths.length.toString(16).padStart(2,"0"),e.numDynamicFields.toString(16).padStart(2,"0"),...e.staticFieldLengths.map(i=>i.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}import{schemaAbiTypes as V,staticAbiTypeToByteLength as pe}from"@latticexyz/schema-type";import{hexToNumber as T,sliceHex as x}from"viem";function D(e){if(e.length!==66)throw new b(e);let t=T(x(e,0,2)),i=T(x(e,2,3)),c=T(x(e,3,4)),a=[],r=[];for(let s=4;s<4+i;s++){let o=T(x(e,s,s+1));a.push(V[o])}for(let s=4+i;s<4+i+c;s++){let o=T(x(e,s,s+1));r.push(V[o])}let n=a.reduce((s,o)=>s+pe[o],0);if(n!==t)throw console.warn(`Schema "${e}" static data length (${t}) did not match the summed length of all static fields (${n}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`),new v(e,t,n);return{staticFields:a,dynamicFields:r}}import{sliceHex as K}from"viem";function ti(e){let t=D(K(e,0,32));return{keySchema:D(K(e,32,64)),valueSchema:t}}import{isStaticAbiType as ye}from"@latticexyz/schema-type";import{schemaAbiTypes as k}from"@latticexyz/schema-type";function P(e){let t=e.staticFields.map(c=>k.indexOf(c)),i=e.dynamicFields.map(c=>k.indexOf(c));return`0x${[F(e.staticFields).toString(16).padStart(4,"0"),e.staticFields.length.toString(16).padStart(2,"0"),e.dynamicFields.length.toString(16).padStart(2,"0"),...t.map(c=>c.toString(16).padStart(2,"0")),...i.map(c=>c.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}function oi(e){return P({staticFields:Object.values(e).filter(ye),dynamicFields:[]})}function pi(e,t){return t<e.staticFields.length?e.staticFields[t]:e.dynamicFields[t-e.staticFields.length]}import{isDynamicAbiType as de,isStaticAbiType as ue,staticAbiTypeToByteLength as le}from"@latticexyz/schema-type";function ui(e){let t=Object.values(e).filter(ue),i=Object.values(e).filter(de),c=t.map(r=>le[r]);return`0x${[c.reduce((r,n)=>r+n,0).toString(16).padStart(4,"0"),t.length.toString(16).padStart(2,"0"),i.length.toString(16).padStart(2,"0"),...c.map(r=>r.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}import{isDynamicAbiType as he,isStaticAbiType as fe}from"@latticexyz/schema-type";function Ti(e){return P({staticFields:Object.values(e).filter(fe),dynamicFields:Object.values(e).filter(he)})}export{l as InvalidHexLengthError,A as InvalidHexLengthForArrayFieldError,S as InvalidHexLengthForPackedCounterError,b as InvalidHexLengthForSchemaError,g as InvalidHexLengthForStaticFieldError,H as PackedCounterLengthMismatchError,v as SchemaStaticLengthMismatchError,ge as abiTypesToSchema,h as decodeDynamicField,Je as decodeField,tt as decodeKey,B as decodeKeyTuple,j as decodeRecord,p as decodeStaticField,vt as decodeValue,f as encodeField,It as encodeKey,O as encodeKeyTuple,I as encodeRecord,Rt as encodeValue,Mt as fieldLayoutToHex,w as hexToPackedCounter,D as hexToSchema,ti as hexToTableSchema,oi as keySchemaToHex,u as readHex,pi as schemaIndexToAbiType,P as schemaToHex,F as staticDataLength,ui as valueSchemaToFieldLayoutHex,Ti as valueSchemaToHex};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/abiTypesToSchema.ts","../src/decodeDynamicField.ts","../src/decodeStaticField.ts","../src/errors.ts","../src/decodeField.ts","../src/decodeKeyTuple.ts","../src/decodeKey.ts","../src/decodeRecord.ts","../src/readHex.ts","../src/hexToPackedCounter.ts","../src/staticDataLength.ts","../src/decodeValue.ts","../src/encodeField.ts","../src/encodeKey.ts","../src/encodeKeyTuple.ts","../src/encodeRecord.ts","../src/encodeValue.ts","../src/hexToSchema.ts","../src/hexToTableSchema.ts","../src/keySchemaToHex.ts","../src/schemaToHex.ts","../src/schemaIndexToAbiType.ts","../src/valueSchemaToHex.ts"],"sourcesContent":["import { DynamicAbiType, SchemaAbiType, StaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\n\nexport function abiTypesToSchema(abiTypes: SchemaAbiType[]): Schema {\n const staticFields: StaticAbiType[] = [];\n const dynamicFields: DynamicAbiType[] = [];\n for (const abiType of abiTypes) {\n if (isDynamicAbiType(abiType)) dynamicFields.push(abiType);\n else staticFields.push(abiType);\n }\n return { staticFields, dynamicFields };\n}\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { assertExhaustive } from \"@latticexyz/common/utils\";\nimport {\n DynamicAbiType,\n DynamicAbiTypeToPrimitiveType,\n arrayAbiTypeToStaticAbiType,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { InvalidHexLengthError, InvalidHexLengthForArrayFieldError } from \"./errors\";\n\n// TODO: require size/length for dynamic fields, because hex might be longer (sometimes we just move the length pointer of arrays without updating the value)\n// this means the error should probably change from \"invalid length\" to \"too short\", which viem has that we could reuse?\n\nexport function decodeDynamicField<\n TAbiType extends DynamicAbiType,\n TPrimitiveType extends DynamicAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n if (abiType === \"bytes\") {\n return data as TPrimitiveType;\n }\n if (abiType === \"string\") {\n return hexToString(data) as TPrimitiveType;\n }\n\n if (data.length > 3 && data.length % 2 !== 0) {\n throw new InvalidHexLengthError(data);\n }\n\n const dataSize = (data.length - 2) / 2;\n\n switch (abiType) {\n case \"uint8[]\":\n case \"uint16[]\":\n case \"uint24[]\":\n case \"uint32[]\":\n case \"uint40[]\":\n case \"uint48[]\":\n case \"uint56[]\":\n case \"uint64[]\":\n case \"uint72[]\":\n case \"uint80[]\":\n case \"uint88[]\":\n case \"uint96[]\":\n case \"uint104[]\":\n case \"uint112[]\":\n case \"uint120[]\":\n case \"uint128[]\":\n case \"uint136[]\":\n case \"uint144[]\":\n case \"uint152[]\":\n case \"uint160[]\":\n case \"uint168[]\":\n case \"uint176[]\":\n case \"uint184[]\":\n case \"uint192[]\":\n case \"uint200[]\":\n case \"uint208[]\":\n case \"uint216[]\":\n case \"uint224[]\":\n case \"uint232[]\":\n case \"uint240[]\":\n case \"uint248[]\":\n case \"uint256[]\":\n case \"int8[]\":\n case \"int16[]\":\n case \"int24[]\":\n case \"int32[]\":\n case \"int40[]\":\n case \"int48[]\":\n case \"int56[]\":\n case \"int64[]\":\n case \"int72[]\":\n case \"int80[]\":\n case \"int88[]\":\n case \"int96[]\":\n case \"int104[]\":\n case \"int112[]\":\n case \"int120[]\":\n case \"int128[]\":\n case \"int136[]\":\n case \"int144[]\":\n case \"int152[]\":\n case \"int160[]\":\n case \"int168[]\":\n case \"int176[]\":\n case \"int184[]\":\n case \"int192[]\":\n case \"int200[]\":\n case \"int208[]\":\n case \"int216[]\":\n case \"int224[]\":\n case \"int232[]\":\n case \"int240[]\":\n case \"int248[]\":\n case \"int256[]\":\n case \"bytes1[]\":\n case \"bytes2[]\":\n case \"bytes3[]\":\n case \"bytes4[]\":\n case \"bytes5[]\":\n case \"bytes6[]\":\n case \"bytes7[]\":\n case \"bytes8[]\":\n case \"bytes9[]\":\n case \"bytes10[]\":\n case \"bytes11[]\":\n case \"bytes12[]\":\n case \"bytes13[]\":\n case \"bytes14[]\":\n case \"bytes15[]\":\n case \"bytes16[]\":\n case \"bytes17[]\":\n case \"bytes18[]\":\n case \"bytes19[]\":\n case \"bytes20[]\":\n case \"bytes21[]\":\n case \"bytes22[]\":\n case \"bytes23[]\":\n case \"bytes24[]\":\n case \"bytes25[]\":\n case \"bytes26[]\":\n case \"bytes27[]\":\n case \"bytes28[]\":\n case \"bytes29[]\":\n case \"bytes30[]\":\n case \"bytes31[]\":\n case \"bytes32[]\":\n case \"bool[]\":\n case \"address[]\": {\n const staticAbiType = arrayAbiTypeToStaticAbiType(abiType);\n const itemByteLength = staticAbiTypeToByteLength[staticAbiType];\n if (dataSize % itemByteLength !== 0) {\n throw new InvalidHexLengthForArrayFieldError(staticAbiType, data);\n }\n const items = new Array(dataSize / itemByteLength).fill(undefined).map((_, i) => {\n const itemData = sliceHex(data, i * itemByteLength, (i + 1) * itemByteLength);\n return decodeStaticField(staticAbiType, itemData);\n });\n return items as TPrimitiveType;\n }\n }\n\n return assertExhaustive(abiType, `Unsupported dynamic ABI type: ${abiType}`);\n}\n","import { Hex, getAddress, hexToBigInt, hexToBool } from \"viem\";\nimport { assertExhaustive } from \"@latticexyz/common/utils\";\nimport {\n StaticAbiType,\n StaticAbiTypeToPrimitiveType,\n staticAbiTypeToByteLength,\n staticAbiTypeToDefaultValue,\n} from \"@latticexyz/schema-type\";\nimport { InvalidHexLengthError, InvalidHexLengthForStaticFieldError } from \"./errors\";\n\nexport function decodeStaticField<\n TAbiType extends StaticAbiType,\n TPrimitiveType extends StaticAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n if (data.length > 3 && data.length % 2 !== 0) {\n throw new InvalidHexLengthError(data);\n }\n\n const dataSize = (data.length - 2) / 2;\n if (dataSize !== staticAbiTypeToByteLength[abiType]) {\n throw new InvalidHexLengthForStaticFieldError(abiType, data);\n }\n\n switch (abiType) {\n case \"uint8\":\n case \"uint16\":\n case \"uint24\":\n case \"uint32\":\n case \"uint40\":\n case \"uint48\":\n case \"uint56\":\n case \"uint64\":\n case \"uint72\":\n case \"uint80\":\n case \"uint88\":\n case \"uint96\":\n case \"uint104\":\n case \"uint112\":\n case \"uint120\":\n case \"uint128\":\n case \"uint136\":\n case \"uint144\":\n case \"uint152\":\n case \"uint160\":\n case \"uint168\":\n case \"uint176\":\n case \"uint184\":\n case \"uint192\":\n case \"uint200\":\n case \"uint208\":\n case \"uint216\":\n case \"uint224\":\n case \"uint232\":\n case \"uint240\":\n case \"uint248\":\n case \"uint256\":\n case \"int8\":\n case \"int16\":\n case \"int24\":\n case \"int32\":\n case \"int40\":\n case \"int48\":\n case \"int56\":\n case \"int64\":\n case \"int72\":\n case \"int80\":\n case \"int88\":\n case \"int96\":\n case \"int104\":\n case \"int112\":\n case \"int120\":\n case \"int128\":\n case \"int136\":\n case \"int144\":\n case \"int152\":\n case \"int160\":\n case \"int168\":\n case \"int176\":\n case \"int184\":\n case \"int192\":\n case \"int200\":\n case \"int208\":\n case \"int216\":\n case \"int224\":\n case \"int232\":\n case \"int240\":\n case \"int248\":\n case \"int256\": {\n const value = hexToBigInt(data, { signed: abiType.startsWith(\"int\") });\n const defaultValueType = typeof staticAbiTypeToDefaultValue[abiType];\n if (defaultValueType === \"number\") {\n return Number(value) as TPrimitiveType;\n }\n if (defaultValueType === \"bigint\") {\n return value as TPrimitiveType;\n }\n throw new Error(`Unexpected default value type (${defaultValueType}) for ABI type (${abiType})`);\n }\n\n case \"bytes1\":\n case \"bytes2\":\n case \"bytes3\":\n case \"bytes4\":\n case \"bytes5\":\n case \"bytes6\":\n case \"bytes7\":\n case \"bytes8\":\n case \"bytes9\":\n case \"bytes10\":\n case \"bytes11\":\n case \"bytes12\":\n case \"bytes13\":\n case \"bytes14\":\n case \"bytes15\":\n case \"bytes16\":\n case \"bytes17\":\n case \"bytes18\":\n case \"bytes19\":\n case \"bytes20\":\n case \"bytes21\":\n case \"bytes22\":\n case \"bytes23\":\n case \"bytes24\":\n case \"bytes25\":\n case \"bytes26\":\n case \"bytes27\":\n case \"bytes28\":\n case \"bytes29\":\n case \"bytes30\":\n case \"bytes31\":\n case \"bytes32\": {\n return data as TPrimitiveType;\n }\n\n case \"bool\": {\n return hexToBool(data) as TPrimitiveType;\n }\n\n case \"address\": {\n return getAddress(data) as TPrimitiveType;\n }\n }\n\n return assertExhaustive(abiType, `Unsupported static ABI type: ${abiType}`);\n}\n","import { Hex } from \"viem\";\nimport { MUDError } from \"@latticexyz/common/errors\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\n\nexport class InvalidHexLengthError extends MUDError {\n override name = \"InvalidHexValueError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" is an odd length (${value.length - 2}). It must be an even length.`);\n }\n}\n\nexport class InvalidHexLengthForSchemaError extends MUDError {\n override name = \"InvalidHexLengthForSchemaError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for a schema.`);\n }\n}\n\nexport class InvalidHexLengthForPackedCounterError extends MUDError {\n override name = \"InvalidHexLengthForPackedCounterError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for a packed counter.`);\n }\n}\n\nexport class InvalidHexLengthForStaticFieldError extends MUDError {\n override name = \"InvalidHexLengthForStaticFieldError\";\n constructor(abiType: StaticAbiType, value: Hex) {\n super(\n `Hex value \"${value}\" has length of ${value.length - 2}, but expected length of ${\n staticAbiTypeToByteLength[abiType] * 2\n } for ${abiType} type.`\n );\n }\n}\n\nexport class InvalidHexLengthForArrayFieldError extends MUDError {\n override name = \"InvalidHexLengthForArrayFieldError\";\n constructor(abiType: StaticAbiType, value: Hex) {\n super(\n `Hex value \"${value}\" has length of ${value.length - 2}, but expected a multiple of ${\n staticAbiTypeToByteLength[abiType] * 2\n } for ${abiType}[] type.`\n );\n }\n}\n\nexport class SchemaStaticLengthMismatchError extends MUDError {\n override name = \"SchemaStaticLengthMismatchError\";\n constructor(schemaData: Hex, definedLength: number, summedLength: number) {\n super(\n `Schema \"${schemaData}\" static data length (${definedLength}) did not match the summed length of all static fields (${summedLength}). Is \\`staticAbiTypeToByteLength\\` up to date with Solidity schema types?`\n );\n }\n}\n\nexport class PackedCounterLengthMismatchError extends MUDError {\n override name = \"PackedCounterLengthMismatchError\";\n constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) {\n super(\n `PackedCounter \"${packedCounterData}\" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`\n );\n }\n}\n","import { Hex } from \"viem\";\nimport { SchemaAbiType, SchemaAbiTypeToPrimitiveType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { decodeStaticField } from \"./decodeStaticField\";\n\nexport function decodeField<\n TAbiType extends SchemaAbiType,\n TPrimitiveType extends SchemaAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n return (\n isDynamicAbiType(abiType) ? decodeDynamicField(abiType, data) : decodeStaticField(abiType, data)\n ) as TPrimitiveType;\n}\n","import { Hex, decodeAbiParameters } from \"viem\";\nimport { StaticPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\n\n// key tuples are encoded in the same way as abi.encode, so we can decode them with viem\n\n/** @deprecated use `decodeKey` instead */\nexport function decodeKeyTuple(keySchema: Schema, keyTuple: readonly Hex[]): StaticPrimitiveType[] {\n if (keySchema.staticFields.length !== keyTuple.length) {\n throw new Error(\n `key tuple length ${keyTuple.length} does not match key schema length ${keySchema.staticFields.length}`\n );\n }\n return keyTuple.map(\n (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType\n );\n}\n","import { Hex } from \"viem\";\nimport { SchemaToPrimitives, KeySchema } from \"./common\";\nimport { decodeKeyTuple } from \"./decodeKeyTuple\";\n\nexport function decodeKey<TSchema extends KeySchema>(\n keySchema: TSchema,\n data: readonly Hex[]\n): SchemaToPrimitives<TSchema> {\n // TODO: refactor and move all decodeKeyTuple logic into this method so we can delete decodeKeyTuple\n const keyValues = decodeKeyTuple({ staticFields: Object.values(keySchema), dynamicFields: [] }, data);\n\n return Object.fromEntries(\n Object.keys(keySchema).map((name, i) => [name, keyValues[i]])\n ) as SchemaToPrimitives<TSchema>;\n}\n","import {\n StaticPrimitiveType,\n DynamicPrimitiveType,\n staticAbiTypeToByteLength,\n dynamicAbiTypeToDefaultValue,\n} from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { hexToPackedCounter } from \"./hexToPackedCounter\";\nimport { staticDataLength } from \"./staticDataLength\";\nimport { readHex } from \"./readHex\";\n\n/** @deprecated use `decodeValue` instead */\nexport function decodeRecord(schema: Schema, data: Hex): readonly (StaticPrimitiveType | DynamicPrimitiveType)[] {\n const values: (StaticPrimitiveType | DynamicPrimitiveType)[] = [];\n\n let bytesOffset = 0;\n schema.staticFields.forEach((fieldType) => {\n const fieldByteLength = staticAbiTypeToByteLength[fieldType];\n const value = decodeStaticField(fieldType, readHex(data, bytesOffset, bytesOffset + fieldByteLength));\n bytesOffset += fieldByteLength;\n values.push(value);\n });\n\n // Warn user if static data length doesn't match the schema, because data corruption might be possible.\n const schemaStaticDataLength = staticDataLength(schema.staticFields);\n const actualStaticDataLength = bytesOffset;\n if (actualStaticDataLength !== schemaStaticDataLength) {\n console.warn(\n \"Decoded static data length does not match schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?\",\n {\n expectedLength: schemaStaticDataLength,\n actualLength: actualStaticDataLength,\n bytesOffset,\n }\n );\n }\n\n if (schema.dynamicFields.length > 0) {\n const dataLayout = hexToPackedCounter(readHex(data, bytesOffset, bytesOffset + 32));\n bytesOffset += 32;\n\n schema.dynamicFields.forEach((fieldType, i) => {\n const dataLength = dataLayout.fieldByteLengths[i];\n if (dataLength > 0) {\n const value = decodeDynamicField(fieldType, readHex(data, bytesOffset, bytesOffset + dataLength));\n bytesOffset += dataLength;\n values.push(value);\n } else {\n values.push(dynamicAbiTypeToDefaultValue[fieldType]);\n }\n });\n\n // Warn user if dynamic data length doesn't match the schema, because data corruption might be possible.\n const actualDynamicDataLength = bytesOffset - 32 - actualStaticDataLength;\n // TODO: refactor this so we don't break for bytes offsets >UINT40\n if (BigInt(actualDynamicDataLength) !== dataLayout.totalByteLength) {\n console.warn(\n \"Decoded dynamic data length does not match data layout's expected data length. Data may get corrupted. Did the data layout change?\",\n {\n expectedLength: dataLayout.totalByteLength,\n actualLength: actualDynamicDataLength,\n bytesOffset,\n }\n );\n }\n }\n\n return values;\n}\n","import { Hex } from \"viem\";\n\n/**\n * Get the hex value at start/end positions. This will always return a valid hex string.\n *\n * If `start` is out of range, this returns `\"0x\"`.\n *\n * If `end` is specified and out of range, the result is right zero-padded to the desired length (`end - start`).\n */\nexport function readHex(data: Hex, start: number, end?: number): Hex {\n return `0x${data\n .replace(/^0x/, \"\")\n .slice(start * 2, end != null ? end * 2 : undefined)\n .padEnd(((end ?? start) - start) * 2, \"0\")}`;\n}\n","import { Hex } from \"viem\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { InvalidHexLengthForPackedCounterError, PackedCounterLengthMismatchError } from \"./errors\";\nimport { readHex } from \"./readHex\";\n\n// Keep this logic in sync with PackedCounter.sol\n\n// - Last 7 bytes (uint56) are used for the total byte length of the dynamic data\n// - The next 5 byte (uint40) sections are used for the byte length of each field, indexed from right to left\n\n// We use byte lengths rather than item counts so that, on chain, we can slice without having to get the schema first (and thus the field lengths of each dynamic type)\n\nexport function hexToPackedCounter(data: Hex): {\n totalByteLength: bigint;\n fieldByteLengths: readonly number[];\n} {\n if (data.length !== 66) {\n throw new InvalidHexLengthForPackedCounterError(data);\n }\n\n const totalByteLength = decodeStaticField(\"uint56\", readHex(data, 32 - 7, 32));\n // TODO: use schema to make sure we only parse as many as we need (rather than zeroes at the end)?\n const reversedFieldByteLengths = decodeDynamicField(\"uint40[]\", readHex(data, 0, 32 - 7));\n // Reverse the lengths\n const fieldByteLengths = Object.freeze([...reversedFieldByteLengths].reverse());\n\n const summedLength = BigInt(fieldByteLengths.reduce((total, length) => total + length, 0));\n if (summedLength !== totalByteLength) {\n throw new PackedCounterLengthMismatchError(data, totalByteLength, summedLength);\n }\n\n return { totalByteLength, fieldByteLengths };\n}\n","import { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\n\nexport function staticDataLength(staticFields: readonly StaticAbiType[]): number {\n return staticFields.reduce((length, fieldType) => length + staticAbiTypeToByteLength[fieldType], 0);\n}\n","import { isStaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, ValueSchema } from \"./common\";\nimport { decodeRecord } from \"./decodeRecord\";\n\nexport function decodeValue<TSchema extends ValueSchema>(valueSchema: TSchema, data: Hex): SchemaToPrimitives<TSchema> {\n const staticFields = Object.values(valueSchema).filter(isStaticAbiType);\n const dynamicFields = Object.values(valueSchema).filter(isDynamicAbiType);\n\n // TODO: refactor and move all decodeRecord logic into this method so we can delete decodeRecord\n const valueTuple = decodeRecord({ staticFields, dynamicFields }, data);\n\n return Object.fromEntries(\n Object.keys(valueSchema).map((name, i) => [name, valueTuple[i]])\n ) as SchemaToPrimitives<TSchema>;\n}\n","import { SchemaAbiType, arrayAbiTypeToStaticAbiType, isArrayAbiType } from \"@latticexyz/schema-type\";\nimport { AbiParameterToPrimitiveType } from \"abitype\";\nimport { Hex, encodePacked } from \"viem\";\n\nexport function encodeField<TSchemaAbiType extends SchemaAbiType>(\n fieldType: TSchemaAbiType,\n value: AbiParameterToPrimitiveType<{ type: TSchemaAbiType }>\n): Hex {\n if (isArrayAbiType(fieldType) && Array.isArray(value)) {\n const staticFieldType = arrayAbiTypeToStaticAbiType(fieldType);\n // TODO: we can remove conditional once this is fixed: https://github.com/wagmi-dev/viem/pull/1147\n return value.length === 0\n ? \"0x\"\n : encodePacked(\n value.map(() => staticFieldType),\n value\n );\n }\n return encodePacked([fieldType], [value]);\n}\n","import { isStaticAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, KeySchema } from \"./common\";\nimport { encodeKeyTuple } from \"./encodeKeyTuple\";\n\nexport function encodeKey<TSchema extends KeySchema>(keySchema: TSchema, key: SchemaToPrimitives<TSchema>): Hex[] {\n const staticFields = Object.values(keySchema).filter(isStaticAbiType);\n // TODO: refactor and move all encodeKeyTuple logic into this method so we can delete encodeKeyTuple\n return encodeKeyTuple({ staticFields, dynamicFields: [] }, Object.values(key));\n}\n","import { StaticPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Hex, encodeAbiParameters } from \"viem\";\nimport { Schema } from \"./common\";\n\n/** @deprecated use `encodeKey` instead */\nexport function encodeKeyTuple(keySchema: Schema, keyTuple: StaticPrimitiveType[]): Hex[] {\n return keyTuple.map((key, index) => encodeAbiParameters([{ type: keySchema.staticFields[index] }], [key]));\n}\n","import { StaticPrimitiveType, DynamicPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { encodeField } from \"./encodeField\";\nimport { Schema } from \"./common\";\n\n/** @deprecated use `encodeValue` instead */\nexport function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[]): Hex {\n const staticValues = values.slice(0, schema.staticFields.length) as readonly StaticPrimitiveType[];\n const dynamicValues = values.slice(schema.staticFields.length) as readonly DynamicPrimitiveType[];\n\n const staticData = staticValues\n .map((value, i) => encodeField(schema.staticFields[i], value).replace(/^0x/, \"\"))\n .join(\"\");\n\n if (schema.dynamicFields.length === 0) return `0x${staticData}`;\n\n const dynamicDataItems = dynamicValues.map((value, i) =>\n encodeField(schema.dynamicFields[i], value).replace(/^0x/, \"\")\n );\n\n const dynamicFieldByteLengths = dynamicDataItems.map((value) => value.length / 2).reverse();\n const dynamicTotalByteLength = dynamicFieldByteLengths.reduce((total, length) => total + BigInt(length), 0n);\n\n const dynamicData = dynamicDataItems.join(\"\");\n\n const packedCounter = `${dynamicFieldByteLengths\n .map((length) => encodeField(\"uint40\", length).replace(/^0x/, \"\"))\n .join(\"\")}${encodeField(\"uint56\", dynamicTotalByteLength).replace(/^0x/, \"\")}`.padStart(64, \"0\");\n\n return `0x${staticData}${packedCounter}${dynamicData}`;\n}\n","import { isStaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, ValueSchema } from \"./common\";\nimport { encodeRecord } from \"./encodeRecord\";\n\nexport function encodeValue<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n value: SchemaToPrimitives<TSchema>\n): Hex {\n const staticFields = Object.values(valueSchema).filter(isStaticAbiType);\n const dynamicFields = Object.values(valueSchema).filter(isDynamicAbiType);\n\n // TODO: refactor and move all encodeRecord logic into this method so we can delete encodeRecord\n\n // This currently assumes fields/values are ordered by static, dynamic\n // TODO: make sure we preserve ordering based on schema definition\n return encodeRecord({ staticFields, dynamicFields }, Object.values(value));\n}\n","import { StaticAbiType, DynamicAbiType, schemaAbiTypes, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\nimport { Hex, hexToNumber, sliceHex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { InvalidHexLengthForSchemaError, SchemaStaticLengthMismatchError } from \"./errors\";\n\nexport function hexToSchema(data: Hex): Schema {\n if (data.length !== 66) {\n throw new InvalidHexLengthForSchemaError(data);\n }\n\n const staticDataLength = hexToNumber(sliceHex(data, 0, 2));\n const numStaticFields = hexToNumber(sliceHex(data, 2, 3));\n const numDynamicFields = hexToNumber(sliceHex(data, 3, 4));\n const staticFields: StaticAbiType[] = [];\n const dynamicFields: DynamicAbiType[] = [];\n\n for (let i = 4; i < 4 + numStaticFields; i++) {\n const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));\n staticFields.push(schemaAbiTypes[schemaTypeIndex] as StaticAbiType);\n }\n for (let i = 4 + numStaticFields; i < 4 + numStaticFields + numDynamicFields; i++) {\n const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));\n dynamicFields.push(schemaAbiTypes[schemaTypeIndex] as DynamicAbiType);\n }\n\n // validate static data length\n const actualStaticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);\n if (actualStaticDataLength !== staticDataLength) {\n console.warn(\n `Schema \"${data}\" static data length (${staticDataLength}) did not match the summed length of all static fields (${actualStaticDataLength}). Is \\`staticAbiTypeToByteLength\\` up to date with Solidity schema types?`\n );\n throw new SchemaStaticLengthMismatchError(data, staticDataLength, actualStaticDataLength);\n }\n\n return { staticFields, dynamicFields };\n}\n","import { Hex, sliceHex } from \"viem\";\nimport { TableSchema } from \"./common\";\nimport { hexToSchema } from \"./hexToSchema\";\n\nexport function hexToTableSchema(data: Hex): TableSchema {\n const valueSchema = hexToSchema(sliceHex(data, 0, 32));\n const keySchema = hexToSchema(sliceHex(data, 32, 64));\n return {\n keySchema,\n valueSchema,\n };\n}\n","import { isStaticAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { KeySchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function keySchemaToHex(schema: KeySchema): Hex {\n return schemaToHex({ staticFields: Object.values(schema).filter(isStaticAbiType), dynamicFields: [] });\n}\n","import { schemaAbiTypes } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { staticDataLength } from \"./staticDataLength\";\n\n/** @deprecated use `keySchemaToHex` or `valueSchemaToHex` instead */\nexport function schemaToHex(schema: Schema): Hex {\n const staticSchemaTypes = schema.staticFields.map((abiType) => schemaAbiTypes.indexOf(abiType));\n const dynamicSchemaTypes = schema.dynamicFields.map((abiType) => schemaAbiTypes.indexOf(abiType));\n return `0x${[\n staticDataLength(schema.staticFields).toString(16).padStart(4, \"0\"),\n schema.staticFields.length.toString(16).padStart(2, \"0\"),\n schema.dynamicFields.length.toString(16).padStart(2, \"0\"),\n ...staticSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ...dynamicSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ]\n .join(\"\")\n .padEnd(64, \"0\")}`;\n}\n","import { SchemaAbiType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\n\nexport function schemaIndexToAbiType(schema: Schema, schemaIndex: number): SchemaAbiType {\n if (schemaIndex < schema.staticFields.length) {\n return schema.staticFields[schemaIndex];\n }\n return schema.dynamicFields[schemaIndex - schema.staticFields.length];\n}\n","import { isDynamicAbiType, isStaticAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { ValueSchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function valueSchemaToHex(schema: ValueSchema): Hex {\n return schemaToHex({\n staticFields: Object.values(schema).filter(isStaticAbiType),\n dynamicFields: Object.values(schema).filter(isDynamicAbiType),\n });\n}\n"],"mappings":"AAAA,OAAuD,oBAAAA,MAAwB,0BAGxE,SAASC,GAAiBC,EAAmC,CAClE,IAAMC,EAAgC,CAAC,EACjCC,EAAkC,CAAC,EACzC,QAAWC,KAAWH,EAChBF,EAAiBK,CAAO,EAAGD,EAAc,KAAKC,CAAO,EACpDF,EAAa,KAAKE,CAAO,EAEhC,MAAO,CAAE,aAAAF,EAAc,cAAAC,CAAc,CACvC,CCXA,OAAc,eAAAE,EAAa,YAAAC,MAAgB,OAC3C,OAAS,oBAAAC,MAAwB,2BACjC,OAGE,+BAAAC,EACA,6BAAAC,MACK,0BCPP,OAAc,cAAAC,EAAY,eAAAC,EAAa,aAAAC,MAAiB,OACxD,OAAS,oBAAAC,MAAwB,2BACjC,OAGE,6BAAAC,EACA,+BAAAC,MACK,0BCNP,OAAS,YAAAC,MAAgB,4BACzB,OAAwB,6BAAAC,MAAiC,0BAElD,IAAMC,EAAN,cAAoCF,CAAS,CACzC,KAAO,uBAChB,YAAYG,EAAY,CACtB,MAAM,cAAcA,wBAA4BA,EAAM,OAAS,gCAAgC,CACjG,CACF,EAEaC,EAAN,cAA6CJ,CAAS,CAClD,KAAO,iCAChB,YAAYG,EAAY,CACtB,MAAM,cAAcA,oBAAwBA,EAAM,OAAS,4CAA4C,CACzG,CACF,EAEaE,EAAN,cAAoDL,CAAS,CACzD,KAAO,wCAChB,YAAYG,EAAY,CACtB,MAAM,cAAcA,oBAAwBA,EAAM,OAAS,oDAAoD,CACjH,CACF,EAEaG,EAAN,cAAkDN,CAAS,CACvD,KAAO,sCAChB,YAAYO,EAAwBJ,EAAY,CAC9C,MACE,cAAcA,oBAAwBA,EAAM,OAAS,6BACnDF,EAA0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E,OAAOG,EAAgB,CAC9D,CAAC,CACH","names":["isDynamicAbiType","abiTypesToSchema","abiTypes","staticFields","dynamicFields","abiType","hexToString","sliceHex","assertExhaustive","arrayAbiTypeToStaticAbiType","staticAbiTypeToByteLength","getAddress","hexToBigInt","hexToBool","assertExhaustive","staticAbiTypeToByteLength","staticAbiTypeToDefaultValue","MUDError","staticAbiTypeToByteLength","InvalidHexLengthError","value","InvalidHexLengthForSchemaError","InvalidHexLengthForPackedCounterError","InvalidHexLengthForStaticFieldError","abiType","InvalidHexLengthForArrayFieldError","SchemaStaticLengthMismatchError","schemaData","definedLength","summedLength","PackedCounterLengthMismatchError","packedCounterData","decodeStaticField","abiType","data","InvalidHexLengthError","staticAbiTypeToByteLength","InvalidHexLengthForStaticFieldError","value","hexToBigInt","defaultValueType","staticAbiTypeToDefaultValue","hexToBool","getAddress","assertExhaustive","decodeDynamicField","abiType","data","hexToString","InvalidHexLengthError","dataSize","staticAbiType","arrayAbiTypeToStaticAbiType","itemByteLength","staticAbiTypeToByteLength","InvalidHexLengthForArrayFieldError","_","i","itemData","sliceHex","decodeStaticField","assertExhaustive","isDynamicAbiType","decodeField","abiType","data","isDynamicAbiType","decodeDynamicField","decodeStaticField","decodeAbiParameters","decodeKeyTuple","keySchema","keyTuple","key","index","decodeKey","keySchema","data","keyValues","decodeKeyTuple","name","i","staticAbiTypeToByteLength","dynamicAbiTypeToDefaultValue","readHex","data","start","end","hexToPackedCounter","data","InvalidHexLengthForPackedCounterError","totalByteLength","decodeStaticField","readHex","reversedFieldByteLengths","decodeDynamicField","fieldByteLengths","summedLength","total","length","PackedCounterLengthMismatchError","staticAbiTypeToByteLength","staticDataLength","staticFields","length","fieldType","decodeRecord","schema","data","values","bytesOffset","fieldType","fieldByteLength","staticAbiTypeToByteLength","value","decodeStaticField","readHex","schemaStaticDataLength","staticDataLength","actualStaticDataLength","dataLayout","hexToPackedCounter","i","dataLength","decodeDynamicField","dynamicAbiTypeToDefaultValue","actualDynamicDataLength","isStaticAbiType","isDynamicAbiType","decodeValue","valueSchema","data","staticFields","isStaticAbiType","dynamicFields","isDynamicAbiType","valueTuple","decodeRecord","name","i","arrayAbiTypeToStaticAbiType","isArrayAbiType","encodePacked","encodeField","fieldType","value","staticFieldType","isStaticAbiType","encodeAbiParameters","encodeKeyTuple","keySchema","keyTuple","key","index","encodeKey","keySchema","key","staticFields","isStaticAbiType","encodeKeyTuple","encodeRecord","schema","values","staticValues","dynamicValues","staticData","value","i","encodeField","dynamicDataItems","dynamicFieldByteLengths","dynamicTotalByteLength","total","length","dynamicData","packedCounter","isStaticAbiType","isDynamicAbiType","encodeValue","valueSchema","value","staticFields","isStaticAbiType","dynamicFields","isDynamicAbiType","encodeRecord","schemaAbiTypes","staticAbiTypeToByteLength","hexToNumber","sliceHex","hexToSchema","data","InvalidHexLengthForSchemaError","staticDataLength","hexToNumber","sliceHex","numStaticFields","numDynamicFields","staticFields","dynamicFields","i","schemaTypeIndex","schemaAbiTypes","actualStaticDataLength","acc","fieldType","staticAbiTypeToByteLength","SchemaStaticLengthMismatchError","sliceHex","hexToTableSchema","data","valueSchema","hexToSchema","sliceHex","isStaticAbiType","schemaAbiTypes","schemaToHex","schema","staticSchemaTypes","abiType","schemaAbiTypes","dynamicSchemaTypes","staticDataLength","schemaType","keySchemaToHex","schema","schemaToHex","isStaticAbiType","schemaIndexToAbiType","schema","schemaIndex","isDynamicAbiType","isStaticAbiType","valueSchemaToHex","schema","schemaToHex","isStaticAbiType","isDynamicAbiType"]}
1
+ {"version":3,"sources":["../src/abiTypesToSchema.ts","../src/decodeDynamicField.ts","../src/decodeStaticField.ts","../src/errors.ts","../src/decodeField.ts","../src/decodeKeyTuple.ts","../src/decodeKey.ts","../src/decodeRecord.ts","../src/readHex.ts","../src/hexToPackedCounter.ts","../src/staticDataLength.ts","../src/decodeValue.ts","../src/encodeField.ts","../src/encodeKey.ts","../src/encodeKeyTuple.ts","../src/encodeRecord.ts","../src/encodeValue.ts","../src/fieldLayoutToHex.ts","../src/hexToSchema.ts","../src/hexToTableSchema.ts","../src/keySchemaToHex.ts","../src/schemaToHex.ts","../src/schemaIndexToAbiType.ts","../src/valueSchemaToFieldLayoutHex.ts","../src/valueSchemaToHex.ts"],"sourcesContent":["import { DynamicAbiType, SchemaAbiType, StaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\n\nexport function abiTypesToSchema(abiTypes: SchemaAbiType[]): Schema {\n const staticFields: StaticAbiType[] = [];\n const dynamicFields: DynamicAbiType[] = [];\n for (const abiType of abiTypes) {\n if (isDynamicAbiType(abiType)) dynamicFields.push(abiType);\n else staticFields.push(abiType);\n }\n return { staticFields, dynamicFields };\n}\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { assertExhaustive } from \"@latticexyz/common/utils\";\nimport {\n DynamicAbiType,\n DynamicAbiTypeToPrimitiveType,\n arrayAbiTypeToStaticAbiType,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { InvalidHexLengthError, InvalidHexLengthForArrayFieldError } from \"./errors\";\n\n// TODO: require size/length for dynamic fields, because hex might be longer (sometimes we just move the length pointer of arrays without updating the value)\n// this means the error should probably change from \"invalid length\" to \"too short\", which viem has that we could reuse?\n\nexport function decodeDynamicField<\n TAbiType extends DynamicAbiType,\n TPrimitiveType extends DynamicAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n if (abiType === \"bytes\") {\n return data as TPrimitiveType;\n }\n if (abiType === \"string\") {\n return hexToString(data) as TPrimitiveType;\n }\n\n if (data.length > 3 && data.length % 2 !== 0) {\n throw new InvalidHexLengthError(data);\n }\n\n const dataSize = (data.length - 2) / 2;\n\n switch (abiType) {\n case \"uint8[]\":\n case \"uint16[]\":\n case \"uint24[]\":\n case \"uint32[]\":\n case \"uint40[]\":\n case \"uint48[]\":\n case \"uint56[]\":\n case \"uint64[]\":\n case \"uint72[]\":\n case \"uint80[]\":\n case \"uint88[]\":\n case \"uint96[]\":\n case \"uint104[]\":\n case \"uint112[]\":\n case \"uint120[]\":\n case \"uint128[]\":\n case \"uint136[]\":\n case \"uint144[]\":\n case \"uint152[]\":\n case \"uint160[]\":\n case \"uint168[]\":\n case \"uint176[]\":\n case \"uint184[]\":\n case \"uint192[]\":\n case \"uint200[]\":\n case \"uint208[]\":\n case \"uint216[]\":\n case \"uint224[]\":\n case \"uint232[]\":\n case \"uint240[]\":\n case \"uint248[]\":\n case \"uint256[]\":\n case \"int8[]\":\n case \"int16[]\":\n case \"int24[]\":\n case \"int32[]\":\n case \"int40[]\":\n case \"int48[]\":\n case \"int56[]\":\n case \"int64[]\":\n case \"int72[]\":\n case \"int80[]\":\n case \"int88[]\":\n case \"int96[]\":\n case \"int104[]\":\n case \"int112[]\":\n case \"int120[]\":\n case \"int128[]\":\n case \"int136[]\":\n case \"int144[]\":\n case \"int152[]\":\n case \"int160[]\":\n case \"int168[]\":\n case \"int176[]\":\n case \"int184[]\":\n case \"int192[]\":\n case \"int200[]\":\n case \"int208[]\":\n case \"int216[]\":\n case \"int224[]\":\n case \"int232[]\":\n case \"int240[]\":\n case \"int248[]\":\n case \"int256[]\":\n case \"bytes1[]\":\n case \"bytes2[]\":\n case \"bytes3[]\":\n case \"bytes4[]\":\n case \"bytes5[]\":\n case \"bytes6[]\":\n case \"bytes7[]\":\n case \"bytes8[]\":\n case \"bytes9[]\":\n case \"bytes10[]\":\n case \"bytes11[]\":\n case \"bytes12[]\":\n case \"bytes13[]\":\n case \"bytes14[]\":\n case \"bytes15[]\":\n case \"bytes16[]\":\n case \"bytes17[]\":\n case \"bytes18[]\":\n case \"bytes19[]\":\n case \"bytes20[]\":\n case \"bytes21[]\":\n case \"bytes22[]\":\n case \"bytes23[]\":\n case \"bytes24[]\":\n case \"bytes25[]\":\n case \"bytes26[]\":\n case \"bytes27[]\":\n case \"bytes28[]\":\n case \"bytes29[]\":\n case \"bytes30[]\":\n case \"bytes31[]\":\n case \"bytes32[]\":\n case \"bool[]\":\n case \"address[]\": {\n const staticAbiType = arrayAbiTypeToStaticAbiType(abiType);\n const itemByteLength = staticAbiTypeToByteLength[staticAbiType];\n if (dataSize % itemByteLength !== 0) {\n throw new InvalidHexLengthForArrayFieldError(staticAbiType, data);\n }\n const items = new Array(dataSize / itemByteLength).fill(undefined).map((_, i) => {\n const itemData = sliceHex(data, i * itemByteLength, (i + 1) * itemByteLength);\n return decodeStaticField(staticAbiType, itemData);\n });\n return items as TPrimitiveType;\n }\n }\n\n return assertExhaustive(abiType, `Unsupported dynamic ABI type: ${abiType}`);\n}\n","import { Hex, getAddress, hexToBigInt, hexToBool } from \"viem\";\nimport { assertExhaustive } from \"@latticexyz/common/utils\";\nimport {\n StaticAbiType,\n StaticAbiTypeToPrimitiveType,\n staticAbiTypeToByteLength,\n staticAbiTypeToDefaultValue,\n} from \"@latticexyz/schema-type\";\nimport { InvalidHexLengthError, InvalidHexLengthForStaticFieldError } from \"./errors\";\n\nexport function decodeStaticField<\n TAbiType extends StaticAbiType,\n TPrimitiveType extends StaticAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n if (data.length > 3 && data.length % 2 !== 0) {\n throw new InvalidHexLengthError(data);\n }\n\n const dataSize = (data.length - 2) / 2;\n if (dataSize !== staticAbiTypeToByteLength[abiType]) {\n throw new InvalidHexLengthForStaticFieldError(abiType, data);\n }\n\n switch (abiType) {\n case \"uint8\":\n case \"uint16\":\n case \"uint24\":\n case \"uint32\":\n case \"uint40\":\n case \"uint48\":\n case \"uint56\":\n case \"uint64\":\n case \"uint72\":\n case \"uint80\":\n case \"uint88\":\n case \"uint96\":\n case \"uint104\":\n case \"uint112\":\n case \"uint120\":\n case \"uint128\":\n case \"uint136\":\n case \"uint144\":\n case \"uint152\":\n case \"uint160\":\n case \"uint168\":\n case \"uint176\":\n case \"uint184\":\n case \"uint192\":\n case \"uint200\":\n case \"uint208\":\n case \"uint216\":\n case \"uint224\":\n case \"uint232\":\n case \"uint240\":\n case \"uint248\":\n case \"uint256\":\n case \"int8\":\n case \"int16\":\n case \"int24\":\n case \"int32\":\n case \"int40\":\n case \"int48\":\n case \"int56\":\n case \"int64\":\n case \"int72\":\n case \"int80\":\n case \"int88\":\n case \"int96\":\n case \"int104\":\n case \"int112\":\n case \"int120\":\n case \"int128\":\n case \"int136\":\n case \"int144\":\n case \"int152\":\n case \"int160\":\n case \"int168\":\n case \"int176\":\n case \"int184\":\n case \"int192\":\n case \"int200\":\n case \"int208\":\n case \"int216\":\n case \"int224\":\n case \"int232\":\n case \"int240\":\n case \"int248\":\n case \"int256\": {\n const value = hexToBigInt(data, { signed: abiType.startsWith(\"int\") });\n const defaultValueType = typeof staticAbiTypeToDefaultValue[abiType];\n if (defaultValueType === \"number\") {\n return Number(value) as TPrimitiveType;\n }\n if (defaultValueType === \"bigint\") {\n return value as TPrimitiveType;\n }\n throw new Error(`Unexpected default value type (${defaultValueType}) for ABI type (${abiType})`);\n }\n\n case \"bytes1\":\n case \"bytes2\":\n case \"bytes3\":\n case \"bytes4\":\n case \"bytes5\":\n case \"bytes6\":\n case \"bytes7\":\n case \"bytes8\":\n case \"bytes9\":\n case \"bytes10\":\n case \"bytes11\":\n case \"bytes12\":\n case \"bytes13\":\n case \"bytes14\":\n case \"bytes15\":\n case \"bytes16\":\n case \"bytes17\":\n case \"bytes18\":\n case \"bytes19\":\n case \"bytes20\":\n case \"bytes21\":\n case \"bytes22\":\n case \"bytes23\":\n case \"bytes24\":\n case \"bytes25\":\n case \"bytes26\":\n case \"bytes27\":\n case \"bytes28\":\n case \"bytes29\":\n case \"bytes30\":\n case \"bytes31\":\n case \"bytes32\": {\n return data as TPrimitiveType;\n }\n\n case \"bool\": {\n return hexToBool(data) as TPrimitiveType;\n }\n\n case \"address\": {\n return getAddress(data) as TPrimitiveType;\n }\n }\n\n return assertExhaustive(abiType, `Unsupported static ABI type: ${abiType}`);\n}\n","import { Hex } from \"viem\";\nimport { MUDError } from \"@latticexyz/common/errors\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\n\nexport class InvalidHexLengthError extends MUDError {\n override name = \"InvalidHexValueError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" is an odd length (${value.length - 2}). It must be an even length.`);\n }\n}\n\nexport class InvalidHexLengthForSchemaError extends MUDError {\n override name = \"InvalidHexLengthForSchemaError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for a schema.`);\n }\n}\n\nexport class InvalidHexLengthForPackedCounterError extends MUDError {\n override name = \"InvalidHexLengthForPackedCounterError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for a packed counter.`);\n }\n}\n\nexport class InvalidHexLengthForStaticFieldError extends MUDError {\n override name = \"InvalidHexLengthForStaticFieldError\";\n constructor(abiType: StaticAbiType, value: Hex) {\n super(\n `Hex value \"${value}\" has length of ${value.length - 2}, but expected length of ${\n staticAbiTypeToByteLength[abiType] * 2\n } for ${abiType} type.`\n );\n }\n}\n\nexport class InvalidHexLengthForArrayFieldError extends MUDError {\n override name = \"InvalidHexLengthForArrayFieldError\";\n constructor(abiType: StaticAbiType, value: Hex) {\n super(\n `Hex value \"${value}\" has length of ${value.length - 2}, but expected a multiple of ${\n staticAbiTypeToByteLength[abiType] * 2\n } for ${abiType}[] type.`\n );\n }\n}\n\nexport class SchemaStaticLengthMismatchError extends MUDError {\n override name = \"SchemaStaticLengthMismatchError\";\n constructor(schemaData: Hex, definedLength: number, summedLength: number) {\n super(\n `Schema \"${schemaData}\" static data length (${definedLength}) did not match the summed length of all static fields (${summedLength}). Is \\`staticAbiTypeToByteLength\\` up to date with Solidity schema types?`\n );\n }\n}\n\nexport class PackedCounterLengthMismatchError extends MUDError {\n override name = \"PackedCounterLengthMismatchError\";\n constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) {\n super(\n `PackedCounter \"${packedCounterData}\" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`\n );\n }\n}\n","import { Hex } from \"viem\";\nimport { SchemaAbiType, SchemaAbiTypeToPrimitiveType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { decodeStaticField } from \"./decodeStaticField\";\n\nexport function decodeField<\n TAbiType extends SchemaAbiType,\n TPrimitiveType extends SchemaAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n return (\n isDynamicAbiType(abiType) ? decodeDynamicField(abiType, data) : decodeStaticField(abiType, data)\n ) as TPrimitiveType;\n}\n","import { Hex, decodeAbiParameters } from \"viem\";\nimport { StaticPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\n\n// key tuples are encoded in the same way as abi.encode, so we can decode them with viem\n\n/** @deprecated use `decodeKey` instead */\nexport function decodeKeyTuple(keySchema: Schema, keyTuple: readonly Hex[]): StaticPrimitiveType[] {\n if (keySchema.staticFields.length !== keyTuple.length) {\n throw new Error(\n `key tuple length ${keyTuple.length} does not match key schema length ${keySchema.staticFields.length}`\n );\n }\n return keyTuple.map(\n (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType\n );\n}\n","import { Hex } from \"viem\";\nimport { SchemaToPrimitives, KeySchema } from \"./common\";\nimport { decodeKeyTuple } from \"./decodeKeyTuple\";\n\nexport function decodeKey<TSchema extends KeySchema>(\n keySchema: TSchema,\n data: readonly Hex[]\n): SchemaToPrimitives<TSchema> {\n // TODO: refactor and move all decodeKeyTuple logic into this method so we can delete decodeKeyTuple\n const keyValues = decodeKeyTuple({ staticFields: Object.values(keySchema), dynamicFields: [] }, data);\n\n return Object.fromEntries(\n Object.keys(keySchema).map((name, i) => [name, keyValues[i]])\n ) as SchemaToPrimitives<TSchema>;\n}\n","import {\n StaticPrimitiveType,\n DynamicPrimitiveType,\n staticAbiTypeToByteLength,\n dynamicAbiTypeToDefaultValue,\n} from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { hexToPackedCounter } from \"./hexToPackedCounter\";\nimport { staticDataLength } from \"./staticDataLength\";\nimport { readHex } from \"./readHex\";\n\n/** @deprecated use `decodeValue` instead */\nexport function decodeRecord(schema: Schema, data: Hex): readonly (StaticPrimitiveType | DynamicPrimitiveType)[] {\n const values: (StaticPrimitiveType | DynamicPrimitiveType)[] = [];\n\n let bytesOffset = 0;\n schema.staticFields.forEach((fieldType) => {\n const fieldByteLength = staticAbiTypeToByteLength[fieldType];\n const value = decodeStaticField(fieldType, readHex(data, bytesOffset, bytesOffset + fieldByteLength));\n bytesOffset += fieldByteLength;\n values.push(value);\n });\n\n // Warn user if static data length doesn't match the schema, because data corruption might be possible.\n const schemaStaticDataLength = staticDataLength(schema.staticFields);\n const actualStaticDataLength = bytesOffset;\n if (actualStaticDataLength !== schemaStaticDataLength) {\n console.warn(\n \"Decoded static data length does not match schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?\",\n {\n expectedLength: schemaStaticDataLength,\n actualLength: actualStaticDataLength,\n bytesOffset,\n }\n );\n }\n\n if (schema.dynamicFields.length > 0) {\n const dataLayout = hexToPackedCounter(readHex(data, bytesOffset, bytesOffset + 32));\n bytesOffset += 32;\n\n schema.dynamicFields.forEach((fieldType, i) => {\n const dataLength = dataLayout.fieldByteLengths[i];\n if (dataLength > 0) {\n const value = decodeDynamicField(fieldType, readHex(data, bytesOffset, bytesOffset + dataLength));\n bytesOffset += dataLength;\n values.push(value);\n } else {\n values.push(dynamicAbiTypeToDefaultValue[fieldType]);\n }\n });\n\n // Warn user if dynamic data length doesn't match the schema, because data corruption might be possible.\n const actualDynamicDataLength = bytesOffset - 32 - actualStaticDataLength;\n // TODO: refactor this so we don't break for bytes offsets >UINT40\n if (BigInt(actualDynamicDataLength) !== dataLayout.totalByteLength) {\n console.warn(\n \"Decoded dynamic data length does not match data layout's expected data length. Data may get corrupted. Did the data layout change?\",\n {\n expectedLength: dataLayout.totalByteLength,\n actualLength: actualDynamicDataLength,\n bytesOffset,\n }\n );\n }\n }\n\n return values;\n}\n","import { Hex } from \"viem\";\n\n/**\n * Get the hex value at start/end positions. This will always return a valid hex string.\n *\n * If `start` is out of range, this returns `\"0x\"`.\n *\n * If `end` is specified and out of range, the result is right zero-padded to the desired length (`end - start`).\n */\nexport function readHex(data: Hex, start: number, end?: number): Hex {\n return `0x${data\n .replace(/^0x/, \"\")\n .slice(start * 2, end != null ? end * 2 : undefined)\n .padEnd(((end ?? start) - start) * 2, \"0\")}`;\n}\n","import { Hex } from \"viem\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { InvalidHexLengthForPackedCounterError, PackedCounterLengthMismatchError } from \"./errors\";\nimport { readHex } from \"./readHex\";\n\n// Keep this logic in sync with PackedCounter.sol\n\n// - Last 7 bytes (uint56) are used for the total byte length of the dynamic data\n// - The next 5 byte (uint40) sections are used for the byte length of each field, indexed from right to left\n\n// We use byte lengths rather than item counts so that, on chain, we can slice without having to get the schema first (and thus the field lengths of each dynamic type)\n\nexport function hexToPackedCounter(data: Hex): {\n totalByteLength: bigint;\n fieldByteLengths: readonly number[];\n} {\n if (data.length !== 66) {\n throw new InvalidHexLengthForPackedCounterError(data);\n }\n\n const totalByteLength = decodeStaticField(\"uint56\", readHex(data, 32 - 7, 32));\n // TODO: use schema to make sure we only parse as many as we need (rather than zeroes at the end)?\n const reversedFieldByteLengths = decodeDynamicField(\"uint40[]\", readHex(data, 0, 32 - 7));\n // Reverse the lengths\n const fieldByteLengths = Object.freeze([...reversedFieldByteLengths].reverse());\n\n const summedLength = BigInt(fieldByteLengths.reduce((total, length) => total + length, 0));\n if (summedLength !== totalByteLength) {\n throw new PackedCounterLengthMismatchError(data, totalByteLength, summedLength);\n }\n\n return { totalByteLength, fieldByteLengths };\n}\n","import { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\n\nexport function staticDataLength(staticFields: readonly StaticAbiType[]): number {\n return staticFields.reduce((length, fieldType) => length + staticAbiTypeToByteLength[fieldType], 0);\n}\n","import { isStaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, ValueSchema } from \"./common\";\nimport { decodeRecord } from \"./decodeRecord\";\n\nexport function decodeValue<TSchema extends ValueSchema>(valueSchema: TSchema, data: Hex): SchemaToPrimitives<TSchema> {\n const staticFields = Object.values(valueSchema).filter(isStaticAbiType);\n const dynamicFields = Object.values(valueSchema).filter(isDynamicAbiType);\n\n // TODO: refactor and move all decodeRecord logic into this method so we can delete decodeRecord\n const valueTuple = decodeRecord({ staticFields, dynamicFields }, data);\n\n return Object.fromEntries(\n Object.keys(valueSchema).map((name, i) => [name, valueTuple[i]])\n ) as SchemaToPrimitives<TSchema>;\n}\n","import { SchemaAbiType, arrayAbiTypeToStaticAbiType, isArrayAbiType } from \"@latticexyz/schema-type\";\nimport { AbiParameterToPrimitiveType } from \"abitype\";\nimport { Hex, encodePacked } from \"viem\";\n\nexport function encodeField<TSchemaAbiType extends SchemaAbiType>(\n fieldType: TSchemaAbiType,\n value: AbiParameterToPrimitiveType<{ type: TSchemaAbiType }>\n): Hex {\n if (isArrayAbiType(fieldType) && Array.isArray(value)) {\n const staticFieldType = arrayAbiTypeToStaticAbiType(fieldType);\n // TODO: we can remove conditional once this is fixed: https://github.com/wagmi-dev/viem/pull/1147\n return value.length === 0\n ? \"0x\"\n : encodePacked(\n value.map(() => staticFieldType),\n value\n );\n }\n return encodePacked([fieldType], [value]);\n}\n","import { isStaticAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, KeySchema } from \"./common\";\nimport { encodeKeyTuple } from \"./encodeKeyTuple\";\n\nexport function encodeKey<TSchema extends KeySchema>(keySchema: TSchema, key: SchemaToPrimitives<TSchema>): Hex[] {\n const staticFields = Object.values(keySchema).filter(isStaticAbiType);\n // TODO: refactor and move all encodeKeyTuple logic into this method so we can delete encodeKeyTuple\n return encodeKeyTuple({ staticFields, dynamicFields: [] }, Object.values(key));\n}\n","import { StaticPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Hex, encodeAbiParameters } from \"viem\";\nimport { Schema } from \"./common\";\n\n/** @deprecated use `encodeKey` instead */\nexport function encodeKeyTuple(keySchema: Schema, keyTuple: StaticPrimitiveType[]): Hex[] {\n return keyTuple.map((key, index) => encodeAbiParameters([{ type: keySchema.staticFields[index] }], [key]));\n}\n","import { StaticPrimitiveType, DynamicPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { encodeField } from \"./encodeField\";\nimport { Schema } from \"./common\";\n\n/** @deprecated use `encodeValue` instead */\nexport function encodeRecord(schema: Schema, values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[]): Hex {\n const staticValues = values.slice(0, schema.staticFields.length) as readonly StaticPrimitiveType[];\n const dynamicValues = values.slice(schema.staticFields.length) as readonly DynamicPrimitiveType[];\n\n const staticData = staticValues\n .map((value, i) => encodeField(schema.staticFields[i], value).replace(/^0x/, \"\"))\n .join(\"\");\n\n if (schema.dynamicFields.length === 0) return `0x${staticData}`;\n\n const dynamicDataItems = dynamicValues.map((value, i) =>\n encodeField(schema.dynamicFields[i], value).replace(/^0x/, \"\")\n );\n\n const dynamicFieldByteLengths = dynamicDataItems.map((value) => value.length / 2).reverse();\n const dynamicTotalByteLength = dynamicFieldByteLengths.reduce((total, length) => total + BigInt(length), 0n);\n\n const dynamicData = dynamicDataItems.join(\"\");\n\n const packedCounter = `${dynamicFieldByteLengths\n .map((length) => encodeField(\"uint40\", length).replace(/^0x/, \"\"))\n .join(\"\")}${encodeField(\"uint56\", dynamicTotalByteLength).replace(/^0x/, \"\")}`.padStart(64, \"0\");\n\n return `0x${staticData}${packedCounter}${dynamicData}`;\n}\n","import { isStaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, ValueSchema } from \"./common\";\nimport { encodeRecord } from \"./encodeRecord\";\n\nexport function encodeValue<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n value: SchemaToPrimitives<TSchema>\n): Hex {\n const staticFields = Object.values(valueSchema).filter(isStaticAbiType);\n const dynamicFields = Object.values(valueSchema).filter(isDynamicAbiType);\n\n // TODO: refactor and move all encodeRecord logic into this method so we can delete encodeRecord\n\n // This currently assumes fields/values are ordered by static, dynamic\n // TODO: make sure we preserve ordering based on schema definition\n return encodeRecord({ staticFields, dynamicFields }, Object.values(value));\n}\n","import { Hex } from \"viem\";\nimport { FieldLayout } from \"./common\";\n\n/** @deprecated use `valueSchemaToFieldLayoutHex` instead */\nexport function fieldLayoutToHex(fieldLayout: FieldLayout): Hex {\n const staticDataLength = fieldLayout.staticFieldLengths.reduce((totalLength, length) => totalLength + length, 0);\n return `0x${[\n staticDataLength.toString(16).padStart(4, \"0\"),\n fieldLayout.staticFieldLengths.length.toString(16).padStart(2, \"0\"),\n fieldLayout.numDynamicFields.toString(16).padStart(2, \"0\"),\n ...fieldLayout.staticFieldLengths.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ]\n .join(\"\")\n .padEnd(64, \"0\")}`;\n}\n","import { StaticAbiType, DynamicAbiType, schemaAbiTypes, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\nimport { Hex, hexToNumber, sliceHex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { InvalidHexLengthForSchemaError, SchemaStaticLengthMismatchError } from \"./errors\";\n\nexport function hexToSchema(data: Hex): Schema {\n if (data.length !== 66) {\n throw new InvalidHexLengthForSchemaError(data);\n }\n\n const staticDataLength = hexToNumber(sliceHex(data, 0, 2));\n const numStaticFields = hexToNumber(sliceHex(data, 2, 3));\n const numDynamicFields = hexToNumber(sliceHex(data, 3, 4));\n const staticFields: StaticAbiType[] = [];\n const dynamicFields: DynamicAbiType[] = [];\n\n for (let i = 4; i < 4 + numStaticFields; i++) {\n const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));\n staticFields.push(schemaAbiTypes[schemaTypeIndex] as StaticAbiType);\n }\n for (let i = 4 + numStaticFields; i < 4 + numStaticFields + numDynamicFields; i++) {\n const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));\n dynamicFields.push(schemaAbiTypes[schemaTypeIndex] as DynamicAbiType);\n }\n\n // validate static data length\n const actualStaticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);\n if (actualStaticDataLength !== staticDataLength) {\n console.warn(\n `Schema \"${data}\" static data length (${staticDataLength}) did not match the summed length of all static fields (${actualStaticDataLength}). Is \\`staticAbiTypeToByteLength\\` up to date with Solidity schema types?`\n );\n throw new SchemaStaticLengthMismatchError(data, staticDataLength, actualStaticDataLength);\n }\n\n return { staticFields, dynamicFields };\n}\n","import { Hex, sliceHex } from \"viem\";\nimport { TableSchema } from \"./common\";\nimport { hexToSchema } from \"./hexToSchema\";\n\nexport function hexToTableSchema(data: Hex): TableSchema {\n const valueSchema = hexToSchema(sliceHex(data, 0, 32));\n const keySchema = hexToSchema(sliceHex(data, 32, 64));\n return {\n keySchema,\n valueSchema,\n };\n}\n","import { isStaticAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { KeySchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function keySchemaToHex(schema: KeySchema): Hex {\n return schemaToHex({ staticFields: Object.values(schema).filter(isStaticAbiType), dynamicFields: [] });\n}\n","import { schemaAbiTypes } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { staticDataLength } from \"./staticDataLength\";\n\n/** @deprecated use `keySchemaToHex` or `valueSchemaToHex` instead */\nexport function schemaToHex(schema: Schema): Hex {\n const staticSchemaTypes = schema.staticFields.map((abiType) => schemaAbiTypes.indexOf(abiType));\n const dynamicSchemaTypes = schema.dynamicFields.map((abiType) => schemaAbiTypes.indexOf(abiType));\n return `0x${[\n staticDataLength(schema.staticFields).toString(16).padStart(4, \"0\"),\n schema.staticFields.length.toString(16).padStart(2, \"0\"),\n schema.dynamicFields.length.toString(16).padStart(2, \"0\"),\n ...staticSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ...dynamicSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ]\n .join(\"\")\n .padEnd(64, \"0\")}`;\n}\n","import { SchemaAbiType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\n\nexport function schemaIndexToAbiType(schema: Schema, schemaIndex: number): SchemaAbiType {\n if (schemaIndex < schema.staticFields.length) {\n return schema.staticFields[schemaIndex];\n }\n return schema.dynamicFields[schemaIndex - schema.staticFields.length];\n}\n","import { Hex } from \"viem\";\nimport { ValueSchema } from \"./common\";\nimport { isDynamicAbiType, isStaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\n\n// TODO: add tests once we have corresponding tests for FieldLayout.sol (bytes32 -> FieldLayout and vice versa)\nexport function valueSchemaToFieldLayoutHex(valueSchema: ValueSchema): Hex {\n const staticFields = Object.values(valueSchema).filter(isStaticAbiType);\n const dynamicFields = Object.values(valueSchema).filter(isDynamicAbiType);\n\n const staticFieldLengths = staticFields.map((fieldType) => staticAbiTypeToByteLength[fieldType]);\n const staticDataLength = staticFieldLengths.reduce((dataLength, fieldLength) => dataLength + fieldLength, 0);\n\n return `0x${[\n staticDataLength.toString(16).padStart(4, \"0\"),\n staticFields.length.toString(16).padStart(2, \"0\"),\n dynamicFields.length.toString(16).padStart(2, \"0\"),\n ...staticFieldLengths.map((fieldLength) => fieldLength.toString(16).padStart(2, \"0\")),\n ]\n .join(\"\")\n .padEnd(64, \"0\")}`;\n}\n","import { isDynamicAbiType, isStaticAbiType } from \"@latticexyz/schema-type\";\nimport { Hex } from \"viem\";\nimport { ValueSchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function valueSchemaToHex(schema: ValueSchema): Hex {\n return schemaToHex({\n staticFields: Object.values(schema).filter(isStaticAbiType),\n dynamicFields: Object.values(schema).filter(isDynamicAbiType),\n });\n}\n"],"mappings":"AAAA,OAAuD,oBAAAA,MAAwB,0BAGxE,SAASC,GAAiBC,EAAmC,CAClE,IAAMC,EAAgC,CAAC,EACjCC,EAAkC,CAAC,EACzC,QAAWC,KAAWH,EAChBF,EAAiBK,CAAO,EAAGD,EAAc,KAAKC,CAAO,EACpDF,EAAa,KAAKE,CAAO,EAEhC,MAAO,CAAE,aAAAF,EAAc,cAAAC,CAAc,CACvC,CCXA,OAAc,eAAAE,EAAa,YAAAC,MAAgB,OAC3C,OAAS,oBAAAC,MAAwB,2BACjC,OAGE,+BAAAC,EACA,6BAAAC,MACK,0BCPP,OAAc,cAAAC,EAAY,eAAAC,EAAa,aAAAC,MAAiB,OACxD,OAAS,oBAAAC,MAAwB,2BACjC,OAGE,6BAAAC,EACA,+BAAAC,MACK,0BCNP,OAAS,YAAAC,MAAgB,4BACzB,OAAwB,6BAAAC,MAAiC,0BAElD,IAAMC,EAAN,cAAoCF,CAAS,CACzC,KAAO,uBAChB,YAAYG,EAAY,CACtB,MAAM,cAAcA,wBAA4BA,EAAM,OAAS,gCAAgC,CACjG,CACF,EAEaC,EAAN,cAA6CJ,CAAS,CAClD,KAAO,iCAChB,YAAYG,EAAY,CACtB,MAAM,cAAcA,oBAAwBA,EAAM,OAAS,4CAA4C,CACzG,CACF,EAEaE,EAAN,cAAoDL,CAAS,CACzD,KAAO,wCAChB,YAAYG,EAAY,CACtB,MAAM,cAAcA,oBAAwBA,EAAM,OAAS,oDAAoD,CACjH,CACF,EAEaG,EAAN,cAAkDN,CAAS,CACvD,KAAO,sCAChB,YAAYO,EAAwBJ,EAAY,CAC9C,MACE,cAA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DbO,SAASC,GAAeC,EAAwB,CACrD,OAAOC,EAAY,CAAE,aAAc,OAAO,OAAOD,CAAM,EAAE,OAAOE,EAAe,EAAG,cAAe,CAAC,CAAE,CAAC,CACvG,CEJO,SAASC,GAAqBC,EAAgBC,EAAoC,CACvF,OAAIA,EAAcD,EAAO,aAAa,OAC7BA,EAAO,aAAaC,CAAW,EAEjCD,EAAO,cAAcC,EAAcD,EAAO,aAAa,MAAM,CACtE,CCNA,OAAS,oBAAAE,GAAkB,mBAAAC,GAAiB,6BAAAC,OAAiC,0BAGtE,SAASC,GAA4BC,EAA+B,CACzE,IAAMC,EAAe,OAAO,OAAOD,CAAW,EAAE,OAAOH,EAAe,EAChEK,EAAgB,OAAO,OAAOF,CAAW,EAAE,OAAOJ,EAAgB,EAElEO,EAAqBF,EAAa,IAAKG,GAAcN,GAA0BM,CAAS,CAAC,EAG/F,MAAO,KAAK,CAFaD,EAAmB,OAAO,CAACE,EAAYC,IAAgBD,EAAaC,EAAa,CAAC,EAGxF,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAC7CL,EAAa,OAAO,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAChDC,EAAc,OAAO,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EACjD,GAAGC,EAAmB,IAAKG,GAAgBA,EAAY,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CAAC,CACtF,EACG,KAAK,EAAE,EACP,OAAO,GAAI,GAAG,GACnB,CCpBA,OAAS,oBAAAC,GAAkB,mBAAAC,OAAuB,0BAK3C,SAASC,GAAiBC,EAA0B,CACzD,OAAOC,EAAY,CACjB,aAAc,OAAO,OAAOD,CAAM,EAAE,OAAOE,EAAe,EAC1D,cAAe,OAAO,OAAOF,CAAM,EAAE,OAAOG,EAAgB,CAC9D,CAAC,CACH","names":["isDynamicAbiType","abiTypesToSchema","abiTypes","staticFields","dynamicFields","abiType","hexToString","sliceHex","assertExhaustive","arrayAbiTypeToStaticAbiType","staticAbiTypeToByteLength","getAddress","hexToBigInt","hexToBool","assertExhaustive","staticAbiTypeToByteLength","staticAbiTypeToDefaultValue","MUDError","staticAbiTypeToByteLength","InvalidHexLengthError","value","InvalidHexLengthForSchemaError","InvalidHexLengthForPackedCounterError","InvalidHexLengthForStaticFieldError","abiType","InvalidHexLengthForArrayFieldError","SchemaStaticLengthMismatchError","schemaData","definedLength","summedLength","PackedCounterLengthMismatchError","packedCounterData","decodeStaticField","abiType","data","InvalidHexLengthError","staticAbiTypeToByteLength","InvalidHexLengthForStaticFieldError","value","hexToBigInt","defaultValueType","staticAbiTypeToDefaultValue","hexToBool","getAddress","assertExhaustive","decodeDynamicField","abiType","data","hexToString","InvalidHexLengthError","dataSize","staticAbiType","arrayAbiTypeToStaticAbiType","itemByteLength","staticAbiTypeToByteLength","InvalidHexLengthForArrayFieldError","_","i","itemData","sliceHex","decodeStaticField","assertExhaustive","isDynamicAbiType","decodeField","abiType","data","isDynamicAbiType","decodeDynamicField","decodeStaticField","decodeAbiParameters","decodeKeyTuple","keySchema","keyTuple","key","index","decodeKey","keySchema","data","keyValues","decodeKeyTuple","name","i","staticAbiTypeToByteLength","dynamicAbiTypeToDefaultValue","readHex","data","start","end","hexToPackedCounter","data","InvalidHexLengthForPackedCounterError","totalByteLength","decodeStaticField","readHex","reversedFieldByteLengths","decodeDynamicField","fieldByteLengths","summedLength","total","length","PackedCounterLengthMismatchError","staticAbiTypeToByteLength","staticDataLength","staticFields","length","fieldType","decodeRecord","schema","data","values","bytesOffset","fieldType","fieldByteLength","staticAbiTypeToByteLength","value","decodeStaticField","readHex","schemaStaticDataLength","staticDataLength","actualStaticDataLength","dataLayout","hexToPackedCounter","i","dataLength","decodeDynamicField","dynamicAbiTypeToDefaultValue","actualDynamicDataLength","isStaticAbiType","isDynamicAbiType","decodeValue","valueSchema","data","staticFields","isStaticAbiType","dynamicFields","isDynamicAbiType","valueTuple","decodeRecord","name","i","arrayAbiTypeToStaticAbiType","isArrayAbiType","encodePacked","encodeField","fieldType","value","staticFieldType","isStaticAbiType","encodeAbiParameters","encodeKeyTuple","keySchema","keyTuple","key","index","encodeKey","keySchema","key","staticFields","isStaticAbiType","encodeKeyTuple","encodeRecord","schema","values","staticValues","dynamicValues","staticData","value","i","encodeField","dynamicDataItems","dynamicFieldByteLengths","dynamicTotalByteLength","total","length","dynamicData","packedCounter","isStaticAbiType","isDynamicAbiType","encodeValue","valueSchema","value","staticFields","isStaticAbiType","dynamicFields","isDynamicAbiType","encodeRecord","fieldLayoutToHex","fieldLayout","totalLength","length","schemaType","schemaAbiTypes","staticAbiTypeToByteLength","hexToNumber","sliceHex","hexToSchema","data","InvalidHexLengthForSchemaError","staticDataLength","hexToNumber","sliceHex","numStaticFields","numDynamicFields","staticFields","dynamicFields","i","schemaTypeIndex","schemaAbiTypes","actualStaticDataLength","acc","fieldType","staticAbiTypeToByteLength","SchemaStaticLengthMismatchError","sliceHex","hexToTableSchema","data","valueSchema","hexToSchema","sliceHex","isStaticAbiType","schemaAbiTypes","schemaToHex","schema","staticSchemaTypes","abiType","schemaAbiTypes","dynamicSchemaTypes","staticDataLength","schemaType","keySchemaToHex","schema","schemaToHex","isStaticAbiType","schemaIndexToAbiType","schema","schemaIndex","isDynamicAbiType","isStaticAbiType","staticAbiTypeToByteLength","valueSchemaToFieldLayoutHex","valueSchema","staticFields","dynamicFields","staticFieldLengths","fieldType","dataLength","fieldLength","isDynamicAbiType","isStaticAbiType","valueSchemaToHex","schema","schemaToHex","isStaticAbiType","isDynamicAbiType"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/protocol-parser",
3
- "version": "2.0.0-next.8",
3
+ "version": "2.0.0-skystrife-playtest-3e6ab07b",
4
4
  "description": "Parser utilities for the MUD protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,8 +16,8 @@
16
16
  "dependencies": {
17
17
  "abitype": "0.9.3",
18
18
  "viem": "1.6.0",
19
- "@latticexyz/common": "2.0.0-next.8",
20
- "@latticexyz/schema-type": "2.0.0-next.8"
19
+ "@latticexyz/common": "2.0.0-skystrife-playtest-3e6ab07b",
20
+ "@latticexyz/schema-type": "2.0.0-skystrife-playtest-3e6ab07b"
21
21
  },
22
22
  "devDependencies": {
23
23
  "tsup": "^6.7.0",
package/src/common.ts CHANGED
@@ -12,6 +12,11 @@ export type TableSchema = {
12
12
  readonly valueSchema: Schema;
13
13
  };
14
14
 
15
+ export type FieldLayout = {
16
+ readonly staticFieldLengths: readonly number[];
17
+ readonly numDynamicFields: number;
18
+ };
19
+
15
20
  export type KeySchema = Record<string, StaticAbiType>;
16
21
  export type ValueSchema = Record<string, SchemaAbiType>;
17
22
 
@@ -0,0 +1,15 @@
1
+ import { Hex } from "viem";
2
+ import { FieldLayout } from "./common";
3
+
4
+ /** @deprecated use `valueSchemaToFieldLayoutHex` instead */
5
+ export function fieldLayoutToHex(fieldLayout: FieldLayout): Hex {
6
+ const staticDataLength = fieldLayout.staticFieldLengths.reduce((totalLength, length) => totalLength + length, 0);
7
+ return `0x${[
8
+ staticDataLength.toString(16).padStart(4, "0"),
9
+ fieldLayout.staticFieldLengths.length.toString(16).padStart(2, "0"),
10
+ fieldLayout.numDynamicFields.toString(16).padStart(2, "0"),
11
+ ...fieldLayout.staticFieldLengths.map((schemaType) => schemaType.toString(16).padStart(2, "0")),
12
+ ]
13
+ .join("")
14
+ .padEnd(64, "0")}`;
15
+ }
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./encodeKeyTuple";
13
13
  export * from "./encodeRecord";
14
14
  export * from "./encodeValue";
15
15
  export * from "./errors";
16
+ export * from "./fieldLayoutToHex";
16
17
  export * from "./hexToPackedCounter";
17
18
  export * from "./hexToSchema";
18
19
  export * from "./hexToTableSchema";
@@ -21,4 +22,5 @@ export * from "./readHex";
21
22
  export * from "./schemaIndexToAbiType";
22
23
  export * from "./schemaToHex";
23
24
  export * from "./staticDataLength";
25
+ export * from "./valueSchemaToFieldLayoutHex";
24
26
  export * from "./valueSchemaToHex";
@@ -0,0 +1,21 @@
1
+ import { Hex } from "viem";
2
+ import { ValueSchema } from "./common";
3
+ import { isDynamicAbiType, isStaticAbiType, staticAbiTypeToByteLength } from "@latticexyz/schema-type";
4
+
5
+ // TODO: add tests once we have corresponding tests for FieldLayout.sol (bytes32 -> FieldLayout and vice versa)
6
+ export function valueSchemaToFieldLayoutHex(valueSchema: ValueSchema): Hex {
7
+ const staticFields = Object.values(valueSchema).filter(isStaticAbiType);
8
+ const dynamicFields = Object.values(valueSchema).filter(isDynamicAbiType);
9
+
10
+ const staticFieldLengths = staticFields.map((fieldType) => staticAbiTypeToByteLength[fieldType]);
11
+ const staticDataLength = staticFieldLengths.reduce((dataLength, fieldLength) => dataLength + fieldLength, 0);
12
+
13
+ return `0x${[
14
+ staticDataLength.toString(16).padStart(4, "0"),
15
+ staticFields.length.toString(16).padStart(2, "0"),
16
+ dynamicFields.length.toString(16).padStart(2, "0"),
17
+ ...staticFieldLengths.map((fieldLength) => fieldLength.toString(16).padStart(2, "0")),
18
+ ]
19
+ .join("")
20
+ .padEnd(64, "0")}`;
21
+ }