@verii/endpoints-organizations-registrar 1.0.0-pre.1752076816

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 (259) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +1 -0
  3. package/README.md +3 -0
  4. package/package.json +86 -0
  5. package/src/config/abi.json +1 -0
  6. package/src/config/config.js +261 -0
  7. package/src/controllers/consents/autohooks.js +6 -0
  8. package/src/controllers/consents/controller.js +106 -0
  9. package/src/controllers/consents/schemas/consent-response.schema.js +45 -0
  10. package/src/controllers/did-web-host/controller.js +64 -0
  11. package/src/controllers/groups/autohooks.js +10 -0
  12. package/src/controllers/groups/controller.js +172 -0
  13. package/src/controllers/groups/schemas/group.schema.json +22 -0
  14. package/src/controllers/groups/schemas/index.js +7 -0
  15. package/src/controllers/groups/schemas/modify-group.schema.json +25 -0
  16. package/src/controllers/image_upload/controller.js +48 -0
  17. package/src/controllers/invitations/controller.js +79 -0
  18. package/src/controllers/organizations/_did/autohooks.js +16 -0
  19. package/src/controllers/organizations/_did/controller.js +617 -0
  20. package/src/controllers/organizations/_did/invitations/_invitationId/autohooks.js +16 -0
  21. package/src/controllers/organizations/_did/invitations/_invitationId/controller.js +217 -0
  22. package/src/controllers/organizations/_did/invitations/controller.js +197 -0
  23. package/src/controllers/organizations/_did/keys/controller.js +141 -0
  24. package/src/controllers/organizations/_did/services/controller.js +195 -0
  25. package/src/controllers/organizations/_did/signatories/controller.js +63 -0
  26. package/src/controllers/organizations/autohooks.js +65 -0
  27. package/src/controllers/organizations/controller.js +322 -0
  28. package/src/controllers/organizations/full/controller.js +285 -0
  29. package/src/controllers/organizations/plugins.js +21 -0
  30. package/src/controllers/organizations/schemas/add-key-body.schema.json +35 -0
  31. package/src/controllers/organizations/schemas/create-did-service.schema.json +70 -0
  32. package/src/controllers/organizations/schemas/did-key.schema.json +178 -0
  33. package/src/controllers/organizations/schemas/full-organization.schema.json +35 -0
  34. package/src/controllers/organizations/schemas/index.js +33 -0
  35. package/src/controllers/organizations/schemas/invitationCodeProperty.schema.json +3 -0
  36. package/src/controllers/organizations/schemas/organization-ids.schema.json +34 -0
  37. package/src/controllers/organizations/schemas/organization-kyb-profile-creation.schema.json +26 -0
  38. package/src/controllers/organizations/schemas/organization-profile-creation.schema.json +20 -0
  39. package/src/controllers/organizations/schemas/organization-profile-update.schema.json +19 -0
  40. package/src/controllers/organizations/schemas/organization-profile-verifiable-credential.schema.json +25 -0
  41. package/src/controllers/organizations/schemas/organization-registry-service-response.schema.json +26 -0
  42. package/src/controllers/organizations/schemas/organization-service.schema.json +34 -0
  43. package/src/controllers/organizations/schemas/organization-verified-profile.schema.json +123 -0
  44. package/src/controllers/organizations/schemas/organization.search-profile.query-params.schema.json +50 -0
  45. package/src/controllers/organizations/schemas/organization.search.query-params.schema.json +42 -0
  46. package/src/controllers/reference/controller.js +103 -0
  47. package/src/controllers/resolve-did/controller.js +45 -0
  48. package/src/controllers/resolve-did/resolve-did.js +30 -0
  49. package/src/controllers/resolve-did/schemas/did-doc.schema.json +155 -0
  50. package/src/controllers/resolve-did/schemas/did-proof.schema.json +44 -0
  51. package/src/controllers/resolve-did/schemas/index.js +26 -0
  52. package/src/controllers/resolve-did/schemas/public-key.schema.json +173 -0
  53. package/src/controllers/resolve-kid/controller.js +76 -0
  54. package/src/controllers/resolve-kid/public-key-formats.js +8 -0
  55. package/src/controllers/service-types/controller.js +81 -0
  56. package/src/controllers/setup_image_upload/controller.js +99 -0
  57. package/src/controllers/signatories/controller.js +43 -0
  58. package/src/controllers/users/autohooks.js +10 -0
  59. package/src/controllers/users/controller.js +221 -0
  60. package/src/controllers/users/schemas/base-user.schema.json +55 -0
  61. package/src/controllers/users/schemas/index.js +4 -0
  62. package/src/controllers/users/schemas/modify-user.schema.js +17 -0
  63. package/src/controllers/users/schemas/user.schema.js +20 -0
  64. package/src/entities/groups/domain/constants.js +21 -0
  65. package/src/entities/groups/domain/index.js +19 -0
  66. package/src/entities/groups/factories/groups-factory.js +48 -0
  67. package/src/entities/groups/factories/index.js +17 -0
  68. package/src/entities/groups/index.js +19 -0
  69. package/src/entities/groups/repo.js +122 -0
  70. package/src/entities/images/domain/constant.js +11 -0
  71. package/src/entities/images/domain/index.js +3 -0
  72. package/src/entities/images/extension/activate.extension.js +35 -0
  73. package/src/entities/images/extension/deactivate.extension.js +27 -0
  74. package/src/entities/images/extension/find-by-url.extension.js +24 -0
  75. package/src/entities/images/extension/index.js +5 -0
  76. package/src/entities/images/factories/images-factory.js +43 -0
  77. package/src/entities/images/factories/index.js +17 -0
  78. package/src/entities/images/index.js +5 -0
  79. package/src/entities/images/repo.js +43 -0
  80. package/src/entities/images/schema/image-metadata.schema.js +58 -0
  81. package/src/entities/images/schema/index.js +3 -0
  82. package/src/entities/index.js +31 -0
  83. package/src/entities/invitations/domains/build-invitation-url.js +14 -0
  84. package/src/entities/invitations/domains/get-given-family-name-from-name.js +20 -0
  85. package/src/entities/invitations/domains/index.js +7 -0
  86. package/src/entities/invitations/domains/init-invitation-emails.js +17 -0
  87. package/src/entities/invitations/domains/is-invitation-expired.js +5 -0
  88. package/src/entities/invitations/domains/validate-invitee-email.js +18 -0
  89. package/src/entities/invitations/factories/index.js +17 -0
  90. package/src/entities/invitations/factories/invitations-factory.js +51 -0
  91. package/src/entities/invitations/index.js +6 -0
  92. package/src/entities/invitations/orchestrators/accept-invitation.js +24 -0
  93. package/src/entities/invitations/orchestrators/index.js +4 -0
  94. package/src/entities/invitations/orchestrators/send-email-invitee.js +36 -0
  95. package/src/entities/invitations/repo.js +37 -0
  96. package/src/entities/invitations/schemas/add-invitation-body.js +122 -0
  97. package/src/entities/invitations/schemas/get-invitation-response-body.js +20 -0
  98. package/src/entities/invitations/schemas/index.js +5 -0
  99. package/src/entities/invitations/schemas/invitation-response-item-body.js +61 -0
  100. package/src/entities/kms/factories/index.js +17 -0
  101. package/src/entities/kms/factories/kms-factory.js +31 -0
  102. package/src/entities/monitors/index.js +17 -0
  103. package/src/entities/monitors/orchestrators/index.js +17 -0
  104. package/src/entities/monitors/orchestrators/monitors.js +230 -0
  105. package/src/entities/oauth/domain/constants.js +23 -0
  106. package/src/entities/oauth/domain/index.js +5 -0
  107. package/src/entities/oauth/domain/roles.js +92 -0
  108. package/src/entities/oauth/domain/scopes.js +35 -0
  109. package/src/entities/oauth/index.js +4 -0
  110. package/src/entities/oauth/orchestrators/auth0-provisioner.js +293 -0
  111. package/src/entities/oauth/orchestrators/index.js +3 -0
  112. package/src/entities/organization-keys/domains/build-organization-key.js +50 -0
  113. package/src/entities/organization-keys/domains/constants.js +30 -0
  114. package/src/entities/organization-keys/domains/extract-verification-method-from-byo-did-document.js +38 -0
  115. package/src/entities/organization-keys/domains/find-key-by-purpose.js +6 -0
  116. package/src/entities/organization-keys/domains/index.js +10 -0
  117. package/src/entities/organization-keys/domains/jwk-to-hex-key-transformer.js +13 -0
  118. package/src/entities/organization-keys/domains/map-key-response.js +29 -0
  119. package/src/entities/organization-keys/domains/validate-non-custodial-key.js +11 -0
  120. package/src/entities/organization-keys/domains/validate-organization-key.js +42 -0
  121. package/src/entities/organization-keys/factories/index.js +17 -0
  122. package/src/entities/organization-keys/factories/organization-keys-factory.js +55 -0
  123. package/src/entities/organization-keys/index.js +5 -0
  124. package/src/entities/organization-keys/orchestrators/add-key-to-did-doc.js +19 -0
  125. package/src/entities/organization-keys/orchestrators/add-key.js +155 -0
  126. package/src/entities/organization-keys/orchestrators/add-operator-keys.js +46 -0
  127. package/src/entities/organization-keys/orchestrators/delete-key.js +93 -0
  128. package/src/entities/organization-keys/orchestrators/get-key.js +39 -0
  129. package/src/entities/organization-keys/orchestrators/index.js +24 -0
  130. package/src/entities/organization-keys/orchestrators/resolve-verification-method-byo-did.js +28 -0
  131. package/src/entities/organization-keys/repos/repo.js +48 -0
  132. package/src/entities/organization-services/adapters/index.js +21 -0
  133. package/src/entities/organization-services/adapters/init-provision-auth0-client-grants.js +44 -0
  134. package/src/entities/organization-services/adapters/init-provision-auth0-clients.js +56 -0
  135. package/src/entities/organization-services/adapters/update-blockchain-permissions-from-permitted-services.js +118 -0
  136. package/src/entities/organization-services/domains/activate-services.js +12 -0
  137. package/src/entities/organization-services/domains/build-organizations-services.js +38 -0
  138. package/src/entities/organization-services/domains/build-public-services.js +19 -0
  139. package/src/entities/organization-services/domains/constants.js +32 -0
  140. package/src/entities/organization-services/domains/extract-cao-service-refs.js +10 -0
  141. package/src/entities/organization-services/domains/extract-service-endpoint-did.js +10 -0
  142. package/src/entities/organization-services/domains/get-service-consent-type.js +16 -0
  143. package/src/entities/organization-services/domains/get-service-types-from-categories.js +18 -0
  144. package/src/entities/organization-services/domains/index.js +17 -0
  145. package/src/entities/organization-services/domains/is-new-node-operator-service.js +25 -0
  146. package/src/entities/organization-services/domains/is-service-category.js +31 -0
  147. package/src/entities/organization-services/domains/normalize-service-endpoint.js +6 -0
  148. package/src/entities/organization-services/domains/select-activated-services.js +8 -0
  149. package/src/entities/organization-services/domains/transform-profile-service.js +88 -0
  150. package/src/entities/organization-services/domains/validate-cao-service-refs.js +25 -0
  151. package/src/entities/organization-services/domains/validate-service-credential-type.js +47 -0
  152. package/src/entities/organization-services/domains/validate-service-endpoint.js +35 -0
  153. package/src/entities/organization-services/domains/validate-service-fields-by-service-type.js +37 -0
  154. package/src/entities/organization-services/domains/validate-service-id-uniqueness.js +19 -0
  155. package/src/entities/organization-services/domains/validate-service-key-purposes.js +56 -0
  156. package/src/entities/organization-services/domains/validate-service-type.js +12 -0
  157. package/src/entities/organization-services/domains/validate-service.js +80 -0
  158. package/src/entities/organization-services/domains/validate-services-for-delete.js +32 -0
  159. package/src/entities/organization-services/index.js +5 -0
  160. package/src/entities/organization-services/orchestrators/add-service.js +106 -0
  161. package/src/entities/organization-services/orchestrators/delete-service.js +142 -0
  162. package/src/entities/organization-services/orchestrators/get-service.js +36 -0
  163. package/src/entities/organization-services/orchestrators/index.js +8 -0
  164. package/src/entities/organization-services/orchestrators/init-add-service-to-organization.js +141 -0
  165. package/src/entities/organization-services/orchestrators/load-cao-service-refs.js +56 -0
  166. package/src/entities/organization-services/orchestrators/update-service.js +103 -0
  167. package/src/entities/organizations/adapters/index.js +6 -0
  168. package/src/entities/organizations/adapters/init-organization-registrar-emails.js +215 -0
  169. package/src/entities/organizations/adapters/init-send-activation-emails-to-caos.js +89 -0
  170. package/src/entities/organizations/adapters/send-email-invitation-accepted-to-inviter.js +70 -0
  171. package/src/entities/organizations/adapters/send-email-notifications.js +212 -0
  172. package/src/entities/organizations/domains/build-custodied-did-web.js +12 -0
  173. package/src/entities/organizations/domains/build-full-organization-response.js +40 -0
  174. package/src/entities/organizations/domains/build-organization-modifications-on-service-change.js +82 -0
  175. package/src/entities/organizations/domains/build-profile-vc-url.js +8 -0
  176. package/src/entities/organizations/domains/build-profile-verifiable-credential.js +36 -0
  177. package/src/entities/organizations/domains/build-public-profile.js +9 -0
  178. package/src/entities/organizations/domains/constants.js +54 -0
  179. package/src/entities/organizations/domains/index.js +17 -0
  180. package/src/entities/organizations/domains/organization-vc-checks.js +49 -0
  181. package/src/entities/organizations/domains/parse-profile-to-csv.js +41 -0
  182. package/src/entities/organizations/domains/prepare-profile-vc.js +28 -0
  183. package/src/entities/organizations/domains/profile-name-normalization.js +5 -0
  184. package/src/entities/organizations/domains/validate-byo-did-keys.js +28 -0
  185. package/src/entities/organizations/domains/validate-profile-name.js +48 -0
  186. package/src/entities/organizations/domains/validate-profile-website.js +17 -0
  187. package/src/entities/organizations/domains/validate-update-profile.js +11 -0
  188. package/src/entities/organizations/factories/index.js +17 -0
  189. package/src/entities/organizations/factories/organizations-factory.js +180 -0
  190. package/src/entities/organizations/index.js +6 -0
  191. package/src/entities/organizations/orchestrators/add-primary-permissions.js +28 -0
  192. package/src/entities/organizations/orchestrators/build-custodied-organization.js +92 -0
  193. package/src/entities/organizations/orchestrators/build-non-custodied-organization.js +83 -0
  194. package/src/entities/organizations/orchestrators/index.js +6 -0
  195. package/src/entities/organizations/orchestrators/init-create-organization.js +221 -0
  196. package/src/entities/organizations/orchestrators/init-provision-group.js +48 -0
  197. package/src/entities/organizations/orchestrators/verify-profile-website-unique.js +15 -0
  198. package/src/entities/organizations/repos/find-caos-extension.js +49 -0
  199. package/src/entities/organizations/repos/index.js +17 -0
  200. package/src/entities/organizations/repos/repo.js +156 -0
  201. package/src/entities/organizations/repos/search-by-aggregation-extension.js +128 -0
  202. package/src/entities/organizations/repos/transform-did-filter.js +13 -0
  203. package/src/entities/organizations/repos/transform-organization-filter.js +106 -0
  204. package/src/entities/registrar-consents/constants.js +10 -0
  205. package/src/entities/registrar-consents/factories/index.js +17 -0
  206. package/src/entities/registrar-consents/factories/registrar-consents-factory.js +38 -0
  207. package/src/entities/registrar-consents/index.js +3 -0
  208. package/src/entities/registrar-consents/repos/registrar-consent-repo-extension.js +55 -0
  209. package/src/entities/registrar-consents/repos/repo.js +31 -0
  210. package/src/entities/signatories/domain/constants.js +12 -0
  211. package/src/entities/signatories/domain/index.js +4 -0
  212. package/src/entities/signatories/domain/organization-emails.js +29 -0
  213. package/src/entities/signatories/factories/index.js +17 -0
  214. package/src/entities/signatories/factories/signatory-status-factory.js +53 -0
  215. package/src/entities/signatories/index.js +5 -0
  216. package/src/entities/signatories/orchestrators/approve-reminder.js +24 -0
  217. package/src/entities/signatories/orchestrators/index.js +6 -0
  218. package/src/entities/signatories/orchestrators/reject-reminder.js +17 -0
  219. package/src/entities/signatories/orchestrators/send-reminders.js +102 -0
  220. package/src/entities/signatories/orchestrators/validate-auth-code.js +56 -0
  221. package/src/entities/signatories/repos/index.js +3 -0
  222. package/src/entities/signatories/repos/repo.js +35 -0
  223. package/src/entities/signatories/repos/signatory-status-state-repo-extension.js +124 -0
  224. package/src/entities/users/domains/constants.js +40 -0
  225. package/src/entities/users/domains/index.js +4 -0
  226. package/src/entities/users/domains/user-registrar-emails.js +52 -0
  227. package/src/entities/users/index.js +4 -0
  228. package/src/entities/users/orchestrators/create-auth0-user.js +60 -0
  229. package/src/entities/users/orchestrators/get-or-create-auth0-user.js +63 -0
  230. package/src/entities/users/orchestrators/index.js +22 -0
  231. package/src/entities/users/orchestrators/user-management.js +157 -0
  232. package/src/fetchers/index.js +19 -0
  233. package/src/fetchers/monitoring/index.js +9 -0
  234. package/src/fetchers/monitoring/monitor-add-to-page-fetcher.js +18 -0
  235. package/src/fetchers/monitoring/monitor-create-fetcher.js +23 -0
  236. package/src/fetchers/monitoring/monitor-delete-fetcher.js +6 -0
  237. package/src/fetchers/monitoring/monitor-get-all-fetcher.js +6 -0
  238. package/src/fetchers/monitoring/section-create-fetcher.js +16 -0
  239. package/src/fetchers/monitoring/section-get-all-fetcher.js +6 -0
  240. package/src/fetchers/monitoring/service-version-fetcher.js +6 -0
  241. package/src/helpers/init-permissions-contract.js +48 -0
  242. package/src/index.js +23 -0
  243. package/src/init-server.js +91 -0
  244. package/src/organizations-registrar-endpoints.js +68 -0
  245. package/src/plugins/authorization.js +233 -0
  246. package/src/plugins/index.js +4 -0
  247. package/src/plugins/pubsub-plugin.js +82 -0
  248. package/src/subscribers/notify-caos.js +63 -0
  249. package/src/subscribers/notify-inviters.js +42 -0
  250. package/src/subscribers/notify-monitoring.js +40 -0
  251. package/src/subscribers/notify-signatory.js +51 -0
  252. package/src/subscribers/notify-support-and-groups.js +95 -0
  253. package/src/templates/invitee-invitation-email-body.hbs +13 -0
  254. package/src/templates/invitee-invitation-email-subject.hbs +1 -0
  255. package/src/templates/signatory-approval-email-body.hbs +92 -0
  256. package/src/templates/support-organization-created-body.hbs +17 -0
  257. package/src/templates/support-organization-created-subject.hbs +1 -0
  258. package/src/templates/support-signatory-max-reminders-reached-email-body.hbs +6 -0
  259. package/src/templates/support-signatory-max-reminders-reached-email-subject.hbs +1 -0
@@ -0,0 +1,82 @@
1
+ /*
2
+ * Copyright 2025 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ const { isEmpty, map, defaults, omit, xor } = require('lodash/fp');
19
+ const { categorizeServices } = require('@verii/organizations-registry');
20
+ const {
21
+ selectActivatedServices,
22
+ } = require('../../organization-services/domains');
23
+ const { initPrepareProfileVc } = require('./prepare-profile-vc');
24
+
25
+ const initBuildOrganizationModificationsOnServiceChange = (fastify) => {
26
+ const prepareProfileVc = initPrepareProfileVc(fastify);
27
+ return async ({
28
+ organization,
29
+ services,
30
+ activatedServiceIds,
31
+ newOrganizationIds,
32
+ authClients,
33
+ }) => {
34
+ const { didDoc, profile, ids } = organization;
35
+ const modifications = {};
36
+
37
+ if (newOrganizationIds != null) {
38
+ modifications.ids = defaults(newOrganizationIds, ids);
39
+ }
40
+
41
+ if (authClients != null) {
42
+ modifications.authClients = map(omit(['clientSecret']), authClients);
43
+ }
44
+
45
+ const activatedServices = selectActivatedServices(
46
+ activatedServiceIds,
47
+ services ?? organization.services
48
+ );
49
+ modifications.activatedServiceIds = map('id', activatedServices);
50
+
51
+ const activatedServiceCategories = categorizeServices(activatedServices);
52
+ if (!isPermissionsChanged(profile, activatedServiceCategories)) {
53
+ return modifications;
54
+ }
55
+
56
+ modifications.profile = {
57
+ ...profile,
58
+ permittedVelocityServiceCategory: activatedServiceCategories,
59
+ };
60
+
61
+ const { jwtVc, credentialId, vcUrl } = await prepareProfileVc(
62
+ didDoc,
63
+ modifications.profile
64
+ );
65
+
66
+ modifications.signedProfileVcJwt = {
67
+ signedCredential: jwtVc,
68
+ credentialId,
69
+ };
70
+ modifications.verifiableCredentialJwt = vcUrl;
71
+
72
+ return modifications;
73
+ };
74
+ };
75
+
76
+ const isPermissionsChanged = (profile, newPermissions) =>
77
+ profile.permittedVelocityServiceCategory == null ||
78
+ !isEmpty(xor(profile.permittedVelocityServiceCategory, newPermissions));
79
+
80
+ module.exports = {
81
+ initBuildOrganizationModificationsOnServiceChange,
82
+ };
@@ -0,0 +1,8 @@
1
+ const initBuildProfileVcUrl =
2
+ ({ registrarUrl }) =>
3
+ (didDoc, vcId) =>
4
+ `${registrarUrl}/api/v0.6/organizations/${didDoc.id}/resolve-vc/${vcId}`;
5
+
6
+ module.exports = {
7
+ initBuildProfileVcUrl,
8
+ };
@@ -0,0 +1,36 @@
1
+ const { generateCredentialJwt } = require('@verii/jwt');
2
+ const { VerifiableCredentialTypes } = require('@verii/verifiable-credentials');
3
+ const { v4: uuid } = require('uuid');
4
+ const { buildPublicProfile } = require('./build-public-profile');
5
+
6
+ const initBuildProfileVerifiableCredential =
7
+ ({ config: { rootDid, rootPrivateKey, rootKid } }) =>
8
+ async (profile, didDoc) => {
9
+ const id = uuid();
10
+
11
+ const credential = {
12
+ id,
13
+ type: [
14
+ VerifiableCredentialTypes.BASIC_PROFILE_V1_0,
15
+ VerifiableCredentialTypes.VERIFIABLE_CREDENTIAL,
16
+ ],
17
+ issuer: {
18
+ id: rootDid,
19
+ },
20
+ credentialSubject: {
21
+ id: didDoc.id,
22
+ alsoKnownAs: didDoc.alsoKnownAs,
23
+ ...buildPublicProfile(profile),
24
+ },
25
+ };
26
+ const jwtVc = await generateCredentialJwt(
27
+ credential,
28
+ rootPrivateKey,
29
+ rootKid
30
+ );
31
+ return { jwtVc, credentialId: id };
32
+ };
33
+
34
+ module.exports = {
35
+ initBuildProfileVerifiableCredential,
36
+ };
@@ -0,0 +1,9 @@
1
+ const { omit } = require('lodash/fp');
2
+ const { PublicProfileFieldsForHide } = require('./constants');
3
+
4
+ const buildPublicProfile = (verifiedProfile) =>
5
+ omit(PublicProfileFieldsForHide, verifiedProfile);
6
+
7
+ module.exports = {
8
+ buildPublicProfile,
9
+ };
@@ -0,0 +1,54 @@
1
+ const { ServiceTypes } = require('@verii/organizations-registry');
2
+
3
+ const Authorities = {
4
+ NationalAuthority: 'NationalAuthority',
5
+ DunnAndBradstreet: 'DunnAndBradstreet',
6
+ GLEIF: 'GLEIF',
7
+ LinkedIn: 'LinkedIn',
8
+ };
9
+
10
+ const OrganizationTypes = {
11
+ COMPANY: 'company',
12
+ NON_PROFIT: 'non-profit',
13
+ };
14
+
15
+ const OrganizationErrorMessages = {
16
+ ORGANIZATION_NOT_FOUND: 'Organization not found',
17
+ VERIFIABLE_CREDENTIAL_NOT_FOUND: 'Verifiable Credential not found',
18
+ UNRECOGNIZED_VERIFIABLE_CREDENTIAL_TYPE:
19
+ 'Unrecognized Verifiable Credential type',
20
+ };
21
+
22
+ const PublicProfileFieldsForHide = [
23
+ 'adminGivenName',
24
+ 'adminFamilyName',
25
+ 'adminName',
26
+ 'adminTitle',
27
+ 'adminEmail',
28
+ 'signatoryGivenName',
29
+ 'signatoryFamilyName',
30
+ 'signatoryName',
31
+ 'signatoryTitle',
32
+ 'signatoryEmail',
33
+ ];
34
+
35
+ const ServiceTypeLabels = {
36
+ [ServiceTypes.InspectionType]: 'Relying Party',
37
+ [ServiceTypes.NotaryIssuerType]: 'Notary Issuer',
38
+ [ServiceTypes.HolderAppProviderType]: 'Wallet App Provider',
39
+ [ServiceTypes.NodeOperatorType]: 'Node Operator',
40
+ [ServiceTypes.CredentialAgentOperatorType]: 'Credential Agent Operator',
41
+ [ServiceTypes.CareerIssuerType]: 'Issuer of Career Credentials',
42
+ [ServiceTypes.IdentityIssuerType]: 'Issuer of Identity Credentials',
43
+ [ServiceTypes.IdentityIssuerType]: 'Issuer of Identity Credentials',
44
+ [ServiceTypes.IdentityIssuerType]: 'Issuer of Identity Credentials',
45
+ [ServiceTypes.IdentityIssuerType]: 'Issuer of Identity Credentials',
46
+ };
47
+
48
+ module.exports = {
49
+ Authorities,
50
+ OrganizationErrorMessages,
51
+ OrganizationTypes,
52
+ PublicProfileFieldsForHide,
53
+ ServiceTypeLabels,
54
+ };
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ ...require('./build-custodied-did-web'),
3
+ ...require('./build-full-organization-response'),
4
+ ...require('./build-organization-modifications-on-service-change'),
5
+ ...require('./build-profile-vc-url'),
6
+ ...require('./build-profile-verifiable-credential'),
7
+ ...require('./build-public-profile'),
8
+ ...require('./constants'),
9
+ ...require('./organization-vc-checks'),
10
+ ...require('./parse-profile-to-csv'),
11
+ ...require('./prepare-profile-vc'),
12
+ ...require('./profile-name-normalization'),
13
+ ...require('./validate-byo-did-keys'),
14
+ ...require('./validate-profile-name'),
15
+ ...require('./validate-profile-website'),
16
+ ...require('./validate-update-profile'),
17
+ };
@@ -0,0 +1,49 @@
1
+ const { decodeCredentialJwt } = require('@verii/jwt');
2
+ const { CredentialCheckResultValue } = require('@verii/verifiable-credentials');
3
+ const {
4
+ checkExpiration,
5
+ checkJwtVCTampering,
6
+ CheckResults,
7
+ } = require('@verii/vc-checks');
8
+
9
+ const checkOrgIssuerMatch = ({ issuer }, trustedIssuer) => {
10
+ const id = issuer?.id ?? issuer;
11
+ return id !== trustedIssuer
12
+ ? CredentialCheckResultValue.FAIL
13
+ : CredentialCheckResultValue.PASS;
14
+ };
15
+
16
+ const runAllOrgChecks = async (
17
+ { signedCredential, rootJwk, rootDid },
18
+ context
19
+ ) => {
20
+ const decodedCredential = await decodeCredentialJwt(signedCredential);
21
+
22
+ const tamperingCheck = await checkJwtVCTampering(
23
+ signedCredential,
24
+ rootJwk,
25
+ context
26
+ );
27
+
28
+ if (tamperingCheck !== CheckResults.PASS) {
29
+ return {
30
+ UNTAMPERED: tamperingCheck,
31
+ TRUSTED_ISSUER: CredentialCheckResultValue.NOT_CHECKED,
32
+ UNREVOKED: CredentialCheckResultValue.NOT_CHECKED,
33
+ UNEXPIRED: CredentialCheckResultValue.NOT_CHECKED,
34
+ checked: new Date(),
35
+ };
36
+ }
37
+
38
+ return {
39
+ UNTAMPERED: tamperingCheck,
40
+ TRUSTED_ISSUER: checkOrgIssuerMatch(decodedCredential, rootDid),
41
+ UNREVOKED: CredentialCheckResultValue.NOT_CHECKED,
42
+ UNEXPIRED: checkExpiration(decodedCredential),
43
+ checked: new Date(),
44
+ };
45
+ };
46
+
47
+ module.exports = {
48
+ runAllOrgChecks,
49
+ };
@@ -0,0 +1,41 @@
1
+ const { parseToCsv } = require('@verii/csv-parser');
2
+ const { join, isNil, omitBy, flow, reject } = require('lodash/fp');
3
+ const { Authorities } = require('./constants');
4
+
5
+ const parseProfileToCsv = async (organizationProfile) => {
6
+ const csvFile = await parseToCsv(
7
+ [
8
+ flow(omitBy(isNil), (profile) => ({
9
+ ...profile,
10
+ ...buildPermittedVelocityServiceCategory(profile),
11
+ ...removeLinkedInRegistrationNumber(profile),
12
+ }))(organizationProfile),
13
+ ],
14
+ ['registrationNumbers', 'commercialEntities']
15
+ );
16
+ return csvFile;
17
+ };
18
+
19
+ const buildPermittedVelocityServiceCategory = (profile) => {
20
+ const obj = {};
21
+ if (profile?.permittedVelocityServiceCategory != null) {
22
+ obj.permittedVelocityServiceCategory = join(
23
+ ', ',
24
+ profile.permittedVelocityServiceCategory
25
+ );
26
+ }
27
+ return obj;
28
+ };
29
+
30
+ const removeLinkedInRegistrationNumber = (profile) => {
31
+ return {
32
+ registrationNumbers: reject(
33
+ { authority: Authorities.LinkedIn },
34
+ profile.registrationNumbers
35
+ ),
36
+ };
37
+ };
38
+
39
+ module.exports = {
40
+ parseProfileToCsv,
41
+ };
@@ -0,0 +1,28 @@
1
+ const {
2
+ initBuildProfileVerifiableCredential,
3
+ } = require('./build-profile-verifiable-credential');
4
+ const { initBuildProfileVcUrl } = require('./build-profile-vc-url');
5
+
6
+ const initPrepareProfileVc = (fastify) => {
7
+ const buildProfileVerifiableCredential =
8
+ initBuildProfileVerifiableCredential(fastify);
9
+ const buildProfileVcUrl = initBuildProfileVcUrl({
10
+ registrarUrl: fastify.config.hostUrl,
11
+ });
12
+ return async (didDoc, profile) => {
13
+ const { jwtVc, credentialId } = await buildProfileVerifiableCredential(
14
+ profile,
15
+ didDoc
16
+ );
17
+
18
+ const vcUrl = buildProfileVcUrl(didDoc, credentialId);
19
+
20
+ return {
21
+ credentialId,
22
+ jwtVc,
23
+ vcUrl,
24
+ };
25
+ };
26
+ };
27
+
28
+ module.exports = { initPrepareProfileVc };
@@ -0,0 +1,5 @@
1
+ const normalizeProfileName = (name) =>
2
+ name.replace(/\s+/g, ' ').toLowerCase().trim();
3
+ module.exports = {
4
+ normalizeProfileName,
5
+ };
@@ -0,0 +1,28 @@
1
+ const { KeyPurposes } = require('@verii/crypto');
2
+ const newError = require('http-errors');
3
+ const { isEmpty, all, find } = require('lodash/fp');
4
+
5
+ const validateByoDidKeys = (keys) => {
6
+ if (isEmpty(keys)) {
7
+ throw newError(400, 'Keys are required for BYO DID', {
8
+ code: 'keys_required',
9
+ });
10
+ }
11
+ const isNonCustodialKeys = all((key) => !key.custodial, keys);
12
+ if (!isNonCustodialKeys) {
13
+ throw newError(400, 'Keys must be non-custodial', {
14
+ code: 'keys_must_be_non_custodial',
15
+ });
16
+ }
17
+ const dlt = find(
18
+ (key) => key.purposes.includes(KeyPurposes.DLT_TRANSACTIONS),
19
+ keys
20
+ );
21
+ if (isEmpty(dlt)) {
22
+ throw newError(400, 'Keys must include DLT_TRANSACTIONS purpose', {
23
+ code: 'keys_must_include_dlt_transactions',
24
+ });
25
+ }
26
+ };
27
+
28
+ module.exports = { validateByoDidKeys };
@@ -0,0 +1,48 @@
1
+ /*
2
+ * Copyright 2025 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ const newError = require('http-errors');
19
+ const { normalizeProfileName } = require('./profile-name-normalization');
20
+ const { hasAdminOrganizationScope } = require('../../oauth');
21
+
22
+ const validateProfileName = async (name, organization, { repos, user }) => {
23
+ const normalizedProfileName = normalizeProfileName(name);
24
+
25
+ if (organization != null) {
26
+ if (normalizedProfileName === organization.normalizedProfileName) {
27
+ return;
28
+ }
29
+
30
+ if (!hasAdminOrganizationScope(user)) {
31
+ throw newError(400, 'Name change forbidden', {
32
+ errorCode: 'name_change_forbidden',
33
+ });
34
+ }
35
+ }
36
+
37
+ const count = await repos.organizations.count({
38
+ filter: { normalizedProfileName },
39
+ });
40
+
41
+ if (count > 0) {
42
+ throw newError(400, 'Organization name already exists', {
43
+ errorCode: 'name_change_forbidden',
44
+ });
45
+ }
46
+ };
47
+
48
+ module.exports = { validateProfileName };
@@ -0,0 +1,17 @@
1
+ const newError = require('http-errors');
2
+
3
+ const validateProfileWebsite = ({ profile }) => {
4
+ const url = new URL(profile.website);
5
+ if (url.protocol !== 'https:') {
6
+ throw newError(400, 'Website protocol must be https', {
7
+ errorCode: 'website_protocol_must_be_https',
8
+ });
9
+ }
10
+ if (url.pathname !== '/' || `${profile.website}/` !== url.href) {
11
+ throw newError(400, 'Website must have empty path after domain', {
12
+ errorCode: 'website_path_must_be_empty',
13
+ });
14
+ }
15
+ };
16
+
17
+ module.exports = { validateProfileWebsite };
@@ -0,0 +1,11 @@
1
+ const newError = require('http-errors');
2
+
3
+ const validateUpdateProfile = (profile) => {
4
+ if (profile.website != null) {
5
+ throw newError(400, 'Website must not be specified', {
6
+ errorCode: 'website_must_not_be_specified',
7
+ });
8
+ }
9
+ };
10
+
11
+ module.exports = { validateUpdateProfile };
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2025 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+ module.exports = { ...require('./organizations-factory') };
@@ -0,0 +1,180 @@
1
+ /*
2
+ * Copyright 2025 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ */
17
+
18
+ /* eslint-disable complexity */
19
+ const { compact, filter, flow, map } = require('lodash/fp');
20
+ const { register } = require('@spencejs/spence-factories');
21
+ const { createDidDoc, toRelativeServiceId } = require('@verii/did-doc');
22
+ const { categorizeServices } = require('@verii/organizations-registry');
23
+ const { hexFromJwk } = require('@verii/jwt');
24
+ const {
25
+ KeyPurposes,
26
+ generateKeyPair,
27
+ KeyAlgorithms,
28
+ } = require('@verii/crypto');
29
+ const { toEthereumAddress } = require('@verii/blockchain-functions');
30
+
31
+ const { ObjectId } = require('mongodb');
32
+ const {
33
+ initBuildProfileVerifiableCredential,
34
+ initBuildProfileVcUrl,
35
+ normalizeProfileName,
36
+ Authorities,
37
+ } = require('../domains');
38
+
39
+ const organizationsRepoPlugin = require('../repos/repo');
40
+
41
+ module.exports = (app) => {
42
+ const buildProfileVerifiableCredential =
43
+ initBuildProfileVerifiableCredential(app);
44
+
45
+ const buildProfileVcUrl = initBuildProfileVcUrl({
46
+ registrarUrl: app.config.hostUrl,
47
+ });
48
+
49
+ return register(
50
+ 'organization',
51
+ organizationsRepoPlugin(app)(app),
52
+ async (overrides, { getOrBuild }) => {
53
+ const nonce = generateKeyPair().privateKey;
54
+ const website = await getOrBuild(
55
+ 'website',
56
+ () => `https://www.${nonce}.organization.com`
57
+ );
58
+ const did = await getOrBuild('did', () => `did:test:${nonce}`);
59
+ const alsoKnownAs = await getOrBuild('alsoKnownAs', () => undefined);
60
+ const didNotCustodied = await getOrBuild('didNotCustodied', () => false);
61
+ const services = await getOrBuild('service', () => []);
62
+ const activatedServiceIds = await getOrBuild('activatedServiceIds', () =>
63
+ flow(map('id'), compact, map(toRelativeServiceId))(services)
64
+ );
65
+ const activatedServices = filter(
66
+ (s) => activatedServiceIds.includes(s.id),
67
+ services
68
+ );
69
+ const { publicKey: ethereumKey } = generateKeyPair({ format: 'jwk' });
70
+ const { publicKey: dltTransactionsPublicKey } = generateKeyPair({
71
+ format: 'jwk',
72
+ });
73
+
74
+ const keys = await getOrBuild('keys', () => [
75
+ {
76
+ id: '#eth-account-key-1',
77
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
78
+ type: 'EcdsaSecp256k1VerificationKey2019',
79
+ publicKey: dltTransactionsPublicKey,
80
+ algorithm: KeyAlgorithms.SECP256K1,
81
+ },
82
+ ]);
83
+ const { didDoc } = createDidDoc({
84
+ did,
85
+ services,
86
+ keys,
87
+ alsoKnownAs,
88
+ });
89
+
90
+ // eslint-disable-next-line better-mutation/no-mutation
91
+ didDoc.id = await getOrBuild('didDocId', () => didDoc.id);
92
+
93
+ const mergeIds = await getOrBuild('_mergeIds', () => {});
94
+
95
+ const ids = {
96
+ did: didDoc.id,
97
+ ethereumAccount: toEthereumAddress(hexFromJwk(ethereumKey, false)),
98
+ fineractClientId: '1',
99
+ tokenAccountId: '9',
100
+ escrowAccountId: '5',
101
+ brokerClientId: new ObjectId(),
102
+ ...mergeIds,
103
+ };
104
+ const commercialEntities = await getOrBuild(
105
+ 'commercialEntities',
106
+ () => undefined
107
+ );
108
+ const skipTechnicalEmail = await getOrBuild(
109
+ 'skipTechnicalEmail',
110
+ () => false
111
+ );
112
+ const skipContactEmail = await getOrBuild(
113
+ 'skipContactEmail',
114
+ () => false
115
+ );
116
+ const ovverideObj = overrides();
117
+ const profile = ovverideObj.profile || {
118
+ name: await getOrBuild('name', () => 'Test Organization'),
119
+ ...(commercialEntities && { commercialEntities }),
120
+ logo: 'http://www.organization.com/logo.png',
121
+ website,
122
+ registrationNumbers: [
123
+ {
124
+ authority: Authorities.DunnAndBradstreet,
125
+ number: '1',
126
+ uri: 'uri://uri',
127
+ },
128
+ ],
129
+ location: {
130
+ countryCode: 'US',
131
+ regionCode: 'NY',
132
+ },
133
+ type: 'company',
134
+ founded: '2020-01-01',
135
+ closed: '2020-01-01',
136
+ description: 'Short description',
137
+ permittedVelocityServiceCategory: categorizeServices(activatedServices),
138
+ linkedInProfile: 'https://www.linkedin.com/in/test-profile',
139
+ physicalAddress: {
140
+ line1: '123 Main St',
141
+ line2: 'Suite 123',
142
+ line3: 'New York',
143
+ },
144
+ adminGivenName: 'Admin Given Name',
145
+ adminFamilyName: 'Admin Family Name',
146
+ adminTitle: 'Admin Title',
147
+ adminEmail: 'admin@email.com',
148
+ signatoryGivenName: 'Signatory Given Name',
149
+ signatoryFamilyName: 'Signatory Family Name',
150
+ signatoryTitle: 'Signatory Title',
151
+ signatoryEmail: 'signatory@email.com',
152
+ ...(!skipTechnicalEmail && { technicalEmail: 'technical@email.com' }),
153
+ ...(!skipContactEmail && { contactEmail: 'contact@example.com' }),
154
+ };
155
+
156
+ const { jwtVc, credentialId } = await buildProfileVerifiableCredential(
157
+ profile,
158
+ didDoc
159
+ );
160
+ const verifiableCredentialJwt = buildProfileVcUrl(didDoc, credentialId);
161
+ return {
162
+ didDoc: didNotCustodied
163
+ ? { id: didDoc.id }
164
+ : { ...didDoc, service: services },
165
+ profile,
166
+ signedProfileVcJwt: { signedCredential: jwtVc, credentialId },
167
+ verifiableCredentialJwt,
168
+ authClients: [],
169
+ services,
170
+ activatedServiceIds,
171
+ didNotCustodied,
172
+ normalizedProfileName: await getOrBuild('normalizedProfileName', () =>
173
+ normalizeProfileName(profile.name)
174
+ ),
175
+ ids,
176
+ ...ovverideObj,
177
+ };
178
+ }
179
+ );
180
+ };
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ ...require('./adapters'),
3
+ ...require('./domains'),
4
+ ...require('./orchestrators'),
5
+ ...require('./repos'),
6
+ };
@@ -0,0 +1,28 @@
1
+ const { toEthereumAddress } = require('@verii/blockchain-functions');
2
+ const { initPermissions } = require('@verii/contract-permissions');
3
+
4
+ const addPrimaryPermissions = async (
5
+ { primaryAccount, rotationKeyPair, permissioningKeyPair },
6
+ context
7
+ ) => {
8
+ const {
9
+ config: { rootPrivateKey, permissionsContractAddress },
10
+ rpcProvider,
11
+ } = context;
12
+
13
+ const permissionRootContract = await initPermissions(
14
+ {
15
+ privateKey: rootPrivateKey,
16
+ contractAddress: permissionsContractAddress,
17
+ rpcProvider,
18
+ },
19
+ context
20
+ );
21
+ await permissionRootContract.addPrimary({
22
+ primary: primaryAccount,
23
+ permissioning: toEthereumAddress(permissioningKeyPair.publicKey),
24
+ rotation: toEthereumAddress(rotationKeyPair.publicKey),
25
+ });
26
+ };
27
+
28
+ module.exports = { addPrimaryPermissions };