@veridid/openbadges 0.0.0-stage → 1.0.0

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 (268) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +43 -2
  3. package/build/OpenBadgesModule.d.mts +15 -0
  4. package/build/OpenBadgesModule.d.mts.map +1 -0
  5. package/build/OpenBadgesModule.mjs +71 -0
  6. package/build/OpenBadgesModule.mjs.map +1 -0
  7. package/build/OpenBadgesModuleConfig.d.mts +101 -0
  8. package/build/OpenBadgesModuleConfig.d.mts.map +1 -0
  9. package/build/OpenBadgesModuleConfig.mjs +51 -0
  10. package/build/OpenBadgesModuleConfig.mjs.map +1 -0
  11. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs +14 -0
  12. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs +11 -0
  13. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs +13 -0
  14. package/build/_virtual/_rolldown/runtime.mjs +41 -0
  15. package/build/api/OpenBadgesApi.d.mts +77 -0
  16. package/build/api/OpenBadgesApi.d.mts.map +1 -0
  17. package/build/api/OpenBadgesApi.mjs +124 -0
  18. package/build/api/OpenBadgesApi.mjs.map +1 -0
  19. package/build/constants.d.mts +17 -0
  20. package/build/constants.d.mts.map +1 -0
  21. package/build/constants.mjs +19 -0
  22. package/build/constants.mjs.map +1 -0
  23. package/build/cryptosuites/EcdsaSd2023.d.mts +129 -0
  24. package/build/cryptosuites/EcdsaSd2023.d.mts.map +1 -0
  25. package/build/cryptosuites/EcdsaSd2023.mjs +408 -0
  26. package/build/cryptosuites/EcdsaSd2023.mjs.map +1 -0
  27. package/build/cryptosuites/EddsaRdfc2022.d.mts +118 -0
  28. package/build/cryptosuites/EddsaRdfc2022.d.mts.map +1 -0
  29. package/build/cryptosuites/EddsaRdfc2022.mjs +301 -0
  30. package/build/cryptosuites/EddsaRdfc2022.mjs.map +1 -0
  31. package/build/cryptosuites/constants.d.mts +18 -0
  32. package/build/cryptosuites/constants.d.mts.map +1 -0
  33. package/build/cryptosuites/constants.mjs +19 -0
  34. package/build/cryptosuites/constants.mjs.map +1 -0
  35. package/build/cryptosuites/contextPreprocessor.mjs +76 -0
  36. package/build/cryptosuites/contextPreprocessor.mjs.map +1 -0
  37. package/build/cryptosuites/dataIntegrityV2Context.d.mts +147 -0
  38. package/build/cryptosuites/dataIntegrityV2Context.d.mts.map +1 -0
  39. package/build/cryptosuites/dataIntegrityV2Context.mjs +82 -0
  40. package/build/cryptosuites/dataIntegrityV2Context.mjs.map +1 -0
  41. package/build/cryptosuites/index.mjs +4 -0
  42. package/build/formats/OpenBadgesCredentialFormat.d.mts +41 -0
  43. package/build/formats/OpenBadgesCredentialFormat.d.mts.map +1 -0
  44. package/build/formats/OpenBadgesCredentialFormat.mjs +7 -0
  45. package/build/formats/OpenBadgesCredentialFormat.mjs.map +1 -0
  46. package/build/formats/OpenBadgesCredentialFormatService.d.mts +79 -0
  47. package/build/formats/OpenBadgesCredentialFormatService.d.mts.map +1 -0
  48. package/build/formats/OpenBadgesCredentialFormatService.mjs +208 -0
  49. package/build/formats/OpenBadgesCredentialFormatService.mjs.map +1 -0
  50. package/build/formats/OpenBadgesProofFormat.d.mts +41 -0
  51. package/build/formats/OpenBadgesProofFormat.d.mts.map +1 -0
  52. package/build/formats/OpenBadgesProofFormat.mjs +7 -0
  53. package/build/formats/OpenBadgesProofFormat.mjs.map +1 -0
  54. package/build/formats/OpenBadgesProofFormatService.d.mts +56 -0
  55. package/build/formats/OpenBadgesProofFormatService.d.mts.map +1 -0
  56. package/build/formats/OpenBadgesProofFormatService.mjs +138 -0
  57. package/build/formats/OpenBadgesProofFormatService.mjs.map +1 -0
  58. package/build/formats/index.d.mts +4 -0
  59. package/build/formats/index.mjs +4 -0
  60. package/build/http/OpenBadgesHttpModule.d.mts +14 -0
  61. package/build/http/OpenBadgesHttpModule.d.mts.map +1 -0
  62. package/build/http/OpenBadgesHttpModule.mjs +85 -0
  63. package/build/http/OpenBadgesHttpModule.mjs.map +1 -0
  64. package/build/http/OpenBadgesHttpModuleConfig.d.mts +60 -0
  65. package/build/http/OpenBadgesHttpModuleConfig.d.mts.map +1 -0
  66. package/build/http/OpenBadgesHttpModuleConfig.mjs +80 -0
  67. package/build/http/OpenBadgesHttpModuleConfig.mjs.map +1 -0
  68. package/build/http/endpoints/authorize.mjs +69 -0
  69. package/build/http/endpoints/authorize.mjs.map +1 -0
  70. package/build/http/endpoints/consent.mjs +34 -0
  71. package/build/http/endpoints/consent.mjs.map +1 -0
  72. package/build/http/endpoints/credentials.mjs +77 -0
  73. package/build/http/endpoints/credentials.mjs.map +1 -0
  74. package/build/http/endpoints/did.mjs +44 -0
  75. package/build/http/endpoints/did.mjs.map +1 -0
  76. package/build/http/endpoints/introspect.mjs +34 -0
  77. package/build/http/endpoints/introspect.mjs.map +1 -0
  78. package/build/http/endpoints/jwks.mjs +40 -0
  79. package/build/http/endpoints/jwks.mjs.map +1 -0
  80. package/build/http/endpoints/profile.mjs +56 -0
  81. package/build/http/endpoints/profile.mjs.map +1 -0
  82. package/build/http/endpoints/refresh.mjs +99 -0
  83. package/build/http/endpoints/refresh.mjs.map +1 -0
  84. package/build/http/endpoints/registration.mjs +42 -0
  85. package/build/http/endpoints/registration.mjs.map +1 -0
  86. package/build/http/endpoints/revoke.mjs +31 -0
  87. package/build/http/endpoints/revoke.mjs.map +1 -0
  88. package/build/http/endpoints/serviceDescription.mjs +48 -0
  89. package/build/http/endpoints/serviceDescription.mjs.map +1 -0
  90. package/build/http/endpoints/statusList.mjs +91 -0
  91. package/build/http/endpoints/statusList.mjs.map +1 -0
  92. package/build/http/endpoints/token.mjs +123 -0
  93. package/build/http/endpoints/token.mjs.map +1 -0
  94. package/build/http/middleware/auth.mjs +38 -0
  95. package/build/http/middleware/auth.mjs.map +1 -0
  96. package/build/http/router.d.mts +19 -0
  97. package/build/http/router.d.mts.map +1 -0
  98. package/build/http/router.mjs +36 -0
  99. package/build/http/router.mjs.map +1 -0
  100. package/build/http/tenants.mjs +16 -0
  101. package/build/http/tenants.mjs.map +1 -0
  102. package/build/http/util/auth.mjs +38 -0
  103. package/build/http/util/auth.mjs.map +1 -0
  104. package/build/index.d.mts +57 -0
  105. package/build/index.mjs +68 -0
  106. package/build/index.mjs.map +1 -0
  107. package/build/models/ClrCredential.d.mts +116 -0
  108. package/build/models/ClrCredential.d.mts.map +1 -0
  109. package/build/models/ClrCredential.mjs +38 -0
  110. package/build/models/ClrCredential.mjs.map +1 -0
  111. package/build/models/EndorsementCredential.d.mts +93 -0
  112. package/build/models/EndorsementCredential.d.mts.map +1 -0
  113. package/build/models/StatusListCredential.d.mts +85 -0
  114. package/build/models/StatusListCredential.d.mts.map +1 -0
  115. package/build/models/StatusListCredential.mjs +29 -0
  116. package/build/models/StatusListCredential.mjs.map +1 -0
  117. package/build/models/index.mjs +2 -0
  118. package/build/repository/OpenBadgeCredentialRecord.d.mts +48 -0
  119. package/build/repository/OpenBadgeCredentialRecord.d.mts.map +1 -0
  120. package/build/repository/OpenBadgeCredentialRecord.mjs +44 -0
  121. package/build/repository/OpenBadgeCredentialRecord.mjs.map +1 -0
  122. package/build/repository/OpenBadgeCredentialRepository.d.mts +13 -0
  123. package/build/repository/OpenBadgeCredentialRepository.d.mts.map +1 -0
  124. package/build/repository/OpenBadgeCredentialRepository.mjs +34 -0
  125. package/build/repository/OpenBadgeCredentialRepository.mjs.map +1 -0
  126. package/build/repository/OpenBadgesAuthCodeRecord.d.mts +39 -0
  127. package/build/repository/OpenBadgesAuthCodeRecord.d.mts.map +1 -0
  128. package/build/repository/OpenBadgesAuthCodeRecord.mjs +40 -0
  129. package/build/repository/OpenBadgesAuthCodeRecord.mjs.map +1 -0
  130. package/build/repository/OpenBadgesAuthCodeRepository.d.mts +11 -0
  131. package/build/repository/OpenBadgesAuthCodeRepository.d.mts.map +1 -0
  132. package/build/repository/OpenBadgesAuthCodeRepository.mjs +29 -0
  133. package/build/repository/OpenBadgesAuthCodeRepository.mjs.map +1 -0
  134. package/build/repository/OpenBadgesConsentRecord.d.mts +28 -0
  135. package/build/repository/OpenBadgesConsentRecord.d.mts.map +1 -0
  136. package/build/repository/OpenBadgesConsentRecord.mjs +33 -0
  137. package/build/repository/OpenBadgesConsentRecord.mjs.map +1 -0
  138. package/build/repository/OpenBadgesConsentRepository.d.mts +11 -0
  139. package/build/repository/OpenBadgesConsentRepository.d.mts.map +1 -0
  140. package/build/repository/OpenBadgesConsentRepository.mjs +37 -0
  141. package/build/repository/OpenBadgesConsentRepository.mjs.map +1 -0
  142. package/build/repository/OpenBadgesKeyBindingRecord.d.mts +32 -0
  143. package/build/repository/OpenBadgesKeyBindingRecord.d.mts.map +1 -0
  144. package/build/repository/OpenBadgesKeyBindingRecord.mjs +37 -0
  145. package/build/repository/OpenBadgesKeyBindingRecord.mjs.map +1 -0
  146. package/build/repository/OpenBadgesKeyBindingRepository.d.mts +12 -0
  147. package/build/repository/OpenBadgesKeyBindingRepository.d.mts.map +1 -0
  148. package/build/repository/OpenBadgesKeyBindingRepository.mjs +31 -0
  149. package/build/repository/OpenBadgesKeyBindingRepository.mjs.map +1 -0
  150. package/build/repository/OpenBadgesOAuthRecord.d.mts +39 -0
  151. package/build/repository/OpenBadgesOAuthRecord.d.mts.map +1 -0
  152. package/build/repository/OpenBadgesOAuthRecord.mjs +37 -0
  153. package/build/repository/OpenBadgesOAuthRecord.mjs.map +1 -0
  154. package/build/repository/OpenBadgesOAuthRepository.d.mts +13 -0
  155. package/build/repository/OpenBadgesOAuthRepository.d.mts.map +1 -0
  156. package/build/repository/OpenBadgesOAuthRepository.mjs +35 -0
  157. package/build/repository/OpenBadgesOAuthRepository.mjs.map +1 -0
  158. package/build/repository/OpenBadgesProfileRecord.d.mts +25 -0
  159. package/build/repository/OpenBadgesProfileRecord.d.mts.map +1 -0
  160. package/build/repository/OpenBadgesProfileRecord.mjs +26 -0
  161. package/build/repository/OpenBadgesProfileRecord.mjs.map +1 -0
  162. package/build/repository/OpenBadgesProfileRepository.d.mts +11 -0
  163. package/build/repository/OpenBadgesProfileRepository.d.mts.map +1 -0
  164. package/build/repository/OpenBadgesProfileRepository.mjs +28 -0
  165. package/build/repository/OpenBadgesProfileRepository.mjs.map +1 -0
  166. package/build/repository/OpenBadgesRevocationCacheRecord.d.mts +27 -0
  167. package/build/repository/OpenBadgesRevocationCacheRecord.d.mts.map +1 -0
  168. package/build/repository/OpenBadgesRevocationCacheRecord.mjs +27 -0
  169. package/build/repository/OpenBadgesRevocationCacheRecord.mjs.map +1 -0
  170. package/build/repository/OpenBadgesRevocationCacheRepository.d.mts +11 -0
  171. package/build/repository/OpenBadgesRevocationCacheRepository.d.mts.map +1 -0
  172. package/build/repository/OpenBadgesRevocationCacheRepository.mjs +28 -0
  173. package/build/repository/OpenBadgesRevocationCacheRepository.mjs.map +1 -0
  174. package/build/repository/OpenBadgesServiceDescriptionRecord.d.mts +25 -0
  175. package/build/repository/OpenBadgesServiceDescriptionRecord.d.mts.map +1 -0
  176. package/build/repository/OpenBadgesServiceDescriptionRecord.mjs +26 -0
  177. package/build/repository/OpenBadgesServiceDescriptionRecord.mjs.map +1 -0
  178. package/build/repository/OpenBadgesServiceDescriptionRepository.d.mts +11 -0
  179. package/build/repository/OpenBadgesServiceDescriptionRepository.d.mts.map +1 -0
  180. package/build/repository/OpenBadgesServiceDescriptionRepository.mjs +28 -0
  181. package/build/repository/OpenBadgesServiceDescriptionRepository.mjs.map +1 -0
  182. package/build/repository/OpenBadgesTokenRecord.d.mts +43 -0
  183. package/build/repository/OpenBadgesTokenRecord.d.mts.map +1 -0
  184. package/build/repository/OpenBadgesTokenRecord.mjs +37 -0
  185. package/build/repository/OpenBadgesTokenRecord.mjs.map +1 -0
  186. package/build/repository/OpenBadgesTokenRepository.d.mts +14 -0
  187. package/build/repository/OpenBadgesTokenRepository.d.mts.map +1 -0
  188. package/build/repository/OpenBadgesTokenRepository.mjs +46 -0
  189. package/build/repository/OpenBadgesTokenRepository.mjs.map +1 -0
  190. package/build/repository/StatusListRecord.d.mts +40 -0
  191. package/build/repository/StatusListRecord.d.mts.map +1 -0
  192. package/build/repository/StatusListRecord.mjs +42 -0
  193. package/build/repository/StatusListRecord.mjs.map +1 -0
  194. package/build/repository/StatusListRepository.d.mts +23 -0
  195. package/build/repository/StatusListRepository.d.mts.map +1 -0
  196. package/build/repository/StatusListRepository.mjs +46 -0
  197. package/build/repository/StatusListRepository.mjs.map +1 -0
  198. package/build/services/AchievementValidator.d.mts +162 -0
  199. package/build/services/AchievementValidator.d.mts.map +1 -0
  200. package/build/services/AchievementValidator.mjs +173 -0
  201. package/build/services/AchievementValidator.mjs.map +1 -0
  202. package/build/services/ConsumerService.d.mts +29 -0
  203. package/build/services/ConsumerService.d.mts.map +1 -0
  204. package/build/services/ConsumerService.mjs +114 -0
  205. package/build/services/ConsumerService.mjs.map +1 -0
  206. package/build/services/ContextService.d.mts +17 -0
  207. package/build/services/ContextService.d.mts.map +1 -0
  208. package/build/services/ContextService.mjs +48 -0
  209. package/build/services/ContextService.mjs.map +1 -0
  210. package/build/services/DataIntegrityService.d.mts +58 -0
  211. package/build/services/DataIntegrityService.d.mts.map +1 -0
  212. package/build/services/DataIntegrityService.mjs +130 -0
  213. package/build/services/DataIntegrityService.mjs.map +1 -0
  214. package/build/services/DidCommLinkService.d.mts +12 -0
  215. package/build/services/DidCommLinkService.d.mts.map +1 -0
  216. package/build/services/DidCommLinkService.mjs +15 -0
  217. package/build/services/DidCommLinkService.mjs.map +1 -0
  218. package/build/services/DisplayMapper.d.mts +13 -0
  219. package/build/services/DisplayMapper.d.mts.map +1 -0
  220. package/build/services/DisplayMapper.mjs +23 -0
  221. package/build/services/DisplayMapper.mjs.map +1 -0
  222. package/build/services/IssuerService.d.mts +43 -0
  223. package/build/services/IssuerService.d.mts.map +1 -0
  224. package/build/services/IssuerService.mjs +230 -0
  225. package/build/services/IssuerService.mjs.map +1 -0
  226. package/build/services/JwtService.d.mts +22 -0
  227. package/build/services/JwtService.d.mts.map +1 -0
  228. package/build/services/JwtService.mjs +190 -0
  229. package/build/services/JwtService.mjs.map +1 -0
  230. package/build/services/KeyService.d.mts +122 -0
  231. package/build/services/KeyService.d.mts.map +1 -0
  232. package/build/services/KeyService.mjs +448 -0
  233. package/build/services/KeyService.mjs.map +1 -0
  234. package/build/services/OAuthClient.d.mts +31 -0
  235. package/build/services/OAuthClient.d.mts.map +1 -0
  236. package/build/services/OAuthClient.mjs +131 -0
  237. package/build/services/OAuthClient.mjs.map +1 -0
  238. package/build/services/ProofService.d.mts +20 -0
  239. package/build/services/ProofService.d.mts.map +1 -0
  240. package/build/services/ProofService.mjs +39 -0
  241. package/build/services/ProofService.mjs.map +1 -0
  242. package/build/services/RevocationService.d.mts +64 -0
  243. package/build/services/RevocationService.d.mts.map +1 -0
  244. package/build/services/RevocationService.mjs +253 -0
  245. package/build/services/RevocationService.mjs.map +1 -0
  246. package/build/services/VerifyService.d.mts +24 -0
  247. package/build/services/VerifyService.d.mts.map +1 -0
  248. package/build/services/VerifyService.mjs +59 -0
  249. package/build/services/VerifyService.mjs.map +1 -0
  250. package/build/services/crypto/CryptoDriver.d.mts +14 -0
  251. package/build/services/crypto/CryptoDriver.d.mts.map +1 -0
  252. package/build/services/crypto/CryptoDriver.mjs +6 -0
  253. package/build/services/crypto/CryptoDriver.mjs.map +1 -0
  254. package/build/services/crypto/JsonLdCryptoDriver.d.mts +22 -0
  255. package/build/services/crypto/JsonLdCryptoDriver.d.mts.map +1 -0
  256. package/build/services/crypto/JsonLdCryptoDriver.mjs +43 -0
  257. package/build/services/crypto/JsonLdCryptoDriver.mjs.map +1 -0
  258. package/build/services/crypto/JwtCryptoDriver.d.mts +18 -0
  259. package/build/services/crypto/JwtCryptoDriver.d.mts.map +1 -0
  260. package/build/services/crypto/JwtCryptoDriver.mjs +46 -0
  261. package/build/services/crypto/JwtCryptoDriver.mjs.map +1 -0
  262. package/build/services/index.d.mts +12 -0
  263. package/build/services/index.mjs +12 -0
  264. package/build/utils/validate.d.mts +21 -0
  265. package/build/utils/validate.d.mts.map +1 -0
  266. package/build/utils/validate.mjs +111 -0
  267. package/build/utils/validate.mjs.map +1 -0
  268. package/package.json +63 -3
@@ -0,0 +1,301 @@
1
+ import { CRYPTOSUITE_EDDSA_RDFC_2022, DATA_INTEGRITY_V2_CONTEXT_URL, PROOF_TYPE_DATA_INTEGRITY, VM_TYPE_ED25519_2020, VM_TYPE_MULTIKEY } from "./constants.mjs";
2
+ import { dataIntegrityV2Context } from "./dataIntegrityV2Context.mjs";
3
+ import { createPreprocessingDocumentLoader } from "./contextPreprocessor.mjs";
4
+ import { Hasher, TypedArrayEncoder } from "@credo-ts/core";
5
+ import * as ed25519 from "@stablelib/ed25519";
6
+ import bs58 from "bs58";
7
+ import * as jsonld from "@digitalcredentials/jsonld";
8
+
9
+ //#region src/cryptosuites/EddsaRdfc2022.ts
10
+ /**
11
+ * EdDSA RDFC 2022 Cryptosuite
12
+ *
13
+ * Implements the eddsa-rdfc-2022 cryptosuite for Data Integrity proofs.
14
+ * This is required for OpenBadges 3.0 certification.
15
+ *
16
+ * Spec: https://www.w3.org/TR/vc-di-eddsa/#eddsa-rdfc-2022
17
+ *
18
+ * Key features:
19
+ * - Uses Ed25519 signature algorithm
20
+ * - Uses RDFC-1.0 canonicalization (RDF Dataset Canonicalization)
21
+ * - Produces DataIntegrityProof with cryptosuite: 'eddsa-rdfc-2022'
22
+ */
23
+ const CONTEXT_CACHE = {
24
+ "https://w3id.org/security/data-integrity/v2": dataIntegrityV2Context,
25
+ "https://www.w3.org/ns/credentials/v2": { "@context": {
26
+ id: "@id",
27
+ type: "@type",
28
+ VerifiableCredential: "https://www.w3.org/2018/credentials#VerifiableCredential",
29
+ credentialSubject: {
30
+ "@id": "https://www.w3.org/2018/credentials#credentialSubject",
31
+ "@type": "@id"
32
+ },
33
+ issuer: {
34
+ "@id": "https://www.w3.org/2018/credentials#issuer",
35
+ "@type": "@id"
36
+ },
37
+ validFrom: {
38
+ "@id": "https://www.w3.org/2018/credentials#validFrom",
39
+ "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
40
+ },
41
+ validUntil: {
42
+ "@id": "https://www.w3.org/2018/credentials#validUntil",
43
+ "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
44
+ }
45
+ } },
46
+ "https://purl.imsglobal.org/spec/ob/v3p0/context-3.0.3.json": { "@context": {
47
+ OpenBadgeCredential: "https://purl.imsglobal.org/spec/vc/ob/vocab.html#OpenBadgeCredential",
48
+ Achievement: "https://purl.imsglobal.org/spec/vc/ob/vocab.html#Achievement",
49
+ AchievementSubject: "https://purl.imsglobal.org/spec/vc/ob/vocab.html#AchievementSubject",
50
+ Profile: "https://purl.imsglobal.org/spec/vc/ob/vocab.html#Profile",
51
+ achievement: {
52
+ "@id": "https://purl.imsglobal.org/spec/vc/ob/vocab.html#achievement",
53
+ "@type": "@id"
54
+ },
55
+ name: "https://schema.org/name",
56
+ description: "https://schema.org/description",
57
+ criteria: {
58
+ "@id": "https://purl.imsglobal.org/spec/vc/ob/vocab.html#criteria",
59
+ "@type": "@id"
60
+ },
61
+ narrative: "https://purl.imsglobal.org/spec/vc/ob/vocab.html#narrative"
62
+ } },
63
+ "https://purl.imsglobal.org/spec/ob/v3p0/extensions.json": { "@context": {
64
+ "1EdTechJsonSchemaValidator2019": "https://purl.imsglobal.org/spec/vccs/v1p0/context.json#1EdTechJsonSchemaValidator2019",
65
+ "1EdTechRevocationList": "https://purl.imsglobal.org/spec/vcrl/v1p0/context.json#1EdTechRevocationList",
66
+ "1EdTechCredentialRefresh": "https://purl.imsglobal.org/spec/vccr/v1p0/context.json#1EdTechCredentialRefresh"
67
+ } }
68
+ };
69
+ const RUNTIME_CONTEXT_CACHE = {};
70
+ const ED25519_PUB_MULTICODEC = new Uint8Array([237, 1]);
71
+ const ED25519_PRIV_MULTICODEC = new Uint8Array([128, 38]);
72
+ /**
73
+ * EdDSA RDFC 2022 Cryptosuite implementation
74
+ */
75
+ var EddsaRdfc2022Cryptosuite = class {
76
+ /**
77
+ * Sign a document using eddsa-rdfc-2022 cryptosuite
78
+ */
79
+ async sign(options) {
80
+ const { document, keyPair, purpose = "assertionMethod", date, challenge, domain } = options;
81
+ const { secretKey } = this.decodeKeyPair(keyPair);
82
+ const proofOptions = {
83
+ type: PROOF_TYPE_DATA_INTEGRITY,
84
+ created: date ? new Date(date).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
85
+ verificationMethod: keyPair.id,
86
+ cryptosuite: CRYPTOSUITE_EDDSA_RDFC_2022,
87
+ proofPurpose: purpose
88
+ };
89
+ if (challenge) proofOptions.challenge = challenge;
90
+ if (domain) proofOptions.domain = domain;
91
+ const documentCopy = { ...document };
92
+ delete documentCopy.proof;
93
+ const hashData = await this.createHashData(documentCopy, proofOptions);
94
+ const signature = ed25519.sign(secretKey, hashData);
95
+ const proofValue = "z" + bs58.encode(signature);
96
+ const proof = {
97
+ ...proofOptions,
98
+ proofValue
99
+ };
100
+ return {
101
+ ...document,
102
+ proof: [proof]
103
+ };
104
+ }
105
+ /**
106
+ * Sign a document using an external signer function (e.g., wallet.sign)
107
+ * This allows integration with KMS-backed keys where private key material is not directly accessible
108
+ */
109
+ async signWithSigner(options) {
110
+ const { document, verificationMethodId, signer, purpose = "assertionMethod", date, challenge, domain, useNetworkContexts = true } = options;
111
+ const proofOptions = {
112
+ type: PROOF_TYPE_DATA_INTEGRITY,
113
+ created: date ? new Date(date).toISOString() : (/* @__PURE__ */ new Date()).toISOString(),
114
+ verificationMethod: verificationMethodId,
115
+ cryptosuite: CRYPTOSUITE_EDDSA_RDFC_2022,
116
+ proofPurpose: purpose
117
+ };
118
+ if (challenge) proofOptions.challenge = challenge;
119
+ if (domain) proofOptions.domain = domain;
120
+ const documentCopy = { ...document };
121
+ delete documentCopy.proof;
122
+ const signature = await signer(await this.createHashData(documentCopy, proofOptions, useNetworkContexts));
123
+ const proofValue = "z" + bs58.encode(signature);
124
+ const proof = {
125
+ ...proofOptions,
126
+ proofValue
127
+ };
128
+ return {
129
+ ...document,
130
+ proof: [proof]
131
+ };
132
+ }
133
+ /**
134
+ * Verify a document with eddsa-rdfc-2022 proof
135
+ *
136
+ * @param options - Verification options including document, proof, public key, and context settings
137
+ */
138
+ async verify(options) {
139
+ const { document, proof, publicKeyMultibase, useNetworkContexts = false } = options;
140
+ try {
141
+ if (proof.type !== PROOF_TYPE_DATA_INTEGRITY) return {
142
+ verified: false,
143
+ error: `Invalid proof type: ${proof.type}`
144
+ };
145
+ if (proof.cryptosuite !== CRYPTOSUITE_EDDSA_RDFC_2022) return {
146
+ verified: false,
147
+ error: `Invalid cryptosuite: ${proof.cryptosuite}`
148
+ };
149
+ if (!proof.proofValue?.startsWith("z")) return {
150
+ verified: false,
151
+ error: "Invalid proofValue: must be multibase base58btc encoded"
152
+ };
153
+ const publicKey = this.decodePublicKey(publicKeyMultibase);
154
+ const signature = bs58.decode(proof.proofValue.slice(1));
155
+ const documentCopy = { ...document };
156
+ delete documentCopy.proof;
157
+ const proofOptions = {
158
+ type: proof.type,
159
+ cryptosuite: proof.cryptosuite,
160
+ created: proof.created,
161
+ verificationMethod: proof.verificationMethod,
162
+ proofPurpose: proof.proofPurpose
163
+ };
164
+ const hashData = await this.createHashData(documentCopy, proofOptions, useNetworkContexts);
165
+ return { verified: ed25519.verify(publicKey, hashData, signature) };
166
+ } catch (error) {
167
+ return {
168
+ verified: false,
169
+ error: error.message
170
+ };
171
+ }
172
+ }
173
+ /**
174
+ * Check if this suite matches a given proof
175
+ */
176
+ matchProof(proof) {
177
+ return proof.type === PROOF_TYPE_DATA_INTEGRITY && proof.cryptosuite === CRYPTOSUITE_EDDSA_RDFC_2022;
178
+ }
179
+ /**
180
+ * Create a document loader for JSON-LD operations
181
+ * Uses cached contexts for internal operations, preprocessed network contexts for external verification
182
+ */
183
+ createDocumentLoader(useNetworkContexts = false) {
184
+ if (useNetworkContexts) return createPreprocessingDocumentLoader();
185
+ return async (url) => {
186
+ if (CONTEXT_CACHE[url]) return {
187
+ contextUrl: null,
188
+ document: CONTEXT_CACHE[url],
189
+ documentUrl: url
190
+ };
191
+ if (RUNTIME_CONTEXT_CACHE[url]) return {
192
+ contextUrl: null,
193
+ document: RUNTIME_CONTEXT_CACHE[url],
194
+ documentUrl: url
195
+ };
196
+ return {
197
+ contextUrl: null,
198
+ document: { "@context": {} },
199
+ documentUrl: url
200
+ };
201
+ };
202
+ }
203
+ /**
204
+ * Canonicalize a document using RDFC-1.0 (URDNA2015)
205
+ * This is the standard algorithm for RDF Dataset Canonicalization.
206
+ *
207
+ * @param document - The document to canonicalize
208
+ * @param useNetworkContexts - If true, fetch contexts from network with @protected stripped
209
+ */
210
+ async canonicalize(document, useNetworkContexts = false) {
211
+ const jld = jsonld.default ?? jsonld;
212
+ const documentLoader = this.createDocumentLoader(useNetworkContexts);
213
+ return await jld.canonize(document, {
214
+ algorithm: "URDNA2015",
215
+ format: "application/n-quads",
216
+ documentLoader
217
+ });
218
+ }
219
+ /**
220
+ * Create hash data for signing/verification using RDFC-1.0 algorithm
221
+ *
222
+ * Per the spec (https://www.w3.org/TR/vc-di-eddsa/#create-verify-data-eddsa-rdfc-2022):
223
+ * 1. Canonicalize the document using RDFC-1.0
224
+ * 2. Hash the canonical document using SHA-256
225
+ * 3. Canonicalize the proof options (without proofValue)
226
+ * 4. Hash the canonical proof options using SHA-256
227
+ * 5. Concatenate: proofOptionsHash || documentHash
228
+ *
229
+ * @param document - The document to hash
230
+ * @param proofOptions - The proof options to hash
231
+ * @param useNetworkContexts - If true, fetch contexts from network with @protected stripped
232
+ */
233
+ async createHashData(document, proofOptions, useNetworkContexts = false) {
234
+ const canonicalDocument = await this.canonicalize(document, useNetworkContexts);
235
+ const documentHash = Hasher.hash(TypedArrayEncoder.fromUtf8String(canonicalDocument), "sha-256");
236
+ const proofConfigDocument = {
237
+ "@context": DATA_INTEGRITY_V2_CONTEXT_URL,
238
+ ...proofOptions
239
+ };
240
+ const canonicalProofConfig = await this.canonicalize(proofConfigDocument, useNetworkContexts);
241
+ const proofConfigHash = Hasher.hash(TypedArrayEncoder.fromUtf8String(canonicalProofConfig), "sha-256");
242
+ const combined = new Uint8Array(proofConfigHash.length + documentHash.length);
243
+ combined.set(proofConfigHash, 0);
244
+ combined.set(documentHash, proofConfigHash.length);
245
+ return combined;
246
+ }
247
+ /**
248
+ * Decode a key pair from multibase format
249
+ */
250
+ decodeKeyPair(keyPair) {
251
+ if (!keyPair.privateKeyMultibase) throw new Error("Private key is required for signing");
252
+ const privBytes = bs58.decode(keyPair.privateKeyMultibase.slice(1));
253
+ if (privBytes[0] !== ED25519_PRIV_MULTICODEC[0] || privBytes[1] !== ED25519_PRIV_MULTICODEC[1]) throw new Error("Invalid private key multicodec prefix");
254
+ const secretKey = privBytes.slice(2);
255
+ let publicKey;
256
+ if (keyPair.publicKeyMultibase) publicKey = this.decodePublicKey(keyPair.publicKeyMultibase);
257
+ else if (secretKey.length === 64) publicKey = secretKey.slice(32);
258
+ else publicKey = ed25519.generateKeyPairFromSeed(secretKey.slice(0, 32)).publicKey;
259
+ return {
260
+ publicKey,
261
+ secretKey
262
+ };
263
+ }
264
+ /**
265
+ * Decode a public key from multibase format
266
+ */
267
+ decodePublicKey(publicKeyMultibase) {
268
+ if (!publicKeyMultibase.startsWith("z")) throw new Error("Invalid multibase prefix: expected base58btc (z)");
269
+ const pubBytes = bs58.decode(publicKeyMultibase.slice(1));
270
+ if (pubBytes[0] !== ED25519_PUB_MULTICODEC[0] || pubBytes[1] !== ED25519_PUB_MULTICODEC[1]) throw new Error("Invalid public key multicodec prefix");
271
+ return pubBytes.slice(2);
272
+ }
273
+ /**
274
+ * Generate a new Ed25519 key pair with multibase encoding
275
+ */
276
+ static generateKeyPair(controller, keyId) {
277
+ const kp = ed25519.generateKeyPair();
278
+ const pubWithHeader = new Uint8Array(2 + kp.publicKey.length);
279
+ pubWithHeader.set(ED25519_PUB_MULTICODEC, 0);
280
+ pubWithHeader.set(kp.publicKey, 2);
281
+ const publicKeyMultibase = "z" + bs58.encode(pubWithHeader);
282
+ const privWithHeader = new Uint8Array(2 + kp.secretKey.length);
283
+ privWithHeader.set(ED25519_PRIV_MULTICODEC, 0);
284
+ privWithHeader.set(kp.secretKey, 2);
285
+ const privateKeyMultibase = "z" + bs58.encode(privWithHeader);
286
+ return {
287
+ id: keyId || `${controller}#key-1`,
288
+ controller,
289
+ publicKeyMultibase,
290
+ privateKeyMultibase
291
+ };
292
+ }
293
+ };
294
+ EddsaRdfc2022Cryptosuite.proofType = PROOF_TYPE_DATA_INTEGRITY;
295
+ EddsaRdfc2022Cryptosuite.cryptosuite = CRYPTOSUITE_EDDSA_RDFC_2022;
296
+ EddsaRdfc2022Cryptosuite.contextUrl = DATA_INTEGRITY_V2_CONTEXT_URL;
297
+ EddsaRdfc2022Cryptosuite.verificationMethodTypes = [VM_TYPE_MULTIKEY, VM_TYPE_ED25519_2020];
298
+
299
+ //#endregion
300
+ export { EddsaRdfc2022Cryptosuite };
301
+ //# sourceMappingURL=EddsaRdfc2022.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EddsaRdfc2022.mjs","names":[],"sources":["../../src/cryptosuites/EddsaRdfc2022.ts"],"sourcesContent":["/**\n * EdDSA RDFC 2022 Cryptosuite\n *\n * Implements the eddsa-rdfc-2022 cryptosuite for Data Integrity proofs.\n * This is required for OpenBadges 3.0 certification.\n *\n * Spec: https://www.w3.org/TR/vc-di-eddsa/#eddsa-rdfc-2022\n *\n * Key features:\n * - Uses Ed25519 signature algorithm\n * - Uses RDFC-1.0 canonicalization (RDF Dataset Canonicalization)\n * - Produces DataIntegrityProof with cryptosuite: 'eddsa-rdfc-2022'\n */\n\nimport * as ed25519 from '@stablelib/ed25519'\nimport bs58 from 'bs58'\nimport { Hasher, TypedArrayEncoder } from '@credo-ts/core'\n\n// Import jsonld for canonicalization\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport * as jsonld from '@digitalcredentials/jsonld'\n\nimport {\n CRYPTOSUITE_EDDSA_RDFC_2022,\n DATA_INTEGRITY_V2_CONTEXT_URL,\n PROOF_TYPE_DATA_INTEGRITY,\n VM_TYPE_MULTIKEY,\n VM_TYPE_ED25519_2020,\n} from './constants'\n\n// Document loader for JSON-LD contexts\nimport { dataIntegrityV2Context } from './dataIntegrityV2Context'\nimport { createPreprocessingDocumentLoader } from './contextPreprocessor'\n\n// Built-in context cache for internal tests and offline operation\n// These simplified contexts work for internal sign/verify round-trips\n// Note: proof/security terms are handled by Data Integrity context to avoid conflicts\nconst CONTEXT_CACHE: Record<string, object> = {\n 'https://w3id.org/security/data-integrity/v2': dataIntegrityV2Context,\n 'https://www.w3.org/ns/credentials/v2': {\n '@context': {\n id: '@id',\n type: '@type',\n VerifiableCredential: 'https://www.w3.org/2018/credentials#VerifiableCredential',\n credentialSubject: { '@id': 'https://www.w3.org/2018/credentials#credentialSubject', '@type': '@id' },\n issuer: { '@id': 'https://www.w3.org/2018/credentials#issuer', '@type': '@id' },\n validFrom: { '@id': 'https://www.w3.org/2018/credentials#validFrom', '@type': 'http://www.w3.org/2001/XMLSchema#dateTime' },\n validUntil: { '@id': 'https://www.w3.org/2018/credentials#validUntil', '@type': 'http://www.w3.org/2001/XMLSchema#dateTime' },\n },\n },\n 'https://purl.imsglobal.org/spec/ob/v3p0/context-3.0.3.json': {\n '@context': {\n OpenBadgeCredential: 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#OpenBadgeCredential',\n Achievement: 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#Achievement',\n AchievementSubject: 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#AchievementSubject',\n Profile: 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#Profile',\n achievement: { '@id': 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#achievement', '@type': '@id' },\n name: 'https://schema.org/name',\n description: 'https://schema.org/description',\n criteria: { '@id': 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#criteria', '@type': '@id' },\n narrative: 'https://purl.imsglobal.org/spec/vc/ob/vocab.html#narrative',\n },\n },\n // Extensions context for Credly credentials\n 'https://purl.imsglobal.org/spec/ob/v3p0/extensions.json': {\n '@context': {\n '1EdTechJsonSchemaValidator2019': 'https://purl.imsglobal.org/spec/vccs/v1p0/context.json#1EdTechJsonSchemaValidator2019',\n '1EdTechRevocationList': 'https://purl.imsglobal.org/spec/vcrl/v1p0/context.json#1EdTechRevocationList',\n '1EdTechCredentialRefresh': 'https://purl.imsglobal.org/spec/vccr/v1p0/context.json#1EdTechCredentialRefresh',\n },\n },\n}\n\n// Runtime cache for network-fetched contexts\nconst RUNTIME_CONTEXT_CACHE: Record<string, object> = {}\n\n// Multicodec prefixes\nconst ED25519_PUB_MULTICODEC = new Uint8Array([0xed, 0x01])\nconst ED25519_PRIV_MULTICODEC = new Uint8Array([0x80, 0x26])\n\nexport interface EddsaRdfc2022KeyPair {\n id: string\n controller: string\n publicKeyMultibase: string\n privateKeyMultibase?: string\n}\n\nexport interface EddsaRdfc2022Proof {\n type: typeof PROOF_TYPE_DATA_INTEGRITY\n cryptosuite: typeof CRYPTOSUITE_EDDSA_RDFC_2022\n created: string\n verificationMethod: string\n proofPurpose: string\n proofValue: string\n}\n\nexport interface SignOptions {\n document: Record<string, unknown>\n keyPair: EddsaRdfc2022KeyPair\n purpose?: string\n date?: Date | string\n challenge?: string\n domain?: string\n}\n\nexport interface VerifyOptions {\n document: Record<string, unknown>\n proof: EddsaRdfc2022Proof\n publicKeyMultibase: string\n /**\n * If true, fetch contexts from the network with @protected stripped.\n * This is needed for verifying external credentials that use full network contexts.\n */\n useNetworkContexts?: boolean\n}\n\n/**\n * EdDSA RDFC 2022 Cryptosuite implementation\n */\nexport class EddsaRdfc2022Cryptosuite {\n public static readonly proofType = PROOF_TYPE_DATA_INTEGRITY\n public static readonly cryptosuite = CRYPTOSUITE_EDDSA_RDFC_2022\n public static readonly contextUrl = DATA_INTEGRITY_V2_CONTEXT_URL\n public static readonly verificationMethodTypes = [VM_TYPE_MULTIKEY, VM_TYPE_ED25519_2020]\n\n /**\n * Sign a document using eddsa-rdfc-2022 cryptosuite\n */\n public async sign(options: SignOptions): Promise<Record<string, unknown>> {\n const { document, keyPair, purpose = 'assertionMethod', date, challenge, domain } = options\n\n // Decode private key\n const { secretKey } = this.decodeKeyPair(keyPair)\n\n // Create proof options (Credly-compatible order)\n const proofOptions: Partial<EddsaRdfc2022Proof> = {\n type: PROOF_TYPE_DATA_INTEGRITY,\n created: date ? new Date(date).toISOString() : new Date().toISOString(),\n verificationMethod: keyPair.id,\n cryptosuite: CRYPTOSUITE_EDDSA_RDFC_2022,\n proofPurpose: purpose,\n }\n\n if (challenge) {\n ;(proofOptions as Record<string, unknown>).challenge = challenge\n }\n if (domain) {\n ;(proofOptions as Record<string, unknown>).domain = domain\n }\n\n // Create hash to sign\n // Note: Full implementation should use RDFC-1.0 canonicalization\n // For now, we use a simplified canonicalization for compatibility\n const documentCopy = { ...document }\n delete (documentCopy as Record<string, unknown>).proof\n\n const hashData = await this.createHashData(documentCopy, proofOptions)\n\n // Sign the hash\n const signature = ed25519.sign(secretKey, hashData)\n\n // Encode signature as multibase base58btc\n const proofValue = 'z' + bs58.encode(signature)\n\n // Create final proof\n const proof: EddsaRdfc2022Proof = {\n ...proofOptions,\n proofValue,\n } as EddsaRdfc2022Proof\n\n // Return document with proof as array (Credly-compatible)\n return {\n ...document,\n proof: [proof],\n }\n }\n\n /**\n * Sign a document using an external signer function (e.g., wallet.sign)\n * This allows integration with KMS-backed keys where private key material is not directly accessible\n */\n public async signWithSigner(options: {\n document: Record<string, unknown>\n verificationMethodId: string\n signer: (data: Uint8Array) => Promise<Uint8Array>\n purpose?: string\n date?: Date | string\n challenge?: string\n domain?: string\n useNetworkContexts?: boolean\n }): Promise<Record<string, unknown>> {\n const { document, verificationMethodId, signer, purpose = 'assertionMethod', date, challenge, domain, useNetworkContexts = true } = options\n\n // Create proof options (Credly-compatible order)\n const proofOptions: Partial<EddsaRdfc2022Proof> = {\n type: PROOF_TYPE_DATA_INTEGRITY,\n created: date ? new Date(date).toISOString() : new Date().toISOString(),\n verificationMethod: verificationMethodId,\n cryptosuite: CRYPTOSUITE_EDDSA_RDFC_2022,\n proofPurpose: purpose,\n }\n\n if (challenge) {\n ;(proofOptions as Record<string, unknown>).challenge = challenge\n }\n if (domain) {\n ;(proofOptions as Record<string, unknown>).domain = domain\n }\n\n // Create hash to sign\n const documentCopy = { ...document }\n delete (documentCopy as Record<string, unknown>).proof\n\n const hashData = await this.createHashData(documentCopy, proofOptions, useNetworkContexts)\n\n // Sign using the external signer\n const signature = await signer(hashData)\n\n // Encode signature as multibase base58btc\n const proofValue = 'z' + bs58.encode(signature)\n\n // Create final proof\n const proof: EddsaRdfc2022Proof = {\n ...proofOptions,\n proofValue,\n } as EddsaRdfc2022Proof\n\n // Return document with proof as array (Credly-compatible)\n return {\n ...document,\n proof: [proof],\n }\n }\n\n /**\n * Verify a document with eddsa-rdfc-2022 proof\n *\n * @param options - Verification options including document, proof, public key, and context settings\n */\n public async verify(options: VerifyOptions): Promise<{ verified: boolean; error?: string }> {\n const { document, proof, publicKeyMultibase, useNetworkContexts = false } = options\n\n try {\n // Validate proof structure\n if (proof.type !== PROOF_TYPE_DATA_INTEGRITY) {\n return { verified: false, error: `Invalid proof type: ${proof.type}` }\n }\n if (proof.cryptosuite !== CRYPTOSUITE_EDDSA_RDFC_2022) {\n return { verified: false, error: `Invalid cryptosuite: ${proof.cryptosuite}` }\n }\n if (!proof.proofValue?.startsWith('z')) {\n return { verified: false, error: 'Invalid proofValue: must be multibase base58btc encoded' }\n }\n\n // Decode public key\n const publicKey = this.decodePublicKey(publicKeyMultibase)\n\n // Decode signature\n const signature = bs58.decode(proof.proofValue.slice(1))\n\n // Recreate hash data\n const documentCopy = { ...document }\n delete (documentCopy as Record<string, unknown>).proof\n\n const proofOptions = {\n type: proof.type,\n cryptosuite: proof.cryptosuite,\n created: proof.created,\n verificationMethod: proof.verificationMethod,\n proofPurpose: proof.proofPurpose,\n }\n\n // Use network contexts if specified (for external credential verification)\n const hashData = await this.createHashData(documentCopy, proofOptions, useNetworkContexts)\n\n // Verify signature\n const verified = ed25519.verify(publicKey, hashData, signature)\n\n return { verified }\n } catch (error) {\n const err = error as Error\n return { verified: false, error: err.message }\n }\n }\n\n /**\n * Check if this suite matches a given proof\n */\n public matchProof(proof: Record<string, unknown>): boolean {\n return (\n proof.type === PROOF_TYPE_DATA_INTEGRITY && proof.cryptosuite === CRYPTOSUITE_EDDSA_RDFC_2022\n )\n }\n\n /**\n * Create a document loader for JSON-LD operations\n * Uses cached contexts for internal operations, preprocessed network contexts for external verification\n */\n private createDocumentLoader(useNetworkContexts = false) {\n // For external credential verification, use preprocessing loader that strips @protected\n if (useNetworkContexts) {\n return createPreprocessingDocumentLoader()\n }\n\n // For internal operations, use cached contexts for stability\n return async (url: string) => {\n // Check static cache first\n if (CONTEXT_CACHE[url]) {\n return {\n contextUrl: null,\n document: CONTEXT_CACHE[url],\n documentUrl: url,\n }\n }\n\n // Check runtime cache\n if (RUNTIME_CONTEXT_CACHE[url]) {\n return {\n contextUrl: null,\n document: RUNTIME_CONTEXT_CACHE[url],\n documentUrl: url,\n }\n }\n\n // For unknown contexts, return minimal context\n return {\n contextUrl: null,\n document: { '@context': {} },\n documentUrl: url,\n }\n }\n }\n\n /**\n * Canonicalize a document using RDFC-1.0 (URDNA2015)\n * This is the standard algorithm for RDF Dataset Canonicalization.\n *\n * @param document - The document to canonicalize\n * @param useNetworkContexts - If true, fetch contexts from network with @protected stripped\n */\n private async canonicalize(\n document: Record<string, unknown>,\n useNetworkContexts = false\n ): Promise<string> {\n const jld = jsonld.default ?? jsonld\n const documentLoader = this.createDocumentLoader(useNetworkContexts)\n\n // Use URDNA2015 algorithm (RDFC-1.0)\n const canonicalized = await jld.canonize(document, {\n algorithm: 'URDNA2015',\n format: 'application/n-quads',\n documentLoader,\n })\n return canonicalized\n }\n\n /**\n * Create hash data for signing/verification using RDFC-1.0 algorithm\n *\n * Per the spec (https://www.w3.org/TR/vc-di-eddsa/#create-verify-data-eddsa-rdfc-2022):\n * 1. Canonicalize the document using RDFC-1.0\n * 2. Hash the canonical document using SHA-256\n * 3. Canonicalize the proof options (without proofValue)\n * 4. Hash the canonical proof options using SHA-256\n * 5. Concatenate: proofOptionsHash || documentHash\n *\n * @param document - The document to hash\n * @param proofOptions - The proof options to hash\n * @param useNetworkContexts - If true, fetch contexts from network with @protected stripped\n */\n private async createHashData(\n document: Record<string, unknown>,\n proofOptions: Record<string, unknown>,\n useNetworkContexts = false\n ): Promise<Uint8Array> {\n // Canonicalize the document\n const canonicalDocument = await this.canonicalize(document, useNetworkContexts)\n\n // Hash the canonical document with SHA-256 (using cross-platform Hasher)\n const documentHash = Hasher.hash(TypedArrayEncoder.fromUtf8String(canonicalDocument), 'sha-256')\n\n // Create proof configuration document for canonicalization\n // Use the Data Integrity context for proof options (per spec section 3.3.1)\n const proofConfigDocument = {\n '@context': DATA_INTEGRITY_V2_CONTEXT_URL,\n ...proofOptions,\n }\n\n // Canonicalize the proof configuration\n const canonicalProofConfig = await this.canonicalize(proofConfigDocument, useNetworkContexts)\n\n // Hash the canonical proof configuration with SHA-256 (using cross-platform Hasher)\n const proofConfigHash = Hasher.hash(TypedArrayEncoder.fromUtf8String(canonicalProofConfig), 'sha-256')\n\n // Concatenate: proofConfigHash || documentHash (per spec)\n const combined = new Uint8Array(proofConfigHash.length + documentHash.length)\n combined.set(proofConfigHash, 0)\n combined.set(documentHash, proofConfigHash.length)\n\n return combined\n }\n\n /**\n * Decode a key pair from multibase format\n */\n private decodeKeyPair(keyPair: EddsaRdfc2022KeyPair): {\n publicKey: Uint8Array\n secretKey: Uint8Array\n } {\n if (!keyPair.privateKeyMultibase) {\n throw new Error('Private key is required for signing')\n }\n\n // Decode private key\n const privBytes = bs58.decode(keyPair.privateKeyMultibase.slice(1))\n\n // Validate multicodec prefix\n if (privBytes[0] !== ED25519_PRIV_MULTICODEC[0] || privBytes[1] !== ED25519_PRIV_MULTICODEC[1]) {\n throw new Error('Invalid private key multicodec prefix')\n }\n\n const secretKey = privBytes.slice(2)\n\n // Decode or derive public key\n let publicKey: Uint8Array\n if (keyPair.publicKeyMultibase) {\n publicKey = this.decodePublicKey(keyPair.publicKeyMultibase)\n } else {\n // Derive public key from secret key (last 32 bytes or generate)\n if (secretKey.length === 64) {\n publicKey = secretKey.slice(32)\n } else {\n const kp = ed25519.generateKeyPairFromSeed(secretKey.slice(0, 32))\n publicKey = kp.publicKey\n }\n }\n\n return { publicKey, secretKey }\n }\n\n /**\n * Decode a public key from multibase format\n */\n private decodePublicKey(publicKeyMultibase: string): Uint8Array {\n if (!publicKeyMultibase.startsWith('z')) {\n throw new Error('Invalid multibase prefix: expected base58btc (z)')\n }\n\n const pubBytes = bs58.decode(publicKeyMultibase.slice(1))\n\n // Validate multicodec prefix\n if (pubBytes[0] !== ED25519_PUB_MULTICODEC[0] || pubBytes[1] !== ED25519_PUB_MULTICODEC[1]) {\n throw new Error('Invalid public key multicodec prefix')\n }\n\n return pubBytes.slice(2)\n }\n\n /**\n * Generate a new Ed25519 key pair with multibase encoding\n */\n public static generateKeyPair(controller: string, keyId?: string): EddsaRdfc2022KeyPair {\n const kp = ed25519.generateKeyPair()\n\n // Encode public key with multicodec prefix\n const pubWithHeader = new Uint8Array(2 + kp.publicKey.length)\n pubWithHeader.set(ED25519_PUB_MULTICODEC, 0)\n pubWithHeader.set(kp.publicKey, 2)\n const publicKeyMultibase = 'z' + bs58.encode(pubWithHeader)\n\n // Encode private key with multicodec prefix\n const privWithHeader = new Uint8Array(2 + kp.secretKey.length)\n privWithHeader.set(ED25519_PRIV_MULTICODEC, 0)\n privWithHeader.set(kp.secretKey, 2)\n const privateKeyMultibase = 'z' + bs58.encode(privWithHeader)\n\n const id = keyId || `${controller}#key-1`\n\n return {\n id,\n controller,\n publicKeyMultibase,\n privateKeyMultibase,\n }\n }\n}\n"],"mappings":";;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AAwB,EAAE;AAC5C,gBAAc,IAAI,GAAG,WAAW,EAAE;EAClC,MAAM,qBAAqB,MAAM,KAAK,OAAO,cAAc;EAG3D,MAAM,iBAAiB,IAAI,WAAW,IAAI,GAAG,UAAU,OAAO;AAC9D,iBAAe,IAAI,yBAAyB,EAAE;AAC9C,iBAAe,IAAI,GAAG,WAAW,EAAE;EACnC,MAAM,sBAAsB,MAAM,KAAK,OAAO,eAAe;AAI7D,SAAO;GACL,IAHS,SAAS,GAAG,WAAW;GAIhC;GACA;GACA;GACD;;;yBA3WoB,YAAY;yBACZ,cAAc;yBACd,aAAa;yBACb,0BAA0B,CAAC,kBAAkB,qBAAqB"}
@@ -0,0 +1,18 @@
1
+ //#region src/cryptosuites/constants.d.ts
2
+ /**
3
+ * Constants for Data Integrity cryptosuites
4
+ */
5
+ declare const DATA_INTEGRITY_V2_CONTEXT_URL = "https://w3id.org/security/data-integrity/v2";
6
+ declare const MULTIKEY_CONTEXT_URL = "https://w3id.org/security/multikey/v1";
7
+ declare const ED25519_2020_CONTEXT_URL = "https://w3id.org/security/suites/ed25519-2020/v1";
8
+ declare const CRYPTOSUITE_EDDSA_RDFC_2022 = "eddsa-rdfc-2022";
9
+ declare const CRYPTOSUITE_ECDSA_SD_2023 = "ecdsa-sd-2023";
10
+ declare const CRYPTOSUITE_ECDSA_RDFC_2019 = "ecdsa-rdfc-2019";
11
+ declare const PROOF_TYPE_DATA_INTEGRITY = "DataIntegrityProof";
12
+ declare const PROOF_TYPE_ED25519_2020 = "Ed25519Signature2020";
13
+ declare const VM_TYPE_MULTIKEY = "Multikey";
14
+ declare const VM_TYPE_ED25519_2020 = "Ed25519VerificationKey2020";
15
+ declare const VM_TYPE_ECDSA_SECP256R1 = "EcdsaSecp256r1VerificationKey2019";
16
+ //#endregion
17
+ export { CRYPTOSUITE_ECDSA_RDFC_2019, CRYPTOSUITE_ECDSA_SD_2023, CRYPTOSUITE_EDDSA_RDFC_2022, DATA_INTEGRITY_V2_CONTEXT_URL, ED25519_2020_CONTEXT_URL, MULTIKEY_CONTEXT_URL, PROOF_TYPE_DATA_INTEGRITY, PROOF_TYPE_ED25519_2020, VM_TYPE_ECDSA_SECP256R1, VM_TYPE_ED25519_2020, VM_TYPE_MULTIKEY };
18
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","names":[],"sources":["../../src/cryptosuites/constants.ts"],"mappings":";;AAKA;;cAAa,6BAAA;AAAA,cACA,oBAAA;AAAA,cACA,wBAAA;AAAA,cAGA,2BAAA;AAAA,cACA,yBAAA;AAAA,cACA,2BAAA;AAAA,cAGA,yBAAA;AAAA,cACA,uBAAA;AAAA,cAGA,gBAAA;AAAA,cACA,oBAAA;AAAA,cACA,uBAAA"}
@@ -0,0 +1,19 @@
1
+ //#region src/cryptosuites/constants.ts
2
+ /**
3
+ * Constants for Data Integrity cryptosuites
4
+ */
5
+ const DATA_INTEGRITY_V2_CONTEXT_URL = "https://w3id.org/security/data-integrity/v2";
6
+ const MULTIKEY_CONTEXT_URL = "https://w3id.org/security/multikey/v1";
7
+ const ED25519_2020_CONTEXT_URL = "https://w3id.org/security/suites/ed25519-2020/v1";
8
+ const CRYPTOSUITE_EDDSA_RDFC_2022 = "eddsa-rdfc-2022";
9
+ const CRYPTOSUITE_ECDSA_SD_2023 = "ecdsa-sd-2023";
10
+ const CRYPTOSUITE_ECDSA_RDFC_2019 = "ecdsa-rdfc-2019";
11
+ const PROOF_TYPE_DATA_INTEGRITY = "DataIntegrityProof";
12
+ const PROOF_TYPE_ED25519_2020 = "Ed25519Signature2020";
13
+ const VM_TYPE_MULTIKEY = "Multikey";
14
+ const VM_TYPE_ED25519_2020 = "Ed25519VerificationKey2020";
15
+ const VM_TYPE_ECDSA_SECP256R1 = "EcdsaSecp256r1VerificationKey2019";
16
+
17
+ //#endregion
18
+ export { CRYPTOSUITE_ECDSA_RDFC_2019, CRYPTOSUITE_ECDSA_SD_2023, CRYPTOSUITE_EDDSA_RDFC_2022, DATA_INTEGRITY_V2_CONTEXT_URL, ED25519_2020_CONTEXT_URL, MULTIKEY_CONTEXT_URL, PROOF_TYPE_DATA_INTEGRITY, PROOF_TYPE_ED25519_2020, VM_TYPE_ECDSA_SECP256R1, VM_TYPE_ED25519_2020, VM_TYPE_MULTIKEY };
19
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../src/cryptosuites/constants.ts"],"sourcesContent":["/**\n * Constants for Data Integrity cryptosuites\n */\n\n// Context URLs\nexport const DATA_INTEGRITY_V2_CONTEXT_URL = 'https://w3id.org/security/data-integrity/v2'\nexport const MULTIKEY_CONTEXT_URL = 'https://w3id.org/security/multikey/v1'\nexport const ED25519_2020_CONTEXT_URL = 'https://w3id.org/security/suites/ed25519-2020/v1'\n\n// Cryptosuite identifiers\nexport const CRYPTOSUITE_EDDSA_RDFC_2022 = 'eddsa-rdfc-2022'\nexport const CRYPTOSUITE_ECDSA_SD_2023 = 'ecdsa-sd-2023'\nexport const CRYPTOSUITE_ECDSA_RDFC_2019 = 'ecdsa-rdfc-2019'\n\n// Proof types\nexport const PROOF_TYPE_DATA_INTEGRITY = 'DataIntegrityProof'\nexport const PROOF_TYPE_ED25519_2020 = 'Ed25519Signature2020'\n\n// Verification method types\nexport const VM_TYPE_MULTIKEY = 'Multikey'\nexport const VM_TYPE_ED25519_2020 = 'Ed25519VerificationKey2020'\nexport const VM_TYPE_ECDSA_SECP256R1 = 'EcdsaSecp256r1VerificationKey2019'\n"],"mappings":";;;;AAKA,MAAa,gCAAgC;AAC7C,MAAa,uBAAuB;AACpC,MAAa,2BAA2B;AAGxC,MAAa,8BAA8B;AAC3C,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAG3C,MAAa,4BAA4B;AACzC,MAAa,0BAA0B;AAGvC,MAAa,mBAAmB;AAChC,MAAa,uBAAuB;AACpC,MAAa,0BAA0B"}
@@ -0,0 +1,76 @@
1
+ import * as jsonld from "@digitalcredentials/jsonld";
2
+
3
+ //#region src/cryptosuites/contextPreprocessor.ts
4
+ /**
5
+ * Context Preprocessor
6
+ *
7
+ * Strips @protected flags from JSON-LD contexts to allow combining
8
+ * multiple contexts that define the same terms identically.
9
+ *
10
+ * This is necessary because:
11
+ * - VC v2 and OBv3 contexts both define terms like "description"
12
+ * - Both map to the same IRIs (e.g., https://schema.org/description)
13
+ * - But both use @protected: true, which prevents redefinition
14
+ * - Stripping @protected allows compatible contexts to work together
15
+ */
16
+ const processedContextCache = {};
17
+ /**
18
+ * Recursively remove @protected from a context object
19
+ */
20
+ function stripProtected(obj) {
21
+ if (obj === null || obj === void 0) return obj;
22
+ if (Array.isArray(obj)) return obj.map(stripProtected);
23
+ if (typeof obj === "object") {
24
+ const result = {};
25
+ for (const [key, value] of Object.entries(obj)) {
26
+ if (key === "@protected") continue;
27
+ result[key] = stripProtected(value);
28
+ }
29
+ return result;
30
+ }
31
+ return obj;
32
+ }
33
+ /**
34
+ * Create a document loader that preprocesses contexts to remove @protected.
35
+ *
36
+ * When a `logger` is provided, fetch failures are reported via `logger.warn`.
37
+ * When omitted, failures are swallowed silently — the fallback empty context
38
+ * is returned either way.
39
+ */
40
+ function createPreprocessingDocumentLoader(logger) {
41
+ const nodeDocumentLoader = (jsonld.default ?? jsonld).documentLoaders?.node?.();
42
+ return async (url) => {
43
+ if (processedContextCache[url]) return {
44
+ contextUrl: null,
45
+ document: processedContextCache[url],
46
+ documentUrl: url
47
+ };
48
+ if (nodeDocumentLoader) try {
49
+ const result = await nodeDocumentLoader(url);
50
+ if (result?.document) {
51
+ const processed = stripProtected(result.document);
52
+ processedContextCache[url] = processed;
53
+ return {
54
+ contextUrl: null,
55
+ document: processed,
56
+ documentUrl: url
57
+ };
58
+ }
59
+ return result;
60
+ } catch (e) {
61
+ logger?.warn("[ContextPreprocessor] Failed to fetch context", {
62
+ url,
63
+ error: e?.message
64
+ });
65
+ }
66
+ return {
67
+ contextUrl: null,
68
+ document: { "@context": {} },
69
+ documentUrl: url
70
+ };
71
+ };
72
+ }
73
+
74
+ //#endregion
75
+ export { createPreprocessingDocumentLoader };
76
+ //# sourceMappingURL=contextPreprocessor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextPreprocessor.mjs","names":[],"sources":["../../src/cryptosuites/contextPreprocessor.ts"],"sourcesContent":["/**\n * Context Preprocessor\n *\n * Strips @protected flags from JSON-LD contexts to allow combining\n * multiple contexts that define the same terms identically.\n *\n * This is necessary because:\n * - VC v2 and OBv3 contexts both define terms like \"description\"\n * - Both map to the same IRIs (e.g., https://schema.org/description)\n * - But both use @protected: true, which prevents redefinition\n * - Stripping @protected allows compatible contexts to work together\n */\n\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport * as jsonld from '@digitalcredentials/jsonld'\n\n// Cache for preprocessed contexts\nconst processedContextCache: Record<string, object> = {}\n\n/**\n * Recursively remove @protected from a context object\n */\nfunction stripProtected(obj: unknown): unknown {\n if (obj === null || obj === undefined) {\n return obj\n }\n\n if (Array.isArray(obj)) {\n return obj.map(stripProtected)\n }\n\n if (typeof obj === 'object') {\n const result: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(obj as Record<string, unknown>)) {\n // Skip @protected keys\n if (key === '@protected') {\n continue\n }\n result[key] = stripProtected(value)\n }\n return result\n }\n\n return obj\n}\n\n/**\n * Minimal logger-shape accepted by the preprocessor. Callers can pass an\n * `AgentContext['config']['logger']` here; we don't import the Credo Logger\n * type to keep this module free of `@credo-ts/core` runtime imports.\n */\nexport interface ContextPreprocessorLogger {\n warn: (message: string, data?: Record<string, unknown>) => void\n}\n\n/**\n * Create a document loader that preprocesses contexts to remove @protected.\n *\n * When a `logger` is provided, fetch failures are reported via `logger.warn`.\n * When omitted, failures are swallowed silently — the fallback empty context\n * is returned either way.\n */\nexport function createPreprocessingDocumentLoader(logger?: ContextPreprocessorLogger) {\n const jld = jsonld.default ?? jsonld\n const nodeDocumentLoader = jld.documentLoaders?.node?.()\n\n return async (url: string) => {\n // Check cache first\n if (processedContextCache[url]) {\n return {\n contextUrl: null,\n document: processedContextCache[url],\n documentUrl: url,\n }\n }\n\n // Fetch from network\n if (nodeDocumentLoader) {\n try {\n const result = await nodeDocumentLoader(url)\n\n if (result?.document) {\n // Strip @protected from the context\n const processed = stripProtected(result.document)\n processedContextCache[url] = processed as object\n\n return {\n contextUrl: null,\n document: processed,\n documentUrl: url,\n }\n }\n return result\n } catch (e) {\n logger?.warn('[ContextPreprocessor] Failed to fetch context', { url, error: (e as Error)?.message })\n }\n }\n\n // Return empty context if fetch fails\n return {\n contextUrl: null,\n document: { '@context': {} },\n documentUrl: url,\n }\n }\n}\n\n/**\n * Clear the processed context cache\n */\nexport function clearContextCache() {\n for (const key of Object.keys(processedContextCache)) {\n delete processedContextCache[key]\n }\n}\n\n/**\n * Pre-warm the context cache by fetching common contexts\n */\nexport async function prewarmContextCache(urls: string[]) {\n const loader = createPreprocessingDocumentLoader()\n await Promise.all(urls.map((url) => loader(url).catch(() => null)))\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAM,wBAAgD,EAAE;;;;AAKxD,SAAS,eAAe,KAAuB;AAC7C,KAAI,QAAQ,QAAQ,QAAQ,OAC1B,QAAO;AAGT,KAAI,MAAM,QAAQ,IAAI,CACpB,QAAO,IAAI,IAAI,eAAe;AAGhC,KAAI,OAAO,QAAQ,UAAU;EAC3B,MAAM,SAAkC,EAAE;AAC1C,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,IAA+B,EAAE;AAEzE,OAAI,QAAQ,aACV;AAEF,UAAO,OAAO,eAAe,MAAM;;AAErC,SAAO;;AAGT,QAAO;;;;;;;;;AAmBT,SAAgB,kCAAkC,QAAoC;CAEpF,MAAM,sBADM,OAAO,WAAW,QACC,iBAAiB,QAAQ;AAExD,QAAO,OAAO,QAAgB;AAE5B,MAAI,sBAAsB,KACxB,QAAO;GACL,YAAY;GACZ,UAAU,sBAAsB;GAChC,aAAa;GACd;AAIH,MAAI,mBACF,KAAI;GACF,MAAM,SAAS,MAAM,mBAAmB,IAAI;AAE5C,OAAI,QAAQ,UAAU;IAEpB,MAAM,YAAY,eAAe,OAAO,SAAS;AACjD,0BAAsB,OAAO;AAE7B,WAAO;KACL,YAAY;KACZ,UAAU;KACV,aAAa;KACd;;AAEH,UAAO;WACA,GAAG;AACV,WAAQ,KAAK,iDAAiD;IAAE;IAAK,OAAQ,GAAa;IAAS,CAAC;;AAKxG,SAAO;GACL,YAAY;GACZ,UAAU,EAAE,YAAY,EAAE,EAAE;GAC5B,aAAa;GACd"}
@@ -0,0 +1,147 @@
1
+ //#region src/cryptosuites/dataIntegrityV2Context.d.ts
2
+ /**
3
+ * Data Integrity v2 Context
4
+ * https://w3id.org/security/data-integrity/v2
5
+ *
6
+ * This context defines the DataIntegrityProof and related terms.
7
+ * Simplified without @protected to avoid conflicts when combining contexts.
8
+ */
9
+ declare const dataIntegrityV2Context: {
10
+ '@context': {
11
+ id: string;
12
+ type: string;
13
+ DataIntegrityProof: string;
14
+ challenge: string;
15
+ created: {
16
+ '@id': string;
17
+ '@type': string;
18
+ };
19
+ domain: string;
20
+ expires: {
21
+ '@id': string;
22
+ '@type': string;
23
+ };
24
+ nonce: string;
25
+ proofPurpose: {
26
+ '@id': string;
27
+ '@type': string;
28
+ };
29
+ assertionMethod: {
30
+ '@id': string;
31
+ '@type': string;
32
+ };
33
+ authentication: {
34
+ '@id': string;
35
+ '@type': string;
36
+ };
37
+ cryptosuite: {
38
+ '@id': string;
39
+ '@type': string;
40
+ };
41
+ proofValue: {
42
+ '@id': string;
43
+ '@type': string;
44
+ };
45
+ verificationMethod: {
46
+ '@id': string;
47
+ '@type': string;
48
+ };
49
+ previousProof: {
50
+ '@id': string;
51
+ '@type': string;
52
+ };
53
+ Multikey: string;
54
+ controller: {
55
+ '@id': string;
56
+ '@type': string;
57
+ };
58
+ revoked: {
59
+ '@id': string;
60
+ '@type': string;
61
+ };
62
+ publicKeyMultibase: {
63
+ '@id': string;
64
+ '@type': string;
65
+ };
66
+ secretKeyMultibase: {
67
+ '@id': string;
68
+ '@type': string;
69
+ };
70
+ proof: {
71
+ '@id': string;
72
+ '@type': string;
73
+ '@container': string;
74
+ };
75
+ };
76
+ };
77
+ declare const dataIntegrityContextMap: Map<string, {
78
+ '@context': {
79
+ id: string;
80
+ type: string;
81
+ DataIntegrityProof: string;
82
+ challenge: string;
83
+ created: {
84
+ '@id': string;
85
+ '@type': string;
86
+ };
87
+ domain: string;
88
+ expires: {
89
+ '@id': string;
90
+ '@type': string;
91
+ };
92
+ nonce: string;
93
+ proofPurpose: {
94
+ '@id': string;
95
+ '@type': string;
96
+ };
97
+ assertionMethod: {
98
+ '@id': string;
99
+ '@type': string;
100
+ };
101
+ authentication: {
102
+ '@id': string;
103
+ '@type': string;
104
+ };
105
+ cryptosuite: {
106
+ '@id': string;
107
+ '@type': string;
108
+ };
109
+ proofValue: {
110
+ '@id': string;
111
+ '@type': string;
112
+ };
113
+ verificationMethod: {
114
+ '@id': string;
115
+ '@type': string;
116
+ };
117
+ previousProof: {
118
+ '@id': string;
119
+ '@type': string;
120
+ };
121
+ Multikey: string;
122
+ controller: {
123
+ '@id': string;
124
+ '@type': string;
125
+ };
126
+ revoked: {
127
+ '@id': string;
128
+ '@type': string;
129
+ };
130
+ publicKeyMultibase: {
131
+ '@id': string;
132
+ '@type': string;
133
+ };
134
+ secretKeyMultibase: {
135
+ '@id': string;
136
+ '@type': string;
137
+ };
138
+ proof: {
139
+ '@id': string;
140
+ '@type': string;
141
+ '@container': string;
142
+ };
143
+ };
144
+ }>;
145
+ //#endregion
146
+ export { dataIntegrityContextMap, dataIntegrityV2Context };
147
+ //# sourceMappingURL=dataIntegrityV2Context.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataIntegrityV2Context.d.mts","names":[],"sources":["../../src/cryptosuites/dataIntegrityV2Context.ts"],"mappings":";;AAUA;;;;;;cAAa,sBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA2EP,uBAAA,EAAuB,GAAA"}