@singularity-layer/cli 0.2.2 → 0.4.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 CHANGED
@@ -7,8 +7,8 @@ npm i -g @singularity-layer/cli
7
7
  singularity --help
8
8
  ```
9
9
 
10
- Requires Node 20+ and a Solana keypair (`solana-keygen new`). No account, no API key, no dashboard
11
- login — your wallet *is* the account.
10
+ Requires Node 20+ and either a Solana keypair (`solana-keygen new`) or a compute API key. No
11
+ account and no dashboard login — your wallet *is* the account.
12
12
 
13
13
  ## Processors
14
14
 
@@ -152,11 +152,36 @@ singularity processors run '{"n":1}' --json
152
152
 
153
153
  ## Auth
154
154
 
155
- A per-request Solana wallet signature, using `~/.config/solana/id.json` by default (`--keypair
156
- <path>`, `SINGULARITY_KEYPAIR`, or `singularity processors configure` to change it). **The key never
157
- leaves your machine** — only a signature is sent, and it covers the method, the path and a hash of the
155
+ Two ways in. The CLI picks the API key when one is given, and the keypair otherwise.
156
+
157
+ **Wallet signature (default).** Uses `~/.config/solana/id.json` (`--keypair <path>`,
158
+ `SINGULARITY_KEYPAIR`, or `singularity processors configure` to change it). **The key never leaves
159
+ your machine** — only a signature is sent, and it covers the method, the path and a hash of the
158
160
  body, so it authorizes exactly one request and cannot be replayed against another.
159
161
 
162
+ **Compute API key.** `--api-key x402c_...`, or `SGL_API_KEY` in the environment. This is the option
163
+ for CI and for agents, where there is no keypair to hold.
164
+
165
+ ```bash
166
+ export SGL_API_KEY=x402c_...
167
+ singularity whoami # the wallet the key resolves to
168
+ singularity processors list
169
+ singularity processors deploy
170
+ ```
171
+
172
+ Mint the key in the dashboard with the `processors:write` scope, or `processors:read` if you only
173
+ need the read commands. Two things to know before you rely on it:
174
+
175
+ - **`processors:write` is full control** of that wallet's processors, delete and secrets included.
176
+ A bearer credential cannot be bound to one request the way a signature is, so scope is the only
177
+ control. Mint `processors:read` if you want something that cannot change anything.
178
+ - **`deploy` needs a key minted on a Solana wallet.** That address becomes your payout account, so
179
+ a key on an EVM wallet gets `400 solana_wallet_required`. It can still manage processors its
180
+ wallet already owns.
181
+
182
+ An API key never expires, and there is no audit log of what it did. Revoking it in the dashboard is
183
+ the only way to stop it.
184
+
160
185
  ## Programmatic use
161
186
 
162
187
  ```ts
package/dist/auth.d.ts CHANGED
@@ -42,9 +42,39 @@ export declare function bs58(bytes: Uint8Array): string;
42
42
  * the machine — only a signature is sent.
43
43
  */
44
44
  export declare function loadKeypair(flags?: Flags): Keypair;
45
+ /** Either credential the control plane accepts. Exactly one is ever set. */
46
+ export interface Creds {
47
+ kp?: Keypair;
48
+ apiKey?: string;
49
+ }
50
+ /**
51
+ * Resolve how this invocation authenticates.
52
+ *
53
+ * An API KEY WINS when one is given, because asking for it is explicit: `--api-key` on the command
54
+ * line, or SGL_API_KEY in the environment. Falling back to the keypair when a key is present would
55
+ * mean a CI job with SGL_API_KEY set silently signed with whatever keypair happened to be on the
56
+ * runner, which is the opposite of what was asked for.
57
+ *
58
+ * Otherwise it is the keypair, exactly as before, so nothing about the existing workflow changes.
59
+ */
60
+ /**
61
+ * Is there a credential to load at all? For commands that work unauthenticated on public data and
62
+ * should not die just because this machine has no keypair.
63
+ */
64
+ export declare function hasAnyCredential(flags?: Flags): boolean;
65
+ export declare function loadCreds(flags?: Flags): Creds;
45
66
  export interface ApiOpts {
46
67
  body?: unknown;
47
68
  kp?: Keypair;
69
+ /**
70
+ * Compute API key (`x402c_…`), sent as `X-API-Key`.
71
+ *
72
+ * MUTUALLY EXCLUSIVE WITH `kp` in practice: loadCreds returns one or the other, never both.
73
+ * The server accepts either, and presenting both would just mean the key decides, but keeping
74
+ * them exclusive at the source means there is never a question about which one authorised an
75
+ * action when reading a log.
76
+ */
77
+ apiKey?: string;
48
78
  bearer?: string;
49
79
  /**
50
80
  * Query parameters. An ARRAY value becomes REPEATED keys (`?tag=a&tag=b`), which is exactly what
@@ -88,7 +118,7 @@ export interface ApiOpts {
88
118
  *
89
119
  * Found by adversarial review after I had written exactly that. The rule is: match the route.
90
120
  */
91
- export declare function api<T = unknown>(base: string, method: NonNullable<ApiOpts['method']>, path: string, { body, kp, bearer, query, signQuery }?: ApiOpts): Promise<T>;
121
+ export declare function api<T = unknown>(base: string, method: NonNullable<ApiOpts['method']>, path: string, { body, kp, apiKey, bearer, query, signQuery }?: ApiOpts): Promise<T>;
92
122
  /**
93
123
  * Parse argv into subcommand path, positional args, and flags.
94
124
  *
package/dist/cli.d.ts CHANGED
@@ -11,6 +11,6 @@
11
11
  * • `sglcode` — the agentic coding CLI. A product in its own right, like Claude Code.
12
12
  * Demoting it to `singularity code` would misrepresent what it is.
13
13
  *
14
- * Auth is a per-request Solana wallet signature. The key never leaves the machine.
14
+ * Auth is a per-request Solana wallet signature, or a compute API key. The key never leaves the machine.
15
15
  */
16
16
  export {};
package/dist/cli.js CHANGED
@@ -36,9 +36,14 @@ function loadKeypair(flags = {}) {
36
36
  flags.keypair || process.env.SINGULARITY_KEYPAIR || process.env.SGLPROC_KEYPAIR || join(homedir(), ".config/solana/id.json")
37
37
  );
38
38
  if (!existsSync(path)) {
39
- die(`no keypair at ${path}
40
- pass --keypair <path>, set SINGULARITY_KEYPAIR, or create one:
41
- solana-keygen new`);
39
+ die(
40
+ `no credential found
41
+ no keypair at ${path}
42
+ pass --keypair <path>, or set SINGULARITY_KEYPAIR, or create one:
43
+ solana-keygen new
44
+ or authenticate with a compute API key instead:
45
+ --api-key x402c_... (also read from SGL_API_KEY)`
46
+ );
42
47
  }
43
48
  let raw;
44
49
  try {
@@ -54,11 +59,35 @@ function loadKeypair(flags = {}) {
54
59
  const pair = nacl.sign.keyPair.fromSecretKey(secret);
55
60
  return { secretKey: pair.secretKey, address: bs58(pair.publicKey) };
56
61
  }
62
+ function hasAnyCredential(flags = {}) {
63
+ if ("api-key" in flags) return true;
64
+ if ((process.env.SGL_API_KEY || process.env.SINGULARITY_API_KEY || "").trim()) return true;
65
+ const path = String(
66
+ flags.keypair || process.env.SINGULARITY_KEYPAIR || process.env.SGLPROC_KEYPAIR || join(homedir(), ".config/solana/id.json")
67
+ );
68
+ return existsSync(path);
69
+ }
70
+ function loadCreds(flags = {}) {
71
+ if ("api-key" in flags && typeof flags["api-key"] !== "string") {
72
+ die("--api-key needs a value:\n --api-key x402c_...\n or set SGL_API_KEY, which keeps it out of your shell history");
73
+ }
74
+ const equalsForm = Object.keys(flags).find((k) => k.startsWith("api-key="));
75
+ if (equalsForm) {
76
+ die(`--api-key=VALUE is not supported; use a space:
77
+ --api-key ${equalsForm.slice("api-key=".length) || "x402c_..."}`);
78
+ }
79
+ const flagKey = typeof flags["api-key"] === "string" ? String(flags["api-key"]).trim() : "";
80
+ if ("api-key" in flags && !flagKey) die("--api-key was given an empty value");
81
+ if (flagKey) return { apiKey: flagKey };
82
+ const envKey = (process.env.SGL_API_KEY || process.env.SINGULARITY_API_KEY || "").trim();
83
+ if (envKey) return { apiKey: envKey };
84
+ return { kp: loadKeypair(flags) };
85
+ }
57
86
  async function sha256Hex(input) {
58
87
  const d = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(input));
59
88
  return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, "0")).join("");
60
89
  }
61
- async function api(base, method, path, { body, kp, bearer, query, signQuery } = {}) {
90
+ async function api(base, method, path, { body, kp, apiKey, bearer, query, signQuery } = {}) {
62
91
  let qs = "";
63
92
  if (query) {
64
93
  const params = new URLSearchParams();
@@ -74,6 +103,8 @@ async function api(base, method, path, { body, kp, bearer, query, signQuery } =
74
103
  const headers = {};
75
104
  if (sentRaw) headers["content-type"] = "application/json";
76
105
  if (bearer) headers.Authorization = `Bearer ${bearer}`;
106
+ if (kp && apiKey) die("pass either a keypair or an apiKey to api(), never both");
107
+ if (apiKey) headers["X-API-Key"] = apiKey;
77
108
  if (kp) {
78
109
  const timestamp = String(Math.floor(Date.now() / 1e3));
79
110
  const nonce = [...nacl.randomBytes(12)].map((b) => b.toString(16).padStart(2, "0")).join("");
@@ -596,15 +627,15 @@ function toQuery(input) {
596
627
  }
597
628
  return out;
598
629
  }
599
- async function invokeAndWait(base, slug, input, kp, token, quiet, asGet = false) {
630
+ async function invokeAndWait(base, slug, input, creds, token, quiet, asGet = false) {
600
631
  let res = asGet ? await api(base, "GET", `/processors/${slug}/run`, {
601
632
  query: toQuery(input),
602
- kp,
633
+ ...creds.kp ? { kp: creds.kp } : {},
603
634
  bearer: token,
604
635
  signQuery: true
605
636
  }) : await api(base, "POST", `/processors/${slug}/run`, {
606
637
  body: { input },
607
- kp,
638
+ ...creds.kp ? { kp: creds.kp } : {},
608
639
  bearer: token
609
640
  });
610
641
  if (res.status !== "completed" && res.run_token && res.run_id) {
@@ -673,12 +704,12 @@ async function run(words, flags) {
673
704
  break;
674
705
  }
675
706
  case "deploy": {
676
- const kp = loadKeypair(flags);
707
+ const creds = loadCreds(flags);
677
708
  const manifest = loadManifest(flags);
678
709
  const source = await resolveSource(manifest, flags);
679
710
  const res = await api(BASE, "POST", "/processors", {
680
711
  body: { manifest: clean(manifest), ...source },
681
- kp
712
+ ...creds
682
713
  });
683
714
  writeState({ slug: res.slug, invoke_token: res.invoke_token });
684
715
  if (emit(flags, res)) break;
@@ -693,7 +724,7 @@ async function run(words, flags) {
693
724
  break;
694
725
  }
695
726
  case "update": {
696
- const kp = loadKeypair(flags);
727
+ const creds = loadCreds(flags);
697
728
  const manifest = loadManifest(flags);
698
729
  const slug = String(flags.slug || manifest.slug || die("no slug in processor.json"));
699
730
  const source = await resolveSource(manifest, flags);
@@ -701,7 +732,7 @@ async function run(words, flags) {
701
732
  BASE,
702
733
  "PATCH",
703
734
  `/processors/${slug}`,
704
- { body: { manifest: clean(manifest), ...source }, kp }
735
+ { body: { manifest: clean(manifest), ...source }, ...creds }
705
736
  );
706
737
  if (emit(flags, res)) break;
707
738
  ok(`updated ${slug} (config_rev ${res.config_rev})`);
@@ -714,7 +745,7 @@ async function run(words, flags) {
714
745
  const slug = requireSlug(flags);
715
746
  const token = String(flags.token || readState().invoke_token || "");
716
747
  if (!token) die(`no invoke token in ${STATE_FILE} \u2014 run \`singularity processors rotate\``);
717
- const kp = loadKeypair(flags);
748
+ const creds = loadCreds(flags);
718
749
  let input = {};
719
750
  const interactive = flags.interactive === true || sub === "call";
720
751
  if (words[1]) {
@@ -728,7 +759,7 @@ async function run(words, flags) {
728
759
  BASE,
729
760
  "GET",
730
761
  `/processors/${slug}`,
731
- { kp }
762
+ { ...creds }
732
763
  );
733
764
  input = await promptForSchema(d.manifest?.input_schema ?? d.input_schema);
734
765
  ok(`input: ${JSON.stringify(input)}`);
@@ -737,7 +768,7 @@ async function run(words, flags) {
737
768
  BASE,
738
769
  slug,
739
770
  input,
740
- kp,
771
+ creds,
741
772
  token,
742
773
  flags.json === true,
743
774
  flags.get === true
@@ -747,13 +778,9 @@ async function run(words, flags) {
747
778
  }
748
779
  case "schema": {
749
780
  const slug = words[1] || requireSlug(flags);
750
- let kp;
751
- try {
752
- kp = loadKeypair(flags);
753
- } catch {
754
- kp = void 0;
755
- }
756
- const d = await api(BASE, "GET", `/processors/${slug}`, kp ? { kp } : {});
781
+ let creds;
782
+ creds = hasAnyCredential(flags) ? loadCreds(flags) : void 0;
783
+ const d = await api(BASE, "GET", `/processors/${slug}`, creds ? { ...creds } : {});
757
784
  const input = d.manifest?.input_schema ?? d.input_schema;
758
785
  const output = d.manifest?.output_schema ?? d.output_schema;
759
786
  if (emit(flags, { slug, input_schema: input, output_schema: output })) break;
@@ -770,7 +797,7 @@ async function run(words, flags) {
770
797
  break;
771
798
  }
772
799
  case "secrets": {
773
- const kp = loadKeypair(flags);
800
+ const creds = loadCreds(flags);
774
801
  const slug = requireSlug(flags);
775
802
  const pairs = words.slice(1);
776
803
  if (!pairs.length) die("usage: singularity processors secrets KEY=value [KEY2=value2] (KEY= clears)");
@@ -785,7 +812,7 @@ async function run(words, flags) {
785
812
  BASE,
786
813
  "PUT",
787
814
  `/processors/${slug}/secrets`,
788
- { body: { values }, kp }
815
+ { body: { values }, ...creds }
789
816
  );
790
817
  if (emit(flags, res)) break;
791
818
  ok(`secrets set: ${res.secrets.join(", ") || "(none)"}`);
@@ -795,11 +822,11 @@ async function run(words, flags) {
795
822
  break;
796
823
  }
797
824
  case "env": {
798
- const kp = loadKeypair(flags);
825
+ const creds = loadCreds(flags);
799
826
  const slug = requireSlug(flags);
800
827
  const action = words[1] || "list";
801
828
  if (action === "list") {
802
- const d = await api(BASE, "GET", `/processors/${slug}`, { kp });
829
+ const d = await api(BASE, "GET", `/processors/${slug}`, { ...creds });
803
830
  const declared = d.manifest?.secrets ?? [];
804
831
  const set = new Set(d.secret_keys ?? []);
805
832
  const modes = d.secret_modes ?? {};
@@ -828,7 +855,7 @@ async function run(words, flags) {
828
855
  BASE,
829
856
  "PUT",
830
857
  `/processors/${slug}/secrets`,
831
- { body: { values: { [key]: null } }, kp }
858
+ { body: { values: { [key]: null } }, ...creds }
832
859
  );
833
860
  if (emit(flags, res)) break;
834
861
  ok(`cleared ${key}`);
@@ -839,8 +866,8 @@ async function run(words, flags) {
839
866
  break;
840
867
  }
841
868
  case "list": {
842
- const kp = loadKeypair(flags);
843
- const res = await api(BASE, "GET", "/processors", { kp });
869
+ const creds = loadCreds(flags);
870
+ const res = await api(BASE, "GET", "/processors", { ...creds });
844
871
  if (emit(flags, res)) break;
845
872
  if (!res.processors.length) {
846
873
  ok("no processors yet \u2014 singularity processors init");
@@ -880,18 +907,18 @@ async function run(words, flags) {
880
907
  break;
881
908
  }
882
909
  case "logs": {
883
- const kp = loadKeypair(flags);
910
+ const creds = loadCreds(flags);
884
911
  const slug = words[1] || requireSlug(flags);
885
912
  const limit = Number(flags.limit || 30);
886
913
  if (flags.follow === true) {
887
- await followLogs(BASE, slug, kp, limit);
914
+ await followLogs(BASE, slug, creds, limit);
888
915
  break;
889
916
  }
890
917
  const res = await api(
891
918
  BASE,
892
919
  "GET",
893
920
  `/processors/${slug}/runs`,
894
- { kp, query: { limit, ...typeof flags.logs === "string" ? { logs: flags.logs } : {} } }
921
+ { ...creds, query: { limit, ...typeof flags.logs === "string" ? { logs: flags.logs } : {} } }
895
922
  );
896
923
  if (emit(flags, res)) break;
897
924
  printRunsPage(res);
@@ -904,8 +931,8 @@ async function run(words, flags) {
904
931
  break;
905
932
  }
906
933
  case "revenue": {
907
- const kp = loadKeypair(flags);
908
- const res = await api(BASE, "GET", "/processors", { kp });
934
+ const creds = loadCreds(flags);
935
+ const res = await api(BASE, "GET", "/processors", { ...creds });
909
936
  let sales = 0n, salesCount = 0n, spent = 0n, held = 0n;
910
937
  for (const p of res.processors) {
911
938
  sales += BigInt(p.sales_micro ?? 0);
@@ -934,9 +961,9 @@ async function run(words, flags) {
934
961
  break;
935
962
  }
936
963
  case "earnings": {
937
- const kp = loadKeypair(flags);
964
+ const creds = loadCreds(flags);
938
965
  const slug = words[1] || requireSlug(flags);
939
- const res = await api(BASE, "GET", `/processors/${slug}/earnings`, { kp });
966
+ const res = await api(BASE, "GET", `/processors/${slug}/earnings`, { ...creds });
940
967
  if (emit(flags, res)) break;
941
968
  const byChain = res.sales.paid_to_by_chain;
942
969
  if (byChain && Object.keys(byChain).length > 1) {
@@ -961,14 +988,14 @@ async function run(words, flags) {
961
988
  }
962
989
  case "pause":
963
990
  case "resume": {
964
- const kp = loadKeypair(flags);
991
+ const creds = loadCreds(flags);
965
992
  const slug = requireSlug(flags);
966
993
  const paused = sub === "pause";
967
994
  const res = await api(
968
995
  BASE,
969
996
  "PUT",
970
997
  `/processors/${slug}/pause`,
971
- { body: { paused }, kp }
998
+ { body: { paused }, ...creds }
972
999
  );
973
1000
  if (emit(flags, res)) break;
974
1001
  ok(`${slug}: ${res.paused ? "paused" : "running"}`);
@@ -977,27 +1004,27 @@ async function run(words, flags) {
977
1004
  }
978
1005
  case "publish":
979
1006
  case "unpublish": {
980
- const kp = loadKeypair(flags);
1007
+ const creds = loadCreds(flags);
981
1008
  const slug = requireSlug(flags);
982
1009
  const listed = sub === "publish";
983
1010
  const res = await api(
984
1011
  BASE,
985
1012
  "PUT",
986
1013
  `/processors/${slug}/listing`,
987
- { body: { listed }, kp }
1014
+ { body: { listed }, ...creds }
988
1015
  );
989
1016
  if (emit(flags, res)) break;
990
1017
  ok(res.note || (listed ? "published" : "unpublished"));
991
1018
  break;
992
1019
  }
993
1020
  case "rotate": {
994
- const kp = loadKeypair(flags);
1021
+ const creds = loadCreds(flags);
995
1022
  const slug = requireSlug(flags);
996
1023
  const res = await api(
997
1024
  BASE,
998
1025
  "POST",
999
1026
  `/processors/${slug}/rotate-token`,
1000
- { kp }
1027
+ { ...creds }
1001
1028
  );
1002
1029
  writeState({ slug, invoke_token: res.invoke_token });
1003
1030
  if (emit(flags, res)) break;
@@ -1007,14 +1034,14 @@ async function run(words, flags) {
1007
1034
  break;
1008
1035
  }
1009
1036
  case "delete": {
1010
- const kp = loadKeypair(flags);
1037
+ const creds = loadCreds(flags);
1011
1038
  const slug = requireSlug(flags);
1012
1039
  if (!flags.yes) {
1013
1040
  die(`this cannot be undone and the slug "${slug}" can NEVER be reused.
1014
1041
  to stop traffic without losing the slug: singularity processors pause
1015
1042
  to really delete it, re-run with --yes`);
1016
1043
  }
1017
- await api(BASE, "DELETE", `/processors/${slug}`, { kp });
1044
+ await api(BASE, "DELETE", `/processors/${slug}`, { ...creds });
1018
1045
  ok(`deleted ${slug} (the slug stays reserved)`);
1019
1046
  break;
1020
1047
  }
@@ -1031,12 +1058,12 @@ function printRunsPage(res) {
1031
1058
  ok(`${when(r.created_at)} ${r.status.padEnd(16)} ${String(r.run_ms ?? "").padStart(6)}ms ${r.error ? r.error.slice(0, 60) : ""}`);
1032
1059
  }
1033
1060
  }
1034
- async function followLogs(base, slug, kp, limit) {
1061
+ async function followLogs(base, slug, creds, limit) {
1035
1062
  const seen = /* @__PURE__ */ new Set();
1036
1063
  let first = true;
1037
1064
  ok(`following ${slug} \u2014 ctrl-c to stop`);
1038
1065
  for (; ; ) {
1039
- const res = await api(base, "GET", `/processors/${slug}/runs`, { kp, query: { limit } });
1066
+ const res = await api(base, "GET", `/processors/${slug}/runs`, { ...creds, query: { limit } });
1040
1067
  for (const r of [...res.runs].reverse()) {
1041
1068
  const key = r.id ?? `${r.created_at}:${r.status}:${r.run_ms}`;
1042
1069
  if (seen.has(key)) continue;
@@ -1055,7 +1082,7 @@ async function followLogs(base, slug, kp, limit) {
1055
1082
  }
1056
1083
 
1057
1084
  // src/version.ts
1058
- var VERSION = "0.2.2";
1085
+ var VERSION = "0.4.0";
1059
1086
 
1060
1087
  // src/cli.ts
1061
1088
  var COMMANDS = {
@@ -1067,10 +1094,20 @@ usage: singularity <command> [subcommand] [options]
1067
1094
 
1068
1095
  commands:
1069
1096
  ${Object.entries(COMMANDS).map(([k, v]) => ` ${k.padEnd(14)} ${v.blurb}`).join("\n")}
1070
- whoami print the wallet address your keypair resolves to
1097
+ whoami print the wallet address this credential resolves to
1071
1098
 
1072
1099
  singularity <command> show that command's subcommands
1073
1100
  --keypair <path> defaults to ~/.config/solana/id.json
1101
+ SGL_API_KEY=x402c_... authenticate with a compute API key instead of a keypair.
1102
+ Prefer the env var: --api-key <key> works too, but argv is
1103
+ visible in ps and your shell history. Needs processors:write
1104
+ (processors:read for read-only commands). A key from a Solana
1105
+ wallet deploys as that wallet. A key from a Google/GitHub/X login
1106
+ (an ACCOUNT key) deploys processors owned by the account: the
1107
+ manifest must set "payout": { "solana": "<a Solana wallet linked to
1108
+ your account>" }, and that payout cannot be changed afterwards.
1109
+ Account keys cannot change a linked wallet's processors (that
1110
+ needs the wallet). 'run' uses the invoke-token lane.
1074
1111
  --json machine-readable output, for scripts and agents
1075
1112
 
1076
1113
  Other Singularity CLIs, deliberately separate:
@@ -1088,8 +1125,17 @@ async function main() {
1088
1125
  process.exit(cmd && cmd !== "help" ? 1 : 0);
1089
1126
  }
1090
1127
  if (cmd === "whoami") {
1091
- const kp = loadKeypair(flags);
1092
- ok(flags.json ? JSON.stringify({ address: kp.address, chain: "solana" }) : kp.address);
1128
+ const creds = loadCreds(flags);
1129
+ if (creds.apiKey) {
1130
+ const res = await api(resolveBase(flags), "GET", "/processors", { ...creds });
1131
+ const owner = res.owner || "";
1132
+ if (!owner) die("the API key is valid but returned no owner wallet");
1133
+ const chain = owner.startsWith("acct:") ? "account" : owner.startsWith("0x") ? "evm" : "solana";
1134
+ ok(flags.json ? JSON.stringify({ address: owner, chain, via: "api-key" }) : owner);
1135
+ return;
1136
+ }
1137
+ const kp = creds.kp;
1138
+ ok(flags.json ? JSON.stringify({ address: kp.address, chain: "solana", via: "keypair" }) : kp.address);
1093
1139
  return;
1094
1140
  }
1095
1141
  const entry = COMMANDS[cmd];
package/dist/index.js CHANGED
@@ -33,9 +33,14 @@ function loadKeypair(flags = {}) {
33
33
  flags.keypair || process.env.SINGULARITY_KEYPAIR || process.env.SGLPROC_KEYPAIR || join(homedir(), ".config/solana/id.json")
34
34
  );
35
35
  if (!existsSync(path)) {
36
- die(`no keypair at ${path}
37
- pass --keypair <path>, set SINGULARITY_KEYPAIR, or create one:
38
- solana-keygen new`);
36
+ die(
37
+ `no credential found
38
+ no keypair at ${path}
39
+ pass --keypair <path>, or set SINGULARITY_KEYPAIR, or create one:
40
+ solana-keygen new
41
+ or authenticate with a compute API key instead:
42
+ --api-key x402c_... (also read from SGL_API_KEY)`
43
+ );
39
44
  }
40
45
  let raw;
41
46
  try {
@@ -55,7 +60,7 @@ async function sha256Hex(input) {
55
60
  const d = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(input));
56
61
  return [...new Uint8Array(d)].map((b) => b.toString(16).padStart(2, "0")).join("");
57
62
  }
58
- async function api(base, method, path, { body, kp, bearer, query, signQuery } = {}) {
63
+ async function api(base, method, path, { body, kp, apiKey, bearer, query, signQuery } = {}) {
59
64
  let qs = "";
60
65
  if (query) {
61
66
  const params = new URLSearchParams();
@@ -71,6 +76,8 @@ async function api(base, method, path, { body, kp, bearer, query, signQuery } =
71
76
  const headers = {};
72
77
  if (sentRaw) headers["content-type"] = "application/json";
73
78
  if (bearer) headers.Authorization = `Bearer ${bearer}`;
79
+ if (kp && apiKey) die("pass either a keypair or an apiKey to api(), never both");
80
+ if (apiKey) headers["X-API-Key"] = apiKey;
74
81
  if (kp) {
75
82
  const timestamp = String(Math.floor(Date.now() / 1e3));
76
83
  const nonce = [...nacl.randomBytes(12)].map((b) => b.toString(16).padStart(2, "0")).join("");
@@ -294,7 +301,7 @@ function coerce(raw, type) {
294
301
  }
295
302
 
296
303
  // src/version.ts
297
- var VERSION = "0.2.2";
304
+ var VERSION = "0.4.0";
298
305
  export {
299
306
  MAX_BUNDLE_BYTES,
300
307
  VERSION,
@@ -6,6 +6,7 @@
6
6
  * reduced one — and an agent can drive it identically.
7
7
  */
8
8
  import { type Flags } from './auth.js';
9
+ export declare function resolveBase(flags: Flags): string;
9
10
  export declare const HELP = "singularity processors \u2014 deploy loops we host and run\n\n init [slug] scaffold processor.json + processor.js here\n configure interactive setup: keypair, defaults\n deploy create it (prints the invoke token ONCE)\n update push new code or manifest\n run '{\"n\":10}' invoke and print the output\n run --get '{\"n\":10}' invoke over GET (for methods: [\"GET\"] processors)\n call -i invoke interactively, prompted per input field\n schema [slug] the input/output schema buyers and agents see\n list your processors\n search [query] the public catalogue\n logs [slug] recent runs and failure rate\n logs --follow stream new runs as they happen\n revenue sales and compute spend across everything you own\n earnings [slug] the same, for one processor\n env list | unset KEY which secrets are set; clear one\n secrets KEY=value ... set secret values (KEY= also clears)\n pause | resume stop or restart traffic, keeping the slug\n publish | unpublish list or unlist publicly (instant, no review)\n rotate new invoke token, the old one stops working\n delete --yes soft delete (the slug is never reusable)\n\n --keypair <path> defaults to ~/.config/solana/id.json\n --slug <slug> when not run from a processor directory\n --json machine-readable output, for scripts and agents\n --bundle bundle with esbuild: imports and npm packages\n --entry <file> bundle entry (default: the manifest's $code)\n\nGetting paid. Buyers pay YOU directly \u2014 we never hold the money and take no cut. By default that\nis USDC on Solana at your signing wallet. To be paid on more than one chain, add a \"payout\" block\nto processor.json:\n\n \"payout\": {\n \"solana\": \"<base58 wallet>\", USDC\n \"base\": \"0x\u2026\", USDC\n \"robinhood\": \"0x\u2026\" USDG on Robinhood Chain\n }\n\nOne price_usd covers all three (every asset is 6-decimal), and buyers pick a chain from the 402.\nName only the chains you want: a chain you leave out is never offered. Check each address twice \u2014\na payment cannot be reversed.";
10
11
  /**
11
12
  * The chains a buyer can pay on. USDC on Solana and Base, USDG on Robinhood Chain — all three are
package/dist/version.d.ts CHANGED
@@ -8,4 +8,4 @@
8
8
  *
9
9
  * Kept in sync with package.json by the release workflow, which is the only thing that bumps either.
10
10
  */
11
- export declare const VERSION = "0.2.2";
11
+ export declare const VERSION = "0.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularity-layer/cli",
3
- "version": "0.2.2",
3
+ "version": "0.4.0",
4
4
  "description": "Singularity developer CLI \u2014 deploy paid endpoints (Processors) on the Singularity Cloud Network",
5
5
  "type": "module",
6
6
  "bin": {