@ozyman42/ozy-cli 0.4.6 → 0.4.7-darwin-x64.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.
Files changed (207) hide show
  1. package/multi-call-binary +0 -0
  2. package/package.json +11 -52
  3. package/bin/ozy +0 -191
  4. package/bin/ozy-signing-agent +0 -191
  5. package/bin/ozy-ssh-keygen +0 -191
  6. package/bin/ozy-virtual-security-key +0 -191
  7. package/dist/commands/git/hosts.js +0 -18
  8. package/dist/commands/git/hosts.js.map +0 -1
  9. package/dist/commands/git/index.js +0 -8
  10. package/dist/commands/git/index.js.map +0 -1
  11. package/dist/commands/git/setup.js +0 -145
  12. package/dist/commands/git/setup.js.map +0 -1
  13. package/dist/commands/index.js +0 -13
  14. package/dist/commands/index.js.map +0 -1
  15. package/dist/commands/npm/index.js +0 -7
  16. package/dist/commands/npm/index.js.map +0 -1
  17. package/dist/commands/npm/setup/git-remote.js +0 -66
  18. package/dist/commands/npm/setup/git-remote.js.map +0 -1
  19. package/dist/commands/npm/setup/index.js +0 -168
  20. package/dist/commands/npm/setup/index.js.map +0 -1
  21. package/dist/commands/npm/setup/npm-auth.js +0 -62
  22. package/dist/commands/npm/setup/npm-auth.js.map +0 -1
  23. package/dist/commands/npm/setup/package-json-validate.js +0 -47
  24. package/dist/commands/npm/setup/package-json-validate.js.map +0 -1
  25. package/dist/commands/npm/setup/package-registry.js +0 -20
  26. package/dist/commands/npm/setup/package-registry.js.map +0 -1
  27. package/dist/commands/npm/setup/setup.test.js +0 -95
  28. package/dist/commands/npm/setup/setup.test.js.map +0 -1
  29. package/dist/commands/npm/setup/trusted-publishing.js +0 -84
  30. package/dist/commands/npm/setup/trusted-publishing.js.map +0 -1
  31. package/dist/commands/npm/setup/workflow.js +0 -19
  32. package/dist/commands/npm/setup/workflow.js.map +0 -1
  33. package/dist/commands/ssh/get-sk-credential.js +0 -104
  34. package/dist/commands/ssh/get-sk-credential.js.map +0 -1
  35. package/dist/commands/ssh/index.js +0 -7
  36. package/dist/commands/ssh/index.js.map +0 -1
  37. package/dist/commands/upgrade.js +0 -81
  38. package/dist/commands/upgrade.js.map +0 -1
  39. package/dist/common/command.js +0 -15
  40. package/dist/common/command.js.map +0 -1
  41. package/dist/common/constants.js +0 -25
  42. package/dist/common/constants.js.map +0 -1
  43. package/dist/common/effective-modules-extensions.js +0 -13
  44. package/dist/common/effective-modules-extensions.js.map +0 -1
  45. package/dist/common/log.js +0 -4
  46. package/dist/common/log.js.map +0 -1
  47. package/dist/common/render-caller-tree.js +0 -20
  48. package/dist/common/render-caller-tree.js.map +0 -1
  49. package/dist/entrypoints/ozy-signing-agent.js +0 -48
  50. package/dist/entrypoints/ozy-signing-agent.js.map +0 -1
  51. package/dist/entrypoints/ozy-ssh-keygen.js +0 -9
  52. package/dist/entrypoints/ozy-ssh-keygen.js.map +0 -1
  53. package/dist/entrypoints/ozy-virtual-security-key.js +0 -18
  54. package/dist/entrypoints/ozy-virtual-security-key.js.map +0 -1
  55. package/dist/entrypoints/ozy.js +0 -3
  56. package/dist/entrypoints/ozy.js.map +0 -1
  57. package/dist/index.js +0 -2
  58. package/dist/index.js.map +0 -1
  59. package/dist/internal/thing.js +0 -4
  60. package/dist/internal/thing.js.map +0 -1
  61. package/dist/modules/cli/agent-client/impl.js +0 -109
  62. package/dist/modules/cli/agent-client/impl.js.map +0 -1
  63. package/dist/modules/cli/agent-client/interface.js +0 -11
  64. package/dist/modules/cli/agent-client/interface.js.map +0 -1
  65. package/dist/modules/cli/git/impl.js +0 -124
  66. package/dist/modules/cli/git/impl.js.map +0 -1
  67. package/dist/modules/cli/git/interface.js +0 -3
  68. package/dist/modules/cli/git/interface.js.map +0 -1
  69. package/dist/modules/cli/git/submodule/fix.js +0 -257
  70. package/dist/modules/cli/git/submodule/fix.js.map +0 -1
  71. package/dist/modules/cli/git/submodule/git-state.js +0 -154
  72. package/dist/modules/cli/git/submodule/git-state.js.map +0 -1
  73. package/dist/modules/cli/git/submodule/gitmodules.js +0 -113
  74. package/dist/modules/cli/git/submodule/gitmodules.js.map +0 -1
  75. package/dist/modules/cli/git/submodule/printer.js +0 -232
  76. package/dist/modules/cli/git/submodule/printer.js.map +0 -1
  77. package/dist/modules/cli/git/submodule/resolve-git-dir.js +0 -16
  78. package/dist/modules/cli/git/submodule/resolve-git-dir.js.map +0 -1
  79. package/dist/modules/cli/github/impl.js +0 -137
  80. package/dist/modules/cli/github/impl.js.map +0 -1
  81. package/dist/modules/cli/github/interface.js +0 -2
  82. package/dist/modules/cli/github/interface.js.map +0 -1
  83. package/dist/modules/cli/index.js +0 -9
  84. package/dist/modules/cli/index.js.map +0 -1
  85. package/dist/modules/common/crypto/impl.js +0 -133
  86. package/dist/modules/common/crypto/impl.js.map +0 -1
  87. package/dist/modules/common/crypto/interface.js +0 -2
  88. package/dist/modules/common/crypto/interface.js.map +0 -1
  89. package/dist/modules/common/index.js +0 -10
  90. package/dist/modules/common/index.js.map +0 -1
  91. package/dist/modules/common/kep-map-store/impl.js +0 -42
  92. package/dist/modules/common/kep-map-store/impl.js.map +0 -1
  93. package/dist/modules/common/kep-map-store/interface.js +0 -2
  94. package/dist/modules/common/kep-map-store/interface.js.map +0 -1
  95. package/dist/modules/common/os-platform/caller-info.js +0 -132
  96. package/dist/modules/common/os-platform/caller-info.js.map +0 -1
  97. package/dist/modules/common/os-platform/impl.js +0 -87
  98. package/dist/modules/common/os-platform/impl.js.map +0 -1
  99. package/dist/modules/common/os-platform/interface.js +0 -2
  100. package/dist/modules/common/os-platform/interface.js.map +0 -1
  101. package/dist/modules/common/os-platform/virtual-hid/index.js +0 -12
  102. package/dist/modules/common/os-platform/virtual-hid/index.js.map +0 -1
  103. package/dist/modules/common/os-platform/virtual-hid/linux.js +0 -5
  104. package/dist/modules/common/os-platform/virtual-hid/linux.js.map +0 -1
  105. package/dist/modules/common/os-platform/virtual-hid/mac.js +0 -119
  106. package/dist/modules/common/os-platform/virtual-hid/mac.js.map +0 -1
  107. package/dist/modules/common/os-platform/virtual-hid/windows.js +0 -5
  108. package/dist/modules/common/os-platform/virtual-hid/windows.js.map +0 -1
  109. package/dist/modules/common/ssh-config/impl.js +0 -116
  110. package/dist/modules/common/ssh-config/impl.js.map +0 -1
  111. package/dist/modules/common/ssh-config/interface.js +0 -10
  112. package/dist/modules/common/ssh-config/interface.js.map +0 -1
  113. package/dist/modules/ssh-agent/index.js +0 -8
  114. package/dist/modules/ssh-agent/index.js.map +0 -1
  115. package/dist/modules/ssh-agent/session/impl.js +0 -265
  116. package/dist/modules/ssh-agent/session/impl.js.map +0 -1
  117. package/dist/modules/ssh-agent/session/interface-rpc.js +0 -20
  118. package/dist/modules/ssh-agent/session/interface-rpc.js.map +0 -1
  119. package/dist/modules/ssh-agent/session/interface.js +0 -32
  120. package/dist/modules/ssh-agent/session/interface.js.map +0 -1
  121. package/dist/modules/ssh-agent/session/passkey-prf-page.js +0 -204
  122. package/dist/modules/ssh-agent/session/passkey-prf-page.js.map +0 -1
  123. package/dist/modules/ssh-agent/session/prf-flow.js +0 -103
  124. package/dist/modules/ssh-agent/session/prf-flow.js.map +0 -1
  125. package/dist/modules/ssh-agent/ssh-agent/impl.js +0 -117
  126. package/dist/modules/ssh-agent/ssh-agent/impl.js.map +0 -1
  127. package/dist/modules/ssh-agent/ssh-agent/interface.js +0 -2
  128. package/dist/modules/ssh-agent/ssh-agent/interface.js.map +0 -1
  129. package/dist/scripts/build.js +0 -412
  130. package/dist/scripts/build.js.map +0 -1
  131. package/dist/scripts/check-npm-version.js +0 -8
  132. package/dist/scripts/check-npm-version.js.map +0 -1
  133. package/dist/scripts/kill-existing-agent.js +0 -21
  134. package/dist/scripts/kill-existing-agent.js.map +0 -1
  135. package/dist/scripts/publish.js +0 -46
  136. package/dist/scripts/publish.js.map +0 -1
  137. package/src/commands/git/hosts.ts +0 -20
  138. package/src/commands/git/index.ts +0 -9
  139. package/src/commands/git/setup.ts +0 -182
  140. package/src/commands/index.ts +0 -15
  141. package/src/commands/npm/index.ts +0 -8
  142. package/src/commands/npm/setup/git-remote.ts +0 -78
  143. package/src/commands/npm/setup/index.ts +0 -189
  144. package/src/commands/npm/setup/npm-auth.ts +0 -58
  145. package/src/commands/npm/setup/package-json-validate.ts +0 -68
  146. package/src/commands/npm/setup/package-registry.ts +0 -24
  147. package/src/commands/npm/setup/publish-workflow.yml +0 -35
  148. package/src/commands/npm/setup/setup.test.ts +0 -117
  149. package/src/commands/npm/setup/trusted-publishing.ts +0 -106
  150. package/src/commands/npm/setup/workflow.ts +0 -20
  151. package/src/commands/ssh/get-sk-credential.ts +0 -110
  152. package/src/commands/ssh/index.ts +0 -8
  153. package/src/commands/upgrade.ts +0 -90
  154. package/src/common/command.ts +0 -16
  155. package/src/common/constants.ts +0 -26
  156. package/src/common/effective-modules-extensions.ts +0 -24
  157. package/src/common/log.ts +0 -3
  158. package/src/common/render-caller-tree.ts +0 -22
  159. package/src/entrypoints/ozy-signing-agent.ts +0 -48
  160. package/src/entrypoints/ozy-ssh-keygen.ts +0 -10
  161. package/src/entrypoints/ozy-virtual-security-key.ts +0 -21
  162. package/src/entrypoints/ozy.ts +0 -2
  163. package/src/index.ts +0 -1
  164. package/src/internal/thing.ts +0 -3
  165. package/src/modules/cli/agent-client/impl.ts +0 -152
  166. package/src/modules/cli/agent-client/interface.ts +0 -17
  167. package/src/modules/cli/git/impl.ts +0 -133
  168. package/src/modules/cli/git/interface.ts +0 -23
  169. package/src/modules/cli/git/submodule/fix.ts +0 -298
  170. package/src/modules/cli/git/submodule/git-state.ts +0 -217
  171. package/src/modules/cli/git/submodule/gitmodules.ts +0 -126
  172. package/src/modules/cli/git/submodule/printer.ts +0 -256
  173. package/src/modules/cli/git/submodule/resolve-git-dir.ts +0 -14
  174. package/src/modules/cli/github/impl.ts +0 -169
  175. package/src/modules/cli/github/interface.ts +0 -29
  176. package/src/modules/cli/index.ts +0 -16
  177. package/src/modules/common/crypto/impl.ts +0 -173
  178. package/src/modules/common/crypto/interface.ts +0 -20
  179. package/src/modules/common/index.ts +0 -19
  180. package/src/modules/common/kep-map-store/impl.ts +0 -47
  181. package/src/modules/common/kep-map-store/interface.ts +0 -9
  182. package/src/modules/common/os-platform/caller-info.ts +0 -152
  183. package/src/modules/common/os-platform/impl.ts +0 -86
  184. package/src/modules/common/os-platform/interface.ts +0 -16
  185. package/src/modules/common/os-platform/virtual-hid/index.ts +0 -12
  186. package/src/modules/common/os-platform/virtual-hid/linux.ts +0 -7
  187. package/src/modules/common/os-platform/virtual-hid/mac.ts +0 -150
  188. package/src/modules/common/os-platform/virtual-hid/windows.ts +0 -7
  189. package/src/modules/common/ssh-config/impl.ts +0 -130
  190. package/src/modules/common/ssh-config/interface.ts +0 -33
  191. package/src/modules/ssh-agent/index.ts +0 -13
  192. package/src/modules/ssh-agent/session/agent-notes.md +0 -210
  193. package/src/modules/ssh-agent/session/design.md +0 -2
  194. package/src/modules/ssh-agent/session/html-refactor.md +0 -23
  195. package/src/modules/ssh-agent/session/impl.ts +0 -328
  196. package/src/modules/ssh-agent/session/interface-rpc.ts +0 -24
  197. package/src/modules/ssh-agent/session/interface.ts +0 -62
  198. package/src/modules/ssh-agent/session/passkey-prf-page.ts +0 -224
  199. package/src/modules/ssh-agent/session/prf-flow.ts +0 -152
  200. package/src/modules/ssh-agent/ssh-agent/impl.ts +0 -136
  201. package/src/modules/ssh-agent/ssh-agent/interface.ts +0 -9
  202. package/src/scripts/build.ts +0 -506
  203. package/src/scripts/check-npm-version.ts +0 -7
  204. package/src/scripts/command-launcher.js.ejs +0 -168
  205. package/src/scripts/kill-existing-agent.ts +0 -22
  206. package/src/scripts/publish.ts +0 -47
  207. package/src/scripts/windows-bin-shims.md +0 -1104
@@ -1,86 +0,0 @@
1
- import { Effect } from "effect";
2
- import { writeFileSync, existsSync, unlinkSync } from "node:fs";
3
- import * as net from "node:net";
4
- import { effunct, implementing, type EffectGen } from "effective-modules";
5
- import type { IOSPlatform, CallerProcess } from "./interface";
6
- import { resolveCallerChainUnix, resolveCallerChainWindows } from "./caller-info";
7
- import { commonModules } from "@/modules/common";
8
- import { registerVirtualHID } from "./virtual-hid";
9
- import { log } from "@/common/log";
10
-
11
- const openCmd = process.platform === 'darwin' ? 'open'
12
- : process.platform === 'linux' ? 'xdg-open'
13
- : 'start';
14
-
15
- const isWindows = process.platform === 'win32';
16
-
17
- function openBrowserWindow(url: string): Effect.Effect<void, never> {
18
- return Effect.sync(() => { Bun.spawnSync([openCmd, url]); });
19
- }
20
-
21
- function writeRestrictedFile(path: string, content: string): Effect.Effect<void, string> {
22
- return Effect.try({
23
- try: () => {
24
- if (isWindows) {
25
- writeFileSync(path, content);
26
- const result = Bun.spawnSync(['icacls', path, '/inheritance:r', '/grant:r', `${process.env['USERNAME']}:(R,W)`]);
27
- if (result.exitCode !== 0)
28
- throw new Error(`icacls failed with exit code ${result.exitCode}`);
29
- } else {
30
- writeFileSync(path, content, { mode: 0o600 });
31
- }
32
- },
33
- catch: (e) => `Failed to write restricted file ${path}: ${e instanceof Error ? e.message : String(e)}`,
34
- });
35
- }
36
-
37
- function makeConnectionHandler(onData: (data: Buffer, callerChain: CallerProcess[]) => EffectGen<Buffer>, resolveChain: (socket: net.Socket) => CallerProcess[]) {
38
- return (socket: net.Socket) => {
39
- let callerChain: CallerProcess[];
40
- try {
41
- callerChain = resolveChain(socket);
42
- } catch (e) {
43
- log(`[socket-server] ERROR: Failed to get caller info — closing connection. Reason: ${e instanceof Error ? e.message : String(e)}`);
44
- socket.destroy();
45
- return;
46
- }
47
- socket.on('data', async (data) => {
48
- try {
49
- socket.write(await Effect.runPromise(effunct(onData)(data, callerChain)));
50
- } catch (e) {
51
- log(`[socket-server] ERROR in onData: ${e instanceof Error ? e.message : String(e)}`);
52
- socket.destroy();
53
- }
54
- });
55
- };
56
- }
57
-
58
- export class OSPlatformImpl extends implementing(commonModules.OSPlatform) implements IOSPlatform {
59
- openBrowserWindow(url: string) { return openBrowserWindow(url); }
60
- writeRestrictedFile(path: string, content: string) { return writeRestrictedFile(path, content); }
61
- *startSocketServer(socketPath: string, onData: (data: Buffer, callerChain: CallerProcess[]) => EffectGen<Buffer>): EffectGen<void, string> {
62
- return yield* Effect.try({
63
- try: () => {
64
- if (existsSync(socketPath)) unlinkSync(socketPath);
65
- if (isWindows) {
66
- const pipePath = `\\\\.\\pipe\\${socketPath.replace(/[/\\:]/g, '-')}`;
67
- const server = net.createServer(makeConnectionHandler(onData, (socket) => {
68
- const remotePid = (socket as any)._handle?.remotePid as number | undefined;
69
- if (remotePid == null) throw new Error('socket._handle.remotePid unavailable on this Windows/Bun version');
70
- return resolveCallerChainWindows(remotePid);
71
- }));
72
- server.listen(pipePath);
73
- } else {
74
- const server = net.createServer(makeConnectionHandler(onData, (socket) => {
75
- const fd = (socket as any)._handle?.fd as number | undefined;
76
- if (fd == null) throw new Error('socket._handle.fd unavailable — cannot resolve peer PID');
77
- return resolveCallerChainUnix(fd);
78
- }));
79
- server.listen(socketPath);
80
- }
81
- },
82
- catch: (e) => `Failed to start socket server at ${socketPath}: ${e instanceof Error ? e.message : String(e)}`,
83
- });
84
- }
85
- registerVirtualHID(onMessage: (data: Buffer) => Effect.Effect<Buffer>) { return registerVirtualHID(onMessage); }
86
- }
@@ -1,16 +0,0 @@
1
- import { Effect } from "effect";
2
- import type { Option } from "effect";
3
- import type { EffectGen } from "effective-modules";
4
-
5
- export interface CallerProcess {
6
- pid: number;
7
- command: string;
8
- directory: Option.Option<string>;
9
- }
10
-
11
- export interface IOSPlatform {
12
- openBrowserWindow(url: string): Effect.Effect<void, never>;
13
- writeRestrictedFile(path: string, content: string): Effect.Effect<void, string>;
14
- startSocketServer(socketPath: string, onData: (data: Buffer, callerChain: CallerProcess[]) => EffectGen<Buffer>): EffectGen<void, string>;
15
- registerVirtualHID(onMessage: (data: Buffer) => Effect.Effect<Buffer>): Effect.Effect<void, string>;
16
- }
@@ -1,12 +0,0 @@
1
- import { Effect } from "effect";
2
- import { registerVirtualHIDMac } from "./mac";
3
- import { registerVirtualHIDLinux } from "./linux";
4
- import { registerVirtualHIDWindows } from "./windows";
5
-
6
- export function registerVirtualHID(
7
- onMessage: (data: Buffer) => Effect.Effect<Buffer>
8
- ): Effect.Effect<void, string> {
9
- if (process.platform === 'darwin') return registerVirtualHIDMac(onMessage);
10
- if (process.platform === 'win32') return registerVirtualHIDWindows(onMessage);
11
- return registerVirtualHIDLinux(onMessage);
12
- }
@@ -1,7 +0,0 @@
1
- import { Effect } from "effect";
2
-
3
- export function registerVirtualHIDLinux(
4
- _onMessage: (data: Buffer) => Effect.Effect<Buffer>
5
- ): Effect.Effect<void, string> {
6
- return Effect.fail('registerVirtualHID is not yet supported on Linux');
7
- }
@@ -1,150 +0,0 @@
1
- import { Effect, Option, pipe } from "effect";
2
- import { JSCallback, dlopen, FFIType, ptr, toArrayBuffer } from "bun:ffi";
3
- import type { Pointer } from "bun:ffi";
4
-
5
- // FIDO Alliance usage page (0xF1D0), 64-byte in/out reports, no report IDs
6
- const FIDO2_HID_DESCRIPTOR = new Uint8Array([
7
- 0x06, 0xD0, 0xF1, // Usage Page (FIDO Alliance 0xF1D0, little-endian)
8
- 0x09, 0x01, // Usage (U2F HID Authenticator Device)
9
- 0xA1, 0x01, // Collection (Application)
10
- 0x09, 0x20, // Usage (Input report data)
11
- 0x15, 0x00, // Logical Minimum (0)
12
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
13
- 0x75, 0x08, // Report Size (8 bits)
14
- 0x95, 0x40, // Report Count (64)
15
- 0x81, 0x02, // Input (Data, Variable, Absolute)
16
- 0x09, 0x21, // Usage (Output report data)
17
- 0x15, 0x00, // Logical Minimum (0)
18
- 0x26, 0xFF, 0x00, // Logical Maximum (255)
19
- 0x75, 0x08, // Report Size (8 bits)
20
- 0x95, 0x40, // Report Count (64)
21
- 0x91, 0x02, // Output (Data, Variable, Absolute)
22
- 0xC0, // End Collection
23
- ]);
24
-
25
- const kIOHIDReportTypeOutput = 1;
26
- const kIOReturnSuccess = 0;
27
- const kCFStringEncodingUTF8 = 0x08000100;
28
- const kCFPropertyListImmutable = 0;
29
-
30
- // Kept at module scope to prevent GC while the virtual device is running
31
- let _vhidCallback: JSCallback | null = null;
32
- _vhidCallback;
33
-
34
- const fromPtr = (label: string, p: Pointer | null): Effect.Effect<Pointer, string> =>
35
- pipe(
36
- Option.fromNullishOr(p),
37
- Effect.fromOption,
38
- Effect.mapError(() => `${label} returned NULL`),
39
- );
40
-
41
- // Build the device properties as an XML plist. CFPropertyListCreateWithData parses this
42
- // into a fully-initialized CFDictionary (with correct hash/equal callbacks), avoiding
43
- // the need to pass raw CFDictionaryKeyCallBacks structs via FFI.
44
- function buildDevicePropertiesPlist(): Uint8Array {
45
- const descriptorB64 = Buffer.from(FIDO2_HID_DESCRIPTOR).toString('base64');
46
- const xml = [
47
- '<?xml version="1.0" encoding="UTF-8"?>',
48
- '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
49
- '<plist version="1.0">',
50
- '<dict>',
51
- ' <key>ReportDescriptor</key>',
52
- ` <data>${descriptorB64}</data>`,
53
- ' <key>VendorID</key>',
54
- ' <integer>4617</integer>', // 0x1209 - pid.codes open-source VID
55
- ' <key>ProductID</key>',
56
- ' <integer>1</integer>',
57
- ' <key>VersionNumber</key>',
58
- ' <integer>256</integer>', // 0x0100
59
- ' <key>Product</key>',
60
- ' <string>Ozy Virtual FIDO2 Key</string>',
61
- '</dict>',
62
- '</plist>',
63
- ].join('\n');
64
- return new TextEncoder().encode(xml);
65
- }
66
-
67
- export function registerVirtualHIDMac(
68
- onMessage: (data: Buffer) => Effect.Effect<Buffer>
69
- ): Effect.Effect<void, string> {
70
- return Effect.gen(function* () {
71
- console.log('[vhid] loading frameworks');
72
-
73
- const IOKit = yield* Effect.try({
74
- try: () => dlopen('/System/Library/Frameworks/IOKit.framework/IOKit', {
75
- IOHIDUserDeviceCreate: { args: [FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
76
- IOHIDUserDeviceRegisterSetReportCallback: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.void },
77
- IOHIDUserDeviceScheduleWithRunLoop: { args: [FFIType.ptr, FFIType.ptr, FFIType.ptr], returns: FFIType.void },
78
- IOHIDUserDeviceHandleReport: { args: [FFIType.ptr, FFIType.ptr, FFIType.i64], returns: FFIType.i32 },
79
- }),
80
- catch: (e) => `Failed to load IOKit: ${e}`,
81
- });
82
-
83
- const CF = yield* Effect.try({
84
- try: () => dlopen('/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation', {
85
- CFRunLoopGetCurrent: { args: [], returns: FFIType.ptr },
86
- CFRunLoopRunInMode: { args: [FFIType.ptr, FFIType.f64, FFIType.bool], returns: FFIType.i32 },
87
- CFStringCreateWithCString: { args: [FFIType.ptr, FFIType.ptr, FFIType.u32], returns: FFIType.ptr },
88
- CFDataCreate: { args: [FFIType.ptr, FFIType.ptr, FFIType.i64], returns: FFIType.ptr },
89
- CFPropertyListCreateWithData: { args: [FFIType.ptr, FFIType.ptr, FFIType.u64, FFIType.ptr, FFIType.ptr], returns: FFIType.ptr },
90
- CFRelease: { args: [FFIType.ptr], returns: FFIType.void },
91
- }),
92
- catch: (e) => `Failed to load CoreFoundation: ${e}`,
93
- });
94
-
95
- console.log('[vhid] frameworks loaded');
96
-
97
- const encoder = new TextEncoder();
98
-
99
- const makeCFString = (s: string): Effect.Effect<Pointer, string> =>
100
- // TextEncoder gives a Uint8Array with its own ArrayBuffer (byteOffset=0, pool-safe)
101
- fromPtr(`CFStringCreateWithCString("${s}")`,
102
- CF.symbols.CFStringCreateWithCString(null, ptr(encoder.encode(s + '\0')), kCFStringEncodingUTF8));
103
-
104
- const makeCFData = (data: Uint8Array): Effect.Effect<Pointer, string> =>
105
- fromPtr('CFDataCreate', CF.symbols.CFDataCreate(null, ptr(data), BigInt(data.length)));
106
-
107
- console.log('[vhid] building device properties plist');
108
- const plistBytes = buildDevicePropertiesPlist();
109
- const plistData = yield* makeCFData(plistBytes);
110
-
111
- const dict = yield* fromPtr('CFPropertyListCreateWithData',
112
- CF.symbols.CFPropertyListCreateWithData(null, plistData, BigInt(kCFPropertyListImmutable), null, null));
113
- CF.symbols.CFRelease(plistData);
114
- console.log('[vhid] device properties dict =', dict);
115
-
116
- console.log('[vhid] creating IOHIDUserDevice');
117
- const device = yield* fromPtr('IOHIDUserDeviceCreate', IOKit.symbols.IOHIDUserDeviceCreate(null, dict));
118
- CF.symbols.CFRelease(dict);
119
- console.log('[vhid] IOHIDUserDeviceCreate =', device);
120
-
121
- const callback = yield* Effect.try({
122
- try: () => new JSCallback(
123
- (_refcon: number, _result: number, _sender: number, type: number, _reportID: number, report: number, reportLength: number) => {
124
- if (type !== kIOHIDReportTypeOutput) return kIOReturnSuccess;
125
- const incoming = Buffer.from(toArrayBuffer(report as unknown as Pointer, 0, reportLength));
126
- console.log(`[vhid] received ${incoming.length} bytes: ${incoming.toString('hex')}`);
127
- Effect.runPromise(onMessage(incoming)).then(response => {
128
- const responseBuf = new Uint8Array(64);
129
- response.copy(Buffer.from(responseBuf.buffer), 0, 0, Math.min(response.length, 64));
130
- IOKit.symbols.IOHIDUserDeviceHandleReport(device, ptr(responseBuf), BigInt(responseBuf.length));
131
- }).catch(() => {});
132
- return kIOReturnSuccess;
133
- },
134
- { returns: 'i32', args: ['ptr', 'i32', 'ptr', 'i32', 'u32', 'ptr', 'i64'] },
135
- ),
136
- catch: (e) => `Failed to create JSCallback: ${e}`,
137
- });
138
- _vhidCallback = callback;
139
-
140
- IOKit.symbols.IOHIDUserDeviceRegisterSetReportCallback(device, callback.ptr, null);
141
-
142
- const runLoop = CF.symbols.CFRunLoopGetCurrent();
143
- const runLoopMode = yield* makeCFString('kCFRunLoopDefaultMode');
144
- IOKit.symbols.IOHIDUserDeviceScheduleWithRunLoop(device, runLoop, runLoopMode);
145
-
146
- console.log('[vhid] virtual FIDO2 device active, pumping run loop');
147
- // Pump CFRunLoop from Bun's libuv event loop without blocking
148
- setInterval(() => CF.symbols.CFRunLoopRunInMode(runLoopMode, 0.0, false), 10);
149
- });
150
- }
@@ -1,7 +0,0 @@
1
- import { Effect } from "effect";
2
-
3
- export function registerVirtualHIDWindows(
4
- _onMessage: (data: Buffer) => Effect.Effect<Buffer>
5
- ): Effect.Effect<void, string> {
6
- return Effect.fail('registerVirtualHID is not yet supported on Windows');
7
- }
@@ -1,130 +0,0 @@
1
- import * as fs from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { writeFileSync } from "node:fs";
4
- import { Effect, Option, Schema } from "effect";
5
- import SSHConfig, { LineType } from "ssh-config";
6
- import expandTilde from "expand-tilde";
7
- import { implementing, type EffectGen } from "effective-modules";
8
- import { commonModules } from "@/modules/common";
9
-
10
- import { SSHConfigSection, type ISSHConfig, type SSHConfigHosts, type WriteHostInput, type WritePubkeyInput } from "./interface";
11
-
12
- const SSH_CONFIG_PATH = "~/.ssh/config";
13
- const SSH_DIR = "~/.ssh";
14
-
15
- export class SSHConfigImpl extends implementing(commonModules.SSHConfig) implements ISSHConfig {
16
- private *loadSSHConfigRaw(): EffectGen<SSHConfig, string> {
17
- const configPath = expandTilde(SSH_CONFIG_PATH);
18
- const exists = yield* Effect.promise(() => fs.exists(configPath));
19
- const text = exists
20
- ? yield* Effect.tryPromise({
21
- try: () => fs.readFile(configPath, "utf8"),
22
- catch: (e) => `Failed to read ssh config at ${configPath}: ${e instanceof Error ? e.message : String(e)}`,
23
- })
24
- : "";
25
- return yield* Effect.try({
26
- try: () => SSHConfig.parse(text),
27
- catch: (e) => `ParseError: unable to parse ssh config at ${configPath}\n${e instanceof Error ? e.message : String(e)}`,
28
- });
29
- }
30
-
31
- *getSSHConfig(): EffectGen<SSHConfigHosts, string> {
32
- const configPath = expandTilde(SSH_CONFIG_PATH);
33
- const exists = yield* Effect.promise(() => fs.exists(configPath));
34
- if (!exists)
35
- return yield* Effect.fail(`SSHConfigFileMissingError: No file found at ${configPath}`);
36
-
37
- const parsed = yield* this.loadSSHConfigRaw();
38
-
39
- const hosts: SSHConfigHosts = {};
40
- for (const line of parsed) {
41
- if (line.type === LineType.COMMENT) continue;
42
- const { param, value: host } = line;
43
- if (param !== "Host")
44
- return yield* Effect.fail(`EntryNotAHostKeyValuePairError: unexpected top-level entry '${param}=${JSON.stringify(host)}'`);
45
- if (typeof host !== "string")
46
- return yield* Effect.fail(`EntryNotAHostKeyValuePairError: Host value is not a string: ${JSON.stringify(host)}`);
47
- if (!("config" in line))
48
- return yield* Effect.fail(`EntryNotAHostKeyValuePairError: non-section Host entry '${host}'`);
49
- if (host in hosts)
50
- return yield* Effect.fail(`DuplicateHostError: duplicate Host '${host}' in ${configPath}`);
51
-
52
- const kv: Record<string, string> = {};
53
- for (const inner of line.config) {
54
- if (inner.type === LineType.COMMENT) continue;
55
- if (typeof inner.value !== "string")
56
- return yield* Effect.fail(`MalformedError: Host '${host}' key '${inner.param}' has non-string value`);
57
- kv[inner.param] = inner.value;
58
- }
59
-
60
- const section = yield* Schema.decodeUnknownEffect(SSHConfigSection)(kv).pipe(
61
- Effect.mapError(e => `MalformedError: malformed section at Host '${host}': ${String(e)}`)
62
- );
63
- hosts[host] = section;
64
- }
65
-
66
- return hosts;
67
- }
68
-
69
- *writeHost({ section }: WriteHostInput): EffectGen<void, string> {
70
- const configPath = expandTilde(SSH_CONFIG_PATH);
71
- const cfg = yield* this.loadSSHConfigRaw();
72
- const newEntries = Object.entries(section)
73
- .filter(([, v]) => v !== undefined)
74
- .map(([k, v]) => ({ type: LineType.DIRECTIVE, before: ' ', param: k, separator: ' ', value: v as string, after: '\n' }));
75
-
76
- const existingIdx = cfg.findIndex((e: any) => e.param === "Host" && e.value === section.HostName);
77
- if (existingIdx >= 0) {
78
- (cfg[existingIdx] as any).config = newEntries;
79
- } else {
80
- const record: Record<string, string> = { Host: section.HostName };
81
- for (const [k, v] of Object.entries(section)) {
82
- if (v !== undefined) record[k] = v;
83
- }
84
- cfg.append(record);
85
- }
86
-
87
- yield* Effect.try({
88
- try: () => writeFileSync(configPath, SSHConfig.stringify(cfg), { mode: 0o600 }),
89
- catch: (e) => `Failed to write ssh config: ${e instanceof Error ? e.message : String(e)}`,
90
- });
91
- }
92
-
93
- *listPubkeyFiles(): EffectGen<{name: string, content: string}[], string> {
94
- const sshDir = expandTilde(SSH_DIR);
95
- const entries = yield* Effect.tryPromise({
96
- try: () => fs.readdir(sshDir),
97
- catch: (e) => `Failed to read ${sshDir}: ${e instanceof Error ? e.message : String(e)}`,
98
- });
99
- const pubkeyFiles = entries.filter(f => f.endsWith('.pub'));
100
- const results: {name: string, content: string}[] = [];
101
- for (const file of pubkeyFiles) {
102
- const content = yield* Effect.tryPromise({
103
- try: () => fs.readFile(join(sshDir, file), 'utf8'),
104
- catch: (e) => `Failed to read ${file}: ${e instanceof Error ? e.message : String(e)}`,
105
- });
106
- results.push({ name: file.slice(0, -'.pub'.length), content: content.trim() });
107
- }
108
- return results;
109
- }
110
-
111
- getPubkeyPath(name: string): string {
112
- return `${expandTilde(SSH_DIR)}/${name}.pub`;
113
- }
114
-
115
- *writePubkey({ name, comment, pubkey }: WritePubkeyInput): EffectGen<{pubkeyPath: string}, string> {
116
- const sshDir = expandTilde(SSH_DIR);
117
- const pubkeyPath = `${sshDir}/${name}.pub`;
118
- const content = Option.match(comment, {
119
- onNone: () => pubkey.authorizedKey,
120
- onSome: (c) => `${pubkey.authorizedKey} ${c}`,
121
- });
122
-
123
- yield* Effect.try({
124
- try: () => writeFileSync(pubkeyPath, content + "\n", { mode: 0o600 }),
125
- catch: (e) => `Failed to write pubkey to ${pubkeyPath}: ${e instanceof Error ? e.message : String(e)}`,
126
- });
127
-
128
- return {pubkeyPath};
129
- }
130
- }
@@ -1,33 +0,0 @@
1
- import { Schema } from "effect";
2
- import type { Option } from "effect";
3
- import type { EffectGen } from "effective-modules";
4
- import type { SSHPubkey } from "@/modules/common/crypto/impl";
5
-
6
- export const SSHConfigSection = Schema.Struct({
7
- HostName: Schema.String,
8
- User: Schema.String,
9
- IdentityFile: Schema.optional(Schema.String),
10
- AddKeysToAgent: Schema.optional(Schema.String),
11
- IdentitiesOnly: Schema.optional(Schema.String),
12
- IdentityAgent: Schema.optional(Schema.String),
13
- });
14
- export type SSHConfigSection = Schema.Schema.Type<typeof SSHConfigSection>;
15
- export type SSHConfigHosts = Record<string, SSHConfigSection>;
16
-
17
- export interface WriteHostInput {
18
- section: SSHConfigSection;
19
- }
20
-
21
- export interface WritePubkeyInput {
22
- name: string;
23
- comment: Option.Option<string>;
24
- pubkey: SSHPubkey;
25
- }
26
-
27
- export interface ISSHConfig {
28
- getSSHConfig(): EffectGen<SSHConfigHosts, string>;
29
- writeHost(input: WriteHostInput): EffectGen<void, string>;
30
- writePubkey(input: WritePubkeyInput): EffectGen<{pubkeyPath: string}, string>;
31
- listPubkeyFiles(): EffectGen<{name: string, content: string}[], string>;
32
- getPubkeyPath(name: string): string;
33
- }
@@ -1,13 +0,0 @@
1
- import { interfaces } from "effective-modules";
2
- import type { ISSHAgent } from "./ssh-agent/interface";
3
- import type { ISession } from "./session/interface";
4
-
5
- export enum AgentModules {
6
- SSHAgent = "SSHAgent",
7
- Session = "Session"
8
- }
9
-
10
- export const agentModules = interfaces<AgentModules, {
11
- SSHAgent: ISSHAgent;
12
- Session: ISession;
13
- }>(AgentModules);