@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,285 @@
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
+ const { map } = require('lodash/fp');
18
+ const { wrapValidationError } = require('@verii/validation');
19
+ const {
20
+ RegistrarScopes,
21
+ buildFullOrganizationResponse,
22
+ buildProfileResponse,
23
+ initCreateOrganization,
24
+ initTransformOrganizationFilter,
25
+ validateProfileName,
26
+ validateProfileWebsite,
27
+ verifyProfileWebsiteUnique,
28
+ } = require('../../../entities');
29
+ const {
30
+ verifyUserOrganizationReadAuthorized,
31
+ verifyUserOrganizationWriteAuthorized,
32
+ } = require('../../../plugins/authorization');
33
+ const { registeredCredentialTypesPreHandler } = require('../plugins');
34
+ const {
35
+ invitationCodePropertySchema,
36
+ addKeyBodySchema,
37
+ } = require('../schemas');
38
+
39
+ const fullOrganizationController = async (fastify) => {
40
+ const transformToFinder = initTransformOrganizationFilter();
41
+ const createOrganization = initCreateOrganization(fastify);
42
+
43
+ fastify
44
+ .get(
45
+ '/',
46
+ {
47
+ onRequest: [
48
+ fastify.verifyAccessToken([
49
+ RegistrarScopes.ReadOrganizations,
50
+ RegistrarScopes.AdminOrganizations,
51
+ ]),
52
+ ],
53
+ preHandler: [verifyUserOrganizationReadAuthorized],
54
+ schema: fastify.autoSchema({
55
+ security: [
56
+ {
57
+ RegistrarOAuth2: [
58
+ RegistrarScopes.ReadOrganizations,
59
+ RegistrarScopes.AdminOrganizations,
60
+ ],
61
+ },
62
+ ],
63
+ querystring: { $ref: 'organization-search-query-params#' },
64
+ response: {
65
+ 200: {
66
+ type: 'object',
67
+ properties: {
68
+ result: {
69
+ type: 'array',
70
+ items: {
71
+ $ref: 'https://velocitycareerlabs.io/full-organization.json#',
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ }),
78
+ },
79
+ async (req) => {
80
+ const { repos, query } = req;
81
+ const organizations = await repos.organizations.find(
82
+ transformToFinder(query)
83
+ );
84
+ return {
85
+ result: map(
86
+ (organization) => buildFullOrganizationResponse({ organization }),
87
+ organizations
88
+ ),
89
+ };
90
+ }
91
+ )
92
+ .get(
93
+ '/:did',
94
+ {
95
+ onRequest: fastify.verifyAccessToken([
96
+ RegistrarScopes.ReadOrganizations,
97
+ RegistrarScopes.AdminOrganizations,
98
+ ]),
99
+ preHandler: [verifyUserOrganizationReadAuthorized],
100
+ schema: fastify.autoSchema({
101
+ security: [
102
+ {
103
+ RegistrarOAuth2: [
104
+ RegistrarScopes.ReadOrganizations,
105
+ RegistrarScopes.AdminOrganizations,
106
+ ],
107
+ },
108
+ ],
109
+ params: {
110
+ type: 'object',
111
+ properties: {
112
+ did: {
113
+ type: 'string',
114
+ },
115
+ },
116
+ },
117
+ response: {
118
+ 200: {
119
+ $ref: 'https://velocitycareerlabs.io/full-organization.json#',
120
+ },
121
+ },
122
+ }),
123
+ },
124
+ async ({ repos, params }) => {
125
+ const organization = await repos.organizations.findOneByDid(params.did);
126
+ return buildFullOrganizationResponse({ organization });
127
+ }
128
+ )
129
+ .post(
130
+ '/',
131
+ {
132
+ onRequest: fastify.verifyAccessToken([
133
+ RegistrarScopes.AdminOrganizations,
134
+ RegistrarScopes.WriteOrganizations,
135
+ ]),
136
+ preHandler: [
137
+ verifyUserOrganizationWriteAuthorized,
138
+ validateFullOrganizationBody,
139
+ registeredCredentialTypesPreHandler,
140
+ ],
141
+ schema: fastify.autoSchema({
142
+ security: [
143
+ {
144
+ RegistrarOAuth2: [
145
+ RegistrarScopes.WriteOrganizations,
146
+ RegistrarScopes.AdminOrganizations,
147
+ ],
148
+ },
149
+ ],
150
+ body: {
151
+ type: 'object',
152
+ properties: {
153
+ profile: {
154
+ $ref: 'organization-profile-creation#',
155
+ },
156
+ serviceEndpoints: {
157
+ type: 'array',
158
+ items: { $ref: 'create-did-service#' },
159
+ },
160
+ invitationCode: invitationCodePropertySchema,
161
+ byoDid: {
162
+ type: 'string',
163
+ pattern: '^did:web:[A-Za-z0-9._:?=&%;-]+$',
164
+ },
165
+ keys: {
166
+ type: 'array',
167
+ items: addKeyBodySchema,
168
+ },
169
+ },
170
+ required: ['profile'],
171
+ },
172
+ response: {
173
+ 201: {
174
+ allOf: [
175
+ {
176
+ $ref: 'https://velocitycareerlabs.io/full-organization.json#',
177
+ },
178
+ {
179
+ type: 'object',
180
+ properties: {
181
+ keys: {
182
+ type: 'array',
183
+ items: { $ref: 'did-key#' },
184
+ },
185
+ authClients: {
186
+ type: 'array',
187
+ items: {
188
+ type: 'object',
189
+ properties: {
190
+ type: { type: 'string' },
191
+ clientType: { type: 'string' },
192
+ clientId: { type: 'string' },
193
+ clientSecret: { type: 'string' },
194
+ serviceId: { type: 'string' },
195
+ },
196
+ },
197
+ },
198
+ messageCode: {
199
+ type: 'string',
200
+ },
201
+ },
202
+ },
203
+ ],
204
+ required: ['didDoc', 'profile', 'keys'],
205
+ },
206
+ 400: { $ref: 'error#' },
207
+ },
208
+ }),
209
+ },
210
+ async (req, reply) => {
211
+ const {
212
+ body: {
213
+ serviceEndpoints,
214
+ invitationCode,
215
+ byoDid,
216
+ profile,
217
+ keys: byoKeys,
218
+ },
219
+ } = req;
220
+
221
+ const { organization, keys, keyPairs, authClients, messageCode } =
222
+ await createOrganization(
223
+ {
224
+ byoDid,
225
+ byoKeys,
226
+ serviceEndpoints,
227
+ invitationCode,
228
+ profile,
229
+ },
230
+ req
231
+ );
232
+ reply.code(201);
233
+ return buildFullOrganizationResponse({
234
+ organization,
235
+ profile: buildProfileResponse(organization, true),
236
+ keys,
237
+ keyPairs,
238
+ authClients,
239
+ messageCode,
240
+ });
241
+ }
242
+ );
243
+ };
244
+
245
+ const validateFullOrganizationBody = async (req) => {
246
+ const schema =
247
+ req.config.isProd || req.headers['x-validate-kyb-profile'] === '1'
248
+ ? newKybFullOrganizationSchema
249
+ : newFullOrganizationSchema;
250
+
251
+ const validate = req.compileValidationSchema(schema, 'body');
252
+
253
+ if (!validate(req.body)) {
254
+ throw wrapValidationError(validate.errors, 'body');
255
+ }
256
+
257
+ const { profile } = req.body;
258
+ await validateProfileName(profile.name, null, req);
259
+ validateProfileWebsite({ profile });
260
+ await verifyProfileWebsiteUnique({ profile }, req);
261
+ };
262
+
263
+ const buildNewFullOrganizationSchema = (profileRef) => ({
264
+ type: 'object',
265
+ properties: {
266
+ profile: {
267
+ $ref: profileRef,
268
+ },
269
+ serviceEndpoints: {
270
+ type: 'array',
271
+ items: { $ref: 'create-did-service#' },
272
+ },
273
+ invitationCode: invitationCodePropertySchema,
274
+ },
275
+ required: ['profile'],
276
+ });
277
+
278
+ const newFullOrganizationSchema = buildNewFullOrganizationSchema(
279
+ 'organization-profile-creation#'
280
+ );
281
+ const newKybFullOrganizationSchema = buildNewFullOrganizationSchema(
282
+ 'organization-kyb-profile-creation#'
283
+ );
284
+
285
+ module.exports = fullOrganizationController;
@@ -0,0 +1,21 @@
1
+ const { map } = require('lodash/fp');
2
+
3
+ const loadCredentialTypes = async (req) => {
4
+ const allCredentialSchemas = await req.repos.credentialSchemas.find(
5
+ { filter: {} },
6
+ { credentialType: 1, _id: 0 }
7
+ );
8
+ return map('credentialType', allCredentialSchemas);
9
+ };
10
+
11
+ const registeredCredentialTypesPreHandler = async (req) => {
12
+ // eslint-disable-next-line better-mutation/no-mutation
13
+ req.registeredCredentialTypes = await loadCredentialTypes(req);
14
+ };
15
+
16
+ const CredentialTypesPlugin = (fastify, options, next) => {
17
+ fastify.decorateRequest('registeredCredentialTypes', null);
18
+ next();
19
+ };
20
+
21
+ module.exports = { CredentialTypesPlugin, registeredCredentialTypesPreHandler };
@@ -0,0 +1,35 @@
1
+ {
2
+ "title": "add-key-body",
3
+ "$id": "https://velocitycareerlabs.io/add-key-body.json",
4
+ "type": "object",
5
+ "description": "payload for adding a key to an organization in the registrar",
6
+ "additionalProperties": true,
7
+ "properties": {
8
+ "kidFragment": {
9
+ "type": "string",
10
+ "pattern": "^#[a-zA-Z0-9-_:?=&;]+$"
11
+ },
12
+ "purposes": {
13
+ "type": "array",
14
+ "minItems": 1,
15
+ "items": {
16
+ "type": "string"
17
+ }
18
+ },
19
+ "algorithm": {
20
+ "type": "string",
21
+ "enum": [
22
+ "SECP256K1"
23
+ ],
24
+ "default": "SECP256K1"
25
+ },
26
+ "custodied": {
27
+ "type": "boolean",
28
+ "default": false
29
+ }
30
+ },
31
+ "required": [
32
+ "purposes",
33
+ "algorithm"
34
+ ]
35
+ }
@@ -0,0 +1,70 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "create-did-service",
4
+ "title": "create-did-service",
5
+ "additionalProperties": true,
6
+ "type": "object",
7
+ "properties": {
8
+ "type": {
9
+ "type": "string",
10
+ "enum": [
11
+ "VlcCredentialAgentOperator_v1",
12
+ "VlcCareerIssuer_v1",
13
+ "VlcIdentityIssuer_v1",
14
+ "VlcNotaryIssuer_v1",
15
+ "VlcInspector_v1",
16
+ "VlcNodeOperator_v1",
17
+ "VlcIdDocumentIssuer_v1",
18
+ "VlcNotaryIdDocumentIssuer_v1",
19
+ "VlcContactIssuer_v1",
20
+ "VlcNotaryContactIssuer_v1",
21
+ "VlcHolderAppProvider_v1",
22
+ "VlcWebWalletProvider_v1"
23
+ ],
24
+ "minLength": 1,
25
+ "maxLength": 30
26
+ },
27
+ "id": {
28
+ "type": "string",
29
+ "description": "Just the id fragment, without the hash"
30
+ },
31
+ "serviceEndpoint": {
32
+ "type": "string"
33
+ },
34
+ "logoUrl": {
35
+ "type": "string",
36
+ "format": "uri"
37
+ },
38
+ "playStoreUrl": {
39
+ "type": "string",
40
+ "format": "uri"
41
+ },
42
+ "appleAppStoreUrl": {
43
+ "type": "string",
44
+ "format": "uri"
45
+ },
46
+ "appleAppId": {
47
+ "type": "string"
48
+ },
49
+ "googlePlayId": {
50
+ "type": "string"
51
+ },
52
+ "name": {
53
+ "type": "string"
54
+ },
55
+ "supportedExchangeProtocols": {
56
+ "type": "array",
57
+ "items": {
58
+ "type": "string",
59
+ "enum": [
60
+ "VN_API",
61
+ "OPENID4VC"
62
+ ]
63
+ },
64
+ "minItems": 1
65
+ }
66
+ },
67
+ "required": [
68
+ "id"
69
+ ]
70
+ }
@@ -0,0 +1,178 @@
1
+ {
2
+ "$id": "did-key",
3
+ "title": "did-key",
4
+ "type": "object",
5
+ "description": "A registered organization's key",
6
+ "properties": {
7
+ "kidFragment": {
8
+ "type": "string",
9
+ "pattern": "^#[a-zA-Z0-9-_:?=&;]+$",
10
+ "description": "the fragment of the key's id value within the did document. Includes the starting #. The full kid used will be {did}{kidFragment}"
11
+ },
12
+ "purposes": {
13
+ "type": "array",
14
+ "description": "the purposes of the key",
15
+ "minItems": 1,
16
+ "items": {
17
+ "type": "string",
18
+ "enum": [
19
+ "DLT_TRANSACTIONS",
20
+ "ISSUING_METADATA",
21
+ "EXCHANGES"
22
+ ]
23
+ }
24
+ },
25
+ "algorithm": {
26
+ "type": "string",
27
+ "enum": [
28
+ "SECP256K1"
29
+ ],
30
+ "deprecated": true,
31
+ "description": "the algorithm used",
32
+ "default": "SECP256K1"
33
+ },
34
+ "encoding": {
35
+ "type": "string",
36
+ "deprecated": true,
37
+ "description": "the encoding of the `key` value. Always set to \"hex\". \nDeprecated"
38
+ },
39
+ "key": {
40
+ "type": "string",
41
+ "pattern": "^#.+$",
42
+ "description": "hex representation of the private key"
43
+ },
44
+ "didDocumentKey": {
45
+ "$ref": "#/definitions/PublicKey"
46
+ },
47
+ "custodied": {
48
+ "type": "boolean",
49
+ "description": "indicates the key is custodied on the server"
50
+ }
51
+
52
+ },
53
+ "required": [
54
+ "kidFragment",
55
+ "purposes",
56
+ "algorithm"
57
+ ],
58
+ "definitions": {
59
+ "EcdsaSecp256k1VerificationKey2019": {
60
+ "type": "object",
61
+ "title": "EcdsaSecp256k1VerificationKey2019",
62
+ "description": "https://w3c.github.io/did-core-registries/#EcdsaSecp256k1VerificationKey2019",
63
+ "additionalProperties": false,
64
+ "properties": {
65
+ "id": {
66
+ "title": "Public Key ID",
67
+ "type": "string"
68
+ },
69
+ "type": {
70
+ "title": "Public Key Type",
71
+ "type": "string",
72
+ "enum": [
73
+ "EcdsaSecp256k1VerificationKey2019"
74
+ ]
75
+ },
76
+ "controller": {
77
+ "title": "Controller",
78
+ "description": "https://w3c.github.io/did-core-registries/#controller",
79
+ "type": "string"
80
+ },
81
+ "publicKeyMultibase": {
82
+ "title": "Public Key Base58",
83
+ "description": "https://w3c.github.io/did-core-registries/#publicKeyBase58",
84
+ "type": "string"
85
+ }
86
+ },
87
+ "required": [
88
+ "id",
89
+ "type",
90
+ "controller"
91
+ ]
92
+ },
93
+ "Ed25519VerificationKey2018": {
94
+ "type": "object",
95
+ "title": "EcdsaSecp256k1VerificationKey2019",
96
+ "description": "https://w3c.github.io/did-core-registries/#EcdsaSecp256k1VerificationKey2019",
97
+ "additionalProperties": false,
98
+ "properties": {
99
+ "id": {
100
+ "title": "Public Key ID",
101
+ "type": "string"
102
+ },
103
+ "type": {
104
+ "title": "Public Key Type",
105
+ "type": "string",
106
+ "enum": [
107
+ "Ed25519VerificationKey2018"
108
+ ]
109
+ },
110
+ "controller": {
111
+ "title": "Controller",
112
+ "description": "https://w3c.github.io/did-core-registries/#controller",
113
+ "type": "string"
114
+ },
115
+ "publicKeyMultibase": {
116
+ "title": "Public Key Base58",
117
+ "description": "https://w3c.github.io/did-core-registries/#publicKeyBase58",
118
+ "type": "string"
119
+ }
120
+ },
121
+ "required": [
122
+ "id",
123
+ "type",
124
+ "controller"
125
+ ]
126
+ },
127
+ "JsonWebKey2020": {
128
+ "type": "object",
129
+ "title": "JsonWebKey2020",
130
+ "description": "https://w3c.github.io/did-core-registries/#JwsVerificationKey2020",
131
+ "additionalProperties": false,
132
+ "properties": {
133
+ "id": {
134
+ "title": "Public Key ID",
135
+ "type": "string"
136
+ },
137
+ "type": {
138
+ "title": "Public Key Type",
139
+ "type": "string",
140
+ "enum": [
141
+ "JsonWebKey2020"
142
+ ]
143
+ },
144
+ "controller": {
145
+ "title": "Controller",
146
+ "description": "https://w3c.github.io/did-core-registries/#controller",
147
+ "type": "string"
148
+ },
149
+ "publicKeyJwk": {
150
+ "title": "Public Key JWK",
151
+ "description": "https://w3c.github.io/did-core-registries/#publicKeyJwk",
152
+ "type": "object",
153
+ "additionalProperties": true
154
+ }
155
+ },
156
+ "required": [
157
+ "id",
158
+ "type",
159
+ "controller"
160
+ ]
161
+ },
162
+ "PublicKey": {
163
+ "title": "Public Key",
164
+ "description": "A public key is a verification method. Public keys are used for digital signatures, encryption and other cryptographic operations, which in turn are the basis for purposes such as authentication.",
165
+ "oneOf": [
166
+ {
167
+ "$ref": "#/definitions/EcdsaSecp256k1VerificationKey2019"
168
+ },
169
+ {
170
+ "$ref": "#/definitions/Ed25519VerificationKey2018"
171
+ },
172
+ {
173
+ "$ref": "#/definitions/JsonWebKey2020"
174
+ }
175
+ ]
176
+ }
177
+ }
178
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "title": "full-organization",
3
+ "$id": "https://velocitycareerlabs.io/full-organization.json",
4
+ "description": "represents a full organization including didDoc if custodied",
5
+ "type": "object",
6
+ "properties": {
7
+ "id": {
8
+ "type": "string"
9
+ },
10
+ "didDoc": {
11
+ "$ref": "did-doc#"
12
+ },
13
+ "profile": {
14
+ "$ref": "organization-profile#"
15
+ },
16
+ "ids": {
17
+ "$ref": "https://velocitycareerlabs.io/organization-ids.json#"
18
+ },
19
+ "custodied": {
20
+ "type": "boolean"
21
+ },
22
+ "activatedServiceIds": {
23
+ "type": "array",
24
+ "items": {
25
+ "type": "string"
26
+ }
27
+ },
28
+ "services": {
29
+ "type": "array",
30
+ "items": {
31
+ "$ref": "https://velocitycareerlabs.io/organization-registry-service-response.schema.json#"
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,33 @@
1
+ const addKeyBodySchema = require('./add-key-body.schema.json');
2
+ const organizationIdsSchema = require('./organization-ids.schema.json');
3
+ const invitationCodePropertySchema = require('./invitationCodeProperty.schema.json');
4
+ const organizationRegistryServiceResponseSchema = require('./organization-registry-service-response.schema.json');
5
+ const fullOrganizationSchema = require('./full-organization.schema.json');
6
+ const createDidServiceSchema = require('./create-did-service.schema.json');
7
+ const organizationProfileCreationSchema = require('./organization-profile-creation.schema.json');
8
+ const organizationKybProfileCreationSchema = require('./organization-kyb-profile-creation.schema.json');
9
+ const organizationProfileUpdateSchema = require('./organization-profile-update.schema.json');
10
+ const organizationSearchQueryParamsSchema = require('./organization.search.query-params.schema.json');
11
+ const organizationSearchQueryProfileParamsSchema = require('./organization.search-profile.query-params.schema.json');
12
+ const organizationProfileVerifiableCredentialSchema = require('./organization-profile-verifiable-credential.schema.json');
13
+ const organizationVerifiedProfileSchema = require('./organization-verified-profile.schema.json');
14
+ const didKeySchema = require('./did-key.schema.json');
15
+ const organizationServiceSchema = require('./organization-service.schema.json');
16
+
17
+ module.exports = {
18
+ addKeyBodySchema,
19
+ invitationCodePropertySchema,
20
+ organizationIdsSchema,
21
+ organizationRegistryServiceResponseSchema,
22
+ fullOrganizationSchema,
23
+ createDidServiceSchema,
24
+ organizationProfileCreationSchema,
25
+ organizationKybProfileCreationSchema,
26
+ organizationProfileUpdateSchema,
27
+ organizationSearchQueryParamsSchema,
28
+ organizationSearchQueryProfileParamsSchema,
29
+ organizationProfileVerifiableCredentialSchema,
30
+ organizationVerifiedProfileSchema,
31
+ didKeySchema,
32
+ organizationServiceSchema,
33
+ };
@@ -0,0 +1,34 @@
1
+ {
2
+ "title": "organization-ids",
3
+ "$id": "https://velocitycareerlabs.io/organization-ids.json",
4
+ "type": "object",
5
+ "description": "represents the ids associated with an organization",
6
+ "properties": {
7
+ "tokenAccountId": {
8
+ "type": "string"
9
+ },
10
+ "stakesAccountId": {
11
+ "type": "string"
12
+ },
13
+ "fineractClientId": {
14
+ "type": "string"
15
+ },
16
+ "escrowAccountId": {
17
+ "type": "string"
18
+ },
19
+ "ethereumAccount": {
20
+ "type": "string"
21
+ },
22
+ "stripeConnectAccountId": {
23
+ "type": "string"
24
+ },
25
+ "did": {
26
+ "type": "string"
27
+ },
28
+ "brokerClientId": {
29
+ "type": "string"
30
+ }
31
+ },
32
+ "required": [
33
+ ]
34
+ }