@agtnames/cli 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +68 -2
- package/dist/abi.d.ts +239 -0
- package/dist/abi.js +32 -0
- package/dist/args.d.ts +15 -0
- package/dist/args.js +66 -0
- package/dist/browser.d.ts +18 -0
- package/dist/browser.js +309 -0
- package/dist/chain.d.ts +36 -0
- package/dist/chain.js +63 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +326 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +48 -0
- package/dist/endpoints.d.ts +42 -0
- package/dist/endpoints.js +142 -0
- package/dist/init.d.ts +47 -0
- package/dist/init.js +430 -0
- package/dist/keyfile.d.ts +20 -0
- package/dist/keyfile.js +60 -0
- package/dist/manifest.d.ts +49 -0
- package/dist/manifest.js +83 -0
- package/dist/picker.d.ts +55 -0
- package/dist/picker.js +330 -0
- package/dist/probe.d.ts +24 -0
- package/dist/probe.js +105 -0
- package/dist/prompt.d.ts +2 -0
- package/dist/prompt.js +45 -0
- package/dist/register.d.ts +55 -0
- package/dist/register.js +54 -0
- package/dist/signer.d.ts +32 -0
- package/dist/signer.js +40 -0
- package/dist/tui.d.ts +62 -0
- package/dist/tui.js +153 -0
- package/dist/verify.d.ts +32 -0
- package/dist/verify.js +71 -0
- package/dist/widgets.d.ts +91 -0
- package/dist/widgets.js +294 -0
- package/package.json +64 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AGT Domains LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agtnames/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `agt` command: register a `.agt` name, publish its signed manifest, set its records and verify the result, all from a terminal.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @agtnames/cli --help
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
It signs in MetaMask by default. `agt` opens a page on `127.0.0.1` and you approve each signature and transaction in your wallet, so the private key never leaves it. Any browser wallet that injects `window.ethereum` works the same way. For automation, it can also sign with a key from an environment variable or from an encrypted keyfile.
|
|
10
|
+
|
|
11
|
+
## From nothing to a verified agent
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
agt available weather # price and availability
|
|
15
|
+
agt register weather --years 1 # quote → approve USDC → register, approved in your wallet
|
|
16
|
+
agt manifest init weather # writes weather.manifest.json to fill in
|
|
17
|
+
agt manifest publish weather weather.manifest.json
|
|
18
|
+
agt verify weather # signer == manifest owner == on-chain owner, endpoints live
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`register` pays in USDC on Polygon and needs a little POL for gas. The quote the site signs is good for about 15 minutes, so the approval and the registration go out one after the other.
|
|
22
|
+
|
|
23
|
+
`manifest publish` does four things:
|
|
24
|
+
|
|
25
|
+
1. checks that every endpoint in the file answers;
|
|
26
|
+
2. signs the manifest in your wallet (EIP-191 over the canonical JSON);
|
|
27
|
+
3. hosts it at `https://agts.dev/<name>.json`, or on IPFS with `--host ipfs`;
|
|
28
|
+
4. sets the on-chain records in one transaction: the manifest pointer, one endpoint per protocol, `addr`, and the agent wallet if the manifest lists a payment address.
|
|
29
|
+
|
|
30
|
+
Pass `--no-records` to host the document without writing the records.
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
agt available <name>
|
|
36
|
+
agt register <name> [--years N] [--to 0x…] [--dry-run] [--yes]
|
|
37
|
+
agt manifest init <name> [--out file.json]
|
|
38
|
+
agt manifest publish <name> <file.json> [--host agts.dev|ipfs] [--no-records] [--skip-live-check] [--dry-run]
|
|
39
|
+
agt records set <name> [--mcp URL] [--a2a URL] [--http URL] [--ws URL] [--wallet 0x…] [--addr 0x…] [--manifest URI] [--dry-run]
|
|
40
|
+
agt verify <name> [--no-endpoints] [--json]
|
|
41
|
+
agt keyfile create <file>
|
|
42
|
+
agt keyfile address <file>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
With `--dry-run`, a write command signs what needs signing, prints the exact document and transactions, and sends nothing. With `--json`, the result goes to stdout as JSON and progress goes to stderr. Exit codes: 0 done, 1 failed or `verify` found a problem, 2 usage error.
|
|
46
|
+
|
|
47
|
+
## Signing
|
|
48
|
+
|
|
49
|
+
| How | Flag | Key source |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| MetaMask or another browser wallet (default) | none, or `--no-open` to print the page URL | stays in the wallet |
|
|
52
|
+
| Environment variable | `--signer key`, or `--key-env NAME` | `AGT_OWNER_KEY`, or the variable you name |
|
|
53
|
+
| Encrypted keyfile | `--keyfile owner.json` | passphrase from `AGT_KEYFILE_PASSPHRASE` or a hidden prompt |
|
|
54
|
+
|
|
55
|
+
A key is never taken from a command-line argument, where it would end up in shell history. `agt keyfile create` reads the key and passphrase at hidden prompts. It uses the same format as `@agtnames/mcp`'s session key: scrypt, then AES-256-GCM, with the address stored in the clear.
|
|
56
|
+
|
|
57
|
+
The wallet page listens only on `127.0.0.1` under a random path. It refuses requests carrying another Host or Origin, and runs under a strict content security policy. The CLI checks everything that comes back: a signature must recover to the connected account, and the page re-checks the chain and account before each transaction.
|
|
58
|
+
|
|
59
|
+
## Registering for someone else
|
|
60
|
+
|
|
61
|
+
`agt register <name> --to 0x…` pays from your wallet and mints the name to another address. Only that address can then publish the manifest or set records. A manifest signed by anyone else shows as unverified.
|
|
62
|
+
|
|
63
|
+
## Networks
|
|
64
|
+
|
|
65
|
+
`--network polygon` (the default) or `--network amoy`. `--rpc URL` overrides the RPC endpoint (default: the resolver's public fallback list). `--site URL` overrides where quotes and manifest hosting come from (default `https://agtnames.com`). Amoy has no public site, so pass `--site`, for example a local `next dev`. The same settings can come from `AGT_NETWORK`, `AGT_RPC_URL` and `AGT_SITE`.
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT
|
package/dist/abi.d.ts
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
export declare const controllerAbi: readonly [{
|
|
2
|
+
readonly name: "register";
|
|
3
|
+
readonly type: "function";
|
|
4
|
+
readonly stateMutability: "payable";
|
|
5
|
+
readonly inputs: readonly [{
|
|
6
|
+
readonly type: "tuple";
|
|
7
|
+
readonly components: readonly [{
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
readonly name: "label";
|
|
10
|
+
}, {
|
|
11
|
+
readonly type: "address";
|
|
12
|
+
readonly name: "to";
|
|
13
|
+
}, {
|
|
14
|
+
readonly type: "address";
|
|
15
|
+
readonly name: "payToken";
|
|
16
|
+
}, {
|
|
17
|
+
readonly type: "uint256";
|
|
18
|
+
readonly name: "price";
|
|
19
|
+
}, {
|
|
20
|
+
readonly type: "uint64";
|
|
21
|
+
readonly name: "duration";
|
|
22
|
+
}, {
|
|
23
|
+
readonly type: "uint64";
|
|
24
|
+
readonly name: "validUntil";
|
|
25
|
+
}, {
|
|
26
|
+
readonly type: "bytes32";
|
|
27
|
+
readonly name: "nonce";
|
|
28
|
+
}];
|
|
29
|
+
readonly name: "q";
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "bytes";
|
|
32
|
+
readonly name: "sig";
|
|
33
|
+
}];
|
|
34
|
+
readonly outputs: readonly [{
|
|
35
|
+
readonly type: "uint256";
|
|
36
|
+
}];
|
|
37
|
+
}, {
|
|
38
|
+
readonly name: "available";
|
|
39
|
+
readonly type: "function";
|
|
40
|
+
readonly stateMutability: "view";
|
|
41
|
+
readonly inputs: readonly [{
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
readonly name: "label";
|
|
44
|
+
}];
|
|
45
|
+
readonly outputs: readonly [{
|
|
46
|
+
readonly type: "bool";
|
|
47
|
+
}];
|
|
48
|
+
}, {
|
|
49
|
+
readonly name: "valid";
|
|
50
|
+
readonly type: "function";
|
|
51
|
+
readonly stateMutability: "view";
|
|
52
|
+
readonly inputs: readonly [{
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
readonly name: "label";
|
|
55
|
+
}];
|
|
56
|
+
readonly outputs: readonly [{
|
|
57
|
+
readonly type: "bool";
|
|
58
|
+
}];
|
|
59
|
+
}, {
|
|
60
|
+
readonly name: "paused";
|
|
61
|
+
readonly type: "function";
|
|
62
|
+
readonly stateMutability: "view";
|
|
63
|
+
readonly inputs: readonly [];
|
|
64
|
+
readonly outputs: readonly [{
|
|
65
|
+
readonly type: "bool";
|
|
66
|
+
}];
|
|
67
|
+
}, {
|
|
68
|
+
readonly name: "usedNonce";
|
|
69
|
+
readonly type: "function";
|
|
70
|
+
readonly stateMutability: "view";
|
|
71
|
+
readonly inputs: readonly [{
|
|
72
|
+
readonly type: "bytes32";
|
|
73
|
+
}];
|
|
74
|
+
readonly outputs: readonly [{
|
|
75
|
+
readonly type: "bool";
|
|
76
|
+
}];
|
|
77
|
+
}];
|
|
78
|
+
export declare const registryAbi: readonly [{
|
|
79
|
+
readonly name: "tokenIdOf";
|
|
80
|
+
readonly type: "function";
|
|
81
|
+
readonly stateMutability: "pure";
|
|
82
|
+
readonly inputs: readonly [{
|
|
83
|
+
readonly type: "string";
|
|
84
|
+
readonly name: "label";
|
|
85
|
+
}];
|
|
86
|
+
readonly outputs: readonly [{
|
|
87
|
+
readonly type: "uint256";
|
|
88
|
+
}];
|
|
89
|
+
}, {
|
|
90
|
+
readonly name: "ownerOf";
|
|
91
|
+
readonly type: "function";
|
|
92
|
+
readonly stateMutability: "view";
|
|
93
|
+
readonly inputs: readonly [{
|
|
94
|
+
readonly type: "uint256";
|
|
95
|
+
readonly name: "tokenId";
|
|
96
|
+
}];
|
|
97
|
+
readonly outputs: readonly [{
|
|
98
|
+
readonly type: "address";
|
|
99
|
+
}];
|
|
100
|
+
}, {
|
|
101
|
+
readonly name: "resolverOf";
|
|
102
|
+
readonly type: "function";
|
|
103
|
+
readonly stateMutability: "view";
|
|
104
|
+
readonly inputs: readonly [{
|
|
105
|
+
readonly type: "uint256";
|
|
106
|
+
readonly name: "tokenId";
|
|
107
|
+
}];
|
|
108
|
+
readonly outputs: readonly [{
|
|
109
|
+
readonly type: "address";
|
|
110
|
+
}];
|
|
111
|
+
}];
|
|
112
|
+
export declare const resolverAbi: readonly [{
|
|
113
|
+
readonly name: "setAgentManifest";
|
|
114
|
+
readonly type: "function";
|
|
115
|
+
readonly stateMutability: "nonpayable";
|
|
116
|
+
readonly inputs: readonly [{
|
|
117
|
+
readonly type: "bytes32";
|
|
118
|
+
readonly name: "node";
|
|
119
|
+
}, {
|
|
120
|
+
readonly type: "string";
|
|
121
|
+
readonly name: "uri";
|
|
122
|
+
}];
|
|
123
|
+
readonly outputs: readonly [];
|
|
124
|
+
}, {
|
|
125
|
+
readonly name: "setAgentEndpoint";
|
|
126
|
+
readonly type: "function";
|
|
127
|
+
readonly stateMutability: "nonpayable";
|
|
128
|
+
readonly inputs: readonly [{
|
|
129
|
+
readonly type: "bytes32";
|
|
130
|
+
readonly name: "node";
|
|
131
|
+
}, {
|
|
132
|
+
readonly type: "string";
|
|
133
|
+
readonly name: "protocol";
|
|
134
|
+
}, {
|
|
135
|
+
readonly type: "string";
|
|
136
|
+
readonly name: "url";
|
|
137
|
+
}];
|
|
138
|
+
readonly outputs: readonly [];
|
|
139
|
+
}, {
|
|
140
|
+
readonly name: "setAddr";
|
|
141
|
+
readonly type: "function";
|
|
142
|
+
readonly stateMutability: "nonpayable";
|
|
143
|
+
readonly inputs: readonly [{
|
|
144
|
+
readonly type: "bytes32";
|
|
145
|
+
readonly name: "node";
|
|
146
|
+
}, {
|
|
147
|
+
readonly type: "address";
|
|
148
|
+
readonly name: "a";
|
|
149
|
+
}];
|
|
150
|
+
readonly outputs: readonly [];
|
|
151
|
+
}, {
|
|
152
|
+
readonly name: "setAgentWallet";
|
|
153
|
+
readonly type: "function";
|
|
154
|
+
readonly stateMutability: "nonpayable";
|
|
155
|
+
readonly inputs: readonly [{
|
|
156
|
+
readonly type: "bytes32";
|
|
157
|
+
readonly name: "node";
|
|
158
|
+
}, {
|
|
159
|
+
readonly type: "address";
|
|
160
|
+
readonly name: "wallet";
|
|
161
|
+
}];
|
|
162
|
+
readonly outputs: readonly [];
|
|
163
|
+
}, {
|
|
164
|
+
readonly name: "agentManifest";
|
|
165
|
+
readonly type: "function";
|
|
166
|
+
readonly stateMutability: "view";
|
|
167
|
+
readonly inputs: readonly [{
|
|
168
|
+
readonly type: "bytes32";
|
|
169
|
+
readonly name: "node";
|
|
170
|
+
}];
|
|
171
|
+
readonly outputs: readonly [{
|
|
172
|
+
readonly type: "string";
|
|
173
|
+
}];
|
|
174
|
+
}, {
|
|
175
|
+
readonly name: "agentEndpoint";
|
|
176
|
+
readonly type: "function";
|
|
177
|
+
readonly stateMutability: "view";
|
|
178
|
+
readonly inputs: readonly [{
|
|
179
|
+
readonly type: "bytes32";
|
|
180
|
+
readonly name: "node";
|
|
181
|
+
}, {
|
|
182
|
+
readonly type: "string";
|
|
183
|
+
readonly name: "protocol";
|
|
184
|
+
}];
|
|
185
|
+
readonly outputs: readonly [{
|
|
186
|
+
readonly type: "string";
|
|
187
|
+
}];
|
|
188
|
+
}, {
|
|
189
|
+
readonly name: "multicall";
|
|
190
|
+
readonly type: "function";
|
|
191
|
+
readonly stateMutability: "nonpayable";
|
|
192
|
+
readonly inputs: readonly [{
|
|
193
|
+
readonly type: "bytes[]";
|
|
194
|
+
readonly name: "data";
|
|
195
|
+
}];
|
|
196
|
+
readonly outputs: readonly [{
|
|
197
|
+
readonly type: "bytes[]";
|
|
198
|
+
}];
|
|
199
|
+
}];
|
|
200
|
+
export declare const erc20Abi: readonly [{
|
|
201
|
+
readonly name: "allowance";
|
|
202
|
+
readonly type: "function";
|
|
203
|
+
readonly stateMutability: "view";
|
|
204
|
+
readonly inputs: readonly [{
|
|
205
|
+
readonly type: "address";
|
|
206
|
+
readonly name: "owner";
|
|
207
|
+
}, {
|
|
208
|
+
readonly type: "address";
|
|
209
|
+
readonly name: "spender";
|
|
210
|
+
}];
|
|
211
|
+
readonly outputs: readonly [{
|
|
212
|
+
readonly type: "uint256";
|
|
213
|
+
}];
|
|
214
|
+
}, {
|
|
215
|
+
readonly name: "approve";
|
|
216
|
+
readonly type: "function";
|
|
217
|
+
readonly stateMutability: "nonpayable";
|
|
218
|
+
readonly inputs: readonly [{
|
|
219
|
+
readonly type: "address";
|
|
220
|
+
readonly name: "spender";
|
|
221
|
+
}, {
|
|
222
|
+
readonly type: "uint256";
|
|
223
|
+
readonly name: "amount";
|
|
224
|
+
}];
|
|
225
|
+
readonly outputs: readonly [{
|
|
226
|
+
readonly type: "bool";
|
|
227
|
+
}];
|
|
228
|
+
}, {
|
|
229
|
+
readonly name: "balanceOf";
|
|
230
|
+
readonly type: "function";
|
|
231
|
+
readonly stateMutability: "view";
|
|
232
|
+
readonly inputs: readonly [{
|
|
233
|
+
readonly type: "address";
|
|
234
|
+
readonly name: "account";
|
|
235
|
+
}];
|
|
236
|
+
readonly outputs: readonly [{
|
|
237
|
+
readonly type: "uint256";
|
|
238
|
+
}];
|
|
239
|
+
}];
|
package/dist/abi.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract surface the CLI writes through. Mirrors the site's src/lib/agt-abi.ts (source of truth:
|
|
3
|
+
* contracts/contracts/launch/*.sol); only what the four write commands need.
|
|
4
|
+
*/
|
|
5
|
+
import { parseAbi } from "viem";
|
|
6
|
+
export const controllerAbi = parseAbi([
|
|
7
|
+
"struct Quote { string label; address to; address payToken; uint256 price; uint64 duration; uint64 validUntil; bytes32 nonce; }",
|
|
8
|
+
"function register(Quote q, bytes sig) payable returns (uint256)",
|
|
9
|
+
"function available(string label) view returns (bool)",
|
|
10
|
+
"function valid(string label) view returns (bool)",
|
|
11
|
+
"function paused() view returns (bool)",
|
|
12
|
+
"function usedNonce(bytes32) view returns (bool)",
|
|
13
|
+
]);
|
|
14
|
+
export const registryAbi = parseAbi([
|
|
15
|
+
"function tokenIdOf(string label) pure returns (uint256)",
|
|
16
|
+
"function ownerOf(uint256 tokenId) view returns (address)",
|
|
17
|
+
"function resolverOf(uint256 tokenId) view returns (address)",
|
|
18
|
+
]);
|
|
19
|
+
export const resolverAbi = parseAbi([
|
|
20
|
+
"function setAgentManifest(bytes32 node, string uri)",
|
|
21
|
+
"function setAgentEndpoint(bytes32 node, string protocol, string url)",
|
|
22
|
+
"function setAddr(bytes32 node, address a)",
|
|
23
|
+
"function setAgentWallet(bytes32 node, address wallet)",
|
|
24
|
+
"function agentManifest(bytes32 node) view returns (string)",
|
|
25
|
+
"function agentEndpoint(bytes32 node, string protocol) view returns (string)",
|
|
26
|
+
"function multicall(bytes[] data) returns (bytes[])",
|
|
27
|
+
]);
|
|
28
|
+
export const erc20Abi = parseAbi([
|
|
29
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
30
|
+
"function approve(address spender, uint256 amount) returns (bool)",
|
|
31
|
+
"function balanceOf(address account) view returns (uint256)",
|
|
32
|
+
]);
|
package/dist/args.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Argument parsing: positionals, `--flag value`, `--flag=value`, and declared booleans. Unknown flags are errors. */
|
|
2
|
+
export declare class UsageError extends Error {
|
|
3
|
+
constructor(m: string);
|
|
4
|
+
}
|
|
5
|
+
export declare const BOOLEAN_FLAGS: readonly ["dry-run", "json", "yes", "no-open", "no-records", "no-endpoints", "skip-live-check", "template", "no-probe", "help", "version"];
|
|
6
|
+
export declare const VALUE_FLAGS: readonly ["network", "rpc", "site", "signer", "key-env", "keyfile", "years", "to", "host", "out", "mcp", "a2a", "http", "ws", "wallet", "addr", "manifest", "timeout", "shell"];
|
|
7
|
+
export interface Parsed {
|
|
8
|
+
positionals: string[];
|
|
9
|
+
flags: Record<string, string>;
|
|
10
|
+
bools: Set<string>;
|
|
11
|
+
}
|
|
12
|
+
export declare function parseArgs(argv: string[]): Parsed;
|
|
13
|
+
export declare function parseYears(v: string | undefined): number;
|
|
14
|
+
export declare function parseAddressFlag(v: string | undefined, flag: string): `0x${string}` | undefined;
|
|
15
|
+
export declare function parseHttpsFlag(v: string | undefined, flag: string): string | undefined;
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Argument parsing: positionals, `--flag value`, `--flag=value`, and declared booleans. Unknown flags are errors. */
|
|
2
|
+
export class UsageError extends Error {
|
|
3
|
+
constructor(m) { super(m); this.name = "UsageError"; }
|
|
4
|
+
}
|
|
5
|
+
export const BOOLEAN_FLAGS = ["dry-run", "json", "yes", "no-open", "no-records", "no-endpoints", "skip-live-check", "template", "no-probe", "help", "version"];
|
|
6
|
+
export const VALUE_FLAGS = ["network", "rpc", "site", "signer", "key-env", "keyfile", "years", "to", "host", "out", "mcp", "a2a", "http", "ws", "wallet", "addr", "manifest", "timeout", "shell"];
|
|
7
|
+
export function parseArgs(argv) {
|
|
8
|
+
const positionals = [];
|
|
9
|
+
const flags = {};
|
|
10
|
+
const bools = new Set();
|
|
11
|
+
for (let i = 0; i < argv.length; i++) {
|
|
12
|
+
const a = argv[i];
|
|
13
|
+
if (a === "-h") {
|
|
14
|
+
bools.add("help");
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (!a.startsWith("--")) {
|
|
18
|
+
positionals.push(a);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const eq = a.indexOf("=");
|
|
22
|
+
const name = a.slice(2, eq > 0 ? eq : undefined);
|
|
23
|
+
if (BOOLEAN_FLAGS.includes(name)) {
|
|
24
|
+
if (eq > 0)
|
|
25
|
+
throw new UsageError(`--${name} takes no value`);
|
|
26
|
+
bools.add(name);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!VALUE_FLAGS.includes(name))
|
|
30
|
+
throw new UsageError(`unknown option --${name}`);
|
|
31
|
+
const value = eq > 0 ? a.slice(eq + 1) : argv[++i];
|
|
32
|
+
if (value === undefined || (eq < 0 && value.startsWith("--")))
|
|
33
|
+
throw new UsageError(`--${name} needs a value`);
|
|
34
|
+
flags[name] = value;
|
|
35
|
+
}
|
|
36
|
+
return { positionals, flags, bools };
|
|
37
|
+
}
|
|
38
|
+
export function parseYears(v) {
|
|
39
|
+
if (v === undefined)
|
|
40
|
+
return 1;
|
|
41
|
+
const n = Number(v);
|
|
42
|
+
if (!Number.isInteger(n) || n < 1 || n > 10)
|
|
43
|
+
throw new UsageError("--years must be a whole number from 1 to 10");
|
|
44
|
+
return n;
|
|
45
|
+
}
|
|
46
|
+
export function parseAddressFlag(v, flag) {
|
|
47
|
+
if (v === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(v))
|
|
50
|
+
throw new UsageError(`--${flag} must be a 0x address (40 hex characters)${/^0x[0-9a-fA-F]{64}$/.test(v) ? "; that looks like a private key, never pass one on the command line" : ""}`);
|
|
51
|
+
return v;
|
|
52
|
+
}
|
|
53
|
+
export function parseHttpsFlag(v, flag) {
|
|
54
|
+
if (v === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
let u;
|
|
57
|
+
try {
|
|
58
|
+
u = new URL(v);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
throw new UsageError(`--${flag} is not a URL: ${v}`);
|
|
62
|
+
}
|
|
63
|
+
if (u.protocol !== "https:" && !(flag === "ws" && u.protocol === "wss:"))
|
|
64
|
+
throw new UsageError(`--${flag} must be an https:// URL`);
|
|
65
|
+
return v;
|
|
66
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Network } from "./config.js";
|
|
2
|
+
import type { Signer } from "./signer.js";
|
|
3
|
+
export interface BrowserSignerOptions {
|
|
4
|
+
network: Network;
|
|
5
|
+
/** Opens the URL; default launches the system browser. Pass a no-op for --no-open or tests. */
|
|
6
|
+
open?: (url: string) => void;
|
|
7
|
+
/** Called once with the URL so the terminal can show it. */
|
|
8
|
+
onUrl?: (url: string) => void;
|
|
9
|
+
/** Per-request wait for the user, default 10 minutes. */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
port?: number;
|
|
12
|
+
}
|
|
13
|
+
export declare class WalletRejectedError extends Error {
|
|
14
|
+
readonly code?: number | undefined;
|
|
15
|
+
constructor(message: string, code?: number | undefined);
|
|
16
|
+
}
|
|
17
|
+
export declare function openInBrowser(url: string): void;
|
|
18
|
+
export declare function browserSigner(opts: BrowserSignerOptions): Promise<Signer>;
|