@silvana-one/nft 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/README.md +1400 -0
  2. package/dist/node/admin/advanced.d.ts +469 -0
  3. package/dist/node/admin/advanced.js +525 -0
  4. package/dist/node/admin/advanced.js.map +1 -0
  5. package/dist/node/admin/index.d.ts +1 -0
  6. package/dist/node/admin/index.js +2 -0
  7. package/dist/node/admin/index.js.map +1 -0
  8. package/dist/node/contracts/admin.d.ts +140 -0
  9. package/dist/node/contracts/admin.js +336 -0
  10. package/dist/node/contracts/admin.js.map +1 -0
  11. package/dist/node/contracts/collection.d.ts +551 -0
  12. package/dist/node/contracts/collection.js +1049 -0
  13. package/dist/node/contracts/collection.js.map +1 -0
  14. package/dist/node/contracts/index.d.ts +3 -0
  15. package/dist/node/contracts/index.js +4 -0
  16. package/dist/node/contracts/index.js.map +1 -0
  17. package/dist/node/contracts/nft.d.ts +76 -0
  18. package/dist/node/contracts/nft.js +329 -0
  19. package/dist/node/contracts/nft.js.map +1 -0
  20. package/dist/node/contracts.d.ts +709 -0
  21. package/dist/node/contracts.js +61 -0
  22. package/dist/node/contracts.js.map +1 -0
  23. package/dist/node/index.cjs +5032 -0
  24. package/dist/node/index.d.ts +8 -0
  25. package/dist/node/index.js +9 -0
  26. package/dist/node/index.js.map +1 -0
  27. package/dist/node/interfaces/admin.d.ts +102 -0
  28. package/dist/node/interfaces/admin.js +2 -0
  29. package/dist/node/interfaces/admin.js.map +1 -0
  30. package/dist/node/interfaces/approval.d.ts +57 -0
  31. package/dist/node/interfaces/approval.js +62 -0
  32. package/dist/node/interfaces/approval.js.map +1 -0
  33. package/dist/node/interfaces/collection.d.ts +57 -0
  34. package/dist/node/interfaces/collection.js +2 -0
  35. package/dist/node/interfaces/collection.js.map +1 -0
  36. package/dist/node/interfaces/encoding.d.ts +24 -0
  37. package/dist/node/interfaces/encoding.js +32 -0
  38. package/dist/node/interfaces/encoding.js.map +1 -0
  39. package/dist/node/interfaces/events.d.ts +833 -0
  40. package/dist/node/interfaces/events.js +106 -0
  41. package/dist/node/interfaces/events.js.map +1 -0
  42. package/dist/node/interfaces/index.d.ts +10 -0
  43. package/dist/node/interfaces/index.js +11 -0
  44. package/dist/node/interfaces/index.js.map +1 -0
  45. package/dist/node/interfaces/ownable.d.ts +94 -0
  46. package/dist/node/interfaces/ownable.js +12 -0
  47. package/dist/node/interfaces/ownable.js.map +1 -0
  48. package/dist/node/interfaces/owner.d.ts +61 -0
  49. package/dist/node/interfaces/owner.js +101 -0
  50. package/dist/node/interfaces/owner.js.map +1 -0
  51. package/dist/node/interfaces/pausable.d.ts +74 -0
  52. package/dist/node/interfaces/pausable.js +14 -0
  53. package/dist/node/interfaces/pausable.js.map +1 -0
  54. package/dist/node/interfaces/types.d.ts +2297 -0
  55. package/dist/node/interfaces/types.js +507 -0
  56. package/dist/node/interfaces/types.js.map +1 -0
  57. package/dist/node/interfaces/update.d.ts +53 -0
  58. package/dist/node/interfaces/update.js +58 -0
  59. package/dist/node/interfaces/update.js.map +1 -0
  60. package/dist/node/marketplace/auction.d.ts +775 -0
  61. package/dist/node/marketplace/auction.js +430 -0
  62. package/dist/node/marketplace/auction.js.map +1 -0
  63. package/dist/node/marketplace/bid.d.ts +254 -0
  64. package/dist/node/marketplace/bid.js +260 -0
  65. package/dist/node/marketplace/bid.js.map +1 -0
  66. package/dist/node/marketplace/index.d.ts +5 -0
  67. package/dist/node/marketplace/index.js +6 -0
  68. package/dist/node/marketplace/index.js.map +1 -0
  69. package/dist/node/marketplace/nft-shares.d.ts +1083 -0
  70. package/dist/node/marketplace/nft-shares.js +398 -0
  71. package/dist/node/marketplace/nft-shares.js.map +1 -0
  72. package/dist/node/marketplace/offer.d.ts +192 -0
  73. package/dist/node/marketplace/offer.js +132 -0
  74. package/dist/node/marketplace/offer.js.map +1 -0
  75. package/dist/node/marketplace/types.d.ts +374 -0
  76. package/dist/node/marketplace/types.js +33 -0
  77. package/dist/node/marketplace/types.js.map +1 -0
  78. package/dist/node/metadata/index.d.ts +3 -0
  79. package/dist/node/metadata/index.js +4 -0
  80. package/dist/node/metadata/index.js.map +1 -0
  81. package/dist/node/metadata/metadata.d.ts +337 -0
  82. package/dist/node/metadata/metadata.js +439 -0
  83. package/dist/node/metadata/metadata.js.map +1 -0
  84. package/dist/node/metadata/text.d.ts +44 -0
  85. package/dist/node/metadata/text.js +42 -0
  86. package/dist/node/metadata/text.js.map +1 -0
  87. package/dist/node/metadata/tree.d.ts +75 -0
  88. package/dist/node/metadata/tree.js +85 -0
  89. package/dist/node/metadata/tree.js.map +1 -0
  90. package/dist/node/vk.d.ts +42 -0
  91. package/dist/node/vk.js +45 -0
  92. package/dist/node/vk.js.map +1 -0
  93. package/dist/node/zkprogram-example/game.d.ts +76 -0
  94. package/dist/node/zkprogram-example/game.js +108 -0
  95. package/dist/node/zkprogram-example/game.js.map +1 -0
  96. package/dist/node/zkprogram-example/index.d.ts +2 -0
  97. package/dist/node/zkprogram-example/index.js +3 -0
  98. package/dist/node/zkprogram-example/index.js.map +1 -0
  99. package/dist/node/zkprogram-example/update.d.ts +76 -0
  100. package/dist/node/zkprogram-example/update.js +85 -0
  101. package/dist/node/zkprogram-example/update.js.map +1 -0
  102. package/dist/tsconfig.tsbuildinfo +1 -0
  103. package/dist/tsconfig.web.tsbuildinfo +1 -0
  104. package/dist/web/admin/advanced.d.ts +469 -0
  105. package/dist/web/admin/advanced.js +525 -0
  106. package/dist/web/admin/advanced.js.map +1 -0
  107. package/dist/web/admin/index.d.ts +1 -0
  108. package/dist/web/admin/index.js +2 -0
  109. package/dist/web/admin/index.js.map +1 -0
  110. package/dist/web/contracts/admin.d.ts +140 -0
  111. package/dist/web/contracts/admin.js +336 -0
  112. package/dist/web/contracts/admin.js.map +1 -0
  113. package/dist/web/contracts/collection.d.ts +551 -0
  114. package/dist/web/contracts/collection.js +1049 -0
  115. package/dist/web/contracts/collection.js.map +1 -0
  116. package/dist/web/contracts/index.d.ts +3 -0
  117. package/dist/web/contracts/index.js +4 -0
  118. package/dist/web/contracts/index.js.map +1 -0
  119. package/dist/web/contracts/nft.d.ts +76 -0
  120. package/dist/web/contracts/nft.js +329 -0
  121. package/dist/web/contracts/nft.js.map +1 -0
  122. package/dist/web/contracts.d.ts +709 -0
  123. package/dist/web/contracts.js +61 -0
  124. package/dist/web/contracts.js.map +1 -0
  125. package/dist/web/index.d.ts +8 -0
  126. package/dist/web/index.js +9 -0
  127. package/dist/web/index.js.map +1 -0
  128. package/dist/web/interfaces/admin.d.ts +102 -0
  129. package/dist/web/interfaces/admin.js +2 -0
  130. package/dist/web/interfaces/admin.js.map +1 -0
  131. package/dist/web/interfaces/approval.d.ts +57 -0
  132. package/dist/web/interfaces/approval.js +62 -0
  133. package/dist/web/interfaces/approval.js.map +1 -0
  134. package/dist/web/interfaces/collection.d.ts +57 -0
  135. package/dist/web/interfaces/collection.js +2 -0
  136. package/dist/web/interfaces/collection.js.map +1 -0
  137. package/dist/web/interfaces/encoding.d.ts +24 -0
  138. package/dist/web/interfaces/encoding.js +32 -0
  139. package/dist/web/interfaces/encoding.js.map +1 -0
  140. package/dist/web/interfaces/events.d.ts +833 -0
  141. package/dist/web/interfaces/events.js +106 -0
  142. package/dist/web/interfaces/events.js.map +1 -0
  143. package/dist/web/interfaces/index.d.ts +10 -0
  144. package/dist/web/interfaces/index.js +11 -0
  145. package/dist/web/interfaces/index.js.map +1 -0
  146. package/dist/web/interfaces/ownable.d.ts +94 -0
  147. package/dist/web/interfaces/ownable.js +12 -0
  148. package/dist/web/interfaces/ownable.js.map +1 -0
  149. package/dist/web/interfaces/owner.d.ts +61 -0
  150. package/dist/web/interfaces/owner.js +101 -0
  151. package/dist/web/interfaces/owner.js.map +1 -0
  152. package/dist/web/interfaces/pausable.d.ts +74 -0
  153. package/dist/web/interfaces/pausable.js +14 -0
  154. package/dist/web/interfaces/pausable.js.map +1 -0
  155. package/dist/web/interfaces/types.d.ts +2297 -0
  156. package/dist/web/interfaces/types.js +507 -0
  157. package/dist/web/interfaces/types.js.map +1 -0
  158. package/dist/web/interfaces/update.d.ts +53 -0
  159. package/dist/web/interfaces/update.js +58 -0
  160. package/dist/web/interfaces/update.js.map +1 -0
  161. package/dist/web/marketplace/auction.d.ts +775 -0
  162. package/dist/web/marketplace/auction.js +430 -0
  163. package/dist/web/marketplace/auction.js.map +1 -0
  164. package/dist/web/marketplace/bid.d.ts +254 -0
  165. package/dist/web/marketplace/bid.js +260 -0
  166. package/dist/web/marketplace/bid.js.map +1 -0
  167. package/dist/web/marketplace/index.d.ts +5 -0
  168. package/dist/web/marketplace/index.js +6 -0
  169. package/dist/web/marketplace/index.js.map +1 -0
  170. package/dist/web/marketplace/nft-shares.d.ts +1083 -0
  171. package/dist/web/marketplace/nft-shares.js +398 -0
  172. package/dist/web/marketplace/nft-shares.js.map +1 -0
  173. package/dist/web/marketplace/offer.d.ts +192 -0
  174. package/dist/web/marketplace/offer.js +132 -0
  175. package/dist/web/marketplace/offer.js.map +1 -0
  176. package/dist/web/marketplace/types.d.ts +374 -0
  177. package/dist/web/marketplace/types.js +33 -0
  178. package/dist/web/marketplace/types.js.map +1 -0
  179. package/dist/web/metadata/index.d.ts +3 -0
  180. package/dist/web/metadata/index.js +4 -0
  181. package/dist/web/metadata/index.js.map +1 -0
  182. package/dist/web/metadata/metadata.d.ts +337 -0
  183. package/dist/web/metadata/metadata.js +439 -0
  184. package/dist/web/metadata/metadata.js.map +1 -0
  185. package/dist/web/metadata/text.d.ts +44 -0
  186. package/dist/web/metadata/text.js +42 -0
  187. package/dist/web/metadata/text.js.map +1 -0
  188. package/dist/web/metadata/tree.d.ts +75 -0
  189. package/dist/web/metadata/tree.js +85 -0
  190. package/dist/web/metadata/tree.js.map +1 -0
  191. package/dist/web/vk.d.ts +42 -0
  192. package/dist/web/vk.js +45 -0
  193. package/dist/web/vk.js.map +1 -0
  194. package/dist/web/zkprogram-example/game.d.ts +76 -0
  195. package/dist/web/zkprogram-example/game.js +108 -0
  196. package/dist/web/zkprogram-example/game.js.map +1 -0
  197. package/dist/web/zkprogram-example/index.d.ts +2 -0
  198. package/dist/web/zkprogram-example/index.js +3 -0
  199. package/dist/web/zkprogram-example/index.js.map +1 -0
  200. package/dist/web/zkprogram-example/update.d.ts +76 -0
  201. package/dist/web/zkprogram-example/update.js +85 -0
  202. package/dist/web/zkprogram-example/update.js.map +1 -0
  203. package/package.json +65 -0
  204. package/src/admin/advanced.ts +601 -0
  205. package/src/admin/index.ts +1 -0
  206. package/src/contracts/admin.ts +301 -0
  207. package/src/contracts/collection.ts +1172 -0
  208. package/src/contracts/index.ts +3 -0
  209. package/src/contracts/nft.ts +344 -0
  210. package/src/contracts.ts +107 -0
  211. package/src/index.ts +8 -0
  212. package/src/interfaces/admin.ts +127 -0
  213. package/src/interfaces/approval.ts +99 -0
  214. package/src/interfaces/collection.ts +68 -0
  215. package/src/interfaces/encoding.ts +32 -0
  216. package/src/interfaces/events.ts +115 -0
  217. package/src/interfaces/index.ts +10 -0
  218. package/src/interfaces/ownable.ts +32 -0
  219. package/src/interfaces/owner.ts +143 -0
  220. package/src/interfaces/pausable.ts +41 -0
  221. package/src/interfaces/types.ts +623 -0
  222. package/src/interfaces/update.ts +104 -0
  223. package/src/marketplace/auction.ts +527 -0
  224. package/src/marketplace/bid.ts +294 -0
  225. package/src/marketplace/index.ts +5 -0
  226. package/src/marketplace/nft-shares.ts +388 -0
  227. package/src/marketplace/offer.ts +153 -0
  228. package/src/marketplace/types.ts +33 -0
  229. package/src/metadata/index.ts +3 -0
  230. package/src/metadata/metadata.ts +603 -0
  231. package/src/metadata/text.ts +60 -0
  232. package/src/metadata/tree.ts +128 -0
  233. package/src/vk.ts +64 -0
  234. package/src/zkprogram-example/game.ts +136 -0
  235. package/src/zkprogram-example/index.ts +2 -0
  236. package/src/zkprogram-example/update.ts +98 -0
@@ -0,0 +1,623 @@
1
+ import {
2
+ Field,
3
+ PublicKey,
4
+ Bool,
5
+ Struct,
6
+ UInt32,
7
+ UInt64,
8
+ Provable,
9
+ DynamicProof,
10
+ FeatureFlags,
11
+ Option,
12
+ Account,
13
+ } from "o1js";
14
+ import { Storage } from "@silvana-one/storage";
15
+ export {
16
+ MintParams,
17
+ MintParamsOption,
18
+ MintRequest,
19
+ NFTDataPacked,
20
+ NFTData,
21
+ CollectionData,
22
+ NFTState,
23
+ NFTImmutableState,
24
+ NFTUpdateProof,
25
+ NFTStateStruct,
26
+ UInt64Option,
27
+ TransferParams,
28
+ MAX_ROYALTY_FEE,
29
+ NFTTransactionContext,
30
+ TransferExtendedParams,
31
+ };
32
+
33
+ class UInt64Option extends Option(UInt64) {}
34
+
35
+ class NFTDataPacked extends Struct({
36
+ ownerX: Field,
37
+ approvedX: Field,
38
+ data: Field,
39
+ }) {
40
+ static assertEqual(a: NFTDataPacked, b: NFTDataPacked) {
41
+ a.ownerX.assertEquals(b.ownerX);
42
+ a.approvedX.assertEquals(b.approvedX);
43
+ a.data.assertEquals(b.data);
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Represents the on-chain state structure of an NFT.
49
+ * The order of the fields is important and should match the NFT SmartContract.
50
+ */
51
+ class NFTStateStruct extends Struct({
52
+ name: Field,
53
+ metadata: Field,
54
+ storage: Storage,
55
+ packedData: NFTDataPacked,
56
+ metadataVerificationKeyHash: Field,
57
+ }) {
58
+ /**
59
+ * Creates an NFTStateStruct from an account's app state.
60
+ * @param account The account containing the zkApp state.
61
+ * @returns A new NFTStateStruct instance.
62
+ */
63
+ static fromAccount(account: Account) {
64
+ if (!account.zkapp?.appState) {
65
+ throw new Error("Invalid zkApp account state");
66
+ }
67
+ if (NFTStateStruct.sizeInFields() !== account.zkapp?.appState.length) {
68
+ throw new Error("Invalid NFTStateStruct size");
69
+ }
70
+ return NFTStateStruct.fromFields(account.zkapp?.appState);
71
+ }
72
+
73
+ /**
74
+ * Asserts that two NFTStateStruct instances are equal.
75
+ * @param a The first NFTStateStruct instance.
76
+ * @param b The second NFTStateStruct instance.
77
+ */
78
+ static assertEqual(a: NFTStateStruct, b: NFTStateStruct) {
79
+ a.name.assertEquals(b.name);
80
+ a.metadata.assertEquals(b.metadata);
81
+ Storage.assertEquals(a.storage, b.storage);
82
+ NFTDataPacked.assertEqual(a.packedData, b.packedData);
83
+ a.metadataVerificationKeyHash.assertEquals(b.metadataVerificationKeyHash);
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Represents the immutable state of an NFT, containing read-only properties
89
+ * and flags that determine the NFT's behavior and permissions.
90
+ */
91
+ class NFTImmutableState extends Struct({
92
+ /** Determines if the NFT's ownership can be changed via a zero-knowledge proof (readonly). */
93
+ canChangeOwnerByProof: Bool, // readonly
94
+ /** Specifies if the NFT's ownership can be transferred (readonly). */
95
+ canTransfer: Bool, // readonly
96
+ /** Specifies if the NFT's approved address can be changed (readonly). */
97
+ canApprove: Bool, // readonly
98
+ /** Indicates whether the NFT's metadata can be updated (readonly). */
99
+ canChangeMetadata: Bool, // readonly
100
+ /** Determines whether the storage associated with the NFT can be altered (readonly). */
101
+ canChangeStorage: Bool, // readonly
102
+ /** Specifies if the name of the NFT can be changed (readonly). */
103
+ canChangeName: Bool, // readonly
104
+ /** Indicates whether the verification key hash for the metadata can be changed (readonly). */
105
+ canChangeMetadataVerificationKeyHash: Bool, // readonly
106
+ /** Specifies if the NFT contract can be paused, preventing certain operations (readonly). */
107
+ canPause: Bool, // readonly
108
+ /** The address of the NFT contract (readonly). */
109
+ address: PublicKey, // readonly
110
+ /** The token ID associated with the NFT (readonly). */
111
+ tokenId: Field, // readonly
112
+ /** The unique identifier of the NFT within the collection (readonly). */
113
+ id: UInt64, // readonly
114
+ }) {
115
+ /**
116
+ * Asserts that two NFTImmutableState instances are equal.
117
+ * @param a The first NFTImmutableState instance.
118
+ * @param b The second NFTImmutableState instance.
119
+ */
120
+ static assertEqual(a: NFTImmutableState, b: NFTImmutableState) {
121
+ a.canChangeOwnerByProof.assertEquals(b.canChangeOwnerByProof);
122
+ a.canTransfer.assertEquals(b.canTransfer);
123
+ a.canApprove.assertEquals(b.canApprove);
124
+ a.canChangeMetadata.assertEquals(b.canChangeMetadata);
125
+ a.canChangeStorage.assertEquals(b.canChangeStorage);
126
+ a.canChangeName.assertEquals(b.canChangeName);
127
+ a.canChangeMetadataVerificationKeyHash.assertEquals(
128
+ b.canChangeMetadataVerificationKeyHash
129
+ );
130
+ a.canPause.assertEquals(b.canPause);
131
+ a.address.assertEquals(b.address);
132
+ a.tokenId.assertEquals(b.tokenId);
133
+ a.id.assertEquals(b.id);
134
+ }
135
+
136
+ /**
137
+ * Creates a new NFTImmutableState from NFTData and other parameters.
138
+ * @param params The parameters including nftData, creator, address, and tokenId.
139
+ * @returns A new NFTImmutableState instance.
140
+ */
141
+ static fromNFTData(params: {
142
+ nftData: NFTData;
143
+ address: PublicKey;
144
+ tokenId: Field;
145
+ }) {
146
+ const { nftData, address, tokenId } = params;
147
+ return new NFTImmutableState({
148
+ address,
149
+ tokenId,
150
+ id: nftData.id,
151
+ canChangeOwnerByProof: nftData.canChangeOwnerByProof,
152
+ canTransfer: nftData.canTransfer,
153
+ canApprove: nftData.canApprove,
154
+ canChangeMetadata: nftData.canChangeMetadata,
155
+ canChangeStorage: nftData.canChangeStorage,
156
+ canChangeName: nftData.canChangeName,
157
+ canChangeMetadataVerificationKeyHash:
158
+ nftData.canChangeMetadataVerificationKeyHash,
159
+ canPause: nftData.canPause,
160
+ });
161
+ }
162
+ }
163
+
164
+ class NFTTransactionContext extends Struct({
165
+ /** Custom context that can be interpreted by the owner or approved contract.
166
+ * Can hold Storage and root or two PublicKeys and UInt64
167
+ * In case of holding Storage and root, the contracts can fetch using witnessAsync any off-chain data with unlimited size
168
+ * and verify it using the root.
169
+ */
170
+ custom: Provable.Array(Field, 3),
171
+ }) {
172
+ static assertEqual(a: NFTTransactionContext, b: NFTTransactionContext) {
173
+ for (let i = 0; i < 3; i++) {
174
+ a.custom[i].assertEquals(b.custom[i]);
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Represents the full state of an NFT, including both immutable and mutable properties.
181
+ */
182
+ class NFTState extends Struct({
183
+ /** The immutable state of the NFT. */
184
+ immutableState: NFTImmutableState,
185
+ /** The name of the NFT. */
186
+ name: Field,
187
+ /** The owner of the NFT. */
188
+ owner: PublicKey,
189
+ /** The approved address of the NFT. */
190
+ approved: PublicKey,
191
+ /** The metadata associated with the NFT. */
192
+ metadata: Field,
193
+ /** The off-chain storage information (e.g., IPFS hash). */
194
+ storage: Storage,
195
+ /** The version number of the NFT state. */
196
+ version: UInt32,
197
+ /** Indicates whether the NFT contract is currently paused. */
198
+ isPaused: Bool,
199
+ /** The hash of the verification key used for metadata proofs. */
200
+ metadataVerificationKeyHash: Field,
201
+
202
+ /** The public key of the creator of the NFT (readonly). */
203
+ creator: PublicKey, // readonly
204
+ /** The transaction context of the NFT. */
205
+ context: NFTTransactionContext, // readonly
206
+ /** The oracle address to link the NFT update with the network and accounts state */
207
+ oracleAddress: PublicKey, // readonly
208
+ }) {
209
+ /**
210
+ * Asserts that two NFTState instances are equal.
211
+ * @param a The first NFTState instance.
212
+ * @param b The second NFTState instance.
213
+ */
214
+ static assertEqual(a: NFTState, b: NFTState) {
215
+ NFTImmutableState.assertEqual(a.immutableState, b.immutableState);
216
+ a.name.assertEquals(b.name);
217
+ a.metadata.assertEquals(b.metadata);
218
+ Storage.assertEquals(a.storage, b.storage);
219
+ a.owner.assertEquals(b.owner);
220
+ a.approved.assertEquals(b.approved);
221
+ a.version.assertEquals(b.version);
222
+ a.isPaused.assertEquals(b.isPaused);
223
+ a.metadataVerificationKeyHash.assertEquals(b.metadataVerificationKeyHash);
224
+ a.creator.assertEquals(b.creator);
225
+ NFTTransactionContext.assertEqual(a.context, b.context);
226
+ }
227
+
228
+ /**
229
+ * Creates a new NFTState from an NFTStateStruct and other parameters.
230
+ * @param params The parameters including nftState, creator, address, and tokenId.
231
+ * @returns A new NFTState instance.
232
+ */
233
+ static fromNFTState(params: {
234
+ nftState: NFTStateStruct;
235
+ creator: PublicKey;
236
+ address: PublicKey;
237
+ tokenId: Field;
238
+ context?: NFTTransactionContext;
239
+ oracleAddress?: PublicKey;
240
+ }) {
241
+ const { nftState, creator, address, tokenId, context, oracleAddress } =
242
+ params;
243
+ const nftData = NFTData.unpack(nftState.packedData);
244
+ const immutableState = NFTImmutableState.fromNFTData({
245
+ nftData,
246
+ address,
247
+ tokenId,
248
+ });
249
+ return new NFTState({
250
+ immutableState,
251
+ name: nftState.name,
252
+ metadata: nftState.metadata,
253
+ storage: nftState.storage,
254
+ owner: nftData.owner,
255
+ approved: nftData.approved,
256
+ version: nftData.version,
257
+ isPaused: nftData.isPaused,
258
+ metadataVerificationKeyHash: nftState.metadataVerificationKeyHash,
259
+ creator,
260
+ context: context ?? NFTTransactionContext.empty(),
261
+ oracleAddress: oracleAddress ?? PublicKey.empty(),
262
+ });
263
+ }
264
+ }
265
+
266
+ /**
267
+ * Represents a dynamic proof used for updating the state of an NFT.
268
+ */
269
+ class NFTUpdateProof extends DynamicProof<NFTState, NFTState> {
270
+ static publicInputType = NFTState;
271
+ static publicOutputType = NFTState;
272
+ static maxProofsVerified = 2 as const;
273
+ static featureFlags = FeatureFlags.allMaybe;
274
+ }
275
+
276
+ /**
277
+ * Represents the data associated with an NFT, including state and permission flags.
278
+ */
279
+ class NFTData extends Struct({
280
+ /** The owner of the NFT. */
281
+ owner: PublicKey,
282
+ /** The approved address of the NFT. */
283
+ approved: PublicKey,
284
+ /** The version number of the NFT state. */
285
+ version: UInt32,
286
+ /** The unique identifier of the NFT within the collection. */
287
+ id: UInt64,
288
+ /** Determines whether the NFT's ownership can be changed via a zero-knowledge proof (readonly). */
289
+ canChangeOwnerByProof: Bool, // readonly
290
+ /** Specifies if the NFT's ownership can be transferred (readonly). */
291
+ canTransfer: Bool, // readonly
292
+ /** Specifies if the NFT's approved address can be changed (readonly). */
293
+ canApprove: Bool, // readonly
294
+ /** Indicates whether the NFT's metadata can be updated (readonly). */
295
+ canChangeMetadata: Bool, // readonly
296
+ /** Determines whether the storage associated with the NFT can be altered (readonly). */
297
+ canChangeStorage: Bool, // readonly
298
+ /** Specifies if the name of the NFT can be changed (readonly). */
299
+ canChangeName: Bool, // readonly
300
+ /** Indicates whether the verification key hash for the metadata can be changed (readonly). */
301
+ canChangeMetadataVerificationKeyHash: Bool, // readonly
302
+ /** Specifies if the NFT contract can be paused, preventing certain operations (readonly). */
303
+ canPause: Bool, // readonly
304
+ /** Indicates whether the NFT contract is currently paused. */
305
+ isPaused: Bool,
306
+ /** Determines whether the owner's authorization is required to upgrade the NFT's verification key (readonly). */
307
+ requireOwnerAuthorizationToUpgrade: Bool, // readonly
308
+ }) {
309
+ /**
310
+ * Creates a new NFTData instance with optional parameters.
311
+ * @param params The parameters to create the NFTData.
312
+ * @returns A new NFTData instance.
313
+ */
314
+ static new(params: {
315
+ owner: string | PublicKey;
316
+ approved?: string | PublicKey;
317
+ version?: number;
318
+ id?: bigint;
319
+ canChangeOwnerByProof?: boolean;
320
+ canTransfer?: boolean;
321
+ canApprove?: boolean;
322
+ canChangeMetadata?: boolean;
323
+ canChangeStorage?: boolean;
324
+ canChangeName?: boolean;
325
+ canChangeMetadataVerificationKeyHash?: boolean;
326
+ canPause?: boolean;
327
+ isPaused?: boolean;
328
+ requireOwnerAuthorizationToUpgrade?: boolean;
329
+ }): NFTData {
330
+ const {
331
+ owner,
332
+ approved,
333
+ version,
334
+ id,
335
+ canChangeOwnerByProof,
336
+ canTransfer,
337
+ canApprove,
338
+ canChangeMetadata,
339
+ canChangeStorage,
340
+ canChangeName,
341
+ canChangeMetadataVerificationKeyHash,
342
+ canPause,
343
+ isPaused,
344
+ requireOwnerAuthorizationToUpgrade,
345
+ } = params;
346
+ return new NFTData({
347
+ owner: typeof owner === "string" ? PublicKey.fromBase58(owner) : owner,
348
+ approved: approved
349
+ ? typeof approved === "string"
350
+ ? PublicKey.fromBase58(approved)
351
+ : approved
352
+ : PublicKey.empty(),
353
+ version: UInt32.from(version ?? 0),
354
+ id: UInt64.from(id ?? 0),
355
+ canChangeOwnerByProof: Bool(canChangeOwnerByProof ?? false),
356
+ canTransfer: Bool(canTransfer ?? true),
357
+ canApprove: Bool(canApprove ?? true),
358
+ canChangeMetadata: Bool(canChangeMetadata ?? false),
359
+ canChangeStorage: Bool(canChangeStorage ?? false),
360
+ canChangeName: Bool(canChangeName ?? false),
361
+ canChangeMetadataVerificationKeyHash: Bool(
362
+ canChangeMetadataVerificationKeyHash ?? false
363
+ ),
364
+ canPause: Bool(canPause ?? false),
365
+ isPaused: Bool(isPaused ?? false),
366
+ requireOwnerAuthorizationToUpgrade: Bool(
367
+ requireOwnerAuthorizationToUpgrade ?? false
368
+ ),
369
+ });
370
+ }
371
+
372
+ /**
373
+ * Packs the NFTData into a single Field for efficient storage.
374
+ * @returns The packed Field representation of the NFTData.
375
+ */
376
+ pack(): NFTDataPacked {
377
+ const id = this.id.value.toBits(64);
378
+ const version = this.version.value.toBits(32);
379
+ return new NFTDataPacked({
380
+ ownerX: this.owner.x,
381
+ approvedX: this.approved.x,
382
+ data: Field.fromBits([
383
+ ...id,
384
+ ...version,
385
+ this.canChangeOwnerByProof,
386
+ this.canTransfer,
387
+ this.canApprove,
388
+ this.canChangeMetadata,
389
+ this.canChangeStorage,
390
+ this.canChangeName,
391
+ this.canChangeMetadataVerificationKeyHash,
392
+ this.canPause,
393
+ this.isPaused,
394
+ this.requireOwnerAuthorizationToUpgrade,
395
+ this.owner.isOdd,
396
+ this.approved.isOdd,
397
+ ]),
398
+ });
399
+ }
400
+
401
+ /**
402
+ * Unpacks a Field into an NFTData instance.
403
+ * @param packed The packed Field representation of the NFTData.
404
+ * @returns A new NFTData instance.
405
+ */
406
+ static unpack(packed: NFTDataPacked): NFTData {
407
+ const bits = packed.data.toBits(64 + 32 + 12);
408
+ const id = UInt64.Unsafe.fromField(Field.fromBits(bits.slice(0, 64)));
409
+ const version = UInt32.Unsafe.fromField(
410
+ Field.fromBits(bits.slice(64, 64 + 32))
411
+ );
412
+
413
+ const canChangeOwnerByProof = bits[64 + 32 + 0];
414
+ const canTransfer = bits[64 + 32 + 1];
415
+ const canApprove = bits[64 + 32 + 2];
416
+ const canChangeMetadata = bits[64 + 32 + 3];
417
+ const canChangeStorage = bits[64 + 32 + 4];
418
+ const canChangeName = bits[64 + 32 + 5];
419
+ const canChangeMetadataVerificationKeyHash = bits[64 + 32 + 6];
420
+ const canPause = bits[64 + 32 + 7];
421
+ const isPaused = bits[64 + 32 + 8];
422
+ const requireOwnerAuthorizationToUpgrade = bits[64 + 32 + 9];
423
+ const ownerIsOdd = bits[64 + 32 + 10];
424
+ const approvedIsOdd = bits[64 + 32 + 11];
425
+ const owner = PublicKey.from({ x: packed.ownerX, isOdd: ownerIsOdd });
426
+ const approved = PublicKey.from({
427
+ x: packed.approvedX,
428
+ isOdd: approvedIsOdd,
429
+ });
430
+ return new NFTData({
431
+ owner,
432
+ approved,
433
+ id,
434
+ version,
435
+ canChangeOwnerByProof,
436
+ canTransfer,
437
+ canApprove,
438
+ canChangeMetadata,
439
+ canChangeStorage,
440
+ canChangeName,
441
+ canChangeMetadataVerificationKeyHash,
442
+ canPause,
443
+ isPaused,
444
+ requireOwnerAuthorizationToUpgrade,
445
+ });
446
+ }
447
+ }
448
+
449
+ const MAX_ROYALTY_FEE = 100000;
450
+
451
+ /**
452
+ * Represents the data associated with an NFT collection, including configuration parameters and permission flags.
453
+ */
454
+ class CollectionData extends Struct({
455
+ /** The royalty fee percentage (e.g., 1000 = 1%, 100 = 0.1%, 10000 = 10%, 100000 = 100%). */
456
+ royaltyFee: UInt32, // 1000 = 1%, 100 = 0.1%, 10000 = 10%, 100000 = 100%
457
+ /** The transfer fee amount. */
458
+ transferFee: UInt64,
459
+ /** If true, transferring NFTs requires approval from the admin contract. */
460
+ requireTransferApproval: Bool,
461
+ /** If true, the minting is stopped and cannot be resumed. */
462
+ mintingIsLimited: Bool,
463
+ /** Indicates whether the collection is currently paused. */
464
+ isPaused: Bool,
465
+ }) {
466
+ /**
467
+ * Creates a new CollectionData instance with specified parameters.
468
+ * @param params The parameters to create the CollectionData.
469
+ * @returns A new CollectionData instance.
470
+ */
471
+ static new(params: {
472
+ royaltyFee?: number;
473
+ transferFee?: number;
474
+ requireTransferApproval?: boolean;
475
+ mintingIsLimited?: boolean;
476
+ isPaused?: boolean;
477
+ }): CollectionData {
478
+ const {
479
+ royaltyFee,
480
+ transferFee,
481
+ requireTransferApproval,
482
+ mintingIsLimited,
483
+ isPaused,
484
+ } = params;
485
+ return new CollectionData({
486
+ royaltyFee: UInt32.from(royaltyFee ?? 0),
487
+ transferFee: UInt64.from(transferFee ?? 0),
488
+ requireTransferApproval: Bool(requireTransferApproval ?? false),
489
+ mintingIsLimited: Bool(mintingIsLimited ?? false),
490
+ isPaused: Bool(isPaused ?? false),
491
+ });
492
+ }
493
+
494
+ /**
495
+ * Packs the CollectionData into a CollectionDataPacked representation for efficient storage.
496
+ * @returns The packed CollectionDataPacked instance.
497
+ */
498
+ pack(): Field {
499
+ return Field.fromBits([
500
+ this.isPaused,
501
+ this.requireTransferApproval,
502
+ this.mintingIsLimited,
503
+ ...this.royaltyFee.value.toBits(32),
504
+ ...this.transferFee.value.toBits(64),
505
+ ]);
506
+ }
507
+
508
+ /**
509
+ * Unpacks a CollectionDataPacked instance into a CollectionData instance.
510
+ * @param packed The packed CollectionDataPacked instance.
511
+ * @returns A new CollectionData instance.
512
+ */
513
+ static unpack(packed: Field) {
514
+ const bits = packed.toBits(3 + 32 + 64);
515
+ const royaltyFee = UInt32.Unsafe.fromField(
516
+ Field.fromBits(bits.slice(3, 3 + 32))
517
+ );
518
+ const transferFee = UInt64.Unsafe.fromField(
519
+ Field.fromBits(bits.slice(3 + 32, 3 + 32 + 64))
520
+ );
521
+
522
+ return new CollectionData({
523
+ isPaused: bits[0],
524
+ requireTransferApproval: bits[1],
525
+ mintingIsLimited: bits[2],
526
+ royaltyFee,
527
+ transferFee,
528
+ });
529
+ }
530
+
531
+ static isPaused(packed: Field) {
532
+ return packed.toBits(3 + 32 + 64)[0];
533
+ }
534
+
535
+ static requireTransferApproval(packed: Field) {
536
+ return packed.toBits(3 + 32 + 64)[1];
537
+ }
538
+
539
+ static mintingIsLimited(packed: Field) {
540
+ const bits = packed.toBits(3 + 32 + 64);
541
+ const isPaused = bits[0];
542
+ const mintingIsLimited = bits[2];
543
+ return isPaused.or(mintingIsLimited);
544
+ }
545
+ }
546
+
547
+ /**
548
+ * Represents the parameters required for minting a new NFT.
549
+ */
550
+ class MintParams extends Struct({
551
+ /** The name of the NFT. */
552
+ name: Field,
553
+ /** The address of the NFT contract. */
554
+ address: PublicKey,
555
+ /** The token ID of the NFT. */
556
+ tokenId: Field,
557
+ /** The data associated with the NFT, including owner, approved, version, id, permissions and flags. */
558
+ data: NFTData,
559
+ /** The fee associated with minting the NFT. */
560
+ fee: UInt64,
561
+ /** The metadata associated with the NFT. */
562
+ metadata: Field,
563
+ /** The off-chain storage information (e.g., IPFS hash). */
564
+ storage: Storage,
565
+ /** The hash of the verification key used for metadata proofs. */
566
+ metadataVerificationKeyHash: Field,
567
+ /** The expiry time slot for minting the NFT. */
568
+ expiry: UInt32,
569
+ }) {}
570
+
571
+ /**
572
+ * Represents an optional MintParams, used in scenarios where minting may or may not be allowed.
573
+ */
574
+ class MintParamsOption extends Option(MintParams) {}
575
+
576
+ /**
577
+ * Represents a request to mint a new NFT, used by the admin contract to determine if minting is allowed.
578
+ */
579
+ class MintRequest extends Struct({
580
+ /** The address of the NFT contract where the NFT will be minted. */
581
+ address: PublicKey,
582
+ /** The owner of the new NFT (can be different from the sender). */
583
+ owner: PublicKey, // can be different from the sender
584
+ /** A custom value that can be interpreted by the admin contract. */
585
+ context: NFTTransactionContext, // should be interpreted by the admin contract
586
+ }) {}
587
+
588
+ /**
589
+ * Represents the parameters required for transferring an NFT.
590
+ */
591
+ class TransferParams extends Struct({
592
+ /** The address of the NFT contract. */
593
+ address: PublicKey,
594
+ /** The sender's public key. */
595
+ from: PublicKey,
596
+ /** The receiver's public key. */
597
+ to: PublicKey,
598
+ /** Optional price for the transfer. */
599
+ price: UInt64Option,
600
+ /** Custom value that can be interpreted by the owner or approved contract. */
601
+ context: NFTTransactionContext,
602
+ }) {}
603
+
604
+ class TransferExtendedParams extends Struct({
605
+ /** The public key of the sender (current owner) before the transfer. */
606
+ from: PublicKey,
607
+ /** The public key of the recipient (new owner) after the transfer. */
608
+ to: PublicKey,
609
+ /** The public key of the collection. */
610
+ collection: PublicKey,
611
+ /** The public key address of the NFT being transferred. */
612
+ nft: PublicKey,
613
+ /** The fee paid for the transfer. */
614
+ fee: UInt64Option,
615
+ /** The price of the NFT being transferred. */
616
+ price: UInt64Option,
617
+ /** Indicates whether the transfer is by owner or by approved address. */
618
+ transferByOwner: Bool,
619
+ /** The public key of the approved address. */
620
+ approved: PublicKey,
621
+ /** Custom value that can be interpreted by the owner or approved contract. */
622
+ context: NFTTransactionContext,
623
+ }) {}