@sphereon/ssi-types 0.30.2-feature.mdoc.funke2.374 → 0.30.2-feature.mdoc.funke2.375
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/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/sd-jwt-type-metadata.d.ts +147 -0
- package/dist/types/sd-jwt-type-metadata.d.ts.map +1 -0
- package/dist/types/sd-jwt-type-metadata.js +84 -0
- package/dist/types/sd-jwt-type-metadata.js.map +1 -0
- package/package.json +4 -3
- package/src/types/index.ts +1 -0
- package/src/types/sd-jwt-type-metadata.ts +220 -0
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA;AACrB,cAAc,MAAM,CAAA;AACpB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA;AACrB,cAAc,MAAM,CAAA;AACpB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,QAAQ,CAAA;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA"}
|
package/dist/types/index.js
CHANGED
|
@@ -19,6 +19,7 @@ __exportStar(require("./pex"), exports);
|
|
|
19
19
|
__exportStar(require("./vc"), exports);
|
|
20
20
|
__exportStar(require("./generic"), exports);
|
|
21
21
|
__exportStar(require("./sd-jwt-vc"), exports);
|
|
22
|
+
__exportStar(require("./sd-jwt-type-metadata"), exports);
|
|
22
23
|
__exportStar(require("./w3c-vc"), exports);
|
|
23
24
|
__exportStar(require("./jose"), exports);
|
|
24
25
|
__exportStar(require("./cose"), exports);
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,wCAAqB;AACrB,uCAAoB;AACpB,4CAAyB;AACzB,8CAA2B;AAC3B,2CAAwB;AACxB,yCAAsB;AACtB,yCAAsB;AACtB,6CAA0B;AAC1B,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,wCAAqB;AACrB,uCAAoB;AACpB,4CAAyB;AACzB,8CAA2B;AAC3B,yDAAsC;AACtC,2CAAwB;AACxB,yCAAsB;AACtB,yCAAsB;AACtB,6CAA0B;AAC1B,mDAAgC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { AsyncHasher } from './sd-jwt-vc';
|
|
2
|
+
/**
|
|
3
|
+
* Represents the metadata associated with a specific SD-JWT VC type.
|
|
4
|
+
*/
|
|
5
|
+
interface SdJwtTypeMetadata {
|
|
6
|
+
/**
|
|
7
|
+
* REQUIRED. The VC type URI.
|
|
8
|
+
*/
|
|
9
|
+
vct: string;
|
|
10
|
+
/**
|
|
11
|
+
* OPTIONAL. A human-readable name for the type.
|
|
12
|
+
*/
|
|
13
|
+
name?: string;
|
|
14
|
+
/**
|
|
15
|
+
* OPTIONAL. A human-readable description for the type.
|
|
16
|
+
*/
|
|
17
|
+
description?: string;
|
|
18
|
+
/**
|
|
19
|
+
* OPTIONAL. A URI of another type that this type extends.
|
|
20
|
+
*/
|
|
21
|
+
extends?: string;
|
|
22
|
+
/**
|
|
23
|
+
* OPTIONAL. Integrity metadata string for the 'extends' field.
|
|
24
|
+
*/
|
|
25
|
+
['extends#integrity']?: string;
|
|
26
|
+
/**
|
|
27
|
+
* OPTIONAL. URL pointing towards a JSON Schema document describing the VC's structure.
|
|
28
|
+
*/
|
|
29
|
+
schema_uri?: string;
|
|
30
|
+
/**
|
|
31
|
+
* OPTIONAL. Integrity metadata string for the 'schema_uri' field.
|
|
32
|
+
*/
|
|
33
|
+
['schema_uri#integrity']?: string;
|
|
34
|
+
/**
|
|
35
|
+
* OPTIONAL. Display metadata for various languages.
|
|
36
|
+
*/
|
|
37
|
+
display?: Array<SdJwtTypeDisplayMetadata>;
|
|
38
|
+
/**
|
|
39
|
+
* OPTIONAL. Metadata for the claims within the VC.
|
|
40
|
+
*/
|
|
41
|
+
claims?: Array<any>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Represents display metadata for a specific language.
|
|
45
|
+
*/
|
|
46
|
+
interface SdJwtTypeDisplayMetadata {
|
|
47
|
+
/**
|
|
48
|
+
* REQUIRED. Language tag for the display information.
|
|
49
|
+
*/
|
|
50
|
+
lang: string;
|
|
51
|
+
/**
|
|
52
|
+
* REQUIRED. Human-readable name for the type.
|
|
53
|
+
*/
|
|
54
|
+
name: string;
|
|
55
|
+
/**
|
|
56
|
+
* OPTIONAL. Human-readable description for the type.
|
|
57
|
+
*/
|
|
58
|
+
description?: string;
|
|
59
|
+
/**
|
|
60
|
+
* OPTIONAL. Rendering metadata for the type.
|
|
61
|
+
*/
|
|
62
|
+
rendering?: SdJwtTypeRenderingMetadata;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Contains rendering metadata for different methods.
|
|
66
|
+
*/
|
|
67
|
+
interface SdJwtTypeRenderingMetadata {
|
|
68
|
+
/**
|
|
69
|
+
* OPTIONAL. Simple rendering method metadata.
|
|
70
|
+
*/
|
|
71
|
+
simple?: SdJwtSimpleRenderingMetadata;
|
|
72
|
+
/**
|
|
73
|
+
* OPTIONAL. Metadata for SVG templates.
|
|
74
|
+
*/
|
|
75
|
+
svg_template?: Array<SdJwtSVGTemplateMetadata>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Represents metadata for simple rendering.
|
|
79
|
+
*/
|
|
80
|
+
interface SdJwtSimpleRenderingMetadata {
|
|
81
|
+
/**
|
|
82
|
+
* OPTIONAL. Metadata for the logo image.
|
|
83
|
+
*/
|
|
84
|
+
logo?: SdJwtLogoMetadata;
|
|
85
|
+
/**
|
|
86
|
+
* OPTIONAL. Background color for the credential.
|
|
87
|
+
*/
|
|
88
|
+
background_color?: string;
|
|
89
|
+
/**
|
|
90
|
+
* OPTIONAL. Text color for the credential.
|
|
91
|
+
*/
|
|
92
|
+
text_color?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Represents metadata for a logo.
|
|
96
|
+
*/
|
|
97
|
+
interface SdJwtLogoMetadata {
|
|
98
|
+
/**
|
|
99
|
+
* REQUIRED. URI pointing to the logo image.
|
|
100
|
+
*/
|
|
101
|
+
uri: string;
|
|
102
|
+
/**
|
|
103
|
+
* OPTIONAL. Integrity metadata string for the 'uri' field.
|
|
104
|
+
*/
|
|
105
|
+
['uri#integrity']?: string;
|
|
106
|
+
/**
|
|
107
|
+
* OPTIONAL. Alternative text for the logo image.
|
|
108
|
+
*/
|
|
109
|
+
alt_text?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Represents metadata for SVG templates.
|
|
113
|
+
*/
|
|
114
|
+
interface SdJwtSVGTemplateMetadata {
|
|
115
|
+
/**
|
|
116
|
+
* REQUIRED. URI pointing to the SVG template.
|
|
117
|
+
*/
|
|
118
|
+
uri: string;
|
|
119
|
+
/**
|
|
120
|
+
* OPTIONAL. Integrity metadata string for the 'uri' field.
|
|
121
|
+
*/
|
|
122
|
+
['uri#integrity']?: string;
|
|
123
|
+
/**
|
|
124
|
+
* OPTIONAL. Properties for the SVG template.
|
|
125
|
+
*/
|
|
126
|
+
properties?: SdJwtSVGTemplateProperties;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Contains properties for SVG templates.
|
|
130
|
+
*/
|
|
131
|
+
interface SdJwtSVGTemplateProperties {
|
|
132
|
+
/**
|
|
133
|
+
* OPTIONAL. The orientation for which the SVG template is optimized.
|
|
134
|
+
*/
|
|
135
|
+
orientation?: string;
|
|
136
|
+
/**
|
|
137
|
+
* OPTIONAL. The color scheme for which the SVG template is optimized.
|
|
138
|
+
*/
|
|
139
|
+
color_scheme?: string;
|
|
140
|
+
}
|
|
141
|
+
export type SdJwtTypeHasher = (input: any, alg?: string) => string;
|
|
142
|
+
export declare function fetchSdJwtTypeMetadataFromVctUrl(vct: string, opts?: {
|
|
143
|
+
hasher?: AsyncHasher;
|
|
144
|
+
integrity?: string;
|
|
145
|
+
}): Promise<SdJwtTypeMetadata>;
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=sd-jwt-type-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sd-jwt-type-metadata.d.ts","sourceRoot":"","sources":["../../src/types/sd-jwt-type-metadata.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC;;GAEG;AACH,UAAU,iBAAiB;IACzB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,CAAC;IAE/B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;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AAC;IAErB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAYD,MAAM,MAAM,eAAe,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;AAQlE,wBAAsB,gCAAgC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAanJ"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.fetchSdJwtTypeMetadataFromVctUrl = fetchSdJwtTypeMetadataFromVctUrl;
|
|
36
|
+
const u8a = __importStar(require("uint8arrays"));
|
|
37
|
+
// Helper function to fetch API with error handling
|
|
38
|
+
function fetchUrlWithErrorHandling(url) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const response = yield fetch(url);
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error(`${response.status}: ${response.statusText}`);
|
|
43
|
+
}
|
|
44
|
+
return response;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function validateIntegrity(input, integrityValue, hasher, alg) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const hash = yield hasher(input, alg !== null && alg !== void 0 ? alg : 'sha256');
|
|
50
|
+
return u8a.toString(hash, 'utf-8') === integrityValue;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Fetch and validate Type Metadata
|
|
54
|
+
function fetchSdJwtTypeMetadataFromVctUrl(vct, opts) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const url = new URL(vct);
|
|
57
|
+
const wellKnownUrl = `${url.origin}/.well-known/vct${url.pathname}`;
|
|
58
|
+
const response = yield fetchUrlWithErrorHandling(wellKnownUrl);
|
|
59
|
+
const metadata = yield response.json();
|
|
60
|
+
assertValidTypeMetadata(metadata, vct);
|
|
61
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.integrity) && opts.hasher) {
|
|
62
|
+
if (!(yield validateIntegrity(metadata, opts.integrity, opts.hasher))) {
|
|
63
|
+
throw new Error('Integrity check failed');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return metadata;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function assertValidTypeMetadata(metadata, vct) {
|
|
70
|
+
if (metadata.vct !== vct) {
|
|
71
|
+
throw new Error('VCT mismatch in metadata and credential');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/*
|
|
75
|
+
// Example usage
|
|
76
|
+
try {
|
|
77
|
+
const vct = 'https://betelgeuse.example.com/education_credential'
|
|
78
|
+
const typeMetadata = await fetchSdJwtTypeMetadataFromVctUrl(vct)
|
|
79
|
+
console.log('Type Metadata retrieved successfully:', typeMetadata)
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error fetching type metadata:', error.message)
|
|
82
|
+
}
|
|
83
|
+
*/
|
|
84
|
+
//# sourceMappingURL=sd-jwt-type-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sd-jwt-type-metadata.js","sourceRoot":"","sources":["../../src/types/sd-jwt-type-metadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2LA,4EAaC;AAxMD,iDAAkC;AA0KlC,mDAAmD;AACnD,SAAe,yBAAyB,CAAC,GAAW;;QAClD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAA;QACjC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;QAC/D,CAAC;QACD,OAAO,QA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E"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-types",
|
|
3
3
|
"description": "SSI Common Types",
|
|
4
|
-
"version": "0.30.2-feature.mdoc.funke2.
|
|
4
|
+
"version": "0.30.2-feature.mdoc.funke2.375+025f6b57",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"@sphereon/kmp-mdoc-core": "0.2.0-SNAPSHOT.14",
|
|
14
14
|
"debug": "^4.3.5",
|
|
15
15
|
"events": "^3.3.0",
|
|
16
|
-
"jwt-decode": "^3.1.2"
|
|
16
|
+
"jwt-decode": "^3.1.2",
|
|
17
|
+
"uint8arrays": "3.1.1"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
20
|
"@types/jest": "^27.5.2",
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"DIDs"
|
|
47
48
|
],
|
|
48
49
|
"nx": {},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "025f6b5785263196a86760930746ce1c98691d1a"
|
|
50
51
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import * as u8a from 'uint8arrays'
|
|
2
|
+
import { AsyncHasher } from './sd-jwt-vc'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents the metadata associated with a specific SD-JWT VC type.
|
|
6
|
+
*/
|
|
7
|
+
interface SdJwtTypeMetadata {
|
|
8
|
+
/**
|
|
9
|
+
* REQUIRED. The VC type URI.
|
|
10
|
+
*/
|
|
11
|
+
vct: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* OPTIONAL. A human-readable name for the type.
|
|
15
|
+
*/
|
|
16
|
+
name?: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* OPTIONAL. A human-readable description for the type.
|
|
20
|
+
*/
|
|
21
|
+
description?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* OPTIONAL. A URI of another type that this type extends.
|
|
25
|
+
*/
|
|
26
|
+
extends?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* OPTIONAL. Integrity metadata string for the 'extends' field.
|
|
30
|
+
*/
|
|
31
|
+
['extends#integrity']?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* OPTIONAL. URL pointing towards a JSON Schema document describing the VC's structure.
|
|
35
|
+
*/
|
|
36
|
+
schema_uri?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* OPTIONAL. Integrity metadata string for the 'schema_uri' field.
|
|
40
|
+
*/
|
|
41
|
+
['schema_uri#integrity']?: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* OPTIONAL. Display metadata for various languages.
|
|
45
|
+
*/
|
|
46
|
+
display?: Array<SdJwtTypeDisplayMetadata>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* OPTIONAL. Metadata for the claims within the VC.
|
|
50
|
+
*/
|
|
51
|
+
// TODO:
|
|
52
|
+
claims?: Array<any>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Represents display metadata for a specific language.
|
|
57
|
+
*/
|
|
58
|
+
interface SdJwtTypeDisplayMetadata {
|
|
59
|
+
/**
|
|
60
|
+
* REQUIRED. Language tag for the display information.
|
|
61
|
+
*/
|
|
62
|
+
lang: string;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* REQUIRED. Human-readable name for the type.
|
|
66
|
+
*/
|
|
67
|
+
name: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* OPTIONAL. Human-readable description for the type.
|
|
71
|
+
*/
|
|
72
|
+
description?: string;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* OPTIONAL. Rendering metadata for the type.
|
|
76
|
+
*/
|
|
77
|
+
rendering?: SdJwtTypeRenderingMetadata;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Contains rendering metadata for different methods.
|
|
82
|
+
*/
|
|
83
|
+
interface SdJwtTypeRenderingMetadata {
|
|
84
|
+
/**
|
|
85
|
+
* OPTIONAL. Simple rendering method metadata.
|
|
86
|
+
*/
|
|
87
|
+
simple?: SdJwtSimpleRenderingMetadata;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* OPTIONAL. Metadata for SVG templates.
|
|
91
|
+
*/
|
|
92
|
+
svg_template?: Array<SdJwtSVGTemplateMetadata>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Represents metadata for simple rendering.
|
|
97
|
+
*/
|
|
98
|
+
interface SdJwtSimpleRenderingMetadata {
|
|
99
|
+
/**
|
|
100
|
+
* OPTIONAL. Metadata for the logo image.
|
|
101
|
+
*/
|
|
102
|
+
logo?: SdJwtLogoMetadata;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* OPTIONAL. Background color for the credential.
|
|
106
|
+
*/
|
|
107
|
+
background_color?: string;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* OPTIONAL. Text color for the credential.
|
|
111
|
+
*/
|
|
112
|
+
text_color?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Represents metadata for a logo.
|
|
117
|
+
*/
|
|
118
|
+
interface SdJwtLogoMetadata {
|
|
119
|
+
/**
|
|
120
|
+
* REQUIRED. URI pointing to the logo image.
|
|
121
|
+
*/
|
|
122
|
+
uri: string;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* OPTIONAL. Integrity metadata string for the 'uri' field.
|
|
126
|
+
*/
|
|
127
|
+
['uri#integrity']?: string;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* OPTIONAL. Alternative text for the logo image.
|
|
131
|
+
*/
|
|
132
|
+
alt_text?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Represents metadata for SVG templates.
|
|
137
|
+
*/
|
|
138
|
+
interface SdJwtSVGTemplateMetadata {
|
|
139
|
+
/**
|
|
140
|
+
* REQUIRED. URI pointing to the SVG template.
|
|
141
|
+
*/
|
|
142
|
+
uri: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* OPTIONAL. Integrity metadata string for the 'uri' field.
|
|
146
|
+
*/
|
|
147
|
+
['uri#integrity']?: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* OPTIONAL. Properties for the SVG template.
|
|
151
|
+
*/
|
|
152
|
+
properties?: SdJwtSVGTemplateProperties;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Contains properties for SVG templates.
|
|
157
|
+
*/
|
|
158
|
+
interface SdJwtSVGTemplateProperties {
|
|
159
|
+
/**
|
|
160
|
+
* OPTIONAL. The orientation for which the SVG template is optimized.
|
|
161
|
+
*/
|
|
162
|
+
orientation?: string;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* OPTIONAL. The color scheme for which the SVG template is optimized.
|
|
166
|
+
*/
|
|
167
|
+
color_scheme?: string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// Helper function to fetch API with error handling
|
|
172
|
+
async function fetchUrlWithErrorHandling(url: string): Promise<Response> {
|
|
173
|
+
const response = await fetch(url)
|
|
174
|
+
if (!response.ok) {
|
|
175
|
+
throw new Error(`${response.status}: ${response.statusText}`)
|
|
176
|
+
}
|
|
177
|
+
return response
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export type SdJwtTypeHasher = (input: any, alg?: string) => string
|
|
181
|
+
|
|
182
|
+
async function validateIntegrity(input: any, integrityValue: string, hasher: AsyncHasher, alg?: string): Promise<boolean> {
|
|
183
|
+
const hash = await hasher(input, alg ?? 'sha256')
|
|
184
|
+
return u8a.toString(hash, 'utf-8') === integrityValue
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Fetch and validate Type Metadata
|
|
188
|
+
export async function fetchSdJwtTypeMetadataFromVctUrl(vct: string, opts?: { hasher?: AsyncHasher, integrity?: string }): Promise<SdJwtTypeMetadata> {
|
|
189
|
+
const url = new URL(vct)
|
|
190
|
+
const wellKnownUrl = `${url.origin}/.well-known/vct${url.pathname}`
|
|
191
|
+
|
|
192
|
+
const response = await fetchUrlWithErrorHandling(wellKnownUrl)
|
|
193
|
+
const metadata: SdJwtTypeMetadata = await response.json()
|
|
194
|
+
assertValidTypeMetadata(metadata, vct)
|
|
195
|
+
if (opts?.integrity && opts.hasher) {
|
|
196
|
+
if (!await validateIntegrity(metadata, opts.integrity, opts.hasher)) {
|
|
197
|
+
throw new Error('Integrity check failed')
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return metadata
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function assertValidTypeMetadata(metadata: SdJwtTypeMetadata, vct: string): void {
|
|
204
|
+
if (metadata.vct !== vct) {
|
|
205
|
+
throw new Error('VCT mismatch in metadata and credential')
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
// Example usage
|
|
212
|
+
try {
|
|
213
|
+
const vct = 'https://betelgeuse.example.com/education_credential'
|
|
214
|
+
const typeMetadata = await fetchSdJwtTypeMetadataFromVctUrl(vct)
|
|
215
|
+
console.log('Type Metadata retrieved successfully:', typeMetadata)
|
|
216
|
+
} catch (error) {
|
|
217
|
+
console.error('Error fetching type metadata:', error.message)
|
|
218
|
+
}
|
|
219
|
+
*/
|
|
220
|
+
|