@originator-profile/verify 0.5.3 → 0.6.0-beta.1

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.d.cts DELETED
@@ -1,471 +0,0 @@
1
- import { ContentAttestation, Image, Target, ContentAttestationSet, OpVc, Jwk, ArticleCA, Certificate as Certificate$1, CoreProfile, WebMediaProfile, WebsiteProfile, JapaneseExistenceCertificate, OriginatorProfileSet, Jwks, SiteProfile, AllowedOrigin } from '@originator-profile/model';
2
- import { JwtVcDecodingResult, UnverifiedJwtVc, JwtVcVerificationResult, VerifiedJwtVc, VcValidator } from '@originator-profile/securing-mechanism';
3
- import { Keys } from '@originator-profile/cryptography';
4
- import { DigestSriResult, ContentFetcher, ElementSelector } from '@originator-profile/sign';
5
-
6
- /** Content Attestation 復号失敗 */
7
- type CaDecodingFailure = JwtVcDecodingResult<ContentAttestation>;
8
- /** 復号済み Content Attestation */
9
- type DecodedCa = UnverifiedJwtVc<ContentAttestation>;
10
- /** Content Attestation 復号結果 */
11
- type CaDecodingResult = DecodedCa | CaInvalid;
12
- /** Content Attestation 検証失敗 */
13
- type CaVerificationFailure = JwtVcVerificationResult<ContentAttestation>;
14
- /** 検証済み Content Attestation */
15
- type VerifiedCa<T extends ContentAttestation = ContentAttestation> = VerifiedJwtVc<T>;
16
- /** Content Attestation 検証結果 */
17
- type CaVerificationResult<T extends ContentAttestation = ContentAttestation> = VerifiedCa<T> | CaInvalid | CaVerifyFailed;
18
-
19
- /**
20
- * Content Attestation 無効
21
- *
22
- * Content Attestation が無効な形式です。詳細は result プロパティに格納される CaInvalid クラスインスタンスのメッセージを確認してください。
23
- */
24
- declare class CaInvalid extends Error {
25
- result: CaDecodingFailure;
26
- static get code(): string;
27
- readonly code: string;
28
- constructor(message: string, result: CaDecodingFailure);
29
- }
30
- /**
31
- * Content Attestation 検証失敗
32
- *
33
- * Content Attestation の検証に失敗しました。詳細は result プロパティに格納される CaVerifyFailed クラスインスタンスのメッセージを確認してください。
34
- **/
35
- declare class CaVerifyFailed extends Error {
36
- result: CaVerificationFailure;
37
- static get code(): string;
38
- readonly code: string;
39
- constructor(message: string, result: CaVerificationFailure);
40
- }
41
-
42
- /**
43
- * `digestSRI` の検証
44
- * @see {@link https://www.w3.org/TR/SRI/#the-integrity-attribute}
45
- * @example
46
- * ```ts
47
- * const content = {
48
- * id: "<URL>",
49
- * digestSRI: "sha256-...",
50
- * };
51
- *
52
- * await verifyDigestSri(content); // true or false
53
- * ```
54
- */
55
- declare function verifyDigestSri(content: DigestSriResult, fetcher?: typeof fetch): Promise<boolean>;
56
- /**
57
- * Image の digestSRI を検証する。
58
- * 後方互換性の観点で、2027年までは検証失敗時に console.warn のみで処理を中断しない。
59
- */
60
- declare function verifyImageDigestSri(value: Image | undefined, fetcher?: typeof fetch): Promise<void>;
61
-
62
- declare class IntegrityFetchFailed extends Error {
63
- static get code(): "ERR_INTEGRITY_FETCH_FAILED";
64
- readonly code: "ERR_INTEGRITY_FETCH_FAILED";
65
- readonly ok = false;
66
- /** 取得結果 */
67
- result?: Error;
68
- constructor(message: string, result: IntegrityFetchFailed["result"]);
69
- }
70
- declare class IntegrityVerificationFailed extends Error {
71
- static get code(): "ERR_INTEGRITY_VERIFICATION_FAILED";
72
- readonly code: "ERR_INTEGRITY_VERIFICATION_FAILED";
73
- readonly ok = false;
74
- /** 取得結果 */
75
- result?: unknown;
76
- constructor(message: string, result: IntegrityVerificationFailed["result"]);
77
- }
78
-
79
- type IntegrityVerifyResult = {
80
- valid: boolean;
81
- failedIntegrities: ReadonlyArray<string>;
82
- };
83
- type FetchIntegrityResult = IntegrityVerifyResult | IntegrityFetchFailed | IntegrityVerificationFailed;
84
-
85
- /** Target Integrity のコンテンツ取得・要素位置特定アルゴリズム */
86
- declare const TargetIntegrityAlgorithm: {
87
- HtmlTargetIntegrity: {
88
- contentFetcher: ContentFetcher;
89
- elementSelector: ElementSelector;
90
- };
91
- TextTargetIntegrity: {
92
- contentFetcher: ContentFetcher;
93
- elementSelector: ElementSelector;
94
- };
95
- VisibleTextTargetIntegrity: {
96
- contentFetcher: ContentFetcher;
97
- elementSelector: ElementSelector;
98
- };
99
- ExternalResourceTargetIntegrity: {
100
- contentFetcher: ContentFetcher;
101
- elementSelector: ElementSelector;
102
- };
103
- };
104
- /**
105
- * Target Integrity の検証
106
- * @see {@link https://docs.originator-profile.org/opb/content-integrity-descriptor/}
107
- * @example
108
- * ```ts
109
- * const content = {
110
- * type: "HtmlTargetIntegrity", // or ***TargetIntegrity
111
- * cssSelector: "<CSS セレクター>",
112
- * integrity: "sha256-...",
113
- * };
114
- *
115
- * await verifyIntegrity(content); // true or false
116
- * ```
117
- */
118
- declare function verifyIntegrity(content: Target, doc?: Document, fetcher?: typeof fetch): Promise<FetchIntegrityResult>;
119
- type VerifyIntegrity = typeof verifyIntegrity;
120
-
121
- /**
122
- * Content Attestation 検証機の作成
123
- * @param ca Content Attestation
124
- * @param keys Content Attestation の発行者の検証鍵
125
- * @param issuer Content Attestation の発行者
126
- * @param url 検証対象のURL
127
- * @param verifyIntegrity Target Integrity の検証器
128
- * @param validator バリデーター
129
- * @returns 検証機
130
- */
131
- declare function CaVerifier<T extends ContentAttestation>(ca: string, keys: Keys, issuer: string, url: URL, verifyIntegrity?: VerifyIntegrity, validator?: VcValidator<VerifiedCa<T>>): () => Promise<CaVerificationResult<T>>;
132
-
133
- /** COntent Attestation Set 要素 */
134
- type CasItem<Ca> = {
135
- main: boolean;
136
- attestation: Ca;
137
- };
138
- /** 検証済み Content Attestation Set */
139
- type VerifiedCas<Ca extends ContentAttestation = ContentAttestation> = Array<CasItem<VerifiedCa<Ca>>>;
140
- /** Content Attestation Set 検証失敗 */
141
- type CasVerificationFailure = Exclude<CasItem<CaVerificationResult>, CaVerificationResult>[];
142
- /** Content Attestation Set 検証結果 */
143
- type CasVerificationResult<T extends ContentAttestation = ContentAttestation> = VerifiedCas<T> | CasVerifyFailed;
144
-
145
- /**
146
- * Content Attestation Set 検証失敗
147
- *
148
- * Content Attestation Set の検証に失敗しました。詳細は result プロパティに格納される CaVerifyFailed クラスインスタンスのメッセージを確認してください。
149
- **/
150
- declare class CasVerifyFailed extends Error {
151
- result: CasVerificationFailure;
152
- static get code(): string;
153
- readonly code: string;
154
- constructor(message: string, result: CasVerificationFailure);
155
- }
156
-
157
- /**
158
- * Content Attestation Set 要素の正規化
159
- *
160
- * @example
161
- * ```ts
162
- * const cas = ["eyJ...", { main: true, attestation: "eyJ..." }];
163
- * const normalized = normalizeCasItem(cas);
164
- * normalized; // [{ main: false, attestation: "eyJ..." }, { main: true, attestation: "eyJ..." }]
165
- * ```
166
- * */
167
- declare function normalizeCasItem<Ca>(ca: Ca | CasItem<Ca>): CasItem<Ca>;
168
-
169
- /**
170
- * Content Attestation Set の検証
171
- * @param cas Content Attestation Set
172
- * @param verifiedOps 検証済み Originator Profile Set
173
- * @param url 検証対象のURL
174
- * @param verifyIntegrity Target Integrity の検証器
175
- * @param validator バリデーター
176
- * @returns CAS 検証結果
177
- *
178
- * @example
179
- * ```ts
180
- * import { verifyIntegirty } from "@originator-profile/verify";
181
- *
182
- * const cas = ["eyJ...", { main: true, attestation: "eyJ..." }];
183
- * const verifiedOps; // VerifiedOps
184
- * const url = location.href;
185
- * const verified = await verifyCas(cas, verifiedOps, url, verifyIntegrity);
186
- * if (verified instanceof Error) {
187
- * verified; // CasVerifyFailed
188
- * process.exit(1);
189
- * }
190
- * verified; // VerifiedCas
191
- * ```
192
- */
193
- declare function verifyCas<T extends ContentAttestation = ContentAttestation>(cas: ContentAttestationSet, verifiedOps: VerifiedOps, url: string, verifyIntegrity: VerifyIntegrity, validator?: typeof VcValidator): Promise<CasVerificationResult<T>>;
194
-
195
- // Definitions by: Eddie Atkinson <https://github.com/eddie-atkinson>
196
-
197
- type Operation = "add" | "replace" | "remove" | "move";
198
-
199
- type DiffOps = Array<{
200
- op: Operation;
201
- path: Array<string | number>;
202
- value?: any;
203
- }>;
204
- type PathConverter = (path: string) => string[];
205
-
206
- declare function diffApply<T extends object>(
207
- obj: T,
208
- diff: DiffOps,
209
- pathConverter?: PathConverter
210
- ): T;
211
-
212
- /**
213
- * JSON Patch を適用する関数
214
- *
215
- * @link https://jsonpatch.com/
216
- */
217
- declare const patch: <T extends object>(...args: Parameters<typeof diffApply<T>>) => T;
218
- /**
219
- * VerifyResult ファクトリー
220
- *
221
- * @link https://reference.originator-profile.org/ts/types/_originator-profile_securing-mechanism.UnverifiedJwtVc
222
- * @link https://reference.originator-profile.org/ts/types/_originator-profile_securing-mechanism.VerifiedJwtVc
223
- */
224
- declare const VerifyResultFactory: (issuedAt: Date, expiredAt: Date) => {
225
- create: (vc: OpVc, jwt: string, verificationKey?: Jwk, validated?: boolean) => UnverifiedJwtVc<OpVc> | VerifiedJwtVc<OpVc>;
226
- };
227
- /** OP ID Constants */
228
- declare const opId: {
229
- /** CP 発行者 */
230
- authority: "dns:cp-issuer.example.org";
231
- /** PA 発行者 */
232
- certifier: "dns:pa-issuer.example.org";
233
- /** CA 発行者 */
234
- originator: "dns:originator.example.org";
235
- /** 無効な第三者 */
236
- invalid: "dns:invalid.example.org";
237
- };
238
- /** Core Profile */
239
- declare const cp: CoreProfile;
240
- /** Certificate */
241
- declare const certificate: Certificate$1;
242
- /** Web Media Profile */
243
- declare const wmp: WebMediaProfile;
244
- /** Website Profile */
245
- declare const wsp: WebsiteProfile;
246
- /** CA ID */
247
- declare const caId = "urn:uuid:78550fa7-f846-4e0f-ad5c-8d34461cb95b";
248
- /** CA URL */
249
- declare const caUrl: URL;
250
- /** Article CA */
251
- declare const article: ArticleCA;
252
-
253
- /**
254
- * Originator Profile Set 無効
255
- *
256
- * Originator Profile Set が無効な形式です。詳細は result プロパティに格納される OpInvalid クラスインスタンスのメッセージを確認してください。
257
- */
258
- declare class OpsInvalid extends Error {
259
- result: OpsDecodingFailure;
260
- static get code(): string;
261
- readonly code: string;
262
- constructor(message: string, result: OpsDecodingFailure);
263
- }
264
- /**
265
- * Originator Profile 無効
266
- *
267
- * Originator Profile が無効な形式です。次の原因で使用されます。
268
- *
269
- * - Core Profile の復号に失敗した
270
- * - Profile Annotation の復号に失敗した
271
- * - Web Media Profile の復号に失敗した
272
- * - Core Profile と Profile Annotation の `credentialSubject.id` が不一致
273
- * - Core Profile と Web Media Profile の `credentialSubject.id` が不一致
274
- */
275
- declare class OpInvalid extends Error {
276
- result: OpDecodingFailure;
277
- static get code(): string;
278
- readonly code: string;
279
- constructor(message: string, result: OpDecodingFailure);
280
- }
281
- /**
282
- * Core Profile 未発見
283
- *
284
- * Core Profile が見つかりませんでした。次の原因で使用されます。
285
- *
286
- * - Core Profile が Originator Profile Set に含まれていない
287
- * - Core Profile の検証結果が見つからなかった
288
- */
289
- declare class CoreProfileNotFound<T extends OpVc> extends Error {
290
- result: UnverifiedJwtVc<T>;
291
- static get code(): string;
292
- readonly code: string;
293
- constructor(message: string, result: UnverifiedJwtVc<T>);
294
- }
295
- /**
296
- * Originator Profile Set 検証失敗
297
- *
298
- * Originator Profile Set の検証に失敗しました。詳細は result プロパティに格納される OpVerifyFailed クラスインスタンスのメッセージを確認してください。
299
- **/
300
- declare class OpsVerifyFailed extends Error {
301
- result: OpsVerificationFailure;
302
- static get code(): string;
303
- readonly code: string;
304
- constructor(message: string, result: OpsVerificationFailure);
305
- }
306
- /**
307
- * Originator Profile 検証失敗
308
- *
309
- * Originator Profile の検証に失敗しました。次の原因で使用されます。
310
- *
311
- * - Core Profile の検証に失敗した
312
- * - Profile Annotation の検証に失敗した
313
- * - Web Media Profile の検証に失敗した
314
- *
315
- * ここでの検証の失敗とは、次の原因を含みます。
316
- *
317
- * - 復号に失敗した
318
- * - Core Profile の検証結果が見つからなかった
319
- * - Profile Annotation 発行者の Core Profile が見つからなかった
320
- * - Web Media Profile 発行者の Core Profile が見つからなかった
321
- * - 署名の検証に失敗した
322
- **/
323
- declare class OpVerifyFailed extends Error {
324
- result: OpVerificationFailure;
325
- static get code(): string;
326
- readonly code: string;
327
- constructor(message: string, result: OpVerificationFailure);
328
- }
329
- /**
330
- * 証明書の有効期限エラー
331
- *
332
- * 証明書の有効期限チェックに失敗しました。次の原因で使用されます。
333
- *
334
- * - 証明書の有効期限が開始していない (validFrom より前)
335
- * - 証明書の有効期限が切れている (validUntil より後)
336
- *
337
- * なお、validFrom と validUntil はオプショナルフィールドのため、
338
- * 片方のみが指定されている場合もあります。
339
- **/
340
- declare class CertificateExpired<T extends OpVc> extends Error {
341
- result: VerifiedJwtVc<T>;
342
- static get code(): string;
343
- readonly code: string;
344
- constructor(message: string, result: VerifiedJwtVc<T>);
345
- }
346
-
347
- type Certificate = Certificate$1 | JapaneseExistenceCertificate;
348
- /** Originator Profile 復号失敗 */
349
- type OpDecodingFailure = {
350
- core: JwtVcDecodingResult<CoreProfile>;
351
- annotations?: JwtVcDecodingResult<Certificate>[];
352
- media?: JwtVcDecodingResult<WebMediaProfile>[];
353
- };
354
- /** 復号済み Originator Profile */
355
- type DecodedOp = {
356
- core: UnverifiedJwtVc<CoreProfile>;
357
- annotations?: UnverifiedJwtVc<Certificate>[];
358
- media?: UnverifiedJwtVc<WebMediaProfile>[];
359
- };
360
- /** Originator Profile 復号結果 */
361
- type OpDecodingResult = DecodedOp | OpInvalid;
362
- /** Originator Profile Set 復号失敗 */
363
- type OpsDecodingFailure = OpDecodingResult[];
364
- /** 復号済み Originator Profile Set */
365
- type DecodedOps = DecodedOp[];
366
- /** Originator Profile Set 復号結果 */
367
- type OpsDecodingResult = DecodedOps | OpsInvalid;
368
- /** Originator Profile 検証失敗 */
369
- type OpVerificationFailure = {
370
- core: JwtVcVerificationResult<CoreProfile> | CoreProfileNotFound<CoreProfile>;
371
- annotations?: (JwtVcVerificationResult<Certificate> | CoreProfileNotFound<Certificate>)[];
372
- media?: (JwtVcVerificationResult<WebMediaProfile> | CoreProfileNotFound<WebMediaProfile>)[];
373
- };
374
- /** 検証済み Originator Profile */
375
- type VerifiedOp = {
376
- core: VerifiedJwtVc<CoreProfile>;
377
- annotations?: VerifiedJwtVc<Certificate>[];
378
- media?: VerifiedJwtVc<WebMediaProfile>[];
379
- };
380
- /** Originator Profile 検証結果 */
381
- type OpVerificationResult = VerifiedOp | OpVerifyFailed;
382
- /** Originator Profile Set 検証失敗 */
383
- type OpsVerificationFailure = OpVerificationResult[];
384
- /** 検証済み Originator Profile Set */
385
- type VerifiedOps = VerifiedOp[];
386
- /** Originator Profile Set 検証結果 */
387
- type OpsVerificationResult = VerifiedOps | OpsInvalid | OpsVerifyFailed;
388
-
389
- /**
390
- * Originator Profile Set の復号
391
- * @param ops Originator Profile Set
392
- * @returns 復号結果
393
- */
394
- declare function decodeOps(ops: OriginatorProfileSet): OpsDecodingResult;
395
-
396
- /**
397
- * Originator Profile Set の検証者の作成
398
- * @param ops Originator Profile Set
399
- * @param keys Core Profile の発行者の検証鍵
400
- * @param issuer Core Profile の発行者
401
- * @param validator バリデーター
402
- * @returns 検証者
403
- */
404
- declare function OpsVerifier(ops: OriginatorProfileSet, keys: Keys, issuer: string | string[], validator?: typeof VcValidator): () => Promise<OpsVerificationResult>;
405
-
406
- type OpId = string;
407
- /**
408
- * OPS から鍵を取得する
409
- * @returns OP ID, JWKS の連想配列
410
- */
411
- declare function getMappedKeys(ops: DecodedOps): Record<OpId, Jwks>;
412
- type MappedKeys = ReturnType<typeof getMappedKeys>;
413
- /**
414
- * OPS から鍵を取得する
415
- * @returns OP ID, Keys のタプル
416
- * @remarks
417
- *
418
- * この実装は複数のissuerと鍵束を一つの組にするので、
419
- * 事前にissuerが特定できる場合にはgetMappedKeys()を優先して使用すべきです
420
- *
421
- * @see https://github.com/originator-profile/originator-profile/issues/90
422
- */
423
- declare function getTupledKeys(ops: DecodedOps): [opId: OpId | OpId[], Keys];
424
- type TupledKeys = ReturnType<typeof getTupledKeys>;
425
-
426
- declare class SiteProfileInvalid extends Error {
427
- result: SpVerificationFailure;
428
- static get code(): "ERR_SITE_PROFILE_INVALID";
429
- readonly code: "ERR_SITE_PROFILE_INVALID";
430
- constructor(message: string, result: SpVerificationFailure);
431
- }
432
- declare class SiteProfileVerifyFailed extends Error {
433
- result: SpVerificationFailure;
434
- static get code(): "ERR_SITE_PROFILE_VERIFY_FAILED";
435
- readonly code: "ERR_SITE_PROFILE_VERIFY_FAILED";
436
- constructor(message: string, result: SpVerificationFailure);
437
- }
438
-
439
- /** Site Profile 検証失敗 */
440
- type SpVerificationFailure = {
441
- originators: OpsVerificationResult;
442
- sites: (JwtVcVerificationResult<WebsiteProfile> | JwtVcDecodingResult<WebsiteProfile> | CoreProfileNotFound<WebsiteProfile>)[];
443
- };
444
- type VerifiedSp = {
445
- originators: VerifiedOps;
446
- sites: VerifiedJwtVc<WebsiteProfile>[];
447
- };
448
- type SpVerificationResult = VerifiedSp | SiteProfileInvalid | SiteProfileVerifyFailed;
449
-
450
- /**
451
- * Site Profile の検証者の作成
452
- * @param sp Site Profile
453
- * @param keys Core Profile の発行者の検証鍵
454
- * @param issuer Core Profile の発行者
455
- * @param origin 提示するWebサイトを識別するための RFC 6454 オリジン
456
- * @param verifyOrigin WSPが提示されたWebサイトのorigin引数との一致性検証の可否 (デフォルト: 有効)
457
- * @param validator バリデーター
458
- * @returns 検証者
459
- */
460
- declare function SpVerifier(sp: SiteProfile, keys: Keys, issuer: string | string[], origin: URL["origin"], verifyOrigin?: boolean, validator?: typeof VcValidator): () => Promise<SpVerificationResult>;
461
-
462
- /**
463
- * URLオリジンが対象のオリジンの中に含まれているのか検証する
464
- * @param origin 対象とするオリジン
465
- * @param allowedOrigins 情報の対象となるオリジン
466
- * @returns 検証結果: allowedOriginsの中にoriginが含まれていればtrue, それ以外ならfalse
467
- */
468
- declare function verifyAllowedOrigin(origin: URL["origin"], allowedOrigins: AllowedOrigin): boolean;
469
-
470
- export { CaInvalid, CaVerifier, CaVerifyFailed, CasVerifyFailed, CertificateExpired, CoreProfileNotFound, IntegrityFetchFailed, IntegrityVerificationFailed, OpInvalid, OpVerifyFailed, OpsInvalid, OpsVerifier, OpsVerifyFailed, SiteProfileInvalid, SiteProfileVerifyFailed, SpVerifier, TargetIntegrityAlgorithm, VerifyResultFactory, article, caId, caUrl, certificate, cp, decodeOps, getMappedKeys, getTupledKeys, normalizeCasItem, opId, patch, verifyAllowedOrigin, verifyCas, verifyDigestSri, verifyImageDigestSri, verifyIntegrity, wmp, wsp };
471
- export type { CaDecodingFailure, CaDecodingResult, CaVerificationFailure, CaVerificationResult, CasItem, CasVerificationFailure, CasVerificationResult, Certificate, DecodedCa, DecodedOp, DecodedOps, FetchIntegrityResult, IntegrityVerifyResult, MappedKeys, OpDecodingFailure, OpDecodingResult, OpVerificationFailure, OpVerificationResult, OpsDecodingFailure, OpsDecodingResult, OpsVerificationFailure, OpsVerificationResult, SpVerificationFailure, SpVerificationResult, TupledKeys, VerifiedCa, VerifiedCas, VerifiedOp, VerifiedOps, VerifiedSp, VerifyIntegrity };
File without changes