@credo-ts/anoncreds 0.5.0-alpha.101

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 (378) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +35 -0
  3. package/build/AnonCredsApi.d.ts +91 -0
  4. package/build/AnonCredsApi.js +577 -0
  5. package/build/AnonCredsApi.js.map +1 -0
  6. package/build/AnonCredsApiOptions.d.ts +24 -0
  7. package/build/AnonCredsApiOptions.js +3 -0
  8. package/build/AnonCredsApiOptions.js.map +1 -0
  9. package/build/AnonCredsModule.d.ts +19 -0
  10. package/build/AnonCredsModule.js +41 -0
  11. package/build/AnonCredsModule.js.map +1 -0
  12. package/build/AnonCredsModuleConfig.d.ts +28 -0
  13. package/build/AnonCredsModuleConfig.js +23 -0
  14. package/build/AnonCredsModuleConfig.js.map +1 -0
  15. package/build/error/AnonCredsError.d.ts +6 -0
  16. package/build/error/AnonCredsError.js +11 -0
  17. package/build/error/AnonCredsError.js.map +1 -0
  18. package/build/error/AnonCredsStoreRecordError.d.ts +6 -0
  19. package/build/error/AnonCredsStoreRecordError.js +11 -0
  20. package/build/error/AnonCredsStoreRecordError.js.map +1 -0
  21. package/build/error/index.d.ts +2 -0
  22. package/build/error/index.js +19 -0
  23. package/build/error/index.js.map +1 -0
  24. package/build/formats/AnonCredsCredentialFormat.d.ts +79 -0
  25. package/build/formats/AnonCredsCredentialFormat.js +3 -0
  26. package/build/formats/AnonCredsCredentialFormat.js.map +1 -0
  27. package/build/formats/AnonCredsCredentialFormatService.d.ts +80 -0
  28. package/build/formats/AnonCredsCredentialFormatService.js +455 -0
  29. package/build/formats/AnonCredsCredentialFormatService.js.map +1 -0
  30. package/build/formats/AnonCredsProofFormat.d.ts +70 -0
  31. package/build/formats/AnonCredsProofFormat.js +3 -0
  32. package/build/formats/AnonCredsProofFormat.js.map +1 -0
  33. package/build/formats/AnonCredsProofFormatService.d.ts +58 -0
  34. package/build/formats/AnonCredsProofFormatService.js +375 -0
  35. package/build/formats/AnonCredsProofFormatService.js.map +1 -0
  36. package/build/formats/LegacyIndyCredentialFormat.d.ts +32 -0
  37. package/build/formats/LegacyIndyCredentialFormat.js +3 -0
  38. package/build/formats/LegacyIndyCredentialFormat.js.map +1 -0
  39. package/build/formats/LegacyIndyCredentialFormatService.d.ts +80 -0
  40. package/build/formats/LegacyIndyCredentialFormatService.js +414 -0
  41. package/build/formats/LegacyIndyCredentialFormatService.js.map +1 -0
  42. package/build/formats/LegacyIndyProofFormat.d.ts +29 -0
  43. package/build/formats/LegacyIndyProofFormat.js +3 -0
  44. package/build/formats/LegacyIndyProofFormat.js.map +1 -0
  45. package/build/formats/LegacyIndyProofFormatService.d.ts +58 -0
  46. package/build/formats/LegacyIndyProofFormatService.js +384 -0
  47. package/build/formats/LegacyIndyProofFormatService.js.map +1 -0
  48. package/build/formats/index.d.ts +8 -0
  49. package/build/formats/index.js +30 -0
  50. package/build/formats/index.js.map +1 -0
  51. package/build/index.d.ts +16 -0
  52. package/build/index.js +41 -0
  53. package/build/index.js.map +1 -0
  54. package/build/models/AnonCredsCredentialProposal.d.ts +62 -0
  55. package/build/models/AnonCredsCredentialProposal.js +81 -0
  56. package/build/models/AnonCredsCredentialProposal.js.map +1 -0
  57. package/build/models/AnonCredsProofRequest.d.ts +27 -0
  58. package/build/models/AnonCredsProofRequest.js +82 -0
  59. package/build/models/AnonCredsProofRequest.js.map +1 -0
  60. package/build/models/AnonCredsRequestedAttribute.d.ts +16 -0
  61. package/build/models/AnonCredsRequestedAttribute.js +56 -0
  62. package/build/models/AnonCredsRequestedAttribute.js.map +1 -0
  63. package/build/models/AnonCredsRequestedPredicate.d.ts +19 -0
  64. package/build/models/AnonCredsRequestedPredicate.js +61 -0
  65. package/build/models/AnonCredsRequestedPredicate.js.map +1 -0
  66. package/build/models/AnonCredsRestriction.d.ts +55 -0
  67. package/build/models/AnonCredsRestriction.js +160 -0
  68. package/build/models/AnonCredsRestriction.js.map +1 -0
  69. package/build/models/AnonCredsRestrictionWrapper.d.ts +4 -0
  70. package/build/models/AnonCredsRestrictionWrapper.js +25 -0
  71. package/build/models/AnonCredsRestrictionWrapper.js.map +1 -0
  72. package/build/models/AnonCredsRevocationInterval.d.ts +5 -0
  73. package/build/models/AnonCredsRevocationInterval.js +33 -0
  74. package/build/models/AnonCredsRevocationInterval.js.map +1 -0
  75. package/build/models/exchange.d.ts +100 -0
  76. package/build/models/exchange.js +5 -0
  77. package/build/models/exchange.js.map +1 -0
  78. package/build/models/index.d.ts +4 -0
  79. package/build/models/index.js +21 -0
  80. package/build/models/index.js.map +1 -0
  81. package/build/models/internal.d.ts +38 -0
  82. package/build/models/internal.js +3 -0
  83. package/build/models/internal.js.map +1 -0
  84. package/build/models/registry.d.ts +39 -0
  85. package/build/models/registry.js +3 -0
  86. package/build/models/registry.js.map +1 -0
  87. package/build/protocols/credentials/v1/V1CredentialProtocol.d.ts +162 -0
  88. package/build/protocols/credentials/v1/V1CredentialProtocol.js +901 -0
  89. package/build/protocols/credentials/v1/V1CredentialProtocol.js.map +1 -0
  90. package/build/protocols/credentials/v1/errors/V1CredentialProblemReportError.d.ts +10 -0
  91. package/build/protocols/credentials/v1/errors/V1CredentialProblemReportError.js +18 -0
  92. package/build/protocols/credentials/v1/errors/V1CredentialProblemReportError.js.map +1 -0
  93. package/build/protocols/credentials/v1/errors/index.d.ts +1 -0
  94. package/build/protocols/credentials/v1/errors/index.js +6 -0
  95. package/build/protocols/credentials/v1/errors/index.js.map +1 -0
  96. package/build/protocols/credentials/v1/handlers/V1CredentialAckHandler.d.ts +9 -0
  97. package/build/protocols/credentials/v1/handlers/V1CredentialAckHandler.js +15 -0
  98. package/build/protocols/credentials/v1/handlers/V1CredentialAckHandler.js.map +1 -0
  99. package/build/protocols/credentials/v1/handlers/V1CredentialProblemReportHandler.d.ts +9 -0
  100. package/build/protocols/credentials/v1/handlers/V1CredentialProblemReportHandler.js +15 -0
  101. package/build/protocols/credentials/v1/handlers/V1CredentialProblemReportHandler.js.map +1 -0
  102. package/build/protocols/credentials/v1/handlers/V1IssueCredentialHandler.d.ts +10 -0
  103. package/build/protocols/credentials/v1/handlers/V1IssueCredentialHandler.js +40 -0
  104. package/build/protocols/credentials/v1/handlers/V1IssueCredentialHandler.js.map +1 -0
  105. package/build/protocols/credentials/v1/handlers/V1OfferCredentialHandler.d.ts +10 -0
  106. package/build/protocols/credentials/v1/handlers/V1OfferCredentialHandler.js +33 -0
  107. package/build/protocols/credentials/v1/handlers/V1OfferCredentialHandler.js.map +1 -0
  108. package/build/protocols/credentials/v1/handlers/V1ProposeCredentialHandler.d.ts +10 -0
  109. package/build/protocols/credentials/v1/handlers/V1ProposeCredentialHandler.js +38 -0
  110. package/build/protocols/credentials/v1/handlers/V1ProposeCredentialHandler.js.map +1 -0
  111. package/build/protocols/credentials/v1/handlers/V1RequestCredentialHandler.d.ts +10 -0
  112. package/build/protocols/credentials/v1/handlers/V1RequestCredentialHandler.js +40 -0
  113. package/build/protocols/credentials/v1/handlers/V1RequestCredentialHandler.js.map +1 -0
  114. package/build/protocols/credentials/v1/handlers/index.d.ts +6 -0
  115. package/build/protocols/credentials/v1/handlers/index.js +23 -0
  116. package/build/protocols/credentials/v1/handlers/index.js.map +1 -0
  117. package/build/protocols/credentials/v1/index.d.ts +2 -0
  118. package/build/protocols/credentials/v1/index.js +19 -0
  119. package/build/protocols/credentials/v1/index.js.map +1 -0
  120. package/build/protocols/credentials/v1/messages/V1CredentialAckMessage.d.ts +16 -0
  121. package/build/protocols/credentials/v1/messages/V1CredentialAckMessage.js +34 -0
  122. package/build/protocols/credentials/v1/messages/V1CredentialAckMessage.js.map +1 -0
  123. package/build/protocols/credentials/v1/messages/V1CredentialPreview.d.ts +26 -0
  124. package/build/protocols/credentials/v1/messages/V1CredentialPreview.js +69 -0
  125. package/build/protocols/credentials/v1/messages/V1CredentialPreview.js.map +1 -0
  126. package/build/protocols/credentials/v1/messages/V1CredentialProblemReportMessage.d.ts +16 -0
  127. package/build/protocols/credentials/v1/messages/V1CredentialProblemReportMessage.js +34 -0
  128. package/build/protocols/credentials/v1/messages/V1CredentialProblemReportMessage.js.map +1 -0
  129. package/build/protocols/credentials/v1/messages/V1IssueCredentialMessage.d.ts +19 -0
  130. package/build/protocols/credentials/v1/messages/V1IssueCredentialMessage.js +62 -0
  131. package/build/protocols/credentials/v1/messages/V1IssueCredentialMessage.js.map +1 -0
  132. package/build/protocols/credentials/v1/messages/V1OfferCredentialMessage.d.ts +27 -0
  133. package/build/protocols/credentials/v1/messages/V1OfferCredentialMessage.js +75 -0
  134. package/build/protocols/credentials/v1/messages/V1OfferCredentialMessage.js.map +1 -0
  135. package/build/protocols/credentials/v1/messages/V1ProposeCredentialMessage.d.ts +59 -0
  136. package/build/protocols/credentials/v1/messages/V1ProposeCredentialMessage.js +109 -0
  137. package/build/protocols/credentials/v1/messages/V1ProposeCredentialMessage.js.map +1 -0
  138. package/build/protocols/credentials/v1/messages/V1RequestCredentialMessage.d.ts +19 -0
  139. package/build/protocols/credentials/v1/messages/V1RequestCredentialMessage.js +61 -0
  140. package/build/protocols/credentials/v1/messages/V1RequestCredentialMessage.js.map +1 -0
  141. package/build/protocols/credentials/v1/messages/index.d.ts +7 -0
  142. package/build/protocols/credentials/v1/messages/index.js +24 -0
  143. package/build/protocols/credentials/v1/messages/index.js.map +1 -0
  144. package/build/protocols/index.d.ts +2 -0
  145. package/build/protocols/index.js +19 -0
  146. package/build/protocols/index.js.map +1 -0
  147. package/build/protocols/proofs/v1/V1ProofProtocol.d.ts +50 -0
  148. package/build/protocols/proofs/v1/V1ProofProtocol.js +826 -0
  149. package/build/protocols/proofs/v1/V1ProofProtocol.js.map +1 -0
  150. package/build/protocols/proofs/v1/errors/V1PresentationProblemReportError.d.ts +12 -0
  151. package/build/protocols/proofs/v1/errors/V1PresentationProblemReportError.js +19 -0
  152. package/build/protocols/proofs/v1/errors/V1PresentationProblemReportError.js.map +1 -0
  153. package/build/protocols/proofs/v1/errors/index.d.ts +1 -0
  154. package/build/protocols/proofs/v1/errors/index.js +18 -0
  155. package/build/protocols/proofs/v1/errors/index.js.map +1 -0
  156. package/build/protocols/proofs/v1/handlers/V1PresentationAckHandler.d.ts +9 -0
  157. package/build/protocols/proofs/v1/handlers/V1PresentationAckHandler.js +15 -0
  158. package/build/protocols/proofs/v1/handlers/V1PresentationAckHandler.js.map +1 -0
  159. package/build/protocols/proofs/v1/handlers/V1PresentationHandler.d.ts +10 -0
  160. package/build/protocols/proofs/v1/handlers/V1PresentationHandler.js +40 -0
  161. package/build/protocols/proofs/v1/handlers/V1PresentationHandler.js.map +1 -0
  162. package/build/protocols/proofs/v1/handlers/V1PresentationProblemReportHandler.d.ts +9 -0
  163. package/build/protocols/proofs/v1/handlers/V1PresentationProblemReportHandler.js +15 -0
  164. package/build/protocols/proofs/v1/handlers/V1PresentationProblemReportHandler.js.map +1 -0
  165. package/build/protocols/proofs/v1/handlers/V1ProposePresentationHandler.d.ts +11 -0
  166. package/build/protocols/proofs/v1/handlers/V1ProposePresentationHandler.js +38 -0
  167. package/build/protocols/proofs/v1/handlers/V1ProposePresentationHandler.js.map +1 -0
  168. package/build/protocols/proofs/v1/handlers/V1RequestPresentationHandler.d.ts +10 -0
  169. package/build/protocols/proofs/v1/handlers/V1RequestPresentationHandler.js +35 -0
  170. package/build/protocols/proofs/v1/handlers/V1RequestPresentationHandler.js.map +1 -0
  171. package/build/protocols/proofs/v1/handlers/index.d.ts +5 -0
  172. package/build/protocols/proofs/v1/handlers/index.js +22 -0
  173. package/build/protocols/proofs/v1/handlers/index.js.map +1 -0
  174. package/build/protocols/proofs/v1/index.d.ts +4 -0
  175. package/build/protocols/proofs/v1/index.js +21 -0
  176. package/build/protocols/proofs/v1/index.js.map +1 -0
  177. package/build/protocols/proofs/v1/messages/V1PresentationAckMessage.d.ts +8 -0
  178. package/build/protocols/proofs/v1/messages/V1PresentationAckMessage.js +27 -0
  179. package/build/protocols/proofs/v1/messages/V1PresentationAckMessage.js.map +1 -0
  180. package/build/protocols/proofs/v1/messages/V1PresentationMessage.d.ts +31 -0
  181. package/build/protocols/proofs/v1/messages/V1PresentationMessage.js +67 -0
  182. package/build/protocols/proofs/v1/messages/V1PresentationMessage.js.map +1 -0
  183. package/build/protocols/proofs/v1/messages/V1PresentationProblemReportMessage.d.ts +16 -0
  184. package/build/protocols/proofs/v1/messages/V1PresentationProblemReportMessage.js +34 -0
  185. package/build/protocols/proofs/v1/messages/V1PresentationProblemReportMessage.js.map +1 -0
  186. package/build/protocols/proofs/v1/messages/V1ProposePresentationMessage.d.ts +26 -0
  187. package/build/protocols/proofs/v1/messages/V1ProposePresentationMessage.js +53 -0
  188. package/build/protocols/proofs/v1/messages/V1ProposePresentationMessage.js.map +1 -0
  189. package/build/protocols/proofs/v1/messages/V1RequestPresentationMessage.d.ts +29 -0
  190. package/build/protocols/proofs/v1/messages/V1RequestPresentationMessage.js +65 -0
  191. package/build/protocols/proofs/v1/messages/V1RequestPresentationMessage.js.map +1 -0
  192. package/build/protocols/proofs/v1/messages/index.d.ts +5 -0
  193. package/build/protocols/proofs/v1/messages/index.js +22 -0
  194. package/build/protocols/proofs/v1/messages/index.js.map +1 -0
  195. package/build/protocols/proofs/v1/models/V1PresentationPreview.d.ts +50 -0
  196. package/build/protocols/proofs/v1/models/V1PresentationPreview.js +130 -0
  197. package/build/protocols/proofs/v1/models/V1PresentationPreview.js.map +1 -0
  198. package/build/protocols/proofs/v1/models/index.d.ts +1 -0
  199. package/build/protocols/proofs/v1/models/index.js +18 -0
  200. package/build/protocols/proofs/v1/models/index.js.map +1 -0
  201. package/build/repository/AnonCredsCredentialDefinitionPrivateRecord.d.ts +20 -0
  202. package/build/repository/AnonCredsCredentialDefinitionPrivateRecord.js +22 -0
  203. package/build/repository/AnonCredsCredentialDefinitionPrivateRecord.js.map +1 -0
  204. package/build/repository/AnonCredsCredentialDefinitionPrivateRepository.d.ts +8 -0
  205. package/build/repository/AnonCredsCredentialDefinitionPrivateRepository.js +35 -0
  206. package/build/repository/AnonCredsCredentialDefinitionPrivateRepository.js.map +1 -0
  207. package/build/repository/AnonCredsCredentialDefinitionRecord.d.ts +38 -0
  208. package/build/repository/AnonCredsCredentialDefinitionRecord.js +29 -0
  209. package/build/repository/AnonCredsCredentialDefinitionRecord.js.map +1 -0
  210. package/build/repository/AnonCredsCredentialDefinitionRepository.d.ts +8 -0
  211. package/build/repository/AnonCredsCredentialDefinitionRepository.js +53 -0
  212. package/build/repository/AnonCredsCredentialDefinitionRepository.js.map +1 -0
  213. package/build/repository/AnonCredsCredentialRecord.d.ts +48 -0
  214. package/build/repository/AnonCredsCredentialRecord.js +37 -0
  215. package/build/repository/AnonCredsCredentialRecord.js.map +1 -0
  216. package/build/repository/AnonCredsCredentialRepository.d.ts +10 -0
  217. package/build/repository/AnonCredsCredentialRepository.js +41 -0
  218. package/build/repository/AnonCredsCredentialRepository.js.map +1 -0
  219. package/build/repository/AnonCredsKeyCorrectnessProofRecord.d.ts +20 -0
  220. package/build/repository/AnonCredsKeyCorrectnessProofRecord.js +22 -0
  221. package/build/repository/AnonCredsKeyCorrectnessProofRecord.js.map +1 -0
  222. package/build/repository/AnonCredsKeyCorrectnessProofRepository.d.ts +8 -0
  223. package/build/repository/AnonCredsKeyCorrectnessProofRepository.js +35 -0
  224. package/build/repository/AnonCredsKeyCorrectnessProofRepository.js.map +1 -0
  225. package/build/repository/AnonCredsLinkSecretRecord.d.ts +23 -0
  226. package/build/repository/AnonCredsLinkSecretRecord.js +22 -0
  227. package/build/repository/AnonCredsLinkSecretRecord.js.map +1 -0
  228. package/build/repository/AnonCredsLinkSecretRepository.d.ts +10 -0
  229. package/build/repository/AnonCredsLinkSecretRepository.js +41 -0
  230. package/build/repository/AnonCredsLinkSecretRepository.js.map +1 -0
  231. package/build/repository/AnonCredsRevocationRegistryDefinitionPrivateRecord.d.ts +34 -0
  232. package/build/repository/AnonCredsRevocationRegistryDefinitionPrivateRecord.js +30 -0
  233. package/build/repository/AnonCredsRevocationRegistryDefinitionPrivateRecord.js.map +1 -0
  234. package/build/repository/AnonCredsRevocationRegistryDefinitionPrivateRepository.d.ts +10 -0
  235. package/build/repository/AnonCredsRevocationRegistryDefinitionPrivateRepository.js +38 -0
  236. package/build/repository/AnonCredsRevocationRegistryDefinitionPrivateRepository.js.map +1 -0
  237. package/build/repository/AnonCredsRevocationRegistryDefinitionRecord.d.ts +24 -0
  238. package/build/repository/AnonCredsRevocationRegistryDefinitionRecord.js +22 -0
  239. package/build/repository/AnonCredsRevocationRegistryDefinitionRecord.js.map +1 -0
  240. package/build/repository/AnonCredsRevocationRegistryDefinitionRepository.d.ts +9 -0
  241. package/build/repository/AnonCredsRevocationRegistryDefinitionRepository.js +38 -0
  242. package/build/repository/AnonCredsRevocationRegistryDefinitionRepository.js.map +1 -0
  243. package/build/repository/AnonCredsSchemaRecord.d.ts +38 -0
  244. package/build/repository/AnonCredsSchemaRecord.js +29 -0
  245. package/build/repository/AnonCredsSchemaRecord.js.map +1 -0
  246. package/build/repository/AnonCredsSchemaRepository.d.ts +8 -0
  247. package/build/repository/AnonCredsSchemaRepository.js +53 -0
  248. package/build/repository/AnonCredsSchemaRepository.js.map +1 -0
  249. package/build/repository/anonCredsCredentialDefinitionRecordMetadataTypes.d.ts +9 -0
  250. package/build/repository/anonCredsCredentialDefinitionRecordMetadataTypes.js +9 -0
  251. package/build/repository/anonCredsCredentialDefinitionRecordMetadataTypes.js.map +1 -0
  252. package/build/repository/anonCredsRevocationRegistryDefinitionRecordMetadataTypes.d.ts +9 -0
  253. package/build/repository/anonCredsRevocationRegistryDefinitionRecordMetadataTypes.js +9 -0
  254. package/build/repository/anonCredsRevocationRegistryDefinitionRecordMetadataTypes.js.map +1 -0
  255. package/build/repository/anonCredsSchemaRecordMetadataTypes.d.ts +9 -0
  256. package/build/repository/anonCredsSchemaRecordMetadataTypes.js +9 -0
  257. package/build/repository/anonCredsSchemaRecordMetadataTypes.js.map +1 -0
  258. package/build/repository/index.d.ts +16 -0
  259. package/build/repository/index.js +33 -0
  260. package/build/repository/index.js.map +1 -0
  261. package/build/services/AnonCredsHolderService.d.ts +15 -0
  262. package/build/services/AnonCredsHolderService.js +5 -0
  263. package/build/services/AnonCredsHolderService.js.map +1 -0
  264. package/build/services/AnonCredsHolderServiceOptions.d.ts +82 -0
  265. package/build/services/AnonCredsHolderServiceOptions.js +3 -0
  266. package/build/services/AnonCredsHolderServiceOptions.js.map +1 -0
  267. package/build/services/AnonCredsIssuerService.d.ts +14 -0
  268. package/build/services/AnonCredsIssuerService.js +5 -0
  269. package/build/services/AnonCredsIssuerService.js.map +1 -0
  270. package/build/services/AnonCredsIssuerServiceOptions.d.ts +61 -0
  271. package/build/services/AnonCredsIssuerServiceOptions.js +3 -0
  272. package/build/services/AnonCredsIssuerServiceOptions.js.map +1 -0
  273. package/build/services/AnonCredsVerifierService.d.ts +6 -0
  274. package/build/services/AnonCredsVerifierService.js +5 -0
  275. package/build/services/AnonCredsVerifierService.js.map +1 -0
  276. package/build/services/AnonCredsVerifierServiceOptions.d.ts +20 -0
  277. package/build/services/AnonCredsVerifierServiceOptions.js +3 -0
  278. package/build/services/AnonCredsVerifierServiceOptions.js.map +1 -0
  279. package/build/services/index.d.ts +8 -0
  280. package/build/services/index.js +27 -0
  281. package/build/services/index.js.map +1 -0
  282. package/build/services/registry/AnonCredsRegistry.d.ts +25 -0
  283. package/build/services/registry/AnonCredsRegistry.js +3 -0
  284. package/build/services/registry/AnonCredsRegistry.js.map +1 -0
  285. package/build/services/registry/AnonCredsRegistryService.d.ts +10 -0
  286. package/build/services/registry/AnonCredsRegistryService.js +33 -0
  287. package/build/services/registry/AnonCredsRegistryService.js.map +1 -0
  288. package/build/services/registry/CredentialDefinitionOptions.d.ts +34 -0
  289. package/build/services/registry/CredentialDefinitionOptions.js +3 -0
  290. package/build/services/registry/CredentialDefinitionOptions.js.map +1 -0
  291. package/build/services/registry/RevocationRegistryDefinitionOptions.d.ts +34 -0
  292. package/build/services/registry/RevocationRegistryDefinitionOptions.js +3 -0
  293. package/build/services/registry/RevocationRegistryDefinitionOptions.js.map +1 -0
  294. package/build/services/registry/RevocationStatusListOptions.d.ts +32 -0
  295. package/build/services/registry/RevocationStatusListOptions.js +3 -0
  296. package/build/services/registry/RevocationStatusListOptions.js.map +1 -0
  297. package/build/services/registry/SchemaOptions.d.ts +34 -0
  298. package/build/services/registry/SchemaOptions.js +3 -0
  299. package/build/services/registry/SchemaOptions.js.map +1 -0
  300. package/build/services/registry/base.d.ts +19 -0
  301. package/build/services/registry/base.js +3 -0
  302. package/build/services/registry/base.js.map +1 -0
  303. package/build/services/registry/index.d.ts +7 -0
  304. package/build/services/registry/index.js +23 -0
  305. package/build/services/registry/index.js.map +1 -0
  306. package/build/services/tails/BasicTailsFileService.d.ts +23 -0
  307. package/build/services/tails/BasicTailsFileService.js +65 -0
  308. package/build/services/tails/BasicTailsFileService.js.map +1 -0
  309. package/build/services/tails/TailsFileService.d.ts +42 -0
  310. package/build/services/tails/TailsFileService.js +3 -0
  311. package/build/services/tails/TailsFileService.js.map +1 -0
  312. package/build/services/tails/index.d.ts +2 -0
  313. package/build/services/tails/index.js +19 -0
  314. package/build/services/tails/index.js.map +1 -0
  315. package/build/updates/0.3.1-0.4/credentialDefinition.d.ts +18 -0
  316. package/build/updates/0.3.1-0.4/credentialDefinition.js +57 -0
  317. package/build/updates/0.3.1-0.4/credentialDefinition.js.map +1 -0
  318. package/build/updates/0.3.1-0.4/credentialExchangeRecord.d.ts +69 -0
  319. package/build/updates/0.3.1-0.4/credentialExchangeRecord.js +122 -0
  320. package/build/updates/0.3.1-0.4/credentialExchangeRecord.js.map +1 -0
  321. package/build/updates/0.3.1-0.4/index.d.ts +2 -0
  322. package/build/updates/0.3.1-0.4/index.js +15 -0
  323. package/build/updates/0.3.1-0.4/index.js.map +1 -0
  324. package/build/updates/0.3.1-0.4/linkSecret.d.ts +6 -0
  325. package/build/updates/0.3.1-0.4/linkSecret.js +36 -0
  326. package/build/updates/0.3.1-0.4/linkSecret.js.map +1 -0
  327. package/build/updates/0.3.1-0.4/schema.d.ts +15 -0
  328. package/build/updates/0.3.1-0.4/schema.js +42 -0
  329. package/build/updates/0.3.1-0.4/schema.js.map +1 -0
  330. package/build/utils/areRequestsEqual.d.ts +6 -0
  331. package/build/utils/areRequestsEqual.js +136 -0
  332. package/build/utils/areRequestsEqual.js.map +1 -0
  333. package/build/utils/composeAutoAccept.d.ts +15 -0
  334. package/build/utils/composeAutoAccept.js +27 -0
  335. package/build/utils/composeAutoAccept.js.map +1 -0
  336. package/build/utils/createRequestFromPreview.d.ts +10 -0
  337. package/build/utils/createRequestFromPreview.js +72 -0
  338. package/build/utils/createRequestFromPreview.js.map +1 -0
  339. package/build/utils/credential.d.ts +62 -0
  340. package/build/utils/credential.js +169 -0
  341. package/build/utils/credential.js.map +1 -0
  342. package/build/utils/credentialPreviewAttributes.d.ts +2 -0
  343. package/build/utils/credentialPreviewAttributes.js +25 -0
  344. package/build/utils/credentialPreviewAttributes.js.map +1 -0
  345. package/build/utils/getRevocationRegistries.d.ts +22 -0
  346. package/build/utils/getRevocationRegistries.js +152 -0
  347. package/build/utils/getRevocationRegistries.js.map +1 -0
  348. package/build/utils/hasDuplicateGroupNames.d.ts +2 -0
  349. package/build/utils/hasDuplicateGroupNames.js +23 -0
  350. package/build/utils/hasDuplicateGroupNames.js.map +1 -0
  351. package/build/utils/index.d.ts +13 -0
  352. package/build/utils/index.js +36 -0
  353. package/build/utils/index.js.map +1 -0
  354. package/build/utils/indyIdentifiers.d.ts +48 -0
  355. package/build/utils/indyIdentifiers.js +146 -0
  356. package/build/utils/indyIdentifiers.js.map +1 -0
  357. package/build/utils/isMap.d.ts +5 -0
  358. package/build/utils/isMap.js +18 -0
  359. package/build/utils/isMap.js.map +1 -0
  360. package/build/utils/linkSecret.d.ts +7 -0
  361. package/build/utils/linkSecret.js +24 -0
  362. package/build/utils/linkSecret.js.map +1 -0
  363. package/build/utils/metadata.d.ts +24 -0
  364. package/build/utils/metadata.js +18 -0
  365. package/build/utils/metadata.js.map +1 -0
  366. package/build/utils/proverDid.d.ts +8 -0
  367. package/build/utils/proverDid.js +16 -0
  368. package/build/utils/proverDid.js.map +1 -0
  369. package/build/utils/revocationInterval.d.ts +7 -0
  370. package/build/utils/revocationInterval.js +15 -0
  371. package/build/utils/revocationInterval.js.map +1 -0
  372. package/build/utils/sortRequestedCredentialsMatches.d.ts +8 -0
  373. package/build/utils/sortRequestedCredentialsMatches.js +33 -0
  374. package/build/utils/sortRequestedCredentialsMatches.js.map +1 -0
  375. package/build/utils/timestamp.d.ts +1 -0
  376. package/build/utils/timestamp.js +7 -0
  377. package/build/utils/timestamp.js.map +1 -0
  378. package/package.json +41 -0
@@ -0,0 +1,901 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.V1CredentialProtocol = void 0;
4
+ const core_1 = require("@credo-ts/core");
5
+ const AnonCredsCredentialProposal_1 = require("../../../models/AnonCredsCredentialProposal");
6
+ const utils_1 = require("../../../utils");
7
+ const handlers_1 = require("./handlers");
8
+ const messages_1 = require("./messages");
9
+ class V1CredentialProtocol extends core_1.BaseCredentialProtocol {
10
+ constructor({ indyCredentialFormat }) {
11
+ super();
12
+ /**
13
+ * The version of the issue credential protocol this protocol supports
14
+ */
15
+ this.version = 'v1';
16
+ // TODO: just create a new instance of LegacyIndyCredentialFormatService here so it makes the setup easier
17
+ this.indyCredentialFormat = indyCredentialFormat;
18
+ }
19
+ /**
20
+ * Registers the protocol implementation (handlers, feature registry) on the agent.
21
+ */
22
+ register(dependencyManager, featureRegistry) {
23
+ // Register message handlers for the Issue Credential V1 Protocol
24
+ dependencyManager.registerMessageHandlers([
25
+ new handlers_1.V1ProposeCredentialHandler(this),
26
+ new handlers_1.V1OfferCredentialHandler(this),
27
+ new handlers_1.V1RequestCredentialHandler(this),
28
+ new handlers_1.V1IssueCredentialHandler(this),
29
+ new handlers_1.V1CredentialAckHandler(this),
30
+ new handlers_1.V1CredentialProblemReportHandler(this),
31
+ ]);
32
+ // Register Issue Credential V1 in feature registry, with supported roles
33
+ featureRegistry.register(new core_1.Protocol({
34
+ id: 'https://didcomm.org/issue-credential/1.0',
35
+ roles: ['holder', 'issuer'],
36
+ }));
37
+ }
38
+ /**
39
+ * Create a {@link ProposeCredentialMessage} not bound to an existing credential exchange.
40
+ * To create a proposal as response to an existing credential exchange, use {@link createProposalAsResponse}.
41
+ *
42
+ * @param options The object containing config options
43
+ * @returns Object containing proposal message and associated credential record
44
+ *
45
+ */
46
+ async createProposal(agentContext, { connectionRecord, credentialFormats, comment, autoAcceptCredential, }) {
47
+ this.assertOnlyIndyFormat(credentialFormats);
48
+ const credentialRepository = agentContext.dependencyManager.resolve(core_1.CredentialRepository);
49
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
50
+ if (!credentialFormats.indy) {
51
+ throw new core_1.AriesFrameworkError('Missing indy credential format in v1 create proposal call.');
52
+ }
53
+ // TODO: linked attachments are broken currently. We never include them in the messages.
54
+ // The linking with previews does work, so it shouldn't be too much work to re-enable this.
55
+ const { linkedAttachments } = credentialFormats.indy;
56
+ // Create record
57
+ const credentialRecord = new core_1.CredentialExchangeRecord({
58
+ connectionId: connectionRecord.id,
59
+ threadId: core_1.utils.uuid(),
60
+ state: core_1.CredentialState.ProposalSent,
61
+ linkedAttachments: linkedAttachments === null || linkedAttachments === void 0 ? void 0 : linkedAttachments.map((linkedAttachment) => linkedAttachment.attachment),
62
+ autoAcceptCredential,
63
+ protocolVersion: 'v1',
64
+ });
65
+ // call create proposal for validation of the proposal and addition of linked attachments
66
+ const { previewAttributes, attachment } = await this.indyCredentialFormat.createProposal(agentContext, {
67
+ credentialFormats,
68
+ credentialRecord,
69
+ });
70
+ // Transform the attachment into the attachment payload and use that to construct the v1 message
71
+ const indyCredentialProposal = core_1.JsonTransformer.fromJSON(attachment.getDataAsJson(), AnonCredsCredentialProposal_1.AnonCredsCredentialProposal);
72
+ const credentialProposal = previewAttributes
73
+ ? new messages_1.V1CredentialPreview({
74
+ attributes: previewAttributes,
75
+ })
76
+ : undefined;
77
+ // Create message
78
+ const message = new messages_1.V1ProposeCredentialMessage(Object.assign(Object.assign({}, indyCredentialProposal), { id: credentialRecord.threadId, credentialPreview: credentialProposal, comment }));
79
+ await didCommMessageRepository.saveAgentMessage(agentContext, {
80
+ agentMessage: message,
81
+ role: core_1.DidCommMessageRole.Sender,
82
+ associatedRecordId: credentialRecord.id,
83
+ });
84
+ credentialRecord.credentialAttributes = credentialProposal === null || credentialProposal === void 0 ? void 0 : credentialProposal.attributes;
85
+ await credentialRepository.save(agentContext, credentialRecord);
86
+ this.emitStateChangedEvent(agentContext, credentialRecord, null);
87
+ return { credentialRecord, message };
88
+ }
89
+ /**
90
+ * Process a received {@link ProposeCredentialMessage}. This will not accept the credential proposal
91
+ * or send a credential offer. It will only create a new, or update the existing credential record with
92
+ * the information from the credential proposal message. Use {@link createOfferAsResponse}
93
+ * after calling this method to create a credential offer.
94
+ *
95
+ * @param messageContext The message context containing a credential proposal message
96
+ * @returns credential record associated with the credential proposal message
97
+ *
98
+ */
99
+ async processProposal(messageContext) {
100
+ const { message: proposalMessage, connection, agentContext } = messageContext;
101
+ const credentialRepository = agentContext.dependencyManager.resolve(core_1.CredentialRepository);
102
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
103
+ // TODO: with this method, we should update the credential protocol to use the ConnectionApi, so it
104
+ // only depends on the public api, rather than the internal API (this helps with breaking changes)
105
+ const connectionService = agentContext.dependencyManager.resolve(core_1.ConnectionService);
106
+ agentContext.config.logger.debug(`Processing credential proposal with message id ${proposalMessage.id}`);
107
+ let credentialRecord = await this.findByThreadAndConnectionId(messageContext.agentContext, proposalMessage.threadId, connection === null || connection === void 0 ? void 0 : connection.id);
108
+ // Credential record already exists, this is a response to an earlier message sent by us
109
+ if (credentialRecord) {
110
+ agentContext.config.logger.debug('Credential record already exists for incoming proposal');
111
+ // Assert
112
+ credentialRecord.assertProtocolVersion('v1');
113
+ credentialRecord.assertState(core_1.CredentialState.OfferSent);
114
+ const lastReceivedMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
115
+ associatedRecordId: credentialRecord.id,
116
+ messageClass: messages_1.V1ProposeCredentialMessage,
117
+ });
118
+ const lastSentMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
119
+ associatedRecordId: credentialRecord.id,
120
+ messageClass: messages_1.V1OfferCredentialMessage,
121
+ });
122
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
123
+ lastReceivedMessage,
124
+ lastSentMessage,
125
+ });
126
+ await this.indyCredentialFormat.processProposal(messageContext.agentContext, {
127
+ credentialRecord,
128
+ attachment: new core_1.Attachment({
129
+ data: new core_1.AttachmentData({
130
+ json: core_1.JsonTransformer.toJSON(this.rfc0592ProposalFromV1ProposeMessage(proposalMessage)),
131
+ }),
132
+ }),
133
+ });
134
+ // Update record
135
+ await this.updateState(messageContext.agentContext, credentialRecord, core_1.CredentialState.ProposalReceived);
136
+ await didCommMessageRepository.saveOrUpdateAgentMessage(messageContext.agentContext, {
137
+ agentMessage: proposalMessage,
138
+ role: core_1.DidCommMessageRole.Receiver,
139
+ associatedRecordId: credentialRecord.id,
140
+ });
141
+ }
142
+ else {
143
+ agentContext.config.logger.debug('Credential record does not exists yet for incoming proposal');
144
+ // No credential record exists with thread id
145
+ credentialRecord = new core_1.CredentialExchangeRecord({
146
+ connectionId: connection === null || connection === void 0 ? void 0 : connection.id,
147
+ threadId: proposalMessage.threadId,
148
+ state: core_1.CredentialState.ProposalReceived,
149
+ protocolVersion: 'v1',
150
+ });
151
+ // Assert
152
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext);
153
+ // Save record
154
+ await credentialRepository.save(messageContext.agentContext, credentialRecord);
155
+ this.emitStateChangedEvent(messageContext.agentContext, credentialRecord, null);
156
+ await didCommMessageRepository.saveAgentMessage(messageContext.agentContext, {
157
+ agentMessage: proposalMessage,
158
+ role: core_1.DidCommMessageRole.Receiver,
159
+ associatedRecordId: credentialRecord.id,
160
+ });
161
+ }
162
+ return credentialRecord;
163
+ }
164
+ /**
165
+ * Processing an incoming credential message and create a credential offer as a response
166
+ * @param options The object containing config options
167
+ * @returns Object containing proposal message and associated credential record
168
+ */
169
+ async acceptProposal(agentContext, { credentialRecord, credentialFormats, comment, autoAcceptCredential, }) {
170
+ var _a;
171
+ // Assert
172
+ credentialRecord.assertProtocolVersion('v1');
173
+ credentialRecord.assertState(core_1.CredentialState.ProposalReceived);
174
+ if (credentialFormats)
175
+ this.assertOnlyIndyFormat(credentialFormats);
176
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
177
+ const proposalMessage = await didCommMessageRepository.getAgentMessage(agentContext, {
178
+ associatedRecordId: credentialRecord.id,
179
+ messageClass: messages_1.V1ProposeCredentialMessage,
180
+ });
181
+ // NOTE: We set the credential attributes from the proposal on the record as we've 'accepted' them
182
+ // and can now use them to create the offer in the format services. It may be overwritten later on
183
+ // if the user provided other attributes in the credentialFormats array.
184
+ credentialRecord.credentialAttributes = (_a = proposalMessage.credentialPreview) === null || _a === void 0 ? void 0 : _a.attributes;
185
+ const { attachment, previewAttributes } = await this.indyCredentialFormat.acceptProposal(agentContext, {
186
+ attachmentId: messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID,
187
+ credentialFormats,
188
+ credentialRecord,
189
+ proposalAttachment: new core_1.Attachment({
190
+ data: new core_1.AttachmentData({
191
+ json: core_1.JsonTransformer.toJSON(this.rfc0592ProposalFromV1ProposeMessage(proposalMessage)),
192
+ }),
193
+ }),
194
+ });
195
+ if (!previewAttributes) {
196
+ throw new core_1.AriesFrameworkError('Missing required credential preview attributes from indy format service');
197
+ }
198
+ const message = new messages_1.V1OfferCredentialMessage({
199
+ comment,
200
+ offerAttachments: [attachment],
201
+ credentialPreview: new messages_1.V1CredentialPreview({
202
+ attributes: previewAttributes,
203
+ }),
204
+ attachments: credentialRecord.linkedAttachments,
205
+ });
206
+ message.setThread({ threadId: credentialRecord.threadId, parentThreadId: credentialRecord.parentThreadId });
207
+ credentialRecord.credentialAttributes = message.credentialPreview.attributes;
208
+ credentialRecord.autoAcceptCredential = autoAcceptCredential !== null && autoAcceptCredential !== void 0 ? autoAcceptCredential : credentialRecord.autoAcceptCredential;
209
+ await this.updateState(agentContext, credentialRecord, core_1.CredentialState.OfferSent);
210
+ await didCommMessageRepository.saveOrUpdateAgentMessage(agentContext, {
211
+ agentMessage: message,
212
+ role: core_1.DidCommMessageRole.Sender,
213
+ associatedRecordId: credentialRecord.id,
214
+ });
215
+ return { credentialRecord, message };
216
+ }
217
+ /**
218
+ * Negotiate a credential proposal as issuer (by sending a credential offer message) to the connection
219
+ * associated with the credential record.
220
+ *
221
+ * @param options configuration for the offer see {@link NegotiateCredentialProposalOptions}
222
+ * @returns Credential record associated with the credential offer and the corresponding new offer message
223
+ *
224
+ */
225
+ async negotiateProposal(agentContext, { credentialFormats, credentialRecord, comment, autoAcceptCredential, }) {
226
+ // Assert
227
+ credentialRecord.assertProtocolVersion('v1');
228
+ credentialRecord.assertState(core_1.CredentialState.ProposalReceived);
229
+ this.assertOnlyIndyFormat(credentialFormats);
230
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
231
+ const { attachment, previewAttributes } = await this.indyCredentialFormat.createOffer(agentContext, {
232
+ attachmentId: messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID,
233
+ credentialFormats,
234
+ credentialRecord,
235
+ });
236
+ if (!previewAttributes) {
237
+ throw new core_1.AriesFrameworkError('Missing required credential preview attributes from indy format service');
238
+ }
239
+ const message = new messages_1.V1OfferCredentialMessage({
240
+ comment,
241
+ offerAttachments: [attachment],
242
+ credentialPreview: new messages_1.V1CredentialPreview({
243
+ attributes: previewAttributes,
244
+ }),
245
+ attachments: credentialRecord.linkedAttachments,
246
+ });
247
+ message.setThread({ threadId: credentialRecord.threadId, parentThreadId: credentialRecord.parentThreadId });
248
+ credentialRecord.credentialAttributes = message.credentialPreview.attributes;
249
+ credentialRecord.autoAcceptCredential = autoAcceptCredential !== null && autoAcceptCredential !== void 0 ? autoAcceptCredential : credentialRecord.autoAcceptCredential;
250
+ await this.updateState(agentContext, credentialRecord, core_1.CredentialState.OfferSent);
251
+ await didCommMessageRepository.saveOrUpdateAgentMessage(agentContext, {
252
+ agentMessage: message,
253
+ role: core_1.DidCommMessageRole.Sender,
254
+ associatedRecordId: credentialRecord.id,
255
+ });
256
+ return { credentialRecord, message };
257
+ }
258
+ /**
259
+ * Create a {@link OfferCredentialMessage} not bound to an existing credential exchange.
260
+ * To create an offer as response to an existing credential exchange, use {@link V1CredentialProtocol#createOfferAsResponse}.
261
+ *
262
+ * @param options The options containing config params for creating the credential offer
263
+ * @returns Object containing offer message and associated credential record
264
+ *
265
+ */
266
+ async createOffer(agentContext, { credentialFormats, autoAcceptCredential, comment, connectionRecord, }) {
267
+ var _a, _b;
268
+ // Assert
269
+ this.assertOnlyIndyFormat(credentialFormats);
270
+ const credentialRepository = agentContext.dependencyManager.resolve(core_1.CredentialRepository);
271
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
272
+ if (!credentialFormats.indy) {
273
+ throw new core_1.AriesFrameworkError('Missing indy credential format data for v1 create offer');
274
+ }
275
+ // Create record
276
+ const credentialRecord = new core_1.CredentialExchangeRecord({
277
+ connectionId: connectionRecord === null || connectionRecord === void 0 ? void 0 : connectionRecord.id,
278
+ threadId: core_1.utils.uuid(),
279
+ linkedAttachments: (_a = credentialFormats.indy.linkedAttachments) === null || _a === void 0 ? void 0 : _a.map((linkedAttachments) => linkedAttachments.attachment),
280
+ state: core_1.CredentialState.OfferSent,
281
+ autoAcceptCredential,
282
+ protocolVersion: 'v1',
283
+ });
284
+ const { attachment, previewAttributes } = await this.indyCredentialFormat.createOffer(agentContext, {
285
+ attachmentId: messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID,
286
+ credentialFormats,
287
+ credentialRecord,
288
+ });
289
+ if (!previewAttributes) {
290
+ throw new core_1.AriesFrameworkError('Missing required credential preview from indy format service');
291
+ }
292
+ // Construct offer message
293
+ const message = new messages_1.V1OfferCredentialMessage({
294
+ id: credentialRecord.threadId,
295
+ credentialPreview: new messages_1.V1CredentialPreview({
296
+ attributes: previewAttributes,
297
+ }),
298
+ comment,
299
+ offerAttachments: [attachment],
300
+ attachments: (_b = credentialFormats.indy.linkedAttachments) === null || _b === void 0 ? void 0 : _b.map((linkedAttachments) => linkedAttachments.attachment),
301
+ });
302
+ await didCommMessageRepository.saveAgentMessage(agentContext, {
303
+ associatedRecordId: credentialRecord.id,
304
+ agentMessage: message,
305
+ role: core_1.DidCommMessageRole.Sender,
306
+ });
307
+ credentialRecord.credentialAttributes = message.credentialPreview.attributes;
308
+ await credentialRepository.save(agentContext, credentialRecord);
309
+ this.emitStateChangedEvent(agentContext, credentialRecord, null);
310
+ return { message, credentialRecord };
311
+ }
312
+ /**
313
+ * Process a received {@link OfferCredentialMessage}. This will not accept the credential offer
314
+ * or send a credential request. It will only create a new credential record with
315
+ * the information from the credential offer message. Use {@link createRequest}
316
+ * after calling this method to create a credential request.
317
+ *
318
+ * @param messageContext The message context containing a credential request message
319
+ * @returns credential record associated with the credential offer message
320
+ *
321
+ */
322
+ async processOffer(messageContext) {
323
+ var _a;
324
+ const { message: offerMessage, connection, agentContext } = messageContext;
325
+ const credentialRepository = agentContext.dependencyManager.resolve(core_1.CredentialRepository);
326
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
327
+ // TODO: with this method, we should update the credential protocol to use the ConnectionApi, so it
328
+ // only depends on the public api, rather than the internal API (this helps with breaking changes)
329
+ const connectionService = agentContext.dependencyManager.resolve(core_1.ConnectionService);
330
+ agentContext.config.logger.debug(`Processing credential offer with id ${offerMessage.id}`);
331
+ let credentialRecord = await this.findByThreadAndConnectionId(agentContext, offerMessage.threadId, connection === null || connection === void 0 ? void 0 : connection.id);
332
+ const offerAttachment = offerMessage.getOfferAttachmentById(messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID);
333
+ if (!offerAttachment) {
334
+ throw new core_1.AriesFrameworkError(`Indy attachment with id ${messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID} not found in offer message`);
335
+ }
336
+ if (credentialRecord) {
337
+ const lastSentMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
338
+ associatedRecordId: credentialRecord.id,
339
+ messageClass: messages_1.V1ProposeCredentialMessage,
340
+ });
341
+ const lastReceivedMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
342
+ associatedRecordId: credentialRecord.id,
343
+ messageClass: messages_1.V1OfferCredentialMessage,
344
+ });
345
+ // Assert
346
+ credentialRecord.assertProtocolVersion('v1');
347
+ credentialRecord.assertState(core_1.CredentialState.ProposalSent);
348
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
349
+ lastReceivedMessage,
350
+ lastSentMessage,
351
+ });
352
+ await this.indyCredentialFormat.processOffer(messageContext.agentContext, {
353
+ credentialRecord,
354
+ attachment: offerAttachment,
355
+ });
356
+ await didCommMessageRepository.saveOrUpdateAgentMessage(messageContext.agentContext, {
357
+ agentMessage: offerMessage,
358
+ role: core_1.DidCommMessageRole.Receiver,
359
+ associatedRecordId: credentialRecord.id,
360
+ });
361
+ await this.updateState(messageContext.agentContext, credentialRecord, core_1.CredentialState.OfferReceived);
362
+ return credentialRecord;
363
+ }
364
+ else {
365
+ // No credential record exists with thread id
366
+ credentialRecord = new core_1.CredentialExchangeRecord({
367
+ connectionId: connection === null || connection === void 0 ? void 0 : connection.id,
368
+ threadId: offerMessage.threadId,
369
+ parentThreadId: (_a = offerMessage.thread) === null || _a === void 0 ? void 0 : _a.parentThreadId,
370
+ state: core_1.CredentialState.OfferReceived,
371
+ protocolVersion: 'v1',
372
+ });
373
+ // Assert
374
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext);
375
+ await this.indyCredentialFormat.processOffer(messageContext.agentContext, {
376
+ credentialRecord,
377
+ attachment: offerAttachment,
378
+ });
379
+ // Save in repository
380
+ await didCommMessageRepository.saveAgentMessage(messageContext.agentContext, {
381
+ agentMessage: offerMessage,
382
+ role: core_1.DidCommMessageRole.Receiver,
383
+ associatedRecordId: credentialRecord.id,
384
+ });
385
+ await credentialRepository.save(messageContext.agentContext, credentialRecord);
386
+ this.emitStateChangedEvent(messageContext.agentContext, credentialRecord, null);
387
+ return credentialRecord;
388
+ }
389
+ }
390
+ /**
391
+ * Create a {@link RequestCredentialMessage} as response to a received credential offer.
392
+ *
393
+ * @param options configuration to use for the credential request
394
+ * @returns Object containing request message and associated credential record
395
+ *
396
+ */
397
+ async acceptOffer(agentContext, { credentialRecord, credentialFormats, comment, autoAcceptCredential, }) {
398
+ var _a, _b;
399
+ // Assert credential
400
+ credentialRecord.assertProtocolVersion('v1');
401
+ credentialRecord.assertState(core_1.CredentialState.OfferReceived);
402
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
403
+ const offerMessage = await didCommMessageRepository.getAgentMessage(agentContext, {
404
+ associatedRecordId: credentialRecord.id,
405
+ messageClass: messages_1.V1OfferCredentialMessage,
406
+ });
407
+ const offerAttachment = offerMessage.getOfferAttachmentById(messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID);
408
+ if (!offerAttachment) {
409
+ throw new core_1.AriesFrameworkError(`Indy attachment with id ${messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID} not found in offer message`);
410
+ }
411
+ const { attachment } = await this.indyCredentialFormat.acceptOffer(agentContext, {
412
+ credentialRecord,
413
+ credentialFormats,
414
+ attachmentId: messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID,
415
+ offerAttachment,
416
+ });
417
+ const requestMessage = new messages_1.V1RequestCredentialMessage({
418
+ comment,
419
+ requestAttachments: [attachment],
420
+ attachments: (_a = offerMessage.appendedAttachments) === null || _a === void 0 ? void 0 : _a.filter((attachment) => (0, core_1.isLinkedAttachment)(attachment)),
421
+ });
422
+ requestMessage.setThread({ threadId: credentialRecord.threadId, parentThreadId: credentialRecord.parentThreadId });
423
+ credentialRecord.credentialAttributes = offerMessage.credentialPreview.attributes;
424
+ credentialRecord.autoAcceptCredential = autoAcceptCredential !== null && autoAcceptCredential !== void 0 ? autoAcceptCredential : credentialRecord.autoAcceptCredential;
425
+ credentialRecord.linkedAttachments = (_b = offerMessage.appendedAttachments) === null || _b === void 0 ? void 0 : _b.filter((attachment) => (0, core_1.isLinkedAttachment)(attachment));
426
+ await didCommMessageRepository.saveOrUpdateAgentMessage(agentContext, {
427
+ agentMessage: requestMessage,
428
+ associatedRecordId: credentialRecord.id,
429
+ role: core_1.DidCommMessageRole.Sender,
430
+ });
431
+ await this.updateState(agentContext, credentialRecord, core_1.CredentialState.RequestSent);
432
+ return { message: requestMessage, credentialRecord };
433
+ }
434
+ /**
435
+ * Process a received {@link RequestCredentialMessage}. This will not accept the credential request
436
+ * or send a credential. It will only update the existing credential record with
437
+ * the information from the credential request message. Use {@link createCredential}
438
+ * after calling this method to create a credential.
439
+ *
440
+ * @param messageContext The message context containing a credential request message
441
+ * @returns credential record associated with the credential request message
442
+ *
443
+ */
444
+ async negotiateOffer(agentContext, { credentialFormats, credentialRecord, autoAcceptCredential, comment, }) {
445
+ var _a;
446
+ // Assert
447
+ credentialRecord.assertProtocolVersion('v1');
448
+ credentialRecord.assertState(core_1.CredentialState.OfferReceived);
449
+ this.assertOnlyIndyFormat(credentialFormats);
450
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
451
+ if (!credentialRecord.connectionId) {
452
+ throw new core_1.AriesFrameworkError(`No connectionId found for credential record '${credentialRecord.id}'. Connection-less issuance does not support negotiation.`);
453
+ }
454
+ if (!credentialFormats.indy) {
455
+ throw new core_1.AriesFrameworkError('Missing indy credential format in v1 negotiate proposal call.');
456
+ }
457
+ const { linkedAttachments } = credentialFormats.indy;
458
+ // call create proposal for validation of the proposal and addition of linked attachments
459
+ // As the format is different for v1 of the issue credential protocol we won't be using the attachment
460
+ const { previewAttributes, attachment } = await this.indyCredentialFormat.createProposal(agentContext, {
461
+ credentialFormats,
462
+ credentialRecord,
463
+ });
464
+ // Transform the attachment into the attachment payload and use that to construct the v1 message
465
+ const indyCredentialProposal = core_1.JsonTransformer.fromJSON(attachment.getDataAsJson(), AnonCredsCredentialProposal_1.AnonCredsCredentialProposal);
466
+ const credentialProposal = previewAttributes
467
+ ? new messages_1.V1CredentialPreview({
468
+ attributes: previewAttributes,
469
+ })
470
+ : undefined;
471
+ // Create message
472
+ const message = new messages_1.V1ProposeCredentialMessage(Object.assign(Object.assign({}, indyCredentialProposal), { credentialPreview: credentialProposal, comment }));
473
+ message.setThread({ threadId: credentialRecord.threadId, parentThreadId: credentialRecord.parentThreadId });
474
+ await didCommMessageRepository.saveOrUpdateAgentMessage(agentContext, {
475
+ agentMessage: message,
476
+ role: core_1.DidCommMessageRole.Sender,
477
+ associatedRecordId: credentialRecord.id,
478
+ });
479
+ // Update record
480
+ credentialRecord.credentialAttributes = (_a = message.credentialPreview) === null || _a === void 0 ? void 0 : _a.attributes;
481
+ credentialRecord.linkedAttachments = linkedAttachments === null || linkedAttachments === void 0 ? void 0 : linkedAttachments.map((attachment) => attachment.attachment);
482
+ credentialRecord.autoAcceptCredential = autoAcceptCredential !== null && autoAcceptCredential !== void 0 ? autoAcceptCredential : credentialRecord.autoAcceptCredential;
483
+ await this.updateState(agentContext, credentialRecord, core_1.CredentialState.ProposalSent);
484
+ return { credentialRecord, message };
485
+ }
486
+ /**
487
+ * Starting from a request is not supported in v1 of the issue credential protocol
488
+ * because indy doesn't allow to start from a request
489
+ */
490
+ async createRequest() {
491
+ throw new core_1.AriesFrameworkError('Starting from a request is not supported for v1 issue credential protocol');
492
+ }
493
+ async processRequest(messageContext) {
494
+ const { message: requestMessage, connection, agentContext } = messageContext;
495
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
496
+ // TODO: with this method, we should update the credential protocol to use the ConnectionApi, so it
497
+ // only depends on the public api, rather than the internal API (this helps with breaking changes)
498
+ const connectionService = agentContext.dependencyManager.resolve(core_1.ConnectionService);
499
+ agentContext.config.logger.debug(`Processing credential request with id ${requestMessage.id}`);
500
+ const credentialRecord = await this.getByThreadAndConnectionId(messageContext.agentContext, requestMessage.threadId);
501
+ agentContext.config.logger.trace('Credential record found when processing credential request', credentialRecord);
502
+ const proposalMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
503
+ associatedRecordId: credentialRecord.id,
504
+ messageClass: messages_1.V1ProposeCredentialMessage,
505
+ });
506
+ const offerMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
507
+ associatedRecordId: credentialRecord.id,
508
+ messageClass: messages_1.V1OfferCredentialMessage,
509
+ });
510
+ // Assert
511
+ credentialRecord.assertProtocolVersion('v1');
512
+ credentialRecord.assertState(core_1.CredentialState.OfferSent);
513
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
514
+ lastReceivedMessage: proposalMessage !== null && proposalMessage !== void 0 ? proposalMessage : undefined,
515
+ lastSentMessage: offerMessage !== null && offerMessage !== void 0 ? offerMessage : undefined,
516
+ });
517
+ // This makes sure that the sender of the incoming message is authorized to do so.
518
+ if (!credentialRecord.connectionId) {
519
+ await connectionService.matchIncomingMessageToRequestMessageInOutOfBandExchange(messageContext, {
520
+ expectedConnectionId: credentialRecord.connectionId,
521
+ });
522
+ credentialRecord.connectionId = connection === null || connection === void 0 ? void 0 : connection.id;
523
+ }
524
+ const requestAttachment = requestMessage.getRequestAttachmentById(messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID);
525
+ if (!requestAttachment) {
526
+ throw new core_1.AriesFrameworkError(`Indy attachment with id ${messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID} not found in request message`);
527
+ }
528
+ await this.indyCredentialFormat.processRequest(messageContext.agentContext, {
529
+ credentialRecord,
530
+ attachment: requestAttachment,
531
+ });
532
+ await didCommMessageRepository.saveAgentMessage(messageContext.agentContext, {
533
+ agentMessage: requestMessage,
534
+ role: core_1.DidCommMessageRole.Receiver,
535
+ associatedRecordId: credentialRecord.id,
536
+ });
537
+ await this.updateState(messageContext.agentContext, credentialRecord, core_1.CredentialState.RequestReceived);
538
+ return credentialRecord;
539
+ }
540
+ /**
541
+ * Create a {@link V1IssueCredentialMessage} as response to a received credential request.
542
+ *
543
+ * @returns Object containing issue credential message and associated credential record
544
+ *
545
+ */
546
+ async acceptRequest(agentContext, { credentialRecord, credentialFormats, comment, autoAcceptCredential, }) {
547
+ // Assert
548
+ credentialRecord.assertProtocolVersion('v1');
549
+ credentialRecord.assertState(core_1.CredentialState.RequestReceived);
550
+ if (credentialFormats)
551
+ this.assertOnlyIndyFormat(credentialFormats);
552
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
553
+ const offerMessage = await didCommMessageRepository.getAgentMessage(agentContext, {
554
+ associatedRecordId: credentialRecord.id,
555
+ messageClass: messages_1.V1OfferCredentialMessage,
556
+ });
557
+ const requestMessage = await didCommMessageRepository.getAgentMessage(agentContext, {
558
+ associatedRecordId: credentialRecord.id,
559
+ messageClass: messages_1.V1RequestCredentialMessage,
560
+ });
561
+ const offerAttachment = offerMessage.getOfferAttachmentById(messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID);
562
+ const requestAttachment = requestMessage.getRequestAttachmentById(messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID);
563
+ if (!offerAttachment || !requestAttachment) {
564
+ throw new core_1.AriesFrameworkError(`Missing data payload in offer or request attachment in credential Record ${credentialRecord.id}`);
565
+ }
566
+ const { attachment } = await this.indyCredentialFormat.acceptRequest(agentContext, {
567
+ credentialRecord,
568
+ requestAttachment,
569
+ offerAttachment,
570
+ attachmentId: messages_1.INDY_CREDENTIAL_ATTACHMENT_ID,
571
+ credentialFormats,
572
+ });
573
+ const issueMessage = new messages_1.V1IssueCredentialMessage({
574
+ comment,
575
+ credentialAttachments: [attachment],
576
+ attachments: credentialRecord.linkedAttachments,
577
+ });
578
+ issueMessage.setThread({ threadId: credentialRecord.threadId, parentThreadId: credentialRecord.parentThreadId });
579
+ issueMessage.setPleaseAck();
580
+ await didCommMessageRepository.saveAgentMessage(agentContext, {
581
+ agentMessage: issueMessage,
582
+ associatedRecordId: credentialRecord.id,
583
+ role: core_1.DidCommMessageRole.Sender,
584
+ });
585
+ credentialRecord.autoAcceptCredential = autoAcceptCredential !== null && autoAcceptCredential !== void 0 ? autoAcceptCredential : credentialRecord.autoAcceptCredential;
586
+ await this.updateState(agentContext, credentialRecord, core_1.CredentialState.CredentialIssued);
587
+ return { message: issueMessage, credentialRecord };
588
+ }
589
+ /**
590
+ * Process an incoming {@link V1IssueCredentialMessage}
591
+ *
592
+ * @param messageContext The message context containing a credential acknowledgement message
593
+ * @returns credential record associated with the credential acknowledgement message
594
+ *
595
+ */
596
+ async processCredential(messageContext) {
597
+ const { message: issueMessage, connection, agentContext } = messageContext;
598
+ agentContext.config.logger.debug(`Processing credential with id ${issueMessage.id}`);
599
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
600
+ // TODO: with this method, we should update the credential protocol to use the ConnectionApi, so it
601
+ // only depends on the public api, rather than the internal API (this helps with breaking changes)
602
+ const connectionService = agentContext.dependencyManager.resolve(core_1.ConnectionService);
603
+ const credentialRecord = await this.getByThreadAndConnectionId(messageContext.agentContext, issueMessage.threadId, connection === null || connection === void 0 ? void 0 : connection.id);
604
+ const requestCredentialMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
605
+ associatedRecordId: credentialRecord.id,
606
+ messageClass: messages_1.V1RequestCredentialMessage,
607
+ });
608
+ const offerCredentialMessage = await didCommMessageRepository.findAgentMessage(messageContext.agentContext, {
609
+ associatedRecordId: credentialRecord.id,
610
+ messageClass: messages_1.V1OfferCredentialMessage,
611
+ });
612
+ // Assert
613
+ credentialRecord.assertProtocolVersion('v1');
614
+ credentialRecord.assertState(core_1.CredentialState.RequestSent);
615
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
616
+ lastReceivedMessage: offerCredentialMessage,
617
+ lastSentMessage: requestCredentialMessage,
618
+ });
619
+ const issueAttachment = issueMessage.getCredentialAttachmentById(messages_1.INDY_CREDENTIAL_ATTACHMENT_ID);
620
+ if (!issueAttachment) {
621
+ throw new core_1.AriesFrameworkError('Missing indy credential attachment in processCredential');
622
+ }
623
+ const requestAttachment = requestCredentialMessage === null || requestCredentialMessage === void 0 ? void 0 : requestCredentialMessage.getRequestAttachmentById(messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID);
624
+ if (!requestAttachment) {
625
+ throw new core_1.AriesFrameworkError('Missing indy credential request attachment in processCredential');
626
+ }
627
+ await this.indyCredentialFormat.processCredential(messageContext.agentContext, {
628
+ attachment: issueAttachment,
629
+ credentialRecord,
630
+ requestAttachment,
631
+ });
632
+ await didCommMessageRepository.saveAgentMessage(messageContext.agentContext, {
633
+ agentMessage: issueMessage,
634
+ role: core_1.DidCommMessageRole.Receiver,
635
+ associatedRecordId: credentialRecord.id,
636
+ });
637
+ await this.updateState(messageContext.agentContext, credentialRecord, core_1.CredentialState.CredentialReceived);
638
+ return credentialRecord;
639
+ }
640
+ /**
641
+ * Create a {@link CredentialAckMessage} as response to a received credential.
642
+ *
643
+ * @param credentialRecord The credential record for which to create the credential acknowledgement
644
+ * @returns Object containing credential acknowledgement message and associated credential record
645
+ *
646
+ */
647
+ async acceptCredential(agentContext, { credentialRecord }) {
648
+ credentialRecord.assertProtocolVersion('v1');
649
+ credentialRecord.assertState(core_1.CredentialState.CredentialReceived);
650
+ // Create message
651
+ const ackMessage = new messages_1.V1CredentialAckMessage({
652
+ status: core_1.AckStatus.OK,
653
+ threadId: credentialRecord.threadId,
654
+ });
655
+ ackMessage.setThread({ threadId: credentialRecord.threadId, parentThreadId: credentialRecord.parentThreadId });
656
+ await this.updateState(agentContext, credentialRecord, core_1.CredentialState.Done);
657
+ return { message: ackMessage, credentialRecord };
658
+ }
659
+ /**
660
+ * Process a received {@link CredentialAckMessage}.
661
+ *
662
+ * @param messageContext The message context containing a credential acknowledgement message
663
+ * @returns credential record associated with the credential acknowledgement message
664
+ *
665
+ */
666
+ async processAck(messageContext) {
667
+ const { message: ackMessage, connection, agentContext } = messageContext;
668
+ agentContext.config.logger.debug(`Processing credential ack with id ${ackMessage.id}`);
669
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
670
+ // TODO: with this method, we should update the credential protocol to use the ConnectionApi, so it
671
+ // only depends on the public api, rather than the internal API (this helps with breaking changes)
672
+ const connectionService = agentContext.dependencyManager.resolve(core_1.ConnectionService);
673
+ const credentialRecord = await this.getByThreadAndConnectionId(messageContext.agentContext, ackMessage.threadId, connection === null || connection === void 0 ? void 0 : connection.id);
674
+ const requestCredentialMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
675
+ associatedRecordId: credentialRecord.id,
676
+ messageClass: messages_1.V1RequestCredentialMessage,
677
+ });
678
+ const issueCredentialMessage = await didCommMessageRepository.getAgentMessage(messageContext.agentContext, {
679
+ associatedRecordId: credentialRecord.id,
680
+ messageClass: messages_1.V1IssueCredentialMessage,
681
+ });
682
+ // Assert
683
+ credentialRecord.assertProtocolVersion('v1');
684
+ credentialRecord.assertState(core_1.CredentialState.CredentialIssued);
685
+ await connectionService.assertConnectionOrOutOfBandExchange(messageContext, {
686
+ lastReceivedMessage: requestCredentialMessage,
687
+ lastSentMessage: issueCredentialMessage,
688
+ });
689
+ // Update record
690
+ await this.updateState(messageContext.agentContext, credentialRecord, core_1.CredentialState.Done);
691
+ return credentialRecord;
692
+ }
693
+ /**
694
+ * Create a {@link V1CredentialProblemReportMessage} to be sent.
695
+ *
696
+ * @param message message to send
697
+ * @returns a {@link V1CredentialProblemReportMessage}
698
+ *
699
+ */
700
+ async createProblemReport(agentContext, { credentialRecord, description }) {
701
+ const message = new messages_1.V1CredentialProblemReportMessage({
702
+ description: {
703
+ en: description,
704
+ code: core_1.CredentialProblemReportReason.IssuanceAbandoned,
705
+ },
706
+ });
707
+ return { message, credentialRecord };
708
+ }
709
+ // AUTO RESPOND METHODS
710
+ async shouldAutoRespondToProposal(agentContext, options) {
711
+ const { credentialRecord, proposalMessage } = options;
712
+ const credentialsModuleConfig = agentContext.dependencyManager.resolve(core_1.CredentialsModuleConfig);
713
+ const autoAccept = (0, utils_1.composeCredentialAutoAccept)(credentialRecord.autoAcceptCredential, credentialsModuleConfig.autoAcceptCredentials);
714
+ // Handle always / never cases
715
+ if (autoAccept === core_1.AutoAcceptCredential.Always)
716
+ return true;
717
+ if (autoAccept === core_1.AutoAcceptCredential.Never)
718
+ return false;
719
+ const offerMessage = await this.findOfferMessage(agentContext, credentialRecord.id);
720
+ // Do not auto accept if missing properties
721
+ if (!offerMessage || !offerMessage.credentialPreview)
722
+ return false;
723
+ if (!proposalMessage.credentialPreview || !proposalMessage.credentialDefinitionId)
724
+ return false;
725
+ const credentialOfferJson = offerMessage.indyCredentialOffer;
726
+ // Check if credential definition id matches
727
+ if (!credentialOfferJson)
728
+ return false;
729
+ if (credentialOfferJson.cred_def_id !== proposalMessage.credentialDefinitionId)
730
+ return false;
731
+ // Check if preview values match
732
+ return (0, utils_1.areCredentialPreviewAttributesEqual)(proposalMessage.credentialPreview.attributes, offerMessage.credentialPreview.attributes);
733
+ }
734
+ async shouldAutoRespondToOffer(agentContext, options) {
735
+ const { credentialRecord, offerMessage } = options;
736
+ const credentialsModuleConfig = agentContext.dependencyManager.resolve(core_1.CredentialsModuleConfig);
737
+ const autoAccept = (0, utils_1.composeCredentialAutoAccept)(credentialRecord.autoAcceptCredential, credentialsModuleConfig.autoAcceptCredentials);
738
+ // Handle always / never cases
739
+ if (autoAccept === core_1.AutoAcceptCredential.Always)
740
+ return true;
741
+ if (autoAccept === core_1.AutoAcceptCredential.Never)
742
+ return false;
743
+ const proposalMessage = await this.findProposalMessage(agentContext, credentialRecord.id);
744
+ // Do not auto accept if missing properties
745
+ if (!offerMessage.credentialPreview)
746
+ return false;
747
+ if (!proposalMessage || !proposalMessage.credentialPreview || !proposalMessage.credentialDefinitionId)
748
+ return false;
749
+ const credentialOfferJson = offerMessage.indyCredentialOffer;
750
+ // Check if credential definition id matches
751
+ if (!credentialOfferJson)
752
+ return false;
753
+ if (credentialOfferJson.cred_def_id !== proposalMessage.credentialDefinitionId)
754
+ return false;
755
+ // Check if preview values match
756
+ return (0, utils_1.areCredentialPreviewAttributesEqual)(proposalMessage.credentialPreview.attributes, offerMessage.credentialPreview.attributes);
757
+ }
758
+ async shouldAutoRespondToRequest(agentContext, options) {
759
+ const { credentialRecord, requestMessage } = options;
760
+ const credentialsModuleConfig = agentContext.dependencyManager.resolve(core_1.CredentialsModuleConfig);
761
+ const autoAccept = (0, utils_1.composeCredentialAutoAccept)(credentialRecord.autoAcceptCredential, credentialsModuleConfig.autoAcceptCredentials);
762
+ // Handle always / never cases
763
+ if (autoAccept === core_1.AutoAcceptCredential.Always)
764
+ return true;
765
+ if (autoAccept === core_1.AutoAcceptCredential.Never)
766
+ return false;
767
+ const offerMessage = await this.findOfferMessage(agentContext, credentialRecord.id);
768
+ if (!offerMessage)
769
+ return false;
770
+ const offerAttachment = offerMessage.getOfferAttachmentById(messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID);
771
+ const requestAttachment = requestMessage.getRequestAttachmentById(messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID);
772
+ if (!offerAttachment || !requestAttachment)
773
+ return false;
774
+ return this.indyCredentialFormat.shouldAutoRespondToRequest(agentContext, {
775
+ credentialRecord,
776
+ offerAttachment,
777
+ requestAttachment,
778
+ });
779
+ }
780
+ async shouldAutoRespondToCredential(agentContext, options) {
781
+ const { credentialRecord, credentialMessage } = options;
782
+ const credentialsModuleConfig = agentContext.dependencyManager.resolve(core_1.CredentialsModuleConfig);
783
+ const autoAccept = (0, utils_1.composeCredentialAutoAccept)(credentialRecord.autoAcceptCredential, credentialsModuleConfig.autoAcceptCredentials);
784
+ // Handle always / never cases
785
+ if (autoAccept === core_1.AutoAcceptCredential.Always)
786
+ return true;
787
+ if (autoAccept === core_1.AutoAcceptCredential.Never)
788
+ return false;
789
+ const requestMessage = await this.findRequestMessage(agentContext, credentialRecord.id);
790
+ const offerMessage = await this.findOfferMessage(agentContext, credentialRecord.id);
791
+ const credentialAttachment = credentialMessage.getCredentialAttachmentById(messages_1.INDY_CREDENTIAL_ATTACHMENT_ID);
792
+ if (!credentialAttachment)
793
+ return false;
794
+ const requestAttachment = requestMessage === null || requestMessage === void 0 ? void 0 : requestMessage.getRequestAttachmentById(messages_1.INDY_CREDENTIAL_REQUEST_ATTACHMENT_ID);
795
+ if (!requestAttachment)
796
+ return false;
797
+ const offerAttachment = offerMessage === null || offerMessage === void 0 ? void 0 : offerMessage.getOfferAttachmentById(messages_1.INDY_CREDENTIAL_OFFER_ATTACHMENT_ID);
798
+ return this.indyCredentialFormat.shouldAutoRespondToCredential(agentContext, {
799
+ credentialRecord,
800
+ credentialAttachment,
801
+ requestAttachment,
802
+ offerAttachment,
803
+ });
804
+ }
805
+ async findProposalMessage(agentContext, credentialExchangeId) {
806
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
807
+ return await didCommMessageRepository.findAgentMessage(agentContext, {
808
+ associatedRecordId: credentialExchangeId,
809
+ messageClass: messages_1.V1ProposeCredentialMessage,
810
+ });
811
+ }
812
+ async findOfferMessage(agentContext, credentialExchangeId) {
813
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
814
+ return await didCommMessageRepository.findAgentMessage(agentContext, {
815
+ associatedRecordId: credentialExchangeId,
816
+ messageClass: messages_1.V1OfferCredentialMessage,
817
+ });
818
+ }
819
+ async findRequestMessage(agentContext, credentialExchangeId) {
820
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
821
+ return await didCommMessageRepository.findAgentMessage(agentContext, {
822
+ associatedRecordId: credentialExchangeId,
823
+ messageClass: messages_1.V1RequestCredentialMessage,
824
+ });
825
+ }
826
+ async findCredentialMessage(agentContext, credentialExchangeId) {
827
+ const didCommMessageRepository = agentContext.dependencyManager.resolve(core_1.DidCommMessageRepository);
828
+ return await didCommMessageRepository.findAgentMessage(agentContext, {
829
+ associatedRecordId: credentialExchangeId,
830
+ messageClass: messages_1.V1IssueCredentialMessage,
831
+ });
832
+ }
833
+ async getFormatData(agentContext, credentialExchangeId) {
834
+ var _a, _b, _c, _d, _e;
835
+ // TODO: we could looking at fetching all record using a single query and then filtering based on the type of the message.
836
+ const [proposalMessage, offerMessage, requestMessage, credentialMessage] = await Promise.all([
837
+ this.findProposalMessage(agentContext, credentialExchangeId),
838
+ this.findOfferMessage(agentContext, credentialExchangeId),
839
+ this.findRequestMessage(agentContext, credentialExchangeId),
840
+ this.findCredentialMessage(agentContext, credentialExchangeId),
841
+ ]);
842
+ const indyProposal = proposalMessage
843
+ ? core_1.JsonTransformer.toJSON(this.rfc0592ProposalFromV1ProposeMessage(proposalMessage))
844
+ : undefined;
845
+ const indyOffer = (_a = offerMessage === null || offerMessage === void 0 ? void 0 : offerMessage.indyCredentialOffer) !== null && _a !== void 0 ? _a : undefined;
846
+ const indyRequest = (_b = requestMessage === null || requestMessage === void 0 ? void 0 : requestMessage.indyCredentialRequest) !== null && _b !== void 0 ? _b : undefined;
847
+ const indyCredential = (_c = credentialMessage === null || credentialMessage === void 0 ? void 0 : credentialMessage.indyCredential) !== null && _c !== void 0 ? _c : undefined;
848
+ return {
849
+ proposalAttributes: (_d = proposalMessage === null || proposalMessage === void 0 ? void 0 : proposalMessage.credentialPreview) === null || _d === void 0 ? void 0 : _d.attributes,
850
+ proposal: proposalMessage
851
+ ? {
852
+ indy: indyProposal,
853
+ }
854
+ : undefined,
855
+ offerAttributes: (_e = offerMessage === null || offerMessage === void 0 ? void 0 : offerMessage.credentialPreview) === null || _e === void 0 ? void 0 : _e.attributes,
856
+ offer: offerMessage
857
+ ? {
858
+ indy: indyOffer,
859
+ }
860
+ : undefined,
861
+ request: requestMessage
862
+ ? {
863
+ indy: indyRequest,
864
+ }
865
+ : undefined,
866
+ credential: credentialMessage
867
+ ? {
868
+ indy: indyCredential,
869
+ }
870
+ : undefined,
871
+ };
872
+ }
873
+ rfc0592ProposalFromV1ProposeMessage(proposalMessage) {
874
+ const indyCredentialProposal = new AnonCredsCredentialProposal_1.AnonCredsCredentialProposal({
875
+ credentialDefinitionId: proposalMessage.credentialDefinitionId,
876
+ schemaId: proposalMessage.schemaId,
877
+ issuerDid: proposalMessage.issuerDid,
878
+ schemaIssuerDid: proposalMessage.schemaIssuerDid,
879
+ schemaName: proposalMessage.schemaName,
880
+ schemaVersion: proposalMessage.schemaVersion,
881
+ });
882
+ return indyCredentialProposal;
883
+ }
884
+ assertOnlyIndyFormat(credentialFormats) {
885
+ const formatKeys = Object.keys(credentialFormats);
886
+ // It's fine to not have any formats in some cases, if indy is required the method that calls this should check for this
887
+ if (formatKeys.length === 0)
888
+ return;
889
+ if (formatKeys.length !== 1 || !formatKeys.includes('indy')) {
890
+ throw new core_1.AriesFrameworkError('Only indy credential format is supported for issue credential v1 protocol');
891
+ }
892
+ }
893
+ getFormatServiceForRecordType(credentialRecordType) {
894
+ if (credentialRecordType !== this.indyCredentialFormat.credentialRecordType) {
895
+ throw new core_1.AriesFrameworkError(`Unsupported credential record type ${credentialRecordType} for v1 issue credential protocol (need ${this.indyCredentialFormat.credentialRecordType})`);
896
+ }
897
+ return this.indyCredentialFormat;
898
+ }
899
+ }
900
+ exports.V1CredentialProtocol = V1CredentialProtocol;
901
+ //# sourceMappingURL=V1CredentialProtocol.js.map