@stage-labs/metro 0.1.0-beta.155 → 0.1.0-beta.156
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stage-labs/metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.156",
|
|
4
4
|
"description": "The metro command line. Sign in once per machine, then hand your MCP connector list to Claude Code without the credentials touching disk, argv or shell history.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.156",
|
|
4
4
|
"description": "Metro for Claude Code, installed by the metro daemon on this machine: every connector the agent holds as its own MCP server relayed through the daemon, the orchestrator-only guard on the main thread, and the standing rules loaded at each session start. No vendor credential ever sits in a config file.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bonustrack",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { encodeFunctionData, namehash, type Hex } from 'viem';
|
|
2
|
+
import { encodeFunctionData, encodePacked, keccak256, namehash, stringToBytes, type Hex } from 'viem';
|
|
3
3
|
import { normalize } from 'viem/ens';
|
|
4
4
|
import { TrainError } from '@metro-labs/core/train-error';
|
|
5
5
|
import {
|
|
@@ -17,6 +17,7 @@ import { respond } from './wire.js';
|
|
|
17
17
|
|
|
18
18
|
export const BASENAME_REGISTRY = '0xB94704422c2a1E396835A571837Aa5AE53285a95' as const;
|
|
19
19
|
export const BASENAME_L2_RESOLVER = '0xC6d566A56A1aFf6508b41f6c90ff131615583BCD' as const;
|
|
20
|
+
export const BASENAME_REVERSE_REGISTRAR = '0x79EA96012eEa67A83431F1701B3dFf7e37F9E282' as const;
|
|
20
21
|
export const PINEAPPLE_UPLOAD_URL = 'https://pineapple.fyi/upload';
|
|
21
22
|
const STAMP_CLEAR_URL = 'https://stamp.fyi/clear/';
|
|
22
23
|
const ZERO = '0x0000000000000000000000000000000000000000';
|
|
@@ -37,6 +38,16 @@ const RESOLVER_ABI = [
|
|
|
37
38
|
{ name: 'multicall', type: 'function', stateMutability: 'nonpayable', inputs: [{ name: 'data', type: 'bytes[]' }], outputs: [{ name: 'results', type: 'bytes[]' }] },
|
|
38
39
|
] as const;
|
|
39
40
|
|
|
41
|
+
const REVERSE_ABI = [
|
|
42
|
+
{ name: 'setName', type: 'function', stateMutability: 'nonpayable', inputs: [{ name: 'name', type: 'string' }], outputs: [{ name: '', type: 'bytes32' }] },
|
|
43
|
+
] as const;
|
|
44
|
+
|
|
45
|
+
const NAME_ABI = [
|
|
46
|
+
{ name: 'name', type: 'function', stateMutability: 'view', inputs: [{ name: 'node', type: 'bytes32' }], outputs: [{ name: '', type: 'string' }] },
|
|
47
|
+
] as const;
|
|
48
|
+
|
|
49
|
+
const BASE_REVERSE_ROOT = namehash('80002105.reverse');
|
|
50
|
+
|
|
40
51
|
type Args = Record<string, unknown>;
|
|
41
52
|
|
|
42
53
|
const NO_NAME = 'this XMTP account has no name yet, so it has no profile: claim a <label>.stage.base.eth name on its channel page first';
|
|
@@ -54,16 +65,39 @@ export async function pinAvatar(avatar: ProfileAvatar, fetchImpl: typeof fetch =
|
|
|
54
65
|
return `ipfs://${body.result.cid}`;
|
|
55
66
|
}
|
|
56
67
|
|
|
68
|
+
export const encodePrimaryName = (name: string): Hex => encodeFunctionData({ abi: REVERSE_ABI, functionName: 'setName', args: [name] });
|
|
69
|
+
|
|
70
|
+
export const reverseNodeOf = (address: string): Hex =>
|
|
71
|
+
keccak256(encodePacked(['bytes32', 'bytes32'], [BASE_REVERSE_ROOT, keccak256(stringToBytes(address.slice(2).toLowerCase()))]));
|
|
72
|
+
|
|
73
|
+
async function resolverOf(smart: SmartAccount, node: Hex): Promise<Hex> {
|
|
74
|
+
const found: Hex = await smart.publicClient.readContract({ address: BASENAME_REGISTRY, abi: REGISTRY_ABI, functionName: 'resolver', args: [node] });
|
|
75
|
+
return found === ZERO ? BASENAME_L2_RESOLVER : found;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function primaryNameOf(smart: SmartAccount): Promise<string | null> {
|
|
79
|
+
const node = reverseNodeOf(smart.address);
|
|
80
|
+
const found = await smart.publicClient.readContract({ address: await resolverOf(smart, node), abi: NAME_ABI, functionName: 'name', args: [node] }).catch(() => '');
|
|
81
|
+
return found === '' ? null : found;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export async function setPrimaryName(smart: SmartAccount, name: string): Promise<boolean> {
|
|
85
|
+
try {
|
|
86
|
+
await sendSponsored(smart, BASENAME_REVERSE_REGISTRAR, encodePrimaryName(name));
|
|
87
|
+
return true;
|
|
88
|
+
} catch (err) {
|
|
89
|
+
process.stderr.write(`xmtp: the name ${name} is claimed but not set as the primary name of ${smart.address}: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
57
94
|
export function encodeTextRecords(name: string, records: Record<string, string>): Hex {
|
|
58
95
|
const node = namehash(normalize(name));
|
|
59
96
|
const calls = Object.entries(records).map(([key, value]) => encodeFunctionData({ abi: RESOLVER_ABI, functionName: 'setText', args: [node, key, value] }));
|
|
60
97
|
return encodeFunctionData({ abi: RESOLVER_ABI, functionName: 'multicall', args: [calls] });
|
|
61
98
|
}
|
|
62
99
|
|
|
63
|
-
|
|
64
|
-
const found: Hex = await smart.publicClient.readContract({ address: BASENAME_REGISTRY, abi: REGISTRY_ABI, functionName: 'resolver', args: [namehash(normalize(name))] });
|
|
65
|
-
return found === ZERO ? BASENAME_L2_RESOLVER : found;
|
|
66
|
-
}
|
|
100
|
+
const resolverFor = (smart: SmartAccount, name: string): Promise<Hex> => resolverOf(smart, namehash(normalize(name)));
|
|
67
101
|
|
|
68
102
|
async function recordsFor(change: ProfileChange, fetchImpl: typeof fetch): Promise<Record<string, string>> {
|
|
69
103
|
const records: Record<string, string> = {};
|
|
@@ -102,11 +136,18 @@ export async function claimNameAction(id: string, args: Args): Promise<void> {
|
|
|
102
136
|
const held = await nameOf(address);
|
|
103
137
|
if (held !== null) throw new TrainError('name_held', `this account already holds ${held}`);
|
|
104
138
|
const name = await claimName(parseLabel(args.label), address, (message) => smart.signMessage(message));
|
|
105
|
-
|
|
139
|
+
const primary = await setPrimaryName(smart, name);
|
|
140
|
+
respond(id, { result: { account: accountId, name, primary } });
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function ensurePrimaryName(smart: SmartAccount, name: string): Promise<boolean> {
|
|
144
|
+
if ((await primaryNameOf(smart)) === name) return true;
|
|
145
|
+
return setPrimaryName(smart, name);
|
|
106
146
|
}
|
|
107
147
|
|
|
108
148
|
export async function nameAction(id: string, args: Args): Promise<void> {
|
|
109
149
|
const acct = accountForCall(args);
|
|
110
150
|
const name = acct.smart === null ? null : await nameOf(acct.address);
|
|
111
|
-
|
|
151
|
+
const primary = acct.smart !== null && name !== null ? await ensurePrimaryName(acct.smart, name) : false;
|
|
152
|
+
respond(id, { result: { account: acct.cfg.id, name, primary, canClaim: acct.smart !== null && name === null } });
|
|
112
153
|
}
|
package/runtime/runtime.json
CHANGED