@clavis.nexus/setup 2.0.0 → 3.0.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 +56 -50
- package/dist/cli.js +58 -48
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +41 -36
- package/dist/index.js +55 -45
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +56 -46
- package/dist/mcp.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The regions an app accepts new connections from. They are stored in this order. */
|
|
2
2
|
declare const APP_REGIONS: readonly ["JP", "US", "GB", "EEA"];
|
|
3
3
|
type AppRegion = (typeof APP_REGIONS)[number];
|
|
4
4
|
|
|
@@ -18,17 +18,15 @@ type DevelopersSession = {
|
|
|
18
18
|
expiresAt?: number;
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* A holder receipt (`receipt@1`): Clavis's countersignature that it accepted a statement signed with
|
|
22
|
+
* a passkey. Pass it as `receipt` in the body of an Org step.
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
[key: string]: unknown;
|
|
31
|
-
};
|
|
24
|
+
/**
|
|
25
|
+
* A holder receipt (`receipt@1`). Carry it as the JSON string Clavis returned and pass it on to where
|
|
26
|
+
* it is consumed, the Org API, without parsing it. To read what it holds, give it to the verifier,
|
|
27
|
+
* `createVerifier` in `@clavis.nexus/app`.
|
|
28
|
+
*/
|
|
29
|
+
type Receipt = string;
|
|
32
30
|
type HumanAction = {
|
|
33
31
|
needs_human: NeedsHuman;
|
|
34
32
|
message: string;
|
|
@@ -42,7 +40,7 @@ type SetupResult<T> = {
|
|
|
42
40
|
error: string;
|
|
43
41
|
human?: HumanAction;
|
|
44
42
|
};
|
|
45
|
-
/**
|
|
43
|
+
/** The place of incorporation declared. `terms_current` says whether the declaration binds the current Customer Terms and DPA versions. */
|
|
46
44
|
type OrgCardIncorporation = {
|
|
47
45
|
code: string;
|
|
48
46
|
at: number;
|
|
@@ -60,9 +58,9 @@ type SetupStatusReport = {
|
|
|
60
58
|
org_status: string;
|
|
61
59
|
setup_complete: boolean;
|
|
62
60
|
signature_card: "unknown" | "active" | "inactive";
|
|
63
|
-
/**
|
|
61
|
+
/** What holds the signature card back, when `signature_card` is `inactive`. */
|
|
64
62
|
signature_card_blockers?: string[];
|
|
65
|
-
/**
|
|
63
|
+
/** The place of incorporation. Null means none is declared. It is left out when the card could not be read. */
|
|
66
64
|
incorporation?: {
|
|
67
65
|
code: string;
|
|
68
66
|
terms_current: boolean;
|
|
@@ -72,30 +70,32 @@ type SetupStatusReport = {
|
|
|
72
70
|
host: string;
|
|
73
71
|
status: string;
|
|
74
72
|
declaration_ok: boolean;
|
|
75
|
-
/**
|
|
73
|
+
/** The regions new connections are accepted from. Left out, it is every region Clavis accepts. */
|
|
76
74
|
accepted_regions?: string[];
|
|
77
75
|
}>;
|
|
78
76
|
}>;
|
|
79
77
|
};
|
|
80
78
|
declare const DEFAULT_ORIGINS: SetupOrigins;
|
|
81
79
|
|
|
82
|
-
/**
|
|
80
|
+
/** What to pass to checkout for the signature card. */
|
|
83
81
|
type CardCheckoutOptions = {
|
|
84
|
-
/** `meter
|
|
82
|
+
/** `meter`, which is metered and the default, or `bundle`, the monthly bundle. */
|
|
85
83
|
offer?: "meter" | "bundle";
|
|
86
84
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
85
|
+
* Set this true only once the customer has consented to their billing data going to the payment
|
|
86
|
+
* provider in the United States, for payment and billing. Whether to consent is the customer's
|
|
87
|
+
* decision, and the SDK never sets it true by default.
|
|
89
88
|
*/
|
|
90
89
|
consentBillingData?: boolean;
|
|
91
|
-
/**
|
|
90
|
+
/** The language the consent statement is shown in, `en` or `ja`, defaulting to `en`. The purchase record is tied to the statement in that language. */
|
|
92
91
|
lang?: "en" | "ja";
|
|
93
92
|
};
|
|
94
93
|
|
|
95
94
|
/**
|
|
96
|
-
*
|
|
97
|
-
* Clavis
|
|
98
|
-
*
|
|
95
|
+
* The statement to sign. `type` is the type ID, `<name>@<version>`, and the other fields are the ones
|
|
96
|
+
* that type fixes. Clavis builds the statement it expects from the same material and refuses anything
|
|
97
|
+
* that does not match under JCS (400 `STATEMENT_MISMATCH`). Put the field values in the same form
|
|
98
|
+
* Clavis uses: domains lowercased, regions with no duplicates and in ascending order.
|
|
99
99
|
*/
|
|
100
100
|
type Statement = {
|
|
101
101
|
type: string;
|
|
@@ -103,15 +103,17 @@ type Statement = {
|
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* Org
|
|
107
|
-
* org-anchor-plan
|
|
106
|
+
* What the customer declares and agrees to when an Org is created.
|
|
107
|
+
* Pass it to both org-anchor-plan, which is the challenge, and org-verify-anchor. Declaring the place
|
|
108
|
+
* of incorporation again with incorporation-set takes the same thing.
|
|
108
109
|
*/
|
|
109
110
|
type OrgCreationTerms = {
|
|
110
|
-
/**
|
|
111
|
+
/** The place of incorporation: `JP`, `GB-EAW`, an EEA country code, or `US-XX`. */
|
|
111
112
|
incorporation?: string;
|
|
112
113
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
114
|
+
* Set this true only once the customer has agreed to the Customer Terms and the Data Processing
|
|
115
|
+
* Agreement (DPA). Whether to agree is the customer's decision, and the SDK never sets it true by
|
|
116
|
+
* default.
|
|
115
117
|
*/
|
|
116
118
|
acceptCustomerTerms?: boolean;
|
|
117
119
|
};
|
|
@@ -147,14 +149,14 @@ type SetupClient = {
|
|
|
147
149
|
cleared: true;
|
|
148
150
|
}>>;
|
|
149
151
|
status(): Promise<SetupResult<SetupStatusReport>>;
|
|
150
|
-
/** terms:
|
|
152
|
+
/** terms: the place of incorporation, and the customer's agreement to the Customer Terms. With either missing, or the place closed, it is refused before the passkey. */
|
|
151
153
|
orgAnchorPlan(domain: string, name?: string, terms?: OrgCreationTerms): Promise<SetupResult<{
|
|
152
154
|
domain: string;
|
|
153
155
|
name?: string;
|
|
154
156
|
incorporation: string;
|
|
155
157
|
nonce: string;
|
|
156
158
|
exp: number;
|
|
157
|
-
/**
|
|
159
|
+
/** The statement signed into the published manifest's `receipt` (`org.anchor.publish@1`) */
|
|
158
160
|
statement: Statement;
|
|
159
161
|
well_known_url: string;
|
|
160
162
|
txt_host: string;
|
|
@@ -189,8 +191,9 @@ type SetupClient = {
|
|
|
189
191
|
already_active: boolean;
|
|
190
192
|
}>>;
|
|
191
193
|
/**
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
+
* Declare the place of incorporation, with a passkey. The declaration binds the current Customer
|
|
195
|
+
* Terms and DPA versions, so it needs the customer's agreement. After those versions move, declare
|
|
196
|
+
* again before a purchase.
|
|
194
197
|
*/
|
|
195
198
|
incorporationSet(args: {
|
|
196
199
|
orgId: string;
|
|
@@ -199,8 +202,9 @@ type SetupClient = {
|
|
|
199
202
|
unchanged?: true;
|
|
200
203
|
}>>;
|
|
201
204
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
205
|
+
* Open checkout for the signature card. It needs a place of incorporation declared against the
|
|
206
|
+
* current versions, and the customer's consent to provide billing data. After the passkey, a person
|
|
207
|
+
* enters the card in the browser.
|
|
204
208
|
*/
|
|
205
209
|
cardCheckout(orgId: string, opts?: CardCheckoutOptions): Promise<SetupResult<{
|
|
206
210
|
url: string;
|
|
@@ -243,8 +247,9 @@ type SetupClient = {
|
|
|
243
247
|
declaration: unknown;
|
|
244
248
|
}>>;
|
|
245
249
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
250
|
+
* Choose the regions the app accepts new connections from, with a passkey. Null goes back to every
|
|
251
|
+
* region Clavis accepts. The choice is limited to the regions Clavis accepts right now. Narrowing
|
|
252
|
+
* the list leaves the people already connected using the app.
|
|
248
253
|
*/
|
|
249
254
|
appRegionsSet(args: {
|
|
250
255
|
orgId: string;
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { promisify } from 'util';
|
|
|
3
3
|
import { readFile, unlink, mkdir, writeFile, chmod, lstat } from 'fs/promises';
|
|
4
4
|
import path, { join, dirname, resolve, relative, isAbsolute } from 'path';
|
|
5
5
|
import { homedir } from 'os';
|
|
6
|
-
import { generateKeyPair, exportJWK,
|
|
6
|
+
import { generateKeyPair, exportJWK, jwtVerify, importJWK } from 'jose';
|
|
7
7
|
import { createInterface } from 'readline/promises';
|
|
8
8
|
import { stdin, stdout } from 'process';
|
|
9
9
|
import { randomBytes } from 'crypto';
|
|
@@ -173,19 +173,10 @@ async function postCardCheckout(apiOrigin, bearer, orgId, args) {
|
|
|
173
173
|
}
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
|
-
async function
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
if (!res.ok) throw new SetupApiError(res.status, "JWKS_FETCH", `jwks ${res.status}`);
|
|
182
|
-
return res.json();
|
|
183
|
-
}
|
|
184
|
-
async function getMasterJwkJson(apiOrigin, masterPinJson) {
|
|
185
|
-
const { verifySignedJwksDocument } = await import('@clavis.nexus/app');
|
|
186
|
-
const doc = await fetchJwksDocument(apiOrigin);
|
|
187
|
-
await verifySignedJwksDocument(doc, masterPinJson);
|
|
188
|
-
return JSON.stringify(doc.master);
|
|
176
|
+
async function checkTrustRoot(apiOrigin, trustRootJson) {
|
|
177
|
+
const { createVerifier } = await import('@clavis.nexus/app');
|
|
178
|
+
await createVerifier({ trustRoot: trustRootJson, apiOrigin }).trust();
|
|
179
|
+
return JSON.stringify(JSON.parse(trustRootJson));
|
|
189
180
|
}
|
|
190
181
|
|
|
191
182
|
// src/app-regions.ts
|
|
@@ -498,6 +489,17 @@ async function digestOf(value) {
|
|
|
498
489
|
const bytes = new TextEncoder().encode(canonicalStringify(value));
|
|
499
490
|
return `sha256:${bytesToBase64Url(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes)))}`;
|
|
500
491
|
}
|
|
492
|
+
async function valueDigest(type, value) {
|
|
493
|
+
return digestOf({ type, value });
|
|
494
|
+
}
|
|
495
|
+
async function orgPayloadDigest(payload) {
|
|
496
|
+
let value = payload;
|
|
497
|
+
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
498
|
+
const { proposer_receipt: _receipt, ...rest } = payload;
|
|
499
|
+
value = rest;
|
|
500
|
+
}
|
|
501
|
+
return valueDigest("org.payload@1", value);
|
|
502
|
+
}
|
|
501
503
|
function orgAnchorPublishStatement(input2) {
|
|
502
504
|
return { type: "org.anchor.publish@1", domain: input2.domain.trim().toLowerCase(), nonce: input2.nonce, exp: input2.exp };
|
|
503
505
|
}
|
|
@@ -505,7 +507,7 @@ function orgPolicyBootstrapStatement(input2) {
|
|
|
505
507
|
return { type: "org.policy.bootstrap@1", org: input2.org.trim(), domain: input2.domain.trim().toLowerCase() };
|
|
506
508
|
}
|
|
507
509
|
function orgAppRegisterStatement(input2) {
|
|
508
|
-
return { type: "org.app.register@1", org: input2.org.trim(), payload: input2.payload.trim()
|
|
510
|
+
return { type: "org.app.register@1", org: input2.org.trim(), payload: input2.payload.trim() };
|
|
509
511
|
}
|
|
510
512
|
function orgAppVerifyHostStatement(input2) {
|
|
511
513
|
return {
|
|
@@ -521,7 +523,7 @@ async function orgAppDeclarationStatement(input2) {
|
|
|
521
523
|
type: "org.app.declaration@1",
|
|
522
524
|
org: input2.org.trim(),
|
|
523
525
|
app: input2.app.trim(),
|
|
524
|
-
declaration: input2.declaration === null ? null : await
|
|
526
|
+
declaration: input2.declaration === null ? null : await valueDigest("app.declaration@1", { endUsers: input2.declaration.endUsers, uses: input2.declaration.uses })
|
|
525
527
|
};
|
|
526
528
|
}
|
|
527
529
|
function orgAppRegionsStatement(input2) {
|
|
@@ -558,13 +560,6 @@ function sameStatement(a, b) {
|
|
|
558
560
|
return false;
|
|
559
561
|
}
|
|
560
562
|
}
|
|
561
|
-
async function computePayloadCommitmentHex(payload) {
|
|
562
|
-
const o = payload && typeof payload === "object" ? { ...payload } : payload;
|
|
563
|
-
if (o && typeof o === "object" && !Array.isArray(o)) {
|
|
564
|
-
delete o.proposer_receipt;
|
|
565
|
-
}
|
|
566
|
-
return sha256HexUtf8(canonicalStringify(o));
|
|
567
|
-
}
|
|
568
563
|
async function hashManifestBody(body) {
|
|
569
564
|
return sha256HexUtf8(canonicalStringify(body));
|
|
570
565
|
}
|
|
@@ -574,14 +569,10 @@ function buildAnchorTxtRecord(args) {
|
|
|
574
569
|
|
|
575
570
|
// src/ceremony.ts
|
|
576
571
|
function receiptFromCeremonyPayload(payload) {
|
|
577
|
-
if (
|
|
572
|
+
if (typeof payload !== "string" || payload.length === 0) {
|
|
578
573
|
throw new Error("Passkey confirmation did not return a receipt.");
|
|
579
574
|
}
|
|
580
|
-
|
|
581
|
-
if (o.type !== "receipt@1" || o.statement === null || typeof o.statement !== "object") {
|
|
582
|
-
throw new Error("Passkey confirmation did not return a receipt.");
|
|
583
|
-
}
|
|
584
|
-
return o;
|
|
575
|
+
return payload;
|
|
585
576
|
}
|
|
586
577
|
async function startCeremony(args) {
|
|
587
578
|
const res = await fetch(`${args.apiOrigin.replace(/\/+$/, "")}/webauthn/authentication/ceremony/start`, {
|
|
@@ -713,19 +704,17 @@ async function writeAppEnvFile(appId, contents) {
|
|
|
713
704
|
|
|
714
705
|
// src/emit-env.ts
|
|
715
706
|
async function emitAppEnv(args) {
|
|
716
|
-
const pin = args.
|
|
707
|
+
const pin = args.trustRoot?.trim() || process.env.CLAVIS_TRUST_ROOT?.trim() || "";
|
|
717
708
|
if (!pin) {
|
|
718
|
-
throw new Error(
|
|
719
|
-
"CLAVIS_MASTER_PUBLIC_JWK_JSON is required. Set it to the master public JWK from GET {apiOrigin}/.well-known/jwks.json."
|
|
720
|
-
);
|
|
709
|
+
throw new Error("CLAVIS_TRUST_ROOT is required. Set it to the Clavis Master public JWK (docs.clavis.nexus).");
|
|
721
710
|
}
|
|
722
|
-
const
|
|
711
|
+
const trustRoot = await checkTrustRoot(args.origins.apiOrigin, pin);
|
|
723
712
|
const operatePath = await saveOperatePrivateJwk(args.appId, args.operatePrivateJwkJson);
|
|
724
713
|
const envRecord = {
|
|
725
714
|
CLAVIS_API_ORIGIN: args.origins.apiOrigin,
|
|
726
715
|
CLAVIS_APP_ID: args.appId,
|
|
727
716
|
OPERATE_PRIVATE_JWK: args.operatePrivateJwkJson,
|
|
728
|
-
|
|
717
|
+
CLAVIS_TRUST_ROOT: trustRoot
|
|
729
718
|
};
|
|
730
719
|
const envFile = await writeAppEnvFile(args.appId, formatEnvExport(envRecord));
|
|
731
720
|
return {
|
|
@@ -761,18 +750,39 @@ async function generateOperateKeyPair() {
|
|
|
761
750
|
privateJwkJson: JSON.stringify(priv)
|
|
762
751
|
};
|
|
763
752
|
}
|
|
764
|
-
var
|
|
753
|
+
var SESSION_SLOT = "wauthn-auth-jwt";
|
|
754
|
+
var SLOT_FIELD = /^[a-z][a-z0-9]{1,31}-slot$/;
|
|
755
|
+
var JWK_MEMBERS = ["kty", "crv", "x", "y", "kid", "alg"];
|
|
756
|
+
async function sessionKey(origin, kid) {
|
|
757
|
+
const res = await fetch(`${origin}/.well-known/jwks.json`, { redirect: "error", headers: { Accept: "application/json" } });
|
|
758
|
+
if (!res.ok) throw new Error(`jwks ${res.status}`);
|
|
759
|
+
const doc = await res.json();
|
|
760
|
+
const key = (doc.keys ?? []).find((k) => k && k.kid === kid);
|
|
761
|
+
if (!key) return null;
|
|
762
|
+
const slot = Object.entries(key).find(([name]) => SLOT_FIELD.test(name))?.[1];
|
|
763
|
+
if (slot !== SESSION_SLOT) return null;
|
|
764
|
+
const jwk = {};
|
|
765
|
+
for (const m of JWK_MEMBERS) if (key[m] !== void 0) jwk[m] = key[m];
|
|
766
|
+
return importJWK(jwk, "ES256");
|
|
767
|
+
}
|
|
765
768
|
async function verifyDevelopersAccessToken(accessToken, apiOrigin) {
|
|
766
769
|
const origin = new URL(apiOrigin).origin;
|
|
767
|
-
|
|
768
|
-
const { payload
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
770
|
+
let refused = false;
|
|
771
|
+
const { payload } = await jwtVerify(
|
|
772
|
+
accessToken,
|
|
773
|
+
async (header) => {
|
|
774
|
+
const key = typeof header.kid === "string" ? await sessionKey(origin, header.kid) : null;
|
|
775
|
+
if (!key) {
|
|
776
|
+
refused = true;
|
|
777
|
+
throw new Error("invalid_access_token_kid");
|
|
778
|
+
}
|
|
779
|
+
return key;
|
|
780
|
+
},
|
|
781
|
+
{ algorithms: ["ES256"], issuer: origin, audience: origin, requiredClaims: ["exp", "iss", "aud", "sub"] }
|
|
782
|
+
).catch((e) => {
|
|
783
|
+
if (refused) throw new Error("invalid_access_token_kid");
|
|
784
|
+
throw e;
|
|
773
785
|
});
|
|
774
|
-
const kid = typeof protectedHeader.kid === "string" ? protectedHeader.kid : "";
|
|
775
|
-
if (!SESSION_SLOT_RE.test(kid)) throw new Error("invalid_access_token_kid");
|
|
776
786
|
if (payload.tk !== "access") throw new Error("invalid_access_token_kind");
|
|
777
787
|
if (typeof payload.sub !== "string" || payload.sub.length === 0) throw new Error("invalid_access_token_sub");
|
|
778
788
|
if (typeof payload.exp !== "number" || !Number.isFinite(payload.exp)) throw new Error("invalid_access_token_exp");
|
|
@@ -1463,7 +1473,7 @@ function createSetupClient(options = {}) {
|
|
|
1463
1473
|
operate_public_jwk: keys.publicJwk,
|
|
1464
1474
|
redirect_paths: paths
|
|
1465
1475
|
};
|
|
1466
|
-
const payload_hash = await
|
|
1476
|
+
const payload_hash = await orgPayloadDigest(manifest);
|
|
1467
1477
|
const cer = await runPasskeyCeremony({
|
|
1468
1478
|
origins: auth.data.origins,
|
|
1469
1479
|
bearer: auth.data.session.accessToken,
|