@etherplay/dev-wallet-host 0.0.0 → 0.1.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 +110 -0
- package/bin/dev-wallet-host.js +163 -0
- package/config.example.json +30 -0
- package/lib/server.js +130 -0
- package/package.json +52 -2
- package/site/Facebook_Logo_Primary.png +0 -0
- package/site/README.txt +12 -0
- package/site/_etherplay_accounts.html +168 -0
- package/site/assets/App-81EXtqUY.css +495 -0
- package/site/assets/App-n-xKxOMT.js +21249 -0
- package/site/assets/App-n-xKxOMT.js.map +1 -0
- package/site/assets/bignumbers-tTSUAFen.js +12 -0
- package/site/assets/bignumbers-tTSUAFen.js.map +1 -0
- package/site/assets/index-BqqAh48J.js +28 -0
- package/site/assets/index-BqqAh48J.js.map +1 -0
- package/site/assets/index-CnVGoVpH.js +4020 -0
- package/site/assets/index-CnVGoVpH.js.map +1 -0
- package/site/assets/index-DqysTtwQ.js +918 -0
- package/site/assets/index-DqysTtwQ.js.map +1 -0
- package/site/assets/index-Wu-sMuYC.js +5153 -0
- package/site/assets/index-Wu-sMuYC.js.map +1 -0
- package/site/assets/index-Y5uolvJQ.js +24364 -0
- package/site/assets/index-Y5uolvJQ.js.map +1 -0
- package/site/assets/index-client-8kPxwRn_.js +1771 -0
- package/site/assets/index-client-8kPxwRn_.js.map +1 -0
- package/site/assets/index-dhS1shEX.js +6227 -0
- package/site/assets/index-dhS1shEX.js.map +1 -0
- package/site/assets/index-l0sNRNKZ.js.map +1 -0
- package/site/assets/login-CbHgl9FL.js +324 -0
- package/site/assets/login-CbHgl9FL.js.map +1 -0
- package/site/assets/login-bn0FJsfM.css +30 -0
- package/site/assets/typed-data-Xi7g-SpO.js +834 -0
- package/site/assets/typed-data-Xi7g-SpO.js.map +1 -0
- package/site/assets/utf8-B9sGmk3K.js +172 -0
- package/site/assets/utf8-B9sGmk3K.js.map +1 -0
- package/site/build-info.json +4 -0
- package/site/google_logo.png +0 -0
- package/site/index.html +12 -0
- package/site/login/index.html +49 -0
- package/site/logo.svg +104 -0
- package/site/x-logo-black.png +0 -0
- package/site/x-logo-white.png +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# @etherplay/dev-wallet-host
|
|
2
|
+
|
|
3
|
+
The Etherplay sign-in host, prebuilt, so you can run it next to your app the way you already run a faucet.
|
|
4
|
+
|
|
5
|
+
**Development and e2e only.** This build takes its configuration at runtime, which makes it unfit for real accounts by construction. That is the point: everything in it is injectable precisely because none of it guards anything. Do not deploy it. The host that holds real accounts is a different build of the same source, with every value baked in and no runtime document honoured.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Without it, anything downstream of hosted sign-in needs either a deployed host or a checkout of the `etherplay-connect` monorepo, so the ordinary local loop stops at the wallet path. This is a dependency, a version in your lockfile, and a directory to serve. No build step, no publishable key, no sibling checkout.
|
|
10
|
+
|
|
11
|
+
It is one artefact for two jobs on purpose: what you want running while you work and what your e2e run starts are the same thing configured the same way, and splitting them gives you a fixture nobody looks at standing in for a service everybody uses.
|
|
12
|
+
|
|
13
|
+
## Install and run
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install --save-dev @etherplay/dev-wallet-host
|
|
17
|
+
npx dev-wallet-host --port 50000
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```jsonc
|
|
21
|
+
{
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "dev-wallet-host --port 50000 & vite dev",
|
|
24
|
+
"test:e2e": "dev-wallet-host --port 50000 & playwright test",
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Then point your app at exactly that origin:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
createConnection({walletHost: 'http://localhost:50000' /* ... */});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
With no configuration at all it serves a working sign-in. The mnemonic mechanism needs no key, no account and no network: it defaults to the standard hardhat test phrase, so the only input is which account index to use, and the accounts it derives are the ones your local chain already funded.
|
|
36
|
+
|
|
37
|
+
### Options
|
|
38
|
+
|
|
39
|
+
| option | what it does |
|
|
40
|
+
| ---------------------- | ----------------------------------------------------------- |
|
|
41
|
+
| `-p, --port <number>` | port to listen on (default `50000`) |
|
|
42
|
+
| `-H, --host <address>` | address to bind (default `127.0.0.1`) |
|
|
43
|
+
| `-c, --config <file>` | serve this file as `/config.json`, re-read on every request |
|
|
44
|
+
| `-d, --dir <path>` | serve a different directory instead of the bundled one |
|
|
45
|
+
| `-v, --version` | print the version |
|
|
46
|
+
| `-h, --help` | print the usage |
|
|
47
|
+
|
|
48
|
+
## Configuring it
|
|
49
|
+
|
|
50
|
+
Optional. Write a JSON file anywhere in your project and pass `--config`; it is re-read on every request, so editing it and reloading the popup is the whole loop. Copy `node_modules/@etherplay/dev-wallet-host/config.example.json` to start from.
|
|
51
|
+
|
|
52
|
+
| field | what it is |
|
|
53
|
+
| --------------------------- | ------------------------------------------------------------------------------ |
|
|
54
|
+
| `hostedAuthProvider` | which provider answers email and OAuth (never consulted for mnemonic) |
|
|
55
|
+
| `devMnemonic` | the phrase the mnemonic mechanism signs in with |
|
|
56
|
+
| `openfort` | `publishableKey`, `shieldPublishableKey`, `encryptionSessionEndpoint` |
|
|
57
|
+
| `allowLoopbackRequesters` | whether a page on this machine may ask for another origin's account |
|
|
58
|
+
| `originAllowlist` | requester origin to the (chainId, contract) pairs it may have without a prompt |
|
|
59
|
+
| `crossOriginAllowlist` | origin whose account is at stake, to who may ask for it |
|
|
60
|
+
| `autoSignedLifetimeSeconds` | how long an auto-signed credential may be presented for |
|
|
61
|
+
| `promptedLifetimeSeconds` | the same for one a human granted; `0` means no expiry |
|
|
62
|
+
|
|
63
|
+
A field of the wrong type is refused out loud in the console rather than silently dropped.
|
|
64
|
+
|
|
65
|
+
The two lifetimes are the ones people forget and then need. An auto-signed credential's deadline is the only lever an allowlist entry has once that entry turns out to be wrong, so a test that cannot set it cannot exercise expiry at all, and nobody can watch a credential expire without waiting three months. Set `autoSignedLifetimeSeconds` to something small and you can.
|
|
66
|
+
|
|
67
|
+
Example, for an app on `http://localhost:5173` testing the auto-signed path against a local chain:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"originAllowlist": {
|
|
72
|
+
"http://localhost:5173": [{"chainId": 31337, "contract": "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512"}]
|
|
73
|
+
},
|
|
74
|
+
"autoSignedLifetimeSeconds": 120
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## The one thing that wastes an afternoon
|
|
79
|
+
|
|
80
|
+
**The origin must match exactly.** The host delivers its result with `postMessage`, using the origin your app declared as `targetOrigin`. If that is not the origin your app is really at, the browser drops the result: the sign-in visibly completes in the popup and your app receives nothing, with no error of its own. `http://127.0.0.1:5173` and `http://localhost:5173` are the same machine and not the same origin.
|
|
81
|
+
|
|
82
|
+
The host checks for this and says so in the popup's console, but it can only warn. Whatever this server prints on startup must be exactly what you pass as `walletHost`.
|
|
83
|
+
|
|
84
|
+
## Plain http is fine
|
|
85
|
+
|
|
86
|
+
The flow is a popup plus `postMessage`, and neither needs a secure context. `http://localhost` and `http://127.0.0.1` are potentially trustworthy origins anyway, so even the APIs that do require one are available there.
|
|
87
|
+
|
|
88
|
+
One edge: binding with `--host 0.0.0.0` so a phone on your network can reach `http://192.168.x.x` gives up secure-context status, and with it `crypto.subtle`. The ordinary popup flow still works; the opt-in domain-redirect bridge does not, and testing that path from a device needs https.
|
|
89
|
+
|
|
90
|
+
## Serving it yourself
|
|
91
|
+
|
|
92
|
+
The bundle is a plain static directory (`node_modules/@etherplay/dev-wallet-host/site`), so any static server will do. One requirement: it must **not** fall back to `index.html` for missing paths. The host asks for `/config.json` and treats an HTML answer as "no document", so a fallback turns a mistyped path into a configuration that silently did nothing. The bundled server answers 404, on purpose.
|
|
93
|
+
|
|
94
|
+
## Which provider answers which sign-in
|
|
95
|
+
|
|
96
|
+
By mechanism. `mnemonic` is derived in the browser with nothing behind it; email and OAuth go to the hosted provider named by `hostedAuthProvider`, which needs that provider's own credentials to do anything. This is why a mnemonic sign-in works here with no keys at all.
|
|
97
|
+
|
|
98
|
+
## Checking it from the outside
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
node scripts/verify-adopter-install.mjs # needs Chrome; CHROME=<path> if not on PATH
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Packs the tarball, installs it with `npm` into a throwaway project with no workspace and no path back to this checkout, starts the bin the way a dev script would, and completes a mnemonic sign-in in a real browser, asserting that the credential and deadline came from the config file.
|
|
105
|
+
|
|
106
|
+
Not part of `pnpm test` and not in CI, because it needs a browser. Run it before publishing, or when the bundle, the bin or the popup contract changes: the unit tests cannot fail for the reasons this package actually fails for. The first run of it found two such reasons.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
MIT
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Serve the prebuilt development sign-in host.
|
|
4
|
+
*
|
|
5
|
+
* This file is only ever the entry point, so it just runs. The server itself is in ../lib/server.js,
|
|
6
|
+
* where the tests reach it without spawning anything: deciding "am I the entry point" from
|
|
7
|
+
* `process.argv[1]` is a question with a wrong answer when the bin is reached through the `.bin`
|
|
8
|
+
* symlink an install creates, which is every real use of this.
|
|
9
|
+
*/
|
|
10
|
+
import {readFile, stat} from 'node:fs/promises';
|
|
11
|
+
import {join, resolve} from 'node:path';
|
|
12
|
+
import {createHost, DEFAULT_DIR, DEFAULT_PORT} from '../lib/server.js';
|
|
13
|
+
|
|
14
|
+
const HELP = `
|
|
15
|
+
dev-wallet-host - the Etherplay sign-in host, prebuilt, for development and e2e
|
|
16
|
+
|
|
17
|
+
DEVELOPMENT ONLY. This build accepts its configuration at runtime and is unfit for
|
|
18
|
+
real accounts by construction. Do not deploy it.
|
|
19
|
+
|
|
20
|
+
Usage
|
|
21
|
+
dev-wallet-host [options]
|
|
22
|
+
|
|
23
|
+
Options
|
|
24
|
+
-p, --port <number> port to listen on (default ${DEFAULT_PORT})
|
|
25
|
+
-H, --host <address> address to bind (default 127.0.0.1)
|
|
26
|
+
-c, --config <file> serve this file as /config.json, read fresh on every request
|
|
27
|
+
-d, --dir <path> serve this directory instead of the bundled one
|
|
28
|
+
-v, --version print the version
|
|
29
|
+
-h, --help print this
|
|
30
|
+
|
|
31
|
+
Notes
|
|
32
|
+
Signing in by mnemonic needs no key, no account and no network: it defaults to the
|
|
33
|
+
standard hardhat test phrase, and the only input is which account index to use.
|
|
34
|
+
|
|
35
|
+
Binding to 0.0.0.0 so another device can reach this gives up secure-context status,
|
|
36
|
+
which the optional domain-redirect bridge needs. The ordinary popup flow is fine.
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
function parseArgs(argv) {
|
|
40
|
+
const options = {port: DEFAULT_PORT, host: '127.0.0.1', dir: DEFAULT_DIR, config: undefined};
|
|
41
|
+
for (let i = 0; i < argv.length; i++) {
|
|
42
|
+
const arg = argv[i];
|
|
43
|
+
const next = () => {
|
|
44
|
+
const value = argv[++i];
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
throw new Error(`${arg} needs a value`);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
if (arg === '--help' || arg === '-h') return {...options, help: true};
|
|
51
|
+
else if (arg === '--version' || arg === '-v') return {...options, version: true};
|
|
52
|
+
else if (arg === '--port' || arg === '-p') options.port = Number(next());
|
|
53
|
+
else if (arg === '--host' || arg === '-H') options.host = next();
|
|
54
|
+
else if (arg === '--dir' || arg === '-d') options.dir = resolve(next());
|
|
55
|
+
else if (arg === '--config' || arg === '-c') options.config = resolve(next());
|
|
56
|
+
else throw new Error(`unknown option: ${arg}`);
|
|
57
|
+
}
|
|
58
|
+
if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65535) {
|
|
59
|
+
throw new Error(`--port must be a port number, got "${options.port}"`);
|
|
60
|
+
}
|
|
61
|
+
return options;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Which spelling to tell the developer to use.
|
|
66
|
+
*
|
|
67
|
+
* Binding the loopback interface answers to `localhost` AND `127.0.0.1`, and those are the SAME
|
|
68
|
+
* server at TWO origins. Printing the bind address would hand out `127.0.0.1` while the app almost
|
|
69
|
+
* certainly says `localhost`, which is the exact confusion this artefact exists to stop, so the
|
|
70
|
+
* banner names one spelling and says plainly that the other is a different origin.
|
|
71
|
+
*/
|
|
72
|
+
function displayHost(host) {
|
|
73
|
+
return host === '127.0.0.1' || host === '::1' || host === '0.0.0.0' || host === '::' ? 'localhost' : host;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function banner(origin, options, version) {
|
|
77
|
+
const config = options.config ? options.config : 'none (built-in defaults, which are enough to sign in)';
|
|
78
|
+
const alias = displayHost(options.host) === 'localhost' ? `http://127.0.0.1:${options.port}` : undefined;
|
|
79
|
+
return [
|
|
80
|
+
``,
|
|
81
|
+
` etherplay dev wallet host ${version} - DEVELOPMENT ONLY, not for real accounts`,
|
|
82
|
+
``,
|
|
83
|
+
` serving ${origin}`,
|
|
84
|
+
` from ${options.dir}`,
|
|
85
|
+
` config ${config}`,
|
|
86
|
+
``,
|
|
87
|
+
` point your app at EXACTLY this origin: walletHost: '${origin}'`,
|
|
88
|
+
...(alias
|
|
89
|
+
? [
|
|
90
|
+
` the same server also answers at ${alias}, which is a DIFFERENT ORIGIN.`,
|
|
91
|
+
` pick one spelling and use it for the app and for walletHost, both: a`,
|
|
92
|
+
` mismatch completes the sign-in and delivers the result to nobody.`,
|
|
93
|
+
]
|
|
94
|
+
: [
|
|
95
|
+
` a different spelling of the same machine, or the wrong port, completes the`,
|
|
96
|
+
` sign-in and delivers the result to nobody.`,
|
|
97
|
+
]),
|
|
98
|
+
``,
|
|
99
|
+
].join('\n');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let options;
|
|
103
|
+
try {
|
|
104
|
+
options = parseArgs(process.argv.slice(2));
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error(`[dev-wallet-host] ${err.message}`);
|
|
107
|
+
console.error(HELP);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const manifest = JSON.parse(await readFile(new URL('../package.json', import.meta.url), 'utf-8'));
|
|
112
|
+
|
|
113
|
+
if (options.help) {
|
|
114
|
+
console.log(HELP);
|
|
115
|
+
} else if (options.version) {
|
|
116
|
+
console.log(manifest.version);
|
|
117
|
+
} else {
|
|
118
|
+
try {
|
|
119
|
+
await stat(join(options.dir, 'login', 'index.html'));
|
|
120
|
+
} catch {
|
|
121
|
+
console.error(
|
|
122
|
+
`[dev-wallet-host] no sign-in host at ${options.dir}: expected ${join(options.dir, 'login', 'index.html')}.\n` +
|
|
123
|
+
`If you are running this from a checkout, build it first: pnpm --filter @etherplay/dev-wallet-host build`,
|
|
124
|
+
);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (options.config) {
|
|
129
|
+
try {
|
|
130
|
+
JSON.parse(await readFile(options.config, 'utf-8'));
|
|
131
|
+
} catch (err) {
|
|
132
|
+
// Said now rather than as a puzzling default at sign-in time.
|
|
133
|
+
console.error(`[dev-wallet-host] ${options.config} is not readable JSON: ${err.message}`);
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const server = createHost(options);
|
|
139
|
+
server.on('error', (err) => {
|
|
140
|
+
if (err.code === 'EADDRINUSE') {
|
|
141
|
+
console.error(
|
|
142
|
+
`[dev-wallet-host] port ${options.port} is already in use. Something else is on it; ` +
|
|
143
|
+
`use --port to pick another rather than assuming it is a stale copy of this.`,
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
console.error(`[dev-wallet-host] ${err.message}`);
|
|
147
|
+
}
|
|
148
|
+
process.exit(1);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
server.listen(options.port, options.host, () => {
|
|
152
|
+
options.port = server.address().port;
|
|
153
|
+
console.log(banner(`http://${displayHost(options.host)}:${options.port}`, options, manifest.version));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
for (const signal of ['SIGINT', 'SIGTERM']) {
|
|
157
|
+
process.on(signal, () => {
|
|
158
|
+
server.close(() => process.exit(0));
|
|
159
|
+
// A dev script that will not die on ctrl-c is its own kind of annoying.
|
|
160
|
+
setTimeout(() => process.exit(0), 500).unref();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_readme": [
|
|
3
|
+
"The runtime configuration document for the DEVELOPMENT build of the login host.",
|
|
4
|
+
"Copy it to the root of the directory you serve, next to index.html, as `config.json`.",
|
|
5
|
+
"Everything here is optional: with no document at all the host runs on the defaults below,",
|
|
6
|
+
"and a mnemonic sign-in needs no key, no account and no network.",
|
|
7
|
+
"A production build IGNORES this file and says so in the console when it finds one.",
|
|
8
|
+
"See web/login/src/lib/config.ts."
|
|
9
|
+
],
|
|
10
|
+
|
|
11
|
+
"hostedAuthProvider": "openfort",
|
|
12
|
+
|
|
13
|
+
"devMnemonic": "test test test test test test test test test test test junk",
|
|
14
|
+
|
|
15
|
+
"openfort": {
|
|
16
|
+
"publishableKey": "",
|
|
17
|
+
"shieldPublishableKey": "",
|
|
18
|
+
"encryptionSessionEndpoint": ""
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
"allowLoopbackRequesters": true,
|
|
22
|
+
|
|
23
|
+
"originAllowlist": {},
|
|
24
|
+
|
|
25
|
+
"crossOriginAllowlist": {},
|
|
26
|
+
|
|
27
|
+
"autoSignedLifetimeSeconds": 7776000,
|
|
28
|
+
|
|
29
|
+
"promptedLifetimeSeconds": 0
|
|
30
|
+
}
|
package/lib/server.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The static server the bin puts on a port.
|
|
3
|
+
*
|
|
4
|
+
* Zero dependencies on purpose: this is the thing an adopter starts in their dev script and in CI,
|
|
5
|
+
* next to their faucet, and every dependency it has is one more thing that can stop their CI for a
|
|
6
|
+
* reason that has nothing to do with them.
|
|
7
|
+
*
|
|
8
|
+
* It is a static file server with three opinions:
|
|
9
|
+
*
|
|
10
|
+
* 1. NEVER falls back to index.html for a missing path. The host asks for `/config.json` and treats
|
|
11
|
+
* an HTML answer as "no document", so a server that helpfully returns the app for every path
|
|
12
|
+
* turns a typo in a filename into a configuration that silently did nothing.
|
|
13
|
+
* 2. Answers with `cache-control: no-store`. The whole point of the runtime document is that you
|
|
14
|
+
* edit it and reload; a cached bundle or a cached document makes that a lie.
|
|
15
|
+
* 3. Reads the configuration document on every request rather than at startup, so editing it and
|
|
16
|
+
* reloading the popup is the whole loop.
|
|
17
|
+
*
|
|
18
|
+
* Separate from the bin so the tests exercise the server without spawning a process, and so the bin
|
|
19
|
+
* has no "am I the entry point" question to get wrong.
|
|
20
|
+
*/
|
|
21
|
+
import {createServer} from 'node:http';
|
|
22
|
+
import {createReadStream} from 'node:fs';
|
|
23
|
+
import {readFile, stat} from 'node:fs/promises';
|
|
24
|
+
import {extname, join, resolve, sep} from 'node:path';
|
|
25
|
+
import {fileURLToPath} from 'node:url';
|
|
26
|
+
|
|
27
|
+
export const DEFAULT_DIR = resolve(fileURLToPath(new URL('.', import.meta.url)), '../site');
|
|
28
|
+
export const DEFAULT_PORT = 50000;
|
|
29
|
+
|
|
30
|
+
const MIME = {
|
|
31
|
+
'.html': 'text/html; charset=utf-8',
|
|
32
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
33
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
34
|
+
'.css': 'text/css; charset=utf-8',
|
|
35
|
+
'.json': 'application/json; charset=utf-8',
|
|
36
|
+
'.map': 'application/json; charset=utf-8',
|
|
37
|
+
'.svg': 'image/svg+xml',
|
|
38
|
+
'.png': 'image/png',
|
|
39
|
+
'.jpg': 'image/jpeg',
|
|
40
|
+
'.jpeg': 'image/jpeg',
|
|
41
|
+
'.gif': 'image/gif',
|
|
42
|
+
'.ico': 'image/x-icon',
|
|
43
|
+
'.webp': 'image/webp',
|
|
44
|
+
'.woff': 'font/woff',
|
|
45
|
+
'.woff2': 'font/woff2',
|
|
46
|
+
'.txt': 'text/plain; charset=utf-8',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Inside the served root, and provably so: `..` in a URL must not reach the rest of the disk. */
|
|
50
|
+
function resolveWithin(root, pathname) {
|
|
51
|
+
const target = resolve(join(root, pathname));
|
|
52
|
+
if (target !== root && !target.startsWith(root + sep)) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createHost(options) {
|
|
59
|
+
const root = resolve(options.dir || DEFAULT_DIR);
|
|
60
|
+
return createServer(async (request, response) => {
|
|
61
|
+
try {
|
|
62
|
+
await handle(request, response, root, options);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
// AN UNCAUGHT THROW IN AN ASYNC HANDLER IS AN UNHANDLED REJECTION, and on Node 18+ that
|
|
65
|
+
// ends the process. This one is somebody's dev script and somebody's CI, where a server
|
|
66
|
+
// that vanishes mid-run reads as a flaky test rather than as a bug here.
|
|
67
|
+
console.error(`[dev-wallet-host] ${request.method} ${request.url} failed: ${err?.stack || err}`);
|
|
68
|
+
if (!response.headersSent) {
|
|
69
|
+
response.writeHead(500, {'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store'});
|
|
70
|
+
}
|
|
71
|
+
response.end('the development wallet host failed to answer this request; see its console');
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function handle(request, response, root, options) {
|
|
77
|
+
const send = (status, body, type = 'text/plain; charset=utf-8') => {
|
|
78
|
+
response.writeHead(status, {'content-type': type, 'cache-control': 'no-store'});
|
|
79
|
+
response.end(body);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
let pathname;
|
|
83
|
+
try {
|
|
84
|
+
pathname = decodeURIComponent(new URL(request.url, 'http://localhost').pathname);
|
|
85
|
+
} catch {
|
|
86
|
+
return send(400, 'bad request');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The runtime configuration document, from wherever the developer keeps it.
|
|
90
|
+
if (pathname === '/config.json' && options.config) {
|
|
91
|
+
try {
|
|
92
|
+
const body = await readFile(options.config);
|
|
93
|
+
return send(200, body, MIME['.json']);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
console.error(`[dev-wallet-host] could not read ${options.config}: ${err.message}`);
|
|
96
|
+
return send(500, 'the configuration document could not be read');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (pathname.endsWith('/')) {
|
|
101
|
+
pathname += 'index.html';
|
|
102
|
+
}
|
|
103
|
+
const file = resolveWithin(root, pathname);
|
|
104
|
+
if (!file) {
|
|
105
|
+
return send(403, 'forbidden');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let info;
|
|
109
|
+
try {
|
|
110
|
+
info = await stat(file);
|
|
111
|
+
} catch {
|
|
112
|
+
// DELIBERATELY NOT index.html. See the header of this file: a fallback here turns a missing
|
|
113
|
+
// configuration document into one that silently did nothing.
|
|
114
|
+
return send(404, `not found: ${pathname}`);
|
|
115
|
+
}
|
|
116
|
+
if (info.isDirectory()) {
|
|
117
|
+
// RE-ENCODED. `pathname` was decoded on the way in, so putting it back verbatim would emit a
|
|
118
|
+
// header with raw spaces or control characters in it, which Node rejects by throwing.
|
|
119
|
+
const location = `${pathname.split('/').map(encodeURIComponent).join('/')}/`;
|
|
120
|
+
response.writeHead(302, {location, 'cache-control': 'no-store'});
|
|
121
|
+
return response.end();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
response.writeHead(200, {
|
|
125
|
+
'content-type': MIME[extname(file)] || 'application/octet-stream',
|
|
126
|
+
'content-length': info.size,
|
|
127
|
+
'cache-control': 'no-store',
|
|
128
|
+
});
|
|
129
|
+
createReadStream(file).pipe(response);
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etherplay/dev-wallet-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The Etherplay sign-in host, prebuilt, for DEVELOPMENT and e2e only - run it next to your app the way you run a faucet. Unfit for real accounts by construction.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"etherplay",
|
|
7
|
+
"development",
|
|
8
|
+
"dev-server",
|
|
9
|
+
"e2e",
|
|
10
|
+
"testing",
|
|
11
|
+
"wallet",
|
|
12
|
+
"sign-in",
|
|
13
|
+
"mnemonic"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/wighawag/etherplay-connect#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/wighawag/etherplay-connect.git",
|
|
19
|
+
"directory": "packages/etherplay-dev-wallet-host"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/wighawag/etherplay-connect/issues"
|
|
23
|
+
},
|
|
24
|
+
"author": "Ronan Sandford",
|
|
25
|
+
"license": "MIT",
|
|
4
26
|
"publishConfig": {
|
|
5
27
|
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"type": "module",
|
|
30
|
+
"bin": {
|
|
31
|
+
"dev-wallet-host": "./bin/dev-wallet-host.js"
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"bin",
|
|
38
|
+
"lib",
|
|
39
|
+
"site",
|
|
40
|
+
"config.example.json"
|
|
41
|
+
],
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=18"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"prettier": "^3.5.3"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "node ./scripts/build.mjs",
|
|
50
|
+
"build:fresh": "node ./scripts/build.mjs --fresh",
|
|
51
|
+
"serve": "node ./bin/dev-wallet-host.js",
|
|
52
|
+
"test": "node --test test/*.test.mjs",
|
|
53
|
+
"verify:adopter": "node ./scripts/verify-adopter-install.mjs",
|
|
54
|
+
"format:check": "prettier --check .",
|
|
55
|
+
"format": "prettier --write ."
|
|
6
56
|
}
|
|
7
|
-
}
|
|
57
|
+
}
|
|
Binary file
|
package/site/README.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
This directory is the Etherplay sign-in host, DEVELOPMENT build.
|
|
2
|
+
|
|
3
|
+
It accepts a runtime configuration document at /config.json and is unfit for real
|
|
4
|
+
accounts by construction. Serve it with `dev-wallet-host`, or with any static server
|
|
5
|
+
that does NOT fall back to index.html for missing paths.
|
|
6
|
+
|
|
7
|
+
An example document to copy and edit lives one level up, at the root of this package:
|
|
8
|
+
node_modules/@etherplay/dev-wallet-host/config.example.json
|
|
9
|
+
Pass yours with `dev-wallet-host --config ./wallet-host.config.json`; it does not have
|
|
10
|
+
to live in here, and is better kept in your own project where you can edit it.
|
|
11
|
+
|
|
12
|
+
https://github.com/wighawag/etherplay-connect
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Completing Sign-In...</title>
|
|
6
|
+
<style>
|
|
7
|
+
body {
|
|
8
|
+
font-family: system-ui, sans-serif;
|
|
9
|
+
padding: 16px;
|
|
10
|
+
}
|
|
11
|
+
#close-button {
|
|
12
|
+
display: none;
|
|
13
|
+
margin-top: 12px;
|
|
14
|
+
padding: 8px 16px;
|
|
15
|
+
font-size: 1rem;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
}
|
|
18
|
+
#debug-log {
|
|
19
|
+
display: none;
|
|
20
|
+
margin-top: 12px;
|
|
21
|
+
white-space: pre-wrap;
|
|
22
|
+
font-family: monospace;
|
|
23
|
+
font-size: 0.8rem;
|
|
24
|
+
background: #f4f4f4;
|
|
25
|
+
padding: 8px;
|
|
26
|
+
border-radius: 4px;
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
29
|
+
<script>
|
|
30
|
+
(function () {
|
|
31
|
+
var LOG = '[etherplay-bridge]';
|
|
32
|
+
var hashParams = new URLSearchParams(window.location.hash.slice(1));
|
|
33
|
+
var queryParams = new URLSearchParams(window.location.search);
|
|
34
|
+
var data = hashParams.get('data');
|
|
35
|
+
var iv = hashParams.get('iv');
|
|
36
|
+
var pubKey = hashParams.get('pubKey');
|
|
37
|
+
var id = hashParams.get('id');
|
|
38
|
+
|
|
39
|
+
// Testing aid: `?forceBroadcastChannel=true` skips the direct opener path
|
|
40
|
+
// so the BroadcastChannel fallback can be exercised even when the opener
|
|
41
|
+
// relationship survived.
|
|
42
|
+
var forceBroadcastChannel = queryParams.get('forceBroadcastChannel') === 'true';
|
|
43
|
+
|
|
44
|
+
// Debug mode: keep this window open (do NOT auto-close on ack or timeout)
|
|
45
|
+
// so the popup can be inspected, mirroring the :50000 login app behavior.
|
|
46
|
+
// A "close" button is shown instead. Activated by `?debug` (any value, even empty).
|
|
47
|
+
var debug = queryParams.has('debug');
|
|
48
|
+
|
|
49
|
+
var debugLogEl = null;
|
|
50
|
+
function log() {
|
|
51
|
+
var args = Array.prototype.slice.call(arguments);
|
|
52
|
+
console.log.apply(console, [LOG].concat(args));
|
|
53
|
+
if (debug && debugLogEl) {
|
|
54
|
+
try {
|
|
55
|
+
debugLogEl.textContent +=
|
|
56
|
+
args
|
|
57
|
+
.map(function (a) {
|
|
58
|
+
return typeof a === 'string' ? a : JSON.stringify(a);
|
|
59
|
+
})
|
|
60
|
+
.join(' ') + '\n';
|
|
61
|
+
} catch (e) {}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function closeWindow() {
|
|
66
|
+
window.close();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function onReady() {
|
|
70
|
+
if (debug) {
|
|
71
|
+
debugLogEl = document.getElementById('debug-log');
|
|
72
|
+
debugLogEl.style.display = 'block';
|
|
73
|
+
var btn = document.getElementById('close-button');
|
|
74
|
+
btn.style.display = 'inline-block';
|
|
75
|
+
btn.addEventListener('click', closeWindow);
|
|
76
|
+
document.getElementById('status').textContent =
|
|
77
|
+
'Debug mode: result delivered. Inspect the console, then click "close".';
|
|
78
|
+
}
|
|
79
|
+
start();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function start() {
|
|
83
|
+
log('loaded', {id: id, forceBroadcastChannel: forceBroadcastChannel, debug: debug, origin: window.origin});
|
|
84
|
+
|
|
85
|
+
if (!(data && iv && pubKey && id)) {
|
|
86
|
+
console.error(LOG, 'missing redirect parameters');
|
|
87
|
+
document.getElementById('status').textContent =
|
|
88
|
+
'Error: missing redirect parameters. You can close this window.';
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var payload = {
|
|
93
|
+
type: 'domain-redirect-result',
|
|
94
|
+
encryptedResult: data,
|
|
95
|
+
iv: iv,
|
|
96
|
+
ephemeralPublicKey: pubKey,
|
|
97
|
+
id: id,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// This page is SAME-ORIGIN with the parent. Two delivery paths are available;
|
|
101
|
+
// try the direct opener first (often re-established once same-origin),
|
|
102
|
+
// then fall back to BroadcastChannel. Parent accepts BOTH.
|
|
103
|
+
var channel = new BroadcastChannel('etherplay-connect');
|
|
104
|
+
|
|
105
|
+
// Close only after the parent acknowledges receipt (avoids dropping the message).
|
|
106
|
+
channel.onmessage = function (event) {
|
|
107
|
+
if (event && event.data && event.data.type === 'ack' && event.data.id === id) {
|
|
108
|
+
if (debug) {
|
|
109
|
+
log('received ack (debug mode: not auto-closing, use the close button)');
|
|
110
|
+
try {
|
|
111
|
+
channel.close();
|
|
112
|
+
} catch (e) {}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
log('received ack, closing');
|
|
116
|
+
try {
|
|
117
|
+
channel.close();
|
|
118
|
+
} catch (e) {}
|
|
119
|
+
closeWindow();
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// Path 1: direct opener (same-origin here, so our own origin is fine).
|
|
124
|
+
if (forceBroadcastChannel) {
|
|
125
|
+
log('forceBroadcastChannel=true -> skipping window.opener.postMessage path');
|
|
126
|
+
} else {
|
|
127
|
+
try {
|
|
128
|
+
if (window.opener && !window.opener.closed) {
|
|
129
|
+
log('delivering via window.opener.postMessage');
|
|
130
|
+
window.opener.postMessage(payload, window.origin);
|
|
131
|
+
} else {
|
|
132
|
+
log('window.opener not available, relying on BroadcastChannel');
|
|
133
|
+
}
|
|
134
|
+
} catch (e) {
|
|
135
|
+
console.warn(LOG, 'window.opener.postMessage failed', e);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Path 2: BroadcastChannel (works even if opener is null).
|
|
140
|
+
log('delivering via BroadcastChannel');
|
|
141
|
+
channel.postMessage(payload);
|
|
142
|
+
|
|
143
|
+
// Safety fallback: close even if no ack arrives. Skipped in debug mode.
|
|
144
|
+
if (!debug) {
|
|
145
|
+
setTimeout(function () {
|
|
146
|
+
log('no ack within timeout, closing anyway');
|
|
147
|
+
try {
|
|
148
|
+
channel.close();
|
|
149
|
+
} catch (e) {}
|
|
150
|
+
closeWindow();
|
|
151
|
+
}, 3000);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (document.readyState === 'loading') {
|
|
156
|
+
document.addEventListener('DOMContentLoaded', onReady);
|
|
157
|
+
} else {
|
|
158
|
+
onReady();
|
|
159
|
+
}
|
|
160
|
+
})();
|
|
161
|
+
</script>
|
|
162
|
+
</head>
|
|
163
|
+
<body>
|
|
164
|
+
<p id="status">Completing sign-in, redirecting back to application...</p>
|
|
165
|
+
<button id="close-button" type="button">close</button>
|
|
166
|
+
<pre id="debug-log"></pre>
|
|
167
|
+
</body>
|
|
168
|
+
</html>
|