@oneaddress/conformance 2.1.0 → 3.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 +24 -3
- package/dist/index.js +293 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,17 +77,38 @@ oneaddress-conformance test https://api.mycompany.com/oneaddress \
|
|
|
77
77
|
oneaddress-conformance test https://api.mycompany.com/oneaddress \
|
|
78
78
|
--secret whsec_xxx \
|
|
79
79
|
--partner-id aaa... \
|
|
80
|
+
--public-key <base64-SPKI-of-your-ECDH-public-key> \
|
|
80
81
|
--customer-url https://oneaddress.io
|
|
81
82
|
```
|
|
82
83
|
|
|
84
|
+
**All three credentials, or none.** A partial set is refused, and the refusal is
|
|
85
|
+
the point: supplying only the secret makes every signature check pass while the
|
|
86
|
+
payload stays sealed to this suite's built-in test key, so the failures land on
|
|
87
|
+
the acceptance checks and read as a decrypt fault in your receiver. Supplying
|
|
88
|
+
none is correct against a `npx @oneaddress/setup` scaffold, which is built
|
|
89
|
+
around those same test values. `--customer-url` only *adds* checks 9 and 10; the
|
|
90
|
+
webhook checks still encrypt to `--public-key`, which is why it belongs in the
|
|
91
|
+
pull-API example too.
|
|
92
|
+
|
|
93
|
+
The safer way to pass them keeps the secret out of your shell history and out of
|
|
94
|
+
`ps`, where any other process on the box can read it:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
export ONEADDRESS_WEBHOOK_SECRET=whsec_xxx
|
|
98
|
+
export ONEADDRESS_PARTNER_ID=aaa...
|
|
99
|
+
export ONEADDRESS_PUBLIC_KEY=MFkw...
|
|
100
|
+
oneaddress-conformance test https://api.mycompany.com/oneaddress --accept address,phone
|
|
101
|
+
```
|
|
102
|
+
|
|
83
103
|
### Flags
|
|
84
104
|
|
|
85
105
|
| Flag | Default | Purpose |
|
|
86
106
|
|------|---------|---------|
|
|
87
|
-
| `--secret` | Built-in synthetic test secret (used when partner is testing the wizard scaffold) | Your HMAC webhook secret |
|
|
88
|
-
| `--partner-id` | Built-in test UUID | Your partner UUID |
|
|
89
|
-
| `--public-key` | Built-in test ECDH SPKI | Your ECDH P-256 public key, base64 SPKI |
|
|
107
|
+
| `--secret` | Built-in synthetic test secret (used when partner is testing the wizard scaffold) | Your HMAC webhook secret. Also `ONEADDRESS_WEBHOOK_SECRET`. **Give all three of these or none** — a partial set is refused |
|
|
108
|
+
| `--partner-id` | Built-in test UUID | Your partner UUID. Also `ONEADDRESS_PARTNER_ID` |
|
|
109
|
+
| `--public-key` | Built-in test ECDH SPKI | Your ECDH P-256 public key, base64 SPKI. Also `ONEADDRESS_PUBLIC_KEY` |
|
|
90
110
|
| `--customer-url` | — | Customer-app base URL; when set, adds pull-API checks |
|
|
111
|
+
| `--account-ref` | `CONF-0001` | The account reference every matching probe carries. Also `ONEADDRESS_ACCOUNT_REF`. Matters only if your receiver matches dispatches to your own customer records: it holds no `CONF-0001`, so it answers `no_match` — correctly — and the run cannot go green however good it is. Point this at a customer you already hold rather than writing test data into your system of record. The no-match probe does **not** derive from it; it sends `CONF-NOSUCH-<nonce>`, which cannot exist whatever you configure here |
|
|
91
112
|
| `--accept` | `address` | Comma-separated update kinds you accept in the partner portal (`address,phone,email`). Adds one contact probe per kind and is compared against what your receiver declares. Match it to the portal: the portal governs what OneAddress sends, this governs what gets tested. |
|
|
92
113
|
|
|
93
114
|
## Exit codes
|
package/dist/index.js
CHANGED
|
@@ -3294,6 +3294,63 @@ function kindProbePlan(declaration, acceptedInPortal) {
|
|
|
3294
3294
|
return { accept, refuse: undeclared ?? UNDEFINED_PROBE_KIND, consentBeyondDeclaration };
|
|
3295
3295
|
}
|
|
3296
3296
|
|
|
3297
|
+
// ../protocol/src/d5-body.ts
|
|
3298
|
+
var D5_BODY_ALWAYS = [
|
|
3299
|
+
"event",
|
|
3300
|
+
"id_verification",
|
|
3301
|
+
"key_share_expiry",
|
|
3302
|
+
"oneaddress_version",
|
|
3303
|
+
"partner_id",
|
|
3304
|
+
"session_envelope",
|
|
3305
|
+
"session_key_share",
|
|
3306
|
+
"stripe_session_id",
|
|
3307
|
+
"timestamp",
|
|
3308
|
+
"update_id",
|
|
3309
|
+
"user_id"
|
|
3310
|
+
];
|
|
3311
|
+
var D5_BODY_CONDITIONAL = {
|
|
3312
|
+
/**
|
|
3313
|
+
* The signed Letter of Authority, sealed to the same key_id as the session.
|
|
3314
|
+
* Present whenever the partner has a usable key — i.e. on every dispatch a
|
|
3315
|
+
* live partner receives. Omitted best-effort when no key is available, which
|
|
3316
|
+
* is a state a live partner is never in.
|
|
3317
|
+
*/
|
|
3318
|
+
loa_encrypted: "partner has a usable encryption key",
|
|
3319
|
+
/**
|
|
3320
|
+
* The shared webhook event id. Set ONLY on a key-crossover copy, where every
|
|
3321
|
+
* copy of one update carries the same id so a receiver holding more than one
|
|
3322
|
+
* rotation key applies it once. Absent on an ordinary dispatch, whose
|
|
3323
|
+
* receiver idempotency falls back to the `X-OneAddress-Dispatch` header.
|
|
3324
|
+
*/
|
|
3325
|
+
id: "key-crossover copy only",
|
|
3326
|
+
/** The sibling marker naming the other key_ids this update was sealed to. */
|
|
3327
|
+
crossover_key_ids: "key-crossover copy only"
|
|
3328
|
+
};
|
|
3329
|
+
var D5_BODY_DRILL_ONLY = ["conformance"];
|
|
3330
|
+
var D5_BODY_ALL_ALLOWED = [
|
|
3331
|
+
...D5_BODY_ALWAYS,
|
|
3332
|
+
...Object.keys(D5_BODY_CONDITIONAL),
|
|
3333
|
+
...D5_BODY_DRILL_ONLY
|
|
3334
|
+
];
|
|
3335
|
+
|
|
3336
|
+
// ../protocol/src/retention.ts
|
|
3337
|
+
var MIN_RETENTION_DAYS = 14;
|
|
3338
|
+
var MAX_RETENTION_DAYS = 365;
|
|
3339
|
+
var DEFAULT_RETENTION_DAYS = 90;
|
|
3340
|
+
function resolveRetentionDays(retentionPeriodDays) {
|
|
3341
|
+
if (typeof retentionPeriodDays !== "number" || !Number.isFinite(retentionPeriodDays)) {
|
|
3342
|
+
return DEFAULT_RETENTION_DAYS;
|
|
3343
|
+
}
|
|
3344
|
+
const days = Math.trunc(retentionPeriodDays);
|
|
3345
|
+
if (days < MIN_RETENTION_DAYS || days > MAX_RETENTION_DAYS) return DEFAULT_RETENTION_DAYS;
|
|
3346
|
+
return days;
|
|
3347
|
+
}
|
|
3348
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
3349
|
+
function keyShareExpiryIso(dispatchAt, retentionPeriodDays) {
|
|
3350
|
+
const days = resolveRetentionDays(retentionPeriodDays);
|
|
3351
|
+
return new Date(dispatchAt.getTime() + days * DAY_MS).toISOString();
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3297
3354
|
// src/credentials.ts
|
|
3298
3355
|
var TEST_WEBHOOK_SECRET = (
|
|
3299
3356
|
// NOSONAR — intentional test credential, not a real secret
|
|
@@ -3317,7 +3374,12 @@ function buildHeaders(partnerId, timestamp, signature, dispatchId, event = "addr
|
|
|
3317
3374
|
"X-OneAddress-Dispatch": dispatchId
|
|
3318
3375
|
};
|
|
3319
3376
|
}
|
|
3320
|
-
|
|
3377
|
+
var DEFAULT_ACCOUNT_REF = "CONF-0001";
|
|
3378
|
+
var CONFORMANCE_USER_ID = "conformance:drill";
|
|
3379
|
+
function conformanceUpdateId() {
|
|
3380
|
+
return import_node_crypto.default.randomInt(9e8, 901e6);
|
|
3381
|
+
}
|
|
3382
|
+
async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address", identity, retentionPeriodDays = DEFAULT_RETENTION_DAYS) {
|
|
3321
3383
|
const partnerKey = {
|
|
3322
3384
|
partner_id: partnerId,
|
|
3323
3385
|
key_id: "conformance-key-1",
|
|
@@ -3325,7 +3387,8 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
|
|
|
3325
3387
|
algorithm: "ECDH-P256-AES-GCM-256"
|
|
3326
3388
|
};
|
|
3327
3389
|
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
3328
|
-
const
|
|
3390
|
+
const updateIdNum = conformanceUpdateId();
|
|
3391
|
+
const updateUid = String(updateIdNum);
|
|
3329
3392
|
const sessionData = {
|
|
3330
3393
|
v: 2,
|
|
3331
3394
|
update_uid: updateUid,
|
|
@@ -3343,7 +3406,7 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
|
|
|
3343
3406
|
...kind === "phone" ? { new_phone: "+61412345678" } : {},
|
|
3344
3407
|
...kind === "email" ? { new_email: "conformance@example.com" } : {},
|
|
3345
3408
|
update_types: [kind],
|
|
3346
|
-
account_number:
|
|
3409
|
+
account_number: DEFAULT_ACCOUNT_REF,
|
|
3347
3410
|
id_verification_ref: import_node_crypto.default.randomUUID(),
|
|
3348
3411
|
known_names: ["Conformance Tester"],
|
|
3349
3412
|
// Applied last so an override wins over the defaults above, including
|
|
@@ -3368,20 +3431,54 @@ async function buildBody(partnerId, publicKeyB64, extraFields, kind = "address",
|
|
|
3368
3431
|
// bearing dispatch stays `address.updated` for every existing integration.
|
|
3369
3432
|
event: kind === "address" ? "address.updated" : "contact.updated",
|
|
3370
3433
|
oneaddress_version: CURRENT_VERSION,
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3434
|
+
/**
|
|
3435
|
+
* ── THIS LIST IS THE D5 CONTRACT (`D5_BODY_ALWAYS`), NOT AN APPROXIMATION ─
|
|
3436
|
+
*
|
|
3437
|
+
* Measured on 25 Sep 2026 by executing this builder beside the relay's own
|
|
3438
|
+
* `composeD5OutgoingPayload`, it sent `version`, `id` and
|
|
3439
|
+
* `encryption_status`, which no D5 dispatch carries; omitted `user_id`,
|
|
3440
|
+
* `key_share_expiry`, `id_verification` and `stripe_session_id`, which every
|
|
3441
|
+
* one carries; sent `update_id` as a UUID where the relay sends the integer
|
|
3442
|
+
* `user_updates.id`; and sent `timestamp` as Unix-epoch seconds where the
|
|
3443
|
+
* relay sends ISO 8601 — the header's format, in the body, which is how the
|
|
3444
|
+
* mistake happened.
|
|
3445
|
+
*
|
|
3446
|
+
* Three of those fail in the silent direction. A receiver gated on
|
|
3447
|
+
* `encryption_status === 'encrypted'`, pinned to `body.version`, or keyed
|
|
3448
|
+
* for idempotency on `body.id` passed this suite and would then have
|
|
3449
|
+
* dropped — or double-written — every real update.
|
|
3450
|
+
*
|
|
3451
|
+
* `src/__tests__/body-contract.test.ts` executes this function and compares
|
|
3452
|
+
* it against `@oneaddress/protocol`'s lists; the customer app executes the
|
|
3453
|
+
* RELAY against the same lists. Neither half can bless a drift on its own.
|
|
3454
|
+
*/
|
|
3455
|
+
update_id: updateIdNum,
|
|
3375
3456
|
partner_id: partnerId,
|
|
3457
|
+
// Real on every dispatch. A drill has no consumer, so it announces itself
|
|
3458
|
+
// under a reserved subject rather than omitting the key and teaching a
|
|
3459
|
+
// receiver that the field is optional.
|
|
3460
|
+
user_id: CONFORMANCE_USER_ID,
|
|
3461
|
+
timestamp: nowIso,
|
|
3376
3462
|
// D5 per-partner encrypted address envelope (identity is INSIDE it).
|
|
3377
3463
|
session_envelope: envelope.session_envelope,
|
|
3378
3464
|
session_key_share: envelope.session_key_share,
|
|
3465
|
+
// Derived from the same resolver the relay uses, so this is the recipient's
|
|
3466
|
+
// horizon rather than a constant. Was hard-coded to 90 days.
|
|
3467
|
+
key_share_expiry: keyShareExpiryIso(/* @__PURE__ */ new Date(), retentionPeriodDays),
|
|
3468
|
+
id_verification: {
|
|
3469
|
+
method: "identity_document",
|
|
3470
|
+
verified_at: nowIso,
|
|
3471
|
+
verified: true,
|
|
3472
|
+
platform: "oneaddress/v1"
|
|
3473
|
+
},
|
|
3379
3474
|
// D5 per-partner encrypted signed LOA. No cleartext letter_of_authority.
|
|
3380
3475
|
loa_encrypted: {
|
|
3381
3476
|
session_envelope: loaEnvelope.session_envelope,
|
|
3382
3477
|
session_key_share: loaEnvelope.session_key_share
|
|
3383
3478
|
},
|
|
3384
|
-
|
|
3479
|
+
// On the wire with a `null` value when no PaymentIntent backed the update,
|
|
3480
|
+
// so the KEY is what a receiver sees either way.
|
|
3481
|
+
stripe_session_id: null,
|
|
3385
3482
|
/**
|
|
3386
3483
|
* THIS DISPATCH IS A DRILL, AND IT SAYS SO IN THE SIGNED BODY.
|
|
3387
3484
|
*
|
|
@@ -3462,6 +3559,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3462
3559
|
let acceptedUpdateTypes = [];
|
|
3463
3560
|
let verifiesAccountReference = false;
|
|
3464
3561
|
let supportsKeyCrossover = false;
|
|
3562
|
+
let accountRef = DEFAULT_ACCOUNT_REF;
|
|
3465
3563
|
if (typeof urlOrOptions === "object") {
|
|
3466
3564
|
targetUrl = urlOrOptions.targetUrl;
|
|
3467
3565
|
secret = urlOrOptions.secret ?? TEST_WEBHOOK_SECRET;
|
|
@@ -3471,11 +3569,13 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3471
3569
|
acceptedUpdateTypes = urlOrOptions.acceptedUpdateTypes ?? [];
|
|
3472
3570
|
verifiesAccountReference = urlOrOptions.verifiesAccountReference === true;
|
|
3473
3571
|
supportsKeyCrossover = urlOrOptions.supportsKeyCrossover === true;
|
|
3572
|
+
accountRef = urlOrOptions.accountRef?.trim() || DEFAULT_ACCOUNT_REF;
|
|
3474
3573
|
} else {
|
|
3475
3574
|
targetUrl = urlOrOptions;
|
|
3476
3575
|
}
|
|
3477
3576
|
const results = [];
|
|
3478
|
-
const
|
|
3577
|
+
const matchable = { account_number: accountRef };
|
|
3578
|
+
const sharedBody = await buildBody(partnerId, publicKeyB64, void 0, "address", matchable);
|
|
3479
3579
|
let declaration = readAcceptedUpdateKindsFromAck(null);
|
|
3480
3580
|
let check1Accepted;
|
|
3481
3581
|
{
|
|
@@ -3547,7 +3647,13 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3547
3647
|
});
|
|
3548
3648
|
}
|
|
3549
3649
|
{
|
|
3550
|
-
const futureBody = await buildBody(
|
|
3650
|
+
const futureBody = await buildBody(
|
|
3651
|
+
partnerId,
|
|
3652
|
+
publicKeyB64,
|
|
3653
|
+
{ future_field: "ignored", future_object: { x: 1 } },
|
|
3654
|
+
"address",
|
|
3655
|
+
matchable
|
|
3656
|
+
);
|
|
3551
3657
|
const ts = String(Math.floor(Date.now() / 1e3));
|
|
3552
3658
|
const sig = sign(futureBody, ts, secret);
|
|
3553
3659
|
const { status, error } = await post(targetUrl, futureBody, buildHeaders(partnerId, ts, sig, "6"));
|
|
@@ -3564,9 +3670,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3564
3670
|
const unknownBody = JSON.stringify({
|
|
3565
3671
|
event: "address.future_event",
|
|
3566
3672
|
oneaddress_version: CURRENT_VERSION,
|
|
3567
|
-
|
|
3568
|
-
id: import_node_crypto.default.randomUUID(),
|
|
3569
|
-
timestamp: String(Math.floor(Date.now() / 1e3)),
|
|
3673
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3570
3674
|
partner_id: partnerId
|
|
3571
3675
|
});
|
|
3572
3676
|
const ts = String(Math.floor(Date.now() / 1e3));
|
|
@@ -3712,7 +3816,9 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3712
3816
|
basis: "rejection",
|
|
3713
3817
|
label: "Refuses an account reference that matches no record (no name fallback)",
|
|
3714
3818
|
passed,
|
|
3715
|
-
detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 an unmatchable account reference was not reported as applied` : `HTTP ${status} with ok:true \u2014 an account reference matching NO record was reported as successfully applied. If your matching falls back to the customer's NAME when the account number misses, you will write one customer's address onto another customer's record. An account number that matches nothing must be a hard no-match: do not fall back to name, and do not accept a matching account number whose name disagrees with that record. Answer the webhook with ok:false so the consumer is told, which is what they were promised before they paid, and confirm the dispatch as "no_match" rather than "failed": "failed" means YOUR system broke and makes the update refundable at your expense, while "no_match" says the person is simply not on your books. This check reads the webhook response only, so it cannot see which status you send; getting it wrong costs you money rather than failing here
|
|
3819
|
+
detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status}${parsed.ok === false ? " with ok:false" : ""} \u2014 an unmatchable account reference was not reported as applied` : `HTTP ${status} with ok:true \u2014 an account reference matching NO record was reported as successfully applied. If your matching falls back to the customer's NAME when the account number misses, you will write one customer's address onto another customer's record. An account number that matches nothing must be a hard no-match: do not fall back to name, and do not accept a matching account number whose name disagrees with that record. Answer the webhook with ok:false so the consumer is told, which is what they were promised before they paid, and confirm the dispatch as "no_match" rather than "failed": "failed" means YOUR system broke and makes the update refundable at your expense, while "no_match" says the person is simply not on your books. This check reads the webhook response only, so it cannot see which status you send; getting it wrong costs you money rather than failing here.
|
|
3820
|
+
|
|
3821
|
+
THERE IS A SECOND READING, and it is the likelier one on a first run: if this receiver does not match dispatches to customer records AT ALL \u2014 no lookup configured, it just queues what arrives \u2014 then the FLAG is wrong, not the receiver. This check asks a question only a matching receiver can answer, so drop --verifies-account-reference (and untick the same declaration in your partner portal, so the two agree) and run again. Nothing out here can tell the two apart: both look like ok:true to an unmatchable reference.`
|
|
3716
3822
|
});
|
|
3717
3823
|
}
|
|
3718
3824
|
const plan = kindProbePlan(declaration, acceptedUpdateTypes);
|
|
@@ -3727,7 +3833,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3727
3833
|
const contactKinds = plan.accept;
|
|
3728
3834
|
for (const kind of contactKinds) {
|
|
3729
3835
|
const article = kind === "email" ? "an" : "a";
|
|
3730
|
-
const body = await buildBody(partnerId, publicKeyB64, void 0, kind);
|
|
3836
|
+
const body = await buildBody(partnerId, publicKeyB64, void 0, kind, matchable);
|
|
3731
3837
|
const ts = String(Math.floor(Date.now() / 1e3));
|
|
3732
3838
|
const sig = sign(body, ts, secret);
|
|
3733
3839
|
const res = await fetch(targetUrl, {
|
|
@@ -3780,7 +3886,7 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3780
3886
|
});
|
|
3781
3887
|
if (plan.refuse !== null) {
|
|
3782
3888
|
const probe = plan.refuse;
|
|
3783
|
-
const body = await buildBody(partnerId, publicKeyB64, void 0, probe);
|
|
3889
|
+
const body = await buildBody(partnerId, publicKeyB64, void 0, probe, matchable);
|
|
3784
3890
|
const ts = String(Math.floor(Date.now() / 1e3));
|
|
3785
3891
|
const sig = sign(body, ts, secret);
|
|
3786
3892
|
const res = await fetch(targetUrl, {
|
|
@@ -3840,6 +3946,62 @@ async function runChecks(urlOrOptions, secret = TEST_WEBHOOK_SECRET, partnerId =
|
|
|
3840
3946
|
detail: !reachable ? "Network error: no response" : passed ? `HTTP ${status} with crossover:true \u2014 a copy sealed to a rotation sibling key was correctly skip-acked; the copy sealed to a held key carries the update` : `HTTP ${status} \u2014 a copy naming one of this receiver's keys as a crossover sibling was not skip-acked. During a key rotation a copy sealed to your OTHER key must be skipped (a decryptable sibling copy is coming), signalled with { ok: true, skipped: true, crossover: true }. A 500 here drops one copy of a live update; a bare 200 ok:true without crossover:true is check-11's silent-loss shape. Configure your handler's key_id (or key store) so it recognises the marker, or clear "supports key crossover" until you have.`
|
|
3841
3947
|
});
|
|
3842
3948
|
}
|
|
3949
|
+
{
|
|
3950
|
+
const nonce = import_node_crypto.default.randomUUID();
|
|
3951
|
+
const body = await buildBody(partnerId, publicKeyB64, {
|
|
3952
|
+
// `event` IS LOAD-BEARING HERE and setting only the header is the bug this
|
|
3953
|
+
// check shipped with for one run. `buildBody` defaults the body event to
|
|
3954
|
+
// `address.updated`, and both the SDK and the drop-in receiver route on the
|
|
3955
|
+
// BODY, not on `X-OneAddress-Event`. With the header alone our own
|
|
3956
|
+
// reference receiver treated the record as an ordinary update, answered
|
|
3957
|
+
// `{ ok: true }`, and failed its own conformance self-test — which is
|
|
3958
|
+
// precisely the signal this check is supposed to produce for a receiver
|
|
3959
|
+
// that never handled test records. Caught by
|
|
3960
|
+
// `packages/receiver/src/conformance-self.test.ts`.
|
|
3961
|
+
//
|
|
3962
|
+
// `extraFields` is spread last, so this wins, and the two now agree as the
|
|
3963
|
+
// builder's own comment requires.
|
|
3964
|
+
event: "address.test",
|
|
3965
|
+
verification_id: `conformance-${nonce}`,
|
|
3966
|
+
index: 1,
|
|
3967
|
+
total: 1
|
|
3968
|
+
}, "address", {
|
|
3969
|
+
// `...matchable` FIRST, and it is not optional: it carries the account
|
|
3970
|
+
// reference the operator supplied, and `account-ref.test.ts` fails any
|
|
3971
|
+
// probe meant to MATCH that falls back to DEFAULT_ACCOUNT_REF. It caught
|
|
3972
|
+
// exactly that here. A verification record IS meant to match: the whole
|
|
3973
|
+
// point is that the receiver decrypts it and finds something it can place.
|
|
3974
|
+
...matchable,
|
|
3975
|
+
// Deliberately self-describing. The drop-in receiver PRINTS a verification
|
|
3976
|
+
// line for this record, so it lands in the partner's own stdout beside the
|
|
3977
|
+
// real ones. A name that says what it is stops a drill line being pasted
|
|
3978
|
+
// into a real submission, where it would parse and then mismatch.
|
|
3979
|
+
verified_name: "CONFORMANCE DRILL",
|
|
3980
|
+
known_names: ["CONFORMANCE DRILL"]
|
|
3981
|
+
});
|
|
3982
|
+
const ts = String(Math.floor(Date.now() / 1e3));
|
|
3983
|
+
const sig = sign(body, ts, secret);
|
|
3984
|
+
const { status, error, body: ackBody } = await post(
|
|
3985
|
+
targetUrl,
|
|
3986
|
+
body,
|
|
3987
|
+
buildHeaders(partnerId, ts, sig, `conformance-${nonce}-1`, "address.test")
|
|
3988
|
+
);
|
|
3989
|
+
let parsed = {};
|
|
3990
|
+
try {
|
|
3991
|
+
parsed = JSON.parse(ackBody);
|
|
3992
|
+
} catch {
|
|
3993
|
+
}
|
|
3994
|
+
const acknowledged = !error && status >= 200 && status < 300;
|
|
3995
|
+
const passed = acknowledged && parsed.verification === true;
|
|
3996
|
+
const missing = typeof parsed.missing_callback === "string" ? parsed.missing_callback : null;
|
|
3997
|
+
results.push({
|
|
3998
|
+
id: "check-16",
|
|
3999
|
+
basis: "acceptance",
|
|
4000
|
+
label: "Answers a connection-verification record (address.test)",
|
|
4001
|
+
passed,
|
|
4002
|
+
detail: error ? `Network error: ${error}` : !acknowledged ? `HTTP ${status} \u2014 expected 2xx. A test record is a real signed, encrypted dispatch; refusing it will fail connection verification.` : missing ? `HTTP ${status}, and your receiver reported no \`${missing}\` callback, so the record was acknowledged and SKIPPED. OneAddress sends five of these before go-live and counts how many you decrypt; with no \`${missing}\` you will score zero while every delivery looks clean. Add \`${missing}\` to createOneAddressHandler.` : parsed.verification === true ? `HTTP ${status} \u2014 verification record decrypted and acknowledged` : `HTTP ${status}, but the response did not carry { verification: true }. OneAddress counts that field as proof you decrypted the record, so without it a working receiver still reads as "decrypted 0 of 5" on the real run. Echo it from your test-record handler.`
|
|
4003
|
+
});
|
|
4004
|
+
}
|
|
3843
4005
|
if (customerUrl) {
|
|
3844
4006
|
const pullBase = customerUrl.replace(/\/$/, "");
|
|
3845
4007
|
{
|
|
@@ -3975,6 +4137,12 @@ function exitCode(results) {
|
|
|
3975
4137
|
}
|
|
3976
4138
|
|
|
3977
4139
|
// src/resolve-credentials.ts
|
|
4140
|
+
var import_node_crypto2 = require("crypto");
|
|
4141
|
+
var FLAG_FOR = {
|
|
4142
|
+
ONEADDRESS_WEBHOOK_SECRET: "--secret",
|
|
4143
|
+
ONEADDRESS_PARTNER_ID: "--partner-id",
|
|
4144
|
+
ONEADDRESS_PUBLIC_KEY: "--public-key"
|
|
4145
|
+
};
|
|
3978
4146
|
function resolveOne(flag, envVar, env, fallback) {
|
|
3979
4147
|
if (flag !== void 0 && flag !== "") return { value: flag, source: "flag", envVar };
|
|
3980
4148
|
const fromEnv = env[envVar]?.trim();
|
|
@@ -3997,6 +4165,66 @@ function resolveCredentials(flags, env = process.env) {
|
|
|
3997
4165
|
allBuiltIn: [secret, partnerId, publicKeyB64].every((c) => c.source === "built-in test value")
|
|
3998
4166
|
};
|
|
3999
4167
|
}
|
|
4168
|
+
function publicKeyProblem(c) {
|
|
4169
|
+
const cred = c.publicKeyB64;
|
|
4170
|
+
if (cred.source === "built-in test value") return null;
|
|
4171
|
+
const where = `${cred.envVar} (--public-key)`;
|
|
4172
|
+
if (/BEGIN[^-]*PRIVATE/.test(cred.value)) {
|
|
4173
|
+
return `${where} is a PRIVATE key. That one belongs on your RECEIVER and must never leave it; this flag takes the PUBLIC half, as base64 of the DER SPKI form.`;
|
|
4174
|
+
}
|
|
4175
|
+
let der;
|
|
4176
|
+
try {
|
|
4177
|
+
der = Buffer.from(cred.value, "base64");
|
|
4178
|
+
if (der.length === 0 || der.toString("base64").replace(/=+$/, "") !== cred.value.trim().replace(/=+$/, "")) {
|
|
4179
|
+
return `${where} is not valid base64. Copy it again from your partner portal \u2014 a line break or a stray space is the usual cause.`;
|
|
4180
|
+
}
|
|
4181
|
+
} catch {
|
|
4182
|
+
return `${where} is not valid base64.`;
|
|
4183
|
+
}
|
|
4184
|
+
try {
|
|
4185
|
+
const key = (0, import_node_crypto2.createPublicKey)({ key: der, format: "der", type: "spki" });
|
|
4186
|
+
if (key.asymmetricKeyType !== "ec") {
|
|
4187
|
+
return `${where} is a ${key.asymmetricKeyType ?? "non-EC"} key. OneAddress envelopes use ECDH P-256, so this key cannot unwrap them.`;
|
|
4188
|
+
}
|
|
4189
|
+
const curve = key.asymmetricKeyDetails?.namedCurve;
|
|
4190
|
+
if (curve && curve !== "prime256v1") {
|
|
4191
|
+
return `${where} is on curve ${curve}, not P-256 (prime256v1).`;
|
|
4192
|
+
}
|
|
4193
|
+
} catch {
|
|
4194
|
+
return `${where} is valid base64 but not an SPKI public key. Expect the BASE64 of the DER SPKI form \u2014 not a PEM, not a private key, and not the key id.`;
|
|
4195
|
+
}
|
|
4196
|
+
return null;
|
|
4197
|
+
}
|
|
4198
|
+
function partialCredentials(c) {
|
|
4199
|
+
if (c.allBuiltIn) return [];
|
|
4200
|
+
return [c.secret, c.partnerId, c.publicKeyB64].filter((x) => x.source === "built-in test value");
|
|
4201
|
+
}
|
|
4202
|
+
function partialCredentialRefusal(c) {
|
|
4203
|
+
const missing = partialCredentials(c);
|
|
4204
|
+
if (missing.length === 0) return null;
|
|
4205
|
+
const named = missing.map((x) => `${x.envVar} (${FLAG_FOR[x.envVar]})`);
|
|
4206
|
+
return [
|
|
4207
|
+
"\u2717 INCOMPLETE CREDENTIALS \u2014 refusing to run.",
|
|
4208
|
+
"",
|
|
4209
|
+
`Some credentials were supplied and some were not: ${named.join(", ")} ${missing.length === 1 ? "is" : "are"} still a built-in test value.`,
|
|
4210
|
+
"",
|
|
4211
|
+
"Against a real receiver a partial set fails the same way a WRONG one does:",
|
|
4212
|
+
"the signature checks pass, so the run looks half-healthy, while the payload",
|
|
4213
|
+
"is sealed to this suite's test key that your receiver cannot decrypt. The",
|
|
4214
|
+
"failures land on the acceptance checks and read as a fault in your code.",
|
|
4215
|
+
"",
|
|
4216
|
+
"Supply all three, or none:",
|
|
4217
|
+
"",
|
|
4218
|
+
" export ONEADDRESS_WEBHOOK_SECRET=whsec_...",
|
|
4219
|
+
" export ONEADDRESS_PARTNER_ID=...",
|
|
4220
|
+
" export ONEADDRESS_PUBLIC_KEY=...",
|
|
4221
|
+
"",
|
|
4222
|
+
"Supplying none is correct for a scaffold from `npx @oneaddress/setup`,",
|
|
4223
|
+
"which is built around the same test values. If you truly mean the test",
|
|
4224
|
+
"value for one of these, pass it explicitly and this will run.",
|
|
4225
|
+
""
|
|
4226
|
+
];
|
|
4227
|
+
}
|
|
4000
4228
|
function describeCredentials(c) {
|
|
4001
4229
|
if (c.allBuiltIn) {
|
|
4002
4230
|
return [
|
|
@@ -4007,19 +4235,15 @@ function describeCredentials(c) {
|
|
|
4007
4235
|
"around these same values. A REAL receiver will reject every request, including",
|
|
4008
4236
|
"the well-formed one, because it validates against its own secret. Your partner",
|
|
4009
4237
|
"portal has the values, and the safer way to pass them keeps the secret out of",
|
|
4010
|
-
"your shell history and out of `ps
|
|
4238
|
+
"your shell history and out of `ps`. ALL THREE, or the run is refused:",
|
|
4011
4239
|
"",
|
|
4012
4240
|
" export ONEADDRESS_WEBHOOK_SECRET=whsec_...",
|
|
4241
|
+
" export ONEADDRESS_PARTNER_ID=...",
|
|
4242
|
+
" export ONEADDRESS_PUBLIC_KEY=...",
|
|
4013
4243
|
""
|
|
4014
4244
|
];
|
|
4015
4245
|
}
|
|
4016
|
-
|
|
4017
|
-
if (missing.length === 0) return [];
|
|
4018
|
-
return [
|
|
4019
|
-
`Some credentials were supplied and some were not: ${missing.join(", ")} ${missing.length === 1 ? "is" : "are"} still a built-in test value.`,
|
|
4020
|
-
"Against a real receiver a partial set fails the same way a wrong one does.",
|
|
4021
|
-
""
|
|
4022
|
-
];
|
|
4246
|
+
return [];
|
|
4023
4247
|
}
|
|
4024
4248
|
|
|
4025
4249
|
// src/index.ts
|
|
@@ -4036,7 +4260,16 @@ Options:
|
|
|
4036
4260
|
ONEADDRESS_WEBHOOK_SECRET same as --secret
|
|
4037
4261
|
ONEADDRESS_PARTNER_ID same as --partner-id
|
|
4038
4262
|
ONEADDRESS_PUBLIC_KEY same as --public-key
|
|
4263
|
+
Supply ALL THREE or none: a partial set is refused, because it passes every
|
|
4264
|
+
signature check while the payload stays sealed to the built-in test key, so
|
|
4265
|
+
the failures land on the acceptance checks and read as a fault in your code.
|
|
4039
4266
|
--customer-url <url> Customer app URL for pull API checks (adds checks 9 + 10)
|
|
4267
|
+
--account-ref <ref> The account reference the dispatches carry (default: CONF-0001,
|
|
4268
|
+
which every scaffold seeds). Only matters if your receiver
|
|
4269
|
+
matches dispatches to your own customer records: it holds no
|
|
4270
|
+
CONF-0001, so it answers no_match \u2014 correctly \u2014 and the run
|
|
4271
|
+
cannot go green. Point this at a customer you already hold
|
|
4272
|
+
rather than writing test data into your system of record.
|
|
4040
4273
|
--accept <kinds> Comma-separated update kinds you accept: address,phone,email.
|
|
4041
4274
|
Adds a check per contact kind. Match this to your accept-set
|
|
4042
4275
|
in the partner portal \u2014 a phone update carries NO address,
|
|
@@ -4052,15 +4285,20 @@ Options:
|
|
|
4052
4285
|
report a defect it cannot have.
|
|
4053
4286
|
|
|
4054
4287
|
Example:
|
|
4288
|
+
# The wizard scaffold: no credentials at all, which is a meaningful run
|
|
4055
4289
|
oneaddress-conformance test http://localhost:3001/webhook
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4290
|
+
|
|
4291
|
+
# A real receiver: all three, kept out of argv and shell history
|
|
4292
|
+
export ONEADDRESS_WEBHOOK_SECRET=whsec_xxx
|
|
4293
|
+
export ONEADDRESS_PARTNER_ID=aaa...
|
|
4294
|
+
export ONEADDRESS_PUBLIC_KEY=MFkw...
|
|
4295
|
+
oneaddress-conformance test https://api.mycompany.com/oneaddress --accept address,phone
|
|
4296
|
+
oneaddress-conformance test https://api.mycompany.com/oneaddress --verifies-account-reference
|
|
4297
|
+
oneaddress-conformance test https://api.mycompany.com/oneaddress --customer-url https://oneaddress.io
|
|
4298
|
+
|
|
4299
|
+
# The same on one line, if you accept the secret landing in \`ps\`
|
|
4062
4300
|
oneaddress-conformance test https://api.mycompany.com/oneaddress \\
|
|
4063
|
-
--secret whsec_xxx --partner-id aaa... --
|
|
4301
|
+
--secret whsec_xxx --partner-id aaa... --public-key MFkw...
|
|
4064
4302
|
`.trim();
|
|
4065
4303
|
async function main() {
|
|
4066
4304
|
const args = process.argv.slice(2);
|
|
@@ -4082,6 +4320,7 @@ async function main() {
|
|
|
4082
4320
|
const partnerId = creds.partnerId.value;
|
|
4083
4321
|
const publicKey = creds.publicKeyB64.value;
|
|
4084
4322
|
const customerUrl = getFlag("--customer-url");
|
|
4323
|
+
const accountRef = getFlag("--account-ref")?.trim() || process.env.ONEADDRESS_ACCOUNT_REF?.trim() || DEFAULT_ACCOUNT_REF;
|
|
4085
4324
|
const acceptedUpdateTypes = (getFlag("--accept") ?? "").split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
|
|
4086
4325
|
const verifiesAccountReference = args.includes("--verifies-account-reference");
|
|
4087
4326
|
const UNKNOWN = acceptedUpdateTypes.filter((t) => !["address", "phone", "email"].includes(t));
|
|
@@ -4118,6 +4357,27 @@ async function main() {
|
|
|
4118
4357
|
if (parsedTarget.protocol === "http:" && isLocalhost) {
|
|
4119
4358
|
console.warn("\n ! HTTP detected \u2014 acceptable for local testing only.\n");
|
|
4120
4359
|
}
|
|
4360
|
+
const refusal = partialCredentialRefusal(creds);
|
|
4361
|
+
if (refusal) {
|
|
4362
|
+
console.error("");
|
|
4363
|
+
for (const line of refusal) console.error(line ? ` ${line}` : "");
|
|
4364
|
+
process.exit(1);
|
|
4365
|
+
}
|
|
4366
|
+
const keyProblem = publicKeyProblem(creds);
|
|
4367
|
+
if (keyProblem) {
|
|
4368
|
+
console.error("");
|
|
4369
|
+
console.error(" \u2717 UNUSABLE PUBLIC KEY \u2014 refusing to run.");
|
|
4370
|
+
console.error("");
|
|
4371
|
+
console.error(` ${keyProblem}`);
|
|
4372
|
+
console.error("");
|
|
4373
|
+
process.exit(1);
|
|
4374
|
+
}
|
|
4375
|
+
if (verifiesAccountReference) {
|
|
4376
|
+
console.log(
|
|
4377
|
+
accountRef === DEFAULT_ACCOUNT_REF ? ` This run sends account reference ${DEFAULT_ACCOUNT_REF}. Your receiver matches references itself, so it needs a customer with that reference, or pass --account-ref <one of yours>.` : ` Account reference: ${accountRef}. It must exist in your system of record, or the matching checks fail on a receiver that is behaving correctly.`
|
|
4378
|
+
);
|
|
4379
|
+
console.log("");
|
|
4380
|
+
}
|
|
4121
4381
|
console.log(`
|
|
4122
4382
|
Running conformance checks against: ${targetUrl}`);
|
|
4123
4383
|
if (customerUrl) console.log(`Pull API checks against: ${customerUrl}`);
|
|
@@ -4130,7 +4390,8 @@ Running conformance checks against: ${targetUrl}`);
|
|
|
4130
4390
|
publicKeyB64: publicKey,
|
|
4131
4391
|
customerUrl,
|
|
4132
4392
|
acceptedUpdateTypes,
|
|
4133
|
-
verifiesAccountReference
|
|
4393
|
+
verifiesAccountReference,
|
|
4394
|
+
accountRef
|
|
4134
4395
|
});
|
|
4135
4396
|
printReport(results);
|
|
4136
4397
|
const code = exitCode(results);
|