@latticexyz/protocol-parser 2.2.16 → 2.2.17-03eae1330cef5cae129841958fb75541ef13fb43

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/internal.js CHANGED
@@ -1,2 +1,2 @@
1
- import{isDynamicAbiType as M}from"@latticexyz/schema-type/internal";function Oe(e){let t=[],i=[];for(let a of e)M(a)?i.push(a):t.push(a);return{staticFields:t,dynamicFields:i}}import{hexToString as Q,sliceHex as X}from"viem";import{assertExhaustive as Y}from"@latticexyz/common/utils";import{arrayToStaticAbiType as Z,staticAbiTypeToByteLength as ee}from"@latticexyz/schema-type/internal";import{getAddress as W,hexToBigInt as _,hexToBool as q}from"viem";import{assertExhaustive as C}from"@latticexyz/common/utils";import{staticAbiTypeToByteLength as G,staticAbiTypeToDefaultValue as J}from"@latticexyz/schema-type/internal";import{MUDError as h}from"@latticexyz/common/errors";import{staticAbiTypeToByteLength as V}from"@latticexyz/schema-type/internal";var u=class extends h{constructor(i){super(`Hex value "${i}" is an odd length (${i.length-2}). It must be an even length.`);this.name="InvalidHexValueError"}},S=class extends h{constructor(i){super(`Hex value "${i}" has length of ${i.length-2}, but expected length of 64 for a schema.`);this.name="InvalidHexLengthForSchemaError"}},g=class extends h{constructor(i){super(`Hex value "${i}" has length of ${i.length-2}, but expected length of 64 for encoded lengths.`);this.name="InvalidHexLengthForEncodedLengthsError"}},A=class extends h{constructor(i,a){super(`Hex value "${a}" has length of ${a.length-2}, but expected length of ${V[i]*2} for ${i} type.`);this.name="InvalidHexLengthForStaticFieldError"}},v=class extends h{constructor(i,a){super(`Hex value "${a}" has length of ${a.length-2}, but expected a multiple of ${V[i]*2} for ${i}[] type.`);this.name="InvalidHexLengthForArrayFieldError"}},P=class extends h{constructor(i,a,c){super(`Schema "${i}" static data length (${a}) did not match the summed length of all static fields (${c}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`);this.name="SchemaStaticLengthMismatchError"}},H=class extends h{constructor(i,a,c){super(`EncodedLengths "${i}" total bytes length (${a}) did not match the summed length of all field byte lengths (${c}).`);this.name="EncodedLengthsLengthMismatchError"}};function y(e,t){if(t.length>3&&t.length%2!==0)throw new u(t);if((t.length-2)/2!==G[e])throw new A(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 a=_(t,{signed:e.startsWith("int")}),c=typeof J[e];if(c==="number")return Number(a);if(c==="bigint")return a;throw new Error(`Unexpected default value type (${c}) 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 q(t);case"address":return W(t)}return C(e,`Unsupported static ABI type: ${e}`)}function f(e,t){if(e==="bytes")return t;if(e==="string")return Q(t);if(t.length>3&&t.length%2!==0)throw new u(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 a=Z(e),c=ee[a];if(i%c!==0)throw new v(a,t);return new Array(i/c).fill(void 0).map((s,r)=>{let o=X(t,r*c,(r+1)*c);return y(a,o)})}}return Y(e,`Unsupported dynamic ABI type: ${e}`)}import{isDynamicAbiType as te}from"@latticexyz/schema-type/internal";function pt(e,t){return te(e)?f(e,t):y(e,t)}import{decodeAbiParameters as ie}from"viem";function $(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,a)=>ie([{type:e.staticFields[a]}],i)[0])}function ft(e,t){let i=$({staticFields:Object.values(e),dynamicFields:[]},t);return Object.fromEntries(Object.keys(e).map((a,c)=>[a,i[c]]))}import{staticAbiTypeToByteLength as ce,dynamicAbiTypeToDefaultValue as re}from"@latticexyz/schema-type/internal";import{readHex as j}from"@latticexyz/common";function k(e){if(e.length!==66)throw new g(e);let t=y("uint56",j(e,25,32)),i=f("uint40[]",j(e,0,25)),a=Object.freeze([...i].reverse()),c=BigInt(a.reduce((n,s)=>n+s,0));if(c!==t)throw new H(e,t,c);return{totalByteLength:t,fieldByteLengths:a}}import{staticAbiTypeToByteLength as ae}from"@latticexyz/schema-type/internal";function T(e){return e.reduce((t,i)=>t+ae[i],0)}import{readHex as L}from"@latticexyz/common";function B(e,t){let i=[],a=0;e.staticFields.forEach(s=>{let r=ce[s],o=y(s,L(t,a,a+r));a+=r,i.push(o)});let c=T(e.staticFields),n=a;if(n!==c&&console.warn("Decoded static data length does not match value schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?",{expectedLength:c,actualLength:n,bytesOffset:a}),e.dynamicFields.length>0){let s=k(L(t,a,a+32));a+=32,e.dynamicFields.forEach((o,l)=>{let m=s.fieldByteLengths[l];if(m>0){let d=f(o,L(t,a,a+m));a+=m,i.push(d)}else i.push(re[o])});let r=a-32-n;BigInt(r)!==s.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:s.totalByteLength,actualLength:r,bytesOffset:a})}return i}import{isStaticAbiType as se,isDynamicAbiType as ne}from"@latticexyz/schema-type/internal";function E(e,t){let i=Object.values(e).filter(se),a=Object.values(e).filter(ne),c=B({staticFields:i,dynamicFields:a},t);return Object.fromEntries(Object.keys(e).map((n,s)=>[n,c[s]]))}import{concatHex as oe}from"viem";import{isStaticAbiType as me}from"@latticexyz/schema-type/internal";import{readHex as pe}from"@latticexyz/common";function Mt(e,{staticData:t,encodedLengths:i,dynamicData:a}){return E(e,oe([pe(t,0,T(Object.values(e).filter(me))),i,a]))}import{arrayToStaticAbiType as ye,isArrayAbiType as le}from"@latticexyz/schema-type/internal";import{encodePacked as w}from"viem";function p(e,t){if(le(e)&&Array.isArray(t)){let i=ye(e);return t.length===0?"0x":w(t.map(()=>i),t)}return w([e],[t])}import{isStaticAbiType as he}from"@latticexyz/schema-type/internal";import{encodeAbiParameters as de}from"viem";function O(e,t){return t.map((i,a)=>de([{type:e.staticFields[a]}],[i]))}function ti(e,t){let i=Object.values(e).filter(he);return O({staticFields:i,dynamicFields:[]},Object.values(t))}function ci(e,t){let i=t.slice(0,e.staticFields.length),a=t.slice(e.staticFields.length),c=i.map((m,d)=>p(e.staticFields[d],m).replace(/^0x/,"")).join("");if(e.dynamicFields.length===0)return`0x${c}`;let n=a.map((m,d)=>p(e.dynamicFields[d],m).replace(/^0x/,"")),s=n.map(m=>m.length/2).reverse(),r=s.reduce((m,d)=>m+BigInt(d),0n),o=n.join(""),l=`${s.map(m=>p("uint40",m).replace(/^0x/,"")).join("")}${p("uint56",r).replace(/^0x/,"")}`.padStart(64,"0");return`0x${c}${l}${o}`}import{concatHex as Se}from"viem";import{isStaticAbiType as be,isDynamicAbiType as xe}from"@latticexyz/schema-type/internal";import{concatHex as I}from"viem";import{concatHex as ue,padHex as fe,size as Te}from"viem";function K(e){let t=e.map(Te).reverse(),i=t.reduce((a,c)=>a+BigInt(c),0n);return fe(ue([...t.map(a=>p("uint40",a)),p("uint56",i)]),{size:32,dir:"left"})}function N(e,t){let i=Object.entries(e),a=i.filter(([,o])=>be(o)),c=i.filter(([,o])=>xe(o)),n=a.map(([o,l])=>p(l,t[o])),s=c.map(([o,l])=>p(l,t[o])),r=K(s);return{staticData:I(n),encodedLengths:r,dynamicData:I(s)}}function Ai(e,t){let{staticData:i,encodedLengths:a,dynamicData:c}=N(e,t);return Se([i,a,c])}function Pi(e){return`0x${[e.staticFieldLengths.reduce((i,a)=>i+a,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 z,staticAbiTypeToByteLength as ge}from"@latticexyz/schema-type/internal";import{hexToNumber as b,sliceHex as x}from"viem";function D(e){if(e.length!==66)throw new S(e);let t=b(x(e,0,2)),i=b(x(e,2,3)),a=b(x(e,3,4)),c=[],n=[];for(let r=4;r<4+i;r++){let o=b(x(e,r,r+1));c.push(z[o])}for(let r=4+i;r<4+i+a;r++){let o=b(x(e,r,r+1));n.push(z[o])}let s=c.reduce((r,o)=>r+ge[o],0);if(s!==t)throw console.warn(`Schema "${e}" static data length (${t}) did not match the summed length of all static fields (${s}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`),new P(e,t,s);return{staticFields:c,dynamicFields:n}}import{sliceHex as R}from"viem";function Oi(e){let t=D(R(e,0,32));return{keySchema:D(R(e,32,64)),valueSchema:t}}import{isStaticAbiType as Ae}from"@latticexyz/schema-type/internal";import{schemaAbiTypes as U}from"@latticexyz/schema-type/internal";function F(e){let t=e.staticFields.map(a=>U.indexOf(a)),i=e.dynamicFields.map(a=>U.indexOf(a));return`0x${[T(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(a=>a.toString(16).padStart(2,"0")),...i.map(a=>a.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}function Mi(e){return F({staticFields:Object.values(e).filter(Ae),dynamicFields:[]})}function _i(e,t){return t<e.staticFields.length?e.staticFields[t]:e.dynamicFields[t-e.staticFields.length]}import{isDynamicAbiType as ve,isStaticAbiType as Pe,staticAbiTypeToByteLength as He}from"@latticexyz/schema-type/internal";function Gi(e){let t=Object.values(e).filter(Pe),i=Object.values(e).filter(ve),a=t.map(n=>He[n]);return`0x${[a.reduce((n,s)=>n+s,0).toString(16).padStart(4,"0"),t.length.toString(16).padStart(2,"0"),i.length.toString(16).padStart(2,"0"),...a.map(n=>n.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}import{isDynamicAbiType as Fe,isStaticAbiType as Le}from"@latticexyz/schema-type/internal";function Yi(e){return F({staticFields:Object.values(e).filter(Le),dynamicFields:Object.values(e).filter(Fe)})}function ea(e,t){return Object.fromEntries(e.key.map(i=>[i,t[i]]))}function ia(e,t){return Object.fromEntries(Object.keys(e.schema).filter(i=>!e.key.includes(i)).map(i=>[i,t[i]]))}import{isDynamicAbiType as De,isStaticAbiType as Ve}from"@latticexyz/schema-type/internal";function ra(e,t){return[...Object.entries(e).filter(([,a])=>Ve(a)).map(([a])=>a),...Object.entries(e).filter(([,a])=>De(a)).map(([a])=>a)].indexOf(t)}function na(e){return Object.fromEntries(e.key.map(t=>[t,e.schema[t]]))}import{encodeAbiParameters as $e}from"viem";function ya(e,t){return e.key.map(i=>$e([e.schema[i]],[t[i]]))}function da(e){return Object.fromEntries(Object.entries(e.schema).filter(([t])=>!e.key.includes(t)))}import{mapObject as je}from"@latticexyz/common/utils";function fa(e){return je(e,t=>t.type)}export{H as EncodedLengthsLengthMismatchError,u as InvalidHexLengthError,v as InvalidHexLengthForArrayFieldError,g as InvalidHexLengthForEncodedLengthsError,S as InvalidHexLengthForSchemaError,A as InvalidHexLengthForStaticFieldError,P as SchemaStaticLengthMismatchError,Oe as abiTypesToSchema,f as decodeDynamicField,pt as decodeField,ft as decodeKey,$ as decodeKeyTuple,B as decodeRecord,y as decodeStaticField,E as decodeValue,Mt as decodeValueArgs,p as encodeField,ti as encodeKey,O as encodeKeyTuple,ci as encodeRecord,Ai as encodeValue,N as encodeValueArgs,Pi as fieldLayoutToHex,ra as getFieldIndex,ea as getKey,na as getKeySchema,ya as getKeyTuple,fa as getSchemaTypes,ia as getValue,da as getValueSchema,k as hexToEncodedLengths,D as hexToSchema,Oi as hexToTableSchema,Mi as keySchemaToHex,_i as schemaIndexToAbiType,F as schemaToHex,T as staticDataLength,Gi as valueSchemaToFieldLayoutHex,Yi as valueSchemaToHex};
1
+ import{isDynamicAbiType as M}from"@latticexyz/schema-type/internal";function Ke(e){let t=[],i=[];for(let a of e)M(a)?i.push(a):t.push(a);return{staticFields:t,dynamicFields:i}}import{hexToString as Q,sliceHex as X}from"viem";import{assertExhaustive as Y}from"@latticexyz/common/utils";import{arrayToStaticAbiType as Z,staticAbiTypeToByteLength as ee}from"@latticexyz/schema-type/internal";import{getAddress as W,hexToBigInt as _,hexToBool as q}from"viem";import{assertExhaustive as C}from"@latticexyz/common/utils";import{staticAbiTypeToByteLength as G,staticAbiTypeToDefaultValue as J}from"@latticexyz/schema-type/internal";import{MUDError as h}from"@latticexyz/common/errors";import{staticAbiTypeToByteLength as V}from"@latticexyz/schema-type/internal";var u=class extends h{constructor(i){super(`Hex value "${i}" is an odd length (${i.length-2}). It must be an even length.`);this.name="InvalidHexValueError"}},S=class extends h{constructor(i){super(`Hex value "${i}" has length of ${i.length-2}, but expected length of 64 for a schema.`);this.name="InvalidHexLengthForSchemaError"}},g=class extends h{constructor(i){super(`Hex value "${i}" has length of ${i.length-2}, but expected length of 64 for encoded lengths.`);this.name="InvalidHexLengthForEncodedLengthsError"}},A=class extends h{constructor(i,a){super(`Hex value "${a}" has length of ${a.length-2}, but expected length of ${V[i]*2} for ${i} type.`);this.name="InvalidHexLengthForStaticFieldError"}},v=class extends h{constructor(i,a){super(`Hex value "${a}" has length of ${a.length-2}, but expected a multiple of ${V[i]*2} for ${i}[] type.`);this.name="InvalidHexLengthForArrayFieldError"}},P=class extends h{constructor(i,a,c){super(`Schema "${i}" static data length (${a}) did not match the summed length of all static fields (${c}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`);this.name="SchemaStaticLengthMismatchError"}},H=class extends h{constructor(i,a,c){super(`EncodedLengths "${i}" total bytes length (${a}) did not match the summed length of all field byte lengths (${c}).`);this.name="EncodedLengthsLengthMismatchError"}};function y(e,t){if(t.length>3&&t.length%2!==0)throw new u(t);if((t.length-2)/2!==G[e])throw new A(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 a=_(t,{signed:e.startsWith("int")}),c=typeof J[e];if(c==="number")return Number(a);if(c==="bigint")return a;throw new Error(`Unexpected default value type (${c}) 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 q(t);case"address":return W(t)}return C(e,`Unsupported static ABI type: ${e}`)}function f(e,t){if(e==="bytes")return t;if(e==="string")return Q(t);if(t.length>3&&t.length%2!==0)throw new u(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 a=Z(e),c=ee[a];if(i%c!==0)throw new v(a,t);return new Array(i/c).fill(void 0).map((s,r)=>{let o=X(t,r*c,(r+1)*c);return y(a,o)})}}return Y(e,`Unsupported dynamic ABI type: ${e}`)}import{isDynamicAbiType as te}from"@latticexyz/schema-type/internal";function yt(e,t){return te(e)?f(e,t):y(e,t)}import{decodeAbiParameters as ie}from"viem";function $(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,a)=>ie([{type:e.staticFields[a]}],i)[0])}function Tt(e,t){let i=$({staticFields:Object.values(e),dynamicFields:[]},t);return Object.fromEntries(Object.keys(e).map((a,c)=>[a,i[c]]))}import{staticAbiTypeToByteLength as ce,dynamicAbiTypeToDefaultValue as re}from"@latticexyz/schema-type/internal";import{readHex as j}from"@latticexyz/common";function k(e){if(e.length!==66)throw new g(e);let t=y("uint56",j(e,25,32)),i=f("uint40[]",j(e,0,25)),a=Object.freeze([...i].reverse()),c=BigInt(a.reduce((n,s)=>n+s,0));if(c!==t)throw new H(e,t,c);return{totalByteLength:t,fieldByteLengths:a}}import{staticAbiTypeToByteLength as ae}from"@latticexyz/schema-type/internal";function T(e){return e.reduce((t,i)=>t+ae[i],0)}import{readHex as L}from"@latticexyz/common";function B(e,t){let i=[],a=0;e.staticFields.forEach(s=>{let r=ce[s],o=y(s,L(t,a,a+r));a+=r,i.push(o)});let c=T(e.staticFields),n=a;if(n!==c&&console.warn("Decoded static data length does not match value schema's expected static data length. Data may get corrupted. Is `getStaticByteLength` outdated?",{expectedLength:c,actualLength:n,bytesOffset:a}),e.dynamicFields.length>0){let s=k(L(t,a,a+32));a+=32,e.dynamicFields.forEach((o,l)=>{let m=s.fieldByteLengths[l];if(m>0){let d=f(o,L(t,a,a+m));a+=m,i.push(d)}else i.push(re[o])});let r=a-32-n;BigInt(r)!==s.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:s.totalByteLength,actualLength:r,bytesOffset:a})}return i}import{isStaticAbiType as se,isDynamicAbiType as ne}from"@latticexyz/schema-type/internal";function E(e,t){let i=Object.values(e).filter(se),a=Object.values(e).filter(ne),c=B({staticFields:i,dynamicFields:a},t);return Object.fromEntries(Object.keys(e).map((n,s)=>[n,c[s]]))}import{concatHex as oe,padHex as me}from"viem";import{isStaticAbiType as pe}from"@latticexyz/schema-type/internal";import{readHex as ye}from"@latticexyz/common";function Wt(e,{staticData:t,encodedLengths:i,dynamicData:a}){return E(e,oe([ye(t,0,T(Object.values(e).filter(pe))),me(i,{size:32}),a]))}import{arrayToStaticAbiType as le,isArrayAbiType as de}from"@latticexyz/schema-type/internal";import{encodePacked as w}from"viem";function p(e,t){if(de(e)&&Array.isArray(t)){let i=le(e);return t.length===0?"0x":w(t.map(()=>i),t)}return w([e],[t])}import{isStaticAbiType as ue}from"@latticexyz/schema-type/internal";import{encodeAbiParameters as he}from"viem";function O(e,t){return t.map((i,a)=>he([{type:e.staticFields[a]}],[i]))}function ii(e,t){let i=Object.values(e).filter(ue);return O({staticFields:i,dynamicFields:[]},Object.values(t))}function ri(e,t){let i=t.slice(0,e.staticFields.length),a=t.slice(e.staticFields.length),c=i.map((m,d)=>p(e.staticFields[d],m).replace(/^0x/,"")).join("");if(e.dynamicFields.length===0)return`0x${c}`;let n=a.map((m,d)=>p(e.dynamicFields[d],m).replace(/^0x/,"")),s=n.map(m=>m.length/2).reverse(),r=s.reduce((m,d)=>m+BigInt(d),0n),o=n.join(""),l=`${s.map(m=>p("uint40",m).replace(/^0x/,"")).join("")}${p("uint56",r).replace(/^0x/,"")}`.padStart(64,"0");return`0x${c}${l}${o}`}import{concatHex as ge}from"viem";import{isStaticAbiType as xe,isDynamicAbiType as Se}from"@latticexyz/schema-type/internal";import{concatHex as I}from"viem";import{concatHex as fe,padHex as Te,size as be}from"viem";function K(e){let t=e.map(be).reverse(),i=t.reduce((a,c)=>a+BigInt(c),0n);return Te(fe([...t.map(a=>p("uint40",a)),p("uint56",i)]),{size:32,dir:"left"})}function z(e,t){let i=Object.entries(e),a=i.filter(([,o])=>xe(o)),c=i.filter(([,o])=>Se(o)),n=a.map(([o,l])=>p(l,t[o])),s=c.map(([o,l])=>p(l,t[o])),r=K(s);return{staticData:I(n),encodedLengths:r,dynamicData:I(s)}}function vi(e,t){let{staticData:i,encodedLengths:a,dynamicData:c}=z(e,t);return ge([i,a,c])}function Hi(e){return`0x${[e.staticFieldLengths.reduce((i,a)=>i+a,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 N,staticAbiTypeToByteLength as Ae}from"@latticexyz/schema-type/internal";import{hexToNumber as b,sliceHex as x}from"viem";function D(e){if(e.length!==66)throw new S(e);let t=b(x(e,0,2)),i=b(x(e,2,3)),a=b(x(e,3,4)),c=[],n=[];for(let r=4;r<4+i;r++){let o=b(x(e,r,r+1));c.push(N[o])}for(let r=4+i;r<4+i+a;r++){let o=b(x(e,r,r+1));n.push(N[o])}let s=c.reduce((r,o)=>r+Ae[o],0);if(s!==t)throw console.warn(`Schema "${e}" static data length (${t}) did not match the summed length of all static fields (${s}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`),new P(e,t,s);return{staticFields:c,dynamicFields:n}}import{sliceHex as R}from"viem";function Ki(e){let t=D(R(e,0,32));return{keySchema:D(R(e,32,64)),valueSchema:t}}import{isStaticAbiType as ve}from"@latticexyz/schema-type/internal";import{schemaAbiTypes as U}from"@latticexyz/schema-type/internal";function F(e){let t=e.staticFields.map(a=>U.indexOf(a)),i=e.dynamicFields.map(a=>U.indexOf(a));return`0x${[T(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(a=>a.toString(16).padStart(2,"0")),...i.map(a=>a.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}function Wi(e){return F({staticFields:Object.values(e).filter(ve),dynamicFields:[]})}function qi(e,t){return t<e.staticFields.length?e.staticFields[t]:e.dynamicFields[t-e.staticFields.length]}import{isDynamicAbiType as Pe,isStaticAbiType as He,staticAbiTypeToByteLength as Fe}from"@latticexyz/schema-type/internal";function Ji(e){let t=Object.values(e).filter(He),i=Object.values(e).filter(Pe),a=t.map(n=>Fe[n]);return`0x${[a.reduce((n,s)=>n+s,0).toString(16).padStart(4,"0"),t.length.toString(16).padStart(2,"0"),i.length.toString(16).padStart(2,"0"),...a.map(n=>n.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}import{isDynamicAbiType as Le,isStaticAbiType as De}from"@latticexyz/schema-type/internal";function Zi(e){return F({staticFields:Object.values(e).filter(De),dynamicFields:Object.values(e).filter(Le)})}function ta(e,t){return Object.fromEntries(e.key.map(i=>[i,t[i]]))}function aa(e,t){return Object.fromEntries(Object.keys(e.schema).filter(i=>!e.key.includes(i)).map(i=>[i,t[i]]))}import{isDynamicAbiType as Ve,isStaticAbiType as $e}from"@latticexyz/schema-type/internal";function sa(e,t){return[...Object.entries(e).filter(([,a])=>$e(a)).map(([a])=>a),...Object.entries(e).filter(([,a])=>Ve(a)).map(([a])=>a)].indexOf(t)}function oa(e){return Object.fromEntries(e.key.map(t=>[t,e.schema[t]]))}import{encodeAbiParameters as je}from"viem";function la(e,t){return e.key.map(i=>je([e.schema[i]],[t[i]]))}function ha(e){return Object.fromEntries(Object.entries(e.schema).filter(([t])=>!e.key.includes(t)))}import{mapObject as ke}from"@latticexyz/common/utils";function Ta(e){return ke(e,t=>t.type)}export{H as EncodedLengthsLengthMismatchError,u as InvalidHexLengthError,v as InvalidHexLengthForArrayFieldError,g as InvalidHexLengthForEncodedLengthsError,S as InvalidHexLengthForSchemaError,A as InvalidHexLengthForStaticFieldError,P as SchemaStaticLengthMismatchError,Ke as abiTypesToSchema,f as decodeDynamicField,yt as decodeField,Tt as decodeKey,$ as decodeKeyTuple,B as decodeRecord,y as decodeStaticField,E as decodeValue,Wt as decodeValueArgs,p as encodeField,ii as encodeKey,O as encodeKeyTuple,ri as encodeRecord,vi as encodeValue,z as encodeValueArgs,Hi as fieldLayoutToHex,sa as getFieldIndex,ta as getKey,oa as getKeySchema,la as getKeyTuple,Ta as getSchemaTypes,aa as getValue,ha as getValueSchema,k as hexToEncodedLengths,D as hexToSchema,Ki as hexToTableSchema,Wi as keySchemaToHex,qi as schemaIndexToAbiType,F as schemaToHex,T as staticDataLength,Ji as valueSchemaToFieldLayoutHex,Zi as valueSchemaToHex};
2
2
  //# sourceMappingURL=internal.js.map
@@ -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/hexToEncodedLengths.ts","../src/staticDataLength.ts","../src/decodeValue.ts","../src/decodeValueArgs.ts","../src/encodeField.ts","../src/encodeKey.ts","../src/encodeKeyTuple.ts","../src/encodeRecord.ts","../src/encodeValue.ts","../src/encodeValueArgs.ts","../src/encodeLengths.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","../src/getKey.ts","../src/getValue.ts","../src/getFieldIndex.ts","../src/getKeySchema.ts","../src/getKeyTuple.ts","../src/getValueSchema.ts","../src/getSchemaTypes.ts"],"sourcesContent":["import { DynamicAbiType, SchemaAbiType, StaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type/internal\";\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 arrayToStaticAbiType,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type/internal\";\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 = arrayToStaticAbiType(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/internal\";\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/internal\";\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 InvalidHexLengthForEncodedLengthsError extends MUDError {\n override name = \"InvalidHexLengthForEncodedLengthsError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for encoded lengths.`);\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}). ` +\n `Is \\`staticAbiTypeToByteLength\\` up to date with Solidity schema types?`,\n );\n }\n}\n\nexport class EncodedLengthsLengthMismatchError extends MUDError {\n override name = \"EncodedLengthsLengthMismatchError\";\n constructor(encodedLengthsData: Hex, definedLength: bigint, summedLength: bigint) {\n super(\n `EncodedLengths \"${encodedLengthsData}\" 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/internal\";\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/internal\";\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/internal\";\nimport { Hex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { hexToEncodedLengths } from \"./hexToEncodedLengths\";\nimport { staticDataLength } from \"./staticDataLength\";\nimport { readHex } from \"@latticexyz/common\";\n\n/** @deprecated use `decodeValue` instead */\nexport function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPrimitiveType | DynamicPrimitiveType)[] {\n const values: (StaticPrimitiveType | DynamicPrimitiveType)[] = [];\n\n let bytesOffset = 0;\n valueSchema.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 value schema, because data corruption might be possible.\n const schemaStaticDataLength = staticDataLength(valueSchema.staticFields);\n const actualStaticDataLength = bytesOffset;\n if (actualStaticDataLength !== schemaStaticDataLength) {\n console.warn(\n \"Decoded static data length does not match value 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 (valueSchema.dynamicFields.length > 0) {\n const dataLayout = hexToEncodedLengths(readHex(data, bytesOffset, bytesOffset + 32));\n bytesOffset += 32;\n\n valueSchema.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 dynamic data length, 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\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { InvalidHexLengthForEncodedLengthsError, EncodedLengthsLengthMismatchError } from \"./errors\";\nimport { readHex } from \"@latticexyz/common\";\n\n// Keep this logic in sync with EncodedLengths.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 value schema first (and thus the field lengths of each dynamic type)\n\nexport function hexToEncodedLengths(data: Hex): {\n totalByteLength: bigint;\n fieldByteLengths: readonly number[];\n} {\n if (data.length !== 66) {\n throw new InvalidHexLengthForEncodedLengthsError(data);\n }\n\n const totalByteLength = decodeStaticField(\"uint56\", readHex(data, 32 - 7, 32));\n // TODO: use value 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 EncodedLengthsLengthMismatchError(data, totalByteLength, summedLength);\n }\n\n return { totalByteLength, fieldByteLengths };\n}\n","import { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type/internal\";\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/internal\";\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 { concatHex } from \"viem\";\nimport { isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { SchemaToPrimitives, ValueArgs, ValueSchema } from \"./common\";\nimport { decodeValue } from \"./decodeValue\";\nimport { staticDataLength } from \"./staticDataLength\";\nimport { readHex } from \"@latticexyz/common\";\n\nexport function decodeValueArgs<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n { staticData, encodedLengths, dynamicData }: ValueArgs,\n): SchemaToPrimitives<TSchema> {\n return decodeValue(\n valueSchema,\n concatHex([\n readHex(staticData, 0, staticDataLength(Object.values(valueSchema).filter(isStaticAbiType))),\n encodedLengths,\n dynamicData,\n ]),\n );\n}\n","import { SchemaAbiType, arrayToStaticAbiType, isArrayAbiType } from \"@latticexyz/schema-type/internal\";\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 = arrayToStaticAbiType(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 as never]);\n}\n","import { isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, KeySchema } from \"./common\";\nimport { encodeKeyTuple } from \"./encodeKeyTuple\";\n\nexport function encodeKey<TSchema extends KeySchema>(\n keySchema: TSchema,\n key: SchemaToPrimitives<TSchema>,\n): readonly 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/internal\";\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/internal\";\nimport { Hex } from \"viem\";\nimport { encodeField } from \"./encodeField\";\nimport { Schema } from \"./common\";\n\n/** @deprecated use `encodeValue` instead */\nexport function encodeRecord(\n valueSchema: Schema,\n values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[],\n): Hex {\n const staticValues = values.slice(0, valueSchema.staticFields.length) as readonly StaticPrimitiveType[];\n const dynamicValues = values.slice(valueSchema.staticFields.length) as readonly DynamicPrimitiveType[];\n\n const staticData = staticValues\n .map((value, i) => encodeField(valueSchema.staticFields[i], value).replace(/^0x/, \"\"))\n .join(\"\");\n\n if (valueSchema.dynamicFields.length === 0) return `0x${staticData}`;\n\n const dynamicDataItems = dynamicValues.map((value, i) =>\n encodeField(valueSchema.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 encodedLengths = `${dynamicFieldByteLengths\n .map((length) => encodeField(\"uint40\", length).replace(/^0x/, \"\"))\n .join(\"\")}${encodeField(\"uint56\", dynamicTotalByteLength).replace(/^0x/, \"\")}`.padStart(64, \"0\");\n\n return `0x${staticData}${encodedLengths}${dynamicData}`;\n}\n","import { Hex, concatHex } from \"viem\";\nimport { SchemaToPrimitives, ValueSchema } from \"./common\";\nimport { encodeValueArgs } from \"./encodeValueArgs\";\n\nexport function encodeValue<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n value: SchemaToPrimitives<TSchema>,\n): Hex {\n const { staticData, encodedLengths, dynamicData } = encodeValueArgs(valueSchema, value);\n return concatHex([staticData, encodedLengths, dynamicData]);\n}\n","import {\n StaticPrimitiveType,\n DynamicPrimitiveType,\n isStaticAbiType,\n isDynamicAbiType,\n StaticAbiType,\n DynamicAbiType,\n} from \"@latticexyz/schema-type/internal\";\nimport { concatHex } from \"viem\";\nimport { encodeField } from \"./encodeField\";\nimport { SchemaToPrimitives, ValueArgs, ValueSchema } from \"./common\";\nimport { encodeLengths } from \"./encodeLengths\";\n\nexport function encodeValueArgs<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n value: SchemaToPrimitives<TSchema>,\n): ValueArgs {\n const valueSchemaEntries = Object.entries(valueSchema);\n const staticFields = valueSchemaEntries.filter(([, type]) => isStaticAbiType(type)) as [string, StaticAbiType][];\n const dynamicFields = valueSchemaEntries.filter(([, type]) => isDynamicAbiType(type)) as [string, DynamicAbiType][];\n // TODO: validate <=5 dynamic fields\n // TODO: validate <=28 total fields\n\n const encodedStaticValues = staticFields.map(([name, type]) => encodeField(type, value[name] as StaticPrimitiveType));\n const encodedDynamicValues = dynamicFields.map(([name, type]) =>\n encodeField(type, value[name] as DynamicPrimitiveType),\n );\n\n const encodedLengths = encodeLengths(encodedDynamicValues);\n\n return {\n staticData: concatHex(encodedStaticValues),\n encodedLengths,\n dynamicData: concatHex(encodedDynamicValues),\n };\n}\n","import { Hex, concatHex, padHex, size } from \"viem\";\nimport { encodeField } from \"./encodeField\";\n\nexport function encodeLengths(values: Hex[]): Hex {\n const byteLengths = values.map(size).reverse();\n const totalByteLength = byteLengths.reduce((total, length) => total + BigInt(length), 0n);\n\n return padHex(\n concatHex([...byteLengths.map((length) => encodeField(\"uint40\", length)), encodeField(\"uint56\", totalByteLength)]),\n { size: 32, dir: \"left\" },\n );\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 {\n StaticAbiType,\n DynamicAbiType,\n schemaAbiTypes,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type/internal\";\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}). ` +\n `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/internal\";\nimport { Hex } from \"viem\";\nimport { KeySchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function keySchemaToHex(keySchema: KeySchema): Hex {\n return schemaToHex({ staticFields: Object.values(keySchema).filter(isStaticAbiType), dynamicFields: [] });\n}\n","import { schemaAbiTypes } from \"@latticexyz/schema-type/internal\";\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/internal\";\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/internal\";\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/internal\";\nimport { Hex } from \"viem\";\nimport { ValueSchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function valueSchemaToHex(valueSchema: ValueSchema): Hex {\n return schemaToHex({\n staticFields: Object.values(valueSchema).filter(isStaticAbiType),\n dynamicFields: Object.values(valueSchema).filter(isDynamicAbiType),\n });\n}\n","import { Table } from \"@latticexyz/config\";\nimport { getKeySchema } from \"./getKeySchema\";\nimport { getSchemaPrimitives } from \"./getSchemaPrimitives\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport function getKey<table extends PartialTable>(\n table: table,\n record: getSchemaPrimitives<table[\"schema\"]>,\n): getSchemaPrimitives<getKeySchema<table>> {\n return Object.fromEntries(table.key.map((fieldName) => [fieldName, record[fieldName]])) as never;\n}\n","import { Table } from \"@latticexyz/config\";\nimport { getValueSchema } from \"./getValueSchema\";\nimport { getSchemaPrimitives } from \"./getSchemaPrimitives\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport function getValue<table extends PartialTable>(\n table: table,\n record: getSchemaPrimitives<table[\"schema\"]>,\n): getSchemaPrimitives<getValueSchema<table>> {\n return Object.fromEntries(\n Object.keys(table.schema)\n .filter((fieldName) => !table.key.includes(fieldName))\n .map((fieldName) => [fieldName, record[fieldName]]),\n ) as never;\n}\n","import { isDynamicAbiType, isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { ValueSchema } from \"./common\";\n\nexport function getFieldIndex<valueSchema extends ValueSchema>(\n valueSchema: valueSchema,\n fieldName: keyof valueSchema & string,\n): number {\n const fieldNames = [\n ...Object.entries(valueSchema)\n .filter(([, fieldType]) => isStaticAbiType(fieldType))\n .map(([fieldName]) => fieldName),\n ...Object.entries(valueSchema)\n .filter(([, fieldType]) => isDynamicAbiType(fieldType))\n .map(([fieldName]) => fieldName),\n ];\n\n return fieldNames.indexOf(fieldName);\n}\n","import { StaticAbiType, Table } from \"@latticexyz/config\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport type ResolvedKeySchema = {\n readonly [fieldName: string]: {\n /** the Solidity primitive ABI type */\n readonly type: StaticAbiType;\n /** the user defined type or Solidity primitive ABI type */\n readonly internalType: string;\n };\n};\n\nexport type getKeySchema<table extends PartialTable> = PartialTable extends table\n ? ResolvedKeySchema\n : {\n readonly [fieldName in Extract<keyof table[\"schema\"], table[\"key\"][number]>]: table[\"schema\"][fieldName] & {\n readonly type: StaticAbiType;\n };\n };\n\nexport function getKeySchema<table extends PartialTable>(table: table): getKeySchema<table> {\n return Object.fromEntries(table.key.map((fieldName) => [fieldName, table.schema[fieldName]])) as getKeySchema<table>;\n}\n","import { Hex, encodeAbiParameters } from \"viem\";\nimport { getSchemaPrimitives } from \"./getSchemaPrimitives\";\nimport { getKeySchema } from \"./getKeySchema\";\nimport { Table } from \"@latticexyz/config\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport type getKeyTuple<table extends PartialTable, key extends readonly unknown[] = table[\"key\"]> = {\n [i in keyof key]: Hex;\n} & unknown;\n\nexport function getKeyTuple<const table extends PartialTable>(\n table: table,\n key: getSchemaPrimitives<getKeySchema<table>>,\n): getKeyTuple<table> {\n return table.key.map((fieldName) =>\n encodeAbiParameters([table.schema[fieldName]], [key[fieldName as never]]),\n ) as never;\n}\n","import { Schema, Table } from \"@latticexyz/config\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport type getValueSchema<table extends PartialTable> = PartialTable extends table\n ? Schema\n : {\n readonly [fieldName in Exclude<keyof table[\"schema\"], table[\"key\"][number]>]: table[\"schema\"][fieldName];\n };\n\nexport function getValueSchema<table extends PartialTable>(table: table): getValueSchema<table> {\n return Object.fromEntries(\n Object.entries(table.schema).filter(([fieldName]) => !table.key.includes(fieldName)),\n ) as getValueSchema<table>;\n}\n","import { Schema } from \"@latticexyz/config\";\nimport { mapObject } from \"@latticexyz/common/utils\";\n\nexport type getSchemaTypes<schema extends Schema> = {\n readonly [fieldName in keyof schema]: schema[fieldName][\"type\"];\n};\n\nexport function getSchemaTypes<schema extends Schema>(schema: schema): getSchemaTypes<schema> {\n return mapObject(schema, (value) => value.type);\n}\n"],"mappings":"AAAA,OAAuD,oBAAAA,MAAwB,mCAGxE,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,wBAAAC,EACA,6BAAAC,OACK,mCCPP,OAAc,cAAAC,EAAY,eAAAC,EAAa,aAAAC,MAAiB,OACxD,OAAS,oBAAAC,MAAwB,2BACjC,OAGE,6BAAAC,EACA,+BAAAC,MACK,mCCNP,OAAS,YAAAC,MAAgB,4BACzB,OAAwB,6BAAAC,MAAiC,mCAElD,IAAMC,EAAN,cAAoCF,CAAS,CAElD,YAAYG,EAAY,CACtB,MAAM,cAAcA,CAAK,uBAAuBA,EAAM,OAAS,CAAC,+BAA+B,EAFjG,KAAS,KAAO,sBAGhB,CACF,EAEaC,EAAN,cAA6CJ,CAAS,CAE3D,YAAYG,EAAY,CACtB,MAAM,cAAcA,CAAK,mBAAmBA,EAAM,OAAS,CAAC,2CAA2C,EAFzG,KAAS,KAAO,gCAGhB,CACF,EAEaE,EAAN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CAACD,EAAIC,CAAkB,CAAC,CAAC,CAC1E,CACF,CCRO,SAASC,GAA2CC,EAAqC,CAC9F,OAAO,OAAO,YACZ,OAAO,QAAQA,EAAM,MAAM,EAAE,OAAO,CAAC,CAACC,CAAS,IAAM,CAACD,EAAM,IAAI,SAASC,CAAS,CAAC,CACrF,CACF,CCbA,OAAS,aAAAC,OAAiB,2BAMnB,SAASC,GAAsCC,EAAwC,CAC5F,OAAOF,GAAUE,EAASC,GAAUA,EAAM,IAAI,CAChD","names":["isDynamicAbiType","abiTypesToSchema","abiTypes","staticFields","dynamicFields","abiType","hexToString","sliceHex","assertExhaustive","arrayToStaticAbiType","staticAbiTypeToByteLength","getAddress","hexToBigInt","hexToBool","assertExhaustive","staticAbiTypeToByteLength","staticAbiTypeToDefaultValue","MUDError","staticAbiTypeToByteLength","InvalidHexLengthError","value","InvalidHexLengthForSchemaError","InvalidHexLengthForEncodedLengthsError","InvalidHexLengthForStaticFieldError","abiType","InvalidHexLengthForArrayFieldError","SchemaStaticLengthMismatchError","schemaData","definedLength","summedLength","EncodedLengthsLengthMismatchError","encodedLengthsData","decodeStaticField","abiType","data","InvalidHexLengthError","staticAbiTypeToByteLength","InvalidHexLengthForStaticFieldError","value","hexToBigInt","defaultValueType","staticAbiTypeToDefaultValue","hexToBool","getAddress","assertExhaustive","decodeDynamicField","abiType","data","hexToString","InvalidHexLengthError","dataSize","staticAbiType","arrayToStaticAbiType","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","hexToEncodedLengths","data","InvalidHexLengthForEncodedLengthsError","totalByteLength","decodeStaticField","reversedFieldByteLengths","decodeDynamicField","fieldByteLengths","summedLength","total","length","EncodedLengthsLengthMismatchError","staticAbiTypeToByteLength","staticDataLength","staticFields","length","fieldType","readHex","decodeRecord","valueSchema","data","values","bytesOffset","fieldType","fieldByteLength","staticAbiTypeToByteLength","value","decodeStaticField","schemaStaticDataLength","staticDataLength","actualStaticDataLength","dataLayout","hexToEncodedLengths","i","dataLength","decodeDynamicField","dynamicAbiTypeToDefaultValue","actualDynamicDataLength","isStaticAbiType","isDynamicAbiType","decodeValue","valueSchema","data","staticFields","isStaticAbiType","dynamicFields","isDynamicAbiType","valueTuple","decodeRecord","name","i","concatHex","isStaticAbiType","readHex","decodeValueArgs","valueSchema","staticData","encodedLengths","dynamicData","decodeValue","concatHex","staticDataLength","isStaticAbiType","arrayToStaticAbiType","isArrayAbiType","encodePacked","encodeField","fieldType","value","staticFieldType","isStaticAbiType","encodeAbiParameters","encodeKeyTuple","keySchema","keyTuple","key","index","encodeKey","keySchema","key","staticFields","isStaticAbiType","encodeKeyTuple","encodeRecord","valueSchema","values","staticValues","dynamicValues","staticData","value","i","encodeField","dynamicDataItems","dynamicFieldByteLengths","dynamicTotalByteLength","total","length","dynamicData","encodedLengths","concatHex","isStaticAbiType","isDynamicAbiType","concatHex","concatHex","padHex","size","encodeLengths","values","byteLengths","size","totalByteLength","total","length","padHex","concatHex","encodeField","encodeValueArgs","valueSchema","value","valueSchemaEntries","staticFields","type","isStaticAbiType","dynamicFields","isDynamicAbiType","encodedStaticValues","name","encodeField","encodedDynamicValues","encodedLengths","encodeLengths","concatHex","encodeValue","valueSchema","value","staticData","encodedLengths","dynamicData","encodeValueArgs","concatHex","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","keySchema","schemaToHex","isStaticAbiType","schemaIndexToAbiType","schema","schemaIndex","isDynamicAbiType","isStaticAbiType","staticAbiTypeToByteLength","valueSchemaToFieldLayoutHex","valueSchema","staticFields","dynamicFields","staticFieldLengths","fieldType","dataLength","fieldLength","isDynamicAbiType","isStaticAbiType","valueSchemaToHex","valueSchema","schemaToHex","isStaticAbiType","isDynamicAbiType","getKey","table","record","fieldName","getValue","table","record","fieldName","isDynamicAbiType","isStaticAbiType","getFieldIndex","valueSchema","fieldName","fieldType","getKeySchema","table","fieldName","encodeAbiParameters","getKeyTuple","table","key","fieldName","getValueSchema","table","fieldName","mapObject","getSchemaTypes","schema","value"]}
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/hexToEncodedLengths.ts","../src/staticDataLength.ts","../src/decodeValue.ts","../src/decodeValueArgs.ts","../src/encodeField.ts","../src/encodeKey.ts","../src/encodeKeyTuple.ts","../src/encodeRecord.ts","../src/encodeValue.ts","../src/encodeValueArgs.ts","../src/encodeLengths.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","../src/getKey.ts","../src/getValue.ts","../src/getFieldIndex.ts","../src/getKeySchema.ts","../src/getKeyTuple.ts","../src/getValueSchema.ts","../src/getSchemaTypes.ts"],"sourcesContent":["import { DynamicAbiType, SchemaAbiType, StaticAbiType, isDynamicAbiType } from \"@latticexyz/schema-type/internal\";\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 arrayToStaticAbiType,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type/internal\";\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 = arrayToStaticAbiType(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/internal\";\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/internal\";\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 InvalidHexLengthForEncodedLengthsError extends MUDError {\n override name = \"InvalidHexLengthForEncodedLengthsError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for encoded lengths.`);\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}). ` +\n `Is \\`staticAbiTypeToByteLength\\` up to date with Solidity schema types?`,\n );\n }\n}\n\nexport class EncodedLengthsLengthMismatchError extends MUDError {\n override name = \"EncodedLengthsLengthMismatchError\";\n constructor(encodedLengthsData: Hex, definedLength: bigint, summedLength: bigint) {\n super(\n `EncodedLengths \"${encodedLengthsData}\" 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/internal\";\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/internal\";\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/internal\";\nimport { Hex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { hexToEncodedLengths } from \"./hexToEncodedLengths\";\nimport { staticDataLength } from \"./staticDataLength\";\nimport { readHex } from \"@latticexyz/common\";\n\n/** @deprecated use `decodeValue` instead */\nexport function decodeRecord(valueSchema: Schema, data: Hex): readonly (StaticPrimitiveType | DynamicPrimitiveType)[] {\n const values: (StaticPrimitiveType | DynamicPrimitiveType)[] = [];\n\n let bytesOffset = 0;\n valueSchema.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 value schema, because data corruption might be possible.\n const schemaStaticDataLength = staticDataLength(valueSchema.staticFields);\n const actualStaticDataLength = bytesOffset;\n if (actualStaticDataLength !== schemaStaticDataLength) {\n console.warn(\n \"Decoded static data length does not match value 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 (valueSchema.dynamicFields.length > 0) {\n const dataLayout = hexToEncodedLengths(readHex(data, bytesOffset, bytesOffset + 32));\n bytesOffset += 32;\n\n valueSchema.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 dynamic data length, 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\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { InvalidHexLengthForEncodedLengthsError, EncodedLengthsLengthMismatchError } from \"./errors\";\nimport { readHex } from \"@latticexyz/common\";\n\n// Keep this logic in sync with EncodedLengths.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 value schema first (and thus the field lengths of each dynamic type)\n\nexport function hexToEncodedLengths(data: Hex): {\n totalByteLength: bigint;\n fieldByteLengths: readonly number[];\n} {\n if (data.length !== 66) {\n throw new InvalidHexLengthForEncodedLengthsError(data);\n }\n\n const totalByteLength = decodeStaticField(\"uint56\", readHex(data, 32 - 7, 32));\n // TODO: use value 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 EncodedLengthsLengthMismatchError(data, totalByteLength, summedLength);\n }\n\n return { totalByteLength, fieldByteLengths };\n}\n","import { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type/internal\";\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/internal\";\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 { concatHex, padHex } from \"viem\";\nimport { isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { SchemaToPrimitives, ValueArgs, ValueSchema } from \"./common\";\nimport { decodeValue } from \"./decodeValue\";\nimport { staticDataLength } from \"./staticDataLength\";\nimport { readHex } from \"@latticexyz/common\";\n\nexport function decodeValueArgs<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n { staticData, encodedLengths, dynamicData }: ValueArgs,\n): SchemaToPrimitives<TSchema> {\n return decodeValue(\n valueSchema,\n concatHex([\n readHex(staticData, 0, staticDataLength(Object.values(valueSchema).filter(isStaticAbiType))),\n padHex(encodedLengths, { size: 32 }),\n dynamicData,\n ]),\n );\n}\n","import { SchemaAbiType, arrayToStaticAbiType, isArrayAbiType } from \"@latticexyz/schema-type/internal\";\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 = arrayToStaticAbiType(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 as never]);\n}\n","import { isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { Hex } from \"viem\";\nimport { SchemaToPrimitives, KeySchema } from \"./common\";\nimport { encodeKeyTuple } from \"./encodeKeyTuple\";\n\nexport function encodeKey<TSchema extends KeySchema>(\n keySchema: TSchema,\n key: SchemaToPrimitives<TSchema>,\n): readonly 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/internal\";\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/internal\";\nimport { Hex } from \"viem\";\nimport { encodeField } from \"./encodeField\";\nimport { Schema } from \"./common\";\n\n/** @deprecated use `encodeValue` instead */\nexport function encodeRecord(\n valueSchema: Schema,\n values: readonly (StaticPrimitiveType | DynamicPrimitiveType)[],\n): Hex {\n const staticValues = values.slice(0, valueSchema.staticFields.length) as readonly StaticPrimitiveType[];\n const dynamicValues = values.slice(valueSchema.staticFields.length) as readonly DynamicPrimitiveType[];\n\n const staticData = staticValues\n .map((value, i) => encodeField(valueSchema.staticFields[i], value).replace(/^0x/, \"\"))\n .join(\"\");\n\n if (valueSchema.dynamicFields.length === 0) return `0x${staticData}`;\n\n const dynamicDataItems = dynamicValues.map((value, i) =>\n encodeField(valueSchema.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 encodedLengths = `${dynamicFieldByteLengths\n .map((length) => encodeField(\"uint40\", length).replace(/^0x/, \"\"))\n .join(\"\")}${encodeField(\"uint56\", dynamicTotalByteLength).replace(/^0x/, \"\")}`.padStart(64, \"0\");\n\n return `0x${staticData}${encodedLengths}${dynamicData}`;\n}\n","import { Hex, concatHex } from \"viem\";\nimport { SchemaToPrimitives, ValueSchema } from \"./common\";\nimport { encodeValueArgs } from \"./encodeValueArgs\";\n\nexport function encodeValue<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n value: SchemaToPrimitives<TSchema>,\n): Hex {\n const { staticData, encodedLengths, dynamicData } = encodeValueArgs(valueSchema, value);\n return concatHex([staticData, encodedLengths, dynamicData]);\n}\n","import {\n StaticPrimitiveType,\n DynamicPrimitiveType,\n isStaticAbiType,\n isDynamicAbiType,\n StaticAbiType,\n DynamicAbiType,\n} from \"@latticexyz/schema-type/internal\";\nimport { concatHex } from \"viem\";\nimport { encodeField } from \"./encodeField\";\nimport { SchemaToPrimitives, ValueArgs, ValueSchema } from \"./common\";\nimport { encodeLengths } from \"./encodeLengths\";\n\nexport function encodeValueArgs<TSchema extends ValueSchema>(\n valueSchema: TSchema,\n value: SchemaToPrimitives<TSchema>,\n): ValueArgs {\n const valueSchemaEntries = Object.entries(valueSchema);\n const staticFields = valueSchemaEntries.filter(([, type]) => isStaticAbiType(type)) as [string, StaticAbiType][];\n const dynamicFields = valueSchemaEntries.filter(([, type]) => isDynamicAbiType(type)) as [string, DynamicAbiType][];\n // TODO: validate <=5 dynamic fields\n // TODO: validate <=28 total fields\n\n const encodedStaticValues = staticFields.map(([name, type]) => encodeField(type, value[name] as StaticPrimitiveType));\n const encodedDynamicValues = dynamicFields.map(([name, type]) =>\n encodeField(type, value[name] as DynamicPrimitiveType),\n );\n\n const encodedLengths = encodeLengths(encodedDynamicValues);\n\n return {\n staticData: concatHex(encodedStaticValues),\n encodedLengths,\n dynamicData: concatHex(encodedDynamicValues),\n };\n}\n","import { Hex, concatHex, padHex, size } from \"viem\";\nimport { encodeField } from \"./encodeField\";\n\nexport function encodeLengths(values: Hex[]): Hex {\n const byteLengths = values.map(size).reverse();\n const totalByteLength = byteLengths.reduce((total, length) => total + BigInt(length), 0n);\n\n return padHex(\n concatHex([...byteLengths.map((length) => encodeField(\"uint40\", length)), encodeField(\"uint56\", totalByteLength)]),\n { size: 32, dir: \"left\" },\n );\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 {\n StaticAbiType,\n DynamicAbiType,\n schemaAbiTypes,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type/internal\";\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}). ` +\n `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/internal\";\nimport { Hex } from \"viem\";\nimport { KeySchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function keySchemaToHex(keySchema: KeySchema): Hex {\n return schemaToHex({ staticFields: Object.values(keySchema).filter(isStaticAbiType), dynamicFields: [] });\n}\n","import { schemaAbiTypes } from \"@latticexyz/schema-type/internal\";\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/internal\";\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/internal\";\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/internal\";\nimport { Hex } from \"viem\";\nimport { ValueSchema } from \"./common\";\nimport { schemaToHex } from \"./schemaToHex\";\n\nexport function valueSchemaToHex(valueSchema: ValueSchema): Hex {\n return schemaToHex({\n staticFields: Object.values(valueSchema).filter(isStaticAbiType),\n dynamicFields: Object.values(valueSchema).filter(isDynamicAbiType),\n });\n}\n","import { Table } from \"@latticexyz/config\";\nimport { getKeySchema } from \"./getKeySchema\";\nimport { getSchemaPrimitives } from \"./getSchemaPrimitives\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport function getKey<table extends PartialTable>(\n table: table,\n record: getSchemaPrimitives<table[\"schema\"]>,\n): getSchemaPrimitives<getKeySchema<table>> {\n return Object.fromEntries(table.key.map((fieldName) => [fieldName, record[fieldName]])) as never;\n}\n","import { Table } from \"@latticexyz/config\";\nimport { getValueSchema } from \"./getValueSchema\";\nimport { getSchemaPrimitives } from \"./getSchemaPrimitives\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport function getValue<table extends PartialTable>(\n table: table,\n record: getSchemaPrimitives<table[\"schema\"]>,\n): getSchemaPrimitives<getValueSchema<table>> {\n return Object.fromEntries(\n Object.keys(table.schema)\n .filter((fieldName) => !table.key.includes(fieldName))\n .map((fieldName) => [fieldName, record[fieldName]]),\n ) as never;\n}\n","import { isDynamicAbiType, isStaticAbiType } from \"@latticexyz/schema-type/internal\";\nimport { ValueSchema } from \"./common\";\n\nexport function getFieldIndex<valueSchema extends ValueSchema>(\n valueSchema: valueSchema,\n fieldName: keyof valueSchema & string,\n): number {\n const fieldNames = [\n ...Object.entries(valueSchema)\n .filter(([, fieldType]) => isStaticAbiType(fieldType))\n .map(([fieldName]) => fieldName),\n ...Object.entries(valueSchema)\n .filter(([, fieldType]) => isDynamicAbiType(fieldType))\n .map(([fieldName]) => fieldName),\n ];\n\n return fieldNames.indexOf(fieldName);\n}\n","import { StaticAbiType, Table } from \"@latticexyz/config\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport type ResolvedKeySchema = {\n readonly [fieldName: string]: {\n /** the Solidity primitive ABI type */\n readonly type: StaticAbiType;\n /** the user defined type or Solidity primitive ABI type */\n readonly internalType: string;\n };\n};\n\nexport type getKeySchema<table extends PartialTable> = PartialTable extends table\n ? ResolvedKeySchema\n : {\n readonly [fieldName in Extract<keyof table[\"schema\"], table[\"key\"][number]>]: table[\"schema\"][fieldName] & {\n readonly type: StaticAbiType;\n };\n };\n\nexport function getKeySchema<table extends PartialTable>(table: table): getKeySchema<table> {\n return Object.fromEntries(table.key.map((fieldName) => [fieldName, table.schema[fieldName]])) as getKeySchema<table>;\n}\n","import { Hex, encodeAbiParameters } from \"viem\";\nimport { getSchemaPrimitives } from \"./getSchemaPrimitives\";\nimport { getKeySchema } from \"./getKeySchema\";\nimport { Table } from \"@latticexyz/config\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport type getKeyTuple<table extends PartialTable, key extends readonly unknown[] = table[\"key\"]> = {\n [i in keyof key]: Hex;\n} & unknown;\n\nexport function getKeyTuple<const table extends PartialTable>(\n table: table,\n key: getSchemaPrimitives<getKeySchema<table>>,\n): getKeyTuple<table> {\n return table.key.map((fieldName) =>\n encodeAbiParameters([table.schema[fieldName]], [key[fieldName as never]]),\n ) as never;\n}\n","import { Schema, Table } from \"@latticexyz/config\";\n\ntype PartialTable = Pick<Table, \"schema\" | \"key\">;\n\nexport type getValueSchema<table extends PartialTable> = PartialTable extends table\n ? Schema\n : {\n readonly [fieldName in Exclude<keyof table[\"schema\"], table[\"key\"][number]>]: table[\"schema\"][fieldName];\n };\n\nexport function getValueSchema<table extends PartialTable>(table: table): getValueSchema<table> {\n return Object.fromEntries(\n Object.entries(table.schema).filter(([fieldName]) => !table.key.includes(fieldName)),\n ) as getValueSchema<table>;\n}\n","import { Schema } from \"@latticexyz/config\";\nimport { mapObject } from \"@latticexyz/common/utils\";\n\nexport type getSchemaTypes<schema extends Schema> = {\n readonly [fieldName in keyof schema]: schema[fieldName][\"type\"];\n};\n\nexport function getSchemaTypes<schema extends Schema>(schema: schema): getSchemaTypes<schema> {\n return mapObject(schema, (value) => value.type);\n}\n"],"mappings":"AAAA,OAAuD,oBAAAA,MAAwB,mCAGxE,SAASC,GAAiBC,EAAmC,CAClE,IAAMC,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EAAM,MAAM,EACrB,OAAQE,GAAc,CAACF,EAAM,IAAI,SAASE,CAAS,CAAC,EACpD,IAAKA,GAAc,CAACA,EAAWD,EAAOC,CAAS,CAAC,CAAC,CACtD,CACF,CCfA,OAAS,oBAAAC,GAAkB,mBAAAC,OAAuB,mCAG3C,SAASC,GACdC,EACAC,EACQ,CAUR,MATmB,CACjB,GAAG,OAAO,QAAQD,CAAW,EAC1B,OAAO,CAAC,CAAC,CAAEE,CAAS,IAAMJ,GAAgBI,CAAS,CAAC,EACpD,IAAI,CAAC,CAACD,CAAS,IAAMA,CAAS,EACjC,GAAG,OAAO,QAAQD,CAAW,EAC1B,OAAO,CAAC,CAAC,CAAEE,CAAS,IAAML,GAAiBK,CAAS,CAAC,EACrD,IAAI,CAAC,CAACD,CAAS,IAAMA,CAAS,CACnC,EAEkB,QAAQA,CAAS,CACrC,CCIO,SAASE,GAAyCC,EAAmC,CAC1F,OAAO,OAAO,YAAYA,EAAM,IAAI,IAAKC,GAAc,CAACA,EAAWD,EAAM,OAAOC,CAAS,CAAC,CAAC,CAAC,CAC9F,CCvBA,OAAc,uBAAAC,OAA2B,OAWlC,SAASC,GACdC,EACAC,EACoB,CACpB,OAAOD,EAAM,IAAI,IAAKE,GACpBJ,GAAoB,CAACE,EAAM,OAAOE,CAAS,CAAC,EAAG,CAACD,EAAIC,CAAkB,CAAC,CAAC,CAC1E,CACF,CCRO,SAASC,GAA2CC,EAAqC,CAC9F,OAAO,OAAO,YACZ,OAAO,QAAQA,EAAM,MAAM,EAAE,OAAO,CAAC,CAACC,CAAS,IAAM,CAACD,EAAM,IAAI,SAASC,CAAS,CAAC,CACrF,CACF,CCbA,OAAS,aAAAC,OAAiB,2BAMnB,SAASC,GAAsCC,EAAwC,CAC5F,OAAOF,GAAUE,EAASC,GAAUA,EAAM,IAAI,CAChD","names":["isDynamicAbiType","abiTypesToSchema","abiTypes","staticFields","dynamicFields","abiType","hexToString","sliceHex","assertExhaustive","arrayToStaticAbiType","staticAbiTypeToByteLength","getAddress","hexToBigInt","hexToBool","assertExhaustive","staticAbiTypeToByteLength","staticAbiTypeToDefaultValue","MUDError","staticAbiTypeToByteLength","InvalidHexLengthError","value","InvalidHexLengthForSchemaError","InvalidHexLengthForEncodedLengthsError","InvalidHexLengthForStaticFieldError","abiType","InvalidHexLengthForArrayFieldError","SchemaStaticLengthMismatchError","schemaData","definedLength","summedLength","EncodedLengthsLengthMismatchError","encodedLengthsData","decodeStaticField","abiType","data","InvalidHexLengthError","staticAbiTypeToByteLength","InvalidHexLengthForStaticFieldError","value","hexToBigInt","defaultValueType","staticAbiTypeToDefaultValue","hexToBool","getAddress","assertExhaustive","decodeDynamicField","abiType","data","hexToString","InvalidHexLengthError","dataSize","staticAbiType","arrayToStaticAbiType","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","hexToEncodedLengths","data","InvalidHexLengthForEncodedLengthsError","totalByteLength","decodeStaticField","reversedFieldByteLengths","decodeDynamicField","fieldByteLengths","summedLength","total","length","EncodedLengthsLengthMismatchError","staticAbiTypeToByteLength","staticDataLength","staticFields","length","fieldType","readHex","decodeRecord","valueSchema","data","values","bytesOffset","fieldType","fieldByteLength","staticAbiTypeToByteLength","value","decodeStaticField","schemaStaticDataLength","staticDataLength","actualStaticDataLength","dataLayout","hexToEncodedLengths","i","dataLength","decodeDynamicField","dynamicAbiTypeToDefaultValue","actualDynamicDataLength","isStaticAbiType","isDynamicAbiType","decodeValue","valueSchema","data","staticFields","isStaticAbiType","dynamicFields","isDynamicAbiType","valueTuple","decodeRecord","name","i","concatHex","padHex","isStaticAbiType","readHex","decodeValueArgs","valueSchema","staticData","encodedLengths","dynamicData","decodeValue","concatHex","staticDataLength","isStaticAbiType","padHex","arrayToStaticAbiType","isArrayAbiType","encodePacked","encodeField","fieldType","value","staticFieldType","isStaticAbiType","encodeAbiParameters","encodeKeyTuple","keySchema","keyTuple","key","index","encodeKey","keySchema","key","staticFields","isStaticAbiType","encodeKeyTuple","encodeRecord","valueSchema","values","staticValues","dynamicValues","staticData","value","i","encodeField","dynamicDataItems","dynamicFieldByteLengths","dynamicTotalByteLength","total","length","dynamicData","encodedLengths","concatHex","isStaticAbiType","isDynamicAbiType","concatHex","concatHex","padHex","size","encodeLengths","values","byteLengths","size","totalByteLength","total","length","padHex","concatHex","encodeField","encodeValueArgs","valueSchema","value","valueSchemaEntries","staticFields","type","isStaticAbiType","dynamicFields","isDynamicAbiType","encodedStaticValues","name","encodeField","encodedDynamicValues","encodedLengths","encodeLengths","concatHex","encodeValue","valueSchema","value","staticData","encodedLengths","dynamicData","encodeValueArgs","concatHex","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","keySchema","schemaToHex","isStaticAbiType","schemaIndexToAbiType","schema","schemaIndex","isDynamicAbiType","isStaticAbiType","staticAbiTypeToByteLength","valueSchemaToFieldLayoutHex","valueSchema","staticFields","dynamicFields","staticFieldLengths","fieldType","dataLength","fieldLength","isDynamicAbiType","isStaticAbiType","valueSchemaToHex","valueSchema","schemaToHex","isStaticAbiType","isDynamicAbiType","getKey","table","record","fieldName","getValue","table","record","fieldName","isDynamicAbiType","isStaticAbiType","getFieldIndex","valueSchema","fieldName","fieldType","getKeySchema","table","fieldName","encodeAbiParameters","getKeyTuple","table","key","fieldName","getValueSchema","table","fieldName","mapObject","getSchemaTypes","schema","value"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/protocol-parser",
3
- "version": "2.2.16",
3
+ "version": "2.2.17-03eae1330cef5cae129841958fb75541ef13fb43",
4
4
  "description": "Parser utilities for the MUD protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,9 +28,9 @@
28
28
  ],
29
29
  "dependencies": {
30
30
  "abitype": "1.0.6",
31
- "@latticexyz/common": "2.2.16",
32
- "@latticexyz/config": "2.2.16",
33
- "@latticexyz/schema-type": "2.2.16"
31
+ "@latticexyz/common": "2.2.17-03eae1330cef5cae129841958fb75541ef13fb43",
32
+ "@latticexyz/schema-type": "2.2.17-03eae1330cef5cae129841958fb75541ef13fb43",
33
+ "@latticexyz/config": "2.2.17-03eae1330cef5cae129841958fb75541ef13fb43"
34
34
  },
35
35
  "devDependencies": {
36
36
  "viem": "2.21.19",