@decaf-ts/for-fabric 0.0.2 → 0.0.4

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 (232) hide show
  1. package/LICENSE.md +159 -17
  2. package/README.md +26 -285
  3. package/dist/for-fabric.cjs +2 -6223
  4. package/dist/for-fabric.cjs.map +1 -0
  5. package/dist/for-fabric.js +2 -0
  6. package/dist/for-fabric.js.map +1 -0
  7. package/lib/bin/build-contracts.cjs +47 -0
  8. package/lib/bin/build-contracts.d.ts +1 -0
  9. package/lib/bin/build-contracts.js.map +1 -0
  10. package/lib/client/FabricClientAdapter.cjs +7 -7
  11. package/lib/client/FabricClientAdapter.js.map +1 -0
  12. package/lib/client/FabricClientDispatch.cjs +1 -1
  13. package/lib/client/FabricClientDispatch.js.map +1 -0
  14. package/lib/client/FabricClientRepository.cjs +1 -1
  15. package/lib/client/FabricClientRepository.js.map +1 -0
  16. package/lib/client/erc20/erc20ClientRepository.cjs +1 -1
  17. package/lib/client/erc20/erc20ClientRepository.js.map +1 -0
  18. package/lib/client/fabric-fs.cjs +1 -1
  19. package/lib/client/fabric-fs.js.map +1 -0
  20. package/lib/client/index.cjs +1 -1
  21. package/lib/client/index.js.map +1 -0
  22. package/lib/client/logging.cjs +1 -1
  23. package/lib/client/logging.js.map +1 -0
  24. package/lib/client/services/LoggedService.cjs +1 -1
  25. package/lib/client/services/LoggedService.js.map +1 -0
  26. package/lib/client/services/constants.cjs +1 -1
  27. package/lib/client/services/constants.js.map +1 -0
  28. package/lib/client/services/enrollementService.cjs +1 -1
  29. package/lib/client/services/enrollementService.js.map +1 -0
  30. package/lib/client/services/index.cjs +1 -1
  31. package/lib/client/services/index.js.map +1 -0
  32. package/lib/contracts/ContractAdapter.cjs +2 -2
  33. package/lib/contracts/ContractAdapter.js.map +1 -0
  34. package/lib/contracts/ContractContext.cjs +1 -1
  35. package/lib/contracts/ContractContext.js.map +1 -0
  36. package/lib/contracts/ContractPrivateDataAdapter.cjs +1 -1
  37. package/lib/contracts/ContractPrivateDataAdapter.js.map +1 -0
  38. package/lib/contracts/FabricConstruction.cjs +1 -1
  39. package/lib/contracts/FabricConstruction.js.map +1 -0
  40. package/lib/contracts/FabricContractRepository.cjs +7 -5
  41. package/lib/contracts/FabricContractRepository.d.ts +2 -2
  42. package/lib/contracts/FabricContractRepository.js.map +1 -0
  43. package/lib/contracts/FabricContractRepositoryObservableHandler.cjs +1 -1
  44. package/lib/contracts/FabricContractRepositoryObservableHandler.js.map +1 -0
  45. package/lib/contracts/FabricContractSequence.cjs +4 -3
  46. package/lib/contracts/FabricContractSequence.d.ts +2 -1
  47. package/lib/contracts/FabricContractSequence.js.map +1 -0
  48. package/lib/contracts/FabricContractStatement.cjs +3 -2
  49. package/lib/contracts/FabricContractStatement.d.ts +2 -1
  50. package/lib/contracts/FabricContractStatement.js.map +1 -0
  51. package/lib/contracts/PrivateSequence.cjs +1 -1
  52. package/lib/contracts/PrivateSequence.js.map +1 -0
  53. package/lib/contracts/crud/crud-contract.cjs +1 -1
  54. package/lib/contracts/crud/crud-contract.js.map +1 -0
  55. package/lib/contracts/crud/index.cjs +1 -1
  56. package/lib/contracts/crud/index.js.map +1 -0
  57. package/lib/contracts/crud/serialized-crud-contract.cjs +1 -1
  58. package/lib/contracts/crud/serialized-crud-contract.js.map +1 -0
  59. package/lib/contracts/erc20/erc20contract.cjs +1 -1
  60. package/lib/contracts/erc20/erc20contract.js.map +1 -0
  61. package/lib/contracts/erc20/index.cjs +1 -1
  62. package/lib/contracts/erc20/index.js.map +1 -0
  63. package/lib/contracts/erc20/models.cjs +1 -1
  64. package/lib/contracts/erc20/models.js.map +1 -0
  65. package/lib/contracts/index.cjs +1 -1
  66. package/lib/contracts/index.js.map +1 -0
  67. package/lib/contracts/logging.cjs +1 -1
  68. package/lib/contracts/logging.js.map +1 -0
  69. package/lib/contracts/private-data.cjs +1 -1
  70. package/lib/contracts/private-data.js.map +1 -0
  71. package/lib/contracts/types.cjs +1 -1
  72. package/lib/contracts/types.js.map +1 -0
  73. package/lib/esm/bin/build-contracts.d.ts +1 -0
  74. package/lib/esm/bin/build-contracts.js +42 -0
  75. package/lib/esm/bin/build-contracts.js.map +1 -0
  76. package/lib/esm/client/FabricClientAdapter.js +7 -7
  77. package/lib/esm/client/FabricClientAdapter.js.map +1 -0
  78. package/lib/esm/client/FabricClientDispatch.js +1 -1
  79. package/lib/esm/client/FabricClientDispatch.js.map +1 -0
  80. package/lib/esm/client/FabricClientRepository.js +1 -1
  81. package/lib/esm/client/FabricClientRepository.js.map +1 -0
  82. package/lib/esm/client/erc20/erc20ClientRepository.js +1 -1
  83. package/lib/esm/client/erc20/erc20ClientRepository.js.map +1 -0
  84. package/lib/esm/client/fabric-fs.js +1 -1
  85. package/lib/esm/client/fabric-fs.js.map +1 -0
  86. package/lib/esm/client/index.js +1 -1
  87. package/lib/esm/client/index.js.map +1 -0
  88. package/lib/esm/client/logging.js +1 -1
  89. package/lib/esm/client/logging.js.map +1 -0
  90. package/lib/esm/client/services/LoggedService.js +1 -1
  91. package/lib/esm/client/services/LoggedService.js.map +1 -0
  92. package/lib/esm/client/services/constants.js +1 -1
  93. package/lib/esm/client/services/constants.js.map +1 -0
  94. package/lib/esm/client/services/enrollementService.js +1 -1
  95. package/lib/esm/client/services/enrollementService.js.map +1 -0
  96. package/lib/esm/client/services/index.js +1 -1
  97. package/lib/esm/client/services/index.js.map +1 -0
  98. package/lib/esm/contracts/ContractAdapter.js +2 -2
  99. package/lib/esm/contracts/ContractAdapter.js.map +1 -0
  100. package/lib/esm/contracts/ContractContext.js +1 -1
  101. package/lib/esm/contracts/ContractContext.js.map +1 -0
  102. package/lib/esm/contracts/ContractPrivateDataAdapter.js +1 -1
  103. package/lib/esm/contracts/ContractPrivateDataAdapter.js.map +1 -0
  104. package/lib/esm/contracts/FabricConstruction.js +1 -1
  105. package/lib/esm/contracts/FabricConstruction.js.map +1 -0
  106. package/lib/esm/contracts/FabricContractRepository.d.ts +2 -2
  107. package/lib/esm/contracts/FabricContractRepository.js +4 -2
  108. package/lib/esm/contracts/FabricContractRepository.js.map +1 -0
  109. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js +1 -1
  110. package/lib/esm/contracts/FabricContractRepositoryObservableHandler.js.map +1 -0
  111. package/lib/esm/contracts/FabricContractSequence.d.ts +2 -1
  112. package/lib/esm/contracts/FabricContractSequence.js +3 -2
  113. package/lib/esm/contracts/FabricContractSequence.js.map +1 -0
  114. package/lib/esm/contracts/FabricContractStatement.d.ts +2 -1
  115. package/lib/esm/contracts/FabricContractStatement.js +3 -2
  116. package/lib/esm/contracts/FabricContractStatement.js.map +1 -0
  117. package/lib/esm/contracts/PrivateSequence.js +1 -1
  118. package/lib/esm/contracts/PrivateSequence.js.map +1 -0
  119. package/lib/esm/contracts/crud/crud-contract.js +1 -1
  120. package/lib/esm/contracts/crud/crud-contract.js.map +1 -0
  121. package/lib/esm/contracts/crud/index.js +1 -1
  122. package/lib/esm/contracts/crud/index.js.map +1 -0
  123. package/lib/esm/contracts/crud/serialized-crud-contract.js +1 -1
  124. package/lib/esm/contracts/crud/serialized-crud-contract.js.map +1 -0
  125. package/lib/esm/contracts/erc20/erc20contract.js +1 -1
  126. package/lib/esm/contracts/erc20/erc20contract.js.map +1 -0
  127. package/lib/esm/contracts/erc20/index.js +1 -1
  128. package/lib/esm/contracts/erc20/index.js.map +1 -0
  129. package/lib/esm/contracts/erc20/models.js +1 -1
  130. package/lib/esm/contracts/erc20/models.js.map +1 -0
  131. package/lib/esm/contracts/index.js +1 -1
  132. package/lib/esm/contracts/index.js.map +1 -0
  133. package/lib/esm/contracts/logging.js +1 -1
  134. package/lib/esm/contracts/logging.js.map +1 -0
  135. package/lib/esm/contracts/private-data.js +2 -2
  136. package/lib/esm/contracts/private-data.js.map +1 -0
  137. package/lib/esm/contracts/types.js +1 -1
  138. package/lib/esm/contracts/types.js.map +1 -0
  139. package/lib/esm/index.d.ts +1 -0
  140. package/lib/esm/index.js +2 -1
  141. package/lib/esm/index.js.map +1 -0
  142. package/lib/esm/shared/ClientSerializer.js +1 -1
  143. package/lib/esm/shared/ClientSerializer.js.map +1 -0
  144. package/lib/esm/shared/DeterministicSerializer.js +1 -1
  145. package/lib/esm/shared/DeterministicSerializer.js.map +1 -0
  146. package/lib/esm/shared/SimpleDeterministicSerializer.js +1 -1
  147. package/lib/esm/shared/SimpleDeterministicSerializer.js.map +1 -0
  148. package/lib/esm/shared/constants.d.ts +0 -7
  149. package/lib/esm/shared/constants.js +1 -8
  150. package/lib/esm/shared/constants.js.map +1 -0
  151. package/lib/esm/shared/crypto.js +2 -2
  152. package/lib/esm/shared/crypto.js.map +1 -0
  153. package/lib/esm/shared/decorators.js +1 -1
  154. package/lib/esm/shared/decorators.js.map +1 -0
  155. package/lib/esm/shared/erc20/erc20-constants.js +1 -1
  156. package/lib/esm/shared/erc20/erc20-constants.js.map +1 -0
  157. package/lib/esm/shared/errors.js +1 -1
  158. package/lib/esm/shared/errors.js.map +1 -0
  159. package/lib/esm/shared/events.d.ts +2 -0
  160. package/lib/esm/shared/events.js +2 -2
  161. package/lib/esm/shared/events.js.map +1 -0
  162. package/lib/esm/shared/fabric-types.js +1 -1
  163. package/lib/esm/shared/fabric-types.js.map +1 -0
  164. package/lib/esm/shared/index.js +1 -1
  165. package/lib/esm/shared/index.js.map +1 -0
  166. package/lib/esm/shared/interfaces/Checkable.js +1 -1
  167. package/lib/esm/shared/interfaces/Checkable.js.map +1 -0
  168. package/lib/esm/shared/math.js +1 -1
  169. package/lib/esm/shared/math.js.map +1 -0
  170. package/lib/esm/shared/model/Identity.js +1 -1
  171. package/lib/esm/shared/model/Identity.js.map +1 -0
  172. package/lib/esm/shared/model/IdentityCredentials.js +1 -1
  173. package/lib/esm/shared/model/IdentityCredentials.js.map +1 -0
  174. package/lib/esm/shared/model/index.js +1 -1
  175. package/lib/esm/shared/model/index.js.map +1 -0
  176. package/lib/esm/shared/types.js +1 -1
  177. package/lib/esm/shared/types.js.map +1 -0
  178. package/lib/esm/shared/utils.js +1 -1
  179. package/lib/esm/shared/utils.js.map +1 -0
  180. package/lib/esm/version.d.ts +2 -0
  181. package/lib/esm/version.js +5 -0
  182. package/lib/esm/version.js.map +1 -0
  183. package/lib/index.cjs +2 -1
  184. package/lib/index.d.ts +1 -0
  185. package/lib/index.js.map +1 -0
  186. package/lib/shared/ClientSerializer.cjs +1 -1
  187. package/lib/shared/ClientSerializer.js.map +1 -0
  188. package/lib/shared/DeterministicSerializer.cjs +1 -1
  189. package/lib/shared/DeterministicSerializer.js.map +1 -0
  190. package/lib/shared/SimpleDeterministicSerializer.cjs +1 -1
  191. package/lib/shared/SimpleDeterministicSerializer.js.map +1 -0
  192. package/lib/shared/constants.cjs +2 -9
  193. package/lib/shared/constants.d.ts +0 -7
  194. package/lib/shared/constants.js.map +1 -0
  195. package/lib/shared/crypto.cjs +3 -3
  196. package/lib/shared/crypto.js.map +1 -0
  197. package/lib/shared/decorators.cjs +1 -1
  198. package/lib/shared/decorators.js.map +1 -0
  199. package/lib/shared/erc20/erc20-constants.cjs +1 -1
  200. package/lib/shared/erc20/erc20-constants.js.map +1 -0
  201. package/lib/shared/errors.cjs +1 -1
  202. package/lib/shared/errors.js.map +1 -0
  203. package/lib/shared/events.cjs +2 -2
  204. package/lib/shared/events.d.ts +2 -0
  205. package/lib/shared/events.js.map +1 -0
  206. package/lib/shared/fabric-types.cjs +1 -1
  207. package/lib/shared/fabric-types.js.map +1 -0
  208. package/lib/shared/index.cjs +1 -1
  209. package/lib/shared/index.js.map +1 -0
  210. package/lib/shared/interfaces/Checkable.cjs +1 -1
  211. package/lib/shared/interfaces/Checkable.js.map +1 -0
  212. package/lib/shared/math.cjs +1 -1
  213. package/lib/shared/math.js.map +1 -0
  214. package/lib/shared/model/Identity.cjs +1 -1
  215. package/lib/shared/model/Identity.js.map +1 -0
  216. package/lib/shared/model/IdentityCredentials.cjs +1 -1
  217. package/lib/shared/model/IdentityCredentials.js.map +1 -0
  218. package/lib/shared/model/index.cjs +1 -1
  219. package/lib/shared/model/index.js.map +1 -0
  220. package/lib/shared/types.cjs +1 -1
  221. package/lib/shared/types.js.map +1 -0
  222. package/lib/shared/utils.cjs +1 -1
  223. package/lib/shared/utils.js.map +1 -0
  224. package/lib/version.cjs +8 -0
  225. package/lib/version.d.ts +2 -0
  226. package/lib/version.js.map +1 -0
  227. package/package.json +43 -65
  228. package/dist/for-fabric.esm.cjs +0 -6180
  229. package/lib/esm/shared/model/utils.d.ts +0 -60
  230. package/lib/esm/shared/model/utils.js +0 -108
  231. package/lib/shared/model/utils.cjs +0 -114
  232. package/lib/shared/model/utils.d.ts +0 -60
package/LICENSE.md CHANGED
@@ -1,22 +1,164 @@
1
- MIT License
1
+ Mozilla Public License Version 2.0
2
2
 
3
- Copyright (c) 2025 Tiago Venceslau and Contributors
3
+ 1. Definitions
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
5
+ "Contributor"
6
+ means each individual or legal entity that creates, contributes to the
7
+ creation of, or owns Covered Software.
11
8
 
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
9
+ "Contributor Version"
10
+ means the combination of the Contributions of others (if any) used by a
11
+ Contributor and that particular Contributor's Contribution.
14
12
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
13
+ "Covered Software"
14
+ means Source Code Form to which the initial Contributor has attached the
15
+ notice in Exhibit A, the Executable Form of such Source Code Form, and
16
+ Modifications of such Source Code Form.
22
17
 
18
+ "Executable Form"
19
+ means any form of the work other than Source Code Form.
20
+
21
+ "Larger Work"
22
+ means a work which combines Covered Software with other material, in a
23
+ separate file or files, that is not Covered Software.
24
+
25
+ "License"
26
+ means this document.
27
+
28
+ "Licensable"
29
+ means having the right to grant, to the maximum extent possible, whether
30
+ at the time of the making or afterwards, any and all of the rights
31
+ conveyed by this License.
32
+
33
+ "Modifications"
34
+ means any addition to or deletion from the contents of Covered Software
35
+ or any new file that contains Covered Software.
36
+
37
+ "Patent Claims"
38
+ means any patent claim(s), now owned or hereafter acquired, including
39
+ without limitation, method, process, and apparatus claims, in any patent
40
+ Licensable by grantor.
41
+
42
+ "Secondary License"
43
+ means either the GNU General Public License, Version 2.0, the GNU Lesser
44
+ General Public License, Version 2.1, the European Union Public License 1.1,
45
+ or any subsequent versions of those licenses that are designated as a
46
+ Secondary License in the notice in Exhibit A.
47
+
48
+ "Source Code Form"
49
+ means the form of the work preferred for making modifications.
50
+
51
+ "You" (or "Your")
52
+ means an individual or a legal entity exercising rights under, and
53
+ complying with all of the terms of, this License. For legal entities,
54
+ "You" includes any entity that controls, is controlled by, or is under
55
+ common control with You. For purposes of this definition, "control"
56
+ means (a) the power, direct or indirect, to cause the direction or
57
+ management of such entity, whether by contract or otherwise, or (b)
58
+ ownership of more than fifty percent (50%) of the outstanding shares or
59
+ beneficial ownership of such entity.
60
+
61
+ 2. License Grants and Conditions
62
+
63
+ Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive
64
+ license:
65
+
66
+ a. under intellectual property rights (other than patent or trademark)
67
+ Licensable by such Contributor to use, reproduce, make available,
68
+ modify, display, perform, distribute, and otherwise exploit its
69
+ Contributions, either on an exclusive or non-exclusive basis; and
70
+
71
+ b. under Patent Claims to make, use, sell, offer for sale, have made,
72
+ import, and otherwise transfer the Contribution(s) of such
73
+ Contributor, if any, in the Covered Software.
74
+
75
+ This license does not grant rights to any trademarks, service marks, or logos
76
+ of any Contributor (except as may be necessary to comply with the notice
77
+ requirements in Section 3.4).
78
+
79
+ 3. Distribution Obligations
80
+
81
+ 3.1. Distribution of Source Form
82
+
83
+ All distribution of Covered Software in Source Code Form, including any
84
+ Modifications that You create or to which You contribute, must be under the
85
+ terms of this License. You must inform recipients that the Source Code Form
86
+ of the Covered Software is governed by the terms of this License and include
87
+ a copy of this License in or with the Source Code Form.
88
+
89
+ 3.2. Distribution of Executable Form
90
+
91
+ If You distribute Covered Software in Executable Form then:
92
+
93
+ a. such Covered Software must also be made available in Source Code Form,
94
+ as described in Section 3.1, and You must inform recipients of the
95
+ Executable Form how to obtain a complete copy of the corresponding
96
+ Source Code Form in a reasonable manner on or through a medium
97
+ customarily used for software exchange; and
98
+
99
+ b. You may distribute the Executable Form under terms of your choice,
100
+ provided that You do not attempt to limit or alter the recipients'
101
+ rights in the Source Code Form under this License.
102
+
103
+ 3.3. Distribution of a Larger Work
104
+
105
+ You may create and distribute a work that combines Covered Software with
106
+ other material, and distribute the Larger Work as a single product. In such
107
+ case, the Covered Software must still be made available under this License
108
+ and must include the notices described in Exhibit A relating to the Covered
109
+ Software.
110
+
111
+ 3.4. Notices
112
+
113
+ You must cause each file that You distribute containing Covered Software to
114
+ carry the legal notices described in Exhibit A.
115
+
116
+ 4. Incompatible With Secondary Licenses
117
+
118
+ If the Covered Software is made available under the terms of this License
119
+ and also made available under the terms of a Secondary License, then the
120
+ terms of the Secondary License apply to the Covered Software in addition to
121
+ this License to the extent the Secondary License grants additional
122
+ permissions. If the Covered Software is not made available under a Secondary
123
+ License, then this License governs its use.
124
+
125
+ 5. Disclaimer of Warranty
126
+
127
+ Covered Software is provided "as is" without warranty of any kind, either
128
+ express or implied, including, but not limited to, the implied warranties of
129
+ merchantability, fitness for a particular purpose, and noninfringement.
130
+
131
+ 6. Limitation of Liability
132
+
133
+ In no event and under no legal theory, whether in tort (including
134
+ negligence), contract, or otherwise, unless required by applicable law (such
135
+ as deliberate and grossly negligent acts) or agreed to in writing, shall any
136
+ Contributor be liable to You for damages, including any direct, indirect,
137
+ special, incidental, or consequential damages of any character arising as a
138
+ result of this License or out of the use or inability to use the Covered
139
+ Software (including but not limited to damages for loss of goodwill, work
140
+ stoppage, computer failure or malfunction, or any and all other commercial
141
+ damages or losses), even if such Contributor has been advised of the
142
+ possibility of such damages.
143
+
144
+ 7. Termination
145
+
146
+ This License and the rights granted hereunder will terminate automatically
147
+ if You fail to comply with terms of this License and do not cure such
148
+ breach within thirty (30) days of becoming aware of the breach.
149
+
150
+ 8. Miscellaneous
151
+
152
+ This License constitutes the entire agreement between the parties with
153
+ respect to the subject matter hereof. If any provision of this License is
154
+ held to be unenforceable, that provision shall be reformed only to the
155
+ extent necessary to make it enforceable. The headings are for convenience
156
+ only and do not affect the interpretation.
157
+
158
+ Exhibit A - Source Code Form License Notice
159
+
160
+ This Source Code Form is subject to the terms of the Mozilla Public
161
+ License, v. 2.0. If a copy of the MPL was not distributed with this
162
+ file, You can obtain one at http://mozilla.org/MPL/2.0/.
163
+
164
+ Copyright (c) 2025 Tiago Venceslau and Contributors
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  [![Banner](./workdocs/assets/Banner.png)](https://decaf-ts.github.io/ts-workspace/)
2
- ## Hyperledger Fabric Contracts for DECAF
2
+ ## Hyperledger Fabric Integration for DECAF
3
3
 
4
- Chaincode-side building blocks for Hyperledger Fabric written in TypeScript. This module provides repositories, CRUD contracts (object and serialized JSON), an ERC20 sample contract, Fabric-backed sequences, event emission, and context-aware logging. It adapts DECAF’s data-access patterns to Fabrics world-state so you can write smart contracts with the same Repository/Model abstractions used elsewhere in DECAF.
4
+ A TypeScript library that provides seamless integration with Hyperledger Fabric networks, offering both client-side connectivity and chaincode contract development capabilities. It extends the DECAF database abstraction framework to work with Fabric's ledger, enabling consistent data access patterns across different storage technologies.
5
5
 
6
6
 
7
7
  ![Licence](https://img.shields.io/github/license/decaf-ts/for-fabric.svg?style=plastic)
@@ -29,48 +29,39 @@ Documentation available [here](https://decaf-ts.github.io/for-fabric/)
29
29
 
30
30
  ### Description
31
31
 
32
- This module focuses on the chaincode (contracts) side of @decaf-ts/for-fabric. It adapts DECAF’s Repository/Model/Adapter abstractions to Hyperledger Fabric’s world state and execution context so you can implement smart contracts with familiar patterns and minimal boilerplate.
32
+ The @decaf-ts/for-fabric library provides a comprehensive integration layer between the DECAF framework and Hyperledger Fabric blockchain networks. It is designed to simplify the development of both client applications that interact with Fabric networks and chaincode (smart contracts) that run on those networks.
33
33
 
34
- Key ideas:
35
- - Keep your domain models as annotated classes (using @decaf-ts/decorator-validation).
36
- - Use a Repository to persist/read/query models through a Fabric-aware Adapter.
37
- - Compose reusable CRUD contracts and utilities instead of hand-writing stub calls.
38
- - Emit first-class Fabric events from repository operations.
39
- - Leverage context-aware logging and typed flags during execution.
34
+ #### Client-Side Features
40
35
 
41
- Contracts building blocks identified in src/contracts:
36
+ The client module offers a robust set of tools for connecting to and interacting with Fabric networks:
42
37
 
43
- 1) Core context and types
44
- - FabricContractContext: Extends the generic Context to expose Fabric-specific properties (stub, clientIdentity, logger) and timestamp resolution from the ledger.
45
- - FabricContractFlags: Interface extending RepositoryFlags with stub, clientIdentity and logger for contract calls.
38
+ - **FabricAdapter**: Extends the CouchDBAdapter to provide a familiar interface for CRUD operations against Fabric chaincode. It handles connection management, transaction submission, and query evaluation.
46
39
 
47
- 2) Logging
48
- - ContractLogger: MiniLogger-compatible logger bound to the Fabric contract Context. It honors log levels and forwards to the underlying Fabric logger.
40
+ - **FabricDispatch**: Listens for and processes events emitted by Fabric chaincode, enabling real-time updates and event-driven architectures.
49
41
 
50
- 3) Adapter and repository
51
- - FabricContractAdapter: Chaincode-side Adapter that implements CRUD, bulk operations, raw Mango queries, result iteration, model preparation/reversion, composite-key prefixes, and sequence creation. Bridges DECAF abstractions to Fabric (ChaincodeStub, ClientIdentity) and CouchDB-style queries.
52
- - FabricContractRepository<M>: Repository for models inside chaincode. Supports create, update, createAll, updateAll, read/readAll, raw queries (Mango), select projections, prefix-based bulk ops, and event emission through an ObserverHandler.
53
- - FabricContractRepositoryObservableHandler: ObserverHandler that emits Fabric events via stub.setEvent using names generated by generateFabricEventName.
42
+ - **Fabric File System Utilities**: Simplifies working with Fabric identities, certificates, and private keys, with support for both Node.js and browser environments.
54
43
 
55
- 4) Sequences
56
- - FabricContractDBSequence: Fabric-backed implementation of Sequence with current, next and range. Stores values in the world state via FabricContractRepository and supports Number or BigInt sequences with configurable startWith and incrementBy.
44
+ #### Chaincode Features
57
45
 
58
- 5) CRUD contracts
59
- - FabricCrudContract<M>: Base smart contract exposing CRUD endpoints (create, read, update, delete, createAll, readAll, updateAll, deleteAll, raw, init, healthcheck) for a model type. Uses DeterministicSerializer and the FabricContractAdapter/Repository behind the scenes and provides logFor(ctx).
60
- - SerializedCrudContract<M>: Same endpoints as FabricCrudContract but takes/returns JSON strings (de)serialized to the model class. This simplifies client interactions and is used in tests.
46
+ The contracts module provides a framework for developing Fabric chaincode with TypeScript:
61
47
 
62
- 6) ERC20 sample
63
- - ERC20Token, ERC20Wallet, Allowance: Sample domain models for an ERC20-like token, wallets and allowances.
64
- - FabricStatement<M,R>: A CouchDBStatement bridge that runs Mango queries through FabricContractAdapter, handling primary key projection when needed.
65
- - FabricERC20Contract: A full ERC20 smart contract showcasing repository-based persistence and arithmetic helpers. Implements Initialize, CheckInitialized, TokenName, Symbol, Decimals, TotalSupply, BalanceOf, Transfer, TransferFrom, Approve, Allowance, Mint, Burn, BurnFrom, ClientAccountBalance, ClientAccountID and an internal _transfer helper.
48
+ - **FabricContractAdapter**: Adapts the DECAF database interface to work within Fabric chaincode, providing access to the state database.
66
49
 
67
- Design notes:
68
- - Deterministic serialization is used to ensure stable bytes for world-state writes.
69
- - onCreate/onCreateUpdate hooks from db-decorators are leveraged by the adapter to set primary keys and creator/owner metadata.
70
- - Mango queries (CouchDB) are used for rich queries via getQueryResultWithPagination.
71
- - Event emission is opt-in per operation type through FabricContractRepositoryObservableHandler’s supportedEvents list.
50
+ - **FabricContractRepository**: Implements the Repository pattern for Fabric chaincode, enabling model-driven data access.
72
51
 
73
- With these components you can build robust chaincode while keeping code concise, testable, and aligned with DECAF’s architecture.
52
+ - **FabricCrudContract**: An abstract base class that provides standard CRUD operations for chaincode models, reducing boilerplate code.
53
+
54
+ - **Event Handling**: Built-in support for emitting and handling chaincode events, facilitating communication between chaincode and client applications.
55
+
56
+ #### Integration with DECAF
57
+
58
+ This library seamlessly integrates with other DECAF components:
59
+
60
+ - Uses the decorator-validation library for model validation
61
+ - Extends the db-decorators framework for consistent data access
62
+ - Leverages the core DECAF patterns and abstractions
63
+
64
+ By providing a consistent interface across different storage technologies, @decaf-ts/for-fabric enables developers to write applications that can work with both traditional databases and blockchain ledgers with minimal code changes.
74
65
 
75
66
 
76
67
  ### How to Use
@@ -356,256 +347,6 @@ function handleEvent(eventName: string, payload: Buffer) {
356
347
  For more detailed examples and API documentation, refer to the [API Reference](./docs/api/index.html).
357
348
 
358
349
 
359
- ## Contracts APIs (Chaincode)
360
-
361
- The following examples are based on the contracts in for-fabric/src/contracts and reflect the patterns used by the unit/integration tests.
362
-
363
- ### FabricCrudContract<M>
364
-
365
- Description: Base contract exposing CRUD endpoints for a model class. It uses Repository and DeterministicSerializer under the hood.
366
-
367
- ```typescript
368
- import { Context, Transaction, Contract } from 'fabric-contract-api';
369
- import { model, ModelArg, required } from '@decaf-ts/decorator-validation';
370
- import { BaseModel, pk } from '@decaf-ts/core';
371
- import { FabricCrudContract } from '@decaf-ts/for-fabric/contracts';
372
-
373
- @model()
374
- class Person extends BaseModel {
375
- @pk({ type: 'Number' })
376
- id!: number;
377
- @required() name!: string;
378
- constructor(arg?: ModelArg<Person>) { super(arg); }
379
- }
380
-
381
- export class PersonContract extends FabricCrudContract<Person> {
382
- constructor() {
383
- super('PersonContract', Person);
384
- }
385
-
386
- @Transaction(false)
387
- async ping(ctx: Context): Promise<string> {
388
- // Uses FabricCrudContract.logFor
389
- this.logFor(ctx).info('ping');
390
- return 'pong';
391
- }
392
- }
393
- ```
394
-
395
- Usage in tests: see tests/unit/contracts.test.ts pattern where a SerializedCrudContract subclass is exercised; FabricCrudContract is similar but takes/returns objects instead of JSON strings.
396
-
397
- ### SerializedCrudContract<M>
398
-
399
- Description: Same endpoints as FabricCrudContract but takes and returns JSON strings. Useful for simple clients. Based on tests/unit/contracts.test.ts.
400
-
401
- ```typescript
402
- import { Context } from 'fabric-contract-api';
403
- import { model, ModelArg, required } from '@decaf-ts/decorator-validation';
404
- import { BaseModel, pk } from '@decaf-ts/core';
405
- import { SerializedCrudContract } from '@decaf-ts/for-fabric/contracts';
406
-
407
- @model()
408
- class TestModel extends BaseModel {
409
- @pk({ type: 'Number' }) id!: number;
410
- @required() name!: string;
411
- @required() nif!: string;
412
- constructor(arg?: ModelArg<TestModel>) { super(arg); }
413
- }
414
-
415
- export class TestModelContract extends SerializedCrudContract<TestModel> {
416
- constructor() {
417
- super('TestModelContract', TestModel);
418
- }
419
- }
420
-
421
- // Example invocation (mirrors unit test usage)
422
- async function createExample(contract: TestModelContract, ctx: Context) {
423
- const payload = new TestModel({ name: 'Alice', nif: '123456789' }).serialize();
424
- const resultJson = await contract.create(ctx, payload);
425
- const created = new TestModel(JSON.parse(resultJson));
426
- return created;
427
- }
428
- ```
429
-
430
- ### FabricContractRepository<M>
431
-
432
- Description: Chaincode-side repository used inside contract methods to persist and query models.
433
-
434
- ```typescript
435
- import { Context } from 'fabric-contract-api';
436
- import { Repo } from '@decaf-ts/core';
437
- import { model, required, ModelArg } from '@decaf-ts/decorator-validation';
438
- import { BaseModel, pk } from '@decaf-ts/core';
439
- import { FabricContractRepository } from '@decaf-ts/for-fabric/contracts';
440
-
441
- @model()
442
- class Asset extends BaseModel {
443
- @pk() id!: string;
444
- @required() owner!: string;
445
- constructor(arg?: ModelArg<Asset>) { super(arg); }
446
- }
447
-
448
- export class AssetContract extends Contract {
449
- private repo: Repo<Asset, any, any, any, any>;
450
- constructor() {
451
- super('AssetContract');
452
- this.repo = new FabricContractRepository<Asset>(new (require('@decaf-ts/for-fabric').contracts.FabricContractAdapter)(), Asset);
453
- }
454
-
455
- @Transaction()
456
- async Create(ctx: Context, id: string, owner: string): Promise<void> {
457
- const m = new Asset({ id, owner });
458
- await this.repo.create(m, ctx as any);
459
- }
460
-
461
- @Transaction(false)
462
- async Read(ctx: Context, id: string): Promise<Asset> {
463
- return this.repo.read(id, ctx as any);
464
- }
465
-
466
- @Transaction(false)
467
- async QueryByOwner(ctx: Context, owner: string): Promise<Asset[]> {
468
- return this.repo.raw({ selector: { owner } } as any, true, ctx as any);
469
- }
470
- }
471
- ```
472
-
473
- ### FabricContractDBSequence
474
-
475
- Description: World-state backed sequences for generating incremental values.
476
-
477
- ```typescript
478
- import { Context } from 'fabric-contract-api';
479
- import { FabricContractDBSequence } from '@decaf-ts/for-fabric/contracts';
480
- import { FabricContractAdapter } from '@decaf-ts/for-fabric/contracts';
481
-
482
- const adapter = new FabricContractAdapter();
483
-
484
- export class OrderContract extends Contract {
485
- private orderSeq = new FabricContractDBSequence({
486
- name: 'orderSeq',
487
- type: 'Number',
488
- startWith: 1,
489
- incrementBy: 1,
490
- }, adapter);
491
-
492
- @Transaction()
493
- async CreateOrder(ctx: Context): Promise<number> {
494
- const next = await this.orderSeq.next(ctx as any);
495
- // use next as order id
496
- return next as number;
497
- }
498
-
499
- @Transaction(false)
500
- async NextRange(ctx: Context, count: number): Promise<number[]> {
501
- return (await this.orderSeq.range(count, ctx as any)) as number[];
502
- }
503
- }
504
- ```
505
-
506
- ### FabricStatement<M,R>
507
-
508
- Description: Bridge to run Mango queries through the Fabric adapter and get typed models back; used internally by repositories and also directly in advanced cases. See tests/unit/erc20conttract.test.ts mocking CouchDBStatement processing.
509
-
510
- ```typescript
511
- import { FabricStatement } from '@decaf-ts/for-fabric/contracts';
512
- import { FabricContractAdapter } from '@decaf-ts/for-fabric/contracts';
513
- import { FabricContractContext } from '@decaf-ts/for-fabric/contracts';
514
- import { MangoQuery } from '@decaf-ts/for-couchdb';
515
- import { Model } from '@decaf-ts/decorator-validation';
516
-
517
- class MyModel extends Model {}
518
-
519
- const adapter = new FabricContractAdapter();
520
-
521
- async function query(ctx: FabricContractContext) {
522
- const stmt = new FabricStatement<MyModel, MyModel[]>(adapter, ctx);
523
- const models = await stmt.raw<MyModel[]>({ selector: { type: 'MyModel' } } as MangoQuery);
524
- return models;
525
- }
526
- ```
527
-
528
- ### ContractLogger
529
-
530
- Description: Context-aware logger bound to Fabric’s Context, honoring log levels.
531
-
532
- ```typescript
533
- import { Context, Transaction } from 'fabric-contract-api';
534
- import { Contract } from 'fabric-contract-api';
535
- import { ContractLogger } from '@decaf-ts/for-fabric/contracts';
536
-
537
- export class LoggableContract extends Contract {
538
- @Transaction()
539
- async DoWork(ctx: Context): Promise<void> {
540
- const log = new ContractLogger('LoggableContract', { level: 'info' }, ctx as any);
541
- log.info('Starting work');
542
- // ... work ...
543
- log.debug('Finished');
544
- }
545
- }
546
- ```
547
-
548
- ### FabricContractRepositoryObservableHandler
549
-
550
- Description: Emits Fabric events for repository operations. You can also use it directly to emit a custom event.
551
-
552
- ```typescript
553
- import { FabricContractRepositoryObservableHandler } from '@decaf-ts/for-fabric/contracts';
554
- import { OperationKeys } from '@decaf-ts/db-decorators';
555
- import { FabricContractContext } from '@decaf-ts/for-fabric/contracts';
556
- import { MiniLogger } from '@decaf-ts/logging';
557
-
558
- async function emitExample(ctx: FabricContractContext) {
559
- const handler = new FabricContractRepositoryObservableHandler();
560
- const log = new MiniLogger('obs');
561
- await handler.updateObservers(log as any, 'assets', OperationKeys.CREATE, 'asset1', ctx);
562
- }
563
- ```
564
-
565
- ### FabricContractContext
566
-
567
- Description: Access Fabric-specific context inside contracts.
568
-
569
- ```typescript
570
- import { FabricContractContext } from '@decaf-ts/for-fabric/contracts';
571
-
572
- function readContext(ctx: FabricContractContext) {
573
- const ts = ctx.timestamp; // Date from stub.getDateTimestamp()
574
- const id = ctx.identity.getID();
575
- ctx.logger.info(`Tx by ${id} at ${ts.toISOString()}`);
576
- }
577
- ```
578
-
579
- ### FabricERC20Contract (sample)
580
-
581
- Description: Full ERC20 implementation used in tests (see tests/unit/erc20conttract.test.ts).
582
-
583
- ```typescript
584
- import { FabricERC20Contract } from '@decaf-ts/for-fabric/contracts';
585
- import { FabricContractContext } from '@decaf-ts/for-fabric/contracts';
586
-
587
- const contract = new FabricERC20Contract('TestToken');
588
-
589
- async function initAndRead(ctx: FabricContractContext) {
590
- const created = await contract.Initialize(ctx, 'TestToken', 'TT', 18);
591
- if (created) {
592
- const name = await contract.TokenName(ctx);
593
- const decimals = await contract.Decimals(ctx);
594
- return { name, decimals };
595
- }
596
- throw new Error('Init failed');
597
- }
598
- ```
599
-
600
- ### Notes on tests as examples
601
-
602
- - tests/unit/contracts.test.ts shows creating a SerializedCrudContract and calling create(ctx, jsonPayload) with a mocked Fabric Context.
603
- - tests/unit/erc20conttract.test.ts demonstrates initializing the ERC20 contract and reading TokenName.
604
- - tests/integration/Serialized-Contract.test.ts shows end-to-end JSON-based CRUD flows via the serialized contract, including create, read, update and rich queries.
605
-
606
- These patterns are mirrored in the examples above to ensure correctness and consistency with the repository’s test suite.
607
-
608
-
609
350
  ### Related
610
351
 
611
352
  [![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=decaf-ts&repo=ts-workspace)](https://github.com/decaf-ts/ts-workspace)
@@ -644,4 +385,4 @@ So if you can, if this project in any way. either by learning something or simpl
644
385
 
645
386
  This project is released under the [MIT License](./LICENSE.md).
646
387
 
647
- By developers, for developers...
388
+ By developers, for developers...