@farmslot/adapter-web 0.5.0 → 0.6.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 (41) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +24 -1
  3. package/dist/web-dapp/cleanup.d.mts +15 -0
  4. package/dist/web-dapp/index.d.mts +123 -0
  5. package/dist/web-dapp/inject.d.mts +12 -0
  6. package/dist/web-dapp/launch.d.mts +56 -0
  7. package/dist/web-dapp/lib/blocked-hosts.d.mts +3 -0
  8. package/dist/web-dapp/lib/cdp-client.d.mts +8 -0
  9. package/dist/web-dapp/lib/display.d.mts +26 -0
  10. package/dist/web-dapp/lib/hud.d.mts +14 -0
  11. package/dist/web-dapp/lib/paths.d.mts +11 -0
  12. package/dist/web-dapp/lib/policy-fence.d.mts +18 -0
  13. package/dist/web-dapp/lib/policy.d.mts +4 -0
  14. package/dist/web-dapp/lib/processes.d.mts +57 -0
  15. package/dist/web-dapp/lib/readiness.d.mts +85 -0
  16. package/dist/web-dapp/lib/runtime.d.mts +29 -0
  17. package/dist/web-dapp/lib/signers.d.mts +13 -0
  18. package/dist/web-dapp/lib/viem.d.mts +1 -0
  19. package/dist/web-dapp/stop.d.mts +2 -0
  20. package/dist/web-dapp/verify.d.mts +2 -0
  21. package/dist/web-dapp/wallet-host.d.mts +2 -0
  22. package/package.json +17 -10
  23. package/src/web-dapp/cleanup.mjs +74 -0
  24. package/src/web-dapp/index.mjs +590 -0
  25. package/src/web-dapp/inject.mjs +100 -0
  26. package/src/web-dapp/launch.mjs +806 -0
  27. package/src/web-dapp/lib/blocked-hosts.mjs +24 -0
  28. package/src/web-dapp/lib/cdp-client.mjs +86 -0
  29. package/src/web-dapp/lib/display.mjs +169 -0
  30. package/src/web-dapp/lib/hud.mjs +156 -0
  31. package/src/web-dapp/lib/paths.mjs +55 -0
  32. package/src/web-dapp/lib/policy-fence.mjs +128 -0
  33. package/src/web-dapp/lib/policy.mjs +108 -0
  34. package/src/web-dapp/lib/processes.mjs +215 -0
  35. package/src/web-dapp/lib/readiness.mjs +438 -0
  36. package/src/web-dapp/lib/runtime.mjs +195 -0
  37. package/src/web-dapp/lib/signers.mjs +105 -0
  38. package/src/web-dapp/lib/viem.mjs +26 -0
  39. package/src/web-dapp/stop.mjs +44 -0
  40. package/src/web-dapp/verify.mjs +68 -0
  41. package/src/web-dapp/wallet-host.mjs +728 -0
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ // inject.mjs — `mm-harness install --adapter <web-dapp adapter>`: prepare the slot
3
+ // runtime directory and install the wallet fixture the web-dapp actions read.
4
+ //
5
+ // Inputs: --target <checkout> [--fixture <wallet-fixture.json>] [--force]
6
+ // env RECIPE_WALLET_FIXTURE (fixture source when --fixture is absent)
7
+ // Outputs: <target>/<harness root>/<adapter id>/install.json (overlay marker),
8
+ // <target>/<runtime>/<adapter id>/ (0700), <runtime>/wallet-fixture.json (0600);
9
+ // JSON summary on stdout (account names only). Exit 0 installed; 1 failure; 2 usage.
10
+ // Never touches: product source files; never prints key material.
11
+
12
+ import {
13
+ chmodSync,
14
+ copyFileSync,
15
+ existsSync,
16
+ mkdirSync,
17
+ readFileSync,
18
+ writeFileSync,
19
+ } from 'node:fs';
20
+ import path from 'node:path';
21
+ import { fileURLToPath } from 'node:url';
22
+
23
+ import { recipeHarnessPath, recipeRuntimeDir, walletFixturePath } from './lib/paths.mjs';
24
+ import { webDappPolicy, webDappRuntimeDir } from './lib/runtime.mjs';
25
+
26
+ const usage = 'Usage: inject.mjs --target <checkout> [--fixture <wallet-fixture.json>] [--force]';
27
+
28
+ export function installWebDappRuntime({ target, fixture, force = false }) {
29
+ const root = path.resolve(target);
30
+ const { adapterId, checkout } = webDappPolicy();
31
+ if (!checkout.matches(root))
32
+ throw new Error(`${root} is not a ${checkout.name} checkout (needs ${checkout.needs}).`);
33
+ mkdirSync(path.join(root, recipeRuntimeDir()), { recursive: true, mode: 0o700 });
34
+ mkdirSync(webDappRuntimeDir(root), { recursive: true, mode: 0o700 });
35
+ const destination = walletFixturePath(root);
36
+ let fixtureAction = 'kept';
37
+ if (fixture && (force || !existsSync(destination))) {
38
+ const parsed = JSON.parse(readFileSync(fixture, 'utf8'));
39
+ if (!Array.isArray(parsed.accounts) || parsed.accounts.length === 0)
40
+ throw new Error(`${fixture} has no accounts.`);
41
+ copyFileSync(fixture, destination);
42
+ chmodSync(destination, 0o600);
43
+ fixtureAction = 'installed';
44
+ } else if (!existsSync(destination)) {
45
+ fixtureAction = 'missing';
46
+ }
47
+ const accounts = existsSync(destination)
48
+ ? JSON.parse(readFileSync(destination, 'utf8'))
49
+ .accounts.map((account) => account?.name)
50
+ .filter(Boolean)
51
+ : [];
52
+ const marker = {
53
+ schemaVersion: 1,
54
+ adapter: adapterId,
55
+ installedAt: new Date().toISOString(),
56
+ fixture: fixtureAction,
57
+ };
58
+ // The overlay directory is the install marker run/call auto-ensure checks.
59
+ const overlay = recipeHarnessPath(root, adapterId);
60
+ mkdirSync(overlay, { recursive: true, mode: 0o700 });
61
+ writeFileSync(path.join(overlay, 'install.json'), `${JSON.stringify(marker, null, 2)}\n`, {
62
+ mode: 0o600,
63
+ });
64
+ return {
65
+ status: fixtureAction === 'missing' ? 'fail' : 'pass',
66
+ target: root,
67
+ fixture: fixtureAction,
68
+ fixturePath: destination,
69
+ accounts,
70
+ };
71
+ }
72
+
73
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
74
+ const argv = process.argv.slice(2);
75
+ if (argv.includes('--help') || argv.includes('-h')) {
76
+ process.stdout.write(`${usage}\n`);
77
+ process.exit(0);
78
+ }
79
+ const value = (flag) => {
80
+ const index = argv.indexOf(flag);
81
+ return index >= 0 ? argv[index + 1] : undefined;
82
+ };
83
+ try {
84
+ const result = installWebDappRuntime({
85
+ target: value('--target') ?? process.cwd(),
86
+ fixture: value('--fixture') ?? process.env.RECIPE_WALLET_FIXTURE,
87
+ force: argv.includes('--force'),
88
+ });
89
+ process.stdout.write(`${JSON.stringify(result)}\n`);
90
+ if (result.status !== 'pass') {
91
+ process.stderr.write(
92
+ 'No wallet fixture installed. Next: set RECIPE_WALLET_FIXTURE or pass --fixture <wallet-fixture.json>.\n',
93
+ );
94
+ process.exit(1);
95
+ }
96
+ } catch (error) {
97
+ process.stderr.write(`${error.message}\n`);
98
+ process.exit(1);
99
+ }
100
+ }