@zktx.io/sui-move-builder 0.2.2 → 0.2.4

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/README.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # @zktx.io/sui-move-builder
2
2
 
3
- > **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (tag: `testnet-v1.63.1`)
3
+ > **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (tag: `v1.63.3`)
4
4
 
5
5
  Build Move packages in web or Node.js with Sui CLI-compatible dependency resolution and compilation.
6
6
 
7
7
  ## Features
8
8
 
9
9
  - ✅ **Sui CLI Compatible**: Identical dependency resolution algorithm as Sui CLI
10
- - ✅ **Lockfile Support**: Reads `Move.lock` for faster, deterministic builds
10
+ - ✅ **Verified Parity**: Audited against `sui-04dd` source code (Jan 2026), byte-level module comparison
11
+ - ✅ **Address Resolution**: Supports `original_id` for compilation, `published_at` for metadata (CLI-identical)
12
+ - ✅ **Lockfile Support**: Reads `Move.lock` v0/v3/v4 for faster, deterministic builds
13
+ - ✅ **Published.toml Support**: Reads deployment records per environment
11
14
  - ✅ **Per-Package Editions**: Each package can use its own Move edition (legacy, 2024.alpha, 2024.beta)
12
15
  - ✅ **Monorepo Support**: Handles local dependencies in monorepo structures
13
16
  - ✅ **Version Conflict Detection**: Matches Sui CLI behavior for conflicting dependency versions
@@ -15,6 +18,9 @@ Build Move packages in web or Node.js with Sui CLI-compatible dependency resolut
15
18
  - ✅ **GitHub Integration**: Fetches dependencies directly from git repositories
16
19
  - ✅ **GitHub Token Support**: Optional token to raise rate limits (API calls only; raw fetch remains CORS-safe)
17
20
 
21
+ > 📖 For detailed CLI behavior documentation, see [CLI_PIPELINE.md](./CLI_PIPELINE.md)
22
+
23
+
18
24
  ## Install
19
25
 
20
26
  ```bash
@@ -141,7 +147,7 @@ name = "my_package"
141
147
  edition = "2024.beta"
142
148
 
143
149
  [dependencies]
144
- deepbook = { git = "https://github.com/MystenLabs/deepbookv3.git", subdir = "packages/deepbook", rev = "main" }
150
+ dep_name = { git = "https://github.com/org/repo.git", subdir = "packages/dep_name", rev = "main" }
145
151
  `,
146
152
  "sources/main.move": "...",
147
153
  };
@@ -242,3 +248,27 @@ if (entry.name === "build" || entry.name === ".git") continue;
242
248
  npm run serve:test # serves ./test via python -m http.server
243
249
  # open http://localhost:8000/test/index.html
244
250
  ```
251
+
252
+ ## Fidelity Tests
253
+
254
+ This package includes byte-level comparison tests against the official Sui CLI output:
255
+
256
+ ```bash
257
+ npm run test:lite # Run fidelity tests (lite version)
258
+ npm test # Run full integration tests
259
+ ```
260
+
261
+ **Test Cases (verified against Sui CLI):**
262
+ - `nautilus.enclave` - Simple package with framework dependencies
263
+ - `apps.kiosk` - Mysten Labs kiosk package
264
+ - `deeptrade-core` - Complex package with Pyth/Deepbook dependencies
265
+
266
+ All tests verify:
267
+ - ✅ Module bytecode (identical to CLI `.mv` output)
268
+ - ✅ Dependency IDs (exact match with CLI)
269
+ - ✅ Dependency order (lexicographical, CLI-consistent)
270
+
271
+ ## Roadmap
272
+
273
+ - **Return Build Artifacts**: Future updates will include generating and returning `Move.lock` and `Published.toml` files to the caller, facilitating deployment tracking and deterministic rebuilds.
274
+
@@ -1,28 +1,24 @@
1
- "use strict";var E=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(d,e)=>{for(var t in e)R(d,t,{get:e[t],enumerable:!0})},G=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of V(e))!q.call(d,n)&&n!==t&&R(d,n,{get:()=>e[n],enumerable:!(s=z(e,n))||s.enumerable});return d};var K=(d,e,t)=>(t=d!=null?E(H(d)):{},G(e||!d||!d.__esModule?R(t,"default",{value:d,enumerable:!0}):t,d)),Q=d=>G(R({},"__esModule",{value:!0}),d);var ae={};J(ae,{buildMovePackage:()=>te,compileRaw:()=>oe,fetchPackageFromGitHub:()=>_,getSuiMoveVersion:()=>se,getSuiVersion:()=>ie,getWasmBindings:()=>re,initMoveCompiler:()=>ee,resolveDependencies:()=>L,testMovePackage:()=>ne});module.exports=Q(ae);var x=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends x{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let s=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");s&&(this.rateLimitRemaining=parseInt(s,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,s,n,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let l of a.tree){if(l.type!=="blob")continue;let p=l.path;if(n){if(!l.path.startsWith(n))continue;p=l.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${l.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let l=g["Move.toml"].trim();if(l.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!l.includes("[")&&!l.includes("=")){let p=l,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(c)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let c=await i.text();return this.cache.set(t,c),c}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function M(d){let e=!1,t="";for(let s=0;s<d.length;s++){let n=d[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return d.slice(0,s)}return d}function F(d){let e=d.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function C(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=F(a)}return e}function X(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(B(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(B(s.trim())),e}function B(d){return d.startsWith("{")?C(d):F(d)}function w(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=M(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+M(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+M(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=M(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let l=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=C(p):p.startsWith("[")?m=X(p):m=F(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[l]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?l.replace(/-/g,"_"):l;h[v]=m}}return e}var D=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib","SuiSystem","Bridge"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,s){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,s=new Set,n=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)n(c)};return n(e),t.delete(e),t}topologicalOrder(){if(!this.lockfileOrder.length)return this.topologicalOrderDFS().filter(i=>i!==this.root);let e=new Set,t=new Set,s=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))s(i);t.push(n)};s(this.root);for(let n of this.packageTable.keys())s(n);return t}detectCycle(){let e=new Set,t=new Set,s=new Map,n=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);if(i)return i}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var A=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let s of t){let n=this.graph.getPackage(s);if(n)for(let[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=i;this.packageResolvedTables.set(s.id.name,n),s.resolvedTable=n}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,s]of this.unifiedAddressTable.entries())e[t]=s;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var I=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let s=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.topologicalOrder(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}extractSourcePaths(e,t){let s=Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move")),n=new TextEncoder,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
2
- `),i=[],c=[],o=!1,u=!1;for(let l of r){let p=l.trim();if(p.startsWith("[package]")){o=!0,u=!1;continue}if(p.startsWith("[dependencies]")){o=!1,u=!0;continue}if(p.startsWith("[")){o=!1,u=!1;continue}o&&p&&i.push(l),u&&p&&c.push(l)}let a=`[package]
3
- `,g=!1,f=!1;for(let l of i)if(l.includes("name ="))a+=l+`
4
- `,g=!0;else if(l.includes("version ="))a+=l+`
5
- `,f=!0;else{if(l.includes("edition ="))continue;a+=l+`
6
- `}g||(a+=`name = "${e}"
7
- `),f||(a+=`version = "0.0.0"
8
- `),a+=`edition = "${s}"
1
+ "use strict";var J=Object.create;var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var Y=(d,e)=>{for(var t in e)x(d,t,{get:e[t],enumerable:!0})},j=(d,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of q(e))!X.call(d,s)&&s!==t&&x(d,s,{get:()=>e[s],enumerable:!(i=K(e,s))||i.enumerable});return d};var Z=(d,e,t)=>(t=d!=null?J(Q(d)):{},j(e||!d||!d.__esModule?x(t,"default",{value:d,enumerable:!0}):t,d)),ee=d=>j(x({},"__esModule",{value:!0}),d);var ge={};Y(ge,{buildMovePackage:()=>re,compileRaw:()=>le,fetchPackageFromGitHub:()=>z,getSuiMoveVersion:()=>ae,getSuiVersion:()=>ce,getWasmBindings:()=>de,initMoveCompiler:()=>ie,resolveDependencies:()=>G,testMovePackage:()=>oe});module.exports=ee(ge);var N=class{async fetch(e,t,i){throw new Error("Not implemented")}async fetchFile(e,t,i){throw new Error("Not implemented")}},A=class extends N{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let i=t.headers.get("x-ratelimit-remaining"),s=t.headers.get("x-ratelimit-reset");i&&(this.rateLimitRemaining=parseInt(i,10)),s&&(this.rateLimitReset=parseInt(s,10)*1e3)}async fetch(t,i,s,n){let{owner:r,repo:o}=this.parseGitUrl(t);if(!r||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${r}/${o}@${i}`,p=`https://api.github.com/repos/${r}/${o}/git/trees/${i}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let b=Math.pow(2,h-1)*1e3;await new Promise(k=>setTimeout(k,b))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:y});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&h<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let l=new Map,u={},g=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(s){if(!m.path.startsWith(s))continue;f=m.path.slice(s.length),f.startsWith("/")&&(f=f.slice(1))}if(!f.endsWith(".move")&&f!=="Move.toml"&&f!=="Move.lock"&&!f.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;f==="Move.toml"&&m.mode&&l.set("Move.toml",m.mode);let h=`https://raw.githubusercontent.com/${r}/${o}/${i}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(u[f]=v)});g.push(y)}if(await Promise.all(g),u["Move.toml"]&&l.get("Move.toml")==="120000"){let f=u["Move.toml"].trim(),h=s?`${s}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${i}/${h}`,v=await this.fetchContent(y);v&&(u["Move.toml"]=v)}return u}async fetchFile(t,i,s){let{owner:n,repo:r}=this.parseGitUrl(t);if(!n||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${n}/${r}/${i}/${s}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let i={},s=typeof window<"u",n=t.startsWith("https://api.github.com/");this.token&&(!s||n)&&(i.Authorization=`Bearer ${this.token}`);let r=await fetch(t,{headers:i});if(!r.ok)return null;let o=await r.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let s=new URL(t).pathname.split("/").filter(n=>n);if(s.length>=2){let n=s[1];return n.endsWith(".git")&&(n=n.slice(0,-4)),{owner:s[0],repo:n}}}catch{}return{owner:null,repo:null}}};function F(d){let e=!1,t="";for(let i=0;i<d.length;i++){let s=d[i];if((s==='"'||s==="'")&&(!e||s===t)&&(e=!e,t=s),!e&&s==="#")return d.slice(0,i)}return d}function C(d){let e=d.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function U(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),i="",s=!1,n="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!s||a===n)&&(s=!s,n=a),!s&&a===","){r.push(i),i="";continue}i+=a}i.trim()&&r.push(i);for(let o of r){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=C(c)}return e}function te(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),i="",s=!1,n="",r=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!s||a===n)&&(s=!s,n=s?a:""),!s&&(a==="{"&&r++,a==="}"&&r--,a===","&&r===0)){i.trim()&&e.push(_(i.trim())),i="";continue}i+=a}return i.trim()&&e.push(_(i.trim())),e}function _(d){return d.startsWith("{")?U(d):C(d)}function S(d){let e={},t=null,i=!1,s=d.split(/\r?\n/),n=[],r=0;for(;r<s.length;){let a=F(s[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<s.length&&!p.includes("]");)p+=" "+F(s[r]).trim(),r++;r<s.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+F(s[r]).trim(),r++),n.push(p)}else n.push(a),r++}function o(a,p){let c=a;for(let l of p){if(!(l in c))return;c=c[l]}return c}for(let a of n){let p=F(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),i=!0;let h=t.split("."),y=e;for(let b=0;b<h.length-1;b++){let k=h[b];k in y||(y[k]={}),y=y[k]}let v=h[h.length-1];Array.isArray(y[v])||(y[v]=[]),y[v].push({});continue}let l=p.match(/^\[([^\]]+)\]$/);if(l){t=l[1].trim(),i=!1;continue}let u=p.indexOf("=");if(u===-1||!t)continue;let g=p.slice(0,u).trim(),m=p.slice(u+1).trim(),f;if(m.startsWith("{")?f=U(m):m.startsWith("[")?f=te(m):f=C(m),i){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[g]=f}}else{let h=t.split("."),y=e;for(let b of h)b in y||(y[b]={}),y=y[b];let v=t==="package"?g.replace(/-/g,"_"):g;y[v]=f}}return e}var O=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,i){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,i=new Set,s=n=>{if(i.has(n))return;i.add(n),t.add(n);let r=this.graph.get(n);if(r)for(let o of r)s(o)};return s(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n){let r=Array.from(n).sort();for(let o of r)i(o)}t.push(s)};return i(this.root),t.filter(s=>s!==this.root)}compilerInputOrder(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n){let r=Array.from(n).sort();for(let o of r)i(o)}t.push(s)};return i(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n)for(let r of Array.from(n))i(r);t.push(s)};i(this.root);for(let s of this.packageTable.keys())i(s);return t}detectCycle(){let e=new Set,t=new Set,i=new Map,s=n=>{e.add(n),t.add(n);let r=this.graph.get(n);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=n;for(;p!==o;)a.unshift(p),p=i.get(p);return a.unshift(o),a}}else{i.set(o,n);let a=s(o);if(a)return a}return t.delete(n),null};for(let n of this.packageTable.keys())if(!e.has(n)){let r=s(n);if(r)return r}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var $=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let i of t){let s=this.graph.getPackage(i);if(s)for(let[n,r]of Object.entries(s.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(n)&&this.unifiedAddressTable.get(n)!==o||this.unifiedAddressTable.set(n,o)}}for(let i of this.graph.getAllPackages()){let s={};for(let[n,r]of this.unifiedAddressTable.entries())s[n]=r;this.packageResolvedTables.set(i.id.name,s),i.resolvedTable=s}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,i]of this.unifiedAddressTable.entries())e[t]=i;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}compilerInputOrder(){return this.graph.compilerInputOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var T=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let i=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),s=this.resolvedGraph.compilerInputOrder(),n=new Map;for(let r of s){if(r===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(r);if(!o)continue;let a=e.get(r)||{},p=this.extractSourcePaths(r,a),c=o.manifest.edition||"legacy",l=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],u=o.manifest.originalId;!u&&o.manifest.publishedAt&&(u=o.manifest.publishedAt),u||(u="0x0000000000000000000000000000000000000000000000000000000000000000",l||(l=u)),n.set(r,u),n.set(r.toLowerCase(),u);let g={...o.resolvedTable||{}};for(let[f,h]of Object.entries(g)){let y=n.get(f)||n.get(f.toLowerCase());y&&(g[f]=y)}u&&r!=="Sui"&&r!=="MoveStdlib"&&(g[r]=u,g[r.toLowerCase()]=u);let m={name:r,isImmediate:i.has(r),sourcePaths:p,addressMapping:g,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:l};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}extractSourcePaths(e,t){return Object.keys(t).filter(s=>s.endsWith("Move.toml")||s.endsWith("Move.lock")?!1:s.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let i of this.dependencies){let s=e.get(i.name)||{},n={};for(let[r,o]of Object.entries(s)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${i.name}/${r}`;r.endsWith("Move.toml")?n[a]=this.reconstructDependencyMoveToml(i.name,o,i.edition,i.addressMapping):n[a]=o}t.push({name:i.name,files:n,edition:i.edition,addressMapping:i.addressMapping,publishedIdForOutput:i.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,i,s){let n=(t||"").split(`
2
+ `),r=[],o="none";for(let c of n){let l=c.trim();if(l.startsWith("[")){l.startsWith("[package]")?o="package":l.startsWith("[addresses]")?o="addresses":l.startsWith("[dependencies")||l.startsWith("[dev-dependencies")?o="dependencies":(o="other",r.push(c));continue}if(o==="package")(l.startsWith("name")||l.startsWith("version")||l.startsWith("edition")||l.startsWith("published-at")||l.startsWith("original-published-id"))&&(l.startsWith("published-at")||l.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
3
+ `;a+=`name = "${e}"
4
+ `,a+=`version = "0.0.0"
5
+ `,a+=`edition = "${i}"
9
6
  `,a+=`
10
- [dependencies]
11
- `;for(let l of c)a+=l+`
12
- `;a+=`
7
+ `,a+=r.join(`
8
+ `),a+=`
13
9
  [addresses]
14
- `;for(let[l,p]of Object.entries(n))a+=`${l} = "${p}"
15
- `;return a}};var T=class{constructor(e,t="mainnet",s=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=s}async resolve(e,t){let s=w(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new D(n),c=await this.buildPackage(n,this.rootSource,e,t);r&&(c.manifest.edition=r);let o=c.manifest.addresses[n];this.normalizeAddress(o||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&c.manifest.originalId&&(c.manifest.addresses[n]=this.normalizeAddress(c.manifest.originalId)),i.addPackage(c),this.packageFiles.set(n,t);let a=await this.loadFromLockfile(i,c,t),g=Array.from(c.dependencies.keys()).filter(v=>!i.getPackage(v));(!a||g.length>0)&&await this.buildDependencyGraph(i,c);let f=i.detectCycle();if(f)throw new Error(`Dependency cycle detected: ${f.join(" \u2192 ")}`);let l=new A(i,{});await l.resolve();let p=new I(l);await p.compute(this.packageFiles);let m=this.reconstructMoveToml(s,l.getUnifiedAddressTable(),!0,r),y={...t};delete y["Move.lock"],y["Move.toml"]=m;let h=p.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(h)}}async buildPackage(e,t,s,n){let r=w(s),i=n["Move.lock"],c=this.getChainIdForNetwork(this.network),o=this.resolvePublishedAt(s,i,c),u=o.latestId?this.normalizeAddress(o.latestId):void 0,a=n["Published.toml"],g,f;if(a)try{let b=w(a).published?.[this.network];b&&(b["published-at"]&&(g=this.normalizeAddress(b["published-at"])),b["original-id"]&&(f=this.normalizeAddress(b["original-id"])))}catch{}o.error;let l={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:g||o.publishedAt,originalId:f||o.originalId,latestPublishedId:u,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},p=l.publishedAt&&l.publishedAt!=="0x0"?this.normalizeAddress(l.publishedAt):void 0,m=l.addresses[l.name],y=m?this.normalizeAddress(m):void 0;p?l.addresses[l.name]=p:y?l.addresses[l.name]=y:l.addresses[l.name]="0x0";let h=new Map;if(l.dependencies)for(let[k,b]of Object.entries(l.dependencies)){let N=this.parseDependencyInfo(b);N&&h.set(k,N)}return{id:{name:l.name,version:l.version,source:t||{type:"local"}},manifest:l,dependencies:h,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir};else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let s=e["addr-subst"]||e.addr_subst,n={};for(let[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){for(let[s,n]of t.dependencies.entries()){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let g=t.id.source.subdir||"",f=n.source.local,l=this.resolveRelativePath(g,f);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:l}}else continue;if(n.source.type!=="git")continue;let r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,n.source);g&&e.addDependency(t.id.name,g.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let c=await this.fetcher.fetch(n.source.git,n.source.rev,i),o=null,u=`Move.${this.network}.toml`;for(let[g,f]of Object.entries(c))if(g.endsWith(u)){o=f;break}if(!o){for(let[g,f]of Object.entries(c))if(g.endsWith("Move.toml")){o=f;break}}if(!o)continue;let a=await this.buildPackage(s,n.source,o,c);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(a.manifest.name);if(g){let f=l=>JSON.stringify(l);throw new Error([`Conflicting versions of package '${a.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
16
- `))}this.packageNameCache.set(a.manifest.name,n.source)}a.manifest.publishedAt&&(a.manifest.addresses[a.manifest.name]=this.normalizeAddress(a.manifest.publishedAt)),a.manifest.edition||(a.manifest.edition="legacy"),e.addPackage(a),e.addDependency(t.id.name,a.id.name,n),this.packageFiles.set(a.id.name,c),await this.buildDependencyGraph(e,a)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s){let n=w(e),r=n.package?.published_at||n.package?.["published-at"],i=r&&r!=="0x0"?r:void 0,c=i?this.normalizeAddress(i):void 0,o=n.package?.["original-id"];return{publishedAt:c,originalId:o}}findPackageBySource(e,t){for(let s of e.getAllPackages()){let n=s.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return s}}resolveRelativePath(e,t){let s=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.join("/")}async computeManifestDigest(e){let s=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=w(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(a=>a.name||a.id||a).filter(Boolean):[],i=n.map(a=>a.name||a.id).filter(Boolean),c=[...r,...i.filter(a=>!r.includes(a))],o=new Map,u=new Map;for(let a of n){let g=a.id||a.name,f=a.source;if(!g||!f)continue;let l=null;if(f.git&&f.rev)l={type:"git",git:f.git,rev:f.rev,subdir:f.subdir};else if(f.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",f.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let p=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(p).length===0)continue;let m=p["Move.toml"];if(!m)continue;let y=await this.buildPackage(g,l,m,p);o.set(g,y),u.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,p),e.addPackage(y)}c.length&&e.setLockfileOrder(c);for(let a of n){let g=a.id||a.name,f=o.get(g);if(!f)continue;let l=a.dependencies;if(l&&Array.isArray(l))for(let p of l){let m=p.id||p.name,y=o.get(m)||u.get(m);if(y){let h={source:y.id.source};e.addDependency(f.id.name,y.id.name,h)}}}for(let a of s.dependencies.keys()){let g=u.get(a);if(g){let f=s.dependencies.get(a);e.addDependency(s.id.name,g.id.name,f)}}return o.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,c=[];for(let o of n)o.id&&i.set(o.id,o);for(let o of n){let u=o.id,a=o.source;c.push(u);let g=null;if(a?.git&&a.rev)g={type:"git",git:a.git,rev:a.rev,subdir:a.subdir};else if(a?.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",a.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;if(!g.git||!g.rev)continue;let f=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(f).length===0)continue;let l=f["Move.toml"];if(!l)continue;let p=await this.buildPackage(u,g,l,f);r.set(u,p),this.packageFiles.set(p.manifest.name,f),e.addPackage(p)}e.setLockfileOrder(c);for(let o of n){let u=o.id,a=r.get(u);if(!a)continue;let g=o.dependencies;if(!(!g||!Array.isArray(g)))for(let f of g){let l=f.id,p=r.get(l);if(!p){let m=i.get(l);if(m?.source?.local&&a.id.source.type==="git"){let y=this.resolveRelativePath(a.id.source.subdir||"",m.source.local),h={type:"git",git:a.id.source.git,rev:a.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),k=v["Move.toml"];if(k){let b=await this.buildPackage(l,h,k,v);r.set(l,b),this.packageFiles.set(b.manifest.name,v),e.addPackage(b),p=b}}}if(p){let m={source:p.id.source};e.addDependency(a.id.name,p.id.name,m)}}}for(let o of s.dependencies.keys()){let u=r.get(o);if(u){let a=s.dependencies.get(o);e.addDependency(s.id.name,u.id.name,a)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let c=new Map,o=new Map,u=[];for(let[a,g]of Object.entries(r)){u.push(a);let f=this.lockfileSourceToDependencySource(g.source);if(!f)continue;let l=await this.fetchFromSource(f);if(!l)return!1;let p=l["Move.toml"];if(!p||g["manifest-digest"]&&await this.computeManifestDigest(p)!==g["manifest-digest"])return!1;let m=await this.buildPackage(a,f,p,l);c.set(a,m),o.set(m.manifest.name,m),this.packageFiles.set(m.manifest.name,l),(f.type!=="local"||!("root"in g.source))&&e.addPackage(m)}u.length>0&&e.setLockfileOrder(u);for(let[a,g]of Object.entries(r)){let f=c.get(a);if(f&&g.deps)for(let[l,p]of Object.entries(g.deps)){let m=c.get(p);if(m){let y=f.dependencies.get(l);y&&e.addDependency(f.id.name,m.id.name,y)}}}for(let a of n.dependencies.keys()){let g=o.get(a)||c.get(a);if(g){let f=n.dependencies.get(a);e.addDependency(n.id.name,g.id.name,f)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
10
+ `;let p=Object.entries(s);for(let[c,l]of p)a+=`${c} = "${l}"
11
+ `;return a}};var W=class{constructor(e,t="mainnet",i=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=i}async resolve(e,t){let i=S(e),s=i.package?.name||"RootPackage",n=i.package?.edition,r=new O(s),o=await this.buildPackage(s,this.rootSource,e,t);n&&(o.manifest.edition=n);let a=o.manifest.addresses[s];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[s]=this.normalizeAddress(o.manifest.originalId)),r.addPackage(o),this.packageFiles.set(s,t);let c=await this.loadFromLockfile(r,o,t),l=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||l.length>0)&&await this.buildDependencyGraph(r,o);let u=r.detectCycle();if(u)throw new Error(`Dependency cycle detected: ${u.join(" \u2192 ")}`);let g=new $(r,{});await g.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new T(g);await f.compute(this.packageFiles);let h=g.getUnifiedAddressTable();for(let k of r.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name===o.manifest.name){let P=Object.keys(k.manifest.addresses).find(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}let M=Object.keys(k.manifest.addresses).find(P=>P.toLowerCase()===k.manifest.name.toLowerCase());if(M&&k.manifest.addresses[M]){let P=this.normalizeAddress(k.manifest.addresses[M]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(i,o.manifest.dependencies,h,!0,n),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,i,s){let n=S(i),r=s["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(i,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=s["Published.toml"],l,u;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(l=this.normalizeAddress(I["published-at"])),I["original-id"]&&(u=this.normalizeAddress(I["original-id"])))}catch{}a.error;let g={name:n.package?.name||e,version:n.package?.version||"0.0.0",edition:n.package?.edition,publishedAt:l||a.publishedAt,originalId:u||a.originalId,latestPublishedId:p,addresses:n.addresses||{},dependencies:this.injectImplicitDependencies(n.dependencies||{},n.package?.name),devDependencies:n["dev-dependencies"]},m=Object.keys(g.addresses).find(w=>w.toLowerCase()===g.name.toLowerCase());if(m&&g.addresses[m]){let w=this.normalizeAddress(g.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(g.originalId=w)}let f=g.originalId||g.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=g.addresses[g.name]||(m?g.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(g.addresses[g.name]=h):v?g.addresses[g.name]=v:g.addresses[g.name]="0x0";let b=new Map;if(g.dependencies)for(let[w,I]of Object.entries(g.dependencies)){let M=this.parseDependencyInfo(I);M&&b.set(w,M)}return{id:{name:g.name,version:g.version,source:t||{type:"local"}},manifest:g,dependencies:b,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir},e.isImplicit&&(t.source.isImplicit=!0);else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let i=e["addr-subst"]||e.addr_subst,s={};for(let[n,r]of Object.entries(i))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?s[n]={type:"assign",address:r}:s[n]={type:"renameFrom",name:r});Object.keys(s).length>0&&(t.subst=s)}return t}async buildDependencyGraph(e,t){let i=Array.from(t.dependencies.entries()).sort(([,s],[,n])=>{let r=s.source.isImplicit?1:0;return(n.source.isImplicit?1:0)-r});for(let[s,n]of i){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let u=t.id.source.subdir||"",g=n.source.local,m=this.resolveRelativePath(u,g);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}else continue;if(n.source.type!=="git")continue;let r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let u=this.findPackageBySource(e,n.source);u&&e.addDependency(t.id.name,u.id.name,n);continue}this.visited.add(r);let o=n.source.subdir;!o&&n.source.git&&this.isSuiRepo(n.source.git)&&(o=this.inferSuiFrameworkSubdir(s),o&&(n.source.subdir=o));let a=await this.fetcher.fetch(n.source.git,n.source.rev,o),p=null,c=`Move.${this.network}.toml`;for(let[u,g]of Object.entries(a))if(u.endsWith(c)){p=g;break}if(!p){for(let[u,g]of Object.entries(a))if(u.endsWith("Move.toml")){p=g;break}}if(!p)continue;let l=await this.buildPackage(s,n.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let u=this.packageNameCache.get(l.manifest.name);if(u){let g=u.isImplicit,m=n.source.isImplicit;if(g&&!m)continue;if(!(!g&&m)){if(JSON.stringify(u)!==JSON.stringify(n.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${l.manifest.name}' found`,`Existing: ${f(u)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
12
+ `))}}}this.packageNameCache.set(l.manifest.name,n.source)}l.manifest.edition||(l.manifest.edition="legacy"),e.addPackage(l),e.addDependency(t.id.name,l.id.name,n),this.packageFiles.set(l.id.name,a),await this.buildDependencyGraph(e,l)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,i,s){let n=S(e),r=n.package?.published_at||n.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=n.package?.["original-id"],c,l;if(t)try{let f=S(t),h=i&&f.env?.[i]||f.env?.[s];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(l=this.normalizeAddress(h["latest-published-id"])))}catch{}let u=a||l||c;return{publishedAt:u,originalId:p||c,latestId:u}}findPackageBySource(e,t){for(let i of e.getAllPackages()){let s=i.id.source;if(s.type===t.type&&s.git===t.git&&s.rev===t.rev&&s.subdir===t.subdir)return i}}resolveRelativePath(e,t){let i=e?e.split("/").filter(Boolean):[],s=t.split("/").filter(Boolean),n=[...i];for(let r of s)r===".."?n.length>0&&n.pop():r!=="."&&n.push(r);return n.join("/")}async computeManifestDigest(e){let i=new TextEncoder().encode(e),s=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(s)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,i){let s=i["Move.lock"];if(!s)return!1;let n=S(s);this.lockfileVersion=n.move?.version;let r=n.move?.version;return r===3?await this.loadFromLockfileV3(e,n,t):r&&r>=4?n.pinned?await this.loadFromLockfileV4(e,n,i,t):!1:await this.loadFromLockfileV0(e,n,t)}async loadFromLockfileV0(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=s.map(c=>c.name||c.id).filter(Boolean),o=[...n,...r.filter(c=>!n.includes(c))],a=new Map,p=new Map;for(let c of s){let l=c.id||c.name,u=c.source;if(!l||!u)continue;let g=null;if(u.git&&u.rev)g={type:"git",git:u.git,rev:u.rev,subdir:u.subdir};else if(u.local&&this.rootSource?.type==="git"){let y=this.resolveRelativePath(this.rootSource.subdir||"",u.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(l,g,f,m);a.set(l,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of s){let l=c.id||c.name,u=a.get(l);if(!u)continue;let g=c.dependencies;if(g&&Array.isArray(g))for(let m of g){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(u.id.name,h.id.name,y)}}}for(let c of i.dependencies.keys()){let l=p.get(c);if(l){let u=i.dependencies.get(c);e.addDependency(i.id.name,l.id.name,u)}}return a.size>0}async loadFromLockfileV3(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=new Map,r=new Map,o=[];for(let a of s)a.id&&r.set(a.id,a);for(let a of s){let p=a.id,c=a.source;o.push(p);let l=null;if(c?.git&&c.rev)l={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!l.git||!l.rev)continue;let u=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(u).length===0)continue;let g=u["Move.toml"];if(!g)continue;let m=await this.buildPackage(p,l,g,u);n.set(p,m),this.packageFiles.set(m.manifest.name,u),e.addPackage(m)}e.setLockfileOrder(o);for(let a of s){let p=a.id,c=n.get(p);if(!c)continue;let l=a.dependencies;if(!(!l||!Array.isArray(l)))for(let u of l){let g=u.id,m=n.get(g);if(!m){let f=r.get(g);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(g,y,b,v);n.set(g,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of i.dependencies.keys()){let p=n.get(a);if(p){let c=i.dependencies.get(a);e.addDependency(i.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,i,s){let n=t.pinned?.[this.network];if(!n)return!1;let r=i["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,l]of Object.entries(n)){p.push(c);let u=this.lockfileSourceToDependencySource(l.source);if(!u)continue;let g=await this.fetchFromSource(u);if(!g)return!1;let m=g["Move.toml"];if(!m||l["manifest-digest"]&&await this.computeManifestDigest(m)!==l["manifest-digest"])return!1;let f=await this.buildPackage(c,u,m,g);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,g),(u.type!=="local"||!("root"in l.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,l]of Object.entries(n)){let u=o.get(c);if(u&&l.deps)for(let[g,m]of Object.entries(l.deps)){let f=o.get(m);if(f){let h=u.dependencies.get(g);h&&e.addDependency(u.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let l=c.id,u=o.get(l);if(u){let g={source:u.id.source};e.addDependency(s.id.name,u.id.name,g)}}else for(let c of s.dependencies.keys()){let l=a.get(c)||o.get(c);if(l){let u=s.dependencies.get(c);e.addDependency(s.id.name,l.id.name,u)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,i,s,n){let o=`[package]
17
13
  name = "${e.package.name}"
18
14
  version = "${e.package.version}"
19
- `,c=n||e.package.edition;if(c&&(i+=`edition = "${c}"
20
- `),i+=`
15
+ `,a=n||e.package.edition;if(a&&(o+=`edition = "${a}"
16
+ `),o+=`
21
17
  [dependencies]
22
- `,e.dependencies)for(let[o,u]of Object.entries(e.dependencies)){let a=u;a.local?i+=`${o} = { local = "${a.local}" }
23
- `:a.git&&a.rev&&(a.subdir?i+=`${o} = { git = "${a.git}", subdir = "${a.subdir}", rev = "${a.rev}" }
24
- `:i+=`${o} = { git = "${a.git}", rev = "${a.rev}" }
25
- `)}i+=`
18
+ `,t){let c=Object.entries(t);for(let[l,u]of c){let g=u;g.local?o+=`${l} = { local = "${g.local}" }
19
+ `:g.git&&g.rev&&(g.subdir?o+=`${l} = { git = "${g.git}", subdir = "${g.subdir}", rev = "${g.rev}" }
20
+ `:o+=`${l} = { git = "${g.git}", rev = "${g.rev}" }
21
+ `)}}o+=`
26
22
  [addresses]
27
- `;for(let[o,u]of Object.entries(t))i+=`${o} = "${u}"
28
- `;return i}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",DeepBook:"crates/sui-framework/packages/deepbook",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function W(d,e,t,s="mainnet",n){return new T(t,s,n||null).resolve(d,e)}function Y(d){try{let e=new URL(d);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let s=t[0],n=t[1],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function _(d,e){let t=Y(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let s=e?.fetcher||new S(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":c,...o}=i;return o}return i}var O;async function P(d){return O||(O=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),O}function $(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function j(d){if(typeof d!="object"||d===null)throw new Error("Unexpected compile result shape from wasm");let e=d;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function Z(d){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let c=parseInt(n.slice(i,i+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");r.push(c)}return r};try{let t=JSON.parse(d);if(!t.modules||!t.dependencies||!t.digest)throw new Error("missing fields in compiler output");let s=typeof t.digest=="string"?e(t.digest):Array.from(t.digest);return{modules:t.modules,dependencies:t.dependencies,digest:s}}catch(t){return $(t)}}function U(d){try{let e=JSON.parse(d);for(let t of e){let s=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let r=w(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function ee(d){await P(d?.wasm)}async function L(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,s=await W(e,{...d.files,"Move.toml":e},new S(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function te(d){try{let e={};for(let[o,u]of Object.entries(d.files))(o.endsWith(".move")||o.endsWith("Move.toml")||o.endsWith("Move.lock")||o.endsWith("Published.toml"))&&(e[o]=u);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await L(d),s=await P(d.wasm);U(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=j(n),i=r.success(),c=r.output();return i?Z(c):$(c)}catch(e){return $(e)}}async function ne(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await L(d),t=await P(d.wasm);U(e.dependencies);let s=d.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof s.passed=="boolean"&&typeof s.output=="string")return{passed:s.passed,output:s.output};let n=typeof s.passed=="function"?s.passed():s.passed,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return $(e)}}async function se(d){return(await P(d?.wasm)).sui_move_version()}async function ie(d){return(await P(d?.wasm)).sui_version()}async function re(d){return P(d?.wasm)}async function oe(d,e,t){let s=await P(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(d,e,!0):s.compile(d,e,JSON.stringify({silenceWarnings:!1})),r=j(n);return{success:r.success(),output:r.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
23
+ `;let p=Object.entries(i);for(let[c,l]of p)o+=`${c} = "${l}"
24
+ `;return o}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}injectImplicitDependencies(e,t){return t==="Sui"||t==="MoveStdlib"||t==="SuiSystem"||t==="sui"||!e.Sui&&!e.sui&&(e.Sui={git:"https://github.com/MystenLabs/sui.git",subdir:"crates/sui-framework/packages/sui-framework",rev:"framework/mainnet",isImplicit:!0}),e}};async function E(d,e,t,i="mainnet",s){return new W(t,i,s||null).resolve(d,e)}function se(d){try{let e=new URL(d);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let i=t[0],s=t[1],n="main",r;return t.length>=4&&t[2]==="tree"&&(n=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:i,repo:s,ref:n,subdir:r}}catch{return null}}async function z(d,e){let t=se(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let i=e?.fetcher||new A(e?.githubToken),s=e?.includeLock!==!1,n=`https://github.com/${t.owner}/${t.repo}.git`,r=await i.fetch(n,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:n,rev:t.ref,subdir:t.subdir},enumerable:!1}),!s&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var B;async function R(d){return B||(B=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),B}function L(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function V(d){if(typeof d!="object"||d===null)throw new Error("Unexpected compile result shape from wasm");let e=d;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function ne(d,e){let t=i=>{let s=i.startsWith("0x")?i.slice(2):i,n=s.length%2===0?s:`0${s}`,r=[];for(let o=0;o<n.length;o+=2){let a=parseInt(n.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let i=JSON.parse(d);if(!i.modules||!i.dependencies||!i.digest)throw new Error("missing fields in compiler output");let s=typeof i.digest=="string"?t(i.digest):Array.from(i.digest),n=i.dependencies;return e&&(n=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),n.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:i.modules,dependencies:n,digest:s}}catch(i){return L(i)}}function H(d){try{let e=JSON.parse(d);for(let t of e){let i=t.addressMapping?.[t.name]??(()=>{let s=Object.entries(t.files).find(([r])=>r.endsWith("Move.toml"));if(!s)return;let n=S(s[1]);return n.addresses&&n.addresses[t.name]||n.package?.published_at||n.package?.["published-at"]})()}}catch{}}async function ie(d){await R(d?.wasm)}async function G(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,i=await E(e,{...d.files,"Move.toml":e},new A(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:i.files,dependencies:i.dependencies}}async function re(d){try{let e={};for(let[p,c]of Object.entries(d.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await G(d),i=await R(d.wasm);H(t.dependencies);let s=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||s.set(c.publishedIdForOutput,c.name)}catch{}let n=i.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=V(n),o=r.success(),a=r.output();return o?ne(a,s):L(a)}catch(e){return L(e)}}async function oe(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await G(d),t=await R(d.wasm);H(e.dependencies);let i=d.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof i.passed=="boolean"&&typeof i.output=="string")return{passed:i.passed,output:i.output};let s=typeof i.passed=="function"?i.passed():i.passed,n=typeof i.output=="function"?i.output():i.output;return{passed:s,output:n}}catch(e){return L(e)}}async function ae(d){return(await R(d?.wasm)).sui_move_version()}async function ce(d){return(await R(d?.wasm)).sui_version()}async function de(d){return R(d?.wasm)}async function le(d,e,t){let i=await R(t?.wasm),s=t?.ansiColor&&typeof i.compile_with_color=="function"?i.compile_with_color(d,e,!0):i.compile(d,e,JSON.stringify({silenceWarnings:!1})),n=V(s);return{success:n.success(),output:n.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
39
39
  * @example
40
40
  * ```ts
41
41
  * const files = await fetchPackageFromGitHub(
42
- * 'https://github.com/MystenLabs/deepbookv3/tree/main/packages/deepbook'
42
+ * 'https://github.com/org/repo/tree/main/packages/example_package'
43
43
  * );
44
44
  *
45
45
  * // files = {
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
39
39
  * @example
40
40
  * ```ts
41
41
  * const files = await fetchPackageFromGitHub(
42
- * 'https://github.com/MystenLabs/deepbookv3/tree/main/packages/deepbook'
42
+ * 'https://github.com/org/repo/tree/main/packages/example_package'
43
43
  * );
44
44
  *
45
45
  * // files = {
@@ -1,28 +1,24 @@
1
- var $=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends ${constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let s=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");s&&(this.rateLimitRemaining=parseInt(s,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,s,n,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let d of a.tree){if(d.type!=="blob")continue;let p=d.path;if(n){if(!d.path.startsWith(n))continue;p=d.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${d.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let d=g["Move.toml"].trim();if(d.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!d.includes("[")&&!d.includes("=")){let p=d,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(c)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let c=await i.text();return this.cache.set(t,c),c}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function R(l){let e=!1,t="";for(let s=0;s<l.length;s++){let n=l[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return l.slice(0,s)}return l}function x(l){let e=l.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function N(l){let e={},t=l.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=x(a)}return e}function _(l){let e=[],t=l.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(L(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(L(s.trim())),e}function L(l){return l.startsWith("{")?N(l):x(l)}function w(l){let e={},t=null,s=!1,n=l.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=R(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+R(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+R(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=R(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let d=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=N(p):p.startsWith("[")?m=_(p):m=x(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[d]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?d.replace(/-/g,"_"):d;h[v]=m}}return e}var M=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib","SuiSystem","Bridge"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,s){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,s=new Set,n=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)n(c)};return n(e),t.delete(e),t}topologicalOrder(){if(!this.lockfileOrder.length)return this.topologicalOrderDFS().filter(i=>i!==this.root);let e=new Set,t=new Set,s=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))s(i);t.push(n)};s(this.root);for(let n of this.packageTable.keys())s(n);return t}detectCycle(){let e=new Set,t=new Set,s=new Map,n=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);if(i)return i}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var D=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let s of t){let n=this.graph.getPackage(s);if(n)for(let[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=i;this.packageResolvedTables.set(s.id.name,n),s.resolvedTable=n}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,s]of this.unifiedAddressTable.entries())e[t]=s;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var A=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let s=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.topologicalOrder(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}extractSourcePaths(e,t){let s=Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move")),n=new TextEncoder,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
2
- `),i=[],c=[],o=!1,u=!1;for(let d of r){let p=d.trim();if(p.startsWith("[package]")){o=!0,u=!1;continue}if(p.startsWith("[dependencies]")){o=!1,u=!0;continue}if(p.startsWith("[")){o=!1,u=!1;continue}o&&p&&i.push(d),u&&p&&c.push(d)}let a=`[package]
3
- `,g=!1,f=!1;for(let d of i)if(d.includes("name ="))a+=d+`
4
- `,g=!0;else if(d.includes("version ="))a+=d+`
5
- `,f=!0;else{if(d.includes("edition ="))continue;a+=d+`
6
- `}g||(a+=`name = "${e}"
7
- `),f||(a+=`version = "0.0.0"
8
- `),a+=`edition = "${s}"
1
+ var L=class{async fetch(e,t,n){throw new Error("Not implemented")}async fetchFile(e,t,n){throw new Error("Not implemented")}},A=class extends L{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let n=t.headers.get("x-ratelimit-remaining"),i=t.headers.get("x-ratelimit-reset");n&&(this.rateLimitRemaining=parseInt(n,10)),i&&(this.rateLimitReset=parseInt(i,10)*1e3)}async fetch(t,n,i,s){let{owner:r,repo:o}=this.parseGitUrl(t);if(!r||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${r}/${o}@${n}`,p=`https://api.github.com/repos/${r}/${o}/git/trees/${n}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let b=Math.pow(2,h-1)*1e3;await new Promise(k=>setTimeout(k,b))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:y});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&h<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let d=new Map,g={},l=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(i){if(!m.path.startsWith(i))continue;f=m.path.slice(i.length),f.startsWith("/")&&(f=f.slice(1))}if(!f.endsWith(".move")&&f!=="Move.toml"&&f!=="Move.lock"&&!f.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;f==="Move.toml"&&m.mode&&d.set("Move.toml",m.mode);let h=`https://raw.githubusercontent.com/${r}/${o}/${n}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(g[f]=v)});l.push(y)}if(await Promise.all(l),g["Move.toml"]&&d.get("Move.toml")==="120000"){let f=g["Move.toml"].trim(),h=i?`${i}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${n}/${h}`,v=await this.fetchContent(y);v&&(g["Move.toml"]=v)}return g}async fetchFile(t,n,i){let{owner:s,repo:r}=this.parseGitUrl(t);if(!s||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${s}/${r}/${n}/${i}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let n={},i=typeof window<"u",s=t.startsWith("https://api.github.com/");this.token&&(!i||s)&&(n.Authorization=`Bearer ${this.token}`);let r=await fetch(t,{headers:n});if(!r.ok)return null;let o=await r.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let i=new URL(t).pathname.split("/").filter(s=>s);if(i.length>=2){let s=i[1];return s.endsWith(".git")&&(s=s.slice(0,-4)),{owner:i[0],repo:s}}}catch{}return{owner:null,repo:null}}};function x(u){let e=!1,t="";for(let n=0;n<u.length;n++){let i=u[n];if((i==='"'||i==="'")&&(!e||i===t)&&(e=!e,t=i),!e&&i==="#")return u.slice(0,n)}return u}function N(u){let e=u.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function G(u){let e={},t=u.trim().replace(/^\{/,"").replace(/\}$/,""),n="",i=!1,s="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!i||a===s)&&(i=!i,s=a),!i&&a===","){r.push(n),n="";continue}n+=a}n.trim()&&r.push(n);for(let o of r){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=N(c)}return e}function z(u){let e=[],t=u.trim().replace(/^\[/,"").replace(/\]$/,""),n="",i=!1,s="",r=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!i||a===s)&&(i=!i,s=i?a:""),!i&&(a==="{"&&r++,a==="}"&&r--,a===","&&r===0)){n.trim()&&e.push(B(n.trim())),n="";continue}n+=a}return n.trim()&&e.push(B(n.trim())),e}function B(u){return u.startsWith("{")?G(u):N(u)}function S(u){let e={},t=null,n=!1,i=u.split(/\r?\n/),s=[],r=0;for(;r<i.length;){let a=x(i[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<i.length&&!p.includes("]");)p+=" "+x(i[r]).trim(),r++;r<i.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+x(i[r]).trim(),r++),s.push(p)}else s.push(a),r++}function o(a,p){let c=a;for(let d of p){if(!(d in c))return;c=c[d]}return c}for(let a of s){let p=x(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),n=!0;let h=t.split("."),y=e;for(let b=0;b<h.length-1;b++){let k=h[b];k in y||(y[k]={}),y=y[k]}let v=h[h.length-1];Array.isArray(y[v])||(y[v]=[]),y[v].push({});continue}let d=p.match(/^\[([^\]]+)\]$/);if(d){t=d[1].trim(),n=!1;continue}let g=p.indexOf("=");if(g===-1||!t)continue;let l=p.slice(0,g).trim(),m=p.slice(g+1).trim(),f;if(m.startsWith("{")?f=G(m):m.startsWith("[")?f=z(m):f=N(m),n){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[l]=f}}else{let h=t.split("."),y=e;for(let b of h)b in y||(y[b]={}),y=y[b];let v=t==="package"?l.replace(/-/g,"_"):l;y[v]=f}}return e}var F=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,n){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,n=new Set,i=s=>{if(n.has(s))return;n.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)i(o)};return i(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.graph.get(i);if(s){let r=Array.from(s).sort();for(let o of r)n(o)}t.push(i)};return n(this.root),t.filter(i=>i!==this.root)}compilerInputOrder(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.graph.get(i);if(s){let r=Array.from(s).sort();for(let o of r)n(o)}t.push(i)};return n(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.graph.get(i);if(s)for(let r of Array.from(s))n(r);t.push(i)};n(this.root);for(let i of this.packageTable.keys())n(i);return t}detectCycle(){let e=new Set,t=new Set,n=new Map,i=s=>{e.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=s;for(;p!==o;)a.unshift(p),p=n.get(p);return a.unshift(o),a}}else{n.set(o,s);let a=i(o);if(a)return a}return t.delete(s),null};for(let s of this.packageTable.keys())if(!e.has(s)){let r=i(s);if(r)return r}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var O=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let n of t){let i=this.graph.getPackage(n);if(i)for(let[s,r]of Object.entries(i.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==o||this.unifiedAddressTable.set(s,o)}}for(let n of this.graph.getAllPackages()){let i={};for(let[s,r]of this.unifiedAddressTable.entries())i[s]=r;this.packageResolvedTables.set(n.id.name,i),n.resolvedTable=i}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,n]of this.unifiedAddressTable.entries())e[t]=n;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}compilerInputOrder(){return this.graph.compilerInputOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var $=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let n=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),i=this.resolvedGraph.compilerInputOrder(),s=new Map;for(let r of i){if(r===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(r);if(!o)continue;let a=e.get(r)||{},p=this.extractSourcePaths(r,a),c=o.manifest.edition||"legacy",d=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],g=o.manifest.originalId;!g&&o.manifest.publishedAt&&(g=o.manifest.publishedAt),g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",d||(d=g)),s.set(r,g),s.set(r.toLowerCase(),g);let l={...o.resolvedTable||{}};for(let[f,h]of Object.entries(l)){let y=s.get(f)||s.get(f.toLowerCase());y&&(l[f]=y)}g&&r!=="Sui"&&r!=="MoveStdlib"&&(l[r]=g,l[r.toLowerCase()]=g);let m={name:r,isImmediate:n.has(r),sourcePaths:p,addressMapping:l,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:d};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}extractSourcePaths(e,t){return Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let n of this.dependencies){let i=e.get(n.name)||{},s={};for(let[r,o]of Object.entries(i)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${n.name}/${r}`;r.endsWith("Move.toml")?s[a]=this.reconstructDependencyMoveToml(n.name,o,n.edition,n.addressMapping):s[a]=o}t.push({name:n.name,files:s,edition:n.edition,addressMapping:n.addressMapping,publishedIdForOutput:n.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,n,i){let s=(t||"").split(`
2
+ `),r=[],o="none";for(let c of s){let d=c.trim();if(d.startsWith("[")){d.startsWith("[package]")?o="package":d.startsWith("[addresses]")?o="addresses":d.startsWith("[dependencies")||d.startsWith("[dev-dependencies")?o="dependencies":(o="other",r.push(c));continue}if(o==="package")(d.startsWith("name")||d.startsWith("version")||d.startsWith("edition")||d.startsWith("published-at")||d.startsWith("original-published-id"))&&(d.startsWith("published-at")||d.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
3
+ `;a+=`name = "${e}"
4
+ `,a+=`version = "0.0.0"
5
+ `,a+=`edition = "${n}"
9
6
  `,a+=`
10
- [dependencies]
11
- `;for(let d of c)a+=d+`
12
- `;a+=`
7
+ `,a+=r.join(`
8
+ `),a+=`
13
9
  [addresses]
14
- `;for(let[d,p]of Object.entries(n))a+=`${d} = "${p}"
15
- `;return a}};var F=class{constructor(e,t="mainnet",s=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=s}async resolve(e,t){let s=w(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new M(n),c=await this.buildPackage(n,this.rootSource,e,t);r&&(c.manifest.edition=r);let o=c.manifest.addresses[n];this.normalizeAddress(o||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&c.manifest.originalId&&(c.manifest.addresses[n]=this.normalizeAddress(c.manifest.originalId)),i.addPackage(c),this.packageFiles.set(n,t);let a=await this.loadFromLockfile(i,c,t),g=Array.from(c.dependencies.keys()).filter(v=>!i.getPackage(v));(!a||g.length>0)&&await this.buildDependencyGraph(i,c);let f=i.detectCycle();if(f)throw new Error(`Dependency cycle detected: ${f.join(" \u2192 ")}`);let d=new D(i,{});await d.resolve();let p=new A(d);await p.compute(this.packageFiles);let m=this.reconstructMoveToml(s,d.getUnifiedAddressTable(),!0,r),y={...t};delete y["Move.lock"],y["Move.toml"]=m;let h=p.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(h)}}async buildPackage(e,t,s,n){let r=w(s),i=n["Move.lock"],c=this.getChainIdForNetwork(this.network),o=this.resolvePublishedAt(s,i,c),u=o.latestId?this.normalizeAddress(o.latestId):void 0,a=n["Published.toml"],g,f;if(a)try{let b=w(a).published?.[this.network];b&&(b["published-at"]&&(g=this.normalizeAddress(b["published-at"])),b["original-id"]&&(f=this.normalizeAddress(b["original-id"])))}catch{}o.error;let d={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:g||o.publishedAt,originalId:f||o.originalId,latestPublishedId:u,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},p=d.publishedAt&&d.publishedAt!=="0x0"?this.normalizeAddress(d.publishedAt):void 0,m=d.addresses[d.name],y=m?this.normalizeAddress(m):void 0;p?d.addresses[d.name]=p:y?d.addresses[d.name]=y:d.addresses[d.name]="0x0";let h=new Map;if(d.dependencies)for(let[k,b]of Object.entries(d.dependencies)){let O=this.parseDependencyInfo(b);O&&h.set(k,O)}return{id:{name:d.name,version:d.version,source:t||{type:"local"}},manifest:d,dependencies:h,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir};else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let s=e["addr-subst"]||e.addr_subst,n={};for(let[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){for(let[s,n]of t.dependencies.entries()){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let g=t.id.source.subdir||"",f=n.source.local,d=this.resolveRelativePath(g,f);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:d}}else continue;if(n.source.type!=="git")continue;let r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,n.source);g&&e.addDependency(t.id.name,g.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let c=await this.fetcher.fetch(n.source.git,n.source.rev,i),o=null,u=`Move.${this.network}.toml`;for(let[g,f]of Object.entries(c))if(g.endsWith(u)){o=f;break}if(!o){for(let[g,f]of Object.entries(c))if(g.endsWith("Move.toml")){o=f;break}}if(!o)continue;let a=await this.buildPackage(s,n.source,o,c);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(a.manifest.name);if(g){let f=d=>JSON.stringify(d);throw new Error([`Conflicting versions of package '${a.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
16
- `))}this.packageNameCache.set(a.manifest.name,n.source)}a.manifest.publishedAt&&(a.manifest.addresses[a.manifest.name]=this.normalizeAddress(a.manifest.publishedAt)),a.manifest.edition||(a.manifest.edition="legacy"),e.addPackage(a),e.addDependency(t.id.name,a.id.name,n),this.packageFiles.set(a.id.name,c),await this.buildDependencyGraph(e,a)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s){let n=w(e),r=n.package?.published_at||n.package?.["published-at"],i=r&&r!=="0x0"?r:void 0,c=i?this.normalizeAddress(i):void 0,o=n.package?.["original-id"];return{publishedAt:c,originalId:o}}findPackageBySource(e,t){for(let s of e.getAllPackages()){let n=s.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return s}}resolveRelativePath(e,t){let s=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.join("/")}async computeManifestDigest(e){let s=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=w(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(a=>a.name||a.id||a).filter(Boolean):[],i=n.map(a=>a.name||a.id).filter(Boolean),c=[...r,...i.filter(a=>!r.includes(a))],o=new Map,u=new Map;for(let a of n){let g=a.id||a.name,f=a.source;if(!g||!f)continue;let d=null;if(f.git&&f.rev)d={type:"git",git:f.git,rev:f.rev,subdir:f.subdir};else if(f.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",f.local);d={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let p=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(p).length===0)continue;let m=p["Move.toml"];if(!m)continue;let y=await this.buildPackage(g,d,m,p);o.set(g,y),u.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,p),e.addPackage(y)}c.length&&e.setLockfileOrder(c);for(let a of n){let g=a.id||a.name,f=o.get(g);if(!f)continue;let d=a.dependencies;if(d&&Array.isArray(d))for(let p of d){let m=p.id||p.name,y=o.get(m)||u.get(m);if(y){let h={source:y.id.source};e.addDependency(f.id.name,y.id.name,h)}}}for(let a of s.dependencies.keys()){let g=u.get(a);if(g){let f=s.dependencies.get(a);e.addDependency(s.id.name,g.id.name,f)}}return o.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,c=[];for(let o of n)o.id&&i.set(o.id,o);for(let o of n){let u=o.id,a=o.source;c.push(u);let g=null;if(a?.git&&a.rev)g={type:"git",git:a.git,rev:a.rev,subdir:a.subdir};else if(a?.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",a.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;if(!g.git||!g.rev)continue;let f=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(f).length===0)continue;let d=f["Move.toml"];if(!d)continue;let p=await this.buildPackage(u,g,d,f);r.set(u,p),this.packageFiles.set(p.manifest.name,f),e.addPackage(p)}e.setLockfileOrder(c);for(let o of n){let u=o.id,a=r.get(u);if(!a)continue;let g=o.dependencies;if(!(!g||!Array.isArray(g)))for(let f of g){let d=f.id,p=r.get(d);if(!p){let m=i.get(d);if(m?.source?.local&&a.id.source.type==="git"){let y=this.resolveRelativePath(a.id.source.subdir||"",m.source.local),h={type:"git",git:a.id.source.git,rev:a.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),k=v["Move.toml"];if(k){let b=await this.buildPackage(d,h,k,v);r.set(d,b),this.packageFiles.set(b.manifest.name,v),e.addPackage(b),p=b}}}if(p){let m={source:p.id.source};e.addDependency(a.id.name,p.id.name,m)}}}for(let o of s.dependencies.keys()){let u=r.get(o);if(u){let a=s.dependencies.get(o);e.addDependency(s.id.name,u.id.name,a)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let c=new Map,o=new Map,u=[];for(let[a,g]of Object.entries(r)){u.push(a);let f=this.lockfileSourceToDependencySource(g.source);if(!f)continue;let d=await this.fetchFromSource(f);if(!d)return!1;let p=d["Move.toml"];if(!p||g["manifest-digest"]&&await this.computeManifestDigest(p)!==g["manifest-digest"])return!1;let m=await this.buildPackage(a,f,p,d);c.set(a,m),o.set(m.manifest.name,m),this.packageFiles.set(m.manifest.name,d),(f.type!=="local"||!("root"in g.source))&&e.addPackage(m)}u.length>0&&e.setLockfileOrder(u);for(let[a,g]of Object.entries(r)){let f=c.get(a);if(f&&g.deps)for(let[d,p]of Object.entries(g.deps)){let m=c.get(p);if(m){let y=f.dependencies.get(d);y&&e.addDependency(f.id.name,m.id.name,y)}}}for(let a of n.dependencies.keys()){let g=o.get(a)||c.get(a);if(g){let f=n.dependencies.get(a);e.addDependency(n.id.name,g.id.name,f)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
10
+ `;let p=Object.entries(i);for(let[c,d]of p)a+=`${c} = "${d}"
11
+ `;return a}};var C=class{constructor(e,t="mainnet",n=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=n}async resolve(e,t){let n=S(e),i=n.package?.name||"RootPackage",s=n.package?.edition,r=new F(i),o=await this.buildPackage(i,this.rootSource,e,t);s&&(o.manifest.edition=s);let a=o.manifest.addresses[i];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[i]=this.normalizeAddress(o.manifest.originalId)),r.addPackage(o),this.packageFiles.set(i,t);let c=await this.loadFromLockfile(r,o,t),d=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||d.length>0)&&await this.buildDependencyGraph(r,o);let g=r.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let l=new O(r,{});await l.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new $(l);await f.compute(this.packageFiles);let h=l.getUnifiedAddressTable();for(let k of r.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name===o.manifest.name){let P=Object.keys(k.manifest.addresses).find(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}let M=Object.keys(k.manifest.addresses).find(P=>P.toLowerCase()===k.manifest.name.toLowerCase());if(M&&k.manifest.addresses[M]){let P=this.normalizeAddress(k.manifest.addresses[M]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(n,o.manifest.dependencies,h,!0,s),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,n,i){let s=S(n),r=i["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(n,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=i["Published.toml"],d,g;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(d=this.normalizeAddress(I["published-at"])),I["original-id"]&&(g=this.normalizeAddress(I["original-id"])))}catch{}a.error;let l={name:s.package?.name||e,version:s.package?.version||"0.0.0",edition:s.package?.edition,publishedAt:d||a.publishedAt,originalId:g||a.originalId,latestPublishedId:p,addresses:s.addresses||{},dependencies:this.injectImplicitDependencies(s.dependencies||{},s.package?.name),devDependencies:s["dev-dependencies"]},m=Object.keys(l.addresses).find(w=>w.toLowerCase()===l.name.toLowerCase());if(m&&l.addresses[m]){let w=this.normalizeAddress(l.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(l.originalId=w)}let f=l.originalId||l.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=l.addresses[l.name]||(m?l.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(l.addresses[l.name]=h):v?l.addresses[l.name]=v:l.addresses[l.name]="0x0";let b=new Map;if(l.dependencies)for(let[w,I]of Object.entries(l.dependencies)){let M=this.parseDependencyInfo(I);M&&b.set(w,M)}return{id:{name:l.name,version:l.version,source:t||{type:"local"}},manifest:l,dependencies:b,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir},e.isImplicit&&(t.source.isImplicit=!0);else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let n=e["addr-subst"]||e.addr_subst,i={};for(let[s,r]of Object.entries(n))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?i[s]={type:"assign",address:r}:i[s]={type:"renameFrom",name:r});Object.keys(i).length>0&&(t.subst=i)}return t}async buildDependencyGraph(e,t){let n=Array.from(t.dependencies.entries()).sort(([,i],[,s])=>{let r=i.source.isImplicit?1:0;return(s.source.isImplicit?1:0)-r});for(let[i,s]of n){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let g=t.id.source.subdir||"",l=s.source.local,m=this.resolveRelativePath(g,l);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}else continue;if(s.source.type!=="git")continue;let r=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,s.source);g&&e.addDependency(t.id.name,g.id.name,s);continue}this.visited.add(r);let o=s.source.subdir;!o&&s.source.git&&this.isSuiRepo(s.source.git)&&(o=this.inferSuiFrameworkSubdir(i),o&&(s.source.subdir=o));let a=await this.fetcher.fetch(s.source.git,s.source.rev,o),p=null,c=`Move.${this.network}.toml`;for(let[g,l]of Object.entries(a))if(g.endsWith(c)){p=l;break}if(!p){for(let[g,l]of Object.entries(a))if(g.endsWith("Move.toml")){p=l;break}}if(!p)continue;let d=await this.buildPackage(i,s.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(d.manifest.name);if(g){let l=g.isImplicit,m=s.source.isImplicit;if(l&&!m)continue;if(!(!l&&m)){if(JSON.stringify(g)!==JSON.stringify(s.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${d.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(s.source)}`,`When resolving dependencies for '${t.id.name}' -> '${i}'`].join(`
12
+ `))}}}this.packageNameCache.set(d.manifest.name,s.source)}d.manifest.edition||(d.manifest.edition="legacy"),e.addPackage(d),e.addDependency(t.id.name,d.id.name,s),this.packageFiles.set(d.id.name,a),await this.buildDependencyGraph(e,d)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,n,i){let s=S(e),r=s.package?.published_at||s.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=s.package?.["original-id"],c,d;if(t)try{let f=S(t),h=n&&f.env?.[n]||f.env?.[i];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(d=this.normalizeAddress(h["latest-published-id"])))}catch{}let g=a||d||c;return{publishedAt:g,originalId:p||c,latestId:g}}findPackageBySource(e,t){for(let n of e.getAllPackages()){let i=n.id.source;if(i.type===t.type&&i.git===t.git&&i.rev===t.rev&&i.subdir===t.subdir)return n}}resolveRelativePath(e,t){let n=e?e.split("/").filter(Boolean):[],i=t.split("/").filter(Boolean),s=[...n];for(let r of i)r===".."?s.length>0&&s.pop():r!=="."&&s.push(r);return s.join("/")}async computeManifestDigest(e){let n=new TextEncoder().encode(e),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,n){let i=n["Move.lock"];if(!i)return!1;let s=S(i);this.lockfileVersion=s.move?.version;let r=s.move?.version;return r===3?await this.loadFromLockfileV3(e,s,t):r&&r>=4?s.pinned?await this.loadFromLockfileV4(e,s,n,t):!1:await this.loadFromLockfileV0(e,s,t)}async loadFromLockfileV0(e,t,n){let i=t.move?.package;if(!i||!Array.isArray(i))return!1;let s=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=i.map(c=>c.name||c.id).filter(Boolean),o=[...s,...r.filter(c=>!s.includes(c))],a=new Map,p=new Map;for(let c of i){let d=c.id||c.name,g=c.source;if(!d||!g)continue;let l=null;if(g.git&&g.rev)l={type:"git",git:g.git,rev:g.rev,subdir:g.subdir};else if(g.local&&this.rootSource?.type==="git"){let y=this.resolveRelativePath(this.rootSource.subdir||"",g.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(d,l,f,m);a.set(d,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of i){let d=c.id||c.name,g=a.get(d);if(!g)continue;let l=c.dependencies;if(l&&Array.isArray(l))for(let m of l){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(g.id.name,h.id.name,y)}}}for(let c of n.dependencies.keys()){let d=p.get(c);if(d){let g=n.dependencies.get(c);e.addDependency(n.id.name,d.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,n){let i=t.move?.package;if(!i||!Array.isArray(i))return!1;let s=new Map,r=new Map,o=[];for(let a of i)a.id&&r.set(a.id,a);for(let a of i){let p=a.id,c=a.source;o.push(p);let d=null;if(c?.git&&c.rev)d={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);d={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!d.git||!d.rev)continue;let g=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(g).length===0)continue;let l=g["Move.toml"];if(!l)continue;let m=await this.buildPackage(p,d,l,g);s.set(p,m),this.packageFiles.set(m.manifest.name,g),e.addPackage(m)}e.setLockfileOrder(o);for(let a of i){let p=a.id,c=s.get(p);if(!c)continue;let d=a.dependencies;if(!(!d||!Array.isArray(d)))for(let g of d){let l=g.id,m=s.get(l);if(!m){let f=r.get(l);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(l,y,b,v);s.set(l,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of n.dependencies.keys()){let p=s.get(a);if(p){let c=n.dependencies.get(a);e.addDependency(n.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,n,i){let s=t.pinned?.[this.network];if(!s)return!1;let r=n["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,d]of Object.entries(s)){p.push(c);let g=this.lockfileSourceToDependencySource(d.source);if(!g)continue;let l=await this.fetchFromSource(g);if(!l)return!1;let m=l["Move.toml"];if(!m||d["manifest-digest"]&&await this.computeManifestDigest(m)!==d["manifest-digest"])return!1;let f=await this.buildPackage(c,g,m,l);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,l),(g.type!=="local"||!("root"in d.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,d]of Object.entries(s)){let g=o.get(c);if(g&&d.deps)for(let[l,m]of Object.entries(d.deps)){let f=o.get(m);if(f){let h=g.dependencies.get(l);h&&e.addDependency(g.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let d=c.id,g=o.get(d);if(g){let l={source:g.id.source};e.addDependency(i.id.name,g.id.name,l)}}else for(let c of i.dependencies.keys()){let d=a.get(c)||o.get(c);if(d){let g=i.dependencies.get(c);e.addDependency(i.id.name,d.id.name,g)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,n,i,s){let o=`[package]
17
13
  name = "${e.package.name}"
18
14
  version = "${e.package.version}"
19
- `,c=n||e.package.edition;if(c&&(i+=`edition = "${c}"
20
- `),i+=`
15
+ `,a=s||e.package.edition;if(a&&(o+=`edition = "${a}"
16
+ `),o+=`
21
17
  [dependencies]
22
- `,e.dependencies)for(let[o,u]of Object.entries(e.dependencies)){let a=u;a.local?i+=`${o} = { local = "${a.local}" }
23
- `:a.git&&a.rev&&(a.subdir?i+=`${o} = { git = "${a.git}", subdir = "${a.subdir}", rev = "${a.rev}" }
24
- `:i+=`${o} = { git = "${a.git}", rev = "${a.rev}" }
25
- `)}i+=`
18
+ `,t){let c=Object.entries(t);for(let[d,g]of c){let l=g;l.local?o+=`${d} = { local = "${l.local}" }
19
+ `:l.git&&l.rev&&(l.subdir?o+=`${d} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
20
+ `:o+=`${d} = { git = "${l.git}", rev = "${l.rev}" }
21
+ `)}}o+=`
26
22
  [addresses]
27
- `;for(let[o,u]of Object.entries(t))i+=`${o} = "${u}"
28
- `;return i}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",DeepBook:"crates/sui-framework/packages/deepbook",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function G(l,e,t,s="mainnet",n){return new F(t,s,n||null).resolve(l,e)}function j(l){try{let e=new URL(l);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let s=t[0],n=t[1],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function U(l,e){let t=j(l);if(!t)throw new Error(`Invalid GitHub URL: ${l}`);let s=e?.fetcher||new S(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":c,...o}=i;return o}return i}var T;async function P(l){return T||(T=import("./sui_move_wasm.js").then(async e=>(l?await e.default(l):await e.default(),e))),T}function I(l){return{error:l instanceof Error?l.message:typeof l=="string"?l:"Unknown error"}}function B(l){if(typeof l!="object"||l===null)throw new Error("Unexpected compile result shape from wasm");let e=l;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function E(l){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let c=parseInt(n.slice(i,i+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");r.push(c)}return r};try{let t=JSON.parse(l);if(!t.modules||!t.dependencies||!t.digest)throw new Error("missing fields in compiler output");let s=typeof t.digest=="string"?e(t.digest):Array.from(t.digest);return{modules:t.modules,dependencies:t.dependencies,digest:s}}catch(t){return I(t)}}function C(l){try{let e=JSON.parse(l);for(let t of e){let s=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let r=w(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function ge(l){await P(l?.wasm)}async function W(l){let e=l.files["Move.toml"]||"",t=l.rootGit||l.files.__rootGit,s=await G(e,{...l.files,"Move.toml":e},new S(l.githubToken),l.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function ue(l){try{let e={};for(let[o,u]of Object.entries(l.files))(o.endsWith(".move")||o.endsWith("Move.toml")||o.endsWith("Move.lock")||o.endsWith("Published.toml"))&&(e[o]=u);l.files=e;let t=l.resolvedDependencies?l.resolvedDependencies:await W(l),s=await P(l.wasm);C(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:l.silenceWarnings,testMode:l.testMode,lintFlag:l.lintFlag,stripMetadata:l.stripMetadata})),r=B(n),i=r.success(),c=r.output();return i?E(c):I(c)}catch(e){return I(e)}}async function pe(l){try{let e=l.resolvedDependencies?l.resolvedDependencies:await W(l),t=await P(l.wasm);C(e.dependencies);let s=l.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof s.passed=="boolean"&&typeof s.output=="string")return{passed:s.passed,output:s.output};let n=typeof s.passed=="function"?s.passed():s.passed,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return I(e)}}async function fe(l){return(await P(l?.wasm)).sui_move_version()}async function he(l){return(await P(l?.wasm)).sui_version()}async function me(l){return P(l?.wasm)}async function ye(l,e,t){let s=await P(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(l,e,!0):s.compile(l,e,JSON.stringify({silenceWarnings:!1})),r=B(n);return{success:r.success(),output:r.output()}}export{ue as buildMovePackage,ye as compileRaw,U as fetchPackageFromGitHub,fe as getSuiMoveVersion,he as getSuiVersion,me as getWasmBindings,ge as initMoveCompiler,W as resolveDependencies,pe as testMovePackage};
23
+ `;let p=Object.entries(n);for(let[c,d]of p)o+=`${c} = "${d}"
24
+ `;return o}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}injectImplicitDependencies(e,t){return t==="Sui"||t==="MoveStdlib"||t==="SuiSystem"||t==="sui"||!e.Sui&&!e.sui&&(e.Sui={git:"https://github.com/MystenLabs/sui.git",subdir:"crates/sui-framework/packages/sui-framework",rev:"framework/mainnet",isImplicit:!0}),e}};async function j(u,e,t,n="mainnet",i){return new C(t,n,i||null).resolve(u,e)}function V(u){try{let e=new URL(u);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let n=t[0],i=t[1],s="main",r;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:n,repo:i,ref:s,subdir:r}}catch{return null}}async function H(u,e){let t=V(u);if(!t)throw new Error(`Invalid GitHub URL: ${u}`);let n=e?.fetcher||new A(e?.githubToken),i=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,r=await n.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!i&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var W;async function R(u){return W||(W=import("./sui_move_wasm.js").then(async e=>(u?await e.default(u):await e.default(),e))),W}function T(u){return{error:u instanceof Error?u.message:typeof u=="string"?u:"Unknown error"}}function _(u){if(typeof u!="object"||u===null)throw new Error("Unexpected compile result shape from wasm");let e=u;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function J(u,e){let t=n=>{let i=n.startsWith("0x")?n.slice(2):n,s=i.length%2===0?i:`0${i}`,r=[];for(let o=0;o<s.length;o+=2){let a=parseInt(s.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let n=JSON.parse(u);if(!n.modules||!n.dependencies||!n.digest)throw new Error("missing fields in compiler output");let i=typeof n.digest=="string"?t(n.digest):Array.from(n.digest),s=n.dependencies;return e&&(s=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),s.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:n.modules,dependencies:s,digest:i}}catch(n){return T(n)}}function U(u){try{let e=JSON.parse(u);for(let t of e){let n=t.addressMapping?.[t.name]??(()=>{let i=Object.entries(t.files).find(([r])=>r.endsWith("Move.toml"));if(!i)return;let s=S(i[1]);return s.addresses&&s.addresses[t.name]||s.package?.published_at||s.package?.["published-at"]})()}}catch{}}async function me(u){await R(u?.wasm)}async function E(u){let e=u.files["Move.toml"]||"",t=u.rootGit||u.files.__rootGit,n=await j(e,{...u.files,"Move.toml":e},new A(u.githubToken),u.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:n.files,dependencies:n.dependencies}}async function he(u){try{let e={};for(let[p,c]of Object.entries(u.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);u.files=e;let t=u.resolvedDependencies?u.resolvedDependencies:await E(u),n=await R(u.wasm);U(t.dependencies);let i=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||i.set(c.publishedIdForOutput,c.name)}catch{}let s=n.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:u.silenceWarnings,testMode:u.testMode,lintFlag:u.lintFlag,stripMetadata:u.stripMetadata})),r=_(s),o=r.success(),a=r.output();return o?J(a,i):T(a)}catch(e){return T(e)}}async function ye(u){try{let e=u.resolvedDependencies?u.resolvedDependencies:await E(u),t=await R(u.wasm);U(e.dependencies);let n=u.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof n.passed=="boolean"&&typeof n.output=="string")return{passed:n.passed,output:n.output};let i=typeof n.passed=="function"?n.passed():n.passed,s=typeof n.output=="function"?n.output():n.output;return{passed:i,output:s}}catch(e){return T(e)}}async function ve(u){return(await R(u?.wasm)).sui_move_version()}async function ke(u){return(await R(u?.wasm)).sui_version()}async function be(u){return R(u?.wasm)}async function we(u,e,t){let n=await R(t?.wasm),i=t?.ansiColor&&typeof n.compile_with_color=="function"?n.compile_with_color(u,e,!0):n.compile(u,e,JSON.stringify({silenceWarnings:!1})),s=_(i);return{success:s.success(),output:s.output()}}export{he as buildMovePackage,we as compileRaw,H as fetchPackageFromGitHub,ve as getSuiMoveVersion,ke as getSuiVersion,be as getWasmBindings,me as initMoveCompiler,E as resolveDependencies,ye as testMovePackage};
@@ -37,8 +37,8 @@ export interface InitOutput {
37
37
  readonly test: (a: number, b: number, c: number, d: number) => number;
38
38
  readonly sui_version: () => [number, number];
39
39
  readonly __wbg_movetestresult_free: (a: number, b: number) => void;
40
- readonly movetestresult_output: (a: number) => [number, number];
41
40
  readonly movetestresult_passed: (a: number) => number;
41
+ readonly movetestresult_output: (a: number) => [number, number];
42
42
  readonly __wbindgen_externrefs: WebAssembly.Table;
43
43
  readonly __wbindgen_malloc: (a: number, b: number) => number;
44
44
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -158,12 +158,12 @@ function __wbg_get_imports() {
158
158
  __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
159
159
  throw new Error(getStringFromWasm0(arg0, arg1));
160
160
  },
161
- __wbg_log_098460783f5a8b3c: function(arg0, arg1) {
162
- console.log(getStringFromWasm0(arg0, arg1));
163
- },
164
161
  __wbg_log_0f025e1465d13170: function(arg0, arg1) {
165
162
  console.log(getStringFromWasm0(arg0, arg1));
166
163
  },
164
+ __wbg_warn_4b3c7c44b93d17a4: function(arg0, arg1) {
165
+ console.warn(getStringFromWasm0(arg0, arg1));
166
+ },
167
167
  __wbindgen_init_externref_table: function() {
168
168
  const table = wasm.__wbindgen_externrefs;
169
169
  const offset = table.grow(4);
Binary file
@@ -9,8 +9,8 @@ export const sui_move_version: () => [number, number];
9
9
  export const test: (a: number, b: number, c: number, d: number) => number;
10
10
  export const sui_version: () => [number, number];
11
11
  export const __wbg_movetestresult_free: (a: number, b: number) => void;
12
- export const movetestresult_output: (a: number) => [number, number];
13
12
  export const movetestresult_passed: (a: number) => number;
13
+ export const movetestresult_output: (a: number) => [number, number];
14
14
  export const __wbindgen_externrefs: WebAssembly.Table;
15
15
  export const __wbindgen_malloc: (a: number, b: number) => number;
16
16
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -1,28 +1,24 @@
1
- "use strict";var E=Object.create;var R=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var J=(d,e)=>{for(var t in e)R(d,t,{get:e[t],enumerable:!0})},G=(d,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of V(e))!q.call(d,n)&&n!==t&&R(d,n,{get:()=>e[n],enumerable:!(s=z(e,n))||s.enumerable});return d};var K=(d,e,t)=>(t=d!=null?E(H(d)):{},G(e||!d||!d.__esModule?R(t,"default",{value:d,enumerable:!0}):t,d)),Q=d=>G(R({},"__esModule",{value:!0}),d);var ae={};J(ae,{buildMovePackage:()=>te,compileRaw:()=>oe,fetchPackageFromGitHub:()=>_,getSuiMoveVersion:()=>se,getSuiVersion:()=>ie,getWasmBindings:()=>re,initMoveCompiler:()=>ee,resolveDependencies:()=>L,testMovePackage:()=>ne});module.exports=Q(ae);var x=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends x{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let s=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");s&&(this.rateLimitRemaining=parseInt(s,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,s,n,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let l of a.tree){if(l.type!=="blob")continue;let p=l.path;if(n){if(!l.path.startsWith(n))continue;p=l.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${l.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let l=g["Move.toml"].trim();if(l.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!l.includes("[")&&!l.includes("=")){let p=l,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(c)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let c=await i.text();return this.cache.set(t,c),c}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function M(d){let e=!1,t="";for(let s=0;s<d.length;s++){let n=d[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return d.slice(0,s)}return d}function F(d){let e=d.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function C(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=F(a)}return e}function X(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(B(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(B(s.trim())),e}function B(d){return d.startsWith("{")?C(d):F(d)}function w(d){let e={},t=null,s=!1,n=d.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=M(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+M(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+M(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=M(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let l=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=C(p):p.startsWith("[")?m=X(p):m=F(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[l]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?l.replace(/-/g,"_"):l;h[v]=m}}return e}var D=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib","SuiSystem","Bridge"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,s){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,s=new Set,n=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)n(c)};return n(e),t.delete(e),t}topologicalOrder(){if(!this.lockfileOrder.length)return this.topologicalOrderDFS().filter(i=>i!==this.root);let e=new Set,t=new Set,s=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))s(i);t.push(n)};s(this.root);for(let n of this.packageTable.keys())s(n);return t}detectCycle(){let e=new Set,t=new Set,s=new Map,n=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);if(i)return i}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var A=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let s of t){let n=this.graph.getPackage(s);if(n)for(let[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=i;this.packageResolvedTables.set(s.id.name,n),s.resolvedTable=n}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,s]of this.unifiedAddressTable.entries())e[t]=s;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var I=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let s=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.topologicalOrder(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}extractSourcePaths(e,t){let s=Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move")),n=new TextEncoder,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
2
- `),i=[],c=[],o=!1,u=!1;for(let l of r){let p=l.trim();if(p.startsWith("[package]")){o=!0,u=!1;continue}if(p.startsWith("[dependencies]")){o=!1,u=!0;continue}if(p.startsWith("[")){o=!1,u=!1;continue}o&&p&&i.push(l),u&&p&&c.push(l)}let a=`[package]
3
- `,g=!1,f=!1;for(let l of i)if(l.includes("name ="))a+=l+`
4
- `,g=!0;else if(l.includes("version ="))a+=l+`
5
- `,f=!0;else{if(l.includes("edition ="))continue;a+=l+`
6
- `}g||(a+=`name = "${e}"
7
- `),f||(a+=`version = "0.0.0"
8
- `),a+=`edition = "${s}"
1
+ "use strict";var J=Object.create;var x=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Q=Object.getPrototypeOf,X=Object.prototype.hasOwnProperty;var Y=(d,e)=>{for(var t in e)x(d,t,{get:e[t],enumerable:!0})},j=(d,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of q(e))!X.call(d,s)&&s!==t&&x(d,s,{get:()=>e[s],enumerable:!(i=K(e,s))||i.enumerable});return d};var Z=(d,e,t)=>(t=d!=null?J(Q(d)):{},j(e||!d||!d.__esModule?x(t,"default",{value:d,enumerable:!0}):t,d)),ee=d=>j(x({},"__esModule",{value:!0}),d);var ge={};Y(ge,{buildMovePackage:()=>re,compileRaw:()=>le,fetchPackageFromGitHub:()=>z,getSuiMoveVersion:()=>ae,getSuiVersion:()=>ce,getWasmBindings:()=>de,initMoveCompiler:()=>ie,resolveDependencies:()=>G,testMovePackage:()=>oe});module.exports=ee(ge);var N=class{async fetch(e,t,i){throw new Error("Not implemented")}async fetchFile(e,t,i){throw new Error("Not implemented")}},A=class extends N{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let i=t.headers.get("x-ratelimit-remaining"),s=t.headers.get("x-ratelimit-reset");i&&(this.rateLimitRemaining=parseInt(i,10)),s&&(this.rateLimitReset=parseInt(s,10)*1e3)}async fetch(t,i,s,n){let{owner:r,repo:o}=this.parseGitUrl(t);if(!r||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${r}/${o}@${i}`,p=`https://api.github.com/repos/${r}/${o}/git/trees/${i}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let b=Math.pow(2,h-1)*1e3;await new Promise(k=>setTimeout(k,b))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:y});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&h<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let l=new Map,u={},g=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(s){if(!m.path.startsWith(s))continue;f=m.path.slice(s.length),f.startsWith("/")&&(f=f.slice(1))}if(!f.endsWith(".move")&&f!=="Move.toml"&&f!=="Move.lock"&&!f.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;f==="Move.toml"&&m.mode&&l.set("Move.toml",m.mode);let h=`https://raw.githubusercontent.com/${r}/${o}/${i}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(u[f]=v)});g.push(y)}if(await Promise.all(g),u["Move.toml"]&&l.get("Move.toml")==="120000"){let f=u["Move.toml"].trim(),h=s?`${s}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${i}/${h}`,v=await this.fetchContent(y);v&&(u["Move.toml"]=v)}return u}async fetchFile(t,i,s){let{owner:n,repo:r}=this.parseGitUrl(t);if(!n||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${n}/${r}/${i}/${s}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let i={},s=typeof window<"u",n=t.startsWith("https://api.github.com/");this.token&&(!s||n)&&(i.Authorization=`Bearer ${this.token}`);let r=await fetch(t,{headers:i});if(!r.ok)return null;let o=await r.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let s=new URL(t).pathname.split("/").filter(n=>n);if(s.length>=2){let n=s[1];return n.endsWith(".git")&&(n=n.slice(0,-4)),{owner:s[0],repo:n}}}catch{}return{owner:null,repo:null}}};function F(d){let e=!1,t="";for(let i=0;i<d.length;i++){let s=d[i];if((s==='"'||s==="'")&&(!e||s===t)&&(e=!e,t=s),!e&&s==="#")return d.slice(0,i)}return d}function C(d){let e=d.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function U(d){let e={},t=d.trim().replace(/^\{/,"").replace(/\}$/,""),i="",s=!1,n="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!s||a===n)&&(s=!s,n=a),!s&&a===","){r.push(i),i="";continue}i+=a}i.trim()&&r.push(i);for(let o of r){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=C(c)}return e}function te(d){let e=[],t=d.trim().replace(/^\[/,"").replace(/\]$/,""),i="",s=!1,n="",r=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!s||a===n)&&(s=!s,n=s?a:""),!s&&(a==="{"&&r++,a==="}"&&r--,a===","&&r===0)){i.trim()&&e.push(_(i.trim())),i="";continue}i+=a}return i.trim()&&e.push(_(i.trim())),e}function _(d){return d.startsWith("{")?U(d):C(d)}function S(d){let e={},t=null,i=!1,s=d.split(/\r?\n/),n=[],r=0;for(;r<s.length;){let a=F(s[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<s.length&&!p.includes("]");)p+=" "+F(s[r]).trim(),r++;r<s.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+F(s[r]).trim(),r++),n.push(p)}else n.push(a),r++}function o(a,p){let c=a;for(let l of p){if(!(l in c))return;c=c[l]}return c}for(let a of n){let p=F(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),i=!0;let h=t.split("."),y=e;for(let b=0;b<h.length-1;b++){let k=h[b];k in y||(y[k]={}),y=y[k]}let v=h[h.length-1];Array.isArray(y[v])||(y[v]=[]),y[v].push({});continue}let l=p.match(/^\[([^\]]+)\]$/);if(l){t=l[1].trim(),i=!1;continue}let u=p.indexOf("=");if(u===-1||!t)continue;let g=p.slice(0,u).trim(),m=p.slice(u+1).trim(),f;if(m.startsWith("{")?f=U(m):m.startsWith("[")?f=te(m):f=C(m),i){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[g]=f}}else{let h=t.split("."),y=e;for(let b of h)b in y||(y[b]={}),y=y[b];let v=t==="package"?g.replace(/-/g,"_"):g;y[v]=f}}return e}var O=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,i){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,i=new Set,s=n=>{if(i.has(n))return;i.add(n),t.add(n);let r=this.graph.get(n);if(r)for(let o of r)s(o)};return s(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n){let r=Array.from(n).sort();for(let o of r)i(o)}t.push(s)};return i(this.root),t.filter(s=>s!==this.root)}compilerInputOrder(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n){let r=Array.from(n).sort();for(let o of r)i(o)}t.push(s)};return i(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],i=s=>{if(e.has(s))return;e.add(s);let n=this.graph.get(s);if(n)for(let r of Array.from(n))i(r);t.push(s)};i(this.root);for(let s of this.packageTable.keys())i(s);return t}detectCycle(){let e=new Set,t=new Set,i=new Map,s=n=>{e.add(n),t.add(n);let r=this.graph.get(n);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=n;for(;p!==o;)a.unshift(p),p=i.get(p);return a.unshift(o),a}}else{i.set(o,n);let a=s(o);if(a)return a}return t.delete(n),null};for(let n of this.packageTable.keys())if(!e.has(n)){let r=s(n);if(r)return r}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var $=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let i of t){let s=this.graph.getPackage(i);if(s)for(let[n,r]of Object.entries(s.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(n)&&this.unifiedAddressTable.get(n)!==o||this.unifiedAddressTable.set(n,o)}}for(let i of this.graph.getAllPackages()){let s={};for(let[n,r]of this.unifiedAddressTable.entries())s[n]=r;this.packageResolvedTables.set(i.id.name,s),i.resolvedTable=s}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,i]of this.unifiedAddressTable.entries())e[t]=i;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}compilerInputOrder(){return this.graph.compilerInputOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var T=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let i=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),s=this.resolvedGraph.compilerInputOrder(),n=new Map;for(let r of s){if(r===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(r);if(!o)continue;let a=e.get(r)||{},p=this.extractSourcePaths(r,a),c=o.manifest.edition||"legacy",l=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],u=o.manifest.originalId;!u&&o.manifest.publishedAt&&(u=o.manifest.publishedAt),u||(u="0x0000000000000000000000000000000000000000000000000000000000000000",l||(l=u)),n.set(r,u),n.set(r.toLowerCase(),u);let g={...o.resolvedTable||{}};for(let[f,h]of Object.entries(g)){let y=n.get(f)||n.get(f.toLowerCase());y&&(g[f]=y)}u&&r!=="Sui"&&r!=="MoveStdlib"&&(g[r]=u,g[r.toLowerCase()]=u);let m={name:r,isImmediate:i.has(r),sourcePaths:p,addressMapping:g,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:l};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}extractSourcePaths(e,t){return Object.keys(t).filter(s=>s.endsWith("Move.toml")||s.endsWith("Move.lock")?!1:s.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let i of this.dependencies){let s=e.get(i.name)||{},n={};for(let[r,o]of Object.entries(s)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${i.name}/${r}`;r.endsWith("Move.toml")?n[a]=this.reconstructDependencyMoveToml(i.name,o,i.edition,i.addressMapping):n[a]=o}t.push({name:i.name,files:n,edition:i.edition,addressMapping:i.addressMapping,publishedIdForOutput:i.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,i,s){let n=(t||"").split(`
2
+ `),r=[],o="none";for(let c of n){let l=c.trim();if(l.startsWith("[")){l.startsWith("[package]")?o="package":l.startsWith("[addresses]")?o="addresses":l.startsWith("[dependencies")||l.startsWith("[dev-dependencies")?o="dependencies":(o="other",r.push(c));continue}if(o==="package")(l.startsWith("name")||l.startsWith("version")||l.startsWith("edition")||l.startsWith("published-at")||l.startsWith("original-published-id"))&&(l.startsWith("published-at")||l.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
3
+ `;a+=`name = "${e}"
4
+ `,a+=`version = "0.0.0"
5
+ `,a+=`edition = "${i}"
9
6
  `,a+=`
10
- [dependencies]
11
- `;for(let l of c)a+=l+`
12
- `;a+=`
7
+ `,a+=r.join(`
8
+ `),a+=`
13
9
  [addresses]
14
- `;for(let[l,p]of Object.entries(n))a+=`${l} = "${p}"
15
- `;return a}};var T=class{constructor(e,t="mainnet",s=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=s}async resolve(e,t){let s=w(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new D(n),c=await this.buildPackage(n,this.rootSource,e,t);r&&(c.manifest.edition=r);let o=c.manifest.addresses[n];this.normalizeAddress(o||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&c.manifest.originalId&&(c.manifest.addresses[n]=this.normalizeAddress(c.manifest.originalId)),i.addPackage(c),this.packageFiles.set(n,t);let a=await this.loadFromLockfile(i,c,t),g=Array.from(c.dependencies.keys()).filter(v=>!i.getPackage(v));(!a||g.length>0)&&await this.buildDependencyGraph(i,c);let f=i.detectCycle();if(f)throw new Error(`Dependency cycle detected: ${f.join(" \u2192 ")}`);let l=new A(i,{});await l.resolve();let p=new I(l);await p.compute(this.packageFiles);let m=this.reconstructMoveToml(s,l.getUnifiedAddressTable(),!0,r),y={...t};delete y["Move.lock"],y["Move.toml"]=m;let h=p.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(h)}}async buildPackage(e,t,s,n){let r=w(s),i=n["Move.lock"],c=this.getChainIdForNetwork(this.network),o=this.resolvePublishedAt(s,i,c),u=o.latestId?this.normalizeAddress(o.latestId):void 0,a=n["Published.toml"],g,f;if(a)try{let b=w(a).published?.[this.network];b&&(b["published-at"]&&(g=this.normalizeAddress(b["published-at"])),b["original-id"]&&(f=this.normalizeAddress(b["original-id"])))}catch{}o.error;let l={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:g||o.publishedAt,originalId:f||o.originalId,latestPublishedId:u,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},p=l.publishedAt&&l.publishedAt!=="0x0"?this.normalizeAddress(l.publishedAt):void 0,m=l.addresses[l.name],y=m?this.normalizeAddress(m):void 0;p?l.addresses[l.name]=p:y?l.addresses[l.name]=y:l.addresses[l.name]="0x0";let h=new Map;if(l.dependencies)for(let[k,b]of Object.entries(l.dependencies)){let N=this.parseDependencyInfo(b);N&&h.set(k,N)}return{id:{name:l.name,version:l.version,source:t||{type:"local"}},manifest:l,dependencies:h,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir};else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let s=e["addr-subst"]||e.addr_subst,n={};for(let[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){for(let[s,n]of t.dependencies.entries()){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let g=t.id.source.subdir||"",f=n.source.local,l=this.resolveRelativePath(g,f);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:l}}else continue;if(n.source.type!=="git")continue;let r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,n.source);g&&e.addDependency(t.id.name,g.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let c=await this.fetcher.fetch(n.source.git,n.source.rev,i),o=null,u=`Move.${this.network}.toml`;for(let[g,f]of Object.entries(c))if(g.endsWith(u)){o=f;break}if(!o){for(let[g,f]of Object.entries(c))if(g.endsWith("Move.toml")){o=f;break}}if(!o)continue;let a=await this.buildPackage(s,n.source,o,c);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(a.manifest.name);if(g){let f=l=>JSON.stringify(l);throw new Error([`Conflicting versions of package '${a.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
16
- `))}this.packageNameCache.set(a.manifest.name,n.source)}a.manifest.publishedAt&&(a.manifest.addresses[a.manifest.name]=this.normalizeAddress(a.manifest.publishedAt)),a.manifest.edition||(a.manifest.edition="legacy"),e.addPackage(a),e.addDependency(t.id.name,a.id.name,n),this.packageFiles.set(a.id.name,c),await this.buildDependencyGraph(e,a)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s){let n=w(e),r=n.package?.published_at||n.package?.["published-at"],i=r&&r!=="0x0"?r:void 0,c=i?this.normalizeAddress(i):void 0,o=n.package?.["original-id"];return{publishedAt:c,originalId:o}}findPackageBySource(e,t){for(let s of e.getAllPackages()){let n=s.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return s}}resolveRelativePath(e,t){let s=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.join("/")}async computeManifestDigest(e){let s=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=w(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(a=>a.name||a.id||a).filter(Boolean):[],i=n.map(a=>a.name||a.id).filter(Boolean),c=[...r,...i.filter(a=>!r.includes(a))],o=new Map,u=new Map;for(let a of n){let g=a.id||a.name,f=a.source;if(!g||!f)continue;let l=null;if(f.git&&f.rev)l={type:"git",git:f.git,rev:f.rev,subdir:f.subdir};else if(f.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",f.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let p=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(p).length===0)continue;let m=p["Move.toml"];if(!m)continue;let y=await this.buildPackage(g,l,m,p);o.set(g,y),u.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,p),e.addPackage(y)}c.length&&e.setLockfileOrder(c);for(let a of n){let g=a.id||a.name,f=o.get(g);if(!f)continue;let l=a.dependencies;if(l&&Array.isArray(l))for(let p of l){let m=p.id||p.name,y=o.get(m)||u.get(m);if(y){let h={source:y.id.source};e.addDependency(f.id.name,y.id.name,h)}}}for(let a of s.dependencies.keys()){let g=u.get(a);if(g){let f=s.dependencies.get(a);e.addDependency(s.id.name,g.id.name,f)}}return o.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,c=[];for(let o of n)o.id&&i.set(o.id,o);for(let o of n){let u=o.id,a=o.source;c.push(u);let g=null;if(a?.git&&a.rev)g={type:"git",git:a.git,rev:a.rev,subdir:a.subdir};else if(a?.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",a.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;if(!g.git||!g.rev)continue;let f=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(f).length===0)continue;let l=f["Move.toml"];if(!l)continue;let p=await this.buildPackage(u,g,l,f);r.set(u,p),this.packageFiles.set(p.manifest.name,f),e.addPackage(p)}e.setLockfileOrder(c);for(let o of n){let u=o.id,a=r.get(u);if(!a)continue;let g=o.dependencies;if(!(!g||!Array.isArray(g)))for(let f of g){let l=f.id,p=r.get(l);if(!p){let m=i.get(l);if(m?.source?.local&&a.id.source.type==="git"){let y=this.resolveRelativePath(a.id.source.subdir||"",m.source.local),h={type:"git",git:a.id.source.git,rev:a.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),k=v["Move.toml"];if(k){let b=await this.buildPackage(l,h,k,v);r.set(l,b),this.packageFiles.set(b.manifest.name,v),e.addPackage(b),p=b}}}if(p){let m={source:p.id.source};e.addDependency(a.id.name,p.id.name,m)}}}for(let o of s.dependencies.keys()){let u=r.get(o);if(u){let a=s.dependencies.get(o);e.addDependency(s.id.name,u.id.name,a)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let c=new Map,o=new Map,u=[];for(let[a,g]of Object.entries(r)){u.push(a);let f=this.lockfileSourceToDependencySource(g.source);if(!f)continue;let l=await this.fetchFromSource(f);if(!l)return!1;let p=l["Move.toml"];if(!p||g["manifest-digest"]&&await this.computeManifestDigest(p)!==g["manifest-digest"])return!1;let m=await this.buildPackage(a,f,p,l);c.set(a,m),o.set(m.manifest.name,m),this.packageFiles.set(m.manifest.name,l),(f.type!=="local"||!("root"in g.source))&&e.addPackage(m)}u.length>0&&e.setLockfileOrder(u);for(let[a,g]of Object.entries(r)){let f=c.get(a);if(f&&g.deps)for(let[l,p]of Object.entries(g.deps)){let m=c.get(p);if(m){let y=f.dependencies.get(l);y&&e.addDependency(f.id.name,m.id.name,y)}}}for(let a of n.dependencies.keys()){let g=o.get(a)||c.get(a);if(g){let f=n.dependencies.get(a);e.addDependency(n.id.name,g.id.name,f)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
10
+ `;let p=Object.entries(s);for(let[c,l]of p)a+=`${c} = "${l}"
11
+ `;return a}};var W=class{constructor(e,t="mainnet",i=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=i}async resolve(e,t){let i=S(e),s=i.package?.name||"RootPackage",n=i.package?.edition,r=new O(s),o=await this.buildPackage(s,this.rootSource,e,t);n&&(o.manifest.edition=n);let a=o.manifest.addresses[s];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[s]=this.normalizeAddress(o.manifest.originalId)),r.addPackage(o),this.packageFiles.set(s,t);let c=await this.loadFromLockfile(r,o,t),l=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||l.length>0)&&await this.buildDependencyGraph(r,o);let u=r.detectCycle();if(u)throw new Error(`Dependency cycle detected: ${u.join(" \u2192 ")}`);let g=new $(r,{});await g.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new T(g);await f.compute(this.packageFiles);let h=g.getUnifiedAddressTable();for(let k of r.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name===o.manifest.name){let P=Object.keys(k.manifest.addresses).find(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}let M=Object.keys(k.manifest.addresses).find(P=>P.toLowerCase()===k.manifest.name.toLowerCase());if(M&&k.manifest.addresses[M]){let P=this.normalizeAddress(k.manifest.addresses[M]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(i,o.manifest.dependencies,h,!0,n),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,i,s){let n=S(i),r=s["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(i,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=s["Published.toml"],l,u;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(l=this.normalizeAddress(I["published-at"])),I["original-id"]&&(u=this.normalizeAddress(I["original-id"])))}catch{}a.error;let g={name:n.package?.name||e,version:n.package?.version||"0.0.0",edition:n.package?.edition,publishedAt:l||a.publishedAt,originalId:u||a.originalId,latestPublishedId:p,addresses:n.addresses||{},dependencies:this.injectImplicitDependencies(n.dependencies||{},n.package?.name),devDependencies:n["dev-dependencies"]},m=Object.keys(g.addresses).find(w=>w.toLowerCase()===g.name.toLowerCase());if(m&&g.addresses[m]){let w=this.normalizeAddress(g.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(g.originalId=w)}let f=g.originalId||g.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=g.addresses[g.name]||(m?g.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(g.addresses[g.name]=h):v?g.addresses[g.name]=v:g.addresses[g.name]="0x0";let b=new Map;if(g.dependencies)for(let[w,I]of Object.entries(g.dependencies)){let M=this.parseDependencyInfo(I);M&&b.set(w,M)}return{id:{name:g.name,version:g.version,source:t||{type:"local"}},manifest:g,dependencies:b,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir},e.isImplicit&&(t.source.isImplicit=!0);else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let i=e["addr-subst"]||e.addr_subst,s={};for(let[n,r]of Object.entries(i))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?s[n]={type:"assign",address:r}:s[n]={type:"renameFrom",name:r});Object.keys(s).length>0&&(t.subst=s)}return t}async buildDependencyGraph(e,t){let i=Array.from(t.dependencies.entries()).sort(([,s],[,n])=>{let r=s.source.isImplicit?1:0;return(n.source.isImplicit?1:0)-r});for(let[s,n]of i){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let u=t.id.source.subdir||"",g=n.source.local,m=this.resolveRelativePath(u,g);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}else continue;if(n.source.type!=="git")continue;let r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let u=this.findPackageBySource(e,n.source);u&&e.addDependency(t.id.name,u.id.name,n);continue}this.visited.add(r);let o=n.source.subdir;!o&&n.source.git&&this.isSuiRepo(n.source.git)&&(o=this.inferSuiFrameworkSubdir(s),o&&(n.source.subdir=o));let a=await this.fetcher.fetch(n.source.git,n.source.rev,o),p=null,c=`Move.${this.network}.toml`;for(let[u,g]of Object.entries(a))if(u.endsWith(c)){p=g;break}if(!p){for(let[u,g]of Object.entries(a))if(u.endsWith("Move.toml")){p=g;break}}if(!p)continue;let l=await this.buildPackage(s,n.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let u=this.packageNameCache.get(l.manifest.name);if(u){let g=u.isImplicit,m=n.source.isImplicit;if(g&&!m)continue;if(!(!g&&m)){if(JSON.stringify(u)!==JSON.stringify(n.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${l.manifest.name}' found`,`Existing: ${f(u)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
12
+ `))}}}this.packageNameCache.set(l.manifest.name,n.source)}l.manifest.edition||(l.manifest.edition="legacy"),e.addPackage(l),e.addDependency(t.id.name,l.id.name,n),this.packageFiles.set(l.id.name,a),await this.buildDependencyGraph(e,l)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,i,s){let n=S(e),r=n.package?.published_at||n.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=n.package?.["original-id"],c,l;if(t)try{let f=S(t),h=i&&f.env?.[i]||f.env?.[s];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(l=this.normalizeAddress(h["latest-published-id"])))}catch{}let u=a||l||c;return{publishedAt:u,originalId:p||c,latestId:u}}findPackageBySource(e,t){for(let i of e.getAllPackages()){let s=i.id.source;if(s.type===t.type&&s.git===t.git&&s.rev===t.rev&&s.subdir===t.subdir)return i}}resolveRelativePath(e,t){let i=e?e.split("/").filter(Boolean):[],s=t.split("/").filter(Boolean),n=[...i];for(let r of s)r===".."?n.length>0&&n.pop():r!=="."&&n.push(r);return n.join("/")}async computeManifestDigest(e){let i=new TextEncoder().encode(e),s=await crypto.subtle.digest("SHA-256",i);return Array.from(new Uint8Array(s)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,i){let s=i["Move.lock"];if(!s)return!1;let n=S(s);this.lockfileVersion=n.move?.version;let r=n.move?.version;return r===3?await this.loadFromLockfileV3(e,n,t):r&&r>=4?n.pinned?await this.loadFromLockfileV4(e,n,i,t):!1:await this.loadFromLockfileV0(e,n,t)}async loadFromLockfileV0(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=s.map(c=>c.name||c.id).filter(Boolean),o=[...n,...r.filter(c=>!n.includes(c))],a=new Map,p=new Map;for(let c of s){let l=c.id||c.name,u=c.source;if(!l||!u)continue;let g=null;if(u.git&&u.rev)g={type:"git",git:u.git,rev:u.rev,subdir:u.subdir};else if(u.local&&this.rootSource?.type==="git"){let y=this.resolveRelativePath(this.rootSource.subdir||"",u.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(l,g,f,m);a.set(l,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of s){let l=c.id||c.name,u=a.get(l);if(!u)continue;let g=c.dependencies;if(g&&Array.isArray(g))for(let m of g){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(u.id.name,h.id.name,y)}}}for(let c of i.dependencies.keys()){let l=p.get(c);if(l){let u=i.dependencies.get(c);e.addDependency(i.id.name,l.id.name,u)}}return a.size>0}async loadFromLockfileV3(e,t,i){let s=t.move?.package;if(!s||!Array.isArray(s))return!1;let n=new Map,r=new Map,o=[];for(let a of s)a.id&&r.set(a.id,a);for(let a of s){let p=a.id,c=a.source;o.push(p);let l=null;if(c?.git&&c.rev)l={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!l.git||!l.rev)continue;let u=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(u).length===0)continue;let g=u["Move.toml"];if(!g)continue;let m=await this.buildPackage(p,l,g,u);n.set(p,m),this.packageFiles.set(m.manifest.name,u),e.addPackage(m)}e.setLockfileOrder(o);for(let a of s){let p=a.id,c=n.get(p);if(!c)continue;let l=a.dependencies;if(!(!l||!Array.isArray(l)))for(let u of l){let g=u.id,m=n.get(g);if(!m){let f=r.get(g);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(g,y,b,v);n.set(g,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of i.dependencies.keys()){let p=n.get(a);if(p){let c=i.dependencies.get(a);e.addDependency(i.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,i,s){let n=t.pinned?.[this.network];if(!n)return!1;let r=i["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,l]of Object.entries(n)){p.push(c);let u=this.lockfileSourceToDependencySource(l.source);if(!u)continue;let g=await this.fetchFromSource(u);if(!g)return!1;let m=g["Move.toml"];if(!m||l["manifest-digest"]&&await this.computeManifestDigest(m)!==l["manifest-digest"])return!1;let f=await this.buildPackage(c,u,m,g);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,g),(u.type!=="local"||!("root"in l.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,l]of Object.entries(n)){let u=o.get(c);if(u&&l.deps)for(let[g,m]of Object.entries(l.deps)){let f=o.get(m);if(f){let h=u.dependencies.get(g);h&&e.addDependency(u.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let l=c.id,u=o.get(l);if(u){let g={source:u.id.source};e.addDependency(s.id.name,u.id.name,g)}}else for(let c of s.dependencies.keys()){let l=a.get(c)||o.get(c);if(l){let u=s.dependencies.get(c);e.addDependency(s.id.name,l.id.name,u)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,i,s,n){let o=`[package]
17
13
  name = "${e.package.name}"
18
14
  version = "${e.package.version}"
19
- `,c=n||e.package.edition;if(c&&(i+=`edition = "${c}"
20
- `),i+=`
15
+ `,a=n||e.package.edition;if(a&&(o+=`edition = "${a}"
16
+ `),o+=`
21
17
  [dependencies]
22
- `,e.dependencies)for(let[o,u]of Object.entries(e.dependencies)){let a=u;a.local?i+=`${o} = { local = "${a.local}" }
23
- `:a.git&&a.rev&&(a.subdir?i+=`${o} = { git = "${a.git}", subdir = "${a.subdir}", rev = "${a.rev}" }
24
- `:i+=`${o} = { git = "${a.git}", rev = "${a.rev}" }
25
- `)}i+=`
18
+ `,t){let c=Object.entries(t);for(let[l,u]of c){let g=u;g.local?o+=`${l} = { local = "${g.local}" }
19
+ `:g.git&&g.rev&&(g.subdir?o+=`${l} = { git = "${g.git}", subdir = "${g.subdir}", rev = "${g.rev}" }
20
+ `:o+=`${l} = { git = "${g.git}", rev = "${g.rev}" }
21
+ `)}}o+=`
26
22
  [addresses]
27
- `;for(let[o,u]of Object.entries(t))i+=`${o} = "${u}"
28
- `;return i}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",DeepBook:"crates/sui-framework/packages/deepbook",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function W(d,e,t,s="mainnet",n){return new T(t,s,n||null).resolve(d,e)}function Y(d){try{let e=new URL(d);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let s=t[0],n=t[1],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function _(d,e){let t=Y(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let s=e?.fetcher||new S(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":c,...o}=i;return o}return i}var O;async function P(d){return O||(O=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),O}function $(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function j(d){if(typeof d!="object"||d===null)throw new Error("Unexpected compile result shape from wasm");let e=d;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function Z(d){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let c=parseInt(n.slice(i,i+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");r.push(c)}return r};try{let t=JSON.parse(d);if(!t.modules||!t.dependencies||!t.digest)throw new Error("missing fields in compiler output");let s=typeof t.digest=="string"?e(t.digest):Array.from(t.digest);return{modules:t.modules,dependencies:t.dependencies,digest:s}}catch(t){return $(t)}}function U(d){try{let e=JSON.parse(d);for(let t of e){let s=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let r=w(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function ee(d){await P(d?.wasm)}async function L(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,s=await W(e,{...d.files,"Move.toml":e},new S(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function te(d){try{let e={};for(let[o,u]of Object.entries(d.files))(o.endsWith(".move")||o.endsWith("Move.toml")||o.endsWith("Move.lock")||o.endsWith("Published.toml"))&&(e[o]=u);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await L(d),s=await P(d.wasm);U(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=j(n),i=r.success(),c=r.output();return i?Z(c):$(c)}catch(e){return $(e)}}async function ne(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await L(d),t=await P(d.wasm);U(e.dependencies);let s=d.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof s.passed=="boolean"&&typeof s.output=="string")return{passed:s.passed,output:s.output};let n=typeof s.passed=="function"?s.passed():s.passed,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return $(e)}}async function se(d){return(await P(d?.wasm)).sui_move_version()}async function ie(d){return(await P(d?.wasm)).sui_version()}async function re(d){return P(d?.wasm)}async function oe(d,e,t){let s=await P(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(d,e,!0):s.compile(d,e,JSON.stringify({silenceWarnings:!1})),r=j(n);return{success:r.success(),output:r.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
23
+ `;let p=Object.entries(i);for(let[c,l]of p)o+=`${c} = "${l}"
24
+ `;return o}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}injectImplicitDependencies(e,t){return t==="Sui"||t==="MoveStdlib"||t==="SuiSystem"||t==="sui"||!e.Sui&&!e.sui&&(e.Sui={git:"https://github.com/MystenLabs/sui.git",subdir:"crates/sui-framework/packages/sui-framework",rev:"framework/mainnet",isImplicit:!0}),e}};async function E(d,e,t,i="mainnet",s){return new W(t,i,s||null).resolve(d,e)}function se(d){try{let e=new URL(d);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let i=t[0],s=t[1],n="main",r;return t.length>=4&&t[2]==="tree"&&(n=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:i,repo:s,ref:n,subdir:r}}catch{return null}}async function z(d,e){let t=se(d);if(!t)throw new Error(`Invalid GitHub URL: ${d}`);let i=e?.fetcher||new A(e?.githubToken),s=e?.includeLock!==!1,n=`https://github.com/${t.owner}/${t.repo}.git`,r=await i.fetch(n,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:n,rev:t.ref,subdir:t.subdir},enumerable:!1}),!s&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var B;async function R(d){return B||(B=import("./sui_move_wasm.js").then(async e=>(d?await e.default(d):await e.default(),e))),B}function L(d){return{error:d instanceof Error?d.message:typeof d=="string"?d:"Unknown error"}}function V(d){if(typeof d!="object"||d===null)throw new Error("Unexpected compile result shape from wasm");let e=d;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function ne(d,e){let t=i=>{let s=i.startsWith("0x")?i.slice(2):i,n=s.length%2===0?s:`0${s}`,r=[];for(let o=0;o<n.length;o+=2){let a=parseInt(n.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let i=JSON.parse(d);if(!i.modules||!i.dependencies||!i.digest)throw new Error("missing fields in compiler output");let s=typeof i.digest=="string"?t(i.digest):Array.from(i.digest),n=i.dependencies;return e&&(n=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),n.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:i.modules,dependencies:n,digest:s}}catch(i){return L(i)}}function H(d){try{let e=JSON.parse(d);for(let t of e){let i=t.addressMapping?.[t.name]??(()=>{let s=Object.entries(t.files).find(([r])=>r.endsWith("Move.toml"));if(!s)return;let n=S(s[1]);return n.addresses&&n.addresses[t.name]||n.package?.published_at||n.package?.["published-at"]})()}}catch{}}async function ie(d){await R(d?.wasm)}async function G(d){let e=d.files["Move.toml"]||"",t=d.rootGit||d.files.__rootGit,i=await E(e,{...d.files,"Move.toml":e},new A(d.githubToken),d.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:i.files,dependencies:i.dependencies}}async function re(d){try{let e={};for(let[p,c]of Object.entries(d.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);d.files=e;let t=d.resolvedDependencies?d.resolvedDependencies:await G(d),i=await R(d.wasm);H(t.dependencies);let s=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||s.set(c.publishedIdForOutput,c.name)}catch{}let n=i.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:d.silenceWarnings,testMode:d.testMode,lintFlag:d.lintFlag,stripMetadata:d.stripMetadata})),r=V(n),o=r.success(),a=r.output();return o?ne(a,s):L(a)}catch(e){return L(e)}}async function oe(d){try{let e=d.resolvedDependencies?d.resolvedDependencies:await G(d),t=await R(d.wasm);H(e.dependencies);let i=d.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof i.passed=="boolean"&&typeof i.output=="string")return{passed:i.passed,output:i.output};let s=typeof i.passed=="function"?i.passed():i.passed,n=typeof i.output=="function"?i.output():i.output;return{passed:s,output:n}}catch(e){return L(e)}}async function ae(d){return(await R(d?.wasm)).sui_move_version()}async function ce(d){return(await R(d?.wasm)).sui_version()}async function de(d){return R(d?.wasm)}async function le(d,e,t){let i=await R(t?.wasm),s=t?.ansiColor&&typeof i.compile_with_color=="function"?i.compile_with_color(d,e,!0):i.compile(d,e,JSON.stringify({silenceWarnings:!1})),n=V(s);return{success:n.success(),output:n.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
39
39
  * @example
40
40
  * ```ts
41
41
  * const files = await fetchPackageFromGitHub(
42
- * 'https://github.com/MystenLabs/deepbookv3/tree/main/packages/deepbook'
42
+ * 'https://github.com/org/repo/tree/main/packages/example_package'
43
43
  * );
44
44
  *
45
45
  * // files = {
@@ -39,7 +39,7 @@ declare class GitHubFetcher extends Fetcher {
39
39
  * @example
40
40
  * ```ts
41
41
  * const files = await fetchPackageFromGitHub(
42
- * 'https://github.com/MystenLabs/deepbookv3/tree/main/packages/deepbook'
42
+ * 'https://github.com/org/repo/tree/main/packages/example_package'
43
43
  * );
44
44
  *
45
45
  * // files = {
@@ -1,28 +1,24 @@
1
- var $=class{async fetch(e,t,s){throw new Error("Not implemented")}async fetchFile(e,t,s){throw new Error("Not implemented")}},S=class extends ${constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let s=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");s&&(this.rateLimitRemaining=parseInt(s,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,s,n,r){let{owner:i,repo:c}=this.parseGitUrl(t);if(!i||!c)throw new Error(`Invalid git URL: ${t}`);let o=`${i}/${c}@${s}`,u=`https://api.github.com/repos/${i}/${c}/git/trees/${s}?recursive=1`,a;if(this.treeCache.has(o))a=this.treeCache.get(o);else{let p=null;for(let m=1;m<=3;m++)try{if(m>1){let v=Math.pow(2,m-1)*1e3;await new Promise(k=>setTimeout(k,v))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let h=await fetch(u,{headers:y});if(this.updateRateLimit(h),!h.ok){if(h.status===403||h.status===429){let v=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${v.toLocaleTimeString()}`)}if(h.status>=500&&h.status<600&&m<3){p=new Error(`Failed to fetch tree: ${h.statusText}`);continue}throw new Error(`Failed to fetch tree: ${h.statusText}`)}a=await h.json(),this.treeCache.set(o,a);break}catch(y){if(p=y instanceof Error?y:new Error(String(y)),m===3)return{}}if(p)return{}}let g={},f=[];for(let d of a.tree){if(d.type!=="blob")continue;let p=d.path;if(n){if(!d.path.startsWith(n))continue;p=d.path.slice(n.length),p.startsWith("/")&&(p=p.slice(1))}if(!p.endsWith(".move")&&p!=="Move.toml"&&p!=="Move.lock"&&!p.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;let m=`https://raw.githubusercontent.com/${i}/${c}/${s}/${d.path}`,y=this.fetchContent(m).then(h=>{h&&(g[p]=h)});f.push(y)}if(await Promise.all(f),g["Move.toml"]){let d=g["Move.toml"].trim();if(d.match(/^Move\.(mainnet|testnet|devnet)\.toml$/)&&!d.includes("[")&&!d.includes("=")){let p=d,m=n?`${n}/${p}`.replace(/\/+/g,"/"):p,y=`https://raw.githubusercontent.com/${i}/${c}/${s}/${m}`,h=await this.fetchContent(y);h&&(g["Move.toml"]=h,g[p]=h)}}return g}async fetchFile(t,s,n){let{owner:r,repo:i}=this.parseGitUrl(t);if(!r||!i)throw new Error(`Invalid git URL: ${t}`);let c=`https://raw.githubusercontent.com/${r}/${i}/${s}/${n}`;return this.fetchContent(c)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let s={},n=typeof window<"u",r=t.startsWith("https://api.github.com/");this.token&&(!n||r)&&(s.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:s});if(!i.ok)return null;let c=await i.text();return this.cache.set(t,c),c}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(r=>r);if(n.length>=2){let r=n[1];return r.endsWith(".git")&&(r=r.slice(0,-4)),{owner:n[0],repo:r}}}catch{}return{owner:null,repo:null}}};function R(l){let e=!1,t="";for(let s=0;s<l.length;s++){let n=l[s];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return l.slice(0,s)}return l}function x(l){let e=l.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function N(l){let e={},t=l.trim().replace(/^\{/,"").replace(/\}$/,""),s="",n=!1,r="",i=[];for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=o),!n&&o===","){i.push(s),s="";continue}s+=o}s.trim()&&i.push(s);for(let c of i){let o=c.indexOf("=");if(o===-1)continue;let u=c.slice(0,o).trim(),a=c.slice(o+1).trim();e[u]=x(a)}return e}function _(l){let e=[],t=l.trim().replace(/^\[/,"").replace(/\]$/,""),s="",n=!1,r="",i=0;for(let c=0;c<t.length;c++){let o=t[c];if((o==='"'||o==="'")&&(!n||o===r)&&(n=!n,r=n?o:""),!n&&(o==="{"&&i++,o==="}"&&i--,o===","&&i===0)){s.trim()&&e.push(L(s.trim())),s="";continue}s+=o}return s.trim()&&e.push(L(s.trim())),e}function L(l){return l.startsWith("{")?N(l):x(l)}function w(l){let e={},t=null,s=!1,n=l.split(/\r?\n/),r=[],i=0;for(;i<n.length;){let o=R(n[i]);if(o.match(/=\s*\[\s*$/)||o.includes("=")&&o.includes("[")&&!o.includes("]")){let u=o;for(i++;i<n.length&&!u.includes("]");)u+=" "+R(n[i]).trim(),i++;i<n.length&&u.includes("[")&&!u.includes("]")&&(u+=" "+R(n[i]).trim(),i++),r.push(u)}else r.push(o),i++}function c(o,u){let a=o;for(let g of u){if(!(g in a))return;a=a[g]}return a}for(let o of r){let u=R(o).trim();if(!u)continue;let a=u.match(/^\[\[([^\]]+)\]\]$/);if(a){t=a[1].trim(),s=!0;let y=t.split("."),h=e;for(let k=0;k<y.length-1;k++){let b=y[k];b in h||(h[b]={}),h=h[b]}let v=y[y.length-1];Array.isArray(h[v])||(h[v]=[]),h[v].push({});continue}let g=u.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),s=!1;continue}let f=u.indexOf("=");if(f===-1||!t)continue;let d=u.slice(0,f).trim(),p=u.slice(f+1).trim(),m;if(p.startsWith("{")?m=N(p):p.startsWith("[")?m=_(p):m=x(p),s){let y=t.split("."),h=c(e,y);if(Array.isArray(h)&&h.length>0){let v=h[h.length-1];v[d]=m}}else{let y=t.split("."),h=e;for(let k of y)k in h||(h[k]={}),h=h[k];let v=t==="package"?d.replace(/-/g,"_"):d;h[v]=m}}return e}var M=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib","SuiSystem","Bridge"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,s){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,s=new Set,n=r=>{if(s.has(r))return;s.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)n(c)};return n(e),t.delete(e),t}topologicalOrder(){if(!this.lockfileOrder.length)return this.topologicalOrderDFS().filter(i=>i!==this.root);let e=new Set,t=new Set,s=r=>{if(t.has(r))return;t.add(r),e.add(r);let i=this.graph.get(r);if(i)for(let c of i)s(c)};s(this.root);let n=[];for(let r of this.lockfileOrder)r!==this.root&&e.has(r)&&n.push(r);return n}topologicalOrderDFS(){let e=new Set,t=[],s=n=>{if(e.has(n))return;e.add(n);let r=this.graph.get(n);if(r)for(let i of Array.from(r))s(i);t.push(n)};s(this.root);for(let n of this.packageTable.keys())s(n);return t}detectCycle(){let e=new Set,t=new Set,s=new Map,n=r=>{e.add(r),t.add(r);let i=this.graph.get(r);if(i)for(let c of i)if(e.has(c)){if(t.has(c)){let o=[c],u=r;for(;u!==c;)o.unshift(u),u=s.get(u);return o.unshift(c),o}}else{s.set(c,r);let o=n(c);if(o)return o}return t.delete(r),null};for(let r of this.packageTable.keys())if(!e.has(r)){let i=n(r);if(i)return i}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var D=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let s of t){let n=this.graph.getPackage(s);if(n)for(let[r,i]of Object.entries(n.manifest.addresses)){let c=this.normalizeAddress(i);this.unifiedAddressTable.has(r)&&this.unifiedAddressTable.get(r)!==c||this.unifiedAddressTable.set(r,c)}}for(let s of this.graph.getAllPackages()){let n={};for(let[r,i]of this.unifiedAddressTable.entries())n[r]=i;this.packageResolvedTables.set(s.id.name,n),s.resolvedTable=n}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,s]of this.unifiedAddressTable.entries())e[t]=s;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var A=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let s=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.topologicalOrder(),r=new Set(["Bridge","SuiSystem"]);for(let i of n){if(i===this.rootPackageName)continue;let c=this.resolvedGraph.getPackage(i);if(!c||r.has(i))continue;let o=e.get(i)||{},u=this.extractSourcePaths(i,o),a=c.manifest.edition||"legacy",g=c.manifest.latestPublishedId||c.manifest.originalId||c.manifest.publishedAt||c.resolvedTable?.[i],f={name:i,isImmediate:s.has(i),sourcePaths:u,addressMapping:c.resolvedTable||{},compilerConfig:{edition:a,flavor:"sui"},moduleFormat:u.length>0?"Source":"Bytecode",edition:a,publishedIdForOutput:g};this.dependencies.push(f)}}extractSourcePaths(e,t){let s=Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move")),n=new TextEncoder,r=(i,c)=>{let o=n.encode(`/vfs/deps/${e}/${i}`),u=n.encode(`/vfs/deps/${e}/${c}`),a=Math.min(o.length,u.length);for(let g=0;g<a;g++)if(o[g]!==u[g])return o[g]-u[g];return o.length-u.length};return s.sort(r),s}toPackageGroupedFormat(e){let t=[];for(let s of this.dependencies){let n=e.get(s.name)||{},r={};for(let[i,c]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let o=`dependencies/${s.name}/${i}`;i.endsWith("Move.toml")?r[o]=this.reconstructDependencyMoveToml(s.name,c,s.edition,s.addressMapping):r[o]=c}t.push({name:s.name,files:r,edition:s.edition,addressMapping:s.addressMapping,publishedIdForOutput:s.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,s,n){let r=(t||"").split(`
2
- `),i=[],c=[],o=!1,u=!1;for(let d of r){let p=d.trim();if(p.startsWith("[package]")){o=!0,u=!1;continue}if(p.startsWith("[dependencies]")){o=!1,u=!0;continue}if(p.startsWith("[")){o=!1,u=!1;continue}o&&p&&i.push(d),u&&p&&c.push(d)}let a=`[package]
3
- `,g=!1,f=!1;for(let d of i)if(d.includes("name ="))a+=d+`
4
- `,g=!0;else if(d.includes("version ="))a+=d+`
5
- `,f=!0;else{if(d.includes("edition ="))continue;a+=d+`
6
- `}g||(a+=`name = "${e}"
7
- `),f||(a+=`version = "0.0.0"
8
- `),a+=`edition = "${s}"
1
+ var L=class{async fetch(e,t,n){throw new Error("Not implemented")}async fetchFile(e,t,n){throw new Error("Not implemented")}},A=class extends L{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.token=t}updateRateLimit(t){let n=t.headers.get("x-ratelimit-remaining"),i=t.headers.get("x-ratelimit-reset");n&&(this.rateLimitRemaining=parseInt(n,10)),i&&(this.rateLimitReset=parseInt(i,10)*1e3)}async fetch(t,n,i,s){let{owner:r,repo:o}=this.parseGitUrl(t);if(!r||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${r}/${o}@${n}`,p=`https://api.github.com/repos/${r}/${o}/git/trees/${n}?recursive=1`,c;if(this.treeCache.has(a))c=this.treeCache.get(a);else{let f=null;for(let h=1;h<=3;h++)try{if(h>1){let b=Math.pow(2,h-1)*1e3;await new Promise(k=>setTimeout(k,b))}let y={};this.token&&(y.Authorization=`Bearer ${this.token}`);let v=await fetch(p,{headers:y});if(this.updateRateLimit(v),!v.ok){if(v.status===403||v.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(v.status>=500&&v.status<600&&h<3){f=new Error(`Failed to fetch tree: ${v.statusText}`);continue}throw new Error(`Failed to fetch tree: ${v.statusText}`)}c=await v.json(),this.treeCache.set(a,c);break}catch(y){if(f=y instanceof Error?y:new Error(String(y)),h===3)return{}}if(f)return{}}let d=new Map,g={},l=[];for(let m of c.tree){if(m.type!=="blob")continue;let f=m.path;if(i){if(!m.path.startsWith(i))continue;f=m.path.slice(i.length),f.startsWith("/")&&(f=f.slice(1))}if(!f.endsWith(".move")&&f!=="Move.toml"&&f!=="Move.lock"&&!f.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;f==="Move.toml"&&m.mode&&d.set("Move.toml",m.mode);let h=`https://raw.githubusercontent.com/${r}/${o}/${n}/${m.path}`,y=this.fetchContent(h).then(v=>{v&&(g[f]=v)});l.push(y)}if(await Promise.all(l),g["Move.toml"]&&d.get("Move.toml")==="120000"){let f=g["Move.toml"].trim(),h=i?`${i}/${f}`.replace(/\/+/g,"/"):f,y=`https://raw.githubusercontent.com/${r}/${o}/${n}/${h}`,v=await this.fetchContent(y);v&&(g["Move.toml"]=v)}return g}async fetchFile(t,n,i){let{owner:s,repo:r}=this.parseGitUrl(t);if(!s||!r)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${s}/${r}/${n}/${i}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let n={},i=typeof window<"u",s=t.startsWith("https://api.github.com/");this.token&&(!i||s)&&(n.Authorization=`Bearer ${this.token}`);let r=await fetch(t,{headers:n});if(!r.ok)return null;let o=await r.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let i=new URL(t).pathname.split("/").filter(s=>s);if(i.length>=2){let s=i[1];return s.endsWith(".git")&&(s=s.slice(0,-4)),{owner:i[0],repo:s}}}catch{}return{owner:null,repo:null}}};function x(u){let e=!1,t="";for(let n=0;n<u.length;n++){let i=u[n];if((i==='"'||i==="'")&&(!e||i===t)&&(e=!e,t=i),!e&&i==="#")return u.slice(0,n)}return u}function N(u){let e=u.trim();if(!e)return"";if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1);if(e==="true")return!0;if(e==="false")return!1;let t=Number(e);return Number.isNaN(t)?e:t}function G(u){let e={},t=u.trim().replace(/^\{/,"").replace(/\}$/,""),n="",i=!1,s="",r=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!i||a===s)&&(i=!i,s=a),!i&&a===","){r.push(n),n="";continue}n+=a}n.trim()&&r.push(n);for(let o of r){let a=o.indexOf("=");if(a===-1)continue;let p=o.slice(0,a).trim(),c=o.slice(a+1).trim();e[p]=N(c)}return e}function z(u){let e=[],t=u.trim().replace(/^\[/,"").replace(/\]$/,""),n="",i=!1,s="",r=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!i||a===s)&&(i=!i,s=i?a:""),!i&&(a==="{"&&r++,a==="}"&&r--,a===","&&r===0)){n.trim()&&e.push(B(n.trim())),n="";continue}n+=a}return n.trim()&&e.push(B(n.trim())),e}function B(u){return u.startsWith("{")?G(u):N(u)}function S(u){let e={},t=null,n=!1,i=u.split(/\r?\n/),s=[],r=0;for(;r<i.length;){let a=x(i[r]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let p=a;for(r++;r<i.length&&!p.includes("]");)p+=" "+x(i[r]).trim(),r++;r<i.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+x(i[r]).trim(),r++),s.push(p)}else s.push(a),r++}function o(a,p){let c=a;for(let d of p){if(!(d in c))return;c=c[d]}return c}for(let a of s){let p=x(a).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),n=!0;let h=t.split("."),y=e;for(let b=0;b<h.length-1;b++){let k=h[b];k in y||(y[k]={}),y=y[k]}let v=h[h.length-1];Array.isArray(y[v])||(y[v]=[]),y[v].push({});continue}let d=p.match(/^\[([^\]]+)\]$/);if(d){t=d[1].trim(),n=!1;continue}let g=p.indexOf("=");if(g===-1||!t)continue;let l=p.slice(0,g).trim(),m=p.slice(g+1).trim(),f;if(m.startsWith("{")?f=G(m):m.startsWith("[")?f=z(m):f=N(m),n){let h=t.split("."),y=o(e,h);if(Array.isArray(y)&&y.length>0){let v=y[y.length-1];v[l]=f}}else{let h=t.split("."),y=e;for(let b of h)b in y||(y[b]={}),y=y[b];let v=t==="package"?l.replace(/-/g,"_"):l;y[v]=f}}return e}var F=class{constructor(e){this.packageTable=new Map;this.graph=new Map;this.alwaysDeps=new Set(["Sui","MoveStdlib"]);this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){this.packageTable.set(e.id.name,e),this.graph.has(e.id.name)||this.graph.set(e.id.name,new Set)}addDependency(e,t,n){this.graph.has(e)||this.graph.set(e,new Set),this.graph.get(e).add(t)}getPackage(e){return this.packageTable.get(e)}getAllPackages(){return Array.from(this.packageTable.values())}getImmediateDependencies(e){return this.graph.get(e)||new Set}getTransitiveDependencies(e){let t=new Set,n=new Set,i=s=>{if(n.has(s))return;n.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)i(o)};return i(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.graph.get(i);if(s){let r=Array.from(s).sort();for(let o of r)n(o)}t.push(i)};return n(this.root),t.filter(i=>i!==this.root)}compilerInputOrder(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.graph.get(i);if(s){let r=Array.from(s).sort();for(let o of r)n(o)}t.push(i)};return n(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.graph.get(i);if(s)for(let r of Array.from(s))n(r);t.push(i)};n(this.root);for(let i of this.packageTable.keys())n(i);return t}detectCycle(){let e=new Set,t=new Set,n=new Map,i=s=>{e.add(s),t.add(s);let r=this.graph.get(s);if(r)for(let o of r)if(e.has(o)){if(t.has(o)){let a=[o],p=s;for(;p!==o;)a.unshift(p),p=n.get(p);return a.unshift(o),a}}else{n.set(o,s);let a=i(o);if(a)return a}return t.delete(s),null};for(let s of this.packageTable.keys())if(!e.has(s)){let r=i(s);if(r)return r}return null}getRootPackage(){return this.packageTable.get(this.root)}getRootName(){return this.root}isAlwaysDep(e){return this.alwaysDeps.has(e)}};var O=class{constructor(e,t={}){this.unifiedAddressTable=new Map;this.packageResolvedTables=new Map;this.graph=e,this.buildConfig=t}async resolve(){let t=[this.graph.getRootName(),...this.graph.topologicalOrder()];for(let n of t){let i=this.graph.getPackage(n);if(i)for(let[s,r]of Object.entries(i.manifest.addresses)){let o=this.normalizeAddress(r);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==o||this.unifiedAddressTable.set(s,o)}}for(let n of this.graph.getAllPackages()){let i={};for(let[s,r]of this.unifiedAddressTable.entries())i[s]=r;this.packageResolvedTables.set(n.id.name,i),n.resolvedTable=i}}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}getUnifiedAddressTable(){let e={};for(let[t,n]of this.unifiedAddressTable.entries())e[t]=n;return e}getPackageResolvedTable(e){return this.packageResolvedTables.get(e)}getGraph(){return this.graph}topologicalOrder(){return this.graph.topologicalOrder()}compilerInputOrder(){return this.graph.compilerInputOrder()}getRootName(){return this.graph.getRootName()}getPackage(e){return this.graph.getPackage(e)}getImmediateDependencies(e){return this.graph.getImmediateDependencies(e)}};var $=class{constructor(e){this.dependencies=[];this.resolvedGraph=e,this.rootPackageName=e.getRootName()}async compute(e){if(!this.resolvedGraph.getPackage(this.rootPackageName))throw new Error(`Root package '${this.rootPackageName}' not found`);let n=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),i=this.resolvedGraph.compilerInputOrder(),s=new Map;for(let r of i){if(r===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(r);if(!o)continue;let a=e.get(r)||{},p=this.extractSourcePaths(r,a),c=o.manifest.edition||"legacy",d=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[r],g=o.manifest.originalId;!g&&o.manifest.publishedAt&&(g=o.manifest.publishedAt),g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",d||(d=g)),s.set(r,g),s.set(r.toLowerCase(),g);let l={...o.resolvedTable||{}};for(let[f,h]of Object.entries(l)){let y=s.get(f)||s.get(f.toLowerCase());y&&(l[f]=y)}g&&r!=="Sui"&&r!=="MoveStdlib"&&(l[r]=g,l[r.toLowerCase()]=g);let m={name:r,isImmediate:n.has(r),sourcePaths:p,addressMapping:l,compilerConfig:{edition:c,flavor:"sui"},moduleFormat:p.length>0?"Source":"Bytecode",edition:c,publishedIdForOutput:d};this.dependencies.push(m)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}extractSourcePaths(e,t){return Object.keys(t).filter(i=>i.endsWith("Move.toml")||i.endsWith("Move.lock")?!1:i.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let n of this.dependencies){let i=e.get(n.name)||{},s={};for(let[r,o]of Object.entries(i)){if(r.endsWith("Move.lock"))continue;let a=`dependencies/${n.name}/${r}`;r.endsWith("Move.toml")?s[a]=this.reconstructDependencyMoveToml(n.name,o,n.edition,n.addressMapping):s[a]=o}t.push({name:n.name,files:s,edition:n.edition,addressMapping:n.addressMapping,publishedIdForOutput:n.publishedIdForOutput})}return t}reconstructDependencyMoveToml(e,t,n,i){let s=(t||"").split(`
2
+ `),r=[],o="none";for(let c of s){let d=c.trim();if(d.startsWith("[")){d.startsWith("[package]")?o="package":d.startsWith("[addresses]")?o="addresses":d.startsWith("[dependencies")||d.startsWith("[dev-dependencies")?o="dependencies":(o="other",r.push(c));continue}if(o==="package")(d.startsWith("name")||d.startsWith("version")||d.startsWith("edition")||d.startsWith("published-at")||d.startsWith("original-published-id"))&&(d.startsWith("published-at")||d.startsWith("original-published-id"))&&r.push(c);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&r.push(c)}}let a=`[package]
3
+ `;a+=`name = "${e}"
4
+ `,a+=`version = "0.0.0"
5
+ `,a+=`edition = "${n}"
9
6
  `,a+=`
10
- [dependencies]
11
- `;for(let d of c)a+=d+`
12
- `;a+=`
7
+ `,a+=r.join(`
8
+ `),a+=`
13
9
  [addresses]
14
- `;for(let[d,p]of Object.entries(n))a+=`${d} = "${p}"
15
- `;return a}};var F=class{constructor(e,t="mainnet",s=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=s}async resolve(e,t){let s=w(e),n=s.package?.name||"RootPackage",r=s.package?.edition,i=new M(n),c=await this.buildPackage(n,this.rootSource,e,t);r&&(c.manifest.edition=r);let o=c.manifest.addresses[n];this.normalizeAddress(o||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&c.manifest.originalId&&(c.manifest.addresses[n]=this.normalizeAddress(c.manifest.originalId)),i.addPackage(c),this.packageFiles.set(n,t);let a=await this.loadFromLockfile(i,c,t),g=Array.from(c.dependencies.keys()).filter(v=>!i.getPackage(v));(!a||g.length>0)&&await this.buildDependencyGraph(i,c);let f=i.detectCycle();if(f)throw new Error(`Dependency cycle detected: ${f.join(" \u2192 ")}`);let d=new D(i,{});await d.resolve();let p=new A(d);await p.compute(this.packageFiles);let m=this.reconstructMoveToml(s,d.getUnifiedAddressTable(),!0,r),y={...t};delete y["Move.lock"],y["Move.toml"]=m;let h=p.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(h)}}async buildPackage(e,t,s,n){let r=w(s),i=n["Move.lock"],c=this.getChainIdForNetwork(this.network),o=this.resolvePublishedAt(s,i,c),u=o.latestId?this.normalizeAddress(o.latestId):void 0,a=n["Published.toml"],g,f;if(a)try{let b=w(a).published?.[this.network];b&&(b["published-at"]&&(g=this.normalizeAddress(b["published-at"])),b["original-id"]&&(f=this.normalizeAddress(b["original-id"])))}catch{}o.error;let d={name:r.package?.name||e,version:r.package?.version||"0.0.0",edition:r.package?.edition,publishedAt:g||o.publishedAt,originalId:f||o.originalId,latestPublishedId:u,addresses:r.addresses||{},dependencies:r.dependencies||{},devDependencies:r["dev-dependencies"]},p=d.publishedAt&&d.publishedAt!=="0x0"?this.normalizeAddress(d.publishedAt):void 0,m=d.addresses[d.name],y=m?this.normalizeAddress(m):void 0;p?d.addresses[d.name]=p:y?d.addresses[d.name]=y:d.addresses[d.name]="0x0";let h=new Map;if(d.dependencies)for(let[k,b]of Object.entries(d.dependencies)){let O=this.parseDependencyInfo(b);O&&h.set(k,O)}return{id:{name:d.name,version:d.version,source:t||{type:"local"}},manifest:d,dependencies:h,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir};else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let s=e["addr-subst"]||e.addr_subst,n={};for(let[r,i]of Object.entries(s))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[r]={type:"assign",address:i}:n[r]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){for(let[s,n]of t.dependencies.entries()){if(n.source.type==="local")if(t.id.source.type==="git"&&n.source.local){let g=t.id.source.subdir||"",f=n.source.local,d=this.resolveRelativePath(g,f);n.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:d}}else continue;if(n.source.type!=="git")continue;let r=`${n.source.git}|${n.source.rev}|${n.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,n.source);g&&e.addDependency(t.id.name,g.id.name,n);continue}this.visited.add(r);let i=n.source.subdir;!i&&n.source.git&&this.isSuiRepo(n.source.git)&&(i=this.inferSuiFrameworkSubdir(s),i&&(n.source.subdir=i));let c=await this.fetcher.fetch(n.source.git,n.source.rev,i),o=null,u=`Move.${this.network}.toml`;for(let[g,f]of Object.entries(c))if(g.endsWith(u)){o=f;break}if(!o){for(let[g,f]of Object.entries(c))if(g.endsWith("Move.toml")){o=f;break}}if(!o)continue;let a=await this.buildPackage(s,n.source,o,c);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(a.manifest.name);if(g){let f=d=>JSON.stringify(d);throw new Error([`Conflicting versions of package '${a.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(n.source)}`,`When resolving dependencies for '${t.id.name}' -> '${s}'`].join(`
16
- `))}this.packageNameCache.set(a.manifest.name,n.source)}a.manifest.publishedAt&&(a.manifest.addresses[a.manifest.name]=this.normalizeAddress(a.manifest.publishedAt)),a.manifest.edition||(a.manifest.edition="legacy"),e.addPackage(a),e.addDependency(t.id.name,a.id.name,n),this.packageFiles.set(a.id.name,c),await this.buildDependencyGraph(e,a)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,s){let n=w(e),r=n.package?.published_at||n.package?.["published-at"],i=r&&r!=="0x0"?r:void 0,c=i?this.normalizeAddress(i):void 0,o=n.package?.["original-id"];return{publishedAt:c,originalId:o}}findPackageBySource(e,t){for(let s of e.getAllPackages()){let n=s.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return s}}resolveRelativePath(e,t){let s=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),r=[...s];for(let i of n)i===".."?r.length>0&&r.pop():i!=="."&&r.push(i);return r.join("/")}async computeManifestDigest(e){let s=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",s);return Array.from(new Uint8Array(n)).map(c=>c.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,s){let n=s["Move.lock"];if(!n)return!1;let r=w(n);this.lockfileVersion=r.move?.version;let i=r.move?.version;return i===3?await this.loadFromLockfileV3(e,r,t):i&&i>=4?r.pinned?await this.loadFromLockfileV4(e,r,s,t):!1:await this.loadFromLockfileV0(e,r,t)}async loadFromLockfileV0(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(a=>a.name||a.id||a).filter(Boolean):[],i=n.map(a=>a.name||a.id).filter(Boolean),c=[...r,...i.filter(a=>!r.includes(a))],o=new Map,u=new Map;for(let a of n){let g=a.id||a.name,f=a.source;if(!g||!f)continue;let d=null;if(f.git&&f.rev)d={type:"git",git:f.git,rev:f.rev,subdir:f.subdir};else if(f.local&&this.rootSource?.type==="git"){let h=this.resolveRelativePath(this.rootSource.subdir||"",f.local);d={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:h}}else continue;let p=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(p).length===0)continue;let m=p["Move.toml"];if(!m)continue;let y=await this.buildPackage(g,d,m,p);o.set(g,y),u.set(y.manifest.name,y),this.packageFiles.set(y.manifest.name,p),e.addPackage(y)}c.length&&e.setLockfileOrder(c);for(let a of n){let g=a.id||a.name,f=o.get(g);if(!f)continue;let d=a.dependencies;if(d&&Array.isArray(d))for(let p of d){let m=p.id||p.name,y=o.get(m)||u.get(m);if(y){let h={source:y.id.source};e.addDependency(f.id.name,y.id.name,h)}}}for(let a of s.dependencies.keys()){let g=u.get(a);if(g){let f=s.dependencies.get(a);e.addDependency(s.id.name,g.id.name,f)}}return o.size>0}async loadFromLockfileV3(e,t,s){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let r=new Map,i=new Map,c=[];for(let o of n)o.id&&i.set(o.id,o);for(let o of n){let u=o.id,a=o.source;c.push(u);let g=null;if(a?.git&&a.rev)g={type:"git",git:a.git,rev:a.rev,subdir:a.subdir};else if(a?.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",a.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;if(!g.git||!g.rev)continue;let f=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(f).length===0)continue;let d=f["Move.toml"];if(!d)continue;let p=await this.buildPackage(u,g,d,f);r.set(u,p),this.packageFiles.set(p.manifest.name,f),e.addPackage(p)}e.setLockfileOrder(c);for(let o of n){let u=o.id,a=r.get(u);if(!a)continue;let g=o.dependencies;if(!(!g||!Array.isArray(g)))for(let f of g){let d=f.id,p=r.get(d);if(!p){let m=i.get(d);if(m?.source?.local&&a.id.source.type==="git"){let y=this.resolveRelativePath(a.id.source.subdir||"",m.source.local),h={type:"git",git:a.id.source.git,rev:a.id.source.rev,subdir:y},v=await this.fetcher.fetch(h.git,h.rev,h.subdir),k=v["Move.toml"];if(k){let b=await this.buildPackage(d,h,k,v);r.set(d,b),this.packageFiles.set(b.manifest.name,v),e.addPackage(b),p=b}}}if(p){let m={source:p.id.source};e.addDependency(a.id.name,p.id.name,m)}}}for(let o of s.dependencies.keys()){let u=r.get(o);if(u){let a=s.dependencies.get(o);e.addDependency(s.id.name,u.id.name,a)}}return!0}async loadFromLockfileV4(e,t,s,n){let r=t.pinned?.[this.network];if(!r)return!1;let i=s["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let c=new Map,o=new Map,u=[];for(let[a,g]of Object.entries(r)){u.push(a);let f=this.lockfileSourceToDependencySource(g.source);if(!f)continue;let d=await this.fetchFromSource(f);if(!d)return!1;let p=d["Move.toml"];if(!p||g["manifest-digest"]&&await this.computeManifestDigest(p)!==g["manifest-digest"])return!1;let m=await this.buildPackage(a,f,p,d);c.set(a,m),o.set(m.manifest.name,m),this.packageFiles.set(m.manifest.name,d),(f.type!=="local"||!("root"in g.source))&&e.addPackage(m)}u.length>0&&e.setLockfileOrder(u);for(let[a,g]of Object.entries(r)){let f=c.get(a);if(f&&g.deps)for(let[d,p]of Object.entries(g.deps)){let m=c.get(p);if(m){let y=f.dependencies.get(d);y&&e.addDependency(f.id.name,m.id.name,y)}}}for(let a of n.dependencies.keys()){let g=o.get(a)||c.get(a);if(g){let f=n.dependencies.get(a);e.addDependency(n.id.name,g.id.name,f)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,s,n){let i=`[package]
10
+ `;let p=Object.entries(i);for(let[c,d]of p)a+=`${c} = "${d}"
11
+ `;return a}};var C=class{constructor(e,t="mainnet",n=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=n}async resolve(e,t){let n=S(e),i=n.package?.name||"RootPackage",s=n.package?.edition,r=new F(i),o=await this.buildPackage(i,this.rootSource,e,t);s&&(o.manifest.edition=s);let a=o.manifest.addresses[i];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[i]=this.normalizeAddress(o.manifest.originalId)),r.addPackage(o),this.packageFiles.set(i,t);let c=await this.loadFromLockfile(r,o,t),d=Array.from(o.dependencies.keys()).filter(k=>!r.getPackage(k));(!c||d.length>0)&&await this.buildDependencyGraph(r,o);let g=r.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let l=new O(r,{});await l.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let f=new $(l);await f.compute(this.packageFiles);let h=l.getUnifiedAddressTable();for(let k of r.getAllPackages()){let w=k.manifest.originalId||k.manifest.publishedAt||k.manifest.latestPublishedId;if(k.manifest.name===o.manifest.name){let P=Object.keys(k.manifest.addresses).find(D=>D.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let D=this.normalizeAddress(k.manifest.addresses[P]);h[k.manifest.name]=D,h[k.manifest.name.toLowerCase()]=D;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}let M=Object.keys(k.manifest.addresses).find(P=>P.toLowerCase()===k.manifest.name.toLowerCase());if(M&&k.manifest.addresses[M]){let P=this.normalizeAddress(k.manifest.addresses[M]);h[k.manifest.name]=P,h[k.manifest.name.toLowerCase()]=P;continue}}let y=this.reconstructMoveToml(n,o.manifest.dependencies,h,!0,s),v={...t};delete v["Move.lock"],v["Move.toml"]=y;let b=f.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(b)}}async buildPackage(e,t,n,i){let s=S(n),r=i["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(n,r,o,this.network),p=a.latestId?this.normalizeAddress(a.latestId):void 0,c=i["Published.toml"],d,g;if(c)try{let I=S(c).published?.[this.network];I&&(I["published-at"]&&(d=this.normalizeAddress(I["published-at"])),I["original-id"]&&(g=this.normalizeAddress(I["original-id"])))}catch{}a.error;let l={name:s.package?.name||e,version:s.package?.version||"0.0.0",edition:s.package?.edition,publishedAt:d||a.publishedAt,originalId:g||a.originalId,latestPublishedId:p,addresses:s.addresses||{},dependencies:this.injectImplicitDependencies(s.dependencies||{},s.package?.name),devDependencies:s["dev-dependencies"]},m=Object.keys(l.addresses).find(w=>w.toLowerCase()===l.name.toLowerCase());if(m&&l.addresses[m]){let w=this.normalizeAddress(l.addresses[m]);w!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(l.originalId=w)}let f=l.originalId||l.publishedAt,h=f&&f!=="0x0"?this.normalizeAddress(f):void 0,y=l.addresses[l.name]||(m?l.addresses[m]:void 0),v=y?this.normalizeAddress(y):void 0;h?y||(l.addresses[l.name]=h):v?l.addresses[l.name]=v:l.addresses[l.name]="0x0";let b=new Map;if(l.dependencies)for(let[w,I]of Object.entries(l.dependencies)){let M=this.parseDependencyInfo(I);M&&b.set(w,M)}return{id:{name:l.name,version:l.version,source:t||{type:"local"}},manifest:l,dependencies:b,devDependencies:new Map}}parseDependencyInfo(e){if(!e)return null;let t={source:{type:"local"}};if(e.git&&e.rev)t.source={type:"git",git:e.git,rev:e.rev,subdir:e.subdir},e.isImplicit&&(t.source.isImplicit=!0);else if(e.local)t.source={type:"local",local:e.local};else return null;if(e["addr-subst"]||e.addr_subst){let n=e["addr-subst"]||e.addr_subst,i={};for(let[s,r]of Object.entries(n))typeof r=="string"&&(r.startsWith("0x")||/^[0-9a-fA-F]+$/.test(r)?i[s]={type:"assign",address:r}:i[s]={type:"renameFrom",name:r});Object.keys(i).length>0&&(t.subst=i)}return t}async buildDependencyGraph(e,t){let n=Array.from(t.dependencies.entries()).sort(([,i],[,s])=>{let r=i.source.isImplicit?1:0;return(s.source.isImplicit?1:0)-r});for(let[i,s]of n){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let g=t.id.source.subdir||"",l=s.source.local,m=this.resolveRelativePath(g,l);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:m}}else continue;if(s.source.type!=="git")continue;let r=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(r)){let g=this.findPackageBySource(e,s.source);g&&e.addDependency(t.id.name,g.id.name,s);continue}this.visited.add(r);let o=s.source.subdir;!o&&s.source.git&&this.isSuiRepo(s.source.git)&&(o=this.inferSuiFrameworkSubdir(i),o&&(s.source.subdir=o));let a=await this.fetcher.fetch(s.source.git,s.source.rev,o),p=null,c=`Move.${this.network}.toml`;for(let[g,l]of Object.entries(a))if(g.endsWith(c)){p=l;break}if(!p){for(let[g,l]of Object.entries(a))if(g.endsWith("Move.toml")){p=l;break}}if(!p)continue;let d=await this.buildPackage(i,s.source,p,a);if(!this.lockfileVersion||this.lockfileVersion<4){let g=this.packageNameCache.get(d.manifest.name);if(g){let l=g.isImplicit,m=s.source.isImplicit;if(l&&!m)continue;if(!(!l&&m)){if(JSON.stringify(g)!==JSON.stringify(s.source)){let f=h=>JSON.stringify(h);throw new Error([`Conflicting versions of package '${d.manifest.name}' found`,`Existing: ${f(g)}`,`New: ${f(s.source)}`,`When resolving dependencies for '${t.id.name}' -> '${i}'`].join(`
12
+ `))}}}this.packageNameCache.set(d.manifest.name,s.source)}d.manifest.edition||(d.manifest.edition="legacy"),e.addPackage(d),e.addDependency(t.id.name,d.id.name,s),this.packageFiles.set(d.id.name,a),await this.buildDependencyGraph(e,d)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,n,i){let s=S(e),r=s.package?.published_at||s.package?.["published-at"],o=r&&r!=="0x0"?r:void 0,a=o?this.normalizeAddress(o):void 0,p=s.package?.["original-id"],c,d;if(t)try{let f=S(t),h=n&&f.env?.[n]||f.env?.[i];h&&(h["original-published-id"]&&(c=this.normalizeAddress(h["original-published-id"])),h["latest-published-id"]&&(d=this.normalizeAddress(h["latest-published-id"])))}catch{}let g=a||d||c;return{publishedAt:g,originalId:p||c,latestId:g}}findPackageBySource(e,t){for(let n of e.getAllPackages()){let i=n.id.source;if(i.type===t.type&&i.git===t.git&&i.rev===t.rev&&i.subdir===t.subdir)return n}}resolveRelativePath(e,t){let n=e?e.split("/").filter(Boolean):[],i=t.split("/").filter(Boolean),s=[...n];for(let r of i)r===".."?s.length>0&&s.pop():r!=="."&&s.push(r);return s.join("/")}async computeManifestDigest(e){let n=new TextEncoder().encode(e),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,n){let i=n["Move.lock"];if(!i)return!1;let s=S(i);this.lockfileVersion=s.move?.version;let r=s.move?.version;return r===3?await this.loadFromLockfileV3(e,s,t):r&&r>=4?s.pinned?await this.loadFromLockfileV4(e,s,n,t):!1:await this.loadFromLockfileV0(e,s,t)}async loadFromLockfileV0(e,t,n){let i=t.move?.package;if(!i||!Array.isArray(i))return!1;let s=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(c=>c.name||c.id||c).filter(Boolean):[],r=i.map(c=>c.name||c.id).filter(Boolean),o=[...s,...r.filter(c=>!s.includes(c))],a=new Map,p=new Map;for(let c of i){let d=c.id||c.name,g=c.source;if(!d||!g)continue;let l=null;if(g.git&&g.rev)l={type:"git",git:g.git,rev:g.rev,subdir:g.subdir};else if(g.local&&this.rootSource?.type==="git"){let y=this.resolveRelativePath(this.rootSource.subdir||"",g.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:y}}else continue;let m=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(m).length===0)continue;let f=m["Move.toml"];if(!f)continue;let h=await this.buildPackage(d,l,f,m);a.set(d,h),p.set(h.manifest.name,h),this.packageFiles.set(h.manifest.name,m),e.addPackage(h)}o.length&&e.setLockfileOrder(o);for(let c of i){let d=c.id||c.name,g=a.get(d);if(!g)continue;let l=c.dependencies;if(l&&Array.isArray(l))for(let m of l){let f=m.id||m.name,h=a.get(f)||p.get(f);if(h){let y={source:h.id.source};e.addDependency(g.id.name,h.id.name,y)}}}for(let c of n.dependencies.keys()){let d=p.get(c);if(d){let g=n.dependencies.get(c);e.addDependency(n.id.name,d.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,n){let i=t.move?.package;if(!i||!Array.isArray(i))return!1;let s=new Map,r=new Map,o=[];for(let a of i)a.id&&r.set(a.id,a);for(let a of i){let p=a.id,c=a.source;o.push(p);let d=null;if(c?.git&&c.rev)d={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let f=this.resolveRelativePath(this.rootSource.subdir||"",c.local);d={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:f}}else continue;if(!d.git||!d.rev)continue;let g=await this.fetcher.fetch(d.git,d.rev,d.subdir);if(Object.keys(g).length===0)continue;let l=g["Move.toml"];if(!l)continue;let m=await this.buildPackage(p,d,l,g);s.set(p,m),this.packageFiles.set(m.manifest.name,g),e.addPackage(m)}e.setLockfileOrder(o);for(let a of i){let p=a.id,c=s.get(p);if(!c)continue;let d=a.dependencies;if(!(!d||!Array.isArray(d)))for(let g of d){let l=g.id,m=s.get(l);if(!m){let f=r.get(l);if(f?.source?.local&&c.id.source.type==="git"){let h=this.resolveRelativePath(c.id.source.subdir||"",f.source.local),y={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:h},v=await this.fetcher.fetch(y.git,y.rev,y.subdir),b=v["Move.toml"];if(b){let k=await this.buildPackage(l,y,b,v);s.set(l,k),this.packageFiles.set(k.manifest.name,v),e.addPackage(k),m=k}}}if(m){let f={source:m.id.source};e.addDependency(c.id.name,m.id.name,f)}}}for(let a of n.dependencies.keys()){let p=s.get(a);if(p){let c=n.dependencies.get(a);e.addDependency(n.id.name,p.id.name,c)}}return!0}async loadFromLockfileV4(e,t,n,i){let s=t.pinned?.[this.network];if(!s)return!1;let r=n["Move.toml"];if(r&&t.move?.manifest_digest&&await this.computeManifestDigest(r)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,p=[];for(let[c,d]of Object.entries(s)){p.push(c);let g=this.lockfileSourceToDependencySource(d.source);if(!g)continue;let l=await this.fetchFromSource(g);if(!l)return!1;let m=l["Move.toml"];if(!m||d["manifest-digest"]&&await this.computeManifestDigest(m)!==d["manifest-digest"])return!1;let f=await this.buildPackage(c,g,m,l);o.set(c,f),a.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,l),(g.type!=="local"||!("root"in d.source))&&e.addPackage(f)}p.length>0&&e.setLockfileOrder(p);for(let[c,d]of Object.entries(s)){let g=o.get(c);if(g&&d.deps)for(let[l,m]of Object.entries(d.deps)){let f=o.get(m);if(f){let h=g.dependencies.get(l);h&&e.addDependency(g.id.name,f.id.name,h)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let d=c.id,g=o.get(d);if(g){let l={source:g.id.source};e.addDependency(i.id.name,g.id.name,l)}}else for(let c of i.dependencies.keys()){let d=a.get(c)||o.get(c);if(d){let g=i.dependencies.get(c);e.addDependency(i.id.name,d.id.name,g)}}return!0}lockfileSourceToDependencySource(e){return"git"in e?{type:"git",git:e.git,rev:e.rev,subdir:e.subdir}:"local"in e?{type:"local",local:e.local}:"root"in e?{type:"local"}:null}async fetchFromSource(e){if(e.type==="git"&&e.git&&e.rev)try{return await this.fetcher.fetch(e.git,e.rev,e.subdir)}catch{return null}return null}reconstructMoveToml(e,t,n,i,s){let o=`[package]
17
13
  name = "${e.package.name}"
18
14
  version = "${e.package.version}"
19
- `,c=n||e.package.edition;if(c&&(i+=`edition = "${c}"
20
- `),i+=`
15
+ `,a=s||e.package.edition;if(a&&(o+=`edition = "${a}"
16
+ `),o+=`
21
17
  [dependencies]
22
- `,e.dependencies)for(let[o,u]of Object.entries(e.dependencies)){let a=u;a.local?i+=`${o} = { local = "${a.local}" }
23
- `:a.git&&a.rev&&(a.subdir?i+=`${o} = { git = "${a.git}", subdir = "${a.subdir}", rev = "${a.rev}" }
24
- `:i+=`${o} = { git = "${a.git}", rev = "${a.rev}" }
25
- `)}i+=`
18
+ `,t){let c=Object.entries(t);for(let[d,g]of c){let l=g;l.local?o+=`${d} = { local = "${l.local}" }
19
+ `:l.git&&l.rev&&(l.subdir?o+=`${d} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
20
+ `:o+=`${d} = { git = "${l.git}", rev = "${l.rev}" }
21
+ `)}}o+=`
26
22
  [addresses]
27
- `;for(let[o,u]of Object.entries(t))i+=`${o} = "${u}"
28
- `;return i}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",DeepBook:"crates/sui-framework/packages/deepbook",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}};async function G(l,e,t,s="mainnet",n){return new F(t,s,n||null).resolve(l,e)}function j(l){try{let e=new URL(l);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let s=t[0],n=t[1],r="main",i;return t.length>=4&&t[2]==="tree"&&(r=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:s,repo:n,ref:r,subdir:i}}catch{return null}}async function U(l,e){let t=j(l);if(!t)throw new Error(`Invalid GitHub URL: ${l}`);let s=e?.fetcher||new S(e?.githubToken),n=e?.includeLock!==!1,r=`https://github.com/${t.owner}/${t.repo}.git`,i=await s.fetch(r,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:r,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":c,...o}=i;return o}return i}var T;async function P(l){return T||(T=import("./sui_move_wasm.js").then(async e=>(l?await e.default(l):await e.default(),e))),T}function I(l){return{error:l instanceof Error?l.message:typeof l=="string"?l:"Unknown error"}}function B(l){if(typeof l!="object"||l===null)throw new Error("Unexpected compile result shape from wasm");let e=l;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function E(l){let e=t=>{let s=t.startsWith("0x")?t.slice(2):t,n=s.length%2===0?s:`0${s}`,r=[];for(let i=0;i<n.length;i+=2){let c=parseInt(n.slice(i,i+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");r.push(c)}return r};try{let t=JSON.parse(l);if(!t.modules||!t.dependencies||!t.digest)throw new Error("missing fields in compiler output");let s=typeof t.digest=="string"?e(t.digest):Array.from(t.digest);return{modules:t.modules,dependencies:t.dependencies,digest:s}}catch(t){return I(t)}}function C(l){try{let e=JSON.parse(l);for(let t of e){let s=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let r=w(n[1]);return r.addresses&&r.addresses[t.name]||r.package?.published_at||r.package?.["published-at"]})()}}catch{}}async function ge(l){await P(l?.wasm)}async function W(l){let e=l.files["Move.toml"]||"",t=l.rootGit||l.files.__rootGit,s=await G(e,{...l.files,"Move.toml":e},new S(l.githubToken),l.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:s.files,dependencies:s.dependencies}}async function ue(l){try{let e={};for(let[o,u]of Object.entries(l.files))(o.endsWith(".move")||o.endsWith("Move.toml")||o.endsWith("Move.lock")||o.endsWith("Published.toml"))&&(e[o]=u);l.files=e;let t=l.resolvedDependencies?l.resolvedDependencies:await W(l),s=await P(l.wasm);C(t.dependencies);let n=s.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:l.silenceWarnings,testMode:l.testMode,lintFlag:l.lintFlag,stripMetadata:l.stripMetadata})),r=B(n),i=r.success(),c=r.output();return i?E(c):I(c)}catch(e){return I(e)}}async function pe(l){try{let e=l.resolvedDependencies?l.resolvedDependencies:await W(l),t=await P(l.wasm);C(e.dependencies);let s=l.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof s.passed=="boolean"&&typeof s.output=="string")return{passed:s.passed,output:s.output};let n=typeof s.passed=="function"?s.passed():s.passed,r=typeof s.output=="function"?s.output():s.output;return{passed:n,output:r}}catch(e){return I(e)}}async function fe(l){return(await P(l?.wasm)).sui_move_version()}async function he(l){return(await P(l?.wasm)).sui_version()}async function me(l){return P(l?.wasm)}async function ye(l,e,t){let s=await P(t?.wasm),n=t?.ansiColor&&typeof s.compile_with_color=="function"?s.compile_with_color(l,e,!0):s.compile(l,e,JSON.stringify({silenceWarnings:!1})),r=B(n);return{success:r.success(),output:r.output()}}export{ue as buildMovePackage,ye as compileRaw,U as fetchPackageFromGitHub,fe as getSuiMoveVersion,he as getSuiVersion,me as getWasmBindings,ge as initMoveCompiler,W as resolveDependencies,pe as testMovePackage};
23
+ `;let p=Object.entries(n);for(let[c,d]of p)o+=`${c} = "${d}"
24
+ `;return o}normalizeAddress(e){if(!e)return e;let t=e.trim();return t.startsWith("0x")&&(t=t.slice(2)),/^[0-9a-fA-F]+$/.test(t)?"0x"+t.padStart(64,"0"):e}isSuiRepo(e){return e.includes("github.com/MystenLabs/sui")}inferSuiFrameworkSubdir(e){let t={Sui:"crates/sui-framework/packages/sui-framework",MoveStdlib:"crates/sui-framework/packages/move-stdlib",SuiSystem:"crates/sui-framework/packages/sui-system",Bridge:"crates/sui-framework/packages/bridge",SuiFramework:"crates/sui-framework/packages/sui-framework"};return t[e]||t[e.toLowerCase()]}injectImplicitDependencies(e,t){return t==="Sui"||t==="MoveStdlib"||t==="SuiSystem"||t==="sui"||!e.Sui&&!e.sui&&(e.Sui={git:"https://github.com/MystenLabs/sui.git",subdir:"crates/sui-framework/packages/sui-framework",rev:"framework/mainnet",isImplicit:!0}),e}};async function j(u,e,t,n="mainnet",i){return new C(t,n,i||null).resolve(u,e)}function V(u){try{let e=new URL(u);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let n=t[0],i=t[1],s="main",r;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(r=t.slice(4).join("/"))),{owner:n,repo:i,ref:s,subdir:r}}catch{return null}}async function H(u,e){let t=V(u);if(!t)throw new Error(`Invalid GitHub URL: ${u}`);let n=e?.fetcher||new A(e?.githubToken),i=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,r=await n.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(r,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!i&&r["Move.lock"]){let{"Move.lock":o,...a}=r;return a}return r}var W;async function R(u){return W||(W=import("./sui_move_wasm.js").then(async e=>(u?await e.default(u):await e.default(),e))),W}function T(u){return{error:u instanceof Error?u.message:typeof u=="string"?u:"Unknown error"}}function _(u){if(typeof u!="object"||u===null)throw new Error("Unexpected compile result shape from wasm");let e=u;if(typeof e.success=="function"&&typeof e.output=="function")return e;if(typeof e.success=="boolean"&&typeof e.output=="string")return{success:()=>e.success,output:()=>e.output};throw new Error("Unexpected compile result shape from wasm")}function J(u,e){let t=n=>{let i=n.startsWith("0x")?n.slice(2):n,s=i.length%2===0?i:`0${i}`,r=[];for(let o=0;o<s.length;o+=2){let a=parseInt(s.slice(o,o+2),16);if(Number.isNaN(a))throw new Error("invalid hex digest");r.push(a)}return r};try{let n=JSON.parse(u);if(!n.modules||!n.dependencies||!n.digest)throw new Error("missing fields in compiler output");let i=typeof n.digest=="string"?t(n.digest):Array.from(n.digest),s=n.dependencies;return e&&(s=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),s.sort((r,o)=>{let a=e.get(r)||"",p=e.get(o)||"";return a<p?-1:a>p?1:0})),{modules:n.modules,dependencies:s,digest:i}}catch(n){return T(n)}}function U(u){try{let e=JSON.parse(u);for(let t of e){let n=t.addressMapping?.[t.name]??(()=>{let i=Object.entries(t.files).find(([r])=>r.endsWith("Move.toml"));if(!i)return;let s=S(i[1]);return s.addresses&&s.addresses[t.name]||s.package?.published_at||s.package?.["published-at"]})()}}catch{}}async function me(u){await R(u?.wasm)}async function E(u){let e=u.files["Move.toml"]||"",t=u.rootGit||u.files.__rootGit,n=await j(e,{...u.files,"Move.toml":e},new A(u.githubToken),u.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:n.files,dependencies:n.dependencies}}async function he(u){try{let e={};for(let[p,c]of Object.entries(u.files))(p.endsWith(".move")||p.endsWith("Move.toml")||p.endsWith("Move.lock")||p.endsWith("Published.toml"))&&(e[p]=c);u.files=e;let t=u.resolvedDependencies?u.resolvedDependencies:await E(u),n=await R(u.wasm);U(t.dependencies);let i=new Map;try{let p=JSON.parse(t.dependencies);for(let c of p)!c.publishedIdForOutput||c.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(c.publishedIdForOutput)||i.set(c.publishedIdForOutput,c.name)}catch{}let s=n.compile(t.files,t.dependencies,JSON.stringify({silenceWarnings:u.silenceWarnings,testMode:u.testMode,lintFlag:u.lintFlag,stripMetadata:u.stripMetadata})),r=_(s),o=r.success(),a=r.output();return o?J(a,i):T(a)}catch(e){return T(e)}}async function ye(u){try{let e=u.resolvedDependencies?u.resolvedDependencies:await E(u),t=await R(u.wasm);U(e.dependencies);let n=u.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof n.passed=="boolean"&&typeof n.output=="string")return{passed:n.passed,output:n.output};let i=typeof n.passed=="function"?n.passed():n.passed,s=typeof n.output=="function"?n.output():n.output;return{passed:i,output:s}}catch(e){return T(e)}}async function ve(u){return(await R(u?.wasm)).sui_move_version()}async function ke(u){return(await R(u?.wasm)).sui_version()}async function be(u){return R(u?.wasm)}async function we(u,e,t){let n=await R(t?.wasm),i=t?.ansiColor&&typeof n.compile_with_color=="function"?n.compile_with_color(u,e,!0):n.compile(u,e,JSON.stringify({silenceWarnings:!1})),s=_(i);return{success:s.success(),output:s.output()}}export{he as buildMovePackage,we as compileRaw,H as fetchPackageFromGitHub,ve as getSuiMoveVersion,ke as getSuiVersion,be as getWasmBindings,me as initMoveCompiler,E as resolveDependencies,ye as testMovePackage};
@@ -110,8 +110,8 @@ function __wbg_get_imports() {
110
110
  __wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
111
111
  throw new Error(getStringFromWasm0(arg0, arg1));
112
112
  },
113
- __wbg_log_098460783f5a8b3c: function(arg0, arg1) {
114
- console.log(getStringFromWasm0(arg0, arg1));
113
+ __wbg_warn_4b3c7c44b93d17a4: function(arg0, arg1) {
114
+ console.warn(getStringFromWasm0(arg0, arg1));
115
115
  },
116
116
  };
117
117
  return {
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zktx.io/sui-move-builder",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Build Move packages in web or Node.js with dependency fetching and dump outputs.",
5
5
  "keywords": [
6
6
  "sui",
@@ -52,8 +52,8 @@
52
52
  "build:js": "tsup --out-dir dist/full && tsup --out-dir dist/lite",
53
53
  "build": "npm run build:wasm && npm run build:js",
54
54
  "serve:test": "python3 -m http.server 8000 --directory .",
55
- "test:integration": "node test/integration/fidelity_test.mjs",
56
- "test:lite": "node test/integration/fidelity_test_lite.mjs",
55
+ "test:integration": "node test/integration/fidelity_test.mjs full",
56
+ "test:lite": "node test/integration/fidelity_test.mjs lite",
57
57
  "test": "npm run test:integration",
58
58
  "prepublishOnly": "npm run build"
59
59
  },