midnight-wallet-cli 0.2.0 → 0.2.1

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
@@ -73,10 +73,42 @@ midnight transfer mn_addr_undeployed1... 100
73
73
 
74
74
  | Network | Description |
75
75
  |---------|-------------|
76
- | `preprod` | Midnight pre-production testnet |
77
76
  | `undeployed` | Local network via Docker (`midnight localnet up`) |
77
+ | `preprod` | Midnight pre-production testnet |
78
+ | `preview` | Midnight preview testnet |
79
+
80
+ Wallets are network-agnostic — one seed derives addresses for all three networks. Use `--network <name>` on any command, or persist it with `midnight config set network preview`.
81
+
82
+ ## DApp Connector
83
+
84
+ `midnight serve` starts a WebSocket JSON-RPC server that implements the same `ConnectedAPI` interface as the Lace browser wallet. Any DApp can connect to it — no browser extension needed.
85
+
86
+ ```bash
87
+ # Start the connector server
88
+ midnight serve --network preview
89
+
90
+ # Or auto-approve all requests (dev only)
91
+ midnight serve --network preview --approve-all
92
+ ```
93
+
94
+ To connect from your DApp, install the connector package:
95
+
96
+ ```bash
97
+ npm install midnight-wallet-connector
98
+ ```
99
+
100
+ ```typescript
101
+ import { createWalletClient } from 'midnight-wallet-connector';
102
+
103
+ const wallet = await createWalletClient({
104
+ url: 'ws://localhost:9932',
105
+ networkId: 'Preview',
106
+ });
107
+
108
+ const balances = await wallet.getUnshieldedBalances();
109
+ ```
78
110
 
79
- Use `--network <name>` to select a network, or persist it with `midnight config set network preprod`.
111
+ See the [midnight-wallet-connector](https://www.npmjs.com/package/midnight-wallet-connector) package for the full API, and [midnight-starship](https://github.com/nel349/midnight-starship) for a working example DApp.
80
112
 
81
113
  ## JSON Output for Automation
82
114
 
@@ -368,5 +368,5 @@ Usage: midnight wallet remove <name>`);if(S2(Z),I($,"json")){M({wallet:Z,removed
368
368
  `),process.stderr.write(H(" Dashboard: ")+r(l0)+`
369
369
 
370
370
  `)};if(W(),X){let P=setInterval(async()=>{try{let[x,...F]=await Promise.all([Promise.all([W1("/api/status"),W1("/api/issues")]).catch(()=>null),...J.map((O)=>X3(O))]);if(x)[Y,G]=x;for(let O=0;O<J.length;O++)U[J[O]]=F[O];process.stderr.write("\x1B[2J\x1B[H"),W()}catch{process.stderr.write(H(" Refresh failed — retrying in 30s")+`
371
- `)}},30000);await new Promise(()=>{process.on("SIGINT",()=>{clearInterval(P),process.exit(0)})})}let B=J.reduce((P,x)=>{let F={...Y?.networks[x]??{},...U[x]??{}},O=X2(F);if(O==="down")return"down";if(O==="degraded"&&P!=="down")return"degraded";return P},"up");if(B==="down")process.exitCode=2;else if(B==="degraded")process.exitCode=1}var x7,A7,Z3,E7=15000,L1=5000,Q3=1e4;var Y3=E(()=>{Q0();c();B0();x7={preprod:{faucet:"https://faucet.preprod.midnight.network/",explorer:"https://preprod.midnightexplorer.com/"},preview:{faucet:"https://faucet.preview.midnight.network/",explorer:null},undeployed:{faucet:"",explorer:""}},A7={indexer:"Indexer",rpc:"RPC Node",faucet:"Faucet",explorer:"Explorer",chain:"Chain",dust:"Dust Generation",wallet:"Wallet Ops",dapp:"DApp Flow"},Z3={up:S("UP"),down:a("DOWN"),degraded:R("\x1B[33mDEGRADED\x1B[0m"),unknown:H("—")}});import{Server as k7}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as w7}from"@modelcontextprotocol/sdk/server/stdio.js";import{ListToolsRequestSchema as h7,CallToolRequestSchema as f7}from"@modelcontextprotocol/sdk/types.js";async function N($,Z,Q){let X=[];M1((q)=>X.push(q));let z=process.stderr.write;process.stderr.write=()=>!0;try{Z.flags.json=!0,await $(Z,Q);let q=X.join("").trim();if(!q)return{};return JSON.parse(q)}finally{M1(null),process.stderr.write=z}}var n={INVALID_ARGS:"INVALID_ARGS",WALLET_NOT_FOUND:"WALLET_NOT_FOUND",NETWORK_ERROR:"NETWORK_ERROR",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",TX_REJECTED:"TX_REJECTED",STALE_UTXO:"STALE_UTXO",PROOF_TIMEOUT:"PROOF_TIMEOUT",DUST_REQUIRED:"DUST_REQUIRED",CANCELLED:"CANCELLED",UNKNOWN:"UNKNOWN"};function j2($){let Z=($.message??"").toLowerCase();if(Z.includes("operation cancelled")||Z.includes("operation aborted")||Z==="cancelled"||Z==="aborted")return{exitCode:7,errorCode:n.CANCELLED};if(Z.includes("wallet file not found")||Z.includes("wallet")&&Z.includes("not found"))return{exitCode:3,errorCode:n.WALLET_NOT_FOUND};if(Z.includes("missing required flag")||Z.includes("missing amount")||Z.includes("missing recipient")||Z.includes("missing config key")||Z.includes("missing or invalid subcommand")||Z.includes("unknown command")||Z.includes("cannot specify both")||Z.includes("invalid bip-39")||Z.includes("seed must be")||Z.includes("key index must be")||Z.includes("usage:"))return{exitCode:2,errorCode:n.INVALID_ARGS};if(Z.includes("proof")&&Z.includes("timeout"))return{exitCode:6,errorCode:n.PROOF_TIMEOUT};if(Z.includes("stale utxo")||Z.includes("error code 115")||Z.includes("errorcode: 115"))return{exitCode:6,errorCode:n.STALE_UTXO};if(Z.includes("no dust")||Z.includes("dust")&&(Z.includes("required")||Z.includes("available")||Z.includes("insufficient")))return{exitCode:5,errorCode:n.DUST_REQUIRED};if(Z.includes("insufficient")||Z.includes("not enough"))return{exitCode:5,errorCode:n.INSUFFICIENT_BALANCE};if(Z.includes("rejected")||Z.includes("transaction failed"))return{exitCode:6,errorCode:n.TX_REJECTED};if(Z.includes("econnrefused")||Z.includes("enotfound")||Z.includes("etimedout")||Z.includes("websocket")||Z.includes("connection refused")||Z.includes("network")&&Z.includes("error"))return{exitCode:4,errorCode:n.NETWORK_ERROR};return{exitCode:1,errorCode:n.UNKNOWN}}var p0={name:"midnight-wallet-cli",version:"0.2.0",type:"module",description:"Git-style CLI wallet for the Midnight blockchain",license:"Apache-2.0",workspaces:["packages/*"],bin:{midnight:"dist/wallet.js",mn:"dist/wallet.js","midnight-wallet-cli":"dist/wallet.js","midnight-wallet-mcp":"dist/mcp-server.js"},files:["dist"],scripts:{wallet:"tsx src/wallet.ts",build:'bun build src/wallet.ts --outfile dist/wallet.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node" && bun build src/mcp-server.ts --outfile dist/mcp-server.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node"',mcp:"tsx src/mcp-server.ts",prepublishOnly:"npm run build && npm run test",test:"vitest run","test:watch":"vitest",typecheck:"tsc --noEmit"},dependencies:{"@midnight-ntwrk/dapp-connector-api":"^4.0.1","@midnight-ntwrk/ledger-v7":"^7.0.2","@midnight-ntwrk/midnight-js-network-id":"3.0.0","@midnight-ntwrk/midnight-js-types":"3.0.0","@midnight-ntwrk/wallet-sdk-abstractions":"^2.0.0","@midnight-ntwrk/wallet-sdk-address-format":"^3.0.1","@midnight-ntwrk/wallet-sdk-dust-wallet":"^2.0.0","@midnight-ntwrk/wallet-sdk-facade":"^2.0.0","@midnight-ntwrk/wallet-sdk-hd":"^3.0.1","@midnight-ntwrk/wallet-sdk-shielded":"^2.0.0","@midnight-ntwrk/wallet-sdk-unshielded-wallet":"^2.0.0","@modelcontextprotocol/sdk":"^1.27.1","@scure/bip39":"^2.0.1",rxjs:"^7.8.1",ws:"^8.19.0"},devDependencies:{"@types/node":"^22.19.13","@types/ws":"^8.18.1",tsx:"^4.21.0",typescript:"^5.9.3",vitest:"^3.2.4"}};var t7=p0.name,V2=p0.version,r7=p0.description;function i($,Z,Q){let X={json:!0},z=[];for(let[q,Y]of Object.entries(Z)){if(Y===void 0||Y===null)continue;if(typeof Y==="boolean"){if(Y)X[q]=!0}else X[q]=String(Y)}return{command:$,subcommand:Q,positionals:z,flags:X}}var p7={generate:()=>Promise.resolve().then(() => (m2(),u2)),info:()=>Promise.resolve().then(() => (d2(),g2)),balance:()=>Promise.resolve().then(() => (a2(),r2)),address:()=>Promise.resolve().then(() => ($$(),e2)),"genesis-address":()=>Promise.resolve().then(() => (X$(),Q$)),"inspect-cost":()=>Promise.resolve().then(() => (G$(),Y$)),airdrop:()=>Promise.resolve().then(() => (_$(),M$)),transfer:()=>Promise.resolve().then(() => (x$(),R$)),dust:()=>Promise.resolve().then(() => (C$(),D$)),cache:()=>Promise.resolve().then(() => (b$(),y$)),config:()=>Promise.resolve().then(() => (k$(),v$)),localnet:()=>Promise.resolve().then(() => (n$(),o$)),wallet:()=>Promise.resolve().then(() => ($3(),e$)),status:()=>Promise.resolve().then(() => (Y3(),q3))};async function y($){let Z=p7[$];if(!Z)throw new Error(`Unknown command handler: ${$}`);return(await Z()).default}var G3=[{name:"midnight_generate",description:"Generate a new wallet (deprecated — use midnight_wallet_generate instead)",inputSchema:{type:"object",properties:{network:{type:"string",description:"Network: preprod, preview, undeployed",enum:["preprod","preview","undeployed"]},seed:{type:"string",description:"Restore from existing seed (64-char hex)"},mnemonic:{type:"string",description:"Restore from BIP-39 mnemonic (24 words)"},output:{type:"string",description:"Custom output path (deprecated — use midnight_wallet_generate instead)"},force:{type:"string",description:'Set to "true" to overwrite existing wallet file'}}},async handler($){let Z=i("generate",$);if($.force==="true"||$.force===!0)Z.flags.force=!0;let Q=await y("generate");return N(Q,Z)}},{name:"midnight_wallet_generate",description:"Create a new named wallet and set it as active",inputSchema:{type:"object",properties:{name:{type:"string",description:'Wallet name (e.g. "alice", "dev")'},network:{type:"string",description:"Network: preprod, preview, undeployed",enum:["preprod","preview","undeployed"]},seed:{type:"string",description:"Restore from existing seed (64-char hex)"},mnemonic:{type:"string",description:"Restore from BIP-39 mnemonic (24 words)"},force:{type:"string",description:'Set to "true" to overwrite existing wallet'}},required:["name"]},async handler($){let Z=$.name,Q=i("wallet",$,"generate");if(Q.positionals=[Z],delete Q.flags.name,$.force==="true"||$.force===!0)Q.flags.force=!0;let X=await y("wallet");return N(X,Q)}},{name:"midnight_wallet_list",description:"List all wallets with name, address, network, and active marker",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"wallet",subcommand:"list",positionals:[],flags:{json:!0}},Z=await y("wallet");return N(Z,$)}},{name:"midnight_wallet_use",description:"Set the active wallet by name",inputSchema:{type:"object",properties:{name:{type:"string",description:"Wallet name to activate"}},required:["name"]},async handler($){let Q={command:"wallet",subcommand:"use",positionals:[$.name],flags:{json:!0}},X=await y("wallet");return N(X,Q)}},{name:"midnight_wallet_info",description:"Show details for a named wallet or the active wallet",inputSchema:{type:"object",properties:{name:{type:"string",description:"Wallet name (default: active wallet)"}}},async handler($){let Z=$.name,Q={command:"wallet",subcommand:"info",positionals:Z?[Z]:[],flags:{json:!0}},X=await y("wallet");return N(X,Q)}},{name:"midnight_wallet_remove",description:"Remove a named wallet (refuses active or last wallet)",inputSchema:{type:"object",properties:{name:{type:"string",description:"Wallet name to remove"}},required:["name"]},async handler($){let Q={command:"wallet",subcommand:"remove",positionals:[$.name],flags:{json:!0}},X=await y("wallet");return N(X,Q)}},{name:"midnight_info",description:"Display wallet address, network, creation date (no secrets shown)",inputSchema:{type:"object",properties:{wallet:{type:"string",description:"Wallet name or path"}}},async handler($){let Z=i("info",$),Q=await y("info");return N(Q,Z)}},{name:"midnight_balance",description:"Check unshielded balance via indexer subscription",inputSchema:{type:"object",properties:{address:{type:"string",description:"Address to check (or reads from wallet file)"},wallet:{type:"string",description:"Wallet name or path"},network:{type:"string",description:"Override network detection",enum:["preprod","preview","undeployed"]},"indexer-ws":{type:"string",description:"Custom indexer WebSocket URL"}}},async handler($){let Z=$.address,Q=i("balance",$,Z);delete Q.flags.address;let X=await y("balance");return N(X,Q)}},{name:"midnight_address",description:"Derive and display an unshielded address from a seed",inputSchema:{type:"object",properties:{seed:{type:"string",description:"Seed to derive from (required, 64-char hex)"},network:{type:"string",description:"Network for address prefix",enum:["preprod","preview","undeployed"]},index:{type:"string",description:"Key derivation index (default: 0)"}},required:["seed"]},async handler($){let Z=i("address",$),Q=await y("address");return N(Q,Z)}},{name:"midnight_genesis_address",description:"Display the genesis wallet address (seed 0x01) for a network",inputSchema:{type:"object",properties:{network:{type:"string",description:"Network for address prefix",enum:["preprod","preview","undeployed"]}}},async handler($){let Z=i("genesis-address",$),Q=await y("genesis-address");return N(Q,Z)}},{name:"midnight_inspect_cost",description:"Display current block limits derived from LedgerParameters",inputSchema:{type:"object",properties:{}},async handler(){let $=i("inspect-cost",{}),Z=await y("inspect-cost");return N(Z,$)}},{name:"midnight_airdrop",description:"Fund your wallet from the genesis wallet (undeployed network only)",inputSchema:{type:"object",properties:{amount:{type:"string",description:"Amount in NIGHT to airdrop"},wallet:{type:"string",description:"Wallet name or path"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}},required:["amount"]},async handler($){let Z=$.amount,Q=i("airdrop",$,Z);delete Q.flags.amount;let X=await y("airdrop");return N(X,Q)}},{name:"midnight_transfer",description:"Send NIGHT tokens to another address",inputSchema:{type:"object",properties:{to:{type:"string",description:"Recipient bech32m address"},amount:{type:"string",description:"Amount in NIGHT to send"},wallet:{type:"string",description:"Wallet name or path"},"proof-server":{type:"string",description:"Override proof server URL"},node:{type:"string",description:"Override substrate node RPC URL"},"indexer-ws":{type:"string",description:"Override indexer WebSocket URL"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}},required:["to","amount"]},async handler($){let{to:Z,amount:Q}=$,X=i("transfer",$,Z);X.positionals=[Q],delete X.flags.to,delete X.flags.amount;let z=await y("transfer");return N(z,X)}},{name:"midnight_dust_register",description:"Register NIGHT UTXOs for dust (fee token) generation",inputSchema:{type:"object",properties:{wallet:{type:"string",description:"Wallet name or path"},"proof-server":{type:"string",description:"Override proof server URL"},node:{type:"string",description:"Override substrate node RPC URL"},"indexer-ws":{type:"string",description:"Override indexer WebSocket URL"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}}},async handler($){let Z=i("dust",$,"register"),Q=await y("dust");return N(Q,Z)}},{name:"midnight_dust_status",description:"Check dust registration status and balance",inputSchema:{type:"object",properties:{wallet:{type:"string",description:"Wallet name or path"},"proof-server":{type:"string",description:"Override proof server URL"},node:{type:"string",description:"Override substrate node RPC URL"},"indexer-ws":{type:"string",description:"Override indexer WebSocket URL"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}}},async handler($){let Z=i("dust",$,"status"),Q=await y("dust");return N(Q,Z)}},{name:"midnight_config_get",description:"Read a persistent config value",inputSchema:{type:"object",properties:{key:{type:"string",description:'Config key to read (e.g. "network")'}},required:["key"]},async handler($){let Q={command:"config",subcommand:"get",positionals:[$.key],flags:{json:!0}},X=await y("config");return N(X,Q)}},{name:"midnight_config_set",description:"Write a persistent config value",inputSchema:{type:"object",properties:{key:{type:"string",description:'Config key to set (e.g. "network")'},value:{type:"string",description:"Config value to set"}},required:["key","value"]},async handler($){let{key:Z,value:Q}=$,X={command:"config",subcommand:"set",positionals:[Z,Q],flags:{json:!0}},z=await y("config");return N(z,X)}},{name:"midnight_cache_clear",description:"Clear cached wallet sync state",inputSchema:{type:"object",properties:{network:{type:"string",description:"Only clear cache for this network",enum:["preprod","preview","undeployed"]},wallet:{type:"string",description:"Only clear cache for this wallet (name or path)"}}},async handler($){let Z=i("cache",$,"clear"),Q=await y("cache");return N(Q,Z)}},{name:"midnight_config_unset",description:"Reset a persistent config value to its default",inputSchema:{type:"object",properties:{key:{type:"string",description:"Config key to reset"}},required:["key"]},async handler($){let Q={command:"config",subcommand:"unset",positionals:[$.key],flags:{json:!0}},X=await y("config");return N(X,Q)}},{name:"midnight_localnet_up",description:"Start a local Midnight network via Docker Compose",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"up",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_stop",description:"Stop local network containers (preserves state for fast restart)",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"stop",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_down",description:"Remove local network containers, networks, and volumes (full teardown)",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"down",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_status",description:"Show local network service status and ports",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"status",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_clean",description:"Remove conflicting containers from other setups",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"clean",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}}],q2=new k7({name:"midnight-wallet-cli",version:V2},{capabilities:{tools:{}}});q2.setRequestHandler(h7,async()=>{return{tools:G3.map(($)=>({name:$.name,description:$.description,inputSchema:$.inputSchema}))}});q2.setRequestHandler(f7,async($)=>{let{name:Z,arguments:Q}=$.params,X=G3.find((z)=>z.name===Z);if(!X)return{content:[{type:"text",text:`Unknown tool: ${Z}`}],isError:!0};try{let z=await X.handler(Q??{});return{content:[{type:"text",text:JSON.stringify(z,null,2)}]}}catch(z){let q=z instanceof Error?z:new Error(String(z)),{errorCode:Y}=j2(q);return{content:[{type:"text",text:JSON.stringify({error:!0,code:Y,message:q.message})}],isError:!0}}});async function u7(){let $=new w7;await q2.connect($)}u7().catch(($)=>{process.stderr.write(`MCP server error: ${$.message}
371
+ `)}},30000);await new Promise(()=>{process.on("SIGINT",()=>{clearInterval(P),process.exit(0)})})}let B=J.reduce((P,x)=>{let F={...Y?.networks[x]??{},...U[x]??{}},O=X2(F);if(O==="down")return"down";if(O==="degraded"&&P!=="down")return"degraded";return P},"up");if(B==="down")process.exitCode=2;else if(B==="degraded")process.exitCode=1}var x7,A7,Z3,E7=15000,L1=5000,Q3=1e4;var Y3=E(()=>{Q0();c();B0();x7={preprod:{faucet:"https://faucet.preprod.midnight.network/",explorer:"https://preprod.midnightexplorer.com/"},preview:{faucet:"https://faucet.preview.midnight.network/",explorer:null},undeployed:{faucet:"",explorer:""}},A7={indexer:"Indexer",rpc:"RPC Node",faucet:"Faucet",explorer:"Explorer",chain:"Chain",dust:"Dust Generation",wallet:"Wallet Ops",dapp:"DApp Flow"},Z3={up:S("UP"),down:a("DOWN"),degraded:R("\x1B[33mDEGRADED\x1B[0m"),unknown:H("—")}});import{Server as k7}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as w7}from"@modelcontextprotocol/sdk/server/stdio.js";import{ListToolsRequestSchema as h7,CallToolRequestSchema as f7}from"@modelcontextprotocol/sdk/types.js";async function N($,Z,Q){let X=[];M1((q)=>X.push(q));let z=process.stderr.write;process.stderr.write=()=>!0;try{Z.flags.json=!0,await $(Z,Q);let q=X.join("").trim();if(!q)return{};return JSON.parse(q)}finally{M1(null),process.stderr.write=z}}var n={INVALID_ARGS:"INVALID_ARGS",WALLET_NOT_FOUND:"WALLET_NOT_FOUND",NETWORK_ERROR:"NETWORK_ERROR",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",TX_REJECTED:"TX_REJECTED",STALE_UTXO:"STALE_UTXO",PROOF_TIMEOUT:"PROOF_TIMEOUT",DUST_REQUIRED:"DUST_REQUIRED",CANCELLED:"CANCELLED",UNKNOWN:"UNKNOWN"};function j2($){let Z=($.message??"").toLowerCase();if(Z.includes("operation cancelled")||Z.includes("operation aborted")||Z==="cancelled"||Z==="aborted")return{exitCode:7,errorCode:n.CANCELLED};if(Z.includes("wallet file not found")||Z.includes("wallet")&&Z.includes("not found"))return{exitCode:3,errorCode:n.WALLET_NOT_FOUND};if(Z.includes("missing required flag")||Z.includes("missing amount")||Z.includes("missing recipient")||Z.includes("missing config key")||Z.includes("missing or invalid subcommand")||Z.includes("unknown command")||Z.includes("cannot specify both")||Z.includes("invalid bip-39")||Z.includes("seed must be")||Z.includes("key index must be")||Z.includes("usage:"))return{exitCode:2,errorCode:n.INVALID_ARGS};if(Z.includes("proof")&&Z.includes("timeout"))return{exitCode:6,errorCode:n.PROOF_TIMEOUT};if(Z.includes("stale utxo")||Z.includes("error code 115")||Z.includes("errorcode: 115"))return{exitCode:6,errorCode:n.STALE_UTXO};if(Z.includes("no dust")||Z.includes("dust")&&(Z.includes("required")||Z.includes("available")||Z.includes("insufficient")))return{exitCode:5,errorCode:n.DUST_REQUIRED};if(Z.includes("insufficient")||Z.includes("not enough"))return{exitCode:5,errorCode:n.INSUFFICIENT_BALANCE};if(Z.includes("rejected")||Z.includes("transaction failed"))return{exitCode:6,errorCode:n.TX_REJECTED};if(Z.includes("econnrefused")||Z.includes("enotfound")||Z.includes("etimedout")||Z.includes("websocket")||Z.includes("connection refused")||Z.includes("network")&&Z.includes("error"))return{exitCode:4,errorCode:n.NETWORK_ERROR};return{exitCode:1,errorCode:n.UNKNOWN}}var p0={name:"midnight-wallet-cli",version:"0.2.1",type:"module",description:"Git-style CLI wallet for the Midnight blockchain",license:"Apache-2.0",workspaces:["packages/*"],bin:{midnight:"dist/wallet.js",mn:"dist/wallet.js","midnight-wallet-cli":"dist/wallet.js","midnight-wallet-mcp":"dist/mcp-server.js"},files:["dist"],scripts:{wallet:"tsx src/wallet.ts",build:'bun build src/wallet.ts --outfile dist/wallet.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node" && bun build src/mcp-server.ts --outfile dist/mcp-server.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node"',mcp:"tsx src/mcp-server.ts",prepublishOnly:"npm run build && npm run test",test:"vitest run","test:watch":"vitest",typecheck:"tsc --noEmit"},dependencies:{"@midnight-ntwrk/dapp-connector-api":"^4.0.1","@midnight-ntwrk/ledger-v7":"^7.0.2","@midnight-ntwrk/midnight-js-network-id":"3.0.0","@midnight-ntwrk/midnight-js-types":"3.0.0","@midnight-ntwrk/wallet-sdk-abstractions":"^2.0.0","@midnight-ntwrk/wallet-sdk-address-format":"^3.0.1","@midnight-ntwrk/wallet-sdk-dust-wallet":"^2.0.0","@midnight-ntwrk/wallet-sdk-facade":"^2.0.0","@midnight-ntwrk/wallet-sdk-hd":"^3.0.1","@midnight-ntwrk/wallet-sdk-shielded":"^2.0.0","@midnight-ntwrk/wallet-sdk-unshielded-wallet":"^2.0.0","@modelcontextprotocol/sdk":"^1.27.1","@scure/bip39":"^2.0.1",rxjs:"^7.8.1",ws:"^8.19.0"},devDependencies:{"@types/node":"^22.19.13","@types/ws":"^8.18.1",tsx:"^4.21.0",typescript:"^5.9.3",vitest:"^3.2.4"}};var t7=p0.name,V2=p0.version,r7=p0.description;function i($,Z,Q){let X={json:!0},z=[];for(let[q,Y]of Object.entries(Z)){if(Y===void 0||Y===null)continue;if(typeof Y==="boolean"){if(Y)X[q]=!0}else X[q]=String(Y)}return{command:$,subcommand:Q,positionals:z,flags:X}}var p7={generate:()=>Promise.resolve().then(() => (m2(),u2)),info:()=>Promise.resolve().then(() => (d2(),g2)),balance:()=>Promise.resolve().then(() => (a2(),r2)),address:()=>Promise.resolve().then(() => ($$(),e2)),"genesis-address":()=>Promise.resolve().then(() => (X$(),Q$)),"inspect-cost":()=>Promise.resolve().then(() => (G$(),Y$)),airdrop:()=>Promise.resolve().then(() => (_$(),M$)),transfer:()=>Promise.resolve().then(() => (x$(),R$)),dust:()=>Promise.resolve().then(() => (C$(),D$)),cache:()=>Promise.resolve().then(() => (b$(),y$)),config:()=>Promise.resolve().then(() => (k$(),v$)),localnet:()=>Promise.resolve().then(() => (n$(),o$)),wallet:()=>Promise.resolve().then(() => ($3(),e$)),status:()=>Promise.resolve().then(() => (Y3(),q3))};async function y($){let Z=p7[$];if(!Z)throw new Error(`Unknown command handler: ${$}`);return(await Z()).default}var G3=[{name:"midnight_generate",description:"Generate a new wallet (deprecated — use midnight_wallet_generate instead)",inputSchema:{type:"object",properties:{network:{type:"string",description:"Network: preprod, preview, undeployed",enum:["preprod","preview","undeployed"]},seed:{type:"string",description:"Restore from existing seed (64-char hex)"},mnemonic:{type:"string",description:"Restore from BIP-39 mnemonic (24 words)"},output:{type:"string",description:"Custom output path (deprecated — use midnight_wallet_generate instead)"},force:{type:"string",description:'Set to "true" to overwrite existing wallet file'}}},async handler($){let Z=i("generate",$);if($.force==="true"||$.force===!0)Z.flags.force=!0;let Q=await y("generate");return N(Q,Z)}},{name:"midnight_wallet_generate",description:"Create a new named wallet and set it as active",inputSchema:{type:"object",properties:{name:{type:"string",description:'Wallet name (e.g. "alice", "dev")'},network:{type:"string",description:"Network: preprod, preview, undeployed",enum:["preprod","preview","undeployed"]},seed:{type:"string",description:"Restore from existing seed (64-char hex)"},mnemonic:{type:"string",description:"Restore from BIP-39 mnemonic (24 words)"},force:{type:"string",description:'Set to "true" to overwrite existing wallet'}},required:["name"]},async handler($){let Z=$.name,Q=i("wallet",$,"generate");if(Q.positionals=[Z],delete Q.flags.name,$.force==="true"||$.force===!0)Q.flags.force=!0;let X=await y("wallet");return N(X,Q)}},{name:"midnight_wallet_list",description:"List all wallets with name, address, network, and active marker",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"wallet",subcommand:"list",positionals:[],flags:{json:!0}},Z=await y("wallet");return N(Z,$)}},{name:"midnight_wallet_use",description:"Set the active wallet by name",inputSchema:{type:"object",properties:{name:{type:"string",description:"Wallet name to activate"}},required:["name"]},async handler($){let Q={command:"wallet",subcommand:"use",positionals:[$.name],flags:{json:!0}},X=await y("wallet");return N(X,Q)}},{name:"midnight_wallet_info",description:"Show details for a named wallet or the active wallet",inputSchema:{type:"object",properties:{name:{type:"string",description:"Wallet name (default: active wallet)"}}},async handler($){let Z=$.name,Q={command:"wallet",subcommand:"info",positionals:Z?[Z]:[],flags:{json:!0}},X=await y("wallet");return N(X,Q)}},{name:"midnight_wallet_remove",description:"Remove a named wallet (refuses active or last wallet)",inputSchema:{type:"object",properties:{name:{type:"string",description:"Wallet name to remove"}},required:["name"]},async handler($){let Q={command:"wallet",subcommand:"remove",positionals:[$.name],flags:{json:!0}},X=await y("wallet");return N(X,Q)}},{name:"midnight_info",description:"Display wallet address, network, creation date (no secrets shown)",inputSchema:{type:"object",properties:{wallet:{type:"string",description:"Wallet name or path"}}},async handler($){let Z=i("info",$),Q=await y("info");return N(Q,Z)}},{name:"midnight_balance",description:"Check unshielded balance via indexer subscription",inputSchema:{type:"object",properties:{address:{type:"string",description:"Address to check (or reads from wallet file)"},wallet:{type:"string",description:"Wallet name or path"},network:{type:"string",description:"Override network detection",enum:["preprod","preview","undeployed"]},"indexer-ws":{type:"string",description:"Custom indexer WebSocket URL"}}},async handler($){let Z=$.address,Q=i("balance",$,Z);delete Q.flags.address;let X=await y("balance");return N(X,Q)}},{name:"midnight_address",description:"Derive and display an unshielded address from a seed",inputSchema:{type:"object",properties:{seed:{type:"string",description:"Seed to derive from (required, 64-char hex)"},network:{type:"string",description:"Network for address prefix",enum:["preprod","preview","undeployed"]},index:{type:"string",description:"Key derivation index (default: 0)"}},required:["seed"]},async handler($){let Z=i("address",$),Q=await y("address");return N(Q,Z)}},{name:"midnight_genesis_address",description:"Display the genesis wallet address (seed 0x01) for a network",inputSchema:{type:"object",properties:{network:{type:"string",description:"Network for address prefix",enum:["preprod","preview","undeployed"]}}},async handler($){let Z=i("genesis-address",$),Q=await y("genesis-address");return N(Q,Z)}},{name:"midnight_inspect_cost",description:"Display current block limits derived from LedgerParameters",inputSchema:{type:"object",properties:{}},async handler(){let $=i("inspect-cost",{}),Z=await y("inspect-cost");return N(Z,$)}},{name:"midnight_airdrop",description:"Fund your wallet from the genesis wallet (undeployed network only)",inputSchema:{type:"object",properties:{amount:{type:"string",description:"Amount in NIGHT to airdrop"},wallet:{type:"string",description:"Wallet name or path"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}},required:["amount"]},async handler($){let Z=$.amount,Q=i("airdrop",$,Z);delete Q.flags.amount;let X=await y("airdrop");return N(X,Q)}},{name:"midnight_transfer",description:"Send NIGHT tokens to another address",inputSchema:{type:"object",properties:{to:{type:"string",description:"Recipient bech32m address"},amount:{type:"string",description:"Amount in NIGHT to send"},wallet:{type:"string",description:"Wallet name or path"},"proof-server":{type:"string",description:"Override proof server URL"},node:{type:"string",description:"Override substrate node RPC URL"},"indexer-ws":{type:"string",description:"Override indexer WebSocket URL"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}},required:["to","amount"]},async handler($){let{to:Z,amount:Q}=$,X=i("transfer",$,Z);X.positionals=[Q],delete X.flags.to,delete X.flags.amount;let z=await y("transfer");return N(z,X)}},{name:"midnight_dust_register",description:"Register NIGHT UTXOs for dust (fee token) generation",inputSchema:{type:"object",properties:{wallet:{type:"string",description:"Wallet name or path"},"proof-server":{type:"string",description:"Override proof server URL"},node:{type:"string",description:"Override substrate node RPC URL"},"indexer-ws":{type:"string",description:"Override indexer WebSocket URL"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}}},async handler($){let Z=i("dust",$,"register"),Q=await y("dust");return N(Q,Z)}},{name:"midnight_dust_status",description:"Check dust registration status and balance",inputSchema:{type:"object",properties:{wallet:{type:"string",description:"Wallet name or path"},"proof-server":{type:"string",description:"Override proof server URL"},node:{type:"string",description:"Override substrate node RPC URL"},"indexer-ws":{type:"string",description:"Override indexer WebSocket URL"},"no-cache":{type:"string",description:'Set to "true" to bypass wallet state cache'}}},async handler($){let Z=i("dust",$,"status"),Q=await y("dust");return N(Q,Z)}},{name:"midnight_config_get",description:"Read a persistent config value",inputSchema:{type:"object",properties:{key:{type:"string",description:'Config key to read (e.g. "network")'}},required:["key"]},async handler($){let Q={command:"config",subcommand:"get",positionals:[$.key],flags:{json:!0}},X=await y("config");return N(X,Q)}},{name:"midnight_config_set",description:"Write a persistent config value",inputSchema:{type:"object",properties:{key:{type:"string",description:'Config key to set (e.g. "network")'},value:{type:"string",description:"Config value to set"}},required:["key","value"]},async handler($){let{key:Z,value:Q}=$,X={command:"config",subcommand:"set",positionals:[Z,Q],flags:{json:!0}},z=await y("config");return N(z,X)}},{name:"midnight_cache_clear",description:"Clear cached wallet sync state",inputSchema:{type:"object",properties:{network:{type:"string",description:"Only clear cache for this network",enum:["preprod","preview","undeployed"]},wallet:{type:"string",description:"Only clear cache for this wallet (name or path)"}}},async handler($){let Z=i("cache",$,"clear"),Q=await y("cache");return N(Q,Z)}},{name:"midnight_config_unset",description:"Reset a persistent config value to its default",inputSchema:{type:"object",properties:{key:{type:"string",description:"Config key to reset"}},required:["key"]},async handler($){let Q={command:"config",subcommand:"unset",positionals:[$.key],flags:{json:!0}},X=await y("config");return N(X,Q)}},{name:"midnight_localnet_up",description:"Start a local Midnight network via Docker Compose",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"up",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_stop",description:"Stop local network containers (preserves state for fast restart)",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"stop",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_down",description:"Remove local network containers, networks, and volumes (full teardown)",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"down",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_status",description:"Show local network service status and ports",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"status",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}},{name:"midnight_localnet_clean",description:"Remove conflicting containers from other setups",inputSchema:{type:"object",properties:{}},async handler(){let $={command:"localnet",subcommand:"clean",positionals:[],flags:{json:!0}},Z=await y("localnet");return N(Z,$)}}],q2=new k7({name:"midnight-wallet-cli",version:V2},{capabilities:{tools:{}}});q2.setRequestHandler(h7,async()=>{return{tools:G3.map(($)=>({name:$.name,description:$.description,inputSchema:$.inputSchema}))}});q2.setRequestHandler(f7,async($)=>{let{name:Z,arguments:Q}=$.params,X=G3.find((z)=>z.name===Z);if(!X)return{content:[{type:"text",text:`Unknown tool: ${Z}`}],isError:!0};try{let z=await X.handler(Q??{});return{content:[{type:"text",text:JSON.stringify(z,null,2)}]}}catch(z){let q=z instanceof Error?z:new Error(String(z)),{errorCode:Y}=j2(q);return{content:[{type:"text",text:JSON.stringify({error:!0,code:Y,message:q.message})}],isError:!0}}});async function u7(){let $=new w7;await q2.connect($)}u7().catch(($)=>{process.stderr.write(`MCP server error: ${$.message}
372
372
  `),process.exit(1)});
package/dist/wallet.js CHANGED
@@ -5,7 +5,7 @@ var h9=Object.defineProperty;var e=($,Z)=>{for(var Q in Z)h9($,Q,{get:Z[Q],enume
5
5
  `).map((Y,J)=>J===0?c(y("Error: "))+c(Y):c(Y));if(Z)X.push(""),X.push(B("Suggestion: ")+Z);let z=W2(X,"heavy");if(R0())return z.replace(/[╔╗╚╝═║]/g,(Y)=>c(Y));return z}function b0($,Z){let X=[`${u("✓")} ${$}`];if(Z)X.push(T("Transaction",t(Z)));return X.join(`
6
6
  `)}var l$=60,d$=15,K1=($)=>$.replace(/\x1b\[[0-9;]*m/g,"");var s=()=>{};function U1($){let Z=($.message??"").toLowerCase();if(Z.includes("operation cancelled")||Z.includes("operation aborted")||Z==="cancelled"||Z==="aborted")return{exitCode:7,errorCode:I0.CANCELLED};if(Z.includes("wallet file not found")||Z.includes("wallet")&&Z.includes("not found"))return{exitCode:3,errorCode:I0.WALLET_NOT_FOUND};if(Z.includes("missing required flag")||Z.includes("missing amount")||Z.includes("missing recipient")||Z.includes("missing config key")||Z.includes("missing or invalid subcommand")||Z.includes("unknown command")||Z.includes("cannot specify both")||Z.includes("invalid bip-39")||Z.includes("seed must be")||Z.includes("key index must be")||Z.includes("usage:"))return{exitCode:2,errorCode:I0.INVALID_ARGS};if(Z.includes("proof")&&Z.includes("timeout"))return{exitCode:6,errorCode:I0.PROOF_TIMEOUT};if(Z.includes("stale utxo")||Z.includes("error code 115")||Z.includes("errorcode: 115"))return{exitCode:6,errorCode:I0.STALE_UTXO};if(Z.includes("no dust")||Z.includes("dust")&&(Z.includes("required")||Z.includes("available")||Z.includes("insufficient")))return{exitCode:5,errorCode:I0.DUST_REQUIRED};if(Z.includes("insufficient")||Z.includes("not enough"))return{exitCode:5,errorCode:I0.INSUFFICIENT_BALANCE};if(Z.includes("rejected")||Z.includes("transaction failed"))return{exitCode:6,errorCode:I0.TX_REJECTED};if(Z.includes("econnrefused")||Z.includes("enotfound")||Z.includes("etimedout")||Z.includes("websocket")||Z.includes("connection refused")||Z.includes("network")&&Z.includes("error"))return{exitCode:4,errorCode:I0.NETWORK_ERROR};return{exitCode:1,errorCode:I0.UNKNOWN}}var I0;var H2=x(()=>{I0={INVALID_ARGS:"INVALID_ARGS",WALLET_NOT_FOUND:"WALLET_NOT_FOUND",NETWORK_ERROR:"NETWORK_ERROR",INSUFFICIENT_BALANCE:"INSUFFICIENT_BALANCE",TX_REJECTED:"TX_REJECTED",STALE_UTXO:"STALE_UTXO",PROOF_TIMEOUT:"PROOF_TIMEOUT",DUST_REQUIRED:"DUST_REQUIRED",CANCELLED:"CANCELLED",UNKNOWN:"UNKNOWN"}});function o$(){let $=process.stderr.write;return process.stderr.write=()=>!0,()=>{process.stderr.write=$}}function L2($){V1=$}function E($){let Z=JSON.stringify($)+`
7
7
  `;if(V1)V1(Z);else process.stdout.write(Z)}function n$($,Z,Q){let X=JSON.stringify({error:!0,code:Z,message:$.message,exitCode:Q})+`
8
- `;if(V1)V1(X);else process.stdout.write(X)}var V1=null;var S1;var a$=x(()=>{S1={name:"midnight-wallet-cli",version:"0.2.0",type:"module",description:"Git-style CLI wallet for the Midnight blockchain",license:"Apache-2.0",workspaces:["packages/*"],bin:{midnight:"dist/wallet.js",mn:"dist/wallet.js","midnight-wallet-cli":"dist/wallet.js","midnight-wallet-mcp":"dist/mcp-server.js"},files:["dist"],scripts:{wallet:"tsx src/wallet.ts",build:'bun build src/wallet.ts --outfile dist/wallet.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node" && bun build src/mcp-server.ts --outfile dist/mcp-server.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node"',mcp:"tsx src/mcp-server.ts",prepublishOnly:"npm run build && npm run test",test:"vitest run","test:watch":"vitest",typecheck:"tsc --noEmit"},dependencies:{"@midnight-ntwrk/dapp-connector-api":"^4.0.1","@midnight-ntwrk/ledger-v7":"^7.0.2","@midnight-ntwrk/midnight-js-network-id":"3.0.0","@midnight-ntwrk/midnight-js-types":"3.0.0","@midnight-ntwrk/wallet-sdk-abstractions":"^2.0.0","@midnight-ntwrk/wallet-sdk-address-format":"^3.0.1","@midnight-ntwrk/wallet-sdk-dust-wallet":"^2.0.0","@midnight-ntwrk/wallet-sdk-facade":"^2.0.0","@midnight-ntwrk/wallet-sdk-hd":"^3.0.1","@midnight-ntwrk/wallet-sdk-shielded":"^2.0.0","@midnight-ntwrk/wallet-sdk-unshielded-wallet":"^2.0.0","@modelcontextprotocol/sdk":"^1.27.1","@scure/bip39":"^2.0.1",rxjs:"^7.8.1",ws:"^8.19.0"},devDependencies:{"@types/node":"^22.19.13","@types/ws":"^8.18.1",tsx:"^4.21.0",typescript:"^5.9.3",vitest:"^3.2.4"}}});var t$,S0,s$;var v1=x(()=>{a$();t$=S1.name,S0=S1.version,s$=S1.description});import{execSync as m9}from"child_process";function A0($){return r$.includes($)}function F2($){return{...g9[$]}}function k1(){return r$}function c9(){try{let $=m9('docker ps --format "{{.Image}}|{{.Ports}}"',{encoding:"utf-8",timeout:5000}),Z={};for(let Q of $.trim().split(`
8
+ `;if(V1)V1(X);else process.stdout.write(X)}var V1=null;var S1;var a$=x(()=>{S1={name:"midnight-wallet-cli",version:"0.2.1",type:"module",description:"Git-style CLI wallet for the Midnight blockchain",license:"Apache-2.0",workspaces:["packages/*"],bin:{midnight:"dist/wallet.js",mn:"dist/wallet.js","midnight-wallet-cli":"dist/wallet.js","midnight-wallet-mcp":"dist/mcp-server.js"},files:["dist"],scripts:{wallet:"tsx src/wallet.ts",build:'bun build src/wallet.ts --outfile dist/wallet.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node" && bun build src/mcp-server.ts --outfile dist/mcp-server.js --target node --format esm --packages external --minify --banner "#!/usr/bin/env node"',mcp:"tsx src/mcp-server.ts",prepublishOnly:"npm run build && npm run test",test:"vitest run","test:watch":"vitest",typecheck:"tsc --noEmit"},dependencies:{"@midnight-ntwrk/dapp-connector-api":"^4.0.1","@midnight-ntwrk/ledger-v7":"^7.0.2","@midnight-ntwrk/midnight-js-network-id":"3.0.0","@midnight-ntwrk/midnight-js-types":"3.0.0","@midnight-ntwrk/wallet-sdk-abstractions":"^2.0.0","@midnight-ntwrk/wallet-sdk-address-format":"^3.0.1","@midnight-ntwrk/wallet-sdk-dust-wallet":"^2.0.0","@midnight-ntwrk/wallet-sdk-facade":"^2.0.0","@midnight-ntwrk/wallet-sdk-hd":"^3.0.1","@midnight-ntwrk/wallet-sdk-shielded":"^2.0.0","@midnight-ntwrk/wallet-sdk-unshielded-wallet":"^2.0.0","@modelcontextprotocol/sdk":"^1.27.1","@scure/bip39":"^2.0.1",rxjs:"^7.8.1",ws:"^8.19.0"},devDependencies:{"@types/node":"^22.19.13","@types/ws":"^8.18.1",tsx:"^4.21.0",typescript:"^5.9.3",vitest:"^3.2.4"}}});var t$,S0,s$;var v1=x(()=>{a$();t$=S1.name,S0=S1.version,s$=S1.description});import{execSync as m9}from"child_process";function A0($){return r$.includes($)}function F2($){return{...g9[$]}}function k1(){return r$}function c9(){try{let $=m9('docker ps --format "{{.Image}}|{{.Ports}}"',{encoding:"utf-8",timeout:5000}),Z={};for(let Q of $.trim().split(`
9
9
  `)){if(!Q)continue;let[X,z]=Q.split("|"),Y=(J)=>{let G=new RegExp(`0\\.0\\.0\\.0:(\\d+)->${J}/tcp`),q=z?.match(G);return q?parseInt(q[1],10):void 0};if(X.includes("indexer-standalone")||X.includes("indexer")){let J=Y(8088);if(J)Z.indexerPort=J}if(X.includes("midnight-node")){let J=Y(9944);if(J)Z.nodePort=J}if(X.includes("proof-server")){let J=Y(6300);if(J)Z.proofServerPort=J}}return Z}catch{return{}}}function e$($){let Z=F2($);if($==="undeployed"){let Q=c9();if(Q.indexerPort)Z.indexer=`http://localhost:${Q.indexerPort}/api/v3/graphql`,Z.indexerWS=`ws://localhost:${Q.indexerPort}/api/v3/graphql/ws`;if(Q.nodePort)Z.node=`ws://localhost:${Q.nodePort}`;if(Q.proofServerPort)Z.proofServer=`http://localhost:${Q.proofServerPort}`}return Z}function _0($,Z,Q){let X=G0(Q);if($.proofServer=Z.proofServer??X["proof-server"]??$.proofServer,$.node=Z.node??X.node??$.node,$.indexerWS=Z.indexerWS??X["indexer-ws"]??$.indexerWS,Z.indexerWS??X["indexer-ws"]){let z=$.indexerWS;$.indexer=z.replace(/^wss:/,"https:").replace(/^ws:/,"http:").replace(/\/ws$/,"")}return $}var g9,r$;var T0=x(()=>{n0();g9={preprod:{indexer:"https://indexer.preprod.midnight.network/api/v3/graphql",indexerWS:"wss://indexer.preprod.midnight.network/api/v3/graphql/ws",node:"wss://rpc.preprod.midnight.network",proofServer:"http://localhost:6300",networkId:"PreProd"},preview:{indexer:"https://indexer.preview.midnight.network/api/v3/graphql",indexerWS:"wss://indexer.preview.midnight.network/api/v3/graphql/ws",node:"wss://rpc.preview.midnight.network",proofServer:"http://localhost:6300",networkId:"Preview"},undeployed:{indexer:"http://localhost:8088/api/v3/graphql",indexerWS:"ws://localhost:8088/api/v3/graphql/ws",node:"ws://localhost:9944",proofServer:"http://localhost:6300",networkId:"Undeployed"}},r$=["preprod","preview","undeployed"]});var Q7={};e(Q7,{unsetConfigValue:()=>T2,setConfigValue:()=>_2,saveCliConfig:()=>a0,loadCliConfig:()=>G0,getValidConfigKeys:()=>f1,getConfigValue:()=>I2});import*as N0 from"fs";import*as P2 from"path";import{homedir as d9}from"os";function l9($){return/^(https?|wss?):\/\/\S+/.test($)}function $7($){return $??P2.join(d9(),J0)}function Z7($){return P2.join($7($),u$)}function i9($){let Z=$7($);if(!N0.existsSync(Z))N0.mkdirSync(Z,{recursive:!0,mode:P0})}function G0($){let Z=Z7($);if(!N0.existsSync(Z))return{...j1};let Q;try{Q=N0.readFileSync(Z,"utf-8")}catch{return{...j1}}let X;try{X=JSON.parse(Q)}catch{return{...j1}}let z={network:X.network&&A0(X.network)?X.network:j1.network};if(X["proof-server"]&&typeof X["proof-server"]==="string")z["proof-server"]=X["proof-server"];if(X.node&&typeof X.node==="string")z.node=X.node;if(X["indexer-ws"]&&typeof X["indexer-ws"]==="string")z["indexer-ws"]=X["indexer-ws"];if(X.wallet&&typeof X.wallet==="string")z.wallet=X.wallet;return z}function a0($,Z){i9(Z);let Q=Z7(Z);N0.writeFileSync(Q,JSON.stringify($,null,2)+`
10
10
  `,{mode:C0})}function I2($,Z){let Q=G0(Z);if($==="network")return Q.network;if($==="wallet")return Q.wallet??"(not set)";if(O2.has($)){let X=Q[$];return typeof X==="string"?X:"(not set)"}throw new Error(`Unknown config key: "${$}"
11
11
  Valid keys: ${w1.join(", ")}`)}function _2($,Z,Q){let X=G0(Q);if($==="network"){if(!A0(Z))throw new Error(`Invalid network: "${Z}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midnight-wallet-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Git-style CLI wallet for the Midnight blockchain",
6
6
  "license": "Apache-2.0",