@twin.org/identity-connector-entity-storage 0.0.2-next.9 → 0.0.3-next.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.
Files changed (31) hide show
  1. package/dist/es/entities/identityDocument.js +45 -0
  2. package/dist/es/entities/identityDocument.js.map +1 -0
  3. package/dist/es/entities/identityProfile.js +37 -0
  4. package/dist/es/entities/identityProfile.js.map +1 -0
  5. package/dist/{esm/index.mjs → es/entityStorageIdentityConnector.js} +18 -355
  6. package/dist/es/entityStorageIdentityConnector.js.map +1 -0
  7. package/dist/es/entityStorageIdentityProfileConnector.js +203 -0
  8. package/dist/es/entityStorageIdentityProfileConnector.js.map +1 -0
  9. package/dist/es/entityStorageIdentityResolverConnector.js +65 -0
  10. package/dist/es/entityStorageIdentityResolverConnector.js.map +1 -0
  11. package/dist/es/index.js +12 -0
  12. package/dist/es/index.js.map +1 -0
  13. package/dist/es/models/IEntityStorageIdentityConnectorConstructorOptions.js +2 -0
  14. package/dist/es/models/IEntityStorageIdentityConnectorConstructorOptions.js.map +1 -0
  15. package/dist/es/models/IEntityStorageIdentityProfileConnectorConstructorOptions.js +4 -0
  16. package/dist/es/models/IEntityStorageIdentityProfileConnectorConstructorOptions.js.map +1 -0
  17. package/dist/es/models/IEntityStorageIdentityResolverConnectorConstructorOptions.js +4 -0
  18. package/dist/es/models/IEntityStorageIdentityResolverConnectorConstructorOptions.js.map +1 -0
  19. package/dist/es/schema.js +20 -0
  20. package/dist/es/schema.js.map +1 -0
  21. package/dist/types/entityStorageIdentityConnector.d.ts +6 -1
  22. package/dist/types/entityStorageIdentityProfileConnector.d.ts +6 -1
  23. package/dist/types/entityStorageIdentityResolverConnector.d.ts +6 -1
  24. package/dist/types/index.d.ts +9 -9
  25. package/dist/types/models/IEntityStorageIdentityConnectorConstructorOptions.d.ts +1 -1
  26. package/docs/changelog.md +57 -0
  27. package/docs/reference/classes/EntityStorageIdentityConnector.md +22 -4
  28. package/docs/reference/classes/EntityStorageIdentityProfileConnector.md +18 -0
  29. package/docs/reference/classes/EntityStorageIdentityResolverConnector.md +18 -0
  30. package/package.json +6 -8
  31. package/dist/cjs/index.cjs +0 -1326
@@ -0,0 +1,45 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { entity, property } from "@twin.org/entity";
4
+ /**
5
+ * Class describing the identity document.
6
+ */
7
+ let IdentityDocument = class IdentityDocument {
8
+ /**
9
+ * The identity of the document.
10
+ */
11
+ id;
12
+ /**
13
+ * The DID document.
14
+ */
15
+ document;
16
+ /**
17
+ * The signature of the document.
18
+ */
19
+ signature;
20
+ /**
21
+ * The controller of the document.
22
+ */
23
+ controller;
24
+ };
25
+ __decorate([
26
+ property({ type: "string", isPrimary: true }),
27
+ __metadata("design:type", String)
28
+ ], IdentityDocument.prototype, "id", void 0);
29
+ __decorate([
30
+ property({ type: "object" }),
31
+ __metadata("design:type", Object)
32
+ ], IdentityDocument.prototype, "document", void 0);
33
+ __decorate([
34
+ property({ type: "string" }),
35
+ __metadata("design:type", String)
36
+ ], IdentityDocument.prototype, "signature", void 0);
37
+ __decorate([
38
+ property({ type: "string" }),
39
+ __metadata("design:type", String)
40
+ ], IdentityDocument.prototype, "controller", void 0);
41
+ IdentityDocument = __decorate([
42
+ entity()
43
+ ], IdentityDocument);
44
+ export { IdentityDocument };
45
+ //# sourceMappingURL=identityDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityDocument.js","sourceRoot":"","sources":["../../../src/entities/identityDocument.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGpD;;GAEG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC5B;;OAEG;IAEI,EAAE,CAAU;IAEnB;;OAEG;IAEI,QAAQ,CAAgB;IAE/B;;OAEG;IAEI,SAAS,CAAU;IAE1B;;OAEG;IAEI,UAAU,CAAU;CAC3B,CAAA;AAnBO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;4CAC3B;AAMZ;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;kDACE;AAMxB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;mDACH;AAMnB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;oDACF;AAvBf,gBAAgB;IAD5B,MAAM,EAAE;GACI,gBAAgB,CAwB5B","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property } from \"@twin.org/entity\";\nimport type { IDidDocument } from \"@twin.org/standards-w3c-did\";\n\n/**\n * Class describing the identity document.\n */\n@entity()\nexport class IdentityDocument {\n\t/**\n\t * The identity of the document.\n\t */\n\t@property({ type: \"string\", isPrimary: true })\n\tpublic id!: string;\n\n\t/**\n\t * The DID document.\n\t */\n\t@property({ type: \"object\" })\n\tpublic document!: IDidDocument;\n\n\t/**\n\t * The signature of the document.\n\t */\n\t@property({ type: \"string\" })\n\tpublic signature!: string;\n\n\t/**\n\t * The controller of the document.\n\t */\n\t@property({ type: \"string\" })\n\tpublic controller!: string;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { entity, property } from "@twin.org/entity";
4
+ /**
5
+ * Class representing profile details for the identity.
6
+ */
7
+ let IdentityProfile = class IdentityProfile {
8
+ /**
9
+ * The id for the identity.
10
+ */
11
+ identity;
12
+ /**
13
+ * The public profile data.
14
+ */
15
+ publicProfile;
16
+ /**
17
+ * The private profile data.
18
+ */
19
+ privateProfile;
20
+ };
21
+ __decorate([
22
+ property({ type: "string", isPrimary: true }),
23
+ __metadata("design:type", String)
24
+ ], IdentityProfile.prototype, "identity", void 0);
25
+ __decorate([
26
+ property({ type: "object", optional: true }),
27
+ __metadata("design:type", Object)
28
+ ], IdentityProfile.prototype, "publicProfile", void 0);
29
+ __decorate([
30
+ property({ type: "object", optional: true }),
31
+ __metadata("design:type", Object)
32
+ ], IdentityProfile.prototype, "privateProfile", void 0);
33
+ IdentityProfile = __decorate([
34
+ entity()
35
+ ], IdentityProfile);
36
+ export { IdentityProfile };
37
+ //# sourceMappingURL=identityProfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityProfile.js","sourceRoot":"","sources":["../../../src/entities/identityProfile.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;GAEG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAC3B;;OAEG;IAEI,QAAQ,CAAU;IAEzB;;OAEG;IAEI,aAAa,CAAW;IAE/B;;OAEG;IAEI,cAAc,CAAW;CAChC,CAAA;AAbO;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;;iDACrB;AAMlB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;sDACd;AAMxB;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;uDACb;AAjBpB,eAAe;IAD3B,MAAM,EAAE;GACI,eAAe,CAkB3B","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { entity, property } from \"@twin.org/entity\";\n\n/**\n * Class representing profile details for the identity.\n */\n@entity()\nexport class IdentityProfile {\n\t/**\n\t * The id for the identity.\n\t */\n\t@property({ type: \"string\", isPrimary: true })\n\tpublic identity!: string;\n\n\t/**\n\t * The public profile data.\n\t */\n\t@property({ type: \"object\", optional: true })\n\tpublic publicProfile?: unknown;\n\n\t/**\n\t * The private profile data.\n\t */\n\t@property({ type: \"object\", optional: true })\n\tpublic privateProfile?: unknown;\n}\n"]}
@@ -1,96 +1,16 @@
1
- import { property, entity, ComparisonOperator, EntitySchemaFactory, EntitySchemaHelper } from '@twin.org/entity';
2
- import { JsonHelper, Converter, GeneralError, Guards, RandomHelper, BitString, Compression, CompressionType, Is, NotFoundError, ObjectHelper, BaseError, Coerce, AlreadyExistsError } from '@twin.org/core';
3
- import { JsonLdProcessor } from '@twin.org/data-json-ld';
4
- import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
5
- import { DocumentHelper } from '@twin.org/identity-models';
6
- import { DidContexts, DidVerificationMethodType, DidTypes, ProofTypes, ProofHelper } from '@twin.org/standards-w3c-did';
7
- import { VaultConnectorFactory, VaultKeyType, VaultConnectorHelper } from '@twin.org/vault-models';
8
- import { Jwk, Jwt } from '@twin.org/web';
9
-
10
- // Copyright 2024 IOTA Stiftung.
11
- // SPDX-License-Identifier: Apache-2.0.
12
- /**
13
- * Class describing the identity document.
14
- */
15
- let IdentityDocument = class IdentityDocument {
16
- /**
17
- * The identity of the document.
18
- */
19
- id;
20
- /**
21
- * The DID document.
22
- */
23
- document;
24
- /**
25
- * The signature of the document.
26
- */
27
- signature;
28
- /**
29
- * The controller of the document.
30
- */
31
- controller;
32
- };
33
- __decorate([
34
- property({ type: "string", isPrimary: true }),
35
- __metadata("design:type", String)
36
- ], IdentityDocument.prototype, "id", void 0);
37
- __decorate([
38
- property({ type: "object" }),
39
- __metadata("design:type", Object)
40
- ], IdentityDocument.prototype, "document", void 0);
41
- __decorate([
42
- property({ type: "string" }),
43
- __metadata("design:type", String)
44
- ], IdentityDocument.prototype, "signature", void 0);
45
- __decorate([
46
- property({ type: "string" }),
47
- __metadata("design:type", String)
48
- ], IdentityDocument.prototype, "controller", void 0);
49
- IdentityDocument = __decorate([
50
- entity()
51
- ], IdentityDocument);
52
-
53
- // Copyright 2024 IOTA Stiftung.
54
- // SPDX-License-Identifier: Apache-2.0.
55
- /**
56
- * Class representing profile details for the identity.
57
- */
58
- let IdentityProfile = class IdentityProfile {
59
- /**
60
- * The id for the identity.
61
- */
62
- identity;
63
- /**
64
- * The public profile data.
65
- */
66
- publicProfile;
67
- /**
68
- * The private profile data.
69
- */
70
- privateProfile;
71
- };
72
- __decorate([
73
- property({ type: "string", isPrimary: true }),
74
- __metadata("design:type", String)
75
- ], IdentityProfile.prototype, "identity", void 0);
76
- __decorate([
77
- property({ type: "object", optional: true }),
78
- __metadata("design:type", Object)
79
- ], IdentityProfile.prototype, "publicProfile", void 0);
80
- __decorate([
81
- property({ type: "object", optional: true }),
82
- __metadata("design:type", Object)
83
- ], IdentityProfile.prototype, "privateProfile", void 0);
84
- IdentityProfile = __decorate([
85
- entity()
86
- ], IdentityProfile);
87
-
88
1
  // Copyright 2024 IOTA Stiftung.
89
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ import { BaseError, BitString, Coerce, Compression, CompressionType, Converter, GeneralError, Guards, Is, JsonHelper, NotFoundError, ObjectHelper, RandomHelper } from "@twin.org/core";
4
+ import { JsonLdProcessor } from "@twin.org/data-json-ld";
5
+ import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
6
+ import { DocumentHelper } from "@twin.org/identity-models";
7
+ import { DidContexts, DidTypes, DidVerificationMethodType, ProofHelper, ProofTypes } from "@twin.org/standards-w3c-did";
8
+ import { VaultConnectorFactory, VaultConnectorHelper, VaultKeyType } from "@twin.org/vault-models";
9
+ import { Jwk, Jwt } from "@twin.org/web";
90
10
  /**
91
11
  * Class for performing identity operations using entity storage.
92
12
  */
93
- class EntityStorageIdentityConnector {
13
+ export class EntityStorageIdentityConnector {
94
14
  /**
95
15
  * Runtime name for the class.
96
16
  */
@@ -144,6 +64,13 @@ class EntityStorageIdentityConnector {
144
64
  throw new GeneralError(EntityStorageIdentityConnector.CLASS_NAME, "signatureVerificationFailed");
145
65
  }
146
66
  }
67
+ /**
68
+ * Returns the class name of the component.
69
+ * @returns The class name of the component.
70
+ */
71
+ className() {
72
+ return EntityStorageIdentityConnector.CLASS_NAME;
73
+ }
147
74
  /**
148
75
  * Create a new document.
149
76
  * @param controller The controller of the identity who can make changes.
@@ -982,7 +909,8 @@ class EntityStorageIdentityConnector {
982
909
  method: proof.verificationMethod
983
910
  });
984
911
  }
985
- return ProofHelper.verifyProof(document, proof, didMethod.publicKeyJwk);
912
+ const result = await ProofHelper.verifyProof(document, proof, didMethod.publicKeyJwk);
913
+ return result;
986
914
  }
987
915
  catch (error) {
988
916
  throw new GeneralError(EntityStorageIdentityConnector.CLASS_NAME, "verifyProofFailed", undefined, error);
@@ -1053,269 +981,4 @@ class EntityStorageIdentityConnector {
1053
981
  });
1054
982
  }
1055
983
  }
1056
-
1057
- // Copyright 2024 IOTA Stiftung.
1058
- // SPDX-License-Identifier: Apache-2.0.
1059
- /**
1060
- * Class which implements the identity profile connector contract.
1061
- */
1062
- class EntityStorageIdentityProfileConnector {
1063
- /**
1064
- * The namespace supported by the identity profile connector.
1065
- */
1066
- static NAMESPACE = "entity-storage";
1067
- /**
1068
- * Runtime name for the class.
1069
- */
1070
- static CLASS_NAME = "EntityStorageIdentityProfileConnector";
1071
- /**
1072
- * The storage connector for the profiles.
1073
- * @internal
1074
- */
1075
- _profileEntityStorage;
1076
- /**
1077
- * Create a new instance of EntityStorageIdentityProfileConnector.
1078
- * @param options The options for the identity service.
1079
- */
1080
- constructor(options) {
1081
- this._profileEntityStorage = EntityStorageConnectorFactory.get(options?.profileEntityStorageType ?? "identity-profile");
1082
- }
1083
- /**
1084
- * Create the profile properties for an identity.
1085
- * @param identity The identity of the profile to create.
1086
- * @param publicProfile The public profile data.
1087
- * @param privateProfile The private profile data.
1088
- * @returns Nothing.
1089
- */
1090
- async create(identity, publicProfile, privateProfile) {
1091
- Guards.stringValue(EntityStorageIdentityProfileConnector.CLASS_NAME, "identity", identity);
1092
- try {
1093
- const profile = await this._profileEntityStorage.get(identity);
1094
- if (!Is.empty(profile)) {
1095
- throw new AlreadyExistsError(EntityStorageIdentityProfileConnector.CLASS_NAME, "alreadyExists", identity);
1096
- }
1097
- await this._profileEntityStorage.set({
1098
- identity,
1099
- publicProfile,
1100
- privateProfile
1101
- });
1102
- }
1103
- catch (error) {
1104
- if (BaseError.someErrorClass(error, EntityStorageIdentityProfileConnector.CLASS_NAME)) {
1105
- throw error;
1106
- }
1107
- throw new GeneralError(EntityStorageIdentityProfileConnector.CLASS_NAME, "createFailed", { identity }, error);
1108
- }
1109
- }
1110
- /**
1111
- * Get the profile properties for an identity.
1112
- * @param identity The identity of the item to get.
1113
- * @param publicPropertyNames The public properties to get for the profile, defaults to all.
1114
- * @param privatePropertyNames The private properties to get for the profile, defaults to all.
1115
- * @returns The items properties.
1116
- */
1117
- async get(identity, publicPropertyNames, privatePropertyNames) {
1118
- try {
1119
- const profile = await this._profileEntityStorage.get(identity);
1120
- if (!profile) {
1121
- throw new NotFoundError(EntityStorageIdentityProfileConnector.CLASS_NAME, "identityNotFound", identity);
1122
- }
1123
- return this.pickProperties(profile, publicPropertyNames, privatePropertyNames);
1124
- }
1125
- catch (error) {
1126
- if (BaseError.someErrorClass(error, EntityStorageIdentityProfileConnector.CLASS_NAME)) {
1127
- throw error;
1128
- }
1129
- throw new GeneralError(EntityStorageIdentityProfileConnector.CLASS_NAME, "getFailed", { identity }, error);
1130
- }
1131
- }
1132
- /**
1133
- * Update the profile properties of an identity.
1134
- * @param identity The identity to update.
1135
- * @param publicProfile The public profile data.
1136
- * @param privateProfile The private profile data.
1137
- * @returns Nothing.
1138
- */
1139
- async update(identity, publicProfile, privateProfile) {
1140
- Guards.stringValue(EntityStorageIdentityProfileConnector.CLASS_NAME, "identity", identity);
1141
- try {
1142
- const profile = await this._profileEntityStorage.get(identity);
1143
- if (Is.empty(profile)) {
1144
- throw new NotFoundError(EntityStorageIdentityProfileConnector.CLASS_NAME, "notFound", identity);
1145
- }
1146
- profile.publicProfile = publicProfile ?? profile.publicProfile;
1147
- profile.privateProfile = privateProfile ?? profile.privateProfile;
1148
- await this._profileEntityStorage.set(profile);
1149
- }
1150
- catch (error) {
1151
- if (BaseError.someErrorClass(error, EntityStorageIdentityProfileConnector.CLASS_NAME)) {
1152
- throw error;
1153
- }
1154
- throw new GeneralError(EntityStorageIdentityProfileConnector.CLASS_NAME, "updateFailed", { identity }, error);
1155
- }
1156
- }
1157
- /**
1158
- * Delete the profile for an identity.
1159
- * @param identity The identity to delete.
1160
- * @returns Nothing.
1161
- */
1162
- async remove(identity) {
1163
- Guards.stringValue(EntityStorageIdentityProfileConnector.CLASS_NAME, "identity", identity);
1164
- try {
1165
- const profile = await this._profileEntityStorage.get(identity);
1166
- if (Is.empty(profile)) {
1167
- throw new NotFoundError(EntityStorageIdentityProfileConnector.CLASS_NAME, "notFound", identity);
1168
- }
1169
- await this._profileEntityStorage.remove(identity);
1170
- }
1171
- catch (error) {
1172
- if (BaseError.someErrorClass(error, EntityStorageIdentityProfileConnector.CLASS_NAME)) {
1173
- throw error;
1174
- }
1175
- throw new GeneralError(EntityStorageIdentityProfileConnector.CLASS_NAME, "removeFailed", { identity }, error);
1176
- }
1177
- }
1178
- /**
1179
- * Get a list of the requested types.
1180
- * @param publicFilters The filters to apply to the identities public profiles.
1181
- * @param privateFilters The filters to apply to the identities private profiles.
1182
- * @param publicPropertyNames The public properties to get for the profile, defaults to all.
1183
- * @param privatePropertyNames The private properties to get for the profile, defaults to all.
1184
- * @param cursor The cursor for paged requests.
1185
- * @param limit The maximum number of items in a page.
1186
- * @returns The list of items and cursor for paging.
1187
- */
1188
- async list(publicFilters, privateFilters, publicPropertyNames, privatePropertyNames, cursor, limit) {
1189
- try {
1190
- const conditions = [];
1191
- if (Is.arrayValue(publicFilters)) {
1192
- for (const filter of publicFilters) {
1193
- conditions.push({
1194
- property: `publicProfile.${filter.propertyName}`,
1195
- value: filter.propertyValue,
1196
- comparison: ComparisonOperator.Equals
1197
- });
1198
- }
1199
- }
1200
- if (Is.arrayValue(privateFilters)) {
1201
- for (const filter of privateFilters) {
1202
- conditions.push({
1203
- property: `privateProfile.${filter.propertyName}`,
1204
- value: filter.propertyValue,
1205
- comparison: ComparisonOperator.Equals
1206
- });
1207
- }
1208
- }
1209
- const result = await this._profileEntityStorage.query(Is.arrayValue(conditions)
1210
- ? {
1211
- conditions
1212
- }
1213
- : undefined, undefined, undefined, cursor, limit);
1214
- const items = [];
1215
- for (const resultEntity of result.entities) {
1216
- items.push({
1217
- identity: resultEntity.identity ?? "",
1218
- ...this.pickProperties(resultEntity, publicPropertyNames, privatePropertyNames)
1219
- });
1220
- }
1221
- return {
1222
- items,
1223
- cursor: result.cursor
1224
- };
1225
- }
1226
- catch (error) {
1227
- throw new GeneralError(EntityStorageIdentityProfileConnector.CLASS_NAME, "listFailed", undefined, error);
1228
- }
1229
- }
1230
- /**
1231
- * Get the profile properties for an identity.
1232
- * @param profile The profile to pick the properties from.
1233
- * @param publicPropertyNames The public properties to get for the profile, defaults to all.
1234
- * @param privatePropertyNames The private properties to get for the profile, defaults to all.
1235
- * @returns The identity profile, will only return private data if you have correct permissions.
1236
- * @internal
1237
- */
1238
- pickProperties(profile, publicPropertyNames, privatePropertyNames) {
1239
- return {
1240
- publicProfile: Is.array(publicPropertyNames)
1241
- ? ObjectHelper.pick(profile.publicProfile, publicPropertyNames)
1242
- : profile.publicProfile,
1243
- privateProfile: Is.array(privatePropertyNames)
1244
- ? ObjectHelper.pick(profile.privateProfile, privatePropertyNames)
1245
- : profile.privateProfile
1246
- };
1247
- }
1248
- }
1249
-
1250
- // Copyright 2024 IOTA Stiftung.
1251
- // SPDX-License-Identifier: Apache-2.0.
1252
- /**
1253
- * Class for performing identity operations using entity storage.
1254
- */
1255
- class EntityStorageIdentityResolverConnector {
1256
- /**
1257
- * The namespace supported by the identity connector.
1258
- */
1259
- static NAMESPACE = "entity-storage";
1260
- /**
1261
- * Runtime name for the class.
1262
- */
1263
- static CLASS_NAME = "EntityStorageIdentityResolverConnector";
1264
- /**
1265
- * The entity storage for identities.
1266
- * @internal
1267
- */
1268
- _didDocumentEntityStorage;
1269
- /**
1270
- * The vault for the keys.
1271
- * @internal
1272
- */
1273
- _vaultConnector;
1274
- /**
1275
- * Create a new instance of EntityStorageIdentityResolverConnector.
1276
- * @param options The options for the identity connector.
1277
- */
1278
- constructor(options) {
1279
- this._didDocumentEntityStorage = EntityStorageConnectorFactory.get(options?.didDocumentEntityStorageType ?? "identity-document");
1280
- this._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? "vault");
1281
- }
1282
- /**
1283
- * Resolve a document from its id.
1284
- * @param documentId The id of the document to resolve.
1285
- * @returns The resolved document.
1286
- * @throws NotFoundError if the id can not be resolved.
1287
- */
1288
- async resolveDocument(documentId) {
1289
- Guards.stringValue(EntityStorageIdentityResolverConnector.CLASS_NAME, "documentId", documentId);
1290
- try {
1291
- const didIdentityDocument = await this._didDocumentEntityStorage.get(documentId);
1292
- if (Is.undefined(didIdentityDocument)) {
1293
- throw new NotFoundError(EntityStorageIdentityResolverConnector.CLASS_NAME, "documentNotFound", documentId);
1294
- }
1295
- await EntityStorageIdentityConnector.verifyDocument(didIdentityDocument, this._vaultConnector);
1296
- return didIdentityDocument.document;
1297
- }
1298
- catch (error) {
1299
- throw new GeneralError(EntityStorageIdentityResolverConnector.CLASS_NAME, "resolveDocumentFailed", undefined, error);
1300
- }
1301
- }
1302
- }
1303
-
1304
- // Copyright 2024 IOTA Stiftung.
1305
- // SPDX-License-Identifier: Apache-2.0.
1306
- /**
1307
- * Initialize the schema for the identity entity storage connector.
1308
- * @param options Options for which entities to register.
1309
- * @param options.includeDocument Whether to include the document entity, defaults to true.
1310
- * @param options.includeProfile Whether to include the profile entity, defaults to true.
1311
- */
1312
- function initSchema(options) {
1313
- if (options?.includeDocument ?? true) {
1314
- EntitySchemaFactory.register("IdentityDocument", () => EntitySchemaHelper.getSchema(IdentityDocument));
1315
- }
1316
- if (options?.includeProfile ?? true) {
1317
- EntitySchemaFactory.register("IdentityProfile", () => EntitySchemaHelper.getSchema(IdentityProfile));
1318
- }
1319
- }
1320
-
1321
- export { EntityStorageIdentityConnector, EntityStorageIdentityProfileConnector, EntityStorageIdentityResolverConnector, IdentityDocument, IdentityProfile, initSchema };
984
+ //# sourceMappingURL=entityStorageIdentityConnector.js.map