@toon-protocol/rig 2.0.1 → 2.2.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 +98 -13
- package/dist/{chunk-G4W4MH6G.js → chunk-JBB7HBQC.js} +120 -6
- package/dist/chunk-JBB7HBQC.js.map +1 -0
- package/dist/chunk-OIJNRACA.js +588 -0
- package/dist/chunk-OIJNRACA.js.map +1 -0
- package/dist/{chunk-LFGDLD6J.js → chunk-PS5QOT62.js} +464 -4
- package/dist/chunk-PS5QOT62.js.map +1 -0
- package/dist/chunk-SW7ZHMGS.js +358 -0
- package/dist/chunk-SW7ZHMGS.js.map +1 -0
- package/dist/cli/rig.js +2664 -410
- package/dist/cli/rig.js.map +1 -1
- package/dist/index.d.ts +271 -3
- package/dist/index.js +44 -8
- package/dist/{publisher-CClD9OIZ.d.ts → publisher-CrwaNQrK.d.ts} +10 -1
- package/dist/standalone/index.d.ts +410 -3
- package/dist/standalone/index.js +20 -6
- package/dist/standalone-mode-64CKUVU2.js +865 -0
- package/dist/standalone-mode-64CKUVU2.js.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-G4W4MH6G.js.map +0 -1
- package/dist/chunk-HPSOQP7Q.js +0 -109
- package/dist/chunk-HPSOQP7Q.js.map +0 -1
- package/dist/chunk-LFGDLD6J.js.map +0 -1
- package/dist/chunk-XRRU6YBQ.js +0 -402
- package/dist/chunk-XRRU6YBQ.js.map +0 -1
- package/dist/standalone-mode-Q3FFZUXE.js +0 -111
- package/dist/standalone-mode-Q3FFZUXE.js.map +0 -1
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fetchRemoteState
|
|
3
|
-
} from "./chunk-G4W4MH6G.js";
|
|
4
|
-
import {
|
|
5
|
-
resolveIdentity
|
|
6
|
-
} from "./chunk-CW4HJNMU.js";
|
|
7
|
-
import "./chunk-HPSOQP7Q.js";
|
|
8
|
-
import {
|
|
9
|
-
StandalonePublisher
|
|
10
|
-
} from "./chunk-XRRU6YBQ.js";
|
|
11
|
-
import "./chunk-X2CZPPDM.js";
|
|
12
|
-
|
|
13
|
-
// src/cli/standalone-mode.ts
|
|
14
|
-
import { readFileSync } from "fs";
|
|
15
|
-
import { homedir } from "os";
|
|
16
|
-
import { join } from "path";
|
|
17
|
-
import {
|
|
18
|
-
GenesisPeerLoader,
|
|
19
|
-
decodeEventFromToon,
|
|
20
|
-
encodeEventToToon
|
|
21
|
-
} from "@toon-protocol/core";
|
|
22
|
-
var MissingUplinkError = class extends Error {
|
|
23
|
-
constructor(configPath) {
|
|
24
|
-
super(
|
|
25
|
-
`no write uplink configured: set TOON_CLIENT_PROXY_URL (connector payment proxy) or TOON_CLIENT_BTP_URL, or add proxyUrl/btpUrl to ${configPath}`
|
|
26
|
-
);
|
|
27
|
-
this.name = "MissingUplinkError";
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
function configDir(env) {
|
|
31
|
-
return env["TOON_CLIENT_HOME"] ?? join(homedir(), ".toon-client");
|
|
32
|
-
}
|
|
33
|
-
function readClientConfig(path) {
|
|
34
|
-
try {
|
|
35
|
-
return JSON.parse(readFileSync(path, "utf8"));
|
|
36
|
-
} catch (err) {
|
|
37
|
-
if (err.code === "ENOENT") return {};
|
|
38
|
-
throw new Error(
|
|
39
|
-
`failed to read client config at ${path}: ${err instanceof Error ? err.message : String(err)}`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async function createStandaloneContext(options) {
|
|
44
|
-
const { env } = options;
|
|
45
|
-
const dir = configDir(env);
|
|
46
|
-
const configPath = join(dir, "config.json");
|
|
47
|
-
const file = readClientConfig(configPath);
|
|
48
|
-
const identity = await resolveIdentity(options);
|
|
49
|
-
const proxyUrl = env["TOON_CLIENT_PROXY_URL"] ?? file.proxyUrl;
|
|
50
|
-
const btpUrl = env["TOON_CLIENT_BTP_URL"] ?? file.btpUrl;
|
|
51
|
-
if (!proxyUrl && !btpUrl) throw new MissingUplinkError(configPath);
|
|
52
|
-
const genesisSeed = GenesisPeerLoader.loadGenesisPeers()[0];
|
|
53
|
-
const relayUrl = env["TOON_CLIENT_RELAY_URL"] ?? file.relayUrl ?? genesisSeed?.relayUrl ?? "ws://localhost:7100";
|
|
54
|
-
const destination = env["TOON_CLIENT_DESTINATION"] ?? file.destination ?? genesisSeed?.ilpAddress ?? "g.proxy";
|
|
55
|
-
const publishDestination = env["TOON_CLIENT_PUBLISH_DESTINATION"] ?? file.publishDestination;
|
|
56
|
-
const storeDestination = env["TOON_CLIENT_STORE_DESTINATION"] ?? file.storeDestination;
|
|
57
|
-
const network = env["TOON_CLIENT_NETWORK"] ?? file.network;
|
|
58
|
-
const channelStorePath = file.channelStorePath ?? join(dir, "channels.json");
|
|
59
|
-
const eventFee = BigInt(file.feePerEvent ?? "1");
|
|
60
|
-
const clientConfig = {
|
|
61
|
-
// validateConfig requires connectorUrl OR proxyUrl; with BTP-only config a
|
|
62
|
-
// dummy connectorUrl satisfies it (unused at runtime — same convention as
|
|
63
|
-
// the daemon).
|
|
64
|
-
...proxyUrl ? { proxyUrl } : { connectorUrl: "http://127.0.0.1:1" },
|
|
65
|
-
mnemonic: identity.mnemonic,
|
|
66
|
-
mnemonicAccountIndex: identity.accountIndex,
|
|
67
|
-
ilpInfo: {
|
|
68
|
-
pubkey: "00".repeat(32),
|
|
69
|
-
ilpAddress: "g.toon.client",
|
|
70
|
-
btpEndpoint: btpUrl ?? "",
|
|
71
|
-
assetCode: "USD",
|
|
72
|
-
assetScale: 6
|
|
73
|
-
},
|
|
74
|
-
toonEncoder: encodeEventToToon,
|
|
75
|
-
toonDecoder: decodeEventFromToon,
|
|
76
|
-
...btpUrl ? { btpUrl, btpAuthToken: "" } : {},
|
|
77
|
-
destinationAddress: destination,
|
|
78
|
-
relayUrl: "",
|
|
79
|
-
// remote state uses fetchRemoteState, not bootstrap discovery
|
|
80
|
-
knownPeers: [],
|
|
81
|
-
channelStorePath,
|
|
82
|
-
...network ? { network } : {},
|
|
83
|
-
...file.supportedChains ? { supportedChains: file.supportedChains } : {},
|
|
84
|
-
...file.settlementAddresses ? { settlementAddresses: file.settlementAddresses } : {},
|
|
85
|
-
...file.preferredTokens ? { preferredTokens: file.preferredTokens } : {},
|
|
86
|
-
...file.tokenNetworks ? { tokenNetworks: file.tokenNetworks } : {},
|
|
87
|
-
...file.chainRpcUrls ? { chainRpcUrls: file.chainRpcUrls } : {},
|
|
88
|
-
...file.solanaChannel ? { solanaChannel: file.solanaChannel } : {},
|
|
89
|
-
...file.minaChannel ? { minaChannel: file.minaChannel } : {}
|
|
90
|
-
};
|
|
91
|
-
const publisher = new StandalonePublisher({
|
|
92
|
-
clientConfig,
|
|
93
|
-
eventFee,
|
|
94
|
-
...publishDestination ? { publishDestination } : {},
|
|
95
|
-
...storeDestination ? { storeDestination } : {}
|
|
96
|
-
});
|
|
97
|
-
return {
|
|
98
|
-
ownerPubkey: publisher.getPublicKey(),
|
|
99
|
-
identitySource: identity.source,
|
|
100
|
-
identitySourceLabel: identity.sourceLabel,
|
|
101
|
-
publisher,
|
|
102
|
-
defaultRelayUrls: [relayUrl],
|
|
103
|
-
fetchRemote: (args) => fetchRemoteState(args),
|
|
104
|
-
stop: () => publisher.stop()
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export {
|
|
108
|
-
MissingUplinkError,
|
|
109
|
-
createStandaloneContext
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=standalone-mode-Q3FFZUXE.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cli/standalone-mode.ts"],"sourcesContent":["/**\n * The embedded-client (standalone) publisher backing every paid `rig`\n * command: build a nonce-guarded {@link StandalonePublisher} from the\n * caller's own identity and config.\n *\n * Identity comes from the #248 precedence chain (`./identity.ts`:\n * RIG_MNEMONIC env → TOON_CLIENT_MNEMONIC env alias → project `.env` →\n * `~/.toon-client` keystore/config). The remaining config resolution\n * DUPLICATES the toon-clientd conventions\n * (`packages/client-mcp/src/daemon/config.ts`) the same way\n * `../standalone/nonce-guard.ts` does — this package must not import\n * `@toon-protocol/client-mcp` (circular; see that module's doc). Keep in sync:\n *\n * - state dir: `TOON_CLIENT_HOME`, else `~/.toon-client`; config `config.json`\n * - env overrides: `TOON_CLIENT_PROXY_URL`, `TOON_CLIENT_BTP_URL`,\n * `TOON_CLIENT_RELAY_URL`, `TOON_CLIENT_DESTINATION`,\n * `TOON_CLIENT_PUBLISH_DESTINATION`, `TOON_CLIENT_STORE_DESTINATION`,\n * `TOON_CLIENT_NETWORK`\n * - defaults bootstrap from the committed genesis peer seed\n * (`@toon-protocol/core` GenesisPeerLoader)\n *\n * This module statically imports `@toon-protocol/client` (heavy: viem,\n * noble, nostr-tools), so it must only ever be reached through the dynamic\n * import in `push.ts` (see `./standalone-context.ts`).\n */\n\nimport { readFileSync } from 'node:fs';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\nimport type { ToonClientConfig } from '@toon-protocol/client';\nimport {\n GenesisPeerLoader,\n decodeEventFromToon,\n encodeEventToToon,\n} from '@toon-protocol/core';\nimport { StandalonePublisher } from '../standalone/standalone-publisher.js';\nimport { fetchRemoteState } from '../remote-state.js';\nimport { resolveIdentity } from './identity.js';\nimport type {\n StandaloneContext,\n StandaloneLoadOptions,\n} from './standalone-context.js';\n\n/** The subset of the shared client config file standalone mode consumes. */\ninterface ClientConfigFile {\n network?: 'mainnet' | 'testnet' | 'devnet' | 'custom';\n mnemonicAccountIndex?: number;\n btpUrl?: string;\n proxyUrl?: string;\n relayUrl?: string;\n destination?: string;\n publishDestination?: string;\n storeDestination?: string;\n feePerEvent?: string;\n channelStorePath?: string;\n supportedChains?: string[];\n settlementAddresses?: Record<string, string>;\n preferredTokens?: Record<string, string>;\n tokenNetworks?: Record<string, string>;\n chainRpcUrls?: Record<string, string>;\n solanaChannel?: ToonClientConfig['solanaChannel'];\n minaChannel?: ToonClientConfig['minaChannel'];\n}\n\n/** An identity was resolved, but there is no way to send paid writes. */\nexport class MissingUplinkError extends Error {\n constructor(configPath: string) {\n super(\n 'no write uplink configured: set TOON_CLIENT_PROXY_URL ' +\n '(connector payment proxy) or TOON_CLIENT_BTP_URL, or add ' +\n `proxyUrl/btpUrl to ${configPath}`\n );\n this.name = 'MissingUplinkError';\n }\n}\n\nfunction configDir(env: NodeJS.ProcessEnv): string {\n return env['TOON_CLIENT_HOME'] ?? join(homedir(), '.toon-client');\n}\n\nfunction readClientConfig(path: string): ClientConfigFile {\n try {\n return JSON.parse(readFileSync(path, 'utf8')) as ClientConfigFile;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return {};\n throw new Error(\n `failed to read client config at ${path}: ${err instanceof Error ? err.message : String(err)}`\n );\n }\n}\n\n/**\n * Assemble an embedded-client standalone context: resolved identity + config\n * → ToonClientConfig → nonce-guarded StandalonePublisher (guard + client\n * start + channel open happen lazily on the first paid call, or eagerly via\n * the publisher's own `start`).\n */\nexport async function createStandaloneContext(\n options: StandaloneLoadOptions\n): Promise<StandaloneContext> {\n const { env } = options;\n const dir = configDir(env);\n const configPath = join(dir, 'config.json');\n const file = readClientConfig(configPath);\n const identity = await resolveIdentity(options);\n\n const proxyUrl = env['TOON_CLIENT_PROXY_URL'] ?? file.proxyUrl;\n const btpUrl = env['TOON_CLIENT_BTP_URL'] ?? file.btpUrl;\n if (!proxyUrl && !btpUrl) throw new MissingUplinkError(configPath);\n\n const genesisSeed = GenesisPeerLoader.loadGenesisPeers()[0];\n const relayUrl =\n env['TOON_CLIENT_RELAY_URL'] ??\n file.relayUrl ??\n genesisSeed?.relayUrl ??\n 'ws://localhost:7100';\n const destination =\n env['TOON_CLIENT_DESTINATION'] ??\n file.destination ??\n genesisSeed?.ilpAddress ??\n 'g.proxy';\n const publishDestination =\n env['TOON_CLIENT_PUBLISH_DESTINATION'] ?? file.publishDestination;\n const storeDestination =\n env['TOON_CLIENT_STORE_DESTINATION'] ?? file.storeDestination;\n const network = (env['TOON_CLIENT_NETWORK'] ?? file.network) as\n | ToonClientConfig['network']\n | undefined;\n const channelStorePath = file.channelStorePath ?? join(dir, 'channels.json');\n const eventFee = BigInt(file.feePerEvent ?? '1');\n\n const clientConfig: ToonClientConfig = {\n // validateConfig requires connectorUrl OR proxyUrl; with BTP-only config a\n // dummy connectorUrl satisfies it (unused at runtime — same convention as\n // the daemon).\n ...(proxyUrl ? { proxyUrl } : { connectorUrl: 'http://127.0.0.1:1' }),\n mnemonic: identity.mnemonic,\n mnemonicAccountIndex: identity.accountIndex,\n ilpInfo: {\n pubkey: '00'.repeat(32),\n ilpAddress: 'g.toon.client',\n btpEndpoint: btpUrl ?? '',\n assetCode: 'USD',\n assetScale: 6,\n },\n toonEncoder: encodeEventToToon,\n toonDecoder: decodeEventFromToon,\n ...(btpUrl ? { btpUrl, btpAuthToken: '' } : {}),\n destinationAddress: destination,\n relayUrl: '', // remote state uses fetchRemoteState, not bootstrap discovery\n knownPeers: [],\n channelStorePath,\n ...(network ? { network } : {}),\n ...(file.supportedChains ? { supportedChains: file.supportedChains } : {}),\n ...(file.settlementAddresses\n ? { settlementAddresses: file.settlementAddresses }\n : {}),\n ...(file.preferredTokens ? { preferredTokens: file.preferredTokens } : {}),\n ...(file.tokenNetworks ? { tokenNetworks: file.tokenNetworks } : {}),\n ...(file.chainRpcUrls ? { chainRpcUrls: file.chainRpcUrls } : {}),\n ...(file.solanaChannel ? { solanaChannel: file.solanaChannel } : {}),\n ...(file.minaChannel ? { minaChannel: file.minaChannel } : {}),\n };\n\n const publisher = new StandalonePublisher({\n clientConfig,\n eventFee,\n ...(publishDestination ? { publishDestination } : {}),\n ...(storeDestination ? { storeDestination } : {}),\n });\n\n return {\n ownerPubkey: publisher.getPublicKey(),\n identitySource: identity.source,\n identitySourceLabel: identity.sourceLabel,\n publisher,\n defaultRelayUrls: [relayUrl],\n fetchRemote: (args) => fetchRemoteState(args),\n stop: () => publisher.stop(),\n };\n}\n"],"mappings":";;;;;;;;;;;;;A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