@ghostlytools/sdk 1.3.10 → 1.4.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/dist/app.js +19 -4
- package/dist/app.js.map +1 -1
- package/dist/core.js +2 -2
- package/dist/{fakes-DRPAYl6q.js → fakes-DkFOiAo6.js} +2 -2
- package/dist/{fakes-DRPAYl6q.js.map → fakes-DkFOiAo6.js.map} +1 -1
- package/dist/fakes.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{keet-identity-key-D-FT8FmL.js → keet-identity-key-CZ27HbZq.js} +2 -2
- package/dist/{keet-identity-key-D-FT8FmL.js.map → keet-identity-key-CZ27HbZq.js.map} +1 -1
- package/dist/{src-DFY7sUQ4.js → src-BBoCvzFt.js} +28665 -26743
- package/dist/src-BBoCvzFt.js.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/types/core/src/appBundle.d.ts +4 -3
- package/dist/types/core/src/chatFiles.d.ts +32 -2
- package/dist/types/core/src/contactInbox.d.ts +68 -0
- package/dist/types/core/src/contactLink.d.ts +27 -0
- package/dist/types/core/src/contactRecords.d.ts +87 -0
- package/dist/types/core/src/dhtDelivery.d.ts +17 -0
- package/dist/types/core/src/ghostlink.d.ts +34 -3
- package/dist/types/core/src/groupCommunity.d.ts +35 -3
- package/dist/types/core/src/groupFiles.d.ts +5 -5
- package/dist/types/core/src/groupMeta.d.ts +19 -0
- package/dist/types/core/src/groupSession.d.ts +47 -5
- package/dist/types/core/src/groupSignals.d.ts +12 -1
- package/dist/types/core/src/index.d.ts +7 -0
- package/dist/types/core/src/link.d.ts +22 -2
- package/dist/types/core/src/miniApp.d.ts +56 -6
- package/dist/types/core/src/pairedCalls.d.ts +8 -3
- package/dist/types/core/src/pairedHttp.d.ts +9 -1
- package/dist/types/core/src/relay.d.ts +71 -6
- package/dist/types/core/src/transport.d.ts +21 -0
- package/dist/types/core/src/x401.d.ts +140 -0
- package/dist/types/core/src/x401Credential.d.ts +58 -0
- package/dist/types/core/src/x401Presentation.d.ts +96 -0
- package/dist/types/core/src/x401Request.d.ts +79 -0
- package/dist/{verify-sFNwqV7P.js → verify-BWtbTAs7.js} +2 -2
- package/dist/{verify-sFNwqV7P.js.map → verify-BWtbTAs7.js.map} +1 -1
- package/package.json +3 -3
- package/dist/src-DFY7sUQ4.js.map +0 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export declare const X401_SCHEME = "x401";
|
|
2
|
+
export declare const X401_VERSION = "0.2.0";
|
|
3
|
+
export declare const X401_HEADERS: {
|
|
4
|
+
readonly request: "PROOF-REQUEST";
|
|
5
|
+
readonly response: "PROOF-RESPONSE";
|
|
6
|
+
readonly result: "PROOF-RESULT";
|
|
7
|
+
};
|
|
8
|
+
export declare const X401_PROTOCOLS: {
|
|
9
|
+
readonly signed: "openid4vp-v1-signed";
|
|
10
|
+
readonly unsigned: "openid4vp-v1-unsigned";
|
|
11
|
+
};
|
|
12
|
+
export type X401Protocol = typeof X401_PROTOCOLS[keyof typeof X401_PROTOCOLS];
|
|
13
|
+
export declare const X401_LIMITS: {
|
|
14
|
+
/** One header value, in characters of base64url. */
|
|
15
|
+
readonly headerChars: number;
|
|
16
|
+
};
|
|
17
|
+
type JsonObject = Record<string, unknown>;
|
|
18
|
+
/** One entry of `credential_requirements.digital.requests`: an OpenID4VP request as the Digital Credentials API has it. */
|
|
19
|
+
export interface X401DigitalRequest {
|
|
20
|
+
protocol: string;
|
|
21
|
+
/** Signed: `{ request: <JAR compact JWS> }`. Unsigned: the OpenID4VP parameters themselves. */
|
|
22
|
+
data: JsonObject;
|
|
23
|
+
}
|
|
24
|
+
export interface X401OAuth {
|
|
25
|
+
token_endpoint: string;
|
|
26
|
+
audience?: string;
|
|
27
|
+
resource?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface X401Payment {
|
|
30
|
+
required?: boolean;
|
|
31
|
+
scheme_hint?: string;
|
|
32
|
+
notes?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The decoded `PROOF-REQUEST`. `credential_requirements` is the verifier's object as it came: an agent never changes it. */
|
|
35
|
+
export interface X401ProofRequest {
|
|
36
|
+
scheme: typeof X401_SCHEME;
|
|
37
|
+
version: typeof X401_VERSION;
|
|
38
|
+
credential_requirements: {
|
|
39
|
+
digital: {
|
|
40
|
+
requests: X401DigitalRequest[];
|
|
41
|
+
};
|
|
42
|
+
} & JsonObject;
|
|
43
|
+
oauth?: X401OAuth;
|
|
44
|
+
request_id?: string;
|
|
45
|
+
satisfied_requirements?: string[];
|
|
46
|
+
/** Set only by a relaying intermediary. Read so it can be shown, never followed (WISP 3xx, Security). */
|
|
47
|
+
return_uri?: string;
|
|
48
|
+
payment?: X401Payment;
|
|
49
|
+
}
|
|
50
|
+
/** The `{ protocol, data }` a Digital Credentials API presentation gives. */
|
|
51
|
+
export interface X401CredentialResult {
|
|
52
|
+
protocol: string;
|
|
53
|
+
data: JsonObject;
|
|
54
|
+
}
|
|
55
|
+
/** A Result Artifact: exactly one of `credential_result` (inline) and `credential_result_uri`. */
|
|
56
|
+
export interface X401ResultArtifact {
|
|
57
|
+
credential_result?: X401CredentialResult;
|
|
58
|
+
credential_result_uri?: string;
|
|
59
|
+
expires_at?: string;
|
|
60
|
+
request_id?: string;
|
|
61
|
+
agent_id?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface X401TokenObject {
|
|
64
|
+
scheme: typeof X401_SCHEME;
|
|
65
|
+
version: typeof X401_VERSION;
|
|
66
|
+
token_type: "Bearer";
|
|
67
|
+
access_token: string;
|
|
68
|
+
}
|
|
69
|
+
export type X401ProofResponse = {
|
|
70
|
+
kind: "artifact";
|
|
71
|
+
artifact: X401ResultArtifact;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "token";
|
|
74
|
+
token: X401TokenObject;
|
|
75
|
+
};
|
|
76
|
+
/** The decoded `PROOF-RESULT`. Its texts are the verifier's words: show them as such, never trust them. */
|
|
77
|
+
export interface X401ProofResult {
|
|
78
|
+
scheme: typeof X401_SCHEME;
|
|
79
|
+
version: typeof X401_VERSION;
|
|
80
|
+
error: string;
|
|
81
|
+
error_description?: string;
|
|
82
|
+
error_uri?: string;
|
|
83
|
+
request_id?: string;
|
|
84
|
+
}
|
|
85
|
+
export type X401Refusal =
|
|
86
|
+
/** More than one header line, or several values joined with commas. */
|
|
87
|
+
"duplicate" | "too-large" | "bad-base64url"
|
|
88
|
+
/** Not UTF-8, not JSON, or JSON that is not one object. */
|
|
89
|
+
| "not-object" | "scheme" | "version"
|
|
90
|
+
/** A member is missing or has the wrong shape; `detail` names it. */
|
|
91
|
+
| "invalid"
|
|
92
|
+
/** No request uses an OpenID4VP protocol x401 0.2.0 defines. */
|
|
93
|
+
| "unsupported";
|
|
94
|
+
export type X401Reading<T> = {
|
|
95
|
+
ok: true;
|
|
96
|
+
value: T;
|
|
97
|
+
} | {
|
|
98
|
+
ok: false;
|
|
99
|
+
reason: X401Refusal;
|
|
100
|
+
detail?: string;
|
|
101
|
+
};
|
|
102
|
+
/** What reads a header: a Fetch `Headers` joins repeated lines with ", ", which a base64url value never holds. */
|
|
103
|
+
export interface X401HeaderSource {
|
|
104
|
+
get(name: string): string | null;
|
|
105
|
+
}
|
|
106
|
+
/** One header value as base64url of a UTF-8 JSON object. */
|
|
107
|
+
export declare function encodeX401Header(payload: object): string;
|
|
108
|
+
/** Decodes one header value to its JSON object, refusing anything that is not exactly that. */
|
|
109
|
+
export declare function decodeX401Header(value: string): X401Reading<JsonObject>;
|
|
110
|
+
/** Reads a decoded `PROOF-REQUEST` payload. */
|
|
111
|
+
export declare function readX401ProofRequest(payload: JsonObject): X401Reading<X401ProofRequest>;
|
|
112
|
+
export declare const isX401Protocol: (protocol: string) => protocol is X401Protocol;
|
|
113
|
+
/**
|
|
114
|
+
* The requests an agent may answer, in the order it should try them: signed ones first (WISP 3xx, step 3), then
|
|
115
|
+
* unsigned, each in the verifier's order. Entries with another protocol are left out.
|
|
116
|
+
*/
|
|
117
|
+
export declare function x401AnswerableRequests(request: X401ProofRequest): X401DigitalRequest[];
|
|
118
|
+
/** Reads a decoded `PROOF-RESPONSE`: a Token Object when it has a `token_type`, else a Result Artifact. */
|
|
119
|
+
export declare function readX401ProofResponse(payload: JsonObject): X401Reading<X401ProofResponse>;
|
|
120
|
+
/** Reads a decoded `PROOF-RESULT`. */
|
|
121
|
+
export declare function readX401ProofResult(payload: JsonObject): X401Reading<X401ProofResult>;
|
|
122
|
+
/** The `PROOF-REQUEST` of a response, `null` when it has none. */
|
|
123
|
+
export declare const readX401ProofRequestHeader: (headers: X401HeaderSource) => X401Reading<X401ProofRequest> | null;
|
|
124
|
+
/** The `PROOF-RESPONSE` of a request, `null` when it has none. */
|
|
125
|
+
export declare const readX401ProofResponseHeader: (headers: X401HeaderSource) => X401Reading<X401ProofResponse> | null;
|
|
126
|
+
/** The `PROOF-RESULT` of a response, `null` when it has none. */
|
|
127
|
+
export declare const readX401ProofResultHeader: (headers: X401HeaderSource) => X401Reading<X401ProofResult> | null;
|
|
128
|
+
/** A `PROOF-RESPONSE` value carrying an inline Result Artifact (an agent never sends `credential_result_uri`). */
|
|
129
|
+
export declare function buildX401ResultArtifact(result: X401CredentialResult, extra?: {
|
|
130
|
+
expires_at?: string;
|
|
131
|
+
request_id?: string;
|
|
132
|
+
agent_id?: string;
|
|
133
|
+
}): string;
|
|
134
|
+
/** A `PROOF-RESPONSE` value carrying a Verification Token. */
|
|
135
|
+
export declare function buildX401TokenObject(accessToken: string): string;
|
|
136
|
+
/** A `PROOF-REQUEST` value, for a verifier (the local one of the CLI's tests). */
|
|
137
|
+
export declare function buildX401ProofRequest(fields: Omit<X401ProofRequest, "scheme" | "version">): string;
|
|
138
|
+
/** A `PROOF-RESULT` value, for a verifier (the local one of the CLI's tests). */
|
|
139
|
+
export declare function buildX401ProofResult(fields: Omit<X401ProofResult, "scheme" | "version">): string;
|
|
140
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const X401_CREDENTIAL_LIMITS: {
|
|
2
|
+
/** One issued credential, in characters. */
|
|
3
|
+
readonly chars: number;
|
|
4
|
+
readonly disclosures: 256;
|
|
5
|
+
};
|
|
6
|
+
/** A P-256 public key as a JWK: what an issuer binds a credential to (`cnf.jwk`). */
|
|
7
|
+
export interface X401HolderJwk {
|
|
8
|
+
kty: "EC";
|
|
9
|
+
crv: "P-256";
|
|
10
|
+
x: string;
|
|
11
|
+
y: string;
|
|
12
|
+
}
|
|
13
|
+
/** A claim's place in the credential, as a DCQL query names it: member names and array indexes from the top. */
|
|
14
|
+
export type X401ClaimPath = (string | number)[];
|
|
15
|
+
export interface X401SdJwtVc {
|
|
16
|
+
format: "dc+sd-jwt";
|
|
17
|
+
/** The issuer-signed JWT, as it came. */
|
|
18
|
+
jwt: string;
|
|
19
|
+
/** The disclosures, as they came, in their order. */
|
|
20
|
+
disclosures: string[];
|
|
21
|
+
/** `vct`: the credential's type. */
|
|
22
|
+
type: string;
|
|
23
|
+
/** `iss`: shown, never trusted. */
|
|
24
|
+
issuer: string;
|
|
25
|
+
holder: X401HolderJwk;
|
|
26
|
+
issuedAt?: number;
|
|
27
|
+
/** `nbf`: the credential is not valid before this second. */
|
|
28
|
+
notBefore?: number;
|
|
29
|
+
expiresAt?: number;
|
|
30
|
+
/** The claims with every disclosure in its place, without the JWT's own members (`iss`, `cnf`, `_sd`...). */
|
|
31
|
+
claims: Record<string, unknown>;
|
|
32
|
+
/** The claims a presentation may leave out: one path per disclosure. */
|
|
33
|
+
disclosable: X401ClaimPath[];
|
|
34
|
+
/** The disclosure that reveals each of `disclosable`, at the same index. */
|
|
35
|
+
disclosedBy: string[];
|
|
36
|
+
}
|
|
37
|
+
export type X401CredentialReading = {
|
|
38
|
+
ok: true;
|
|
39
|
+
value: X401SdJwtVc;
|
|
40
|
+
} | {
|
|
41
|
+
ok: false;
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
/** A fresh holder key: its secret, kept sealed by the profile, and the public JWK an issuer binds to. */
|
|
45
|
+
export declare function newX401HolderKey(): {
|
|
46
|
+
secret: Uint8Array;
|
|
47
|
+
jwk: X401HolderJwk;
|
|
48
|
+
};
|
|
49
|
+
/** The JWK of an uncompressed P-256 public key. */
|
|
50
|
+
export declare function x401HolderJwk(publicKey: Uint8Array): X401HolderJwk;
|
|
51
|
+
export declare const sameX401HolderJwk: (a: X401HolderJwk, b: X401HolderJwk) => boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Reads an issued SD-JWT VC: `<issuer-signed JWT>~<disclosure>~…~`. Refused, with the reason: anything over 64 KiB,
|
|
54
|
+
* a key binding JWT after the last `~` (that is a presentation, not what an issuer gives), a JWT that is not signed or
|
|
55
|
+
* not typed `dc+sd-jwt` (or the older `vc+sd-jwt`), no `iss` or `vct`, a `cnf` that is no P-256 JWK, a digest other
|
|
56
|
+
* than SHA-256, and a disclosure that is malformed, given twice, or named by no digest of the credential.
|
|
57
|
+
*/
|
|
58
|
+
export declare function readX401SdJwtVc(text: string): X401CredentialReading;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { X401ClaimPath, X401SdJwtVc } from "./x401Credential.js";
|
|
2
|
+
/** A claim path as a query writes it: member names, array indexes, and `null` for every element of an array. */
|
|
3
|
+
export type X401DcqlPath = (string | number | null)[];
|
|
4
|
+
export interface X401DcqlClaim {
|
|
5
|
+
id?: string;
|
|
6
|
+
path: X401DcqlPath;
|
|
7
|
+
values?: (string | number | boolean)[];
|
|
8
|
+
}
|
|
9
|
+
export interface X401DcqlCredentialQuery {
|
|
10
|
+
id: string;
|
|
11
|
+
format: string;
|
|
12
|
+
multiple?: boolean;
|
|
13
|
+
meta?: {
|
|
14
|
+
vct_values?: string[];
|
|
15
|
+
} & Record<string, unknown>;
|
|
16
|
+
claims?: X401DcqlClaim[];
|
|
17
|
+
claim_sets?: string[][];
|
|
18
|
+
/** The issuers the verifier trusts: shown to the person as its hint, never used to decide. */
|
|
19
|
+
trusted_authorities?: unknown[];
|
|
20
|
+
}
|
|
21
|
+
export interface X401DcqlCredentialSet {
|
|
22
|
+
options: string[][];
|
|
23
|
+
required?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface X401DcqlQuery {
|
|
26
|
+
credentials: X401DcqlCredentialQuery[];
|
|
27
|
+
credential_sets?: X401DcqlCredentialSet[];
|
|
28
|
+
}
|
|
29
|
+
export declare const X401_DCQL_LIMITS: {
|
|
30
|
+
readonly credentials: 32;
|
|
31
|
+
readonly claims: 64;
|
|
32
|
+
readonly pathDepth: 32;
|
|
33
|
+
readonly values: 64;
|
|
34
|
+
readonly sets: 32;
|
|
35
|
+
};
|
|
36
|
+
/** A credential the profile keeps, as matching sees it. */
|
|
37
|
+
export interface X401HeldCredential {
|
|
38
|
+
id: string;
|
|
39
|
+
vc: X401SdJwtVc;
|
|
40
|
+
}
|
|
41
|
+
/** One credential query answered: by which credential, disclosing which claims (concrete paths, no `null`). */
|
|
42
|
+
export interface X401DcqlMatch {
|
|
43
|
+
query: string;
|
|
44
|
+
credential: string;
|
|
45
|
+
claims: X401ClaimPath[];
|
|
46
|
+
}
|
|
47
|
+
/** What a credential query asked, to show when nothing the profile keeps answers it. */
|
|
48
|
+
export interface X401DcqlAsk {
|
|
49
|
+
query: string;
|
|
50
|
+
format: string;
|
|
51
|
+
types: string[];
|
|
52
|
+
claims: X401DcqlPath[];
|
|
53
|
+
}
|
|
54
|
+
export type X401DcqlOutcome = {
|
|
55
|
+
ok: true;
|
|
56
|
+
matches: X401DcqlMatch[];
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
asked: X401DcqlAsk[];
|
|
60
|
+
};
|
|
61
|
+
/** Reads `dcql_query`. Refused with the member at fault: a query Ghostly cannot answer exactly as written. */
|
|
62
|
+
export declare function readX401DcqlQuery(value: unknown): {
|
|
63
|
+
ok: true;
|
|
64
|
+
value: X401DcqlQuery;
|
|
65
|
+
} | {
|
|
66
|
+
ok: false;
|
|
67
|
+
reason: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Matches a DCQL query against the credentials held, in their order: the first one of the asked format and type, valid
|
|
71
|
+
* now (past its `nbf`, before its `exp`), that holds every claim asked. With credential sets, each required set takes its first option the profile
|
|
72
|
+
* can answer whole, and optional sets are left out (least disclosure); without them, every credential query must be
|
|
73
|
+
* answered. One credential per query, even when the query allows `multiple`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function matchX401Dcql(query: X401DcqlQuery, held: X401HeldCredential[], now?: number): X401DcqlOutcome;
|
|
76
|
+
/** What ties a presentation to one verifier and one request (the Key Binding JWT's members). */
|
|
77
|
+
export interface X401Binding {
|
|
78
|
+
holderSecret: Uint8Array;
|
|
79
|
+
aud: string;
|
|
80
|
+
nonce: string;
|
|
81
|
+
iat?: number;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* An SD-JWT VC presentation: the issuer's JWT, the disclosures of the claims given (each claim's own, those of the
|
|
85
|
+
* members it sits in, and those inside it), then a Key Binding JWT signed by the holder key with `aud`, `nonce`,
|
|
86
|
+
* `iat` and `sd_hash` over everything before it.
|
|
87
|
+
*/
|
|
88
|
+
export declare function presentX401SdJwtVc(vc: X401SdJwtVc, claims: X401ClaimPath[], binding: X401Binding): string;
|
|
89
|
+
/**
|
|
90
|
+
* The `vp_token` of an OpenID4VP response: each presentation in a list under its credential query id. The ids are the
|
|
91
|
+
* verifier's, and `constructor` or `__proto__` is one as good as `pid`: gathered in a Map, answered as own members.
|
|
92
|
+
*/
|
|
93
|
+
export declare function x401VpToken(presentations: {
|
|
94
|
+
query: string;
|
|
95
|
+
presentation: string;
|
|
96
|
+
}[]): Record<string, string[]>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type X401DigitalRequest } from "./x401.js";
|
|
2
|
+
import { type X401DcqlMatch, type X401DcqlQuery } from "./x401Presentation.js";
|
|
3
|
+
export declare const X401_REQUEST_LIMITS: {
|
|
4
|
+
/** Certificates in `x5c`. */
|
|
5
|
+
readonly chain: 8;
|
|
6
|
+
/** Characters of a `nonce`. */
|
|
7
|
+
readonly nonce: 512;
|
|
8
|
+
readonly expectedOrigins: 32;
|
|
9
|
+
};
|
|
10
|
+
export declare const X401_RESPONSE_MODES: readonly ["dc_api", "dc_api.jwt"];
|
|
11
|
+
export type X401ResponseMode = typeof X401_RESPONSE_MODES[number];
|
|
12
|
+
/** A request the agent may answer, as read and checked. */
|
|
13
|
+
export interface X401OpenId4VpRequest {
|
|
14
|
+
signed: boolean;
|
|
15
|
+
/** The verifier: the signed request's `client_id`, else `origin:<origin called>`. Also the Key Binding JWT's `aud`. */
|
|
16
|
+
verifier: string;
|
|
17
|
+
/** The origin called. */
|
|
18
|
+
origin: string;
|
|
19
|
+
nonce: string;
|
|
20
|
+
dcql: X401DcqlQuery;
|
|
21
|
+
/** `dc_api.jwt` asks for an encrypted response, to a key in `client_metadata`. */
|
|
22
|
+
responseMode: X401ResponseMode;
|
|
23
|
+
clientMetadata?: Record<string, unknown>;
|
|
24
|
+
/** The signed request's `exp`, in seconds. */
|
|
25
|
+
expiresAt?: number;
|
|
26
|
+
}
|
|
27
|
+
export type X401RequestRefusal =
|
|
28
|
+
/** A member is missing or has the wrong shape; `detail` names it. */
|
|
29
|
+
"invalid"
|
|
30
|
+
/** A signature algorithm, `client_id` prefix, `response_type` or `response_mode` Ghostly does not answer. */
|
|
31
|
+
| "unsupported" | "expired"
|
|
32
|
+
/** The request names another host or origin than the one called. */
|
|
33
|
+
| "host"
|
|
34
|
+
/** The certificate chain was not accepted; `detail` says why. */
|
|
35
|
+
| "certificate" | "signature";
|
|
36
|
+
export type X401RequestReading = {
|
|
37
|
+
ok: true;
|
|
38
|
+
value: X401OpenId4VpRequest;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
reason: X401RequestRefusal;
|
|
42
|
+
detail?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Checks a signed request's `x5c` chain (DER, leaf first) for a host at a time: that it leads to a trusted root, that
|
|
46
|
+
* each certificate is valid then, and that a DNS name of the leaf is that host. Gives the leaf's P-256 public key,
|
|
47
|
+
* uncompressed.
|
|
48
|
+
*/
|
|
49
|
+
export type X401CertificateCheck = (chain: Uint8Array[], host: string, now: number) => Promise<{
|
|
50
|
+
ok: true;
|
|
51
|
+
publicKey: Uint8Array;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
reason: string;
|
|
55
|
+
}>;
|
|
56
|
+
export interface X401RequestContext {
|
|
57
|
+
/** The URL the agent called; its origin and host bind the request. */
|
|
58
|
+
url: string;
|
|
59
|
+
certificates: X401CertificateCheck;
|
|
60
|
+
now?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reads one entry of `credential_requirements.digital.requests` for the URL the agent called, checking a signed one's
|
|
64
|
+
* binding, certificate and signature. Only `https:` is answered; `http:` only to a loopback host, for a local verifier.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readX401OpenId4VpRequest(entry: X401DigitalRequest, context: X401RequestContext): Promise<X401RequestReading>;
|
|
67
|
+
/** What the person approves: this verifier, these credentials, these claims, and the token endpoint when one is used. */
|
|
68
|
+
export interface X401ApprovalSubject {
|
|
69
|
+
verifier: string;
|
|
70
|
+
matches: Pick<X401DcqlMatch, "credential" | "claims">[];
|
|
71
|
+
/** The token endpoint's origin, when the approval also covers a token exchange. */
|
|
72
|
+
tokenEndpoint?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The approval digest (`--approve <digest>`): SHA-256, base64url, over the verifier, each credential with its claim
|
|
76
|
+
* paths, and the token endpoint's origin. Order does not count: a request that asks the same thing in another order
|
|
77
|
+
* keeps its digest; one more claim, another credential or another verifier changes it.
|
|
78
|
+
*/
|
|
79
|
+
export declare function x401ApprovalDigest(subject: X401ApprovalSubject): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ou as boundVerifiedIdentity } from "./src-BBoCvzFt.js";
|
|
2
2
|
//#region ../browser/src/proofs/verify.ts
|
|
3
3
|
var DAY = 86400;
|
|
4
4
|
/**
|
|
@@ -103,4 +103,4 @@ function boundedIdentityFetch(options = { online: () => true }) {
|
|
|
103
103
|
//#endregion
|
|
104
104
|
export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
|
|
105
105
|
|
|
106
|
-
//# sourceMappingURL=verify-
|
|
106
|
+
//# sourceMappingURL=verify-BWtbTAs7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-
|
|
1
|
+
{"version":3,"file":"verify-BWtbTAs7.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\n\nconst DAY = 86_400;\n\n/**\n * The checks every proof goes through, whatever its provider: known provider, validity within the\n * provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule\n * (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).\n * The engine verifies a contact's proof, and the person's own proof before saving it, only through this.\n */\nexport async function verifyIdentity(providers: readonly IdentityProofProvider[], statement: IdentityStatement, evidence: unknown, ctx: VerifyContext): Promise<VerifiedIdentity> {\n const { binding } = statement;\n const provider = providers.find(p => p.id === binding.provider);\n if (!provider) throw new Error(\"This app cannot verify this kind of identity\");\n if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, IDENTITY_MAX_VALIDITY)) throw new Error(\"The proof lasts longer than this kind of identity allows\");\n if (JSON.stringify(evidence ?? null).length > IDENTITY_MAX_EVIDENCE) throw new Error(\"Evidence too large\");\n const parsed = provider.parseEvidence(evidence);\n const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));\n if (provider.category === \"self-custodied\" && verified.subject !== binding.subject) throw new Error(\"The evidence is for another identity\");\n if (provider.category === \"provider-attested\" && !verified.attester) throw new Error(\"The evidence does not say who attests it\");\n return verified;\n}\n\n/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */\nexport function descriptorProblems(p: IdentityProofProvider): string[] {\n const problems: string[] = [];\n if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!p.label?.trim()) problems.push(\"label is empty\");\n if (!p.description?.trim()) problems.push(\"description is empty\");\n if (!p.privacy?.trim()) problems.push(\"privacy is empty: say what verify contacts\");\n if (p.category !== \"self-custodied\" && p.category !== \"provider-attested\") problems.push(\"category is unknown\");\n if (!p.platforms.length) problems.push(\"no platforms\");\n const { defaultDays, maxDays } = p.validity;\n if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= IDENTITY_MAX_VALIDITY)) problems.push(\"validity must be whole days, 1 ≤ default ≤ max ≤ 400\");\n if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push(\"recheck.afterSeconds must be at least 60\");\n if (!p.signers.length) problems.push(\"no signers\");\n const ids = p.signers.map(s => s.id);\n if (new Set(ids).size !== ids.length) problems.push(\"signer ids are not unique\");\n for (const s of p.signers as readonly IdentitySigner<unknown>[]) {\n if (![\"in-app\", \"external-tool\", \"redirect\", \"publish\"].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);\n if (s.kind === \"in-app\" && typeof s.run !== \"function\") problems.push(`signer ${s.id} has no run()`);\n if (s.kind === \"external-tool\" && (typeof s.instructions !== \"function\" || typeof s.parse !== \"function\")) problems.push(`signer ${s.id} needs instructions() and parse()`);\n if (s.kind === \"redirect\" && typeof s.start !== \"function\") problems.push(`signer ${s.id} has no start()`);\n if (s.kind === \"publish\" && (typeof s.instructions !== \"function\" || typeof s.evidence !== \"function\")) problems.push(`signer ${s.id} needs instructions() and evidence()`);\n }\n return problems;\n}\n\n/** Signers of a provider that run on this platform and are available in this window. */\nexport function availableSigners<E>(p: IdentityProofProvider<E>, platform: IdentityProofProvider[\"platforms\"][number]): IdentitySigner<E>[] {\n return p.signers.filter(s => (s.platforms ?? p.platforms).includes(platform) && (s.available?.() ?? true));\n}\n\n/**\n * The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,\n * redirects refused unless asked for.\n * `online` false refuses everything (the person turned the network off).\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\" } = {}) => {\n if (!options.online()) throw new Error(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n if (target.protocol !== \"https:\" || target.username || target.password) throw new Error(\"Identity checks use HTTPS only\");\n const timeout = AbortSignal.timeout(options.timeoutMs ?? 10_000);\n const response = await (options.fetcher ?? fetch)(target.href, {\n headers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n credentials: \"omit\", referrerPolicy: \"no-referrer\", cache: \"no-store\", redirect,\n });\n if (Number(response.headers.get(\"content-length\")) > maxBytes) throw new Error(\"Identity check response too large\");\n const reader = response.body?.getReader();\n const parts: Uint8Array[] = [];\n let length = 0;\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n length += value.length;\n if (length > maxBytes) throw new Error(\"Identity check response too large\");\n parts.push(value);\n }\n } finally { await reader.cancel().catch(() => {}); }\n }\n const bytes = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) { bytes.set(part, offset); offset += part.length; }\n return { status: response.status, contentType: response.headers.get(\"content-type\") ?? \"\", text: new TextDecoder().decode(bytes), bytes };\n };\n}\n"],"mappings":";;AAGA,IAAM,MAAM;;;;;;;AAQZ,eAAsB,eAAe,WAA6C,WAA8B,UAAmB,KAA+C;CAChL,MAAM,EAAE,YAAY;CACpB,MAAM,WAAW,UAAU,M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.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Build a wallet source, an identity proof, a mini-app or a client for Ghostly without reading its internals: the adapter contracts, their fakes and contract test suites, the plugin registry, and the mini-app API types (Apps run in Ghostly 1.2 and later).",
|
|
6
6
|
"license": "MIT",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@ghostly/browser": "*",
|
|
67
67
|
"@ghostly/core": "*",
|
|
68
68
|
"typescript": "^5.9.3",
|
|
69
|
-
"vite": "^8.3.
|
|
70
|
-
"vitest": "^5.0.
|
|
69
|
+
"vite": "^8.3.4",
|
|
70
|
+
"vitest": "^5.0.4"
|
|
71
71
|
}
|
|
72
72
|
}
|