@originator-profile/opvc 0.5.0-beta.2 → 0.5.0-beta.3

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 CHANGED
@@ -122,7 +122,7 @@ FLAG DESCRIPTIONS
122
122
  }
123
123
  ```
124
124
 
125
- _See code: [src/commands/ca/sign.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.2/packages/opvc/src/commands/ca/sign.ts)_
125
+ _See code: [src/commands/ca/sign.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.3/packages/opvc/src/commands/ca/sign.ts)_
126
126
 
127
127
  ## `opvc ca:unsigned`
128
128
 
@@ -207,7 +207,7 @@ FLAG DESCRIPTIONS
207
207
  }
208
208
  ```
209
209
 
210
- _See code: [src/commands/ca/unsigned.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.2/packages/opvc/src/commands/ca/unsigned.ts)_
210
+ _See code: [src/commands/ca/unsigned.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.3/packages/opvc/src/commands/ca/unsigned.ts)_
211
211
 
212
212
  ## `opvc help [COMMAND]`
213
213
 
@@ -245,7 +245,7 @@ DESCRIPTION
245
245
  鍵ペアの生成
246
246
  ```
247
247
 
248
- _See code: [src/commands/key-gen/index.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.2/packages/opvc/src/commands/key-gen/index.ts)_
248
+ _See code: [src/commands/key-gen/index.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.3/packages/opvc/src/commands/key-gen/index.ts)_
249
249
 
250
250
  ## `opvc sign`
251
251
 
@@ -412,7 +412,7 @@ FLAG DESCRIPTIONS
412
412
  }
413
413
  ```
414
414
 
415
- _See code: [src/commands/sign.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.2/packages/opvc/src/commands/sign.ts)_
415
+ _See code: [src/commands/sign.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.3/packages/opvc/src/commands/sign.ts)_
416
416
 
417
417
  ## `opvc wsp:unsigned`
418
418
 
@@ -477,10 +477,56 @@ FLAG DESCRIPTIONS
477
477
  }
478
478
  ```
479
479
 
480
- _See code: [src/commands/wsp/unsigned.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.2/packages/opvc/src/commands/wsp/unsigned.ts)_
480
+ _See code: [src/commands/wsp/unsigned.ts](https://github.com/originator-profile/originator-profile/blob/v0.5.0-beta.3/packages/opvc/src/commands/wsp/unsigned.ts)_
481
481
  <!-- commandsstop -->
482
482
  <!-- prettier-ignore-end -->
483
483
 
484
+ ## Node.js から利用する
485
+
486
+ `@originator-profile/opvc` は TypeScript/JavaScript からも利用できます。
487
+
488
+ ### ローカル環境でのContent Attestationの署名
489
+
490
+ ローカルのプライベート鍵で署名する場合は `ContentAttestation.sign()` を使います。
491
+
492
+ ```ts
493
+ import { ContentAttestation } from "@originator-profile/opvc";
494
+
495
+ const jwt = await ContentAttestation.sign(input, privateKey, {
496
+ issuedAt: new Date(),
497
+ expiredAt: "2027-03-31",
498
+ });
499
+ ```
500
+
501
+ ### 未署名 Content Attestation の取得
502
+
503
+ 未署名の Content Attestation が必要な場合は `ContentAttestation.unsignedCa()` を使えます。
504
+
505
+ ```ts
506
+ import { ContentAttestation } from "@originator-profile/opvc";
507
+
508
+ const uca = await ContentAttestation.unsignedCa(input, {
509
+ issuedAt: new Date(),
510
+ expiredAt: "2027-03-31",
511
+ });
512
+ ```
513
+
514
+ ### CA Server経由での署名
515
+
516
+ CA Server で署名する場合は `ContentAttestation.signByServer()` を使います。
517
+ 内部では未署名 Content Attestation を組み立てて CA server に送信し、返却された JWT を受け取ります。
518
+
519
+ ```ts
520
+ import { ContentAttestation } from "@originator-profile/opvc";
521
+
522
+ const jwt = await ContentAttestation.signByServer(input, {
523
+ endpoint: "https://example.com/ca",
524
+ accessToken: process.env.CA_SERVER_ACCESS_TOKEN!,
525
+ issuedAt: new Date(),
526
+ expiredAt: "2027-03-31",
527
+ });
528
+ ```
529
+
484
530
  ## Development
485
531
 
486
532
  ```sh
@@ -1,12 +1,12 @@
1
1
  import { Command } from "@oclif/core";
2
- import * as _oclif_core_interfaces5 from "@oclif/core/interfaces";
2
+ import * as _oclif_core_interfaces9 from "@oclif/core/interfaces";
3
3
 
4
4
  //#region src/commands/ca/sign.d.ts
5
5
  declare class CaSign extends Command {
6
6
  static summary: string;
7
7
  static description: string;
8
8
  static flags: {
9
- identity: _oclif_core_interfaces5.OptionFlag<{
9
+ identity: _oclif_core_interfaces9.OptionFlag<{
10
10
  [x: string]: unknown;
11
11
  kty: string;
12
12
  kid: string;
@@ -17,10 +17,10 @@ declare class CaSign extends Command {
17
17
  x5c?: string[] | undefined;
18
18
  x5t?: string | undefined;
19
19
  "x5t#S256"?: string | undefined;
20
- }, _oclif_core_interfaces5.CustomOptions>;
21
- input: _oclif_core_interfaces5.OptionFlag<string, _oclif_core_interfaces5.CustomOptions>;
22
- "issued-at": _oclif_core_interfaces5.OptionFlag<string | undefined, _oclif_core_interfaces5.CustomOptions>;
23
- "expired-at": _oclif_core_interfaces5.OptionFlag<Date | undefined, _oclif_core_interfaces5.CustomOptions>;
20
+ }, _oclif_core_interfaces9.CustomOptions>;
21
+ input: _oclif_core_interfaces9.OptionFlag<string, _oclif_core_interfaces9.CustomOptions>;
22
+ "issued-at": _oclif_core_interfaces9.OptionFlag<string | undefined, _oclif_core_interfaces9.CustomOptions>;
23
+ "expired-at": _oclif_core_interfaces9.OptionFlag<Date | undefined, _oclif_core_interfaces9.CustomOptions>;
24
24
  };
25
25
  static examples: string[];
26
26
  run(): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { n as sign } from "../../content-attestation-rNiF6uH4.mjs";
1
+ import { n as sign } from "../../content-attestation-M-2LmatR.mjs";
2
2
  import { r as privateKey, t as expirationDate } from "../../flags-CFmMpf5A.mjs";
3
3
  import { Command, Flags } from "@oclif/core";
4
4
  import fs from "node:fs/promises";
@@ -1,14 +1,14 @@
1
1
  import { Command } from "@oclif/core";
2
- import * as _oclif_core_interfaces13 from "@oclif/core/interfaces";
2
+ import * as _oclif_core_interfaces25 from "@oclif/core/interfaces";
3
3
 
4
4
  //#region src/commands/ca/unsigned.d.ts
5
5
  declare class CaUnsigned extends Command {
6
6
  static summary: string;
7
7
  static description: string;
8
8
  static flags: {
9
- input: _oclif_core_interfaces13.OptionFlag<string, _oclif_core_interfaces13.CustomOptions>;
10
- "issued-at": _oclif_core_interfaces13.OptionFlag<string | undefined, _oclif_core_interfaces13.CustomOptions>;
11
- "expired-at": _oclif_core_interfaces13.OptionFlag<Date | undefined, _oclif_core_interfaces13.CustomOptions>;
9
+ input: _oclif_core_interfaces25.OptionFlag<string, _oclif_core_interfaces25.CustomOptions>;
10
+ "issued-at": _oclif_core_interfaces25.OptionFlag<string | undefined, _oclif_core_interfaces25.CustomOptions>;
11
+ "expired-at": _oclif_core_interfaces25.OptionFlag<Date | undefined, _oclif_core_interfaces25.CustomOptions>;
12
12
  };
13
13
  static examples: string[];
14
14
  run(): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { r as unsignedCa } from "../../content-attestation-rNiF6uH4.mjs";
1
+ import { r as unsignedCa } from "../../content-attestation-M-2LmatR.mjs";
2
2
  import { t as expirationDate } from "../../flags-CFmMpf5A.mjs";
3
3
  import { Command, Flags } from "@oclif/core";
4
4
  import fs from "node:fs/promises";
@@ -1,11 +1,11 @@
1
1
  import { Command } from "@oclif/core";
2
- import * as _oclif_core_interfaces29 from "@oclif/core/interfaces";
2
+ import * as _oclif_core_interfaces23 from "@oclif/core/interfaces";
3
3
 
4
4
  //#region src/commands/key-gen/index.d.ts
5
5
  declare class KeyGen extends Command {
6
6
  static description: string;
7
7
  static flags: {
8
- output: _oclif_core_interfaces29.OptionFlag<string, _oclif_core_interfaces29.CustomOptions>;
8
+ output: _oclif_core_interfaces23.OptionFlag<string, _oclif_core_interfaces23.CustomOptions>;
9
9
  };
10
10
  run(): Promise<void>;
11
11
  }
@@ -1,12 +1,12 @@
1
1
  import { Command } from "@oclif/core";
2
- import * as _oclif_core_interfaces19 from "@oclif/core/interfaces";
2
+ import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
3
3
 
4
4
  //#region src/commands/sign.d.ts
5
5
  declare class VcSign extends Command {
6
6
  static summary: string;
7
7
  static description: string;
8
8
  static flags: {
9
- identity: _oclif_core_interfaces19.OptionFlag<{
9
+ identity: _oclif_core_interfaces0.OptionFlag<{
10
10
  [x: string]: unknown;
11
11
  kty: string;
12
12
  kid: string;
@@ -17,11 +17,11 @@ declare class VcSign extends Command {
17
17
  x5c?: string[] | undefined;
18
18
  x5t?: string | undefined;
19
19
  "x5t#S256"?: string | undefined;
20
- }, _oclif_core_interfaces19.CustomOptions>;
21
- id: _oclif_core_interfaces19.OptionFlag<string | undefined, _oclif_core_interfaces19.CustomOptions>;
22
- input: _oclif_core_interfaces19.OptionFlag<string, _oclif_core_interfaces19.CustomOptions>;
23
- "issued-at": _oclif_core_interfaces19.OptionFlag<string | undefined, _oclif_core_interfaces19.CustomOptions>;
24
- "expired-at": _oclif_core_interfaces19.OptionFlag<Date | undefined, _oclif_core_interfaces19.CustomOptions>;
20
+ }, _oclif_core_interfaces0.CustomOptions>;
21
+ id: _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
22
+ input: _oclif_core_interfaces0.OptionFlag<string, _oclif_core_interfaces0.CustomOptions>;
23
+ "issued-at": _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
24
+ "expired-at": _oclif_core_interfaces0.OptionFlag<Date | undefined, _oclif_core_interfaces0.CustomOptions>;
25
25
  };
26
26
  static examples: string[];
27
27
  run(): Promise<void>;
@@ -1,14 +1,14 @@
1
1
  import { Command } from "@oclif/core";
2
- import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
2
+ import * as _oclif_core_interfaces17 from "@oclif/core/interfaces";
3
3
 
4
4
  //#region src/commands/wsp/unsigned.d.ts
5
5
  declare class WspUnsigned extends Command {
6
6
  static summary: string;
7
7
  static description: string;
8
8
  static flags: {
9
- input: _oclif_core_interfaces0.OptionFlag<string, _oclif_core_interfaces0.CustomOptions>;
10
- "issued-at": _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
11
- "expired-at": _oclif_core_interfaces0.OptionFlag<Date | undefined, _oclif_core_interfaces0.CustomOptions>;
9
+ input: _oclif_core_interfaces17.OptionFlag<string, _oclif_core_interfaces17.CustomOptions>;
10
+ "issued-at": _oclif_core_interfaces17.OptionFlag<string | undefined, _oclif_core_interfaces17.CustomOptions>;
11
+ "expired-at": _oclif_core_interfaces17.OptionFlag<Date | undefined, _oclif_core_interfaces17.CustomOptions>;
12
12
  };
13
13
  static examples: string[];
14
14
  run(): Promise<void>;
@@ -0,0 +1,122 @@
1
+ import { t as __export } from "./chunk-DJTHdtxa.mjs";
2
+ import { JSDOM } from "jsdom";
3
+ import { parseExpirationDate } from "@originator-profile/core";
4
+ import { fetchAndSetDigestSri, fetchAndSetTargetIntegrity, signCa } from "@originator-profile/sign";
5
+ import { addYears, getUnixTime } from "date-fns";
6
+ import { BadRequestError } from "http-errors-enhanced";
7
+
8
+ //#region src/document-provider.ts
9
+ async function documentProvider({ type, content = "" }) {
10
+ if (type === "ExternalResourceTargetIntegrity") throw new Error("ExternalResourceTargetIntegrity is not supported in this context.");
11
+ if (Array.isArray(content) && content.length > 1) throw new Error("Multiple contents are not supported in this context.");
12
+ [content] = [content].flat();
13
+ let url;
14
+ let html = "";
15
+ if (URL.canParse(content)) {
16
+ url = content;
17
+ html = await fetch(url).then((res) => res.text());
18
+ } else {
19
+ url = void 0;
20
+ html = content;
21
+ }
22
+ return new JSDOM(html, { url }).window.document;
23
+ }
24
+
25
+ //#endregion
26
+ //#region src/content-attestation.ts
27
+ var content_attestation_exports = /* @__PURE__ */ __export({
28
+ sign: () => sign,
29
+ signByServer: () => signByServer,
30
+ unsignedCa: () => unsignedCa
31
+ });
32
+ function assertValidDate(value, fieldName) {
33
+ if (Number.isNaN(value.getTime())) throw new BadRequestError(`${fieldName} must be a valid date.`);
34
+ }
35
+ function parseDates({ issuedAt: issuedAtDateOrString = /* @__PURE__ */ new Date(), expiredAt: expiredAtDateOrString = addYears(/* @__PURE__ */ new Date(), 1) }) {
36
+ const issuedAt = new Date(issuedAtDateOrString);
37
+ const expiredAt = typeof expiredAtDateOrString === "string" ? parseExpirationDate(expiredAtDateOrString) : new Date(expiredAtDateOrString);
38
+ assertValidDate(issuedAt, "issuedAt");
39
+ assertValidDate(expiredAt, "expiredAt");
40
+ return {
41
+ issuedAt,
42
+ expiredAt
43
+ };
44
+ }
45
+ async function prepareUnsignedCa(uca, { integrityAlg = "sha256", documentProvider: documentProvider$1 = documentProvider, ...timingOptions }) {
46
+ const { issuedAt, expiredAt } = parseDates(timingOptions);
47
+ uca.credentialSubject.id ??= `urn:uuid:${crypto.randomUUID()}`;
48
+ try {
49
+ await fetchAndSetDigestSri(integrityAlg, uca.credentialSubject.image);
50
+ await fetchAndSetTargetIntegrity(integrityAlg, uca, documentProvider$1);
51
+ } catch (e) {
52
+ throw new BadRequestError(e.message);
53
+ }
54
+ return {
55
+ ...uca,
56
+ iss: uca.issuer,
57
+ sub: uca.credentialSubject.id,
58
+ iat: getUnixTime(issuedAt),
59
+ exp: getUnixTime(expiredAt)
60
+ };
61
+ }
62
+ /**
63
+ * Content Attestation への署名
64
+ * @param uca 未署名 Content Attestation オブジェクト
65
+ * @param privateKey プライベート鍵
66
+ * @return Content Attestation
67
+ */
68
+ async function sign(uca, privateKey, options = {}) {
69
+ const { issuedAt, expiredAt } = parseDates(options);
70
+ uca.credentialSubject.id ??= `urn:uuid:${crypto.randomUUID()}`;
71
+ return await signCa(uca, privateKey, {
72
+ issuedAt,
73
+ expiredAt,
74
+ documentProvider
75
+ });
76
+ }
77
+ /**
78
+ * 未署名 Content Attestation の取得
79
+ * @param uca 未署名 Content Attestation オブジェクト
80
+ * @throws {BadRequestError} 検証対象のコンテンツが存在しない/コンテンツにアクセスできない/Integrityの計算に失敗
81
+ * @return 未署名 Content Attestation オブジェクト
82
+ */
83
+ async function unsignedCa(uca, options) {
84
+ return await prepareUnsignedCa(uca, options);
85
+ }
86
+ /**
87
+ * CA server 経由で Content Attestation を作成
88
+ * @param uca 未署名 Content Attestation オブジェクト
89
+ * @param options Content Attestation の生成オプション
90
+ * @param options.endpoint CA server のエンドポイント URL
91
+ * @param options.accessToken CA server 呼び出しに利用する Bearer トークン
92
+ * @return JWT でエンコードされた Content Attestation
93
+ */
94
+ async function signByServer(uca, { endpoint, accessToken, ...options }) {
95
+ const payload = await prepareUnsignedCa(uca, options);
96
+ const response = await fetch(endpoint, {
97
+ method: "POST",
98
+ headers: {
99
+ "Content-Type": "application/json",
100
+ Authorization: `Bearer ${accessToken}`
101
+ },
102
+ body: JSON.stringify(payload)
103
+ });
104
+ if (!response.ok) {
105
+ const responseBody$1 = await response.text();
106
+ throw new Error(`CA API error: ${response.status} ${response.statusText}: ${responseBody$1}`);
107
+ }
108
+ const responseBody = (await response.text()).trim();
109
+ if (responseBody === "") throw new Error("CA API returned no JWT.");
110
+ let result;
111
+ try {
112
+ result = JSON.parse(responseBody);
113
+ } catch {
114
+ return responseBody;
115
+ }
116
+ if (typeof result === "string") return result;
117
+ if (Array.isArray(result) && typeof result[0] === "string") return result[0];
118
+ throw new Error("CA API returned no JWT.");
119
+ }
120
+
121
+ //#endregion
122
+ export { documentProvider as i, sign as n, unsignedCa as r, content_attestation_exports as t };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,6 @@
1
+ import { DocumentProvider } from "@originator-profile/sign";
1
2
  import { Jwk, RawTarget, UnsignedContentAttestation, UnsignedWebsiteProfile } from "@originator-profile/model";
3
+ import { HashAlgorithm } from "websri";
2
4
 
3
5
  //#region src/document-provider.d.ts
4
6
  declare function documentProvider({
@@ -6,34 +8,46 @@ declare function documentProvider({
6
8
  content
7
9
  }: RawTarget): Promise<Document>;
8
10
  declare namespace content_attestation_d_exports {
9
- export { sign, unsignedCa };
11
+ export { sign, signByServer, unsignedCa };
10
12
  }
13
+ type ContentAttestationTimingOptions = {
14
+ issuedAt?: Date | string;
15
+ expiredAt?: Date | string;
16
+ };
17
+ type UnsignedCaOptions = ContentAttestationTimingOptions & {
18
+ integrityAlg?: HashAlgorithm;
19
+ documentProvider?: DocumentProvider;
20
+ };
11
21
  /**
12
22
  * Content Attestation への署名
13
23
  * @param uca 未署名 Content Attestation オブジェクト
14
24
  * @param privateKey プライベート鍵
15
25
  * @return Content Attestation
16
26
  */
17
- declare function sign(uca: UnsignedContentAttestation, privateKey: Jwk, {
18
- issuedAt: issuedAtDateOrString,
19
- expiredAt: expiredAtDateOrString
20
- }: {
21
- issuedAt?: Date | string;
22
- expiredAt?: Date | string;
23
- }): Promise<string>;
27
+ declare function sign(uca: UnsignedContentAttestation, privateKey: Jwk, options?: ContentAttestationTimingOptions): Promise<string>;
24
28
  /**
25
29
  * 未署名 Content Attestation の取得
26
30
  * @param uca 未署名 Content Attestation オブジェクト
27
31
  * @throws {BadRequestError} 検証対象のコンテンツが存在しない/コンテンツにアクセスできない/Integrityの計算に失敗
28
32
  * @return 未署名 Content Attestation オブジェクト
29
33
  */
30
- declare function unsignedCa(uca: UnsignedContentAttestation, {
31
- issuedAt: issuedAtDateOrString,
32
- expiredAt: expiredAtDateOrString
33
- }: {
34
- issuedAt?: Date | string;
35
- expiredAt?: Date | string;
36
- }): Promise<UnsignedContentAttestation>;
34
+ declare function unsignedCa(uca: UnsignedContentAttestation, options: UnsignedCaOptions): Promise<UnsignedContentAttestation>;
35
+ /**
36
+ * CA server 経由で Content Attestation を作成
37
+ * @param uca 未署名 Content Attestation オブジェクト
38
+ * @param options Content Attestation の生成オプション
39
+ * @param options.endpoint CA server のエンドポイント URL
40
+ * @param options.accessToken CA server 呼び出しに利用する Bearer トークン
41
+ * @return JWT でエンコードされた Content Attestation
42
+ */
43
+ declare function signByServer(uca: UnsignedContentAttestation, {
44
+ endpoint,
45
+ accessToken,
46
+ ...options
47
+ }: UnsignedCaOptions & {
48
+ endpoint: string;
49
+ accessToken: string;
50
+ }): Promise<string>;
37
51
  declare namespace website_profile_d_exports {
38
52
  export { unsignedWsp };
39
53
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as documentProvider, t as content_attestation_exports } from "./content-attestation-rNiF6uH4.mjs";
1
+ import { i as documentProvider, t as content_attestation_exports } from "./content-attestation-M-2LmatR.mjs";
2
2
  import { n as website_profile_exports } from "./website-profile-Dhto-mS2.mjs";
3
3
 
4
4
  export { content_attestation_exports as ContentAttestation, website_profile_exports as WebsiteProfile, documentProvider };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@originator-profile/opvc",
3
- "version": "0.5.0-beta.2",
3
+ "version": "0.5.0-beta.3",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://docs.originator-profile.org",
6
6
  "repository": {
@@ -39,11 +39,11 @@
39
39
  "http-errors-enhanced": "^4.0.0",
40
40
  "jose": "^6.0.11",
41
41
  "jsdom": "^27.0.0",
42
- "@originator-profile/core": "0.5.0-beta.2",
43
- "@originator-profile/securing-mechanism": "0.5.0-beta.2",
44
- "@originator-profile/cryptography": "0.5.0-beta.2",
45
- "@originator-profile/sign": "0.5.0-beta.2",
46
- "@originator-profile/model": "0.5.0-beta.2"
42
+ "@originator-profile/core": "0.5.0-beta.3",
43
+ "@originator-profile/cryptography": "0.5.0-beta.3",
44
+ "@originator-profile/model": "0.5.0-beta.3",
45
+ "@originator-profile/sign": "0.5.0-beta.3",
46
+ "@originator-profile/securing-mechanism": "0.5.0-beta.3"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^24.3.1",
@@ -52,8 +52,8 @@
52
52
  "tsdown": "^0.16.7",
53
53
  "typescript": "^5.8.3",
54
54
  "websri": "^1.0.1",
55
- "eslint-config-originator-profile": "0.5.0-beta.2",
56
- "@originator-profile/tsconfig": "0.5.0-beta.2"
55
+ "@originator-profile/tsconfig": "0.5.0-beta.3",
56
+ "eslint-config-originator-profile": "0.5.0-beta.3"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "tsdown && oclif manifest && oclif readme",
@@ -1,73 +0,0 @@
1
- import { t as __export } from "./chunk-DJTHdtxa.mjs";
2
- import { JSDOM } from "jsdom";
3
- import { parseExpirationDate } from "@originator-profile/core";
4
- import { fetchAndSetDigestSri, fetchAndSetTargetIntegrity, signCa } from "@originator-profile/sign";
5
- import { addYears, getUnixTime } from "date-fns";
6
- import { BadRequestError } from "http-errors-enhanced";
7
-
8
- //#region src/document-provider.ts
9
- async function documentProvider({ type, content = "" }) {
10
- if (type === "ExternalResourceTargetIntegrity") throw new Error("ExternalResourceTargetIntegrity is not supported in this context.");
11
- if (Array.isArray(content) && content.length > 1) throw new Error("Multiple contents are not supported in this context.");
12
- [content] = [content].flat();
13
- let url;
14
- let html = "";
15
- if (URL.canParse(content)) {
16
- url = content;
17
- html = await fetch(url).then((res) => res.text());
18
- } else {
19
- url = void 0;
20
- html = content;
21
- }
22
- return new JSDOM(html, { url }).window.document;
23
- }
24
-
25
- //#endregion
26
- //#region src/content-attestation.ts
27
- var content_attestation_exports = /* @__PURE__ */ __export({
28
- sign: () => sign,
29
- unsignedCa: () => unsignedCa
30
- });
31
- /**
32
- * Content Attestation への署名
33
- * @param uca 未署名 Content Attestation オブジェクト
34
- * @param privateKey プライベート鍵
35
- * @return Content Attestation
36
- */
37
- async function sign(uca, privateKey, { issuedAt: issuedAtDateOrString = /* @__PURE__ */ new Date(), expiredAt: expiredAtDateOrString = addYears(/* @__PURE__ */ new Date(), 1) }) {
38
- const issuedAt = new Date(issuedAtDateOrString);
39
- const expiredAt = typeof expiredAtDateOrString === "string" ? parseExpirationDate(expiredAtDateOrString) : expiredAtDateOrString;
40
- uca.credentialSubject.id ??= `urn:uuid:${crypto.randomUUID()}`;
41
- return await signCa(uca, privateKey, {
42
- issuedAt,
43
- expiredAt,
44
- documentProvider
45
- });
46
- }
47
- /**
48
- * 未署名 Content Attestation の取得
49
- * @param uca 未署名 Content Attestation オブジェクト
50
- * @throws {BadRequestError} 検証対象のコンテンツが存在しない/コンテンツにアクセスできない/Integrityの計算に失敗
51
- * @return 未署名 Content Attestation オブジェクト
52
- */
53
- async function unsignedCa(uca, { issuedAt: issuedAtDateOrString = /* @__PURE__ */ new Date(), expiredAt: expiredAtDateOrString = addYears(/* @__PURE__ */ new Date(), 1) }) {
54
- const issuedAt = new Date(issuedAtDateOrString);
55
- const expiredAt = typeof expiredAtDateOrString === "string" ? parseExpirationDate(expiredAtDateOrString) : expiredAtDateOrString;
56
- uca.credentialSubject.id ??= `urn:uuid:${crypto.randomUUID()}`;
57
- try {
58
- await fetchAndSetDigestSri("sha256", uca.credentialSubject.image);
59
- await fetchAndSetTargetIntegrity("sha256", uca, documentProvider);
60
- } catch (e) {
61
- throw new BadRequestError(e.message);
62
- }
63
- return {
64
- iss: uca.issuer,
65
- sub: uca.credentialSubject.id,
66
- iat: getUnixTime(issuedAt),
67
- exp: getUnixTime(expiredAt),
68
- ...uca
69
- };
70
- }
71
-
72
- //#endregion
73
- export { documentProvider as i, sign as n, unsignedCa as r, content_attestation_exports as t };