@heyditto/cli 3.22.2 → 3.23.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/README.md +102 -0
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/gamma/btauth.d.ts +84 -0
- package/dist/gamma/btauth.js +175 -0
- package/dist/gamma/btauth.js.map +1 -0
- package/dist/gamma/client.d.ts +145 -0
- package/dist/gamma/client.js +551 -0
- package/dist/gamma/client.js.map +1 -0
- package/dist/gamma/commands.d.ts +4 -0
- package/dist/gamma/commands.js +194 -0
- package/dist/gamma/commands.js.map +1 -0
- package/dist/gamma/hotkey.d.ts +51 -0
- package/dist/gamma/hotkey.js +241 -0
- package/dist/gamma/hotkey.js.map +1 -0
- package/dist/review-commands.js +85 -14
- package/dist/review-commands.js.map +1 -1
- package/dist/update-lock.json +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `heyditto gamma …`: use Ditto Router's paid inference with a Bittensor
|
|
3
|
+
* hotkey alone (Gamma Integration Standard V1.3 §4/§4a, SN118). No Ditto
|
|
4
|
+
* login or API key is read or sent by these commands.
|
|
5
|
+
*
|
|
6
|
+
* The crypto modules load lazily so the rest of the CLI never pays for them.
|
|
7
|
+
*/
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { Option } from "commander";
|
|
10
|
+
/** The session every `gamma chat` turn joins unless told otherwise. */
|
|
11
|
+
export const DEFAULT_GAMMA_SESSION = "heyditto-gamma-cli";
|
|
12
|
+
function addGammaOptions(cmd) {
|
|
13
|
+
return cmd
|
|
14
|
+
.option("--wallet <name>", "btcli wallet name (default: BT_WALLET_NAME or default)")
|
|
15
|
+
.option("--hotkey <name>", "btcli hotkey name (default: BT_WALLET_HOTKEY or default); read-only commands also take an SS58")
|
|
16
|
+
.option("--wallet-path <dir>", "btcli wallets directory (default: BT_WALLET_PATH or ~/.bittensor/wallets)")
|
|
17
|
+
.option("--hotkey-file <path>", "an unencrypted btcli hotkey file")
|
|
18
|
+
.option("--hotkey-uri <uri>", "a dev secret URI such as //Alice (visible to other local processes; prefer DITTO_HOTKEY_MNEMONIC)")
|
|
19
|
+
.addOption(new Option("--crypto <scheme>", "key scheme for --hotkey-uri, DITTO_HOTKEY_MNEMONIC and DITTO_HOTKEY_SEED").choices(["sr25519", "ed25519"]))
|
|
20
|
+
.option("--services <url>", "services document URL (default: DITTO_GAMMA_SERVICES_URL or the SN118 set_service URL)")
|
|
21
|
+
.option("--netuid <n>", "subnet of the publisher hotkey", "118")
|
|
22
|
+
.option("--receiver <ss58>", "sign for this publisher hotkey (must be listed in the services document)")
|
|
23
|
+
.option("--allow-untrusted-origin", "sign requests for an API host outside heyditto.ai (also DITTO_GAMMA_ALLOW_UNTRUSTED_ORIGIN=1); only for a host you run")
|
|
24
|
+
.addOption(new Option("--output <format>", "output format").choices(["text", "json"]).default("text"));
|
|
25
|
+
}
|
|
26
|
+
function netuidOf(raw) {
|
|
27
|
+
const n = Number(raw ?? "118");
|
|
28
|
+
if (!Number.isInteger(n) || n < 0 || n > 65535)
|
|
29
|
+
throw new Error("--netuid must be an integer subnet id");
|
|
30
|
+
return n;
|
|
31
|
+
}
|
|
32
|
+
async function discovery(o) {
|
|
33
|
+
const { discover } = await import("./client.js");
|
|
34
|
+
return discover({ servicesUrl: o.services, netuid: netuidOf(o.netuid), receiver: o.receiver, allowUntrustedOrigin: o.allowUntrustedOrigin });
|
|
35
|
+
}
|
|
36
|
+
function hotkeyName(key) {
|
|
37
|
+
return key?.btcliName?.hotkey ?? "HOTKEY_NAME";
|
|
38
|
+
}
|
|
39
|
+
async function signedClient(o) {
|
|
40
|
+
const { loadHotkey } = await import("./hotkey.js");
|
|
41
|
+
const key = await loadHotkey(o, true);
|
|
42
|
+
const d = await discovery(o);
|
|
43
|
+
return { client: { discovery: d, signer: key.signer, hotkeyName: hotkeyName(key) }, key };
|
|
44
|
+
}
|
|
45
|
+
const json = (o) => o.output === "json";
|
|
46
|
+
const print = (value) => process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
47
|
+
export function registerGammaCommands(program, addExamples) {
|
|
48
|
+
const gamma = program
|
|
49
|
+
.command("gamma")
|
|
50
|
+
.description("use Ditto Router with only a Bittensor hotkey that spent SN118 gamma (btauth/1; no login or API key)");
|
|
51
|
+
addExamples(gamma, ` heyditto gamma info # your hotkey, Ditto's publisher hotkey, how to fund it
|
|
52
|
+
heyditto gamma balance
|
|
53
|
+
heyditto gamma chat "Summarize btauth/1 in one line"
|
|
54
|
+
heyditto gamma models --wallet my_wallet --hotkey ditto_pay
|
|
55
|
+
|
|
56
|
+
The hotkey is the account: spend gamma at Ditto's publisher hotkey with btcli
|
|
57
|
+
and the signing hotkey is credited in USD (1 gamma = 1 USD). Every request is
|
|
58
|
+
signed with btauth/1; no Ditto login, API key or account link is used.
|
|
59
|
+
Exit status: 0 ok, 3 the hotkey's balance is empty (HTTP 402), 1 other errors.`);
|
|
60
|
+
addGammaOptions(gamma.command("info"))
|
|
61
|
+
.description("print the hotkey, discovered publisher hotkey and URLs, and the btcli commands that fund it")
|
|
62
|
+
.action(async (o) => {
|
|
63
|
+
const { loadHotkey } = await import("./hotkey.js");
|
|
64
|
+
const { fundingHelp } = await import("./client.js");
|
|
65
|
+
let key;
|
|
66
|
+
let keyError;
|
|
67
|
+
try {
|
|
68
|
+
key = await loadHotkey(o, false);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
keyError = error instanceof Error ? error.message : String(error);
|
|
72
|
+
}
|
|
73
|
+
const d = await discovery(o);
|
|
74
|
+
if (json(o)) {
|
|
75
|
+
print({ hotkey: key?.address ?? null, crypto: key?.scheme ?? null, hotkeySource: key?.source ?? null, hotkeyError: keyError ?? null, ...d });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const name = hotkeyName(key);
|
|
79
|
+
const lines = [
|
|
80
|
+
key ? `Hotkey: ${key.address} (${key.scheme}, from ${key.source})` : `Hotkey: not loaded (${keyError})`,
|
|
81
|
+
`Publisher hotkey: ${d.receiver} (netuid ${d.netuid}; requests are signed for it)`,
|
|
82
|
+
...(d.publishers.length > 1 ? [`All publishers: ${d.publishers.join(", ")}`] : []),
|
|
83
|
+
`API base: ${d.apiBase}`,
|
|
84
|
+
`Balance: ${d.balanceUrl}?hotkey=<ss58>`,
|
|
85
|
+
`OpenAPI: ${d.openapiUrl}`,
|
|
86
|
+
`Pricing: ${d.pricingUrl ?? "(not listed)"}`,
|
|
87
|
+
`Services document: ${d.servicesUrl}`,
|
|
88
|
+
"",
|
|
89
|
+
"Fund this hotkey (btcli; 1 gamma = 1 USD, credited within about 10 finalized blocks):",
|
|
90
|
+
...(key?.btcliName ? [] : [` btcli wallet new-hotkey --hotkey ${name}`]),
|
|
91
|
+
fundingHelp(d, name),
|
|
92
|
+
` btcli gamma show --netuid ${d.netuid} --hotkey ${name}`,
|
|
93
|
+
"",
|
|
94
|
+
"Then: heyditto gamma balance, heyditto gamma chat \"…\".",
|
|
95
|
+
key ? `Ditto Desktop uses the same btcli hotkey file; it should show ${key.address}.` : "Ditto Desktop uses the same btcli hotkey file, so both share one account.",
|
|
96
|
+
];
|
|
97
|
+
process.stdout.write(`${lines.join("\n")}\n`);
|
|
98
|
+
});
|
|
99
|
+
addGammaOptions(gamma.command("balance"))
|
|
100
|
+
.description("print the hotkey's Ditto balance in USD (public; no signature needed)")
|
|
101
|
+
.action(async (o) => {
|
|
102
|
+
const { loadHotkey } = await import("./hotkey.js");
|
|
103
|
+
const { fetchBalance } = await import("./client.js");
|
|
104
|
+
const key = await loadHotkey(o, false);
|
|
105
|
+
const d = await discovery(o);
|
|
106
|
+
const b = await fetchBalance(d, key.address);
|
|
107
|
+
if (json(o)) {
|
|
108
|
+
print(b);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
process.stdout.write([
|
|
112
|
+
`hotkey ${b.hotkey}`,
|
|
113
|
+
`credited_usd ${b.credited_usd}`,
|
|
114
|
+
`used_usd ${b.used_usd}`,
|
|
115
|
+
`remaining_usd ${b.remaining_usd}`,
|
|
116
|
+
].join("\n") + "\n");
|
|
117
|
+
});
|
|
118
|
+
addGammaOptions(gamma.command("models"))
|
|
119
|
+
.description("list the models this hotkey can call (btauth/1-signed GET /v1/models)")
|
|
120
|
+
.action(async (o) => {
|
|
121
|
+
const { listModels } = await import("./client.js");
|
|
122
|
+
const { client } = await signedClient(o);
|
|
123
|
+
const models = await listModels(client);
|
|
124
|
+
if (json(o))
|
|
125
|
+
print(models.raw);
|
|
126
|
+
else
|
|
127
|
+
process.stdout.write(models.ids.length ? `${models.ids.join("\n")}\n` : "(no models)\n");
|
|
128
|
+
});
|
|
129
|
+
addGammaOptions(gamma.command("chat"))
|
|
130
|
+
.description("send one prompt to Ditto Router (btauth/1-signed POST /v1/chat/completions)")
|
|
131
|
+
.argument("<prompt>", "the prompt")
|
|
132
|
+
.option("--model <id>", "model id (default: the pricing document's default_model)")
|
|
133
|
+
.option("--session <id>", `session the turn joins, so turns build one thread on the hotkey account (default: ${DEFAULT_GAMMA_SESSION})`)
|
|
134
|
+
.option("--new-session", "start a fresh session and print its id")
|
|
135
|
+
.option("--no-stream", "wait for the whole answer instead of streaming it")
|
|
136
|
+
.option("--stream-timeout <seconds>", "cancel a streamed answer after this long in all (default 900, or DITTO_GAMMA_STREAM_TIMEOUT_MS)")
|
|
137
|
+
.option("--idle-timeout <seconds>", "cancel a streamed answer that sends nothing for this long (default 120, or DITTO_GAMMA_STREAM_IDLE_MS)")
|
|
138
|
+
.action(async (prompt, o) => {
|
|
139
|
+
const { chat, defaultModel, parseTimerLimit, streamLimits } = await import("./client.js");
|
|
140
|
+
const stream = o.stream !== false && !json(o);
|
|
141
|
+
// Stream limits matter only when streaming: an invalid streaming setting
|
|
142
|
+
// never breaks a --no-stream or --output json chat.
|
|
143
|
+
let limits;
|
|
144
|
+
if (stream) {
|
|
145
|
+
limits = streamLimits();
|
|
146
|
+
if (o.streamTimeout !== undefined)
|
|
147
|
+
limits.totalMs = parseTimerLimit(o.streamTimeout, 1000, "--stream-timeout (seconds)");
|
|
148
|
+
if (o.idleTimeout !== undefined)
|
|
149
|
+
limits.idleMs = parseTimerLimit(o.idleTimeout, 1000, "--idle-timeout (seconds)");
|
|
150
|
+
}
|
|
151
|
+
if (o.session && o.newSession)
|
|
152
|
+
throw new Error("use --session or --new-session, not both");
|
|
153
|
+
if (!prompt.trim())
|
|
154
|
+
throw new Error("the prompt is empty");
|
|
155
|
+
const { client } = await signedClient(o);
|
|
156
|
+
const model = o.model ?? await defaultModel(client.discovery);
|
|
157
|
+
if (!model)
|
|
158
|
+
throw new Error("no --model given and the pricing document names no default_model");
|
|
159
|
+
const session = o.newSession ? `heyditto-gamma-${randomUUID()}` : (o.session ?? DEFAULT_GAMMA_SESSION);
|
|
160
|
+
if (o.newSession)
|
|
161
|
+
process.stderr.write(`session: ${session} (continue it with --session ${session})\n`);
|
|
162
|
+
let wrote = false;
|
|
163
|
+
const result = await chat(client, {
|
|
164
|
+
model, prompt, session, stream, limits,
|
|
165
|
+
onDelta: stream ? (t) => { wrote = true; process.stdout.write(t); } : undefined,
|
|
166
|
+
});
|
|
167
|
+
if (json(o)) {
|
|
168
|
+
print(result.raw ?? { model: result.model, content: result.text, session });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (!stream)
|
|
172
|
+
process.stdout.write(result.text);
|
|
173
|
+
if (!wrote || !result.text.endsWith("\n"))
|
|
174
|
+
process.stdout.write("\n");
|
|
175
|
+
});
|
|
176
|
+
const memories = gamma.command("memories").description("the hotkey account's Ditto memories (Router MCP surface, btauth/1-signed)");
|
|
177
|
+
addGammaOptions(memories.command("search"))
|
|
178
|
+
.description("search the hotkey account's memories")
|
|
179
|
+
.argument("<query>", "what to look for")
|
|
180
|
+
.option("--limit <n>", "max memories")
|
|
181
|
+
.action(async (query, o) => {
|
|
182
|
+
const { searchMemories } = await import("./client.js");
|
|
183
|
+
const limit = o.limit === undefined ? undefined : Number(o.limit);
|
|
184
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 1))
|
|
185
|
+
throw new Error("--limit must be a positive integer");
|
|
186
|
+
const { client } = await signedClient(o);
|
|
187
|
+
const result = await searchMemories(client, query, limit);
|
|
188
|
+
if (json(o))
|
|
189
|
+
print(result.raw);
|
|
190
|
+
else
|
|
191
|
+
process.stdout.write(result.text ? `${result.text}\n` : "(no memories)\n");
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../../src/gamma/commands.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAW,MAAM,EAAE,MAAM,WAAW,CAAC;AAY5C,uEAAuE;AACvE,MAAM,CAAC,MAAM,qBAAqB,GAAG,oBAAoB,CAAC;AAE1D,SAAS,eAAe,CAAC,GAAY;IACnC,OAAO,GAAG;SACP,MAAM,CAAC,iBAAiB,EAAE,wDAAwD,CAAC;SACnF,MAAM,CAAC,iBAAiB,EAAE,gGAAgG,CAAC;SAC3H,MAAM,CAAC,qBAAqB,EAAE,2EAA2E,CAAC;SAC1G,MAAM,CAAC,sBAAsB,EAAE,kCAAkC,CAAC;SAClE,MAAM,CAAC,oBAAoB,EAAE,mGAAmG,CAAC;SACjI,SAAS,CAAC,IAAI,MAAM,CAAC,mBAAmB,EAAE,0EAA0E,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;SACtJ,MAAM,CAAC,kBAAkB,EAAE,wFAAwF,CAAC;SACpH,MAAM,CAAC,cAAc,EAAE,gCAAgC,EAAE,KAAK,CAAC;SAC/D,MAAM,CAAC,mBAAmB,EAAE,0EAA0E,CAAC;SACvG,MAAM,CAAC,0BAA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,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAClE,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC1H,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,CAAC,CAAC;YAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;;YAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;IAClF,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type BtauthScheme, type HotkeySigner } from "./btauth.js";
|
|
2
|
+
/** Bittensor's SS58 prefix (generic substrate, 42). */
|
|
3
|
+
export declare const SS58_PREFIX = 42;
|
|
4
|
+
export interface HotkeyOptions {
|
|
5
|
+
/** btcli wallet name (default BT_WALLET_NAME or "default"). */
|
|
6
|
+
wallet?: string;
|
|
7
|
+
/** btcli hotkey name, or an SS58 address for read-only commands. */
|
|
8
|
+
hotkey?: string;
|
|
9
|
+
/** btcli wallets directory (default BT_WALLET_PATH or ~/.bittensor/wallets). */
|
|
10
|
+
walletPath?: string;
|
|
11
|
+
/** An explicit hotkey file path. */
|
|
12
|
+
hotkeyFile?: string;
|
|
13
|
+
/** A dev secret URI such as //Alice. */
|
|
14
|
+
hotkeyUri?: string;
|
|
15
|
+
/** Scheme for URI/seed/mnemonic sources (files carry their own). */
|
|
16
|
+
crypto?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface LoadedHotkey {
|
|
19
|
+
address: string;
|
|
20
|
+
scheme: BtauthScheme;
|
|
21
|
+
/** Where the key came from, safe to print (a path or an env var name, never a value). */
|
|
22
|
+
source: string;
|
|
23
|
+
/** The btcli hotkey name, when it came from a wallet, for btcli command hints. */
|
|
24
|
+
btcliName?: {
|
|
25
|
+
wallet: string;
|
|
26
|
+
hotkey: string;
|
|
27
|
+
};
|
|
28
|
+
/** Undefined when only the address is known (an SS58 given directly). */
|
|
29
|
+
signer?: HotkeySigner;
|
|
30
|
+
}
|
|
31
|
+
/** True when value is a valid SS58 address (checksum included). */
|
|
32
|
+
export declare function isAddress(value: string | undefined): value is string;
|
|
33
|
+
export declare function normalizeAddress(value: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* A btcli wallet or hotkey name: never a path on any OS. Separators of every
|
|
36
|
+
* platform (`/`, `\`), drive colons, NUL and a leading dot are refused, so a
|
|
37
|
+
* name cannot leave the wallet's hotkeys directory.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isSafeKeyName(name: string): boolean;
|
|
40
|
+
/** The btcli hotkey file the options name. */
|
|
41
|
+
export declare function hotkeyFilePath(o: HotkeyOptions, env?: NodeJS.ProcessEnv): string;
|
|
42
|
+
/** Parses an unencrypted btcli hotkey file. Errors never quote the file. */
|
|
43
|
+
export declare function signerFromKeyfile(data: Buffer, label: string): Promise<{
|
|
44
|
+
signer: HotkeySigner;
|
|
45
|
+
recorded?: string;
|
|
46
|
+
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the hotkey. With `needSigner` false an SS58 `--hotkey`, or the
|
|
49
|
+
* address recorded in a hotkey file, is enough and no secret is parsed.
|
|
50
|
+
*/
|
|
51
|
+
export declare function loadHotkey(o: HotkeyOptions, needSigner: boolean, env?: NodeJS.ProcessEnv): Promise<LoadedHotkey>;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loading the Bittensor hotkey that signs btauth/1 requests.
|
|
3
|
+
*
|
|
4
|
+
* The shared source is btcli's wallet hotkey file,
|
|
5
|
+
* `~/.bittensor/wallets/<wallet>/hotkeys/<hotkey>` (wallet and hotkey both
|
|
6
|
+
* `default` unless named), so the CLI and Ditto Desktop use the same hotkey and
|
|
7
|
+
* therefore the same Ditto account. btcli writes that file unencrypted by
|
|
8
|
+
* default as JSON with `secretPhrase`, `secretSeed`, `privateKey`,
|
|
9
|
+
* `publicKey`/`accountId`, `ss58Address` and `cryptoType` (1 sr25519,
|
|
10
|
+
* 0 ed25519; absent means sr25519). An encrypted file is refused with
|
|
11
|
+
* guidance rather than prompted for.
|
|
12
|
+
*
|
|
13
|
+
* Alternatives: DITTO_HOTKEY_MNEMONIC, DITTO_HOTKEY_SEED (0x + 32-byte hex) or
|
|
14
|
+
* `--hotkey-uri` (a dev URI such as `//Alice`).
|
|
15
|
+
*
|
|
16
|
+
* Secret material is held only in memory for signing. It is never printed,
|
|
17
|
+
* logged, written or included in an error message.
|
|
18
|
+
*/
|
|
19
|
+
import { readFile } from "node:fs/promises";
|
|
20
|
+
import os from "node:os";
|
|
21
|
+
import path from "node:path";
|
|
22
|
+
import { Keyring } from "@polkadot/keyring";
|
|
23
|
+
import { hexToU8a, isHex, u8aToHex } from "@polkadot/util";
|
|
24
|
+
import { cryptoWaitReady, decodeAddress, encodeAddress } from "@polkadot/util-crypto";
|
|
25
|
+
import { verifySignature } from "./btauth.js";
|
|
26
|
+
/** Bittensor's SS58 prefix (generic substrate, 42). */
|
|
27
|
+
export const SS58_PREFIX = 42;
|
|
28
|
+
class UnsupportedKeyTypeError extends Error {
|
|
29
|
+
}
|
|
30
|
+
/** True when value is a valid SS58 address (checksum included). */
|
|
31
|
+
export function isAddress(value) {
|
|
32
|
+
if (!value)
|
|
33
|
+
return false;
|
|
34
|
+
try {
|
|
35
|
+
decodeAddress(value);
|
|
36
|
+
return !isHex(value);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function normalizeAddress(value) {
|
|
43
|
+
return encodeAddress(decodeAddress(value), SS58_PREFIX);
|
|
44
|
+
}
|
|
45
|
+
function schemeOf(raw) {
|
|
46
|
+
const v = (raw ?? "sr25519").trim().toLowerCase();
|
|
47
|
+
if (v === "sr25519" || v === "ed25519")
|
|
48
|
+
return v;
|
|
49
|
+
throw new Error("--crypto must be sr25519 or ed25519 (hashed hotkeys cannot sign btauth/1 requests here)");
|
|
50
|
+
}
|
|
51
|
+
function signerOf(pair, scheme) {
|
|
52
|
+
const address = encodeAddress(pair.publicKey, SS58_PREFIX);
|
|
53
|
+
return { address, scheme, sign: (message) => pair.sign(message) };
|
|
54
|
+
}
|
|
55
|
+
function keyring(scheme) {
|
|
56
|
+
return new Keyring({ type: scheme, ss58Format: SS58_PREFIX });
|
|
57
|
+
}
|
|
58
|
+
function walletDefaults(o, env) {
|
|
59
|
+
const walletPath = o.walletPath || env.BT_WALLET_PATH || path.join(os.homedir(), ".bittensor", "wallets");
|
|
60
|
+
const wallet = o.wallet || env.BT_WALLET_NAME || "default";
|
|
61
|
+
const hotkey = o.hotkey || env.BT_WALLET_HOTKEY || "default";
|
|
62
|
+
return { walletPath: walletPath.replace(/^~(?=$|\/)/, os.homedir()), wallet, hotkey };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A btcli wallet or hotkey name: never a path on any OS. Separators of every
|
|
66
|
+
* platform (`/`, `\`), drive colons, NUL and a leading dot are refused, so a
|
|
67
|
+
* name cannot leave the wallet's hotkeys directory.
|
|
68
|
+
*/
|
|
69
|
+
export function isSafeKeyName(name) {
|
|
70
|
+
return name.length > 0 && name.length <= 255 && !/[/\\:\0]/.test(name) && !name.startsWith(".") && !name.includes(path.sep);
|
|
71
|
+
}
|
|
72
|
+
/** The btcli hotkey file the options name. */
|
|
73
|
+
export function hotkeyFilePath(o, env = process.env) {
|
|
74
|
+
if (o.hotkeyFile)
|
|
75
|
+
return o.hotkeyFile.replace(/^~(?=$|\/)/, os.homedir());
|
|
76
|
+
const d = walletDefaults(o, env);
|
|
77
|
+
if (!isSafeKeyName(d.wallet) || !isSafeKeyName(d.hotkey)) {
|
|
78
|
+
throw new Error("--wallet and --hotkey are btcli names, not paths; use --hotkey-file for a path");
|
|
79
|
+
}
|
|
80
|
+
return path.join(d.walletPath, d.wallet, "hotkeys", d.hotkey);
|
|
81
|
+
}
|
|
82
|
+
function hex32or64(value, bytes) {
|
|
83
|
+
if (typeof value !== "string" || !isHex(value))
|
|
84
|
+
return undefined;
|
|
85
|
+
const u = hexToU8a(value);
|
|
86
|
+
return bytes.includes(u.length) ? u : undefined;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* schnorrkel's canonical secret scalar (what sp_core writes as privateKey) to
|
|
90
|
+
* the ed25519-expanded form @polkadot/wasm-crypto signs with: the scalar
|
|
91
|
+
* times the cofactor 8, little-endian. The nonce half is unchanged.
|
|
92
|
+
*/
|
|
93
|
+
function sr25519CanonicalToExpanded(secret) {
|
|
94
|
+
const out = new Uint8Array(secret);
|
|
95
|
+
let carry = 0;
|
|
96
|
+
for (let i = 0; i < 32; i++) {
|
|
97
|
+
const v = (secret[i] << 3) | carry;
|
|
98
|
+
out[i] = v & 0xff;
|
|
99
|
+
carry = v >> 8;
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function probe(signer) {
|
|
104
|
+
const msg = new TextEncoder().encode("heyditto btauth/1 key self-check");
|
|
105
|
+
return verifySignature(signer.scheme, msg, signer.sign(msg), signer.address);
|
|
106
|
+
}
|
|
107
|
+
/** Parses an unencrypted btcli hotkey file. Errors never quote the file. */
|
|
108
|
+
export async function signerFromKeyfile(data, label) {
|
|
109
|
+
const text = data.toString("utf8").trimStart();
|
|
110
|
+
if (text.startsWith("$NACL") || text.startsWith("$ANSIBLE_VAULT") || text.startsWith("gAAAAA")) {
|
|
111
|
+
throw new Error(`${label} is encrypted. heyditto reads btcli's default unencrypted hotkey files only; set DITTO_HOTKEY_MNEMONIC for this run instead`);
|
|
112
|
+
}
|
|
113
|
+
let json;
|
|
114
|
+
try {
|
|
115
|
+
json = JSON.parse(text);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
throw new Error(`${label} is not a btcli hotkey file (expected JSON)`);
|
|
119
|
+
}
|
|
120
|
+
if (!json || typeof json !== "object")
|
|
121
|
+
throw new Error(`${label} is not a btcli hotkey file (expected JSON)`);
|
|
122
|
+
let scheme;
|
|
123
|
+
if (json.cryptoType === undefined || json.cryptoType === null || json.cryptoType === 1)
|
|
124
|
+
scheme = "sr25519";
|
|
125
|
+
else if (json.cryptoType === 0)
|
|
126
|
+
scheme = "ed25519";
|
|
127
|
+
else
|
|
128
|
+
throw new Error(`${label} uses an unsupported key type; btauth/1 here signs with sr25519 or ed25519 hotkeys`);
|
|
129
|
+
await cryptoWaitReady();
|
|
130
|
+
const ring = keyring(scheme);
|
|
131
|
+
const recorded = typeof json.ss58Address === "string" && isAddress(json.ss58Address) ? json.ss58Address : undefined;
|
|
132
|
+
const recordedPub = hex32or64(json.publicKey ?? json.accountId, [32]) ?? (recorded ? decodeAddress(recorded) : undefined);
|
|
133
|
+
let signer;
|
|
134
|
+
try {
|
|
135
|
+
if (typeof json.secretPhrase === "string" && json.secretPhrase.trim()) {
|
|
136
|
+
signer = signerOf(ring.addFromUri(json.secretPhrase.trim()), scheme);
|
|
137
|
+
}
|
|
138
|
+
else if (hex32or64(json.secretSeed, [32])) {
|
|
139
|
+
signer = signerOf(ring.addFromSeed(hex32or64(json.secretSeed, [32])), scheme);
|
|
140
|
+
}
|
|
141
|
+
else if (scheme === "ed25519" && hex32or64(json.privateKey, [32])) {
|
|
142
|
+
signer = signerOf(ring.addFromSeed(hex32or64(json.privateKey, [32])), scheme);
|
|
143
|
+
}
|
|
144
|
+
else if (scheme === "sr25519" && hex32or64(json.privateKey, [64]) && recordedPub) {
|
|
145
|
+
const raw = hex32or64(json.privateKey, [64]);
|
|
146
|
+
for (const secretKey of [raw, sr25519CanonicalToExpanded(raw)]) {
|
|
147
|
+
const candidate = signerOf(ring.addFromPair({ publicKey: recordedPub, secretKey }), scheme);
|
|
148
|
+
if (probe(candidate)) {
|
|
149
|
+
signer = candidate;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
throw new Error(`${label} holds a secret that could not be read as a ${scheme} hotkey`);
|
|
157
|
+
}
|
|
158
|
+
if (!signer)
|
|
159
|
+
throw new Error(`${label} has no usable secret (secretPhrase, secretSeed or privateKey); a public-only file cannot sign`);
|
|
160
|
+
if (recordedPub && u8aToHex(decodeAddress(signer.address)) !== u8aToHex(recordedPub)) {
|
|
161
|
+
throw new Error(`${label}: the secret does not match the address recorded in the file; refusing to sign with it`);
|
|
162
|
+
}
|
|
163
|
+
if (!probe(signer))
|
|
164
|
+
throw new Error(`${label}: the key failed its signing self-check`);
|
|
165
|
+
return { signer, recorded };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Resolves the hotkey. With `needSigner` false an SS58 `--hotkey`, or the
|
|
169
|
+
* address recorded in a hotkey file, is enough and no secret is parsed.
|
|
170
|
+
*/
|
|
171
|
+
export async function loadHotkey(o, needSigner, env = process.env) {
|
|
172
|
+
if (isAddress(o.hotkey) && (o.hotkeyFile || o.hotkeyUri)) {
|
|
173
|
+
throw new Error("--hotkey is an SS58 address and cannot be combined with --hotkey-file or --hotkey-uri; pass one key source");
|
|
174
|
+
}
|
|
175
|
+
if (isAddress(o.hotkey)) {
|
|
176
|
+
if (needSigner)
|
|
177
|
+
throw new Error("--hotkey is an SS58 address, which cannot sign; name a btcli hotkey (--wallet/--hotkey), --hotkey-file, DITTO_HOTKEY_MNEMONIC or DITTO_HOTKEY_SEED");
|
|
178
|
+
return { address: normalizeAddress(o.hotkey), scheme: schemeOf(o.crypto), source: "--hotkey address" };
|
|
179
|
+
}
|
|
180
|
+
const explicitWallet = Boolean(o.wallet || o.hotkey || o.walletPath || o.hotkeyFile);
|
|
181
|
+
const scheme = schemeOf(o.crypto);
|
|
182
|
+
const fromSecret = async (make, source) => {
|
|
183
|
+
await cryptoWaitReady();
|
|
184
|
+
let signer;
|
|
185
|
+
try {
|
|
186
|
+
signer = signerOf(make(keyring(scheme)), scheme);
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
throw new Error(`${source} is not a valid ${scheme} secret`);
|
|
190
|
+
}
|
|
191
|
+
return { address: signer.address, scheme, source, signer };
|
|
192
|
+
};
|
|
193
|
+
if (o.hotkeyUri)
|
|
194
|
+
return fromSecret((ring) => ring.addFromUri(o.hotkeyUri), "--hotkey-uri");
|
|
195
|
+
if (!explicitWallet) {
|
|
196
|
+
const mnemonic = env.DITTO_HOTKEY_MNEMONIC?.trim();
|
|
197
|
+
if (mnemonic)
|
|
198
|
+
return fromSecret((ring) => ring.addFromUri(mnemonic), "DITTO_HOTKEY_MNEMONIC");
|
|
199
|
+
const seed = env.DITTO_HOTKEY_SEED?.trim();
|
|
200
|
+
if (seed) {
|
|
201
|
+
const bytes = hex32or64(seed.startsWith("0x") ? seed : `0x${seed}`, [32]);
|
|
202
|
+
if (!bytes)
|
|
203
|
+
throw new Error("DITTO_HOTKEY_SEED must be a 32-byte hex seed (0x + 64 hex digits)");
|
|
204
|
+
return fromSecret((ring) => ring.addFromSeed(bytes), "DITTO_HOTKEY_SEED");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const file = hotkeyFilePath(o, env);
|
|
208
|
+
const d = walletDefaults(o, env);
|
|
209
|
+
const btcliName = o.hotkeyFile ? undefined : { wallet: d.wallet, hotkey: d.hotkey };
|
|
210
|
+
let data;
|
|
211
|
+
try {
|
|
212
|
+
data = await readFile(file);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
const code = error.code;
|
|
216
|
+
if (code === "ENOENT") {
|
|
217
|
+
throw new Error(`no btcli hotkey at ${file}. Create one with \`btcli wallet new-hotkey --wallet-name ${d.wallet} --hotkey ${d.hotkey}\`, pass --wallet/--hotkey, or set DITTO_HOTKEY_MNEMONIC`);
|
|
218
|
+
}
|
|
219
|
+
throw new Error(`could not read ${file} (${code ?? "error"})`);
|
|
220
|
+
}
|
|
221
|
+
if (!needSigner) {
|
|
222
|
+
try {
|
|
223
|
+
const json = JSON.parse(data.toString("utf8"));
|
|
224
|
+
if (typeof json.ss58Address === "string" && isAddress(json.ss58Address)) {
|
|
225
|
+
if (!(json.cryptoType === undefined || json.cryptoType === null || json.cryptoType === 0 || json.cryptoType === 1)) {
|
|
226
|
+
throw new UnsupportedKeyTypeError(`${file} uses an unsupported key type; btauth/1 here signs with sr25519 or ed25519 hotkeys`);
|
|
227
|
+
}
|
|
228
|
+
const scheme2 = json.cryptoType === 0 ? "ed25519" : "sr25519";
|
|
229
|
+
return { address: normalizeAddress(json.ss58Address), scheme: scheme2, source: file, btcliName };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
if (error instanceof UnsupportedKeyTypeError)
|
|
234
|
+
throw error;
|
|
235
|
+
/* otherwise fall through to the full parse for a precise error */
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const { signer } = await signerFromKeyfile(data, file);
|
|
239
|
+
return { address: signer.address, scheme: signer.scheme, source: file, btcliName, signer };
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=hotkey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkey.js","sourceRoot":"","sources":["../../src/gamma/hotkey.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,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