@originator-profile/sign 0.4.0 → 0.5.0-beta.2
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.cjs +22 -1
- package/dist/index.d.cts +21 -10
- package/dist/index.d.mts +21 -10
- package/dist/index.mjs +22 -2
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -135,6 +135,19 @@ async function createDigestSri(alg, resource, fetcher = fetch) {
|
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
class FetchFailed extends Error {
|
|
139
|
+
static get code() {
|
|
140
|
+
return "ERR_FETCH_FAILED";
|
|
141
|
+
}
|
|
142
|
+
code = FetchFailed.code;
|
|
143
|
+
ok = false;
|
|
144
|
+
error;
|
|
145
|
+
constructor(message, error) {
|
|
146
|
+
super(message);
|
|
147
|
+
this.error = error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
138
151
|
async function fetchAndSetDigestSri(alg, content) {
|
|
139
152
|
if (!content) return content;
|
|
140
153
|
if (typeof content.digestSRI !== "string") {
|
|
@@ -167,7 +180,14 @@ const fetchExternalResource = async (elements, fetcher = fetch) => {
|
|
|
167
180
|
if (!src) {
|
|
168
181
|
throw new Error("Element has no src or currentSrc property");
|
|
169
182
|
}
|
|
170
|
-
|
|
183
|
+
try {
|
|
184
|
+
return await fetcher(src);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
if (e instanceof Error || e instanceof window.Error) {
|
|
187
|
+
throw new FetchFailed(`Failed to fetch`, e);
|
|
188
|
+
}
|
|
189
|
+
throw e;
|
|
190
|
+
}
|
|
171
191
|
})
|
|
172
192
|
);
|
|
173
193
|
};
|
|
@@ -272,6 +292,7 @@ async function signCp(cp, privateKey, options) {
|
|
|
272
292
|
return securingMechanism.signJwtVc(cp, privateKey, options);
|
|
273
293
|
}
|
|
274
294
|
|
|
295
|
+
exports.FetchFailed = FetchFailed;
|
|
275
296
|
exports.IntegrityCalculationError = IntegrityCalculationError;
|
|
276
297
|
exports.createDigestSri = createDigestSri;
|
|
277
298
|
exports.createIntegrity = createIntegrity;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RawTarget, Target, UnsignedContentAttestation, Jwk, CoreProfile } from '@originator-profile/model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents the available hash algorithms used for Subresource Integrity.
|
|
@@ -6,7 +6,15 @@ import { Image, RawTarget, Target, UnsignedContentAttestation, Jwk, CoreProfile
|
|
|
6
6
|
*/
|
|
7
7
|
type HashAlgorithm = "sha256" | "sha384" | "sha512";
|
|
8
8
|
|
|
9
|
-
type
|
|
9
|
+
type DigestSriSource = {
|
|
10
|
+
id: string;
|
|
11
|
+
content?: string | string[];
|
|
12
|
+
};
|
|
13
|
+
type DigestSriResult = {
|
|
14
|
+
id: string;
|
|
15
|
+
digestSRI: string;
|
|
16
|
+
};
|
|
17
|
+
type DigestSriContent = DigestSriSource | DigestSriResult;
|
|
10
18
|
type ContentFetcher = (elements: ReadonlyArray<HTMLElement>, fetcher?: typeof fetch) => Promise<ReadonlyArray<Response>>;
|
|
11
19
|
type ElementSelector = (params: {
|
|
12
20
|
cssSelector?: string;
|
|
@@ -50,12 +58,15 @@ type DocumentProvider = (raw: RawTarget) => Promise<Document>;
|
|
|
50
58
|
* console.log(digestSRI); // sha256-... sha256-...
|
|
51
59
|
* ```
|
|
52
60
|
*/
|
|
53
|
-
declare function createDigestSri(alg: HashAlgorithm, resource:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
declare function createDigestSri(alg: HashAlgorithm, resource: DigestSriSource, fetcher?: typeof fetch): Promise<DigestSriContent>;
|
|
62
|
+
|
|
63
|
+
declare class FetchFailed extends Error {
|
|
64
|
+
static get code(): "ERR_FETCH_FAILED";
|
|
65
|
+
readonly code: "ERR_FETCH_FAILED";
|
|
66
|
+
readonly ok = false;
|
|
67
|
+
error: Error;
|
|
68
|
+
constructor(message: string, error: Error);
|
|
69
|
+
}
|
|
59
70
|
|
|
60
71
|
/**
|
|
61
72
|
* オブジェクトへの `digestSRI` の割り当て
|
|
@@ -80,7 +91,7 @@ declare function createDigestSri(alg: HashAlgorithm, resource: {
|
|
|
80
91
|
* // }
|
|
81
92
|
* ```
|
|
82
93
|
*/
|
|
83
|
-
declare function fetchAndSetDigestSri(alg: HashAlgorithm, content: unknown): Promise<
|
|
94
|
+
declare function fetchAndSetDigestSri(alg: HashAlgorithm, content: unknown): Promise<DigestSriResult | undefined>;
|
|
84
95
|
|
|
85
96
|
/** Integrityの計算に失敗 (例: 検証対象が存在しない) エラー */
|
|
86
97
|
declare class IntegrityCalculationError extends Error {
|
|
@@ -196,4 +207,4 @@ declare function signCp(cp: CoreProfile, privateKey: Jwk, options: {
|
|
|
196
207
|
expiredAt: Date;
|
|
197
208
|
}): Promise<string>;
|
|
198
209
|
|
|
199
|
-
export { type ContentFetcher, type DigestSriContent, type DocumentProvider, type ElementSelector, IntegrityCalculationError, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp };
|
|
210
|
+
export { type ContentFetcher, type DigestSriContent, type DigestSriResult, type DigestSriSource, type DocumentProvider, type ElementSelector, FetchFailed, IntegrityCalculationError, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RawTarget, Target, UnsignedContentAttestation, Jwk, CoreProfile } from '@originator-profile/model';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents the available hash algorithms used for Subresource Integrity.
|
|
@@ -6,7 +6,15 @@ import { Image, RawTarget, Target, UnsignedContentAttestation, Jwk, CoreProfile
|
|
|
6
6
|
*/
|
|
7
7
|
type HashAlgorithm = "sha256" | "sha384" | "sha512";
|
|
8
8
|
|
|
9
|
-
type
|
|
9
|
+
type DigestSriSource = {
|
|
10
|
+
id: string;
|
|
11
|
+
content?: string | string[];
|
|
12
|
+
};
|
|
13
|
+
type DigestSriResult = {
|
|
14
|
+
id: string;
|
|
15
|
+
digestSRI: string;
|
|
16
|
+
};
|
|
17
|
+
type DigestSriContent = DigestSriSource | DigestSriResult;
|
|
10
18
|
type ContentFetcher = (elements: ReadonlyArray<HTMLElement>, fetcher?: typeof fetch) => Promise<ReadonlyArray<Response>>;
|
|
11
19
|
type ElementSelector = (params: {
|
|
12
20
|
cssSelector?: string;
|
|
@@ -50,12 +58,15 @@ type DocumentProvider = (raw: RawTarget) => Promise<Document>;
|
|
|
50
58
|
* console.log(digestSRI); // sha256-... sha256-...
|
|
51
59
|
* ```
|
|
52
60
|
*/
|
|
53
|
-
declare function createDigestSri(alg: HashAlgorithm, resource:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
declare function createDigestSri(alg: HashAlgorithm, resource: DigestSriSource, fetcher?: typeof fetch): Promise<DigestSriContent>;
|
|
62
|
+
|
|
63
|
+
declare class FetchFailed extends Error {
|
|
64
|
+
static get code(): "ERR_FETCH_FAILED";
|
|
65
|
+
readonly code: "ERR_FETCH_FAILED";
|
|
66
|
+
readonly ok = false;
|
|
67
|
+
error: Error;
|
|
68
|
+
constructor(message: string, error: Error);
|
|
69
|
+
}
|
|
59
70
|
|
|
60
71
|
/**
|
|
61
72
|
* オブジェクトへの `digestSRI` の割り当て
|
|
@@ -80,7 +91,7 @@ declare function createDigestSri(alg: HashAlgorithm, resource: {
|
|
|
80
91
|
* // }
|
|
81
92
|
* ```
|
|
82
93
|
*/
|
|
83
|
-
declare function fetchAndSetDigestSri(alg: HashAlgorithm, content: unknown): Promise<
|
|
94
|
+
declare function fetchAndSetDigestSri(alg: HashAlgorithm, content: unknown): Promise<DigestSriResult | undefined>;
|
|
84
95
|
|
|
85
96
|
/** Integrityの計算に失敗 (例: 検証対象が存在しない) エラー */
|
|
86
97
|
declare class IntegrityCalculationError extends Error {
|
|
@@ -196,4 +207,4 @@ declare function signCp(cp: CoreProfile, privateKey: Jwk, options: {
|
|
|
196
207
|
expiredAt: Date;
|
|
197
208
|
}): Promise<string>;
|
|
198
209
|
|
|
199
|
-
export { type ContentFetcher, type DigestSriContent, type DocumentProvider, type ElementSelector, IntegrityCalculationError, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp };
|
|
210
|
+
export { type ContentFetcher, type DigestSriContent, type DigestSriResult, type DigestSriSource, type DocumentProvider, type ElementSelector, FetchFailed, IntegrityCalculationError, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp };
|
package/dist/index.mjs
CHANGED
|
@@ -133,6 +133,19 @@ async function createDigestSri(alg, resource, fetcher = fetch) {
|
|
|
133
133
|
};
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
class FetchFailed extends Error {
|
|
137
|
+
static get code() {
|
|
138
|
+
return "ERR_FETCH_FAILED";
|
|
139
|
+
}
|
|
140
|
+
code = FetchFailed.code;
|
|
141
|
+
ok = false;
|
|
142
|
+
error;
|
|
143
|
+
constructor(message, error) {
|
|
144
|
+
super(message);
|
|
145
|
+
this.error = error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
136
149
|
async function fetchAndSetDigestSri(alg, content) {
|
|
137
150
|
if (!content) return content;
|
|
138
151
|
if (typeof content.digestSRI !== "string") {
|
|
@@ -165,7 +178,14 @@ const fetchExternalResource = async (elements, fetcher = fetch) => {
|
|
|
165
178
|
if (!src) {
|
|
166
179
|
throw new Error("Element has no src or currentSrc property");
|
|
167
180
|
}
|
|
168
|
-
|
|
181
|
+
try {
|
|
182
|
+
return await fetcher(src);
|
|
183
|
+
} catch (e) {
|
|
184
|
+
if (e instanceof Error || e instanceof window.Error) {
|
|
185
|
+
throw new FetchFailed(`Failed to fetch`, e);
|
|
186
|
+
}
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
169
189
|
})
|
|
170
190
|
);
|
|
171
191
|
};
|
|
@@ -270,4 +290,4 @@ async function signCp(cp, privateKey, options) {
|
|
|
270
290
|
return signJwtVc(cp, privateKey, options);
|
|
271
291
|
}
|
|
272
292
|
|
|
273
|
-
export { IntegrityCalculationError, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp };
|
|
293
|
+
export { FetchFailed, IntegrityCalculationError, createDigestSri, createIntegrity, fetchAndSetDigestSri, fetchAndSetTargetIntegrity, fetchExternalResource, fetchHtmlContent, fetchTextContent, fetchVisibleTextContent, selectByCss, selectByIntegrity, signCa, signCp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@originator-profile/sign",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0-beta.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://docs.originator-profile.org",
|
|
6
6
|
"repository": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"jose": "^6.0.10",
|
|
33
|
-
"@originator-profile/cryptography": "0.
|
|
34
|
-
"@originator-profile/
|
|
35
|
-
"@originator-profile/
|
|
33
|
+
"@originator-profile/cryptography": "0.5.0-beta.2",
|
|
34
|
+
"@originator-profile/securing-mechanism": "0.5.0-beta.2",
|
|
35
|
+
"@originator-profile/model": "0.5.0-beta.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"date-fns": "^4.1.0",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"typescript": "^5.8.3",
|
|
42
42
|
"vitest": "^4.0.0",
|
|
43
43
|
"websri": "^1.0.1",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
44
|
+
"@originator-profile/tsconfig": "0.5.0-beta.2",
|
|
45
|
+
"eslint-config-originator-profile": "0.5.0-beta.2"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "pkgroll --clean-dist --target=node20",
|