@zktx.io/sui-move-builder 0.2.6 → 0.2.7

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,6 +1,6 @@
1
1
  # @zktx.io/sui-move-builder
2
2
 
3
- > **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (tag: `v1.63.3`)
3
+ > **Upstream source:** [MystenLabs/sui](https://github.com/MystenLabs/sui) (see `sui-version.json`)
4
4
 
5
5
  Build Move packages in web or Node.js with Sui CLI-compatible dependency resolution and compilation.
6
6
 
@@ -10,7 +10,7 @@ Build Move packages in web or Node.js with Sui CLI-compatible dependency resolut
10
10
  - ✅ **Verified Parity**: Audited against `sui-04dd` source code (Jan 2026), byte-level module comparison
11
11
  - ✅ **Address Resolution**: Supports `original_id` for compilation, `published_at` for metadata (CLI-identical)
12
12
  - ✅ **Lockfile Support**: Reads `Move.lock` v0/v3/v4 for faster, deterministic builds
13
- - ✅ **Move.lock V4 Output**: Generates **V4 format** (`version = 4`) with CLI-compatible `manifest_digest`
13
+ - ✅ **Move.lock V4 Output**: Generates **V4 format** with CLI-compatible **lexicographical sorting** and `manifest_digest`
14
14
  - ✅ **Published.toml Support**: Reads deployment records per environment
15
15
  - ✅ **Per-Package Editions**: Each package can use its own Move edition (legacy, 2024.alpha, 2024.beta)
16
16
  - ✅ **Monorepo Support**: Handles local dependencies in monorepo structures
@@ -92,15 +92,35 @@ const result = await buildMovePackage({
92
92
  });
93
93
 
94
94
  if (result.success) {
95
- console.log("Digest:", result.digest);
96
- console.log("Modules:", result.modules); // Base64-encoded bytecode
97
- console.log("Move.lock:", result.moveLock); // V4 lockfile content
98
- console.log("Environment:", result.environment); // e.g., "mainnet"
95
+ // Compilation outputs
96
+ console.log("Modules:", result.modules); // Array<string>: Base64-encoded bytecode
97
+ console.log("Dependencies:", result.dependencies); // Array<string>: Hex-encoded package IDs
98
+ console.log("Digest:", result.digest); // Array<number>: Package digest bytes
99
+
100
+ // Lockfile outputs
101
+ console.log("Move.lock:", result.moveLock); // string: V4 lockfile content (CLI-compatible)
102
+ console.log("Environment:", result.environment); // string: e.g., "mainnet"
103
+
104
+ // Migration output (V3 → V4)
105
+ if (result.publishedToml) {
106
+ console.log("Published.toml:", result.publishedToml); // string: Migrated from legacy Move.lock
107
+ }
99
108
  } else {
100
109
  console.error("Build failed:", result.error);
101
110
  }
102
111
  ```
103
112
 
113
+ ### Build Output Reference
114
+
115
+ | Field | Type | Description |
116
+ | --------------- | ---------- | ---------------------------------------------- |
117
+ | `modules` | `string[]` | Base64-encoded compiled bytecode modules |
118
+ | `dependencies` | `string[]` | Hex-encoded package IDs for linking |
119
+ | `digest` | `number[]` | Package digest bytes (32 bytes) |
120
+ | `moveLock` | `string` | Generated Move.lock V4 content |
121
+ | `environment` | `string` | Build environment (e.g., "mainnet", "testnet") |
122
+ | `publishedToml` | `string?` | Migrated Published.toml (if V3→V4 migration) |
123
+
104
124
  ## Fetching packages from GitHub
105
125
 
106
126
  ```ts
@@ -260,19 +280,26 @@ npm run test:lite # Run fidelity tests (lite version)
260
280
  npm test # Run full integration tests
261
281
  ```
262
282
 
263
- **Test Cases (verified against Sui CLI):**
283
+ **Test Cases (verified against sui-mainnet-v1.63.3):**
264
284
 
265
- - `nautilus.enclave` - Simple package with framework dependencies
266
- - `apps.kiosk` - Mysten Labs kiosk package
267
- - `deeptrade-core` - Complex package with Pyth/Deepbook dependencies
285
+ | Package | Modules | Dependencies | Digest | Lockfile |
286
+ | ----------- | ------- | ------------ | ------ | ---------------------- |
287
+ | `nautilus` | ✅ | ✅ | ✅ | ✅ |
288
+ | `deepbook` | ✅ | ✅ | ✅ | ✅ (mainnet + testnet) |
289
+ | `deeptrade` | ✅ | ✅ | ✅ | ✅ (diamond deps) |
268
290
 
269
291
  All tests verify:
270
292
 
271
293
  - ✅ Module bytecode (identical to CLI `.mv` output)
272
294
  - ✅ Dependency IDs (exact match with CLI)
273
- - ✅ Dependency order (lexicographical, CLI-consistent)
295
+ - ✅ Package digest (identical hash)
296
+ - ✅ Move.lock V4 content (all environments preserved)
297
+ - ✅ manifest_digest calculation (CLI-compatible)
274
298
 
275
299
  ## Roadmap
276
300
 
277
- - ✅ **Move.lock V4 Generation**: Build results now include CLI-compatible `moveLock` field
278
- - **Published.toml Generation**: Future updates will include generating `Published.toml` for deployment tracking
301
+ - ✅ **Move.lock V4 Generation**: CLI-compatible with deterministic sorting and manifest_digest
302
+ - **Multi-Environment Support**: Preserves all environments from existing Move.lock
303
+ - ✅ **V3→V4 Migration**: Automatically generates Published.toml from legacy Move.lock
304
+ - **Published.toml Generation**: Generate Published.toml after successful deployment
305
+ - **Bytecode Dependencies**: Support for .mv-only dependencies (CLI fallback path)
@@ -1,25 +1,27 @@
1
- "use strict";var q=Object.create;var $=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var ee=(c,e)=>{for(var t in e)$(c,t,{get:e[t],enumerable:!0})},j=(c,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of X(e))!Z.call(c,n)&&n!==t&&$(c,n,{get:()=>e[n],enumerable:!(r=Q(e,n))||r.enumerable});return c};var te=(c,e,t)=>(t=c!=null?q(Y(c)):{},j(e||!c||!c.__esModule?$(t,"default",{value:c,enumerable:!0}):t,c)),se=c=>j($({},"__esModule",{value:!0}),c);var fe={};ee(fe,{buildMovePackage:()=>ce,compileRaw:()=>pe,fetchPackageFromGitHub:()=>H,getSuiMoveVersion:()=>le,getSuiVersion:()=>ge,getWasmBindings:()=>ue,initMoveCompiler:()=>ae,resolveDependencies:()=>W,testMovePackage:()=>de});module.exports=se(fe);var C=class{async fetch(e,t,r){throw new Error("Not implemented")}async fetchFile(e,t,r){throw new Error("Not implemented")}getResolvedSha(e,t){}},D=class extends C{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.resolvedShaCache=new Map,this.token=t}getResolvedSha(t,r){let{owner:n,repo:s}=this.parseGitUrl(t);if(!n||!s)return;let i=`${n}/${s}@${r}`;return this.resolvedShaCache.get(i)}updateRateLimit(t){let r=t.headers.get("x-ratelimit-remaining"),n=t.headers.get("x-ratelimit-reset");r&&(this.rateLimitRemaining=parseInt(r,10)),n&&(this.rateLimitReset=parseInt(n,10)*1e3)}async fetch(t,r,n,s){let{owner:i,repo:o}=this.parseGitUrl(t);if(!i||!o)throw new Error(`Invalid git URL: ${t}`);let a=`${i}/${o}@${r}`,h=`https://api.github.com/repos/${i}/${o}/git/trees/${r}?recursive=1`,d;if(this.treeCache.has(a))d=this.treeCache.get(a);else{let u=null;for(let f=1;f<=3;f++)try{if(f>1){let b=Math.pow(2,f-1)*1e3;await new Promise(k=>setTimeout(k,b))}let v={};this.token&&(v.Authorization=`Bearer ${this.token}`);let y=await fetch(h,{headers:v});if(this.updateRateLimit(y),!y.ok){if(y.status===403||y.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(y.status>=500&&y.status<600&&f<3){u=new Error(`Failed to fetch tree: ${y.statusText}`);continue}throw new Error(`Failed to fetch tree: ${y.statusText}`)}d=await y.json(),this.treeCache.set(a,d),d.sha&&this.resolvedShaCache.set(a,d.sha);break}catch(v){if(u=v instanceof Error?v:new Error(String(v)),f===3)return{}}if(u)return{}}let p=new Map,g={},l=[];for(let m of d.tree){if(m.type!=="blob")continue;let u=m.path;if(n){let y=n.endsWith("/")?n:n+"/";if(!m.path.startsWith(y))continue;u=m.path.slice(y.length)}if(!u.endsWith(".move")&&u!=="Move.toml"&&u!=="Move.lock"&&!u.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;u==="Move.toml"&&m.mode&&p.set("Move.toml",m.mode);let f=`https://raw.githubusercontent.com/${i}/${o}/${r}/${m.path}`,v=this.fetchContent(f).then(y=>{y&&(g[u]=y)});l.push(v)}if(await Promise.all(l),g["Move.toml"]&&p.get("Move.toml")==="120000"){let u=g["Move.toml"].trim(),f=n?`${n}/${u}`.replace(/\/+/g,"/"):u,v=`https://raw.githubusercontent.com/${i}/${o}/${r}/${f}`,y=await this.fetchContent(v);y&&(g["Move.toml"]=y)}return g}async fetchFile(t,r,n){let{owner:s,repo:i}=this.parseGitUrl(t);if(!s||!i)throw new Error(`Invalid git URL: ${t}`);let o=`https://raw.githubusercontent.com/${s}/${i}/${r}/${n}`;return this.fetchContent(o)}async fetchContent(t){if(this.cache.has(t))return this.cache.get(t)??null;try{let r={},n=typeof window<"u",s=t.startsWith("https://api.github.com/");this.token&&(!n||s)&&(r.Authorization=`Bearer ${this.token}`);let i=await fetch(t,{headers:r});if(!i.ok)return null;let o=await i.text();return this.cache.set(t,o),o}catch{return null}}parseGitUrl(t){try{let n=new URL(t).pathname.split("/").filter(s=>s);if(n.length>=2){let s=n[1];return s.endsWith(".git")&&(s=s.slice(0,-4)),{owner:n[0],repo:s}}}catch{}return{owner:null,repo:null}}};function x(c){let e=!1,t="";for(let r=0;r<c.length;r++){let n=c[r];if((n==='"'||n==="'")&&(!e||n===t)&&(e=!e,t=n),!e&&n==="#")return c.slice(0,r)}return c}function _(c){let e=c.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 E(c){let e={},t=c.trim().replace(/^\{/,"").replace(/\}$/,""),r="",n=!1,s="",i=[];for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===s)&&(n=!n,s=a),!n&&a===","){i.push(r),r="";continue}r+=a}r.trim()&&i.push(r);for(let o of i){let a=o.indexOf("=");if(a===-1)continue;let h=o.slice(0,a).trim(),d=o.slice(a+1).trim();e[h]=_(d)}return e}function ne(c){let e=[],t=c.trim().replace(/^\[/,"").replace(/\]$/,""),r="",n=!1,s="",i=0;for(let o=0;o<t.length;o++){let a=t[o];if((a==='"'||a==="'")&&(!n||a===s)&&(n=!n,s=n?a:""),!n&&(a==="{"&&i++,a==="}"&&i--,a===","&&i===0)){r.trim()&&e.push(U(r.trim())),r="";continue}r+=a}return r.trim()&&e.push(U(r.trim())),e}function U(c){return c.startsWith("{")?E(c):_(c)}function S(c){let e={},t=null,r=!1,n=c.split(/\r?\n/),s=[],i=0;for(;i<n.length;){let a=x(n[i]);if(a.match(/=\s*\[\s*$/)||a.includes("=")&&a.includes("[")&&!a.includes("]")){let h=a;for(i++;i<n.length&&!h.includes("]");)h+=" "+x(n[i]).trim(),i++;i<n.length&&h.includes("[")&&!h.includes("]")&&(h+=" "+x(n[i]).trim(),i++),s.push(h)}else s.push(a),i++}function o(a,h){let d=a;for(let p of h){if(!(p in d))return;d=d[p]}return d}for(let a of s){let h=x(a).trim();if(!h)continue;let d=h.match(/^\[\[([^\]]+)\]\]$/);if(d){t=d[1].trim(),r=!0;let f=t.split("."),v=e;for(let b=0;b<f.length-1;b++){let k=f[b];k in v||(v[k]={}),v=v[k]}let y=f[f.length-1];Array.isArray(v[y])||(v[y]=[]),v[y].push({});continue}let p=h.match(/^\[([^\]]+)\]$/);if(p){t=p[1].trim(),r=!1;continue}let g=h.indexOf("=");if(g===-1||!t)continue;let l=h.slice(0,g).trim(),m=h.slice(g+1).trim(),u;if(m.startsWith("{")?u=E(m):m.startsWith("[")?u=ne(m):u=_(m),r){let f=t.split("."),v=o(e,f);if(Array.isArray(v)&&v.length>0){let y=v[v.length-1];y[l]=u}}else{let f=t.split("."),v=e;for(let b of f)b in v||(v[b]={}),v=v[b];let y=t==="package"?l.replace(/-/g,"_"):l;v[y]=u}}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,r){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,r=new Set,n=s=>{if(r.has(s))return;r.add(s),t.add(s);let i=this.graph.get(s);if(i)for(let o of i)n(o)};return n(e),t.delete(e),t}topologicalOrder(){let e=new Set,t=[],r=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let i=Array.from(s).sort();for(let o of i)r(o)}t.push(n)};return r(this.root),t.filter(n=>n!==this.root)}compilerInputOrder(){let e=new Set,t=[],r=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s){let i=Array.from(s).sort();for(let o of i)r(o)}t.push(n)};return r(this.root),t}topologicalOrderDFS(){let e=new Set,t=[],r=n=>{if(e.has(n))return;e.add(n);let s=this.graph.get(n);if(s)for(let i of Array.from(s))r(i);t.push(n)};r(this.root);for(let n of this.packageTable.keys())r(n);return t}detectCycle(){let e=new Set,t=new Set,r=new Map,n=s=>{e.add(s),t.add(s);let i=this.graph.get(s);if(i)for(let o of i)if(e.has(o)){if(t.has(o)){let a=[o],h=s;for(;h!==o;)a.unshift(h),h=r.get(h);return a.unshift(o),a}}else{r.set(o,s);let a=n(o);if(a)return a}return t.delete(s),null};for(let s of this.packageTable.keys())if(!e.has(s)){let i=n(s);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 F=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 r of t){let n=this.graph.getPackage(r);if(n)for(let[s,i]of Object.entries(n.manifest.addresses)){let o=this.normalizeAddress(i);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==o||this.unifiedAddressTable.set(s,o)}}for(let r of this.graph.getAllPackages()){let n={};for(let[s,i]of this.unifiedAddressTable.entries())n[s]=i;this.packageResolvedTables.set(r.id.name,n),r.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,r]of this.unifiedAddressTable.entries())e[t]=r;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 L=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 r=this.resolvedGraph.getImmediateDependencies(this.rootPackageName),n=this.resolvedGraph.compilerInputOrder(),s=new Map;for(let i of n){if(i===this.rootPackageName)continue;let o=this.resolvedGraph.getPackage(i);if(!o)continue;let a=e.get(i)||{},h=this.extractSourcePaths(i,a),d=o.manifest.edition||"legacy",p=o.manifest.latestPublishedId||o.manifest.publishedAt||o.manifest.originalId||o.resolvedTable?.[i],g=o.manifest.originalId;!g&&o.manifest.publishedAt&&(g=o.manifest.publishedAt),g||(g="0x0000000000000000000000000000000000000000000000000000000000000000",p||(p=g)),s.set(i,g),s.set(i.toLowerCase(),g);let l={...o.resolvedTable||{}};for(let[y,b]of Object.entries(l)){let k=s.get(y)||s.get(y.toLowerCase());k&&(l[y]=k)}g&&i!=="Sui"&&i!=="MoveStdlib"&&(l[i]=g,l[i.toLowerCase()]=g);let m=o.id.source,u={type:m.type,git:m.git,rev:m.rev,subdir:m.subdir,local:m.local},f=Object.keys(o.manifest.dependencies||{}),v={name:i,isImmediate:r.has(i),sourcePaths:h,addressMapping:l,compilerConfig:{edition:d,flavor:"sui"},moduleFormat:h.length>0?"Source":"Bytecode",edition:d,publishedIdForOutput:p,source:u,manifestDeps:f,manifest:{name:o.manifest.name,dependencies:o.manifest.dependencies}};this.dependencies.push(v)}}getDependencyAddress(e){return this.dependencies.find(t=>t.name===e)?.publishedIdForOutput}extractSourcePaths(e,t){return Object.keys(t).filter(n=>n.endsWith("Move.toml")||n.endsWith("Move.lock")?!1:n.endsWith(".move"))}toPackageGroupedFormat(e){let t=[];for(let r of this.dependencies){let n=e.get(r.name)||{},s={};for(let[i,o]of Object.entries(n)){if(i.endsWith("Move.lock"))continue;let a=`dependencies/${r.name}/${i}`;i.endsWith("Move.toml")?s[a]=this.reconstructDependencyMoveToml(r.name,o,r.edition,r.addressMapping):s[a]=o}t.push({name:r.name,files:s,edition:r.edition,addressMapping:r.addressMapping,publishedIdForOutput:r.publishedIdForOutput,source:r.source,manifestDeps:r.manifestDeps,manifest:r.manifest})}return t}reconstructDependencyMoveToml(e,t,r,n){let s=(t||"").split(`
2
- `),i=[],o="none";for(let d of s){let p=d.trim();if(p.startsWith("[")){p.startsWith("[package]")?o="package":p.startsWith("[addresses]")?o="addresses":p.startsWith("[dependencies")||p.startsWith("[dev-dependencies")?o="dependencies":(o="other",i.push(d));continue}if(o==="package")(p.startsWith("name")||p.startsWith("version")||p.startsWith("edition")||p.startsWith("published-at")||p.startsWith("original-published-id"))&&(p.startsWith("published-at")||p.startsWith("original-published-id"))&&i.push(d);else{if(o==="addresses")continue;if(o==="dependencies")continue;o!=="none"&&i.push(d)}}let a=`[package]
3
- `;a+=`name = "${e}"
4
- `,a+=`version = "0.0.0"
5
- `,a+=`edition = "${r}"
6
- `,a+=`
7
- `,a+=i.join(`
8
- `),a+=`
1
+ "use strict";var ne=Object.create;var F=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty;var ce=(u,e)=>{for(var t in e)F(u,t,{get:e[t],enumerable:!0})},z=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of re(e))!ae.call(u,i)&&i!==t&&F(u,i,{get:()=>e[i],enumerable:!(n=ie(e,i))||n.enumerable});return u};var de=(u,e,t)=>(t=u!=null?ne(oe(u)):{},z(e||!u||!u.__esModule?F(t,"default",{value:u,enumerable:!0}):t,u)),le=u=>z(F({},"__esModule",{value:!0}),u);var Se={};ce(Se,{buildMovePackage:()=>ke,compileRaw:()=>Ie,fetchPackageFromGitHub:()=>Z,getSuiMoveVersion:()=>be,getSuiVersion:()=>Pe,getWasmBindings:()=>we,initMoveCompiler:()=>ve,resolveDependencies:()=>U,testMovePackage:()=>ye});module.exports=le(Se);var W=class{async fetch(e,t,n){throw new Error("Not implemented")}async fetchFile(e,t,n){throw new Error("Not implemented")}getResolvedSha(e,t){}},D=class extends W{constructor(t){super();this.rateLimitRemaining=60;this.rateLimitReset=0;this.cache=new Map,this.treeCache=new Map,this.resolvedShaCache=new Map,this.token=t}getResolvedSha(t,n){let{owner:i,repo:s}=this.parseGitUrl(t);if(!i||!s)return;let o=`${i}/${s}@${n}`;return this.resolvedShaCache.get(o)}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:o,repo:a}=this.parseGitUrl(t);if(!o||!a)throw new Error(`Invalid git URL: ${t}`);let r=`${o}/${a}@${n}`,p=`https://api.github.com/repos/${o}/${a}/git/trees/${n}?recursive=1`,c;if(this.treeCache.has(r))c=this.treeCache.get(r);else{let h=null;for(let m=1;m<=3;m++)try{if(m>1){let b=Math.pow(2,m-1)*1e3;await new Promise(P=>setTimeout(P,b))}let v={};this.token&&(v.Authorization=`Bearer ${this.token}`);let k=await fetch(p,{headers:v});if(this.updateRateLimit(k),!k.ok){if(k.status===403||k.status===429){let b=new Date(this.rateLimitReset);throw new Error(`GitHub API rate limit exceeded. Resets at ${b.toLocaleTimeString()}`)}if(k.status>=500&&k.status<600&&m<3){h=new Error(`Failed to fetch tree: ${k.statusText}`);continue}throw new Error(`Failed to fetch tree: ${k.statusText}`)}c=await k.json(),this.treeCache.set(r,c),c.sha&&this.resolvedShaCache.set(r,c.sha);break}catch(v){if(h=v instanceof Error?v:new Error(String(v)),m===3)return{}}if(h)return{}}let g=new Map,d={},l=[];for(let f of c.tree){if(f.type!=="blob")continue;let h=f.path;if(i){let k=i.endsWith("/")?i:i+"/";if(!f.path.startsWith(k))continue;h=f.path.slice(k.length)}if(!h.endsWith(".move")&&h!=="Move.toml"&&h!=="Move.lock"&&!h.match(/^Move\.(mainnet|testnet|devnet)\.toml$/))continue;h==="Move.toml"&&f.mode&&g.set("Move.toml",f.mode);let m=`https://raw.githubusercontent.com/${o}/${a}/${n}/${f.path}`,v=this.fetchContent(m).then(k=>{k&&(d[h]=k)});l.push(v)}if(await Promise.all(l),d["Move.toml"]&&g.get("Move.toml")==="120000"){let h=d["Move.toml"].trim(),m=i?`${i}/${h}`.replace(/\/+/g,"/"):h,v=`https://raw.githubusercontent.com/${o}/${a}/${n}/${m}`,k=await this.fetchContent(v);k&&(d["Move.toml"]=k)}return d}async fetchFile(t,n,i){let{owner:s,repo:o}=this.parseGitUrl(t);if(!s||!o)throw new Error(`Invalid git URL: ${t}`);let a=`https://raw.githubusercontent.com/${s}/${o}/${n}/${i}`;return this.fetchContent(a)}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 o=await fetch(t,{headers:n});if(!o.ok)return null;let a=await o.text();return this.cache.set(t,a),a}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 N(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 G(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 J(u){let e={},t=u.trim().replace(/^\{/,"").replace(/\}$/,""),n="",i=!1,s="",o=[];for(let a=0;a<t.length;a++){let r=t[a];if((r==='"'||r==="'")&&(!i||r===s)&&(i=!i,s=r),!i&&r===","){o.push(n),n="";continue}n+=r}n.trim()&&o.push(n);for(let a of o){let r=a.indexOf("=");if(r===-1)continue;let p=a.slice(0,r).trim(),c=a.slice(r+1).trim();e[p]=G(c)}return e}function ue(u){let e=[],t=u.trim().replace(/^\[/,"").replace(/\]$/,""),n="",i=!1,s="",o=0;for(let a=0;a<t.length;a++){let r=t[a];if((r==='"'||r==="'")&&(!i||r===s)&&(i=!i,s=i?r:""),!i&&(r==="{"&&o++,r==="}"&&o--,r===","&&o===0)){n.trim()&&e.push(H(n.trim())),n="";continue}n+=r}return n.trim()&&e.push(H(n.trim())),e}function H(u){return u.startsWith("{")?J(u):G(u)}function $(u){let e={},t=null,n=!1,i=u.split(/\r?\n/),s=[],o=0;for(;o<i.length;){let r=N(i[o]);if(r.match(/=\s*\[\s*$/)||r.includes("=")&&r.includes("[")&&!r.includes("]")){let p=r;for(o++;o<i.length&&!p.includes("]");)p+=" "+N(i[o]).trim(),o++;o<i.length&&p.includes("[")&&!p.includes("]")&&(p+=" "+N(i[o]).trim(),o++),s.push(p)}else s.push(r),o++}function a(r,p){let c=r;for(let g of p){if(!(g in c))return;c=c[g]}return c}for(let r of s){let p=N(r).trim();if(!p)continue;let c=p.match(/^\[\[([^\]]+)\]\]$/);if(c){t=c[1].trim(),n=!0;let m=t.split("."),v=e;for(let b=0;b<m.length-1;b++){let P=m[b];P in v||(v[P]={}),v=v[P]}let k=m[m.length-1];Array.isArray(v[k])||(v[k]=[]),v[k].push({});continue}let g=p.match(/^\[([^\]]+)\]$/);if(g){t=g[1].trim(),n=!1;continue}let d=p.indexOf("=");if(d===-1||!t)continue;let l=p.slice(0,d).trim(),f=p.slice(d+1).trim(),h;if(f.startsWith("{")?h=J(f):f.startsWith("[")?h=ue(f):h=G(f),n){let m=t.split("."),v=a(e,m);if(Array.isArray(v)&&v.length>0){let k=v[v.length-1];k[l]=h}}else{let m=t.split("."),v=e;for(let b of m)b in v||(v[b]={}),v=v[b];let k=t==="package"?l.replace(/-/g,"_"):l;v[k]=h}}return e}var O=class{constructor(e){this.packages=[];this.edges=new Map;this.nameToFirstIndex=new Map;this.lockfileOrder=[];this.root=e}setLockfileOrder(e){this.lockfileOrder=e}addPackage(e){let t=this.packages.length;return this.packages.push(e),this.edges.set(t,new Set),this.nameToFirstIndex.has(e.id.name)||this.nameToFirstIndex.set(e.id.name,t),t}addDependency(e,t,n){let i=this.nameToFirstIndex.get(e),s=this.nameToFirstIndex.get(t);i!==void 0&&s!==void 0&&this.edges.get(i)?.add(s)}addDependencyByIndex(e,t){this.edges.get(e)?.add(t)}getPackage(e){let t=this.nameToFirstIndex.get(e);return t!==void 0?this.packages[t]:void 0}getAllPackages(){return this.packages}createIds(){let e=new Map,t=new Map;for(let n=0;n<this.packages.length;n++){let i=this.packages[n];if(!i)continue;let s=i.id.name,o=e.get(s)??0,a=o===0?s:`${s}_${o}`;t.set(n,a),e.set(s,o+1)}return t}getPackageByIndex(e){return this.packages[e]}getImmediateDependenciesOf(e){return this.edges.get(e)||new Set}getImmediateDependencies(e){let t=this.nameToFirstIndex.get(e);if(t===void 0)return new Set;let n=this.edges.get(t)||new Set,i=new Set;for(let s of n)this.packages[s]&&i.add(this.packages[s].id.name);return i}getTransitiveDependencies(e){let t=new Set,n=new Set,i=s=>{if(n.has(s))return;n.add(s),t.add(s);let o=this.nameToFirstIndex.get(s);if(o!==void 0){let a=this.edges.get(o);if(a)for(let r of a)this.packages[r]&&i(this.packages[r].id.name)}};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.nameToFirstIndex.get(i);if(s!==void 0){let o=this.edges.get(s);if(o){let a=Array.from(o).map(r=>this.packages[r]?.id.name).filter(r=>r!==void 0).sort();for(let r of a)n(r)}}t.push(i)};return n(this.root),t.filter(i=>i!==this.root)}compilerInputOrder(){let e=new Set,t=[],n=a=>{if(e.has(a))return;e.add(a);let r=this.edges.get(a);if(r){let p=Array.from(r).sort((c,g)=>{let d=this.packages[c]?.id.name||"",l=this.packages[g]?.id.name||"";return d.localeCompare(l)});for(let c of p)n(c)}t.push(a)},i=this.nameToFirstIndex.get(this.root)??0;n(i);let s=this.createIds();return t.map(a=>s.get(a)||this.packages[a]?.id.name||"")}compilerInputOrderWithIndices(){let e=new Map,t=(g,d)=>{let l=this.packages[g];if(!l)return;let f=l.manifest.originalId||l.manifest.publishedAt||l.id.name,h=e.get(f);if(h&&h.depth<=d)return;e.set(f,{depth:d,idx:g});let m=this.edges.get(g);if(m)for(let v of m)t(v,d+1)},n=this.nameToFirstIndex.get(this.root)??0;t(n,0);let i=new Set,s=[],o=g=>{if(i.has(g)||(i.add(g),!this.packages[g]))return;let l=this.edges.get(g);if(l){let f=Array.from(l).sort((h,m)=>{let v=this.packages[h]?.id.name||"",k=this.packages[m]?.id.name||"";return v.localeCompare(k)});for(let h of f){let m=this.packages[h];if(!m)continue;let v=m.manifest.originalId||m.manifest.publishedAt||m.id.name,k=e.get(v);k&&o(k.idx)}}s.push(g)};o(n);let a=[],r=new Set;for(let g of s)r.has(g)||(r.add(g),a.push(g));let p=this.createIds();return{ids:a.map(g=>p.get(g)||this.packages[g]?.id.name||""),indices:a}}allPackagesOrderWithIndices(){let e=new Set,t=[],n=a=>{if(e.has(a)||(e.add(a),!this.packages[a]))return;let p=this.edges.get(a);if(p)for(let c of p)n(c);t.push(a)},i=this.nameToFirstIndex.get(this.root)??0;n(i);let s=this.createIds();return{ids:t.map(a=>s.get(a)||this.packages[a]?.id.name||""),indices:t}}topologicalOrderDFS(){let e=new Set,t=[],n=i=>{if(e.has(i))return;e.add(i);let s=this.nameToFirstIndex.get(i);if(s!==void 0){let o=this.edges.get(s);if(o)for(let a of o)this.packages[a]&&n(this.packages[a].id.name)}t.push(i)};n(this.root);for(let i of this.packages)n(i.id.name);return t}detectCycle(){let e=new Set,t=new Set,n=new Map,i=s=>{e.add(s),t.add(s);let o=this.nameToFirstIndex.get(s);if(o!==void 0){let a=this.edges.get(o);if(a)for(let r of a){let p=this.packages[r]?.id.name;if(p)if(e.has(p)){if(t.has(p)){let c=[p],g=s;for(;g!==p;)c.unshift(g),g=n.get(g);return c.unshift(p),c}}else{n.set(p,s);let c=i(p);if(c)return c}}}return t.delete(s),null};for(let s of this.packages)if(!e.has(s.id.name)){let o=i(s.id.name);if(o)return o}return null}getRootPackage(){return this.getPackage(this.root)}getRootName(){return this.root}};var L=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,o]of Object.entries(i.manifest.addresses)){let a=this.normalizeAddress(o);this.unifiedAddressTable.has(s)&&this.unifiedAddressTable.get(s)!==a||this.unifiedAddressTable.set(s,a)}}for(let n of this.graph.getAllPackages()){let i={};for(let[s,o]of this.unifiedAddressTable.entries())i[s]=o;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)}getPackageByIndex(e){return this.graph.getPackageByIndex(e)}compilerInputOrderWithIndices(){return this.graph.compilerInputOrderWithIndices()}allPackagesOrderWithIndices(){return this.graph.allPackagesOrderWithIndices()}};var _=class{constructor(e){this.dependencies=[];this.lockfileDependencies=[];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),{ids:i,indices:s}=this.resolvedGraph.compilerInputOrderWithIndices(),o=new Map;for(let p=0;p<i.length;p++){let c=i[p],g=s[p],d=this.resolvedGraph.getPackageByIndex(g);if(!d)continue;let l=d.id.name;if(l===this.rootPackageName)continue;let f=e.has(l);console.log(`[Compile] pkgId=${c}, pkgName=${l}, hasFiles=${f}, manifestName=${d.manifest.name}`);let h=e.get(l)||{},m=this.extractSourcePaths(l,h),v=d.manifest.edition||"legacy",k=d.manifest.latestPublishedId||d.manifest.publishedAt||d.manifest.originalId||d.resolvedTable?.[l],b=d.manifest.originalId;!b&&d.manifest.publishedAt&&(b=d.manifest.publishedAt),b||(b="0x0000000000000000000000000000000000000000000000000000000000000000",k||(k=b)),o.set(l,b),o.set(l.toLowerCase(),b);let P={...d.resolvedTable||{}};for(let[w,T]of Object.entries(P)){let A=o.get(w)||o.get(w.toLowerCase());A&&(P[w]=A)}b&&l!=="Sui"&&l!=="MoveStdlib"&&(P[l]=b,P[l.toLowerCase()]=b);let R=d.id.source,I={type:R.type,git:R.git,rev:R.rev,subdir:R.subdir,local:R.local},S=Object.keys(d.manifest.dependencies||{}),y={name:c,isImmediate:n.has(l),sourcePaths:m,addressMapping:P,compilerConfig:{edition:v,flavor:"sui"},moduleFormat:m.length>0?"Source":"Bytecode",edition:v,publishedIdForOutput:k,source:I,manifestDeps:S,manifest:{name:d.manifest.name,dependencies:d.manifest.dependencies},depAliasToPackageName:d.depAliasToPackageName};this.dependencies.push(y)}let{ids:a,indices:r}=this.resolvedGraph.allPackagesOrderWithIndices();for(let p=0;p<a.length;p++){let c=a[p],g=r[p],d=this.resolvedGraph.getPackageByIndex(g);if(!d)continue;let l=d.id.name;if(l===this.rootPackageName)continue;let f=e.get(l)||{},h=this.extractSourcePaths(l,f),m=d.manifest.edition||"legacy",v=d.manifest.latestPublishedId||d.manifest.publishedAt||d.manifest.originalId||d.resolvedTable?.[l],k=d.id.source,b={type:k.type,git:k.git,rev:k.rev,subdir:k.subdir,local:k.local},P=Object.keys(d.manifest.dependencies),R={};for(let[S,y]of Object.entries(d.manifest.addresses))y&&(R[S]=y);d.manifest.originalId&&(R[l]=d.manifest.originalId);let I={name:c,isImmediate:n.has(l),sourcePaths:h,addressMapping:R,compilerConfig:{edition:m,flavor:"sui"},moduleFormat:h.length>0?"Source":"Bytecode",edition:m,publishedIdForOutput:v,source:b,manifestDeps:P,manifest:{name:d.manifest.name,dependencies:d.manifest.dependencies},depAliasToPackageName:d.depAliasToPackageName};this.lockfileDependencies.push(I)}}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[o,a]of Object.entries(i)){if(o.endsWith("Move.lock"))continue;let r=`dependencies/${n.name}/${o}`;o.endsWith("Move.toml")?s[r]=this.reconstructDependencyMoveToml(n.name,a,n.edition,n.addressMapping):s[r]=a}t.push({name:n.name,files:s,edition:n.edition,addressMapping:n.addressMapping,publishedIdForOutput:n.publishedIdForOutput,source:n.source,manifestDeps:n.manifestDeps,manifest:n.manifest,depAliasToPackageName:n.depAliasToPackageName})}return t}toPackageGroupedFormatForLockfile(e){let t=[];for(let n of this.lockfileDependencies){let i=n.name.replace(/_\d+$/,""),s=e.get(i)||{},o={};for(let[a,r]of Object.entries(s)){if(a.endsWith("Move.lock"))continue;let p=`dependencies/${n.name}/${a}`;o[p]=r}t.push({name:n.name,files:o,edition:n.edition,addressMapping:n.addressMapping,publishedIdForOutput:n.publishedIdForOutput,source:n.source,manifestDeps:n.manifestDeps,manifest:n.manifest,depAliasToPackageName:n.depAliasToPackageName})}return t}reconstructDependencyMoveToml(e,t,n,i){let s=(t||"").split(`
2
+ `),o=[],a="none";for(let c of s){let g=c.trim();if(g.startsWith("[")){g.startsWith("[package]")?a="package":g.startsWith("[addresses]")?a="addresses":g.startsWith("[dependencies")||g.startsWith("[dev-dependencies")?a="dependencies":(a="other",o.push(c));continue}if(a==="package")(g.startsWith("name")||g.startsWith("version")||g.startsWith("edition")||g.startsWith("published-at")||g.startsWith("original-published-id"))&&(g.startsWith("published-at")||g.startsWith("original-published-id"))&&o.push(c);else{if(a==="addresses")continue;if(a==="dependencies")continue;a!=="none"&&o.push(c)}}let r=`[package]
3
+ `;r+=`name = "${e}"
4
+ `,r+=`version = "0.0.0"
5
+ `,r+=`edition = "${n}"
6
+ `,r+=`
7
+ `,r+=o.join(`
8
+ `),r+=`
9
9
  [addresses]
10
- `;let h=Object.entries(n);for(let[d,p]of h)a+=`${d} = "${p}"
11
- `;return a}};var G=class{constructor(e,t="mainnet",r=null){this.visited=new Set;this.packageNameCache=new Map;this.packageFiles=new Map;this.fetcher=e,this.network=t,this.rootSource=r}async resolve(e,t){let r=S(e),n=r.package?.name||"RootPackage",s=r.package?.edition,i=new O(n),o=await this.buildPackage(n,this.rootSource,e,t);s&&(o.manifest.edition=s);let a=o.manifest.addresses[n];this.normalizeAddress(a||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&o.manifest.originalId&&(o.manifest.addresses[n]=this.normalizeAddress(o.manifest.originalId)),i.addPackage(o),this.packageFiles.set(n,t);let d=await this.loadFromLockfile(i,o,t),p=Array.from(o.dependencies.keys()).filter(k=>!i.getPackage(k));(!d||p.length>0)&&await this.buildDependencyGraph(i,o);let g=i.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let l=new F(i,{});await l.resolve();let m=`Move.${this.network}.toml`;for(let[k,w]of this.packageFiles)w[m]&&(w["Move.toml"]=w[m]);let u=new L(l);await u.compute(this.packageFiles);let f=l.getUnifiedAddressTable();for(let k of i.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(A=>A.toLowerCase()===k.manifest.name.toLowerCase());if(P&&k.manifest.addresses[P]){let A=this.normalizeAddress(k.manifest.addresses[P]);f[k.manifest.name]=A,f[k.manifest.name.toLowerCase()]=A;continue}}if(w&&w!=="0x0"&&!w.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let P=this.normalizeAddress(w);f[k.manifest.name]=P,f[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]);f[k.manifest.name]=P,f[k.manifest.name.toLowerCase()]=P;continue}}let v=this.reconstructMoveToml(r,o.manifest.dependencies,f,!0,s),y={...t};delete y["Move.lock"],y["Move.toml"]=v;let b=u.toPackageGroupedFormat(this.packageFiles);return{files:JSON.stringify(y),dependencies:JSON.stringify(b)}}async buildPackage(e,t,r,n){let s=S(r),i=n["Move.lock"],o=this.getChainIdForNetwork(this.network),a=this.resolvePublishedAt(r,i,o,this.network),h=a.latestId?this.normalizeAddress(a.latestId):void 0,d=n["Published.toml"],p,g;if(d)try{let R=S(d).published?.[this.network];R&&(R["published-at"]&&(p=this.normalizeAddress(R["published-at"])),R["original-id"]&&(g=this.normalizeAddress(R["original-id"])))}catch{}a.error;let l={name:s.package?.name||e,version:s.package?.version||"0.0.0",edition:s.package?.edition,publishedAt:p||a.publishedAt,originalId:g||a.originalId,latestPublishedId:h,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 u=l.originalId||l.publishedAt,f=u&&u!=="0x0"?this.normalizeAddress(u):void 0,v=l.addresses[l.name]||(m?l.addresses[m]:void 0),y=v?this.normalizeAddress(v):void 0;f?v||(l.addresses[l.name]=f):y?l.addresses[l.name]=y:l.addresses[l.name]="0x0";let b=new Map;if(l.dependencies)for(let[w,R]of Object.entries(l.dependencies)){let M=this.parseDependencyInfo(R);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 r=e["addr-subst"]||e.addr_subst,n={};for(let[s,i]of Object.entries(r))typeof i=="string"&&(i.startsWith("0x")||/^[0-9a-fA-F]+$/.test(i)?n[s]={type:"assign",address:i}:n[s]={type:"renameFrom",name:i});Object.keys(n).length>0&&(t.subst=n)}return t}async buildDependencyGraph(e,t){let r=Array.from(t.dependencies.entries()).sort(([,n],[,s])=>{let i=n.source.isImplicit?1:0;return(s.source.isImplicit?1:0)-i});for(let[n,s]of r){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let l=t.id.source.subdir||"",m=s.source.local,u=this.resolveRelativePath(l,m);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:u}}else continue;if(s.source.type!=="git")continue;let i=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(i)){let l=this.findPackageBySource(e,s.source);l&&e.addDependency(t.id.name,l.id.name,s);continue}this.visited.add(i);let o=s.source.subdir;!o&&s.source.git&&this.isSuiRepo(s.source.git)&&(o=this.inferSuiFrameworkSubdir(n),o&&(s.source.subdir=o));let a=await this.fetcher.fetch(s.source.git,s.source.rev,o),h=this.fetcher.getResolvedSha(s.source.git,s.source.rev);h&&(s.source.rev=h);let d=null,p=`Move.${this.network}.toml`;for(let[l,m]of Object.entries(a))if(l.endsWith(p)){d=m;break}if(!d){for(let[l,m]of Object.entries(a))if(l.endsWith("Move.toml")){d=m;break}}if(!d)continue;let g=await this.buildPackage(n,s.source,d,a);if(!this.lockfileVersion||this.lockfileVersion<4){let l=this.packageNameCache.get(g.manifest.name);if(l){let m=l.isImplicit,u=s.source.isImplicit;if(m&&!u)continue;if(!(!m&&u)){if(JSON.stringify(l)!==JSON.stringify(s.source)){let f=v=>JSON.stringify(v);throw new Error([`Conflicting versions of package '${g.manifest.name}' found`,`Existing: ${f(l)}`,`New: ${f(s.source)}`,`When resolving dependencies for '${t.id.name}' -> '${n}'`].join(`
12
- `))}}}this.packageNameCache.set(g.manifest.name,s.source)}g.manifest.edition||(g.manifest.edition="legacy"),e.addPackage(g),e.addDependency(t.id.name,g.id.name,s),this.packageFiles.set(g.id.name,a),await this.buildDependencyGraph(e,g)}}getChainIdForNetwork(e){return{mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"}[e]||e}resolvePublishedAt(e,t,r,n){let s=S(e),i=s.package?.published_at||s.package?.["published-at"],o=i&&i!=="0x0"?i:void 0,a=o?this.normalizeAddress(o):void 0,h=s.package?.["original-id"],d,p;if(t)try{let u=S(t),f=r&&u.env?.[r]||u.env?.[n];f&&(f["original-published-id"]&&(d=this.normalizeAddress(f["original-published-id"])),f["latest-published-id"]&&(p=this.normalizeAddress(f["latest-published-id"])))}catch{}let g=a||p||d;return{publishedAt:g,originalId:h||d,latestId:g}}findPackageBySource(e,t){for(let r of e.getAllPackages()){let n=r.id.source;if(n.type===t.type&&n.git===t.git&&n.rev===t.rev&&n.subdir===t.subdir)return r}}resolveRelativePath(e,t){let r=e?e.split("/").filter(Boolean):[],n=t.split("/").filter(Boolean),s=[...r];for(let i of n)i===".."?s.length>0&&s.pop():i!=="."&&s.push(i);return s.join("/")}async computeManifestDigest(e){let r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,r){let n=r["Move.lock"];if(!n)return!1;let s=S(n);this.lockfileVersion=s.move?.version;let i=s.move?.version;return i===3?await this.loadFromLockfileV3(e,s,t):i&&i>=4?s.pinned?await this.loadFromLockfileV4(e,s,r,t):!1:await this.loadFromLockfileV0(e,s,t)}async loadFromLockfileV0(e,t,r){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=Array.isArray(t.move?.dependencies)?t.move.dependencies.map(d=>d.name||d.id||d).filter(Boolean):[],i=n.map(d=>d.name||d.id).filter(Boolean),o=[...s,...i.filter(d=>!s.includes(d))],a=new Map,h=new Map;for(let d of n){let p=d.id||d.name,g=d.source;if(!p||!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 v=this.resolveRelativePath(this.rootSource.subdir||"",g.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:v}}else continue;let m=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(m).length===0)continue;let u=m["Move.toml"];if(!u)continue;let f=await this.buildPackage(p,l,u,m);a.set(p,f),h.set(f.manifest.name,f),this.packageFiles.set(f.manifest.name,m),e.addPackage(f)}o.length&&e.setLockfileOrder(o);for(let d of n){let p=d.id||d.name,g=a.get(p);if(!g)continue;let l=d.dependencies;if(l&&Array.isArray(l))for(let m of l){let u=m.id||m.name,f=a.get(u)||h.get(u);if(f){let v={source:f.id.source};e.addDependency(g.id.name,f.id.name,v)}}}for(let d of r.dependencies.keys()){let p=h.get(d);if(p){let g=r.dependencies.get(d);e.addDependency(r.id.name,p.id.name,g)}}return a.size>0}async loadFromLockfileV3(e,t,r){let n=t.move?.package;if(!n||!Array.isArray(n))return!1;let s=new Map,i=new Map,o=[];for(let a of n)a.id&&i.set(a.id,a);for(let a of n){let h=a.id,d=a.source;o.push(h);let p=null;if(d?.git&&d.rev)p={type:"git",git:d.git,rev:d.rev,subdir:d.subdir};else if(d?.local&&this.rootSource?.type==="git"){let u=this.resolveRelativePath(this.rootSource.subdir||"",d.local);p={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:u}}else continue;if(!p.git||!p.rev)continue;let g=await this.fetcher.fetch(p.git,p.rev,p.subdir);if(Object.keys(g).length===0)continue;let l=g["Move.toml"];if(!l)continue;let m=await this.buildPackage(h,p,l,g);s.set(h,m),this.packageFiles.set(m.manifest.name,g),e.addPackage(m)}e.setLockfileOrder(o);for(let a of n){let h=a.id,d=s.get(h);if(!d)continue;let p=a.dependencies;if(!(!p||!Array.isArray(p)))for(let g of p){let l=g.id,m=s.get(l);if(!m){let u=i.get(l);if(u?.source?.local&&d.id.source.type==="git"){let f=this.resolveRelativePath(d.id.source.subdir||"",u.source.local),v={type:"git",git:d.id.source.git,rev:d.id.source.rev,subdir:f},y=await this.fetcher.fetch(v.git,v.rev,v.subdir),b=y["Move.toml"];if(b){let k=await this.buildPackage(l,v,b,y);s.set(l,k),this.packageFiles.set(k.manifest.name,y),e.addPackage(k),m=k}}}if(m){let u={source:m.id.source};e.addDependency(d.id.name,m.id.name,u)}}}for(let a of r.dependencies.keys()){let h=s.get(a);if(h){let d=r.dependencies.get(a);e.addDependency(r.id.name,h.id.name,d)}}return!0}async loadFromLockfileV4(e,t,r,n){let s=t.pinned?.[this.network];if(!s)return!1;let i=r["Move.toml"];if(i&&t.move?.manifest_digest&&await this.computeManifestDigest(i)!==t.move.manifest_digest)return!1;let o=new Map,a=new Map,h=[];for(let[d,p]of Object.entries(s)){h.push(d);let g=this.lockfileSourceToDependencySource(p.source);if(!g)continue;let l=await this.fetchFromSource(g);if(!l)return!1;let m=l["Move.toml"];if(!m||p["manifest-digest"]&&await this.computeManifestDigest(m)!==p["manifest-digest"])return!1;let u=await this.buildPackage(d,g,m,l);o.set(d,u),a.set(u.manifest.name,u),this.packageFiles.set(u.manifest.name,l),(g.type!=="local"||!("root"in p.source))&&e.addPackage(u)}h.length>0&&e.setLockfileOrder(h);for(let[d,p]of Object.entries(s)){let g=o.get(d);if(g&&p.deps)for(let[l,m]of Object.entries(p.deps)){let u=o.get(m);if(u){let f=g.dependencies.get(l);f&&e.addDependency(g.id.name,u.id.name,f)}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let d of t.move.dependencies){let p=d.id,g=o.get(p);if(g){let l={source:g.id.source};e.addDependency(n.id.name,g.id.name,l)}}else for(let d of n.dependencies.keys()){let p=a.get(d)||o.get(d);if(p){let g=n.dependencies.get(d);e.addDependency(n.id.name,p.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,r,n,s){let o=`[package]
10
+ `;let p=Object.entries(i);for(let[c,g]of p)r+=`${c} = "${g}"
11
+ `;return r}};var K={version:"1.63.3",commit:"04dd28d5c5d92bff685ddfecb86f8acce18ce6df",tag:"framework/mainnet"};var pe=K.commit,B=class{constructor(e,t="mainnet",n=null){this.visited=new Set;this.packageNameToSuffix=new Map;this.repoRevToSuiRev=new Map;this.suiTagToShaCache=new Map;this.packageFiles=new Map;this.diamondPackages=new Map;this.fetcher=e,this.network=t,this.rootSource=n}async resolve(e,t){let n=$(e),i=n.package?.name||"RootPackage",s=n.package?.edition,o=new O(i),a=await this.buildPackage(i,this.rootSource,e,t,!0);s&&(a.manifest.edition=s);let r=a.manifest.addresses[i];this.normalizeAddress(r||"")==="0x0000000000000000000000000000000000000000000000000000000000000000"&&a.manifest.originalId&&(a.manifest.addresses[i]=this.normalizeAddress(a.manifest.originalId)),o.addPackage(a),this.packageFiles.set(i,t),await this.loadFromLockfile(o,a,t)||await this.buildDependencyGraph(o,a);let g=o.detectCycle();if(g)throw new Error(`Dependency cycle detected: ${g.join(" \u2192 ")}`);let d=new L(o,{});await d.resolve();let l=`Move.${this.network}.toml`;for(let[P,R]of this.packageFiles)R[l]&&(R["Move.toml"]=R[l]);let f=new _(d);await f.compute(this.packageFiles);let h=d.getUnifiedAddressTable();for(let P of o.getAllPackages()){let R=P.manifest.originalId||P.manifest.publishedAt||P.manifest.latestPublishedId;if(P.manifest.name===a.manifest.name){let y=Object.keys(P.manifest.addresses).find(w=>w.toLowerCase()===P.manifest.name.toLowerCase());if(y&&P.manifest.addresses[y]){let w=this.normalizeAddress(P.manifest.addresses[y]);h[P.manifest.name]=w,h[P.manifest.name.toLowerCase()]=w;continue}}if(R&&R!=="0x0"&&!R.startsWith("0x0000000000000000000000000000000000000000000000000000000000000000")){let y=this.normalizeAddress(R);h[P.manifest.name]=y,h[P.manifest.name.toLowerCase()]=y;continue}let S=Object.keys(P.manifest.addresses).find(y=>y.toLowerCase()===P.manifest.name.toLowerCase());if(S&&P.manifest.addresses[S]){let y=this.normalizeAddress(P.manifest.addresses[S]);h[P.manifest.name]=y,h[P.manifest.name.toLowerCase()]=y;continue}}let m=this.reconstructMoveToml(n,a.manifest.dependencies,h,!0,s),v={...t};delete v["Move.lock"],v["Move.toml"]=m;let k=f.toPackageGroupedFormat(this.packageFiles),b=f.toPackageGroupedFormatForLockfile(this.packageFiles);return{files:JSON.stringify(v),dependencies:JSON.stringify(k),lockfileDependencies:JSON.stringify(b)}}async buildPackage(e,t,n,i,s=!1){let o=$(n),a=i["Move.lock"],r=this.getChainIdForNetwork(this.network),p=this.resolvePublishedAt(n,a,r,this.network),c=p.latestId?this.normalizeAddress(p.latestId):void 0,g=i["Published.toml"],d,l;if(g)try{let S=$(g).published?.[this.network];S&&(S["published-at"]&&(d=this.normalizeAddress(S["published-at"])),S["original-id"]&&(l=this.normalizeAddress(S["original-id"])))}catch{}p.error;let f={name:o.package?.name||e,version:o.package?.version||"0.0.0",edition:o.package?.edition,publishedAt:d||p.publishedAt,originalId:l||p.originalId,latestPublishedId:c,addresses:o.addresses||{},dependencies:s?this.injectImplicitDependencies(o.dependencies||{},o.package?.name):o.dependencies||{},devDependencies:o["dev-dependencies"]},h=Object.keys(f.addresses).find(I=>I.toLowerCase()===f.name.toLowerCase());if(h&&f.addresses[h]){let I=this.normalizeAddress(f.addresses[h]);I!=="0x0000000000000000000000000000000000000000000000000000000000000000"&&(f.originalId=I)}let m=f.originalId||f.publishedAt,v=m&&m!=="0x0"?this.normalizeAddress(m):void 0,k=f.addresses[f.name]||(h?f.addresses[h]:void 0),b=k?this.normalizeAddress(k):void 0;v?k?k==="0x0000000000000000000000000000000000000000000000000000000000000000"&&(f.addresses[f.name]=v):f.addresses[f.name]=v:b?f.addresses[f.name]=b:f.addresses[f.name]="0x0";let P=new Map;if(f.dependencies)for(let[I,S]of Object.entries(f.dependencies)){let y=this.parseDependencyInfo(S);y&&P.set(I,y)}return{id:{name:f.name,version:f.version,source:t||{type:"local"}},manifest:f,dependencies:P,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,o]of Object.entries(n))typeof o=="string"&&(o.startsWith("0x")||/^[0-9a-fA-F]+$/.test(o)?i[s]={type:"assign",address:o}:i[s]={type:"renameFrom",name:o});Object.keys(i).length>0&&(t.subst=i)}return t}async buildDependencyGraph(e,t){let n=Array.from(t.dependencies.entries()).sort(([i,s],[o,a])=>{let r=s.source.isImplicit?1:0,p=a.source.isImplicit?1:0;return r!==p?p-r:i<o?-1:i>o?1:0});for(let[i,s]of n){if(s.source.type==="local")if(t.id.source.type==="git"&&s.source.local){let m=t.id.source.subdir||"",v=s.source.local,k=this.resolveRelativePath(m,v);s.source={type:"git",git:t.id.source.git,rev:t.id.source.rev,subdir:k}}else continue;if(s.source.type!=="git")continue;if(s.source.git&&this.isSuiRepo(s.source.git)){if(!s.source.subdir){let b=this.inferSuiFrameworkSubdir(i);b&&(s.source.subdir=b)}let m=t.id.source.type==="git"?`${t.id.source.git}|${t.id.source.rev}`:null;if(m){let b=this.repoRevToSuiRev.get(m);b&&s.source.rev!==b&&(s.source.rev=b)}let v=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`,k=this.suiTagToShaCache.get(v);if(k)s.source.rev=k;else{await this.fetcher.fetch(s.source.git,s.source.rev,s.source.subdir);let b=this.fetcher.getResolvedSha(s.source.git,s.source.rev);b&&b!==s.source.rev&&(this.suiTagToShaCache.set(v,b),s.source.rev=b)}}let o=`${s.source.git}|${s.source.rev}|${s.source.subdir||""}`;if(this.visited.has(o)){let m=this.findPackageBySource(e,s.source);m&&(e.addDependency(t.id.name,m.id.name,s),t.depAliasToPackageName||(t.depAliasToPackageName={}),t.depAliasToPackageName[i]=m.id.name,t.depAliasToSource||(t.depAliasToSource={}),t.depAliasToSource[i]={name:m.id.name,git:s.source.git,rev:s.source.rev,subdir:s.source.subdir});continue}this.visited.add(o);let a=s.source.subdir,r=await this.fetcher.fetch(s.source.git,s.source.rev,a),p=this.fetcher.getResolvedSha(s.source.git,s.source.rev);if(p&&(s.source.rev=p),s.source.git&&this.isSuiRepo(s.source.git)){let m=t.id.source.type==="git"?`${t.id.source.git}|${t.id.source.rev}`:null;m&&s.source.rev&&(this.repoRevToSuiRev.has(m)||this.repoRevToSuiRev.set(m,s.source.rev))}let c=null,g=`Move.${this.network}.toml`;for(let[m,v]of Object.entries(r))if(m.endsWith(g)){c=v;break}if(!c){for(let[m,v]of Object.entries(r))if(m.endsWith("Move.toml")){c=v;break}}if(!c)continue;let d=await this.buildPackage(i,s.source,c,r),l=d.manifest.name,f=this.packageNameToSuffix.get(l)??0,h=f===0?l:`${l}_${f}`;this.packageNameToSuffix.set(l,f+1),d.id.name=h,d.manifest.edition||(d.manifest.edition="legacy"),e.addPackage(d),e.addDependency(t.id.name,d.id.name,s),t.depAliasToPackageName||(t.depAliasToPackageName={}),t.depAliasToPackageName[i]=d.id.name,t.depAliasToSource||(t.depAliasToSource={}),t.depAliasToSource[i]={name:d.id.name,git:s.source.git,rev:s.source.rev,subdir:s.source.subdir},console.log(`[V3 Files] Storing: ${d.id.name} (manifest: ${d.manifest.name})`),this.packageFiles.set(d.id.name,r),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=$(e),o=s.package?.published_at||s.package?.["published-at"],a=o&&o!=="0x0"?o:void 0,r=a?this.normalizeAddress(a):void 0,p=s.package?.["original-id"],c,g;if(t)try{let h=$(t),m=n&&h.env?.[n]||h.env?.[i];m&&(m["original-published-id"]&&(c=this.normalizeAddress(m["original-published-id"])),m["latest-published-id"]&&(g=this.normalizeAddress(m["latest-published-id"])))}catch{}let d=r||g||c;return{publishedAt:d,originalId:p||c,latestId:d}}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 o of i)o===".."?s.length>0&&s.pop():o!=="."&&s.push(o);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(a=>a.toString(16).padStart(2,"0")).join("").toUpperCase()}async loadFromLockfile(e,t,n){let i=n["Move.lock"];if(!i)return!1;let s=$(i);this.lockfileVersion=s.move?.version,console.log(`[Lockfile] version=${this.lockfileVersion}, hasPinned=${!!s.pinned}`);let o=s.move?.version;return o===3?!1:o&&o>=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):[],o=i.map(c=>c.name||c.id).filter(Boolean),a=[...s,...o.filter(c=>!s.includes(c))],r=new Map,p=new Map;for(let c of i){let g=c.id||c.name,d=c.source;if(!g||!d)continue;let l=null;if(d.git&&d.rev)l={type:"git",git:d.git,rev:d.rev,subdir:d.subdir};else if(d.local&&this.rootSource?.type==="git"){let k=this.resolveRelativePath(this.rootSource.subdir||"",d.local);l={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:k}}else continue;let f=await this.fetcher.fetch(l.git,l.rev,l.subdir);if(Object.keys(f).length===0)continue;let h=this.fetcher.getResolvedSha(l.git,l.rev);h&&(l.rev=h);let m=f["Move.toml"];if(!m)continue;let v=await this.buildPackage(g,l,m,f);r.set(g,v),p.set(v.manifest.name,v),this.packageFiles.set(v.manifest.name,f),e.addPackage(v)}a.length&&e.setLockfileOrder(a);for(let c of i){let g=c.id||c.name,d=r.get(g);if(!d)continue;let l=c.dependencies;if(l&&Array.isArray(l))for(let f of l){let h=f.id||f.name,m=r.get(h)||p.get(h);if(m){let v={source:m.id.source};e.addDependency(d.id.name,m.id.name,v),d.depAliasToPackageName||(d.depAliasToPackageName={});let k=f.name||h;d.depAliasToPackageName[k]=m.id.name}}}for(let c of n.dependencies.keys()){let g=p.get(c);if(g){let d=n.dependencies.get(c);e.addDependency(n.id.name,g.id.name,d)}}return r.size>0}async loadFromLockfileV3(e,t,n){let i=t.move?.package;if(!i||!Array.isArray(i))return!1;let s=new Map,o=new Map,a=[];for(let r of i)r.id&&o.set(r.id,r);for(let r of i){let p=r.id,c=r.source;a.push(p);let g=null;if(c?.git&&c.rev)g={type:"git",git:c.git,rev:c.rev,subdir:c.subdir};else if(c?.local&&this.rootSource?.type==="git"){let m=this.resolveRelativePath(this.rootSource.subdir||"",c.local);g={type:"git",git:this.rootSource.git,rev:this.rootSource.rev,subdir:m}}else continue;if(!g.git||!g.rev)continue;let d=await this.fetcher.fetch(g.git,g.rev,g.subdir);if(Object.keys(d).length===0)continue;let l=this.fetcher.getResolvedSha(g.git,g.rev);l&&(g.rev=l);let f=d["Move.toml"];if(!f)continue;let h=await this.buildPackage(p,g,f,d);s.set(p,h),this.packageFiles.set(h.manifest.name,d),e.addPackage(h)}e.setLockfileOrder(a);for(let r of i){let p=r.id,c=s.get(p);if(!c)continue;let g=r.dependencies;if(!(!g||!Array.isArray(g)))for(let d of g){let l=d.id,f=s.get(l);if(!f){let h=o.get(l);if(h?.source?.local&&c.id.source.type==="git"){let m=this.resolveRelativePath(c.id.source.subdir||"",h.source.local),v={type:"git",git:c.id.source.git,rev:c.id.source.rev,subdir:m},k=await this.fetcher.fetch(v.git,v.rev,v.subdir),b=k["Move.toml"];if(b){let P=await this.buildPackage(l,v,b,k);s.set(l,P),this.packageFiles.set(P.manifest.name,k),e.addPackage(P),f=P}}}if(f){let h={source:f.id.source};e.addDependency(c.id.name,f.id.name,h),c.depAliasToPackageName||(c.depAliasToPackageName={});let m=d.name||l;c.depAliasToPackageName[m]=f.id.name}}}for(let r of n.dependencies.keys()){let p=s.get(r);if(p){let c=n.dependencies.get(r);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 o=n["Move.toml"];if(o&&t.move?.manifest_digest&&await this.computeManifestDigest(o)!==t.move.manifest_digest)return!1;let a=new Map,r=new Map,p=[];console.log(`[V4 Load] Loading ${Object.keys(s).length} packages from lockfile`);for(let[c,g]of Object.entries(s)){console.log(`[V4 Load] Processing: ${c}`),p.push(c);let d=this.lockfileSourceToDependencySource(g.source);if(!d)continue;if("root"in g.source){a.set(c,i),r.set(i.manifest.name,i);continue}let l=await this.fetchFromSource(d);if(!l)return!1;let f=l["Move.toml"];if(!f)return!1;let h=await this.buildPackage(c,d,f,l);h.id.name=c,a.set(c,h),r.set(c,h),console.log(`[V4 Files] Storing: ${c} (manifest: ${h.manifest.name})`),this.packageFiles.set(c,l),(d.type!=="local"||!("root"in g.source))&&e.addPackage(h)}p.length>0&&e.setLockfileOrder(p);for(let[c,g]of Object.entries(s)){let d=a.get(c);if(d&&g.deps)for(let[l,f]of Object.entries(g.deps)){let h=a.get(f);if(h){let m=d.dependencies.get(l)||{source:h.id.source};e.addDependency(d.id.name,h.id.name,m),d.depAliasToPackageName||(d.depAliasToPackageName={}),d.depAliasToPackageName[l]=h.id.name}}}if(t.move?.dependencies&&Array.isArray(t.move.dependencies))for(let c of t.move.dependencies){let g=c.id,d=a.get(g);if(d){let l={source:d.id.source};e.addDependency(i.id.name,d.id.name,l)}}else for(let c of i.dependencies.keys()){let g=r.get(c)||a.get(c);if(g){let d=i.dependencies.get(c);e.addDependency(i.id.name,g.id.name,d)}}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 a=`[package]
13
12
  name = "${e.package.name}"
14
13
  version = "${e.package.version}"
15
- `,a=s||e.package.edition;if(a&&(o+=`edition = "${a}"
16
- `),o+=`
14
+ `,r=s||e.package.edition;if(r&&(a+=`edition = "${r}"
15
+ `),a+=`
17
16
  [dependencies]
18
- `,t){let d=Object.entries(t);for(let[p,g]of d){let l=g;l.local?o+=`${p} = { local = "${l.local}" }
19
- `:l.git&&l.rev&&(l.subdir?o+=`${p} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
20
- `:o+=`${p} = { git = "${l.git}", rev = "${l.rev}" }
21
- `)}}o+=`
17
+ `,t){let c=Object.entries(t);for(let[g,d]of c){let l=d;l.local?a+=`${g} = { local = "${l.local}" }
18
+ `:l.git&&l.rev&&(l.subdir?a+=`${g} = { git = "${l.git}", subdir = "${l.subdir}", rev = "${l.rev}" }
19
+ `:a+=`${g} = { git = "${l.git}", rev = "${l.rev}" }
20
+ `)}}a+=`
22
21
  [addresses]
23
- `;let h=Object.entries(r);for(let[d,p]of h)o+=`${d} = "${p}"
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 z(c,e,t,r="mainnet",n){return new G(t,r,n||null).resolve(c,e)}var ie=4;function T(c){return c.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function V(c,e,t,r,n,s){let i=[];i.push("# Generated by move; do not edit"),i.push("# This file should be checked in."),i.push(""),i.push("[move]"),i.push(`version = ${ie}`),i.push("");try{let o=JSON.parse(c),a=new Map(o.map(g=>[g.name,g])),h=(g,l)=>{let m=l.map(u=>{let f=g?.[u];return f?.git?{name:u,git:f.git,subdir:f.subdir||"",rev:f.rev||"",use_environment:t}:f?.local?{name:u,local:f.local,use_environment:t}:{name:u,use_environment:t}});return JSON.stringify({deps:m})},d=r||[];i.push(`[pinned.${t}.${e}]`),i.push("source = { root = true }"),i.push(`use_environment = "${t}"`);let p=n?n(h(s,d)):"";if(i.push(`manifest_digest = "${p}"`),d.length>0){let g=d.sort().map(l=>`${l} = "${l}"`);i.push(`deps = { ${g.join(", ")} }`)}else i.push("deps = {}");i.push("");for(let g of o){let l=g.name,m=`pinned.${t}.${l}`;i.push(`[${m}]`);let u=g.source;u?.type==="git"&&u?.git&&u?.rev?i.push(`source = { git = "${T(u.git)}", subdir = "${T(u.subdir||"")}", rev = "${T(u.rev)}" }`):u?.type==="local"&&u?.local?i.push(`source = { local = "${T(u.local)}" }`):i.push("source = { root = true }");let f=g.manifestDeps||Object.keys(g.manifest?.dependencies||{});i.push(`use_environment = "${t}"`);let v=n?n(h(g.manifest?.dependencies,f)):"";if(i.push(`manifest_digest = "${v}"`),f.length>0){let y=f.sort().map(b=>`${b} = "${b}"`);i.push(`deps = { ${y.join(", ")} }`)}else i.push("deps = {}");i.push("")}}catch{i.push(`[pinned.${t}.${e}]`),i.push("source = { root = true }"),i.push(`use_environment = "${t}"`),i.push('manifest_digest = ""'),i.push("deps = {}"),i.push("")}return i.join(`
25
- `)}function re(c){try{let e=new URL(c);if(e.hostname!=="github.com")return null;let t=e.pathname.split("/").filter(Boolean);if(t.length<2)return null;let r=t[0],n=t[1],s="main",i;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(i=t.slice(4).join("/"))),{owner:r,repo:n,ref:s,subdir:i}}catch{return null}}async function H(c,e){let t=re(c);if(!t)throw new Error(`Invalid GitHub URL: ${c}`);let r=e?.fetcher||new D(e?.githubToken),n=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,i=await r.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(i,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!n&&i["Move.lock"]){let{"Move.lock":o,...a}=i;return a}return i}var B;async function I(c){return B||(B=import("./sui_move_wasm.js").then(async e=>(c?await e.default(c):await e.default(),e))),B}function N(c){return{error:c instanceof Error?c.message:typeof c=="string"?c:"Unknown error"}}function J(c){if(typeof c!="object"||c===null)throw new Error("Unexpected compile result shape from wasm");let e=c;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 oe(c,e,t,r){let n=s=>{let i=s.startsWith("0x")?s.slice(2):s,o=i.length%2===0?i:`0${i}`,a=[];for(let h=0;h<o.length;h+=2){let d=parseInt(o.slice(h,h+2),16);if(Number.isNaN(d))throw new Error("invalid hex digest");a.push(d)}return a};try{let s=JSON.parse(c);if(!s.modules||!s.dependencies||!s.digest)throw new Error("missing fields in compiler output");let i=typeof s.digest=="string"?n(s.digest):Array.from(s.digest),o=s.dependencies;return e&&(o=Array.from(e.keys()).filter(a=>a!=="0x0000000000000000000000000000000000000000000000000000000000000000"),o.sort((a,h)=>{let d=e.get(a)||"",p=e.get(h)||"";return d<p?-1:d>p?1:0})),{modules:s.modules,dependencies:o,digest:i,moveLock:t||"",environment:r||"mainnet"}}catch(s){return N(s)}}function K(c){try{let e=JSON.parse(c);for(let t of e){let r=t.addressMapping?.[t.name]??(()=>{let n=Object.entries(t.files).find(([i])=>i.endsWith("Move.toml"));if(!n)return;let s=S(n[1]);return s.addresses&&s.addresses[t.name]||s.package?.published_at||s.package?.["published-at"]})()}}catch{}}async function ae(c){await I(c?.wasm)}async function W(c){let e=c.files["Move.toml"]||"",t=c.rootGit||c.files.__rootGit,r=await z(e,{...c.files,"Move.toml":e},new D(c.githubToken),c.network,t?{type:"git",git:t.git,rev:t.rev,subdir:t.subdir}:void 0);return{files:r.files,dependencies:r.dependencies}}async function ce(c){let e=c.network||"mainnet";try{let t={};for(let[u,f]of Object.entries(c.files))(u.endsWith(".move")||u.endsWith("Move.toml")||u.endsWith("Move.lock")||u.endsWith("Published.toml"))&&(t[u]=f);c.files=t,c.onProgress?.({type:"resolve_start"});let r=c.resolvedDependencies?c.resolvedDependencies:await W(c),n=0;try{n=JSON.parse(r.dependencies).length}catch{}c.onProgress?.({type:"resolve_complete",count:n});let s=await I(c.wasm);K(r.dependencies);let i=new Map,o="Package";try{let u=JSON.parse(r.dependencies),f=c.files["Move.toml"],v=[];if(f){let y=S(f);y.package?.name&&(o=y.package.name),y.dependencies&&(v=Object.keys(y.dependencies))}for(let y of u)!y.publishedIdForOutput||y.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(y.publishedIdForOutput)||i.set(y.publishedIdForOutput,y.name)}catch{}c.onProgress?.({type:"compile_start"});let a=s.compile(r.files,r.dependencies,JSON.stringify({silenceWarnings:c.silenceWarnings,testMode:c.testMode,lintFlag:c.lintFlag,stripMetadata:c.stripMetadata})),h=J(a),d=h.success(),p=h.output();if(c.onProgress?.({type:"compile_complete"}),!d)return N(p);c.onProgress?.({type:"lockfile_generate"});let g=[],l;try{let u=c.files["Move.toml"];if(u){let f=S(u);f.dependencies&&(g=Object.keys(f.dependencies),l=f.dependencies)}}catch{}let m=V(r.dependencies,o,e,g,s.compute_manifest_digest,l);return oe(p,i,m,e)}catch(t){return N(t)}}async function de(c){try{let e=c.resolvedDependencies?c.resolvedDependencies:await W(c),t=await I(c.wasm);K(e.dependencies);let r=c.ansiColor&&typeof t.test_with_color=="function"?t.test_with_color(e.files,e.dependencies,!0):t.test(e.files,e.dependencies);if(typeof r.passed=="boolean"&&typeof r.output=="string")return{passed:r.passed,output:r.output};let n=typeof r.passed=="function"?r.passed():r.passed,s=typeof r.output=="function"?r.output():r.output;return{passed:n,output:s}}catch(e){return N(e)}}async function le(c){return(await I(c?.wasm)).sui_move_version()}async function ge(c){return(await I(c?.wasm)).sui_version()}async function ue(c){return I(c?.wasm)}async function pe(c,e,t){let r=await I(t?.wasm),n=t?.ansiColor&&typeof r.compile_with_color=="function"?r.compile_with_color(c,e,!0):r.compile(c,e,JSON.stringify({silenceWarnings:!1})),s=J(n);return{success:s.success(),output:s.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
22
+ `;let p=Object.entries(n);for(let[c,g]of p)a+=`${c} = "${g}"
23
+ `;return a}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.toLowerCase().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:pe,isImplicit:!0}),e}};async function q(u,e,t,n="mainnet",i){return new B(t,n,i||null).resolve(u,e)}var fe=4;function C(u){return u.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}function Q(u,e,t,n,i,s,o,a){let r=[];r.push("# Generated by move; do not edit"),r.push("# This file should be checked in."),r.push(""),r.push("[move]"),r.push(`version = ${fe}`),r.push("");try{let p=JSON.parse(u),c=new Map(p.map(l=>[l.name,l])),g=(l,f,h)=>{let m=f.map(S=>{let y=l?.[S];if(y?.git)return{name:S,git:y.git,subdir:y.subdir||"",rev:y.rev||"",use_environment:t};if(y?.local)return{name:S,local:y.local,use_environment:t};let w=S.toLowerCase();return w==="sui"||w==="std"||w==="movestdlib"?{name:S,system:w==="movestdlib"?"std":w,is_override:!0,use_environment:t}:{name:S,use_environment:t}}),k=f.some(S=>{let y=S.toLowerCase();return y==="sui"||y==="std"||y==="movestdlib"}),b=h.toLowerCase(),P=[],R=b==="sui"||b.startsWith("sui_")||b==="std"||b==="movestdlib"||b.startsWith("movestdlib_");!k&&!R&&(P.push({name:"sui",system:"sui",is_override:!0,use_environment:t}),P.push({name:"std",system:"std",is_override:!0,use_environment:t}));let I=[...m,...P];return JSON.stringify({deps:I})},d=[];d.push({name:e,isRoot:!0});for(let l of p)d.push({name:l.name,isRoot:!1,dep:l});d.sort((l,f)=>l.name<f.name?-1:l.name>f.name?1:0);for(let l of d){let f=`pinned.${t}.${l.name}`;r.push(`[${f}]`);let h=l.isRoot?s?Object.keys(s).map(R=>s[R]):[]:[],m=l.isRoot?n||[]:l.dep.depAliasToPackageName?Object.keys(l.dep.depAliasToPackageName):l.dep.manifestDeps||Object.keys(l.dep.manifest?.dependencies||{}),v=m.some(R=>{let I=R.toLowerCase();return I==="sui"||I==="std"||I==="movestdlib"}),k=l.name.toLowerCase(),b=[],P=k==="sui"||k.startsWith("sui_")||k==="std"||k==="movestdlib"||k.startsWith("movestdlib_");if(!v&&!P&&(b.push("sui"),b.push("std")),l.isRoot){r.push("source = { root = true }"),r.push(`use_environment = "${t}"`);let R=i?i(g(s,m,e)):"";r.push(`manifest_digest = "${R}"`);let I=[...m,...b].sort();if(I.length>0){let S=o||{},y=I.map(w=>{let T=S[w]||w;return w==="sui"&&!S[w]&&c.has("Sui")&&(T="Sui"),w==="std"&&!S[w]&&c.has("MoveStdlib")&&(T="MoveStdlib"),`${w} = "${T}"`});r.push(`deps = { ${y.join(", ")} }`)}else r.push("deps = {}")}else{let R=l.dep,I=R.source;I?.type==="git"&&I?.git&&I?.rev?r.push(`source = { git = "${C(I?.git)}", subdir = "${C(I?.subdir||"")}", rev = "${C(I?.rev)}" }`):I?.type==="local"&&I?.local?r.push(`source = { local = "${C(I?.local)}" }`):r.push("source = { root = true }"),r.push(`use_environment = "${t}"`);let S=i?i(g(R.manifest?.dependencies,m,l.name)):"";r.push(`manifest_digest = "${S}"`);let y=[...m,...b].sort();if(y.length>0){let w=R.depAliasToPackageName||{},T=y.map(A=>{let x=w[A]||A;return A==="sui"&&!w[A]&&c.has("Sui")&&(x="Sui"),A==="std"&&!w[A]&&c.has("MoveStdlib")&&(x="MoveStdlib"),`${A} = "${x}"`});r.push(`deps = { ${T.join(", ")} }`)}else r.push("deps = {}")}r.push("")}}catch(p){console.error("Lockfile generation error:",p),r.push(`[pinned.${t}.${e}]`),r.push("source = { root = true }"),r.push(`use_environment = "${t}"`),r.push('manifest_digest = ""'),r.push("deps = {}"),r.push("")}if(a)try{let p=a.split(`
24
+ `),c=[],g="",d=!1;for(let l of p){let f=l.match(/^\[pinned\.([^.]+)\./);f?(d&&c.length>0&&(r.push(...c),r.push("")),g=f[1],d=g!==t,c=d?[l]:[]):d&&(l.trim()!==""||c.length>0)&&c.push(l)}d&&c.length>0&&(r.push(...c),r.push(""))}catch{}return r.join(`
25
+ `)}function V(u,e,t){try{let n=$(u);if((n.move?.version??0)>3)return null;let s=n.env;if(!s||typeof s!="object")return null;let o=[];for(let[r,p]of Object.entries(s)){if(!p||typeof p!="object")continue;let c=p,g=c["chain-id"],d=c["original-published-id"],l=c["latest-published-id"],f=c["published-version"];if(!g||!d||!l||!f)continue;let h=parseInt(f,10);isNaN(h)||o.push({network:r,chainId:g,originalId:X(d),publishedAt:X(l),version:h})}if(o.length===0)return null;o.sort((r,p)=>r.network.localeCompare(p.network));let a=["# Generated by Move","# This file contains metadata about published versions of this package in different environments","# This file SHOULD be committed to source control",""];for(let r of o)a.push(`[published.${r.network}]`),a.push(`chain-id = "${r.chainId}"`),a.push(`published-at = "${r.publishedAt}"`),a.push(`original-id = "${r.originalId}"`),a.push(`version = ${r.version}`),a.push("");return a.join(`
26
+ `)}catch(n){return console.warn("Failed to migrate legacy lockfile:",n),null}}function X(u){if(!u)return u;let e=u.trim();return e.startsWith("0x")&&(e=e.slice(2)),/^[0-9a-fA-F]+$/.test(e)?"0x"+e.toLowerCase().padStart(64,"0"):u}function Y(u){try{let e=$(u);if((e.move?.version??0)>3||!e.env||typeof e.env!="object")return null;let n=[];if(n.push("[move]"),n.push("version = 4"),n.push(""),e.dependencies&&typeof e.dependencies=="object"){n.push("[dependencies]");for(let[i,s]of Object.entries(e.dependencies))if(typeof s=="object"&&s!==null){let o=s,a=[];o.name&&a.push(`name = "${o.name}"`),o.source&&a.push(`source = "${o.source}"`),n.push(`${i} = { ${a.join(", ")} }`)}n.push("")}return n.join(`
27
+ `)}catch(e){return console.warn("Failed to strip env sections from V3 lockfile:",e),null}}function me(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",o;return t.length>=4&&t[2]==="tree"&&(s=t[3],t.length>4&&(o=t.slice(4).join("/"))),{owner:n,repo:i,ref:s,subdir:o}}catch{return null}}async function Z(u,e){let t=me(u);if(!t)throw new Error(`Invalid GitHub URL: ${u}`);let n=e?.fetcher||new D(e?.githubToken),i=e?.includeLock!==!1,s=`https://github.com/${t.owner}/${t.repo}.git`,o=await n.fetch(s,t.ref,t.subdir,`root:${t.owner}/${t.repo}`);if(Object.defineProperty(o,"__rootGit",{value:{git:s,rev:t.ref,subdir:t.subdir},enumerable:!1}),!i&&o["Move.lock"]){let{"Move.lock":a,...r}=o;return r}return o}var ee={mainnet:"35834a8a",testnet:"4c78adac",devnet:"2",localnet:"localnet"},E;async function M(u){return E||(E=import("./sui_move_wasm.js").then(async e=>(u?await e.default(u):await e.default(),e))),E}function j(u){return{error:u instanceof Error?u.message:typeof u=="string"?u:"Unknown error"}}function te(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 he(u,e,t,n){let i=s=>{let o=s.startsWith("0x")?s.slice(2):s,a=o.length%2===0?o:`0${o}`,r=[];for(let p=0;p<a.length;p+=2){let c=parseInt(a.slice(p,p+2),16);if(Number.isNaN(c))throw new Error("invalid hex digest");r.push(c)}return r};try{let s=JSON.parse(u);if(!s.modules||!s.dependencies||!s.digest)throw new Error("missing fields in compiler output");let o=typeof s.digest=="string"?i(s.digest):Array.from(s.digest),a=s.dependencies;return e&&(a=Array.from(e.keys()).filter(r=>r!=="0x0000000000000000000000000000000000000000000000000000000000000000"),a.sort((r,p)=>{let c=e.get(r)||"",g=e.get(p)||"";return c<g?-1:c>g?1:0})),{modules:s.modules,dependencies:a,digest:o,moveLock:t||"",environment:n||"mainnet"}}catch(s){return j(s)}}function se(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(([o])=>o.endsWith("Move.toml"));if(!i)return;let s=$(i[1]);return s.addresses&&s.addresses[t.name]||s.package?.published_at||s.package?.["published-at"]})()}}catch{}}async function ve(u){await M(u?.wasm)}async function U(u){let e=u.files["Move.toml"]||"",t=u.rootGit||u.files.__rootGit,n=await q(e,{...u.files,"Move.toml":e},new D(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,lockfileDependencies:n.lockfileDependencies}}async function ke(u){let e=u.network||"mainnet";try{let t={};for(let[y,w]of Object.entries(u.files))(y.endsWith(".move")||y.endsWith("Move.toml")||y.endsWith("Move.lock")||y.endsWith("Published.toml"))&&(t[y]=w);u.files=t;let n,i=u.files["Move.lock"];if(i){let y=ee[e]||e;if(n=V(i,e,y)??void 0,n){u.files["Published.toml"]||(u.files["Published.toml"]=n);let T=Y(i);T&&(u.files["Move.lock"]=T)}}u.onProgress?.({type:"resolve_start"});let s=u.resolvedDependencies?u.resolvedDependencies:await U(u),o=0;try{o=JSON.parse(s.dependencies).length}catch{}u.onProgress?.({type:"resolve_complete",count:o});let a=await M(u.wasm);se(s.dependencies);let r=new Map,p="Package";try{let y=JSON.parse(s.dependencies),w=u.files["Move.toml"],T=[];if(w){let A=$(w);A.package?.name&&(p=A.package.name),A.dependencies&&(T=Object.keys(A.dependencies))}for(let A of y)!A.publishedIdForOutput||A.publishedIdForOutput==="0x0000000000000000000000000000000000000000000000000000000000000000"||["0x0000000000000000000000000000000000000000000000000000000000000003","0x000000000000000000000000000000000000000000000000000000000000000b"].includes(A.publishedIdForOutput)||r.set(A.publishedIdForOutput,A.name)}catch{}u.onProgress?.({type:"compile_start"});let c=JSON.parse(s.dependencies),g=new Map,d=c.map(y=>{let w=g.get(y.name)??0,T=w===0?y.name:`${y.name}_${w}`;return g.set(y.name,w+1),{id:T,name:y.name,source:y.source??{root:!0},deps:y.deps??{},manifestDigest:y.manifestDigest??"",is_root:!1}});d.unshift({id:p,name:p,source:{root:!0},deps:{},manifestDigest:"",is_root:!0}),d.sort((y,w)=>y.id.localeCompare(w.id));let l={environment:e,root:p,packages:d},f=a.compile(s.files,s.dependencies,JSON.stringify({silenceWarnings:u.silenceWarnings,testMode:u.testMode,lintFlag:u.lintFlag,stripMetadata:u.stripMetadata}),JSON.stringify(l)),h=te(f),m=h.success(),v=h.output();if(u.onProgress?.({type:"compile_complete"}),!m)return j(v);u.onProgress?.({type:"lockfile_generate"});let k=[],b,P;try{let y=u.files["Move.toml"];if(y){let w=$(y);w.dependencies&&(k=Object.keys(w.dependencies),b=w.dependencies)}}catch{}try{let w=JSON.parse(s.dependencies).find(T=>T.name===p);w?.depAliasToPackageName&&(P=w.depAliasToPackageName)}catch{}let R=u.files["Move.lock"],I=Q(s.lockfileDependencies,p,e,k,a.compute_manifest_digest,b,P,R),S=he(v,r,I,e);if(!("error"in S)){let y=u.files["Move.lock"];if(y){let w=ee[e]||e,T=V(y,e,w);T&&(S.publishedToml=T)}}return S}catch(t){return j(t)}}async function ye(u){try{let e=u.resolvedDependencies?u.resolvedDependencies:await U(u),t=await M(u.wasm);se(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 j(e)}}async function be(u){return(await M(u?.wasm)).sui_move_version()}async function Pe(u){return(await M(u?.wasm)).sui_version()}async function we(u){return M(u?.wasm)}async function Ie(u,e,t){let n=await M(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=te(i);return{success:s.success(),output:s.output()}}0&&(module.exports={buildMovePackage,compileRaw,fetchPackageFromGitHub,getSuiMoveVersion,getSuiVersion,getWasmBindings,initMoveCompiler,resolveDependencies,testMovePackage});
@@ -92,8 +92,10 @@ type OnProgressCallback = (event: BuildProgressEvent) => void;
92
92
  interface ResolvedDependencies {
93
93
  /** JSON string of resolved files for the root package */
94
94
  files: string;
95
- /** JSON string of resolved dependencies */
95
+ /** JSON string of resolved dependencies (linkage applied, for compilation) */
96
96
  dependencies: string;
97
+ /** JSON string of all dependencies including diamond duplicates (for lockfile) */
98
+ lockfileDependencies: string;
97
99
  }
98
100
  interface BuildInput {
99
101
  /** Virtual file system contents. Keys are paths (e.g. "Move.toml", "sources/Module.move"). */
@@ -136,6 +138,8 @@ interface BuildSuccess {
136
138
  moveLock: string;
137
139
  /** Build environment used */
138
140
  environment: string;
141
+ /** Generated Published.toml content (if migration occurred) */
142
+ publishedToml?: string;
139
143
  }
140
144
  interface BuildFailure {
141
145
  error: string;
@@ -92,8 +92,10 @@ type OnProgressCallback = (event: BuildProgressEvent) => void;
92
92
  interface ResolvedDependencies {
93
93
  /** JSON string of resolved files for the root package */
94
94
  files: string;
95
- /** JSON string of resolved dependencies */
95
+ /** JSON string of resolved dependencies (linkage applied, for compilation) */
96
96
  dependencies: string;
97
+ /** JSON string of all dependencies including diamond duplicates (for lockfile) */
98
+ lockfileDependencies: string;
97
99
  }
98
100
  interface BuildInput {
99
101
  /** Virtual file system contents. Keys are paths (e.g. "Move.toml", "sources/Module.move"). */
@@ -136,6 +138,8 @@ interface BuildSuccess {
136
138
  moveLock: string;
137
139
  /** Build environment used */
138
140
  environment: string;
141
+ /** Generated Published.toml content (if migration occurred) */
142
+ publishedToml?: string;
139
143
  }
140
144
  interface BuildFailure {
141
145
  error: string;