@oneaddress/setup 1.1.1 → 1.1.4
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/dist/index.js +98 -47
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -808,7 +808,7 @@ var L2 = () => {
|
|
|
808
808
|
};
|
|
809
809
|
|
|
810
810
|
// src/prompts.ts
|
|
811
|
-
var
|
|
811
|
+
var import_node_crypto4 = require("crypto");
|
|
812
812
|
var import_node_fs4 = require("fs");
|
|
813
813
|
var import_node_os2 = require("os");
|
|
814
814
|
var import_node_path5 = require("path");
|
|
@@ -821,13 +821,11 @@ var CRM = "\x1B[38;2;245;238;216m";
|
|
|
821
821
|
var FNT = "\x1B[38;2;130;100;45m";
|
|
822
822
|
var DIM = "\x1B[38;2;70;58;35m";
|
|
823
823
|
var MID = "\x1B[38;2;155;135;100m";
|
|
824
|
-
var GRN = "\x1B[38;2;80;200;120m";
|
|
825
824
|
var ab = (s) => `${B2}${AMB}${s}${R3}`;
|
|
826
825
|
var wb = (s) => `${B2}${CRM}${s}${R3}`;
|
|
827
826
|
var fn = (s) => `${FNT}${s}${R3}`;
|
|
828
827
|
var dm = (s) => `${DIM}${s}${R3}`;
|
|
829
828
|
var mi = (s) => `${MID}${s}${R3}`;
|
|
830
|
-
var gn = (s) => `${GRN}${s}${R3}`;
|
|
831
829
|
var _O = [" \u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588", " \u2588\u2588\u2588\u2588\u2588 "];
|
|
832
830
|
var _N = ["\u2588\u2588 \u2588\u2588", "\u2588\u2588\u2588 \u2588\u2588", "\u2588\u2588\u2588\u2588 \u2588\u2588", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588", "\u2588\u2588 \u2588\u2588\u2588\u2588", "\u2588\u2588 \u2588\u2588\u2588", "\u2588\u2588 \u2588\u2588"];
|
|
833
831
|
var _E = ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588", "\u2588\u2588 ", "\u2588\u2588 ", "\u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 ", "\u2588\u2588 ", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588"];
|
|
@@ -837,8 +835,9 @@ var _R = ["\u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 \u2588\u2588"
|
|
|
837
835
|
var _S = [" \u2588\u2588\u2588\u2588\u2588\u2588", "\u2588\u2588 ", "\u2588\u2588 ", " \u2588\u2588\u2588\u2588\u2588 ", " \u2588\u2588", " \u2588\u2588", "\u2588\u2588\u2588\u2588\u2588\u2588 "];
|
|
838
836
|
var ONE_ROWS = Array.from({ length: 7 }, (_2, i) => [_O[i], _N[i], _E[i]].join(" "));
|
|
839
837
|
var ADDR_ROWS = Array.from({ length: 7 }, (_2, i) => [_A[i], _D2[i], _D2[i], _R[i], _E[i], _S[i], _S[i]].join(" "));
|
|
838
|
+
var WIZARD_VERSION = true ? "1.1.4" : "?";
|
|
840
839
|
function printHeader() {
|
|
841
|
-
const BAR_LEN =
|
|
840
|
+
const BAR_LEN = 85;
|
|
842
841
|
const TOP_BAR = fn("\u250C") + dm("\u2500".repeat(BAR_LEN)) + fn("\u2510");
|
|
843
842
|
const BOT_BAR = fn("\u2514") + dm("\u2500".repeat(BAR_LEN)) + fn("\u2518");
|
|
844
843
|
const SIDE = dm("\u2502");
|
|
@@ -847,13 +846,13 @@ function printHeader() {
|
|
|
847
846
|
console.log(` ${SIDE}${" ".repeat(BAR_LEN)}${SIDE}`);
|
|
848
847
|
for (let i = 0; i < 7; i++) {
|
|
849
848
|
const line = wb(ONE_ROWS[i]) + " " + ab(ADDR_ROWS[i]);
|
|
850
|
-
console.log(`
|
|
849
|
+
console.log(` ${SIDE} ${line} ${SIDE}`);
|
|
851
850
|
}
|
|
852
|
-
console.log(`
|
|
851
|
+
console.log(` ${SIDE} ${fn("\u2591".repeat(81))} ${SIDE}`);
|
|
853
852
|
console.log(` ${SIDE}${" ".repeat(BAR_LEN)}${SIDE}`);
|
|
854
853
|
const wizard = mi("Partner Setup Wizard");
|
|
855
|
-
const
|
|
856
|
-
const tagLine = ` ${wizard} ${
|
|
854
|
+
const ver = fn(`v${WIZARD_VERSION} \xB7 partners.oneaddress.io`);
|
|
855
|
+
const tagLine = ` ${wizard} ${ver}`;
|
|
857
856
|
const padLen = BAR_LEN - 4 - stripAnsi(tagLine).length;
|
|
858
857
|
console.log(` ${SIDE} ${tagLine}${" ".repeat(Math.max(0, padLen))} ${SIDE}`);
|
|
859
858
|
console.log(` ${SIDE}${" ".repeat(BAR_LEN)}${SIDE}`);
|
|
@@ -2934,25 +2933,72 @@ async function registerInstall(installId, partnerId, webhookSecret, platform, we
|
|
|
2934
2933
|
}
|
|
2935
2934
|
|
|
2936
2935
|
// src/conformance.ts
|
|
2937
|
-
var
|
|
2938
|
-
function runConformance(webhookUrl,
|
|
2939
|
-
(
|
|
2940
|
-
"
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
"
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2936
|
+
var import_node_crypto2 = require("crypto");
|
|
2937
|
+
async function runConformance(webhookUrl, _partnerId, webhookSecret) {
|
|
2938
|
+
function sign(ts, body) {
|
|
2939
|
+
return (0, import_node_crypto2.createHmac)("sha256", webhookSecret).update(`${ts}.${body}`).digest("hex");
|
|
2940
|
+
}
|
|
2941
|
+
const validBody = JSON.stringify({ event: "conformance.ping", test: true });
|
|
2942
|
+
const now = String(Math.floor(Date.now() / 1e3));
|
|
2943
|
+
const staleTs = String(Math.floor(Date.now() / 1e3) - 400);
|
|
2944
|
+
const tests = [
|
|
2945
|
+
{
|
|
2946
|
+
name: "Replay attack rejected (stale timestamp)",
|
|
2947
|
+
ts: staleTs,
|
|
2948
|
+
sig: sign(staleTs, validBody),
|
|
2949
|
+
expectOk: false
|
|
2950
|
+
},
|
|
2951
|
+
{
|
|
2952
|
+
name: "Bad signature rejected",
|
|
2953
|
+
ts: now,
|
|
2954
|
+
sig: "deadbeef".repeat(8),
|
|
2955
|
+
expectOk: false
|
|
2956
|
+
},
|
|
2957
|
+
{
|
|
2958
|
+
name: "Valid signed request accepted",
|
|
2959
|
+
ts: now,
|
|
2960
|
+
sig: sign(now, validBody),
|
|
2961
|
+
expectOk: true
|
|
2962
|
+
}
|
|
2963
|
+
];
|
|
2964
|
+
let passed = 0;
|
|
2965
|
+
let failed = 0;
|
|
2966
|
+
for (const t of tests) {
|
|
2967
|
+
try {
|
|
2968
|
+
const res = await fetch(webhookUrl, {
|
|
2969
|
+
method: "POST",
|
|
2970
|
+
headers: {
|
|
2971
|
+
"Content-Type": "application/json",
|
|
2972
|
+
"X-OneAddress-Timestamp": t.ts,
|
|
2973
|
+
"X-OneAddress-Signature": t.sig,
|
|
2974
|
+
"X-OneAddress-Dispatch": "0"
|
|
2975
|
+
},
|
|
2976
|
+
body: validBody,
|
|
2977
|
+
signal: AbortSignal.timeout(8e3)
|
|
2978
|
+
});
|
|
2979
|
+
const gotOk = res.ok;
|
|
2980
|
+
const pass = t.expectOk ? gotOk : !gotOk;
|
|
2981
|
+
if (pass) {
|
|
2982
|
+
v2.success(` \u2713 ${t.name} (${res.status})`);
|
|
2983
|
+
passed++;
|
|
2984
|
+
} else {
|
|
2985
|
+
v2.warn(` \u2717 ${t.name} (${res.status} \u2014 expected ${t.expectOk ? "2xx" : "4xx"})`);
|
|
2986
|
+
failed++;
|
|
2987
|
+
}
|
|
2988
|
+
} catch (err) {
|
|
2989
|
+
v2.warn(` \u2717 ${t.name} (network error: ${err instanceof Error ? err.message : String(err)})`);
|
|
2990
|
+
failed++;
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
if (failed === 0) {
|
|
2994
|
+
v2.success(`Conformance passed ${passed}/${tests.length} \u2014 your endpoint is correctly secured.`);
|
|
2995
|
+
} else {
|
|
2996
|
+
v2.warn(`Conformance: ${passed}/${tests.length} passed. Check your WEBHOOK_SECRET and timestamp enforcement.`);
|
|
2997
|
+
}
|
|
2952
2998
|
}
|
|
2953
2999
|
|
|
2954
3000
|
// src/install.ts
|
|
2955
|
-
var
|
|
3001
|
+
var import_node_child_process = require("child_process");
|
|
2956
3002
|
var import_node_fs2 = require("fs");
|
|
2957
3003
|
var import_node_path2 = require("path");
|
|
2958
3004
|
var COMMANDS = {
|
|
@@ -2979,7 +3025,7 @@ function installDependencies(platform, outputDir) {
|
|
|
2979
3025
|
}
|
|
2980
3026
|
const cwd = spec.cwd ? (0, import_node_path2.join)(outputDir, spec.cwd) : outputDir;
|
|
2981
3027
|
const manualCommand = `cd ${outputDir} && ${spec.cmd} ${spec.args.join(" ")}`;
|
|
2982
|
-
const result = (0,
|
|
3028
|
+
const result = (0, import_node_child_process.spawnSync)(spec.cmd, spec.args, {
|
|
2983
3029
|
cwd,
|
|
2984
3030
|
stdio: "pipe",
|
|
2985
3031
|
encoding: "utf8",
|
|
@@ -2996,7 +3042,7 @@ function installDependencies(platform, outputDir) {
|
|
|
2996
3042
|
}
|
|
2997
3043
|
|
|
2998
3044
|
// src/autostart.ts
|
|
2999
|
-
var
|
|
3045
|
+
var import_node_child_process2 = require("child_process");
|
|
3000
3046
|
var import_node_path3 = require("path");
|
|
3001
3047
|
var import_node_fs3 = require("fs");
|
|
3002
3048
|
var COMMANDS2 = {
|
|
@@ -3012,7 +3058,14 @@ var serverOutput = "";
|
|
|
3012
3058
|
function stopServer() {
|
|
3013
3059
|
if (serverProcess) {
|
|
3014
3060
|
try {
|
|
3015
|
-
|
|
3061
|
+
if (process.platform === "win32" && serverProcess.pid) {
|
|
3062
|
+
(0, import_node_child_process2.spawn)("taskkill", ["/F", "/T", "/PID", String(serverProcess.pid)], {
|
|
3063
|
+
stdio: "ignore",
|
|
3064
|
+
detached: true
|
|
3065
|
+
});
|
|
3066
|
+
} else {
|
|
3067
|
+
serverProcess.kill("SIGTERM");
|
|
3068
|
+
}
|
|
3016
3069
|
} catch {
|
|
3017
3070
|
}
|
|
3018
3071
|
serverProcess = null;
|
|
@@ -3062,7 +3115,7 @@ async function startServer(platform, outputDir, port = 3001) {
|
|
|
3062
3115
|
}
|
|
3063
3116
|
serverOutput = "";
|
|
3064
3117
|
const manualCommand = `cd ${outputDir} && ${spec.cmd} ${spec.args.join(" ")}`;
|
|
3065
|
-
serverProcess = (0,
|
|
3118
|
+
serverProcess = (0, import_node_child_process2.spawn)(spec.cmd, spec.args, {
|
|
3066
3119
|
cwd: outputDir,
|
|
3067
3120
|
stdio: ["ignore", "pipe", "pipe"],
|
|
3068
3121
|
detached: false,
|
|
@@ -3084,7 +3137,7 @@ async function startServer(platform, outputDir, port = 3001) {
|
|
|
3084
3137
|
}
|
|
3085
3138
|
|
|
3086
3139
|
// src/tunnel.ts
|
|
3087
|
-
var
|
|
3140
|
+
var import_node_child_process3 = require("child_process");
|
|
3088
3141
|
var import_promises2 = require("fs/promises");
|
|
3089
3142
|
var import_node_path4 = require("path");
|
|
3090
3143
|
var import_node_os = __toESM(require("os"));
|
|
@@ -3120,7 +3173,7 @@ async function downloadCloudflared() {
|
|
|
3120
3173
|
}
|
|
3121
3174
|
async function resolveBinary() {
|
|
3122
3175
|
try {
|
|
3123
|
-
(0,
|
|
3176
|
+
(0, import_node_child_process3.execSync)("cloudflared --version", { stdio: "pipe" });
|
|
3124
3177
|
return "cloudflared";
|
|
3125
3178
|
} catch {
|
|
3126
3179
|
}
|
|
@@ -3129,7 +3182,7 @@ async function resolveBinary() {
|
|
|
3129
3182
|
async function startTunnel(port) {
|
|
3130
3183
|
const binary = await resolveBinary();
|
|
3131
3184
|
return new Promise((resolve2, reject) => {
|
|
3132
|
-
tunnelProcess = (0,
|
|
3185
|
+
tunnelProcess = (0, import_node_child_process3.spawn)(binary, ["tunnel", "--url", `http://localhost:${port}`], {
|
|
3133
3186
|
stdio: ["ignore", "pipe", "pipe"]
|
|
3134
3187
|
});
|
|
3135
3188
|
let resolved = false;
|
|
@@ -3168,13 +3221,13 @@ async function startTunnel(port) {
|
|
|
3168
3221
|
}
|
|
3169
3222
|
|
|
3170
3223
|
// src/register-url.ts
|
|
3171
|
-
var
|
|
3224
|
+
var import_node_crypto3 = require("crypto");
|
|
3172
3225
|
var PORTAL_API = "https://partners.oneaddress.io/api/partner/webhook-url";
|
|
3173
3226
|
async function registerWebhookUrl(partnerId, webhookSecret, webhookUrl) {
|
|
3174
3227
|
try {
|
|
3175
3228
|
const body = JSON.stringify({ webhook_url: webhookUrl });
|
|
3176
3229
|
const ts = String(Math.floor(Date.now() / 1e3));
|
|
3177
|
-
const sig = (0,
|
|
3230
|
+
const sig = (0, import_node_crypto3.createHmac)("sha256", webhookSecret).update(`${ts}.${body}`).digest("hex");
|
|
3178
3231
|
const res = await fetch(PORTAL_API, {
|
|
3179
3232
|
method: "PATCH",
|
|
3180
3233
|
headers: {
|
|
@@ -3197,7 +3250,7 @@ var R4 = "\x1B[0m";
|
|
|
3197
3250
|
var AMB2 = "\x1B[38;2;224;162;72m";
|
|
3198
3251
|
var MID2 = "\x1B[38;2;155;135;100m";
|
|
3199
3252
|
var DIM2 = "\x1B[38;2;70;58;35m";
|
|
3200
|
-
var
|
|
3253
|
+
var GRN = "\x1B[38;2;80;200;120m";
|
|
3201
3254
|
var CRM2 = "\x1B[1m\x1B[38;2;245;238;216m";
|
|
3202
3255
|
var cleanupFns = [];
|
|
3203
3256
|
function onCleanup(fn2) {
|
|
@@ -3274,7 +3327,7 @@ function normalisePrivateKey(raw) {
|
|
|
3274
3327
|
}
|
|
3275
3328
|
function validatePkcs8Pem(pem) {
|
|
3276
3329
|
try {
|
|
3277
|
-
(0,
|
|
3330
|
+
(0, import_node_crypto4.createPrivateKey)({ key: pem, format: "pem", type: "pkcs8" });
|
|
3278
3331
|
return void 0;
|
|
3279
3332
|
} catch (err) {
|
|
3280
3333
|
return `Key validation failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
@@ -3378,7 +3431,7 @@ async function main() {
|
|
|
3378
3431
|
process.exit(1);
|
|
3379
3432
|
}
|
|
3380
3433
|
const s2 = L2();
|
|
3381
|
-
s2.start("Installing dependencies\u2026");
|
|
3434
|
+
s2.start("Installing dependencies (this can take 30\u201360 s)\u2026");
|
|
3382
3435
|
const install = installDependencies(platform, outDir);
|
|
3383
3436
|
if (install.ok) {
|
|
3384
3437
|
s2.stop("Dependencies installed");
|
|
@@ -3454,7 +3507,7 @@ async function main() {
|
|
|
3454
3507
|
);
|
|
3455
3508
|
}
|
|
3456
3509
|
registerInstall(
|
|
3457
|
-
`OA-${(0,
|
|
3510
|
+
`OA-${(0, import_node_crypto4.randomUUID)()}`,
|
|
3458
3511
|
pid,
|
|
3459
3512
|
secret,
|
|
3460
3513
|
platform,
|
|
@@ -3462,15 +3515,13 @@ async function main() {
|
|
|
3462
3515
|
).catch(() => {
|
|
3463
3516
|
});
|
|
3464
3517
|
}
|
|
3465
|
-
if (webhookUrl
|
|
3466
|
-
v2.info("
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
v2.info("\nOnce your endpoint is live, run the conformance check:");
|
|
3473
|
-
v2.info(" npx @oneaddress/conformance test <your-https-url>/webhook");
|
|
3518
|
+
if (webhookUrl) {
|
|
3519
|
+
v2.info("");
|
|
3520
|
+
const s6 = L2();
|
|
3521
|
+
s6.start("Running conformance checks\u2026");
|
|
3522
|
+
await new Promise((r2) => setTimeout(r2, 200));
|
|
3523
|
+
s6.stop("Conformance checks:");
|
|
3524
|
+
await runConformance(webhookUrl, pid, secret);
|
|
3474
3525
|
}
|
|
3475
3526
|
const summary = [
|
|
3476
3527
|
`Partner ID: ${pid}`,
|
|
@@ -3490,7 +3541,7 @@ async function main() {
|
|
|
3490
3541
|
if (serverRunning) {
|
|
3491
3542
|
console.log("");
|
|
3492
3543
|
console.log(` ${DIM2}\u250C${"\u2500".repeat(56)}\u2510${R4}`);
|
|
3493
|
-
console.log(` ${DIM2}\u2502${R4} ${
|
|
3544
|
+
console.log(` ${DIM2}\u2502${R4} ${GRN}\u25C8${R4} ${CRM2}Server live${R4} ${MID2}on http://localhost:3001/webhook${R4} ${DIM2}\u2502${R4}`);
|
|
3494
3545
|
console.log(` ${DIM2}\u2502${R4} ${AMB2}\u25C8${R4} ${MID2}Edit ${CRM2}src/store.ts${R4} ${MID2}to wire your database${R4} ${DIM2}\u2502${R4}`);
|
|
3495
3546
|
console.log(` ${DIM2}\u2502${R4} ${MID2}Press Ctrl+C to stop the server and exit.${R4} ${DIM2} \u2502${R4}`);
|
|
3496
3547
|
console.log(` ${DIM2}\u2514${"\u2500".repeat(56)}\u2518${R4}`);
|